1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2015 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 "fold-const.h"
67 #include "stringpool.h"
68 #include "stor-layout.h"
70 #include "hard-reg-set.h"
77 #include "insn-config.h"
88 #include "dwarf2out.h"
89 #include "dwarf2asm.h"
93 #include "diagnostic.h"
94 #include "tree-pretty-print.h"
97 #include "common/common-target.h"
98 #include "langhooks.h"
99 #include "plugin-api.h"
104 #include "dumpfile.h"
106 #include "tree-dfa.h"
107 #include "gdb/gdb-index.h"
108 #include "rtl-iter.h"
110 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
111 static rtx_insn
*last_var_location_insn
;
112 static rtx_insn
*cached_next_real_insn
;
113 static void dwarf2out_decl (tree
);
115 #ifdef VMS_DEBUGGING_INFO
116 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
118 /* Define this macro to be a nonzero value if the directory specifications
119 which are output in the debug info should end with a separator. */
120 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
121 /* Define this macro to evaluate to a nonzero value if GCC should refrain
122 from generating indirect strings in DWARF2 debug information, for instance
123 if your target is stuck with an old version of GDB that is unable to
124 process them properly or uses VMS Debug. */
125 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
127 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
128 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
131 /* ??? Poison these here until it can be done generically. They've been
132 totally replaced in this file; make sure it stays that way. */
133 #undef DWARF2_UNWIND_INFO
134 #undef DWARF2_FRAME_INFO
135 #if (GCC_VERSION >= 3000)
136 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
139 /* The size of the target's pointer type. */
141 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
144 /* Array of RTXes referenced by the debugging information, which therefore
145 must be kept around forever. */
146 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
148 /* A pointer to the base of a list of incomplete types which might be
149 completed at some later time. incomplete_types_list needs to be a
150 vec<tree, va_gc> *because we want to tell the garbage collector about
152 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
154 /* A pointer to the base of a table of references to declaration
155 scopes. This table is a display which tracks the nesting
156 of declaration scopes at the current scope and containing
157 scopes. This table is used to find the proper place to
158 define type declaration DIE's. */
159 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
161 /* Pointers to various DWARF2 sections. */
162 static GTY(()) section
*debug_info_section
;
163 static GTY(()) section
*debug_skeleton_info_section
;
164 static GTY(()) section
*debug_abbrev_section
;
165 static GTY(()) section
*debug_skeleton_abbrev_section
;
166 static GTY(()) section
*debug_aranges_section
;
167 static GTY(()) section
*debug_addr_section
;
168 static GTY(()) section
*debug_macinfo_section
;
169 static GTY(()) section
*debug_line_section
;
170 static GTY(()) section
*debug_skeleton_line_section
;
171 static GTY(()) section
*debug_loc_section
;
172 static GTY(()) section
*debug_pubnames_section
;
173 static GTY(()) section
*debug_pubtypes_section
;
174 static GTY(()) section
*debug_str_section
;
175 static GTY(()) section
*debug_str_dwo_section
;
176 static GTY(()) section
*debug_str_offsets_section
;
177 static GTY(()) section
*debug_ranges_section
;
178 static GTY(()) section
*debug_frame_section
;
180 /* Maximum size (in bytes) of an artificially generated label. */
181 #define MAX_ARTIFICIAL_LABEL_BYTES 30
183 /* According to the (draft) DWARF 3 specification, the initial length
184 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
185 bytes are 0xffffffff, followed by the length stored in the next 8
188 However, the SGI/MIPS ABI uses an initial length which is equal to
189 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
191 #ifndef DWARF_INITIAL_LENGTH_SIZE
192 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
195 /* Round SIZE up to the nearest BOUNDARY. */
196 #define DWARF_ROUND(SIZE,BOUNDARY) \
197 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
199 /* CIE identifier. */
200 #if HOST_BITS_PER_WIDE_INT >= 64
201 #define DWARF_CIE_ID \
202 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
204 #define DWARF_CIE_ID DW_CIE_ID
208 /* A vector for a table that contains frame description
209 information for each routine. */
210 #define NOT_INDEXED (-1U)
211 #define NO_INDEX_ASSIGNED (-2U)
213 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
215 struct GTY((for_user
)) indirect_string_node
{
217 unsigned int refcount
;
218 enum dwarf_form form
;
223 struct indirect_string_hasher
: ggc_ptr_hash
<indirect_string_node
>
225 typedef const char *compare_type
;
227 static hashval_t
hash (indirect_string_node
*);
228 static bool equal (indirect_string_node
*, const char *);
231 static GTY (()) hash_table
<indirect_string_hasher
> *debug_str_hash
;
233 /* With split_debug_info, both the comp_dir and dwo_name go in the
234 main object file, rather than the dwo, similar to the force_direct
235 parameter elsewhere but with additional complications:
237 1) The string is needed in both the main object file and the dwo.
238 That is, the comp_dir and dwo_name will appear in both places.
240 2) Strings can use three forms: DW_FORM_string, DW_FORM_strp or
241 DW_FORM_GNU_str_index.
243 3) GCC chooses the form to use late, depending on the size and
246 Rather than forcing the all debug string handling functions and
247 callers to deal with these complications, simply use a separate,
248 special-cased string table for any attribute that should go in the
249 main object file. This limits the complexity to just the places
252 static GTY (()) hash_table
<indirect_string_hasher
> *skeleton_debug_str_hash
;
254 static GTY(()) int dw2_string_counter
;
256 /* True if the compilation unit places functions in more than one section. */
257 static GTY(()) bool have_multiple_function_sections
= false;
259 /* Whether the default text and cold text sections have been used at all. */
261 static GTY(()) bool text_section_used
= false;
262 static GTY(()) bool cold_text_section_used
= false;
264 /* The default cold text section. */
265 static GTY(()) section
*cold_text_section
;
267 /* The DIE for C++14 'auto' in a function return type. */
268 static GTY(()) dw_die_ref auto_die
;
270 /* The DIE for C++14 'decltype(auto)' in a function return type. */
271 static GTY(()) dw_die_ref decltype_auto_die
;
273 /* Forward declarations for functions defined in this file. */
275 static char *stripattributes (const char *);
276 static void output_call_frame_info (int);
277 static void dwarf2out_note_section_used (void);
279 /* Personality decl of current unit. Used only when assembler does not support
281 static GTY(()) rtx current_unit_personality
;
283 /* Data and reference forms for relocatable data. */
284 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
285 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
287 #ifndef DEBUG_FRAME_SECTION
288 #define DEBUG_FRAME_SECTION ".debug_frame"
291 #ifndef FUNC_BEGIN_LABEL
292 #define FUNC_BEGIN_LABEL "LFB"
295 #ifndef FUNC_END_LABEL
296 #define FUNC_END_LABEL "LFE"
299 #ifndef PROLOGUE_END_LABEL
300 #define PROLOGUE_END_LABEL "LPE"
303 #ifndef EPILOGUE_BEGIN_LABEL
304 #define EPILOGUE_BEGIN_LABEL "LEB"
307 #ifndef FRAME_BEGIN_LABEL
308 #define FRAME_BEGIN_LABEL "Lframe"
310 #define CIE_AFTER_SIZE_LABEL "LSCIE"
311 #define CIE_END_LABEL "LECIE"
312 #define FDE_LABEL "LSFDE"
313 #define FDE_AFTER_SIZE_LABEL "LASFDE"
314 #define FDE_END_LABEL "LEFDE"
315 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
316 #define LINE_NUMBER_END_LABEL "LELT"
317 #define LN_PROLOG_AS_LABEL "LASLTP"
318 #define LN_PROLOG_END_LABEL "LELTP"
319 #define DIE_LABEL_PREFIX "DW"
321 /* Match the base name of a file to the base name of a compilation unit. */
324 matches_main_base (const char *path
)
326 /* Cache the last query. */
327 static const char *last_path
= NULL
;
328 static int last_match
= 0;
329 if (path
!= last_path
)
332 int length
= base_of_path (path
, &base
);
334 last_match
= (length
== main_input_baselength
335 && memcmp (base
, main_input_basename
, length
) == 0);
340 #ifdef DEBUG_DEBUG_STRUCT
343 dump_struct_debug (tree type
, enum debug_info_usage usage
,
344 enum debug_struct_file criterion
, int generic
,
345 int matches
, int result
)
347 /* Find the type name. */
348 tree type_decl
= TYPE_STUB_DECL (type
);
350 const char *name
= 0;
351 if (TREE_CODE (t
) == TYPE_DECL
)
354 name
= IDENTIFIER_POINTER (t
);
356 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
358 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
359 matches
? "bas" : "hdr",
360 generic
? "gen" : "ord",
361 usage
== DINFO_USAGE_DFN
? ";" :
362 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
364 (void*) type_decl
, name
);
367 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
368 dump_struct_debug (type, usage, criterion, generic, matches, result)
372 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
377 /* Get the number of HOST_WIDE_INTs needed to represent the precision
381 get_full_len (const wide_int
&op
)
383 return ((op
.get_precision () + HOST_BITS_PER_WIDE_INT
- 1)
384 / HOST_BITS_PER_WIDE_INT
);
388 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
390 enum debug_struct_file criterion
;
392 bool generic
= lang_hooks
.types
.generic_p (type
);
395 criterion
= debug_struct_generic
[usage
];
397 criterion
= debug_struct_ordinary
[usage
];
399 if (criterion
== DINFO_STRUCT_FILE_NONE
)
400 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
401 if (criterion
== DINFO_STRUCT_FILE_ANY
)
402 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
404 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
406 if (type_decl
!= NULL
)
408 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
409 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
411 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
412 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
415 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
418 /* Return a pointer to a copy of the section string name S with all
419 attributes stripped off, and an asterisk prepended (for assemble_name). */
422 stripattributes (const char *s
)
424 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
429 while (*s
&& *s
!= ',')
436 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
437 switch to the data section instead, and write out a synthetic start label
438 for collect2 the first time around. */
441 switch_to_eh_frame_section (bool back
)
445 #ifdef EH_FRAME_SECTION_NAME
446 if (eh_frame_section
== 0)
450 if (EH_TABLES_CAN_BE_READ_ONLY
)
456 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
458 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
460 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
463 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
464 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
465 && (per_encoding
& 0x70) != DW_EH_PE_absptr
466 && (per_encoding
& 0x70) != DW_EH_PE_aligned
467 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
468 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
469 ? 0 : SECTION_WRITE
);
472 flags
= SECTION_WRITE
;
473 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
475 #endif /* EH_FRAME_SECTION_NAME */
477 if (eh_frame_section
)
478 switch_to_section (eh_frame_section
);
481 /* We have no special eh_frame section. Put the information in
482 the data section and emit special labels to guide collect2. */
483 switch_to_section (data_section
);
487 label
= get_file_function_name ("F");
488 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
489 targetm
.asm_out
.globalize_label (asm_out_file
,
490 IDENTIFIER_POINTER (label
));
491 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
496 /* Switch [BACK] to the eh or debug frame table section, depending on
500 switch_to_frame_table_section (int for_eh
, bool back
)
503 switch_to_eh_frame_section (back
);
506 if (!debug_frame_section
)
507 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
508 SECTION_DEBUG
, NULL
);
509 switch_to_section (debug_frame_section
);
513 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
515 enum dw_cfi_oprnd_type
516 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
521 case DW_CFA_GNU_window_save
:
522 case DW_CFA_remember_state
:
523 case DW_CFA_restore_state
:
524 return dw_cfi_oprnd_unused
;
527 case DW_CFA_advance_loc1
:
528 case DW_CFA_advance_loc2
:
529 case DW_CFA_advance_loc4
:
530 case DW_CFA_MIPS_advance_loc8
:
531 return dw_cfi_oprnd_addr
;
534 case DW_CFA_offset_extended
:
536 case DW_CFA_offset_extended_sf
:
537 case DW_CFA_def_cfa_sf
:
539 case DW_CFA_restore_extended
:
540 case DW_CFA_undefined
:
541 case DW_CFA_same_value
:
542 case DW_CFA_def_cfa_register
:
543 case DW_CFA_register
:
544 case DW_CFA_expression
:
545 return dw_cfi_oprnd_reg_num
;
547 case DW_CFA_def_cfa_offset
:
548 case DW_CFA_GNU_args_size
:
549 case DW_CFA_def_cfa_offset_sf
:
550 return dw_cfi_oprnd_offset
;
552 case DW_CFA_def_cfa_expression
:
553 return dw_cfi_oprnd_loc
;
560 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
562 enum dw_cfi_oprnd_type
563 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
568 case DW_CFA_def_cfa_sf
:
570 case DW_CFA_offset_extended_sf
:
571 case DW_CFA_offset_extended
:
572 return dw_cfi_oprnd_offset
;
574 case DW_CFA_register
:
575 return dw_cfi_oprnd_reg_num
;
577 case DW_CFA_expression
:
578 return dw_cfi_oprnd_loc
;
581 return dw_cfi_oprnd_unused
;
585 /* Output one FDE. */
588 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
589 char *section_start_label
, int fde_encoding
, char *augmentation
,
590 bool any_lsda_needed
, int lsda_encoding
)
592 const char *begin
, *end
;
593 static unsigned int j
;
596 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
598 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
600 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
601 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
602 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
603 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
604 " indicating 64-bit DWARF extension");
605 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
607 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
610 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
612 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
613 debug_frame_section
, "FDE CIE offset");
615 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
616 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
620 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
621 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
622 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
623 "FDE initial location");
624 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
625 end
, begin
, "FDE address range");
629 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
630 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
637 int size
= size_of_encoded_value (lsda_encoding
);
639 if (lsda_encoding
== DW_EH_PE_aligned
)
641 int offset
= ( 4 /* Length */
643 + 2 * size_of_encoded_value (fde_encoding
)
644 + 1 /* Augmentation size */ );
645 int pad
= -offset
& (PTR_SIZE
- 1);
648 gcc_assert (size_of_uleb128 (size
) == 1);
651 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
653 if (fde
->uses_eh_lsda
)
655 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
656 fde
->funcdef_number
);
657 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
658 gen_rtx_SYMBOL_REF (Pmode
, l1
),
660 "Language Specific Data Area");
664 if (lsda_encoding
== DW_EH_PE_aligned
)
665 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
666 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
667 "Language Specific Data Area (none)");
671 dw2_asm_output_data_uleb128 (0, "Augmentation size");
674 /* Loop through the Call Frame Instructions associated with this FDE. */
675 fde
->dw_fde_current_label
= begin
;
677 size_t from
, until
, i
;
680 until
= vec_safe_length (fde
->dw_fde_cfi
);
682 if (fde
->dw_fde_second_begin
== NULL
)
685 until
= fde
->dw_fde_switch_cfi_index
;
687 from
= fde
->dw_fde_switch_cfi_index
;
689 for (i
= from
; i
< until
; i
++)
690 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
693 /* If we are to emit a ref/link from function bodies to their frame tables,
694 do it now. This is typically performed to make sure that tables
695 associated with functions are dragged with them and not discarded in
696 garbage collecting links. We need to do this on a per function basis to
697 cope with -ffunction-sections. */
699 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
700 /* Switch to the function section, emit the ref to the tables, and
701 switch *back* into the table section. */
702 switch_to_section (function_section (fde
->decl
));
703 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
704 switch_to_frame_table_section (for_eh
, true);
707 /* Pad the FDE out to an address sized boundary. */
708 ASM_OUTPUT_ALIGN (asm_out_file
,
709 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
710 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
715 /* Return true if frame description entry FDE is needed for EH. */
718 fde_needed_for_eh_p (dw_fde_ref fde
)
720 if (flag_asynchronous_unwind_tables
)
723 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
726 if (fde
->uses_eh_lsda
)
729 /* If exceptions are enabled, we have collected nothrow info. */
730 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
736 /* Output the call frame information used to record information
737 that relates to calculating the frame pointer, and records the
738 location of saved registers. */
741 output_call_frame_info (int for_eh
)
746 char l1
[20], l2
[20], section_start_label
[20];
747 bool any_lsda_needed
= false;
748 char augmentation
[6];
749 int augmentation_size
;
750 int fde_encoding
= DW_EH_PE_absptr
;
751 int per_encoding
= DW_EH_PE_absptr
;
752 int lsda_encoding
= DW_EH_PE_absptr
;
754 rtx personality
= NULL
;
757 /* Don't emit a CIE if there won't be any FDEs. */
761 /* Nothing to do if the assembler's doing it all. */
762 if (dwarf2out_do_cfi_asm ())
765 /* If we don't have any functions we'll want to unwind out of, don't emit
766 any EH unwind information. If we make FDEs linkonce, we may have to
767 emit an empty label for an FDE that wouldn't otherwise be emitted. We
768 want to avoid having an FDE kept around when the function it refers to
769 is discarded. Example where this matters: a primary function template
770 in C++ requires EH information, an explicit specialization doesn't. */
773 bool any_eh_needed
= false;
775 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
777 if (fde
->uses_eh_lsda
)
778 any_eh_needed
= any_lsda_needed
= true;
779 else if (fde_needed_for_eh_p (fde
))
780 any_eh_needed
= true;
781 else if (TARGET_USES_WEAK_UNWIND_INFO
)
782 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
789 /* We're going to be generating comments, so turn on app. */
793 /* Switch to the proper frame section, first time. */
794 switch_to_frame_table_section (for_eh
, false);
796 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
797 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
799 /* Output the CIE. */
800 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
801 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
802 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
803 dw2_asm_output_data (4, 0xffffffff,
804 "Initial length escape value indicating 64-bit DWARF extension");
805 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
806 "Length of Common Information Entry");
807 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
809 /* Now that the CIE pointer is PC-relative for EH,
810 use 0 to identify the CIE. */
811 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
812 (for_eh
? 0 : DWARF_CIE_ID
),
813 "CIE Identifier Tag");
815 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
816 use CIE version 1, unless that would produce incorrect results
817 due to overflowing the return register column. */
818 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
820 if (return_reg
>= 256 || dwarf_version
> 2)
822 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
825 augmentation_size
= 0;
827 personality
= current_unit_personality
;
833 z Indicates that a uleb128 is present to size the
834 augmentation section.
835 L Indicates the encoding (and thus presence) of
836 an LSDA pointer in the FDE augmentation.
837 R Indicates a non-default pointer encoding for
839 P Indicates the presence of an encoding + language
840 personality routine in the CIE augmentation. */
842 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
843 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
844 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
846 p
= augmentation
+ 1;
850 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
851 assemble_external_libcall (personality
);
856 augmentation_size
+= 1;
858 if (fde_encoding
!= DW_EH_PE_absptr
)
861 augmentation_size
+= 1;
863 if (p
> augmentation
+ 1)
865 augmentation
[0] = 'z';
869 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
870 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
872 int offset
= ( 4 /* Length */
874 + 1 /* CIE version */
875 + strlen (augmentation
) + 1 /* Augmentation */
876 + size_of_uleb128 (1) /* Code alignment */
877 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
879 + 1 /* Augmentation size */
880 + 1 /* Personality encoding */ );
881 int pad
= -offset
& (PTR_SIZE
- 1);
883 augmentation_size
+= pad
;
885 /* Augmentations should be small, so there's scarce need to
886 iterate for a solution. Die if we exceed one uleb128 byte. */
887 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
891 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
892 if (dw_cie_version
>= 4)
894 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
895 dw2_asm_output_data (1, 0, "CIE Segment Size");
897 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
898 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
899 "CIE Data Alignment Factor");
901 if (dw_cie_version
== 1)
902 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
904 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
908 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
911 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
912 eh_data_format_name (per_encoding
));
913 dw2_asm_output_encoded_addr_rtx (per_encoding
,
919 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
920 eh_data_format_name (lsda_encoding
));
922 if (fde_encoding
!= DW_EH_PE_absptr
)
923 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
924 eh_data_format_name (fde_encoding
));
927 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
928 output_cfi (cfi
, NULL
, for_eh
);
930 /* Pad the CIE out to an address sized boundary. */
931 ASM_OUTPUT_ALIGN (asm_out_file
,
932 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
933 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
935 /* Loop through all of the FDE's. */
936 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
940 /* Don't emit EH unwind info for leaf functions that don't need it. */
941 if (for_eh
&& !fde_needed_for_eh_p (fde
))
944 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
945 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
946 augmentation
, any_lsda_needed
, lsda_encoding
);
949 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
950 dw2_asm_output_data (4, 0, "End of Table");
952 /* Turn off app to make assembly quicker. */
957 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
960 dwarf2out_do_cfi_startproc (bool second
)
964 rtx personality
= get_personality_function (current_function_decl
);
966 fprintf (asm_out_file
, "\t.cfi_startproc\n");
970 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
973 /* ??? The GAS support isn't entirely consistent. We have to
974 handle indirect support ourselves, but PC-relative is done
975 in the assembler. Further, the assembler can't handle any
976 of the weirder relocation types. */
977 if (enc
& DW_EH_PE_indirect
)
978 ref
= dw2_force_const_mem (ref
, true);
980 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
981 output_addr_const (asm_out_file
, ref
);
982 fputc ('\n', asm_out_file
);
985 if (crtl
->uses_eh_lsda
)
989 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
990 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
991 current_function_funcdef_no
);
992 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
993 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
995 if (enc
& DW_EH_PE_indirect
)
996 ref
= dw2_force_const_mem (ref
, true);
998 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
999 output_addr_const (asm_out_file
, ref
);
1000 fputc ('\n', asm_out_file
);
1004 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
1005 this allocation may be done before pass_final. */
1008 dwarf2out_alloc_current_fde (void)
1012 fde
= ggc_cleared_alloc
<dw_fde_node
> ();
1013 fde
->decl
= current_function_decl
;
1014 fde
->funcdef_number
= current_function_funcdef_no
;
1015 fde
->fde_index
= vec_safe_length (fde_vec
);
1016 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
1017 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
1018 fde
->nothrow
= crtl
->nothrow
;
1019 fde
->drap_reg
= INVALID_REGNUM
;
1020 fde
->vdrap_reg
= INVALID_REGNUM
;
1022 /* Record the FDE associated with this function. */
1024 vec_safe_push (fde_vec
, fde
);
1029 /* Output a marker (i.e. a label) for the beginning of a function, before
1033 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1034 const char *file ATTRIBUTE_UNUSED
)
1036 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1042 current_function_func_begin_label
= NULL
;
1044 do_frame
= dwarf2out_do_frame ();
1046 /* ??? current_function_func_begin_label is also used by except.c for
1047 call-site information. We must emit this label if it might be used. */
1049 && (!flag_exceptions
1050 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1053 fnsec
= function_section (current_function_decl
);
1054 switch_to_section (fnsec
);
1055 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1056 current_function_funcdef_no
);
1057 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1058 current_function_funcdef_no
);
1059 dup_label
= xstrdup (label
);
1060 current_function_func_begin_label
= dup_label
;
1062 /* We can elide the fde allocation if we're not emitting debug info. */
1066 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1067 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1068 would include pass_dwarf2_frame. If we've not created the FDE yet,
1072 fde
= dwarf2out_alloc_current_fde ();
1074 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1075 fde
->dw_fde_begin
= dup_label
;
1076 fde
->dw_fde_current_label
= dup_label
;
1077 fde
->in_std_section
= (fnsec
== text_section
1078 || (cold_text_section
&& fnsec
== cold_text_section
));
1080 /* We only want to output line number information for the genuine dwarf2
1081 prologue case, not the eh frame case. */
1082 #ifdef DWARF2_DEBUGGING_INFO
1084 dwarf2out_source_line (line
, file
, 0, true);
1087 if (dwarf2out_do_cfi_asm ())
1088 dwarf2out_do_cfi_startproc (false);
1091 rtx personality
= get_personality_function (current_function_decl
);
1092 if (!current_unit_personality
)
1093 current_unit_personality
= personality
;
1095 /* We cannot keep a current personality per function as without CFI
1096 asm, at the point where we emit the CFI data, there is no current
1097 function anymore. */
1098 if (personality
&& current_unit_personality
!= personality
)
1099 sorry ("multiple EH personalities are supported only with assemblers "
1100 "supporting .cfi_personality directive");
1104 /* Output a marker (i.e. a label) for the end of the generated code
1105 for a function prologue. This gets called *after* the prologue code has
1109 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1110 const char *file ATTRIBUTE_UNUSED
)
1112 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1114 /* Output a label to mark the endpoint of the code generated for this
1116 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1117 current_function_funcdef_no
);
1118 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1119 current_function_funcdef_no
);
1120 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1123 /* Output a marker (i.e. a label) for the beginning of the generated code
1124 for a function epilogue. This gets called *before* the prologue code has
1128 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1129 const char *file ATTRIBUTE_UNUSED
)
1131 dw_fde_ref fde
= cfun
->fde
;
1132 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1134 if (fde
->dw_fde_vms_begin_epilogue
)
1137 /* Output a label to mark the endpoint of the code generated for this
1139 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1140 current_function_funcdef_no
);
1141 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1142 current_function_funcdef_no
);
1143 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1146 /* Output a marker (i.e. a label) for the absolute end of the generated code
1147 for a function definition. This gets called *after* the epilogue code has
1151 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1152 const char *file ATTRIBUTE_UNUSED
)
1155 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1157 last_var_location_insn
= NULL
;
1158 cached_next_real_insn
= NULL
;
1160 if (dwarf2out_do_cfi_asm ())
1161 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1163 /* Output a label to mark the endpoint of the code generated for this
1165 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1166 current_function_funcdef_no
);
1167 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1169 gcc_assert (fde
!= NULL
);
1170 if (fde
->dw_fde_second_begin
== NULL
)
1171 fde
->dw_fde_end
= xstrdup (label
);
1175 dwarf2out_frame_finish (void)
1177 /* Output call frame information. */
1178 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1179 output_call_frame_info (0);
1181 /* Output another copy for the unwinder. */
1182 if ((flag_unwind_tables
|| flag_exceptions
)
1183 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1184 output_call_frame_info (1);
1187 /* Note that the current function section is being used for code. */
1190 dwarf2out_note_section_used (void)
1192 section
*sec
= current_function_section ();
1193 if (sec
== text_section
)
1194 text_section_used
= true;
1195 else if (sec
== cold_text_section
)
1196 cold_text_section_used
= true;
1199 static void var_location_switch_text_section (void);
1200 static void set_cur_line_info_table (section
*);
1203 dwarf2out_switch_text_section (void)
1206 dw_fde_ref fde
= cfun
->fde
;
1208 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1210 if (!in_cold_section_p
)
1212 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1213 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1214 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1218 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1219 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1220 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1222 have_multiple_function_sections
= true;
1224 /* There is no need to mark used sections when not debugging. */
1225 if (cold_text_section
!= NULL
)
1226 dwarf2out_note_section_used ();
1228 if (dwarf2out_do_cfi_asm ())
1229 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1231 /* Now do the real section switch. */
1232 sect
= current_function_section ();
1233 switch_to_section (sect
);
1235 fde
->second_in_std_section
1236 = (sect
== text_section
1237 || (cold_text_section
&& sect
== cold_text_section
));
1239 if (dwarf2out_do_cfi_asm ())
1240 dwarf2out_do_cfi_startproc (true);
1242 var_location_switch_text_section ();
1244 if (cold_text_section
!= NULL
)
1245 set_cur_line_info_table (sect
);
1248 /* And now, the subset of the debugging information support code necessary
1249 for emitting location expressions. */
1251 /* Data about a single source file. */
1252 struct GTY((for_user
)) dwarf_file_data
{
1253 const char * filename
;
1257 /* Describe an entry into the .debug_addr section. */
1261 ate_kind_rtx_dtprel
,
1265 typedef struct GTY((for_user
)) addr_table_entry_struct
{
1267 unsigned int refcount
;
1269 union addr_table_entry_struct_union
1271 rtx
GTY ((tag ("0"))) rtl
;
1272 char * GTY ((tag ("1"))) label
;
1274 GTY ((desc ("%1.kind"))) addr
;
1278 /* Location lists are ranges + location descriptions for that range,
1279 so you can track variables that are in different places over
1280 their entire life. */
1281 typedef struct GTY(()) dw_loc_list_struct
{
1282 dw_loc_list_ref dw_loc_next
;
1283 const char *begin
; /* Label and addr_entry for start of range */
1284 addr_table_entry
*begin_entry
;
1285 const char *end
; /* Label for end of range */
1286 char *ll_symbol
; /* Label for beginning of location list.
1287 Only on head of list */
1288 const char *section
; /* Section this loclist is relative to */
1289 dw_loc_descr_ref expr
;
1291 /* True if all addresses in this and subsequent lists are known to be
1294 /* True if this list has been replaced by dw_loc_next. */
1297 /* True if the range should be emitted even if begin and end
1302 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1304 /* Convert a DWARF stack opcode into its string name. */
1307 dwarf_stack_op_name (unsigned int op
)
1309 const char *name
= get_DW_OP_name (op
);
1314 return "OP_<unknown>";
1317 /* Return a pointer to a newly allocated location description. Location
1318 descriptions are simple expression terms that can be strung
1319 together to form more complicated location (address) descriptions. */
1321 static inline dw_loc_descr_ref
1322 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1323 unsigned HOST_WIDE_INT oprnd2
)
1325 dw_loc_descr_ref descr
= ggc_cleared_alloc
<dw_loc_descr_node
> ();
1327 descr
->dw_loc_opc
= op
;
1328 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1329 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1330 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1331 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1332 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1333 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1338 /* Return a pointer to a newly allocated location description for
1341 static inline dw_loc_descr_ref
1342 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1345 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1348 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1351 /* Add a location description term to a location description expression. */
1354 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1356 dw_loc_descr_ref
*d
;
1358 /* Find the end of the chain. */
1359 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1365 /* Compare two location operands for exact equality. */
1368 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1370 if (a
->val_class
!= b
->val_class
)
1372 switch (a
->val_class
)
1374 case dw_val_class_none
:
1376 case dw_val_class_addr
:
1377 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1379 case dw_val_class_offset
:
1380 case dw_val_class_unsigned_const
:
1381 case dw_val_class_const
:
1382 case dw_val_class_range_list
:
1383 case dw_val_class_lineptr
:
1384 case dw_val_class_macptr
:
1385 /* These are all HOST_WIDE_INT, signed or unsigned. */
1386 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1388 case dw_val_class_loc
:
1389 return a
->v
.val_loc
== b
->v
.val_loc
;
1390 case dw_val_class_loc_list
:
1391 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1392 case dw_val_class_die_ref
:
1393 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1394 case dw_val_class_fde_ref
:
1395 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1396 case dw_val_class_lbl_id
:
1397 case dw_val_class_high_pc
:
1398 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1399 case dw_val_class_str
:
1400 return a
->v
.val_str
== b
->v
.val_str
;
1401 case dw_val_class_flag
:
1402 return a
->v
.val_flag
== b
->v
.val_flag
;
1403 case dw_val_class_file
:
1404 return a
->v
.val_file
== b
->v
.val_file
;
1405 case dw_val_class_decl_ref
:
1406 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1408 case dw_val_class_const_double
:
1409 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1410 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1412 case dw_val_class_wide_int
:
1413 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1415 case dw_val_class_vec
:
1417 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1418 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1420 return (a_len
== b_len
1421 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1424 case dw_val_class_data8
:
1425 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1427 case dw_val_class_vms_delta
:
1428 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1429 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1434 /* Compare two location atoms for exact equality. */
1437 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1439 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1442 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1443 address size, but since we always allocate cleared storage it
1444 should be zero for other types of locations. */
1445 if (a
->dtprel
!= b
->dtprel
)
1448 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1449 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1452 /* Compare two complete location expressions for exact equality. */
1455 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1461 if (a
== NULL
|| b
== NULL
)
1463 if (!loc_descr_equal_p_1 (a
, b
))
1472 /* Add a constant OFFSET to a location expression. */
1475 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1477 dw_loc_descr_ref loc
;
1480 gcc_assert (*list_head
!= NULL
);
1485 /* Find the end of the chain. */
1486 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1490 if (loc
->dw_loc_opc
== DW_OP_fbreg
1491 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1492 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1493 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1494 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1496 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1497 offset. Don't optimize if an signed integer overflow would happen. */
1499 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1500 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1503 else if (offset
> 0)
1504 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1508 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1509 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1513 /* Add a constant OFFSET to a location list. */
1516 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1519 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1520 loc_descr_plus_const (&d
->expr
, offset
);
1523 #define DWARF_REF_SIZE \
1524 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1526 static unsigned long int get_base_type_offset (dw_die_ref
);
1528 /* Return the size of a location descriptor. */
1530 static unsigned long
1531 size_of_loc_descr (dw_loc_descr_ref loc
)
1533 unsigned long size
= 1;
1535 switch (loc
->dw_loc_opc
)
1538 size
+= DWARF2_ADDR_SIZE
;
1540 case DW_OP_GNU_addr_index
:
1541 case DW_OP_GNU_const_index
:
1542 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1543 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1562 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1565 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1570 case DW_OP_plus_uconst
:
1571 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1609 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1612 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1615 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1618 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1619 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1622 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1624 case DW_OP_bit_piece
:
1625 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1626 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1628 case DW_OP_deref_size
:
1629 case DW_OP_xderef_size
:
1638 case DW_OP_call_ref
:
1639 size
+= DWARF_REF_SIZE
;
1641 case DW_OP_implicit_value
:
1642 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1643 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1645 case DW_OP_GNU_implicit_pointer
:
1646 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1648 case DW_OP_GNU_entry_value
:
1650 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1651 size
+= size_of_uleb128 (op_size
) + op_size
;
1654 case DW_OP_GNU_const_type
:
1657 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1658 size
+= size_of_uleb128 (o
) + 1;
1659 switch (loc
->dw_loc_oprnd2
.val_class
)
1661 case dw_val_class_vec
:
1662 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1663 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1665 case dw_val_class_const
:
1666 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1668 case dw_val_class_const_double
:
1669 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1671 case dw_val_class_wide_int
:
1672 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
1673 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
1680 case DW_OP_GNU_regval_type
:
1683 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1684 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1685 + size_of_uleb128 (o
);
1688 case DW_OP_GNU_deref_type
:
1691 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1692 size
+= 1 + size_of_uleb128 (o
);
1695 case DW_OP_GNU_convert
:
1696 case DW_OP_GNU_reinterpret
:
1697 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1698 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1702 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1703 size
+= size_of_uleb128 (o
);
1706 case DW_OP_GNU_parameter_ref
:
1716 /* Return the size of a series of location descriptors. */
1719 size_of_locs (dw_loc_descr_ref loc
)
1724 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1725 field, to avoid writing to a PCH file. */
1726 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1728 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1730 size
+= size_of_loc_descr (l
);
1735 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1737 l
->dw_loc_addr
= size
;
1738 size
+= size_of_loc_descr (l
);
1744 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1745 static void get_ref_die_offset_label (char *, dw_die_ref
);
1746 static unsigned long int get_ref_die_offset (dw_die_ref
);
1748 /* Output location description stack opcode's operands (if any).
1749 The for_eh_or_skip parameter controls whether register numbers are
1750 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1751 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1752 info). This should be suppressed for the cases that have not been converted
1753 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1756 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1758 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1759 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1761 switch (loc
->dw_loc_opc
)
1763 #ifdef DWARF2_DEBUGGING_INFO
1766 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1771 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1772 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1774 fputc ('\n', asm_out_file
);
1779 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1784 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1785 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1787 fputc ('\n', asm_out_file
);
1792 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1793 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1800 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1801 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1803 dw2_asm_output_data (2, offset
, NULL
);
1806 case DW_OP_implicit_value
:
1807 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1808 switch (val2
->val_class
)
1810 case dw_val_class_const
:
1811 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1813 case dw_val_class_vec
:
1815 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1816 unsigned int len
= val2
->v
.val_vec
.length
;
1820 if (elt_size
> sizeof (HOST_WIDE_INT
))
1825 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1828 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1829 "fp or vector constant word %u", i
);
1832 case dw_val_class_const_double
:
1834 unsigned HOST_WIDE_INT first
, second
;
1836 if (WORDS_BIG_ENDIAN
)
1838 first
= val2
->v
.val_double
.high
;
1839 second
= val2
->v
.val_double
.low
;
1843 first
= val2
->v
.val_double
.low
;
1844 second
= val2
->v
.val_double
.high
;
1846 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1848 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1852 case dw_val_class_wide_int
:
1855 int len
= get_full_len (*val2
->v
.val_wide
);
1856 if (WORDS_BIG_ENDIAN
)
1857 for (i
= len
- 1; i
>= 0; --i
)
1858 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1859 val2
->v
.val_wide
->elt (i
), NULL
);
1861 for (i
= 0; i
< len
; ++i
)
1862 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1863 val2
->v
.val_wide
->elt (i
), NULL
);
1866 case dw_val_class_addr
:
1867 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1868 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1883 case DW_OP_implicit_value
:
1884 /* We currently don't make any attempt to make sure these are
1885 aligned properly like we do for the main unwind info, so
1886 don't support emitting things larger than a byte if we're
1887 only doing unwinding. */
1892 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1895 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1898 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1901 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1903 case DW_OP_plus_uconst
:
1904 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1938 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1942 unsigned r
= val1
->v
.val_unsigned
;
1943 if (for_eh_or_skip
>= 0)
1944 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1945 gcc_assert (size_of_uleb128 (r
)
1946 == size_of_uleb128 (val1
->v
.val_unsigned
));
1947 dw2_asm_output_data_uleb128 (r
, NULL
);
1951 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1955 unsigned r
= val1
->v
.val_unsigned
;
1956 if (for_eh_or_skip
>= 0)
1957 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1958 gcc_assert (size_of_uleb128 (r
)
1959 == size_of_uleb128 (val1
->v
.val_unsigned
));
1960 dw2_asm_output_data_uleb128 (r
, NULL
);
1961 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1965 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1967 case DW_OP_bit_piece
:
1968 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1969 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1971 case DW_OP_deref_size
:
1972 case DW_OP_xderef_size
:
1973 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1979 if (targetm
.asm_out
.output_dwarf_dtprel
)
1981 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1984 fputc ('\n', asm_out_file
);
1991 #ifdef DWARF2_DEBUGGING_INFO
1992 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
1999 case DW_OP_GNU_addr_index
:
2000 case DW_OP_GNU_const_index
:
2001 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
2002 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
2003 "(index into .debug_addr)");
2006 case DW_OP_GNU_implicit_pointer
:
2008 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2009 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2010 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2011 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2012 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2013 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2017 case DW_OP_GNU_entry_value
:
2018 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2019 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2022 case DW_OP_GNU_const_type
:
2024 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2026 dw2_asm_output_data_uleb128 (o
, NULL
);
2027 switch (val2
->val_class
)
2029 case dw_val_class_const
:
2030 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2031 dw2_asm_output_data (1, l
, NULL
);
2032 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2034 case dw_val_class_vec
:
2036 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2037 unsigned int len
= val2
->v
.val_vec
.length
;
2042 dw2_asm_output_data (1, l
, NULL
);
2043 if (elt_size
> sizeof (HOST_WIDE_INT
))
2048 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2051 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2052 "fp or vector constant word %u", i
);
2055 case dw_val_class_const_double
:
2057 unsigned HOST_WIDE_INT first
, second
;
2058 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2060 dw2_asm_output_data (1, 2 * l
, NULL
);
2061 if (WORDS_BIG_ENDIAN
)
2063 first
= val2
->v
.val_double
.high
;
2064 second
= val2
->v
.val_double
.low
;
2068 first
= val2
->v
.val_double
.low
;
2069 second
= val2
->v
.val_double
.high
;
2071 dw2_asm_output_data (l
, first
, NULL
);
2072 dw2_asm_output_data (l
, second
, NULL
);
2075 case dw_val_class_wide_int
:
2078 int len
= get_full_len (*val2
->v
.val_wide
);
2079 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2081 dw2_asm_output_data (1, len
* l
, NULL
);
2082 if (WORDS_BIG_ENDIAN
)
2083 for (i
= len
- 1; i
>= 0; --i
)
2084 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2086 for (i
= 0; i
< len
; ++i
)
2087 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2095 case DW_OP_GNU_regval_type
:
2097 unsigned r
= val1
->v
.val_unsigned
;
2098 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2100 if (for_eh_or_skip
>= 0)
2102 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2103 gcc_assert (size_of_uleb128 (r
)
2104 == size_of_uleb128 (val1
->v
.val_unsigned
));
2106 dw2_asm_output_data_uleb128 (r
, NULL
);
2107 dw2_asm_output_data_uleb128 (o
, NULL
);
2110 case DW_OP_GNU_deref_type
:
2112 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2114 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2115 dw2_asm_output_data_uleb128 (o
, NULL
);
2118 case DW_OP_GNU_convert
:
2119 case DW_OP_GNU_reinterpret
:
2120 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2121 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2124 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2126 dw2_asm_output_data_uleb128 (o
, NULL
);
2130 case DW_OP_GNU_parameter_ref
:
2133 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2134 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2135 dw2_asm_output_data (4, o
, NULL
);
2140 /* Other codes have no operands. */
2145 /* Output a sequence of location operations.
2146 The for_eh_or_skip parameter controls whether register numbers are
2147 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2148 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2149 info). This should be suppressed for the cases that have not been converted
2150 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2153 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2155 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2157 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2158 /* Output the opcode. */
2159 if (for_eh_or_skip
>= 0
2160 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2162 unsigned r
= (opc
- DW_OP_breg0
);
2163 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2164 gcc_assert (r
<= 31);
2165 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2167 else if (for_eh_or_skip
>= 0
2168 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2170 unsigned r
= (opc
- DW_OP_reg0
);
2171 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2172 gcc_assert (r
<= 31);
2173 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2176 dw2_asm_output_data (1, opc
,
2177 "%s", dwarf_stack_op_name (opc
));
2179 /* Output the operand(s) (if any). */
2180 output_loc_operands (loc
, for_eh_or_skip
);
2184 /* Output location description stack opcode's operands (if any).
2185 The output is single bytes on a line, suitable for .cfi_escape. */
2188 output_loc_operands_raw (dw_loc_descr_ref loc
)
2190 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2191 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2193 switch (loc
->dw_loc_opc
)
2196 case DW_OP_GNU_addr_index
:
2197 case DW_OP_GNU_const_index
:
2198 case DW_OP_implicit_value
:
2199 /* We cannot output addresses in .cfi_escape, only bytes. */
2205 case DW_OP_deref_size
:
2206 case DW_OP_xderef_size
:
2207 fputc (',', asm_out_file
);
2208 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2213 fputc (',', asm_out_file
);
2214 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2219 fputc (',', asm_out_file
);
2220 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2225 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2226 fputc (',', asm_out_file
);
2227 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2235 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2236 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2238 fputc (',', asm_out_file
);
2239 dw2_asm_output_data_raw (2, offset
);
2245 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2246 gcc_assert (size_of_uleb128 (r
)
2247 == size_of_uleb128 (val1
->v
.val_unsigned
));
2248 fputc (',', asm_out_file
);
2249 dw2_asm_output_data_uleb128_raw (r
);
2254 case DW_OP_plus_uconst
:
2256 fputc (',', asm_out_file
);
2257 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2260 case DW_OP_bit_piece
:
2261 fputc (',', asm_out_file
);
2262 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2263 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2300 fputc (',', asm_out_file
);
2301 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2306 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2307 gcc_assert (size_of_uleb128 (r
)
2308 == size_of_uleb128 (val1
->v
.val_unsigned
));
2309 fputc (',', asm_out_file
);
2310 dw2_asm_output_data_uleb128_raw (r
);
2311 fputc (',', asm_out_file
);
2312 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2316 case DW_OP_GNU_implicit_pointer
:
2317 case DW_OP_GNU_entry_value
:
2318 case DW_OP_GNU_const_type
:
2319 case DW_OP_GNU_regval_type
:
2320 case DW_OP_GNU_deref_type
:
2321 case DW_OP_GNU_convert
:
2322 case DW_OP_GNU_reinterpret
:
2323 case DW_OP_GNU_parameter_ref
:
2328 /* Other codes have no operands. */
2334 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2338 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2339 /* Output the opcode. */
2340 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2342 unsigned r
= (opc
- DW_OP_breg0
);
2343 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2344 gcc_assert (r
<= 31);
2345 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2347 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2349 unsigned r
= (opc
- DW_OP_reg0
);
2350 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2351 gcc_assert (r
<= 31);
2352 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2354 /* Output the opcode. */
2355 fprintf (asm_out_file
, "%#x", opc
);
2356 output_loc_operands_raw (loc
);
2358 if (!loc
->dw_loc_next
)
2360 loc
= loc
->dw_loc_next
;
2362 fputc (',', asm_out_file
);
2366 /* This function builds a dwarf location descriptor sequence from a
2367 dw_cfa_location, adding the given OFFSET to the result of the
2370 struct dw_loc_descr_node
*
2371 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2373 struct dw_loc_descr_node
*head
, *tmp
;
2375 offset
+= cfa
->offset
;
2379 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2380 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2381 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2382 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2383 add_loc_descr (&head
, tmp
);
2386 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2387 add_loc_descr (&head
, tmp
);
2391 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2396 /* This function builds a dwarf location descriptor sequence for
2397 the address at OFFSET from the CFA when stack is aligned to
2400 struct dw_loc_descr_node
*
2401 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2402 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2404 struct dw_loc_descr_node
*head
;
2405 unsigned int dwarf_fp
2406 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2408 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2409 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2411 head
= new_reg_loc_descr (dwarf_fp
, 0);
2412 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2413 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2414 loc_descr_plus_const (&head
, offset
);
2417 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2421 /* And now, the support for symbolic debugging information. */
2423 /* .debug_str support. */
2425 static void dwarf2out_init (const char *);
2426 static void dwarf2out_finish (const char *);
2427 static void dwarf2out_early_finish (void);
2428 static void dwarf2out_assembly_start (void);
2429 static void dwarf2out_define (unsigned int, const char *);
2430 static void dwarf2out_undef (unsigned int, const char *);
2431 static void dwarf2out_start_source_file (unsigned, const char *);
2432 static void dwarf2out_end_source_file (unsigned);
2433 static void dwarf2out_function_decl (tree
);
2434 static void dwarf2out_begin_block (unsigned, unsigned);
2435 static void dwarf2out_end_block (unsigned, unsigned);
2436 static bool dwarf2out_ignore_block (const_tree
);
2437 static void dwarf2out_early_global_decl (tree
);
2438 static void dwarf2out_late_global_decl (tree
);
2439 static void dwarf2out_type_decl (tree
, int);
2440 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2441 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2443 static void dwarf2out_abstract_function (tree
);
2444 static void dwarf2out_var_location (rtx_insn
*);
2445 static void dwarf2out_begin_function (tree
);
2446 static void dwarf2out_end_function (unsigned int);
2447 static void dwarf2out_register_main_translation_unit (tree unit
);
2448 static void dwarf2out_set_name (tree
, tree
);
2450 /* The debug hooks structure. */
2452 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2456 dwarf2out_early_finish
,
2457 dwarf2out_assembly_start
,
2460 dwarf2out_start_source_file
,
2461 dwarf2out_end_source_file
,
2462 dwarf2out_begin_block
,
2463 dwarf2out_end_block
,
2464 dwarf2out_ignore_block
,
2465 dwarf2out_source_line
,
2466 dwarf2out_begin_prologue
,
2467 #if VMS_DEBUGGING_INFO
2468 dwarf2out_vms_end_prologue
,
2469 dwarf2out_vms_begin_epilogue
,
2471 debug_nothing_int_charstar
,
2472 debug_nothing_int_charstar
,
2474 dwarf2out_end_epilogue
,
2475 dwarf2out_begin_function
,
2476 dwarf2out_end_function
, /* end_function */
2477 dwarf2out_register_main_translation_unit
,
2478 dwarf2out_function_decl
, /* function_decl */
2479 dwarf2out_early_global_decl
,
2480 dwarf2out_late_global_decl
,
2481 dwarf2out_type_decl
, /* type_decl */
2482 dwarf2out_imported_module_or_decl
,
2483 debug_nothing_tree
, /* deferred_inline_function */
2484 /* The DWARF 2 backend tries to reduce debugging bloat by not
2485 emitting the abstract description of inline functions until
2486 something tries to reference them. */
2487 dwarf2out_abstract_function
, /* outlining_inline_function */
2488 debug_nothing_rtx_code_label
, /* label */
2489 debug_nothing_int
, /* handle_pch */
2490 dwarf2out_var_location
,
2491 dwarf2out_switch_text_section
,
2493 1, /* start_end_main_source_file */
2494 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2497 /* NOTE: In the comments in this file, many references are made to
2498 "Debugging Information Entries". This term is abbreviated as `DIE'
2499 throughout the remainder of this file. */
2501 /* An internal representation of the DWARF output is built, and then
2502 walked to generate the DWARF debugging info. The walk of the internal
2503 representation is done after the entire program has been compiled.
2504 The types below are used to describe the internal representation. */
2506 /* Whether to put type DIEs into their own section .debug_types instead
2507 of making them part of the .debug_info section. Only supported for
2508 Dwarf V4 or higher and the user didn't disable them through
2509 -fno-debug-types-section. It is more efficient to put them in a
2510 separate comdat sections since the linker will then be able to
2511 remove duplicates. But not all tools support .debug_types sections
2514 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2516 /* Various DIE's use offsets relative to the beginning of the
2517 .debug_info section to refer to each other. */
2519 typedef long int dw_offset
;
2521 /* Define typedefs here to avoid circular dependencies. */
2523 typedef struct dw_attr_struct
*dw_attr_ref
;
2524 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2525 typedef struct pubname_struct
*pubname_ref
;
2526 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2527 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2528 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2530 /* The entries in the line_info table more-or-less mirror the opcodes
2531 that are used in the real dwarf line table. Arrays of these entries
2532 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2535 enum dw_line_info_opcode
{
2536 /* Emit DW_LNE_set_address; the operand is the label index. */
2539 /* Emit a row to the matrix with the given line. This may be done
2540 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2544 /* Emit a DW_LNS_set_file. */
2547 /* Emit a DW_LNS_set_column. */
2550 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2553 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2554 LI_set_prologue_end
,
2555 LI_set_epilogue_begin
,
2557 /* Emit a DW_LNE_set_discriminator. */
2558 LI_set_discriminator
2561 typedef struct GTY(()) dw_line_info_struct
{
2562 enum dw_line_info_opcode opcode
;
2564 } dw_line_info_entry
;
2567 typedef struct GTY(()) dw_line_info_table_struct
{
2568 /* The label that marks the end of this section. */
2569 const char *end_label
;
2571 /* The values for the last row of the matrix, as collected in the table.
2572 These are used to minimize the changes to the next row. */
2573 unsigned int file_num
;
2574 unsigned int line_num
;
2575 unsigned int column_num
;
2580 vec
<dw_line_info_entry
, va_gc
> *entries
;
2581 } dw_line_info_table
;
2583 typedef dw_line_info_table
*dw_line_info_table_p
;
2586 /* Each DIE attribute has a field specifying the attribute kind,
2587 a link to the next attribute in the chain, and an attribute value.
2588 Attributes are typically linked below the DIE they modify. */
2590 typedef struct GTY(()) dw_attr_struct
{
2591 enum dwarf_attribute dw_attr
;
2592 dw_val_node dw_attr_val
;
2597 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2598 The children of each node form a circular list linked by
2599 die_sib. die_child points to the node *before* the "first" child node. */
2601 typedef struct GTY((chain_circular ("%h.die_sib"), for_user
)) die_struct
{
2602 union die_symbol_or_type_node
2604 const char * GTY ((tag ("0"))) die_symbol
;
2605 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2607 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2608 vec
<dw_attr_node
, va_gc
> *die_attr
;
2609 dw_die_ref die_parent
;
2610 dw_die_ref die_child
;
2612 dw_die_ref die_definition
; /* ref from a specification to its definition */
2613 dw_offset die_offset
;
2614 unsigned long die_abbrev
;
2616 unsigned int decl_id
;
2617 enum dwarf_tag die_tag
;
2618 /* Die is used and must not be pruned as unused. */
2619 BOOL_BITFIELD die_perennial_p
: 1;
2620 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2621 /* Lots of spare bits. */
2625 /* Set to TRUE while dwarf2out_early_global_decl is running. */
2626 static bool early_dwarf
;
2627 struct set_early_dwarf
{
2629 set_early_dwarf () : saved(early_dwarf
) { early_dwarf
= true; }
2630 ~set_early_dwarf () { early_dwarf
= saved
; }
2633 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2634 #define FOR_EACH_CHILD(die, c, expr) do { \
2635 c = die->die_child; \
2639 } while (c != die->die_child); \
2642 /* The pubname structure */
2644 typedef struct GTY(()) pubname_struct
{
2651 struct GTY(()) dw_ranges_struct
{
2652 /* If this is positive, it's a block number, otherwise it's a
2653 bitwise-negated index into dw_ranges_by_label. */
2657 /* A structure to hold a macinfo entry. */
2659 typedef struct GTY(()) macinfo_struct
{
2661 unsigned HOST_WIDE_INT lineno
;
2667 struct GTY(()) dw_ranges_by_label_struct
{
2672 /* The comdat type node structure. */
2673 typedef struct GTY(()) comdat_type_struct
2675 dw_die_ref root_die
;
2676 dw_die_ref type_die
;
2677 dw_die_ref skeleton_die
;
2678 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2679 struct comdat_type_struct
*next
;
2683 /* A list of DIEs for which we can't determine ancestry (parent_die
2684 field) just yet. Later in dwarf2out_finish we will fill in the
2686 typedef struct GTY(()) limbo_die_struct
{
2688 /* The tree for which this DIE was created. We use this to
2689 determine ancestry later. */
2691 struct limbo_die_struct
*next
;
2695 typedef struct skeleton_chain_struct
2699 struct skeleton_chain_struct
*parent
;
2701 skeleton_chain_node
;
2703 /* Define a macro which returns nonzero for a TYPE_DECL which was
2704 implicitly generated for a type.
2706 Note that, unlike the C front-end (which generates a NULL named
2707 TYPE_DECL node for each complete tagged type, each array type,
2708 and each function type node created) the C++ front-end generates
2709 a _named_ TYPE_DECL node for each tagged type node created.
2710 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2711 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2712 front-end, but for each type, tagged or not. */
2714 #define TYPE_DECL_IS_STUB(decl) \
2715 (DECL_NAME (decl) == NULL_TREE \
2716 || (DECL_ARTIFICIAL (decl) \
2717 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2718 /* This is necessary for stub decls that \
2719 appear in nested inline functions. */ \
2720 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2721 && (decl_ultimate_origin (decl) \
2722 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2724 /* Information concerning the compilation unit's programming
2725 language, and compiler version. */
2727 /* Fixed size portion of the DWARF compilation unit header. */
2728 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2729 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2731 /* Fixed size portion of the DWARF comdat type unit header. */
2732 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2733 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2734 + DWARF_OFFSET_SIZE)
2736 /* Fixed size portion of public names info. */
2737 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2739 /* Fixed size portion of the address range info. */
2740 #define DWARF_ARANGES_HEADER_SIZE \
2741 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2742 DWARF2_ADDR_SIZE * 2) \
2743 - DWARF_INITIAL_LENGTH_SIZE)
2745 /* Size of padding portion in the address range info. It must be
2746 aligned to twice the pointer size. */
2747 #define DWARF_ARANGES_PAD_SIZE \
2748 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2749 DWARF2_ADDR_SIZE * 2) \
2750 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2752 /* Use assembler line directives if available. */
2753 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2754 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2755 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2757 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2761 /* Minimum line offset in a special line info. opcode.
2762 This value was chosen to give a reasonable range of values. */
2763 #define DWARF_LINE_BASE -10
2765 /* First special line opcode - leave room for the standard opcodes. */
2766 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2768 /* Range of line offsets in a special line info. opcode. */
2769 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2771 /* Flag that indicates the initial value of the is_stmt_start flag.
2772 In the present implementation, we do not mark any lines as
2773 the beginning of a source statement, because that information
2774 is not made available by the GCC front-end. */
2775 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2777 /* Maximum number of operations per instruction bundle. */
2778 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2779 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2782 /* This location is used by calc_die_sizes() to keep track
2783 the offset of each DIE within the .debug_info section. */
2784 static unsigned long next_die_offset
;
2786 /* Record the root of the DIE's built for the current compilation unit. */
2787 static GTY(()) dw_die_ref single_comp_unit_die
;
2789 /* A list of type DIEs that have been separated into comdat sections. */
2790 static GTY(()) comdat_type_node
*comdat_type_list
;
2792 /* A list of DIEs with a NULL parent waiting to be relocated. */
2793 static GTY(()) limbo_die_node
*limbo_die_list
;
2795 /* A list of DIEs for which we may have to generate
2796 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2797 static GTY(()) limbo_die_node
*deferred_asm_name
;
2799 struct dwarf_file_hasher
: ggc_ptr_hash
<dwarf_file_data
>
2801 typedef const char *compare_type
;
2803 static hashval_t
hash (dwarf_file_data
*);
2804 static bool equal (dwarf_file_data
*, const char *);
2807 /* Filenames referenced by this compilation unit. */
2808 static GTY(()) hash_table
<dwarf_file_hasher
> *file_table
;
2810 struct decl_die_hasher
: ggc_ptr_hash
<die_node
>
2812 typedef tree compare_type
;
2814 static hashval_t
hash (die_node
*);
2815 static bool equal (die_node
*, tree
);
2817 /* A hash table of references to DIE's that describe declarations.
2818 The key is a DECL_UID() which is a unique number identifying each decl. */
2819 static GTY (()) hash_table
<decl_die_hasher
> *decl_die_table
;
2821 struct block_die_hasher
: ggc_ptr_hash
<die_struct
>
2823 static hashval_t
hash (die_struct
*);
2824 static bool equal (die_struct
*, die_struct
*);
2827 /* A hash table of references to DIE's that describe COMMON blocks.
2828 The key is DECL_UID() ^ die_parent. */
2829 static GTY (()) hash_table
<block_die_hasher
> *common_block_die_table
;
2831 typedef struct GTY(()) die_arg_entry_struct
{
2837 /* Node of the variable location list. */
2838 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2839 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2840 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2841 in mode of the EXPR_LIST node and first EXPR_LIST operand
2842 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2843 location or NULL for padding. For larger bitsizes,
2844 mode is 0 and first operand is a CONCAT with bitsize
2845 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2846 NULL as second operand. */
2848 const char * GTY (()) label
;
2849 struct var_loc_node
* GTY (()) next
;
2852 /* Variable location list. */
2853 struct GTY ((for_user
)) var_loc_list_def
{
2854 struct var_loc_node
* GTY (()) first
;
2856 /* Pointer to the last but one or last element of the
2857 chained list. If the list is empty, both first and
2858 last are NULL, if the list contains just one node
2859 or the last node certainly is not redundant, it points
2860 to the last node, otherwise points to the last but one.
2861 Do not mark it for GC because it is marked through the chain. */
2862 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2864 /* Pointer to the last element before section switch,
2865 if NULL, either sections weren't switched or first
2866 is after section switch. */
2867 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2869 /* DECL_UID of the variable decl. */
2870 unsigned int decl_id
;
2872 typedef struct var_loc_list_def var_loc_list
;
2874 /* Call argument location list. */
2875 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2876 rtx
GTY (()) call_arg_loc_note
;
2877 const char * GTY (()) label
;
2878 tree
GTY (()) block
;
2880 rtx
GTY (()) symbol_ref
;
2881 struct call_arg_loc_node
* GTY (()) next
;
2885 struct decl_loc_hasher
: ggc_ptr_hash
<var_loc_list
>
2887 typedef const_tree compare_type
;
2889 static hashval_t
hash (var_loc_list
*);
2890 static bool equal (var_loc_list
*, const_tree
);
2893 /* Table of decl location linked lists. */
2894 static GTY (()) hash_table
<decl_loc_hasher
> *decl_loc_table
;
2896 /* Head and tail of call_arg_loc chain. */
2897 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2898 static struct call_arg_loc_node
*call_arg_loc_last
;
2900 /* Number of call sites in the current function. */
2901 static int call_site_count
= -1;
2902 /* Number of tail call sites in the current function. */
2903 static int tail_call_site_count
= -1;
2905 /* A cached location list. */
2906 struct GTY ((for_user
)) cached_dw_loc_list_def
{
2907 /* The DECL_UID of the decl that this entry describes. */
2908 unsigned int decl_id
;
2910 /* The cached location list. */
2911 dw_loc_list_ref loc_list
;
2913 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2915 struct dw_loc_list_hasher
: ggc_ptr_hash
<cached_dw_loc_list
>
2918 typedef const_tree compare_type
;
2920 static hashval_t
hash (cached_dw_loc_list
*);
2921 static bool equal (cached_dw_loc_list
*, const_tree
);
2924 /* Table of cached location lists. */
2925 static GTY (()) hash_table
<dw_loc_list_hasher
> *cached_dw_loc_list_table
;
2927 /* A pointer to the base of a list of references to DIE's that
2928 are uniquely identified by their tag, presence/absence of
2929 children DIE's, and list of attribute/value pairs. */
2930 static GTY((length ("abbrev_die_table_allocated")))
2931 dw_die_ref
*abbrev_die_table
;
2933 /* Number of elements currently allocated for abbrev_die_table. */
2934 static GTY(()) unsigned abbrev_die_table_allocated
;
2936 /* Number of elements in abbrev_die_table currently in use. */
2937 static GTY(()) unsigned abbrev_die_table_in_use
;
2939 /* Size (in elements) of increments by which we may expand the
2940 abbrev_die_table. */
2941 #define ABBREV_DIE_TABLE_INCREMENT 256
2943 /* A global counter for generating labels for line number data. */
2944 static unsigned int line_info_label_num
;
2946 /* The current table to which we should emit line number information
2947 for the current function. This will be set up at the beginning of
2948 assembly for the function. */
2949 static dw_line_info_table
*cur_line_info_table
;
2951 /* The two default tables of line number info. */
2952 static GTY(()) dw_line_info_table
*text_section_line_info
;
2953 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2955 /* The set of all non-default tables of line number info. */
2956 static GTY(()) vec
<dw_line_info_table_p
, va_gc
> *separate_line_info
;
2958 /* A flag to tell pubnames/types export if there is an info section to
2960 static bool info_section_emitted
;
2962 /* A pointer to the base of a table that contains a list of publicly
2963 accessible names. */
2964 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2966 /* A pointer to the base of a table that contains a list of publicly
2967 accessible types. */
2968 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
2970 /* A pointer to the base of a table that contains a list of macro
2971 defines/undefines (and file start/end markers). */
2972 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
2974 /* True if .debug_macinfo or .debug_macros section is going to be
2976 #define have_macinfo \
2977 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2978 && !macinfo_table->is_empty ())
2980 /* Array of dies for which we should generate .debug_ranges info. */
2981 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2983 /* Number of elements currently allocated for ranges_table. */
2984 static GTY(()) unsigned ranges_table_allocated
;
2986 /* Number of elements in ranges_table currently in use. */
2987 static GTY(()) unsigned ranges_table_in_use
;
2989 /* Array of pairs of labels referenced in ranges_table. */
2990 static GTY ((length ("ranges_by_label_allocated")))
2991 dw_ranges_by_label_ref ranges_by_label
;
2993 /* Number of elements currently allocated for ranges_by_label. */
2994 static GTY(()) unsigned ranges_by_label_allocated
;
2996 /* Number of elements in ranges_by_label currently in use. */
2997 static GTY(()) unsigned ranges_by_label_in_use
;
2999 /* Size (in elements) of increments by which we may expand the
3001 #define RANGES_TABLE_INCREMENT 64
3003 /* Whether we have location lists that need outputting */
3004 static GTY(()) bool have_location_lists
;
3006 /* Unique label counter. */
3007 static GTY(()) unsigned int loclabel_num
;
3009 /* Unique label counter for point-of-call tables. */
3010 static GTY(()) unsigned int poc_label_num
;
3012 /* The last file entry emitted by maybe_emit_file(). */
3013 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3015 /* Number of internal labels generated by gen_internal_sym(). */
3016 static GTY(()) int label_num
;
3018 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
3020 /* Instances of generic types for which we need to generate debug
3021 info that describe their generic parameters and arguments. That
3022 generation needs to happen once all types are properly laid out so
3023 we do it at the end of compilation. */
3024 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
3026 /* Offset from the "steady-state frame pointer" to the frame base,
3027 within the current function. */
3028 static HOST_WIDE_INT frame_pointer_fb_offset
;
3029 static bool frame_pointer_fb_offset_valid
;
3031 static vec
<dw_die_ref
> base_types
;
3033 /* Flags to represent a set of attribute classes for attributes that represent
3034 a scalar value (bounds, pointers, ...). */
3037 dw_scalar_form_constant
= 0x01,
3038 dw_scalar_form_exprloc
= 0x02,
3039 dw_scalar_form_reference
= 0x04
3042 /* Forward declarations for functions defined in this file. */
3044 static int is_pseudo_reg (const_rtx
);
3045 static tree
type_main_variant (tree
);
3046 static int is_tagged_type (const_tree
);
3047 static const char *dwarf_tag_name (unsigned);
3048 static const char *dwarf_attr_name (unsigned);
3049 static const char *dwarf_form_name (unsigned);
3050 static tree
decl_ultimate_origin (const_tree
);
3051 static tree
decl_class_context (tree
);
3052 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
3053 static inline enum dw_val_class
AT_class (dw_attr_ref
);
3054 static inline unsigned int AT_index (dw_attr_ref
);
3055 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3056 static inline unsigned AT_flag (dw_attr_ref
);
3057 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3058 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
3059 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3060 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
3061 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3062 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3063 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3064 unsigned int, unsigned char *);
3065 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3066 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3067 static inline const char *AT_string (dw_attr_ref
);
3068 static enum dwarf_form
AT_string_form (dw_attr_ref
);
3069 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3070 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3071 static inline dw_die_ref
AT_ref (dw_attr_ref
);
3072 static inline int AT_ref_external (dw_attr_ref
);
3073 static inline void set_AT_ref_external (dw_attr_ref
, int);
3074 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3075 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3076 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
3077 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3079 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
3080 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3081 static void remove_addr_table_entry (addr_table_entry
*);
3082 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3083 static inline rtx
AT_addr (dw_attr_ref
);
3084 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3085 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3086 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3087 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3088 unsigned HOST_WIDE_INT
);
3089 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3090 unsigned long, bool);
3091 static inline const char *AT_lbl (dw_attr_ref
);
3092 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
3093 static const char *get_AT_low_pc (dw_die_ref
);
3094 static const char *get_AT_hi_pc (dw_die_ref
);
3095 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3096 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3097 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3098 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3099 static bool is_cxx (void);
3100 static bool is_fortran (void);
3101 static bool is_ada (void);
3102 static bool remove_AT (dw_die_ref
, enum dwarf_attribute
);
3103 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3104 static void add_child_die (dw_die_ref
, dw_die_ref
);
3105 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3106 static dw_die_ref
lookup_type_die (tree
);
3107 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3108 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3109 static void equate_type_number_to_die (tree
, dw_die_ref
);
3110 static dw_die_ref
lookup_decl_die (tree
);
3111 static var_loc_list
*lookup_decl_loc (const_tree
);
3112 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3113 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3114 static void print_spaces (FILE *);
3115 static void print_die (dw_die_ref
, FILE *);
3116 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3117 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3118 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3119 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3120 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3121 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3122 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3123 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3124 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
3125 struct md5_ctx
*, int *);
3126 struct checksum_attributes
;
3127 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3128 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3129 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3130 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3131 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3132 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3133 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3134 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3135 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3136 static void compute_section_prefix (dw_die_ref
);
3137 static int is_type_die (dw_die_ref
);
3138 static int is_comdat_die (dw_die_ref
);
3139 static int is_symbol_die (dw_die_ref
);
3140 static inline bool is_template_instantiation (dw_die_ref
);
3141 static void assign_symbol_names (dw_die_ref
);
3142 static void break_out_includes (dw_die_ref
);
3143 static int is_declaration_die (dw_die_ref
);
3144 static int should_move_die_to_comdat (dw_die_ref
);
3145 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3146 static dw_die_ref
clone_die (dw_die_ref
);
3147 static dw_die_ref
clone_tree (dw_die_ref
);
3148 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3149 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3150 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3151 static dw_die_ref
generate_skeleton (dw_die_ref
);
3152 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3155 static void break_out_comdat_types (dw_die_ref
);
3156 static void copy_decls_for_unworthy_types (dw_die_ref
);
3158 static void add_sibling_attributes (dw_die_ref
);
3159 static void output_location_lists (dw_die_ref
);
3160 static int constant_size (unsigned HOST_WIDE_INT
);
3161 static unsigned long size_of_die (dw_die_ref
);
3162 static void calc_die_sizes (dw_die_ref
);
3163 static void calc_base_type_die_sizes (void);
3164 static void mark_dies (dw_die_ref
);
3165 static void unmark_dies (dw_die_ref
);
3166 static void unmark_all_dies (dw_die_ref
);
3167 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3168 static unsigned long size_of_aranges (void);
3169 static enum dwarf_form
value_format (dw_attr_ref
);
3170 static void output_value_format (dw_attr_ref
);
3171 static void output_abbrev_section (void);
3172 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3173 static void output_die_symbol (dw_die_ref
);
3174 static void output_die (dw_die_ref
);
3175 static void output_compilation_unit_header (void);
3176 static void output_comp_unit (dw_die_ref
, int);
3177 static void output_comdat_type_unit (comdat_type_node
*);
3178 static const char *dwarf2_name (tree
, int);
3179 static void add_pubname (tree
, dw_die_ref
);
3180 static void add_enumerator_pubname (const char *, dw_die_ref
);
3181 static void add_pubname_string (const char *, dw_die_ref
);
3182 static void add_pubtype (tree
, dw_die_ref
);
3183 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3184 static void output_aranges (unsigned long);
3185 static unsigned int add_ranges_num (int);
3186 static unsigned int add_ranges (const_tree
);
3187 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3189 static void output_ranges (void);
3190 static dw_line_info_table
*new_line_info_table (void);
3191 static void output_line_info (bool);
3192 static void output_file_names (void);
3193 static dw_die_ref
base_type_die (tree
);
3194 static int is_base_type (tree
);
3195 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3196 static int decl_quals (const_tree
);
3197 static dw_die_ref
modified_type_die (tree
, int, dw_die_ref
);
3198 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3199 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3200 static int type_is_enum (const_tree
);
3201 static unsigned int dbx_reg_number (const_rtx
);
3202 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3203 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3204 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3205 enum var_init_status
);
3206 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3207 enum var_init_status
);
3208 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3209 enum var_init_status
);
3210 static int is_based_loc (const_rtx
);
3211 static bool resolve_one_addr (rtx
*);
3212 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3213 enum var_init_status
);
3214 static dw_loc_descr_ref
loc_descriptor (rtx
, machine_mode mode
,
3215 enum var_init_status
);
3216 struct loc_descr_context
;
3217 static dw_loc_list_ref
loc_list_from_tree (tree
, int,
3218 const struct loc_descr_context
*);
3219 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int,
3220 const struct loc_descr_context
*);
3221 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3222 static tree
field_type (const_tree
);
3223 static unsigned int simple_type_align_in_bits (const_tree
);
3224 static unsigned int simple_decl_align_in_bits (const_tree
);
3225 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3226 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3227 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3229 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3230 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3231 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3232 static void insert_wide_int (const wide_int
&, unsigned char *, int);
3233 static void insert_float (const_rtx
, unsigned char *);
3234 static rtx
rtl_for_decl_location (tree
);
3235 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3236 enum dwarf_attribute
);
3237 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3238 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3239 static void add_name_attribute (dw_die_ref
, const char *);
3240 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3241 static void add_comp_dir_attribute (dw_die_ref
);
3242 static void add_scalar_info (dw_die_ref
, enum dwarf_attribute
, tree
, int,
3243 const struct loc_descr_context
*);
3244 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
,
3245 const struct loc_descr_context
*);
3246 static void add_subscript_info (dw_die_ref
, tree
, bool);
3247 static void add_byte_size_attribute (dw_die_ref
, tree
);
3248 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3249 static void add_bit_size_attribute (dw_die_ref
, tree
);
3250 static void add_prototyped_attribute (dw_die_ref
, tree
);
3251 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3252 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3253 static void add_src_coords_attributes (dw_die_ref
, tree
);
3254 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3255 static void push_decl_scope (tree
);
3256 static void pop_decl_scope (void);
3257 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3258 static inline int local_scope_p (dw_die_ref
);
3259 static inline int class_scope_p (dw_die_ref
);
3260 static inline int class_or_namespace_scope_p (dw_die_ref
);
3261 static void add_type_attribute (dw_die_ref
, tree
, int, dw_die_ref
);
3262 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3263 static const char *type_tag (const_tree
);
3264 static tree
member_declared_type (const_tree
);
3266 static const char *decl_start_label (tree
);
3268 static void gen_array_type_die (tree
, dw_die_ref
);
3269 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3271 static void gen_entry_point_die (tree
, dw_die_ref
);
3273 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3274 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3275 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3276 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3277 static void gen_formal_types_die (tree
, dw_die_ref
);
3278 static void gen_subprogram_die (tree
, dw_die_ref
);
3279 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3280 static void gen_const_die (tree
, dw_die_ref
);
3281 static void gen_label_die (tree
, dw_die_ref
);
3282 static void gen_lexical_block_die (tree
, dw_die_ref
);
3283 static void gen_inlined_subroutine_die (tree
, dw_die_ref
);
3284 static void gen_field_die (tree
, dw_die_ref
);
3285 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3286 static dw_die_ref
gen_compile_unit_die (const char *);
3287 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3288 static void gen_member_die (tree
, dw_die_ref
);
3289 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3290 enum debug_info_usage
);
3291 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3292 static void gen_typedef_die (tree
, dw_die_ref
);
3293 static void gen_type_die (tree
, dw_die_ref
);
3294 static void gen_block_die (tree
, dw_die_ref
);
3295 static void decls_for_scope (tree
, dw_die_ref
);
3296 static inline int is_redundant_typedef (const_tree
);
3297 static bool is_naming_typedef_decl (const_tree
);
3298 static inline dw_die_ref
get_context_die (tree
);
3299 static void gen_namespace_die (tree
, dw_die_ref
);
3300 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3301 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3302 static dw_die_ref
force_decl_die (tree
);
3303 static dw_die_ref
force_type_die (tree
);
3304 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3305 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3306 static struct dwarf_file_data
* lookup_filename (const char *);
3307 static void retry_incomplete_types (void);
3308 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3309 static void gen_generic_params_dies (tree
);
3310 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3311 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3312 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3313 static int file_info_cmp (const void *, const void *);
3314 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3315 const char *, const char *);
3316 static void output_loc_list (dw_loc_list_ref
);
3317 static char *gen_internal_sym (const char *);
3318 static bool want_pubnames (void);
3320 static void prune_unmark_dies (dw_die_ref
);
3321 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3322 static void prune_unused_types_mark (dw_die_ref
, int);
3323 static void prune_unused_types_walk (dw_die_ref
);
3324 static void prune_unused_types_walk_attribs (dw_die_ref
);
3325 static void prune_unused_types_prune (dw_die_ref
);
3326 static void prune_unused_types (void);
3327 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3328 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3329 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3330 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3331 const char *, const char *);
3332 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3333 static void gen_remaining_tmpl_value_param_die_attribute (void);
3334 static bool generic_type_p (tree
);
3335 static void schedule_generic_params_dies_gen (tree t
);
3336 static void gen_scheduled_generic_parms_dies (void);
3338 static const char *comp_dir_string (void);
3340 static void hash_loc_operands (dw_loc_descr_ref
, inchash::hash
&);
3342 /* enum for tracking thread-local variables whose address is really an offset
3343 relative to the TLS pointer, which will need link-time relocation, but will
3344 not need relocation by the DWARF consumer. */
3352 /* Return the operator to use for an address of a variable. For dtprel_true, we
3353 use DW_OP_const*. For regular variables, which need both link-time
3354 relocation and consumer-level relocation (e.g., to account for shared objects
3355 loaded at a random address), we use DW_OP_addr*. */
3357 static inline enum dwarf_location_atom
3358 dw_addr_op (enum dtprel_bool dtprel
)
3360 if (dtprel
== dtprel_true
)
3361 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3362 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3364 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3367 /* Return a pointer to a newly allocated address location description. If
3368 dwarf_split_debug_info is true, then record the address with the appropriate
3370 static inline dw_loc_descr_ref
3371 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3373 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3375 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3376 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3377 ref
->dtprel
= dtprel
;
3378 if (dwarf_split_debug_info
)
3379 ref
->dw_loc_oprnd1
.val_entry
3380 = add_addr_table_entry (addr
,
3381 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3383 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3388 /* Section names used to hold DWARF debugging information. */
3390 #ifndef DEBUG_INFO_SECTION
3391 #define DEBUG_INFO_SECTION ".debug_info"
3393 #ifndef DEBUG_DWO_INFO_SECTION
3394 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3396 #ifndef DEBUG_ABBREV_SECTION
3397 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3399 #ifndef DEBUG_DWO_ABBREV_SECTION
3400 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3402 #ifndef DEBUG_ARANGES_SECTION
3403 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3405 #ifndef DEBUG_ADDR_SECTION
3406 #define DEBUG_ADDR_SECTION ".debug_addr"
3408 #ifndef DEBUG_NORM_MACINFO_SECTION
3409 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3411 #ifndef DEBUG_DWO_MACINFO_SECTION
3412 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3414 #ifndef DEBUG_MACINFO_SECTION
3415 #define DEBUG_MACINFO_SECTION \
3416 (!dwarf_split_debug_info \
3417 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3419 #ifndef DEBUG_NORM_MACRO_SECTION
3420 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3422 #ifndef DEBUG_DWO_MACRO_SECTION
3423 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3425 #ifndef DEBUG_MACRO_SECTION
3426 #define DEBUG_MACRO_SECTION \
3427 (!dwarf_split_debug_info \
3428 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3430 #ifndef DEBUG_LINE_SECTION
3431 #define DEBUG_LINE_SECTION ".debug_line"
3433 #ifndef DEBUG_DWO_LINE_SECTION
3434 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3436 #ifndef DEBUG_LOC_SECTION
3437 #define DEBUG_LOC_SECTION ".debug_loc"
3439 #ifndef DEBUG_DWO_LOC_SECTION
3440 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3442 #ifndef DEBUG_PUBNAMES_SECTION
3443 #define DEBUG_PUBNAMES_SECTION \
3444 ((debug_generate_pub_sections == 2) \
3445 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3447 #ifndef DEBUG_PUBTYPES_SECTION
3448 #define DEBUG_PUBTYPES_SECTION \
3449 ((debug_generate_pub_sections == 2) \
3450 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3452 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3453 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3454 #ifndef DEBUG_STR_OFFSETS_SECTION
3455 #define DEBUG_STR_OFFSETS_SECTION \
3456 (!dwarf_split_debug_info \
3457 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3459 #ifndef DEBUG_STR_DWO_SECTION
3460 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3462 #ifndef DEBUG_STR_SECTION
3463 #define DEBUG_STR_SECTION ".debug_str"
3465 #ifndef DEBUG_RANGES_SECTION
3466 #define DEBUG_RANGES_SECTION ".debug_ranges"
3469 /* Standard ELF section names for compiled code and data. */
3470 #ifndef TEXT_SECTION_NAME
3471 #define TEXT_SECTION_NAME ".text"
3474 /* Section flags for .debug_macinfo/.debug_macro section. */
3475 #define DEBUG_MACRO_SECTION_FLAGS \
3476 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3478 /* Section flags for .debug_str section. */
3479 #define DEBUG_STR_SECTION_FLAGS \
3480 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3481 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3484 /* Section flags for .debug_str.dwo section. */
3485 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3487 /* Labels we insert at beginning sections we can reference instead of
3488 the section names themselves. */
3490 #ifndef TEXT_SECTION_LABEL
3491 #define TEXT_SECTION_LABEL "Ltext"
3493 #ifndef COLD_TEXT_SECTION_LABEL
3494 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3496 #ifndef DEBUG_LINE_SECTION_LABEL
3497 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3499 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3500 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3502 #ifndef DEBUG_INFO_SECTION_LABEL
3503 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3505 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3506 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3508 #ifndef DEBUG_ABBREV_SECTION_LABEL
3509 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3511 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3512 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3514 #ifndef DEBUG_ADDR_SECTION_LABEL
3515 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3517 #ifndef DEBUG_LOC_SECTION_LABEL
3518 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3520 #ifndef DEBUG_RANGES_SECTION_LABEL
3521 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3523 #ifndef DEBUG_MACINFO_SECTION_LABEL
3524 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3526 #ifndef DEBUG_MACRO_SECTION_LABEL
3527 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3529 #define SKELETON_COMP_DIE_ABBREV 1
3530 #define SKELETON_TYPE_DIE_ABBREV 2
3532 /* Definitions of defaults for formats and names of various special
3533 (artificial) labels which may be generated within this file (when the -g
3534 options is used and DWARF2_DEBUGGING_INFO is in effect.
3535 If necessary, these may be overridden from within the tm.h file, but
3536 typically, overriding these defaults is unnecessary. */
3538 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3539 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3540 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3541 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3542 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3543 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3544 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3545 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3546 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3547 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3548 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3549 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3550 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3551 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3553 #ifndef TEXT_END_LABEL
3554 #define TEXT_END_LABEL "Letext"
3556 #ifndef COLD_END_LABEL
3557 #define COLD_END_LABEL "Letext_cold"
3559 #ifndef BLOCK_BEGIN_LABEL
3560 #define BLOCK_BEGIN_LABEL "LBB"
3562 #ifndef BLOCK_END_LABEL
3563 #define BLOCK_END_LABEL "LBE"
3565 #ifndef LINE_CODE_LABEL
3566 #define LINE_CODE_LABEL "LM"
3570 /* Return the root of the DIE's built for the current compilation unit. */
3572 comp_unit_die (void)
3574 if (!single_comp_unit_die
)
3575 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3576 return single_comp_unit_die
;
3579 /* We allow a language front-end to designate a function that is to be
3580 called to "demangle" any name before it is put into a DIE. */
3582 static const char *(*demangle_name_func
) (const char *);
3585 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3587 demangle_name_func
= func
;
3590 /* Test if rtl node points to a pseudo register. */
3593 is_pseudo_reg (const_rtx rtl
)
3595 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3596 || (GET_CODE (rtl
) == SUBREG
3597 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3600 /* Return a reference to a type, with its const and volatile qualifiers
3604 type_main_variant (tree type
)
3606 type
= TYPE_MAIN_VARIANT (type
);
3608 /* ??? There really should be only one main variant among any group of
3609 variants of a given type (and all of the MAIN_VARIANT values for all
3610 members of the group should point to that one type) but sometimes the C
3611 front-end messes this up for array types, so we work around that bug
3613 if (TREE_CODE (type
) == ARRAY_TYPE
)
3614 while (type
!= TYPE_MAIN_VARIANT (type
))
3615 type
= TYPE_MAIN_VARIANT (type
);
3620 /* Return nonzero if the given type node represents a tagged type. */
3623 is_tagged_type (const_tree type
)
3625 enum tree_code code
= TREE_CODE (type
);
3627 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3628 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3631 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3634 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3636 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3639 /* Return die_offset of a DIE reference to a base type. */
3641 static unsigned long int
3642 get_base_type_offset (dw_die_ref ref
)
3644 if (ref
->die_offset
)
3645 return ref
->die_offset
;
3646 if (comp_unit_die ()->die_abbrev
)
3648 calc_base_type_die_sizes ();
3649 gcc_assert (ref
->die_offset
);
3651 return ref
->die_offset
;
3654 /* Return die_offset of a DIE reference other than base type. */
3656 static unsigned long int
3657 get_ref_die_offset (dw_die_ref ref
)
3659 gcc_assert (ref
->die_offset
);
3660 return ref
->die_offset
;
3663 /* Convert a DIE tag into its string name. */
3666 dwarf_tag_name (unsigned int tag
)
3668 const char *name
= get_DW_TAG_name (tag
);
3673 return "DW_TAG_<unknown>";
3676 /* Convert a DWARF attribute code into its string name. */
3679 dwarf_attr_name (unsigned int attr
)
3685 #if VMS_DEBUGGING_INFO
3686 case DW_AT_HP_prologue
:
3687 return "DW_AT_HP_prologue";
3689 case DW_AT_MIPS_loop_unroll_factor
:
3690 return "DW_AT_MIPS_loop_unroll_factor";
3693 #if VMS_DEBUGGING_INFO
3694 case DW_AT_HP_epilogue
:
3695 return "DW_AT_HP_epilogue";
3697 case DW_AT_MIPS_stride
:
3698 return "DW_AT_MIPS_stride";
3702 name
= get_DW_AT_name (attr
);
3707 return "DW_AT_<unknown>";
3710 /* Convert a DWARF value form code into its string name. */
3713 dwarf_form_name (unsigned int form
)
3715 const char *name
= get_DW_FORM_name (form
);
3720 return "DW_FORM_<unknown>";
3723 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3724 instance of an inlined instance of a decl which is local to an inline
3725 function, so we have to trace all of the way back through the origin chain
3726 to find out what sort of node actually served as the original seed for the
3730 decl_ultimate_origin (const_tree decl
)
3732 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3735 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
3736 we're trying to output the abstract instance of this function. */
3737 if (DECL_ABSTRACT_P (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3740 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3741 most distant ancestor, this should never happen. */
3742 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3744 return DECL_ABSTRACT_ORIGIN (decl
);
3747 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3748 of a virtual function may refer to a base class, so we check the 'this'
3752 decl_class_context (tree decl
)
3754 tree context
= NULL_TREE
;
3756 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3757 context
= DECL_CONTEXT (decl
);
3759 context
= TYPE_MAIN_VARIANT
3760 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3762 if (context
&& !TYPE_P (context
))
3763 context
= NULL_TREE
;
3768 /* Add an attribute/value pair to a DIE. */
3771 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3773 /* Maybe this should be an assert? */
3777 vec_safe_reserve (die
->die_attr
, 1);
3778 vec_safe_push (die
->die_attr
, *attr
);
3781 static inline enum dw_val_class
3782 AT_class (dw_attr_ref a
)
3784 return a
->dw_attr_val
.val_class
;
3787 /* Return the index for any attribute that will be referenced with a
3788 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3789 are stored in dw_attr_val.v.val_str for reference counting
3792 static inline unsigned int
3793 AT_index (dw_attr_ref a
)
3795 if (AT_class (a
) == dw_val_class_str
)
3796 return a
->dw_attr_val
.v
.val_str
->index
;
3797 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3798 return a
->dw_attr_val
.val_entry
->index
;
3802 /* Add a flag value attribute to a DIE. */
3805 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3809 attr
.dw_attr
= attr_kind
;
3810 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3811 attr
.dw_attr_val
.val_entry
= NULL
;
3812 attr
.dw_attr_val
.v
.val_flag
= flag
;
3813 add_dwarf_attr (die
, &attr
);
3816 static inline unsigned
3817 AT_flag (dw_attr_ref a
)
3819 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3820 return a
->dw_attr_val
.v
.val_flag
;
3823 /* Add a signed integer attribute value to a DIE. */
3826 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3830 attr
.dw_attr
= attr_kind
;
3831 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3832 attr
.dw_attr_val
.val_entry
= NULL
;
3833 attr
.dw_attr_val
.v
.val_int
= int_val
;
3834 add_dwarf_attr (die
, &attr
);
3837 static inline HOST_WIDE_INT
3838 AT_int (dw_attr_ref a
)
3840 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3841 return a
->dw_attr_val
.v
.val_int
;
3844 /* Add an unsigned integer attribute value to a DIE. */
3847 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3848 unsigned HOST_WIDE_INT unsigned_val
)
3852 attr
.dw_attr
= attr_kind
;
3853 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3854 attr
.dw_attr_val
.val_entry
= NULL
;
3855 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3856 add_dwarf_attr (die
, &attr
);
3859 static inline unsigned HOST_WIDE_INT
3860 AT_unsigned (dw_attr_ref a
)
3862 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3863 return a
->dw_attr_val
.v
.val_unsigned
;
3866 /* Add an unsigned wide integer attribute value to a DIE. */
3869 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3874 attr
.dw_attr
= attr_kind
;
3875 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
3876 attr
.dw_attr_val
.val_entry
= NULL
;
3877 attr
.dw_attr_val
.v
.val_wide
= ggc_alloc
<wide_int
> ();
3878 *attr
.dw_attr_val
.v
.val_wide
= w
;
3879 add_dwarf_attr (die
, &attr
);
3882 /* Add an unsigned double integer attribute value to a DIE. */
3885 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3886 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3890 attr
.dw_attr
= attr_kind
;
3891 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3892 attr
.dw_attr_val
.val_entry
= NULL
;
3893 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3894 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3895 add_dwarf_attr (die
, &attr
);
3898 /* Add a floating point attribute value to a DIE and return it. */
3901 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3902 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3906 attr
.dw_attr
= attr_kind
;
3907 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3908 attr
.dw_attr_val
.val_entry
= NULL
;
3909 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3910 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3911 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3912 add_dwarf_attr (die
, &attr
);
3915 /* Add an 8-byte data attribute value to a DIE. */
3918 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3919 unsigned char data8
[8])
3923 attr
.dw_attr
= attr_kind
;
3924 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3925 attr
.dw_attr_val
.val_entry
= NULL
;
3926 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3927 add_dwarf_attr (die
, &attr
);
3930 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3931 dwarf_split_debug_info, address attributes in dies destined for the
3932 final executable have force_direct set to avoid using indexed
3936 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3942 lbl_id
= xstrdup (lbl_low
);
3943 attr
.dw_attr
= DW_AT_low_pc
;
3944 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3945 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3946 if (dwarf_split_debug_info
&& !force_direct
)
3947 attr
.dw_attr_val
.val_entry
3948 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3950 attr
.dw_attr_val
.val_entry
= NULL
;
3951 add_dwarf_attr (die
, &attr
);
3953 attr
.dw_attr
= DW_AT_high_pc
;
3954 if (dwarf_version
< 4)
3955 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3957 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3958 lbl_id
= xstrdup (lbl_high
);
3959 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3960 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3961 && dwarf_split_debug_info
&& !force_direct
)
3962 attr
.dw_attr_val
.val_entry
3963 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3965 attr
.dw_attr_val
.val_entry
= NULL
;
3966 add_dwarf_attr (die
, &attr
);
3969 /* Hash and equality functions for debug_str_hash. */
3972 indirect_string_hasher::hash (indirect_string_node
*x
)
3974 return htab_hash_string (x
->str
);
3978 indirect_string_hasher::equal (indirect_string_node
*x1
, const char *x2
)
3980 return strcmp (x1
->str
, x2
) == 0;
3983 /* Add STR to the given string hash table. */
3985 static struct indirect_string_node
*
3986 find_AT_string_in_table (const char *str
,
3987 hash_table
<indirect_string_hasher
> *table
)
3989 struct indirect_string_node
*node
;
3991 indirect_string_node
**slot
3992 = table
->find_slot_with_hash (str
, htab_hash_string (str
), INSERT
);
3995 node
= ggc_cleared_alloc
<indirect_string_node
> ();
3996 node
->str
= ggc_strdup (str
);
4006 /* Add STR to the indirect string hash table. */
4008 static struct indirect_string_node
*
4009 find_AT_string (const char *str
)
4011 if (! debug_str_hash
)
4012 debug_str_hash
= hash_table
<indirect_string_hasher
>::create_ggc (10);
4014 return find_AT_string_in_table (str
, debug_str_hash
);
4017 /* Add a string attribute value to a DIE. */
4020 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4023 struct indirect_string_node
*node
;
4025 node
= find_AT_string (str
);
4027 attr
.dw_attr
= attr_kind
;
4028 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4029 attr
.dw_attr_val
.val_entry
= NULL
;
4030 attr
.dw_attr_val
.v
.val_str
= node
;
4031 add_dwarf_attr (die
, &attr
);
4034 static inline const char *
4035 AT_string (dw_attr_ref a
)
4037 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4038 return a
->dw_attr_val
.v
.val_str
->str
;
4041 /* Call this function directly to bypass AT_string_form's logic to put
4042 the string inline in the die. */
4045 set_indirect_string (struct indirect_string_node
*node
)
4048 /* Already indirect is a no op. */
4049 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
4051 gcc_assert (node
->label
);
4054 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4055 ++dw2_string_counter
;
4056 node
->label
= xstrdup (label
);
4058 if (!dwarf_split_debug_info
)
4060 node
->form
= DW_FORM_strp
;
4061 node
->index
= NOT_INDEXED
;
4065 node
->form
= DW_FORM_GNU_str_index
;
4066 node
->index
= NO_INDEX_ASSIGNED
;
4070 /* Find out whether a string should be output inline in DIE
4071 or out-of-line in .debug_str section. */
4073 static enum dwarf_form
4074 find_string_form (struct indirect_string_node
*node
)
4081 len
= strlen (node
->str
) + 1;
4083 /* If the string is shorter or equal to the size of the reference, it is
4084 always better to put it inline. */
4085 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4086 return node
->form
= DW_FORM_string
;
4088 /* If we cannot expect the linker to merge strings in .debug_str
4089 section, only put it into .debug_str if it is worth even in this
4091 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4092 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4093 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4094 return node
->form
= DW_FORM_string
;
4096 set_indirect_string (node
);
4101 /* Find out whether the string referenced from the attribute should be
4102 output inline in DIE or out-of-line in .debug_str section. */
4104 static enum dwarf_form
4105 AT_string_form (dw_attr_ref a
)
4107 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4108 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4111 /* Add a DIE reference attribute value to a DIE. */
4114 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4118 #ifdef ENABLE_CHECKING
4119 gcc_assert (targ_die
!= NULL
);
4121 /* With LTO we can end up trying to reference something we didn't create
4122 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4123 if (targ_die
== NULL
)
4127 attr
.dw_attr
= attr_kind
;
4128 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4129 attr
.dw_attr_val
.val_entry
= NULL
;
4130 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4131 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4132 add_dwarf_attr (die
, &attr
);
4135 /* Change DIE reference REF to point to NEW_DIE instead. */
4138 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
4140 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4141 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4142 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4145 /* Add an AT_specification attribute to a DIE, and also make the back
4146 pointer from the specification to the definition. */
4149 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4151 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4152 gcc_assert (!targ_die
->die_definition
);
4153 targ_die
->die_definition
= die
;
4156 static inline dw_die_ref
4157 AT_ref (dw_attr_ref a
)
4159 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4160 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4164 AT_ref_external (dw_attr_ref a
)
4166 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4167 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4173 set_AT_ref_external (dw_attr_ref a
, int i
)
4175 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4176 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4179 /* Add an FDE reference attribute value to a DIE. */
4182 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4186 attr
.dw_attr
= attr_kind
;
4187 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4188 attr
.dw_attr_val
.val_entry
= NULL
;
4189 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4190 add_dwarf_attr (die
, &attr
);
4193 /* Add a location description attribute value to a DIE. */
4196 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4200 attr
.dw_attr
= attr_kind
;
4201 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4202 attr
.dw_attr_val
.val_entry
= NULL
;
4203 attr
.dw_attr_val
.v
.val_loc
= loc
;
4204 add_dwarf_attr (die
, &attr
);
4207 static inline dw_loc_descr_ref
4208 AT_loc (dw_attr_ref a
)
4210 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4211 return a
->dw_attr_val
.v
.val_loc
;
4215 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4219 attr
.dw_attr
= attr_kind
;
4220 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4221 attr
.dw_attr_val
.val_entry
= NULL
;
4222 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4223 add_dwarf_attr (die
, &attr
);
4224 have_location_lists
= true;
4227 static inline dw_loc_list_ref
4228 AT_loc_list (dw_attr_ref a
)
4230 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4231 return a
->dw_attr_val
.v
.val_loc_list
;
4234 static inline dw_loc_list_ref
*
4235 AT_loc_list_ptr (dw_attr_ref a
)
4237 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4238 return &a
->dw_attr_val
.v
.val_loc_list
;
4241 struct addr_hasher
: ggc_ptr_hash
<addr_table_entry
>
4243 static hashval_t
hash (addr_table_entry
*);
4244 static bool equal (addr_table_entry
*, addr_table_entry
*);
4247 /* Table of entries into the .debug_addr section. */
4249 static GTY (()) hash_table
<addr_hasher
> *addr_index_table
;
4251 /* Hash an address_table_entry. */
4254 addr_hasher::hash (addr_table_entry
*a
)
4256 inchash::hash hstate
;
4262 case ate_kind_rtx_dtprel
:
4265 case ate_kind_label
:
4266 return htab_hash_string (a
->addr
.label
);
4270 inchash::add_rtx (a
->addr
.rtl
, hstate
);
4271 return hstate
.end ();
4274 /* Determine equality for two address_table_entries. */
4277 addr_hasher::equal (addr_table_entry
*a1
, addr_table_entry
*a2
)
4279 if (a1
->kind
!= a2
->kind
)
4284 case ate_kind_rtx_dtprel
:
4285 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4286 case ate_kind_label
:
4287 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4293 /* Initialize an addr_table_entry. */
4296 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4302 case ate_kind_rtx_dtprel
:
4303 e
->addr
.rtl
= (rtx
) addr
;
4305 case ate_kind_label
:
4306 e
->addr
.label
= (char *) addr
;
4310 e
->index
= NO_INDEX_ASSIGNED
;
4313 /* Add attr to the address table entry to the table. Defer setting an
4314 index until output time. */
4316 static addr_table_entry
*
4317 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4319 addr_table_entry
*node
;
4320 addr_table_entry finder
;
4322 gcc_assert (dwarf_split_debug_info
);
4323 if (! addr_index_table
)
4324 addr_index_table
= hash_table
<addr_hasher
>::create_ggc (10);
4325 init_addr_table_entry (&finder
, kind
, addr
);
4326 addr_table_entry
**slot
= addr_index_table
->find_slot (&finder
, INSERT
);
4328 if (*slot
== HTAB_EMPTY_ENTRY
)
4330 node
= ggc_cleared_alloc
<addr_table_entry
> ();
4331 init_addr_table_entry (node
, kind
, addr
);
4341 /* Remove an entry from the addr table by decrementing its refcount.
4342 Strictly, decrementing the refcount would be enough, but the
4343 assertion that the entry is actually in the table has found
4347 remove_addr_table_entry (addr_table_entry
*entry
)
4349 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4350 /* After an index is assigned, the table is frozen. */
4351 gcc_assert (entry
->refcount
> 0 && entry
->index
== NO_INDEX_ASSIGNED
);
4355 /* Given a location list, remove all addresses it refers to from the
4359 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4361 for (; descr
; descr
= descr
->dw_loc_next
)
4362 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4364 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4365 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4369 /* A helper function for dwarf2out_finish called through
4370 htab_traverse. Assign an addr_table_entry its index. All entries
4371 must be collected into the table when this function is called,
4372 because the indexing code relies on htab_traverse to traverse nodes
4373 in the same order for each run. */
4376 index_addr_table_entry (addr_table_entry
**h
, unsigned int *index
)
4378 addr_table_entry
*node
= *h
;
4380 /* Don't index unreferenced nodes. */
4381 if (node
->refcount
== 0)
4384 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4385 node
->index
= *index
;
4391 /* Add an address constant attribute value to a DIE. When using
4392 dwarf_split_debug_info, address attributes in dies destined for the
4393 final executable should be direct references--setting the parameter
4394 force_direct ensures this behavior. */
4397 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4402 attr
.dw_attr
= attr_kind
;
4403 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4404 attr
.dw_attr_val
.v
.val_addr
= addr
;
4405 if (dwarf_split_debug_info
&& !force_direct
)
4406 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4408 attr
.dw_attr_val
.val_entry
= NULL
;
4409 add_dwarf_attr (die
, &attr
);
4412 /* Get the RTX from to an address DIE attribute. */
4415 AT_addr (dw_attr_ref a
)
4417 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4418 return a
->dw_attr_val
.v
.val_addr
;
4421 /* Add a file attribute value to a DIE. */
4424 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4425 struct dwarf_file_data
*fd
)
4429 attr
.dw_attr
= attr_kind
;
4430 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4431 attr
.dw_attr_val
.val_entry
= NULL
;
4432 attr
.dw_attr_val
.v
.val_file
= fd
;
4433 add_dwarf_attr (die
, &attr
);
4436 /* Get the dwarf_file_data from a file DIE attribute. */
4438 static inline struct dwarf_file_data
*
4439 AT_file (dw_attr_ref a
)
4441 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4442 return a
->dw_attr_val
.v
.val_file
;
4445 /* Add a vms delta attribute value to a DIE. */
4448 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4449 const char *lbl1
, const char *lbl2
)
4453 attr
.dw_attr
= attr_kind
;
4454 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4455 attr
.dw_attr_val
.val_entry
= NULL
;
4456 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4457 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4458 add_dwarf_attr (die
, &attr
);
4461 /* Add a label identifier attribute value to a DIE. */
4464 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4469 attr
.dw_attr
= attr_kind
;
4470 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4471 attr
.dw_attr_val
.val_entry
= NULL
;
4472 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4473 if (dwarf_split_debug_info
)
4474 attr
.dw_attr_val
.val_entry
4475 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4477 add_dwarf_attr (die
, &attr
);
4480 /* Add a section offset attribute value to a DIE, an offset into the
4481 debug_line section. */
4484 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4489 attr
.dw_attr
= attr_kind
;
4490 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4491 attr
.dw_attr_val
.val_entry
= NULL
;
4492 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4493 add_dwarf_attr (die
, &attr
);
4496 /* Add a section offset attribute value to a DIE, an offset into the
4497 debug_macinfo section. */
4500 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4505 attr
.dw_attr
= attr_kind
;
4506 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4507 attr
.dw_attr_val
.val_entry
= NULL
;
4508 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4509 add_dwarf_attr (die
, &attr
);
4512 /* Add an offset attribute value to a DIE. */
4515 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4516 unsigned HOST_WIDE_INT offset
)
4520 attr
.dw_attr
= attr_kind
;
4521 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4522 attr
.dw_attr_val
.val_entry
= NULL
;
4523 attr
.dw_attr_val
.v
.val_offset
= offset
;
4524 add_dwarf_attr (die
, &attr
);
4527 /* Add a range_list attribute value to a DIE. When using
4528 dwarf_split_debug_info, address attributes in dies destined for the
4529 final executable should be direct references--setting the parameter
4530 force_direct ensures this behavior. */
4532 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4533 #define RELOCATED_OFFSET (NULL)
4536 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4537 long unsigned int offset
, bool force_direct
)
4541 attr
.dw_attr
= attr_kind
;
4542 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4543 /* For the range_list attribute, use val_entry to store whether the
4544 offset should follow split-debug-info or normal semantics. This
4545 value is read in output_range_list_offset. */
4546 if (dwarf_split_debug_info
&& !force_direct
)
4547 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4549 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4550 attr
.dw_attr_val
.v
.val_offset
= offset
;
4551 add_dwarf_attr (die
, &attr
);
4554 /* Return the start label of a delta attribute. */
4556 static inline const char *
4557 AT_vms_delta1 (dw_attr_ref a
)
4559 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4560 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4563 /* Return the end label of a delta attribute. */
4565 static inline const char *
4566 AT_vms_delta2 (dw_attr_ref a
)
4568 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4569 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4572 static inline const char *
4573 AT_lbl (dw_attr_ref a
)
4575 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4576 || AT_class (a
) == dw_val_class_lineptr
4577 || AT_class (a
) == dw_val_class_macptr
4578 || AT_class (a
) == dw_val_class_high_pc
));
4579 return a
->dw_attr_val
.v
.val_lbl_id
;
4582 /* Get the attribute of type attr_kind. */
4585 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4589 dw_die_ref spec
= NULL
;
4594 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4595 if (a
->dw_attr
== attr_kind
)
4597 else if (a
->dw_attr
== DW_AT_specification
4598 || a
->dw_attr
== DW_AT_abstract_origin
)
4602 return get_AT (spec
, attr_kind
);
4607 /* Returns the parent of the declaration of DIE. */
4610 get_die_parent (dw_die_ref die
)
4617 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4618 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4621 return die
->die_parent
;
4624 /* Return the "low pc" attribute value, typically associated with a subprogram
4625 DIE. Return null if the "low pc" attribute is either not present, or if it
4626 cannot be represented as an assembler label identifier. */
4628 static inline const char *
4629 get_AT_low_pc (dw_die_ref die
)
4631 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4633 return a
? AT_lbl (a
) : NULL
;
4636 /* Return the "high pc" attribute value, typically associated with a subprogram
4637 DIE. Return null if the "high pc" attribute is either not present, or if it
4638 cannot be represented as an assembler label identifier. */
4640 static inline const char *
4641 get_AT_hi_pc (dw_die_ref die
)
4643 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4645 return a
? AT_lbl (a
) : NULL
;
4648 /* Return the value of the string attribute designated by ATTR_KIND, or
4649 NULL if it is not present. */
4651 static inline const char *
4652 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4654 dw_attr_ref a
= get_AT (die
, attr_kind
);
4656 return a
? AT_string (a
) : NULL
;
4659 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4660 if it is not present. */
4663 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4665 dw_attr_ref a
= get_AT (die
, attr_kind
);
4667 return a
? AT_flag (a
) : 0;
4670 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4671 if it is not present. */
4673 static inline unsigned
4674 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4676 dw_attr_ref a
= get_AT (die
, attr_kind
);
4678 return a
? AT_unsigned (a
) : 0;
4681 static inline dw_die_ref
4682 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4684 dw_attr_ref a
= get_AT (die
, attr_kind
);
4686 return a
? AT_ref (a
) : NULL
;
4689 static inline struct dwarf_file_data
*
4690 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4692 dw_attr_ref a
= get_AT (die
, attr_kind
);
4694 return a
? AT_file (a
) : NULL
;
4697 /* Return TRUE if the language is C++. */
4702 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4704 return (lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
4705 || lang
== DW_LANG_C_plus_plus_11
|| lang
== DW_LANG_C_plus_plus_14
);
4708 /* Return TRUE if the language is Java. */
4713 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4715 return lang
== DW_LANG_Java
;
4718 /* Return TRUE if the language is Fortran. */
4723 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4725 return (lang
== DW_LANG_Fortran77
4726 || lang
== DW_LANG_Fortran90
4727 || lang
== DW_LANG_Fortran95
4728 || lang
== DW_LANG_Fortran03
4729 || lang
== DW_LANG_Fortran08
);
4732 /* Return TRUE if the language is Ada. */
4737 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4739 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4742 /* Remove the specified attribute if present. Return TRUE if removal
4746 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4754 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4755 if (a
->dw_attr
== attr_kind
)
4757 if (AT_class (a
) == dw_val_class_str
)
4758 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4759 a
->dw_attr_val
.v
.val_str
->refcount
--;
4761 /* vec::ordered_remove should help reduce the number of abbrevs
4763 die
->die_attr
->ordered_remove (ix
);
4769 /* Remove CHILD from its parent. PREV must have the property that
4770 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4773 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4775 gcc_assert (child
->die_parent
== prev
->die_parent
);
4776 gcc_assert (prev
->die_sib
== child
);
4779 gcc_assert (child
->die_parent
->die_child
== child
);
4783 prev
->die_sib
= child
->die_sib
;
4784 if (child
->die_parent
->die_child
== child
)
4785 child
->die_parent
->die_child
= prev
;
4788 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4789 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4792 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4794 dw_die_ref parent
= old_child
->die_parent
;
4796 gcc_assert (parent
== prev
->die_parent
);
4797 gcc_assert (prev
->die_sib
== old_child
);
4799 new_child
->die_parent
= parent
;
4800 if (prev
== old_child
)
4802 gcc_assert (parent
->die_child
== old_child
);
4803 new_child
->die_sib
= new_child
;
4807 prev
->die_sib
= new_child
;
4808 new_child
->die_sib
= old_child
->die_sib
;
4810 if (old_child
->die_parent
->die_child
== old_child
)
4811 old_child
->die_parent
->die_child
= new_child
;
4814 /* Move all children from OLD_PARENT to NEW_PARENT. */
4817 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4820 new_parent
->die_child
= old_parent
->die_child
;
4821 old_parent
->die_child
= NULL
;
4822 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4825 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4829 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4835 dw_die_ref prev
= c
;
4837 while (c
->die_tag
== tag
)
4839 remove_child_with_prev (c
, prev
);
4840 c
->die_parent
= NULL
;
4841 /* Might have removed every child. */
4842 if (c
== c
->die_sib
)
4846 } while (c
!= die
->die_child
);
4849 /* Add a CHILD_DIE as the last child of DIE. */
4852 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4854 /* FIXME this should probably be an assert. */
4855 if (! die
|| ! child_die
)
4857 gcc_assert (die
!= child_die
);
4859 child_die
->die_parent
= die
;
4862 child_die
->die_sib
= die
->die_child
->die_sib
;
4863 die
->die_child
->die_sib
= child_die
;
4866 child_die
->die_sib
= child_die
;
4867 die
->die_child
= child_die
;
4870 /* Unassociate CHILD from its parent, and make its parent be
4874 reparent_child (dw_die_ref child
, dw_die_ref new_parent
)
4876 for (dw_die_ref p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4877 if (p
->die_sib
== child
)
4879 remove_child_with_prev (child
, p
);
4882 add_child_die (new_parent
, child
);
4885 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4886 is the specification, to the end of PARENT's list of children.
4887 This is done by removing and re-adding it. */
4890 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4892 /* We want the declaration DIE from inside the class, not the
4893 specification DIE at toplevel. */
4894 if (child
->die_parent
!= parent
)
4896 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4902 gcc_assert (child
->die_parent
== parent
4903 || (child
->die_parent
4904 == get_AT_ref (parent
, DW_AT_specification
)));
4906 reparent_child (child
, parent
);
4909 /* Create and return a new die with a parent of PARENT_DIE. If
4910 PARENT_DIE is NULL, the new DIE is placed in limbo and an
4911 associated tree T must be supplied to determine parenthood
4914 static inline dw_die_ref
4915 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4917 dw_die_ref die
= ggc_cleared_alloc
<die_node
> ();
4919 die
->die_tag
= tag_value
;
4921 if (parent_die
!= NULL
)
4922 add_child_die (parent_die
, die
);
4925 limbo_die_node
*limbo_node
;
4927 /* No DIEs created after early dwarf should end up in limbo,
4928 because the limbo list should not persist past LTO
4930 if (tag_value
!= DW_TAG_compile_unit
4931 /* These are allowed because they're generated while
4932 breaking out COMDAT units late. */
4933 && tag_value
!= DW_TAG_type_unit
4935 /* Allow nested functions to live in limbo because they will
4936 only temporarily live there, as decls_for_scope will fix
4938 && (TREE_CODE (t
) != FUNCTION_DECL
4939 || !decl_function_context (t
))
4940 /* Same as nested functions above but for types. Types that
4941 are local to a function will be fixed in
4943 && (!RECORD_OR_UNION_TYPE_P (t
)
4944 || !TYPE_CONTEXT (t
)
4945 || TREE_CODE (TYPE_CONTEXT (t
)) != FUNCTION_DECL
)
4946 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
4947 especially in the ltrans stage, but once we implement LTO
4948 dwarf streaming, we should remove this exception. */
4951 fprintf (stderr
, "symbol ended up in limbo too late:");
4952 debug_generic_stmt (t
);
4956 limbo_node
= ggc_cleared_alloc
<limbo_die_node
> ();
4957 limbo_node
->die
= die
;
4958 limbo_node
->created_for
= t
;
4959 limbo_node
->next
= limbo_die_list
;
4960 limbo_die_list
= limbo_node
;
4966 /* Return the DIE associated with the given type specifier. */
4968 static inline dw_die_ref
4969 lookup_type_die (tree type
)
4971 return TYPE_SYMTAB_DIE (type
);
4974 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4975 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4976 anonymous type instead the one of the naming typedef. */
4978 static inline dw_die_ref
4979 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4982 && TREE_CODE (type
) == RECORD_TYPE
4984 && type_die
->die_tag
== DW_TAG_typedef
4985 && is_naming_typedef_decl (TYPE_NAME (type
)))
4986 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4990 /* Like lookup_type_die, but if type is an anonymous type named by a
4991 typedef[1], return the DIE of the anonymous type instead the one of
4992 the naming typedef. This is because in gen_typedef_die, we did
4993 equate the anonymous struct named by the typedef with the DIE of
4994 the naming typedef. So by default, lookup_type_die on an anonymous
4995 struct yields the DIE of the naming typedef.
4997 [1]: Read the comment of is_naming_typedef_decl to learn about what
4998 a naming typedef is. */
5000 static inline dw_die_ref
5001 lookup_type_die_strip_naming_typedef (tree type
)
5003 dw_die_ref die
= lookup_type_die (type
);
5004 return strip_naming_typedef (type
, die
);
5007 /* Equate a DIE to a given type specifier. */
5010 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5012 TYPE_SYMTAB_DIE (type
) = type_die
;
5015 /* Returns a hash value for X (which really is a die_struct). */
5018 decl_die_hasher::hash (die_node
*x
)
5020 return (hashval_t
) x
->decl_id
;
5023 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5026 decl_die_hasher::equal (die_node
*x
, tree y
)
5028 return (x
->decl_id
== DECL_UID (y
));
5031 /* Return the DIE associated with a given declaration. */
5033 static inline dw_die_ref
5034 lookup_decl_die (tree decl
)
5036 return decl_die_table
->find_with_hash (decl
, DECL_UID (decl
));
5039 /* Returns a hash value for X (which really is a var_loc_list). */
5042 decl_loc_hasher::hash (var_loc_list
*x
)
5044 return (hashval_t
) x
->decl_id
;
5047 /* Return nonzero if decl_id of var_loc_list X is the same as
5051 decl_loc_hasher::equal (var_loc_list
*x
, const_tree y
)
5053 return (x
->decl_id
== DECL_UID (y
));
5056 /* Return the var_loc list associated with a given declaration. */
5058 static inline var_loc_list
*
5059 lookup_decl_loc (const_tree decl
)
5061 if (!decl_loc_table
)
5063 return decl_loc_table
->find_with_hash (decl
, DECL_UID (decl
));
5066 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5069 dw_loc_list_hasher::hash (cached_dw_loc_list
*x
)
5071 return (hashval_t
) x
->decl_id
;
5074 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5078 dw_loc_list_hasher::equal (cached_dw_loc_list
*x
, const_tree y
)
5080 return (x
->decl_id
== DECL_UID (y
));
5083 /* Equate a DIE to a particular declaration. */
5086 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5088 unsigned int decl_id
= DECL_UID (decl
);
5090 *decl_die_table
->find_slot_with_hash (decl
, decl_id
, INSERT
) = decl_die
;
5091 decl_die
->decl_id
= decl_id
;
5094 /* Return how many bits covers PIECE EXPR_LIST. */
5096 static HOST_WIDE_INT
5097 decl_piece_bitsize (rtx piece
)
5099 int ret
= (int) GET_MODE (piece
);
5102 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
5103 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5104 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5107 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5110 decl_piece_varloc_ptr (rtx piece
)
5112 if ((int) GET_MODE (piece
))
5113 return &XEXP (piece
, 0);
5115 return &XEXP (XEXP (piece
, 0), 1);
5118 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5119 Next is the chain of following piece nodes. */
5121 static rtx_expr_list
*
5122 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5124 if (bitsize
> 0 && bitsize
<= (int) MAX_MACHINE_MODE
)
5125 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5127 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5132 /* Return rtx that should be stored into loc field for
5133 LOC_NOTE and BITPOS/BITSIZE. */
5136 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5137 HOST_WIDE_INT bitsize
)
5141 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5143 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5148 /* This function either modifies location piece list *DEST in
5149 place (if SRC and INNER is NULL), or copies location piece list
5150 *SRC to *DEST while modifying it. Location BITPOS is modified
5151 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5152 not copied and if needed some padding around it is added.
5153 When modifying in place, DEST should point to EXPR_LIST where
5154 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5155 to the start of the whole list and INNER points to the EXPR_LIST
5156 where earlier pieces cover PIECE_BITPOS bits. */
5159 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5160 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5161 HOST_WIDE_INT bitsize
, rtx loc_note
)
5164 bool copy
= inner
!= NULL
;
5168 /* First copy all nodes preceding the current bitpos. */
5169 while (src
!= inner
)
5171 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5172 decl_piece_bitsize (*src
), NULL_RTX
);
5173 dest
= &XEXP (*dest
, 1);
5174 src
= &XEXP (*src
, 1);
5177 /* Add padding if needed. */
5178 if (bitpos
!= piece_bitpos
)
5180 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5181 copy
? NULL_RTX
: *dest
);
5182 dest
= &XEXP (*dest
, 1);
5184 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5187 /* A piece with correct bitpos and bitsize already exist,
5188 just update the location for it and return. */
5189 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5192 /* Add the piece that changed. */
5193 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5194 dest
= &XEXP (*dest
, 1);
5195 /* Skip over pieces that overlap it. */
5196 diff
= bitpos
- piece_bitpos
+ bitsize
;
5199 while (diff
> 0 && *src
)
5202 diff
-= decl_piece_bitsize (piece
);
5204 src
= &XEXP (piece
, 1);
5207 *src
= XEXP (piece
, 1);
5208 free_EXPR_LIST_node (piece
);
5211 /* Add padding if needed. */
5212 if (diff
< 0 && *src
)
5216 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5217 dest
= &XEXP (*dest
, 1);
5221 /* Finally copy all nodes following it. */
5224 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5225 decl_piece_bitsize (*src
), NULL_RTX
);
5226 dest
= &XEXP (*dest
, 1);
5227 src
= &XEXP (*src
, 1);
5231 /* Add a variable location node to the linked list for DECL. */
5233 static struct var_loc_node
*
5234 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5236 unsigned int decl_id
;
5238 struct var_loc_node
*loc
= NULL
;
5239 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5241 if (TREE_CODE (decl
) == VAR_DECL
5242 && DECL_HAS_DEBUG_EXPR_P (decl
))
5244 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5245 if (handled_component_p (realdecl
)
5246 || (TREE_CODE (realdecl
) == MEM_REF
5247 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5249 HOST_WIDE_INT maxsize
;
5252 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5253 if (!DECL_P (innerdecl
)
5254 || DECL_IGNORED_P (innerdecl
)
5255 || TREE_STATIC (innerdecl
)
5257 || bitpos
+ bitsize
> 256
5258 || bitsize
!= maxsize
)
5264 decl_id
= DECL_UID (decl
);
5266 = decl_loc_table
->find_slot_with_hash (decl
, decl_id
, INSERT
);
5269 temp
= ggc_cleared_alloc
<var_loc_list
> ();
5270 temp
->decl_id
= decl_id
;
5276 /* For PARM_DECLs try to keep around the original incoming value,
5277 even if that means we'll emit a zero-range .debug_loc entry. */
5279 && temp
->first
== temp
->last
5280 && TREE_CODE (decl
) == PARM_DECL
5281 && NOTE_P (temp
->first
->loc
)
5282 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5283 && DECL_INCOMING_RTL (decl
)
5284 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5285 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5286 == GET_CODE (DECL_INCOMING_RTL (decl
))
5287 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5289 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5290 NOTE_VAR_LOCATION_LOC (loc_note
))
5291 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5292 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5294 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5295 temp
->first
->next
= loc
;
5297 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5299 else if (temp
->last
)
5301 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5302 rtx
*piece_loc
= NULL
, last_loc_note
;
5303 HOST_WIDE_INT piece_bitpos
= 0;
5307 gcc_assert (last
->next
== NULL
);
5309 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5311 piece_loc
= &last
->loc
;
5314 HOST_WIDE_INT cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5315 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5317 piece_bitpos
+= cur_bitsize
;
5318 piece_loc
= &XEXP (*piece_loc
, 1);
5322 /* TEMP->LAST here is either pointer to the last but one or
5323 last element in the chained list, LAST is pointer to the
5325 if (label
&& strcmp (last
->label
, label
) == 0)
5327 /* For SRA optimized variables if there weren't any real
5328 insns since last note, just modify the last node. */
5329 if (piece_loc
!= NULL
)
5331 adjust_piece_list (piece_loc
, NULL
, NULL
,
5332 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5335 /* If the last note doesn't cover any instructions, remove it. */
5336 if (temp
->last
!= last
)
5338 temp
->last
->next
= NULL
;
5341 gcc_assert (strcmp (last
->label
, label
) != 0);
5345 gcc_assert (temp
->first
== temp
->last
5346 || (temp
->first
->next
== temp
->last
5347 && TREE_CODE (decl
) == PARM_DECL
));
5348 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5349 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5353 if (bitsize
== -1 && NOTE_P (last
->loc
))
5354 last_loc_note
= last
->loc
;
5355 else if (piece_loc
!= NULL
5356 && *piece_loc
!= NULL_RTX
5357 && piece_bitpos
== bitpos
5358 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5359 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5361 last_loc_note
= NULL_RTX
;
5362 /* If the current location is the same as the end of the list,
5363 and either both or neither of the locations is uninitialized,
5364 we have nothing to do. */
5365 if (last_loc_note
== NULL_RTX
5366 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5367 NOTE_VAR_LOCATION_LOC (loc_note
)))
5368 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5369 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5370 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5371 == VAR_INIT_STATUS_UNINITIALIZED
)
5372 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5373 == VAR_INIT_STATUS_UNINITIALIZED
))))
5375 /* Add LOC to the end of list and update LAST. If the last
5376 element of the list has been removed above, reuse its
5377 memory for the new node, otherwise allocate a new one. */
5381 memset (loc
, '\0', sizeof (*loc
));
5384 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5385 if (bitsize
== -1 || piece_loc
== NULL
)
5386 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5388 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5389 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5391 /* Ensure TEMP->LAST will point either to the new last but one
5392 element of the chain, or to the last element in it. */
5393 if (last
!= temp
->last
)
5401 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5404 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5409 /* Keep track of the number of spaces used to indent the
5410 output of the debugging routines that print the structure of
5411 the DIE internal representation. */
5412 static int print_indent
;
5414 /* Indent the line the number of spaces given by print_indent. */
5417 print_spaces (FILE *outfile
)
5419 fprintf (outfile
, "%*s", print_indent
, "");
5422 /* Print a type signature in hex. */
5425 print_signature (FILE *outfile
, char *sig
)
5429 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5430 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5433 static void print_loc_descr (dw_loc_descr_ref
, FILE *);
5435 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
5436 RECURSE, output location descriptor operations. */
5439 print_dw_val (dw_val_node
*val
, bool recurse
, FILE *outfile
)
5441 switch (val
->val_class
)
5443 case dw_val_class_addr
:
5444 fprintf (outfile
, "address");
5446 case dw_val_class_offset
:
5447 fprintf (outfile
, "offset");
5449 case dw_val_class_loc
:
5450 fprintf (outfile
, "location descriptor");
5451 if (val
->v
.val_loc
== NULL
)
5452 fprintf (outfile
, " -> <null>\n");
5455 fprintf (outfile
, ":\n");
5457 print_loc_descr (val
->v
.val_loc
, outfile
);
5461 fprintf (outfile
, " (%p)\n", (void *) val
->v
.val_loc
);
5463 case dw_val_class_loc_list
:
5464 fprintf (outfile
, "location list -> label:%s",
5465 val
->v
.val_loc_list
->ll_symbol
);
5467 case dw_val_class_range_list
:
5468 fprintf (outfile
, "range list");
5470 case dw_val_class_const
:
5471 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, val
->v
.val_int
);
5473 case dw_val_class_unsigned_const
:
5474 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, val
->v
.val_unsigned
);
5476 case dw_val_class_const_double
:
5477 fprintf (outfile
, "constant (" HOST_WIDE_INT_PRINT_DEC
","\
5478 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5479 val
->v
.val_double
.high
,
5480 val
->v
.val_double
.low
);
5482 case dw_val_class_wide_int
:
5484 int i
= val
->v
.val_wide
->get_len ();
5485 fprintf (outfile
, "constant (");
5487 if (val
->v
.val_wide
->elt (i
- 1) == 0)
5488 fprintf (outfile
, "0x");
5489 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
5490 val
->v
.val_wide
->elt (--i
));
5492 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
5493 val
->v
.val_wide
->elt (i
));
5494 fprintf (outfile
, ")");
5497 case dw_val_class_vec
:
5498 fprintf (outfile
, "floating-point or vector constant");
5500 case dw_val_class_flag
:
5501 fprintf (outfile
, "%u", val
->v
.val_flag
);
5503 case dw_val_class_die_ref
:
5504 if (val
->v
.val_die_ref
.die
!= NULL
)
5506 dw_die_ref die
= val
->v
.val_die_ref
.die
;
5508 if (die
->comdat_type_p
)
5510 fprintf (outfile
, "die -> signature: ");
5511 print_signature (outfile
,
5512 die
->die_id
.die_type_node
->signature
);
5514 else if (die
->die_id
.die_symbol
)
5515 fprintf (outfile
, "die -> label: %s", die
->die_id
.die_symbol
);
5517 fprintf (outfile
, "die -> %ld", die
->die_offset
);
5518 fprintf (outfile
, " (%p)", (void *) die
);
5521 fprintf (outfile
, "die -> <null>");
5523 case dw_val_class_vms_delta
:
5524 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5525 val
->v
.val_vms_delta
.lbl2
, val
->v
.val_vms_delta
.lbl1
);
5527 case dw_val_class_lbl_id
:
5528 case dw_val_class_lineptr
:
5529 case dw_val_class_macptr
:
5530 case dw_val_class_high_pc
:
5531 fprintf (outfile
, "label: %s", val
->v
.val_lbl_id
);
5533 case dw_val_class_str
:
5534 if (val
->v
.val_str
->str
!= NULL
)
5535 fprintf (outfile
, "\"%s\"", val
->v
.val_str
->str
);
5537 fprintf (outfile
, "<null>");
5539 case dw_val_class_file
:
5540 fprintf (outfile
, "\"%s\" (%d)", val
->v
.val_file
->filename
,
5541 val
->v
.val_file
->emitted_number
);
5543 case dw_val_class_data8
:
5547 for (i
= 0; i
< 8; i
++)
5548 fprintf (outfile
, "%02x", val
->v
.val_data8
[i
]);
5556 /* Likewise, for a DIE attribute. */
5559 print_attribute (dw_attr_ref a
, bool recurse
, FILE *outfile
)
5561 print_dw_val (&a
->dw_attr_val
, recurse
, outfile
);
5565 /* Print the list of operands in the LOC location description to OUTFILE. This
5566 routine is a debugging aid only. */
5569 print_loc_descr (dw_loc_descr_ref loc
, FILE *outfile
)
5571 dw_loc_descr_ref l
= loc
;
5575 print_spaces (outfile
);
5576 fprintf (outfile
, "<null>\n");
5580 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
5582 print_spaces (outfile
);
5583 fprintf (outfile
, "(%p) %s",
5585 dwarf_stack_op_name (l
->dw_loc_opc
));
5586 if (l
->dw_loc_oprnd1
.val_class
!= dw_val_class_none
)
5588 fprintf (outfile
, " ");
5589 print_dw_val (&l
->dw_loc_oprnd1
, false, outfile
);
5591 if (l
->dw_loc_oprnd2
.val_class
!= dw_val_class_none
)
5593 fprintf (outfile
, ", ");
5594 print_dw_val (&l
->dw_loc_oprnd2
, false, outfile
);
5596 fprintf (outfile
, "\n");
5600 /* Print the information associated with a given DIE, and its children.
5601 This routine is a debugging aid only. */
5604 print_die (dw_die_ref die
, FILE *outfile
)
5610 print_spaces (outfile
);
5611 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5612 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5614 print_spaces (outfile
);
5615 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5616 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5617 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5619 if (die
->comdat_type_p
)
5621 print_spaces (outfile
);
5622 fprintf (outfile
, " signature: ");
5623 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5624 fprintf (outfile
, "\n");
5627 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5629 print_spaces (outfile
);
5630 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5632 print_attribute (a
, true, outfile
);
5633 fprintf (outfile
, "\n");
5636 if (die
->die_child
!= NULL
)
5639 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5642 if (print_indent
== 0)
5643 fprintf (outfile
, "\n");
5646 /* Print the list of operations in the LOC location description. */
5649 debug_dwarf_loc_descr (dw_loc_descr_ref loc
)
5651 print_loc_descr (loc
, stderr
);
5654 /* Print the information collected for a given DIE. */
5657 debug_dwarf_die (dw_die_ref die
)
5659 print_die (die
, stderr
);
5663 debug (die_struct
&ref
)
5665 print_die (&ref
, stderr
);
5669 debug (die_struct
*ptr
)
5674 fprintf (stderr
, "<nil>\n");
5678 /* Print all DWARF information collected for the compilation unit.
5679 This routine is a debugging aid only. */
5685 print_die (comp_unit_die (), stderr
);
5688 #ifdef ENABLE_CHECKING
5689 /* Sanity checks on DIEs. */
5692 check_die (dw_die_ref die
)
5696 bool inline_found
= false;
5697 int n_location
= 0, n_low_pc
= 0, n_high_pc
= 0, n_artificial
= 0;
5698 int n_decl_line
= 0, n_decl_file
= 0;
5699 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5704 if (a
->dw_attr_val
.v
.val_unsigned
)
5705 inline_found
= true;
5707 case DW_AT_location
:
5716 case DW_AT_artificial
:
5719 case DW_AT_decl_line
:
5722 case DW_AT_decl_file
:
5729 if (n_location
> 1 || n_low_pc
> 1 || n_high_pc
> 1 || n_artificial
> 1
5730 || n_decl_line
> 1 || n_decl_file
> 1)
5732 fprintf (stderr
, "Duplicate attributes in DIE:\n");
5733 debug_dwarf_die (die
);
5738 /* A debugging information entry that is a member of an abstract
5739 instance tree [that has DW_AT_inline] should not contain any
5740 attributes which describe aspects of the subroutine which vary
5741 between distinct inlined expansions or distinct out-of-line
5743 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5744 gcc_assert (a
->dw_attr
!= DW_AT_low_pc
5745 && a
->dw_attr
!= DW_AT_high_pc
5746 && a
->dw_attr
!= DW_AT_location
5747 && a
->dw_attr
!= DW_AT_frame_base
5748 && a
->dw_attr
!= DW_AT_GNU_all_call_sites
);
5753 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5754 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5755 DIE that marks the start of the DIEs for this include file. */
5758 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5760 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5761 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5763 new_unit
->die_sib
= old_unit
;
5767 /* Close an include-file CU and reopen the enclosing one. */
5770 pop_compile_unit (dw_die_ref old_unit
)
5772 dw_die_ref new_unit
= old_unit
->die_sib
;
5774 old_unit
->die_sib
= NULL
;
5778 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5779 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5780 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5782 /* Calculate the checksum of a location expression. */
5785 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5788 inchash::hash hstate
;
5791 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5793 hash_loc_operands (loc
, hstate
);
5794 hash
= hstate
.end();
5798 /* Calculate the checksum of an attribute. */
5801 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5803 dw_loc_descr_ref loc
;
5806 CHECKSUM (at
->dw_attr
);
5808 /* We don't care that this was compiled with a different compiler
5809 snapshot; if the output is the same, that's what matters. */
5810 if (at
->dw_attr
== DW_AT_producer
)
5813 switch (AT_class (at
))
5815 case dw_val_class_const
:
5816 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5818 case dw_val_class_unsigned_const
:
5819 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5821 case dw_val_class_const_double
:
5822 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5824 case dw_val_class_wide_int
:
5825 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
5826 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
5827 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
5829 case dw_val_class_vec
:
5830 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5831 (at
->dw_attr_val
.v
.val_vec
.length
5832 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5834 case dw_val_class_flag
:
5835 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5837 case dw_val_class_str
:
5838 CHECKSUM_STRING (AT_string (at
));
5841 case dw_val_class_addr
:
5843 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5844 CHECKSUM_STRING (XSTR (r
, 0));
5847 case dw_val_class_offset
:
5848 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5851 case dw_val_class_loc
:
5852 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5853 loc_checksum (loc
, ctx
);
5856 case dw_val_class_die_ref
:
5857 die_checksum (AT_ref (at
), ctx
, mark
);
5860 case dw_val_class_fde_ref
:
5861 case dw_val_class_vms_delta
:
5862 case dw_val_class_lbl_id
:
5863 case dw_val_class_lineptr
:
5864 case dw_val_class_macptr
:
5865 case dw_val_class_high_pc
:
5868 case dw_val_class_file
:
5869 CHECKSUM_STRING (AT_file (at
)->filename
);
5872 case dw_val_class_data8
:
5873 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5881 /* Calculate the checksum of a DIE. */
5884 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5890 /* To avoid infinite recursion. */
5893 CHECKSUM (die
->die_mark
);
5896 die
->die_mark
= ++(*mark
);
5898 CHECKSUM (die
->die_tag
);
5900 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5901 attr_checksum (a
, ctx
, mark
);
5903 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5907 #undef CHECKSUM_BLOCK
5908 #undef CHECKSUM_STRING
5910 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5911 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5912 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5913 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5914 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5915 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5916 #define CHECKSUM_ATTR(FOO) \
5917 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5919 /* Calculate the checksum of a number in signed LEB128 format. */
5922 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5929 byte
= (value
& 0x7f);
5931 more
= !((value
== 0 && (byte
& 0x40) == 0)
5932 || (value
== -1 && (byte
& 0x40) != 0));
5941 /* Calculate the checksum of a number in unsigned LEB128 format. */
5944 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5948 unsigned char byte
= (value
& 0x7f);
5951 /* More bytes to follow. */
5959 /* Checksum the context of the DIE. This adds the names of any
5960 surrounding namespaces or structures to the checksum. */
5963 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5967 int tag
= die
->die_tag
;
5969 if (tag
!= DW_TAG_namespace
5970 && tag
!= DW_TAG_structure_type
5971 && tag
!= DW_TAG_class_type
)
5974 name
= get_AT_string (die
, DW_AT_name
);
5976 spec
= get_AT_ref (die
, DW_AT_specification
);
5980 if (die
->die_parent
!= NULL
)
5981 checksum_die_context (die
->die_parent
, ctx
);
5983 CHECKSUM_ULEB128 ('C');
5984 CHECKSUM_ULEB128 (tag
);
5986 CHECKSUM_STRING (name
);
5989 /* Calculate the checksum of a location expression. */
5992 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5994 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5995 were emitted as a DW_FORM_sdata instead of a location expression. */
5996 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5998 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5999 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
6003 /* Otherwise, just checksum the raw location expression. */
6006 inchash::hash hstate
;
6009 CHECKSUM_ULEB128 (loc
->dtprel
);
6010 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
6011 hash_loc_operands (loc
, hstate
);
6012 hash
= hstate
.end ();
6014 loc
= loc
->dw_loc_next
;
6018 /* Calculate the checksum of an attribute. */
6021 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
6022 struct md5_ctx
*ctx
, int *mark
)
6024 dw_loc_descr_ref loc
;
6027 if (AT_class (at
) == dw_val_class_die_ref
)
6029 dw_die_ref target_die
= AT_ref (at
);
6031 /* For pointer and reference types, we checksum only the (qualified)
6032 name of the target type (if there is a name). For friend entries,
6033 we checksum only the (qualified) name of the target type or function.
6034 This allows the checksum to remain the same whether the target type
6035 is complete or not. */
6036 if ((at
->dw_attr
== DW_AT_type
6037 && (tag
== DW_TAG_pointer_type
6038 || tag
== DW_TAG_reference_type
6039 || tag
== DW_TAG_rvalue_reference_type
6040 || tag
== DW_TAG_ptr_to_member_type
))
6041 || (at
->dw_attr
== DW_AT_friend
6042 && tag
== DW_TAG_friend
))
6044 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
6046 if (name_attr
!= NULL
)
6048 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6052 CHECKSUM_ULEB128 ('N');
6053 CHECKSUM_ULEB128 (at
->dw_attr
);
6054 if (decl
->die_parent
!= NULL
)
6055 checksum_die_context (decl
->die_parent
, ctx
);
6056 CHECKSUM_ULEB128 ('E');
6057 CHECKSUM_STRING (AT_string (name_attr
));
6062 /* For all other references to another DIE, we check to see if the
6063 target DIE has already been visited. If it has, we emit a
6064 backward reference; if not, we descend recursively. */
6065 if (target_die
->die_mark
> 0)
6067 CHECKSUM_ULEB128 ('R');
6068 CHECKSUM_ULEB128 (at
->dw_attr
);
6069 CHECKSUM_ULEB128 (target_die
->die_mark
);
6073 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6077 target_die
->die_mark
= ++(*mark
);
6078 CHECKSUM_ULEB128 ('T');
6079 CHECKSUM_ULEB128 (at
->dw_attr
);
6080 if (decl
->die_parent
!= NULL
)
6081 checksum_die_context (decl
->die_parent
, ctx
);
6082 die_checksum_ordered (target_die
, ctx
, mark
);
6087 CHECKSUM_ULEB128 ('A');
6088 CHECKSUM_ULEB128 (at
->dw_attr
);
6090 switch (AT_class (at
))
6092 case dw_val_class_const
:
6093 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6094 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
6097 case dw_val_class_unsigned_const
:
6098 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6099 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
6102 case dw_val_class_const_double
:
6103 CHECKSUM_ULEB128 (DW_FORM_block
);
6104 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
6105 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6108 case dw_val_class_wide_int
:
6109 CHECKSUM_ULEB128 (DW_FORM_block
);
6110 CHECKSUM_ULEB128 (get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6111 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
6112 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6113 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6114 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6117 case dw_val_class_vec
:
6118 CHECKSUM_ULEB128 (DW_FORM_block
);
6119 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
6120 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
6121 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6122 (at
->dw_attr_val
.v
.val_vec
.length
6123 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6126 case dw_val_class_flag
:
6127 CHECKSUM_ULEB128 (DW_FORM_flag
);
6128 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
6131 case dw_val_class_str
:
6132 CHECKSUM_ULEB128 (DW_FORM_string
);
6133 CHECKSUM_STRING (AT_string (at
));
6136 case dw_val_class_addr
:
6138 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6139 CHECKSUM_ULEB128 (DW_FORM_string
);
6140 CHECKSUM_STRING (XSTR (r
, 0));
6143 case dw_val_class_offset
:
6144 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6145 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
6148 case dw_val_class_loc
:
6149 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6150 loc_checksum_ordered (loc
, ctx
);
6153 case dw_val_class_fde_ref
:
6154 case dw_val_class_lbl_id
:
6155 case dw_val_class_lineptr
:
6156 case dw_val_class_macptr
:
6157 case dw_val_class_high_pc
:
6160 case dw_val_class_file
:
6161 CHECKSUM_ULEB128 (DW_FORM_string
);
6162 CHECKSUM_STRING (AT_file (at
)->filename
);
6165 case dw_val_class_data8
:
6166 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6174 struct checksum_attributes
6176 dw_attr_ref at_name
;
6177 dw_attr_ref at_type
;
6178 dw_attr_ref at_friend
;
6179 dw_attr_ref at_accessibility
;
6180 dw_attr_ref at_address_class
;
6181 dw_attr_ref at_allocated
;
6182 dw_attr_ref at_artificial
;
6183 dw_attr_ref at_associated
;
6184 dw_attr_ref at_binary_scale
;
6185 dw_attr_ref at_bit_offset
;
6186 dw_attr_ref at_bit_size
;
6187 dw_attr_ref at_bit_stride
;
6188 dw_attr_ref at_byte_size
;
6189 dw_attr_ref at_byte_stride
;
6190 dw_attr_ref at_const_value
;
6191 dw_attr_ref at_containing_type
;
6192 dw_attr_ref at_count
;
6193 dw_attr_ref at_data_location
;
6194 dw_attr_ref at_data_member_location
;
6195 dw_attr_ref at_decimal_scale
;
6196 dw_attr_ref at_decimal_sign
;
6197 dw_attr_ref at_default_value
;
6198 dw_attr_ref at_digit_count
;
6199 dw_attr_ref at_discr
;
6200 dw_attr_ref at_discr_list
;
6201 dw_attr_ref at_discr_value
;
6202 dw_attr_ref at_encoding
;
6203 dw_attr_ref at_endianity
;
6204 dw_attr_ref at_explicit
;
6205 dw_attr_ref at_is_optional
;
6206 dw_attr_ref at_location
;
6207 dw_attr_ref at_lower_bound
;
6208 dw_attr_ref at_mutable
;
6209 dw_attr_ref at_ordering
;
6210 dw_attr_ref at_picture_string
;
6211 dw_attr_ref at_prototyped
;
6212 dw_attr_ref at_small
;
6213 dw_attr_ref at_segment
;
6214 dw_attr_ref at_string_length
;
6215 dw_attr_ref at_threads_scaled
;
6216 dw_attr_ref at_upper_bound
;
6217 dw_attr_ref at_use_location
;
6218 dw_attr_ref at_use_UTF8
;
6219 dw_attr_ref at_variable_parameter
;
6220 dw_attr_ref at_virtuality
;
6221 dw_attr_ref at_visibility
;
6222 dw_attr_ref at_vtable_elem_location
;
6225 /* Collect the attributes that we will want to use for the checksum. */
6228 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
6233 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6244 attrs
->at_friend
= a
;
6246 case DW_AT_accessibility
:
6247 attrs
->at_accessibility
= a
;
6249 case DW_AT_address_class
:
6250 attrs
->at_address_class
= a
;
6252 case DW_AT_allocated
:
6253 attrs
->at_allocated
= a
;
6255 case DW_AT_artificial
:
6256 attrs
->at_artificial
= a
;
6258 case DW_AT_associated
:
6259 attrs
->at_associated
= a
;
6261 case DW_AT_binary_scale
:
6262 attrs
->at_binary_scale
= a
;
6264 case DW_AT_bit_offset
:
6265 attrs
->at_bit_offset
= a
;
6267 case DW_AT_bit_size
:
6268 attrs
->at_bit_size
= a
;
6270 case DW_AT_bit_stride
:
6271 attrs
->at_bit_stride
= a
;
6273 case DW_AT_byte_size
:
6274 attrs
->at_byte_size
= a
;
6276 case DW_AT_byte_stride
:
6277 attrs
->at_byte_stride
= a
;
6279 case DW_AT_const_value
:
6280 attrs
->at_const_value
= a
;
6282 case DW_AT_containing_type
:
6283 attrs
->at_containing_type
= a
;
6286 attrs
->at_count
= a
;
6288 case DW_AT_data_location
:
6289 attrs
->at_data_location
= a
;
6291 case DW_AT_data_member_location
:
6292 attrs
->at_data_member_location
= a
;
6294 case DW_AT_decimal_scale
:
6295 attrs
->at_decimal_scale
= a
;
6297 case DW_AT_decimal_sign
:
6298 attrs
->at_decimal_sign
= a
;
6300 case DW_AT_default_value
:
6301 attrs
->at_default_value
= a
;
6303 case DW_AT_digit_count
:
6304 attrs
->at_digit_count
= a
;
6307 attrs
->at_discr
= a
;
6309 case DW_AT_discr_list
:
6310 attrs
->at_discr_list
= a
;
6312 case DW_AT_discr_value
:
6313 attrs
->at_discr_value
= a
;
6315 case DW_AT_encoding
:
6316 attrs
->at_encoding
= a
;
6318 case DW_AT_endianity
:
6319 attrs
->at_endianity
= a
;
6321 case DW_AT_explicit
:
6322 attrs
->at_explicit
= a
;
6324 case DW_AT_is_optional
:
6325 attrs
->at_is_optional
= a
;
6327 case DW_AT_location
:
6328 attrs
->at_location
= a
;
6330 case DW_AT_lower_bound
:
6331 attrs
->at_lower_bound
= a
;
6334 attrs
->at_mutable
= a
;
6336 case DW_AT_ordering
:
6337 attrs
->at_ordering
= a
;
6339 case DW_AT_picture_string
:
6340 attrs
->at_picture_string
= a
;
6342 case DW_AT_prototyped
:
6343 attrs
->at_prototyped
= a
;
6346 attrs
->at_small
= a
;
6349 attrs
->at_segment
= a
;
6351 case DW_AT_string_length
:
6352 attrs
->at_string_length
= a
;
6354 case DW_AT_threads_scaled
:
6355 attrs
->at_threads_scaled
= a
;
6357 case DW_AT_upper_bound
:
6358 attrs
->at_upper_bound
= a
;
6360 case DW_AT_use_location
:
6361 attrs
->at_use_location
= a
;
6363 case DW_AT_use_UTF8
:
6364 attrs
->at_use_UTF8
= a
;
6366 case DW_AT_variable_parameter
:
6367 attrs
->at_variable_parameter
= a
;
6369 case DW_AT_virtuality
:
6370 attrs
->at_virtuality
= a
;
6372 case DW_AT_visibility
:
6373 attrs
->at_visibility
= a
;
6375 case DW_AT_vtable_elem_location
:
6376 attrs
->at_vtable_elem_location
= a
;
6384 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6387 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6391 struct checksum_attributes attrs
;
6393 CHECKSUM_ULEB128 ('D');
6394 CHECKSUM_ULEB128 (die
->die_tag
);
6396 memset (&attrs
, 0, sizeof (attrs
));
6398 decl
= get_AT_ref (die
, DW_AT_specification
);
6400 collect_checksum_attributes (&attrs
, decl
);
6401 collect_checksum_attributes (&attrs
, die
);
6403 CHECKSUM_ATTR (attrs
.at_name
);
6404 CHECKSUM_ATTR (attrs
.at_accessibility
);
6405 CHECKSUM_ATTR (attrs
.at_address_class
);
6406 CHECKSUM_ATTR (attrs
.at_allocated
);
6407 CHECKSUM_ATTR (attrs
.at_artificial
);
6408 CHECKSUM_ATTR (attrs
.at_associated
);
6409 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6410 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6411 CHECKSUM_ATTR (attrs
.at_bit_size
);
6412 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6413 CHECKSUM_ATTR (attrs
.at_byte_size
);
6414 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6415 CHECKSUM_ATTR (attrs
.at_const_value
);
6416 CHECKSUM_ATTR (attrs
.at_containing_type
);
6417 CHECKSUM_ATTR (attrs
.at_count
);
6418 CHECKSUM_ATTR (attrs
.at_data_location
);
6419 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6420 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6421 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6422 CHECKSUM_ATTR (attrs
.at_default_value
);
6423 CHECKSUM_ATTR (attrs
.at_digit_count
);
6424 CHECKSUM_ATTR (attrs
.at_discr
);
6425 CHECKSUM_ATTR (attrs
.at_discr_list
);
6426 CHECKSUM_ATTR (attrs
.at_discr_value
);
6427 CHECKSUM_ATTR (attrs
.at_encoding
);
6428 CHECKSUM_ATTR (attrs
.at_endianity
);
6429 CHECKSUM_ATTR (attrs
.at_explicit
);
6430 CHECKSUM_ATTR (attrs
.at_is_optional
);
6431 CHECKSUM_ATTR (attrs
.at_location
);
6432 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6433 CHECKSUM_ATTR (attrs
.at_mutable
);
6434 CHECKSUM_ATTR (attrs
.at_ordering
);
6435 CHECKSUM_ATTR (attrs
.at_picture_string
);
6436 CHECKSUM_ATTR (attrs
.at_prototyped
);
6437 CHECKSUM_ATTR (attrs
.at_small
);
6438 CHECKSUM_ATTR (attrs
.at_segment
);
6439 CHECKSUM_ATTR (attrs
.at_string_length
);
6440 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6441 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6442 CHECKSUM_ATTR (attrs
.at_use_location
);
6443 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6444 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6445 CHECKSUM_ATTR (attrs
.at_virtuality
);
6446 CHECKSUM_ATTR (attrs
.at_visibility
);
6447 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6448 CHECKSUM_ATTR (attrs
.at_type
);
6449 CHECKSUM_ATTR (attrs
.at_friend
);
6451 /* Checksum the child DIEs. */
6454 dw_attr_ref name_attr
;
6457 name_attr
= get_AT (c
, DW_AT_name
);
6458 if (is_template_instantiation (c
))
6460 /* Ignore instantiations of member type and function templates. */
6462 else if (name_attr
!= NULL
6463 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6465 /* Use a shallow checksum for named nested types and member
6467 CHECKSUM_ULEB128 ('S');
6468 CHECKSUM_ULEB128 (c
->die_tag
);
6469 CHECKSUM_STRING (AT_string (name_attr
));
6473 /* Use a deep checksum for other children. */
6474 /* Mark this DIE so it gets processed when unmarking. */
6475 if (c
->die_mark
== 0)
6477 die_checksum_ordered (c
, ctx
, mark
);
6479 } while (c
!= die
->die_child
);
6481 CHECKSUM_ULEB128 (0);
6484 /* Add a type name and tag to a hash. */
6486 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6488 CHECKSUM_ULEB128 (tag
);
6489 CHECKSUM_STRING (name
);
6493 #undef CHECKSUM_STRING
6494 #undef CHECKSUM_ATTR
6495 #undef CHECKSUM_LEB128
6496 #undef CHECKSUM_ULEB128
6498 /* Generate the type signature for DIE. This is computed by generating an
6499 MD5 checksum over the DIE's tag, its relevant attributes, and its
6500 children. Attributes that are references to other DIEs are processed
6501 by recursion, using the MARK field to prevent infinite recursion.
6502 If the DIE is nested inside a namespace or another type, we also
6503 need to include that context in the signature. The lower 64 bits
6504 of the resulting MD5 checksum comprise the signature. */
6507 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6511 unsigned char checksum
[16];
6516 name
= get_AT_string (die
, DW_AT_name
);
6517 decl
= get_AT_ref (die
, DW_AT_specification
);
6518 parent
= get_die_parent (die
);
6520 /* First, compute a signature for just the type name (and its surrounding
6521 context, if any. This is stored in the type unit DIE for link-time
6522 ODR (one-definition rule) checking. */
6524 if (is_cxx () && name
!= NULL
)
6526 md5_init_ctx (&ctx
);
6528 /* Checksum the names of surrounding namespaces and structures. */
6530 checksum_die_context (parent
, &ctx
);
6532 /* Checksum the current DIE. */
6533 die_odr_checksum (die
->die_tag
, name
, &ctx
);
6534 md5_finish_ctx (&ctx
, checksum
);
6536 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6539 /* Next, compute the complete type signature. */
6541 md5_init_ctx (&ctx
);
6543 die
->die_mark
= mark
;
6545 /* Checksum the names of surrounding namespaces and structures. */
6547 checksum_die_context (parent
, &ctx
);
6549 /* Checksum the DIE and its children. */
6550 die_checksum_ordered (die
, &ctx
, &mark
);
6551 unmark_all_dies (die
);
6552 md5_finish_ctx (&ctx
, checksum
);
6554 /* Store the signature in the type node and link the type DIE and the
6555 type node together. */
6556 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6557 DWARF_TYPE_SIGNATURE_SIZE
);
6558 die
->comdat_type_p
= true;
6559 die
->die_id
.die_type_node
= type_node
;
6560 type_node
->type_die
= die
;
6562 /* If the DIE is a specification, link its declaration to the type node
6566 decl
->comdat_type_p
= true;
6567 decl
->die_id
.die_type_node
= type_node
;
6571 /* Do the location expressions look same? */
6573 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6575 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6576 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6577 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6580 /* Do the values look the same? */
6582 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6584 dw_loc_descr_ref loc1
, loc2
;
6587 if (v1
->val_class
!= v2
->val_class
)
6590 switch (v1
->val_class
)
6592 case dw_val_class_const
:
6593 return v1
->v
.val_int
== v2
->v
.val_int
;
6594 case dw_val_class_unsigned_const
:
6595 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6596 case dw_val_class_const_double
:
6597 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6598 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6599 case dw_val_class_wide_int
:
6600 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
6601 case dw_val_class_vec
:
6602 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6603 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6605 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6606 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6609 case dw_val_class_flag
:
6610 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6611 case dw_val_class_str
:
6612 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6614 case dw_val_class_addr
:
6615 r1
= v1
->v
.val_addr
;
6616 r2
= v2
->v
.val_addr
;
6617 if (GET_CODE (r1
) != GET_CODE (r2
))
6619 return !rtx_equal_p (r1
, r2
);
6621 case dw_val_class_offset
:
6622 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6624 case dw_val_class_loc
:
6625 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6627 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6628 if (!same_loc_p (loc1
, loc2
, mark
))
6630 return !loc1
&& !loc2
;
6632 case dw_val_class_die_ref
:
6633 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6635 case dw_val_class_fde_ref
:
6636 case dw_val_class_vms_delta
:
6637 case dw_val_class_lbl_id
:
6638 case dw_val_class_lineptr
:
6639 case dw_val_class_macptr
:
6640 case dw_val_class_high_pc
:
6643 case dw_val_class_file
:
6644 return v1
->v
.val_file
== v2
->v
.val_file
;
6646 case dw_val_class_data8
:
6647 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6654 /* Do the attributes look the same? */
6657 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6659 if (at1
->dw_attr
!= at2
->dw_attr
)
6662 /* We don't care that this was compiled with a different compiler
6663 snapshot; if the output is the same, that's what matters. */
6664 if (at1
->dw_attr
== DW_AT_producer
)
6667 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6670 /* Do the dies look the same? */
6673 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6679 /* To avoid infinite recursion. */
6681 return die1
->die_mark
== die2
->die_mark
;
6682 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6684 if (die1
->die_tag
!= die2
->die_tag
)
6687 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6690 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6691 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6694 c1
= die1
->die_child
;
6695 c2
= die2
->die_child
;
6704 if (!same_die_p (c1
, c2
, mark
))
6708 if (c1
== die1
->die_child
)
6710 if (c2
== die2
->die_child
)
6720 /* Do the dies look the same? Wrapper around same_die_p. */
6723 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6726 int ret
= same_die_p (die1
, die2
, &mark
);
6728 unmark_all_dies (die1
);
6729 unmark_all_dies (die2
);
6734 /* The prefix to attach to symbols on DIEs in the current comdat debug
6736 static const char *comdat_symbol_id
;
6738 /* The index of the current symbol within the current comdat CU. */
6739 static unsigned int comdat_symbol_number
;
6741 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6742 children, and set comdat_symbol_id accordingly. */
6745 compute_section_prefix (dw_die_ref unit_die
)
6747 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6748 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6749 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6752 unsigned char checksum
[16];
6755 /* Compute the checksum of the DIE, then append part of it as hex digits to
6756 the name filename of the unit. */
6758 md5_init_ctx (&ctx
);
6760 die_checksum (unit_die
, &ctx
, &mark
);
6761 unmark_all_dies (unit_die
);
6762 md5_finish_ctx (&ctx
, checksum
);
6764 sprintf (name
, "%s.", base
);
6765 clean_symbol_name (name
);
6767 p
= name
+ strlen (name
);
6768 for (i
= 0; i
< 4; i
++)
6770 sprintf (p
, "%.2x", checksum
[i
]);
6774 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6775 comdat_symbol_number
= 0;
6778 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6781 is_type_die (dw_die_ref die
)
6783 switch (die
->die_tag
)
6785 case DW_TAG_array_type
:
6786 case DW_TAG_class_type
:
6787 case DW_TAG_interface_type
:
6788 case DW_TAG_enumeration_type
:
6789 case DW_TAG_pointer_type
:
6790 case DW_TAG_reference_type
:
6791 case DW_TAG_rvalue_reference_type
:
6792 case DW_TAG_string_type
:
6793 case DW_TAG_structure_type
:
6794 case DW_TAG_subroutine_type
:
6795 case DW_TAG_union_type
:
6796 case DW_TAG_ptr_to_member_type
:
6797 case DW_TAG_set_type
:
6798 case DW_TAG_subrange_type
:
6799 case DW_TAG_base_type
:
6800 case DW_TAG_const_type
:
6801 case DW_TAG_file_type
:
6802 case DW_TAG_packed_type
:
6803 case DW_TAG_volatile_type
:
6804 case DW_TAG_typedef
:
6811 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6812 Basically, we want to choose the bits that are likely to be shared between
6813 compilations (types) and leave out the bits that are specific to individual
6814 compilations (functions). */
6817 is_comdat_die (dw_die_ref c
)
6819 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6820 we do for stabs. The advantage is a greater likelihood of sharing between
6821 objects that don't include headers in the same order (and therefore would
6822 put the base types in a different comdat). jason 8/28/00 */
6824 if (c
->die_tag
== DW_TAG_base_type
)
6827 if (c
->die_tag
== DW_TAG_pointer_type
6828 || c
->die_tag
== DW_TAG_reference_type
6829 || c
->die_tag
== DW_TAG_rvalue_reference_type
6830 || c
->die_tag
== DW_TAG_const_type
6831 || c
->die_tag
== DW_TAG_volatile_type
)
6833 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6835 return t
? is_comdat_die (t
) : 0;
6838 return is_type_die (c
);
6841 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6842 compilation unit. */
6845 is_symbol_die (dw_die_ref c
)
6847 return (is_type_die (c
)
6848 || is_declaration_die (c
)
6849 || c
->die_tag
== DW_TAG_namespace
6850 || c
->die_tag
== DW_TAG_module
);
6853 /* Returns true iff C is a compile-unit DIE. */
6856 is_cu_die (dw_die_ref c
)
6858 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6861 /* Returns true iff C is a unit DIE of some sort. */
6864 is_unit_die (dw_die_ref c
)
6866 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6867 || c
->die_tag
== DW_TAG_partial_unit
6868 || c
->die_tag
== DW_TAG_type_unit
);
6871 /* Returns true iff C is a namespace DIE. */
6874 is_namespace_die (dw_die_ref c
)
6876 return c
&& c
->die_tag
== DW_TAG_namespace
;
6879 /* Returns true iff C is a class or structure DIE. */
6882 is_class_die (dw_die_ref c
)
6884 return c
&& (c
->die_tag
== DW_TAG_class_type
6885 || c
->die_tag
== DW_TAG_structure_type
);
6888 /* Return non-zero if this DIE is a template parameter. */
6891 is_template_parameter (dw_die_ref die
)
6893 switch (die
->die_tag
)
6895 case DW_TAG_template_type_param
:
6896 case DW_TAG_template_value_param
:
6897 case DW_TAG_GNU_template_template_param
:
6898 case DW_TAG_GNU_template_parameter_pack
:
6905 /* Return non-zero if this DIE represents a template instantiation. */
6908 is_template_instantiation (dw_die_ref die
)
6912 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
6914 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
6919 gen_internal_sym (const char *prefix
)
6923 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6924 return xstrdup (buf
);
6927 /* Assign symbols to all worthy DIEs under DIE. */
6930 assign_symbol_names (dw_die_ref die
)
6934 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6936 if (comdat_symbol_id
)
6938 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6940 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6941 comdat_symbol_id
, comdat_symbol_number
++);
6942 die
->die_id
.die_symbol
= xstrdup (p
);
6945 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6948 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6951 struct cu_hash_table_entry
6954 unsigned min_comdat_num
, max_comdat_num
;
6955 struct cu_hash_table_entry
*next
;
6958 /* Helpers to manipulate hash table of CUs. */
6960 struct cu_hash_table_entry_hasher
6962 typedef cu_hash_table_entry
*value_type
;
6963 typedef die_struct
*compare_type
;
6964 static inline hashval_t
hash (const cu_hash_table_entry
*);
6965 static inline bool equal (const cu_hash_table_entry
*, const die_struct
*);
6966 static inline void remove (cu_hash_table_entry
*);
6970 cu_hash_table_entry_hasher::hash (const cu_hash_table_entry
*entry
)
6972 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6976 cu_hash_table_entry_hasher::equal (const cu_hash_table_entry
*entry1
,
6977 const die_struct
*entry2
)
6979 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6983 cu_hash_table_entry_hasher::remove (cu_hash_table_entry
*entry
)
6985 struct cu_hash_table_entry
*next
;
6995 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
6997 /* Check whether we have already seen this CU and set up SYM_NUM
7000 check_duplicate_cu (dw_die_ref cu
, cu_hash_type
*htable
, unsigned int *sym_num
)
7002 struct cu_hash_table_entry dummy
;
7003 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
7005 dummy
.max_comdat_num
= 0;
7007 slot
= htable
->find_slot_with_hash (cu
,
7008 htab_hash_string (cu
->die_id
.die_symbol
),
7012 for (; entry
; last
= entry
, entry
= entry
->next
)
7014 if (same_die_p_wrap (cu
, entry
->cu
))
7020 *sym_num
= entry
->min_comdat_num
;
7024 entry
= XCNEW (struct cu_hash_table_entry
);
7026 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
7027 entry
->next
= *slot
;
7033 /* Record SYM_NUM to record of CU in HTABLE. */
7035 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type
*htable
,
7036 unsigned int sym_num
)
7038 struct cu_hash_table_entry
**slot
, *entry
;
7040 slot
= htable
->find_slot_with_hash (cu
,
7041 htab_hash_string (cu
->die_id
.die_symbol
),
7045 entry
->max_comdat_num
= sym_num
;
7048 /* Traverse the DIE (which is always comp_unit_die), and set up
7049 additional compilation units for each of the include files we see
7050 bracketed by BINCL/EINCL. */
7053 break_out_includes (dw_die_ref die
)
7056 dw_die_ref unit
= NULL
;
7057 limbo_die_node
*node
, **pnode
;
7061 dw_die_ref prev
= c
;
7063 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
7064 || (unit
&& is_comdat_die (c
)))
7066 dw_die_ref next
= c
->die_sib
;
7068 /* This DIE is for a secondary CU; remove it from the main one. */
7069 remove_child_with_prev (c
, prev
);
7071 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
7072 unit
= push_new_compile_unit (unit
, c
);
7073 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
7074 unit
= pop_compile_unit (unit
);
7076 add_child_die (unit
, c
);
7078 if (c
== die
->die_child
)
7081 } while (c
!= die
->die_child
);
7084 /* We can only use this in debugging, since the frontend doesn't check
7085 to make sure that we leave every include file we enter. */
7089 assign_symbol_names (die
);
7090 cu_hash_type
cu_hash_table (10);
7091 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
7097 compute_section_prefix (node
->die
);
7098 is_dupl
= check_duplicate_cu (node
->die
, &cu_hash_table
,
7099 &comdat_symbol_number
);
7100 assign_symbol_names (node
->die
);
7102 *pnode
= node
->next
;
7105 pnode
= &node
->next
;
7106 record_comdat_symbol_number (node
->die
, &cu_hash_table
,
7107 comdat_symbol_number
);
7112 /* Return non-zero if this DIE is a declaration. */
7115 is_declaration_die (dw_die_ref die
)
7120 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7121 if (a
->dw_attr
== DW_AT_declaration
)
7127 /* Return non-zero if this DIE is nested inside a subprogram. */
7130 is_nested_in_subprogram (dw_die_ref die
)
7132 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
7136 return local_scope_p (decl
);
7139 /* Return non-zero if this DIE contains a defining declaration of a
7143 contains_subprogram_definition (dw_die_ref die
)
7147 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
7149 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
7153 /* Return non-zero if this is a type DIE that should be moved to a
7154 COMDAT .debug_types section. */
7157 should_move_die_to_comdat (dw_die_ref die
)
7159 switch (die
->die_tag
)
7161 case DW_TAG_class_type
:
7162 case DW_TAG_structure_type
:
7163 case DW_TAG_enumeration_type
:
7164 case DW_TAG_union_type
:
7165 /* Don't move declarations, inlined instances, types nested in a
7166 subprogram, or types that contain subprogram definitions. */
7167 if (is_declaration_die (die
)
7168 || get_AT (die
, DW_AT_abstract_origin
)
7169 || is_nested_in_subprogram (die
)
7170 || contains_subprogram_definition (die
))
7173 case DW_TAG_array_type
:
7174 case DW_TAG_interface_type
:
7175 case DW_TAG_pointer_type
:
7176 case DW_TAG_reference_type
:
7177 case DW_TAG_rvalue_reference_type
:
7178 case DW_TAG_string_type
:
7179 case DW_TAG_subroutine_type
:
7180 case DW_TAG_ptr_to_member_type
:
7181 case DW_TAG_set_type
:
7182 case DW_TAG_subrange_type
:
7183 case DW_TAG_base_type
:
7184 case DW_TAG_const_type
:
7185 case DW_TAG_file_type
:
7186 case DW_TAG_packed_type
:
7187 case DW_TAG_volatile_type
:
7188 case DW_TAG_typedef
:
7194 /* Make a clone of DIE. */
7197 clone_die (dw_die_ref die
)
7203 clone
= ggc_cleared_alloc
<die_node
> ();
7204 clone
->die_tag
= die
->die_tag
;
7206 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7207 add_dwarf_attr (clone
, a
);
7212 /* Make a clone of the tree rooted at DIE. */
7215 clone_tree (dw_die_ref die
)
7218 dw_die_ref clone
= clone_die (die
);
7220 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
7225 /* Make a clone of DIE as a declaration. */
7228 clone_as_declaration (dw_die_ref die
)
7235 /* If the DIE is already a declaration, just clone it. */
7236 if (is_declaration_die (die
))
7237 return clone_die (die
);
7239 /* If the DIE is a specification, just clone its declaration DIE. */
7240 decl
= get_AT_ref (die
, DW_AT_specification
);
7243 clone
= clone_die (decl
);
7244 if (die
->comdat_type_p
)
7245 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7249 clone
= ggc_cleared_alloc
<die_node
> ();
7250 clone
->die_tag
= die
->die_tag
;
7252 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7254 /* We don't want to copy over all attributes.
7255 For example we don't want DW_AT_byte_size because otherwise we will no
7256 longer have a declaration and GDB will treat it as a definition. */
7260 case DW_AT_abstract_origin
:
7261 case DW_AT_artificial
:
7262 case DW_AT_containing_type
:
7263 case DW_AT_external
:
7266 case DW_AT_virtuality
:
7267 case DW_AT_linkage_name
:
7268 case DW_AT_MIPS_linkage_name
:
7269 add_dwarf_attr (clone
, a
);
7271 case DW_AT_byte_size
:
7277 if (die
->comdat_type_p
)
7278 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7280 add_AT_flag (clone
, DW_AT_declaration
, 1);
7285 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7287 struct decl_table_entry
7293 /* Helpers to manipulate hash table of copied declarations. */
7295 /* Hashtable helpers. */
7297 struct decl_table_entry_hasher
: free_ptr_hash
<decl_table_entry
>
7299 typedef die_struct
*compare_type
;
7300 static inline hashval_t
hash (const decl_table_entry
*);
7301 static inline bool equal (const decl_table_entry
*, const die_struct
*);
7305 decl_table_entry_hasher::hash (const decl_table_entry
*entry
)
7307 return htab_hash_pointer (entry
->orig
);
7311 decl_table_entry_hasher::equal (const decl_table_entry
*entry1
,
7312 const die_struct
*entry2
)
7314 return entry1
->orig
== entry2
;
7317 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
7319 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7320 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7321 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7322 to check if the ancestor has already been copied into UNIT. */
7325 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
,
7326 decl_hash_type
*decl_table
)
7328 dw_die_ref parent
= die
->die_parent
;
7329 dw_die_ref new_parent
= unit
;
7331 decl_table_entry
**slot
= NULL
;
7332 struct decl_table_entry
*entry
= NULL
;
7336 /* Check if the entry has already been copied to UNIT. */
7337 slot
= decl_table
->find_slot_with_hash (die
, htab_hash_pointer (die
),
7339 if (*slot
!= HTAB_EMPTY_ENTRY
)
7345 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7346 entry
= XCNEW (struct decl_table_entry
);
7354 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7357 if (!is_unit_die (parent
))
7358 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7361 copy
= clone_as_declaration (die
);
7362 add_child_die (new_parent
, copy
);
7366 /* Record the pointer to the copy. */
7372 /* Copy the declaration context to the new type unit DIE. This includes
7373 any surrounding namespace or type declarations. If the DIE has an
7374 AT_specification attribute, it also includes attributes and children
7375 attached to the specification, and returns a pointer to the original
7376 parent of the declaration DIE. Returns NULL otherwise. */
7379 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7382 dw_die_ref new_decl
;
7383 dw_die_ref orig_parent
= NULL
;
7385 decl
= get_AT_ref (die
, DW_AT_specification
);
7394 /* The original DIE will be changed to a declaration, and must
7395 be moved to be a child of the original declaration DIE. */
7396 orig_parent
= decl
->die_parent
;
7398 /* Copy the type node pointer from the new DIE to the original
7399 declaration DIE so we can forward references later. */
7400 decl
->comdat_type_p
= true;
7401 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7403 remove_AT (die
, DW_AT_specification
);
7405 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7407 if (a
->dw_attr
!= DW_AT_name
7408 && a
->dw_attr
!= DW_AT_declaration
7409 && a
->dw_attr
!= DW_AT_external
)
7410 add_dwarf_attr (die
, a
);
7413 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7416 if (decl
->die_parent
!= NULL
7417 && !is_unit_die (decl
->die_parent
))
7419 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
7420 if (new_decl
!= NULL
)
7422 remove_AT (new_decl
, DW_AT_signature
);
7423 add_AT_specification (die
, new_decl
);
7430 /* Generate the skeleton ancestor tree for the given NODE, then clone
7431 the DIE and add the clone into the tree. */
7434 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7436 if (node
->new_die
!= NULL
)
7439 node
->new_die
= clone_as_declaration (node
->old_die
);
7441 if (node
->parent
!= NULL
)
7443 generate_skeleton_ancestor_tree (node
->parent
);
7444 add_child_die (node
->parent
->new_die
, node
->new_die
);
7448 /* Generate a skeleton tree of DIEs containing any declarations that are
7449 found in the original tree. We traverse the tree looking for declaration
7450 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7453 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7455 skeleton_chain_node node
;
7458 dw_die_ref prev
= NULL
;
7459 dw_die_ref next
= NULL
;
7461 node
.parent
= parent
;
7463 first
= c
= parent
->old_die
->die_child
;
7467 if (prev
== NULL
|| prev
->die_sib
== c
)
7470 next
= (c
== first
? NULL
: c
->die_sib
);
7472 node
.new_die
= NULL
;
7473 if (is_declaration_die (c
))
7475 if (is_template_instantiation (c
))
7477 /* Instantiated templates do not need to be cloned into the
7478 type unit. Just move the DIE and its children back to
7479 the skeleton tree (in the main CU). */
7480 remove_child_with_prev (c
, prev
);
7481 add_child_die (parent
->new_die
, c
);
7486 /* Clone the existing DIE, move the original to the skeleton
7487 tree (which is in the main CU), and put the clone, with
7488 all the original's children, where the original came from
7489 (which is about to be moved to the type unit). */
7490 dw_die_ref clone
= clone_die (c
);
7491 move_all_children (c
, clone
);
7493 /* If the original has a DW_AT_object_pointer attribute,
7494 it would now point to a child DIE just moved to the
7495 cloned tree, so we need to remove that attribute from
7497 remove_AT (c
, DW_AT_object_pointer
);
7499 replace_child (c
, clone
, prev
);
7500 generate_skeleton_ancestor_tree (parent
);
7501 add_child_die (parent
->new_die
, c
);
7506 generate_skeleton_bottom_up (&node
);
7507 } while (next
!= NULL
);
7510 /* Wrapper function for generate_skeleton_bottom_up. */
7513 generate_skeleton (dw_die_ref die
)
7515 skeleton_chain_node node
;
7518 node
.new_die
= NULL
;
7521 /* If this type definition is nested inside another type,
7522 and is not an instantiation of a template, always leave
7523 at least a declaration in its place. */
7524 if (die
->die_parent
!= NULL
7525 && is_type_die (die
->die_parent
)
7526 && !is_template_instantiation (die
))
7527 node
.new_die
= clone_as_declaration (die
);
7529 generate_skeleton_bottom_up (&node
);
7530 return node
.new_die
;
7533 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7534 declaration. The original DIE is moved to a new compile unit so that
7535 existing references to it follow it to the new location. If any of the
7536 original DIE's descendants is a declaration, we need to replace the
7537 original DIE with a skeleton tree and move the declarations back into the
7541 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7544 dw_die_ref skeleton
, orig_parent
;
7546 /* Copy the declaration context to the type unit DIE. If the returned
7547 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7549 orig_parent
= copy_declaration_context (unit
, child
);
7551 skeleton
= generate_skeleton (child
);
7552 if (skeleton
== NULL
)
7553 remove_child_with_prev (child
, prev
);
7556 skeleton
->comdat_type_p
= true;
7557 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7559 /* If the original DIE was a specification, we need to put
7560 the skeleton under the parent DIE of the declaration.
7561 This leaves the original declaration in the tree, but
7562 it will be pruned later since there are no longer any
7563 references to it. */
7564 if (orig_parent
!= NULL
)
7566 remove_child_with_prev (child
, prev
);
7567 add_child_die (orig_parent
, skeleton
);
7570 replace_child (child
, skeleton
, prev
);
7576 /* Traverse the DIE and set up additional .debug_types sections for each
7577 type worthy of being placed in a COMDAT section. */
7580 break_out_comdat_types (dw_die_ref die
)
7584 dw_die_ref prev
= NULL
;
7585 dw_die_ref next
= NULL
;
7586 dw_die_ref unit
= NULL
;
7588 first
= c
= die
->die_child
;
7592 if (prev
== NULL
|| prev
->die_sib
== c
)
7595 next
= (c
== first
? NULL
: c
->die_sib
);
7596 if (should_move_die_to_comdat (c
))
7598 dw_die_ref replacement
;
7599 comdat_type_node_ref type_node
;
7601 /* Break out nested types into their own type units. */
7602 break_out_comdat_types (c
);
7604 /* Create a new type unit DIE as the root for the new tree, and
7605 add it to the list of comdat types. */
7606 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7607 add_AT_unsigned (unit
, DW_AT_language
,
7608 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7609 type_node
= ggc_cleared_alloc
<comdat_type_node
> ();
7610 type_node
->root_die
= unit
;
7611 type_node
->next
= comdat_type_list
;
7612 comdat_type_list
= type_node
;
7614 /* Generate the type signature. */
7615 generate_type_signature (c
, type_node
);
7617 /* Copy the declaration context, attributes, and children of the
7618 declaration into the new type unit DIE, then remove this DIE
7619 from the main CU (or replace it with a skeleton if necessary). */
7620 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7621 type_node
->skeleton_die
= replacement
;
7623 /* Add the DIE to the new compunit. */
7624 add_child_die (unit
, c
);
7626 if (replacement
!= NULL
)
7629 else if (c
->die_tag
== DW_TAG_namespace
7630 || c
->die_tag
== DW_TAG_class_type
7631 || c
->die_tag
== DW_TAG_structure_type
7632 || c
->die_tag
== DW_TAG_union_type
)
7634 /* Look for nested types that can be broken out. */
7635 break_out_comdat_types (c
);
7637 } while (next
!= NULL
);
7640 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
7641 Enter all the cloned children into the hash table decl_table. */
7644 clone_tree_partial (dw_die_ref die
, decl_hash_type
*decl_table
)
7648 struct decl_table_entry
*entry
;
7649 decl_table_entry
**slot
;
7651 if (die
->die_tag
== DW_TAG_subprogram
)
7652 clone
= clone_as_declaration (die
);
7654 clone
= clone_die (die
);
7656 slot
= decl_table
->find_slot_with_hash (die
,
7657 htab_hash_pointer (die
), INSERT
);
7659 /* Assert that DIE isn't in the hash table yet. If it would be there
7660 before, the ancestors would be necessarily there as well, therefore
7661 clone_tree_partial wouldn't be called. */
7662 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7664 entry
= XCNEW (struct decl_table_entry
);
7666 entry
->copy
= clone
;
7669 if (die
->die_tag
!= DW_TAG_subprogram
)
7670 FOR_EACH_CHILD (die
, c
,
7671 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
7676 /* Walk the DIE and its children, looking for references to incomplete
7677 or trivial types that are unmarked (i.e., that are not in the current
7681 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type
*decl_table
)
7687 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7689 if (AT_class (a
) == dw_val_class_die_ref
)
7691 dw_die_ref targ
= AT_ref (a
);
7692 decl_table_entry
**slot
;
7693 struct decl_table_entry
*entry
;
7695 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7698 slot
= decl_table
->find_slot_with_hash (targ
,
7699 htab_hash_pointer (targ
),
7702 if (*slot
!= HTAB_EMPTY_ENTRY
)
7704 /* TARG has already been copied, so we just need to
7705 modify the reference to point to the copy. */
7707 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7711 dw_die_ref parent
= unit
;
7712 dw_die_ref copy
= clone_die (targ
);
7714 /* Record in DECL_TABLE that TARG has been copied.
7715 Need to do this now, before the recursive call,
7716 because DECL_TABLE may be expanded and SLOT
7717 would no longer be a valid pointer. */
7718 entry
= XCNEW (struct decl_table_entry
);
7723 /* If TARG is not a declaration DIE, we need to copy its
7725 if (!is_declaration_die (targ
))
7729 add_child_die (copy
,
7730 clone_tree_partial (c
, decl_table
)));
7733 /* Make sure the cloned tree is marked as part of the
7737 /* If TARG has surrounding context, copy its ancestor tree
7738 into the new type unit. */
7739 if (targ
->die_parent
!= NULL
7740 && !is_unit_die (targ
->die_parent
))
7741 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7744 add_child_die (parent
, copy
);
7745 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7747 /* Make sure the newly-copied DIE is walked. If it was
7748 installed in a previously-added context, it won't
7749 get visited otherwise. */
7752 /* Find the highest point of the newly-added tree,
7753 mark each node along the way, and walk from there. */
7754 parent
->die_mark
= 1;
7755 while (parent
->die_parent
7756 && parent
->die_parent
->die_mark
== 0)
7758 parent
= parent
->die_parent
;
7759 parent
->die_mark
= 1;
7761 copy_decls_walk (unit
, parent
, decl_table
);
7767 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7770 /* Copy declarations for "unworthy" types into the new comdat section.
7771 Incomplete types, modified types, and certain other types aren't broken
7772 out into comdat sections of their own, so they don't have a signature,
7773 and we need to copy the declaration into the same section so that we
7774 don't have an external reference. */
7777 copy_decls_for_unworthy_types (dw_die_ref unit
)
7780 decl_hash_type
decl_table (10);
7781 copy_decls_walk (unit
, unit
, &decl_table
);
7785 /* Traverse the DIE and add a sibling attribute if it may have the
7786 effect of speeding up access to siblings. To save some space,
7787 avoid generating sibling attributes for DIE's without children. */
7790 add_sibling_attributes (dw_die_ref die
)
7794 if (! die
->die_child
)
7797 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7798 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7800 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7803 /* Output all location lists for the DIE and its children. */
7806 output_location_lists (dw_die_ref die
)
7812 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7813 if (AT_class (a
) == dw_val_class_loc_list
)
7814 output_loc_list (AT_loc_list (a
));
7816 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7819 /* We want to limit the number of external references, because they are
7820 larger than local references: a relocation takes multiple words, and
7821 even a sig8 reference is always eight bytes, whereas a local reference
7822 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7823 So if we encounter multiple external references to the same type DIE, we
7824 make a local typedef stub for it and redirect all references there.
7826 This is the element of the hash table for keeping track of these
7836 /* Hashtable helpers. */
7838 struct external_ref_hasher
: free_ptr_hash
<external_ref
>
7840 static inline hashval_t
hash (const external_ref
*);
7841 static inline bool equal (const external_ref
*, const external_ref
*);
7845 external_ref_hasher::hash (const external_ref
*r
)
7847 dw_die_ref die
= r
->type
;
7850 /* We can't use the address of the DIE for hashing, because
7851 that will make the order of the stub DIEs non-deterministic. */
7852 if (! die
->comdat_type_p
)
7853 /* We have a symbol; use it to compute a hash. */
7854 h
= htab_hash_string (die
->die_id
.die_symbol
);
7857 /* We have a type signature; use a subset of the bits as the hash.
7858 The 8-byte signature is at least as large as hashval_t. */
7859 comdat_type_node_ref type_node
= die
->die_id
.die_type_node
;
7860 memcpy (&h
, type_node
->signature
, sizeof (h
));
7866 external_ref_hasher::equal (const external_ref
*r1
, const external_ref
*r2
)
7868 return r1
->type
== r2
->type
;
7871 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
7873 /* Return a pointer to the external_ref for references to DIE. */
7875 static struct external_ref
*
7876 lookup_external_ref (external_ref_hash_type
*map
, dw_die_ref die
)
7878 struct external_ref ref
, *ref_p
;
7879 external_ref
**slot
;
7882 slot
= map
->find_slot (&ref
, INSERT
);
7883 if (*slot
!= HTAB_EMPTY_ENTRY
)
7886 ref_p
= XCNEW (struct external_ref
);
7892 /* Subroutine of optimize_external_refs, below.
7894 If we see a type skeleton, record it as our stub. If we see external
7895 references, remember how many we've seen. */
7898 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type
*map
)
7903 struct external_ref
*ref_p
;
7905 if (is_type_die (die
)
7906 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7908 /* This is a local skeleton; use it for local references. */
7909 ref_p
= lookup_external_ref (map
, c
);
7913 /* Scan the DIE references, and remember any that refer to DIEs from
7914 other CUs (i.e. those which are not marked). */
7915 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7916 if (AT_class (a
) == dw_val_class_die_ref
7917 && (c
= AT_ref (a
))->die_mark
== 0
7920 ref_p
= lookup_external_ref (map
, c
);
7924 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7927 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7928 points to an external_ref, DATA is the CU we're processing. If we don't
7929 already have a local stub, and we have multiple refs, build a stub. */
7932 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
7934 struct external_ref
*ref_p
= *slot
;
7936 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7938 /* We have multiple references to this type, so build a small stub.
7939 Both of these forms are a bit dodgy from the perspective of the
7940 DWARF standard, since technically they should have names. */
7941 dw_die_ref cu
= data
;
7942 dw_die_ref type
= ref_p
->type
;
7943 dw_die_ref stub
= NULL
;
7945 if (type
->comdat_type_p
)
7947 /* If we refer to this type via sig8, use AT_signature. */
7948 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7949 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7953 /* Otherwise, use a typedef with no name. */
7954 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7955 add_AT_die_ref (stub
, DW_AT_type
, type
);
7964 /* DIE is a unit; look through all the DIE references to see if there are
7965 any external references to types, and if so, create local stubs for
7966 them which will be applied in build_abbrev_table. This is useful because
7967 references to local DIEs are smaller. */
7969 static external_ref_hash_type
*
7970 optimize_external_refs (dw_die_ref die
)
7972 external_ref_hash_type
*map
= new external_ref_hash_type (10);
7973 optimize_external_refs_1 (die
, map
);
7974 map
->traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
7978 /* The format of each DIE (and its attribute value pairs) is encoded in an
7979 abbreviation table. This routine builds the abbreviation table and assigns
7980 a unique abbreviation id for each abbreviation entry. The children of each
7981 die are visited recursively. */
7984 build_abbrev_table (dw_die_ref die
, external_ref_hash_type
*extern_map
)
7986 unsigned long abbrev_id
;
7987 unsigned int n_alloc
;
7992 /* Scan the DIE references, and replace any that refer to
7993 DIEs from other CUs (i.e. those which are not marked) with
7994 the local stubs we built in optimize_external_refs. */
7995 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7996 if (AT_class (a
) == dw_val_class_die_ref
7997 && (c
= AT_ref (a
))->die_mark
== 0)
7999 struct external_ref
*ref_p
;
8000 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
8002 ref_p
= lookup_external_ref (extern_map
, c
);
8003 if (ref_p
->stub
&& ref_p
->stub
!= die
)
8004 change_AT_die_ref (a
, ref_p
->stub
);
8006 /* We aren't changing this reference, so mark it external. */
8007 set_AT_ref_external (a
, 1);
8010 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8012 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
8013 dw_attr_ref die_a
, abbrev_a
;
8017 if (abbrev
->die_tag
!= die
->die_tag
)
8019 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
8022 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
8025 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
8027 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
8028 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
8029 || (value_format (abbrev_a
) != value_format (die_a
)))
8039 if (abbrev_id
>= abbrev_die_table_in_use
)
8041 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
8043 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
8044 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
8047 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
8048 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
8049 abbrev_die_table_allocated
= n_alloc
;
8052 ++abbrev_die_table_in_use
;
8053 abbrev_die_table
[abbrev_id
] = die
;
8056 die
->die_abbrev
= abbrev_id
;
8057 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
8060 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8063 constant_size (unsigned HOST_WIDE_INT value
)
8070 log
= floor_log2 (value
);
8073 log
= 1 << (floor_log2 (log
) + 1);
8078 /* Return the size of a DIE as it is represented in the
8079 .debug_info section. */
8081 static unsigned long
8082 size_of_die (dw_die_ref die
)
8084 unsigned long size
= 0;
8087 enum dwarf_form form
;
8089 size
+= size_of_uleb128 (die
->die_abbrev
);
8090 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8092 switch (AT_class (a
))
8094 case dw_val_class_addr
:
8095 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8097 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8098 size
+= size_of_uleb128 (AT_index (a
));
8101 size
+= DWARF2_ADDR_SIZE
;
8103 case dw_val_class_offset
:
8104 size
+= DWARF_OFFSET_SIZE
;
8106 case dw_val_class_loc
:
8108 unsigned long lsize
= size_of_locs (AT_loc (a
));
8111 if (dwarf_version
>= 4)
8112 size
+= size_of_uleb128 (lsize
);
8114 size
+= constant_size (lsize
);
8118 case dw_val_class_loc_list
:
8119 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8121 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8122 size
+= size_of_uleb128 (AT_index (a
));
8125 size
+= DWARF_OFFSET_SIZE
;
8127 case dw_val_class_range_list
:
8128 size
+= DWARF_OFFSET_SIZE
;
8130 case dw_val_class_const
:
8131 size
+= size_of_sleb128 (AT_int (a
));
8133 case dw_val_class_unsigned_const
:
8135 int csize
= constant_size (AT_unsigned (a
));
8136 if (dwarf_version
== 3
8137 && a
->dw_attr
== DW_AT_data_member_location
8139 size
+= size_of_uleb128 (AT_unsigned (a
));
8144 case dw_val_class_const_double
:
8145 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
8146 if (HOST_BITS_PER_WIDE_INT
>= 64)
8149 case dw_val_class_wide_int
:
8150 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
8151 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
8152 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
8156 case dw_val_class_vec
:
8157 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
8158 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
8159 + a
->dw_attr_val
.v
.val_vec
.length
8160 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
8162 case dw_val_class_flag
:
8163 if (dwarf_version
>= 4)
8164 /* Currently all add_AT_flag calls pass in 1 as last argument,
8165 so DW_FORM_flag_present can be used. If that ever changes,
8166 we'll need to use DW_FORM_flag and have some optimization
8167 in build_abbrev_table that will change those to
8168 DW_FORM_flag_present if it is set to 1 in all DIEs using
8169 the same abbrev entry. */
8170 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8174 case dw_val_class_die_ref
:
8175 if (AT_ref_external (a
))
8177 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
8178 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
8179 is sized by target address length, whereas in DWARF3
8180 it's always sized as an offset. */
8181 if (use_debug_types
)
8182 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
8183 else if (dwarf_version
== 2)
8184 size
+= DWARF2_ADDR_SIZE
;
8186 size
+= DWARF_OFFSET_SIZE
;
8189 size
+= DWARF_OFFSET_SIZE
;
8191 case dw_val_class_fde_ref
:
8192 size
+= DWARF_OFFSET_SIZE
;
8194 case dw_val_class_lbl_id
:
8195 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8197 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8198 size
+= size_of_uleb128 (AT_index (a
));
8201 size
+= DWARF2_ADDR_SIZE
;
8203 case dw_val_class_lineptr
:
8204 case dw_val_class_macptr
:
8205 size
+= DWARF_OFFSET_SIZE
;
8207 case dw_val_class_str
:
8208 form
= AT_string_form (a
);
8209 if (form
== DW_FORM_strp
)
8210 size
+= DWARF_OFFSET_SIZE
;
8211 else if (form
== DW_FORM_GNU_str_index
)
8212 size
+= size_of_uleb128 (AT_index (a
));
8214 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
8216 case dw_val_class_file
:
8217 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
8219 case dw_val_class_data8
:
8222 case dw_val_class_vms_delta
:
8223 size
+= DWARF_OFFSET_SIZE
;
8225 case dw_val_class_high_pc
:
8226 size
+= DWARF2_ADDR_SIZE
;
8236 /* Size the debugging information associated with a given DIE. Visits the
8237 DIE's children recursively. Updates the global variable next_die_offset, on
8238 each time through. Uses the current value of next_die_offset to update the
8239 die_offset field in each DIE. */
8242 calc_die_sizes (dw_die_ref die
)
8246 gcc_assert (die
->die_offset
== 0
8247 || (unsigned long int) die
->die_offset
== next_die_offset
);
8248 die
->die_offset
= next_die_offset
;
8249 next_die_offset
+= size_of_die (die
);
8251 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
8253 if (die
->die_child
!= NULL
)
8254 /* Count the null byte used to terminate sibling lists. */
8255 next_die_offset
+= 1;
8258 /* Size just the base type children at the start of the CU.
8259 This is needed because build_abbrev needs to size locs
8260 and sizing of type based stack ops needs to know die_offset
8261 values for the base types. */
8264 calc_base_type_die_sizes (void)
8266 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8268 dw_die_ref base_type
;
8269 #if ENABLE_ASSERT_CHECKING
8270 dw_die_ref prev
= comp_unit_die ()->die_child
;
8273 die_offset
+= size_of_die (comp_unit_die ());
8274 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
8276 #if ENABLE_ASSERT_CHECKING
8277 gcc_assert (base_type
->die_offset
== 0
8278 && prev
->die_sib
== base_type
8279 && base_type
->die_child
== NULL
8280 && base_type
->die_abbrev
);
8283 base_type
->die_offset
= die_offset
;
8284 die_offset
+= size_of_die (base_type
);
8288 /* Set the marks for a die and its children. We do this so
8289 that we know whether or not a reference needs to use FORM_ref_addr; only
8290 DIEs in the same CU will be marked. We used to clear out the offset
8291 and use that as the flag, but ran into ordering problems. */
8294 mark_dies (dw_die_ref die
)
8298 gcc_assert (!die
->die_mark
);
8301 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
8304 /* Clear the marks for a die and its children. */
8307 unmark_dies (dw_die_ref die
)
8311 if (! use_debug_types
)
8312 gcc_assert (die
->die_mark
);
8315 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
8318 /* Clear the marks for a die, its children and referred dies. */
8321 unmark_all_dies (dw_die_ref die
)
8331 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
8333 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8334 if (AT_class (a
) == dw_val_class_die_ref
)
8335 unmark_all_dies (AT_ref (a
));
8338 /* Calculate if the entry should appear in the final output file. It may be
8339 from a pruned a type. */
8342 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
8344 /* By limiting gnu pubnames to definitions only, gold can generate a
8345 gdb index without entries for declarations, which don't include
8346 enough information to be useful. */
8347 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
8350 if (table
== pubname_table
)
8352 /* Enumerator names are part of the pubname table, but the
8353 parent DW_TAG_enumeration_type die may have been pruned.
8354 Don't output them if that is the case. */
8355 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
8356 (p
->die
->die_parent
== NULL
8357 || !p
->die
->die_parent
->die_perennial_p
))
8360 /* Everything else in the pubname table is included. */
8364 /* The pubtypes table shouldn't include types that have been
8366 return (p
->die
->die_offset
!= 0
8367 || !flag_eliminate_unused_debug_types
);
8370 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8371 generated for the compilation unit. */
8373 static unsigned long
8374 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8379 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
8381 size
= DWARF_PUBNAMES_HEADER_SIZE
;
8382 FOR_EACH_VEC_ELT (*names
, i
, p
)
8383 if (include_pubname_in_output (names
, p
))
8384 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
8386 size
+= DWARF_OFFSET_SIZE
;
8390 /* Return the size of the information in the .debug_aranges section. */
8392 static unsigned long
8393 size_of_aranges (void)
8397 size
= DWARF_ARANGES_HEADER_SIZE
;
8399 /* Count the address/length pair for this compilation unit. */
8400 if (text_section_used
)
8401 size
+= 2 * DWARF2_ADDR_SIZE
;
8402 if (cold_text_section_used
)
8403 size
+= 2 * DWARF2_ADDR_SIZE
;
8404 if (have_multiple_function_sections
)
8409 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
8411 if (DECL_IGNORED_P (fde
->decl
))
8413 if (!fde
->in_std_section
)
8414 size
+= 2 * DWARF2_ADDR_SIZE
;
8415 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8416 size
+= 2 * DWARF2_ADDR_SIZE
;
8420 /* Count the two zero words used to terminated the address range table. */
8421 size
+= 2 * DWARF2_ADDR_SIZE
;
8425 /* Select the encoding of an attribute value. */
8427 static enum dwarf_form
8428 value_format (dw_attr_ref a
)
8430 switch (AT_class (a
))
8432 case dw_val_class_addr
:
8433 /* Only very few attributes allow DW_FORM_addr. */
8438 case DW_AT_entry_pc
:
8439 case DW_AT_trampoline
:
8440 return (AT_index (a
) == NOT_INDEXED
8441 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8445 switch (DWARF2_ADDR_SIZE
)
8448 return DW_FORM_data1
;
8450 return DW_FORM_data2
;
8452 return DW_FORM_data4
;
8454 return DW_FORM_data8
;
8458 case dw_val_class_range_list
:
8459 case dw_val_class_loc_list
:
8460 if (dwarf_version
>= 4)
8461 return DW_FORM_sec_offset
;
8463 case dw_val_class_vms_delta
:
8464 case dw_val_class_offset
:
8465 switch (DWARF_OFFSET_SIZE
)
8468 return DW_FORM_data4
;
8470 return DW_FORM_data8
;
8474 case dw_val_class_loc
:
8475 if (dwarf_version
>= 4)
8476 return DW_FORM_exprloc
;
8477 switch (constant_size (size_of_locs (AT_loc (a
))))
8480 return DW_FORM_block1
;
8482 return DW_FORM_block2
;
8484 return DW_FORM_block4
;
8488 case dw_val_class_const
:
8489 return DW_FORM_sdata
;
8490 case dw_val_class_unsigned_const
:
8491 switch (constant_size (AT_unsigned (a
)))
8494 return DW_FORM_data1
;
8496 return DW_FORM_data2
;
8498 /* In DWARF3 DW_AT_data_member_location with
8499 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8500 constant, so we need to use DW_FORM_udata if we need
8501 a large constant. */
8502 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8503 return DW_FORM_udata
;
8504 return DW_FORM_data4
;
8506 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8507 return DW_FORM_udata
;
8508 return DW_FORM_data8
;
8512 case dw_val_class_const_double
:
8513 switch (HOST_BITS_PER_WIDE_INT
)
8516 return DW_FORM_data2
;
8518 return DW_FORM_data4
;
8520 return DW_FORM_data8
;
8523 return DW_FORM_block1
;
8525 case dw_val_class_wide_int
:
8526 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
8529 return DW_FORM_data1
;
8531 return DW_FORM_data2
;
8533 return DW_FORM_data4
;
8535 return DW_FORM_data8
;
8537 return DW_FORM_block1
;
8539 case dw_val_class_vec
:
8540 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8541 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8544 return DW_FORM_block1
;
8546 return DW_FORM_block2
;
8548 return DW_FORM_block4
;
8552 case dw_val_class_flag
:
8553 if (dwarf_version
>= 4)
8555 /* Currently all add_AT_flag calls pass in 1 as last argument,
8556 so DW_FORM_flag_present can be used. If that ever changes,
8557 we'll need to use DW_FORM_flag and have some optimization
8558 in build_abbrev_table that will change those to
8559 DW_FORM_flag_present if it is set to 1 in all DIEs using
8560 the same abbrev entry. */
8561 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8562 return DW_FORM_flag_present
;
8564 return DW_FORM_flag
;
8565 case dw_val_class_die_ref
:
8566 if (AT_ref_external (a
))
8567 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8570 case dw_val_class_fde_ref
:
8571 return DW_FORM_data
;
8572 case dw_val_class_lbl_id
:
8573 return (AT_index (a
) == NOT_INDEXED
8574 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8575 case dw_val_class_lineptr
:
8576 case dw_val_class_macptr
:
8577 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8578 case dw_val_class_str
:
8579 return AT_string_form (a
);
8580 case dw_val_class_file
:
8581 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8584 return DW_FORM_data1
;
8586 return DW_FORM_data2
;
8588 return DW_FORM_data4
;
8593 case dw_val_class_data8
:
8594 return DW_FORM_data8
;
8596 case dw_val_class_high_pc
:
8597 switch (DWARF2_ADDR_SIZE
)
8600 return DW_FORM_data1
;
8602 return DW_FORM_data2
;
8604 return DW_FORM_data4
;
8606 return DW_FORM_data8
;
8616 /* Output the encoding of an attribute value. */
8619 output_value_format (dw_attr_ref a
)
8621 enum dwarf_form form
= value_format (a
);
8623 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8626 /* Given a die and id, produce the appropriate abbreviations. */
8629 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8634 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8635 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8636 dwarf_tag_name (abbrev
->die_tag
));
8638 if (abbrev
->die_child
!= NULL
)
8639 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8641 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8643 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8645 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8646 dwarf_attr_name (a_attr
->dw_attr
));
8647 output_value_format (a_attr
);
8650 dw2_asm_output_data (1, 0, NULL
);
8651 dw2_asm_output_data (1, 0, NULL
);
8655 /* Output the .debug_abbrev section which defines the DIE abbreviation
8659 output_abbrev_section (void)
8661 unsigned long abbrev_id
;
8663 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8664 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8666 /* Terminate the table. */
8667 dw2_asm_output_data (1, 0, NULL
);
8670 /* Output a symbol we can use to refer to this DIE from another CU. */
8673 output_die_symbol (dw_die_ref die
)
8675 const char *sym
= die
->die_id
.die_symbol
;
8677 gcc_assert (!die
->comdat_type_p
);
8682 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8683 /* We make these global, not weak; if the target doesn't support
8684 .linkonce, it doesn't support combining the sections, so debugging
8686 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8688 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8691 /* Return a new location list, given the begin and end range, and the
8694 static inline dw_loc_list_ref
8695 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8696 const char *section
)
8698 dw_loc_list_ref retlist
= ggc_cleared_alloc
<dw_loc_list_node
> ();
8700 retlist
->begin
= begin
;
8701 retlist
->begin_entry
= NULL
;
8703 retlist
->expr
= expr
;
8704 retlist
->section
= section
;
8709 /* Generate a new internal symbol for this location list node, if it
8710 hasn't got one yet. */
8713 gen_llsym (dw_loc_list_ref list
)
8715 gcc_assert (!list
->ll_symbol
);
8716 list
->ll_symbol
= gen_internal_sym ("LLST");
8719 /* Output the location list given to us. */
8722 output_loc_list (dw_loc_list_ref list_head
)
8724 dw_loc_list_ref curr
= list_head
;
8726 if (list_head
->emitted
)
8728 list_head
->emitted
= true;
8730 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8732 /* Walk the location list, and output each range + expression. */
8733 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8736 /* Don't output an entry that starts and ends at the same address. */
8737 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8739 size
= size_of_locs (curr
->expr
);
8740 /* If the expression is too large, drop it on the floor. We could
8741 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8742 in the expression, but >= 64KB expressions for a single value
8743 in a single range are unlikely very useful. */
8746 if (dwarf_split_debug_info
)
8748 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8749 "Location list start/length entry (%s)",
8750 list_head
->ll_symbol
);
8751 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8752 "Location list range start index (%s)",
8754 /* The length field is 4 bytes. If we ever need to support
8755 an 8-byte length, we can add a new DW_LLE code or fall back
8756 to DW_LLE_GNU_start_end_entry. */
8757 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8758 "Location list range length (%s)",
8759 list_head
->ll_symbol
);
8761 else if (!have_multiple_function_sections
)
8763 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8764 "Location list begin address (%s)",
8765 list_head
->ll_symbol
);
8766 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8767 "Location list end address (%s)",
8768 list_head
->ll_symbol
);
8772 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8773 "Location list begin address (%s)",
8774 list_head
->ll_symbol
);
8775 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8776 "Location list end address (%s)",
8777 list_head
->ll_symbol
);
8780 /* Output the block length for this list of location operations. */
8781 gcc_assert (size
<= 0xffff);
8782 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8784 output_loc_sequence (curr
->expr
, -1);
8787 if (dwarf_split_debug_info
)
8788 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8789 "Location list terminator (%s)",
8790 list_head
->ll_symbol
);
8793 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8794 "Location list terminator begin (%s)",
8795 list_head
->ll_symbol
);
8796 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8797 "Location list terminator end (%s)",
8798 list_head
->ll_symbol
);
8802 /* Output a range_list offset into the debug_range section. Emit a
8803 relocated reference if val_entry is NULL, otherwise, emit an
8804 indirect reference. */
8807 output_range_list_offset (dw_attr_ref a
)
8809 const char *name
= dwarf_attr_name (a
->dw_attr
);
8811 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8813 char *p
= strchr (ranges_section_label
, '\0');
8814 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8815 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8816 debug_ranges_section
, "%s", name
);
8820 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8821 "%s (offset from %s)", name
, ranges_section_label
);
8824 /* Output the offset into the debug_loc section. */
8827 output_loc_list_offset (dw_attr_ref a
)
8829 char *sym
= AT_loc_list (a
)->ll_symbol
;
8832 if (dwarf_split_debug_info
)
8833 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8834 "%s", dwarf_attr_name (a
->dw_attr
));
8836 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8837 "%s", dwarf_attr_name (a
->dw_attr
));
8840 /* Output an attribute's index or value appropriately. */
8843 output_attr_index_or_value (dw_attr_ref a
)
8845 const char *name
= dwarf_attr_name (a
->dw_attr
);
8847 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8849 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8852 switch (AT_class (a
))
8854 case dw_val_class_addr
:
8855 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8857 case dw_val_class_high_pc
:
8858 case dw_val_class_lbl_id
:
8859 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8861 case dw_val_class_loc_list
:
8862 output_loc_list_offset (a
);
8869 /* Output a type signature. */
8872 output_signature (const char *sig
, const char *name
)
8876 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8877 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8880 /* Output the DIE and its attributes. Called recursively to generate
8881 the definitions of each child DIE. */
8884 output_die (dw_die_ref die
)
8891 /* If someone in another CU might refer to us, set up a symbol for
8892 them to point to. */
8893 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8894 output_die_symbol (die
);
8896 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8897 (unsigned long)die
->die_offset
,
8898 dwarf_tag_name (die
->die_tag
));
8900 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8902 const char *name
= dwarf_attr_name (a
->dw_attr
);
8904 switch (AT_class (a
))
8906 case dw_val_class_addr
:
8907 output_attr_index_or_value (a
);
8910 case dw_val_class_offset
:
8911 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8915 case dw_val_class_range_list
:
8916 output_range_list_offset (a
);
8919 case dw_val_class_loc
:
8920 size
= size_of_locs (AT_loc (a
));
8922 /* Output the block length for this list of location operations. */
8923 if (dwarf_version
>= 4)
8924 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8926 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8928 output_loc_sequence (AT_loc (a
), -1);
8931 case dw_val_class_const
:
8932 /* ??? It would be slightly more efficient to use a scheme like is
8933 used for unsigned constants below, but gdb 4.x does not sign
8934 extend. Gdb 5.x does sign extend. */
8935 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8938 case dw_val_class_unsigned_const
:
8940 int csize
= constant_size (AT_unsigned (a
));
8941 if (dwarf_version
== 3
8942 && a
->dw_attr
== DW_AT_data_member_location
8944 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8946 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8950 case dw_val_class_const_double
:
8952 unsigned HOST_WIDE_INT first
, second
;
8954 if (HOST_BITS_PER_WIDE_INT
>= 64)
8955 dw2_asm_output_data (1,
8956 HOST_BITS_PER_DOUBLE_INT
8957 / HOST_BITS_PER_CHAR
,
8960 if (WORDS_BIG_ENDIAN
)
8962 first
= a
->dw_attr_val
.v
.val_double
.high
;
8963 second
= a
->dw_attr_val
.v
.val_double
.low
;
8967 first
= a
->dw_attr_val
.v
.val_double
.low
;
8968 second
= a
->dw_attr_val
.v
.val_double
.high
;
8971 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8973 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8978 case dw_val_class_wide_int
:
8981 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
8982 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
8983 if (len
* HOST_BITS_PER_WIDE_INT
> 64)
8984 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
) * l
,
8987 if (WORDS_BIG_ENDIAN
)
8988 for (i
= len
- 1; i
>= 0; --i
)
8990 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
8995 for (i
= 0; i
< len
; ++i
)
8997 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
9004 case dw_val_class_vec
:
9006 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
9007 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
9011 dw2_asm_output_data (constant_size (len
* elt_size
),
9012 len
* elt_size
, "%s", name
);
9013 if (elt_size
> sizeof (HOST_WIDE_INT
))
9018 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
9021 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
9022 "fp or vector constant word %u", i
);
9026 case dw_val_class_flag
:
9027 if (dwarf_version
>= 4)
9029 /* Currently all add_AT_flag calls pass in 1 as last argument,
9030 so DW_FORM_flag_present can be used. If that ever changes,
9031 we'll need to use DW_FORM_flag and have some optimization
9032 in build_abbrev_table that will change those to
9033 DW_FORM_flag_present if it is set to 1 in all DIEs using
9034 the same abbrev entry. */
9035 gcc_assert (AT_flag (a
) == 1);
9037 fprintf (asm_out_file
, "\t\t\t%s %s\n",
9038 ASM_COMMENT_START
, name
);
9041 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
9044 case dw_val_class_loc_list
:
9045 output_attr_index_or_value (a
);
9048 case dw_val_class_die_ref
:
9049 if (AT_ref_external (a
))
9051 if (AT_ref (a
)->comdat_type_p
)
9053 comdat_type_node_ref type_node
=
9054 AT_ref (a
)->die_id
.die_type_node
;
9056 gcc_assert (type_node
);
9057 output_signature (type_node
->signature
, name
);
9061 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
9065 /* In DWARF2, DW_FORM_ref_addr is sized by target address
9066 length, whereas in DWARF3 it's always sized as an
9068 if (dwarf_version
== 2)
9069 size
= DWARF2_ADDR_SIZE
;
9071 size
= DWARF_OFFSET_SIZE
;
9072 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
9078 gcc_assert (AT_ref (a
)->die_offset
);
9079 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
9084 case dw_val_class_fde_ref
:
9088 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
9089 a
->dw_attr_val
.v
.val_fde_index
* 2);
9090 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
9095 case dw_val_class_vms_delta
:
9096 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
9097 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
9098 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
9101 dw2_asm_output_delta (DWARF_OFFSET_SIZE
,
9102 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
9107 case dw_val_class_lbl_id
:
9108 output_attr_index_or_value (a
);
9111 case dw_val_class_lineptr
:
9112 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
9113 debug_line_section
, "%s", name
);
9116 case dw_val_class_macptr
:
9117 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
9118 debug_macinfo_section
, "%s", name
);
9121 case dw_val_class_str
:
9122 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
9123 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
9124 a
->dw_attr_val
.v
.val_str
->label
,
9126 "%s: \"%s\"", name
, AT_string (a
));
9127 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
9128 dw2_asm_output_data_uleb128 (AT_index (a
),
9129 "%s: \"%s\"", name
, AT_string (a
));
9131 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
9134 case dw_val_class_file
:
9136 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
9138 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
9139 a
->dw_attr_val
.v
.val_file
->filename
);
9143 case dw_val_class_data8
:
9147 for (i
= 0; i
< 8; i
++)
9148 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
9149 i
== 0 ? "%s" : NULL
, name
);
9153 case dw_val_class_high_pc
:
9154 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
9155 get_AT_low_pc (die
), "DW_AT_high_pc");
9163 FOR_EACH_CHILD (die
, c
, output_die (c
));
9165 /* Add null byte to terminate sibling list. */
9166 if (die
->die_child
!= NULL
)
9167 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
9168 (unsigned long) die
->die_offset
);
9171 /* Output the compilation unit that appears at the beginning of the
9172 .debug_info section, and precedes the DIE descriptions. */
9175 output_compilation_unit_header (void)
9177 /* We don't support actual DWARFv5 units yet, we just use some
9178 DWARFv5 draft DIE tags in DWARFv4 format. */
9179 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
9181 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9182 dw2_asm_output_data (4, 0xffffffff,
9183 "Initial length escape value indicating 64-bit DWARF extension");
9184 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9185 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
9186 "Length of Compilation Unit Info");
9187 dw2_asm_output_data (2, ver
, "DWARF version number");
9188 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
9189 debug_abbrev_section
,
9190 "Offset Into Abbrev. Section");
9191 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9194 /* Output the compilation unit DIE and its children. */
9197 output_comp_unit (dw_die_ref die
, int output_if_empty
)
9199 const char *secname
, *oldsym
;
9202 /* Unless we are outputting main CU, we may throw away empty ones. */
9203 if (!output_if_empty
&& die
->die_child
== NULL
)
9206 /* Even if there are no children of this DIE, we must output the information
9207 about the compilation unit. Otherwise, on an empty translation unit, we
9208 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
9209 will then complain when examining the file. First mark all the DIEs in
9210 this CU so we know which get local refs. */
9213 external_ref_hash_type
*extern_map
= optimize_external_refs (die
);
9215 build_abbrev_table (die
, extern_map
);
9219 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9220 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
9221 calc_die_sizes (die
);
9223 oldsym
= die
->die_id
.die_symbol
;
9226 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
9228 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
9230 die
->die_id
.die_symbol
= NULL
;
9231 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9235 switch_to_section (debug_info_section
);
9236 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
9237 info_section_emitted
= true;
9240 /* Output debugging information. */
9241 output_compilation_unit_header ();
9244 /* Leave the marks on the main CU, so we can check them in
9249 die
->die_id
.die_symbol
= oldsym
;
9253 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
9254 and .debug_pubtypes. This is configured per-target, but can be
9255 overridden by the -gpubnames or -gno-pubnames options. */
9258 want_pubnames (void)
9260 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9262 if (debug_generate_pub_sections
!= -1)
9263 return debug_generate_pub_sections
;
9264 return targetm
.want_debug_pub_sections
;
9267 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
9270 add_AT_pubnames (dw_die_ref die
)
9272 if (want_pubnames ())
9273 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
9276 /* Add a string attribute value to a skeleton DIE. */
9279 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
9283 struct indirect_string_node
*node
;
9285 if (! skeleton_debug_str_hash
)
9286 skeleton_debug_str_hash
9287 = hash_table
<indirect_string_hasher
>::create_ggc (10);
9289 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
9290 find_string_form (node
);
9291 if (node
->form
== DW_FORM_GNU_str_index
)
9292 node
->form
= DW_FORM_strp
;
9294 attr
.dw_attr
= attr_kind
;
9295 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
9296 attr
.dw_attr_val
.val_entry
= NULL
;
9297 attr
.dw_attr_val
.v
.val_str
= node
;
9298 add_dwarf_attr (die
, &attr
);
9301 /* Helper function to generate top-level dies for skeleton debug_info and
9305 add_top_level_skeleton_die_attrs (dw_die_ref die
)
9307 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
9308 const char *comp_dir
= comp_dir_string ();
9310 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
9311 if (comp_dir
!= NULL
)
9312 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
9313 add_AT_pubnames (die
);
9314 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
9317 /* Output skeleton debug sections that point to the dwo file. */
9320 output_skeleton_debug_sections (dw_die_ref comp_unit
)
9322 /* We don't support actual DWARFv5 units yet, we just use some
9323 DWARFv5 draft DIE tags in DWARFv4 format. */
9324 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
9326 /* These attributes will be found in the full debug_info section. */
9327 remove_AT (comp_unit
, DW_AT_producer
);
9328 remove_AT (comp_unit
, DW_AT_language
);
9330 switch_to_section (debug_skeleton_info_section
);
9331 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
9333 /* Produce the skeleton compilation-unit header. This one differs enough from
9334 a normal CU header that it's better not to call output_compilation_unit
9336 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9337 dw2_asm_output_data (4, 0xffffffff,
9338 "Initial length escape value indicating 64-bit DWARF extension");
9340 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9341 DWARF_COMPILE_UNIT_HEADER_SIZE
9342 - DWARF_INITIAL_LENGTH_SIZE
9343 + size_of_die (comp_unit
),
9344 "Length of Compilation Unit Info");
9345 dw2_asm_output_data (2, ver
, "DWARF version number");
9346 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
9347 debug_abbrev_section
,
9348 "Offset Into Abbrev. Section");
9349 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9351 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
9352 output_die (comp_unit
);
9354 /* Build the skeleton debug_abbrev section. */
9355 switch_to_section (debug_skeleton_abbrev_section
);
9356 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
9358 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
9360 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
9363 /* Output a comdat type unit DIE and its children. */
9366 output_comdat_type_unit (comdat_type_node
*node
)
9368 const char *secname
;
9371 #if defined (OBJECT_FORMAT_ELF)
9375 /* First mark all the DIEs in this CU so we know which get local refs. */
9376 mark_dies (node
->root_die
);
9378 external_ref_hash_type
*extern_map
= optimize_external_refs (node
->root_die
);
9380 build_abbrev_table (node
->root_die
, extern_map
);
9385 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9386 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
9387 calc_die_sizes (node
->root_die
);
9389 #if defined (OBJECT_FORMAT_ELF)
9390 if (!dwarf_split_debug_info
)
9391 secname
= ".debug_types";
9393 secname
= ".debug_types.dwo";
9395 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9396 sprintf (tmp
, "wt.");
9397 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9398 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9399 comdat_key
= get_identifier (tmp
);
9400 targetm
.asm_out
.named_section (secname
,
9401 SECTION_DEBUG
| SECTION_LINKONCE
,
9404 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9405 sprintf (tmp
, ".gnu.linkonce.wt.");
9406 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9407 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9409 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9412 /* Output debugging information. */
9413 output_compilation_unit_header ();
9414 output_signature (node
->signature
, "Type Signature");
9415 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
9416 "Offset to Type DIE");
9417 output_die (node
->root_die
);
9419 unmark_dies (node
->root_die
);
9422 /* Return the DWARF2/3 pubname associated with a decl. */
9425 dwarf2_name (tree decl
, int scope
)
9427 if (DECL_NAMELESS (decl
))
9429 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
9432 /* Add a new entry to .debug_pubnames if appropriate. */
9435 add_pubname_string (const char *str
, dw_die_ref die
)
9440 e
.name
= xstrdup (str
);
9441 vec_safe_push (pubname_table
, e
);
9445 add_pubname (tree decl
, dw_die_ref die
)
9447 if (!want_pubnames ())
9450 /* Don't add items to the table when we expect that the consumer will have
9451 just read the enclosing die. For example, if the consumer is looking at a
9452 class_member, it will either be inside the class already, or will have just
9453 looked up the class to find the member. Either way, searching the class is
9454 faster than searching the index. */
9455 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
9456 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9458 const char *name
= dwarf2_name (decl
, 1);
9461 add_pubname_string (name
, die
);
9465 /* Add an enumerator to the pubnames section. */
9468 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
9472 gcc_assert (scope_name
);
9473 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
9475 vec_safe_push (pubname_table
, e
);
9478 /* Add a new entry to .debug_pubtypes if appropriate. */
9481 add_pubtype (tree decl
, dw_die_ref die
)
9485 if (!want_pubnames ())
9488 if ((TREE_PUBLIC (decl
)
9489 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9490 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9493 const char *scope_name
= "";
9494 const char *sep
= is_cxx () ? "::" : ".";
9497 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9498 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9500 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9501 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9502 scope_name
= concat (scope_name
, sep
, NULL
);
9508 name
= type_tag (decl
);
9510 name
= lang_hooks
.dwarf_name (decl
, 1);
9512 /* If we don't have a name for the type, there's no point in adding
9514 if (name
!= NULL
&& name
[0] != '\0')
9517 e
.name
= concat (scope_name
, name
, NULL
);
9518 vec_safe_push (pubtype_table
, e
);
9521 /* Although it might be more consistent to add the pubinfo for the
9522 enumerators as their dies are created, they should only be added if the
9523 enum type meets the criteria above. So rather than re-check the parent
9524 enum type whenever an enumerator die is created, just output them all
9525 here. This isn't protected by the name conditional because anonymous
9526 enums don't have names. */
9527 if (die
->die_tag
== DW_TAG_enumeration_type
)
9531 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9536 /* Output a single entry in the pubnames table. */
9539 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
9541 dw_die_ref die
= entry
->die
;
9542 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
9544 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9546 if (debug_generate_pub_sections
== 2)
9548 /* This logic follows gdb's method for determining the value of the flag
9550 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
9551 switch (die
->die_tag
)
9553 case DW_TAG_typedef
:
9554 case DW_TAG_base_type
:
9555 case DW_TAG_subrange_type
:
9556 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9557 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9559 case DW_TAG_enumerator
:
9560 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9561 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9562 if (!is_cxx () && !is_java ())
9563 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9565 case DW_TAG_subprogram
:
9566 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9567 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
9569 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9571 case DW_TAG_constant
:
9572 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9573 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9574 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9576 case DW_TAG_variable
:
9577 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9578 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9579 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9581 case DW_TAG_namespace
:
9582 case DW_TAG_imported_declaration
:
9583 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9585 case DW_TAG_class_type
:
9586 case DW_TAG_interface_type
:
9587 case DW_TAG_structure_type
:
9588 case DW_TAG_union_type
:
9589 case DW_TAG_enumeration_type
:
9590 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9591 if (!is_cxx () && !is_java ())
9592 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9595 /* An unusual tag. Leave the flag-byte empty. */
9598 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
9602 dw2_asm_output_nstring (entry
->name
, -1, "external name");
9606 /* Output the public names table used to speed up access to externally
9607 visible names; or the public types table used to find type definitions. */
9610 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9613 unsigned long pubnames_length
= size_of_pubnames (names
);
9616 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9617 dw2_asm_output_data (4, 0xffffffff,
9618 "Initial length escape value indicating 64-bit DWARF extension");
9619 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
, "Pub Info Length");
9621 /* Version number for pubnames/pubtypes is independent of dwarf version. */
9622 dw2_asm_output_data (2, 2, "DWARF Version");
9624 if (dwarf_split_debug_info
)
9625 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9626 debug_skeleton_info_section
,
9627 "Offset of Compilation Unit Info");
9629 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9631 "Offset of Compilation Unit Info");
9632 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9633 "Compilation Unit Length");
9635 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9637 if (include_pubname_in_output (names
, pub
))
9639 dw_offset die_offset
= pub
->die
->die_offset
;
9641 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9642 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9643 gcc_assert (pub
->die
->die_mark
);
9645 /* If we're putting types in their own .debug_types sections,
9646 the .debug_pubtypes table will still point to the compile
9647 unit (not the type unit), so we want to use the offset of
9648 the skeleton DIE (if there is one). */
9649 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9651 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9653 if (type_node
!= NULL
)
9654 die_offset
= (type_node
->skeleton_die
!= NULL
9655 ? type_node
->skeleton_die
->die_offset
9656 : comp_unit_die ()->die_offset
);
9659 output_pubname (die_offset
, pub
);
9663 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9666 /* Output public names and types tables if necessary. */
9669 output_pubtables (void)
9671 if (!want_pubnames () || !info_section_emitted
)
9674 switch_to_section (debug_pubnames_section
);
9675 output_pubnames (pubname_table
);
9676 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
9677 It shouldn't hurt to emit it always, since pure DWARF2 consumers
9678 simply won't look for the section. */
9679 switch_to_section (debug_pubtypes_section
);
9680 output_pubnames (pubtype_table
);
9684 /* Output the information that goes into the .debug_aranges table.
9685 Namely, define the beginning and ending address range of the
9686 text section generated for this compilation unit. */
9689 output_aranges (unsigned long aranges_length
)
9693 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9694 dw2_asm_output_data (4, 0xffffffff,
9695 "Initial length escape value indicating 64-bit DWARF extension");
9696 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9697 "Length of Address Ranges Info");
9698 /* Version number for aranges is still 2, even up to DWARF5. */
9699 dw2_asm_output_data (2, 2, "DWARF Version");
9700 if (dwarf_split_debug_info
)
9701 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9702 debug_skeleton_info_section
,
9703 "Offset of Compilation Unit Info");
9705 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9707 "Offset of Compilation Unit Info");
9708 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9709 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9711 /* We need to align to twice the pointer size here. */
9712 if (DWARF_ARANGES_PAD_SIZE
)
9714 /* Pad using a 2 byte words so that padding is correct for any
9716 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9717 2 * DWARF2_ADDR_SIZE
);
9718 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9719 dw2_asm_output_data (2, 0, NULL
);
9722 /* It is necessary not to output these entries if the sections were
9723 not used; if the sections were not used, the length will be 0 and
9724 the address may end up as 0 if the section is discarded by ld
9725 --gc-sections, leaving an invalid (0, 0) entry that can be
9726 confused with the terminator. */
9727 if (text_section_used
)
9729 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9730 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9731 text_section_label
, "Length");
9733 if (cold_text_section_used
)
9735 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9737 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9738 cold_text_section_label
, "Length");
9741 if (have_multiple_function_sections
)
9746 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9748 if (DECL_IGNORED_P (fde
->decl
))
9750 if (!fde
->in_std_section
)
9752 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9754 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9755 fde
->dw_fde_begin
, "Length");
9757 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9759 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9761 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9762 fde
->dw_fde_second_begin
, "Length");
9767 /* Output the terminator words. */
9768 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9769 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9772 /* Add a new entry to .debug_ranges. Return the offset at which it
9776 add_ranges_num (int num
)
9778 unsigned int in_use
= ranges_table_in_use
;
9780 if (in_use
== ranges_table_allocated
)
9782 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9783 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9784 ranges_table_allocated
);
9785 memset (ranges_table
+ ranges_table_in_use
, 0,
9786 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9789 ranges_table
[in_use
].num
= num
;
9790 ranges_table_in_use
= in_use
+ 1;
9792 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9795 /* Add a new entry to .debug_ranges corresponding to a block, or a
9796 range terminator if BLOCK is NULL. */
9799 add_ranges (const_tree block
)
9801 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9804 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9805 When using dwarf_split_debug_info, address attributes in dies destined
9806 for the final executable should be direct references--setting the
9807 parameter force_direct ensures this behavior. */
9810 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9811 bool *added
, bool force_direct
)
9813 unsigned int in_use
= ranges_by_label_in_use
;
9814 unsigned int offset
;
9816 if (in_use
== ranges_by_label_allocated
)
9818 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9819 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9821 ranges_by_label_allocated
);
9822 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9823 RANGES_TABLE_INCREMENT
9824 * sizeof (struct dw_ranges_by_label_struct
));
9827 ranges_by_label
[in_use
].begin
= begin
;
9828 ranges_by_label
[in_use
].end
= end
;
9829 ranges_by_label_in_use
= in_use
+ 1;
9831 offset
= add_ranges_num (-(int)in_use
- 1);
9834 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9840 output_ranges (void)
9843 static const char *const start_fmt
= "Offset %#x";
9844 const char *fmt
= start_fmt
;
9846 for (i
= 0; i
< ranges_table_in_use
; i
++)
9848 int block_num
= ranges_table
[i
].num
;
9852 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9853 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9855 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9856 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9858 /* If all code is in the text section, then the compilation
9859 unit base address defaults to DW_AT_low_pc, which is the
9860 base of the text section. */
9861 if (!have_multiple_function_sections
)
9863 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9865 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9866 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9867 text_section_label
, NULL
);
9870 /* Otherwise, the compilation unit base address is zero,
9871 which allows us to use absolute addresses, and not worry
9872 about whether the target supports cross-section
9876 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9877 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9878 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9884 /* Negative block_num stands for an index into ranges_by_label. */
9885 else if (block_num
< 0)
9887 int lab_idx
= - block_num
- 1;
9889 if (!have_multiple_function_sections
)
9893 /* If we ever use add_ranges_by_labels () for a single
9894 function section, all we have to do is to take out
9896 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9897 ranges_by_label
[lab_idx
].begin
,
9899 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9900 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9901 ranges_by_label
[lab_idx
].end
,
9902 text_section_label
, NULL
);
9907 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9908 ranges_by_label
[lab_idx
].begin
,
9909 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9910 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9911 ranges_by_label
[lab_idx
].end
,
9917 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9918 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9924 /* Data structure containing information about input files. */
9927 const char *path
; /* Complete file name. */
9928 const char *fname
; /* File name part. */
9929 int length
; /* Length of entire string. */
9930 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9931 int dir_idx
; /* Index in directory table. */
9934 /* Data structure containing information about directories with source
9938 const char *path
; /* Path including directory name. */
9939 int length
; /* Path length. */
9940 int prefix
; /* Index of directory entry which is a prefix. */
9941 int count
; /* Number of files in this directory. */
9942 int dir_idx
; /* Index of directory used as base. */
9945 /* Callback function for file_info comparison. We sort by looking at
9946 the directories in the path. */
9949 file_info_cmp (const void *p1
, const void *p2
)
9951 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9952 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9953 const unsigned char *cp1
;
9954 const unsigned char *cp2
;
9956 /* Take care of file names without directories. We need to make sure that
9957 we return consistent values to qsort since some will get confused if
9958 we return the same value when identical operands are passed in opposite
9959 orders. So if neither has a directory, return 0 and otherwise return
9960 1 or -1 depending on which one has the directory. */
9961 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9962 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9964 cp1
= (const unsigned char *) s1
->path
;
9965 cp2
= (const unsigned char *) s2
->path
;
9971 /* Reached the end of the first path? If so, handle like above. */
9972 if ((cp1
== (const unsigned char *) s1
->fname
)
9973 || (cp2
== (const unsigned char *) s2
->fname
))
9974 return ((cp2
== (const unsigned char *) s2
->fname
)
9975 - (cp1
== (const unsigned char *) s1
->fname
));
9977 /* Character of current path component the same? */
9978 else if (*cp1
!= *cp2
)
9983 struct file_name_acquire_data
9985 struct file_info
*files
;
9990 /* Traversal function for the hash table. */
9993 file_name_acquire (dwarf_file_data
**slot
, file_name_acquire_data
*fnad
)
9995 struct dwarf_file_data
*d
= *slot
;
9996 struct file_info
*fi
;
9999 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
10001 if (! d
->emitted_number
)
10004 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
10006 fi
= fnad
->files
+ fnad
->used_files
++;
10008 /* Skip all leading "./". */
10010 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
10013 /* Create a new array entry. */
10015 fi
->length
= strlen (f
);
10018 /* Search for the file name part. */
10019 f
= strrchr (f
, DIR_SEPARATOR
);
10020 #if defined (DIR_SEPARATOR_2)
10022 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
10026 if (f
== NULL
|| f
< g
)
10032 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
10036 /* Output the directory table and the file name table. We try to minimize
10037 the total amount of memory needed. A heuristic is used to avoid large
10038 slowdowns with many input files. */
10041 output_file_names (void)
10043 struct file_name_acquire_data fnad
;
10045 struct file_info
*files
;
10046 struct dir_info
*dirs
;
10054 if (!last_emitted_file
)
10056 dw2_asm_output_data (1, 0, "End directory table");
10057 dw2_asm_output_data (1, 0, "End file name table");
10061 numfiles
= last_emitted_file
->emitted_number
;
10063 /* Allocate the various arrays we need. */
10064 files
= XALLOCAVEC (struct file_info
, numfiles
);
10065 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
10067 fnad
.files
= files
;
10068 fnad
.used_files
= 0;
10069 fnad
.max_files
= numfiles
;
10070 file_table
->traverse
<file_name_acquire_data
*, file_name_acquire
> (&fnad
);
10071 gcc_assert (fnad
.used_files
== fnad
.max_files
);
10073 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
10075 /* Find all the different directories used. */
10076 dirs
[0].path
= files
[0].path
;
10077 dirs
[0].length
= files
[0].fname
- files
[0].path
;
10078 dirs
[0].prefix
= -1;
10080 dirs
[0].dir_idx
= 0;
10081 files
[0].dir_idx
= 0;
10084 for (i
= 1; i
< numfiles
; i
++)
10085 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
10086 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
10087 dirs
[ndirs
- 1].length
) == 0)
10089 /* Same directory as last entry. */
10090 files
[i
].dir_idx
= ndirs
- 1;
10091 ++dirs
[ndirs
- 1].count
;
10097 /* This is a new directory. */
10098 dirs
[ndirs
].path
= files
[i
].path
;
10099 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
10100 dirs
[ndirs
].count
= 1;
10101 dirs
[ndirs
].dir_idx
= ndirs
;
10102 files
[i
].dir_idx
= ndirs
;
10104 /* Search for a prefix. */
10105 dirs
[ndirs
].prefix
= -1;
10106 for (j
= 0; j
< ndirs
; j
++)
10107 if (dirs
[j
].length
< dirs
[ndirs
].length
10108 && dirs
[j
].length
> 1
10109 && (dirs
[ndirs
].prefix
== -1
10110 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
10111 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
10112 dirs
[ndirs
].prefix
= j
;
10117 /* Now to the actual work. We have to find a subset of the directories which
10118 allow expressing the file name using references to the directory table
10119 with the least amount of characters. We do not do an exhaustive search
10120 where we would have to check out every combination of every single
10121 possible prefix. Instead we use a heuristic which provides nearly optimal
10122 results in most cases and never is much off. */
10123 saved
= XALLOCAVEC (int, ndirs
);
10124 savehere
= XALLOCAVEC (int, ndirs
);
10126 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
10127 for (i
= 0; i
< ndirs
; i
++)
10132 /* We can always save some space for the current directory. But this
10133 does not mean it will be enough to justify adding the directory. */
10134 savehere
[i
] = dirs
[i
].length
;
10135 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
10137 for (j
= i
+ 1; j
< ndirs
; j
++)
10140 if (saved
[j
] < dirs
[i
].length
)
10142 /* Determine whether the dirs[i] path is a prefix of the
10146 k
= dirs
[j
].prefix
;
10147 while (k
!= -1 && k
!= (int) i
)
10148 k
= dirs
[k
].prefix
;
10152 /* Yes it is. We can possibly save some memory by
10153 writing the filenames in dirs[j] relative to
10155 savehere
[j
] = dirs
[i
].length
;
10156 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
10161 /* Check whether we can save enough to justify adding the dirs[i]
10163 if (total
> dirs
[i
].length
+ 1)
10165 /* It's worthwhile adding. */
10166 for (j
= i
; j
< ndirs
; j
++)
10167 if (savehere
[j
] > 0)
10169 /* Remember how much we saved for this directory so far. */
10170 saved
[j
] = savehere
[j
];
10172 /* Remember the prefix directory. */
10173 dirs
[j
].dir_idx
= i
;
10178 /* Emit the directory name table. */
10179 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
10180 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
10181 dw2_asm_output_nstring (dirs
[i
].path
,
10183 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
10184 "Directory Entry: %#x", i
+ idx_offset
);
10186 dw2_asm_output_data (1, 0, "End directory table");
10188 /* We have to emit them in the order of emitted_number since that's
10189 used in the debug info generation. To do this efficiently we
10190 generate a back-mapping of the indices first. */
10191 backmap
= XALLOCAVEC (int, numfiles
);
10192 for (i
= 0; i
< numfiles
; i
++)
10193 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
10195 /* Now write all the file names. */
10196 for (i
= 0; i
< numfiles
; i
++)
10198 int file_idx
= backmap
[i
];
10199 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
10201 #ifdef VMS_DEBUGGING_INFO
10202 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
10204 /* Setting these fields can lead to debugger miscomparisons,
10205 but VMS Debug requires them to be set correctly. */
10210 int maxfilelen
= strlen (files
[file_idx
].path
)
10211 + dirs
[dir_idx
].length
10212 + MAX_VMS_VERSION_LEN
+ 1;
10213 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
10215 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
10216 snprintf (filebuf
, maxfilelen
, "%s;%d",
10217 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
10219 dw2_asm_output_nstring
10220 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
10222 /* Include directory index. */
10223 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10225 /* Modification time. */
10226 dw2_asm_output_data_uleb128
10227 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
10231 /* File length in bytes. */
10232 dw2_asm_output_data_uleb128
10233 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
10237 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
10238 "File Entry: %#x", (unsigned) i
+ 1);
10240 /* Include directory index. */
10241 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10243 /* Modification time. */
10244 dw2_asm_output_data_uleb128 (0, NULL
);
10246 /* File length in bytes. */
10247 dw2_asm_output_data_uleb128 (0, NULL
);
10248 #endif /* VMS_DEBUGGING_INFO */
10251 dw2_asm_output_data (1, 0, "End file name table");
10255 /* Output one line number table into the .debug_line section. */
10258 output_one_line_info_table (dw_line_info_table
*table
)
10260 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10261 unsigned int current_line
= 1;
10262 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
10263 dw_line_info_entry
*ent
;
10266 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
10268 switch (ent
->opcode
)
10270 case LI_set_address
:
10271 /* ??? Unfortunately, we have little choice here currently, and
10272 must always use the most general form. GCC does not know the
10273 address delta itself, so we can't use DW_LNS_advance_pc. Many
10274 ports do have length attributes which will give an upper bound
10275 on the address range. We could perhaps use length attributes
10276 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
10277 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
10279 /* This can handle any delta. This takes
10280 4+DWARF2_ADDR_SIZE bytes. */
10281 dw2_asm_output_data (1, 0, "set address %s", line_label
);
10282 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10283 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10284 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
10288 if (ent
->val
== current_line
)
10290 /* We still need to start a new row, so output a copy insn. */
10291 dw2_asm_output_data (1, DW_LNS_copy
,
10292 "copy line %u", current_line
);
10296 int line_offset
= ent
->val
- current_line
;
10297 int line_delta
= line_offset
- DWARF_LINE_BASE
;
10299 current_line
= ent
->val
;
10300 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
10302 /* This can handle deltas from -10 to 234, using the current
10303 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
10304 This takes 1 byte. */
10305 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
10306 "line %u", current_line
);
10310 /* This can handle any delta. This takes at least 4 bytes,
10311 depending on the value being encoded. */
10312 dw2_asm_output_data (1, DW_LNS_advance_line
,
10313 "advance to line %u", current_line
);
10314 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
10315 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
10321 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
10322 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10325 case LI_set_column
:
10326 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
10327 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10330 case LI_negate_stmt
:
10331 current_is_stmt
= !current_is_stmt
;
10332 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
10333 "is_stmt %d", current_is_stmt
);
10336 case LI_set_prologue_end
:
10337 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
10338 "set prologue end");
10341 case LI_set_epilogue_begin
:
10342 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
10343 "set epilogue begin");
10346 case LI_set_discriminator
:
10347 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
10348 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
10349 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
10350 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
10355 /* Emit debug info for the address of the end of the table. */
10356 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
10357 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10358 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10359 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
10361 dw2_asm_output_data (1, 0, "end sequence");
10362 dw2_asm_output_data_uleb128 (1, NULL
);
10363 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
10366 /* Output the source line number correspondence information. This
10367 information goes into the .debug_line section. */
10370 output_line_info (bool prologue_only
)
10372 char l1
[20], l2
[20], p1
[20], p2
[20];
10373 /* We don't support DWARFv5 line tables yet. */
10374 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
10375 bool saw_one
= false;
10378 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
10379 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
10380 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
10381 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
10383 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10384 dw2_asm_output_data (4, 0xffffffff,
10385 "Initial length escape value indicating 64-bit DWARF extension");
10386 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
10387 "Length of Source Line Info");
10388 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
10390 dw2_asm_output_data (2, ver
, "DWARF Version");
10391 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
10392 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
10394 /* Define the architecture-dependent minimum instruction length (in bytes).
10395 In this implementation of DWARF, this field is used for information
10396 purposes only. Since GCC generates assembly language, we have no
10397 a priori knowledge of how many instruction bytes are generated for each
10398 source line, and therefore can use only the DW_LNE_set_address and
10399 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10400 this as '1', which is "correct enough" for all architectures,
10401 and don't let the target override. */
10402 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10405 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
10406 "Maximum Operations Per Instruction");
10407 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
10408 "Default is_stmt_start flag");
10409 dw2_asm_output_data (1, DWARF_LINE_BASE
,
10410 "Line Base Value (Special Opcodes)");
10411 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
10412 "Line Range Value (Special Opcodes)");
10413 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
10414 "Special Opcode Base");
10416 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
10421 case DW_LNS_advance_pc
:
10422 case DW_LNS_advance_line
:
10423 case DW_LNS_set_file
:
10424 case DW_LNS_set_column
:
10425 case DW_LNS_fixed_advance_pc
:
10426 case DW_LNS_set_isa
:
10434 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
10438 /* Write out the information about the files we use. */
10439 output_file_names ();
10440 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
10443 /* Output the marker for the end of the line number info. */
10444 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10448 if (separate_line_info
)
10450 dw_line_info_table
*table
;
10453 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
10456 output_one_line_info_table (table
);
10460 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
10462 output_one_line_info_table (cold_text_section_line_info
);
10466 /* ??? Some Darwin linkers crash on a .debug_line section with no
10467 sequences. Further, merely a DW_LNE_end_sequence entry is not
10468 sufficient -- the address column must also be initialized.
10469 Make sure to output at least one set_address/end_sequence pair,
10470 choosing .text since that section is always present. */
10471 if (text_section_line_info
->in_use
|| !saw_one
)
10472 output_one_line_info_table (text_section_line_info
);
10474 /* Output the marker for the end of the line number info. */
10475 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10478 /* Given a pointer to a tree node for some base type, return a pointer to
10479 a DIE that describes the given type.
10481 This routine must only be called for GCC type nodes that correspond to
10482 Dwarf base (fundamental) types. */
10485 base_type_die (tree type
)
10487 dw_die_ref base_type_result
;
10488 enum dwarf_type encoding
;
10490 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
10493 /* If this is a subtype that should not be emitted as a subrange type,
10494 use the base type. See subrange_type_for_debug_p. */
10495 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
10496 type
= TREE_TYPE (type
);
10498 switch (TREE_CODE (type
))
10501 if ((dwarf_version
>= 4 || !dwarf_strict
)
10502 && TYPE_NAME (type
)
10503 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10504 && DECL_IS_BUILTIN (TYPE_NAME (type
))
10505 && DECL_NAME (TYPE_NAME (type
)))
10507 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
10508 if (strcmp (name
, "char16_t") == 0
10509 || strcmp (name
, "char32_t") == 0)
10511 encoding
= DW_ATE_UTF
;
10515 if (TYPE_STRING_FLAG (type
))
10517 if (TYPE_UNSIGNED (type
))
10518 encoding
= DW_ATE_unsigned_char
;
10520 encoding
= DW_ATE_signed_char
;
10522 else if (TYPE_UNSIGNED (type
))
10523 encoding
= DW_ATE_unsigned
;
10525 encoding
= DW_ATE_signed
;
10529 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
10531 if (dwarf_version
>= 3 || !dwarf_strict
)
10532 encoding
= DW_ATE_decimal_float
;
10534 encoding
= DW_ATE_lo_user
;
10537 encoding
= DW_ATE_float
;
10540 case FIXED_POINT_TYPE
:
10541 if (!(dwarf_version
>= 3 || !dwarf_strict
))
10542 encoding
= DW_ATE_lo_user
;
10543 else if (TYPE_UNSIGNED (type
))
10544 encoding
= DW_ATE_unsigned_fixed
;
10546 encoding
= DW_ATE_signed_fixed
;
10549 /* Dwarf2 doesn't know anything about complex ints, so use
10550 a user defined type for it. */
10552 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10553 encoding
= DW_ATE_complex_float
;
10555 encoding
= DW_ATE_lo_user
;
10559 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10560 encoding
= DW_ATE_boolean
;
10564 /* No other TREE_CODEs are Dwarf fundamental types. */
10565 gcc_unreachable ();
10568 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10570 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10571 int_size_in_bytes (type
));
10572 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10573 add_pubtype (type
, base_type_result
);
10575 return base_type_result
;
10578 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
10579 named 'auto' in its type: return true for it, false otherwise. */
10582 is_cxx_auto (tree type
)
10586 tree name
= TYPE_IDENTIFIER (type
);
10587 if (name
== get_identifier ("auto")
10588 || name
== get_identifier ("decltype(auto)"))
10594 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10595 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10598 is_base_type (tree type
)
10600 switch (TREE_CODE (type
))
10606 case FIXED_POINT_TYPE
:
10609 case POINTER_BOUNDS_TYPE
:
10615 case QUAL_UNION_TYPE
:
10616 case ENUMERAL_TYPE
:
10617 case FUNCTION_TYPE
:
10620 case REFERENCE_TYPE
:
10628 if (is_cxx_auto (type
))
10630 gcc_unreachable ();
10636 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10637 node, return the size in bits for the type if it is a constant, or else
10638 return the alignment for the type if the type's size is not constant, or
10639 else return BITS_PER_WORD if the type actually turns out to be an
10640 ERROR_MARK node. */
10642 static inline unsigned HOST_WIDE_INT
10643 simple_type_size_in_bits (const_tree type
)
10645 if (TREE_CODE (type
) == ERROR_MARK
)
10646 return BITS_PER_WORD
;
10647 else if (TYPE_SIZE (type
) == NULL_TREE
)
10649 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
10650 return tree_to_uhwi (TYPE_SIZE (type
));
10652 return TYPE_ALIGN (type
);
10655 /* Similarly, but return an offset_int instead of UHWI. */
10657 static inline offset_int
10658 offset_int_type_size_in_bits (const_tree type
)
10660 if (TREE_CODE (type
) == ERROR_MARK
)
10661 return BITS_PER_WORD
;
10662 else if (TYPE_SIZE (type
) == NULL_TREE
)
10664 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10665 return wi::to_offset (TYPE_SIZE (type
));
10667 return TYPE_ALIGN (type
);
10670 /* Given a pointer to a tree node for a subrange type, return a pointer
10671 to a DIE that describes the given type. */
10674 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10676 dw_die_ref subrange_die
;
10677 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10679 if (context_die
== NULL
)
10680 context_die
= comp_unit_die ();
10682 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10684 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10686 /* The size of the subrange type and its base type do not match,
10687 so we need to generate a size attribute for the subrange type. */
10688 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10692 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
, NULL
);
10694 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
, NULL
);
10696 return subrange_die
;
10699 /* Returns the (const and/or volatile) cv_qualifiers associated with
10700 the decl node. This will normally be augmented with the
10701 cv_qualifiers of the underlying type in add_type_attribute. */
10704 decl_quals (const_tree decl
)
10706 return ((TREE_READONLY (decl
)
10707 ? TYPE_QUAL_CONST
: TYPE_UNQUALIFIED
)
10708 | (TREE_THIS_VOLATILE (decl
)
10709 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
));
10712 /* Determine the TYPE whose qualifiers match the largest strict subset
10713 of the given TYPE_QUALS, and return its qualifiers. Ignore all
10714 qualifiers outside QUAL_MASK. */
10717 get_nearest_type_subqualifiers (tree type
, int type_quals
, int qual_mask
)
10720 int best_rank
= 0, best_qual
= 0, max_rank
;
10722 type_quals
&= qual_mask
;
10723 max_rank
= popcount_hwi (type_quals
) - 1;
10725 for (t
= TYPE_MAIN_VARIANT (type
); t
&& best_rank
< max_rank
;
10726 t
= TYPE_NEXT_VARIANT (t
))
10728 int q
= TYPE_QUALS (t
) & qual_mask
;
10730 if ((q
& type_quals
) == q
&& q
!= type_quals
10731 && check_base_type (t
, type
))
10733 int rank
= popcount_hwi (q
);
10735 if (rank
> best_rank
)
10746 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10747 entry that chains various modifiers in front of the given type. */
10750 modified_type_die (tree type
, int cv_quals
, dw_die_ref context_die
)
10752 enum tree_code code
= TREE_CODE (type
);
10753 dw_die_ref mod_type_die
;
10754 dw_die_ref sub_die
= NULL
;
10755 tree item_type
= NULL
;
10756 tree qualified_type
;
10757 tree name
, low
, high
;
10758 dw_die_ref mod_scope
;
10759 /* Only these cv-qualifiers are currently handled. */
10760 const int cv_qual_mask
= (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
10761 | TYPE_QUAL_RESTRICT
| TYPE_QUAL_ATOMIC
);
10763 if (code
== ERROR_MARK
)
10766 cv_quals
&= cv_qual_mask
;
10768 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
10769 tag modifier (and not an attribute) old consumers won't be able
10771 if (dwarf_version
< 3)
10772 cv_quals
&= ~TYPE_QUAL_RESTRICT
;
10774 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
10775 if (dwarf_version
< 5)
10776 cv_quals
&= ~TYPE_QUAL_ATOMIC
;
10778 /* See if we already have the appropriately qualified variant of
10780 qualified_type
= get_qualified_type (type
, cv_quals
);
10782 if (qualified_type
== sizetype
10783 && TYPE_NAME (qualified_type
)
10784 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10786 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10788 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10789 && TYPE_PRECISION (t
)
10790 == TYPE_PRECISION (qualified_type
)
10791 && TYPE_UNSIGNED (t
)
10792 == TYPE_UNSIGNED (qualified_type
));
10793 qualified_type
= t
;
10796 /* If we do, then we can just use its DIE, if it exists. */
10797 if (qualified_type
)
10799 mod_type_die
= lookup_type_die (qualified_type
);
10801 return mod_type_die
;
10804 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10806 /* Handle C typedef types. */
10807 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10808 && !DECL_ARTIFICIAL (name
))
10810 tree dtype
= TREE_TYPE (name
);
10812 if (qualified_type
== dtype
)
10814 /* For a named type, use the typedef. */
10815 gen_type_die (qualified_type
, context_die
);
10816 return lookup_type_die (qualified_type
);
10820 int dquals
= TYPE_QUALS_NO_ADDR_SPACE (dtype
);
10821 dquals
&= cv_qual_mask
;
10822 if ((dquals
& ~cv_quals
) != TYPE_UNQUALIFIED
10823 || (cv_quals
== dquals
&& DECL_ORIGINAL_TYPE (name
) != type
))
10824 /* cv-unqualified version of named type. Just use
10825 the unnamed type to which it refers. */
10826 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10827 cv_quals
, context_die
);
10828 /* Else cv-qualified version of named type; fall through. */
10832 mod_scope
= scope_die_for (type
, context_die
);
10836 struct qual_info
{ int q
; enum dwarf_tag t
; };
10837 static const struct qual_info qual_info
[] =
10839 { TYPE_QUAL_ATOMIC
, DW_TAG_atomic_type
},
10840 { TYPE_QUAL_RESTRICT
, DW_TAG_restrict_type
},
10841 { TYPE_QUAL_VOLATILE
, DW_TAG_volatile_type
},
10842 { TYPE_QUAL_CONST
, DW_TAG_const_type
},
10847 /* Determine a lesser qualified type that most closely matches
10848 this one. Then generate DW_TAG_* entries for the remaining
10850 sub_quals
= get_nearest_type_subqualifiers (type
, cv_quals
,
10852 mod_type_die
= modified_type_die (type
, sub_quals
, context_die
);
10854 for (i
= 0; i
< sizeof (qual_info
) / sizeof (qual_info
[0]); i
++)
10855 if (qual_info
[i
].q
& cv_quals
& ~sub_quals
)
10857 dw_die_ref d
= new_die (qual_info
[i
].t
, mod_scope
, type
);
10859 add_AT_die_ref (d
, DW_AT_type
, mod_type_die
);
10863 else if (code
== POINTER_TYPE
)
10865 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10866 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10867 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10868 item_type
= TREE_TYPE (type
);
10869 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10870 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10871 TYPE_ADDR_SPACE (item_type
));
10873 else if (code
== REFERENCE_TYPE
)
10875 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10876 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10879 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10880 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10881 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10882 item_type
= TREE_TYPE (type
);
10883 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10884 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10885 TYPE_ADDR_SPACE (item_type
));
10887 else if (code
== INTEGER_TYPE
10888 && TREE_TYPE (type
) != NULL_TREE
10889 && subrange_type_for_debug_p (type
, &low
, &high
))
10891 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10892 item_type
= TREE_TYPE (type
);
10894 else if (is_base_type (type
))
10895 mod_type_die
= base_type_die (type
);
10898 gen_type_die (type
, context_die
);
10900 /* We have to get the type_main_variant here (and pass that to the
10901 `lookup_type_die' routine) because the ..._TYPE node we have
10902 might simply be a *copy* of some original type node (where the
10903 copy was created to help us keep track of typedef names) and
10904 that copy might have a different TYPE_UID from the original
10906 if (TREE_CODE (type
) != VECTOR_TYPE
)
10907 return lookup_type_die (type_main_variant (type
));
10909 /* Vectors have the debugging information in the type,
10910 not the main variant. */
10911 return lookup_type_die (type
);
10914 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10915 don't output a DW_TAG_typedef, since there isn't one in the
10916 user's program; just attach a DW_AT_name to the type.
10917 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10918 if the base type already has the same name. */
10920 && ((TREE_CODE (name
) != TYPE_DECL
10921 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10922 || (cv_quals
== TYPE_UNQUALIFIED
)))
10923 || (TREE_CODE (name
) == TYPE_DECL
10924 && TREE_TYPE (name
) == qualified_type
10925 && DECL_NAME (name
))))
10927 if (TREE_CODE (name
) == TYPE_DECL
)
10928 /* Could just call add_name_and_src_coords_attributes here,
10929 but since this is a builtin type it doesn't have any
10930 useful source coordinates anyway. */
10931 name
= DECL_NAME (name
);
10932 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10934 /* This probably indicates a bug. */
10935 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10937 name
= TYPE_IDENTIFIER (type
);
10938 add_name_attribute (mod_type_die
,
10939 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10942 if (qualified_type
)
10943 equate_type_number_to_die (qualified_type
, mod_type_die
);
10946 /* We must do this after the equate_type_number_to_die call, in case
10947 this is a recursive type. This ensures that the modified_type_die
10948 recursion will terminate even if the type is recursive. Recursive
10949 types are possible in Ada. */
10950 sub_die
= modified_type_die (item_type
,
10951 TYPE_QUALS_NO_ADDR_SPACE (item_type
),
10954 if (sub_die
!= NULL
)
10955 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10957 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10958 if (TYPE_ARTIFICIAL (type
))
10959 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10961 return mod_type_die
;
10964 /* Generate DIEs for the generic parameters of T.
10965 T must be either a generic type or a generic function.
10966 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10969 gen_generic_params_dies (tree t
)
10973 dw_die_ref die
= NULL
;
10976 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10980 die
= lookup_type_die (t
);
10981 else if (DECL_P (t
))
10982 die
= lookup_decl_die (t
);
10986 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10988 /* T has no generic parameter. It means T is neither a generic type
10989 or function. End of story. */
10992 parms_num
= TREE_VEC_LENGTH (parms
);
10993 args
= lang_hooks
.get_innermost_generic_args (t
);
10994 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
10995 non_default
= int_cst_value (TREE_CHAIN (args
));
10997 non_default
= TREE_VEC_LENGTH (args
);
10998 for (i
= 0; i
< parms_num
; i
++)
11000 tree parm
, arg
, arg_pack_elems
;
11001 dw_die_ref parm_die
;
11003 parm
= TREE_VEC_ELT (parms
, i
);
11004 arg
= TREE_VEC_ELT (args
, i
);
11005 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
11006 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
11008 if (parm
&& TREE_VALUE (parm
) && arg
)
11010 /* If PARM represents a template parameter pack,
11011 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
11012 by DW_TAG_template_*_parameter DIEs for the argument
11013 pack elements of ARG. Note that ARG would then be
11014 an argument pack. */
11015 if (arg_pack_elems
)
11016 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
11020 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
11021 true /* emit name */, die
);
11022 if (i
>= non_default
)
11023 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
11028 /* Create and return a DIE for PARM which should be
11029 the representation of a generic type parameter.
11030 For instance, in the C++ front end, PARM would be a template parameter.
11031 ARG is the argument to PARM.
11032 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
11034 PARENT_DIE is the parent DIE which the new created DIE should be added to,
11035 as a child node. */
11038 generic_parameter_die (tree parm
, tree arg
,
11040 dw_die_ref parent_die
)
11042 dw_die_ref tmpl_die
= NULL
;
11043 const char *name
= NULL
;
11045 if (!parm
|| !DECL_NAME (parm
) || !arg
)
11048 /* We support non-type generic parameters and arguments,
11049 type generic parameters and arguments, as well as
11050 generic generic parameters (a.k.a. template template parameters in C++)
11052 if (TREE_CODE (parm
) == PARM_DECL
)
11053 /* PARM is a nontype generic parameter */
11054 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
11055 else if (TREE_CODE (parm
) == TYPE_DECL
)
11056 /* PARM is a type generic parameter. */
11057 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
11058 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
11059 /* PARM is a generic generic parameter.
11060 Its DIE is a GNU extension. It shall have a
11061 DW_AT_name attribute to represent the name of the template template
11062 parameter, and a DW_AT_GNU_template_name attribute to represent the
11063 name of the template template argument. */
11064 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
11067 gcc_unreachable ();
11073 /* If PARM is a generic parameter pack, it means we are
11074 emitting debug info for a template argument pack element.
11075 In other terms, ARG is a template argument pack element.
11076 In that case, we don't emit any DW_AT_name attribute for
11080 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
11082 add_AT_string (tmpl_die
, DW_AT_name
, name
);
11085 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
11087 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
11088 TMPL_DIE should have a child DW_AT_type attribute that is set
11089 to the type of the argument to PARM, which is ARG.
11090 If PARM is a type generic parameter, TMPL_DIE should have a
11091 child DW_AT_type that is set to ARG. */
11092 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
11093 add_type_attribute (tmpl_die
, tmpl_type
,
11094 (TREE_THIS_VOLATILE (tmpl_type
)
11095 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
),
11100 /* So TMPL_DIE is a DIE representing a
11101 a generic generic template parameter, a.k.a template template
11102 parameter in C++ and arg is a template. */
11104 /* The DW_AT_GNU_template_name attribute of the DIE must be set
11105 to the name of the argument. */
11106 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
11108 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
11111 if (TREE_CODE (parm
) == PARM_DECL
)
11112 /* So PARM is a non-type generic parameter.
11113 DWARF3 5.6.8 says we must set a DW_AT_const_value child
11114 attribute of TMPL_DIE which value represents the value
11116 We must be careful here:
11117 The value of ARG might reference some function decls.
11118 We might currently be emitting debug info for a generic
11119 type and types are emitted before function decls, we don't
11120 know if the function decls referenced by ARG will actually be
11121 emitted after cgraph computations.
11122 So must defer the generation of the DW_AT_const_value to
11123 after cgraph is ready. */
11124 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
11130 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
11131 PARM_PACK must be a template parameter pack. The returned DIE
11132 will be child DIE of PARENT_DIE. */
11135 template_parameter_pack_die (tree parm_pack
,
11136 tree parm_pack_args
,
11137 dw_die_ref parent_die
)
11142 gcc_assert (parent_die
&& parm_pack
);
11144 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
11145 add_name_and_src_coords_attributes (die
, parm_pack
);
11146 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
11147 generic_parameter_die (parm_pack
,
11148 TREE_VEC_ELT (parm_pack_args
, j
),
11149 false /* Don't emit DW_AT_name */,
11154 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
11155 an enumerated type. */
11158 type_is_enum (const_tree type
)
11160 return TREE_CODE (type
) == ENUMERAL_TYPE
;
11163 /* Return the DBX register number described by a given RTL node. */
11165 static unsigned int
11166 dbx_reg_number (const_rtx rtl
)
11168 unsigned regno
= REGNO (rtl
);
11170 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
11172 #ifdef LEAF_REG_REMAP
11173 if (crtl
->uses_only_leaf_regs
)
11175 int leaf_reg
= LEAF_REG_REMAP (regno
);
11176 if (leaf_reg
!= -1)
11177 regno
= (unsigned) leaf_reg
;
11181 regno
= DBX_REGISTER_NUMBER (regno
);
11182 gcc_assert (regno
!= INVALID_REGNUM
);
11186 /* Optionally add a DW_OP_piece term to a location description expression.
11187 DW_OP_piece is only added if the location description expression already
11188 doesn't end with DW_OP_piece. */
11191 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
11193 dw_loc_descr_ref loc
;
11195 if (*list_head
!= NULL
)
11197 /* Find the end of the chain. */
11198 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
11201 if (loc
->dw_loc_opc
!= DW_OP_piece
)
11202 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
11206 /* Return a location descriptor that designates a machine register or
11207 zero if there is none. */
11209 static dw_loc_descr_ref
11210 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
11214 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
11217 /* We only use "frame base" when we're sure we're talking about the
11218 post-prologue local stack frame. We do this by *not* running
11219 register elimination until this point, and recognizing the special
11220 argument pointer and soft frame pointer rtx's.
11221 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
11222 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
11223 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
11225 dw_loc_descr_ref result
= NULL
;
11227 if (dwarf_version
>= 4 || !dwarf_strict
)
11229 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
11232 add_loc_descr (&result
,
11233 new_loc_descr (DW_OP_stack_value
, 0, 0));
11238 regs
= targetm
.dwarf_register_span (rtl
);
11240 if (REG_NREGS (rtl
) > 1 || regs
)
11241 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
11244 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
11245 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
11247 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
11251 /* Return a location descriptor that designates a machine register for
11252 a given hard register number. */
11254 static dw_loc_descr_ref
11255 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
11257 dw_loc_descr_ref reg_loc_descr
;
11261 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
11263 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
11265 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11266 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11268 return reg_loc_descr
;
11271 /* Given an RTL of a register, return a location descriptor that
11272 designates a value that spans more than one register. */
11274 static dw_loc_descr_ref
11275 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
11276 enum var_init_status initialized
)
11279 dw_loc_descr_ref loc_result
= NULL
;
11281 /* Simple, contiguous registers. */
11282 if (regs
== NULL_RTX
)
11284 unsigned reg
= REGNO (rtl
);
11287 #ifdef LEAF_REG_REMAP
11288 if (crtl
->uses_only_leaf_regs
)
11290 int leaf_reg
= LEAF_REG_REMAP (reg
);
11291 if (leaf_reg
!= -1)
11292 reg
= (unsigned) leaf_reg
;
11296 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
11297 nregs
= REG_NREGS (rtl
);
11299 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
11304 dw_loc_descr_ref t
;
11306 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
11307 VAR_INIT_STATUS_INITIALIZED
);
11308 add_loc_descr (&loc_result
, t
);
11309 add_loc_descr_op_piece (&loc_result
, size
);
11315 /* Now onto stupid register sets in non contiguous locations. */
11317 gcc_assert (GET_CODE (regs
) == PARALLEL
);
11319 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
11322 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
11324 dw_loc_descr_ref t
;
11326 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
11327 VAR_INIT_STATUS_INITIALIZED
);
11328 add_loc_descr (&loc_result
, t
);
11329 add_loc_descr_op_piece (&loc_result
, size
);
11332 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11333 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11337 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
11339 /* Return a location descriptor that designates a constant i,
11340 as a compound operation from constant (i >> shift), constant shift
11343 static dw_loc_descr_ref
11344 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11346 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
11347 add_loc_descr (&ret
, int_loc_descriptor (shift
));
11348 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11352 /* Return a location descriptor that designates a constant. */
11354 static dw_loc_descr_ref
11355 int_loc_descriptor (HOST_WIDE_INT i
)
11357 enum dwarf_location_atom op
;
11359 /* Pick the smallest representation of a constant, rather than just
11360 defaulting to the LEB encoding. */
11363 int clz
= clz_hwi (i
);
11364 int ctz
= ctz_hwi (i
);
11366 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
11367 else if (i
<= 0xff)
11368 op
= DW_OP_const1u
;
11369 else if (i
<= 0xffff)
11370 op
= DW_OP_const2u
;
11371 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11372 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11373 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
11374 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
11375 while DW_OP_const4u is 5 bytes. */
11376 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
11377 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11378 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11379 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
11380 while DW_OP_const4u is 5 bytes. */
11381 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11382 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11383 op
= DW_OP_const4u
;
11384 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11385 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11386 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
11387 while DW_OP_constu of constant >= 0x100000000 takes at least
11389 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11390 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11391 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
11392 >= HOST_BITS_PER_WIDE_INT
)
11393 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
11394 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
11395 while DW_OP_constu takes in this case at least 6 bytes. */
11396 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
11397 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11398 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11399 && size_of_uleb128 (i
) > 6)
11400 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
11401 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
11408 op
= DW_OP_const1s
;
11409 else if (i
>= -0x8000)
11410 op
= DW_OP_const2s
;
11411 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11413 if (size_of_int_loc_descriptor (i
) < 5)
11415 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11416 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11419 op
= DW_OP_const4s
;
11423 if (size_of_int_loc_descriptor (i
)
11424 < (unsigned long) 1 + size_of_sleb128 (i
))
11426 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11427 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11434 return new_loc_descr (op
, i
, 0);
11437 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
11438 without actually allocating it. */
11440 static unsigned long
11441 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11443 return size_of_int_loc_descriptor (i
>> shift
)
11444 + size_of_int_loc_descriptor (shift
)
11448 /* Return size_of_locs (int_loc_descriptor (i)) without
11449 actually allocating it. */
11451 static unsigned long
11452 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
11461 else if (i
<= 0xff)
11463 else if (i
<= 0xffff)
11467 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11468 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11469 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11471 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11472 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11473 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11475 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11477 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
11478 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11479 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11480 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11482 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11483 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
11484 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11486 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11487 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11489 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11498 else if (i
>= -0x8000)
11500 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11502 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11504 s
= size_of_int_loc_descriptor (-i
) + 1;
11512 unsigned long r
= 1 + size_of_sleb128 (i
);
11513 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11515 s
= size_of_int_loc_descriptor (-i
) + 1;
11524 /* Return loc description representing "address" of integer value.
11525 This can appear only as toplevel expression. */
11527 static dw_loc_descr_ref
11528 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
11531 dw_loc_descr_ref loc_result
= NULL
;
11533 if (!(dwarf_version
>= 4 || !dwarf_strict
))
11536 litsize
= size_of_int_loc_descriptor (i
);
11537 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
11538 is more compact. For DW_OP_stack_value we need:
11539 litsize + 1 (DW_OP_stack_value)
11540 and for DW_OP_implicit_value:
11541 1 (DW_OP_implicit_value) + 1 (length) + size. */
11542 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
11544 loc_result
= int_loc_descriptor (i
);
11545 add_loc_descr (&loc_result
,
11546 new_loc_descr (DW_OP_stack_value
, 0, 0));
11550 loc_result
= new_loc_descr (DW_OP_implicit_value
,
11552 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
11553 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
11557 /* Return a location descriptor that designates a base+offset location. */
11559 static dw_loc_descr_ref
11560 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
11561 enum var_init_status initialized
)
11563 unsigned int regno
;
11564 dw_loc_descr_ref result
;
11565 dw_fde_ref fde
= cfun
->fde
;
11567 /* We only use "frame base" when we're sure we're talking about the
11568 post-prologue local stack frame. We do this by *not* running
11569 register elimination until this point, and recognizing the special
11570 argument pointer and soft frame pointer rtx's. */
11571 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
11573 rtx elim
= (ira_use_lra_p
11574 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
11575 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
11579 if (GET_CODE (elim
) == PLUS
)
11581 offset
+= INTVAL (XEXP (elim
, 1));
11582 elim
= XEXP (elim
, 0);
11584 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11585 && (elim
== hard_frame_pointer_rtx
11586 || elim
== stack_pointer_rtx
))
11587 || elim
== (frame_pointer_needed
11588 ? hard_frame_pointer_rtx
11589 : stack_pointer_rtx
));
11591 /* If drap register is used to align stack, use frame
11592 pointer + offset to access stack variables. If stack
11593 is aligned without drap, use stack pointer + offset to
11594 access stack variables. */
11595 if (crtl
->stack_realign_tried
11596 && reg
== frame_pointer_rtx
)
11599 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
11600 ? HARD_FRAME_POINTER_REGNUM
11602 return new_reg_loc_descr (base_reg
, offset
);
11605 gcc_assert (frame_pointer_fb_offset_valid
);
11606 offset
+= frame_pointer_fb_offset
;
11607 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11611 regno
= REGNO (reg
);
11612 #ifdef LEAF_REG_REMAP
11613 if (crtl
->uses_only_leaf_regs
)
11615 int leaf_reg
= LEAF_REG_REMAP (regno
);
11616 if (leaf_reg
!= -1)
11617 regno
= (unsigned) leaf_reg
;
11620 regno
= DWARF_FRAME_REGNUM (regno
);
11622 if (!optimize
&& fde
11623 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
11625 /* Use cfa+offset to represent the location of arguments passed
11626 on the stack when drap is used to align stack.
11627 Only do this when not optimizing, for optimized code var-tracking
11628 is supposed to track where the arguments live and the register
11629 used as vdrap or drap in some spot might be used for something
11630 else in other part of the routine. */
11631 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11635 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
11638 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
11640 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11641 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11646 /* Return true if this RTL expression describes a base+offset calculation. */
11649 is_based_loc (const_rtx rtl
)
11651 return (GET_CODE (rtl
) == PLUS
11652 && ((REG_P (XEXP (rtl
, 0))
11653 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
11654 && CONST_INT_P (XEXP (rtl
, 1)))));
11657 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11660 static dw_loc_descr_ref
11661 tls_mem_loc_descriptor (rtx mem
)
11664 dw_loc_descr_ref loc_result
;
11666 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
11669 base
= get_base_address (MEM_EXPR (mem
));
11671 || TREE_CODE (base
) != VAR_DECL
11672 || !DECL_THREAD_LOCAL_P (base
))
11675 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1, NULL
);
11676 if (loc_result
== NULL
)
11679 if (MEM_OFFSET (mem
))
11680 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
11685 /* Output debug info about reason why we failed to expand expression as dwarf
11689 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
11691 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
11693 fprintf (dump_file
, "Failed to expand as dwarf: ");
11695 print_generic_expr (dump_file
, expr
, dump_flags
);
11698 fprintf (dump_file
, "\n");
11699 print_rtl (dump_file
, rtl
);
11701 fprintf (dump_file
, "\nReason: %s\n", reason
);
11705 /* Helper function for const_ok_for_output. */
11708 const_ok_for_output_1 (rtx rtl
)
11710 if (GET_CODE (rtl
) == UNSPEC
)
11712 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11713 we can't express it in the debug info. */
11714 #ifdef ENABLE_CHECKING
11715 /* Don't complain about TLS UNSPECs, those are just too hard to
11716 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11717 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11718 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11719 if (XVECLEN (rtl
, 0) == 0
11720 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11721 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
11722 inform (current_function_decl
11723 ? DECL_SOURCE_LOCATION (current_function_decl
)
11724 : UNKNOWN_LOCATION
,
11725 #if NUM_UNSPEC_VALUES > 0
11726 "non-delegitimized UNSPEC %s (%d) found in variable location",
11727 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11728 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11731 "non-delegitimized UNSPEC %d found in variable location",
11735 expansion_failed (NULL_TREE
, rtl
,
11736 "UNSPEC hasn't been delegitimized.\n");
11740 if (targetm
.const_not_ok_for_debug_p (rtl
))
11742 expansion_failed (NULL_TREE
, rtl
,
11743 "Expression rejected for debug by the backend.\n");
11747 /* FIXME: Refer to PR60655. It is possible for simplification
11748 of rtl expressions in var tracking to produce such expressions.
11749 We should really identify / validate expressions
11750 enclosed in CONST that can be handled by assemblers on various
11751 targets and only handle legitimate cases here. */
11752 if (GET_CODE (rtl
) != SYMBOL_REF
)
11754 if (GET_CODE (rtl
) == NOT
)
11759 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11762 get_pool_constant_mark (rtl
, &marked
);
11763 /* If all references to this pool constant were optimized away,
11764 it was not output and thus we can't represent it. */
11767 expansion_failed (NULL_TREE
, rtl
,
11768 "Constant was removed from constant pool.\n");
11773 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11776 /* Avoid references to external symbols in debug info, on several targets
11777 the linker might even refuse to link when linking a shared library,
11778 and in many other cases the relocations for .debug_info/.debug_loc are
11779 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11780 to be defined within the same shared library or executable are fine. */
11781 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11783 tree decl
= SYMBOL_REF_DECL (rtl
);
11785 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11787 expansion_failed (NULL_TREE
, rtl
,
11788 "Symbol not defined in current TU.\n");
11796 /* Return true if constant RTL can be emitted in DW_OP_addr or
11797 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11798 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11801 const_ok_for_output (rtx rtl
)
11803 if (GET_CODE (rtl
) == SYMBOL_REF
)
11804 return const_ok_for_output_1 (rtl
);
11806 if (GET_CODE (rtl
) == CONST
)
11808 subrtx_var_iterator::array_type array
;
11809 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
11810 if (!const_ok_for_output_1 (*iter
))
11818 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11819 if possible, NULL otherwise. */
11822 base_type_for_mode (machine_mode mode
, bool unsignedp
)
11824 dw_die_ref type_die
;
11825 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11829 switch (TREE_CODE (type
))
11837 type_die
= lookup_type_die (type
);
11839 type_die
= modified_type_die (type
, TYPE_UNQUALIFIED
, comp_unit_die ());
11840 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11845 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11846 type matching MODE, or, if MODE is narrower than or as wide as
11847 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11850 static dw_loc_descr_ref
11851 convert_descriptor_to_mode (machine_mode mode
, dw_loc_descr_ref op
)
11853 machine_mode outer_mode
= mode
;
11854 dw_die_ref type_die
;
11855 dw_loc_descr_ref cvt
;
11857 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11859 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11862 type_die
= base_type_for_mode (outer_mode
, 1);
11863 if (type_die
== NULL
)
11865 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11866 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11867 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11868 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11869 add_loc_descr (&op
, cvt
);
11873 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11875 static dw_loc_descr_ref
11876 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11877 dw_loc_descr_ref op1
)
11879 dw_loc_descr_ref ret
= op0
;
11880 add_loc_descr (&ret
, op1
);
11881 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11882 if (STORE_FLAG_VALUE
!= 1)
11884 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11885 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11890 /* Return location descriptor for signed comparison OP RTL. */
11892 static dw_loc_descr_ref
11893 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11894 machine_mode mem_mode
)
11896 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11897 dw_loc_descr_ref op0
, op1
;
11900 if (op_mode
== VOIDmode
)
11901 op_mode
= GET_MODE (XEXP (rtl
, 1));
11902 if (op_mode
== VOIDmode
)
11906 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11907 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11910 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11911 VAR_INIT_STATUS_INITIALIZED
);
11912 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11913 VAR_INIT_STATUS_INITIALIZED
);
11915 if (op0
== NULL
|| op1
== NULL
)
11918 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11919 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11920 return compare_loc_descriptor (op
, op0
, op1
);
11922 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11924 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11925 dw_loc_descr_ref cvt
;
11927 if (type_die
== NULL
)
11929 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11930 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11931 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11932 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11933 add_loc_descr (&op0
, cvt
);
11934 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11935 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11936 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11937 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11938 add_loc_descr (&op1
, cvt
);
11939 return compare_loc_descriptor (op
, op0
, op1
);
11942 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11943 /* For eq/ne, if the operands are known to be zero-extended,
11944 there is no need to do the fancy shifting up. */
11945 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11947 dw_loc_descr_ref last0
, last1
;
11948 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11950 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11952 /* deref_size zero extends, and for constants we can check
11953 whether they are zero extended or not. */
11954 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11955 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11956 || (CONST_INT_P (XEXP (rtl
, 0))
11957 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11958 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11959 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11960 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11961 || (CONST_INT_P (XEXP (rtl
, 1))
11962 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11963 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11964 return compare_loc_descriptor (op
, op0
, op1
);
11966 /* EQ/NE comparison against constant in narrower type than
11967 DWARF2_ADDR_SIZE can be performed either as
11968 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11971 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11972 DW_OP_{eq,ne}. Pick whatever is shorter. */
11973 if (CONST_INT_P (XEXP (rtl
, 1))
11974 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11975 && (size_of_int_loc_descriptor (shift
) + 1
11976 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11977 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11978 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11979 & GET_MODE_MASK (op_mode
))))
11981 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11982 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11983 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11984 & GET_MODE_MASK (op_mode
));
11985 return compare_loc_descriptor (op
, op0
, op1
);
11988 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11989 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11990 if (CONST_INT_P (XEXP (rtl
, 1)))
11991 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11994 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11995 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11997 return compare_loc_descriptor (op
, op0
, op1
);
12000 /* Return location descriptor for unsigned comparison OP RTL. */
12002 static dw_loc_descr_ref
12003 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
12004 machine_mode mem_mode
)
12006 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
12007 dw_loc_descr_ref op0
, op1
;
12009 if (op_mode
== VOIDmode
)
12010 op_mode
= GET_MODE (XEXP (rtl
, 1));
12011 if (op_mode
== VOIDmode
)
12013 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
12016 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
12019 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
12020 VAR_INIT_STATUS_INITIALIZED
);
12021 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
12022 VAR_INIT_STATUS_INITIALIZED
);
12024 if (op0
== NULL
|| op1
== NULL
)
12027 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
12029 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
12030 dw_loc_descr_ref last0
, last1
;
12031 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
12033 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
12035 if (CONST_INT_P (XEXP (rtl
, 0)))
12036 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
12037 /* deref_size zero extends, so no need to mask it again. */
12038 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
12039 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
12041 add_loc_descr (&op0
, int_loc_descriptor (mask
));
12042 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
12044 if (CONST_INT_P (XEXP (rtl
, 1)))
12045 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
12046 /* deref_size zero extends, so no need to mask it again. */
12047 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
12048 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
12050 add_loc_descr (&op1
, int_loc_descriptor (mask
));
12051 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
12054 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
12056 HOST_WIDE_INT bias
= 1;
12057 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
12058 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12059 if (CONST_INT_P (XEXP (rtl
, 1)))
12060 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
12061 + INTVAL (XEXP (rtl
, 1)));
12063 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
12066 return compare_loc_descriptor (op
, op0
, op1
);
12069 /* Return location descriptor for {U,S}{MIN,MAX}. */
12071 static dw_loc_descr_ref
12072 minmax_loc_descriptor (rtx rtl
, machine_mode mode
,
12073 machine_mode mem_mode
)
12075 enum dwarf_location_atom op
;
12076 dw_loc_descr_ref op0
, op1
, ret
;
12077 dw_loc_descr_ref bra_node
, drop_node
;
12080 && (GET_MODE_CLASS (mode
) != MODE_INT
12081 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
12084 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12085 VAR_INIT_STATUS_INITIALIZED
);
12086 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12087 VAR_INIT_STATUS_INITIALIZED
);
12089 if (op0
== NULL
|| op1
== NULL
)
12092 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
12093 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
12094 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
12095 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
12097 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12099 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
12100 add_loc_descr (&op0
, int_loc_descriptor (mask
));
12101 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
12102 add_loc_descr (&op1
, int_loc_descriptor (mask
));
12103 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
12105 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12107 HOST_WIDE_INT bias
= 1;
12108 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
12109 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12110 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12113 else if (GET_MODE_CLASS (mode
) == MODE_INT
12114 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12116 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
12117 add_loc_descr (&op0
, int_loc_descriptor (shift
));
12118 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
12119 add_loc_descr (&op1
, int_loc_descriptor (shift
));
12120 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
12122 else if (GET_MODE_CLASS (mode
) == MODE_INT
12123 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12125 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
12126 dw_loc_descr_ref cvt
;
12127 if (type_die
== NULL
)
12129 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12130 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12131 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12132 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12133 add_loc_descr (&op0
, cvt
);
12134 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12135 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12136 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12137 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12138 add_loc_descr (&op1
, cvt
);
12141 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
12146 add_loc_descr (&ret
, op1
);
12147 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
12148 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12149 add_loc_descr (&ret
, bra_node
);
12150 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12151 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12152 add_loc_descr (&ret
, drop_node
);
12153 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12154 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12155 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
12156 && GET_MODE_CLASS (mode
) == MODE_INT
12157 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12158 ret
= convert_descriptor_to_mode (mode
, ret
);
12162 /* Helper function for mem_loc_descriptor. Perform OP binary op,
12163 but after converting arguments to type_die, afterwards
12164 convert back to unsigned. */
12166 static dw_loc_descr_ref
12167 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
12168 machine_mode mode
, machine_mode mem_mode
)
12170 dw_loc_descr_ref cvt
, op0
, op1
;
12172 if (type_die
== NULL
)
12174 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12175 VAR_INIT_STATUS_INITIALIZED
);
12176 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12177 VAR_INIT_STATUS_INITIALIZED
);
12178 if (op0
== NULL
|| op1
== NULL
)
12180 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12181 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12182 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12183 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12184 add_loc_descr (&op0
, cvt
);
12185 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12186 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12187 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12188 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12189 add_loc_descr (&op1
, cvt
);
12190 add_loc_descr (&op0
, op1
);
12191 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
12192 return convert_descriptor_to_mode (mode
, op0
);
12195 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
12196 const0 is DW_OP_lit0 or corresponding typed constant,
12197 const1 is DW_OP_lit1 or corresponding typed constant
12198 and constMSB is constant with just the MSB bit set
12200 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12201 L1: const0 DW_OP_swap
12202 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
12203 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12208 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12209 L1: const0 DW_OP_swap
12210 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12211 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12216 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
12217 L1: const1 DW_OP_swap
12218 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12219 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12223 static dw_loc_descr_ref
12224 clz_loc_descriptor (rtx rtl
, machine_mode mode
,
12225 machine_mode mem_mode
)
12227 dw_loc_descr_ref op0
, ret
, tmp
;
12228 HOST_WIDE_INT valv
;
12229 dw_loc_descr_ref l1jump
, l1label
;
12230 dw_loc_descr_ref l2jump
, l2label
;
12231 dw_loc_descr_ref l3jump
, l3label
;
12232 dw_loc_descr_ref l4jump
, l4label
;
12235 if (GET_MODE_CLASS (mode
) != MODE_INT
12236 || GET_MODE (XEXP (rtl
, 0)) != mode
)
12239 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12240 VAR_INIT_STATUS_INITIALIZED
);
12244 if (GET_CODE (rtl
) == CLZ
)
12246 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
12247 valv
= GET_MODE_BITSIZE (mode
);
12249 else if (GET_CODE (rtl
) == FFS
)
12251 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
12252 valv
= GET_MODE_BITSIZE (mode
);
12253 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12254 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12255 add_loc_descr (&ret
, l1jump
);
12256 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12257 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
12258 VAR_INIT_STATUS_INITIALIZED
);
12261 add_loc_descr (&ret
, tmp
);
12262 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12263 add_loc_descr (&ret
, l4jump
);
12264 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
12265 ? const1_rtx
: const0_rtx
,
12267 VAR_INIT_STATUS_INITIALIZED
);
12268 if (l1label
== NULL
)
12270 add_loc_descr (&ret
, l1label
);
12271 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12272 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
12273 add_loc_descr (&ret
, l2label
);
12274 if (GET_CODE (rtl
) != CLZ
)
12276 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
12277 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
12278 << (GET_MODE_BITSIZE (mode
) - 1));
12280 msb
= immed_wide_int_const
12281 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
12282 GET_MODE_PRECISION (mode
)), mode
);
12283 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
12284 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12285 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
12286 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
12288 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
12289 VAR_INIT_STATUS_INITIALIZED
);
12292 add_loc_descr (&ret
, tmp
);
12293 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12294 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12295 add_loc_descr (&ret
, l3jump
);
12296 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12297 VAR_INIT_STATUS_INITIALIZED
);
12300 add_loc_descr (&ret
, tmp
);
12301 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
12302 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
12303 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12304 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
12305 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12306 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12307 add_loc_descr (&ret
, l2jump
);
12308 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
12309 add_loc_descr (&ret
, l3label
);
12310 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
12311 add_loc_descr (&ret
, l4label
);
12312 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12313 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12314 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12315 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12316 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12317 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
12318 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12319 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
12323 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
12324 const1 is DW_OP_lit1 or corresponding typed constant):
12326 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12327 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12331 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12332 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12335 static dw_loc_descr_ref
12336 popcount_loc_descriptor (rtx rtl
, machine_mode mode
,
12337 machine_mode mem_mode
)
12339 dw_loc_descr_ref op0
, ret
, tmp
;
12340 dw_loc_descr_ref l1jump
, l1label
;
12341 dw_loc_descr_ref l2jump
, l2label
;
12343 if (GET_MODE_CLASS (mode
) != MODE_INT
12344 || GET_MODE (XEXP (rtl
, 0)) != mode
)
12347 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12348 VAR_INIT_STATUS_INITIALIZED
);
12352 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12353 VAR_INIT_STATUS_INITIALIZED
);
12356 add_loc_descr (&ret
, tmp
);
12357 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12358 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
12359 add_loc_descr (&ret
, l1label
);
12360 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12361 add_loc_descr (&ret
, l2jump
);
12362 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12363 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12364 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12365 VAR_INIT_STATUS_INITIALIZED
);
12368 add_loc_descr (&ret
, tmp
);
12369 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12370 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
12371 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
12372 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12373 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12374 VAR_INIT_STATUS_INITIALIZED
);
12375 add_loc_descr (&ret
, tmp
);
12376 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12377 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12378 add_loc_descr (&ret
, l1jump
);
12379 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12380 add_loc_descr (&ret
, l2label
);
12381 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12382 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12383 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12384 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12388 /* BSWAP (constS is initial shift count, either 56 or 24):
12390 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
12391 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
12392 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
12393 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
12394 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
12396 static dw_loc_descr_ref
12397 bswap_loc_descriptor (rtx rtl
, machine_mode mode
,
12398 machine_mode mem_mode
)
12400 dw_loc_descr_ref op0
, ret
, tmp
;
12401 dw_loc_descr_ref l1jump
, l1label
;
12402 dw_loc_descr_ref l2jump
, l2label
;
12404 if (GET_MODE_CLASS (mode
) != MODE_INT
12405 || BITS_PER_UNIT
!= 8
12406 || (GET_MODE_BITSIZE (mode
) != 32
12407 && GET_MODE_BITSIZE (mode
) != 64))
12410 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12411 VAR_INIT_STATUS_INITIALIZED
);
12416 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
12418 VAR_INIT_STATUS_INITIALIZED
);
12421 add_loc_descr (&ret
, tmp
);
12422 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12423 VAR_INIT_STATUS_INITIALIZED
);
12426 add_loc_descr (&ret
, tmp
);
12427 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
12428 add_loc_descr (&ret
, l1label
);
12429 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
12431 VAR_INIT_STATUS_INITIALIZED
);
12432 add_loc_descr (&ret
, tmp
);
12433 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
12434 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12435 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12436 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
12437 VAR_INIT_STATUS_INITIALIZED
);
12440 add_loc_descr (&ret
, tmp
);
12441 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12442 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
12443 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12444 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12445 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12446 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12447 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12448 VAR_INIT_STATUS_INITIALIZED
);
12449 add_loc_descr (&ret
, tmp
);
12450 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
12451 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12452 add_loc_descr (&ret
, l2jump
);
12453 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
12454 VAR_INIT_STATUS_INITIALIZED
);
12455 add_loc_descr (&ret
, tmp
);
12456 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12457 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12458 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12459 add_loc_descr (&ret
, l1jump
);
12460 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12461 add_loc_descr (&ret
, l2label
);
12462 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12463 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12464 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12465 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12466 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12467 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12471 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
12472 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12473 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
12474 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
12476 ROTATERT is similar:
12477 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
12478 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12479 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
12481 static dw_loc_descr_ref
12482 rotate_loc_descriptor (rtx rtl
, machine_mode mode
,
12483 machine_mode mem_mode
)
12485 rtx rtlop1
= XEXP (rtl
, 1);
12486 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
12489 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12492 if (GET_MODE (rtlop1
) != VOIDmode
12493 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
12494 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12495 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12496 VAR_INIT_STATUS_INITIALIZED
);
12497 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12498 VAR_INIT_STATUS_INITIALIZED
);
12499 if (op0
== NULL
|| op1
== NULL
)
12501 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12502 for (i
= 0; i
< 2; i
++)
12504 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
12505 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
12507 VAR_INIT_STATUS_INITIALIZED
);
12508 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12509 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12511 : HOST_BITS_PER_WIDE_INT
== 64
12512 ? DW_OP_const8u
: DW_OP_constu
,
12513 GET_MODE_MASK (mode
), 0);
12516 if (mask
[i
] == NULL
)
12518 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
12521 add_loc_descr (&ret
, op1
);
12522 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12523 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12524 if (GET_CODE (rtl
) == ROTATERT
)
12526 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12527 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12528 GET_MODE_BITSIZE (mode
), 0));
12530 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12531 if (mask
[0] != NULL
)
12532 add_loc_descr (&ret
, mask
[0]);
12533 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12534 if (mask
[1] != NULL
)
12536 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12537 add_loc_descr (&ret
, mask
[1]);
12538 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12540 if (GET_CODE (rtl
) == ROTATE
)
12542 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12543 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12544 GET_MODE_BITSIZE (mode
), 0));
12546 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12547 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12551 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
12552 for DEBUG_PARAMETER_REF RTL. */
12554 static dw_loc_descr_ref
12555 parameter_ref_descriptor (rtx rtl
)
12557 dw_loc_descr_ref ret
;
12562 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
12563 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
12564 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
12567 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12568 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12569 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12573 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12574 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
12579 /* The following routine converts the RTL for a variable or parameter
12580 (resident in memory) into an equivalent Dwarf representation of a
12581 mechanism for getting the address of that same variable onto the top of a
12582 hypothetical "address evaluation" stack.
12584 When creating memory location descriptors, we are effectively transforming
12585 the RTL for a memory-resident object into its Dwarf postfix expression
12586 equivalent. This routine recursively descends an RTL tree, turning
12587 it into Dwarf postfix code as it goes.
12589 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
12591 MEM_MODE is the mode of the memory reference, needed to handle some
12592 autoincrement addressing modes.
12594 Return 0 if we can't represent the location. */
12597 mem_loc_descriptor (rtx rtl
, machine_mode mode
,
12598 machine_mode mem_mode
,
12599 enum var_init_status initialized
)
12601 dw_loc_descr_ref mem_loc_result
= NULL
;
12602 enum dwarf_location_atom op
;
12603 dw_loc_descr_ref op0
, op1
;
12604 rtx inner
= NULL_RTX
;
12606 if (mode
== VOIDmode
)
12607 mode
= GET_MODE (rtl
);
12609 /* Note that for a dynamically sized array, the location we will generate a
12610 description of here will be the lowest numbered location which is
12611 actually within the array. That's *not* necessarily the same as the
12612 zeroth element of the array. */
12614 rtl
= targetm
.delegitimize_address (rtl
);
12616 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
12619 switch (GET_CODE (rtl
))
12624 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
12627 /* The case of a subreg may arise when we have a local (register)
12628 variable or a formal (register) parameter which doesn't quite fill
12629 up an entire register. For now, just assume that it is
12630 legitimate to make the Dwarf info refer to the whole register which
12631 contains the given subreg. */
12632 if (!subreg_lowpart_p (rtl
))
12634 inner
= SUBREG_REG (rtl
);
12636 if (inner
== NULL_RTX
)
12637 inner
= XEXP (rtl
, 0);
12638 if (GET_MODE_CLASS (mode
) == MODE_INT
12639 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
12640 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12641 #ifdef POINTERS_EXTEND_UNSIGNED
12642 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
12645 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
12647 mem_loc_result
= mem_loc_descriptor (inner
,
12649 mem_mode
, initialized
);
12654 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
12656 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
12657 && (GET_MODE_CLASS (mode
) != MODE_INT
12658 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
12662 dw_die_ref type_die
;
12663 dw_loc_descr_ref cvt
;
12665 mem_loc_result
= mem_loc_descriptor (inner
,
12667 mem_mode
, initialized
);
12668 if (mem_loc_result
== NULL
)
12670 type_die
= base_type_for_mode (mode
,
12671 GET_MODE_CLASS (mode
) == MODE_INT
);
12672 if (type_die
== NULL
)
12674 mem_loc_result
= NULL
;
12677 if (GET_MODE_SIZE (mode
)
12678 != GET_MODE_SIZE (GET_MODE (inner
)))
12679 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12681 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
12682 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12683 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12684 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12685 add_loc_descr (&mem_loc_result
, cvt
);
12690 if (GET_MODE_CLASS (mode
) != MODE_INT
12691 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12692 && rtl
!= arg_pointer_rtx
12693 && rtl
!= frame_pointer_rtx
12694 #ifdef POINTERS_EXTEND_UNSIGNED
12695 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12699 dw_die_ref type_die
;
12700 unsigned int dbx_regnum
;
12704 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
12706 type_die
= base_type_for_mode (mode
,
12707 GET_MODE_CLASS (mode
) == MODE_INT
);
12708 if (type_die
== NULL
)
12711 dbx_regnum
= dbx_reg_number (rtl
);
12712 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12714 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
12716 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12717 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12718 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12721 /* Whenever a register number forms a part of the description of the
12722 method for calculating the (dynamic) address of a memory resident
12723 object, DWARF rules require the register number be referred to as
12724 a "base register". This distinction is not based in any way upon
12725 what category of register the hardware believes the given register
12726 belongs to. This is strictly DWARF terminology we're dealing with
12727 here. Note that in cases where the location of a memory-resident
12728 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12729 OP_CONST (0)) the actual DWARF location descriptor that we generate
12730 may just be OP_BASEREG (basereg). This may look deceptively like
12731 the object in question was allocated to a register (rather than in
12732 memory) so DWARF consumers need to be aware of the subtle
12733 distinction between OP_REG and OP_BASEREG. */
12734 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12735 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12736 else if (stack_realign_drap
12738 && crtl
->args
.internal_arg_pointer
== rtl
12739 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12741 /* If RTL is internal_arg_pointer, which has been optimized
12742 out, use DRAP instead. */
12743 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12744 VAR_INIT_STATUS_INITIALIZED
);
12750 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12752 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12753 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12756 else if (GET_CODE (rtl
) == ZERO_EXTEND
12757 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12758 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12759 < HOST_BITS_PER_WIDE_INT
12760 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12761 to expand zero extend as two shifts instead of
12763 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12765 machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12766 mem_loc_result
= op0
;
12767 add_loc_descr (&mem_loc_result
,
12768 int_loc_descriptor (GET_MODE_MASK (imode
)));
12769 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12771 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12773 int shift
= DWARF2_ADDR_SIZE
12774 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12775 shift
*= BITS_PER_UNIT
;
12776 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12780 mem_loc_result
= op0
;
12781 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12782 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12783 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12784 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12786 else if (!dwarf_strict
)
12788 dw_die_ref type_die1
, type_die2
;
12789 dw_loc_descr_ref cvt
;
12791 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12792 GET_CODE (rtl
) == ZERO_EXTEND
);
12793 if (type_die1
== NULL
)
12795 type_die2
= base_type_for_mode (mode
, 1);
12796 if (type_die2
== NULL
)
12798 mem_loc_result
= op0
;
12799 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12800 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12801 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12802 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12803 add_loc_descr (&mem_loc_result
, cvt
);
12804 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12805 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12806 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12807 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12808 add_loc_descr (&mem_loc_result
, cvt
);
12814 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12815 if (new_rtl
!= rtl
)
12817 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12819 if (mem_loc_result
!= NULL
)
12820 return mem_loc_result
;
12823 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12824 get_address_mode (rtl
), mode
,
12825 VAR_INIT_STATUS_INITIALIZED
);
12826 if (mem_loc_result
== NULL
)
12827 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12828 if (mem_loc_result
!= NULL
)
12830 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12831 || GET_MODE_CLASS (mode
) != MODE_INT
)
12833 dw_die_ref type_die
;
12834 dw_loc_descr_ref deref
;
12839 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12840 if (type_die
== NULL
)
12842 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12843 GET_MODE_SIZE (mode
), 0);
12844 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12845 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12846 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12847 add_loc_descr (&mem_loc_result
, deref
);
12849 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12850 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12852 add_loc_descr (&mem_loc_result
,
12853 new_loc_descr (DW_OP_deref_size
,
12854 GET_MODE_SIZE (mode
), 0));
12859 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12862 /* Some ports can transform a symbol ref into a label ref, because
12863 the symbol ref is too far away and has to be dumped into a constant
12867 if ((GET_MODE_CLASS (mode
) != MODE_INT
12868 && GET_MODE_CLASS (mode
) != MODE_PARTIAL_INT
)
12869 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12870 #ifdef POINTERS_EXTEND_UNSIGNED
12871 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12875 if (GET_CODE (rtl
) == SYMBOL_REF
12876 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12878 dw_loc_descr_ref temp
;
12880 /* If this is not defined, we have no way to emit the data. */
12881 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12884 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12886 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12887 add_loc_descr (&mem_loc_result
, temp
);
12892 if (!const_ok_for_output (rtl
))
12894 if (GET_CODE (rtl
) == CONST
)
12895 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12901 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12902 vec_safe_push (used_rtx_array
, rtl
);
12908 case DEBUG_IMPLICIT_PTR
:
12909 expansion_failed (NULL_TREE
, rtl
,
12910 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12916 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12918 if (GET_MODE_CLASS (mode
) != MODE_INT
12919 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12920 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12921 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12924 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12925 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12927 op0
= one_reg_loc_descriptor (dbx_regnum
,
12928 VAR_INIT_STATUS_INITIALIZED
);
12931 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12932 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12934 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12935 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12936 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12940 gcc_unreachable ();
12943 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12944 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12945 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12948 case DEBUG_PARAMETER_REF
:
12949 mem_loc_result
= parameter_ref_descriptor (rtl
);
12953 /* Extract the PLUS expression nested inside and fall into
12954 PLUS code below. */
12955 rtl
= XEXP (rtl
, 1);
12960 /* Turn these into a PLUS expression and fall into the PLUS code
12962 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12963 gen_int_mode (GET_CODE (rtl
) == PRE_INC
12964 ? GET_MODE_UNIT_SIZE (mem_mode
)
12965 : -GET_MODE_UNIT_SIZE (mem_mode
),
12968 /* ... fall through ... */
12972 if (is_based_loc (rtl
)
12973 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12974 || XEXP (rtl
, 0) == arg_pointer_rtx
12975 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12976 && GET_MODE_CLASS (mode
) == MODE_INT
)
12977 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12978 INTVAL (XEXP (rtl
, 1)),
12979 VAR_INIT_STATUS_INITIALIZED
);
12982 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12983 VAR_INIT_STATUS_INITIALIZED
);
12984 if (mem_loc_result
== 0)
12987 if (CONST_INT_P (XEXP (rtl
, 1))
12988 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12989 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12992 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12993 VAR_INIT_STATUS_INITIALIZED
);
12996 add_loc_descr (&mem_loc_result
, op1
);
12997 add_loc_descr (&mem_loc_result
,
12998 new_loc_descr (DW_OP_plus
, 0, 0));
13003 /* If a pseudo-reg is optimized away, it is possible for it to
13004 be replaced with a MEM containing a multiply or shift. */
13015 && GET_MODE_CLASS (mode
) == MODE_INT
13016 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
13018 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
13019 base_type_for_mode (mode
, 0),
13043 if (GET_MODE_CLASS (mode
) != MODE_INT
)
13045 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13046 VAR_INIT_STATUS_INITIALIZED
);
13048 rtx rtlop1
= XEXP (rtl
, 1);
13049 if (GET_MODE (rtlop1
) != VOIDmode
13050 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
13051 < GET_MODE_BITSIZE (mode
))
13052 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
13053 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
13054 VAR_INIT_STATUS_INITIALIZED
);
13057 if (op0
== 0 || op1
== 0)
13060 mem_loc_result
= op0
;
13061 add_loc_descr (&mem_loc_result
, op1
);
13062 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13078 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13079 VAR_INIT_STATUS_INITIALIZED
);
13080 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13081 VAR_INIT_STATUS_INITIALIZED
);
13083 if (op0
== 0 || op1
== 0)
13086 mem_loc_result
= op0
;
13087 add_loc_descr (&mem_loc_result
, op1
);
13088 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13092 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
13094 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
13095 base_type_for_mode (mode
, 0),
13100 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13101 VAR_INIT_STATUS_INITIALIZED
);
13102 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13103 VAR_INIT_STATUS_INITIALIZED
);
13105 if (op0
== 0 || op1
== 0)
13108 mem_loc_result
= op0
;
13109 add_loc_descr (&mem_loc_result
, op1
);
13110 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13111 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13112 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
13113 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
13114 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
13118 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
13120 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
13125 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
13126 base_type_for_mode (mode
, 1),
13144 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13145 VAR_INIT_STATUS_INITIALIZED
);
13150 mem_loc_result
= op0
;
13151 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13155 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13156 #ifdef POINTERS_EXTEND_UNSIGNED
13158 && mem_mode
!= VOIDmode
13159 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
13163 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
13167 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
13168 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
13170 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
13171 machine_mode amode
;
13172 if (type_die
== NULL
)
13174 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
13176 if (INTVAL (rtl
) >= 0
13177 && amode
!= BLKmode
13178 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
13179 /* const DW_OP_GNU_convert <XXX> vs.
13180 DW_OP_GNU_const_type <XXX, 1, const>. */
13181 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
13182 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
13184 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
13185 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13186 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13187 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13188 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13189 add_loc_descr (&mem_loc_result
, op0
);
13190 return mem_loc_result
;
13192 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
13194 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13195 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13196 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13197 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
13198 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13201 mem_loc_result
->dw_loc_oprnd2
.val_class
13202 = dw_val_class_const_double
;
13203 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
13204 = double_int::from_shwi (INTVAL (rtl
));
13212 dw_die_ref type_die
;
13214 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
13215 CONST_DOUBLE rtx could represent either a large integer
13216 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
13217 the value is always a floating point constant.
13219 When it is an integer, a CONST_DOUBLE is used whenever
13220 the constant requires 2 HWIs to be adequately represented.
13221 We output CONST_DOUBLEs as blocks. */
13222 if (mode
== VOIDmode
13223 || (GET_MODE (rtl
) == VOIDmode
13224 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
13226 type_die
= base_type_for_mode (mode
,
13227 GET_MODE_CLASS (mode
) == MODE_INT
);
13228 if (type_die
== NULL
)
13230 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
13231 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13232 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13233 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13234 #if TARGET_SUPPORTS_WIDE_INT == 0
13235 if (!SCALAR_FLOAT_MODE_P (mode
))
13237 mem_loc_result
->dw_loc_oprnd2
.val_class
13238 = dw_val_class_const_double
;
13239 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
13240 = rtx_to_double_int (rtl
);
13245 unsigned int length
= GET_MODE_SIZE (mode
);
13246 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
13248 insert_float (rtl
, array
);
13249 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13250 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13251 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13252 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13257 case CONST_WIDE_INT
:
13260 dw_die_ref type_die
;
13262 type_die
= base_type_for_mode (mode
,
13263 GET_MODE_CLASS (mode
) == MODE_INT
);
13264 if (type_die
== NULL
)
13266 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
13267 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13268 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13269 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13270 mem_loc_result
->dw_loc_oprnd2
.val_class
13271 = dw_val_class_wide_int
;
13272 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
13273 *mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
13278 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
13282 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
13286 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
13290 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
13294 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
13298 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
13302 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
13306 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
13310 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
13314 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
13319 if (GET_MODE_CLASS (mode
) != MODE_INT
)
13324 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
13329 if (CONST_INT_P (XEXP (rtl
, 1))
13330 && CONST_INT_P (XEXP (rtl
, 2))
13331 && ((unsigned) INTVAL (XEXP (rtl
, 1))
13332 + (unsigned) INTVAL (XEXP (rtl
, 2))
13333 <= GET_MODE_BITSIZE (mode
))
13334 && GET_MODE_CLASS (mode
) == MODE_INT
13335 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13336 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
13339 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13340 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13343 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
13347 mem_loc_result
= op0
;
13348 size
= INTVAL (XEXP (rtl
, 1));
13349 shift
= INTVAL (XEXP (rtl
, 2));
13350 if (BITS_BIG_ENDIAN
)
13351 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
13353 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
13355 add_loc_descr (&mem_loc_result
,
13356 int_loc_descriptor (DWARF2_ADDR_SIZE
13358 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
13360 if (size
!= (int) DWARF2_ADDR_SIZE
)
13362 add_loc_descr (&mem_loc_result
,
13363 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
13364 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13371 dw_loc_descr_ref op2
, bra_node
, drop_node
;
13372 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
13373 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
13374 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
13375 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13376 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13377 VAR_INIT_STATUS_INITIALIZED
);
13378 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
13379 VAR_INIT_STATUS_INITIALIZED
);
13380 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
13383 mem_loc_result
= op1
;
13384 add_loc_descr (&mem_loc_result
, op2
);
13385 add_loc_descr (&mem_loc_result
, op0
);
13386 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13387 add_loc_descr (&mem_loc_result
, bra_node
);
13388 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
13389 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
13390 add_loc_descr (&mem_loc_result
, drop_node
);
13391 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13392 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
13397 case FLOAT_TRUNCATE
:
13399 case UNSIGNED_FLOAT
:
13404 dw_die_ref type_die
;
13405 dw_loc_descr_ref cvt
;
13407 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13408 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13411 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
13412 && (GET_CODE (rtl
) == FLOAT
13413 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
13414 <= DWARF2_ADDR_SIZE
))
13416 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
13417 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
13418 if (type_die
== NULL
)
13420 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13421 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13422 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13423 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13424 add_loc_descr (&op0
, cvt
);
13426 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
13427 if (type_die
== NULL
)
13429 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13430 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13431 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13432 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13433 add_loc_descr (&op0
, cvt
);
13434 if (GET_MODE_CLASS (mode
) == MODE_INT
13435 && (GET_CODE (rtl
) == FIX
13436 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
13438 op0
= convert_descriptor_to_mode (mode
, op0
);
13442 mem_loc_result
= op0
;
13449 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
13454 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
13458 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
13463 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
13467 /* In theory, we could implement the above. */
13468 /* DWARF cannot represent the unsigned compare operations
13493 case FRACT_CONVERT
:
13494 case UNSIGNED_FRACT_CONVERT
:
13496 case UNSIGNED_SAT_FRACT
:
13502 case VEC_DUPLICATE
:
13506 case STRICT_LOW_PART
:
13511 /* If delegitimize_address couldn't do anything with the UNSPEC, we
13512 can't express it in the debug info. This can happen e.g. with some
13517 resolve_one_addr (&rtl
);
13521 #ifdef ENABLE_CHECKING
13522 print_rtl (stderr
, rtl
);
13523 gcc_unreachable ();
13529 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13530 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13532 return mem_loc_result
;
13535 /* Return a descriptor that describes the concatenation of two locations.
13536 This is typically a complex variable. */
13538 static dw_loc_descr_ref
13539 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
13541 dw_loc_descr_ref cc_loc_result
= NULL
;
13542 dw_loc_descr_ref x0_ref
13543 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13544 dw_loc_descr_ref x1_ref
13545 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13547 if (x0_ref
== 0 || x1_ref
== 0)
13550 cc_loc_result
= x0_ref
;
13551 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
13553 add_loc_descr (&cc_loc_result
, x1_ref
);
13554 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
13556 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13557 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13559 return cc_loc_result
;
13562 /* Return a descriptor that describes the concatenation of N
13565 static dw_loc_descr_ref
13566 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
13569 dw_loc_descr_ref cc_loc_result
= NULL
;
13570 unsigned int n
= XVECLEN (concatn
, 0);
13572 for (i
= 0; i
< n
; ++i
)
13574 dw_loc_descr_ref ref
;
13575 rtx x
= XVECEXP (concatn
, 0, i
);
13577 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13581 add_loc_descr (&cc_loc_result
, ref
);
13582 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
13585 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13586 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13588 return cc_loc_result
;
13591 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
13592 for DEBUG_IMPLICIT_PTR RTL. */
13594 static dw_loc_descr_ref
13595 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
13597 dw_loc_descr_ref ret
;
13602 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
13603 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
13604 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
13605 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
13606 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
13607 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13610 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13611 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
13612 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13616 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
13617 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
13622 /* Output a proper Dwarf location descriptor for a variable or parameter
13623 which is either allocated in a register or in a memory location. For a
13624 register, we just generate an OP_REG and the register number. For a
13625 memory location we provide a Dwarf postfix expression describing how to
13626 generate the (dynamic) address of the object onto the address stack.
13628 MODE is mode of the decl if this loc_descriptor is going to be used in
13629 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
13630 allowed, VOIDmode otherwise.
13632 If we don't know how to describe it, return 0. */
13634 static dw_loc_descr_ref
13635 loc_descriptor (rtx rtl
, machine_mode mode
,
13636 enum var_init_status initialized
)
13638 dw_loc_descr_ref loc_result
= NULL
;
13640 switch (GET_CODE (rtl
))
13643 /* The case of a subreg may arise when we have a local (register)
13644 variable or a formal (register) parameter which doesn't quite fill
13645 up an entire register. For now, just assume that it is
13646 legitimate to make the Dwarf info refer to the whole register which
13647 contains the given subreg. */
13648 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
13649 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
13650 GET_MODE (SUBREG_REG (rtl
)), initialized
);
13656 loc_result
= reg_loc_descriptor (rtl
, initialized
);
13660 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13661 GET_MODE (rtl
), initialized
);
13662 if (loc_result
== NULL
)
13663 loc_result
= tls_mem_loc_descriptor (rtl
);
13664 if (loc_result
== NULL
)
13666 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13667 if (new_rtl
!= rtl
)
13668 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
13673 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
13678 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
13683 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
13685 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
13686 if (GET_CODE (loc
) == EXPR_LIST
)
13687 loc
= XEXP (loc
, 0);
13688 loc_result
= loc_descriptor (loc
, mode
, initialized
);
13692 rtl
= XEXP (rtl
, 1);
13697 rtvec par_elems
= XVEC (rtl
, 0);
13698 int num_elem
= GET_NUM_ELEM (par_elems
);
13702 /* Create the first one, so we have something to add to. */
13703 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
13704 VOIDmode
, initialized
);
13705 if (loc_result
== NULL
)
13707 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
13708 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13709 for (i
= 1; i
< num_elem
; i
++)
13711 dw_loc_descr_ref temp
;
13713 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
13714 VOIDmode
, initialized
);
13717 add_loc_descr (&loc_result
, temp
);
13718 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
13719 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13725 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
13726 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
13731 if (mode
== VOIDmode
)
13732 mode
= GET_MODE (rtl
);
13734 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13736 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13738 /* Note that a CONST_DOUBLE rtx could represent either an integer
13739 or a floating-point constant. A CONST_DOUBLE is used whenever
13740 the constant requires more than one word in order to be
13741 adequately represented. We output CONST_DOUBLEs as blocks. */
13742 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13743 GET_MODE_SIZE (mode
), 0);
13744 #if TARGET_SUPPORTS_WIDE_INT == 0
13745 if (!SCALAR_FLOAT_MODE_P (mode
))
13747 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
13748 loc_result
->dw_loc_oprnd2
.v
.val_double
13749 = rtx_to_double_int (rtl
);
13754 unsigned int length
= GET_MODE_SIZE (mode
);
13755 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
13757 insert_float (rtl
, array
);
13758 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13759 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13760 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13761 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13766 case CONST_WIDE_INT
:
13767 if (mode
== VOIDmode
)
13768 mode
= GET_MODE (rtl
);
13770 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13772 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13773 GET_MODE_SIZE (mode
), 0);
13774 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
13775 loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
13776 *loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
13781 if (mode
== VOIDmode
)
13782 mode
= GET_MODE (rtl
);
13784 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13786 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13787 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13788 unsigned char *array
13789 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
13792 machine_mode imode
= GET_MODE_INNER (mode
);
13794 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13795 switch (GET_MODE_CLASS (mode
))
13797 case MODE_VECTOR_INT
:
13798 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13800 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13801 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
13805 case MODE_VECTOR_FLOAT
:
13806 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13808 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13809 insert_float (elt
, p
);
13814 gcc_unreachable ();
13817 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13818 length
* elt_size
, 0);
13819 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13820 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13821 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13822 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13827 if (mode
== VOIDmode
13828 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13829 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13830 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13832 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13837 if (!const_ok_for_output (rtl
))
13840 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13841 && (dwarf_version
>= 4 || !dwarf_strict
))
13843 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13844 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13845 vec_safe_push (used_rtx_array
, rtl
);
13849 case DEBUG_IMPLICIT_PTR
:
13850 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13854 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13855 && CONST_INT_P (XEXP (rtl
, 1)))
13858 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13864 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13865 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13866 && dwarf_version
>= 4)
13867 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13869 /* Value expression. */
13870 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13872 add_loc_descr (&loc_result
,
13873 new_loc_descr (DW_OP_stack_value
, 0, 0));
13881 /* We need to figure out what section we should use as the base for the
13882 address ranges where a given location is valid.
13883 1. If this particular DECL has a section associated with it, use that.
13884 2. If this function has a section associated with it, use that.
13885 3. Otherwise, use the text section.
13886 XXX: If you split a variable across multiple sections, we won't notice. */
13888 static const char *
13889 secname_for_decl (const_tree decl
)
13891 const char *secname
;
13893 if (VAR_OR_FUNCTION_DECL_P (decl
)
13894 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
) || TREE_STATIC (decl
))
13895 && DECL_SECTION_NAME (decl
))
13896 secname
= DECL_SECTION_NAME (decl
);
13897 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13898 secname
= DECL_SECTION_NAME (current_function_decl
);
13899 else if (cfun
&& in_cold_section_p
)
13900 secname
= crtl
->subsections
.cold_section_label
;
13902 secname
= text_section_label
;
13907 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13910 decl_by_reference_p (tree decl
)
13912 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13913 || TREE_CODE (decl
) == VAR_DECL
)
13914 && DECL_BY_REFERENCE (decl
));
13917 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13920 static dw_loc_descr_ref
13921 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13922 enum var_init_status initialized
)
13924 int have_address
= 0;
13925 dw_loc_descr_ref descr
;
13928 if (want_address
!= 2)
13930 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13932 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13934 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13935 if (GET_CODE (varloc
) == EXPR_LIST
)
13936 varloc
= XEXP (varloc
, 0);
13937 mode
= GET_MODE (varloc
);
13938 if (MEM_P (varloc
))
13940 rtx addr
= XEXP (varloc
, 0);
13941 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13942 mode
, initialized
);
13947 rtx x
= avoid_constant_pool_reference (varloc
);
13949 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13954 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13961 if (GET_CODE (varloc
) == VAR_LOCATION
)
13962 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13964 mode
= DECL_MODE (loc
);
13965 descr
= loc_descriptor (varloc
, mode
, initialized
);
13972 if (want_address
== 2 && !have_address
13973 && (dwarf_version
>= 4 || !dwarf_strict
))
13975 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13977 expansion_failed (loc
, NULL_RTX
,
13978 "DWARF address size mismatch");
13981 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13984 /* Show if we can't fill the request for an address. */
13985 if (want_address
&& !have_address
)
13987 expansion_failed (loc
, NULL_RTX
,
13988 "Want address and only have value");
13992 /* If we've got an address and don't want one, dereference. */
13993 if (!want_address
&& have_address
)
13995 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13996 enum dwarf_location_atom op
;
13998 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14000 expansion_failed (loc
, NULL_RTX
,
14001 "DWARF address size mismatch");
14004 else if (size
== DWARF2_ADDR_SIZE
)
14007 op
= DW_OP_deref_size
;
14009 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
14015 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14016 if it is not possible. */
14018 static dw_loc_descr_ref
14019 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
14021 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
14022 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
14023 else if (dwarf_version
>= 3 || !dwarf_strict
)
14024 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
14029 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14030 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14032 static dw_loc_descr_ref
14033 dw_sra_loc_expr (tree decl
, rtx loc
)
14036 unsigned HOST_WIDE_INT padsize
= 0;
14037 dw_loc_descr_ref descr
, *descr_tail
;
14038 unsigned HOST_WIDE_INT decl_size
;
14040 enum var_init_status initialized
;
14042 if (DECL_SIZE (decl
) == NULL
14043 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
14046 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
14048 descr_tail
= &descr
;
14050 for (p
= loc
; p
; p
= XEXP (p
, 1))
14052 unsigned HOST_WIDE_INT bitsize
= decl_piece_bitsize (p
);
14053 rtx loc_note
= *decl_piece_varloc_ptr (p
);
14054 dw_loc_descr_ref cur_descr
;
14055 dw_loc_descr_ref
*tail
, last
= NULL
;
14056 unsigned HOST_WIDE_INT opsize
= 0;
14058 if (loc_note
== NULL_RTX
14059 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
14061 padsize
+= bitsize
;
14064 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
14065 varloc
= NOTE_VAR_LOCATION (loc_note
);
14066 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
14067 if (cur_descr
== NULL
)
14069 padsize
+= bitsize
;
14073 /* Check that cur_descr either doesn't use
14074 DW_OP_*piece operations, or their sum is equal
14075 to bitsize. Otherwise we can't embed it. */
14076 for (tail
= &cur_descr
; *tail
!= NULL
;
14077 tail
= &(*tail
)->dw_loc_next
)
14078 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
14080 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
14084 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
14086 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
14090 if (last
!= NULL
&& opsize
!= bitsize
)
14092 padsize
+= bitsize
;
14093 /* Discard the current piece of the descriptor and release any
14094 addr_table entries it uses. */
14095 remove_loc_list_addr_table_entries (cur_descr
);
14099 /* If there is a hole, add DW_OP_*piece after empty DWARF
14100 expression, which means that those bits are optimized out. */
14103 if (padsize
> decl_size
)
14105 remove_loc_list_addr_table_entries (cur_descr
);
14106 goto discard_descr
;
14108 decl_size
-= padsize
;
14109 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
14110 if (*descr_tail
== NULL
)
14112 remove_loc_list_addr_table_entries (cur_descr
);
14113 goto discard_descr
;
14115 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14118 *descr_tail
= cur_descr
;
14120 if (bitsize
> decl_size
)
14121 goto discard_descr
;
14122 decl_size
-= bitsize
;
14125 HOST_WIDE_INT offset
= 0;
14126 if (GET_CODE (varloc
) == VAR_LOCATION
14127 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
14129 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
14130 if (GET_CODE (varloc
) == EXPR_LIST
)
14131 varloc
= XEXP (varloc
, 0);
14135 if (GET_CODE (varloc
) == CONST
14136 || GET_CODE (varloc
) == SIGN_EXTEND
14137 || GET_CODE (varloc
) == ZERO_EXTEND
)
14138 varloc
= XEXP (varloc
, 0);
14139 else if (GET_CODE (varloc
) == SUBREG
)
14140 varloc
= SUBREG_REG (varloc
);
14145 /* DW_OP_bit_size offset should be zero for register
14146 or implicit location descriptions and empty location
14147 descriptions, but for memory addresses needs big endian
14149 if (MEM_P (varloc
))
14151 unsigned HOST_WIDE_INT memsize
14152 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
14153 if (memsize
!= bitsize
)
14155 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
14156 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
14157 goto discard_descr
;
14158 if (memsize
< bitsize
)
14159 goto discard_descr
;
14160 if (BITS_BIG_ENDIAN
)
14161 offset
= memsize
- bitsize
;
14165 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
14166 if (*descr_tail
== NULL
)
14167 goto discard_descr
;
14168 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14172 /* If there were any non-empty expressions, add padding till the end of
14174 if (descr
!= NULL
&& decl_size
!= 0)
14176 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
14177 if (*descr_tail
== NULL
)
14178 goto discard_descr
;
14183 /* Discard the descriptor and release any addr_table entries it uses. */
14184 remove_loc_list_addr_table_entries (descr
);
14188 /* Return the dwarf representation of the location list LOC_LIST of
14189 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
14192 static dw_loc_list_ref
14193 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
14195 const char *endname
, *secname
;
14197 enum var_init_status initialized
;
14198 struct var_loc_node
*node
;
14199 dw_loc_descr_ref descr
;
14200 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
14201 dw_loc_list_ref list
= NULL
;
14202 dw_loc_list_ref
*listp
= &list
;
14204 /* Now that we know what section we are using for a base,
14205 actually construct the list of locations.
14206 The first location information is what is passed to the
14207 function that creates the location list, and the remaining
14208 locations just get added on to that list.
14209 Note that we only know the start address for a location
14210 (IE location changes), so to build the range, we use
14211 the range [current location start, next location start].
14212 This means we have to special case the last node, and generate
14213 a range of [last location start, end of function label]. */
14215 secname
= secname_for_decl (decl
);
14217 for (node
= loc_list
->first
; node
; node
= node
->next
)
14218 if (GET_CODE (node
->loc
) == EXPR_LIST
14219 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
14221 if (GET_CODE (node
->loc
) == EXPR_LIST
)
14223 /* This requires DW_OP_{,bit_}piece, which is not usable
14224 inside DWARF expressions. */
14225 if (want_address
!= 2)
14227 descr
= dw_sra_loc_expr (decl
, node
->loc
);
14233 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
14234 varloc
= NOTE_VAR_LOCATION (node
->loc
);
14235 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
14239 bool range_across_switch
= false;
14240 /* If section switch happens in between node->label
14241 and node->next->label (or end of function) and
14242 we can't emit it as a single entry list,
14243 emit two ranges, first one ending at the end
14244 of first partition and second one starting at the
14245 beginning of second partition. */
14246 if (node
== loc_list
->last_before_switch
14247 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
14248 && current_function_decl
)
14250 endname
= cfun
->fde
->dw_fde_end
;
14251 range_across_switch
= true;
14253 /* The variable has a location between NODE->LABEL and
14254 NODE->NEXT->LABEL. */
14255 else if (node
->next
)
14256 endname
= node
->next
->label
;
14257 /* If the variable has a location at the last label
14258 it keeps its location until the end of function. */
14259 else if (!current_function_decl
)
14260 endname
= text_end_label
;
14263 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
14264 current_function_funcdef_no
);
14265 endname
= ggc_strdup (label_id
);
14268 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
14269 if (TREE_CODE (decl
) == PARM_DECL
14270 && node
== loc_list
->first
14271 && NOTE_P (node
->loc
)
14272 && strcmp (node
->label
, endname
) == 0)
14273 (*listp
)->force
= true;
14274 listp
= &(*listp
)->dw_loc_next
;
14276 if (range_across_switch
)
14278 if (GET_CODE (node
->loc
) == EXPR_LIST
)
14279 descr
= dw_sra_loc_expr (decl
, node
->loc
);
14282 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
14283 varloc
= NOTE_VAR_LOCATION (node
->loc
);
14284 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
14287 gcc_assert (descr
);
14288 /* The variable has a location between NODE->LABEL and
14289 NODE->NEXT->LABEL. */
14291 endname
= node
->next
->label
;
14293 endname
= cfun
->fde
->dw_fde_second_end
;
14294 *listp
= new_loc_list (descr
,
14295 cfun
->fde
->dw_fde_second_begin
,
14297 listp
= &(*listp
)->dw_loc_next
;
14302 /* Try to avoid the overhead of a location list emitting a location
14303 expression instead, but only if we didn't have more than one
14304 location entry in the first place. If some entries were not
14305 representable, we don't want to pretend a single entry that was
14306 applies to the entire scope in which the variable is
14308 if (list
&& loc_list
->first
->next
)
14314 /* Return if the loc_list has only single element and thus can be represented
14315 as location description. */
14318 single_element_loc_list_p (dw_loc_list_ref list
)
14320 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
14321 return !list
->ll_symbol
;
14324 /* To each location in list LIST add loc descr REF. */
14327 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
14329 dw_loc_descr_ref copy
;
14330 add_loc_descr (&list
->expr
, ref
);
14331 list
= list
->dw_loc_next
;
14334 copy
= ggc_alloc
<dw_loc_descr_node
> ();
14335 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
14336 add_loc_descr (&list
->expr
, copy
);
14337 while (copy
->dw_loc_next
)
14339 dw_loc_descr_ref new_copy
= ggc_alloc
<dw_loc_descr_node
> ();
14340 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
14341 copy
->dw_loc_next
= new_copy
;
14344 list
= list
->dw_loc_next
;
14348 /* Given two lists RET and LIST
14349 produce location list that is result of adding expression in LIST
14350 to expression in RET on each position in program.
14351 Might be destructive on both RET and LIST.
14353 TODO: We handle only simple cases of RET or LIST having at most one
14354 element. General case would inolve sorting the lists in program order
14355 and merging them that will need some additional work.
14356 Adding that will improve quality of debug info especially for SRA-ed
14360 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
14369 if (!list
->dw_loc_next
)
14371 add_loc_descr_to_each (*ret
, list
->expr
);
14374 if (!(*ret
)->dw_loc_next
)
14376 add_loc_descr_to_each (list
, (*ret
)->expr
);
14380 expansion_failed (NULL_TREE
, NULL_RTX
,
14381 "Don't know how to merge two non-trivial"
14382 " location lists.\n");
14387 /* LOC is constant expression. Try a luck, look it up in constant
14388 pool and return its loc_descr of its address. */
14390 static dw_loc_descr_ref
14391 cst_pool_loc_descr (tree loc
)
14393 /* Get an RTL for this, if something has been emitted. */
14394 rtx rtl
= lookup_constant_def (loc
);
14396 if (!rtl
|| !MEM_P (rtl
))
14401 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
14403 /* TODO: We might get more coverage if we was actually delaying expansion
14404 of all expressions till end of compilation when constant pools are fully
14406 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
14408 expansion_failed (loc
, NULL_RTX
,
14409 "CST value in contant pool but not marked.");
14412 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
14413 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
14416 /* Return dw_loc_list representing address of addr_expr LOC
14417 by looking for inner INDIRECT_REF expression and turning
14418 it into simple arithmetics.
14420 See loc_list_from_tree for the meaning of CONTEXT. */
14422 static dw_loc_list_ref
14423 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
,
14424 const loc_descr_context
*context
)
14427 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14429 int unsignedp
, volatilep
= 0;
14430 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14432 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
14433 &bitsize
, &bitpos
, &offset
, &mode
,
14434 &unsignedp
, &volatilep
, false);
14436 if (bitpos
% BITS_PER_UNIT
)
14438 expansion_failed (loc
, NULL_RTX
, "bitfield access");
14441 if (!INDIRECT_REF_P (obj
))
14443 expansion_failed (obj
,
14444 NULL_RTX
, "no indirect ref in inner refrence");
14447 if (!offset
&& !bitpos
)
14448 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1,
14451 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
14452 && (dwarf_version
>= 4 || !dwarf_strict
))
14454 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0, context
);
14459 /* Variable offset. */
14460 list_ret1
= loc_list_from_tree (offset
, 0, context
);
14461 if (list_ret1
== 0)
14463 add_loc_list (&list_ret
, list_ret1
);
14466 add_loc_descr_to_each (list_ret
,
14467 new_loc_descr (DW_OP_plus
, 0, 0));
14469 bytepos
= bitpos
/ BITS_PER_UNIT
;
14471 add_loc_descr_to_each (list_ret
,
14472 new_loc_descr (DW_OP_plus_uconst
,
14474 else if (bytepos
< 0)
14475 loc_list_plus_const (list_ret
, bytepos
);
14476 add_loc_descr_to_each (list_ret
,
14477 new_loc_descr (DW_OP_stack_value
, 0, 0));
14483 /* Helper structure for location descriptions generation. */
14484 struct loc_descr_context
14486 /* The type that is implicitly referenced by DW_OP_push_object_address, or
14487 NULL_TREE if DW_OP_push_object_address in invalid for this location
14488 description. This is used when processing PLACEHOLDER_EXPR nodes. */
14490 /* The ..._DECL node that should be translated as a
14491 DW_OP_push_object_address operation. */
14495 /* Generate Dwarf location list representing LOC.
14496 If WANT_ADDRESS is false, expression computing LOC will be computed
14497 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
14498 if WANT_ADDRESS is 2, expression computing address useable in location
14499 will be returned (i.e. DW_OP_reg can be used
14500 to refer to register values).
14502 CONTEXT provides information to customize the location descriptions
14503 generation. Its context_type field specifies what type is implicitly
14504 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
14505 will not be generated.
14507 If CONTEXT is NULL, the behavior is the same as if both context_type and
14508 base_decl fields were NULL_TREE. */
14510 static dw_loc_list_ref
14511 loc_list_from_tree (tree loc
, int want_address
,
14512 const struct loc_descr_context
*context
)
14514 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
14515 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14516 int have_address
= 0;
14517 enum dwarf_location_atom op
;
14519 /* ??? Most of the time we do not take proper care for sign/zero
14520 extending the values properly. Hopefully this won't be a real
14523 if (context
!= NULL
14524 && context
->base_decl
== loc
14525 && want_address
== 0)
14527 if (dwarf_version
>= 3 || !dwarf_strict
)
14528 return new_loc_list (new_loc_descr (DW_OP_push_object_address
, 0, 0),
14534 switch (TREE_CODE (loc
))
14537 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
14540 case PLACEHOLDER_EXPR
:
14541 /* This case involves extracting fields from an object to determine the
14542 position of other fields. It is supposed to appear only as the first
14543 operand of COMPONENT_REF nodes and to reference precisely the type
14544 that the context allows. */
14545 if (context
!= NULL
14546 && TREE_TYPE (loc
) == context
->context_type
14547 && want_address
>= 1)
14549 if (dwarf_version
>= 3 || !dwarf_strict
)
14551 ret
= new_loc_descr (DW_OP_push_object_address
, 0, 0);
14559 expansion_failed (loc
, NULL_RTX
,
14560 "PLACEHOLDER_EXPR for an unexpected type");
14564 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
14565 /* There are no opcodes for these operations. */
14568 case PREINCREMENT_EXPR
:
14569 case PREDECREMENT_EXPR
:
14570 case POSTINCREMENT_EXPR
:
14571 case POSTDECREMENT_EXPR
:
14572 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
14573 /* There are no opcodes for these operations. */
14577 /* If we already want an address, see if there is INDIRECT_REF inside
14578 e.g. for &this->field. */
14581 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
14582 (loc
, want_address
== 2, context
);
14585 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
14586 && (ret
= cst_pool_loc_descr (loc
)))
14589 /* Otherwise, process the argument and look for the address. */
14590 if (!list_ret
&& !ret
)
14591 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1, context
);
14595 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
14601 if (DECL_THREAD_LOCAL_P (loc
))
14604 enum dwarf_location_atom tls_op
;
14605 enum dtprel_bool dtprel
= dtprel_false
;
14607 if (targetm
.have_tls
)
14609 /* If this is not defined, we have no way to emit the
14611 if (!targetm
.asm_out
.output_dwarf_dtprel
)
14614 /* The way DW_OP_GNU_push_tls_address is specified, we
14615 can only look up addresses of objects in the current
14616 module. We used DW_OP_addr as first op, but that's
14617 wrong, because DW_OP_addr is relocated by the debug
14618 info consumer, while DW_OP_GNU_push_tls_address
14619 operand shouldn't be. */
14620 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
14622 dtprel
= dtprel_true
;
14623 tls_op
= DW_OP_GNU_push_tls_address
;
14627 if (!targetm
.emutls
.debug_form_tls_address
14628 || !(dwarf_version
>= 3 || !dwarf_strict
))
14630 /* We stuffed the control variable into the DECL_VALUE_EXPR
14631 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
14632 no longer appear in gimple code. We used the control
14633 variable in specific so that we could pick it up here. */
14634 loc
= DECL_VALUE_EXPR (loc
);
14635 tls_op
= DW_OP_form_tls_address
;
14638 rtl
= rtl_for_decl_location (loc
);
14639 if (rtl
== NULL_RTX
)
14644 rtl
= XEXP (rtl
, 0);
14645 if (! CONSTANT_P (rtl
))
14648 ret
= new_addr_loc_descr (rtl
, dtprel
);
14649 ret1
= new_loc_descr (tls_op
, 0, 0);
14650 add_loc_descr (&ret
, ret1
);
14659 if (DECL_HAS_VALUE_EXPR_P (loc
))
14660 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
14661 want_address
, context
);
14664 case FUNCTION_DECL
:
14667 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
14669 if (loc_list
&& loc_list
->first
)
14671 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
14672 have_address
= want_address
!= 0;
14675 rtl
= rtl_for_decl_location (loc
);
14676 if (rtl
== NULL_RTX
)
14678 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
14681 else if (CONST_INT_P (rtl
))
14683 HOST_WIDE_INT val
= INTVAL (rtl
);
14684 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14685 val
&= GET_MODE_MASK (DECL_MODE (loc
));
14686 ret
= int_loc_descriptor (val
);
14688 else if (GET_CODE (rtl
) == CONST_STRING
)
14690 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
14693 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
14694 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
14697 machine_mode mode
, mem_mode
;
14699 /* Certain constructs can only be represented at top-level. */
14700 if (want_address
== 2)
14702 ret
= loc_descriptor (rtl
, VOIDmode
,
14703 VAR_INIT_STATUS_INITIALIZED
);
14708 mode
= GET_MODE (rtl
);
14709 mem_mode
= VOIDmode
;
14713 mode
= get_address_mode (rtl
);
14714 rtl
= XEXP (rtl
, 0);
14717 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
14718 VAR_INIT_STATUS_INITIALIZED
);
14721 expansion_failed (loc
, rtl
,
14722 "failed to produce loc descriptor for rtl");
14728 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
14735 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14739 case TARGET_MEM_REF
:
14741 case DEBUG_EXPR_DECL
:
14744 case COMPOUND_EXPR
:
14745 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
, context
);
14748 case VIEW_CONVERT_EXPR
:
14751 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
, context
);
14753 case COMPONENT_REF
:
14754 case BIT_FIELD_REF
:
14756 case ARRAY_RANGE_REF
:
14757 case REALPART_EXPR
:
14758 case IMAGPART_EXPR
:
14761 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14763 int unsignedp
, volatilep
= 0;
14765 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
14766 &unsignedp
, &volatilep
, false);
14768 gcc_assert (obj
!= loc
);
14770 list_ret
= loc_list_from_tree (obj
,
14772 && !bitpos
&& !offset
? 2 : 1,
14774 /* TODO: We can extract value of the small expression via shifting even
14775 for nonzero bitpos. */
14778 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
14780 expansion_failed (loc
, NULL_RTX
,
14781 "bitfield access");
14785 if (offset
!= NULL_TREE
)
14787 /* Variable offset. */
14788 list_ret1
= loc_list_from_tree (offset
, 0, context
);
14789 if (list_ret1
== 0)
14791 add_loc_list (&list_ret
, list_ret1
);
14794 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14797 bytepos
= bitpos
/ BITS_PER_UNIT
;
14799 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
14800 else if (bytepos
< 0)
14801 loc_list_plus_const (list_ret
, bytepos
);
14808 if ((want_address
|| !tree_fits_shwi_p (loc
))
14809 && (ret
= cst_pool_loc_descr (loc
)))
14811 else if (want_address
== 2
14812 && tree_fits_shwi_p (loc
)
14813 && (ret
= address_of_int_loc_descriptor
14814 (int_size_in_bytes (TREE_TYPE (loc
)),
14815 tree_to_shwi (loc
))))
14817 else if (tree_fits_shwi_p (loc
))
14818 ret
= int_loc_descriptor (tree_to_shwi (loc
));
14821 expansion_failed (loc
, NULL_RTX
,
14822 "Integer operand is not host integer");
14831 if ((ret
= cst_pool_loc_descr (loc
)))
14834 /* We can construct small constants here using int_loc_descriptor. */
14835 expansion_failed (loc
, NULL_RTX
,
14836 "constructor or constant not in constant pool");
14839 case TRUTH_AND_EXPR
:
14840 case TRUTH_ANDIF_EXPR
:
14845 case TRUTH_XOR_EXPR
:
14850 case TRUTH_OR_EXPR
:
14851 case TRUTH_ORIF_EXPR
:
14856 case FLOOR_DIV_EXPR
:
14857 case CEIL_DIV_EXPR
:
14858 case ROUND_DIV_EXPR
:
14859 case TRUNC_DIV_EXPR
:
14860 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14869 case FLOOR_MOD_EXPR
:
14870 case CEIL_MOD_EXPR
:
14871 case ROUND_MOD_EXPR
:
14872 case TRUNC_MOD_EXPR
:
14873 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14878 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14879 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
14880 if (list_ret
== 0 || list_ret1
== 0)
14883 add_loc_list (&list_ret
, list_ret1
);
14886 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14887 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14888 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14889 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14890 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14902 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14905 case POINTER_PLUS_EXPR
:
14908 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
14910 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14914 loc_list_plus_const (list_ret
, tree_to_shwi (TREE_OPERAND (loc
, 1)));
14922 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14929 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14936 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14943 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14958 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14959 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
14960 if (list_ret
== 0 || list_ret1
== 0)
14963 add_loc_list (&list_ret
, list_ret1
);
14966 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14969 case TRUTH_NOT_EXPR
:
14983 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14987 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14993 const enum tree_code code
=
14994 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14996 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14997 build2 (code
, integer_type_node
,
14998 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14999 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
15002 /* ... fall through ... */
15006 dw_loc_descr_ref lhs
15007 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
15008 dw_loc_list_ref rhs
15009 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0, context
);
15010 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
15012 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
15013 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
15016 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
15017 add_loc_descr_to_each (list_ret
, bra_node
);
15019 add_loc_list (&list_ret
, rhs
);
15020 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
15021 add_loc_descr_to_each (list_ret
, jump_node
);
15023 add_loc_descr_to_each (list_ret
, lhs
);
15024 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15025 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
15027 /* ??? Need a node to point the skip at. Use a nop. */
15028 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
15029 add_loc_descr_to_each (list_ret
, tmp
);
15030 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15031 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
15035 case FIX_TRUNC_EXPR
:
15039 /* Leave front-end specific codes as simply unknown. This comes
15040 up, for instance, with the C STMT_EXPR. */
15041 if ((unsigned int) TREE_CODE (loc
)
15042 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
15044 expansion_failed (loc
, NULL_RTX
,
15045 "language specific tree node");
15049 #ifdef ENABLE_CHECKING
15050 /* Otherwise this is a generic code; we should just lists all of
15051 these explicitly. We forgot one. */
15052 gcc_unreachable ();
15054 /* In a release build, we want to degrade gracefully: better to
15055 generate incomplete debugging information than to crash. */
15060 if (!ret
&& !list_ret
)
15063 if (want_address
== 2 && !have_address
15064 && (dwarf_version
>= 4 || !dwarf_strict
))
15066 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
15068 expansion_failed (loc
, NULL_RTX
,
15069 "DWARF address size mismatch");
15073 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15075 add_loc_descr_to_each (list_ret
,
15076 new_loc_descr (DW_OP_stack_value
, 0, 0));
15079 /* Show if we can't fill the request for an address. */
15080 if (want_address
&& !have_address
)
15082 expansion_failed (loc
, NULL_RTX
,
15083 "Want address and only have value");
15087 gcc_assert (!ret
|| !list_ret
);
15089 /* If we've got an address and don't want one, dereference. */
15090 if (!want_address
&& have_address
)
15092 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
15094 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
15096 expansion_failed (loc
, NULL_RTX
,
15097 "DWARF address size mismatch");
15100 else if (size
== DWARF2_ADDR_SIZE
)
15103 op
= DW_OP_deref_size
;
15106 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
15108 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
15111 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
15116 /* Same as above but return only single location expression. */
15117 static dw_loc_descr_ref
15118 loc_descriptor_from_tree (tree loc
, int want_address
,
15119 const struct loc_descr_context
*context
)
15121 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
, context
);
15124 if (ret
->dw_loc_next
)
15126 expansion_failed (loc
, NULL_RTX
,
15127 "Location list where only loc descriptor needed");
15133 /* Given a value, round it up to the lowest multiple of `boundary'
15134 which is not less than the value itself. */
15136 static inline HOST_WIDE_INT
15137 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
15139 return (((value
+ boundary
- 1) / boundary
) * boundary
);
15142 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
15143 pointer to the declared type for the relevant field variable, or return
15144 `integer_type_node' if the given node turns out to be an
15145 ERROR_MARK node. */
15148 field_type (const_tree decl
)
15152 if (TREE_CODE (decl
) == ERROR_MARK
)
15153 return integer_type_node
;
15155 type
= DECL_BIT_FIELD_TYPE (decl
);
15156 if (type
== NULL_TREE
)
15157 type
= TREE_TYPE (decl
);
15162 /* Given a pointer to a tree node, return the alignment in bits for
15163 it, or else return BITS_PER_WORD if the node actually turns out to
15164 be an ERROR_MARK node. */
15166 static inline unsigned
15167 simple_type_align_in_bits (const_tree type
)
15169 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
15172 static inline unsigned
15173 simple_decl_align_in_bits (const_tree decl
)
15175 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
15178 /* Return the result of rounding T up to ALIGN. */
15180 static inline offset_int
15181 round_up_to_align (const offset_int
&t
, unsigned int align
)
15183 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
15186 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
15187 lowest addressed byte of the "containing object" for the given FIELD_DECL,
15188 or return 0 if we are unable to determine what that offset is, either
15189 because the argument turns out to be a pointer to an ERROR_MARK node, or
15190 because the offset is actually variable. (We can't handle the latter case
15193 static HOST_WIDE_INT
15194 field_byte_offset (const_tree decl
)
15196 offset_int object_offset_in_bits
;
15197 offset_int object_offset_in_bytes
;
15198 offset_int bitpos_int
;
15200 if (TREE_CODE (decl
) == ERROR_MARK
)
15203 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
15205 /* We cannot yet cope with fields whose positions are variable, so
15206 for now, when we see such things, we simply return 0. Someday, we may
15207 be able to handle such cases, but it will be damn difficult. */
15208 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
15211 bitpos_int
= wi::to_offset (bit_position (decl
));
15213 if (PCC_BITFIELD_TYPE_MATTERS
)
15216 tree field_size_tree
;
15217 offset_int deepest_bitpos
;
15218 offset_int field_size_in_bits
;
15219 unsigned int type_align_in_bits
;
15220 unsigned int decl_align_in_bits
;
15221 offset_int type_size_in_bits
;
15223 type
= field_type (decl
);
15224 type_size_in_bits
= offset_int_type_size_in_bits (type
);
15225 type_align_in_bits
= simple_type_align_in_bits (type
);
15227 field_size_tree
= DECL_SIZE (decl
);
15229 /* The size could be unspecified if there was an error, or for
15230 a flexible array member. */
15231 if (!field_size_tree
)
15232 field_size_tree
= bitsize_zero_node
;
15234 /* If the size of the field is not constant, use the type size. */
15235 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
15236 field_size_in_bits
= wi::to_offset (field_size_tree
);
15238 field_size_in_bits
= type_size_in_bits
;
15240 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
15242 /* The GCC front-end doesn't make any attempt to keep track of the
15243 starting bit offset (relative to the start of the containing
15244 structure type) of the hypothetical "containing object" for a
15245 bit-field. Thus, when computing the byte offset value for the
15246 start of the "containing object" of a bit-field, we must deduce
15247 this information on our own. This can be rather tricky to do in
15248 some cases. For example, handling the following structure type
15249 definition when compiling for an i386/i486 target (which only
15250 aligns long long's to 32-bit boundaries) can be very tricky:
15252 struct S { int field1; long long field2:31; };
15254 Fortunately, there is a simple rule-of-thumb which can be used
15255 in such cases. When compiling for an i386/i486, GCC will
15256 allocate 8 bytes for the structure shown above. It decides to
15257 do this based upon one simple rule for bit-field allocation.
15258 GCC allocates each "containing object" for each bit-field at
15259 the first (i.e. lowest addressed) legitimate alignment boundary
15260 (based upon the required minimum alignment for the declared
15261 type of the field) which it can possibly use, subject to the
15262 condition that there is still enough available space remaining
15263 in the containing object (when allocated at the selected point)
15264 to fully accommodate all of the bits of the bit-field itself.
15266 This simple rule makes it obvious why GCC allocates 8 bytes for
15267 each object of the structure type shown above. When looking
15268 for a place to allocate the "containing object" for `field2',
15269 the compiler simply tries to allocate a 64-bit "containing
15270 object" at each successive 32-bit boundary (starting at zero)
15271 until it finds a place to allocate that 64- bit field such that
15272 at least 31 contiguous (and previously unallocated) bits remain
15273 within that selected 64 bit field. (As it turns out, for the
15274 example above, the compiler finds it is OK to allocate the
15275 "containing object" 64-bit field at bit-offset zero within the
15278 Here we attempt to work backwards from the limited set of facts
15279 we're given, and we try to deduce from those facts, where GCC
15280 must have believed that the containing object started (within
15281 the structure type). The value we deduce is then used (by the
15282 callers of this routine) to generate DW_AT_location and
15283 DW_AT_bit_offset attributes for fields (both bit-fields and, in
15284 the case of DW_AT_location, regular fields as well). */
15286 /* Figure out the bit-distance from the start of the structure to
15287 the "deepest" bit of the bit-field. */
15288 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
15290 /* This is the tricky part. Use some fancy footwork to deduce
15291 where the lowest addressed bit of the containing object must
15293 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
15295 /* Round up to type_align by default. This works best for
15297 object_offset_in_bits
15298 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
15300 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
15302 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
15304 /* Round up to decl_align instead. */
15305 object_offset_in_bits
15306 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
15310 object_offset_in_bits
= bitpos_int
;
15312 object_offset_in_bytes
15313 = wi::lrshift (object_offset_in_bits
, LOG2_BITS_PER_UNIT
);
15314 return object_offset_in_bytes
.to_shwi ();
15317 /* The following routines define various Dwarf attributes and any data
15318 associated with them. */
15320 /* Add a location description attribute value to a DIE.
15322 This emits location attributes suitable for whole variables and
15323 whole parameters. Note that the location attributes for struct fields are
15324 generated by the routine `data_member_location_attribute' below. */
15327 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
15328 dw_loc_list_ref descr
)
15332 if (single_element_loc_list_p (descr
))
15333 add_AT_loc (die
, attr_kind
, descr
->expr
);
15335 add_AT_loc_list (die
, attr_kind
, descr
);
15338 /* Add DW_AT_accessibility attribute to DIE if needed. */
15341 add_accessibility_attribute (dw_die_ref die
, tree decl
)
15343 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
15344 children, otherwise the default is DW_ACCESS_public. In DWARF2
15345 the default has always been DW_ACCESS_public. */
15346 if (TREE_PROTECTED (decl
))
15347 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
15348 else if (TREE_PRIVATE (decl
))
15350 if (dwarf_version
== 2
15351 || die
->die_parent
== NULL
15352 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
15353 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
15355 else if (dwarf_version
> 2
15357 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
15358 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
15361 /* Attach the specialized form of location attribute used for data members of
15362 struct and union types. In the special case of a FIELD_DECL node which
15363 represents a bit-field, the "offset" part of this special location
15364 descriptor must indicate the distance in bytes from the lowest-addressed
15365 byte of the containing struct or union type to the lowest-addressed byte of
15366 the "containing object" for the bit-field. (See the `field_byte_offset'
15369 For any given bit-field, the "containing object" is a hypothetical object
15370 (of some integral or enum type) within which the given bit-field lives. The
15371 type of this hypothetical "containing object" is always the same as the
15372 declared type of the individual bit-field itself (for GCC anyway... the
15373 DWARF spec doesn't actually mandate this). Note that it is the size (in
15374 bytes) of the hypothetical "containing object" which will be given in the
15375 DW_AT_byte_size attribute for this bit-field. (See the
15376 `byte_size_attribute' function below.) It is also used when calculating the
15377 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
15378 function below.) */
15381 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
15383 HOST_WIDE_INT offset
;
15384 dw_loc_descr_ref loc_descr
= 0;
15386 if (TREE_CODE (decl
) == TREE_BINFO
)
15388 /* We're working on the TAG_inheritance for a base class. */
15389 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
15391 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
15392 aren't at a fixed offset from all (sub)objects of the same
15393 type. We need to extract the appropriate offset from our
15394 vtable. The following dwarf expression means
15396 BaseAddr = ObAddr + *((*ObAddr) - Offset)
15398 This is specific to the V3 ABI, of course. */
15400 dw_loc_descr_ref tmp
;
15402 /* Make a copy of the object address. */
15403 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
15404 add_loc_descr (&loc_descr
, tmp
);
15406 /* Extract the vtable address. */
15407 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
15408 add_loc_descr (&loc_descr
, tmp
);
15410 /* Calculate the address of the offset. */
15411 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
15412 gcc_assert (offset
< 0);
15414 tmp
= int_loc_descriptor (-offset
);
15415 add_loc_descr (&loc_descr
, tmp
);
15416 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
15417 add_loc_descr (&loc_descr
, tmp
);
15419 /* Extract the offset. */
15420 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
15421 add_loc_descr (&loc_descr
, tmp
);
15423 /* Add it to the object address. */
15424 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
15425 add_loc_descr (&loc_descr
, tmp
);
15428 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
15431 offset
= field_byte_offset (decl
);
15435 if (dwarf_version
> 2)
15437 /* Don't need to output a location expression, just the constant. */
15439 add_AT_int (die
, DW_AT_data_member_location
, offset
);
15441 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
15446 enum dwarf_location_atom op
;
15448 /* The DWARF2 standard says that we should assume that the structure
15449 address is already on the stack, so we can specify a structure
15450 field address by using DW_OP_plus_uconst. */
15451 op
= DW_OP_plus_uconst
;
15452 loc_descr
= new_loc_descr (op
, offset
, 0);
15456 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
15459 /* Writes integer values to dw_vec_const array. */
15462 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
15466 *dest
++ = val
& 0xff;
15472 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
15474 static HOST_WIDE_INT
15475 extract_int (const unsigned char *src
, unsigned int size
)
15477 HOST_WIDE_INT val
= 0;
15483 val
|= *--src
& 0xff;
15489 /* Writes wide_int values to dw_vec_const array. */
15492 insert_wide_int (const wide_int
&val
, unsigned char *dest
, int elt_size
)
15496 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
15498 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
15502 /* We'd have to extend this code to support odd sizes. */
15503 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
) == 0);
15505 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
15507 if (WORDS_BIG_ENDIAN
)
15508 for (i
= n
- 1; i
>= 0; i
--)
15510 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
15511 dest
+= sizeof (HOST_WIDE_INT
);
15514 for (i
= 0; i
< n
; i
++)
15516 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
15517 dest
+= sizeof (HOST_WIDE_INT
);
15521 /* Writes floating point values to dw_vec_const array. */
15524 insert_float (const_rtx rtl
, unsigned char *array
)
15526 REAL_VALUE_TYPE rv
;
15530 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
15531 real_to_target (val
, &rv
, GET_MODE (rtl
));
15533 /* real_to_target puts 32-bit pieces in each long. Pack them. */
15534 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
15536 insert_int (val
[i
], 4, array
);
15541 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
15542 does not have a "location" either in memory or in a register. These
15543 things can arise in GNU C when a constant is passed as an actual parameter
15544 to an inlined function. They can also arise in C++ where declared
15545 constants do not necessarily get memory "homes". */
15548 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
15550 switch (GET_CODE (rtl
))
15554 HOST_WIDE_INT val
= INTVAL (rtl
);
15557 add_AT_int (die
, DW_AT_const_value
, val
);
15559 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
15563 case CONST_WIDE_INT
:
15564 add_AT_wide (die
, DW_AT_const_value
,
15565 std::make_pair (rtl
, GET_MODE (rtl
)));
15569 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
15570 floating-point constant. A CONST_DOUBLE is used whenever the
15571 constant requires more than one word in order to be adequately
15574 machine_mode mode
= GET_MODE (rtl
);
15576 if (TARGET_SUPPORTS_WIDE_INT
== 0 && !SCALAR_FLOAT_MODE_P (mode
))
15577 add_AT_double (die
, DW_AT_const_value
,
15578 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
15581 unsigned int length
= GET_MODE_SIZE (mode
);
15582 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15584 insert_float (rtl
, array
);
15585 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
15592 machine_mode mode
= GET_MODE (rtl
);
15593 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
15594 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15595 unsigned char *array
15596 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
15599 machine_mode imode
= GET_MODE_INNER (mode
);
15601 switch (GET_MODE_CLASS (mode
))
15603 case MODE_VECTOR_INT
:
15604 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15606 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15607 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
15611 case MODE_VECTOR_FLOAT
:
15612 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15614 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15615 insert_float (elt
, p
);
15620 gcc_unreachable ();
15623 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
15628 if (dwarf_version
>= 4 || !dwarf_strict
)
15630 dw_loc_descr_ref loc_result
;
15631 resolve_one_addr (&rtl
);
15633 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15634 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15635 add_AT_loc (die
, DW_AT_location
, loc_result
);
15636 vec_safe_push (used_rtx_array
, rtl
);
15642 if (CONSTANT_P (XEXP (rtl
, 0)))
15643 return add_const_value_attribute (die
, XEXP (rtl
, 0));
15646 if (!const_ok_for_output (rtl
))
15649 if (dwarf_version
>= 4 || !dwarf_strict
)
15654 /* In cases where an inlined instance of an inline function is passed
15655 the address of an `auto' variable (which is local to the caller) we
15656 can get a situation where the DECL_RTL of the artificial local
15657 variable (for the inlining) which acts as a stand-in for the
15658 corresponding formal parameter (of the inline function) will look
15659 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
15660 exactly a compile-time constant expression, but it isn't the address
15661 of the (artificial) local variable either. Rather, it represents the
15662 *value* which the artificial local variable always has during its
15663 lifetime. We currently have no way to represent such quasi-constant
15664 values in Dwarf, so for now we just punt and generate nothing. */
15672 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
15673 && MEM_READONLY_P (rtl
)
15674 && GET_MODE (rtl
) == BLKmode
)
15676 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
15682 /* No other kinds of rtx should be possible here. */
15683 gcc_unreachable ();
15688 /* Determine whether the evaluation of EXPR references any variables
15689 or functions which aren't otherwise used (and therefore may not be
15692 reference_to_unused (tree
* tp
, int * walk_subtrees
,
15693 void * data ATTRIBUTE_UNUSED
)
15695 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
15696 *walk_subtrees
= 0;
15698 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
15699 && ! TREE_ASM_WRITTEN (*tp
))
15701 /* ??? The C++ FE emits debug information for using decls, so
15702 putting gcc_unreachable here falls over. See PR31899. For now
15703 be conservative. */
15704 else if (!symtab
->global_info_ready
15705 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
15707 else if (TREE_CODE (*tp
) == VAR_DECL
)
15709 varpool_node
*node
= varpool_node::get (*tp
);
15710 if (!node
|| !node
->definition
)
15713 else if (TREE_CODE (*tp
) == FUNCTION_DECL
15714 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
15716 /* The call graph machinery must have finished analyzing,
15717 optimizing and gimplifying the CU by now.
15718 So if *TP has no call graph node associated
15719 to it, it means *TP will not be emitted. */
15720 if (!cgraph_node::get (*tp
))
15723 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
15729 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
15730 for use in a later add_const_value_attribute call. */
15733 rtl_for_decl_init (tree init
, tree type
)
15735 rtx rtl
= NULL_RTX
;
15739 /* If a variable is initialized with a string constant without embedded
15740 zeros, build CONST_STRING. */
15741 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
15743 tree enttype
= TREE_TYPE (type
);
15744 tree domain
= TYPE_DOMAIN (type
);
15745 machine_mode mode
= TYPE_MODE (enttype
);
15747 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
15749 && integer_zerop (TYPE_MIN_VALUE (domain
))
15750 && compare_tree_int (TYPE_MAX_VALUE (domain
),
15751 TREE_STRING_LENGTH (init
) - 1) == 0
15752 && ((size_t) TREE_STRING_LENGTH (init
)
15753 == strlen (TREE_STRING_POINTER (init
)) + 1))
15755 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
15756 ggc_strdup (TREE_STRING_POINTER (init
)));
15757 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
15758 MEM_READONLY_P (rtl
) = 1;
15761 /* Other aggregates, and complex values, could be represented using
15763 else if (AGGREGATE_TYPE_P (type
)
15764 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
15765 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
15766 || TREE_CODE (type
) == COMPLEX_TYPE
)
15768 /* Vectors only work if their mode is supported by the target.
15769 FIXME: generic vectors ought to work too. */
15770 else if (TREE_CODE (type
) == VECTOR_TYPE
15771 && !VECTOR_MODE_P (TYPE_MODE (type
)))
15773 /* If the initializer is something that we know will expand into an
15774 immediate RTL constant, expand it now. We must be careful not to
15775 reference variables which won't be output. */
15776 else if (initializer_constant_valid_p (init
, type
)
15777 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
15779 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
15781 if (TREE_CODE (type
) == VECTOR_TYPE
)
15782 switch (TREE_CODE (init
))
15787 if (TREE_CONSTANT (init
))
15789 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
15790 bool constant_p
= true;
15792 unsigned HOST_WIDE_INT ix
;
15794 /* Even when ctor is constant, it might contain non-*_CST
15795 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15796 belong into VECTOR_CST nodes. */
15797 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
15798 if (!CONSTANT_CLASS_P (value
))
15800 constant_p
= false;
15806 init
= build_vector_from_ctor (type
, elts
);
15816 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
15818 /* If expand_expr returns a MEM, it wasn't immediate. */
15819 gcc_assert (!rtl
|| !MEM_P (rtl
));
15825 /* Generate RTL for the variable DECL to represent its location. */
15828 rtl_for_decl_location (tree decl
)
15832 /* Here we have to decide where we are going to say the parameter "lives"
15833 (as far as the debugger is concerned). We only have a couple of
15834 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15836 DECL_RTL normally indicates where the parameter lives during most of the
15837 activation of the function. If optimization is enabled however, this
15838 could be either NULL or else a pseudo-reg. Both of those cases indicate
15839 that the parameter doesn't really live anywhere (as far as the code
15840 generation parts of GCC are concerned) during most of the function's
15841 activation. That will happen (for example) if the parameter is never
15842 referenced within the function.
15844 We could just generate a location descriptor here for all non-NULL
15845 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15846 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15847 where DECL_RTL is NULL or is a pseudo-reg.
15849 Note however that we can only get away with using DECL_INCOMING_RTL as
15850 a backup substitute for DECL_RTL in certain limited cases. In cases
15851 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15852 we can be sure that the parameter was passed using the same type as it is
15853 declared to have within the function, and that its DECL_INCOMING_RTL
15854 points us to a place where a value of that type is passed.
15856 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15857 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15858 because in these cases DECL_INCOMING_RTL points us to a value of some
15859 type which is *different* from the type of the parameter itself. Thus,
15860 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15861 such cases, the debugger would end up (for example) trying to fetch a
15862 `float' from a place which actually contains the first part of a
15863 `double'. That would lead to really incorrect and confusing
15864 output at debug-time.
15866 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15867 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15868 are a couple of exceptions however. On little-endian machines we can
15869 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15870 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15871 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15872 when (on a little-endian machine) a non-prototyped function has a
15873 parameter declared to be of type `short' or `char'. In such cases,
15874 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15875 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15876 passed `int' value. If the debugger then uses that address to fetch
15877 a `short' or a `char' (on a little-endian machine) the result will be
15878 the correct data, so we allow for such exceptional cases below.
15880 Note that our goal here is to describe the place where the given formal
15881 parameter lives during most of the function's activation (i.e. between the
15882 end of the prologue and the start of the epilogue). We'll do that as best
15883 as we can. Note however that if the given formal parameter is modified
15884 sometime during the execution of the function, then a stack backtrace (at
15885 debug-time) will show the function as having been called with the *new*
15886 value rather than the value which was originally passed in. This happens
15887 rarely enough that it is not a major problem, but it *is* a problem, and
15888 I'd like to fix it.
15890 A future version of dwarf2out.c may generate two additional attributes for
15891 any given DW_TAG_formal_parameter DIE which will describe the "passed
15892 type" and the "passed location" for the given formal parameter in addition
15893 to the attributes we now generate to indicate the "declared type" and the
15894 "active location" for each parameter. This additional set of attributes
15895 could be used by debuggers for stack backtraces. Separately, note that
15896 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15897 This happens (for example) for inlined-instances of inline function formal
15898 parameters which are never referenced. This really shouldn't be
15899 happening. All PARM_DECL nodes should get valid non-NULL
15900 DECL_INCOMING_RTL values. FIXME. */
15902 /* Use DECL_RTL as the "location" unless we find something better. */
15903 rtl
= DECL_RTL_IF_SET (decl
);
15905 /* When generating abstract instances, ignore everything except
15906 constants, symbols living in memory, and symbols living in
15907 fixed registers. */
15908 if (! reload_completed
)
15911 && (CONSTANT_P (rtl
)
15913 && CONSTANT_P (XEXP (rtl
, 0)))
15915 && TREE_CODE (decl
) == VAR_DECL
15916 && TREE_STATIC (decl
))))
15918 rtl
= targetm
.delegitimize_address (rtl
);
15923 else if (TREE_CODE (decl
) == PARM_DECL
)
15925 if (rtl
== NULL_RTX
15926 || is_pseudo_reg (rtl
)
15928 && is_pseudo_reg (XEXP (rtl
, 0))
15929 && DECL_INCOMING_RTL (decl
)
15930 && MEM_P (DECL_INCOMING_RTL (decl
))
15931 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15933 tree declared_type
= TREE_TYPE (decl
);
15934 tree passed_type
= DECL_ARG_TYPE (decl
);
15935 machine_mode dmode
= TYPE_MODE (declared_type
);
15936 machine_mode pmode
= TYPE_MODE (passed_type
);
15938 /* This decl represents a formal parameter which was optimized out.
15939 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15940 all cases where (rtl == NULL_RTX) just below. */
15941 if (dmode
== pmode
)
15942 rtl
= DECL_INCOMING_RTL (decl
);
15943 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15944 && SCALAR_INT_MODE_P (dmode
)
15945 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15946 && DECL_INCOMING_RTL (decl
))
15948 rtx inc
= DECL_INCOMING_RTL (decl
);
15951 else if (MEM_P (inc
))
15953 if (BYTES_BIG_ENDIAN
)
15954 rtl
= adjust_address_nv (inc
, dmode
,
15955 GET_MODE_SIZE (pmode
)
15956 - GET_MODE_SIZE (dmode
));
15963 /* If the parm was passed in registers, but lives on the stack, then
15964 make a big endian correction if the mode of the type of the
15965 parameter is not the same as the mode of the rtl. */
15966 /* ??? This is the same series of checks that are made in dbxout.c before
15967 we reach the big endian correction code there. It isn't clear if all
15968 of these checks are necessary here, but keeping them all is the safe
15970 else if (MEM_P (rtl
)
15971 && XEXP (rtl
, 0) != const0_rtx
15972 && ! CONSTANT_P (XEXP (rtl
, 0))
15973 /* Not passed in memory. */
15974 && !MEM_P (DECL_INCOMING_RTL (decl
))
15975 /* Not passed by invisible reference. */
15976 && (!REG_P (XEXP (rtl
, 0))
15977 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15978 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15979 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15980 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15983 /* Big endian correction check. */
15984 && BYTES_BIG_ENDIAN
15985 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15986 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15989 machine_mode addr_mode
= get_address_mode (rtl
);
15990 int offset
= (UNITS_PER_WORD
15991 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15993 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15994 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15997 else if (TREE_CODE (decl
) == VAR_DECL
16000 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
16001 && BYTES_BIG_ENDIAN
)
16003 machine_mode addr_mode
= get_address_mode (rtl
);
16004 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
16005 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
16007 /* If a variable is declared "register" yet is smaller than
16008 a register, then if we store the variable to memory, it
16009 looks like we're storing a register-sized value, when in
16010 fact we are not. We need to adjust the offset of the
16011 storage location to reflect the actual value's bytes,
16012 else gdb will not be able to display it. */
16014 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
16015 plus_constant (addr_mode
, XEXP (rtl
, 0),
16019 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16020 and will have been substituted directly into all expressions that use it.
16021 C does not have such a concept, but C++ and other languages do. */
16022 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
16023 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
16026 rtl
= targetm
.delegitimize_address (rtl
);
16028 /* If we don't look past the constant pool, we risk emitting a
16029 reference to a constant pool entry that isn't referenced from
16030 code, and thus is not emitted. */
16032 rtl
= avoid_constant_pool_reference (rtl
);
16034 /* Try harder to get a rtl. If this symbol ends up not being emitted
16035 in the current CU, resolve_addr will remove the expression referencing
16037 if (rtl
== NULL_RTX
16038 && TREE_CODE (decl
) == VAR_DECL
16039 && !DECL_EXTERNAL (decl
)
16040 && TREE_STATIC (decl
)
16041 && DECL_NAME (decl
)
16042 && !DECL_HARD_REGISTER (decl
)
16043 && DECL_MODE (decl
) != VOIDmode
)
16045 rtl
= make_decl_rtl_for_debug (decl
);
16047 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
16048 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
16055 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
16056 returned. If so, the decl for the COMMON block is returned, and the
16057 value is the offset into the common block for the symbol. */
16060 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
16062 tree val_expr
, cvar
;
16064 HOST_WIDE_INT bitsize
, bitpos
;
16066 int unsignedp
, volatilep
= 0;
16068 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
16069 it does not have a value (the offset into the common area), or if it
16070 is thread local (as opposed to global) then it isn't common, and shouldn't
16071 be handled as such. */
16072 if (TREE_CODE (decl
) != VAR_DECL
16073 || !TREE_STATIC (decl
)
16074 || !DECL_HAS_VALUE_EXPR_P (decl
)
16078 val_expr
= DECL_VALUE_EXPR (decl
);
16079 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
16082 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
16083 &mode
, &unsignedp
, &volatilep
, true);
16085 if (cvar
== NULL_TREE
16086 || TREE_CODE (cvar
) != VAR_DECL
16087 || DECL_ARTIFICIAL (cvar
)
16088 || !TREE_PUBLIC (cvar
))
16092 if (offset
!= NULL
)
16094 if (!tree_fits_shwi_p (offset
))
16096 *value
= tree_to_shwi (offset
);
16099 *value
+= bitpos
/ BITS_PER_UNIT
;
16104 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
16105 data attribute for a variable or a parameter. We generate the
16106 DW_AT_const_value attribute only in those cases where the given variable
16107 or parameter does not have a true "location" either in memory or in a
16108 register. This can happen (for example) when a constant is passed as an
16109 actual argument in a call to an inline function. (It's possible that
16110 these things can crop up in other ways also.) Note that one type of
16111 constant value which can be passed into an inlined function is a constant
16112 pointer. This can happen for example if an actual argument in an inlined
16113 function call evaluates to a compile-time constant address.
16115 CACHE_P is true if it is worth caching the location list for DECL,
16116 so that future calls can reuse it rather than regenerate it from scratch.
16117 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
16118 since we will need to refer to them each time the function is inlined. */
16121 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
16122 enum dwarf_attribute attr
)
16125 dw_loc_list_ref list
;
16126 var_loc_list
*loc_list
;
16127 cached_dw_loc_list
*cache
;
16129 if (TREE_CODE (decl
) == ERROR_MARK
)
16132 if (get_AT (die
, attr
))
16135 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
16136 || TREE_CODE (decl
) == RESULT_DECL
);
16138 /* Try to get some constant RTL for this decl, and use that as the value of
16141 rtl
= rtl_for_decl_location (decl
);
16142 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
16143 && add_const_value_attribute (die
, rtl
))
16146 /* See if we have single element location list that is equivalent to
16147 a constant value. That way we are better to use add_const_value_attribute
16148 rather than expanding constant value equivalent. */
16149 loc_list
= lookup_decl_loc (decl
);
16152 && loc_list
->first
->next
== NULL
16153 && NOTE_P (loc_list
->first
->loc
)
16154 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
16155 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
16157 struct var_loc_node
*node
;
16159 node
= loc_list
->first
;
16160 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
16161 if (GET_CODE (rtl
) == EXPR_LIST
)
16162 rtl
= XEXP (rtl
, 0);
16163 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
16164 && add_const_value_attribute (die
, rtl
))
16167 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
16168 list several times. See if we've already cached the contents. */
16170 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
16174 cache
= cached_dw_loc_list_table
->find_with_hash (decl
, DECL_UID (decl
));
16176 list
= cache
->loc_list
;
16180 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2,
16182 /* It is usually worth caching this result if the decl is from
16183 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
16184 if (cache_p
&& list
&& list
->dw_loc_next
)
16186 cached_dw_loc_list
**slot
16187 = cached_dw_loc_list_table
->find_slot_with_hash (decl
,
16190 cache
= ggc_cleared_alloc
<cached_dw_loc_list
> ();
16191 cache
->decl_id
= DECL_UID (decl
);
16192 cache
->loc_list
= list
;
16198 add_AT_location_description (die
, attr
, list
);
16201 /* None of that worked, so it must not really have a location;
16202 try adding a constant value attribute from the DECL_INITIAL. */
16203 return tree_add_const_value_attribute_for_decl (die
, decl
);
16206 /* Helper function for tree_add_const_value_attribute. Natively encode
16207 initializer INIT into an array. Return true if successful. */
16210 native_encode_initializer (tree init
, unsigned char *array
, int size
)
16214 if (init
== NULL_TREE
)
16218 switch (TREE_CODE (init
))
16221 type
= TREE_TYPE (init
);
16222 if (TREE_CODE (type
) == ARRAY_TYPE
)
16224 tree enttype
= TREE_TYPE (type
);
16225 machine_mode mode
= TYPE_MODE (enttype
);
16227 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
16229 if (int_size_in_bytes (type
) != size
)
16231 if (size
> TREE_STRING_LENGTH (init
))
16233 memcpy (array
, TREE_STRING_POINTER (init
),
16234 TREE_STRING_LENGTH (init
));
16235 memset (array
+ TREE_STRING_LENGTH (init
),
16236 '\0', size
- TREE_STRING_LENGTH (init
));
16239 memcpy (array
, TREE_STRING_POINTER (init
), size
);
16244 type
= TREE_TYPE (init
);
16245 if (int_size_in_bytes (type
) != size
)
16247 if (TREE_CODE (type
) == ARRAY_TYPE
)
16249 HOST_WIDE_INT min_index
;
16250 unsigned HOST_WIDE_INT cnt
;
16251 int curpos
= 0, fieldsize
;
16252 constructor_elt
*ce
;
16254 if (TYPE_DOMAIN (type
) == NULL_TREE
16255 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
16258 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
16259 if (fieldsize
<= 0)
16262 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
16263 memset (array
, '\0', size
);
16264 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
16266 tree val
= ce
->value
;
16267 tree index
= ce
->index
;
16269 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
16270 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
16273 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
16278 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
16281 curpos
= pos
+ fieldsize
;
16282 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
16284 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
16285 - tree_to_shwi (TREE_OPERAND (index
, 0));
16286 while (count
-- > 0)
16289 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
16290 curpos
+= fieldsize
;
16293 gcc_assert (curpos
<= size
);
16297 else if (TREE_CODE (type
) == RECORD_TYPE
16298 || TREE_CODE (type
) == UNION_TYPE
)
16300 tree field
= NULL_TREE
;
16301 unsigned HOST_WIDE_INT cnt
;
16302 constructor_elt
*ce
;
16304 if (int_size_in_bytes (type
) != size
)
16307 if (TREE_CODE (type
) == RECORD_TYPE
)
16308 field
= TYPE_FIELDS (type
);
16310 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
16312 tree val
= ce
->value
;
16313 int pos
, fieldsize
;
16315 if (ce
->index
!= 0)
16321 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
16324 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
16325 && TYPE_DOMAIN (TREE_TYPE (field
))
16326 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
16328 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
16329 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
16331 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
16332 pos
= int_byte_position (field
);
16333 gcc_assert (pos
+ fieldsize
<= size
);
16335 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
16341 case VIEW_CONVERT_EXPR
:
16342 case NON_LVALUE_EXPR
:
16343 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
16345 return native_encode_expr (init
, array
, size
) == size
;
16349 /* Attach a DW_AT_const_value attribute to DIE. The value of the
16350 attribute is the const value T. */
16353 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
16356 tree type
= TREE_TYPE (t
);
16359 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
16363 gcc_assert (!DECL_P (init
));
16365 rtl
= rtl_for_decl_init (init
, type
);
16367 return add_const_value_attribute (die
, rtl
);
16368 /* If the host and target are sane, try harder. */
16369 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
16370 && initializer_constant_valid_p (init
, type
))
16372 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
16373 if (size
> 0 && (int) size
== size
)
16375 unsigned char *array
= ggc_cleared_vec_alloc
<unsigned char> (size
);
16377 if (native_encode_initializer (init
, array
, size
))
16379 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
16388 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
16389 attribute is the const value of T, where T is an integral constant
16390 variable with static storage duration
16391 (so it can't be a PARM_DECL or a RESULT_DECL). */
16394 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
16398 || (TREE_CODE (decl
) != VAR_DECL
16399 && TREE_CODE (decl
) != CONST_DECL
)
16400 || (TREE_CODE (decl
) == VAR_DECL
16401 && !TREE_STATIC (decl
)))
16404 if (TREE_READONLY (decl
)
16405 && ! TREE_THIS_VOLATILE (decl
)
16406 && DECL_INITIAL (decl
))
16411 /* Don't add DW_AT_const_value if abstract origin already has one. */
16412 if (get_AT (var_die
, DW_AT_const_value
))
16415 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
16418 /* Convert the CFI instructions for the current function into a
16419 location list. This is used for DW_AT_frame_base when we targeting
16420 a dwarf2 consumer that does not support the dwarf3
16421 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
16424 static dw_loc_list_ref
16425 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
16429 dw_loc_list_ref list
, *list_tail
;
16431 dw_cfa_location last_cfa
, next_cfa
;
16432 const char *start_label
, *last_label
, *section
;
16433 dw_cfa_location remember
;
16436 gcc_assert (fde
!= NULL
);
16438 section
= secname_for_decl (current_function_decl
);
16442 memset (&next_cfa
, 0, sizeof (next_cfa
));
16443 next_cfa
.reg
= INVALID_REGNUM
;
16444 remember
= next_cfa
;
16446 start_label
= fde
->dw_fde_begin
;
16448 /* ??? Bald assumption that the CIE opcode list does not contain
16449 advance opcodes. */
16450 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
16451 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
16453 last_cfa
= next_cfa
;
16454 last_label
= start_label
;
16456 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
16458 /* If the first partition contained no CFI adjustments, the
16459 CIE opcodes apply to the whole first partition. */
16460 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16461 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
16462 list_tail
=&(*list_tail
)->dw_loc_next
;
16463 start_label
= last_label
= fde
->dw_fde_second_begin
;
16466 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
16468 switch (cfi
->dw_cfi_opc
)
16470 case DW_CFA_set_loc
:
16471 case DW_CFA_advance_loc1
:
16472 case DW_CFA_advance_loc2
:
16473 case DW_CFA_advance_loc4
:
16474 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16476 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16477 start_label
, last_label
, section
);
16479 list_tail
= &(*list_tail
)->dw_loc_next
;
16480 last_cfa
= next_cfa
;
16481 start_label
= last_label
;
16483 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
16486 case DW_CFA_advance_loc
:
16487 /* The encoding is complex enough that we should never emit this. */
16488 gcc_unreachable ();
16491 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
16494 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
16496 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16498 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16499 start_label
, last_label
, section
);
16501 list_tail
= &(*list_tail
)->dw_loc_next
;
16502 last_cfa
= next_cfa
;
16503 start_label
= last_label
;
16505 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16506 start_label
, fde
->dw_fde_end
, section
);
16507 list_tail
= &(*list_tail
)->dw_loc_next
;
16508 start_label
= last_label
= fde
->dw_fde_second_begin
;
16512 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16514 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16515 start_label
, last_label
, section
);
16516 list_tail
= &(*list_tail
)->dw_loc_next
;
16517 start_label
= last_label
;
16520 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
16522 fde
->dw_fde_second_begin
16523 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
16526 if (list
&& list
->dw_loc_next
)
16532 /* Compute a displacement from the "steady-state frame pointer" to the
16533 frame base (often the same as the CFA), and store it in
16534 frame_pointer_fb_offset. OFFSET is added to the displacement
16535 before the latter is negated. */
16538 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
16542 #ifdef FRAME_POINTER_CFA_OFFSET
16543 reg
= frame_pointer_rtx
;
16544 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
16546 reg
= arg_pointer_rtx
;
16547 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
16550 elim
= (ira_use_lra_p
16551 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
16552 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
16553 if (GET_CODE (elim
) == PLUS
)
16555 offset
+= INTVAL (XEXP (elim
, 1));
16556 elim
= XEXP (elim
, 0);
16559 frame_pointer_fb_offset
= -offset
;
16561 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
16562 in which to eliminate. This is because it's stack pointer isn't
16563 directly accessible as a register within the ISA. To work around
16564 this, assume that while we cannot provide a proper value for
16565 frame_pointer_fb_offset, we won't need one either. */
16566 frame_pointer_fb_offset_valid
16567 = ((SUPPORTS_STACK_ALIGNMENT
16568 && (elim
== hard_frame_pointer_rtx
16569 || elim
== stack_pointer_rtx
))
16570 || elim
== (frame_pointer_needed
16571 ? hard_frame_pointer_rtx
16572 : stack_pointer_rtx
));
16575 /* Generate a DW_AT_name attribute given some string value to be included as
16576 the value of the attribute. */
16579 add_name_attribute (dw_die_ref die
, const char *name_string
)
16581 if (name_string
!= NULL
&& *name_string
!= 0)
16583 if (demangle_name_func
)
16584 name_string
= (*demangle_name_func
) (name_string
);
16586 add_AT_string (die
, DW_AT_name
, name_string
);
16590 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
16591 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
16592 of TYPE accordingly.
16594 ??? This is a temporary measure until after we're able to generate
16595 regular DWARF for the complex Ada type system. */
16598 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
16599 dw_die_ref context_die
)
16602 dw_die_ref dtype_die
;
16604 if (!lang_hooks
.types
.descriptive_type
)
16607 dtype
= lang_hooks
.types
.descriptive_type (type
);
16611 dtype_die
= lookup_type_die (dtype
);
16614 gen_type_die (dtype
, context_die
);
16615 dtype_die
= lookup_type_die (dtype
);
16616 gcc_assert (dtype_die
);
16619 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
16622 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
16624 static const char *
16625 comp_dir_string (void)
16629 static const char *cached_wd
= NULL
;
16631 if (cached_wd
!= NULL
)
16634 wd
= get_src_pwd ();
16638 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
16642 wdlen
= strlen (wd
);
16643 wd1
= ggc_vec_alloc
<char> (wdlen
+ 2);
16645 wd1
[wdlen
] = DIR_SEPARATOR
;
16646 wd1
[wdlen
+ 1] = 0;
16650 cached_wd
= remap_debug_filename (wd
);
16654 /* Generate a DW_AT_comp_dir attribute for DIE. */
16657 add_comp_dir_attribute (dw_die_ref die
)
16659 const char * wd
= comp_dir_string ();
16661 add_AT_string (die
, DW_AT_comp_dir
, wd
);
16664 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
16665 pointer computation, ...), output a representation for that bound according
16666 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
16667 loc_list_from_tree for the meaning of CONTEXT. */
16670 add_scalar_info (dw_die_ref die
, enum dwarf_attribute attr
, tree value
,
16671 int forms
, const struct loc_descr_context
*context
)
16673 dw_die_ref ctx
, decl_die
;
16674 dw_loc_list_ref list
;
16676 bool strip_conversions
= true;
16678 while (strip_conversions
)
16679 switch (TREE_CODE (value
))
16686 case VIEW_CONVERT_EXPR
:
16687 value
= TREE_OPERAND (value
, 0);
16691 strip_conversions
= false;
16695 /* If possible and permitted, output the attribute as a constant. */
16696 if ((forms
& dw_scalar_form_constant
) != 0
16697 && TREE_CODE (value
) == INTEGER_CST
)
16699 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (value
));
16701 /* If HOST_WIDE_INT is big enough then represent the bound as
16702 a constant value. We need to choose a form based on
16703 whether the type is signed or unsigned. We cannot just
16704 call add_AT_unsigned if the value itself is positive
16705 (add_AT_unsigned might add the unsigned value encoded as
16706 DW_FORM_data[1248]). Some DWARF consumers will lookup the
16707 bounds type and then sign extend any unsigned values found
16708 for signed types. This is needed only for
16709 DW_AT_{lower,upper}_bound, since for most other attributes,
16710 consumers will treat DW_FORM_data[1248] as unsigned values,
16711 regardless of the underlying type. */
16712 if (prec
<= HOST_BITS_PER_WIDE_INT
16713 || tree_fits_uhwi_p (value
))
16715 if (TYPE_UNSIGNED (TREE_TYPE (value
)))
16716 add_AT_unsigned (die
, attr
, TREE_INT_CST_LOW (value
));
16718 add_AT_int (die
, attr
, TREE_INT_CST_LOW (value
));
16721 /* Otherwise represent the bound as an unsigned value with
16722 the precision of its type. The precision and signedness
16723 of the type will be necessary to re-interpret it
16725 add_AT_wide (die
, attr
, value
);
16729 /* Otherwise, if it's possible and permitted too, output a reference to
16731 if ((forms
& dw_scalar_form_reference
) != 0)
16733 tree decl
= NULL_TREE
;
16735 /* Some type attributes reference an outer type. For instance, the upper
16736 bound of an array may reference an embedding record (this happens in
16738 if (TREE_CODE (value
) == COMPONENT_REF
16739 && TREE_CODE (TREE_OPERAND (value
, 0)) == PLACEHOLDER_EXPR
16740 && TREE_CODE (TREE_OPERAND (value
, 1)) == FIELD_DECL
)
16741 decl
= TREE_OPERAND (value
, 1);
16743 else if (TREE_CODE (value
) == VAR_DECL
16744 || TREE_CODE (value
) == PARM_DECL
16745 || TREE_CODE (value
) == RESULT_DECL
)
16748 if (decl
!= NULL_TREE
)
16750 dw_die_ref decl_die
= lookup_decl_die (decl
);
16752 /* ??? Can this happen, or should the variable have been bound
16753 first? Probably it can, since I imagine that we try to create
16754 the types of parameters in the order in which they exist in
16755 the list, and won't have created a forward reference to a
16756 later parameter. */
16757 if (decl_die
!= NULL
)
16759 add_AT_die_ref (die
, attr
, decl_die
);
16765 /* Last chance: try to create a stack operation procedure to evaluate the
16766 value. Do nothing if even that is not possible or permitted. */
16767 if ((forms
& dw_scalar_form_exprloc
) == 0)
16770 list
= loc_list_from_tree (value
, 2, context
);
16771 if (list
== NULL
|| single_element_loc_list_p (list
))
16773 /* If this attribute is not a reference nor constant, it is
16774 a DWARF expression rather than location description. For that
16775 loc_list_from_tree (value, 0, &context) is needed. */
16776 dw_loc_list_ref list2
= loc_list_from_tree (value
, 0, context
);
16777 if (list2
&& single_element_loc_list_p (list2
))
16779 add_AT_loc (die
, attr
, list2
->expr
);
16784 /* If that failed to give a single element location list, fall back to
16785 outputting this as a reference... still if permitted. */
16786 if (list
== NULL
|| (forms
& dw_scalar_form_reference
) == 0)
16789 if (current_function_decl
== 0)
16790 ctx
= comp_unit_die ();
16792 ctx
= lookup_decl_die (current_function_decl
);
16794 decl_die
= new_die (DW_TAG_variable
, ctx
, value
);
16795 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
16796 add_type_attribute (decl_die
, TREE_TYPE (value
), TYPE_QUAL_CONST
, ctx
);
16797 add_AT_location_description (decl_die
, DW_AT_location
, list
);
16798 add_AT_die_ref (die
, attr
, decl_die
);
16801 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
16805 lower_bound_default (void)
16807 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
16813 case DW_LANG_C_plus_plus
:
16814 case DW_LANG_C_plus_plus_11
:
16815 case DW_LANG_C_plus_plus_14
:
16817 case DW_LANG_ObjC_plus_plus
:
16820 case DW_LANG_Fortran77
:
16821 case DW_LANG_Fortran90
:
16822 case DW_LANG_Fortran95
:
16823 case DW_LANG_Fortran03
:
16824 case DW_LANG_Fortran08
:
16828 case DW_LANG_Python
:
16829 return dwarf_version
>= 4 ? 0 : -1;
16830 case DW_LANG_Ada95
:
16831 case DW_LANG_Ada83
:
16832 case DW_LANG_Cobol74
:
16833 case DW_LANG_Cobol85
:
16834 case DW_LANG_Pascal83
:
16835 case DW_LANG_Modula2
:
16837 return dwarf_version
>= 4 ? 1 : -1;
16843 /* Given a tree node describing an array bound (either lower or upper) output
16844 a representation for that bound. */
16847 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
,
16848 tree bound
, const struct loc_descr_context
*context
)
16853 switch (TREE_CODE (bound
))
16855 /* Strip all conversions. */
16857 case VIEW_CONVERT_EXPR
:
16858 bound
= TREE_OPERAND (bound
, 0);
16861 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
16862 are even omitted when they are the default. */
16864 /* If the value for this bound is the default one, we can even omit the
16866 if (bound_attr
== DW_AT_lower_bound
16867 && tree_fits_shwi_p (bound
)
16868 && (dflt
= lower_bound_default ()) != -1
16869 && tree_to_shwi (bound
) == dflt
)
16875 add_scalar_info (subrange_die
, bound_attr
, bound
,
16876 dw_scalar_form_constant
16877 | dw_scalar_form_exprloc
16878 | dw_scalar_form_reference
,
16884 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16885 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16886 Note that the block of subscript information for an array type also
16887 includes information about the element type of the given array type.
16889 This function reuses previously set type and bound information if
16893 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
16895 unsigned dimension_number
;
16897 dw_die_ref child
= type_die
->die_child
;
16899 for (dimension_number
= 0;
16900 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
16901 type
= TREE_TYPE (type
), dimension_number
++)
16903 tree domain
= TYPE_DOMAIN (type
);
16905 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
16908 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16909 and (in GNU C only) variable bounds. Handle all three forms
16912 /* Find and reuse a previously generated DW_TAG_subrange_type if
16915 For multi-dimensional arrays, as we iterate through the
16916 various dimensions in the enclosing for loop above, we also
16917 iterate through the DIE children and pick at each
16918 DW_TAG_subrange_type previously generated (if available).
16919 Each child DW_TAG_subrange_type DIE describes the range of
16920 the current dimension. At this point we should have as many
16921 DW_TAG_subrange_type's as we have dimensions in the
16923 dw_die_ref subrange_die
= NULL
;
16927 child
= child
->die_sib
;
16928 if (child
->die_tag
== DW_TAG_subrange_type
)
16929 subrange_die
= child
;
16930 if (child
== type_die
->die_child
)
16932 /* If we wrapped around, stop looking next time. */
16936 if (child
->die_tag
== DW_TAG_subrange_type
)
16940 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
16944 /* We have an array type with specified bounds. */
16945 lower
= TYPE_MIN_VALUE (domain
);
16946 upper
= TYPE_MAX_VALUE (domain
);
16948 /* Define the index type. */
16949 if (TREE_TYPE (domain
)
16950 && !get_AT (subrange_die
, DW_AT_type
))
16952 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16953 TREE_TYPE field. We can't emit debug info for this
16954 because it is an unnamed integral type. */
16955 if (TREE_CODE (domain
) == INTEGER_TYPE
16956 && TYPE_NAME (domain
) == NULL_TREE
16957 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
16958 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
16961 add_type_attribute (subrange_die
, TREE_TYPE (domain
),
16962 TYPE_UNQUALIFIED
, type_die
);
16965 /* ??? If upper is NULL, the array has unspecified length,
16966 but it does have a lower bound. This happens with Fortran
16968 Since the debugger is definitely going to need to know N
16969 to produce useful results, go ahead and output the lower
16970 bound solo, and hope the debugger can cope. */
16972 if (!get_AT (subrange_die
, DW_AT_lower_bound
))
16973 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
, NULL
);
16974 if (upper
&& !get_AT (subrange_die
, DW_AT_upper_bound
))
16975 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
, NULL
);
16978 /* Otherwise we have an array type with an unspecified length. The
16979 DWARF-2 spec does not say how to handle this; let's just leave out the
16984 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
16987 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16989 dw_die_ref decl_die
;
16990 HOST_WIDE_INT size
;
16992 switch (TREE_CODE (tree_node
))
16997 case ENUMERAL_TYPE
:
17000 case QUAL_UNION_TYPE
:
17001 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
17002 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
17004 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
17007 size
= int_size_in_bytes (tree_node
);
17010 /* For a data member of a struct or union, the DW_AT_byte_size is
17011 generally given as the number of bytes normally allocated for an
17012 object of the *declared* type of the member itself. This is true
17013 even for bit-fields. */
17014 size
= int_size_in_bytes (field_type (tree_node
));
17017 gcc_unreachable ();
17020 /* Note that `size' might be -1 when we get to this point. If it is, that
17021 indicates that the byte size of the entity in question is variable. We
17022 have no good way of expressing this fact in Dwarf at the present time,
17023 when location description was not used by the caller code instead. */
17025 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
17028 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17029 which specifies the distance in bits from the highest order bit of the
17030 "containing object" for the bit-field to the highest order bit of the
17033 For any given bit-field, the "containing object" is a hypothetical object
17034 (of some integral or enum type) within which the given bit-field lives. The
17035 type of this hypothetical "containing object" is always the same as the
17036 declared type of the individual bit-field itself. The determination of the
17037 exact location of the "containing object" for a bit-field is rather
17038 complicated. It's handled by the `field_byte_offset' function (above).
17040 Note that it is the size (in bytes) of the hypothetical "containing object"
17041 which will be given in the DW_AT_byte_size attribute for this bit-field.
17042 (See `byte_size_attribute' above). */
17045 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
17047 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
17048 tree type
= DECL_BIT_FIELD_TYPE (decl
);
17049 HOST_WIDE_INT bitpos_int
;
17050 HOST_WIDE_INT highest_order_object_bit_offset
;
17051 HOST_WIDE_INT highest_order_field_bit_offset
;
17052 HOST_WIDE_INT bit_offset
;
17054 /* Must be a field and a bit field. */
17055 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
17057 /* We can't yet handle bit-fields whose offsets are variable, so if we
17058 encounter such things, just return without generating any attribute
17059 whatsoever. Likewise for variable or too large size. */
17060 if (! tree_fits_shwi_p (bit_position (decl
))
17061 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
17064 bitpos_int
= int_bit_position (decl
);
17066 /* Note that the bit offset is always the distance (in bits) from the
17067 highest-order bit of the "containing object" to the highest-order bit of
17068 the bit-field itself. Since the "high-order end" of any object or field
17069 is different on big-endian and little-endian machines, the computation
17070 below must take account of these differences. */
17071 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
17072 highest_order_field_bit_offset
= bitpos_int
;
17074 if (! BYTES_BIG_ENDIAN
)
17076 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
17077 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
17081 = (! BYTES_BIG_ENDIAN
17082 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
17083 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
17085 if (bit_offset
< 0)
17086 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
17088 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
17091 /* For a FIELD_DECL node which represents a bit field, output an attribute
17092 which specifies the length in bits of the given field. */
17095 add_bit_size_attribute (dw_die_ref die
, tree decl
)
17097 /* Must be a field and a bit field. */
17098 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
17099 && DECL_BIT_FIELD_TYPE (decl
));
17101 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
17102 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
17105 /* If the compiled language is ANSI C, then add a 'prototyped'
17106 attribute, if arg types are given for the parameters of a function. */
17109 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
17111 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
17118 if (prototype_p (func_type
))
17119 add_AT_flag (die
, DW_AT_prototyped
, 1);
17126 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17127 by looking in either the type declaration or object declaration
17130 static inline dw_die_ref
17131 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
17133 dw_die_ref origin_die
= NULL
;
17135 if (TREE_CODE (origin
) != FUNCTION_DECL
)
17137 /* We may have gotten separated from the block for the inlined
17138 function, if we're in an exception handler or some such; make
17139 sure that the abstract function has been written out.
17141 Doing this for nested functions is wrong, however; functions are
17142 distinct units, and our context might not even be inline. */
17146 fn
= TYPE_STUB_DECL (fn
);
17148 fn
= decl_function_context (fn
);
17150 dwarf2out_abstract_function (fn
);
17153 if (DECL_P (origin
))
17154 origin_die
= lookup_decl_die (origin
);
17155 else if (TYPE_P (origin
))
17156 origin_die
= lookup_type_die (origin
);
17158 /* XXX: Functions that are never lowered don't always have correct block
17159 trees (in the case of java, they simply have no block tree, in some other
17160 languages). For these functions, there is nothing we can really do to
17161 output correct debug info for inlined functions in all cases. Rather
17162 than die, we'll just produce deficient debug info now, in that we will
17163 have variables without a proper abstract origin. In the future, when all
17164 functions are lowered, we should re-add a gcc_assert (origin_die)
17168 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
17172 /* We do not currently support the pure_virtual attribute. */
17175 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
17177 if (DECL_VINDEX (func_decl
))
17179 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
17181 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
17182 add_AT_loc (die
, DW_AT_vtable_elem_location
,
17183 new_loc_descr (DW_OP_constu
,
17184 tree_to_shwi (DECL_VINDEX (func_decl
)),
17187 /* GNU extension: Record what type this method came from originally. */
17188 if (debug_info_level
> DINFO_LEVEL_TERSE
17189 && DECL_CONTEXT (func_decl
))
17190 add_AT_die_ref (die
, DW_AT_containing_type
,
17191 lookup_type_die (DECL_CONTEXT (func_decl
)));
17195 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
17196 given decl. This used to be a vendor extension until after DWARF 4
17197 standardized it. */
17200 add_linkage_attr (dw_die_ref die
, tree decl
)
17202 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
17204 /* Mimic what assemble_name_raw does with a leading '*'. */
17205 if (name
[0] == '*')
17208 if (dwarf_version
>= 4)
17209 add_AT_string (die
, DW_AT_linkage_name
, name
);
17211 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
17214 /* Add source coordinate attributes for the given decl. */
17217 add_src_coords_attributes (dw_die_ref die
, tree decl
)
17219 expanded_location s
;
17221 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
17223 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17224 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
17225 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
17228 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
17231 add_linkage_name (dw_die_ref die
, tree decl
)
17233 if (debug_info_level
> DINFO_LEVEL_NONE
17234 && (TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
17235 && TREE_PUBLIC (decl
)
17236 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
17237 && die
->die_tag
!= DW_TAG_member
)
17239 /* Defer until we have an assembler name set. */
17240 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
17242 limbo_die_node
*asm_name
;
17244 asm_name
= ggc_cleared_alloc
<limbo_die_node
> ();
17245 asm_name
->die
= die
;
17246 asm_name
->created_for
= decl
;
17247 asm_name
->next
= deferred_asm_name
;
17248 deferred_asm_name
= asm_name
;
17250 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
17251 add_linkage_attr (die
, decl
);
17255 /* Add a DW_AT_name attribute and source coordinate attribute for the
17256 given decl, but only if it actually has a name. */
17259 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
17263 decl_name
= DECL_NAME (decl
);
17264 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
17266 const char *name
= dwarf2_name (decl
, 0);
17268 add_name_attribute (die
, name
);
17269 if (! DECL_ARTIFICIAL (decl
))
17270 add_src_coords_attributes (die
, decl
);
17272 add_linkage_name (die
, decl
);
17275 #ifdef VMS_DEBUGGING_INFO
17276 /* Get the function's name, as described by its RTL. This may be different
17277 from the DECL_NAME name used in the source file. */
17278 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
17280 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
17281 XEXP (DECL_RTL (decl
), 0), false);
17282 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
17284 #endif /* VMS_DEBUGGING_INFO */
17287 #ifdef VMS_DEBUGGING_INFO
17288 /* Output the debug main pointer die for VMS */
17291 dwarf2out_vms_debug_main_pointer (void)
17293 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
17296 /* Allocate the VMS debug main subprogram die. */
17297 die
= ggc_cleared_alloc
<die_node
> ();
17298 die
->die_tag
= DW_TAG_subprogram
;
17299 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
17300 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
17301 current_function_funcdef_no
);
17302 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
17304 /* Make it the first child of comp_unit_die (). */
17305 die
->die_parent
= comp_unit_die ();
17306 if (comp_unit_die ()->die_child
)
17308 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
17309 comp_unit_die ()->die_child
->die_sib
= die
;
17313 die
->die_sib
= die
;
17314 comp_unit_die ()->die_child
= die
;
17317 #endif /* VMS_DEBUGGING_INFO */
17319 /* Push a new declaration scope. */
17322 push_decl_scope (tree scope
)
17324 vec_safe_push (decl_scope_table
, scope
);
17327 /* Pop a declaration scope. */
17330 pop_decl_scope (void)
17332 decl_scope_table
->pop ();
17335 /* walk_tree helper function for uses_local_type, below. */
17338 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
17341 *walk_subtrees
= 0;
17344 tree name
= TYPE_NAME (*tp
);
17345 if (name
&& DECL_P (name
) && decl_function_context (name
))
17351 /* If TYPE involves a function-local type (including a local typedef to a
17352 non-local type), returns that type; otherwise returns NULL_TREE. */
17355 uses_local_type (tree type
)
17357 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
17361 /* Return the DIE for the scope that immediately contains this type.
17362 Non-named types that do not involve a function-local type get global
17363 scope. Named types nested in namespaces or other types get their
17364 containing scope. All other types (i.e. function-local named types) get
17365 the current active scope. */
17368 scope_die_for (tree t
, dw_die_ref context_die
)
17370 dw_die_ref scope_die
= NULL
;
17371 tree containing_scope
;
17373 /* Non-types always go in the current scope. */
17374 gcc_assert (TYPE_P (t
));
17376 /* Use the scope of the typedef, rather than the scope of the type
17378 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
17379 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
17381 containing_scope
= TYPE_CONTEXT (t
);
17383 /* Use the containing namespace if there is one. */
17384 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
17386 if (context_die
== lookup_decl_die (containing_scope
))
17388 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
17389 context_die
= get_context_die (containing_scope
);
17391 containing_scope
= NULL_TREE
;
17394 /* Ignore function type "scopes" from the C frontend. They mean that
17395 a tagged type is local to a parmlist of a function declarator, but
17396 that isn't useful to DWARF. */
17397 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
17398 containing_scope
= NULL_TREE
;
17400 if (SCOPE_FILE_SCOPE_P (containing_scope
))
17402 /* If T uses a local type keep it local as well, to avoid references
17403 to function-local DIEs from outside the function. */
17404 if (current_function_decl
&& uses_local_type (t
))
17405 scope_die
= context_die
;
17407 scope_die
= comp_unit_die ();
17409 else if (TYPE_P (containing_scope
))
17411 /* For types, we can just look up the appropriate DIE. */
17412 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17413 scope_die
= get_context_die (containing_scope
);
17416 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
17417 if (scope_die
== NULL
)
17418 scope_die
= comp_unit_die ();
17422 scope_die
= context_die
;
17427 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
17430 local_scope_p (dw_die_ref context_die
)
17432 for (; context_die
; context_die
= context_die
->die_parent
)
17433 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
17434 || context_die
->die_tag
== DW_TAG_subprogram
)
17440 /* Returns nonzero if CONTEXT_DIE is a class. */
17443 class_scope_p (dw_die_ref context_die
)
17445 return (context_die
17446 && (context_die
->die_tag
== DW_TAG_structure_type
17447 || context_die
->die_tag
== DW_TAG_class_type
17448 || context_die
->die_tag
== DW_TAG_interface_type
17449 || context_die
->die_tag
== DW_TAG_union_type
));
17452 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
17453 whether or not to treat a DIE in this context as a declaration. */
17456 class_or_namespace_scope_p (dw_die_ref context_die
)
17458 return (class_scope_p (context_die
)
17459 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
17462 /* Many forms of DIEs require a "type description" attribute. This
17463 routine locates the proper "type descriptor" die for the type given
17464 by 'type' plus any additional qualifiers given by 'cv_quals', and
17465 adds a DW_AT_type attribute below the given die. */
17468 add_type_attribute (dw_die_ref object_die
, tree type
, int cv_quals
,
17469 dw_die_ref context_die
)
17471 enum tree_code code
= TREE_CODE (type
);
17472 dw_die_ref type_die
= NULL
;
17474 /* ??? If this type is an unnamed subrange type of an integral, floating-point
17475 or fixed-point type, use the inner type. This is because we have no
17476 support for unnamed types in base_type_die. This can happen if this is
17477 an Ada subrange type. Correct solution is emit a subrange type die. */
17478 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
17479 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
17480 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
17482 if (code
== ERROR_MARK
17483 /* Handle a special case. For functions whose return type is void, we
17484 generate *no* type attribute. (Note that no object may have type
17485 `void', so this only applies to function return types). */
17486 || code
== VOID_TYPE
)
17489 type_die
= modified_type_die (type
,
17490 cv_quals
| TYPE_QUALS_NO_ADDR_SPACE (type
),
17493 if (type_die
!= NULL
)
17494 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
17497 /* Given an object die, add the calling convention attribute for the
17498 function call type. */
17500 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
17502 enum dwarf_calling_convention value
= DW_CC_normal
;
17504 value
= ((enum dwarf_calling_convention
)
17505 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
17508 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
17510 /* DWARF 2 doesn't provide a way to identify a program's source-level
17511 entry point. DW_AT_calling_convention attributes are only meant
17512 to describe functions' calling conventions. However, lacking a
17513 better way to signal the Fortran main program, we used this for
17514 a long time, following existing custom. Now, DWARF 4 has
17515 DW_AT_main_subprogram, which we add below, but some tools still
17516 rely on the old way, which we thus keep. */
17517 value
= DW_CC_program
;
17519 if (dwarf_version
>= 4 || !dwarf_strict
)
17520 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
17523 /* Only add the attribute if the backend requests it, and
17524 is not DW_CC_normal. */
17525 if (value
&& (value
!= DW_CC_normal
))
17526 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
17529 /* Given a tree pointer to a struct, class, union, or enum type node, return
17530 a pointer to the (string) tag name for the given type, or zero if the type
17531 was declared without a tag. */
17533 static const char *
17534 type_tag (const_tree type
)
17536 const char *name
= 0;
17538 if (TYPE_NAME (type
) != 0)
17542 /* Find the IDENTIFIER_NODE for the type name. */
17543 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
17544 && !TYPE_NAMELESS (type
))
17545 t
= TYPE_NAME (type
);
17547 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
17548 a TYPE_DECL node, regardless of whether or not a `typedef' was
17550 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
17551 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
17553 /* We want to be extra verbose. Don't call dwarf_name if
17554 DECL_NAME isn't set. The default hook for decl_printable_name
17555 doesn't like that, and in this context it's correct to return
17556 0, instead of "<anonymous>" or the like. */
17557 if (DECL_NAME (TYPE_NAME (type
))
17558 && !DECL_NAMELESS (TYPE_NAME (type
)))
17559 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
17562 /* Now get the name as a string, or invent one. */
17563 if (!name
&& t
!= 0)
17564 name
= IDENTIFIER_POINTER (t
);
17567 return (name
== 0 || *name
== '\0') ? 0 : name
;
17570 /* Return the type associated with a data member, make a special check
17571 for bit field types. */
17574 member_declared_type (const_tree member
)
17576 return (DECL_BIT_FIELD_TYPE (member
)
17577 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
17580 /* Get the decl's label, as described by its RTL. This may be different
17581 from the DECL_NAME name used in the source file. */
17584 static const char *
17585 decl_start_label (tree decl
)
17588 const char *fnname
;
17590 x
= DECL_RTL (decl
);
17591 gcc_assert (MEM_P (x
));
17594 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
17596 fnname
= XSTR (x
, 0);
17601 /* For variable-length arrays that have been previously generated, but
17602 may be incomplete due to missing subscript info, fill the subscript
17603 info. Return TRUE if this is one of those cases. */
17605 fill_variable_array_bounds (tree type
)
17607 if (TREE_ASM_WRITTEN (type
)
17608 && TREE_CODE (type
) == ARRAY_TYPE
17609 && variably_modified_type_p (type
, NULL
))
17611 dw_die_ref array_die
= lookup_type_die (type
);
17614 add_subscript_info (array_die
, type
, !is_ada ());
17620 /* These routines generate the internal representation of the DIE's for
17621 the compilation unit. Debugging information is collected by walking
17622 the declaration trees passed in from dwarf2out_decl(). */
17625 gen_array_type_die (tree type
, dw_die_ref context_die
)
17627 dw_die_ref array_die
;
17629 /* GNU compilers represent multidimensional array types as sequences of one
17630 dimensional array types whose element types are themselves array types.
17631 We sometimes squish that down to a single array_type DIE with multiple
17632 subscripts in the Dwarf debugging info. The draft Dwarf specification
17633 say that we are allowed to do this kind of compression in C, because
17634 there is no difference between an array of arrays and a multidimensional
17635 array. We don't do this for Ada to remain as close as possible to the
17636 actual representation, which is especially important against the language
17637 flexibilty wrt arrays of variable size. */
17639 bool collapse_nested_arrays
= !is_ada ();
17641 if (fill_variable_array_bounds (type
))
17644 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17647 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
17648 DW_TAG_string_type doesn't have DW_AT_type attribute). */
17649 if (TYPE_STRING_FLAG (type
)
17650 && TREE_CODE (type
) == ARRAY_TYPE
17652 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
17654 HOST_WIDE_INT size
;
17656 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
17657 add_name_attribute (array_die
, type_tag (type
));
17658 equate_type_number_to_die (type
, array_die
);
17659 size
= int_size_in_bytes (type
);
17661 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17662 else if (TYPE_DOMAIN (type
) != NULL_TREE
17663 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
17664 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
17666 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
17667 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2, NULL
);
17669 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
17670 if (loc
&& size
> 0)
17672 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
17673 if (size
!= DWARF2_ADDR_SIZE
)
17674 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17680 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17681 add_name_attribute (array_die
, type_tag (type
));
17682 equate_type_number_to_die (type
, array_die
);
17684 if (TREE_CODE (type
) == VECTOR_TYPE
)
17685 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
17687 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17689 && TREE_CODE (type
) == ARRAY_TYPE
17690 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
17691 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
17692 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17695 /* We default the array ordering. SDB will probably do
17696 the right things even if DW_AT_ordering is not present. It's not even
17697 an issue until we start to get into multidimensional arrays anyway. If
17698 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
17699 then we'll have to put the DW_AT_ordering attribute back in. (But if
17700 and when we find out that we need to put these in, we will only do so
17701 for multidimensional arrays. */
17702 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
17705 if (TREE_CODE (type
) == VECTOR_TYPE
)
17707 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
17708 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17709 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
, NULL
);
17710 add_bound_info (subrange_die
, DW_AT_upper_bound
,
17711 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1), NULL
);
17714 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
17716 /* Add representation of the type of the elements of this array type and
17717 emit the corresponding DIE if we haven't done it already. */
17718 element_type
= TREE_TYPE (type
);
17719 if (collapse_nested_arrays
)
17720 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
17722 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
17724 element_type
= TREE_TYPE (element_type
);
17727 add_type_attribute (array_die
, element_type
, TYPE_UNQUALIFIED
, context_die
);
17729 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
17730 if (TYPE_ARTIFICIAL (type
))
17731 add_AT_flag (array_die
, DW_AT_artificial
, 1);
17733 if (get_AT (array_die
, DW_AT_name
))
17734 add_pubtype (type
, array_die
);
17737 /* This routine generates DIE for array with hidden descriptor, details
17738 are filled into *info by a langhook. */
17741 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
17742 dw_die_ref context_die
)
17744 const dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17745 const dw_die_ref array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17746 const struct loc_descr_context context
= { type
, info
->base_decl
};
17749 add_name_attribute (array_die
, type_tag (type
));
17750 equate_type_number_to_die (type
, array_die
);
17752 if (info
->ndimensions
> 1)
17753 switch (info
->ordering
)
17755 case array_descr_ordering_row_major
:
17756 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
17758 case array_descr_ordering_column_major
:
17759 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17765 if (dwarf_version
>= 3 || !dwarf_strict
)
17767 if (info
->data_location
)
17768 add_scalar_info (array_die
, DW_AT_data_location
, info
->data_location
,
17769 dw_scalar_form_exprloc
, &context
);
17770 if (info
->associated
)
17771 add_scalar_info (array_die
, DW_AT_associated
, info
->associated
,
17772 dw_scalar_form_constant
17773 | dw_scalar_form_exprloc
17774 | dw_scalar_form_reference
, &context
);
17775 if (info
->allocated
)
17776 add_scalar_info (array_die
, DW_AT_allocated
, info
->allocated
,
17777 dw_scalar_form_constant
17778 | dw_scalar_form_exprloc
17779 | dw_scalar_form_reference
, &context
);
17782 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
17784 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
17786 dw_die_ref subrange_die
17787 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17789 if (info
->dimen
[dim
].bounds_type
)
17790 add_type_attribute (subrange_die
,
17791 info
->dimen
[dim
].bounds_type
, 0,
17793 if (info
->dimen
[dim
].lower_bound
)
17794 add_bound_info (subrange_die
, DW_AT_lower_bound
,
17795 info
->dimen
[dim
].lower_bound
, &context
);
17796 if (info
->dimen
[dim
].upper_bound
)
17797 add_bound_info (subrange_die
, DW_AT_upper_bound
,
17798 info
->dimen
[dim
].upper_bound
, &context
);
17799 if ((dwarf_version
>= 3 || !dwarf_strict
) && info
->dimen
[dim
].stride
)
17800 add_scalar_info (subrange_die
, DW_AT_byte_stride
,
17801 info
->dimen
[dim
].stride
,
17802 dw_scalar_form_constant
17803 | dw_scalar_form_exprloc
17804 | dw_scalar_form_reference
,
17808 gen_type_die (info
->element_type
, context_die
);
17809 add_type_attribute (array_die
, info
->element_type
, TYPE_UNQUALIFIED
,
17812 if (get_AT (array_die
, DW_AT_name
))
17813 add_pubtype (type
, array_die
);
17818 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
17820 tree origin
= decl_ultimate_origin (decl
);
17821 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
17823 if (origin
!= NULL
)
17824 add_abstract_origin_attribute (decl_die
, origin
);
17827 add_name_and_src_coords_attributes (decl_die
, decl
);
17828 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
17829 TYPE_UNQUALIFIED
, context_die
);
17832 if (DECL_ABSTRACT_P (decl
))
17833 equate_decl_number_to_die (decl
, decl_die
);
17835 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
17839 /* Walk through the list of incomplete types again, trying once more to
17840 emit full debugging info for them. */
17843 retry_incomplete_types (void)
17847 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
17848 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
17849 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
17852 /* Determine what tag to use for a record type. */
17854 static enum dwarf_tag
17855 record_type_tag (tree type
)
17857 if (! lang_hooks
.types
.classify_record
)
17858 return DW_TAG_structure_type
;
17860 switch (lang_hooks
.types
.classify_record (type
))
17862 case RECORD_IS_STRUCT
:
17863 return DW_TAG_structure_type
;
17865 case RECORD_IS_CLASS
:
17866 return DW_TAG_class_type
;
17868 case RECORD_IS_INTERFACE
:
17869 if (dwarf_version
>= 3 || !dwarf_strict
)
17870 return DW_TAG_interface_type
;
17871 return DW_TAG_structure_type
;
17874 gcc_unreachable ();
17878 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17879 include all of the information about the enumeration values also. Each
17880 enumerated type name/value is listed as a child of the enumerated type
17884 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
17886 dw_die_ref type_die
= lookup_type_die (type
);
17888 if (type_die
== NULL
)
17890 type_die
= new_die (DW_TAG_enumeration_type
,
17891 scope_die_for (type
, context_die
), type
);
17892 equate_type_number_to_die (type
, type_die
);
17893 add_name_attribute (type_die
, type_tag (type
));
17894 if (dwarf_version
>= 4 || !dwarf_strict
)
17896 if (ENUM_IS_SCOPED (type
))
17897 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
17898 if (ENUM_IS_OPAQUE (type
))
17899 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17902 else if (! TYPE_SIZE (type
))
17905 remove_AT (type_die
, DW_AT_declaration
);
17907 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17908 given enum type is incomplete, do not generate the DW_AT_byte_size
17909 attribute or the DW_AT_element_list attribute. */
17910 if (TYPE_SIZE (type
))
17914 TREE_ASM_WRITTEN (type
) = 1;
17915 add_byte_size_attribute (type_die
, type
);
17916 if (dwarf_version
>= 3 || !dwarf_strict
)
17918 tree underlying
= lang_hooks
.types
.enum_underlying_base_type (type
);
17919 add_type_attribute (type_die
, underlying
, TYPE_UNQUALIFIED
,
17922 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17924 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17925 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17928 /* If the first reference to this type was as the return type of an
17929 inline function, then it may not have a parent. Fix this now. */
17930 if (type_die
->die_parent
== NULL
)
17931 add_child_die (scope_die_for (type
, context_die
), type_die
);
17933 for (link
= TYPE_VALUES (type
);
17934 link
!= NULL
; link
= TREE_CHAIN (link
))
17936 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17937 tree value
= TREE_VALUE (link
);
17939 add_name_attribute (enum_die
,
17940 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17942 if (TREE_CODE (value
) == CONST_DECL
)
17943 value
= DECL_INITIAL (value
);
17945 if (simple_type_size_in_bits (TREE_TYPE (value
))
17946 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
17948 /* For constant forms created by add_AT_unsigned DWARF
17949 consumers (GDB, elfutils, etc.) always zero extend
17950 the value. Only when the actual value is negative
17951 do we need to use add_AT_int to generate a constant
17952 form that can represent negative values. */
17953 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
17954 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
17955 add_AT_unsigned (enum_die
, DW_AT_const_value
,
17956 (unsigned HOST_WIDE_INT
) val
);
17958 add_AT_int (enum_die
, DW_AT_const_value
, val
);
17961 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
17962 that here. TODO: This should be re-worked to use correct
17963 signed/unsigned double tags for all cases. */
17964 add_AT_wide (enum_die
, DW_AT_const_value
, value
);
17967 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17968 if (TYPE_ARTIFICIAL (type
))
17969 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17972 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17974 add_pubtype (type
, type_die
);
17979 /* Generate a DIE to represent either a real live formal parameter decl or to
17980 represent just the type of some formal parameter position in some function
17983 Note that this routine is a bit unusual because its argument may be a
17984 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17985 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17986 node. If it's the former then this function is being called to output a
17987 DIE to represent a formal parameter object (or some inlining thereof). If
17988 it's the latter, then this function is only being called to output a
17989 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17990 argument type of some subprogram type.
17991 If EMIT_NAME_P is true, name and source coordinate attributes
17995 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17996 dw_die_ref context_die
)
17998 tree node_or_origin
= node
? node
: origin
;
17999 tree ultimate_origin
;
18000 dw_die_ref parm_die
= NULL
;
18002 if (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)) == tcc_declaration
)
18004 parm_die
= lookup_decl_die (node
);
18006 /* If the contexts differ, we may not be talking about the same
18008 if (parm_die
&& parm_die
->die_parent
!= context_die
)
18010 if (!DECL_ABSTRACT_P (node
))
18012 /* This can happen when creating an inlined instance, in
18013 which case we need to create a new DIE that will get
18014 annotated with DW_AT_abstract_origin. */
18019 /* FIXME: Reuse DIE even with a differing context.
18021 This can happen when calling
18022 dwarf2out_abstract_function to build debug info for
18023 the abstract instance of a function for which we have
18024 already generated a DIE in
18025 dwarf2out_early_global_decl.
18027 Once we remove dwarf2out_abstract_function, we should
18028 have a call to gcc_unreachable here. */
18032 if (parm_die
&& parm_die
->die_parent
== NULL
)
18034 /* Check that parm_die already has the right attributes that
18035 we would have added below. If any attributes are
18036 missing, fall through to add them. */
18037 if (! DECL_ABSTRACT_P (node_or_origin
)
18038 && !get_AT (parm_die
, DW_AT_location
)
18039 && !get_AT (parm_die
, DW_AT_const_value
))
18040 /* We are missing location info, and are about to add it. */
18044 add_child_die (context_die
, parm_die
);
18050 /* If we have a previously generated DIE, use it, unless this is an
18051 concrete instance (origin != NULL), in which case we need a new
18052 DIE with a corresponding DW_AT_abstract_origin. */
18054 if (parm_die
&& origin
== NULL
)
18055 reusing_die
= true;
18058 parm_die
= new_die (DW_TAG_formal_parameter
, context_die
, node
);
18059 reusing_die
= false;
18062 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
18064 case tcc_declaration
:
18065 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
18066 if (node
|| ultimate_origin
)
18067 origin
= ultimate_origin
;
18072 if (origin
!= NULL
)
18073 add_abstract_origin_attribute (parm_die
, origin
);
18074 else if (emit_name_p
)
18075 add_name_and_src_coords_attributes (parm_die
, node
);
18077 || (! DECL_ABSTRACT_P (node_or_origin
)
18078 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
18079 decl_function_context
18080 (node_or_origin
))))
18082 tree type
= TREE_TYPE (node_or_origin
);
18083 if (decl_by_reference_p (node_or_origin
))
18084 add_type_attribute (parm_die
, TREE_TYPE (type
),
18085 TYPE_UNQUALIFIED
, context_die
);
18087 add_type_attribute (parm_die
, type
,
18088 decl_quals (node_or_origin
),
18091 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
18092 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18094 if (node
&& node
!= origin
)
18095 equate_decl_number_to_die (node
, parm_die
);
18096 if (! DECL_ABSTRACT_P (node_or_origin
))
18097 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
18098 node
== NULL
, DW_AT_location
);
18103 /* We were called with some kind of a ..._TYPE node. */
18104 add_type_attribute (parm_die
, node_or_origin
, TYPE_UNQUALIFIED
,
18109 gcc_unreachable ();
18115 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18116 children DW_TAG_formal_parameter DIEs representing the arguments of the
18119 PARM_PACK must be a function parameter pack.
18120 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18121 must point to the subsequent arguments of the function PACK_ARG belongs to.
18122 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18123 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18124 following the last one for which a DIE was generated. */
18127 gen_formal_parameter_pack_die (tree parm_pack
,
18129 dw_die_ref subr_die
,
18133 dw_die_ref parm_pack_die
;
18135 gcc_assert (parm_pack
18136 && lang_hooks
.function_parameter_pack_p (parm_pack
)
18139 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
18140 add_src_coords_attributes (parm_pack_die
, parm_pack
);
18142 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
18144 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
18147 gen_formal_parameter_die (arg
, NULL
,
18148 false /* Don't emit name attribute. */,
18153 return parm_pack_die
;
18156 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18157 at the end of an (ANSI prototyped) formal parameters list. */
18160 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
18162 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
18165 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18166 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18167 parameters as specified in some function type specification (except for
18168 those which appear as part of a function *definition*). */
18171 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
18174 tree formal_type
= NULL
;
18175 tree first_parm_type
;
18178 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
18180 arg
= DECL_ARGUMENTS (function_or_method_type
);
18181 function_or_method_type
= TREE_TYPE (function_or_method_type
);
18186 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
18188 /* Make our first pass over the list of formal parameter types and output a
18189 DW_TAG_formal_parameter DIE for each one. */
18190 for (link
= first_parm_type
; link
; )
18192 dw_die_ref parm_die
;
18194 formal_type
= TREE_VALUE (link
);
18195 if (formal_type
== void_type_node
)
18198 /* Output a (nameless) DIE to represent the formal parameter itself. */
18199 if (!POINTER_BOUNDS_TYPE_P (formal_type
))
18201 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
18202 true /* Emit name attribute. */,
18204 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
18205 && link
== first_parm_type
)
18207 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18208 if (dwarf_version
>= 3 || !dwarf_strict
)
18209 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
18211 else if (arg
&& DECL_ARTIFICIAL (arg
))
18212 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18215 link
= TREE_CHAIN (link
);
18217 arg
= DECL_CHAIN (arg
);
18220 /* If this function type has an ellipsis, add a
18221 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18222 if (formal_type
!= void_type_node
)
18223 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
18225 /* Make our second (and final) pass over the list of formal parameter types
18226 and output DIEs to represent those types (as necessary). */
18227 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
18228 link
&& TREE_VALUE (link
);
18229 link
= TREE_CHAIN (link
))
18230 gen_type_die (TREE_VALUE (link
), context_die
);
18233 /* We want to generate the DIE for TYPE so that we can generate the
18234 die for MEMBER, which has been defined; we will need to refer back
18235 to the member declaration nested within TYPE. If we're trying to
18236 generate minimal debug info for TYPE, processing TYPE won't do the
18237 trick; we need to attach the member declaration by hand. */
18240 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
18242 gen_type_die (type
, context_die
);
18244 /* If we're trying to avoid duplicate debug info, we may not have
18245 emitted the member decl for this function. Emit it now. */
18246 if (TYPE_STUB_DECL (type
)
18247 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
18248 && ! lookup_decl_die (member
))
18250 dw_die_ref type_die
;
18251 gcc_assert (!decl_ultimate_origin (member
));
18253 push_decl_scope (type
);
18254 type_die
= lookup_type_die_strip_naming_typedef (type
);
18255 if (TREE_CODE (member
) == FUNCTION_DECL
)
18256 gen_subprogram_die (member
, type_die
);
18257 else if (TREE_CODE (member
) == FIELD_DECL
)
18259 /* Ignore the nameless fields that are used to skip bits but handle
18260 C++ anonymous unions and structs. */
18261 if (DECL_NAME (member
) != NULL_TREE
18262 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
18263 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
18265 gen_type_die (member_declared_type (member
), type_die
);
18266 gen_field_die (member
, type_die
);
18270 gen_variable_die (member
, NULL_TREE
, type_die
);
18276 /* Forward declare these functions, because they are mutually recursive
18277 with their set_block_* pairing functions. */
18278 static void set_decl_origin_self (tree
);
18279 static void set_decl_abstract_flags (tree
, vec
<tree
> &);
18281 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
18282 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
18283 that it points to the node itself, thus indicating that the node is its
18284 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
18285 the given node is NULL, recursively descend the decl/block tree which
18286 it is the root of, and for each other ..._DECL or BLOCK node contained
18287 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
18288 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
18289 values to point to themselves. */
18292 set_block_origin_self (tree stmt
)
18294 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
18296 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
18301 for (local_decl
= BLOCK_VARS (stmt
);
18302 local_decl
!= NULL_TREE
;
18303 local_decl
= DECL_CHAIN (local_decl
))
18304 /* Do not recurse on nested functions since the inlining status
18305 of parent and child can be different as per the DWARF spec. */
18306 if (TREE_CODE (local_decl
) != FUNCTION_DECL
18307 && !DECL_EXTERNAL (local_decl
))
18308 set_decl_origin_self (local_decl
);
18314 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
18315 subblock
!= NULL_TREE
;
18316 subblock
= BLOCK_CHAIN (subblock
))
18317 set_block_origin_self (subblock
); /* Recurse. */
18322 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
18323 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
18324 node to so that it points to the node itself, thus indicating that the
18325 node represents its own (abstract) origin. Additionally, if the
18326 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
18327 the decl/block tree of which the given node is the root of, and for
18328 each other ..._DECL or BLOCK node contained therein whose
18329 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
18330 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
18331 point to themselves. */
18334 set_decl_origin_self (tree decl
)
18336 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
18338 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
18339 if (TREE_CODE (decl
) == FUNCTION_DECL
)
18343 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
18344 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
18345 if (DECL_INITIAL (decl
) != NULL_TREE
18346 && DECL_INITIAL (decl
) != error_mark_node
)
18347 set_block_origin_self (DECL_INITIAL (decl
));
18352 /* Given a pointer to some BLOCK node, set the BLOCK_ABSTRACT flag to 1
18353 and if it wasn't 1 before, push it to abstract_vec vector.
18354 For all local decls and all local sub-blocks (recursively) do it
18358 set_block_abstract_flags (tree stmt
, vec
<tree
> &abstract_vec
)
18364 if (!BLOCK_ABSTRACT (stmt
))
18366 abstract_vec
.safe_push (stmt
);
18367 BLOCK_ABSTRACT (stmt
) = 1;
18370 for (local_decl
= BLOCK_VARS (stmt
);
18371 local_decl
!= NULL_TREE
;
18372 local_decl
= DECL_CHAIN (local_decl
))
18373 if (! DECL_EXTERNAL (local_decl
))
18374 set_decl_abstract_flags (local_decl
, abstract_vec
);
18376 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
18378 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
18379 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
18380 || TREE_CODE (local_decl
) == PARM_DECL
)
18381 set_decl_abstract_flags (local_decl
, abstract_vec
);
18384 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
18385 subblock
!= NULL_TREE
;
18386 subblock
= BLOCK_CHAIN (subblock
))
18387 set_block_abstract_flags (subblock
, abstract_vec
);
18390 /* Given a pointer to some ..._DECL node, set DECL_ABSTRACT_P flag on it
18391 to 1 and if it wasn't 1 before, push to abstract_vec vector.
18392 In the case where the decl is a FUNCTION_DECL also set the abstract
18393 flags for all of the parameters, local vars, local
18394 blocks and sub-blocks (recursively). */
18397 set_decl_abstract_flags (tree decl
, vec
<tree
> &abstract_vec
)
18399 if (!DECL_ABSTRACT_P (decl
))
18401 abstract_vec
.safe_push (decl
);
18402 DECL_ABSTRACT_P (decl
) = 1;
18405 if (TREE_CODE (decl
) == FUNCTION_DECL
)
18409 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
18410 if (!DECL_ABSTRACT_P (arg
))
18412 abstract_vec
.safe_push (arg
);
18413 DECL_ABSTRACT_P (arg
) = 1;
18415 if (DECL_INITIAL (decl
) != NULL_TREE
18416 && DECL_INITIAL (decl
) != error_mark_node
)
18417 set_block_abstract_flags (DECL_INITIAL (decl
), abstract_vec
);
18421 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18422 may later generate inlined and/or out-of-line instances of.
18424 FIXME: In the early-dwarf world, this function, and most of the
18425 DECL_ABSTRACT code should be obsoleted. The early DIE _is_
18426 the abstract instance. All we would need to do is annotate
18427 the early DIE with the appropriate DW_AT_inline in late
18428 dwarf (perhaps in gen_inlined_subroutine_die).
18430 However, we can't do this yet, because LTO streaming of DIEs
18431 has not been implemented yet. */
18434 dwarf2out_abstract_function (tree decl
)
18436 dw_die_ref old_die
;
18439 hash_table
<decl_loc_hasher
> *old_decl_loc_table
;
18440 hash_table
<dw_loc_list_hasher
> *old_cached_dw_loc_list_table
;
18441 int old_call_site_count
, old_tail_call_site_count
;
18442 struct call_arg_loc_node
*old_call_arg_locations
;
18444 /* Make sure we have the actual abstract inline, not a clone. */
18445 decl
= DECL_ORIGIN (decl
);
18447 old_die
= lookup_decl_die (decl
);
18448 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
18449 /* We've already generated the abstract instance. */
18452 /* We can be called while recursively when seeing block defining inlined subroutine
18453 DIE. Be sure to not clobber the outer location table nor use it or we would
18454 get locations in abstract instantces. */
18455 old_decl_loc_table
= decl_loc_table
;
18456 decl_loc_table
= NULL
;
18457 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
18458 cached_dw_loc_list_table
= NULL
;
18459 old_call_arg_locations
= call_arg_locations
;
18460 call_arg_locations
= NULL
;
18461 old_call_site_count
= call_site_count
;
18462 call_site_count
= -1;
18463 old_tail_call_site_count
= tail_call_site_count
;
18464 tail_call_site_count
= -1;
18466 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18467 we don't get confused by DECL_ABSTRACT_P. */
18468 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18470 context
= decl_class_context (decl
);
18472 gen_type_die_for_member
18473 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
18476 /* Pretend we've just finished compiling this function. */
18477 save_fn
= current_function_decl
;
18478 current_function_decl
= decl
;
18480 auto_vec
<tree
, 64> abstract_vec
;
18481 set_decl_abstract_flags (decl
, abstract_vec
);
18482 dwarf2out_decl (decl
);
18485 FOR_EACH_VEC_ELT (abstract_vec
, i
, t
)
18486 if (TREE_CODE (t
) == BLOCK
)
18487 BLOCK_ABSTRACT (t
) = 0;
18489 DECL_ABSTRACT_P (t
) = 0;
18491 current_function_decl
= save_fn
;
18492 decl_loc_table
= old_decl_loc_table
;
18493 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
18494 call_arg_locations
= old_call_arg_locations
;
18495 call_site_count
= old_call_site_count
;
18496 tail_call_site_count
= old_tail_call_site_count
;
18499 /* Helper function of premark_used_types() which gets called through
18502 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18503 marked as unused by prune_unused_types. */
18506 premark_used_types_helper (tree
const &type
, void *)
18510 die
= lookup_type_die (type
);
18512 die
->die_perennial_p
= 1;
18516 /* Helper function of premark_types_used_by_global_vars which gets called
18517 through htab_traverse.
18519 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18520 marked as unused by prune_unused_types. The DIE of the type is marked
18521 only if the global variable using the type will actually be emitted. */
18524 premark_types_used_by_global_vars_helper (types_used_by_vars_entry
**slot
,
18527 struct types_used_by_vars_entry
*entry
;
18530 entry
= (struct types_used_by_vars_entry
*) *slot
;
18531 gcc_assert (entry
->type
!= NULL
18532 && entry
->var_decl
!= NULL
);
18533 die
= lookup_type_die (entry
->type
);
18536 /* Ask cgraph if the global variable really is to be emitted.
18537 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18538 varpool_node
*node
= varpool_node::get (entry
->var_decl
);
18539 if (node
&& node
->definition
)
18541 die
->die_perennial_p
= 1;
18542 /* Keep the parent DIEs as well. */
18543 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
18544 die
->die_perennial_p
= 1;
18550 /* Mark all members of used_types_hash as perennial. */
18553 premark_used_types (struct function
*fun
)
18555 if (fun
&& fun
->used_types_hash
)
18556 fun
->used_types_hash
->traverse
<void *, premark_used_types_helper
> (NULL
);
18559 /* Mark all members of types_used_by_vars_entry as perennial. */
18562 premark_types_used_by_global_vars (void)
18564 if (types_used_by_vars_hash
)
18565 types_used_by_vars_hash
18566 ->traverse
<void *, premark_types_used_by_global_vars_helper
> (NULL
);
18569 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
18570 for CA_LOC call arg loc node. */
18573 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
18574 struct call_arg_loc_node
*ca_loc
)
18576 dw_die_ref stmt_die
= NULL
, die
;
18577 tree block
= ca_loc
->block
;
18580 && block
!= DECL_INITIAL (decl
)
18581 && TREE_CODE (block
) == BLOCK
)
18583 stmt_die
= BLOCK_DIE (block
);
18586 block
= BLOCK_SUPERCONTEXT (block
);
18588 if (stmt_die
== NULL
)
18589 stmt_die
= subr_die
;
18590 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
18591 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
18592 if (ca_loc
->tail_call_p
)
18593 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
18594 if (ca_loc
->symbol_ref
)
18596 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
18598 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
18600 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
18605 /* Generate a DIE to represent a declared function (either file-scope or
18609 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
18611 tree origin
= decl_ultimate_origin (decl
);
18612 dw_die_ref subr_die
;
18613 dw_die_ref old_die
= lookup_decl_die (decl
);
18615 /* This function gets called multiple times for different stages of
18616 the debug process. For example, for func() in this code:
18620 void func() { ... }
18623 ...we get called 4 times. Twice in early debug and twice in
18629 1. Once while generating func() within the namespace. This is
18630 the declaration. The declaration bit below is set, as the
18631 context is the namespace.
18633 A new DIE will be generated with DW_AT_declaration set.
18635 2. Once for func() itself. This is the specification. The
18636 declaration bit below is clear as the context is the CU.
18638 We will use the cached DIE from (1) to create a new DIE with
18639 DW_AT_specification pointing to the declaration in (1).
18641 Late debug via rest_of_handle_final()
18642 -------------------------------------
18644 3. Once generating func() within the namespace. This is also the
18645 declaration, as in (1), but this time we will early exit below
18646 as we have a cached DIE and a declaration needs no additional
18647 annotations (no locations), as the source declaration line
18650 4. Once for func() itself. As in (2), this is the specification,
18651 but this time we will re-use the cached DIE, and just annotate
18652 it with the location information that should now be available.
18654 For something without namespaces, but with abstract instances, we
18655 are also called a multiple times:
18660 Base (); // constructor declaration (1)
18663 Base::Base () { } // constructor specification (2)
18668 1. Once for the Base() constructor by virtue of it being a
18669 member of the Base class. This is done via
18670 rest_of_type_compilation.
18672 This is a declaration, so a new DIE will be created with
18675 2. Once for the Base() constructor definition, but this time
18676 while generating the abstract instance of the base
18677 constructor (__base_ctor) which is being generated via early
18678 debug of reachable functions.
18680 Even though we have a cached version of the declaration (1),
18681 we will create a DW_AT_specification of the declaration DIE
18684 3. Once for the __base_ctor itself, but this time, we generate
18685 an DW_AT_abstract_origin version of the DW_AT_specification in
18688 Late debug via rest_of_handle_final
18689 -----------------------------------
18691 4. One final time for the __base_ctor (which will have a cached
18692 DIE with DW_AT_abstract_origin created in (3). This time,
18693 we will just annotate the location information now
18696 int declaration
= (current_function_decl
!= decl
18697 || class_or_namespace_scope_p (context_die
));
18699 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
18701 /* Now that the C++ front end lazily declares artificial member fns, we
18702 might need to retrofit the declaration into its class. */
18703 if (!declaration
&& !origin
&& !old_die
18704 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
18705 && !class_or_namespace_scope_p (context_die
)
18706 && debug_info_level
> DINFO_LEVEL_TERSE
)
18707 old_die
= force_decl_die (decl
);
18709 /* An inlined instance, tag a new DIE with DW_AT_abstract_origin. */
18710 if (origin
!= NULL
)
18712 gcc_assert (!declaration
|| local_scope_p (context_die
));
18714 /* Fixup die_parent for the abstract instance of a nested
18715 inline function. */
18716 if (old_die
&& old_die
->die_parent
== NULL
)
18717 add_child_die (context_die
, old_die
);
18719 if (old_die
&& get_AT_ref (old_die
, DW_AT_abstract_origin
))
18721 /* If we have a DW_AT_abstract_origin we have a working
18723 subr_die
= old_die
;
18727 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18728 add_abstract_origin_attribute (subr_die
, origin
);
18729 /* This is where the actual code for a cloned function is.
18730 Let's emit linkage name attribute for it. This helps
18731 debuggers to e.g, set breakpoints into
18732 constructors/destructors when the user asks "break
18734 add_linkage_name (subr_die
, decl
);
18737 /* A cached copy, possibly from early dwarf generation. Reuse as
18738 much as possible. */
18741 /* A declaration that has been previously dumped needs no
18742 additional information. */
18746 if (!get_AT_flag (old_die
, DW_AT_declaration
)
18747 /* We can have a normal definition following an inline one in the
18748 case of redefinition of GNU C extern inlines.
18749 It seems reasonable to use AT_specification in this case. */
18750 && !get_AT (old_die
, DW_AT_inline
))
18752 /* Detect and ignore this case, where we are trying to output
18753 something we have already output. */
18754 if (get_AT (old_die
, DW_AT_low_pc
)
18755 || get_AT (old_die
, DW_AT_ranges
))
18758 /* If we have no location information, this must be a
18759 partially generated DIE from early dwarf generation.
18760 Fall through and generate it. */
18763 /* If the definition comes from the same place as the declaration,
18764 maybe use the old DIE. We always want the DIE for this function
18765 that has the *_pc attributes to be under comp_unit_die so the
18766 debugger can find it. We also need to do this for abstract
18767 instances of inlines, since the spec requires the out-of-line copy
18768 to have the same parent. For local class methods, this doesn't
18769 apply; we just use the old DIE. */
18770 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18771 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18772 if ((is_cu_die (old_die
->die_parent
)
18773 /* This condition fixes the inconsistency/ICE with the
18774 following Fortran test (or some derivative thereof) while
18775 building libgfortran:
18779 logical function funky (FLAG)
18784 || (old_die
->die_parent
18785 && old_die
->die_parent
->die_tag
== DW_TAG_module
)
18786 || context_die
== NULL
)
18787 && (DECL_ARTIFICIAL (decl
)
18788 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
18789 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
18790 == (unsigned) s
.line
))))
18792 subr_die
= old_die
;
18794 /* Clear out the declaration attribute, but leave the
18795 parameters so they can be augmented with location
18796 information later. Unless this was a declaration, in
18797 which case, wipe out the nameless parameters and recreate
18798 them further down. */
18799 if (remove_AT (subr_die
, DW_AT_declaration
))
18802 remove_AT (subr_die
, DW_AT_object_pointer
);
18803 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
18806 /* Make a specification pointing to the previously built
18810 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18811 add_AT_specification (subr_die
, old_die
);
18812 add_pubname (decl
, subr_die
);
18813 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18814 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
18815 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18816 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
18818 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
18819 emit the real type on the definition die. */
18820 if (is_cxx() && debug_info_level
> DINFO_LEVEL_TERSE
)
18822 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
18823 if (die
== auto_die
|| die
== decltype_auto_die
)
18824 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18825 TYPE_UNQUALIFIED
, context_die
);
18829 /* Create a fresh DIE for anything else. */
18832 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18834 if (TREE_PUBLIC (decl
))
18835 add_AT_flag (subr_die
, DW_AT_external
, 1);
18837 add_name_and_src_coords_attributes (subr_die
, decl
);
18838 add_pubname (decl
, subr_die
);
18839 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18841 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
18842 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18843 TYPE_UNQUALIFIED
, context_die
);
18846 add_pure_or_virtual_attribute (subr_die
, decl
);
18847 if (DECL_ARTIFICIAL (decl
))
18848 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18850 if (TREE_THIS_VOLATILE (decl
) && (dwarf_version
>= 5 || !dwarf_strict
))
18851 add_AT_flag (subr_die
, DW_AT_noreturn
, 1);
18853 add_accessibility_attribute (subr_die
, decl
);
18856 /* Unless we have an existing non-declaration DIE, equate the new
18858 if (!old_die
|| is_declaration_die (old_die
))
18859 equate_decl_number_to_die (decl
, subr_die
);
18863 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18865 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
18867 /* If this is an explicit function declaration then generate
18868 a DW_AT_explicit attribute. */
18869 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
18870 && (dwarf_version
>= 3 || !dwarf_strict
))
18871 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
18873 /* If this is a C++11 deleted special function member then generate
18874 a DW_AT_GNU_deleted attribute. */
18875 if (lang_hooks
.decls
.function_decl_deleted_p (decl
)
18876 && (! dwarf_strict
))
18877 add_AT_flag (subr_die
, DW_AT_GNU_deleted
, 1);
18880 /* Tag abstract instances with DW_AT_inline. */
18881 else if (DECL_ABSTRACT_P (decl
))
18883 if (DECL_DECLARED_INLINE_P (decl
))
18885 if (cgraph_function_possibly_inlined_p (decl
))
18886 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
18888 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
18892 if (cgraph_function_possibly_inlined_p (decl
))
18893 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
18895 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
18898 if (DECL_DECLARED_INLINE_P (decl
)
18899 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
18900 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18902 /* For non DECL_EXTERNALs, if range information is available, fill
18903 the DIE with it. */
18904 else if (!DECL_EXTERNAL (decl
) && !early_dwarf
)
18906 HOST_WIDE_INT cfa_fb_offset
;
18908 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
18910 if (!flag_reorder_blocks_and_partition
)
18912 dw_fde_ref fde
= fun
->fde
;
18913 if (fde
->dw_fde_begin
)
18915 /* We have already generated the labels. */
18916 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18917 fde
->dw_fde_end
, false);
18921 /* Create start/end labels and add the range. */
18922 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
18923 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18924 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
18925 current_function_funcdef_no
);
18926 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
18927 current_function_funcdef_no
);
18928 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
18932 #if VMS_DEBUGGING_INFO
18933 /* HP OpenVMS Industry Standard 64: DWARF Extensions
18934 Section 2.3 Prologue and Epilogue Attributes:
18935 When a breakpoint is set on entry to a function, it is generally
18936 desirable for execution to be suspended, not on the very first
18937 instruction of the function, but rather at a point after the
18938 function's frame has been set up, after any language defined local
18939 declaration processing has been completed, and before execution of
18940 the first statement of the function begins. Debuggers generally
18941 cannot properly determine where this point is. Similarly for a
18942 breakpoint set on exit from a function. The prologue and epilogue
18943 attributes allow a compiler to communicate the location(s) to use. */
18946 if (fde
->dw_fde_vms_end_prologue
)
18947 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
18948 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
18950 if (fde
->dw_fde_vms_begin_epilogue
)
18951 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
18952 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
18959 /* Generate pubnames entries for the split function code ranges. */
18960 dw_fde_ref fde
= fun
->fde
;
18962 if (fde
->dw_fde_second_begin
)
18964 if (dwarf_version
>= 3 || !dwarf_strict
)
18966 /* We should use ranges for non-contiguous code section
18967 addresses. Use the actual code range for the initial
18968 section, since the HOT/COLD labels might precede an
18969 alignment offset. */
18970 bool range_list_added
= false;
18971 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
18972 fde
->dw_fde_end
, &range_list_added
,
18974 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
18975 fde
->dw_fde_second_end
,
18976 &range_list_added
, false);
18977 if (range_list_added
)
18982 /* There is no real support in DW2 for this .. so we make
18983 a work-around. First, emit the pub name for the segment
18984 containing the function label. Then make and emit a
18985 simplified subprogram DIE for the second segment with the
18986 name pre-fixed by __hot/cold_sect_of_. We use the same
18987 linkage name for the second die so that gdb will find both
18988 sections when given "b foo". */
18989 const char *name
= NULL
;
18990 tree decl_name
= DECL_NAME (decl
);
18991 dw_die_ref seg_die
;
18993 /* Do the 'primary' section. */
18994 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18995 fde
->dw_fde_end
, false);
18997 /* Build a minimal DIE for the secondary section. */
18998 seg_die
= new_die (DW_TAG_subprogram
,
18999 subr_die
->die_parent
, decl
);
19001 if (TREE_PUBLIC (decl
))
19002 add_AT_flag (seg_die
, DW_AT_external
, 1);
19004 if (decl_name
!= NULL
19005 && IDENTIFIER_POINTER (decl_name
) != NULL
)
19007 name
= dwarf2_name (decl
, 1);
19008 if (! DECL_ARTIFICIAL (decl
))
19009 add_src_coords_attributes (seg_die
, decl
);
19011 add_linkage_name (seg_die
, decl
);
19013 gcc_assert (name
!= NULL
);
19014 add_pure_or_virtual_attribute (seg_die
, decl
);
19015 if (DECL_ARTIFICIAL (decl
))
19016 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
19018 name
= concat ("__second_sect_of_", name
, NULL
);
19019 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
19020 fde
->dw_fde_second_end
, false);
19021 add_name_attribute (seg_die
, name
);
19022 if (want_pubnames ())
19023 add_pubname_string (name
, seg_die
);
19027 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
19031 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
19033 /* We define the "frame base" as the function's CFA. This is more
19034 convenient for several reasons: (1) It's stable across the prologue
19035 and epilogue, which makes it better than just a frame pointer,
19036 (2) With dwarf3, there exists a one-byte encoding that allows us
19037 to reference the .debug_frame data by proxy, but failing that,
19038 (3) We can at least reuse the code inspection and interpretation
19039 code that determines the CFA position at various points in the
19041 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
19043 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
19044 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
19048 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
19049 if (list
->dw_loc_next
)
19050 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
19052 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
19055 /* Compute a displacement from the "steady-state frame pointer" to
19056 the CFA. The former is what all stack slots and argument slots
19057 will reference in the rtl; the latter is what we've told the
19058 debugger about. We'll need to adjust all frame_base references
19059 by this displacement. */
19060 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
19062 if (fun
->static_chain_decl
)
19063 add_AT_location_description
19064 (subr_die
, DW_AT_static_link
,
19065 loc_list_from_tree (fun
->static_chain_decl
, 2, NULL
));
19068 /* Generate child dies for template paramaters. */
19069 if (early_dwarf
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19070 gen_generic_params_dies (decl
);
19072 /* Now output descriptions of the arguments for this function. This gets
19073 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
19074 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
19075 `...' at the end of the formal parameter list. In order to find out if
19076 there was a trailing ellipsis or not, we must instead look at the type
19077 associated with the FUNCTION_DECL. This will be a node of type
19078 FUNCTION_TYPE. If the chain of type nodes hanging off of this
19079 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
19080 an ellipsis at the end. */
19082 /* In the case where we are describing a mere function declaration, all we
19083 need to do here (and all we *can* do here) is to describe the *types* of
19084 its formal parameters. */
19085 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19087 else if (declaration
)
19088 gen_formal_types_die (decl
, subr_die
);
19091 /* Generate DIEs to represent all known formal parameters. */
19092 tree parm
= DECL_ARGUMENTS (decl
);
19093 tree generic_decl
= early_dwarf
19094 ? lang_hooks
.decls
.get_generic_function_decl (decl
) : NULL
;
19095 tree generic_decl_parm
= generic_decl
19096 ? DECL_ARGUMENTS (generic_decl
)
19099 /* Now we want to walk the list of parameters of the function and
19100 emit their relevant DIEs.
19102 We consider the case of DECL being an instance of a generic function
19103 as well as it being a normal function.
19105 If DECL is an instance of a generic function we walk the
19106 parameters of the generic function declaration _and_ the parameters of
19107 DECL itself. This is useful because we want to emit specific DIEs for
19108 function parameter packs and those are declared as part of the
19109 generic function declaration. In that particular case,
19110 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
19111 That DIE has children DIEs representing the set of arguments
19112 of the pack. Note that the set of pack arguments can be empty.
19113 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
19116 Otherwise, we just consider the parameters of DECL. */
19117 while (generic_decl_parm
|| parm
)
19119 if (generic_decl_parm
19120 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
19121 gen_formal_parameter_pack_die (generic_decl_parm
,
19124 else if (parm
&& !POINTER_BOUNDS_P (parm
))
19126 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
19128 if (parm
== DECL_ARGUMENTS (decl
)
19129 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
19131 && (dwarf_version
>= 3 || !dwarf_strict
))
19132 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
19134 parm
= DECL_CHAIN (parm
);
19137 parm
= DECL_CHAIN (parm
);
19139 if (generic_decl_parm
)
19140 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
19143 /* Decide whether we need an unspecified_parameters DIE at the end.
19144 There are 2 more cases to do this for: 1) the ansi ... declaration -
19145 this is detectable when the end of the arg list is not a
19146 void_type_node 2) an unprototyped function declaration (not a
19147 definition). This just means that we have no info about the
19148 parameters at all. */
19149 if (prototype_p (TREE_TYPE (decl
)))
19151 /* This is the prototyped case, check for.... */
19152 if (stdarg_p (TREE_TYPE (decl
)))
19153 gen_unspecified_parameters_die (decl
, subr_die
);
19155 else if (DECL_INITIAL (decl
) == NULL_TREE
)
19156 gen_unspecified_parameters_die (decl
, subr_die
);
19159 if (subr_die
!= old_die
)
19160 /* Add the calling convention attribute if requested. */
19161 add_calling_convention_attribute (subr_die
, decl
);
19163 /* Output Dwarf info for all of the stuff within the body of the function
19164 (if it has one - it may be just a declaration).
19166 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
19167 a function. This BLOCK actually represents the outermost binding contour
19168 for the function, i.e. the contour in which the function's formal
19169 parameters and labels get declared. Curiously, it appears that the front
19170 end doesn't actually put the PARM_DECL nodes for the current function onto
19171 the BLOCK_VARS list for this outer scope, but are strung off of the
19172 DECL_ARGUMENTS list for the function instead.
19174 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
19175 the LABEL_DECL nodes for the function however, and we output DWARF info
19176 for those in decls_for_scope. Just within the `outer_scope' there will be
19177 a BLOCK node representing the function's outermost pair of curly braces,
19178 and any blocks used for the base and member initializers of a C++
19179 constructor function. */
19180 tree outer_scope
= DECL_INITIAL (decl
);
19181 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
19183 int call_site_note_count
= 0;
19184 int tail_call_site_note_count
= 0;
19186 /* Emit a DW_TAG_variable DIE for a named return value. */
19187 if (DECL_NAME (DECL_RESULT (decl
)))
19188 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
19190 /* The first time through decls_for_scope we will generate the
19191 DIEs for the locals. The second time, we fill in the
19193 decls_for_scope (outer_scope
, subr_die
);
19195 if (call_arg_locations
&& !dwarf_strict
)
19197 struct call_arg_loc_node
*ca_loc
;
19198 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
19200 dw_die_ref die
= NULL
;
19201 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
19204 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
19205 arg
; arg
= next_arg
)
19207 dw_loc_descr_ref reg
, val
;
19208 machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
19209 dw_die_ref cdie
, tdie
= NULL
;
19211 next_arg
= XEXP (arg
, 1);
19212 if (REG_P (XEXP (XEXP (arg
, 0), 0))
19214 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
19215 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
19216 && REGNO (XEXP (XEXP (arg
, 0), 0))
19217 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
19218 next_arg
= XEXP (next_arg
, 1);
19219 if (mode
== VOIDmode
)
19221 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
19222 if (mode
== VOIDmode
)
19223 mode
= GET_MODE (XEXP (arg
, 0));
19225 if (mode
== VOIDmode
|| mode
== BLKmode
)
19227 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
19229 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
19230 tloc
= XEXP (XEXP (arg
, 0), 1);
19233 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
19234 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
19236 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
19237 tlocc
= XEXP (XEXP (arg
, 0), 1);
19241 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
19242 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
19243 VAR_INIT_STATUS_INITIALIZED
);
19244 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
19246 rtx mem
= XEXP (XEXP (arg
, 0), 0);
19247 reg
= mem_loc_descriptor (XEXP (mem
, 0),
19248 get_address_mode (mem
),
19250 VAR_INIT_STATUS_INITIALIZED
);
19252 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
19253 == DEBUG_PARAMETER_REF
)
19256 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
19257 tdie
= lookup_decl_die (tdecl
);
19264 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
19265 != DEBUG_PARAMETER_REF
)
19267 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
19269 VAR_INIT_STATUS_INITIALIZED
);
19273 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
19274 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
19277 add_AT_loc (cdie
, DW_AT_location
, reg
);
19278 else if (tdie
!= NULL
)
19279 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
19280 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
19281 if (next_arg
!= XEXP (arg
, 1))
19283 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
19284 if (mode
== VOIDmode
)
19285 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
19286 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
19289 VAR_INIT_STATUS_INITIALIZED
);
19291 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
19295 && (ca_loc
->symbol_ref
|| tloc
))
19296 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
19297 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
19299 dw_loc_descr_ref tval
= NULL
;
19301 if (tloc
!= NULL_RTX
)
19302 tval
= mem_loc_descriptor (tloc
,
19303 GET_MODE (tloc
) == VOIDmode
19304 ? Pmode
: GET_MODE (tloc
),
19306 VAR_INIT_STATUS_INITIALIZED
);
19308 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
19309 else if (tlocc
!= NULL_RTX
)
19311 tval
= mem_loc_descriptor (tlocc
,
19312 GET_MODE (tlocc
) == VOIDmode
19313 ? Pmode
: GET_MODE (tlocc
),
19315 VAR_INIT_STATUS_INITIALIZED
);
19317 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
19323 call_site_note_count
++;
19324 if (ca_loc
->tail_call_p
)
19325 tail_call_site_note_count
++;
19329 call_arg_locations
= NULL
;
19330 call_arg_loc_last
= NULL
;
19331 if (tail_call_site_count
>= 0
19332 && tail_call_site_count
== tail_call_site_note_count
19335 if (call_site_count
>= 0
19336 && call_site_count
== call_site_note_count
)
19337 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
19339 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
19341 call_site_count
= -1;
19342 tail_call_site_count
= -1;
19346 /* Returns a hash value for X (which really is a die_struct). */
19349 block_die_hasher::hash (die_struct
*d
)
19351 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
19354 /* Return nonzero if decl_id and die_parent of die_struct X is the same
19355 as decl_id and die_parent of die_struct Y. */
19358 block_die_hasher::equal (die_struct
*x
, die_struct
*y
)
19360 return x
->decl_id
== y
->decl_id
&& x
->die_parent
== y
->die_parent
;
19363 /* Return TRUE if DECL, which may have been previously generated as
19364 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
19365 true if decl (or its origin) is either an extern declaration or a
19366 class/namespace scoped declaration.
19368 The declare_in_namespace support causes us to get two DIEs for one
19369 variable, both of which are declarations. We want to avoid
19370 considering one to be a specification, so we must test for
19371 DECLARATION and DW_AT_declaration. */
19373 decl_will_get_specification_p (dw_die_ref old_die
, tree decl
, bool declaration
)
19375 return (old_die
&& TREE_STATIC (decl
) && !declaration
19376 && get_AT_flag (old_die
, DW_AT_declaration
) == 1);
19379 /* Return true if DECL is a local static. */
19382 local_function_static (tree decl
)
19384 gcc_assert (TREE_CODE (decl
) == VAR_DECL
);
19385 return TREE_STATIC (decl
)
19386 && DECL_CONTEXT (decl
)
19387 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
;
19390 /* Generate a DIE to represent a declared data object.
19391 Either DECL or ORIGIN must be non-null. */
19394 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
19396 HOST_WIDE_INT off
= 0;
19398 tree decl_or_origin
= decl
? decl
: origin
;
19399 tree ultimate_origin
;
19400 dw_die_ref var_die
;
19401 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
19402 dw_die_ref origin_die
= NULL
;
19403 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
19404 || class_or_namespace_scope_p (context_die
));
19405 bool specialization_p
= false;
19407 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
19408 if (decl
|| ultimate_origin
)
19409 origin
= ultimate_origin
;
19410 com_decl
= fortran_common (decl_or_origin
, &off
);
19412 /* Symbol in common gets emitted as a child of the common block, in the form
19413 of a data member. */
19416 dw_die_ref com_die
;
19417 dw_loc_list_ref loc
;
19418 die_node com_die_arg
;
19420 var_die
= lookup_decl_die (decl_or_origin
);
19423 if (get_AT (var_die
, DW_AT_location
) == NULL
)
19425 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2, NULL
);
19430 /* Optimize the common case. */
19431 if (single_element_loc_list_p (loc
)
19432 && loc
->expr
->dw_loc_opc
== DW_OP_addr
19433 && loc
->expr
->dw_loc_next
== NULL
19434 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
19437 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
19438 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
19439 = plus_constant (GET_MODE (x
), x
, off
);
19442 loc_list_plus_const (loc
, off
);
19444 add_AT_location_description (var_die
, DW_AT_location
, loc
);
19445 remove_AT (var_die
, DW_AT_declaration
);
19451 if (common_block_die_table
== NULL
)
19452 common_block_die_table
= hash_table
<block_die_hasher
>::create_ggc (10);
19454 com_die_arg
.decl_id
= DECL_UID (com_decl
);
19455 com_die_arg
.die_parent
= context_die
;
19456 com_die
= common_block_die_table
->find (&com_die_arg
);
19457 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
19458 if (com_die
== NULL
)
19461 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
19464 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
19465 add_name_and_src_coords_attributes (com_die
, com_decl
);
19468 add_AT_location_description (com_die
, DW_AT_location
, loc
);
19469 /* Avoid sharing the same loc descriptor between
19470 DW_TAG_common_block and DW_TAG_variable. */
19471 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
19473 else if (DECL_EXTERNAL (decl
))
19474 add_AT_flag (com_die
, DW_AT_declaration
, 1);
19475 if (want_pubnames ())
19476 add_pubname_string (cnam
, com_die
); /* ??? needed? */
19477 com_die
->decl_id
= DECL_UID (com_decl
);
19478 slot
= common_block_die_table
->find_slot (com_die
, INSERT
);
19481 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
19483 add_AT_location_description (com_die
, DW_AT_location
, loc
);
19484 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
19485 remove_AT (com_die
, DW_AT_declaration
);
19487 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
19488 add_name_and_src_coords_attributes (var_die
, decl
);
19489 add_type_attribute (var_die
, TREE_TYPE (decl
), decl_quals (decl
),
19491 add_AT_flag (var_die
, DW_AT_external
, 1);
19496 /* Optimize the common case. */
19497 if (single_element_loc_list_p (loc
)
19498 && loc
->expr
->dw_loc_opc
== DW_OP_addr
19499 && loc
->expr
->dw_loc_next
== NULL
19500 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
19502 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
19503 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
19504 = plus_constant (GET_MODE (x
), x
, off
);
19507 loc_list_plus_const (loc
, off
);
19509 add_AT_location_description (var_die
, DW_AT_location
, loc
);
19511 else if (DECL_EXTERNAL (decl
))
19512 add_AT_flag (var_die
, DW_AT_declaration
, 1);
19513 equate_decl_number_to_die (decl
, var_die
);
19521 /* A declaration that has been previously dumped, needs no
19522 further annotations, since it doesn't need location on
19523 the second pass. */
19526 else if (decl_will_get_specification_p (old_die
, decl
, declaration
)
19527 && !get_AT (old_die
, DW_AT_specification
))
19529 /* Fall-thru so we can make a new variable die along with a
19530 DW_AT_specification. */
19532 else if (origin
&& old_die
->die_parent
!= context_die
)
19534 /* If we will be creating an inlined instance, we need a
19535 new DIE that will get annotated with
19536 DW_AT_abstract_origin. Clear things so we can get a
19538 gcc_assert (!DECL_ABSTRACT_P (decl
));
19543 /* If a DIE was dumped early, it still needs location info.
19544 Skip to where we fill the location bits. */
19546 goto gen_variable_die_location
;
19550 /* For static data members, the declaration in the class is supposed
19551 to have DW_TAG_member tag; the specification should still be
19552 DW_TAG_variable referencing the DW_TAG_member DIE. */
19553 if (declaration
&& class_scope_p (context_die
))
19554 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
19556 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
19558 if (origin
!= NULL
)
19559 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
19561 /* Loop unrolling can create multiple blocks that refer to the same
19562 static variable, so we must test for the DW_AT_declaration flag.
19564 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19565 copy decls and set the DECL_ABSTRACT_P flag on them instead of
19568 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
19569 else if (decl_will_get_specification_p (old_die
, decl
, declaration
))
19571 /* This is a definition of a C++ class level static. */
19572 add_AT_specification (var_die
, old_die
);
19573 specialization_p
= true;
19574 if (DECL_NAME (decl
))
19576 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
19577 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
19579 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
19580 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
19582 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
19583 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
19585 if (old_die
->die_tag
== DW_TAG_member
)
19586 add_linkage_name (var_die
, decl
);
19590 add_name_and_src_coords_attributes (var_die
, decl
);
19592 if ((origin
== NULL
&& !specialization_p
)
19594 && !DECL_ABSTRACT_P (decl_or_origin
)
19595 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
19596 decl_function_context
19597 (decl_or_origin
))))
19599 tree type
= TREE_TYPE (decl_or_origin
);
19601 if (decl_by_reference_p (decl_or_origin
))
19602 add_type_attribute (var_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
19605 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
),
19609 if (origin
== NULL
&& !specialization_p
)
19611 if (TREE_PUBLIC (decl
))
19612 add_AT_flag (var_die
, DW_AT_external
, 1);
19614 if (DECL_ARTIFICIAL (decl
))
19615 add_AT_flag (var_die
, DW_AT_artificial
, 1);
19617 add_accessibility_attribute (var_die
, decl
);
19621 add_AT_flag (var_die
, DW_AT_declaration
, 1);
19623 if (decl
&& (DECL_ABSTRACT_P (decl
)
19624 || !old_die
|| is_declaration_die (old_die
)))
19625 equate_decl_number_to_die (decl
, var_die
);
19627 gen_variable_die_location
:
19629 && (! DECL_ABSTRACT_P (decl_or_origin
)
19630 /* Local static vars are shared between all clones/inlines,
19631 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19633 || (TREE_CODE (decl_or_origin
) == VAR_DECL
19634 && TREE_STATIC (decl_or_origin
)
19635 && DECL_RTL_SET_P (decl_or_origin
)))
19636 /* When abstract origin already has DW_AT_location attribute, no need
19637 to add it again. */
19638 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
19641 add_pubname (decl_or_origin
, var_die
);
19643 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
19644 decl
== NULL
, DW_AT_location
);
19647 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
19650 /* Generate a DIE to represent a named constant. */
19653 gen_const_die (tree decl
, dw_die_ref context_die
)
19655 dw_die_ref const_die
;
19656 tree type
= TREE_TYPE (decl
);
19658 const_die
= lookup_decl_die (decl
);
19662 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
19663 equate_decl_number_to_die (decl
, const_die
);
19664 add_name_and_src_coords_attributes (const_die
, decl
);
19665 add_type_attribute (const_die
, type
, TYPE_QUAL_CONST
, context_die
);
19666 if (TREE_PUBLIC (decl
))
19667 add_AT_flag (const_die
, DW_AT_external
, 1);
19668 if (DECL_ARTIFICIAL (decl
))
19669 add_AT_flag (const_die
, DW_AT_artificial
, 1);
19670 tree_add_const_value_attribute_for_decl (const_die
, decl
);
19673 /* Generate a DIE to represent a label identifier. */
19676 gen_label_die (tree decl
, dw_die_ref context_die
)
19678 tree origin
= decl_ultimate_origin (decl
);
19679 dw_die_ref lbl_die
= lookup_decl_die (decl
);
19681 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19685 lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
19686 equate_decl_number_to_die (decl
, lbl_die
);
19688 if (origin
!= NULL
)
19689 add_abstract_origin_attribute (lbl_die
, origin
);
19691 add_name_and_src_coords_attributes (lbl_die
, decl
);
19694 if (DECL_ABSTRACT_P (decl
))
19695 equate_decl_number_to_die (decl
, lbl_die
);
19698 insn
= DECL_RTL_IF_SET (decl
);
19700 /* Deleted labels are programmer specified labels which have been
19701 eliminated because of various optimizations. We still emit them
19702 here so that it is possible to put breakpoints on them. */
19706 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
19708 /* When optimization is enabled (via -O) some parts of the compiler
19709 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19710 represent source-level labels which were explicitly declared by
19711 the user. This really shouldn't be happening though, so catch
19712 it if it ever does happen. */
19713 gcc_assert (!as_a
<rtx_insn
*> (insn
)->deleted ());
19715 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
19716 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19720 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
19721 && CODE_LABEL_NUMBER (insn
) != -1)
19723 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
19724 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19729 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19730 attributes to the DIE for a block STMT, to describe where the inlined
19731 function was called from. This is similar to add_src_coords_attributes. */
19734 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
19736 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
19738 if (dwarf_version
>= 3 || !dwarf_strict
)
19740 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
19741 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
19746 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19747 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19750 add_high_low_attributes (tree stmt
, dw_die_ref die
)
19752 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19754 if (BLOCK_FRAGMENT_CHAIN (stmt
)
19755 && (dwarf_version
>= 3 || !dwarf_strict
))
19757 tree chain
, superblock
= NULL_TREE
;
19759 dw_attr_ref attr
= NULL
;
19761 if (inlined_function_outer_scope_p (stmt
))
19763 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19764 BLOCK_NUMBER (stmt
));
19765 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
19768 /* Optimize duplicate .debug_ranges lists or even tails of
19769 lists. If this BLOCK has same ranges as its supercontext,
19770 lookup DW_AT_ranges attribute in the supercontext (and
19771 recursively so), verify that the ranges_table contains the
19772 right values and use it instead of adding a new .debug_range. */
19773 for (chain
= stmt
, pdie
= die
;
19774 BLOCK_SAME_RANGE (chain
);
19775 chain
= BLOCK_SUPERCONTEXT (chain
))
19777 dw_attr_ref new_attr
;
19779 pdie
= pdie
->die_parent
;
19782 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
19784 new_attr
= get_AT (pdie
, DW_AT_ranges
);
19785 if (new_attr
== NULL
19786 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
19789 superblock
= BLOCK_SUPERCONTEXT (chain
);
19792 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
19793 / 2 / DWARF2_ADDR_SIZE
].num
19794 == BLOCK_NUMBER (superblock
))
19795 && BLOCK_FRAGMENT_CHAIN (superblock
))
19797 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
19798 / 2 / DWARF2_ADDR_SIZE
;
19799 unsigned long supercnt
= 0, thiscnt
= 0;
19800 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
19801 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
19804 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
19805 == BLOCK_NUMBER (chain
));
19807 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
19808 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19809 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
19811 gcc_assert (supercnt
>= thiscnt
);
19812 add_AT_range_list (die
, DW_AT_ranges
,
19813 ((off
+ supercnt
- thiscnt
)
19814 * 2 * DWARF2_ADDR_SIZE
),
19819 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
19821 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19824 add_ranges (chain
);
19825 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
19832 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
19833 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19834 BLOCK_NUMBER (stmt
));
19835 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
19836 BLOCK_NUMBER (stmt
));
19837 add_AT_low_high_pc (die
, label
, label_high
, false);
19841 /* Generate a DIE for a lexical block. */
19844 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
)
19846 dw_die_ref old_die
= BLOCK_DIE (stmt
);
19847 dw_die_ref stmt_die
= NULL
;
19850 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
19851 BLOCK_DIE (stmt
) = stmt_die
;
19854 if (BLOCK_ABSTRACT (stmt
))
19858 #ifdef ENABLE_CHECKING
19859 /* This must have been generated early and it won't even
19860 need location information since it's a DW_AT_inline
19862 for (dw_die_ref c
= context_die
; c
; c
= c
->die_parent
)
19863 if (c
->die_tag
== DW_TAG_inlined_subroutine
19864 || c
->die_tag
== DW_TAG_subprogram
)
19866 gcc_assert (get_AT (c
, DW_AT_inline
));
19873 else if (BLOCK_ABSTRACT_ORIGIN (stmt
))
19875 /* If this is an inlined instance, create a new lexical die for
19876 anything below to attach DW_AT_abstract_origin to. */
19879 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
19880 BLOCK_DIE (stmt
) = stmt_die
;
19886 stmt_die
= old_die
;
19888 /* A non abstract block whose blocks have already been reordered
19889 should have the instruction range for this block. If so, set the
19890 high/low attributes. */
19891 if (!early_dwarf
&& !BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
19893 gcc_assert (stmt_die
);
19894 add_high_low_attributes (stmt
, stmt_die
);
19897 decls_for_scope (stmt
, stmt_die
);
19900 /* Generate a DIE for an inlined subprogram. */
19903 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
)
19907 /* The instance of function that is effectively being inlined shall not
19909 gcc_assert (! BLOCK_ABSTRACT (stmt
));
19911 decl
= block_ultimate_origin (stmt
);
19913 /* Emit info for the abstract instance first, if we haven't yet. We
19914 must emit this even if the block is abstract, otherwise when we
19915 emit the block below (or elsewhere), we may end up trying to emit
19916 a die whose origin die hasn't been emitted, and crashing. */
19917 dwarf2out_abstract_function (decl
);
19919 if (! BLOCK_ABSTRACT (stmt
))
19921 dw_die_ref subr_die
19922 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
19924 if (call_arg_locations
)
19925 BLOCK_DIE (stmt
) = subr_die
;
19926 add_abstract_origin_attribute (subr_die
, decl
);
19927 if (TREE_ASM_WRITTEN (stmt
))
19928 add_high_low_attributes (stmt
, subr_die
);
19929 add_call_src_coords_attributes (stmt
, subr_die
);
19931 decls_for_scope (stmt
, subr_die
);
19935 /* Generate a DIE for a field in a record, or structure. */
19938 gen_field_die (tree decl
, dw_die_ref context_die
)
19940 dw_die_ref decl_die
;
19942 if (TREE_TYPE (decl
) == error_mark_node
)
19945 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
19946 add_name_and_src_coords_attributes (decl_die
, decl
);
19947 add_type_attribute (decl_die
, member_declared_type (decl
),
19948 decl_quals (decl
), context_die
);
19950 if (DECL_BIT_FIELD_TYPE (decl
))
19952 add_byte_size_attribute (decl_die
, decl
);
19953 add_bit_size_attribute (decl_die
, decl
);
19954 add_bit_offset_attribute (decl_die
, decl
);
19957 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
19958 add_data_member_location_attribute (decl_die
, decl
);
19960 if (DECL_ARTIFICIAL (decl
))
19961 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19963 add_accessibility_attribute (decl_die
, decl
);
19965 /* Equate decl number to die, so that we can look up this decl later on. */
19966 equate_decl_number_to_die (decl
, decl_die
);
19970 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19971 Use modified_type_die instead.
19972 We keep this code here just in case these types of DIEs may be needed to
19973 represent certain things in other languages (e.g. Pascal) someday. */
19976 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
19979 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
19981 equate_type_number_to_die (type
, ptr_die
);
19982 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
19984 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19987 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19988 Use modified_type_die instead.
19989 We keep this code here just in case these types of DIEs may be needed to
19990 represent certain things in other languages (e.g. Pascal) someday. */
19993 gen_reference_type_die (tree type
, dw_die_ref context_die
)
19995 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
19997 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
19998 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
20000 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
20002 equate_type_number_to_die (type
, ref_die
);
20003 add_type_attribute (ref_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
20005 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
20009 /* Generate a DIE for a pointer to a member type. */
20012 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
20015 = new_die (DW_TAG_ptr_to_member_type
,
20016 scope_die_for (type
, context_die
), type
);
20018 equate_type_number_to_die (type
, ptr_die
);
20019 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
20020 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
20021 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
20025 typedef const char *dchar_p
; /* For DEF_VEC_P. */
20027 static char *producer_string
;
20029 /* Return a heap allocated producer string including command line options
20030 if -grecord-gcc-switches. */
20033 gen_producer_string (void)
20036 auto_vec
<dchar_p
> switches
;
20037 const char *language_string
= lang_hooks
.name
;
20038 char *producer
, *tail
;
20040 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
20041 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
20043 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
20044 switch (save_decoded_options
[j
].opt_index
)
20051 case OPT_auxbase_strip
:
20060 case OPT_SPECIAL_unknown
:
20061 case OPT_SPECIAL_ignore
:
20062 case OPT_SPECIAL_program_name
:
20063 case OPT_SPECIAL_input_file
:
20064 case OPT_grecord_gcc_switches
:
20065 case OPT_gno_record_gcc_switches
:
20066 case OPT__output_pch_
:
20067 case OPT_fdiagnostics_show_location_
:
20068 case OPT_fdiagnostics_show_option
:
20069 case OPT_fdiagnostics_show_caret
:
20070 case OPT_fdiagnostics_color_
:
20071 case OPT_fverbose_asm
:
20073 case OPT__sysroot_
:
20075 case OPT_nostdinc__
:
20076 case OPT_fpreprocessed
:
20077 case OPT_fltrans_output_list_
:
20078 case OPT_fresolution_
:
20079 /* Ignore these. */
20082 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
20083 & CL_NO_DWARF_RECORD
)
20085 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
20087 switch (save_decoded_options
[j
].canonical_option
[0][1])
20094 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
20101 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
20102 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
20106 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
20108 sprintf (tail
, "%s %s", language_string
, version_string
);
20111 FOR_EACH_VEC_ELT (switches
, j
, p
)
20115 memcpy (tail
+ 1, p
, len
);
20123 /* Given a C and/or C++ language/version string return the "highest".
20124 C++ is assumed to be "higher" than C in this case. Used for merging
20125 LTO translation unit languages. */
20126 static const char *
20127 highest_c_language (const char *lang1
, const char *lang2
)
20129 if (strcmp ("GNU C++14", lang1
) == 0 || strcmp ("GNU C++14", lang2
) == 0)
20130 return "GNU C++14";
20131 if (strcmp ("GNU C++11", lang1
) == 0 || strcmp ("GNU C++11", lang2
) == 0)
20132 return "GNU C++11";
20133 if (strcmp ("GNU C++98", lang1
) == 0 || strcmp ("GNU C++98", lang2
) == 0)
20134 return "GNU C++98";
20136 if (strcmp ("GNU C11", lang1
) == 0 || strcmp ("GNU C11", lang2
) == 0)
20138 if (strcmp ("GNU C99", lang1
) == 0 || strcmp ("GNU C99", lang2
) == 0)
20140 if (strcmp ("GNU C89", lang1
) == 0 || strcmp ("GNU C89", lang2
) == 0)
20143 gcc_unreachable ();
20147 /* Generate the DIE for the compilation unit. */
20150 gen_compile_unit_die (const char *filename
)
20153 const char *language_string
= lang_hooks
.name
;
20156 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
20160 add_name_attribute (die
, filename
);
20161 /* Don't add cwd for <built-in>. */
20162 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
20163 add_comp_dir_attribute (die
);
20166 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
20168 /* If our producer is LTO try to figure out a common language to use
20169 from the global list of translation units. */
20170 if (strcmp (language_string
, "GNU GIMPLE") == 0)
20174 const char *common_lang
= NULL
;
20176 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
20178 if (!TRANSLATION_UNIT_LANGUAGE (t
))
20181 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
20182 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
20184 else if (strncmp (common_lang
, "GNU C", 5) == 0
20185 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
20186 /* Mixing C and C++ is ok, use C++ in that case. */
20187 common_lang
= highest_c_language (common_lang
,
20188 TRANSLATION_UNIT_LANGUAGE (t
));
20191 /* Fall back to C. */
20192 common_lang
= NULL
;
20198 language_string
= common_lang
;
20201 language
= DW_LANG_C
;
20202 if (strncmp (language_string
, "GNU C", 5) == 0
20203 && ISDIGIT (language_string
[5]))
20205 language
= DW_LANG_C89
;
20206 if (dwarf_version
>= 3 || !dwarf_strict
)
20208 if (strcmp (language_string
, "GNU C89") != 0)
20209 language
= DW_LANG_C99
;
20211 if (dwarf_version
>= 5 /* || !dwarf_strict */)
20212 if (strcmp (language_string
, "GNU C11") == 0)
20213 language
= DW_LANG_C11
;
20216 else if (strncmp (language_string
, "GNU C++", 7) == 0)
20218 language
= DW_LANG_C_plus_plus
;
20219 if (dwarf_version
>= 5 /* || !dwarf_strict */)
20221 if (strcmp (language_string
, "GNU C++11") == 0)
20222 language
= DW_LANG_C_plus_plus_11
;
20223 else if (strcmp (language_string
, "GNU C++14") == 0)
20224 language
= DW_LANG_C_plus_plus_14
;
20227 else if (strcmp (language_string
, "GNU F77") == 0)
20228 language
= DW_LANG_Fortran77
;
20229 else if (strcmp (language_string
, "GNU Pascal") == 0)
20230 language
= DW_LANG_Pascal83
;
20231 else if (dwarf_version
>= 3 || !dwarf_strict
)
20233 if (strcmp (language_string
, "GNU Ada") == 0)
20234 language
= DW_LANG_Ada95
;
20235 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
20237 language
= DW_LANG_Fortran95
;
20238 if (dwarf_version
>= 5 /* || !dwarf_strict */)
20240 if (strcmp (language_string
, "GNU Fortran2003") == 0)
20241 language
= DW_LANG_Fortran03
;
20242 else if (strcmp (language_string
, "GNU Fortran2008") == 0)
20243 language
= DW_LANG_Fortran08
;
20246 else if (strcmp (language_string
, "GNU Java") == 0)
20247 language
= DW_LANG_Java
;
20248 else if (strcmp (language_string
, "GNU Objective-C") == 0)
20249 language
= DW_LANG_ObjC
;
20250 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
20251 language
= DW_LANG_ObjC_plus_plus
;
20252 else if (dwarf_version
>= 5 || !dwarf_strict
)
20254 if (strcmp (language_string
, "GNU Go") == 0)
20255 language
= DW_LANG_Go
;
20258 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
20259 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
20260 language
= DW_LANG_Fortran90
;
20262 add_AT_unsigned (die
, DW_AT_language
, language
);
20266 case DW_LANG_Fortran77
:
20267 case DW_LANG_Fortran90
:
20268 case DW_LANG_Fortran95
:
20269 case DW_LANG_Fortran03
:
20270 case DW_LANG_Fortran08
:
20271 /* Fortran has case insensitive identifiers and the front-end
20272 lowercases everything. */
20273 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
20276 /* The default DW_ID_case_sensitive doesn't need to be specified. */
20282 /* Generate the DIE for a base class. */
20285 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
20287 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
20289 add_type_attribute (die
, BINFO_TYPE (binfo
), TYPE_UNQUALIFIED
, context_die
);
20290 add_data_member_location_attribute (die
, binfo
);
20292 if (BINFO_VIRTUAL_P (binfo
))
20293 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
20295 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
20296 children, otherwise the default is DW_ACCESS_public. In DWARF2
20297 the default has always been DW_ACCESS_private. */
20298 if (access
== access_public_node
)
20300 if (dwarf_version
== 2
20301 || context_die
->die_tag
== DW_TAG_class_type
)
20302 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
20304 else if (access
== access_protected_node
)
20305 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
20306 else if (dwarf_version
> 2
20307 && context_die
->die_tag
!= DW_TAG_class_type
)
20308 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
20311 /* Generate a DIE for a class member. */
20314 gen_member_die (tree type
, dw_die_ref context_die
)
20317 tree binfo
= TYPE_BINFO (type
);
20320 /* If this is not an incomplete type, output descriptions of each of its
20321 members. Note that as we output the DIEs necessary to represent the
20322 members of this record or union type, we will also be trying to output
20323 DIEs to represent the *types* of those members. However the `type'
20324 function (above) will specifically avoid generating type DIEs for member
20325 types *within* the list of member DIEs for this (containing) type except
20326 for those types (of members) which are explicitly marked as also being
20327 members of this (containing) type themselves. The g++ front- end can
20328 force any given type to be treated as a member of some other (containing)
20329 type by setting the TYPE_CONTEXT of the given (member) type to point to
20330 the TREE node representing the appropriate (containing) type. */
20332 /* First output info about the base classes. */
20335 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
20339 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
20340 gen_inheritance_die (base
,
20341 (accesses
? (*accesses
)[i
] : access_public_node
),
20345 /* Now output info about the data members and type members. */
20346 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
20348 /* If we thought we were generating minimal debug info for TYPE
20349 and then changed our minds, some of the member declarations
20350 may have already been defined. Don't define them again, but
20351 do put them in the right order. */
20353 child
= lookup_decl_die (member
);
20355 splice_child_die (context_die
, child
);
20357 gen_decl_die (member
, NULL
, context_die
);
20360 /* We do not keep type methods in type variants. */
20361 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
20362 /* Now output info about the function members (if any). */
20363 if (TYPE_METHODS (type
) != error_mark_node
)
20364 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
20366 /* Don't include clones in the member list. */
20367 if (DECL_ABSTRACT_ORIGIN (member
))
20369 /* Nor constructors for anonymous classes. */
20370 if (DECL_ARTIFICIAL (member
)
20371 && dwarf2_name (member
, 0) == NULL
)
20374 child
= lookup_decl_die (member
);
20376 splice_child_die (context_die
, child
);
20378 gen_decl_die (member
, NULL
, context_die
);
20382 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
20383 is set, we pretend that the type was never defined, so we only get the
20384 member DIEs needed by later specification DIEs. */
20387 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
20388 enum debug_info_usage usage
)
20390 if (TREE_ASM_WRITTEN (type
))
20392 /* Fill in the bound of variable-length fields in late dwarf if
20393 still incomplete. */
20394 if (!early_dwarf
&& variably_modified_type_p (type
, NULL
))
20395 for (tree member
= TYPE_FIELDS (type
);
20397 member
= DECL_CHAIN (member
))
20398 fill_variable_array_bounds (TREE_TYPE (member
));
20402 dw_die_ref type_die
= lookup_type_die (type
);
20403 dw_die_ref scope_die
= 0;
20405 int complete
= (TYPE_SIZE (type
)
20406 && (! TYPE_STUB_DECL (type
)
20407 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
20408 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
20409 complete
= complete
&& should_emit_struct_debug (type
, usage
);
20411 if (type_die
&& ! complete
)
20414 if (TYPE_CONTEXT (type
) != NULL_TREE
20415 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
20416 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
20419 scope_die
= scope_die_for (type
, context_die
);
20421 /* Generate child dies for template paramaters. */
20422 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
20423 schedule_generic_params_dies_gen (type
);
20425 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
20426 /* First occurrence of type or toplevel definition of nested class. */
20428 dw_die_ref old_die
= type_die
;
20430 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
20431 ? record_type_tag (type
) : DW_TAG_union_type
,
20433 equate_type_number_to_die (type
, type_die
);
20435 add_AT_specification (type_die
, old_die
);
20437 add_name_attribute (type_die
, type_tag (type
));
20440 remove_AT (type_die
, DW_AT_declaration
);
20442 /* If this type has been completed, then give it a byte_size attribute and
20443 then give a list of members. */
20444 if (complete
&& !ns_decl
)
20446 /* Prevent infinite recursion in cases where the type of some member of
20447 this type is expressed in terms of this type itself. */
20448 TREE_ASM_WRITTEN (type
) = 1;
20449 add_byte_size_attribute (type_die
, type
);
20450 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
20452 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
20453 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
20456 /* If the first reference to this type was as the return type of an
20457 inline function, then it may not have a parent. Fix this now. */
20458 if (type_die
->die_parent
== NULL
)
20459 add_child_die (scope_die
, type_die
);
20461 push_decl_scope (type
);
20462 gen_member_die (type
, type_die
);
20465 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
20466 if (TYPE_ARTIFICIAL (type
))
20467 add_AT_flag (type_die
, DW_AT_artificial
, 1);
20469 /* GNU extension: Record what type our vtable lives in. */
20470 if (TYPE_VFIELD (type
))
20472 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
20474 gen_type_die (vtype
, context_die
);
20475 add_AT_die_ref (type_die
, DW_AT_containing_type
,
20476 lookup_type_die (vtype
));
20481 add_AT_flag (type_die
, DW_AT_declaration
, 1);
20483 /* We don't need to do this for function-local types. */
20484 if (TYPE_STUB_DECL (type
)
20485 && ! decl_function_context (TYPE_STUB_DECL (type
)))
20486 vec_safe_push (incomplete_types
, type
);
20489 if (get_AT (type_die
, DW_AT_name
))
20490 add_pubtype (type
, type_die
);
20493 /* Generate a DIE for a subroutine _type_. */
20496 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
20498 tree return_type
= TREE_TYPE (type
);
20499 dw_die_ref subr_die
20500 = new_die (DW_TAG_subroutine_type
,
20501 scope_die_for (type
, context_die
), type
);
20503 equate_type_number_to_die (type
, subr_die
);
20504 add_prototyped_attribute (subr_die
, type
);
20505 add_type_attribute (subr_die
, return_type
, TYPE_UNQUALIFIED
, context_die
);
20506 gen_formal_types_die (type
, subr_die
);
20508 if (get_AT (subr_die
, DW_AT_name
))
20509 add_pubtype (type
, subr_die
);
20512 /* Generate a DIE for a type definition. */
20515 gen_typedef_die (tree decl
, dw_die_ref context_die
)
20517 dw_die_ref type_die
;
20520 if (TREE_ASM_WRITTEN (decl
))
20522 if (DECL_ORIGINAL_TYPE (decl
))
20523 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl
));
20527 TREE_ASM_WRITTEN (decl
) = 1;
20528 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
20529 origin
= decl_ultimate_origin (decl
);
20530 if (origin
!= NULL
)
20531 add_abstract_origin_attribute (type_die
, origin
);
20536 add_name_and_src_coords_attributes (type_die
, decl
);
20537 if (DECL_ORIGINAL_TYPE (decl
))
20539 type
= DECL_ORIGINAL_TYPE (decl
);
20541 if (type
== error_mark_node
)
20544 gcc_assert (type
!= TREE_TYPE (decl
));
20545 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
20549 type
= TREE_TYPE (decl
);
20551 if (type
== error_mark_node
)
20554 if (is_naming_typedef_decl (TYPE_NAME (type
)))
20556 /* Here, we are in the case of decl being a typedef naming
20557 an anonymous type, e.g:
20558 typedef struct {...} foo;
20559 In that case TREE_TYPE (decl) is not a typedef variant
20560 type and TYPE_NAME of the anonymous type is set to the
20561 TYPE_DECL of the typedef. This construct is emitted by
20564 TYPE is the anonymous struct named by the typedef
20565 DECL. As we need the DW_AT_type attribute of the
20566 DW_TAG_typedef to point to the DIE of TYPE, let's
20567 generate that DIE right away. add_type_attribute
20568 called below will then pick (via lookup_type_die) that
20569 anonymous struct DIE. */
20570 if (!TREE_ASM_WRITTEN (type
))
20571 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
20573 /* This is a GNU Extension. We are adding a
20574 DW_AT_linkage_name attribute to the DIE of the
20575 anonymous struct TYPE. The value of that attribute
20576 is the name of the typedef decl naming the anonymous
20577 struct. This greatly eases the work of consumers of
20578 this debug info. */
20579 add_linkage_attr (lookup_type_die (type
), decl
);
20583 add_type_attribute (type_die
, type
, decl_quals (decl
), context_die
);
20585 if (is_naming_typedef_decl (decl
))
20586 /* We want that all subsequent calls to lookup_type_die with
20587 TYPE in argument yield the DW_TAG_typedef we have just
20589 equate_type_number_to_die (type
, type_die
);
20591 add_accessibility_attribute (type_die
, decl
);
20594 if (DECL_ABSTRACT_P (decl
))
20595 equate_decl_number_to_die (decl
, type_die
);
20597 if (get_AT (type_die
, DW_AT_name
))
20598 add_pubtype (decl
, type_die
);
20601 /* Generate a DIE for a struct, class, enum or union type. */
20604 gen_tagged_type_die (tree type
,
20605 dw_die_ref context_die
,
20606 enum debug_info_usage usage
)
20610 if (type
== NULL_TREE
20611 || !is_tagged_type (type
))
20614 if (TREE_ASM_WRITTEN (type
))
20616 /* If this is a nested type whose containing class hasn't been written
20617 out yet, writing it out will cover this one, too. This does not apply
20618 to instantiations of member class templates; they need to be added to
20619 the containing class as they are generated. FIXME: This hurts the
20620 idea of combining type decls from multiple TUs, since we can't predict
20621 what set of template instantiations we'll get. */
20622 else if (TYPE_CONTEXT (type
)
20623 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
20624 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
20626 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
20628 if (TREE_ASM_WRITTEN (type
))
20631 /* If that failed, attach ourselves to the stub. */
20632 push_decl_scope (TYPE_CONTEXT (type
));
20633 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
20636 else if (TYPE_CONTEXT (type
) != NULL_TREE
20637 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
20639 /* If this type is local to a function that hasn't been written
20640 out yet, use a NULL context for now; it will be fixed up in
20641 decls_for_scope. */
20642 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
20643 /* A declaration DIE doesn't count; nested types need to go in the
20645 if (context_die
&& is_declaration_die (context_die
))
20646 context_die
= NULL
;
20651 context_die
= declare_in_namespace (type
, context_die
);
20655 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
20657 /* This might have been written out by the call to
20658 declare_in_namespace. */
20659 if (!TREE_ASM_WRITTEN (type
))
20660 gen_enumeration_type_die (type
, context_die
);
20663 gen_struct_or_union_type_die (type
, context_die
, usage
);
20668 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
20669 it up if it is ever completed. gen_*_type_die will set it for us
20670 when appropriate. */
20673 /* Generate a type description DIE. */
20676 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
20677 enum debug_info_usage usage
)
20679 struct array_descr_info info
;
20681 if (type
== NULL_TREE
|| type
== error_mark_node
)
20684 #ifdef ENABLE_CHECKING
20686 verify_type (type
);
20689 if (TYPE_NAME (type
) != NULL_TREE
20690 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
20691 && is_redundant_typedef (TYPE_NAME (type
))
20692 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
20693 /* The DECL of this type is a typedef we don't want to emit debug
20694 info for but we want debug info for its underlying typedef.
20695 This can happen for e.g, the injected-class-name of a C++
20697 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
20699 /* If TYPE is a typedef type variant, let's generate debug info
20700 for the parent typedef which TYPE is a type of. */
20701 if (typedef_variant_p (type
))
20703 if (TREE_ASM_WRITTEN (type
))
20706 /* Prevent broken recursion; we can't hand off to the same type. */
20707 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
20709 /* Give typedefs the right scope. */
20710 context_die
= scope_die_for (type
, context_die
);
20712 TREE_ASM_WRITTEN (type
) = 1;
20714 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
20718 /* If type is an anonymous tagged type named by a typedef, let's
20719 generate debug info for the typedef. */
20720 if (is_naming_typedef_decl (TYPE_NAME (type
)))
20722 /* Use the DIE of the containing namespace as the parent DIE of
20723 the type description DIE we want to generate. */
20724 if (DECL_CONTEXT (TYPE_NAME (type
))
20725 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
20726 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
20728 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
20732 /* We are going to output a DIE to represent the unqualified version
20733 of this type (i.e. without any const or volatile qualifiers) so
20734 get the main variant (i.e. the unqualified version) of this type
20735 now. (Vectors are special because the debugging info is in the
20736 cloned type itself). */
20737 if (TREE_CODE (type
) != VECTOR_TYPE
)
20738 type
= type_main_variant (type
);
20740 /* If this is an array type with hidden descriptor, handle it first. */
20741 if (!TREE_ASM_WRITTEN (type
)
20742 && lang_hooks
.types
.get_array_descr_info
)
20744 memset (&info
, 0, sizeof (info
));
20745 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
20747 gen_descr_array_type_die (type
, &info
, context_die
);
20748 TREE_ASM_WRITTEN (type
) = 1;
20753 if (TREE_ASM_WRITTEN (type
))
20755 /* Variable-length types may be incomplete even if
20756 TREE_ASM_WRITTEN. For such types, fall through to
20757 gen_array_type_die() and possibly fill in
20758 DW_AT_{upper,lower}_bound attributes. */
20759 if ((TREE_CODE (type
) != ARRAY_TYPE
20760 && TREE_CODE (type
) != RECORD_TYPE
20761 && TREE_CODE (type
) != UNION_TYPE
20762 && TREE_CODE (type
) != QUAL_UNION_TYPE
)
20763 || !variably_modified_type_p (type
, NULL
))
20767 switch (TREE_CODE (type
))
20773 case REFERENCE_TYPE
:
20774 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
20775 ensures that the gen_type_die recursion will terminate even if the
20776 type is recursive. Recursive types are possible in Ada. */
20777 /* ??? We could perhaps do this for all types before the switch
20779 TREE_ASM_WRITTEN (type
) = 1;
20781 /* For these types, all that is required is that we output a DIE (or a
20782 set of DIEs) to represent the "basis" type. */
20783 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20784 DINFO_USAGE_IND_USE
);
20788 /* This code is used for C++ pointer-to-data-member types.
20789 Output a description of the relevant class type. */
20790 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
20791 DINFO_USAGE_IND_USE
);
20793 /* Output a description of the type of the object pointed to. */
20794 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20795 DINFO_USAGE_IND_USE
);
20797 /* Now output a DIE to represent this pointer-to-data-member type
20799 gen_ptr_to_mbr_type_die (type
, context_die
);
20802 case FUNCTION_TYPE
:
20803 /* Force out return type (in case it wasn't forced out already). */
20804 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20805 DINFO_USAGE_DIR_USE
);
20806 gen_subroutine_type_die (type
, context_die
);
20810 /* Force out return type (in case it wasn't forced out already). */
20811 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20812 DINFO_USAGE_DIR_USE
);
20813 gen_subroutine_type_die (type
, context_die
);
20818 gen_array_type_die (type
, context_die
);
20821 case ENUMERAL_TYPE
:
20824 case QUAL_UNION_TYPE
:
20825 gen_tagged_type_die (type
, context_die
, usage
);
20831 case FIXED_POINT_TYPE
:
20834 case POINTER_BOUNDS_TYPE
:
20835 /* No DIEs needed for fundamental types. */
20840 /* Just use DW_TAG_unspecified_type. */
20842 dw_die_ref type_die
= lookup_type_die (type
);
20843 if (type_die
== NULL
)
20845 tree name
= TYPE_IDENTIFIER (type
);
20846 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
20848 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
20849 equate_type_number_to_die (type
, type_die
);
20855 if (is_cxx_auto (type
))
20857 tree name
= TYPE_IDENTIFIER (type
);
20858 dw_die_ref
*die
= (name
== get_identifier ("auto")
20859 ? &auto_die
: &decltype_auto_die
);
20862 *die
= new_die (DW_TAG_unspecified_type
,
20863 comp_unit_die (), NULL_TREE
);
20864 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
20866 equate_type_number_to_die (type
, *die
);
20869 gcc_unreachable ();
20872 TREE_ASM_WRITTEN (type
) = 1;
20876 gen_type_die (tree type
, dw_die_ref context_die
)
20878 if (type
!= error_mark_node
)
20880 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
20881 #ifdef ENABLE_CHECKING
20882 dw_die_ref die
= lookup_type_die (type
);
20889 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20890 things which are local to the given block. */
20893 gen_block_die (tree stmt
, dw_die_ref context_die
)
20895 int must_output_die
= 0;
20898 /* Ignore blocks that are NULL. */
20899 if (stmt
== NULL_TREE
)
20902 inlined_func
= inlined_function_outer_scope_p (stmt
);
20904 /* If the block is one fragment of a non-contiguous block, do not
20905 process the variables, since they will have been done by the
20906 origin block. Do process subblocks. */
20907 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
20911 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
20912 gen_block_die (sub
, context_die
);
20917 /* Determine if we need to output any Dwarf DIEs at all to represent this
20920 /* The outer scopes for inlinings *must* always be represented. We
20921 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20922 must_output_die
= 1;
20925 /* Determine if this block directly contains any "significant"
20926 local declarations which we will need to output DIEs for. */
20927 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20928 /* We are not in terse mode so *any* local declaration counts
20929 as being a "significant" one. */
20930 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
20931 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
20932 && (TREE_USED (stmt
)
20933 || TREE_ASM_WRITTEN (stmt
)
20934 || BLOCK_ABSTRACT (stmt
)));
20935 else if ((TREE_USED (stmt
)
20936 || TREE_ASM_WRITTEN (stmt
)
20937 || BLOCK_ABSTRACT (stmt
))
20938 && !dwarf2out_ignore_block (stmt
))
20939 must_output_die
= 1;
20942 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20943 DIE for any block which contains no significant local declarations at
20944 all. Rather, in such cases we just call `decls_for_scope' so that any
20945 needed Dwarf info for any sub-blocks will get properly generated. Note
20946 that in terse mode, our definition of what constitutes a "significant"
20947 local declaration gets restricted to include only inlined function
20948 instances and local (nested) function definitions. */
20949 if (must_output_die
)
20953 /* If STMT block is abstract, that means we have been called
20954 indirectly from dwarf2out_abstract_function.
20955 That function rightfully marks the descendent blocks (of
20956 the abstract function it is dealing with) as being abstract,
20957 precisely to prevent us from emitting any
20958 DW_TAG_inlined_subroutine DIE as a descendent
20959 of an abstract function instance. So in that case, we should
20960 not call gen_inlined_subroutine_die.
20962 Later though, when cgraph asks dwarf2out to emit info
20963 for the concrete instance of the function decl into which
20964 the concrete instance of STMT got inlined, the later will lead
20965 to the generation of a DW_TAG_inlined_subroutine DIE. */
20966 if (! BLOCK_ABSTRACT (stmt
))
20967 gen_inlined_subroutine_die (stmt
, context_die
);
20970 gen_lexical_block_die (stmt
, context_die
);
20973 decls_for_scope (stmt
, context_die
);
20976 /* Process variable DECL (or variable with origin ORIGIN) within
20977 block STMT and add it to CONTEXT_DIE. */
20979 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
20982 tree decl_or_origin
= decl
? decl
: origin
;
20984 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
20985 die
= lookup_decl_die (decl_or_origin
);
20986 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
20987 && TYPE_DECL_IS_STUB (decl_or_origin
))
20988 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
20992 if (die
!= NULL
&& die
->die_parent
== NULL
)
20993 add_child_die (context_die
, die
);
20994 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
20997 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
20998 stmt
, context_die
);
21001 gen_decl_die (decl
, origin
, context_die
);
21004 /* Generate all of the decls declared within a given scope and (recursively)
21005 all of its sub-blocks. */
21008 decls_for_scope (tree stmt
, dw_die_ref context_die
)
21014 /* Ignore NULL blocks. */
21015 if (stmt
== NULL_TREE
)
21018 /* Output the DIEs to represent all of the data objects and typedefs
21019 declared directly within this block but not within any nested
21020 sub-blocks. Also, nested function and tag DIEs have been
21021 generated with a parent of NULL; fix that up now. We don't
21022 have to do this if we're at -g1. */
21023 if (debug_info_level
> DINFO_LEVEL_TERSE
)
21025 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
21026 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
21027 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
21028 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
21032 /* Even if we're at -g1, we need to process the subblocks in order to get
21033 inlined call information. */
21035 /* Output the DIEs to represent all sub-blocks (and the items declared
21036 therein) of this block. */
21037 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
21039 subblocks
= BLOCK_CHAIN (subblocks
))
21040 gen_block_die (subblocks
, context_die
);
21043 /* Is this a typedef we can avoid emitting? */
21046 is_redundant_typedef (const_tree decl
)
21048 if (TYPE_DECL_IS_STUB (decl
))
21051 if (DECL_ARTIFICIAL (decl
)
21052 && DECL_CONTEXT (decl
)
21053 && is_tagged_type (DECL_CONTEXT (decl
))
21054 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
21055 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
21056 /* Also ignore the artificial member typedef for the class name. */
21062 /* Return TRUE if TYPE is a typedef that names a type for linkage
21063 purposes. This kind of typedefs is produced by the C++ FE for
21066 typedef struct {...} foo;
21068 In that case, there is no typedef variant type produced for foo.
21069 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
21073 is_naming_typedef_decl (const_tree decl
)
21075 if (decl
== NULL_TREE
21076 || TREE_CODE (decl
) != TYPE_DECL
21077 || !is_tagged_type (TREE_TYPE (decl
))
21078 || DECL_IS_BUILTIN (decl
)
21079 || is_redundant_typedef (decl
)
21080 /* It looks like Ada produces TYPE_DECLs that are very similar
21081 to C++ naming typedefs but that have different
21082 semantics. Let's be specific to c++ for now. */
21086 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
21087 && TYPE_NAME (TREE_TYPE (decl
)) == decl
21088 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
21089 != TYPE_NAME (TREE_TYPE (decl
))));
21092 /* Looks up the DIE for a context. */
21094 static inline dw_die_ref
21095 lookup_context_die (tree context
)
21099 /* Find die that represents this context. */
21100 if (TYPE_P (context
))
21102 context
= TYPE_MAIN_VARIANT (context
);
21103 dw_die_ref ctx
= lookup_type_die (context
);
21106 return strip_naming_typedef (context
, ctx
);
21109 return lookup_decl_die (context
);
21111 return comp_unit_die ();
21114 /* Returns the DIE for a context. */
21116 static inline dw_die_ref
21117 get_context_die (tree context
)
21121 /* Find die that represents this context. */
21122 if (TYPE_P (context
))
21124 context
= TYPE_MAIN_VARIANT (context
);
21125 return strip_naming_typedef (context
, force_type_die (context
));
21128 return force_decl_die (context
);
21130 return comp_unit_die ();
21133 /* Returns the DIE for decl. A DIE will always be returned. */
21136 force_decl_die (tree decl
)
21138 dw_die_ref decl_die
;
21139 unsigned saved_external_flag
;
21140 tree save_fn
= NULL_TREE
;
21141 decl_die
= lookup_decl_die (decl
);
21144 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
21146 decl_die
= lookup_decl_die (decl
);
21150 switch (TREE_CODE (decl
))
21152 case FUNCTION_DECL
:
21153 /* Clear current_function_decl, so that gen_subprogram_die thinks
21154 that this is a declaration. At this point, we just want to force
21155 declaration die. */
21156 save_fn
= current_function_decl
;
21157 current_function_decl
= NULL_TREE
;
21158 gen_subprogram_die (decl
, context_die
);
21159 current_function_decl
= save_fn
;
21163 /* Set external flag to force declaration die. Restore it after
21164 gen_decl_die() call. */
21165 saved_external_flag
= DECL_EXTERNAL (decl
);
21166 DECL_EXTERNAL (decl
) = 1;
21167 gen_decl_die (decl
, NULL
, context_die
);
21168 DECL_EXTERNAL (decl
) = saved_external_flag
;
21171 case NAMESPACE_DECL
:
21172 if (dwarf_version
>= 3 || !dwarf_strict
)
21173 dwarf2out_decl (decl
);
21175 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
21176 decl_die
= comp_unit_die ();
21179 case TRANSLATION_UNIT_DECL
:
21180 decl_die
= comp_unit_die ();
21184 gcc_unreachable ();
21187 /* We should be able to find the DIE now. */
21189 decl_die
= lookup_decl_die (decl
);
21190 gcc_assert (decl_die
);
21196 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
21197 always returned. */
21200 force_type_die (tree type
)
21202 dw_die_ref type_die
;
21204 type_die
= lookup_type_die (type
);
21207 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
21209 type_die
= modified_type_die (type
, TYPE_QUALS_NO_ADDR_SPACE (type
),
21211 gcc_assert (type_die
);
21216 /* Force out any required namespaces to be able to output DECL,
21217 and return the new context_die for it, if it's changed. */
21220 setup_namespace_context (tree thing
, dw_die_ref context_die
)
21222 tree context
= (DECL_P (thing
)
21223 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
21224 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
21225 /* Force out the namespace. */
21226 context_die
= force_decl_die (context
);
21228 return context_die
;
21231 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
21232 type) within its namespace, if appropriate.
21234 For compatibility with older debuggers, namespace DIEs only contain
21235 declarations; all definitions are emitted at CU scope, with
21236 DW_AT_specification pointing to the declaration (like with class
21240 declare_in_namespace (tree thing
, dw_die_ref context_die
)
21242 dw_die_ref ns_context
;
21244 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21245 return context_die
;
21247 /* External declarations in the local scope only need to be emitted
21248 once, not once in the namespace and once in the scope.
21250 This avoids declaring the `extern' below in the
21251 namespace DIE as well as in the innermost scope:
21264 if (DECL_P (thing
) && DECL_EXTERNAL (thing
) && local_scope_p (context_die
))
21265 return context_die
;
21267 /* If this decl is from an inlined function, then don't try to emit it in its
21268 namespace, as we will get confused. It would have already been emitted
21269 when the abstract instance of the inline function was emitted anyways. */
21270 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
21271 return context_die
;
21273 ns_context
= setup_namespace_context (thing
, context_die
);
21275 if (ns_context
!= context_die
)
21279 if (DECL_P (thing
))
21280 gen_decl_die (thing
, NULL
, ns_context
);
21282 gen_type_die (thing
, ns_context
);
21284 return context_die
;
21287 /* Generate a DIE for a namespace or namespace alias. */
21290 gen_namespace_die (tree decl
, dw_die_ref context_die
)
21292 dw_die_ref namespace_die
;
21294 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
21295 they are an alias of. */
21296 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
21298 /* Output a real namespace or module. */
21299 context_die
= setup_namespace_context (decl
, comp_unit_die ());
21300 namespace_die
= new_die (is_fortran ()
21301 ? DW_TAG_module
: DW_TAG_namespace
,
21302 context_die
, decl
);
21303 /* For Fortran modules defined in different CU don't add src coords. */
21304 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
21306 const char *name
= dwarf2_name (decl
, 0);
21308 add_name_attribute (namespace_die
, name
);
21311 add_name_and_src_coords_attributes (namespace_die
, decl
);
21312 if (DECL_EXTERNAL (decl
))
21313 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
21314 equate_decl_number_to_die (decl
, namespace_die
);
21318 /* Output a namespace alias. */
21320 /* Force out the namespace we are an alias of, if necessary. */
21321 dw_die_ref origin_die
21322 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
21324 if (DECL_FILE_SCOPE_P (decl
)
21325 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
21326 context_die
= setup_namespace_context (decl
, comp_unit_die ());
21327 /* Now create the namespace alias DIE. */
21328 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
21329 add_name_and_src_coords_attributes (namespace_die
, decl
);
21330 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
21331 equate_decl_number_to_die (decl
, namespace_die
);
21333 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
21334 if (want_pubnames ())
21335 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
21338 /* Generate Dwarf debug information for a decl described by DECL.
21339 The return value is currently only meaningful for PARM_DECLs,
21340 for all other decls it returns NULL. */
21343 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
21345 tree decl_or_origin
= decl
? decl
: origin
;
21346 tree class_origin
= NULL
, ultimate_origin
;
21348 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
21351 /* Ignore pointer bounds decls. */
21352 if (DECL_P (decl_or_origin
)
21353 && TREE_TYPE (decl_or_origin
)
21354 && POINTER_BOUNDS_P (decl_or_origin
))
21357 switch (TREE_CODE (decl_or_origin
))
21363 if (!is_fortran () && !is_ada ())
21365 /* The individual enumerators of an enum type get output when we output
21366 the Dwarf representation of the relevant enum type itself. */
21370 /* Emit its type. */
21371 gen_type_die (TREE_TYPE (decl
), context_die
);
21373 /* And its containing namespace. */
21374 context_die
= declare_in_namespace (decl
, context_die
);
21376 gen_const_die (decl
, context_die
);
21379 case FUNCTION_DECL
:
21380 /* Don't output any DIEs to represent mere function declarations,
21381 unless they are class members or explicit block externs. */
21382 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
21383 && DECL_FILE_SCOPE_P (decl_or_origin
)
21384 && (current_function_decl
== NULL_TREE
21385 || DECL_ARTIFICIAL (decl_or_origin
)))
21390 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
21391 on local redeclarations of global functions. That seems broken. */
21392 if (current_function_decl
!= decl
)
21393 /* This is only a declaration. */;
21396 /* If we're emitting a clone, emit info for the abstract instance. */
21397 if (origin
|| DECL_ORIGIN (decl
) != decl
)
21398 dwarf2out_abstract_function (origin
21399 ? DECL_ORIGIN (origin
)
21400 : DECL_ABSTRACT_ORIGIN (decl
));
21402 /* If we're emitting an out-of-line copy of an inline function,
21403 emit info for the abstract instance and set up to refer to it. */
21404 else if (cgraph_function_possibly_inlined_p (decl
)
21405 && ! DECL_ABSTRACT_P (decl
)
21406 && ! class_or_namespace_scope_p (context_die
)
21407 /* dwarf2out_abstract_function won't emit a die if this is just
21408 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
21409 that case, because that works only if we have a die. */
21410 && DECL_INITIAL (decl
) != NULL_TREE
)
21412 dwarf2out_abstract_function (decl
);
21413 set_decl_origin_self (decl
);
21416 /* Otherwise we're emitting the primary DIE for this decl. */
21417 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
21419 /* Before we describe the FUNCTION_DECL itself, make sure that we
21420 have its containing type. */
21422 origin
= decl_class_context (decl
);
21423 if (origin
!= NULL_TREE
)
21424 gen_type_die (origin
, context_die
);
21426 /* And its return type. */
21427 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
21429 /* And its virtual context. */
21430 if (DECL_VINDEX (decl
) != NULL_TREE
)
21431 gen_type_die (DECL_CONTEXT (decl
), context_die
);
21433 /* Make sure we have a member DIE for decl. */
21434 if (origin
!= NULL_TREE
)
21435 gen_type_die_for_member (origin
, decl
, context_die
);
21437 /* And its containing namespace. */
21438 context_die
= declare_in_namespace (decl
, context_die
);
21441 /* Now output a DIE to represent the function itself. */
21443 gen_subprogram_die (decl
, context_die
);
21447 /* If we are in terse mode, don't generate any DIEs to represent any
21448 actual typedefs. */
21449 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21452 /* In the special case of a TYPE_DECL node representing the declaration
21453 of some type tag, if the given TYPE_DECL is marked as having been
21454 instantiated from some other (original) TYPE_DECL node (e.g. one which
21455 was generated within the original definition of an inline function) we
21456 used to generate a special (abbreviated) DW_TAG_structure_type,
21457 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
21458 should be actually referencing those DIEs, as variable DIEs with that
21459 type would be emitted already in the abstract origin, so it was always
21460 removed during unused type prunning. Don't add anything in this
21462 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
21465 if (is_redundant_typedef (decl
))
21466 gen_type_die (TREE_TYPE (decl
), context_die
);
21468 /* Output a DIE to represent the typedef itself. */
21469 gen_typedef_die (decl
, context_die
);
21473 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
21474 gen_label_die (decl
, context_die
);
21479 /* If we are in terse mode, don't generate any DIEs to represent any
21480 variable declarations or definitions. */
21481 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21484 /* Output any DIEs that are needed to specify the type of this data
21486 if (decl_by_reference_p (decl_or_origin
))
21487 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
21489 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
21491 /* And its containing type. */
21492 class_origin
= decl_class_context (decl_or_origin
);
21493 if (class_origin
!= NULL_TREE
)
21494 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
21496 /* And its containing namespace. */
21497 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
21499 /* Now output the DIE to represent the data object itself. This gets
21500 complicated because of the possibility that the VAR_DECL really
21501 represents an inlined instance of a formal parameter for an inline
21503 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
21504 if (ultimate_origin
!= NULL_TREE
21505 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
21506 gen_formal_parameter_die (decl
, origin
,
21507 true /* Emit name attribute. */,
21510 gen_variable_die (decl
, origin
, context_die
);
21514 /* Ignore the nameless fields that are used to skip bits but handle C++
21515 anonymous unions and structs. */
21516 if (DECL_NAME (decl
) != NULL_TREE
21517 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
21518 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
21520 gen_type_die (member_declared_type (decl
), context_die
);
21521 gen_field_die (decl
, context_die
);
21526 if (DECL_BY_REFERENCE (decl_or_origin
))
21527 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
21529 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
21530 return gen_formal_parameter_die (decl
, origin
,
21531 true /* Emit name attribute. */,
21534 case NAMESPACE_DECL
:
21535 case IMPORTED_DECL
:
21536 if (dwarf_version
>= 3 || !dwarf_strict
)
21537 gen_namespace_die (decl
, context_die
);
21540 case NAMELIST_DECL
:
21541 gen_namelist_decl (DECL_NAME (decl
), context_die
,
21542 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
21546 /* Probably some frontend-internal decl. Assume we don't care. */
21547 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
21554 /* Output initial debug information for global DECL. Called at the
21555 end of the parsing process.
21557 This is the initial debug generation process. As such, the DIEs
21558 generated may be incomplete. A later debug generation pass
21559 (dwarf2out_late_global_decl) will augment the information generated
21560 in this pass (e.g., with complete location info). */
21563 dwarf2out_early_global_decl (tree decl
)
21567 /* gen_decl_die() will set DECL_ABSTRACT because
21568 cgraph_function_possibly_inlined_p() returns true. This is in
21569 turn will cause DW_AT_inline attributes to be set.
21571 This happens because at early dwarf generation, there is no
21572 cgraph information, causing cgraph_function_possibly_inlined_p()
21573 to return true. Trick cgraph_function_possibly_inlined_p()
21574 while we generate dwarf early. */
21575 bool save
= symtab
->global_info_ready
;
21576 symtab
->global_info_ready
= true;
21578 /* We don't handle TYPE_DECLs. If required, they'll be reached via
21579 other DECLs and they can point to template types or other things
21580 that dwarf2out can't handle when done via dwarf2out_decl. */
21581 if (TREE_CODE (decl
) != TYPE_DECL
21582 && TREE_CODE (decl
) != PARM_DECL
)
21584 tree save_fndecl
= current_function_decl
;
21585 if (TREE_CODE (decl
) == FUNCTION_DECL
)
21587 /* No cfun means the symbol has no body, so there's nothing
21589 if (!DECL_STRUCT_FUNCTION (decl
))
21590 goto early_decl_exit
;
21592 current_function_decl
= decl
;
21594 dwarf2out_decl (decl
);
21595 if (TREE_CODE (decl
) == FUNCTION_DECL
)
21596 current_function_decl
= save_fndecl
;
21599 symtab
->global_info_ready
= save
;
21602 /* Output debug information for global decl DECL. Called from
21603 toplev.c after compilation proper has finished. */
21606 dwarf2out_late_global_decl (tree decl
)
21608 /* Output any global decls we missed or fill-in any location
21609 information we were unable to determine on the first pass.
21611 Skip over functions because they were handled by the
21612 debug_hooks->function_decl() call in rest_of_handle_final. */
21613 if ((TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
21614 && !POINTER_BOUNDS_P (decl
))
21615 dwarf2out_decl (decl
);
21618 /* Output debug information for type decl DECL. Called from toplev.c
21619 and from language front ends (to record built-in types). */
21621 dwarf2out_type_decl (tree decl
, int local
)
21626 dwarf2out_decl (decl
);
21630 /* Output debug information for imported module or decl DECL.
21631 NAME is non-NULL name in the lexical block if the decl has been renamed.
21632 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
21633 that DECL belongs to.
21634 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
21636 dwarf2out_imported_module_or_decl_1 (tree decl
,
21638 tree lexical_block
,
21639 dw_die_ref lexical_block_die
)
21641 expanded_location xloc
;
21642 dw_die_ref imported_die
= NULL
;
21643 dw_die_ref at_import_die
;
21645 if (TREE_CODE (decl
) == IMPORTED_DECL
)
21647 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
21648 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
21652 xloc
= expand_location (input_location
);
21654 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
21656 at_import_die
= force_type_die (TREE_TYPE (decl
));
21657 /* For namespace N { typedef void T; } using N::T; base_type_die
21658 returns NULL, but DW_TAG_imported_declaration requires
21659 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
21660 if (!at_import_die
)
21662 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
21663 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
21664 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
21665 gcc_assert (at_import_die
);
21670 at_import_die
= lookup_decl_die (decl
);
21671 if (!at_import_die
)
21673 /* If we're trying to avoid duplicate debug info, we may not have
21674 emitted the member decl for this field. Emit it now. */
21675 if (TREE_CODE (decl
) == FIELD_DECL
)
21677 tree type
= DECL_CONTEXT (decl
);
21679 if (TYPE_CONTEXT (type
)
21680 && TYPE_P (TYPE_CONTEXT (type
))
21681 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
21682 DINFO_USAGE_DIR_USE
))
21684 gen_type_die_for_member (type
, decl
,
21685 get_context_die (TYPE_CONTEXT (type
)));
21687 if (TREE_CODE (decl
) == NAMELIST_DECL
)
21688 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
21689 get_context_die (DECL_CONTEXT (decl
)),
21692 at_import_die
= force_decl_die (decl
);
21696 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
21698 if (dwarf_version
>= 3 || !dwarf_strict
)
21699 imported_die
= new_die (DW_TAG_imported_module
,
21706 imported_die
= new_die (DW_TAG_imported_declaration
,
21710 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
21711 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
21713 add_AT_string (imported_die
, DW_AT_name
,
21714 IDENTIFIER_POINTER (name
));
21715 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
21718 /* Output debug information for imported module or decl DECL.
21719 NAME is non-NULL name in context if the decl has been renamed.
21720 CHILD is true if decl is one of the renamed decls as part of
21721 importing whole module. */
21724 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
21727 /* dw_die_ref at_import_die; */
21728 dw_die_ref scope_die
;
21730 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21737 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
21738 We need decl DIE for reference and scope die. First, get DIE for the decl
21741 /* Get the scope die for decl context. Use comp_unit_die for global module
21742 or decl. If die is not found for non globals, force new die. */
21744 && TYPE_P (context
)
21745 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
21748 if (!(dwarf_version
>= 3 || !dwarf_strict
))
21751 scope_die
= get_context_die (context
);
21755 gcc_assert (scope_die
->die_child
);
21756 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
21757 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
21758 scope_die
= scope_die
->die_child
;
21761 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
21762 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
21765 /* Output debug information for namelists. */
21768 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
21770 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
21774 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21777 gcc_assert (scope_die
!= NULL
);
21778 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
21779 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
21781 /* If there are no item_decls, we have a nondefining namelist, e.g.
21782 with USE association; hence, set DW_AT_declaration. */
21783 if (item_decls
== NULL_TREE
)
21785 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
21789 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
21791 nml_item_ref_die
= lookup_decl_die (value
);
21792 if (!nml_item_ref_die
)
21793 nml_item_ref_die
= force_decl_die (value
);
21795 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
21796 add_AT_die_ref (nml_item_die
, DW_AT_namelist_items
, nml_item_ref_die
);
21802 /* Write the debugging output for DECL and return the DIE. */
21805 dwarf2out_decl (tree decl
)
21807 dw_die_ref context_die
= comp_unit_die ();
21809 switch (TREE_CODE (decl
))
21814 case FUNCTION_DECL
:
21815 /* What we would really like to do here is to filter out all mere
21816 file-scope declarations of file-scope functions which are never
21817 referenced later within this translation unit (and keep all of ones
21818 that *are* referenced later on) but we aren't clairvoyant, so we have
21819 no idea which functions will be referenced in the future (i.e. later
21820 on within the current translation unit). So here we just ignore all
21821 file-scope function declarations which are not also definitions. If
21822 and when the debugger needs to know something about these functions,
21823 it will have to hunt around and find the DWARF information associated
21824 with the definition of the function.
21826 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
21827 nodes represent definitions and which ones represent mere
21828 declarations. We have to check DECL_INITIAL instead. That's because
21829 the C front-end supports some weird semantics for "extern inline"
21830 function definitions. These can get inlined within the current
21831 translation unit (and thus, we need to generate Dwarf info for their
21832 abstract instances so that the Dwarf info for the concrete inlined
21833 instances can have something to refer to) but the compiler never
21834 generates any out-of-lines instances of such things (despite the fact
21835 that they *are* definitions).
21837 The important point is that the C front-end marks these "extern
21838 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
21839 them anyway. Note that the C++ front-end also plays some similar games
21840 for inline function definitions appearing within include files which
21841 also contain `#pragma interface' pragmas.
21843 If we are called from dwarf2out_abstract_function output a DIE
21844 anyway. We can end up here this way with early inlining and LTO
21845 where the inlined function is output in a different LTRANS unit
21847 if (DECL_INITIAL (decl
) == NULL_TREE
21848 && ! DECL_ABSTRACT_P (decl
))
21851 /* If we're a nested function, initially use a parent of NULL; if we're
21852 a plain function, this will be fixed up in decls_for_scope. If
21853 we're a method, it will be ignored, since we already have a DIE. */
21854 if (decl_function_context (decl
)
21855 /* But if we're in terse mode, we don't care about scope. */
21856 && debug_info_level
> DINFO_LEVEL_TERSE
)
21857 context_die
= NULL
;
21861 /* For local statics lookup proper context die. */
21862 if (local_function_static (decl
))
21863 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
21865 /* If we are in terse mode, don't generate any DIEs to represent any
21866 variable declarations or definitions. */
21867 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21872 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21874 if (!is_fortran () && !is_ada ())
21876 if (TREE_STATIC (decl
) && decl_function_context (decl
))
21877 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
21880 case NAMESPACE_DECL
:
21881 case IMPORTED_DECL
:
21882 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21884 if (lookup_decl_die (decl
) != NULL
)
21889 /* Don't emit stubs for types unless they are needed by other DIEs. */
21890 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
21893 /* Don't bother trying to generate any DIEs to represent any of the
21894 normal built-in types for the language we are compiling. */
21895 if (DECL_IS_BUILTIN (decl
))
21898 /* If we are in terse mode, don't generate any DIEs for types. */
21899 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21902 /* If we're a function-scope tag, initially use a parent of NULL;
21903 this will be fixed up in decls_for_scope. */
21904 if (decl_function_context (decl
))
21905 context_die
= NULL
;
21909 case NAMELIST_DECL
:
21916 gen_decl_die (decl
, NULL
, context_die
);
21918 #ifdef ENABLE_CHECKING
21919 dw_die_ref die
= lookup_decl_die (decl
);
21925 /* Write the debugging output for DECL. */
21928 dwarf2out_function_decl (tree decl
)
21930 dwarf2out_decl (decl
);
21931 call_arg_locations
= NULL
;
21932 call_arg_loc_last
= NULL
;
21933 call_site_count
= -1;
21934 tail_call_site_count
= -1;
21935 decl_loc_table
->empty ();
21936 cached_dw_loc_list_table
->empty ();
21939 /* Output a marker (i.e. a label) for the beginning of the generated code for
21940 a lexical block. */
21943 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
21944 unsigned int blocknum
)
21946 switch_to_section (current_function_section ());
21947 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
21950 /* Output a marker (i.e. a label) for the end of the generated code for a
21954 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
21956 switch_to_section (current_function_section ());
21957 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
21960 /* Returns nonzero if it is appropriate not to emit any debugging
21961 information for BLOCK, because it doesn't contain any instructions.
21963 Don't allow this for blocks with nested functions or local classes
21964 as we would end up with orphans, and in the presence of scheduling
21965 we may end up calling them anyway. */
21968 dwarf2out_ignore_block (const_tree block
)
21973 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
21974 if (TREE_CODE (decl
) == FUNCTION_DECL
21975 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
21977 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
21979 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
21980 if (TREE_CODE (decl
) == FUNCTION_DECL
21981 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
21988 /* Hash table routines for file_hash. */
21991 dwarf_file_hasher::equal (dwarf_file_data
*p1
, const char *p2
)
21993 return filename_cmp (p1
->filename
, p2
) == 0;
21997 dwarf_file_hasher::hash (dwarf_file_data
*p
)
21999 return htab_hash_string (p
->filename
);
22002 /* Lookup FILE_NAME (in the list of filenames that we know about here in
22003 dwarf2out.c) and return its "index". The index of each (known) filename is
22004 just a unique number which is associated with only that one filename. We
22005 need such numbers for the sake of generating labels (in the .debug_sfnames
22006 section) and references to those files numbers (in the .debug_srcinfo
22007 and.debug_macinfo sections). If the filename given as an argument is not
22008 found in our current list, add it to the list and assign it the next
22009 available unique index number. */
22011 static struct dwarf_file_data
*
22012 lookup_filename (const char *file_name
)
22014 struct dwarf_file_data
* created
;
22019 dwarf_file_data
**slot
22020 = file_table
->find_slot_with_hash (file_name
, htab_hash_string (file_name
),
22025 created
= ggc_alloc
<dwarf_file_data
> ();
22026 created
->filename
= file_name
;
22027 created
->emitted_number
= 0;
22032 /* If the assembler will construct the file table, then translate the compiler
22033 internal file table number into the assembler file table number, and emit
22034 a .file directive if we haven't already emitted one yet. The file table
22035 numbers are different because we prune debug info for unused variables and
22036 types, which may include filenames. */
22039 maybe_emit_file (struct dwarf_file_data
* fd
)
22041 if (! fd
->emitted_number
)
22043 if (last_emitted_file
)
22044 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
22046 fd
->emitted_number
= 1;
22047 last_emitted_file
= fd
;
22049 if (DWARF2_ASM_LINE_DEBUG_INFO
)
22051 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
22052 output_quoted_string (asm_out_file
,
22053 remap_debug_filename (fd
->filename
));
22054 fputc ('\n', asm_out_file
);
22058 return fd
->emitted_number
;
22061 /* Schedule generation of a DW_AT_const_value attribute to DIE.
22062 That generation should happen after function debug info has been
22063 generated. The value of the attribute is the constant value of ARG. */
22066 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
22068 die_arg_entry entry
;
22073 if (!tmpl_value_parm_die_table
)
22074 vec_alloc (tmpl_value_parm_die_table
, 32);
22078 vec_safe_push (tmpl_value_parm_die_table
, entry
);
22081 /* Return TRUE if T is an instance of generic type, FALSE
22085 generic_type_p (tree t
)
22087 if (t
== NULL_TREE
|| !TYPE_P (t
))
22089 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
22092 /* Schedule the generation of the generic parameter dies for the
22093 instance of generic type T. The proper generation itself is later
22094 done by gen_scheduled_generic_parms_dies. */
22097 schedule_generic_params_dies_gen (tree t
)
22099 if (!generic_type_p (t
))
22102 if (!generic_type_instances
)
22103 vec_alloc (generic_type_instances
, 256);
22105 vec_safe_push (generic_type_instances
, t
);
22108 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
22109 by append_entry_to_tmpl_value_parm_die_table. This function must
22110 be called after function DIEs have been generated. */
22113 gen_remaining_tmpl_value_param_die_attribute (void)
22115 if (tmpl_value_parm_die_table
)
22120 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
22121 tree_add_const_value_attribute (e
->die
, e
->arg
);
22125 /* Generate generic parameters DIEs for instances of generic types
22126 that have been previously scheduled by
22127 schedule_generic_params_dies_gen. This function must be called
22128 after all the types of the CU have been laid out. */
22131 gen_scheduled_generic_parms_dies (void)
22136 if (!generic_type_instances
)
22139 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
22140 if (COMPLETE_TYPE_P (t
))
22141 gen_generic_params_dies (t
);
22145 /* Replace DW_AT_name for the decl with name. */
22148 dwarf2out_set_name (tree decl
, tree name
)
22154 die
= TYPE_SYMTAB_DIE (decl
);
22158 dname
= dwarf2_name (name
, 0);
22162 attr
= get_AT (die
, DW_AT_name
);
22165 struct indirect_string_node
*node
;
22167 node
= find_AT_string (dname
);
22168 /* replace the string. */
22169 attr
->dw_attr_val
.v
.val_str
= node
;
22173 add_name_attribute (die
, dname
);
22176 /* True if before or during processing of the first function being emitted. */
22177 static bool in_first_function_p
= true;
22178 /* True if loc_note during dwarf2out_var_location call might still be
22179 before first real instruction at address equal to .Ltext0. */
22180 static bool maybe_at_text_label_p
= true;
22181 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
22182 static unsigned int first_loclabel_num_not_at_text_label
;
22184 /* Called by the final INSN scan whenever we see a var location. We
22185 use it to drop labels in the right places, and throw the location in
22186 our lookup table. */
22189 dwarf2out_var_location (rtx_insn
*loc_note
)
22191 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
22192 struct var_loc_node
*newloc
;
22193 rtx_insn
*next_real
, *next_note
;
22194 static const char *last_label
;
22195 static const char *last_postcall_label
;
22196 static bool last_in_cold_section_p
;
22197 static rtx_insn
*expected_next_loc_note
;
22201 if (!NOTE_P (loc_note
))
22203 if (CALL_P (loc_note
))
22206 if (SIBLING_CALL_P (loc_note
))
22207 tail_call_site_count
++;
22212 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
22213 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
22216 /* Optimize processing a large consecutive sequence of location
22217 notes so we don't spend too much time in next_real_insn. If the
22218 next insn is another location note, remember the next_real_insn
22219 calculation for next time. */
22220 next_real
= cached_next_real_insn
;
22223 if (expected_next_loc_note
!= loc_note
)
22227 next_note
= NEXT_INSN (loc_note
);
22229 || next_note
->deleted ()
22230 || ! NOTE_P (next_note
)
22231 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
22232 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
22236 next_real
= next_real_insn (loc_note
);
22240 expected_next_loc_note
= next_note
;
22241 cached_next_real_insn
= next_real
;
22244 cached_next_real_insn
= NULL
;
22246 /* If there are no instructions which would be affected by this note,
22247 don't do anything. */
22249 && next_real
== NULL_RTX
22250 && !NOTE_DURING_CALL_P (loc_note
))
22253 if (next_real
== NULL_RTX
)
22254 next_real
= get_last_insn ();
22256 /* If there were any real insns between note we processed last time
22257 and this note (or if it is the first note), clear
22258 last_{,postcall_}label so that they are not reused this time. */
22259 if (last_var_location_insn
== NULL_RTX
22260 || last_var_location_insn
!= next_real
22261 || last_in_cold_section_p
!= in_cold_section_p
)
22264 last_postcall_label
= NULL
;
22269 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
22270 newloc
= add_var_loc_to_decl (decl
, loc_note
,
22271 NOTE_DURING_CALL_P (loc_note
)
22272 ? last_postcall_label
: last_label
);
22273 if (newloc
== NULL
)
22282 /* If there were no real insns between note we processed last time
22283 and this note, use the label we emitted last time. Otherwise
22284 create a new label and emit it. */
22285 if (last_label
== NULL
)
22287 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
22288 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
22290 last_label
= ggc_strdup (loclabel
);
22291 /* See if loclabel might be equal to .Ltext0. If yes,
22292 bump first_loclabel_num_not_at_text_label. */
22293 if (!have_multiple_function_sections
22294 && in_first_function_p
22295 && maybe_at_text_label_p
)
22297 static rtx_insn
*last_start
;
22299 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
22300 if (insn
== last_start
)
22302 else if (!NONDEBUG_INSN_P (insn
))
22306 rtx body
= PATTERN (insn
);
22307 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
22309 /* Inline asm could occupy zero bytes. */
22310 else if (GET_CODE (body
) == ASM_INPUT
22311 || asm_noperands (body
) >= 0)
22313 #ifdef HAVE_attr_length
22314 else if (get_attr_min_length (insn
) == 0)
22319 /* Assume insn has non-zero length. */
22320 maybe_at_text_label_p
= false;
22324 if (maybe_at_text_label_p
)
22326 last_start
= loc_note
;
22327 first_loclabel_num_not_at_text_label
= loclabel_num
;
22334 struct call_arg_loc_node
*ca_loc
22335 = ggc_cleared_alloc
<call_arg_loc_node
> ();
22336 rtx_insn
*prev
= prev_real_insn (loc_note
);
22338 ca_loc
->call_arg_loc_note
= loc_note
;
22339 ca_loc
->next
= NULL
;
22340 ca_loc
->label
= last_label
;
22343 || (NONJUMP_INSN_P (prev
)
22344 && GET_CODE (PATTERN (prev
)) == SEQUENCE
22345 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
22346 if (!CALL_P (prev
))
22347 prev
= as_a
<rtx_sequence
*> (PATTERN (prev
))->insn (0);
22348 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
22349 x
= get_call_rtx_from (PATTERN (prev
));
22352 x
= XEXP (XEXP (x
, 0), 0);
22353 if (GET_CODE (x
) == SYMBOL_REF
22354 && SYMBOL_REF_DECL (x
)
22355 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
22356 ca_loc
->symbol_ref
= x
;
22358 ca_loc
->block
= insn_scope (prev
);
22359 if (call_arg_locations
)
22360 call_arg_loc_last
->next
= ca_loc
;
22362 call_arg_locations
= ca_loc
;
22363 call_arg_loc_last
= ca_loc
;
22365 else if (!NOTE_DURING_CALL_P (loc_note
))
22366 newloc
->label
= last_label
;
22369 if (!last_postcall_label
)
22371 sprintf (loclabel
, "%s-1", last_label
);
22372 last_postcall_label
= ggc_strdup (loclabel
);
22374 newloc
->label
= last_postcall_label
;
22377 last_var_location_insn
= next_real
;
22378 last_in_cold_section_p
= in_cold_section_p
;
22381 /* Note in one location list that text section has changed. */
22384 var_location_switch_text_section_1 (var_loc_list
**slot
, void *)
22386 var_loc_list
*list
= *slot
;
22388 list
->last_before_switch
22389 = list
->last
->next
? list
->last
->next
: list
->last
;
22393 /* Note in all location lists that text section has changed. */
22396 var_location_switch_text_section (void)
22398 if (decl_loc_table
== NULL
)
22401 decl_loc_table
->traverse
<void *, var_location_switch_text_section_1
> (NULL
);
22404 /* Create a new line number table. */
22406 static dw_line_info_table
*
22407 new_line_info_table (void)
22409 dw_line_info_table
*table
;
22411 table
= ggc_cleared_alloc
<dw_line_info_table_struct
> ();
22412 table
->file_num
= 1;
22413 table
->line_num
= 1;
22414 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
22419 /* Lookup the "current" table into which we emit line info, so
22420 that we don't have to do it for every source line. */
22423 set_cur_line_info_table (section
*sec
)
22425 dw_line_info_table
*table
;
22427 if (sec
== text_section
)
22428 table
= text_section_line_info
;
22429 else if (sec
== cold_text_section
)
22431 table
= cold_text_section_line_info
;
22434 cold_text_section_line_info
= table
= new_line_info_table ();
22435 table
->end_label
= cold_end_label
;
22440 const char *end_label
;
22442 if (flag_reorder_blocks_and_partition
)
22444 if (in_cold_section_p
)
22445 end_label
= crtl
->subsections
.cold_section_end_label
;
22447 end_label
= crtl
->subsections
.hot_section_end_label
;
22451 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22452 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
22453 current_function_funcdef_no
);
22454 end_label
= ggc_strdup (label
);
22457 table
= new_line_info_table ();
22458 table
->end_label
= end_label
;
22460 vec_safe_push (separate_line_info
, table
);
22463 if (DWARF2_ASM_LINE_DEBUG_INFO
)
22464 table
->is_stmt
= (cur_line_info_table
22465 ? cur_line_info_table
->is_stmt
22466 : DWARF_LINE_DEFAULT_IS_STMT_START
);
22467 cur_line_info_table
= table
;
22471 /* We need to reset the locations at the beginning of each
22472 function. We can't do this in the end_function hook, because the
22473 declarations that use the locations won't have been output when
22474 that hook is called. Also compute have_multiple_function_sections here. */
22477 dwarf2out_begin_function (tree fun
)
22479 section
*sec
= function_section (fun
);
22481 if (sec
!= text_section
)
22482 have_multiple_function_sections
= true;
22484 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
22486 gcc_assert (current_function_decl
== fun
);
22487 cold_text_section
= unlikely_text_section ();
22488 switch_to_section (cold_text_section
);
22489 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
22490 switch_to_section (sec
);
22493 dwarf2out_note_section_used ();
22494 call_site_count
= 0;
22495 tail_call_site_count
= 0;
22497 set_cur_line_info_table (sec
);
22500 /* Helper function of dwarf2out_end_function, called only after emitting
22501 the very first function into assembly. Check if some .debug_loc range
22502 might end with a .LVL* label that could be equal to .Ltext0.
22503 In that case we must force using absolute addresses in .debug_loc ranges,
22504 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
22505 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
22507 Set have_multiple_function_sections to true in that case and
22508 terminate htab traversal. */
22511 find_empty_loc_ranges_at_text_label (var_loc_list
**slot
, int)
22513 var_loc_list
*entry
= *slot
;
22514 struct var_loc_node
*node
;
22516 node
= entry
->first
;
22517 if (node
&& node
->next
&& node
->next
->label
)
22520 const char *label
= node
->next
->label
;
22521 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
22523 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
22525 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
22526 if (strcmp (label
, loclabel
) == 0)
22528 have_multiple_function_sections
= true;
22536 /* Hook called after emitting a function into assembly.
22537 This does something only for the very first function emitted. */
22540 dwarf2out_end_function (unsigned int)
22542 if (in_first_function_p
22543 && !have_multiple_function_sections
22544 && first_loclabel_num_not_at_text_label
22546 decl_loc_table
->traverse
<int, find_empty_loc_ranges_at_text_label
> (0);
22547 in_first_function_p
= false;
22548 maybe_at_text_label_p
= false;
22551 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
22552 front-ends register a translation unit even before dwarf2out_init is
22554 static tree main_translation_unit
= NULL_TREE
;
22556 /* Hook called by front-ends after they built their main translation unit.
22557 Associate comp_unit_die to UNIT. */
22560 dwarf2out_register_main_translation_unit (tree unit
)
22562 gcc_assert (TREE_CODE (unit
) == TRANSLATION_UNIT_DECL
22563 && main_translation_unit
== NULL_TREE
);
22564 main_translation_unit
= unit
;
22565 /* If dwarf2out_init has not been called yet, it will perform the association
22566 itself looking at main_translation_unit. */
22567 if (decl_die_table
!= NULL
)
22568 equate_decl_number_to_die (unit
, comp_unit_die ());
22571 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
22574 push_dw_line_info_entry (dw_line_info_table
*table
,
22575 enum dw_line_info_opcode opcode
, unsigned int val
)
22577 dw_line_info_entry e
;
22580 vec_safe_push (table
->entries
, e
);
22583 /* Output a label to mark the beginning of a source code line entry
22584 and record information relating to this source line, in
22585 'line_info_table' for later output of the .debug_line section. */
22586 /* ??? The discriminator parameter ought to be unsigned. */
22589 dwarf2out_source_line (unsigned int line
, const char *filename
,
22590 int discriminator
, bool is_stmt
)
22592 unsigned int file_num
;
22593 dw_line_info_table
*table
;
22595 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
22598 /* The discriminator column was added in dwarf4. Simplify the below
22599 by simply removing it if we're not supposed to output it. */
22600 if (dwarf_version
< 4 && dwarf_strict
)
22603 table
= cur_line_info_table
;
22604 file_num
= maybe_emit_file (lookup_filename (filename
));
22606 /* ??? TODO: Elide duplicate line number entries. Traditionally,
22607 the debugger has used the second (possibly duplicate) line number
22608 at the beginning of the function to mark the end of the prologue.
22609 We could eliminate any other duplicates within the function. For
22610 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
22611 that second line number entry. */
22612 /* Recall that this end-of-prologue indication is *not* the same thing
22613 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
22614 to which the hook corresponds, follows the last insn that was
22615 emitted by gen_prologue. What we need is to precede the first insn
22616 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
22617 insn that corresponds to something the user wrote. These may be
22618 very different locations once scheduling is enabled. */
22620 if (0 && file_num
== table
->file_num
22621 && line
== table
->line_num
22622 && discriminator
== table
->discrim_num
22623 && is_stmt
== table
->is_stmt
)
22626 switch_to_section (current_function_section ());
22628 /* If requested, emit something human-readable. */
22629 if (flag_debug_asm
)
22630 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
22632 if (DWARF2_ASM_LINE_DEBUG_INFO
)
22634 /* Emit the .loc directive understood by GNU as. */
22635 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
22636 file_num, line, is_stmt, discriminator */
22637 fputs ("\t.loc ", asm_out_file
);
22638 fprint_ul (asm_out_file
, file_num
);
22639 putc (' ', asm_out_file
);
22640 fprint_ul (asm_out_file
, line
);
22641 putc (' ', asm_out_file
);
22642 putc ('0', asm_out_file
);
22644 if (is_stmt
!= table
->is_stmt
)
22646 fputs (" is_stmt ", asm_out_file
);
22647 putc (is_stmt
? '1' : '0', asm_out_file
);
22649 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
22651 gcc_assert (discriminator
> 0);
22652 fputs (" discriminator ", asm_out_file
);
22653 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
22655 putc ('\n', asm_out_file
);
22659 unsigned int label_num
= ++line_info_label_num
;
22661 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
22663 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
22664 if (file_num
!= table
->file_num
)
22665 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
22666 if (discriminator
!= table
->discrim_num
)
22667 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
22668 if (is_stmt
!= table
->is_stmt
)
22669 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
22670 push_dw_line_info_entry (table
, LI_set_line
, line
);
22673 table
->file_num
= file_num
;
22674 table
->line_num
= line
;
22675 table
->discrim_num
= discriminator
;
22676 table
->is_stmt
= is_stmt
;
22677 table
->in_use
= true;
22680 /* Record the beginning of a new source file. */
22683 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
22685 if (flag_eliminate_dwarf2_dups
)
22687 /* Record the beginning of the file for break_out_includes. */
22688 dw_die_ref bincl_die
;
22690 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
22691 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
22694 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22697 e
.code
= DW_MACINFO_start_file
;
22699 e
.info
= ggc_strdup (filename
);
22700 vec_safe_push (macinfo_table
, e
);
22704 /* Record the end of a source file. */
22707 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
22709 if (flag_eliminate_dwarf2_dups
)
22710 /* Record the end of the file for break_out_includes. */
22711 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
22713 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22716 e
.code
= DW_MACINFO_end_file
;
22719 vec_safe_push (macinfo_table
, e
);
22723 /* Called from debug_define in toplev.c. The `buffer' parameter contains
22724 the tail part of the directive line, i.e. the part which is past the
22725 initial whitespace, #, whitespace, directive-name, whitespace part. */
22728 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
22729 const char *buffer ATTRIBUTE_UNUSED
)
22731 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22734 /* Insert a dummy first entry to be able to optimize the whole
22735 predefined macro block using DW_MACRO_GNU_transparent_include. */
22736 if (macinfo_table
->is_empty () && lineno
<= 1)
22741 vec_safe_push (macinfo_table
, e
);
22743 e
.code
= DW_MACINFO_define
;
22745 e
.info
= ggc_strdup (buffer
);
22746 vec_safe_push (macinfo_table
, e
);
22750 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
22751 the tail part of the directive line, i.e. the part which is past the
22752 initial whitespace, #, whitespace, directive-name, whitespace part. */
22755 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
22756 const char *buffer ATTRIBUTE_UNUSED
)
22758 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22761 /* Insert a dummy first entry to be able to optimize the whole
22762 predefined macro block using DW_MACRO_GNU_transparent_include. */
22763 if (macinfo_table
->is_empty () && lineno
<= 1)
22768 vec_safe_push (macinfo_table
, e
);
22770 e
.code
= DW_MACINFO_undef
;
22772 e
.info
= ggc_strdup (buffer
);
22773 vec_safe_push (macinfo_table
, e
);
22777 /* Helpers to manipulate hash table of CUs. */
22779 struct macinfo_entry_hasher
: nofree_ptr_hash
<macinfo_entry
>
22781 static inline hashval_t
hash (const macinfo_entry
*);
22782 static inline bool equal (const macinfo_entry
*, const macinfo_entry
*);
22786 macinfo_entry_hasher::hash (const macinfo_entry
*entry
)
22788 return htab_hash_string (entry
->info
);
22792 macinfo_entry_hasher::equal (const macinfo_entry
*entry1
,
22793 const macinfo_entry
*entry2
)
22795 return !strcmp (entry1
->info
, entry2
->info
);
22798 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
22800 /* Output a single .debug_macinfo entry. */
22803 output_macinfo_op (macinfo_entry
*ref
)
22807 struct indirect_string_node
*node
;
22808 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22809 struct dwarf_file_data
*fd
;
22813 case DW_MACINFO_start_file
:
22814 fd
= lookup_filename (ref
->info
);
22815 file_num
= maybe_emit_file (fd
);
22816 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
22817 dw2_asm_output_data_uleb128 (ref
->lineno
,
22818 "Included from line number %lu",
22819 (unsigned long) ref
->lineno
);
22820 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
22822 case DW_MACINFO_end_file
:
22823 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
22825 case DW_MACINFO_define
:
22826 case DW_MACINFO_undef
:
22827 len
= strlen (ref
->info
) + 1;
22829 && len
> DWARF_OFFSET_SIZE
22830 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
22831 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
22833 ref
->code
= ref
->code
== DW_MACINFO_define
22834 ? DW_MACRO_GNU_define_indirect
22835 : DW_MACRO_GNU_undef_indirect
;
22836 output_macinfo_op (ref
);
22839 dw2_asm_output_data (1, ref
->code
,
22840 ref
->code
== DW_MACINFO_define
22841 ? "Define macro" : "Undefine macro");
22842 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
22843 (unsigned long) ref
->lineno
);
22844 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
22846 case DW_MACRO_GNU_define_indirect
:
22847 case DW_MACRO_GNU_undef_indirect
:
22848 node
= find_AT_string (ref
->info
);
22850 && ((node
->form
== DW_FORM_strp
)
22851 || (node
->form
== DW_FORM_GNU_str_index
)));
22852 dw2_asm_output_data (1, ref
->code
,
22853 ref
->code
== DW_MACRO_GNU_define_indirect
22854 ? "Define macro indirect"
22855 : "Undefine macro indirect");
22856 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
22857 (unsigned long) ref
->lineno
);
22858 if (node
->form
== DW_FORM_strp
)
22859 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
22860 debug_str_section
, "The macro: \"%s\"",
22863 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
22866 case DW_MACRO_GNU_transparent_include
:
22867 dw2_asm_output_data (1, ref
->code
, "Transparent include");
22868 ASM_GENERATE_INTERNAL_LABEL (label
,
22869 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
22870 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
22873 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
22874 ASM_COMMENT_START
, (unsigned long) ref
->code
);
22879 /* Attempt to make a sequence of define/undef macinfo ops shareable with
22880 other compilation unit .debug_macinfo sections. IDX is the first
22881 index of a define/undef, return the number of ops that should be
22882 emitted in a comdat .debug_macinfo section and emit
22883 a DW_MACRO_GNU_transparent_include entry referencing it.
22884 If the define/undef entry should be emitted normally, return 0. */
22887 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
22888 macinfo_hash_type
**macinfo_htab
)
22890 macinfo_entry
*first
, *second
, *cur
, *inc
;
22891 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
22892 unsigned char checksum
[16];
22893 struct md5_ctx ctx
;
22894 char *grp_name
, *tail
;
22896 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
22897 macinfo_entry
**slot
;
22899 first
= &(*macinfo_table
)[idx
];
22900 second
= &(*macinfo_table
)[idx
+ 1];
22902 /* Optimize only if there are at least two consecutive define/undef ops,
22903 and either all of them are before first DW_MACINFO_start_file
22904 with lineno {0,1} (i.e. predefined macro block), or all of them are
22905 in some included header file. */
22906 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
22908 if (vec_safe_is_empty (files
))
22910 if (first
->lineno
> 1 || second
->lineno
> 1)
22913 else if (first
->lineno
== 0)
22916 /* Find the last define/undef entry that can be grouped together
22917 with first and at the same time compute md5 checksum of their
22918 codes, linenumbers and strings. */
22919 md5_init_ctx (&ctx
);
22920 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
22921 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
22923 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
22927 unsigned char code
= cur
->code
;
22928 md5_process_bytes (&code
, 1, &ctx
);
22929 checksum_uleb128 (cur
->lineno
, &ctx
);
22930 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
22932 md5_finish_ctx (&ctx
, checksum
);
22935 /* From the containing include filename (if any) pick up just
22936 usable characters from its basename. */
22937 if (vec_safe_is_empty (files
))
22940 base
= lbasename (files
->last ().info
);
22941 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
22942 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
22943 encoded_filename_len
++;
22944 /* Count . at the end. */
22945 if (encoded_filename_len
)
22946 encoded_filename_len
++;
22948 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
22949 linebuf_len
= strlen (linebuf
);
22951 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
22952 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
22954 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
22955 tail
= grp_name
+ 4;
22956 if (encoded_filename_len
)
22958 for (i
= 0; base
[i
]; i
++)
22959 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
22963 memcpy (tail
, linebuf
, linebuf_len
);
22964 tail
+= linebuf_len
;
22966 for (i
= 0; i
< 16; i
++)
22967 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
22969 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
22970 in the empty vector entry before the first define/undef. */
22971 inc
= &(*macinfo_table
)[idx
- 1];
22972 inc
->code
= DW_MACRO_GNU_transparent_include
;
22974 inc
->info
= ggc_strdup (grp_name
);
22975 if (!*macinfo_htab
)
22976 *macinfo_htab
= new macinfo_hash_type (10);
22977 /* Avoid emitting duplicates. */
22978 slot
= (*macinfo_htab
)->find_slot (inc
, INSERT
);
22983 /* If such an entry has been used before, just emit
22984 a DW_MACRO_GNU_transparent_include op. */
22986 output_macinfo_op (inc
);
22987 /* And clear all macinfo_entry in the range to avoid emitting them
22988 in the second pass. */
22989 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
22998 inc
->lineno
= (*macinfo_htab
)->elements ();
22999 output_macinfo_op (inc
);
23004 /* Save any strings needed by the macinfo table in the debug str
23005 table. All strings must be collected into the table by the time
23006 index_string is called. */
23009 save_macinfo_strings (void)
23013 macinfo_entry
*ref
;
23015 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
23019 /* Match the logic in output_macinfo_op to decide on
23020 indirect strings. */
23021 case DW_MACINFO_define
:
23022 case DW_MACINFO_undef
:
23023 len
= strlen (ref
->info
) + 1;
23025 && len
> DWARF_OFFSET_SIZE
23026 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
23027 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
23028 set_indirect_string (find_AT_string (ref
->info
));
23030 case DW_MACRO_GNU_define_indirect
:
23031 case DW_MACRO_GNU_undef_indirect
:
23032 set_indirect_string (find_AT_string (ref
->info
));
23040 /* Output macinfo section(s). */
23043 output_macinfo (void)
23046 unsigned long length
= vec_safe_length (macinfo_table
);
23047 macinfo_entry
*ref
;
23048 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
23049 macinfo_hash_type
*macinfo_htab
= NULL
;
23054 /* output_macinfo* uses these interchangeably. */
23055 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
23056 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
23057 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
23058 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
23060 /* For .debug_macro emit the section header. */
23063 dw2_asm_output_data (2, 4, "DWARF macro version number");
23064 if (DWARF_OFFSET_SIZE
== 8)
23065 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
23067 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
23068 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
23069 (!dwarf_split_debug_info
? debug_line_section_label
23070 : debug_skeleton_line_section_label
),
23071 debug_line_section
, NULL
);
23074 /* In the first loop, it emits the primary .debug_macinfo section
23075 and after each emitted op the macinfo_entry is cleared.
23076 If a longer range of define/undef ops can be optimized using
23077 DW_MACRO_GNU_transparent_include, the
23078 DW_MACRO_GNU_transparent_include op is emitted and kept in
23079 the vector before the first define/undef in the range and the
23080 whole range of define/undef ops is not emitted and kept. */
23081 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
23085 case DW_MACINFO_start_file
:
23086 vec_safe_push (files
, *ref
);
23088 case DW_MACINFO_end_file
:
23089 if (!vec_safe_is_empty (files
))
23092 case DW_MACINFO_define
:
23093 case DW_MACINFO_undef
:
23095 && HAVE_COMDAT_GROUP
23096 && vec_safe_length (files
) != 1
23099 && (*macinfo_table
)[i
- 1].code
== 0)
23101 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
23110 /* A dummy entry may be inserted at the beginning to be able
23111 to optimize the whole block of predefined macros. */
23117 output_macinfo_op (ref
);
23125 delete macinfo_htab
;
23126 macinfo_htab
= NULL
;
23128 /* If any DW_MACRO_GNU_transparent_include were used, on those
23129 DW_MACRO_GNU_transparent_include entries terminate the
23130 current chain and switch to a new comdat .debug_macinfo
23131 section and emit the define/undef entries within it. */
23132 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
23137 case DW_MACRO_GNU_transparent_include
:
23139 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
23140 tree comdat_key
= get_identifier (ref
->info
);
23141 /* Terminate the previous .debug_macinfo section. */
23142 dw2_asm_output_data (1, 0, "End compilation unit");
23143 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
23145 | SECTION_LINKONCE
,
23147 ASM_GENERATE_INTERNAL_LABEL (label
,
23148 DEBUG_MACRO_SECTION_LABEL
,
23150 ASM_OUTPUT_LABEL (asm_out_file
, label
);
23153 dw2_asm_output_data (2, 4, "DWARF macro version number");
23154 if (DWARF_OFFSET_SIZE
== 8)
23155 dw2_asm_output_data (1, 1, "Flags: 64-bit");
23157 dw2_asm_output_data (1, 0, "Flags: 32-bit");
23160 case DW_MACINFO_define
:
23161 case DW_MACINFO_undef
:
23162 output_macinfo_op (ref
);
23167 gcc_unreachable ();
23171 /* Set up for Dwarf output at the start of compilation. */
23174 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
23176 /* This option is currently broken, see (PR53118 and PR46102). */
23177 if (flag_eliminate_dwarf2_dups
23178 && strstr (lang_hooks
.name
, "C++"))
23180 warning (0, "-feliminate-dwarf2-dups is broken for C++, ignoring");
23181 flag_eliminate_dwarf2_dups
= 0;
23184 /* Allocate the file_table. */
23185 file_table
= hash_table
<dwarf_file_hasher
>::create_ggc (50);
23187 /* Allocate the decl_die_table. */
23188 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (10);
23190 /* Allocate the decl_loc_table. */
23191 decl_loc_table
= hash_table
<decl_loc_hasher
>::create_ggc (10);
23193 /* Allocate the cached_dw_loc_list_table. */
23194 cached_dw_loc_list_table
= hash_table
<dw_loc_list_hasher
>::create_ggc (10);
23196 /* Allocate the initial hunk of the decl_scope_table. */
23197 vec_alloc (decl_scope_table
, 256);
23199 /* Allocate the initial hunk of the abbrev_die_table. */
23200 abbrev_die_table
= ggc_cleared_vec_alloc
<dw_die_ref
>
23201 (ABBREV_DIE_TABLE_INCREMENT
);
23202 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
23203 /* Zero-th entry is allocated, but unused. */
23204 abbrev_die_table_in_use
= 1;
23206 /* Allocate the pubtypes and pubnames vectors. */
23207 vec_alloc (pubname_table
, 32);
23208 vec_alloc (pubtype_table
, 32);
23210 vec_alloc (incomplete_types
, 64);
23212 vec_alloc (used_rtx_array
, 32);
23214 if (!dwarf_split_debug_info
)
23216 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
23217 SECTION_DEBUG
, NULL
);
23218 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
23219 SECTION_DEBUG
, NULL
);
23220 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
23221 SECTION_DEBUG
, NULL
);
23225 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
23226 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
23227 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
23228 SECTION_DEBUG
| SECTION_EXCLUDE
,
23230 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
23231 SECTION_DEBUG
, NULL
);
23232 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
23233 SECTION_DEBUG
, NULL
);
23234 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
23235 SECTION_DEBUG
, NULL
);
23236 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
23237 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
23239 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
23240 the main .o, but the skeleton_line goes into the split off dwo. */
23241 debug_skeleton_line_section
23242 = get_section (DEBUG_DWO_LINE_SECTION
,
23243 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
23244 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
23245 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
23246 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
23247 SECTION_DEBUG
| SECTION_EXCLUDE
,
23249 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
23250 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
23251 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
23252 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
23253 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
23254 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
23256 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
23257 SECTION_DEBUG
, NULL
);
23258 debug_macinfo_section
= get_section (dwarf_strict
23259 ? DEBUG_MACINFO_SECTION
23260 : DEBUG_MACRO_SECTION
,
23261 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
23262 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
23263 SECTION_DEBUG
, NULL
);
23264 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
23265 SECTION_DEBUG
, NULL
);
23266 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
23267 SECTION_DEBUG
, NULL
);
23268 debug_str_section
= get_section (DEBUG_STR_SECTION
,
23269 DEBUG_STR_SECTION_FLAGS
, NULL
);
23270 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
23271 SECTION_DEBUG
, NULL
);
23272 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
23273 SECTION_DEBUG
, NULL
);
23275 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
23276 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
23277 DEBUG_ABBREV_SECTION_LABEL
, 0);
23278 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
23279 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
23280 COLD_TEXT_SECTION_LABEL
, 0);
23281 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
23283 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
23284 DEBUG_INFO_SECTION_LABEL
, 0);
23285 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
23286 DEBUG_LINE_SECTION_LABEL
, 0);
23287 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
23288 DEBUG_RANGES_SECTION_LABEL
, 0);
23289 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
23290 DEBUG_ADDR_SECTION_LABEL
, 0);
23291 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
23293 ? DEBUG_MACINFO_SECTION_LABEL
23294 : DEBUG_MACRO_SECTION_LABEL
, 0);
23295 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
23297 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
23298 vec_alloc (macinfo_table
, 64);
23300 switch_to_section (text_section
);
23301 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
23303 /* Make sure the line number table for .text always exists. */
23304 text_section_line_info
= new_line_info_table ();
23305 text_section_line_info
->end_label
= text_end_label
;
23307 /* If front-ends already registered a main translation unit but we were not
23308 ready to perform the association, do this now. */
23309 if (main_translation_unit
!= NULL_TREE
)
23310 equate_decl_number_to_die (main_translation_unit
, comp_unit_die ());
23313 /* Called before compile () starts outputtting functions, variables
23314 and toplevel asms into assembly. */
23317 dwarf2out_assembly_start (void)
23319 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
23320 && dwarf2out_do_cfi_asm ()
23321 && (!(flag_unwind_tables
|| flag_exceptions
)
23322 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
23323 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
23326 /* A helper function for dwarf2out_finish called through
23327 htab_traverse. Assign a string its index. All strings must be
23328 collected into the table by the time index_string is called,
23329 because the indexing code relies on htab_traverse to traverse nodes
23330 in the same order for each run. */
23333 index_string (indirect_string_node
**h
, unsigned int *index
)
23335 indirect_string_node
*node
= *h
;
23337 find_string_form (node
);
23338 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
23340 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
23341 node
->index
= *index
;
23347 /* A helper function for output_indirect_strings called through
23348 htab_traverse. Output the offset to a string and update the
23352 output_index_string_offset (indirect_string_node
**h
, unsigned int *offset
)
23354 indirect_string_node
*node
= *h
;
23356 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
23358 /* Assert that this node has been assigned an index. */
23359 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
23360 && node
->index
!= NOT_INDEXED
);
23361 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
23362 "indexed string 0x%x: %s", node
->index
, node
->str
);
23363 *offset
+= strlen (node
->str
) + 1;
23368 /* A helper function for dwarf2out_finish called through
23369 htab_traverse. Output the indexed string. */
23372 output_index_string (indirect_string_node
**h
, unsigned int *cur_idx
)
23374 struct indirect_string_node
*node
= *h
;
23376 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
23378 /* Assert that the strings are output in the same order as their
23379 indexes were assigned. */
23380 gcc_assert (*cur_idx
== node
->index
);
23381 assemble_string (node
->str
, strlen (node
->str
) + 1);
23387 /* A helper function for dwarf2out_finish called through
23388 htab_traverse. Emit one queued .debug_str string. */
23391 output_indirect_string (indirect_string_node
**h
, void *)
23393 struct indirect_string_node
*node
= *h
;
23395 node
->form
= find_string_form (node
);
23396 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
23398 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
23399 assemble_string (node
->str
, strlen (node
->str
) + 1);
23405 /* Output the indexed string table. */
23408 output_indirect_strings (void)
23410 switch_to_section (debug_str_section
);
23411 if (!dwarf_split_debug_info
)
23412 debug_str_hash
->traverse
<void *, output_indirect_string
> (NULL
);
23415 unsigned int offset
= 0;
23416 unsigned int cur_idx
= 0;
23418 skeleton_debug_str_hash
->traverse
<void *, output_indirect_string
> (NULL
);
23420 switch_to_section (debug_str_offsets_section
);
23421 debug_str_hash
->traverse_noresize
23422 <unsigned int *, output_index_string_offset
> (&offset
);
23423 switch_to_section (debug_str_dwo_section
);
23424 debug_str_hash
->traverse_noresize
<unsigned int *, output_index_string
>
23429 /* Callback for htab_traverse to assign an index to an entry in the
23430 table, and to write that entry to the .debug_addr section. */
23433 output_addr_table_entry (addr_table_entry
**slot
, unsigned int *cur_index
)
23435 addr_table_entry
*entry
= *slot
;
23437 if (entry
->refcount
== 0)
23439 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
23440 || entry
->index
== NOT_INDEXED
);
23444 gcc_assert (entry
->index
== *cur_index
);
23447 switch (entry
->kind
)
23450 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
23451 "0x%x", entry
->index
);
23453 case ate_kind_rtx_dtprel
:
23454 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
23455 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
23458 fputc ('\n', asm_out_file
);
23460 case ate_kind_label
:
23461 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
23462 "0x%x", entry
->index
);
23465 gcc_unreachable ();
23470 /* Produce the .debug_addr section. */
23473 output_addr_table (void)
23475 unsigned int index
= 0;
23476 if (addr_index_table
== NULL
|| addr_index_table
->size () == 0)
23479 switch_to_section (debug_addr_section
);
23481 ->traverse_noresize
<unsigned int *, output_addr_table_entry
> (&index
);
23484 #if ENABLE_ASSERT_CHECKING
23485 /* Verify that all marks are clear. */
23488 verify_marks_clear (dw_die_ref die
)
23492 gcc_assert (! die
->die_mark
);
23493 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
23495 #endif /* ENABLE_ASSERT_CHECKING */
23497 /* Clear the marks for a die and its children.
23498 Be cool if the mark isn't set. */
23501 prune_unmark_dies (dw_die_ref die
)
23507 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
23510 /* Given DIE that we're marking as used, find any other dies
23511 it references as attributes and mark them as used. */
23514 prune_unused_types_walk_attribs (dw_die_ref die
)
23519 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23521 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
23523 /* A reference to another DIE.
23524 Make sure that it will get emitted.
23525 If it was broken out into a comdat group, don't follow it. */
23526 if (! AT_ref (a
)->comdat_type_p
23527 || a
->dw_attr
== DW_AT_specification
)
23528 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
23530 /* Set the string's refcount to 0 so that prune_unused_types_mark
23531 accounts properly for it. */
23532 if (AT_class (a
) == dw_val_class_str
)
23533 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
23537 /* Mark the generic parameters and arguments children DIEs of DIE. */
23540 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
23544 if (die
== NULL
|| die
->die_child
== NULL
)
23546 c
= die
->die_child
;
23549 if (is_template_parameter (c
))
23550 prune_unused_types_mark (c
, 1);
23552 } while (c
&& c
!= die
->die_child
);
23555 /* Mark DIE as being used. If DOKIDS is true, then walk down
23556 to DIE's children. */
23559 prune_unused_types_mark (dw_die_ref die
, int dokids
)
23563 if (die
->die_mark
== 0)
23565 /* We haven't done this node yet. Mark it as used. */
23567 /* If this is the DIE of a generic type instantiation,
23568 mark the children DIEs that describe its generic parms and
23570 prune_unused_types_mark_generic_parms_dies (die
);
23572 /* We also have to mark its parents as used.
23573 (But we don't want to mark our parent's kids due to this,
23574 unless it is a class.) */
23575 if (die
->die_parent
)
23576 prune_unused_types_mark (die
->die_parent
,
23577 class_scope_p (die
->die_parent
));
23579 /* Mark any referenced nodes. */
23580 prune_unused_types_walk_attribs (die
);
23582 /* If this node is a specification,
23583 also mark the definition, if it exists. */
23584 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
23585 prune_unused_types_mark (die
->die_definition
, 1);
23588 if (dokids
&& die
->die_mark
!= 2)
23590 /* We need to walk the children, but haven't done so yet.
23591 Remember that we've walked the kids. */
23594 /* If this is an array type, we need to make sure our
23595 kids get marked, even if they're types. If we're
23596 breaking out types into comdat sections, do this
23597 for all type definitions. */
23598 if (die
->die_tag
== DW_TAG_array_type
23599 || (use_debug_types
23600 && is_type_die (die
) && ! is_declaration_die (die
)))
23601 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
23603 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
23607 /* For local classes, look if any static member functions were emitted
23608 and if so, mark them. */
23611 prune_unused_types_walk_local_classes (dw_die_ref die
)
23615 if (die
->die_mark
== 2)
23618 switch (die
->die_tag
)
23620 case DW_TAG_structure_type
:
23621 case DW_TAG_union_type
:
23622 case DW_TAG_class_type
:
23625 case DW_TAG_subprogram
:
23626 if (!get_AT_flag (die
, DW_AT_declaration
)
23627 || die
->die_definition
!= NULL
)
23628 prune_unused_types_mark (die
, 1);
23635 /* Mark children. */
23636 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
23639 /* Walk the tree DIE and mark types that we actually use. */
23642 prune_unused_types_walk (dw_die_ref die
)
23646 /* Don't do anything if this node is already marked and
23647 children have been marked as well. */
23648 if (die
->die_mark
== 2)
23651 switch (die
->die_tag
)
23653 case DW_TAG_structure_type
:
23654 case DW_TAG_union_type
:
23655 case DW_TAG_class_type
:
23656 if (die
->die_perennial_p
)
23659 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
23660 if (c
->die_tag
== DW_TAG_subprogram
)
23663 /* Finding used static member functions inside of classes
23664 is needed just for local classes, because for other classes
23665 static member function DIEs with DW_AT_specification
23666 are emitted outside of the DW_TAG_*_type. If we ever change
23667 it, we'd need to call this even for non-local classes. */
23669 prune_unused_types_walk_local_classes (die
);
23671 /* It's a type node --- don't mark it. */
23674 case DW_TAG_const_type
:
23675 case DW_TAG_packed_type
:
23676 case DW_TAG_pointer_type
:
23677 case DW_TAG_reference_type
:
23678 case DW_TAG_rvalue_reference_type
:
23679 case DW_TAG_volatile_type
:
23680 case DW_TAG_typedef
:
23681 case DW_TAG_array_type
:
23682 case DW_TAG_interface_type
:
23683 case DW_TAG_friend
:
23684 case DW_TAG_variant_part
:
23685 case DW_TAG_enumeration_type
:
23686 case DW_TAG_subroutine_type
:
23687 case DW_TAG_string_type
:
23688 case DW_TAG_set_type
:
23689 case DW_TAG_subrange_type
:
23690 case DW_TAG_ptr_to_member_type
:
23691 case DW_TAG_file_type
:
23692 if (die
->die_perennial_p
)
23695 /* It's a type node --- don't mark it. */
23699 /* Mark everything else. */
23703 if (die
->die_mark
== 0)
23707 /* Now, mark any dies referenced from here. */
23708 prune_unused_types_walk_attribs (die
);
23713 /* Mark children. */
23714 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
23717 /* Increment the string counts on strings referred to from DIE's
23721 prune_unused_types_update_strings (dw_die_ref die
)
23726 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23727 if (AT_class (a
) == dw_val_class_str
)
23729 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
23731 /* Avoid unnecessarily putting strings that are used less than
23732 twice in the hash table. */
23734 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
23736 indirect_string_node
**slot
23737 = debug_str_hash
->find_slot_with_hash (s
->str
,
23738 htab_hash_string (s
->str
),
23740 gcc_assert (*slot
== NULL
);
23746 /* Remove from the tree DIE any dies that aren't marked. */
23749 prune_unused_types_prune (dw_die_ref die
)
23753 gcc_assert (die
->die_mark
);
23754 prune_unused_types_update_strings (die
);
23756 if (! die
->die_child
)
23759 c
= die
->die_child
;
23761 dw_die_ref prev
= c
;
23762 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
23763 if (c
== die
->die_child
)
23765 /* No marked children between 'prev' and the end of the list. */
23767 /* No marked children at all. */
23768 die
->die_child
= NULL
;
23771 prev
->die_sib
= c
->die_sib
;
23772 die
->die_child
= prev
;
23777 if (c
!= prev
->die_sib
)
23779 prune_unused_types_prune (c
);
23780 } while (c
!= die
->die_child
);
23783 /* Remove dies representing declarations that we never use. */
23786 prune_unused_types (void)
23789 limbo_die_node
*node
;
23790 comdat_type_node
*ctnode
;
23792 dw_die_ref base_type
;
23794 #if ENABLE_ASSERT_CHECKING
23795 /* All the marks should already be clear. */
23796 verify_marks_clear (comp_unit_die ());
23797 for (node
= limbo_die_list
; node
; node
= node
->next
)
23798 verify_marks_clear (node
->die
);
23799 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23800 verify_marks_clear (ctnode
->root_die
);
23801 #endif /* ENABLE_ASSERT_CHECKING */
23803 /* Mark types that are used in global variables. */
23804 premark_types_used_by_global_vars ();
23806 /* Set the mark on nodes that are actually used. */
23807 prune_unused_types_walk (comp_unit_die ());
23808 for (node
= limbo_die_list
; node
; node
= node
->next
)
23809 prune_unused_types_walk (node
->die
);
23810 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23812 prune_unused_types_walk (ctnode
->root_die
);
23813 prune_unused_types_mark (ctnode
->type_die
, 1);
23816 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
23817 are unusual in that they are pubnames that are the children of pubtypes.
23818 They should only be marked via their parent DW_TAG_enumeration_type die,
23819 not as roots in themselves. */
23820 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
23821 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
23822 prune_unused_types_mark (pub
->die
, 1);
23823 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
23824 prune_unused_types_mark (base_type
, 1);
23826 if (debug_str_hash
)
23827 debug_str_hash
->empty ();
23828 if (skeleton_debug_str_hash
)
23829 skeleton_debug_str_hash
->empty ();
23830 prune_unused_types_prune (comp_unit_die ());
23831 for (limbo_die_node
**pnode
= &limbo_die_list
; *pnode
; )
23834 if (!node
->die
->die_mark
)
23835 *pnode
= node
->next
;
23838 prune_unused_types_prune (node
->die
);
23839 pnode
= &node
->next
;
23842 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23843 prune_unused_types_prune (ctnode
->root_die
);
23845 /* Leave the marks clear. */
23846 prune_unmark_dies (comp_unit_die ());
23847 for (node
= limbo_die_list
; node
; node
= node
->next
)
23848 prune_unmark_dies (node
->die
);
23849 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23850 prune_unmark_dies (ctnode
->root_die
);
23853 /* Set the parameter to true if there are any relative pathnames in
23856 file_table_relative_p (dwarf_file_data
**slot
, bool *p
)
23858 struct dwarf_file_data
*d
= *slot
;
23859 if (!IS_ABSOLUTE_PATH (d
->filename
))
23867 /* Helpers to manipulate hash table of comdat type units. */
23869 struct comdat_type_hasher
: nofree_ptr_hash
<comdat_type_node
>
23871 static inline hashval_t
hash (const comdat_type_node
*);
23872 static inline bool equal (const comdat_type_node
*, const comdat_type_node
*);
23876 comdat_type_hasher::hash (const comdat_type_node
*type_node
)
23879 memcpy (&h
, type_node
->signature
, sizeof (h
));
23884 comdat_type_hasher::equal (const comdat_type_node
*type_node_1
,
23885 const comdat_type_node
*type_node_2
)
23887 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
23888 DWARF_TYPE_SIGNATURE_SIZE
));
23891 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
23892 to the location it would have been added, should we know its
23893 DECL_ASSEMBLER_NAME when we added other attributes. This will
23894 probably improve compactness of debug info, removing equivalent
23895 abbrevs, and hide any differences caused by deferring the
23896 computation of the assembler name, triggered by e.g. PCH. */
23899 move_linkage_attr (dw_die_ref die
)
23901 unsigned ix
= vec_safe_length (die
->die_attr
);
23902 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
23904 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
23905 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
23909 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
23911 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
23915 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
23917 die
->die_attr
->pop ();
23918 die
->die_attr
->quick_insert (ix
, linkage
);
23922 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
23923 referenced from typed stack ops and count how often they are used. */
23926 mark_base_types (dw_loc_descr_ref loc
)
23928 dw_die_ref base_type
= NULL
;
23930 for (; loc
; loc
= loc
->dw_loc_next
)
23932 switch (loc
->dw_loc_opc
)
23934 case DW_OP_GNU_regval_type
:
23935 case DW_OP_GNU_deref_type
:
23936 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
23938 case DW_OP_GNU_convert
:
23939 case DW_OP_GNU_reinterpret
:
23940 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
23943 case DW_OP_GNU_const_type
:
23944 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23946 case DW_OP_GNU_entry_value
:
23947 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
23952 gcc_assert (base_type
->die_parent
== comp_unit_die ());
23953 if (base_type
->die_mark
)
23954 base_type
->die_mark
++;
23957 base_types
.safe_push (base_type
);
23958 base_type
->die_mark
= 1;
23963 /* Comparison function for sorting marked base types. */
23966 base_type_cmp (const void *x
, const void *y
)
23968 dw_die_ref dx
= *(const dw_die_ref
*) x
;
23969 dw_die_ref dy
= *(const dw_die_ref
*) y
;
23970 unsigned int byte_size1
, byte_size2
;
23971 unsigned int encoding1
, encoding2
;
23972 if (dx
->die_mark
> dy
->die_mark
)
23974 if (dx
->die_mark
< dy
->die_mark
)
23976 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
23977 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
23978 if (byte_size1
< byte_size2
)
23980 if (byte_size1
> byte_size2
)
23982 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
23983 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
23984 if (encoding1
< encoding2
)
23986 if (encoding1
> encoding2
)
23991 /* Move base types marked by mark_base_types as early as possible
23992 in the CU, sorted by decreasing usage count both to make the
23993 uleb128 references as small as possible and to make sure they
23994 will have die_offset already computed by calc_die_sizes when
23995 sizes of typed stack loc ops is computed. */
23998 move_marked_base_types (void)
24001 dw_die_ref base_type
, die
, c
;
24003 if (base_types
.is_empty ())
24006 /* Sort by decreasing usage count, they will be added again in that
24008 base_types
.qsort (base_type_cmp
);
24009 die
= comp_unit_die ();
24010 c
= die
->die_child
;
24013 dw_die_ref prev
= c
;
24015 while (c
->die_mark
)
24017 remove_child_with_prev (c
, prev
);
24018 /* As base types got marked, there must be at least
24019 one node other than DW_TAG_base_type. */
24020 gcc_assert (c
!= c
->die_sib
);
24024 while (c
!= die
->die_child
);
24025 gcc_assert (die
->die_child
);
24026 c
= die
->die_child
;
24027 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
24029 base_type
->die_mark
= 0;
24030 base_type
->die_sib
= c
->die_sib
;
24031 c
->die_sib
= base_type
;
24036 /* Helper function for resolve_addr, attempt to resolve
24037 one CONST_STRING, return true if successful. Similarly verify that
24038 SYMBOL_REFs refer to variables emitted in the current CU. */
24041 resolve_one_addr (rtx
*addr
)
24045 if (GET_CODE (rtl
) == CONST_STRING
)
24047 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
24048 tree t
= build_string (len
, XSTR (rtl
, 0));
24049 tree tlen
= size_int (len
- 1);
24051 = build_array_type (char_type_node
, build_index_type (tlen
));
24052 rtl
= lookup_constant_def (t
);
24053 if (!rtl
|| !MEM_P (rtl
))
24055 rtl
= XEXP (rtl
, 0);
24056 if (GET_CODE (rtl
) == SYMBOL_REF
24057 && SYMBOL_REF_DECL (rtl
)
24058 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
24060 vec_safe_push (used_rtx_array
, rtl
);
24065 if (GET_CODE (rtl
) == SYMBOL_REF
24066 && SYMBOL_REF_DECL (rtl
))
24068 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
24070 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
24073 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
24077 if (GET_CODE (rtl
) == CONST
)
24079 subrtx_ptr_iterator::array_type array
;
24080 FOR_EACH_SUBRTX_PTR (iter
, array
, &XEXP (rtl
, 0), ALL
)
24081 if (!resolve_one_addr (*iter
))
24088 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
24089 if possible, and create DW_TAG_dwarf_procedure that can be referenced
24090 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
24093 string_cst_pool_decl (tree t
)
24095 rtx rtl
= output_constant_def (t
, 1);
24096 unsigned char *array
;
24097 dw_loc_descr_ref l
;
24102 if (!rtl
|| !MEM_P (rtl
))
24104 rtl
= XEXP (rtl
, 0);
24105 if (GET_CODE (rtl
) != SYMBOL_REF
24106 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
24109 decl
= SYMBOL_REF_DECL (rtl
);
24110 if (!lookup_decl_die (decl
))
24112 len
= TREE_STRING_LENGTH (t
);
24113 vec_safe_push (used_rtx_array
, rtl
);
24114 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
24115 array
= ggc_vec_alloc
<unsigned char> (len
);
24116 memcpy (array
, TREE_STRING_POINTER (t
), len
);
24117 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
24118 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
24119 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
24120 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
24121 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
24122 add_AT_loc (ref
, DW_AT_location
, l
);
24123 equate_decl_number_to_die (decl
, ref
);
24128 /* Helper function of resolve_addr_in_expr. LOC is
24129 a DW_OP_addr followed by DW_OP_stack_value, either at the start
24130 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
24131 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
24132 with DW_OP_GNU_implicit_pointer if possible
24133 and return true, if unsuccessful, return false. */
24136 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
24138 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
24139 HOST_WIDE_INT offset
= 0;
24140 dw_die_ref ref
= NULL
;
24143 if (GET_CODE (rtl
) == CONST
24144 && GET_CODE (XEXP (rtl
, 0)) == PLUS
24145 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
24147 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
24148 rtl
= XEXP (XEXP (rtl
, 0), 0);
24150 if (GET_CODE (rtl
) == CONST_STRING
)
24152 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
24153 tree t
= build_string (len
, XSTR (rtl
, 0));
24154 tree tlen
= size_int (len
- 1);
24157 = build_array_type (char_type_node
, build_index_type (tlen
));
24158 rtl
= string_cst_pool_decl (t
);
24162 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
24164 decl
= SYMBOL_REF_DECL (rtl
);
24165 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
24167 ref
= lookup_decl_die (decl
);
24168 if (ref
&& (get_AT (ref
, DW_AT_location
)
24169 || get_AT (ref
, DW_AT_const_value
)))
24171 loc
->dw_loc_opc
= DW_OP_GNU_implicit_pointer
;
24172 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
24173 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
24174 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
24175 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
24176 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
24177 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
24185 /* Helper function for resolve_addr, handle one location
24186 expression, return false if at least one CONST_STRING or SYMBOL_REF in
24187 the location list couldn't be resolved. */
24190 resolve_addr_in_expr (dw_loc_descr_ref loc
)
24192 dw_loc_descr_ref keep
= NULL
;
24193 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
24194 switch (loc
->dw_loc_opc
)
24197 if (!resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
24200 || prev
->dw_loc_opc
== DW_OP_piece
24201 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
24202 && loc
->dw_loc_next
24203 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
24205 && optimize_one_addr_into_implicit_ptr (loc
))
24210 case DW_OP_GNU_addr_index
:
24211 case DW_OP_GNU_const_index
:
24212 if (loc
->dw_loc_opc
== DW_OP_GNU_addr_index
24213 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
24215 rtx rtl
= loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
;
24216 if (!resolve_one_addr (&rtl
))
24218 remove_addr_table_entry (loc
->dw_loc_oprnd1
.val_entry
);
24219 loc
->dw_loc_oprnd1
.val_entry
=
24220 add_addr_table_entry (rtl
, ate_kind_rtx
);
24223 case DW_OP_const4u
:
24224 case DW_OP_const8u
:
24226 && !resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
24229 case DW_OP_plus_uconst
:
24230 if (size_of_loc_descr (loc
)
24231 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
24233 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
24235 dw_loc_descr_ref repl
24236 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
24237 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
24238 add_loc_descr (&repl
, loc
->dw_loc_next
);
24242 case DW_OP_implicit_value
:
24243 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
24244 && !resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
))
24247 case DW_OP_GNU_implicit_pointer
:
24248 case DW_OP_GNU_parameter_ref
:
24249 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
24252 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
24255 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
24256 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
24257 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
24260 case DW_OP_GNU_const_type
:
24261 case DW_OP_GNU_regval_type
:
24262 case DW_OP_GNU_deref_type
:
24263 case DW_OP_GNU_convert
:
24264 case DW_OP_GNU_reinterpret
:
24265 while (loc
->dw_loc_next
24266 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
24268 dw_die_ref base1
, base2
;
24269 unsigned enc1
, enc2
, size1
, size2
;
24270 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
24271 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
24272 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
24273 else if (loc
->dw_loc_oprnd1
.val_class
24274 == dw_val_class_unsigned_const
)
24277 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
24278 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
24279 == dw_val_class_unsigned_const
)
24281 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
24282 gcc_assert (base1
->die_tag
== DW_TAG_base_type
24283 && base2
->die_tag
== DW_TAG_base_type
);
24284 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
24285 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
24286 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
24287 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
24289 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
24290 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
24294 /* Optimize away next DW_OP_GNU_convert after
24295 adjusting LOC's base type die reference. */
24296 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
24297 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
24298 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
24300 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
24301 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
24304 /* Don't change integer DW_OP_GNU_convert after e.g. floating
24305 point typed stack entry. */
24306 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
24307 keep
= loc
->dw_loc_next
;
24317 /* Helper function of resolve_addr. DIE had DW_AT_location of
24318 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
24319 and DW_OP_addr couldn't be resolved. resolve_addr has already
24320 removed the DW_AT_location attribute. This function attempts to
24321 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
24322 to it or DW_AT_const_value attribute, if possible. */
24325 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
24327 if (TREE_CODE (decl
) != VAR_DECL
24328 || lookup_decl_die (decl
) != die
24329 || DECL_EXTERNAL (decl
)
24330 || !TREE_STATIC (decl
)
24331 || DECL_INITIAL (decl
) == NULL_TREE
24332 || DECL_P (DECL_INITIAL (decl
))
24333 || get_AT (die
, DW_AT_const_value
))
24336 tree init
= DECL_INITIAL (decl
);
24337 HOST_WIDE_INT offset
= 0;
24338 /* For variables that have been optimized away and thus
24339 don't have a memory location, see if we can emit
24340 DW_AT_const_value instead. */
24341 if (tree_add_const_value_attribute (die
, init
))
24345 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
24346 and ADDR_EXPR refers to a decl that has DW_AT_location or
24347 DW_AT_const_value (but isn't addressable, otherwise
24348 resolving the original DW_OP_addr wouldn't fail), see if
24349 we can add DW_OP_GNU_implicit_pointer. */
24351 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
24352 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
24354 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
24355 init
= TREE_OPERAND (init
, 0);
24358 if (TREE_CODE (init
) != ADDR_EXPR
)
24360 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
24361 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
24362 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
24363 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
24364 && TREE_OPERAND (init
, 0) != decl
))
24367 dw_loc_descr_ref l
;
24369 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
24371 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
24374 decl
= SYMBOL_REF_DECL (rtl
);
24377 decl
= TREE_OPERAND (init
, 0);
24378 ref
= lookup_decl_die (decl
);
24380 || (!get_AT (ref
, DW_AT_location
)
24381 && !get_AT (ref
, DW_AT_const_value
)))
24383 l
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
24384 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
24385 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
24386 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
24387 add_AT_loc (die
, DW_AT_location
, l
);
24391 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
24392 an address in .rodata section if the string literal is emitted there,
24393 or remove the containing location list or replace DW_AT_const_value
24394 with DW_AT_location and empty location expression, if it isn't found
24395 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
24396 to something that has been emitted in the current CU. */
24399 resolve_addr (dw_die_ref die
)
24403 dw_loc_list_ref
*curr
, *start
, loc
;
24406 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
24407 switch (AT_class (a
))
24409 case dw_val_class_loc_list
:
24410 start
= curr
= AT_loc_list_ptr (a
);
24413 /* The same list can be referenced more than once. See if we have
24414 already recorded the result from a previous pass. */
24416 *curr
= loc
->dw_loc_next
;
24417 else if (!loc
->resolved_addr
)
24419 /* As things stand, we do not expect or allow one die to
24420 reference a suffix of another die's location list chain.
24421 References must be identical or completely separate.
24422 There is therefore no need to cache the result of this
24423 pass on any list other than the first; doing so
24424 would lead to unnecessary writes. */
24427 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
24428 if (!resolve_addr_in_expr ((*curr
)->expr
))
24430 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
24431 dw_loc_descr_ref l
= (*curr
)->expr
;
24433 if (next
&& (*curr
)->ll_symbol
)
24435 gcc_assert (!next
->ll_symbol
);
24436 next
->ll_symbol
= (*curr
)->ll_symbol
;
24438 if (dwarf_split_debug_info
)
24439 remove_loc_list_addr_table_entries (l
);
24444 mark_base_types ((*curr
)->expr
);
24445 curr
= &(*curr
)->dw_loc_next
;
24449 loc
->resolved_addr
= 1;
24453 loc
->dw_loc_next
= *start
;
24458 remove_AT (die
, a
->dw_attr
);
24462 case dw_val_class_loc
:
24464 dw_loc_descr_ref l
= AT_loc (a
);
24465 /* For -gdwarf-2 don't attempt to optimize
24466 DW_AT_data_member_location containing
24467 DW_OP_plus_uconst - older consumers might
24468 rely on it being that op instead of a more complex,
24469 but shorter, location description. */
24470 if ((dwarf_version
> 2
24471 || a
->dw_attr
!= DW_AT_data_member_location
24473 || l
->dw_loc_opc
!= DW_OP_plus_uconst
24474 || l
->dw_loc_next
!= NULL
)
24475 && !resolve_addr_in_expr (l
))
24477 if (dwarf_split_debug_info
)
24478 remove_loc_list_addr_table_entries (l
);
24480 && l
->dw_loc_next
== NULL
24481 && l
->dw_loc_opc
== DW_OP_addr
24482 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
24483 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
24484 && a
->dw_attr
== DW_AT_location
)
24486 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
24487 remove_AT (die
, a
->dw_attr
);
24489 optimize_location_into_implicit_ptr (die
, decl
);
24492 remove_AT (die
, a
->dw_attr
);
24496 mark_base_types (l
);
24499 case dw_val_class_addr
:
24500 if (a
->dw_attr
== DW_AT_const_value
24501 && !resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
))
24503 if (AT_index (a
) != NOT_INDEXED
)
24504 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
24505 remove_AT (die
, a
->dw_attr
);
24508 if (die
->die_tag
== DW_TAG_GNU_call_site
24509 && a
->dw_attr
== DW_AT_abstract_origin
)
24511 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
24512 dw_die_ref tdie
= lookup_decl_die (tdecl
);
24515 && DECL_EXTERNAL (tdecl
)
24516 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
24517 && (cdie
= lookup_context_die (DECL_CONTEXT (tdecl
))))
24519 /* Creating a full DIE for tdecl is overly expensive and
24520 at this point even wrong when in the LTO phase
24521 as it can end up generating new type DIEs we didn't
24522 output and thus optimize_external_refs will crash. */
24523 tdie
= new_die (DW_TAG_subprogram
, cdie
, NULL_TREE
);
24524 add_AT_flag (tdie
, DW_AT_external
, 1);
24525 add_AT_flag (tdie
, DW_AT_declaration
, 1);
24526 add_linkage_attr (tdie
, tdecl
);
24527 add_name_and_src_coords_attributes (tdie
, tdecl
);
24528 equate_decl_number_to_die (tdecl
, tdie
);
24532 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
24533 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
24534 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
24538 if (AT_index (a
) != NOT_INDEXED
)
24539 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
24540 remove_AT (die
, a
->dw_attr
);
24549 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
24552 /* Helper routines for optimize_location_lists.
24553 This pass tries to share identical local lists in .debug_loc
24556 /* Iteratively hash operands of LOC opcode into HSTATE. */
24559 hash_loc_operands (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
24561 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
24562 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
24564 switch (loc
->dw_loc_opc
)
24566 case DW_OP_const4u
:
24567 case DW_OP_const8u
:
24571 case DW_OP_const1u
:
24572 case DW_OP_const1s
:
24573 case DW_OP_const2u
:
24574 case DW_OP_const2s
:
24575 case DW_OP_const4s
:
24576 case DW_OP_const8s
:
24580 case DW_OP_plus_uconst
:
24616 case DW_OP_deref_size
:
24617 case DW_OP_xderef_size
:
24618 hstate
.add_object (val1
->v
.val_int
);
24625 gcc_assert (val1
->val_class
== dw_val_class_loc
);
24626 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
24627 hstate
.add_object (offset
);
24630 case DW_OP_implicit_value
:
24631 hstate
.add_object (val1
->v
.val_unsigned
);
24632 switch (val2
->val_class
)
24634 case dw_val_class_const
:
24635 hstate
.add_object (val2
->v
.val_int
);
24637 case dw_val_class_vec
:
24639 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
24640 unsigned int len
= val2
->v
.val_vec
.length
;
24642 hstate
.add_int (elt_size
);
24643 hstate
.add_int (len
);
24644 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
24647 case dw_val_class_const_double
:
24648 hstate
.add_object (val2
->v
.val_double
.low
);
24649 hstate
.add_object (val2
->v
.val_double
.high
);
24651 case dw_val_class_wide_int
:
24652 hstate
.add (val2
->v
.val_wide
->get_val (),
24653 get_full_len (*val2
->v
.val_wide
)
24654 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
24656 case dw_val_class_addr
:
24657 inchash::add_rtx (val2
->v
.val_addr
, hstate
);
24660 gcc_unreachable ();
24664 case DW_OP_bit_piece
:
24665 hstate
.add_object (val1
->v
.val_int
);
24666 hstate
.add_object (val2
->v
.val_int
);
24672 unsigned char dtprel
= 0xd1;
24673 hstate
.add_object (dtprel
);
24675 inchash::add_rtx (val1
->v
.val_addr
, hstate
);
24677 case DW_OP_GNU_addr_index
:
24678 case DW_OP_GNU_const_index
:
24682 unsigned char dtprel
= 0xd1;
24683 hstate
.add_object (dtprel
);
24685 inchash::add_rtx (val1
->val_entry
->addr
.rtl
, hstate
);
24688 case DW_OP_GNU_implicit_pointer
:
24689 hstate
.add_int (val2
->v
.val_int
);
24691 case DW_OP_GNU_entry_value
:
24692 hstate
.add_object (val1
->v
.val_loc
);
24694 case DW_OP_GNU_regval_type
:
24695 case DW_OP_GNU_deref_type
:
24697 unsigned int byte_size
24698 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
24699 unsigned int encoding
24700 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
24701 hstate
.add_object (val1
->v
.val_int
);
24702 hstate
.add_object (byte_size
);
24703 hstate
.add_object (encoding
);
24706 case DW_OP_GNU_convert
:
24707 case DW_OP_GNU_reinterpret
:
24708 if (val1
->val_class
== dw_val_class_unsigned_const
)
24710 hstate
.add_object (val1
->v
.val_unsigned
);
24714 case DW_OP_GNU_const_type
:
24716 unsigned int byte_size
24717 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
24718 unsigned int encoding
24719 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
24720 hstate
.add_object (byte_size
);
24721 hstate
.add_object (encoding
);
24722 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
24724 hstate
.add_object (val2
->val_class
);
24725 switch (val2
->val_class
)
24727 case dw_val_class_const
:
24728 hstate
.add_object (val2
->v
.val_int
);
24730 case dw_val_class_vec
:
24732 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
24733 unsigned int len
= val2
->v
.val_vec
.length
;
24735 hstate
.add_object (elt_size
);
24736 hstate
.add_object (len
);
24737 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
24740 case dw_val_class_const_double
:
24741 hstate
.add_object (val2
->v
.val_double
.low
);
24742 hstate
.add_object (val2
->v
.val_double
.high
);
24744 case dw_val_class_wide_int
:
24745 hstate
.add (val2
->v
.val_wide
->get_val (),
24746 get_full_len (*val2
->v
.val_wide
)
24747 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
24750 gcc_unreachable ();
24756 /* Other codes have no operands. */
24761 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
24764 hash_locs (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
24766 dw_loc_descr_ref l
;
24767 bool sizes_computed
= false;
24768 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
24769 size_of_locs (loc
);
24771 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
24773 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
24774 hstate
.add_object (opc
);
24775 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
24777 size_of_locs (loc
);
24778 sizes_computed
= true;
24780 hash_loc_operands (l
, hstate
);
24784 /* Compute hash of the whole location list LIST_HEAD. */
24787 hash_loc_list (dw_loc_list_ref list_head
)
24789 dw_loc_list_ref curr
= list_head
;
24790 inchash::hash hstate
;
24792 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
24794 hstate
.add (curr
->begin
, strlen (curr
->begin
) + 1);
24795 hstate
.add (curr
->end
, strlen (curr
->end
) + 1);
24797 hstate
.add (curr
->section
, strlen (curr
->section
) + 1);
24798 hash_locs (curr
->expr
, hstate
);
24800 list_head
->hash
= hstate
.end ();
24803 /* Return true if X and Y opcodes have the same operands. */
24806 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
24808 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
24809 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
24810 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
24811 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
24813 switch (x
->dw_loc_opc
)
24815 case DW_OP_const4u
:
24816 case DW_OP_const8u
:
24820 case DW_OP_const1u
:
24821 case DW_OP_const1s
:
24822 case DW_OP_const2u
:
24823 case DW_OP_const2s
:
24824 case DW_OP_const4s
:
24825 case DW_OP_const8s
:
24829 case DW_OP_plus_uconst
:
24865 case DW_OP_deref_size
:
24866 case DW_OP_xderef_size
:
24867 return valx1
->v
.val_int
== valy1
->v
.val_int
;
24870 /* If splitting debug info, the use of DW_OP_GNU_addr_index
24871 can cause irrelevant differences in dw_loc_addr. */
24872 gcc_assert (valx1
->val_class
== dw_val_class_loc
24873 && valy1
->val_class
== dw_val_class_loc
24874 && (dwarf_split_debug_info
24875 || x
->dw_loc_addr
== y
->dw_loc_addr
));
24876 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
24877 case DW_OP_implicit_value
:
24878 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
24879 || valx2
->val_class
!= valy2
->val_class
)
24881 switch (valx2
->val_class
)
24883 case dw_val_class_const
:
24884 return valx2
->v
.val_int
== valy2
->v
.val_int
;
24885 case dw_val_class_vec
:
24886 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
24887 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
24888 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
24889 valx2
->v
.val_vec
.elt_size
24890 * valx2
->v
.val_vec
.length
) == 0;
24891 case dw_val_class_const_double
:
24892 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
24893 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
24894 case dw_val_class_wide_int
:
24895 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
24896 case dw_val_class_addr
:
24897 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
24899 gcc_unreachable ();
24902 case DW_OP_bit_piece
:
24903 return valx1
->v
.val_int
== valy1
->v
.val_int
24904 && valx2
->v
.val_int
== valy2
->v
.val_int
;
24907 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
24908 case DW_OP_GNU_addr_index
:
24909 case DW_OP_GNU_const_index
:
24911 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
24912 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
24913 return rtx_equal_p (ax1
, ay1
);
24915 case DW_OP_GNU_implicit_pointer
:
24916 return valx1
->val_class
== dw_val_class_die_ref
24917 && valx1
->val_class
== valy1
->val_class
24918 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
24919 && valx2
->v
.val_int
== valy2
->v
.val_int
;
24920 case DW_OP_GNU_entry_value
:
24921 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
24922 case DW_OP_GNU_const_type
:
24923 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
24924 || valx2
->val_class
!= valy2
->val_class
)
24926 switch (valx2
->val_class
)
24928 case dw_val_class_const
:
24929 return valx2
->v
.val_int
== valy2
->v
.val_int
;
24930 case dw_val_class_vec
:
24931 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
24932 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
24933 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
24934 valx2
->v
.val_vec
.elt_size
24935 * valx2
->v
.val_vec
.length
) == 0;
24936 case dw_val_class_const_double
:
24937 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
24938 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
24939 case dw_val_class_wide_int
:
24940 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
24942 gcc_unreachable ();
24944 case DW_OP_GNU_regval_type
:
24945 case DW_OP_GNU_deref_type
:
24946 return valx1
->v
.val_int
== valy1
->v
.val_int
24947 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
24948 case DW_OP_GNU_convert
:
24949 case DW_OP_GNU_reinterpret
:
24950 if (valx1
->val_class
!= valy1
->val_class
)
24952 if (valx1
->val_class
== dw_val_class_unsigned_const
)
24953 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
24954 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
24955 case DW_OP_GNU_parameter_ref
:
24956 return valx1
->val_class
== dw_val_class_die_ref
24957 && valx1
->val_class
== valy1
->val_class
24958 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
24960 /* Other codes have no operands. */
24965 /* Return true if DWARF location expressions X and Y are the same. */
24968 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
24970 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
24971 if (x
->dw_loc_opc
!= y
->dw_loc_opc
24972 || x
->dtprel
!= y
->dtprel
24973 || !compare_loc_operands (x
, y
))
24975 return x
== NULL
&& y
== NULL
;
24978 /* Hashtable helpers. */
24980 struct loc_list_hasher
: nofree_ptr_hash
<dw_loc_list_struct
>
24982 static inline hashval_t
hash (const dw_loc_list_struct
*);
24983 static inline bool equal (const dw_loc_list_struct
*,
24984 const dw_loc_list_struct
*);
24987 /* Return precomputed hash of location list X. */
24990 loc_list_hasher::hash (const dw_loc_list_struct
*x
)
24995 /* Return true if location lists A and B are the same. */
24998 loc_list_hasher::equal (const dw_loc_list_struct
*a
,
24999 const dw_loc_list_struct
*b
)
25003 if (a
->hash
!= b
->hash
)
25005 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
25006 if (strcmp (a
->begin
, b
->begin
) != 0
25007 || strcmp (a
->end
, b
->end
) != 0
25008 || (a
->section
== NULL
) != (b
->section
== NULL
)
25009 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
25010 || !compare_locs (a
->expr
, b
->expr
))
25012 return a
== NULL
&& b
== NULL
;
25015 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
25018 /* Recursively optimize location lists referenced from DIE
25019 children and share them whenever possible. */
25022 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type
*htab
)
25027 dw_loc_list_struct
**slot
;
25029 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
25030 if (AT_class (a
) == dw_val_class_loc_list
)
25032 dw_loc_list_ref list
= AT_loc_list (a
);
25033 /* TODO: perform some optimizations here, before hashing
25034 it and storing into the hash table. */
25035 hash_loc_list (list
);
25036 slot
= htab
->find_slot_with_hash (list
, list
->hash
, INSERT
);
25040 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
25043 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
25047 /* Recursively assign each location list a unique index into the debug_addr
25051 index_location_lists (dw_die_ref die
)
25057 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
25058 if (AT_class (a
) == dw_val_class_loc_list
)
25060 dw_loc_list_ref list
= AT_loc_list (a
);
25061 dw_loc_list_ref curr
;
25062 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
25064 /* Don't index an entry that has already been indexed
25065 or won't be output. */
25066 if (curr
->begin_entry
!= NULL
25067 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
25071 = add_addr_table_entry (xstrdup (curr
->begin
),
25076 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
25079 /* Optimize location lists referenced from DIE
25080 children and share them whenever possible. */
25083 optimize_location_lists (dw_die_ref die
)
25085 loc_list_hash_type
htab (500);
25086 optimize_location_lists_1 (die
, &htab
);
25089 /* Output stuff that dwarf requires at the end of every file,
25090 and generate the DWARF-2 debugging info. */
25093 dwarf2out_finish (const char *filename
)
25095 comdat_type_node
*ctnode
;
25096 dw_die_ref main_comp_unit_die
;
25098 /* Flush out any latecomers to the limbo party. */
25099 dwarf2out_early_finish ();
25101 /* PCH might result in DW_AT_producer string being restored from the
25102 header compilation, so always fill it with empty string initially
25103 and overwrite only here. */
25104 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
25105 producer_string
= gen_producer_string ();
25106 producer
->dw_attr_val
.v
.val_str
->refcount
--;
25107 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
25109 gen_scheduled_generic_parms_dies ();
25110 gen_remaining_tmpl_value_param_die_attribute ();
25112 /* Add the name for the main input file now. We delayed this from
25113 dwarf2out_init to avoid complications with PCH.
25114 For LTO produced units use a fixed artificial name to avoid
25115 leaking tempfile names into the dwarf. */
25117 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
25119 add_name_attribute (comp_unit_die (), "<artificial>");
25120 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
25121 add_comp_dir_attribute (comp_unit_die ());
25122 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
25125 file_table
->traverse
<bool *, file_table_relative_p
> (&p
);
25127 add_comp_dir_attribute (comp_unit_die ());
25130 #if ENABLE_ASSERT_CHECKING
25132 dw_die_ref die
= comp_unit_die (), c
;
25133 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
25136 resolve_addr (comp_unit_die ());
25137 move_marked_base_types ();
25139 /* Walk through the list of incomplete types again, trying once more to
25140 emit full debugging info for them. */
25141 retry_incomplete_types ();
25143 if (flag_eliminate_unused_debug_types
)
25144 prune_unused_types ();
25146 /* Generate separate COMDAT sections for type DIEs. */
25147 if (use_debug_types
)
25149 break_out_comdat_types (comp_unit_die ());
25151 /* Each new type_unit DIE was added to the limbo die list when created.
25152 Since these have all been added to comdat_type_list, clear the
25154 limbo_die_list
= NULL
;
25156 /* For each new comdat type unit, copy declarations for incomplete
25157 types to make the new unit self-contained (i.e., no direct
25158 references to the main compile unit). */
25159 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
25160 copy_decls_for_unworthy_types (ctnode
->root_die
);
25161 copy_decls_for_unworthy_types (comp_unit_die ());
25163 /* In the process of copying declarations from one unit to another,
25164 we may have left some declarations behind that are no longer
25165 referenced. Prune them. */
25166 prune_unused_types ();
25169 /* Generate separate CUs for each of the include files we've seen.
25170 They will go into limbo_die_list. */
25171 if (flag_eliminate_dwarf2_dups
)
25172 break_out_includes (comp_unit_die ());
25174 /* Traverse the DIE's and add add sibling attributes to those DIE's
25175 that have children. */
25176 add_sibling_attributes (comp_unit_die ());
25177 limbo_die_node
*node
;
25178 for (node
= limbo_die_list
; node
; node
= node
->next
)
25179 add_sibling_attributes (node
->die
);
25180 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
25181 add_sibling_attributes (ctnode
->root_die
);
25183 /* When splitting DWARF info, we put some attributes in the
25184 skeleton compile_unit DIE that remains in the .o, while
25185 most attributes go in the DWO compile_unit_die. */
25186 if (dwarf_split_debug_info
)
25187 main_comp_unit_die
= gen_compile_unit_die (NULL
);
25189 main_comp_unit_die
= comp_unit_die ();
25191 /* Output a terminator label for the .text section. */
25192 switch_to_section (text_section
);
25193 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
25194 if (cold_text_section
)
25196 switch_to_section (cold_text_section
);
25197 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
25200 /* We can only use the low/high_pc attributes if all of the code was
25202 if (!have_multiple_function_sections
25203 || (dwarf_version
< 3 && dwarf_strict
))
25205 /* Don't add if the CU has no associated code. */
25206 if (text_section_used
)
25207 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
25208 text_end_label
, true);
25214 bool range_list_added
= false;
25216 if (text_section_used
)
25217 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
25218 text_end_label
, &range_list_added
, true);
25219 if (cold_text_section_used
)
25220 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
25221 cold_end_label
, &range_list_added
, true);
25223 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
25225 if (DECL_IGNORED_P (fde
->decl
))
25227 if (!fde
->in_std_section
)
25228 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
25229 fde
->dw_fde_end
, &range_list_added
,
25231 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
25232 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
25233 fde
->dw_fde_second_end
, &range_list_added
,
25237 if (range_list_added
)
25239 /* We need to give .debug_loc and .debug_ranges an appropriate
25240 "base address". Use zero so that these addresses become
25241 absolute. Historically, we've emitted the unexpected
25242 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
25243 Emit both to give time for other tools to adapt. */
25244 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
25245 if (! dwarf_strict
&& dwarf_version
< 4)
25246 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
25252 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
25253 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
25254 debug_line_section_label
);
25257 add_AT_macptr (comp_unit_die (),
25258 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
25259 macinfo_section_label
);
25261 if (dwarf_split_debug_info
)
25263 /* optimize_location_lists calculates the size of the lists,
25264 so index them first, and assign indices to the entries.
25265 Although optimize_location_lists will remove entries from
25266 the table, it only does so for duplicates, and therefore
25267 only reduces ref_counts to 1. */
25268 index_location_lists (comp_unit_die ());
25270 if (addr_index_table
!= NULL
)
25272 unsigned int index
= 0;
25274 ->traverse_noresize
<unsigned int *, index_addr_table_entry
>
25279 if (have_location_lists
)
25280 optimize_location_lists (comp_unit_die ());
25282 save_macinfo_strings ();
25284 if (dwarf_split_debug_info
)
25286 unsigned int index
= 0;
25288 /* Add attributes common to skeleton compile_units and
25289 type_units. Because these attributes include strings, it
25290 must be done before freezing the string table. Top-level
25291 skeleton die attrs are added when the skeleton type unit is
25292 created, so ensure it is created by this point. */
25293 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
25294 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
25297 /* Output all of the compilation units. We put the main one last so that
25298 the offsets are available to output_pubnames. */
25299 for (node
= limbo_die_list
; node
; node
= node
->next
)
25300 output_comp_unit (node
->die
, 0);
25302 hash_table
<comdat_type_hasher
> comdat_type_table (100);
25303 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
25305 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
25307 /* Don't output duplicate types. */
25308 if (*slot
!= HTAB_EMPTY_ENTRY
)
25311 /* Add a pointer to the line table for the main compilation unit
25312 so that the debugger can make sense of DW_AT_decl_file
25314 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
25315 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
25316 (!dwarf_split_debug_info
25317 ? debug_line_section_label
25318 : debug_skeleton_line_section_label
));
25320 output_comdat_type_unit (ctnode
);
25324 /* The AT_pubnames attribute needs to go in all skeleton dies, including
25325 both the main_cu and all skeleton TUs. Making this call unconditional
25326 would end up either adding a second copy of the AT_pubnames attribute, or
25327 requiring a special case in add_top_level_skeleton_die_attrs. */
25328 if (!dwarf_split_debug_info
)
25329 add_AT_pubnames (comp_unit_die ());
25331 if (dwarf_split_debug_info
)
25334 unsigned char checksum
[16];
25335 struct md5_ctx ctx
;
25337 /* Compute a checksum of the comp_unit to use as the dwo_id. */
25338 md5_init_ctx (&ctx
);
25340 die_checksum (comp_unit_die (), &ctx
, &mark
);
25341 unmark_all_dies (comp_unit_die ());
25342 md5_finish_ctx (&ctx
, checksum
);
25344 /* Use the first 8 bytes of the checksum as the dwo_id,
25345 and add it to both comp-unit DIEs. */
25346 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
25347 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
25349 /* Add the base offset of the ranges table to the skeleton
25351 if (ranges_table_in_use
)
25352 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
25353 ranges_section_label
);
25355 switch_to_section (debug_addr_section
);
25356 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
25357 output_addr_table ();
25360 /* Output the main compilation unit if non-empty or if .debug_macinfo
25361 or .debug_macro will be emitted. */
25362 output_comp_unit (comp_unit_die (), have_macinfo
);
25364 if (dwarf_split_debug_info
&& info_section_emitted
)
25365 output_skeleton_debug_sections (main_comp_unit_die
);
25367 /* Output the abbreviation table. */
25368 if (abbrev_die_table_in_use
!= 1)
25370 switch_to_section (debug_abbrev_section
);
25371 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
25372 output_abbrev_section ();
25375 /* Output location list section if necessary. */
25376 if (have_location_lists
)
25378 /* Output the location lists info. */
25379 switch_to_section (debug_loc_section
);
25380 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
25381 output_location_lists (comp_unit_die ());
25384 output_pubtables ();
25386 /* Output the address range information if a CU (.debug_info section)
25387 was emitted. We output an empty table even if we had no functions
25388 to put in it. This because the consumer has no way to tell the
25389 difference between an empty table that we omitted and failure to
25390 generate a table that would have contained data. */
25391 if (info_section_emitted
)
25393 unsigned long aranges_length
= size_of_aranges ();
25395 switch_to_section (debug_aranges_section
);
25396 output_aranges (aranges_length
);
25399 /* Output ranges section if necessary. */
25400 if (ranges_table_in_use
)
25402 switch_to_section (debug_ranges_section
);
25403 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
25407 /* Have to end the macro section. */
25410 switch_to_section (debug_macinfo_section
);
25411 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
25413 dw2_asm_output_data (1, 0, "End compilation unit");
25416 /* Output the source line correspondence table. We must do this
25417 even if there is no line information. Otherwise, on an empty
25418 translation unit, we will generate a present, but empty,
25419 .debug_info section. IRIX 6.5 `nm' will then complain when
25420 examining the file. This is done late so that any filenames
25421 used by the debug_info section are marked as 'used'. */
25422 switch_to_section (debug_line_section
);
25423 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
25424 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
25425 output_line_info (false);
25427 if (dwarf_split_debug_info
&& info_section_emitted
)
25429 switch_to_section (debug_skeleton_line_section
);
25430 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
25431 output_line_info (true);
25434 /* If we emitted any indirect strings, output the string table too. */
25435 if (debug_str_hash
|| skeleton_debug_str_hash
)
25436 output_indirect_strings ();
25439 /* Perform any cleanups needed after the early debug generation pass
25443 dwarf2out_early_finish (void)
25445 limbo_die_node
*node
, *next_node
;
25447 /* Add DW_AT_linkage_name for all deferred DIEs. */
25448 for (node
= deferred_asm_name
; node
; node
= node
->next
)
25450 tree decl
= node
->created_for
;
25451 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
25452 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
25453 ended up in in deferred_asm_name before we knew it was
25454 constant and never written to disk. */
25455 && DECL_ASSEMBLER_NAME (decl
))
25457 add_linkage_attr (node
->die
, decl
);
25458 move_linkage_attr (node
->die
);
25461 deferred_asm_name
= NULL
;
25463 /* Traverse the limbo die list, and add parent/child links. The only
25464 dies without parents that should be here are concrete instances of
25465 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
25466 For concrete instances, we can get the parent die from the abstract
25469 The point here is to flush out the limbo list so that it is empty
25470 and we don't need to stream it for LTO. */
25471 for (node
= limbo_die_list
; node
; node
= next_node
)
25473 dw_die_ref die
= node
->die
;
25474 next_node
= node
->next
;
25476 if (die
->die_parent
== NULL
)
25478 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
25480 if (origin
&& origin
->die_parent
)
25481 add_child_die (origin
->die_parent
, die
);
25482 else if (is_cu_die (die
))
25484 else if (seen_error ())
25485 /* It's OK to be confused by errors in the input. */
25486 add_child_die (comp_unit_die (), die
);
25489 /* In certain situations, the lexical block containing a
25490 nested function can be optimized away, which results
25491 in the nested function die being orphaned. Likewise
25492 with the return type of that nested function. Force
25493 this to be a child of the containing function.
25495 It may happen that even the containing function got fully
25496 inlined and optimized out. In that case we are lost and
25497 assign the empty child. This should not be big issue as
25498 the function is likely unreachable too. */
25499 gcc_assert (node
->created_for
);
25501 if (DECL_P (node
->created_for
))
25502 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
25503 else if (TYPE_P (node
->created_for
))
25504 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
25506 origin
= comp_unit_die ();
25508 add_child_die (origin
, die
);
25513 limbo_die_list
= NULL
;
25516 /* Reset all state within dwarf2out.c so that we can rerun the compiler
25517 within the same process. For use by toplev::finalize. */
25520 dwarf2out_c_finalize (void)
25522 last_var_location_insn
= NULL
;
25523 cached_next_real_insn
= NULL
;
25524 used_rtx_array
= NULL
;
25525 incomplete_types
= NULL
;
25526 decl_scope_table
= NULL
;
25527 debug_info_section
= NULL
;
25528 debug_skeleton_info_section
= NULL
;
25529 debug_abbrev_section
= NULL
;
25530 debug_skeleton_abbrev_section
= NULL
;
25531 debug_aranges_section
= NULL
;
25532 debug_addr_section
= NULL
;
25533 debug_macinfo_section
= NULL
;
25534 debug_line_section
= NULL
;
25535 debug_skeleton_line_section
= NULL
;
25536 debug_loc_section
= NULL
;
25537 debug_pubnames_section
= NULL
;
25538 debug_pubtypes_section
= NULL
;
25539 debug_str_section
= NULL
;
25540 debug_str_dwo_section
= NULL
;
25541 debug_str_offsets_section
= NULL
;
25542 debug_ranges_section
= NULL
;
25543 debug_frame_section
= NULL
;
25545 debug_str_hash
= NULL
;
25546 skeleton_debug_str_hash
= NULL
;
25547 dw2_string_counter
= 0;
25548 have_multiple_function_sections
= false;
25549 text_section_used
= false;
25550 cold_text_section_used
= false;
25551 cold_text_section
= NULL
;
25552 current_unit_personality
= NULL
;
25554 next_die_offset
= 0;
25555 single_comp_unit_die
= NULL
;
25556 comdat_type_list
= NULL
;
25557 limbo_die_list
= NULL
;
25559 decl_die_table
= NULL
;
25560 common_block_die_table
= NULL
;
25561 decl_loc_table
= NULL
;
25562 call_arg_locations
= NULL
;
25563 call_arg_loc_last
= NULL
;
25564 call_site_count
= -1;
25565 tail_call_site_count
= -1;
25566 cached_dw_loc_list_table
= NULL
;
25567 abbrev_die_table
= NULL
;
25568 abbrev_die_table_allocated
= 0;
25569 abbrev_die_table_in_use
= 0;
25570 line_info_label_num
= 0;
25571 cur_line_info_table
= NULL
;
25572 text_section_line_info
= NULL
;
25573 cold_text_section_line_info
= NULL
;
25574 separate_line_info
= NULL
;
25575 info_section_emitted
= false;
25576 pubname_table
= NULL
;
25577 pubtype_table
= NULL
;
25578 macinfo_table
= NULL
;
25579 ranges_table
= NULL
;
25580 ranges_table_allocated
= 0;
25581 ranges_table_in_use
= 0;
25582 ranges_by_label
= 0;
25583 ranges_by_label_allocated
= 0;
25584 ranges_by_label_in_use
= 0;
25585 have_location_lists
= false;
25588 last_emitted_file
= NULL
;
25590 tmpl_value_parm_die_table
= NULL
;
25591 generic_type_instances
= NULL
;
25592 frame_pointer_fb_offset
= 0;
25593 frame_pointer_fb_offset_valid
= false;
25594 base_types
.release ();
25595 XDELETEVEC (producer_string
);
25596 producer_string
= NULL
;
25599 #include "gt-dwarf2out.h"