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"
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 (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
370 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
372 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
373 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
374 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
377 /* Return a pointer to a copy of the section string name S with all
378 attributes stripped off, and an asterisk prepended (for assemble_name). */
381 stripattributes (const char *s
)
383 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
388 while (*s
&& *s
!= ',')
395 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
396 switch to the data section instead, and write out a synthetic start label
397 for collect2 the first time around. */
400 switch_to_eh_frame_section (bool back
)
404 #ifdef EH_FRAME_SECTION_NAME
405 if (eh_frame_section
== 0)
409 if (EH_TABLES_CAN_BE_READ_ONLY
)
415 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
417 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
419 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
422 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
423 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
424 && (per_encoding
& 0x70) != DW_EH_PE_absptr
425 && (per_encoding
& 0x70) != DW_EH_PE_aligned
426 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
427 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
428 ? 0 : SECTION_WRITE
);
431 flags
= SECTION_WRITE
;
432 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
434 #endif /* EH_FRAME_SECTION_NAME */
436 if (eh_frame_section
)
437 switch_to_section (eh_frame_section
);
440 /* We have no special eh_frame section. Put the information in
441 the data section and emit special labels to guide collect2. */
442 switch_to_section (data_section
);
446 label
= get_file_function_name ("F");
447 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
448 targetm
.asm_out
.globalize_label (asm_out_file
,
449 IDENTIFIER_POINTER (label
));
450 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
455 /* Switch [BACK] to the eh or debug frame table section, depending on
459 switch_to_frame_table_section (int for_eh
, bool back
)
462 switch_to_eh_frame_section (back
);
465 if (!debug_frame_section
)
466 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
467 SECTION_DEBUG
, NULL
);
468 switch_to_section (debug_frame_section
);
472 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
474 enum dw_cfi_oprnd_type
475 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
480 case DW_CFA_GNU_window_save
:
481 case DW_CFA_remember_state
:
482 case DW_CFA_restore_state
:
483 return dw_cfi_oprnd_unused
;
486 case DW_CFA_advance_loc1
:
487 case DW_CFA_advance_loc2
:
488 case DW_CFA_advance_loc4
:
489 case DW_CFA_MIPS_advance_loc8
:
490 return dw_cfi_oprnd_addr
;
493 case DW_CFA_offset_extended
:
495 case DW_CFA_offset_extended_sf
:
496 case DW_CFA_def_cfa_sf
:
498 case DW_CFA_restore_extended
:
499 case DW_CFA_undefined
:
500 case DW_CFA_same_value
:
501 case DW_CFA_def_cfa_register
:
502 case DW_CFA_register
:
503 case DW_CFA_expression
:
504 return dw_cfi_oprnd_reg_num
;
506 case DW_CFA_def_cfa_offset
:
507 case DW_CFA_GNU_args_size
:
508 case DW_CFA_def_cfa_offset_sf
:
509 return dw_cfi_oprnd_offset
;
511 case DW_CFA_def_cfa_expression
:
512 return dw_cfi_oprnd_loc
;
519 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
521 enum dw_cfi_oprnd_type
522 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
527 case DW_CFA_def_cfa_sf
:
529 case DW_CFA_offset_extended_sf
:
530 case DW_CFA_offset_extended
:
531 return dw_cfi_oprnd_offset
;
533 case DW_CFA_register
:
534 return dw_cfi_oprnd_reg_num
;
536 case DW_CFA_expression
:
537 return dw_cfi_oprnd_loc
;
540 return dw_cfi_oprnd_unused
;
544 /* Output one FDE. */
547 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
548 char *section_start_label
, int fde_encoding
, char *augmentation
,
549 bool any_lsda_needed
, int lsda_encoding
)
551 const char *begin
, *end
;
552 static unsigned int j
;
555 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
557 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
559 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
560 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
561 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
562 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
563 " indicating 64-bit DWARF extension");
564 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
566 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
569 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
571 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
572 debug_frame_section
, "FDE CIE offset");
574 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
575 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
579 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
580 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
581 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
582 "FDE initial location");
583 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
584 end
, begin
, "FDE address range");
588 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
589 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
596 int size
= size_of_encoded_value (lsda_encoding
);
598 if (lsda_encoding
== DW_EH_PE_aligned
)
600 int offset
= ( 4 /* Length */
602 + 2 * size_of_encoded_value (fde_encoding
)
603 + 1 /* Augmentation size */ );
604 int pad
= -offset
& (PTR_SIZE
- 1);
607 gcc_assert (size_of_uleb128 (size
) == 1);
610 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
612 if (fde
->uses_eh_lsda
)
614 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
615 fde
->funcdef_number
);
616 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
617 gen_rtx_SYMBOL_REF (Pmode
, l1
),
619 "Language Specific Data Area");
623 if (lsda_encoding
== DW_EH_PE_aligned
)
624 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
625 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
626 "Language Specific Data Area (none)");
630 dw2_asm_output_data_uleb128 (0, "Augmentation size");
633 /* Loop through the Call Frame Instructions associated with this FDE. */
634 fde
->dw_fde_current_label
= begin
;
636 size_t from
, until
, i
;
639 until
= vec_safe_length (fde
->dw_fde_cfi
);
641 if (fde
->dw_fde_second_begin
== NULL
)
644 until
= fde
->dw_fde_switch_cfi_index
;
646 from
= fde
->dw_fde_switch_cfi_index
;
648 for (i
= from
; i
< until
; i
++)
649 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
652 /* If we are to emit a ref/link from function bodies to their frame tables,
653 do it now. This is typically performed to make sure that tables
654 associated with functions are dragged with them and not discarded in
655 garbage collecting links. We need to do this on a per function basis to
656 cope with -ffunction-sections. */
658 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
659 /* Switch to the function section, emit the ref to the tables, and
660 switch *back* into the table section. */
661 switch_to_section (function_section (fde
->decl
));
662 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
663 switch_to_frame_table_section (for_eh
, true);
666 /* Pad the FDE out to an address sized boundary. */
667 ASM_OUTPUT_ALIGN (asm_out_file
,
668 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
669 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
674 /* Return true if frame description entry FDE is needed for EH. */
677 fde_needed_for_eh_p (dw_fde_ref fde
)
679 if (flag_asynchronous_unwind_tables
)
682 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
685 if (fde
->uses_eh_lsda
)
688 /* If exceptions are enabled, we have collected nothrow info. */
689 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
695 /* Output the call frame information used to record information
696 that relates to calculating the frame pointer, and records the
697 location of saved registers. */
700 output_call_frame_info (int for_eh
)
705 char l1
[20], l2
[20], section_start_label
[20];
706 bool any_lsda_needed
= false;
707 char augmentation
[6];
708 int augmentation_size
;
709 int fde_encoding
= DW_EH_PE_absptr
;
710 int per_encoding
= DW_EH_PE_absptr
;
711 int lsda_encoding
= DW_EH_PE_absptr
;
713 rtx personality
= NULL
;
716 /* Don't emit a CIE if there won't be any FDEs. */
720 /* Nothing to do if the assembler's doing it all. */
721 if (dwarf2out_do_cfi_asm ())
724 /* If we don't have any functions we'll want to unwind out of, don't emit
725 any EH unwind information. If we make FDEs linkonce, we may have to
726 emit an empty label for an FDE that wouldn't otherwise be emitted. We
727 want to avoid having an FDE kept around when the function it refers to
728 is discarded. Example where this matters: a primary function template
729 in C++ requires EH information, an explicit specialization doesn't. */
732 bool any_eh_needed
= false;
734 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
736 if (fde
->uses_eh_lsda
)
737 any_eh_needed
= any_lsda_needed
= true;
738 else if (fde_needed_for_eh_p (fde
))
739 any_eh_needed
= true;
740 else if (TARGET_USES_WEAK_UNWIND_INFO
)
741 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
748 /* We're going to be generating comments, so turn on app. */
752 /* Switch to the proper frame section, first time. */
753 switch_to_frame_table_section (for_eh
, false);
755 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
756 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
758 /* Output the CIE. */
759 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
760 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
761 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
762 dw2_asm_output_data (4, 0xffffffff,
763 "Initial length escape value indicating 64-bit DWARF extension");
764 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
765 "Length of Common Information Entry");
766 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
768 /* Now that the CIE pointer is PC-relative for EH,
769 use 0 to identify the CIE. */
770 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
771 (for_eh
? 0 : DWARF_CIE_ID
),
772 "CIE Identifier Tag");
774 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
775 use CIE version 1, unless that would produce incorrect results
776 due to overflowing the return register column. */
777 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
779 if (return_reg
>= 256 || dwarf_version
> 2)
781 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
784 augmentation_size
= 0;
786 personality
= current_unit_personality
;
792 z Indicates that a uleb128 is present to size the
793 augmentation section.
794 L Indicates the encoding (and thus presence) of
795 an LSDA pointer in the FDE augmentation.
796 R Indicates a non-default pointer encoding for
798 P Indicates the presence of an encoding + language
799 personality routine in the CIE augmentation. */
801 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
802 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
803 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
805 p
= augmentation
+ 1;
809 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
810 assemble_external_libcall (personality
);
815 augmentation_size
+= 1;
817 if (fde_encoding
!= DW_EH_PE_absptr
)
820 augmentation_size
+= 1;
822 if (p
> augmentation
+ 1)
824 augmentation
[0] = 'z';
828 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
829 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
831 int offset
= ( 4 /* Length */
833 + 1 /* CIE version */
834 + strlen (augmentation
) + 1 /* Augmentation */
835 + size_of_uleb128 (1) /* Code alignment */
836 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
838 + 1 /* Augmentation size */
839 + 1 /* Personality encoding */ );
840 int pad
= -offset
& (PTR_SIZE
- 1);
842 augmentation_size
+= pad
;
844 /* Augmentations should be small, so there's scarce need to
845 iterate for a solution. Die if we exceed one uleb128 byte. */
846 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
850 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
851 if (dw_cie_version
>= 4)
853 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
854 dw2_asm_output_data (1, 0, "CIE Segment Size");
856 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
857 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
858 "CIE Data Alignment Factor");
860 if (dw_cie_version
== 1)
861 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
863 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
867 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
870 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
871 eh_data_format_name (per_encoding
));
872 dw2_asm_output_encoded_addr_rtx (per_encoding
,
878 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
879 eh_data_format_name (lsda_encoding
));
881 if (fde_encoding
!= DW_EH_PE_absptr
)
882 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
883 eh_data_format_name (fde_encoding
));
886 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
887 output_cfi (cfi
, NULL
, for_eh
);
889 /* Pad the CIE out to an address sized boundary. */
890 ASM_OUTPUT_ALIGN (asm_out_file
,
891 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
892 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
894 /* Loop through all of the FDE's. */
895 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
899 /* Don't emit EH unwind info for leaf functions that don't need it. */
900 if (for_eh
&& !fde_needed_for_eh_p (fde
))
903 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
904 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
905 augmentation
, any_lsda_needed
, lsda_encoding
);
908 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
909 dw2_asm_output_data (4, 0, "End of Table");
911 /* Turn off app to make assembly quicker. */
916 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
919 dwarf2out_do_cfi_startproc (bool second
)
923 rtx personality
= get_personality_function (current_function_decl
);
925 fprintf (asm_out_file
, "\t.cfi_startproc\n");
929 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
932 /* ??? The GAS support isn't entirely consistent. We have to
933 handle indirect support ourselves, but PC-relative is done
934 in the assembler. Further, the assembler can't handle any
935 of the weirder relocation types. */
936 if (enc
& DW_EH_PE_indirect
)
937 ref
= dw2_force_const_mem (ref
, true);
939 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
940 output_addr_const (asm_out_file
, ref
);
941 fputc ('\n', asm_out_file
);
944 if (crtl
->uses_eh_lsda
)
948 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
949 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
950 FUNC_LABEL_ID (cfun
));
951 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
952 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
954 if (enc
& DW_EH_PE_indirect
)
955 ref
= dw2_force_const_mem (ref
, true);
957 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
958 output_addr_const (asm_out_file
, ref
);
959 fputc ('\n', asm_out_file
);
963 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
964 this allocation may be done before pass_final. */
967 dwarf2out_alloc_current_fde (void)
971 fde
= ggc_alloc_cleared_dw_fde_node ();
972 fde
->decl
= current_function_decl
;
973 fde
->funcdef_number
= FUNC_LABEL_ID (cfun
);
974 fde
->fde_index
= vec_safe_length (fde_vec
);
975 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
976 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
977 fde
->nothrow
= crtl
->nothrow
;
978 fde
->drap_reg
= INVALID_REGNUM
;
979 fde
->vdrap_reg
= INVALID_REGNUM
;
981 /* Record the FDE associated with this function. */
983 vec_safe_push (fde_vec
, fde
);
988 /* Output a marker (i.e. a label) for the beginning of a function, before
992 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
993 const char *file ATTRIBUTE_UNUSED
)
995 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1001 current_function_func_begin_label
= NULL
;
1003 do_frame
= dwarf2out_do_frame ();
1005 /* ??? current_function_func_begin_label is also used by except.c for
1006 call-site information. We must emit this label if it might be used. */
1008 && (!flag_exceptions
1009 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1012 fnsec
= function_section (current_function_decl
);
1013 switch_to_section (fnsec
);
1014 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1015 FUNC_LABEL_ID (cfun
));
1016 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1017 FUNC_LABEL_ID (cfun
));
1018 dup_label
= xstrdup (label
);
1019 current_function_func_begin_label
= dup_label
;
1021 /* We can elide the fde allocation if we're not emitting debug info. */
1025 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1026 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1027 would include pass_dwarf2_frame. If we've not created the FDE yet,
1031 fde
= dwarf2out_alloc_current_fde ();
1033 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1034 fde
->dw_fde_begin
= dup_label
;
1035 fde
->dw_fde_current_label
= dup_label
;
1036 fde
->in_std_section
= (fnsec
== text_section
1037 || (cold_text_section
&& fnsec
== cold_text_section
));
1039 /* We only want to output line number information for the genuine dwarf2
1040 prologue case, not the eh frame case. */
1041 #ifdef DWARF2_DEBUGGING_INFO
1043 dwarf2out_source_line (line
, file
, 0, true);
1046 if (dwarf2out_do_cfi_asm ())
1047 dwarf2out_do_cfi_startproc (false);
1050 rtx personality
= get_personality_function (current_function_decl
);
1051 if (!current_unit_personality
)
1052 current_unit_personality
= personality
;
1054 /* We cannot keep a current personality per function as without CFI
1055 asm, at the point where we emit the CFI data, there is no current
1056 function anymore. */
1057 if (personality
&& current_unit_personality
!= personality
)
1058 sorry ("multiple EH personalities are supported only with assemblers "
1059 "supporting .cfi_personality directive");
1063 /* Output a marker (i.e. a label) for the end of the generated code
1064 for a function prologue. This gets called *after* the prologue code has
1068 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1069 const char *file ATTRIBUTE_UNUSED
)
1071 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1073 /* Output a label to mark the endpoint of the code generated for this
1075 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1076 FUNC_LABEL_ID (cfun
));
1077 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1078 FUNC_LABEL_ID (cfun
));
1079 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1082 /* Output a marker (i.e. a label) for the beginning of the generated code
1083 for a function epilogue. This gets called *before* the prologue code has
1087 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1088 const char *file ATTRIBUTE_UNUSED
)
1090 dw_fde_ref fde
= cfun
->fde
;
1091 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1093 if (fde
->dw_fde_vms_begin_epilogue
)
1096 /* Output a label to mark the endpoint of the code generated for this
1098 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1099 FUNC_LABEL_ID (cfun
));
1100 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1101 FUNC_LABEL_ID (cfun
));
1102 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1105 /* Output a marker (i.e. a label) for the absolute end of the generated code
1106 for a function definition. This gets called *after* the epilogue code has
1110 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1111 const char *file ATTRIBUTE_UNUSED
)
1114 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1116 last_var_location_insn
= NULL_RTX
;
1117 cached_next_real_insn
= NULL_RTX
;
1119 if (dwarf2out_do_cfi_asm ())
1120 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1122 /* Output a label to mark the endpoint of the code generated for this
1124 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1125 FUNC_LABEL_ID (cfun
));
1126 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1128 gcc_assert (fde
!= NULL
);
1129 if (fde
->dw_fde_second_begin
== NULL
)
1130 fde
->dw_fde_end
= xstrdup (label
);
1134 dwarf2out_frame_finish (void)
1136 /* Output call frame information. */
1137 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1138 output_call_frame_info (0);
1140 /* Output another copy for the unwinder. */
1141 if ((flag_unwind_tables
|| flag_exceptions
)
1142 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1143 output_call_frame_info (1);
1146 /* Note that the current function section is being used for code. */
1149 dwarf2out_note_section_used (void)
1151 section
*sec
= current_function_section ();
1152 if (sec
== text_section
)
1153 text_section_used
= true;
1154 else if (sec
== cold_text_section
)
1155 cold_text_section_used
= true;
1158 static void var_location_switch_text_section (void);
1159 static void set_cur_line_info_table (section
*);
1162 dwarf2out_switch_text_section (void)
1165 dw_fde_ref fde
= cfun
->fde
;
1167 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1169 if (!in_cold_section_p
)
1171 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1172 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1173 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1177 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1178 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1179 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1181 have_multiple_function_sections
= true;
1183 /* There is no need to mark used sections when not debugging. */
1184 if (cold_text_section
!= NULL
)
1185 dwarf2out_note_section_used ();
1187 if (dwarf2out_do_cfi_asm ())
1188 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1190 /* Now do the real section switch. */
1191 sect
= current_function_section ();
1192 switch_to_section (sect
);
1194 fde
->second_in_std_section
1195 = (sect
== text_section
1196 || (cold_text_section
&& sect
== cold_text_section
));
1198 if (dwarf2out_do_cfi_asm ())
1199 dwarf2out_do_cfi_startproc (true);
1201 var_location_switch_text_section ();
1203 if (cold_text_section
!= NULL
)
1204 set_cur_line_info_table (sect
);
1207 /* And now, the subset of the debugging information support code necessary
1208 for emitting location expressions. */
1210 /* Data about a single source file. */
1211 struct GTY(()) dwarf_file_data
{
1212 const char * filename
;
1216 typedef struct GTY(()) deferred_locations_struct
1220 } deferred_locations
;
1223 static GTY(()) vec
<deferred_locations
, va_gc
> *deferred_locations_list
;
1226 /* Describe an entry into the .debug_addr section. */
1230 ate_kind_rtx_dtprel
,
1234 typedef struct GTY(()) addr_table_entry_struct
{
1236 unsigned int refcount
;
1238 union addr_table_entry_struct_union
1240 rtx
GTY ((tag ("0"))) rtl
;
1241 char * GTY ((tag ("1"))) label
;
1243 GTY ((desc ("%1.kind"))) addr
;
1247 /* Location lists are ranges + location descriptions for that range,
1248 so you can track variables that are in different places over
1249 their entire life. */
1250 typedef struct GTY(()) dw_loc_list_struct
{
1251 dw_loc_list_ref dw_loc_next
;
1252 const char *begin
; /* Label and addr_entry for start of range */
1253 addr_table_entry
*begin_entry
;
1254 const char *end
; /* Label for end of range */
1255 char *ll_symbol
; /* Label for beginning of location list.
1256 Only on head of list */
1257 const char *section
; /* Section this loclist is relative to */
1258 dw_loc_descr_ref expr
;
1260 /* True if all addresses in this and subsequent lists are known to be
1263 /* True if this list has been replaced by dw_loc_next. */
1266 /* True if the range should be emitted even if begin and end
1271 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1273 /* Convert a DWARF stack opcode into its string name. */
1276 dwarf_stack_op_name (unsigned int op
)
1278 const char *name
= get_DW_OP_name (op
);
1283 return "OP_<unknown>";
1286 /* Return a pointer to a newly allocated location description. Location
1287 descriptions are simple expression terms that can be strung
1288 together to form more complicated location (address) descriptions. */
1290 static inline dw_loc_descr_ref
1291 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1292 unsigned HOST_WIDE_INT oprnd2
)
1294 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
1296 descr
->dw_loc_opc
= op
;
1297 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1298 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1299 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1300 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1301 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1302 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1307 /* Return a pointer to a newly allocated location description for
1310 static inline dw_loc_descr_ref
1311 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1314 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1317 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1320 /* Add a location description term to a location description expression. */
1323 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1325 dw_loc_descr_ref
*d
;
1327 /* Find the end of the chain. */
1328 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1334 /* Compare two location operands for exact equality. */
1337 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1339 if (a
->val_class
!= b
->val_class
)
1341 switch (a
->val_class
)
1343 case dw_val_class_none
:
1345 case dw_val_class_addr
:
1346 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1348 case dw_val_class_offset
:
1349 case dw_val_class_unsigned_const
:
1350 case dw_val_class_const
:
1351 case dw_val_class_range_list
:
1352 case dw_val_class_lineptr
:
1353 case dw_val_class_macptr
:
1354 /* These are all HOST_WIDE_INT, signed or unsigned. */
1355 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1357 case dw_val_class_loc
:
1358 return a
->v
.val_loc
== b
->v
.val_loc
;
1359 case dw_val_class_loc_list
:
1360 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1361 case dw_val_class_die_ref
:
1362 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1363 case dw_val_class_fde_ref
:
1364 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1365 case dw_val_class_lbl_id
:
1366 case dw_val_class_high_pc
:
1367 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1368 case dw_val_class_str
:
1369 return a
->v
.val_str
== b
->v
.val_str
;
1370 case dw_val_class_flag
:
1371 return a
->v
.val_flag
== b
->v
.val_flag
;
1372 case dw_val_class_file
:
1373 return a
->v
.val_file
== b
->v
.val_file
;
1374 case dw_val_class_decl_ref
:
1375 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1377 case dw_val_class_const_double
:
1378 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1379 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1381 case dw_val_class_vec
:
1383 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1384 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1386 return (a_len
== b_len
1387 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1390 case dw_val_class_data8
:
1391 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1393 case dw_val_class_vms_delta
:
1394 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1395 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1400 /* Compare two location atoms for exact equality. */
1403 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1405 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1408 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1409 address size, but since we always allocate cleared storage it
1410 should be zero for other types of locations. */
1411 if (a
->dtprel
!= b
->dtprel
)
1414 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1415 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1418 /* Compare two complete location expressions for exact equality. */
1421 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1427 if (a
== NULL
|| b
== NULL
)
1429 if (!loc_descr_equal_p_1 (a
, b
))
1438 /* Add a constant OFFSET to a location expression. */
1441 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1443 dw_loc_descr_ref loc
;
1446 gcc_assert (*list_head
!= NULL
);
1451 /* Find the end of the chain. */
1452 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1456 if (loc
->dw_loc_opc
== DW_OP_fbreg
1457 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1458 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1459 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1460 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1462 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1463 offset. Don't optimize if an signed integer overflow would happen. */
1465 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1466 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1469 else if (offset
> 0)
1470 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1474 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1475 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1479 /* Add a constant OFFSET to a location list. */
1482 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1485 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1486 loc_descr_plus_const (&d
->expr
, offset
);
1489 #define DWARF_REF_SIZE \
1490 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1492 static unsigned long int get_base_type_offset (dw_die_ref
);
1494 /* Return the size of a location descriptor. */
1496 static unsigned long
1497 size_of_loc_descr (dw_loc_descr_ref loc
)
1499 unsigned long size
= 1;
1501 switch (loc
->dw_loc_opc
)
1504 size
+= DWARF2_ADDR_SIZE
;
1506 case DW_OP_GNU_addr_index
:
1507 case DW_OP_GNU_const_index
:
1508 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1509 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1528 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1531 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1536 case DW_OP_plus_uconst
:
1537 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1575 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1578 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1581 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1584 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1585 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1588 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1590 case DW_OP_bit_piece
:
1591 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1592 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1594 case DW_OP_deref_size
:
1595 case DW_OP_xderef_size
:
1604 case DW_OP_call_ref
:
1605 size
+= DWARF_REF_SIZE
;
1607 case DW_OP_implicit_value
:
1608 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1609 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1611 case DW_OP_GNU_implicit_pointer
:
1612 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1614 case DW_OP_GNU_entry_value
:
1616 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1617 size
+= size_of_uleb128 (op_size
) + op_size
;
1620 case DW_OP_GNU_const_type
:
1623 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1624 size
+= size_of_uleb128 (o
) + 1;
1625 switch (loc
->dw_loc_oprnd2
.val_class
)
1627 case dw_val_class_vec
:
1628 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1629 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1631 case dw_val_class_const
:
1632 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1634 case dw_val_class_const_double
:
1635 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1642 case DW_OP_GNU_regval_type
:
1645 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1646 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1647 + size_of_uleb128 (o
);
1650 case DW_OP_GNU_deref_type
:
1653 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1654 size
+= 1 + size_of_uleb128 (o
);
1657 case DW_OP_GNU_convert
:
1658 case DW_OP_GNU_reinterpret
:
1659 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1660 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1664 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1665 size
+= size_of_uleb128 (o
);
1668 case DW_OP_GNU_parameter_ref
:
1678 /* Return the size of a series of location descriptors. */
1681 size_of_locs (dw_loc_descr_ref loc
)
1686 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1687 field, to avoid writing to a PCH file. */
1688 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1690 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1692 size
+= size_of_loc_descr (l
);
1697 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1699 l
->dw_loc_addr
= size
;
1700 size
+= size_of_loc_descr (l
);
1706 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1707 static void get_ref_die_offset_label (char *, dw_die_ref
);
1708 static unsigned long int get_ref_die_offset (dw_die_ref
);
1710 /* Output location description stack opcode's operands (if any).
1711 The for_eh_or_skip parameter controls whether register numbers are
1712 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1713 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1714 info). This should be suppressed for the cases that have not been converted
1715 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1718 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1720 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1721 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1723 switch (loc
->dw_loc_opc
)
1725 #ifdef DWARF2_DEBUGGING_INFO
1728 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1733 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1734 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1736 fputc ('\n', asm_out_file
);
1741 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1746 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1747 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1749 fputc ('\n', asm_out_file
);
1754 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1755 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1762 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1763 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1765 dw2_asm_output_data (2, offset
, NULL
);
1768 case DW_OP_implicit_value
:
1769 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1770 switch (val2
->val_class
)
1772 case dw_val_class_const
:
1773 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1775 case dw_val_class_vec
:
1777 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1778 unsigned int len
= val2
->v
.val_vec
.length
;
1782 if (elt_size
> sizeof (HOST_WIDE_INT
))
1787 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1790 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1791 "fp or vector constant word %u", i
);
1794 case dw_val_class_const_double
:
1796 unsigned HOST_WIDE_INT first
, second
;
1798 if (WORDS_BIG_ENDIAN
)
1800 first
= val2
->v
.val_double
.high
;
1801 second
= val2
->v
.val_double
.low
;
1805 first
= val2
->v
.val_double
.low
;
1806 second
= val2
->v
.val_double
.high
;
1808 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1810 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1814 case dw_val_class_addr
:
1815 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1816 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1831 case DW_OP_implicit_value
:
1832 /* We currently don't make any attempt to make sure these are
1833 aligned properly like we do for the main unwind info, so
1834 don't support emitting things larger than a byte if we're
1835 only doing unwinding. */
1840 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1843 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1846 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1849 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1851 case DW_OP_plus_uconst
:
1852 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1886 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1890 unsigned r
= val1
->v
.val_unsigned
;
1891 if (for_eh_or_skip
>= 0)
1892 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1893 gcc_assert (size_of_uleb128 (r
)
1894 == size_of_uleb128 (val1
->v
.val_unsigned
));
1895 dw2_asm_output_data_uleb128 (r
, NULL
);
1899 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1903 unsigned r
= val1
->v
.val_unsigned
;
1904 if (for_eh_or_skip
>= 0)
1905 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1906 gcc_assert (size_of_uleb128 (r
)
1907 == size_of_uleb128 (val1
->v
.val_unsigned
));
1908 dw2_asm_output_data_uleb128 (r
, NULL
);
1909 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1913 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1915 case DW_OP_bit_piece
:
1916 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1917 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1919 case DW_OP_deref_size
:
1920 case DW_OP_xderef_size
:
1921 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1927 if (targetm
.asm_out
.output_dwarf_dtprel
)
1929 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1932 fputc ('\n', asm_out_file
);
1939 #ifdef DWARF2_DEBUGGING_INFO
1940 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
1947 case DW_OP_GNU_addr_index
:
1948 case DW_OP_GNU_const_index
:
1949 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1950 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
1951 "(index into .debug_addr)");
1954 case DW_OP_GNU_implicit_pointer
:
1956 char label
[MAX_ARTIFICIAL_LABEL_BYTES
1957 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
1958 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
1959 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
1960 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
1961 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1965 case DW_OP_GNU_entry_value
:
1966 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
1967 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
1970 case DW_OP_GNU_const_type
:
1972 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
1974 dw2_asm_output_data_uleb128 (o
, NULL
);
1975 switch (val2
->val_class
)
1977 case dw_val_class_const
:
1978 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
1979 dw2_asm_output_data (1, l
, NULL
);
1980 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
1982 case dw_val_class_vec
:
1984 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1985 unsigned int len
= val2
->v
.val_vec
.length
;
1990 dw2_asm_output_data (1, l
, NULL
);
1991 if (elt_size
> sizeof (HOST_WIDE_INT
))
1996 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1999 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2000 "fp or vector constant word %u", i
);
2003 case dw_val_class_const_double
:
2005 unsigned HOST_WIDE_INT first
, second
;
2006 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2008 dw2_asm_output_data (1, 2 * l
, NULL
);
2009 if (WORDS_BIG_ENDIAN
)
2011 first
= val2
->v
.val_double
.high
;
2012 second
= val2
->v
.val_double
.low
;
2016 first
= val2
->v
.val_double
.low
;
2017 second
= val2
->v
.val_double
.high
;
2019 dw2_asm_output_data (l
, first
, NULL
);
2020 dw2_asm_output_data (l
, second
, NULL
);
2028 case DW_OP_GNU_regval_type
:
2030 unsigned r
= val1
->v
.val_unsigned
;
2031 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2033 if (for_eh_or_skip
>= 0)
2035 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2036 gcc_assert (size_of_uleb128 (r
)
2037 == size_of_uleb128 (val1
->v
.val_unsigned
));
2039 dw2_asm_output_data_uleb128 (r
, NULL
);
2040 dw2_asm_output_data_uleb128 (o
, NULL
);
2043 case DW_OP_GNU_deref_type
:
2045 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2047 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2048 dw2_asm_output_data_uleb128 (o
, NULL
);
2051 case DW_OP_GNU_convert
:
2052 case DW_OP_GNU_reinterpret
:
2053 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2054 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2057 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2059 dw2_asm_output_data_uleb128 (o
, NULL
);
2063 case DW_OP_GNU_parameter_ref
:
2066 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2067 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2068 dw2_asm_output_data (4, o
, NULL
);
2073 /* Other codes have no operands. */
2078 /* Output a sequence of location operations.
2079 The for_eh_or_skip parameter controls whether register numbers are
2080 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2081 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2082 info). This should be suppressed for the cases that have not been converted
2083 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2086 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2088 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2090 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2091 /* Output the opcode. */
2092 if (for_eh_or_skip
>= 0
2093 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2095 unsigned r
= (opc
- DW_OP_breg0
);
2096 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2097 gcc_assert (r
<= 31);
2098 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2100 else if (for_eh_or_skip
>= 0
2101 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2103 unsigned r
= (opc
- DW_OP_reg0
);
2104 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2105 gcc_assert (r
<= 31);
2106 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2109 dw2_asm_output_data (1, opc
,
2110 "%s", dwarf_stack_op_name (opc
));
2112 /* Output the operand(s) (if any). */
2113 output_loc_operands (loc
, for_eh_or_skip
);
2117 /* Output location description stack opcode's operands (if any).
2118 The output is single bytes on a line, suitable for .cfi_escape. */
2121 output_loc_operands_raw (dw_loc_descr_ref loc
)
2123 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2124 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2126 switch (loc
->dw_loc_opc
)
2129 case DW_OP_GNU_addr_index
:
2130 case DW_OP_GNU_const_index
:
2131 case DW_OP_implicit_value
:
2132 /* We cannot output addresses in .cfi_escape, only bytes. */
2138 case DW_OP_deref_size
:
2139 case DW_OP_xderef_size
:
2140 fputc (',', asm_out_file
);
2141 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2146 fputc (',', asm_out_file
);
2147 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2152 fputc (',', asm_out_file
);
2153 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2158 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2159 fputc (',', asm_out_file
);
2160 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2168 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2169 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2171 fputc (',', asm_out_file
);
2172 dw2_asm_output_data_raw (2, offset
);
2178 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2179 gcc_assert (size_of_uleb128 (r
)
2180 == size_of_uleb128 (val1
->v
.val_unsigned
));
2181 fputc (',', asm_out_file
);
2182 dw2_asm_output_data_uleb128_raw (r
);
2187 case DW_OP_plus_uconst
:
2189 fputc (',', asm_out_file
);
2190 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2193 case DW_OP_bit_piece
:
2194 fputc (',', asm_out_file
);
2195 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2196 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2233 fputc (',', asm_out_file
);
2234 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2239 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2240 gcc_assert (size_of_uleb128 (r
)
2241 == size_of_uleb128 (val1
->v
.val_unsigned
));
2242 fputc (',', asm_out_file
);
2243 dw2_asm_output_data_uleb128_raw (r
);
2244 fputc (',', asm_out_file
);
2245 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2249 case DW_OP_GNU_implicit_pointer
:
2250 case DW_OP_GNU_entry_value
:
2251 case DW_OP_GNU_const_type
:
2252 case DW_OP_GNU_regval_type
:
2253 case DW_OP_GNU_deref_type
:
2254 case DW_OP_GNU_convert
:
2255 case DW_OP_GNU_reinterpret
:
2256 case DW_OP_GNU_parameter_ref
:
2261 /* Other codes have no operands. */
2267 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2271 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2272 /* Output the opcode. */
2273 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2275 unsigned r
= (opc
- DW_OP_breg0
);
2276 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2277 gcc_assert (r
<= 31);
2278 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2280 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2282 unsigned r
= (opc
- DW_OP_reg0
);
2283 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2284 gcc_assert (r
<= 31);
2285 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2287 /* Output the opcode. */
2288 fprintf (asm_out_file
, "%#x", opc
);
2289 output_loc_operands_raw (loc
);
2291 if (!loc
->dw_loc_next
)
2293 loc
= loc
->dw_loc_next
;
2295 fputc (',', asm_out_file
);
2299 /* This function builds a dwarf location descriptor sequence from a
2300 dw_cfa_location, adding the given OFFSET to the result of the
2303 struct dw_loc_descr_struct
*
2304 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2306 struct dw_loc_descr_struct
*head
, *tmp
;
2308 offset
+= cfa
->offset
;
2312 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2313 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2314 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2315 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2316 add_loc_descr (&head
, tmp
);
2319 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2320 add_loc_descr (&head
, tmp
);
2324 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2329 /* This function builds a dwarf location descriptor sequence for
2330 the address at OFFSET from the CFA when stack is aligned to
2333 struct dw_loc_descr_struct
*
2334 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2335 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2337 struct dw_loc_descr_struct
*head
;
2338 unsigned int dwarf_fp
2339 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2341 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2342 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2344 head
= new_reg_loc_descr (dwarf_fp
, 0);
2345 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2346 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2347 loc_descr_plus_const (&head
, offset
);
2350 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2354 /* And now, the support for symbolic debugging information. */
2356 /* .debug_str support. */
2357 static int output_indirect_string (void **, void *);
2359 static void dwarf2out_init (const char *);
2360 static void dwarf2out_finish (const char *);
2361 static void dwarf2out_assembly_start (void);
2362 static void dwarf2out_define (unsigned int, const char *);
2363 static void dwarf2out_undef (unsigned int, const char *);
2364 static void dwarf2out_start_source_file (unsigned, const char *);
2365 static void dwarf2out_end_source_file (unsigned);
2366 static void dwarf2out_function_decl (tree
);
2367 static void dwarf2out_begin_block (unsigned, unsigned);
2368 static void dwarf2out_end_block (unsigned, unsigned);
2369 static bool dwarf2out_ignore_block (const_tree
);
2370 static void dwarf2out_global_decl (tree
);
2371 static void dwarf2out_type_decl (tree
, int);
2372 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2373 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2375 static void dwarf2out_abstract_function (tree
);
2376 static void dwarf2out_var_location (rtx
);
2377 static void dwarf2out_begin_function (tree
);
2378 static void dwarf2out_end_function (unsigned int);
2379 static void dwarf2out_set_name (tree
, tree
);
2381 /* The debug hooks structure. */
2383 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2387 dwarf2out_assembly_start
,
2390 dwarf2out_start_source_file
,
2391 dwarf2out_end_source_file
,
2392 dwarf2out_begin_block
,
2393 dwarf2out_end_block
,
2394 dwarf2out_ignore_block
,
2395 dwarf2out_source_line
,
2396 dwarf2out_begin_prologue
,
2397 #if VMS_DEBUGGING_INFO
2398 dwarf2out_vms_end_prologue
,
2399 dwarf2out_vms_begin_epilogue
,
2401 debug_nothing_int_charstar
,
2402 debug_nothing_int_charstar
,
2404 dwarf2out_end_epilogue
,
2405 dwarf2out_begin_function
,
2406 dwarf2out_end_function
, /* end_function */
2407 dwarf2out_function_decl
, /* function_decl */
2408 dwarf2out_global_decl
,
2409 dwarf2out_type_decl
, /* type_decl */
2410 dwarf2out_imported_module_or_decl
,
2411 debug_nothing_tree
, /* deferred_inline_function */
2412 /* The DWARF 2 backend tries to reduce debugging bloat by not
2413 emitting the abstract description of inline functions until
2414 something tries to reference them. */
2415 dwarf2out_abstract_function
, /* outlining_inline_function */
2416 debug_nothing_rtx
, /* label */
2417 debug_nothing_int
, /* handle_pch */
2418 dwarf2out_var_location
,
2419 dwarf2out_switch_text_section
,
2421 1, /* start_end_main_source_file */
2422 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2425 const struct gcc_debug_hooks auto_profile_debug_hooks
=
2427 debug_nothing_charstar
,
2428 debug_nothing_charstar
,
2430 debug_nothing_int_charstar
,
2431 debug_nothing_int_charstar
,
2432 debug_nothing_int_charstar
,
2434 debug_nothing_int_int
, /* begin_block */
2435 debug_nothing_int_int
, /* end_block */
2436 dwarf2out_ignore_block
, /* ignore_block */
2437 debug_nothing_int_charstar_int_bool
, /* source_line */
2438 debug_nothing_int_charstar
, /* begin_prologue */
2439 debug_nothing_int_charstar
, /* end_prologue */
2440 debug_nothing_int_charstar
, /* begin_epilogue */
2441 debug_nothing_int_charstar
, /* end_epilogue */
2442 debug_nothing_tree
, /* begin_function */
2443 debug_nothing_int
, /* end_function */
2444 debug_nothing_tree
, /* function_decl */
2445 debug_nothing_tree
, /* global_decl */
2446 debug_nothing_tree_int
, /* type_decl */
2447 debug_nothing_tree_tree_tree_bool
, /* imported_module_or_decl */
2448 debug_nothing_tree
, /* deferred_inline_function */
2449 debug_nothing_tree
, /* outlining_inline_function */
2450 debug_nothing_rtx
, /* label */
2451 debug_nothing_int
, /* handle_pch */
2452 debug_nothing_rtx
, /* var_location */
2453 debug_nothing_void
, /* switch_text_section */
2454 debug_nothing_tree_tree
, /* set_name */
2455 0, /* start_end_main_source_file */
2456 TYPE_SYMTAB_IS_ADDRESS
/* tree_type_symtab_field */
2460 /* NOTE: In the comments in this file, many references are made to
2461 "Debugging Information Entries". This term is abbreviated as `DIE'
2462 throughout the remainder of this file. */
2464 /* An internal representation of the DWARF output is built, and then
2465 walked to generate the DWARF debugging info. The walk of the internal
2466 representation is done after the entire program has been compiled.
2467 The types below are used to describe the internal representation. */
2469 /* Whether to put type DIEs into their own section .debug_types instead
2470 of making them part of the .debug_info section. Only supported for
2471 Dwarf V4 or higher and the user didn't disable them through
2472 -fno-debug-types-section. It is more efficient to put them in a
2473 separate comdat sections since the linker will then be able to
2474 remove duplicates. But not all tools support .debug_types sections
2477 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2479 /* Various DIE's use offsets relative to the beginning of the
2480 .debug_info section to refer to each other. */
2482 typedef long int dw_offset
;
2484 /* Define typedefs here to avoid circular dependencies. */
2486 typedef struct dw_attr_struct
*dw_attr_ref
;
2487 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2488 typedef struct pubname_struct
*pubname_ref
;
2489 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2490 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2491 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2493 /* The entries in the line_info table more-or-less mirror the opcodes
2494 that are used in the real dwarf line table. Arrays of these entries
2495 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2498 enum dw_line_info_opcode
{
2499 /* Emit DW_LNE_set_address; the operand is the label index. */
2502 /* Emit a row to the matrix with the given line. This may be done
2503 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2507 /* Emit a DW_LNS_set_file. */
2510 /* Emit a DW_LNS_set_column. */
2513 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2516 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2517 LI_set_prologue_end
,
2518 LI_set_epilogue_begin
,
2520 /* Emit a DW_LNE_set_discriminator. */
2521 LI_set_discriminator
2524 typedef struct GTY(()) dw_line_info_struct
{
2525 enum dw_line_info_opcode opcode
;
2527 } dw_line_info_entry
;
2530 typedef struct GTY(()) dw_line_info_table_struct
{
2531 /* The label that marks the end of this section. */
2532 const char *end_label
;
2534 /* The values for the last row of the matrix, as collected in the table.
2535 These are used to minimize the changes to the next row. */
2536 unsigned int file_num
;
2537 unsigned int line_num
;
2538 unsigned int column_num
;
2543 vec
<dw_line_info_entry
, va_gc
> *entries
;
2544 } dw_line_info_table
;
2546 typedef dw_line_info_table
*dw_line_info_table_p
;
2549 /* Each DIE attribute has a field specifying the attribute kind,
2550 a link to the next attribute in the chain, and an attribute value.
2551 Attributes are typically linked below the DIE they modify. */
2553 typedef struct GTY(()) dw_attr_struct
{
2554 enum dwarf_attribute dw_attr
;
2555 dw_val_node dw_attr_val
;
2560 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2561 The children of each node form a circular list linked by
2562 die_sib. die_child points to the node *before* the "first" child node. */
2564 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
2565 union die_symbol_or_type_node
2567 const char * GTY ((tag ("0"))) die_symbol
;
2568 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2570 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2571 vec
<dw_attr_node
, va_gc
> *die_attr
;
2572 dw_die_ref die_parent
;
2573 dw_die_ref die_child
;
2575 dw_die_ref die_definition
; /* ref from a specification to its definition */
2576 dw_offset die_offset
;
2577 unsigned long die_abbrev
;
2579 unsigned int decl_id
;
2580 enum dwarf_tag die_tag
;
2581 /* Die is used and must not be pruned as unused. */
2582 BOOL_BITFIELD die_perennial_p
: 1;
2583 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2584 /* Lots of spare bits. */
2588 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2589 #define FOR_EACH_CHILD(die, c, expr) do { \
2590 c = die->die_child; \
2594 } while (c != die->die_child); \
2597 /* The pubname structure */
2599 typedef struct GTY(()) pubname_struct
{
2606 struct GTY(()) dw_ranges_struct
{
2607 /* If this is positive, it's a block number, otherwise it's a
2608 bitwise-negated index into dw_ranges_by_label. */
2612 /* A structure to hold a macinfo entry. */
2614 typedef struct GTY(()) macinfo_struct
{
2616 unsigned HOST_WIDE_INT lineno
;
2622 struct GTY(()) dw_ranges_by_label_struct
{
2627 /* The comdat type node structure. */
2628 typedef struct GTY(()) comdat_type_struct
2630 dw_die_ref root_die
;
2631 dw_die_ref type_die
;
2632 dw_die_ref skeleton_die
;
2633 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2634 struct comdat_type_struct
*next
;
2638 /* The limbo die list structure. */
2639 typedef struct GTY(()) limbo_die_struct
{
2642 struct limbo_die_struct
*next
;
2646 typedef struct skeleton_chain_struct
2650 struct skeleton_chain_struct
*parent
;
2652 skeleton_chain_node
;
2654 /* Define a macro which returns nonzero for a TYPE_DECL which was
2655 implicitly generated for a type.
2657 Note that, unlike the C front-end (which generates a NULL named
2658 TYPE_DECL node for each complete tagged type, each array type,
2659 and each function type node created) the C++ front-end generates
2660 a _named_ TYPE_DECL node for each tagged type node created.
2661 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2662 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2663 front-end, but for each type, tagged or not. */
2665 #define TYPE_DECL_IS_STUB(decl) \
2666 (DECL_NAME (decl) == NULL_TREE \
2667 || (DECL_ARTIFICIAL (decl) \
2668 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2669 /* This is necessary for stub decls that \
2670 appear in nested inline functions. */ \
2671 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2672 && (decl_ultimate_origin (decl) \
2673 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2675 /* Information concerning the compilation unit's programming
2676 language, and compiler version. */
2678 /* Fixed size portion of the DWARF compilation unit header. */
2679 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2680 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2682 /* Fixed size portion of the DWARF comdat type unit header. */
2683 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2684 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2685 + DWARF_OFFSET_SIZE)
2687 /* Fixed size portion of public names info. */
2688 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2690 /* Fixed size portion of the address range info. */
2691 #define DWARF_ARANGES_HEADER_SIZE \
2692 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2693 DWARF2_ADDR_SIZE * 2) \
2694 - DWARF_INITIAL_LENGTH_SIZE)
2696 /* Size of padding portion in the address range info. It must be
2697 aligned to twice the pointer size. */
2698 #define DWARF_ARANGES_PAD_SIZE \
2699 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2700 DWARF2_ADDR_SIZE * 2) \
2701 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2703 /* Use assembler line directives if available. */
2704 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2705 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2706 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2708 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2712 /* Minimum line offset in a special line info. opcode.
2713 This value was chosen to give a reasonable range of values. */
2714 #define DWARF_LINE_BASE -10
2716 /* First special line opcode - leave room for the standard opcodes. */
2717 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2719 /* Range of line offsets in a special line info. opcode. */
2720 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2722 /* Flag that indicates the initial value of the is_stmt_start flag.
2723 In the present implementation, we do not mark any lines as
2724 the beginning of a source statement, because that information
2725 is not made available by the GCC front-end. */
2726 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2728 /* Maximum number of operations per instruction bundle. */
2729 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2730 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2733 /* This location is used by calc_die_sizes() to keep track
2734 the offset of each DIE within the .debug_info section. */
2735 static unsigned long next_die_offset
;
2737 /* Record the root of the DIE's built for the current compilation unit. */
2738 static GTY(()) dw_die_ref single_comp_unit_die
;
2740 /* A list of type DIEs that have been separated into comdat sections. */
2741 static GTY(()) comdat_type_node
*comdat_type_list
;
2743 /* A list of DIEs with a NULL parent waiting to be relocated. */
2744 static GTY(()) limbo_die_node
*limbo_die_list
;
2746 /* A list of DIEs for which we may have to generate
2747 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2748 static GTY(()) limbo_die_node
*deferred_asm_name
;
2750 /* Filenames referenced by this compilation unit. */
2751 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
2753 /* A hash table of references to DIE's that describe declarations.
2754 The key is a DECL_UID() which is a unique number identifying each decl. */
2755 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
2757 /* A hash table of references to DIE's that describe COMMON blocks.
2758 The key is DECL_UID() ^ die_parent. */
2759 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
2761 typedef struct GTY(()) die_arg_entry_struct
{
2767 /* Node of the variable location list. */
2768 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2769 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2770 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2771 in mode of the EXPR_LIST node and first EXPR_LIST operand
2772 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2773 location or NULL for padding. For larger bitsizes,
2774 mode is 0 and first operand is a CONCAT with bitsize
2775 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2776 NULL as second operand. */
2778 const char * GTY (()) label
;
2779 struct var_loc_node
* GTY (()) next
;
2782 /* Variable location list. */
2783 struct GTY (()) var_loc_list_def
{
2784 struct var_loc_node
* GTY (()) first
;
2786 /* Pointer to the last but one or last element of the
2787 chained list. If the list is empty, both first and
2788 last are NULL, if the list contains just one node
2789 or the last node certainly is not redundant, it points
2790 to the last node, otherwise points to the last but one.
2791 Do not mark it for GC because it is marked through the chain. */
2792 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2794 /* Pointer to the last element before section switch,
2795 if NULL, either sections weren't switched or first
2796 is after section switch. */
2797 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2799 /* DECL_UID of the variable decl. */
2800 unsigned int decl_id
;
2802 typedef struct var_loc_list_def var_loc_list
;
2804 /* Call argument location list. */
2805 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2806 rtx
GTY (()) call_arg_loc_note
;
2807 const char * GTY (()) label
;
2808 tree
GTY (()) block
;
2810 rtx
GTY (()) symbol_ref
;
2811 struct call_arg_loc_node
* GTY (()) next
;
2815 /* Table of decl location linked lists. */
2816 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
2818 /* Head and tail of call_arg_loc chain. */
2819 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2820 static struct call_arg_loc_node
*call_arg_loc_last
;
2822 /* Number of call sites in the current function. */
2823 static int call_site_count
= -1;
2824 /* Number of tail call sites in the current function. */
2825 static int tail_call_site_count
= -1;
2827 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2829 static vec
<dw_die_ref
> block_map
;
2831 /* A cached location list. */
2832 struct GTY (()) cached_dw_loc_list_def
{
2833 /* The DECL_UID of the decl that this entry describes. */
2834 unsigned int decl_id
;
2836 /* The cached location list. */
2837 dw_loc_list_ref loc_list
;
2839 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2841 /* Table of cached location lists. */
2842 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
2844 /* A pointer to the base of a list of references to DIE's that
2845 are uniquely identified by their tag, presence/absence of
2846 children DIE's, and list of attribute/value pairs. */
2847 static GTY((length ("abbrev_die_table_allocated")))
2848 dw_die_ref
*abbrev_die_table
;
2850 /* Number of elements currently allocated for abbrev_die_table. */
2851 static GTY(()) unsigned abbrev_die_table_allocated
;
2853 /* Number of elements in type_die_table currently in use. */
2854 static GTY(()) unsigned abbrev_die_table_in_use
;
2856 /* Size (in elements) of increments by which we may expand the
2857 abbrev_die_table. */
2858 #define ABBREV_DIE_TABLE_INCREMENT 256
2860 /* A global counter for generating labels for line number data. */
2861 static unsigned int line_info_label_num
;
2863 /* The current table to which we should emit line number information
2864 for the current function. This will be set up at the beginning of
2865 assembly for the function. */
2866 static dw_line_info_table
*cur_line_info_table
;
2868 /* The two default tables of line number info. */
2869 static GTY(()) dw_line_info_table
*text_section_line_info
;
2870 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2872 /* The set of all non-default tables of line number info. */
2873 static GTY(()) vec
<dw_line_info_table_p
, va_gc
> *separate_line_info
;
2875 /* A flag to tell pubnames/types export if there is an info section to
2877 static bool info_section_emitted
;
2879 /* A pointer to the base of a table that contains a list of publicly
2880 accessible names. */
2881 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2883 /* A pointer to the base of a table that contains a list of publicly
2884 accessible types. */
2885 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
2887 /* A pointer to the base of a table that contains a list of macro
2888 defines/undefines (and file start/end markers). */
2889 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
2891 /* True if .debug_macinfo or .debug_macros section is going to be
2893 #define have_macinfo \
2894 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2895 && !macinfo_table->is_empty ())
2897 /* Array of dies for which we should generate .debug_ranges info. */
2898 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2900 /* Number of elements currently allocated for ranges_table. */
2901 static GTY(()) unsigned ranges_table_allocated
;
2903 /* Number of elements in ranges_table currently in use. */
2904 static GTY(()) unsigned ranges_table_in_use
;
2906 /* Array of pairs of labels referenced in ranges_table. */
2907 static GTY ((length ("ranges_by_label_allocated")))
2908 dw_ranges_by_label_ref ranges_by_label
;
2910 /* Number of elements currently allocated for ranges_by_label. */
2911 static GTY(()) unsigned ranges_by_label_allocated
;
2913 /* Number of elements in ranges_by_label currently in use. */
2914 static GTY(()) unsigned ranges_by_label_in_use
;
2916 /* Size (in elements) of increments by which we may expand the
2918 #define RANGES_TABLE_INCREMENT 64
2920 /* Whether we have location lists that need outputting */
2921 static GTY(()) bool have_location_lists
;
2923 /* Unique label counter. */
2924 static GTY(()) unsigned int loclabel_num
;
2926 /* Unique label counter for point-of-call tables. */
2927 static GTY(()) unsigned int poc_label_num
;
2929 /* Record whether the function being analyzed contains inlined functions. */
2930 static int current_function_has_inlines
;
2932 /* The last file entry emitted by maybe_emit_file(). */
2933 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
2935 /* Number of internal labels generated by gen_internal_sym(). */
2936 static GTY(()) int label_num
;
2938 /* Cached result of previous call to lookup_filename. */
2939 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
2941 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
2943 /* Instances of generic types for which we need to generate debug
2944 info that describe their generic parameters and arguments. That
2945 generation needs to happen once all types are properly laid out so
2946 we do it at the end of compilation. */
2947 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
2949 /* Offset from the "steady-state frame pointer" to the frame base,
2950 within the current function. */
2951 static HOST_WIDE_INT frame_pointer_fb_offset
;
2952 static bool frame_pointer_fb_offset_valid
;
2954 static vec
<dw_die_ref
> base_types
;
2956 /* Forward declarations for functions defined in this file. */
2958 static int is_pseudo_reg (const_rtx
);
2959 static tree
type_main_variant (tree
);
2960 static int is_tagged_type (const_tree
);
2961 static const char *dwarf_tag_name (unsigned);
2962 static const char *dwarf_attr_name (unsigned);
2963 static const char *dwarf_form_name (unsigned);
2964 static tree
decl_ultimate_origin (const_tree
);
2965 static tree
decl_class_context (tree
);
2966 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
2967 static inline enum dw_val_class
AT_class (dw_attr_ref
);
2968 static inline unsigned int AT_index (dw_attr_ref
);
2969 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
2970 static inline unsigned AT_flag (dw_attr_ref
);
2971 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
2972 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
2973 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
2974 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
2975 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
2976 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2977 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
2978 unsigned int, unsigned char *);
2979 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
2980 static hashval_t
debug_str_do_hash (const void *);
2981 static int debug_str_eq (const void *, const void *);
2982 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
2983 static inline const char *AT_string (dw_attr_ref
);
2984 static enum dwarf_form
AT_string_form (dw_attr_ref
);
2985 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
2986 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
2987 static inline dw_die_ref
AT_ref (dw_attr_ref
);
2988 static inline int AT_ref_external (dw_attr_ref
);
2989 static inline void set_AT_ref_external (dw_attr_ref
, int);
2990 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
2991 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
2992 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
2993 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
2995 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
2996 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
2997 static void remove_addr_table_entry (addr_table_entry
*);
2998 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
2999 static inline rtx
AT_addr (dw_attr_ref
);
3000 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3001 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3002 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3003 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3004 unsigned HOST_WIDE_INT
);
3005 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3006 unsigned long, bool);
3007 static inline const char *AT_lbl (dw_attr_ref
);
3008 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
3009 static const char *get_AT_low_pc (dw_die_ref
);
3010 static const char *get_AT_hi_pc (dw_die_ref
);
3011 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3012 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3013 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3014 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3015 static bool is_cxx (void);
3016 static bool is_fortran (void);
3017 static bool is_ada (void);
3018 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
3019 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3020 static void add_child_die (dw_die_ref
, dw_die_ref
);
3021 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3022 static dw_die_ref
lookup_type_die (tree
);
3023 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3024 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3025 static void equate_type_number_to_die (tree
, dw_die_ref
);
3026 static hashval_t
decl_die_table_hash (const void *);
3027 static int decl_die_table_eq (const void *, const void *);
3028 static dw_die_ref
lookup_decl_die (tree
);
3029 static hashval_t
common_block_die_table_hash (const void *);
3030 static int common_block_die_table_eq (const void *, const void *);
3031 static hashval_t
decl_loc_table_hash (const void *);
3032 static int decl_loc_table_eq (const void *, const void *);
3033 static var_loc_list
*lookup_decl_loc (const_tree
);
3034 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3035 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3036 static void print_spaces (FILE *);
3037 static void print_die (dw_die_ref
, FILE *);
3038 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3039 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3040 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3041 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3042 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3043 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3044 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3045 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3046 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
3047 struct md5_ctx
*, int *);
3048 struct checksum_attributes
;
3049 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3050 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3051 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3052 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3053 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3054 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3055 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3056 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3057 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3058 static void compute_section_prefix (dw_die_ref
);
3059 static int is_type_die (dw_die_ref
);
3060 static int is_comdat_die (dw_die_ref
);
3061 static int is_symbol_die (dw_die_ref
);
3062 static void assign_symbol_names (dw_die_ref
);
3063 static void break_out_includes (dw_die_ref
);
3064 static int is_declaration_die (dw_die_ref
);
3065 static int should_move_die_to_comdat (dw_die_ref
);
3066 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3067 static dw_die_ref
clone_die (dw_die_ref
);
3068 static dw_die_ref
clone_tree (dw_die_ref
);
3069 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3070 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3071 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3072 static dw_die_ref
generate_skeleton (dw_die_ref
);
3073 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3076 static void break_out_comdat_types (dw_die_ref
);
3077 static dw_die_ref
copy_ancestor_tree (dw_die_ref
, dw_die_ref
, htab_t
);
3078 static void copy_decls_walk (dw_die_ref
, dw_die_ref
, htab_t
);
3079 static void copy_decls_for_unworthy_types (dw_die_ref
);
3081 static hashval_t
htab_cu_hash (const void *);
3082 static int htab_cu_eq (const void *, const void *);
3083 static void htab_cu_del (void *);
3084 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
3085 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
3086 static void add_sibling_attributes (dw_die_ref
);
3087 static void build_abbrev_table (dw_die_ref
, htab_t
);
3088 static void output_location_lists (dw_die_ref
);
3089 static int constant_size (unsigned HOST_WIDE_INT
);
3090 static unsigned long size_of_die (dw_die_ref
);
3091 static void calc_die_sizes (dw_die_ref
);
3092 static void calc_base_type_die_sizes (void);
3093 static void mark_dies (dw_die_ref
);
3094 static void unmark_dies (dw_die_ref
);
3095 static void unmark_all_dies (dw_die_ref
);
3096 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3097 static unsigned long size_of_aranges (void);
3098 static enum dwarf_form
value_format (dw_attr_ref
);
3099 static void output_value_format (dw_attr_ref
);
3100 static void output_abbrev_section (void);
3101 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3102 static void output_die_symbol (dw_die_ref
);
3103 static void output_die (dw_die_ref
);
3104 static void output_compilation_unit_header (void);
3105 static void output_comp_unit (dw_die_ref
, int);
3106 static void output_comdat_type_unit (comdat_type_node
*);
3107 static const char *dwarf2_name (tree
, int);
3108 static void add_pubname (tree
, dw_die_ref
);
3109 static void add_enumerator_pubname (const char *, dw_die_ref
);
3110 static void add_pubname_string (const char *, dw_die_ref
);
3111 static void add_pubtype (tree
, dw_die_ref
);
3112 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3113 static void output_aranges (unsigned long);
3114 static unsigned int add_ranges_num (int);
3115 static unsigned int add_ranges (const_tree
);
3116 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3118 static void output_ranges (void);
3119 static dw_line_info_table
*new_line_info_table (void);
3120 static void output_line_info (bool);
3121 static void output_file_names (void);
3122 static dw_die_ref
base_type_die (tree
);
3123 static int is_base_type (tree
);
3124 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3125 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3126 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3127 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3128 static int type_is_enum (const_tree
);
3129 static unsigned int dbx_reg_number (const_rtx
);
3130 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3131 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3132 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3133 enum var_init_status
);
3134 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3135 enum var_init_status
);
3136 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3137 enum var_init_status
);
3138 static int is_based_loc (const_rtx
);
3139 static int resolve_one_addr (rtx
*, void *);
3140 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3141 enum var_init_status
);
3142 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
3143 enum var_init_status
);
3144 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3145 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3146 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3147 static tree
field_type (const_tree
);
3148 static unsigned int simple_type_align_in_bits (const_tree
);
3149 static unsigned int simple_decl_align_in_bits (const_tree
);
3150 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3151 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3152 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3154 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3155 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3156 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3157 static void insert_double (double_int
, unsigned char *);
3158 static void insert_float (const_rtx
, unsigned char *);
3159 static rtx
rtl_for_decl_location (tree
);
3160 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3161 enum dwarf_attribute
);
3162 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3163 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3164 static void add_name_attribute (dw_die_ref
, const char *);
3165 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3166 static void add_comp_dir_attribute (dw_die_ref
);
3167 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3168 static void add_subscript_info (dw_die_ref
, tree
, bool);
3169 static void add_byte_size_attribute (dw_die_ref
, tree
);
3170 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3171 static void add_bit_size_attribute (dw_die_ref
, tree
);
3172 static void add_prototyped_attribute (dw_die_ref
, tree
);
3173 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3174 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3175 static void add_src_coords_attributes (dw_die_ref
, tree
);
3176 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3177 static void push_decl_scope (tree
);
3178 static void pop_decl_scope (void);
3179 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3180 static inline int local_scope_p (dw_die_ref
);
3181 static inline int class_scope_p (dw_die_ref
);
3182 static inline int class_or_namespace_scope_p (dw_die_ref
);
3183 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3184 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3185 static const char *type_tag (const_tree
);
3186 static tree
member_declared_type (const_tree
);
3188 static const char *decl_start_label (tree
);
3190 static void gen_array_type_die (tree
, dw_die_ref
);
3191 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3193 static void gen_entry_point_die (tree
, dw_die_ref
);
3195 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3196 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3197 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3198 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3199 static void gen_formal_types_die (tree
, dw_die_ref
);
3200 static void gen_subprogram_die (tree
, dw_die_ref
);
3201 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3202 static void gen_const_die (tree
, dw_die_ref
);
3203 static void gen_label_die (tree
, dw_die_ref
);
3204 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3205 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3206 static void gen_field_die (tree
, dw_die_ref
);
3207 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3208 static dw_die_ref
gen_compile_unit_die (const char *);
3209 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3210 static void gen_member_die (tree
, dw_die_ref
);
3211 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3212 enum debug_info_usage
);
3213 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3214 static void gen_typedef_die (tree
, dw_die_ref
);
3215 static void gen_type_die (tree
, dw_die_ref
);
3216 static void gen_block_die (tree
, dw_die_ref
, int);
3217 static void decls_for_scope (tree
, dw_die_ref
, int);
3218 static inline int is_redundant_typedef (const_tree
);
3219 static bool is_naming_typedef_decl (const_tree
);
3220 static inline dw_die_ref
get_context_die (tree
);
3221 static void gen_namespace_die (tree
, dw_die_ref
);
3222 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3223 static dw_die_ref
force_decl_die (tree
);
3224 static dw_die_ref
force_type_die (tree
);
3225 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3226 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3227 static struct dwarf_file_data
* lookup_filename (const char *);
3228 static void retry_incomplete_types (void);
3229 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3230 static void gen_generic_params_dies (tree
);
3231 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3232 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3233 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3234 static int file_info_cmp (const void *, const void *);
3235 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3236 const char *, const char *);
3237 static void output_loc_list (dw_loc_list_ref
);
3238 static char *gen_internal_sym (const char *);
3239 static bool want_pubnames (void);
3241 static void prune_unmark_dies (dw_die_ref
);
3242 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3243 static void prune_unused_types_mark (dw_die_ref
, int);
3244 static void prune_unused_types_walk (dw_die_ref
);
3245 static void prune_unused_types_walk_attribs (dw_die_ref
);
3246 static void prune_unused_types_prune (dw_die_ref
);
3247 static void prune_unused_types (void);
3248 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3249 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3250 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3251 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3252 const char *, const char *);
3253 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3254 static void gen_remaining_tmpl_value_param_die_attribute (void);
3255 static bool generic_type_p (tree
);
3256 static void schedule_generic_params_dies_gen (tree t
);
3257 static void gen_scheduled_generic_parms_dies (void);
3259 static const char *comp_dir_string (void);
3261 /* enum for tracking thread-local variables whose address is really an offset
3262 relative to the TLS pointer, which will need link-time relocation, but will
3263 not need relocation by the DWARF consumer. */
3271 /* Return the operator to use for an address of a variable. For dtprel_true, we
3272 use DW_OP_const*. For regular variables, which need both link-time
3273 relocation and consumer-level relocation (e.g., to account for shared objects
3274 loaded at a random address), we use DW_OP_addr*. */
3276 static inline enum dwarf_location_atom
3277 dw_addr_op (enum dtprel_bool dtprel
)
3279 if (dtprel
== dtprel_true
)
3280 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3281 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3283 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3286 /* Return a pointer to a newly allocated address location description. If
3287 dwarf_split_debug_info is true, then record the address with the appropriate
3289 static inline dw_loc_descr_ref
3290 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3292 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3294 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3295 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3296 ref
->dtprel
= dtprel
;
3297 if (dwarf_split_debug_info
)
3298 ref
->dw_loc_oprnd1
.val_entry
3299 = add_addr_table_entry (addr
,
3300 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3302 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3307 /* Section names used to hold DWARF debugging information. */
3309 #ifndef DEBUG_INFO_SECTION
3310 #define DEBUG_INFO_SECTION ".debug_info"
3312 #ifndef DEBUG_DWO_INFO_SECTION
3313 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3315 #ifndef DEBUG_ABBREV_SECTION
3316 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3318 #ifndef DEBUG_DWO_ABBREV_SECTION
3319 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3321 #ifndef DEBUG_ARANGES_SECTION
3322 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3324 #ifndef DEBUG_ADDR_SECTION
3325 #define DEBUG_ADDR_SECTION ".debug_addr"
3327 #ifndef DEBUG_NORM_MACINFO_SECTION
3328 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3330 #ifndef DEBUG_DWO_MACINFO_SECTION
3331 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3333 #ifndef DEBUG_MACINFO_SECTION
3334 #define DEBUG_MACINFO_SECTION \
3335 (!dwarf_split_debug_info \
3336 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3338 #ifndef DEBUG_NORM_MACRO_SECTION
3339 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3341 #ifndef DEBUG_DWO_MACRO_SECTION
3342 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3344 #ifndef DEBUG_MACRO_SECTION
3345 #define DEBUG_MACRO_SECTION \
3346 (!dwarf_split_debug_info \
3347 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3349 #ifndef DEBUG_LINE_SECTION
3350 #define DEBUG_LINE_SECTION ".debug_line"
3352 #ifndef DEBUG_DWO_LINE_SECTION
3353 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3355 #ifndef DEBUG_LOC_SECTION
3356 #define DEBUG_LOC_SECTION ".debug_loc"
3358 #ifndef DEBUG_DWO_LOC_SECTION
3359 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3361 #ifndef DEBUG_PUBNAMES_SECTION
3362 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3364 #ifndef DEBUG_PUBTYPES_SECTION
3365 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
3367 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3368 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3369 #ifndef DEBUG_STR_OFFSETS_SECTION
3370 #define DEBUG_STR_OFFSETS_SECTION \
3371 (!dwarf_split_debug_info \
3372 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3374 #ifndef DEBUG_STR_DWO_SECTION
3375 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3377 #ifndef DEBUG_STR_SECTION
3378 #define DEBUG_STR_SECTION ".debug_str"
3380 #ifndef DEBUG_RANGES_SECTION
3381 #define DEBUG_RANGES_SECTION ".debug_ranges"
3384 /* Standard ELF section names for compiled code and data. */
3385 #ifndef TEXT_SECTION_NAME
3386 #define TEXT_SECTION_NAME ".text"
3389 /* Section flags for .debug_macinfo/.debug_macro section. */
3390 #define DEBUG_MACRO_SECTION_FLAGS \
3391 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3393 /* Section flags for .debug_str section. */
3394 #define DEBUG_STR_SECTION_FLAGS \
3395 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3396 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3399 /* Section flags for .debug_str.dwo section. */
3400 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3402 /* Labels we insert at beginning sections we can reference instead of
3403 the section names themselves. */
3405 #ifndef TEXT_SECTION_LABEL
3406 #define TEXT_SECTION_LABEL "Ltext"
3408 #ifndef COLD_TEXT_SECTION_LABEL
3409 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3411 #ifndef DEBUG_LINE_SECTION_LABEL
3412 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3414 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3415 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3417 #ifndef DEBUG_INFO_SECTION_LABEL
3418 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3420 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3421 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3423 #ifndef DEBUG_ABBREV_SECTION_LABEL
3424 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3426 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3427 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3429 #ifndef DEBUG_ADDR_SECTION_LABEL
3430 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3432 #ifndef DEBUG_LOC_SECTION_LABEL
3433 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3435 #ifndef DEBUG_RANGES_SECTION_LABEL
3436 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3438 #ifndef DEBUG_MACINFO_SECTION_LABEL
3439 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3441 #ifndef DEBUG_MACRO_SECTION_LABEL
3442 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3444 #define SKELETON_COMP_DIE_ABBREV 1
3445 #define SKELETON_TYPE_DIE_ABBREV 2
3447 /* Definitions of defaults for formats and names of various special
3448 (artificial) labels which may be generated within this file (when the -g
3449 options is used and DWARF2_DEBUGGING_INFO is in effect.
3450 If necessary, these may be overridden from within the tm.h file, but
3451 typically, overriding these defaults is unnecessary. */
3453 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3454 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3455 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3456 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3457 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3458 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3459 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3460 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3461 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3462 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3463 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3464 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3465 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3466 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3468 #ifndef TEXT_END_LABEL
3469 #define TEXT_END_LABEL "Letext"
3471 #ifndef COLD_END_LABEL
3472 #define COLD_END_LABEL "Letext_cold"
3474 #ifndef BLOCK_BEGIN_LABEL
3475 #define BLOCK_BEGIN_LABEL "LBB"
3477 #ifndef BLOCK_END_LABEL
3478 #define BLOCK_END_LABEL "LBE"
3480 #ifndef LINE_CODE_LABEL
3481 #define LINE_CODE_LABEL "LM"
3485 /* Return the root of the DIE's built for the current compilation unit. */
3487 comp_unit_die (void)
3489 if (!single_comp_unit_die
)
3490 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3491 return single_comp_unit_die
;
3494 /* We allow a language front-end to designate a function that is to be
3495 called to "demangle" any name before it is put into a DIE. */
3497 static const char *(*demangle_name_func
) (const char *);
3500 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3502 demangle_name_func
= func
;
3505 /* Test if rtl node points to a pseudo register. */
3508 is_pseudo_reg (const_rtx rtl
)
3510 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3511 || (GET_CODE (rtl
) == SUBREG
3512 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3515 /* Return a reference to a type, with its const and volatile qualifiers
3519 type_main_variant (tree type
)
3521 type
= TYPE_MAIN_VARIANT (type
);
3523 /* ??? There really should be only one main variant among any group of
3524 variants of a given type (and all of the MAIN_VARIANT values for all
3525 members of the group should point to that one type) but sometimes the C
3526 front-end messes this up for array types, so we work around that bug
3528 if (TREE_CODE (type
) == ARRAY_TYPE
)
3529 while (type
!= TYPE_MAIN_VARIANT (type
))
3530 type
= TYPE_MAIN_VARIANT (type
);
3535 /* Return nonzero if the given type node represents a tagged type. */
3538 is_tagged_type (const_tree type
)
3540 enum tree_code code
= TREE_CODE (type
);
3542 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3543 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3546 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3549 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3551 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3554 /* Return die_offset of a DIE reference to a base type. */
3556 static unsigned long int
3557 get_base_type_offset (dw_die_ref ref
)
3559 if (ref
->die_offset
)
3560 return ref
->die_offset
;
3561 if (comp_unit_die ()->die_abbrev
)
3563 calc_base_type_die_sizes ();
3564 gcc_assert (ref
->die_offset
);
3566 return ref
->die_offset
;
3569 /* Return die_offset of a DIE reference other than base type. */
3571 static unsigned long int
3572 get_ref_die_offset (dw_die_ref ref
)
3574 gcc_assert (ref
->die_offset
);
3575 return ref
->die_offset
;
3578 /* Convert a DIE tag into its string name. */
3581 dwarf_tag_name (unsigned int tag
)
3583 const char *name
= get_DW_TAG_name (tag
);
3588 return "DW_TAG_<unknown>";
3591 /* Convert a DWARF attribute code into its string name. */
3594 dwarf_attr_name (unsigned int attr
)
3600 #if VMS_DEBUGGING_INFO
3601 case DW_AT_HP_prologue
:
3602 return "DW_AT_HP_prologue";
3604 case DW_AT_MIPS_loop_unroll_factor
:
3605 return "DW_AT_MIPS_loop_unroll_factor";
3608 #if VMS_DEBUGGING_INFO
3609 case DW_AT_HP_epilogue
:
3610 return "DW_AT_HP_epilogue";
3612 case DW_AT_MIPS_stride
:
3613 return "DW_AT_MIPS_stride";
3617 name
= get_DW_AT_name (attr
);
3622 return "DW_AT_<unknown>";
3625 /* Convert a DWARF value form code into its string name. */
3628 dwarf_form_name (unsigned int form
)
3630 const char *name
= get_DW_FORM_name (form
);
3635 return "DW_FORM_<unknown>";
3638 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3639 instance of an inlined instance of a decl which is local to an inline
3640 function, so we have to trace all of the way back through the origin chain
3641 to find out what sort of node actually served as the original seed for the
3645 decl_ultimate_origin (const_tree decl
)
3647 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3650 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3651 nodes in the function to point to themselves; ignore that if
3652 we're trying to output the abstract instance of this function. */
3653 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3656 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3657 most distant ancestor, this should never happen. */
3658 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3660 return DECL_ABSTRACT_ORIGIN (decl
);
3663 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3664 of a virtual function may refer to a base class, so we check the 'this'
3668 decl_class_context (tree decl
)
3670 tree context
= NULL_TREE
;
3672 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3673 context
= DECL_CONTEXT (decl
);
3675 context
= TYPE_MAIN_VARIANT
3676 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3678 if (context
&& !TYPE_P (context
))
3679 context
= NULL_TREE
;
3684 /* Add an attribute/value pair to a DIE. */
3687 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3689 /* Maybe this should be an assert? */
3693 vec_safe_reserve (die
->die_attr
, 1);
3694 vec_safe_push (die
->die_attr
, *attr
);
3697 static inline enum dw_val_class
3698 AT_class (dw_attr_ref a
)
3700 return a
->dw_attr_val
.val_class
;
3703 /* Return the index for any attribute that will be referenced with a
3704 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3705 are stored in dw_attr_val.v.val_str for reference counting
3708 static inline unsigned int
3709 AT_index (dw_attr_ref a
)
3711 if (AT_class (a
) == dw_val_class_str
)
3712 return a
->dw_attr_val
.v
.val_str
->index
;
3713 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3714 return a
->dw_attr_val
.val_entry
->index
;
3718 /* Add a flag value attribute to a DIE. */
3721 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3725 attr
.dw_attr
= attr_kind
;
3726 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3727 attr
.dw_attr_val
.val_entry
= NULL
;
3728 attr
.dw_attr_val
.v
.val_flag
= flag
;
3729 add_dwarf_attr (die
, &attr
);
3732 static inline unsigned
3733 AT_flag (dw_attr_ref a
)
3735 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3736 return a
->dw_attr_val
.v
.val_flag
;
3739 /* Add a signed integer attribute value to a DIE. */
3742 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3746 attr
.dw_attr
= attr_kind
;
3747 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3748 attr
.dw_attr_val
.val_entry
= NULL
;
3749 attr
.dw_attr_val
.v
.val_int
= int_val
;
3750 add_dwarf_attr (die
, &attr
);
3753 static inline HOST_WIDE_INT
3754 AT_int (dw_attr_ref a
)
3756 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3757 return a
->dw_attr_val
.v
.val_int
;
3760 /* Add an unsigned integer attribute value to a DIE. */
3763 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3764 unsigned HOST_WIDE_INT unsigned_val
)
3768 attr
.dw_attr
= attr_kind
;
3769 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3770 attr
.dw_attr_val
.val_entry
= NULL
;
3771 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3772 add_dwarf_attr (die
, &attr
);
3775 static inline unsigned HOST_WIDE_INT
3776 AT_unsigned (dw_attr_ref a
)
3778 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3779 return a
->dw_attr_val
.v
.val_unsigned
;
3782 /* Add an unsigned double integer attribute value to a DIE. */
3785 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3786 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3790 attr
.dw_attr
= attr_kind
;
3791 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3792 attr
.dw_attr_val
.val_entry
= NULL
;
3793 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3794 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3795 add_dwarf_attr (die
, &attr
);
3798 /* Add a floating point attribute value to a DIE and return it. */
3801 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3802 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3806 attr
.dw_attr
= attr_kind
;
3807 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3808 attr
.dw_attr_val
.val_entry
= NULL
;
3809 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3810 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3811 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3812 add_dwarf_attr (die
, &attr
);
3815 /* Add an 8-byte data attribute value to a DIE. */
3818 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3819 unsigned char data8
[8])
3823 attr
.dw_attr
= attr_kind
;
3824 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3825 attr
.dw_attr_val
.val_entry
= NULL
;
3826 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3827 add_dwarf_attr (die
, &attr
);
3830 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3831 dwarf_split_debug_info, address attributes in dies destined for the
3832 final executable have force_direct set to avoid using indexed
3836 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3842 lbl_id
= xstrdup (lbl_low
);
3843 attr
.dw_attr
= DW_AT_low_pc
;
3844 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3845 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3846 if (dwarf_split_debug_info
&& !force_direct
)
3847 attr
.dw_attr_val
.val_entry
3848 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3850 attr
.dw_attr_val
.val_entry
= NULL
;
3851 add_dwarf_attr (die
, &attr
);
3853 attr
.dw_attr
= DW_AT_high_pc
;
3854 if (dwarf_version
< 4)
3855 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3857 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3858 lbl_id
= xstrdup (lbl_high
);
3859 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3860 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3861 && dwarf_split_debug_info
&& !force_direct
)
3862 attr
.dw_attr_val
.val_entry
3863 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3865 attr
.dw_attr_val
.val_entry
= NULL
;
3866 add_dwarf_attr (die
, &attr
);
3869 /* Hash and equality functions for debug_str_hash. */
3872 debug_str_do_hash (const void *x
)
3874 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
3878 debug_str_eq (const void *x1
, const void *x2
)
3880 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
3881 (const char *)x2
) == 0;
3884 /* Add STR to the given string hash table. */
3886 static struct indirect_string_node
*
3887 find_AT_string_in_table (const char *str
, htab_t table
)
3889 struct indirect_string_node
*node
;
3892 slot
= htab_find_slot_with_hash (table
, str
,
3893 htab_hash_string (str
), INSERT
);
3896 node
= ggc_alloc_cleared_indirect_string_node ();
3897 node
->str
= ggc_strdup (str
);
3901 node
= (struct indirect_string_node
*) *slot
;
3907 /* Add STR to the indirect string hash table. */
3909 static struct indirect_string_node
*
3910 find_AT_string (const char *str
)
3912 if (! debug_str_hash
)
3913 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
3914 debug_str_eq
, NULL
);
3916 return find_AT_string_in_table (str
, debug_str_hash
);
3919 /* Add a string attribute value to a DIE. */
3922 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
3925 struct indirect_string_node
*node
;
3927 node
= find_AT_string (str
);
3929 attr
.dw_attr
= attr_kind
;
3930 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
3931 attr
.dw_attr_val
.val_entry
= NULL
;
3932 attr
.dw_attr_val
.v
.val_str
= node
;
3933 add_dwarf_attr (die
, &attr
);
3936 static inline const char *
3937 AT_string (dw_attr_ref a
)
3939 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3940 return a
->dw_attr_val
.v
.val_str
->str
;
3943 /* Call this function directly to bypass AT_string_form's logic to put
3944 the string inline in the die. */
3947 set_indirect_string (struct indirect_string_node
*node
)
3950 /* Already indirect is a no op. */
3951 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
3953 gcc_assert (node
->label
);
3956 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
3957 ++dw2_string_counter
;
3958 node
->label
= xstrdup (label
);
3960 if (!dwarf_split_debug_info
)
3962 node
->form
= DW_FORM_strp
;
3963 node
->index
= NOT_INDEXED
;
3967 node
->form
= DW_FORM_GNU_str_index
;
3968 node
->index
= NO_INDEX_ASSIGNED
;
3972 /* Find out whether a string should be output inline in DIE
3973 or out-of-line in .debug_str section. */
3975 static enum dwarf_form
3976 find_string_form (struct indirect_string_node
*node
)
3983 len
= strlen (node
->str
) + 1;
3985 /* If the string is shorter or equal to the size of the reference, it is
3986 always better to put it inline. */
3987 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
3988 return node
->form
= DW_FORM_string
;
3990 /* If we cannot expect the linker to merge strings in .debug_str
3991 section, only put it into .debug_str if it is worth even in this
3993 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
3994 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
3995 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
3996 return node
->form
= DW_FORM_string
;
3998 set_indirect_string (node
);
4003 /* Find out whether the string referenced from the attribute should be
4004 output inline in DIE or out-of-line in .debug_str section. */
4006 static enum dwarf_form
4007 AT_string_form (dw_attr_ref a
)
4009 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4010 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4013 /* Add a DIE reference attribute value to a DIE. */
4016 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4020 #ifdef ENABLE_CHECKING
4021 gcc_assert (targ_die
!= NULL
);
4023 /* With LTO we can end up trying to reference something we didn't create
4024 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4025 if (targ_die
== NULL
)
4029 attr
.dw_attr
= attr_kind
;
4030 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4031 attr
.dw_attr_val
.val_entry
= NULL
;
4032 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4033 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4034 add_dwarf_attr (die
, &attr
);
4037 /* Change DIE reference REF to point to NEW_DIE instead. */
4040 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
4042 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4043 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4044 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4047 /* Add an AT_specification attribute to a DIE, and also make the back
4048 pointer from the specification to the definition. */
4051 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4053 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4054 gcc_assert (!targ_die
->die_definition
);
4055 targ_die
->die_definition
= die
;
4058 static inline dw_die_ref
4059 AT_ref (dw_attr_ref a
)
4061 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4062 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4066 AT_ref_external (dw_attr_ref a
)
4068 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4069 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4075 set_AT_ref_external (dw_attr_ref a
, int i
)
4077 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4078 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4081 /* Add an FDE reference attribute value to a DIE. */
4084 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4088 attr
.dw_attr
= attr_kind
;
4089 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4090 attr
.dw_attr_val
.val_entry
= NULL
;
4091 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4092 add_dwarf_attr (die
, &attr
);
4095 /* Add a location description attribute value to a DIE. */
4098 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4102 attr
.dw_attr
= attr_kind
;
4103 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4104 attr
.dw_attr_val
.val_entry
= NULL
;
4105 attr
.dw_attr_val
.v
.val_loc
= loc
;
4106 add_dwarf_attr (die
, &attr
);
4109 static inline dw_loc_descr_ref
4110 AT_loc (dw_attr_ref a
)
4112 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4113 return a
->dw_attr_val
.v
.val_loc
;
4117 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4121 attr
.dw_attr
= attr_kind
;
4122 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4123 attr
.dw_attr_val
.val_entry
= NULL
;
4124 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4125 add_dwarf_attr (die
, &attr
);
4126 have_location_lists
= true;
4129 static inline dw_loc_list_ref
4130 AT_loc_list (dw_attr_ref a
)
4132 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4133 return a
->dw_attr_val
.v
.val_loc_list
;
4136 static inline dw_loc_list_ref
*
4137 AT_loc_list_ptr (dw_attr_ref a
)
4139 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4140 return &a
->dw_attr_val
.v
.val_loc_list
;
4143 /* Table of entries into the .debug_addr section. */
4145 static GTY ((param_is (addr_table_entry
))) htab_t addr_index_table
;
4147 /* Hash an address_table_entry. */
4150 addr_table_entry_do_hash (const void *x
)
4152 const addr_table_entry
*a
= (const addr_table_entry
*) x
;
4156 return iterative_hash_rtx (a
->addr
.rtl
, 0);
4157 case ate_kind_rtx_dtprel
:
4158 return iterative_hash_rtx (a
->addr
.rtl
, 1);
4159 case ate_kind_label
:
4160 return htab_hash_string (a
->addr
.label
);
4166 /* Determine equality for two address_table_entries. */
4169 addr_table_entry_eq (const void *x1
, const void *x2
)
4171 const addr_table_entry
*a1
= (const addr_table_entry
*) x1
;
4172 const addr_table_entry
*a2
= (const addr_table_entry
*) x2
;
4174 if (a1
->kind
!= a2
->kind
)
4179 case ate_kind_rtx_dtprel
:
4180 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4181 case ate_kind_label
:
4182 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4188 /* Initialize an addr_table_entry. */
4191 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4197 case ate_kind_rtx_dtprel
:
4198 e
->addr
.rtl
= (rtx
) addr
;
4200 case ate_kind_label
:
4201 e
->addr
.label
= (char *) addr
;
4205 e
->index
= NO_INDEX_ASSIGNED
;
4208 /* Add attr to the address table entry to the table. Defer setting an
4209 index until output time. */
4211 static addr_table_entry
*
4212 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4214 addr_table_entry
*node
;
4215 addr_table_entry finder
;
4218 gcc_assert (dwarf_split_debug_info
);
4219 if (! addr_index_table
)
4220 addr_index_table
= htab_create_ggc (10, addr_table_entry_do_hash
,
4221 addr_table_entry_eq
, NULL
);
4222 init_addr_table_entry (&finder
, kind
, addr
);
4223 slot
= htab_find_slot (addr_index_table
, &finder
, INSERT
);
4225 if (*slot
== HTAB_EMPTY_ENTRY
)
4227 node
= ggc_alloc_cleared_addr_table_entry ();
4228 init_addr_table_entry (node
, kind
, addr
);
4232 node
= (addr_table_entry
*) *slot
;
4238 /* Remove an entry from the addr table by decrementing its refcount.
4239 Strictly, decrementing the refcount would be enough, but the
4240 assertion that the entry is actually in the table has found
4244 remove_addr_table_entry (addr_table_entry
*entry
)
4246 addr_table_entry
*node
;
4248 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4249 node
= (addr_table_entry
*) htab_find (addr_index_table
, entry
);
4250 /* After an index is assigned, the table is frozen. */
4251 gcc_assert (node
->refcount
> 0 && node
->index
== NO_INDEX_ASSIGNED
);
4255 /* Given a location list, remove all addresses it refers to from the
4259 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4261 for (; descr
; descr
= descr
->dw_loc_next
)
4262 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4264 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4265 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4269 /* A helper function for dwarf2out_finish called through
4270 htab_traverse. Assign an addr_table_entry its index. All entries
4271 must be collected into the table when this function is called,
4272 because the indexing code relies on htab_traverse to traverse nodes
4273 in the same order for each run. */
4276 index_addr_table_entry (void **h
, void *v
)
4278 addr_table_entry
*node
= (addr_table_entry
*) *h
;
4279 unsigned int *index
= (unsigned int *) v
;
4281 /* Don't index unreferenced nodes. */
4282 if (node
->refcount
== 0)
4285 gcc_assert(node
->index
== NO_INDEX_ASSIGNED
);
4286 node
->index
= *index
;
4292 /* Add an address constant attribute value to a DIE. When using
4293 dwarf_split_debug_info, address attributes in dies destined for the
4294 final executable should be direct references--setting the parameter
4295 force_direct ensures this behavior. */
4298 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4303 attr
.dw_attr
= attr_kind
;
4304 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4305 attr
.dw_attr_val
.v
.val_addr
= addr
;
4306 if (dwarf_split_debug_info
&& !force_direct
)
4307 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4309 attr
.dw_attr_val
.val_entry
= NULL
;
4310 add_dwarf_attr (die
, &attr
);
4313 /* Get the RTX from to an address DIE attribute. */
4316 AT_addr (dw_attr_ref a
)
4318 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4319 return a
->dw_attr_val
.v
.val_addr
;
4322 /* Add a file attribute value to a DIE. */
4325 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4326 struct dwarf_file_data
*fd
)
4330 attr
.dw_attr
= attr_kind
;
4331 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4332 attr
.dw_attr_val
.val_entry
= NULL
;
4333 attr
.dw_attr_val
.v
.val_file
= fd
;
4334 add_dwarf_attr (die
, &attr
);
4337 /* Get the dwarf_file_data from a file DIE attribute. */
4339 static inline struct dwarf_file_data
*
4340 AT_file (dw_attr_ref a
)
4342 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4343 return a
->dw_attr_val
.v
.val_file
;
4346 /* Add a vms delta attribute value to a DIE. */
4349 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4350 const char *lbl1
, const char *lbl2
)
4354 attr
.dw_attr
= attr_kind
;
4355 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4356 attr
.dw_attr_val
.val_entry
= NULL
;
4357 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4358 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4359 add_dwarf_attr (die
, &attr
);
4362 /* Add a label identifier attribute value to a DIE. */
4365 add_AT_lbl_id (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_lbl_id
;
4372 attr
.dw_attr_val
.val_entry
= NULL
;
4373 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4374 if (dwarf_split_debug_info
)
4375 attr
.dw_attr_val
.val_entry
4376 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4378 add_dwarf_attr (die
, &attr
);
4381 /* Add a section offset attribute value to a DIE, an offset into the
4382 debug_line section. */
4385 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4390 attr
.dw_attr
= attr_kind
;
4391 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4392 attr
.dw_attr_val
.val_entry
= NULL
;
4393 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4394 add_dwarf_attr (die
, &attr
);
4397 /* Add a section offset attribute value to a DIE, an offset into the
4398 debug_macinfo section. */
4401 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4406 attr
.dw_attr
= attr_kind
;
4407 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4408 attr
.dw_attr_val
.val_entry
= NULL
;
4409 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4410 add_dwarf_attr (die
, &attr
);
4413 /* Add an offset attribute value to a DIE. */
4416 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4417 unsigned HOST_WIDE_INT offset
)
4421 attr
.dw_attr
= attr_kind
;
4422 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4423 attr
.dw_attr_val
.val_entry
= NULL
;
4424 attr
.dw_attr_val
.v
.val_offset
= offset
;
4425 add_dwarf_attr (die
, &attr
);
4428 /* Add a range_list attribute value to a DIE. When using
4429 dwarf_split_debug_info, address attributes in dies destined for the
4430 final executable should be direct references--setting the parameter
4431 force_direct ensures this behavior. */
4433 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4434 #define RELOCATED_OFFSET (NULL)
4437 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4438 long unsigned int offset
, bool force_direct
)
4442 attr
.dw_attr
= attr_kind
;
4443 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4444 /* For the range_list attribute, use val_entry to store whether the
4445 offset should follow split-debug-info or normal semantics. This
4446 value is read in output_range_list_offset. */
4447 if (dwarf_split_debug_info
&& !force_direct
)
4448 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4450 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4451 attr
.dw_attr_val
.v
.val_offset
= offset
;
4452 add_dwarf_attr (die
, &attr
);
4455 /* Return the start label of a delta attribute. */
4457 static inline const char *
4458 AT_vms_delta1 (dw_attr_ref a
)
4460 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4461 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4464 /* Return the end label of a delta attribute. */
4466 static inline const char *
4467 AT_vms_delta2 (dw_attr_ref a
)
4469 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4470 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4473 static inline const char *
4474 AT_lbl (dw_attr_ref a
)
4476 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4477 || AT_class (a
) == dw_val_class_lineptr
4478 || AT_class (a
) == dw_val_class_macptr
4479 || AT_class (a
) == dw_val_class_high_pc
));
4480 return a
->dw_attr_val
.v
.val_lbl_id
;
4483 /* Get the attribute of type attr_kind. */
4486 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4490 dw_die_ref spec
= NULL
;
4495 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4496 if (a
->dw_attr
== attr_kind
)
4498 else if (a
->dw_attr
== DW_AT_specification
4499 || a
->dw_attr
== DW_AT_abstract_origin
)
4503 return get_AT (spec
, attr_kind
);
4508 /* Returns the parent of the declaration of DIE. */
4511 get_die_parent (dw_die_ref die
)
4518 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4519 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4522 return die
->die_parent
;
4525 /* Return the "low pc" attribute value, typically associated with a subprogram
4526 DIE. Return null if the "low pc" attribute is either not present, or if it
4527 cannot be represented as an assembler label identifier. */
4529 static inline const char *
4530 get_AT_low_pc (dw_die_ref die
)
4532 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4534 return a
? AT_lbl (a
) : NULL
;
4537 /* Return the "high pc" attribute value, typically associated with a subprogram
4538 DIE. Return null if the "high pc" attribute is either not present, or if it
4539 cannot be represented as an assembler label identifier. */
4541 static inline const char *
4542 get_AT_hi_pc (dw_die_ref die
)
4544 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4546 return a
? AT_lbl (a
) : NULL
;
4549 /* Return the value of the string attribute designated by ATTR_KIND, or
4550 NULL if it is not present. */
4552 static inline const char *
4553 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4555 dw_attr_ref a
= get_AT (die
, attr_kind
);
4557 return a
? AT_string (a
) : NULL
;
4560 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4561 if it is not present. */
4564 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4566 dw_attr_ref a
= get_AT (die
, attr_kind
);
4568 return a
? AT_flag (a
) : 0;
4571 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4572 if it is not present. */
4574 static inline unsigned
4575 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4577 dw_attr_ref a
= get_AT (die
, attr_kind
);
4579 return a
? AT_unsigned (a
) : 0;
4582 static inline dw_die_ref
4583 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4585 dw_attr_ref a
= get_AT (die
, attr_kind
);
4587 return a
? AT_ref (a
) : NULL
;
4590 static inline struct dwarf_file_data
*
4591 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4593 dw_attr_ref a
= get_AT (die
, attr_kind
);
4595 return a
? AT_file (a
) : NULL
;
4598 /* Return TRUE if the language is C++. */
4603 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4605 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4608 /* Return TRUE if the language is Fortran. */
4613 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4615 return (lang
== DW_LANG_Fortran77
4616 || lang
== DW_LANG_Fortran90
4617 || lang
== DW_LANG_Fortran95
);
4620 /* Return TRUE if the language is Ada. */
4625 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4627 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4630 /* Remove the specified attribute if present. */
4633 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4641 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4642 if (a
->dw_attr
== attr_kind
)
4644 if (AT_class (a
) == dw_val_class_str
)
4645 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4646 a
->dw_attr_val
.v
.val_str
->refcount
--;
4648 /* vec::ordered_remove should help reduce the number of abbrevs
4650 die
->die_attr
->ordered_remove (ix
);
4655 /* Remove CHILD from its parent. PREV must have the property that
4656 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4659 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4661 gcc_assert (child
->die_parent
== prev
->die_parent
);
4662 gcc_assert (prev
->die_sib
== child
);
4665 gcc_assert (child
->die_parent
->die_child
== child
);
4669 prev
->die_sib
= child
->die_sib
;
4670 if (child
->die_parent
->die_child
== child
)
4671 child
->die_parent
->die_child
= prev
;
4674 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4675 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4678 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4680 dw_die_ref parent
= old_child
->die_parent
;
4682 gcc_assert (parent
== prev
->die_parent
);
4683 gcc_assert (prev
->die_sib
== old_child
);
4685 new_child
->die_parent
= parent
;
4686 if (prev
== old_child
)
4688 gcc_assert (parent
->die_child
== old_child
);
4689 new_child
->die_sib
= new_child
;
4693 prev
->die_sib
= new_child
;
4694 new_child
->die_sib
= old_child
->die_sib
;
4696 if (old_child
->die_parent
->die_child
== old_child
)
4697 old_child
->die_parent
->die_child
= new_child
;
4700 /* Move all children from OLD_PARENT to NEW_PARENT. */
4703 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4706 new_parent
->die_child
= old_parent
->die_child
;
4707 old_parent
->die_child
= NULL
;
4708 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4711 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4715 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4721 dw_die_ref prev
= c
;
4723 while (c
->die_tag
== tag
)
4725 remove_child_with_prev (c
, prev
);
4726 /* Might have removed every child. */
4727 if (c
== c
->die_sib
)
4731 } while (c
!= die
->die_child
);
4734 /* Add a CHILD_DIE as the last child of DIE. */
4737 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4739 /* FIXME this should probably be an assert. */
4740 if (! die
|| ! child_die
)
4742 gcc_assert (die
!= child_die
);
4744 child_die
->die_parent
= die
;
4747 child_die
->die_sib
= die
->die_child
->die_sib
;
4748 die
->die_child
->die_sib
= child_die
;
4751 child_die
->die_sib
= child_die
;
4752 die
->die_child
= child_die
;
4755 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4756 is the specification, to the end of PARENT's list of children.
4757 This is done by removing and re-adding it. */
4760 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4764 /* We want the declaration DIE from inside the class, not the
4765 specification DIE at toplevel. */
4766 if (child
->die_parent
!= parent
)
4768 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4774 gcc_assert (child
->die_parent
== parent
4775 || (child
->die_parent
4776 == get_AT_ref (parent
, DW_AT_specification
)));
4778 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4779 if (p
->die_sib
== child
)
4781 remove_child_with_prev (child
, p
);
4785 add_child_die (parent
, child
);
4788 /* Return a pointer to a newly created DIE node. */
4790 static inline dw_die_ref
4791 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4793 dw_die_ref die
= ggc_alloc_cleared_die_node ();
4795 die
->die_tag
= tag_value
;
4797 if (parent_die
!= NULL
)
4798 add_child_die (parent_die
, die
);
4801 limbo_die_node
*limbo_node
;
4803 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
4804 limbo_node
->die
= die
;
4805 limbo_node
->created_for
= t
;
4806 limbo_node
->next
= limbo_die_list
;
4807 limbo_die_list
= limbo_node
;
4813 /* Return the DIE associated with the given type specifier. */
4815 static inline dw_die_ref
4816 lookup_type_die (tree type
)
4818 return TYPE_SYMTAB_DIE (type
);
4821 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4822 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4823 anonymous type instead the one of the naming typedef. */
4825 static inline dw_die_ref
4826 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4829 && TREE_CODE (type
) == RECORD_TYPE
4831 && type_die
->die_tag
== DW_TAG_typedef
4832 && is_naming_typedef_decl (TYPE_NAME (type
)))
4833 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4837 /* Like lookup_type_die, but if type is an anonymous type named by a
4838 typedef[1], return the DIE of the anonymous type instead the one of
4839 the naming typedef. This is because in gen_typedef_die, we did
4840 equate the anonymous struct named by the typedef with the DIE of
4841 the naming typedef. So by default, lookup_type_die on an anonymous
4842 struct yields the DIE of the naming typedef.
4844 [1]: Read the comment of is_naming_typedef_decl to learn about what
4845 a naming typedef is. */
4847 static inline dw_die_ref
4848 lookup_type_die_strip_naming_typedef (tree type
)
4850 dw_die_ref die
= lookup_type_die (type
);
4851 return strip_naming_typedef (type
, die
);
4854 /* Equate a DIE to a given type specifier. */
4857 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
4859 TYPE_SYMTAB_DIE (type
) = type_die
;
4862 /* Returns a hash value for X (which really is a die_struct). */
4865 decl_die_table_hash (const void *x
)
4867 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
4870 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
4873 decl_die_table_eq (const void *x
, const void *y
)
4875 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4878 /* Return the DIE associated with a given declaration. */
4880 static inline dw_die_ref
4881 lookup_decl_die (tree decl
)
4883 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
4886 /* Returns a hash value for X (which really is a var_loc_list). */
4889 decl_loc_table_hash (const void *x
)
4891 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
4894 /* Return nonzero if decl_id of var_loc_list X is the same as
4898 decl_loc_table_eq (const void *x
, const void *y
)
4900 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4903 /* Return the var_loc list associated with a given declaration. */
4905 static inline var_loc_list
*
4906 lookup_decl_loc (const_tree decl
)
4908 if (!decl_loc_table
)
4910 return (var_loc_list
*)
4911 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
4914 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
4917 cached_dw_loc_list_table_hash (const void *x
)
4919 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
4922 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
4926 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
4928 return (((const cached_dw_loc_list
*) x
)->decl_id
4929 == DECL_UID ((const_tree
) y
));
4932 /* Equate a DIE to a particular declaration. */
4935 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
4937 unsigned int decl_id
= DECL_UID (decl
);
4940 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
4942 decl_die
->decl_id
= decl_id
;
4945 /* Return how many bits covers PIECE EXPR_LIST. */
4948 decl_piece_bitsize (rtx piece
)
4950 int ret
= (int) GET_MODE (piece
);
4953 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
4954 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
4955 return INTVAL (XEXP (XEXP (piece
, 0), 0));
4958 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
4961 decl_piece_varloc_ptr (rtx piece
)
4963 if ((int) GET_MODE (piece
))
4964 return &XEXP (piece
, 0);
4966 return &XEXP (XEXP (piece
, 0), 1);
4969 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
4970 Next is the chain of following piece nodes. */
4973 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
4975 if (bitsize
<= (int) MAX_MACHINE_MODE
)
4976 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
4978 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
4983 /* Return rtx that should be stored into loc field for
4984 LOC_NOTE and BITPOS/BITSIZE. */
4987 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
4988 HOST_WIDE_INT bitsize
)
4992 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
4994 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
4999 /* This function either modifies location piece list *DEST in
5000 place (if SRC and INNER is NULL), or copies location piece list
5001 *SRC to *DEST while modifying it. Location BITPOS is modified
5002 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5003 not copied and if needed some padding around it is added.
5004 When modifying in place, DEST should point to EXPR_LIST where
5005 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5006 to the start of the whole list and INNER points to the EXPR_LIST
5007 where earlier pieces cover PIECE_BITPOS bits. */
5010 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5011 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5012 HOST_WIDE_INT bitsize
, rtx loc_note
)
5015 bool copy
= inner
!= NULL
;
5019 /* First copy all nodes preceding the current bitpos. */
5020 while (src
!= inner
)
5022 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5023 decl_piece_bitsize (*src
), NULL_RTX
);
5024 dest
= &XEXP (*dest
, 1);
5025 src
= &XEXP (*src
, 1);
5028 /* Add padding if needed. */
5029 if (bitpos
!= piece_bitpos
)
5031 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5032 copy
? NULL_RTX
: *dest
);
5033 dest
= &XEXP (*dest
, 1);
5035 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5038 /* A piece with correct bitpos and bitsize already exist,
5039 just update the location for it and return. */
5040 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5043 /* Add the piece that changed. */
5044 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5045 dest
= &XEXP (*dest
, 1);
5046 /* Skip over pieces that overlap it. */
5047 diff
= bitpos
- piece_bitpos
+ bitsize
;
5050 while (diff
> 0 && *src
)
5053 diff
-= decl_piece_bitsize (piece
);
5055 src
= &XEXP (piece
, 1);
5058 *src
= XEXP (piece
, 1);
5059 free_EXPR_LIST_node (piece
);
5062 /* Add padding if needed. */
5063 if (diff
< 0 && *src
)
5067 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5068 dest
= &XEXP (*dest
, 1);
5072 /* Finally copy all nodes following it. */
5075 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5076 decl_piece_bitsize (*src
), NULL_RTX
);
5077 dest
= &XEXP (*dest
, 1);
5078 src
= &XEXP (*src
, 1);
5082 /* Add a variable location node to the linked list for DECL. */
5084 static struct var_loc_node
*
5085 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5087 unsigned int decl_id
;
5090 struct var_loc_node
*loc
= NULL
;
5091 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5093 if (DECL_DEBUG_EXPR_IS_FROM (decl
))
5095 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5097 && (handled_component_p (realdecl
)
5098 || (TREE_CODE (realdecl
) == MEM_REF
5099 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
)))
5101 HOST_WIDE_INT maxsize
;
5104 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5105 if (!DECL_P (innerdecl
)
5106 || DECL_IGNORED_P (innerdecl
)
5107 || TREE_STATIC (innerdecl
)
5109 || bitpos
+ bitsize
> 256
5110 || bitsize
!= maxsize
)
5116 decl_id
= DECL_UID (decl
);
5117 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5120 temp
= ggc_alloc_cleared_var_loc_list ();
5121 temp
->decl_id
= decl_id
;
5125 temp
= (var_loc_list
*) *slot
;
5127 /* For PARM_DECLs try to keep around the original incoming value,
5128 even if that means we'll emit a zero-range .debug_loc entry. */
5130 && temp
->first
== temp
->last
5131 && TREE_CODE (decl
) == PARM_DECL
5132 && GET_CODE (temp
->first
->loc
) == NOTE
5133 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5134 && DECL_INCOMING_RTL (decl
)
5135 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5136 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5137 == GET_CODE (DECL_INCOMING_RTL (decl
))
5138 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5140 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5141 NOTE_VAR_LOCATION_LOC (loc_note
))
5142 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5143 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5145 loc
= ggc_alloc_cleared_var_loc_node ();
5146 temp
->first
->next
= loc
;
5148 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5150 else if (temp
->last
)
5152 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5153 rtx
*piece_loc
= NULL
, last_loc_note
;
5154 int piece_bitpos
= 0;
5158 gcc_assert (last
->next
== NULL
);
5160 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5162 piece_loc
= &last
->loc
;
5165 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5166 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5168 piece_bitpos
+= cur_bitsize
;
5169 piece_loc
= &XEXP (*piece_loc
, 1);
5173 /* TEMP->LAST here is either pointer to the last but one or
5174 last element in the chained list, LAST is pointer to the
5176 if (label
&& strcmp (last
->label
, label
) == 0)
5178 /* For SRA optimized variables if there weren't any real
5179 insns since last note, just modify the last node. */
5180 if (piece_loc
!= NULL
)
5182 adjust_piece_list (piece_loc
, NULL
, NULL
,
5183 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5186 /* If the last note doesn't cover any instructions, remove it. */
5187 if (temp
->last
!= last
)
5189 temp
->last
->next
= NULL
;
5192 gcc_assert (strcmp (last
->label
, label
) != 0);
5196 gcc_assert (temp
->first
== temp
->last
5197 || (temp
->first
->next
== temp
->last
5198 && TREE_CODE (decl
) == PARM_DECL
));
5199 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5200 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5204 if (bitsize
== -1 && NOTE_P (last
->loc
))
5205 last_loc_note
= last
->loc
;
5206 else if (piece_loc
!= NULL
5207 && *piece_loc
!= NULL_RTX
5208 && piece_bitpos
== bitpos
5209 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5210 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5212 last_loc_note
= NULL_RTX
;
5213 /* If the current location is the same as the end of the list,
5214 and either both or neither of the locations is uninitialized,
5215 we have nothing to do. */
5216 if (last_loc_note
== NULL_RTX
5217 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5218 NOTE_VAR_LOCATION_LOC (loc_note
)))
5219 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5220 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5221 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5222 == VAR_INIT_STATUS_UNINITIALIZED
)
5223 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5224 == VAR_INIT_STATUS_UNINITIALIZED
))))
5226 /* Add LOC to the end of list and update LAST. If the last
5227 element of the list has been removed above, reuse its
5228 memory for the new node, otherwise allocate a new one. */
5232 memset (loc
, '\0', sizeof (*loc
));
5235 loc
= ggc_alloc_cleared_var_loc_node ();
5236 if (bitsize
== -1 || piece_loc
== NULL
)
5237 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5239 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5240 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5242 /* Ensure TEMP->LAST will point either to the new last but one
5243 element of the chain, or to the last element in it. */
5244 if (last
!= temp
->last
)
5252 loc
= ggc_alloc_cleared_var_loc_node ();
5255 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5260 /* Keep track of the number of spaces used to indent the
5261 output of the debugging routines that print the structure of
5262 the DIE internal representation. */
5263 static int print_indent
;
5265 /* Indent the line the number of spaces given by print_indent. */
5268 print_spaces (FILE *outfile
)
5270 fprintf (outfile
, "%*s", print_indent
, "");
5273 /* Print a type signature in hex. */
5276 print_signature (FILE *outfile
, char *sig
)
5280 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5281 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5284 /* Print the information associated with a given DIE, and its children.
5285 This routine is a debugging aid only. */
5288 print_die (dw_die_ref die
, FILE *outfile
)
5294 print_spaces (outfile
);
5295 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5296 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5298 print_spaces (outfile
);
5299 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5300 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5301 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5303 if (die
->comdat_type_p
)
5305 print_spaces (outfile
);
5306 fprintf (outfile
, " signature: ");
5307 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5308 fprintf (outfile
, "\n");
5311 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5313 print_spaces (outfile
);
5314 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5316 switch (AT_class (a
))
5318 case dw_val_class_addr
:
5319 fprintf (outfile
, "address");
5321 case dw_val_class_offset
:
5322 fprintf (outfile
, "offset");
5324 case dw_val_class_loc
:
5325 fprintf (outfile
, "location descriptor");
5327 case dw_val_class_loc_list
:
5328 fprintf (outfile
, "location list -> label:%s",
5329 AT_loc_list (a
)->ll_symbol
);
5331 case dw_val_class_range_list
:
5332 fprintf (outfile
, "range list");
5334 case dw_val_class_const
:
5335 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5337 case dw_val_class_unsigned_const
:
5338 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5340 case dw_val_class_const_double
:
5341 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
5342 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5343 a
->dw_attr_val
.v
.val_double
.high
,
5344 a
->dw_attr_val
.v
.val_double
.low
);
5346 case dw_val_class_vec
:
5347 fprintf (outfile
, "floating-point or vector constant");
5349 case dw_val_class_flag
:
5350 fprintf (outfile
, "%u", AT_flag (a
));
5352 case dw_val_class_die_ref
:
5353 if (AT_ref (a
) != NULL
)
5355 if (AT_ref (a
)->comdat_type_p
)
5357 fprintf (outfile
, "die -> signature: ");
5358 print_signature (outfile
,
5359 AT_ref (a
)->die_id
.die_type_node
->signature
);
5361 else if (AT_ref (a
)->die_id
.die_symbol
)
5362 fprintf (outfile
, "die -> label: %s",
5363 AT_ref (a
)->die_id
.die_symbol
);
5365 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
5366 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
5369 fprintf (outfile
, "die -> <null>");
5371 case dw_val_class_vms_delta
:
5372 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5373 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
5375 case dw_val_class_lbl_id
:
5376 case dw_val_class_lineptr
:
5377 case dw_val_class_macptr
:
5378 case dw_val_class_high_pc
:
5379 fprintf (outfile
, "label: %s", AT_lbl (a
));
5381 case dw_val_class_str
:
5382 if (AT_string (a
) != NULL
)
5383 fprintf (outfile
, "\"%s\"", AT_string (a
));
5385 fprintf (outfile
, "<null>");
5387 case dw_val_class_file
:
5388 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
5389 AT_file (a
)->emitted_number
);
5391 case dw_val_class_data8
:
5395 for (i
= 0; i
< 8; i
++)
5396 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
5403 fprintf (outfile
, "\n");
5406 if (die
->die_child
!= NULL
)
5409 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5412 if (print_indent
== 0)
5413 fprintf (outfile
, "\n");
5416 /* Print the information collected for a given DIE. */
5419 debug_dwarf_die (dw_die_ref die
)
5421 print_die (die
, stderr
);
5424 /* Print all DWARF information collected for the compilation unit.
5425 This routine is a debugging aid only. */
5431 print_die (comp_unit_die (), stderr
);
5434 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5435 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5436 DIE that marks the start of the DIEs for this include file. */
5439 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5441 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5442 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5444 new_unit
->die_sib
= old_unit
;
5448 /* Close an include-file CU and reopen the enclosing one. */
5451 pop_compile_unit (dw_die_ref old_unit
)
5453 dw_die_ref new_unit
= old_unit
->die_sib
;
5455 old_unit
->die_sib
= NULL
;
5459 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5460 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5462 /* Calculate the checksum of a location expression. */
5465 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5469 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5471 CHECKSUM (loc
->dw_loc_oprnd1
);
5472 CHECKSUM (loc
->dw_loc_oprnd2
);
5475 /* Calculate the checksum of an attribute. */
5478 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5480 dw_loc_descr_ref loc
;
5483 CHECKSUM (at
->dw_attr
);
5485 /* We don't care that this was compiled with a different compiler
5486 snapshot; if the output is the same, that's what matters. */
5487 if (at
->dw_attr
== DW_AT_producer
)
5490 switch (AT_class (at
))
5492 case dw_val_class_const
:
5493 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5495 case dw_val_class_unsigned_const
:
5496 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5498 case dw_val_class_const_double
:
5499 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5501 case dw_val_class_vec
:
5502 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5504 case dw_val_class_flag
:
5505 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5507 case dw_val_class_str
:
5508 CHECKSUM_STRING (AT_string (at
));
5511 case dw_val_class_addr
:
5513 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5514 CHECKSUM_STRING (XSTR (r
, 0));
5517 case dw_val_class_offset
:
5518 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5521 case dw_val_class_loc
:
5522 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5523 loc_checksum (loc
, ctx
);
5526 case dw_val_class_die_ref
:
5527 die_checksum (AT_ref (at
), ctx
, mark
);
5530 case dw_val_class_fde_ref
:
5531 case dw_val_class_vms_delta
:
5532 case dw_val_class_lbl_id
:
5533 case dw_val_class_lineptr
:
5534 case dw_val_class_macptr
:
5535 case dw_val_class_high_pc
:
5538 case dw_val_class_file
:
5539 CHECKSUM_STRING (AT_file (at
)->filename
);
5542 case dw_val_class_data8
:
5543 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5551 /* Calculate the checksum of a DIE. */
5554 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5560 /* To avoid infinite recursion. */
5563 CHECKSUM (die
->die_mark
);
5566 die
->die_mark
= ++(*mark
);
5568 CHECKSUM (die
->die_tag
);
5570 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5571 attr_checksum (a
, ctx
, mark
);
5573 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5577 #undef CHECKSUM_STRING
5579 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5580 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5581 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5582 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5583 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5584 #define CHECKSUM_ATTR(FOO) \
5585 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5587 /* Calculate the checksum of a number in signed LEB128 format. */
5590 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5597 byte
= (value
& 0x7f);
5599 more
= !((value
== 0 && (byte
& 0x40) == 0)
5600 || (value
== -1 && (byte
& 0x40) != 0));
5609 /* Calculate the checksum of a number in unsigned LEB128 format. */
5612 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5616 unsigned char byte
= (value
& 0x7f);
5619 /* More bytes to follow. */
5627 /* Checksum the context of the DIE. This adds the names of any
5628 surrounding namespaces or structures to the checksum. */
5631 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5635 int tag
= die
->die_tag
;
5637 if (tag
!= DW_TAG_namespace
5638 && tag
!= DW_TAG_structure_type
5639 && tag
!= DW_TAG_class_type
)
5642 name
= get_AT_string (die
, DW_AT_name
);
5644 spec
= get_AT_ref (die
, DW_AT_specification
);
5648 if (die
->die_parent
!= NULL
)
5649 checksum_die_context (die
->die_parent
, ctx
);
5651 CHECKSUM_ULEB128 ('C');
5652 CHECKSUM_ULEB128 (tag
);
5654 CHECKSUM_STRING (name
);
5657 /* Calculate the checksum of a location expression. */
5660 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5662 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5663 were emitted as a DW_FORM_sdata instead of a location expression. */
5664 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5666 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5667 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5671 /* Otherwise, just checksum the raw location expression. */
5674 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5675 CHECKSUM (loc
->dw_loc_oprnd1
);
5676 CHECKSUM (loc
->dw_loc_oprnd2
);
5677 loc
= loc
->dw_loc_next
;
5681 /* Calculate the checksum of an attribute. */
5684 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5685 struct md5_ctx
*ctx
, int *mark
)
5687 dw_loc_descr_ref loc
;
5690 if (AT_class (at
) == dw_val_class_die_ref
)
5692 dw_die_ref target_die
= AT_ref (at
);
5694 /* For pointer and reference types, we checksum only the (qualified)
5695 name of the target type (if there is a name). For friend entries,
5696 we checksum only the (qualified) name of the target type or function.
5697 This allows the checksum to remain the same whether the target type
5698 is complete or not. */
5699 if ((at
->dw_attr
== DW_AT_type
5700 && (tag
== DW_TAG_pointer_type
5701 || tag
== DW_TAG_reference_type
5702 || tag
== DW_TAG_rvalue_reference_type
5703 || tag
== DW_TAG_ptr_to_member_type
))
5704 || (at
->dw_attr
== DW_AT_friend
5705 && tag
== DW_TAG_friend
))
5707 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5709 if (name_attr
!= NULL
)
5711 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5715 CHECKSUM_ULEB128 ('N');
5716 CHECKSUM_ULEB128 (at
->dw_attr
);
5717 if (decl
->die_parent
!= NULL
)
5718 checksum_die_context (decl
->die_parent
, ctx
);
5719 CHECKSUM_ULEB128 ('E');
5720 CHECKSUM_STRING (AT_string (name_attr
));
5725 /* For all other references to another DIE, we check to see if the
5726 target DIE has already been visited. If it has, we emit a
5727 backward reference; if not, we descend recursively. */
5728 if (target_die
->die_mark
> 0)
5730 CHECKSUM_ULEB128 ('R');
5731 CHECKSUM_ULEB128 (at
->dw_attr
);
5732 CHECKSUM_ULEB128 (target_die
->die_mark
);
5736 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5740 target_die
->die_mark
= ++(*mark
);
5741 CHECKSUM_ULEB128 ('T');
5742 CHECKSUM_ULEB128 (at
->dw_attr
);
5743 if (decl
->die_parent
!= NULL
)
5744 checksum_die_context (decl
->die_parent
, ctx
);
5745 die_checksum_ordered (target_die
, ctx
, mark
);
5750 CHECKSUM_ULEB128 ('A');
5751 CHECKSUM_ULEB128 (at
->dw_attr
);
5753 switch (AT_class (at
))
5755 case dw_val_class_const
:
5756 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5757 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5760 case dw_val_class_unsigned_const
:
5761 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5762 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5765 case dw_val_class_const_double
:
5766 CHECKSUM_ULEB128 (DW_FORM_block
);
5767 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5768 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5771 case dw_val_class_vec
:
5772 CHECKSUM_ULEB128 (DW_FORM_block
);
5773 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_vec
));
5774 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5777 case dw_val_class_flag
:
5778 CHECKSUM_ULEB128 (DW_FORM_flag
);
5779 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
5782 case dw_val_class_str
:
5783 CHECKSUM_ULEB128 (DW_FORM_string
);
5784 CHECKSUM_STRING (AT_string (at
));
5787 case dw_val_class_addr
:
5789 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5790 CHECKSUM_ULEB128 (DW_FORM_string
);
5791 CHECKSUM_STRING (XSTR (r
, 0));
5794 case dw_val_class_offset
:
5795 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5796 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
5799 case dw_val_class_loc
:
5800 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5801 loc_checksum_ordered (loc
, ctx
);
5804 case dw_val_class_fde_ref
:
5805 case dw_val_class_lbl_id
:
5806 case dw_val_class_lineptr
:
5807 case dw_val_class_macptr
:
5808 case dw_val_class_high_pc
:
5811 case dw_val_class_file
:
5812 CHECKSUM_ULEB128 (DW_FORM_string
);
5813 CHECKSUM_STRING (AT_file (at
)->filename
);
5816 case dw_val_class_data8
:
5817 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5825 struct checksum_attributes
5827 dw_attr_ref at_name
;
5828 dw_attr_ref at_type
;
5829 dw_attr_ref at_friend
;
5830 dw_attr_ref at_accessibility
;
5831 dw_attr_ref at_address_class
;
5832 dw_attr_ref at_allocated
;
5833 dw_attr_ref at_artificial
;
5834 dw_attr_ref at_associated
;
5835 dw_attr_ref at_binary_scale
;
5836 dw_attr_ref at_bit_offset
;
5837 dw_attr_ref at_bit_size
;
5838 dw_attr_ref at_bit_stride
;
5839 dw_attr_ref at_byte_size
;
5840 dw_attr_ref at_byte_stride
;
5841 dw_attr_ref at_const_value
;
5842 dw_attr_ref at_containing_type
;
5843 dw_attr_ref at_count
;
5844 dw_attr_ref at_data_location
;
5845 dw_attr_ref at_data_member_location
;
5846 dw_attr_ref at_decimal_scale
;
5847 dw_attr_ref at_decimal_sign
;
5848 dw_attr_ref at_default_value
;
5849 dw_attr_ref at_digit_count
;
5850 dw_attr_ref at_discr
;
5851 dw_attr_ref at_discr_list
;
5852 dw_attr_ref at_discr_value
;
5853 dw_attr_ref at_encoding
;
5854 dw_attr_ref at_endianity
;
5855 dw_attr_ref at_explicit
;
5856 dw_attr_ref at_is_optional
;
5857 dw_attr_ref at_location
;
5858 dw_attr_ref at_lower_bound
;
5859 dw_attr_ref at_mutable
;
5860 dw_attr_ref at_ordering
;
5861 dw_attr_ref at_picture_string
;
5862 dw_attr_ref at_prototyped
;
5863 dw_attr_ref at_small
;
5864 dw_attr_ref at_segment
;
5865 dw_attr_ref at_string_length
;
5866 dw_attr_ref at_threads_scaled
;
5867 dw_attr_ref at_upper_bound
;
5868 dw_attr_ref at_use_location
;
5869 dw_attr_ref at_use_UTF8
;
5870 dw_attr_ref at_variable_parameter
;
5871 dw_attr_ref at_virtuality
;
5872 dw_attr_ref at_visibility
;
5873 dw_attr_ref at_vtable_elem_location
;
5876 /* Collect the attributes that we will want to use for the checksum. */
5879 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
5884 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5895 attrs
->at_friend
= a
;
5897 case DW_AT_accessibility
:
5898 attrs
->at_accessibility
= a
;
5900 case DW_AT_address_class
:
5901 attrs
->at_address_class
= a
;
5903 case DW_AT_allocated
:
5904 attrs
->at_allocated
= a
;
5906 case DW_AT_artificial
:
5907 attrs
->at_artificial
= a
;
5909 case DW_AT_associated
:
5910 attrs
->at_associated
= a
;
5912 case DW_AT_binary_scale
:
5913 attrs
->at_binary_scale
= a
;
5915 case DW_AT_bit_offset
:
5916 attrs
->at_bit_offset
= a
;
5918 case DW_AT_bit_size
:
5919 attrs
->at_bit_size
= a
;
5921 case DW_AT_bit_stride
:
5922 attrs
->at_bit_stride
= a
;
5924 case DW_AT_byte_size
:
5925 attrs
->at_byte_size
= a
;
5927 case DW_AT_byte_stride
:
5928 attrs
->at_byte_stride
= a
;
5930 case DW_AT_const_value
:
5931 attrs
->at_const_value
= a
;
5933 case DW_AT_containing_type
:
5934 attrs
->at_containing_type
= a
;
5937 attrs
->at_count
= a
;
5939 case DW_AT_data_location
:
5940 attrs
->at_data_location
= a
;
5942 case DW_AT_data_member_location
:
5943 attrs
->at_data_member_location
= a
;
5945 case DW_AT_decimal_scale
:
5946 attrs
->at_decimal_scale
= a
;
5948 case DW_AT_decimal_sign
:
5949 attrs
->at_decimal_sign
= a
;
5951 case DW_AT_default_value
:
5952 attrs
->at_default_value
= a
;
5954 case DW_AT_digit_count
:
5955 attrs
->at_digit_count
= a
;
5958 attrs
->at_discr
= a
;
5960 case DW_AT_discr_list
:
5961 attrs
->at_discr_list
= a
;
5963 case DW_AT_discr_value
:
5964 attrs
->at_discr_value
= a
;
5966 case DW_AT_encoding
:
5967 attrs
->at_encoding
= a
;
5969 case DW_AT_endianity
:
5970 attrs
->at_endianity
= a
;
5972 case DW_AT_explicit
:
5973 attrs
->at_explicit
= a
;
5975 case DW_AT_is_optional
:
5976 attrs
->at_is_optional
= a
;
5978 case DW_AT_location
:
5979 attrs
->at_location
= a
;
5981 case DW_AT_lower_bound
:
5982 attrs
->at_lower_bound
= a
;
5985 attrs
->at_mutable
= a
;
5987 case DW_AT_ordering
:
5988 attrs
->at_ordering
= a
;
5990 case DW_AT_picture_string
:
5991 attrs
->at_picture_string
= a
;
5993 case DW_AT_prototyped
:
5994 attrs
->at_prototyped
= a
;
5997 attrs
->at_small
= a
;
6000 attrs
->at_segment
= a
;
6002 case DW_AT_string_length
:
6003 attrs
->at_string_length
= a
;
6005 case DW_AT_threads_scaled
:
6006 attrs
->at_threads_scaled
= a
;
6008 case DW_AT_upper_bound
:
6009 attrs
->at_upper_bound
= a
;
6011 case DW_AT_use_location
:
6012 attrs
->at_use_location
= a
;
6014 case DW_AT_use_UTF8
:
6015 attrs
->at_use_UTF8
= a
;
6017 case DW_AT_variable_parameter
:
6018 attrs
->at_variable_parameter
= a
;
6020 case DW_AT_virtuality
:
6021 attrs
->at_virtuality
= a
;
6023 case DW_AT_visibility
:
6024 attrs
->at_visibility
= a
;
6026 case DW_AT_vtable_elem_location
:
6027 attrs
->at_vtable_elem_location
= a
;
6035 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6038 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6042 struct checksum_attributes attrs
;
6044 CHECKSUM_ULEB128 ('D');
6045 CHECKSUM_ULEB128 (die
->die_tag
);
6047 memset (&attrs
, 0, sizeof (attrs
));
6049 decl
= get_AT_ref (die
, DW_AT_specification
);
6051 collect_checksum_attributes (&attrs
, decl
);
6052 collect_checksum_attributes (&attrs
, die
);
6054 CHECKSUM_ATTR (attrs
.at_name
);
6055 CHECKSUM_ATTR (attrs
.at_accessibility
);
6056 CHECKSUM_ATTR (attrs
.at_address_class
);
6057 CHECKSUM_ATTR (attrs
.at_allocated
);
6058 CHECKSUM_ATTR (attrs
.at_artificial
);
6059 CHECKSUM_ATTR (attrs
.at_associated
);
6060 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6061 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6062 CHECKSUM_ATTR (attrs
.at_bit_size
);
6063 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6064 CHECKSUM_ATTR (attrs
.at_byte_size
);
6065 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6066 CHECKSUM_ATTR (attrs
.at_const_value
);
6067 CHECKSUM_ATTR (attrs
.at_containing_type
);
6068 CHECKSUM_ATTR (attrs
.at_count
);
6069 CHECKSUM_ATTR (attrs
.at_data_location
);
6070 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6071 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6072 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6073 CHECKSUM_ATTR (attrs
.at_default_value
);
6074 CHECKSUM_ATTR (attrs
.at_digit_count
);
6075 CHECKSUM_ATTR (attrs
.at_discr
);
6076 CHECKSUM_ATTR (attrs
.at_discr_list
);
6077 CHECKSUM_ATTR (attrs
.at_discr_value
);
6078 CHECKSUM_ATTR (attrs
.at_encoding
);
6079 CHECKSUM_ATTR (attrs
.at_endianity
);
6080 CHECKSUM_ATTR (attrs
.at_explicit
);
6081 CHECKSUM_ATTR (attrs
.at_is_optional
);
6082 CHECKSUM_ATTR (attrs
.at_location
);
6083 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6084 CHECKSUM_ATTR (attrs
.at_mutable
);
6085 CHECKSUM_ATTR (attrs
.at_ordering
);
6086 CHECKSUM_ATTR (attrs
.at_picture_string
);
6087 CHECKSUM_ATTR (attrs
.at_prototyped
);
6088 CHECKSUM_ATTR (attrs
.at_small
);
6089 CHECKSUM_ATTR (attrs
.at_segment
);
6090 CHECKSUM_ATTR (attrs
.at_string_length
);
6091 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6092 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6093 CHECKSUM_ATTR (attrs
.at_use_location
);
6094 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6095 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6096 CHECKSUM_ATTR (attrs
.at_virtuality
);
6097 CHECKSUM_ATTR (attrs
.at_visibility
);
6098 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6099 CHECKSUM_ATTR (attrs
.at_type
);
6100 CHECKSUM_ATTR (attrs
.at_friend
);
6102 /* Checksum the child DIEs, except for nested types and member functions. */
6105 dw_attr_ref name_attr
;
6108 name_attr
= get_AT (c
, DW_AT_name
);
6109 if ((is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
)
6110 && name_attr
!= NULL
)
6112 CHECKSUM_ULEB128 ('S');
6113 CHECKSUM_ULEB128 (c
->die_tag
);
6114 CHECKSUM_STRING (AT_string (name_attr
));
6118 /* Mark this DIE so it gets processed when unmarking. */
6119 if (c
->die_mark
== 0)
6121 die_checksum_ordered (c
, ctx
, mark
);
6123 } while (c
!= die
->die_child
);
6125 CHECKSUM_ULEB128 (0);
6129 #undef CHECKSUM_STRING
6130 #undef CHECKSUM_ATTR
6131 #undef CHECKSUM_LEB128
6132 #undef CHECKSUM_ULEB128
6134 /* Generate the type signature for DIE. This is computed by generating an
6135 MD5 checksum over the DIE's tag, its relevant attributes, and its
6136 children. Attributes that are references to other DIEs are processed
6137 by recursion, using the MARK field to prevent infinite recursion.
6138 If the DIE is nested inside a namespace or another type, we also
6139 need to include that context in the signature. The lower 64 bits
6140 of the resulting MD5 checksum comprise the signature. */
6143 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6147 unsigned char checksum
[16];
6152 name
= get_AT_string (die
, DW_AT_name
);
6153 decl
= get_AT_ref (die
, DW_AT_specification
);
6154 parent
= get_die_parent (die
);
6156 /* First, compute a signature for just the type name (and its surrounding
6157 context, if any. This is stored in the type unit DIE for link-time
6158 ODR (one-definition rule) checking. */
6160 if (is_cxx() && name
!= NULL
)
6162 md5_init_ctx (&ctx
);
6164 /* Checksum the names of surrounding namespaces and structures. */
6166 checksum_die_context (parent
, &ctx
);
6168 md5_process_bytes (&die
->die_tag
, sizeof (die
->die_tag
), &ctx
);
6169 md5_process_bytes (name
, strlen (name
) + 1, &ctx
);
6170 md5_finish_ctx (&ctx
, checksum
);
6172 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6175 /* Next, compute the complete type signature. */
6177 md5_init_ctx (&ctx
);
6179 die
->die_mark
= mark
;
6181 /* Checksum the names of surrounding namespaces and structures. */
6183 checksum_die_context (parent
, &ctx
);
6185 /* Checksum the DIE and its children. */
6186 die_checksum_ordered (die
, &ctx
, &mark
);
6187 unmark_all_dies (die
);
6188 md5_finish_ctx (&ctx
, checksum
);
6190 /* Store the signature in the type node and link the type DIE and the
6191 type node together. */
6192 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6193 DWARF_TYPE_SIGNATURE_SIZE
);
6194 die
->comdat_type_p
= true;
6195 die
->die_id
.die_type_node
= type_node
;
6196 type_node
->type_die
= die
;
6198 /* If the DIE is a specification, link its declaration to the type node
6202 decl
->comdat_type_p
= true;
6203 decl
->die_id
.die_type_node
= type_node
;
6207 /* Do the location expressions look same? */
6209 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6211 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6212 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6213 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6216 /* Do the values look the same? */
6218 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6220 dw_loc_descr_ref loc1
, loc2
;
6223 if (v1
->val_class
!= v2
->val_class
)
6226 switch (v1
->val_class
)
6228 case dw_val_class_const
:
6229 return v1
->v
.val_int
== v2
->v
.val_int
;
6230 case dw_val_class_unsigned_const
:
6231 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6232 case dw_val_class_const_double
:
6233 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6234 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6235 case dw_val_class_vec
:
6236 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6237 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6239 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6240 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6243 case dw_val_class_flag
:
6244 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6245 case dw_val_class_str
:
6246 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6248 case dw_val_class_addr
:
6249 r1
= v1
->v
.val_addr
;
6250 r2
= v2
->v
.val_addr
;
6251 if (GET_CODE (r1
) != GET_CODE (r2
))
6253 return !rtx_equal_p (r1
, r2
);
6255 case dw_val_class_offset
:
6256 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6258 case dw_val_class_loc
:
6259 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6261 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6262 if (!same_loc_p (loc1
, loc2
, mark
))
6264 return !loc1
&& !loc2
;
6266 case dw_val_class_die_ref
:
6267 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6269 case dw_val_class_fde_ref
:
6270 case dw_val_class_vms_delta
:
6271 case dw_val_class_lbl_id
:
6272 case dw_val_class_lineptr
:
6273 case dw_val_class_macptr
:
6274 case dw_val_class_high_pc
:
6277 case dw_val_class_file
:
6278 return v1
->v
.val_file
== v2
->v
.val_file
;
6280 case dw_val_class_data8
:
6281 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6288 /* Do the attributes look the same? */
6291 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6293 if (at1
->dw_attr
!= at2
->dw_attr
)
6296 /* We don't care that this was compiled with a different compiler
6297 snapshot; if the output is the same, that's what matters. */
6298 if (at1
->dw_attr
== DW_AT_producer
)
6301 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6304 /* Do the dies look the same? */
6307 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6313 /* To avoid infinite recursion. */
6315 return die1
->die_mark
== die2
->die_mark
;
6316 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6318 if (die1
->die_tag
!= die2
->die_tag
)
6321 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6324 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6325 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6328 c1
= die1
->die_child
;
6329 c2
= die2
->die_child
;
6338 if (!same_die_p (c1
, c2
, mark
))
6342 if (c1
== die1
->die_child
)
6344 if (c2
== die2
->die_child
)
6354 /* Do the dies look the same? Wrapper around same_die_p. */
6357 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6360 int ret
= same_die_p (die1
, die2
, &mark
);
6362 unmark_all_dies (die1
);
6363 unmark_all_dies (die2
);
6368 /* The prefix to attach to symbols on DIEs in the current comdat debug
6370 static const char *comdat_symbol_id
;
6372 /* The index of the current symbol within the current comdat CU. */
6373 static unsigned int comdat_symbol_number
;
6375 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6376 children, and set comdat_symbol_id accordingly. */
6379 compute_section_prefix (dw_die_ref unit_die
)
6381 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6382 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6383 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6386 unsigned char checksum
[16];
6389 /* Compute the checksum of the DIE, then append part of it as hex digits to
6390 the name filename of the unit. */
6392 md5_init_ctx (&ctx
);
6394 die_checksum (unit_die
, &ctx
, &mark
);
6395 unmark_all_dies (unit_die
);
6396 md5_finish_ctx (&ctx
, checksum
);
6398 sprintf (name
, "%s.", base
);
6399 clean_symbol_name (name
);
6401 p
= name
+ strlen (name
);
6402 for (i
= 0; i
< 4; i
++)
6404 sprintf (p
, "%.2x", checksum
[i
]);
6408 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6409 comdat_symbol_number
= 0;
6412 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6415 is_type_die (dw_die_ref die
)
6417 switch (die
->die_tag
)
6419 case DW_TAG_array_type
:
6420 case DW_TAG_class_type
:
6421 case DW_TAG_interface_type
:
6422 case DW_TAG_enumeration_type
:
6423 case DW_TAG_pointer_type
:
6424 case DW_TAG_reference_type
:
6425 case DW_TAG_rvalue_reference_type
:
6426 case DW_TAG_string_type
:
6427 case DW_TAG_structure_type
:
6428 case DW_TAG_subroutine_type
:
6429 case DW_TAG_union_type
:
6430 case DW_TAG_ptr_to_member_type
:
6431 case DW_TAG_set_type
:
6432 case DW_TAG_subrange_type
:
6433 case DW_TAG_base_type
:
6434 case DW_TAG_const_type
:
6435 case DW_TAG_file_type
:
6436 case DW_TAG_packed_type
:
6437 case DW_TAG_volatile_type
:
6438 case DW_TAG_typedef
:
6445 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6446 Basically, we want to choose the bits that are likely to be shared between
6447 compilations (types) and leave out the bits that are specific to individual
6448 compilations (functions). */
6451 is_comdat_die (dw_die_ref c
)
6453 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6454 we do for stabs. The advantage is a greater likelihood of sharing between
6455 objects that don't include headers in the same order (and therefore would
6456 put the base types in a different comdat). jason 8/28/00 */
6458 if (c
->die_tag
== DW_TAG_base_type
)
6461 if (c
->die_tag
== DW_TAG_pointer_type
6462 || c
->die_tag
== DW_TAG_reference_type
6463 || c
->die_tag
== DW_TAG_rvalue_reference_type
6464 || c
->die_tag
== DW_TAG_const_type
6465 || c
->die_tag
== DW_TAG_volatile_type
)
6467 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6469 return t
? is_comdat_die (t
) : 0;
6472 return is_type_die (c
);
6475 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6476 compilation unit. */
6479 is_symbol_die (dw_die_ref c
)
6481 return (is_type_die (c
)
6482 || is_declaration_die (c
)
6483 || c
->die_tag
== DW_TAG_namespace
6484 || c
->die_tag
== DW_TAG_module
);
6487 /* Returns true iff C is a compile-unit DIE. */
6490 is_cu_die (dw_die_ref c
)
6492 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6495 /* Returns true iff C is a unit DIE of some sort. */
6498 is_unit_die (dw_die_ref c
)
6500 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6501 || c
->die_tag
== DW_TAG_partial_unit
6502 || c
->die_tag
== DW_TAG_type_unit
);
6505 /* Returns true iff C is a namespace DIE. */
6508 is_namespace_die (dw_die_ref c
)
6510 return c
&& c
->die_tag
== DW_TAG_namespace
;
6513 /* Returns true iff C is a class or structure DIE. */
6516 is_class_die (dw_die_ref c
)
6518 return c
&& (c
->die_tag
== DW_TAG_class_type
6519 || c
->die_tag
== DW_TAG_structure_type
);
6523 gen_internal_sym (const char *prefix
)
6527 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6528 return xstrdup (buf
);
6531 /* Assign symbols to all worthy DIEs under DIE. */
6534 assign_symbol_names (dw_die_ref die
)
6538 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6540 if (comdat_symbol_id
)
6542 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6544 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6545 comdat_symbol_id
, comdat_symbol_number
++);
6546 die
->die_id
.die_symbol
= xstrdup (p
);
6549 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6552 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6555 struct cu_hash_table_entry
6558 unsigned min_comdat_num
, max_comdat_num
;
6559 struct cu_hash_table_entry
*next
;
6562 /* Routines to manipulate hash table of CUs. */
6564 htab_cu_hash (const void *of
)
6566 const struct cu_hash_table_entry
*const entry
=
6567 (const struct cu_hash_table_entry
*) of
;
6569 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6573 htab_cu_eq (const void *of1
, const void *of2
)
6575 const struct cu_hash_table_entry
*const entry1
=
6576 (const struct cu_hash_table_entry
*) of1
;
6577 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
6579 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6583 htab_cu_del (void *what
)
6585 struct cu_hash_table_entry
*next
,
6586 *entry
= (struct cu_hash_table_entry
*) what
;
6596 /* Check whether we have already seen this CU and set up SYM_NUM
6599 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
6601 struct cu_hash_table_entry dummy
;
6602 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6604 dummy
.max_comdat_num
= 0;
6606 slot
= (struct cu_hash_table_entry
**)
6607 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6611 for (; entry
; last
= entry
, entry
= entry
->next
)
6613 if (same_die_p_wrap (cu
, entry
->cu
))
6619 *sym_num
= entry
->min_comdat_num
;
6623 entry
= XCNEW (struct cu_hash_table_entry
);
6625 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6626 entry
->next
= *slot
;
6632 /* Record SYM_NUM to record of CU in HTABLE. */
6634 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
6636 struct cu_hash_table_entry
**slot
, *entry
;
6638 slot
= (struct cu_hash_table_entry
**)
6639 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6643 entry
->max_comdat_num
= sym_num
;
6646 /* Traverse the DIE (which is always comp_unit_die), and set up
6647 additional compilation units for each of the include files we see
6648 bracketed by BINCL/EINCL. */
6651 break_out_includes (dw_die_ref die
)
6654 dw_die_ref unit
= NULL
;
6655 limbo_die_node
*node
, **pnode
;
6656 htab_t cu_hash_table
;
6660 dw_die_ref prev
= c
;
6662 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6663 || (unit
&& is_comdat_die (c
)))
6665 dw_die_ref next
= c
->die_sib
;
6667 /* This DIE is for a secondary CU; remove it from the main one. */
6668 remove_child_with_prev (c
, prev
);
6670 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6671 unit
= push_new_compile_unit (unit
, c
);
6672 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6673 unit
= pop_compile_unit (unit
);
6675 add_child_die (unit
, c
);
6677 if (c
== die
->die_child
)
6680 } while (c
!= die
->die_child
);
6683 /* We can only use this in debugging, since the frontend doesn't check
6684 to make sure that we leave every include file we enter. */
6688 assign_symbol_names (die
);
6689 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
6690 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6696 compute_section_prefix (node
->die
);
6697 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6698 &comdat_symbol_number
);
6699 assign_symbol_names (node
->die
);
6701 *pnode
= node
->next
;
6704 pnode
= &node
->next
;
6705 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6706 comdat_symbol_number
);
6709 htab_delete (cu_hash_table
);
6712 /* Return non-zero if this DIE is a declaration. */
6715 is_declaration_die (dw_die_ref die
)
6720 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6721 if (a
->dw_attr
== DW_AT_declaration
)
6727 /* Return non-zero if this DIE is nested inside a subprogram. */
6730 is_nested_in_subprogram (dw_die_ref die
)
6732 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6736 return local_scope_p (decl
);
6739 /* Return non-zero if this DIE contains a defining declaration of a
6743 contains_subprogram_definition (dw_die_ref die
)
6747 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6749 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition(c
)) return 1);
6753 /* Return non-zero if this is a type DIE that should be moved to a
6754 COMDAT .debug_types section. */
6757 should_move_die_to_comdat (dw_die_ref die
)
6759 switch (die
->die_tag
)
6761 case DW_TAG_class_type
:
6762 case DW_TAG_structure_type
:
6763 case DW_TAG_enumeration_type
:
6764 case DW_TAG_union_type
:
6765 /* Don't move declarations, inlined instances, types nested in a
6766 subprogram, or types that contain subprogram definitions. */
6767 if (is_declaration_die (die
)
6768 || get_AT (die
, DW_AT_abstract_origin
)
6769 || is_nested_in_subprogram (die
)
6770 || contains_subprogram_definition (die
))
6773 case DW_TAG_array_type
:
6774 case DW_TAG_interface_type
:
6775 case DW_TAG_pointer_type
:
6776 case DW_TAG_reference_type
:
6777 case DW_TAG_rvalue_reference_type
:
6778 case DW_TAG_string_type
:
6779 case DW_TAG_subroutine_type
:
6780 case DW_TAG_ptr_to_member_type
:
6781 case DW_TAG_set_type
:
6782 case DW_TAG_subrange_type
:
6783 case DW_TAG_base_type
:
6784 case DW_TAG_const_type
:
6785 case DW_TAG_file_type
:
6786 case DW_TAG_packed_type
:
6787 case DW_TAG_volatile_type
:
6788 case DW_TAG_typedef
:
6794 /* Make a clone of DIE. */
6797 clone_die (dw_die_ref die
)
6803 clone
= ggc_alloc_cleared_die_node ();
6804 clone
->die_tag
= die
->die_tag
;
6806 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6807 add_dwarf_attr (clone
, a
);
6812 /* Make a clone of the tree rooted at DIE. */
6815 clone_tree (dw_die_ref die
)
6818 dw_die_ref clone
= clone_die (die
);
6820 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree(c
)));
6825 /* Make a clone of DIE as a declaration. */
6828 clone_as_declaration (dw_die_ref die
)
6835 /* If the DIE is already a declaration, just clone it. */
6836 if (is_declaration_die (die
))
6837 return clone_die (die
);
6839 /* If the DIE is a specification, just clone its declaration DIE. */
6840 decl
= get_AT_ref (die
, DW_AT_specification
);
6843 clone
= clone_die (decl
);
6844 if (die
->comdat_type_p
)
6845 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6849 clone
= ggc_alloc_cleared_die_node ();
6850 clone
->die_tag
= die
->die_tag
;
6852 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6854 /* We don't want to copy over all attributes.
6855 For example we don't want DW_AT_byte_size because otherwise we will no
6856 longer have a declaration and GDB will treat it as a definition. */
6860 case DW_AT_abstract_origin
:
6861 case DW_AT_artificial
:
6862 case DW_AT_containing_type
:
6863 case DW_AT_external
:
6866 case DW_AT_virtuality
:
6867 case DW_AT_linkage_name
:
6868 case DW_AT_MIPS_linkage_name
:
6869 add_dwarf_attr (clone
, a
);
6871 case DW_AT_byte_size
:
6877 if (die
->comdat_type_p
)
6878 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6880 add_AT_flag (clone
, DW_AT_declaration
, 1);
6884 /* Copy the declaration context to the new type unit DIE. This includes
6885 any surrounding namespace or type declarations. If the DIE has an
6886 AT_specification attribute, it also includes attributes and children
6887 attached to the specification, and returns a pointer to the original
6888 parent of the declaration DIE. Returns NULL otherwise. */
6891 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
6894 dw_die_ref new_decl
;
6895 dw_die_ref orig_parent
= NULL
;
6897 decl
= get_AT_ref (die
, DW_AT_specification
);
6906 /* The original DIE will be changed to a declaration, and must
6907 be moved to be a child of the original declaration DIE. */
6908 orig_parent
= decl
->die_parent
;
6910 /* Copy the type node pointer from the new DIE to the original
6911 declaration DIE so we can forward references later. */
6912 decl
->comdat_type_p
= true;
6913 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
6915 remove_AT (die
, DW_AT_specification
);
6917 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
6919 if (a
->dw_attr
!= DW_AT_name
6920 && a
->dw_attr
!= DW_AT_declaration
6921 && a
->dw_attr
!= DW_AT_external
)
6922 add_dwarf_attr (die
, a
);
6925 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree(c
)));
6928 if (decl
->die_parent
!= NULL
6929 && !is_unit_die (decl
->die_parent
))
6931 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
6932 if (new_decl
!= NULL
)
6934 remove_AT (new_decl
, DW_AT_signature
);
6935 add_AT_specification (die
, new_decl
);
6942 /* Generate the skeleton ancestor tree for the given NODE, then clone
6943 the DIE and add the clone into the tree. */
6946 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
6948 if (node
->new_die
!= NULL
)
6951 node
->new_die
= clone_as_declaration (node
->old_die
);
6953 if (node
->parent
!= NULL
)
6955 generate_skeleton_ancestor_tree (node
->parent
);
6956 add_child_die (node
->parent
->new_die
, node
->new_die
);
6960 /* Generate a skeleton tree of DIEs containing any declarations that are
6961 found in the original tree. We traverse the tree looking for declaration
6962 DIEs, and construct the skeleton from the bottom up whenever we find one. */
6965 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
6967 skeleton_chain_node node
;
6970 dw_die_ref prev
= NULL
;
6971 dw_die_ref next
= NULL
;
6973 node
.parent
= parent
;
6975 first
= c
= parent
->old_die
->die_child
;
6979 if (prev
== NULL
|| prev
->die_sib
== c
)
6982 next
= (c
== first
? NULL
: c
->die_sib
);
6984 node
.new_die
= NULL
;
6985 if (is_declaration_die (c
))
6987 /* Clone the existing DIE, move the original to the skeleton
6988 tree (which is in the main CU), and put the clone, with
6989 all the original's children, where the original came from. */
6990 dw_die_ref clone
= clone_die (c
);
6991 move_all_children (c
, clone
);
6993 /* If the original has a DW_AT_object_pointer attribute,
6994 it would now point to a child DIE just moved to the
6995 cloned tree, so we need to remove that attribute from
6997 remove_AT (c
, DW_AT_object_pointer
);
6999 replace_child (c
, clone
, prev
);
7000 generate_skeleton_ancestor_tree (parent
);
7001 add_child_die (parent
->new_die
, c
);
7005 generate_skeleton_bottom_up (&node
);
7006 } while (next
!= NULL
);
7009 /* Wrapper function for generate_skeleton_bottom_up. */
7012 generate_skeleton (dw_die_ref die
)
7014 skeleton_chain_node node
;
7017 node
.new_die
= NULL
;
7020 /* If this type definition is nested inside another type,
7021 always leave at least a declaration in its place. */
7022 if (die
->die_parent
!= NULL
&& is_type_die (die
->die_parent
))
7023 node
.new_die
= clone_as_declaration (die
);
7025 generate_skeleton_bottom_up (&node
);
7026 return node
.new_die
;
7029 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7030 declaration. The original DIE is moved to a new compile unit so that
7031 existing references to it follow it to the new location. If any of the
7032 original DIE's descendants is a declaration, we need to replace the
7033 original DIE with a skeleton tree and move the declarations back into the
7037 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7040 dw_die_ref skeleton
, orig_parent
;
7042 /* Copy the declaration context to the type unit DIE. If the returned
7043 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7045 orig_parent
= copy_declaration_context (unit
, child
);
7047 skeleton
= generate_skeleton (child
);
7048 if (skeleton
== NULL
)
7049 remove_child_with_prev (child
, prev
);
7052 skeleton
->comdat_type_p
= true;
7053 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7055 /* If the original DIE was a specification, we need to put
7056 the skeleton under the parent DIE of the declaration.
7057 This leaves the original declaration in the tree, but
7058 it will be pruned later since there are no longer any
7059 references to it. */
7060 if (orig_parent
!= NULL
)
7062 remove_child_with_prev (child
, prev
);
7063 add_child_die (orig_parent
, skeleton
);
7066 replace_child (child
, skeleton
, prev
);
7072 /* Traverse the DIE and set up additional .debug_types sections for each
7073 type worthy of being placed in a COMDAT section. */
7076 break_out_comdat_types (dw_die_ref die
)
7080 dw_die_ref prev
= NULL
;
7081 dw_die_ref next
= NULL
;
7082 dw_die_ref unit
= NULL
;
7084 first
= c
= die
->die_child
;
7088 if (prev
== NULL
|| prev
->die_sib
== c
)
7091 next
= (c
== first
? NULL
: c
->die_sib
);
7092 if (should_move_die_to_comdat (c
))
7094 dw_die_ref replacement
;
7095 comdat_type_node_ref type_node
;
7097 /* Create a new type unit DIE as the root for the new tree, and
7098 add it to the list of comdat types. */
7099 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7100 add_AT_unsigned (unit
, DW_AT_language
,
7101 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7102 type_node
= ggc_alloc_cleared_comdat_type_node ();
7103 type_node
->root_die
= unit
;
7104 type_node
->next
= comdat_type_list
;
7105 comdat_type_list
= type_node
;
7107 /* Generate the type signature. */
7108 generate_type_signature (c
, type_node
);
7110 /* Copy the declaration context, attributes, and children of the
7111 declaration into the new type unit DIE, then remove this DIE
7112 from the main CU (or replace it with a skeleton if necessary). */
7113 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7114 type_node
->skeleton_die
= replacement
;
7116 /* Break out nested types into their own type units. */
7117 break_out_comdat_types (c
);
7119 /* Add the DIE to the new compunit. */
7120 add_child_die (unit
, c
);
7122 if (replacement
!= NULL
)
7125 else if (c
->die_tag
== DW_TAG_namespace
7126 || c
->die_tag
== DW_TAG_class_type
7127 || c
->die_tag
== DW_TAG_structure_type
7128 || c
->die_tag
== DW_TAG_union_type
)
7130 /* Look for nested types that can be broken out. */
7131 break_out_comdat_types (c
);
7133 } while (next
!= NULL
);
7136 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7138 struct decl_table_entry
7144 /* Routines to manipulate hash table of copied declarations. */
7147 htab_decl_hash (const void *of
)
7149 const struct decl_table_entry
*const entry
=
7150 (const struct decl_table_entry
*) of
;
7152 return htab_hash_pointer (entry
->orig
);
7156 htab_decl_eq (const void *of1
, const void *of2
)
7158 const struct decl_table_entry
*const entry1
=
7159 (const struct decl_table_entry
*) of1
;
7160 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
7162 return entry1
->orig
== entry2
;
7166 htab_decl_del (void *what
)
7168 struct decl_table_entry
*entry
= (struct decl_table_entry
*) what
;
7173 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7174 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7175 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7176 to check if the ancestor has already been copied into UNIT. */
7179 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
7181 dw_die_ref parent
= die
->die_parent
;
7182 dw_die_ref new_parent
= unit
;
7185 struct decl_table_entry
*entry
= NULL
;
7189 /* Check if the entry has already been copied to UNIT. */
7190 slot
= htab_find_slot_with_hash (decl_table
, die
,
7191 htab_hash_pointer (die
), INSERT
);
7192 if (*slot
!= HTAB_EMPTY_ENTRY
)
7194 entry
= (struct decl_table_entry
*) *slot
;
7198 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7199 entry
= XCNEW (struct decl_table_entry
);
7207 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7210 if (!is_unit_die (parent
))
7211 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7214 copy
= clone_as_declaration (die
);
7215 add_child_die (new_parent
, copy
);
7217 if (decl_table
!= NULL
)
7219 /* Record the pointer to the copy. */
7226 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
7227 Enter all the cloned children into the hash table decl_table. */
7230 clone_tree_partial (dw_die_ref die
, htab_t decl_table
)
7234 struct decl_table_entry
*entry
;
7237 if (die
->die_tag
== DW_TAG_subprogram
)
7238 clone
= clone_as_declaration (die
);
7240 clone
= clone_die (die
);
7242 slot
= htab_find_slot_with_hash (decl_table
, die
,
7243 htab_hash_pointer (die
), INSERT
);
7244 /* Assert that DIE isn't in the hash table yet. If it would be there
7245 before, the ancestors would be necessarily there as well, therefore
7246 clone_tree_partial wouldn't be called. */
7247 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7248 entry
= XCNEW (struct decl_table_entry
);
7250 entry
->copy
= clone
;
7253 if (die
->die_tag
!= DW_TAG_subprogram
)
7254 FOR_EACH_CHILD (die
, c
,
7255 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
7260 /* Walk the DIE and its children, looking for references to incomplete
7261 or trivial types that are unmarked (i.e., that are not in the current
7265 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
7271 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7273 if (AT_class (a
) == dw_val_class_die_ref
)
7275 dw_die_ref targ
= AT_ref (a
);
7277 struct decl_table_entry
*entry
;
7279 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7282 slot
= htab_find_slot_with_hash (decl_table
, targ
,
7283 htab_hash_pointer (targ
), INSERT
);
7285 if (*slot
!= HTAB_EMPTY_ENTRY
)
7287 /* TARG has already been copied, so we just need to
7288 modify the reference to point to the copy. */
7289 entry
= (struct decl_table_entry
*) *slot
;
7290 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7294 dw_die_ref parent
= unit
;
7295 dw_die_ref copy
= clone_die (targ
);
7297 /* Record in DECL_TABLE that TARG has been copied.
7298 Need to do this now, before the recursive call,
7299 because DECL_TABLE may be expanded and SLOT
7300 would no longer be a valid pointer. */
7301 entry
= XCNEW (struct decl_table_entry
);
7306 /* If TARG is not a declaration DIE, we need to copy its
7308 if (!is_declaration_die (targ
))
7312 add_child_die (copy
,
7313 clone_tree_partial (c
, decl_table
)));
7316 /* Make sure the cloned tree is marked as part of the
7320 /* If TARG has surrounding context, copy its ancestor tree
7321 into the new type unit. */
7322 if (targ
->die_parent
!= NULL
7323 && !is_unit_die (targ
->die_parent
))
7324 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7327 add_child_die (parent
, copy
);
7328 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7330 /* Make sure the newly-copied DIE is walked. If it was
7331 installed in a previously-added context, it won't
7332 get visited otherwise. */
7335 /* Find the highest point of the newly-added tree,
7336 mark each node along the way, and walk from there. */
7337 parent
->die_mark
= 1;
7338 while (parent
->die_parent
7339 && parent
->die_parent
->die_mark
== 0)
7341 parent
= parent
->die_parent
;
7342 parent
->die_mark
= 1;
7344 copy_decls_walk (unit
, parent
, decl_table
);
7350 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7353 /* Copy declarations for "unworthy" types into the new comdat section.
7354 Incomplete types, modified types, and certain other types aren't broken
7355 out into comdat sections of their own, so they don't have a signature,
7356 and we need to copy the declaration into the same section so that we
7357 don't have an external reference. */
7360 copy_decls_for_unworthy_types (dw_die_ref unit
)
7365 decl_table
= htab_create (10, htab_decl_hash
, htab_decl_eq
, htab_decl_del
);
7366 copy_decls_walk (unit
, unit
, decl_table
);
7367 htab_delete (decl_table
);
7371 /* Traverse the DIE and add a sibling attribute if it may have the
7372 effect of speeding up access to siblings. To save some space,
7373 avoid generating sibling attributes for DIE's without children. */
7376 add_sibling_attributes (dw_die_ref die
)
7380 if (! die
->die_child
)
7383 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7384 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7386 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7389 /* Output all location lists for the DIE and its children. */
7392 output_location_lists (dw_die_ref die
)
7398 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7399 if (AT_class (a
) == dw_val_class_loc_list
)
7400 output_loc_list (AT_loc_list (a
));
7402 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7405 /* We want to limit the number of external references, because they are
7406 larger than local references: a relocation takes multiple words, and
7407 even a sig8 reference is always eight bytes, whereas a local reference
7408 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7409 So if we encounter multiple external references to the same type DIE, we
7410 make a local typedef stub for it and redirect all references there.
7412 This is the element of the hash table for keeping track of these
7422 /* Hash an external_ref. */
7425 hash_external_ref (const void *p
)
7427 const struct external_ref
*r
= (const struct external_ref
*)p
;
7428 dw_die_ref die
= r
->type
;
7431 if (! die
->comdat_type_p
)
7432 h
= htab_hash_string (die
->die_id
.die_symbol
);
7435 comdat_type_node_ref type_node
= die
->die_id
.die_type_node
;
7436 memcpy (&h
, type_node
->signature
, sizeof (h
));
7441 /* Compare external_refs. */
7444 external_ref_eq (const void *p1
, const void *p2
)
7446 const struct external_ref
*r1
= (const struct external_ref
*)p1
;
7447 const struct external_ref
*r2
= (const struct external_ref
*)p2
;
7448 return r1
->type
== r2
->type
;
7451 /* Return a pointer to the external_ref for references to DIE. */
7453 static struct external_ref
*
7454 lookup_external_ref (htab_t map
, dw_die_ref die
)
7456 struct external_ref ref
, *ref_p
;
7460 slot
= htab_find_slot (map
, &ref
, INSERT
);
7461 if (*slot
!= HTAB_EMPTY_ENTRY
)
7462 return (struct external_ref
*) *slot
;
7464 ref_p
= XCNEW (struct external_ref
);
7470 /* Subroutine of optimize_external_refs, below.
7472 If we see a type skeleton, record it as our stub. If we see external
7473 references, remember how many we've seen. */
7476 optimize_external_refs_1 (dw_die_ref die
, htab_t map
)
7481 struct external_ref
*ref_p
;
7483 if (is_type_die (die
)
7484 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7486 /* This is a local skeleton; use it for local references. */
7487 ref_p
= lookup_external_ref (map
, c
);
7491 /* Scan the DIE references, and remember any that refer to DIEs from
7492 other CUs (i.e. those which are not marked). */
7493 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7494 if (AT_class (a
) == dw_val_class_die_ref
7495 && (c
= AT_ref (a
))->die_mark
== 0
7498 ref_p
= lookup_external_ref (map
, c
);
7502 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7505 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7506 points to an external_ref, DATA is the CU we're processing. If we don't
7507 already have a local stub, and we have multiple refs, build a stub. */
7510 build_local_stub (void **slot
, void *data
)
7512 struct external_ref
*ref_p
= (struct external_ref
*)*slot
;
7514 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7516 /* We have multiple references to this type, so build a small stub.
7517 Both of these forms are a bit dodgy from the perspective of the
7518 DWARF standard, since technically they should have names. */
7519 dw_die_ref cu
= (dw_die_ref
) data
;
7520 dw_die_ref type
= ref_p
->type
;
7521 dw_die_ref stub
= NULL
;
7523 if (type
->comdat_type_p
)
7525 /* If we refer to this type via sig8, use AT_signature. */
7526 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7527 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7531 /* Otherwise, use a typedef with no name. */
7532 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7533 add_AT_die_ref (stub
, DW_AT_type
, type
);
7542 /* DIE is a unit; look through all the DIE references to see if there are
7543 any external references to types, and if so, create local stubs for
7544 them which will be applied in build_abbrev_table. This is useful because
7545 references to local DIEs are smaller. */
7548 optimize_external_refs (dw_die_ref die
)
7550 htab_t map
= htab_create (10, hash_external_ref
, external_ref_eq
, free
);
7551 optimize_external_refs_1 (die
, map
);
7552 htab_traverse (map
, build_local_stub
, die
);
7556 /* The format of each DIE (and its attribute value pairs) is encoded in an
7557 abbreviation table. This routine builds the abbreviation table and assigns
7558 a unique abbreviation id for each abbreviation entry. The children of each
7559 die are visited recursively. */
7562 build_abbrev_table (dw_die_ref die
, htab_t extern_map
)
7564 unsigned long abbrev_id
;
7565 unsigned int n_alloc
;
7570 /* Scan the DIE references, and replace any that refer to
7571 DIEs from other CUs (i.e. those which are not marked) with
7572 the local stubs we built in optimize_external_refs. */
7573 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7574 if (AT_class (a
) == dw_val_class_die_ref
7575 && (c
= AT_ref (a
))->die_mark
== 0)
7577 struct external_ref
*ref_p
;
7578 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7580 ref_p
= lookup_external_ref (extern_map
, c
);
7581 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7582 change_AT_die_ref (a
, ref_p
->stub
);
7584 /* We aren't changing this reference, so mark it external. */
7585 set_AT_ref_external (a
, 1);
7588 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7590 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7591 dw_attr_ref die_a
, abbrev_a
;
7595 if (abbrev
->die_tag
!= die
->die_tag
)
7597 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7600 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
7603 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
7605 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
7606 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7607 || (value_format (abbrev_a
) != value_format (die_a
)))
7617 if (abbrev_id
>= abbrev_die_table_in_use
)
7619 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7621 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7622 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7625 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7626 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7627 abbrev_die_table_allocated
= n_alloc
;
7630 ++abbrev_die_table_in_use
;
7631 abbrev_die_table
[abbrev_id
] = die
;
7634 die
->die_abbrev
= abbrev_id
;
7635 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
7638 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7641 constant_size (unsigned HOST_WIDE_INT value
)
7648 log
= floor_log2 (value
);
7651 log
= 1 << (floor_log2 (log
) + 1);
7656 /* Return the size of a DIE as it is represented in the
7657 .debug_info section. */
7659 static unsigned long
7660 size_of_die (dw_die_ref die
)
7662 unsigned long size
= 0;
7665 enum dwarf_form form
;
7667 size
+= size_of_uleb128 (die
->die_abbrev
);
7668 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7670 switch (AT_class (a
))
7672 case dw_val_class_addr
:
7673 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7675 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7676 size
+= size_of_uleb128 (AT_index (a
));
7679 size
+= DWARF2_ADDR_SIZE
;
7681 case dw_val_class_offset
:
7682 size
+= DWARF_OFFSET_SIZE
;
7684 case dw_val_class_loc
:
7686 unsigned long lsize
= size_of_locs (AT_loc (a
));
7689 if (dwarf_version
>= 4)
7690 size
+= size_of_uleb128 (lsize
);
7692 size
+= constant_size (lsize
);
7696 case dw_val_class_loc_list
:
7697 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7699 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7700 size
+= size_of_uleb128 (AT_index (a
));
7703 size
+= DWARF_OFFSET_SIZE
;
7705 case dw_val_class_range_list
:
7706 size
+= DWARF_OFFSET_SIZE
;
7708 case dw_val_class_const
:
7709 size
+= size_of_sleb128 (AT_int (a
));
7711 case dw_val_class_unsigned_const
:
7713 int csize
= constant_size (AT_unsigned (a
));
7714 if (dwarf_version
== 3
7715 && a
->dw_attr
== DW_AT_data_member_location
7717 size
+= size_of_uleb128 (AT_unsigned (a
));
7722 case dw_val_class_const_double
:
7723 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
7724 if (HOST_BITS_PER_WIDE_INT
>= 64)
7727 case dw_val_class_vec
:
7728 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7729 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7730 + a
->dw_attr_val
.v
.val_vec
.length
7731 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7733 case dw_val_class_flag
:
7734 if (dwarf_version
>= 4)
7735 /* Currently all add_AT_flag calls pass in 1 as last argument,
7736 so DW_FORM_flag_present can be used. If that ever changes,
7737 we'll need to use DW_FORM_flag and have some optimization
7738 in build_abbrev_table that will change those to
7739 DW_FORM_flag_present if it is set to 1 in all DIEs using
7740 the same abbrev entry. */
7741 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7745 case dw_val_class_die_ref
:
7746 if (AT_ref_external (a
))
7748 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7749 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7750 is sized by target address length, whereas in DWARF3
7751 it's always sized as an offset. */
7752 if (use_debug_types
)
7753 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7754 else if (dwarf_version
== 2)
7755 size
+= DWARF2_ADDR_SIZE
;
7757 size
+= DWARF_OFFSET_SIZE
;
7760 size
+= DWARF_OFFSET_SIZE
;
7762 case dw_val_class_fde_ref
:
7763 size
+= DWARF_OFFSET_SIZE
;
7765 case dw_val_class_lbl_id
:
7766 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7768 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7769 size
+= size_of_uleb128 (AT_index (a
));
7772 size
+= DWARF2_ADDR_SIZE
;
7774 case dw_val_class_lineptr
:
7775 case dw_val_class_macptr
:
7776 size
+= DWARF_OFFSET_SIZE
;
7778 case dw_val_class_str
:
7779 form
= AT_string_form (a
);
7780 if (form
== DW_FORM_strp
)
7781 size
+= DWARF_OFFSET_SIZE
;
7782 else if (form
== DW_FORM_GNU_str_index
)
7783 size
+= size_of_uleb128 (AT_index (a
));
7785 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7787 case dw_val_class_file
:
7788 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7790 case dw_val_class_data8
:
7793 case dw_val_class_vms_delta
:
7794 size
+= DWARF_OFFSET_SIZE
;
7796 case dw_val_class_high_pc
:
7797 size
+= DWARF2_ADDR_SIZE
;
7807 /* Size the debugging information associated with a given DIE. Visits the
7808 DIE's children recursively. Updates the global variable next_die_offset, on
7809 each time through. Uses the current value of next_die_offset to update the
7810 die_offset field in each DIE. */
7813 calc_die_sizes (dw_die_ref die
)
7817 gcc_assert (die
->die_offset
== 0
7818 || (unsigned long int) die
->die_offset
== next_die_offset
);
7819 die
->die_offset
= next_die_offset
;
7820 next_die_offset
+= size_of_die (die
);
7822 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7824 if (die
->die_child
!= NULL
)
7825 /* Count the null byte used to terminate sibling lists. */
7826 next_die_offset
+= 1;
7829 /* Size just the base type children at the start of the CU.
7830 This is needed because build_abbrev needs to size locs
7831 and sizing of type based stack ops needs to know die_offset
7832 values for the base types. */
7835 calc_base_type_die_sizes (void)
7837 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7839 dw_die_ref base_type
;
7840 #if ENABLE_ASSERT_CHECKING
7841 dw_die_ref prev
= comp_unit_die ()->die_child
;
7844 die_offset
+= size_of_die (comp_unit_die ());
7845 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
7847 #if ENABLE_ASSERT_CHECKING
7848 gcc_assert (base_type
->die_offset
== 0
7849 && prev
->die_sib
== base_type
7850 && base_type
->die_child
== NULL
7851 && base_type
->die_abbrev
);
7854 base_type
->die_offset
= die_offset
;
7855 die_offset
+= size_of_die (base_type
);
7859 /* Set the marks for a die and its children. We do this so
7860 that we know whether or not a reference needs to use FORM_ref_addr; only
7861 DIEs in the same CU will be marked. We used to clear out the offset
7862 and use that as the flag, but ran into ordering problems. */
7865 mark_dies (dw_die_ref die
)
7869 gcc_assert (!die
->die_mark
);
7872 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7875 /* Clear the marks for a die and its children. */
7878 unmark_dies (dw_die_ref die
)
7882 if (! use_debug_types
)
7883 gcc_assert (die
->die_mark
);
7886 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7889 /* Clear the marks for a die, its children and referred dies. */
7892 unmark_all_dies (dw_die_ref die
)
7902 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7904 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7905 if (AT_class (a
) == dw_val_class_die_ref
)
7906 unmark_all_dies (AT_ref (a
));
7909 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7910 generated for the compilation unit. */
7912 static unsigned long
7913 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
7919 size
= DWARF_PUBNAMES_HEADER_SIZE
;
7920 FOR_EACH_VEC_ELT (*names
, i
, p
)
7921 if (names
!= pubtype_table
7922 || p
->die
->die_offset
!= 0
7923 || !flag_eliminate_unused_debug_types
)
7924 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
7926 size
+= DWARF_OFFSET_SIZE
;
7930 /* Return the size of the information in the .debug_aranges section. */
7932 static unsigned long
7933 size_of_aranges (void)
7937 size
= DWARF_ARANGES_HEADER_SIZE
;
7939 /* Count the address/length pair for this compilation unit. */
7940 if (text_section_used
)
7941 size
+= 2 * DWARF2_ADDR_SIZE
;
7942 if (cold_text_section_used
)
7943 size
+= 2 * DWARF2_ADDR_SIZE
;
7944 if (have_multiple_function_sections
)
7949 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
7951 if (DECL_IGNORED_P (fde
->decl
))
7953 if (!fde
->in_std_section
)
7954 size
+= 2 * DWARF2_ADDR_SIZE
;
7955 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
7956 size
+= 2 * DWARF2_ADDR_SIZE
;
7960 /* Count the two zero words used to terminated the address range table. */
7961 size
+= 2 * DWARF2_ADDR_SIZE
;
7965 /* Select the encoding of an attribute value. */
7967 static enum dwarf_form
7968 value_format (dw_attr_ref a
)
7970 switch (AT_class (a
))
7972 case dw_val_class_addr
:
7973 /* Only very few attributes allow DW_FORM_addr. */
7978 case DW_AT_entry_pc
:
7979 case DW_AT_trampoline
:
7980 return (AT_index (a
) == NOT_INDEXED
7981 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
7985 switch (DWARF2_ADDR_SIZE
)
7988 return DW_FORM_data1
;
7990 return DW_FORM_data2
;
7992 return DW_FORM_data4
;
7994 return DW_FORM_data8
;
7998 case dw_val_class_range_list
:
7999 case dw_val_class_loc_list
:
8000 if (dwarf_version
>= 4)
8001 return DW_FORM_sec_offset
;
8003 case dw_val_class_vms_delta
:
8004 case dw_val_class_offset
:
8005 switch (DWARF_OFFSET_SIZE
)
8008 return DW_FORM_data4
;
8010 return DW_FORM_data8
;
8014 case dw_val_class_loc
:
8015 if (dwarf_version
>= 4)
8016 return DW_FORM_exprloc
;
8017 switch (constant_size (size_of_locs (AT_loc (a
))))
8020 return DW_FORM_block1
;
8022 return DW_FORM_block2
;
8024 return DW_FORM_block4
;
8028 case dw_val_class_const
:
8029 return DW_FORM_sdata
;
8030 case dw_val_class_unsigned_const
:
8031 switch (constant_size (AT_unsigned (a
)))
8034 return DW_FORM_data1
;
8036 return DW_FORM_data2
;
8038 /* In DWARF3 DW_AT_data_member_location with
8039 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8040 constant, so we need to use DW_FORM_udata if we need
8041 a large constant. */
8042 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8043 return DW_FORM_udata
;
8044 return DW_FORM_data4
;
8046 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8047 return DW_FORM_udata
;
8048 return DW_FORM_data8
;
8052 case dw_val_class_const_double
:
8053 switch (HOST_BITS_PER_WIDE_INT
)
8056 return DW_FORM_data2
;
8058 return DW_FORM_data4
;
8060 return DW_FORM_data8
;
8063 return DW_FORM_block1
;
8065 case dw_val_class_vec
:
8066 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8067 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8070 return DW_FORM_block1
;
8072 return DW_FORM_block2
;
8074 return DW_FORM_block4
;
8078 case dw_val_class_flag
:
8079 if (dwarf_version
>= 4)
8081 /* Currently all add_AT_flag calls pass in 1 as last argument,
8082 so DW_FORM_flag_present can be used. If that ever changes,
8083 we'll need to use DW_FORM_flag and have some optimization
8084 in build_abbrev_table that will change those to
8085 DW_FORM_flag_present if it is set to 1 in all DIEs using
8086 the same abbrev entry. */
8087 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8088 return DW_FORM_flag_present
;
8090 return DW_FORM_flag
;
8091 case dw_val_class_die_ref
:
8092 if (AT_ref_external (a
))
8093 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8096 case dw_val_class_fde_ref
:
8097 return DW_FORM_data
;
8098 case dw_val_class_lbl_id
:
8099 return (AT_index (a
) == NOT_INDEXED
8100 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8101 case dw_val_class_lineptr
:
8102 case dw_val_class_macptr
:
8103 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8104 case dw_val_class_str
:
8105 return AT_string_form (a
);
8106 case dw_val_class_file
:
8107 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8110 return DW_FORM_data1
;
8112 return DW_FORM_data2
;
8114 return DW_FORM_data4
;
8119 case dw_val_class_data8
:
8120 return DW_FORM_data8
;
8122 case dw_val_class_high_pc
:
8123 switch (DWARF2_ADDR_SIZE
)
8126 return DW_FORM_data1
;
8128 return DW_FORM_data2
;
8130 return DW_FORM_data4
;
8132 return DW_FORM_data8
;
8142 /* Output the encoding of an attribute value. */
8145 output_value_format (dw_attr_ref a
)
8147 enum dwarf_form form
= value_format (a
);
8149 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8152 /* Given a die and id, produce the appropriate abbreviations. */
8155 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8160 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8161 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8162 dwarf_tag_name (abbrev
->die_tag
));
8164 if (abbrev
->die_child
!= NULL
)
8165 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8167 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8169 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8171 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8172 dwarf_attr_name (a_attr
->dw_attr
));
8173 output_value_format (a_attr
);
8176 dw2_asm_output_data (1, 0, NULL
);
8177 dw2_asm_output_data (1, 0, NULL
);
8181 /* Output the .debug_abbrev section which defines the DIE abbreviation
8185 output_abbrev_section (void)
8187 unsigned long abbrev_id
;
8189 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8190 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8192 /* Terminate the table. */
8193 dw2_asm_output_data (1, 0, NULL
);
8196 /* Output a symbol we can use to refer to this DIE from another CU. */
8199 output_die_symbol (dw_die_ref die
)
8201 const char *sym
= die
->die_id
.die_symbol
;
8203 gcc_assert (!die
->comdat_type_p
);
8208 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8209 /* We make these global, not weak; if the target doesn't support
8210 .linkonce, it doesn't support combining the sections, so debugging
8212 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8214 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8217 /* Return a new location list, given the begin and end range, and the
8220 static inline dw_loc_list_ref
8221 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8222 const char *section
)
8224 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
8226 retlist
->begin
= begin
;
8227 retlist
->begin_entry
= NULL
;
8229 retlist
->expr
= expr
;
8230 retlist
->section
= section
;
8235 /* Generate a new internal symbol for this location list node, if it
8236 hasn't got one yet. */
8239 gen_llsym (dw_loc_list_ref list
)
8241 gcc_assert (!list
->ll_symbol
);
8242 list
->ll_symbol
= gen_internal_sym ("LLST");
8245 /* Output the location list given to us. */
8248 output_loc_list (dw_loc_list_ref list_head
)
8250 dw_loc_list_ref curr
= list_head
;
8252 if (list_head
->emitted
)
8254 list_head
->emitted
= true;
8256 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8258 /* Walk the location list, and output each range + expression. */
8259 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8262 /* Don't output an entry that starts and ends at the same address. */
8263 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8265 size
= size_of_locs (curr
->expr
);
8266 /* If the expression is too large, drop it on the floor. We could
8267 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8268 in the expression, but >= 64KB expressions for a single value
8269 in a single range are unlikely very useful. */
8272 if (dwarf_split_debug_info
)
8274 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8275 "Location list start/length entry (%s)",
8276 list_head
->ll_symbol
);
8277 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8278 "Location list range start index (%s)",
8280 /* The length field is 4 bytes. If we ever need to support
8281 an 8-byte length, we can add a new DW_LLE code or fall back
8282 to DW_LLE_GNU_start_end_entry. */
8283 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8284 "Location list range length (%s)",
8285 list_head
->ll_symbol
);
8287 else if (!have_multiple_function_sections
)
8289 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8290 "Location list begin address (%s)",
8291 list_head
->ll_symbol
);
8292 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8293 "Location list end address (%s)",
8294 list_head
->ll_symbol
);
8298 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8299 "Location list begin address (%s)",
8300 list_head
->ll_symbol
);
8301 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8302 "Location list end address (%s)",
8303 list_head
->ll_symbol
);
8306 /* Output the block length for this list of location operations. */
8307 gcc_assert (size
<= 0xffff);
8308 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8310 output_loc_sequence (curr
->expr
, -1);
8313 if (dwarf_split_debug_info
)
8314 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8315 "Location list terminator (%s)",
8316 list_head
->ll_symbol
);
8319 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8320 "Location list terminator begin (%s)",
8321 list_head
->ll_symbol
);
8322 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8323 "Location list terminator end (%s)",
8324 list_head
->ll_symbol
);
8328 /* Output a range_list offset into the debug_range section. Emit a
8329 relocated reference if val_entry is NULL, otherwise, emit an
8330 indirect reference. */
8333 output_range_list_offset (dw_attr_ref a
)
8335 const char *name
= dwarf_attr_name (a
->dw_attr
);
8337 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8339 char *p
= strchr (ranges_section_label
, '\0');
8340 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8341 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8342 debug_ranges_section
, "%s", name
);
8346 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8347 "%s (offset from %s)", name
, ranges_section_label
);
8350 /* Output the offset into the debug_loc section. */
8353 output_loc_list_offset (dw_attr_ref a
)
8355 char *sym
= AT_loc_list (a
)->ll_symbol
;
8358 if (dwarf_split_debug_info
)
8359 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8360 "%s", dwarf_attr_name (a
->dw_attr
));
8362 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8363 "%s", dwarf_attr_name (a
->dw_attr
));
8366 /* Output an attribute's index or value appropriately. */
8369 output_attr_index_or_value (dw_attr_ref a
)
8371 const char *name
= dwarf_attr_name (a
->dw_attr
);
8373 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8375 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8378 switch (AT_class (a
))
8380 case dw_val_class_addr
:
8381 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8383 case dw_val_class_high_pc
:
8384 case dw_val_class_lbl_id
:
8385 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8387 case dw_val_class_loc_list
:
8388 output_loc_list_offset (a
);
8395 /* Output a type signature. */
8398 output_signature (const char *sig
, const char *name
)
8402 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8403 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8406 /* Output the DIE and its attributes. Called recursively to generate
8407 the definitions of each child DIE. */
8410 output_die (dw_die_ref die
)
8417 /* If someone in another CU might refer to us, set up a symbol for
8418 them to point to. */
8419 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8420 output_die_symbol (die
);
8422 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8423 (unsigned long)die
->die_offset
,
8424 dwarf_tag_name (die
->die_tag
));
8426 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8428 const char *name
= dwarf_attr_name (a
->dw_attr
);
8430 switch (AT_class (a
))
8432 case dw_val_class_addr
:
8433 output_attr_index_or_value (a
);
8436 case dw_val_class_offset
:
8437 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8441 case dw_val_class_range_list
:
8442 output_range_list_offset (a
);
8445 case dw_val_class_loc
:
8446 size
= size_of_locs (AT_loc (a
));
8448 /* Output the block length for this list of location operations. */
8449 if (dwarf_version
>= 4)
8450 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8452 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8454 output_loc_sequence (AT_loc (a
), -1);
8457 case dw_val_class_const
:
8458 /* ??? It would be slightly more efficient to use a scheme like is
8459 used for unsigned constants below, but gdb 4.x does not sign
8460 extend. Gdb 5.x does sign extend. */
8461 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8464 case dw_val_class_unsigned_const
:
8466 int csize
= constant_size (AT_unsigned (a
));
8467 if (dwarf_version
== 3
8468 && a
->dw_attr
== DW_AT_data_member_location
8470 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8472 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8476 case dw_val_class_const_double
:
8478 unsigned HOST_WIDE_INT first
, second
;
8480 if (HOST_BITS_PER_WIDE_INT
>= 64)
8481 dw2_asm_output_data (1,
8482 HOST_BITS_PER_DOUBLE_INT
8483 / HOST_BITS_PER_CHAR
,
8486 if (WORDS_BIG_ENDIAN
)
8488 first
= a
->dw_attr_val
.v
.val_double
.high
;
8489 second
= a
->dw_attr_val
.v
.val_double
.low
;
8493 first
= a
->dw_attr_val
.v
.val_double
.low
;
8494 second
= a
->dw_attr_val
.v
.val_double
.high
;
8497 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8499 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8504 case dw_val_class_vec
:
8506 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8507 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8511 dw2_asm_output_data (constant_size (len
* elt_size
),
8512 len
* elt_size
, "%s", name
);
8513 if (elt_size
> sizeof (HOST_WIDE_INT
))
8518 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8521 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8522 "fp or vector constant word %u", i
);
8526 case dw_val_class_flag
:
8527 if (dwarf_version
>= 4)
8529 /* Currently all add_AT_flag calls pass in 1 as last argument,
8530 so DW_FORM_flag_present can be used. If that ever changes,
8531 we'll need to use DW_FORM_flag and have some optimization
8532 in build_abbrev_table that will change those to
8533 DW_FORM_flag_present if it is set to 1 in all DIEs using
8534 the same abbrev entry. */
8535 gcc_assert (AT_flag (a
) == 1);
8537 fprintf (asm_out_file
, "\t\t\t%s %s\n",
8538 ASM_COMMENT_START
, name
);
8541 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8544 case dw_val_class_loc_list
:
8545 output_attr_index_or_value (a
);
8548 case dw_val_class_die_ref
:
8549 if (AT_ref_external (a
))
8551 if (AT_ref (a
)->comdat_type_p
)
8553 comdat_type_node_ref type_node
=
8554 AT_ref (a
)->die_id
.die_type_node
;
8556 gcc_assert (type_node
);
8557 output_signature (type_node
->signature
, name
);
8561 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
8565 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8566 length, whereas in DWARF3 it's always sized as an
8568 if (dwarf_version
== 2)
8569 size
= DWARF2_ADDR_SIZE
;
8571 size
= DWARF_OFFSET_SIZE
;
8572 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
8578 gcc_assert (AT_ref (a
)->die_offset
);
8579 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8584 case dw_val_class_fde_ref
:
8588 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8589 a
->dw_attr_val
.v
.val_fde_index
* 2);
8590 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8595 case dw_val_class_vms_delta
:
8596 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
8597 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
8601 case dw_val_class_lbl_id
:
8602 output_attr_index_or_value (a
);
8605 case dw_val_class_lineptr
:
8606 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8607 debug_line_section
, "%s", name
);
8610 case dw_val_class_macptr
:
8611 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8612 debug_macinfo_section
, "%s", name
);
8615 case dw_val_class_str
:
8616 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
8617 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8618 a
->dw_attr_val
.v
.val_str
->label
,
8620 "%s: \"%s\"", name
, AT_string (a
));
8621 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
8622 dw2_asm_output_data_uleb128 (AT_index (a
),
8623 "%s: \"%s\"", name
, AT_string (a
));
8625 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8628 case dw_val_class_file
:
8630 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8632 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8633 a
->dw_attr_val
.v
.val_file
->filename
);
8637 case dw_val_class_data8
:
8641 for (i
= 0; i
< 8; i
++)
8642 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8643 i
== 0 ? "%s" : NULL
, name
);
8647 case dw_val_class_high_pc
:
8648 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
8649 get_AT_low_pc (die
), "DW_AT_high_pc");
8657 FOR_EACH_CHILD (die
, c
, output_die (c
));
8659 /* Add null byte to terminate sibling list. */
8660 if (die
->die_child
!= NULL
)
8661 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8662 (unsigned long) die
->die_offset
);
8665 /* Output the compilation unit that appears at the beginning of the
8666 .debug_info section, and precedes the DIE descriptions. */
8669 output_compilation_unit_header (void)
8671 int ver
= dwarf_version
;
8673 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8674 dw2_asm_output_data (4, 0xffffffff,
8675 "Initial length escape value indicating 64-bit DWARF extension");
8676 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8677 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8678 "Length of Compilation Unit Info");
8679 dw2_asm_output_data (2, ver
, "DWARF version number");
8680 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8681 debug_abbrev_section
,
8682 "Offset Into Abbrev. Section");
8683 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8686 /* Output the compilation unit DIE and its children. */
8689 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8691 const char *secname
, *oldsym
;
8695 /* Unless we are outputting main CU, we may throw away empty ones. */
8696 if (!output_if_empty
&& die
->die_child
== NULL
)
8699 /* Even if there are no children of this DIE, we must output the information
8700 about the compilation unit. Otherwise, on an empty translation unit, we
8701 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8702 will then complain when examining the file. First mark all the DIEs in
8703 this CU so we know which get local refs. */
8706 extern_map
= optimize_external_refs (die
);
8708 build_abbrev_table (die
, extern_map
);
8710 htab_delete (extern_map
);
8712 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8713 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8714 calc_die_sizes (die
);
8716 oldsym
= die
->die_id
.die_symbol
;
8719 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8721 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8723 die
->die_id
.die_symbol
= NULL
;
8724 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8728 switch_to_section (debug_info_section
);
8729 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8730 info_section_emitted
= true;
8733 /* Output debugging information. */
8734 output_compilation_unit_header ();
8737 /* Leave the marks on the main CU, so we can check them in
8742 die
->die_id
.die_symbol
= oldsym
;
8746 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
8747 and .debug_pubtypes. This is configured per-target, but can be
8748 overridden by the -gpubnames or -gno-pubnames options. */
8751 want_pubnames (void)
8753 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
8755 if (debug_generate_pub_sections
!= -1)
8756 return debug_generate_pub_sections
;
8757 return targetm
.want_debug_pub_sections
;
8760 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
8763 add_AT_pubnames (dw_die_ref die
)
8765 if (want_pubnames ())
8766 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
8769 /* Add a string attribute value to a skeleton DIE. */
8772 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
8776 struct indirect_string_node
*node
;
8778 if (! skeleton_debug_str_hash
)
8779 skeleton_debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
8780 debug_str_eq
, NULL
);
8782 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
8783 find_string_form (node
);
8784 if (node
->form
== DW_FORM_GNU_str_index
)
8785 node
->form
= DW_FORM_strp
;
8787 attr
.dw_attr
= attr_kind
;
8788 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
8789 attr
.dw_attr_val
.val_entry
= NULL
;
8790 attr
.dw_attr_val
.v
.val_str
= node
;
8791 add_dwarf_attr (die
, &attr
);
8794 /* Helper function to generate top-level dies for skeleton debug_info and
8798 add_top_level_skeleton_die_attrs (dw_die_ref die
)
8800 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
8801 const char *comp_dir
= comp_dir_string ();
8803 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
8804 if (comp_dir
!= NULL
)
8805 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
8806 add_AT_pubnames (die
);
8807 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
8810 /* Return the single type-unit die for skeleton type units. */
8813 get_skeleton_type_unit (void)
8815 /* For dwarf_split_debug_sections with use_type info, all type units in the
8816 skeleton sections have identical dies (but different headers). This
8817 single die will be output many times. */
8819 static dw_die_ref skeleton_type_unit
= NULL
;
8821 if (skeleton_type_unit
== NULL
)
8823 skeleton_type_unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8824 add_top_level_skeleton_die_attrs (skeleton_type_unit
);
8825 skeleton_type_unit
->die_abbrev
= SKELETON_TYPE_DIE_ABBREV
;
8827 return skeleton_type_unit
;
8830 /* Output skeleton debug sections that point to the dwo file. */
8833 output_skeleton_debug_sections (dw_die_ref comp_unit
)
8835 /* These attributes will be found in the full debug_info section. */
8836 remove_AT (comp_unit
, DW_AT_producer
);
8837 remove_AT (comp_unit
, DW_AT_language
);
8839 switch_to_section (debug_skeleton_info_section
);
8840 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
8842 /* Produce the skeleton compilation-unit header. This one differs enough from
8843 a normal CU header that it's better not to call output_compilation_unit
8845 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8846 dw2_asm_output_data (4, 0xffffffff,
8847 "Initial length escape value indicating 64-bit DWARF extension");
8849 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8850 DWARF_COMPILE_UNIT_HEADER_SIZE
8851 - DWARF_INITIAL_LENGTH_SIZE
8852 + size_of_die (comp_unit
),
8853 "Length of Compilation Unit Info");
8854 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8855 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
8856 debug_abbrev_section
,
8857 "Offset Into Abbrev. Section");
8858 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8860 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
8861 output_die (comp_unit
);
8863 /* Build the skeleton debug_abbrev section. */
8864 switch_to_section (debug_skeleton_abbrev_section
);
8865 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
8867 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
8868 if (use_debug_types
)
8869 output_die_abbrevs (SKELETON_TYPE_DIE_ABBREV
, get_skeleton_type_unit ());
8871 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
8874 /* Output a comdat type unit DIE and its children. */
8877 output_comdat_type_unit (comdat_type_node
*node
)
8879 const char *secname
;
8882 #if defined (OBJECT_FORMAT_ELF)
8887 /* First mark all the DIEs in this CU so we know which get local refs. */
8888 mark_dies (node
->root_die
);
8890 extern_map
= optimize_external_refs (node
->root_die
);
8892 build_abbrev_table (node
->root_die
, extern_map
);
8894 htab_delete (extern_map
);
8896 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8897 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
8898 calc_die_sizes (node
->root_die
);
8900 #if defined (OBJECT_FORMAT_ELF)
8901 if (!dwarf_split_debug_info
)
8902 secname
= ".debug_types";
8904 secname
= ".debug_types.dwo";
8906 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8907 sprintf (tmp
, "wt.");
8908 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8909 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8910 comdat_key
= get_identifier (tmp
);
8911 targetm
.asm_out
.named_section (secname
,
8912 SECTION_DEBUG
| SECTION_LINKONCE
,
8915 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8916 sprintf (tmp
, ".gnu.linkonce.wt.");
8917 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8918 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8920 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8923 /* Output debugging information. */
8924 output_compilation_unit_header ();
8925 output_signature (node
->signature
, "Type Signature");
8926 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
8927 "Offset to Type DIE");
8928 output_die (node
->root_die
);
8930 unmark_dies (node
->root_die
);
8932 #if defined (OBJECT_FORMAT_ELF)
8933 if (dwarf_split_debug_info
)
8935 /* Produce the skeleton type-unit header. */
8936 const char *secname
= ".debug_types";
8938 targetm
.asm_out
.named_section (secname
,
8939 SECTION_DEBUG
| SECTION_LINKONCE
,
8941 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8942 dw2_asm_output_data (4, 0xffffffff,
8943 "Initial length escape value indicating 64-bit DWARF extension");
8945 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8946 DWARF_COMPILE_UNIT_HEADER_SIZE
8947 - DWARF_INITIAL_LENGTH_SIZE
8948 + size_of_die (get_skeleton_type_unit ())
8949 + DWARF_TYPE_SIGNATURE_SIZE
+ DWARF_OFFSET_SIZE
,
8950 "Length of Type Unit Info");
8951 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8952 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8953 debug_skeleton_abbrev_section_label
,
8954 debug_abbrev_section
,
8955 "Offset Into Abbrev. Section");
8956 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8957 output_signature (node
->signature
, "Type Signature");
8958 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, "Offset to Type DIE");
8960 output_die (get_skeleton_type_unit ());
8965 /* Return the DWARF2/3 pubname associated with a decl. */
8968 dwarf2_name (tree decl
, int scope
)
8970 if (DECL_NAMELESS (decl
))
8972 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
8975 /* Add a new entry to .debug_pubnames if appropriate. */
8978 add_pubname_string (const char *str
, dw_die_ref die
)
8983 e
.name
= xstrdup (str
);
8984 vec_safe_push (pubname_table
, e
);
8988 add_pubname (tree decl
, dw_die_ref die
)
8990 if (!want_pubnames ())
8993 /* Don't add items to the table when we expect that the consumer will have
8994 just read the enclosing die. For example, if the consumer is looking at a
8995 class_member, it will either be inside the class already, or will have just
8996 looked up the class to find the member. Either way, searching the class is
8997 faster than searching the index. */
8998 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
8999 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9001 const char *name
= dwarf2_name (decl
, 1);
9004 add_pubname_string (name
, die
);
9008 /* Add an enumerator to the pubnames section. */
9011 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
9015 gcc_assert (scope_name
);
9016 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
9018 vec_safe_push (pubname_table
, e
);
9021 /* Add a new entry to .debug_pubtypes if appropriate. */
9024 add_pubtype (tree decl
, dw_die_ref die
)
9028 if (!want_pubnames ())
9031 if ((TREE_PUBLIC (decl
)
9032 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9033 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9036 const char *scope_name
= "";
9037 const char *sep
= is_cxx () ? "::" : ".";
9040 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9041 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9043 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9044 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9045 scope_name
= concat (scope_name
, sep
, NULL
);
9051 name
= type_tag (decl
);
9053 name
= lang_hooks
.dwarf_name (decl
, 1);
9055 /* If we don't have a name for the type, there's no point in adding
9057 if (name
!= NULL
&& name
[0] != '\0')
9060 e
.name
= concat (scope_name
, name
, NULL
);
9061 vec_safe_push (pubtype_table
, e
);
9064 /* Although it might be more consistent to add the pubinfo for the
9065 enumerators as their dies are created, they should only be added if the
9066 enum type meets the criteria above. So rather than re-check the parent
9067 enum type whenever an enumerator die is created, just output them all
9068 here. This isn't protected by the name conditional because anonymous
9069 enums don't have names. */
9070 if (die
->die_tag
== DW_TAG_enumeration_type
)
9074 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9079 /* Output the public names table used to speed up access to externally
9080 visible names; or the public types table used to find type definitions. */
9083 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9086 unsigned long pubnames_length
= size_of_pubnames (names
);
9089 if (!want_pubnames () || !info_section_emitted
)
9091 if (names
== pubname_table
)
9092 switch_to_section (debug_pubnames_section
);
9094 switch_to_section (debug_pubtypes_section
);
9095 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9096 dw2_asm_output_data (4, 0xffffffff,
9097 "Initial length escape value indicating 64-bit DWARF extension");
9098 if (names
== pubname_table
)
9099 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
9100 "Length of Public Names Info");
9102 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
9103 "Length of Public Type Names Info");
9104 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
9105 dw2_asm_output_data (2, 2, "DWARF Version");
9106 if (dwarf_split_debug_info
)
9107 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9108 debug_skeleton_info_section
,
9109 "Offset of Compilation Unit Info");
9111 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9113 "Offset of Compilation Unit Info");
9114 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9115 "Compilation Unit Length");
9117 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9119 /* Enumerator names are part of the pubname table, but the parent
9120 DW_TAG_enumeration_type die may have been pruned. Don't output
9121 them if that is the case. */
9122 if (pub
->die
->die_tag
== DW_TAG_enumerator
&&
9123 (pub
->die
->die_parent
== NULL
9124 || !pub
->die
->die_parent
->die_perennial_p
))
9127 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9128 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9129 gcc_assert (pub
->die
->die_mark
);
9131 if (names
!= pubtype_table
9132 || pub
->die
->die_offset
!= 0
9133 || !flag_eliminate_unused_debug_types
)
9135 dw_offset die_offset
= pub
->die
->die_offset
;
9137 /* If we're putting types in their own .debug_types sections,
9138 the .debug_pubtypes table will still point to the compile
9139 unit (not the type unit), so we want to use the offset of
9140 the skeleton DIE (if there is one). */
9141 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9143 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9145 if (type_node
!= NULL
)
9146 die_offset
= (type_node
->skeleton_die
!= NULL
9147 ? type_node
->skeleton_die
->die_offset
9151 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9153 dw2_asm_output_nstring (pub
->name
, -1, "external name");
9157 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9160 /* Output the information that goes into the .debug_aranges table.
9161 Namely, define the beginning and ending address range of the
9162 text section generated for this compilation unit. */
9165 output_aranges (unsigned long aranges_length
)
9169 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9170 dw2_asm_output_data (4, 0xffffffff,
9171 "Initial length escape value indicating 64-bit DWARF extension");
9172 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9173 "Length of Address Ranges Info");
9174 /* Version number for aranges 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 (1, DWARF2_ADDR_SIZE
, "Size of Address");
9185 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9187 /* We need to align to twice the pointer size here. */
9188 if (DWARF_ARANGES_PAD_SIZE
)
9190 /* Pad using a 2 byte words so that padding is correct for any
9192 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9193 2 * DWARF2_ADDR_SIZE
);
9194 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9195 dw2_asm_output_data (2, 0, NULL
);
9198 /* It is necessary not to output these entries if the sections were
9199 not used; if the sections were not used, the length will be 0 and
9200 the address may end up as 0 if the section is discarded by ld
9201 --gc-sections, leaving an invalid (0, 0) entry that can be
9202 confused with the terminator. */
9203 if (text_section_used
)
9205 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9206 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9207 text_section_label
, "Length");
9209 if (cold_text_section_used
)
9211 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9213 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9214 cold_text_section_label
, "Length");
9217 if (have_multiple_function_sections
)
9222 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9224 if (DECL_IGNORED_P (fde
->decl
))
9226 if (!fde
->in_std_section
)
9228 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9230 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9231 fde
->dw_fde_begin
, "Length");
9233 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9235 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9237 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9238 fde
->dw_fde_second_begin
, "Length");
9243 /* Output the terminator words. */
9244 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9245 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9248 /* Add a new entry to .debug_ranges. Return the offset at which it
9252 add_ranges_num (int num
)
9254 unsigned int in_use
= ranges_table_in_use
;
9256 if (in_use
== ranges_table_allocated
)
9258 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9259 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9260 ranges_table_allocated
);
9261 memset (ranges_table
+ ranges_table_in_use
, 0,
9262 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9265 ranges_table
[in_use
].num
= num
;
9266 ranges_table_in_use
= in_use
+ 1;
9268 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9271 /* Add a new entry to .debug_ranges corresponding to a block, or a
9272 range terminator if BLOCK is NULL. */
9275 add_ranges (const_tree block
)
9277 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9280 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9281 When using dwarf_split_debug_info, address attributes in dies destined
9282 for the final executable should be direct references--setting the
9283 parameter force_direct ensures this behavior. */
9286 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9287 bool *added
, bool force_direct
)
9289 unsigned int in_use
= ranges_by_label_in_use
;
9290 unsigned int offset
;
9292 if (in_use
== ranges_by_label_allocated
)
9294 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9295 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9297 ranges_by_label_allocated
);
9298 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9299 RANGES_TABLE_INCREMENT
9300 * sizeof (struct dw_ranges_by_label_struct
));
9303 ranges_by_label
[in_use
].begin
= begin
;
9304 ranges_by_label
[in_use
].end
= end
;
9305 ranges_by_label_in_use
= in_use
+ 1;
9307 offset
= add_ranges_num (-(int)in_use
- 1);
9310 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9316 output_ranges (void)
9319 static const char *const start_fmt
= "Offset %#x";
9320 const char *fmt
= start_fmt
;
9322 for (i
= 0; i
< ranges_table_in_use
; i
++)
9324 int block_num
= ranges_table
[i
].num
;
9328 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9329 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9331 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9332 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9334 /* If all code is in the text section, then the compilation
9335 unit base address defaults to DW_AT_low_pc, which is the
9336 base of the text section. */
9337 if (!have_multiple_function_sections
)
9339 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9341 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9342 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9343 text_section_label
, NULL
);
9346 /* Otherwise, the compilation unit base address is zero,
9347 which allows us to use absolute addresses, and not worry
9348 about whether the target supports cross-section
9352 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9353 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9354 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9360 /* Negative block_num stands for an index into ranges_by_label. */
9361 else if (block_num
< 0)
9363 int lab_idx
= - block_num
- 1;
9365 if (!have_multiple_function_sections
)
9369 /* If we ever use add_ranges_by_labels () for a single
9370 function section, all we have to do is to take out
9372 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9373 ranges_by_label
[lab_idx
].begin
,
9375 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9376 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9377 ranges_by_label
[lab_idx
].end
,
9378 text_section_label
, NULL
);
9383 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9384 ranges_by_label
[lab_idx
].begin
,
9385 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9386 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9387 ranges_by_label
[lab_idx
].end
,
9393 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9394 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9400 /* Data structure containing information about input files. */
9403 const char *path
; /* Complete file name. */
9404 const char *fname
; /* File name part. */
9405 int length
; /* Length of entire string. */
9406 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9407 int dir_idx
; /* Index in directory table. */
9410 /* Data structure containing information about directories with source
9414 const char *path
; /* Path including directory name. */
9415 int length
; /* Path length. */
9416 int prefix
; /* Index of directory entry which is a prefix. */
9417 int count
; /* Number of files in this directory. */
9418 int dir_idx
; /* Index of directory used as base. */
9421 /* Callback function for file_info comparison. We sort by looking at
9422 the directories in the path. */
9425 file_info_cmp (const void *p1
, const void *p2
)
9427 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9428 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9429 const unsigned char *cp1
;
9430 const unsigned char *cp2
;
9432 /* Take care of file names without directories. We need to make sure that
9433 we return consistent values to qsort since some will get confused if
9434 we return the same value when identical operands are passed in opposite
9435 orders. So if neither has a directory, return 0 and otherwise return
9436 1 or -1 depending on which one has the directory. */
9437 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9438 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9440 cp1
= (const unsigned char *) s1
->path
;
9441 cp2
= (const unsigned char *) s2
->path
;
9447 /* Reached the end of the first path? If so, handle like above. */
9448 if ((cp1
== (const unsigned char *) s1
->fname
)
9449 || (cp2
== (const unsigned char *) s2
->fname
))
9450 return ((cp2
== (const unsigned char *) s2
->fname
)
9451 - (cp1
== (const unsigned char *) s1
->fname
));
9453 /* Character of current path component the same? */
9454 else if (*cp1
!= *cp2
)
9459 struct file_name_acquire_data
9461 struct file_info
*files
;
9466 /* Traversal function for the hash table. */
9469 file_name_acquire (void ** slot
, void *data
)
9471 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
9472 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
9473 struct file_info
*fi
;
9476 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9478 if (! d
->emitted_number
)
9481 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9483 fi
= fnad
->files
+ fnad
->used_files
++;
9485 /* Skip all leading "./". */
9487 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9490 /* Create a new array entry. */
9492 fi
->length
= strlen (f
);
9495 /* Search for the file name part. */
9496 f
= strrchr (f
, DIR_SEPARATOR
);
9497 #if defined (DIR_SEPARATOR_2)
9499 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9503 if (f
== NULL
|| f
< g
)
9509 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9513 /* Output the directory table and the file name table. We try to minimize
9514 the total amount of memory needed. A heuristic is used to avoid large
9515 slowdowns with many input files. */
9518 output_file_names (void)
9520 struct file_name_acquire_data fnad
;
9522 struct file_info
*files
;
9523 struct dir_info
*dirs
;
9531 if (!last_emitted_file
)
9533 dw2_asm_output_data (1, 0, "End directory table");
9534 dw2_asm_output_data (1, 0, "End file name table");
9538 numfiles
= last_emitted_file
->emitted_number
;
9540 /* Allocate the various arrays we need. */
9541 files
= XALLOCAVEC (struct file_info
, numfiles
);
9542 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9545 fnad
.used_files
= 0;
9546 fnad
.max_files
= numfiles
;
9547 htab_traverse (file_table
, file_name_acquire
, &fnad
);
9548 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9550 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9552 /* Find all the different directories used. */
9553 dirs
[0].path
= files
[0].path
;
9554 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9555 dirs
[0].prefix
= -1;
9557 dirs
[0].dir_idx
= 0;
9558 files
[0].dir_idx
= 0;
9561 for (i
= 1; i
< numfiles
; i
++)
9562 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9563 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9564 dirs
[ndirs
- 1].length
) == 0)
9566 /* Same directory as last entry. */
9567 files
[i
].dir_idx
= ndirs
- 1;
9568 ++dirs
[ndirs
- 1].count
;
9574 /* This is a new directory. */
9575 dirs
[ndirs
].path
= files
[i
].path
;
9576 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9577 dirs
[ndirs
].count
= 1;
9578 dirs
[ndirs
].dir_idx
= ndirs
;
9579 files
[i
].dir_idx
= ndirs
;
9581 /* Search for a prefix. */
9582 dirs
[ndirs
].prefix
= -1;
9583 for (j
= 0; j
< ndirs
; j
++)
9584 if (dirs
[j
].length
< dirs
[ndirs
].length
9585 && dirs
[j
].length
> 1
9586 && (dirs
[ndirs
].prefix
== -1
9587 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9588 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9589 dirs
[ndirs
].prefix
= j
;
9594 /* Now to the actual work. We have to find a subset of the directories which
9595 allow expressing the file name using references to the directory table
9596 with the least amount of characters. We do not do an exhaustive search
9597 where we would have to check out every combination of every single
9598 possible prefix. Instead we use a heuristic which provides nearly optimal
9599 results in most cases and never is much off. */
9600 saved
= XALLOCAVEC (int, ndirs
);
9601 savehere
= XALLOCAVEC (int, ndirs
);
9603 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9604 for (i
= 0; i
< ndirs
; i
++)
9609 /* We can always save some space for the current directory. But this
9610 does not mean it will be enough to justify adding the directory. */
9611 savehere
[i
] = dirs
[i
].length
;
9612 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9614 for (j
= i
+ 1; j
< ndirs
; j
++)
9617 if (saved
[j
] < dirs
[i
].length
)
9619 /* Determine whether the dirs[i] path is a prefix of the
9624 while (k
!= -1 && k
!= (int) i
)
9629 /* Yes it is. We can possibly save some memory by
9630 writing the filenames in dirs[j] relative to
9632 savehere
[j
] = dirs
[i
].length
;
9633 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9638 /* Check whether we can save enough to justify adding the dirs[i]
9640 if (total
> dirs
[i
].length
+ 1)
9642 /* It's worthwhile adding. */
9643 for (j
= i
; j
< ndirs
; j
++)
9644 if (savehere
[j
] > 0)
9646 /* Remember how much we saved for this directory so far. */
9647 saved
[j
] = savehere
[j
];
9649 /* Remember the prefix directory. */
9650 dirs
[j
].dir_idx
= i
;
9655 /* Emit the directory name table. */
9656 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9657 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9658 dw2_asm_output_nstring (dirs
[i
].path
,
9660 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
9661 "Directory Entry: %#x", i
+ idx_offset
);
9663 dw2_asm_output_data (1, 0, "End directory table");
9665 /* We have to emit them in the order of emitted_number since that's
9666 used in the debug info generation. To do this efficiently we
9667 generate a back-mapping of the indices first. */
9668 backmap
= XALLOCAVEC (int, numfiles
);
9669 for (i
= 0; i
< numfiles
; i
++)
9670 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9672 /* Now write all the file names. */
9673 for (i
= 0; i
< numfiles
; i
++)
9675 int file_idx
= backmap
[i
];
9676 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9678 #ifdef VMS_DEBUGGING_INFO
9679 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9681 /* Setting these fields can lead to debugger miscomparisons,
9682 but VMS Debug requires them to be set correctly. */
9687 int maxfilelen
= strlen (files
[file_idx
].path
)
9688 + dirs
[dir_idx
].length
9689 + MAX_VMS_VERSION_LEN
+ 1;
9690 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
9692 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
9693 snprintf (filebuf
, maxfilelen
, "%s;%d",
9694 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
9696 dw2_asm_output_nstring
9697 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
9699 /* Include directory index. */
9700 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9702 /* Modification time. */
9703 dw2_asm_output_data_uleb128
9704 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
9708 /* File length in bytes. */
9709 dw2_asm_output_data_uleb128
9710 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
9714 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
9715 "File Entry: %#x", (unsigned) i
+ 1);
9717 /* Include directory index. */
9718 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9720 /* Modification time. */
9721 dw2_asm_output_data_uleb128 (0, NULL
);
9723 /* File length in bytes. */
9724 dw2_asm_output_data_uleb128 (0, NULL
);
9725 #endif /* VMS_DEBUGGING_INFO */
9728 dw2_asm_output_data (1, 0, "End file name table");
9732 /* Output one line number table into the .debug_line section. */
9735 output_one_line_info_table (dw_line_info_table
*table
)
9737 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9738 unsigned int current_line
= 1;
9739 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
9740 dw_line_info_entry
*ent
;
9743 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
9745 switch (ent
->opcode
)
9747 case LI_set_address
:
9748 /* ??? Unfortunately, we have little choice here currently, and
9749 must always use the most general form. GCC does not know the
9750 address delta itself, so we can't use DW_LNS_advance_pc. Many
9751 ports do have length attributes which will give an upper bound
9752 on the address range. We could perhaps use length attributes
9753 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9754 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
9756 /* This can handle any delta. This takes
9757 4+DWARF2_ADDR_SIZE bytes. */
9758 dw2_asm_output_data (1, 0, "set address %s", line_label
);
9759 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9760 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9761 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9765 if (ent
->val
== current_line
)
9767 /* We still need to start a new row, so output a copy insn. */
9768 dw2_asm_output_data (1, DW_LNS_copy
,
9769 "copy line %u", current_line
);
9773 int line_offset
= ent
->val
- current_line
;
9774 int line_delta
= line_offset
- DWARF_LINE_BASE
;
9776 current_line
= ent
->val
;
9777 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9779 /* This can handle deltas from -10 to 234, using the current
9780 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9781 This takes 1 byte. */
9782 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9783 "line %u", current_line
);
9787 /* This can handle any delta. This takes at least 4 bytes,
9788 depending on the value being encoded. */
9789 dw2_asm_output_data (1, DW_LNS_advance_line
,
9790 "advance to line %u", current_line
);
9791 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9792 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
9798 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
9799 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9803 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
9804 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9807 case LI_negate_stmt
:
9808 current_is_stmt
= !current_is_stmt
;
9809 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
9810 "is_stmt %d", current_is_stmt
);
9813 case LI_set_prologue_end
:
9814 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
9815 "set prologue end");
9818 case LI_set_epilogue_begin
:
9819 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
9820 "set epilogue begin");
9823 case LI_set_discriminator
:
9824 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
9825 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
9826 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
9827 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
9832 /* Emit debug info for the address of the end of the table. */
9833 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
9834 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9835 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9836 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
9838 dw2_asm_output_data (1, 0, "end sequence");
9839 dw2_asm_output_data_uleb128 (1, NULL
);
9840 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
9843 /* Output the source line number correspondence information. This
9844 information goes into the .debug_line section. */
9847 output_line_info (bool prologue_only
)
9849 char l1
[20], l2
[20], p1
[20], p2
[20];
9850 int ver
= dwarf_version
;
9851 bool saw_one
= false;
9854 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
9855 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
9856 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
9857 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
9859 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9860 dw2_asm_output_data (4, 0xffffffff,
9861 "Initial length escape value indicating 64-bit DWARF extension");
9862 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
9863 "Length of Source Line Info");
9864 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
9866 dw2_asm_output_data (2, ver
, "DWARF Version");
9867 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
9868 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
9870 /* Define the architecture-dependent minimum instruction length (in bytes).
9871 In this implementation of DWARF, this field is used for information
9872 purposes only. Since GCC generates assembly language, we have no
9873 a priori knowledge of how many instruction bytes are generated for each
9874 source line, and therefore can use only the DW_LNE_set_address and
9875 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
9876 this as '1', which is "correct enough" for all architectures,
9877 and don't let the target override. */
9878 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
9881 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
9882 "Maximum Operations Per Instruction");
9883 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
9884 "Default is_stmt_start flag");
9885 dw2_asm_output_data (1, DWARF_LINE_BASE
,
9886 "Line Base Value (Special Opcodes)");
9887 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
9888 "Line Range Value (Special Opcodes)");
9889 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
9890 "Special Opcode Base");
9892 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
9897 case DW_LNS_advance_pc
:
9898 case DW_LNS_advance_line
:
9899 case DW_LNS_set_file
:
9900 case DW_LNS_set_column
:
9901 case DW_LNS_fixed_advance_pc
:
9902 case DW_LNS_set_isa
:
9910 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
9914 /* Write out the information about the files we use. */
9915 output_file_names ();
9916 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
9919 /* Output the marker for the end of the line number info. */
9920 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9924 if (separate_line_info
)
9926 dw_line_info_table
*table
;
9929 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
9932 output_one_line_info_table (table
);
9936 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
9938 output_one_line_info_table (cold_text_section_line_info
);
9942 /* ??? Some Darwin linkers crash on a .debug_line section with no
9943 sequences. Further, merely a DW_LNE_end_sequence entry is not
9944 sufficient -- the address column must also be initialized.
9945 Make sure to output at least one set_address/end_sequence pair,
9946 choosing .text since that section is always present. */
9947 if (text_section_line_info
->in_use
|| !saw_one
)
9948 output_one_line_info_table (text_section_line_info
);
9950 /* Output the marker for the end of the line number info. */
9951 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9954 /* Given a pointer to a tree node for some base type, return a pointer to
9955 a DIE that describes the given type.
9957 This routine must only be called for GCC type nodes that correspond to
9958 Dwarf base (fundamental) types. */
9961 base_type_die (tree type
)
9963 dw_die_ref base_type_result
;
9964 enum dwarf_type encoding
;
9966 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
9969 /* If this is a subtype that should not be emitted as a subrange type,
9970 use the base type. See subrange_type_for_debug_p. */
9971 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
9972 type
= TREE_TYPE (type
);
9974 switch (TREE_CODE (type
))
9977 if ((dwarf_version
>= 4 || !dwarf_strict
)
9979 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9980 && DECL_IS_BUILTIN (TYPE_NAME (type
))
9981 && DECL_NAME (TYPE_NAME (type
)))
9983 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
9984 if (strcmp (name
, "char16_t") == 0
9985 || strcmp (name
, "char32_t") == 0)
9987 encoding
= DW_ATE_UTF
;
9991 if (TYPE_STRING_FLAG (type
))
9993 if (TYPE_UNSIGNED (type
))
9994 encoding
= DW_ATE_unsigned_char
;
9996 encoding
= DW_ATE_signed_char
;
9998 else if (TYPE_UNSIGNED (type
))
9999 encoding
= DW_ATE_unsigned
;
10001 encoding
= DW_ATE_signed
;
10005 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
10007 if (dwarf_version
>= 3 || !dwarf_strict
)
10008 encoding
= DW_ATE_decimal_float
;
10010 encoding
= DW_ATE_lo_user
;
10013 encoding
= DW_ATE_float
;
10016 case FIXED_POINT_TYPE
:
10017 if (!(dwarf_version
>= 3 || !dwarf_strict
))
10018 encoding
= DW_ATE_lo_user
;
10019 else if (TYPE_UNSIGNED (type
))
10020 encoding
= DW_ATE_unsigned_fixed
;
10022 encoding
= DW_ATE_signed_fixed
;
10025 /* Dwarf2 doesn't know anything about complex ints, so use
10026 a user defined type for it. */
10028 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10029 encoding
= DW_ATE_complex_float
;
10031 encoding
= DW_ATE_lo_user
;
10035 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10036 encoding
= DW_ATE_boolean
;
10040 /* No other TREE_CODEs are Dwarf fundamental types. */
10041 gcc_unreachable ();
10044 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10046 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10047 int_size_in_bytes (type
));
10048 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10049 add_pubtype (type
, base_type_result
);
10051 return base_type_result
;
10054 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10055 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10058 is_base_type (tree type
)
10060 switch (TREE_CODE (type
))
10066 case FIXED_POINT_TYPE
:
10074 case QUAL_UNION_TYPE
:
10075 case ENUMERAL_TYPE
:
10076 case FUNCTION_TYPE
:
10079 case REFERENCE_TYPE
:
10087 gcc_unreachable ();
10093 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10094 node, return the size in bits for the type if it is a constant, or else
10095 return the alignment for the type if the type's size is not constant, or
10096 else return BITS_PER_WORD if the type actually turns out to be an
10097 ERROR_MARK node. */
10099 static inline unsigned HOST_WIDE_INT
10100 simple_type_size_in_bits (const_tree type
)
10102 if (TREE_CODE (type
) == ERROR_MARK
)
10103 return BITS_PER_WORD
;
10104 else if (TYPE_SIZE (type
) == NULL_TREE
)
10106 else if (host_integerp (TYPE_SIZE (type
), 1))
10107 return tree_low_cst (TYPE_SIZE (type
), 1);
10109 return TYPE_ALIGN (type
);
10112 /* Similarly, but return a double_int instead of UHWI. */
10114 static inline double_int
10115 double_int_type_size_in_bits (const_tree type
)
10117 if (TREE_CODE (type
) == ERROR_MARK
)
10118 return double_int::from_uhwi (BITS_PER_WORD
);
10119 else if (TYPE_SIZE (type
) == NULL_TREE
)
10120 return double_int_zero
;
10121 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10122 return tree_to_double_int (TYPE_SIZE (type
));
10124 return double_int::from_uhwi (TYPE_ALIGN (type
));
10127 /* Given a pointer to a tree node for a subrange type, return a pointer
10128 to a DIE that describes the given type. */
10131 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10133 dw_die_ref subrange_die
;
10134 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10136 if (context_die
== NULL
)
10137 context_die
= comp_unit_die ();
10139 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10141 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10143 /* The size of the subrange type and its base type do not match,
10144 so we need to generate a size attribute for the subrange type. */
10145 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10149 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
10151 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
10153 return subrange_die
;
10156 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10157 entry that chains various modifiers in front of the given type. */
10160 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
10161 dw_die_ref context_die
)
10163 enum tree_code code
= TREE_CODE (type
);
10164 dw_die_ref mod_type_die
;
10165 dw_die_ref sub_die
= NULL
;
10166 tree item_type
= NULL
;
10167 tree qualified_type
;
10168 tree name
, low
, high
;
10169 dw_die_ref mod_scope
;
10171 if (code
== ERROR_MARK
)
10174 /* See if we already have the appropriately qualified variant of
10177 = get_qualified_type (type
,
10178 ((is_const_type
? TYPE_QUAL_CONST
: 0)
10179 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
10181 if (qualified_type
== sizetype
10182 && TYPE_NAME (qualified_type
)
10183 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10185 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10187 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10188 && TYPE_PRECISION (t
)
10189 == TYPE_PRECISION (qualified_type
)
10190 && TYPE_UNSIGNED (t
)
10191 == TYPE_UNSIGNED (qualified_type
));
10192 qualified_type
= t
;
10195 /* If we do, then we can just use its DIE, if it exists. */
10196 if (qualified_type
)
10198 mod_type_die
= lookup_type_die (qualified_type
);
10200 return mod_type_die
;
10203 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10205 /* Handle C typedef types. */
10206 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10207 && !DECL_ARTIFICIAL (name
))
10209 tree dtype
= TREE_TYPE (name
);
10211 if (qualified_type
== dtype
)
10213 /* For a named type, use the typedef. */
10214 gen_type_die (qualified_type
, context_die
);
10215 return lookup_type_die (qualified_type
);
10217 else if (is_const_type
< TYPE_READONLY (dtype
)
10218 || is_volatile_type
< TYPE_VOLATILE (dtype
)
10219 || (is_const_type
<= TYPE_READONLY (dtype
)
10220 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
10221 && DECL_ORIGINAL_TYPE (name
) != type
))
10222 /* cv-unqualified version of named type. Just use the unnamed
10223 type to which it refers. */
10224 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10225 is_const_type
, is_volatile_type
,
10227 /* Else cv-qualified version of named type; fall through. */
10230 mod_scope
= scope_die_for (type
, context_die
);
10233 /* If both is_const_type and is_volatile_type, prefer the path
10234 which leads to a qualified type. */
10235 && (!is_volatile_type
10236 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
10237 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
10239 mod_type_die
= new_die (DW_TAG_const_type
, mod_scope
, type
);
10240 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
10242 else if (is_volatile_type
)
10244 mod_type_die
= new_die (DW_TAG_volatile_type
, mod_scope
, type
);
10245 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
10247 else if (code
== POINTER_TYPE
)
10249 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10250 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10251 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10252 item_type
= TREE_TYPE (type
);
10253 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10254 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10255 TYPE_ADDR_SPACE (item_type
));
10257 else if (code
== REFERENCE_TYPE
)
10259 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10260 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10263 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10264 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10265 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10266 item_type
= TREE_TYPE (type
);
10267 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10268 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10269 TYPE_ADDR_SPACE (item_type
));
10271 else if (code
== INTEGER_TYPE
10272 && TREE_TYPE (type
) != NULL_TREE
10273 && subrange_type_for_debug_p (type
, &low
, &high
))
10275 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10276 item_type
= TREE_TYPE (type
);
10278 else if (is_base_type (type
))
10279 mod_type_die
= base_type_die (type
);
10282 gen_type_die (type
, context_die
);
10284 /* We have to get the type_main_variant here (and pass that to the
10285 `lookup_type_die' routine) because the ..._TYPE node we have
10286 might simply be a *copy* of some original type node (where the
10287 copy was created to help us keep track of typedef names) and
10288 that copy might have a different TYPE_UID from the original
10290 if (TREE_CODE (type
) != VECTOR_TYPE
)
10291 return lookup_type_die (type_main_variant (type
));
10293 /* Vectors have the debugging information in the type,
10294 not the main variant. */
10295 return lookup_type_die (type
);
10298 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10299 don't output a DW_TAG_typedef, since there isn't one in the
10300 user's program; just attach a DW_AT_name to the type.
10301 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10302 if the base type already has the same name. */
10304 && ((TREE_CODE (name
) != TYPE_DECL
10305 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10306 || (!is_const_type
&& !is_volatile_type
)))
10307 || (TREE_CODE (name
) == TYPE_DECL
10308 && TREE_TYPE (name
) == qualified_type
10309 && DECL_NAME (name
))))
10311 if (TREE_CODE (name
) == TYPE_DECL
)
10312 /* Could just call add_name_and_src_coords_attributes here,
10313 but since this is a builtin type it doesn't have any
10314 useful source coordinates anyway. */
10315 name
= DECL_NAME (name
);
10316 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10318 /* This probably indicates a bug. */
10319 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10321 name
= TYPE_NAME (type
);
10323 && TREE_CODE (name
) == TYPE_DECL
)
10324 name
= DECL_NAME (name
);
10325 add_name_attribute (mod_type_die
,
10326 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10329 if (qualified_type
)
10330 equate_type_number_to_die (qualified_type
, mod_type_die
);
10333 /* We must do this after the equate_type_number_to_die call, in case
10334 this is a recursive type. This ensures that the modified_type_die
10335 recursion will terminate even if the type is recursive. Recursive
10336 types are possible in Ada. */
10337 sub_die
= modified_type_die (item_type
,
10338 TYPE_READONLY (item_type
),
10339 TYPE_VOLATILE (item_type
),
10342 if (sub_die
!= NULL
)
10343 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10345 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10346 if (TYPE_ARTIFICIAL (type
))
10347 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10349 return mod_type_die
;
10352 /* Generate DIEs for the generic parameters of T.
10353 T must be either a generic type or a generic function.
10354 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10357 gen_generic_params_dies (tree t
)
10361 dw_die_ref die
= NULL
;
10363 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10367 die
= lookup_type_die (t
);
10368 else if (DECL_P (t
))
10369 die
= lookup_decl_die (t
);
10373 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10375 /* T has no generic parameter. It means T is neither a generic type
10376 or function. End of story. */
10379 parms_num
= TREE_VEC_LENGTH (parms
);
10380 args
= lang_hooks
.get_innermost_generic_args (t
);
10381 for (i
= 0; i
< parms_num
; i
++)
10383 tree parm
, arg
, arg_pack_elems
;
10385 parm
= TREE_VEC_ELT (parms
, i
);
10386 arg
= TREE_VEC_ELT (args
, i
);
10387 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
10388 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
10390 if (parm
&& TREE_VALUE (parm
) && arg
)
10392 /* If PARM represents a template parameter pack,
10393 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10394 by DW_TAG_template_*_parameter DIEs for the argument
10395 pack elements of ARG. Note that ARG would then be
10396 an argument pack. */
10397 if (arg_pack_elems
)
10398 template_parameter_pack_die (TREE_VALUE (parm
),
10402 generic_parameter_die (TREE_VALUE (parm
), arg
,
10403 true /* Emit DW_AT_name */, die
);
10408 /* Create and return a DIE for PARM which should be
10409 the representation of a generic type parameter.
10410 For instance, in the C++ front end, PARM would be a template parameter.
10411 ARG is the argument to PARM.
10412 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10414 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10415 as a child node. */
10418 generic_parameter_die (tree parm
, tree arg
,
10420 dw_die_ref parent_die
)
10422 dw_die_ref tmpl_die
= NULL
;
10423 const char *name
= NULL
;
10425 if (!parm
|| !DECL_NAME (parm
) || !arg
)
10428 /* We support non-type generic parameters and arguments,
10429 type generic parameters and arguments, as well as
10430 generic generic parameters (a.k.a. template template parameters in C++)
10432 if (TREE_CODE (parm
) == PARM_DECL
)
10433 /* PARM is a nontype generic parameter */
10434 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
10435 else if (TREE_CODE (parm
) == TYPE_DECL
)
10436 /* PARM is a type generic parameter. */
10437 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
10438 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10439 /* PARM is a generic generic parameter.
10440 Its DIE is a GNU extension. It shall have a
10441 DW_AT_name attribute to represent the name of the template template
10442 parameter, and a DW_AT_GNU_template_name attribute to represent the
10443 name of the template template argument. */
10444 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
10447 gcc_unreachable ();
10453 /* If PARM is a generic parameter pack, it means we are
10454 emitting debug info for a template argument pack element.
10455 In other terms, ARG is a template argument pack element.
10456 In that case, we don't emit any DW_AT_name attribute for
10460 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
10462 add_AT_string (tmpl_die
, DW_AT_name
, name
);
10465 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10467 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10468 TMPL_DIE should have a child DW_AT_type attribute that is set
10469 to the type of the argument to PARM, which is ARG.
10470 If PARM is a type generic parameter, TMPL_DIE should have a
10471 child DW_AT_type that is set to ARG. */
10472 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
10473 add_type_attribute (tmpl_die
, tmpl_type
, 0,
10474 TREE_THIS_VOLATILE (tmpl_type
),
10479 /* So TMPL_DIE is a DIE representing a
10480 a generic generic template parameter, a.k.a template template
10481 parameter in C++ and arg is a template. */
10483 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10484 to the name of the argument. */
10485 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
10487 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
10490 if (TREE_CODE (parm
) == PARM_DECL
)
10491 /* So PARM is a non-type generic parameter.
10492 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10493 attribute of TMPL_DIE which value represents the value
10495 We must be careful here:
10496 The value of ARG might reference some function decls.
10497 We might currently be emitting debug info for a generic
10498 type and types are emitted before function decls, we don't
10499 know if the function decls referenced by ARG will actually be
10500 emitted after cgraph computations.
10501 So must defer the generation of the DW_AT_const_value to
10502 after cgraph is ready. */
10503 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
10509 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10510 PARM_PACK must be a template parameter pack. The returned DIE
10511 will be child DIE of PARENT_DIE. */
10514 template_parameter_pack_die (tree parm_pack
,
10515 tree parm_pack_args
,
10516 dw_die_ref parent_die
)
10521 gcc_assert (parent_die
&& parm_pack
);
10523 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
10524 add_name_and_src_coords_attributes (die
, parm_pack
);
10525 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
10526 generic_parameter_die (parm_pack
,
10527 TREE_VEC_ELT (parm_pack_args
, j
),
10528 false /* Don't emit DW_AT_name */,
10533 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10534 an enumerated type. */
10537 type_is_enum (const_tree type
)
10539 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10542 /* Return the DBX register number described by a given RTL node. */
10544 static unsigned int
10545 dbx_reg_number (const_rtx rtl
)
10547 unsigned regno
= REGNO (rtl
);
10549 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10551 #ifdef LEAF_REG_REMAP
10552 if (crtl
->uses_only_leaf_regs
)
10554 int leaf_reg
= LEAF_REG_REMAP (regno
);
10555 if (leaf_reg
!= -1)
10556 regno
= (unsigned) leaf_reg
;
10560 regno
= DBX_REGISTER_NUMBER (regno
);
10561 gcc_assert (regno
!= INVALID_REGNUM
);
10565 /* Optionally add a DW_OP_piece term to a location description expression.
10566 DW_OP_piece is only added if the location description expression already
10567 doesn't end with DW_OP_piece. */
10570 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10572 dw_loc_descr_ref loc
;
10574 if (*list_head
!= NULL
)
10576 /* Find the end of the chain. */
10577 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10580 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10581 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10585 /* Return a location descriptor that designates a machine register or
10586 zero if there is none. */
10588 static dw_loc_descr_ref
10589 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10593 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10596 /* We only use "frame base" when we're sure we're talking about the
10597 post-prologue local stack frame. We do this by *not* running
10598 register elimination until this point, and recognizing the special
10599 argument pointer and soft frame pointer rtx's.
10600 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10601 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
10602 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
10604 dw_loc_descr_ref result
= NULL
;
10606 if (dwarf_version
>= 4 || !dwarf_strict
)
10608 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
10611 add_loc_descr (&result
,
10612 new_loc_descr (DW_OP_stack_value
, 0, 0));
10617 regs
= targetm
.dwarf_register_span (rtl
);
10619 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
10620 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
10623 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
10624 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
10626 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
10630 /* Return a location descriptor that designates a machine register for
10631 a given hard register number. */
10633 static dw_loc_descr_ref
10634 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10636 dw_loc_descr_ref reg_loc_descr
;
10640 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10642 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10644 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10645 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10647 return reg_loc_descr
;
10650 /* Given an RTL of a register, return a location descriptor that
10651 designates a value that spans more than one register. */
10653 static dw_loc_descr_ref
10654 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10655 enum var_init_status initialized
)
10657 int nregs
, size
, i
;
10659 dw_loc_descr_ref loc_result
= NULL
;
10662 #ifdef LEAF_REG_REMAP
10663 if (crtl
->uses_only_leaf_regs
)
10665 int leaf_reg
= LEAF_REG_REMAP (reg
);
10666 if (leaf_reg
!= -1)
10667 reg
= (unsigned) leaf_reg
;
10670 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
10671 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
10673 /* Simple, contiguous registers. */
10674 if (regs
== NULL_RTX
)
10676 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
10681 dw_loc_descr_ref t
;
10683 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
10684 VAR_INIT_STATUS_INITIALIZED
);
10685 add_loc_descr (&loc_result
, t
);
10686 add_loc_descr_op_piece (&loc_result
, size
);
10692 /* Now onto stupid register sets in non contiguous locations. */
10694 gcc_assert (GET_CODE (regs
) == PARALLEL
);
10696 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10699 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
10701 dw_loc_descr_ref t
;
10703 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
10704 VAR_INIT_STATUS_INITIALIZED
);
10705 add_loc_descr (&loc_result
, t
);
10706 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10707 add_loc_descr_op_piece (&loc_result
, size
);
10710 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10711 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10715 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
10717 /* Return a location descriptor that designates a constant i,
10718 as a compound operation from constant (i >> shift), constant shift
10721 static dw_loc_descr_ref
10722 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10724 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
10725 add_loc_descr (&ret
, int_loc_descriptor (shift
));
10726 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
10730 /* Return a location descriptor that designates a constant. */
10732 static dw_loc_descr_ref
10733 int_loc_descriptor (HOST_WIDE_INT i
)
10735 enum dwarf_location_atom op
;
10737 /* Pick the smallest representation of a constant, rather than just
10738 defaulting to the LEB encoding. */
10741 int clz
= clz_hwi (i
);
10742 int ctz
= ctz_hwi (i
);
10744 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
10745 else if (i
<= 0xff)
10746 op
= DW_OP_const1u
;
10747 else if (i
<= 0xffff)
10748 op
= DW_OP_const2u
;
10749 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10750 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10751 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10752 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
10753 while DW_OP_const4u is 5 bytes. */
10754 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
10755 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10756 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10757 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10758 while DW_OP_const4u is 5 bytes. */
10759 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10760 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10761 op
= DW_OP_const4u
;
10762 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10763 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10764 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10765 while DW_OP_constu of constant >= 0x100000000 takes at least
10767 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10768 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10769 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
10770 >= HOST_BITS_PER_WIDE_INT
)
10771 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10772 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10773 while DW_OP_constu takes in this case at least 6 bytes. */
10774 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
10775 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10776 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10777 && size_of_uleb128 (i
) > 6)
10778 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10779 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
10786 op
= DW_OP_const1s
;
10787 else if (i
>= -0x8000)
10788 op
= DW_OP_const2s
;
10789 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10791 if (size_of_int_loc_descriptor (i
) < 5)
10793 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10794 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10797 op
= DW_OP_const4s
;
10801 if (size_of_int_loc_descriptor (i
)
10802 < (unsigned long) 1 + size_of_sleb128 (i
))
10804 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10805 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10812 return new_loc_descr (op
, i
, 0);
10815 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10816 without actually allocating it. */
10818 static unsigned long
10819 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10821 return size_of_int_loc_descriptor (i
>> shift
)
10822 + size_of_int_loc_descriptor (shift
)
10826 /* Return size_of_locs (int_loc_descriptor (i)) without
10827 actually allocating it. */
10829 static unsigned long
10830 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
10839 else if (i
<= 0xff)
10841 else if (i
<= 0xffff)
10845 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10846 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10847 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10849 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10850 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10851 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10853 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10855 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
10856 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10857 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10858 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10860 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10861 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
10862 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10864 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10865 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10867 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10876 else if (i
>= -0x8000)
10878 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10880 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10882 s
= size_of_int_loc_descriptor (-i
) + 1;
10890 unsigned long r
= 1 + size_of_sleb128 (i
);
10891 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10893 s
= size_of_int_loc_descriptor (-i
) + 1;
10902 /* Return loc description representing "address" of integer value.
10903 This can appear only as toplevel expression. */
10905 static dw_loc_descr_ref
10906 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
10909 dw_loc_descr_ref loc_result
= NULL
;
10911 if (!(dwarf_version
>= 4 || !dwarf_strict
))
10914 litsize
= size_of_int_loc_descriptor (i
);
10915 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10916 is more compact. For DW_OP_stack_value we need:
10917 litsize + 1 (DW_OP_stack_value)
10918 and for DW_OP_implicit_value:
10919 1 (DW_OP_implicit_value) + 1 (length) + size. */
10920 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
10922 loc_result
= int_loc_descriptor (i
);
10923 add_loc_descr (&loc_result
,
10924 new_loc_descr (DW_OP_stack_value
, 0, 0));
10928 loc_result
= new_loc_descr (DW_OP_implicit_value
,
10930 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
10931 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
10935 /* Return a location descriptor that designates a base+offset location. */
10937 static dw_loc_descr_ref
10938 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
10939 enum var_init_status initialized
)
10941 unsigned int regno
;
10942 dw_loc_descr_ref result
;
10943 dw_fde_ref fde
= cfun
->fde
;
10945 /* We only use "frame base" when we're sure we're talking about the
10946 post-prologue local stack frame. We do this by *not* running
10947 register elimination until this point, and recognizing the special
10948 argument pointer and soft frame pointer rtx's. */
10949 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
10951 rtx elim
= (ira_use_lra_p
10952 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
10953 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
10957 if (GET_CODE (elim
) == PLUS
)
10959 offset
+= INTVAL (XEXP (elim
, 1));
10960 elim
= XEXP (elim
, 0);
10962 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10963 && (elim
== hard_frame_pointer_rtx
10964 || elim
== stack_pointer_rtx
))
10965 || elim
== (frame_pointer_needed
10966 ? hard_frame_pointer_rtx
10967 : stack_pointer_rtx
));
10969 /* If drap register is used to align stack, use frame
10970 pointer + offset to access stack variables. If stack
10971 is aligned without drap, use stack pointer + offset to
10972 access stack variables. */
10973 if (crtl
->stack_realign_tried
10974 && reg
== frame_pointer_rtx
)
10977 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
10978 ? HARD_FRAME_POINTER_REGNUM
10980 return new_reg_loc_descr (base_reg
, offset
);
10983 gcc_assert (frame_pointer_fb_offset_valid
);
10984 offset
+= frame_pointer_fb_offset
;
10985 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10989 regno
= REGNO (reg
);
10990 #ifdef LEAF_REG_REMAP
10991 if (crtl
->uses_only_leaf_regs
)
10993 int leaf_reg
= LEAF_REG_REMAP (regno
);
10994 if (leaf_reg
!= -1)
10995 regno
= (unsigned) leaf_reg
;
10998 regno
= DWARF_FRAME_REGNUM (regno
);
11000 if (!optimize
&& fde
11001 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
11003 /* Use cfa+offset to represent the location of arguments passed
11004 on the stack when drap is used to align stack.
11005 Only do this when not optimizing, for optimized code var-tracking
11006 is supposed to track where the arguments live and the register
11007 used as vdrap or drap in some spot might be used for something
11008 else in other part of the routine. */
11009 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11013 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
11016 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
11018 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11019 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11024 /* Return true if this RTL expression describes a base+offset calculation. */
11027 is_based_loc (const_rtx rtl
)
11029 return (GET_CODE (rtl
) == PLUS
11030 && ((REG_P (XEXP (rtl
, 0))
11031 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
11032 && CONST_INT_P (XEXP (rtl
, 1)))));
11035 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11038 static dw_loc_descr_ref
11039 tls_mem_loc_descriptor (rtx mem
)
11042 dw_loc_descr_ref loc_result
;
11044 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
11047 base
= get_base_address (MEM_EXPR (mem
));
11049 || TREE_CODE (base
) != VAR_DECL
11050 || !DECL_THREAD_LOCAL_P (base
))
11053 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
11054 if (loc_result
== NULL
)
11057 if (MEM_OFFSET (mem
))
11058 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
11063 /* Output debug info about reason why we failed to expand expression as dwarf
11067 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
11069 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
11071 fprintf (dump_file
, "Failed to expand as dwarf: ");
11073 print_generic_expr (dump_file
, expr
, dump_flags
);
11076 fprintf (dump_file
, "\n");
11077 print_rtl (dump_file
, rtl
);
11079 fprintf (dump_file
, "\nReason: %s\n", reason
);
11083 /* Helper function for const_ok_for_output, called either directly
11084 or via for_each_rtx. */
11087 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
11091 if (GET_CODE (rtl
) == UNSPEC
)
11093 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11094 we can't express it in the debug info. */
11095 #ifdef ENABLE_CHECKING
11096 /* Don't complain about TLS UNSPECs, those are just too hard to
11097 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11098 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11099 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11100 if (XVECLEN (rtl
, 0) == 0
11101 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11102 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
11103 inform (current_function_decl
11104 ? DECL_SOURCE_LOCATION (current_function_decl
)
11105 : UNKNOWN_LOCATION
,
11106 #if NUM_UNSPEC_VALUES > 0
11107 "non-delegitimized UNSPEC %s (%d) found in variable location",
11108 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11109 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11112 "non-delegitimized UNSPEC %d found in variable location",
11116 expansion_failed (NULL_TREE
, rtl
,
11117 "UNSPEC hasn't been delegitimized.\n");
11121 if (targetm
.const_not_ok_for_debug_p (rtl
))
11123 expansion_failed (NULL_TREE
, rtl
,
11124 "Expression rejected for debug by the backend.\n");
11128 if (GET_CODE (rtl
) != SYMBOL_REF
)
11131 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11134 get_pool_constant_mark (rtl
, &marked
);
11135 /* If all references to this pool constant were optimized away,
11136 it was not output and thus we can't represent it. */
11139 expansion_failed (NULL_TREE
, rtl
,
11140 "Constant was removed from constant pool.\n");
11145 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11148 /* Avoid references to external symbols in debug info, on several targets
11149 the linker might even refuse to link when linking a shared library,
11150 and in many other cases the relocations for .debug_info/.debug_loc are
11151 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11152 to be defined within the same shared library or executable are fine. */
11153 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11155 tree decl
= SYMBOL_REF_DECL (rtl
);
11157 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11159 expansion_failed (NULL_TREE
, rtl
,
11160 "Symbol not defined in current TU.\n");
11168 /* Return true if constant RTL can be emitted in DW_OP_addr or
11169 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11170 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11173 const_ok_for_output (rtx rtl
)
11175 if (GET_CODE (rtl
) == SYMBOL_REF
)
11176 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
11178 if (GET_CODE (rtl
) == CONST
)
11179 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
11184 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11185 if possible, NULL otherwise. */
11188 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
11190 dw_die_ref type_die
;
11191 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11195 switch (TREE_CODE (type
))
11203 type_die
= lookup_type_die (type
);
11205 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
11206 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11211 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11212 type matching MODE, or, if MODE is narrower than or as wide as
11213 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11216 static dw_loc_descr_ref
11217 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
11219 enum machine_mode outer_mode
= mode
;
11220 dw_die_ref type_die
;
11221 dw_loc_descr_ref cvt
;
11223 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11225 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11228 type_die
= base_type_for_mode (outer_mode
, 1);
11229 if (type_die
== NULL
)
11231 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11232 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11233 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11234 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11235 add_loc_descr (&op
, cvt
);
11239 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11241 static dw_loc_descr_ref
11242 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11243 dw_loc_descr_ref op1
)
11245 dw_loc_descr_ref ret
= op0
;
11246 add_loc_descr (&ret
, op1
);
11247 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11248 if (STORE_FLAG_VALUE
!= 1)
11250 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11251 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11256 /* Return location descriptor for signed comparison OP RTL. */
11258 static dw_loc_descr_ref
11259 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11260 enum machine_mode mem_mode
)
11262 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11263 dw_loc_descr_ref op0
, op1
;
11266 if (op_mode
== VOIDmode
)
11267 op_mode
= GET_MODE (XEXP (rtl
, 1));
11268 if (op_mode
== VOIDmode
)
11272 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11273 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11276 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11277 VAR_INIT_STATUS_INITIALIZED
);
11278 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11279 VAR_INIT_STATUS_INITIALIZED
);
11281 if (op0
== NULL
|| op1
== NULL
)
11284 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11285 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11286 return compare_loc_descriptor (op
, op0
, op1
);
11288 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11290 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11291 dw_loc_descr_ref cvt
;
11293 if (type_die
== NULL
)
11295 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11296 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11297 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11298 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11299 add_loc_descr (&op0
, cvt
);
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 (&op1
, cvt
);
11305 return compare_loc_descriptor (op
, op0
, op1
);
11308 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11309 /* For eq/ne, if the operands are known to be zero-extended,
11310 there is no need to do the fancy shifting up. */
11311 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11313 dw_loc_descr_ref last0
, last1
;
11314 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11316 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11318 /* deref_size zero extends, and for constants we can check
11319 whether they are zero extended or not. */
11320 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11321 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11322 || (CONST_INT_P (XEXP (rtl
, 0))
11323 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11324 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11325 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11326 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11327 || (CONST_INT_P (XEXP (rtl
, 1))
11328 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11329 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11330 return compare_loc_descriptor (op
, op0
, op1
);
11332 /* EQ/NE comparison against constant in narrower type than
11333 DWARF2_ADDR_SIZE can be performed either as
11334 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11337 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11338 DW_OP_{eq,ne}. Pick whatever is shorter. */
11339 if (CONST_INT_P (XEXP (rtl
, 1))
11340 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11341 && (size_of_int_loc_descriptor (shift
) + 1
11342 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11343 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11344 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11345 & GET_MODE_MASK (op_mode
))))
11347 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11348 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11349 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11350 & GET_MODE_MASK (op_mode
));
11351 return compare_loc_descriptor (op
, op0
, op1
);
11354 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11355 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11356 if (CONST_INT_P (XEXP (rtl
, 1)))
11357 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11360 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11361 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11363 return compare_loc_descriptor (op
, op0
, op1
);
11366 /* Return location descriptor for unsigned comparison OP RTL. */
11368 static dw_loc_descr_ref
11369 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11370 enum machine_mode mem_mode
)
11372 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11373 dw_loc_descr_ref op0
, op1
;
11375 if (op_mode
== VOIDmode
)
11376 op_mode
= GET_MODE (XEXP (rtl
, 1));
11377 if (op_mode
== VOIDmode
)
11379 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
11382 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11385 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11386 VAR_INIT_STATUS_INITIALIZED
);
11387 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11388 VAR_INIT_STATUS_INITIALIZED
);
11390 if (op0
== NULL
|| op1
== NULL
)
11393 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
11395 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
11396 dw_loc_descr_ref last0
, last1
;
11397 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11399 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11401 if (CONST_INT_P (XEXP (rtl
, 0)))
11402 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
11403 /* deref_size zero extends, so no need to mask it again. */
11404 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
11405 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11407 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11408 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11410 if (CONST_INT_P (XEXP (rtl
, 1)))
11411 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
11412 /* deref_size zero extends, so no need to mask it again. */
11413 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
11414 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11416 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11417 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11420 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11422 HOST_WIDE_INT bias
= 1;
11423 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11424 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11425 if (CONST_INT_P (XEXP (rtl
, 1)))
11426 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
11427 + INTVAL (XEXP (rtl
, 1)));
11429 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
11432 return compare_loc_descriptor (op
, op0
, op1
);
11435 /* Return location descriptor for {U,S}{MIN,MAX}. */
11437 static dw_loc_descr_ref
11438 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11439 enum machine_mode mem_mode
)
11441 enum dwarf_location_atom op
;
11442 dw_loc_descr_ref op0
, op1
, ret
;
11443 dw_loc_descr_ref bra_node
, drop_node
;
11446 && (GET_MODE_CLASS (mode
) != MODE_INT
11447 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
11450 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11451 VAR_INIT_STATUS_INITIALIZED
);
11452 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11453 VAR_INIT_STATUS_INITIALIZED
);
11455 if (op0
== NULL
|| op1
== NULL
)
11458 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
11459 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
11460 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
11461 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
11463 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11465 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
11466 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11467 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11468 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11469 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11471 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11473 HOST_WIDE_INT bias
= 1;
11474 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11475 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11476 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11479 else if (GET_MODE_CLASS (mode
) == MODE_INT
11480 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11482 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11483 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11484 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11485 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11486 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11488 else if (GET_MODE_CLASS (mode
) == MODE_INT
11489 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11491 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11492 dw_loc_descr_ref cvt
;
11493 if (type_die
== NULL
)
11495 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11496 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11497 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11498 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11499 add_loc_descr (&op0
, cvt
);
11500 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11501 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11502 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11503 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11504 add_loc_descr (&op1
, cvt
);
11507 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11512 add_loc_descr (&ret
, op1
);
11513 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11514 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11515 add_loc_descr (&ret
, bra_node
);
11516 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11517 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11518 add_loc_descr (&ret
, drop_node
);
11519 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11520 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11521 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11522 && GET_MODE_CLASS (mode
) == MODE_INT
11523 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11524 ret
= convert_descriptor_to_mode (mode
, ret
);
11528 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11529 but after converting arguments to type_die, afterwards
11530 convert back to unsigned. */
11532 static dw_loc_descr_ref
11533 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11534 enum machine_mode mode
, enum machine_mode mem_mode
)
11536 dw_loc_descr_ref cvt
, op0
, op1
;
11538 if (type_die
== NULL
)
11540 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11541 VAR_INIT_STATUS_INITIALIZED
);
11542 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11543 VAR_INIT_STATUS_INITIALIZED
);
11544 if (op0
== NULL
|| op1
== NULL
)
11546 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11547 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11548 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11549 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11550 add_loc_descr (&op0
, cvt
);
11551 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11552 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11553 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11554 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11555 add_loc_descr (&op1
, cvt
);
11556 add_loc_descr (&op0
, op1
);
11557 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11558 return convert_descriptor_to_mode (mode
, op0
);
11561 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11562 const0 is DW_OP_lit0 or corresponding typed constant,
11563 const1 is DW_OP_lit1 or corresponding typed constant
11564 and constMSB is constant with just the MSB bit set
11566 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11567 L1: const0 DW_OP_swap
11568 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11569 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11574 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11575 L1: const0 DW_OP_swap
11576 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11577 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11582 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11583 L1: const1 DW_OP_swap
11584 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11585 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11589 static dw_loc_descr_ref
11590 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11591 enum machine_mode mem_mode
)
11593 dw_loc_descr_ref op0
, ret
, tmp
;
11594 HOST_WIDE_INT valv
;
11595 dw_loc_descr_ref l1jump
, l1label
;
11596 dw_loc_descr_ref l2jump
, l2label
;
11597 dw_loc_descr_ref l3jump
, l3label
;
11598 dw_loc_descr_ref l4jump
, l4label
;
11601 if (GET_MODE_CLASS (mode
) != MODE_INT
11602 || GET_MODE (XEXP (rtl
, 0)) != mode
11603 || (GET_CODE (rtl
) == CLZ
11604 && GET_MODE_BITSIZE (mode
) > HOST_BITS_PER_DOUBLE_INT
))
11607 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11608 VAR_INIT_STATUS_INITIALIZED
);
11612 if (GET_CODE (rtl
) == CLZ
)
11614 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11615 valv
= GET_MODE_BITSIZE (mode
);
11617 else if (GET_CODE (rtl
) == FFS
)
11619 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11620 valv
= GET_MODE_BITSIZE (mode
);
11621 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11622 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11623 add_loc_descr (&ret
, l1jump
);
11624 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11625 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
11626 VAR_INIT_STATUS_INITIALIZED
);
11629 add_loc_descr (&ret
, tmp
);
11630 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11631 add_loc_descr (&ret
, l4jump
);
11632 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
11633 ? const1_rtx
: const0_rtx
,
11635 VAR_INIT_STATUS_INITIALIZED
);
11636 if (l1label
== NULL
)
11638 add_loc_descr (&ret
, l1label
);
11639 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11640 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
11641 add_loc_descr (&ret
, l2label
);
11642 if (GET_CODE (rtl
) != CLZ
)
11644 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11645 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
11646 << (GET_MODE_BITSIZE (mode
) - 1));
11648 msb
= immed_double_const (0, (unsigned HOST_WIDE_INT
) 1
11649 << (GET_MODE_BITSIZE (mode
)
11650 - HOST_BITS_PER_WIDE_INT
- 1), mode
);
11651 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
11652 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11653 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
11654 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
11656 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
11657 VAR_INIT_STATUS_INITIALIZED
);
11660 add_loc_descr (&ret
, tmp
);
11661 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11662 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11663 add_loc_descr (&ret
, l3jump
);
11664 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11665 VAR_INIT_STATUS_INITIALIZED
);
11668 add_loc_descr (&ret
, tmp
);
11669 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
11670 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
11671 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11672 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
11673 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11674 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11675 add_loc_descr (&ret
, l2jump
);
11676 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
11677 add_loc_descr (&ret
, l3label
);
11678 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
11679 add_loc_descr (&ret
, l4label
);
11680 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11681 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11682 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11683 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11684 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11685 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
11686 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11687 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
11691 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11692 const1 is DW_OP_lit1 or corresponding typed constant):
11694 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11695 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11699 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11700 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11703 static dw_loc_descr_ref
11704 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11705 enum machine_mode mem_mode
)
11707 dw_loc_descr_ref op0
, ret
, tmp
;
11708 dw_loc_descr_ref l1jump
, l1label
;
11709 dw_loc_descr_ref l2jump
, l2label
;
11711 if (GET_MODE_CLASS (mode
) != MODE_INT
11712 || GET_MODE (XEXP (rtl
, 0)) != mode
)
11715 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11716 VAR_INIT_STATUS_INITIALIZED
);
11720 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11721 VAR_INIT_STATUS_INITIALIZED
);
11724 add_loc_descr (&ret
, tmp
);
11725 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11726 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
11727 add_loc_descr (&ret
, l1label
);
11728 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11729 add_loc_descr (&ret
, l2jump
);
11730 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11731 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11732 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11733 VAR_INIT_STATUS_INITIALIZED
);
11736 add_loc_descr (&ret
, tmp
);
11737 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11738 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
11739 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
11740 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11741 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11742 VAR_INIT_STATUS_INITIALIZED
);
11743 add_loc_descr (&ret
, tmp
);
11744 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11745 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11746 add_loc_descr (&ret
, l1jump
);
11747 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11748 add_loc_descr (&ret
, l2label
);
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
;
11756 /* BSWAP (constS is initial shift count, either 56 or 24):
11758 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11759 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11760 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11761 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11762 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11764 static dw_loc_descr_ref
11765 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11766 enum machine_mode mem_mode
)
11768 dw_loc_descr_ref op0
, ret
, tmp
;
11769 dw_loc_descr_ref l1jump
, l1label
;
11770 dw_loc_descr_ref l2jump
, l2label
;
11772 if (GET_MODE_CLASS (mode
) != MODE_INT
11773 || BITS_PER_UNIT
!= 8
11774 || (GET_MODE_BITSIZE (mode
) != 32
11775 && GET_MODE_BITSIZE (mode
) != 64))
11778 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11779 VAR_INIT_STATUS_INITIALIZED
);
11784 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11786 VAR_INIT_STATUS_INITIALIZED
);
11789 add_loc_descr (&ret
, tmp
);
11790 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11791 VAR_INIT_STATUS_INITIALIZED
);
11794 add_loc_descr (&ret
, tmp
);
11795 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
11796 add_loc_descr (&ret
, l1label
);
11797 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11799 VAR_INIT_STATUS_INITIALIZED
);
11800 add_loc_descr (&ret
, tmp
);
11801 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
11802 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11803 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11804 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
11805 VAR_INIT_STATUS_INITIALIZED
);
11808 add_loc_descr (&ret
, tmp
);
11809 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11810 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
11811 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11812 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11813 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11814 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11815 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11816 VAR_INIT_STATUS_INITIALIZED
);
11817 add_loc_descr (&ret
, tmp
);
11818 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
11819 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11820 add_loc_descr (&ret
, l2jump
);
11821 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
11822 VAR_INIT_STATUS_INITIALIZED
);
11823 add_loc_descr (&ret
, tmp
);
11824 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11825 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11826 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11827 add_loc_descr (&ret
, l1jump
);
11828 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11829 add_loc_descr (&ret
, l2label
);
11830 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11831 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11832 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11833 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11834 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11835 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11839 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
11840 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11841 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
11842 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
11844 ROTATERT is similar:
11845 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
11846 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11847 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
11849 static dw_loc_descr_ref
11850 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11851 enum machine_mode mem_mode
)
11853 rtx rtlop1
= XEXP (rtl
, 1);
11854 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
11857 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11860 if (GET_MODE (rtlop1
) != VOIDmode
11861 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
11862 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
11863 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11864 VAR_INIT_STATUS_INITIALIZED
);
11865 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
11866 VAR_INIT_STATUS_INITIALIZED
);
11867 if (op0
== NULL
|| op1
== NULL
)
11869 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11870 for (i
= 0; i
< 2; i
++)
11872 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
11873 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
11875 VAR_INIT_STATUS_INITIALIZED
);
11876 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
11877 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11879 : HOST_BITS_PER_WIDE_INT
== 64
11880 ? DW_OP_const8u
: DW_OP_constu
,
11881 GET_MODE_MASK (mode
), 0);
11884 if (mask
[i
] == NULL
)
11886 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
11889 add_loc_descr (&ret
, op1
);
11890 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11891 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11892 if (GET_CODE (rtl
) == ROTATERT
)
11894 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11895 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11896 GET_MODE_BITSIZE (mode
), 0));
11898 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11899 if (mask
[0] != NULL
)
11900 add_loc_descr (&ret
, mask
[0]);
11901 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11902 if (mask
[1] != NULL
)
11904 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11905 add_loc_descr (&ret
, mask
[1]);
11906 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11908 if (GET_CODE (rtl
) == ROTATE
)
11910 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11911 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11912 GET_MODE_BITSIZE (mode
), 0));
11914 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11915 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11919 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11920 for DEBUG_PARAMETER_REF RTL. */
11922 static dw_loc_descr_ref
11923 parameter_ref_descriptor (rtx rtl
)
11925 dw_loc_descr_ref ret
;
11930 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
11931 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
11932 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
11935 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11936 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
11937 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11941 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
11942 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
11947 /* The following routine converts the RTL for a variable or parameter
11948 (resident in memory) into an equivalent Dwarf representation of a
11949 mechanism for getting the address of that same variable onto the top of a
11950 hypothetical "address evaluation" stack.
11952 When creating memory location descriptors, we are effectively transforming
11953 the RTL for a memory-resident object into its Dwarf postfix expression
11954 equivalent. This routine recursively descends an RTL tree, turning
11955 it into Dwarf postfix code as it goes.
11957 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
11959 MEM_MODE is the mode of the memory reference, needed to handle some
11960 autoincrement addressing modes.
11962 Return 0 if we can't represent the location. */
11965 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11966 enum machine_mode mem_mode
,
11967 enum var_init_status initialized
)
11969 dw_loc_descr_ref mem_loc_result
= NULL
;
11970 enum dwarf_location_atom op
;
11971 dw_loc_descr_ref op0
, op1
;
11972 rtx inner
= NULL_RTX
;
11974 if (mode
== VOIDmode
)
11975 mode
= GET_MODE (rtl
);
11977 /* Note that for a dynamically sized array, the location we will generate a
11978 description of here will be the lowest numbered location which is
11979 actually within the array. That's *not* necessarily the same as the
11980 zeroth element of the array. */
11982 rtl
= targetm
.delegitimize_address (rtl
);
11984 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
11987 switch (GET_CODE (rtl
))
11992 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
11995 /* The case of a subreg may arise when we have a local (register)
11996 variable or a formal (register) parameter which doesn't quite fill
11997 up an entire register. For now, just assume that it is
11998 legitimate to make the Dwarf info refer to the whole register which
11999 contains the given subreg. */
12000 if (!subreg_lowpart_p (rtl
))
12002 inner
= SUBREG_REG (rtl
);
12004 if (inner
== NULL_RTX
)
12005 inner
= XEXP (rtl
, 0);
12006 if (GET_MODE_CLASS (mode
) == MODE_INT
12007 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
12008 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12009 #ifdef POINTERS_EXTEND_UNSIGNED
12010 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
12013 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
12015 mem_loc_result
= mem_loc_descriptor (inner
,
12017 mem_mode
, initialized
);
12022 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
12024 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
12025 && (GET_MODE_CLASS (mode
) != MODE_INT
12026 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
12030 dw_die_ref type_die
;
12031 dw_loc_descr_ref cvt
;
12033 mem_loc_result
= mem_loc_descriptor (inner
,
12035 mem_mode
, initialized
);
12036 if (mem_loc_result
== NULL
)
12038 type_die
= base_type_for_mode (mode
,
12039 GET_MODE_CLASS (mode
) == MODE_INT
);
12040 if (type_die
== NULL
)
12042 mem_loc_result
= NULL
;
12045 if (GET_MODE_SIZE (mode
)
12046 != GET_MODE_SIZE (GET_MODE (inner
)))
12047 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12049 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
12050 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12051 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12052 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12053 add_loc_descr (&mem_loc_result
, cvt
);
12058 if (GET_MODE_CLASS (mode
) != MODE_INT
12059 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12060 && rtl
!= arg_pointer_rtx
12061 && rtl
!= frame_pointer_rtx
12062 #ifdef POINTERS_EXTEND_UNSIGNED
12063 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12067 dw_die_ref type_die
;
12068 unsigned int dbx_regnum
;
12072 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
12074 type_die
= base_type_for_mode (mode
,
12075 GET_MODE_CLASS (mode
) == MODE_INT
);
12076 if (type_die
== NULL
)
12079 dbx_regnum
= dbx_reg_number (rtl
);
12080 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12082 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
12084 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12085 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12086 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12089 /* Whenever a register number forms a part of the description of the
12090 method for calculating the (dynamic) address of a memory resident
12091 object, DWARF rules require the register number be referred to as
12092 a "base register". This distinction is not based in any way upon
12093 what category of register the hardware believes the given register
12094 belongs to. This is strictly DWARF terminology we're dealing with
12095 here. Note that in cases where the location of a memory-resident
12096 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12097 OP_CONST (0)) the actual DWARF location descriptor that we generate
12098 may just be OP_BASEREG (basereg). This may look deceptively like
12099 the object in question was allocated to a register (rather than in
12100 memory) so DWARF consumers need to be aware of the subtle
12101 distinction between OP_REG and OP_BASEREG. */
12102 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12103 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12104 else if (stack_realign_drap
12106 && crtl
->args
.internal_arg_pointer
== rtl
12107 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12109 /* If RTL is internal_arg_pointer, which has been optimized
12110 out, use DRAP instead. */
12111 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12112 VAR_INIT_STATUS_INITIALIZED
);
12118 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12120 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12121 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12124 else if (GET_CODE (rtl
) == ZERO_EXTEND
12125 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12126 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12127 < HOST_BITS_PER_WIDE_INT
12128 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12129 to expand zero extend as two shifts instead of
12131 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12133 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12134 mem_loc_result
= op0
;
12135 add_loc_descr (&mem_loc_result
,
12136 int_loc_descriptor (GET_MODE_MASK (imode
)));
12137 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12139 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12141 int shift
= DWARF2_ADDR_SIZE
12142 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12143 shift
*= BITS_PER_UNIT
;
12144 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12148 mem_loc_result
= op0
;
12149 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12150 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12151 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12152 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12154 else if (!dwarf_strict
)
12156 dw_die_ref type_die1
, type_die2
;
12157 dw_loc_descr_ref cvt
;
12159 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12160 GET_CODE (rtl
) == ZERO_EXTEND
);
12161 if (type_die1
== NULL
)
12163 type_die2
= base_type_for_mode (mode
, 1);
12164 if (type_die2
== NULL
)
12166 mem_loc_result
= op0
;
12167 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12168 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12169 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12170 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12171 add_loc_descr (&mem_loc_result
, cvt
);
12172 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12173 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12174 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12175 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12176 add_loc_descr (&mem_loc_result
, cvt
);
12182 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12183 if (new_rtl
!= rtl
)
12185 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12187 if (mem_loc_result
!= NULL
)
12188 return mem_loc_result
;
12191 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12192 get_address_mode (rtl
), mode
,
12193 VAR_INIT_STATUS_INITIALIZED
);
12194 if (mem_loc_result
== NULL
)
12195 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12196 if (mem_loc_result
!= NULL
)
12198 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12199 || GET_MODE_CLASS (mode
) != MODE_INT
)
12201 dw_die_ref type_die
;
12202 dw_loc_descr_ref deref
;
12207 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12208 if (type_die
== NULL
)
12210 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12211 GET_MODE_SIZE (mode
), 0);
12212 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12213 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12214 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12215 add_loc_descr (&mem_loc_result
, deref
);
12217 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12218 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12220 add_loc_descr (&mem_loc_result
,
12221 new_loc_descr (DW_OP_deref_size
,
12222 GET_MODE_SIZE (mode
), 0));
12227 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12230 /* Some ports can transform a symbol ref into a label ref, because
12231 the symbol ref is too far away and has to be dumped into a constant
12235 if (GET_MODE_CLASS (mode
) != MODE_INT
12236 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12237 #ifdef POINTERS_EXTEND_UNSIGNED
12238 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12242 if (GET_CODE (rtl
) == SYMBOL_REF
12243 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12245 dw_loc_descr_ref temp
;
12247 /* If this is not defined, we have no way to emit the data. */
12248 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12251 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12253 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12254 add_loc_descr (&mem_loc_result
, temp
);
12259 if (!const_ok_for_output (rtl
))
12263 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12264 vec_safe_push (used_rtx_array
, rtl
);
12270 case DEBUG_IMPLICIT_PTR
:
12271 expansion_failed (NULL_TREE
, rtl
,
12272 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12278 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12280 if (GET_MODE_CLASS (mode
) != MODE_INT
12281 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12282 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12283 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12286 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12287 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12289 op0
= one_reg_loc_descriptor (dbx_regnum
,
12290 VAR_INIT_STATUS_INITIALIZED
);
12293 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12294 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12296 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12297 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12298 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12302 gcc_unreachable ();
12305 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12306 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12307 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12310 case DEBUG_PARAMETER_REF
:
12311 mem_loc_result
= parameter_ref_descriptor (rtl
);
12315 /* Extract the PLUS expression nested inside and fall into
12316 PLUS code below. */
12317 rtl
= XEXP (rtl
, 1);
12322 /* Turn these into a PLUS expression and fall into the PLUS code
12324 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12325 GEN_INT (GET_CODE (rtl
) == PRE_INC
12326 ? GET_MODE_UNIT_SIZE (mem_mode
)
12327 : -GET_MODE_UNIT_SIZE (mem_mode
)));
12329 /* ... fall through ... */
12333 if (is_based_loc (rtl
)
12334 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12335 || XEXP (rtl
, 0) == arg_pointer_rtx
12336 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12337 && GET_MODE_CLASS (mode
) == MODE_INT
)
12338 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12339 INTVAL (XEXP (rtl
, 1)),
12340 VAR_INIT_STATUS_INITIALIZED
);
12343 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12344 VAR_INIT_STATUS_INITIALIZED
);
12345 if (mem_loc_result
== 0)
12348 if (CONST_INT_P (XEXP (rtl
, 1))
12349 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12350 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12353 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12354 VAR_INIT_STATUS_INITIALIZED
);
12357 add_loc_descr (&mem_loc_result
, op1
);
12358 add_loc_descr (&mem_loc_result
,
12359 new_loc_descr (DW_OP_plus
, 0, 0));
12364 /* If a pseudo-reg is optimized away, it is possible for it to
12365 be replaced with a MEM containing a multiply or shift. */
12376 && GET_MODE_CLASS (mode
) == MODE_INT
12377 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12379 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12380 base_type_for_mode (mode
, 0),
12404 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12406 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12407 VAR_INIT_STATUS_INITIALIZED
);
12409 rtx rtlop1
= XEXP (rtl
, 1);
12410 if (GET_MODE (rtlop1
) != VOIDmode
12411 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
12412 < GET_MODE_BITSIZE (mode
))
12413 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12414 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12415 VAR_INIT_STATUS_INITIALIZED
);
12418 if (op0
== 0 || op1
== 0)
12421 mem_loc_result
= op0
;
12422 add_loc_descr (&mem_loc_result
, op1
);
12423 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12439 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12440 VAR_INIT_STATUS_INITIALIZED
);
12441 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12442 VAR_INIT_STATUS_INITIALIZED
);
12444 if (op0
== 0 || op1
== 0)
12447 mem_loc_result
= op0
;
12448 add_loc_descr (&mem_loc_result
, op1
);
12449 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12453 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
12455 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
12456 base_type_for_mode (mode
, 0),
12461 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12462 VAR_INIT_STATUS_INITIALIZED
);
12463 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12464 VAR_INIT_STATUS_INITIALIZED
);
12466 if (op0
== 0 || op1
== 0)
12469 mem_loc_result
= op0
;
12470 add_loc_descr (&mem_loc_result
, op1
);
12471 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12472 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12473 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
12474 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
12475 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12479 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12481 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12486 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12487 base_type_for_mode (mode
, 1),
12505 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12506 VAR_INIT_STATUS_INITIALIZED
);
12511 mem_loc_result
= op0
;
12512 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12516 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12517 #ifdef POINTERS_EXTEND_UNSIGNED
12519 && mem_mode
!= VOIDmode
12520 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12524 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12528 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12529 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
12531 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12532 enum machine_mode amode
;
12533 if (type_die
== NULL
)
12535 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12537 if (INTVAL (rtl
) >= 0
12538 && amode
!= BLKmode
12539 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12540 /* const DW_OP_GNU_convert <XXX> vs.
12541 DW_OP_GNU_const_type <XXX, 1, const>. */
12542 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12543 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12545 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12546 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12547 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12548 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12549 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12550 add_loc_descr (&mem_loc_result
, op0
);
12551 return mem_loc_result
;
12553 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12555 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12556 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12557 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12558 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12559 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12562 mem_loc_result
->dw_loc_oprnd2
.val_class
12563 = dw_val_class_const_double
;
12564 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12565 = double_int::from_shwi (INTVAL (rtl
));
12573 dw_die_ref type_die
;
12575 /* Note that a CONST_DOUBLE rtx could represent either an integer
12576 or a floating-point constant. A CONST_DOUBLE is used whenever
12577 the constant requires more than one word in order to be
12578 adequately represented. We output CONST_DOUBLEs as blocks. */
12579 if (mode
== VOIDmode
12580 || (GET_MODE (rtl
) == VOIDmode
12581 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
12583 type_die
= base_type_for_mode (mode
,
12584 GET_MODE_CLASS (mode
) == MODE_INT
);
12585 if (type_die
== NULL
)
12587 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12588 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12589 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12590 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12591 if (SCALAR_FLOAT_MODE_P (mode
))
12593 unsigned int length
= GET_MODE_SIZE (mode
);
12594 unsigned char *array
12595 = (unsigned char*) ggc_alloc_atomic (length
);
12597 insert_float (rtl
, array
);
12598 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12599 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12600 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12601 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12605 mem_loc_result
->dw_loc_oprnd2
.val_class
12606 = dw_val_class_const_double
;
12607 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12608 = rtx_to_double_int (rtl
);
12614 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
12618 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12622 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12626 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12630 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12634 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
12638 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12642 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12646 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12650 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12655 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12660 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
12665 if (CONST_INT_P (XEXP (rtl
, 1))
12666 && CONST_INT_P (XEXP (rtl
, 2))
12667 && ((unsigned) INTVAL (XEXP (rtl
, 1))
12668 + (unsigned) INTVAL (XEXP (rtl
, 2))
12669 <= GET_MODE_BITSIZE (mode
))
12670 && GET_MODE_CLASS (mode
) == MODE_INT
12671 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12672 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
12675 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12676 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12679 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
12683 mem_loc_result
= op0
;
12684 size
= INTVAL (XEXP (rtl
, 1));
12685 shift
= INTVAL (XEXP (rtl
, 2));
12686 if (BITS_BIG_ENDIAN
)
12687 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12689 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
12691 add_loc_descr (&mem_loc_result
,
12692 int_loc_descriptor (DWARF2_ADDR_SIZE
12694 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12696 if (size
!= (int) DWARF2_ADDR_SIZE
)
12698 add_loc_descr (&mem_loc_result
,
12699 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
12700 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12707 dw_loc_descr_ref op2
, bra_node
, drop_node
;
12708 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
12709 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
12710 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
12711 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12712 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12713 VAR_INIT_STATUS_INITIALIZED
);
12714 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
12715 VAR_INIT_STATUS_INITIALIZED
);
12716 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
12719 mem_loc_result
= op1
;
12720 add_loc_descr (&mem_loc_result
, op2
);
12721 add_loc_descr (&mem_loc_result
, op0
);
12722 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12723 add_loc_descr (&mem_loc_result
, bra_node
);
12724 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
12725 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12726 add_loc_descr (&mem_loc_result
, drop_node
);
12727 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12728 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12733 case FLOAT_TRUNCATE
:
12735 case UNSIGNED_FLOAT
:
12740 dw_die_ref type_die
;
12741 dw_loc_descr_ref cvt
;
12743 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12744 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12747 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
12748 && (GET_CODE (rtl
) == FLOAT
12749 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
12750 <= DWARF2_ADDR_SIZE
))
12752 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12753 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
12754 if (type_die
== NULL
)
12756 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12757 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12758 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12759 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12760 add_loc_descr (&op0
, cvt
);
12762 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
12763 if (type_die
== NULL
)
12765 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12766 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12767 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12768 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12769 add_loc_descr (&op0
, cvt
);
12770 if (GET_MODE_CLASS (mode
) == MODE_INT
12771 && (GET_CODE (rtl
) == FIX
12772 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
12774 op0
= convert_descriptor_to_mode (mode
, op0
);
12778 mem_loc_result
= op0
;
12785 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
12790 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
12794 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
12799 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
12803 /* In theory, we could implement the above. */
12804 /* DWARF cannot represent the unsigned compare operations
12829 case FRACT_CONVERT
:
12830 case UNSIGNED_FRACT_CONVERT
:
12832 case UNSIGNED_SAT_FRACT
:
12838 case VEC_DUPLICATE
:
12842 case STRICT_LOW_PART
:
12847 /* If delegitimize_address couldn't do anything with the UNSPEC, we
12848 can't express it in the debug info. This can happen e.g. with some
12853 resolve_one_addr (&rtl
, NULL
);
12857 #ifdef ENABLE_CHECKING
12858 print_rtl (stderr
, rtl
);
12859 gcc_unreachable ();
12865 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12866 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12868 return mem_loc_result
;
12871 /* Return a descriptor that describes the concatenation of two locations.
12872 This is typically a complex variable. */
12874 static dw_loc_descr_ref
12875 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
12877 dw_loc_descr_ref cc_loc_result
= NULL
;
12878 dw_loc_descr_ref x0_ref
12879 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12880 dw_loc_descr_ref x1_ref
12881 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12883 if (x0_ref
== 0 || x1_ref
== 0)
12886 cc_loc_result
= x0_ref
;
12887 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
12889 add_loc_descr (&cc_loc_result
, x1_ref
);
12890 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
12892 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12893 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12895 return cc_loc_result
;
12898 /* Return a descriptor that describes the concatenation of N
12901 static dw_loc_descr_ref
12902 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
12905 dw_loc_descr_ref cc_loc_result
= NULL
;
12906 unsigned int n
= XVECLEN (concatn
, 0);
12908 for (i
= 0; i
< n
; ++i
)
12910 dw_loc_descr_ref ref
;
12911 rtx x
= XVECEXP (concatn
, 0, i
);
12913 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12917 add_loc_descr (&cc_loc_result
, ref
);
12918 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
12921 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12922 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12924 return cc_loc_result
;
12927 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12928 for DEBUG_IMPLICIT_PTR RTL. */
12930 static dw_loc_descr_ref
12931 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
12933 dw_loc_descr_ref ret
;
12938 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
12939 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
12940 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
12941 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
12942 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
12943 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12946 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12947 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12948 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12952 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12953 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
12958 /* Output a proper Dwarf location descriptor for a variable or parameter
12959 which is either allocated in a register or in a memory location. For a
12960 register, we just generate an OP_REG and the register number. For a
12961 memory location we provide a Dwarf postfix expression describing how to
12962 generate the (dynamic) address of the object onto the address stack.
12964 MODE is mode of the decl if this loc_descriptor is going to be used in
12965 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
12966 allowed, VOIDmode otherwise.
12968 If we don't know how to describe it, return 0. */
12970 static dw_loc_descr_ref
12971 loc_descriptor (rtx rtl
, enum machine_mode mode
,
12972 enum var_init_status initialized
)
12974 dw_loc_descr_ref loc_result
= NULL
;
12976 switch (GET_CODE (rtl
))
12979 /* The case of a subreg may arise when we have a local (register)
12980 variable or a formal (register) parameter which doesn't quite fill
12981 up an entire register. For now, just assume that it is
12982 legitimate to make the Dwarf info refer to the whole register which
12983 contains the given subreg. */
12984 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
12985 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
12986 GET_MODE (SUBREG_REG (rtl
)), initialized
);
12992 loc_result
= reg_loc_descriptor (rtl
, initialized
);
12996 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
12997 GET_MODE (rtl
), initialized
);
12998 if (loc_result
== NULL
)
12999 loc_result
= tls_mem_loc_descriptor (rtl
);
13000 if (loc_result
== NULL
)
13002 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13003 if (new_rtl
!= rtl
)
13004 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
13009 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
13014 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
13019 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
13021 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
13022 if (GET_CODE (loc
) == EXPR_LIST
)
13023 loc
= XEXP (loc
, 0);
13024 loc_result
= loc_descriptor (loc
, mode
, initialized
);
13028 rtl
= XEXP (rtl
, 1);
13033 rtvec par_elems
= XVEC (rtl
, 0);
13034 int num_elem
= GET_NUM_ELEM (par_elems
);
13035 enum machine_mode mode
;
13038 /* Create the first one, so we have something to add to. */
13039 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
13040 VOIDmode
, initialized
);
13041 if (loc_result
== NULL
)
13043 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
13044 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13045 for (i
= 1; i
< num_elem
; i
++)
13047 dw_loc_descr_ref temp
;
13049 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
13050 VOIDmode
, initialized
);
13053 add_loc_descr (&loc_result
, temp
);
13054 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
13055 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13061 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
13062 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
13067 if (mode
== VOIDmode
)
13068 mode
= GET_MODE (rtl
);
13070 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13072 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13074 /* Note that a CONST_DOUBLE rtx could represent either an integer
13075 or a floating-point constant. A CONST_DOUBLE is used whenever
13076 the constant requires more than one word in order to be
13077 adequately represented. We output CONST_DOUBLEs as blocks. */
13078 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13079 GET_MODE_SIZE (mode
), 0);
13080 if (SCALAR_FLOAT_MODE_P (mode
))
13082 unsigned int length
= GET_MODE_SIZE (mode
);
13083 unsigned char *array
13084 = (unsigned char*) ggc_alloc_atomic (length
);
13086 insert_float (rtl
, array
);
13087 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13088 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13089 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13090 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13094 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
13095 loc_result
->dw_loc_oprnd2
.v
.val_double
13096 = rtx_to_double_int (rtl
);
13102 if (mode
== VOIDmode
)
13103 mode
= GET_MODE (rtl
);
13105 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13107 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13108 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13109 unsigned char *array
= (unsigned char *)
13110 ggc_alloc_atomic (length
* elt_size
);
13114 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13115 switch (GET_MODE_CLASS (mode
))
13117 case MODE_VECTOR_INT
:
13118 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13120 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13121 double_int val
= rtx_to_double_int (elt
);
13123 if (elt_size
<= sizeof (HOST_WIDE_INT
))
13124 insert_int (val
.to_shwi (), elt_size
, p
);
13127 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
13128 insert_double (val
, p
);
13133 case MODE_VECTOR_FLOAT
:
13134 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13136 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13137 insert_float (elt
, p
);
13142 gcc_unreachable ();
13145 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13146 length
* elt_size
, 0);
13147 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13148 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13149 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13150 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13155 if (mode
== VOIDmode
13156 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13157 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13158 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13160 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13165 if (!const_ok_for_output (rtl
))
13168 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13169 && (dwarf_version
>= 4 || !dwarf_strict
))
13171 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13172 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13173 vec_safe_push (used_rtx_array
, rtl
);
13177 case DEBUG_IMPLICIT_PTR
:
13178 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13182 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13183 && CONST_INT_P (XEXP (rtl
, 1)))
13186 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13192 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13193 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13194 && dwarf_version
>= 4)
13195 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13197 /* Value expression. */
13198 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13200 add_loc_descr (&loc_result
,
13201 new_loc_descr (DW_OP_stack_value
, 0, 0));
13209 /* We need to figure out what section we should use as the base for the
13210 address ranges where a given location is valid.
13211 1. If this particular DECL has a section associated with it, use that.
13212 2. If this function has a section associated with it, use that.
13213 3. Otherwise, use the text section.
13214 XXX: If you split a variable across multiple sections, we won't notice. */
13216 static const char *
13217 secname_for_decl (const_tree decl
)
13219 const char *secname
;
13221 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
13223 tree sectree
= DECL_SECTION_NAME (decl
);
13224 secname
= TREE_STRING_POINTER (sectree
);
13226 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13228 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
13229 secname
= TREE_STRING_POINTER (sectree
);
13231 else if (cfun
&& in_cold_section_p
)
13232 secname
= crtl
->subsections
.cold_section_label
;
13234 secname
= text_section_label
;
13239 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13242 decl_by_reference_p (tree decl
)
13244 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13245 || TREE_CODE (decl
) == VAR_DECL
)
13246 && DECL_BY_REFERENCE (decl
));
13249 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13252 static dw_loc_descr_ref
13253 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13254 enum var_init_status initialized
)
13256 int have_address
= 0;
13257 dw_loc_descr_ref descr
;
13258 enum machine_mode mode
;
13260 if (want_address
!= 2)
13262 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13264 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13266 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13267 if (GET_CODE (varloc
) == EXPR_LIST
)
13268 varloc
= XEXP (varloc
, 0);
13269 mode
= GET_MODE (varloc
);
13270 if (MEM_P (varloc
))
13272 rtx addr
= XEXP (varloc
, 0);
13273 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13274 mode
, initialized
);
13279 rtx x
= avoid_constant_pool_reference (varloc
);
13281 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13286 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13293 if (GET_CODE (varloc
) == VAR_LOCATION
)
13294 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13296 mode
= DECL_MODE (loc
);
13297 descr
= loc_descriptor (varloc
, mode
, initialized
);
13304 if (want_address
== 2 && !have_address
13305 && (dwarf_version
>= 4 || !dwarf_strict
))
13307 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13309 expansion_failed (loc
, NULL_RTX
,
13310 "DWARF address size mismatch");
13313 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13316 /* Show if we can't fill the request for an address. */
13317 if (want_address
&& !have_address
)
13319 expansion_failed (loc
, NULL_RTX
,
13320 "Want address and only have value");
13324 /* If we've got an address and don't want one, dereference. */
13325 if (!want_address
&& have_address
)
13327 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13328 enum dwarf_location_atom op
;
13330 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13332 expansion_failed (loc
, NULL_RTX
,
13333 "DWARF address size mismatch");
13336 else if (size
== DWARF2_ADDR_SIZE
)
13339 op
= DW_OP_deref_size
;
13341 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
13347 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13348 if it is not possible. */
13350 static dw_loc_descr_ref
13351 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
13353 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
13354 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
13355 else if (dwarf_version
>= 3 || !dwarf_strict
)
13356 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
13361 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13362 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13364 static dw_loc_descr_ref
13365 dw_sra_loc_expr (tree decl
, rtx loc
)
13368 unsigned int padsize
= 0;
13369 dw_loc_descr_ref descr
, *descr_tail
;
13370 unsigned HOST_WIDE_INT decl_size
;
13372 enum var_init_status initialized
;
13374 if (DECL_SIZE (decl
) == NULL
13375 || !host_integerp (DECL_SIZE (decl
), 1))
13378 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
13380 descr_tail
= &descr
;
13382 for (p
= loc
; p
; p
= XEXP (p
, 1))
13384 unsigned int bitsize
= decl_piece_bitsize (p
);
13385 rtx loc_note
= *decl_piece_varloc_ptr (p
);
13386 dw_loc_descr_ref cur_descr
;
13387 dw_loc_descr_ref
*tail
, last
= NULL
;
13388 unsigned int opsize
= 0;
13390 if (loc_note
== NULL_RTX
13391 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
13393 padsize
+= bitsize
;
13396 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
13397 varloc
= NOTE_VAR_LOCATION (loc_note
);
13398 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
13399 if (cur_descr
== NULL
)
13401 padsize
+= bitsize
;
13405 /* Check that cur_descr either doesn't use
13406 DW_OP_*piece operations, or their sum is equal
13407 to bitsize. Otherwise we can't embed it. */
13408 for (tail
= &cur_descr
; *tail
!= NULL
;
13409 tail
= &(*tail
)->dw_loc_next
)
13410 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
13412 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
13416 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
13418 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
13422 if (last
!= NULL
&& opsize
!= bitsize
)
13424 padsize
+= bitsize
;
13428 /* If there is a hole, add DW_OP_*piece after empty DWARF
13429 expression, which means that those bits are optimized out. */
13432 if (padsize
> decl_size
)
13434 decl_size
-= padsize
;
13435 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
13436 if (*descr_tail
== NULL
)
13438 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13441 *descr_tail
= cur_descr
;
13443 if (bitsize
> decl_size
)
13445 decl_size
-= bitsize
;
13448 HOST_WIDE_INT offset
= 0;
13449 if (GET_CODE (varloc
) == VAR_LOCATION
13450 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13452 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13453 if (GET_CODE (varloc
) == EXPR_LIST
)
13454 varloc
= XEXP (varloc
, 0);
13458 if (GET_CODE (varloc
) == CONST
13459 || GET_CODE (varloc
) == SIGN_EXTEND
13460 || GET_CODE (varloc
) == ZERO_EXTEND
)
13461 varloc
= XEXP (varloc
, 0);
13462 else if (GET_CODE (varloc
) == SUBREG
)
13463 varloc
= SUBREG_REG (varloc
);
13468 /* DW_OP_bit_size offset should be zero for register
13469 or implicit location descriptions and empty location
13470 descriptions, but for memory addresses needs big endian
13472 if (MEM_P (varloc
))
13474 unsigned HOST_WIDE_INT memsize
13475 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13476 if (memsize
!= bitsize
)
13478 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13479 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13481 if (memsize
< bitsize
)
13483 if (BITS_BIG_ENDIAN
)
13484 offset
= memsize
- bitsize
;
13488 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13489 if (*descr_tail
== NULL
)
13491 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13495 /* If there were any non-empty expressions, add padding till the end of
13497 if (descr
!= NULL
&& decl_size
!= 0)
13499 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13500 if (*descr_tail
== NULL
)
13506 /* Return the dwarf representation of the location list LOC_LIST of
13507 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13510 static dw_loc_list_ref
13511 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13513 const char *endname
, *secname
;
13515 enum var_init_status initialized
;
13516 struct var_loc_node
*node
;
13517 dw_loc_descr_ref descr
;
13518 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13519 dw_loc_list_ref list
= NULL
;
13520 dw_loc_list_ref
*listp
= &list
;
13522 /* Now that we know what section we are using for a base,
13523 actually construct the list of locations.
13524 The first location information is what is passed to the
13525 function that creates the location list, and the remaining
13526 locations just get added on to that list.
13527 Note that we only know the start address for a location
13528 (IE location changes), so to build the range, we use
13529 the range [current location start, next location start].
13530 This means we have to special case the last node, and generate
13531 a range of [last location start, end of function label]. */
13533 secname
= secname_for_decl (decl
);
13535 for (node
= loc_list
->first
; node
; node
= node
->next
)
13536 if (GET_CODE (node
->loc
) == EXPR_LIST
13537 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13539 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13541 /* This requires DW_OP_{,bit_}piece, which is not usable
13542 inside DWARF expressions. */
13543 if (want_address
!= 2)
13545 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13551 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13552 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13553 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
13557 bool range_across_switch
= false;
13558 /* If section switch happens in between node->label
13559 and node->next->label (or end of function) and
13560 we can't emit it as a single entry list,
13561 emit two ranges, first one ending at the end
13562 of first partition and second one starting at the
13563 beginning of second partition. */
13564 if (node
== loc_list
->last_before_switch
13565 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
13566 && current_function_decl
)
13568 endname
= cfun
->fde
->dw_fde_end
;
13569 range_across_switch
= true;
13571 /* The variable has a location between NODE->LABEL and
13572 NODE->NEXT->LABEL. */
13573 else if (node
->next
)
13574 endname
= node
->next
->label
;
13575 /* If the variable has a location at the last label
13576 it keeps its location until the end of function. */
13577 else if (!current_function_decl
)
13578 endname
= text_end_label
;
13581 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13582 FUNC_LABEL_ID (cfun
));
13583 endname
= ggc_strdup (label_id
);
13586 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
13587 if (TREE_CODE (decl
) == PARM_DECL
13588 && node
== loc_list
->first
13589 && GET_CODE (node
->loc
) == NOTE
13590 && strcmp (node
->label
, endname
) == 0)
13591 (*listp
)->force
= true;
13592 listp
= &(*listp
)->dw_loc_next
;
13594 if (range_across_switch
)
13596 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13597 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13600 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13601 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13602 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
13605 gcc_assert (descr
);
13606 /* The variable has a location between NODE->LABEL and
13607 NODE->NEXT->LABEL. */
13609 endname
= node
->next
->label
;
13611 endname
= cfun
->fde
->dw_fde_second_end
;
13612 *listp
= new_loc_list (descr
,
13613 cfun
->fde
->dw_fde_second_begin
,
13615 listp
= &(*listp
)->dw_loc_next
;
13620 /* Try to avoid the overhead of a location list emitting a location
13621 expression instead, but only if we didn't have more than one
13622 location entry in the first place. If some entries were not
13623 representable, we don't want to pretend a single entry that was
13624 applies to the entire scope in which the variable is
13626 if (list
&& loc_list
->first
->next
)
13632 /* Return if the loc_list has only single element and thus can be represented
13633 as location description. */
13636 single_element_loc_list_p (dw_loc_list_ref list
)
13638 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
13639 return !list
->ll_symbol
;
13642 /* To each location in list LIST add loc descr REF. */
13645 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
13647 dw_loc_descr_ref copy
;
13648 add_loc_descr (&list
->expr
, ref
);
13649 list
= list
->dw_loc_next
;
13652 copy
= ggc_alloc_dw_loc_descr_node ();
13653 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
13654 add_loc_descr (&list
->expr
, copy
);
13655 while (copy
->dw_loc_next
)
13657 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
13658 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
13659 copy
->dw_loc_next
= new_copy
;
13662 list
= list
->dw_loc_next
;
13666 /* Given two lists RET and LIST
13667 produce location list that is result of adding expression in LIST
13668 to expression in RET on each position in program.
13669 Might be destructive on both RET and LIST.
13671 TODO: We handle only simple cases of RET or LIST having at most one
13672 element. General case would inolve sorting the lists in program order
13673 and merging them that will need some additional work.
13674 Adding that will improve quality of debug info especially for SRA-ed
13678 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
13687 if (!list
->dw_loc_next
)
13689 add_loc_descr_to_each (*ret
, list
->expr
);
13692 if (!(*ret
)->dw_loc_next
)
13694 add_loc_descr_to_each (list
, (*ret
)->expr
);
13698 expansion_failed (NULL_TREE
, NULL_RTX
,
13699 "Don't know how to merge two non-trivial"
13700 " location lists.\n");
13705 /* LOC is constant expression. Try a luck, look it up in constant
13706 pool and return its loc_descr of its address. */
13708 static dw_loc_descr_ref
13709 cst_pool_loc_descr (tree loc
)
13711 /* Get an RTL for this, if something has been emitted. */
13712 rtx rtl
= lookup_constant_def (loc
);
13714 if (!rtl
|| !MEM_P (rtl
))
13719 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
13721 /* TODO: We might get more coverage if we was actually delaying expansion
13722 of all expressions till end of compilation when constant pools are fully
13724 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
13726 expansion_failed (loc
, NULL_RTX
,
13727 "CST value in contant pool but not marked.");
13730 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13731 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
13734 /* Return dw_loc_list representing address of addr_expr LOC
13735 by looking for inner INDIRECT_REF expression and turning
13736 it into simple arithmetics. */
13738 static dw_loc_list_ref
13739 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
13742 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13743 enum machine_mode mode
;
13744 int unsignedp
, volatilep
= 0;
13745 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13747 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
13748 &bitsize
, &bitpos
, &offset
, &mode
,
13749 &unsignedp
, &volatilep
, false);
13751 if (bitpos
% BITS_PER_UNIT
)
13753 expansion_failed (loc
, NULL_RTX
, "bitfield access");
13756 if (!INDIRECT_REF_P (obj
))
13758 expansion_failed (obj
,
13759 NULL_RTX
, "no indirect ref in inner refrence");
13762 if (!offset
&& !bitpos
)
13763 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
13765 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
13766 && (dwarf_version
>= 4 || !dwarf_strict
))
13768 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
13773 /* Variable offset. */
13774 list_ret1
= loc_list_from_tree (offset
, 0);
13775 if (list_ret1
== 0)
13777 add_loc_list (&list_ret
, list_ret1
);
13780 add_loc_descr_to_each (list_ret
,
13781 new_loc_descr (DW_OP_plus
, 0, 0));
13783 bytepos
= bitpos
/ BITS_PER_UNIT
;
13785 add_loc_descr_to_each (list_ret
,
13786 new_loc_descr (DW_OP_plus_uconst
,
13788 else if (bytepos
< 0)
13789 loc_list_plus_const (list_ret
, bytepos
);
13790 add_loc_descr_to_each (list_ret
,
13791 new_loc_descr (DW_OP_stack_value
, 0, 0));
13797 /* Generate Dwarf location list representing LOC.
13798 If WANT_ADDRESS is false, expression computing LOC will be computed
13799 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13800 if WANT_ADDRESS is 2, expression computing address useable in location
13801 will be returned (i.e. DW_OP_reg can be used
13802 to refer to register values). */
13804 static dw_loc_list_ref
13805 loc_list_from_tree (tree loc
, int want_address
)
13807 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
13808 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13809 int have_address
= 0;
13810 enum dwarf_location_atom op
;
13812 /* ??? Most of the time we do not take proper care for sign/zero
13813 extending the values properly. Hopefully this won't be a real
13816 switch (TREE_CODE (loc
))
13819 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
13822 case PLACEHOLDER_EXPR
:
13823 /* This case involves extracting fields from an object to determine the
13824 position of other fields. We don't try to encode this here. The
13825 only user of this is Ada, which encodes the needed information using
13826 the names of types. */
13827 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
13831 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
13832 /* There are no opcodes for these operations. */
13835 case PREINCREMENT_EXPR
:
13836 case PREDECREMENT_EXPR
:
13837 case POSTINCREMENT_EXPR
:
13838 case POSTDECREMENT_EXPR
:
13839 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
13840 /* There are no opcodes for these operations. */
13844 /* If we already want an address, see if there is INDIRECT_REF inside
13845 e.g. for &this->field. */
13848 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
13849 (loc
, want_address
== 2);
13852 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
13853 && (ret
= cst_pool_loc_descr (loc
)))
13856 /* Otherwise, process the argument and look for the address. */
13857 if (!list_ret
&& !ret
)
13858 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
13862 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
13868 if (DECL_THREAD_LOCAL_P (loc
))
13871 enum dwarf_location_atom tls_op
;
13872 enum dtprel_bool dtprel
= dtprel_false
;
13874 if (targetm
.have_tls
)
13876 /* If this is not defined, we have no way to emit the
13878 if (!targetm
.asm_out
.output_dwarf_dtprel
)
13881 /* The way DW_OP_GNU_push_tls_address is specified, we
13882 can only look up addresses of objects in the current
13883 module. We used DW_OP_addr as first op, but that's
13884 wrong, because DW_OP_addr is relocated by the debug
13885 info consumer, while DW_OP_GNU_push_tls_address
13886 operand shouldn't be. */
13887 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
13889 dtprel
= dtprel_true
;
13890 tls_op
= DW_OP_GNU_push_tls_address
;
13894 if (!targetm
.emutls
.debug_form_tls_address
13895 || !(dwarf_version
>= 3 || !dwarf_strict
))
13897 /* We stuffed the control variable into the DECL_VALUE_EXPR
13898 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13899 no longer appear in gimple code. We used the control
13900 variable in specific so that we could pick it up here. */
13901 loc
= DECL_VALUE_EXPR (loc
);
13902 tls_op
= DW_OP_form_tls_address
;
13905 rtl
= rtl_for_decl_location (loc
);
13906 if (rtl
== NULL_RTX
)
13911 rtl
= XEXP (rtl
, 0);
13912 if (! CONSTANT_P (rtl
))
13915 ret
= new_addr_loc_descr (rtl
, dtprel
);
13916 ret1
= new_loc_descr (tls_op
, 0, 0);
13917 add_loc_descr (&ret
, ret1
);
13926 if (DECL_HAS_VALUE_EXPR_P (loc
))
13927 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
13931 case FUNCTION_DECL
:
13934 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
13936 if (loc_list
&& loc_list
->first
)
13938 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
13939 have_address
= want_address
!= 0;
13942 rtl
= rtl_for_decl_location (loc
);
13943 if (rtl
== NULL_RTX
)
13945 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
13948 else if (CONST_INT_P (rtl
))
13950 HOST_WIDE_INT val
= INTVAL (rtl
);
13951 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13952 val
&= GET_MODE_MASK (DECL_MODE (loc
));
13953 ret
= int_loc_descriptor (val
);
13955 else if (GET_CODE (rtl
) == CONST_STRING
)
13957 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
13960 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
13961 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
13964 enum machine_mode mode
, mem_mode
;
13966 /* Certain constructs can only be represented at top-level. */
13967 if (want_address
== 2)
13969 ret
= loc_descriptor (rtl
, VOIDmode
,
13970 VAR_INIT_STATUS_INITIALIZED
);
13975 mode
= GET_MODE (rtl
);
13976 mem_mode
= VOIDmode
;
13980 mode
= get_address_mode (rtl
);
13981 rtl
= XEXP (rtl
, 0);
13984 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
13985 VAR_INIT_STATUS_INITIALIZED
);
13988 expansion_failed (loc
, rtl
,
13989 "failed to produce loc descriptor for rtl");
13996 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
14000 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14004 case COMPOUND_EXPR
:
14005 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
14008 case VIEW_CONVERT_EXPR
:
14011 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
14013 case COMPONENT_REF
:
14014 case BIT_FIELD_REF
:
14016 case ARRAY_RANGE_REF
:
14017 case REALPART_EXPR
:
14018 case IMAGPART_EXPR
:
14021 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14022 enum machine_mode mode
;
14023 int unsignedp
, volatilep
= 0;
14025 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
14026 &unsignedp
, &volatilep
, false);
14028 gcc_assert (obj
!= loc
);
14030 list_ret
= loc_list_from_tree (obj
,
14032 && !bitpos
&& !offset
? 2 : 1);
14033 /* TODO: We can extract value of the small expression via shifting even
14034 for nonzero bitpos. */
14037 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
14039 expansion_failed (loc
, NULL_RTX
,
14040 "bitfield access");
14044 if (offset
!= NULL_TREE
)
14046 /* Variable offset. */
14047 list_ret1
= loc_list_from_tree (offset
, 0);
14048 if (list_ret1
== 0)
14050 add_loc_list (&list_ret
, list_ret1
);
14053 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14056 bytepos
= bitpos
/ BITS_PER_UNIT
;
14058 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
14059 else if (bytepos
< 0)
14060 loc_list_plus_const (list_ret
, bytepos
);
14067 if ((want_address
|| !host_integerp (loc
, 0))
14068 && (ret
= cst_pool_loc_descr (loc
)))
14070 else if (want_address
== 2
14071 && host_integerp (loc
, 0)
14072 && (ret
= address_of_int_loc_descriptor
14073 (int_size_in_bytes (TREE_TYPE (loc
)),
14074 tree_low_cst (loc
, 0))))
14076 else if (host_integerp (loc
, 0))
14077 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
14080 expansion_failed (loc
, NULL_RTX
,
14081 "Integer operand is not host integer");
14090 if ((ret
= cst_pool_loc_descr (loc
)))
14093 /* We can construct small constants here using int_loc_descriptor. */
14094 expansion_failed (loc
, NULL_RTX
,
14095 "constructor or constant not in constant pool");
14098 case TRUTH_AND_EXPR
:
14099 case TRUTH_ANDIF_EXPR
:
14104 case TRUTH_XOR_EXPR
:
14109 case TRUTH_OR_EXPR
:
14110 case TRUTH_ORIF_EXPR
:
14115 case FLOOR_DIV_EXPR
:
14116 case CEIL_DIV_EXPR
:
14117 case ROUND_DIV_EXPR
:
14118 case TRUNC_DIV_EXPR
:
14119 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14128 case FLOOR_MOD_EXPR
:
14129 case CEIL_MOD_EXPR
:
14130 case ROUND_MOD_EXPR
:
14131 case TRUNC_MOD_EXPR
:
14132 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14137 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14138 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14139 if (list_ret
== 0 || list_ret1
== 0)
14142 add_loc_list (&list_ret
, list_ret1
);
14145 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14146 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14147 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14148 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14149 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14161 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14164 case POINTER_PLUS_EXPR
:
14166 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
14168 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14172 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
14180 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14187 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14194 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14201 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14216 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14217 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14218 if (list_ret
== 0 || list_ret1
== 0)
14221 add_loc_list (&list_ret
, list_ret1
);
14224 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14227 case TRUTH_NOT_EXPR
:
14241 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14245 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14251 const enum tree_code code
=
14252 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14254 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14255 build2 (code
, integer_type_node
,
14256 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14257 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14260 /* ... fall through ... */
14264 dw_loc_descr_ref lhs
14265 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
14266 dw_loc_list_ref rhs
14267 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
14268 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
14270 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14271 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
14274 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14275 add_loc_descr_to_each (list_ret
, bra_node
);
14277 add_loc_list (&list_ret
, rhs
);
14278 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14279 add_loc_descr_to_each (list_ret
, jump_node
);
14281 add_loc_descr_to_each (list_ret
, lhs
);
14282 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14283 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
14285 /* ??? Need a node to point the skip at. Use a nop. */
14286 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14287 add_loc_descr_to_each (list_ret
, tmp
);
14288 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14289 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14293 case FIX_TRUNC_EXPR
:
14297 /* Leave front-end specific codes as simply unknown. This comes
14298 up, for instance, with the C STMT_EXPR. */
14299 if ((unsigned int) TREE_CODE (loc
)
14300 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
14302 expansion_failed (loc
, NULL_RTX
,
14303 "language specific tree node");
14307 #ifdef ENABLE_CHECKING
14308 /* Otherwise this is a generic code; we should just lists all of
14309 these explicitly. We forgot one. */
14310 gcc_unreachable ();
14312 /* In a release build, we want to degrade gracefully: better to
14313 generate incomplete debugging information than to crash. */
14318 if (!ret
&& !list_ret
)
14321 if (want_address
== 2 && !have_address
14322 && (dwarf_version
>= 4 || !dwarf_strict
))
14324 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14326 expansion_failed (loc
, NULL_RTX
,
14327 "DWARF address size mismatch");
14331 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14333 add_loc_descr_to_each (list_ret
,
14334 new_loc_descr (DW_OP_stack_value
, 0, 0));
14337 /* Show if we can't fill the request for an address. */
14338 if (want_address
&& !have_address
)
14340 expansion_failed (loc
, NULL_RTX
,
14341 "Want address and only have value");
14345 gcc_assert (!ret
|| !list_ret
);
14347 /* If we've got an address and don't want one, dereference. */
14348 if (!want_address
&& have_address
)
14350 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14352 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14354 expansion_failed (loc
, NULL_RTX
,
14355 "DWARF address size mismatch");
14358 else if (size
== DWARF2_ADDR_SIZE
)
14361 op
= DW_OP_deref_size
;
14364 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
14366 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
14369 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
14374 /* Same as above but return only single location expression. */
14375 static dw_loc_descr_ref
14376 loc_descriptor_from_tree (tree loc
, int want_address
)
14378 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
14381 if (ret
->dw_loc_next
)
14383 expansion_failed (loc
, NULL_RTX
,
14384 "Location list where only loc descriptor needed");
14390 /* Given a value, round it up to the lowest multiple of `boundary'
14391 which is not less than the value itself. */
14393 static inline HOST_WIDE_INT
14394 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
14396 return (((value
+ boundary
- 1) / boundary
) * boundary
);
14399 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14400 pointer to the declared type for the relevant field variable, or return
14401 `integer_type_node' if the given node turns out to be an
14402 ERROR_MARK node. */
14405 field_type (const_tree decl
)
14409 if (TREE_CODE (decl
) == ERROR_MARK
)
14410 return integer_type_node
;
14412 type
= DECL_BIT_FIELD_TYPE (decl
);
14413 if (type
== NULL_TREE
)
14414 type
= TREE_TYPE (decl
);
14419 /* Given a pointer to a tree node, return the alignment in bits for
14420 it, or else return BITS_PER_WORD if the node actually turns out to
14421 be an ERROR_MARK node. */
14423 static inline unsigned
14424 simple_type_align_in_bits (const_tree type
)
14426 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
14429 static inline unsigned
14430 simple_decl_align_in_bits (const_tree decl
)
14432 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
14435 /* Return the result of rounding T up to ALIGN. */
14437 static inline double_int
14438 round_up_to_align (double_int t
, unsigned int align
)
14440 double_int alignd
= double_int::from_uhwi (align
);
14442 t
+= double_int_minus_one
;
14443 t
= t
.div (alignd
, true, TRUNC_DIV_EXPR
);
14448 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14449 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14450 or return 0 if we are unable to determine what that offset is, either
14451 because the argument turns out to be a pointer to an ERROR_MARK node, or
14452 because the offset is actually variable. (We can't handle the latter case
14455 static HOST_WIDE_INT
14456 field_byte_offset (const_tree decl
)
14458 double_int object_offset_in_bits
;
14459 double_int object_offset_in_bytes
;
14460 double_int bitpos_int
;
14462 if (TREE_CODE (decl
) == ERROR_MARK
)
14465 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14467 /* We cannot yet cope with fields whose positions are variable, so
14468 for now, when we see such things, we simply return 0. Someday, we may
14469 be able to handle such cases, but it will be damn difficult. */
14470 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14473 bitpos_int
= tree_to_double_int (bit_position (decl
));
14475 #ifdef PCC_BITFIELD_TYPE_MATTERS
14476 if (PCC_BITFIELD_TYPE_MATTERS
)
14479 tree field_size_tree
;
14480 double_int deepest_bitpos
;
14481 double_int field_size_in_bits
;
14482 unsigned int type_align_in_bits
;
14483 unsigned int decl_align_in_bits
;
14484 double_int type_size_in_bits
;
14486 type
= field_type (decl
);
14487 type_size_in_bits
= double_int_type_size_in_bits (type
);
14488 type_align_in_bits
= simple_type_align_in_bits (type
);
14490 field_size_tree
= DECL_SIZE (decl
);
14492 /* The size could be unspecified if there was an error, or for
14493 a flexible array member. */
14494 if (!field_size_tree
)
14495 field_size_tree
= bitsize_zero_node
;
14497 /* If the size of the field is not constant, use the type size. */
14498 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14499 field_size_in_bits
= tree_to_double_int (field_size_tree
);
14501 field_size_in_bits
= type_size_in_bits
;
14503 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14505 /* The GCC front-end doesn't make any attempt to keep track of the
14506 starting bit offset (relative to the start of the containing
14507 structure type) of the hypothetical "containing object" for a
14508 bit-field. Thus, when computing the byte offset value for the
14509 start of the "containing object" of a bit-field, we must deduce
14510 this information on our own. This can be rather tricky to do in
14511 some cases. For example, handling the following structure type
14512 definition when compiling for an i386/i486 target (which only
14513 aligns long long's to 32-bit boundaries) can be very tricky:
14515 struct S { int field1; long long field2:31; };
14517 Fortunately, there is a simple rule-of-thumb which can be used
14518 in such cases. When compiling for an i386/i486, GCC will
14519 allocate 8 bytes for the structure shown above. It decides to
14520 do this based upon one simple rule for bit-field allocation.
14521 GCC allocates each "containing object" for each bit-field at
14522 the first (i.e. lowest addressed) legitimate alignment boundary
14523 (based upon the required minimum alignment for the declared
14524 type of the field) which it can possibly use, subject to the
14525 condition that there is still enough available space remaining
14526 in the containing object (when allocated at the selected point)
14527 to fully accommodate all of the bits of the bit-field itself.
14529 This simple rule makes it obvious why GCC allocates 8 bytes for
14530 each object of the structure type shown above. When looking
14531 for a place to allocate the "containing object" for `field2',
14532 the compiler simply tries to allocate a 64-bit "containing
14533 object" at each successive 32-bit boundary (starting at zero)
14534 until it finds a place to allocate that 64- bit field such that
14535 at least 31 contiguous (and previously unallocated) bits remain
14536 within that selected 64 bit field. (As it turns out, for the
14537 example above, the compiler finds it is OK to allocate the
14538 "containing object" 64-bit field at bit-offset zero within the
14541 Here we attempt to work backwards from the limited set of facts
14542 we're given, and we try to deduce from those facts, where GCC
14543 must have believed that the containing object started (within
14544 the structure type). The value we deduce is then used (by the
14545 callers of this routine) to generate DW_AT_location and
14546 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14547 the case of DW_AT_location, regular fields as well). */
14549 /* Figure out the bit-distance from the start of the structure to
14550 the "deepest" bit of the bit-field. */
14551 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
14553 /* This is the tricky part. Use some fancy footwork to deduce
14554 where the lowest addressed bit of the containing object must
14556 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14558 /* Round up to type_align by default. This works best for
14560 object_offset_in_bits
14561 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
14563 if (object_offset_in_bits
.ugt (bitpos_int
))
14565 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14567 /* Round up to decl_align instead. */
14568 object_offset_in_bits
14569 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
14573 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14574 object_offset_in_bits
= bitpos_int
;
14576 object_offset_in_bytes
14577 = object_offset_in_bits
.div (double_int::from_uhwi (BITS_PER_UNIT
),
14578 true, TRUNC_DIV_EXPR
);
14579 return object_offset_in_bytes
.to_shwi ();
14582 /* The following routines define various Dwarf attributes and any data
14583 associated with them. */
14585 /* Add a location description attribute value to a DIE.
14587 This emits location attributes suitable for whole variables and
14588 whole parameters. Note that the location attributes for struct fields are
14589 generated by the routine `data_member_location_attribute' below. */
14592 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
14593 dw_loc_list_ref descr
)
14597 if (single_element_loc_list_p (descr
))
14598 add_AT_loc (die
, attr_kind
, descr
->expr
);
14600 add_AT_loc_list (die
, attr_kind
, descr
);
14603 /* Add DW_AT_accessibility attribute to DIE if needed. */
14606 add_accessibility_attribute (dw_die_ref die
, tree decl
)
14608 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14609 children, otherwise the default is DW_ACCESS_public. In DWARF2
14610 the default has always been DW_ACCESS_public. */
14611 if (TREE_PROTECTED (decl
))
14612 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14613 else if (TREE_PRIVATE (decl
))
14615 if (dwarf_version
== 2
14616 || die
->die_parent
== NULL
14617 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
14618 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
14620 else if (dwarf_version
> 2
14622 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
14623 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14626 /* Attach the specialized form of location attribute used for data members of
14627 struct and union types. In the special case of a FIELD_DECL node which
14628 represents a bit-field, the "offset" part of this special location
14629 descriptor must indicate the distance in bytes from the lowest-addressed
14630 byte of the containing struct or union type to the lowest-addressed byte of
14631 the "containing object" for the bit-field. (See the `field_byte_offset'
14634 For any given bit-field, the "containing object" is a hypothetical object
14635 (of some integral or enum type) within which the given bit-field lives. The
14636 type of this hypothetical "containing object" is always the same as the
14637 declared type of the individual bit-field itself (for GCC anyway... the
14638 DWARF spec doesn't actually mandate this). Note that it is the size (in
14639 bytes) of the hypothetical "containing object" which will be given in the
14640 DW_AT_byte_size attribute for this bit-field. (See the
14641 `byte_size_attribute' function below.) It is also used when calculating the
14642 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14643 function below.) */
14646 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
14648 HOST_WIDE_INT offset
;
14649 dw_loc_descr_ref loc_descr
= 0;
14651 if (TREE_CODE (decl
) == TREE_BINFO
)
14653 /* We're working on the TAG_inheritance for a base class. */
14654 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
14656 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14657 aren't at a fixed offset from all (sub)objects of the same
14658 type. We need to extract the appropriate offset from our
14659 vtable. The following dwarf expression means
14661 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14663 This is specific to the V3 ABI, of course. */
14665 dw_loc_descr_ref tmp
;
14667 /* Make a copy of the object address. */
14668 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
14669 add_loc_descr (&loc_descr
, tmp
);
14671 /* Extract the vtable address. */
14672 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14673 add_loc_descr (&loc_descr
, tmp
);
14675 /* Calculate the address of the offset. */
14676 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
14677 gcc_assert (offset
< 0);
14679 tmp
= int_loc_descriptor (-offset
);
14680 add_loc_descr (&loc_descr
, tmp
);
14681 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
14682 add_loc_descr (&loc_descr
, tmp
);
14684 /* Extract the offset. */
14685 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14686 add_loc_descr (&loc_descr
, tmp
);
14688 /* Add it to the object address. */
14689 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
14690 add_loc_descr (&loc_descr
, tmp
);
14693 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
14696 offset
= field_byte_offset (decl
);
14700 if (dwarf_version
> 2)
14702 /* Don't need to output a location expression, just the constant. */
14704 add_AT_int (die
, DW_AT_data_member_location
, offset
);
14706 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
14711 enum dwarf_location_atom op
;
14713 /* The DWARF2 standard says that we should assume that the structure
14714 address is already on the stack, so we can specify a structure
14715 field address by using DW_OP_plus_uconst. */
14716 op
= DW_OP_plus_uconst
;
14717 loc_descr
= new_loc_descr (op
, offset
, 0);
14721 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
14724 /* Writes integer values to dw_vec_const array. */
14727 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
14731 *dest
++ = val
& 0xff;
14737 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14739 static HOST_WIDE_INT
14740 extract_int (const unsigned char *src
, unsigned int size
)
14742 HOST_WIDE_INT val
= 0;
14748 val
|= *--src
& 0xff;
14754 /* Writes double_int values to dw_vec_const array. */
14757 insert_double (double_int val
, unsigned char *dest
)
14759 unsigned char *p0
= dest
;
14760 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
14762 if (WORDS_BIG_ENDIAN
)
14768 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
14769 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
14772 /* Writes floating point values to dw_vec_const array. */
14775 insert_float (const_rtx rtl
, unsigned char *array
)
14777 REAL_VALUE_TYPE rv
;
14781 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
14782 real_to_target (val
, &rv
, GET_MODE (rtl
));
14784 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14785 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
14787 insert_int (val
[i
], 4, array
);
14792 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14793 does not have a "location" either in memory or in a register. These
14794 things can arise in GNU C when a constant is passed as an actual parameter
14795 to an inlined function. They can also arise in C++ where declared
14796 constants do not necessarily get memory "homes". */
14799 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
14801 switch (GET_CODE (rtl
))
14805 HOST_WIDE_INT val
= INTVAL (rtl
);
14808 add_AT_int (die
, DW_AT_const_value
, val
);
14810 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
14815 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14816 floating-point constant. A CONST_DOUBLE is used whenever the
14817 constant requires more than one word in order to be adequately
14820 enum machine_mode mode
= GET_MODE (rtl
);
14822 if (SCALAR_FLOAT_MODE_P (mode
))
14824 unsigned int length
= GET_MODE_SIZE (mode
);
14825 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
14827 insert_float (rtl
, array
);
14828 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
14831 add_AT_double (die
, DW_AT_const_value
,
14832 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
14838 enum machine_mode mode
= GET_MODE (rtl
);
14839 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
14840 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
14841 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
14842 (length
* elt_size
);
14846 switch (GET_MODE_CLASS (mode
))
14848 case MODE_VECTOR_INT
:
14849 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14851 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14852 double_int val
= rtx_to_double_int (elt
);
14854 if (elt_size
<= sizeof (HOST_WIDE_INT
))
14855 insert_int (val
.to_shwi (), elt_size
, p
);
14858 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
14859 insert_double (val
, p
);
14864 case MODE_VECTOR_FLOAT
:
14865 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14867 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14868 insert_float (elt
, p
);
14873 gcc_unreachable ();
14876 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
14881 if (dwarf_version
>= 4 || !dwarf_strict
)
14883 dw_loc_descr_ref loc_result
;
14884 resolve_one_addr (&rtl
, NULL
);
14886 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
14887 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14888 add_AT_loc (die
, DW_AT_location
, loc_result
);
14889 vec_safe_push (used_rtx_array
, rtl
);
14895 if (CONSTANT_P (XEXP (rtl
, 0)))
14896 return add_const_value_attribute (die
, XEXP (rtl
, 0));
14899 if (!const_ok_for_output (rtl
))
14902 if (dwarf_version
>= 4 || !dwarf_strict
)
14907 /* In cases where an inlined instance of an inline function is passed
14908 the address of an `auto' variable (which is local to the caller) we
14909 can get a situation where the DECL_RTL of the artificial local
14910 variable (for the inlining) which acts as a stand-in for the
14911 corresponding formal parameter (of the inline function) will look
14912 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14913 exactly a compile-time constant expression, but it isn't the address
14914 of the (artificial) local variable either. Rather, it represents the
14915 *value* which the artificial local variable always has during its
14916 lifetime. We currently have no way to represent such quasi-constant
14917 values in Dwarf, so for now we just punt and generate nothing. */
14925 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
14926 && MEM_READONLY_P (rtl
)
14927 && GET_MODE (rtl
) == BLKmode
)
14929 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
14935 /* No other kinds of rtx should be possible here. */
14936 gcc_unreachable ();
14941 /* Determine whether the evaluation of EXPR references any variables
14942 or functions which aren't otherwise used (and therefore may not be
14945 reference_to_unused (tree
* tp
, int * walk_subtrees
,
14946 void * data ATTRIBUTE_UNUSED
)
14948 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
14949 *walk_subtrees
= 0;
14951 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
14952 && ! TREE_ASM_WRITTEN (*tp
))
14954 /* ??? The C++ FE emits debug information for using decls, so
14955 putting gcc_unreachable here falls over. See PR31899. For now
14956 be conservative. */
14957 else if (!cgraph_global_info_ready
14958 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
14960 else if (TREE_CODE (*tp
) == VAR_DECL
)
14962 struct varpool_node
*node
= varpool_get_node (*tp
);
14963 if (!node
|| !node
->analyzed
)
14966 else if (TREE_CODE (*tp
) == FUNCTION_DECL
14967 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
14969 /* The call graph machinery must have finished analyzing,
14970 optimizing and gimplifying the CU by now.
14971 So if *TP has no call graph node associated
14972 to it, it means *TP will not be emitted. */
14973 if (!cgraph_get_node (*tp
))
14976 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
14982 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
14983 for use in a later add_const_value_attribute call. */
14986 rtl_for_decl_init (tree init
, tree type
)
14988 rtx rtl
= NULL_RTX
;
14992 /* If a variable is initialized with a string constant without embedded
14993 zeros, build CONST_STRING. */
14994 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
14996 tree enttype
= TREE_TYPE (type
);
14997 tree domain
= TYPE_DOMAIN (type
);
14998 enum machine_mode mode
= TYPE_MODE (enttype
);
15000 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
15002 && integer_zerop (TYPE_MIN_VALUE (domain
))
15003 && compare_tree_int (TYPE_MAX_VALUE (domain
),
15004 TREE_STRING_LENGTH (init
) - 1) == 0
15005 && ((size_t) TREE_STRING_LENGTH (init
)
15006 == strlen (TREE_STRING_POINTER (init
)) + 1))
15008 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
15009 ggc_strdup (TREE_STRING_POINTER (init
)));
15010 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
15011 MEM_READONLY_P (rtl
) = 1;
15014 /* Other aggregates, and complex values, could be represented using
15016 else if (AGGREGATE_TYPE_P (type
)
15017 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
15018 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
15019 || TREE_CODE (type
) == COMPLEX_TYPE
)
15021 /* Vectors only work if their mode is supported by the target.
15022 FIXME: generic vectors ought to work too. */
15023 else if (TREE_CODE (type
) == VECTOR_TYPE
15024 && !VECTOR_MODE_P (TYPE_MODE (type
)))
15026 /* If the initializer is something that we know will expand into an
15027 immediate RTL constant, expand it now. We must be careful not to
15028 reference variables which won't be output. */
15029 else if (initializer_constant_valid_p (init
, type
)
15030 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
15032 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
15034 if (TREE_CODE (type
) == VECTOR_TYPE
)
15035 switch (TREE_CODE (init
))
15040 if (TREE_CONSTANT (init
))
15042 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
15043 bool constant_p
= true;
15045 unsigned HOST_WIDE_INT ix
;
15047 /* Even when ctor is constant, it might contain non-*_CST
15048 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15049 belong into VECTOR_CST nodes. */
15050 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
15051 if (!CONSTANT_CLASS_P (value
))
15053 constant_p
= false;
15059 init
= build_vector_from_ctor (type
, elts
);
15069 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
15071 /* If expand_expr returns a MEM, it wasn't immediate. */
15072 gcc_assert (!rtl
|| !MEM_P (rtl
));
15078 /* Generate RTL for the variable DECL to represent its location. */
15081 rtl_for_decl_location (tree decl
)
15085 /* Here we have to decide where we are going to say the parameter "lives"
15086 (as far as the debugger is concerned). We only have a couple of
15087 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15089 DECL_RTL normally indicates where the parameter lives during most of the
15090 activation of the function. If optimization is enabled however, this
15091 could be either NULL or else a pseudo-reg. Both of those cases indicate
15092 that the parameter doesn't really live anywhere (as far as the code
15093 generation parts of GCC are concerned) during most of the function's
15094 activation. That will happen (for example) if the parameter is never
15095 referenced within the function.
15097 We could just generate a location descriptor here for all non-NULL
15098 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15099 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15100 where DECL_RTL is NULL or is a pseudo-reg.
15102 Note however that we can only get away with using DECL_INCOMING_RTL as
15103 a backup substitute for DECL_RTL in certain limited cases. In cases
15104 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15105 we can be sure that the parameter was passed using the same type as it is
15106 declared to have within the function, and that its DECL_INCOMING_RTL
15107 points us to a place where a value of that type is passed.
15109 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15110 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15111 because in these cases DECL_INCOMING_RTL points us to a value of some
15112 type which is *different* from the type of the parameter itself. Thus,
15113 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15114 such cases, the debugger would end up (for example) trying to fetch a
15115 `float' from a place which actually contains the first part of a
15116 `double'. That would lead to really incorrect and confusing
15117 output at debug-time.
15119 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15120 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15121 are a couple of exceptions however. On little-endian machines we can
15122 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15123 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15124 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15125 when (on a little-endian machine) a non-prototyped function has a
15126 parameter declared to be of type `short' or `char'. In such cases,
15127 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15128 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15129 passed `int' value. If the debugger then uses that address to fetch
15130 a `short' or a `char' (on a little-endian machine) the result will be
15131 the correct data, so we allow for such exceptional cases below.
15133 Note that our goal here is to describe the place where the given formal
15134 parameter lives during most of the function's activation (i.e. between the
15135 end of the prologue and the start of the epilogue). We'll do that as best
15136 as we can. Note however that if the given formal parameter is modified
15137 sometime during the execution of the function, then a stack backtrace (at
15138 debug-time) will show the function as having been called with the *new*
15139 value rather than the value which was originally passed in. This happens
15140 rarely enough that it is not a major problem, but it *is* a problem, and
15141 I'd like to fix it.
15143 A future version of dwarf2out.c may generate two additional attributes for
15144 any given DW_TAG_formal_parameter DIE which will describe the "passed
15145 type" and the "passed location" for the given formal parameter in addition
15146 to the attributes we now generate to indicate the "declared type" and the
15147 "active location" for each parameter. This additional set of attributes
15148 could be used by debuggers for stack backtraces. Separately, note that
15149 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15150 This happens (for example) for inlined-instances of inline function formal
15151 parameters which are never referenced. This really shouldn't be
15152 happening. All PARM_DECL nodes should get valid non-NULL
15153 DECL_INCOMING_RTL values. FIXME. */
15155 /* Use DECL_RTL as the "location" unless we find something better. */
15156 rtl
= DECL_RTL_IF_SET (decl
);
15158 /* When generating abstract instances, ignore everything except
15159 constants, symbols living in memory, and symbols living in
15160 fixed registers. */
15161 if (! reload_completed
)
15164 && (CONSTANT_P (rtl
)
15166 && CONSTANT_P (XEXP (rtl
, 0)))
15168 && TREE_CODE (decl
) == VAR_DECL
15169 && TREE_STATIC (decl
))))
15171 rtl
= targetm
.delegitimize_address (rtl
);
15176 else if (TREE_CODE (decl
) == PARM_DECL
)
15178 if (rtl
== NULL_RTX
15179 || is_pseudo_reg (rtl
)
15181 && is_pseudo_reg (XEXP (rtl
, 0))
15182 && DECL_INCOMING_RTL (decl
)
15183 && MEM_P (DECL_INCOMING_RTL (decl
))
15184 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15186 tree declared_type
= TREE_TYPE (decl
);
15187 tree passed_type
= DECL_ARG_TYPE (decl
);
15188 enum machine_mode dmode
= TYPE_MODE (declared_type
);
15189 enum machine_mode pmode
= TYPE_MODE (passed_type
);
15191 /* This decl represents a formal parameter which was optimized out.
15192 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15193 all cases where (rtl == NULL_RTX) just below. */
15194 if (dmode
== pmode
)
15195 rtl
= DECL_INCOMING_RTL (decl
);
15196 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15197 && SCALAR_INT_MODE_P (dmode
)
15198 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15199 && DECL_INCOMING_RTL (decl
))
15201 rtx inc
= DECL_INCOMING_RTL (decl
);
15204 else if (MEM_P (inc
))
15206 if (BYTES_BIG_ENDIAN
)
15207 rtl
= adjust_address_nv (inc
, dmode
,
15208 GET_MODE_SIZE (pmode
)
15209 - GET_MODE_SIZE (dmode
));
15216 /* If the parm was passed in registers, but lives on the stack, then
15217 make a big endian correction if the mode of the type of the
15218 parameter is not the same as the mode of the rtl. */
15219 /* ??? This is the same series of checks that are made in dbxout.c before
15220 we reach the big endian correction code there. It isn't clear if all
15221 of these checks are necessary here, but keeping them all is the safe
15223 else if (MEM_P (rtl
)
15224 && XEXP (rtl
, 0) != const0_rtx
15225 && ! CONSTANT_P (XEXP (rtl
, 0))
15226 /* Not passed in memory. */
15227 && !MEM_P (DECL_INCOMING_RTL (decl
))
15228 /* Not passed by invisible reference. */
15229 && (!REG_P (XEXP (rtl
, 0))
15230 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15231 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15232 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15233 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15236 /* Big endian correction check. */
15237 && BYTES_BIG_ENDIAN
15238 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15239 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15242 enum machine_mode addr_mode
= get_address_mode (rtl
);
15243 int offset
= (UNITS_PER_WORD
15244 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15246 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15247 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15250 else if (TREE_CODE (decl
) == VAR_DECL
15253 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15254 && BYTES_BIG_ENDIAN
)
15256 enum machine_mode addr_mode
= get_address_mode (rtl
);
15257 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
15258 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
15260 /* If a variable is declared "register" yet is smaller than
15261 a register, then if we store the variable to memory, it
15262 looks like we're storing a register-sized value, when in
15263 fact we are not. We need to adjust the offset of the
15264 storage location to reflect the actual value's bytes,
15265 else gdb will not be able to display it. */
15267 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15268 plus_constant (addr_mode
, XEXP (rtl
, 0),
15272 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15273 and will have been substituted directly into all expressions that use it.
15274 C does not have such a concept, but C++ and other languages do. */
15275 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
15276 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
15279 rtl
= targetm
.delegitimize_address (rtl
);
15281 /* If we don't look past the constant pool, we risk emitting a
15282 reference to a constant pool entry that isn't referenced from
15283 code, and thus is not emitted. */
15285 rtl
= avoid_constant_pool_reference (rtl
);
15287 /* Try harder to get a rtl. If this symbol ends up not being emitted
15288 in the current CU, resolve_addr will remove the expression referencing
15290 if (rtl
== NULL_RTX
15291 && TREE_CODE (decl
) == VAR_DECL
15292 && !DECL_EXTERNAL (decl
)
15293 && TREE_STATIC (decl
)
15294 && DECL_NAME (decl
)
15295 && !DECL_HARD_REGISTER (decl
)
15296 && DECL_MODE (decl
) != VOIDmode
)
15298 rtl
= make_decl_rtl_for_debug (decl
);
15300 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
15301 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
15308 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15309 returned. If so, the decl for the COMMON block is returned, and the
15310 value is the offset into the common block for the symbol. */
15313 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
15315 tree val_expr
, cvar
;
15316 enum machine_mode mode
;
15317 HOST_WIDE_INT bitsize
, bitpos
;
15319 int unsignedp
, volatilep
= 0;
15321 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15322 it does not have a value (the offset into the common area), or if it
15323 is thread local (as opposed to global) then it isn't common, and shouldn't
15324 be handled as such. */
15325 if (TREE_CODE (decl
) != VAR_DECL
15326 || !TREE_STATIC (decl
)
15327 || !DECL_HAS_VALUE_EXPR_P (decl
)
15331 val_expr
= DECL_VALUE_EXPR (decl
);
15332 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
15335 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
15336 &mode
, &unsignedp
, &volatilep
, true);
15338 if (cvar
== NULL_TREE
15339 || TREE_CODE (cvar
) != VAR_DECL
15340 || DECL_ARTIFICIAL (cvar
)
15341 || !TREE_PUBLIC (cvar
))
15345 if (offset
!= NULL
)
15347 if (!host_integerp (offset
, 0))
15349 *value
= tree_low_cst (offset
, 0);
15352 *value
+= bitpos
/ BITS_PER_UNIT
;
15357 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15358 data attribute for a variable or a parameter. We generate the
15359 DW_AT_const_value attribute only in those cases where the given variable
15360 or parameter does not have a true "location" either in memory or in a
15361 register. This can happen (for example) when a constant is passed as an
15362 actual argument in a call to an inline function. (It's possible that
15363 these things can crop up in other ways also.) Note that one type of
15364 constant value which can be passed into an inlined function is a constant
15365 pointer. This can happen for example if an actual argument in an inlined
15366 function call evaluates to a compile-time constant address.
15368 CACHE_P is true if it is worth caching the location list for DECL,
15369 so that future calls can reuse it rather than regenerate it from scratch.
15370 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15371 since we will need to refer to them each time the function is inlined. */
15374 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
15375 enum dwarf_attribute attr
)
15378 dw_loc_list_ref list
;
15379 var_loc_list
*loc_list
;
15380 cached_dw_loc_list
*cache
;
15383 if (TREE_CODE (decl
) == ERROR_MARK
)
15386 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
15387 || TREE_CODE (decl
) == RESULT_DECL
);
15389 /* Try to get some constant RTL for this decl, and use that as the value of
15392 rtl
= rtl_for_decl_location (decl
);
15393 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15394 && add_const_value_attribute (die
, rtl
))
15397 /* See if we have single element location list that is equivalent to
15398 a constant value. That way we are better to use add_const_value_attribute
15399 rather than expanding constant value equivalent. */
15400 loc_list
= lookup_decl_loc (decl
);
15403 && loc_list
->first
->next
== NULL
15404 && NOTE_P (loc_list
->first
->loc
)
15405 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
15406 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
15408 struct var_loc_node
*node
;
15410 node
= loc_list
->first
;
15411 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
15412 if (GET_CODE (rtl
) == EXPR_LIST
)
15413 rtl
= XEXP (rtl
, 0);
15414 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15415 && add_const_value_attribute (die
, rtl
))
15418 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15419 list several times. See if we've already cached the contents. */
15421 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
15425 cache
= (cached_dw_loc_list
*)
15426 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
15428 list
= cache
->loc_list
;
15432 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
15433 /* It is usually worth caching this result if the decl is from
15434 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15435 if (cache_p
&& list
&& list
->dw_loc_next
)
15437 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
15438 DECL_UID (decl
), INSERT
);
15439 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
15440 cache
->decl_id
= DECL_UID (decl
);
15441 cache
->loc_list
= list
;
15447 add_AT_location_description (die
, attr
, list
);
15450 /* None of that worked, so it must not really have a location;
15451 try adding a constant value attribute from the DECL_INITIAL. */
15452 return tree_add_const_value_attribute_for_decl (die
, decl
);
15455 /* Add VARIABLE and DIE into deferred locations list. */
15458 defer_location (tree variable
, dw_die_ref die
)
15460 deferred_locations entry
;
15461 entry
.variable
= variable
;
15463 vec_safe_push (deferred_locations_list
, entry
);
15466 /* Helper function for tree_add_const_value_attribute. Natively encode
15467 initializer INIT into an array. Return true if successful. */
15470 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15474 if (init
== NULL_TREE
)
15478 switch (TREE_CODE (init
))
15481 type
= TREE_TYPE (init
);
15482 if (TREE_CODE (type
) == ARRAY_TYPE
)
15484 tree enttype
= TREE_TYPE (type
);
15485 enum machine_mode mode
= TYPE_MODE (enttype
);
15487 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15489 if (int_size_in_bytes (type
) != size
)
15491 if (size
> TREE_STRING_LENGTH (init
))
15493 memcpy (array
, TREE_STRING_POINTER (init
),
15494 TREE_STRING_LENGTH (init
));
15495 memset (array
+ TREE_STRING_LENGTH (init
),
15496 '\0', size
- TREE_STRING_LENGTH (init
));
15499 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15504 type
= TREE_TYPE (init
);
15505 if (int_size_in_bytes (type
) != size
)
15507 if (TREE_CODE (type
) == ARRAY_TYPE
)
15509 HOST_WIDE_INT min_index
;
15510 unsigned HOST_WIDE_INT cnt
;
15511 int curpos
= 0, fieldsize
;
15512 constructor_elt
*ce
;
15514 if (TYPE_DOMAIN (type
) == NULL_TREE
15515 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
15518 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15519 if (fieldsize
<= 0)
15522 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
15523 memset (array
, '\0', size
);
15524 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15526 tree val
= ce
->value
;
15527 tree index
= ce
->index
;
15529 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15530 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
15533 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
15538 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
15541 curpos
= pos
+ fieldsize
;
15542 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15544 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
15545 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
15546 while (count
-- > 0)
15549 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
15550 curpos
+= fieldsize
;
15553 gcc_assert (curpos
<= size
);
15557 else if (TREE_CODE (type
) == RECORD_TYPE
15558 || TREE_CODE (type
) == UNION_TYPE
)
15560 tree field
= NULL_TREE
;
15561 unsigned HOST_WIDE_INT cnt
;
15562 constructor_elt
*ce
;
15564 if (int_size_in_bytes (type
) != size
)
15567 if (TREE_CODE (type
) == RECORD_TYPE
)
15568 field
= TYPE_FIELDS (type
);
15570 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15572 tree val
= ce
->value
;
15573 int pos
, fieldsize
;
15575 if (ce
->index
!= 0)
15581 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
15584 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
15585 && TYPE_DOMAIN (TREE_TYPE (field
))
15586 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
15588 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
15589 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
15591 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
15592 pos
= int_byte_position (field
);
15593 gcc_assert (pos
+ fieldsize
<= size
);
15595 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
15601 case VIEW_CONVERT_EXPR
:
15602 case NON_LVALUE_EXPR
:
15603 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
15605 return native_encode_expr (init
, array
, size
) == size
;
15609 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15610 attribute is the const value T. */
15613 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
15616 tree type
= TREE_TYPE (t
);
15619 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
15623 gcc_assert (!DECL_P (init
));
15625 rtl
= rtl_for_decl_init (init
, type
);
15627 return add_const_value_attribute (die
, rtl
);
15628 /* If the host and target are sane, try harder. */
15629 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
15630 && initializer_constant_valid_p (init
, type
))
15632 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
15633 if (size
> 0 && (int) size
== size
)
15635 unsigned char *array
= (unsigned char *)
15636 ggc_alloc_cleared_atomic (size
);
15638 if (native_encode_initializer (init
, array
, size
))
15640 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
15648 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15649 attribute is the const value of T, where T is an integral constant
15650 variable with static storage duration
15651 (so it can't be a PARM_DECL or a RESULT_DECL). */
15654 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
15658 || (TREE_CODE (decl
) != VAR_DECL
15659 && TREE_CODE (decl
) != CONST_DECL
)
15660 || (TREE_CODE (decl
) == VAR_DECL
15661 && !TREE_STATIC (decl
)))
15664 if (TREE_READONLY (decl
)
15665 && ! TREE_THIS_VOLATILE (decl
)
15666 && DECL_INITIAL (decl
))
15671 /* Don't add DW_AT_const_value if abstract origin already has one. */
15672 if (get_AT (var_die
, DW_AT_const_value
))
15675 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
15678 /* Convert the CFI instructions for the current function into a
15679 location list. This is used for DW_AT_frame_base when we targeting
15680 a dwarf2 consumer that does not support the dwarf3
15681 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15684 static dw_loc_list_ref
15685 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
15689 dw_loc_list_ref list
, *list_tail
;
15691 dw_cfa_location last_cfa
, next_cfa
;
15692 const char *start_label
, *last_label
, *section
;
15693 dw_cfa_location remember
;
15696 gcc_assert (fde
!= NULL
);
15698 section
= secname_for_decl (current_function_decl
);
15702 memset (&next_cfa
, 0, sizeof (next_cfa
));
15703 next_cfa
.reg
= INVALID_REGNUM
;
15704 remember
= next_cfa
;
15706 start_label
= fde
->dw_fde_begin
;
15708 /* ??? Bald assumption that the CIE opcode list does not contain
15709 advance opcodes. */
15710 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
15711 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15713 last_cfa
= next_cfa
;
15714 last_label
= start_label
;
15716 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
15718 /* If the first partition contained no CFI adjustments, the
15719 CIE opcodes apply to the whole first partition. */
15720 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15721 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
15722 list_tail
=&(*list_tail
)->dw_loc_next
;
15723 start_label
= last_label
= fde
->dw_fde_second_begin
;
15726 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
15728 switch (cfi
->dw_cfi_opc
)
15730 case DW_CFA_set_loc
:
15731 case DW_CFA_advance_loc1
:
15732 case DW_CFA_advance_loc2
:
15733 case DW_CFA_advance_loc4
:
15734 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15736 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15737 start_label
, last_label
, section
);
15739 list_tail
= &(*list_tail
)->dw_loc_next
;
15740 last_cfa
= next_cfa
;
15741 start_label
= last_label
;
15743 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
15746 case DW_CFA_advance_loc
:
15747 /* The encoding is complex enough that we should never emit this. */
15748 gcc_unreachable ();
15751 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15754 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
15756 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15758 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15759 start_label
, last_label
, section
);
15761 list_tail
= &(*list_tail
)->dw_loc_next
;
15762 last_cfa
= next_cfa
;
15763 start_label
= last_label
;
15765 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15766 start_label
, fde
->dw_fde_end
, section
);
15767 list_tail
= &(*list_tail
)->dw_loc_next
;
15768 start_label
= last_label
= fde
->dw_fde_second_begin
;
15772 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15774 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15775 start_label
, last_label
, section
);
15776 list_tail
= &(*list_tail
)->dw_loc_next
;
15777 start_label
= last_label
;
15780 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
15782 fde
->dw_fde_second_begin
15783 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
15786 if (list
&& list
->dw_loc_next
)
15792 /* Compute a displacement from the "steady-state frame pointer" to the
15793 frame base (often the same as the CFA), and store it in
15794 frame_pointer_fb_offset. OFFSET is added to the displacement
15795 before the latter is negated. */
15798 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
15802 #ifdef FRAME_POINTER_CFA_OFFSET
15803 reg
= frame_pointer_rtx
;
15804 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
15806 reg
= arg_pointer_rtx
;
15807 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
15810 elim
= (ira_use_lra_p
15811 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
15812 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
15813 if (GET_CODE (elim
) == PLUS
)
15815 offset
+= INTVAL (XEXP (elim
, 1));
15816 elim
= XEXP (elim
, 0);
15819 frame_pointer_fb_offset
= -offset
;
15821 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15822 in which to eliminate. This is because it's stack pointer isn't
15823 directly accessible as a register within the ISA. To work around
15824 this, assume that while we cannot provide a proper value for
15825 frame_pointer_fb_offset, we won't need one either. */
15826 frame_pointer_fb_offset_valid
15827 = ((SUPPORTS_STACK_ALIGNMENT
15828 && (elim
== hard_frame_pointer_rtx
15829 || elim
== stack_pointer_rtx
))
15830 || elim
== (frame_pointer_needed
15831 ? hard_frame_pointer_rtx
15832 : stack_pointer_rtx
));
15835 /* Generate a DW_AT_name attribute given some string value to be included as
15836 the value of the attribute. */
15839 add_name_attribute (dw_die_ref die
, const char *name_string
)
15841 if (name_string
!= NULL
&& *name_string
!= 0)
15843 if (demangle_name_func
)
15844 name_string
= (*demangle_name_func
) (name_string
);
15846 add_AT_string (die
, DW_AT_name
, name_string
);
15850 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
15851 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
15852 of TYPE accordingly.
15854 ??? This is a temporary measure until after we're able to generate
15855 regular DWARF for the complex Ada type system. */
15858 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
15859 dw_die_ref context_die
)
15862 dw_die_ref dtype_die
;
15864 if (!lang_hooks
.types
.descriptive_type
)
15867 dtype
= lang_hooks
.types
.descriptive_type (type
);
15871 dtype_die
= lookup_type_die (dtype
);
15874 gen_type_die (dtype
, context_die
);
15875 dtype_die
= lookup_type_die (dtype
);
15876 gcc_assert (dtype_die
);
15879 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
15882 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
15884 static const char *
15885 comp_dir_string (void)
15889 static const char *cached_wd
= NULL
;
15891 if (cached_wd
!= NULL
)
15894 wd
= get_src_pwd ();
15898 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
15902 wdlen
= strlen (wd
);
15903 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
15905 wd1
[wdlen
] = DIR_SEPARATOR
;
15906 wd1
[wdlen
+ 1] = 0;
15910 cached_wd
= remap_debug_filename (wd
);
15914 /* Generate a DW_AT_comp_dir attribute for DIE. */
15917 add_comp_dir_attribute (dw_die_ref die
)
15919 const char * wd
= comp_dir_string ();
15921 add_AT_string (die
, DW_AT_comp_dir
, wd
);
15924 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
15928 lower_bound_default (void)
15930 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
15935 case DW_LANG_C_plus_plus
:
15937 case DW_LANG_ObjC_plus_plus
:
15940 case DW_LANG_Fortran77
:
15941 case DW_LANG_Fortran90
:
15942 case DW_LANG_Fortran95
:
15946 case DW_LANG_Python
:
15947 return dwarf_version
>= 4 ? 0 : -1;
15948 case DW_LANG_Ada95
:
15949 case DW_LANG_Ada83
:
15950 case DW_LANG_Cobol74
:
15951 case DW_LANG_Cobol85
:
15952 case DW_LANG_Pascal83
:
15953 case DW_LANG_Modula2
:
15955 return dwarf_version
>= 4 ? 1 : -1;
15961 /* Given a tree node describing an array bound (either lower or upper) output
15962 a representation for that bound. */
15965 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
15967 switch (TREE_CODE (bound
))
15972 /* All fixed-bounds are represented by INTEGER_CST nodes. */
15975 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
15978 /* Use the default if possible. */
15979 if (bound_attr
== DW_AT_lower_bound
15980 && host_integerp (bound
, 0)
15981 && (dflt
= lower_bound_default ()) != -1
15982 && tree_low_cst (bound
, 0) == dflt
)
15985 /* Otherwise represent the bound as an unsigned value with the
15986 precision of its type. The precision and signedness of the
15987 type will be necessary to re-interpret it unambiguously. */
15988 else if (prec
< HOST_BITS_PER_WIDE_INT
)
15990 unsigned HOST_WIDE_INT mask
15991 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
15992 add_AT_unsigned (subrange_die
, bound_attr
,
15993 TREE_INT_CST_LOW (bound
) & mask
);
15995 else if (prec
== HOST_BITS_PER_WIDE_INT
15996 || TREE_INT_CST_HIGH (bound
) == 0)
15997 add_AT_unsigned (subrange_die
, bound_attr
,
15998 TREE_INT_CST_LOW (bound
));
16000 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
16001 TREE_INT_CST_LOW (bound
));
16006 case VIEW_CONVERT_EXPR
:
16007 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
16017 dw_die_ref decl_die
= lookup_decl_die (bound
);
16019 /* ??? Can this happen, or should the variable have been bound
16020 first? Probably it can, since I imagine that we try to create
16021 the types of parameters in the order in which they exist in
16022 the list, and won't have created a forward reference to a
16023 later parameter. */
16024 if (decl_die
!= NULL
)
16026 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16034 /* Otherwise try to create a stack operation procedure to
16035 evaluate the value of the array bound. */
16037 dw_die_ref ctx
, decl_die
;
16038 dw_loc_list_ref list
;
16040 list
= loc_list_from_tree (bound
, 2);
16041 if (list
== NULL
|| single_element_loc_list_p (list
))
16043 /* If DW_AT_*bound is not a reference nor constant, it is
16044 a DWARF expression rather than location description.
16045 For that loc_list_from_tree (bound, 0) is needed.
16046 If that fails to give a single element list,
16047 fall back to outputting this as a reference anyway. */
16048 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
16049 if (list2
&& single_element_loc_list_p (list2
))
16051 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
16058 if (current_function_decl
== 0)
16059 ctx
= comp_unit_die ();
16061 ctx
= lookup_decl_die (current_function_decl
);
16063 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
16064 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
16065 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
16066 add_AT_location_description (decl_die
, DW_AT_location
, list
);
16067 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16073 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16074 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16075 Note that the block of subscript information for an array type also
16076 includes information about the element type of the given array type. */
16079 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
16081 unsigned dimension_number
;
16083 dw_die_ref subrange_die
;
16085 for (dimension_number
= 0;
16086 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
16087 type
= TREE_TYPE (type
), dimension_number
++)
16089 tree domain
= TYPE_DOMAIN (type
);
16091 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
16094 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16095 and (in GNU C only) variable bounds. Handle all three forms
16097 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
16100 /* We have an array type with specified bounds. */
16101 lower
= TYPE_MIN_VALUE (domain
);
16102 upper
= TYPE_MAX_VALUE (domain
);
16104 /* Define the index type. */
16105 if (TREE_TYPE (domain
))
16107 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16108 TREE_TYPE field. We can't emit debug info for this
16109 because it is an unnamed integral type. */
16110 if (TREE_CODE (domain
) == INTEGER_TYPE
16111 && TYPE_NAME (domain
) == NULL_TREE
16112 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
16113 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
16116 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
16120 /* ??? If upper is NULL, the array has unspecified length,
16121 but it does have a lower bound. This happens with Fortran
16123 Since the debugger is definitely going to need to know N
16124 to produce useful results, go ahead and output the lower
16125 bound solo, and hope the debugger can cope. */
16127 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
16129 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
16132 /* Otherwise we have an array type with an unspecified length. The
16133 DWARF-2 spec does not say how to handle this; let's just leave out the
16139 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16141 dw_die_ref decl_die
;
16144 switch (TREE_CODE (tree_node
))
16149 case ENUMERAL_TYPE
:
16152 case QUAL_UNION_TYPE
:
16153 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
16154 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
16156 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
16159 size
= int_size_in_bytes (tree_node
);
16162 /* For a data member of a struct or union, the DW_AT_byte_size is
16163 generally given as the number of bytes normally allocated for an
16164 object of the *declared* type of the member itself. This is true
16165 even for bit-fields. */
16166 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
16169 gcc_unreachable ();
16172 /* Note that `size' might be -1 when we get to this point. If it is, that
16173 indicates that the byte size of the entity in question is variable. We
16174 have no good way of expressing this fact in Dwarf at the present time,
16175 so just let the -1 pass on through. */
16176 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
16179 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16180 which specifies the distance in bits from the highest order bit of the
16181 "containing object" for the bit-field to the highest order bit of the
16184 For any given bit-field, the "containing object" is a hypothetical object
16185 (of some integral or enum type) within which the given bit-field lives. The
16186 type of this hypothetical "containing object" is always the same as the
16187 declared type of the individual bit-field itself. The determination of the
16188 exact location of the "containing object" for a bit-field is rather
16189 complicated. It's handled by the `field_byte_offset' function (above).
16191 Note that it is the size (in bytes) of the hypothetical "containing object"
16192 which will be given in the DW_AT_byte_size attribute for this bit-field.
16193 (See `byte_size_attribute' above). */
16196 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
16198 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
16199 tree type
= DECL_BIT_FIELD_TYPE (decl
);
16200 HOST_WIDE_INT bitpos_int
;
16201 HOST_WIDE_INT highest_order_object_bit_offset
;
16202 HOST_WIDE_INT highest_order_field_bit_offset
;
16203 HOST_WIDE_INT bit_offset
;
16205 /* Must be a field and a bit field. */
16206 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
16208 /* We can't yet handle bit-fields whose offsets are variable, so if we
16209 encounter such things, just return without generating any attribute
16210 whatsoever. Likewise for variable or too large size. */
16211 if (! host_integerp (bit_position (decl
), 0)
16212 || ! host_integerp (DECL_SIZE (decl
), 1))
16215 bitpos_int
= int_bit_position (decl
);
16217 /* Note that the bit offset is always the distance (in bits) from the
16218 highest-order bit of the "containing object" to the highest-order bit of
16219 the bit-field itself. Since the "high-order end" of any object or field
16220 is different on big-endian and little-endian machines, the computation
16221 below must take account of these differences. */
16222 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
16223 highest_order_field_bit_offset
= bitpos_int
;
16225 if (! BYTES_BIG_ENDIAN
)
16227 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
16228 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
16232 = (! BYTES_BIG_ENDIAN
16233 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
16234 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
16236 if (bit_offset
< 0)
16237 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
16239 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
16242 /* For a FIELD_DECL node which represents a bit field, output an attribute
16243 which specifies the length in bits of the given field. */
16246 add_bit_size_attribute (dw_die_ref die
, tree decl
)
16248 /* Must be a field and a bit field. */
16249 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
16250 && DECL_BIT_FIELD_TYPE (decl
));
16252 if (host_integerp (DECL_SIZE (decl
), 1))
16253 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
16256 /* If the compiled language is ANSI C, then add a 'prototyped'
16257 attribute, if arg types are given for the parameters of a function. */
16260 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
16262 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
16263 && prototype_p (func_type
))
16264 add_AT_flag (die
, DW_AT_prototyped
, 1);
16267 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16268 by looking in either the type declaration or object declaration
16271 static inline dw_die_ref
16272 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
16274 dw_die_ref origin_die
= NULL
;
16276 if (TREE_CODE (origin
) != FUNCTION_DECL
)
16278 /* We may have gotten separated from the block for the inlined
16279 function, if we're in an exception handler or some such; make
16280 sure that the abstract function has been written out.
16282 Doing this for nested functions is wrong, however; functions are
16283 distinct units, and our context might not even be inline. */
16287 fn
= TYPE_STUB_DECL (fn
);
16289 fn
= decl_function_context (fn
);
16291 dwarf2out_abstract_function (fn
);
16294 if (DECL_P (origin
))
16295 origin_die
= lookup_decl_die (origin
);
16296 else if (TYPE_P (origin
))
16297 origin_die
= lookup_type_die (origin
);
16299 /* XXX: Functions that are never lowered don't always have correct block
16300 trees (in the case of java, they simply have no block tree, in some other
16301 languages). For these functions, there is nothing we can really do to
16302 output correct debug info for inlined functions in all cases. Rather
16303 than die, we'll just produce deficient debug info now, in that we will
16304 have variables without a proper abstract origin. In the future, when all
16305 functions are lowered, we should re-add a gcc_assert (origin_die)
16309 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
16313 /* We do not currently support the pure_virtual attribute. */
16316 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
16318 if (DECL_VINDEX (func_decl
))
16320 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
16322 if (host_integerp (DECL_VINDEX (func_decl
), 0))
16323 add_AT_loc (die
, DW_AT_vtable_elem_location
,
16324 new_loc_descr (DW_OP_constu
,
16325 tree_low_cst (DECL_VINDEX (func_decl
), 0),
16328 /* GNU extension: Record what type this method came from originally. */
16329 if (debug_info_level
> DINFO_LEVEL_TERSE
16330 && DECL_CONTEXT (func_decl
))
16331 add_AT_die_ref (die
, DW_AT_containing_type
,
16332 lookup_type_die (DECL_CONTEXT (func_decl
)));
16336 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16337 given decl. This used to be a vendor extension until after DWARF 4
16338 standardized it. */
16341 add_linkage_attr (dw_die_ref die
, tree decl
)
16343 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
16345 /* Mimic what assemble_name_raw does with a leading '*'. */
16346 if (name
[0] == '*')
16349 if (dwarf_version
>= 4)
16350 add_AT_string (die
, DW_AT_linkage_name
, name
);
16352 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
16355 /* Add source coordinate attributes for the given decl. */
16358 add_src_coords_attributes (dw_die_ref die
, tree decl
)
16360 expanded_location s
;
16362 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
16364 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16365 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
16366 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
16369 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16372 add_linkage_name (dw_die_ref die
, tree decl
)
16374 if (debug_info_level
> DINFO_LEVEL_TERSE
16375 && (TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
16376 && TREE_PUBLIC (decl
)
16377 && !DECL_ABSTRACT (decl
)
16378 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
16379 && die
->die_tag
!= DW_TAG_member
)
16381 /* Defer until we have an assembler name set. */
16382 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
16384 limbo_die_node
*asm_name
;
16386 asm_name
= ggc_alloc_cleared_limbo_die_node ();
16387 asm_name
->die
= die
;
16388 asm_name
->created_for
= decl
;
16389 asm_name
->next
= deferred_asm_name
;
16390 deferred_asm_name
= asm_name
;
16392 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
16393 add_linkage_attr (die
, decl
);
16397 /* Add a DW_AT_name attribute and source coordinate attribute for the
16398 given decl, but only if it actually has a name. */
16401 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
16405 decl_name
= DECL_NAME (decl
);
16406 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
16408 const char *name
= dwarf2_name (decl
, 0);
16410 add_name_attribute (die
, name
);
16411 if (! DECL_ARTIFICIAL (decl
))
16412 add_src_coords_attributes (die
, decl
);
16414 add_linkage_name (die
, decl
);
16417 #ifdef VMS_DEBUGGING_INFO
16418 /* Get the function's name, as described by its RTL. This may be different
16419 from the DECL_NAME name used in the source file. */
16420 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
16422 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
16423 XEXP (DECL_RTL (decl
), 0), false);
16424 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
16426 #endif /* VMS_DEBUGGING_INFO */
16429 #ifdef VMS_DEBUGGING_INFO
16430 /* Output the debug main pointer die for VMS */
16433 dwarf2out_vms_debug_main_pointer (void)
16435 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
16438 /* Allocate the VMS debug main subprogram die. */
16439 die
= ggc_alloc_cleared_die_node ();
16440 die
->die_tag
= DW_TAG_subprogram
;
16441 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
16442 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
16443 FUNC_LABEL_ID (cfun
));
16444 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
16446 /* Make it the first child of comp_unit_die (). */
16447 die
->die_parent
= comp_unit_die ();
16448 if (comp_unit_die ()->die_child
)
16450 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
16451 comp_unit_die ()->die_child
->die_sib
= die
;
16455 die
->die_sib
= die
;
16456 comp_unit_die ()->die_child
= die
;
16459 #endif /* VMS_DEBUGGING_INFO */
16461 /* Push a new declaration scope. */
16464 push_decl_scope (tree scope
)
16466 vec_safe_push (decl_scope_table
, scope
);
16469 /* Pop a declaration scope. */
16472 pop_decl_scope (void)
16474 decl_scope_table
->pop ();
16477 /* walk_tree helper function for uses_local_type, below. */
16480 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
16483 *walk_subtrees
= 0;
16486 tree name
= TYPE_NAME (*tp
);
16487 if (name
&& DECL_P (name
) && decl_function_context (name
))
16493 /* If TYPE involves a function-local type (including a local typedef to a
16494 non-local type), returns that type; otherwise returns NULL_TREE. */
16497 uses_local_type (tree type
)
16499 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
16503 /* Return the DIE for the scope that immediately contains this type.
16504 Non-named types that do not involve a function-local type get global
16505 scope. Named types nested in namespaces or other types get their
16506 containing scope. All other types (i.e. function-local named types) get
16507 the current active scope. */
16510 scope_die_for (tree t
, dw_die_ref context_die
)
16512 dw_die_ref scope_die
= NULL
;
16513 tree containing_scope
;
16515 /* Non-types always go in the current scope. */
16516 gcc_assert (TYPE_P (t
));
16518 /* Use the scope of the typedef, rather than the scope of the type
16520 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
16521 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
16523 containing_scope
= TYPE_CONTEXT (t
);
16525 /* Use the containing namespace if there is one. */
16526 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
16528 if (context_die
== lookup_decl_die (containing_scope
))
16530 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
16531 context_die
= get_context_die (containing_scope
);
16533 containing_scope
= NULL_TREE
;
16536 /* Ignore function type "scopes" from the C frontend. They mean that
16537 a tagged type is local to a parmlist of a function declarator, but
16538 that isn't useful to DWARF. */
16539 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
16540 containing_scope
= NULL_TREE
;
16542 if (SCOPE_FILE_SCOPE_P (containing_scope
))
16544 /* If T uses a local type keep it local as well, to avoid references
16545 to function-local DIEs from outside the function. */
16546 if (current_function_decl
&& uses_local_type (t
))
16547 scope_die
= context_die
;
16549 scope_die
= comp_unit_die ();
16551 else if (TYPE_P (containing_scope
))
16553 /* For types, we can just look up the appropriate DIE. */
16554 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16555 scope_die
= get_context_die (containing_scope
);
16558 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
16559 if (scope_die
== NULL
)
16560 scope_die
= comp_unit_die ();
16564 scope_die
= context_die
;
16569 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16572 local_scope_p (dw_die_ref context_die
)
16574 for (; context_die
; context_die
= context_die
->die_parent
)
16575 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
16576 || context_die
->die_tag
== DW_TAG_subprogram
)
16582 /* Returns nonzero if CONTEXT_DIE is a class. */
16585 class_scope_p (dw_die_ref context_die
)
16587 return (context_die
16588 && (context_die
->die_tag
== DW_TAG_structure_type
16589 || context_die
->die_tag
== DW_TAG_class_type
16590 || context_die
->die_tag
== DW_TAG_interface_type
16591 || context_die
->die_tag
== DW_TAG_union_type
));
16594 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16595 whether or not to treat a DIE in this context as a declaration. */
16598 class_or_namespace_scope_p (dw_die_ref context_die
)
16600 return (class_scope_p (context_die
)
16601 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
16604 /* Many forms of DIEs require a "type description" attribute. This
16605 routine locates the proper "type descriptor" die for the type given
16606 by 'type', and adds a DW_AT_type attribute below the given die. */
16609 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
16610 int decl_volatile
, dw_die_ref context_die
)
16612 enum tree_code code
= TREE_CODE (type
);
16613 dw_die_ref type_die
= NULL
;
16615 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16616 or fixed-point type, use the inner type. This is because we have no
16617 support for unnamed types in base_type_die. This can happen if this is
16618 an Ada subrange type. Correct solution is emit a subrange type die. */
16619 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
16620 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
16621 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
16623 if (code
== ERROR_MARK
16624 /* Handle a special case. For functions whose return type is void, we
16625 generate *no* type attribute. (Note that no object may have type
16626 `void', so this only applies to function return types). */
16627 || code
== VOID_TYPE
)
16630 type_die
= modified_type_die (type
,
16631 decl_const
|| TYPE_READONLY (type
),
16632 decl_volatile
|| TYPE_VOLATILE (type
),
16635 if (type_die
!= NULL
)
16636 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
16639 /* Given an object die, add the calling convention attribute for the
16640 function call type. */
16642 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
16644 enum dwarf_calling_convention value
= DW_CC_normal
;
16646 value
= ((enum dwarf_calling_convention
)
16647 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
16650 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
16652 /* DWARF 2 doesn't provide a way to identify a program's source-level
16653 entry point. DW_AT_calling_convention attributes are only meant
16654 to describe functions' calling conventions. However, lacking a
16655 better way to signal the Fortran main program, we used this for
16656 a long time, following existing custom. Now, DWARF 4 has
16657 DW_AT_main_subprogram, which we add below, but some tools still
16658 rely on the old way, which we thus keep. */
16659 value
= DW_CC_program
;
16661 if (dwarf_version
>= 4 || !dwarf_strict
)
16662 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
16665 /* Only add the attribute if the backend requests it, and
16666 is not DW_CC_normal. */
16667 if (value
&& (value
!= DW_CC_normal
))
16668 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
16671 /* Given a tree pointer to a struct, class, union, or enum type node, return
16672 a pointer to the (string) tag name for the given type, or zero if the type
16673 was declared without a tag. */
16675 static const char *
16676 type_tag (const_tree type
)
16678 const char *name
= 0;
16680 if (TYPE_NAME (type
) != 0)
16684 /* Find the IDENTIFIER_NODE for the type name. */
16685 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
16686 && !TYPE_NAMELESS (type
))
16687 t
= TYPE_NAME (type
);
16689 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16690 a TYPE_DECL node, regardless of whether or not a `typedef' was
16692 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
16693 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
16695 /* We want to be extra verbose. Don't call dwarf_name if
16696 DECL_NAME isn't set. The default hook for decl_printable_name
16697 doesn't like that, and in this context it's correct to return
16698 0, instead of "<anonymous>" or the like. */
16699 if (DECL_NAME (TYPE_NAME (type
))
16700 && !DECL_NAMELESS (TYPE_NAME (type
)))
16701 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
16704 /* Now get the name as a string, or invent one. */
16705 if (!name
&& t
!= 0)
16706 name
= IDENTIFIER_POINTER (t
);
16709 return (name
== 0 || *name
== '\0') ? 0 : name
;
16712 /* Return the type associated with a data member, make a special check
16713 for bit field types. */
16716 member_declared_type (const_tree member
)
16718 return (DECL_BIT_FIELD_TYPE (member
)
16719 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
16722 /* Get the decl's label, as described by its RTL. This may be different
16723 from the DECL_NAME name used in the source file. */
16726 static const char *
16727 decl_start_label (tree decl
)
16730 const char *fnname
;
16732 x
= DECL_RTL (decl
);
16733 gcc_assert (MEM_P (x
));
16736 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
16738 fnname
= XSTR (x
, 0);
16743 /* These routines generate the internal representation of the DIE's for
16744 the compilation unit. Debugging information is collected by walking
16745 the declaration trees passed in from dwarf2out_decl(). */
16748 gen_array_type_die (tree type
, dw_die_ref context_die
)
16750 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16751 dw_die_ref array_die
;
16753 /* GNU compilers represent multidimensional array types as sequences of one
16754 dimensional array types whose element types are themselves array types.
16755 We sometimes squish that down to a single array_type DIE with multiple
16756 subscripts in the Dwarf debugging info. The draft Dwarf specification
16757 say that we are allowed to do this kind of compression in C, because
16758 there is no difference between an array of arrays and a multidimensional
16759 array. We don't do this for Ada to remain as close as possible to the
16760 actual representation, which is especially important against the language
16761 flexibilty wrt arrays of variable size. */
16763 bool collapse_nested_arrays
= !is_ada ();
16766 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16767 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16768 if (TYPE_STRING_FLAG (type
)
16769 && TREE_CODE (type
) == ARRAY_TYPE
16771 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
16773 HOST_WIDE_INT size
;
16775 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
16776 add_name_attribute (array_die
, type_tag (type
));
16777 equate_type_number_to_die (type
, array_die
);
16778 size
= int_size_in_bytes (type
);
16780 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16781 else if (TYPE_DOMAIN (type
) != NULL_TREE
16782 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
16783 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
16785 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
16786 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
16788 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
16789 if (loc
&& size
> 0)
16791 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
16792 if (size
!= DWARF2_ADDR_SIZE
)
16793 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16799 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16800 add_name_attribute (array_die
, type_tag (type
));
16801 equate_type_number_to_die (type
, array_die
);
16803 if (TREE_CODE (type
) == VECTOR_TYPE
)
16804 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
16806 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16808 && TREE_CODE (type
) == ARRAY_TYPE
16809 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
16810 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
16811 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16814 /* We default the array ordering. SDB will probably do
16815 the right things even if DW_AT_ordering is not present. It's not even
16816 an issue until we start to get into multidimensional arrays anyway. If
16817 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16818 then we'll have to put the DW_AT_ordering attribute back in. (But if
16819 and when we find out that we need to put these in, we will only do so
16820 for multidimensional arrays. */
16821 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
16824 if (TREE_CODE (type
) == VECTOR_TYPE
)
16826 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
16827 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16828 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
16829 add_bound_info (subrange_die
, DW_AT_upper_bound
,
16830 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
16833 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
16835 /* Add representation of the type of the elements of this array type and
16836 emit the corresponding DIE if we haven't done it already. */
16837 element_type
= TREE_TYPE (type
);
16838 if (collapse_nested_arrays
)
16839 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
16841 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
16843 element_type
= TREE_TYPE (element_type
);
16846 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
16848 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
16849 if (TYPE_ARTIFICIAL (type
))
16850 add_AT_flag (array_die
, DW_AT_artificial
, 1);
16852 if (get_AT (array_die
, DW_AT_name
))
16853 add_pubtype (type
, array_die
);
16856 static dw_loc_descr_ref
16857 descr_info_loc (tree val
, tree base_decl
)
16859 HOST_WIDE_INT size
;
16860 dw_loc_descr_ref loc
, loc2
;
16861 enum dwarf_location_atom op
;
16863 if (val
== base_decl
)
16864 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
16866 switch (TREE_CODE (val
))
16869 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16871 return loc_descriptor_from_tree (val
, 0);
16873 if (host_integerp (val
, 0))
16874 return int_loc_descriptor (tree_low_cst (val
, 0));
16877 size
= int_size_in_bytes (TREE_TYPE (val
));
16880 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16883 if (size
== DWARF2_ADDR_SIZE
)
16884 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
16886 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
16888 case POINTER_PLUS_EXPR
:
16890 if (host_integerp (TREE_OPERAND (val
, 1), 1)
16891 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
16894 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16897 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
16903 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16906 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
16909 add_loc_descr (&loc
, loc2
);
16910 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
16932 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
16933 tree val
, tree base_decl
)
16935 dw_loc_descr_ref loc
;
16937 if (host_integerp (val
, 0))
16939 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
16943 loc
= descr_info_loc (val
, base_decl
);
16947 add_AT_loc (die
, attr
, loc
);
16950 /* This routine generates DIE for array with hidden descriptor, details
16951 are filled into *info by a langhook. */
16954 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
16955 dw_die_ref context_die
)
16957 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16958 dw_die_ref array_die
;
16961 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16962 add_name_attribute (array_die
, type_tag (type
));
16963 equate_type_number_to_die (type
, array_die
);
16965 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16967 && info
->ndimensions
>= 2)
16968 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16970 if (info
->data_location
)
16971 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
16973 if (info
->associated
)
16974 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
16976 if (info
->allocated
)
16977 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
16980 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
16982 dw_die_ref subrange_die
16983 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16985 if (info
->dimen
[dim
].lower_bound
)
16987 /* If it is the default value, omit it. */
16990 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
16991 && (dflt
= lower_bound_default ()) != -1
16992 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
16995 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
16996 info
->dimen
[dim
].lower_bound
,
16999 if (info
->dimen
[dim
].upper_bound
)
17000 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
17001 info
->dimen
[dim
].upper_bound
,
17003 if (info
->dimen
[dim
].stride
)
17004 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
17005 info
->dimen
[dim
].stride
,
17009 gen_type_die (info
->element_type
, context_die
);
17010 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
17012 if (get_AT (array_die
, DW_AT_name
))
17013 add_pubtype (type
, array_die
);
17018 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
17020 tree origin
= decl_ultimate_origin (decl
);
17021 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
17023 if (origin
!= NULL
)
17024 add_abstract_origin_attribute (decl_die
, origin
);
17027 add_name_and_src_coords_attributes (decl_die
, decl
);
17028 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
17029 0, 0, context_die
);
17032 if (DECL_ABSTRACT (decl
))
17033 equate_decl_number_to_die (decl
, decl_die
);
17035 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
17039 /* Walk through the list of incomplete types again, trying once more to
17040 emit full debugging info for them. */
17043 retry_incomplete_types (void)
17047 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
17048 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
17049 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
17052 /* Determine what tag to use for a record type. */
17054 static enum dwarf_tag
17055 record_type_tag (tree type
)
17057 if (! lang_hooks
.types
.classify_record
)
17058 return DW_TAG_structure_type
;
17060 switch (lang_hooks
.types
.classify_record (type
))
17062 case RECORD_IS_STRUCT
:
17063 return DW_TAG_structure_type
;
17065 case RECORD_IS_CLASS
:
17066 return DW_TAG_class_type
;
17068 case RECORD_IS_INTERFACE
:
17069 if (dwarf_version
>= 3 || !dwarf_strict
)
17070 return DW_TAG_interface_type
;
17071 return DW_TAG_structure_type
;
17074 gcc_unreachable ();
17078 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17079 include all of the information about the enumeration values also. Each
17080 enumerated type name/value is listed as a child of the enumerated type
17084 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
17086 dw_die_ref type_die
= lookup_type_die (type
);
17088 if (type_die
== NULL
)
17090 type_die
= new_die (DW_TAG_enumeration_type
,
17091 scope_die_for (type
, context_die
), type
);
17092 equate_type_number_to_die (type
, type_die
);
17093 add_name_attribute (type_die
, type_tag (type
));
17094 if (dwarf_version
>= 4 || !dwarf_strict
)
17096 if (ENUM_IS_SCOPED (type
))
17097 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
17098 if (ENUM_IS_OPAQUE (type
))
17099 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17102 else if (! TYPE_SIZE (type
))
17105 remove_AT (type_die
, DW_AT_declaration
);
17107 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17108 given enum type is incomplete, do not generate the DW_AT_byte_size
17109 attribute or the DW_AT_element_list attribute. */
17110 if (TYPE_SIZE (type
))
17114 TREE_ASM_WRITTEN (type
) = 1;
17115 add_byte_size_attribute (type_die
, type
);
17116 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17118 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17119 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17122 /* If the first reference to this type was as the return type of an
17123 inline function, then it may not have a parent. Fix this now. */
17124 if (type_die
->die_parent
== NULL
)
17125 add_child_die (scope_die_for (type
, context_die
), type_die
);
17127 for (link
= TYPE_VALUES (type
);
17128 link
!= NULL
; link
= TREE_CHAIN (link
))
17130 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17131 tree value
= TREE_VALUE (link
);
17133 add_name_attribute (enum_die
,
17134 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17136 if (TREE_CODE (value
) == CONST_DECL
)
17137 value
= DECL_INITIAL (value
);
17139 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
17140 /* DWARF2 does not provide a way of indicating whether or
17141 not enumeration constants are signed or unsigned. GDB
17142 always assumes the values are signed, so we output all
17143 values as if they were signed. That means that
17144 enumeration constants with very large unsigned values
17145 will appear to have negative values in the debugger. */
17146 add_AT_int (enum_die
, DW_AT_const_value
,
17147 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
17150 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17151 if (TYPE_ARTIFICIAL (type
))
17152 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17155 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17157 add_pubtype (type
, type_die
);
17162 /* Generate a DIE to represent either a real live formal parameter decl or to
17163 represent just the type of some formal parameter position in some function
17166 Note that this routine is a bit unusual because its argument may be a
17167 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17168 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17169 node. If it's the former then this function is being called to output a
17170 DIE to represent a formal parameter object (or some inlining thereof). If
17171 it's the latter, then this function is only being called to output a
17172 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17173 argument type of some subprogram type.
17174 If EMIT_NAME_P is true, name and source coordinate attributes
17178 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17179 dw_die_ref context_die
)
17181 tree node_or_origin
= node
? node
: origin
;
17182 tree ultimate_origin
;
17183 dw_die_ref parm_die
17184 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
17186 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
17188 case tcc_declaration
:
17189 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
17190 if (node
|| ultimate_origin
)
17191 origin
= ultimate_origin
;
17192 if (origin
!= NULL
)
17193 add_abstract_origin_attribute (parm_die
, origin
);
17194 else if (emit_name_p
)
17195 add_name_and_src_coords_attributes (parm_die
, node
);
17197 || (! DECL_ABSTRACT (node_or_origin
)
17198 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
17199 decl_function_context
17200 (node_or_origin
))))
17202 tree type
= TREE_TYPE (node_or_origin
);
17203 if (decl_by_reference_p (node_or_origin
))
17204 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
17207 add_type_attribute (parm_die
, type
,
17208 TREE_READONLY (node_or_origin
),
17209 TREE_THIS_VOLATILE (node_or_origin
),
17212 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
17213 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17215 if (node
&& node
!= origin
)
17216 equate_decl_number_to_die (node
, parm_die
);
17217 if (! DECL_ABSTRACT (node_or_origin
))
17218 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
17219 node
== NULL
, DW_AT_location
);
17224 /* We were called with some kind of a ..._TYPE node. */
17225 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
17229 gcc_unreachable ();
17235 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17236 children DW_TAG_formal_parameter DIEs representing the arguments of the
17239 PARM_PACK must be a function parameter pack.
17240 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17241 must point to the subsequent arguments of the function PACK_ARG belongs to.
17242 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17243 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17244 following the last one for which a DIE was generated. */
17247 gen_formal_parameter_pack_die (tree parm_pack
,
17249 dw_die_ref subr_die
,
17253 dw_die_ref parm_pack_die
;
17255 gcc_assert (parm_pack
17256 && lang_hooks
.function_parameter_pack_p (parm_pack
)
17259 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
17260 add_src_coords_attributes (parm_pack_die
, parm_pack
);
17262 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
17264 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
17267 gen_formal_parameter_die (arg
, NULL
,
17268 false /* Don't emit name attribute. */,
17273 return parm_pack_die
;
17276 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17277 at the end of an (ANSI prototyped) formal parameters list. */
17280 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
17282 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
17285 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17286 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17287 parameters as specified in some function type specification (except for
17288 those which appear as part of a function *definition*). */
17291 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
17294 tree formal_type
= NULL
;
17295 tree first_parm_type
;
17298 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
17300 arg
= DECL_ARGUMENTS (function_or_method_type
);
17301 function_or_method_type
= TREE_TYPE (function_or_method_type
);
17306 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
17308 /* Make our first pass over the list of formal parameter types and output a
17309 DW_TAG_formal_parameter DIE for each one. */
17310 for (link
= first_parm_type
; link
; )
17312 dw_die_ref parm_die
;
17314 formal_type
= TREE_VALUE (link
);
17315 if (formal_type
== void_type_node
)
17318 /* Output a (nameless) DIE to represent the formal parameter itself. */
17319 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
17320 true /* Emit name attribute. */,
17322 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
17323 && link
== first_parm_type
)
17325 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17326 if (dwarf_version
>= 3 || !dwarf_strict
)
17327 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
17329 else if (arg
&& DECL_ARTIFICIAL (arg
))
17330 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17332 link
= TREE_CHAIN (link
);
17334 arg
= DECL_CHAIN (arg
);
17337 /* If this function type has an ellipsis, add a
17338 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17339 if (formal_type
!= void_type_node
)
17340 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
17342 /* Make our second (and final) pass over the list of formal parameter types
17343 and output DIEs to represent those types (as necessary). */
17344 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
17345 link
&& TREE_VALUE (link
);
17346 link
= TREE_CHAIN (link
))
17347 gen_type_die (TREE_VALUE (link
), context_die
);
17350 /* We want to generate the DIE for TYPE so that we can generate the
17351 die for MEMBER, which has been defined; we will need to refer back
17352 to the member declaration nested within TYPE. If we're trying to
17353 generate minimal debug info for TYPE, processing TYPE won't do the
17354 trick; we need to attach the member declaration by hand. */
17357 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
17359 gen_type_die (type
, context_die
);
17361 /* If we're trying to avoid duplicate debug info, we may not have
17362 emitted the member decl for this function. Emit it now. */
17363 if (TYPE_STUB_DECL (type
)
17364 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
17365 && ! lookup_decl_die (member
))
17367 dw_die_ref type_die
;
17368 gcc_assert (!decl_ultimate_origin (member
));
17370 push_decl_scope (type
);
17371 type_die
= lookup_type_die_strip_naming_typedef (type
);
17372 if (TREE_CODE (member
) == FUNCTION_DECL
)
17373 gen_subprogram_die (member
, type_die
);
17374 else if (TREE_CODE (member
) == FIELD_DECL
)
17376 /* Ignore the nameless fields that are used to skip bits but handle
17377 C++ anonymous unions and structs. */
17378 if (DECL_NAME (member
) != NULL_TREE
17379 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
17380 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
17382 gen_type_die (member_declared_type (member
), type_die
);
17383 gen_field_die (member
, type_die
);
17387 gen_variable_die (member
, NULL_TREE
, type_die
);
17393 /* Forward declare these functions, because they are mutually recursive
17394 with their set_block_* pairing functions. */
17395 static void set_decl_origin_self (tree
);
17396 static void set_decl_abstract_flags (tree
, int);
17398 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
17399 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
17400 that it points to the node itself, thus indicating that the node is its
17401 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
17402 the given node is NULL, recursively descend the decl/block tree which
17403 it is the root of, and for each other ..._DECL or BLOCK node contained
17404 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
17405 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
17406 values to point to themselves. */
17409 set_block_origin_self (tree stmt
)
17411 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
17413 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
17418 for (local_decl
= BLOCK_VARS (stmt
);
17419 local_decl
!= NULL_TREE
;
17420 local_decl
= DECL_CHAIN (local_decl
))
17421 if (! DECL_EXTERNAL (local_decl
))
17422 set_decl_origin_self (local_decl
); /* Potential recursion. */
17428 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17429 subblock
!= NULL_TREE
;
17430 subblock
= BLOCK_CHAIN (subblock
))
17431 set_block_origin_self (subblock
); /* Recurse. */
17436 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
17437 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
17438 node to so that it points to the node itself, thus indicating that the
17439 node represents its own (abstract) origin. Additionally, if the
17440 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
17441 the decl/block tree of which the given node is the root of, and for
17442 each other ..._DECL or BLOCK node contained therein whose
17443 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
17444 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
17445 point to themselves. */
17448 set_decl_origin_self (tree decl
)
17450 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
17452 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
17453 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17457 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17458 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
17459 if (DECL_INITIAL (decl
) != NULL_TREE
17460 && DECL_INITIAL (decl
) != error_mark_node
)
17461 set_block_origin_self (DECL_INITIAL (decl
));
17466 /* Given a pointer to some BLOCK node, and a boolean value to set the
17467 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
17468 the given block, and for all local decls and all local sub-blocks
17469 (recursively) which are contained therein. */
17472 set_block_abstract_flags (tree stmt
, int setting
)
17478 BLOCK_ABSTRACT (stmt
) = setting
;
17480 for (local_decl
= BLOCK_VARS (stmt
);
17481 local_decl
!= NULL_TREE
;
17482 local_decl
= DECL_CHAIN (local_decl
))
17483 if (! DECL_EXTERNAL (local_decl
))
17484 set_decl_abstract_flags (local_decl
, setting
);
17486 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
17488 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
17489 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
17490 || TREE_CODE (local_decl
) == PARM_DECL
)
17491 set_decl_abstract_flags (local_decl
, setting
);
17494 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17495 subblock
!= NULL_TREE
;
17496 subblock
= BLOCK_CHAIN (subblock
))
17497 set_block_abstract_flags (subblock
, setting
);
17500 /* Given a pointer to some ..._DECL node, and a boolean value to set the
17501 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
17502 given decl, and (in the case where the decl is a FUNCTION_DECL) also
17503 set the abstract flags for all of the parameters, local vars, local
17504 blocks and sub-blocks (recursively) to the same setting. */
17507 set_decl_abstract_flags (tree decl
, int setting
)
17509 DECL_ABSTRACT (decl
) = setting
;
17510 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17514 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17515 DECL_ABSTRACT (arg
) = setting
;
17516 if (DECL_INITIAL (decl
) != NULL_TREE
17517 && DECL_INITIAL (decl
) != error_mark_node
)
17518 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
17522 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17523 may later generate inlined and/or out-of-line instances of. */
17526 dwarf2out_abstract_function (tree decl
)
17528 dw_die_ref old_die
;
17532 htab_t old_decl_loc_table
;
17533 htab_t old_cached_dw_loc_list_table
;
17534 int old_call_site_count
, old_tail_call_site_count
;
17535 struct call_arg_loc_node
*old_call_arg_locations
;
17537 /* Make sure we have the actual abstract inline, not a clone. */
17538 decl
= DECL_ORIGIN (decl
);
17540 old_die
= lookup_decl_die (decl
);
17541 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
17542 /* We've already generated the abstract instance. */
17545 /* We can be called while recursively when seeing block defining inlined subroutine
17546 DIE. Be sure to not clobber the outer location table nor use it or we would
17547 get locations in abstract instantces. */
17548 old_decl_loc_table
= decl_loc_table
;
17549 decl_loc_table
= NULL
;
17550 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
17551 cached_dw_loc_list_table
= NULL
;
17552 old_call_arg_locations
= call_arg_locations
;
17553 call_arg_locations
= NULL
;
17554 old_call_site_count
= call_site_count
;
17555 call_site_count
= -1;
17556 old_tail_call_site_count
= tail_call_site_count
;
17557 tail_call_site_count
= -1;
17559 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17560 we don't get confused by DECL_ABSTRACT. */
17561 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17563 context
= decl_class_context (decl
);
17565 gen_type_die_for_member
17566 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
17569 /* Pretend we've just finished compiling this function. */
17570 save_fn
= current_function_decl
;
17571 current_function_decl
= decl
;
17573 was_abstract
= DECL_ABSTRACT (decl
);
17574 set_decl_abstract_flags (decl
, 1);
17575 dwarf2out_decl (decl
);
17576 if (! was_abstract
)
17577 set_decl_abstract_flags (decl
, 0);
17579 current_function_decl
= save_fn
;
17580 decl_loc_table
= old_decl_loc_table
;
17581 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
17582 call_arg_locations
= old_call_arg_locations
;
17583 call_site_count
= old_call_site_count
;
17584 tail_call_site_count
= old_tail_call_site_count
;
17587 /* Helper function of premark_used_types() which gets called through
17590 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17591 marked as unused by prune_unused_types. */
17594 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
17599 type
= (tree
) *slot
;
17600 die
= lookup_type_die (type
);
17602 die
->die_perennial_p
= 1;
17606 /* Helper function of premark_types_used_by_global_vars which gets called
17607 through htab_traverse.
17609 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17610 marked as unused by prune_unused_types. The DIE of the type is marked
17611 only if the global variable using the type will actually be emitted. */
17614 premark_types_used_by_global_vars_helper (void **slot
,
17615 void *data ATTRIBUTE_UNUSED
)
17617 struct types_used_by_vars_entry
*entry
;
17620 entry
= (struct types_used_by_vars_entry
*) *slot
;
17621 gcc_assert (entry
->type
!= NULL
17622 && entry
->var_decl
!= NULL
);
17623 die
= lookup_type_die (entry
->type
);
17626 /* Ask cgraph if the global variable really is to be emitted.
17627 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17628 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
17629 if (node
&& node
->analyzed
)
17631 die
->die_perennial_p
= 1;
17632 /* Keep the parent DIEs as well. */
17633 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
17634 die
->die_perennial_p
= 1;
17640 /* Mark all members of used_types_hash as perennial. */
17643 premark_used_types (struct function
*fun
)
17645 if (fun
&& fun
->used_types_hash
)
17646 htab_traverse (fun
->used_types_hash
, premark_used_types_helper
, NULL
);
17649 /* Mark all members of types_used_by_vars_entry as perennial. */
17652 premark_types_used_by_global_vars (void)
17654 if (types_used_by_vars_hash
)
17655 htab_traverse (types_used_by_vars_hash
,
17656 premark_types_used_by_global_vars_helper
, NULL
);
17659 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17660 for CA_LOC call arg loc node. */
17663 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
17664 struct call_arg_loc_node
*ca_loc
)
17666 dw_die_ref stmt_die
= NULL
, die
;
17667 tree block
= ca_loc
->block
;
17670 && block
!= DECL_INITIAL (decl
)
17671 && TREE_CODE (block
) == BLOCK
)
17673 if (block_map
.length () > BLOCK_NUMBER (block
))
17674 stmt_die
= block_map
[BLOCK_NUMBER (block
)];
17677 block
= BLOCK_SUPERCONTEXT (block
);
17679 if (stmt_die
== NULL
)
17680 stmt_die
= subr_die
;
17681 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
17682 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
17683 if (ca_loc
->tail_call_p
)
17684 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
17685 if (ca_loc
->symbol_ref
)
17687 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
17689 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
17691 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
17696 /* Generate a DIE to represent a declared function (either file-scope or
17700 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
17702 tree origin
= decl_ultimate_origin (decl
);
17703 dw_die_ref subr_die
;
17705 dw_die_ref old_die
= lookup_decl_die (decl
);
17706 int declaration
= (current_function_decl
!= decl
17707 || class_or_namespace_scope_p (context_die
));
17709 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
17711 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17712 started to generate the abstract instance of an inline, decided to output
17713 its containing class, and proceeded to emit the declaration of the inline
17714 from the member list for the class. If so, DECLARATION takes priority;
17715 we'll get back to the abstract instance when done with the class. */
17717 /* The class-scope declaration DIE must be the primary DIE. */
17718 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
17721 gcc_assert (!old_die
);
17724 /* Now that the C++ front end lazily declares artificial member fns, we
17725 might need to retrofit the declaration into its class. */
17726 if (!declaration
&& !origin
&& !old_die
17727 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
17728 && !class_or_namespace_scope_p (context_die
)
17729 && debug_info_level
> DINFO_LEVEL_TERSE
)
17730 old_die
= force_decl_die (decl
);
17732 if (origin
!= NULL
)
17734 gcc_assert (!declaration
|| local_scope_p (context_die
));
17736 /* Fixup die_parent for the abstract instance of a nested
17737 inline function. */
17738 if (old_die
&& old_die
->die_parent
== NULL
)
17739 add_child_die (context_die
, old_die
);
17741 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17742 add_abstract_origin_attribute (subr_die
, origin
);
17743 /* This is where the actual code for a cloned function is.
17744 Let's emit linkage name attribute for it. This helps
17745 debuggers to e.g, set breakpoints into
17746 constructors/destructors when the user asks "break
17748 add_linkage_name (subr_die
, decl
);
17752 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17753 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17755 if (!get_AT_flag (old_die
, DW_AT_declaration
)
17756 /* We can have a normal definition following an inline one in the
17757 case of redefinition of GNU C extern inlines.
17758 It seems reasonable to use AT_specification in this case. */
17759 && !get_AT (old_die
, DW_AT_inline
))
17761 /* Detect and ignore this case, where we are trying to output
17762 something we have already output. */
17766 /* If the definition comes from the same place as the declaration,
17767 maybe use the old DIE. We always want the DIE for this function
17768 that has the *_pc attributes to be under comp_unit_die so the
17769 debugger can find it. We also need to do this for abstract
17770 instances of inlines, since the spec requires the out-of-line copy
17771 to have the same parent. For local class methods, this doesn't
17772 apply; we just use the old DIE. */
17773 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
17774 && (DECL_ARTIFICIAL (decl
)
17775 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
17776 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
17777 == (unsigned) s
.line
))))
17779 subr_die
= old_die
;
17781 /* Clear out the declaration attribute and the formal parameters.
17782 Do not remove all children, because it is possible that this
17783 declaration die was forced using force_decl_die(). In such
17784 cases die that forced declaration die (e.g. TAG_imported_module)
17785 is one of the children that we do not want to remove. */
17786 remove_AT (subr_die
, DW_AT_declaration
);
17787 remove_AT (subr_die
, DW_AT_object_pointer
);
17788 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
17792 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17793 add_AT_specification (subr_die
, old_die
);
17794 add_pubname (decl
, subr_die
);
17795 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17796 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
17797 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17798 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
17803 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17805 if (TREE_PUBLIC (decl
))
17806 add_AT_flag (subr_die
, DW_AT_external
, 1);
17808 add_name_and_src_coords_attributes (subr_die
, decl
);
17809 add_pubname (decl
, subr_die
);
17810 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17812 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
17813 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
17814 0, 0, context_die
);
17817 add_pure_or_virtual_attribute (subr_die
, decl
);
17818 if (DECL_ARTIFICIAL (decl
))
17819 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17821 add_accessibility_attribute (subr_die
, decl
);
17826 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17828 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
17830 /* If this is an explicit function declaration then generate
17831 a DW_AT_explicit attribute. */
17832 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
17833 && (dwarf_version
>= 3 || !dwarf_strict
))
17834 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
17836 /* The first time we see a member function, it is in the context of
17837 the class to which it belongs. We make sure of this by emitting
17838 the class first. The next time is the definition, which is
17839 handled above. The two may come from the same source text.
17841 Note that force_decl_die() forces function declaration die. It is
17842 later reused to represent definition. */
17843 equate_decl_number_to_die (decl
, subr_die
);
17846 else if (DECL_ABSTRACT (decl
))
17848 if (DECL_DECLARED_INLINE_P (decl
))
17850 if (cgraph_function_possibly_inlined_p (decl
))
17851 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
17853 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
17857 if (cgraph_function_possibly_inlined_p (decl
))
17858 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
17860 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
17863 if (DECL_DECLARED_INLINE_P (decl
)
17864 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
17865 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17867 equate_decl_number_to_die (decl
, subr_die
);
17869 else if (!DECL_EXTERNAL (decl
))
17871 HOST_WIDE_INT cfa_fb_offset
;
17872 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
17874 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17875 equate_decl_number_to_die (decl
, subr_die
);
17877 gcc_checking_assert (fun
);
17878 if (!flag_reorder_blocks_and_partition
)
17880 dw_fde_ref fde
= fun
->fde
;
17881 if (fde
->dw_fde_begin
)
17883 /* We have already generated the labels. */
17884 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
17885 fde
->dw_fde_end
, false);
17889 /* Create start/end labels and add the range. */
17890 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
17891 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
17892 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
17893 FUNC_LABEL_ID (cfun
));
17894 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
17895 FUNC_LABEL_ID (cfun
));
17896 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
17900 #if VMS_DEBUGGING_INFO
17901 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17902 Section 2.3 Prologue and Epilogue Attributes:
17903 When a breakpoint is set on entry to a function, it is generally
17904 desirable for execution to be suspended, not on the very first
17905 instruction of the function, but rather at a point after the
17906 function's frame has been set up, after any language defined local
17907 declaration processing has been completed, and before execution of
17908 the first statement of the function begins. Debuggers generally
17909 cannot properly determine where this point is. Similarly for a
17910 breakpoint set on exit from a function. The prologue and epilogue
17911 attributes allow a compiler to communicate the location(s) to use. */
17914 if (fde
->dw_fde_vms_end_prologue
)
17915 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
17916 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
17918 if (fde
->dw_fde_vms_begin_epilogue
)
17919 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
17920 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
17927 /* Generate pubnames entries for the split function code ranges. */
17928 dw_fde_ref fde
= fun
->fde
;
17930 if (fde
->dw_fde_second_begin
)
17932 if (dwarf_version
>= 3 || !dwarf_strict
)
17934 /* We should use ranges for non-contiguous code section
17935 addresses. Use the actual code range for the initial
17936 section, since the HOT/COLD labels might precede an
17937 alignment offset. */
17938 bool range_list_added
= false;
17939 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
17940 fde
->dw_fde_end
, &range_list_added
,
17942 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
17943 fde
->dw_fde_second_end
,
17944 &range_list_added
, false);
17945 if (range_list_added
)
17950 /* There is no real support in DW2 for this .. so we make
17951 a work-around. First, emit the pub name for the segment
17952 containing the function label. Then make and emit a
17953 simplified subprogram DIE for the second segment with the
17954 name pre-fixed by __hot/cold_sect_of_. We use the same
17955 linkage name for the second die so that gdb will find both
17956 sections when given "b foo". */
17957 const char *name
= NULL
;
17958 tree decl_name
= DECL_NAME (decl
);
17959 dw_die_ref seg_die
;
17961 /* Do the 'primary' section. */
17962 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
17963 fde
->dw_fde_end
, false);
17965 /* Build a minimal DIE for the secondary section. */
17966 seg_die
= new_die (DW_TAG_subprogram
,
17967 subr_die
->die_parent
, decl
);
17969 if (TREE_PUBLIC (decl
))
17970 add_AT_flag (seg_die
, DW_AT_external
, 1);
17972 if (decl_name
!= NULL
17973 && IDENTIFIER_POINTER (decl_name
) != NULL
)
17975 name
= dwarf2_name (decl
, 1);
17976 if (! DECL_ARTIFICIAL (decl
))
17977 add_src_coords_attributes (seg_die
, decl
);
17979 add_linkage_name (seg_die
, decl
);
17981 gcc_assert (name
!= NULL
);
17982 add_pure_or_virtual_attribute (seg_die
, decl
);
17983 if (DECL_ARTIFICIAL (decl
))
17984 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
17986 name
= concat ("__second_sect_of_", name
, NULL
);
17987 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
17988 fde
->dw_fde_second_end
, false);
17989 add_name_attribute (seg_die
, name
);
17990 if (want_pubnames ())
17991 add_pubname_string (name
, seg_die
);
17995 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
17999 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
18001 /* We define the "frame base" as the function's CFA. This is more
18002 convenient for several reasons: (1) It's stable across the prologue
18003 and epilogue, which makes it better than just a frame pointer,
18004 (2) With dwarf3, there exists a one-byte encoding that allows us
18005 to reference the .debug_frame data by proxy, but failing that,
18006 (3) We can at least reuse the code inspection and interpretation
18007 code that determines the CFA position at various points in the
18009 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
18011 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
18012 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
18016 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
18017 if (list
->dw_loc_next
)
18018 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
18020 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
18023 /* Compute a displacement from the "steady-state frame pointer" to
18024 the CFA. The former is what all stack slots and argument slots
18025 will reference in the rtl; the latter is what we've told the
18026 debugger about. We'll need to adjust all frame_base references
18027 by this displacement. */
18028 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
18030 if (fun
->static_chain_decl
)
18031 add_AT_location_description (subr_die
, DW_AT_static_link
,
18032 loc_list_from_tree (fun
->static_chain_decl
, 2));
18035 /* Generate child dies for template paramaters. */
18036 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18037 gen_generic_params_dies (decl
);
18039 /* Now output descriptions of the arguments for this function. This gets
18040 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
18041 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
18042 `...' at the end of the formal parameter list. In order to find out if
18043 there was a trailing ellipsis or not, we must instead look at the type
18044 associated with the FUNCTION_DECL. This will be a node of type
18045 FUNCTION_TYPE. If the chain of type nodes hanging off of this
18046 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
18047 an ellipsis at the end. */
18049 /* In the case where we are describing a mere function declaration, all we
18050 need to do here (and all we *can* do here) is to describe the *types* of
18051 its formal parameters. */
18052 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
18054 else if (declaration
)
18055 gen_formal_types_die (decl
, subr_die
);
18058 /* Generate DIEs to represent all known formal parameters. */
18059 tree parm
= DECL_ARGUMENTS (decl
);
18060 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
18061 tree generic_decl_parm
= generic_decl
18062 ? DECL_ARGUMENTS (generic_decl
)
18065 /* Now we want to walk the list of parameters of the function and
18066 emit their relevant DIEs.
18068 We consider the case of DECL being an instance of a generic function
18069 as well as it being a normal function.
18071 If DECL is an instance of a generic function we walk the
18072 parameters of the generic function declaration _and_ the parameters of
18073 DECL itself. This is useful because we want to emit specific DIEs for
18074 function parameter packs and those are declared as part of the
18075 generic function declaration. In that particular case,
18076 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
18077 That DIE has children DIEs representing the set of arguments
18078 of the pack. Note that the set of pack arguments can be empty.
18079 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
18082 Otherwise, we just consider the parameters of DECL. */
18083 while (generic_decl_parm
|| parm
)
18085 if (generic_decl_parm
18086 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
18087 gen_formal_parameter_pack_die (generic_decl_parm
,
18092 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
18094 if (parm
== DECL_ARGUMENTS (decl
)
18095 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
18097 && (dwarf_version
>= 3 || !dwarf_strict
))
18098 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
18100 parm
= DECL_CHAIN (parm
);
18103 if (generic_decl_parm
)
18104 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
18107 /* Decide whether we need an unspecified_parameters DIE at the end.
18108 There are 2 more cases to do this for: 1) the ansi ... declaration -
18109 this is detectable when the end of the arg list is not a
18110 void_type_node 2) an unprototyped function declaration (not a
18111 definition). This just means that we have no info about the
18112 parameters at all. */
18113 if (prototype_p (TREE_TYPE (decl
)))
18115 /* This is the prototyped case, check for.... */
18116 if (stdarg_p (TREE_TYPE (decl
)))
18117 gen_unspecified_parameters_die (decl
, subr_die
);
18119 else if (DECL_INITIAL (decl
) == NULL_TREE
)
18120 gen_unspecified_parameters_die (decl
, subr_die
);
18123 /* Output Dwarf info for all of the stuff within the body of the function
18124 (if it has one - it may be just a declaration). */
18125 outer_scope
= DECL_INITIAL (decl
);
18127 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
18128 a function. This BLOCK actually represents the outermost binding contour
18129 for the function, i.e. the contour in which the function's formal
18130 parameters and labels get declared. Curiously, it appears that the front
18131 end doesn't actually put the PARM_DECL nodes for the current function onto
18132 the BLOCK_VARS list for this outer scope, but are strung off of the
18133 DECL_ARGUMENTS list for the function instead.
18135 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
18136 the LABEL_DECL nodes for the function however, and we output DWARF info
18137 for those in decls_for_scope. Just within the `outer_scope' there will be
18138 a BLOCK node representing the function's outermost pair of curly braces,
18139 and any blocks used for the base and member initializers of a C++
18140 constructor function. */
18141 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
18143 int call_site_note_count
= 0;
18144 int tail_call_site_note_count
= 0;
18146 /* Emit a DW_TAG_variable DIE for a named return value. */
18147 if (DECL_NAME (DECL_RESULT (decl
)))
18148 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
18150 current_function_has_inlines
= 0;
18151 decls_for_scope (outer_scope
, subr_die
, 0);
18153 if (call_arg_locations
&& !dwarf_strict
)
18155 struct call_arg_loc_node
*ca_loc
;
18156 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
18158 dw_die_ref die
= NULL
;
18159 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
18162 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
18163 arg
; arg
= next_arg
)
18165 dw_loc_descr_ref reg
, val
;
18166 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
18167 dw_die_ref cdie
, tdie
= NULL
;
18169 next_arg
= XEXP (arg
, 1);
18170 if (REG_P (XEXP (XEXP (arg
, 0), 0))
18172 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
18173 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
18174 && REGNO (XEXP (XEXP (arg
, 0), 0))
18175 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
18176 next_arg
= XEXP (next_arg
, 1);
18177 if (mode
== VOIDmode
)
18179 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
18180 if (mode
== VOIDmode
)
18181 mode
= GET_MODE (XEXP (arg
, 0));
18183 if (mode
== VOIDmode
|| mode
== BLKmode
)
18185 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
18187 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18188 tloc
= XEXP (XEXP (arg
, 0), 1);
18191 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
18192 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
18194 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18195 tlocc
= XEXP (XEXP (arg
, 0), 1);
18199 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
18200 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
18201 VAR_INIT_STATUS_INITIALIZED
);
18202 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
18204 rtx mem
= XEXP (XEXP (arg
, 0), 0);
18205 reg
= mem_loc_descriptor (XEXP (mem
, 0),
18206 get_address_mode (mem
),
18208 VAR_INIT_STATUS_INITIALIZED
);
18210 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
18211 == DEBUG_PARAMETER_REF
)
18214 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
18215 tdie
= lookup_decl_die (tdecl
);
18222 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
18223 != DEBUG_PARAMETER_REF
)
18225 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
18227 VAR_INIT_STATUS_INITIALIZED
);
18231 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18232 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
18235 add_AT_loc (cdie
, DW_AT_location
, reg
);
18236 else if (tdie
!= NULL
)
18237 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
18238 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
18239 if (next_arg
!= XEXP (arg
, 1))
18241 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
18242 if (mode
== VOIDmode
)
18243 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
18244 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
18247 VAR_INIT_STATUS_INITIALIZED
);
18249 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
18253 && (ca_loc
->symbol_ref
|| tloc
))
18254 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18255 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
18257 dw_loc_descr_ref tval
= NULL
;
18259 if (tloc
!= NULL_RTX
)
18260 tval
= mem_loc_descriptor (tloc
,
18261 GET_MODE (tloc
) == VOIDmode
18262 ? Pmode
: GET_MODE (tloc
),
18264 VAR_INIT_STATUS_INITIALIZED
);
18266 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
18267 else if (tlocc
!= NULL_RTX
)
18269 tval
= mem_loc_descriptor (tlocc
,
18270 GET_MODE (tlocc
) == VOIDmode
18271 ? Pmode
: GET_MODE (tlocc
),
18273 VAR_INIT_STATUS_INITIALIZED
);
18275 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
18281 call_site_note_count
++;
18282 if (ca_loc
->tail_call_p
)
18283 tail_call_site_note_count
++;
18287 call_arg_locations
= NULL
;
18288 call_arg_loc_last
= NULL
;
18289 if (tail_call_site_count
>= 0
18290 && tail_call_site_count
== tail_call_site_note_count
18293 if (call_site_count
>= 0
18294 && call_site_count
== call_site_note_count
)
18295 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
18297 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
18299 call_site_count
= -1;
18300 tail_call_site_count
= -1;
18302 /* Add the calling convention attribute if requested. */
18303 add_calling_convention_attribute (subr_die
, decl
);
18307 /* Returns a hash value for X (which really is a die_struct). */
18310 common_block_die_table_hash (const void *x
)
18312 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18313 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
18316 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18317 as decl_id and die_parent of die_struct Y. */
18320 common_block_die_table_eq (const void *x
, const void *y
)
18322 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18323 const_dw_die_ref e
= (const_dw_die_ref
) y
;
18324 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
18327 /* Generate a DIE to represent a declared data object.
18328 Either DECL or ORIGIN must be non-null. */
18331 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
18333 HOST_WIDE_INT off
= 0;
18335 tree decl_or_origin
= decl
? decl
: origin
;
18336 tree ultimate_origin
;
18337 dw_die_ref var_die
;
18338 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
18339 dw_die_ref origin_die
;
18340 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
18341 || class_or_namespace_scope_p (context_die
));
18342 bool specialization_p
= false;
18344 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
18345 if (decl
|| ultimate_origin
)
18346 origin
= ultimate_origin
;
18347 com_decl
= fortran_common (decl_or_origin
, &off
);
18349 /* Symbol in common gets emitted as a child of the common block, in the form
18350 of a data member. */
18353 dw_die_ref com_die
;
18354 dw_loc_list_ref loc
;
18355 die_node com_die_arg
;
18357 var_die
= lookup_decl_die (decl_or_origin
);
18360 if (get_AT (var_die
, DW_AT_location
) == NULL
)
18362 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
18367 /* Optimize the common case. */
18368 if (single_element_loc_list_p (loc
)
18369 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18370 && loc
->expr
->dw_loc_next
== NULL
18371 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
18374 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18375 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18376 = plus_constant (GET_MODE (x
), x
, off
);
18379 loc_list_plus_const (loc
, off
);
18381 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18382 remove_AT (var_die
, DW_AT_declaration
);
18388 if (common_block_die_table
== NULL
)
18389 common_block_die_table
18390 = htab_create_ggc (10, common_block_die_table_hash
,
18391 common_block_die_table_eq
, NULL
);
18393 com_die_arg
.decl_id
= DECL_UID (com_decl
);
18394 com_die_arg
.die_parent
= context_die
;
18395 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
18396 loc
= loc_list_from_tree (com_decl
, 2);
18397 if (com_die
== NULL
)
18400 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
18403 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
18404 add_name_and_src_coords_attributes (com_die
, com_decl
);
18407 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18408 /* Avoid sharing the same loc descriptor between
18409 DW_TAG_common_block and DW_TAG_variable. */
18410 loc
= loc_list_from_tree (com_decl
, 2);
18412 else if (DECL_EXTERNAL (decl
))
18413 add_AT_flag (com_die
, DW_AT_declaration
, 1);
18414 if (want_pubnames ())
18415 add_pubname_string (cnam
, com_die
); /* ??? needed? */
18416 com_die
->decl_id
= DECL_UID (com_decl
);
18417 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
18418 *slot
= (void *) com_die
;
18420 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
18422 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18423 loc
= loc_list_from_tree (com_decl
, 2);
18424 remove_AT (com_die
, DW_AT_declaration
);
18426 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
18427 add_name_and_src_coords_attributes (var_die
, decl
);
18428 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
18429 TREE_THIS_VOLATILE (decl
), context_die
);
18430 add_AT_flag (var_die
, DW_AT_external
, 1);
18435 /* Optimize the common case. */
18436 if (single_element_loc_list_p (loc
)
18437 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18438 && loc
->expr
->dw_loc_next
== NULL
18439 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
18441 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18442 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18443 = plus_constant (GET_MODE (x
), x
, off
);
18446 loc_list_plus_const (loc
, off
);
18448 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18450 else if (DECL_EXTERNAL (decl
))
18451 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18452 equate_decl_number_to_die (decl
, var_die
);
18456 /* If the compiler emitted a definition for the DECL declaration
18457 and if we already emitted a DIE for it, don't emit a second
18458 DIE for it again. Allow re-declarations of DECLs that are
18459 inside functions, though. */
18460 if (old_die
&& declaration
&& !local_scope_p (context_die
))
18463 /* For static data members, the declaration in the class is supposed
18464 to have DW_TAG_member tag; the specification should still be
18465 DW_TAG_variable referencing the DW_TAG_member DIE. */
18466 if (declaration
&& class_scope_p (context_die
))
18467 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
18469 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
18472 if (origin
!= NULL
)
18473 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
18475 /* Loop unrolling can create multiple blocks that refer to the same
18476 static variable, so we must test for the DW_AT_declaration flag.
18478 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18479 copy decls and set the DECL_ABSTRACT flag on them instead of
18482 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18484 ??? The declare_in_namespace support causes us to get two DIEs for one
18485 variable, both of which are declarations. We want to avoid considering
18486 one to be a specification, so we must test that this DIE is not a
18488 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
18489 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
18491 /* This is a definition of a C++ class level static. */
18492 add_AT_specification (var_die
, old_die
);
18493 specialization_p
= true;
18494 if (DECL_NAME (decl
))
18496 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18497 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18499 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18500 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
18502 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18503 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
18505 if (old_die
->die_tag
== DW_TAG_member
)
18506 add_linkage_name (var_die
, decl
);
18510 add_name_and_src_coords_attributes (var_die
, decl
);
18512 if ((origin
== NULL
&& !specialization_p
)
18514 && !DECL_ABSTRACT (decl_or_origin
)
18515 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
18516 decl_function_context
18517 (decl_or_origin
))))
18519 tree type
= TREE_TYPE (decl_or_origin
);
18521 if (decl_by_reference_p (decl_or_origin
))
18522 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
18524 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
18525 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
18528 if (origin
== NULL
&& !specialization_p
)
18530 if (TREE_PUBLIC (decl
))
18531 add_AT_flag (var_die
, DW_AT_external
, 1);
18533 if (DECL_ARTIFICIAL (decl
))
18534 add_AT_flag (var_die
, DW_AT_artificial
, 1);
18536 add_accessibility_attribute (var_die
, decl
);
18540 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18542 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
18543 equate_decl_number_to_die (decl
, var_die
);
18546 && (! DECL_ABSTRACT (decl_or_origin
)
18547 /* Local static vars are shared between all clones/inlines,
18548 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18550 || (TREE_CODE (decl_or_origin
) == VAR_DECL
18551 && TREE_STATIC (decl_or_origin
)
18552 && DECL_RTL_SET_P (decl_or_origin
)))
18553 /* When abstract origin already has DW_AT_location attribute, no need
18554 to add it again. */
18555 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
18557 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
18558 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
18559 defer_location (decl_or_origin
, var_die
);
18561 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
18562 decl
== NULL
, DW_AT_location
);
18563 add_pubname (decl_or_origin
, var_die
);
18566 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
18569 /* Generate a DIE to represent a named constant. */
18572 gen_const_die (tree decl
, dw_die_ref context_die
)
18574 dw_die_ref const_die
;
18575 tree type
= TREE_TYPE (decl
);
18577 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
18578 add_name_and_src_coords_attributes (const_die
, decl
);
18579 add_type_attribute (const_die
, type
, 1, 0, context_die
);
18580 if (TREE_PUBLIC (decl
))
18581 add_AT_flag (const_die
, DW_AT_external
, 1);
18582 if (DECL_ARTIFICIAL (decl
))
18583 add_AT_flag (const_die
, DW_AT_artificial
, 1);
18584 tree_add_const_value_attribute_for_decl (const_die
, decl
);
18587 /* Generate a DIE to represent a label identifier. */
18590 gen_label_die (tree decl
, dw_die_ref context_die
)
18592 tree origin
= decl_ultimate_origin (decl
);
18593 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
18595 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18597 if (origin
!= NULL
)
18598 add_abstract_origin_attribute (lbl_die
, origin
);
18600 add_name_and_src_coords_attributes (lbl_die
, decl
);
18602 if (DECL_ABSTRACT (decl
))
18603 equate_decl_number_to_die (decl
, lbl_die
);
18606 insn
= DECL_RTL_IF_SET (decl
);
18608 /* Deleted labels are programmer specified labels which have been
18609 eliminated because of various optimizations. We still emit them
18610 here so that it is possible to put breakpoints on them. */
18614 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
18616 /* When optimization is enabled (via -O) some parts of the compiler
18617 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18618 represent source-level labels which were explicitly declared by
18619 the user. This really shouldn't be happening though, so catch
18620 it if it ever does happen. */
18621 gcc_assert (!INSN_DELETED_P (insn
));
18623 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
18624 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18628 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
18629 && CODE_LABEL_NUMBER (insn
) != -1)
18631 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
18632 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18637 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18638 attributes to the DIE for a block STMT, to describe where the inlined
18639 function was called from. This is similar to add_src_coords_attributes. */
18642 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
18644 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
18646 if (dwarf_version
>= 3 || !dwarf_strict
)
18648 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
18649 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
18654 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18655 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18658 add_high_low_attributes (tree stmt
, dw_die_ref die
)
18660 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18662 if (BLOCK_FRAGMENT_CHAIN (stmt
)
18663 && (dwarf_version
>= 3 || !dwarf_strict
))
18665 tree chain
, superblock
= NULL_TREE
;
18667 dw_attr_ref attr
= NULL
;
18669 if (inlined_function_outer_scope_p (stmt
))
18671 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18672 BLOCK_NUMBER (stmt
));
18673 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
18676 /* Optimize duplicate .debug_ranges lists or even tails of
18677 lists. If this BLOCK has same ranges as its supercontext,
18678 lookup DW_AT_ranges attribute in the supercontext (and
18679 recursively so), verify that the ranges_table contains the
18680 right values and use it instead of adding a new .debug_range. */
18681 for (chain
= stmt
, pdie
= die
;
18682 BLOCK_SAME_RANGE (chain
);
18683 chain
= BLOCK_SUPERCONTEXT (chain
))
18685 dw_attr_ref new_attr
;
18687 pdie
= pdie
->die_parent
;
18690 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
18692 new_attr
= get_AT (pdie
, DW_AT_ranges
);
18693 if (new_attr
== NULL
18694 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
18697 superblock
= BLOCK_SUPERCONTEXT (chain
);
18700 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
18701 / 2 / DWARF2_ADDR_SIZE
].num
18702 == BLOCK_NUMBER (superblock
))
18703 && BLOCK_FRAGMENT_CHAIN (superblock
))
18705 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
18706 / 2 / DWARF2_ADDR_SIZE
;
18707 unsigned long supercnt
= 0, thiscnt
= 0;
18708 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
18709 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18712 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
18713 == BLOCK_NUMBER (chain
));
18715 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
18716 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18717 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18719 gcc_assert (supercnt
>= thiscnt
);
18720 add_AT_range_list (die
, DW_AT_ranges
,
18721 ((off
+ supercnt
- thiscnt
)
18722 * 2 * DWARF2_ADDR_SIZE
),
18727 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
18729 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18732 add_ranges (chain
);
18733 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
18740 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18741 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18742 BLOCK_NUMBER (stmt
));
18743 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
18744 BLOCK_NUMBER (stmt
));
18745 add_AT_low_high_pc (die
, label
, label_high
, false);
18749 /* Generate a DIE for a lexical block. */
18752 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
18754 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
18756 if (call_arg_locations
)
18758 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18759 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18760 block_map
[BLOCK_NUMBER (stmt
)] = stmt_die
;
18763 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
18764 add_high_low_attributes (stmt
, stmt_die
);
18766 decls_for_scope (stmt
, stmt_die
, depth
);
18769 /* Generate a DIE for an inlined subprogram. */
18772 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
18776 /* The instance of function that is effectively being inlined shall not
18778 gcc_assert (! BLOCK_ABSTRACT (stmt
));
18780 decl
= block_ultimate_origin (stmt
);
18782 /* Emit info for the abstract instance first, if we haven't yet. We
18783 must emit this even if the block is abstract, otherwise when we
18784 emit the block below (or elsewhere), we may end up trying to emit
18785 a die whose origin die hasn't been emitted, and crashing. */
18786 dwarf2out_abstract_function (decl
);
18788 if (! BLOCK_ABSTRACT (stmt
))
18790 dw_die_ref subr_die
18791 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
18793 if (call_arg_locations
)
18795 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18796 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18797 block_map
[BLOCK_NUMBER (stmt
)] = subr_die
;
18799 add_abstract_origin_attribute (subr_die
, decl
);
18800 if (TREE_ASM_WRITTEN (stmt
))
18801 add_high_low_attributes (stmt
, subr_die
);
18802 add_call_src_coords_attributes (stmt
, subr_die
);
18804 decls_for_scope (stmt
, subr_die
, depth
);
18805 current_function_has_inlines
= 1;
18809 /* Generate a DIE for a field in a record, or structure. */
18812 gen_field_die (tree decl
, dw_die_ref context_die
)
18814 dw_die_ref decl_die
;
18816 if (TREE_TYPE (decl
) == error_mark_node
)
18819 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
18820 add_name_and_src_coords_attributes (decl_die
, decl
);
18821 add_type_attribute (decl_die
, member_declared_type (decl
),
18822 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
18825 if (DECL_BIT_FIELD_TYPE (decl
))
18827 add_byte_size_attribute (decl_die
, decl
);
18828 add_bit_size_attribute (decl_die
, decl
);
18829 add_bit_offset_attribute (decl_die
, decl
);
18832 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
18833 add_data_member_location_attribute (decl_die
, decl
);
18835 if (DECL_ARTIFICIAL (decl
))
18836 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
18838 add_accessibility_attribute (decl_die
, decl
);
18840 /* Equate decl number to die, so that we can look up this decl later on. */
18841 equate_decl_number_to_die (decl
, decl_die
);
18845 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18846 Use modified_type_die instead.
18847 We keep this code here just in case these types of DIEs may be needed to
18848 represent certain things in other languages (e.g. Pascal) someday. */
18851 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
18854 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
18856 equate_type_number_to_die (type
, ptr_die
);
18857 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18858 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18861 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18862 Use modified_type_die instead.
18863 We keep this code here just in case these types of DIEs may be needed to
18864 represent certain things in other languages (e.g. Pascal) someday. */
18867 gen_reference_type_die (tree type
, dw_die_ref context_die
)
18869 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
18871 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
18872 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
18874 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
18876 equate_type_number_to_die (type
, ref_die
);
18877 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
18878 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18882 /* Generate a DIE for a pointer to a member type. */
18885 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
18888 = new_die (DW_TAG_ptr_to_member_type
,
18889 scope_die_for (type
, context_die
), type
);
18891 equate_type_number_to_die (type
, ptr_die
);
18892 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
18893 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
18894 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18897 typedef const char *dchar_p
; /* For DEF_VEC_P. */
18899 static char *producer_string
;
18901 /* Return a heap allocated producer string including command line options
18902 if -grecord-gcc-switches. */
18905 gen_producer_string (void)
18908 vec
<dchar_p
> switches
= vNULL
;
18909 const char *language_string
= lang_hooks
.name
;
18910 char *producer
, *tail
;
18912 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
18913 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
18915 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
18916 switch (save_decoded_options
[j
].opt_index
)
18923 case OPT_auxbase_strip
:
18932 case OPT_SPECIAL_unknown
:
18933 case OPT_SPECIAL_ignore
:
18934 case OPT_SPECIAL_program_name
:
18935 case OPT_SPECIAL_input_file
:
18936 case OPT_grecord_gcc_switches
:
18937 case OPT_gno_record_gcc_switches
:
18938 case OPT__output_pch_
:
18939 case OPT_fdiagnostics_show_location_
:
18940 case OPT_fdiagnostics_show_option
:
18941 case OPT_fdiagnostics_show_caret
:
18942 case OPT_fverbose_asm
:
18944 case OPT__sysroot_
:
18946 case OPT_nostdinc__
:
18947 /* Ignore these. */
18950 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
18951 & CL_NO_DWARF_RECORD
)
18953 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
18955 switch (save_decoded_options
[j
].canonical_option
[0][1])
18962 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
18969 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
18970 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
18974 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
18976 sprintf (tail
, "%s %s", language_string
, version_string
);
18979 FOR_EACH_VEC_ELT (switches
, j
, p
)
18983 memcpy (tail
+ 1, p
, len
);
18988 switches
.release ();
18992 /* Generate the DIE for the compilation unit. */
18995 gen_compile_unit_die (const char *filename
)
18998 const char *language_string
= lang_hooks
.name
;
19001 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
19005 add_name_attribute (die
, filename
);
19006 /* Don't add cwd for <built-in>. */
19007 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
19008 add_comp_dir_attribute (die
);
19011 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
19013 /* If our producer is LTO try to figure out a common language to use
19014 from the global list of translation units. */
19015 if (strcmp (language_string
, "GNU GIMPLE") == 0)
19019 const char *common_lang
= NULL
;
19021 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
19023 if (!TRANSLATION_UNIT_LANGUAGE (t
))
19026 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
19027 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
19029 else if (strncmp (common_lang
, "GNU C", 5) == 0
19030 && strncmp(TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
19031 /* Mixing C and C++ is ok, use C++ in that case. */
19032 common_lang
= "GNU C++";
19035 /* Fall back to C. */
19036 common_lang
= NULL
;
19042 language_string
= common_lang
;
19045 language
= DW_LANG_C89
;
19046 if (strcmp (language_string
, "GNU C++") == 0)
19047 language
= DW_LANG_C_plus_plus
;
19048 else if (strcmp (language_string
, "GNU F77") == 0)
19049 language
= DW_LANG_Fortran77
;
19050 else if (strcmp (language_string
, "GNU Pascal") == 0)
19051 language
= DW_LANG_Pascal83
;
19052 else if (dwarf_version
>= 3 || !dwarf_strict
)
19054 if (strcmp (language_string
, "GNU Ada") == 0)
19055 language
= DW_LANG_Ada95
;
19056 else if (strcmp (language_string
, "GNU Fortran") == 0)
19057 language
= DW_LANG_Fortran95
;
19058 else if (strcmp (language_string
, "GNU Java") == 0)
19059 language
= DW_LANG_Java
;
19060 else if (strcmp (language_string
, "GNU Objective-C") == 0)
19061 language
= DW_LANG_ObjC
;
19062 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
19063 language
= DW_LANG_ObjC_plus_plus
;
19064 else if (dwarf_version
>= 5 || !dwarf_strict
)
19066 if (strcmp (language_string
, "GNU Go") == 0)
19067 language
= DW_LANG_Go
;
19070 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
19071 else if (strcmp (language_string
, "GNU Fortran") == 0)
19072 language
= DW_LANG_Fortran90
;
19074 add_AT_unsigned (die
, DW_AT_language
, language
);
19078 case DW_LANG_Fortran77
:
19079 case DW_LANG_Fortran90
:
19080 case DW_LANG_Fortran95
:
19081 /* Fortran has case insensitive identifiers and the front-end
19082 lowercases everything. */
19083 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
19086 /* The default DW_ID_case_sensitive doesn't need to be specified. */
19092 /* Generate the DIE for a base class. */
19095 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
19097 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
19099 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
19100 add_data_member_location_attribute (die
, binfo
);
19102 if (BINFO_VIRTUAL_P (binfo
))
19103 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
19105 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19106 children, otherwise the default is DW_ACCESS_public. In DWARF2
19107 the default has always been DW_ACCESS_private. */
19108 if (access
== access_public_node
)
19110 if (dwarf_version
== 2
19111 || context_die
->die_tag
== DW_TAG_class_type
)
19112 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
19114 else if (access
== access_protected_node
)
19115 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19116 else if (dwarf_version
> 2
19117 && context_die
->die_tag
!= DW_TAG_class_type
)
19118 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
19121 /* Generate a DIE for a class member. */
19124 gen_member_die (tree type
, dw_die_ref context_die
)
19127 tree binfo
= TYPE_BINFO (type
);
19130 /* If this is not an incomplete type, output descriptions of each of its
19131 members. Note that as we output the DIEs necessary to represent the
19132 members of this record or union type, we will also be trying to output
19133 DIEs to represent the *types* of those members. However the `type'
19134 function (above) will specifically avoid generating type DIEs for member
19135 types *within* the list of member DIEs for this (containing) type except
19136 for those types (of members) which are explicitly marked as also being
19137 members of this (containing) type themselves. The g++ front- end can
19138 force any given type to be treated as a member of some other (containing)
19139 type by setting the TYPE_CONTEXT of the given (member) type to point to
19140 the TREE node representing the appropriate (containing) type. */
19142 /* First output info about the base classes. */
19145 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
19149 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
19150 gen_inheritance_die (base
,
19151 (accesses
? (*accesses
)[i
] : access_public_node
),
19155 /* Now output info about the data members and type members. */
19156 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
19158 /* If we thought we were generating minimal debug info for TYPE
19159 and then changed our minds, some of the member declarations
19160 may have already been defined. Don't define them again, but
19161 do put them in the right order. */
19163 child
= lookup_decl_die (member
);
19165 splice_child_die (context_die
, child
);
19167 gen_decl_die (member
, NULL
, context_die
);
19170 /* Now output info about the function members (if any). */
19171 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
19173 /* Don't include clones in the member list. */
19174 if (DECL_ABSTRACT_ORIGIN (member
))
19177 child
= lookup_decl_die (member
);
19179 splice_child_die (context_die
, child
);
19181 gen_decl_die (member
, NULL
, context_die
);
19185 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19186 is set, we pretend that the type was never defined, so we only get the
19187 member DIEs needed by later specification DIEs. */
19190 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19191 enum debug_info_usage usage
)
19193 dw_die_ref type_die
= lookup_type_die (type
);
19194 dw_die_ref scope_die
= 0;
19196 int complete
= (TYPE_SIZE (type
)
19197 && (! TYPE_STUB_DECL (type
)
19198 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19199 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19200 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19202 if (type_die
&& ! complete
)
19205 if (TYPE_CONTEXT (type
) != NULL_TREE
19206 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19207 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19210 scope_die
= scope_die_for (type
, context_die
);
19212 /* Generate child dies for template paramaters. */
19213 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19214 schedule_generic_params_dies_gen (type
);
19216 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
19217 /* First occurrence of type or toplevel definition of nested class. */
19219 dw_die_ref old_die
= type_die
;
19221 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19222 ? record_type_tag (type
) : DW_TAG_union_type
,
19224 equate_type_number_to_die (type
, type_die
);
19226 add_AT_specification (type_die
, old_die
);
19228 add_name_attribute (type_die
, type_tag (type
));
19231 remove_AT (type_die
, DW_AT_declaration
);
19233 /* If this type has been completed, then give it a byte_size attribute and
19234 then give a list of members. */
19235 if (complete
&& !ns_decl
)
19237 /* Prevent infinite recursion in cases where the type of some member of
19238 this type is expressed in terms of this type itself. */
19239 TREE_ASM_WRITTEN (type
) = 1;
19240 add_byte_size_attribute (type_die
, type
);
19241 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19243 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19244 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19247 /* If the first reference to this type was as the return type of an
19248 inline function, then it may not have a parent. Fix this now. */
19249 if (type_die
->die_parent
== NULL
)
19250 add_child_die (scope_die
, type_die
);
19252 push_decl_scope (type
);
19253 gen_member_die (type
, type_die
);
19256 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19257 if (TYPE_ARTIFICIAL (type
))
19258 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19260 /* GNU extension: Record what type our vtable lives in. */
19261 if (TYPE_VFIELD (type
))
19263 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19265 gen_type_die (vtype
, context_die
);
19266 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19267 lookup_type_die (vtype
));
19272 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19274 /* We don't need to do this for function-local types. */
19275 if (TYPE_STUB_DECL (type
)
19276 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19277 vec_safe_push (incomplete_types
, type
);
19280 if (get_AT (type_die
, DW_AT_name
))
19281 add_pubtype (type
, type_die
);
19284 /* Generate a DIE for a subroutine _type_. */
19287 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19289 tree return_type
= TREE_TYPE (type
);
19290 dw_die_ref subr_die
19291 = new_die (DW_TAG_subroutine_type
,
19292 scope_die_for (type
, context_die
), type
);
19294 equate_type_number_to_die (type
, subr_die
);
19295 add_prototyped_attribute (subr_die
, type
);
19296 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
19297 gen_formal_types_die (type
, subr_die
);
19299 if (get_AT (subr_die
, DW_AT_name
))
19300 add_pubtype (type
, subr_die
);
19303 /* Generate a DIE for a type definition. */
19306 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19308 dw_die_ref type_die
;
19311 if (TREE_ASM_WRITTEN (decl
))
19314 TREE_ASM_WRITTEN (decl
) = 1;
19315 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19316 origin
= decl_ultimate_origin (decl
);
19317 if (origin
!= NULL
)
19318 add_abstract_origin_attribute (type_die
, origin
);
19323 add_name_and_src_coords_attributes (type_die
, decl
);
19324 if (DECL_ORIGINAL_TYPE (decl
))
19326 type
= DECL_ORIGINAL_TYPE (decl
);
19328 gcc_assert (type
!= TREE_TYPE (decl
));
19329 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19333 type
= TREE_TYPE (decl
);
19335 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19337 /* Here, we are in the case of decl being a typedef naming
19338 an anonymous type, e.g:
19339 typedef struct {...} foo;
19340 In that case TREE_TYPE (decl) is not a typedef variant
19341 type and TYPE_NAME of the anonymous type is set to the
19342 TYPE_DECL of the typedef. This construct is emitted by
19345 TYPE is the anonymous struct named by the typedef
19346 DECL. As we need the DW_AT_type attribute of the
19347 DW_TAG_typedef to point to the DIE of TYPE, let's
19348 generate that DIE right away. add_type_attribute
19349 called below will then pick (via lookup_type_die) that
19350 anonymous struct DIE. */
19351 if (!TREE_ASM_WRITTEN (type
))
19352 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
19354 /* This is a GNU Extension. We are adding a
19355 DW_AT_linkage_name attribute to the DIE of the
19356 anonymous struct TYPE. The value of that attribute
19357 is the name of the typedef decl naming the anonymous
19358 struct. This greatly eases the work of consumers of
19359 this debug info. */
19360 add_linkage_attr (lookup_type_die (type
), decl
);
19364 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
19365 TREE_THIS_VOLATILE (decl
), context_die
);
19367 if (is_naming_typedef_decl (decl
))
19368 /* We want that all subsequent calls to lookup_type_die with
19369 TYPE in argument yield the DW_TAG_typedef we have just
19371 equate_type_number_to_die (type
, type_die
);
19373 add_accessibility_attribute (type_die
, decl
);
19376 if (DECL_ABSTRACT (decl
))
19377 equate_decl_number_to_die (decl
, type_die
);
19379 if (get_AT (type_die
, DW_AT_name
))
19380 add_pubtype (decl
, type_die
);
19383 /* Generate a DIE for a struct, class, enum or union type. */
19386 gen_tagged_type_die (tree type
,
19387 dw_die_ref context_die
,
19388 enum debug_info_usage usage
)
19392 if (type
== NULL_TREE
19393 || !is_tagged_type (type
))
19396 /* If this is a nested type whose containing class hasn't been written
19397 out yet, writing it out will cover this one, too. This does not apply
19398 to instantiations of member class templates; they need to be added to
19399 the containing class as they are generated. FIXME: This hurts the
19400 idea of combining type decls from multiple TUs, since we can't predict
19401 what set of template instantiations we'll get. */
19402 if (TYPE_CONTEXT (type
)
19403 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19404 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
19406 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
19408 if (TREE_ASM_WRITTEN (type
))
19411 /* If that failed, attach ourselves to the stub. */
19412 push_decl_scope (TYPE_CONTEXT (type
));
19413 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
19416 else if (TYPE_CONTEXT (type
) != NULL_TREE
19417 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
19419 /* If this type is local to a function that hasn't been written
19420 out yet, use a NULL context for now; it will be fixed up in
19421 decls_for_scope. */
19422 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
19423 /* A declaration DIE doesn't count; nested types need to go in the
19425 if (context_die
&& is_declaration_die (context_die
))
19426 context_die
= NULL
;
19431 context_die
= declare_in_namespace (type
, context_die
);
19435 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
19437 /* This might have been written out by the call to
19438 declare_in_namespace. */
19439 if (!TREE_ASM_WRITTEN (type
))
19440 gen_enumeration_type_die (type
, context_die
);
19443 gen_struct_or_union_type_die (type
, context_die
, usage
);
19448 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19449 it up if it is ever completed. gen_*_type_die will set it for us
19450 when appropriate. */
19453 /* Generate a type description DIE. */
19456 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
19457 enum debug_info_usage usage
)
19459 struct array_descr_info info
;
19461 if (type
== NULL_TREE
|| type
== error_mark_node
)
19464 if (TYPE_NAME (type
) != NULL_TREE
19465 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19466 && is_redundant_typedef (TYPE_NAME (type
))
19467 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
19468 /* The DECL of this type is a typedef we don't want to emit debug
19469 info for but we want debug info for its underlying typedef.
19470 This can happen for e.g, the injected-class-name of a C++
19472 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
19474 /* If TYPE is a typedef type variant, let's generate debug info
19475 for the parent typedef which TYPE is a type of. */
19476 if (typedef_variant_p (type
))
19478 if (TREE_ASM_WRITTEN (type
))
19481 /* Prevent broken recursion; we can't hand off to the same type. */
19482 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
19484 /* Give typedefs the right scope. */
19485 context_die
= scope_die_for (type
, context_die
);
19487 TREE_ASM_WRITTEN (type
) = 1;
19489 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19493 /* If type is an anonymous tagged type named by a typedef, let's
19494 generate debug info for the typedef. */
19495 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19497 /* Use the DIE of the containing namespace as the parent DIE of
19498 the type description DIE we want to generate. */
19499 if (DECL_CONTEXT (TYPE_NAME (type
))
19500 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
19501 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
19503 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19507 /* If this is an array type with hidden descriptor, handle it first. */
19508 if (!TREE_ASM_WRITTEN (type
)
19509 && lang_hooks
.types
.get_array_descr_info
19510 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
19511 && (dwarf_version
>= 3 || !dwarf_strict
))
19513 gen_descr_array_type_die (type
, &info
, context_die
);
19514 TREE_ASM_WRITTEN (type
) = 1;
19518 /* We are going to output a DIE to represent the unqualified version
19519 of this type (i.e. without any const or volatile qualifiers) so
19520 get the main variant (i.e. the unqualified version) of this type
19521 now. (Vectors are special because the debugging info is in the
19522 cloned type itself). */
19523 if (TREE_CODE (type
) != VECTOR_TYPE
)
19524 type
= type_main_variant (type
);
19526 if (TREE_ASM_WRITTEN (type
))
19529 switch (TREE_CODE (type
))
19535 case REFERENCE_TYPE
:
19536 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19537 ensures that the gen_type_die recursion will terminate even if the
19538 type is recursive. Recursive types are possible in Ada. */
19539 /* ??? We could perhaps do this for all types before the switch
19541 TREE_ASM_WRITTEN (type
) = 1;
19543 /* For these types, all that is required is that we output a DIE (or a
19544 set of DIEs) to represent the "basis" type. */
19545 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19546 DINFO_USAGE_IND_USE
);
19550 /* This code is used for C++ pointer-to-data-member types.
19551 Output a description of the relevant class type. */
19552 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
19553 DINFO_USAGE_IND_USE
);
19555 /* Output a description of the type of the object pointed to. */
19556 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19557 DINFO_USAGE_IND_USE
);
19559 /* Now output a DIE to represent this pointer-to-data-member type
19561 gen_ptr_to_mbr_type_die (type
, context_die
);
19564 case FUNCTION_TYPE
:
19565 /* Force out return type (in case it wasn't forced out already). */
19566 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19567 DINFO_USAGE_DIR_USE
);
19568 gen_subroutine_type_die (type
, context_die
);
19572 /* Force out return type (in case it wasn't forced out already). */
19573 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19574 DINFO_USAGE_DIR_USE
);
19575 gen_subroutine_type_die (type
, context_die
);
19579 gen_array_type_die (type
, context_die
);
19583 gen_array_type_die (type
, context_die
);
19586 case ENUMERAL_TYPE
:
19589 case QUAL_UNION_TYPE
:
19590 gen_tagged_type_die (type
, context_die
, usage
);
19596 case FIXED_POINT_TYPE
:
19599 /* No DIEs needed for fundamental types. */
19604 /* Just use DW_TAG_unspecified_type. */
19606 dw_die_ref type_die
= lookup_type_die (type
);
19607 if (type_die
== NULL
)
19609 tree name
= TYPE_NAME (type
);
19610 if (TREE_CODE (name
) == TYPE_DECL
)
19611 name
= DECL_NAME (name
);
19612 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
19613 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
19614 equate_type_number_to_die (type
, type_die
);
19620 gcc_unreachable ();
19623 TREE_ASM_WRITTEN (type
) = 1;
19627 gen_type_die (tree type
, dw_die_ref context_die
)
19629 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
19632 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19633 things which are local to the given block. */
19636 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19638 int must_output_die
= 0;
19641 /* Ignore blocks that are NULL. */
19642 if (stmt
== NULL_TREE
)
19645 inlined_func
= inlined_function_outer_scope_p (stmt
);
19647 /* If the block is one fragment of a non-contiguous block, do not
19648 process the variables, since they will have been done by the
19649 origin block. Do process subblocks. */
19650 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
19654 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
19655 gen_block_die (sub
, context_die
, depth
+ 1);
19660 /* Determine if we need to output any Dwarf DIEs at all to represent this
19663 /* The outer scopes for inlinings *must* always be represented. We
19664 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19665 must_output_die
= 1;
19668 /* Determine if this block directly contains any "significant"
19669 local declarations which we will need to output DIEs for. */
19670 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19671 /* We are not in terse mode so *any* local declaration counts
19672 as being a "significant" one. */
19673 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
19674 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
19675 && (TREE_USED (stmt
)
19676 || TREE_ASM_WRITTEN (stmt
)
19677 || BLOCK_ABSTRACT (stmt
)));
19678 else if ((TREE_USED (stmt
)
19679 || TREE_ASM_WRITTEN (stmt
)
19680 || BLOCK_ABSTRACT (stmt
))
19681 && !dwarf2out_ignore_block (stmt
))
19682 must_output_die
= 1;
19685 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19686 DIE for any block which contains no significant local declarations at
19687 all. Rather, in such cases we just call `decls_for_scope' so that any
19688 needed Dwarf info for any sub-blocks will get properly generated. Note
19689 that in terse mode, our definition of what constitutes a "significant"
19690 local declaration gets restricted to include only inlined function
19691 instances and local (nested) function definitions. */
19692 if (must_output_die
)
19696 /* If STMT block is abstract, that means we have been called
19697 indirectly from dwarf2out_abstract_function.
19698 That function rightfully marks the descendent blocks (of
19699 the abstract function it is dealing with) as being abstract,
19700 precisely to prevent us from emitting any
19701 DW_TAG_inlined_subroutine DIE as a descendent
19702 of an abstract function instance. So in that case, we should
19703 not call gen_inlined_subroutine_die.
19705 Later though, when cgraph asks dwarf2out to emit info
19706 for the concrete instance of the function decl into which
19707 the concrete instance of STMT got inlined, the later will lead
19708 to the generation of a DW_TAG_inlined_subroutine DIE. */
19709 if (! BLOCK_ABSTRACT (stmt
))
19710 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
19713 gen_lexical_block_die (stmt
, context_die
, depth
);
19716 decls_for_scope (stmt
, context_die
, depth
);
19719 /* Process variable DECL (or variable with origin ORIGIN) within
19720 block STMT and add it to CONTEXT_DIE. */
19722 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
19725 tree decl_or_origin
= decl
? decl
: origin
;
19727 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
19728 die
= lookup_decl_die (decl_or_origin
);
19729 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
19730 && TYPE_DECL_IS_STUB (decl_or_origin
))
19731 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
19735 if (die
!= NULL
&& die
->die_parent
== NULL
)
19736 add_child_die (context_die
, die
);
19737 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
19738 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
19739 stmt
, context_die
);
19741 gen_decl_die (decl
, origin
, context_die
);
19744 /* Generate all of the decls declared within a given scope and (recursively)
19745 all of its sub-blocks. */
19748 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
19754 /* Ignore NULL blocks. */
19755 if (stmt
== NULL_TREE
)
19758 /* Output the DIEs to represent all of the data objects and typedefs
19759 declared directly within this block but not within any nested
19760 sub-blocks. Also, nested function and tag DIEs have been
19761 generated with a parent of NULL; fix that up now. We don't
19762 have to do this if we're at -g1. */
19763 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19765 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
19766 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
19767 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
19768 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
19772 /* Even if we're at -g1, we need to process the subblocks in order to get
19773 inlined call information. */
19775 /* Output the DIEs to represent all sub-blocks (and the items declared
19776 therein) of this block. */
19777 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
19779 subblocks
= BLOCK_CHAIN (subblocks
))
19780 gen_block_die (subblocks
, context_die
, depth
+ 1);
19783 /* Is this a typedef we can avoid emitting? */
19786 is_redundant_typedef (const_tree decl
)
19788 if (TYPE_DECL_IS_STUB (decl
))
19791 if (DECL_ARTIFICIAL (decl
)
19792 && DECL_CONTEXT (decl
)
19793 && is_tagged_type (DECL_CONTEXT (decl
))
19794 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
19795 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
19796 /* Also ignore the artificial member typedef for the class name. */
19802 /* Return TRUE if TYPE is a typedef that names a type for linkage
19803 purposes. This kind of typedefs is produced by the C++ FE for
19806 typedef struct {...} foo;
19808 In that case, there is no typedef variant type produced for foo.
19809 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
19813 is_naming_typedef_decl (const_tree decl
)
19815 if (decl
== NULL_TREE
19816 || TREE_CODE (decl
) != TYPE_DECL
19817 || !is_tagged_type (TREE_TYPE (decl
))
19818 || DECL_IS_BUILTIN (decl
)
19819 || is_redundant_typedef (decl
)
19820 /* It looks like Ada produces TYPE_DECLs that are very similar
19821 to C++ naming typedefs but that have different
19822 semantics. Let's be specific to c++ for now. */
19826 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
19827 && TYPE_NAME (TREE_TYPE (decl
)) == decl
19828 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
19829 != TYPE_NAME (TREE_TYPE (decl
))));
19832 /* Returns the DIE for a context. */
19834 static inline dw_die_ref
19835 get_context_die (tree context
)
19839 /* Find die that represents this context. */
19840 if (TYPE_P (context
))
19842 context
= TYPE_MAIN_VARIANT (context
);
19843 return strip_naming_typedef (context
, force_type_die (context
));
19846 return force_decl_die (context
);
19848 return comp_unit_die ();
19851 /* Returns the DIE for decl. A DIE will always be returned. */
19854 force_decl_die (tree decl
)
19856 dw_die_ref decl_die
;
19857 unsigned saved_external_flag
;
19858 tree save_fn
= NULL_TREE
;
19859 decl_die
= lookup_decl_die (decl
);
19862 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
19864 decl_die
= lookup_decl_die (decl
);
19868 switch (TREE_CODE (decl
))
19870 case FUNCTION_DECL
:
19871 /* Clear current_function_decl, so that gen_subprogram_die thinks
19872 that this is a declaration. At this point, we just want to force
19873 declaration die. */
19874 save_fn
= current_function_decl
;
19875 current_function_decl
= NULL_TREE
;
19876 gen_subprogram_die (decl
, context_die
);
19877 current_function_decl
= save_fn
;
19881 /* Set external flag to force declaration die. Restore it after
19882 gen_decl_die() call. */
19883 saved_external_flag
= DECL_EXTERNAL (decl
);
19884 DECL_EXTERNAL (decl
) = 1;
19885 gen_decl_die (decl
, NULL
, context_die
);
19886 DECL_EXTERNAL (decl
) = saved_external_flag
;
19889 case NAMESPACE_DECL
:
19890 if (dwarf_version
>= 3 || !dwarf_strict
)
19891 dwarf2out_decl (decl
);
19893 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19894 decl_die
= comp_unit_die ();
19897 case TRANSLATION_UNIT_DECL
:
19898 decl_die
= comp_unit_die ();
19902 gcc_unreachable ();
19905 /* We should be able to find the DIE now. */
19907 decl_die
= lookup_decl_die (decl
);
19908 gcc_assert (decl_die
);
19914 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
19915 always returned. */
19918 force_type_die (tree type
)
19920 dw_die_ref type_die
;
19922 type_die
= lookup_type_die (type
);
19925 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
19927 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
19928 TYPE_VOLATILE (type
), context_die
);
19929 gcc_assert (type_die
);
19934 /* Force out any required namespaces to be able to output DECL,
19935 and return the new context_die for it, if it's changed. */
19938 setup_namespace_context (tree thing
, dw_die_ref context_die
)
19940 tree context
= (DECL_P (thing
)
19941 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
19942 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
19943 /* Force out the namespace. */
19944 context_die
= force_decl_die (context
);
19946 return context_die
;
19949 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
19950 type) within its namespace, if appropriate.
19952 For compatibility with older debuggers, namespace DIEs only contain
19953 declarations; all definitions are emitted at CU scope. */
19956 declare_in_namespace (tree thing
, dw_die_ref context_die
)
19958 dw_die_ref ns_context
;
19960 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19961 return context_die
;
19963 /* If this decl is from an inlined function, then don't try to emit it in its
19964 namespace, as we will get confused. It would have already been emitted
19965 when the abstract instance of the inline function was emitted anyways. */
19966 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
19967 return context_die
;
19969 ns_context
= setup_namespace_context (thing
, context_die
);
19971 if (ns_context
!= context_die
)
19975 if (DECL_P (thing
))
19976 gen_decl_die (thing
, NULL
, ns_context
);
19978 gen_type_die (thing
, ns_context
);
19980 return context_die
;
19983 /* Generate a DIE for a namespace or namespace alias. */
19986 gen_namespace_die (tree decl
, dw_die_ref context_die
)
19988 dw_die_ref namespace_die
;
19990 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
19991 they are an alias of. */
19992 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
19994 /* Output a real namespace or module. */
19995 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19996 namespace_die
= new_die (is_fortran ()
19997 ? DW_TAG_module
: DW_TAG_namespace
,
19998 context_die
, decl
);
19999 /* For Fortran modules defined in different CU don't add src coords. */
20000 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
20002 const char *name
= dwarf2_name (decl
, 0);
20004 add_name_attribute (namespace_die
, name
);
20007 add_name_and_src_coords_attributes (namespace_die
, decl
);
20008 if (DECL_EXTERNAL (decl
))
20009 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
20010 equate_decl_number_to_die (decl
, namespace_die
);
20014 /* Output a namespace alias. */
20016 /* Force out the namespace we are an alias of, if necessary. */
20017 dw_die_ref origin_die
20018 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
20020 if (DECL_FILE_SCOPE_P (decl
)
20021 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
20022 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20023 /* Now create the namespace alias DIE. */
20024 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
20025 add_name_and_src_coords_attributes (namespace_die
, decl
);
20026 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
20027 equate_decl_number_to_die (decl
, namespace_die
);
20029 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
20030 if (want_pubnames ())
20031 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
20034 /* Generate Dwarf debug information for a decl described by DECL.
20035 The return value is currently only meaningful for PARM_DECLs,
20036 for all other decls it returns NULL. */
20039 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
20041 tree decl_or_origin
= decl
? decl
: origin
;
20042 tree class_origin
= NULL
, ultimate_origin
;
20044 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
20047 switch (TREE_CODE (decl_or_origin
))
20053 if (!is_fortran () && !is_ada ())
20055 /* The individual enumerators of an enum type get output when we output
20056 the Dwarf representation of the relevant enum type itself. */
20060 /* Emit its type. */
20061 gen_type_die (TREE_TYPE (decl
), context_die
);
20063 /* And its containing namespace. */
20064 context_die
= declare_in_namespace (decl
, context_die
);
20066 gen_const_die (decl
, context_die
);
20069 case FUNCTION_DECL
:
20070 /* Don't output any DIEs to represent mere function declarations,
20071 unless they are class members or explicit block externs. */
20072 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
20073 && DECL_FILE_SCOPE_P (decl_or_origin
)
20074 && (current_function_decl
== NULL_TREE
20075 || DECL_ARTIFICIAL (decl_or_origin
)))
20080 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
20081 on local redeclarations of global functions. That seems broken. */
20082 if (current_function_decl
!= decl
)
20083 /* This is only a declaration. */;
20086 /* If we're emitting a clone, emit info for the abstract instance. */
20087 if (origin
|| DECL_ORIGIN (decl
) != decl
)
20088 dwarf2out_abstract_function (origin
20089 ? DECL_ORIGIN (origin
)
20090 : DECL_ABSTRACT_ORIGIN (decl
));
20092 /* If we're emitting an out-of-line copy of an inline function,
20093 emit info for the abstract instance and set up to refer to it. */
20094 else if (cgraph_function_possibly_inlined_p (decl
)
20095 && ! DECL_ABSTRACT (decl
)
20096 && ! class_or_namespace_scope_p (context_die
)
20097 /* dwarf2out_abstract_function won't emit a die if this is just
20098 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
20099 that case, because that works only if we have a die. */
20100 && DECL_INITIAL (decl
) != NULL_TREE
)
20102 dwarf2out_abstract_function (decl
);
20103 set_decl_origin_self (decl
);
20106 /* Otherwise we're emitting the primary DIE for this decl. */
20107 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20109 /* Before we describe the FUNCTION_DECL itself, make sure that we
20110 have its containing type. */
20112 origin
= decl_class_context (decl
);
20113 if (origin
!= NULL_TREE
)
20114 gen_type_die (origin
, context_die
);
20116 /* And its return type. */
20117 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
20119 /* And its virtual context. */
20120 if (DECL_VINDEX (decl
) != NULL_TREE
)
20121 gen_type_die (DECL_CONTEXT (decl
), context_die
);
20123 /* Make sure we have a member DIE for decl. */
20124 if (origin
!= NULL_TREE
)
20125 gen_type_die_for_member (origin
, decl
, context_die
);
20127 /* And its containing namespace. */
20128 context_die
= declare_in_namespace (decl
, context_die
);
20131 /* Now output a DIE to represent the function itself. */
20133 gen_subprogram_die (decl
, context_die
);
20137 /* If we are in terse mode, don't generate any DIEs to represent any
20138 actual typedefs. */
20139 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20142 /* In the special case of a TYPE_DECL node representing the declaration
20143 of some type tag, if the given TYPE_DECL is marked as having been
20144 instantiated from some other (original) TYPE_DECL node (e.g. one which
20145 was generated within the original definition of an inline function) we
20146 used to generate a special (abbreviated) DW_TAG_structure_type,
20147 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20148 should be actually referencing those DIEs, as variable DIEs with that
20149 type would be emitted already in the abstract origin, so it was always
20150 removed during unused type prunning. Don't add anything in this
20152 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
20155 if (is_redundant_typedef (decl
))
20156 gen_type_die (TREE_TYPE (decl
), context_die
);
20158 /* Output a DIE to represent the typedef itself. */
20159 gen_typedef_die (decl
, context_die
);
20163 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
20164 gen_label_die (decl
, context_die
);
20169 /* If we are in terse mode, don't generate any DIEs to represent any
20170 variable declarations or definitions. */
20171 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20174 /* Output any DIEs that are needed to specify the type of this data
20176 if (decl_by_reference_p (decl_or_origin
))
20177 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20179 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20181 /* And its containing type. */
20182 class_origin
= decl_class_context (decl_or_origin
);
20183 if (class_origin
!= NULL_TREE
)
20184 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20186 /* And its containing namespace. */
20187 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20189 /* Now output the DIE to represent the data object itself. This gets
20190 complicated because of the possibility that the VAR_DECL really
20191 represents an inlined instance of a formal parameter for an inline
20193 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20194 if (ultimate_origin
!= NULL_TREE
20195 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20196 gen_formal_parameter_die (decl
, origin
,
20197 true /* Emit name attribute. */,
20200 gen_variable_die (decl
, origin
, context_die
);
20204 /* Ignore the nameless fields that are used to skip bits but handle C++
20205 anonymous unions and structs. */
20206 if (DECL_NAME (decl
) != NULL_TREE
20207 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20208 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20210 gen_type_die (member_declared_type (decl
), context_die
);
20211 gen_field_die (decl
, context_die
);
20216 if (DECL_BY_REFERENCE (decl_or_origin
))
20217 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20219 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20220 return gen_formal_parameter_die (decl
, origin
,
20221 true /* Emit name attribute. */,
20224 case NAMESPACE_DECL
:
20225 case IMPORTED_DECL
:
20226 if (dwarf_version
>= 3 || !dwarf_strict
)
20227 gen_namespace_die (decl
, context_die
);
20231 /* Probably some frontend-internal decl. Assume we don't care. */
20232 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20239 /* Output debug information for global decl DECL. Called from toplev.c after
20240 compilation proper has finished. */
20243 dwarf2out_global_decl (tree decl
)
20245 /* Output DWARF2 information for file-scope tentative data object
20246 declarations, file-scope (extern) function declarations (which
20247 had no corresponding body) and file-scope tagged type declarations
20248 and definitions which have not yet been forced out. */
20249 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20250 dwarf2out_decl (decl
);
20253 /* Output debug information for type decl DECL. Called from toplev.c
20254 and from language front ends (to record built-in types). */
20256 dwarf2out_type_decl (tree decl
, int local
)
20259 dwarf2out_decl (decl
);
20262 /* Output debug information for imported module or decl DECL.
20263 NAME is non-NULL name in the lexical block if the decl has been renamed.
20264 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20265 that DECL belongs to.
20266 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20268 dwarf2out_imported_module_or_decl_1 (tree decl
,
20270 tree lexical_block
,
20271 dw_die_ref lexical_block_die
)
20273 expanded_location xloc
;
20274 dw_die_ref imported_die
= NULL
;
20275 dw_die_ref at_import_die
;
20277 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20279 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20280 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20284 xloc
= expand_location (input_location
);
20286 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20288 at_import_die
= force_type_die (TREE_TYPE (decl
));
20289 /* For namespace N { typedef void T; } using N::T; base_type_die
20290 returns NULL, but DW_TAG_imported_declaration requires
20291 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20292 if (!at_import_die
)
20294 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20295 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20296 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20297 gcc_assert (at_import_die
);
20302 at_import_die
= lookup_decl_die (decl
);
20303 if (!at_import_die
)
20305 /* If we're trying to avoid duplicate debug info, we may not have
20306 emitted the member decl for this field. Emit it now. */
20307 if (TREE_CODE (decl
) == FIELD_DECL
)
20309 tree type
= DECL_CONTEXT (decl
);
20311 if (TYPE_CONTEXT (type
)
20312 && TYPE_P (TYPE_CONTEXT (type
))
20313 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20314 DINFO_USAGE_DIR_USE
))
20316 gen_type_die_for_member (type
, decl
,
20317 get_context_die (TYPE_CONTEXT (type
)));
20319 at_import_die
= force_decl_die (decl
);
20323 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20325 if (dwarf_version
>= 3 || !dwarf_strict
)
20326 imported_die
= new_die (DW_TAG_imported_module
,
20333 imported_die
= new_die (DW_TAG_imported_declaration
,
20337 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20338 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20340 add_AT_string (imported_die
, DW_AT_name
,
20341 IDENTIFIER_POINTER (name
));
20342 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20345 /* Output debug information for imported module or decl DECL.
20346 NAME is non-NULL name in context if the decl has been renamed.
20347 CHILD is true if decl is one of the renamed decls as part of
20348 importing whole module. */
20351 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20354 /* dw_die_ref at_import_die; */
20355 dw_die_ref scope_die
;
20357 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20362 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20363 We need decl DIE for reference and scope die. First, get DIE for the decl
20366 /* Get the scope die for decl context. Use comp_unit_die for global module
20367 or decl. If die is not found for non globals, force new die. */
20369 && TYPE_P (context
)
20370 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20373 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20376 scope_die
= get_context_die (context
);
20380 gcc_assert (scope_die
->die_child
);
20381 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
20382 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
20383 scope_die
= scope_die
->die_child
;
20386 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20387 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
20391 /* Write the debugging output for DECL. */
20394 dwarf2out_decl (tree decl
)
20396 dw_die_ref context_die
;
20398 /* In LIPO mode, we may output some functions whose type is defined
20399 in another function that will not be output. This can result in
20400 undefined location list symbols in the debug type info.
20401 Here we disable the output of the type info for this case.
20402 It is safe since this function and its debug info should never
20404 if (L_IPO_COMP_MODE
)
20406 tree decl_context
, orig_decl
;
20408 decl_context
= DECL_CONTEXT (decl
);
20409 while (decl_context
&&
20410 TREE_CODE (decl_context
) != TRANSLATION_UNIT_DECL
)
20412 struct cgraph_node
*node
;
20414 /* Refer to cgraph_mark_functions_to_output() in cgraphunit.c,
20415 if cgraph_is_aux_decl_external() is true,
20416 this function will not be output in LIPO mode. */
20417 if (TREE_CODE (decl_context
) == FUNCTION_DECL
&&
20418 TREE_PUBLIC (decl_context
) &&
20419 (node
= cgraph_get_node (decl_context
)) &&
20420 cgraph_is_aux_decl_external (node
))
20423 if (TYPE_P (decl_context
))
20425 decl_context
= TYPE_CONTEXT (decl_context
);
20429 orig_decl
= DECL_ORIGIN (decl_context
);
20430 while (orig_decl
!= DECL_ORIGIN (orig_decl
))
20431 orig_decl
= DECL_ORIGIN (orig_decl
);
20433 decl_context
= DECL_CONTEXT (orig_decl
);
20437 context_die
= comp_unit_die ();
20439 switch (TREE_CODE (decl
))
20444 case FUNCTION_DECL
:
20445 /* What we would really like to do here is to filter out all mere
20446 file-scope declarations of file-scope functions which are never
20447 referenced later within this translation unit (and keep all of ones
20448 that *are* referenced later on) but we aren't clairvoyant, so we have
20449 no idea which functions will be referenced in the future (i.e. later
20450 on within the current translation unit). So here we just ignore all
20451 file-scope function declarations which are not also definitions. If
20452 and when the debugger needs to know something about these functions,
20453 it will have to hunt around and find the DWARF information associated
20454 with the definition of the function.
20456 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20457 nodes represent definitions and which ones represent mere
20458 declarations. We have to check DECL_INITIAL instead. That's because
20459 the C front-end supports some weird semantics for "extern inline"
20460 function definitions. These can get inlined within the current
20461 translation unit (and thus, we need to generate Dwarf info for their
20462 abstract instances so that the Dwarf info for the concrete inlined
20463 instances can have something to refer to) but the compiler never
20464 generates any out-of-lines instances of such things (despite the fact
20465 that they *are* definitions).
20467 The important point is that the C front-end marks these "extern
20468 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20469 them anyway. Note that the C++ front-end also plays some similar games
20470 for inline function definitions appearing within include files which
20471 also contain `#pragma interface' pragmas.
20473 If we are called from dwarf2out_abstract_function output a DIE
20474 anyway. We can end up here this way with early inlining and LTO
20475 where the inlined function is output in a different LTRANS unit
20477 if (DECL_INITIAL (decl
) == NULL_TREE
20478 && ! DECL_ABSTRACT (decl
))
20481 /* If we're a nested function, initially use a parent of NULL; if we're
20482 a plain function, this will be fixed up in decls_for_scope. If
20483 we're a method, it will be ignored, since we already have a DIE. */
20484 if (decl_function_context (decl
)
20485 /* But if we're in terse mode, we don't care about scope. */
20486 && debug_info_level
> DINFO_LEVEL_TERSE
)
20487 context_die
= NULL
;
20491 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20492 declaration and if the declaration was never even referenced from
20493 within this entire compilation unit. We suppress these DIEs in
20494 order to save space in the .debug section (by eliminating entries
20495 which are probably useless). Note that we must not suppress
20496 block-local extern declarations (whether used or not) because that
20497 would screw-up the debugger's name lookup mechanism and cause it to
20498 miss things which really ought to be in scope at a given point. */
20499 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
20502 /* For local statics lookup proper context die. */
20503 if (TREE_STATIC (decl
)
20504 && DECL_CONTEXT (decl
)
20505 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
20506 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20508 /* If we are in terse mode, don't generate any DIEs to represent any
20509 variable declarations or definitions. */
20510 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20515 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20517 if (!is_fortran () && !is_ada ())
20519 if (TREE_STATIC (decl
) && decl_function_context (decl
))
20520 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20523 case NAMESPACE_DECL
:
20524 case IMPORTED_DECL
:
20525 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20527 if (lookup_decl_die (decl
) != NULL
)
20532 /* Don't emit stubs for types unless they are needed by other DIEs. */
20533 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
20536 /* Don't bother trying to generate any DIEs to represent any of the
20537 normal built-in types for the language we are compiling. */
20538 if (DECL_IS_BUILTIN (decl
))
20541 /* If we are in terse mode, don't generate any DIEs for types. */
20542 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20545 /* If we're a function-scope tag, initially use a parent of NULL;
20546 this will be fixed up in decls_for_scope. */
20547 if (decl_function_context (decl
))
20548 context_die
= NULL
;
20556 gen_decl_die (decl
, NULL
, context_die
);
20559 /* Write the debugging output for DECL. */
20562 dwarf2out_function_decl (tree decl
)
20564 dwarf2out_decl (decl
);
20565 call_arg_locations
= NULL
;
20566 call_arg_loc_last
= NULL
;
20567 call_site_count
= -1;
20568 tail_call_site_count
= -1;
20569 block_map
.release ();
20570 htab_empty (decl_loc_table
);
20571 htab_empty (cached_dw_loc_list_table
);
20574 /* Output a marker (i.e. a label) for the beginning of the generated code for
20575 a lexical block. */
20578 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
20579 unsigned int blocknum
)
20581 switch_to_section (current_function_section ());
20582 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
20585 /* Output a marker (i.e. a label) for the end of the generated code for a
20589 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
20591 switch_to_section (current_function_section ());
20592 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
20595 /* Returns nonzero if it is appropriate not to emit any debugging
20596 information for BLOCK, because it doesn't contain any instructions.
20598 Don't allow this for blocks with nested functions or local classes
20599 as we would end up with orphans, and in the presence of scheduling
20600 we may end up calling them anyway. */
20603 dwarf2out_ignore_block (const_tree block
)
20608 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
20609 if (TREE_CODE (decl
) == FUNCTION_DECL
20610 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20612 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
20614 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
20615 if (TREE_CODE (decl
) == FUNCTION_DECL
20616 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20623 /* Hash table routines for file_hash. */
20626 file_table_eq (const void *p1_p
, const void *p2_p
)
20628 const struct dwarf_file_data
*const p1
=
20629 (const struct dwarf_file_data
*) p1_p
;
20630 const char *const p2
= (const char *) p2_p
;
20631 return filename_cmp (p1
->filename
, p2
) == 0;
20635 file_table_hash (const void *p_p
)
20637 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
20638 return htab_hash_string (p
->filename
);
20641 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20642 dwarf2out.c) and return its "index". The index of each (known) filename is
20643 just a unique number which is associated with only that one filename. We
20644 need such numbers for the sake of generating labels (in the .debug_sfnames
20645 section) and references to those files numbers (in the .debug_srcinfo
20646 and.debug_macinfo sections). If the filename given as an argument is not
20647 found in our current list, add it to the list and assign it the next
20648 available unique index number. In order to speed up searches, we remember
20649 the index of the filename was looked up last. This handles the majority of
20652 static struct dwarf_file_data
*
20653 lookup_filename (const char *file_name
)
20656 struct dwarf_file_data
* created
;
20658 /* Check to see if the file name that was searched on the previous
20659 call matches this file name. If so, return the index. */
20660 if (file_table_last_lookup
20661 && (file_name
== file_table_last_lookup
->filename
20662 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
20663 return file_table_last_lookup
;
20665 /* Didn't match the previous lookup, search the table. */
20666 slot
= htab_find_slot_with_hash (file_table
, file_name
,
20667 htab_hash_string (file_name
), INSERT
);
20669 return (struct dwarf_file_data
*) *slot
;
20671 created
= ggc_alloc_dwarf_file_data ();
20672 created
->filename
= file_name
;
20673 created
->emitted_number
= 0;
20678 /* If the assembler will construct the file table, then translate the compiler
20679 internal file table number into the assembler file table number, and emit
20680 a .file directive if we haven't already emitted one yet. The file table
20681 numbers are different because we prune debug info for unused variables and
20682 types, which may include filenames. */
20685 maybe_emit_file (struct dwarf_file_data
* fd
)
20687 if (! fd
->emitted_number
)
20689 if (last_emitted_file
)
20690 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
20692 fd
->emitted_number
= 1;
20693 last_emitted_file
= fd
;
20695 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20697 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
20698 output_quoted_string (asm_out_file
,
20699 remap_debug_filename (fd
->filename
));
20700 fputc ('\n', asm_out_file
);
20704 return fd
->emitted_number
;
20707 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20708 That generation should happen after function debug info has been
20709 generated. The value of the attribute is the constant value of ARG. */
20712 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
20714 die_arg_entry entry
;
20719 if (!tmpl_value_parm_die_table
)
20720 vec_alloc (tmpl_value_parm_die_table
, 32);
20724 vec_safe_push (tmpl_value_parm_die_table
, entry
);
20727 /* Return TRUE if T is an instance of generic type, FALSE
20731 generic_type_p (tree t
)
20733 if (t
== NULL_TREE
|| !TYPE_P (t
))
20735 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
20738 /* Schedule the generation of the generic parameter dies for the
20739 instance of generic type T. The proper generation itself is later
20740 done by gen_scheduled_generic_parms_dies. */
20743 schedule_generic_params_dies_gen (tree t
)
20745 if (!generic_type_p (t
))
20748 if (!generic_type_instances
)
20749 vec_alloc (generic_type_instances
, 256);
20751 vec_safe_push (generic_type_instances
, t
);
20754 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20755 by append_entry_to_tmpl_value_parm_die_table. This function must
20756 be called after function DIEs have been generated. */
20759 gen_remaining_tmpl_value_param_die_attribute (void)
20761 if (tmpl_value_parm_die_table
)
20766 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
20767 tree_add_const_value_attribute (e
->die
, e
->arg
);
20771 /* Generate generic parameters DIEs for instances of generic types
20772 that have been previously scheduled by
20773 schedule_generic_params_dies_gen. This function must be called
20774 after all the types of the CU have been laid out. */
20777 gen_scheduled_generic_parms_dies (void)
20782 if (!generic_type_instances
)
20785 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
20786 if (COMPLETE_TYPE_P (t
))
20787 gen_generic_params_dies (t
);
20791 /* Replace DW_AT_name for the decl with name. */
20794 dwarf2out_set_name (tree decl
, tree name
)
20800 die
= TYPE_SYMTAB_DIE (decl
);
20804 dname
= dwarf2_name (name
, 0);
20808 attr
= get_AT (die
, DW_AT_name
);
20811 struct indirect_string_node
*node
;
20813 node
= find_AT_string (dname
);
20814 /* replace the string. */
20815 attr
->dw_attr_val
.v
.val_str
= node
;
20819 add_name_attribute (die
, dname
);
20822 /* True if before or during processing of the first function being emitted. */
20823 static bool in_first_function_p
= true;
20824 /* True if loc_note during dwarf2out_var_location call might still be
20825 before first real instruction at address equal to .Ltext0. */
20826 static bool maybe_at_text_label_p
= true;
20827 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
20828 static unsigned int first_loclabel_num_not_at_text_label
;
20830 /* Called by the final INSN scan whenever we see a var location. We
20831 use it to drop labels in the right places, and throw the location in
20832 our lookup table. */
20835 dwarf2out_var_location (rtx loc_note
)
20837 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
20838 struct var_loc_node
*newloc
;
20839 rtx next_real
, next_note
;
20840 static const char *last_label
;
20841 static const char *last_postcall_label
;
20842 static bool last_in_cold_section_p
;
20843 static rtx expected_next_loc_note
;
20847 if (!NOTE_P (loc_note
))
20849 if (CALL_P (loc_note
))
20852 if (SIBLING_CALL_P (loc_note
))
20853 tail_call_site_count
++;
20858 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
20859 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
20862 /* Optimize processing a large consecutive sequence of location
20863 notes so we don't spend too much time in next_real_insn. If the
20864 next insn is another location note, remember the next_real_insn
20865 calculation for next time. */
20866 next_real
= cached_next_real_insn
;
20869 if (expected_next_loc_note
!= loc_note
)
20870 next_real
= NULL_RTX
;
20873 next_note
= NEXT_INSN (loc_note
);
20875 || INSN_DELETED_P (next_note
)
20876 || GET_CODE (next_note
) != NOTE
20877 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
20878 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
20879 next_note
= NULL_RTX
;
20882 next_real
= next_real_insn (loc_note
);
20886 expected_next_loc_note
= next_note
;
20887 cached_next_real_insn
= next_real
;
20890 cached_next_real_insn
= NULL_RTX
;
20892 /* If there are no instructions which would be affected by this note,
20893 don't do anything. */
20895 && next_real
== NULL_RTX
20896 && !NOTE_DURING_CALL_P (loc_note
))
20899 if (next_real
== NULL_RTX
)
20900 next_real
= get_last_insn ();
20902 /* If there were any real insns between note we processed last time
20903 and this note (or if it is the first note), clear
20904 last_{,postcall_}label so that they are not reused this time. */
20905 if (last_var_location_insn
== NULL_RTX
20906 || last_var_location_insn
!= next_real
20907 || last_in_cold_section_p
!= in_cold_section_p
)
20910 last_postcall_label
= NULL
;
20915 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
20916 newloc
= add_var_loc_to_decl (decl
, loc_note
,
20917 NOTE_DURING_CALL_P (loc_note
)
20918 ? last_postcall_label
: last_label
);
20919 if (newloc
== NULL
)
20928 /* If there were no real insns between note we processed last time
20929 and this note, use the label we emitted last time. Otherwise
20930 create a new label and emit it. */
20931 if (last_label
== NULL
)
20933 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
20934 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
20936 last_label
= ggc_strdup (loclabel
);
20937 /* See if loclabel might be equal to .Ltext0. If yes,
20938 bump first_loclabel_num_not_at_text_label. */
20939 if (!have_multiple_function_sections
20940 && in_first_function_p
20941 && maybe_at_text_label_p
)
20943 static rtx last_start
;
20945 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
20946 if (insn
== last_start
)
20948 else if (!NONDEBUG_INSN_P (insn
))
20952 rtx body
= PATTERN (insn
);
20953 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
20955 /* Inline asm could occupy zero bytes. */
20956 else if (GET_CODE (body
) == ASM_INPUT
20957 || asm_noperands (body
) >= 0)
20959 #ifdef HAVE_attr_length
20960 else if (get_attr_min_length (insn
) == 0)
20965 /* Assume insn has non-zero length. */
20966 maybe_at_text_label_p
= false;
20970 if (maybe_at_text_label_p
)
20972 last_start
= loc_note
;
20973 first_loclabel_num_not_at_text_label
= loclabel_num
;
20980 struct call_arg_loc_node
*ca_loc
20981 = ggc_alloc_cleared_call_arg_loc_node ();
20982 rtx prev
= prev_real_insn (loc_note
), x
;
20983 ca_loc
->call_arg_loc_note
= loc_note
;
20984 ca_loc
->next
= NULL
;
20985 ca_loc
->label
= last_label
;
20988 || (NONJUMP_INSN_P (prev
)
20989 && GET_CODE (PATTERN (prev
)) == SEQUENCE
20990 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
20991 if (!CALL_P (prev
))
20992 prev
= XVECEXP (PATTERN (prev
), 0, 0);
20993 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
20994 x
= get_call_rtx_from (PATTERN (prev
));
20997 x
= XEXP (XEXP (x
, 0), 0);
20998 if (GET_CODE (x
) == SYMBOL_REF
20999 && SYMBOL_REF_DECL (x
)
21000 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
21001 ca_loc
->symbol_ref
= x
;
21003 ca_loc
->block
= insn_scope (prev
);
21004 if (call_arg_locations
)
21005 call_arg_loc_last
->next
= ca_loc
;
21007 call_arg_locations
= ca_loc
;
21008 call_arg_loc_last
= ca_loc
;
21010 else if (!NOTE_DURING_CALL_P (loc_note
))
21011 newloc
->label
= last_label
;
21014 if (!last_postcall_label
)
21016 sprintf (loclabel
, "%s-1", last_label
);
21017 last_postcall_label
= ggc_strdup (loclabel
);
21019 newloc
->label
= last_postcall_label
;
21022 last_var_location_insn
= next_real
;
21023 last_in_cold_section_p
= in_cold_section_p
;
21026 /* Note in one location list that text section has changed. */
21029 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
21031 var_loc_list
*list
= (var_loc_list
*) *slot
;
21033 list
->last_before_switch
21034 = list
->last
->next
? list
->last
->next
: list
->last
;
21038 /* Note in all location lists that text section has changed. */
21041 var_location_switch_text_section (void)
21043 if (decl_loc_table
== NULL
)
21046 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
21049 /* Create a new line number table. */
21051 static dw_line_info_table
*
21052 new_line_info_table (void)
21054 dw_line_info_table
*table
;
21056 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
21057 table
->file_num
= 1;
21058 table
->line_num
= 1;
21059 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
21064 /* Lookup the "current" table into which we emit line info, so
21065 that we don't have to do it for every source line. */
21068 set_cur_line_info_table (section
*sec
)
21070 dw_line_info_table
*table
;
21072 if (sec
== text_section
)
21073 table
= text_section_line_info
;
21074 else if (sec
== cold_text_section
)
21076 table
= cold_text_section_line_info
;
21079 cold_text_section_line_info
= table
= new_line_info_table ();
21080 table
->end_label
= cold_end_label
;
21085 const char *end_label
;
21087 if (flag_reorder_blocks_and_partition
)
21089 if (in_cold_section_p
)
21090 end_label
= crtl
->subsections
.cold_section_end_label
;
21092 end_label
= crtl
->subsections
.hot_section_end_label
;
21096 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21097 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
21098 FUNC_LABEL_ID (cfun
));
21099 end_label
= ggc_strdup (label
);
21102 table
= new_line_info_table ();
21103 table
->end_label
= end_label
;
21105 vec_safe_push (separate_line_info
, table
);
21108 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21109 table
->is_stmt
= (cur_line_info_table
21110 ? cur_line_info_table
->is_stmt
21111 : DWARF_LINE_DEFAULT_IS_STMT_START
);
21112 cur_line_info_table
= table
;
21116 /* We need to reset the locations at the beginning of each
21117 function. We can't do this in the end_function hook, because the
21118 declarations that use the locations won't have been output when
21119 that hook is called. Also compute have_multiple_function_sections here. */
21122 dwarf2out_begin_function (tree fun
)
21124 section
*sec
= function_section (fun
);
21126 if (sec
!= text_section
)
21127 have_multiple_function_sections
= true;
21129 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
21131 gcc_assert (current_function_decl
== fun
);
21132 cold_text_section
= unlikely_text_section ();
21133 switch_to_section (cold_text_section
);
21134 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
21135 switch_to_section (sec
);
21138 dwarf2out_note_section_used ();
21139 call_site_count
= 0;
21140 tail_call_site_count
= 0;
21142 set_cur_line_info_table (sec
);
21145 /* Helper function of dwarf2out_end_function, called only after emitting
21146 the very first function into assembly. Check if some .debug_loc range
21147 might end with a .LVL* label that could be equal to .Ltext0.
21148 In that case we must force using absolute addresses in .debug_loc ranges,
21149 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
21150 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
21152 Set have_multiple_function_sections to true in that case and
21153 terminate htab traversal. */
21156 find_empty_loc_ranges_at_text_label (void **slot
, void *)
21158 var_loc_list
*entry
;
21159 struct var_loc_node
*node
;
21161 entry
= (var_loc_list
*) *slot
;
21162 node
= entry
->first
;
21163 if (node
&& node
->next
&& node
->next
->label
)
21166 const char *label
= node
->next
->label
;
21167 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
21169 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
21171 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
21172 if (strcmp (label
, loclabel
) == 0)
21174 have_multiple_function_sections
= true;
21182 /* Hook called after emitting a function into assembly.
21183 This does something only for the very first function emitted. */
21186 dwarf2out_end_function (unsigned int)
21188 if (in_first_function_p
21189 && !have_multiple_function_sections
21190 && first_loclabel_num_not_at_text_label
21192 htab_traverse (decl_loc_table
, find_empty_loc_ranges_at_text_label
,
21194 in_first_function_p
= false;
21195 maybe_at_text_label_p
= false;
21198 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
21201 push_dw_line_info_entry (dw_line_info_table
*table
,
21202 enum dw_line_info_opcode opcode
, unsigned int val
)
21204 dw_line_info_entry e
;
21207 vec_safe_push (table
->entries
, e
);
21210 /* Output a label to mark the beginning of a source code line entry
21211 and record information relating to this source line, in
21212 'line_info_table' for later output of the .debug_line section. */
21213 /* ??? The discriminator parameter ought to be unsigned. */
21216 dwarf2out_source_line (unsigned int line
, const char *filename
,
21217 int discriminator
, bool is_stmt
)
21219 unsigned int file_num
;
21220 dw_line_info_table
*table
;
21222 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
21225 /* The discriminator column was added in dwarf4. Simplify the below
21226 by simply removing it if we're not supposed to output it. */
21227 if (dwarf_version
< 4 && dwarf_strict
)
21230 table
= cur_line_info_table
;
21231 file_num
= maybe_emit_file (lookup_filename (filename
));
21233 /* ??? TODO: Elide duplicate line number entries. Traditionally,
21234 the debugger has used the second (possibly duplicate) line number
21235 at the beginning of the function to mark the end of the prologue.
21236 We could eliminate any other duplicates within the function. For
21237 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
21238 that second line number entry. */
21239 /* Recall that this end-of-prologue indication is *not* the same thing
21240 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
21241 to which the hook corresponds, follows the last insn that was
21242 emitted by gen_prologue. What we need is to precede the first insn
21243 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
21244 insn that corresponds to something the user wrote. These may be
21245 very different locations once scheduling is enabled. */
21247 if (0 && file_num
== table
->file_num
21248 && line
== table
->line_num
21249 && discriminator
== table
->discrim_num
21250 && is_stmt
== table
->is_stmt
)
21253 switch_to_section (current_function_section ());
21255 /* If requested, emit something human-readable. */
21256 if (flag_debug_asm
)
21257 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
21259 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21261 /* Emit the .loc directive understood by GNU as. */
21262 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
21263 file_num, line, is_stmt, discriminator */
21264 fputs ("\t.loc ", asm_out_file
);
21265 fprint_ul (asm_out_file
, file_num
);
21266 putc (' ', asm_out_file
);
21267 fprint_ul (asm_out_file
, line
);
21268 putc (' ', asm_out_file
);
21269 putc ('0', asm_out_file
);
21271 if (is_stmt
!= table
->is_stmt
)
21273 fputs (" is_stmt ", asm_out_file
);
21274 putc (is_stmt
? '1' : '0', asm_out_file
);
21276 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
21278 gcc_assert (discriminator
> 0);
21279 fputs (" discriminator ", asm_out_file
);
21280 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
21282 putc ('\n', asm_out_file
);
21286 unsigned int label_num
= ++line_info_label_num
;
21288 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
21290 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
21291 if (file_num
!= table
->file_num
)
21292 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
21293 if (discriminator
!= table
->discrim_num
)
21294 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
21295 if (is_stmt
!= table
->is_stmt
)
21296 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
21297 push_dw_line_info_entry (table
, LI_set_line
, line
);
21300 table
->file_num
= file_num
;
21301 table
->line_num
= line
;
21302 table
->discrim_num
= discriminator
;
21303 table
->is_stmt
= is_stmt
;
21304 table
->in_use
= true;
21307 /* Record the beginning of a new source file. */
21310 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21312 if (flag_eliminate_dwarf2_dups
)
21314 /* Record the beginning of the file for break_out_includes. */
21315 dw_die_ref bincl_die
;
21317 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
21318 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21321 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21324 e
.code
= DW_MACINFO_start_file
;
21326 e
.info
= ggc_strdup (filename
);
21327 vec_safe_push (macinfo_table
, e
);
21331 /* Record the end of a source file. */
21334 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21336 if (flag_eliminate_dwarf2_dups
)
21337 /* Record the end of the file for break_out_includes. */
21338 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
21340 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21343 e
.code
= DW_MACINFO_end_file
;
21346 vec_safe_push (macinfo_table
, e
);
21350 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21351 the tail part of the directive line, i.e. the part which is past the
21352 initial whitespace, #, whitespace, directive-name, whitespace part. */
21355 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
21356 const char *buffer ATTRIBUTE_UNUSED
)
21358 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21361 /* Insert a dummy first entry to be able to optimize the whole
21362 predefined macro block using DW_MACRO_GNU_transparent_include. */
21363 if (macinfo_table
->is_empty () && lineno
<= 1)
21368 vec_safe_push (macinfo_table
, e
);
21370 e
.code
= DW_MACINFO_define
;
21372 e
.info
= ggc_strdup (buffer
);
21373 vec_safe_push (macinfo_table
, e
);
21377 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21378 the tail part of the directive line, i.e. the part which is past the
21379 initial whitespace, #, whitespace, directive-name, whitespace part. */
21382 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21383 const char *buffer ATTRIBUTE_UNUSED
)
21385 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21388 /* Insert a dummy first entry to be able to optimize the whole
21389 predefined macro block using DW_MACRO_GNU_transparent_include. */
21390 if (macinfo_table
->is_empty () && lineno
<= 1)
21395 vec_safe_push (macinfo_table
, e
);
21397 e
.code
= DW_MACINFO_undef
;
21399 e
.info
= ggc_strdup (buffer
);
21400 vec_safe_push (macinfo_table
, e
);
21404 /* Routines to manipulate hash table of CUs. */
21407 htab_macinfo_hash (const void *of
)
21409 const macinfo_entry
*const entry
=
21410 (const macinfo_entry
*) of
;
21412 return htab_hash_string (entry
->info
);
21416 htab_macinfo_eq (const void *of1
, const void *of2
)
21418 const macinfo_entry
*const entry1
= (const macinfo_entry
*) of1
;
21419 const macinfo_entry
*const entry2
= (const macinfo_entry
*) of2
;
21421 return !strcmp (entry1
->info
, entry2
->info
);
21424 /* Output a single .debug_macinfo entry. */
21427 output_macinfo_op (macinfo_entry
*ref
)
21431 struct indirect_string_node
*node
;
21432 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21433 struct dwarf_file_data
*fd
;
21437 case DW_MACINFO_start_file
:
21438 fd
= lookup_filename (ref
->info
);
21439 file_num
= maybe_emit_file (fd
);
21440 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
21441 dw2_asm_output_data_uleb128 (ref
->lineno
,
21442 "Included from line number %lu",
21443 (unsigned long) ref
->lineno
);
21444 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
21446 case DW_MACINFO_end_file
:
21447 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
21449 case DW_MACINFO_define
:
21450 case DW_MACINFO_undef
:
21451 len
= strlen (ref
->info
) + 1;
21453 && len
> DWARF_OFFSET_SIZE
21454 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21455 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21457 ref
->code
= ref
->code
== DW_MACINFO_define
21458 ? DW_MACRO_GNU_define_indirect
21459 : DW_MACRO_GNU_undef_indirect
;
21460 output_macinfo_op (ref
);
21463 dw2_asm_output_data (1, ref
->code
,
21464 ref
->code
== DW_MACINFO_define
21465 ? "Define macro" : "Undefine macro");
21466 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21467 (unsigned long) ref
->lineno
);
21468 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
21470 case DW_MACRO_GNU_define_indirect
:
21471 case DW_MACRO_GNU_undef_indirect
:
21472 node
= find_AT_string (ref
->info
);
21474 && ((node
->form
== DW_FORM_strp
)
21475 || (node
->form
== DW_FORM_GNU_str_index
)));
21476 dw2_asm_output_data (1, ref
->code
,
21477 ref
->code
== DW_MACRO_GNU_define_indirect
21478 ? "Define macro indirect"
21479 : "Undefine macro indirect");
21480 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21481 (unsigned long) ref
->lineno
);
21482 if (node
->form
== DW_FORM_strp
)
21483 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
21484 debug_str_section
, "The macro: \"%s\"",
21487 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
21490 case DW_MACRO_GNU_transparent_include
:
21491 dw2_asm_output_data (1, ref
->code
, "Transparent include");
21492 ASM_GENERATE_INTERNAL_LABEL (label
,
21493 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
21494 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
21497 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
21498 ASM_COMMENT_START
, (unsigned long) ref
->code
);
21503 /* Attempt to make a sequence of define/undef macinfo ops shareable with
21504 other compilation unit .debug_macinfo sections. IDX is the first
21505 index of a define/undef, return the number of ops that should be
21506 emitted in a comdat .debug_macinfo section and emit
21507 a DW_MACRO_GNU_transparent_include entry referencing it.
21508 If the define/undef entry should be emitted normally, return 0. */
21511 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
21512 htab_t
*macinfo_htab
)
21514 macinfo_entry
*first
, *second
, *cur
, *inc
;
21515 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
21516 unsigned char checksum
[16];
21517 struct md5_ctx ctx
;
21518 char *grp_name
, *tail
;
21520 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
21523 first
= &(*macinfo_table
)[idx
];
21524 second
= &(*macinfo_table
)[idx
+ 1];
21526 /* Optimize only if there are at least two consecutive define/undef ops,
21527 and either all of them are before first DW_MACINFO_start_file
21528 with lineno {0,1} (i.e. predefined macro block), or all of them are
21529 in some included header file. */
21530 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
21532 if (vec_safe_is_empty (files
))
21534 if (first
->lineno
> 1 || second
->lineno
> 1)
21537 else if (first
->lineno
== 0)
21540 /* Find the last define/undef entry that can be grouped together
21541 with first and at the same time compute md5 checksum of their
21542 codes, linenumbers and strings. */
21543 md5_init_ctx (&ctx
);
21544 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
21545 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
21547 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
21551 unsigned char code
= cur
->code
;
21552 md5_process_bytes (&code
, 1, &ctx
);
21553 checksum_uleb128 (cur
->lineno
, &ctx
);
21554 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
21556 md5_finish_ctx (&ctx
, checksum
);
21559 /* From the containing include filename (if any) pick up just
21560 usable characters from its basename. */
21561 if (vec_safe_is_empty (files
))
21564 base
= lbasename (files
->last ().info
);
21565 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
21566 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21567 encoded_filename_len
++;
21568 /* Count . at the end. */
21569 if (encoded_filename_len
)
21570 encoded_filename_len
++;
21572 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
21573 linebuf_len
= strlen (linebuf
);
21575 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
21576 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
21578 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
21579 tail
= grp_name
+ 4;
21580 if (encoded_filename_len
)
21582 for (i
= 0; base
[i
]; i
++)
21583 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21587 memcpy (tail
, linebuf
, linebuf_len
);
21588 tail
+= linebuf_len
;
21590 for (i
= 0; i
< 16; i
++)
21591 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
21593 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
21594 in the empty vector entry before the first define/undef. */
21595 inc
= &(*macinfo_table
)[idx
- 1];
21596 inc
->code
= DW_MACRO_GNU_transparent_include
;
21598 inc
->info
= ggc_strdup (grp_name
);
21599 if (*macinfo_htab
== NULL
)
21600 *macinfo_htab
= htab_create (10, htab_macinfo_hash
, htab_macinfo_eq
, NULL
);
21601 /* Avoid emitting duplicates. */
21602 slot
= htab_find_slot (*macinfo_htab
, inc
, INSERT
);
21607 /* If such an entry has been used before, just emit
21608 a DW_MACRO_GNU_transparent_include op. */
21609 inc
= (macinfo_entry
*) *slot
;
21610 output_macinfo_op (inc
);
21611 /* And clear all macinfo_entry in the range to avoid emitting them
21612 in the second pass. */
21613 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
21622 inc
->lineno
= htab_elements (*macinfo_htab
);
21623 output_macinfo_op (inc
);
21628 /* Save any strings needed by the macinfo table in the debug str
21629 table. All strings must be collected into the table by the time
21630 index_string is called. */
21633 save_macinfo_strings (void)
21637 macinfo_entry
*ref
;
21639 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
21643 /* Match the logic in output_macinfo_op to decide on
21644 indirect strings. */
21645 case DW_MACINFO_define
:
21646 case DW_MACINFO_undef
:
21647 len
= strlen (ref
->info
) + 1;
21649 && len
> DWARF_OFFSET_SIZE
21650 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21651 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21652 set_indirect_string (find_AT_string (ref
->info
));
21654 case DW_MACRO_GNU_define_indirect
:
21655 case DW_MACRO_GNU_undef_indirect
:
21656 set_indirect_string (find_AT_string (ref
->info
));
21664 /* Output macinfo section(s). */
21667 output_macinfo (void)
21670 unsigned long length
= vec_safe_length (macinfo_table
);
21671 macinfo_entry
*ref
;
21672 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
21673 htab_t macinfo_htab
= NULL
;
21678 /* output_macinfo* uses these interchangeably. */
21679 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
21680 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
21681 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
21682 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
21684 /* For .debug_macro emit the section header. */
21687 dw2_asm_output_data (2, 4, "DWARF macro version number");
21688 if (DWARF_OFFSET_SIZE
== 8)
21689 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
21691 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
21692 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
21693 (!dwarf_split_debug_info
? debug_line_section_label
21694 : debug_skeleton_line_section_label
),
21695 debug_line_section
, NULL
);
21698 /* In the first loop, it emits the primary .debug_macinfo section
21699 and after each emitted op the macinfo_entry is cleared.
21700 If a longer range of define/undef ops can be optimized using
21701 DW_MACRO_GNU_transparent_include, the
21702 DW_MACRO_GNU_transparent_include op is emitted and kept in
21703 the vector before the first define/undef in the range and the
21704 whole range of define/undef ops is not emitted and kept. */
21705 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21709 case DW_MACINFO_start_file
:
21710 vec_safe_push (files
, *ref
);
21712 case DW_MACINFO_end_file
:
21713 if (!vec_safe_is_empty (files
))
21716 case DW_MACINFO_define
:
21717 case DW_MACINFO_undef
:
21719 && HAVE_COMDAT_GROUP
21720 && vec_safe_length (files
) != 1
21723 && (*macinfo_table
)[i
- 1].code
== 0)
21725 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
21734 /* A dummy entry may be inserted at the beginning to be able
21735 to optimize the whole block of predefined macros. */
21741 output_macinfo_op (ref
);
21746 if (macinfo_htab
== NULL
)
21749 htab_delete (macinfo_htab
);
21751 /* If any DW_MACRO_GNU_transparent_include were used, on those
21752 DW_MACRO_GNU_transparent_include entries terminate the
21753 current chain and switch to a new comdat .debug_macinfo
21754 section and emit the define/undef entries within it. */
21755 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21760 case DW_MACRO_GNU_transparent_include
:
21762 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21763 tree comdat_key
= get_identifier (ref
->info
);
21764 /* Terminate the previous .debug_macinfo section. */
21765 dw2_asm_output_data (1, 0, "End compilation unit");
21766 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
21768 | SECTION_LINKONCE
,
21770 ASM_GENERATE_INTERNAL_LABEL (label
,
21771 DEBUG_MACRO_SECTION_LABEL
,
21773 ASM_OUTPUT_LABEL (asm_out_file
, label
);
21776 dw2_asm_output_data (2, 4, "DWARF macro version number");
21777 if (DWARF_OFFSET_SIZE
== 8)
21778 dw2_asm_output_data (1, 1, "Flags: 64-bit");
21780 dw2_asm_output_data (1, 0, "Flags: 32-bit");
21783 case DW_MACINFO_define
:
21784 case DW_MACINFO_undef
:
21785 output_macinfo_op (ref
);
21790 gcc_unreachable ();
21794 /* Set up for Dwarf output at the start of compilation. */
21797 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
21799 /* Allocate the file_table. */
21800 file_table
= htab_create_ggc (50, file_table_hash
,
21801 file_table_eq
, NULL
);
21803 /* Allocate the decl_die_table. */
21804 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
21805 decl_die_table_eq
, NULL
);
21807 /* Allocate the decl_loc_table. */
21808 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
21809 decl_loc_table_eq
, NULL
);
21811 /* Allocate the cached_dw_loc_list_table. */
21812 cached_dw_loc_list_table
21813 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
21814 cached_dw_loc_list_table_eq
, NULL
);
21816 /* Allocate the initial hunk of the decl_scope_table. */
21817 vec_alloc (decl_scope_table
, 256);
21819 /* Allocate the initial hunk of the abbrev_die_table. */
21820 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
21821 (ABBREV_DIE_TABLE_INCREMENT
);
21822 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
21823 /* Zero-th entry is allocated, but unused. */
21824 abbrev_die_table_in_use
= 1;
21826 /* Allocate the pubtypes and pubnames vectors. */
21827 vec_alloc (pubname_table
, 32);
21828 vec_alloc (pubtype_table
, 32);
21830 vec_alloc (incomplete_types
, 64);
21832 vec_alloc (used_rtx_array
, 32);
21834 if (!dwarf_split_debug_info
)
21836 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
21837 SECTION_DEBUG
, NULL
);
21838 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21839 SECTION_DEBUG
, NULL
);
21840 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
21841 SECTION_DEBUG
, NULL
);
21845 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
21846 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21847 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
21848 SECTION_DEBUG
| SECTION_EXCLUDE
,
21850 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
21851 SECTION_DEBUG
, NULL
);
21852 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
21853 SECTION_DEBUG
, NULL
);
21854 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21855 SECTION_DEBUG
, NULL
);
21856 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
21857 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
21859 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
21860 the main .o, but the skeleton_line goes into the split off dwo. */
21861 debug_skeleton_line_section
21862 = get_section (DEBUG_DWO_LINE_SECTION
,
21863 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21864 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
21865 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
21866 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
21867 SECTION_DEBUG
| SECTION_EXCLUDE
,
21869 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
21870 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
21871 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
21872 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21873 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
21874 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
21876 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
21877 SECTION_DEBUG
, NULL
);
21878 debug_macinfo_section
= get_section (dwarf_strict
21879 ? DEBUG_MACINFO_SECTION
21880 : DEBUG_MACRO_SECTION
,
21881 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
21882 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
21883 SECTION_DEBUG
, NULL
);
21884 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
21885 SECTION_DEBUG
, NULL
);
21886 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
21887 SECTION_DEBUG
, NULL
);
21888 debug_str_section
= get_section (DEBUG_STR_SECTION
,
21889 DEBUG_STR_SECTION_FLAGS
, NULL
);
21890 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
21891 SECTION_DEBUG
, NULL
);
21892 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
21893 SECTION_DEBUG
, NULL
);
21895 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
21896 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
21897 DEBUG_ABBREV_SECTION_LABEL
, 0);
21898 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
21899 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
21900 COLD_TEXT_SECTION_LABEL
, 0);
21901 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
21903 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
21904 DEBUG_INFO_SECTION_LABEL
, 0);
21905 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
21906 DEBUG_LINE_SECTION_LABEL
, 0);
21907 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
21908 DEBUG_RANGES_SECTION_LABEL
, 0);
21909 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
21910 DEBUG_ADDR_SECTION_LABEL
, 0);
21911 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
21913 ? DEBUG_MACINFO_SECTION_LABEL
21914 : DEBUG_MACRO_SECTION_LABEL
, 0);
21915 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
21917 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21918 vec_alloc (macinfo_table
, 64);
21920 switch_to_section (text_section
);
21921 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
21923 /* Make sure the line number table for .text always exists. */
21924 text_section_line_info
= new_line_info_table ();
21925 text_section_line_info
->end_label
= text_end_label
;
21928 /* Called before compile () starts outputtting functions, variables
21929 and toplevel asms into assembly. */
21932 dwarf2out_assembly_start (void)
21934 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
21935 && dwarf2out_do_cfi_asm ()
21936 && (!(flag_unwind_tables
|| flag_exceptions
)
21937 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
21938 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
21941 /* A helper function for dwarf2out_finish called through
21942 htab_traverse. Assign a string its index. All strings must be
21943 collected into the table by the time index_string is called,
21944 because the indexing code relies on htab_traverse to traverse nodes
21945 in the same order for each run. */
21948 index_string (void **h
, void *v
)
21950 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21951 unsigned int *index
= (unsigned int *) v
;
21953 find_string_form (node
);
21954 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21956 gcc_assert(node
->index
== NO_INDEX_ASSIGNED
);
21957 node
->index
= *index
;
21963 /* A helper function for output_indirect_strings called through
21964 htab_traverse. Output the offset to a string and update the
21968 output_index_string_offset (void **h
, void *v
)
21970 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21971 unsigned int *offset
= (unsigned int *) v
;
21973 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21975 /* Assert that this node has been assigned an index. */
21976 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
21977 && node
->index
!= NOT_INDEXED
);
21978 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
21979 "indexed string 0x%x: %s", node
->index
, node
->str
);
21980 *offset
+= strlen (node
->str
) + 1;
21985 /* A helper function for dwarf2out_finish called through
21986 htab_traverse. Output the indexed string. */
21989 output_index_string (void **h
, void *v
)
21991 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21992 unsigned int *cur_idx
= (unsigned int *) v
;
21994 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21996 /* Assert that the strings are output in the same order as their
21997 indexes were assigned. */
21998 gcc_assert (*cur_idx
== node
->index
);
21999 assemble_string (node
->str
, strlen (node
->str
) + 1);
22005 /* A helper function for dwarf2out_finish called through
22006 htab_traverse. Emit one queued .debug_str string. */
22009 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
22011 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22013 node
->form
= find_string_form (node
);
22014 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
22016 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
22017 assemble_string (node
->str
, strlen (node
->str
) + 1);
22023 /* Output the indexed string table. */
22026 output_indirect_strings (void)
22028 switch_to_section (debug_str_section
);
22029 if (!dwarf_split_debug_info
)
22030 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
22033 unsigned int offset
= 0;
22034 unsigned int cur_idx
= 0;
22036 htab_traverse (skeleton_debug_str_hash
, output_indirect_string
, NULL
);
22038 switch_to_section (debug_str_offsets_section
);
22039 htab_traverse_noresize (debug_str_hash
,
22040 output_index_string_offset
,
22042 switch_to_section (debug_str_dwo_section
);
22043 htab_traverse_noresize (debug_str_hash
,
22044 output_index_string
,
22049 /* Callback for htab_traverse to assign an index to an entry in the
22050 table, and to write that entry to the .debug_addr section. */
22053 output_addr_table_entry (void **slot
, void *data
)
22055 addr_table_entry
*entry
= (addr_table_entry
*) *slot
;
22056 unsigned int *cur_index
= (unsigned int *)data
;
22058 if (entry
->refcount
== 0)
22060 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
22061 || entry
->index
== NOT_INDEXED
);
22065 gcc_assert (entry
->index
== *cur_index
);
22068 switch (entry
->kind
)
22071 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
22072 "0x%x", entry
->index
);
22074 case ate_kind_rtx_dtprel
:
22075 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
22076 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
22079 fputc ('\n', asm_out_file
);
22081 case ate_kind_label
:
22082 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
22083 "0x%x", entry
->index
);
22086 gcc_unreachable ();
22091 /* Produce the .debug_addr section. */
22094 output_addr_table (void)
22096 unsigned int index
= 0;
22097 if (addr_index_table
== NULL
|| htab_size (addr_index_table
) == 0)
22100 switch_to_section (debug_addr_section
);
22101 htab_traverse_noresize (addr_index_table
, output_addr_table_entry
, &index
);
22104 #if ENABLE_ASSERT_CHECKING
22105 /* Verify that all marks are clear. */
22108 verify_marks_clear (dw_die_ref die
)
22112 gcc_assert (! die
->die_mark
);
22113 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
22115 #endif /* ENABLE_ASSERT_CHECKING */
22117 /* Clear the marks for a die and its children.
22118 Be cool if the mark isn't set. */
22121 prune_unmark_dies (dw_die_ref die
)
22127 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
22130 /* Given DIE that we're marking as used, find any other dies
22131 it references as attributes and mark them as used. */
22134 prune_unused_types_walk_attribs (dw_die_ref die
)
22139 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22141 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
22143 /* A reference to another DIE.
22144 Make sure that it will get emitted.
22145 If it was broken out into a comdat group, don't follow it. */
22146 if (! AT_ref (a
)->comdat_type_p
22147 || a
->dw_attr
== DW_AT_specification
)
22148 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
22150 /* Set the string's refcount to 0 so that prune_unused_types_mark
22151 accounts properly for it. */
22152 if (AT_class (a
) == dw_val_class_str
)
22153 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
22157 /* Mark the generic parameters and arguments children DIEs of DIE. */
22160 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
22164 if (die
== NULL
|| die
->die_child
== NULL
)
22166 c
= die
->die_child
;
22169 switch (c
->die_tag
)
22171 case DW_TAG_template_type_param
:
22172 case DW_TAG_template_value_param
:
22173 case DW_TAG_GNU_template_template_param
:
22174 case DW_TAG_GNU_template_parameter_pack
:
22175 prune_unused_types_mark (c
, 1);
22181 } while (c
&& c
!= die
->die_child
);
22184 /* Mark DIE as being used. If DOKIDS is true, then walk down
22185 to DIE's children. */
22188 prune_unused_types_mark (dw_die_ref die
, int dokids
)
22192 if (die
->die_mark
== 0)
22194 /* We haven't done this node yet. Mark it as used. */
22196 /* If this is the DIE of a generic type instantiation,
22197 mark the children DIEs that describe its generic parms and
22199 prune_unused_types_mark_generic_parms_dies (die
);
22201 /* We also have to mark its parents as used.
22202 (But we don't want to mark our parent's kids due to this,
22203 unless it is a class.) */
22204 if (die
->die_parent
)
22205 prune_unused_types_mark (die
->die_parent
,
22206 class_scope_p (die
->die_parent
));
22208 /* Mark any referenced nodes. */
22209 prune_unused_types_walk_attribs (die
);
22211 /* If this node is a specification,
22212 also mark the definition, if it exists. */
22213 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
22214 prune_unused_types_mark (die
->die_definition
, 1);
22217 if (dokids
&& die
->die_mark
!= 2)
22219 /* We need to walk the children, but haven't done so yet.
22220 Remember that we've walked the kids. */
22223 /* If this is an array type, we need to make sure our
22224 kids get marked, even if they're types. If we're
22225 breaking out types into comdat sections, do this
22226 for all type definitions. */
22227 if (die
->die_tag
== DW_TAG_array_type
22228 || (use_debug_types
22229 && is_type_die (die
) && ! is_declaration_die (die
)))
22230 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
22232 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22236 /* For local classes, look if any static member functions were emitted
22237 and if so, mark them. */
22240 prune_unused_types_walk_local_classes (dw_die_ref die
)
22244 if (die
->die_mark
== 2)
22247 switch (die
->die_tag
)
22249 case DW_TAG_structure_type
:
22250 case DW_TAG_union_type
:
22251 case DW_TAG_class_type
:
22254 case DW_TAG_subprogram
:
22255 if (!get_AT_flag (die
, DW_AT_declaration
)
22256 || die
->die_definition
!= NULL
)
22257 prune_unused_types_mark (die
, 1);
22264 /* Mark children. */
22265 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
22268 /* Walk the tree DIE and mark types that we actually use. */
22271 prune_unused_types_walk (dw_die_ref die
)
22275 /* Don't do anything if this node is already marked and
22276 children have been marked as well. */
22277 if (die
->die_mark
== 2)
22280 switch (die
->die_tag
)
22282 case DW_TAG_structure_type
:
22283 case DW_TAG_union_type
:
22284 case DW_TAG_class_type
:
22285 if (die
->die_perennial_p
)
22288 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
22289 if (c
->die_tag
== DW_TAG_subprogram
)
22292 /* Finding used static member functions inside of classes
22293 is needed just for local classes, because for other classes
22294 static member function DIEs with DW_AT_specification
22295 are emitted outside of the DW_TAG_*_type. If we ever change
22296 it, we'd need to call this even for non-local classes. */
22298 prune_unused_types_walk_local_classes (die
);
22300 /* It's a type node --- don't mark it. */
22303 case DW_TAG_const_type
:
22304 case DW_TAG_packed_type
:
22305 case DW_TAG_pointer_type
:
22306 case DW_TAG_reference_type
:
22307 case DW_TAG_rvalue_reference_type
:
22308 case DW_TAG_volatile_type
:
22309 case DW_TAG_typedef
:
22310 case DW_TAG_array_type
:
22311 case DW_TAG_interface_type
:
22312 case DW_TAG_friend
:
22313 case DW_TAG_variant_part
:
22314 case DW_TAG_enumeration_type
:
22315 case DW_TAG_subroutine_type
:
22316 case DW_TAG_string_type
:
22317 case DW_TAG_set_type
:
22318 case DW_TAG_subrange_type
:
22319 case DW_TAG_ptr_to_member_type
:
22320 case DW_TAG_file_type
:
22321 if (die
->die_perennial_p
)
22324 /* It's a type node --- don't mark it. */
22328 /* Mark everything else. */
22332 if (die
->die_mark
== 0)
22336 /* Now, mark any dies referenced from here. */
22337 prune_unused_types_walk_attribs (die
);
22342 /* Mark children. */
22343 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22346 /* Increment the string counts on strings referred to from DIE's
22350 prune_unused_types_update_strings (dw_die_ref die
)
22355 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22356 if (AT_class (a
) == dw_val_class_str
)
22358 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22360 /* Avoid unnecessarily putting strings that are used less than
22361 twice in the hash table. */
22363 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22366 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22367 htab_hash_string (s
->str
),
22369 gcc_assert (*slot
== NULL
);
22375 /* Remove from the tree DIE any dies that aren't marked. */
22378 prune_unused_types_prune (dw_die_ref die
)
22382 gcc_assert (die
->die_mark
);
22383 prune_unused_types_update_strings (die
);
22385 if (! die
->die_child
)
22388 c
= die
->die_child
;
22390 dw_die_ref prev
= c
;
22391 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22392 if (c
== die
->die_child
)
22394 /* No marked children between 'prev' and the end of the list. */
22396 /* No marked children at all. */
22397 die
->die_child
= NULL
;
22400 prev
->die_sib
= c
->die_sib
;
22401 die
->die_child
= prev
;
22406 if (c
!= prev
->die_sib
)
22408 prune_unused_types_prune (c
);
22409 } while (c
!= die
->die_child
);
22412 /* Remove dies representing declarations that we never use. */
22415 prune_unused_types (void)
22418 limbo_die_node
*node
;
22419 comdat_type_node
*ctnode
;
22421 dw_die_ref base_type
;
22423 #if ENABLE_ASSERT_CHECKING
22424 /* All the marks should already be clear. */
22425 verify_marks_clear (comp_unit_die ());
22426 for (node
= limbo_die_list
; node
; node
= node
->next
)
22427 verify_marks_clear (node
->die
);
22428 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22429 verify_marks_clear (ctnode
->root_die
);
22430 #endif /* ENABLE_ASSERT_CHECKING */
22432 /* Mark types that are used in global variables. */
22433 premark_types_used_by_global_vars ();
22435 /* Set the mark on nodes that are actually used. */
22436 prune_unused_types_walk (comp_unit_die ());
22437 for (node
= limbo_die_list
; node
; node
= node
->next
)
22438 prune_unused_types_walk (node
->die
);
22439 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22441 prune_unused_types_walk (ctnode
->root_die
);
22442 prune_unused_types_mark (ctnode
->type_die
, 1);
22445 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
22446 are unusual in that they are pubnames that are the children of pubtypes.
22447 They should only be marked via their parent DW_TAG_enumeration_type die,
22448 not as roots in themselves. */
22449 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
22450 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
22451 prune_unused_types_mark (pub
->die
, 1);
22452 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22453 prune_unused_types_mark (base_type
, 1);
22455 if (debug_str_hash
)
22456 htab_empty (debug_str_hash
);
22457 if (skeleton_debug_str_hash
)
22458 htab_empty (skeleton_debug_str_hash
);
22459 prune_unused_types_prune (comp_unit_die ());
22460 for (node
= limbo_die_list
; node
; node
= node
->next
)
22461 prune_unused_types_prune (node
->die
);
22462 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22463 prune_unused_types_prune (ctnode
->root_die
);
22465 /* Leave the marks clear. */
22466 prune_unmark_dies (comp_unit_die ());
22467 for (node
= limbo_die_list
; node
; node
= node
->next
)
22468 prune_unmark_dies (node
->die
);
22469 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22470 prune_unmark_dies (ctnode
->root_die
);
22473 /* Set the parameter to true if there are any relative pathnames in
22476 file_table_relative_p (void ** slot
, void *param
)
22478 bool *p
= (bool *) param
;
22479 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22480 if (!IS_ABSOLUTE_PATH (d
->filename
))
22488 /* Routines to manipulate hash table of comdat type units. */
22491 htab_ct_hash (const void *of
)
22494 const comdat_type_node
*const type_node
= (const comdat_type_node
*) of
;
22496 memcpy (&h
, type_node
->signature
, sizeof (h
));
22501 htab_ct_eq (const void *of1
, const void *of2
)
22503 const comdat_type_node
*const type_node_1
= (const comdat_type_node
*) of1
;
22504 const comdat_type_node
*const type_node_2
= (const comdat_type_node
*) of2
;
22506 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22507 DWARF_TYPE_SIGNATURE_SIZE
));
22510 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22511 to the location it would have been added, should we know its
22512 DECL_ASSEMBLER_NAME when we added other attributes. This will
22513 probably improve compactness of debug info, removing equivalent
22514 abbrevs, and hide any differences caused by deferring the
22515 computation of the assembler name, triggered by e.g. PCH. */
22518 move_linkage_attr (dw_die_ref die
)
22520 unsigned ix
= vec_safe_length (die
->die_attr
);
22521 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
22523 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22524 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22528 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
22530 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22534 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
22536 die
->die_attr
->pop ();
22537 die
->die_attr
->quick_insert (ix
, linkage
);
22541 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
22542 referenced from typed stack ops and count how often they are used. */
22545 mark_base_types (dw_loc_descr_ref loc
)
22547 dw_die_ref base_type
= NULL
;
22549 for (; loc
; loc
= loc
->dw_loc_next
)
22551 switch (loc
->dw_loc_opc
)
22553 case DW_OP_GNU_regval_type
:
22554 case DW_OP_GNU_deref_type
:
22555 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22557 case DW_OP_GNU_convert
:
22558 case DW_OP_GNU_reinterpret
:
22559 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
22562 case DW_OP_GNU_const_type
:
22563 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22565 case DW_OP_GNU_entry_value
:
22566 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
22571 gcc_assert (base_type
->die_parent
== comp_unit_die ());
22572 if (base_type
->die_mark
)
22573 base_type
->die_mark
++;
22576 base_types
.safe_push (base_type
);
22577 base_type
->die_mark
= 1;
22582 /* Comparison function for sorting marked base types. */
22585 base_type_cmp (const void *x
, const void *y
)
22587 dw_die_ref dx
= *(const dw_die_ref
*) x
;
22588 dw_die_ref dy
= *(const dw_die_ref
*) y
;
22589 unsigned int byte_size1
, byte_size2
;
22590 unsigned int encoding1
, encoding2
;
22591 if (dx
->die_mark
> dy
->die_mark
)
22593 if (dx
->die_mark
< dy
->die_mark
)
22595 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
22596 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
22597 if (byte_size1
< byte_size2
)
22599 if (byte_size1
> byte_size2
)
22601 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
22602 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
22603 if (encoding1
< encoding2
)
22605 if (encoding1
> encoding2
)
22610 /* Move base types marked by mark_base_types as early as possible
22611 in the CU, sorted by decreasing usage count both to make the
22612 uleb128 references as small as possible and to make sure they
22613 will have die_offset already computed by calc_die_sizes when
22614 sizes of typed stack loc ops is computed. */
22617 move_marked_base_types (void)
22620 dw_die_ref base_type
, die
, c
;
22622 if (base_types
.is_empty ())
22625 /* Sort by decreasing usage count, they will be added again in that
22627 base_types
.qsort (base_type_cmp
);
22628 die
= comp_unit_die ();
22629 c
= die
->die_child
;
22632 dw_die_ref prev
= c
;
22634 while (c
->die_mark
)
22636 remove_child_with_prev (c
, prev
);
22637 /* As base types got marked, there must be at least
22638 one node other than DW_TAG_base_type. */
22639 gcc_assert (c
!= c
->die_sib
);
22643 while (c
!= die
->die_child
);
22644 gcc_assert (die
->die_child
);
22645 c
= die
->die_child
;
22646 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22648 base_type
->die_mark
= 0;
22649 base_type
->die_sib
= c
->die_sib
;
22650 c
->die_sib
= base_type
;
22655 /* Helper function for resolve_addr, attempt to resolve
22656 one CONST_STRING, return non-zero if not successful. Similarly verify that
22657 SYMBOL_REFs refer to variables emitted in the current CU. */
22660 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
22664 if (GET_CODE (rtl
) == CONST_STRING
)
22666 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22667 tree t
= build_string (len
, XSTR (rtl
, 0));
22668 tree tlen
= size_int (len
- 1);
22670 = build_array_type (char_type_node
, build_index_type (tlen
));
22671 rtl
= lookup_constant_def (t
);
22672 if (!rtl
|| !MEM_P (rtl
))
22674 rtl
= XEXP (rtl
, 0);
22675 vec_safe_push (used_rtx_array
, rtl
);
22680 if (GET_CODE (rtl
) == SYMBOL_REF
22681 && SYMBOL_REF_DECL (rtl
))
22683 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
22685 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
22688 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22692 if (GET_CODE (rtl
) == CONST
22693 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
22699 /* Helper function for resolve_addr, handle one location
22700 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22701 the location list couldn't be resolved. */
22704 resolve_addr_in_expr (dw_loc_descr_ref loc
)
22706 dw_loc_descr_ref keep
= NULL
;
22707 for (; loc
; loc
= loc
->dw_loc_next
)
22708 switch (loc
->dw_loc_opc
)
22711 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22714 case DW_OP_GNU_addr_index
:
22715 case DW_OP_GNU_const_index
:
22717 if ((loc
->dw_loc_opc
== DW_OP_GNU_addr_index
22718 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
22719 && resolve_one_addr (&loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
,
22724 case DW_OP_const4u
:
22725 case DW_OP_const8u
:
22727 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22730 case DW_OP_plus_uconst
:
22731 if (size_of_loc_descr (loc
)
22732 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
22734 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
22736 dw_loc_descr_ref repl
22737 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
22738 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
22739 add_loc_descr (&repl
, loc
->dw_loc_next
);
22743 case DW_OP_implicit_value
:
22744 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
22745 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
22748 case DW_OP_GNU_implicit_pointer
:
22749 case DW_OP_GNU_parameter_ref
:
22750 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
22753 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
22756 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22757 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22758 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22761 case DW_OP_GNU_const_type
:
22762 case DW_OP_GNU_regval_type
:
22763 case DW_OP_GNU_deref_type
:
22764 case DW_OP_GNU_convert
:
22765 case DW_OP_GNU_reinterpret
:
22766 while (loc
->dw_loc_next
22767 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
22769 dw_die_ref base1
, base2
;
22770 unsigned enc1
, enc2
, size1
, size2
;
22771 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22772 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22773 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22774 else if (loc
->dw_loc_oprnd1
.val_class
22775 == dw_val_class_unsigned_const
)
22778 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22779 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
22780 == dw_val_class_unsigned_const
)
22782 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22783 gcc_assert (base1
->die_tag
== DW_TAG_base_type
22784 && base2
->die_tag
== DW_TAG_base_type
);
22785 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
22786 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
22787 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
22788 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
22790 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
22791 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
22795 /* Optimize away next DW_OP_GNU_convert after
22796 adjusting LOC's base type die reference. */
22797 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22798 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22799 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
22801 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
22802 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
22805 /* Don't change integer DW_OP_GNU_convert after e.g. floating
22806 point typed stack entry. */
22807 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
22808 keep
= loc
->dw_loc_next
;
22818 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
22819 an address in .rodata section if the string literal is emitted there,
22820 or remove the containing location list or replace DW_AT_const_value
22821 with DW_AT_location and empty location expression, if it isn't found
22822 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
22823 to something that has been emitted in the current CU. */
22826 resolve_addr (dw_die_ref die
)
22830 dw_loc_list_ref
*curr
, *start
, loc
;
22833 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22834 switch (AT_class (a
))
22836 case dw_val_class_loc_list
:
22837 start
= curr
= AT_loc_list_ptr (a
);
22840 /* The same list can be referenced more than once. See if we have
22841 already recorded the result from a previous pass. */
22843 *curr
= loc
->dw_loc_next
;
22844 else if (!loc
->resolved_addr
)
22846 /* As things stand, we do not expect or allow one die to
22847 reference a suffix of another die's location list chain.
22848 References must be identical or completely separate.
22849 There is therefore no need to cache the result of this
22850 pass on any list other than the first; doing so
22851 would lead to unnecessary writes. */
22854 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
22855 if (!resolve_addr_in_expr ((*curr
)->expr
))
22857 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
22858 dw_loc_descr_ref l
= (*curr
)->expr
;
22860 if (next
&& (*curr
)->ll_symbol
)
22862 gcc_assert (!next
->ll_symbol
);
22863 next
->ll_symbol
= (*curr
)->ll_symbol
;
22865 if (dwarf_split_debug_info
)
22866 remove_loc_list_addr_table_entries (l
);
22871 mark_base_types ((*curr
)->expr
);
22872 curr
= &(*curr
)->dw_loc_next
;
22876 loc
->resolved_addr
= 1;
22880 loc
->dw_loc_next
= *start
;
22885 remove_AT (die
, a
->dw_attr
);
22889 case dw_val_class_loc
:
22891 dw_loc_descr_ref l
= AT_loc (a
);
22892 /* For -gdwarf-2 don't attempt to optimize
22893 DW_AT_data_member_location containing
22894 DW_OP_plus_uconst - older consumers might
22895 rely on it being that op instead of a more complex,
22896 but shorter, location description. */
22897 if ((dwarf_version
> 2
22898 || a
->dw_attr
!= DW_AT_data_member_location
22900 || l
->dw_loc_opc
!= DW_OP_plus_uconst
22901 || l
->dw_loc_next
!= NULL
)
22902 && !resolve_addr_in_expr (l
))
22904 if (dwarf_split_debug_info
)
22905 remove_loc_list_addr_table_entries (l
);
22906 remove_AT (die
, a
->dw_attr
);
22910 mark_base_types (l
);
22913 case dw_val_class_addr
:
22914 if (a
->dw_attr
== DW_AT_const_value
22915 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
22917 if (AT_index (a
) != NOT_INDEXED
)
22918 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
22919 remove_AT (die
, a
->dw_attr
);
22922 if (die
->die_tag
== DW_TAG_GNU_call_site
22923 && a
->dw_attr
== DW_AT_abstract_origin
)
22925 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
22926 dw_die_ref tdie
= lookup_decl_die (tdecl
);
22928 && DECL_EXTERNAL (tdecl
)
22929 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
22931 force_decl_die (tdecl
);
22932 tdie
= lookup_decl_die (tdecl
);
22936 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
22937 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
22938 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
22942 if (AT_index (a
) != NOT_INDEXED
)
22943 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
22944 remove_AT (die
, a
->dw_attr
);
22953 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
22956 /* Helper routines for optimize_location_lists.
22957 This pass tries to share identical local lists in .debug_loc
22960 /* Iteratively hash operands of LOC opcode. */
22962 static inline hashval_t
22963 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
22965 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
22966 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
22968 switch (loc
->dw_loc_opc
)
22970 case DW_OP_const4u
:
22971 case DW_OP_const8u
:
22975 case DW_OP_const1u
:
22976 case DW_OP_const1s
:
22977 case DW_OP_const2u
:
22978 case DW_OP_const2s
:
22979 case DW_OP_const4s
:
22980 case DW_OP_const8s
:
22984 case DW_OP_plus_uconst
:
23020 case DW_OP_deref_size
:
23021 case DW_OP_xderef_size
:
23022 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23029 gcc_assert (val1
->val_class
== dw_val_class_loc
);
23030 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
23031 hash
= iterative_hash_object (offset
, hash
);
23034 case DW_OP_implicit_value
:
23035 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23036 switch (val2
->val_class
)
23038 case dw_val_class_const
:
23039 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23041 case dw_val_class_vec
:
23043 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23044 unsigned int len
= val2
->v
.val_vec
.length
;
23046 hash
= iterative_hash_object (elt_size
, hash
);
23047 hash
= iterative_hash_object (len
, hash
);
23048 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23049 len
* elt_size
, hash
);
23052 case dw_val_class_const_double
:
23053 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23054 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23056 case dw_val_class_addr
:
23057 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
23060 gcc_unreachable ();
23064 case DW_OP_bit_piece
:
23065 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23066 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23072 unsigned char dtprel
= 0xd1;
23073 hash
= iterative_hash_object (dtprel
, hash
);
23075 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
23077 case DW_OP_GNU_addr_index
:
23078 case DW_OP_GNU_const_index
:
23082 unsigned char dtprel
= 0xd1;
23083 hash
= iterative_hash_object (dtprel
, hash
);
23085 hash
= iterative_hash_rtx (val1
->val_entry
->addr
.rtl
, hash
);
23088 case DW_OP_GNU_implicit_pointer
:
23089 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23091 case DW_OP_GNU_entry_value
:
23092 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
23094 case DW_OP_GNU_regval_type
:
23095 case DW_OP_GNU_deref_type
:
23097 unsigned int byte_size
23098 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23099 unsigned int encoding
23100 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
23101 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23102 hash
= iterative_hash_object (byte_size
, hash
);
23103 hash
= iterative_hash_object (encoding
, hash
);
23106 case DW_OP_GNU_convert
:
23107 case DW_OP_GNU_reinterpret
:
23108 if (val1
->val_class
== dw_val_class_unsigned_const
)
23110 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23114 case DW_OP_GNU_const_type
:
23116 unsigned int byte_size
23117 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23118 unsigned int encoding
23119 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
23120 hash
= iterative_hash_object (byte_size
, hash
);
23121 hash
= iterative_hash_object (encoding
, hash
);
23122 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
23124 hash
= iterative_hash_object (val2
->val_class
, hash
);
23125 switch (val2
->val_class
)
23127 case dw_val_class_const
:
23128 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23130 case dw_val_class_vec
:
23132 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23133 unsigned int len
= val2
->v
.val_vec
.length
;
23135 hash
= iterative_hash_object (elt_size
, hash
);
23136 hash
= iterative_hash_object (len
, hash
);
23137 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23138 len
* elt_size
, hash
);
23141 case dw_val_class_const_double
:
23142 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23143 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23146 gcc_unreachable ();
23152 /* Other codes have no operands. */
23158 /* Iteratively hash the whole DWARF location expression LOC. */
23160 static inline hashval_t
23161 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
23163 dw_loc_descr_ref l
;
23164 bool sizes_computed
= false;
23165 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23166 size_of_locs (loc
);
23168 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
23170 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
23171 hash
= iterative_hash_object (opc
, hash
);
23172 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
23174 size_of_locs (loc
);
23175 sizes_computed
= true;
23177 hash
= hash_loc_operands (l
, hash
);
23182 /* Compute hash of the whole location list LIST_HEAD. */
23185 hash_loc_list (dw_loc_list_ref list_head
)
23187 dw_loc_list_ref curr
= list_head
;
23188 hashval_t hash
= 0;
23190 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23192 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
23193 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
23195 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
23197 hash
= hash_locs (curr
->expr
, hash
);
23199 list_head
->hash
= hash
;
23202 /* Return true if X and Y opcodes have the same operands. */
23205 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23207 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
23208 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
23209 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
23210 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
23212 switch (x
->dw_loc_opc
)
23214 case DW_OP_const4u
:
23215 case DW_OP_const8u
:
23219 case DW_OP_const1u
:
23220 case DW_OP_const1s
:
23221 case DW_OP_const2u
:
23222 case DW_OP_const2s
:
23223 case DW_OP_const4s
:
23224 case DW_OP_const8s
:
23228 case DW_OP_plus_uconst
:
23264 case DW_OP_deref_size
:
23265 case DW_OP_xderef_size
:
23266 return valx1
->v
.val_int
== valy1
->v
.val_int
;
23269 /* If splitting debug info, the use of DW_OP_GNU_addr_index
23270 can cause irrelevant differences in dw_loc_addr. */
23271 gcc_assert (valx1
->val_class
== dw_val_class_loc
23272 && valy1
->val_class
== dw_val_class_loc
23273 && (dwarf_split_debug_info
23274 || x
->dw_loc_addr
== y
->dw_loc_addr
));
23275 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
23276 case DW_OP_implicit_value
:
23277 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
23278 || valx2
->val_class
!= valy2
->val_class
)
23280 switch (valx2
->val_class
)
23282 case dw_val_class_const
:
23283 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23284 case dw_val_class_vec
:
23285 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23286 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23287 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23288 valx2
->v
.val_vec
.elt_size
23289 * valx2
->v
.val_vec
.length
) == 0;
23290 case dw_val_class_const_double
:
23291 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23292 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23293 case dw_val_class_addr
:
23294 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
23296 gcc_unreachable ();
23299 case DW_OP_bit_piece
:
23300 return valx1
->v
.val_int
== valy1
->v
.val_int
23301 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23304 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
23305 case DW_OP_GNU_addr_index
:
23306 case DW_OP_GNU_const_index
:
23308 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
23309 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
23310 return rtx_equal_p (ax1
, ay1
);
23312 case DW_OP_GNU_implicit_pointer
:
23313 return valx1
->val_class
== dw_val_class_die_ref
23314 && valx1
->val_class
== valy1
->val_class
23315 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
23316 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23317 case DW_OP_GNU_entry_value
:
23318 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
23319 case DW_OP_GNU_const_type
:
23320 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
23321 || valx2
->val_class
!= valy2
->val_class
)
23323 switch (valx2
->val_class
)
23325 case dw_val_class_const
:
23326 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23327 case dw_val_class_vec
:
23328 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23329 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23330 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23331 valx2
->v
.val_vec
.elt_size
23332 * valx2
->v
.val_vec
.length
) == 0;
23333 case dw_val_class_const_double
:
23334 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23335 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23337 gcc_unreachable ();
23339 case DW_OP_GNU_regval_type
:
23340 case DW_OP_GNU_deref_type
:
23341 return valx1
->v
.val_int
== valy1
->v
.val_int
23342 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
23343 case DW_OP_GNU_convert
:
23344 case DW_OP_GNU_reinterpret
:
23345 if (valx1
->val_class
!= valy1
->val_class
)
23347 if (valx1
->val_class
== dw_val_class_unsigned_const
)
23348 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
23349 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23350 case DW_OP_GNU_parameter_ref
:
23351 return valx1
->val_class
== dw_val_class_die_ref
23352 && valx1
->val_class
== valy1
->val_class
23353 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23355 /* Other codes have no operands. */
23360 /* Return true if DWARF location expressions X and Y are the same. */
23363 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23365 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
23366 if (x
->dw_loc_opc
!= y
->dw_loc_opc
23367 || x
->dtprel
!= y
->dtprel
23368 || !compare_loc_operands (x
, y
))
23370 return x
== NULL
&& y
== NULL
;
23373 /* Return precomputed hash of location list X. */
23376 loc_list_hash (const void *x
)
23378 return ((const struct dw_loc_list_struct
*) x
)->hash
;
23381 /* Return 1 if location lists X and Y are the same. */
23384 loc_list_eq (const void *x
, const void *y
)
23386 const struct dw_loc_list_struct
*a
= (const struct dw_loc_list_struct
*) x
;
23387 const struct dw_loc_list_struct
*b
= (const struct dw_loc_list_struct
*) y
;
23390 if (a
->hash
!= b
->hash
)
23392 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
23393 if (strcmp (a
->begin
, b
->begin
) != 0
23394 || strcmp (a
->end
, b
->end
) != 0
23395 || (a
->section
== NULL
) != (b
->section
== NULL
)
23396 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
23397 || !compare_locs (a
->expr
, b
->expr
))
23399 return a
== NULL
&& b
== NULL
;
23402 /* Recursively optimize location lists referenced from DIE
23403 children and share them whenever possible. */
23406 optimize_location_lists_1 (dw_die_ref die
, htab_t htab
)
23413 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23414 if (AT_class (a
) == dw_val_class_loc_list
)
23416 dw_loc_list_ref list
= AT_loc_list (a
);
23417 /* TODO: perform some optimizations here, before hashing
23418 it and storing into the hash table. */
23419 hash_loc_list (list
);
23420 slot
= htab_find_slot_with_hash (htab
, list
, list
->hash
,
23423 *slot
= (void *) list
;
23425 a
->dw_attr_val
.v
.val_loc_list
= (dw_loc_list_ref
) *slot
;
23428 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
23432 /* Recursively assign each location list a unique index into the debug_addr
23436 index_location_lists (dw_die_ref die
)
23442 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23443 if (AT_class (a
) == dw_val_class_loc_list
)
23445 dw_loc_list_ref list
= AT_loc_list (a
);
23446 dw_loc_list_ref curr
;
23447 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23449 /* Don't index an entry that has already been indexed
23450 or won't be output. */
23451 if (curr
->begin_entry
!= NULL
23452 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
23456 = add_addr_table_entry (xstrdup (curr
->begin
),
23461 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
23464 /* Optimize location lists referenced from DIE
23465 children and share them whenever possible. */
23468 optimize_location_lists (dw_die_ref die
)
23470 htab_t htab
= htab_create (500, loc_list_hash
, loc_list_eq
, NULL
);
23471 optimize_location_lists_1 (die
, htab
);
23472 htab_delete (htab
);
23475 /* Output stuff that dwarf requires at the end of every file,
23476 and generate the DWARF-2 debugging info. */
23479 dwarf2out_finish (const char *filename
)
23481 limbo_die_node
*node
, *next_node
;
23482 comdat_type_node
*ctnode
;
23483 htab_t comdat_type_table
;
23485 dw_die_ref main_comp_unit_die
;
23487 /* PCH might result in DW_AT_producer string being restored from the
23488 header compilation, so always fill it with empty string initially
23489 and overwrite only here. */
23490 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
23491 producer_string
= gen_producer_string ();
23492 producer
->dw_attr_val
.v
.val_str
->refcount
--;
23493 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
23495 gen_scheduled_generic_parms_dies ();
23496 gen_remaining_tmpl_value_param_die_attribute ();
23498 /* Add the name for the main input file now. We delayed this from
23499 dwarf2out_init to avoid complications with PCH. */
23500 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
23501 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
23502 add_comp_dir_attribute (comp_unit_die ());
23503 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
23506 htab_traverse (file_table
, file_table_relative_p
, &p
);
23508 add_comp_dir_attribute (comp_unit_die ());
23511 if (deferred_locations_list
)
23512 for (i
= 0; i
< deferred_locations_list
->length (); i
++)
23514 add_location_or_const_value_attribute (
23515 (*deferred_locations_list
)[i
].die
,
23516 (*deferred_locations_list
)[i
].variable
,
23521 /* Traverse the limbo die list, and add parent/child links. The only
23522 dies without parents that should be here are concrete instances of
23523 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23524 For concrete instances, we can get the parent die from the abstract
23526 for (node
= limbo_die_list
; node
; node
= next_node
)
23528 dw_die_ref die
= node
->die
;
23529 next_node
= node
->next
;
23531 if (die
->die_parent
== NULL
)
23533 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
23535 if (origin
&& origin
->die_parent
)
23536 add_child_die (origin
->die_parent
, die
);
23537 else if (is_cu_die (die
))
23539 else if (seen_error ())
23540 /* It's OK to be confused by errors in the input. */
23541 add_child_die (comp_unit_die (), die
);
23544 /* In certain situations, the lexical block containing a
23545 nested function can be optimized away, which results
23546 in the nested function die being orphaned. Likewise
23547 with the return type of that nested function. Force
23548 this to be a child of the containing function.
23550 It may happen that even the containing function got fully
23551 inlined and optimized out. In that case we are lost and
23552 assign the empty child. This should not be big issue as
23553 the function is likely unreachable too. */
23554 gcc_assert (node
->created_for
);
23556 if (DECL_P (node
->created_for
))
23557 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
23558 else if (TYPE_P (node
->created_for
))
23559 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
23561 origin
= comp_unit_die ();
23563 add_child_die (origin
, die
);
23568 limbo_die_list
= NULL
;
23570 #if ENABLE_ASSERT_CHECKING
23572 dw_die_ref die
= comp_unit_die (), c
;
23573 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
23576 resolve_addr (comp_unit_die ());
23577 move_marked_base_types ();
23579 for (node
= deferred_asm_name
; node
; node
= node
->next
)
23581 tree decl
= node
->created_for
;
23582 /* When generating LTO bytecode we can not generate new assembler
23583 names at this point and all important decls got theirs via
23585 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
23586 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
23588 add_linkage_attr (node
->die
, decl
);
23589 move_linkage_attr (node
->die
);
23593 deferred_asm_name
= NULL
;
23595 /* Walk through the list of incomplete types again, trying once more to
23596 emit full debugging info for them. */
23597 retry_incomplete_types ();
23599 if (flag_eliminate_unused_debug_types
)
23600 prune_unused_types ();
23602 /* Generate separate COMDAT sections for type DIEs. */
23603 if (use_debug_types
)
23605 break_out_comdat_types (comp_unit_die ());
23607 /* Each new type_unit DIE was added to the limbo die list when created.
23608 Since these have all been added to comdat_type_list, clear the
23610 limbo_die_list
= NULL
;
23612 /* For each new comdat type unit, copy declarations for incomplete
23613 types to make the new unit self-contained (i.e., no direct
23614 references to the main compile unit). */
23615 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23616 copy_decls_for_unworthy_types (ctnode
->root_die
);
23617 copy_decls_for_unworthy_types (comp_unit_die ());
23619 /* In the process of copying declarations from one unit to another,
23620 we may have left some declarations behind that are no longer
23621 referenced. Prune them. */
23622 prune_unused_types ();
23625 /* Generate separate CUs for each of the include files we've seen.
23626 They will go into limbo_die_list. */
23627 if (flag_eliminate_dwarf2_dups
)
23628 break_out_includes (comp_unit_die ());
23630 /* Traverse the DIE's and add add sibling attributes to those DIE's
23631 that have children. */
23632 add_sibling_attributes (comp_unit_die ());
23633 for (node
= limbo_die_list
; node
; node
= node
->next
)
23634 add_sibling_attributes (node
->die
);
23635 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23636 add_sibling_attributes (ctnode
->root_die
);
23638 /* When splitting DWARF info, we put some attributes in the
23639 skeleton compile_unit DIE that remains in the .o, while
23640 most attributes go in the DWO compile_unit_die. */
23641 if (dwarf_split_debug_info
)
23642 main_comp_unit_die
= gen_compile_unit_die (NULL
);
23644 main_comp_unit_die
= comp_unit_die ();
23646 /* Output a terminator label for the .text section. */
23647 switch_to_section (text_section
);
23648 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
23649 if (cold_text_section
)
23651 switch_to_section (cold_text_section
);
23652 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
23655 /* We can only use the low/high_pc attributes if all of the code was
23657 if (!have_multiple_function_sections
23658 || (dwarf_version
< 3 && dwarf_strict
))
23660 /* Don't add if the CU has no associated code. */
23661 if (text_section_used
)
23662 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
23663 text_end_label
, true);
23669 bool range_list_added
= false;
23671 if (text_section_used
)
23672 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
23673 text_end_label
, &range_list_added
, true);
23674 if (cold_text_section_used
)
23675 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
23676 cold_end_label
, &range_list_added
, true);
23678 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
23680 if (DECL_IGNORED_P (fde
->decl
))
23682 if (!fde
->in_std_section
)
23683 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
23684 fde
->dw_fde_end
, &range_list_added
,
23686 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
23687 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
23688 fde
->dw_fde_second_end
, &range_list_added
,
23692 if (range_list_added
)
23694 /* We need to give .debug_loc and .debug_ranges an appropriate
23695 "base address". Use zero so that these addresses become
23696 absolute. Historically, we've emitted the unexpected
23697 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23698 Emit both to give time for other tools to adapt. */
23699 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
23700 if (! dwarf_strict
&& dwarf_version
< 4)
23701 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
23707 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
23708 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
23709 debug_line_section_label
);
23712 add_AT_macptr (comp_unit_die (),
23713 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
23714 macinfo_section_label
);
23716 if (dwarf_split_debug_info
&& addr_index_table
!= NULL
)
23718 /* optimize_location_lists calculates the size of the lists,
23719 so index them first, and assign indices to the entries.
23720 Although optimize_location_lists will remove entries from
23721 the table, it only does so for duplicates, and therefore
23722 only reduces ref_counts to 1. */
23723 unsigned int index
= 0;
23724 index_location_lists (comp_unit_die ());
23725 htab_traverse_noresize (addr_index_table
,
23726 index_addr_table_entry
, &index
);
23728 if (have_location_lists
)
23729 optimize_location_lists (comp_unit_die ());
23731 save_macinfo_strings ();
23733 if (dwarf_split_debug_info
)
23735 unsigned int index
= 0;
23737 /* Add attributes common to skeleton compile_units and
23738 type_units. Because these attributes include strings, it
23739 must be done before freezing the string table. Top-level
23740 skeleton die attrs are added when the skeleton type unit is
23741 created, so ensure it is created by this point. */
23742 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
23743 (void) get_skeleton_type_unit ();
23744 htab_traverse_noresize (debug_str_hash
, index_string
, &index
);
23747 /* Output all of the compilation units. We put the main one last so that
23748 the offsets are available to output_pubnames. */
23749 for (node
= limbo_die_list
; node
; node
= node
->next
)
23750 output_comp_unit (node
->die
, 0);
23752 comdat_type_table
= htab_create (100, htab_ct_hash
, htab_ct_eq
, NULL
);
23753 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23755 void **slot
= htab_find_slot (comdat_type_table
, ctnode
, INSERT
);
23757 /* Don't output duplicate types. */
23758 if (*slot
!= HTAB_EMPTY_ENTRY
)
23761 /* Add a pointer to the line table for the main compilation unit
23762 so that the debugger can make sense of DW_AT_decl_file
23764 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
23765 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
23766 (!dwarf_split_debug_info
23767 ? debug_line_section_label
23768 : debug_skeleton_line_section_label
));
23770 output_comdat_type_unit (ctnode
);
23773 htab_delete (comdat_type_table
);
23775 /* The AT_pubnames attribute needs to go in all skeleton dies, including
23776 both the main_cu and all skeleton TUs. Making this call unconditional
23777 would end up either adding a second copy of the AT_pubnames attribute, or
23778 requiring a special case in add_top_level_skeleton_die_attrs. */
23779 if (!dwarf_split_debug_info
)
23780 add_AT_pubnames (comp_unit_die ());
23782 if (dwarf_split_debug_info
)
23785 unsigned char checksum
[16];
23786 struct md5_ctx ctx
;
23788 /* Compute a checksum of the comp_unit to use as the dwo_id. */
23789 md5_init_ctx (&ctx
);
23791 die_checksum (comp_unit_die (), &ctx
, &mark
);
23792 unmark_all_dies (comp_unit_die ());
23793 md5_finish_ctx (&ctx
, checksum
);
23795 /* Use the first 8 bytes of the checksum as the dwo_id,
23796 and add it to both comp-unit DIEs. */
23797 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
23798 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
23800 /* Add the base offset of the ranges table to the skeleton
23802 if (ranges_table_in_use
)
23803 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
23804 ranges_section_label
);
23806 switch_to_section (debug_addr_section
);
23807 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
23808 output_addr_table ();
23811 /* Output the main compilation unit if non-empty or if .debug_macinfo
23812 or .debug_macro will be emitted. */
23813 output_comp_unit (comp_unit_die (), have_macinfo
);
23815 if (dwarf_split_debug_info
&& info_section_emitted
)
23816 output_skeleton_debug_sections (main_comp_unit_die
);
23818 /* Output the abbreviation table. */
23819 if (abbrev_die_table_in_use
!= 1)
23821 switch_to_section (debug_abbrev_section
);
23822 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
23823 output_abbrev_section ();
23826 /* Output location list section if necessary. */
23827 if (have_location_lists
)
23829 /* Output the location lists info. */
23830 switch_to_section (debug_loc_section
);
23831 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
23832 output_location_lists (comp_unit_die ());
23835 /* Output public names and types tables if necessary. */
23836 output_pubnames (pubname_table
);
23837 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
23838 It shouldn't hurt to emit it always, since pure DWARF2 consumers
23839 simply won't look for the section. */
23840 output_pubnames (pubtype_table
);
23842 /* Output the address range information if a CU (.debug_info section)
23843 was emitted. We output an empty table even if we had no functions
23844 to put in it. This because the consumer has no way to tell the
23845 difference between an empty table that we omitted and failure to
23846 generate a table that would have contained data. */
23847 if (info_section_emitted
)
23849 unsigned long aranges_length
= size_of_aranges ();
23851 switch_to_section (debug_aranges_section
);
23852 output_aranges (aranges_length
);
23855 /* Output ranges section if necessary. */
23856 if (ranges_table_in_use
)
23858 switch_to_section (debug_ranges_section
);
23859 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
23863 /* Have to end the macro section. */
23866 switch_to_section (debug_macinfo_section
);
23867 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
23869 dw2_asm_output_data (1, 0, "End compilation unit");
23872 /* Output the source line correspondence table. We must do this
23873 even if there is no line information. Otherwise, on an empty
23874 translation unit, we will generate a present, but empty,
23875 .debug_info section. IRIX 6.5 `nm' will then complain when
23876 examining the file. This is done late so that any filenames
23877 used by the debug_info section are marked as 'used'. */
23878 switch_to_section (debug_line_section
);
23879 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
23880 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
23881 output_line_info (false);
23883 if (dwarf_split_debug_info
&& info_section_emitted
)
23885 switch_to_section (debug_skeleton_line_section
);
23886 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
23887 output_line_info (true);
23890 /* If we emitted any indirect strings, output the string table too. */
23891 if (debug_str_hash
|| skeleton_debug_str_hash
)
23892 output_indirect_strings ();
23895 #include "gt-dwarf2out.h"