1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2014 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"
64 #include "stringpool.h"
65 #include "stor-layout.h"
71 #include "hard-reg-set.h"
75 #include "hash-table.h"
80 #include "insn-config.h"
86 #include "dwarf2out.h"
87 #include "dwarf2asm.h"
91 #include "diagnostic.h"
92 #include "tree-pretty-print.h"
95 #include "common/common-target.h"
96 #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_hasher
<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 typedef struct GTY(()) deferred_locations_struct
1261 } deferred_locations
;
1264 static GTY(()) vec
<deferred_locations
, va_gc
> *deferred_locations_list
;
1267 /* Describe an entry into the .debug_addr section. */
1271 ate_kind_rtx_dtprel
,
1275 typedef struct GTY((for_user
)) addr_table_entry_struct
{
1277 unsigned int refcount
;
1279 union addr_table_entry_struct_union
1281 rtx
GTY ((tag ("0"))) rtl
;
1282 char * GTY ((tag ("1"))) label
;
1284 GTY ((desc ("%1.kind"))) addr
;
1288 /* Location lists are ranges + location descriptions for that range,
1289 so you can track variables that are in different places over
1290 their entire life. */
1291 typedef struct GTY(()) dw_loc_list_struct
{
1292 dw_loc_list_ref dw_loc_next
;
1293 const char *begin
; /* Label and addr_entry for start of range */
1294 addr_table_entry
*begin_entry
;
1295 const char *end
; /* Label for end of range */
1296 char *ll_symbol
; /* Label for beginning of location list.
1297 Only on head of list */
1298 const char *section
; /* Section this loclist is relative to */
1299 dw_loc_descr_ref expr
;
1301 /* True if all addresses in this and subsequent lists are known to be
1304 /* True if this list has been replaced by dw_loc_next. */
1307 /* True if the range should be emitted even if begin and end
1312 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1314 /* Convert a DWARF stack opcode into its string name. */
1317 dwarf_stack_op_name (unsigned int op
)
1319 const char *name
= get_DW_OP_name (op
);
1324 return "OP_<unknown>";
1327 /* Return a pointer to a newly allocated location description. Location
1328 descriptions are simple expression terms that can be strung
1329 together to form more complicated location (address) descriptions. */
1331 static inline dw_loc_descr_ref
1332 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1333 unsigned HOST_WIDE_INT oprnd2
)
1335 dw_loc_descr_ref descr
= ggc_cleared_alloc
<dw_loc_descr_node
> ();
1337 descr
->dw_loc_opc
= op
;
1338 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1339 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1340 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1341 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1342 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1343 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1348 /* Return a pointer to a newly allocated location description for
1351 static inline dw_loc_descr_ref
1352 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1355 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1358 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1361 /* Add a location description term to a location description expression. */
1364 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1366 dw_loc_descr_ref
*d
;
1368 /* Find the end of the chain. */
1369 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1375 /* Compare two location operands for exact equality. */
1378 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1380 if (a
->val_class
!= b
->val_class
)
1382 switch (a
->val_class
)
1384 case dw_val_class_none
:
1386 case dw_val_class_addr
:
1387 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1389 case dw_val_class_offset
:
1390 case dw_val_class_unsigned_const
:
1391 case dw_val_class_const
:
1392 case dw_val_class_range_list
:
1393 case dw_val_class_lineptr
:
1394 case dw_val_class_macptr
:
1395 /* These are all HOST_WIDE_INT, signed or unsigned. */
1396 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1398 case dw_val_class_loc
:
1399 return a
->v
.val_loc
== b
->v
.val_loc
;
1400 case dw_val_class_loc_list
:
1401 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1402 case dw_val_class_die_ref
:
1403 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1404 case dw_val_class_fde_ref
:
1405 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1406 case dw_val_class_lbl_id
:
1407 case dw_val_class_high_pc
:
1408 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1409 case dw_val_class_str
:
1410 return a
->v
.val_str
== b
->v
.val_str
;
1411 case dw_val_class_flag
:
1412 return a
->v
.val_flag
== b
->v
.val_flag
;
1413 case dw_val_class_file
:
1414 return a
->v
.val_file
== b
->v
.val_file
;
1415 case dw_val_class_decl_ref
:
1416 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1418 case dw_val_class_const_double
:
1419 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1420 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1422 case dw_val_class_wide_int
:
1423 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1425 case dw_val_class_vec
:
1427 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1428 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1430 return (a_len
== b_len
1431 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1434 case dw_val_class_data8
:
1435 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1437 case dw_val_class_vms_delta
:
1438 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1439 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1444 /* Compare two location atoms for exact equality. */
1447 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1449 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1452 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1453 address size, but since we always allocate cleared storage it
1454 should be zero for other types of locations. */
1455 if (a
->dtprel
!= b
->dtprel
)
1458 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1459 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1462 /* Compare two complete location expressions for exact equality. */
1465 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1471 if (a
== NULL
|| b
== NULL
)
1473 if (!loc_descr_equal_p_1 (a
, b
))
1482 /* Add a constant OFFSET to a location expression. */
1485 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1487 dw_loc_descr_ref loc
;
1490 gcc_assert (*list_head
!= NULL
);
1495 /* Find the end of the chain. */
1496 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1500 if (loc
->dw_loc_opc
== DW_OP_fbreg
1501 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1502 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1503 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1504 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1506 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1507 offset. Don't optimize if an signed integer overflow would happen. */
1509 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1510 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1513 else if (offset
> 0)
1514 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1518 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1519 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1523 /* Add a constant OFFSET to a location list. */
1526 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1529 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1530 loc_descr_plus_const (&d
->expr
, offset
);
1533 #define DWARF_REF_SIZE \
1534 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1536 static unsigned long int get_base_type_offset (dw_die_ref
);
1538 /* Return the size of a location descriptor. */
1540 static unsigned long
1541 size_of_loc_descr (dw_loc_descr_ref loc
)
1543 unsigned long size
= 1;
1545 switch (loc
->dw_loc_opc
)
1548 size
+= DWARF2_ADDR_SIZE
;
1550 case DW_OP_GNU_addr_index
:
1551 case DW_OP_GNU_const_index
:
1552 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1553 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1572 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1575 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1580 case DW_OP_plus_uconst
:
1581 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1619 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1622 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1625 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1628 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1629 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1632 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1634 case DW_OP_bit_piece
:
1635 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1636 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1638 case DW_OP_deref_size
:
1639 case DW_OP_xderef_size
:
1648 case DW_OP_call_ref
:
1649 size
+= DWARF_REF_SIZE
;
1651 case DW_OP_implicit_value
:
1652 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1653 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1655 case DW_OP_GNU_implicit_pointer
:
1656 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1658 case DW_OP_GNU_entry_value
:
1660 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1661 size
+= size_of_uleb128 (op_size
) + op_size
;
1664 case DW_OP_GNU_const_type
:
1667 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1668 size
+= size_of_uleb128 (o
) + 1;
1669 switch (loc
->dw_loc_oprnd2
.val_class
)
1671 case dw_val_class_vec
:
1672 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1673 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1675 case dw_val_class_const
:
1676 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1678 case dw_val_class_const_double
:
1679 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1681 case dw_val_class_wide_int
:
1682 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
1683 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
1690 case DW_OP_GNU_regval_type
:
1693 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1694 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1695 + size_of_uleb128 (o
);
1698 case DW_OP_GNU_deref_type
:
1701 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1702 size
+= 1 + size_of_uleb128 (o
);
1705 case DW_OP_GNU_convert
:
1706 case DW_OP_GNU_reinterpret
:
1707 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1708 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1712 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1713 size
+= size_of_uleb128 (o
);
1716 case DW_OP_GNU_parameter_ref
:
1726 /* Return the size of a series of location descriptors. */
1729 size_of_locs (dw_loc_descr_ref loc
)
1734 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1735 field, to avoid writing to a PCH file. */
1736 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1738 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1740 size
+= size_of_loc_descr (l
);
1745 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1747 l
->dw_loc_addr
= size
;
1748 size
+= size_of_loc_descr (l
);
1754 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1755 static void get_ref_die_offset_label (char *, dw_die_ref
);
1756 static unsigned long int get_ref_die_offset (dw_die_ref
);
1758 /* Output location description stack opcode's operands (if any).
1759 The for_eh_or_skip parameter controls whether register numbers are
1760 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1761 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1762 info). This should be suppressed for the cases that have not been converted
1763 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1766 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1768 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1769 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1771 switch (loc
->dw_loc_opc
)
1773 #ifdef DWARF2_DEBUGGING_INFO
1776 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1781 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1782 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1784 fputc ('\n', asm_out_file
);
1789 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1794 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1795 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1797 fputc ('\n', asm_out_file
);
1802 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1803 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1810 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1811 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1813 dw2_asm_output_data (2, offset
, NULL
);
1816 case DW_OP_implicit_value
:
1817 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1818 switch (val2
->val_class
)
1820 case dw_val_class_const
:
1821 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1823 case dw_val_class_vec
:
1825 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1826 unsigned int len
= val2
->v
.val_vec
.length
;
1830 if (elt_size
> sizeof (HOST_WIDE_INT
))
1835 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1838 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1839 "fp or vector constant word %u", i
);
1842 case dw_val_class_const_double
:
1844 unsigned HOST_WIDE_INT first
, second
;
1846 if (WORDS_BIG_ENDIAN
)
1848 first
= val2
->v
.val_double
.high
;
1849 second
= val2
->v
.val_double
.low
;
1853 first
= val2
->v
.val_double
.low
;
1854 second
= val2
->v
.val_double
.high
;
1856 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1858 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1862 case dw_val_class_wide_int
:
1865 int len
= get_full_len (*val2
->v
.val_wide
);
1866 if (WORDS_BIG_ENDIAN
)
1867 for (i
= len
- 1; i
>= 0; --i
)
1868 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1869 val2
->v
.val_wide
->elt (i
), NULL
);
1871 for (i
= 0; i
< len
; ++i
)
1872 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1873 val2
->v
.val_wide
->elt (i
), NULL
);
1876 case dw_val_class_addr
:
1877 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1878 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1893 case DW_OP_implicit_value
:
1894 /* We currently don't make any attempt to make sure these are
1895 aligned properly like we do for the main unwind info, so
1896 don't support emitting things larger than a byte if we're
1897 only doing unwinding. */
1902 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1905 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1908 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1911 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1913 case DW_OP_plus_uconst
:
1914 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1948 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1952 unsigned r
= val1
->v
.val_unsigned
;
1953 if (for_eh_or_skip
>= 0)
1954 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1955 gcc_assert (size_of_uleb128 (r
)
1956 == size_of_uleb128 (val1
->v
.val_unsigned
));
1957 dw2_asm_output_data_uleb128 (r
, NULL
);
1961 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1965 unsigned r
= val1
->v
.val_unsigned
;
1966 if (for_eh_or_skip
>= 0)
1967 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1968 gcc_assert (size_of_uleb128 (r
)
1969 == size_of_uleb128 (val1
->v
.val_unsigned
));
1970 dw2_asm_output_data_uleb128 (r
, NULL
);
1971 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1975 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1977 case DW_OP_bit_piece
:
1978 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1979 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1981 case DW_OP_deref_size
:
1982 case DW_OP_xderef_size
:
1983 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1989 if (targetm
.asm_out
.output_dwarf_dtprel
)
1991 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1994 fputc ('\n', asm_out_file
);
2001 #ifdef DWARF2_DEBUGGING_INFO
2002 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2009 case DW_OP_GNU_addr_index
:
2010 case DW_OP_GNU_const_index
:
2011 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
2012 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
2013 "(index into .debug_addr)");
2016 case DW_OP_GNU_implicit_pointer
:
2018 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2019 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2020 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2021 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2022 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2023 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2027 case DW_OP_GNU_entry_value
:
2028 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2029 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2032 case DW_OP_GNU_const_type
:
2034 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2036 dw2_asm_output_data_uleb128 (o
, NULL
);
2037 switch (val2
->val_class
)
2039 case dw_val_class_const
:
2040 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2041 dw2_asm_output_data (1, l
, NULL
);
2042 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2044 case dw_val_class_vec
:
2046 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2047 unsigned int len
= val2
->v
.val_vec
.length
;
2052 dw2_asm_output_data (1, l
, NULL
);
2053 if (elt_size
> sizeof (HOST_WIDE_INT
))
2058 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2061 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2062 "fp or vector constant word %u", i
);
2065 case dw_val_class_const_double
:
2067 unsigned HOST_WIDE_INT first
, second
;
2068 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2070 dw2_asm_output_data (1, 2 * l
, NULL
);
2071 if (WORDS_BIG_ENDIAN
)
2073 first
= val2
->v
.val_double
.high
;
2074 second
= val2
->v
.val_double
.low
;
2078 first
= val2
->v
.val_double
.low
;
2079 second
= val2
->v
.val_double
.high
;
2081 dw2_asm_output_data (l
, first
, NULL
);
2082 dw2_asm_output_data (l
, second
, NULL
);
2085 case dw_val_class_wide_int
:
2088 int len
= get_full_len (*val2
->v
.val_wide
);
2089 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2091 dw2_asm_output_data (1, len
* l
, NULL
);
2092 if (WORDS_BIG_ENDIAN
)
2093 for (i
= len
- 1; i
>= 0; --i
)
2094 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2096 for (i
= 0; i
< len
; ++i
)
2097 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2105 case DW_OP_GNU_regval_type
:
2107 unsigned r
= val1
->v
.val_unsigned
;
2108 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2110 if (for_eh_or_skip
>= 0)
2112 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2113 gcc_assert (size_of_uleb128 (r
)
2114 == size_of_uleb128 (val1
->v
.val_unsigned
));
2116 dw2_asm_output_data_uleb128 (r
, NULL
);
2117 dw2_asm_output_data_uleb128 (o
, NULL
);
2120 case DW_OP_GNU_deref_type
:
2122 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2124 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2125 dw2_asm_output_data_uleb128 (o
, NULL
);
2128 case DW_OP_GNU_convert
:
2129 case DW_OP_GNU_reinterpret
:
2130 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2131 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2134 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2136 dw2_asm_output_data_uleb128 (o
, NULL
);
2140 case DW_OP_GNU_parameter_ref
:
2143 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2144 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2145 dw2_asm_output_data (4, o
, NULL
);
2150 /* Other codes have no operands. */
2155 /* Output a sequence of location operations.
2156 The for_eh_or_skip parameter controls whether register numbers are
2157 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2158 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2159 info). This should be suppressed for the cases that have not been converted
2160 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2163 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2165 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2167 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2168 /* Output the opcode. */
2169 if (for_eh_or_skip
>= 0
2170 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2172 unsigned r
= (opc
- DW_OP_breg0
);
2173 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2174 gcc_assert (r
<= 31);
2175 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2177 else if (for_eh_or_skip
>= 0
2178 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2180 unsigned r
= (opc
- DW_OP_reg0
);
2181 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2182 gcc_assert (r
<= 31);
2183 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2186 dw2_asm_output_data (1, opc
,
2187 "%s", dwarf_stack_op_name (opc
));
2189 /* Output the operand(s) (if any). */
2190 output_loc_operands (loc
, for_eh_or_skip
);
2194 /* Output location description stack opcode's operands (if any).
2195 The output is single bytes on a line, suitable for .cfi_escape. */
2198 output_loc_operands_raw (dw_loc_descr_ref loc
)
2200 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2201 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2203 switch (loc
->dw_loc_opc
)
2206 case DW_OP_GNU_addr_index
:
2207 case DW_OP_GNU_const_index
:
2208 case DW_OP_implicit_value
:
2209 /* We cannot output addresses in .cfi_escape, only bytes. */
2215 case DW_OP_deref_size
:
2216 case DW_OP_xderef_size
:
2217 fputc (',', asm_out_file
);
2218 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2223 fputc (',', asm_out_file
);
2224 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2229 fputc (',', asm_out_file
);
2230 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2235 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2236 fputc (',', asm_out_file
);
2237 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2245 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2246 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2248 fputc (',', asm_out_file
);
2249 dw2_asm_output_data_raw (2, offset
);
2255 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2256 gcc_assert (size_of_uleb128 (r
)
2257 == size_of_uleb128 (val1
->v
.val_unsigned
));
2258 fputc (',', asm_out_file
);
2259 dw2_asm_output_data_uleb128_raw (r
);
2264 case DW_OP_plus_uconst
:
2266 fputc (',', asm_out_file
);
2267 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2270 case DW_OP_bit_piece
:
2271 fputc (',', asm_out_file
);
2272 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2273 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2310 fputc (',', asm_out_file
);
2311 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2316 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2317 gcc_assert (size_of_uleb128 (r
)
2318 == size_of_uleb128 (val1
->v
.val_unsigned
));
2319 fputc (',', asm_out_file
);
2320 dw2_asm_output_data_uleb128_raw (r
);
2321 fputc (',', asm_out_file
);
2322 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2326 case DW_OP_GNU_implicit_pointer
:
2327 case DW_OP_GNU_entry_value
:
2328 case DW_OP_GNU_const_type
:
2329 case DW_OP_GNU_regval_type
:
2330 case DW_OP_GNU_deref_type
:
2331 case DW_OP_GNU_convert
:
2332 case DW_OP_GNU_reinterpret
:
2333 case DW_OP_GNU_parameter_ref
:
2338 /* Other codes have no operands. */
2344 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2348 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2349 /* Output the opcode. */
2350 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2352 unsigned r
= (opc
- DW_OP_breg0
);
2353 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2354 gcc_assert (r
<= 31);
2355 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2357 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2359 unsigned r
= (opc
- DW_OP_reg0
);
2360 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2361 gcc_assert (r
<= 31);
2362 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2364 /* Output the opcode. */
2365 fprintf (asm_out_file
, "%#x", opc
);
2366 output_loc_operands_raw (loc
);
2368 if (!loc
->dw_loc_next
)
2370 loc
= loc
->dw_loc_next
;
2372 fputc (',', asm_out_file
);
2376 /* This function builds a dwarf location descriptor sequence from a
2377 dw_cfa_location, adding the given OFFSET to the result of the
2380 struct dw_loc_descr_node
*
2381 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2383 struct dw_loc_descr_node
*head
, *tmp
;
2385 offset
+= cfa
->offset
;
2389 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2390 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2391 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2392 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2393 add_loc_descr (&head
, tmp
);
2396 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2397 add_loc_descr (&head
, tmp
);
2401 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2406 /* This function builds a dwarf location descriptor sequence for
2407 the address at OFFSET from the CFA when stack is aligned to
2410 struct dw_loc_descr_node
*
2411 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2412 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2414 struct dw_loc_descr_node
*head
;
2415 unsigned int dwarf_fp
2416 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2418 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2419 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2421 head
= new_reg_loc_descr (dwarf_fp
, 0);
2422 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2423 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2424 loc_descr_plus_const (&head
, offset
);
2427 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2431 /* And now, the support for symbolic debugging information. */
2433 /* .debug_str support. */
2435 static void dwarf2out_init (const char *);
2436 static void dwarf2out_finish (const char *);
2437 static void dwarf2out_assembly_start (void);
2438 static void dwarf2out_define (unsigned int, const char *);
2439 static void dwarf2out_undef (unsigned int, const char *);
2440 static void dwarf2out_start_source_file (unsigned, const char *);
2441 static void dwarf2out_end_source_file (unsigned);
2442 static void dwarf2out_function_decl (tree
);
2443 static void dwarf2out_begin_block (unsigned, unsigned);
2444 static void dwarf2out_end_block (unsigned, unsigned);
2445 static bool dwarf2out_ignore_block (const_tree
);
2446 static void dwarf2out_global_decl (tree
);
2447 static void dwarf2out_type_decl (tree
, int);
2448 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2449 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2451 static void dwarf2out_abstract_function (tree
);
2452 static void dwarf2out_var_location (rtx_insn
*);
2453 static void dwarf2out_begin_function (tree
);
2454 static void dwarf2out_end_function (unsigned int);
2455 static void dwarf2out_set_name (tree
, tree
);
2457 /* The debug hooks structure. */
2459 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2463 dwarf2out_assembly_start
,
2466 dwarf2out_start_source_file
,
2467 dwarf2out_end_source_file
,
2468 dwarf2out_begin_block
,
2469 dwarf2out_end_block
,
2470 dwarf2out_ignore_block
,
2471 dwarf2out_source_line
,
2472 dwarf2out_begin_prologue
,
2473 #if VMS_DEBUGGING_INFO
2474 dwarf2out_vms_end_prologue
,
2475 dwarf2out_vms_begin_epilogue
,
2477 debug_nothing_int_charstar
,
2478 debug_nothing_int_charstar
,
2480 dwarf2out_end_epilogue
,
2481 dwarf2out_begin_function
,
2482 dwarf2out_end_function
, /* end_function */
2483 dwarf2out_function_decl
, /* function_decl */
2484 dwarf2out_global_decl
,
2485 dwarf2out_type_decl
, /* type_decl */
2486 dwarf2out_imported_module_or_decl
,
2487 debug_nothing_tree
, /* deferred_inline_function */
2488 /* The DWARF 2 backend tries to reduce debugging bloat by not
2489 emitting the abstract description of inline functions until
2490 something tries to reference them. */
2491 dwarf2out_abstract_function
, /* outlining_inline_function */
2492 debug_nothing_rtx_code_label
, /* label */
2493 debug_nothing_int
, /* handle_pch */
2494 dwarf2out_var_location
,
2495 dwarf2out_switch_text_section
,
2497 1, /* start_end_main_source_file */
2498 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2501 /* NOTE: In the comments in this file, many references are made to
2502 "Debugging Information Entries". This term is abbreviated as `DIE'
2503 throughout the remainder of this file. */
2505 /* An internal representation of the DWARF output is built, and then
2506 walked to generate the DWARF debugging info. The walk of the internal
2507 representation is done after the entire program has been compiled.
2508 The types below are used to describe the internal representation. */
2510 /* Whether to put type DIEs into their own section .debug_types instead
2511 of making them part of the .debug_info section. Only supported for
2512 Dwarf V4 or higher and the user didn't disable them through
2513 -fno-debug-types-section. It is more efficient to put them in a
2514 separate comdat sections since the linker will then be able to
2515 remove duplicates. But not all tools support .debug_types sections
2518 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2520 /* Various DIE's use offsets relative to the beginning of the
2521 .debug_info section to refer to each other. */
2523 typedef long int dw_offset
;
2525 /* Define typedefs here to avoid circular dependencies. */
2527 typedef struct dw_attr_struct
*dw_attr_ref
;
2528 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2529 typedef struct pubname_struct
*pubname_ref
;
2530 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2531 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2532 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2534 /* The entries in the line_info table more-or-less mirror the opcodes
2535 that are used in the real dwarf line table. Arrays of these entries
2536 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2539 enum dw_line_info_opcode
{
2540 /* Emit DW_LNE_set_address; the operand is the label index. */
2543 /* Emit a row to the matrix with the given line. This may be done
2544 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2548 /* Emit a DW_LNS_set_file. */
2551 /* Emit a DW_LNS_set_column. */
2554 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2557 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2558 LI_set_prologue_end
,
2559 LI_set_epilogue_begin
,
2561 /* Emit a DW_LNE_set_discriminator. */
2562 LI_set_discriminator
2565 typedef struct GTY(()) dw_line_info_struct
{
2566 enum dw_line_info_opcode opcode
;
2568 } dw_line_info_entry
;
2571 typedef struct GTY(()) dw_line_info_table_struct
{
2572 /* The label that marks the end of this section. */
2573 const char *end_label
;
2575 /* The values for the last row of the matrix, as collected in the table.
2576 These are used to minimize the changes to the next row. */
2577 unsigned int file_num
;
2578 unsigned int line_num
;
2579 unsigned int column_num
;
2584 vec
<dw_line_info_entry
, va_gc
> *entries
;
2585 } dw_line_info_table
;
2587 typedef dw_line_info_table
*dw_line_info_table_p
;
2590 /* Each DIE attribute has a field specifying the attribute kind,
2591 a link to the next attribute in the chain, and an attribute value.
2592 Attributes are typically linked below the DIE they modify. */
2594 typedef struct GTY(()) dw_attr_struct
{
2595 enum dwarf_attribute dw_attr
;
2596 dw_val_node dw_attr_val
;
2601 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2602 The children of each node form a circular list linked by
2603 die_sib. die_child points to the node *before* the "first" child node. */
2605 typedef struct GTY((chain_circular ("%h.die_sib"), for_user
)) die_struct
{
2606 union die_symbol_or_type_node
2608 const char * GTY ((tag ("0"))) die_symbol
;
2609 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2611 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2612 vec
<dw_attr_node
, va_gc
> *die_attr
;
2613 dw_die_ref die_parent
;
2614 dw_die_ref die_child
;
2616 dw_die_ref die_definition
; /* ref from a specification to its definition */
2617 dw_offset die_offset
;
2618 unsigned long die_abbrev
;
2620 unsigned int decl_id
;
2621 enum dwarf_tag die_tag
;
2622 /* Die is used and must not be pruned as unused. */
2623 BOOL_BITFIELD die_perennial_p
: 1;
2624 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2625 /* Lots of spare bits. */
2629 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2630 #define FOR_EACH_CHILD(die, c, expr) do { \
2631 c = die->die_child; \
2635 } while (c != die->die_child); \
2638 /* The pubname structure */
2640 typedef struct GTY(()) pubname_struct
{
2647 struct GTY(()) dw_ranges_struct
{
2648 /* If this is positive, it's a block number, otherwise it's a
2649 bitwise-negated index into dw_ranges_by_label. */
2653 /* A structure to hold a macinfo entry. */
2655 typedef struct GTY(()) macinfo_struct
{
2657 unsigned HOST_WIDE_INT lineno
;
2663 struct GTY(()) dw_ranges_by_label_struct
{
2668 /* The comdat type node structure. */
2669 typedef struct GTY(()) comdat_type_struct
2671 dw_die_ref root_die
;
2672 dw_die_ref type_die
;
2673 dw_die_ref skeleton_die
;
2674 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2675 struct comdat_type_struct
*next
;
2679 /* The limbo die list structure. */
2680 typedef struct GTY(()) limbo_die_struct
{
2683 struct limbo_die_struct
*next
;
2687 typedef struct skeleton_chain_struct
2691 struct skeleton_chain_struct
*parent
;
2693 skeleton_chain_node
;
2695 /* Define a macro which returns nonzero for a TYPE_DECL which was
2696 implicitly generated for a type.
2698 Note that, unlike the C front-end (which generates a NULL named
2699 TYPE_DECL node for each complete tagged type, each array type,
2700 and each function type node created) the C++ front-end generates
2701 a _named_ TYPE_DECL node for each tagged type node created.
2702 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2703 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2704 front-end, but for each type, tagged or not. */
2706 #define TYPE_DECL_IS_STUB(decl) \
2707 (DECL_NAME (decl) == NULL_TREE \
2708 || (DECL_ARTIFICIAL (decl) \
2709 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2710 /* This is necessary for stub decls that \
2711 appear in nested inline functions. */ \
2712 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2713 && (decl_ultimate_origin (decl) \
2714 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2716 /* Information concerning the compilation unit's programming
2717 language, and compiler version. */
2719 /* Fixed size portion of the DWARF compilation unit header. */
2720 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2721 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2723 /* Fixed size portion of the DWARF comdat type unit header. */
2724 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2725 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2726 + DWARF_OFFSET_SIZE)
2728 /* Fixed size portion of public names info. */
2729 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2731 /* Fixed size portion of the address range info. */
2732 #define DWARF_ARANGES_HEADER_SIZE \
2733 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2734 DWARF2_ADDR_SIZE * 2) \
2735 - DWARF_INITIAL_LENGTH_SIZE)
2737 /* Size of padding portion in the address range info. It must be
2738 aligned to twice the pointer size. */
2739 #define DWARF_ARANGES_PAD_SIZE \
2740 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2741 DWARF2_ADDR_SIZE * 2) \
2742 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2744 /* Use assembler line directives if available. */
2745 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2746 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2747 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2749 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2753 /* Minimum line offset in a special line info. opcode.
2754 This value was chosen to give a reasonable range of values. */
2755 #define DWARF_LINE_BASE -10
2757 /* First special line opcode - leave room for the standard opcodes. */
2758 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2760 /* Range of line offsets in a special line info. opcode. */
2761 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2763 /* Flag that indicates the initial value of the is_stmt_start flag.
2764 In the present implementation, we do not mark any lines as
2765 the beginning of a source statement, because that information
2766 is not made available by the GCC front-end. */
2767 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2769 /* Maximum number of operations per instruction bundle. */
2770 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2771 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2774 /* This location is used by calc_die_sizes() to keep track
2775 the offset of each DIE within the .debug_info section. */
2776 static unsigned long next_die_offset
;
2778 /* Record the root of the DIE's built for the current compilation unit. */
2779 static GTY(()) dw_die_ref single_comp_unit_die
;
2781 /* A list of type DIEs that have been separated into comdat sections. */
2782 static GTY(()) comdat_type_node
*comdat_type_list
;
2784 /* A list of DIEs with a NULL parent waiting to be relocated. */
2785 static GTY(()) limbo_die_node
*limbo_die_list
;
2787 /* A list of DIEs for which we may have to generate
2788 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2789 static GTY(()) limbo_die_node
*deferred_asm_name
;
2791 struct dwarf_file_hasher
: ggc_hasher
<dwarf_file_data
*>
2793 typedef const char *compare_type
;
2795 static hashval_t
hash (dwarf_file_data
*);
2796 static bool equal (dwarf_file_data
*, const char *);
2799 /* Filenames referenced by this compilation unit. */
2800 static GTY(()) hash_table
<dwarf_file_hasher
> *file_table
;
2802 struct decl_die_hasher
: ggc_hasher
<die_node
*>
2804 typedef tree compare_type
;
2806 static hashval_t
hash (die_node
*);
2807 static bool equal (die_node
*, tree
);
2809 /* A hash table of references to DIE's that describe declarations.
2810 The key is a DECL_UID() which is a unique number identifying each decl. */
2811 static GTY (()) hash_table
<decl_die_hasher
> *decl_die_table
;
2813 struct block_die_hasher
: ggc_hasher
<die_struct
*>
2815 static hashval_t
hash (die_struct
*);
2816 static bool equal (die_struct
*, die_struct
*);
2819 /* A hash table of references to DIE's that describe COMMON blocks.
2820 The key is DECL_UID() ^ die_parent. */
2821 static GTY (()) hash_table
<block_die_hasher
> *common_block_die_table
;
2823 typedef struct GTY(()) die_arg_entry_struct
{
2829 /* Node of the variable location list. */
2830 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2831 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2832 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2833 in mode of the EXPR_LIST node and first EXPR_LIST operand
2834 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2835 location or NULL for padding. For larger bitsizes,
2836 mode is 0 and first operand is a CONCAT with bitsize
2837 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2838 NULL as second operand. */
2840 const char * GTY (()) label
;
2841 struct var_loc_node
* GTY (()) next
;
2844 /* Variable location list. */
2845 struct GTY ((for_user
)) var_loc_list_def
{
2846 struct var_loc_node
* GTY (()) first
;
2848 /* Pointer to the last but one or last element of the
2849 chained list. If the list is empty, both first and
2850 last are NULL, if the list contains just one node
2851 or the last node certainly is not redundant, it points
2852 to the last node, otherwise points to the last but one.
2853 Do not mark it for GC because it is marked through the chain. */
2854 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2856 /* Pointer to the last element before section switch,
2857 if NULL, either sections weren't switched or first
2858 is after section switch. */
2859 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2861 /* DECL_UID of the variable decl. */
2862 unsigned int decl_id
;
2864 typedef struct var_loc_list_def var_loc_list
;
2866 /* Call argument location list. */
2867 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2868 rtx
GTY (()) call_arg_loc_note
;
2869 const char * GTY (()) label
;
2870 tree
GTY (()) block
;
2872 rtx
GTY (()) symbol_ref
;
2873 struct call_arg_loc_node
* GTY (()) next
;
2877 struct decl_loc_hasher
: ggc_hasher
<var_loc_list
*>
2879 typedef const_tree compare_type
;
2881 static hashval_t
hash (var_loc_list
*);
2882 static bool equal (var_loc_list
*, const_tree
);
2885 /* Table of decl location linked lists. */
2886 static GTY (()) hash_table
<decl_loc_hasher
> *decl_loc_table
;
2888 /* Head and tail of call_arg_loc chain. */
2889 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2890 static struct call_arg_loc_node
*call_arg_loc_last
;
2892 /* Number of call sites in the current function. */
2893 static int call_site_count
= -1;
2894 /* Number of tail call sites in the current function. */
2895 static int tail_call_site_count
= -1;
2897 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2899 static vec
<dw_die_ref
> block_map
;
2901 /* A cached location list. */
2902 struct GTY ((for_user
)) cached_dw_loc_list_def
{
2903 /* The DECL_UID of the decl that this entry describes. */
2904 unsigned int decl_id
;
2906 /* The cached location list. */
2907 dw_loc_list_ref loc_list
;
2909 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2911 struct dw_loc_list_hasher
: ggc_hasher
<cached_dw_loc_list
*>
2914 typedef const_tree compare_type
;
2916 static hashval_t
hash (cached_dw_loc_list
*);
2917 static bool equal (cached_dw_loc_list
*, const_tree
);
2920 /* Table of cached location lists. */
2921 static GTY (()) hash_table
<dw_loc_list_hasher
> *cached_dw_loc_list_table
;
2923 /* A pointer to the base of a list of references to DIE's that
2924 are uniquely identified by their tag, presence/absence of
2925 children DIE's, and list of attribute/value pairs. */
2926 static GTY((length ("abbrev_die_table_allocated")))
2927 dw_die_ref
*abbrev_die_table
;
2929 /* Number of elements currently allocated for abbrev_die_table. */
2930 static GTY(()) unsigned abbrev_die_table_allocated
;
2932 /* Number of elements in type_die_table currently in use. */
2933 static GTY(()) unsigned abbrev_die_table_in_use
;
2935 /* Size (in elements) of increments by which we may expand the
2936 abbrev_die_table. */
2937 #define ABBREV_DIE_TABLE_INCREMENT 256
2939 /* A global counter for generating labels for line number data. */
2940 static unsigned int line_info_label_num
;
2942 /* The current table to which we should emit line number information
2943 for the current function. This will be set up at the beginning of
2944 assembly for the function. */
2945 static dw_line_info_table
*cur_line_info_table
;
2947 /* The two default tables of line number info. */
2948 static GTY(()) dw_line_info_table
*text_section_line_info
;
2949 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2951 /* The set of all non-default tables of line number info. */
2952 static GTY(()) vec
<dw_line_info_table_p
, va_gc
> *separate_line_info
;
2954 /* A flag to tell pubnames/types export if there is an info section to
2956 static bool info_section_emitted
;
2958 /* A pointer to the base of a table that contains a list of publicly
2959 accessible names. */
2960 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2962 /* A pointer to the base of a table that contains a list of publicly
2963 accessible types. */
2964 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
2966 /* A pointer to the base of a table that contains a list of macro
2967 defines/undefines (and file start/end markers). */
2968 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
2970 /* True if .debug_macinfo or .debug_macros section is going to be
2972 #define have_macinfo \
2973 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2974 && !macinfo_table->is_empty ())
2976 /* Array of dies for which we should generate .debug_ranges info. */
2977 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2979 /* Number of elements currently allocated for ranges_table. */
2980 static GTY(()) unsigned ranges_table_allocated
;
2982 /* Number of elements in ranges_table currently in use. */
2983 static GTY(()) unsigned ranges_table_in_use
;
2985 /* Array of pairs of labels referenced in ranges_table. */
2986 static GTY ((length ("ranges_by_label_allocated")))
2987 dw_ranges_by_label_ref ranges_by_label
;
2989 /* Number of elements currently allocated for ranges_by_label. */
2990 static GTY(()) unsigned ranges_by_label_allocated
;
2992 /* Number of elements in ranges_by_label currently in use. */
2993 static GTY(()) unsigned ranges_by_label_in_use
;
2995 /* Size (in elements) of increments by which we may expand the
2997 #define RANGES_TABLE_INCREMENT 64
2999 /* Whether we have location lists that need outputting */
3000 static GTY(()) bool have_location_lists
;
3002 /* Unique label counter. */
3003 static GTY(()) unsigned int loclabel_num
;
3005 /* Unique label counter for point-of-call tables. */
3006 static GTY(()) unsigned int poc_label_num
;
3008 /* The last file entry emitted by maybe_emit_file(). */
3009 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3011 /* Number of internal labels generated by gen_internal_sym(). */
3012 static GTY(()) int label_num
;
3014 /* Cached result of previous call to lookup_filename. */
3015 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
3017 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
3019 /* Instances of generic types for which we need to generate debug
3020 info that describe their generic parameters and arguments. That
3021 generation needs to happen once all types are properly laid out so
3022 we do it at the end of compilation. */
3023 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
3025 /* Offset from the "steady-state frame pointer" to the frame base,
3026 within the current function. */
3027 static HOST_WIDE_INT frame_pointer_fb_offset
;
3028 static bool frame_pointer_fb_offset_valid
;
3030 static vec
<dw_die_ref
> base_types
;
3032 /* Forward declarations for functions defined in this file. */
3034 static int is_pseudo_reg (const_rtx
);
3035 static tree
type_main_variant (tree
);
3036 static int is_tagged_type (const_tree
);
3037 static const char *dwarf_tag_name (unsigned);
3038 static const char *dwarf_attr_name (unsigned);
3039 static const char *dwarf_form_name (unsigned);
3040 static tree
decl_ultimate_origin (const_tree
);
3041 static tree
decl_class_context (tree
);
3042 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
3043 static inline enum dw_val_class
AT_class (dw_attr_ref
);
3044 static inline unsigned int AT_index (dw_attr_ref
);
3045 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3046 static inline unsigned AT_flag (dw_attr_ref
);
3047 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3048 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
3049 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3050 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
3051 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3052 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3053 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3054 unsigned int, unsigned char *);
3055 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3056 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3057 static inline const char *AT_string (dw_attr_ref
);
3058 static enum dwarf_form
AT_string_form (dw_attr_ref
);
3059 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3060 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3061 static inline dw_die_ref
AT_ref (dw_attr_ref
);
3062 static inline int AT_ref_external (dw_attr_ref
);
3063 static inline void set_AT_ref_external (dw_attr_ref
, int);
3064 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3065 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3066 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
3067 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3069 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
3070 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3071 static void remove_addr_table_entry (addr_table_entry
*);
3072 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3073 static inline rtx
AT_addr (dw_attr_ref
);
3074 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3075 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3076 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3077 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3078 unsigned HOST_WIDE_INT
);
3079 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3080 unsigned long, bool);
3081 static inline const char *AT_lbl (dw_attr_ref
);
3082 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
3083 static const char *get_AT_low_pc (dw_die_ref
);
3084 static const char *get_AT_hi_pc (dw_die_ref
);
3085 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3086 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3087 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3088 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3089 static bool is_cxx (void);
3090 static bool is_fortran (void);
3091 static bool is_ada (void);
3092 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
3093 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3094 static void add_child_die (dw_die_ref
, dw_die_ref
);
3095 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3096 static dw_die_ref
lookup_type_die (tree
);
3097 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3098 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3099 static void equate_type_number_to_die (tree
, dw_die_ref
);
3100 static dw_die_ref
lookup_decl_die (tree
);
3101 static var_loc_list
*lookup_decl_loc (const_tree
);
3102 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3103 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3104 static void print_spaces (FILE *);
3105 static void print_die (dw_die_ref
, FILE *);
3106 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3107 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3108 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3109 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3110 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3111 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3112 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3113 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3114 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
3115 struct md5_ctx
*, int *);
3116 struct checksum_attributes
;
3117 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3118 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3119 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3120 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3121 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3122 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3123 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3124 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3125 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3126 static void compute_section_prefix (dw_die_ref
);
3127 static int is_type_die (dw_die_ref
);
3128 static int is_comdat_die (dw_die_ref
);
3129 static int is_symbol_die (dw_die_ref
);
3130 static inline bool is_template_instantiation (dw_die_ref
);
3131 static void assign_symbol_names (dw_die_ref
);
3132 static void break_out_includes (dw_die_ref
);
3133 static int is_declaration_die (dw_die_ref
);
3134 static int should_move_die_to_comdat (dw_die_ref
);
3135 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3136 static dw_die_ref
clone_die (dw_die_ref
);
3137 static dw_die_ref
clone_tree (dw_die_ref
);
3138 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3139 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3140 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3141 static dw_die_ref
generate_skeleton (dw_die_ref
);
3142 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3145 static void break_out_comdat_types (dw_die_ref
);
3146 static void copy_decls_for_unworthy_types (dw_die_ref
);
3148 static void add_sibling_attributes (dw_die_ref
);
3149 static void output_location_lists (dw_die_ref
);
3150 static int constant_size (unsigned HOST_WIDE_INT
);
3151 static unsigned long size_of_die (dw_die_ref
);
3152 static void calc_die_sizes (dw_die_ref
);
3153 static void calc_base_type_die_sizes (void);
3154 static void mark_dies (dw_die_ref
);
3155 static void unmark_dies (dw_die_ref
);
3156 static void unmark_all_dies (dw_die_ref
);
3157 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3158 static unsigned long size_of_aranges (void);
3159 static enum dwarf_form
value_format (dw_attr_ref
);
3160 static void output_value_format (dw_attr_ref
);
3161 static void output_abbrev_section (void);
3162 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3163 static void output_die_symbol (dw_die_ref
);
3164 static void output_die (dw_die_ref
);
3165 static void output_compilation_unit_header (void);
3166 static void output_comp_unit (dw_die_ref
, int);
3167 static void output_comdat_type_unit (comdat_type_node
*);
3168 static const char *dwarf2_name (tree
, int);
3169 static void add_pubname (tree
, dw_die_ref
);
3170 static void add_enumerator_pubname (const char *, dw_die_ref
);
3171 static void add_pubname_string (const char *, dw_die_ref
);
3172 static void add_pubtype (tree
, dw_die_ref
);
3173 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3174 static void output_aranges (unsigned long);
3175 static unsigned int add_ranges_num (int);
3176 static unsigned int add_ranges (const_tree
);
3177 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3179 static void output_ranges (void);
3180 static dw_line_info_table
*new_line_info_table (void);
3181 static void output_line_info (bool);
3182 static void output_file_names (void);
3183 static dw_die_ref
base_type_die (tree
);
3184 static int is_base_type (tree
);
3185 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3186 static int decl_quals (const_tree
);
3187 static dw_die_ref
modified_type_die (tree
, int, dw_die_ref
);
3188 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3189 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3190 static int type_is_enum (const_tree
);
3191 static unsigned int dbx_reg_number (const_rtx
);
3192 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3193 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3194 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3195 enum var_init_status
);
3196 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3197 enum var_init_status
);
3198 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3199 enum var_init_status
);
3200 static int is_based_loc (const_rtx
);
3201 static bool resolve_one_addr (rtx
*);
3202 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3203 enum var_init_status
);
3204 static dw_loc_descr_ref
loc_descriptor (rtx
, machine_mode mode
,
3205 enum var_init_status
);
3206 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3207 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3208 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3209 static tree
field_type (const_tree
);
3210 static unsigned int simple_type_align_in_bits (const_tree
);
3211 static unsigned int simple_decl_align_in_bits (const_tree
);
3212 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3213 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3214 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3216 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3217 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3218 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3219 static void insert_wide_int (const wide_int
&, unsigned char *, int);
3220 static void insert_float (const_rtx
, unsigned char *);
3221 static rtx
rtl_for_decl_location (tree
);
3222 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3223 enum dwarf_attribute
);
3224 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3225 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3226 static void add_name_attribute (dw_die_ref
, const char *);
3227 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3228 static void add_comp_dir_attribute (dw_die_ref
);
3229 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3230 static void add_subscript_info (dw_die_ref
, tree
, bool);
3231 static void add_byte_size_attribute (dw_die_ref
, tree
);
3232 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3233 static void add_bit_size_attribute (dw_die_ref
, tree
);
3234 static void add_prototyped_attribute (dw_die_ref
, tree
);
3235 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3236 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3237 static void add_src_coords_attributes (dw_die_ref
, tree
);
3238 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3239 static void push_decl_scope (tree
);
3240 static void pop_decl_scope (void);
3241 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3242 static inline int local_scope_p (dw_die_ref
);
3243 static inline int class_scope_p (dw_die_ref
);
3244 static inline int class_or_namespace_scope_p (dw_die_ref
);
3245 static void add_type_attribute (dw_die_ref
, tree
, int, dw_die_ref
);
3246 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3247 static const char *type_tag (const_tree
);
3248 static tree
member_declared_type (const_tree
);
3250 static const char *decl_start_label (tree
);
3252 static void gen_array_type_die (tree
, dw_die_ref
);
3253 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3255 static void gen_entry_point_die (tree
, dw_die_ref
);
3257 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3258 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3259 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3260 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3261 static void gen_formal_types_die (tree
, dw_die_ref
);
3262 static void gen_subprogram_die (tree
, dw_die_ref
);
3263 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3264 static void gen_const_die (tree
, dw_die_ref
);
3265 static void gen_label_die (tree
, dw_die_ref
);
3266 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3267 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3268 static void gen_field_die (tree
, dw_die_ref
);
3269 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3270 static dw_die_ref
gen_compile_unit_die (const char *);
3271 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3272 static void gen_member_die (tree
, dw_die_ref
);
3273 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3274 enum debug_info_usage
);
3275 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3276 static void gen_typedef_die (tree
, dw_die_ref
);
3277 static void gen_type_die (tree
, dw_die_ref
);
3278 static void gen_block_die (tree
, dw_die_ref
, int);
3279 static void decls_for_scope (tree
, dw_die_ref
, int);
3280 static inline int is_redundant_typedef (const_tree
);
3281 static bool is_naming_typedef_decl (const_tree
);
3282 static inline dw_die_ref
get_context_die (tree
);
3283 static void gen_namespace_die (tree
, dw_die_ref
);
3284 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3285 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3286 static dw_die_ref
force_decl_die (tree
);
3287 static dw_die_ref
force_type_die (tree
);
3288 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3289 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3290 static struct dwarf_file_data
* lookup_filename (const char *);
3291 static void retry_incomplete_types (void);
3292 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3293 static void gen_generic_params_dies (tree
);
3294 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3295 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3296 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3297 static int file_info_cmp (const void *, const void *);
3298 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3299 const char *, const char *);
3300 static void output_loc_list (dw_loc_list_ref
);
3301 static char *gen_internal_sym (const char *);
3302 static bool want_pubnames (void);
3304 static void prune_unmark_dies (dw_die_ref
);
3305 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3306 static void prune_unused_types_mark (dw_die_ref
, int);
3307 static void prune_unused_types_walk (dw_die_ref
);
3308 static void prune_unused_types_walk_attribs (dw_die_ref
);
3309 static void prune_unused_types_prune (dw_die_ref
);
3310 static void prune_unused_types (void);
3311 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3312 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3313 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3314 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3315 const char *, const char *);
3316 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3317 static void gen_remaining_tmpl_value_param_die_attribute (void);
3318 static bool generic_type_p (tree
);
3319 static void schedule_generic_params_dies_gen (tree t
);
3320 static void gen_scheduled_generic_parms_dies (void);
3322 static const char *comp_dir_string (void);
3324 static void hash_loc_operands (dw_loc_descr_ref
, inchash::hash
&);
3326 /* enum for tracking thread-local variables whose address is really an offset
3327 relative to the TLS pointer, which will need link-time relocation, but will
3328 not need relocation by the DWARF consumer. */
3336 /* Return the operator to use for an address of a variable. For dtprel_true, we
3337 use DW_OP_const*. For regular variables, which need both link-time
3338 relocation and consumer-level relocation (e.g., to account for shared objects
3339 loaded at a random address), we use DW_OP_addr*. */
3341 static inline enum dwarf_location_atom
3342 dw_addr_op (enum dtprel_bool dtprel
)
3344 if (dtprel
== dtprel_true
)
3345 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3346 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3348 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3351 /* Return a pointer to a newly allocated address location description. If
3352 dwarf_split_debug_info is true, then record the address with the appropriate
3354 static inline dw_loc_descr_ref
3355 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3357 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3359 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3360 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3361 ref
->dtprel
= dtprel
;
3362 if (dwarf_split_debug_info
)
3363 ref
->dw_loc_oprnd1
.val_entry
3364 = add_addr_table_entry (addr
,
3365 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3367 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3372 /* Section names used to hold DWARF debugging information. */
3374 #ifndef DEBUG_INFO_SECTION
3375 #define DEBUG_INFO_SECTION ".debug_info"
3377 #ifndef DEBUG_DWO_INFO_SECTION
3378 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3380 #ifndef DEBUG_ABBREV_SECTION
3381 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3383 #ifndef DEBUG_DWO_ABBREV_SECTION
3384 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3386 #ifndef DEBUG_ARANGES_SECTION
3387 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3389 #ifndef DEBUG_ADDR_SECTION
3390 #define DEBUG_ADDR_SECTION ".debug_addr"
3392 #ifndef DEBUG_NORM_MACINFO_SECTION
3393 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3395 #ifndef DEBUG_DWO_MACINFO_SECTION
3396 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3398 #ifndef DEBUG_MACINFO_SECTION
3399 #define DEBUG_MACINFO_SECTION \
3400 (!dwarf_split_debug_info \
3401 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3403 #ifndef DEBUG_NORM_MACRO_SECTION
3404 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3406 #ifndef DEBUG_DWO_MACRO_SECTION
3407 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3409 #ifndef DEBUG_MACRO_SECTION
3410 #define DEBUG_MACRO_SECTION \
3411 (!dwarf_split_debug_info \
3412 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3414 #ifndef DEBUG_LINE_SECTION
3415 #define DEBUG_LINE_SECTION ".debug_line"
3417 #ifndef DEBUG_DWO_LINE_SECTION
3418 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3420 #ifndef DEBUG_LOC_SECTION
3421 #define DEBUG_LOC_SECTION ".debug_loc"
3423 #ifndef DEBUG_DWO_LOC_SECTION
3424 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3426 #ifndef DEBUG_PUBNAMES_SECTION
3427 #define DEBUG_PUBNAMES_SECTION \
3428 ((debug_generate_pub_sections == 2) \
3429 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3431 #ifndef DEBUG_PUBTYPES_SECTION
3432 #define DEBUG_PUBTYPES_SECTION \
3433 ((debug_generate_pub_sections == 2) \
3434 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3436 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3437 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3438 #ifndef DEBUG_STR_OFFSETS_SECTION
3439 #define DEBUG_STR_OFFSETS_SECTION \
3440 (!dwarf_split_debug_info \
3441 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3443 #ifndef DEBUG_STR_DWO_SECTION
3444 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3446 #ifndef DEBUG_STR_SECTION
3447 #define DEBUG_STR_SECTION ".debug_str"
3449 #ifndef DEBUG_RANGES_SECTION
3450 #define DEBUG_RANGES_SECTION ".debug_ranges"
3453 /* Standard ELF section names for compiled code and data. */
3454 #ifndef TEXT_SECTION_NAME
3455 #define TEXT_SECTION_NAME ".text"
3458 /* Section flags for .debug_macinfo/.debug_macro section. */
3459 #define DEBUG_MACRO_SECTION_FLAGS \
3460 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3462 /* Section flags for .debug_str section. */
3463 #define DEBUG_STR_SECTION_FLAGS \
3464 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3465 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3468 /* Section flags for .debug_str.dwo section. */
3469 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3471 /* Labels we insert at beginning sections we can reference instead of
3472 the section names themselves. */
3474 #ifndef TEXT_SECTION_LABEL
3475 #define TEXT_SECTION_LABEL "Ltext"
3477 #ifndef COLD_TEXT_SECTION_LABEL
3478 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3480 #ifndef DEBUG_LINE_SECTION_LABEL
3481 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3483 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3484 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3486 #ifndef DEBUG_INFO_SECTION_LABEL
3487 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3489 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3490 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3492 #ifndef DEBUG_ABBREV_SECTION_LABEL
3493 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3495 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3496 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3498 #ifndef DEBUG_ADDR_SECTION_LABEL
3499 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3501 #ifndef DEBUG_LOC_SECTION_LABEL
3502 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3504 #ifndef DEBUG_RANGES_SECTION_LABEL
3505 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3507 #ifndef DEBUG_MACINFO_SECTION_LABEL
3508 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3510 #ifndef DEBUG_MACRO_SECTION_LABEL
3511 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3513 #define SKELETON_COMP_DIE_ABBREV 1
3514 #define SKELETON_TYPE_DIE_ABBREV 2
3516 /* Definitions of defaults for formats and names of various special
3517 (artificial) labels which may be generated within this file (when the -g
3518 options is used and DWARF2_DEBUGGING_INFO is in effect.
3519 If necessary, these may be overridden from within the tm.h file, but
3520 typically, overriding these defaults is unnecessary. */
3522 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3523 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3524 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3525 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3526 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3527 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3528 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3529 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3530 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3531 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3532 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3533 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3534 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3535 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3537 #ifndef TEXT_END_LABEL
3538 #define TEXT_END_LABEL "Letext"
3540 #ifndef COLD_END_LABEL
3541 #define COLD_END_LABEL "Letext_cold"
3543 #ifndef BLOCK_BEGIN_LABEL
3544 #define BLOCK_BEGIN_LABEL "LBB"
3546 #ifndef BLOCK_END_LABEL
3547 #define BLOCK_END_LABEL "LBE"
3549 #ifndef LINE_CODE_LABEL
3550 #define LINE_CODE_LABEL "LM"
3554 /* Return the root of the DIE's built for the current compilation unit. */
3556 comp_unit_die (void)
3558 if (!single_comp_unit_die
)
3559 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3560 return single_comp_unit_die
;
3563 /* We allow a language front-end to designate a function that is to be
3564 called to "demangle" any name before it is put into a DIE. */
3566 static const char *(*demangle_name_func
) (const char *);
3569 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3571 demangle_name_func
= func
;
3574 /* Test if rtl node points to a pseudo register. */
3577 is_pseudo_reg (const_rtx rtl
)
3579 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3580 || (GET_CODE (rtl
) == SUBREG
3581 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3584 /* Return a reference to a type, with its const and volatile qualifiers
3588 type_main_variant (tree type
)
3590 type
= TYPE_MAIN_VARIANT (type
);
3592 /* ??? There really should be only one main variant among any group of
3593 variants of a given type (and all of the MAIN_VARIANT values for all
3594 members of the group should point to that one type) but sometimes the C
3595 front-end messes this up for array types, so we work around that bug
3597 if (TREE_CODE (type
) == ARRAY_TYPE
)
3598 while (type
!= TYPE_MAIN_VARIANT (type
))
3599 type
= TYPE_MAIN_VARIANT (type
);
3604 /* Return nonzero if the given type node represents a tagged type. */
3607 is_tagged_type (const_tree type
)
3609 enum tree_code code
= TREE_CODE (type
);
3611 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3612 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3615 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3618 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3620 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3623 /* Return die_offset of a DIE reference to a base type. */
3625 static unsigned long int
3626 get_base_type_offset (dw_die_ref ref
)
3628 if (ref
->die_offset
)
3629 return ref
->die_offset
;
3630 if (comp_unit_die ()->die_abbrev
)
3632 calc_base_type_die_sizes ();
3633 gcc_assert (ref
->die_offset
);
3635 return ref
->die_offset
;
3638 /* Return die_offset of a DIE reference other than base type. */
3640 static unsigned long int
3641 get_ref_die_offset (dw_die_ref ref
)
3643 gcc_assert (ref
->die_offset
);
3644 return ref
->die_offset
;
3647 /* Convert a DIE tag into its string name. */
3650 dwarf_tag_name (unsigned int tag
)
3652 const char *name
= get_DW_TAG_name (tag
);
3657 return "DW_TAG_<unknown>";
3660 /* Convert a DWARF attribute code into its string name. */
3663 dwarf_attr_name (unsigned int attr
)
3669 #if VMS_DEBUGGING_INFO
3670 case DW_AT_HP_prologue
:
3671 return "DW_AT_HP_prologue";
3673 case DW_AT_MIPS_loop_unroll_factor
:
3674 return "DW_AT_MIPS_loop_unroll_factor";
3677 #if VMS_DEBUGGING_INFO
3678 case DW_AT_HP_epilogue
:
3679 return "DW_AT_HP_epilogue";
3681 case DW_AT_MIPS_stride
:
3682 return "DW_AT_MIPS_stride";
3686 name
= get_DW_AT_name (attr
);
3691 return "DW_AT_<unknown>";
3694 /* Convert a DWARF value form code into its string name. */
3697 dwarf_form_name (unsigned int form
)
3699 const char *name
= get_DW_FORM_name (form
);
3704 return "DW_FORM_<unknown>";
3707 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3708 instance of an inlined instance of a decl which is local to an inline
3709 function, so we have to trace all of the way back through the origin chain
3710 to find out what sort of node actually served as the original seed for the
3714 decl_ultimate_origin (const_tree decl
)
3716 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3719 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
3720 we're trying to output the abstract instance of this function. */
3721 if (DECL_ABSTRACT_P (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3724 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3725 most distant ancestor, this should never happen. */
3726 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3728 return DECL_ABSTRACT_ORIGIN (decl
);
3731 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3732 of a virtual function may refer to a base class, so we check the 'this'
3736 decl_class_context (tree decl
)
3738 tree context
= NULL_TREE
;
3740 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3741 context
= DECL_CONTEXT (decl
);
3743 context
= TYPE_MAIN_VARIANT
3744 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3746 if (context
&& !TYPE_P (context
))
3747 context
= NULL_TREE
;
3752 /* Add an attribute/value pair to a DIE. */
3755 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3757 /* Maybe this should be an assert? */
3761 vec_safe_reserve (die
->die_attr
, 1);
3762 vec_safe_push (die
->die_attr
, *attr
);
3765 static inline enum dw_val_class
3766 AT_class (dw_attr_ref a
)
3768 return a
->dw_attr_val
.val_class
;
3771 /* Return the index for any attribute that will be referenced with a
3772 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3773 are stored in dw_attr_val.v.val_str for reference counting
3776 static inline unsigned int
3777 AT_index (dw_attr_ref a
)
3779 if (AT_class (a
) == dw_val_class_str
)
3780 return a
->dw_attr_val
.v
.val_str
->index
;
3781 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3782 return a
->dw_attr_val
.val_entry
->index
;
3786 /* Add a flag value attribute to a DIE. */
3789 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3793 attr
.dw_attr
= attr_kind
;
3794 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3795 attr
.dw_attr_val
.val_entry
= NULL
;
3796 attr
.dw_attr_val
.v
.val_flag
= flag
;
3797 add_dwarf_attr (die
, &attr
);
3800 static inline unsigned
3801 AT_flag (dw_attr_ref a
)
3803 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3804 return a
->dw_attr_val
.v
.val_flag
;
3807 /* Add a signed integer attribute value to a DIE. */
3810 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3814 attr
.dw_attr
= attr_kind
;
3815 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3816 attr
.dw_attr_val
.val_entry
= NULL
;
3817 attr
.dw_attr_val
.v
.val_int
= int_val
;
3818 add_dwarf_attr (die
, &attr
);
3821 static inline HOST_WIDE_INT
3822 AT_int (dw_attr_ref a
)
3824 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3825 return a
->dw_attr_val
.v
.val_int
;
3828 /* Add an unsigned integer attribute value to a DIE. */
3831 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3832 unsigned HOST_WIDE_INT unsigned_val
)
3836 attr
.dw_attr
= attr_kind
;
3837 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3838 attr
.dw_attr_val
.val_entry
= NULL
;
3839 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3840 add_dwarf_attr (die
, &attr
);
3843 static inline unsigned HOST_WIDE_INT
3844 AT_unsigned (dw_attr_ref a
)
3846 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3847 return a
->dw_attr_val
.v
.val_unsigned
;
3850 /* Add an unsigned wide integer attribute value to a DIE. */
3853 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3858 attr
.dw_attr
= attr_kind
;
3859 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
3860 attr
.dw_attr_val
.v
.val_wide
= ggc_cleared_alloc
<wide_int
> ();
3861 *attr
.dw_attr_val
.v
.val_wide
= w
;
3862 add_dwarf_attr (die
, &attr
);
3865 /* Add an unsigned double integer attribute value to a DIE. */
3868 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3869 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3873 attr
.dw_attr
= attr_kind
;
3874 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3875 attr
.dw_attr_val
.val_entry
= NULL
;
3876 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3877 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3878 add_dwarf_attr (die
, &attr
);
3881 /* Add a floating point attribute value to a DIE and return it. */
3884 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3885 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3889 attr
.dw_attr
= attr_kind
;
3890 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3891 attr
.dw_attr_val
.val_entry
= NULL
;
3892 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3893 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3894 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3895 add_dwarf_attr (die
, &attr
);
3898 /* Add an 8-byte data attribute value to a DIE. */
3901 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3902 unsigned char data8
[8])
3906 attr
.dw_attr
= attr_kind
;
3907 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3908 attr
.dw_attr_val
.val_entry
= NULL
;
3909 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3910 add_dwarf_attr (die
, &attr
);
3913 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3914 dwarf_split_debug_info, address attributes in dies destined for the
3915 final executable have force_direct set to avoid using indexed
3919 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3925 lbl_id
= xstrdup (lbl_low
);
3926 attr
.dw_attr
= DW_AT_low_pc
;
3927 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3928 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3929 if (dwarf_split_debug_info
&& !force_direct
)
3930 attr
.dw_attr_val
.val_entry
3931 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3933 attr
.dw_attr_val
.val_entry
= NULL
;
3934 add_dwarf_attr (die
, &attr
);
3936 attr
.dw_attr
= DW_AT_high_pc
;
3937 if (dwarf_version
< 4)
3938 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3940 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3941 lbl_id
= xstrdup (lbl_high
);
3942 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3943 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3944 && dwarf_split_debug_info
&& !force_direct
)
3945 attr
.dw_attr_val
.val_entry
3946 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3948 attr
.dw_attr_val
.val_entry
= NULL
;
3949 add_dwarf_attr (die
, &attr
);
3952 /* Hash and equality functions for debug_str_hash. */
3955 indirect_string_hasher::hash (indirect_string_node
*x
)
3957 return htab_hash_string (x
->str
);
3961 indirect_string_hasher::equal (indirect_string_node
*x1
, const char *x2
)
3963 return strcmp (x1
->str
, x2
) == 0;
3966 /* Add STR to the given string hash table. */
3968 static struct indirect_string_node
*
3969 find_AT_string_in_table (const char *str
,
3970 hash_table
<indirect_string_hasher
> *table
)
3972 struct indirect_string_node
*node
;
3974 indirect_string_node
**slot
3975 = table
->find_slot_with_hash (str
, htab_hash_string (str
), INSERT
);
3978 node
= ggc_cleared_alloc
<indirect_string_node
> ();
3979 node
->str
= ggc_strdup (str
);
3989 /* Add STR to the indirect string hash table. */
3991 static struct indirect_string_node
*
3992 find_AT_string (const char *str
)
3994 if (! debug_str_hash
)
3995 debug_str_hash
= hash_table
<indirect_string_hasher
>::create_ggc (10);
3997 return find_AT_string_in_table (str
, debug_str_hash
);
4000 /* Add a string attribute value to a DIE. */
4003 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4006 struct indirect_string_node
*node
;
4008 node
= find_AT_string (str
);
4010 attr
.dw_attr
= attr_kind
;
4011 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4012 attr
.dw_attr_val
.val_entry
= NULL
;
4013 attr
.dw_attr_val
.v
.val_str
= node
;
4014 add_dwarf_attr (die
, &attr
);
4017 static inline const char *
4018 AT_string (dw_attr_ref a
)
4020 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4021 return a
->dw_attr_val
.v
.val_str
->str
;
4024 /* Call this function directly to bypass AT_string_form's logic to put
4025 the string inline in the die. */
4028 set_indirect_string (struct indirect_string_node
*node
)
4031 /* Already indirect is a no op. */
4032 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
4034 gcc_assert (node
->label
);
4037 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4038 ++dw2_string_counter
;
4039 node
->label
= xstrdup (label
);
4041 if (!dwarf_split_debug_info
)
4043 node
->form
= DW_FORM_strp
;
4044 node
->index
= NOT_INDEXED
;
4048 node
->form
= DW_FORM_GNU_str_index
;
4049 node
->index
= NO_INDEX_ASSIGNED
;
4053 /* Find out whether a string should be output inline in DIE
4054 or out-of-line in .debug_str section. */
4056 static enum dwarf_form
4057 find_string_form (struct indirect_string_node
*node
)
4064 len
= strlen (node
->str
) + 1;
4066 /* If the string is shorter or equal to the size of the reference, it is
4067 always better to put it inline. */
4068 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4069 return node
->form
= DW_FORM_string
;
4071 /* If we cannot expect the linker to merge strings in .debug_str
4072 section, only put it into .debug_str if it is worth even in this
4074 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4075 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4076 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4077 return node
->form
= DW_FORM_string
;
4079 set_indirect_string (node
);
4084 /* Find out whether the string referenced from the attribute should be
4085 output inline in DIE or out-of-line in .debug_str section. */
4087 static enum dwarf_form
4088 AT_string_form (dw_attr_ref a
)
4090 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4091 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4094 /* Add a DIE reference attribute value to a DIE. */
4097 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4101 #ifdef ENABLE_CHECKING
4102 gcc_assert (targ_die
!= NULL
);
4104 /* With LTO we can end up trying to reference something we didn't create
4105 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4106 if (targ_die
== NULL
)
4110 attr
.dw_attr
= attr_kind
;
4111 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4112 attr
.dw_attr_val
.val_entry
= NULL
;
4113 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4114 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4115 add_dwarf_attr (die
, &attr
);
4118 /* Change DIE reference REF to point to NEW_DIE instead. */
4121 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
4123 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4124 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4125 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4128 /* Add an AT_specification attribute to a DIE, and also make the back
4129 pointer from the specification to the definition. */
4132 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4134 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4135 gcc_assert (!targ_die
->die_definition
);
4136 targ_die
->die_definition
= die
;
4139 static inline dw_die_ref
4140 AT_ref (dw_attr_ref a
)
4142 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4143 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4147 AT_ref_external (dw_attr_ref a
)
4149 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4150 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4156 set_AT_ref_external (dw_attr_ref a
, int i
)
4158 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4159 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4162 /* Add an FDE reference attribute value to a DIE. */
4165 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4169 attr
.dw_attr
= attr_kind
;
4170 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4171 attr
.dw_attr_val
.val_entry
= NULL
;
4172 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4173 add_dwarf_attr (die
, &attr
);
4176 /* Add a location description attribute value to a DIE. */
4179 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4183 attr
.dw_attr
= attr_kind
;
4184 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4185 attr
.dw_attr_val
.val_entry
= NULL
;
4186 attr
.dw_attr_val
.v
.val_loc
= loc
;
4187 add_dwarf_attr (die
, &attr
);
4190 static inline dw_loc_descr_ref
4191 AT_loc (dw_attr_ref a
)
4193 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4194 return a
->dw_attr_val
.v
.val_loc
;
4198 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4202 attr
.dw_attr
= attr_kind
;
4203 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4204 attr
.dw_attr_val
.val_entry
= NULL
;
4205 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4206 add_dwarf_attr (die
, &attr
);
4207 have_location_lists
= true;
4210 static inline dw_loc_list_ref
4211 AT_loc_list (dw_attr_ref a
)
4213 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4214 return a
->dw_attr_val
.v
.val_loc_list
;
4217 static inline dw_loc_list_ref
*
4218 AT_loc_list_ptr (dw_attr_ref a
)
4220 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4221 return &a
->dw_attr_val
.v
.val_loc_list
;
4224 struct addr_hasher
: ggc_hasher
<addr_table_entry
*>
4226 static hashval_t
hash (addr_table_entry
*);
4227 static bool equal (addr_table_entry
*, addr_table_entry
*);
4230 /* Table of entries into the .debug_addr section. */
4232 static GTY (()) hash_table
<addr_hasher
> *addr_index_table
;
4234 /* Hash an address_table_entry. */
4237 addr_hasher::hash (addr_table_entry
*a
)
4239 inchash::hash hstate
;
4245 case ate_kind_rtx_dtprel
:
4248 case ate_kind_label
:
4249 return htab_hash_string (a
->addr
.label
);
4253 inchash::add_rtx (a
->addr
.rtl
, hstate
);
4254 return hstate
.end ();
4257 /* Determine equality for two address_table_entries. */
4260 addr_hasher::equal (addr_table_entry
*a1
, addr_table_entry
*a2
)
4262 if (a1
->kind
!= a2
->kind
)
4267 case ate_kind_rtx_dtprel
:
4268 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4269 case ate_kind_label
:
4270 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4276 /* Initialize an addr_table_entry. */
4279 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4285 case ate_kind_rtx_dtprel
:
4286 e
->addr
.rtl
= (rtx
) addr
;
4288 case ate_kind_label
:
4289 e
->addr
.label
= (char *) addr
;
4293 e
->index
= NO_INDEX_ASSIGNED
;
4296 /* Add attr to the address table entry to the table. Defer setting an
4297 index until output time. */
4299 static addr_table_entry
*
4300 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4302 addr_table_entry
*node
;
4303 addr_table_entry finder
;
4305 gcc_assert (dwarf_split_debug_info
);
4306 if (! addr_index_table
)
4307 addr_index_table
= hash_table
<addr_hasher
>::create_ggc (10);
4308 init_addr_table_entry (&finder
, kind
, addr
);
4309 addr_table_entry
**slot
= addr_index_table
->find_slot (&finder
, INSERT
);
4311 if (*slot
== HTAB_EMPTY_ENTRY
)
4313 node
= ggc_cleared_alloc
<addr_table_entry
> ();
4314 init_addr_table_entry (node
, kind
, addr
);
4324 /* Remove an entry from the addr table by decrementing its refcount.
4325 Strictly, decrementing the refcount would be enough, but the
4326 assertion that the entry is actually in the table has found
4330 remove_addr_table_entry (addr_table_entry
*entry
)
4332 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4333 /* After an index is assigned, the table is frozen. */
4334 gcc_assert (entry
->refcount
> 0 && entry
->index
== NO_INDEX_ASSIGNED
);
4338 /* Given a location list, remove all addresses it refers to from the
4342 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4344 for (; descr
; descr
= descr
->dw_loc_next
)
4345 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4347 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4348 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4352 /* A helper function for dwarf2out_finish called through
4353 htab_traverse. Assign an addr_table_entry its index. All entries
4354 must be collected into the table when this function is called,
4355 because the indexing code relies on htab_traverse to traverse nodes
4356 in the same order for each run. */
4359 index_addr_table_entry (addr_table_entry
**h
, unsigned int *index
)
4361 addr_table_entry
*node
= *h
;
4363 /* Don't index unreferenced nodes. */
4364 if (node
->refcount
== 0)
4367 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4368 node
->index
= *index
;
4374 /* Add an address constant attribute value to a DIE. When using
4375 dwarf_split_debug_info, address attributes in dies destined for the
4376 final executable should be direct references--setting the parameter
4377 force_direct ensures this behavior. */
4380 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4385 attr
.dw_attr
= attr_kind
;
4386 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4387 attr
.dw_attr_val
.v
.val_addr
= addr
;
4388 if (dwarf_split_debug_info
&& !force_direct
)
4389 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4391 attr
.dw_attr_val
.val_entry
= NULL
;
4392 add_dwarf_attr (die
, &attr
);
4395 /* Get the RTX from to an address DIE attribute. */
4398 AT_addr (dw_attr_ref a
)
4400 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4401 return a
->dw_attr_val
.v
.val_addr
;
4404 /* Add a file attribute value to a DIE. */
4407 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4408 struct dwarf_file_data
*fd
)
4412 attr
.dw_attr
= attr_kind
;
4413 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4414 attr
.dw_attr_val
.val_entry
= NULL
;
4415 attr
.dw_attr_val
.v
.val_file
= fd
;
4416 add_dwarf_attr (die
, &attr
);
4419 /* Get the dwarf_file_data from a file DIE attribute. */
4421 static inline struct dwarf_file_data
*
4422 AT_file (dw_attr_ref a
)
4424 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4425 return a
->dw_attr_val
.v
.val_file
;
4428 /* Add a vms delta attribute value to a DIE. */
4431 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4432 const char *lbl1
, const char *lbl2
)
4436 attr
.dw_attr
= attr_kind
;
4437 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4438 attr
.dw_attr_val
.val_entry
= NULL
;
4439 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4440 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4441 add_dwarf_attr (die
, &attr
);
4444 /* Add a label identifier attribute value to a DIE. */
4447 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4452 attr
.dw_attr
= attr_kind
;
4453 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4454 attr
.dw_attr_val
.val_entry
= NULL
;
4455 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4456 if (dwarf_split_debug_info
)
4457 attr
.dw_attr_val
.val_entry
4458 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4460 add_dwarf_attr (die
, &attr
);
4463 /* Add a section offset attribute value to a DIE, an offset into the
4464 debug_line section. */
4467 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4472 attr
.dw_attr
= attr_kind
;
4473 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4474 attr
.dw_attr_val
.val_entry
= NULL
;
4475 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4476 add_dwarf_attr (die
, &attr
);
4479 /* Add a section offset attribute value to a DIE, an offset into the
4480 debug_macinfo section. */
4483 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4488 attr
.dw_attr
= attr_kind
;
4489 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4490 attr
.dw_attr_val
.val_entry
= NULL
;
4491 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4492 add_dwarf_attr (die
, &attr
);
4495 /* Add an offset attribute value to a DIE. */
4498 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4499 unsigned HOST_WIDE_INT offset
)
4503 attr
.dw_attr
= attr_kind
;
4504 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4505 attr
.dw_attr_val
.val_entry
= NULL
;
4506 attr
.dw_attr_val
.v
.val_offset
= offset
;
4507 add_dwarf_attr (die
, &attr
);
4510 /* Add a range_list attribute value to a DIE. When using
4511 dwarf_split_debug_info, address attributes in dies destined for the
4512 final executable should be direct references--setting the parameter
4513 force_direct ensures this behavior. */
4515 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4516 #define RELOCATED_OFFSET (NULL)
4519 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4520 long unsigned int offset
, bool force_direct
)
4524 attr
.dw_attr
= attr_kind
;
4525 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4526 /* For the range_list attribute, use val_entry to store whether the
4527 offset should follow split-debug-info or normal semantics. This
4528 value is read in output_range_list_offset. */
4529 if (dwarf_split_debug_info
&& !force_direct
)
4530 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4532 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4533 attr
.dw_attr_val
.v
.val_offset
= offset
;
4534 add_dwarf_attr (die
, &attr
);
4537 /* Return the start label of a delta attribute. */
4539 static inline const char *
4540 AT_vms_delta1 (dw_attr_ref a
)
4542 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4543 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4546 /* Return the end label of a delta attribute. */
4548 static inline const char *
4549 AT_vms_delta2 (dw_attr_ref a
)
4551 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4552 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4555 static inline const char *
4556 AT_lbl (dw_attr_ref a
)
4558 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4559 || AT_class (a
) == dw_val_class_lineptr
4560 || AT_class (a
) == dw_val_class_macptr
4561 || AT_class (a
) == dw_val_class_high_pc
));
4562 return a
->dw_attr_val
.v
.val_lbl_id
;
4565 /* Get the attribute of type attr_kind. */
4568 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4572 dw_die_ref spec
= NULL
;
4577 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4578 if (a
->dw_attr
== attr_kind
)
4580 else if (a
->dw_attr
== DW_AT_specification
4581 || a
->dw_attr
== DW_AT_abstract_origin
)
4585 return get_AT (spec
, attr_kind
);
4590 /* Returns the parent of the declaration of DIE. */
4593 get_die_parent (dw_die_ref die
)
4600 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4601 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4604 return die
->die_parent
;
4607 /* Return the "low pc" attribute value, typically associated with a subprogram
4608 DIE. Return null if the "low pc" attribute is either not present, or if it
4609 cannot be represented as an assembler label identifier. */
4611 static inline const char *
4612 get_AT_low_pc (dw_die_ref die
)
4614 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4616 return a
? AT_lbl (a
) : NULL
;
4619 /* Return the "high pc" attribute value, typically associated with a subprogram
4620 DIE. Return null if the "high pc" attribute is either not present, or if it
4621 cannot be represented as an assembler label identifier. */
4623 static inline const char *
4624 get_AT_hi_pc (dw_die_ref die
)
4626 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4628 return a
? AT_lbl (a
) : NULL
;
4631 /* Return the value of the string attribute designated by ATTR_KIND, or
4632 NULL if it is not present. */
4634 static inline const char *
4635 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4637 dw_attr_ref a
= get_AT (die
, attr_kind
);
4639 return a
? AT_string (a
) : NULL
;
4642 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4643 if it is not present. */
4646 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4648 dw_attr_ref a
= get_AT (die
, attr_kind
);
4650 return a
? AT_flag (a
) : 0;
4653 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4654 if it is not present. */
4656 static inline unsigned
4657 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4659 dw_attr_ref a
= get_AT (die
, attr_kind
);
4661 return a
? AT_unsigned (a
) : 0;
4664 static inline dw_die_ref
4665 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4667 dw_attr_ref a
= get_AT (die
, attr_kind
);
4669 return a
? AT_ref (a
) : NULL
;
4672 static inline struct dwarf_file_data
*
4673 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4675 dw_attr_ref a
= get_AT (die
, attr_kind
);
4677 return a
? AT_file (a
) : NULL
;
4680 /* Return TRUE if the language is C++. */
4685 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4687 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4690 /* Return TRUE if the language is Java. */
4695 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4697 return lang
== DW_LANG_Java
;
4700 /* Return TRUE if the language is Fortran. */
4705 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4707 return (lang
== DW_LANG_Fortran77
4708 || lang
== DW_LANG_Fortran90
4709 || lang
== DW_LANG_Fortran95
);
4712 /* Return TRUE if the language is Ada. */
4717 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4719 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4722 /* Remove the specified attribute if present. */
4725 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4733 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4734 if (a
->dw_attr
== attr_kind
)
4736 if (AT_class (a
) == dw_val_class_str
)
4737 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4738 a
->dw_attr_val
.v
.val_str
->refcount
--;
4740 /* vec::ordered_remove should help reduce the number of abbrevs
4742 die
->die_attr
->ordered_remove (ix
);
4747 /* Remove CHILD from its parent. PREV must have the property that
4748 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4751 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4753 gcc_assert (child
->die_parent
== prev
->die_parent
);
4754 gcc_assert (prev
->die_sib
== child
);
4757 gcc_assert (child
->die_parent
->die_child
== child
);
4761 prev
->die_sib
= child
->die_sib
;
4762 if (child
->die_parent
->die_child
== child
)
4763 child
->die_parent
->die_child
= prev
;
4766 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4767 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4770 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4772 dw_die_ref parent
= old_child
->die_parent
;
4774 gcc_assert (parent
== prev
->die_parent
);
4775 gcc_assert (prev
->die_sib
== old_child
);
4777 new_child
->die_parent
= parent
;
4778 if (prev
== old_child
)
4780 gcc_assert (parent
->die_child
== old_child
);
4781 new_child
->die_sib
= new_child
;
4785 prev
->die_sib
= new_child
;
4786 new_child
->die_sib
= old_child
->die_sib
;
4788 if (old_child
->die_parent
->die_child
== old_child
)
4789 old_child
->die_parent
->die_child
= new_child
;
4792 /* Move all children from OLD_PARENT to NEW_PARENT. */
4795 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4798 new_parent
->die_child
= old_parent
->die_child
;
4799 old_parent
->die_child
= NULL
;
4800 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4803 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4807 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4813 dw_die_ref prev
= c
;
4815 while (c
->die_tag
== tag
)
4817 remove_child_with_prev (c
, prev
);
4818 /* Might have removed every child. */
4819 if (c
== c
->die_sib
)
4823 } while (c
!= die
->die_child
);
4826 /* Add a CHILD_DIE as the last child of DIE. */
4829 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4831 /* FIXME this should probably be an assert. */
4832 if (! die
|| ! child_die
)
4834 gcc_assert (die
!= child_die
);
4836 child_die
->die_parent
= die
;
4839 child_die
->die_sib
= die
->die_child
->die_sib
;
4840 die
->die_child
->die_sib
= child_die
;
4843 child_die
->die_sib
= child_die
;
4844 die
->die_child
= child_die
;
4847 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4848 is the specification, to the end of PARENT's list of children.
4849 This is done by removing and re-adding it. */
4852 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4856 /* We want the declaration DIE from inside the class, not the
4857 specification DIE at toplevel. */
4858 if (child
->die_parent
!= parent
)
4860 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4866 gcc_assert (child
->die_parent
== parent
4867 || (child
->die_parent
4868 == get_AT_ref (parent
, DW_AT_specification
)));
4870 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4871 if (p
->die_sib
== child
)
4873 remove_child_with_prev (child
, p
);
4877 add_child_die (parent
, child
);
4880 /* Return a pointer to a newly created DIE node. */
4882 static inline dw_die_ref
4883 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4885 dw_die_ref die
= ggc_cleared_alloc
<die_node
> ();
4887 die
->die_tag
= tag_value
;
4889 if (parent_die
!= NULL
)
4890 add_child_die (parent_die
, die
);
4893 limbo_die_node
*limbo_node
;
4895 limbo_node
= ggc_cleared_alloc
<limbo_die_node
> ();
4896 limbo_node
->die
= die
;
4897 limbo_node
->created_for
= t
;
4898 limbo_node
->next
= limbo_die_list
;
4899 limbo_die_list
= limbo_node
;
4905 /* Return the DIE associated with the given type specifier. */
4907 static inline dw_die_ref
4908 lookup_type_die (tree type
)
4910 return TYPE_SYMTAB_DIE (type
);
4913 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4914 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4915 anonymous type instead the one of the naming typedef. */
4917 static inline dw_die_ref
4918 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4921 && TREE_CODE (type
) == RECORD_TYPE
4923 && type_die
->die_tag
== DW_TAG_typedef
4924 && is_naming_typedef_decl (TYPE_NAME (type
)))
4925 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4929 /* Like lookup_type_die, but if type is an anonymous type named by a
4930 typedef[1], return the DIE of the anonymous type instead the one of
4931 the naming typedef. This is because in gen_typedef_die, we did
4932 equate the anonymous struct named by the typedef with the DIE of
4933 the naming typedef. So by default, lookup_type_die on an anonymous
4934 struct yields the DIE of the naming typedef.
4936 [1]: Read the comment of is_naming_typedef_decl to learn about what
4937 a naming typedef is. */
4939 static inline dw_die_ref
4940 lookup_type_die_strip_naming_typedef (tree type
)
4942 dw_die_ref die
= lookup_type_die (type
);
4943 return strip_naming_typedef (type
, die
);
4946 /* Equate a DIE to a given type specifier. */
4949 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
4951 TYPE_SYMTAB_DIE (type
) = type_die
;
4954 /* Returns a hash value for X (which really is a die_struct). */
4957 decl_die_hasher::hash (die_node
*x
)
4959 return (hashval_t
) x
->decl_id
;
4962 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
4965 decl_die_hasher::equal (die_node
*x
, tree y
)
4967 return (x
->decl_id
== DECL_UID (y
));
4970 /* Return the DIE associated with a given declaration. */
4972 static inline dw_die_ref
4973 lookup_decl_die (tree decl
)
4975 return decl_die_table
->find_with_hash (decl
, DECL_UID (decl
));
4978 /* Returns a hash value for X (which really is a var_loc_list). */
4981 decl_loc_hasher::hash (var_loc_list
*x
)
4983 return (hashval_t
) x
->decl_id
;
4986 /* Return nonzero if decl_id of var_loc_list X is the same as
4990 decl_loc_hasher::equal (var_loc_list
*x
, const_tree y
)
4992 return (x
->decl_id
== DECL_UID (y
));
4995 /* Return the var_loc list associated with a given declaration. */
4997 static inline var_loc_list
*
4998 lookup_decl_loc (const_tree decl
)
5000 if (!decl_loc_table
)
5002 return decl_loc_table
->find_with_hash (decl
, DECL_UID (decl
));
5005 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5008 dw_loc_list_hasher::hash (cached_dw_loc_list
*x
)
5010 return (hashval_t
) x
->decl_id
;
5013 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5017 dw_loc_list_hasher::equal (cached_dw_loc_list
*x
, const_tree y
)
5019 return (x
->decl_id
== DECL_UID (y
));
5022 /* Equate a DIE to a particular declaration. */
5025 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5027 unsigned int decl_id
= DECL_UID (decl
);
5029 *decl_die_table
->find_slot_with_hash (decl
, decl_id
, INSERT
) = decl_die
;
5030 decl_die
->decl_id
= decl_id
;
5033 /* Return how many bits covers PIECE EXPR_LIST. */
5036 decl_piece_bitsize (rtx piece
)
5038 int ret
= (int) GET_MODE (piece
);
5041 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
5042 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5043 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5046 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5049 decl_piece_varloc_ptr (rtx piece
)
5051 if ((int) GET_MODE (piece
))
5052 return &XEXP (piece
, 0);
5054 return &XEXP (XEXP (piece
, 0), 1);
5057 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5058 Next is the chain of following piece nodes. */
5060 static rtx_expr_list
*
5061 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5063 if (bitsize
<= (int) MAX_MACHINE_MODE
)
5064 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5066 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5071 /* Return rtx that should be stored into loc field for
5072 LOC_NOTE and BITPOS/BITSIZE. */
5075 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5076 HOST_WIDE_INT bitsize
)
5080 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5082 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5087 /* This function either modifies location piece list *DEST in
5088 place (if SRC and INNER is NULL), or copies location piece list
5089 *SRC to *DEST while modifying it. Location BITPOS is modified
5090 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5091 not copied and if needed some padding around it is added.
5092 When modifying in place, DEST should point to EXPR_LIST where
5093 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5094 to the start of the whole list and INNER points to the EXPR_LIST
5095 where earlier pieces cover PIECE_BITPOS bits. */
5098 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5099 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5100 HOST_WIDE_INT bitsize
, rtx loc_note
)
5103 bool copy
= inner
!= NULL
;
5107 /* First copy all nodes preceding the current bitpos. */
5108 while (src
!= inner
)
5110 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5111 decl_piece_bitsize (*src
), NULL_RTX
);
5112 dest
= &XEXP (*dest
, 1);
5113 src
= &XEXP (*src
, 1);
5116 /* Add padding if needed. */
5117 if (bitpos
!= piece_bitpos
)
5119 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5120 copy
? NULL_RTX
: *dest
);
5121 dest
= &XEXP (*dest
, 1);
5123 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5126 /* A piece with correct bitpos and bitsize already exist,
5127 just update the location for it and return. */
5128 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5131 /* Add the piece that changed. */
5132 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5133 dest
= &XEXP (*dest
, 1);
5134 /* Skip over pieces that overlap it. */
5135 diff
= bitpos
- piece_bitpos
+ bitsize
;
5138 while (diff
> 0 && *src
)
5141 diff
-= decl_piece_bitsize (piece
);
5143 src
= &XEXP (piece
, 1);
5146 *src
= XEXP (piece
, 1);
5147 free_EXPR_LIST_node (piece
);
5150 /* Add padding if needed. */
5151 if (diff
< 0 && *src
)
5155 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5156 dest
= &XEXP (*dest
, 1);
5160 /* Finally copy all nodes following it. */
5163 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5164 decl_piece_bitsize (*src
), NULL_RTX
);
5165 dest
= &XEXP (*dest
, 1);
5166 src
= &XEXP (*src
, 1);
5170 /* Add a variable location node to the linked list for DECL. */
5172 static struct var_loc_node
*
5173 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5175 unsigned int decl_id
;
5177 struct var_loc_node
*loc
= NULL
;
5178 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5180 if (TREE_CODE (decl
) == VAR_DECL
5181 && DECL_HAS_DEBUG_EXPR_P (decl
))
5183 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5184 if (handled_component_p (realdecl
)
5185 || (TREE_CODE (realdecl
) == MEM_REF
5186 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5188 HOST_WIDE_INT maxsize
;
5191 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
,
5193 if (!DECL_P (innerdecl
)
5194 || DECL_IGNORED_P (innerdecl
)
5195 || TREE_STATIC (innerdecl
)
5197 || bitpos
+ bitsize
> 256
5198 || bitsize
!= maxsize
)
5204 decl_id
= DECL_UID (decl
);
5206 = decl_loc_table
->find_slot_with_hash (decl
, decl_id
, INSERT
);
5209 temp
= ggc_cleared_alloc
<var_loc_list
> ();
5210 temp
->decl_id
= decl_id
;
5216 /* For PARM_DECLs try to keep around the original incoming value,
5217 even if that means we'll emit a zero-range .debug_loc entry. */
5219 && temp
->first
== temp
->last
5220 && TREE_CODE (decl
) == PARM_DECL
5221 && NOTE_P (temp
->first
->loc
)
5222 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5223 && DECL_INCOMING_RTL (decl
)
5224 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5225 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5226 == GET_CODE (DECL_INCOMING_RTL (decl
))
5227 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5229 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5230 NOTE_VAR_LOCATION_LOC (loc_note
))
5231 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5232 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5234 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5235 temp
->first
->next
= loc
;
5237 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5239 else if (temp
->last
)
5241 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5242 rtx
*piece_loc
= NULL
, last_loc_note
;
5243 int piece_bitpos
= 0;
5247 gcc_assert (last
->next
== NULL
);
5249 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5251 piece_loc
= &last
->loc
;
5254 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5255 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5257 piece_bitpos
+= cur_bitsize
;
5258 piece_loc
= &XEXP (*piece_loc
, 1);
5262 /* TEMP->LAST here is either pointer to the last but one or
5263 last element in the chained list, LAST is pointer to the
5265 if (label
&& strcmp (last
->label
, label
) == 0)
5267 /* For SRA optimized variables if there weren't any real
5268 insns since last note, just modify the last node. */
5269 if (piece_loc
!= NULL
)
5271 adjust_piece_list (piece_loc
, NULL
, NULL
,
5272 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5275 /* If the last note doesn't cover any instructions, remove it. */
5276 if (temp
->last
!= last
)
5278 temp
->last
->next
= NULL
;
5281 gcc_assert (strcmp (last
->label
, label
) != 0);
5285 gcc_assert (temp
->first
== temp
->last
5286 || (temp
->first
->next
== temp
->last
5287 && TREE_CODE (decl
) == PARM_DECL
));
5288 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5289 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5293 if (bitsize
== -1 && NOTE_P (last
->loc
))
5294 last_loc_note
= last
->loc
;
5295 else if (piece_loc
!= NULL
5296 && *piece_loc
!= NULL_RTX
5297 && piece_bitpos
== bitpos
5298 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5299 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5301 last_loc_note
= NULL_RTX
;
5302 /* If the current location is the same as the end of the list,
5303 and either both or neither of the locations is uninitialized,
5304 we have nothing to do. */
5305 if (last_loc_note
== NULL_RTX
5306 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5307 NOTE_VAR_LOCATION_LOC (loc_note
)))
5308 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5309 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5310 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5311 == VAR_INIT_STATUS_UNINITIALIZED
)
5312 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5313 == VAR_INIT_STATUS_UNINITIALIZED
))))
5315 /* Add LOC to the end of list and update LAST. If the last
5316 element of the list has been removed above, reuse its
5317 memory for the new node, otherwise allocate a new one. */
5321 memset (loc
, '\0', sizeof (*loc
));
5324 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5325 if (bitsize
== -1 || piece_loc
== NULL
)
5326 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5328 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5329 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5331 /* Ensure TEMP->LAST will point either to the new last but one
5332 element of the chain, or to the last element in it. */
5333 if (last
!= temp
->last
)
5341 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5344 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5349 /* Keep track of the number of spaces used to indent the
5350 output of the debugging routines that print the structure of
5351 the DIE internal representation. */
5352 static int print_indent
;
5354 /* Indent the line the number of spaces given by print_indent. */
5357 print_spaces (FILE *outfile
)
5359 fprintf (outfile
, "%*s", print_indent
, "");
5362 /* Print a type signature in hex. */
5365 print_signature (FILE *outfile
, char *sig
)
5369 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5370 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5373 /* Print the information associated with a given DIE, and its children.
5374 This routine is a debugging aid only. */
5377 print_die (dw_die_ref die
, FILE *outfile
)
5383 print_spaces (outfile
);
5384 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5385 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5387 print_spaces (outfile
);
5388 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5389 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5390 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5392 if (die
->comdat_type_p
)
5394 print_spaces (outfile
);
5395 fprintf (outfile
, " signature: ");
5396 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5397 fprintf (outfile
, "\n");
5400 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5402 print_spaces (outfile
);
5403 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5405 switch (AT_class (a
))
5407 case dw_val_class_addr
:
5408 fprintf (outfile
, "address");
5410 case dw_val_class_offset
:
5411 fprintf (outfile
, "offset");
5413 case dw_val_class_loc
:
5414 fprintf (outfile
, "location descriptor");
5416 case dw_val_class_loc_list
:
5417 fprintf (outfile
, "location list -> label:%s",
5418 AT_loc_list (a
)->ll_symbol
);
5420 case dw_val_class_range_list
:
5421 fprintf (outfile
, "range list");
5423 case dw_val_class_const
:
5424 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5426 case dw_val_class_unsigned_const
:
5427 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5429 case dw_val_class_const_double
:
5430 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
5431 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5432 a
->dw_attr_val
.v
.val_double
.high
,
5433 a
->dw_attr_val
.v
.val_double
.low
);
5435 case dw_val_class_wide_int
:
5437 int i
= a
->dw_attr_val
.v
.val_wide
->get_len ();
5438 fprintf (outfile
, "constant (");
5440 if (a
->dw_attr_val
.v
.val_wide
->elt (i
- 1) == 0)
5441 fprintf (outfile
, "0x");
5442 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
5443 a
->dw_attr_val
.v
.val_wide
->elt (--i
));
5445 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
5446 a
->dw_attr_val
.v
.val_wide
->elt (i
));
5447 fprintf (outfile
, ")");
5450 case dw_val_class_vec
:
5451 fprintf (outfile
, "floating-point or vector constant");
5453 case dw_val_class_flag
:
5454 fprintf (outfile
, "%u", AT_flag (a
));
5456 case dw_val_class_die_ref
:
5457 if (AT_ref (a
) != NULL
)
5459 if (AT_ref (a
)->comdat_type_p
)
5461 fprintf (outfile
, "die -> signature: ");
5462 print_signature (outfile
,
5463 AT_ref (a
)->die_id
.die_type_node
->signature
);
5465 else if (AT_ref (a
)->die_id
.die_symbol
)
5466 fprintf (outfile
, "die -> label: %s",
5467 AT_ref (a
)->die_id
.die_symbol
);
5469 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
5470 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
5473 fprintf (outfile
, "die -> <null>");
5475 case dw_val_class_vms_delta
:
5476 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5477 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
5479 case dw_val_class_lbl_id
:
5480 case dw_val_class_lineptr
:
5481 case dw_val_class_macptr
:
5482 case dw_val_class_high_pc
:
5483 fprintf (outfile
, "label: %s", AT_lbl (a
));
5485 case dw_val_class_str
:
5486 if (AT_string (a
) != NULL
)
5487 fprintf (outfile
, "\"%s\"", AT_string (a
));
5489 fprintf (outfile
, "<null>");
5491 case dw_val_class_file
:
5492 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
5493 AT_file (a
)->emitted_number
);
5495 case dw_val_class_data8
:
5499 for (i
= 0; i
< 8; i
++)
5500 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
5507 fprintf (outfile
, "\n");
5510 if (die
->die_child
!= NULL
)
5513 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5516 if (print_indent
== 0)
5517 fprintf (outfile
, "\n");
5520 /* Print the information collected for a given DIE. */
5523 debug_dwarf_die (dw_die_ref die
)
5525 print_die (die
, stderr
);
5529 debug (die_struct
&ref
)
5531 print_die (&ref
, stderr
);
5535 debug (die_struct
*ptr
)
5540 fprintf (stderr
, "<nil>\n");
5544 /* Print all DWARF information collected for the compilation unit.
5545 This routine is a debugging aid only. */
5551 print_die (comp_unit_die (), stderr
);
5554 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5555 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5556 DIE that marks the start of the DIEs for this include file. */
5559 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5561 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5562 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5564 new_unit
->die_sib
= old_unit
;
5568 /* Close an include-file CU and reopen the enclosing one. */
5571 pop_compile_unit (dw_die_ref old_unit
)
5573 dw_die_ref new_unit
= old_unit
->die_sib
;
5575 old_unit
->die_sib
= NULL
;
5579 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5580 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5581 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5583 /* Calculate the checksum of a location expression. */
5586 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5589 inchash::hash hstate
;
5592 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5594 hash_loc_operands (loc
, hstate
);
5595 hash
= hstate
.end();
5599 /* Calculate the checksum of an attribute. */
5602 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5604 dw_loc_descr_ref loc
;
5607 CHECKSUM (at
->dw_attr
);
5609 /* We don't care that this was compiled with a different compiler
5610 snapshot; if the output is the same, that's what matters. */
5611 if (at
->dw_attr
== DW_AT_producer
)
5614 switch (AT_class (at
))
5616 case dw_val_class_const
:
5617 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5619 case dw_val_class_unsigned_const
:
5620 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5622 case dw_val_class_const_double
:
5623 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5625 case dw_val_class_wide_int
:
5626 CHECKSUM (*at
->dw_attr_val
.v
.val_wide
);
5628 case dw_val_class_vec
:
5629 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5630 (at
->dw_attr_val
.v
.val_vec
.length
5631 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5633 case dw_val_class_flag
:
5634 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5636 case dw_val_class_str
:
5637 CHECKSUM_STRING (AT_string (at
));
5640 case dw_val_class_addr
:
5642 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5643 CHECKSUM_STRING (XSTR (r
, 0));
5646 case dw_val_class_offset
:
5647 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5650 case dw_val_class_loc
:
5651 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5652 loc_checksum (loc
, ctx
);
5655 case dw_val_class_die_ref
:
5656 die_checksum (AT_ref (at
), ctx
, mark
);
5659 case dw_val_class_fde_ref
:
5660 case dw_val_class_vms_delta
:
5661 case dw_val_class_lbl_id
:
5662 case dw_val_class_lineptr
:
5663 case dw_val_class_macptr
:
5664 case dw_val_class_high_pc
:
5667 case dw_val_class_file
:
5668 CHECKSUM_STRING (AT_file (at
)->filename
);
5671 case dw_val_class_data8
:
5672 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5680 /* Calculate the checksum of a DIE. */
5683 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5689 /* To avoid infinite recursion. */
5692 CHECKSUM (die
->die_mark
);
5695 die
->die_mark
= ++(*mark
);
5697 CHECKSUM (die
->die_tag
);
5699 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5700 attr_checksum (a
, ctx
, mark
);
5702 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5706 #undef CHECKSUM_BLOCK
5707 #undef CHECKSUM_STRING
5709 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5710 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5711 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5712 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5713 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5714 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5715 #define CHECKSUM_ATTR(FOO) \
5716 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5718 /* Calculate the checksum of a number in signed LEB128 format. */
5721 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5728 byte
= (value
& 0x7f);
5730 more
= !((value
== 0 && (byte
& 0x40) == 0)
5731 || (value
== -1 && (byte
& 0x40) != 0));
5740 /* Calculate the checksum of a number in unsigned LEB128 format. */
5743 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5747 unsigned char byte
= (value
& 0x7f);
5750 /* More bytes to follow. */
5758 /* Checksum the context of the DIE. This adds the names of any
5759 surrounding namespaces or structures to the checksum. */
5762 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5766 int tag
= die
->die_tag
;
5768 if (tag
!= DW_TAG_namespace
5769 && tag
!= DW_TAG_structure_type
5770 && tag
!= DW_TAG_class_type
)
5773 name
= get_AT_string (die
, DW_AT_name
);
5775 spec
= get_AT_ref (die
, DW_AT_specification
);
5779 if (die
->die_parent
!= NULL
)
5780 checksum_die_context (die
->die_parent
, ctx
);
5782 CHECKSUM_ULEB128 ('C');
5783 CHECKSUM_ULEB128 (tag
);
5785 CHECKSUM_STRING (name
);
5788 /* Calculate the checksum of a location expression. */
5791 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5793 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5794 were emitted as a DW_FORM_sdata instead of a location expression. */
5795 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5797 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5798 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5802 /* Otherwise, just checksum the raw location expression. */
5805 inchash::hash hstate
;
5808 CHECKSUM_ULEB128 (loc
->dtprel
);
5809 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5810 hash_loc_operands (loc
, hstate
);
5811 hash
= hstate
.end ();
5813 loc
= loc
->dw_loc_next
;
5817 /* Calculate the checksum of an attribute. */
5820 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5821 struct md5_ctx
*ctx
, int *mark
)
5823 dw_loc_descr_ref loc
;
5826 if (AT_class (at
) == dw_val_class_die_ref
)
5828 dw_die_ref target_die
= AT_ref (at
);
5830 /* For pointer and reference types, we checksum only the (qualified)
5831 name of the target type (if there is a name). For friend entries,
5832 we checksum only the (qualified) name of the target type or function.
5833 This allows the checksum to remain the same whether the target type
5834 is complete or not. */
5835 if ((at
->dw_attr
== DW_AT_type
5836 && (tag
== DW_TAG_pointer_type
5837 || tag
== DW_TAG_reference_type
5838 || tag
== DW_TAG_rvalue_reference_type
5839 || tag
== DW_TAG_ptr_to_member_type
))
5840 || (at
->dw_attr
== DW_AT_friend
5841 && tag
== DW_TAG_friend
))
5843 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5845 if (name_attr
!= NULL
)
5847 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5851 CHECKSUM_ULEB128 ('N');
5852 CHECKSUM_ULEB128 (at
->dw_attr
);
5853 if (decl
->die_parent
!= NULL
)
5854 checksum_die_context (decl
->die_parent
, ctx
);
5855 CHECKSUM_ULEB128 ('E');
5856 CHECKSUM_STRING (AT_string (name_attr
));
5861 /* For all other references to another DIE, we check to see if the
5862 target DIE has already been visited. If it has, we emit a
5863 backward reference; if not, we descend recursively. */
5864 if (target_die
->die_mark
> 0)
5866 CHECKSUM_ULEB128 ('R');
5867 CHECKSUM_ULEB128 (at
->dw_attr
);
5868 CHECKSUM_ULEB128 (target_die
->die_mark
);
5872 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5876 target_die
->die_mark
= ++(*mark
);
5877 CHECKSUM_ULEB128 ('T');
5878 CHECKSUM_ULEB128 (at
->dw_attr
);
5879 if (decl
->die_parent
!= NULL
)
5880 checksum_die_context (decl
->die_parent
, ctx
);
5881 die_checksum_ordered (target_die
, ctx
, mark
);
5886 CHECKSUM_ULEB128 ('A');
5887 CHECKSUM_ULEB128 (at
->dw_attr
);
5889 switch (AT_class (at
))
5891 case dw_val_class_const
:
5892 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5893 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5896 case dw_val_class_unsigned_const
:
5897 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5898 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5901 case dw_val_class_const_double
:
5902 CHECKSUM_ULEB128 (DW_FORM_block
);
5903 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5904 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5907 case dw_val_class_wide_int
:
5908 CHECKSUM_ULEB128 (DW_FORM_block
);
5909 CHECKSUM_ULEB128 (sizeof (*at
->dw_attr_val
.v
.val_wide
));
5910 CHECKSUM (*at
->dw_attr_val
.v
.val_wide
);
5913 case dw_val_class_vec
:
5914 CHECKSUM_ULEB128 (DW_FORM_block
);
5915 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
5916 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
5917 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5918 (at
->dw_attr_val
.v
.val_vec
.length
5919 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5922 case dw_val_class_flag
:
5923 CHECKSUM_ULEB128 (DW_FORM_flag
);
5924 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
5927 case dw_val_class_str
:
5928 CHECKSUM_ULEB128 (DW_FORM_string
);
5929 CHECKSUM_STRING (AT_string (at
));
5932 case dw_val_class_addr
:
5934 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5935 CHECKSUM_ULEB128 (DW_FORM_string
);
5936 CHECKSUM_STRING (XSTR (r
, 0));
5939 case dw_val_class_offset
:
5940 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5941 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
5944 case dw_val_class_loc
:
5945 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5946 loc_checksum_ordered (loc
, ctx
);
5949 case dw_val_class_fde_ref
:
5950 case dw_val_class_lbl_id
:
5951 case dw_val_class_lineptr
:
5952 case dw_val_class_macptr
:
5953 case dw_val_class_high_pc
:
5956 case dw_val_class_file
:
5957 CHECKSUM_ULEB128 (DW_FORM_string
);
5958 CHECKSUM_STRING (AT_file (at
)->filename
);
5961 case dw_val_class_data8
:
5962 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5970 struct checksum_attributes
5972 dw_attr_ref at_name
;
5973 dw_attr_ref at_type
;
5974 dw_attr_ref at_friend
;
5975 dw_attr_ref at_accessibility
;
5976 dw_attr_ref at_address_class
;
5977 dw_attr_ref at_allocated
;
5978 dw_attr_ref at_artificial
;
5979 dw_attr_ref at_associated
;
5980 dw_attr_ref at_binary_scale
;
5981 dw_attr_ref at_bit_offset
;
5982 dw_attr_ref at_bit_size
;
5983 dw_attr_ref at_bit_stride
;
5984 dw_attr_ref at_byte_size
;
5985 dw_attr_ref at_byte_stride
;
5986 dw_attr_ref at_const_value
;
5987 dw_attr_ref at_containing_type
;
5988 dw_attr_ref at_count
;
5989 dw_attr_ref at_data_location
;
5990 dw_attr_ref at_data_member_location
;
5991 dw_attr_ref at_decimal_scale
;
5992 dw_attr_ref at_decimal_sign
;
5993 dw_attr_ref at_default_value
;
5994 dw_attr_ref at_digit_count
;
5995 dw_attr_ref at_discr
;
5996 dw_attr_ref at_discr_list
;
5997 dw_attr_ref at_discr_value
;
5998 dw_attr_ref at_encoding
;
5999 dw_attr_ref at_endianity
;
6000 dw_attr_ref at_explicit
;
6001 dw_attr_ref at_is_optional
;
6002 dw_attr_ref at_location
;
6003 dw_attr_ref at_lower_bound
;
6004 dw_attr_ref at_mutable
;
6005 dw_attr_ref at_ordering
;
6006 dw_attr_ref at_picture_string
;
6007 dw_attr_ref at_prototyped
;
6008 dw_attr_ref at_small
;
6009 dw_attr_ref at_segment
;
6010 dw_attr_ref at_string_length
;
6011 dw_attr_ref at_threads_scaled
;
6012 dw_attr_ref at_upper_bound
;
6013 dw_attr_ref at_use_location
;
6014 dw_attr_ref at_use_UTF8
;
6015 dw_attr_ref at_variable_parameter
;
6016 dw_attr_ref at_virtuality
;
6017 dw_attr_ref at_visibility
;
6018 dw_attr_ref at_vtable_elem_location
;
6021 /* Collect the attributes that we will want to use for the checksum. */
6024 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
6029 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6040 attrs
->at_friend
= a
;
6042 case DW_AT_accessibility
:
6043 attrs
->at_accessibility
= a
;
6045 case DW_AT_address_class
:
6046 attrs
->at_address_class
= a
;
6048 case DW_AT_allocated
:
6049 attrs
->at_allocated
= a
;
6051 case DW_AT_artificial
:
6052 attrs
->at_artificial
= a
;
6054 case DW_AT_associated
:
6055 attrs
->at_associated
= a
;
6057 case DW_AT_binary_scale
:
6058 attrs
->at_binary_scale
= a
;
6060 case DW_AT_bit_offset
:
6061 attrs
->at_bit_offset
= a
;
6063 case DW_AT_bit_size
:
6064 attrs
->at_bit_size
= a
;
6066 case DW_AT_bit_stride
:
6067 attrs
->at_bit_stride
= a
;
6069 case DW_AT_byte_size
:
6070 attrs
->at_byte_size
= a
;
6072 case DW_AT_byte_stride
:
6073 attrs
->at_byte_stride
= a
;
6075 case DW_AT_const_value
:
6076 attrs
->at_const_value
= a
;
6078 case DW_AT_containing_type
:
6079 attrs
->at_containing_type
= a
;
6082 attrs
->at_count
= a
;
6084 case DW_AT_data_location
:
6085 attrs
->at_data_location
= a
;
6087 case DW_AT_data_member_location
:
6088 attrs
->at_data_member_location
= a
;
6090 case DW_AT_decimal_scale
:
6091 attrs
->at_decimal_scale
= a
;
6093 case DW_AT_decimal_sign
:
6094 attrs
->at_decimal_sign
= a
;
6096 case DW_AT_default_value
:
6097 attrs
->at_default_value
= a
;
6099 case DW_AT_digit_count
:
6100 attrs
->at_digit_count
= a
;
6103 attrs
->at_discr
= a
;
6105 case DW_AT_discr_list
:
6106 attrs
->at_discr_list
= a
;
6108 case DW_AT_discr_value
:
6109 attrs
->at_discr_value
= a
;
6111 case DW_AT_encoding
:
6112 attrs
->at_encoding
= a
;
6114 case DW_AT_endianity
:
6115 attrs
->at_endianity
= a
;
6117 case DW_AT_explicit
:
6118 attrs
->at_explicit
= a
;
6120 case DW_AT_is_optional
:
6121 attrs
->at_is_optional
= a
;
6123 case DW_AT_location
:
6124 attrs
->at_location
= a
;
6126 case DW_AT_lower_bound
:
6127 attrs
->at_lower_bound
= a
;
6130 attrs
->at_mutable
= a
;
6132 case DW_AT_ordering
:
6133 attrs
->at_ordering
= a
;
6135 case DW_AT_picture_string
:
6136 attrs
->at_picture_string
= a
;
6138 case DW_AT_prototyped
:
6139 attrs
->at_prototyped
= a
;
6142 attrs
->at_small
= a
;
6145 attrs
->at_segment
= a
;
6147 case DW_AT_string_length
:
6148 attrs
->at_string_length
= a
;
6150 case DW_AT_threads_scaled
:
6151 attrs
->at_threads_scaled
= a
;
6153 case DW_AT_upper_bound
:
6154 attrs
->at_upper_bound
= a
;
6156 case DW_AT_use_location
:
6157 attrs
->at_use_location
= a
;
6159 case DW_AT_use_UTF8
:
6160 attrs
->at_use_UTF8
= a
;
6162 case DW_AT_variable_parameter
:
6163 attrs
->at_variable_parameter
= a
;
6165 case DW_AT_virtuality
:
6166 attrs
->at_virtuality
= a
;
6168 case DW_AT_visibility
:
6169 attrs
->at_visibility
= a
;
6171 case DW_AT_vtable_elem_location
:
6172 attrs
->at_vtable_elem_location
= a
;
6180 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6183 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6187 struct checksum_attributes attrs
;
6189 CHECKSUM_ULEB128 ('D');
6190 CHECKSUM_ULEB128 (die
->die_tag
);
6192 memset (&attrs
, 0, sizeof (attrs
));
6194 decl
= get_AT_ref (die
, DW_AT_specification
);
6196 collect_checksum_attributes (&attrs
, decl
);
6197 collect_checksum_attributes (&attrs
, die
);
6199 CHECKSUM_ATTR (attrs
.at_name
);
6200 CHECKSUM_ATTR (attrs
.at_accessibility
);
6201 CHECKSUM_ATTR (attrs
.at_address_class
);
6202 CHECKSUM_ATTR (attrs
.at_allocated
);
6203 CHECKSUM_ATTR (attrs
.at_artificial
);
6204 CHECKSUM_ATTR (attrs
.at_associated
);
6205 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6206 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6207 CHECKSUM_ATTR (attrs
.at_bit_size
);
6208 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6209 CHECKSUM_ATTR (attrs
.at_byte_size
);
6210 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6211 CHECKSUM_ATTR (attrs
.at_const_value
);
6212 CHECKSUM_ATTR (attrs
.at_containing_type
);
6213 CHECKSUM_ATTR (attrs
.at_count
);
6214 CHECKSUM_ATTR (attrs
.at_data_location
);
6215 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6216 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6217 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6218 CHECKSUM_ATTR (attrs
.at_default_value
);
6219 CHECKSUM_ATTR (attrs
.at_digit_count
);
6220 CHECKSUM_ATTR (attrs
.at_discr
);
6221 CHECKSUM_ATTR (attrs
.at_discr_list
);
6222 CHECKSUM_ATTR (attrs
.at_discr_value
);
6223 CHECKSUM_ATTR (attrs
.at_encoding
);
6224 CHECKSUM_ATTR (attrs
.at_endianity
);
6225 CHECKSUM_ATTR (attrs
.at_explicit
);
6226 CHECKSUM_ATTR (attrs
.at_is_optional
);
6227 CHECKSUM_ATTR (attrs
.at_location
);
6228 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6229 CHECKSUM_ATTR (attrs
.at_mutable
);
6230 CHECKSUM_ATTR (attrs
.at_ordering
);
6231 CHECKSUM_ATTR (attrs
.at_picture_string
);
6232 CHECKSUM_ATTR (attrs
.at_prototyped
);
6233 CHECKSUM_ATTR (attrs
.at_small
);
6234 CHECKSUM_ATTR (attrs
.at_segment
);
6235 CHECKSUM_ATTR (attrs
.at_string_length
);
6236 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6237 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6238 CHECKSUM_ATTR (attrs
.at_use_location
);
6239 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6240 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6241 CHECKSUM_ATTR (attrs
.at_virtuality
);
6242 CHECKSUM_ATTR (attrs
.at_visibility
);
6243 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6244 CHECKSUM_ATTR (attrs
.at_type
);
6245 CHECKSUM_ATTR (attrs
.at_friend
);
6247 /* Checksum the child DIEs. */
6250 dw_attr_ref name_attr
;
6253 name_attr
= get_AT (c
, DW_AT_name
);
6254 if (is_template_instantiation (c
))
6256 /* Ignore instantiations of member type and function templates. */
6258 else if (name_attr
!= NULL
6259 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6261 /* Use a shallow checksum for named nested types and member
6263 CHECKSUM_ULEB128 ('S');
6264 CHECKSUM_ULEB128 (c
->die_tag
);
6265 CHECKSUM_STRING (AT_string (name_attr
));
6269 /* Use a deep checksum for other children. */
6270 /* Mark this DIE so it gets processed when unmarking. */
6271 if (c
->die_mark
== 0)
6273 die_checksum_ordered (c
, ctx
, mark
);
6275 } while (c
!= die
->die_child
);
6277 CHECKSUM_ULEB128 (0);
6280 /* Add a type name and tag to a hash. */
6282 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6284 CHECKSUM_ULEB128 (tag
);
6285 CHECKSUM_STRING (name
);
6289 #undef CHECKSUM_STRING
6290 #undef CHECKSUM_ATTR
6291 #undef CHECKSUM_LEB128
6292 #undef CHECKSUM_ULEB128
6294 /* Generate the type signature for DIE. This is computed by generating an
6295 MD5 checksum over the DIE's tag, its relevant attributes, and its
6296 children. Attributes that are references to other DIEs are processed
6297 by recursion, using the MARK field to prevent infinite recursion.
6298 If the DIE is nested inside a namespace or another type, we also
6299 need to include that context in the signature. The lower 64 bits
6300 of the resulting MD5 checksum comprise the signature. */
6303 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6307 unsigned char checksum
[16];
6312 name
= get_AT_string (die
, DW_AT_name
);
6313 decl
= get_AT_ref (die
, DW_AT_specification
);
6314 parent
= get_die_parent (die
);
6316 /* First, compute a signature for just the type name (and its surrounding
6317 context, if any. This is stored in the type unit DIE for link-time
6318 ODR (one-definition rule) checking. */
6320 if (is_cxx () && name
!= NULL
)
6322 md5_init_ctx (&ctx
);
6324 /* Checksum the names of surrounding namespaces and structures. */
6326 checksum_die_context (parent
, &ctx
);
6328 /* Checksum the current DIE. */
6329 die_odr_checksum (die
->die_tag
, name
, &ctx
);
6330 md5_finish_ctx (&ctx
, checksum
);
6332 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6335 /* Next, compute the complete type signature. */
6337 md5_init_ctx (&ctx
);
6339 die
->die_mark
= mark
;
6341 /* Checksum the names of surrounding namespaces and structures. */
6343 checksum_die_context (parent
, &ctx
);
6345 /* Checksum the DIE and its children. */
6346 die_checksum_ordered (die
, &ctx
, &mark
);
6347 unmark_all_dies (die
);
6348 md5_finish_ctx (&ctx
, checksum
);
6350 /* Store the signature in the type node and link the type DIE and the
6351 type node together. */
6352 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6353 DWARF_TYPE_SIGNATURE_SIZE
);
6354 die
->comdat_type_p
= true;
6355 die
->die_id
.die_type_node
= type_node
;
6356 type_node
->type_die
= die
;
6358 /* If the DIE is a specification, link its declaration to the type node
6362 decl
->comdat_type_p
= true;
6363 decl
->die_id
.die_type_node
= type_node
;
6367 /* Do the location expressions look same? */
6369 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6371 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6372 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6373 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6376 /* Do the values look the same? */
6378 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6380 dw_loc_descr_ref loc1
, loc2
;
6383 if (v1
->val_class
!= v2
->val_class
)
6386 switch (v1
->val_class
)
6388 case dw_val_class_const
:
6389 return v1
->v
.val_int
== v2
->v
.val_int
;
6390 case dw_val_class_unsigned_const
:
6391 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6392 case dw_val_class_const_double
:
6393 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6394 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6395 case dw_val_class_wide_int
:
6396 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
6397 case dw_val_class_vec
:
6398 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6399 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6401 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6402 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6405 case dw_val_class_flag
:
6406 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6407 case dw_val_class_str
:
6408 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6410 case dw_val_class_addr
:
6411 r1
= v1
->v
.val_addr
;
6412 r2
= v2
->v
.val_addr
;
6413 if (GET_CODE (r1
) != GET_CODE (r2
))
6415 return !rtx_equal_p (r1
, r2
);
6417 case dw_val_class_offset
:
6418 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6420 case dw_val_class_loc
:
6421 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6423 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6424 if (!same_loc_p (loc1
, loc2
, mark
))
6426 return !loc1
&& !loc2
;
6428 case dw_val_class_die_ref
:
6429 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6431 case dw_val_class_fde_ref
:
6432 case dw_val_class_vms_delta
:
6433 case dw_val_class_lbl_id
:
6434 case dw_val_class_lineptr
:
6435 case dw_val_class_macptr
:
6436 case dw_val_class_high_pc
:
6439 case dw_val_class_file
:
6440 return v1
->v
.val_file
== v2
->v
.val_file
;
6442 case dw_val_class_data8
:
6443 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6450 /* Do the attributes look the same? */
6453 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6455 if (at1
->dw_attr
!= at2
->dw_attr
)
6458 /* We don't care that this was compiled with a different compiler
6459 snapshot; if the output is the same, that's what matters. */
6460 if (at1
->dw_attr
== DW_AT_producer
)
6463 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6466 /* Do the dies look the same? */
6469 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6475 /* To avoid infinite recursion. */
6477 return die1
->die_mark
== die2
->die_mark
;
6478 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6480 if (die1
->die_tag
!= die2
->die_tag
)
6483 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6486 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6487 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6490 c1
= die1
->die_child
;
6491 c2
= die2
->die_child
;
6500 if (!same_die_p (c1
, c2
, mark
))
6504 if (c1
== die1
->die_child
)
6506 if (c2
== die2
->die_child
)
6516 /* Do the dies look the same? Wrapper around same_die_p. */
6519 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6522 int ret
= same_die_p (die1
, die2
, &mark
);
6524 unmark_all_dies (die1
);
6525 unmark_all_dies (die2
);
6530 /* The prefix to attach to symbols on DIEs in the current comdat debug
6532 static const char *comdat_symbol_id
;
6534 /* The index of the current symbol within the current comdat CU. */
6535 static unsigned int comdat_symbol_number
;
6537 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6538 children, and set comdat_symbol_id accordingly. */
6541 compute_section_prefix (dw_die_ref unit_die
)
6543 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6544 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6545 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6548 unsigned char checksum
[16];
6551 /* Compute the checksum of the DIE, then append part of it as hex digits to
6552 the name filename of the unit. */
6554 md5_init_ctx (&ctx
);
6556 die_checksum (unit_die
, &ctx
, &mark
);
6557 unmark_all_dies (unit_die
);
6558 md5_finish_ctx (&ctx
, checksum
);
6560 sprintf (name
, "%s.", base
);
6561 clean_symbol_name (name
);
6563 p
= name
+ strlen (name
);
6564 for (i
= 0; i
< 4; i
++)
6566 sprintf (p
, "%.2x", checksum
[i
]);
6570 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6571 comdat_symbol_number
= 0;
6574 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6577 is_type_die (dw_die_ref die
)
6579 switch (die
->die_tag
)
6581 case DW_TAG_array_type
:
6582 case DW_TAG_class_type
:
6583 case DW_TAG_interface_type
:
6584 case DW_TAG_enumeration_type
:
6585 case DW_TAG_pointer_type
:
6586 case DW_TAG_reference_type
:
6587 case DW_TAG_rvalue_reference_type
:
6588 case DW_TAG_string_type
:
6589 case DW_TAG_structure_type
:
6590 case DW_TAG_subroutine_type
:
6591 case DW_TAG_union_type
:
6592 case DW_TAG_ptr_to_member_type
:
6593 case DW_TAG_set_type
:
6594 case DW_TAG_subrange_type
:
6595 case DW_TAG_base_type
:
6596 case DW_TAG_const_type
:
6597 case DW_TAG_file_type
:
6598 case DW_TAG_packed_type
:
6599 case DW_TAG_volatile_type
:
6600 case DW_TAG_typedef
:
6607 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6608 Basically, we want to choose the bits that are likely to be shared between
6609 compilations (types) and leave out the bits that are specific to individual
6610 compilations (functions). */
6613 is_comdat_die (dw_die_ref c
)
6615 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6616 we do for stabs. The advantage is a greater likelihood of sharing between
6617 objects that don't include headers in the same order (and therefore would
6618 put the base types in a different comdat). jason 8/28/00 */
6620 if (c
->die_tag
== DW_TAG_base_type
)
6623 if (c
->die_tag
== DW_TAG_pointer_type
6624 || c
->die_tag
== DW_TAG_reference_type
6625 || c
->die_tag
== DW_TAG_rvalue_reference_type
6626 || c
->die_tag
== DW_TAG_const_type
6627 || c
->die_tag
== DW_TAG_volatile_type
)
6629 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6631 return t
? is_comdat_die (t
) : 0;
6634 return is_type_die (c
);
6637 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6638 compilation unit. */
6641 is_symbol_die (dw_die_ref c
)
6643 return (is_type_die (c
)
6644 || is_declaration_die (c
)
6645 || c
->die_tag
== DW_TAG_namespace
6646 || c
->die_tag
== DW_TAG_module
);
6649 /* Returns true iff C is a compile-unit DIE. */
6652 is_cu_die (dw_die_ref c
)
6654 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6657 /* Returns true iff C is a unit DIE of some sort. */
6660 is_unit_die (dw_die_ref c
)
6662 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6663 || c
->die_tag
== DW_TAG_partial_unit
6664 || c
->die_tag
== DW_TAG_type_unit
);
6667 /* Returns true iff C is a namespace DIE. */
6670 is_namespace_die (dw_die_ref c
)
6672 return c
&& c
->die_tag
== DW_TAG_namespace
;
6675 /* Returns true iff C is a class or structure DIE. */
6678 is_class_die (dw_die_ref c
)
6680 return c
&& (c
->die_tag
== DW_TAG_class_type
6681 || c
->die_tag
== DW_TAG_structure_type
);
6684 /* Return non-zero if this DIE is a template parameter. */
6687 is_template_parameter (dw_die_ref die
)
6689 switch (die
->die_tag
)
6691 case DW_TAG_template_type_param
:
6692 case DW_TAG_template_value_param
:
6693 case DW_TAG_GNU_template_template_param
:
6694 case DW_TAG_GNU_template_parameter_pack
:
6701 /* Return non-zero if this DIE represents a template instantiation. */
6704 is_template_instantiation (dw_die_ref die
)
6708 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
6710 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
6715 gen_internal_sym (const char *prefix
)
6719 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6720 return xstrdup (buf
);
6723 /* Assign symbols to all worthy DIEs under DIE. */
6726 assign_symbol_names (dw_die_ref die
)
6730 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6732 if (comdat_symbol_id
)
6734 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6736 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6737 comdat_symbol_id
, comdat_symbol_number
++);
6738 die
->die_id
.die_symbol
= xstrdup (p
);
6741 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6744 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6747 struct cu_hash_table_entry
6750 unsigned min_comdat_num
, max_comdat_num
;
6751 struct cu_hash_table_entry
*next
;
6754 /* Helpers to manipulate hash table of CUs. */
6756 struct cu_hash_table_entry_hasher
6758 typedef cu_hash_table_entry value_type
;
6759 typedef die_struct compare_type
;
6760 static inline hashval_t
hash (const value_type
*);
6761 static inline bool equal (const value_type
*, const compare_type
*);
6762 static inline void remove (value_type
*);
6766 cu_hash_table_entry_hasher::hash (const value_type
*entry
)
6768 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6772 cu_hash_table_entry_hasher::equal (const value_type
*entry1
,
6773 const compare_type
*entry2
)
6775 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6779 cu_hash_table_entry_hasher::remove (value_type
*entry
)
6781 struct cu_hash_table_entry
*next
;
6791 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
6793 /* Check whether we have already seen this CU and set up SYM_NUM
6796 check_duplicate_cu (dw_die_ref cu
, cu_hash_type
*htable
, unsigned int *sym_num
)
6798 struct cu_hash_table_entry dummy
;
6799 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6801 dummy
.max_comdat_num
= 0;
6803 slot
= htable
->find_slot_with_hash (cu
,
6804 htab_hash_string (cu
->die_id
.die_symbol
),
6808 for (; entry
; last
= entry
, entry
= entry
->next
)
6810 if (same_die_p_wrap (cu
, entry
->cu
))
6816 *sym_num
= entry
->min_comdat_num
;
6820 entry
= XCNEW (struct cu_hash_table_entry
);
6822 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6823 entry
->next
= *slot
;
6829 /* Record SYM_NUM to record of CU in HTABLE. */
6831 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type
*htable
,
6832 unsigned int sym_num
)
6834 struct cu_hash_table_entry
**slot
, *entry
;
6836 slot
= htable
->find_slot_with_hash (cu
,
6837 htab_hash_string (cu
->die_id
.die_symbol
),
6841 entry
->max_comdat_num
= sym_num
;
6844 /* Traverse the DIE (which is always comp_unit_die), and set up
6845 additional compilation units for each of the include files we see
6846 bracketed by BINCL/EINCL. */
6849 break_out_includes (dw_die_ref die
)
6852 dw_die_ref unit
= NULL
;
6853 limbo_die_node
*node
, **pnode
;
6857 dw_die_ref prev
= c
;
6859 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6860 || (unit
&& is_comdat_die (c
)))
6862 dw_die_ref next
= c
->die_sib
;
6864 /* This DIE is for a secondary CU; remove it from the main one. */
6865 remove_child_with_prev (c
, prev
);
6867 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6868 unit
= push_new_compile_unit (unit
, c
);
6869 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6870 unit
= pop_compile_unit (unit
);
6872 add_child_die (unit
, c
);
6874 if (c
== die
->die_child
)
6877 } while (c
!= die
->die_child
);
6880 /* We can only use this in debugging, since the frontend doesn't check
6881 to make sure that we leave every include file we enter. */
6885 assign_symbol_names (die
);
6886 cu_hash_type
cu_hash_table (10);
6887 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6893 compute_section_prefix (node
->die
);
6894 is_dupl
= check_duplicate_cu (node
->die
, &cu_hash_table
,
6895 &comdat_symbol_number
);
6896 assign_symbol_names (node
->die
);
6898 *pnode
= node
->next
;
6901 pnode
= &node
->next
;
6902 record_comdat_symbol_number (node
->die
, &cu_hash_table
,
6903 comdat_symbol_number
);
6908 /* Return non-zero if this DIE is a declaration. */
6911 is_declaration_die (dw_die_ref die
)
6916 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6917 if (a
->dw_attr
== DW_AT_declaration
)
6923 /* Return non-zero if this DIE is nested inside a subprogram. */
6926 is_nested_in_subprogram (dw_die_ref die
)
6928 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6932 return local_scope_p (decl
);
6935 /* Return non-zero if this DIE contains a defining declaration of a
6939 contains_subprogram_definition (dw_die_ref die
)
6943 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6945 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
6949 /* Return non-zero if this is a type DIE that should be moved to a
6950 COMDAT .debug_types section. */
6953 should_move_die_to_comdat (dw_die_ref die
)
6955 switch (die
->die_tag
)
6957 case DW_TAG_class_type
:
6958 case DW_TAG_structure_type
:
6959 case DW_TAG_enumeration_type
:
6960 case DW_TAG_union_type
:
6961 /* Don't move declarations, inlined instances, types nested in a
6962 subprogram, or types that contain subprogram definitions. */
6963 if (is_declaration_die (die
)
6964 || get_AT (die
, DW_AT_abstract_origin
)
6965 || is_nested_in_subprogram (die
)
6966 || contains_subprogram_definition (die
))
6969 case DW_TAG_array_type
:
6970 case DW_TAG_interface_type
:
6971 case DW_TAG_pointer_type
:
6972 case DW_TAG_reference_type
:
6973 case DW_TAG_rvalue_reference_type
:
6974 case DW_TAG_string_type
:
6975 case DW_TAG_subroutine_type
:
6976 case DW_TAG_ptr_to_member_type
:
6977 case DW_TAG_set_type
:
6978 case DW_TAG_subrange_type
:
6979 case DW_TAG_base_type
:
6980 case DW_TAG_const_type
:
6981 case DW_TAG_file_type
:
6982 case DW_TAG_packed_type
:
6983 case DW_TAG_volatile_type
:
6984 case DW_TAG_typedef
:
6990 /* Make a clone of DIE. */
6993 clone_die (dw_die_ref die
)
6999 clone
= ggc_cleared_alloc
<die_node
> ();
7000 clone
->die_tag
= die
->die_tag
;
7002 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7003 add_dwarf_attr (clone
, a
);
7008 /* Make a clone of the tree rooted at DIE. */
7011 clone_tree (dw_die_ref die
)
7014 dw_die_ref clone
= clone_die (die
);
7016 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
7021 /* Make a clone of DIE as a declaration. */
7024 clone_as_declaration (dw_die_ref die
)
7031 /* If the DIE is already a declaration, just clone it. */
7032 if (is_declaration_die (die
))
7033 return clone_die (die
);
7035 /* If the DIE is a specification, just clone its declaration DIE. */
7036 decl
= get_AT_ref (die
, DW_AT_specification
);
7039 clone
= clone_die (decl
);
7040 if (die
->comdat_type_p
)
7041 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7045 clone
= ggc_cleared_alloc
<die_node
> ();
7046 clone
->die_tag
= die
->die_tag
;
7048 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7050 /* We don't want to copy over all attributes.
7051 For example we don't want DW_AT_byte_size because otherwise we will no
7052 longer have a declaration and GDB will treat it as a definition. */
7056 case DW_AT_abstract_origin
:
7057 case DW_AT_artificial
:
7058 case DW_AT_containing_type
:
7059 case DW_AT_external
:
7062 case DW_AT_virtuality
:
7063 case DW_AT_linkage_name
:
7064 case DW_AT_MIPS_linkage_name
:
7065 add_dwarf_attr (clone
, a
);
7067 case DW_AT_byte_size
:
7073 if (die
->comdat_type_p
)
7074 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7076 add_AT_flag (clone
, DW_AT_declaration
, 1);
7081 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7083 struct decl_table_entry
7089 /* Helpers to manipulate hash table of copied declarations. */
7091 /* Hashtable helpers. */
7093 struct decl_table_entry_hasher
: typed_free_remove
<decl_table_entry
>
7095 typedef decl_table_entry value_type
;
7096 typedef die_struct compare_type
;
7097 static inline hashval_t
hash (const value_type
*);
7098 static inline bool equal (const value_type
*, const compare_type
*);
7102 decl_table_entry_hasher::hash (const value_type
*entry
)
7104 return htab_hash_pointer (entry
->orig
);
7108 decl_table_entry_hasher::equal (const value_type
*entry1
,
7109 const compare_type
*entry2
)
7111 return entry1
->orig
== entry2
;
7114 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
7116 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7117 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7118 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7119 to check if the ancestor has already been copied into UNIT. */
7122 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
,
7123 decl_hash_type
*decl_table
)
7125 dw_die_ref parent
= die
->die_parent
;
7126 dw_die_ref new_parent
= unit
;
7128 decl_table_entry
**slot
= NULL
;
7129 struct decl_table_entry
*entry
= NULL
;
7133 /* Check if the entry has already been copied to UNIT. */
7134 slot
= decl_table
->find_slot_with_hash (die
, htab_hash_pointer (die
),
7136 if (*slot
!= HTAB_EMPTY_ENTRY
)
7142 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7143 entry
= XCNEW (struct decl_table_entry
);
7151 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7154 if (!is_unit_die (parent
))
7155 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7158 copy
= clone_as_declaration (die
);
7159 add_child_die (new_parent
, copy
);
7163 /* Record the pointer to the copy. */
7169 /* Copy the declaration context to the new type unit DIE. This includes
7170 any surrounding namespace or type declarations. If the DIE has an
7171 AT_specification attribute, it also includes attributes and children
7172 attached to the specification, and returns a pointer to the original
7173 parent of the declaration DIE. Returns NULL otherwise. */
7176 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7179 dw_die_ref new_decl
;
7180 dw_die_ref orig_parent
= NULL
;
7182 decl
= get_AT_ref (die
, DW_AT_specification
);
7191 /* The original DIE will be changed to a declaration, and must
7192 be moved to be a child of the original declaration DIE. */
7193 orig_parent
= decl
->die_parent
;
7195 /* Copy the type node pointer from the new DIE to the original
7196 declaration DIE so we can forward references later. */
7197 decl
->comdat_type_p
= true;
7198 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7200 remove_AT (die
, DW_AT_specification
);
7202 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7204 if (a
->dw_attr
!= DW_AT_name
7205 && a
->dw_attr
!= DW_AT_declaration
7206 && a
->dw_attr
!= DW_AT_external
)
7207 add_dwarf_attr (die
, a
);
7210 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7213 if (decl
->die_parent
!= NULL
7214 && !is_unit_die (decl
->die_parent
))
7216 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
7217 if (new_decl
!= NULL
)
7219 remove_AT (new_decl
, DW_AT_signature
);
7220 add_AT_specification (die
, new_decl
);
7227 /* Generate the skeleton ancestor tree for the given NODE, then clone
7228 the DIE and add the clone into the tree. */
7231 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7233 if (node
->new_die
!= NULL
)
7236 node
->new_die
= clone_as_declaration (node
->old_die
);
7238 if (node
->parent
!= NULL
)
7240 generate_skeleton_ancestor_tree (node
->parent
);
7241 add_child_die (node
->parent
->new_die
, node
->new_die
);
7245 /* Generate a skeleton tree of DIEs containing any declarations that are
7246 found in the original tree. We traverse the tree looking for declaration
7247 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7250 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7252 skeleton_chain_node node
;
7255 dw_die_ref prev
= NULL
;
7256 dw_die_ref next
= NULL
;
7258 node
.parent
= parent
;
7260 first
= c
= parent
->old_die
->die_child
;
7264 if (prev
== NULL
|| prev
->die_sib
== c
)
7267 next
= (c
== first
? NULL
: c
->die_sib
);
7269 node
.new_die
= NULL
;
7270 if (is_declaration_die (c
))
7272 if (is_template_instantiation (c
))
7274 /* Instantiated templates do not need to be cloned into the
7275 type unit. Just move the DIE and its children back to
7276 the skeleton tree (in the main CU). */
7277 remove_child_with_prev (c
, prev
);
7278 add_child_die (parent
->new_die
, c
);
7283 /* Clone the existing DIE, move the original to the skeleton
7284 tree (which is in the main CU), and put the clone, with
7285 all the original's children, where the original came from
7286 (which is about to be moved to the type unit). */
7287 dw_die_ref clone
= clone_die (c
);
7288 move_all_children (c
, clone
);
7290 /* If the original has a DW_AT_object_pointer attribute,
7291 it would now point to a child DIE just moved to the
7292 cloned tree, so we need to remove that attribute from
7294 remove_AT (c
, DW_AT_object_pointer
);
7296 replace_child (c
, clone
, prev
);
7297 generate_skeleton_ancestor_tree (parent
);
7298 add_child_die (parent
->new_die
, c
);
7303 generate_skeleton_bottom_up (&node
);
7304 } while (next
!= NULL
);
7307 /* Wrapper function for generate_skeleton_bottom_up. */
7310 generate_skeleton (dw_die_ref die
)
7312 skeleton_chain_node node
;
7315 node
.new_die
= NULL
;
7318 /* If this type definition is nested inside another type,
7319 and is not an instantiation of a template, always leave
7320 at least a declaration in its place. */
7321 if (die
->die_parent
!= NULL
7322 && is_type_die (die
->die_parent
)
7323 && !is_template_instantiation (die
))
7324 node
.new_die
= clone_as_declaration (die
);
7326 generate_skeleton_bottom_up (&node
);
7327 return node
.new_die
;
7330 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7331 declaration. The original DIE is moved to a new compile unit so that
7332 existing references to it follow it to the new location. If any of the
7333 original DIE's descendants is a declaration, we need to replace the
7334 original DIE with a skeleton tree and move the declarations back into the
7338 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7341 dw_die_ref skeleton
, orig_parent
;
7343 /* Copy the declaration context to the type unit DIE. If the returned
7344 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7346 orig_parent
= copy_declaration_context (unit
, child
);
7348 skeleton
= generate_skeleton (child
);
7349 if (skeleton
== NULL
)
7350 remove_child_with_prev (child
, prev
);
7353 skeleton
->comdat_type_p
= true;
7354 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7356 /* If the original DIE was a specification, we need to put
7357 the skeleton under the parent DIE of the declaration.
7358 This leaves the original declaration in the tree, but
7359 it will be pruned later since there are no longer any
7360 references to it. */
7361 if (orig_parent
!= NULL
)
7363 remove_child_with_prev (child
, prev
);
7364 add_child_die (orig_parent
, skeleton
);
7367 replace_child (child
, skeleton
, prev
);
7373 /* Traverse the DIE and set up additional .debug_types sections for each
7374 type worthy of being placed in a COMDAT section. */
7377 break_out_comdat_types (dw_die_ref die
)
7381 dw_die_ref prev
= NULL
;
7382 dw_die_ref next
= NULL
;
7383 dw_die_ref unit
= NULL
;
7385 first
= c
= die
->die_child
;
7389 if (prev
== NULL
|| prev
->die_sib
== c
)
7392 next
= (c
== first
? NULL
: c
->die_sib
);
7393 if (should_move_die_to_comdat (c
))
7395 dw_die_ref replacement
;
7396 comdat_type_node_ref type_node
;
7398 /* Break out nested types into their own type units. */
7399 break_out_comdat_types (c
);
7401 /* Create a new type unit DIE as the root for the new tree, and
7402 add it to the list of comdat types. */
7403 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7404 add_AT_unsigned (unit
, DW_AT_language
,
7405 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7406 type_node
= ggc_cleared_alloc
<comdat_type_node
> ();
7407 type_node
->root_die
= unit
;
7408 type_node
->next
= comdat_type_list
;
7409 comdat_type_list
= type_node
;
7411 /* Generate the type signature. */
7412 generate_type_signature (c
, type_node
);
7414 /* Copy the declaration context, attributes, and children of the
7415 declaration into the new type unit DIE, then remove this DIE
7416 from the main CU (or replace it with a skeleton if necessary). */
7417 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7418 type_node
->skeleton_die
= replacement
;
7420 /* Add the DIE to the new compunit. */
7421 add_child_die (unit
, c
);
7423 if (replacement
!= NULL
)
7426 else if (c
->die_tag
== DW_TAG_namespace
7427 || c
->die_tag
== DW_TAG_class_type
7428 || c
->die_tag
== DW_TAG_structure_type
7429 || c
->die_tag
== DW_TAG_union_type
)
7431 /* Look for nested types that can be broken out. */
7432 break_out_comdat_types (c
);
7434 } while (next
!= NULL
);
7437 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
7438 Enter all the cloned children into the hash table decl_table. */
7441 clone_tree_partial (dw_die_ref die
, decl_hash_type
*decl_table
)
7445 struct decl_table_entry
*entry
;
7446 decl_table_entry
**slot
;
7448 if (die
->die_tag
== DW_TAG_subprogram
)
7449 clone
= clone_as_declaration (die
);
7451 clone
= clone_die (die
);
7453 slot
= decl_table
->find_slot_with_hash (die
,
7454 htab_hash_pointer (die
), INSERT
);
7456 /* Assert that DIE isn't in the hash table yet. If it would be there
7457 before, the ancestors would be necessarily there as well, therefore
7458 clone_tree_partial wouldn't be called. */
7459 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7461 entry
= XCNEW (struct decl_table_entry
);
7463 entry
->copy
= clone
;
7466 if (die
->die_tag
!= DW_TAG_subprogram
)
7467 FOR_EACH_CHILD (die
, c
,
7468 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
7473 /* Walk the DIE and its children, looking for references to incomplete
7474 or trivial types that are unmarked (i.e., that are not in the current
7478 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type
*decl_table
)
7484 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7486 if (AT_class (a
) == dw_val_class_die_ref
)
7488 dw_die_ref targ
= AT_ref (a
);
7489 decl_table_entry
**slot
;
7490 struct decl_table_entry
*entry
;
7492 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7495 slot
= decl_table
->find_slot_with_hash (targ
,
7496 htab_hash_pointer (targ
),
7499 if (*slot
!= HTAB_EMPTY_ENTRY
)
7501 /* TARG has already been copied, so we just need to
7502 modify the reference to point to the copy. */
7504 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7508 dw_die_ref parent
= unit
;
7509 dw_die_ref copy
= clone_die (targ
);
7511 /* Record in DECL_TABLE that TARG has been copied.
7512 Need to do this now, before the recursive call,
7513 because DECL_TABLE may be expanded and SLOT
7514 would no longer be a valid pointer. */
7515 entry
= XCNEW (struct decl_table_entry
);
7520 /* If TARG is not a declaration DIE, we need to copy its
7522 if (!is_declaration_die (targ
))
7526 add_child_die (copy
,
7527 clone_tree_partial (c
, decl_table
)));
7530 /* Make sure the cloned tree is marked as part of the
7534 /* If TARG has surrounding context, copy its ancestor tree
7535 into the new type unit. */
7536 if (targ
->die_parent
!= NULL
7537 && !is_unit_die (targ
->die_parent
))
7538 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7541 add_child_die (parent
, copy
);
7542 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7544 /* Make sure the newly-copied DIE is walked. If it was
7545 installed in a previously-added context, it won't
7546 get visited otherwise. */
7549 /* Find the highest point of the newly-added tree,
7550 mark each node along the way, and walk from there. */
7551 parent
->die_mark
= 1;
7552 while (parent
->die_parent
7553 && parent
->die_parent
->die_mark
== 0)
7555 parent
= parent
->die_parent
;
7556 parent
->die_mark
= 1;
7558 copy_decls_walk (unit
, parent
, decl_table
);
7564 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7567 /* Copy declarations for "unworthy" types into the new comdat section.
7568 Incomplete types, modified types, and certain other types aren't broken
7569 out into comdat sections of their own, so they don't have a signature,
7570 and we need to copy the declaration into the same section so that we
7571 don't have an external reference. */
7574 copy_decls_for_unworthy_types (dw_die_ref unit
)
7577 decl_hash_type
decl_table (10);
7578 copy_decls_walk (unit
, unit
, &decl_table
);
7582 /* Traverse the DIE and add a sibling attribute if it may have the
7583 effect of speeding up access to siblings. To save some space,
7584 avoid generating sibling attributes for DIE's without children. */
7587 add_sibling_attributes (dw_die_ref die
)
7591 if (! die
->die_child
)
7594 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7595 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7597 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7600 /* Output all location lists for the DIE and its children. */
7603 output_location_lists (dw_die_ref die
)
7609 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7610 if (AT_class (a
) == dw_val_class_loc_list
)
7611 output_loc_list (AT_loc_list (a
));
7613 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7616 /* We want to limit the number of external references, because they are
7617 larger than local references: a relocation takes multiple words, and
7618 even a sig8 reference is always eight bytes, whereas a local reference
7619 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7620 So if we encounter multiple external references to the same type DIE, we
7621 make a local typedef stub for it and redirect all references there.
7623 This is the element of the hash table for keeping track of these
7633 /* Hashtable helpers. */
7635 struct external_ref_hasher
: typed_free_remove
<external_ref
>
7637 typedef external_ref value_type
;
7638 typedef external_ref compare_type
;
7639 static inline hashval_t
hash (const value_type
*);
7640 static inline bool equal (const value_type
*, const compare_type
*);
7644 external_ref_hasher::hash (const value_type
*r
)
7646 dw_die_ref die
= r
->type
;
7649 /* We can't use the address of the DIE for hashing, because
7650 that will make the order of the stub DIEs non-deterministic. */
7651 if (! die
->comdat_type_p
)
7652 /* We have a symbol; use it to compute a hash. */
7653 h
= htab_hash_string (die
->die_id
.die_symbol
);
7656 /* We have a type signature; use a subset of the bits as the hash.
7657 The 8-byte signature is at least as large as hashval_t. */
7658 comdat_type_node_ref type_node
= die
->die_id
.die_type_node
;
7659 memcpy (&h
, type_node
->signature
, sizeof (h
));
7665 external_ref_hasher::equal (const value_type
*r1
, const compare_type
*r2
)
7667 return r1
->type
== r2
->type
;
7670 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
7672 /* Return a pointer to the external_ref for references to DIE. */
7674 static struct external_ref
*
7675 lookup_external_ref (external_ref_hash_type
*map
, dw_die_ref die
)
7677 struct external_ref ref
, *ref_p
;
7678 external_ref
**slot
;
7681 slot
= map
->find_slot (&ref
, INSERT
);
7682 if (*slot
!= HTAB_EMPTY_ENTRY
)
7685 ref_p
= XCNEW (struct external_ref
);
7691 /* Subroutine of optimize_external_refs, below.
7693 If we see a type skeleton, record it as our stub. If we see external
7694 references, remember how many we've seen. */
7697 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type
*map
)
7702 struct external_ref
*ref_p
;
7704 if (is_type_die (die
)
7705 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7707 /* This is a local skeleton; use it for local references. */
7708 ref_p
= lookup_external_ref (map
, c
);
7712 /* Scan the DIE references, and remember any that refer to DIEs from
7713 other CUs (i.e. those which are not marked). */
7714 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7715 if (AT_class (a
) == dw_val_class_die_ref
7716 && (c
= AT_ref (a
))->die_mark
== 0
7719 ref_p
= lookup_external_ref (map
, c
);
7723 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7726 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7727 points to an external_ref, DATA is the CU we're processing. If we don't
7728 already have a local stub, and we have multiple refs, build a stub. */
7731 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
7733 struct external_ref
*ref_p
= *slot
;
7735 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7737 /* We have multiple references to this type, so build a small stub.
7738 Both of these forms are a bit dodgy from the perspective of the
7739 DWARF standard, since technically they should have names. */
7740 dw_die_ref cu
= data
;
7741 dw_die_ref type
= ref_p
->type
;
7742 dw_die_ref stub
= NULL
;
7744 if (type
->comdat_type_p
)
7746 /* If we refer to this type via sig8, use AT_signature. */
7747 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7748 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7752 /* Otherwise, use a typedef with no name. */
7753 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7754 add_AT_die_ref (stub
, DW_AT_type
, type
);
7763 /* DIE is a unit; look through all the DIE references to see if there are
7764 any external references to types, and if so, create local stubs for
7765 them which will be applied in build_abbrev_table. This is useful because
7766 references to local DIEs are smaller. */
7768 static external_ref_hash_type
*
7769 optimize_external_refs (dw_die_ref die
)
7771 external_ref_hash_type
*map
= new external_ref_hash_type (10);
7772 optimize_external_refs_1 (die
, map
);
7773 map
->traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
7777 /* The format of each DIE (and its attribute value pairs) is encoded in an
7778 abbreviation table. This routine builds the abbreviation table and assigns
7779 a unique abbreviation id for each abbreviation entry. The children of each
7780 die are visited recursively. */
7783 build_abbrev_table (dw_die_ref die
, external_ref_hash_type
*extern_map
)
7785 unsigned long abbrev_id
;
7786 unsigned int n_alloc
;
7791 /* Scan the DIE references, and replace any that refer to
7792 DIEs from other CUs (i.e. those which are not marked) with
7793 the local stubs we built in optimize_external_refs. */
7794 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7795 if (AT_class (a
) == dw_val_class_die_ref
7796 && (c
= AT_ref (a
))->die_mark
== 0)
7798 struct external_ref
*ref_p
;
7799 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7801 ref_p
= lookup_external_ref (extern_map
, c
);
7802 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7803 change_AT_die_ref (a
, ref_p
->stub
);
7805 /* We aren't changing this reference, so mark it external. */
7806 set_AT_ref_external (a
, 1);
7809 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7811 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7812 dw_attr_ref die_a
, abbrev_a
;
7816 if (abbrev
->die_tag
!= die
->die_tag
)
7818 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7821 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
7824 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
7826 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
7827 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7828 || (value_format (abbrev_a
) != value_format (die_a
)))
7838 if (abbrev_id
>= abbrev_die_table_in_use
)
7840 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7842 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7843 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7846 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7847 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7848 abbrev_die_table_allocated
= n_alloc
;
7851 ++abbrev_die_table_in_use
;
7852 abbrev_die_table
[abbrev_id
] = die
;
7855 die
->die_abbrev
= abbrev_id
;
7856 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
7859 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7862 constant_size (unsigned HOST_WIDE_INT value
)
7869 log
= floor_log2 (value
);
7872 log
= 1 << (floor_log2 (log
) + 1);
7877 /* Return the size of a DIE as it is represented in the
7878 .debug_info section. */
7880 static unsigned long
7881 size_of_die (dw_die_ref die
)
7883 unsigned long size
= 0;
7886 enum dwarf_form form
;
7888 size
+= size_of_uleb128 (die
->die_abbrev
);
7889 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7891 switch (AT_class (a
))
7893 case dw_val_class_addr
:
7894 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7896 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7897 size
+= size_of_uleb128 (AT_index (a
));
7900 size
+= DWARF2_ADDR_SIZE
;
7902 case dw_val_class_offset
:
7903 size
+= DWARF_OFFSET_SIZE
;
7905 case dw_val_class_loc
:
7907 unsigned long lsize
= size_of_locs (AT_loc (a
));
7910 if (dwarf_version
>= 4)
7911 size
+= size_of_uleb128 (lsize
);
7913 size
+= constant_size (lsize
);
7917 case dw_val_class_loc_list
:
7918 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7920 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7921 size
+= size_of_uleb128 (AT_index (a
));
7924 size
+= DWARF_OFFSET_SIZE
;
7926 case dw_val_class_range_list
:
7927 size
+= DWARF_OFFSET_SIZE
;
7929 case dw_val_class_const
:
7930 size
+= size_of_sleb128 (AT_int (a
));
7932 case dw_val_class_unsigned_const
:
7934 int csize
= constant_size (AT_unsigned (a
));
7935 if (dwarf_version
== 3
7936 && a
->dw_attr
== DW_AT_data_member_location
7938 size
+= size_of_uleb128 (AT_unsigned (a
));
7943 case dw_val_class_const_double
:
7944 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
7945 if (HOST_BITS_PER_WIDE_INT
>= 64)
7948 case dw_val_class_wide_int
:
7949 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
7950 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
7951 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
7955 case dw_val_class_vec
:
7956 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7957 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7958 + a
->dw_attr_val
.v
.val_vec
.length
7959 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7961 case dw_val_class_flag
:
7962 if (dwarf_version
>= 4)
7963 /* Currently all add_AT_flag calls pass in 1 as last argument,
7964 so DW_FORM_flag_present can be used. If that ever changes,
7965 we'll need to use DW_FORM_flag and have some optimization
7966 in build_abbrev_table that will change those to
7967 DW_FORM_flag_present if it is set to 1 in all DIEs using
7968 the same abbrev entry. */
7969 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7973 case dw_val_class_die_ref
:
7974 if (AT_ref_external (a
))
7976 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7977 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7978 is sized by target address length, whereas in DWARF3
7979 it's always sized as an offset. */
7980 if (use_debug_types
)
7981 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7982 else if (dwarf_version
== 2)
7983 size
+= DWARF2_ADDR_SIZE
;
7985 size
+= DWARF_OFFSET_SIZE
;
7988 size
+= DWARF_OFFSET_SIZE
;
7990 case dw_val_class_fde_ref
:
7991 size
+= DWARF_OFFSET_SIZE
;
7993 case dw_val_class_lbl_id
:
7994 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7996 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7997 size
+= size_of_uleb128 (AT_index (a
));
8000 size
+= DWARF2_ADDR_SIZE
;
8002 case dw_val_class_lineptr
:
8003 case dw_val_class_macptr
:
8004 size
+= DWARF_OFFSET_SIZE
;
8006 case dw_val_class_str
:
8007 form
= AT_string_form (a
);
8008 if (form
== DW_FORM_strp
)
8009 size
+= DWARF_OFFSET_SIZE
;
8010 else if (form
== DW_FORM_GNU_str_index
)
8011 size
+= size_of_uleb128 (AT_index (a
));
8013 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
8015 case dw_val_class_file
:
8016 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
8018 case dw_val_class_data8
:
8021 case dw_val_class_vms_delta
:
8022 size
+= DWARF_OFFSET_SIZE
;
8024 case dw_val_class_high_pc
:
8025 size
+= DWARF2_ADDR_SIZE
;
8035 /* Size the debugging information associated with a given DIE. Visits the
8036 DIE's children recursively. Updates the global variable next_die_offset, on
8037 each time through. Uses the current value of next_die_offset to update the
8038 die_offset field in each DIE. */
8041 calc_die_sizes (dw_die_ref die
)
8045 gcc_assert (die
->die_offset
== 0
8046 || (unsigned long int) die
->die_offset
== next_die_offset
);
8047 die
->die_offset
= next_die_offset
;
8048 next_die_offset
+= size_of_die (die
);
8050 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
8052 if (die
->die_child
!= NULL
)
8053 /* Count the null byte used to terminate sibling lists. */
8054 next_die_offset
+= 1;
8057 /* Size just the base type children at the start of the CU.
8058 This is needed because build_abbrev needs to size locs
8059 and sizing of type based stack ops needs to know die_offset
8060 values for the base types. */
8063 calc_base_type_die_sizes (void)
8065 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8067 dw_die_ref base_type
;
8068 #if ENABLE_ASSERT_CHECKING
8069 dw_die_ref prev
= comp_unit_die ()->die_child
;
8072 die_offset
+= size_of_die (comp_unit_die ());
8073 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
8075 #if ENABLE_ASSERT_CHECKING
8076 gcc_assert (base_type
->die_offset
== 0
8077 && prev
->die_sib
== base_type
8078 && base_type
->die_child
== NULL
8079 && base_type
->die_abbrev
);
8082 base_type
->die_offset
= die_offset
;
8083 die_offset
+= size_of_die (base_type
);
8087 /* Set the marks for a die and its children. We do this so
8088 that we know whether or not a reference needs to use FORM_ref_addr; only
8089 DIEs in the same CU will be marked. We used to clear out the offset
8090 and use that as the flag, but ran into ordering problems. */
8093 mark_dies (dw_die_ref die
)
8097 gcc_assert (!die
->die_mark
);
8100 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
8103 /* Clear the marks for a die and its children. */
8106 unmark_dies (dw_die_ref die
)
8110 if (! use_debug_types
)
8111 gcc_assert (die
->die_mark
);
8114 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
8117 /* Clear the marks for a die, its children and referred dies. */
8120 unmark_all_dies (dw_die_ref die
)
8130 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
8132 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8133 if (AT_class (a
) == dw_val_class_die_ref
)
8134 unmark_all_dies (AT_ref (a
));
8137 /* Calculate if the entry should appear in the final output file. It may be
8138 from a pruned a type. */
8141 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
8143 /* By limiting gnu pubnames to definitions only, gold can generate a
8144 gdb index without entries for declarations, which don't include
8145 enough information to be useful. */
8146 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
8149 if (table
== pubname_table
)
8151 /* Enumerator names are part of the pubname table, but the
8152 parent DW_TAG_enumeration_type die may have been pruned.
8153 Don't output them if that is the case. */
8154 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
8155 (p
->die
->die_parent
== NULL
8156 || !p
->die
->die_parent
->die_perennial_p
))
8159 /* Everything else in the pubname table is included. */
8163 /* The pubtypes table shouldn't include types that have been
8165 return (p
->die
->die_offset
!= 0
8166 || !flag_eliminate_unused_debug_types
);
8169 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8170 generated for the compilation unit. */
8172 static unsigned long
8173 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8178 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
8180 size
= DWARF_PUBNAMES_HEADER_SIZE
;
8181 FOR_EACH_VEC_ELT (*names
, i
, p
)
8182 if (include_pubname_in_output (names
, p
))
8183 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
8185 size
+= DWARF_OFFSET_SIZE
;
8189 /* Return the size of the information in the .debug_aranges section. */
8191 static unsigned long
8192 size_of_aranges (void)
8196 size
= DWARF_ARANGES_HEADER_SIZE
;
8198 /* Count the address/length pair for this compilation unit. */
8199 if (text_section_used
)
8200 size
+= 2 * DWARF2_ADDR_SIZE
;
8201 if (cold_text_section_used
)
8202 size
+= 2 * DWARF2_ADDR_SIZE
;
8203 if (have_multiple_function_sections
)
8208 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
8210 if (DECL_IGNORED_P (fde
->decl
))
8212 if (!fde
->in_std_section
)
8213 size
+= 2 * DWARF2_ADDR_SIZE
;
8214 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8215 size
+= 2 * DWARF2_ADDR_SIZE
;
8219 /* Count the two zero words used to terminated the address range table. */
8220 size
+= 2 * DWARF2_ADDR_SIZE
;
8224 /* Select the encoding of an attribute value. */
8226 static enum dwarf_form
8227 value_format (dw_attr_ref a
)
8229 switch (AT_class (a
))
8231 case dw_val_class_addr
:
8232 /* Only very few attributes allow DW_FORM_addr. */
8237 case DW_AT_entry_pc
:
8238 case DW_AT_trampoline
:
8239 return (AT_index (a
) == NOT_INDEXED
8240 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8244 switch (DWARF2_ADDR_SIZE
)
8247 return DW_FORM_data1
;
8249 return DW_FORM_data2
;
8251 return DW_FORM_data4
;
8253 return DW_FORM_data8
;
8257 case dw_val_class_range_list
:
8258 case dw_val_class_loc_list
:
8259 if (dwarf_version
>= 4)
8260 return DW_FORM_sec_offset
;
8262 case dw_val_class_vms_delta
:
8263 case dw_val_class_offset
:
8264 switch (DWARF_OFFSET_SIZE
)
8267 return DW_FORM_data4
;
8269 return DW_FORM_data8
;
8273 case dw_val_class_loc
:
8274 if (dwarf_version
>= 4)
8275 return DW_FORM_exprloc
;
8276 switch (constant_size (size_of_locs (AT_loc (a
))))
8279 return DW_FORM_block1
;
8281 return DW_FORM_block2
;
8283 return DW_FORM_block4
;
8287 case dw_val_class_const
:
8288 return DW_FORM_sdata
;
8289 case dw_val_class_unsigned_const
:
8290 switch (constant_size (AT_unsigned (a
)))
8293 return DW_FORM_data1
;
8295 return DW_FORM_data2
;
8297 /* In DWARF3 DW_AT_data_member_location with
8298 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8299 constant, so we need to use DW_FORM_udata if we need
8300 a large constant. */
8301 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8302 return DW_FORM_udata
;
8303 return DW_FORM_data4
;
8305 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8306 return DW_FORM_udata
;
8307 return DW_FORM_data8
;
8311 case dw_val_class_const_double
:
8312 switch (HOST_BITS_PER_WIDE_INT
)
8315 return DW_FORM_data2
;
8317 return DW_FORM_data4
;
8319 return DW_FORM_data8
;
8322 return DW_FORM_block1
;
8324 case dw_val_class_wide_int
:
8325 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
8328 return DW_FORM_data1
;
8330 return DW_FORM_data2
;
8332 return DW_FORM_data4
;
8334 return DW_FORM_data8
;
8336 return DW_FORM_block1
;
8338 case dw_val_class_vec
:
8339 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8340 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8343 return DW_FORM_block1
;
8345 return DW_FORM_block2
;
8347 return DW_FORM_block4
;
8351 case dw_val_class_flag
:
8352 if (dwarf_version
>= 4)
8354 /* Currently all add_AT_flag calls pass in 1 as last argument,
8355 so DW_FORM_flag_present can be used. If that ever changes,
8356 we'll need to use DW_FORM_flag and have some optimization
8357 in build_abbrev_table that will change those to
8358 DW_FORM_flag_present if it is set to 1 in all DIEs using
8359 the same abbrev entry. */
8360 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8361 return DW_FORM_flag_present
;
8363 return DW_FORM_flag
;
8364 case dw_val_class_die_ref
:
8365 if (AT_ref_external (a
))
8366 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8369 case dw_val_class_fde_ref
:
8370 return DW_FORM_data
;
8371 case dw_val_class_lbl_id
:
8372 return (AT_index (a
) == NOT_INDEXED
8373 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8374 case dw_val_class_lineptr
:
8375 case dw_val_class_macptr
:
8376 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8377 case dw_val_class_str
:
8378 return AT_string_form (a
);
8379 case dw_val_class_file
:
8380 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8383 return DW_FORM_data1
;
8385 return DW_FORM_data2
;
8387 return DW_FORM_data4
;
8392 case dw_val_class_data8
:
8393 return DW_FORM_data8
;
8395 case dw_val_class_high_pc
:
8396 switch (DWARF2_ADDR_SIZE
)
8399 return DW_FORM_data1
;
8401 return DW_FORM_data2
;
8403 return DW_FORM_data4
;
8405 return DW_FORM_data8
;
8415 /* Output the encoding of an attribute value. */
8418 output_value_format (dw_attr_ref a
)
8420 enum dwarf_form form
= value_format (a
);
8422 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8425 /* Given a die and id, produce the appropriate abbreviations. */
8428 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8433 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8434 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8435 dwarf_tag_name (abbrev
->die_tag
));
8437 if (abbrev
->die_child
!= NULL
)
8438 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8440 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8442 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8444 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8445 dwarf_attr_name (a_attr
->dw_attr
));
8446 output_value_format (a_attr
);
8449 dw2_asm_output_data (1, 0, NULL
);
8450 dw2_asm_output_data (1, 0, NULL
);
8454 /* Output the .debug_abbrev section which defines the DIE abbreviation
8458 output_abbrev_section (void)
8460 unsigned long abbrev_id
;
8462 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8463 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8465 /* Terminate the table. */
8466 dw2_asm_output_data (1, 0, NULL
);
8469 /* Output a symbol we can use to refer to this DIE from another CU. */
8472 output_die_symbol (dw_die_ref die
)
8474 const char *sym
= die
->die_id
.die_symbol
;
8476 gcc_assert (!die
->comdat_type_p
);
8481 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8482 /* We make these global, not weak; if the target doesn't support
8483 .linkonce, it doesn't support combining the sections, so debugging
8485 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8487 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8490 /* Return a new location list, given the begin and end range, and the
8493 static inline dw_loc_list_ref
8494 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8495 const char *section
)
8497 dw_loc_list_ref retlist
= ggc_cleared_alloc
<dw_loc_list_node
> ();
8499 retlist
->begin
= begin
;
8500 retlist
->begin_entry
= NULL
;
8502 retlist
->expr
= expr
;
8503 retlist
->section
= section
;
8508 /* Generate a new internal symbol for this location list node, if it
8509 hasn't got one yet. */
8512 gen_llsym (dw_loc_list_ref list
)
8514 gcc_assert (!list
->ll_symbol
);
8515 list
->ll_symbol
= gen_internal_sym ("LLST");
8518 /* Output the location list given to us. */
8521 output_loc_list (dw_loc_list_ref list_head
)
8523 dw_loc_list_ref curr
= list_head
;
8525 if (list_head
->emitted
)
8527 list_head
->emitted
= true;
8529 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8531 /* Walk the location list, and output each range + expression. */
8532 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8535 /* Don't output an entry that starts and ends at the same address. */
8536 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8538 size
= size_of_locs (curr
->expr
);
8539 /* If the expression is too large, drop it on the floor. We could
8540 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8541 in the expression, but >= 64KB expressions for a single value
8542 in a single range are unlikely very useful. */
8545 if (dwarf_split_debug_info
)
8547 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8548 "Location list start/length entry (%s)",
8549 list_head
->ll_symbol
);
8550 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8551 "Location list range start index (%s)",
8553 /* The length field is 4 bytes. If we ever need to support
8554 an 8-byte length, we can add a new DW_LLE code or fall back
8555 to DW_LLE_GNU_start_end_entry. */
8556 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8557 "Location list range length (%s)",
8558 list_head
->ll_symbol
);
8560 else if (!have_multiple_function_sections
)
8562 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8563 "Location list begin address (%s)",
8564 list_head
->ll_symbol
);
8565 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8566 "Location list end address (%s)",
8567 list_head
->ll_symbol
);
8571 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8572 "Location list begin address (%s)",
8573 list_head
->ll_symbol
);
8574 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8575 "Location list end address (%s)",
8576 list_head
->ll_symbol
);
8579 /* Output the block length for this list of location operations. */
8580 gcc_assert (size
<= 0xffff);
8581 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8583 output_loc_sequence (curr
->expr
, -1);
8586 if (dwarf_split_debug_info
)
8587 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8588 "Location list terminator (%s)",
8589 list_head
->ll_symbol
);
8592 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8593 "Location list terminator begin (%s)",
8594 list_head
->ll_symbol
);
8595 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8596 "Location list terminator end (%s)",
8597 list_head
->ll_symbol
);
8601 /* Output a range_list offset into the debug_range section. Emit a
8602 relocated reference if val_entry is NULL, otherwise, emit an
8603 indirect reference. */
8606 output_range_list_offset (dw_attr_ref a
)
8608 const char *name
= dwarf_attr_name (a
->dw_attr
);
8610 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8612 char *p
= strchr (ranges_section_label
, '\0');
8613 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8614 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8615 debug_ranges_section
, "%s", name
);
8619 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8620 "%s (offset from %s)", name
, ranges_section_label
);
8623 /* Output the offset into the debug_loc section. */
8626 output_loc_list_offset (dw_attr_ref a
)
8628 char *sym
= AT_loc_list (a
)->ll_symbol
;
8631 if (dwarf_split_debug_info
)
8632 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8633 "%s", dwarf_attr_name (a
->dw_attr
));
8635 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8636 "%s", dwarf_attr_name (a
->dw_attr
));
8639 /* Output an attribute's index or value appropriately. */
8642 output_attr_index_or_value (dw_attr_ref a
)
8644 const char *name
= dwarf_attr_name (a
->dw_attr
);
8646 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8648 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8651 switch (AT_class (a
))
8653 case dw_val_class_addr
:
8654 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8656 case dw_val_class_high_pc
:
8657 case dw_val_class_lbl_id
:
8658 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8660 case dw_val_class_loc_list
:
8661 output_loc_list_offset (a
);
8668 /* Output a type signature. */
8671 output_signature (const char *sig
, const char *name
)
8675 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8676 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8679 /* Output the DIE and its attributes. Called recursively to generate
8680 the definitions of each child DIE. */
8683 output_die (dw_die_ref die
)
8690 /* If someone in another CU might refer to us, set up a symbol for
8691 them to point to. */
8692 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8693 output_die_symbol (die
);
8695 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8696 (unsigned long)die
->die_offset
,
8697 dwarf_tag_name (die
->die_tag
));
8699 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8701 const char *name
= dwarf_attr_name (a
->dw_attr
);
8703 switch (AT_class (a
))
8705 case dw_val_class_addr
:
8706 output_attr_index_or_value (a
);
8709 case dw_val_class_offset
:
8710 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8714 case dw_val_class_range_list
:
8715 output_range_list_offset (a
);
8718 case dw_val_class_loc
:
8719 size
= size_of_locs (AT_loc (a
));
8721 /* Output the block length for this list of location operations. */
8722 if (dwarf_version
>= 4)
8723 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8725 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8727 output_loc_sequence (AT_loc (a
), -1);
8730 case dw_val_class_const
:
8731 /* ??? It would be slightly more efficient to use a scheme like is
8732 used for unsigned constants below, but gdb 4.x does not sign
8733 extend. Gdb 5.x does sign extend. */
8734 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8737 case dw_val_class_unsigned_const
:
8739 int csize
= constant_size (AT_unsigned (a
));
8740 if (dwarf_version
== 3
8741 && a
->dw_attr
== DW_AT_data_member_location
8743 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8745 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8749 case dw_val_class_const_double
:
8751 unsigned HOST_WIDE_INT first
, second
;
8753 if (HOST_BITS_PER_WIDE_INT
>= 64)
8754 dw2_asm_output_data (1,
8755 HOST_BITS_PER_DOUBLE_INT
8756 / HOST_BITS_PER_CHAR
,
8759 if (WORDS_BIG_ENDIAN
)
8761 first
= a
->dw_attr_val
.v
.val_double
.high
;
8762 second
= a
->dw_attr_val
.v
.val_double
.low
;
8766 first
= a
->dw_attr_val
.v
.val_double
.low
;
8767 second
= a
->dw_attr_val
.v
.val_double
.high
;
8770 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8772 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8777 case dw_val_class_wide_int
:
8780 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
8781 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
8782 if (len
* HOST_BITS_PER_WIDE_INT
> 64)
8783 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
) * l
,
8786 if (WORDS_BIG_ENDIAN
)
8787 for (i
= len
- 1; i
>= 0; --i
)
8789 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
8794 for (i
= 0; i
< len
; ++i
)
8796 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
8803 case dw_val_class_vec
:
8805 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8806 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8810 dw2_asm_output_data (constant_size (len
* elt_size
),
8811 len
* elt_size
, "%s", name
);
8812 if (elt_size
> sizeof (HOST_WIDE_INT
))
8817 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8820 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8821 "fp or vector constant word %u", i
);
8825 case dw_val_class_flag
:
8826 if (dwarf_version
>= 4)
8828 /* Currently all add_AT_flag calls pass in 1 as last argument,
8829 so DW_FORM_flag_present can be used. If that ever changes,
8830 we'll need to use DW_FORM_flag and have some optimization
8831 in build_abbrev_table that will change those to
8832 DW_FORM_flag_present if it is set to 1 in all DIEs using
8833 the same abbrev entry. */
8834 gcc_assert (AT_flag (a
) == 1);
8836 fprintf (asm_out_file
, "\t\t\t%s %s\n",
8837 ASM_COMMENT_START
, name
);
8840 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8843 case dw_val_class_loc_list
:
8844 output_attr_index_or_value (a
);
8847 case dw_val_class_die_ref
:
8848 if (AT_ref_external (a
))
8850 if (AT_ref (a
)->comdat_type_p
)
8852 comdat_type_node_ref type_node
=
8853 AT_ref (a
)->die_id
.die_type_node
;
8855 gcc_assert (type_node
);
8856 output_signature (type_node
->signature
, name
);
8860 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
8864 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8865 length, whereas in DWARF3 it's always sized as an
8867 if (dwarf_version
== 2)
8868 size
= DWARF2_ADDR_SIZE
;
8870 size
= DWARF_OFFSET_SIZE
;
8871 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
8877 gcc_assert (AT_ref (a
)->die_offset
);
8878 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8883 case dw_val_class_fde_ref
:
8887 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8888 a
->dw_attr_val
.v
.val_fde_index
* 2);
8889 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8894 case dw_val_class_vms_delta
:
8895 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
8896 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
8900 case dw_val_class_lbl_id
:
8901 output_attr_index_or_value (a
);
8904 case dw_val_class_lineptr
:
8905 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8906 debug_line_section
, "%s", name
);
8909 case dw_val_class_macptr
:
8910 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8911 debug_macinfo_section
, "%s", name
);
8914 case dw_val_class_str
:
8915 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
8916 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8917 a
->dw_attr_val
.v
.val_str
->label
,
8919 "%s: \"%s\"", name
, AT_string (a
));
8920 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
8921 dw2_asm_output_data_uleb128 (AT_index (a
),
8922 "%s: \"%s\"", name
, AT_string (a
));
8924 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8927 case dw_val_class_file
:
8929 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8931 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8932 a
->dw_attr_val
.v
.val_file
->filename
);
8936 case dw_val_class_data8
:
8940 for (i
= 0; i
< 8; i
++)
8941 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8942 i
== 0 ? "%s" : NULL
, name
);
8946 case dw_val_class_high_pc
:
8947 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
8948 get_AT_low_pc (die
), "DW_AT_high_pc");
8956 FOR_EACH_CHILD (die
, c
, output_die (c
));
8958 /* Add null byte to terminate sibling list. */
8959 if (die
->die_child
!= NULL
)
8960 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8961 (unsigned long) die
->die_offset
);
8964 /* Output the compilation unit that appears at the beginning of the
8965 .debug_info section, and precedes the DIE descriptions. */
8968 output_compilation_unit_header (void)
8970 int ver
= dwarf_version
;
8972 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8973 dw2_asm_output_data (4, 0xffffffff,
8974 "Initial length escape value indicating 64-bit DWARF extension");
8975 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8976 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8977 "Length of Compilation Unit Info");
8978 dw2_asm_output_data (2, ver
, "DWARF version number");
8979 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8980 debug_abbrev_section
,
8981 "Offset Into Abbrev. Section");
8982 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8985 /* Output the compilation unit DIE and its children. */
8988 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8990 const char *secname
, *oldsym
;
8993 /* Unless we are outputting main CU, we may throw away empty ones. */
8994 if (!output_if_empty
&& die
->die_child
== NULL
)
8997 /* Even if there are no children of this DIE, we must output the information
8998 about the compilation unit. Otherwise, on an empty translation unit, we
8999 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
9000 will then complain when examining the file. First mark all the DIEs in
9001 this CU so we know which get local refs. */
9004 external_ref_hash_type
*extern_map
= optimize_external_refs (die
);
9006 build_abbrev_table (die
, extern_map
);
9010 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9011 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
9012 calc_die_sizes (die
);
9014 oldsym
= die
->die_id
.die_symbol
;
9017 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
9019 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
9021 die
->die_id
.die_symbol
= NULL
;
9022 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9026 switch_to_section (debug_info_section
);
9027 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
9028 info_section_emitted
= true;
9031 /* Output debugging information. */
9032 output_compilation_unit_header ();
9035 /* Leave the marks on the main CU, so we can check them in
9040 die
->die_id
.die_symbol
= oldsym
;
9044 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
9045 and .debug_pubtypes. This is configured per-target, but can be
9046 overridden by the -gpubnames or -gno-pubnames options. */
9049 want_pubnames (void)
9051 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9053 if (debug_generate_pub_sections
!= -1)
9054 return debug_generate_pub_sections
;
9055 return targetm
.want_debug_pub_sections
;
9058 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
9061 add_AT_pubnames (dw_die_ref die
)
9063 if (want_pubnames ())
9064 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
9067 /* Add a string attribute value to a skeleton DIE. */
9070 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
9074 struct indirect_string_node
*node
;
9076 if (! skeleton_debug_str_hash
)
9077 skeleton_debug_str_hash
9078 = hash_table
<indirect_string_hasher
>::create_ggc (10);
9080 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
9081 find_string_form (node
);
9082 if (node
->form
== DW_FORM_GNU_str_index
)
9083 node
->form
= DW_FORM_strp
;
9085 attr
.dw_attr
= attr_kind
;
9086 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
9087 attr
.dw_attr_val
.val_entry
= NULL
;
9088 attr
.dw_attr_val
.v
.val_str
= node
;
9089 add_dwarf_attr (die
, &attr
);
9092 /* Helper function to generate top-level dies for skeleton debug_info and
9096 add_top_level_skeleton_die_attrs (dw_die_ref die
)
9098 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
9099 const char *comp_dir
= comp_dir_string ();
9101 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
9102 if (comp_dir
!= NULL
)
9103 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
9104 add_AT_pubnames (die
);
9105 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
9108 /* Output skeleton debug sections that point to the dwo file. */
9111 output_skeleton_debug_sections (dw_die_ref comp_unit
)
9113 /* These attributes will be found in the full debug_info section. */
9114 remove_AT (comp_unit
, DW_AT_producer
);
9115 remove_AT (comp_unit
, DW_AT_language
);
9117 switch_to_section (debug_skeleton_info_section
);
9118 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
9120 /* Produce the skeleton compilation-unit header. This one differs enough from
9121 a normal CU header that it's better not to call output_compilation_unit
9123 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9124 dw2_asm_output_data (4, 0xffffffff,
9125 "Initial length escape value indicating 64-bit DWARF extension");
9127 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9128 DWARF_COMPILE_UNIT_HEADER_SIZE
9129 - DWARF_INITIAL_LENGTH_SIZE
9130 + size_of_die (comp_unit
),
9131 "Length of Compilation Unit Info");
9132 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
9133 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
9134 debug_abbrev_section
,
9135 "Offset Into Abbrev. Section");
9136 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9138 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
9139 output_die (comp_unit
);
9141 /* Build the skeleton debug_abbrev section. */
9142 switch_to_section (debug_skeleton_abbrev_section
);
9143 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
9145 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
9147 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
9150 /* Output a comdat type unit DIE and its children. */
9153 output_comdat_type_unit (comdat_type_node
*node
)
9155 const char *secname
;
9158 #if defined (OBJECT_FORMAT_ELF)
9162 /* First mark all the DIEs in this CU so we know which get local refs. */
9163 mark_dies (node
->root_die
);
9165 external_ref_hash_type
*extern_map
= optimize_external_refs (node
->root_die
);
9167 build_abbrev_table (node
->root_die
, extern_map
);
9172 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9173 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
9174 calc_die_sizes (node
->root_die
);
9176 #if defined (OBJECT_FORMAT_ELF)
9177 if (!dwarf_split_debug_info
)
9178 secname
= ".debug_types";
9180 secname
= ".debug_types.dwo";
9182 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9183 sprintf (tmp
, "wt.");
9184 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9185 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9186 comdat_key
= get_identifier (tmp
);
9187 targetm
.asm_out
.named_section (secname
,
9188 SECTION_DEBUG
| SECTION_LINKONCE
,
9191 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9192 sprintf (tmp
, ".gnu.linkonce.wt.");
9193 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9194 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9196 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9199 /* Output debugging information. */
9200 output_compilation_unit_header ();
9201 output_signature (node
->signature
, "Type Signature");
9202 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
9203 "Offset to Type DIE");
9204 output_die (node
->root_die
);
9206 unmark_dies (node
->root_die
);
9209 /* Return the DWARF2/3 pubname associated with a decl. */
9212 dwarf2_name (tree decl
, int scope
)
9214 if (DECL_NAMELESS (decl
))
9216 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
9219 /* Add a new entry to .debug_pubnames if appropriate. */
9222 add_pubname_string (const char *str
, dw_die_ref die
)
9227 e
.name
= xstrdup (str
);
9228 vec_safe_push (pubname_table
, e
);
9232 add_pubname (tree decl
, dw_die_ref die
)
9234 if (!want_pubnames ())
9237 /* Don't add items to the table when we expect that the consumer will have
9238 just read the enclosing die. For example, if the consumer is looking at a
9239 class_member, it will either be inside the class already, or will have just
9240 looked up the class to find the member. Either way, searching the class is
9241 faster than searching the index. */
9242 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
9243 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9245 const char *name
= dwarf2_name (decl
, 1);
9248 add_pubname_string (name
, die
);
9252 /* Add an enumerator to the pubnames section. */
9255 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
9259 gcc_assert (scope_name
);
9260 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
9262 vec_safe_push (pubname_table
, e
);
9265 /* Add a new entry to .debug_pubtypes if appropriate. */
9268 add_pubtype (tree decl
, dw_die_ref die
)
9272 if (!want_pubnames ())
9275 if ((TREE_PUBLIC (decl
)
9276 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9277 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9280 const char *scope_name
= "";
9281 const char *sep
= is_cxx () ? "::" : ".";
9284 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9285 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9287 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9288 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9289 scope_name
= concat (scope_name
, sep
, NULL
);
9295 name
= type_tag (decl
);
9297 name
= lang_hooks
.dwarf_name (decl
, 1);
9299 /* If we don't have a name for the type, there's no point in adding
9301 if (name
!= NULL
&& name
[0] != '\0')
9304 e
.name
= concat (scope_name
, name
, NULL
);
9305 vec_safe_push (pubtype_table
, e
);
9308 /* Although it might be more consistent to add the pubinfo for the
9309 enumerators as their dies are created, they should only be added if the
9310 enum type meets the criteria above. So rather than re-check the parent
9311 enum type whenever an enumerator die is created, just output them all
9312 here. This isn't protected by the name conditional because anonymous
9313 enums don't have names. */
9314 if (die
->die_tag
== DW_TAG_enumeration_type
)
9318 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9323 /* Output a single entry in the pubnames table. */
9326 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
9328 dw_die_ref die
= entry
->die
;
9329 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
9331 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9333 if (debug_generate_pub_sections
== 2)
9335 /* This logic follows gdb's method for determining the value of the flag
9337 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
9338 switch (die
->die_tag
)
9340 case DW_TAG_typedef
:
9341 case DW_TAG_base_type
:
9342 case DW_TAG_subrange_type
:
9343 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9344 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9346 case DW_TAG_enumerator
:
9347 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9348 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9349 if (!is_cxx () && !is_java ())
9350 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9352 case DW_TAG_subprogram
:
9353 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9354 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
9356 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9358 case DW_TAG_constant
:
9359 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9360 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9361 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9363 case DW_TAG_variable
:
9364 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9365 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9366 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9368 case DW_TAG_namespace
:
9369 case DW_TAG_imported_declaration
:
9370 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9372 case DW_TAG_class_type
:
9373 case DW_TAG_interface_type
:
9374 case DW_TAG_structure_type
:
9375 case DW_TAG_union_type
:
9376 case DW_TAG_enumeration_type
:
9377 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9378 if (!is_cxx () && !is_java ())
9379 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9382 /* An unusual tag. Leave the flag-byte empty. */
9385 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
9389 dw2_asm_output_nstring (entry
->name
, -1, "external name");
9393 /* Output the public names table used to speed up access to externally
9394 visible names; or the public types table used to find type definitions. */
9397 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9400 unsigned long pubnames_length
= size_of_pubnames (names
);
9403 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9404 dw2_asm_output_data (4, 0xffffffff,
9405 "Initial length escape value indicating 64-bit DWARF extension");
9406 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
, "Pub Info Length");
9408 /* Version number for pubnames/pubtypes is independent of dwarf version. */
9409 dw2_asm_output_data (2, 2, "DWARF Version");
9411 if (dwarf_split_debug_info
)
9412 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9413 debug_skeleton_info_section
,
9414 "Offset of Compilation Unit Info");
9416 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9418 "Offset of Compilation Unit Info");
9419 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9420 "Compilation Unit Length");
9422 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9424 if (include_pubname_in_output (names
, pub
))
9426 dw_offset die_offset
= pub
->die
->die_offset
;
9428 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9429 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9430 gcc_assert (pub
->die
->die_mark
);
9432 /* If we're putting types in their own .debug_types sections,
9433 the .debug_pubtypes table will still point to the compile
9434 unit (not the type unit), so we want to use the offset of
9435 the skeleton DIE (if there is one). */
9436 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9438 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9440 if (type_node
!= NULL
)
9441 die_offset
= (type_node
->skeleton_die
!= NULL
9442 ? type_node
->skeleton_die
->die_offset
9443 : comp_unit_die ()->die_offset
);
9446 output_pubname (die_offset
, pub
);
9450 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9453 /* Output public names and types tables if necessary. */
9456 output_pubtables (void)
9458 if (!want_pubnames () || !info_section_emitted
)
9461 switch_to_section (debug_pubnames_section
);
9462 output_pubnames (pubname_table
);
9463 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
9464 It shouldn't hurt to emit it always, since pure DWARF2 consumers
9465 simply won't look for the section. */
9466 switch_to_section (debug_pubtypes_section
);
9467 output_pubnames (pubtype_table
);
9471 /* Output the information that goes into the .debug_aranges table.
9472 Namely, define the beginning and ending address range of the
9473 text section generated for this compilation unit. */
9476 output_aranges (unsigned long aranges_length
)
9480 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9481 dw2_asm_output_data (4, 0xffffffff,
9482 "Initial length escape value indicating 64-bit DWARF extension");
9483 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9484 "Length of Address Ranges Info");
9485 /* Version number for aranges is still 2, even in DWARF3. */
9486 dw2_asm_output_data (2, 2, "DWARF Version");
9487 if (dwarf_split_debug_info
)
9488 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9489 debug_skeleton_info_section
,
9490 "Offset of Compilation Unit Info");
9492 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9494 "Offset of Compilation Unit Info");
9495 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9496 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9498 /* We need to align to twice the pointer size here. */
9499 if (DWARF_ARANGES_PAD_SIZE
)
9501 /* Pad using a 2 byte words so that padding is correct for any
9503 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9504 2 * DWARF2_ADDR_SIZE
);
9505 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9506 dw2_asm_output_data (2, 0, NULL
);
9509 /* It is necessary not to output these entries if the sections were
9510 not used; if the sections were not used, the length will be 0 and
9511 the address may end up as 0 if the section is discarded by ld
9512 --gc-sections, leaving an invalid (0, 0) entry that can be
9513 confused with the terminator. */
9514 if (text_section_used
)
9516 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9517 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9518 text_section_label
, "Length");
9520 if (cold_text_section_used
)
9522 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9524 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9525 cold_text_section_label
, "Length");
9528 if (have_multiple_function_sections
)
9533 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9535 if (DECL_IGNORED_P (fde
->decl
))
9537 if (!fde
->in_std_section
)
9539 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9541 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9542 fde
->dw_fde_begin
, "Length");
9544 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9546 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9548 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9549 fde
->dw_fde_second_begin
, "Length");
9554 /* Output the terminator words. */
9555 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9556 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9559 /* Add a new entry to .debug_ranges. Return the offset at which it
9563 add_ranges_num (int num
)
9565 unsigned int in_use
= ranges_table_in_use
;
9567 if (in_use
== ranges_table_allocated
)
9569 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9570 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9571 ranges_table_allocated
);
9572 memset (ranges_table
+ ranges_table_in_use
, 0,
9573 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9576 ranges_table
[in_use
].num
= num
;
9577 ranges_table_in_use
= in_use
+ 1;
9579 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9582 /* Add a new entry to .debug_ranges corresponding to a block, or a
9583 range terminator if BLOCK is NULL. */
9586 add_ranges (const_tree block
)
9588 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9591 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9592 When using dwarf_split_debug_info, address attributes in dies destined
9593 for the final executable should be direct references--setting the
9594 parameter force_direct ensures this behavior. */
9597 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9598 bool *added
, bool force_direct
)
9600 unsigned int in_use
= ranges_by_label_in_use
;
9601 unsigned int offset
;
9603 if (in_use
== ranges_by_label_allocated
)
9605 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9606 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9608 ranges_by_label_allocated
);
9609 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9610 RANGES_TABLE_INCREMENT
9611 * sizeof (struct dw_ranges_by_label_struct
));
9614 ranges_by_label
[in_use
].begin
= begin
;
9615 ranges_by_label
[in_use
].end
= end
;
9616 ranges_by_label_in_use
= in_use
+ 1;
9618 offset
= add_ranges_num (-(int)in_use
- 1);
9621 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9627 output_ranges (void)
9630 static const char *const start_fmt
= "Offset %#x";
9631 const char *fmt
= start_fmt
;
9633 for (i
= 0; i
< ranges_table_in_use
; i
++)
9635 int block_num
= ranges_table
[i
].num
;
9639 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9640 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9642 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9643 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9645 /* If all code is in the text section, then the compilation
9646 unit base address defaults to DW_AT_low_pc, which is the
9647 base of the text section. */
9648 if (!have_multiple_function_sections
)
9650 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9652 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9653 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9654 text_section_label
, NULL
);
9657 /* Otherwise, the compilation unit base address is zero,
9658 which allows us to use absolute addresses, and not worry
9659 about whether the target supports cross-section
9663 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9664 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9665 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9671 /* Negative block_num stands for an index into ranges_by_label. */
9672 else if (block_num
< 0)
9674 int lab_idx
= - block_num
- 1;
9676 if (!have_multiple_function_sections
)
9680 /* If we ever use add_ranges_by_labels () for a single
9681 function section, all we have to do is to take out
9683 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9684 ranges_by_label
[lab_idx
].begin
,
9686 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9687 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9688 ranges_by_label
[lab_idx
].end
,
9689 text_section_label
, NULL
);
9694 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9695 ranges_by_label
[lab_idx
].begin
,
9696 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9697 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9698 ranges_by_label
[lab_idx
].end
,
9704 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9705 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9711 /* Data structure containing information about input files. */
9714 const char *path
; /* Complete file name. */
9715 const char *fname
; /* File name part. */
9716 int length
; /* Length of entire string. */
9717 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9718 int dir_idx
; /* Index in directory table. */
9721 /* Data structure containing information about directories with source
9725 const char *path
; /* Path including directory name. */
9726 int length
; /* Path length. */
9727 int prefix
; /* Index of directory entry which is a prefix. */
9728 int count
; /* Number of files in this directory. */
9729 int dir_idx
; /* Index of directory used as base. */
9732 /* Callback function for file_info comparison. We sort by looking at
9733 the directories in the path. */
9736 file_info_cmp (const void *p1
, const void *p2
)
9738 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9739 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9740 const unsigned char *cp1
;
9741 const unsigned char *cp2
;
9743 /* Take care of file names without directories. We need to make sure that
9744 we return consistent values to qsort since some will get confused if
9745 we return the same value when identical operands are passed in opposite
9746 orders. So if neither has a directory, return 0 and otherwise return
9747 1 or -1 depending on which one has the directory. */
9748 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9749 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9751 cp1
= (const unsigned char *) s1
->path
;
9752 cp2
= (const unsigned char *) s2
->path
;
9758 /* Reached the end of the first path? If so, handle like above. */
9759 if ((cp1
== (const unsigned char *) s1
->fname
)
9760 || (cp2
== (const unsigned char *) s2
->fname
))
9761 return ((cp2
== (const unsigned char *) s2
->fname
)
9762 - (cp1
== (const unsigned char *) s1
->fname
));
9764 /* Character of current path component the same? */
9765 else if (*cp1
!= *cp2
)
9770 struct file_name_acquire_data
9772 struct file_info
*files
;
9777 /* Traversal function for the hash table. */
9780 file_name_acquire (dwarf_file_data
**slot
, file_name_acquire_data
*fnad
)
9782 struct dwarf_file_data
*d
= *slot
;
9783 struct file_info
*fi
;
9786 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9788 if (! d
->emitted_number
)
9791 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9793 fi
= fnad
->files
+ fnad
->used_files
++;
9795 /* Skip all leading "./". */
9797 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9800 /* Create a new array entry. */
9802 fi
->length
= strlen (f
);
9805 /* Search for the file name part. */
9806 f
= strrchr (f
, DIR_SEPARATOR
);
9807 #if defined (DIR_SEPARATOR_2)
9809 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9813 if (f
== NULL
|| f
< g
)
9819 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9823 /* Output the directory table and the file name table. We try to minimize
9824 the total amount of memory needed. A heuristic is used to avoid large
9825 slowdowns with many input files. */
9828 output_file_names (void)
9830 struct file_name_acquire_data fnad
;
9832 struct file_info
*files
;
9833 struct dir_info
*dirs
;
9841 if (!last_emitted_file
)
9843 dw2_asm_output_data (1, 0, "End directory table");
9844 dw2_asm_output_data (1, 0, "End file name table");
9848 numfiles
= last_emitted_file
->emitted_number
;
9850 /* Allocate the various arrays we need. */
9851 files
= XALLOCAVEC (struct file_info
, numfiles
);
9852 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9855 fnad
.used_files
= 0;
9856 fnad
.max_files
= numfiles
;
9857 file_table
->traverse
<file_name_acquire_data
*, file_name_acquire
> (&fnad
);
9858 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9860 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9862 /* Find all the different directories used. */
9863 dirs
[0].path
= files
[0].path
;
9864 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9865 dirs
[0].prefix
= -1;
9867 dirs
[0].dir_idx
= 0;
9868 files
[0].dir_idx
= 0;
9871 for (i
= 1; i
< numfiles
; i
++)
9872 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9873 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9874 dirs
[ndirs
- 1].length
) == 0)
9876 /* Same directory as last entry. */
9877 files
[i
].dir_idx
= ndirs
- 1;
9878 ++dirs
[ndirs
- 1].count
;
9884 /* This is a new directory. */
9885 dirs
[ndirs
].path
= files
[i
].path
;
9886 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9887 dirs
[ndirs
].count
= 1;
9888 dirs
[ndirs
].dir_idx
= ndirs
;
9889 files
[i
].dir_idx
= ndirs
;
9891 /* Search for a prefix. */
9892 dirs
[ndirs
].prefix
= -1;
9893 for (j
= 0; j
< ndirs
; j
++)
9894 if (dirs
[j
].length
< dirs
[ndirs
].length
9895 && dirs
[j
].length
> 1
9896 && (dirs
[ndirs
].prefix
== -1
9897 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9898 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9899 dirs
[ndirs
].prefix
= j
;
9904 /* Now to the actual work. We have to find a subset of the directories which
9905 allow expressing the file name using references to the directory table
9906 with the least amount of characters. We do not do an exhaustive search
9907 where we would have to check out every combination of every single
9908 possible prefix. Instead we use a heuristic which provides nearly optimal
9909 results in most cases and never is much off. */
9910 saved
= XALLOCAVEC (int, ndirs
);
9911 savehere
= XALLOCAVEC (int, ndirs
);
9913 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9914 for (i
= 0; i
< ndirs
; i
++)
9919 /* We can always save some space for the current directory. But this
9920 does not mean it will be enough to justify adding the directory. */
9921 savehere
[i
] = dirs
[i
].length
;
9922 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9924 for (j
= i
+ 1; j
< ndirs
; j
++)
9927 if (saved
[j
] < dirs
[i
].length
)
9929 /* Determine whether the dirs[i] path is a prefix of the
9934 while (k
!= -1 && k
!= (int) i
)
9939 /* Yes it is. We can possibly save some memory by
9940 writing the filenames in dirs[j] relative to
9942 savehere
[j
] = dirs
[i
].length
;
9943 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9948 /* Check whether we can save enough to justify adding the dirs[i]
9950 if (total
> dirs
[i
].length
+ 1)
9952 /* It's worthwhile adding. */
9953 for (j
= i
; j
< ndirs
; j
++)
9954 if (savehere
[j
] > 0)
9956 /* Remember how much we saved for this directory so far. */
9957 saved
[j
] = savehere
[j
];
9959 /* Remember the prefix directory. */
9960 dirs
[j
].dir_idx
= i
;
9965 /* Emit the directory name table. */
9966 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9967 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9968 dw2_asm_output_nstring (dirs
[i
].path
,
9970 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
9971 "Directory Entry: %#x", i
+ idx_offset
);
9973 dw2_asm_output_data (1, 0, "End directory table");
9975 /* We have to emit them in the order of emitted_number since that's
9976 used in the debug info generation. To do this efficiently we
9977 generate a back-mapping of the indices first. */
9978 backmap
= XALLOCAVEC (int, numfiles
);
9979 for (i
= 0; i
< numfiles
; i
++)
9980 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9982 /* Now write all the file names. */
9983 for (i
= 0; i
< numfiles
; i
++)
9985 int file_idx
= backmap
[i
];
9986 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9988 #ifdef VMS_DEBUGGING_INFO
9989 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9991 /* Setting these fields can lead to debugger miscomparisons,
9992 but VMS Debug requires them to be set correctly. */
9997 int maxfilelen
= strlen (files
[file_idx
].path
)
9998 + dirs
[dir_idx
].length
9999 + MAX_VMS_VERSION_LEN
+ 1;
10000 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
10002 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
10003 snprintf (filebuf
, maxfilelen
, "%s;%d",
10004 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
10006 dw2_asm_output_nstring
10007 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
10009 /* Include directory index. */
10010 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10012 /* Modification time. */
10013 dw2_asm_output_data_uleb128
10014 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
10018 /* File length in bytes. */
10019 dw2_asm_output_data_uleb128
10020 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
10024 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
10025 "File Entry: %#x", (unsigned) i
+ 1);
10027 /* Include directory index. */
10028 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10030 /* Modification time. */
10031 dw2_asm_output_data_uleb128 (0, NULL
);
10033 /* File length in bytes. */
10034 dw2_asm_output_data_uleb128 (0, NULL
);
10035 #endif /* VMS_DEBUGGING_INFO */
10038 dw2_asm_output_data (1, 0, "End file name table");
10042 /* Output one line number table into the .debug_line section. */
10045 output_one_line_info_table (dw_line_info_table
*table
)
10047 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10048 unsigned int current_line
= 1;
10049 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
10050 dw_line_info_entry
*ent
;
10053 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
10055 switch (ent
->opcode
)
10057 case LI_set_address
:
10058 /* ??? Unfortunately, we have little choice here currently, and
10059 must always use the most general form. GCC does not know the
10060 address delta itself, so we can't use DW_LNS_advance_pc. Many
10061 ports do have length attributes which will give an upper bound
10062 on the address range. We could perhaps use length attributes
10063 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
10064 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
10066 /* This can handle any delta. This takes
10067 4+DWARF2_ADDR_SIZE bytes. */
10068 dw2_asm_output_data (1, 0, "set address %s", line_label
);
10069 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10070 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10071 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
10075 if (ent
->val
== current_line
)
10077 /* We still need to start a new row, so output a copy insn. */
10078 dw2_asm_output_data (1, DW_LNS_copy
,
10079 "copy line %u", current_line
);
10083 int line_offset
= ent
->val
- current_line
;
10084 int line_delta
= line_offset
- DWARF_LINE_BASE
;
10086 current_line
= ent
->val
;
10087 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
10089 /* This can handle deltas from -10 to 234, using the current
10090 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
10091 This takes 1 byte. */
10092 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
10093 "line %u", current_line
);
10097 /* This can handle any delta. This takes at least 4 bytes,
10098 depending on the value being encoded. */
10099 dw2_asm_output_data (1, DW_LNS_advance_line
,
10100 "advance to line %u", current_line
);
10101 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
10102 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
10108 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
10109 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10112 case LI_set_column
:
10113 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
10114 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10117 case LI_negate_stmt
:
10118 current_is_stmt
= !current_is_stmt
;
10119 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
10120 "is_stmt %d", current_is_stmt
);
10123 case LI_set_prologue_end
:
10124 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
10125 "set prologue end");
10128 case LI_set_epilogue_begin
:
10129 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
10130 "set epilogue begin");
10133 case LI_set_discriminator
:
10134 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
10135 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
10136 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
10137 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
10142 /* Emit debug info for the address of the end of the table. */
10143 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
10144 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10145 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10146 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
10148 dw2_asm_output_data (1, 0, "end sequence");
10149 dw2_asm_output_data_uleb128 (1, NULL
);
10150 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
10153 /* Output the source line number correspondence information. This
10154 information goes into the .debug_line section. */
10157 output_line_info (bool prologue_only
)
10159 char l1
[20], l2
[20], p1
[20], p2
[20];
10160 int ver
= dwarf_version
;
10161 bool saw_one
= false;
10164 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
10165 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
10166 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
10167 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
10169 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10170 dw2_asm_output_data (4, 0xffffffff,
10171 "Initial length escape value indicating 64-bit DWARF extension");
10172 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
10173 "Length of Source Line Info");
10174 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
10176 dw2_asm_output_data (2, ver
, "DWARF Version");
10177 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
10178 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
10180 /* Define the architecture-dependent minimum instruction length (in bytes).
10181 In this implementation of DWARF, this field is used for information
10182 purposes only. Since GCC generates assembly language, we have no
10183 a priori knowledge of how many instruction bytes are generated for each
10184 source line, and therefore can use only the DW_LNE_set_address and
10185 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10186 this as '1', which is "correct enough" for all architectures,
10187 and don't let the target override. */
10188 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10191 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
10192 "Maximum Operations Per Instruction");
10193 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
10194 "Default is_stmt_start flag");
10195 dw2_asm_output_data (1, DWARF_LINE_BASE
,
10196 "Line Base Value (Special Opcodes)");
10197 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
10198 "Line Range Value (Special Opcodes)");
10199 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
10200 "Special Opcode Base");
10202 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
10207 case DW_LNS_advance_pc
:
10208 case DW_LNS_advance_line
:
10209 case DW_LNS_set_file
:
10210 case DW_LNS_set_column
:
10211 case DW_LNS_fixed_advance_pc
:
10212 case DW_LNS_set_isa
:
10220 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
10224 /* Write out the information about the files we use. */
10225 output_file_names ();
10226 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
10229 /* Output the marker for the end of the line number info. */
10230 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10234 if (separate_line_info
)
10236 dw_line_info_table
*table
;
10239 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
10242 output_one_line_info_table (table
);
10246 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
10248 output_one_line_info_table (cold_text_section_line_info
);
10252 /* ??? Some Darwin linkers crash on a .debug_line section with no
10253 sequences. Further, merely a DW_LNE_end_sequence entry is not
10254 sufficient -- the address column must also be initialized.
10255 Make sure to output at least one set_address/end_sequence pair,
10256 choosing .text since that section is always present. */
10257 if (text_section_line_info
->in_use
|| !saw_one
)
10258 output_one_line_info_table (text_section_line_info
);
10260 /* Output the marker for the end of the line number info. */
10261 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10264 /* Given a pointer to a tree node for some base type, return a pointer to
10265 a DIE that describes the given type.
10267 This routine must only be called for GCC type nodes that correspond to
10268 Dwarf base (fundamental) types. */
10271 base_type_die (tree type
)
10273 dw_die_ref base_type_result
;
10274 enum dwarf_type encoding
;
10276 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
10279 /* If this is a subtype that should not be emitted as a subrange type,
10280 use the base type. See subrange_type_for_debug_p. */
10281 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
10282 type
= TREE_TYPE (type
);
10284 switch (TREE_CODE (type
))
10287 if ((dwarf_version
>= 4 || !dwarf_strict
)
10288 && TYPE_NAME (type
)
10289 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10290 && DECL_IS_BUILTIN (TYPE_NAME (type
))
10291 && DECL_NAME (TYPE_NAME (type
)))
10293 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
10294 if (strcmp (name
, "char16_t") == 0
10295 || strcmp (name
, "char32_t") == 0)
10297 encoding
= DW_ATE_UTF
;
10301 if (TYPE_STRING_FLAG (type
))
10303 if (TYPE_UNSIGNED (type
))
10304 encoding
= DW_ATE_unsigned_char
;
10306 encoding
= DW_ATE_signed_char
;
10308 else if (TYPE_UNSIGNED (type
))
10309 encoding
= DW_ATE_unsigned
;
10311 encoding
= DW_ATE_signed
;
10315 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
10317 if (dwarf_version
>= 3 || !dwarf_strict
)
10318 encoding
= DW_ATE_decimal_float
;
10320 encoding
= DW_ATE_lo_user
;
10323 encoding
= DW_ATE_float
;
10326 case FIXED_POINT_TYPE
:
10327 if (!(dwarf_version
>= 3 || !dwarf_strict
))
10328 encoding
= DW_ATE_lo_user
;
10329 else if (TYPE_UNSIGNED (type
))
10330 encoding
= DW_ATE_unsigned_fixed
;
10332 encoding
= DW_ATE_signed_fixed
;
10335 /* Dwarf2 doesn't know anything about complex ints, so use
10336 a user defined type for it. */
10338 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10339 encoding
= DW_ATE_complex_float
;
10341 encoding
= DW_ATE_lo_user
;
10345 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10346 encoding
= DW_ATE_boolean
;
10350 /* No other TREE_CODEs are Dwarf fundamental types. */
10351 gcc_unreachable ();
10354 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10356 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10357 int_size_in_bytes (type
));
10358 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10359 add_pubtype (type
, base_type_result
);
10361 return base_type_result
;
10364 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
10365 named 'auto' in its type: return true for it, false otherwise. */
10368 is_cxx_auto (tree type
)
10372 tree name
= TYPE_IDENTIFIER (type
);
10373 if (name
== get_identifier ("auto")
10374 || name
== get_identifier ("decltype(auto)"))
10380 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10381 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10384 is_base_type (tree type
)
10386 switch (TREE_CODE (type
))
10392 case FIXED_POINT_TYPE
:
10395 case POINTER_BOUNDS_TYPE
:
10401 case QUAL_UNION_TYPE
:
10402 case ENUMERAL_TYPE
:
10403 case FUNCTION_TYPE
:
10406 case REFERENCE_TYPE
:
10414 if (is_cxx_auto (type
))
10416 gcc_unreachable ();
10422 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10423 node, return the size in bits for the type if it is a constant, or else
10424 return the alignment for the type if the type's size is not constant, or
10425 else return BITS_PER_WORD if the type actually turns out to be an
10426 ERROR_MARK node. */
10428 static inline unsigned HOST_WIDE_INT
10429 simple_type_size_in_bits (const_tree type
)
10431 if (TREE_CODE (type
) == ERROR_MARK
)
10432 return BITS_PER_WORD
;
10433 else if (TYPE_SIZE (type
) == NULL_TREE
)
10435 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
10436 return tree_to_uhwi (TYPE_SIZE (type
));
10438 return TYPE_ALIGN (type
);
10441 /* Similarly, but return an offset_int instead of UHWI. */
10443 static inline offset_int
10444 offset_int_type_size_in_bits (const_tree type
)
10446 if (TREE_CODE (type
) == ERROR_MARK
)
10447 return BITS_PER_WORD
;
10448 else if (TYPE_SIZE (type
) == NULL_TREE
)
10450 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10451 return wi::to_offset (TYPE_SIZE (type
));
10453 return TYPE_ALIGN (type
);
10456 /* Given a pointer to a tree node for a subrange type, return a pointer
10457 to a DIE that describes the given type. */
10460 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10462 dw_die_ref subrange_die
;
10463 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10465 if (context_die
== NULL
)
10466 context_die
= comp_unit_die ();
10468 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10470 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10472 /* The size of the subrange type and its base type do not match,
10473 so we need to generate a size attribute for the subrange type. */
10474 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10478 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
10480 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
10482 return subrange_die
;
10485 /* Returns the (const and/or volatile) cv_qualifiers associated with
10486 the decl node. This will normally be augmented with the
10487 cv_qualifiers of the underlying type in add_type_attribute. */
10490 decl_quals (const_tree decl
)
10492 return ((TREE_READONLY (decl
)
10493 ? TYPE_QUAL_CONST
: TYPE_UNQUALIFIED
)
10494 | (TREE_THIS_VOLATILE (decl
)
10495 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
));
10498 /* Determine the TYPE whose qualifiers match the largest strict subset
10499 of the given TYPE_QUALS, and return its qualifiers. Ignore all
10500 qualifiers outside QUAL_MASK. */
10503 get_nearest_type_subqualifiers (tree type
, int type_quals
, int qual_mask
)
10506 int best_rank
= 0, best_qual
= 0, max_rank
;
10508 type_quals
&= qual_mask
;
10509 max_rank
= popcount_hwi (type_quals
) - 1;
10511 for (t
= TYPE_MAIN_VARIANT (type
); t
&& best_rank
< max_rank
;
10512 t
= TYPE_NEXT_VARIANT (t
))
10514 int q
= TYPE_QUALS (t
) & qual_mask
;
10516 if ((q
& type_quals
) == q
&& q
!= type_quals
10517 && check_base_type (t
, type
))
10519 int rank
= popcount_hwi (q
);
10521 if (rank
> best_rank
)
10532 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10533 entry that chains various modifiers in front of the given type. */
10536 modified_type_die (tree type
, int cv_quals
, dw_die_ref context_die
)
10538 enum tree_code code
= TREE_CODE (type
);
10539 dw_die_ref mod_type_die
;
10540 dw_die_ref sub_die
= NULL
;
10541 tree item_type
= NULL
;
10542 tree qualified_type
;
10543 tree name
, low
, high
;
10544 dw_die_ref mod_scope
;
10545 /* Only these cv-qualifiers are currently handled. */
10546 const int cv_qual_mask
= (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
10547 | TYPE_QUAL_RESTRICT
);
10549 if (code
== ERROR_MARK
)
10552 cv_quals
&= cv_qual_mask
;
10554 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
10555 tag modifier (and not an attribute) old consumers won't be able
10557 if (dwarf_version
< 3)
10558 cv_quals
&= ~TYPE_QUAL_RESTRICT
;
10560 /* See if we already have the appropriately qualified variant of
10562 qualified_type
= get_qualified_type (type
, cv_quals
);
10564 if (qualified_type
== sizetype
10565 && TYPE_NAME (qualified_type
)
10566 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10568 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10570 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10571 && TYPE_PRECISION (t
)
10572 == TYPE_PRECISION (qualified_type
)
10573 && TYPE_UNSIGNED (t
)
10574 == TYPE_UNSIGNED (qualified_type
));
10575 qualified_type
= t
;
10578 /* If we do, then we can just use its DIE, if it exists. */
10579 if (qualified_type
)
10581 mod_type_die
= lookup_type_die (qualified_type
);
10583 return mod_type_die
;
10586 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10588 /* Handle C typedef types. */
10589 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10590 && !DECL_ARTIFICIAL (name
))
10592 tree dtype
= TREE_TYPE (name
);
10594 if (qualified_type
== dtype
)
10596 /* For a named type, use the typedef. */
10597 gen_type_die (qualified_type
, context_die
);
10598 return lookup_type_die (qualified_type
);
10602 int dquals
= TYPE_QUALS_NO_ADDR_SPACE (dtype
);
10603 dquals
&= cv_qual_mask
;
10604 if ((dquals
& ~cv_quals
) != TYPE_UNQUALIFIED
10605 || (cv_quals
== dquals
&& DECL_ORIGINAL_TYPE (name
) != type
))
10606 /* cv-unqualified version of named type. Just use
10607 the unnamed type to which it refers. */
10608 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10609 cv_quals
, context_die
);
10610 /* Else cv-qualified version of named type; fall through. */
10614 mod_scope
= scope_die_for (type
, context_die
);
10618 struct qual_info
{ int q
; enum dwarf_tag t
; };
10619 static const struct qual_info qual_info
[] =
10621 { TYPE_QUAL_RESTRICT
, DW_TAG_restrict_type
},
10622 { TYPE_QUAL_VOLATILE
, DW_TAG_volatile_type
},
10623 { TYPE_QUAL_CONST
, DW_TAG_const_type
},
10628 /* Determine a lesser qualified type that most closely matches
10629 this one. Then generate DW_TAG_* entries for the remaining
10631 sub_quals
= get_nearest_type_subqualifiers (type
, cv_quals
,
10633 mod_type_die
= modified_type_die (type
, sub_quals
, context_die
);
10635 for (i
= 0; i
< sizeof (qual_info
) / sizeof (qual_info
[0]); i
++)
10636 if (qual_info
[i
].q
& cv_quals
& ~sub_quals
)
10638 dw_die_ref d
= new_die (qual_info
[i
].t
, mod_scope
, type
);
10640 add_AT_die_ref (d
, DW_AT_type
, mod_type_die
);
10644 else if (code
== POINTER_TYPE
)
10646 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10647 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10648 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10649 item_type
= TREE_TYPE (type
);
10650 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10651 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10652 TYPE_ADDR_SPACE (item_type
));
10654 else if (code
== REFERENCE_TYPE
)
10656 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10657 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10660 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10661 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10662 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10663 item_type
= TREE_TYPE (type
);
10664 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10665 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10666 TYPE_ADDR_SPACE (item_type
));
10668 else if (code
== INTEGER_TYPE
10669 && TREE_TYPE (type
) != NULL_TREE
10670 && subrange_type_for_debug_p (type
, &low
, &high
))
10672 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10673 item_type
= TREE_TYPE (type
);
10675 else if (is_base_type (type
))
10676 mod_type_die
= base_type_die (type
);
10679 gen_type_die (type
, context_die
);
10681 /* We have to get the type_main_variant here (and pass that to the
10682 `lookup_type_die' routine) because the ..._TYPE node we have
10683 might simply be a *copy* of some original type node (where the
10684 copy was created to help us keep track of typedef names) and
10685 that copy might have a different TYPE_UID from the original
10687 if (TREE_CODE (type
) != VECTOR_TYPE
)
10688 return lookup_type_die (type_main_variant (type
));
10690 /* Vectors have the debugging information in the type,
10691 not the main variant. */
10692 return lookup_type_die (type
);
10695 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10696 don't output a DW_TAG_typedef, since there isn't one in the
10697 user's program; just attach a DW_AT_name to the type.
10698 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10699 if the base type already has the same name. */
10701 && ((TREE_CODE (name
) != TYPE_DECL
10702 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10703 || (cv_quals
== TYPE_UNQUALIFIED
)))
10704 || (TREE_CODE (name
) == TYPE_DECL
10705 && TREE_TYPE (name
) == qualified_type
10706 && DECL_NAME (name
))))
10708 if (TREE_CODE (name
) == TYPE_DECL
)
10709 /* Could just call add_name_and_src_coords_attributes here,
10710 but since this is a builtin type it doesn't have any
10711 useful source coordinates anyway. */
10712 name
= DECL_NAME (name
);
10713 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10715 /* This probably indicates a bug. */
10716 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10718 name
= TYPE_IDENTIFIER (type
);
10719 add_name_attribute (mod_type_die
,
10720 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10723 if (qualified_type
)
10724 equate_type_number_to_die (qualified_type
, mod_type_die
);
10727 /* We must do this after the equate_type_number_to_die call, in case
10728 this is a recursive type. This ensures that the modified_type_die
10729 recursion will terminate even if the type is recursive. Recursive
10730 types are possible in Ada. */
10731 sub_die
= modified_type_die (item_type
,
10732 TYPE_QUALS_NO_ADDR_SPACE (item_type
),
10735 if (sub_die
!= NULL
)
10736 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10738 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10739 if (TYPE_ARTIFICIAL (type
))
10740 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10742 return mod_type_die
;
10745 /* Generate DIEs for the generic parameters of T.
10746 T must be either a generic type or a generic function.
10747 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10750 gen_generic_params_dies (tree t
)
10754 dw_die_ref die
= NULL
;
10757 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10761 die
= lookup_type_die (t
);
10762 else if (DECL_P (t
))
10763 die
= lookup_decl_die (t
);
10767 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10769 /* T has no generic parameter. It means T is neither a generic type
10770 or function. End of story. */
10773 parms_num
= TREE_VEC_LENGTH (parms
);
10774 args
= lang_hooks
.get_innermost_generic_args (t
);
10775 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
10776 non_default
= int_cst_value (TREE_CHAIN (args
));
10778 non_default
= TREE_VEC_LENGTH (args
);
10779 for (i
= 0; i
< parms_num
; i
++)
10781 tree parm
, arg
, arg_pack_elems
;
10782 dw_die_ref parm_die
;
10784 parm
= TREE_VEC_ELT (parms
, i
);
10785 arg
= TREE_VEC_ELT (args
, i
);
10786 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
10787 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
10789 if (parm
&& TREE_VALUE (parm
) && arg
)
10791 /* If PARM represents a template parameter pack,
10792 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10793 by DW_TAG_template_*_parameter DIEs for the argument
10794 pack elements of ARG. Note that ARG would then be
10795 an argument pack. */
10796 if (arg_pack_elems
)
10797 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
10801 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
10802 true /* emit name */, die
);
10803 if (i
>= non_default
)
10804 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
10809 /* Create and return a DIE for PARM which should be
10810 the representation of a generic type parameter.
10811 For instance, in the C++ front end, PARM would be a template parameter.
10812 ARG is the argument to PARM.
10813 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10815 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10816 as a child node. */
10819 generic_parameter_die (tree parm
, tree arg
,
10821 dw_die_ref parent_die
)
10823 dw_die_ref tmpl_die
= NULL
;
10824 const char *name
= NULL
;
10826 if (!parm
|| !DECL_NAME (parm
) || !arg
)
10829 /* We support non-type generic parameters and arguments,
10830 type generic parameters and arguments, as well as
10831 generic generic parameters (a.k.a. template template parameters in C++)
10833 if (TREE_CODE (parm
) == PARM_DECL
)
10834 /* PARM is a nontype generic parameter */
10835 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
10836 else if (TREE_CODE (parm
) == TYPE_DECL
)
10837 /* PARM is a type generic parameter. */
10838 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
10839 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10840 /* PARM is a generic generic parameter.
10841 Its DIE is a GNU extension. It shall have a
10842 DW_AT_name attribute to represent the name of the template template
10843 parameter, and a DW_AT_GNU_template_name attribute to represent the
10844 name of the template template argument. */
10845 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
10848 gcc_unreachable ();
10854 /* If PARM is a generic parameter pack, it means we are
10855 emitting debug info for a template argument pack element.
10856 In other terms, ARG is a template argument pack element.
10857 In that case, we don't emit any DW_AT_name attribute for
10861 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
10863 add_AT_string (tmpl_die
, DW_AT_name
, name
);
10866 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10868 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10869 TMPL_DIE should have a child DW_AT_type attribute that is set
10870 to the type of the argument to PARM, which is ARG.
10871 If PARM is a type generic parameter, TMPL_DIE should have a
10872 child DW_AT_type that is set to ARG. */
10873 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
10874 add_type_attribute (tmpl_die
, tmpl_type
,
10875 (TREE_THIS_VOLATILE (tmpl_type
)
10876 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
),
10881 /* So TMPL_DIE is a DIE representing a
10882 a generic generic template parameter, a.k.a template template
10883 parameter in C++ and arg is a template. */
10885 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10886 to the name of the argument. */
10887 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
10889 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
10892 if (TREE_CODE (parm
) == PARM_DECL
)
10893 /* So PARM is a non-type generic parameter.
10894 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10895 attribute of TMPL_DIE which value represents the value
10897 We must be careful here:
10898 The value of ARG might reference some function decls.
10899 We might currently be emitting debug info for a generic
10900 type and types are emitted before function decls, we don't
10901 know if the function decls referenced by ARG will actually be
10902 emitted after cgraph computations.
10903 So must defer the generation of the DW_AT_const_value to
10904 after cgraph is ready. */
10905 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
10911 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10912 PARM_PACK must be a template parameter pack. The returned DIE
10913 will be child DIE of PARENT_DIE. */
10916 template_parameter_pack_die (tree parm_pack
,
10917 tree parm_pack_args
,
10918 dw_die_ref parent_die
)
10923 gcc_assert (parent_die
&& parm_pack
);
10925 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
10926 add_name_and_src_coords_attributes (die
, parm_pack
);
10927 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
10928 generic_parameter_die (parm_pack
,
10929 TREE_VEC_ELT (parm_pack_args
, j
),
10930 false /* Don't emit DW_AT_name */,
10935 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10936 an enumerated type. */
10939 type_is_enum (const_tree type
)
10941 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10944 /* Return the DBX register number described by a given RTL node. */
10946 static unsigned int
10947 dbx_reg_number (const_rtx rtl
)
10949 unsigned regno
= REGNO (rtl
);
10951 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10953 #ifdef LEAF_REG_REMAP
10954 if (crtl
->uses_only_leaf_regs
)
10956 int leaf_reg
= LEAF_REG_REMAP (regno
);
10957 if (leaf_reg
!= -1)
10958 regno
= (unsigned) leaf_reg
;
10962 regno
= DBX_REGISTER_NUMBER (regno
);
10963 gcc_assert (regno
!= INVALID_REGNUM
);
10967 /* Optionally add a DW_OP_piece term to a location description expression.
10968 DW_OP_piece is only added if the location description expression already
10969 doesn't end with DW_OP_piece. */
10972 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10974 dw_loc_descr_ref loc
;
10976 if (*list_head
!= NULL
)
10978 /* Find the end of the chain. */
10979 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10982 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10983 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10987 /* Return a location descriptor that designates a machine register or
10988 zero if there is none. */
10990 static dw_loc_descr_ref
10991 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10995 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10998 /* We only use "frame base" when we're sure we're talking about the
10999 post-prologue local stack frame. We do this by *not* running
11000 register elimination until this point, and recognizing the special
11001 argument pointer and soft frame pointer rtx's.
11002 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
11003 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
11004 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
11006 dw_loc_descr_ref result
= NULL
;
11008 if (dwarf_version
>= 4 || !dwarf_strict
)
11010 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
11013 add_loc_descr (&result
,
11014 new_loc_descr (DW_OP_stack_value
, 0, 0));
11019 regs
= targetm
.dwarf_register_span (rtl
);
11021 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
11022 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
11025 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
11026 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
11028 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
11032 /* Return a location descriptor that designates a machine register for
11033 a given hard register number. */
11035 static dw_loc_descr_ref
11036 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
11038 dw_loc_descr_ref reg_loc_descr
;
11042 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
11044 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
11046 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11047 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11049 return reg_loc_descr
;
11052 /* Given an RTL of a register, return a location descriptor that
11053 designates a value that spans more than one register. */
11055 static dw_loc_descr_ref
11056 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
11057 enum var_init_status initialized
)
11060 dw_loc_descr_ref loc_result
= NULL
;
11062 /* Simple, contiguous registers. */
11063 if (regs
== NULL_RTX
)
11065 unsigned reg
= REGNO (rtl
);
11068 #ifdef LEAF_REG_REMAP
11069 if (crtl
->uses_only_leaf_regs
)
11071 int leaf_reg
= LEAF_REG_REMAP (reg
);
11072 if (leaf_reg
!= -1)
11073 reg
= (unsigned) leaf_reg
;
11077 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
11078 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
11080 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
11085 dw_loc_descr_ref t
;
11087 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
11088 VAR_INIT_STATUS_INITIALIZED
);
11089 add_loc_descr (&loc_result
, t
);
11090 add_loc_descr_op_piece (&loc_result
, size
);
11096 /* Now onto stupid register sets in non contiguous locations. */
11098 gcc_assert (GET_CODE (regs
) == PARALLEL
);
11100 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
11103 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
11105 dw_loc_descr_ref t
;
11107 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
11108 VAR_INIT_STATUS_INITIALIZED
);
11109 add_loc_descr (&loc_result
, t
);
11110 add_loc_descr_op_piece (&loc_result
, size
);
11113 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11114 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11118 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
11120 /* Return a location descriptor that designates a constant i,
11121 as a compound operation from constant (i >> shift), constant shift
11124 static dw_loc_descr_ref
11125 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11127 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
11128 add_loc_descr (&ret
, int_loc_descriptor (shift
));
11129 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11133 /* Return a location descriptor that designates a constant. */
11135 static dw_loc_descr_ref
11136 int_loc_descriptor (HOST_WIDE_INT i
)
11138 enum dwarf_location_atom op
;
11140 /* Pick the smallest representation of a constant, rather than just
11141 defaulting to the LEB encoding. */
11144 int clz
= clz_hwi (i
);
11145 int ctz
= ctz_hwi (i
);
11147 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
11148 else if (i
<= 0xff)
11149 op
= DW_OP_const1u
;
11150 else if (i
<= 0xffff)
11151 op
= DW_OP_const2u
;
11152 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11153 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11154 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
11155 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
11156 while DW_OP_const4u is 5 bytes. */
11157 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
11158 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11159 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11160 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
11161 while DW_OP_const4u is 5 bytes. */
11162 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11163 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11164 op
= DW_OP_const4u
;
11165 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11166 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11167 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
11168 while DW_OP_constu of constant >= 0x100000000 takes at least
11170 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11171 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11172 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
11173 >= HOST_BITS_PER_WIDE_INT
)
11174 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
11175 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
11176 while DW_OP_constu takes in this case at least 6 bytes. */
11177 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
11178 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11179 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11180 && size_of_uleb128 (i
) > 6)
11181 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
11182 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
11189 op
= DW_OP_const1s
;
11190 else if (i
>= -0x8000)
11191 op
= DW_OP_const2s
;
11192 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11194 if (size_of_int_loc_descriptor (i
) < 5)
11196 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11197 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11200 op
= DW_OP_const4s
;
11204 if (size_of_int_loc_descriptor (i
)
11205 < (unsigned long) 1 + size_of_sleb128 (i
))
11207 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11208 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11215 return new_loc_descr (op
, i
, 0);
11218 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
11219 without actually allocating it. */
11221 static unsigned long
11222 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11224 return size_of_int_loc_descriptor (i
>> shift
)
11225 + size_of_int_loc_descriptor (shift
)
11229 /* Return size_of_locs (int_loc_descriptor (i)) without
11230 actually allocating it. */
11232 static unsigned long
11233 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
11242 else if (i
<= 0xff)
11244 else if (i
<= 0xffff)
11248 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11249 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11250 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11252 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11253 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11254 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11256 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11258 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
11259 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11260 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11261 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11263 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11264 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
11265 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11267 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11268 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11270 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11279 else if (i
>= -0x8000)
11281 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11283 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11285 s
= size_of_int_loc_descriptor (-i
) + 1;
11293 unsigned long r
= 1 + size_of_sleb128 (i
);
11294 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11296 s
= size_of_int_loc_descriptor (-i
) + 1;
11305 /* Return loc description representing "address" of integer value.
11306 This can appear only as toplevel expression. */
11308 static dw_loc_descr_ref
11309 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
11312 dw_loc_descr_ref loc_result
= NULL
;
11314 if (!(dwarf_version
>= 4 || !dwarf_strict
))
11317 litsize
= size_of_int_loc_descriptor (i
);
11318 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
11319 is more compact. For DW_OP_stack_value we need:
11320 litsize + 1 (DW_OP_stack_value)
11321 and for DW_OP_implicit_value:
11322 1 (DW_OP_implicit_value) + 1 (length) + size. */
11323 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
11325 loc_result
= int_loc_descriptor (i
);
11326 add_loc_descr (&loc_result
,
11327 new_loc_descr (DW_OP_stack_value
, 0, 0));
11331 loc_result
= new_loc_descr (DW_OP_implicit_value
,
11333 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
11334 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
11338 /* Return a location descriptor that designates a base+offset location. */
11340 static dw_loc_descr_ref
11341 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
11342 enum var_init_status initialized
)
11344 unsigned int regno
;
11345 dw_loc_descr_ref result
;
11346 dw_fde_ref fde
= cfun
->fde
;
11348 /* We only use "frame base" when we're sure we're talking about the
11349 post-prologue local stack frame. We do this by *not* running
11350 register elimination until this point, and recognizing the special
11351 argument pointer and soft frame pointer rtx's. */
11352 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
11354 rtx elim
= (ira_use_lra_p
11355 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
11356 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
11360 if (GET_CODE (elim
) == PLUS
)
11362 offset
+= INTVAL (XEXP (elim
, 1));
11363 elim
= XEXP (elim
, 0);
11365 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11366 && (elim
== hard_frame_pointer_rtx
11367 || elim
== stack_pointer_rtx
))
11368 || elim
== (frame_pointer_needed
11369 ? hard_frame_pointer_rtx
11370 : stack_pointer_rtx
));
11372 /* If drap register is used to align stack, use frame
11373 pointer + offset to access stack variables. If stack
11374 is aligned without drap, use stack pointer + offset to
11375 access stack variables. */
11376 if (crtl
->stack_realign_tried
11377 && reg
== frame_pointer_rtx
)
11380 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
11381 ? HARD_FRAME_POINTER_REGNUM
11383 return new_reg_loc_descr (base_reg
, offset
);
11386 gcc_assert (frame_pointer_fb_offset_valid
);
11387 offset
+= frame_pointer_fb_offset
;
11388 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11392 regno
= REGNO (reg
);
11393 #ifdef LEAF_REG_REMAP
11394 if (crtl
->uses_only_leaf_regs
)
11396 int leaf_reg
= LEAF_REG_REMAP (regno
);
11397 if (leaf_reg
!= -1)
11398 regno
= (unsigned) leaf_reg
;
11401 regno
= DWARF_FRAME_REGNUM (regno
);
11403 if (!optimize
&& fde
11404 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
11406 /* Use cfa+offset to represent the location of arguments passed
11407 on the stack when drap is used to align stack.
11408 Only do this when not optimizing, for optimized code var-tracking
11409 is supposed to track where the arguments live and the register
11410 used as vdrap or drap in some spot might be used for something
11411 else in other part of the routine. */
11412 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11416 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
11419 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
11421 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11422 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11427 /* Return true if this RTL expression describes a base+offset calculation. */
11430 is_based_loc (const_rtx rtl
)
11432 return (GET_CODE (rtl
) == PLUS
11433 && ((REG_P (XEXP (rtl
, 0))
11434 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
11435 && CONST_INT_P (XEXP (rtl
, 1)))));
11438 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11441 static dw_loc_descr_ref
11442 tls_mem_loc_descriptor (rtx mem
)
11445 dw_loc_descr_ref loc_result
;
11447 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
11450 base
= get_base_address (MEM_EXPR (mem
));
11452 || TREE_CODE (base
) != VAR_DECL
11453 || !DECL_THREAD_LOCAL_P (base
))
11456 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
11457 if (loc_result
== NULL
)
11460 if (MEM_OFFSET (mem
))
11461 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
11466 /* Output debug info about reason why we failed to expand expression as dwarf
11470 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
11472 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
11474 fprintf (dump_file
, "Failed to expand as dwarf: ");
11476 print_generic_expr (dump_file
, expr
, dump_flags
);
11479 fprintf (dump_file
, "\n");
11480 print_rtl (dump_file
, rtl
);
11482 fprintf (dump_file
, "\nReason: %s\n", reason
);
11486 /* Helper function for const_ok_for_output. */
11489 const_ok_for_output_1 (rtx rtl
)
11491 if (GET_CODE (rtl
) == UNSPEC
)
11493 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11494 we can't express it in the debug info. */
11495 #ifdef ENABLE_CHECKING
11496 /* Don't complain about TLS UNSPECs, those are just too hard to
11497 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11498 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11499 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11500 if (XVECLEN (rtl
, 0) == 0
11501 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11502 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
11503 inform (current_function_decl
11504 ? DECL_SOURCE_LOCATION (current_function_decl
)
11505 : UNKNOWN_LOCATION
,
11506 #if NUM_UNSPEC_VALUES > 0
11507 "non-delegitimized UNSPEC %s (%d) found in variable location",
11508 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11509 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11512 "non-delegitimized UNSPEC %d found in variable location",
11516 expansion_failed (NULL_TREE
, rtl
,
11517 "UNSPEC hasn't been delegitimized.\n");
11521 if (targetm
.const_not_ok_for_debug_p (rtl
))
11523 expansion_failed (NULL_TREE
, rtl
,
11524 "Expression rejected for debug by the backend.\n");
11528 /* FIXME: Refer to PR60655. It is possible for simplification
11529 of rtl expressions in var tracking to produce such expressions.
11530 We should really identify / validate expressions
11531 enclosed in CONST that can be handled by assemblers on various
11532 targets and only handle legitimate cases here. */
11533 if (GET_CODE (rtl
) != SYMBOL_REF
)
11535 if (GET_CODE (rtl
) == NOT
)
11540 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11543 get_pool_constant_mark (rtl
, &marked
);
11544 /* If all references to this pool constant were optimized away,
11545 it was not output and thus we can't represent it. */
11548 expansion_failed (NULL_TREE
, rtl
,
11549 "Constant was removed from constant pool.\n");
11554 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11557 /* Avoid references to external symbols in debug info, on several targets
11558 the linker might even refuse to link when linking a shared library,
11559 and in many other cases the relocations for .debug_info/.debug_loc are
11560 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11561 to be defined within the same shared library or executable are fine. */
11562 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11564 tree decl
= SYMBOL_REF_DECL (rtl
);
11566 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11568 expansion_failed (NULL_TREE
, rtl
,
11569 "Symbol not defined in current TU.\n");
11577 /* Return true if constant RTL can be emitted in DW_OP_addr or
11578 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11579 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11582 const_ok_for_output (rtx rtl
)
11584 if (GET_CODE (rtl
) == SYMBOL_REF
)
11585 return const_ok_for_output_1 (rtl
);
11587 if (GET_CODE (rtl
) == CONST
)
11589 subrtx_var_iterator::array_type array
;
11590 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
11591 if (!const_ok_for_output_1 (*iter
))
11599 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11600 if possible, NULL otherwise. */
11603 base_type_for_mode (machine_mode mode
, bool unsignedp
)
11605 dw_die_ref type_die
;
11606 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11610 switch (TREE_CODE (type
))
11618 type_die
= lookup_type_die (type
);
11620 type_die
= modified_type_die (type
, TYPE_UNQUALIFIED
, comp_unit_die ());
11621 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11626 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11627 type matching MODE, or, if MODE is narrower than or as wide as
11628 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11631 static dw_loc_descr_ref
11632 convert_descriptor_to_mode (machine_mode mode
, dw_loc_descr_ref op
)
11634 machine_mode outer_mode
= mode
;
11635 dw_die_ref type_die
;
11636 dw_loc_descr_ref cvt
;
11638 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11640 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11643 type_die
= base_type_for_mode (outer_mode
, 1);
11644 if (type_die
== NULL
)
11646 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11647 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11648 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11649 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11650 add_loc_descr (&op
, cvt
);
11654 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11656 static dw_loc_descr_ref
11657 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11658 dw_loc_descr_ref op1
)
11660 dw_loc_descr_ref ret
= op0
;
11661 add_loc_descr (&ret
, op1
);
11662 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11663 if (STORE_FLAG_VALUE
!= 1)
11665 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11666 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11671 /* Return location descriptor for signed comparison OP RTL. */
11673 static dw_loc_descr_ref
11674 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11675 machine_mode mem_mode
)
11677 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11678 dw_loc_descr_ref op0
, op1
;
11681 if (op_mode
== VOIDmode
)
11682 op_mode
= GET_MODE (XEXP (rtl
, 1));
11683 if (op_mode
== VOIDmode
)
11687 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11688 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11691 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11692 VAR_INIT_STATUS_INITIALIZED
);
11693 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11694 VAR_INIT_STATUS_INITIALIZED
);
11696 if (op0
== NULL
|| op1
== NULL
)
11699 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11700 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11701 return compare_loc_descriptor (op
, op0
, op1
);
11703 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11705 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11706 dw_loc_descr_ref cvt
;
11708 if (type_die
== NULL
)
11710 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11711 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11712 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11713 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11714 add_loc_descr (&op0
, cvt
);
11715 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11716 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11717 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11718 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11719 add_loc_descr (&op1
, cvt
);
11720 return compare_loc_descriptor (op
, op0
, op1
);
11723 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11724 /* For eq/ne, if the operands are known to be zero-extended,
11725 there is no need to do the fancy shifting up. */
11726 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11728 dw_loc_descr_ref last0
, last1
;
11729 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11731 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11733 /* deref_size zero extends, and for constants we can check
11734 whether they are zero extended or not. */
11735 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11736 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11737 || (CONST_INT_P (XEXP (rtl
, 0))
11738 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11739 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11740 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11741 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11742 || (CONST_INT_P (XEXP (rtl
, 1))
11743 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11744 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11745 return compare_loc_descriptor (op
, op0
, op1
);
11747 /* EQ/NE comparison against constant in narrower type than
11748 DWARF2_ADDR_SIZE can be performed either as
11749 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11752 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11753 DW_OP_{eq,ne}. Pick whatever is shorter. */
11754 if (CONST_INT_P (XEXP (rtl
, 1))
11755 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11756 && (size_of_int_loc_descriptor (shift
) + 1
11757 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11758 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11759 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11760 & GET_MODE_MASK (op_mode
))))
11762 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11763 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11764 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11765 & GET_MODE_MASK (op_mode
));
11766 return compare_loc_descriptor (op
, op0
, op1
);
11769 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11770 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11771 if (CONST_INT_P (XEXP (rtl
, 1)))
11772 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11775 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11776 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11778 return compare_loc_descriptor (op
, op0
, op1
);
11781 /* Return location descriptor for unsigned comparison OP RTL. */
11783 static dw_loc_descr_ref
11784 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11785 machine_mode mem_mode
)
11787 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11788 dw_loc_descr_ref op0
, op1
;
11790 if (op_mode
== VOIDmode
)
11791 op_mode
= GET_MODE (XEXP (rtl
, 1));
11792 if (op_mode
== VOIDmode
)
11794 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
11797 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11800 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11801 VAR_INIT_STATUS_INITIALIZED
);
11802 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11803 VAR_INIT_STATUS_INITIALIZED
);
11805 if (op0
== NULL
|| op1
== NULL
)
11808 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
11810 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
11811 dw_loc_descr_ref last0
, last1
;
11812 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11814 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11816 if (CONST_INT_P (XEXP (rtl
, 0)))
11817 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
11818 /* deref_size zero extends, so no need to mask it again. */
11819 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
11820 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11822 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11823 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11825 if (CONST_INT_P (XEXP (rtl
, 1)))
11826 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
11827 /* deref_size zero extends, so no need to mask it again. */
11828 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
11829 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11831 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11832 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11835 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11837 HOST_WIDE_INT bias
= 1;
11838 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11839 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11840 if (CONST_INT_P (XEXP (rtl
, 1)))
11841 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
11842 + INTVAL (XEXP (rtl
, 1)));
11844 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
11847 return compare_loc_descriptor (op
, op0
, op1
);
11850 /* Return location descriptor for {U,S}{MIN,MAX}. */
11852 static dw_loc_descr_ref
11853 minmax_loc_descriptor (rtx rtl
, machine_mode mode
,
11854 machine_mode mem_mode
)
11856 enum dwarf_location_atom op
;
11857 dw_loc_descr_ref op0
, op1
, ret
;
11858 dw_loc_descr_ref bra_node
, drop_node
;
11861 && (GET_MODE_CLASS (mode
) != MODE_INT
11862 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
11865 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11866 VAR_INIT_STATUS_INITIALIZED
);
11867 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11868 VAR_INIT_STATUS_INITIALIZED
);
11870 if (op0
== NULL
|| op1
== NULL
)
11873 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
11874 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
11875 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
11876 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
11878 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11880 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
11881 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11882 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11883 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11884 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11886 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11888 HOST_WIDE_INT bias
= 1;
11889 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11890 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11891 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11894 else if (GET_MODE_CLASS (mode
) == MODE_INT
11895 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11897 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11898 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11899 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11900 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11901 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11903 else if (GET_MODE_CLASS (mode
) == MODE_INT
11904 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11906 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11907 dw_loc_descr_ref cvt
;
11908 if (type_die
== NULL
)
11910 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11911 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11912 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11913 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11914 add_loc_descr (&op0
, cvt
);
11915 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11916 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11917 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11918 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11919 add_loc_descr (&op1
, cvt
);
11922 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11927 add_loc_descr (&ret
, op1
);
11928 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11929 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11930 add_loc_descr (&ret
, bra_node
);
11931 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11932 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11933 add_loc_descr (&ret
, drop_node
);
11934 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11935 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11936 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11937 && GET_MODE_CLASS (mode
) == MODE_INT
11938 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11939 ret
= convert_descriptor_to_mode (mode
, ret
);
11943 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11944 but after converting arguments to type_die, afterwards
11945 convert back to unsigned. */
11947 static dw_loc_descr_ref
11948 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11949 machine_mode mode
, machine_mode mem_mode
)
11951 dw_loc_descr_ref cvt
, op0
, op1
;
11953 if (type_die
== NULL
)
11955 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11956 VAR_INIT_STATUS_INITIALIZED
);
11957 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11958 VAR_INIT_STATUS_INITIALIZED
);
11959 if (op0
== NULL
|| op1
== NULL
)
11961 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11962 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11963 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11964 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11965 add_loc_descr (&op0
, cvt
);
11966 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11967 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11968 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11969 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11970 add_loc_descr (&op1
, cvt
);
11971 add_loc_descr (&op0
, op1
);
11972 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11973 return convert_descriptor_to_mode (mode
, op0
);
11976 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11977 const0 is DW_OP_lit0 or corresponding typed constant,
11978 const1 is DW_OP_lit1 or corresponding typed constant
11979 and constMSB is constant with just the MSB bit set
11981 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11982 L1: const0 DW_OP_swap
11983 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11984 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11989 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11990 L1: const0 DW_OP_swap
11991 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11992 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11997 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11998 L1: const1 DW_OP_swap
11999 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12000 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12004 static dw_loc_descr_ref
12005 clz_loc_descriptor (rtx rtl
, machine_mode mode
,
12006 machine_mode mem_mode
)
12008 dw_loc_descr_ref op0
, ret
, tmp
;
12009 HOST_WIDE_INT valv
;
12010 dw_loc_descr_ref l1jump
, l1label
;
12011 dw_loc_descr_ref l2jump
, l2label
;
12012 dw_loc_descr_ref l3jump
, l3label
;
12013 dw_loc_descr_ref l4jump
, l4label
;
12016 if (GET_MODE_CLASS (mode
) != MODE_INT
12017 || GET_MODE (XEXP (rtl
, 0)) != mode
)
12020 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12021 VAR_INIT_STATUS_INITIALIZED
);
12025 if (GET_CODE (rtl
) == CLZ
)
12027 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
12028 valv
= GET_MODE_BITSIZE (mode
);
12030 else if (GET_CODE (rtl
) == FFS
)
12032 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
12033 valv
= GET_MODE_BITSIZE (mode
);
12034 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12035 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12036 add_loc_descr (&ret
, l1jump
);
12037 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12038 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
12039 VAR_INIT_STATUS_INITIALIZED
);
12042 add_loc_descr (&ret
, tmp
);
12043 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12044 add_loc_descr (&ret
, l4jump
);
12045 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
12046 ? const1_rtx
: const0_rtx
,
12048 VAR_INIT_STATUS_INITIALIZED
);
12049 if (l1label
== NULL
)
12051 add_loc_descr (&ret
, l1label
);
12052 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12053 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
12054 add_loc_descr (&ret
, l2label
);
12055 if (GET_CODE (rtl
) != CLZ
)
12057 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
12058 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
12059 << (GET_MODE_BITSIZE (mode
) - 1));
12061 msb
= immed_wide_int_const
12062 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
12063 GET_MODE_PRECISION (mode
)), mode
);
12064 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
12065 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12066 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
12067 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
12069 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
12070 VAR_INIT_STATUS_INITIALIZED
);
12073 add_loc_descr (&ret
, tmp
);
12074 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12075 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12076 add_loc_descr (&ret
, l3jump
);
12077 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12078 VAR_INIT_STATUS_INITIALIZED
);
12081 add_loc_descr (&ret
, tmp
);
12082 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
12083 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
12084 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12085 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
12086 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12087 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12088 add_loc_descr (&ret
, l2jump
);
12089 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
12090 add_loc_descr (&ret
, l3label
);
12091 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
12092 add_loc_descr (&ret
, l4label
);
12093 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12094 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12095 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12096 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12097 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12098 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
12099 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12100 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
12104 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
12105 const1 is DW_OP_lit1 or corresponding typed constant):
12107 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12108 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12112 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12113 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12116 static dw_loc_descr_ref
12117 popcount_loc_descriptor (rtx rtl
, machine_mode mode
,
12118 machine_mode mem_mode
)
12120 dw_loc_descr_ref op0
, ret
, tmp
;
12121 dw_loc_descr_ref l1jump
, l1label
;
12122 dw_loc_descr_ref l2jump
, l2label
;
12124 if (GET_MODE_CLASS (mode
) != MODE_INT
12125 || GET_MODE (XEXP (rtl
, 0)) != mode
)
12128 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12129 VAR_INIT_STATUS_INITIALIZED
);
12133 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12134 VAR_INIT_STATUS_INITIALIZED
);
12137 add_loc_descr (&ret
, tmp
);
12138 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12139 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
12140 add_loc_descr (&ret
, l1label
);
12141 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12142 add_loc_descr (&ret
, l2jump
);
12143 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12144 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12145 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12146 VAR_INIT_STATUS_INITIALIZED
);
12149 add_loc_descr (&ret
, tmp
);
12150 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12151 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
12152 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
12153 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12154 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12155 VAR_INIT_STATUS_INITIALIZED
);
12156 add_loc_descr (&ret
, tmp
);
12157 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12158 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12159 add_loc_descr (&ret
, l1jump
);
12160 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12161 add_loc_descr (&ret
, l2label
);
12162 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12163 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12164 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12165 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12169 /* BSWAP (constS is initial shift count, either 56 or 24):
12171 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
12172 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
12173 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
12174 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
12175 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
12177 static dw_loc_descr_ref
12178 bswap_loc_descriptor (rtx rtl
, machine_mode mode
,
12179 machine_mode mem_mode
)
12181 dw_loc_descr_ref op0
, ret
, tmp
;
12182 dw_loc_descr_ref l1jump
, l1label
;
12183 dw_loc_descr_ref l2jump
, l2label
;
12185 if (GET_MODE_CLASS (mode
) != MODE_INT
12186 || BITS_PER_UNIT
!= 8
12187 || (GET_MODE_BITSIZE (mode
) != 32
12188 && GET_MODE_BITSIZE (mode
) != 64))
12191 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12192 VAR_INIT_STATUS_INITIALIZED
);
12197 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
12199 VAR_INIT_STATUS_INITIALIZED
);
12202 add_loc_descr (&ret
, tmp
);
12203 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12204 VAR_INIT_STATUS_INITIALIZED
);
12207 add_loc_descr (&ret
, tmp
);
12208 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
12209 add_loc_descr (&ret
, l1label
);
12210 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
12212 VAR_INIT_STATUS_INITIALIZED
);
12213 add_loc_descr (&ret
, tmp
);
12214 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
12215 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12216 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12217 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
12218 VAR_INIT_STATUS_INITIALIZED
);
12221 add_loc_descr (&ret
, tmp
);
12222 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12223 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
12224 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12225 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12226 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12227 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12228 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12229 VAR_INIT_STATUS_INITIALIZED
);
12230 add_loc_descr (&ret
, tmp
);
12231 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
12232 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12233 add_loc_descr (&ret
, l2jump
);
12234 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
12235 VAR_INIT_STATUS_INITIALIZED
);
12236 add_loc_descr (&ret
, tmp
);
12237 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12238 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12239 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12240 add_loc_descr (&ret
, l1jump
);
12241 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12242 add_loc_descr (&ret
, l2label
);
12243 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12244 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12245 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12246 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12247 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12248 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12252 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
12253 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12254 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
12255 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
12257 ROTATERT is similar:
12258 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
12259 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12260 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
12262 static dw_loc_descr_ref
12263 rotate_loc_descriptor (rtx rtl
, machine_mode mode
,
12264 machine_mode mem_mode
)
12266 rtx rtlop1
= XEXP (rtl
, 1);
12267 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
12270 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12273 if (GET_MODE (rtlop1
) != VOIDmode
12274 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
12275 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12276 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12277 VAR_INIT_STATUS_INITIALIZED
);
12278 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12279 VAR_INIT_STATUS_INITIALIZED
);
12280 if (op0
== NULL
|| op1
== NULL
)
12282 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12283 for (i
= 0; i
< 2; i
++)
12285 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
12286 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
12288 VAR_INIT_STATUS_INITIALIZED
);
12289 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12290 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12292 : HOST_BITS_PER_WIDE_INT
== 64
12293 ? DW_OP_const8u
: DW_OP_constu
,
12294 GET_MODE_MASK (mode
), 0);
12297 if (mask
[i
] == NULL
)
12299 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
12302 add_loc_descr (&ret
, op1
);
12303 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12304 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12305 if (GET_CODE (rtl
) == ROTATERT
)
12307 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12308 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12309 GET_MODE_BITSIZE (mode
), 0));
12311 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12312 if (mask
[0] != NULL
)
12313 add_loc_descr (&ret
, mask
[0]);
12314 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12315 if (mask
[1] != NULL
)
12317 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12318 add_loc_descr (&ret
, mask
[1]);
12319 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12321 if (GET_CODE (rtl
) == ROTATE
)
12323 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12324 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12325 GET_MODE_BITSIZE (mode
), 0));
12327 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12328 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12332 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
12333 for DEBUG_PARAMETER_REF RTL. */
12335 static dw_loc_descr_ref
12336 parameter_ref_descriptor (rtx rtl
)
12338 dw_loc_descr_ref ret
;
12343 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
12344 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
12345 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
12348 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12349 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12350 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12354 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12355 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
12360 /* The following routine converts the RTL for a variable or parameter
12361 (resident in memory) into an equivalent Dwarf representation of a
12362 mechanism for getting the address of that same variable onto the top of a
12363 hypothetical "address evaluation" stack.
12365 When creating memory location descriptors, we are effectively transforming
12366 the RTL for a memory-resident object into its Dwarf postfix expression
12367 equivalent. This routine recursively descends an RTL tree, turning
12368 it into Dwarf postfix code as it goes.
12370 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
12372 MEM_MODE is the mode of the memory reference, needed to handle some
12373 autoincrement addressing modes.
12375 Return 0 if we can't represent the location. */
12378 mem_loc_descriptor (rtx rtl
, machine_mode mode
,
12379 machine_mode mem_mode
,
12380 enum var_init_status initialized
)
12382 dw_loc_descr_ref mem_loc_result
= NULL
;
12383 enum dwarf_location_atom op
;
12384 dw_loc_descr_ref op0
, op1
;
12385 rtx inner
= NULL_RTX
;
12387 if (mode
== VOIDmode
)
12388 mode
= GET_MODE (rtl
);
12390 /* Note that for a dynamically sized array, the location we will generate a
12391 description of here will be the lowest numbered location which is
12392 actually within the array. That's *not* necessarily the same as the
12393 zeroth element of the array. */
12395 rtl
= targetm
.delegitimize_address (rtl
);
12397 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
12400 switch (GET_CODE (rtl
))
12405 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
12408 /* The case of a subreg may arise when we have a local (register)
12409 variable or a formal (register) parameter which doesn't quite fill
12410 up an entire register. For now, just assume that it is
12411 legitimate to make the Dwarf info refer to the whole register which
12412 contains the given subreg. */
12413 if (!subreg_lowpart_p (rtl
))
12415 inner
= SUBREG_REG (rtl
);
12417 if (inner
== NULL_RTX
)
12418 inner
= XEXP (rtl
, 0);
12419 if (GET_MODE_CLASS (mode
) == MODE_INT
12420 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
12421 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12422 #ifdef POINTERS_EXTEND_UNSIGNED
12423 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
12426 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
12428 mem_loc_result
= mem_loc_descriptor (inner
,
12430 mem_mode
, initialized
);
12435 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
12437 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
12438 && (GET_MODE_CLASS (mode
) != MODE_INT
12439 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
12443 dw_die_ref type_die
;
12444 dw_loc_descr_ref cvt
;
12446 mem_loc_result
= mem_loc_descriptor (inner
,
12448 mem_mode
, initialized
);
12449 if (mem_loc_result
== NULL
)
12451 type_die
= base_type_for_mode (mode
,
12452 GET_MODE_CLASS (mode
) == MODE_INT
);
12453 if (type_die
== NULL
)
12455 mem_loc_result
= NULL
;
12458 if (GET_MODE_SIZE (mode
)
12459 != GET_MODE_SIZE (GET_MODE (inner
)))
12460 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12462 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
12463 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12464 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12465 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12466 add_loc_descr (&mem_loc_result
, cvt
);
12471 if (GET_MODE_CLASS (mode
) != MODE_INT
12472 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12473 && rtl
!= arg_pointer_rtx
12474 && rtl
!= frame_pointer_rtx
12475 #ifdef POINTERS_EXTEND_UNSIGNED
12476 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12480 dw_die_ref type_die
;
12481 unsigned int dbx_regnum
;
12485 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
12487 type_die
= base_type_for_mode (mode
,
12488 GET_MODE_CLASS (mode
) == MODE_INT
);
12489 if (type_die
== NULL
)
12492 dbx_regnum
= dbx_reg_number (rtl
);
12493 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12495 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
12497 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12498 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12499 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12502 /* Whenever a register number forms a part of the description of the
12503 method for calculating the (dynamic) address of a memory resident
12504 object, DWARF rules require the register number be referred to as
12505 a "base register". This distinction is not based in any way upon
12506 what category of register the hardware believes the given register
12507 belongs to. This is strictly DWARF terminology we're dealing with
12508 here. Note that in cases where the location of a memory-resident
12509 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12510 OP_CONST (0)) the actual DWARF location descriptor that we generate
12511 may just be OP_BASEREG (basereg). This may look deceptively like
12512 the object in question was allocated to a register (rather than in
12513 memory) so DWARF consumers need to be aware of the subtle
12514 distinction between OP_REG and OP_BASEREG. */
12515 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12516 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12517 else if (stack_realign_drap
12519 && crtl
->args
.internal_arg_pointer
== rtl
12520 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12522 /* If RTL is internal_arg_pointer, which has been optimized
12523 out, use DRAP instead. */
12524 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12525 VAR_INIT_STATUS_INITIALIZED
);
12531 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12533 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12534 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12537 else if (GET_CODE (rtl
) == ZERO_EXTEND
12538 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12539 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12540 < HOST_BITS_PER_WIDE_INT
12541 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12542 to expand zero extend as two shifts instead of
12544 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12546 machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12547 mem_loc_result
= op0
;
12548 add_loc_descr (&mem_loc_result
,
12549 int_loc_descriptor (GET_MODE_MASK (imode
)));
12550 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12552 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12554 int shift
= DWARF2_ADDR_SIZE
12555 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12556 shift
*= BITS_PER_UNIT
;
12557 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12561 mem_loc_result
= op0
;
12562 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12563 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12564 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12565 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12567 else if (!dwarf_strict
)
12569 dw_die_ref type_die1
, type_die2
;
12570 dw_loc_descr_ref cvt
;
12572 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12573 GET_CODE (rtl
) == ZERO_EXTEND
);
12574 if (type_die1
== NULL
)
12576 type_die2
= base_type_for_mode (mode
, 1);
12577 if (type_die2
== NULL
)
12579 mem_loc_result
= op0
;
12580 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12581 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12582 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12583 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12584 add_loc_descr (&mem_loc_result
, cvt
);
12585 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12586 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12587 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12588 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12589 add_loc_descr (&mem_loc_result
, cvt
);
12595 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12596 if (new_rtl
!= rtl
)
12598 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12600 if (mem_loc_result
!= NULL
)
12601 return mem_loc_result
;
12604 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12605 get_address_mode (rtl
), mode
,
12606 VAR_INIT_STATUS_INITIALIZED
);
12607 if (mem_loc_result
== NULL
)
12608 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12609 if (mem_loc_result
!= NULL
)
12611 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12612 || GET_MODE_CLASS (mode
) != MODE_INT
)
12614 dw_die_ref type_die
;
12615 dw_loc_descr_ref deref
;
12620 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12621 if (type_die
== NULL
)
12623 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12624 GET_MODE_SIZE (mode
), 0);
12625 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12626 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12627 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12628 add_loc_descr (&mem_loc_result
, deref
);
12630 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12631 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12633 add_loc_descr (&mem_loc_result
,
12634 new_loc_descr (DW_OP_deref_size
,
12635 GET_MODE_SIZE (mode
), 0));
12640 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12643 /* Some ports can transform a symbol ref into a label ref, because
12644 the symbol ref is too far away and has to be dumped into a constant
12648 if ((GET_MODE_CLASS (mode
) != MODE_INT
12649 && GET_MODE_CLASS (mode
) != MODE_PARTIAL_INT
)
12650 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12651 #ifdef POINTERS_EXTEND_UNSIGNED
12652 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12656 if (GET_CODE (rtl
) == SYMBOL_REF
12657 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12659 dw_loc_descr_ref temp
;
12661 /* If this is not defined, we have no way to emit the data. */
12662 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12665 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12667 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12668 add_loc_descr (&mem_loc_result
, temp
);
12673 if (!const_ok_for_output (rtl
))
12677 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12678 vec_safe_push (used_rtx_array
, rtl
);
12684 case DEBUG_IMPLICIT_PTR
:
12685 expansion_failed (NULL_TREE
, rtl
,
12686 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12692 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12694 if (GET_MODE_CLASS (mode
) != MODE_INT
12695 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12696 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12697 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12700 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12701 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12703 op0
= one_reg_loc_descriptor (dbx_regnum
,
12704 VAR_INIT_STATUS_INITIALIZED
);
12707 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12708 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12710 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12711 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12712 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12716 gcc_unreachable ();
12719 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12720 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12721 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12724 case DEBUG_PARAMETER_REF
:
12725 mem_loc_result
= parameter_ref_descriptor (rtl
);
12729 /* Extract the PLUS expression nested inside and fall into
12730 PLUS code below. */
12731 rtl
= XEXP (rtl
, 1);
12736 /* Turn these into a PLUS expression and fall into the PLUS code
12738 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12739 gen_int_mode (GET_CODE (rtl
) == PRE_INC
12740 ? GET_MODE_UNIT_SIZE (mem_mode
)
12741 : -GET_MODE_UNIT_SIZE (mem_mode
),
12744 /* ... fall through ... */
12748 if (is_based_loc (rtl
)
12749 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12750 || XEXP (rtl
, 0) == arg_pointer_rtx
12751 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12752 && GET_MODE_CLASS (mode
) == MODE_INT
)
12753 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12754 INTVAL (XEXP (rtl
, 1)),
12755 VAR_INIT_STATUS_INITIALIZED
);
12758 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12759 VAR_INIT_STATUS_INITIALIZED
);
12760 if (mem_loc_result
== 0)
12763 if (CONST_INT_P (XEXP (rtl
, 1))
12764 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12765 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12768 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12769 VAR_INIT_STATUS_INITIALIZED
);
12772 add_loc_descr (&mem_loc_result
, op1
);
12773 add_loc_descr (&mem_loc_result
,
12774 new_loc_descr (DW_OP_plus
, 0, 0));
12779 /* If a pseudo-reg is optimized away, it is possible for it to
12780 be replaced with a MEM containing a multiply or shift. */
12791 && GET_MODE_CLASS (mode
) == MODE_INT
12792 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12794 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12795 base_type_for_mode (mode
, 0),
12819 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12821 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12822 VAR_INIT_STATUS_INITIALIZED
);
12824 rtx rtlop1
= XEXP (rtl
, 1);
12825 if (GET_MODE (rtlop1
) != VOIDmode
12826 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
12827 < GET_MODE_BITSIZE (mode
))
12828 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12829 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12830 VAR_INIT_STATUS_INITIALIZED
);
12833 if (op0
== 0 || op1
== 0)
12836 mem_loc_result
= op0
;
12837 add_loc_descr (&mem_loc_result
, op1
);
12838 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12854 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12855 VAR_INIT_STATUS_INITIALIZED
);
12856 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12857 VAR_INIT_STATUS_INITIALIZED
);
12859 if (op0
== 0 || op1
== 0)
12862 mem_loc_result
= op0
;
12863 add_loc_descr (&mem_loc_result
, op1
);
12864 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12868 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
12870 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
12871 base_type_for_mode (mode
, 0),
12876 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12877 VAR_INIT_STATUS_INITIALIZED
);
12878 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12879 VAR_INIT_STATUS_INITIALIZED
);
12881 if (op0
== 0 || op1
== 0)
12884 mem_loc_result
= op0
;
12885 add_loc_descr (&mem_loc_result
, op1
);
12886 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12887 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12888 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
12889 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
12890 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12894 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12896 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12901 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12902 base_type_for_mode (mode
, 1),
12920 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12921 VAR_INIT_STATUS_INITIALIZED
);
12926 mem_loc_result
= op0
;
12927 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12931 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12932 #ifdef POINTERS_EXTEND_UNSIGNED
12934 && mem_mode
!= VOIDmode
12935 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12939 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12943 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12944 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
12946 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12947 machine_mode amode
;
12948 if (type_die
== NULL
)
12950 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12952 if (INTVAL (rtl
) >= 0
12953 && amode
!= BLKmode
12954 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12955 /* const DW_OP_GNU_convert <XXX> vs.
12956 DW_OP_GNU_const_type <XXX, 1, const>. */
12957 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12958 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12960 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12961 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12962 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12963 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12964 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12965 add_loc_descr (&mem_loc_result
, op0
);
12966 return mem_loc_result
;
12968 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12970 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12971 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12972 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12973 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12974 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12977 mem_loc_result
->dw_loc_oprnd2
.val_class
12978 = dw_val_class_const_double
;
12979 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12980 = double_int::from_shwi (INTVAL (rtl
));
12988 dw_die_ref type_die
;
12990 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
12991 CONST_DOUBLE rtx could represent either a large integer
12992 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
12993 the value is always a floating point constant.
12995 When it is an integer, a CONST_DOUBLE is used whenever
12996 the constant requires 2 HWIs to be adequately represented.
12997 We output CONST_DOUBLEs as blocks. */
12998 if (mode
== VOIDmode
12999 || (GET_MODE (rtl
) == VOIDmode
13000 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
13002 type_die
= base_type_for_mode (mode
,
13003 GET_MODE_CLASS (mode
) == MODE_INT
);
13004 if (type_die
== NULL
)
13006 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
13007 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13008 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13009 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13010 #if TARGET_SUPPORTS_WIDE_INT == 0
13011 if (!SCALAR_FLOAT_MODE_P (mode
))
13013 mem_loc_result
->dw_loc_oprnd2
.val_class
13014 = dw_val_class_const_double
;
13015 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
13016 = rtx_to_double_int (rtl
);
13021 unsigned int length
= GET_MODE_SIZE (mode
);
13022 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
13024 insert_float (rtl
, array
);
13025 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13026 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13027 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13028 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13033 case CONST_WIDE_INT
:
13036 dw_die_ref type_die
;
13038 type_die
= base_type_for_mode (mode
,
13039 GET_MODE_CLASS (mode
) == MODE_INT
);
13040 if (type_die
== NULL
)
13042 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
13043 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13044 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13045 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13046 mem_loc_result
->dw_loc_oprnd2
.val_class
13047 = dw_val_class_wide_int
;
13048 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_cleared_alloc
<wide_int
> ();
13049 *mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
13054 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
13058 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
13062 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
13066 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
13070 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
13074 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
13078 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
13082 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
13086 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
13090 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
13095 if (GET_MODE_CLASS (mode
) != MODE_INT
)
13100 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
13105 if (CONST_INT_P (XEXP (rtl
, 1))
13106 && CONST_INT_P (XEXP (rtl
, 2))
13107 && ((unsigned) INTVAL (XEXP (rtl
, 1))
13108 + (unsigned) INTVAL (XEXP (rtl
, 2))
13109 <= GET_MODE_BITSIZE (mode
))
13110 && GET_MODE_CLASS (mode
) == MODE_INT
13111 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13112 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
13115 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13116 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13119 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
13123 mem_loc_result
= op0
;
13124 size
= INTVAL (XEXP (rtl
, 1));
13125 shift
= INTVAL (XEXP (rtl
, 2));
13126 if (BITS_BIG_ENDIAN
)
13127 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
13129 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
13131 add_loc_descr (&mem_loc_result
,
13132 int_loc_descriptor (DWARF2_ADDR_SIZE
13134 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
13136 if (size
!= (int) DWARF2_ADDR_SIZE
)
13138 add_loc_descr (&mem_loc_result
,
13139 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
13140 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13147 dw_loc_descr_ref op2
, bra_node
, drop_node
;
13148 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
13149 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
13150 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
13151 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13152 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13153 VAR_INIT_STATUS_INITIALIZED
);
13154 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
13155 VAR_INIT_STATUS_INITIALIZED
);
13156 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
13159 mem_loc_result
= op1
;
13160 add_loc_descr (&mem_loc_result
, op2
);
13161 add_loc_descr (&mem_loc_result
, op0
);
13162 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13163 add_loc_descr (&mem_loc_result
, bra_node
);
13164 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
13165 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
13166 add_loc_descr (&mem_loc_result
, drop_node
);
13167 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13168 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
13173 case FLOAT_TRUNCATE
:
13175 case UNSIGNED_FLOAT
:
13180 dw_die_ref type_die
;
13181 dw_loc_descr_ref cvt
;
13183 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13184 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13187 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
13188 && (GET_CODE (rtl
) == FLOAT
13189 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
13190 <= DWARF2_ADDR_SIZE
))
13192 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
13193 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
13194 if (type_die
== NULL
)
13196 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13197 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13198 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13199 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13200 add_loc_descr (&op0
, cvt
);
13202 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
13203 if (type_die
== NULL
)
13205 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13206 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13207 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13208 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13209 add_loc_descr (&op0
, cvt
);
13210 if (GET_MODE_CLASS (mode
) == MODE_INT
13211 && (GET_CODE (rtl
) == FIX
13212 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
13214 op0
= convert_descriptor_to_mode (mode
, op0
);
13218 mem_loc_result
= op0
;
13225 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
13230 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
13234 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
13239 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
13243 /* In theory, we could implement the above. */
13244 /* DWARF cannot represent the unsigned compare operations
13269 case FRACT_CONVERT
:
13270 case UNSIGNED_FRACT_CONVERT
:
13272 case UNSIGNED_SAT_FRACT
:
13278 case VEC_DUPLICATE
:
13282 case STRICT_LOW_PART
:
13287 /* If delegitimize_address couldn't do anything with the UNSPEC, we
13288 can't express it in the debug info. This can happen e.g. with some
13293 resolve_one_addr (&rtl
);
13297 #ifdef ENABLE_CHECKING
13298 print_rtl (stderr
, rtl
);
13299 gcc_unreachable ();
13305 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13306 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13308 return mem_loc_result
;
13311 /* Return a descriptor that describes the concatenation of two locations.
13312 This is typically a complex variable. */
13314 static dw_loc_descr_ref
13315 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
13317 dw_loc_descr_ref cc_loc_result
= NULL
;
13318 dw_loc_descr_ref x0_ref
13319 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13320 dw_loc_descr_ref x1_ref
13321 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13323 if (x0_ref
== 0 || x1_ref
== 0)
13326 cc_loc_result
= x0_ref
;
13327 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
13329 add_loc_descr (&cc_loc_result
, x1_ref
);
13330 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
13332 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13333 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13335 return cc_loc_result
;
13338 /* Return a descriptor that describes the concatenation of N
13341 static dw_loc_descr_ref
13342 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
13345 dw_loc_descr_ref cc_loc_result
= NULL
;
13346 unsigned int n
= XVECLEN (concatn
, 0);
13348 for (i
= 0; i
< n
; ++i
)
13350 dw_loc_descr_ref ref
;
13351 rtx x
= XVECEXP (concatn
, 0, i
);
13353 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13357 add_loc_descr (&cc_loc_result
, ref
);
13358 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
13361 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13362 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13364 return cc_loc_result
;
13367 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
13368 for DEBUG_IMPLICIT_PTR RTL. */
13370 static dw_loc_descr_ref
13371 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
13373 dw_loc_descr_ref ret
;
13378 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
13379 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
13380 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
13381 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
13382 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
13383 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13386 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13387 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
13388 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13392 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
13393 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
13398 /* Output a proper Dwarf location descriptor for a variable or parameter
13399 which is either allocated in a register or in a memory location. For a
13400 register, we just generate an OP_REG and the register number. For a
13401 memory location we provide a Dwarf postfix expression describing how to
13402 generate the (dynamic) address of the object onto the address stack.
13404 MODE is mode of the decl if this loc_descriptor is going to be used in
13405 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
13406 allowed, VOIDmode otherwise.
13408 If we don't know how to describe it, return 0. */
13410 static dw_loc_descr_ref
13411 loc_descriptor (rtx rtl
, machine_mode mode
,
13412 enum var_init_status initialized
)
13414 dw_loc_descr_ref loc_result
= NULL
;
13416 switch (GET_CODE (rtl
))
13419 /* The case of a subreg may arise when we have a local (register)
13420 variable or a formal (register) parameter which doesn't quite fill
13421 up an entire register. For now, just assume that it is
13422 legitimate to make the Dwarf info refer to the whole register which
13423 contains the given subreg. */
13424 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
13425 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
13426 GET_MODE (SUBREG_REG (rtl
)), initialized
);
13432 loc_result
= reg_loc_descriptor (rtl
, initialized
);
13436 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13437 GET_MODE (rtl
), initialized
);
13438 if (loc_result
== NULL
)
13439 loc_result
= tls_mem_loc_descriptor (rtl
);
13440 if (loc_result
== NULL
)
13442 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13443 if (new_rtl
!= rtl
)
13444 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
13449 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
13454 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
13459 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
13461 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
13462 if (GET_CODE (loc
) == EXPR_LIST
)
13463 loc
= XEXP (loc
, 0);
13464 loc_result
= loc_descriptor (loc
, mode
, initialized
);
13468 rtl
= XEXP (rtl
, 1);
13473 rtvec par_elems
= XVEC (rtl
, 0);
13474 int num_elem
= GET_NUM_ELEM (par_elems
);
13478 /* Create the first one, so we have something to add to. */
13479 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
13480 VOIDmode
, initialized
);
13481 if (loc_result
== NULL
)
13483 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
13484 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13485 for (i
= 1; i
< num_elem
; i
++)
13487 dw_loc_descr_ref temp
;
13489 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
13490 VOIDmode
, initialized
);
13493 add_loc_descr (&loc_result
, temp
);
13494 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
13495 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13501 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
13502 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
13507 if (mode
== VOIDmode
)
13508 mode
= GET_MODE (rtl
);
13510 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13512 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13514 /* Note that a CONST_DOUBLE rtx could represent either an integer
13515 or a floating-point constant. A CONST_DOUBLE is used whenever
13516 the constant requires more than one word in order to be
13517 adequately represented. We output CONST_DOUBLEs as blocks. */
13518 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13519 GET_MODE_SIZE (mode
), 0);
13520 #if TARGET_SUPPORTS_WIDE_INT == 0
13521 if (!SCALAR_FLOAT_MODE_P (mode
))
13523 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
13524 loc_result
->dw_loc_oprnd2
.v
.val_double
13525 = rtx_to_double_int (rtl
);
13530 unsigned int length
= GET_MODE_SIZE (mode
);
13531 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
13533 insert_float (rtl
, array
);
13534 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13535 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13536 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13537 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13542 case CONST_WIDE_INT
:
13543 if (mode
== VOIDmode
)
13544 mode
= GET_MODE (rtl
);
13546 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13548 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13549 GET_MODE_SIZE (mode
), 0);
13550 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
13551 loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_cleared_alloc
<wide_int
> ();
13552 *loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
13557 if (mode
== VOIDmode
)
13558 mode
= GET_MODE (rtl
);
13560 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13562 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13563 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13564 unsigned char *array
13565 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
13568 machine_mode imode
= GET_MODE_INNER (mode
);
13570 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13571 switch (GET_MODE_CLASS (mode
))
13573 case MODE_VECTOR_INT
:
13574 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13576 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13577 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
13581 case MODE_VECTOR_FLOAT
:
13582 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13584 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13585 insert_float (elt
, p
);
13590 gcc_unreachable ();
13593 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13594 length
* elt_size
, 0);
13595 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13596 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13597 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13598 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13603 if (mode
== VOIDmode
13604 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13605 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13606 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13608 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13613 if (!const_ok_for_output (rtl
))
13616 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13617 && (dwarf_version
>= 4 || !dwarf_strict
))
13619 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13620 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13621 vec_safe_push (used_rtx_array
, rtl
);
13625 case DEBUG_IMPLICIT_PTR
:
13626 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13630 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13631 && CONST_INT_P (XEXP (rtl
, 1)))
13634 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13640 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13641 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13642 && dwarf_version
>= 4)
13643 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13645 /* Value expression. */
13646 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13648 add_loc_descr (&loc_result
,
13649 new_loc_descr (DW_OP_stack_value
, 0, 0));
13657 /* We need to figure out what section we should use as the base for the
13658 address ranges where a given location is valid.
13659 1. If this particular DECL has a section associated with it, use that.
13660 2. If this function has a section associated with it, use that.
13661 3. Otherwise, use the text section.
13662 XXX: If you split a variable across multiple sections, we won't notice. */
13664 static const char *
13665 secname_for_decl (const_tree decl
)
13667 const char *secname
;
13669 if (VAR_OR_FUNCTION_DECL_P (decl
)
13670 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
) || TREE_STATIC (decl
))
13671 && DECL_SECTION_NAME (decl
))
13672 secname
= DECL_SECTION_NAME (decl
);
13673 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13674 secname
= DECL_SECTION_NAME (current_function_decl
);
13675 else if (cfun
&& in_cold_section_p
)
13676 secname
= crtl
->subsections
.cold_section_label
;
13678 secname
= text_section_label
;
13683 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13686 decl_by_reference_p (tree decl
)
13688 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13689 || TREE_CODE (decl
) == VAR_DECL
)
13690 && DECL_BY_REFERENCE (decl
));
13693 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13696 static dw_loc_descr_ref
13697 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13698 enum var_init_status initialized
)
13700 int have_address
= 0;
13701 dw_loc_descr_ref descr
;
13704 if (want_address
!= 2)
13706 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13708 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13710 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13711 if (GET_CODE (varloc
) == EXPR_LIST
)
13712 varloc
= XEXP (varloc
, 0);
13713 mode
= GET_MODE (varloc
);
13714 if (MEM_P (varloc
))
13716 rtx addr
= XEXP (varloc
, 0);
13717 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13718 mode
, initialized
);
13723 rtx x
= avoid_constant_pool_reference (varloc
);
13725 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13730 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13737 if (GET_CODE (varloc
) == VAR_LOCATION
)
13738 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13740 mode
= DECL_MODE (loc
);
13741 descr
= loc_descriptor (varloc
, mode
, initialized
);
13748 if (want_address
== 2 && !have_address
13749 && (dwarf_version
>= 4 || !dwarf_strict
))
13751 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13753 expansion_failed (loc
, NULL_RTX
,
13754 "DWARF address size mismatch");
13757 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13760 /* Show if we can't fill the request for an address. */
13761 if (want_address
&& !have_address
)
13763 expansion_failed (loc
, NULL_RTX
,
13764 "Want address and only have value");
13768 /* If we've got an address and don't want one, dereference. */
13769 if (!want_address
&& have_address
)
13771 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13772 enum dwarf_location_atom op
;
13774 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13776 expansion_failed (loc
, NULL_RTX
,
13777 "DWARF address size mismatch");
13780 else if (size
== DWARF2_ADDR_SIZE
)
13783 op
= DW_OP_deref_size
;
13785 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
13791 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13792 if it is not possible. */
13794 static dw_loc_descr_ref
13795 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
13797 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
13798 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
13799 else if (dwarf_version
>= 3 || !dwarf_strict
)
13800 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
13805 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13806 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13808 static dw_loc_descr_ref
13809 dw_sra_loc_expr (tree decl
, rtx loc
)
13812 unsigned int padsize
= 0;
13813 dw_loc_descr_ref descr
, *descr_tail
;
13814 unsigned HOST_WIDE_INT decl_size
;
13816 enum var_init_status initialized
;
13818 if (DECL_SIZE (decl
) == NULL
13819 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
13822 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
13824 descr_tail
= &descr
;
13826 for (p
= loc
; p
; p
= XEXP (p
, 1))
13828 unsigned int bitsize
= decl_piece_bitsize (p
);
13829 rtx loc_note
= *decl_piece_varloc_ptr (p
);
13830 dw_loc_descr_ref cur_descr
;
13831 dw_loc_descr_ref
*tail
, last
= NULL
;
13832 unsigned int opsize
= 0;
13834 if (loc_note
== NULL_RTX
13835 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
13837 padsize
+= bitsize
;
13840 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
13841 varloc
= NOTE_VAR_LOCATION (loc_note
);
13842 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
13843 if (cur_descr
== NULL
)
13845 padsize
+= bitsize
;
13849 /* Check that cur_descr either doesn't use
13850 DW_OP_*piece operations, or their sum is equal
13851 to bitsize. Otherwise we can't embed it. */
13852 for (tail
= &cur_descr
; *tail
!= NULL
;
13853 tail
= &(*tail
)->dw_loc_next
)
13854 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
13856 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
13860 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
13862 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
13866 if (last
!= NULL
&& opsize
!= bitsize
)
13868 padsize
+= bitsize
;
13869 /* Discard the current piece of the descriptor and release any
13870 addr_table entries it uses. */
13871 remove_loc_list_addr_table_entries (cur_descr
);
13875 /* If there is a hole, add DW_OP_*piece after empty DWARF
13876 expression, which means that those bits are optimized out. */
13879 if (padsize
> decl_size
)
13881 remove_loc_list_addr_table_entries (cur_descr
);
13882 goto discard_descr
;
13884 decl_size
-= padsize
;
13885 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
13886 if (*descr_tail
== NULL
)
13888 remove_loc_list_addr_table_entries (cur_descr
);
13889 goto discard_descr
;
13891 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13894 *descr_tail
= cur_descr
;
13896 if (bitsize
> decl_size
)
13897 goto discard_descr
;
13898 decl_size
-= bitsize
;
13901 HOST_WIDE_INT offset
= 0;
13902 if (GET_CODE (varloc
) == VAR_LOCATION
13903 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13905 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13906 if (GET_CODE (varloc
) == EXPR_LIST
)
13907 varloc
= XEXP (varloc
, 0);
13911 if (GET_CODE (varloc
) == CONST
13912 || GET_CODE (varloc
) == SIGN_EXTEND
13913 || GET_CODE (varloc
) == ZERO_EXTEND
)
13914 varloc
= XEXP (varloc
, 0);
13915 else if (GET_CODE (varloc
) == SUBREG
)
13916 varloc
= SUBREG_REG (varloc
);
13921 /* DW_OP_bit_size offset should be zero for register
13922 or implicit location descriptions and empty location
13923 descriptions, but for memory addresses needs big endian
13925 if (MEM_P (varloc
))
13927 unsigned HOST_WIDE_INT memsize
13928 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13929 if (memsize
!= bitsize
)
13931 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13932 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13933 goto discard_descr
;
13934 if (memsize
< bitsize
)
13935 goto discard_descr
;
13936 if (BITS_BIG_ENDIAN
)
13937 offset
= memsize
- bitsize
;
13941 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13942 if (*descr_tail
== NULL
)
13943 goto discard_descr
;
13944 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13948 /* If there were any non-empty expressions, add padding till the end of
13950 if (descr
!= NULL
&& decl_size
!= 0)
13952 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13953 if (*descr_tail
== NULL
)
13954 goto discard_descr
;
13959 /* Discard the descriptor and release any addr_table entries it uses. */
13960 remove_loc_list_addr_table_entries (descr
);
13964 /* Return the dwarf representation of the location list LOC_LIST of
13965 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13968 static dw_loc_list_ref
13969 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13971 const char *endname
, *secname
;
13973 enum var_init_status initialized
;
13974 struct var_loc_node
*node
;
13975 dw_loc_descr_ref descr
;
13976 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13977 dw_loc_list_ref list
= NULL
;
13978 dw_loc_list_ref
*listp
= &list
;
13980 /* Now that we know what section we are using for a base,
13981 actually construct the list of locations.
13982 The first location information is what is passed to the
13983 function that creates the location list, and the remaining
13984 locations just get added on to that list.
13985 Note that we only know the start address for a location
13986 (IE location changes), so to build the range, we use
13987 the range [current location start, next location start].
13988 This means we have to special case the last node, and generate
13989 a range of [last location start, end of function label]. */
13991 secname
= secname_for_decl (decl
);
13993 for (node
= loc_list
->first
; node
; node
= node
->next
)
13994 if (GET_CODE (node
->loc
) == EXPR_LIST
13995 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13997 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13999 /* This requires DW_OP_{,bit_}piece, which is not usable
14000 inside DWARF expressions. */
14001 if (want_address
!= 2)
14003 descr
= dw_sra_loc_expr (decl
, node
->loc
);
14009 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
14010 varloc
= NOTE_VAR_LOCATION (node
->loc
);
14011 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
14015 bool range_across_switch
= false;
14016 /* If section switch happens in between node->label
14017 and node->next->label (or end of function) and
14018 we can't emit it as a single entry list,
14019 emit two ranges, first one ending at the end
14020 of first partition and second one starting at the
14021 beginning of second partition. */
14022 if (node
== loc_list
->last_before_switch
14023 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
14024 && current_function_decl
)
14026 endname
= cfun
->fde
->dw_fde_end
;
14027 range_across_switch
= true;
14029 /* The variable has a location between NODE->LABEL and
14030 NODE->NEXT->LABEL. */
14031 else if (node
->next
)
14032 endname
= node
->next
->label
;
14033 /* If the variable has a location at the last label
14034 it keeps its location until the end of function. */
14035 else if (!current_function_decl
)
14036 endname
= text_end_label
;
14039 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
14040 current_function_funcdef_no
);
14041 endname
= ggc_strdup (label_id
);
14044 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
14045 if (TREE_CODE (decl
) == PARM_DECL
14046 && node
== loc_list
->first
14047 && NOTE_P (node
->loc
)
14048 && strcmp (node
->label
, endname
) == 0)
14049 (*listp
)->force
= true;
14050 listp
= &(*listp
)->dw_loc_next
;
14052 if (range_across_switch
)
14054 if (GET_CODE (node
->loc
) == EXPR_LIST
)
14055 descr
= dw_sra_loc_expr (decl
, node
->loc
);
14058 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
14059 varloc
= NOTE_VAR_LOCATION (node
->loc
);
14060 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
14063 gcc_assert (descr
);
14064 /* The variable has a location between NODE->LABEL and
14065 NODE->NEXT->LABEL. */
14067 endname
= node
->next
->label
;
14069 endname
= cfun
->fde
->dw_fde_second_end
;
14070 *listp
= new_loc_list (descr
,
14071 cfun
->fde
->dw_fde_second_begin
,
14073 listp
= &(*listp
)->dw_loc_next
;
14078 /* Try to avoid the overhead of a location list emitting a location
14079 expression instead, but only if we didn't have more than one
14080 location entry in the first place. If some entries were not
14081 representable, we don't want to pretend a single entry that was
14082 applies to the entire scope in which the variable is
14084 if (list
&& loc_list
->first
->next
)
14090 /* Return if the loc_list has only single element and thus can be represented
14091 as location description. */
14094 single_element_loc_list_p (dw_loc_list_ref list
)
14096 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
14097 return !list
->ll_symbol
;
14100 /* To each location in list LIST add loc descr REF. */
14103 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
14105 dw_loc_descr_ref copy
;
14106 add_loc_descr (&list
->expr
, ref
);
14107 list
= list
->dw_loc_next
;
14110 copy
= ggc_alloc
<dw_loc_descr_node
> ();
14111 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
14112 add_loc_descr (&list
->expr
, copy
);
14113 while (copy
->dw_loc_next
)
14115 dw_loc_descr_ref new_copy
= ggc_alloc
<dw_loc_descr_node
> ();
14116 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
14117 copy
->dw_loc_next
= new_copy
;
14120 list
= list
->dw_loc_next
;
14124 /* Given two lists RET and LIST
14125 produce location list that is result of adding expression in LIST
14126 to expression in RET on each position in program.
14127 Might be destructive on both RET and LIST.
14129 TODO: We handle only simple cases of RET or LIST having at most one
14130 element. General case would inolve sorting the lists in program order
14131 and merging them that will need some additional work.
14132 Adding that will improve quality of debug info especially for SRA-ed
14136 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
14145 if (!list
->dw_loc_next
)
14147 add_loc_descr_to_each (*ret
, list
->expr
);
14150 if (!(*ret
)->dw_loc_next
)
14152 add_loc_descr_to_each (list
, (*ret
)->expr
);
14156 expansion_failed (NULL_TREE
, NULL_RTX
,
14157 "Don't know how to merge two non-trivial"
14158 " location lists.\n");
14163 /* LOC is constant expression. Try a luck, look it up in constant
14164 pool and return its loc_descr of its address. */
14166 static dw_loc_descr_ref
14167 cst_pool_loc_descr (tree loc
)
14169 /* Get an RTL for this, if something has been emitted. */
14170 rtx rtl
= lookup_constant_def (loc
);
14172 if (!rtl
|| !MEM_P (rtl
))
14177 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
14179 /* TODO: We might get more coverage if we was actually delaying expansion
14180 of all expressions till end of compilation when constant pools are fully
14182 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
14184 expansion_failed (loc
, NULL_RTX
,
14185 "CST value in contant pool but not marked.");
14188 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
14189 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
14192 /* Return dw_loc_list representing address of addr_expr LOC
14193 by looking for inner INDIRECT_REF expression and turning
14194 it into simple arithmetics. */
14196 static dw_loc_list_ref
14197 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
14200 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14202 int unsignedp
, reversep
, volatilep
= 0;
14203 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14205 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
14206 &bitsize
, &bitpos
, &offset
, &mode
,
14207 &unsignedp
, &reversep
, &volatilep
, false);
14209 if (bitpos
% BITS_PER_UNIT
)
14211 expansion_failed (loc
, NULL_RTX
, "bitfield access");
14214 if (!INDIRECT_REF_P (obj
))
14216 expansion_failed (obj
,
14217 NULL_RTX
, "no indirect ref in inner refrence");
14220 if (!offset
&& !bitpos
)
14221 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
14223 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
14224 && (dwarf_version
>= 4 || !dwarf_strict
))
14226 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
14231 /* Variable offset. */
14232 list_ret1
= loc_list_from_tree (offset
, 0);
14233 if (list_ret1
== 0)
14235 add_loc_list (&list_ret
, list_ret1
);
14238 add_loc_descr_to_each (list_ret
,
14239 new_loc_descr (DW_OP_plus
, 0, 0));
14241 bytepos
= bitpos
/ BITS_PER_UNIT
;
14243 add_loc_descr_to_each (list_ret
,
14244 new_loc_descr (DW_OP_plus_uconst
,
14246 else if (bytepos
< 0)
14247 loc_list_plus_const (list_ret
, bytepos
);
14248 add_loc_descr_to_each (list_ret
,
14249 new_loc_descr (DW_OP_stack_value
, 0, 0));
14255 /* Generate Dwarf location list representing LOC.
14256 If WANT_ADDRESS is false, expression computing LOC will be computed
14257 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
14258 if WANT_ADDRESS is 2, expression computing address useable in location
14259 will be returned (i.e. DW_OP_reg can be used
14260 to refer to register values). */
14262 static dw_loc_list_ref
14263 loc_list_from_tree (tree loc
, int want_address
)
14265 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
14266 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14267 int have_address
= 0;
14268 enum dwarf_location_atom op
;
14270 /* ??? Most of the time we do not take proper care for sign/zero
14271 extending the values properly. Hopefully this won't be a real
14274 switch (TREE_CODE (loc
))
14277 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
14280 case PLACEHOLDER_EXPR
:
14281 /* This case involves extracting fields from an object to determine the
14282 position of other fields. We don't try to encode this here. The
14283 only user of this is Ada, which encodes the needed information using
14284 the names of types. */
14285 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
14289 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
14290 /* There are no opcodes for these operations. */
14293 case PREINCREMENT_EXPR
:
14294 case PREDECREMENT_EXPR
:
14295 case POSTINCREMENT_EXPR
:
14296 case POSTDECREMENT_EXPR
:
14297 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
14298 /* There are no opcodes for these operations. */
14302 /* If we already want an address, see if there is INDIRECT_REF inside
14303 e.g. for &this->field. */
14306 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
14307 (loc
, want_address
== 2);
14310 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
14311 && (ret
= cst_pool_loc_descr (loc
)))
14314 /* Otherwise, process the argument and look for the address. */
14315 if (!list_ret
&& !ret
)
14316 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
14320 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
14326 if (DECL_THREAD_LOCAL_P (loc
))
14329 enum dwarf_location_atom tls_op
;
14330 enum dtprel_bool dtprel
= dtprel_false
;
14332 if (targetm
.have_tls
)
14334 /* If this is not defined, we have no way to emit the
14336 if (!targetm
.asm_out
.output_dwarf_dtprel
)
14339 /* The way DW_OP_GNU_push_tls_address is specified, we
14340 can only look up addresses of objects in the current
14341 module. We used DW_OP_addr as first op, but that's
14342 wrong, because DW_OP_addr is relocated by the debug
14343 info consumer, while DW_OP_GNU_push_tls_address
14344 operand shouldn't be. */
14345 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
14347 dtprel
= dtprel_true
;
14348 tls_op
= DW_OP_GNU_push_tls_address
;
14352 if (!targetm
.emutls
.debug_form_tls_address
14353 || !(dwarf_version
>= 3 || !dwarf_strict
))
14355 /* We stuffed the control variable into the DECL_VALUE_EXPR
14356 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
14357 no longer appear in gimple code. We used the control
14358 variable in specific so that we could pick it up here. */
14359 loc
= DECL_VALUE_EXPR (loc
);
14360 tls_op
= DW_OP_form_tls_address
;
14363 rtl
= rtl_for_decl_location (loc
);
14364 if (rtl
== NULL_RTX
)
14369 rtl
= XEXP (rtl
, 0);
14370 if (! CONSTANT_P (rtl
))
14373 ret
= new_addr_loc_descr (rtl
, dtprel
);
14374 ret1
= new_loc_descr (tls_op
, 0, 0);
14375 add_loc_descr (&ret
, ret1
);
14384 if (DECL_HAS_VALUE_EXPR_P (loc
))
14385 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
14389 case FUNCTION_DECL
:
14392 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
14394 if (loc_list
&& loc_list
->first
)
14396 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
14397 have_address
= want_address
!= 0;
14400 rtl
= rtl_for_decl_location (loc
);
14401 if (rtl
== NULL_RTX
)
14403 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
14406 else if (CONST_INT_P (rtl
))
14408 HOST_WIDE_INT val
= INTVAL (rtl
);
14409 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14410 val
&= GET_MODE_MASK (DECL_MODE (loc
));
14411 ret
= int_loc_descriptor (val
);
14413 else if (GET_CODE (rtl
) == CONST_STRING
)
14415 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
14418 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
14419 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
14422 machine_mode mode
, mem_mode
;
14424 /* Certain constructs can only be represented at top-level. */
14425 if (want_address
== 2)
14427 ret
= loc_descriptor (rtl
, VOIDmode
,
14428 VAR_INIT_STATUS_INITIALIZED
);
14433 mode
= GET_MODE (rtl
);
14434 mem_mode
= VOIDmode
;
14438 mode
= get_address_mode (rtl
);
14439 rtl
= XEXP (rtl
, 0);
14442 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
14443 VAR_INIT_STATUS_INITIALIZED
);
14446 expansion_failed (loc
, rtl
,
14447 "failed to produce loc descriptor for rtl");
14453 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
14460 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14464 case TARGET_MEM_REF
:
14468 case COMPOUND_EXPR
:
14469 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
14472 case VIEW_CONVERT_EXPR
:
14475 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
14477 case COMPONENT_REF
:
14478 case BIT_FIELD_REF
:
14480 case ARRAY_RANGE_REF
:
14481 case REALPART_EXPR
:
14482 case IMAGPART_EXPR
:
14485 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14487 int unsignedp
, reversep
, volatilep
= 0;
14489 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
14490 &unsignedp
, &reversep
, &volatilep
, false);
14492 gcc_assert (obj
!= loc
);
14494 list_ret
= loc_list_from_tree (obj
,
14496 && !bitpos
&& !offset
? 2 : 1);
14497 /* TODO: We can extract value of the small expression via shifting even
14498 for nonzero bitpos. */
14501 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
14503 expansion_failed (loc
, NULL_RTX
,
14504 "bitfield access");
14508 if (offset
!= NULL_TREE
)
14510 /* Variable offset. */
14511 list_ret1
= loc_list_from_tree (offset
, 0);
14512 if (list_ret1
== 0)
14514 add_loc_list (&list_ret
, list_ret1
);
14517 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14520 bytepos
= bitpos
/ BITS_PER_UNIT
;
14522 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
14523 else if (bytepos
< 0)
14524 loc_list_plus_const (list_ret
, bytepos
);
14531 if ((want_address
|| !tree_fits_shwi_p (loc
))
14532 && (ret
= cst_pool_loc_descr (loc
)))
14534 else if (want_address
== 2
14535 && tree_fits_shwi_p (loc
)
14536 && (ret
= address_of_int_loc_descriptor
14537 (int_size_in_bytes (TREE_TYPE (loc
)),
14538 tree_to_shwi (loc
))))
14540 else if (tree_fits_shwi_p (loc
))
14541 ret
= int_loc_descriptor (tree_to_shwi (loc
));
14544 expansion_failed (loc
, NULL_RTX
,
14545 "Integer operand is not host integer");
14554 if ((ret
= cst_pool_loc_descr (loc
)))
14557 /* We can construct small constants here using int_loc_descriptor. */
14558 expansion_failed (loc
, NULL_RTX
,
14559 "constructor or constant not in constant pool");
14562 case TRUTH_AND_EXPR
:
14563 case TRUTH_ANDIF_EXPR
:
14568 case TRUTH_XOR_EXPR
:
14573 case TRUTH_OR_EXPR
:
14574 case TRUTH_ORIF_EXPR
:
14579 case FLOOR_DIV_EXPR
:
14580 case CEIL_DIV_EXPR
:
14581 case ROUND_DIV_EXPR
:
14582 case TRUNC_DIV_EXPR
:
14583 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14592 case FLOOR_MOD_EXPR
:
14593 case CEIL_MOD_EXPR
:
14594 case ROUND_MOD_EXPR
:
14595 case TRUNC_MOD_EXPR
:
14596 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14601 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14602 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14603 if (list_ret
== 0 || list_ret1
== 0)
14606 add_loc_list (&list_ret
, list_ret1
);
14609 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14610 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14611 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14612 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14613 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14625 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14628 case POINTER_PLUS_EXPR
:
14631 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
14633 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14637 loc_list_plus_const (list_ret
, tree_to_shwi (TREE_OPERAND (loc
, 1)));
14645 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14652 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14659 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14666 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14681 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14682 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14683 if (list_ret
== 0 || list_ret1
== 0)
14686 add_loc_list (&list_ret
, list_ret1
);
14689 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14692 case TRUTH_NOT_EXPR
:
14706 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14710 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14716 const enum tree_code code
=
14717 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14719 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14720 build2 (code
, integer_type_node
,
14721 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14722 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14725 /* ... fall through ... */
14729 dw_loc_descr_ref lhs
14730 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
14731 dw_loc_list_ref rhs
14732 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
14733 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
14735 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14736 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
14739 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14740 add_loc_descr_to_each (list_ret
, bra_node
);
14742 add_loc_list (&list_ret
, rhs
);
14743 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14744 add_loc_descr_to_each (list_ret
, jump_node
);
14746 add_loc_descr_to_each (list_ret
, lhs
);
14747 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14748 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
14750 /* ??? Need a node to point the skip at. Use a nop. */
14751 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14752 add_loc_descr_to_each (list_ret
, tmp
);
14753 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14754 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14758 case FIX_TRUNC_EXPR
:
14762 /* Leave front-end specific codes as simply unknown. This comes
14763 up, for instance, with the C STMT_EXPR. */
14764 if ((unsigned int) TREE_CODE (loc
)
14765 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
14767 expansion_failed (loc
, NULL_RTX
,
14768 "language specific tree node");
14772 #ifdef ENABLE_CHECKING
14773 /* Otherwise this is a generic code; we should just lists all of
14774 these explicitly. We forgot one. */
14775 gcc_unreachable ();
14777 /* In a release build, we want to degrade gracefully: better to
14778 generate incomplete debugging information than to crash. */
14783 if (!ret
&& !list_ret
)
14786 if (want_address
== 2 && !have_address
14787 && (dwarf_version
>= 4 || !dwarf_strict
))
14789 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14791 expansion_failed (loc
, NULL_RTX
,
14792 "DWARF address size mismatch");
14796 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14798 add_loc_descr_to_each (list_ret
,
14799 new_loc_descr (DW_OP_stack_value
, 0, 0));
14802 /* Show if we can't fill the request for an address. */
14803 if (want_address
&& !have_address
)
14805 expansion_failed (loc
, NULL_RTX
,
14806 "Want address and only have value");
14810 gcc_assert (!ret
|| !list_ret
);
14812 /* If we've got an address and don't want one, dereference. */
14813 if (!want_address
&& have_address
)
14815 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14817 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14819 expansion_failed (loc
, NULL_RTX
,
14820 "DWARF address size mismatch");
14823 else if (size
== DWARF2_ADDR_SIZE
)
14826 op
= DW_OP_deref_size
;
14829 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
14831 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
14834 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
14839 /* Same as above but return only single location expression. */
14840 static dw_loc_descr_ref
14841 loc_descriptor_from_tree (tree loc
, int want_address
)
14843 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
14846 if (ret
->dw_loc_next
)
14848 expansion_failed (loc
, NULL_RTX
,
14849 "Location list where only loc descriptor needed");
14855 /* Given a value, round it up to the lowest multiple of `boundary'
14856 which is not less than the value itself. */
14858 static inline HOST_WIDE_INT
14859 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
14861 return (((value
+ boundary
- 1) / boundary
) * boundary
);
14864 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14865 pointer to the declared type for the relevant field variable, or return
14866 `integer_type_node' if the given node turns out to be an
14867 ERROR_MARK node. */
14870 field_type (const_tree decl
)
14874 if (TREE_CODE (decl
) == ERROR_MARK
)
14875 return integer_type_node
;
14877 type
= DECL_BIT_FIELD_TYPE (decl
);
14878 if (type
== NULL_TREE
)
14879 type
= TREE_TYPE (decl
);
14884 /* Given a pointer to a tree node, return the alignment in bits for
14885 it, or else return BITS_PER_WORD if the node actually turns out to
14886 be an ERROR_MARK node. */
14888 static inline unsigned
14889 simple_type_align_in_bits (const_tree type
)
14891 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
14894 static inline unsigned
14895 simple_decl_align_in_bits (const_tree decl
)
14897 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
14900 /* Return the result of rounding T up to ALIGN. */
14902 static inline offset_int
14903 round_up_to_align (const offset_int
&t
, unsigned int align
)
14905 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
14908 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14909 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14910 or return 0 if we are unable to determine what that offset is, either
14911 because the argument turns out to be a pointer to an ERROR_MARK node, or
14912 because the offset is actually variable. (We can't handle the latter case
14915 static HOST_WIDE_INT
14916 field_byte_offset (const_tree decl
)
14918 offset_int object_offset_in_bits
;
14919 offset_int object_offset_in_bytes
;
14920 offset_int bitpos_int
;
14922 if (TREE_CODE (decl
) == ERROR_MARK
)
14925 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14927 /* We cannot yet cope with fields whose positions are variable, so
14928 for now, when we see such things, we simply return 0. Someday, we may
14929 be able to handle such cases, but it will be damn difficult. */
14930 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14933 bitpos_int
= wi::to_offset (bit_position (decl
));
14935 #ifdef PCC_BITFIELD_TYPE_MATTERS
14936 if (PCC_BITFIELD_TYPE_MATTERS
)
14939 tree field_size_tree
;
14940 offset_int deepest_bitpos
;
14941 offset_int field_size_in_bits
;
14942 unsigned int type_align_in_bits
;
14943 unsigned int decl_align_in_bits
;
14944 offset_int type_size_in_bits
;
14946 type
= field_type (decl
);
14947 type_size_in_bits
= offset_int_type_size_in_bits (type
);
14948 type_align_in_bits
= simple_type_align_in_bits (type
);
14950 field_size_tree
= DECL_SIZE (decl
);
14952 /* The size could be unspecified if there was an error, or for
14953 a flexible array member. */
14954 if (!field_size_tree
)
14955 field_size_tree
= bitsize_zero_node
;
14957 /* If the size of the field is not constant, use the type size. */
14958 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14959 field_size_in_bits
= wi::to_offset (field_size_tree
);
14961 field_size_in_bits
= type_size_in_bits
;
14963 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14965 /* The GCC front-end doesn't make any attempt to keep track of the
14966 starting bit offset (relative to the start of the containing
14967 structure type) of the hypothetical "containing object" for a
14968 bit-field. Thus, when computing the byte offset value for the
14969 start of the "containing object" of a bit-field, we must deduce
14970 this information on our own. This can be rather tricky to do in
14971 some cases. For example, handling the following structure type
14972 definition when compiling for an i386/i486 target (which only
14973 aligns long long's to 32-bit boundaries) can be very tricky:
14975 struct S { int field1; long long field2:31; };
14977 Fortunately, there is a simple rule-of-thumb which can be used
14978 in such cases. When compiling for an i386/i486, GCC will
14979 allocate 8 bytes for the structure shown above. It decides to
14980 do this based upon one simple rule for bit-field allocation.
14981 GCC allocates each "containing object" for each bit-field at
14982 the first (i.e. lowest addressed) legitimate alignment boundary
14983 (based upon the required minimum alignment for the declared
14984 type of the field) which it can possibly use, subject to the
14985 condition that there is still enough available space remaining
14986 in the containing object (when allocated at the selected point)
14987 to fully accommodate all of the bits of the bit-field itself.
14989 This simple rule makes it obvious why GCC allocates 8 bytes for
14990 each object of the structure type shown above. When looking
14991 for a place to allocate the "containing object" for `field2',
14992 the compiler simply tries to allocate a 64-bit "containing
14993 object" at each successive 32-bit boundary (starting at zero)
14994 until it finds a place to allocate that 64- bit field such that
14995 at least 31 contiguous (and previously unallocated) bits remain
14996 within that selected 64 bit field. (As it turns out, for the
14997 example above, the compiler finds it is OK to allocate the
14998 "containing object" 64-bit field at bit-offset zero within the
15001 Here we attempt to work backwards from the limited set of facts
15002 we're given, and we try to deduce from those facts, where GCC
15003 must have believed that the containing object started (within
15004 the structure type). The value we deduce is then used (by the
15005 callers of this routine) to generate DW_AT_location and
15006 DW_AT_bit_offset attributes for fields (both bit-fields and, in
15007 the case of DW_AT_location, regular fields as well). */
15009 /* Figure out the bit-distance from the start of the structure to
15010 the "deepest" bit of the bit-field. */
15011 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
15013 /* This is the tricky part. Use some fancy footwork to deduce
15014 where the lowest addressed bit of the containing object must
15016 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
15018 /* Round up to type_align by default. This works best for
15020 object_offset_in_bits
15021 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
15023 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
15025 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
15027 /* Round up to decl_align instead. */
15028 object_offset_in_bits
15029 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
15033 #endif /* PCC_BITFIELD_TYPE_MATTERS */
15034 object_offset_in_bits
= bitpos_int
;
15036 object_offset_in_bytes
15037 = wi::lrshift (object_offset_in_bits
, LOG2_BITS_PER_UNIT
);
15038 return object_offset_in_bytes
.to_shwi ();
15041 /* The following routines define various Dwarf attributes and any data
15042 associated with them. */
15044 /* Add a location description attribute value to a DIE.
15046 This emits location attributes suitable for whole variables and
15047 whole parameters. Note that the location attributes for struct fields are
15048 generated by the routine `data_member_location_attribute' below. */
15051 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
15052 dw_loc_list_ref descr
)
15056 if (single_element_loc_list_p (descr
))
15057 add_AT_loc (die
, attr_kind
, descr
->expr
);
15059 add_AT_loc_list (die
, attr_kind
, descr
);
15062 /* Add DW_AT_accessibility attribute to DIE if needed. */
15065 add_accessibility_attribute (dw_die_ref die
, tree decl
)
15067 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
15068 children, otherwise the default is DW_ACCESS_public. In DWARF2
15069 the default has always been DW_ACCESS_public. */
15070 if (TREE_PROTECTED (decl
))
15071 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
15072 else if (TREE_PRIVATE (decl
))
15074 if (dwarf_version
== 2
15075 || die
->die_parent
== NULL
15076 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
15077 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
15079 else if (dwarf_version
> 2
15081 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
15082 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
15085 /* Attach the specialized form of location attribute used for data members of
15086 struct and union types. In the special case of a FIELD_DECL node which
15087 represents a bit-field, the "offset" part of this special location
15088 descriptor must indicate the distance in bytes from the lowest-addressed
15089 byte of the containing struct or union type to the lowest-addressed byte of
15090 the "containing object" for the bit-field. (See the `field_byte_offset'
15093 For any given bit-field, the "containing object" is a hypothetical object
15094 (of some integral or enum type) within which the given bit-field lives. The
15095 type of this hypothetical "containing object" is always the same as the
15096 declared type of the individual bit-field itself (for GCC anyway... the
15097 DWARF spec doesn't actually mandate this). Note that it is the size (in
15098 bytes) of the hypothetical "containing object" which will be given in the
15099 DW_AT_byte_size attribute for this bit-field. (See the
15100 `byte_size_attribute' function below.) It is also used when calculating the
15101 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
15102 function below.) */
15105 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
15107 HOST_WIDE_INT offset
;
15108 dw_loc_descr_ref loc_descr
= 0;
15110 if (TREE_CODE (decl
) == TREE_BINFO
)
15112 /* We're working on the TAG_inheritance for a base class. */
15113 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
15115 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
15116 aren't at a fixed offset from all (sub)objects of the same
15117 type. We need to extract the appropriate offset from our
15118 vtable. The following dwarf expression means
15120 BaseAddr = ObAddr + *((*ObAddr) - Offset)
15122 This is specific to the V3 ABI, of course. */
15124 dw_loc_descr_ref tmp
;
15126 /* Make a copy of the object address. */
15127 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
15128 add_loc_descr (&loc_descr
, tmp
);
15130 /* Extract the vtable address. */
15131 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
15132 add_loc_descr (&loc_descr
, tmp
);
15134 /* Calculate the address of the offset. */
15135 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
15136 gcc_assert (offset
< 0);
15138 tmp
= int_loc_descriptor (-offset
);
15139 add_loc_descr (&loc_descr
, tmp
);
15140 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
15141 add_loc_descr (&loc_descr
, tmp
);
15143 /* Extract the offset. */
15144 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
15145 add_loc_descr (&loc_descr
, tmp
);
15147 /* Add it to the object address. */
15148 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
15149 add_loc_descr (&loc_descr
, tmp
);
15152 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
15155 offset
= field_byte_offset (decl
);
15159 if (dwarf_version
> 2)
15161 /* Don't need to output a location expression, just the constant. */
15163 add_AT_int (die
, DW_AT_data_member_location
, offset
);
15165 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
15170 enum dwarf_location_atom op
;
15172 /* The DWARF2 standard says that we should assume that the structure
15173 address is already on the stack, so we can specify a structure
15174 field address by using DW_OP_plus_uconst. */
15175 op
= DW_OP_plus_uconst
;
15176 loc_descr
= new_loc_descr (op
, offset
, 0);
15180 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
15183 /* Writes integer values to dw_vec_const array. */
15186 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
15190 *dest
++ = val
& 0xff;
15196 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
15198 static HOST_WIDE_INT
15199 extract_int (const unsigned char *src
, unsigned int size
)
15201 HOST_WIDE_INT val
= 0;
15207 val
|= *--src
& 0xff;
15213 /* Writes wide_int values to dw_vec_const array. */
15216 insert_wide_int (const wide_int
&val
, unsigned char *dest
, int elt_size
)
15220 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
15222 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
15226 /* We'd have to extend this code to support odd sizes. */
15227 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
) == 0);
15229 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
15231 if (WORDS_BIG_ENDIAN
)
15232 for (i
= n
- 1; i
>= 0; i
--)
15234 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
15235 dest
+= sizeof (HOST_WIDE_INT
);
15238 for (i
= 0; i
< n
; i
++)
15240 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
15241 dest
+= sizeof (HOST_WIDE_INT
);
15245 /* Writes floating point values to dw_vec_const array. */
15248 insert_float (const_rtx rtl
, unsigned char *array
)
15250 REAL_VALUE_TYPE rv
;
15254 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
15255 real_to_target (val
, &rv
, GET_MODE (rtl
));
15257 /* real_to_target puts 32-bit pieces in each long. Pack them. */
15258 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
15260 insert_int (val
[i
], 4, array
);
15265 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
15266 does not have a "location" either in memory or in a register. These
15267 things can arise in GNU C when a constant is passed as an actual parameter
15268 to an inlined function. They can also arise in C++ where declared
15269 constants do not necessarily get memory "homes". */
15272 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
15274 switch (GET_CODE (rtl
))
15278 HOST_WIDE_INT val
= INTVAL (rtl
);
15281 add_AT_int (die
, DW_AT_const_value
, val
);
15283 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
15287 case CONST_WIDE_INT
:
15288 add_AT_wide (die
, DW_AT_const_value
,
15289 std::make_pair (rtl
, GET_MODE (rtl
)));
15293 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
15294 floating-point constant. A CONST_DOUBLE is used whenever the
15295 constant requires more than one word in order to be adequately
15298 machine_mode mode
= GET_MODE (rtl
);
15300 if (TARGET_SUPPORTS_WIDE_INT
== 0 && !SCALAR_FLOAT_MODE_P (mode
))
15301 add_AT_double (die
, DW_AT_const_value
,
15302 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
15305 unsigned int length
= GET_MODE_SIZE (mode
);
15306 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15308 insert_float (rtl
, array
);
15309 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
15316 machine_mode mode
= GET_MODE (rtl
);
15317 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
15318 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15319 unsigned char *array
15320 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
15323 machine_mode imode
= GET_MODE_INNER (mode
);
15325 switch (GET_MODE_CLASS (mode
))
15327 case MODE_VECTOR_INT
:
15328 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15330 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15331 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
15335 case MODE_VECTOR_FLOAT
:
15336 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15338 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15339 insert_float (elt
, p
);
15344 gcc_unreachable ();
15347 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
15352 if (dwarf_version
>= 4 || !dwarf_strict
)
15354 dw_loc_descr_ref loc_result
;
15355 resolve_one_addr (&rtl
);
15357 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15358 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15359 add_AT_loc (die
, DW_AT_location
, loc_result
);
15360 vec_safe_push (used_rtx_array
, rtl
);
15366 if (CONSTANT_P (XEXP (rtl
, 0)))
15367 return add_const_value_attribute (die
, XEXP (rtl
, 0));
15370 if (!const_ok_for_output (rtl
))
15373 if (dwarf_version
>= 4 || !dwarf_strict
)
15378 /* In cases where an inlined instance of an inline function is passed
15379 the address of an `auto' variable (which is local to the caller) we
15380 can get a situation where the DECL_RTL of the artificial local
15381 variable (for the inlining) which acts as a stand-in for the
15382 corresponding formal parameter (of the inline function) will look
15383 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
15384 exactly a compile-time constant expression, but it isn't the address
15385 of the (artificial) local variable either. Rather, it represents the
15386 *value* which the artificial local variable always has during its
15387 lifetime. We currently have no way to represent such quasi-constant
15388 values in Dwarf, so for now we just punt and generate nothing. */
15396 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
15397 && MEM_READONLY_P (rtl
)
15398 && GET_MODE (rtl
) == BLKmode
)
15400 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
15406 /* No other kinds of rtx should be possible here. */
15407 gcc_unreachable ();
15412 /* Determine whether the evaluation of EXPR references any variables
15413 or functions which aren't otherwise used (and therefore may not be
15416 reference_to_unused (tree
* tp
, int * walk_subtrees
,
15417 void * data ATTRIBUTE_UNUSED
)
15419 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
15420 *walk_subtrees
= 0;
15422 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
15423 && ! TREE_ASM_WRITTEN (*tp
))
15425 /* ??? The C++ FE emits debug information for using decls, so
15426 putting gcc_unreachable here falls over. See PR31899. For now
15427 be conservative. */
15428 else if (!symtab
->global_info_ready
15429 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
15431 else if (TREE_CODE (*tp
) == VAR_DECL
)
15433 varpool_node
*node
= varpool_node::get (*tp
);
15434 if (!node
|| !node
->definition
)
15437 else if (TREE_CODE (*tp
) == FUNCTION_DECL
15438 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
15440 /* The call graph machinery must have finished analyzing,
15441 optimizing and gimplifying the CU by now.
15442 So if *TP has no call graph node associated
15443 to it, it means *TP will not be emitted. */
15444 if (!cgraph_node::get (*tp
))
15447 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
15453 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
15454 for use in a later add_const_value_attribute call. */
15457 rtl_for_decl_init (tree init
, tree type
)
15459 rtx rtl
= NULL_RTX
;
15463 /* If a variable is initialized with a string constant without embedded
15464 zeros, build CONST_STRING. */
15465 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
15467 tree enttype
= TREE_TYPE (type
);
15468 tree domain
= TYPE_DOMAIN (type
);
15469 machine_mode mode
= TYPE_MODE (enttype
);
15471 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
15473 && integer_zerop (TYPE_MIN_VALUE (domain
))
15474 && compare_tree_int (TYPE_MAX_VALUE (domain
),
15475 TREE_STRING_LENGTH (init
) - 1) == 0
15476 && ((size_t) TREE_STRING_LENGTH (init
)
15477 == strlen (TREE_STRING_POINTER (init
)) + 1))
15479 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
15480 ggc_strdup (TREE_STRING_POINTER (init
)));
15481 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
15482 MEM_READONLY_P (rtl
) = 1;
15485 /* Other aggregates, and complex values, could be represented using
15487 else if (AGGREGATE_TYPE_P (type
)
15488 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
15489 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
15490 || TREE_CODE (type
) == COMPLEX_TYPE
)
15492 /* Vectors only work if their mode is supported by the target.
15493 FIXME: generic vectors ought to work too. */
15494 else if (TREE_CODE (type
) == VECTOR_TYPE
15495 && !VECTOR_MODE_P (TYPE_MODE (type
)))
15497 /* If the initializer is something that we know will expand into an
15498 immediate RTL constant, expand it now. We must be careful not to
15499 reference variables which won't be output. */
15500 else if (initializer_constant_valid_p (init
, type
)
15501 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
15503 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
15505 if (TREE_CODE (type
) == VECTOR_TYPE
)
15506 switch (TREE_CODE (init
))
15511 if (TREE_CONSTANT (init
))
15513 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
15514 bool constant_p
= true;
15516 unsigned HOST_WIDE_INT ix
;
15518 /* Even when ctor is constant, it might contain non-*_CST
15519 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15520 belong into VECTOR_CST nodes. */
15521 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
15522 if (!CONSTANT_CLASS_P (value
))
15524 constant_p
= false;
15530 init
= build_vector_from_ctor (type
, elts
);
15540 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
15542 /* If expand_expr returns a MEM, it wasn't immediate. */
15543 gcc_assert (!rtl
|| !MEM_P (rtl
));
15549 /* Generate RTL for the variable DECL to represent its location. */
15552 rtl_for_decl_location (tree decl
)
15556 /* Here we have to decide where we are going to say the parameter "lives"
15557 (as far as the debugger is concerned). We only have a couple of
15558 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15560 DECL_RTL normally indicates where the parameter lives during most of the
15561 activation of the function. If optimization is enabled however, this
15562 could be either NULL or else a pseudo-reg. Both of those cases indicate
15563 that the parameter doesn't really live anywhere (as far as the code
15564 generation parts of GCC are concerned) during most of the function's
15565 activation. That will happen (for example) if the parameter is never
15566 referenced within the function.
15568 We could just generate a location descriptor here for all non-NULL
15569 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15570 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15571 where DECL_RTL is NULL or is a pseudo-reg.
15573 Note however that we can only get away with using DECL_INCOMING_RTL as
15574 a backup substitute for DECL_RTL in certain limited cases. In cases
15575 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15576 we can be sure that the parameter was passed using the same type as it is
15577 declared to have within the function, and that its DECL_INCOMING_RTL
15578 points us to a place where a value of that type is passed.
15580 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15581 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15582 because in these cases DECL_INCOMING_RTL points us to a value of some
15583 type which is *different* from the type of the parameter itself. Thus,
15584 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15585 such cases, the debugger would end up (for example) trying to fetch a
15586 `float' from a place which actually contains the first part of a
15587 `double'. That would lead to really incorrect and confusing
15588 output at debug-time.
15590 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15591 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15592 are a couple of exceptions however. On little-endian machines we can
15593 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15594 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15595 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15596 when (on a little-endian machine) a non-prototyped function has a
15597 parameter declared to be of type `short' or `char'. In such cases,
15598 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15599 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15600 passed `int' value. If the debugger then uses that address to fetch
15601 a `short' or a `char' (on a little-endian machine) the result will be
15602 the correct data, so we allow for such exceptional cases below.
15604 Note that our goal here is to describe the place where the given formal
15605 parameter lives during most of the function's activation (i.e. between the
15606 end of the prologue and the start of the epilogue). We'll do that as best
15607 as we can. Note however that if the given formal parameter is modified
15608 sometime during the execution of the function, then a stack backtrace (at
15609 debug-time) will show the function as having been called with the *new*
15610 value rather than the value which was originally passed in. This happens
15611 rarely enough that it is not a major problem, but it *is* a problem, and
15612 I'd like to fix it.
15614 A future version of dwarf2out.c may generate two additional attributes for
15615 any given DW_TAG_formal_parameter DIE which will describe the "passed
15616 type" and the "passed location" for the given formal parameter in addition
15617 to the attributes we now generate to indicate the "declared type" and the
15618 "active location" for each parameter. This additional set of attributes
15619 could be used by debuggers for stack backtraces. Separately, note that
15620 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15621 This happens (for example) for inlined-instances of inline function formal
15622 parameters which are never referenced. This really shouldn't be
15623 happening. All PARM_DECL nodes should get valid non-NULL
15624 DECL_INCOMING_RTL values. FIXME. */
15626 /* Use DECL_RTL as the "location" unless we find something better. */
15627 rtl
= DECL_RTL_IF_SET (decl
);
15629 /* When generating abstract instances, ignore everything except
15630 constants, symbols living in memory, and symbols living in
15631 fixed registers. */
15632 if (! reload_completed
)
15635 && (CONSTANT_P (rtl
)
15637 && CONSTANT_P (XEXP (rtl
, 0)))
15639 && TREE_CODE (decl
) == VAR_DECL
15640 && TREE_STATIC (decl
))))
15642 rtl
= targetm
.delegitimize_address (rtl
);
15647 else if (TREE_CODE (decl
) == PARM_DECL
)
15649 if (rtl
== NULL_RTX
15650 || is_pseudo_reg (rtl
)
15652 && is_pseudo_reg (XEXP (rtl
, 0))
15653 && DECL_INCOMING_RTL (decl
)
15654 && MEM_P (DECL_INCOMING_RTL (decl
))
15655 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15657 tree declared_type
= TREE_TYPE (decl
);
15658 tree passed_type
= DECL_ARG_TYPE (decl
);
15659 machine_mode dmode
= TYPE_MODE (declared_type
);
15660 machine_mode pmode
= TYPE_MODE (passed_type
);
15662 /* This decl represents a formal parameter which was optimized out.
15663 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15664 all cases where (rtl == NULL_RTX) just below. */
15665 if (dmode
== pmode
)
15666 rtl
= DECL_INCOMING_RTL (decl
);
15667 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15668 && SCALAR_INT_MODE_P (dmode
)
15669 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15670 && DECL_INCOMING_RTL (decl
))
15672 rtx inc
= DECL_INCOMING_RTL (decl
);
15675 else if (MEM_P (inc
))
15677 if (BYTES_BIG_ENDIAN
)
15678 rtl
= adjust_address_nv (inc
, dmode
,
15679 GET_MODE_SIZE (pmode
)
15680 - GET_MODE_SIZE (dmode
));
15687 /* If the parm was passed in registers, but lives on the stack, then
15688 make a big endian correction if the mode of the type of the
15689 parameter is not the same as the mode of the rtl. */
15690 /* ??? This is the same series of checks that are made in dbxout.c before
15691 we reach the big endian correction code there. It isn't clear if all
15692 of these checks are necessary here, but keeping them all is the safe
15694 else if (MEM_P (rtl
)
15695 && XEXP (rtl
, 0) != const0_rtx
15696 && ! CONSTANT_P (XEXP (rtl
, 0))
15697 /* Not passed in memory. */
15698 && !MEM_P (DECL_INCOMING_RTL (decl
))
15699 /* Not passed by invisible reference. */
15700 && (!REG_P (XEXP (rtl
, 0))
15701 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15702 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15703 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15704 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15707 /* Big endian correction check. */
15708 && BYTES_BIG_ENDIAN
15709 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15710 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15713 machine_mode addr_mode
= get_address_mode (rtl
);
15714 int offset
= (UNITS_PER_WORD
15715 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15717 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15718 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15721 else if (TREE_CODE (decl
) == VAR_DECL
15724 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15725 && BYTES_BIG_ENDIAN
)
15727 machine_mode addr_mode
= get_address_mode (rtl
);
15728 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
15729 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
15731 /* If a variable is declared "register" yet is smaller than
15732 a register, then if we store the variable to memory, it
15733 looks like we're storing a register-sized value, when in
15734 fact we are not. We need to adjust the offset of the
15735 storage location to reflect the actual value's bytes,
15736 else gdb will not be able to display it. */
15738 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15739 plus_constant (addr_mode
, XEXP (rtl
, 0),
15743 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15744 and will have been substituted directly into all expressions that use it.
15745 C does not have such a concept, but C++ and other languages do. */
15746 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
15747 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
15750 rtl
= targetm
.delegitimize_address (rtl
);
15752 /* If we don't look past the constant pool, we risk emitting a
15753 reference to a constant pool entry that isn't referenced from
15754 code, and thus is not emitted. */
15756 rtl
= avoid_constant_pool_reference (rtl
);
15758 /* Try harder to get a rtl. If this symbol ends up not being emitted
15759 in the current CU, resolve_addr will remove the expression referencing
15761 if (rtl
== NULL_RTX
15762 && TREE_CODE (decl
) == VAR_DECL
15763 && !DECL_EXTERNAL (decl
)
15764 && TREE_STATIC (decl
)
15765 && DECL_NAME (decl
)
15766 && !DECL_HARD_REGISTER (decl
)
15767 && DECL_MODE (decl
) != VOIDmode
)
15769 rtl
= make_decl_rtl_for_debug (decl
);
15771 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
15772 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
15779 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15780 returned. If so, the decl for the COMMON block is returned, and the
15781 value is the offset into the common block for the symbol. */
15784 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
15786 tree val_expr
, cvar
;
15788 HOST_WIDE_INT bitsize
, bitpos
;
15790 int unsignedp
, reversep
, volatilep
= 0;
15792 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15793 it does not have a value (the offset into the common area), or if it
15794 is thread local (as opposed to global) then it isn't common, and shouldn't
15795 be handled as such. */
15796 if (TREE_CODE (decl
) != VAR_DECL
15797 || !TREE_STATIC (decl
)
15798 || !DECL_HAS_VALUE_EXPR_P (decl
)
15802 val_expr
= DECL_VALUE_EXPR (decl
);
15803 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
15806 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
, &mode
,
15807 &unsignedp
, &reversep
, &volatilep
, true);
15809 if (cvar
== NULL_TREE
15810 || TREE_CODE (cvar
) != VAR_DECL
15811 || DECL_ARTIFICIAL (cvar
)
15812 || !TREE_PUBLIC (cvar
))
15816 if (offset
!= NULL
)
15818 if (!tree_fits_shwi_p (offset
))
15820 *value
= tree_to_shwi (offset
);
15823 *value
+= bitpos
/ BITS_PER_UNIT
;
15828 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15829 data attribute for a variable or a parameter. We generate the
15830 DW_AT_const_value attribute only in those cases where the given variable
15831 or parameter does not have a true "location" either in memory or in a
15832 register. This can happen (for example) when a constant is passed as an
15833 actual argument in a call to an inline function. (It's possible that
15834 these things can crop up in other ways also.) Note that one type of
15835 constant value which can be passed into an inlined function is a constant
15836 pointer. This can happen for example if an actual argument in an inlined
15837 function call evaluates to a compile-time constant address.
15839 CACHE_P is true if it is worth caching the location list for DECL,
15840 so that future calls can reuse it rather than regenerate it from scratch.
15841 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15842 since we will need to refer to them each time the function is inlined. */
15845 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
15846 enum dwarf_attribute attr
)
15849 dw_loc_list_ref list
;
15850 var_loc_list
*loc_list
;
15851 cached_dw_loc_list
*cache
;
15853 if (TREE_CODE (decl
) == ERROR_MARK
)
15856 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
15857 || TREE_CODE (decl
) == RESULT_DECL
);
15859 /* Try to get some constant RTL for this decl, and use that as the value of
15862 rtl
= rtl_for_decl_location (decl
);
15863 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15864 && add_const_value_attribute (die
, rtl
))
15867 /* See if we have single element location list that is equivalent to
15868 a constant value. That way we are better to use add_const_value_attribute
15869 rather than expanding constant value equivalent. */
15870 loc_list
= lookup_decl_loc (decl
);
15873 && loc_list
->first
->next
== NULL
15874 && NOTE_P (loc_list
->first
->loc
)
15875 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
15876 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
15878 struct var_loc_node
*node
;
15880 node
= loc_list
->first
;
15881 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
15882 if (GET_CODE (rtl
) == EXPR_LIST
)
15883 rtl
= XEXP (rtl
, 0);
15884 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15885 && add_const_value_attribute (die
, rtl
))
15888 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15889 list several times. See if we've already cached the contents. */
15891 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
15895 cache
= cached_dw_loc_list_table
->find_with_hash (decl
, DECL_UID (decl
));
15897 list
= cache
->loc_list
;
15901 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
15902 /* It is usually worth caching this result if the decl is from
15903 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15904 if (cache_p
&& list
&& list
->dw_loc_next
)
15906 cached_dw_loc_list
**slot
15907 = cached_dw_loc_list_table
->find_slot_with_hash (decl
,
15910 cache
= ggc_cleared_alloc
<cached_dw_loc_list
> ();
15911 cache
->decl_id
= DECL_UID (decl
);
15912 cache
->loc_list
= list
;
15918 add_AT_location_description (die
, attr
, list
);
15921 /* None of that worked, so it must not really have a location;
15922 try adding a constant value attribute from the DECL_INITIAL. */
15923 return tree_add_const_value_attribute_for_decl (die
, decl
);
15926 /* Add VARIABLE and DIE into deferred locations list. */
15929 defer_location (tree variable
, dw_die_ref die
)
15931 deferred_locations entry
;
15932 entry
.variable
= variable
;
15934 vec_safe_push (deferred_locations_list
, entry
);
15937 /* Helper function for tree_add_const_value_attribute. Natively encode
15938 initializer INIT into an array. Return true if successful. */
15941 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15945 if (init
== NULL_TREE
)
15949 switch (TREE_CODE (init
))
15952 type
= TREE_TYPE (init
);
15953 if (TREE_CODE (type
) == ARRAY_TYPE
)
15955 tree enttype
= TREE_TYPE (type
);
15956 machine_mode mode
= TYPE_MODE (enttype
);
15958 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15960 if (int_size_in_bytes (type
) != size
)
15962 if (size
> TREE_STRING_LENGTH (init
))
15964 memcpy (array
, TREE_STRING_POINTER (init
),
15965 TREE_STRING_LENGTH (init
));
15966 memset (array
+ TREE_STRING_LENGTH (init
),
15967 '\0', size
- TREE_STRING_LENGTH (init
));
15970 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15975 type
= TREE_TYPE (init
);
15976 if (int_size_in_bytes (type
) != size
)
15978 if (TREE_CODE (type
) == ARRAY_TYPE
)
15980 HOST_WIDE_INT min_index
;
15981 unsigned HOST_WIDE_INT cnt
;
15982 int curpos
= 0, fieldsize
;
15983 constructor_elt
*ce
;
15985 if (TYPE_DOMAIN (type
) == NULL_TREE
15986 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
15989 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15990 if (fieldsize
<= 0)
15993 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
15994 memset (array
, '\0', size
);
15995 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15997 tree val
= ce
->value
;
15998 tree index
= ce
->index
;
16000 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
16001 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
16004 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
16009 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
16012 curpos
= pos
+ fieldsize
;
16013 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
16015 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
16016 - tree_to_shwi (TREE_OPERAND (index
, 0));
16017 while (count
-- > 0)
16020 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
16021 curpos
+= fieldsize
;
16024 gcc_assert (curpos
<= size
);
16028 else if (TREE_CODE (type
) == RECORD_TYPE
16029 || TREE_CODE (type
) == UNION_TYPE
)
16031 tree field
= NULL_TREE
;
16032 unsigned HOST_WIDE_INT cnt
;
16033 constructor_elt
*ce
;
16035 if (int_size_in_bytes (type
) != size
)
16038 if (TREE_CODE (type
) == RECORD_TYPE
)
16039 field
= TYPE_FIELDS (type
);
16041 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
16043 tree val
= ce
->value
;
16044 int pos
, fieldsize
;
16046 if (ce
->index
!= 0)
16052 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
16055 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
16056 && TYPE_DOMAIN (TREE_TYPE (field
))
16057 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
16059 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
16060 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
16062 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
16063 pos
= int_byte_position (field
);
16064 gcc_assert (pos
+ fieldsize
<= size
);
16066 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
16072 case VIEW_CONVERT_EXPR
:
16073 case NON_LVALUE_EXPR
:
16074 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
16076 return native_encode_expr (init
, array
, size
, false) == size
;
16080 /* Attach a DW_AT_const_value attribute to DIE. The value of the
16081 attribute is the const value T. */
16084 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
16087 tree type
= TREE_TYPE (t
);
16090 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
16094 gcc_assert (!DECL_P (init
));
16096 rtl
= rtl_for_decl_init (init
, type
);
16098 return add_const_value_attribute (die
, rtl
);
16099 /* If the host and target are sane, try harder. */
16100 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
16101 && initializer_constant_valid_p (init
, type
))
16103 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
16104 if (size
> 0 && (int) size
== size
)
16106 unsigned char *array
= ggc_cleared_vec_alloc
<unsigned char> (size
);
16108 if (native_encode_initializer (init
, array
, size
))
16110 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
16119 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
16120 attribute is the const value of T, where T is an integral constant
16121 variable with static storage duration
16122 (so it can't be a PARM_DECL or a RESULT_DECL). */
16125 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
16129 || (TREE_CODE (decl
) != VAR_DECL
16130 && TREE_CODE (decl
) != CONST_DECL
)
16131 || (TREE_CODE (decl
) == VAR_DECL
16132 && !TREE_STATIC (decl
)))
16135 if (TREE_READONLY (decl
)
16136 && ! TREE_THIS_VOLATILE (decl
)
16137 && DECL_INITIAL (decl
))
16142 /* Don't add DW_AT_const_value if abstract origin already has one. */
16143 if (get_AT (var_die
, DW_AT_const_value
))
16146 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
16149 /* Convert the CFI instructions for the current function into a
16150 location list. This is used for DW_AT_frame_base when we targeting
16151 a dwarf2 consumer that does not support the dwarf3
16152 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
16155 static dw_loc_list_ref
16156 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
16160 dw_loc_list_ref list
, *list_tail
;
16162 dw_cfa_location last_cfa
, next_cfa
;
16163 const char *start_label
, *last_label
, *section
;
16164 dw_cfa_location remember
;
16167 gcc_assert (fde
!= NULL
);
16169 section
= secname_for_decl (current_function_decl
);
16173 memset (&next_cfa
, 0, sizeof (next_cfa
));
16174 next_cfa
.reg
= INVALID_REGNUM
;
16175 remember
= next_cfa
;
16177 start_label
= fde
->dw_fde_begin
;
16179 /* ??? Bald assumption that the CIE opcode list does not contain
16180 advance opcodes. */
16181 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
16182 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
16184 last_cfa
= next_cfa
;
16185 last_label
= start_label
;
16187 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
16189 /* If the first partition contained no CFI adjustments, the
16190 CIE opcodes apply to the whole first partition. */
16191 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16192 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
16193 list_tail
=&(*list_tail
)->dw_loc_next
;
16194 start_label
= last_label
= fde
->dw_fde_second_begin
;
16197 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
16199 switch (cfi
->dw_cfi_opc
)
16201 case DW_CFA_set_loc
:
16202 case DW_CFA_advance_loc1
:
16203 case DW_CFA_advance_loc2
:
16204 case DW_CFA_advance_loc4
:
16205 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16207 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16208 start_label
, last_label
, section
);
16210 list_tail
= &(*list_tail
)->dw_loc_next
;
16211 last_cfa
= next_cfa
;
16212 start_label
= last_label
;
16214 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
16217 case DW_CFA_advance_loc
:
16218 /* The encoding is complex enough that we should never emit this. */
16219 gcc_unreachable ();
16222 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
16225 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
16227 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16229 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16230 start_label
, last_label
, section
);
16232 list_tail
= &(*list_tail
)->dw_loc_next
;
16233 last_cfa
= next_cfa
;
16234 start_label
= last_label
;
16236 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16237 start_label
, fde
->dw_fde_end
, section
);
16238 list_tail
= &(*list_tail
)->dw_loc_next
;
16239 start_label
= last_label
= fde
->dw_fde_second_begin
;
16243 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16245 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16246 start_label
, last_label
, section
);
16247 list_tail
= &(*list_tail
)->dw_loc_next
;
16248 start_label
= last_label
;
16251 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
16253 fde
->dw_fde_second_begin
16254 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
16257 if (list
&& list
->dw_loc_next
)
16263 /* Compute a displacement from the "steady-state frame pointer" to the
16264 frame base (often the same as the CFA), and store it in
16265 frame_pointer_fb_offset. OFFSET is added to the displacement
16266 before the latter is negated. */
16269 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
16273 #ifdef FRAME_POINTER_CFA_OFFSET
16274 reg
= frame_pointer_rtx
;
16275 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
16277 reg
= arg_pointer_rtx
;
16278 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
16281 elim
= (ira_use_lra_p
16282 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
16283 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
16284 if (GET_CODE (elim
) == PLUS
)
16286 offset
+= INTVAL (XEXP (elim
, 1));
16287 elim
= XEXP (elim
, 0);
16290 frame_pointer_fb_offset
= -offset
;
16292 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
16293 in which to eliminate. This is because it's stack pointer isn't
16294 directly accessible as a register within the ISA. To work around
16295 this, assume that while we cannot provide a proper value for
16296 frame_pointer_fb_offset, we won't need one either. */
16297 frame_pointer_fb_offset_valid
16298 = ((SUPPORTS_STACK_ALIGNMENT
16299 && (elim
== hard_frame_pointer_rtx
16300 || elim
== stack_pointer_rtx
))
16301 || elim
== (frame_pointer_needed
16302 ? hard_frame_pointer_rtx
16303 : stack_pointer_rtx
));
16306 /* Generate a DW_AT_name attribute given some string value to be included as
16307 the value of the attribute. */
16310 add_name_attribute (dw_die_ref die
, const char *name_string
)
16312 if (name_string
!= NULL
&& *name_string
!= 0)
16314 if (demangle_name_func
)
16315 name_string
= (*demangle_name_func
) (name_string
);
16317 add_AT_string (die
, DW_AT_name
, name_string
);
16321 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
16322 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
16323 of TYPE accordingly.
16325 ??? This is a temporary measure until after we're able to generate
16326 regular DWARF for the complex Ada type system. */
16329 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
16330 dw_die_ref context_die
)
16333 dw_die_ref dtype_die
;
16335 if (!lang_hooks
.types
.descriptive_type
)
16338 dtype
= lang_hooks
.types
.descriptive_type (type
);
16342 dtype_die
= lookup_type_die (dtype
);
16345 gen_type_die (dtype
, context_die
);
16346 dtype_die
= lookup_type_die (dtype
);
16347 gcc_assert (dtype_die
);
16350 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
16353 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
16355 static const char *
16356 comp_dir_string (void)
16360 static const char *cached_wd
= NULL
;
16362 if (cached_wd
!= NULL
)
16365 wd
= get_src_pwd ();
16369 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
16373 wdlen
= strlen (wd
);
16374 wd1
= ggc_vec_alloc
<char> (wdlen
+ 2);
16376 wd1
[wdlen
] = DIR_SEPARATOR
;
16377 wd1
[wdlen
+ 1] = 0;
16381 cached_wd
= remap_debug_filename (wd
);
16385 /* Generate a DW_AT_comp_dir attribute for DIE. */
16388 add_comp_dir_attribute (dw_die_ref die
)
16390 const char * wd
= comp_dir_string ();
16392 add_AT_string (die
, DW_AT_comp_dir
, wd
);
16395 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
16399 lower_bound_default (void)
16401 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
16406 case DW_LANG_C_plus_plus
:
16408 case DW_LANG_ObjC_plus_plus
:
16411 case DW_LANG_Fortran77
:
16412 case DW_LANG_Fortran90
:
16413 case DW_LANG_Fortran95
:
16417 case DW_LANG_Python
:
16418 return dwarf_version
>= 4 ? 0 : -1;
16419 case DW_LANG_Ada95
:
16420 case DW_LANG_Ada83
:
16421 case DW_LANG_Cobol74
:
16422 case DW_LANG_Cobol85
:
16423 case DW_LANG_Pascal83
:
16424 case DW_LANG_Modula2
:
16426 return dwarf_version
>= 4 ? 1 : -1;
16432 /* Given a tree node describing an array bound (either lower or upper) output
16433 a representation for that bound. */
16436 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
16438 switch (TREE_CODE (bound
))
16443 /* All fixed-bounds are represented by INTEGER_CST nodes. */
16446 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
16449 /* Use the default if possible. */
16450 if (bound_attr
== DW_AT_lower_bound
16451 && tree_fits_shwi_p (bound
)
16452 && (dflt
= lower_bound_default ()) != -1
16453 && tree_to_shwi (bound
) == dflt
)
16456 /* If HOST_WIDE_INT is big enough then represent the bound as
16457 a constant value. We need to choose a form based on
16458 whether the type is signed or unsigned. We cannot just
16459 call add_AT_unsigned if the value itself is positive
16460 (add_AT_unsigned might add the unsigned value encoded as
16461 DW_FORM_data[1248]). Some DWARF consumers will lookup the
16462 bounds type and then sign extend any unsigned values found
16463 for signed types. This is needed only for
16464 DW_AT_{lower,upper}_bound, since for most other attributes,
16465 consumers will treat DW_FORM_data[1248] as unsigned values,
16466 regardless of the underlying type. */
16467 else if (prec
<= HOST_BITS_PER_WIDE_INT
16468 || tree_fits_uhwi_p (bound
))
16470 if (TYPE_UNSIGNED (TREE_TYPE (bound
)))
16471 add_AT_unsigned (subrange_die
, bound_attr
,
16472 TREE_INT_CST_LOW (bound
));
16474 add_AT_int (subrange_die
, bound_attr
, TREE_INT_CST_LOW (bound
));
16477 /* Otherwise represent the bound as an unsigned value with
16478 the precision of its type. The precision and signedness
16479 of the type will be necessary to re-interpret it
16481 add_AT_wide (subrange_die
, bound_attr
, bound
);
16486 case VIEW_CONVERT_EXPR
:
16487 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
16497 dw_die_ref decl_die
= lookup_decl_die (bound
);
16499 /* ??? Can this happen, or should the variable have been bound
16500 first? Probably it can, since I imagine that we try to create
16501 the types of parameters in the order in which they exist in
16502 the list, and won't have created a forward reference to a
16503 later parameter. */
16504 if (decl_die
!= NULL
)
16506 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16514 /* Otherwise try to create a stack operation procedure to
16515 evaluate the value of the array bound. */
16517 dw_die_ref ctx
, decl_die
;
16518 dw_loc_list_ref list
;
16520 list
= loc_list_from_tree (bound
, 2);
16521 if (list
== NULL
|| single_element_loc_list_p (list
))
16523 /* If DW_AT_*bound is not a reference nor constant, it is
16524 a DWARF expression rather than location description.
16525 For that loc_list_from_tree (bound, 0) is needed.
16526 If that fails to give a single element list,
16527 fall back to outputting this as a reference anyway. */
16528 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
16529 if (list2
&& single_element_loc_list_p (list2
))
16531 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
16538 if (current_function_decl
== 0)
16539 ctx
= comp_unit_die ();
16541 ctx
= lookup_decl_die (current_function_decl
);
16543 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
16544 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
16545 add_type_attribute (decl_die
, TREE_TYPE (bound
), TYPE_QUAL_CONST
, ctx
);
16546 add_AT_location_description (decl_die
, DW_AT_location
, list
);
16547 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16553 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16554 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16555 Note that the block of subscript information for an array type also
16556 includes information about the element type of the given array type. */
16559 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
16561 unsigned dimension_number
;
16563 dw_die_ref subrange_die
;
16565 for (dimension_number
= 0;
16566 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
16567 type
= TREE_TYPE (type
), dimension_number
++)
16569 tree domain
= TYPE_DOMAIN (type
);
16571 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
16574 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16575 and (in GNU C only) variable bounds. Handle all three forms
16577 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
16580 /* We have an array type with specified bounds. */
16581 lower
= TYPE_MIN_VALUE (domain
);
16582 upper
= TYPE_MAX_VALUE (domain
);
16584 /* Define the index type. */
16585 if (TREE_TYPE (domain
))
16587 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16588 TREE_TYPE field. We can't emit debug info for this
16589 because it is an unnamed integral type. */
16590 if (TREE_CODE (domain
) == INTEGER_TYPE
16591 && TYPE_NAME (domain
) == NULL_TREE
16592 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
16593 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
16596 add_type_attribute (subrange_die
, TREE_TYPE (domain
),
16597 TYPE_UNQUALIFIED
, type_die
);
16600 /* ??? If upper is NULL, the array has unspecified length,
16601 but it does have a lower bound. This happens with Fortran
16603 Since the debugger is definitely going to need to know N
16604 to produce useful results, go ahead and output the lower
16605 bound solo, and hope the debugger can cope. */
16607 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
16609 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
16612 /* Otherwise we have an array type with an unspecified length. The
16613 DWARF-2 spec does not say how to handle this; let's just leave out the
16618 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
16621 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16623 dw_die_ref decl_die
;
16624 HOST_WIDE_INT size
;
16626 switch (TREE_CODE (tree_node
))
16631 case ENUMERAL_TYPE
:
16634 case QUAL_UNION_TYPE
:
16635 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
16636 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
16638 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
16641 size
= int_size_in_bytes (tree_node
);
16644 /* For a data member of a struct or union, the DW_AT_byte_size is
16645 generally given as the number of bytes normally allocated for an
16646 object of the *declared* type of the member itself. This is true
16647 even for bit-fields. */
16648 size
= int_size_in_bytes (field_type (tree_node
));
16651 gcc_unreachable ();
16654 /* Note that `size' might be -1 when we get to this point. If it is, that
16655 indicates that the byte size of the entity in question is variable. We
16656 have no good way of expressing this fact in Dwarf at the present time,
16657 when location description was not used by the caller code instead. */
16659 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
16662 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16663 which specifies the distance in bits from the highest order bit of the
16664 "containing object" for the bit-field to the highest order bit of the
16667 For any given bit-field, the "containing object" is a hypothetical object
16668 (of some integral or enum type) within which the given bit-field lives. The
16669 type of this hypothetical "containing object" is always the same as the
16670 declared type of the individual bit-field itself. The determination of the
16671 exact location of the "containing object" for a bit-field is rather
16672 complicated. It's handled by the `field_byte_offset' function (above).
16674 Note that it is the size (in bytes) of the hypothetical "containing object"
16675 which will be given in the DW_AT_byte_size attribute for this bit-field.
16676 (See `byte_size_attribute' above). */
16679 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
16681 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
16682 tree type
= DECL_BIT_FIELD_TYPE (decl
);
16683 HOST_WIDE_INT bitpos_int
;
16684 HOST_WIDE_INT highest_order_object_bit_offset
;
16685 HOST_WIDE_INT highest_order_field_bit_offset
;
16686 HOST_WIDE_INT bit_offset
;
16688 /* Must be a field and a bit field. */
16689 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
16691 /* We can't yet handle bit-fields whose offsets are variable, so if we
16692 encounter such things, just return without generating any attribute
16693 whatsoever. Likewise for variable or too large size. */
16694 if (! tree_fits_shwi_p (bit_position (decl
))
16695 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
16698 bitpos_int
= int_bit_position (decl
);
16700 /* Note that the bit offset is always the distance (in bits) from the
16701 highest-order bit of the "containing object" to the highest-order bit of
16702 the bit-field itself. Since the "high-order end" of any object or field
16703 is different on big-endian and little-endian machines, the computation
16704 below must take account of these differences. */
16705 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
16706 highest_order_field_bit_offset
= bitpos_int
;
16708 if (! BYTES_BIG_ENDIAN
)
16710 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
16711 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
16715 = (! BYTES_BIG_ENDIAN
16716 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
16717 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
16719 if (bit_offset
< 0)
16720 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
16722 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
16725 /* For a FIELD_DECL node which represents a bit field, output an attribute
16726 which specifies the length in bits of the given field. */
16729 add_bit_size_attribute (dw_die_ref die
, tree decl
)
16731 /* Must be a field and a bit field. */
16732 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
16733 && DECL_BIT_FIELD_TYPE (decl
));
16735 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
16736 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
16739 /* If the compiled language is ANSI C, then add a 'prototyped'
16740 attribute, if arg types are given for the parameters of a function. */
16743 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
16745 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
16746 && prototype_p (func_type
))
16747 add_AT_flag (die
, DW_AT_prototyped
, 1);
16750 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16751 by looking in either the type declaration or object declaration
16754 static inline dw_die_ref
16755 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
16757 dw_die_ref origin_die
= NULL
;
16759 if (TREE_CODE (origin
) != FUNCTION_DECL
)
16761 /* We may have gotten separated from the block for the inlined
16762 function, if we're in an exception handler or some such; make
16763 sure that the abstract function has been written out.
16765 Doing this for nested functions is wrong, however; functions are
16766 distinct units, and our context might not even be inline. */
16770 fn
= TYPE_STUB_DECL (fn
);
16772 fn
= decl_function_context (fn
);
16774 dwarf2out_abstract_function (fn
);
16777 if (DECL_P (origin
))
16778 origin_die
= lookup_decl_die (origin
);
16779 else if (TYPE_P (origin
))
16780 origin_die
= lookup_type_die (origin
);
16782 /* XXX: Functions that are never lowered don't always have correct block
16783 trees (in the case of java, they simply have no block tree, in some other
16784 languages). For these functions, there is nothing we can really do to
16785 output correct debug info for inlined functions in all cases. Rather
16786 than die, we'll just produce deficient debug info now, in that we will
16787 have variables without a proper abstract origin. In the future, when all
16788 functions are lowered, we should re-add a gcc_assert (origin_die)
16792 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
16796 /* We do not currently support the pure_virtual attribute. */
16799 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
16801 if (DECL_VINDEX (func_decl
))
16803 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
16805 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
16806 add_AT_loc (die
, DW_AT_vtable_elem_location
,
16807 new_loc_descr (DW_OP_constu
,
16808 tree_to_shwi (DECL_VINDEX (func_decl
)),
16811 /* GNU extension: Record what type this method came from originally. */
16812 if (debug_info_level
> DINFO_LEVEL_TERSE
16813 && DECL_CONTEXT (func_decl
))
16814 add_AT_die_ref (die
, DW_AT_containing_type
,
16815 lookup_type_die (DECL_CONTEXT (func_decl
)));
16819 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16820 given decl. This used to be a vendor extension until after DWARF 4
16821 standardized it. */
16824 add_linkage_attr (dw_die_ref die
, tree decl
)
16826 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
16828 /* Mimic what assemble_name_raw does with a leading '*'. */
16829 if (name
[0] == '*')
16832 if (dwarf_version
>= 4)
16833 add_AT_string (die
, DW_AT_linkage_name
, name
);
16835 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
16838 /* Add source coordinate attributes for the given decl. */
16841 add_src_coords_attributes (dw_die_ref die
, tree decl
)
16843 expanded_location s
;
16845 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
16847 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16848 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
16849 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
16852 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16855 add_linkage_name (dw_die_ref die
, tree decl
)
16857 if (debug_info_level
> DINFO_LEVEL_NONE
16858 && (TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
16859 && TREE_PUBLIC (decl
)
16860 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
16861 && die
->die_tag
!= DW_TAG_member
)
16863 /* Defer until we have an assembler name set. */
16864 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
16866 limbo_die_node
*asm_name
;
16868 asm_name
= ggc_cleared_alloc
<limbo_die_node
> ();
16869 asm_name
->die
= die
;
16870 asm_name
->created_for
= decl
;
16871 asm_name
->next
= deferred_asm_name
;
16872 deferred_asm_name
= asm_name
;
16874 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
16875 add_linkage_attr (die
, decl
);
16879 /* Add a DW_AT_name attribute and source coordinate attribute for the
16880 given decl, but only if it actually has a name. */
16883 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
16887 decl_name
= DECL_NAME (decl
);
16888 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
16890 const char *name
= dwarf2_name (decl
, 0);
16892 add_name_attribute (die
, name
);
16893 if (! DECL_ARTIFICIAL (decl
))
16894 add_src_coords_attributes (die
, decl
);
16896 add_linkage_name (die
, decl
);
16899 #ifdef VMS_DEBUGGING_INFO
16900 /* Get the function's name, as described by its RTL. This may be different
16901 from the DECL_NAME name used in the source file. */
16902 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
16904 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
16905 XEXP (DECL_RTL (decl
), 0), false);
16906 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
16908 #endif /* VMS_DEBUGGING_INFO */
16911 #ifdef VMS_DEBUGGING_INFO
16912 /* Output the debug main pointer die for VMS */
16915 dwarf2out_vms_debug_main_pointer (void)
16917 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
16920 /* Allocate the VMS debug main subprogram die. */
16921 die
= ggc_cleared_alloc
<die_node
> ();
16922 die
->die_tag
= DW_TAG_subprogram
;
16923 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
16924 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
16925 current_function_funcdef_no
);
16926 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
16928 /* Make it the first child of comp_unit_die (). */
16929 die
->die_parent
= comp_unit_die ();
16930 if (comp_unit_die ()->die_child
)
16932 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
16933 comp_unit_die ()->die_child
->die_sib
= die
;
16937 die
->die_sib
= die
;
16938 comp_unit_die ()->die_child
= die
;
16941 #endif /* VMS_DEBUGGING_INFO */
16943 /* Push a new declaration scope. */
16946 push_decl_scope (tree scope
)
16948 vec_safe_push (decl_scope_table
, scope
);
16951 /* Pop a declaration scope. */
16954 pop_decl_scope (void)
16956 decl_scope_table
->pop ();
16959 /* walk_tree helper function for uses_local_type, below. */
16962 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
16965 *walk_subtrees
= 0;
16968 tree name
= TYPE_NAME (*tp
);
16969 if (name
&& DECL_P (name
) && decl_function_context (name
))
16975 /* If TYPE involves a function-local type (including a local typedef to a
16976 non-local type), returns that type; otherwise returns NULL_TREE. */
16979 uses_local_type (tree type
)
16981 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
16985 /* Return the DIE for the scope that immediately contains this type.
16986 Non-named types that do not involve a function-local type get global
16987 scope. Named types nested in namespaces or other types get their
16988 containing scope. All other types (i.e. function-local named types) get
16989 the current active scope. */
16992 scope_die_for (tree t
, dw_die_ref context_die
)
16994 dw_die_ref scope_die
= NULL
;
16995 tree containing_scope
;
16997 /* Non-types always go in the current scope. */
16998 gcc_assert (TYPE_P (t
));
17000 /* Use the scope of the typedef, rather than the scope of the type
17002 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
17003 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
17005 containing_scope
= TYPE_CONTEXT (t
);
17007 /* Use the containing namespace if there is one. */
17008 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
17010 if (context_die
== lookup_decl_die (containing_scope
))
17012 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
17013 context_die
= get_context_die (containing_scope
);
17015 containing_scope
= NULL_TREE
;
17018 /* Ignore function type "scopes" from the C frontend. They mean that
17019 a tagged type is local to a parmlist of a function declarator, but
17020 that isn't useful to DWARF. */
17021 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
17022 containing_scope
= NULL_TREE
;
17024 if (SCOPE_FILE_SCOPE_P (containing_scope
))
17026 /* If T uses a local type keep it local as well, to avoid references
17027 to function-local DIEs from outside the function. */
17028 if (current_function_decl
&& uses_local_type (t
))
17029 scope_die
= context_die
;
17031 scope_die
= comp_unit_die ();
17033 else if (TYPE_P (containing_scope
))
17035 /* For types, we can just look up the appropriate DIE. */
17036 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17037 scope_die
= get_context_die (containing_scope
);
17040 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
17041 if (scope_die
== NULL
)
17042 scope_die
= comp_unit_die ();
17046 scope_die
= context_die
;
17051 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
17054 local_scope_p (dw_die_ref context_die
)
17056 for (; context_die
; context_die
= context_die
->die_parent
)
17057 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
17058 || context_die
->die_tag
== DW_TAG_subprogram
)
17064 /* Returns nonzero if CONTEXT_DIE is a class. */
17067 class_scope_p (dw_die_ref context_die
)
17069 return (context_die
17070 && (context_die
->die_tag
== DW_TAG_structure_type
17071 || context_die
->die_tag
== DW_TAG_class_type
17072 || context_die
->die_tag
== DW_TAG_interface_type
17073 || context_die
->die_tag
== DW_TAG_union_type
));
17076 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
17077 whether or not to treat a DIE in this context as a declaration. */
17080 class_or_namespace_scope_p (dw_die_ref context_die
)
17082 return (class_scope_p (context_die
)
17083 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
17086 /* Many forms of DIEs require a "type description" attribute. This
17087 routine locates the proper "type descriptor" die for the type given
17088 by 'type' plus any additional qualifiers given by 'cv_quals', and
17089 adds a DW_AT_type attribute below the given die. */
17092 add_type_attribute (dw_die_ref object_die
, tree type
, int cv_quals
,
17093 dw_die_ref context_die
)
17095 enum tree_code code
= TREE_CODE (type
);
17096 dw_die_ref type_die
= NULL
;
17098 /* ??? If this type is an unnamed subrange type of an integral, floating-point
17099 or fixed-point type, use the inner type. This is because we have no
17100 support for unnamed types in base_type_die. This can happen if this is
17101 an Ada subrange type. Correct solution is emit a subrange type die. */
17102 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
17103 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
17104 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
17106 if (code
== ERROR_MARK
17107 /* Handle a special case. For functions whose return type is void, we
17108 generate *no* type attribute. (Note that no object may have type
17109 `void', so this only applies to function return types). */
17110 || code
== VOID_TYPE
)
17113 type_die
= modified_type_die (type
,
17114 cv_quals
| TYPE_QUALS_NO_ADDR_SPACE (type
),
17117 if (type_die
!= NULL
)
17118 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
17121 /* Given an object die, add the calling convention attribute for the
17122 function call type. */
17124 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
17126 enum dwarf_calling_convention value
= DW_CC_normal
;
17128 value
= ((enum dwarf_calling_convention
)
17129 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
17132 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
17134 /* DWARF 2 doesn't provide a way to identify a program's source-level
17135 entry point. DW_AT_calling_convention attributes are only meant
17136 to describe functions' calling conventions. However, lacking a
17137 better way to signal the Fortran main program, we used this for
17138 a long time, following existing custom. Now, DWARF 4 has
17139 DW_AT_main_subprogram, which we add below, but some tools still
17140 rely on the old way, which we thus keep. */
17141 value
= DW_CC_program
;
17143 if (dwarf_version
>= 4 || !dwarf_strict
)
17144 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
17147 /* Only add the attribute if the backend requests it, and
17148 is not DW_CC_normal. */
17149 if (value
&& (value
!= DW_CC_normal
))
17150 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
17153 /* Given a tree pointer to a struct, class, union, or enum type node, return
17154 a pointer to the (string) tag name for the given type, or zero if the type
17155 was declared without a tag. */
17157 static const char *
17158 type_tag (const_tree type
)
17160 const char *name
= 0;
17162 if (TYPE_NAME (type
) != 0)
17166 /* Find the IDENTIFIER_NODE for the type name. */
17167 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
17168 && !TYPE_NAMELESS (type
))
17169 t
= TYPE_NAME (type
);
17171 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
17172 a TYPE_DECL node, regardless of whether or not a `typedef' was
17174 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
17175 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
17177 /* We want to be extra verbose. Don't call dwarf_name if
17178 DECL_NAME isn't set. The default hook for decl_printable_name
17179 doesn't like that, and in this context it's correct to return
17180 0, instead of "<anonymous>" or the like. */
17181 if (DECL_NAME (TYPE_NAME (type
))
17182 && !DECL_NAMELESS (TYPE_NAME (type
)))
17183 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
17186 /* Now get the name as a string, or invent one. */
17187 if (!name
&& t
!= 0)
17188 name
= IDENTIFIER_POINTER (t
);
17191 return (name
== 0 || *name
== '\0') ? 0 : name
;
17194 /* Return the type associated with a data member, make a special check
17195 for bit field types. */
17198 member_declared_type (const_tree member
)
17200 return (DECL_BIT_FIELD_TYPE (member
)
17201 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
17204 /* Get the decl's label, as described by its RTL. This may be different
17205 from the DECL_NAME name used in the source file. */
17208 static const char *
17209 decl_start_label (tree decl
)
17212 const char *fnname
;
17214 x
= DECL_RTL (decl
);
17215 gcc_assert (MEM_P (x
));
17218 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
17220 fnname
= XSTR (x
, 0);
17225 /* These routines generate the internal representation of the DIE's for
17226 the compilation unit. Debugging information is collected by walking
17227 the declaration trees passed in from dwarf2out_decl(). */
17230 gen_array_type_die (tree type
, dw_die_ref context_die
)
17232 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17233 dw_die_ref array_die
;
17235 /* GNU compilers represent multidimensional array types as sequences of one
17236 dimensional array types whose element types are themselves array types.
17237 We sometimes squish that down to a single array_type DIE with multiple
17238 subscripts in the Dwarf debugging info. The draft Dwarf specification
17239 say that we are allowed to do this kind of compression in C, because
17240 there is no difference between an array of arrays and a multidimensional
17241 array. We don't do this for Ada to remain as close as possible to the
17242 actual representation, which is especially important against the language
17243 flexibilty wrt arrays of variable size. */
17245 bool collapse_nested_arrays
= !is_ada ();
17248 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
17249 DW_TAG_string_type doesn't have DW_AT_type attribute). */
17250 if (TYPE_STRING_FLAG (type
)
17251 && TREE_CODE (type
) == ARRAY_TYPE
17253 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
17255 HOST_WIDE_INT size
;
17257 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
17258 add_name_attribute (array_die
, type_tag (type
));
17259 equate_type_number_to_die (type
, array_die
);
17260 size
= int_size_in_bytes (type
);
17262 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17263 else if (TYPE_DOMAIN (type
) != NULL_TREE
17264 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
17265 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
17267 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
17268 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
17270 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
17271 if (loc
&& size
> 0)
17273 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
17274 if (size
!= DWARF2_ADDR_SIZE
)
17275 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17281 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17282 add_name_attribute (array_die
, type_tag (type
));
17283 equate_type_number_to_die (type
, array_die
);
17285 if (TREE_CODE (type
) == VECTOR_TYPE
)
17286 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
17288 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17290 && TREE_CODE (type
) == ARRAY_TYPE
17291 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
17292 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
17293 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17296 /* We default the array ordering. SDB will probably do
17297 the right things even if DW_AT_ordering is not present. It's not even
17298 an issue until we start to get into multidimensional arrays anyway. If
17299 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
17300 then we'll have to put the DW_AT_ordering attribute back in. (But if
17301 and when we find out that we need to put these in, we will only do so
17302 for multidimensional arrays. */
17303 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
17306 if (TREE_CODE (type
) == VECTOR_TYPE
)
17308 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
17309 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17310 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
17311 add_bound_info (subrange_die
, DW_AT_upper_bound
,
17312 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
17315 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
17317 /* Add representation of the type of the elements of this array type and
17318 emit the corresponding DIE if we haven't done it already. */
17319 element_type
= TREE_TYPE (type
);
17320 if (collapse_nested_arrays
)
17321 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
17323 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
17325 element_type
= TREE_TYPE (element_type
);
17328 add_type_attribute (array_die
, element_type
, TYPE_UNQUALIFIED
, context_die
);
17330 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
17331 if (TYPE_ARTIFICIAL (type
))
17332 add_AT_flag (array_die
, DW_AT_artificial
, 1);
17334 if (get_AT (array_die
, DW_AT_name
))
17335 add_pubtype (type
, array_die
);
17338 static dw_loc_descr_ref
17339 descr_info_loc (tree val
, tree base_decl
)
17341 HOST_WIDE_INT size
;
17342 dw_loc_descr_ref loc
, loc2
;
17343 enum dwarf_location_atom op
;
17345 if (val
== base_decl
)
17346 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
17348 switch (TREE_CODE (val
))
17351 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17353 return loc_descriptor_from_tree (val
, 0);
17355 if (tree_fits_shwi_p (val
))
17356 return int_loc_descriptor (tree_to_shwi (val
));
17359 size
= int_size_in_bytes (TREE_TYPE (val
));
17362 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17365 if (size
== DWARF2_ADDR_SIZE
)
17366 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
17368 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
17370 case POINTER_PLUS_EXPR
:
17372 if (tree_fits_uhwi_p (TREE_OPERAND (val
, 1))
17373 && tree_to_uhwi (TREE_OPERAND (val
, 1)) < 16384)
17375 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17378 loc_descr_plus_const (&loc
, tree_to_shwi (TREE_OPERAND (val
, 1)));
17384 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17387 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
17390 add_loc_descr (&loc
, loc2
);
17391 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
17413 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
17414 tree val
, tree base_decl
)
17416 dw_loc_descr_ref loc
;
17418 if (tree_fits_shwi_p (val
))
17420 add_AT_unsigned (die
, attr
, tree_to_shwi (val
));
17424 loc
= descr_info_loc (val
, base_decl
);
17428 add_AT_loc (die
, attr
, loc
);
17431 /* This routine generates DIE for array with hidden descriptor, details
17432 are filled into *info by a langhook. */
17435 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
17436 dw_die_ref context_die
)
17438 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17439 dw_die_ref array_die
;
17442 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17443 add_name_attribute (array_die
, type_tag (type
));
17444 equate_type_number_to_die (type
, array_die
);
17446 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17448 && info
->ndimensions
>= 2)
17449 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17451 if (info
->data_location
)
17452 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
17454 if (info
->associated
)
17455 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
17457 if (info
->allocated
)
17458 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
17461 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
17463 dw_die_ref subrange_die
17464 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17466 if (info
->dimen
[dim
].lower_bound
)
17468 /* If it is the default value, omit it. */
17471 if (tree_fits_shwi_p (info
->dimen
[dim
].lower_bound
)
17472 && (dflt
= lower_bound_default ()) != -1
17473 && tree_to_shwi (info
->dimen
[dim
].lower_bound
) == dflt
)
17476 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
17477 info
->dimen
[dim
].lower_bound
,
17480 if (info
->dimen
[dim
].upper_bound
)
17481 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
17482 info
->dimen
[dim
].upper_bound
,
17484 if (info
->dimen
[dim
].stride
)
17485 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
17486 info
->dimen
[dim
].stride
,
17490 gen_type_die (info
->element_type
, context_die
);
17491 add_type_attribute (array_die
, info
->element_type
, TYPE_UNQUALIFIED
,
17494 if (get_AT (array_die
, DW_AT_name
))
17495 add_pubtype (type
, array_die
);
17500 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
17502 tree origin
= decl_ultimate_origin (decl
);
17503 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
17505 if (origin
!= NULL
)
17506 add_abstract_origin_attribute (decl_die
, origin
);
17509 add_name_and_src_coords_attributes (decl_die
, decl
);
17510 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
17511 TYPE_UNQUALIFIED
, context_die
);
17514 if (DECL_ABSTRACT_P (decl
))
17515 equate_decl_number_to_die (decl
, decl_die
);
17517 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
17521 /* Walk through the list of incomplete types again, trying once more to
17522 emit full debugging info for them. */
17525 retry_incomplete_types (void)
17529 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
17530 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
17531 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
17534 /* Determine what tag to use for a record type. */
17536 static enum dwarf_tag
17537 record_type_tag (tree type
)
17539 if (! lang_hooks
.types
.classify_record
)
17540 return DW_TAG_structure_type
;
17542 switch (lang_hooks
.types
.classify_record (type
))
17544 case RECORD_IS_STRUCT
:
17545 return DW_TAG_structure_type
;
17547 case RECORD_IS_CLASS
:
17548 return DW_TAG_class_type
;
17550 case RECORD_IS_INTERFACE
:
17551 if (dwarf_version
>= 3 || !dwarf_strict
)
17552 return DW_TAG_interface_type
;
17553 return DW_TAG_structure_type
;
17556 gcc_unreachable ();
17560 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17561 include all of the information about the enumeration values also. Each
17562 enumerated type name/value is listed as a child of the enumerated type
17566 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
17568 dw_die_ref type_die
= lookup_type_die (type
);
17570 if (type_die
== NULL
)
17572 type_die
= new_die (DW_TAG_enumeration_type
,
17573 scope_die_for (type
, context_die
), type
);
17574 equate_type_number_to_die (type
, type_die
);
17575 add_name_attribute (type_die
, type_tag (type
));
17576 if (dwarf_version
>= 4 || !dwarf_strict
)
17578 if (ENUM_IS_SCOPED (type
))
17579 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
17580 if (ENUM_IS_OPAQUE (type
))
17581 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17584 else if (! TYPE_SIZE (type
))
17587 remove_AT (type_die
, DW_AT_declaration
);
17589 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17590 given enum type is incomplete, do not generate the DW_AT_byte_size
17591 attribute or the DW_AT_element_list attribute. */
17592 if (TYPE_SIZE (type
))
17596 TREE_ASM_WRITTEN (type
) = 1;
17597 add_byte_size_attribute (type_die
, type
);
17598 if (dwarf_version
>= 3 || !dwarf_strict
)
17600 tree underlying
= lang_hooks
.types
.enum_underlying_base_type (type
);
17601 add_type_attribute (type_die
, underlying
, TYPE_UNQUALIFIED
,
17604 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17606 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17607 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17610 /* If the first reference to this type was as the return type of an
17611 inline function, then it may not have a parent. Fix this now. */
17612 if (type_die
->die_parent
== NULL
)
17613 add_child_die (scope_die_for (type
, context_die
), type_die
);
17615 for (link
= TYPE_VALUES (type
);
17616 link
!= NULL
; link
= TREE_CHAIN (link
))
17618 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17619 tree value
= TREE_VALUE (link
);
17621 add_name_attribute (enum_die
,
17622 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17624 if (TREE_CODE (value
) == CONST_DECL
)
17625 value
= DECL_INITIAL (value
);
17627 if (simple_type_size_in_bits (TREE_TYPE (value
))
17628 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
17630 /* For constant forms created by add_AT_unsigned DWARF
17631 consumers (GDB, elfutils, etc.) always zero extend
17632 the value. Only when the actual value is negative
17633 do we need to use add_AT_int to generate a constant
17634 form that can represent negative values. */
17635 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
17636 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
17637 add_AT_unsigned (enum_die
, DW_AT_const_value
,
17638 (unsigned HOST_WIDE_INT
) val
);
17640 add_AT_int (enum_die
, DW_AT_const_value
, val
);
17643 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
17644 that here. TODO: This should be re-worked to use correct
17645 signed/unsigned double tags for all cases. */
17646 add_AT_wide (enum_die
, DW_AT_const_value
, value
);
17649 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17650 if (TYPE_ARTIFICIAL (type
))
17651 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17654 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17656 add_pubtype (type
, type_die
);
17661 /* Generate a DIE to represent either a real live formal parameter decl or to
17662 represent just the type of some formal parameter position in some function
17665 Note that this routine is a bit unusual because its argument may be a
17666 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17667 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17668 node. If it's the former then this function is being called to output a
17669 DIE to represent a formal parameter object (or some inlining thereof). If
17670 it's the latter, then this function is only being called to output a
17671 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17672 argument type of some subprogram type.
17673 If EMIT_NAME_P is true, name and source coordinate attributes
17677 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17678 dw_die_ref context_die
)
17680 tree node_or_origin
= node
? node
: origin
;
17681 tree ultimate_origin
;
17682 dw_die_ref parm_die
17683 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
17685 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
17687 case tcc_declaration
:
17688 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
17689 if (node
|| ultimate_origin
)
17690 origin
= ultimate_origin
;
17691 if (origin
!= NULL
)
17692 add_abstract_origin_attribute (parm_die
, origin
);
17693 else if (emit_name_p
)
17694 add_name_and_src_coords_attributes (parm_die
, node
);
17696 || (! DECL_ABSTRACT_P (node_or_origin
)
17697 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
17698 decl_function_context
17699 (node_or_origin
))))
17701 tree type
= TREE_TYPE (node_or_origin
);
17702 if (decl_by_reference_p (node_or_origin
))
17703 add_type_attribute (parm_die
, TREE_TYPE (type
),
17704 TYPE_UNQUALIFIED
, context_die
);
17706 add_type_attribute (parm_die
, type
,
17707 decl_quals (node_or_origin
),
17710 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
17711 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17713 if (node
&& node
!= origin
)
17714 equate_decl_number_to_die (node
, parm_die
);
17715 if (! DECL_ABSTRACT_P (node_or_origin
))
17716 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
17717 node
== NULL
, DW_AT_location
);
17722 /* We were called with some kind of a ..._TYPE node. */
17723 add_type_attribute (parm_die
, node_or_origin
, TYPE_UNQUALIFIED
,
17728 gcc_unreachable ();
17734 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17735 children DW_TAG_formal_parameter DIEs representing the arguments of the
17738 PARM_PACK must be a function parameter pack.
17739 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17740 must point to the subsequent arguments of the function PACK_ARG belongs to.
17741 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17742 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17743 following the last one for which a DIE was generated. */
17746 gen_formal_parameter_pack_die (tree parm_pack
,
17748 dw_die_ref subr_die
,
17752 dw_die_ref parm_pack_die
;
17754 gcc_assert (parm_pack
17755 && lang_hooks
.function_parameter_pack_p (parm_pack
)
17758 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
17759 add_src_coords_attributes (parm_pack_die
, parm_pack
);
17761 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
17763 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
17766 gen_formal_parameter_die (arg
, NULL
,
17767 false /* Don't emit name attribute. */,
17772 return parm_pack_die
;
17775 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17776 at the end of an (ANSI prototyped) formal parameters list. */
17779 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
17781 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
17784 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17785 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17786 parameters as specified in some function type specification (except for
17787 those which appear as part of a function *definition*). */
17790 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
17793 tree formal_type
= NULL
;
17794 tree first_parm_type
;
17797 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
17799 arg
= DECL_ARGUMENTS (function_or_method_type
);
17800 function_or_method_type
= TREE_TYPE (function_or_method_type
);
17805 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
17807 /* Make our first pass over the list of formal parameter types and output a
17808 DW_TAG_formal_parameter DIE for each one. */
17809 for (link
= first_parm_type
; link
; )
17811 dw_die_ref parm_die
;
17813 formal_type
= TREE_VALUE (link
);
17814 if (formal_type
== void_type_node
)
17817 /* Output a (nameless) DIE to represent the formal parameter itself. */
17818 if (!POINTER_BOUNDS_TYPE_P (formal_type
))
17820 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
17821 true /* Emit name attribute. */,
17823 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
17824 && link
== first_parm_type
)
17826 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17827 if (dwarf_version
>= 3 || !dwarf_strict
)
17828 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
17830 else if (arg
&& DECL_ARTIFICIAL (arg
))
17831 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17834 link
= TREE_CHAIN (link
);
17836 arg
= DECL_CHAIN (arg
);
17839 /* If this function type has an ellipsis, add a
17840 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17841 if (formal_type
!= void_type_node
)
17842 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
17844 /* Make our second (and final) pass over the list of formal parameter types
17845 and output DIEs to represent those types (as necessary). */
17846 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
17847 link
&& TREE_VALUE (link
);
17848 link
= TREE_CHAIN (link
))
17849 gen_type_die (TREE_VALUE (link
), context_die
);
17852 /* We want to generate the DIE for TYPE so that we can generate the
17853 die for MEMBER, which has been defined; we will need to refer back
17854 to the member declaration nested within TYPE. If we're trying to
17855 generate minimal debug info for TYPE, processing TYPE won't do the
17856 trick; we need to attach the member declaration by hand. */
17859 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
17861 gen_type_die (type
, context_die
);
17863 /* If we're trying to avoid duplicate debug info, we may not have
17864 emitted the member decl for this function. Emit it now. */
17865 if (TYPE_STUB_DECL (type
)
17866 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
17867 && ! lookup_decl_die (member
))
17869 dw_die_ref type_die
;
17870 gcc_assert (!decl_ultimate_origin (member
));
17872 push_decl_scope (type
);
17873 type_die
= lookup_type_die_strip_naming_typedef (type
);
17874 if (TREE_CODE (member
) == FUNCTION_DECL
)
17875 gen_subprogram_die (member
, type_die
);
17876 else if (TREE_CODE (member
) == FIELD_DECL
)
17878 /* Ignore the nameless fields that are used to skip bits but handle
17879 C++ anonymous unions and structs. */
17880 if (DECL_NAME (member
) != NULL_TREE
17881 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
17882 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
17884 gen_type_die (member_declared_type (member
), type_die
);
17885 gen_field_die (member
, type_die
);
17889 gen_variable_die (member
, NULL_TREE
, type_die
);
17895 /* Forward declare these functions, because they are mutually recursive
17896 with their set_block_* pairing functions. */
17897 static void set_decl_origin_self (tree
);
17898 static void set_decl_abstract_flags (tree
, int);
17900 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
17901 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
17902 that it points to the node itself, thus indicating that the node is its
17903 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
17904 the given node is NULL, recursively descend the decl/block tree which
17905 it is the root of, and for each other ..._DECL or BLOCK node contained
17906 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
17907 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
17908 values to point to themselves. */
17911 set_block_origin_self (tree stmt
)
17913 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
17915 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
17920 for (local_decl
= BLOCK_VARS (stmt
);
17921 local_decl
!= NULL_TREE
;
17922 local_decl
= DECL_CHAIN (local_decl
))
17923 if (! DECL_EXTERNAL (local_decl
))
17924 set_decl_origin_self (local_decl
); /* Potential recursion. */
17930 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17931 subblock
!= NULL_TREE
;
17932 subblock
= BLOCK_CHAIN (subblock
))
17933 set_block_origin_self (subblock
); /* Recurse. */
17938 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
17939 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
17940 node to so that it points to the node itself, thus indicating that the
17941 node represents its own (abstract) origin. Additionally, if the
17942 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
17943 the decl/block tree of which the given node is the root of, and for
17944 each other ..._DECL or BLOCK node contained therein whose
17945 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
17946 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
17947 point to themselves. */
17950 set_decl_origin_self (tree decl
)
17952 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
17954 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
17955 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17959 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17960 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
17961 if (DECL_INITIAL (decl
) != NULL_TREE
17962 && DECL_INITIAL (decl
) != error_mark_node
)
17963 set_block_origin_self (DECL_INITIAL (decl
));
17968 /* Given a pointer to some BLOCK node, and a boolean value to set the
17969 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
17970 the given block, and for all local decls and all local sub-blocks
17971 (recursively) which are contained therein. */
17974 set_block_abstract_flags (tree stmt
, int setting
)
17980 BLOCK_ABSTRACT (stmt
) = setting
;
17982 for (local_decl
= BLOCK_VARS (stmt
);
17983 local_decl
!= NULL_TREE
;
17984 local_decl
= DECL_CHAIN (local_decl
))
17985 if (! DECL_EXTERNAL (local_decl
))
17986 set_decl_abstract_flags (local_decl
, setting
);
17988 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
17990 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
17991 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
17992 || TREE_CODE (local_decl
) == PARM_DECL
)
17993 set_decl_abstract_flags (local_decl
, setting
);
17996 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17997 subblock
!= NULL_TREE
;
17998 subblock
= BLOCK_CHAIN (subblock
))
17999 set_block_abstract_flags (subblock
, setting
);
18002 /* Given a pointer to some ..._DECL node, and a boolean value to set the
18003 "abstract" flags to, set that value into the DECL_ABSTRACT_P flag for the
18004 given decl, and (in the case where the decl is a FUNCTION_DECL) also
18005 set the abstract flags for all of the parameters, local vars, local
18006 blocks and sub-blocks (recursively) to the same setting. */
18009 set_decl_abstract_flags (tree decl
, int setting
)
18011 DECL_ABSTRACT_P (decl
) = setting
;
18012 if (TREE_CODE (decl
) == FUNCTION_DECL
)
18016 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
18017 DECL_ABSTRACT_P (arg
) = setting
;
18018 if (DECL_INITIAL (decl
) != NULL_TREE
18019 && DECL_INITIAL (decl
) != error_mark_node
)
18020 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
18024 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18025 may later generate inlined and/or out-of-line instances of. */
18028 dwarf2out_abstract_function (tree decl
)
18030 dw_die_ref old_die
;
18034 hash_table
<decl_loc_hasher
> *old_decl_loc_table
;
18035 hash_table
<dw_loc_list_hasher
> *old_cached_dw_loc_list_table
;
18036 int old_call_site_count
, old_tail_call_site_count
;
18037 struct call_arg_loc_node
*old_call_arg_locations
;
18039 /* Make sure we have the actual abstract inline, not a clone. */
18040 decl
= DECL_ORIGIN (decl
);
18042 old_die
= lookup_decl_die (decl
);
18043 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
18044 /* We've already generated the abstract instance. */
18047 /* We can be called while recursively when seeing block defining inlined subroutine
18048 DIE. Be sure to not clobber the outer location table nor use it or we would
18049 get locations in abstract instantces. */
18050 old_decl_loc_table
= decl_loc_table
;
18051 decl_loc_table
= NULL
;
18052 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
18053 cached_dw_loc_list_table
= NULL
;
18054 old_call_arg_locations
= call_arg_locations
;
18055 call_arg_locations
= NULL
;
18056 old_call_site_count
= call_site_count
;
18057 call_site_count
= -1;
18058 old_tail_call_site_count
= tail_call_site_count
;
18059 tail_call_site_count
= -1;
18061 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18062 we don't get confused by DECL_ABSTRACT_P. */
18063 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18065 context
= decl_class_context (decl
);
18067 gen_type_die_for_member
18068 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
18071 /* Pretend we've just finished compiling this function. */
18072 save_fn
= current_function_decl
;
18073 current_function_decl
= decl
;
18075 was_abstract
= DECL_ABSTRACT_P (decl
);
18076 set_decl_abstract_flags (decl
, 1);
18077 dwarf2out_decl (decl
);
18078 if (! was_abstract
)
18079 set_decl_abstract_flags (decl
, 0);
18081 current_function_decl
= save_fn
;
18082 decl_loc_table
= old_decl_loc_table
;
18083 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
18084 call_arg_locations
= old_call_arg_locations
;
18085 call_site_count
= old_call_site_count
;
18086 tail_call_site_count
= old_tail_call_site_count
;
18089 /* Helper function of premark_used_types() which gets called through
18092 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18093 marked as unused by prune_unused_types. */
18096 premark_used_types_helper (tree
const &type
, void *)
18100 die
= lookup_type_die (type
);
18102 die
->die_perennial_p
= 1;
18106 /* Helper function of premark_types_used_by_global_vars which gets called
18107 through htab_traverse.
18109 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18110 marked as unused by prune_unused_types. The DIE of the type is marked
18111 only if the global variable using the type will actually be emitted. */
18114 premark_types_used_by_global_vars_helper (types_used_by_vars_entry
**slot
,
18117 struct types_used_by_vars_entry
*entry
;
18120 entry
= (struct types_used_by_vars_entry
*) *slot
;
18121 gcc_assert (entry
->type
!= NULL
18122 && entry
->var_decl
!= NULL
);
18123 die
= lookup_type_die (entry
->type
);
18126 /* Ask cgraph if the global variable really is to be emitted.
18127 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18128 varpool_node
*node
= varpool_node::get (entry
->var_decl
);
18129 if (node
&& node
->definition
)
18131 die
->die_perennial_p
= 1;
18132 /* Keep the parent DIEs as well. */
18133 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
18134 die
->die_perennial_p
= 1;
18140 /* Mark all members of used_types_hash as perennial. */
18143 premark_used_types (struct function
*fun
)
18145 if (fun
&& fun
->used_types_hash
)
18146 fun
->used_types_hash
->traverse
<void *, premark_used_types_helper
> (NULL
);
18149 /* Mark all members of types_used_by_vars_entry as perennial. */
18152 premark_types_used_by_global_vars (void)
18154 if (types_used_by_vars_hash
)
18155 types_used_by_vars_hash
18156 ->traverse
<void *, premark_types_used_by_global_vars_helper
> (NULL
);
18159 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
18160 for CA_LOC call arg loc node. */
18163 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
18164 struct call_arg_loc_node
*ca_loc
)
18166 dw_die_ref stmt_die
= NULL
, die
;
18167 tree block
= ca_loc
->block
;
18170 && block
!= DECL_INITIAL (decl
)
18171 && TREE_CODE (block
) == BLOCK
)
18173 if (block_map
.length () > BLOCK_NUMBER (block
))
18174 stmt_die
= block_map
[BLOCK_NUMBER (block
)];
18177 block
= BLOCK_SUPERCONTEXT (block
);
18179 if (stmt_die
== NULL
)
18180 stmt_die
= subr_die
;
18181 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
18182 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
18183 if (ca_loc
->tail_call_p
)
18184 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
18185 if (ca_loc
->symbol_ref
)
18187 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
18189 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
18191 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
18196 /* Generate a DIE to represent a declared function (either file-scope or
18200 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
18202 tree origin
= decl_ultimate_origin (decl
);
18203 dw_die_ref subr_die
;
18205 dw_die_ref old_die
= lookup_decl_die (decl
);
18206 int declaration
= (current_function_decl
!= decl
18207 || class_or_namespace_scope_p (context_die
));
18209 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
18211 /* It is possible to have both DECL_ABSTRACT_P and DECLARATION be true if we
18212 started to generate the abstract instance of an inline, decided to output
18213 its containing class, and proceeded to emit the declaration of the inline
18214 from the member list for the class. If so, DECLARATION takes priority;
18215 we'll get back to the abstract instance when done with the class. */
18217 /* The class-scope declaration DIE must be the primary DIE. */
18218 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
18221 gcc_assert (!old_die
);
18224 /* Now that the C++ front end lazily declares artificial member fns, we
18225 might need to retrofit the declaration into its class. */
18226 if (!declaration
&& !origin
&& !old_die
18227 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
18228 && !class_or_namespace_scope_p (context_die
)
18229 && debug_info_level
> DINFO_LEVEL_TERSE
)
18230 old_die
= force_decl_die (decl
);
18232 if (origin
!= NULL
)
18234 gcc_assert (!declaration
|| local_scope_p (context_die
));
18236 /* Fixup die_parent for the abstract instance of a nested
18237 inline function. */
18238 if (old_die
&& old_die
->die_parent
== NULL
)
18239 add_child_die (context_die
, old_die
);
18241 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18242 add_abstract_origin_attribute (subr_die
, origin
);
18243 /* This is where the actual code for a cloned function is.
18244 Let's emit linkage name attribute for it. This helps
18245 debuggers to e.g, set breakpoints into
18246 constructors/destructors when the user asks "break
18248 add_linkage_name (subr_die
, decl
);
18252 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18253 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18255 if (!get_AT_flag (old_die
, DW_AT_declaration
)
18256 /* We can have a normal definition following an inline one in the
18257 case of redefinition of GNU C extern inlines.
18258 It seems reasonable to use AT_specification in this case. */
18259 && !get_AT (old_die
, DW_AT_inline
))
18261 /* Detect and ignore this case, where we are trying to output
18262 something we have already output. */
18266 /* If the definition comes from the same place as the declaration,
18267 maybe use the old DIE. We always want the DIE for this function
18268 that has the *_pc attributes to be under comp_unit_die so the
18269 debugger can find it. We also need to do this for abstract
18270 instances of inlines, since the spec requires the out-of-line copy
18271 to have the same parent. For local class methods, this doesn't
18272 apply; we just use the old DIE. */
18273 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
18274 && (DECL_ARTIFICIAL (decl
)
18275 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
18276 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
18277 == (unsigned) s
.line
))))
18279 subr_die
= old_die
;
18281 /* Clear out the declaration attribute and the formal parameters.
18282 Do not remove all children, because it is possible that this
18283 declaration die was forced using force_decl_die(). In such
18284 cases die that forced declaration die (e.g. TAG_imported_module)
18285 is one of the children that we do not want to remove. */
18286 remove_AT (subr_die
, DW_AT_declaration
);
18287 remove_AT (subr_die
, DW_AT_object_pointer
);
18288 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
18292 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18293 add_AT_specification (subr_die
, old_die
);
18294 add_pubname (decl
, subr_die
);
18295 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18296 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
18297 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18298 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
18300 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
18301 emit the real type on the definition die. */
18302 if (is_cxx() && debug_info_level
> DINFO_LEVEL_TERSE
)
18304 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
18305 if (die
== auto_die
|| die
== decltype_auto_die
)
18306 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18307 TYPE_UNQUALIFIED
, context_die
);
18313 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18315 if (TREE_PUBLIC (decl
))
18316 add_AT_flag (subr_die
, DW_AT_external
, 1);
18318 add_name_and_src_coords_attributes (subr_die
, decl
);
18319 add_pubname (decl
, subr_die
);
18320 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18322 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
18323 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18324 TYPE_UNQUALIFIED
, context_die
);
18327 add_pure_or_virtual_attribute (subr_die
, decl
);
18328 if (DECL_ARTIFICIAL (decl
))
18329 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18331 add_accessibility_attribute (subr_die
, decl
);
18336 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18338 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
18340 /* If this is an explicit function declaration then generate
18341 a DW_AT_explicit attribute. */
18342 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
18343 && (dwarf_version
>= 3 || !dwarf_strict
))
18344 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
18346 /* If this is a C++11 deleted special function member then generate
18347 a DW_AT_GNU_deleted attribute. */
18348 if (lang_hooks
.decls
.function_decl_deleted_p (decl
)
18349 && (! dwarf_strict
))
18350 add_AT_flag (subr_die
, DW_AT_GNU_deleted
, 1);
18352 /* The first time we see a member function, it is in the context of
18353 the class to which it belongs. We make sure of this by emitting
18354 the class first. The next time is the definition, which is
18355 handled above. The two may come from the same source text.
18357 Note that force_decl_die() forces function declaration die. It is
18358 later reused to represent definition. */
18359 equate_decl_number_to_die (decl
, subr_die
);
18362 else if (DECL_ABSTRACT_P (decl
))
18364 if (DECL_DECLARED_INLINE_P (decl
))
18366 if (cgraph_function_possibly_inlined_p (decl
))
18367 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
18369 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
18373 if (cgraph_function_possibly_inlined_p (decl
))
18374 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
18376 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
18379 if (DECL_DECLARED_INLINE_P (decl
)
18380 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
18381 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18383 equate_decl_number_to_die (decl
, subr_die
);
18385 else if (!DECL_EXTERNAL (decl
))
18387 HOST_WIDE_INT cfa_fb_offset
;
18388 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
18390 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18391 equate_decl_number_to_die (decl
, subr_die
);
18393 gcc_checking_assert (fun
);
18394 if (!flag_reorder_blocks_and_partition
)
18396 dw_fde_ref fde
= fun
->fde
;
18397 if (fde
->dw_fde_begin
)
18399 /* We have already generated the labels. */
18400 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18401 fde
->dw_fde_end
, false);
18405 /* Create start/end labels and add the range. */
18406 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
18407 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18408 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
18409 current_function_funcdef_no
);
18410 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
18411 current_function_funcdef_no
);
18412 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
18416 #if VMS_DEBUGGING_INFO
18417 /* HP OpenVMS Industry Standard 64: DWARF Extensions
18418 Section 2.3 Prologue and Epilogue Attributes:
18419 When a breakpoint is set on entry to a function, it is generally
18420 desirable for execution to be suspended, not on the very first
18421 instruction of the function, but rather at a point after the
18422 function's frame has been set up, after any language defined local
18423 declaration processing has been completed, and before execution of
18424 the first statement of the function begins. Debuggers generally
18425 cannot properly determine where this point is. Similarly for a
18426 breakpoint set on exit from a function. The prologue and epilogue
18427 attributes allow a compiler to communicate the location(s) to use. */
18430 if (fde
->dw_fde_vms_end_prologue
)
18431 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
18432 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
18434 if (fde
->dw_fde_vms_begin_epilogue
)
18435 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
18436 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
18443 /* Generate pubnames entries for the split function code ranges. */
18444 dw_fde_ref fde
= fun
->fde
;
18446 if (fde
->dw_fde_second_begin
)
18448 if (dwarf_version
>= 3 || !dwarf_strict
)
18450 /* We should use ranges for non-contiguous code section
18451 addresses. Use the actual code range for the initial
18452 section, since the HOT/COLD labels might precede an
18453 alignment offset. */
18454 bool range_list_added
= false;
18455 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
18456 fde
->dw_fde_end
, &range_list_added
,
18458 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
18459 fde
->dw_fde_second_end
,
18460 &range_list_added
, false);
18461 if (range_list_added
)
18466 /* There is no real support in DW2 for this .. so we make
18467 a work-around. First, emit the pub name for the segment
18468 containing the function label. Then make and emit a
18469 simplified subprogram DIE for the second segment with the
18470 name pre-fixed by __hot/cold_sect_of_. We use the same
18471 linkage name for the second die so that gdb will find both
18472 sections when given "b foo". */
18473 const char *name
= NULL
;
18474 tree decl_name
= DECL_NAME (decl
);
18475 dw_die_ref seg_die
;
18477 /* Do the 'primary' section. */
18478 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18479 fde
->dw_fde_end
, false);
18481 /* Build a minimal DIE for the secondary section. */
18482 seg_die
= new_die (DW_TAG_subprogram
,
18483 subr_die
->die_parent
, decl
);
18485 if (TREE_PUBLIC (decl
))
18486 add_AT_flag (seg_die
, DW_AT_external
, 1);
18488 if (decl_name
!= NULL
18489 && IDENTIFIER_POINTER (decl_name
) != NULL
)
18491 name
= dwarf2_name (decl
, 1);
18492 if (! DECL_ARTIFICIAL (decl
))
18493 add_src_coords_attributes (seg_die
, decl
);
18495 add_linkage_name (seg_die
, decl
);
18497 gcc_assert (name
!= NULL
);
18498 add_pure_or_virtual_attribute (seg_die
, decl
);
18499 if (DECL_ARTIFICIAL (decl
))
18500 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
18502 name
= concat ("__second_sect_of_", name
, NULL
);
18503 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
18504 fde
->dw_fde_second_end
, false);
18505 add_name_attribute (seg_die
, name
);
18506 if (want_pubnames ())
18507 add_pubname_string (name
, seg_die
);
18511 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
18515 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
18517 /* We define the "frame base" as the function's CFA. This is more
18518 convenient for several reasons: (1) It's stable across the prologue
18519 and epilogue, which makes it better than just a frame pointer,
18520 (2) With dwarf3, there exists a one-byte encoding that allows us
18521 to reference the .debug_frame data by proxy, but failing that,
18522 (3) We can at least reuse the code inspection and interpretation
18523 code that determines the CFA position at various points in the
18525 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
18527 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
18528 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
18532 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
18533 if (list
->dw_loc_next
)
18534 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
18536 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
18539 /* Compute a displacement from the "steady-state frame pointer" to
18540 the CFA. The former is what all stack slots and argument slots
18541 will reference in the rtl; the latter is what we've told the
18542 debugger about. We'll need to adjust all frame_base references
18543 by this displacement. */
18544 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
18546 if (fun
->static_chain_decl
)
18547 add_AT_location_description (subr_die
, DW_AT_static_link
,
18548 loc_list_from_tree (fun
->static_chain_decl
, 2));
18551 /* Generate child dies for template paramaters. */
18552 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18553 gen_generic_params_dies (decl
);
18555 /* Now output descriptions of the arguments for this function. This gets
18556 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
18557 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
18558 `...' at the end of the formal parameter list. In order to find out if
18559 there was a trailing ellipsis or not, we must instead look at the type
18560 associated with the FUNCTION_DECL. This will be a node of type
18561 FUNCTION_TYPE. If the chain of type nodes hanging off of this
18562 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
18563 an ellipsis at the end. */
18565 /* In the case where we are describing a mere function declaration, all we
18566 need to do here (and all we *can* do here) is to describe the *types* of
18567 its formal parameters. */
18568 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
18570 else if (declaration
)
18571 gen_formal_types_die (decl
, subr_die
);
18574 /* Generate DIEs to represent all known formal parameters. */
18575 tree parm
= DECL_ARGUMENTS (decl
);
18576 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
18577 tree generic_decl_parm
= generic_decl
18578 ? DECL_ARGUMENTS (generic_decl
)
18581 /* Now we want to walk the list of parameters of the function and
18582 emit their relevant DIEs.
18584 We consider the case of DECL being an instance of a generic function
18585 as well as it being a normal function.
18587 If DECL is an instance of a generic function we walk the
18588 parameters of the generic function declaration _and_ the parameters of
18589 DECL itself. This is useful because we want to emit specific DIEs for
18590 function parameter packs and those are declared as part of the
18591 generic function declaration. In that particular case,
18592 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
18593 That DIE has children DIEs representing the set of arguments
18594 of the pack. Note that the set of pack arguments can be empty.
18595 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
18598 Otherwise, we just consider the parameters of DECL. */
18599 while (generic_decl_parm
|| parm
)
18601 if (generic_decl_parm
18602 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
18603 gen_formal_parameter_pack_die (generic_decl_parm
,
18606 else if (parm
&& !POINTER_BOUNDS_P (parm
))
18608 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
18610 if (parm
== DECL_ARGUMENTS (decl
)
18611 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
18613 && (dwarf_version
>= 3 || !dwarf_strict
))
18614 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
18616 parm
= DECL_CHAIN (parm
);
18619 parm
= DECL_CHAIN (parm
);
18621 if (generic_decl_parm
)
18622 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
18625 /* Decide whether we need an unspecified_parameters DIE at the end.
18626 There are 2 more cases to do this for: 1) the ansi ... declaration -
18627 this is detectable when the end of the arg list is not a
18628 void_type_node 2) an unprototyped function declaration (not a
18629 definition). This just means that we have no info about the
18630 parameters at all. */
18631 if (prototype_p (TREE_TYPE (decl
)))
18633 /* This is the prototyped case, check for.... */
18634 if (stdarg_p (TREE_TYPE (decl
)))
18635 gen_unspecified_parameters_die (decl
, subr_die
);
18637 else if (DECL_INITIAL (decl
) == NULL_TREE
)
18638 gen_unspecified_parameters_die (decl
, subr_die
);
18641 /* Output Dwarf info for all of the stuff within the body of the function
18642 (if it has one - it may be just a declaration). */
18643 outer_scope
= DECL_INITIAL (decl
);
18645 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
18646 a function. This BLOCK actually represents the outermost binding contour
18647 for the function, i.e. the contour in which the function's formal
18648 parameters and labels get declared. Curiously, it appears that the front
18649 end doesn't actually put the PARM_DECL nodes for the current function onto
18650 the BLOCK_VARS list for this outer scope, but are strung off of the
18651 DECL_ARGUMENTS list for the function instead.
18653 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
18654 the LABEL_DECL nodes for the function however, and we output DWARF info
18655 for those in decls_for_scope. Just within the `outer_scope' there will be
18656 a BLOCK node representing the function's outermost pair of curly braces,
18657 and any blocks used for the base and member initializers of a C++
18658 constructor function. */
18659 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
18661 int call_site_note_count
= 0;
18662 int tail_call_site_note_count
= 0;
18664 /* Emit a DW_TAG_variable DIE for a named return value. */
18665 if (DECL_NAME (DECL_RESULT (decl
)))
18666 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
18668 decls_for_scope (outer_scope
, subr_die
, 0);
18670 if (call_arg_locations
&& !dwarf_strict
)
18672 struct call_arg_loc_node
*ca_loc
;
18673 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
18675 dw_die_ref die
= NULL
;
18676 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
18679 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
18680 arg
; arg
= next_arg
)
18682 dw_loc_descr_ref reg
, val
;
18683 machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
18684 dw_die_ref cdie
, tdie
= NULL
;
18686 next_arg
= XEXP (arg
, 1);
18687 if (REG_P (XEXP (XEXP (arg
, 0), 0))
18689 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
18690 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
18691 && REGNO (XEXP (XEXP (arg
, 0), 0))
18692 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
18693 next_arg
= XEXP (next_arg
, 1);
18694 if (mode
== VOIDmode
)
18696 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
18697 if (mode
== VOIDmode
)
18698 mode
= GET_MODE (XEXP (arg
, 0));
18700 if (mode
== VOIDmode
|| mode
== BLKmode
)
18702 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
18704 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18705 tloc
= XEXP (XEXP (arg
, 0), 1);
18708 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
18709 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
18711 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18712 tlocc
= XEXP (XEXP (arg
, 0), 1);
18716 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
18717 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
18718 VAR_INIT_STATUS_INITIALIZED
);
18719 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
18721 rtx mem
= XEXP (XEXP (arg
, 0), 0);
18722 reg
= mem_loc_descriptor (XEXP (mem
, 0),
18723 get_address_mode (mem
),
18725 VAR_INIT_STATUS_INITIALIZED
);
18727 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
18728 == DEBUG_PARAMETER_REF
)
18731 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
18732 tdie
= lookup_decl_die (tdecl
);
18739 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
18740 != DEBUG_PARAMETER_REF
)
18742 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
18744 VAR_INIT_STATUS_INITIALIZED
);
18748 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18749 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
18752 add_AT_loc (cdie
, DW_AT_location
, reg
);
18753 else if (tdie
!= NULL
)
18754 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
18755 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
18756 if (next_arg
!= XEXP (arg
, 1))
18758 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
18759 if (mode
== VOIDmode
)
18760 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
18761 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
18764 VAR_INIT_STATUS_INITIALIZED
);
18766 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
18770 && (ca_loc
->symbol_ref
|| tloc
))
18771 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18772 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
18774 dw_loc_descr_ref tval
= NULL
;
18776 if (tloc
!= NULL_RTX
)
18777 tval
= mem_loc_descriptor (tloc
,
18778 GET_MODE (tloc
) == VOIDmode
18779 ? Pmode
: GET_MODE (tloc
),
18781 VAR_INIT_STATUS_INITIALIZED
);
18783 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
18784 else if (tlocc
!= NULL_RTX
)
18786 tval
= mem_loc_descriptor (tlocc
,
18787 GET_MODE (tlocc
) == VOIDmode
18788 ? Pmode
: GET_MODE (tlocc
),
18790 VAR_INIT_STATUS_INITIALIZED
);
18792 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
18798 call_site_note_count
++;
18799 if (ca_loc
->tail_call_p
)
18800 tail_call_site_note_count
++;
18804 call_arg_locations
= NULL
;
18805 call_arg_loc_last
= NULL
;
18806 if (tail_call_site_count
>= 0
18807 && tail_call_site_count
== tail_call_site_note_count
18810 if (call_site_count
>= 0
18811 && call_site_count
== call_site_note_count
)
18812 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
18814 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
18816 call_site_count
= -1;
18817 tail_call_site_count
= -1;
18820 if (subr_die
!= old_die
)
18821 /* Add the calling convention attribute if requested. */
18822 add_calling_convention_attribute (subr_die
, decl
);
18825 /* Returns a hash value for X (which really is a die_struct). */
18828 block_die_hasher::hash (die_struct
*d
)
18830 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
18833 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18834 as decl_id and die_parent of die_struct Y. */
18837 block_die_hasher::equal (die_struct
*x
, die_struct
*y
)
18839 return x
->decl_id
== y
->decl_id
&& x
->die_parent
== y
->die_parent
;
18842 /* Generate a DIE to represent a declared data object.
18843 Either DECL or ORIGIN must be non-null. */
18846 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
18848 HOST_WIDE_INT off
= 0;
18850 tree decl_or_origin
= decl
? decl
: origin
;
18851 tree ultimate_origin
;
18852 dw_die_ref var_die
;
18853 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
18854 dw_die_ref origin_die
;
18855 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
18856 || class_or_namespace_scope_p (context_die
));
18857 bool specialization_p
= false;
18859 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
18860 if (decl
|| ultimate_origin
)
18861 origin
= ultimate_origin
;
18862 com_decl
= fortran_common (decl_or_origin
, &off
);
18864 /* Symbol in common gets emitted as a child of the common block, in the form
18865 of a data member. */
18868 dw_die_ref com_die
;
18869 dw_loc_list_ref loc
;
18870 die_node com_die_arg
;
18872 var_die
= lookup_decl_die (decl_or_origin
);
18875 if (get_AT (var_die
, DW_AT_location
) == NULL
)
18877 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
18882 /* Optimize the common case. */
18883 if (single_element_loc_list_p (loc
)
18884 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18885 && loc
->expr
->dw_loc_next
== NULL
18886 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
18889 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18890 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18891 = plus_constant (GET_MODE (x
), x
, off
);
18894 loc_list_plus_const (loc
, off
);
18896 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18897 remove_AT (var_die
, DW_AT_declaration
);
18903 if (common_block_die_table
== NULL
)
18904 common_block_die_table
= hash_table
<block_die_hasher
>::create_ggc (10);
18906 com_die_arg
.decl_id
= DECL_UID (com_decl
);
18907 com_die_arg
.die_parent
= context_die
;
18908 com_die
= common_block_die_table
->find (&com_die_arg
);
18909 loc
= loc_list_from_tree (com_decl
, 2);
18910 if (com_die
== NULL
)
18913 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
18916 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
18917 add_name_and_src_coords_attributes (com_die
, com_decl
);
18920 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18921 /* Avoid sharing the same loc descriptor between
18922 DW_TAG_common_block and DW_TAG_variable. */
18923 loc
= loc_list_from_tree (com_decl
, 2);
18925 else if (DECL_EXTERNAL (decl
))
18926 add_AT_flag (com_die
, DW_AT_declaration
, 1);
18927 if (want_pubnames ())
18928 add_pubname_string (cnam
, com_die
); /* ??? needed? */
18929 com_die
->decl_id
= DECL_UID (com_decl
);
18930 slot
= common_block_die_table
->find_slot (com_die
, INSERT
);
18933 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
18935 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18936 loc
= loc_list_from_tree (com_decl
, 2);
18937 remove_AT (com_die
, DW_AT_declaration
);
18939 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
18940 add_name_and_src_coords_attributes (var_die
, decl
);
18941 add_type_attribute (var_die
, TREE_TYPE (decl
), decl_quals (decl
),
18943 add_AT_flag (var_die
, DW_AT_external
, 1);
18948 /* Optimize the common case. */
18949 if (single_element_loc_list_p (loc
)
18950 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18951 && loc
->expr
->dw_loc_next
== NULL
18952 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
18954 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18955 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18956 = plus_constant (GET_MODE (x
), x
, off
);
18959 loc_list_plus_const (loc
, off
);
18961 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18963 else if (DECL_EXTERNAL (decl
))
18964 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18965 equate_decl_number_to_die (decl
, var_die
);
18969 /* If the compiler emitted a definition for the DECL declaration
18970 and if we already emitted a DIE for it, don't emit a second
18971 DIE for it again. Allow re-declarations of DECLs that are
18972 inside functions, though. */
18973 if (old_die
&& declaration
&& !local_scope_p (context_die
))
18976 /* For static data members, the declaration in the class is supposed
18977 to have DW_TAG_member tag; the specification should still be
18978 DW_TAG_variable referencing the DW_TAG_member DIE. */
18979 if (declaration
&& class_scope_p (context_die
))
18980 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
18982 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
18985 if (origin
!= NULL
)
18986 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
18988 /* Loop unrolling can create multiple blocks that refer to the same
18989 static variable, so we must test for the DW_AT_declaration flag.
18991 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18992 copy decls and set the DECL_ABSTRACT_P flag on them instead of
18995 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18997 ??? The declare_in_namespace support causes us to get two DIEs for one
18998 variable, both of which are declarations. We want to avoid considering
18999 one to be a specification, so we must test that this DIE is not a
19001 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
19002 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
19004 /* This is a definition of a C++ class level static. */
19005 add_AT_specification (var_die
, old_die
);
19006 specialization_p
= true;
19007 if (DECL_NAME (decl
))
19009 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
19010 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
19012 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
19013 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
19015 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
19016 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
19018 if (old_die
->die_tag
== DW_TAG_member
)
19019 add_linkage_name (var_die
, decl
);
19023 add_name_and_src_coords_attributes (var_die
, decl
);
19025 if ((origin
== NULL
&& !specialization_p
)
19027 && !DECL_ABSTRACT_P (decl_or_origin
)
19028 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
19029 decl_function_context
19030 (decl_or_origin
))))
19032 tree type
= TREE_TYPE (decl_or_origin
);
19034 if (decl_by_reference_p (decl_or_origin
))
19035 add_type_attribute (var_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
19038 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
),
19042 if (origin
== NULL
&& !specialization_p
)
19044 if (TREE_PUBLIC (decl
))
19045 add_AT_flag (var_die
, DW_AT_external
, 1);
19047 if (DECL_ARTIFICIAL (decl
))
19048 add_AT_flag (var_die
, DW_AT_artificial
, 1);
19050 add_accessibility_attribute (var_die
, decl
);
19054 add_AT_flag (var_die
, DW_AT_declaration
, 1);
19056 if (decl
&& (DECL_ABSTRACT_P (decl
) || declaration
|| old_die
== NULL
))
19057 equate_decl_number_to_die (decl
, var_die
);
19060 && (! DECL_ABSTRACT_P (decl_or_origin
)
19061 /* Local static vars are shared between all clones/inlines,
19062 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19064 || (TREE_CODE (decl_or_origin
) == VAR_DECL
19065 && TREE_STATIC (decl_or_origin
)
19066 && DECL_RTL_SET_P (decl_or_origin
)))
19067 /* When abstract origin already has DW_AT_location attribute, no need
19068 to add it again. */
19069 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
19071 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
19072 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
19073 defer_location (decl_or_origin
, var_die
);
19075 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
19076 decl
== NULL
, DW_AT_location
);
19077 add_pubname (decl_or_origin
, var_die
);
19080 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
19083 /* Generate a DIE to represent a named constant. */
19086 gen_const_die (tree decl
, dw_die_ref context_die
)
19088 dw_die_ref const_die
;
19089 tree type
= TREE_TYPE (decl
);
19091 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
19092 add_name_and_src_coords_attributes (const_die
, decl
);
19093 add_type_attribute (const_die
, type
, TYPE_QUAL_CONST
, context_die
);
19094 if (TREE_PUBLIC (decl
))
19095 add_AT_flag (const_die
, DW_AT_external
, 1);
19096 if (DECL_ARTIFICIAL (decl
))
19097 add_AT_flag (const_die
, DW_AT_artificial
, 1);
19098 tree_add_const_value_attribute_for_decl (const_die
, decl
);
19101 /* Generate a DIE to represent a label identifier. */
19104 gen_label_die (tree decl
, dw_die_ref context_die
)
19106 tree origin
= decl_ultimate_origin (decl
);
19107 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
19109 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19111 if (origin
!= NULL
)
19112 add_abstract_origin_attribute (lbl_die
, origin
);
19114 add_name_and_src_coords_attributes (lbl_die
, decl
);
19116 if (DECL_ABSTRACT_P (decl
))
19117 equate_decl_number_to_die (decl
, lbl_die
);
19120 insn
= DECL_RTL_IF_SET (decl
);
19122 /* Deleted labels are programmer specified labels which have been
19123 eliminated because of various optimizations. We still emit them
19124 here so that it is possible to put breakpoints on them. */
19128 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
19130 /* When optimization is enabled (via -O) some parts of the compiler
19131 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19132 represent source-level labels which were explicitly declared by
19133 the user. This really shouldn't be happening though, so catch
19134 it if it ever does happen. */
19135 gcc_assert (!as_a
<rtx_insn
*> (insn
)->deleted ());
19137 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
19138 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19142 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
19143 && CODE_LABEL_NUMBER (insn
) != -1)
19145 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
19146 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19151 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19152 attributes to the DIE for a block STMT, to describe where the inlined
19153 function was called from. This is similar to add_src_coords_attributes. */
19156 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
19158 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
19160 if (dwarf_version
>= 3 || !dwarf_strict
)
19162 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
19163 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
19168 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19169 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19172 add_high_low_attributes (tree stmt
, dw_die_ref die
)
19174 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19176 if (BLOCK_FRAGMENT_CHAIN (stmt
)
19177 && (dwarf_version
>= 3 || !dwarf_strict
))
19179 tree chain
, superblock
= NULL_TREE
;
19181 dw_attr_ref attr
= NULL
;
19183 if (inlined_function_outer_scope_p (stmt
))
19185 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19186 BLOCK_NUMBER (stmt
));
19187 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
19190 /* Optimize duplicate .debug_ranges lists or even tails of
19191 lists. If this BLOCK has same ranges as its supercontext,
19192 lookup DW_AT_ranges attribute in the supercontext (and
19193 recursively so), verify that the ranges_table contains the
19194 right values and use it instead of adding a new .debug_range. */
19195 for (chain
= stmt
, pdie
= die
;
19196 BLOCK_SAME_RANGE (chain
);
19197 chain
= BLOCK_SUPERCONTEXT (chain
))
19199 dw_attr_ref new_attr
;
19201 pdie
= pdie
->die_parent
;
19204 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
19206 new_attr
= get_AT (pdie
, DW_AT_ranges
);
19207 if (new_attr
== NULL
19208 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
19211 superblock
= BLOCK_SUPERCONTEXT (chain
);
19214 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
19215 / 2 / DWARF2_ADDR_SIZE
].num
19216 == BLOCK_NUMBER (superblock
))
19217 && BLOCK_FRAGMENT_CHAIN (superblock
))
19219 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
19220 / 2 / DWARF2_ADDR_SIZE
;
19221 unsigned long supercnt
= 0, thiscnt
= 0;
19222 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
19223 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
19226 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
19227 == BLOCK_NUMBER (chain
));
19229 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
19230 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19231 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
19233 gcc_assert (supercnt
>= thiscnt
);
19234 add_AT_range_list (die
, DW_AT_ranges
,
19235 ((off
+ supercnt
- thiscnt
)
19236 * 2 * DWARF2_ADDR_SIZE
),
19241 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
19243 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19246 add_ranges (chain
);
19247 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
19254 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
19255 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19256 BLOCK_NUMBER (stmt
));
19257 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
19258 BLOCK_NUMBER (stmt
));
19259 add_AT_low_high_pc (die
, label
, label_high
, false);
19263 /* Generate a DIE for a lexical block. */
19266 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19268 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
19270 if (call_arg_locations
)
19272 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
19273 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
19274 block_map
[BLOCK_NUMBER (stmt
)] = stmt_die
;
19277 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
19278 add_high_low_attributes (stmt
, stmt_die
);
19280 decls_for_scope (stmt
, stmt_die
, depth
);
19283 /* Generate a DIE for an inlined subprogram. */
19286 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
19290 /* The instance of function that is effectively being inlined shall not
19292 gcc_assert (! BLOCK_ABSTRACT (stmt
));
19294 decl
= block_ultimate_origin (stmt
);
19296 /* Emit info for the abstract instance first, if we haven't yet. We
19297 must emit this even if the block is abstract, otherwise when we
19298 emit the block below (or elsewhere), we may end up trying to emit
19299 a die whose origin die hasn't been emitted, and crashing. */
19300 dwarf2out_abstract_function (decl
);
19302 if (! BLOCK_ABSTRACT (stmt
))
19304 dw_die_ref subr_die
19305 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
19307 if (call_arg_locations
)
19309 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
19310 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
19311 block_map
[BLOCK_NUMBER (stmt
)] = subr_die
;
19313 add_abstract_origin_attribute (subr_die
, decl
);
19314 if (TREE_ASM_WRITTEN (stmt
))
19315 add_high_low_attributes (stmt
, subr_die
);
19316 add_call_src_coords_attributes (stmt
, subr_die
);
19318 decls_for_scope (stmt
, subr_die
, depth
);
19322 /* Generate a DIE for a field in a record, or structure. */
19325 gen_field_die (tree decl
, dw_die_ref context_die
)
19327 dw_die_ref decl_die
;
19329 if (TREE_TYPE (decl
) == error_mark_node
)
19332 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
19333 add_name_and_src_coords_attributes (decl_die
, decl
);
19334 add_type_attribute (decl_die
, member_declared_type (decl
),
19335 decl_quals (decl
), context_die
);
19337 if (DECL_BIT_FIELD_TYPE (decl
))
19339 add_byte_size_attribute (decl_die
, decl
);
19340 add_bit_size_attribute (decl_die
, decl
);
19341 add_bit_offset_attribute (decl_die
, decl
);
19344 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
19345 add_data_member_location_attribute (decl_die
, decl
);
19347 if (DECL_ARTIFICIAL (decl
))
19348 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19350 add_accessibility_attribute (decl_die
, decl
);
19352 /* Equate decl number to die, so that we can look up this decl later on. */
19353 equate_decl_number_to_die (decl
, decl_die
);
19357 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19358 Use modified_type_die instead.
19359 We keep this code here just in case these types of DIEs may be needed to
19360 represent certain things in other languages (e.g. Pascal) someday. */
19363 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
19366 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
19368 equate_type_number_to_die (type
, ptr_die
);
19369 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
19371 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19374 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19375 Use modified_type_die instead.
19376 We keep this code here just in case these types of DIEs may be needed to
19377 represent certain things in other languages (e.g. Pascal) someday. */
19380 gen_reference_type_die (tree type
, dw_die_ref context_die
)
19382 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
19384 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
19385 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
19387 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
19389 equate_type_number_to_die (type
, ref_die
);
19390 add_type_attribute (ref_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
19392 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19396 /* Generate a DIE for a pointer to a member type. */
19399 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
19402 = new_die (DW_TAG_ptr_to_member_type
,
19403 scope_die_for (type
, context_die
), type
);
19405 equate_type_number_to_die (type
, ptr_die
);
19406 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
19407 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
19408 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
19412 typedef const char *dchar_p
; /* For DEF_VEC_P. */
19414 static char *producer_string
;
19416 /* Return a heap allocated producer string including command line options
19417 if -grecord-gcc-switches. */
19420 gen_producer_string (void)
19423 auto_vec
<dchar_p
> switches
;
19424 const char *language_string
= lang_hooks
.name
;
19425 char *producer
, *tail
;
19427 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
19428 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
19430 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
19431 switch (save_decoded_options
[j
].opt_index
)
19438 case OPT_auxbase_strip
:
19447 case OPT_SPECIAL_unknown
:
19448 case OPT_SPECIAL_ignore
:
19449 case OPT_SPECIAL_program_name
:
19450 case OPT_SPECIAL_input_file
:
19451 case OPT_grecord_gcc_switches
:
19452 case OPT_gno_record_gcc_switches
:
19453 case OPT__output_pch_
:
19454 case OPT_fdiagnostics_show_location_
:
19455 case OPT_fdiagnostics_show_option
:
19456 case OPT_fdiagnostics_show_caret
:
19457 case OPT_fdiagnostics_color_
:
19458 case OPT_fverbose_asm
:
19460 case OPT__sysroot_
:
19462 case OPT_nostdinc__
:
19463 /* Ignore these. */
19466 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
19467 & CL_NO_DWARF_RECORD
)
19469 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
19471 switch (save_decoded_options
[j
].canonical_option
[0][1])
19478 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
19485 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
19486 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
19490 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
19492 sprintf (tail
, "%s %s", language_string
, version_string
);
19495 FOR_EACH_VEC_ELT (switches
, j
, p
)
19499 memcpy (tail
+ 1, p
, len
);
19507 /* Generate the DIE for the compilation unit. */
19510 gen_compile_unit_die (const char *filename
)
19513 const char *language_string
= lang_hooks
.name
;
19516 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
19520 add_name_attribute (die
, filename
);
19521 /* Don't add cwd for <built-in>. */
19522 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
19523 add_comp_dir_attribute (die
);
19526 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
19528 /* If our producer is LTO try to figure out a common language to use
19529 from the global list of translation units. */
19530 if (strcmp (language_string
, "GNU GIMPLE") == 0)
19534 const char *common_lang
= NULL
;
19536 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
19538 if (!TRANSLATION_UNIT_LANGUAGE (t
))
19541 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
19542 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
19544 else if (strncmp (common_lang
, "GNU C", 5) == 0
19545 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
19546 /* Mixing C and C++ is ok, use C++ in that case. */
19547 common_lang
= "GNU C++";
19550 /* Fall back to C. */
19551 common_lang
= NULL
;
19557 language_string
= common_lang
;
19560 language
= DW_LANG_C89
;
19561 if (strcmp (language_string
, "GNU C++") == 0)
19562 language
= DW_LANG_C_plus_plus
;
19563 else if (strcmp (language_string
, "GNU F77") == 0)
19564 language
= DW_LANG_Fortran77
;
19565 else if (strcmp (language_string
, "GNU Pascal") == 0)
19566 language
= DW_LANG_Pascal83
;
19567 else if (dwarf_version
>= 3 || !dwarf_strict
)
19569 if (strcmp (language_string
, "GNU Ada") == 0)
19570 language
= DW_LANG_Ada95
;
19571 else if (strcmp (language_string
, "GNU Fortran") == 0)
19572 language
= DW_LANG_Fortran95
;
19573 else if (strcmp (language_string
, "GNU Java") == 0)
19574 language
= DW_LANG_Java
;
19575 else if (strcmp (language_string
, "GNU Objective-C") == 0)
19576 language
= DW_LANG_ObjC
;
19577 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
19578 language
= DW_LANG_ObjC_plus_plus
;
19579 else if (dwarf_version
>= 5 || !dwarf_strict
)
19581 if (strcmp (language_string
, "GNU Go") == 0)
19582 language
= DW_LANG_Go
;
19585 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
19586 else if (strcmp (language_string
, "GNU Fortran") == 0)
19587 language
= DW_LANG_Fortran90
;
19589 add_AT_unsigned (die
, DW_AT_language
, language
);
19593 case DW_LANG_Fortran77
:
19594 case DW_LANG_Fortran90
:
19595 case DW_LANG_Fortran95
:
19596 /* Fortran has case insensitive identifiers and the front-end
19597 lowercases everything. */
19598 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
19601 /* The default DW_ID_case_sensitive doesn't need to be specified. */
19607 /* Generate the DIE for a base class. */
19610 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
19612 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
19614 add_type_attribute (die
, BINFO_TYPE (binfo
), TYPE_UNQUALIFIED
, context_die
);
19615 add_data_member_location_attribute (die
, binfo
);
19617 if (BINFO_VIRTUAL_P (binfo
))
19618 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
19620 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19621 children, otherwise the default is DW_ACCESS_public. In DWARF2
19622 the default has always been DW_ACCESS_private. */
19623 if (access
== access_public_node
)
19625 if (dwarf_version
== 2
19626 || context_die
->die_tag
== DW_TAG_class_type
)
19627 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
19629 else if (access
== access_protected_node
)
19630 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19631 else if (dwarf_version
> 2
19632 && context_die
->die_tag
!= DW_TAG_class_type
)
19633 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
19636 /* Generate a DIE for a class member. */
19639 gen_member_die (tree type
, dw_die_ref context_die
)
19642 tree binfo
= TYPE_BINFO (type
);
19645 /* If this is not an incomplete type, output descriptions of each of its
19646 members. Note that as we output the DIEs necessary to represent the
19647 members of this record or union type, we will also be trying to output
19648 DIEs to represent the *types* of those members. However the `type'
19649 function (above) will specifically avoid generating type DIEs for member
19650 types *within* the list of member DIEs for this (containing) type except
19651 for those types (of members) which are explicitly marked as also being
19652 members of this (containing) type themselves. The g++ front- end can
19653 force any given type to be treated as a member of some other (containing)
19654 type by setting the TYPE_CONTEXT of the given (member) type to point to
19655 the TREE node representing the appropriate (containing) type. */
19657 /* First output info about the base classes. */
19660 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
19664 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
19665 gen_inheritance_die (base
,
19666 (accesses
? (*accesses
)[i
] : access_public_node
),
19670 /* Now output info about the data members and type members. */
19671 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
19673 /* If we thought we were generating minimal debug info for TYPE
19674 and then changed our minds, some of the member declarations
19675 may have already been defined. Don't define them again, but
19676 do put them in the right order. */
19678 child
= lookup_decl_die (member
);
19680 splice_child_die (context_die
, child
);
19682 gen_decl_die (member
, NULL
, context_die
);
19685 /* Now output info about the function members (if any). */
19686 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
19688 /* Don't include clones in the member list. */
19689 if (DECL_ABSTRACT_ORIGIN (member
))
19692 child
= lookup_decl_die (member
);
19694 splice_child_die (context_die
, child
);
19696 gen_decl_die (member
, NULL
, context_die
);
19700 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19701 is set, we pretend that the type was never defined, so we only get the
19702 member DIEs needed by later specification DIEs. */
19705 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19706 enum debug_info_usage usage
)
19708 dw_die_ref type_die
= lookup_type_die (type
);
19709 dw_die_ref scope_die
= 0;
19711 int complete
= (TYPE_SIZE (type
)
19712 && (! TYPE_STUB_DECL (type
)
19713 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19714 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19715 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19717 if (type_die
&& ! complete
)
19720 if (TYPE_CONTEXT (type
) != NULL_TREE
19721 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19722 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19725 scope_die
= scope_die_for (type
, context_die
);
19727 /* Generate child dies for template paramaters. */
19728 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19729 schedule_generic_params_dies_gen (type
);
19731 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
19732 /* First occurrence of type or toplevel definition of nested class. */
19734 dw_die_ref old_die
= type_die
;
19736 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19737 ? record_type_tag (type
) : DW_TAG_union_type
,
19739 equate_type_number_to_die (type
, type_die
);
19741 add_AT_specification (type_die
, old_die
);
19743 add_name_attribute (type_die
, type_tag (type
));
19746 remove_AT (type_die
, DW_AT_declaration
);
19748 /* If this type has been completed, then give it a byte_size attribute and
19749 then give a list of members. */
19750 if (complete
&& !ns_decl
)
19752 /* Prevent infinite recursion in cases where the type of some member of
19753 this type is expressed in terms of this type itself. */
19754 TREE_ASM_WRITTEN (type
) = 1;
19755 add_byte_size_attribute (type_die
, type
);
19756 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19758 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19759 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19762 /* If the first reference to this type was as the return type of an
19763 inline function, then it may not have a parent. Fix this now. */
19764 if (type_die
->die_parent
== NULL
)
19765 add_child_die (scope_die
, type_die
);
19767 push_decl_scope (type
);
19768 gen_member_die (type
, type_die
);
19771 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19772 if (TYPE_ARTIFICIAL (type
))
19773 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19775 /* GNU extension: Record what type our vtable lives in. */
19776 if (TYPE_VFIELD (type
))
19778 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19780 gen_type_die (vtype
, context_die
);
19781 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19782 lookup_type_die (vtype
));
19787 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19789 /* We don't need to do this for function-local types. */
19790 if (TYPE_STUB_DECL (type
)
19791 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19792 vec_safe_push (incomplete_types
, type
);
19795 if (get_AT (type_die
, DW_AT_name
))
19796 add_pubtype (type
, type_die
);
19799 /* Generate a DIE for a subroutine _type_. */
19802 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19804 tree return_type
= TREE_TYPE (type
);
19805 dw_die_ref subr_die
19806 = new_die (DW_TAG_subroutine_type
,
19807 scope_die_for (type
, context_die
), type
);
19809 equate_type_number_to_die (type
, subr_die
);
19810 add_prototyped_attribute (subr_die
, type
);
19811 add_type_attribute (subr_die
, return_type
, TYPE_UNQUALIFIED
, context_die
);
19812 gen_formal_types_die (type
, subr_die
);
19814 if (get_AT (subr_die
, DW_AT_name
))
19815 add_pubtype (type
, subr_die
);
19818 /* Generate a DIE for a type definition. */
19821 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19823 dw_die_ref type_die
;
19826 if (TREE_ASM_WRITTEN (decl
))
19829 TREE_ASM_WRITTEN (decl
) = 1;
19830 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19831 origin
= decl_ultimate_origin (decl
);
19832 if (origin
!= NULL
)
19833 add_abstract_origin_attribute (type_die
, origin
);
19838 add_name_and_src_coords_attributes (type_die
, decl
);
19839 if (DECL_ORIGINAL_TYPE (decl
))
19841 type
= DECL_ORIGINAL_TYPE (decl
);
19843 gcc_assert (type
!= TREE_TYPE (decl
));
19844 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19848 type
= TREE_TYPE (decl
);
19850 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19852 /* Here, we are in the case of decl being a typedef naming
19853 an anonymous type, e.g:
19854 typedef struct {...} foo;
19855 In that case TREE_TYPE (decl) is not a typedef variant
19856 type and TYPE_NAME of the anonymous type is set to the
19857 TYPE_DECL of the typedef. This construct is emitted by
19860 TYPE is the anonymous struct named by the typedef
19861 DECL. As we need the DW_AT_type attribute of the
19862 DW_TAG_typedef to point to the DIE of TYPE, let's
19863 generate that DIE right away. add_type_attribute
19864 called below will then pick (via lookup_type_die) that
19865 anonymous struct DIE. */
19866 if (!TREE_ASM_WRITTEN (type
))
19867 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
19869 /* This is a GNU Extension. We are adding a
19870 DW_AT_linkage_name attribute to the DIE of the
19871 anonymous struct TYPE. The value of that attribute
19872 is the name of the typedef decl naming the anonymous
19873 struct. This greatly eases the work of consumers of
19874 this debug info. */
19875 add_linkage_attr (lookup_type_die (type
), decl
);
19879 add_type_attribute (type_die
, type
, decl_quals (decl
), context_die
);
19881 if (is_naming_typedef_decl (decl
))
19882 /* We want that all subsequent calls to lookup_type_die with
19883 TYPE in argument yield the DW_TAG_typedef we have just
19885 equate_type_number_to_die (type
, type_die
);
19887 add_accessibility_attribute (type_die
, decl
);
19890 if (DECL_ABSTRACT_P (decl
))
19891 equate_decl_number_to_die (decl
, type_die
);
19893 if (get_AT (type_die
, DW_AT_name
))
19894 add_pubtype (decl
, type_die
);
19897 /* Generate a DIE for a struct, class, enum or union type. */
19900 gen_tagged_type_die (tree type
,
19901 dw_die_ref context_die
,
19902 enum debug_info_usage usage
)
19906 if (type
== NULL_TREE
19907 || !is_tagged_type (type
))
19910 /* If this is a nested type whose containing class hasn't been written
19911 out yet, writing it out will cover this one, too. This does not apply
19912 to instantiations of member class templates; they need to be added to
19913 the containing class as they are generated. FIXME: This hurts the
19914 idea of combining type decls from multiple TUs, since we can't predict
19915 what set of template instantiations we'll get. */
19916 if (TYPE_CONTEXT (type
)
19917 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19918 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
19920 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
19922 if (TREE_ASM_WRITTEN (type
))
19925 /* If that failed, attach ourselves to the stub. */
19926 push_decl_scope (TYPE_CONTEXT (type
));
19927 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
19930 else if (TYPE_CONTEXT (type
) != NULL_TREE
19931 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
19933 /* If this type is local to a function that hasn't been written
19934 out yet, use a NULL context for now; it will be fixed up in
19935 decls_for_scope. */
19936 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
19937 /* A declaration DIE doesn't count; nested types need to go in the
19939 if (context_die
&& is_declaration_die (context_die
))
19940 context_die
= NULL
;
19945 context_die
= declare_in_namespace (type
, context_die
);
19949 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
19951 /* This might have been written out by the call to
19952 declare_in_namespace. */
19953 if (!TREE_ASM_WRITTEN (type
))
19954 gen_enumeration_type_die (type
, context_die
);
19957 gen_struct_or_union_type_die (type
, context_die
, usage
);
19962 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19963 it up if it is ever completed. gen_*_type_die will set it for us
19964 when appropriate. */
19967 /* Generate a type description DIE. */
19970 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
19971 enum debug_info_usage usage
)
19973 struct array_descr_info info
;
19975 if (type
== NULL_TREE
|| type
== error_mark_node
)
19978 if (TYPE_NAME (type
) != NULL_TREE
19979 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19980 && is_redundant_typedef (TYPE_NAME (type
))
19981 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
19982 /* The DECL of this type is a typedef we don't want to emit debug
19983 info for but we want debug info for its underlying typedef.
19984 This can happen for e.g, the injected-class-name of a C++
19986 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
19988 /* If TYPE is a typedef type variant, let's generate debug info
19989 for the parent typedef which TYPE is a type of. */
19990 if (typedef_variant_p (type
))
19992 if (TREE_ASM_WRITTEN (type
))
19995 /* Prevent broken recursion; we can't hand off to the same type. */
19996 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
19998 /* Give typedefs the right scope. */
19999 context_die
= scope_die_for (type
, context_die
);
20001 TREE_ASM_WRITTEN (type
) = 1;
20003 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
20007 /* If type is an anonymous tagged type named by a typedef, let's
20008 generate debug info for the typedef. */
20009 if (is_naming_typedef_decl (TYPE_NAME (type
)))
20011 /* Use the DIE of the containing namespace as the parent DIE of
20012 the type description DIE we want to generate. */
20013 if (DECL_CONTEXT (TYPE_NAME (type
))
20014 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
20015 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
20017 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
20021 /* If this is an array type with hidden descriptor, handle it first. */
20022 if (!TREE_ASM_WRITTEN (type
)
20023 && lang_hooks
.types
.get_array_descr_info
20024 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
20025 && (dwarf_version
>= 3 || !dwarf_strict
))
20027 gen_descr_array_type_die (type
, &info
, context_die
);
20028 TREE_ASM_WRITTEN (type
) = 1;
20032 /* We are going to output a DIE to represent the unqualified version
20033 of this type (i.e. without any const or volatile qualifiers) so
20034 get the main variant (i.e. the unqualified version) of this type
20035 now. (Vectors are special because the debugging info is in the
20036 cloned type itself). */
20037 if (TREE_CODE (type
) != VECTOR_TYPE
)
20038 type
= type_main_variant (type
);
20040 if (TREE_ASM_WRITTEN (type
))
20043 switch (TREE_CODE (type
))
20049 case REFERENCE_TYPE
:
20050 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
20051 ensures that the gen_type_die recursion will terminate even if the
20052 type is recursive. Recursive types are possible in Ada. */
20053 /* ??? We could perhaps do this for all types before the switch
20055 TREE_ASM_WRITTEN (type
) = 1;
20057 /* For these types, all that is required is that we output a DIE (or a
20058 set of DIEs) to represent the "basis" type. */
20059 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20060 DINFO_USAGE_IND_USE
);
20064 /* This code is used for C++ pointer-to-data-member types.
20065 Output a description of the relevant class type. */
20066 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
20067 DINFO_USAGE_IND_USE
);
20069 /* Output a description of the type of the object pointed to. */
20070 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20071 DINFO_USAGE_IND_USE
);
20073 /* Now output a DIE to represent this pointer-to-data-member type
20075 gen_ptr_to_mbr_type_die (type
, context_die
);
20078 case FUNCTION_TYPE
:
20079 /* Force out return type (in case it wasn't forced out already). */
20080 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20081 DINFO_USAGE_DIR_USE
);
20082 gen_subroutine_type_die (type
, context_die
);
20086 /* Force out return type (in case it wasn't forced out already). */
20087 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20088 DINFO_USAGE_DIR_USE
);
20089 gen_subroutine_type_die (type
, context_die
);
20093 gen_array_type_die (type
, context_die
);
20097 gen_array_type_die (type
, context_die
);
20100 case ENUMERAL_TYPE
:
20103 case QUAL_UNION_TYPE
:
20104 gen_tagged_type_die (type
, context_die
, usage
);
20110 case FIXED_POINT_TYPE
:
20113 case POINTER_BOUNDS_TYPE
:
20114 /* No DIEs needed for fundamental types. */
20119 /* Just use DW_TAG_unspecified_type. */
20121 dw_die_ref type_die
= lookup_type_die (type
);
20122 if (type_die
== NULL
)
20124 tree name
= TYPE_IDENTIFIER (type
);
20125 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
20127 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
20128 equate_type_number_to_die (type
, type_die
);
20134 if (is_cxx_auto (type
))
20136 tree name
= TYPE_IDENTIFIER (type
);
20137 dw_die_ref
*die
= (name
== get_identifier ("auto")
20138 ? &auto_die
: &decltype_auto_die
);
20141 *die
= new_die (DW_TAG_unspecified_type
,
20142 comp_unit_die (), NULL_TREE
);
20143 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
20145 equate_type_number_to_die (type
, *die
);
20148 gcc_unreachable ();
20151 TREE_ASM_WRITTEN (type
) = 1;
20155 gen_type_die (tree type
, dw_die_ref context_die
)
20157 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
20160 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20161 things which are local to the given block. */
20164 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
20166 int must_output_die
= 0;
20169 /* Ignore blocks that are NULL. */
20170 if (stmt
== NULL_TREE
)
20173 inlined_func
= inlined_function_outer_scope_p (stmt
);
20175 /* If the block is one fragment of a non-contiguous block, do not
20176 process the variables, since they will have been done by the
20177 origin block. Do process subblocks. */
20178 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
20182 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
20183 gen_block_die (sub
, context_die
, depth
+ 1);
20188 /* Determine if we need to output any Dwarf DIEs at all to represent this
20191 /* The outer scopes for inlinings *must* always be represented. We
20192 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20193 must_output_die
= 1;
20196 /* Determine if this block directly contains any "significant"
20197 local declarations which we will need to output DIEs for. */
20198 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20199 /* We are not in terse mode so *any* local declaration counts
20200 as being a "significant" one. */
20201 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
20202 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
20203 && (TREE_USED (stmt
)
20204 || TREE_ASM_WRITTEN (stmt
)
20205 || BLOCK_ABSTRACT (stmt
)));
20206 else if ((TREE_USED (stmt
)
20207 || TREE_ASM_WRITTEN (stmt
)
20208 || BLOCK_ABSTRACT (stmt
))
20209 && !dwarf2out_ignore_block (stmt
))
20210 must_output_die
= 1;
20213 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20214 DIE for any block which contains no significant local declarations at
20215 all. Rather, in such cases we just call `decls_for_scope' so that any
20216 needed Dwarf info for any sub-blocks will get properly generated. Note
20217 that in terse mode, our definition of what constitutes a "significant"
20218 local declaration gets restricted to include only inlined function
20219 instances and local (nested) function definitions. */
20220 if (must_output_die
)
20224 /* If STMT block is abstract, that means we have been called
20225 indirectly from dwarf2out_abstract_function.
20226 That function rightfully marks the descendent blocks (of
20227 the abstract function it is dealing with) as being abstract,
20228 precisely to prevent us from emitting any
20229 DW_TAG_inlined_subroutine DIE as a descendent
20230 of an abstract function instance. So in that case, we should
20231 not call gen_inlined_subroutine_die.
20233 Later though, when cgraph asks dwarf2out to emit info
20234 for the concrete instance of the function decl into which
20235 the concrete instance of STMT got inlined, the later will lead
20236 to the generation of a DW_TAG_inlined_subroutine DIE. */
20237 if (! BLOCK_ABSTRACT (stmt
))
20238 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
20241 gen_lexical_block_die (stmt
, context_die
, depth
);
20244 decls_for_scope (stmt
, context_die
, depth
);
20247 /* Process variable DECL (or variable with origin ORIGIN) within
20248 block STMT and add it to CONTEXT_DIE. */
20250 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
20253 tree decl_or_origin
= decl
? decl
: origin
;
20255 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
20256 die
= lookup_decl_die (decl_or_origin
);
20257 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
20258 && TYPE_DECL_IS_STUB (decl_or_origin
))
20259 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
20263 if (die
!= NULL
&& die
->die_parent
== NULL
)
20264 add_child_die (context_die
, die
);
20265 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
20266 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
20267 stmt
, context_die
);
20269 gen_decl_die (decl
, origin
, context_die
);
20272 /* Generate all of the decls declared within a given scope and (recursively)
20273 all of its sub-blocks. */
20276 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
20282 /* Ignore NULL blocks. */
20283 if (stmt
== NULL_TREE
)
20286 /* Output the DIEs to represent all of the data objects and typedefs
20287 declared directly within this block but not within any nested
20288 sub-blocks. Also, nested function and tag DIEs have been
20289 generated with a parent of NULL; fix that up now. We don't
20290 have to do this if we're at -g1. */
20291 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20293 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
20294 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
20295 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
20296 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
20300 /* Even if we're at -g1, we need to process the subblocks in order to get
20301 inlined call information. */
20303 /* Output the DIEs to represent all sub-blocks (and the items declared
20304 therein) of this block. */
20305 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
20307 subblocks
= BLOCK_CHAIN (subblocks
))
20308 gen_block_die (subblocks
, context_die
, depth
+ 1);
20311 /* Is this a typedef we can avoid emitting? */
20314 is_redundant_typedef (const_tree decl
)
20316 if (TYPE_DECL_IS_STUB (decl
))
20319 if (DECL_ARTIFICIAL (decl
)
20320 && DECL_CONTEXT (decl
)
20321 && is_tagged_type (DECL_CONTEXT (decl
))
20322 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
20323 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
20324 /* Also ignore the artificial member typedef for the class name. */
20330 /* Return TRUE if TYPE is a typedef that names a type for linkage
20331 purposes. This kind of typedefs is produced by the C++ FE for
20334 typedef struct {...} foo;
20336 In that case, there is no typedef variant type produced for foo.
20337 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20341 is_naming_typedef_decl (const_tree decl
)
20343 if (decl
== NULL_TREE
20344 || TREE_CODE (decl
) != TYPE_DECL
20345 || !is_tagged_type (TREE_TYPE (decl
))
20346 || DECL_IS_BUILTIN (decl
)
20347 || is_redundant_typedef (decl
)
20348 /* It looks like Ada produces TYPE_DECLs that are very similar
20349 to C++ naming typedefs but that have different
20350 semantics. Let's be specific to c++ for now. */
20354 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
20355 && TYPE_NAME (TREE_TYPE (decl
)) == decl
20356 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
20357 != TYPE_NAME (TREE_TYPE (decl
))));
20360 /* Returns the DIE for a context. */
20362 static inline dw_die_ref
20363 get_context_die (tree context
)
20367 /* Find die that represents this context. */
20368 if (TYPE_P (context
))
20370 context
= TYPE_MAIN_VARIANT (context
);
20371 return strip_naming_typedef (context
, force_type_die (context
));
20374 return force_decl_die (context
);
20376 return comp_unit_die ();
20379 /* Returns the DIE for decl. A DIE will always be returned. */
20382 force_decl_die (tree decl
)
20384 dw_die_ref decl_die
;
20385 unsigned saved_external_flag
;
20386 tree save_fn
= NULL_TREE
;
20387 decl_die
= lookup_decl_die (decl
);
20390 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
20392 decl_die
= lookup_decl_die (decl
);
20396 switch (TREE_CODE (decl
))
20398 case FUNCTION_DECL
:
20399 /* Clear current_function_decl, so that gen_subprogram_die thinks
20400 that this is a declaration. At this point, we just want to force
20401 declaration die. */
20402 save_fn
= current_function_decl
;
20403 current_function_decl
= NULL_TREE
;
20404 gen_subprogram_die (decl
, context_die
);
20405 current_function_decl
= save_fn
;
20409 /* Set external flag to force declaration die. Restore it after
20410 gen_decl_die() call. */
20411 saved_external_flag
= DECL_EXTERNAL (decl
);
20412 DECL_EXTERNAL (decl
) = 1;
20413 gen_decl_die (decl
, NULL
, context_die
);
20414 DECL_EXTERNAL (decl
) = saved_external_flag
;
20417 case NAMESPACE_DECL
:
20418 if (dwarf_version
>= 3 || !dwarf_strict
)
20419 dwarf2out_decl (decl
);
20421 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
20422 decl_die
= comp_unit_die ();
20425 case TRANSLATION_UNIT_DECL
:
20426 decl_die
= comp_unit_die ();
20430 gcc_unreachable ();
20433 /* We should be able to find the DIE now. */
20435 decl_die
= lookup_decl_die (decl
);
20436 gcc_assert (decl_die
);
20442 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
20443 always returned. */
20446 force_type_die (tree type
)
20448 dw_die_ref type_die
;
20450 type_die
= lookup_type_die (type
);
20453 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
20455 type_die
= modified_type_die (type
, TYPE_QUALS_NO_ADDR_SPACE (type
),
20457 gcc_assert (type_die
);
20462 /* Force out any required namespaces to be able to output DECL,
20463 and return the new context_die for it, if it's changed. */
20466 setup_namespace_context (tree thing
, dw_die_ref context_die
)
20468 tree context
= (DECL_P (thing
)
20469 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
20470 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
20471 /* Force out the namespace. */
20472 context_die
= force_decl_die (context
);
20474 return context_die
;
20477 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
20478 type) within its namespace, if appropriate.
20480 For compatibility with older debuggers, namespace DIEs only contain
20481 declarations; all definitions are emitted at CU scope. */
20484 declare_in_namespace (tree thing
, dw_die_ref context_die
)
20486 dw_die_ref ns_context
;
20488 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20489 return context_die
;
20491 /* External declarations in the local scope only need to be emitted
20492 once, not once in the namespace and once in the scope.
20494 This avoids declaring the `extern' below in the
20495 namespace DIE as well as in the innermost scope:
20508 if (DECL_P (thing
) && DECL_EXTERNAL (thing
) && local_scope_p (context_die
))
20509 return context_die
;
20511 /* If this decl is from an inlined function, then don't try to emit it in its
20512 namespace, as we will get confused. It would have already been emitted
20513 when the abstract instance of the inline function was emitted anyways. */
20514 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
20515 return context_die
;
20517 ns_context
= setup_namespace_context (thing
, context_die
);
20519 if (ns_context
!= context_die
)
20523 if (DECL_P (thing
))
20524 gen_decl_die (thing
, NULL
, ns_context
);
20526 gen_type_die (thing
, ns_context
);
20528 return context_die
;
20531 /* Generate a DIE for a namespace or namespace alias. */
20534 gen_namespace_die (tree decl
, dw_die_ref context_die
)
20536 dw_die_ref namespace_die
;
20538 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
20539 they are an alias of. */
20540 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
20542 /* Output a real namespace or module. */
20543 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20544 namespace_die
= new_die (is_fortran ()
20545 ? DW_TAG_module
: DW_TAG_namespace
,
20546 context_die
, decl
);
20547 /* For Fortran modules defined in different CU don't add src coords. */
20548 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
20550 const char *name
= dwarf2_name (decl
, 0);
20552 add_name_attribute (namespace_die
, name
);
20555 add_name_and_src_coords_attributes (namespace_die
, decl
);
20556 if (DECL_EXTERNAL (decl
))
20557 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
20558 equate_decl_number_to_die (decl
, namespace_die
);
20562 /* Output a namespace alias. */
20564 /* Force out the namespace we are an alias of, if necessary. */
20565 dw_die_ref origin_die
20566 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
20568 if (DECL_FILE_SCOPE_P (decl
)
20569 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
20570 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20571 /* Now create the namespace alias DIE. */
20572 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
20573 add_name_and_src_coords_attributes (namespace_die
, decl
);
20574 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
20575 equate_decl_number_to_die (decl
, namespace_die
);
20577 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
20578 if (want_pubnames ())
20579 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
20582 /* Generate Dwarf debug information for a decl described by DECL.
20583 The return value is currently only meaningful for PARM_DECLs,
20584 for all other decls it returns NULL. */
20587 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
20589 tree decl_or_origin
= decl
? decl
: origin
;
20590 tree class_origin
= NULL
, ultimate_origin
;
20592 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
20595 /* Ignore pointer bounds decls. */
20596 if (DECL_P (decl_or_origin
)
20597 && TREE_TYPE (decl_or_origin
)
20598 && POINTER_BOUNDS_P (decl_or_origin
))
20601 switch (TREE_CODE (decl_or_origin
))
20607 if (!is_fortran () && !is_ada ())
20609 /* The individual enumerators of an enum type get output when we output
20610 the Dwarf representation of the relevant enum type itself. */
20614 /* Emit its type. */
20615 gen_type_die (TREE_TYPE (decl
), context_die
);
20617 /* And its containing namespace. */
20618 context_die
= declare_in_namespace (decl
, context_die
);
20620 gen_const_die (decl
, context_die
);
20623 case FUNCTION_DECL
:
20624 /* Don't output any DIEs to represent mere function declarations,
20625 unless they are class members or explicit block externs. */
20626 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
20627 && DECL_FILE_SCOPE_P (decl_or_origin
)
20628 && (current_function_decl
== NULL_TREE
20629 || DECL_ARTIFICIAL (decl_or_origin
)))
20634 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
20635 on local redeclarations of global functions. That seems broken. */
20636 if (current_function_decl
!= decl
)
20637 /* This is only a declaration. */;
20640 /* If we're emitting a clone, emit info for the abstract instance. */
20641 if (origin
|| DECL_ORIGIN (decl
) != decl
)
20642 dwarf2out_abstract_function (origin
20643 ? DECL_ORIGIN (origin
)
20644 : DECL_ABSTRACT_ORIGIN (decl
));
20646 /* If we're emitting an out-of-line copy of an inline function,
20647 emit info for the abstract instance and set up to refer to it. */
20648 else if (cgraph_function_possibly_inlined_p (decl
)
20649 && ! DECL_ABSTRACT_P (decl
)
20650 && ! class_or_namespace_scope_p (context_die
)
20651 /* dwarf2out_abstract_function won't emit a die if this is just
20652 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
20653 that case, because that works only if we have a die. */
20654 && DECL_INITIAL (decl
) != NULL_TREE
)
20656 dwarf2out_abstract_function (decl
);
20657 set_decl_origin_self (decl
);
20660 /* Otherwise we're emitting the primary DIE for this decl. */
20661 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20663 /* Before we describe the FUNCTION_DECL itself, make sure that we
20664 have its containing type. */
20666 origin
= decl_class_context (decl
);
20667 if (origin
!= NULL_TREE
)
20668 gen_type_die (origin
, context_die
);
20670 /* And its return type. */
20671 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
20673 /* And its virtual context. */
20674 if (DECL_VINDEX (decl
) != NULL_TREE
)
20675 gen_type_die (DECL_CONTEXT (decl
), context_die
);
20677 /* Make sure we have a member DIE for decl. */
20678 if (origin
!= NULL_TREE
)
20679 gen_type_die_for_member (origin
, decl
, context_die
);
20681 /* And its containing namespace. */
20682 context_die
= declare_in_namespace (decl
, context_die
);
20685 /* Now output a DIE to represent the function itself. */
20687 gen_subprogram_die (decl
, context_die
);
20691 /* If we are in terse mode, don't generate any DIEs to represent any
20692 actual typedefs. */
20693 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20696 /* In the special case of a TYPE_DECL node representing the declaration
20697 of some type tag, if the given TYPE_DECL is marked as having been
20698 instantiated from some other (original) TYPE_DECL node (e.g. one which
20699 was generated within the original definition of an inline function) we
20700 used to generate a special (abbreviated) DW_TAG_structure_type,
20701 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20702 should be actually referencing those DIEs, as variable DIEs with that
20703 type would be emitted already in the abstract origin, so it was always
20704 removed during unused type prunning. Don't add anything in this
20706 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
20709 if (is_redundant_typedef (decl
))
20710 gen_type_die (TREE_TYPE (decl
), context_die
);
20712 /* Output a DIE to represent the typedef itself. */
20713 gen_typedef_die (decl
, context_die
);
20717 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
20718 gen_label_die (decl
, context_die
);
20723 /* If we are in terse mode, don't generate any DIEs to represent any
20724 variable declarations or definitions. */
20725 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20728 /* Output any DIEs that are needed to specify the type of this data
20730 if (decl_by_reference_p (decl_or_origin
))
20731 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20733 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20735 /* And its containing type. */
20736 class_origin
= decl_class_context (decl_or_origin
);
20737 if (class_origin
!= NULL_TREE
)
20738 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20740 /* And its containing namespace. */
20741 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20743 /* Now output the DIE to represent the data object itself. This gets
20744 complicated because of the possibility that the VAR_DECL really
20745 represents an inlined instance of a formal parameter for an inline
20747 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20748 if (ultimate_origin
!= NULL_TREE
20749 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20750 gen_formal_parameter_die (decl
, origin
,
20751 true /* Emit name attribute. */,
20754 gen_variable_die (decl
, origin
, context_die
);
20758 /* Ignore the nameless fields that are used to skip bits but handle C++
20759 anonymous unions and structs. */
20760 if (DECL_NAME (decl
) != NULL_TREE
20761 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20762 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20764 gen_type_die (member_declared_type (decl
), context_die
);
20765 gen_field_die (decl
, context_die
);
20770 if (DECL_BY_REFERENCE (decl_or_origin
))
20771 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20773 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20774 return gen_formal_parameter_die (decl
, origin
,
20775 true /* Emit name attribute. */,
20778 case NAMESPACE_DECL
:
20779 case IMPORTED_DECL
:
20780 if (dwarf_version
>= 3 || !dwarf_strict
)
20781 gen_namespace_die (decl
, context_die
);
20784 case NAMELIST_DECL
:
20785 gen_namelist_decl (DECL_NAME (decl
), context_die
,
20786 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
20790 /* Probably some frontend-internal decl. Assume we don't care. */
20791 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20798 /* Output debug information for global decl DECL. Called from toplev.c after
20799 compilation proper has finished. */
20802 dwarf2out_global_decl (tree decl
)
20804 /* Output DWARF2 information for file-scope tentative data object
20805 declarations, file-scope (extern) function declarations (which
20806 had no corresponding body) and file-scope tagged type declarations
20807 and definitions which have not yet been forced out. */
20808 if ((TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20809 && !POINTER_BOUNDS_P (decl
))
20810 dwarf2out_decl (decl
);
20813 /* Output debug information for type decl DECL. Called from toplev.c
20814 and from language front ends (to record built-in types). */
20816 dwarf2out_type_decl (tree decl
, int local
)
20819 dwarf2out_decl (decl
);
20822 /* Output debug information for imported module or decl DECL.
20823 NAME is non-NULL name in the lexical block if the decl has been renamed.
20824 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20825 that DECL belongs to.
20826 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20828 dwarf2out_imported_module_or_decl_1 (tree decl
,
20830 tree lexical_block
,
20831 dw_die_ref lexical_block_die
)
20833 expanded_location xloc
;
20834 dw_die_ref imported_die
= NULL
;
20835 dw_die_ref at_import_die
;
20837 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20839 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20840 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20844 xloc
= expand_location (input_location
);
20846 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20848 at_import_die
= force_type_die (TREE_TYPE (decl
));
20849 /* For namespace N { typedef void T; } using N::T; base_type_die
20850 returns NULL, but DW_TAG_imported_declaration requires
20851 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20852 if (!at_import_die
)
20854 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20855 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20856 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20857 gcc_assert (at_import_die
);
20862 at_import_die
= lookup_decl_die (decl
);
20863 if (!at_import_die
)
20865 /* If we're trying to avoid duplicate debug info, we may not have
20866 emitted the member decl for this field. Emit it now. */
20867 if (TREE_CODE (decl
) == FIELD_DECL
)
20869 tree type
= DECL_CONTEXT (decl
);
20871 if (TYPE_CONTEXT (type
)
20872 && TYPE_P (TYPE_CONTEXT (type
))
20873 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20874 DINFO_USAGE_DIR_USE
))
20876 gen_type_die_for_member (type
, decl
,
20877 get_context_die (TYPE_CONTEXT (type
)));
20879 if (TREE_CODE (decl
) == NAMELIST_DECL
)
20880 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
20881 get_context_die (DECL_CONTEXT (decl
)),
20884 at_import_die
= force_decl_die (decl
);
20888 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20890 if (dwarf_version
>= 3 || !dwarf_strict
)
20891 imported_die
= new_die (DW_TAG_imported_module
,
20898 imported_die
= new_die (DW_TAG_imported_declaration
,
20902 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20903 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20905 add_AT_string (imported_die
, DW_AT_name
,
20906 IDENTIFIER_POINTER (name
));
20907 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20910 /* Output debug information for imported module or decl DECL.
20911 NAME is non-NULL name in context if the decl has been renamed.
20912 CHILD is true if decl is one of the renamed decls as part of
20913 importing whole module. */
20916 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20919 /* dw_die_ref at_import_die; */
20920 dw_die_ref scope_die
;
20922 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20927 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20928 We need decl DIE for reference and scope die. First, get DIE for the decl
20931 /* Get the scope die for decl context. Use comp_unit_die for global module
20932 or decl. If die is not found for non globals, force new die. */
20934 && TYPE_P (context
)
20935 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20938 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20941 scope_die
= get_context_die (context
);
20945 gcc_assert (scope_die
->die_child
);
20946 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
20947 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
20948 scope_die
= scope_die
->die_child
;
20951 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20952 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
20956 /* Output debug information for namelists. */
20959 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
20961 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
20965 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20968 gcc_assert (scope_die
!= NULL
);
20969 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
20970 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
20972 /* If there are no item_decls, we have a nondefining namelist, e.g.
20973 with USE association; hence, set DW_AT_declaration. */
20974 if (item_decls
== NULL_TREE
)
20976 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
20980 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
20982 nml_item_ref_die
= lookup_decl_die (value
);
20983 if (!nml_item_ref_die
)
20984 nml_item_ref_die
= force_decl_die (value
);
20986 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
20987 add_AT_die_ref (nml_item_die
, DW_AT_namelist_items
, nml_item_ref_die
);
20993 /* Write the debugging output for DECL. */
20996 dwarf2out_decl (tree decl
)
20998 dw_die_ref context_die
= comp_unit_die ();
21000 switch (TREE_CODE (decl
))
21005 case FUNCTION_DECL
:
21006 /* What we would really like to do here is to filter out all mere
21007 file-scope declarations of file-scope functions which are never
21008 referenced later within this translation unit (and keep all of ones
21009 that *are* referenced later on) but we aren't clairvoyant, so we have
21010 no idea which functions will be referenced in the future (i.e. later
21011 on within the current translation unit). So here we just ignore all
21012 file-scope function declarations which are not also definitions. If
21013 and when the debugger needs to know something about these functions,
21014 it will have to hunt around and find the DWARF information associated
21015 with the definition of the function.
21017 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
21018 nodes represent definitions and which ones represent mere
21019 declarations. We have to check DECL_INITIAL instead. That's because
21020 the C front-end supports some weird semantics for "extern inline"
21021 function definitions. These can get inlined within the current
21022 translation unit (and thus, we need to generate Dwarf info for their
21023 abstract instances so that the Dwarf info for the concrete inlined
21024 instances can have something to refer to) but the compiler never
21025 generates any out-of-lines instances of such things (despite the fact
21026 that they *are* definitions).
21028 The important point is that the C front-end marks these "extern
21029 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
21030 them anyway. Note that the C++ front-end also plays some similar games
21031 for inline function definitions appearing within include files which
21032 also contain `#pragma interface' pragmas.
21034 If we are called from dwarf2out_abstract_function output a DIE
21035 anyway. We can end up here this way with early inlining and LTO
21036 where the inlined function is output in a different LTRANS unit
21038 if (DECL_INITIAL (decl
) == NULL_TREE
21039 && ! DECL_ABSTRACT_P (decl
))
21042 /* If we're a nested function, initially use a parent of NULL; if we're
21043 a plain function, this will be fixed up in decls_for_scope. If
21044 we're a method, it will be ignored, since we already have a DIE. */
21045 if (decl_function_context (decl
)
21046 /* But if we're in terse mode, we don't care about scope. */
21047 && debug_info_level
> DINFO_LEVEL_TERSE
)
21048 context_die
= NULL
;
21052 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
21053 declaration and if the declaration was never even referenced from
21054 within this entire compilation unit. We suppress these DIEs in
21055 order to save space in the .debug section (by eliminating entries
21056 which are probably useless). Note that we must not suppress
21057 block-local extern declarations (whether used or not) because that
21058 would screw-up the debugger's name lookup mechanism and cause it to
21059 miss things which really ought to be in scope at a given point. */
21060 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
21063 /* For local statics lookup proper context die. */
21064 if (TREE_STATIC (decl
)
21065 && DECL_CONTEXT (decl
)
21066 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
21067 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
21069 /* If we are in terse mode, don't generate any DIEs to represent any
21070 variable declarations or definitions. */
21071 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21076 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21078 if (!is_fortran () && !is_ada ())
21080 if (TREE_STATIC (decl
) && decl_function_context (decl
))
21081 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
21084 case NAMESPACE_DECL
:
21085 case IMPORTED_DECL
:
21086 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21088 if (lookup_decl_die (decl
) != NULL
)
21093 /* Don't emit stubs for types unless they are needed by other DIEs. */
21094 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
21097 /* Don't bother trying to generate any DIEs to represent any of the
21098 normal built-in types for the language we are compiling. */
21099 if (DECL_IS_BUILTIN (decl
))
21102 /* If we are in terse mode, don't generate any DIEs for types. */
21103 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21106 /* If we're a function-scope tag, initially use a parent of NULL;
21107 this will be fixed up in decls_for_scope. */
21108 if (decl_function_context (decl
))
21109 context_die
= NULL
;
21113 case NAMELIST_DECL
:
21120 gen_decl_die (decl
, NULL
, context_die
);
21123 /* Write the debugging output for DECL. */
21126 dwarf2out_function_decl (tree decl
)
21128 dwarf2out_decl (decl
);
21129 call_arg_locations
= NULL
;
21130 call_arg_loc_last
= NULL
;
21131 call_site_count
= -1;
21132 tail_call_site_count
= -1;
21133 block_map
.release ();
21134 decl_loc_table
->empty ();
21135 cached_dw_loc_list_table
->empty ();
21138 /* Output a marker (i.e. a label) for the beginning of the generated code for
21139 a lexical block. */
21142 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
21143 unsigned int blocknum
)
21145 switch_to_section (current_function_section ());
21146 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
21149 /* Output a marker (i.e. a label) for the end of the generated code for a
21153 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
21155 switch_to_section (current_function_section ());
21156 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
21159 /* Returns nonzero if it is appropriate not to emit any debugging
21160 information for BLOCK, because it doesn't contain any instructions.
21162 Don't allow this for blocks with nested functions or local classes
21163 as we would end up with orphans, and in the presence of scheduling
21164 we may end up calling them anyway. */
21167 dwarf2out_ignore_block (const_tree block
)
21172 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
21173 if (TREE_CODE (decl
) == FUNCTION_DECL
21174 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
21176 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
21178 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
21179 if (TREE_CODE (decl
) == FUNCTION_DECL
21180 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
21187 /* Hash table routines for file_hash. */
21190 dwarf_file_hasher::equal (dwarf_file_data
*p1
, const char *p2
)
21192 return filename_cmp (p1
->filename
, p2
) == 0;
21196 dwarf_file_hasher::hash (dwarf_file_data
*p
)
21198 return htab_hash_string (p
->filename
);
21201 /* Lookup FILE_NAME (in the list of filenames that we know about here in
21202 dwarf2out.c) and return its "index". The index of each (known) filename is
21203 just a unique number which is associated with only that one filename. We
21204 need such numbers for the sake of generating labels (in the .debug_sfnames
21205 section) and references to those files numbers (in the .debug_srcinfo
21206 and.debug_macinfo sections). If the filename given as an argument is not
21207 found in our current list, add it to the list and assign it the next
21208 available unique index number. In order to speed up searches, we remember
21209 the index of the filename was looked up last. This handles the majority of
21212 static struct dwarf_file_data
*
21213 lookup_filename (const char *file_name
)
21215 struct dwarf_file_data
* created
;
21217 /* Check to see if the file name that was searched on the previous
21218 call matches this file name. If so, return the index. */
21219 if (file_table_last_lookup
21220 && (file_name
== file_table_last_lookup
->filename
21221 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
21222 return file_table_last_lookup
;
21224 /* Didn't match the previous lookup, search the table. */
21225 dwarf_file_data
**slot
21226 = file_table
->find_slot_with_hash (file_name
, htab_hash_string (file_name
),
21231 created
= ggc_alloc
<dwarf_file_data
> ();
21232 created
->filename
= file_name
;
21233 created
->emitted_number
= 0;
21238 /* If the assembler will construct the file table, then translate the compiler
21239 internal file table number into the assembler file table number, and emit
21240 a .file directive if we haven't already emitted one yet. The file table
21241 numbers are different because we prune debug info for unused variables and
21242 types, which may include filenames. */
21245 maybe_emit_file (struct dwarf_file_data
* fd
)
21247 if (! fd
->emitted_number
)
21249 if (last_emitted_file
)
21250 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
21252 fd
->emitted_number
= 1;
21253 last_emitted_file
= fd
;
21255 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21257 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
21258 output_quoted_string (asm_out_file
,
21259 remap_debug_filename (fd
->filename
));
21260 fputc ('\n', asm_out_file
);
21264 return fd
->emitted_number
;
21267 /* Schedule generation of a DW_AT_const_value attribute to DIE.
21268 That generation should happen after function debug info has been
21269 generated. The value of the attribute is the constant value of ARG. */
21272 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
21274 die_arg_entry entry
;
21279 if (!tmpl_value_parm_die_table
)
21280 vec_alloc (tmpl_value_parm_die_table
, 32);
21284 vec_safe_push (tmpl_value_parm_die_table
, entry
);
21287 /* Return TRUE if T is an instance of generic type, FALSE
21291 generic_type_p (tree t
)
21293 if (t
== NULL_TREE
|| !TYPE_P (t
))
21295 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
21298 /* Schedule the generation of the generic parameter dies for the
21299 instance of generic type T. The proper generation itself is later
21300 done by gen_scheduled_generic_parms_dies. */
21303 schedule_generic_params_dies_gen (tree t
)
21305 if (!generic_type_p (t
))
21308 if (!generic_type_instances
)
21309 vec_alloc (generic_type_instances
, 256);
21311 vec_safe_push (generic_type_instances
, t
);
21314 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
21315 by append_entry_to_tmpl_value_parm_die_table. This function must
21316 be called after function DIEs have been generated. */
21319 gen_remaining_tmpl_value_param_die_attribute (void)
21321 if (tmpl_value_parm_die_table
)
21326 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
21327 tree_add_const_value_attribute (e
->die
, e
->arg
);
21331 /* Generate generic parameters DIEs for instances of generic types
21332 that have been previously scheduled by
21333 schedule_generic_params_dies_gen. This function must be called
21334 after all the types of the CU have been laid out. */
21337 gen_scheduled_generic_parms_dies (void)
21342 if (!generic_type_instances
)
21345 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
21346 if (COMPLETE_TYPE_P (t
))
21347 gen_generic_params_dies (t
);
21351 /* Replace DW_AT_name for the decl with name. */
21354 dwarf2out_set_name (tree decl
, tree name
)
21360 die
= TYPE_SYMTAB_DIE (decl
);
21364 dname
= dwarf2_name (name
, 0);
21368 attr
= get_AT (die
, DW_AT_name
);
21371 struct indirect_string_node
*node
;
21373 node
= find_AT_string (dname
);
21374 /* replace the string. */
21375 attr
->dw_attr_val
.v
.val_str
= node
;
21379 add_name_attribute (die
, dname
);
21382 /* True if before or during processing of the first function being emitted. */
21383 static bool in_first_function_p
= true;
21384 /* True if loc_note during dwarf2out_var_location call might still be
21385 before first real instruction at address equal to .Ltext0. */
21386 static bool maybe_at_text_label_p
= true;
21387 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
21388 static unsigned int first_loclabel_num_not_at_text_label
;
21390 /* Called by the final INSN scan whenever we see a var location. We
21391 use it to drop labels in the right places, and throw the location in
21392 our lookup table. */
21395 dwarf2out_var_location (rtx_insn
*loc_note
)
21397 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
21398 struct var_loc_node
*newloc
;
21399 rtx_insn
*next_real
, *next_note
;
21400 static const char *last_label
;
21401 static const char *last_postcall_label
;
21402 static bool last_in_cold_section_p
;
21403 static rtx_insn
*expected_next_loc_note
;
21407 if (!NOTE_P (loc_note
))
21409 if (CALL_P (loc_note
))
21412 if (SIBLING_CALL_P (loc_note
))
21413 tail_call_site_count
++;
21418 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
21419 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
21422 /* Optimize processing a large consecutive sequence of location
21423 notes so we don't spend too much time in next_real_insn. If the
21424 next insn is another location note, remember the next_real_insn
21425 calculation for next time. */
21426 next_real
= cached_next_real_insn
;
21429 if (expected_next_loc_note
!= loc_note
)
21433 next_note
= NEXT_INSN (loc_note
);
21435 || next_note
->deleted ()
21436 || ! NOTE_P (next_note
)
21437 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
21438 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
21442 next_real
= next_real_insn (loc_note
);
21446 expected_next_loc_note
= next_note
;
21447 cached_next_real_insn
= next_real
;
21450 cached_next_real_insn
= NULL
;
21452 /* If there are no instructions which would be affected by this note,
21453 don't do anything. */
21455 && next_real
== NULL_RTX
21456 && !NOTE_DURING_CALL_P (loc_note
))
21459 if (next_real
== NULL_RTX
)
21460 next_real
= get_last_insn ();
21462 /* If there were any real insns between note we processed last time
21463 and this note (or if it is the first note), clear
21464 last_{,postcall_}label so that they are not reused this time. */
21465 if (last_var_location_insn
== NULL_RTX
21466 || last_var_location_insn
!= next_real
21467 || last_in_cold_section_p
!= in_cold_section_p
)
21470 last_postcall_label
= NULL
;
21475 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
21476 newloc
= add_var_loc_to_decl (decl
, loc_note
,
21477 NOTE_DURING_CALL_P (loc_note
)
21478 ? last_postcall_label
: last_label
);
21479 if (newloc
== NULL
)
21488 /* If there were no real insns between note we processed last time
21489 and this note, use the label we emitted last time. Otherwise
21490 create a new label and emit it. */
21491 if (last_label
== NULL
)
21493 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
21494 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
21496 last_label
= ggc_strdup (loclabel
);
21497 /* See if loclabel might be equal to .Ltext0. If yes,
21498 bump first_loclabel_num_not_at_text_label. */
21499 if (!have_multiple_function_sections
21500 && in_first_function_p
21501 && maybe_at_text_label_p
)
21503 static rtx_insn
*last_start
;
21505 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
21506 if (insn
== last_start
)
21508 else if (!NONDEBUG_INSN_P (insn
))
21512 rtx body
= PATTERN (insn
);
21513 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
21515 /* Inline asm could occupy zero bytes. */
21516 else if (GET_CODE (body
) == ASM_INPUT
21517 || asm_noperands (body
) >= 0)
21519 #ifdef HAVE_attr_length
21520 else if (get_attr_min_length (insn
) == 0)
21525 /* Assume insn has non-zero length. */
21526 maybe_at_text_label_p
= false;
21530 if (maybe_at_text_label_p
)
21532 last_start
= loc_note
;
21533 first_loclabel_num_not_at_text_label
= loclabel_num
;
21540 struct call_arg_loc_node
*ca_loc
21541 = ggc_cleared_alloc
<call_arg_loc_node
> ();
21542 rtx_insn
*prev
= prev_real_insn (loc_note
);
21544 ca_loc
->call_arg_loc_note
= loc_note
;
21545 ca_loc
->next
= NULL
;
21546 ca_loc
->label
= last_label
;
21549 || (NONJUMP_INSN_P (prev
)
21550 && GET_CODE (PATTERN (prev
)) == SEQUENCE
21551 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
21552 if (!CALL_P (prev
))
21553 prev
= as_a
<rtx_sequence
*> (PATTERN (prev
))->insn (0);
21554 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
21555 x
= get_call_rtx_from (PATTERN (prev
));
21558 x
= XEXP (XEXP (x
, 0), 0);
21559 if (GET_CODE (x
) == SYMBOL_REF
21560 && SYMBOL_REF_DECL (x
)
21561 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
21562 ca_loc
->symbol_ref
= x
;
21564 ca_loc
->block
= insn_scope (prev
);
21565 if (call_arg_locations
)
21566 call_arg_loc_last
->next
= ca_loc
;
21568 call_arg_locations
= ca_loc
;
21569 call_arg_loc_last
= ca_loc
;
21571 else if (!NOTE_DURING_CALL_P (loc_note
))
21572 newloc
->label
= last_label
;
21575 if (!last_postcall_label
)
21577 sprintf (loclabel
, "%s-1", last_label
);
21578 last_postcall_label
= ggc_strdup (loclabel
);
21580 newloc
->label
= last_postcall_label
;
21583 last_var_location_insn
= next_real
;
21584 last_in_cold_section_p
= in_cold_section_p
;
21587 /* Note in one location list that text section has changed. */
21590 var_location_switch_text_section_1 (var_loc_list
**slot
, void *)
21592 var_loc_list
*list
= *slot
;
21594 list
->last_before_switch
21595 = list
->last
->next
? list
->last
->next
: list
->last
;
21599 /* Note in all location lists that text section has changed. */
21602 var_location_switch_text_section (void)
21604 if (decl_loc_table
== NULL
)
21607 decl_loc_table
->traverse
<void *, var_location_switch_text_section_1
> (NULL
);
21610 /* Create a new line number table. */
21612 static dw_line_info_table
*
21613 new_line_info_table (void)
21615 dw_line_info_table
*table
;
21617 table
= ggc_cleared_alloc
<dw_line_info_table_struct
> ();
21618 table
->file_num
= 1;
21619 table
->line_num
= 1;
21620 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
21625 /* Lookup the "current" table into which we emit line info, so
21626 that we don't have to do it for every source line. */
21629 set_cur_line_info_table (section
*sec
)
21631 dw_line_info_table
*table
;
21633 if (sec
== text_section
)
21634 table
= text_section_line_info
;
21635 else if (sec
== cold_text_section
)
21637 table
= cold_text_section_line_info
;
21640 cold_text_section_line_info
= table
= new_line_info_table ();
21641 table
->end_label
= cold_end_label
;
21646 const char *end_label
;
21648 if (flag_reorder_blocks_and_partition
)
21650 if (in_cold_section_p
)
21651 end_label
= crtl
->subsections
.cold_section_end_label
;
21653 end_label
= crtl
->subsections
.hot_section_end_label
;
21657 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21658 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
21659 current_function_funcdef_no
);
21660 end_label
= ggc_strdup (label
);
21663 table
= new_line_info_table ();
21664 table
->end_label
= end_label
;
21666 vec_safe_push (separate_line_info
, table
);
21669 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21670 table
->is_stmt
= (cur_line_info_table
21671 ? cur_line_info_table
->is_stmt
21672 : DWARF_LINE_DEFAULT_IS_STMT_START
);
21673 cur_line_info_table
= table
;
21677 /* We need to reset the locations at the beginning of each
21678 function. We can't do this in the end_function hook, because the
21679 declarations that use the locations won't have been output when
21680 that hook is called. Also compute have_multiple_function_sections here. */
21683 dwarf2out_begin_function (tree fun
)
21685 section
*sec
= function_section (fun
);
21687 if (sec
!= text_section
)
21688 have_multiple_function_sections
= true;
21690 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
21692 gcc_assert (current_function_decl
== fun
);
21693 cold_text_section
= unlikely_text_section ();
21694 switch_to_section (cold_text_section
);
21695 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
21696 switch_to_section (sec
);
21699 dwarf2out_note_section_used ();
21700 call_site_count
= 0;
21701 tail_call_site_count
= 0;
21703 set_cur_line_info_table (sec
);
21706 /* Helper function of dwarf2out_end_function, called only after emitting
21707 the very first function into assembly. Check if some .debug_loc range
21708 might end with a .LVL* label that could be equal to .Ltext0.
21709 In that case we must force using absolute addresses in .debug_loc ranges,
21710 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
21711 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
21713 Set have_multiple_function_sections to true in that case and
21714 terminate htab traversal. */
21717 find_empty_loc_ranges_at_text_label (var_loc_list
**slot
, int)
21719 var_loc_list
*entry
= *slot
;
21720 struct var_loc_node
*node
;
21722 node
= entry
->first
;
21723 if (node
&& node
->next
&& node
->next
->label
)
21726 const char *label
= node
->next
->label
;
21727 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
21729 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
21731 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
21732 if (strcmp (label
, loclabel
) == 0)
21734 have_multiple_function_sections
= true;
21742 /* Hook called after emitting a function into assembly.
21743 This does something only for the very first function emitted. */
21746 dwarf2out_end_function (unsigned int)
21748 if (in_first_function_p
21749 && !have_multiple_function_sections
21750 && first_loclabel_num_not_at_text_label
21752 decl_loc_table
->traverse
<int, find_empty_loc_ranges_at_text_label
> (0);
21753 in_first_function_p
= false;
21754 maybe_at_text_label_p
= false;
21757 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
21760 push_dw_line_info_entry (dw_line_info_table
*table
,
21761 enum dw_line_info_opcode opcode
, unsigned int val
)
21763 dw_line_info_entry e
;
21766 vec_safe_push (table
->entries
, e
);
21769 /* Output a label to mark the beginning of a source code line entry
21770 and record information relating to this source line, in
21771 'line_info_table' for later output of the .debug_line section. */
21772 /* ??? The discriminator parameter ought to be unsigned. */
21775 dwarf2out_source_line (unsigned int line
, const char *filename
,
21776 int discriminator
, bool is_stmt
)
21778 unsigned int file_num
;
21779 dw_line_info_table
*table
;
21781 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
21784 /* The discriminator column was added in dwarf4. Simplify the below
21785 by simply removing it if we're not supposed to output it. */
21786 if (dwarf_version
< 4 && dwarf_strict
)
21789 table
= cur_line_info_table
;
21790 file_num
= maybe_emit_file (lookup_filename (filename
));
21792 /* ??? TODO: Elide duplicate line number entries. Traditionally,
21793 the debugger has used the second (possibly duplicate) line number
21794 at the beginning of the function to mark the end of the prologue.
21795 We could eliminate any other duplicates within the function. For
21796 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
21797 that second line number entry. */
21798 /* Recall that this end-of-prologue indication is *not* the same thing
21799 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
21800 to which the hook corresponds, follows the last insn that was
21801 emitted by gen_prologue. What we need is to precede the first insn
21802 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
21803 insn that corresponds to something the user wrote. These may be
21804 very different locations once scheduling is enabled. */
21806 if (0 && file_num
== table
->file_num
21807 && line
== table
->line_num
21808 && discriminator
== table
->discrim_num
21809 && is_stmt
== table
->is_stmt
)
21812 switch_to_section (current_function_section ());
21814 /* If requested, emit something human-readable. */
21815 if (flag_debug_asm
)
21816 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
21818 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21820 /* Emit the .loc directive understood by GNU as. */
21821 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
21822 file_num, line, is_stmt, discriminator */
21823 fputs ("\t.loc ", asm_out_file
);
21824 fprint_ul (asm_out_file
, file_num
);
21825 putc (' ', asm_out_file
);
21826 fprint_ul (asm_out_file
, line
);
21827 putc (' ', asm_out_file
);
21828 putc ('0', asm_out_file
);
21830 if (is_stmt
!= table
->is_stmt
)
21832 fputs (" is_stmt ", asm_out_file
);
21833 putc (is_stmt
? '1' : '0', asm_out_file
);
21835 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
21837 gcc_assert (discriminator
> 0);
21838 fputs (" discriminator ", asm_out_file
);
21839 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
21841 putc ('\n', asm_out_file
);
21845 unsigned int label_num
= ++line_info_label_num
;
21847 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
21849 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
21850 if (file_num
!= table
->file_num
)
21851 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
21852 if (discriminator
!= table
->discrim_num
)
21853 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
21854 if (is_stmt
!= table
->is_stmt
)
21855 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
21856 push_dw_line_info_entry (table
, LI_set_line
, line
);
21859 table
->file_num
= file_num
;
21860 table
->line_num
= line
;
21861 table
->discrim_num
= discriminator
;
21862 table
->is_stmt
= is_stmt
;
21863 table
->in_use
= true;
21866 /* Record the beginning of a new source file. */
21869 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21871 if (flag_eliminate_dwarf2_dups
)
21873 /* Record the beginning of the file for break_out_includes. */
21874 dw_die_ref bincl_die
;
21876 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
21877 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21880 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21883 e
.code
= DW_MACINFO_start_file
;
21885 e
.info
= ggc_strdup (filename
);
21886 vec_safe_push (macinfo_table
, e
);
21890 /* Record the end of a source file. */
21893 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21895 if (flag_eliminate_dwarf2_dups
)
21896 /* Record the end of the file for break_out_includes. */
21897 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
21899 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21902 e
.code
= DW_MACINFO_end_file
;
21905 vec_safe_push (macinfo_table
, e
);
21909 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21910 the tail part of the directive line, i.e. the part which is past the
21911 initial whitespace, #, whitespace, directive-name, whitespace part. */
21914 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
21915 const char *buffer ATTRIBUTE_UNUSED
)
21917 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21920 /* Insert a dummy first entry to be able to optimize the whole
21921 predefined macro block using DW_MACRO_GNU_transparent_include. */
21922 if (macinfo_table
->is_empty () && lineno
<= 1)
21927 vec_safe_push (macinfo_table
, e
);
21929 e
.code
= DW_MACINFO_define
;
21931 e
.info
= ggc_strdup (buffer
);
21932 vec_safe_push (macinfo_table
, e
);
21936 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21937 the tail part of the directive line, i.e. the part which is past the
21938 initial whitespace, #, whitespace, directive-name, whitespace part. */
21941 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21942 const char *buffer ATTRIBUTE_UNUSED
)
21944 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21947 /* Insert a dummy first entry to be able to optimize the whole
21948 predefined macro block using DW_MACRO_GNU_transparent_include. */
21949 if (macinfo_table
->is_empty () && lineno
<= 1)
21954 vec_safe_push (macinfo_table
, e
);
21956 e
.code
= DW_MACINFO_undef
;
21958 e
.info
= ggc_strdup (buffer
);
21959 vec_safe_push (macinfo_table
, e
);
21963 /* Helpers to manipulate hash table of CUs. */
21965 struct macinfo_entry_hasher
: typed_noop_remove
<macinfo_entry
>
21967 typedef macinfo_entry value_type
;
21968 typedef macinfo_entry compare_type
;
21969 static inline hashval_t
hash (const value_type
*);
21970 static inline bool equal (const value_type
*, const compare_type
*);
21974 macinfo_entry_hasher::hash (const value_type
*entry
)
21976 return htab_hash_string (entry
->info
);
21980 macinfo_entry_hasher::equal (const value_type
*entry1
,
21981 const compare_type
*entry2
)
21983 return !strcmp (entry1
->info
, entry2
->info
);
21986 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
21988 /* Output a single .debug_macinfo entry. */
21991 output_macinfo_op (macinfo_entry
*ref
)
21995 struct indirect_string_node
*node
;
21996 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21997 struct dwarf_file_data
*fd
;
22001 case DW_MACINFO_start_file
:
22002 fd
= lookup_filename (ref
->info
);
22003 file_num
= maybe_emit_file (fd
);
22004 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
22005 dw2_asm_output_data_uleb128 (ref
->lineno
,
22006 "Included from line number %lu",
22007 (unsigned long) ref
->lineno
);
22008 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
22010 case DW_MACINFO_end_file
:
22011 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
22013 case DW_MACINFO_define
:
22014 case DW_MACINFO_undef
:
22015 len
= strlen (ref
->info
) + 1;
22017 && len
> DWARF_OFFSET_SIZE
22018 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
22019 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
22021 ref
->code
= ref
->code
== DW_MACINFO_define
22022 ? DW_MACRO_GNU_define_indirect
22023 : DW_MACRO_GNU_undef_indirect
;
22024 output_macinfo_op (ref
);
22027 dw2_asm_output_data (1, ref
->code
,
22028 ref
->code
== DW_MACINFO_define
22029 ? "Define macro" : "Undefine macro");
22030 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
22031 (unsigned long) ref
->lineno
);
22032 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
22034 case DW_MACRO_GNU_define_indirect
:
22035 case DW_MACRO_GNU_undef_indirect
:
22036 node
= find_AT_string (ref
->info
);
22038 && ((node
->form
== DW_FORM_strp
)
22039 || (node
->form
== DW_FORM_GNU_str_index
)));
22040 dw2_asm_output_data (1, ref
->code
,
22041 ref
->code
== DW_MACRO_GNU_define_indirect
22042 ? "Define macro indirect"
22043 : "Undefine macro indirect");
22044 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
22045 (unsigned long) ref
->lineno
);
22046 if (node
->form
== DW_FORM_strp
)
22047 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
22048 debug_str_section
, "The macro: \"%s\"",
22051 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
22054 case DW_MACRO_GNU_transparent_include
:
22055 dw2_asm_output_data (1, ref
->code
, "Transparent include");
22056 ASM_GENERATE_INTERNAL_LABEL (label
,
22057 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
22058 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
22061 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
22062 ASM_COMMENT_START
, (unsigned long) ref
->code
);
22067 /* Attempt to make a sequence of define/undef macinfo ops shareable with
22068 other compilation unit .debug_macinfo sections. IDX is the first
22069 index of a define/undef, return the number of ops that should be
22070 emitted in a comdat .debug_macinfo section and emit
22071 a DW_MACRO_GNU_transparent_include entry referencing it.
22072 If the define/undef entry should be emitted normally, return 0. */
22075 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
22076 macinfo_hash_type
**macinfo_htab
)
22078 macinfo_entry
*first
, *second
, *cur
, *inc
;
22079 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
22080 unsigned char checksum
[16];
22081 struct md5_ctx ctx
;
22082 char *grp_name
, *tail
;
22084 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
22085 macinfo_entry
**slot
;
22087 first
= &(*macinfo_table
)[idx
];
22088 second
= &(*macinfo_table
)[idx
+ 1];
22090 /* Optimize only if there are at least two consecutive define/undef ops,
22091 and either all of them are before first DW_MACINFO_start_file
22092 with lineno {0,1} (i.e. predefined macro block), or all of them are
22093 in some included header file. */
22094 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
22096 if (vec_safe_is_empty (files
))
22098 if (first
->lineno
> 1 || second
->lineno
> 1)
22101 else if (first
->lineno
== 0)
22104 /* Find the last define/undef entry that can be grouped together
22105 with first and at the same time compute md5 checksum of their
22106 codes, linenumbers and strings. */
22107 md5_init_ctx (&ctx
);
22108 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
22109 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
22111 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
22115 unsigned char code
= cur
->code
;
22116 md5_process_bytes (&code
, 1, &ctx
);
22117 checksum_uleb128 (cur
->lineno
, &ctx
);
22118 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
22120 md5_finish_ctx (&ctx
, checksum
);
22123 /* From the containing include filename (if any) pick up just
22124 usable characters from its basename. */
22125 if (vec_safe_is_empty (files
))
22128 base
= lbasename (files
->last ().info
);
22129 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
22130 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
22131 encoded_filename_len
++;
22132 /* Count . at the end. */
22133 if (encoded_filename_len
)
22134 encoded_filename_len
++;
22136 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
22137 linebuf_len
= strlen (linebuf
);
22139 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
22140 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
22142 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
22143 tail
= grp_name
+ 4;
22144 if (encoded_filename_len
)
22146 for (i
= 0; base
[i
]; i
++)
22147 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
22151 memcpy (tail
, linebuf
, linebuf_len
);
22152 tail
+= linebuf_len
;
22154 for (i
= 0; i
< 16; i
++)
22155 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
22157 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
22158 in the empty vector entry before the first define/undef. */
22159 inc
= &(*macinfo_table
)[idx
- 1];
22160 inc
->code
= DW_MACRO_GNU_transparent_include
;
22162 inc
->info
= ggc_strdup (grp_name
);
22163 if (!*macinfo_htab
)
22164 *macinfo_htab
= new macinfo_hash_type (10);
22165 /* Avoid emitting duplicates. */
22166 slot
= (*macinfo_htab
)->find_slot (inc
, INSERT
);
22171 /* If such an entry has been used before, just emit
22172 a DW_MACRO_GNU_transparent_include op. */
22174 output_macinfo_op (inc
);
22175 /* And clear all macinfo_entry in the range to avoid emitting them
22176 in the second pass. */
22177 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
22186 inc
->lineno
= (*macinfo_htab
)->elements ();
22187 output_macinfo_op (inc
);
22192 /* Save any strings needed by the macinfo table in the debug str
22193 table. All strings must be collected into the table by the time
22194 index_string is called. */
22197 save_macinfo_strings (void)
22201 macinfo_entry
*ref
;
22203 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
22207 /* Match the logic in output_macinfo_op to decide on
22208 indirect strings. */
22209 case DW_MACINFO_define
:
22210 case DW_MACINFO_undef
:
22211 len
= strlen (ref
->info
) + 1;
22213 && len
> DWARF_OFFSET_SIZE
22214 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
22215 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
22216 set_indirect_string (find_AT_string (ref
->info
));
22218 case DW_MACRO_GNU_define_indirect
:
22219 case DW_MACRO_GNU_undef_indirect
:
22220 set_indirect_string (find_AT_string (ref
->info
));
22228 /* Output macinfo section(s). */
22231 output_macinfo (void)
22234 unsigned long length
= vec_safe_length (macinfo_table
);
22235 macinfo_entry
*ref
;
22236 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
22237 macinfo_hash_type
*macinfo_htab
= NULL
;
22242 /* output_macinfo* uses these interchangeably. */
22243 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
22244 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
22245 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
22246 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
22248 /* For .debug_macro emit the section header. */
22251 dw2_asm_output_data (2, 4, "DWARF macro version number");
22252 if (DWARF_OFFSET_SIZE
== 8)
22253 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
22255 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
22256 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
22257 (!dwarf_split_debug_info
? debug_line_section_label
22258 : debug_skeleton_line_section_label
),
22259 debug_line_section
, NULL
);
22262 /* In the first loop, it emits the primary .debug_macinfo section
22263 and after each emitted op the macinfo_entry is cleared.
22264 If a longer range of define/undef ops can be optimized using
22265 DW_MACRO_GNU_transparent_include, the
22266 DW_MACRO_GNU_transparent_include op is emitted and kept in
22267 the vector before the first define/undef in the range and the
22268 whole range of define/undef ops is not emitted and kept. */
22269 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
22273 case DW_MACINFO_start_file
:
22274 vec_safe_push (files
, *ref
);
22276 case DW_MACINFO_end_file
:
22277 if (!vec_safe_is_empty (files
))
22280 case DW_MACINFO_define
:
22281 case DW_MACINFO_undef
:
22283 && HAVE_COMDAT_GROUP
22284 && vec_safe_length (files
) != 1
22287 && (*macinfo_table
)[i
- 1].code
== 0)
22289 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
22298 /* A dummy entry may be inserted at the beginning to be able
22299 to optimize the whole block of predefined macros. */
22305 output_macinfo_op (ref
);
22313 delete macinfo_htab
;
22314 macinfo_htab
= NULL
;
22316 /* If any DW_MACRO_GNU_transparent_include were used, on those
22317 DW_MACRO_GNU_transparent_include entries terminate the
22318 current chain and switch to a new comdat .debug_macinfo
22319 section and emit the define/undef entries within it. */
22320 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
22325 case DW_MACRO_GNU_transparent_include
:
22327 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22328 tree comdat_key
= get_identifier (ref
->info
);
22329 /* Terminate the previous .debug_macinfo section. */
22330 dw2_asm_output_data (1, 0, "End compilation unit");
22331 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
22333 | SECTION_LINKONCE
,
22335 ASM_GENERATE_INTERNAL_LABEL (label
,
22336 DEBUG_MACRO_SECTION_LABEL
,
22338 ASM_OUTPUT_LABEL (asm_out_file
, label
);
22341 dw2_asm_output_data (2, 4, "DWARF macro version number");
22342 if (DWARF_OFFSET_SIZE
== 8)
22343 dw2_asm_output_data (1, 1, "Flags: 64-bit");
22345 dw2_asm_output_data (1, 0, "Flags: 32-bit");
22348 case DW_MACINFO_define
:
22349 case DW_MACINFO_undef
:
22350 output_macinfo_op (ref
);
22355 gcc_unreachable ();
22359 /* Set up for Dwarf output at the start of compilation. */
22362 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
22364 /* Allocate the file_table. */
22365 file_table
= hash_table
<dwarf_file_hasher
>::create_ggc (50);
22367 /* Allocate the decl_die_table. */
22368 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (10);
22370 /* Allocate the decl_loc_table. */
22371 decl_loc_table
= hash_table
<decl_loc_hasher
>::create_ggc (10);
22373 /* Allocate the cached_dw_loc_list_table. */
22374 cached_dw_loc_list_table
= hash_table
<dw_loc_list_hasher
>::create_ggc (10);
22376 /* Allocate the initial hunk of the decl_scope_table. */
22377 vec_alloc (decl_scope_table
, 256);
22379 /* Allocate the initial hunk of the abbrev_die_table. */
22380 abbrev_die_table
= ggc_cleared_vec_alloc
<dw_die_ref
>
22381 (ABBREV_DIE_TABLE_INCREMENT
);
22382 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
22383 /* Zero-th entry is allocated, but unused. */
22384 abbrev_die_table_in_use
= 1;
22386 /* Allocate the pubtypes and pubnames vectors. */
22387 vec_alloc (pubname_table
, 32);
22388 vec_alloc (pubtype_table
, 32);
22390 vec_alloc (incomplete_types
, 64);
22392 vec_alloc (used_rtx_array
, 32);
22394 if (!dwarf_split_debug_info
)
22396 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
22397 SECTION_DEBUG
, NULL
);
22398 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
22399 SECTION_DEBUG
, NULL
);
22400 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
22401 SECTION_DEBUG
, NULL
);
22405 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
22406 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22407 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
22408 SECTION_DEBUG
| SECTION_EXCLUDE
,
22410 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
22411 SECTION_DEBUG
, NULL
);
22412 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
22413 SECTION_DEBUG
, NULL
);
22414 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
22415 SECTION_DEBUG
, NULL
);
22416 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
22417 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
22419 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
22420 the main .o, but the skeleton_line goes into the split off dwo. */
22421 debug_skeleton_line_section
22422 = get_section (DEBUG_DWO_LINE_SECTION
,
22423 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22424 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
22425 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
22426 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
22427 SECTION_DEBUG
| SECTION_EXCLUDE
,
22429 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
22430 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
22431 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
22432 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22433 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
22434 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
22436 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
22437 SECTION_DEBUG
, NULL
);
22438 debug_macinfo_section
= get_section (dwarf_strict
22439 ? DEBUG_MACINFO_SECTION
22440 : DEBUG_MACRO_SECTION
,
22441 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
22442 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
22443 SECTION_DEBUG
, NULL
);
22444 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
22445 SECTION_DEBUG
, NULL
);
22446 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
22447 SECTION_DEBUG
, NULL
);
22448 debug_str_section
= get_section (DEBUG_STR_SECTION
,
22449 DEBUG_STR_SECTION_FLAGS
, NULL
);
22450 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
22451 SECTION_DEBUG
, NULL
);
22452 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
22453 SECTION_DEBUG
, NULL
);
22455 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
22456 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
22457 DEBUG_ABBREV_SECTION_LABEL
, 0);
22458 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
22459 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
22460 COLD_TEXT_SECTION_LABEL
, 0);
22461 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
22463 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
22464 DEBUG_INFO_SECTION_LABEL
, 0);
22465 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
22466 DEBUG_LINE_SECTION_LABEL
, 0);
22467 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
22468 DEBUG_RANGES_SECTION_LABEL
, 0);
22469 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
22470 DEBUG_ADDR_SECTION_LABEL
, 0);
22471 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
22473 ? DEBUG_MACINFO_SECTION_LABEL
22474 : DEBUG_MACRO_SECTION_LABEL
, 0);
22475 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
22477 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22478 vec_alloc (macinfo_table
, 64);
22480 switch_to_section (text_section
);
22481 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
22483 /* Make sure the line number table for .text always exists. */
22484 text_section_line_info
= new_line_info_table ();
22485 text_section_line_info
->end_label
= text_end_label
;
22488 /* Called before compile () starts outputtting functions, variables
22489 and toplevel asms into assembly. */
22492 dwarf2out_assembly_start (void)
22494 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
22495 && dwarf2out_do_cfi_asm ()
22496 && (!(flag_unwind_tables
|| flag_exceptions
)
22497 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
22498 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
22501 /* A helper function for dwarf2out_finish called through
22502 htab_traverse. Assign a string its index. All strings must be
22503 collected into the table by the time index_string is called,
22504 because the indexing code relies on htab_traverse to traverse nodes
22505 in the same order for each run. */
22508 index_string (indirect_string_node
**h
, unsigned int *index
)
22510 indirect_string_node
*node
= *h
;
22512 find_string_form (node
);
22513 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22515 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
22516 node
->index
= *index
;
22522 /* A helper function for output_indirect_strings called through
22523 htab_traverse. Output the offset to a string and update the
22527 output_index_string_offset (indirect_string_node
**h
, unsigned int *offset
)
22529 indirect_string_node
*node
= *h
;
22531 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22533 /* Assert that this node has been assigned an index. */
22534 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
22535 && node
->index
!= NOT_INDEXED
);
22536 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
22537 "indexed string 0x%x: %s", node
->index
, node
->str
);
22538 *offset
+= strlen (node
->str
) + 1;
22543 /* A helper function for dwarf2out_finish called through
22544 htab_traverse. Output the indexed string. */
22547 output_index_string (indirect_string_node
**h
, unsigned int *cur_idx
)
22549 struct indirect_string_node
*node
= *h
;
22551 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22553 /* Assert that the strings are output in the same order as their
22554 indexes were assigned. */
22555 gcc_assert (*cur_idx
== node
->index
);
22556 assemble_string (node
->str
, strlen (node
->str
) + 1);
22562 /* A helper function for dwarf2out_finish called through
22563 htab_traverse. Emit one queued .debug_str string. */
22566 output_indirect_string (indirect_string_node
**h
, void *)
22568 struct indirect_string_node
*node
= *h
;
22570 node
->form
= find_string_form (node
);
22571 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
22573 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
22574 assemble_string (node
->str
, strlen (node
->str
) + 1);
22580 /* Output the indexed string table. */
22583 output_indirect_strings (void)
22585 switch_to_section (debug_str_section
);
22586 if (!dwarf_split_debug_info
)
22587 debug_str_hash
->traverse
<void *, output_indirect_string
> (NULL
);
22590 unsigned int offset
= 0;
22591 unsigned int cur_idx
= 0;
22593 skeleton_debug_str_hash
->traverse
<void *, output_indirect_string
> (NULL
);
22595 switch_to_section (debug_str_offsets_section
);
22596 debug_str_hash
->traverse_noresize
22597 <unsigned int *, output_index_string_offset
> (&offset
);
22598 switch_to_section (debug_str_dwo_section
);
22599 debug_str_hash
->traverse_noresize
<unsigned int *, output_index_string
>
22604 /* Callback for htab_traverse to assign an index to an entry in the
22605 table, and to write that entry to the .debug_addr section. */
22608 output_addr_table_entry (addr_table_entry
**slot
, unsigned int *cur_index
)
22610 addr_table_entry
*entry
= *slot
;
22612 if (entry
->refcount
== 0)
22614 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
22615 || entry
->index
== NOT_INDEXED
);
22619 gcc_assert (entry
->index
== *cur_index
);
22622 switch (entry
->kind
)
22625 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
22626 "0x%x", entry
->index
);
22628 case ate_kind_rtx_dtprel
:
22629 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
22630 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
22633 fputc ('\n', asm_out_file
);
22635 case ate_kind_label
:
22636 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
22637 "0x%x", entry
->index
);
22640 gcc_unreachable ();
22645 /* Produce the .debug_addr section. */
22648 output_addr_table (void)
22650 unsigned int index
= 0;
22651 if (addr_index_table
== NULL
|| addr_index_table
->size () == 0)
22654 switch_to_section (debug_addr_section
);
22656 ->traverse_noresize
<unsigned int *, output_addr_table_entry
> (&index
);
22659 #if ENABLE_ASSERT_CHECKING
22660 /* Verify that all marks are clear. */
22663 verify_marks_clear (dw_die_ref die
)
22667 gcc_assert (! die
->die_mark
);
22668 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
22670 #endif /* ENABLE_ASSERT_CHECKING */
22672 /* Clear the marks for a die and its children.
22673 Be cool if the mark isn't set. */
22676 prune_unmark_dies (dw_die_ref die
)
22682 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
22685 /* Given DIE that we're marking as used, find any other dies
22686 it references as attributes and mark them as used. */
22689 prune_unused_types_walk_attribs (dw_die_ref die
)
22694 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22696 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
22698 /* A reference to another DIE.
22699 Make sure that it will get emitted.
22700 If it was broken out into a comdat group, don't follow it. */
22701 if (! AT_ref (a
)->comdat_type_p
22702 || a
->dw_attr
== DW_AT_specification
)
22703 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
22705 /* Set the string's refcount to 0 so that prune_unused_types_mark
22706 accounts properly for it. */
22707 if (AT_class (a
) == dw_val_class_str
)
22708 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
22712 /* Mark the generic parameters and arguments children DIEs of DIE. */
22715 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
22719 if (die
== NULL
|| die
->die_child
== NULL
)
22721 c
= die
->die_child
;
22724 if (is_template_parameter (c
))
22725 prune_unused_types_mark (c
, 1);
22727 } while (c
&& c
!= die
->die_child
);
22730 /* Mark DIE as being used. If DOKIDS is true, then walk down
22731 to DIE's children. */
22734 prune_unused_types_mark (dw_die_ref die
, int dokids
)
22738 if (die
->die_mark
== 0)
22740 /* We haven't done this node yet. Mark it as used. */
22742 /* If this is the DIE of a generic type instantiation,
22743 mark the children DIEs that describe its generic parms and
22745 prune_unused_types_mark_generic_parms_dies (die
);
22747 /* We also have to mark its parents as used.
22748 (But we don't want to mark our parent's kids due to this,
22749 unless it is a class.) */
22750 if (die
->die_parent
)
22751 prune_unused_types_mark (die
->die_parent
,
22752 class_scope_p (die
->die_parent
));
22754 /* Mark any referenced nodes. */
22755 prune_unused_types_walk_attribs (die
);
22757 /* If this node is a specification,
22758 also mark the definition, if it exists. */
22759 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
22760 prune_unused_types_mark (die
->die_definition
, 1);
22763 if (dokids
&& die
->die_mark
!= 2)
22765 /* We need to walk the children, but haven't done so yet.
22766 Remember that we've walked the kids. */
22769 /* If this is an array type, we need to make sure our
22770 kids get marked, even if they're types. If we're
22771 breaking out types into comdat sections, do this
22772 for all type definitions. */
22773 if (die
->die_tag
== DW_TAG_array_type
22774 || (use_debug_types
22775 && is_type_die (die
) && ! is_declaration_die (die
)))
22776 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
22778 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22782 /* For local classes, look if any static member functions were emitted
22783 and if so, mark them. */
22786 prune_unused_types_walk_local_classes (dw_die_ref die
)
22790 if (die
->die_mark
== 2)
22793 switch (die
->die_tag
)
22795 case DW_TAG_structure_type
:
22796 case DW_TAG_union_type
:
22797 case DW_TAG_class_type
:
22800 case DW_TAG_subprogram
:
22801 if (!get_AT_flag (die
, DW_AT_declaration
)
22802 || die
->die_definition
!= NULL
)
22803 prune_unused_types_mark (die
, 1);
22810 /* Mark children. */
22811 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
22814 /* Walk the tree DIE and mark types that we actually use. */
22817 prune_unused_types_walk (dw_die_ref die
)
22821 /* Don't do anything if this node is already marked and
22822 children have been marked as well. */
22823 if (die
->die_mark
== 2)
22826 switch (die
->die_tag
)
22828 case DW_TAG_structure_type
:
22829 case DW_TAG_union_type
:
22830 case DW_TAG_class_type
:
22831 if (die
->die_perennial_p
)
22834 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
22835 if (c
->die_tag
== DW_TAG_subprogram
)
22838 /* Finding used static member functions inside of classes
22839 is needed just for local classes, because for other classes
22840 static member function DIEs with DW_AT_specification
22841 are emitted outside of the DW_TAG_*_type. If we ever change
22842 it, we'd need to call this even for non-local classes. */
22844 prune_unused_types_walk_local_classes (die
);
22846 /* It's a type node --- don't mark it. */
22849 case DW_TAG_const_type
:
22850 case DW_TAG_packed_type
:
22851 case DW_TAG_pointer_type
:
22852 case DW_TAG_reference_type
:
22853 case DW_TAG_rvalue_reference_type
:
22854 case DW_TAG_volatile_type
:
22855 case DW_TAG_typedef
:
22856 case DW_TAG_array_type
:
22857 case DW_TAG_interface_type
:
22858 case DW_TAG_friend
:
22859 case DW_TAG_variant_part
:
22860 case DW_TAG_enumeration_type
:
22861 case DW_TAG_subroutine_type
:
22862 case DW_TAG_string_type
:
22863 case DW_TAG_set_type
:
22864 case DW_TAG_subrange_type
:
22865 case DW_TAG_ptr_to_member_type
:
22866 case DW_TAG_file_type
:
22867 if (die
->die_perennial_p
)
22870 /* It's a type node --- don't mark it. */
22874 /* Mark everything else. */
22878 if (die
->die_mark
== 0)
22882 /* Now, mark any dies referenced from here. */
22883 prune_unused_types_walk_attribs (die
);
22888 /* Mark children. */
22889 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22892 /* Increment the string counts on strings referred to from DIE's
22896 prune_unused_types_update_strings (dw_die_ref die
)
22901 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22902 if (AT_class (a
) == dw_val_class_str
)
22904 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22906 /* Avoid unnecessarily putting strings that are used less than
22907 twice in the hash table. */
22909 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22911 indirect_string_node
**slot
22912 = debug_str_hash
->find_slot_with_hash (s
->str
,
22913 htab_hash_string (s
->str
),
22915 gcc_assert (*slot
== NULL
);
22921 /* Remove from the tree DIE any dies that aren't marked. */
22924 prune_unused_types_prune (dw_die_ref die
)
22928 gcc_assert (die
->die_mark
);
22929 prune_unused_types_update_strings (die
);
22931 if (! die
->die_child
)
22934 c
= die
->die_child
;
22936 dw_die_ref prev
= c
;
22937 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22938 if (c
== die
->die_child
)
22940 /* No marked children between 'prev' and the end of the list. */
22942 /* No marked children at all. */
22943 die
->die_child
= NULL
;
22946 prev
->die_sib
= c
->die_sib
;
22947 die
->die_child
= prev
;
22952 if (c
!= prev
->die_sib
)
22954 prune_unused_types_prune (c
);
22955 } while (c
!= die
->die_child
);
22958 /* Remove dies representing declarations that we never use. */
22961 prune_unused_types (void)
22964 limbo_die_node
*node
;
22965 comdat_type_node
*ctnode
;
22967 dw_die_ref base_type
;
22969 #if ENABLE_ASSERT_CHECKING
22970 /* All the marks should already be clear. */
22971 verify_marks_clear (comp_unit_die ());
22972 for (node
= limbo_die_list
; node
; node
= node
->next
)
22973 verify_marks_clear (node
->die
);
22974 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22975 verify_marks_clear (ctnode
->root_die
);
22976 #endif /* ENABLE_ASSERT_CHECKING */
22978 /* Mark types that are used in global variables. */
22979 premark_types_used_by_global_vars ();
22981 /* Set the mark on nodes that are actually used. */
22982 prune_unused_types_walk (comp_unit_die ());
22983 for (node
= limbo_die_list
; node
; node
= node
->next
)
22984 prune_unused_types_walk (node
->die
);
22985 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22987 prune_unused_types_walk (ctnode
->root_die
);
22988 prune_unused_types_mark (ctnode
->type_die
, 1);
22991 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
22992 are unusual in that they are pubnames that are the children of pubtypes.
22993 They should only be marked via their parent DW_TAG_enumeration_type die,
22994 not as roots in themselves. */
22995 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
22996 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
22997 prune_unused_types_mark (pub
->die
, 1);
22998 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22999 prune_unused_types_mark (base_type
, 1);
23001 if (debug_str_hash
)
23002 debug_str_hash
->empty ();
23003 if (skeleton_debug_str_hash
)
23004 skeleton_debug_str_hash
->empty ();
23005 prune_unused_types_prune (comp_unit_die ());
23006 for (node
= limbo_die_list
; node
; node
= node
->next
)
23007 prune_unused_types_prune (node
->die
);
23008 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23009 prune_unused_types_prune (ctnode
->root_die
);
23011 /* Leave the marks clear. */
23012 prune_unmark_dies (comp_unit_die ());
23013 for (node
= limbo_die_list
; node
; node
= node
->next
)
23014 prune_unmark_dies (node
->die
);
23015 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23016 prune_unmark_dies (ctnode
->root_die
);
23019 /* Set the parameter to true if there are any relative pathnames in
23022 file_table_relative_p (dwarf_file_data
**slot
, bool *p
)
23024 struct dwarf_file_data
*d
= *slot
;
23025 if (!IS_ABSOLUTE_PATH (d
->filename
))
23033 /* Helpers to manipulate hash table of comdat type units. */
23035 struct comdat_type_hasher
: typed_noop_remove
<comdat_type_node
>
23037 typedef comdat_type_node value_type
;
23038 typedef comdat_type_node compare_type
;
23039 static inline hashval_t
hash (const value_type
*);
23040 static inline bool equal (const value_type
*, const compare_type
*);
23044 comdat_type_hasher::hash (const value_type
*type_node
)
23047 memcpy (&h
, type_node
->signature
, sizeof (h
));
23052 comdat_type_hasher::equal (const value_type
*type_node_1
,
23053 const compare_type
*type_node_2
)
23055 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
23056 DWARF_TYPE_SIGNATURE_SIZE
));
23059 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
23060 to the location it would have been added, should we know its
23061 DECL_ASSEMBLER_NAME when we added other attributes. This will
23062 probably improve compactness of debug info, removing equivalent
23063 abbrevs, and hide any differences caused by deferring the
23064 computation of the assembler name, triggered by e.g. PCH. */
23067 move_linkage_attr (dw_die_ref die
)
23069 unsigned ix
= vec_safe_length (die
->die_attr
);
23070 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
23072 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
23073 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
23077 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
23079 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
23083 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
23085 die
->die_attr
->pop ();
23086 die
->die_attr
->quick_insert (ix
, linkage
);
23090 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
23091 referenced from typed stack ops and count how often they are used. */
23094 mark_base_types (dw_loc_descr_ref loc
)
23096 dw_die_ref base_type
= NULL
;
23098 for (; loc
; loc
= loc
->dw_loc_next
)
23100 switch (loc
->dw_loc_opc
)
23102 case DW_OP_GNU_regval_type
:
23103 case DW_OP_GNU_deref_type
:
23104 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
23106 case DW_OP_GNU_convert
:
23107 case DW_OP_GNU_reinterpret
:
23108 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
23111 case DW_OP_GNU_const_type
:
23112 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23114 case DW_OP_GNU_entry_value
:
23115 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
23120 gcc_assert (base_type
->die_parent
== comp_unit_die ());
23121 if (base_type
->die_mark
)
23122 base_type
->die_mark
++;
23125 base_types
.safe_push (base_type
);
23126 base_type
->die_mark
= 1;
23131 /* Comparison function for sorting marked base types. */
23134 base_type_cmp (const void *x
, const void *y
)
23136 dw_die_ref dx
= *(const dw_die_ref
*) x
;
23137 dw_die_ref dy
= *(const dw_die_ref
*) y
;
23138 unsigned int byte_size1
, byte_size2
;
23139 unsigned int encoding1
, encoding2
;
23140 if (dx
->die_mark
> dy
->die_mark
)
23142 if (dx
->die_mark
< dy
->die_mark
)
23144 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
23145 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
23146 if (byte_size1
< byte_size2
)
23148 if (byte_size1
> byte_size2
)
23150 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
23151 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
23152 if (encoding1
< encoding2
)
23154 if (encoding1
> encoding2
)
23159 /* Move base types marked by mark_base_types as early as possible
23160 in the CU, sorted by decreasing usage count both to make the
23161 uleb128 references as small as possible and to make sure they
23162 will have die_offset already computed by calc_die_sizes when
23163 sizes of typed stack loc ops is computed. */
23166 move_marked_base_types (void)
23169 dw_die_ref base_type
, die
, c
;
23171 if (base_types
.is_empty ())
23174 /* Sort by decreasing usage count, they will be added again in that
23176 base_types
.qsort (base_type_cmp
);
23177 die
= comp_unit_die ();
23178 c
= die
->die_child
;
23181 dw_die_ref prev
= c
;
23183 while (c
->die_mark
)
23185 remove_child_with_prev (c
, prev
);
23186 /* As base types got marked, there must be at least
23187 one node other than DW_TAG_base_type. */
23188 gcc_assert (c
!= c
->die_sib
);
23192 while (c
!= die
->die_child
);
23193 gcc_assert (die
->die_child
);
23194 c
= die
->die_child
;
23195 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
23197 base_type
->die_mark
= 0;
23198 base_type
->die_sib
= c
->die_sib
;
23199 c
->die_sib
= base_type
;
23204 /* Helper function for resolve_addr, attempt to resolve
23205 one CONST_STRING, return true if successful. Similarly verify that
23206 SYMBOL_REFs refer to variables emitted in the current CU. */
23209 resolve_one_addr (rtx
*addr
)
23213 if (GET_CODE (rtl
) == CONST_STRING
)
23215 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
23216 tree t
= build_string (len
, XSTR (rtl
, 0));
23217 tree tlen
= size_int (len
- 1);
23219 = build_array_type (char_type_node
, build_index_type (tlen
));
23220 rtl
= lookup_constant_def (t
);
23221 if (!rtl
|| !MEM_P (rtl
))
23223 rtl
= XEXP (rtl
, 0);
23224 if (GET_CODE (rtl
) == SYMBOL_REF
23225 && SYMBOL_REF_DECL (rtl
)
23226 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
23228 vec_safe_push (used_rtx_array
, rtl
);
23233 if (GET_CODE (rtl
) == SYMBOL_REF
23234 && SYMBOL_REF_DECL (rtl
))
23236 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
23238 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
23241 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
23245 if (GET_CODE (rtl
) == CONST
)
23247 subrtx_ptr_iterator::array_type array
;
23248 FOR_EACH_SUBRTX_PTR (iter
, array
, &XEXP (rtl
, 0), ALL
)
23249 if (!resolve_one_addr (*iter
))
23256 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
23257 if possible, and create DW_TAG_dwarf_procedure that can be referenced
23258 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
23261 string_cst_pool_decl (tree t
)
23263 rtx rtl
= output_constant_def (t
, 1);
23264 unsigned char *array
;
23265 dw_loc_descr_ref l
;
23270 if (!rtl
|| !MEM_P (rtl
))
23272 rtl
= XEXP (rtl
, 0);
23273 if (GET_CODE (rtl
) != SYMBOL_REF
23274 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
23277 decl
= SYMBOL_REF_DECL (rtl
);
23278 if (!lookup_decl_die (decl
))
23280 len
= TREE_STRING_LENGTH (t
);
23281 vec_safe_push (used_rtx_array
, rtl
);
23282 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
23283 array
= ggc_vec_alloc
<unsigned char> (len
);
23284 memcpy (array
, TREE_STRING_POINTER (t
), len
);
23285 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
23286 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
23287 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
23288 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
23289 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
23290 add_AT_loc (ref
, DW_AT_location
, l
);
23291 equate_decl_number_to_die (decl
, ref
);
23296 /* Helper function of resolve_addr_in_expr. LOC is
23297 a DW_OP_addr followed by DW_OP_stack_value, either at the start
23298 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
23299 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
23300 with DW_OP_GNU_implicit_pointer if possible
23301 and return true, if unsuccessful, return false. */
23304 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
23306 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
23307 HOST_WIDE_INT offset
= 0;
23308 dw_die_ref ref
= NULL
;
23311 if (GET_CODE (rtl
) == CONST
23312 && GET_CODE (XEXP (rtl
, 0)) == PLUS
23313 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
23315 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
23316 rtl
= XEXP (XEXP (rtl
, 0), 0);
23318 if (GET_CODE (rtl
) == CONST_STRING
)
23320 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
23321 tree t
= build_string (len
, XSTR (rtl
, 0));
23322 tree tlen
= size_int (len
- 1);
23325 = build_array_type (char_type_node
, build_index_type (tlen
));
23326 rtl
= string_cst_pool_decl (t
);
23330 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
23332 decl
= SYMBOL_REF_DECL (rtl
);
23333 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
23335 ref
= lookup_decl_die (decl
);
23336 if (ref
&& (get_AT (ref
, DW_AT_location
)
23337 || get_AT (ref
, DW_AT_const_value
)))
23339 loc
->dw_loc_opc
= DW_OP_GNU_implicit_pointer
;
23340 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23341 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
23342 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23343 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23344 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
23345 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
23353 /* Helper function for resolve_addr, handle one location
23354 expression, return false if at least one CONST_STRING or SYMBOL_REF in
23355 the location list couldn't be resolved. */
23358 resolve_addr_in_expr (dw_loc_descr_ref loc
)
23360 dw_loc_descr_ref keep
= NULL
;
23361 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
23362 switch (loc
->dw_loc_opc
)
23365 if (!resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
23368 || prev
->dw_loc_opc
== DW_OP_piece
23369 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
23370 && loc
->dw_loc_next
23371 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
23373 && optimize_one_addr_into_implicit_ptr (loc
))
23378 case DW_OP_GNU_addr_index
:
23379 case DW_OP_GNU_const_index
:
23380 if (loc
->dw_loc_opc
== DW_OP_GNU_addr_index
23381 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
23383 rtx rtl
= loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
;
23384 if (!resolve_one_addr (&rtl
))
23386 remove_addr_table_entry (loc
->dw_loc_oprnd1
.val_entry
);
23387 loc
->dw_loc_oprnd1
.val_entry
=
23388 add_addr_table_entry (rtl
, ate_kind_rtx
);
23391 case DW_OP_const4u
:
23392 case DW_OP_const8u
:
23394 && !resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
23397 case DW_OP_plus_uconst
:
23398 if (size_of_loc_descr (loc
)
23399 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
23401 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
23403 dw_loc_descr_ref repl
23404 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
23405 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
23406 add_loc_descr (&repl
, loc
->dw_loc_next
);
23410 case DW_OP_implicit_value
:
23411 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
23412 && !resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
))
23415 case DW_OP_GNU_implicit_pointer
:
23416 case DW_OP_GNU_parameter_ref
:
23417 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
23420 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
23423 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23424 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23425 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23428 case DW_OP_GNU_const_type
:
23429 case DW_OP_GNU_regval_type
:
23430 case DW_OP_GNU_deref_type
:
23431 case DW_OP_GNU_convert
:
23432 case DW_OP_GNU_reinterpret
:
23433 while (loc
->dw_loc_next
23434 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
23436 dw_die_ref base1
, base2
;
23437 unsigned enc1
, enc2
, size1
, size2
;
23438 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
23439 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
23440 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
23441 else if (loc
->dw_loc_oprnd1
.val_class
23442 == dw_val_class_unsigned_const
)
23445 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23446 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
23447 == dw_val_class_unsigned_const
)
23449 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23450 gcc_assert (base1
->die_tag
== DW_TAG_base_type
23451 && base2
->die_tag
== DW_TAG_base_type
);
23452 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
23453 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
23454 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
23455 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
23457 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
23458 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
23462 /* Optimize away next DW_OP_GNU_convert after
23463 adjusting LOC's base type die reference. */
23464 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
23465 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
23466 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
23468 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
23469 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
23472 /* Don't change integer DW_OP_GNU_convert after e.g. floating
23473 point typed stack entry. */
23474 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
23475 keep
= loc
->dw_loc_next
;
23485 /* Helper function of resolve_addr. DIE had DW_AT_location of
23486 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
23487 and DW_OP_addr couldn't be resolved. resolve_addr has already
23488 removed the DW_AT_location attribute. This function attempts to
23489 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
23490 to it or DW_AT_const_value attribute, if possible. */
23493 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
23495 if (TREE_CODE (decl
) != VAR_DECL
23496 || lookup_decl_die (decl
) != die
23497 || DECL_EXTERNAL (decl
)
23498 || !TREE_STATIC (decl
)
23499 || DECL_INITIAL (decl
) == NULL_TREE
23500 || DECL_P (DECL_INITIAL (decl
))
23501 || get_AT (die
, DW_AT_const_value
))
23504 tree init
= DECL_INITIAL (decl
);
23505 HOST_WIDE_INT offset
= 0;
23506 /* For variables that have been optimized away and thus
23507 don't have a memory location, see if we can emit
23508 DW_AT_const_value instead. */
23509 if (tree_add_const_value_attribute (die
, init
))
23513 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
23514 and ADDR_EXPR refers to a decl that has DW_AT_location or
23515 DW_AT_const_value (but isn't addressable, otherwise
23516 resolving the original DW_OP_addr wouldn't fail), see if
23517 we can add DW_OP_GNU_implicit_pointer. */
23519 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
23520 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
23522 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
23523 init
= TREE_OPERAND (init
, 0);
23526 if (TREE_CODE (init
) != ADDR_EXPR
)
23528 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
23529 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
23530 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
23531 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
23532 && TREE_OPERAND (init
, 0) != decl
))
23535 dw_loc_descr_ref l
;
23537 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
23539 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
23542 decl
= SYMBOL_REF_DECL (rtl
);
23545 decl
= TREE_OPERAND (init
, 0);
23546 ref
= lookup_decl_die (decl
);
23548 || (!get_AT (ref
, DW_AT_location
)
23549 && !get_AT (ref
, DW_AT_const_value
)))
23551 l
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
23552 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23553 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23554 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23555 add_AT_loc (die
, DW_AT_location
, l
);
23559 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
23560 an address in .rodata section if the string literal is emitted there,
23561 or remove the containing location list or replace DW_AT_const_value
23562 with DW_AT_location and empty location expression, if it isn't found
23563 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
23564 to something that has been emitted in the current CU. */
23567 resolve_addr (dw_die_ref die
)
23571 dw_loc_list_ref
*curr
, *start
, loc
;
23574 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23575 switch (AT_class (a
))
23577 case dw_val_class_loc_list
:
23578 start
= curr
= AT_loc_list_ptr (a
);
23581 /* The same list can be referenced more than once. See if we have
23582 already recorded the result from a previous pass. */
23584 *curr
= loc
->dw_loc_next
;
23585 else if (!loc
->resolved_addr
)
23587 /* As things stand, we do not expect or allow one die to
23588 reference a suffix of another die's location list chain.
23589 References must be identical or completely separate.
23590 There is therefore no need to cache the result of this
23591 pass on any list other than the first; doing so
23592 would lead to unnecessary writes. */
23595 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
23596 if (!resolve_addr_in_expr ((*curr
)->expr
))
23598 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
23599 dw_loc_descr_ref l
= (*curr
)->expr
;
23601 if (next
&& (*curr
)->ll_symbol
)
23603 gcc_assert (!next
->ll_symbol
);
23604 next
->ll_symbol
= (*curr
)->ll_symbol
;
23606 if (dwarf_split_debug_info
)
23607 remove_loc_list_addr_table_entries (l
);
23612 mark_base_types ((*curr
)->expr
);
23613 curr
= &(*curr
)->dw_loc_next
;
23617 loc
->resolved_addr
= 1;
23621 loc
->dw_loc_next
= *start
;
23626 remove_AT (die
, a
->dw_attr
);
23630 case dw_val_class_loc
:
23632 dw_loc_descr_ref l
= AT_loc (a
);
23633 /* For -gdwarf-2 don't attempt to optimize
23634 DW_AT_data_member_location containing
23635 DW_OP_plus_uconst - older consumers might
23636 rely on it being that op instead of a more complex,
23637 but shorter, location description. */
23638 if ((dwarf_version
> 2
23639 || a
->dw_attr
!= DW_AT_data_member_location
23641 || l
->dw_loc_opc
!= DW_OP_plus_uconst
23642 || l
->dw_loc_next
!= NULL
)
23643 && !resolve_addr_in_expr (l
))
23645 if (dwarf_split_debug_info
)
23646 remove_loc_list_addr_table_entries (l
);
23648 && l
->dw_loc_next
== NULL
23649 && l
->dw_loc_opc
== DW_OP_addr
23650 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
23651 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
23652 && a
->dw_attr
== DW_AT_location
)
23654 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
23655 remove_AT (die
, a
->dw_attr
);
23657 optimize_location_into_implicit_ptr (die
, decl
);
23660 remove_AT (die
, a
->dw_attr
);
23664 mark_base_types (l
);
23667 case dw_val_class_addr
:
23668 if (a
->dw_attr
== DW_AT_const_value
23669 && !resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
))
23671 if (AT_index (a
) != NOT_INDEXED
)
23672 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23673 remove_AT (die
, a
->dw_attr
);
23676 if (die
->die_tag
== DW_TAG_GNU_call_site
23677 && a
->dw_attr
== DW_AT_abstract_origin
)
23679 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
23680 dw_die_ref tdie
= lookup_decl_die (tdecl
);
23682 && DECL_EXTERNAL (tdecl
)
23683 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
23685 force_decl_die (tdecl
);
23686 tdie
= lookup_decl_die (tdecl
);
23690 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
23691 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
23692 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
23696 if (AT_index (a
) != NOT_INDEXED
)
23697 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23698 remove_AT (die
, a
->dw_attr
);
23707 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
23710 /* Helper routines for optimize_location_lists.
23711 This pass tries to share identical local lists in .debug_loc
23714 /* Iteratively hash operands of LOC opcode into HSTATE. */
23717 hash_loc_operands (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
23719 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
23720 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
23722 switch (loc
->dw_loc_opc
)
23724 case DW_OP_const4u
:
23725 case DW_OP_const8u
:
23729 case DW_OP_const1u
:
23730 case DW_OP_const1s
:
23731 case DW_OP_const2u
:
23732 case DW_OP_const2s
:
23733 case DW_OP_const4s
:
23734 case DW_OP_const8s
:
23738 case DW_OP_plus_uconst
:
23774 case DW_OP_deref_size
:
23775 case DW_OP_xderef_size
:
23776 hstate
.add_object (val1
->v
.val_int
);
23783 gcc_assert (val1
->val_class
== dw_val_class_loc
);
23784 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
23785 hstate
.add_object (offset
);
23788 case DW_OP_implicit_value
:
23789 hstate
.add_object (val1
->v
.val_unsigned
);
23790 switch (val2
->val_class
)
23792 case dw_val_class_const
:
23793 hstate
.add_object (val2
->v
.val_int
);
23795 case dw_val_class_vec
:
23797 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23798 unsigned int len
= val2
->v
.val_vec
.length
;
23800 hstate
.add_int (elt_size
);
23801 hstate
.add_int (len
);
23802 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
23805 case dw_val_class_const_double
:
23806 hstate
.add_object (val2
->v
.val_double
.low
);
23807 hstate
.add_object (val2
->v
.val_double
.high
);
23809 case dw_val_class_wide_int
:
23810 hstate
.add_object (*val2
->v
.val_wide
);
23812 case dw_val_class_addr
:
23813 inchash::add_rtx (val2
->v
.val_addr
, hstate
);
23816 gcc_unreachable ();
23820 case DW_OP_bit_piece
:
23821 hstate
.add_object (val1
->v
.val_int
);
23822 hstate
.add_object (val2
->v
.val_int
);
23828 unsigned char dtprel
= 0xd1;
23829 hstate
.add_object (dtprel
);
23831 inchash::add_rtx (val1
->v
.val_addr
, hstate
);
23833 case DW_OP_GNU_addr_index
:
23834 case DW_OP_GNU_const_index
:
23838 unsigned char dtprel
= 0xd1;
23839 hstate
.add_object (dtprel
);
23841 inchash::add_rtx (val1
->val_entry
->addr
.rtl
, hstate
);
23844 case DW_OP_GNU_implicit_pointer
:
23845 hstate
.add_int (val2
->v
.val_int
);
23847 case DW_OP_GNU_entry_value
:
23848 hstate
.add_object (val1
->v
.val_loc
);
23850 case DW_OP_GNU_regval_type
:
23851 case DW_OP_GNU_deref_type
:
23853 unsigned int byte_size
23854 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23855 unsigned int encoding
23856 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
23857 hstate
.add_object (val1
->v
.val_int
);
23858 hstate
.add_object (byte_size
);
23859 hstate
.add_object (encoding
);
23862 case DW_OP_GNU_convert
:
23863 case DW_OP_GNU_reinterpret
:
23864 if (val1
->val_class
== dw_val_class_unsigned_const
)
23866 hstate
.add_object (val1
->v
.val_unsigned
);
23870 case DW_OP_GNU_const_type
:
23872 unsigned int byte_size
23873 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23874 unsigned int encoding
23875 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
23876 hstate
.add_object (byte_size
);
23877 hstate
.add_object (encoding
);
23878 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
23880 hstate
.add_object (val2
->val_class
);
23881 switch (val2
->val_class
)
23883 case dw_val_class_const
:
23884 hstate
.add_object (val2
->v
.val_int
);
23886 case dw_val_class_vec
:
23888 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23889 unsigned int len
= val2
->v
.val_vec
.length
;
23891 hstate
.add_object (elt_size
);
23892 hstate
.add_object (len
);
23893 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
23896 case dw_val_class_const_double
:
23897 hstate
.add_object (val2
->v
.val_double
.low
);
23898 hstate
.add_object (val2
->v
.val_double
.high
);
23900 case dw_val_class_wide_int
:
23901 hstate
.add_object (*val2
->v
.val_wide
);
23904 gcc_unreachable ();
23910 /* Other codes have no operands. */
23915 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
23918 hash_locs (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
23920 dw_loc_descr_ref l
;
23921 bool sizes_computed
= false;
23922 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23923 size_of_locs (loc
);
23925 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
23927 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
23928 hstate
.add_object (opc
);
23929 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
23931 size_of_locs (loc
);
23932 sizes_computed
= true;
23934 hash_loc_operands (l
, hstate
);
23938 /* Compute hash of the whole location list LIST_HEAD. */
23941 hash_loc_list (dw_loc_list_ref list_head
)
23943 dw_loc_list_ref curr
= list_head
;
23944 inchash::hash hstate
;
23946 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23948 hstate
.add (curr
->begin
, strlen (curr
->begin
) + 1);
23949 hstate
.add (curr
->end
, strlen (curr
->end
) + 1);
23951 hstate
.add (curr
->section
, strlen (curr
->section
) + 1);
23952 hash_locs (curr
->expr
, hstate
);
23954 list_head
->hash
= hstate
.end ();
23957 /* Return true if X and Y opcodes have the same operands. */
23960 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23962 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
23963 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
23964 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
23965 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
23967 switch (x
->dw_loc_opc
)
23969 case DW_OP_const4u
:
23970 case DW_OP_const8u
:
23974 case DW_OP_const1u
:
23975 case DW_OP_const1s
:
23976 case DW_OP_const2u
:
23977 case DW_OP_const2s
:
23978 case DW_OP_const4s
:
23979 case DW_OP_const8s
:
23983 case DW_OP_plus_uconst
:
24019 case DW_OP_deref_size
:
24020 case DW_OP_xderef_size
:
24021 return valx1
->v
.val_int
== valy1
->v
.val_int
;
24024 /* If splitting debug info, the use of DW_OP_GNU_addr_index
24025 can cause irrelevant differences in dw_loc_addr. */
24026 gcc_assert (valx1
->val_class
== dw_val_class_loc
24027 && valy1
->val_class
== dw_val_class_loc
24028 && (dwarf_split_debug_info
24029 || x
->dw_loc_addr
== y
->dw_loc_addr
));
24030 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
24031 case DW_OP_implicit_value
:
24032 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
24033 || valx2
->val_class
!= valy2
->val_class
)
24035 switch (valx2
->val_class
)
24037 case dw_val_class_const
:
24038 return valx2
->v
.val_int
== valy2
->v
.val_int
;
24039 case dw_val_class_vec
:
24040 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
24041 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
24042 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
24043 valx2
->v
.val_vec
.elt_size
24044 * valx2
->v
.val_vec
.length
) == 0;
24045 case dw_val_class_const_double
:
24046 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
24047 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
24048 case dw_val_class_wide_int
:
24049 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
24050 case dw_val_class_addr
:
24051 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
24053 gcc_unreachable ();
24056 case DW_OP_bit_piece
:
24057 return valx1
->v
.val_int
== valy1
->v
.val_int
24058 && valx2
->v
.val_int
== valy2
->v
.val_int
;
24061 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
24062 case DW_OP_GNU_addr_index
:
24063 case DW_OP_GNU_const_index
:
24065 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
24066 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
24067 return rtx_equal_p (ax1
, ay1
);
24069 case DW_OP_GNU_implicit_pointer
:
24070 return valx1
->val_class
== dw_val_class_die_ref
24071 && valx1
->val_class
== valy1
->val_class
24072 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
24073 && valx2
->v
.val_int
== valy2
->v
.val_int
;
24074 case DW_OP_GNU_entry_value
:
24075 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
24076 case DW_OP_GNU_const_type
:
24077 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
24078 || valx2
->val_class
!= valy2
->val_class
)
24080 switch (valx2
->val_class
)
24082 case dw_val_class_const
:
24083 return valx2
->v
.val_int
== valy2
->v
.val_int
;
24084 case dw_val_class_vec
:
24085 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
24086 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
24087 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
24088 valx2
->v
.val_vec
.elt_size
24089 * valx2
->v
.val_vec
.length
) == 0;
24090 case dw_val_class_const_double
:
24091 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
24092 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
24093 case dw_val_class_wide_int
:
24094 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
24096 gcc_unreachable ();
24098 case DW_OP_GNU_regval_type
:
24099 case DW_OP_GNU_deref_type
:
24100 return valx1
->v
.val_int
== valy1
->v
.val_int
24101 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
24102 case DW_OP_GNU_convert
:
24103 case DW_OP_GNU_reinterpret
:
24104 if (valx1
->val_class
!= valy1
->val_class
)
24106 if (valx1
->val_class
== dw_val_class_unsigned_const
)
24107 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
24108 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
24109 case DW_OP_GNU_parameter_ref
:
24110 return valx1
->val_class
== dw_val_class_die_ref
24111 && valx1
->val_class
== valy1
->val_class
24112 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
24114 /* Other codes have no operands. */
24119 /* Return true if DWARF location expressions X and Y are the same. */
24122 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
24124 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
24125 if (x
->dw_loc_opc
!= y
->dw_loc_opc
24126 || x
->dtprel
!= y
->dtprel
24127 || !compare_loc_operands (x
, y
))
24129 return x
== NULL
&& y
== NULL
;
24132 /* Hashtable helpers. */
24134 struct loc_list_hasher
: typed_noop_remove
<dw_loc_list_struct
>
24136 typedef dw_loc_list_struct value_type
;
24137 typedef dw_loc_list_struct compare_type
;
24138 static inline hashval_t
hash (const value_type
*);
24139 static inline bool equal (const value_type
*, const compare_type
*);
24142 /* Return precomputed hash of location list X. */
24145 loc_list_hasher::hash (const value_type
*x
)
24150 /* Return true if location lists A and B are the same. */
24153 loc_list_hasher::equal (const value_type
*a
, const compare_type
*b
)
24157 if (a
->hash
!= b
->hash
)
24159 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
24160 if (strcmp (a
->begin
, b
->begin
) != 0
24161 || strcmp (a
->end
, b
->end
) != 0
24162 || (a
->section
== NULL
) != (b
->section
== NULL
)
24163 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
24164 || !compare_locs (a
->expr
, b
->expr
))
24166 return a
== NULL
&& b
== NULL
;
24169 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
24172 /* Recursively optimize location lists referenced from DIE
24173 children and share them whenever possible. */
24176 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type
*htab
)
24181 dw_loc_list_struct
**slot
;
24183 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
24184 if (AT_class (a
) == dw_val_class_loc_list
)
24186 dw_loc_list_ref list
= AT_loc_list (a
);
24187 /* TODO: perform some optimizations here, before hashing
24188 it and storing into the hash table. */
24189 hash_loc_list (list
);
24190 slot
= htab
->find_slot_with_hash (list
, list
->hash
, INSERT
);
24194 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
24197 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
24201 /* Recursively assign each location list a unique index into the debug_addr
24205 index_location_lists (dw_die_ref die
)
24211 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
24212 if (AT_class (a
) == dw_val_class_loc_list
)
24214 dw_loc_list_ref list
= AT_loc_list (a
);
24215 dw_loc_list_ref curr
;
24216 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
24218 /* Don't index an entry that has already been indexed
24219 or won't be output. */
24220 if (curr
->begin_entry
!= NULL
24221 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
24225 = add_addr_table_entry (xstrdup (curr
->begin
),
24230 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
24233 /* Optimize location lists referenced from DIE
24234 children and share them whenever possible. */
24237 optimize_location_lists (dw_die_ref die
)
24239 loc_list_hash_type
htab (500);
24240 optimize_location_lists_1 (die
, &htab
);
24243 /* Output stuff that dwarf requires at the end of every file,
24244 and generate the DWARF-2 debugging info. */
24247 dwarf2out_finish (const char *filename
)
24249 limbo_die_node
*node
, *next_node
;
24250 comdat_type_node
*ctnode
;
24252 dw_die_ref main_comp_unit_die
;
24254 /* PCH might result in DW_AT_producer string being restored from the
24255 header compilation, so always fill it with empty string initially
24256 and overwrite only here. */
24257 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
24258 producer_string
= gen_producer_string ();
24259 producer
->dw_attr_val
.v
.val_str
->refcount
--;
24260 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
24262 gen_scheduled_generic_parms_dies ();
24263 gen_remaining_tmpl_value_param_die_attribute ();
24265 /* Add the name for the main input file now. We delayed this from
24266 dwarf2out_init to avoid complications with PCH. */
24267 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
24268 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
24269 add_comp_dir_attribute (comp_unit_die ());
24270 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
24273 file_table
->traverse
<bool *, file_table_relative_p
> (&p
);
24275 add_comp_dir_attribute (comp_unit_die ());
24278 if (deferred_locations_list
)
24279 for (i
= 0; i
< deferred_locations_list
->length (); i
++)
24281 add_location_or_const_value_attribute (
24282 (*deferred_locations_list
)[i
].die
,
24283 (*deferred_locations_list
)[i
].variable
,
24288 /* Traverse the limbo die list, and add parent/child links. The only
24289 dies without parents that should be here are concrete instances of
24290 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
24291 For concrete instances, we can get the parent die from the abstract
24293 for (node
= limbo_die_list
; node
; node
= next_node
)
24295 dw_die_ref die
= node
->die
;
24296 next_node
= node
->next
;
24298 if (die
->die_parent
== NULL
)
24300 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
24302 if (origin
&& origin
->die_parent
)
24303 add_child_die (origin
->die_parent
, die
);
24304 else if (is_cu_die (die
))
24306 else if (seen_error ())
24307 /* It's OK to be confused by errors in the input. */
24308 add_child_die (comp_unit_die (), die
);
24311 /* In certain situations, the lexical block containing a
24312 nested function can be optimized away, which results
24313 in the nested function die being orphaned. Likewise
24314 with the return type of that nested function. Force
24315 this to be a child of the containing function.
24317 It may happen that even the containing function got fully
24318 inlined and optimized out. In that case we are lost and
24319 assign the empty child. This should not be big issue as
24320 the function is likely unreachable too. */
24321 gcc_assert (node
->created_for
);
24323 if (DECL_P (node
->created_for
))
24324 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
24325 else if (TYPE_P (node
->created_for
))
24326 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
24328 origin
= comp_unit_die ();
24330 add_child_die (origin
, die
);
24335 limbo_die_list
= NULL
;
24337 #if ENABLE_ASSERT_CHECKING
24339 dw_die_ref die
= comp_unit_die (), c
;
24340 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
24343 resolve_addr (comp_unit_die ());
24344 move_marked_base_types ();
24346 for (node
= deferred_asm_name
; node
; node
= node
->next
)
24348 tree decl
= node
->created_for
;
24349 /* When generating LTO bytecode we can not generate new assembler
24350 names at this point and all important decls got theirs via
24352 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
24353 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
24355 add_linkage_attr (node
->die
, decl
);
24356 move_linkage_attr (node
->die
);
24360 deferred_asm_name
= NULL
;
24362 /* Walk through the list of incomplete types again, trying once more to
24363 emit full debugging info for them. */
24364 retry_incomplete_types ();
24366 if (flag_eliminate_unused_debug_types
)
24367 prune_unused_types ();
24369 /* Generate separate COMDAT sections for type DIEs. */
24370 if (use_debug_types
)
24372 break_out_comdat_types (comp_unit_die ());
24374 /* Each new type_unit DIE was added to the limbo die list when created.
24375 Since these have all been added to comdat_type_list, clear the
24377 limbo_die_list
= NULL
;
24379 /* For each new comdat type unit, copy declarations for incomplete
24380 types to make the new unit self-contained (i.e., no direct
24381 references to the main compile unit). */
24382 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24383 copy_decls_for_unworthy_types (ctnode
->root_die
);
24384 copy_decls_for_unworthy_types (comp_unit_die ());
24386 /* In the process of copying declarations from one unit to another,
24387 we may have left some declarations behind that are no longer
24388 referenced. Prune them. */
24389 prune_unused_types ();
24392 /* Generate separate CUs for each of the include files we've seen.
24393 They will go into limbo_die_list. */
24394 if (flag_eliminate_dwarf2_dups
)
24395 break_out_includes (comp_unit_die ());
24397 /* Traverse the DIE's and add add sibling attributes to those DIE's
24398 that have children. */
24399 add_sibling_attributes (comp_unit_die ());
24400 for (node
= limbo_die_list
; node
; node
= node
->next
)
24401 add_sibling_attributes (node
->die
);
24402 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24403 add_sibling_attributes (ctnode
->root_die
);
24405 /* When splitting DWARF info, we put some attributes in the
24406 skeleton compile_unit DIE that remains in the .o, while
24407 most attributes go in the DWO compile_unit_die. */
24408 if (dwarf_split_debug_info
)
24409 main_comp_unit_die
= gen_compile_unit_die (NULL
);
24411 main_comp_unit_die
= comp_unit_die ();
24413 /* Output a terminator label for the .text section. */
24414 switch_to_section (text_section
);
24415 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
24416 if (cold_text_section
)
24418 switch_to_section (cold_text_section
);
24419 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
24422 /* We can only use the low/high_pc attributes if all of the code was
24424 if (!have_multiple_function_sections
24425 || (dwarf_version
< 3 && dwarf_strict
))
24427 /* Don't add if the CU has no associated code. */
24428 if (text_section_used
)
24429 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
24430 text_end_label
, true);
24436 bool range_list_added
= false;
24438 if (text_section_used
)
24439 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
24440 text_end_label
, &range_list_added
, true);
24441 if (cold_text_section_used
)
24442 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
24443 cold_end_label
, &range_list_added
, true);
24445 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
24447 if (DECL_IGNORED_P (fde
->decl
))
24449 if (!fde
->in_std_section
)
24450 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
24451 fde
->dw_fde_end
, &range_list_added
,
24453 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
24454 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
24455 fde
->dw_fde_second_end
, &range_list_added
,
24459 if (range_list_added
)
24461 /* We need to give .debug_loc and .debug_ranges an appropriate
24462 "base address". Use zero so that these addresses become
24463 absolute. Historically, we've emitted the unexpected
24464 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
24465 Emit both to give time for other tools to adapt. */
24466 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
24467 if (! dwarf_strict
&& dwarf_version
< 4)
24468 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
24474 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
24475 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
24476 debug_line_section_label
);
24479 add_AT_macptr (comp_unit_die (),
24480 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
24481 macinfo_section_label
);
24483 if (dwarf_split_debug_info
)
24485 /* optimize_location_lists calculates the size of the lists,
24486 so index them first, and assign indices to the entries.
24487 Although optimize_location_lists will remove entries from
24488 the table, it only does so for duplicates, and therefore
24489 only reduces ref_counts to 1. */
24490 index_location_lists (comp_unit_die ());
24492 if (addr_index_table
!= NULL
)
24494 unsigned int index
= 0;
24496 ->traverse_noresize
<unsigned int *, index_addr_table_entry
>
24501 if (have_location_lists
)
24502 optimize_location_lists (comp_unit_die ());
24504 save_macinfo_strings ();
24506 if (dwarf_split_debug_info
)
24508 unsigned int index
= 0;
24510 /* Add attributes common to skeleton compile_units and
24511 type_units. Because these attributes include strings, it
24512 must be done before freezing the string table. Top-level
24513 skeleton die attrs are added when the skeleton type unit is
24514 created, so ensure it is created by this point. */
24515 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
24516 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
24519 /* Output all of the compilation units. We put the main one last so that
24520 the offsets are available to output_pubnames. */
24521 for (node
= limbo_die_list
; node
; node
= node
->next
)
24522 output_comp_unit (node
->die
, 0);
24524 hash_table
<comdat_type_hasher
> comdat_type_table (100);
24525 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24527 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
24529 /* Don't output duplicate types. */
24530 if (*slot
!= HTAB_EMPTY_ENTRY
)
24533 /* Add a pointer to the line table for the main compilation unit
24534 so that the debugger can make sense of DW_AT_decl_file
24536 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
24537 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
24538 (!dwarf_split_debug_info
24539 ? debug_line_section_label
24540 : debug_skeleton_line_section_label
));
24542 output_comdat_type_unit (ctnode
);
24546 /* The AT_pubnames attribute needs to go in all skeleton dies, including
24547 both the main_cu and all skeleton TUs. Making this call unconditional
24548 would end up either adding a second copy of the AT_pubnames attribute, or
24549 requiring a special case in add_top_level_skeleton_die_attrs. */
24550 if (!dwarf_split_debug_info
)
24551 add_AT_pubnames (comp_unit_die ());
24553 if (dwarf_split_debug_info
)
24556 unsigned char checksum
[16];
24557 struct md5_ctx ctx
;
24559 /* Compute a checksum of the comp_unit to use as the dwo_id. */
24560 md5_init_ctx (&ctx
);
24562 die_checksum (comp_unit_die (), &ctx
, &mark
);
24563 unmark_all_dies (comp_unit_die ());
24564 md5_finish_ctx (&ctx
, checksum
);
24566 /* Use the first 8 bytes of the checksum as the dwo_id,
24567 and add it to both comp-unit DIEs. */
24568 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
24569 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
24571 /* Add the base offset of the ranges table to the skeleton
24573 if (ranges_table_in_use
)
24574 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
24575 ranges_section_label
);
24577 switch_to_section (debug_addr_section
);
24578 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
24579 output_addr_table ();
24582 /* Output the main compilation unit if non-empty or if .debug_macinfo
24583 or .debug_macro will be emitted. */
24584 output_comp_unit (comp_unit_die (), have_macinfo
);
24586 if (dwarf_split_debug_info
&& info_section_emitted
)
24587 output_skeleton_debug_sections (main_comp_unit_die
);
24589 /* Output the abbreviation table. */
24590 if (abbrev_die_table_in_use
!= 1)
24592 switch_to_section (debug_abbrev_section
);
24593 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
24594 output_abbrev_section ();
24597 /* Output location list section if necessary. */
24598 if (have_location_lists
)
24600 /* Output the location lists info. */
24601 switch_to_section (debug_loc_section
);
24602 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
24603 output_location_lists (comp_unit_die ());
24606 output_pubtables ();
24608 /* Output the address range information if a CU (.debug_info section)
24609 was emitted. We output an empty table even if we had no functions
24610 to put in it. This because the consumer has no way to tell the
24611 difference between an empty table that we omitted and failure to
24612 generate a table that would have contained data. */
24613 if (info_section_emitted
)
24615 unsigned long aranges_length
= size_of_aranges ();
24617 switch_to_section (debug_aranges_section
);
24618 output_aranges (aranges_length
);
24621 /* Output ranges section if necessary. */
24622 if (ranges_table_in_use
)
24624 switch_to_section (debug_ranges_section
);
24625 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
24629 /* Have to end the macro section. */
24632 switch_to_section (debug_macinfo_section
);
24633 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
24635 dw2_asm_output_data (1, 0, "End compilation unit");
24638 /* Output the source line correspondence table. We must do this
24639 even if there is no line information. Otherwise, on an empty
24640 translation unit, we will generate a present, but empty,
24641 .debug_info section. IRIX 6.5 `nm' will then complain when
24642 examining the file. This is done late so that any filenames
24643 used by the debug_info section are marked as 'used'. */
24644 switch_to_section (debug_line_section
);
24645 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
24646 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
24647 output_line_info (false);
24649 if (dwarf_split_debug_info
&& info_section_emitted
)
24651 switch_to_section (debug_skeleton_line_section
);
24652 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
24653 output_line_info (true);
24656 /* If we emitted any indirect strings, output the string table too. */
24657 if (debug_str_hash
|| skeleton_debug_str_hash
)
24658 output_indirect_strings ();
24661 /* Reset all state within dwarf2out.c so that we can rerun the compiler
24662 within the same process. For use by toplev::finalize. */
24665 dwarf2out_c_finalize (void)
24667 last_var_location_insn
= NULL
;
24668 cached_next_real_insn
= NULL
;
24669 used_rtx_array
= NULL
;
24670 incomplete_types
= NULL
;
24671 decl_scope_table
= NULL
;
24672 debug_info_section
= NULL
;
24673 debug_skeleton_info_section
= NULL
;
24674 debug_abbrev_section
= NULL
;
24675 debug_skeleton_abbrev_section
= NULL
;
24676 debug_aranges_section
= NULL
;
24677 debug_addr_section
= NULL
;
24678 debug_macinfo_section
= NULL
;
24679 debug_line_section
= NULL
;
24680 debug_skeleton_line_section
= NULL
;
24681 debug_loc_section
= NULL
;
24682 debug_pubnames_section
= NULL
;
24683 debug_pubtypes_section
= NULL
;
24684 debug_str_section
= NULL
;
24685 debug_str_dwo_section
= NULL
;
24686 debug_str_offsets_section
= NULL
;
24687 debug_ranges_section
= NULL
;
24688 debug_frame_section
= NULL
;
24690 debug_str_hash
= NULL
;
24691 skeleton_debug_str_hash
= NULL
;
24692 dw2_string_counter
= 0;
24693 have_multiple_function_sections
= false;
24694 text_section_used
= false;
24695 cold_text_section_used
= false;
24696 cold_text_section
= NULL
;
24697 current_unit_personality
= NULL
;
24699 deferred_locations_list
= NULL
;
24701 next_die_offset
= 0;
24702 single_comp_unit_die
= NULL
;
24703 comdat_type_list
= NULL
;
24704 limbo_die_list
= NULL
;
24705 deferred_asm_name
= NULL
;
24707 decl_die_table
= NULL
;
24708 common_block_die_table
= NULL
;
24709 decl_loc_table
= NULL
;
24710 call_arg_locations
= NULL
;
24711 call_arg_loc_last
= NULL
;
24712 call_site_count
= -1;
24713 tail_call_site_count
= -1;
24714 //block_map = NULL;
24715 cached_dw_loc_list_table
= NULL
;
24716 abbrev_die_table
= NULL
;
24717 abbrev_die_table_allocated
= 0;
24718 abbrev_die_table_in_use
= 0;
24719 line_info_label_num
= 0;
24720 cur_line_info_table
= NULL
;
24721 text_section_line_info
= NULL
;
24722 cold_text_section_line_info
= NULL
;
24723 separate_line_info
= NULL
;
24724 info_section_emitted
= false;
24725 pubname_table
= NULL
;
24726 pubtype_table
= NULL
;
24727 macinfo_table
= NULL
;
24728 ranges_table
= NULL
;
24729 ranges_table_allocated
= 0;
24730 ranges_table_in_use
= 0;
24731 ranges_by_label
= 0;
24732 ranges_by_label_allocated
= 0;
24733 ranges_by_label_in_use
= 0;
24734 have_location_lists
= false;
24737 last_emitted_file
= NULL
;
24739 file_table_last_lookup
= NULL
;
24740 tmpl_value_parm_die_table
= NULL
;
24741 generic_type_instances
= NULL
;
24742 frame_pointer_fb_offset
= 0;
24743 frame_pointer_fb_offset_valid
= false;
24744 base_types
.release ();
24747 #include "gt-dwarf2out.h"