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"
69 #include "hash-table.h"
72 #include "hard-reg-set.h"
75 #include "insn-config.h"
82 #include "dwarf2out.h"
83 #include "dwarf2asm.h"
87 #include "diagnostic.h"
88 #include "tree-pretty-print.h"
91 #include "common/common-target.h"
92 #include "langhooks.h"
100 #include "gdb/gdb-index.h"
102 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
103 static rtx last_var_location_insn
;
104 static rtx cached_next_real_insn
;
106 #ifdef VMS_DEBUGGING_INFO
107 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
109 /* Define this macro to be a nonzero value if the directory specifications
110 which are output in the debug info should end with a separator. */
111 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
112 /* Define this macro to evaluate to a nonzero value if GCC should refrain
113 from generating indirect strings in DWARF2 debug information, for instance
114 if your target is stuck with an old version of GDB that is unable to
115 process them properly or uses VMS Debug. */
116 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
118 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
119 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
122 /* ??? Poison these here until it can be done generically. They've been
123 totally replaced in this file; make sure it stays that way. */
124 #undef DWARF2_UNWIND_INFO
125 #undef DWARF2_FRAME_INFO
126 #if (GCC_VERSION >= 3000)
127 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
130 /* The size of the target's pointer type. */
132 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
135 /* Array of RTXes referenced by the debugging information, which therefore
136 must be kept around forever. */
137 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
139 /* A pointer to the base of a list of incomplete types which might be
140 completed at some later time. incomplete_types_list needs to be a
141 vec<tree, va_gc> *because we want to tell the garbage collector about
143 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
145 /* A pointer to the base of a table of references to declaration
146 scopes. This table is a display which tracks the nesting
147 of declaration scopes at the current scope and containing
148 scopes. This table is used to find the proper place to
149 define type declaration DIE's. */
150 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
152 /* Pointers to various DWARF2 sections. */
153 static GTY(()) section
*debug_info_section
;
154 static GTY(()) section
*debug_skeleton_info_section
;
155 static GTY(()) section
*debug_abbrev_section
;
156 static GTY(()) section
*debug_skeleton_abbrev_section
;
157 static GTY(()) section
*debug_aranges_section
;
158 static GTY(()) section
*debug_addr_section
;
159 static GTY(()) section
*debug_macinfo_section
;
160 static GTY(()) section
*debug_line_section
;
161 static GTY(()) section
*debug_skeleton_line_section
;
162 static GTY(()) section
*debug_loc_section
;
163 static GTY(()) section
*debug_pubnames_section
;
164 static GTY(()) section
*debug_pubtypes_section
;
165 static GTY(()) section
*debug_str_section
;
166 static GTY(()) section
*debug_str_dwo_section
;
167 static GTY(()) section
*debug_str_offsets_section
;
168 static GTY(()) section
*debug_ranges_section
;
169 static GTY(()) section
*debug_frame_section
;
171 /* Maximum size (in bytes) of an artificially generated label. */
172 #define MAX_ARTIFICIAL_LABEL_BYTES 30
174 /* According to the (draft) DWARF 3 specification, the initial length
175 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
176 bytes are 0xffffffff, followed by the length stored in the next 8
179 However, the SGI/MIPS ABI uses an initial length which is equal to
180 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
182 #ifndef DWARF_INITIAL_LENGTH_SIZE
183 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
186 /* Round SIZE up to the nearest BOUNDARY. */
187 #define DWARF_ROUND(SIZE,BOUNDARY) \
188 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
190 /* CIE identifier. */
191 #if HOST_BITS_PER_WIDE_INT >= 64
192 #define DWARF_CIE_ID \
193 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
195 #define DWARF_CIE_ID DW_CIE_ID
199 /* A vector for a table that contains frame description
200 information for each routine. */
201 #define NOT_INDEXED (-1U)
202 #define NO_INDEX_ASSIGNED (-2U)
204 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
206 struct GTY(()) indirect_string_node
{
208 unsigned int refcount
;
209 enum dwarf_form form
;
214 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
216 /* With split_debug_info, both the comp_dir and dwo_name go in the
217 main object file, rather than the dwo, similar to the force_direct
218 parameter elsewhere but with additional complications:
220 1) The string is needed in both the main object file and the dwo.
221 That is, the comp_dir and dwo_name will appear in both places.
223 2) Strings can use three forms: DW_FORM_string, DW_FORM_strp or
224 DW_FORM_GNU_str_index.
226 3) GCC chooses the form to use late, depending on the size and
229 Rather than forcing the all debug string handling functions and
230 callers to deal with these complications, simply use a separate,
231 special-cased string table for any attribute that should go in the
232 main object file. This limits the complexity to just the places
235 static GTY ((param_is (struct indirect_string_node
)))
236 htab_t skeleton_debug_str_hash
;
238 static GTY(()) int dw2_string_counter
;
240 /* True if the compilation unit places functions in more than one section. */
241 static GTY(()) bool have_multiple_function_sections
= false;
243 /* Whether the default text and cold text sections have been used at all. */
245 static GTY(()) bool text_section_used
= false;
246 static GTY(()) bool cold_text_section_used
= false;
248 /* The default cold text section. */
249 static GTY(()) section
*cold_text_section
;
251 /* The DIE for C++1y 'auto' in a function return type. */
252 static GTY(()) dw_die_ref auto_die
;
254 /* The DIE for C++1y 'decltype(auto)' in a function return type. */
255 static GTY(()) dw_die_ref decltype_auto_die
;
257 /* Forward declarations for functions defined in this file. */
259 static char *stripattributes (const char *);
260 static void output_call_frame_info (int);
261 static void dwarf2out_note_section_used (void);
263 /* Personality decl of current unit. Used only when assembler does not support
265 static GTY(()) rtx current_unit_personality
;
267 /* Data and reference forms for relocatable data. */
268 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
269 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
271 #ifndef DEBUG_FRAME_SECTION
272 #define DEBUG_FRAME_SECTION ".debug_frame"
275 #ifndef FUNC_BEGIN_LABEL
276 #define FUNC_BEGIN_LABEL "LFB"
279 #ifndef FUNC_END_LABEL
280 #define FUNC_END_LABEL "LFE"
283 #ifndef PROLOGUE_END_LABEL
284 #define PROLOGUE_END_LABEL "LPE"
287 #ifndef EPILOGUE_BEGIN_LABEL
288 #define EPILOGUE_BEGIN_LABEL "LEB"
291 #ifndef FRAME_BEGIN_LABEL
292 #define FRAME_BEGIN_LABEL "Lframe"
294 #define CIE_AFTER_SIZE_LABEL "LSCIE"
295 #define CIE_END_LABEL "LECIE"
296 #define FDE_LABEL "LSFDE"
297 #define FDE_AFTER_SIZE_LABEL "LASFDE"
298 #define FDE_END_LABEL "LEFDE"
299 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
300 #define LINE_NUMBER_END_LABEL "LELT"
301 #define LN_PROLOG_AS_LABEL "LASLTP"
302 #define LN_PROLOG_END_LABEL "LELTP"
303 #define DIE_LABEL_PREFIX "DW"
305 /* Match the base name of a file to the base name of a compilation unit. */
308 matches_main_base (const char *path
)
310 /* Cache the last query. */
311 static const char *last_path
= NULL
;
312 static int last_match
= 0;
313 if (path
!= last_path
)
316 int length
= base_of_path (path
, &base
);
318 last_match
= (length
== main_input_baselength
319 && memcmp (base
, main_input_basename
, length
) == 0);
324 #ifdef DEBUG_DEBUG_STRUCT
327 dump_struct_debug (tree type
, enum debug_info_usage usage
,
328 enum debug_struct_file criterion
, int generic
,
329 int matches
, int result
)
331 /* Find the type name. */
332 tree type_decl
= TYPE_STUB_DECL (type
);
334 const char *name
= 0;
335 if (TREE_CODE (t
) == TYPE_DECL
)
338 name
= IDENTIFIER_POINTER (t
);
340 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
342 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
343 matches
? "bas" : "hdr",
344 generic
? "gen" : "ord",
345 usage
== DINFO_USAGE_DFN
? ";" :
346 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
348 (void*) type_decl
, name
);
351 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
352 dump_struct_debug (type, usage, criterion, generic, matches, result)
356 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
361 /* Get the number of HOST_WIDE_INTs needed to represent the precision
365 get_full_len (const wide_int
&op
)
367 return ((op
.get_precision () + HOST_BITS_PER_WIDE_INT
- 1)
368 / HOST_BITS_PER_WIDE_INT
);
372 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
374 enum debug_struct_file criterion
;
376 bool generic
= lang_hooks
.types
.generic_p (type
);
379 criterion
= debug_struct_generic
[usage
];
381 criterion
= debug_struct_ordinary
[usage
];
383 if (criterion
== DINFO_STRUCT_FILE_NONE
)
384 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
385 if (criterion
== DINFO_STRUCT_FILE_ANY
)
386 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
388 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
390 if (type_decl
!= NULL
)
392 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
393 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
395 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
396 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
399 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
402 /* Return a pointer to a copy of the section string name S with all
403 attributes stripped off, and an asterisk prepended (for assemble_name). */
406 stripattributes (const char *s
)
408 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
413 while (*s
&& *s
!= ',')
420 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
421 switch to the data section instead, and write out a synthetic start label
422 for collect2 the first time around. */
425 switch_to_eh_frame_section (bool back
)
429 #ifdef EH_FRAME_SECTION_NAME
430 if (eh_frame_section
== 0)
434 if (EH_TABLES_CAN_BE_READ_ONLY
)
440 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
442 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
444 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
447 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
448 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
449 && (per_encoding
& 0x70) != DW_EH_PE_absptr
450 && (per_encoding
& 0x70) != DW_EH_PE_aligned
451 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
452 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
453 ? 0 : SECTION_WRITE
);
456 flags
= SECTION_WRITE
;
457 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
459 #endif /* EH_FRAME_SECTION_NAME */
461 if (eh_frame_section
)
462 switch_to_section (eh_frame_section
);
465 /* We have no special eh_frame section. Put the information in
466 the data section and emit special labels to guide collect2. */
467 switch_to_section (data_section
);
471 label
= get_file_function_name ("F");
472 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
473 targetm
.asm_out
.globalize_label (asm_out_file
,
474 IDENTIFIER_POINTER (label
));
475 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
480 /* Switch [BACK] to the eh or debug frame table section, depending on
484 switch_to_frame_table_section (int for_eh
, bool back
)
487 switch_to_eh_frame_section (back
);
490 if (!debug_frame_section
)
491 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
492 SECTION_DEBUG
, NULL
);
493 switch_to_section (debug_frame_section
);
497 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
499 enum dw_cfi_oprnd_type
500 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
505 case DW_CFA_GNU_window_save
:
506 case DW_CFA_remember_state
:
507 case DW_CFA_restore_state
:
508 return dw_cfi_oprnd_unused
;
511 case DW_CFA_advance_loc1
:
512 case DW_CFA_advance_loc2
:
513 case DW_CFA_advance_loc4
:
514 case DW_CFA_MIPS_advance_loc8
:
515 return dw_cfi_oprnd_addr
;
518 case DW_CFA_offset_extended
:
520 case DW_CFA_offset_extended_sf
:
521 case DW_CFA_def_cfa_sf
:
523 case DW_CFA_restore_extended
:
524 case DW_CFA_undefined
:
525 case DW_CFA_same_value
:
526 case DW_CFA_def_cfa_register
:
527 case DW_CFA_register
:
528 case DW_CFA_expression
:
529 return dw_cfi_oprnd_reg_num
;
531 case DW_CFA_def_cfa_offset
:
532 case DW_CFA_GNU_args_size
:
533 case DW_CFA_def_cfa_offset_sf
:
534 return dw_cfi_oprnd_offset
;
536 case DW_CFA_def_cfa_expression
:
537 return dw_cfi_oprnd_loc
;
544 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
546 enum dw_cfi_oprnd_type
547 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
552 case DW_CFA_def_cfa_sf
:
554 case DW_CFA_offset_extended_sf
:
555 case DW_CFA_offset_extended
:
556 return dw_cfi_oprnd_offset
;
558 case DW_CFA_register
:
559 return dw_cfi_oprnd_reg_num
;
561 case DW_CFA_expression
:
562 return dw_cfi_oprnd_loc
;
565 return dw_cfi_oprnd_unused
;
569 /* Output one FDE. */
572 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
573 char *section_start_label
, int fde_encoding
, char *augmentation
,
574 bool any_lsda_needed
, int lsda_encoding
)
576 const char *begin
, *end
;
577 static unsigned int j
;
580 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
582 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
584 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
585 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
586 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
587 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
588 " indicating 64-bit DWARF extension");
589 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
591 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
594 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
596 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
597 debug_frame_section
, "FDE CIE offset");
599 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
600 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
604 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
605 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
606 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
607 "FDE initial location");
608 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
609 end
, begin
, "FDE address range");
613 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
614 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
621 int size
= size_of_encoded_value (lsda_encoding
);
623 if (lsda_encoding
== DW_EH_PE_aligned
)
625 int offset
= ( 4 /* Length */
627 + 2 * size_of_encoded_value (fde_encoding
)
628 + 1 /* Augmentation size */ );
629 int pad
= -offset
& (PTR_SIZE
- 1);
632 gcc_assert (size_of_uleb128 (size
) == 1);
635 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
637 if (fde
->uses_eh_lsda
)
639 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
640 fde
->funcdef_number
);
641 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
642 gen_rtx_SYMBOL_REF (Pmode
, l1
),
644 "Language Specific Data Area");
648 if (lsda_encoding
== DW_EH_PE_aligned
)
649 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
650 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
651 "Language Specific Data Area (none)");
655 dw2_asm_output_data_uleb128 (0, "Augmentation size");
658 /* Loop through the Call Frame Instructions associated with this FDE. */
659 fde
->dw_fde_current_label
= begin
;
661 size_t from
, until
, i
;
664 until
= vec_safe_length (fde
->dw_fde_cfi
);
666 if (fde
->dw_fde_second_begin
== NULL
)
669 until
= fde
->dw_fde_switch_cfi_index
;
671 from
= fde
->dw_fde_switch_cfi_index
;
673 for (i
= from
; i
< until
; i
++)
674 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
677 /* If we are to emit a ref/link from function bodies to their frame tables,
678 do it now. This is typically performed to make sure that tables
679 associated with functions are dragged with them and not discarded in
680 garbage collecting links. We need to do this on a per function basis to
681 cope with -ffunction-sections. */
683 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
684 /* Switch to the function section, emit the ref to the tables, and
685 switch *back* into the table section. */
686 switch_to_section (function_section (fde
->decl
));
687 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
688 switch_to_frame_table_section (for_eh
, true);
691 /* Pad the FDE out to an address sized boundary. */
692 ASM_OUTPUT_ALIGN (asm_out_file
,
693 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
694 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
699 /* Return true if frame description entry FDE is needed for EH. */
702 fde_needed_for_eh_p (dw_fde_ref fde
)
704 if (flag_asynchronous_unwind_tables
)
707 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
710 if (fde
->uses_eh_lsda
)
713 /* If exceptions are enabled, we have collected nothrow info. */
714 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
720 /* Output the call frame information used to record information
721 that relates to calculating the frame pointer, and records the
722 location of saved registers. */
725 output_call_frame_info (int for_eh
)
730 char l1
[20], l2
[20], section_start_label
[20];
731 bool any_lsda_needed
= false;
732 char augmentation
[6];
733 int augmentation_size
;
734 int fde_encoding
= DW_EH_PE_absptr
;
735 int per_encoding
= DW_EH_PE_absptr
;
736 int lsda_encoding
= DW_EH_PE_absptr
;
738 rtx personality
= NULL
;
741 /* Don't emit a CIE if there won't be any FDEs. */
745 /* Nothing to do if the assembler's doing it all. */
746 if (dwarf2out_do_cfi_asm ())
749 /* If we don't have any functions we'll want to unwind out of, don't emit
750 any EH unwind information. If we make FDEs linkonce, we may have to
751 emit an empty label for an FDE that wouldn't otherwise be emitted. We
752 want to avoid having an FDE kept around when the function it refers to
753 is discarded. Example where this matters: a primary function template
754 in C++ requires EH information, an explicit specialization doesn't. */
757 bool any_eh_needed
= false;
759 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
761 if (fde
->uses_eh_lsda
)
762 any_eh_needed
= any_lsda_needed
= true;
763 else if (fde_needed_for_eh_p (fde
))
764 any_eh_needed
= true;
765 else if (TARGET_USES_WEAK_UNWIND_INFO
)
766 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
773 /* We're going to be generating comments, so turn on app. */
777 /* Switch to the proper frame section, first time. */
778 switch_to_frame_table_section (for_eh
, false);
780 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
781 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
783 /* Output the CIE. */
784 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
785 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
786 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
787 dw2_asm_output_data (4, 0xffffffff,
788 "Initial length escape value indicating 64-bit DWARF extension");
789 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
790 "Length of Common Information Entry");
791 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
793 /* Now that the CIE pointer is PC-relative for EH,
794 use 0 to identify the CIE. */
795 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
796 (for_eh
? 0 : DWARF_CIE_ID
),
797 "CIE Identifier Tag");
799 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
800 use CIE version 1, unless that would produce incorrect results
801 due to overflowing the return register column. */
802 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
804 if (return_reg
>= 256 || dwarf_version
> 2)
806 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
809 augmentation_size
= 0;
811 personality
= current_unit_personality
;
817 z Indicates that a uleb128 is present to size the
818 augmentation section.
819 L Indicates the encoding (and thus presence) of
820 an LSDA pointer in the FDE augmentation.
821 R Indicates a non-default pointer encoding for
823 P Indicates the presence of an encoding + language
824 personality routine in the CIE augmentation. */
826 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
827 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
828 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
830 p
= augmentation
+ 1;
834 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
835 assemble_external_libcall (personality
);
840 augmentation_size
+= 1;
842 if (fde_encoding
!= DW_EH_PE_absptr
)
845 augmentation_size
+= 1;
847 if (p
> augmentation
+ 1)
849 augmentation
[0] = 'z';
853 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
854 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
856 int offset
= ( 4 /* Length */
858 + 1 /* CIE version */
859 + strlen (augmentation
) + 1 /* Augmentation */
860 + size_of_uleb128 (1) /* Code alignment */
861 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
863 + 1 /* Augmentation size */
864 + 1 /* Personality encoding */ );
865 int pad
= -offset
& (PTR_SIZE
- 1);
867 augmentation_size
+= pad
;
869 /* Augmentations should be small, so there's scarce need to
870 iterate for a solution. Die if we exceed one uleb128 byte. */
871 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
875 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
876 if (dw_cie_version
>= 4)
878 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
879 dw2_asm_output_data (1, 0, "CIE Segment Size");
881 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
882 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
883 "CIE Data Alignment Factor");
885 if (dw_cie_version
== 1)
886 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
888 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
892 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
895 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
896 eh_data_format_name (per_encoding
));
897 dw2_asm_output_encoded_addr_rtx (per_encoding
,
903 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
904 eh_data_format_name (lsda_encoding
));
906 if (fde_encoding
!= DW_EH_PE_absptr
)
907 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
908 eh_data_format_name (fde_encoding
));
911 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
912 output_cfi (cfi
, NULL
, for_eh
);
914 /* Pad the CIE out to an address sized boundary. */
915 ASM_OUTPUT_ALIGN (asm_out_file
,
916 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
917 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
919 /* Loop through all of the FDE's. */
920 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
924 /* Don't emit EH unwind info for leaf functions that don't need it. */
925 if (for_eh
&& !fde_needed_for_eh_p (fde
))
928 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
929 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
930 augmentation
, any_lsda_needed
, lsda_encoding
);
933 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
934 dw2_asm_output_data (4, 0, "End of Table");
936 /* Turn off app to make assembly quicker. */
941 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
944 dwarf2out_do_cfi_startproc (bool second
)
948 rtx personality
= get_personality_function (current_function_decl
);
950 fprintf (asm_out_file
, "\t.cfi_startproc\n");
954 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
957 /* ??? The GAS support isn't entirely consistent. We have to
958 handle indirect support ourselves, but PC-relative is done
959 in the assembler. Further, the assembler can't handle any
960 of the weirder relocation types. */
961 if (enc
& DW_EH_PE_indirect
)
962 ref
= dw2_force_const_mem (ref
, true);
964 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
965 output_addr_const (asm_out_file
, ref
);
966 fputc ('\n', asm_out_file
);
969 if (crtl
->uses_eh_lsda
)
973 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
974 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
975 current_function_funcdef_no
);
976 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
977 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
979 if (enc
& DW_EH_PE_indirect
)
980 ref
= dw2_force_const_mem (ref
, true);
982 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
983 output_addr_const (asm_out_file
, ref
);
984 fputc ('\n', asm_out_file
);
988 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
989 this allocation may be done before pass_final. */
992 dwarf2out_alloc_current_fde (void)
996 fde
= ggc_cleared_alloc
<dw_fde_node
> ();
997 fde
->decl
= current_function_decl
;
998 fde
->funcdef_number
= current_function_funcdef_no
;
999 fde
->fde_index
= vec_safe_length (fde_vec
);
1000 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
1001 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
1002 fde
->nothrow
= crtl
->nothrow
;
1003 fde
->drap_reg
= INVALID_REGNUM
;
1004 fde
->vdrap_reg
= INVALID_REGNUM
;
1006 /* Record the FDE associated with this function. */
1008 vec_safe_push (fde_vec
, fde
);
1013 /* Output a marker (i.e. a label) for the beginning of a function, before
1017 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1018 const char *file ATTRIBUTE_UNUSED
)
1020 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1026 current_function_func_begin_label
= NULL
;
1028 do_frame
= dwarf2out_do_frame ();
1030 /* ??? current_function_func_begin_label is also used by except.c for
1031 call-site information. We must emit this label if it might be used. */
1033 && (!flag_exceptions
1034 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1037 fnsec
= function_section (current_function_decl
);
1038 switch_to_section (fnsec
);
1039 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1040 current_function_funcdef_no
);
1041 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1042 current_function_funcdef_no
);
1043 dup_label
= xstrdup (label
);
1044 current_function_func_begin_label
= dup_label
;
1046 /* We can elide the fde allocation if we're not emitting debug info. */
1050 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1051 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1052 would include pass_dwarf2_frame. If we've not created the FDE yet,
1056 fde
= dwarf2out_alloc_current_fde ();
1058 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1059 fde
->dw_fde_begin
= dup_label
;
1060 fde
->dw_fde_current_label
= dup_label
;
1061 fde
->in_std_section
= (fnsec
== text_section
1062 || (cold_text_section
&& fnsec
== cold_text_section
));
1064 /* We only want to output line number information for the genuine dwarf2
1065 prologue case, not the eh frame case. */
1066 #ifdef DWARF2_DEBUGGING_INFO
1068 dwarf2out_source_line (line
, file
, 0, true);
1071 if (dwarf2out_do_cfi_asm ())
1072 dwarf2out_do_cfi_startproc (false);
1075 rtx personality
= get_personality_function (current_function_decl
);
1076 if (!current_unit_personality
)
1077 current_unit_personality
= personality
;
1079 /* We cannot keep a current personality per function as without CFI
1080 asm, at the point where we emit the CFI data, there is no current
1081 function anymore. */
1082 if (personality
&& current_unit_personality
!= personality
)
1083 sorry ("multiple EH personalities are supported only with assemblers "
1084 "supporting .cfi_personality directive");
1088 /* Output a marker (i.e. a label) for the end of the generated code
1089 for a function prologue. This gets called *after* the prologue code has
1093 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1094 const char *file ATTRIBUTE_UNUSED
)
1096 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1098 /* Output a label to mark the endpoint of the code generated for this
1100 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1101 current_function_funcdef_no
);
1102 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1103 current_function_funcdef_no
);
1104 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1107 /* Output a marker (i.e. a label) for the beginning of the generated code
1108 for a function epilogue. This gets called *before* the prologue code has
1112 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1113 const char *file ATTRIBUTE_UNUSED
)
1115 dw_fde_ref fde
= cfun
->fde
;
1116 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1118 if (fde
->dw_fde_vms_begin_epilogue
)
1121 /* Output a label to mark the endpoint of the code generated for this
1123 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1124 current_function_funcdef_no
);
1125 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1126 current_function_funcdef_no
);
1127 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1130 /* Output a marker (i.e. a label) for the absolute end of the generated code
1131 for a function definition. This gets called *after* the epilogue code has
1135 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1136 const char *file ATTRIBUTE_UNUSED
)
1139 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1141 last_var_location_insn
= NULL_RTX
;
1142 cached_next_real_insn
= NULL_RTX
;
1144 if (dwarf2out_do_cfi_asm ())
1145 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1147 /* Output a label to mark the endpoint of the code generated for this
1149 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1150 current_function_funcdef_no
);
1151 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1153 gcc_assert (fde
!= NULL
);
1154 if (fde
->dw_fde_second_begin
== NULL
)
1155 fde
->dw_fde_end
= xstrdup (label
);
1159 dwarf2out_frame_finish (void)
1161 /* Output call frame information. */
1162 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1163 output_call_frame_info (0);
1165 /* Output another copy for the unwinder. */
1166 if ((flag_unwind_tables
|| flag_exceptions
)
1167 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1168 output_call_frame_info (1);
1171 /* Note that the current function section is being used for code. */
1174 dwarf2out_note_section_used (void)
1176 section
*sec
= current_function_section ();
1177 if (sec
== text_section
)
1178 text_section_used
= true;
1179 else if (sec
== cold_text_section
)
1180 cold_text_section_used
= true;
1183 static void var_location_switch_text_section (void);
1184 static void set_cur_line_info_table (section
*);
1187 dwarf2out_switch_text_section (void)
1190 dw_fde_ref fde
= cfun
->fde
;
1192 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1194 if (!in_cold_section_p
)
1196 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1197 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1198 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1202 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1203 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1204 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1206 have_multiple_function_sections
= true;
1208 /* There is no need to mark used sections when not debugging. */
1209 if (cold_text_section
!= NULL
)
1210 dwarf2out_note_section_used ();
1212 if (dwarf2out_do_cfi_asm ())
1213 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1215 /* Now do the real section switch. */
1216 sect
= current_function_section ();
1217 switch_to_section (sect
);
1219 fde
->second_in_std_section
1220 = (sect
== text_section
1221 || (cold_text_section
&& sect
== cold_text_section
));
1223 if (dwarf2out_do_cfi_asm ())
1224 dwarf2out_do_cfi_startproc (true);
1226 var_location_switch_text_section ();
1228 if (cold_text_section
!= NULL
)
1229 set_cur_line_info_table (sect
);
1232 /* And now, the subset of the debugging information support code necessary
1233 for emitting location expressions. */
1235 /* Data about a single source file. */
1236 struct GTY(()) dwarf_file_data
{
1237 const char * filename
;
1241 typedef struct GTY(()) deferred_locations_struct
1245 } deferred_locations
;
1248 static GTY(()) vec
<deferred_locations
, va_gc
> *deferred_locations_list
;
1251 /* Describe an entry into the .debug_addr section. */
1255 ate_kind_rtx_dtprel
,
1259 typedef struct GTY(()) addr_table_entry_struct
{
1261 unsigned int refcount
;
1263 union addr_table_entry_struct_union
1265 rtx
GTY ((tag ("0"))) rtl
;
1266 char * GTY ((tag ("1"))) label
;
1268 GTY ((desc ("%1.kind"))) addr
;
1272 /* Location lists are ranges + location descriptions for that range,
1273 so you can track variables that are in different places over
1274 their entire life. */
1275 typedef struct GTY(()) dw_loc_list_struct
{
1276 dw_loc_list_ref dw_loc_next
;
1277 const char *begin
; /* Label and addr_entry for start of range */
1278 addr_table_entry
*begin_entry
;
1279 const char *end
; /* Label for end of range */
1280 char *ll_symbol
; /* Label for beginning of location list.
1281 Only on head of list */
1282 const char *section
; /* Section this loclist is relative to */
1283 dw_loc_descr_ref expr
;
1285 /* True if all addresses in this and subsequent lists are known to be
1288 /* True if this list has been replaced by dw_loc_next. */
1291 /* True if the range should be emitted even if begin and end
1296 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1298 /* Convert a DWARF stack opcode into its string name. */
1301 dwarf_stack_op_name (unsigned int op
)
1303 const char *name
= get_DW_OP_name (op
);
1308 return "OP_<unknown>";
1311 /* Return a pointer to a newly allocated location description. Location
1312 descriptions are simple expression terms that can be strung
1313 together to form more complicated location (address) descriptions. */
1315 static inline dw_loc_descr_ref
1316 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1317 unsigned HOST_WIDE_INT oprnd2
)
1319 dw_loc_descr_ref descr
= ggc_cleared_alloc
<dw_loc_descr_node
> ();
1321 descr
->dw_loc_opc
= op
;
1322 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1323 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1324 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1325 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1326 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1327 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1332 /* Return a pointer to a newly allocated location description for
1335 static inline dw_loc_descr_ref
1336 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1339 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1342 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1345 /* Add a location description term to a location description expression. */
1348 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1350 dw_loc_descr_ref
*d
;
1352 /* Find the end of the chain. */
1353 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1359 /* Compare two location operands for exact equality. */
1362 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1364 if (a
->val_class
!= b
->val_class
)
1366 switch (a
->val_class
)
1368 case dw_val_class_none
:
1370 case dw_val_class_addr
:
1371 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1373 case dw_val_class_offset
:
1374 case dw_val_class_unsigned_const
:
1375 case dw_val_class_const
:
1376 case dw_val_class_range_list
:
1377 case dw_val_class_lineptr
:
1378 case dw_val_class_macptr
:
1379 /* These are all HOST_WIDE_INT, signed or unsigned. */
1380 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1382 case dw_val_class_loc
:
1383 return a
->v
.val_loc
== b
->v
.val_loc
;
1384 case dw_val_class_loc_list
:
1385 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1386 case dw_val_class_die_ref
:
1387 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1388 case dw_val_class_fde_ref
:
1389 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1390 case dw_val_class_lbl_id
:
1391 case dw_val_class_high_pc
:
1392 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1393 case dw_val_class_str
:
1394 return a
->v
.val_str
== b
->v
.val_str
;
1395 case dw_val_class_flag
:
1396 return a
->v
.val_flag
== b
->v
.val_flag
;
1397 case dw_val_class_file
:
1398 return a
->v
.val_file
== b
->v
.val_file
;
1399 case dw_val_class_decl_ref
:
1400 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1402 case dw_val_class_const_double
:
1403 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1404 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1406 case dw_val_class_wide_int
:
1407 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1409 case dw_val_class_vec
:
1411 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1412 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1414 return (a_len
== b_len
1415 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1418 case dw_val_class_data8
:
1419 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1421 case dw_val_class_vms_delta
:
1422 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1423 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1428 /* Compare two location atoms for exact equality. */
1431 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1433 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1436 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1437 address size, but since we always allocate cleared storage it
1438 should be zero for other types of locations. */
1439 if (a
->dtprel
!= b
->dtprel
)
1442 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1443 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1446 /* Compare two complete location expressions for exact equality. */
1449 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1455 if (a
== NULL
|| b
== NULL
)
1457 if (!loc_descr_equal_p_1 (a
, b
))
1466 /* Add a constant OFFSET to a location expression. */
1469 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1471 dw_loc_descr_ref loc
;
1474 gcc_assert (*list_head
!= NULL
);
1479 /* Find the end of the chain. */
1480 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1484 if (loc
->dw_loc_opc
== DW_OP_fbreg
1485 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1486 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1487 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1488 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1490 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1491 offset. Don't optimize if an signed integer overflow would happen. */
1493 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1494 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1497 else if (offset
> 0)
1498 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1502 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1503 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1507 /* Add a constant OFFSET to a location list. */
1510 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1513 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1514 loc_descr_plus_const (&d
->expr
, offset
);
1517 #define DWARF_REF_SIZE \
1518 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1520 static unsigned long int get_base_type_offset (dw_die_ref
);
1522 /* Return the size of a location descriptor. */
1524 static unsigned long
1525 size_of_loc_descr (dw_loc_descr_ref loc
)
1527 unsigned long size
= 1;
1529 switch (loc
->dw_loc_opc
)
1532 size
+= DWARF2_ADDR_SIZE
;
1534 case DW_OP_GNU_addr_index
:
1535 case DW_OP_GNU_const_index
:
1536 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1537 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1556 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1559 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1564 case DW_OP_plus_uconst
:
1565 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1603 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1606 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1609 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1612 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1613 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1616 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1618 case DW_OP_bit_piece
:
1619 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1620 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1622 case DW_OP_deref_size
:
1623 case DW_OP_xderef_size
:
1632 case DW_OP_call_ref
:
1633 size
+= DWARF_REF_SIZE
;
1635 case DW_OP_implicit_value
:
1636 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1637 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1639 case DW_OP_GNU_implicit_pointer
:
1640 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1642 case DW_OP_GNU_entry_value
:
1644 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1645 size
+= size_of_uleb128 (op_size
) + op_size
;
1648 case DW_OP_GNU_const_type
:
1651 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1652 size
+= size_of_uleb128 (o
) + 1;
1653 switch (loc
->dw_loc_oprnd2
.val_class
)
1655 case dw_val_class_vec
:
1656 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1657 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1659 case dw_val_class_const
:
1660 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1662 case dw_val_class_const_double
:
1663 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1665 case dw_val_class_wide_int
:
1666 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
1667 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
1674 case DW_OP_GNU_regval_type
:
1677 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1678 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1679 + size_of_uleb128 (o
);
1682 case DW_OP_GNU_deref_type
:
1685 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1686 size
+= 1 + size_of_uleb128 (o
);
1689 case DW_OP_GNU_convert
:
1690 case DW_OP_GNU_reinterpret
:
1691 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1692 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1696 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1697 size
+= size_of_uleb128 (o
);
1700 case DW_OP_GNU_parameter_ref
:
1710 /* Return the size of a series of location descriptors. */
1713 size_of_locs (dw_loc_descr_ref loc
)
1718 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1719 field, to avoid writing to a PCH file. */
1720 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1722 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1724 size
+= size_of_loc_descr (l
);
1729 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1731 l
->dw_loc_addr
= size
;
1732 size
+= size_of_loc_descr (l
);
1738 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1739 static void get_ref_die_offset_label (char *, dw_die_ref
);
1740 static unsigned long int get_ref_die_offset (dw_die_ref
);
1742 /* Output location description stack opcode's operands (if any).
1743 The for_eh_or_skip parameter controls whether register numbers are
1744 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1745 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1746 info). This should be suppressed for the cases that have not been converted
1747 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1750 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1752 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1753 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1755 switch (loc
->dw_loc_opc
)
1757 #ifdef DWARF2_DEBUGGING_INFO
1760 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1765 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1766 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1768 fputc ('\n', asm_out_file
);
1773 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1778 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1779 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1781 fputc ('\n', asm_out_file
);
1786 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1787 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1794 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1795 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1797 dw2_asm_output_data (2, offset
, NULL
);
1800 case DW_OP_implicit_value
:
1801 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1802 switch (val2
->val_class
)
1804 case dw_val_class_const
:
1805 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1807 case dw_val_class_vec
:
1809 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1810 unsigned int len
= val2
->v
.val_vec
.length
;
1814 if (elt_size
> sizeof (HOST_WIDE_INT
))
1819 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1822 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1823 "fp or vector constant word %u", i
);
1826 case dw_val_class_const_double
:
1828 unsigned HOST_WIDE_INT first
, second
;
1830 if (WORDS_BIG_ENDIAN
)
1832 first
= val2
->v
.val_double
.high
;
1833 second
= val2
->v
.val_double
.low
;
1837 first
= val2
->v
.val_double
.low
;
1838 second
= val2
->v
.val_double
.high
;
1840 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1842 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1846 case dw_val_class_wide_int
:
1849 int len
= get_full_len (*val2
->v
.val_wide
);
1850 if (WORDS_BIG_ENDIAN
)
1851 for (i
= len
- 1; i
>= 0; --i
)
1852 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1853 val2
->v
.val_wide
->elt (i
), NULL
);
1855 for (i
= 0; i
< len
; ++i
)
1856 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1857 val2
->v
.val_wide
->elt (i
), NULL
);
1860 case dw_val_class_addr
:
1861 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1862 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1877 case DW_OP_implicit_value
:
1878 /* We currently don't make any attempt to make sure these are
1879 aligned properly like we do for the main unwind info, so
1880 don't support emitting things larger than a byte if we're
1881 only doing unwinding. */
1886 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1889 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1892 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1895 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1897 case DW_OP_plus_uconst
:
1898 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1932 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1936 unsigned r
= val1
->v
.val_unsigned
;
1937 if (for_eh_or_skip
>= 0)
1938 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1939 gcc_assert (size_of_uleb128 (r
)
1940 == size_of_uleb128 (val1
->v
.val_unsigned
));
1941 dw2_asm_output_data_uleb128 (r
, NULL
);
1945 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1949 unsigned r
= val1
->v
.val_unsigned
;
1950 if (for_eh_or_skip
>= 0)
1951 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1952 gcc_assert (size_of_uleb128 (r
)
1953 == size_of_uleb128 (val1
->v
.val_unsigned
));
1954 dw2_asm_output_data_uleb128 (r
, NULL
);
1955 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1959 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1961 case DW_OP_bit_piece
:
1962 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1963 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1965 case DW_OP_deref_size
:
1966 case DW_OP_xderef_size
:
1967 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1973 if (targetm
.asm_out
.output_dwarf_dtprel
)
1975 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1978 fputc ('\n', asm_out_file
);
1985 #ifdef DWARF2_DEBUGGING_INFO
1986 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
1993 case DW_OP_GNU_addr_index
:
1994 case DW_OP_GNU_const_index
:
1995 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1996 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
1997 "(index into .debug_addr)");
2000 case DW_OP_GNU_implicit_pointer
:
2002 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2003 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2004 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2005 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2006 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2007 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2011 case DW_OP_GNU_entry_value
:
2012 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2013 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2016 case DW_OP_GNU_const_type
:
2018 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2020 dw2_asm_output_data_uleb128 (o
, NULL
);
2021 switch (val2
->val_class
)
2023 case dw_val_class_const
:
2024 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2025 dw2_asm_output_data (1, l
, NULL
);
2026 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2028 case dw_val_class_vec
:
2030 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2031 unsigned int len
= val2
->v
.val_vec
.length
;
2036 dw2_asm_output_data (1, l
, NULL
);
2037 if (elt_size
> sizeof (HOST_WIDE_INT
))
2042 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2045 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2046 "fp or vector constant word %u", i
);
2049 case dw_val_class_const_double
:
2051 unsigned HOST_WIDE_INT first
, second
;
2052 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2054 dw2_asm_output_data (1, 2 * l
, NULL
);
2055 if (WORDS_BIG_ENDIAN
)
2057 first
= val2
->v
.val_double
.high
;
2058 second
= val2
->v
.val_double
.low
;
2062 first
= val2
->v
.val_double
.low
;
2063 second
= val2
->v
.val_double
.high
;
2065 dw2_asm_output_data (l
, first
, NULL
);
2066 dw2_asm_output_data (l
, second
, NULL
);
2069 case dw_val_class_wide_int
:
2072 int len
= get_full_len (*val2
->v
.val_wide
);
2073 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2075 dw2_asm_output_data (1, len
* l
, NULL
);
2076 if (WORDS_BIG_ENDIAN
)
2077 for (i
= len
- 1; i
>= 0; --i
)
2078 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2080 for (i
= 0; i
< len
; ++i
)
2081 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2089 case DW_OP_GNU_regval_type
:
2091 unsigned r
= val1
->v
.val_unsigned
;
2092 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2094 if (for_eh_or_skip
>= 0)
2096 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2097 gcc_assert (size_of_uleb128 (r
)
2098 == size_of_uleb128 (val1
->v
.val_unsigned
));
2100 dw2_asm_output_data_uleb128 (r
, NULL
);
2101 dw2_asm_output_data_uleb128 (o
, NULL
);
2104 case DW_OP_GNU_deref_type
:
2106 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2108 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2109 dw2_asm_output_data_uleb128 (o
, NULL
);
2112 case DW_OP_GNU_convert
:
2113 case DW_OP_GNU_reinterpret
:
2114 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2115 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2118 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2120 dw2_asm_output_data_uleb128 (o
, NULL
);
2124 case DW_OP_GNU_parameter_ref
:
2127 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2128 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2129 dw2_asm_output_data (4, o
, NULL
);
2134 /* Other codes have no operands. */
2139 /* Output a sequence of location operations.
2140 The for_eh_or_skip parameter controls whether register numbers are
2141 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2142 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2143 info). This should be suppressed for the cases that have not been converted
2144 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2147 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2149 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2151 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2152 /* Output the opcode. */
2153 if (for_eh_or_skip
>= 0
2154 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2156 unsigned r
= (opc
- DW_OP_breg0
);
2157 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2158 gcc_assert (r
<= 31);
2159 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2161 else if (for_eh_or_skip
>= 0
2162 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2164 unsigned r
= (opc
- DW_OP_reg0
);
2165 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2166 gcc_assert (r
<= 31);
2167 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2170 dw2_asm_output_data (1, opc
,
2171 "%s", dwarf_stack_op_name (opc
));
2173 /* Output the operand(s) (if any). */
2174 output_loc_operands (loc
, for_eh_or_skip
);
2178 /* Output location description stack opcode's operands (if any).
2179 The output is single bytes on a line, suitable for .cfi_escape. */
2182 output_loc_operands_raw (dw_loc_descr_ref loc
)
2184 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2185 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2187 switch (loc
->dw_loc_opc
)
2190 case DW_OP_GNU_addr_index
:
2191 case DW_OP_GNU_const_index
:
2192 case DW_OP_implicit_value
:
2193 /* We cannot output addresses in .cfi_escape, only bytes. */
2199 case DW_OP_deref_size
:
2200 case DW_OP_xderef_size
:
2201 fputc (',', asm_out_file
);
2202 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2207 fputc (',', asm_out_file
);
2208 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2213 fputc (',', asm_out_file
);
2214 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2219 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2220 fputc (',', asm_out_file
);
2221 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2229 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2230 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2232 fputc (',', asm_out_file
);
2233 dw2_asm_output_data_raw (2, offset
);
2239 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2240 gcc_assert (size_of_uleb128 (r
)
2241 == size_of_uleb128 (val1
->v
.val_unsigned
));
2242 fputc (',', asm_out_file
);
2243 dw2_asm_output_data_uleb128_raw (r
);
2248 case DW_OP_plus_uconst
:
2250 fputc (',', asm_out_file
);
2251 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2254 case DW_OP_bit_piece
:
2255 fputc (',', asm_out_file
);
2256 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2257 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2294 fputc (',', asm_out_file
);
2295 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2300 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2301 gcc_assert (size_of_uleb128 (r
)
2302 == size_of_uleb128 (val1
->v
.val_unsigned
));
2303 fputc (',', asm_out_file
);
2304 dw2_asm_output_data_uleb128_raw (r
);
2305 fputc (',', asm_out_file
);
2306 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2310 case DW_OP_GNU_implicit_pointer
:
2311 case DW_OP_GNU_entry_value
:
2312 case DW_OP_GNU_const_type
:
2313 case DW_OP_GNU_regval_type
:
2314 case DW_OP_GNU_deref_type
:
2315 case DW_OP_GNU_convert
:
2316 case DW_OP_GNU_reinterpret
:
2317 case DW_OP_GNU_parameter_ref
:
2322 /* Other codes have no operands. */
2328 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2332 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2333 /* Output the opcode. */
2334 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2336 unsigned r
= (opc
- DW_OP_breg0
);
2337 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2338 gcc_assert (r
<= 31);
2339 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2341 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2343 unsigned r
= (opc
- DW_OP_reg0
);
2344 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2345 gcc_assert (r
<= 31);
2346 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2348 /* Output the opcode. */
2349 fprintf (asm_out_file
, "%#x", opc
);
2350 output_loc_operands_raw (loc
);
2352 if (!loc
->dw_loc_next
)
2354 loc
= loc
->dw_loc_next
;
2356 fputc (',', asm_out_file
);
2360 /* This function builds a dwarf location descriptor sequence from a
2361 dw_cfa_location, adding the given OFFSET to the result of the
2364 struct dw_loc_descr_node
*
2365 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2367 struct dw_loc_descr_node
*head
, *tmp
;
2369 offset
+= cfa
->offset
;
2373 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2374 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2375 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2376 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2377 add_loc_descr (&head
, tmp
);
2380 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2381 add_loc_descr (&head
, tmp
);
2385 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2390 /* This function builds a dwarf location descriptor sequence for
2391 the address at OFFSET from the CFA when stack is aligned to
2394 struct dw_loc_descr_node
*
2395 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2396 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2398 struct dw_loc_descr_node
*head
;
2399 unsigned int dwarf_fp
2400 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2402 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2403 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2405 head
= new_reg_loc_descr (dwarf_fp
, 0);
2406 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2407 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2408 loc_descr_plus_const (&head
, offset
);
2411 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2415 /* And now, the support for symbolic debugging information. */
2417 /* .debug_str support. */
2418 static int output_indirect_string (void **, void *);
2420 static void dwarf2out_init (const char *);
2421 static void dwarf2out_finish (const char *);
2422 static void dwarf2out_assembly_start (void);
2423 static void dwarf2out_define (unsigned int, const char *);
2424 static void dwarf2out_undef (unsigned int, const char *);
2425 static void dwarf2out_start_source_file (unsigned, const char *);
2426 static void dwarf2out_end_source_file (unsigned);
2427 static void dwarf2out_function_decl (tree
);
2428 static void dwarf2out_begin_block (unsigned, unsigned);
2429 static void dwarf2out_end_block (unsigned, unsigned);
2430 static bool dwarf2out_ignore_block (const_tree
);
2431 static void dwarf2out_global_decl (tree
);
2432 static void dwarf2out_type_decl (tree
, int);
2433 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2434 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2436 static void dwarf2out_abstract_function (tree
);
2437 static void dwarf2out_var_location (rtx
);
2438 static void dwarf2out_begin_function (tree
);
2439 static void dwarf2out_end_function (unsigned int);
2440 static void dwarf2out_set_name (tree
, tree
);
2442 /* The debug hooks structure. */
2444 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2448 dwarf2out_assembly_start
,
2451 dwarf2out_start_source_file
,
2452 dwarf2out_end_source_file
,
2453 dwarf2out_begin_block
,
2454 dwarf2out_end_block
,
2455 dwarf2out_ignore_block
,
2456 dwarf2out_source_line
,
2457 dwarf2out_begin_prologue
,
2458 #if VMS_DEBUGGING_INFO
2459 dwarf2out_vms_end_prologue
,
2460 dwarf2out_vms_begin_epilogue
,
2462 debug_nothing_int_charstar
,
2463 debug_nothing_int_charstar
,
2465 dwarf2out_end_epilogue
,
2466 dwarf2out_begin_function
,
2467 dwarf2out_end_function
, /* end_function */
2468 dwarf2out_function_decl
, /* function_decl */
2469 dwarf2out_global_decl
,
2470 dwarf2out_type_decl
, /* type_decl */
2471 dwarf2out_imported_module_or_decl
,
2472 debug_nothing_tree
, /* deferred_inline_function */
2473 /* The DWARF 2 backend tries to reduce debugging bloat by not
2474 emitting the abstract description of inline functions until
2475 something tries to reference them. */
2476 dwarf2out_abstract_function
, /* outlining_inline_function */
2477 debug_nothing_rtx
, /* label */
2478 debug_nothing_int
, /* handle_pch */
2479 dwarf2out_var_location
,
2480 dwarf2out_switch_text_section
,
2482 1, /* start_end_main_source_file */
2483 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2486 /* NOTE: In the comments in this file, many references are made to
2487 "Debugging Information Entries". This term is abbreviated as `DIE'
2488 throughout the remainder of this file. */
2490 /* An internal representation of the DWARF output is built, and then
2491 walked to generate the DWARF debugging info. The walk of the internal
2492 representation is done after the entire program has been compiled.
2493 The types below are used to describe the internal representation. */
2495 /* Whether to put type DIEs into their own section .debug_types instead
2496 of making them part of the .debug_info section. Only supported for
2497 Dwarf V4 or higher and the user didn't disable them through
2498 -fno-debug-types-section. It is more efficient to put them in a
2499 separate comdat sections since the linker will then be able to
2500 remove duplicates. But not all tools support .debug_types sections
2503 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2505 /* Various DIE's use offsets relative to the beginning of the
2506 .debug_info section to refer to each other. */
2508 typedef long int dw_offset
;
2510 /* Define typedefs here to avoid circular dependencies. */
2512 typedef struct dw_attr_struct
*dw_attr_ref
;
2513 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2514 typedef struct pubname_struct
*pubname_ref
;
2515 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2516 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2517 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2519 /* The entries in the line_info table more-or-less mirror the opcodes
2520 that are used in the real dwarf line table. Arrays of these entries
2521 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2524 enum dw_line_info_opcode
{
2525 /* Emit DW_LNE_set_address; the operand is the label index. */
2528 /* Emit a row to the matrix with the given line. This may be done
2529 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2533 /* Emit a DW_LNS_set_file. */
2536 /* Emit a DW_LNS_set_column. */
2539 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2542 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2543 LI_set_prologue_end
,
2544 LI_set_epilogue_begin
,
2546 /* Emit a DW_LNE_set_discriminator. */
2547 LI_set_discriminator
2550 typedef struct GTY(()) dw_line_info_struct
{
2551 enum dw_line_info_opcode opcode
;
2553 } dw_line_info_entry
;
2556 typedef struct GTY(()) dw_line_info_table_struct
{
2557 /* The label that marks the end of this section. */
2558 const char *end_label
;
2560 /* The values for the last row of the matrix, as collected in the table.
2561 These are used to minimize the changes to the next row. */
2562 unsigned int file_num
;
2563 unsigned int line_num
;
2564 unsigned int column_num
;
2569 vec
<dw_line_info_entry
, va_gc
> *entries
;
2570 } dw_line_info_table
;
2572 typedef dw_line_info_table
*dw_line_info_table_p
;
2575 /* Each DIE attribute has a field specifying the attribute kind,
2576 a link to the next attribute in the chain, and an attribute value.
2577 Attributes are typically linked below the DIE they modify. */
2579 typedef struct GTY(()) dw_attr_struct
{
2580 enum dwarf_attribute dw_attr
;
2581 dw_val_node dw_attr_val
;
2586 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2587 The children of each node form a circular list linked by
2588 die_sib. die_child points to the node *before* the "first" child node. */
2590 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
2591 union die_symbol_or_type_node
2593 const char * GTY ((tag ("0"))) die_symbol
;
2594 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2596 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2597 vec
<dw_attr_node
, va_gc
> *die_attr
;
2598 dw_die_ref die_parent
;
2599 dw_die_ref die_child
;
2601 dw_die_ref die_definition
; /* ref from a specification to its definition */
2602 dw_offset die_offset
;
2603 unsigned long die_abbrev
;
2605 unsigned int decl_id
;
2606 enum dwarf_tag die_tag
;
2607 /* Die is used and must not be pruned as unused. */
2608 BOOL_BITFIELD die_perennial_p
: 1;
2609 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2610 /* Lots of spare bits. */
2614 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2615 #define FOR_EACH_CHILD(die, c, expr) do { \
2616 c = die->die_child; \
2620 } while (c != die->die_child); \
2623 /* The pubname structure */
2625 typedef struct GTY(()) pubname_struct
{
2632 struct GTY(()) dw_ranges_struct
{
2633 /* If this is positive, it's a block number, otherwise it's a
2634 bitwise-negated index into dw_ranges_by_label. */
2638 /* A structure to hold a macinfo entry. */
2640 typedef struct GTY(()) macinfo_struct
{
2642 unsigned HOST_WIDE_INT lineno
;
2648 struct GTY(()) dw_ranges_by_label_struct
{
2653 /* The comdat type node structure. */
2654 typedef struct GTY(()) comdat_type_struct
2656 dw_die_ref root_die
;
2657 dw_die_ref type_die
;
2658 dw_die_ref skeleton_die
;
2659 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2660 struct comdat_type_struct
*next
;
2664 /* The limbo die list structure. */
2665 typedef struct GTY(()) limbo_die_struct
{
2668 struct limbo_die_struct
*next
;
2672 typedef struct skeleton_chain_struct
2676 struct skeleton_chain_struct
*parent
;
2678 skeleton_chain_node
;
2680 /* Define a macro which returns nonzero for a TYPE_DECL which was
2681 implicitly generated for a type.
2683 Note that, unlike the C front-end (which generates a NULL named
2684 TYPE_DECL node for each complete tagged type, each array type,
2685 and each function type node created) the C++ front-end generates
2686 a _named_ TYPE_DECL node for each tagged type node created.
2687 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2688 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2689 front-end, but for each type, tagged or not. */
2691 #define TYPE_DECL_IS_STUB(decl) \
2692 (DECL_NAME (decl) == NULL_TREE \
2693 || (DECL_ARTIFICIAL (decl) \
2694 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2695 /* This is necessary for stub decls that \
2696 appear in nested inline functions. */ \
2697 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2698 && (decl_ultimate_origin (decl) \
2699 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2701 /* Information concerning the compilation unit's programming
2702 language, and compiler version. */
2704 /* Fixed size portion of the DWARF compilation unit header. */
2705 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2706 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2708 /* Fixed size portion of the DWARF comdat type unit header. */
2709 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2710 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2711 + DWARF_OFFSET_SIZE)
2713 /* Fixed size portion of public names info. */
2714 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2716 /* Fixed size portion of the address range info. */
2717 #define DWARF_ARANGES_HEADER_SIZE \
2718 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2719 DWARF2_ADDR_SIZE * 2) \
2720 - DWARF_INITIAL_LENGTH_SIZE)
2722 /* Size of padding portion in the address range info. It must be
2723 aligned to twice the pointer size. */
2724 #define DWARF_ARANGES_PAD_SIZE \
2725 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2726 DWARF2_ADDR_SIZE * 2) \
2727 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2729 /* Use assembler line directives if available. */
2730 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2731 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2732 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2734 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2738 /* Minimum line offset in a special line info. opcode.
2739 This value was chosen to give a reasonable range of values. */
2740 #define DWARF_LINE_BASE -10
2742 /* First special line opcode - leave room for the standard opcodes. */
2743 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2745 /* Range of line offsets in a special line info. opcode. */
2746 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2748 /* Flag that indicates the initial value of the is_stmt_start flag.
2749 In the present implementation, we do not mark any lines as
2750 the beginning of a source statement, because that information
2751 is not made available by the GCC front-end. */
2752 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2754 /* Maximum number of operations per instruction bundle. */
2755 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2756 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2759 /* This location is used by calc_die_sizes() to keep track
2760 the offset of each DIE within the .debug_info section. */
2761 static unsigned long next_die_offset
;
2763 /* Record the root of the DIE's built for the current compilation unit. */
2764 static GTY(()) dw_die_ref single_comp_unit_die
;
2766 /* A list of type DIEs that have been separated into comdat sections. */
2767 static GTY(()) comdat_type_node
*comdat_type_list
;
2769 /* A list of DIEs with a NULL parent waiting to be relocated. */
2770 static GTY(()) limbo_die_node
*limbo_die_list
;
2772 /* A list of DIEs for which we may have to generate
2773 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2774 static GTY(()) limbo_die_node
*deferred_asm_name
;
2776 /* Filenames referenced by this compilation unit. */
2777 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
2779 /* A hash table of references to DIE's that describe declarations.
2780 The key is a DECL_UID() which is a unique number identifying each decl. */
2781 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
2783 /* A hash table of references to DIE's that describe COMMON blocks.
2784 The key is DECL_UID() ^ die_parent. */
2785 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
2787 typedef struct GTY(()) die_arg_entry_struct
{
2793 /* Node of the variable location list. */
2794 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2795 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2796 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2797 in mode of the EXPR_LIST node and first EXPR_LIST operand
2798 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2799 location or NULL for padding. For larger bitsizes,
2800 mode is 0 and first operand is a CONCAT with bitsize
2801 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2802 NULL as second operand. */
2804 const char * GTY (()) label
;
2805 struct var_loc_node
* GTY (()) next
;
2808 /* Variable location list. */
2809 struct GTY (()) var_loc_list_def
{
2810 struct var_loc_node
* GTY (()) first
;
2812 /* Pointer to the last but one or last element of the
2813 chained list. If the list is empty, both first and
2814 last are NULL, if the list contains just one node
2815 or the last node certainly is not redundant, it points
2816 to the last node, otherwise points to the last but one.
2817 Do not mark it for GC because it is marked through the chain. */
2818 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2820 /* Pointer to the last element before section switch,
2821 if NULL, either sections weren't switched or first
2822 is after section switch. */
2823 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2825 /* DECL_UID of the variable decl. */
2826 unsigned int decl_id
;
2828 typedef struct var_loc_list_def var_loc_list
;
2830 /* Call argument location list. */
2831 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2832 rtx
GTY (()) call_arg_loc_note
;
2833 const char * GTY (()) label
;
2834 tree
GTY (()) block
;
2836 rtx
GTY (()) symbol_ref
;
2837 struct call_arg_loc_node
* GTY (()) next
;
2841 /* Table of decl location linked lists. */
2842 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
2844 /* Head and tail of call_arg_loc chain. */
2845 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2846 static struct call_arg_loc_node
*call_arg_loc_last
;
2848 /* Number of call sites in the current function. */
2849 static int call_site_count
= -1;
2850 /* Number of tail call sites in the current function. */
2851 static int tail_call_site_count
= -1;
2853 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2855 static vec
<dw_die_ref
> block_map
;
2857 /* A cached location list. */
2858 struct GTY (()) cached_dw_loc_list_def
{
2859 /* The DECL_UID of the decl that this entry describes. */
2860 unsigned int decl_id
;
2862 /* The cached location list. */
2863 dw_loc_list_ref loc_list
;
2865 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2867 /* Table of cached location lists. */
2868 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
2870 /* A pointer to the base of a list of references to DIE's that
2871 are uniquely identified by their tag, presence/absence of
2872 children DIE's, and list of attribute/value pairs. */
2873 static GTY((length ("abbrev_die_table_allocated")))
2874 dw_die_ref
*abbrev_die_table
;
2876 /* Number of elements currently allocated for abbrev_die_table. */
2877 static GTY(()) unsigned abbrev_die_table_allocated
;
2879 /* Number of elements in type_die_table currently in use. */
2880 static GTY(()) unsigned abbrev_die_table_in_use
;
2882 /* Size (in elements) of increments by which we may expand the
2883 abbrev_die_table. */
2884 #define ABBREV_DIE_TABLE_INCREMENT 256
2886 /* A global counter for generating labels for line number data. */
2887 static unsigned int line_info_label_num
;
2889 /* The current table to which we should emit line number information
2890 for the current function. This will be set up at the beginning of
2891 assembly for the function. */
2892 static dw_line_info_table
*cur_line_info_table
;
2894 /* The two default tables of line number info. */
2895 static GTY(()) dw_line_info_table
*text_section_line_info
;
2896 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2898 /* The set of all non-default tables of line number info. */
2899 static GTY(()) vec
<dw_line_info_table_p
, va_gc
> *separate_line_info
;
2901 /* A flag to tell pubnames/types export if there is an info section to
2903 static bool info_section_emitted
;
2905 /* A pointer to the base of a table that contains a list of publicly
2906 accessible names. */
2907 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2909 /* A pointer to the base of a table that contains a list of publicly
2910 accessible types. */
2911 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
2913 /* A pointer to the base of a table that contains a list of macro
2914 defines/undefines (and file start/end markers). */
2915 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
2917 /* True if .debug_macinfo or .debug_macros section is going to be
2919 #define have_macinfo \
2920 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2921 && !macinfo_table->is_empty ())
2923 /* Array of dies for which we should generate .debug_ranges info. */
2924 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2926 /* Number of elements currently allocated for ranges_table. */
2927 static GTY(()) unsigned ranges_table_allocated
;
2929 /* Number of elements in ranges_table currently in use. */
2930 static GTY(()) unsigned ranges_table_in_use
;
2932 /* Array of pairs of labels referenced in ranges_table. */
2933 static GTY ((length ("ranges_by_label_allocated")))
2934 dw_ranges_by_label_ref ranges_by_label
;
2936 /* Number of elements currently allocated for ranges_by_label. */
2937 static GTY(()) unsigned ranges_by_label_allocated
;
2939 /* Number of elements in ranges_by_label currently in use. */
2940 static GTY(()) unsigned ranges_by_label_in_use
;
2942 /* Size (in elements) of increments by which we may expand the
2944 #define RANGES_TABLE_INCREMENT 64
2946 /* Whether we have location lists that need outputting */
2947 static GTY(()) bool have_location_lists
;
2949 /* Unique label counter. */
2950 static GTY(()) unsigned int loclabel_num
;
2952 /* Unique label counter for point-of-call tables. */
2953 static GTY(()) unsigned int poc_label_num
;
2955 /* Record whether the function being analyzed contains inlined functions. */
2956 static int current_function_has_inlines
;
2958 /* The last file entry emitted by maybe_emit_file(). */
2959 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
2961 /* Number of internal labels generated by gen_internal_sym(). */
2962 static GTY(()) int label_num
;
2964 /* Cached result of previous call to lookup_filename. */
2965 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
2967 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
2969 /* Instances of generic types for which we need to generate debug
2970 info that describe their generic parameters and arguments. That
2971 generation needs to happen once all types are properly laid out so
2972 we do it at the end of compilation. */
2973 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
2975 /* Offset from the "steady-state frame pointer" to the frame base,
2976 within the current function. */
2977 static HOST_WIDE_INT frame_pointer_fb_offset
;
2978 static bool frame_pointer_fb_offset_valid
;
2980 static vec
<dw_die_ref
> base_types
;
2982 /* Forward declarations for functions defined in this file. */
2984 static int is_pseudo_reg (const_rtx
);
2985 static tree
type_main_variant (tree
);
2986 static int is_tagged_type (const_tree
);
2987 static const char *dwarf_tag_name (unsigned);
2988 static const char *dwarf_attr_name (unsigned);
2989 static const char *dwarf_form_name (unsigned);
2990 static tree
decl_ultimate_origin (const_tree
);
2991 static tree
decl_class_context (tree
);
2992 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
2993 static inline enum dw_val_class
AT_class (dw_attr_ref
);
2994 static inline unsigned int AT_index (dw_attr_ref
);
2995 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
2996 static inline unsigned AT_flag (dw_attr_ref
);
2997 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
2998 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
2999 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3000 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
3001 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3002 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3003 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3004 unsigned int, unsigned char *);
3005 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3006 static hashval_t
debug_str_do_hash (const void *);
3007 static int debug_str_eq (const void *, const void *);
3008 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3009 static inline const char *AT_string (dw_attr_ref
);
3010 static enum dwarf_form
AT_string_form (dw_attr_ref
);
3011 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3012 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3013 static inline dw_die_ref
AT_ref (dw_attr_ref
);
3014 static inline int AT_ref_external (dw_attr_ref
);
3015 static inline void set_AT_ref_external (dw_attr_ref
, int);
3016 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3017 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3018 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
3019 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3021 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
3022 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3023 static void remove_addr_table_entry (addr_table_entry
*);
3024 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3025 static inline rtx
AT_addr (dw_attr_ref
);
3026 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3027 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3028 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3029 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3030 unsigned HOST_WIDE_INT
);
3031 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3032 unsigned long, bool);
3033 static inline const char *AT_lbl (dw_attr_ref
);
3034 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
3035 static const char *get_AT_low_pc (dw_die_ref
);
3036 static const char *get_AT_hi_pc (dw_die_ref
);
3037 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3038 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3039 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3040 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3041 static bool is_cxx (void);
3042 static bool is_fortran (void);
3043 static bool is_ada (void);
3044 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
3045 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3046 static void add_child_die (dw_die_ref
, dw_die_ref
);
3047 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3048 static dw_die_ref
lookup_type_die (tree
);
3049 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3050 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3051 static void equate_type_number_to_die (tree
, dw_die_ref
);
3052 static hashval_t
decl_die_table_hash (const void *);
3053 static int decl_die_table_eq (const void *, const void *);
3054 static dw_die_ref
lookup_decl_die (tree
);
3055 static hashval_t
common_block_die_table_hash (const void *);
3056 static int common_block_die_table_eq (const void *, const void *);
3057 static hashval_t
decl_loc_table_hash (const void *);
3058 static int decl_loc_table_eq (const void *, const void *);
3059 static var_loc_list
*lookup_decl_loc (const_tree
);
3060 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3061 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3062 static void print_spaces (FILE *);
3063 static void print_die (dw_die_ref
, FILE *);
3064 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3065 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3066 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3067 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3068 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3069 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3070 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3071 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3072 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
3073 struct md5_ctx
*, int *);
3074 struct checksum_attributes
;
3075 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3076 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3077 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3078 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3079 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3080 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3081 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3082 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3083 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3084 static void compute_section_prefix (dw_die_ref
);
3085 static int is_type_die (dw_die_ref
);
3086 static int is_comdat_die (dw_die_ref
);
3087 static int is_symbol_die (dw_die_ref
);
3088 static inline bool is_template_instantiation (dw_die_ref
);
3089 static void assign_symbol_names (dw_die_ref
);
3090 static void break_out_includes (dw_die_ref
);
3091 static int is_declaration_die (dw_die_ref
);
3092 static int should_move_die_to_comdat (dw_die_ref
);
3093 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3094 static dw_die_ref
clone_die (dw_die_ref
);
3095 static dw_die_ref
clone_tree (dw_die_ref
);
3096 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3097 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3098 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3099 static dw_die_ref
generate_skeleton (dw_die_ref
);
3100 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3103 static void break_out_comdat_types (dw_die_ref
);
3104 static void copy_decls_for_unworthy_types (dw_die_ref
);
3106 static void add_sibling_attributes (dw_die_ref
);
3107 static void output_location_lists (dw_die_ref
);
3108 static int constant_size (unsigned HOST_WIDE_INT
);
3109 static unsigned long size_of_die (dw_die_ref
);
3110 static void calc_die_sizes (dw_die_ref
);
3111 static void calc_base_type_die_sizes (void);
3112 static void mark_dies (dw_die_ref
);
3113 static void unmark_dies (dw_die_ref
);
3114 static void unmark_all_dies (dw_die_ref
);
3115 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3116 static unsigned long size_of_aranges (void);
3117 static enum dwarf_form
value_format (dw_attr_ref
);
3118 static void output_value_format (dw_attr_ref
);
3119 static void output_abbrev_section (void);
3120 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3121 static void output_die_symbol (dw_die_ref
);
3122 static void output_die (dw_die_ref
);
3123 static void output_compilation_unit_header (void);
3124 static void output_comp_unit (dw_die_ref
, int);
3125 static void output_comdat_type_unit (comdat_type_node
*);
3126 static const char *dwarf2_name (tree
, int);
3127 static void add_pubname (tree
, dw_die_ref
);
3128 static void add_enumerator_pubname (const char *, dw_die_ref
);
3129 static void add_pubname_string (const char *, dw_die_ref
);
3130 static void add_pubtype (tree
, dw_die_ref
);
3131 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3132 static void output_aranges (unsigned long);
3133 static unsigned int add_ranges_num (int);
3134 static unsigned int add_ranges (const_tree
);
3135 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3137 static void output_ranges (void);
3138 static dw_line_info_table
*new_line_info_table (void);
3139 static void output_line_info (bool);
3140 static void output_file_names (void);
3141 static dw_die_ref
base_type_die (tree
);
3142 static int is_base_type (tree
);
3143 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3144 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3145 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3146 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3147 static int type_is_enum (const_tree
);
3148 static unsigned int dbx_reg_number (const_rtx
);
3149 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3150 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3151 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3152 enum var_init_status
);
3153 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3154 enum var_init_status
);
3155 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3156 enum var_init_status
);
3157 static int is_based_loc (const_rtx
);
3158 static int resolve_one_addr (rtx
*, void *);
3159 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3160 enum var_init_status
);
3161 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
3162 enum var_init_status
);
3163 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3164 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3165 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3166 static tree
field_type (const_tree
);
3167 static unsigned int simple_type_align_in_bits (const_tree
);
3168 static unsigned int simple_decl_align_in_bits (const_tree
);
3169 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3170 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3171 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3173 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3174 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3175 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3176 static void insert_wide_int (const wide_int
&, unsigned char *, int);
3177 static void insert_float (const_rtx
, unsigned char *);
3178 static rtx
rtl_for_decl_location (tree
);
3179 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3180 enum dwarf_attribute
);
3181 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3182 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3183 static void add_name_attribute (dw_die_ref
, const char *);
3184 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3185 static void add_comp_dir_attribute (dw_die_ref
);
3186 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3187 static void add_subscript_info (dw_die_ref
, tree
, bool);
3188 static void add_byte_size_attribute (dw_die_ref
, tree
);
3189 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3190 static void add_bit_size_attribute (dw_die_ref
, tree
);
3191 static void add_prototyped_attribute (dw_die_ref
, tree
);
3192 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3193 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3194 static void add_src_coords_attributes (dw_die_ref
, tree
);
3195 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3196 static void push_decl_scope (tree
);
3197 static void pop_decl_scope (void);
3198 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3199 static inline int local_scope_p (dw_die_ref
);
3200 static inline int class_scope_p (dw_die_ref
);
3201 static inline int class_or_namespace_scope_p (dw_die_ref
);
3202 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3203 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3204 static const char *type_tag (const_tree
);
3205 static tree
member_declared_type (const_tree
);
3207 static const char *decl_start_label (tree
);
3209 static void gen_array_type_die (tree
, dw_die_ref
);
3210 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3212 static void gen_entry_point_die (tree
, dw_die_ref
);
3214 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3215 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3216 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3217 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3218 static void gen_formal_types_die (tree
, dw_die_ref
);
3219 static void gen_subprogram_die (tree
, dw_die_ref
);
3220 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3221 static void gen_const_die (tree
, dw_die_ref
);
3222 static void gen_label_die (tree
, dw_die_ref
);
3223 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3224 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3225 static void gen_field_die (tree
, dw_die_ref
);
3226 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3227 static dw_die_ref
gen_compile_unit_die (const char *);
3228 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3229 static void gen_member_die (tree
, dw_die_ref
);
3230 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3231 enum debug_info_usage
);
3232 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3233 static void gen_typedef_die (tree
, dw_die_ref
);
3234 static void gen_type_die (tree
, dw_die_ref
);
3235 static void gen_block_die (tree
, dw_die_ref
, int);
3236 static void decls_for_scope (tree
, dw_die_ref
, int);
3237 static inline int is_redundant_typedef (const_tree
);
3238 static bool is_naming_typedef_decl (const_tree
);
3239 static inline dw_die_ref
get_context_die (tree
);
3240 static void gen_namespace_die (tree
, dw_die_ref
);
3241 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3242 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3243 static dw_die_ref
force_decl_die (tree
);
3244 static dw_die_ref
force_type_die (tree
);
3245 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3246 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3247 static struct dwarf_file_data
* lookup_filename (const char *);
3248 static void retry_incomplete_types (void);
3249 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3250 static void gen_generic_params_dies (tree
);
3251 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3252 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3253 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3254 static int file_info_cmp (const void *, const void *);
3255 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3256 const char *, const char *);
3257 static void output_loc_list (dw_loc_list_ref
);
3258 static char *gen_internal_sym (const char *);
3259 static bool want_pubnames (void);
3261 static void prune_unmark_dies (dw_die_ref
);
3262 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3263 static void prune_unused_types_mark (dw_die_ref
, int);
3264 static void prune_unused_types_walk (dw_die_ref
);
3265 static void prune_unused_types_walk_attribs (dw_die_ref
);
3266 static void prune_unused_types_prune (dw_die_ref
);
3267 static void prune_unused_types (void);
3268 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3269 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3270 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3271 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3272 const char *, const char *);
3273 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3274 static void gen_remaining_tmpl_value_param_die_attribute (void);
3275 static bool generic_type_p (tree
);
3276 static void schedule_generic_params_dies_gen (tree t
);
3277 static void gen_scheduled_generic_parms_dies (void);
3279 static const char *comp_dir_string (void);
3281 static void hash_loc_operands (dw_loc_descr_ref
, inchash::hash
&);
3283 /* enum for tracking thread-local variables whose address is really an offset
3284 relative to the TLS pointer, which will need link-time relocation, but will
3285 not need relocation by the DWARF consumer. */
3293 /* Return the operator to use for an address of a variable. For dtprel_true, we
3294 use DW_OP_const*. For regular variables, which need both link-time
3295 relocation and consumer-level relocation (e.g., to account for shared objects
3296 loaded at a random address), we use DW_OP_addr*. */
3298 static inline enum dwarf_location_atom
3299 dw_addr_op (enum dtprel_bool dtprel
)
3301 if (dtprel
== dtprel_true
)
3302 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3303 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3305 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3308 /* Return a pointer to a newly allocated address location description. If
3309 dwarf_split_debug_info is true, then record the address with the appropriate
3311 static inline dw_loc_descr_ref
3312 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3314 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3316 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3317 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3318 ref
->dtprel
= dtprel
;
3319 if (dwarf_split_debug_info
)
3320 ref
->dw_loc_oprnd1
.val_entry
3321 = add_addr_table_entry (addr
,
3322 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3324 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3329 /* Section names used to hold DWARF debugging information. */
3331 #ifndef DEBUG_INFO_SECTION
3332 #define DEBUG_INFO_SECTION ".debug_info"
3334 #ifndef DEBUG_DWO_INFO_SECTION
3335 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3337 #ifndef DEBUG_ABBREV_SECTION
3338 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3340 #ifndef DEBUG_DWO_ABBREV_SECTION
3341 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3343 #ifndef DEBUG_ARANGES_SECTION
3344 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3346 #ifndef DEBUG_ADDR_SECTION
3347 #define DEBUG_ADDR_SECTION ".debug_addr"
3349 #ifndef DEBUG_NORM_MACINFO_SECTION
3350 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3352 #ifndef DEBUG_DWO_MACINFO_SECTION
3353 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3355 #ifndef DEBUG_MACINFO_SECTION
3356 #define DEBUG_MACINFO_SECTION \
3357 (!dwarf_split_debug_info \
3358 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3360 #ifndef DEBUG_NORM_MACRO_SECTION
3361 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3363 #ifndef DEBUG_DWO_MACRO_SECTION
3364 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3366 #ifndef DEBUG_MACRO_SECTION
3367 #define DEBUG_MACRO_SECTION \
3368 (!dwarf_split_debug_info \
3369 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3371 #ifndef DEBUG_LINE_SECTION
3372 #define DEBUG_LINE_SECTION ".debug_line"
3374 #ifndef DEBUG_DWO_LINE_SECTION
3375 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3377 #ifndef DEBUG_LOC_SECTION
3378 #define DEBUG_LOC_SECTION ".debug_loc"
3380 #ifndef DEBUG_DWO_LOC_SECTION
3381 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3383 #ifndef DEBUG_PUBNAMES_SECTION
3384 #define DEBUG_PUBNAMES_SECTION \
3385 ((debug_generate_pub_sections == 2) \
3386 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3388 #ifndef DEBUG_PUBTYPES_SECTION
3389 #define DEBUG_PUBTYPES_SECTION \
3390 ((debug_generate_pub_sections == 2) \
3391 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3393 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3394 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3395 #ifndef DEBUG_STR_OFFSETS_SECTION
3396 #define DEBUG_STR_OFFSETS_SECTION \
3397 (!dwarf_split_debug_info \
3398 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3400 #ifndef DEBUG_STR_DWO_SECTION
3401 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3403 #ifndef DEBUG_STR_SECTION
3404 #define DEBUG_STR_SECTION ".debug_str"
3406 #ifndef DEBUG_RANGES_SECTION
3407 #define DEBUG_RANGES_SECTION ".debug_ranges"
3410 /* Standard ELF section names for compiled code and data. */
3411 #ifndef TEXT_SECTION_NAME
3412 #define TEXT_SECTION_NAME ".text"
3415 /* Section flags for .debug_macinfo/.debug_macro section. */
3416 #define DEBUG_MACRO_SECTION_FLAGS \
3417 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3419 /* Section flags for .debug_str section. */
3420 #define DEBUG_STR_SECTION_FLAGS \
3421 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3422 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3425 /* Section flags for .debug_str.dwo section. */
3426 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3428 /* Labels we insert at beginning sections we can reference instead of
3429 the section names themselves. */
3431 #ifndef TEXT_SECTION_LABEL
3432 #define TEXT_SECTION_LABEL "Ltext"
3434 #ifndef COLD_TEXT_SECTION_LABEL
3435 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3437 #ifndef DEBUG_LINE_SECTION_LABEL
3438 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3440 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3441 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3443 #ifndef DEBUG_INFO_SECTION_LABEL
3444 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3446 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3447 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3449 #ifndef DEBUG_ABBREV_SECTION_LABEL
3450 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3452 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3453 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3455 #ifndef DEBUG_ADDR_SECTION_LABEL
3456 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3458 #ifndef DEBUG_LOC_SECTION_LABEL
3459 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3461 #ifndef DEBUG_RANGES_SECTION_LABEL
3462 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3464 #ifndef DEBUG_MACINFO_SECTION_LABEL
3465 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3467 #ifndef DEBUG_MACRO_SECTION_LABEL
3468 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3470 #define SKELETON_COMP_DIE_ABBREV 1
3471 #define SKELETON_TYPE_DIE_ABBREV 2
3473 /* Definitions of defaults for formats and names of various special
3474 (artificial) labels which may be generated within this file (when the -g
3475 options is used and DWARF2_DEBUGGING_INFO is in effect.
3476 If necessary, these may be overridden from within the tm.h file, but
3477 typically, overriding these defaults is unnecessary. */
3479 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3480 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3481 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3482 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3483 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3484 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3485 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3486 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3487 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3488 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3489 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3490 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3491 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3492 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3494 #ifndef TEXT_END_LABEL
3495 #define TEXT_END_LABEL "Letext"
3497 #ifndef COLD_END_LABEL
3498 #define COLD_END_LABEL "Letext_cold"
3500 #ifndef BLOCK_BEGIN_LABEL
3501 #define BLOCK_BEGIN_LABEL "LBB"
3503 #ifndef BLOCK_END_LABEL
3504 #define BLOCK_END_LABEL "LBE"
3506 #ifndef LINE_CODE_LABEL
3507 #define LINE_CODE_LABEL "LM"
3511 /* Return the root of the DIE's built for the current compilation unit. */
3513 comp_unit_die (void)
3515 if (!single_comp_unit_die
)
3516 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3517 return single_comp_unit_die
;
3520 /* We allow a language front-end to designate a function that is to be
3521 called to "demangle" any name before it is put into a DIE. */
3523 static const char *(*demangle_name_func
) (const char *);
3526 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3528 demangle_name_func
= func
;
3531 /* Test if rtl node points to a pseudo register. */
3534 is_pseudo_reg (const_rtx rtl
)
3536 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3537 || (GET_CODE (rtl
) == SUBREG
3538 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3541 /* Return a reference to a type, with its const and volatile qualifiers
3545 type_main_variant (tree type
)
3547 type
= TYPE_MAIN_VARIANT (type
);
3549 /* ??? There really should be only one main variant among any group of
3550 variants of a given type (and all of the MAIN_VARIANT values for all
3551 members of the group should point to that one type) but sometimes the C
3552 front-end messes this up for array types, so we work around that bug
3554 if (TREE_CODE (type
) == ARRAY_TYPE
)
3555 while (type
!= TYPE_MAIN_VARIANT (type
))
3556 type
= TYPE_MAIN_VARIANT (type
);
3561 /* Return nonzero if the given type node represents a tagged type. */
3564 is_tagged_type (const_tree type
)
3566 enum tree_code code
= TREE_CODE (type
);
3568 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3569 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3572 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3575 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3577 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3580 /* Return die_offset of a DIE reference to a base type. */
3582 static unsigned long int
3583 get_base_type_offset (dw_die_ref ref
)
3585 if (ref
->die_offset
)
3586 return ref
->die_offset
;
3587 if (comp_unit_die ()->die_abbrev
)
3589 calc_base_type_die_sizes ();
3590 gcc_assert (ref
->die_offset
);
3592 return ref
->die_offset
;
3595 /* Return die_offset of a DIE reference other than base type. */
3597 static unsigned long int
3598 get_ref_die_offset (dw_die_ref ref
)
3600 gcc_assert (ref
->die_offset
);
3601 return ref
->die_offset
;
3604 /* Convert a DIE tag into its string name. */
3607 dwarf_tag_name (unsigned int tag
)
3609 const char *name
= get_DW_TAG_name (tag
);
3614 return "DW_TAG_<unknown>";
3617 /* Convert a DWARF attribute code into its string name. */
3620 dwarf_attr_name (unsigned int attr
)
3626 #if VMS_DEBUGGING_INFO
3627 case DW_AT_HP_prologue
:
3628 return "DW_AT_HP_prologue";
3630 case DW_AT_MIPS_loop_unroll_factor
:
3631 return "DW_AT_MIPS_loop_unroll_factor";
3634 #if VMS_DEBUGGING_INFO
3635 case DW_AT_HP_epilogue
:
3636 return "DW_AT_HP_epilogue";
3638 case DW_AT_MIPS_stride
:
3639 return "DW_AT_MIPS_stride";
3643 name
= get_DW_AT_name (attr
);
3648 return "DW_AT_<unknown>";
3651 /* Convert a DWARF value form code into its string name. */
3654 dwarf_form_name (unsigned int form
)
3656 const char *name
= get_DW_FORM_name (form
);
3661 return "DW_FORM_<unknown>";
3664 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3665 instance of an inlined instance of a decl which is local to an inline
3666 function, so we have to trace all of the way back through the origin chain
3667 to find out what sort of node actually served as the original seed for the
3671 decl_ultimate_origin (const_tree decl
)
3673 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3676 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3677 nodes in the function to point to themselves; ignore that if
3678 we're trying to output the abstract instance of this function. */
3679 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3682 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3683 most distant ancestor, this should never happen. */
3684 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3686 return DECL_ABSTRACT_ORIGIN (decl
);
3689 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3690 of a virtual function may refer to a base class, so we check the 'this'
3694 decl_class_context (tree decl
)
3696 tree context
= NULL_TREE
;
3698 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3699 context
= DECL_CONTEXT (decl
);
3701 context
= TYPE_MAIN_VARIANT
3702 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3704 if (context
&& !TYPE_P (context
))
3705 context
= NULL_TREE
;
3710 /* Add an attribute/value pair to a DIE. */
3713 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3715 /* Maybe this should be an assert? */
3719 vec_safe_reserve (die
->die_attr
, 1);
3720 vec_safe_push (die
->die_attr
, *attr
);
3723 static inline enum dw_val_class
3724 AT_class (dw_attr_ref a
)
3726 return a
->dw_attr_val
.val_class
;
3729 /* Return the index for any attribute that will be referenced with a
3730 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3731 are stored in dw_attr_val.v.val_str for reference counting
3734 static inline unsigned int
3735 AT_index (dw_attr_ref a
)
3737 if (AT_class (a
) == dw_val_class_str
)
3738 return a
->dw_attr_val
.v
.val_str
->index
;
3739 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3740 return a
->dw_attr_val
.val_entry
->index
;
3744 /* Add a flag value attribute to a DIE. */
3747 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3751 attr
.dw_attr
= attr_kind
;
3752 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3753 attr
.dw_attr_val
.val_entry
= NULL
;
3754 attr
.dw_attr_val
.v
.val_flag
= flag
;
3755 add_dwarf_attr (die
, &attr
);
3758 static inline unsigned
3759 AT_flag (dw_attr_ref a
)
3761 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3762 return a
->dw_attr_val
.v
.val_flag
;
3765 /* Add a signed integer attribute value to a DIE. */
3768 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3772 attr
.dw_attr
= attr_kind
;
3773 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3774 attr
.dw_attr_val
.val_entry
= NULL
;
3775 attr
.dw_attr_val
.v
.val_int
= int_val
;
3776 add_dwarf_attr (die
, &attr
);
3779 static inline HOST_WIDE_INT
3780 AT_int (dw_attr_ref a
)
3782 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3783 return a
->dw_attr_val
.v
.val_int
;
3786 /* Add an unsigned integer attribute value to a DIE. */
3789 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3790 unsigned HOST_WIDE_INT unsigned_val
)
3794 attr
.dw_attr
= attr_kind
;
3795 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3796 attr
.dw_attr_val
.val_entry
= NULL
;
3797 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3798 add_dwarf_attr (die
, &attr
);
3801 static inline unsigned HOST_WIDE_INT
3802 AT_unsigned (dw_attr_ref a
)
3804 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3805 return a
->dw_attr_val
.v
.val_unsigned
;
3808 /* Add an unsigned wide integer attribute value to a DIE. */
3811 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3816 attr
.dw_attr
= attr_kind
;
3817 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
3818 attr
.dw_attr_val
.v
.val_wide
= ggc_cleared_alloc
<wide_int
> ();
3819 *attr
.dw_attr_val
.v
.val_wide
= w
;
3820 add_dwarf_attr (die
, &attr
);
3823 /* Add an unsigned double integer attribute value to a DIE. */
3826 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3827 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3831 attr
.dw_attr
= attr_kind
;
3832 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3833 attr
.dw_attr_val
.val_entry
= NULL
;
3834 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3835 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3836 add_dwarf_attr (die
, &attr
);
3839 /* Add a floating point attribute value to a DIE and return it. */
3842 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3843 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3847 attr
.dw_attr
= attr_kind
;
3848 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3849 attr
.dw_attr_val
.val_entry
= NULL
;
3850 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3851 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3852 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3853 add_dwarf_attr (die
, &attr
);
3856 /* Add an 8-byte data attribute value to a DIE. */
3859 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3860 unsigned char data8
[8])
3864 attr
.dw_attr
= attr_kind
;
3865 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3866 attr
.dw_attr_val
.val_entry
= NULL
;
3867 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3868 add_dwarf_attr (die
, &attr
);
3871 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3872 dwarf_split_debug_info, address attributes in dies destined for the
3873 final executable have force_direct set to avoid using indexed
3877 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3883 lbl_id
= xstrdup (lbl_low
);
3884 attr
.dw_attr
= DW_AT_low_pc
;
3885 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3886 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3887 if (dwarf_split_debug_info
&& !force_direct
)
3888 attr
.dw_attr_val
.val_entry
3889 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3891 attr
.dw_attr_val
.val_entry
= NULL
;
3892 add_dwarf_attr (die
, &attr
);
3894 attr
.dw_attr
= DW_AT_high_pc
;
3895 if (dwarf_version
< 4)
3896 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3898 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3899 lbl_id
= xstrdup (lbl_high
);
3900 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3901 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3902 && dwarf_split_debug_info
&& !force_direct
)
3903 attr
.dw_attr_val
.val_entry
3904 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3906 attr
.dw_attr_val
.val_entry
= NULL
;
3907 add_dwarf_attr (die
, &attr
);
3910 /* Hash and equality functions for debug_str_hash. */
3913 debug_str_do_hash (const void *x
)
3915 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
3919 debug_str_eq (const void *x1
, const void *x2
)
3921 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
3922 (const char *)x2
) == 0;
3925 /* Add STR to the given string hash table. */
3927 static struct indirect_string_node
*
3928 find_AT_string_in_table (const char *str
, htab_t table
)
3930 struct indirect_string_node
*node
;
3933 slot
= htab_find_slot_with_hash (table
, str
,
3934 htab_hash_string (str
), INSERT
);
3937 node
= ggc_cleared_alloc
<indirect_string_node
> ();
3938 node
->str
= ggc_strdup (str
);
3942 node
= (struct indirect_string_node
*) *slot
;
3948 /* Add STR to the indirect string hash table. */
3950 static struct indirect_string_node
*
3951 find_AT_string (const char *str
)
3953 if (! debug_str_hash
)
3954 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
3955 debug_str_eq
, NULL
);
3957 return find_AT_string_in_table (str
, debug_str_hash
);
3960 /* Add a string attribute value to a DIE. */
3963 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
3966 struct indirect_string_node
*node
;
3968 node
= find_AT_string (str
);
3970 attr
.dw_attr
= attr_kind
;
3971 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
3972 attr
.dw_attr_val
.val_entry
= NULL
;
3973 attr
.dw_attr_val
.v
.val_str
= node
;
3974 add_dwarf_attr (die
, &attr
);
3977 static inline const char *
3978 AT_string (dw_attr_ref a
)
3980 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3981 return a
->dw_attr_val
.v
.val_str
->str
;
3984 /* Call this function directly to bypass AT_string_form's logic to put
3985 the string inline in the die. */
3988 set_indirect_string (struct indirect_string_node
*node
)
3991 /* Already indirect is a no op. */
3992 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
3994 gcc_assert (node
->label
);
3997 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
3998 ++dw2_string_counter
;
3999 node
->label
= xstrdup (label
);
4001 if (!dwarf_split_debug_info
)
4003 node
->form
= DW_FORM_strp
;
4004 node
->index
= NOT_INDEXED
;
4008 node
->form
= DW_FORM_GNU_str_index
;
4009 node
->index
= NO_INDEX_ASSIGNED
;
4013 /* Find out whether a string should be output inline in DIE
4014 or out-of-line in .debug_str section. */
4016 static enum dwarf_form
4017 find_string_form (struct indirect_string_node
*node
)
4024 len
= strlen (node
->str
) + 1;
4026 /* If the string is shorter or equal to the size of the reference, it is
4027 always better to put it inline. */
4028 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4029 return node
->form
= DW_FORM_string
;
4031 /* If we cannot expect the linker to merge strings in .debug_str
4032 section, only put it into .debug_str if it is worth even in this
4034 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4035 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4036 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4037 return node
->form
= DW_FORM_string
;
4039 set_indirect_string (node
);
4044 /* Find out whether the string referenced from the attribute should be
4045 output inline in DIE or out-of-line in .debug_str section. */
4047 static enum dwarf_form
4048 AT_string_form (dw_attr_ref a
)
4050 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4051 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4054 /* Add a DIE reference attribute value to a DIE. */
4057 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4061 #ifdef ENABLE_CHECKING
4062 gcc_assert (targ_die
!= NULL
);
4064 /* With LTO we can end up trying to reference something we didn't create
4065 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4066 if (targ_die
== NULL
)
4070 attr
.dw_attr
= attr_kind
;
4071 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4072 attr
.dw_attr_val
.val_entry
= NULL
;
4073 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4074 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4075 add_dwarf_attr (die
, &attr
);
4078 /* Change DIE reference REF to point to NEW_DIE instead. */
4081 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
4083 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4084 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4085 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4088 /* Add an AT_specification attribute to a DIE, and also make the back
4089 pointer from the specification to the definition. */
4092 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4094 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4095 gcc_assert (!targ_die
->die_definition
);
4096 targ_die
->die_definition
= die
;
4099 static inline dw_die_ref
4100 AT_ref (dw_attr_ref a
)
4102 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4103 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4107 AT_ref_external (dw_attr_ref a
)
4109 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4110 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4116 set_AT_ref_external (dw_attr_ref a
, int i
)
4118 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4119 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4122 /* Add an FDE reference attribute value to a DIE. */
4125 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4129 attr
.dw_attr
= attr_kind
;
4130 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4131 attr
.dw_attr_val
.val_entry
= NULL
;
4132 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4133 add_dwarf_attr (die
, &attr
);
4136 /* Add a location description attribute value to a DIE. */
4139 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4143 attr
.dw_attr
= attr_kind
;
4144 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4145 attr
.dw_attr_val
.val_entry
= NULL
;
4146 attr
.dw_attr_val
.v
.val_loc
= loc
;
4147 add_dwarf_attr (die
, &attr
);
4150 static inline dw_loc_descr_ref
4151 AT_loc (dw_attr_ref a
)
4153 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4154 return a
->dw_attr_val
.v
.val_loc
;
4158 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4162 attr
.dw_attr
= attr_kind
;
4163 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4164 attr
.dw_attr_val
.val_entry
= NULL
;
4165 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4166 add_dwarf_attr (die
, &attr
);
4167 have_location_lists
= true;
4170 static inline dw_loc_list_ref
4171 AT_loc_list (dw_attr_ref a
)
4173 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4174 return a
->dw_attr_val
.v
.val_loc_list
;
4177 static inline dw_loc_list_ref
*
4178 AT_loc_list_ptr (dw_attr_ref a
)
4180 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4181 return &a
->dw_attr_val
.v
.val_loc_list
;
4184 /* Table of entries into the .debug_addr section. */
4186 static GTY ((param_is (addr_table_entry
))) htab_t addr_index_table
;
4188 /* Hash an address_table_entry. */
4191 addr_table_entry_do_hash (const void *x
)
4193 const addr_table_entry
*a
= (const addr_table_entry
*) x
;
4194 inchash::hash hstate
;
4200 case ate_kind_rtx_dtprel
:
4203 case ate_kind_label
:
4204 return htab_hash_string (a
->addr
.label
);
4208 inchash::add_rtx (a
->addr
.rtl
, hstate
);
4209 return hstate
.end ();
4212 /* Determine equality for two address_table_entries. */
4215 addr_table_entry_eq (const void *x1
, const void *x2
)
4217 const addr_table_entry
*a1
= (const addr_table_entry
*) x1
;
4218 const addr_table_entry
*a2
= (const addr_table_entry
*) x2
;
4220 if (a1
->kind
!= a2
->kind
)
4225 case ate_kind_rtx_dtprel
:
4226 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4227 case ate_kind_label
:
4228 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4234 /* Initialize an addr_table_entry. */
4237 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4243 case ate_kind_rtx_dtprel
:
4244 e
->addr
.rtl
= (rtx
) addr
;
4246 case ate_kind_label
:
4247 e
->addr
.label
= (char *) addr
;
4251 e
->index
= NO_INDEX_ASSIGNED
;
4254 /* Add attr to the address table entry to the table. Defer setting an
4255 index until output time. */
4257 static addr_table_entry
*
4258 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4260 addr_table_entry
*node
;
4261 addr_table_entry finder
;
4264 gcc_assert (dwarf_split_debug_info
);
4265 if (! addr_index_table
)
4266 addr_index_table
= htab_create_ggc (10, addr_table_entry_do_hash
,
4267 addr_table_entry_eq
, NULL
);
4268 init_addr_table_entry (&finder
, kind
, addr
);
4269 slot
= htab_find_slot (addr_index_table
, &finder
, INSERT
);
4271 if (*slot
== HTAB_EMPTY_ENTRY
)
4273 node
= ggc_cleared_alloc
<addr_table_entry
> ();
4274 init_addr_table_entry (node
, kind
, addr
);
4278 node
= (addr_table_entry
*) *slot
;
4284 /* Remove an entry from the addr table by decrementing its refcount.
4285 Strictly, decrementing the refcount would be enough, but the
4286 assertion that the entry is actually in the table has found
4290 remove_addr_table_entry (addr_table_entry
*entry
)
4292 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4293 /* After an index is assigned, the table is frozen. */
4294 gcc_assert (entry
->refcount
> 0 && entry
->index
== NO_INDEX_ASSIGNED
);
4298 /* Given a location list, remove all addresses it refers to from the
4302 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4304 for (; descr
; descr
= descr
->dw_loc_next
)
4305 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4307 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4308 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4312 /* A helper function for dwarf2out_finish called through
4313 htab_traverse. Assign an addr_table_entry its index. All entries
4314 must be collected into the table when this function is called,
4315 because the indexing code relies on htab_traverse to traverse nodes
4316 in the same order for each run. */
4319 index_addr_table_entry (void **h
, void *v
)
4321 addr_table_entry
*node
= (addr_table_entry
*) *h
;
4322 unsigned int *index
= (unsigned int *) v
;
4324 /* Don't index unreferenced nodes. */
4325 if (node
->refcount
== 0)
4328 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4329 node
->index
= *index
;
4335 /* Add an address constant attribute value to a DIE. When using
4336 dwarf_split_debug_info, address attributes in dies destined for the
4337 final executable should be direct references--setting the parameter
4338 force_direct ensures this behavior. */
4341 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4346 attr
.dw_attr
= attr_kind
;
4347 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4348 attr
.dw_attr_val
.v
.val_addr
= addr
;
4349 if (dwarf_split_debug_info
&& !force_direct
)
4350 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4352 attr
.dw_attr_val
.val_entry
= NULL
;
4353 add_dwarf_attr (die
, &attr
);
4356 /* Get the RTX from to an address DIE attribute. */
4359 AT_addr (dw_attr_ref a
)
4361 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4362 return a
->dw_attr_val
.v
.val_addr
;
4365 /* Add a file attribute value to a DIE. */
4368 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4369 struct dwarf_file_data
*fd
)
4373 attr
.dw_attr
= attr_kind
;
4374 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4375 attr
.dw_attr_val
.val_entry
= NULL
;
4376 attr
.dw_attr_val
.v
.val_file
= fd
;
4377 add_dwarf_attr (die
, &attr
);
4380 /* Get the dwarf_file_data from a file DIE attribute. */
4382 static inline struct dwarf_file_data
*
4383 AT_file (dw_attr_ref a
)
4385 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4386 return a
->dw_attr_val
.v
.val_file
;
4389 /* Add a vms delta attribute value to a DIE. */
4392 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4393 const char *lbl1
, const char *lbl2
)
4397 attr
.dw_attr
= attr_kind
;
4398 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4399 attr
.dw_attr_val
.val_entry
= NULL
;
4400 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4401 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4402 add_dwarf_attr (die
, &attr
);
4405 /* Add a label identifier attribute value to a DIE. */
4408 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4413 attr
.dw_attr
= attr_kind
;
4414 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4415 attr
.dw_attr_val
.val_entry
= NULL
;
4416 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4417 if (dwarf_split_debug_info
)
4418 attr
.dw_attr_val
.val_entry
4419 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4421 add_dwarf_attr (die
, &attr
);
4424 /* Add a section offset attribute value to a DIE, an offset into the
4425 debug_line section. */
4428 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4433 attr
.dw_attr
= attr_kind
;
4434 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4435 attr
.dw_attr_val
.val_entry
= NULL
;
4436 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4437 add_dwarf_attr (die
, &attr
);
4440 /* Add a section offset attribute value to a DIE, an offset into the
4441 debug_macinfo section. */
4444 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4449 attr
.dw_attr
= attr_kind
;
4450 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4451 attr
.dw_attr_val
.val_entry
= NULL
;
4452 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4453 add_dwarf_attr (die
, &attr
);
4456 /* Add an offset attribute value to a DIE. */
4459 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4460 unsigned HOST_WIDE_INT offset
)
4464 attr
.dw_attr
= attr_kind
;
4465 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4466 attr
.dw_attr_val
.val_entry
= NULL
;
4467 attr
.dw_attr_val
.v
.val_offset
= offset
;
4468 add_dwarf_attr (die
, &attr
);
4471 /* Add a range_list attribute value to a DIE. When using
4472 dwarf_split_debug_info, address attributes in dies destined for the
4473 final executable should be direct references--setting the parameter
4474 force_direct ensures this behavior. */
4476 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4477 #define RELOCATED_OFFSET (NULL)
4480 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4481 long unsigned int offset
, bool force_direct
)
4485 attr
.dw_attr
= attr_kind
;
4486 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4487 /* For the range_list attribute, use val_entry to store whether the
4488 offset should follow split-debug-info or normal semantics. This
4489 value is read in output_range_list_offset. */
4490 if (dwarf_split_debug_info
&& !force_direct
)
4491 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4493 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4494 attr
.dw_attr_val
.v
.val_offset
= offset
;
4495 add_dwarf_attr (die
, &attr
);
4498 /* Return the start label of a delta attribute. */
4500 static inline const char *
4501 AT_vms_delta1 (dw_attr_ref a
)
4503 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4504 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4507 /* Return the end label of a delta attribute. */
4509 static inline const char *
4510 AT_vms_delta2 (dw_attr_ref a
)
4512 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4513 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4516 static inline const char *
4517 AT_lbl (dw_attr_ref a
)
4519 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4520 || AT_class (a
) == dw_val_class_lineptr
4521 || AT_class (a
) == dw_val_class_macptr
4522 || AT_class (a
) == dw_val_class_high_pc
));
4523 return a
->dw_attr_val
.v
.val_lbl_id
;
4526 /* Get the attribute of type attr_kind. */
4529 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4533 dw_die_ref spec
= NULL
;
4538 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4539 if (a
->dw_attr
== attr_kind
)
4541 else if (a
->dw_attr
== DW_AT_specification
4542 || a
->dw_attr
== DW_AT_abstract_origin
)
4546 return get_AT (spec
, attr_kind
);
4551 /* Returns the parent of the declaration of DIE. */
4554 get_die_parent (dw_die_ref die
)
4561 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4562 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4565 return die
->die_parent
;
4568 /* Return the "low pc" attribute value, typically associated with a subprogram
4569 DIE. Return null if the "low pc" attribute is either not present, or if it
4570 cannot be represented as an assembler label identifier. */
4572 static inline const char *
4573 get_AT_low_pc (dw_die_ref die
)
4575 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4577 return a
? AT_lbl (a
) : NULL
;
4580 /* Return the "high pc" attribute value, typically associated with a subprogram
4581 DIE. Return null if the "high pc" attribute is either not present, or if it
4582 cannot be represented as an assembler label identifier. */
4584 static inline const char *
4585 get_AT_hi_pc (dw_die_ref die
)
4587 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4589 return a
? AT_lbl (a
) : NULL
;
4592 /* Return the value of the string attribute designated by ATTR_KIND, or
4593 NULL if it is not present. */
4595 static inline const char *
4596 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4598 dw_attr_ref a
= get_AT (die
, attr_kind
);
4600 return a
? AT_string (a
) : NULL
;
4603 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4604 if it is not present. */
4607 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4609 dw_attr_ref a
= get_AT (die
, attr_kind
);
4611 return a
? AT_flag (a
) : 0;
4614 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4615 if it is not present. */
4617 static inline unsigned
4618 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4620 dw_attr_ref a
= get_AT (die
, attr_kind
);
4622 return a
? AT_unsigned (a
) : 0;
4625 static inline dw_die_ref
4626 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4628 dw_attr_ref a
= get_AT (die
, attr_kind
);
4630 return a
? AT_ref (a
) : NULL
;
4633 static inline struct dwarf_file_data
*
4634 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4636 dw_attr_ref a
= get_AT (die
, attr_kind
);
4638 return a
? AT_file (a
) : NULL
;
4641 /* Return TRUE if the language is C++. */
4646 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4648 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4651 /* Return TRUE if the language is Java. */
4656 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4658 return lang
== DW_LANG_Java
;
4661 /* Return TRUE if the language is Fortran. */
4666 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4668 return (lang
== DW_LANG_Fortran77
4669 || lang
== DW_LANG_Fortran90
4670 || lang
== DW_LANG_Fortran95
);
4673 /* Return TRUE if the language is Ada. */
4678 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4680 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4683 /* Remove the specified attribute if present. */
4686 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4694 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4695 if (a
->dw_attr
== attr_kind
)
4697 if (AT_class (a
) == dw_val_class_str
)
4698 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4699 a
->dw_attr_val
.v
.val_str
->refcount
--;
4701 /* vec::ordered_remove should help reduce the number of abbrevs
4703 die
->die_attr
->ordered_remove (ix
);
4708 /* Remove CHILD from its parent. PREV must have the property that
4709 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4712 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4714 gcc_assert (child
->die_parent
== prev
->die_parent
);
4715 gcc_assert (prev
->die_sib
== child
);
4718 gcc_assert (child
->die_parent
->die_child
== child
);
4722 prev
->die_sib
= child
->die_sib
;
4723 if (child
->die_parent
->die_child
== child
)
4724 child
->die_parent
->die_child
= prev
;
4727 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4728 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4731 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4733 dw_die_ref parent
= old_child
->die_parent
;
4735 gcc_assert (parent
== prev
->die_parent
);
4736 gcc_assert (prev
->die_sib
== old_child
);
4738 new_child
->die_parent
= parent
;
4739 if (prev
== old_child
)
4741 gcc_assert (parent
->die_child
== old_child
);
4742 new_child
->die_sib
= new_child
;
4746 prev
->die_sib
= new_child
;
4747 new_child
->die_sib
= old_child
->die_sib
;
4749 if (old_child
->die_parent
->die_child
== old_child
)
4750 old_child
->die_parent
->die_child
= new_child
;
4753 /* Move all children from OLD_PARENT to NEW_PARENT. */
4756 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4759 new_parent
->die_child
= old_parent
->die_child
;
4760 old_parent
->die_child
= NULL
;
4761 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4764 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4768 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4774 dw_die_ref prev
= c
;
4776 while (c
->die_tag
== tag
)
4778 remove_child_with_prev (c
, prev
);
4779 /* Might have removed every child. */
4780 if (c
== c
->die_sib
)
4784 } while (c
!= die
->die_child
);
4787 /* Add a CHILD_DIE as the last child of DIE. */
4790 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4792 /* FIXME this should probably be an assert. */
4793 if (! die
|| ! child_die
)
4795 gcc_assert (die
!= child_die
);
4797 child_die
->die_parent
= die
;
4800 child_die
->die_sib
= die
->die_child
->die_sib
;
4801 die
->die_child
->die_sib
= child_die
;
4804 child_die
->die_sib
= child_die
;
4805 die
->die_child
= child_die
;
4808 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4809 is the specification, to the end of PARENT's list of children.
4810 This is done by removing and re-adding it. */
4813 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4817 /* We want the declaration DIE from inside the class, not the
4818 specification DIE at toplevel. */
4819 if (child
->die_parent
!= parent
)
4821 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4827 gcc_assert (child
->die_parent
== parent
4828 || (child
->die_parent
4829 == get_AT_ref (parent
, DW_AT_specification
)));
4831 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4832 if (p
->die_sib
== child
)
4834 remove_child_with_prev (child
, p
);
4838 add_child_die (parent
, child
);
4841 /* Return a pointer to a newly created DIE node. */
4843 static inline dw_die_ref
4844 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4846 dw_die_ref die
= ggc_cleared_alloc
<die_node
> ();
4848 die
->die_tag
= tag_value
;
4850 if (parent_die
!= NULL
)
4851 add_child_die (parent_die
, die
);
4854 limbo_die_node
*limbo_node
;
4856 limbo_node
= ggc_cleared_alloc
<limbo_die_node
> ();
4857 limbo_node
->die
= die
;
4858 limbo_node
->created_for
= t
;
4859 limbo_node
->next
= limbo_die_list
;
4860 limbo_die_list
= limbo_node
;
4866 /* Return the DIE associated with the given type specifier. */
4868 static inline dw_die_ref
4869 lookup_type_die (tree type
)
4871 return TYPE_SYMTAB_DIE (type
);
4874 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4875 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4876 anonymous type instead the one of the naming typedef. */
4878 static inline dw_die_ref
4879 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4882 && TREE_CODE (type
) == RECORD_TYPE
4884 && type_die
->die_tag
== DW_TAG_typedef
4885 && is_naming_typedef_decl (TYPE_NAME (type
)))
4886 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4890 /* Like lookup_type_die, but if type is an anonymous type named by a
4891 typedef[1], return the DIE of the anonymous type instead the one of
4892 the naming typedef. This is because in gen_typedef_die, we did
4893 equate the anonymous struct named by the typedef with the DIE of
4894 the naming typedef. So by default, lookup_type_die on an anonymous
4895 struct yields the DIE of the naming typedef.
4897 [1]: Read the comment of is_naming_typedef_decl to learn about what
4898 a naming typedef is. */
4900 static inline dw_die_ref
4901 lookup_type_die_strip_naming_typedef (tree type
)
4903 dw_die_ref die
= lookup_type_die (type
);
4904 return strip_naming_typedef (type
, die
);
4907 /* Equate a DIE to a given type specifier. */
4910 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
4912 TYPE_SYMTAB_DIE (type
) = type_die
;
4915 /* Returns a hash value for X (which really is a die_struct). */
4918 decl_die_table_hash (const void *x
)
4920 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
4923 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
4926 decl_die_table_eq (const void *x
, const void *y
)
4928 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4931 /* Return the DIE associated with a given declaration. */
4933 static inline dw_die_ref
4934 lookup_decl_die (tree decl
)
4936 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
4939 /* Returns a hash value for X (which really is a var_loc_list). */
4942 decl_loc_table_hash (const void *x
)
4944 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
4947 /* Return nonzero if decl_id of var_loc_list X is the same as
4951 decl_loc_table_eq (const void *x
, const void *y
)
4953 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4956 /* Return the var_loc list associated with a given declaration. */
4958 static inline var_loc_list
*
4959 lookup_decl_loc (const_tree decl
)
4961 if (!decl_loc_table
)
4963 return (var_loc_list
*)
4964 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
4967 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
4970 cached_dw_loc_list_table_hash (const void *x
)
4972 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
4975 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
4979 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
4981 return (((const cached_dw_loc_list
*) x
)->decl_id
4982 == DECL_UID ((const_tree
) y
));
4985 /* Equate a DIE to a particular declaration. */
4988 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
4990 unsigned int decl_id
= DECL_UID (decl
);
4993 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
4995 decl_die
->decl_id
= decl_id
;
4998 /* Return how many bits covers PIECE EXPR_LIST. */
5001 decl_piece_bitsize (rtx piece
)
5003 int ret
= (int) GET_MODE (piece
);
5006 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
5007 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5008 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5011 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5014 decl_piece_varloc_ptr (rtx piece
)
5016 if ((int) GET_MODE (piece
))
5017 return &XEXP (piece
, 0);
5019 return &XEXP (XEXP (piece
, 0), 1);
5022 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5023 Next is the chain of following piece nodes. */
5026 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5028 if (bitsize
<= (int) MAX_MACHINE_MODE
)
5029 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5031 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5036 /* Return rtx that should be stored into loc field for
5037 LOC_NOTE and BITPOS/BITSIZE. */
5040 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5041 HOST_WIDE_INT bitsize
)
5045 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5047 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5052 /* This function either modifies location piece list *DEST in
5053 place (if SRC and INNER is NULL), or copies location piece list
5054 *SRC to *DEST while modifying it. Location BITPOS is modified
5055 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5056 not copied and if needed some padding around it is added.
5057 When modifying in place, DEST should point to EXPR_LIST where
5058 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5059 to the start of the whole list and INNER points to the EXPR_LIST
5060 where earlier pieces cover PIECE_BITPOS bits. */
5063 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5064 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5065 HOST_WIDE_INT bitsize
, rtx loc_note
)
5068 bool copy
= inner
!= NULL
;
5072 /* First copy all nodes preceding the current bitpos. */
5073 while (src
!= inner
)
5075 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5076 decl_piece_bitsize (*src
), NULL_RTX
);
5077 dest
= &XEXP (*dest
, 1);
5078 src
= &XEXP (*src
, 1);
5081 /* Add padding if needed. */
5082 if (bitpos
!= piece_bitpos
)
5084 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5085 copy
? NULL_RTX
: *dest
);
5086 dest
= &XEXP (*dest
, 1);
5088 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5091 /* A piece with correct bitpos and bitsize already exist,
5092 just update the location for it and return. */
5093 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5096 /* Add the piece that changed. */
5097 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5098 dest
= &XEXP (*dest
, 1);
5099 /* Skip over pieces that overlap it. */
5100 diff
= bitpos
- piece_bitpos
+ bitsize
;
5103 while (diff
> 0 && *src
)
5106 diff
-= decl_piece_bitsize (piece
);
5108 src
= &XEXP (piece
, 1);
5111 *src
= XEXP (piece
, 1);
5112 free_EXPR_LIST_node (piece
);
5115 /* Add padding if needed. */
5116 if (diff
< 0 && *src
)
5120 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5121 dest
= &XEXP (*dest
, 1);
5125 /* Finally copy all nodes following it. */
5128 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5129 decl_piece_bitsize (*src
), NULL_RTX
);
5130 dest
= &XEXP (*dest
, 1);
5131 src
= &XEXP (*src
, 1);
5135 /* Add a variable location node to the linked list for DECL. */
5137 static struct var_loc_node
*
5138 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5140 unsigned int decl_id
;
5143 struct var_loc_node
*loc
= NULL
;
5144 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5146 if (TREE_CODE (decl
) == VAR_DECL
5147 && DECL_HAS_DEBUG_EXPR_P (decl
))
5149 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5150 if (handled_component_p (realdecl
)
5151 || (TREE_CODE (realdecl
) == MEM_REF
5152 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5154 HOST_WIDE_INT maxsize
;
5157 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5158 if (!DECL_P (innerdecl
)
5159 || DECL_IGNORED_P (innerdecl
)
5160 || TREE_STATIC (innerdecl
)
5162 || bitpos
+ bitsize
> 256
5163 || bitsize
!= maxsize
)
5169 decl_id
= DECL_UID (decl
);
5170 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5173 temp
= ggc_cleared_alloc
<var_loc_list
> ();
5174 temp
->decl_id
= decl_id
;
5178 temp
= (var_loc_list
*) *slot
;
5180 /* For PARM_DECLs try to keep around the original incoming value,
5181 even if that means we'll emit a zero-range .debug_loc entry. */
5183 && temp
->first
== temp
->last
5184 && TREE_CODE (decl
) == PARM_DECL
5185 && NOTE_P (temp
->first
->loc
)
5186 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5187 && DECL_INCOMING_RTL (decl
)
5188 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5189 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5190 == GET_CODE (DECL_INCOMING_RTL (decl
))
5191 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5193 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5194 NOTE_VAR_LOCATION_LOC (loc_note
))
5195 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5196 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5198 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5199 temp
->first
->next
= loc
;
5201 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5203 else if (temp
->last
)
5205 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5206 rtx
*piece_loc
= NULL
, last_loc_note
;
5207 int piece_bitpos
= 0;
5211 gcc_assert (last
->next
== NULL
);
5213 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5215 piece_loc
= &last
->loc
;
5218 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5219 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5221 piece_bitpos
+= cur_bitsize
;
5222 piece_loc
= &XEXP (*piece_loc
, 1);
5226 /* TEMP->LAST here is either pointer to the last but one or
5227 last element in the chained list, LAST is pointer to the
5229 if (label
&& strcmp (last
->label
, label
) == 0)
5231 /* For SRA optimized variables if there weren't any real
5232 insns since last note, just modify the last node. */
5233 if (piece_loc
!= NULL
)
5235 adjust_piece_list (piece_loc
, NULL
, NULL
,
5236 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5239 /* If the last note doesn't cover any instructions, remove it. */
5240 if (temp
->last
!= last
)
5242 temp
->last
->next
= NULL
;
5245 gcc_assert (strcmp (last
->label
, label
) != 0);
5249 gcc_assert (temp
->first
== temp
->last
5250 || (temp
->first
->next
== temp
->last
5251 && TREE_CODE (decl
) == PARM_DECL
));
5252 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5253 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5257 if (bitsize
== -1 && NOTE_P (last
->loc
))
5258 last_loc_note
= last
->loc
;
5259 else if (piece_loc
!= NULL
5260 && *piece_loc
!= NULL_RTX
5261 && piece_bitpos
== bitpos
5262 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5263 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5265 last_loc_note
= NULL_RTX
;
5266 /* If the current location is the same as the end of the list,
5267 and either both or neither of the locations is uninitialized,
5268 we have nothing to do. */
5269 if (last_loc_note
== NULL_RTX
5270 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5271 NOTE_VAR_LOCATION_LOC (loc_note
)))
5272 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5273 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5274 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5275 == VAR_INIT_STATUS_UNINITIALIZED
)
5276 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5277 == VAR_INIT_STATUS_UNINITIALIZED
))))
5279 /* Add LOC to the end of list and update LAST. If the last
5280 element of the list has been removed above, reuse its
5281 memory for the new node, otherwise allocate a new one. */
5285 memset (loc
, '\0', sizeof (*loc
));
5288 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5289 if (bitsize
== -1 || piece_loc
== NULL
)
5290 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5292 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5293 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5295 /* Ensure TEMP->LAST will point either to the new last but one
5296 element of the chain, or to the last element in it. */
5297 if (last
!= temp
->last
)
5305 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5308 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5313 /* Keep track of the number of spaces used to indent the
5314 output of the debugging routines that print the structure of
5315 the DIE internal representation. */
5316 static int print_indent
;
5318 /* Indent the line the number of spaces given by print_indent. */
5321 print_spaces (FILE *outfile
)
5323 fprintf (outfile
, "%*s", print_indent
, "");
5326 /* Print a type signature in hex. */
5329 print_signature (FILE *outfile
, char *sig
)
5333 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5334 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5337 /* Print the information associated with a given DIE, and its children.
5338 This routine is a debugging aid only. */
5341 print_die (dw_die_ref die
, FILE *outfile
)
5347 print_spaces (outfile
);
5348 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5349 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5351 print_spaces (outfile
);
5352 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5353 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5354 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5356 if (die
->comdat_type_p
)
5358 print_spaces (outfile
);
5359 fprintf (outfile
, " signature: ");
5360 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5361 fprintf (outfile
, "\n");
5364 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5366 print_spaces (outfile
);
5367 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5369 switch (AT_class (a
))
5371 case dw_val_class_addr
:
5372 fprintf (outfile
, "address");
5374 case dw_val_class_offset
:
5375 fprintf (outfile
, "offset");
5377 case dw_val_class_loc
:
5378 fprintf (outfile
, "location descriptor");
5380 case dw_val_class_loc_list
:
5381 fprintf (outfile
, "location list -> label:%s",
5382 AT_loc_list (a
)->ll_symbol
);
5384 case dw_val_class_range_list
:
5385 fprintf (outfile
, "range list");
5387 case dw_val_class_const
:
5388 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5390 case dw_val_class_unsigned_const
:
5391 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5393 case dw_val_class_const_double
:
5394 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
5395 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5396 a
->dw_attr_val
.v
.val_double
.high
,
5397 a
->dw_attr_val
.v
.val_double
.low
);
5399 case dw_val_class_wide_int
:
5401 int i
= a
->dw_attr_val
.v
.val_wide
->get_len ();
5402 fprintf (outfile
, "constant (");
5404 if (a
->dw_attr_val
.v
.val_wide
->elt (i
- 1) == 0)
5405 fprintf (outfile
, "0x");
5406 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
5407 a
->dw_attr_val
.v
.val_wide
->elt (--i
));
5409 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
5410 a
->dw_attr_val
.v
.val_wide
->elt (i
));
5411 fprintf (outfile
, ")");
5414 case dw_val_class_vec
:
5415 fprintf (outfile
, "floating-point or vector constant");
5417 case dw_val_class_flag
:
5418 fprintf (outfile
, "%u", AT_flag (a
));
5420 case dw_val_class_die_ref
:
5421 if (AT_ref (a
) != NULL
)
5423 if (AT_ref (a
)->comdat_type_p
)
5425 fprintf (outfile
, "die -> signature: ");
5426 print_signature (outfile
,
5427 AT_ref (a
)->die_id
.die_type_node
->signature
);
5429 else if (AT_ref (a
)->die_id
.die_symbol
)
5430 fprintf (outfile
, "die -> label: %s",
5431 AT_ref (a
)->die_id
.die_symbol
);
5433 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
5434 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
5437 fprintf (outfile
, "die -> <null>");
5439 case dw_val_class_vms_delta
:
5440 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5441 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
5443 case dw_val_class_lbl_id
:
5444 case dw_val_class_lineptr
:
5445 case dw_val_class_macptr
:
5446 case dw_val_class_high_pc
:
5447 fprintf (outfile
, "label: %s", AT_lbl (a
));
5449 case dw_val_class_str
:
5450 if (AT_string (a
) != NULL
)
5451 fprintf (outfile
, "\"%s\"", AT_string (a
));
5453 fprintf (outfile
, "<null>");
5455 case dw_val_class_file
:
5456 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
5457 AT_file (a
)->emitted_number
);
5459 case dw_val_class_data8
:
5463 for (i
= 0; i
< 8; i
++)
5464 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
5471 fprintf (outfile
, "\n");
5474 if (die
->die_child
!= NULL
)
5477 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5480 if (print_indent
== 0)
5481 fprintf (outfile
, "\n");
5484 /* Print the information collected for a given DIE. */
5487 debug_dwarf_die (dw_die_ref die
)
5489 print_die (die
, stderr
);
5493 debug (die_struct
&ref
)
5495 print_die (&ref
, stderr
);
5499 debug (die_struct
*ptr
)
5504 fprintf (stderr
, "<nil>\n");
5508 /* Print all DWARF information collected for the compilation unit.
5509 This routine is a debugging aid only. */
5515 print_die (comp_unit_die (), stderr
);
5518 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5519 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5520 DIE that marks the start of the DIEs for this include file. */
5523 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5525 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5526 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5528 new_unit
->die_sib
= old_unit
;
5532 /* Close an include-file CU and reopen the enclosing one. */
5535 pop_compile_unit (dw_die_ref old_unit
)
5537 dw_die_ref new_unit
= old_unit
->die_sib
;
5539 old_unit
->die_sib
= NULL
;
5543 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5544 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5545 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5547 /* Calculate the checksum of a location expression. */
5550 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5553 inchash::hash hstate
;
5556 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5558 hash_loc_operands (loc
, hstate
);
5559 hash
= hstate
.end();
5563 /* Calculate the checksum of an attribute. */
5566 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5568 dw_loc_descr_ref loc
;
5571 CHECKSUM (at
->dw_attr
);
5573 /* We don't care that this was compiled with a different compiler
5574 snapshot; if the output is the same, that's what matters. */
5575 if (at
->dw_attr
== DW_AT_producer
)
5578 switch (AT_class (at
))
5580 case dw_val_class_const
:
5581 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5583 case dw_val_class_unsigned_const
:
5584 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5586 case dw_val_class_const_double
:
5587 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5589 case dw_val_class_wide_int
:
5590 CHECKSUM (*at
->dw_attr_val
.v
.val_wide
);
5592 case dw_val_class_vec
:
5593 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5594 (at
->dw_attr_val
.v
.val_vec
.length
5595 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5597 case dw_val_class_flag
:
5598 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5600 case dw_val_class_str
:
5601 CHECKSUM_STRING (AT_string (at
));
5604 case dw_val_class_addr
:
5606 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5607 CHECKSUM_STRING (XSTR (r
, 0));
5610 case dw_val_class_offset
:
5611 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5614 case dw_val_class_loc
:
5615 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5616 loc_checksum (loc
, ctx
);
5619 case dw_val_class_die_ref
:
5620 die_checksum (AT_ref (at
), ctx
, mark
);
5623 case dw_val_class_fde_ref
:
5624 case dw_val_class_vms_delta
:
5625 case dw_val_class_lbl_id
:
5626 case dw_val_class_lineptr
:
5627 case dw_val_class_macptr
:
5628 case dw_val_class_high_pc
:
5631 case dw_val_class_file
:
5632 CHECKSUM_STRING (AT_file (at
)->filename
);
5635 case dw_val_class_data8
:
5636 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5644 /* Calculate the checksum of a DIE. */
5647 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5653 /* To avoid infinite recursion. */
5656 CHECKSUM (die
->die_mark
);
5659 die
->die_mark
= ++(*mark
);
5661 CHECKSUM (die
->die_tag
);
5663 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5664 attr_checksum (a
, ctx
, mark
);
5666 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5670 #undef CHECKSUM_BLOCK
5671 #undef CHECKSUM_STRING
5673 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5674 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5675 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5676 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5677 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5678 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5679 #define CHECKSUM_ATTR(FOO) \
5680 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5682 /* Calculate the checksum of a number in signed LEB128 format. */
5685 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5692 byte
= (value
& 0x7f);
5694 more
= !((value
== 0 && (byte
& 0x40) == 0)
5695 || (value
== -1 && (byte
& 0x40) != 0));
5704 /* Calculate the checksum of a number in unsigned LEB128 format. */
5707 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5711 unsigned char byte
= (value
& 0x7f);
5714 /* More bytes to follow. */
5722 /* Checksum the context of the DIE. This adds the names of any
5723 surrounding namespaces or structures to the checksum. */
5726 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5730 int tag
= die
->die_tag
;
5732 if (tag
!= DW_TAG_namespace
5733 && tag
!= DW_TAG_structure_type
5734 && tag
!= DW_TAG_class_type
)
5737 name
= get_AT_string (die
, DW_AT_name
);
5739 spec
= get_AT_ref (die
, DW_AT_specification
);
5743 if (die
->die_parent
!= NULL
)
5744 checksum_die_context (die
->die_parent
, ctx
);
5746 CHECKSUM_ULEB128 ('C');
5747 CHECKSUM_ULEB128 (tag
);
5749 CHECKSUM_STRING (name
);
5752 /* Calculate the checksum of a location expression. */
5755 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5757 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5758 were emitted as a DW_FORM_sdata instead of a location expression. */
5759 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5761 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5762 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5766 /* Otherwise, just checksum the raw location expression. */
5769 inchash::hash hstate
;
5772 CHECKSUM_ULEB128 (loc
->dtprel
);
5773 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5774 hash_loc_operands (loc
, hstate
);
5775 hash
= hstate
.end ();
5777 loc
= loc
->dw_loc_next
;
5781 /* Calculate the checksum of an attribute. */
5784 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5785 struct md5_ctx
*ctx
, int *mark
)
5787 dw_loc_descr_ref loc
;
5790 if (AT_class (at
) == dw_val_class_die_ref
)
5792 dw_die_ref target_die
= AT_ref (at
);
5794 /* For pointer and reference types, we checksum only the (qualified)
5795 name of the target type (if there is a name). For friend entries,
5796 we checksum only the (qualified) name of the target type or function.
5797 This allows the checksum to remain the same whether the target type
5798 is complete or not. */
5799 if ((at
->dw_attr
== DW_AT_type
5800 && (tag
== DW_TAG_pointer_type
5801 || tag
== DW_TAG_reference_type
5802 || tag
== DW_TAG_rvalue_reference_type
5803 || tag
== DW_TAG_ptr_to_member_type
))
5804 || (at
->dw_attr
== DW_AT_friend
5805 && tag
== DW_TAG_friend
))
5807 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5809 if (name_attr
!= NULL
)
5811 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5815 CHECKSUM_ULEB128 ('N');
5816 CHECKSUM_ULEB128 (at
->dw_attr
);
5817 if (decl
->die_parent
!= NULL
)
5818 checksum_die_context (decl
->die_parent
, ctx
);
5819 CHECKSUM_ULEB128 ('E');
5820 CHECKSUM_STRING (AT_string (name_attr
));
5825 /* For all other references to another DIE, we check to see if the
5826 target DIE has already been visited. If it has, we emit a
5827 backward reference; if not, we descend recursively. */
5828 if (target_die
->die_mark
> 0)
5830 CHECKSUM_ULEB128 ('R');
5831 CHECKSUM_ULEB128 (at
->dw_attr
);
5832 CHECKSUM_ULEB128 (target_die
->die_mark
);
5836 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5840 target_die
->die_mark
= ++(*mark
);
5841 CHECKSUM_ULEB128 ('T');
5842 CHECKSUM_ULEB128 (at
->dw_attr
);
5843 if (decl
->die_parent
!= NULL
)
5844 checksum_die_context (decl
->die_parent
, ctx
);
5845 die_checksum_ordered (target_die
, ctx
, mark
);
5850 CHECKSUM_ULEB128 ('A');
5851 CHECKSUM_ULEB128 (at
->dw_attr
);
5853 switch (AT_class (at
))
5855 case dw_val_class_const
:
5856 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5857 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5860 case dw_val_class_unsigned_const
:
5861 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5862 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5865 case dw_val_class_const_double
:
5866 CHECKSUM_ULEB128 (DW_FORM_block
);
5867 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5868 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5871 case dw_val_class_wide_int
:
5872 CHECKSUM_ULEB128 (DW_FORM_block
);
5873 CHECKSUM_ULEB128 (sizeof (*at
->dw_attr_val
.v
.val_wide
));
5874 CHECKSUM (*at
->dw_attr_val
.v
.val_wide
);
5877 case dw_val_class_vec
:
5878 CHECKSUM_ULEB128 (DW_FORM_block
);
5879 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
5880 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
5881 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5882 (at
->dw_attr_val
.v
.val_vec
.length
5883 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5886 case dw_val_class_flag
:
5887 CHECKSUM_ULEB128 (DW_FORM_flag
);
5888 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
5891 case dw_val_class_str
:
5892 CHECKSUM_ULEB128 (DW_FORM_string
);
5893 CHECKSUM_STRING (AT_string (at
));
5896 case dw_val_class_addr
:
5898 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5899 CHECKSUM_ULEB128 (DW_FORM_string
);
5900 CHECKSUM_STRING (XSTR (r
, 0));
5903 case dw_val_class_offset
:
5904 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5905 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
5908 case dw_val_class_loc
:
5909 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5910 loc_checksum_ordered (loc
, ctx
);
5913 case dw_val_class_fde_ref
:
5914 case dw_val_class_lbl_id
:
5915 case dw_val_class_lineptr
:
5916 case dw_val_class_macptr
:
5917 case dw_val_class_high_pc
:
5920 case dw_val_class_file
:
5921 CHECKSUM_ULEB128 (DW_FORM_string
);
5922 CHECKSUM_STRING (AT_file (at
)->filename
);
5925 case dw_val_class_data8
:
5926 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5934 struct checksum_attributes
5936 dw_attr_ref at_name
;
5937 dw_attr_ref at_type
;
5938 dw_attr_ref at_friend
;
5939 dw_attr_ref at_accessibility
;
5940 dw_attr_ref at_address_class
;
5941 dw_attr_ref at_allocated
;
5942 dw_attr_ref at_artificial
;
5943 dw_attr_ref at_associated
;
5944 dw_attr_ref at_binary_scale
;
5945 dw_attr_ref at_bit_offset
;
5946 dw_attr_ref at_bit_size
;
5947 dw_attr_ref at_bit_stride
;
5948 dw_attr_ref at_byte_size
;
5949 dw_attr_ref at_byte_stride
;
5950 dw_attr_ref at_const_value
;
5951 dw_attr_ref at_containing_type
;
5952 dw_attr_ref at_count
;
5953 dw_attr_ref at_data_location
;
5954 dw_attr_ref at_data_member_location
;
5955 dw_attr_ref at_decimal_scale
;
5956 dw_attr_ref at_decimal_sign
;
5957 dw_attr_ref at_default_value
;
5958 dw_attr_ref at_digit_count
;
5959 dw_attr_ref at_discr
;
5960 dw_attr_ref at_discr_list
;
5961 dw_attr_ref at_discr_value
;
5962 dw_attr_ref at_encoding
;
5963 dw_attr_ref at_endianity
;
5964 dw_attr_ref at_explicit
;
5965 dw_attr_ref at_is_optional
;
5966 dw_attr_ref at_location
;
5967 dw_attr_ref at_lower_bound
;
5968 dw_attr_ref at_mutable
;
5969 dw_attr_ref at_ordering
;
5970 dw_attr_ref at_picture_string
;
5971 dw_attr_ref at_prototyped
;
5972 dw_attr_ref at_small
;
5973 dw_attr_ref at_segment
;
5974 dw_attr_ref at_string_length
;
5975 dw_attr_ref at_threads_scaled
;
5976 dw_attr_ref at_upper_bound
;
5977 dw_attr_ref at_use_location
;
5978 dw_attr_ref at_use_UTF8
;
5979 dw_attr_ref at_variable_parameter
;
5980 dw_attr_ref at_virtuality
;
5981 dw_attr_ref at_visibility
;
5982 dw_attr_ref at_vtable_elem_location
;
5985 /* Collect the attributes that we will want to use for the checksum. */
5988 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
5993 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6004 attrs
->at_friend
= a
;
6006 case DW_AT_accessibility
:
6007 attrs
->at_accessibility
= a
;
6009 case DW_AT_address_class
:
6010 attrs
->at_address_class
= a
;
6012 case DW_AT_allocated
:
6013 attrs
->at_allocated
= a
;
6015 case DW_AT_artificial
:
6016 attrs
->at_artificial
= a
;
6018 case DW_AT_associated
:
6019 attrs
->at_associated
= a
;
6021 case DW_AT_binary_scale
:
6022 attrs
->at_binary_scale
= a
;
6024 case DW_AT_bit_offset
:
6025 attrs
->at_bit_offset
= a
;
6027 case DW_AT_bit_size
:
6028 attrs
->at_bit_size
= a
;
6030 case DW_AT_bit_stride
:
6031 attrs
->at_bit_stride
= a
;
6033 case DW_AT_byte_size
:
6034 attrs
->at_byte_size
= a
;
6036 case DW_AT_byte_stride
:
6037 attrs
->at_byte_stride
= a
;
6039 case DW_AT_const_value
:
6040 attrs
->at_const_value
= a
;
6042 case DW_AT_containing_type
:
6043 attrs
->at_containing_type
= a
;
6046 attrs
->at_count
= a
;
6048 case DW_AT_data_location
:
6049 attrs
->at_data_location
= a
;
6051 case DW_AT_data_member_location
:
6052 attrs
->at_data_member_location
= a
;
6054 case DW_AT_decimal_scale
:
6055 attrs
->at_decimal_scale
= a
;
6057 case DW_AT_decimal_sign
:
6058 attrs
->at_decimal_sign
= a
;
6060 case DW_AT_default_value
:
6061 attrs
->at_default_value
= a
;
6063 case DW_AT_digit_count
:
6064 attrs
->at_digit_count
= a
;
6067 attrs
->at_discr
= a
;
6069 case DW_AT_discr_list
:
6070 attrs
->at_discr_list
= a
;
6072 case DW_AT_discr_value
:
6073 attrs
->at_discr_value
= a
;
6075 case DW_AT_encoding
:
6076 attrs
->at_encoding
= a
;
6078 case DW_AT_endianity
:
6079 attrs
->at_endianity
= a
;
6081 case DW_AT_explicit
:
6082 attrs
->at_explicit
= a
;
6084 case DW_AT_is_optional
:
6085 attrs
->at_is_optional
= a
;
6087 case DW_AT_location
:
6088 attrs
->at_location
= a
;
6090 case DW_AT_lower_bound
:
6091 attrs
->at_lower_bound
= a
;
6094 attrs
->at_mutable
= a
;
6096 case DW_AT_ordering
:
6097 attrs
->at_ordering
= a
;
6099 case DW_AT_picture_string
:
6100 attrs
->at_picture_string
= a
;
6102 case DW_AT_prototyped
:
6103 attrs
->at_prototyped
= a
;
6106 attrs
->at_small
= a
;
6109 attrs
->at_segment
= a
;
6111 case DW_AT_string_length
:
6112 attrs
->at_string_length
= a
;
6114 case DW_AT_threads_scaled
:
6115 attrs
->at_threads_scaled
= a
;
6117 case DW_AT_upper_bound
:
6118 attrs
->at_upper_bound
= a
;
6120 case DW_AT_use_location
:
6121 attrs
->at_use_location
= a
;
6123 case DW_AT_use_UTF8
:
6124 attrs
->at_use_UTF8
= a
;
6126 case DW_AT_variable_parameter
:
6127 attrs
->at_variable_parameter
= a
;
6129 case DW_AT_virtuality
:
6130 attrs
->at_virtuality
= a
;
6132 case DW_AT_visibility
:
6133 attrs
->at_visibility
= a
;
6135 case DW_AT_vtable_elem_location
:
6136 attrs
->at_vtable_elem_location
= a
;
6144 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6147 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6151 struct checksum_attributes attrs
;
6153 CHECKSUM_ULEB128 ('D');
6154 CHECKSUM_ULEB128 (die
->die_tag
);
6156 memset (&attrs
, 0, sizeof (attrs
));
6158 decl
= get_AT_ref (die
, DW_AT_specification
);
6160 collect_checksum_attributes (&attrs
, decl
);
6161 collect_checksum_attributes (&attrs
, die
);
6163 CHECKSUM_ATTR (attrs
.at_name
);
6164 CHECKSUM_ATTR (attrs
.at_accessibility
);
6165 CHECKSUM_ATTR (attrs
.at_address_class
);
6166 CHECKSUM_ATTR (attrs
.at_allocated
);
6167 CHECKSUM_ATTR (attrs
.at_artificial
);
6168 CHECKSUM_ATTR (attrs
.at_associated
);
6169 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6170 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6171 CHECKSUM_ATTR (attrs
.at_bit_size
);
6172 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6173 CHECKSUM_ATTR (attrs
.at_byte_size
);
6174 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6175 CHECKSUM_ATTR (attrs
.at_const_value
);
6176 CHECKSUM_ATTR (attrs
.at_containing_type
);
6177 CHECKSUM_ATTR (attrs
.at_count
);
6178 CHECKSUM_ATTR (attrs
.at_data_location
);
6179 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6180 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6181 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6182 CHECKSUM_ATTR (attrs
.at_default_value
);
6183 CHECKSUM_ATTR (attrs
.at_digit_count
);
6184 CHECKSUM_ATTR (attrs
.at_discr
);
6185 CHECKSUM_ATTR (attrs
.at_discr_list
);
6186 CHECKSUM_ATTR (attrs
.at_discr_value
);
6187 CHECKSUM_ATTR (attrs
.at_encoding
);
6188 CHECKSUM_ATTR (attrs
.at_endianity
);
6189 CHECKSUM_ATTR (attrs
.at_explicit
);
6190 CHECKSUM_ATTR (attrs
.at_is_optional
);
6191 CHECKSUM_ATTR (attrs
.at_location
);
6192 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6193 CHECKSUM_ATTR (attrs
.at_mutable
);
6194 CHECKSUM_ATTR (attrs
.at_ordering
);
6195 CHECKSUM_ATTR (attrs
.at_picture_string
);
6196 CHECKSUM_ATTR (attrs
.at_prototyped
);
6197 CHECKSUM_ATTR (attrs
.at_small
);
6198 CHECKSUM_ATTR (attrs
.at_segment
);
6199 CHECKSUM_ATTR (attrs
.at_string_length
);
6200 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6201 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6202 CHECKSUM_ATTR (attrs
.at_use_location
);
6203 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6204 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6205 CHECKSUM_ATTR (attrs
.at_virtuality
);
6206 CHECKSUM_ATTR (attrs
.at_visibility
);
6207 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6208 CHECKSUM_ATTR (attrs
.at_type
);
6209 CHECKSUM_ATTR (attrs
.at_friend
);
6211 /* Checksum the child DIEs. */
6214 dw_attr_ref name_attr
;
6217 name_attr
= get_AT (c
, DW_AT_name
);
6218 if (is_template_instantiation (c
))
6220 /* Ignore instantiations of member type and function templates. */
6222 else if (name_attr
!= NULL
6223 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6225 /* Use a shallow checksum for named nested types and member
6227 CHECKSUM_ULEB128 ('S');
6228 CHECKSUM_ULEB128 (c
->die_tag
);
6229 CHECKSUM_STRING (AT_string (name_attr
));
6233 /* Use a deep checksum for other children. */
6234 /* Mark this DIE so it gets processed when unmarking. */
6235 if (c
->die_mark
== 0)
6237 die_checksum_ordered (c
, ctx
, mark
);
6239 } while (c
!= die
->die_child
);
6241 CHECKSUM_ULEB128 (0);
6244 /* Add a type name and tag to a hash. */
6246 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6248 CHECKSUM_ULEB128 (tag
);
6249 CHECKSUM_STRING (name
);
6253 #undef CHECKSUM_STRING
6254 #undef CHECKSUM_ATTR
6255 #undef CHECKSUM_LEB128
6256 #undef CHECKSUM_ULEB128
6258 /* Generate the type signature for DIE. This is computed by generating an
6259 MD5 checksum over the DIE's tag, its relevant attributes, and its
6260 children. Attributes that are references to other DIEs are processed
6261 by recursion, using the MARK field to prevent infinite recursion.
6262 If the DIE is nested inside a namespace or another type, we also
6263 need to include that context in the signature. The lower 64 bits
6264 of the resulting MD5 checksum comprise the signature. */
6267 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6271 unsigned char checksum
[16];
6276 name
= get_AT_string (die
, DW_AT_name
);
6277 decl
= get_AT_ref (die
, DW_AT_specification
);
6278 parent
= get_die_parent (die
);
6280 /* First, compute a signature for just the type name (and its surrounding
6281 context, if any. This is stored in the type unit DIE for link-time
6282 ODR (one-definition rule) checking. */
6284 if (is_cxx () && name
!= NULL
)
6286 md5_init_ctx (&ctx
);
6288 /* Checksum the names of surrounding namespaces and structures. */
6290 checksum_die_context (parent
, &ctx
);
6292 /* Checksum the current DIE. */
6293 die_odr_checksum (die
->die_tag
, name
, &ctx
);
6294 md5_finish_ctx (&ctx
, checksum
);
6296 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6299 /* Next, compute the complete type signature. */
6301 md5_init_ctx (&ctx
);
6303 die
->die_mark
= mark
;
6305 /* Checksum the names of surrounding namespaces and structures. */
6307 checksum_die_context (parent
, &ctx
);
6309 /* Checksum the DIE and its children. */
6310 die_checksum_ordered (die
, &ctx
, &mark
);
6311 unmark_all_dies (die
);
6312 md5_finish_ctx (&ctx
, checksum
);
6314 /* Store the signature in the type node and link the type DIE and the
6315 type node together. */
6316 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6317 DWARF_TYPE_SIGNATURE_SIZE
);
6318 die
->comdat_type_p
= true;
6319 die
->die_id
.die_type_node
= type_node
;
6320 type_node
->type_die
= die
;
6322 /* If the DIE is a specification, link its declaration to the type node
6326 decl
->comdat_type_p
= true;
6327 decl
->die_id
.die_type_node
= type_node
;
6331 /* Do the location expressions look same? */
6333 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6335 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6336 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6337 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6340 /* Do the values look the same? */
6342 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6344 dw_loc_descr_ref loc1
, loc2
;
6347 if (v1
->val_class
!= v2
->val_class
)
6350 switch (v1
->val_class
)
6352 case dw_val_class_const
:
6353 return v1
->v
.val_int
== v2
->v
.val_int
;
6354 case dw_val_class_unsigned_const
:
6355 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6356 case dw_val_class_const_double
:
6357 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6358 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6359 case dw_val_class_wide_int
:
6360 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
6361 case dw_val_class_vec
:
6362 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6363 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6365 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6366 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6369 case dw_val_class_flag
:
6370 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6371 case dw_val_class_str
:
6372 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6374 case dw_val_class_addr
:
6375 r1
= v1
->v
.val_addr
;
6376 r2
= v2
->v
.val_addr
;
6377 if (GET_CODE (r1
) != GET_CODE (r2
))
6379 return !rtx_equal_p (r1
, r2
);
6381 case dw_val_class_offset
:
6382 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6384 case dw_val_class_loc
:
6385 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6387 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6388 if (!same_loc_p (loc1
, loc2
, mark
))
6390 return !loc1
&& !loc2
;
6392 case dw_val_class_die_ref
:
6393 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6395 case dw_val_class_fde_ref
:
6396 case dw_val_class_vms_delta
:
6397 case dw_val_class_lbl_id
:
6398 case dw_val_class_lineptr
:
6399 case dw_val_class_macptr
:
6400 case dw_val_class_high_pc
:
6403 case dw_val_class_file
:
6404 return v1
->v
.val_file
== v2
->v
.val_file
;
6406 case dw_val_class_data8
:
6407 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6414 /* Do the attributes look the same? */
6417 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6419 if (at1
->dw_attr
!= at2
->dw_attr
)
6422 /* We don't care that this was compiled with a different compiler
6423 snapshot; if the output is the same, that's what matters. */
6424 if (at1
->dw_attr
== DW_AT_producer
)
6427 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6430 /* Do the dies look the same? */
6433 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6439 /* To avoid infinite recursion. */
6441 return die1
->die_mark
== die2
->die_mark
;
6442 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6444 if (die1
->die_tag
!= die2
->die_tag
)
6447 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6450 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6451 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6454 c1
= die1
->die_child
;
6455 c2
= die2
->die_child
;
6464 if (!same_die_p (c1
, c2
, mark
))
6468 if (c1
== die1
->die_child
)
6470 if (c2
== die2
->die_child
)
6480 /* Do the dies look the same? Wrapper around same_die_p. */
6483 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6486 int ret
= same_die_p (die1
, die2
, &mark
);
6488 unmark_all_dies (die1
);
6489 unmark_all_dies (die2
);
6494 /* The prefix to attach to symbols on DIEs in the current comdat debug
6496 static const char *comdat_symbol_id
;
6498 /* The index of the current symbol within the current comdat CU. */
6499 static unsigned int comdat_symbol_number
;
6501 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6502 children, and set comdat_symbol_id accordingly. */
6505 compute_section_prefix (dw_die_ref unit_die
)
6507 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6508 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6509 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6512 unsigned char checksum
[16];
6515 /* Compute the checksum of the DIE, then append part of it as hex digits to
6516 the name filename of the unit. */
6518 md5_init_ctx (&ctx
);
6520 die_checksum (unit_die
, &ctx
, &mark
);
6521 unmark_all_dies (unit_die
);
6522 md5_finish_ctx (&ctx
, checksum
);
6524 sprintf (name
, "%s.", base
);
6525 clean_symbol_name (name
);
6527 p
= name
+ strlen (name
);
6528 for (i
= 0; i
< 4; i
++)
6530 sprintf (p
, "%.2x", checksum
[i
]);
6534 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6535 comdat_symbol_number
= 0;
6538 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6541 is_type_die (dw_die_ref die
)
6543 switch (die
->die_tag
)
6545 case DW_TAG_array_type
:
6546 case DW_TAG_class_type
:
6547 case DW_TAG_interface_type
:
6548 case DW_TAG_enumeration_type
:
6549 case DW_TAG_pointer_type
:
6550 case DW_TAG_reference_type
:
6551 case DW_TAG_rvalue_reference_type
:
6552 case DW_TAG_string_type
:
6553 case DW_TAG_structure_type
:
6554 case DW_TAG_subroutine_type
:
6555 case DW_TAG_union_type
:
6556 case DW_TAG_ptr_to_member_type
:
6557 case DW_TAG_set_type
:
6558 case DW_TAG_subrange_type
:
6559 case DW_TAG_base_type
:
6560 case DW_TAG_const_type
:
6561 case DW_TAG_file_type
:
6562 case DW_TAG_packed_type
:
6563 case DW_TAG_volatile_type
:
6564 case DW_TAG_typedef
:
6571 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6572 Basically, we want to choose the bits that are likely to be shared between
6573 compilations (types) and leave out the bits that are specific to individual
6574 compilations (functions). */
6577 is_comdat_die (dw_die_ref c
)
6579 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6580 we do for stabs. The advantage is a greater likelihood of sharing between
6581 objects that don't include headers in the same order (and therefore would
6582 put the base types in a different comdat). jason 8/28/00 */
6584 if (c
->die_tag
== DW_TAG_base_type
)
6587 if (c
->die_tag
== DW_TAG_pointer_type
6588 || c
->die_tag
== DW_TAG_reference_type
6589 || c
->die_tag
== DW_TAG_rvalue_reference_type
6590 || c
->die_tag
== DW_TAG_const_type
6591 || c
->die_tag
== DW_TAG_volatile_type
)
6593 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6595 return t
? is_comdat_die (t
) : 0;
6598 return is_type_die (c
);
6601 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6602 compilation unit. */
6605 is_symbol_die (dw_die_ref c
)
6607 return (is_type_die (c
)
6608 || is_declaration_die (c
)
6609 || c
->die_tag
== DW_TAG_namespace
6610 || c
->die_tag
== DW_TAG_module
);
6613 /* Returns true iff C is a compile-unit DIE. */
6616 is_cu_die (dw_die_ref c
)
6618 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6621 /* Returns true iff C is a unit DIE of some sort. */
6624 is_unit_die (dw_die_ref c
)
6626 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6627 || c
->die_tag
== DW_TAG_partial_unit
6628 || c
->die_tag
== DW_TAG_type_unit
);
6631 /* Returns true iff C is a namespace DIE. */
6634 is_namespace_die (dw_die_ref c
)
6636 return c
&& c
->die_tag
== DW_TAG_namespace
;
6639 /* Returns true iff C is a class or structure DIE. */
6642 is_class_die (dw_die_ref c
)
6644 return c
&& (c
->die_tag
== DW_TAG_class_type
6645 || c
->die_tag
== DW_TAG_structure_type
);
6648 /* Return non-zero if this DIE is a template parameter. */
6651 is_template_parameter (dw_die_ref die
)
6653 switch (die
->die_tag
)
6655 case DW_TAG_template_type_param
:
6656 case DW_TAG_template_value_param
:
6657 case DW_TAG_GNU_template_template_param
:
6658 case DW_TAG_GNU_template_parameter_pack
:
6665 /* Return non-zero if this DIE represents a template instantiation. */
6668 is_template_instantiation (dw_die_ref die
)
6672 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
6674 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
6679 gen_internal_sym (const char *prefix
)
6683 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6684 return xstrdup (buf
);
6687 /* Assign symbols to all worthy DIEs under DIE. */
6690 assign_symbol_names (dw_die_ref die
)
6694 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6696 if (comdat_symbol_id
)
6698 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6700 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6701 comdat_symbol_id
, comdat_symbol_number
++);
6702 die
->die_id
.die_symbol
= xstrdup (p
);
6705 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6708 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6711 struct cu_hash_table_entry
6714 unsigned min_comdat_num
, max_comdat_num
;
6715 struct cu_hash_table_entry
*next
;
6718 /* Helpers to manipulate hash table of CUs. */
6720 struct cu_hash_table_entry_hasher
6722 typedef cu_hash_table_entry value_type
;
6723 typedef die_struct compare_type
;
6724 static inline hashval_t
hash (const value_type
*);
6725 static inline bool equal (const value_type
*, const compare_type
*);
6726 static inline void remove (value_type
*);
6730 cu_hash_table_entry_hasher::hash (const value_type
*entry
)
6732 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6736 cu_hash_table_entry_hasher::equal (const value_type
*entry1
,
6737 const compare_type
*entry2
)
6739 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6743 cu_hash_table_entry_hasher::remove (value_type
*entry
)
6745 struct cu_hash_table_entry
*next
;
6755 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
6757 /* Check whether we have already seen this CU and set up SYM_NUM
6760 check_duplicate_cu (dw_die_ref cu
, cu_hash_type
*htable
, unsigned int *sym_num
)
6762 struct cu_hash_table_entry dummy
;
6763 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6765 dummy
.max_comdat_num
= 0;
6767 slot
= htable
->find_slot_with_hash (cu
,
6768 htab_hash_string (cu
->die_id
.die_symbol
),
6772 for (; entry
; last
= entry
, entry
= entry
->next
)
6774 if (same_die_p_wrap (cu
, entry
->cu
))
6780 *sym_num
= entry
->min_comdat_num
;
6784 entry
= XCNEW (struct cu_hash_table_entry
);
6786 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6787 entry
->next
= *slot
;
6793 /* Record SYM_NUM to record of CU in HTABLE. */
6795 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type
*htable
,
6796 unsigned int sym_num
)
6798 struct cu_hash_table_entry
**slot
, *entry
;
6800 slot
= htable
->find_slot_with_hash (cu
,
6801 htab_hash_string (cu
->die_id
.die_symbol
),
6805 entry
->max_comdat_num
= sym_num
;
6808 /* Traverse the DIE (which is always comp_unit_die), and set up
6809 additional compilation units for each of the include files we see
6810 bracketed by BINCL/EINCL. */
6813 break_out_includes (dw_die_ref die
)
6816 dw_die_ref unit
= NULL
;
6817 limbo_die_node
*node
, **pnode
;
6821 dw_die_ref prev
= c
;
6823 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6824 || (unit
&& is_comdat_die (c
)))
6826 dw_die_ref next
= c
->die_sib
;
6828 /* This DIE is for a secondary CU; remove it from the main one. */
6829 remove_child_with_prev (c
, prev
);
6831 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6832 unit
= push_new_compile_unit (unit
, c
);
6833 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6834 unit
= pop_compile_unit (unit
);
6836 add_child_die (unit
, c
);
6838 if (c
== die
->die_child
)
6841 } while (c
!= die
->die_child
);
6844 /* We can only use this in debugging, since the frontend doesn't check
6845 to make sure that we leave every include file we enter. */
6849 assign_symbol_names (die
);
6850 cu_hash_type
cu_hash_table (10);
6851 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6857 compute_section_prefix (node
->die
);
6858 is_dupl
= check_duplicate_cu (node
->die
, &cu_hash_table
,
6859 &comdat_symbol_number
);
6860 assign_symbol_names (node
->die
);
6862 *pnode
= node
->next
;
6865 pnode
= &node
->next
;
6866 record_comdat_symbol_number (node
->die
, &cu_hash_table
,
6867 comdat_symbol_number
);
6872 /* Return non-zero if this DIE is a declaration. */
6875 is_declaration_die (dw_die_ref die
)
6880 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6881 if (a
->dw_attr
== DW_AT_declaration
)
6887 /* Return non-zero if this DIE is nested inside a subprogram. */
6890 is_nested_in_subprogram (dw_die_ref die
)
6892 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6896 return local_scope_p (decl
);
6899 /* Return non-zero if this DIE contains a defining declaration of a
6903 contains_subprogram_definition (dw_die_ref die
)
6907 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6909 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
6913 /* Return non-zero if this is a type DIE that should be moved to a
6914 COMDAT .debug_types section. */
6917 should_move_die_to_comdat (dw_die_ref die
)
6919 switch (die
->die_tag
)
6921 case DW_TAG_class_type
:
6922 case DW_TAG_structure_type
:
6923 case DW_TAG_enumeration_type
:
6924 case DW_TAG_union_type
:
6925 /* Don't move declarations, inlined instances, types nested in a
6926 subprogram, or types that contain subprogram definitions. */
6927 if (is_declaration_die (die
)
6928 || get_AT (die
, DW_AT_abstract_origin
)
6929 || is_nested_in_subprogram (die
)
6930 || contains_subprogram_definition (die
))
6933 case DW_TAG_array_type
:
6934 case DW_TAG_interface_type
:
6935 case DW_TAG_pointer_type
:
6936 case DW_TAG_reference_type
:
6937 case DW_TAG_rvalue_reference_type
:
6938 case DW_TAG_string_type
:
6939 case DW_TAG_subroutine_type
:
6940 case DW_TAG_ptr_to_member_type
:
6941 case DW_TAG_set_type
:
6942 case DW_TAG_subrange_type
:
6943 case DW_TAG_base_type
:
6944 case DW_TAG_const_type
:
6945 case DW_TAG_file_type
:
6946 case DW_TAG_packed_type
:
6947 case DW_TAG_volatile_type
:
6948 case DW_TAG_typedef
:
6954 /* Make a clone of DIE. */
6957 clone_die (dw_die_ref die
)
6963 clone
= ggc_cleared_alloc
<die_node
> ();
6964 clone
->die_tag
= die
->die_tag
;
6966 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6967 add_dwarf_attr (clone
, a
);
6972 /* Make a clone of the tree rooted at DIE. */
6975 clone_tree (dw_die_ref die
)
6978 dw_die_ref clone
= clone_die (die
);
6980 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
6985 /* Make a clone of DIE as a declaration. */
6988 clone_as_declaration (dw_die_ref die
)
6995 /* If the DIE is already a declaration, just clone it. */
6996 if (is_declaration_die (die
))
6997 return clone_die (die
);
6999 /* If the DIE is a specification, just clone its declaration DIE. */
7000 decl
= get_AT_ref (die
, DW_AT_specification
);
7003 clone
= clone_die (decl
);
7004 if (die
->comdat_type_p
)
7005 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7009 clone
= ggc_cleared_alloc
<die_node
> ();
7010 clone
->die_tag
= die
->die_tag
;
7012 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7014 /* We don't want to copy over all attributes.
7015 For example we don't want DW_AT_byte_size because otherwise we will no
7016 longer have a declaration and GDB will treat it as a definition. */
7020 case DW_AT_abstract_origin
:
7021 case DW_AT_artificial
:
7022 case DW_AT_containing_type
:
7023 case DW_AT_external
:
7026 case DW_AT_virtuality
:
7027 case DW_AT_linkage_name
:
7028 case DW_AT_MIPS_linkage_name
:
7029 add_dwarf_attr (clone
, a
);
7031 case DW_AT_byte_size
:
7037 if (die
->comdat_type_p
)
7038 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7040 add_AT_flag (clone
, DW_AT_declaration
, 1);
7045 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7047 struct decl_table_entry
7053 /* Helpers to manipulate hash table of copied declarations. */
7055 /* Hashtable helpers. */
7057 struct decl_table_entry_hasher
: typed_free_remove
<decl_table_entry
>
7059 typedef decl_table_entry value_type
;
7060 typedef die_struct compare_type
;
7061 static inline hashval_t
hash (const value_type
*);
7062 static inline bool equal (const value_type
*, const compare_type
*);
7066 decl_table_entry_hasher::hash (const value_type
*entry
)
7068 return htab_hash_pointer (entry
->orig
);
7072 decl_table_entry_hasher::equal (const value_type
*entry1
,
7073 const compare_type
*entry2
)
7075 return entry1
->orig
== entry2
;
7078 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
7080 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7081 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7082 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7083 to check if the ancestor has already been copied into UNIT. */
7086 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
,
7087 decl_hash_type
*decl_table
)
7089 dw_die_ref parent
= die
->die_parent
;
7090 dw_die_ref new_parent
= unit
;
7092 decl_table_entry
**slot
= NULL
;
7093 struct decl_table_entry
*entry
= NULL
;
7097 /* Check if the entry has already been copied to UNIT. */
7098 slot
= decl_table
->find_slot_with_hash (die
, htab_hash_pointer (die
),
7100 if (*slot
!= HTAB_EMPTY_ENTRY
)
7106 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7107 entry
= XCNEW (struct decl_table_entry
);
7115 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7118 if (!is_unit_die (parent
))
7119 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7122 copy
= clone_as_declaration (die
);
7123 add_child_die (new_parent
, copy
);
7127 /* Record the pointer to the copy. */
7133 /* Copy the declaration context to the new type unit DIE. This includes
7134 any surrounding namespace or type declarations. If the DIE has an
7135 AT_specification attribute, it also includes attributes and children
7136 attached to the specification, and returns a pointer to the original
7137 parent of the declaration DIE. Returns NULL otherwise. */
7140 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7143 dw_die_ref new_decl
;
7144 dw_die_ref orig_parent
= NULL
;
7146 decl
= get_AT_ref (die
, DW_AT_specification
);
7155 /* The original DIE will be changed to a declaration, and must
7156 be moved to be a child of the original declaration DIE. */
7157 orig_parent
= decl
->die_parent
;
7159 /* Copy the type node pointer from the new DIE to the original
7160 declaration DIE so we can forward references later. */
7161 decl
->comdat_type_p
= true;
7162 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7164 remove_AT (die
, DW_AT_specification
);
7166 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7168 if (a
->dw_attr
!= DW_AT_name
7169 && a
->dw_attr
!= DW_AT_declaration
7170 && a
->dw_attr
!= DW_AT_external
)
7171 add_dwarf_attr (die
, a
);
7174 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7177 if (decl
->die_parent
!= NULL
7178 && !is_unit_die (decl
->die_parent
))
7180 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
7181 if (new_decl
!= NULL
)
7183 remove_AT (new_decl
, DW_AT_signature
);
7184 add_AT_specification (die
, new_decl
);
7191 /* Generate the skeleton ancestor tree for the given NODE, then clone
7192 the DIE and add the clone into the tree. */
7195 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7197 if (node
->new_die
!= NULL
)
7200 node
->new_die
= clone_as_declaration (node
->old_die
);
7202 if (node
->parent
!= NULL
)
7204 generate_skeleton_ancestor_tree (node
->parent
);
7205 add_child_die (node
->parent
->new_die
, node
->new_die
);
7209 /* Generate a skeleton tree of DIEs containing any declarations that are
7210 found in the original tree. We traverse the tree looking for declaration
7211 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7214 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7216 skeleton_chain_node node
;
7219 dw_die_ref prev
= NULL
;
7220 dw_die_ref next
= NULL
;
7222 node
.parent
= parent
;
7224 first
= c
= parent
->old_die
->die_child
;
7228 if (prev
== NULL
|| prev
->die_sib
== c
)
7231 next
= (c
== first
? NULL
: c
->die_sib
);
7233 node
.new_die
= NULL
;
7234 if (is_declaration_die (c
))
7236 if (is_template_instantiation (c
))
7238 /* Instantiated templates do not need to be cloned into the
7239 type unit. Just move the DIE and its children back to
7240 the skeleton tree (in the main CU). */
7241 remove_child_with_prev (c
, prev
);
7242 add_child_die (parent
->new_die
, c
);
7247 /* Clone the existing DIE, move the original to the skeleton
7248 tree (which is in the main CU), and put the clone, with
7249 all the original's children, where the original came from
7250 (which is about to be moved to the type unit). */
7251 dw_die_ref clone
= clone_die (c
);
7252 move_all_children (c
, clone
);
7254 /* If the original has a DW_AT_object_pointer attribute,
7255 it would now point to a child DIE just moved to the
7256 cloned tree, so we need to remove that attribute from
7258 remove_AT (c
, DW_AT_object_pointer
);
7260 replace_child (c
, clone
, prev
);
7261 generate_skeleton_ancestor_tree (parent
);
7262 add_child_die (parent
->new_die
, c
);
7267 generate_skeleton_bottom_up (&node
);
7268 } while (next
!= NULL
);
7271 /* Wrapper function for generate_skeleton_bottom_up. */
7274 generate_skeleton (dw_die_ref die
)
7276 skeleton_chain_node node
;
7279 node
.new_die
= NULL
;
7282 /* If this type definition is nested inside another type,
7283 and is not an instantiation of a template, always leave
7284 at least a declaration in its place. */
7285 if (die
->die_parent
!= NULL
7286 && is_type_die (die
->die_parent
)
7287 && !is_template_instantiation (die
))
7288 node
.new_die
= clone_as_declaration (die
);
7290 generate_skeleton_bottom_up (&node
);
7291 return node
.new_die
;
7294 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7295 declaration. The original DIE is moved to a new compile unit so that
7296 existing references to it follow it to the new location. If any of the
7297 original DIE's descendants is a declaration, we need to replace the
7298 original DIE with a skeleton tree and move the declarations back into the
7302 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7305 dw_die_ref skeleton
, orig_parent
;
7307 /* Copy the declaration context to the type unit DIE. If the returned
7308 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7310 orig_parent
= copy_declaration_context (unit
, child
);
7312 skeleton
= generate_skeleton (child
);
7313 if (skeleton
== NULL
)
7314 remove_child_with_prev (child
, prev
);
7317 skeleton
->comdat_type_p
= true;
7318 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7320 /* If the original DIE was a specification, we need to put
7321 the skeleton under the parent DIE of the declaration.
7322 This leaves the original declaration in the tree, but
7323 it will be pruned later since there are no longer any
7324 references to it. */
7325 if (orig_parent
!= NULL
)
7327 remove_child_with_prev (child
, prev
);
7328 add_child_die (orig_parent
, skeleton
);
7331 replace_child (child
, skeleton
, prev
);
7337 /* Traverse the DIE and set up additional .debug_types sections for each
7338 type worthy of being placed in a COMDAT section. */
7341 break_out_comdat_types (dw_die_ref die
)
7345 dw_die_ref prev
= NULL
;
7346 dw_die_ref next
= NULL
;
7347 dw_die_ref unit
= NULL
;
7349 first
= c
= die
->die_child
;
7353 if (prev
== NULL
|| prev
->die_sib
== c
)
7356 next
= (c
== first
? NULL
: c
->die_sib
);
7357 if (should_move_die_to_comdat (c
))
7359 dw_die_ref replacement
;
7360 comdat_type_node_ref type_node
;
7362 /* Break out nested types into their own type units. */
7363 break_out_comdat_types (c
);
7365 /* Create a new type unit DIE as the root for the new tree, and
7366 add it to the list of comdat types. */
7367 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7368 add_AT_unsigned (unit
, DW_AT_language
,
7369 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7370 type_node
= ggc_cleared_alloc
<comdat_type_node
> ();
7371 type_node
->root_die
= unit
;
7372 type_node
->next
= comdat_type_list
;
7373 comdat_type_list
= type_node
;
7375 /* Generate the type signature. */
7376 generate_type_signature (c
, type_node
);
7378 /* Copy the declaration context, attributes, and children of the
7379 declaration into the new type unit DIE, then remove this DIE
7380 from the main CU (or replace it with a skeleton if necessary). */
7381 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7382 type_node
->skeleton_die
= replacement
;
7384 /* Add the DIE to the new compunit. */
7385 add_child_die (unit
, c
);
7387 if (replacement
!= NULL
)
7390 else if (c
->die_tag
== DW_TAG_namespace
7391 || c
->die_tag
== DW_TAG_class_type
7392 || c
->die_tag
== DW_TAG_structure_type
7393 || c
->die_tag
== DW_TAG_union_type
)
7395 /* Look for nested types that can be broken out. */
7396 break_out_comdat_types (c
);
7398 } while (next
!= NULL
);
7401 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
7402 Enter all the cloned children into the hash table decl_table. */
7405 clone_tree_partial (dw_die_ref die
, decl_hash_type
*decl_table
)
7409 struct decl_table_entry
*entry
;
7410 decl_table_entry
**slot
;
7412 if (die
->die_tag
== DW_TAG_subprogram
)
7413 clone
= clone_as_declaration (die
);
7415 clone
= clone_die (die
);
7417 slot
= decl_table
->find_slot_with_hash (die
,
7418 htab_hash_pointer (die
), INSERT
);
7420 /* Assert that DIE isn't in the hash table yet. If it would be there
7421 before, the ancestors would be necessarily there as well, therefore
7422 clone_tree_partial wouldn't be called. */
7423 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7425 entry
= XCNEW (struct decl_table_entry
);
7427 entry
->copy
= clone
;
7430 if (die
->die_tag
!= DW_TAG_subprogram
)
7431 FOR_EACH_CHILD (die
, c
,
7432 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
7437 /* Walk the DIE and its children, looking for references to incomplete
7438 or trivial types that are unmarked (i.e., that are not in the current
7442 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type
*decl_table
)
7448 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7450 if (AT_class (a
) == dw_val_class_die_ref
)
7452 dw_die_ref targ
= AT_ref (a
);
7453 decl_table_entry
**slot
;
7454 struct decl_table_entry
*entry
;
7456 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7459 slot
= decl_table
->find_slot_with_hash (targ
,
7460 htab_hash_pointer (targ
),
7463 if (*slot
!= HTAB_EMPTY_ENTRY
)
7465 /* TARG has already been copied, so we just need to
7466 modify the reference to point to the copy. */
7468 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7472 dw_die_ref parent
= unit
;
7473 dw_die_ref copy
= clone_die (targ
);
7475 /* Record in DECL_TABLE that TARG has been copied.
7476 Need to do this now, before the recursive call,
7477 because DECL_TABLE may be expanded and SLOT
7478 would no longer be a valid pointer. */
7479 entry
= XCNEW (struct decl_table_entry
);
7484 /* If TARG is not a declaration DIE, we need to copy its
7486 if (!is_declaration_die (targ
))
7490 add_child_die (copy
,
7491 clone_tree_partial (c
, decl_table
)));
7494 /* Make sure the cloned tree is marked as part of the
7498 /* If TARG has surrounding context, copy its ancestor tree
7499 into the new type unit. */
7500 if (targ
->die_parent
!= NULL
7501 && !is_unit_die (targ
->die_parent
))
7502 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7505 add_child_die (parent
, copy
);
7506 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7508 /* Make sure the newly-copied DIE is walked. If it was
7509 installed in a previously-added context, it won't
7510 get visited otherwise. */
7513 /* Find the highest point of the newly-added tree,
7514 mark each node along the way, and walk from there. */
7515 parent
->die_mark
= 1;
7516 while (parent
->die_parent
7517 && parent
->die_parent
->die_mark
== 0)
7519 parent
= parent
->die_parent
;
7520 parent
->die_mark
= 1;
7522 copy_decls_walk (unit
, parent
, decl_table
);
7528 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7531 /* Copy declarations for "unworthy" types into the new comdat section.
7532 Incomplete types, modified types, and certain other types aren't broken
7533 out into comdat sections of their own, so they don't have a signature,
7534 and we need to copy the declaration into the same section so that we
7535 don't have an external reference. */
7538 copy_decls_for_unworthy_types (dw_die_ref unit
)
7541 decl_hash_type
decl_table (10);
7542 copy_decls_walk (unit
, unit
, &decl_table
);
7546 /* Traverse the DIE and add a sibling attribute if it may have the
7547 effect of speeding up access to siblings. To save some space,
7548 avoid generating sibling attributes for DIE's without children. */
7551 add_sibling_attributes (dw_die_ref die
)
7555 if (! die
->die_child
)
7558 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7559 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7561 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7564 /* Output all location lists for the DIE and its children. */
7567 output_location_lists (dw_die_ref die
)
7573 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7574 if (AT_class (a
) == dw_val_class_loc_list
)
7575 output_loc_list (AT_loc_list (a
));
7577 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7580 /* We want to limit the number of external references, because they are
7581 larger than local references: a relocation takes multiple words, and
7582 even a sig8 reference is always eight bytes, whereas a local reference
7583 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7584 So if we encounter multiple external references to the same type DIE, we
7585 make a local typedef stub for it and redirect all references there.
7587 This is the element of the hash table for keeping track of these
7597 /* Hashtable helpers. */
7599 struct external_ref_hasher
: typed_free_remove
<external_ref
>
7601 typedef external_ref value_type
;
7602 typedef external_ref compare_type
;
7603 static inline hashval_t
hash (const value_type
*);
7604 static inline bool equal (const value_type
*, const compare_type
*);
7608 external_ref_hasher::hash (const value_type
*r
)
7610 dw_die_ref die
= r
->type
;
7613 /* We can't use the address of the DIE for hashing, because
7614 that will make the order of the stub DIEs non-deterministic. */
7615 if (! die
->comdat_type_p
)
7616 /* We have a symbol; use it to compute a hash. */
7617 h
= htab_hash_string (die
->die_id
.die_symbol
);
7620 /* We have a type signature; use a subset of the bits as the hash.
7621 The 8-byte signature is at least as large as hashval_t. */
7622 comdat_type_node_ref type_node
= die
->die_id
.die_type_node
;
7623 memcpy (&h
, type_node
->signature
, sizeof (h
));
7629 external_ref_hasher::equal (const value_type
*r1
, const compare_type
*r2
)
7631 return r1
->type
== r2
->type
;
7634 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
7636 /* Return a pointer to the external_ref for references to DIE. */
7638 static struct external_ref
*
7639 lookup_external_ref (external_ref_hash_type
*map
, dw_die_ref die
)
7641 struct external_ref ref
, *ref_p
;
7642 external_ref
**slot
;
7645 slot
= map
->find_slot (&ref
, INSERT
);
7646 if (*slot
!= HTAB_EMPTY_ENTRY
)
7649 ref_p
= XCNEW (struct external_ref
);
7655 /* Subroutine of optimize_external_refs, below.
7657 If we see a type skeleton, record it as our stub. If we see external
7658 references, remember how many we've seen. */
7661 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type
*map
)
7666 struct external_ref
*ref_p
;
7668 if (is_type_die (die
)
7669 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7671 /* This is a local skeleton; use it for local references. */
7672 ref_p
= lookup_external_ref (map
, c
);
7676 /* Scan the DIE references, and remember any that refer to DIEs from
7677 other CUs (i.e. those which are not marked). */
7678 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7679 if (AT_class (a
) == dw_val_class_die_ref
7680 && (c
= AT_ref (a
))->die_mark
== 0
7683 ref_p
= lookup_external_ref (map
, c
);
7687 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7690 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7691 points to an external_ref, DATA is the CU we're processing. If we don't
7692 already have a local stub, and we have multiple refs, build a stub. */
7695 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
7697 struct external_ref
*ref_p
= *slot
;
7699 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7701 /* We have multiple references to this type, so build a small stub.
7702 Both of these forms are a bit dodgy from the perspective of the
7703 DWARF standard, since technically they should have names. */
7704 dw_die_ref cu
= data
;
7705 dw_die_ref type
= ref_p
->type
;
7706 dw_die_ref stub
= NULL
;
7708 if (type
->comdat_type_p
)
7710 /* If we refer to this type via sig8, use AT_signature. */
7711 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7712 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7716 /* Otherwise, use a typedef with no name. */
7717 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7718 add_AT_die_ref (stub
, DW_AT_type
, type
);
7727 /* DIE is a unit; look through all the DIE references to see if there are
7728 any external references to types, and if so, create local stubs for
7729 them which will be applied in build_abbrev_table. This is useful because
7730 references to local DIEs are smaller. */
7732 static external_ref_hash_type
*
7733 optimize_external_refs (dw_die_ref die
)
7735 external_ref_hash_type
*map
= new external_ref_hash_type (10);
7736 optimize_external_refs_1 (die
, map
);
7737 map
->traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
7741 /* The format of each DIE (and its attribute value pairs) is encoded in an
7742 abbreviation table. This routine builds the abbreviation table and assigns
7743 a unique abbreviation id for each abbreviation entry. The children of each
7744 die are visited recursively. */
7747 build_abbrev_table (dw_die_ref die
, external_ref_hash_type
*extern_map
)
7749 unsigned long abbrev_id
;
7750 unsigned int n_alloc
;
7755 /* Scan the DIE references, and replace any that refer to
7756 DIEs from other CUs (i.e. those which are not marked) with
7757 the local stubs we built in optimize_external_refs. */
7758 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7759 if (AT_class (a
) == dw_val_class_die_ref
7760 && (c
= AT_ref (a
))->die_mark
== 0)
7762 struct external_ref
*ref_p
;
7763 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7765 ref_p
= lookup_external_ref (extern_map
, c
);
7766 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7767 change_AT_die_ref (a
, ref_p
->stub
);
7769 /* We aren't changing this reference, so mark it external. */
7770 set_AT_ref_external (a
, 1);
7773 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7775 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7776 dw_attr_ref die_a
, abbrev_a
;
7780 if (abbrev
->die_tag
!= die
->die_tag
)
7782 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7785 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
7788 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
7790 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
7791 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7792 || (value_format (abbrev_a
) != value_format (die_a
)))
7802 if (abbrev_id
>= abbrev_die_table_in_use
)
7804 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7806 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7807 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7810 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7811 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7812 abbrev_die_table_allocated
= n_alloc
;
7815 ++abbrev_die_table_in_use
;
7816 abbrev_die_table
[abbrev_id
] = die
;
7819 die
->die_abbrev
= abbrev_id
;
7820 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
7823 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7826 constant_size (unsigned HOST_WIDE_INT value
)
7833 log
= floor_log2 (value
);
7836 log
= 1 << (floor_log2 (log
) + 1);
7841 /* Return the size of a DIE as it is represented in the
7842 .debug_info section. */
7844 static unsigned long
7845 size_of_die (dw_die_ref die
)
7847 unsigned long size
= 0;
7850 enum dwarf_form form
;
7852 size
+= size_of_uleb128 (die
->die_abbrev
);
7853 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7855 switch (AT_class (a
))
7857 case dw_val_class_addr
:
7858 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7860 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7861 size
+= size_of_uleb128 (AT_index (a
));
7864 size
+= DWARF2_ADDR_SIZE
;
7866 case dw_val_class_offset
:
7867 size
+= DWARF_OFFSET_SIZE
;
7869 case dw_val_class_loc
:
7871 unsigned long lsize
= size_of_locs (AT_loc (a
));
7874 if (dwarf_version
>= 4)
7875 size
+= size_of_uleb128 (lsize
);
7877 size
+= constant_size (lsize
);
7881 case dw_val_class_loc_list
:
7882 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7884 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7885 size
+= size_of_uleb128 (AT_index (a
));
7888 size
+= DWARF_OFFSET_SIZE
;
7890 case dw_val_class_range_list
:
7891 size
+= DWARF_OFFSET_SIZE
;
7893 case dw_val_class_const
:
7894 size
+= size_of_sleb128 (AT_int (a
));
7896 case dw_val_class_unsigned_const
:
7898 int csize
= constant_size (AT_unsigned (a
));
7899 if (dwarf_version
== 3
7900 && a
->dw_attr
== DW_AT_data_member_location
7902 size
+= size_of_uleb128 (AT_unsigned (a
));
7907 case dw_val_class_const_double
:
7908 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
7909 if (HOST_BITS_PER_WIDE_INT
>= 64)
7912 case dw_val_class_wide_int
:
7913 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
7914 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
7915 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
7919 case dw_val_class_vec
:
7920 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7921 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7922 + a
->dw_attr_val
.v
.val_vec
.length
7923 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7925 case dw_val_class_flag
:
7926 if (dwarf_version
>= 4)
7927 /* Currently all add_AT_flag calls pass in 1 as last argument,
7928 so DW_FORM_flag_present can be used. If that ever changes,
7929 we'll need to use DW_FORM_flag and have some optimization
7930 in build_abbrev_table that will change those to
7931 DW_FORM_flag_present if it is set to 1 in all DIEs using
7932 the same abbrev entry. */
7933 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7937 case dw_val_class_die_ref
:
7938 if (AT_ref_external (a
))
7940 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7941 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7942 is sized by target address length, whereas in DWARF3
7943 it's always sized as an offset. */
7944 if (use_debug_types
)
7945 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7946 else if (dwarf_version
== 2)
7947 size
+= DWARF2_ADDR_SIZE
;
7949 size
+= DWARF_OFFSET_SIZE
;
7952 size
+= DWARF_OFFSET_SIZE
;
7954 case dw_val_class_fde_ref
:
7955 size
+= DWARF_OFFSET_SIZE
;
7957 case dw_val_class_lbl_id
:
7958 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7960 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7961 size
+= size_of_uleb128 (AT_index (a
));
7964 size
+= DWARF2_ADDR_SIZE
;
7966 case dw_val_class_lineptr
:
7967 case dw_val_class_macptr
:
7968 size
+= DWARF_OFFSET_SIZE
;
7970 case dw_val_class_str
:
7971 form
= AT_string_form (a
);
7972 if (form
== DW_FORM_strp
)
7973 size
+= DWARF_OFFSET_SIZE
;
7974 else if (form
== DW_FORM_GNU_str_index
)
7975 size
+= size_of_uleb128 (AT_index (a
));
7977 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7979 case dw_val_class_file
:
7980 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7982 case dw_val_class_data8
:
7985 case dw_val_class_vms_delta
:
7986 size
+= DWARF_OFFSET_SIZE
;
7988 case dw_val_class_high_pc
:
7989 size
+= DWARF2_ADDR_SIZE
;
7999 /* Size the debugging information associated with a given DIE. Visits the
8000 DIE's children recursively. Updates the global variable next_die_offset, on
8001 each time through. Uses the current value of next_die_offset to update the
8002 die_offset field in each DIE. */
8005 calc_die_sizes (dw_die_ref die
)
8009 gcc_assert (die
->die_offset
== 0
8010 || (unsigned long int) die
->die_offset
== next_die_offset
);
8011 die
->die_offset
= next_die_offset
;
8012 next_die_offset
+= size_of_die (die
);
8014 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
8016 if (die
->die_child
!= NULL
)
8017 /* Count the null byte used to terminate sibling lists. */
8018 next_die_offset
+= 1;
8021 /* Size just the base type children at the start of the CU.
8022 This is needed because build_abbrev needs to size locs
8023 and sizing of type based stack ops needs to know die_offset
8024 values for the base types. */
8027 calc_base_type_die_sizes (void)
8029 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8031 dw_die_ref base_type
;
8032 #if ENABLE_ASSERT_CHECKING
8033 dw_die_ref prev
= comp_unit_die ()->die_child
;
8036 die_offset
+= size_of_die (comp_unit_die ());
8037 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
8039 #if ENABLE_ASSERT_CHECKING
8040 gcc_assert (base_type
->die_offset
== 0
8041 && prev
->die_sib
== base_type
8042 && base_type
->die_child
== NULL
8043 && base_type
->die_abbrev
);
8046 base_type
->die_offset
= die_offset
;
8047 die_offset
+= size_of_die (base_type
);
8051 /* Set the marks for a die and its children. We do this so
8052 that we know whether or not a reference needs to use FORM_ref_addr; only
8053 DIEs in the same CU will be marked. We used to clear out the offset
8054 and use that as the flag, but ran into ordering problems. */
8057 mark_dies (dw_die_ref die
)
8061 gcc_assert (!die
->die_mark
);
8064 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
8067 /* Clear the marks for a die and its children. */
8070 unmark_dies (dw_die_ref die
)
8074 if (! use_debug_types
)
8075 gcc_assert (die
->die_mark
);
8078 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
8081 /* Clear the marks for a die, its children and referred dies. */
8084 unmark_all_dies (dw_die_ref die
)
8094 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
8096 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8097 if (AT_class (a
) == dw_val_class_die_ref
)
8098 unmark_all_dies (AT_ref (a
));
8101 /* Calculate if the entry should appear in the final output file. It may be
8102 from a pruned a type. */
8105 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
8107 /* By limiting gnu pubnames to definitions only, gold can generate a
8108 gdb index without entries for declarations, which don't include
8109 enough information to be useful. */
8110 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
8113 if (table
== pubname_table
)
8115 /* Enumerator names are part of the pubname table, but the
8116 parent DW_TAG_enumeration_type die may have been pruned.
8117 Don't output them if that is the case. */
8118 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
8119 (p
->die
->die_parent
== NULL
8120 || !p
->die
->die_parent
->die_perennial_p
))
8123 /* Everything else in the pubname table is included. */
8127 /* The pubtypes table shouldn't include types that have been
8129 return (p
->die
->die_offset
!= 0
8130 || !flag_eliminate_unused_debug_types
);
8133 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8134 generated for the compilation unit. */
8136 static unsigned long
8137 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8142 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
8144 size
= DWARF_PUBNAMES_HEADER_SIZE
;
8145 FOR_EACH_VEC_ELT (*names
, i
, p
)
8146 if (include_pubname_in_output (names
, p
))
8147 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
8149 size
+= DWARF_OFFSET_SIZE
;
8153 /* Return the size of the information in the .debug_aranges section. */
8155 static unsigned long
8156 size_of_aranges (void)
8160 size
= DWARF_ARANGES_HEADER_SIZE
;
8162 /* Count the address/length pair for this compilation unit. */
8163 if (text_section_used
)
8164 size
+= 2 * DWARF2_ADDR_SIZE
;
8165 if (cold_text_section_used
)
8166 size
+= 2 * DWARF2_ADDR_SIZE
;
8167 if (have_multiple_function_sections
)
8172 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
8174 if (DECL_IGNORED_P (fde
->decl
))
8176 if (!fde
->in_std_section
)
8177 size
+= 2 * DWARF2_ADDR_SIZE
;
8178 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8179 size
+= 2 * DWARF2_ADDR_SIZE
;
8183 /* Count the two zero words used to terminated the address range table. */
8184 size
+= 2 * DWARF2_ADDR_SIZE
;
8188 /* Select the encoding of an attribute value. */
8190 static enum dwarf_form
8191 value_format (dw_attr_ref a
)
8193 switch (AT_class (a
))
8195 case dw_val_class_addr
:
8196 /* Only very few attributes allow DW_FORM_addr. */
8201 case DW_AT_entry_pc
:
8202 case DW_AT_trampoline
:
8203 return (AT_index (a
) == NOT_INDEXED
8204 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8208 switch (DWARF2_ADDR_SIZE
)
8211 return DW_FORM_data1
;
8213 return DW_FORM_data2
;
8215 return DW_FORM_data4
;
8217 return DW_FORM_data8
;
8221 case dw_val_class_range_list
:
8222 case dw_val_class_loc_list
:
8223 if (dwarf_version
>= 4)
8224 return DW_FORM_sec_offset
;
8226 case dw_val_class_vms_delta
:
8227 case dw_val_class_offset
:
8228 switch (DWARF_OFFSET_SIZE
)
8231 return DW_FORM_data4
;
8233 return DW_FORM_data8
;
8237 case dw_val_class_loc
:
8238 if (dwarf_version
>= 4)
8239 return DW_FORM_exprloc
;
8240 switch (constant_size (size_of_locs (AT_loc (a
))))
8243 return DW_FORM_block1
;
8245 return DW_FORM_block2
;
8247 return DW_FORM_block4
;
8251 case dw_val_class_const
:
8252 return DW_FORM_sdata
;
8253 case dw_val_class_unsigned_const
:
8254 switch (constant_size (AT_unsigned (a
)))
8257 return DW_FORM_data1
;
8259 return DW_FORM_data2
;
8261 /* In DWARF3 DW_AT_data_member_location with
8262 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8263 constant, so we need to use DW_FORM_udata if we need
8264 a large constant. */
8265 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8266 return DW_FORM_udata
;
8267 return DW_FORM_data4
;
8269 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8270 return DW_FORM_udata
;
8271 return DW_FORM_data8
;
8275 case dw_val_class_const_double
:
8276 switch (HOST_BITS_PER_WIDE_INT
)
8279 return DW_FORM_data2
;
8281 return DW_FORM_data4
;
8283 return DW_FORM_data8
;
8286 return DW_FORM_block1
;
8288 case dw_val_class_wide_int
:
8289 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
8292 return DW_FORM_data1
;
8294 return DW_FORM_data2
;
8296 return DW_FORM_data4
;
8298 return DW_FORM_data8
;
8300 return DW_FORM_block1
;
8302 case dw_val_class_vec
:
8303 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8304 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8307 return DW_FORM_block1
;
8309 return DW_FORM_block2
;
8311 return DW_FORM_block4
;
8315 case dw_val_class_flag
:
8316 if (dwarf_version
>= 4)
8318 /* Currently all add_AT_flag calls pass in 1 as last argument,
8319 so DW_FORM_flag_present can be used. If that ever changes,
8320 we'll need to use DW_FORM_flag and have some optimization
8321 in build_abbrev_table that will change those to
8322 DW_FORM_flag_present if it is set to 1 in all DIEs using
8323 the same abbrev entry. */
8324 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8325 return DW_FORM_flag_present
;
8327 return DW_FORM_flag
;
8328 case dw_val_class_die_ref
:
8329 if (AT_ref_external (a
))
8330 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8333 case dw_val_class_fde_ref
:
8334 return DW_FORM_data
;
8335 case dw_val_class_lbl_id
:
8336 return (AT_index (a
) == NOT_INDEXED
8337 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8338 case dw_val_class_lineptr
:
8339 case dw_val_class_macptr
:
8340 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8341 case dw_val_class_str
:
8342 return AT_string_form (a
);
8343 case dw_val_class_file
:
8344 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8347 return DW_FORM_data1
;
8349 return DW_FORM_data2
;
8351 return DW_FORM_data4
;
8356 case dw_val_class_data8
:
8357 return DW_FORM_data8
;
8359 case dw_val_class_high_pc
:
8360 switch (DWARF2_ADDR_SIZE
)
8363 return DW_FORM_data1
;
8365 return DW_FORM_data2
;
8367 return DW_FORM_data4
;
8369 return DW_FORM_data8
;
8379 /* Output the encoding of an attribute value. */
8382 output_value_format (dw_attr_ref a
)
8384 enum dwarf_form form
= value_format (a
);
8386 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8389 /* Given a die and id, produce the appropriate abbreviations. */
8392 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8397 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8398 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8399 dwarf_tag_name (abbrev
->die_tag
));
8401 if (abbrev
->die_child
!= NULL
)
8402 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8404 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8406 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8408 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8409 dwarf_attr_name (a_attr
->dw_attr
));
8410 output_value_format (a_attr
);
8413 dw2_asm_output_data (1, 0, NULL
);
8414 dw2_asm_output_data (1, 0, NULL
);
8418 /* Output the .debug_abbrev section which defines the DIE abbreviation
8422 output_abbrev_section (void)
8424 unsigned long abbrev_id
;
8426 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8427 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8429 /* Terminate the table. */
8430 dw2_asm_output_data (1, 0, NULL
);
8433 /* Output a symbol we can use to refer to this DIE from another CU. */
8436 output_die_symbol (dw_die_ref die
)
8438 const char *sym
= die
->die_id
.die_symbol
;
8440 gcc_assert (!die
->comdat_type_p
);
8445 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8446 /* We make these global, not weak; if the target doesn't support
8447 .linkonce, it doesn't support combining the sections, so debugging
8449 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8451 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8454 /* Return a new location list, given the begin and end range, and the
8457 static inline dw_loc_list_ref
8458 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8459 const char *section
)
8461 dw_loc_list_ref retlist
= ggc_cleared_alloc
<dw_loc_list_node
> ();
8463 retlist
->begin
= begin
;
8464 retlist
->begin_entry
= NULL
;
8466 retlist
->expr
= expr
;
8467 retlist
->section
= section
;
8472 /* Generate a new internal symbol for this location list node, if it
8473 hasn't got one yet. */
8476 gen_llsym (dw_loc_list_ref list
)
8478 gcc_assert (!list
->ll_symbol
);
8479 list
->ll_symbol
= gen_internal_sym ("LLST");
8482 /* Output the location list given to us. */
8485 output_loc_list (dw_loc_list_ref list_head
)
8487 dw_loc_list_ref curr
= list_head
;
8489 if (list_head
->emitted
)
8491 list_head
->emitted
= true;
8493 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8495 /* Walk the location list, and output each range + expression. */
8496 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8499 /* Don't output an entry that starts and ends at the same address. */
8500 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8502 size
= size_of_locs (curr
->expr
);
8503 /* If the expression is too large, drop it on the floor. We could
8504 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8505 in the expression, but >= 64KB expressions for a single value
8506 in a single range are unlikely very useful. */
8509 if (dwarf_split_debug_info
)
8511 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8512 "Location list start/length entry (%s)",
8513 list_head
->ll_symbol
);
8514 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8515 "Location list range start index (%s)",
8517 /* The length field is 4 bytes. If we ever need to support
8518 an 8-byte length, we can add a new DW_LLE code or fall back
8519 to DW_LLE_GNU_start_end_entry. */
8520 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8521 "Location list range length (%s)",
8522 list_head
->ll_symbol
);
8524 else if (!have_multiple_function_sections
)
8526 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8527 "Location list begin address (%s)",
8528 list_head
->ll_symbol
);
8529 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8530 "Location list end address (%s)",
8531 list_head
->ll_symbol
);
8535 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8536 "Location list begin address (%s)",
8537 list_head
->ll_symbol
);
8538 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8539 "Location list end address (%s)",
8540 list_head
->ll_symbol
);
8543 /* Output the block length for this list of location operations. */
8544 gcc_assert (size
<= 0xffff);
8545 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8547 output_loc_sequence (curr
->expr
, -1);
8550 if (dwarf_split_debug_info
)
8551 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8552 "Location list terminator (%s)",
8553 list_head
->ll_symbol
);
8556 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8557 "Location list terminator begin (%s)",
8558 list_head
->ll_symbol
);
8559 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8560 "Location list terminator end (%s)",
8561 list_head
->ll_symbol
);
8565 /* Output a range_list offset into the debug_range section. Emit a
8566 relocated reference if val_entry is NULL, otherwise, emit an
8567 indirect reference. */
8570 output_range_list_offset (dw_attr_ref a
)
8572 const char *name
= dwarf_attr_name (a
->dw_attr
);
8574 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8576 char *p
= strchr (ranges_section_label
, '\0');
8577 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8578 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8579 debug_ranges_section
, "%s", name
);
8583 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8584 "%s (offset from %s)", name
, ranges_section_label
);
8587 /* Output the offset into the debug_loc section. */
8590 output_loc_list_offset (dw_attr_ref a
)
8592 char *sym
= AT_loc_list (a
)->ll_symbol
;
8595 if (dwarf_split_debug_info
)
8596 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8597 "%s", dwarf_attr_name (a
->dw_attr
));
8599 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8600 "%s", dwarf_attr_name (a
->dw_attr
));
8603 /* Output an attribute's index or value appropriately. */
8606 output_attr_index_or_value (dw_attr_ref a
)
8608 const char *name
= dwarf_attr_name (a
->dw_attr
);
8610 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8612 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8615 switch (AT_class (a
))
8617 case dw_val_class_addr
:
8618 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8620 case dw_val_class_high_pc
:
8621 case dw_val_class_lbl_id
:
8622 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8624 case dw_val_class_loc_list
:
8625 output_loc_list_offset (a
);
8632 /* Output a type signature. */
8635 output_signature (const char *sig
, const char *name
)
8639 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8640 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8643 /* Output the DIE and its attributes. Called recursively to generate
8644 the definitions of each child DIE. */
8647 output_die (dw_die_ref die
)
8654 /* If someone in another CU might refer to us, set up a symbol for
8655 them to point to. */
8656 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8657 output_die_symbol (die
);
8659 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8660 (unsigned long)die
->die_offset
,
8661 dwarf_tag_name (die
->die_tag
));
8663 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8665 const char *name
= dwarf_attr_name (a
->dw_attr
);
8667 switch (AT_class (a
))
8669 case dw_val_class_addr
:
8670 output_attr_index_or_value (a
);
8673 case dw_val_class_offset
:
8674 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8678 case dw_val_class_range_list
:
8679 output_range_list_offset (a
);
8682 case dw_val_class_loc
:
8683 size
= size_of_locs (AT_loc (a
));
8685 /* Output the block length for this list of location operations. */
8686 if (dwarf_version
>= 4)
8687 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8689 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8691 output_loc_sequence (AT_loc (a
), -1);
8694 case dw_val_class_const
:
8695 /* ??? It would be slightly more efficient to use a scheme like is
8696 used for unsigned constants below, but gdb 4.x does not sign
8697 extend. Gdb 5.x does sign extend. */
8698 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8701 case dw_val_class_unsigned_const
:
8703 int csize
= constant_size (AT_unsigned (a
));
8704 if (dwarf_version
== 3
8705 && a
->dw_attr
== DW_AT_data_member_location
8707 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8709 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8713 case dw_val_class_const_double
:
8715 unsigned HOST_WIDE_INT first
, second
;
8717 if (HOST_BITS_PER_WIDE_INT
>= 64)
8718 dw2_asm_output_data (1,
8719 HOST_BITS_PER_DOUBLE_INT
8720 / HOST_BITS_PER_CHAR
,
8723 if (WORDS_BIG_ENDIAN
)
8725 first
= a
->dw_attr_val
.v
.val_double
.high
;
8726 second
= a
->dw_attr_val
.v
.val_double
.low
;
8730 first
= a
->dw_attr_val
.v
.val_double
.low
;
8731 second
= a
->dw_attr_val
.v
.val_double
.high
;
8734 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8736 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8741 case dw_val_class_wide_int
:
8744 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
8745 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
8746 if (len
* HOST_BITS_PER_WIDE_INT
> 64)
8747 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
) * l
,
8750 if (WORDS_BIG_ENDIAN
)
8751 for (i
= len
- 1; i
>= 0; --i
)
8753 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
8758 for (i
= 0; i
< len
; ++i
)
8760 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
8767 case dw_val_class_vec
:
8769 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8770 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8774 dw2_asm_output_data (constant_size (len
* elt_size
),
8775 len
* elt_size
, "%s", name
);
8776 if (elt_size
> sizeof (HOST_WIDE_INT
))
8781 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8784 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8785 "fp or vector constant word %u", i
);
8789 case dw_val_class_flag
:
8790 if (dwarf_version
>= 4)
8792 /* Currently all add_AT_flag calls pass in 1 as last argument,
8793 so DW_FORM_flag_present can be used. If that ever changes,
8794 we'll need to use DW_FORM_flag and have some optimization
8795 in build_abbrev_table that will change those to
8796 DW_FORM_flag_present if it is set to 1 in all DIEs using
8797 the same abbrev entry. */
8798 gcc_assert (AT_flag (a
) == 1);
8800 fprintf (asm_out_file
, "\t\t\t%s %s\n",
8801 ASM_COMMENT_START
, name
);
8804 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8807 case dw_val_class_loc_list
:
8808 output_attr_index_or_value (a
);
8811 case dw_val_class_die_ref
:
8812 if (AT_ref_external (a
))
8814 if (AT_ref (a
)->comdat_type_p
)
8816 comdat_type_node_ref type_node
=
8817 AT_ref (a
)->die_id
.die_type_node
;
8819 gcc_assert (type_node
);
8820 output_signature (type_node
->signature
, name
);
8824 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
8828 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8829 length, whereas in DWARF3 it's always sized as an
8831 if (dwarf_version
== 2)
8832 size
= DWARF2_ADDR_SIZE
;
8834 size
= DWARF_OFFSET_SIZE
;
8835 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
8841 gcc_assert (AT_ref (a
)->die_offset
);
8842 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8847 case dw_val_class_fde_ref
:
8851 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8852 a
->dw_attr_val
.v
.val_fde_index
* 2);
8853 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8858 case dw_val_class_vms_delta
:
8859 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
8860 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
8864 case dw_val_class_lbl_id
:
8865 output_attr_index_or_value (a
);
8868 case dw_val_class_lineptr
:
8869 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8870 debug_line_section
, "%s", name
);
8873 case dw_val_class_macptr
:
8874 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8875 debug_macinfo_section
, "%s", name
);
8878 case dw_val_class_str
:
8879 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
8880 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8881 a
->dw_attr_val
.v
.val_str
->label
,
8883 "%s: \"%s\"", name
, AT_string (a
));
8884 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
8885 dw2_asm_output_data_uleb128 (AT_index (a
),
8886 "%s: \"%s\"", name
, AT_string (a
));
8888 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8891 case dw_val_class_file
:
8893 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8895 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8896 a
->dw_attr_val
.v
.val_file
->filename
);
8900 case dw_val_class_data8
:
8904 for (i
= 0; i
< 8; i
++)
8905 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8906 i
== 0 ? "%s" : NULL
, name
);
8910 case dw_val_class_high_pc
:
8911 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
8912 get_AT_low_pc (die
), "DW_AT_high_pc");
8920 FOR_EACH_CHILD (die
, c
, output_die (c
));
8922 /* Add null byte to terminate sibling list. */
8923 if (die
->die_child
!= NULL
)
8924 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8925 (unsigned long) die
->die_offset
);
8928 /* Output the compilation unit that appears at the beginning of the
8929 .debug_info section, and precedes the DIE descriptions. */
8932 output_compilation_unit_header (void)
8934 int ver
= dwarf_version
;
8936 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8937 dw2_asm_output_data (4, 0xffffffff,
8938 "Initial length escape value indicating 64-bit DWARF extension");
8939 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8940 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8941 "Length of Compilation Unit Info");
8942 dw2_asm_output_data (2, ver
, "DWARF version number");
8943 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8944 debug_abbrev_section
,
8945 "Offset Into Abbrev. Section");
8946 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8949 /* Output the compilation unit DIE and its children. */
8952 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8954 const char *secname
, *oldsym
;
8957 /* Unless we are outputting main CU, we may throw away empty ones. */
8958 if (!output_if_empty
&& die
->die_child
== NULL
)
8961 /* Even if there are no children of this DIE, we must output the information
8962 about the compilation unit. Otherwise, on an empty translation unit, we
8963 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8964 will then complain when examining the file. First mark all the DIEs in
8965 this CU so we know which get local refs. */
8968 external_ref_hash_type
*extern_map
= optimize_external_refs (die
);
8970 build_abbrev_table (die
, extern_map
);
8974 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8975 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8976 calc_die_sizes (die
);
8978 oldsym
= die
->die_id
.die_symbol
;
8981 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8983 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8985 die
->die_id
.die_symbol
= NULL
;
8986 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8990 switch_to_section (debug_info_section
);
8991 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8992 info_section_emitted
= true;
8995 /* Output debugging information. */
8996 output_compilation_unit_header ();
8999 /* Leave the marks on the main CU, so we can check them in
9004 die
->die_id
.die_symbol
= oldsym
;
9008 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
9009 and .debug_pubtypes. This is configured per-target, but can be
9010 overridden by the -gpubnames or -gno-pubnames options. */
9013 want_pubnames (void)
9015 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9017 if (debug_generate_pub_sections
!= -1)
9018 return debug_generate_pub_sections
;
9019 return targetm
.want_debug_pub_sections
;
9022 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
9025 add_AT_pubnames (dw_die_ref die
)
9027 if (want_pubnames ())
9028 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
9031 /* Add a string attribute value to a skeleton DIE. */
9034 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
9038 struct indirect_string_node
*node
;
9040 if (! skeleton_debug_str_hash
)
9041 skeleton_debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
9042 debug_str_eq
, NULL
);
9044 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
9045 find_string_form (node
);
9046 if (node
->form
== DW_FORM_GNU_str_index
)
9047 node
->form
= DW_FORM_strp
;
9049 attr
.dw_attr
= attr_kind
;
9050 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
9051 attr
.dw_attr_val
.val_entry
= NULL
;
9052 attr
.dw_attr_val
.v
.val_str
= node
;
9053 add_dwarf_attr (die
, &attr
);
9056 /* Helper function to generate top-level dies for skeleton debug_info and
9060 add_top_level_skeleton_die_attrs (dw_die_ref die
)
9062 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
9063 const char *comp_dir
= comp_dir_string ();
9065 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
9066 if (comp_dir
!= NULL
)
9067 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
9068 add_AT_pubnames (die
);
9069 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
9072 /* Output skeleton debug sections that point to the dwo file. */
9075 output_skeleton_debug_sections (dw_die_ref comp_unit
)
9077 /* These attributes will be found in the full debug_info section. */
9078 remove_AT (comp_unit
, DW_AT_producer
);
9079 remove_AT (comp_unit
, DW_AT_language
);
9081 switch_to_section (debug_skeleton_info_section
);
9082 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
9084 /* Produce the skeleton compilation-unit header. This one differs enough from
9085 a normal CU header that it's better not to call output_compilation_unit
9087 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9088 dw2_asm_output_data (4, 0xffffffff,
9089 "Initial length escape value indicating 64-bit DWARF extension");
9091 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9092 DWARF_COMPILE_UNIT_HEADER_SIZE
9093 - DWARF_INITIAL_LENGTH_SIZE
9094 + size_of_die (comp_unit
),
9095 "Length of Compilation Unit Info");
9096 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
9097 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
9098 debug_abbrev_section
,
9099 "Offset Into Abbrev. Section");
9100 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9102 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
9103 output_die (comp_unit
);
9105 /* Build the skeleton debug_abbrev section. */
9106 switch_to_section (debug_skeleton_abbrev_section
);
9107 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
9109 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
9111 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
9114 /* Output a comdat type unit DIE and its children. */
9117 output_comdat_type_unit (comdat_type_node
*node
)
9119 const char *secname
;
9122 #if defined (OBJECT_FORMAT_ELF)
9126 /* First mark all the DIEs in this CU so we know which get local refs. */
9127 mark_dies (node
->root_die
);
9129 external_ref_hash_type
*extern_map
= optimize_external_refs (node
->root_die
);
9131 build_abbrev_table (node
->root_die
, extern_map
);
9136 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9137 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
9138 calc_die_sizes (node
->root_die
);
9140 #if defined (OBJECT_FORMAT_ELF)
9141 if (!dwarf_split_debug_info
)
9142 secname
= ".debug_types";
9144 secname
= ".debug_types.dwo";
9146 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9147 sprintf (tmp
, "wt.");
9148 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9149 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9150 comdat_key
= get_identifier (tmp
);
9151 targetm
.asm_out
.named_section (secname
,
9152 SECTION_DEBUG
| SECTION_LINKONCE
,
9155 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9156 sprintf (tmp
, ".gnu.linkonce.wt.");
9157 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9158 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9160 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9163 /* Output debugging information. */
9164 output_compilation_unit_header ();
9165 output_signature (node
->signature
, "Type Signature");
9166 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
9167 "Offset to Type DIE");
9168 output_die (node
->root_die
);
9170 unmark_dies (node
->root_die
);
9173 /* Return the DWARF2/3 pubname associated with a decl. */
9176 dwarf2_name (tree decl
, int scope
)
9178 if (DECL_NAMELESS (decl
))
9180 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
9183 /* Add a new entry to .debug_pubnames if appropriate. */
9186 add_pubname_string (const char *str
, dw_die_ref die
)
9191 e
.name
= xstrdup (str
);
9192 vec_safe_push (pubname_table
, e
);
9196 add_pubname (tree decl
, dw_die_ref die
)
9198 if (!want_pubnames ())
9201 /* Don't add items to the table when we expect that the consumer will have
9202 just read the enclosing die. For example, if the consumer is looking at a
9203 class_member, it will either be inside the class already, or will have just
9204 looked up the class to find the member. Either way, searching the class is
9205 faster than searching the index. */
9206 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
9207 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9209 const char *name
= dwarf2_name (decl
, 1);
9212 add_pubname_string (name
, die
);
9216 /* Add an enumerator to the pubnames section. */
9219 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
9223 gcc_assert (scope_name
);
9224 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
9226 vec_safe_push (pubname_table
, e
);
9229 /* Add a new entry to .debug_pubtypes if appropriate. */
9232 add_pubtype (tree decl
, dw_die_ref die
)
9236 if (!want_pubnames ())
9239 if ((TREE_PUBLIC (decl
)
9240 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9241 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9244 const char *scope_name
= "";
9245 const char *sep
= is_cxx () ? "::" : ".";
9248 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9249 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9251 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9252 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9253 scope_name
= concat (scope_name
, sep
, NULL
);
9259 name
= type_tag (decl
);
9261 name
= lang_hooks
.dwarf_name (decl
, 1);
9263 /* If we don't have a name for the type, there's no point in adding
9265 if (name
!= NULL
&& name
[0] != '\0')
9268 e
.name
= concat (scope_name
, name
, NULL
);
9269 vec_safe_push (pubtype_table
, e
);
9272 /* Although it might be more consistent to add the pubinfo for the
9273 enumerators as their dies are created, they should only be added if the
9274 enum type meets the criteria above. So rather than re-check the parent
9275 enum type whenever an enumerator die is created, just output them all
9276 here. This isn't protected by the name conditional because anonymous
9277 enums don't have names. */
9278 if (die
->die_tag
== DW_TAG_enumeration_type
)
9282 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9287 /* Output a single entry in the pubnames table. */
9290 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
9292 dw_die_ref die
= entry
->die
;
9293 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
9295 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9297 if (debug_generate_pub_sections
== 2)
9299 /* This logic follows gdb's method for determining the value of the flag
9301 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
9302 switch (die
->die_tag
)
9304 case DW_TAG_typedef
:
9305 case DW_TAG_base_type
:
9306 case DW_TAG_subrange_type
:
9307 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9308 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9310 case DW_TAG_enumerator
:
9311 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9312 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9313 if (!is_cxx () && !is_java ())
9314 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9316 case DW_TAG_subprogram
:
9317 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9318 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
9320 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9322 case DW_TAG_constant
:
9323 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9324 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9325 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9327 case DW_TAG_variable
:
9328 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9329 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9330 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9332 case DW_TAG_namespace
:
9333 case DW_TAG_imported_declaration
:
9334 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9336 case DW_TAG_class_type
:
9337 case DW_TAG_interface_type
:
9338 case DW_TAG_structure_type
:
9339 case DW_TAG_union_type
:
9340 case DW_TAG_enumeration_type
:
9341 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9342 if (!is_cxx () && !is_java ())
9343 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9346 /* An unusual tag. Leave the flag-byte empty. */
9349 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
9353 dw2_asm_output_nstring (entry
->name
, -1, "external name");
9357 /* Output the public names table used to speed up access to externally
9358 visible names; or the public types table used to find type definitions. */
9361 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9364 unsigned long pubnames_length
= size_of_pubnames (names
);
9367 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9368 dw2_asm_output_data (4, 0xffffffff,
9369 "Initial length escape value indicating 64-bit DWARF extension");
9370 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
, "Pub Info Length");
9372 /* Version number for pubnames/pubtypes is independent of dwarf version. */
9373 dw2_asm_output_data (2, 2, "DWARF Version");
9375 if (dwarf_split_debug_info
)
9376 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9377 debug_skeleton_info_section
,
9378 "Offset of Compilation Unit Info");
9380 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9382 "Offset of Compilation Unit Info");
9383 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9384 "Compilation Unit Length");
9386 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9388 if (include_pubname_in_output (names
, pub
))
9390 dw_offset die_offset
= pub
->die
->die_offset
;
9392 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9393 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9394 gcc_assert (pub
->die
->die_mark
);
9396 /* If we're putting types in their own .debug_types sections,
9397 the .debug_pubtypes table will still point to the compile
9398 unit (not the type unit), so we want to use the offset of
9399 the skeleton DIE (if there is one). */
9400 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9402 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9404 if (type_node
!= NULL
)
9405 die_offset
= (type_node
->skeleton_die
!= NULL
9406 ? type_node
->skeleton_die
->die_offset
9407 : comp_unit_die ()->die_offset
);
9410 output_pubname (die_offset
, pub
);
9414 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9417 /* Output public names and types tables if necessary. */
9420 output_pubtables (void)
9422 if (!want_pubnames () || !info_section_emitted
)
9425 switch_to_section (debug_pubnames_section
);
9426 output_pubnames (pubname_table
);
9427 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
9428 It shouldn't hurt to emit it always, since pure DWARF2 consumers
9429 simply won't look for the section. */
9430 switch_to_section (debug_pubtypes_section
);
9431 output_pubnames (pubtype_table
);
9435 /* Output the information that goes into the .debug_aranges table.
9436 Namely, define the beginning and ending address range of the
9437 text section generated for this compilation unit. */
9440 output_aranges (unsigned long aranges_length
)
9444 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9445 dw2_asm_output_data (4, 0xffffffff,
9446 "Initial length escape value indicating 64-bit DWARF extension");
9447 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9448 "Length of Address Ranges Info");
9449 /* Version number for aranges is still 2, even in DWARF3. */
9450 dw2_asm_output_data (2, 2, "DWARF Version");
9451 if (dwarf_split_debug_info
)
9452 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9453 debug_skeleton_info_section
,
9454 "Offset of Compilation Unit Info");
9456 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9458 "Offset of Compilation Unit Info");
9459 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9460 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9462 /* We need to align to twice the pointer size here. */
9463 if (DWARF_ARANGES_PAD_SIZE
)
9465 /* Pad using a 2 byte words so that padding is correct for any
9467 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9468 2 * DWARF2_ADDR_SIZE
);
9469 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9470 dw2_asm_output_data (2, 0, NULL
);
9473 /* It is necessary not to output these entries if the sections were
9474 not used; if the sections were not used, the length will be 0 and
9475 the address may end up as 0 if the section is discarded by ld
9476 --gc-sections, leaving an invalid (0, 0) entry that can be
9477 confused with the terminator. */
9478 if (text_section_used
)
9480 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9481 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9482 text_section_label
, "Length");
9484 if (cold_text_section_used
)
9486 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9488 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9489 cold_text_section_label
, "Length");
9492 if (have_multiple_function_sections
)
9497 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9499 if (DECL_IGNORED_P (fde
->decl
))
9501 if (!fde
->in_std_section
)
9503 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9505 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9506 fde
->dw_fde_begin
, "Length");
9508 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9510 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9512 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9513 fde
->dw_fde_second_begin
, "Length");
9518 /* Output the terminator words. */
9519 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9520 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9523 /* Add a new entry to .debug_ranges. Return the offset at which it
9527 add_ranges_num (int num
)
9529 unsigned int in_use
= ranges_table_in_use
;
9531 if (in_use
== ranges_table_allocated
)
9533 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9534 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9535 ranges_table_allocated
);
9536 memset (ranges_table
+ ranges_table_in_use
, 0,
9537 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9540 ranges_table
[in_use
].num
= num
;
9541 ranges_table_in_use
= in_use
+ 1;
9543 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9546 /* Add a new entry to .debug_ranges corresponding to a block, or a
9547 range terminator if BLOCK is NULL. */
9550 add_ranges (const_tree block
)
9552 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9555 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9556 When using dwarf_split_debug_info, address attributes in dies destined
9557 for the final executable should be direct references--setting the
9558 parameter force_direct ensures this behavior. */
9561 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9562 bool *added
, bool force_direct
)
9564 unsigned int in_use
= ranges_by_label_in_use
;
9565 unsigned int offset
;
9567 if (in_use
== ranges_by_label_allocated
)
9569 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9570 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9572 ranges_by_label_allocated
);
9573 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9574 RANGES_TABLE_INCREMENT
9575 * sizeof (struct dw_ranges_by_label_struct
));
9578 ranges_by_label
[in_use
].begin
= begin
;
9579 ranges_by_label
[in_use
].end
= end
;
9580 ranges_by_label_in_use
= in_use
+ 1;
9582 offset
= add_ranges_num (-(int)in_use
- 1);
9585 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9591 output_ranges (void)
9594 static const char *const start_fmt
= "Offset %#x";
9595 const char *fmt
= start_fmt
;
9597 for (i
= 0; i
< ranges_table_in_use
; i
++)
9599 int block_num
= ranges_table
[i
].num
;
9603 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9604 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9606 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9607 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9609 /* If all code is in the text section, then the compilation
9610 unit base address defaults to DW_AT_low_pc, which is the
9611 base of the text section. */
9612 if (!have_multiple_function_sections
)
9614 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9616 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9617 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9618 text_section_label
, NULL
);
9621 /* Otherwise, the compilation unit base address is zero,
9622 which allows us to use absolute addresses, and not worry
9623 about whether the target supports cross-section
9627 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9628 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9629 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9635 /* Negative block_num stands for an index into ranges_by_label. */
9636 else if (block_num
< 0)
9638 int lab_idx
= - block_num
- 1;
9640 if (!have_multiple_function_sections
)
9644 /* If we ever use add_ranges_by_labels () for a single
9645 function section, all we have to do is to take out
9647 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9648 ranges_by_label
[lab_idx
].begin
,
9650 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9651 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9652 ranges_by_label
[lab_idx
].end
,
9653 text_section_label
, NULL
);
9658 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9659 ranges_by_label
[lab_idx
].begin
,
9660 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9661 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9662 ranges_by_label
[lab_idx
].end
,
9668 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9669 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9675 /* Data structure containing information about input files. */
9678 const char *path
; /* Complete file name. */
9679 const char *fname
; /* File name part. */
9680 int length
; /* Length of entire string. */
9681 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9682 int dir_idx
; /* Index in directory table. */
9685 /* Data structure containing information about directories with source
9689 const char *path
; /* Path including directory name. */
9690 int length
; /* Path length. */
9691 int prefix
; /* Index of directory entry which is a prefix. */
9692 int count
; /* Number of files in this directory. */
9693 int dir_idx
; /* Index of directory used as base. */
9696 /* Callback function for file_info comparison. We sort by looking at
9697 the directories in the path. */
9700 file_info_cmp (const void *p1
, const void *p2
)
9702 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9703 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9704 const unsigned char *cp1
;
9705 const unsigned char *cp2
;
9707 /* Take care of file names without directories. We need to make sure that
9708 we return consistent values to qsort since some will get confused if
9709 we return the same value when identical operands are passed in opposite
9710 orders. So if neither has a directory, return 0 and otherwise return
9711 1 or -1 depending on which one has the directory. */
9712 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9713 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9715 cp1
= (const unsigned char *) s1
->path
;
9716 cp2
= (const unsigned char *) s2
->path
;
9722 /* Reached the end of the first path? If so, handle like above. */
9723 if ((cp1
== (const unsigned char *) s1
->fname
)
9724 || (cp2
== (const unsigned char *) s2
->fname
))
9725 return ((cp2
== (const unsigned char *) s2
->fname
)
9726 - (cp1
== (const unsigned char *) s1
->fname
));
9728 /* Character of current path component the same? */
9729 else if (*cp1
!= *cp2
)
9734 struct file_name_acquire_data
9736 struct file_info
*files
;
9741 /* Traversal function for the hash table. */
9744 file_name_acquire (void ** slot
, void *data
)
9746 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
9747 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
9748 struct file_info
*fi
;
9751 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9753 if (! d
->emitted_number
)
9756 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9758 fi
= fnad
->files
+ fnad
->used_files
++;
9760 /* Skip all leading "./". */
9762 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9765 /* Create a new array entry. */
9767 fi
->length
= strlen (f
);
9770 /* Search for the file name part. */
9771 f
= strrchr (f
, DIR_SEPARATOR
);
9772 #if defined (DIR_SEPARATOR_2)
9774 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9778 if (f
== NULL
|| f
< g
)
9784 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9788 /* Output the directory table and the file name table. We try to minimize
9789 the total amount of memory needed. A heuristic is used to avoid large
9790 slowdowns with many input files. */
9793 output_file_names (void)
9795 struct file_name_acquire_data fnad
;
9797 struct file_info
*files
;
9798 struct dir_info
*dirs
;
9806 if (!last_emitted_file
)
9808 dw2_asm_output_data (1, 0, "End directory table");
9809 dw2_asm_output_data (1, 0, "End file name table");
9813 numfiles
= last_emitted_file
->emitted_number
;
9815 /* Allocate the various arrays we need. */
9816 files
= XALLOCAVEC (struct file_info
, numfiles
);
9817 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9820 fnad
.used_files
= 0;
9821 fnad
.max_files
= numfiles
;
9822 htab_traverse (file_table
, file_name_acquire
, &fnad
);
9823 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9825 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9827 /* Find all the different directories used. */
9828 dirs
[0].path
= files
[0].path
;
9829 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9830 dirs
[0].prefix
= -1;
9832 dirs
[0].dir_idx
= 0;
9833 files
[0].dir_idx
= 0;
9836 for (i
= 1; i
< numfiles
; i
++)
9837 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9838 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9839 dirs
[ndirs
- 1].length
) == 0)
9841 /* Same directory as last entry. */
9842 files
[i
].dir_idx
= ndirs
- 1;
9843 ++dirs
[ndirs
- 1].count
;
9849 /* This is a new directory. */
9850 dirs
[ndirs
].path
= files
[i
].path
;
9851 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9852 dirs
[ndirs
].count
= 1;
9853 dirs
[ndirs
].dir_idx
= ndirs
;
9854 files
[i
].dir_idx
= ndirs
;
9856 /* Search for a prefix. */
9857 dirs
[ndirs
].prefix
= -1;
9858 for (j
= 0; j
< ndirs
; j
++)
9859 if (dirs
[j
].length
< dirs
[ndirs
].length
9860 && dirs
[j
].length
> 1
9861 && (dirs
[ndirs
].prefix
== -1
9862 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9863 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9864 dirs
[ndirs
].prefix
= j
;
9869 /* Now to the actual work. We have to find a subset of the directories which
9870 allow expressing the file name using references to the directory table
9871 with the least amount of characters. We do not do an exhaustive search
9872 where we would have to check out every combination of every single
9873 possible prefix. Instead we use a heuristic which provides nearly optimal
9874 results in most cases and never is much off. */
9875 saved
= XALLOCAVEC (int, ndirs
);
9876 savehere
= XALLOCAVEC (int, ndirs
);
9878 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9879 for (i
= 0; i
< ndirs
; i
++)
9884 /* We can always save some space for the current directory. But this
9885 does not mean it will be enough to justify adding the directory. */
9886 savehere
[i
] = dirs
[i
].length
;
9887 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9889 for (j
= i
+ 1; j
< ndirs
; j
++)
9892 if (saved
[j
] < dirs
[i
].length
)
9894 /* Determine whether the dirs[i] path is a prefix of the
9899 while (k
!= -1 && k
!= (int) i
)
9904 /* Yes it is. We can possibly save some memory by
9905 writing the filenames in dirs[j] relative to
9907 savehere
[j
] = dirs
[i
].length
;
9908 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9913 /* Check whether we can save enough to justify adding the dirs[i]
9915 if (total
> dirs
[i
].length
+ 1)
9917 /* It's worthwhile adding. */
9918 for (j
= i
; j
< ndirs
; j
++)
9919 if (savehere
[j
] > 0)
9921 /* Remember how much we saved for this directory so far. */
9922 saved
[j
] = savehere
[j
];
9924 /* Remember the prefix directory. */
9925 dirs
[j
].dir_idx
= i
;
9930 /* Emit the directory name table. */
9931 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9932 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9933 dw2_asm_output_nstring (dirs
[i
].path
,
9935 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
9936 "Directory Entry: %#x", i
+ idx_offset
);
9938 dw2_asm_output_data (1, 0, "End directory table");
9940 /* We have to emit them in the order of emitted_number since that's
9941 used in the debug info generation. To do this efficiently we
9942 generate a back-mapping of the indices first. */
9943 backmap
= XALLOCAVEC (int, numfiles
);
9944 for (i
= 0; i
< numfiles
; i
++)
9945 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9947 /* Now write all the file names. */
9948 for (i
= 0; i
< numfiles
; i
++)
9950 int file_idx
= backmap
[i
];
9951 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9953 #ifdef VMS_DEBUGGING_INFO
9954 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9956 /* Setting these fields can lead to debugger miscomparisons,
9957 but VMS Debug requires them to be set correctly. */
9962 int maxfilelen
= strlen (files
[file_idx
].path
)
9963 + dirs
[dir_idx
].length
9964 + MAX_VMS_VERSION_LEN
+ 1;
9965 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
9967 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
9968 snprintf (filebuf
, maxfilelen
, "%s;%d",
9969 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
9971 dw2_asm_output_nstring
9972 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
9974 /* Include directory index. */
9975 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9977 /* Modification time. */
9978 dw2_asm_output_data_uleb128
9979 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
9983 /* File length in bytes. */
9984 dw2_asm_output_data_uleb128
9985 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
9989 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
9990 "File Entry: %#x", (unsigned) i
+ 1);
9992 /* Include directory index. */
9993 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9995 /* Modification time. */
9996 dw2_asm_output_data_uleb128 (0, NULL
);
9998 /* File length in bytes. */
9999 dw2_asm_output_data_uleb128 (0, NULL
);
10000 #endif /* VMS_DEBUGGING_INFO */
10003 dw2_asm_output_data (1, 0, "End file name table");
10007 /* Output one line number table into the .debug_line section. */
10010 output_one_line_info_table (dw_line_info_table
*table
)
10012 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10013 unsigned int current_line
= 1;
10014 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
10015 dw_line_info_entry
*ent
;
10018 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
10020 switch (ent
->opcode
)
10022 case LI_set_address
:
10023 /* ??? Unfortunately, we have little choice here currently, and
10024 must always use the most general form. GCC does not know the
10025 address delta itself, so we can't use DW_LNS_advance_pc. Many
10026 ports do have length attributes which will give an upper bound
10027 on the address range. We could perhaps use length attributes
10028 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
10029 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
10031 /* This can handle any delta. This takes
10032 4+DWARF2_ADDR_SIZE bytes. */
10033 dw2_asm_output_data (1, 0, "set address %s", line_label
);
10034 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10035 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10036 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
10040 if (ent
->val
== current_line
)
10042 /* We still need to start a new row, so output a copy insn. */
10043 dw2_asm_output_data (1, DW_LNS_copy
,
10044 "copy line %u", current_line
);
10048 int line_offset
= ent
->val
- current_line
;
10049 int line_delta
= line_offset
- DWARF_LINE_BASE
;
10051 current_line
= ent
->val
;
10052 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
10054 /* This can handle deltas from -10 to 234, using the current
10055 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
10056 This takes 1 byte. */
10057 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
10058 "line %u", current_line
);
10062 /* This can handle any delta. This takes at least 4 bytes,
10063 depending on the value being encoded. */
10064 dw2_asm_output_data (1, DW_LNS_advance_line
,
10065 "advance to line %u", current_line
);
10066 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
10067 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
10073 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
10074 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10077 case LI_set_column
:
10078 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
10079 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10082 case LI_negate_stmt
:
10083 current_is_stmt
= !current_is_stmt
;
10084 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
10085 "is_stmt %d", current_is_stmt
);
10088 case LI_set_prologue_end
:
10089 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
10090 "set prologue end");
10093 case LI_set_epilogue_begin
:
10094 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
10095 "set epilogue begin");
10098 case LI_set_discriminator
:
10099 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
10100 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
10101 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
10102 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
10107 /* Emit debug info for the address of the end of the table. */
10108 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
10109 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10110 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10111 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
10113 dw2_asm_output_data (1, 0, "end sequence");
10114 dw2_asm_output_data_uleb128 (1, NULL
);
10115 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
10118 /* Output the source line number correspondence information. This
10119 information goes into the .debug_line section. */
10122 output_line_info (bool prologue_only
)
10124 char l1
[20], l2
[20], p1
[20], p2
[20];
10125 int ver
= dwarf_version
;
10126 bool saw_one
= false;
10129 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
10130 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
10131 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
10132 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
10134 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10135 dw2_asm_output_data (4, 0xffffffff,
10136 "Initial length escape value indicating 64-bit DWARF extension");
10137 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
10138 "Length of Source Line Info");
10139 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
10141 dw2_asm_output_data (2, ver
, "DWARF Version");
10142 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
10143 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
10145 /* Define the architecture-dependent minimum instruction length (in bytes).
10146 In this implementation of DWARF, this field is used for information
10147 purposes only. Since GCC generates assembly language, we have no
10148 a priori knowledge of how many instruction bytes are generated for each
10149 source line, and therefore can use only the DW_LNE_set_address and
10150 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10151 this as '1', which is "correct enough" for all architectures,
10152 and don't let the target override. */
10153 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10156 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
10157 "Maximum Operations Per Instruction");
10158 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
10159 "Default is_stmt_start flag");
10160 dw2_asm_output_data (1, DWARF_LINE_BASE
,
10161 "Line Base Value (Special Opcodes)");
10162 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
10163 "Line Range Value (Special Opcodes)");
10164 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
10165 "Special Opcode Base");
10167 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
10172 case DW_LNS_advance_pc
:
10173 case DW_LNS_advance_line
:
10174 case DW_LNS_set_file
:
10175 case DW_LNS_set_column
:
10176 case DW_LNS_fixed_advance_pc
:
10177 case DW_LNS_set_isa
:
10185 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
10189 /* Write out the information about the files we use. */
10190 output_file_names ();
10191 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
10194 /* Output the marker for the end of the line number info. */
10195 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10199 if (separate_line_info
)
10201 dw_line_info_table
*table
;
10204 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
10207 output_one_line_info_table (table
);
10211 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
10213 output_one_line_info_table (cold_text_section_line_info
);
10217 /* ??? Some Darwin linkers crash on a .debug_line section with no
10218 sequences. Further, merely a DW_LNE_end_sequence entry is not
10219 sufficient -- the address column must also be initialized.
10220 Make sure to output at least one set_address/end_sequence pair,
10221 choosing .text since that section is always present. */
10222 if (text_section_line_info
->in_use
|| !saw_one
)
10223 output_one_line_info_table (text_section_line_info
);
10225 /* Output the marker for the end of the line number info. */
10226 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10229 /* Given a pointer to a tree node for some base type, return a pointer to
10230 a DIE that describes the given type.
10232 This routine must only be called for GCC type nodes that correspond to
10233 Dwarf base (fundamental) types. */
10236 base_type_die (tree type
)
10238 dw_die_ref base_type_result
;
10239 enum dwarf_type encoding
;
10241 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
10244 /* If this is a subtype that should not be emitted as a subrange type,
10245 use the base type. See subrange_type_for_debug_p. */
10246 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
10247 type
= TREE_TYPE (type
);
10249 switch (TREE_CODE (type
))
10252 if ((dwarf_version
>= 4 || !dwarf_strict
)
10253 && TYPE_NAME (type
)
10254 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10255 && DECL_IS_BUILTIN (TYPE_NAME (type
))
10256 && DECL_NAME (TYPE_NAME (type
)))
10258 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
10259 if (strcmp (name
, "char16_t") == 0
10260 || strcmp (name
, "char32_t") == 0)
10262 encoding
= DW_ATE_UTF
;
10266 if (TYPE_STRING_FLAG (type
))
10268 if (TYPE_UNSIGNED (type
))
10269 encoding
= DW_ATE_unsigned_char
;
10271 encoding
= DW_ATE_signed_char
;
10273 else if (TYPE_UNSIGNED (type
))
10274 encoding
= DW_ATE_unsigned
;
10276 encoding
= DW_ATE_signed
;
10280 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
10282 if (dwarf_version
>= 3 || !dwarf_strict
)
10283 encoding
= DW_ATE_decimal_float
;
10285 encoding
= DW_ATE_lo_user
;
10288 encoding
= DW_ATE_float
;
10291 case FIXED_POINT_TYPE
:
10292 if (!(dwarf_version
>= 3 || !dwarf_strict
))
10293 encoding
= DW_ATE_lo_user
;
10294 else if (TYPE_UNSIGNED (type
))
10295 encoding
= DW_ATE_unsigned_fixed
;
10297 encoding
= DW_ATE_signed_fixed
;
10300 /* Dwarf2 doesn't know anything about complex ints, so use
10301 a user defined type for it. */
10303 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10304 encoding
= DW_ATE_complex_float
;
10306 encoding
= DW_ATE_lo_user
;
10310 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10311 encoding
= DW_ATE_boolean
;
10315 /* No other TREE_CODEs are Dwarf fundamental types. */
10316 gcc_unreachable ();
10319 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10321 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10322 int_size_in_bytes (type
));
10323 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10324 add_pubtype (type
, base_type_result
);
10326 return base_type_result
;
10329 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
10330 named 'auto' in its type: return true for it, false otherwise. */
10333 is_cxx_auto (tree type
)
10337 tree name
= TYPE_IDENTIFIER (type
);
10338 if (name
== get_identifier ("auto")
10339 || name
== get_identifier ("decltype(auto)"))
10345 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10346 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10349 is_base_type (tree type
)
10351 switch (TREE_CODE (type
))
10357 case FIXED_POINT_TYPE
:
10365 case QUAL_UNION_TYPE
:
10366 case ENUMERAL_TYPE
:
10367 case FUNCTION_TYPE
:
10370 case REFERENCE_TYPE
:
10378 if (is_cxx_auto (type
))
10380 gcc_unreachable ();
10386 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10387 node, return the size in bits for the type if it is a constant, or else
10388 return the alignment for the type if the type's size is not constant, or
10389 else return BITS_PER_WORD if the type actually turns out to be an
10390 ERROR_MARK node. */
10392 static inline unsigned HOST_WIDE_INT
10393 simple_type_size_in_bits (const_tree type
)
10395 if (TREE_CODE (type
) == ERROR_MARK
)
10396 return BITS_PER_WORD
;
10397 else if (TYPE_SIZE (type
) == NULL_TREE
)
10399 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
10400 return tree_to_uhwi (TYPE_SIZE (type
));
10402 return TYPE_ALIGN (type
);
10405 /* Similarly, but return an offset_int instead of UHWI. */
10407 static inline offset_int
10408 offset_int_type_size_in_bits (const_tree type
)
10410 if (TREE_CODE (type
) == ERROR_MARK
)
10411 return BITS_PER_WORD
;
10412 else if (TYPE_SIZE (type
) == NULL_TREE
)
10414 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10415 return wi::to_offset (TYPE_SIZE (type
));
10417 return TYPE_ALIGN (type
);
10420 /* Given a pointer to a tree node for a subrange type, return a pointer
10421 to a DIE that describes the given type. */
10424 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10426 dw_die_ref subrange_die
;
10427 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10429 if (context_die
== NULL
)
10430 context_die
= comp_unit_die ();
10432 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10434 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10436 /* The size of the subrange type and its base type do not match,
10437 so we need to generate a size attribute for the subrange type. */
10438 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10442 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
10444 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
10446 return subrange_die
;
10449 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10450 entry that chains various modifiers in front of the given type. */
10453 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
10454 dw_die_ref context_die
)
10456 enum tree_code code
= TREE_CODE (type
);
10457 dw_die_ref mod_type_die
;
10458 dw_die_ref sub_die
= NULL
;
10459 tree item_type
= NULL
;
10460 tree qualified_type
;
10461 tree name
, low
, high
;
10462 dw_die_ref mod_scope
;
10464 if (code
== ERROR_MARK
)
10467 /* See if we already have the appropriately qualified variant of
10470 = get_qualified_type (type
,
10471 ((is_const_type
? TYPE_QUAL_CONST
: 0)
10472 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
10474 if (qualified_type
== sizetype
10475 && TYPE_NAME (qualified_type
)
10476 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10478 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10480 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10481 && TYPE_PRECISION (t
)
10482 == TYPE_PRECISION (qualified_type
)
10483 && TYPE_UNSIGNED (t
)
10484 == TYPE_UNSIGNED (qualified_type
));
10485 qualified_type
= t
;
10488 /* If we do, then we can just use its DIE, if it exists. */
10489 if (qualified_type
)
10491 mod_type_die
= lookup_type_die (qualified_type
);
10493 return mod_type_die
;
10496 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10498 /* Handle C typedef types. */
10499 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10500 && !DECL_ARTIFICIAL (name
))
10502 tree dtype
= TREE_TYPE (name
);
10504 if (qualified_type
== dtype
)
10506 /* For a named type, use the typedef. */
10507 gen_type_die (qualified_type
, context_die
);
10508 return lookup_type_die (qualified_type
);
10510 else if (is_const_type
< TYPE_READONLY (dtype
)
10511 || is_volatile_type
< TYPE_VOLATILE (dtype
)
10512 || (is_const_type
<= TYPE_READONLY (dtype
)
10513 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
10514 && DECL_ORIGINAL_TYPE (name
) != type
))
10515 /* cv-unqualified version of named type. Just use the unnamed
10516 type to which it refers. */
10517 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10518 is_const_type
, is_volatile_type
,
10520 /* Else cv-qualified version of named type; fall through. */
10523 mod_scope
= scope_die_for (type
, context_die
);
10526 /* If both is_const_type and is_volatile_type, prefer the path
10527 which leads to a qualified type. */
10528 && (!is_volatile_type
10529 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
10530 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
10532 mod_type_die
= new_die (DW_TAG_const_type
, mod_scope
, type
);
10533 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
10535 else if (is_volatile_type
)
10537 mod_type_die
= new_die (DW_TAG_volatile_type
, mod_scope
, type
);
10538 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
10540 else if (code
== POINTER_TYPE
)
10542 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10543 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10544 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10545 item_type
= TREE_TYPE (type
);
10546 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10547 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10548 TYPE_ADDR_SPACE (item_type
));
10550 else if (code
== REFERENCE_TYPE
)
10552 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10553 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10556 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10557 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10558 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10559 item_type
= TREE_TYPE (type
);
10560 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10561 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10562 TYPE_ADDR_SPACE (item_type
));
10564 else if (code
== INTEGER_TYPE
10565 && TREE_TYPE (type
) != NULL_TREE
10566 && subrange_type_for_debug_p (type
, &low
, &high
))
10568 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10569 item_type
= TREE_TYPE (type
);
10571 else if (is_base_type (type
))
10572 mod_type_die
= base_type_die (type
);
10575 gen_type_die (type
, context_die
);
10577 /* We have to get the type_main_variant here (and pass that to the
10578 `lookup_type_die' routine) because the ..._TYPE node we have
10579 might simply be a *copy* of some original type node (where the
10580 copy was created to help us keep track of typedef names) and
10581 that copy might have a different TYPE_UID from the original
10583 if (TREE_CODE (type
) != VECTOR_TYPE
)
10584 return lookup_type_die (type_main_variant (type
));
10586 /* Vectors have the debugging information in the type,
10587 not the main variant. */
10588 return lookup_type_die (type
);
10591 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10592 don't output a DW_TAG_typedef, since there isn't one in the
10593 user's program; just attach a DW_AT_name to the type.
10594 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10595 if the base type already has the same name. */
10597 && ((TREE_CODE (name
) != TYPE_DECL
10598 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10599 || (!is_const_type
&& !is_volatile_type
)))
10600 || (TREE_CODE (name
) == TYPE_DECL
10601 && TREE_TYPE (name
) == qualified_type
10602 && DECL_NAME (name
))))
10604 if (TREE_CODE (name
) == TYPE_DECL
)
10605 /* Could just call add_name_and_src_coords_attributes here,
10606 but since this is a builtin type it doesn't have any
10607 useful source coordinates anyway. */
10608 name
= DECL_NAME (name
);
10609 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10611 /* This probably indicates a bug. */
10612 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10614 name
= TYPE_IDENTIFIER (type
);
10615 add_name_attribute (mod_type_die
,
10616 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10619 if (qualified_type
)
10620 equate_type_number_to_die (qualified_type
, mod_type_die
);
10623 /* We must do this after the equate_type_number_to_die call, in case
10624 this is a recursive type. This ensures that the modified_type_die
10625 recursion will terminate even if the type is recursive. Recursive
10626 types are possible in Ada. */
10627 sub_die
= modified_type_die (item_type
,
10628 TYPE_READONLY (item_type
),
10629 TYPE_VOLATILE (item_type
),
10632 if (sub_die
!= NULL
)
10633 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10635 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10636 if (TYPE_ARTIFICIAL (type
))
10637 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10639 return mod_type_die
;
10642 /* Generate DIEs for the generic parameters of T.
10643 T must be either a generic type or a generic function.
10644 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10647 gen_generic_params_dies (tree t
)
10651 dw_die_ref die
= NULL
;
10654 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10658 die
= lookup_type_die (t
);
10659 else if (DECL_P (t
))
10660 die
= lookup_decl_die (t
);
10664 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10666 /* T has no generic parameter. It means T is neither a generic type
10667 or function. End of story. */
10670 parms_num
= TREE_VEC_LENGTH (parms
);
10671 args
= lang_hooks
.get_innermost_generic_args (t
);
10672 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
10673 non_default
= int_cst_value (TREE_CHAIN (args
));
10675 non_default
= TREE_VEC_LENGTH (args
);
10676 for (i
= 0; i
< parms_num
; i
++)
10678 tree parm
, arg
, arg_pack_elems
;
10679 dw_die_ref parm_die
;
10681 parm
= TREE_VEC_ELT (parms
, i
);
10682 arg
= TREE_VEC_ELT (args
, i
);
10683 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
10684 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
10686 if (parm
&& TREE_VALUE (parm
) && arg
)
10688 /* If PARM represents a template parameter pack,
10689 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10690 by DW_TAG_template_*_parameter DIEs for the argument
10691 pack elements of ARG. Note that ARG would then be
10692 an argument pack. */
10693 if (arg_pack_elems
)
10694 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
10698 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
10699 true /* emit name */, die
);
10700 if (i
>= non_default
)
10701 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
10706 /* Create and return a DIE for PARM which should be
10707 the representation of a generic type parameter.
10708 For instance, in the C++ front end, PARM would be a template parameter.
10709 ARG is the argument to PARM.
10710 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10712 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10713 as a child node. */
10716 generic_parameter_die (tree parm
, tree arg
,
10718 dw_die_ref parent_die
)
10720 dw_die_ref tmpl_die
= NULL
;
10721 const char *name
= NULL
;
10723 if (!parm
|| !DECL_NAME (parm
) || !arg
)
10726 /* We support non-type generic parameters and arguments,
10727 type generic parameters and arguments, as well as
10728 generic generic parameters (a.k.a. template template parameters in C++)
10730 if (TREE_CODE (parm
) == PARM_DECL
)
10731 /* PARM is a nontype generic parameter */
10732 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
10733 else if (TREE_CODE (parm
) == TYPE_DECL
)
10734 /* PARM is a type generic parameter. */
10735 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
10736 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10737 /* PARM is a generic generic parameter.
10738 Its DIE is a GNU extension. It shall have a
10739 DW_AT_name attribute to represent the name of the template template
10740 parameter, and a DW_AT_GNU_template_name attribute to represent the
10741 name of the template template argument. */
10742 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
10745 gcc_unreachable ();
10751 /* If PARM is a generic parameter pack, it means we are
10752 emitting debug info for a template argument pack element.
10753 In other terms, ARG is a template argument pack element.
10754 In that case, we don't emit any DW_AT_name attribute for
10758 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
10760 add_AT_string (tmpl_die
, DW_AT_name
, name
);
10763 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10765 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10766 TMPL_DIE should have a child DW_AT_type attribute that is set
10767 to the type of the argument to PARM, which is ARG.
10768 If PARM is a type generic parameter, TMPL_DIE should have a
10769 child DW_AT_type that is set to ARG. */
10770 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
10771 add_type_attribute (tmpl_die
, tmpl_type
, 0,
10772 TREE_THIS_VOLATILE (tmpl_type
),
10777 /* So TMPL_DIE is a DIE representing a
10778 a generic generic template parameter, a.k.a template template
10779 parameter in C++ and arg is a template. */
10781 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10782 to the name of the argument. */
10783 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
10785 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
10788 if (TREE_CODE (parm
) == PARM_DECL
)
10789 /* So PARM is a non-type generic parameter.
10790 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10791 attribute of TMPL_DIE which value represents the value
10793 We must be careful here:
10794 The value of ARG might reference some function decls.
10795 We might currently be emitting debug info for a generic
10796 type and types are emitted before function decls, we don't
10797 know if the function decls referenced by ARG will actually be
10798 emitted after cgraph computations.
10799 So must defer the generation of the DW_AT_const_value to
10800 after cgraph is ready. */
10801 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
10807 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10808 PARM_PACK must be a template parameter pack. The returned DIE
10809 will be child DIE of PARENT_DIE. */
10812 template_parameter_pack_die (tree parm_pack
,
10813 tree parm_pack_args
,
10814 dw_die_ref parent_die
)
10819 gcc_assert (parent_die
&& parm_pack
);
10821 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
10822 add_name_and_src_coords_attributes (die
, parm_pack
);
10823 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
10824 generic_parameter_die (parm_pack
,
10825 TREE_VEC_ELT (parm_pack_args
, j
),
10826 false /* Don't emit DW_AT_name */,
10831 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10832 an enumerated type. */
10835 type_is_enum (const_tree type
)
10837 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10840 /* Return the DBX register number described by a given RTL node. */
10842 static unsigned int
10843 dbx_reg_number (const_rtx rtl
)
10845 unsigned regno
= REGNO (rtl
);
10847 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10849 #ifdef LEAF_REG_REMAP
10850 if (crtl
->uses_only_leaf_regs
)
10852 int leaf_reg
= LEAF_REG_REMAP (regno
);
10853 if (leaf_reg
!= -1)
10854 regno
= (unsigned) leaf_reg
;
10858 regno
= DBX_REGISTER_NUMBER (regno
);
10859 gcc_assert (regno
!= INVALID_REGNUM
);
10863 /* Optionally add a DW_OP_piece term to a location description expression.
10864 DW_OP_piece is only added if the location description expression already
10865 doesn't end with DW_OP_piece. */
10868 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10870 dw_loc_descr_ref loc
;
10872 if (*list_head
!= NULL
)
10874 /* Find the end of the chain. */
10875 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10878 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10879 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10883 /* Return a location descriptor that designates a machine register or
10884 zero if there is none. */
10886 static dw_loc_descr_ref
10887 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10891 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10894 /* We only use "frame base" when we're sure we're talking about the
10895 post-prologue local stack frame. We do this by *not* running
10896 register elimination until this point, and recognizing the special
10897 argument pointer and soft frame pointer rtx's.
10898 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10899 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
10900 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
10902 dw_loc_descr_ref result
= NULL
;
10904 if (dwarf_version
>= 4 || !dwarf_strict
)
10906 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
10909 add_loc_descr (&result
,
10910 new_loc_descr (DW_OP_stack_value
, 0, 0));
10915 regs
= targetm
.dwarf_register_span (rtl
);
10917 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
10918 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
10921 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
10922 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
10924 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
10928 /* Return a location descriptor that designates a machine register for
10929 a given hard register number. */
10931 static dw_loc_descr_ref
10932 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10934 dw_loc_descr_ref reg_loc_descr
;
10938 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10940 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10942 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10943 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10945 return reg_loc_descr
;
10948 /* Given an RTL of a register, return a location descriptor that
10949 designates a value that spans more than one register. */
10951 static dw_loc_descr_ref
10952 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10953 enum var_init_status initialized
)
10956 dw_loc_descr_ref loc_result
= NULL
;
10958 /* Simple, contiguous registers. */
10959 if (regs
== NULL_RTX
)
10961 unsigned reg
= REGNO (rtl
);
10964 #ifdef LEAF_REG_REMAP
10965 if (crtl
->uses_only_leaf_regs
)
10967 int leaf_reg
= LEAF_REG_REMAP (reg
);
10968 if (leaf_reg
!= -1)
10969 reg
= (unsigned) leaf_reg
;
10973 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
10974 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
10976 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
10981 dw_loc_descr_ref t
;
10983 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
10984 VAR_INIT_STATUS_INITIALIZED
);
10985 add_loc_descr (&loc_result
, t
);
10986 add_loc_descr_op_piece (&loc_result
, size
);
10992 /* Now onto stupid register sets in non contiguous locations. */
10994 gcc_assert (GET_CODE (regs
) == PARALLEL
);
10996 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10999 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
11001 dw_loc_descr_ref t
;
11003 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
11004 VAR_INIT_STATUS_INITIALIZED
);
11005 add_loc_descr (&loc_result
, t
);
11006 add_loc_descr_op_piece (&loc_result
, size
);
11009 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11010 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11014 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
11016 /* Return a location descriptor that designates a constant i,
11017 as a compound operation from constant (i >> shift), constant shift
11020 static dw_loc_descr_ref
11021 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11023 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
11024 add_loc_descr (&ret
, int_loc_descriptor (shift
));
11025 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11029 /* Return a location descriptor that designates a constant. */
11031 static dw_loc_descr_ref
11032 int_loc_descriptor (HOST_WIDE_INT i
)
11034 enum dwarf_location_atom op
;
11036 /* Pick the smallest representation of a constant, rather than just
11037 defaulting to the LEB encoding. */
11040 int clz
= clz_hwi (i
);
11041 int ctz
= ctz_hwi (i
);
11043 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
11044 else if (i
<= 0xff)
11045 op
= DW_OP_const1u
;
11046 else if (i
<= 0xffff)
11047 op
= DW_OP_const2u
;
11048 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11049 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11050 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
11051 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
11052 while DW_OP_const4u is 5 bytes. */
11053 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
11054 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11055 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11056 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
11057 while DW_OP_const4u is 5 bytes. */
11058 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11059 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11060 op
= DW_OP_const4u
;
11061 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11062 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11063 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
11064 while DW_OP_constu of constant >= 0x100000000 takes at least
11066 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11067 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11068 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
11069 >= HOST_BITS_PER_WIDE_INT
)
11070 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
11071 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
11072 while DW_OP_constu takes in this case at least 6 bytes. */
11073 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
11074 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11075 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11076 && size_of_uleb128 (i
) > 6)
11077 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
11078 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
11085 op
= DW_OP_const1s
;
11086 else if (i
>= -0x8000)
11087 op
= DW_OP_const2s
;
11088 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11090 if (size_of_int_loc_descriptor (i
) < 5)
11092 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11093 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11096 op
= DW_OP_const4s
;
11100 if (size_of_int_loc_descriptor (i
)
11101 < (unsigned long) 1 + size_of_sleb128 (i
))
11103 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11104 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11111 return new_loc_descr (op
, i
, 0);
11114 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
11115 without actually allocating it. */
11117 static unsigned long
11118 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11120 return size_of_int_loc_descriptor (i
>> shift
)
11121 + size_of_int_loc_descriptor (shift
)
11125 /* Return size_of_locs (int_loc_descriptor (i)) without
11126 actually allocating it. */
11128 static unsigned long
11129 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
11138 else if (i
<= 0xff)
11140 else if (i
<= 0xffff)
11144 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11145 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11146 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11148 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11149 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11150 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11152 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11154 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
11155 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11156 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11157 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11159 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11160 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
11161 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11163 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11164 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11166 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11175 else if (i
>= -0x8000)
11177 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11179 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11181 s
= size_of_int_loc_descriptor (-i
) + 1;
11189 unsigned long r
= 1 + size_of_sleb128 (i
);
11190 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11192 s
= size_of_int_loc_descriptor (-i
) + 1;
11201 /* Return loc description representing "address" of integer value.
11202 This can appear only as toplevel expression. */
11204 static dw_loc_descr_ref
11205 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
11208 dw_loc_descr_ref loc_result
= NULL
;
11210 if (!(dwarf_version
>= 4 || !dwarf_strict
))
11213 litsize
= size_of_int_loc_descriptor (i
);
11214 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
11215 is more compact. For DW_OP_stack_value we need:
11216 litsize + 1 (DW_OP_stack_value)
11217 and for DW_OP_implicit_value:
11218 1 (DW_OP_implicit_value) + 1 (length) + size. */
11219 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
11221 loc_result
= int_loc_descriptor (i
);
11222 add_loc_descr (&loc_result
,
11223 new_loc_descr (DW_OP_stack_value
, 0, 0));
11227 loc_result
= new_loc_descr (DW_OP_implicit_value
,
11229 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
11230 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
11234 /* Return a location descriptor that designates a base+offset location. */
11236 static dw_loc_descr_ref
11237 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
11238 enum var_init_status initialized
)
11240 unsigned int regno
;
11241 dw_loc_descr_ref result
;
11242 dw_fde_ref fde
= cfun
->fde
;
11244 /* We only use "frame base" when we're sure we're talking about the
11245 post-prologue local stack frame. We do this by *not* running
11246 register elimination until this point, and recognizing the special
11247 argument pointer and soft frame pointer rtx's. */
11248 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
11250 rtx elim
= (ira_use_lra_p
11251 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
11252 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
11256 if (GET_CODE (elim
) == PLUS
)
11258 offset
+= INTVAL (XEXP (elim
, 1));
11259 elim
= XEXP (elim
, 0);
11261 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11262 && (elim
== hard_frame_pointer_rtx
11263 || elim
== stack_pointer_rtx
))
11264 || elim
== (frame_pointer_needed
11265 ? hard_frame_pointer_rtx
11266 : stack_pointer_rtx
));
11268 /* If drap register is used to align stack, use frame
11269 pointer + offset to access stack variables. If stack
11270 is aligned without drap, use stack pointer + offset to
11271 access stack variables. */
11272 if (crtl
->stack_realign_tried
11273 && reg
== frame_pointer_rtx
)
11276 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
11277 ? HARD_FRAME_POINTER_REGNUM
11279 return new_reg_loc_descr (base_reg
, offset
);
11282 gcc_assert (frame_pointer_fb_offset_valid
);
11283 offset
+= frame_pointer_fb_offset
;
11284 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11288 regno
= REGNO (reg
);
11289 #ifdef LEAF_REG_REMAP
11290 if (crtl
->uses_only_leaf_regs
)
11292 int leaf_reg
= LEAF_REG_REMAP (regno
);
11293 if (leaf_reg
!= -1)
11294 regno
= (unsigned) leaf_reg
;
11297 regno
= DWARF_FRAME_REGNUM (regno
);
11299 if (!optimize
&& fde
11300 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
11302 /* Use cfa+offset to represent the location of arguments passed
11303 on the stack when drap is used to align stack.
11304 Only do this when not optimizing, for optimized code var-tracking
11305 is supposed to track where the arguments live and the register
11306 used as vdrap or drap in some spot might be used for something
11307 else in other part of the routine. */
11308 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11312 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
11315 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
11317 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11318 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11323 /* Return true if this RTL expression describes a base+offset calculation. */
11326 is_based_loc (const_rtx rtl
)
11328 return (GET_CODE (rtl
) == PLUS
11329 && ((REG_P (XEXP (rtl
, 0))
11330 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
11331 && CONST_INT_P (XEXP (rtl
, 1)))));
11334 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11337 static dw_loc_descr_ref
11338 tls_mem_loc_descriptor (rtx mem
)
11341 dw_loc_descr_ref loc_result
;
11343 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
11346 base
= get_base_address (MEM_EXPR (mem
));
11348 || TREE_CODE (base
) != VAR_DECL
11349 || !DECL_THREAD_LOCAL_P (base
))
11352 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
11353 if (loc_result
== NULL
)
11356 if (MEM_OFFSET (mem
))
11357 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
11362 /* Output debug info about reason why we failed to expand expression as dwarf
11366 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
11368 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
11370 fprintf (dump_file
, "Failed to expand as dwarf: ");
11372 print_generic_expr (dump_file
, expr
, dump_flags
);
11375 fprintf (dump_file
, "\n");
11376 print_rtl (dump_file
, rtl
);
11378 fprintf (dump_file
, "\nReason: %s\n", reason
);
11382 /* Helper function for const_ok_for_output, called either directly
11383 or via for_each_rtx. */
11386 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
11390 if (GET_CODE (rtl
) == UNSPEC
)
11392 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11393 we can't express it in the debug info. */
11394 #ifdef ENABLE_CHECKING
11395 /* Don't complain about TLS UNSPECs, those are just too hard to
11396 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11397 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11398 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11399 if (XVECLEN (rtl
, 0) == 0
11400 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11401 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
11402 inform (current_function_decl
11403 ? DECL_SOURCE_LOCATION (current_function_decl
)
11404 : UNKNOWN_LOCATION
,
11405 #if NUM_UNSPEC_VALUES > 0
11406 "non-delegitimized UNSPEC %s (%d) found in variable location",
11407 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11408 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11411 "non-delegitimized UNSPEC %d found in variable location",
11415 expansion_failed (NULL_TREE
, rtl
,
11416 "UNSPEC hasn't been delegitimized.\n");
11420 if (targetm
.const_not_ok_for_debug_p (rtl
))
11422 expansion_failed (NULL_TREE
, rtl
,
11423 "Expression rejected for debug by the backend.\n");
11427 /* FIXME: Refer to PR60655. It is possible for simplification
11428 of rtl expressions in var tracking to produce such expressions.
11429 We should really identify / validate expressions
11430 enclosed in CONST that can be handled by assemblers on various
11431 targets and only handle legitimate cases here. */
11432 if (GET_CODE (rtl
) != SYMBOL_REF
)
11434 if (GET_CODE (rtl
) == NOT
)
11440 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11443 get_pool_constant_mark (rtl
, &marked
);
11444 /* If all references to this pool constant were optimized away,
11445 it was not output and thus we can't represent it. */
11448 expansion_failed (NULL_TREE
, rtl
,
11449 "Constant was removed from constant pool.\n");
11454 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11457 /* Avoid references to external symbols in debug info, on several targets
11458 the linker might even refuse to link when linking a shared library,
11459 and in many other cases the relocations for .debug_info/.debug_loc are
11460 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11461 to be defined within the same shared library or executable are fine. */
11462 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11464 tree decl
= SYMBOL_REF_DECL (rtl
);
11466 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11468 expansion_failed (NULL_TREE
, rtl
,
11469 "Symbol not defined in current TU.\n");
11477 /* Return true if constant RTL can be emitted in DW_OP_addr or
11478 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11479 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11482 const_ok_for_output (rtx rtl
)
11484 if (GET_CODE (rtl
) == SYMBOL_REF
)
11485 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
11487 if (GET_CODE (rtl
) == CONST
)
11488 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
11493 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11494 if possible, NULL otherwise. */
11497 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
11499 dw_die_ref type_die
;
11500 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11504 switch (TREE_CODE (type
))
11512 type_die
= lookup_type_die (type
);
11514 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
11515 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11520 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11521 type matching MODE, or, if MODE is narrower than or as wide as
11522 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11525 static dw_loc_descr_ref
11526 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
11528 enum machine_mode outer_mode
= mode
;
11529 dw_die_ref type_die
;
11530 dw_loc_descr_ref cvt
;
11532 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11534 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11537 type_die
= base_type_for_mode (outer_mode
, 1);
11538 if (type_die
== NULL
)
11540 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11541 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11542 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11543 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11544 add_loc_descr (&op
, cvt
);
11548 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11550 static dw_loc_descr_ref
11551 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11552 dw_loc_descr_ref op1
)
11554 dw_loc_descr_ref ret
= op0
;
11555 add_loc_descr (&ret
, op1
);
11556 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11557 if (STORE_FLAG_VALUE
!= 1)
11559 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11560 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11565 /* Return location descriptor for signed comparison OP RTL. */
11567 static dw_loc_descr_ref
11568 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11569 enum machine_mode mem_mode
)
11571 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11572 dw_loc_descr_ref op0
, op1
;
11575 if (op_mode
== VOIDmode
)
11576 op_mode
= GET_MODE (XEXP (rtl
, 1));
11577 if (op_mode
== VOIDmode
)
11581 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11582 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11585 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11586 VAR_INIT_STATUS_INITIALIZED
);
11587 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11588 VAR_INIT_STATUS_INITIALIZED
);
11590 if (op0
== NULL
|| op1
== NULL
)
11593 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11594 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11595 return compare_loc_descriptor (op
, op0
, op1
);
11597 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11599 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11600 dw_loc_descr_ref cvt
;
11602 if (type_die
== NULL
)
11604 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11605 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11606 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11607 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11608 add_loc_descr (&op0
, cvt
);
11609 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11610 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11611 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11612 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11613 add_loc_descr (&op1
, cvt
);
11614 return compare_loc_descriptor (op
, op0
, op1
);
11617 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11618 /* For eq/ne, if the operands are known to be zero-extended,
11619 there is no need to do the fancy shifting up. */
11620 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11622 dw_loc_descr_ref last0
, last1
;
11623 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11625 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11627 /* deref_size zero extends, and for constants we can check
11628 whether they are zero extended or not. */
11629 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11630 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11631 || (CONST_INT_P (XEXP (rtl
, 0))
11632 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11633 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11634 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11635 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11636 || (CONST_INT_P (XEXP (rtl
, 1))
11637 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11638 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11639 return compare_loc_descriptor (op
, op0
, op1
);
11641 /* EQ/NE comparison against constant in narrower type than
11642 DWARF2_ADDR_SIZE can be performed either as
11643 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11646 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11647 DW_OP_{eq,ne}. Pick whatever is shorter. */
11648 if (CONST_INT_P (XEXP (rtl
, 1))
11649 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11650 && (size_of_int_loc_descriptor (shift
) + 1
11651 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11652 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11653 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11654 & GET_MODE_MASK (op_mode
))))
11656 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11657 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11658 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11659 & GET_MODE_MASK (op_mode
));
11660 return compare_loc_descriptor (op
, op0
, op1
);
11663 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11664 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11665 if (CONST_INT_P (XEXP (rtl
, 1)))
11666 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11669 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11670 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11672 return compare_loc_descriptor (op
, op0
, op1
);
11675 /* Return location descriptor for unsigned comparison OP RTL. */
11677 static dw_loc_descr_ref
11678 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11679 enum machine_mode mem_mode
)
11681 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11682 dw_loc_descr_ref op0
, op1
;
11684 if (op_mode
== VOIDmode
)
11685 op_mode
= GET_MODE (XEXP (rtl
, 1));
11686 if (op_mode
== VOIDmode
)
11688 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
11691 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11694 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11695 VAR_INIT_STATUS_INITIALIZED
);
11696 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11697 VAR_INIT_STATUS_INITIALIZED
);
11699 if (op0
== NULL
|| op1
== NULL
)
11702 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
11704 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
11705 dw_loc_descr_ref last0
, last1
;
11706 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11708 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11710 if (CONST_INT_P (XEXP (rtl
, 0)))
11711 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
11712 /* deref_size zero extends, so no need to mask it again. */
11713 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
11714 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11716 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11717 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11719 if (CONST_INT_P (XEXP (rtl
, 1)))
11720 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
11721 /* deref_size zero extends, so no need to mask it again. */
11722 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
11723 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11725 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11726 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11729 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11731 HOST_WIDE_INT bias
= 1;
11732 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11733 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11734 if (CONST_INT_P (XEXP (rtl
, 1)))
11735 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
11736 + INTVAL (XEXP (rtl
, 1)));
11738 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
11741 return compare_loc_descriptor (op
, op0
, op1
);
11744 /* Return location descriptor for {U,S}{MIN,MAX}. */
11746 static dw_loc_descr_ref
11747 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11748 enum machine_mode mem_mode
)
11750 enum dwarf_location_atom op
;
11751 dw_loc_descr_ref op0
, op1
, ret
;
11752 dw_loc_descr_ref bra_node
, drop_node
;
11755 && (GET_MODE_CLASS (mode
) != MODE_INT
11756 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
11759 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11760 VAR_INIT_STATUS_INITIALIZED
);
11761 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11762 VAR_INIT_STATUS_INITIALIZED
);
11764 if (op0
== NULL
|| op1
== NULL
)
11767 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
11768 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
11769 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
11770 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
11772 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11774 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
11775 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11776 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11777 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11778 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11780 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11782 HOST_WIDE_INT bias
= 1;
11783 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11784 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11785 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11788 else if (GET_MODE_CLASS (mode
) == MODE_INT
11789 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11791 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11792 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11793 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11794 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11795 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11797 else if (GET_MODE_CLASS (mode
) == MODE_INT
11798 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11800 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11801 dw_loc_descr_ref cvt
;
11802 if (type_die
== NULL
)
11804 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11805 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11806 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11807 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11808 add_loc_descr (&op0
, cvt
);
11809 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11810 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11811 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11812 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11813 add_loc_descr (&op1
, cvt
);
11816 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11821 add_loc_descr (&ret
, op1
);
11822 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11823 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11824 add_loc_descr (&ret
, bra_node
);
11825 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11826 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11827 add_loc_descr (&ret
, drop_node
);
11828 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11829 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11830 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11831 && GET_MODE_CLASS (mode
) == MODE_INT
11832 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11833 ret
= convert_descriptor_to_mode (mode
, ret
);
11837 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11838 but after converting arguments to type_die, afterwards
11839 convert back to unsigned. */
11841 static dw_loc_descr_ref
11842 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11843 enum machine_mode mode
, enum machine_mode mem_mode
)
11845 dw_loc_descr_ref cvt
, op0
, op1
;
11847 if (type_die
== NULL
)
11849 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11850 VAR_INIT_STATUS_INITIALIZED
);
11851 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11852 VAR_INIT_STATUS_INITIALIZED
);
11853 if (op0
== NULL
|| op1
== NULL
)
11855 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11856 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11857 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11858 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11859 add_loc_descr (&op0
, cvt
);
11860 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11861 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11862 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11863 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11864 add_loc_descr (&op1
, cvt
);
11865 add_loc_descr (&op0
, op1
);
11866 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11867 return convert_descriptor_to_mode (mode
, op0
);
11870 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11871 const0 is DW_OP_lit0 or corresponding typed constant,
11872 const1 is DW_OP_lit1 or corresponding typed constant
11873 and constMSB is constant with just the MSB bit set
11875 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11876 L1: const0 DW_OP_swap
11877 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11878 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11883 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11884 L1: const0 DW_OP_swap
11885 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11886 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11891 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11892 L1: const1 DW_OP_swap
11893 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11894 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11898 static dw_loc_descr_ref
11899 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11900 enum machine_mode mem_mode
)
11902 dw_loc_descr_ref op0
, ret
, tmp
;
11903 HOST_WIDE_INT valv
;
11904 dw_loc_descr_ref l1jump
, l1label
;
11905 dw_loc_descr_ref l2jump
, l2label
;
11906 dw_loc_descr_ref l3jump
, l3label
;
11907 dw_loc_descr_ref l4jump
, l4label
;
11910 if (GET_MODE_CLASS (mode
) != MODE_INT
11911 || GET_MODE (XEXP (rtl
, 0)) != mode
)
11914 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11915 VAR_INIT_STATUS_INITIALIZED
);
11919 if (GET_CODE (rtl
) == CLZ
)
11921 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11922 valv
= GET_MODE_BITSIZE (mode
);
11924 else if (GET_CODE (rtl
) == FFS
)
11926 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11927 valv
= GET_MODE_BITSIZE (mode
);
11928 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11929 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11930 add_loc_descr (&ret
, l1jump
);
11931 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11932 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
11933 VAR_INIT_STATUS_INITIALIZED
);
11936 add_loc_descr (&ret
, tmp
);
11937 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11938 add_loc_descr (&ret
, l4jump
);
11939 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
11940 ? const1_rtx
: const0_rtx
,
11942 VAR_INIT_STATUS_INITIALIZED
);
11943 if (l1label
== NULL
)
11945 add_loc_descr (&ret
, l1label
);
11946 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11947 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
11948 add_loc_descr (&ret
, l2label
);
11949 if (GET_CODE (rtl
) != CLZ
)
11951 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11952 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
11953 << (GET_MODE_BITSIZE (mode
) - 1));
11955 msb
= immed_wide_int_const
11956 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
11957 GET_MODE_PRECISION (mode
)), mode
);
11958 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
11959 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11960 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
11961 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
11963 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
11964 VAR_INIT_STATUS_INITIALIZED
);
11967 add_loc_descr (&ret
, tmp
);
11968 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11969 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11970 add_loc_descr (&ret
, l3jump
);
11971 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11972 VAR_INIT_STATUS_INITIALIZED
);
11975 add_loc_descr (&ret
, tmp
);
11976 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
11977 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
11978 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11979 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
11980 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11981 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11982 add_loc_descr (&ret
, l2jump
);
11983 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
11984 add_loc_descr (&ret
, l3label
);
11985 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
11986 add_loc_descr (&ret
, l4label
);
11987 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11988 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11989 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11990 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11991 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11992 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
11993 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11994 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
11998 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11999 const1 is DW_OP_lit1 or corresponding typed constant):
12001 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12002 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12006 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12007 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12010 static dw_loc_descr_ref
12011 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12012 enum machine_mode mem_mode
)
12014 dw_loc_descr_ref op0
, ret
, tmp
;
12015 dw_loc_descr_ref l1jump
, l1label
;
12016 dw_loc_descr_ref l2jump
, l2label
;
12018 if (GET_MODE_CLASS (mode
) != MODE_INT
12019 || GET_MODE (XEXP (rtl
, 0)) != mode
)
12022 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12023 VAR_INIT_STATUS_INITIALIZED
);
12027 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12028 VAR_INIT_STATUS_INITIALIZED
);
12031 add_loc_descr (&ret
, tmp
);
12032 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12033 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
12034 add_loc_descr (&ret
, l1label
);
12035 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12036 add_loc_descr (&ret
, l2jump
);
12037 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12038 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12039 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12040 VAR_INIT_STATUS_INITIALIZED
);
12043 add_loc_descr (&ret
, tmp
);
12044 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12045 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
12046 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
12047 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12048 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12049 VAR_INIT_STATUS_INITIALIZED
);
12050 add_loc_descr (&ret
, tmp
);
12051 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12052 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12053 add_loc_descr (&ret
, l1jump
);
12054 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12055 add_loc_descr (&ret
, l2label
);
12056 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12057 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12058 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12059 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12063 /* BSWAP (constS is initial shift count, either 56 or 24):
12065 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
12066 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
12067 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
12068 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
12069 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
12071 static dw_loc_descr_ref
12072 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12073 enum machine_mode mem_mode
)
12075 dw_loc_descr_ref op0
, ret
, tmp
;
12076 dw_loc_descr_ref l1jump
, l1label
;
12077 dw_loc_descr_ref l2jump
, l2label
;
12079 if (GET_MODE_CLASS (mode
) != MODE_INT
12080 || BITS_PER_UNIT
!= 8
12081 || (GET_MODE_BITSIZE (mode
) != 32
12082 && GET_MODE_BITSIZE (mode
) != 64))
12085 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12086 VAR_INIT_STATUS_INITIALIZED
);
12091 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
12093 VAR_INIT_STATUS_INITIALIZED
);
12096 add_loc_descr (&ret
, tmp
);
12097 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12098 VAR_INIT_STATUS_INITIALIZED
);
12101 add_loc_descr (&ret
, tmp
);
12102 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
12103 add_loc_descr (&ret
, l1label
);
12104 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
12106 VAR_INIT_STATUS_INITIALIZED
);
12107 add_loc_descr (&ret
, tmp
);
12108 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
12109 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12110 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12111 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
12112 VAR_INIT_STATUS_INITIALIZED
);
12115 add_loc_descr (&ret
, tmp
);
12116 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12117 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
12118 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12119 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12120 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12121 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12122 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12123 VAR_INIT_STATUS_INITIALIZED
);
12124 add_loc_descr (&ret
, tmp
);
12125 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
12126 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12127 add_loc_descr (&ret
, l2jump
);
12128 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
12129 VAR_INIT_STATUS_INITIALIZED
);
12130 add_loc_descr (&ret
, tmp
);
12131 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12132 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12133 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12134 add_loc_descr (&ret
, l1jump
);
12135 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12136 add_loc_descr (&ret
, l2label
);
12137 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12138 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12139 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12140 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12141 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12142 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12146 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
12147 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12148 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
12149 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
12151 ROTATERT is similar:
12152 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
12153 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12154 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
12156 static dw_loc_descr_ref
12157 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12158 enum machine_mode mem_mode
)
12160 rtx rtlop1
= XEXP (rtl
, 1);
12161 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
12164 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12167 if (GET_MODE (rtlop1
) != VOIDmode
12168 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
12169 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12170 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12171 VAR_INIT_STATUS_INITIALIZED
);
12172 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12173 VAR_INIT_STATUS_INITIALIZED
);
12174 if (op0
== NULL
|| op1
== NULL
)
12176 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12177 for (i
= 0; i
< 2; i
++)
12179 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
12180 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
12182 VAR_INIT_STATUS_INITIALIZED
);
12183 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12184 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12186 : HOST_BITS_PER_WIDE_INT
== 64
12187 ? DW_OP_const8u
: DW_OP_constu
,
12188 GET_MODE_MASK (mode
), 0);
12191 if (mask
[i
] == NULL
)
12193 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
12196 add_loc_descr (&ret
, op1
);
12197 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12198 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12199 if (GET_CODE (rtl
) == ROTATERT
)
12201 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12202 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12203 GET_MODE_BITSIZE (mode
), 0));
12205 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12206 if (mask
[0] != NULL
)
12207 add_loc_descr (&ret
, mask
[0]);
12208 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12209 if (mask
[1] != NULL
)
12211 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12212 add_loc_descr (&ret
, mask
[1]);
12213 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12215 if (GET_CODE (rtl
) == ROTATE
)
12217 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12218 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12219 GET_MODE_BITSIZE (mode
), 0));
12221 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12222 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12226 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
12227 for DEBUG_PARAMETER_REF RTL. */
12229 static dw_loc_descr_ref
12230 parameter_ref_descriptor (rtx rtl
)
12232 dw_loc_descr_ref ret
;
12237 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
12238 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
12239 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
12242 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12243 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12244 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12248 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12249 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
12254 /* The following routine converts the RTL for a variable or parameter
12255 (resident in memory) into an equivalent Dwarf representation of a
12256 mechanism for getting the address of that same variable onto the top of a
12257 hypothetical "address evaluation" stack.
12259 When creating memory location descriptors, we are effectively transforming
12260 the RTL for a memory-resident object into its Dwarf postfix expression
12261 equivalent. This routine recursively descends an RTL tree, turning
12262 it into Dwarf postfix code as it goes.
12264 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
12266 MEM_MODE is the mode of the memory reference, needed to handle some
12267 autoincrement addressing modes.
12269 Return 0 if we can't represent the location. */
12272 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12273 enum machine_mode mem_mode
,
12274 enum var_init_status initialized
)
12276 dw_loc_descr_ref mem_loc_result
= NULL
;
12277 enum dwarf_location_atom op
;
12278 dw_loc_descr_ref op0
, op1
;
12279 rtx inner
= NULL_RTX
;
12281 if (mode
== VOIDmode
)
12282 mode
= GET_MODE (rtl
);
12284 /* Note that for a dynamically sized array, the location we will generate a
12285 description of here will be the lowest numbered location which is
12286 actually within the array. That's *not* necessarily the same as the
12287 zeroth element of the array. */
12289 rtl
= targetm
.delegitimize_address (rtl
);
12291 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
12294 switch (GET_CODE (rtl
))
12299 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
12302 /* The case of a subreg may arise when we have a local (register)
12303 variable or a formal (register) parameter which doesn't quite fill
12304 up an entire register. For now, just assume that it is
12305 legitimate to make the Dwarf info refer to the whole register which
12306 contains the given subreg. */
12307 if (!subreg_lowpart_p (rtl
))
12309 inner
= SUBREG_REG (rtl
);
12311 if (inner
== NULL_RTX
)
12312 inner
= XEXP (rtl
, 0);
12313 if (GET_MODE_CLASS (mode
) == MODE_INT
12314 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
12315 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12316 #ifdef POINTERS_EXTEND_UNSIGNED
12317 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
12320 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
12322 mem_loc_result
= mem_loc_descriptor (inner
,
12324 mem_mode
, initialized
);
12329 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
12331 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
12332 && (GET_MODE_CLASS (mode
) != MODE_INT
12333 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
12337 dw_die_ref type_die
;
12338 dw_loc_descr_ref cvt
;
12340 mem_loc_result
= mem_loc_descriptor (inner
,
12342 mem_mode
, initialized
);
12343 if (mem_loc_result
== NULL
)
12345 type_die
= base_type_for_mode (mode
,
12346 GET_MODE_CLASS (mode
) == MODE_INT
);
12347 if (type_die
== NULL
)
12349 mem_loc_result
= NULL
;
12352 if (GET_MODE_SIZE (mode
)
12353 != GET_MODE_SIZE (GET_MODE (inner
)))
12354 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12356 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
12357 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12358 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12359 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12360 add_loc_descr (&mem_loc_result
, cvt
);
12365 if (GET_MODE_CLASS (mode
) != MODE_INT
12366 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12367 && rtl
!= arg_pointer_rtx
12368 && rtl
!= frame_pointer_rtx
12369 #ifdef POINTERS_EXTEND_UNSIGNED
12370 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12374 dw_die_ref type_die
;
12375 unsigned int dbx_regnum
;
12379 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
12381 type_die
= base_type_for_mode (mode
,
12382 GET_MODE_CLASS (mode
) == MODE_INT
);
12383 if (type_die
== NULL
)
12386 dbx_regnum
= dbx_reg_number (rtl
);
12387 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12389 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
12391 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12392 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12393 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12396 /* Whenever a register number forms a part of the description of the
12397 method for calculating the (dynamic) address of a memory resident
12398 object, DWARF rules require the register number be referred to as
12399 a "base register". This distinction is not based in any way upon
12400 what category of register the hardware believes the given register
12401 belongs to. This is strictly DWARF terminology we're dealing with
12402 here. Note that in cases where the location of a memory-resident
12403 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12404 OP_CONST (0)) the actual DWARF location descriptor that we generate
12405 may just be OP_BASEREG (basereg). This may look deceptively like
12406 the object in question was allocated to a register (rather than in
12407 memory) so DWARF consumers need to be aware of the subtle
12408 distinction between OP_REG and OP_BASEREG. */
12409 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12410 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12411 else if (stack_realign_drap
12413 && crtl
->args
.internal_arg_pointer
== rtl
12414 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12416 /* If RTL is internal_arg_pointer, which has been optimized
12417 out, use DRAP instead. */
12418 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12419 VAR_INIT_STATUS_INITIALIZED
);
12425 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12427 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12428 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12431 else if (GET_CODE (rtl
) == ZERO_EXTEND
12432 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12433 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12434 < HOST_BITS_PER_WIDE_INT
12435 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12436 to expand zero extend as two shifts instead of
12438 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12440 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12441 mem_loc_result
= op0
;
12442 add_loc_descr (&mem_loc_result
,
12443 int_loc_descriptor (GET_MODE_MASK (imode
)));
12444 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12446 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12448 int shift
= DWARF2_ADDR_SIZE
12449 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12450 shift
*= BITS_PER_UNIT
;
12451 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12455 mem_loc_result
= op0
;
12456 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12457 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12458 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12459 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12461 else if (!dwarf_strict
)
12463 dw_die_ref type_die1
, type_die2
;
12464 dw_loc_descr_ref cvt
;
12466 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12467 GET_CODE (rtl
) == ZERO_EXTEND
);
12468 if (type_die1
== NULL
)
12470 type_die2
= base_type_for_mode (mode
, 1);
12471 if (type_die2
== NULL
)
12473 mem_loc_result
= op0
;
12474 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12475 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12476 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12477 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12478 add_loc_descr (&mem_loc_result
, cvt
);
12479 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12480 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12481 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12482 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12483 add_loc_descr (&mem_loc_result
, cvt
);
12489 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12490 if (new_rtl
!= rtl
)
12492 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12494 if (mem_loc_result
!= NULL
)
12495 return mem_loc_result
;
12498 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12499 get_address_mode (rtl
), mode
,
12500 VAR_INIT_STATUS_INITIALIZED
);
12501 if (mem_loc_result
== NULL
)
12502 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12503 if (mem_loc_result
!= NULL
)
12505 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12506 || GET_MODE_CLASS (mode
) != MODE_INT
)
12508 dw_die_ref type_die
;
12509 dw_loc_descr_ref deref
;
12514 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12515 if (type_die
== NULL
)
12517 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12518 GET_MODE_SIZE (mode
), 0);
12519 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12520 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12521 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12522 add_loc_descr (&mem_loc_result
, deref
);
12524 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12525 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12527 add_loc_descr (&mem_loc_result
,
12528 new_loc_descr (DW_OP_deref_size
,
12529 GET_MODE_SIZE (mode
), 0));
12534 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12537 /* Some ports can transform a symbol ref into a label ref, because
12538 the symbol ref is too far away and has to be dumped into a constant
12542 if (GET_MODE_CLASS (mode
) != MODE_INT
12543 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12544 #ifdef POINTERS_EXTEND_UNSIGNED
12545 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12549 if (GET_CODE (rtl
) == SYMBOL_REF
12550 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12552 dw_loc_descr_ref temp
;
12554 /* If this is not defined, we have no way to emit the data. */
12555 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12558 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12560 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12561 add_loc_descr (&mem_loc_result
, temp
);
12566 if (!const_ok_for_output (rtl
))
12570 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12571 vec_safe_push (used_rtx_array
, rtl
);
12577 case DEBUG_IMPLICIT_PTR
:
12578 expansion_failed (NULL_TREE
, rtl
,
12579 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12585 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12587 if (GET_MODE_CLASS (mode
) != MODE_INT
12588 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12589 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12590 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12593 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12594 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12596 op0
= one_reg_loc_descriptor (dbx_regnum
,
12597 VAR_INIT_STATUS_INITIALIZED
);
12600 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12601 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12603 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12604 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12605 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12609 gcc_unreachable ();
12612 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12613 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12614 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12617 case DEBUG_PARAMETER_REF
:
12618 mem_loc_result
= parameter_ref_descriptor (rtl
);
12622 /* Extract the PLUS expression nested inside and fall into
12623 PLUS code below. */
12624 rtl
= XEXP (rtl
, 1);
12629 /* Turn these into a PLUS expression and fall into the PLUS code
12631 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12632 gen_int_mode (GET_CODE (rtl
) == PRE_INC
12633 ? GET_MODE_UNIT_SIZE (mem_mode
)
12634 : -GET_MODE_UNIT_SIZE (mem_mode
),
12637 /* ... fall through ... */
12641 if (is_based_loc (rtl
)
12642 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12643 || XEXP (rtl
, 0) == arg_pointer_rtx
12644 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12645 && GET_MODE_CLASS (mode
) == MODE_INT
)
12646 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12647 INTVAL (XEXP (rtl
, 1)),
12648 VAR_INIT_STATUS_INITIALIZED
);
12651 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12652 VAR_INIT_STATUS_INITIALIZED
);
12653 if (mem_loc_result
== 0)
12656 if (CONST_INT_P (XEXP (rtl
, 1))
12657 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12658 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12661 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12662 VAR_INIT_STATUS_INITIALIZED
);
12665 add_loc_descr (&mem_loc_result
, op1
);
12666 add_loc_descr (&mem_loc_result
,
12667 new_loc_descr (DW_OP_plus
, 0, 0));
12672 /* If a pseudo-reg is optimized away, it is possible for it to
12673 be replaced with a MEM containing a multiply or shift. */
12684 && GET_MODE_CLASS (mode
) == MODE_INT
12685 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12687 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12688 base_type_for_mode (mode
, 0),
12712 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12714 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12715 VAR_INIT_STATUS_INITIALIZED
);
12717 rtx rtlop1
= XEXP (rtl
, 1);
12718 if (GET_MODE (rtlop1
) != VOIDmode
12719 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
12720 < GET_MODE_BITSIZE (mode
))
12721 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12722 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12723 VAR_INIT_STATUS_INITIALIZED
);
12726 if (op0
== 0 || op1
== 0)
12729 mem_loc_result
= op0
;
12730 add_loc_descr (&mem_loc_result
, op1
);
12731 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12747 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12748 VAR_INIT_STATUS_INITIALIZED
);
12749 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12750 VAR_INIT_STATUS_INITIALIZED
);
12752 if (op0
== 0 || op1
== 0)
12755 mem_loc_result
= op0
;
12756 add_loc_descr (&mem_loc_result
, op1
);
12757 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12761 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
12763 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
12764 base_type_for_mode (mode
, 0),
12769 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12770 VAR_INIT_STATUS_INITIALIZED
);
12771 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12772 VAR_INIT_STATUS_INITIALIZED
);
12774 if (op0
== 0 || op1
== 0)
12777 mem_loc_result
= op0
;
12778 add_loc_descr (&mem_loc_result
, op1
);
12779 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12780 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12781 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
12782 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
12783 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12787 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12789 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12794 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12795 base_type_for_mode (mode
, 1),
12813 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12814 VAR_INIT_STATUS_INITIALIZED
);
12819 mem_loc_result
= op0
;
12820 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12824 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12825 #ifdef POINTERS_EXTEND_UNSIGNED
12827 && mem_mode
!= VOIDmode
12828 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12832 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12836 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12837 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
12839 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12840 enum machine_mode amode
;
12841 if (type_die
== NULL
)
12843 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12845 if (INTVAL (rtl
) >= 0
12846 && amode
!= BLKmode
12847 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12848 /* const DW_OP_GNU_convert <XXX> vs.
12849 DW_OP_GNU_const_type <XXX, 1, const>. */
12850 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12851 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12853 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12854 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12855 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12856 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12857 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12858 add_loc_descr (&mem_loc_result
, op0
);
12859 return mem_loc_result
;
12861 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12863 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12864 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12865 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12866 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12867 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12870 mem_loc_result
->dw_loc_oprnd2
.val_class
12871 = dw_val_class_const_double
;
12872 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12873 = double_int::from_shwi (INTVAL (rtl
));
12881 dw_die_ref type_die
;
12883 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
12884 CONST_DOUBLE rtx could represent either a large integer
12885 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
12886 the value is always a floating point constant.
12888 When it is an integer, a CONST_DOUBLE is used whenever
12889 the constant requires 2 HWIs to be adequately represented.
12890 We output CONST_DOUBLEs as blocks. */
12891 if (mode
== VOIDmode
12892 || (GET_MODE (rtl
) == VOIDmode
12893 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
12895 type_die
= base_type_for_mode (mode
,
12896 GET_MODE_CLASS (mode
) == MODE_INT
);
12897 if (type_die
== NULL
)
12899 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12900 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12901 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12902 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12903 #if TARGET_SUPPORTS_WIDE_INT == 0
12904 if (!SCALAR_FLOAT_MODE_P (mode
))
12906 mem_loc_result
->dw_loc_oprnd2
.val_class
12907 = dw_val_class_const_double
;
12908 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12909 = rtx_to_double_int (rtl
);
12914 unsigned int length
= GET_MODE_SIZE (mode
);
12915 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
12917 insert_float (rtl
, array
);
12918 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12919 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12920 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12921 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12926 case CONST_WIDE_INT
:
12929 dw_die_ref type_die
;
12931 type_die
= base_type_for_mode (mode
,
12932 GET_MODE_CLASS (mode
) == MODE_INT
);
12933 if (type_die
== NULL
)
12935 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12936 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12937 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12938 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12939 mem_loc_result
->dw_loc_oprnd2
.val_class
12940 = dw_val_class_wide_int
;
12941 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_cleared_alloc
<wide_int
> ();
12942 *mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
12947 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
12951 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12955 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12959 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12963 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12967 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
12971 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12975 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12979 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12983 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12988 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12993 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
12998 if (CONST_INT_P (XEXP (rtl
, 1))
12999 && CONST_INT_P (XEXP (rtl
, 2))
13000 && ((unsigned) INTVAL (XEXP (rtl
, 1))
13001 + (unsigned) INTVAL (XEXP (rtl
, 2))
13002 <= GET_MODE_BITSIZE (mode
))
13003 && GET_MODE_CLASS (mode
) == MODE_INT
13004 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13005 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
13008 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13009 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13012 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
13016 mem_loc_result
= op0
;
13017 size
= INTVAL (XEXP (rtl
, 1));
13018 shift
= INTVAL (XEXP (rtl
, 2));
13019 if (BITS_BIG_ENDIAN
)
13020 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
13022 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
13024 add_loc_descr (&mem_loc_result
,
13025 int_loc_descriptor (DWARF2_ADDR_SIZE
13027 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
13029 if (size
!= (int) DWARF2_ADDR_SIZE
)
13031 add_loc_descr (&mem_loc_result
,
13032 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
13033 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13040 dw_loc_descr_ref op2
, bra_node
, drop_node
;
13041 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
13042 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
13043 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
13044 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13045 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13046 VAR_INIT_STATUS_INITIALIZED
);
13047 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
13048 VAR_INIT_STATUS_INITIALIZED
);
13049 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
13052 mem_loc_result
= op1
;
13053 add_loc_descr (&mem_loc_result
, op2
);
13054 add_loc_descr (&mem_loc_result
, op0
);
13055 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13056 add_loc_descr (&mem_loc_result
, bra_node
);
13057 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
13058 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
13059 add_loc_descr (&mem_loc_result
, drop_node
);
13060 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13061 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
13066 case FLOAT_TRUNCATE
:
13068 case UNSIGNED_FLOAT
:
13073 dw_die_ref type_die
;
13074 dw_loc_descr_ref cvt
;
13076 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13077 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13080 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
13081 && (GET_CODE (rtl
) == FLOAT
13082 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
13083 <= DWARF2_ADDR_SIZE
))
13085 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
13086 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
13087 if (type_die
== NULL
)
13089 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13090 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13091 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13092 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13093 add_loc_descr (&op0
, cvt
);
13095 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
13096 if (type_die
== NULL
)
13098 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13099 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13100 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13101 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13102 add_loc_descr (&op0
, cvt
);
13103 if (GET_MODE_CLASS (mode
) == MODE_INT
13104 && (GET_CODE (rtl
) == FIX
13105 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
13107 op0
= convert_descriptor_to_mode (mode
, op0
);
13111 mem_loc_result
= op0
;
13118 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
13123 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
13127 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
13132 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
13136 /* In theory, we could implement the above. */
13137 /* DWARF cannot represent the unsigned compare operations
13162 case FRACT_CONVERT
:
13163 case UNSIGNED_FRACT_CONVERT
:
13165 case UNSIGNED_SAT_FRACT
:
13171 case VEC_DUPLICATE
:
13175 case STRICT_LOW_PART
:
13180 /* If delegitimize_address couldn't do anything with the UNSPEC, we
13181 can't express it in the debug info. This can happen e.g. with some
13186 resolve_one_addr (&rtl
, NULL
);
13190 #ifdef ENABLE_CHECKING
13191 print_rtl (stderr
, rtl
);
13192 gcc_unreachable ();
13198 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13199 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13201 return mem_loc_result
;
13204 /* Return a descriptor that describes the concatenation of two locations.
13205 This is typically a complex variable. */
13207 static dw_loc_descr_ref
13208 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
13210 dw_loc_descr_ref cc_loc_result
= NULL
;
13211 dw_loc_descr_ref x0_ref
13212 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13213 dw_loc_descr_ref x1_ref
13214 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13216 if (x0_ref
== 0 || x1_ref
== 0)
13219 cc_loc_result
= x0_ref
;
13220 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
13222 add_loc_descr (&cc_loc_result
, x1_ref
);
13223 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
13225 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13226 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13228 return cc_loc_result
;
13231 /* Return a descriptor that describes the concatenation of N
13234 static dw_loc_descr_ref
13235 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
13238 dw_loc_descr_ref cc_loc_result
= NULL
;
13239 unsigned int n
= XVECLEN (concatn
, 0);
13241 for (i
= 0; i
< n
; ++i
)
13243 dw_loc_descr_ref ref
;
13244 rtx x
= XVECEXP (concatn
, 0, i
);
13246 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13250 add_loc_descr (&cc_loc_result
, ref
);
13251 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
13254 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13255 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13257 return cc_loc_result
;
13260 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
13261 for DEBUG_IMPLICIT_PTR RTL. */
13263 static dw_loc_descr_ref
13264 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
13266 dw_loc_descr_ref ret
;
13271 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
13272 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
13273 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
13274 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
13275 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
13276 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13279 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13280 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
13281 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13285 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
13286 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
13291 /* Output a proper Dwarf location descriptor for a variable or parameter
13292 which is either allocated in a register or in a memory location. For a
13293 register, we just generate an OP_REG and the register number. For a
13294 memory location we provide a Dwarf postfix expression describing how to
13295 generate the (dynamic) address of the object onto the address stack.
13297 MODE is mode of the decl if this loc_descriptor is going to be used in
13298 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
13299 allowed, VOIDmode otherwise.
13301 If we don't know how to describe it, return 0. */
13303 static dw_loc_descr_ref
13304 loc_descriptor (rtx rtl
, enum machine_mode mode
,
13305 enum var_init_status initialized
)
13307 dw_loc_descr_ref loc_result
= NULL
;
13309 switch (GET_CODE (rtl
))
13312 /* The case of a subreg may arise when we have a local (register)
13313 variable or a formal (register) parameter which doesn't quite fill
13314 up an entire register. For now, just assume that it is
13315 legitimate to make the Dwarf info refer to the whole register which
13316 contains the given subreg. */
13317 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
13318 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
13319 GET_MODE (SUBREG_REG (rtl
)), initialized
);
13325 loc_result
= reg_loc_descriptor (rtl
, initialized
);
13329 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13330 GET_MODE (rtl
), initialized
);
13331 if (loc_result
== NULL
)
13332 loc_result
= tls_mem_loc_descriptor (rtl
);
13333 if (loc_result
== NULL
)
13335 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13336 if (new_rtl
!= rtl
)
13337 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
13342 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
13347 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
13352 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
13354 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
13355 if (GET_CODE (loc
) == EXPR_LIST
)
13356 loc
= XEXP (loc
, 0);
13357 loc_result
= loc_descriptor (loc
, mode
, initialized
);
13361 rtl
= XEXP (rtl
, 1);
13366 rtvec par_elems
= XVEC (rtl
, 0);
13367 int num_elem
= GET_NUM_ELEM (par_elems
);
13368 enum machine_mode mode
;
13371 /* Create the first one, so we have something to add to. */
13372 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
13373 VOIDmode
, initialized
);
13374 if (loc_result
== NULL
)
13376 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
13377 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13378 for (i
= 1; i
< num_elem
; i
++)
13380 dw_loc_descr_ref temp
;
13382 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
13383 VOIDmode
, initialized
);
13386 add_loc_descr (&loc_result
, temp
);
13387 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
13388 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13394 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
13395 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
13400 if (mode
== VOIDmode
)
13401 mode
= GET_MODE (rtl
);
13403 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13405 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13407 /* Note that a CONST_DOUBLE rtx could represent either an integer
13408 or a floating-point constant. A CONST_DOUBLE is used whenever
13409 the constant requires more than one word in order to be
13410 adequately represented. We output CONST_DOUBLEs as blocks. */
13411 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13412 GET_MODE_SIZE (mode
), 0);
13413 #if TARGET_SUPPORTS_WIDE_INT == 0
13414 if (!SCALAR_FLOAT_MODE_P (mode
))
13416 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
13417 loc_result
->dw_loc_oprnd2
.v
.val_double
13418 = rtx_to_double_int (rtl
);
13423 unsigned int length
= GET_MODE_SIZE (mode
);
13424 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
13426 insert_float (rtl
, array
);
13427 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13428 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13429 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13430 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13435 case CONST_WIDE_INT
:
13436 if (mode
== VOIDmode
)
13437 mode
= GET_MODE (rtl
);
13439 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13441 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13442 GET_MODE_SIZE (mode
), 0);
13443 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
13444 loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_cleared_alloc
<wide_int
> ();
13445 *loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
13450 if (mode
== VOIDmode
)
13451 mode
= GET_MODE (rtl
);
13453 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13455 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13456 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13457 unsigned char *array
13458 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
13461 enum machine_mode imode
= GET_MODE_INNER (mode
);
13463 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13464 switch (GET_MODE_CLASS (mode
))
13466 case MODE_VECTOR_INT
:
13467 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13469 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13470 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
13474 case MODE_VECTOR_FLOAT
:
13475 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13477 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13478 insert_float (elt
, p
);
13483 gcc_unreachable ();
13486 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13487 length
* elt_size
, 0);
13488 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13489 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13490 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13491 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13496 if (mode
== VOIDmode
13497 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13498 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13499 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13501 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13506 if (!const_ok_for_output (rtl
))
13509 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13510 && (dwarf_version
>= 4 || !dwarf_strict
))
13512 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13513 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13514 vec_safe_push (used_rtx_array
, rtl
);
13518 case DEBUG_IMPLICIT_PTR
:
13519 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13523 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13524 && CONST_INT_P (XEXP (rtl
, 1)))
13527 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13533 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13534 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13535 && dwarf_version
>= 4)
13536 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13538 /* Value expression. */
13539 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13541 add_loc_descr (&loc_result
,
13542 new_loc_descr (DW_OP_stack_value
, 0, 0));
13550 /* We need to figure out what section we should use as the base for the
13551 address ranges where a given location is valid.
13552 1. If this particular DECL has a section associated with it, use that.
13553 2. If this function has a section associated with it, use that.
13554 3. Otherwise, use the text section.
13555 XXX: If you split a variable across multiple sections, we won't notice. */
13557 static const char *
13558 secname_for_decl (const_tree decl
)
13560 const char *secname
;
13562 if (VAR_OR_FUNCTION_DECL_P (decl
)
13563 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
) || TREE_STATIC (decl
))
13564 && DECL_SECTION_NAME (decl
))
13565 secname
= DECL_SECTION_NAME (decl
);
13566 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13567 secname
= DECL_SECTION_NAME (current_function_decl
);
13568 else if (cfun
&& in_cold_section_p
)
13569 secname
= crtl
->subsections
.cold_section_label
;
13571 secname
= text_section_label
;
13576 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13579 decl_by_reference_p (tree decl
)
13581 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13582 || TREE_CODE (decl
) == VAR_DECL
)
13583 && DECL_BY_REFERENCE (decl
));
13586 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13589 static dw_loc_descr_ref
13590 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13591 enum var_init_status initialized
)
13593 int have_address
= 0;
13594 dw_loc_descr_ref descr
;
13595 enum machine_mode mode
;
13597 if (want_address
!= 2)
13599 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13601 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13603 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13604 if (GET_CODE (varloc
) == EXPR_LIST
)
13605 varloc
= XEXP (varloc
, 0);
13606 mode
= GET_MODE (varloc
);
13607 if (MEM_P (varloc
))
13609 rtx addr
= XEXP (varloc
, 0);
13610 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13611 mode
, initialized
);
13616 rtx x
= avoid_constant_pool_reference (varloc
);
13618 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13623 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13630 if (GET_CODE (varloc
) == VAR_LOCATION
)
13631 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13633 mode
= DECL_MODE (loc
);
13634 descr
= loc_descriptor (varloc
, mode
, initialized
);
13641 if (want_address
== 2 && !have_address
13642 && (dwarf_version
>= 4 || !dwarf_strict
))
13644 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13646 expansion_failed (loc
, NULL_RTX
,
13647 "DWARF address size mismatch");
13650 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13653 /* Show if we can't fill the request for an address. */
13654 if (want_address
&& !have_address
)
13656 expansion_failed (loc
, NULL_RTX
,
13657 "Want address and only have value");
13661 /* If we've got an address and don't want one, dereference. */
13662 if (!want_address
&& have_address
)
13664 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13665 enum dwarf_location_atom op
;
13667 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13669 expansion_failed (loc
, NULL_RTX
,
13670 "DWARF address size mismatch");
13673 else if (size
== DWARF2_ADDR_SIZE
)
13676 op
= DW_OP_deref_size
;
13678 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
13684 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13685 if it is not possible. */
13687 static dw_loc_descr_ref
13688 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
13690 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
13691 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
13692 else if (dwarf_version
>= 3 || !dwarf_strict
)
13693 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
13698 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13699 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13701 static dw_loc_descr_ref
13702 dw_sra_loc_expr (tree decl
, rtx loc
)
13705 unsigned int padsize
= 0;
13706 dw_loc_descr_ref descr
, *descr_tail
;
13707 unsigned HOST_WIDE_INT decl_size
;
13709 enum var_init_status initialized
;
13711 if (DECL_SIZE (decl
) == NULL
13712 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
13715 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
13717 descr_tail
= &descr
;
13719 for (p
= loc
; p
; p
= XEXP (p
, 1))
13721 unsigned int bitsize
= decl_piece_bitsize (p
);
13722 rtx loc_note
= *decl_piece_varloc_ptr (p
);
13723 dw_loc_descr_ref cur_descr
;
13724 dw_loc_descr_ref
*tail
, last
= NULL
;
13725 unsigned int opsize
= 0;
13727 if (loc_note
== NULL_RTX
13728 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
13730 padsize
+= bitsize
;
13733 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
13734 varloc
= NOTE_VAR_LOCATION (loc_note
);
13735 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
13736 if (cur_descr
== NULL
)
13738 padsize
+= bitsize
;
13742 /* Check that cur_descr either doesn't use
13743 DW_OP_*piece operations, or their sum is equal
13744 to bitsize. Otherwise we can't embed it. */
13745 for (tail
= &cur_descr
; *tail
!= NULL
;
13746 tail
= &(*tail
)->dw_loc_next
)
13747 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
13749 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
13753 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
13755 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
13759 if (last
!= NULL
&& opsize
!= bitsize
)
13761 padsize
+= bitsize
;
13762 /* Discard the current piece of the descriptor and release any
13763 addr_table entries it uses. */
13764 remove_loc_list_addr_table_entries (cur_descr
);
13768 /* If there is a hole, add DW_OP_*piece after empty DWARF
13769 expression, which means that those bits are optimized out. */
13772 if (padsize
> decl_size
)
13774 remove_loc_list_addr_table_entries (cur_descr
);
13775 goto discard_descr
;
13777 decl_size
-= padsize
;
13778 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
13779 if (*descr_tail
== NULL
)
13781 remove_loc_list_addr_table_entries (cur_descr
);
13782 goto discard_descr
;
13784 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13787 *descr_tail
= cur_descr
;
13789 if (bitsize
> decl_size
)
13790 goto discard_descr
;
13791 decl_size
-= bitsize
;
13794 HOST_WIDE_INT offset
= 0;
13795 if (GET_CODE (varloc
) == VAR_LOCATION
13796 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13798 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13799 if (GET_CODE (varloc
) == EXPR_LIST
)
13800 varloc
= XEXP (varloc
, 0);
13804 if (GET_CODE (varloc
) == CONST
13805 || GET_CODE (varloc
) == SIGN_EXTEND
13806 || GET_CODE (varloc
) == ZERO_EXTEND
)
13807 varloc
= XEXP (varloc
, 0);
13808 else if (GET_CODE (varloc
) == SUBREG
)
13809 varloc
= SUBREG_REG (varloc
);
13814 /* DW_OP_bit_size offset should be zero for register
13815 or implicit location descriptions and empty location
13816 descriptions, but for memory addresses needs big endian
13818 if (MEM_P (varloc
))
13820 unsigned HOST_WIDE_INT memsize
13821 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13822 if (memsize
!= bitsize
)
13824 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13825 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13826 goto discard_descr
;
13827 if (memsize
< bitsize
)
13828 goto discard_descr
;
13829 if (BITS_BIG_ENDIAN
)
13830 offset
= memsize
- bitsize
;
13834 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13835 if (*descr_tail
== NULL
)
13836 goto discard_descr
;
13837 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13841 /* If there were any non-empty expressions, add padding till the end of
13843 if (descr
!= NULL
&& decl_size
!= 0)
13845 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13846 if (*descr_tail
== NULL
)
13847 goto discard_descr
;
13852 /* Discard the descriptor and release any addr_table entries it uses. */
13853 remove_loc_list_addr_table_entries (descr
);
13857 /* Return the dwarf representation of the location list LOC_LIST of
13858 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13861 static dw_loc_list_ref
13862 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13864 const char *endname
, *secname
;
13866 enum var_init_status initialized
;
13867 struct var_loc_node
*node
;
13868 dw_loc_descr_ref descr
;
13869 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13870 dw_loc_list_ref list
= NULL
;
13871 dw_loc_list_ref
*listp
= &list
;
13873 /* Now that we know what section we are using for a base,
13874 actually construct the list of locations.
13875 The first location information is what is passed to the
13876 function that creates the location list, and the remaining
13877 locations just get added on to that list.
13878 Note that we only know the start address for a location
13879 (IE location changes), so to build the range, we use
13880 the range [current location start, next location start].
13881 This means we have to special case the last node, and generate
13882 a range of [last location start, end of function label]. */
13884 secname
= secname_for_decl (decl
);
13886 for (node
= loc_list
->first
; node
; node
= node
->next
)
13887 if (GET_CODE (node
->loc
) == EXPR_LIST
13888 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13890 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13892 /* This requires DW_OP_{,bit_}piece, which is not usable
13893 inside DWARF expressions. */
13894 if (want_address
!= 2)
13896 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13902 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13903 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13904 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
13908 bool range_across_switch
= false;
13909 /* If section switch happens in between node->label
13910 and node->next->label (or end of function) and
13911 we can't emit it as a single entry list,
13912 emit two ranges, first one ending at the end
13913 of first partition and second one starting at the
13914 beginning of second partition. */
13915 if (node
== loc_list
->last_before_switch
13916 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
13917 && current_function_decl
)
13919 endname
= cfun
->fde
->dw_fde_end
;
13920 range_across_switch
= true;
13922 /* The variable has a location between NODE->LABEL and
13923 NODE->NEXT->LABEL. */
13924 else if (node
->next
)
13925 endname
= node
->next
->label
;
13926 /* If the variable has a location at the last label
13927 it keeps its location until the end of function. */
13928 else if (!current_function_decl
)
13929 endname
= text_end_label
;
13932 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13933 current_function_funcdef_no
);
13934 endname
= ggc_strdup (label_id
);
13937 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
13938 if (TREE_CODE (decl
) == PARM_DECL
13939 && node
== loc_list
->first
13940 && NOTE_P (node
->loc
)
13941 && strcmp (node
->label
, endname
) == 0)
13942 (*listp
)->force
= true;
13943 listp
= &(*listp
)->dw_loc_next
;
13945 if (range_across_switch
)
13947 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13948 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13951 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13952 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13953 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
13956 gcc_assert (descr
);
13957 /* The variable has a location between NODE->LABEL and
13958 NODE->NEXT->LABEL. */
13960 endname
= node
->next
->label
;
13962 endname
= cfun
->fde
->dw_fde_second_end
;
13963 *listp
= new_loc_list (descr
,
13964 cfun
->fde
->dw_fde_second_begin
,
13966 listp
= &(*listp
)->dw_loc_next
;
13971 /* Try to avoid the overhead of a location list emitting a location
13972 expression instead, but only if we didn't have more than one
13973 location entry in the first place. If some entries were not
13974 representable, we don't want to pretend a single entry that was
13975 applies to the entire scope in which the variable is
13977 if (list
&& loc_list
->first
->next
)
13983 /* Return if the loc_list has only single element and thus can be represented
13984 as location description. */
13987 single_element_loc_list_p (dw_loc_list_ref list
)
13989 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
13990 return !list
->ll_symbol
;
13993 /* To each location in list LIST add loc descr REF. */
13996 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
13998 dw_loc_descr_ref copy
;
13999 add_loc_descr (&list
->expr
, ref
);
14000 list
= list
->dw_loc_next
;
14003 copy
= ggc_alloc
<dw_loc_descr_node
> ();
14004 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
14005 add_loc_descr (&list
->expr
, copy
);
14006 while (copy
->dw_loc_next
)
14008 dw_loc_descr_ref new_copy
= ggc_alloc
<dw_loc_descr_node
> ();
14009 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
14010 copy
->dw_loc_next
= new_copy
;
14013 list
= list
->dw_loc_next
;
14017 /* Given two lists RET and LIST
14018 produce location list that is result of adding expression in LIST
14019 to expression in RET on each position in program.
14020 Might be destructive on both RET and LIST.
14022 TODO: We handle only simple cases of RET or LIST having at most one
14023 element. General case would inolve sorting the lists in program order
14024 and merging them that will need some additional work.
14025 Adding that will improve quality of debug info especially for SRA-ed
14029 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
14038 if (!list
->dw_loc_next
)
14040 add_loc_descr_to_each (*ret
, list
->expr
);
14043 if (!(*ret
)->dw_loc_next
)
14045 add_loc_descr_to_each (list
, (*ret
)->expr
);
14049 expansion_failed (NULL_TREE
, NULL_RTX
,
14050 "Don't know how to merge two non-trivial"
14051 " location lists.\n");
14056 /* LOC is constant expression. Try a luck, look it up in constant
14057 pool and return its loc_descr of its address. */
14059 static dw_loc_descr_ref
14060 cst_pool_loc_descr (tree loc
)
14062 /* Get an RTL for this, if something has been emitted. */
14063 rtx rtl
= lookup_constant_def (loc
);
14065 if (!rtl
|| !MEM_P (rtl
))
14070 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
14072 /* TODO: We might get more coverage if we was actually delaying expansion
14073 of all expressions till end of compilation when constant pools are fully
14075 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
14077 expansion_failed (loc
, NULL_RTX
,
14078 "CST value in contant pool but not marked.");
14081 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
14082 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
14085 /* Return dw_loc_list representing address of addr_expr LOC
14086 by looking for inner INDIRECT_REF expression and turning
14087 it into simple arithmetics. */
14089 static dw_loc_list_ref
14090 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
14093 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14094 enum machine_mode mode
;
14095 int unsignedp
, volatilep
= 0;
14096 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14098 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
14099 &bitsize
, &bitpos
, &offset
, &mode
,
14100 &unsignedp
, &volatilep
, false);
14102 if (bitpos
% BITS_PER_UNIT
)
14104 expansion_failed (loc
, NULL_RTX
, "bitfield access");
14107 if (!INDIRECT_REF_P (obj
))
14109 expansion_failed (obj
,
14110 NULL_RTX
, "no indirect ref in inner refrence");
14113 if (!offset
&& !bitpos
)
14114 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
14116 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
14117 && (dwarf_version
>= 4 || !dwarf_strict
))
14119 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
14124 /* Variable offset. */
14125 list_ret1
= loc_list_from_tree (offset
, 0);
14126 if (list_ret1
== 0)
14128 add_loc_list (&list_ret
, list_ret1
);
14131 add_loc_descr_to_each (list_ret
,
14132 new_loc_descr (DW_OP_plus
, 0, 0));
14134 bytepos
= bitpos
/ BITS_PER_UNIT
;
14136 add_loc_descr_to_each (list_ret
,
14137 new_loc_descr (DW_OP_plus_uconst
,
14139 else if (bytepos
< 0)
14140 loc_list_plus_const (list_ret
, bytepos
);
14141 add_loc_descr_to_each (list_ret
,
14142 new_loc_descr (DW_OP_stack_value
, 0, 0));
14148 /* Generate Dwarf location list representing LOC.
14149 If WANT_ADDRESS is false, expression computing LOC will be computed
14150 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
14151 if WANT_ADDRESS is 2, expression computing address useable in location
14152 will be returned (i.e. DW_OP_reg can be used
14153 to refer to register values). */
14155 static dw_loc_list_ref
14156 loc_list_from_tree (tree loc
, int want_address
)
14158 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
14159 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14160 int have_address
= 0;
14161 enum dwarf_location_atom op
;
14163 /* ??? Most of the time we do not take proper care for sign/zero
14164 extending the values properly. Hopefully this won't be a real
14167 switch (TREE_CODE (loc
))
14170 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
14173 case PLACEHOLDER_EXPR
:
14174 /* This case involves extracting fields from an object to determine the
14175 position of other fields. We don't try to encode this here. The
14176 only user of this is Ada, which encodes the needed information using
14177 the names of types. */
14178 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
14182 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
14183 /* There are no opcodes for these operations. */
14186 case PREINCREMENT_EXPR
:
14187 case PREDECREMENT_EXPR
:
14188 case POSTINCREMENT_EXPR
:
14189 case POSTDECREMENT_EXPR
:
14190 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
14191 /* There are no opcodes for these operations. */
14195 /* If we already want an address, see if there is INDIRECT_REF inside
14196 e.g. for &this->field. */
14199 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
14200 (loc
, want_address
== 2);
14203 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
14204 && (ret
= cst_pool_loc_descr (loc
)))
14207 /* Otherwise, process the argument and look for the address. */
14208 if (!list_ret
&& !ret
)
14209 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
14213 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
14219 if (DECL_THREAD_LOCAL_P (loc
))
14222 enum dwarf_location_atom tls_op
;
14223 enum dtprel_bool dtprel
= dtprel_false
;
14225 if (targetm
.have_tls
)
14227 /* If this is not defined, we have no way to emit the
14229 if (!targetm
.asm_out
.output_dwarf_dtprel
)
14232 /* The way DW_OP_GNU_push_tls_address is specified, we
14233 can only look up addresses of objects in the current
14234 module. We used DW_OP_addr as first op, but that's
14235 wrong, because DW_OP_addr is relocated by the debug
14236 info consumer, while DW_OP_GNU_push_tls_address
14237 operand shouldn't be. */
14238 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
14240 dtprel
= dtprel_true
;
14241 tls_op
= DW_OP_GNU_push_tls_address
;
14245 if (!targetm
.emutls
.debug_form_tls_address
14246 || !(dwarf_version
>= 3 || !dwarf_strict
))
14248 /* We stuffed the control variable into the DECL_VALUE_EXPR
14249 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
14250 no longer appear in gimple code. We used the control
14251 variable in specific so that we could pick it up here. */
14252 loc
= DECL_VALUE_EXPR (loc
);
14253 tls_op
= DW_OP_form_tls_address
;
14256 rtl
= rtl_for_decl_location (loc
);
14257 if (rtl
== NULL_RTX
)
14262 rtl
= XEXP (rtl
, 0);
14263 if (! CONSTANT_P (rtl
))
14266 ret
= new_addr_loc_descr (rtl
, dtprel
);
14267 ret1
= new_loc_descr (tls_op
, 0, 0);
14268 add_loc_descr (&ret
, ret1
);
14277 if (DECL_HAS_VALUE_EXPR_P (loc
))
14278 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
14282 case FUNCTION_DECL
:
14285 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
14287 if (loc_list
&& loc_list
->first
)
14289 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
14290 have_address
= want_address
!= 0;
14293 rtl
= rtl_for_decl_location (loc
);
14294 if (rtl
== NULL_RTX
)
14296 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
14299 else if (CONST_INT_P (rtl
))
14301 HOST_WIDE_INT val
= INTVAL (rtl
);
14302 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14303 val
&= GET_MODE_MASK (DECL_MODE (loc
));
14304 ret
= int_loc_descriptor (val
);
14306 else if (GET_CODE (rtl
) == CONST_STRING
)
14308 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
14311 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
14312 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
14315 enum machine_mode mode
, mem_mode
;
14317 /* Certain constructs can only be represented at top-level. */
14318 if (want_address
== 2)
14320 ret
= loc_descriptor (rtl
, VOIDmode
,
14321 VAR_INIT_STATUS_INITIALIZED
);
14326 mode
= GET_MODE (rtl
);
14327 mem_mode
= VOIDmode
;
14331 mode
= get_address_mode (rtl
);
14332 rtl
= XEXP (rtl
, 0);
14335 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
14336 VAR_INIT_STATUS_INITIALIZED
);
14339 expansion_failed (loc
, rtl
,
14340 "failed to produce loc descriptor for rtl");
14347 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
14351 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14355 case COMPOUND_EXPR
:
14356 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
14359 case VIEW_CONVERT_EXPR
:
14362 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
14364 case COMPONENT_REF
:
14365 case BIT_FIELD_REF
:
14367 case ARRAY_RANGE_REF
:
14368 case REALPART_EXPR
:
14369 case IMAGPART_EXPR
:
14372 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14373 enum machine_mode mode
;
14374 int unsignedp
, volatilep
= 0;
14376 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
14377 &unsignedp
, &volatilep
, false);
14379 gcc_assert (obj
!= loc
);
14381 list_ret
= loc_list_from_tree (obj
,
14383 && !bitpos
&& !offset
? 2 : 1);
14384 /* TODO: We can extract value of the small expression via shifting even
14385 for nonzero bitpos. */
14388 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
14390 expansion_failed (loc
, NULL_RTX
,
14391 "bitfield access");
14395 if (offset
!= NULL_TREE
)
14397 /* Variable offset. */
14398 list_ret1
= loc_list_from_tree (offset
, 0);
14399 if (list_ret1
== 0)
14401 add_loc_list (&list_ret
, list_ret1
);
14404 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14407 bytepos
= bitpos
/ BITS_PER_UNIT
;
14409 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
14410 else if (bytepos
< 0)
14411 loc_list_plus_const (list_ret
, bytepos
);
14418 if ((want_address
|| !tree_fits_shwi_p (loc
))
14419 && (ret
= cst_pool_loc_descr (loc
)))
14421 else if (want_address
== 2
14422 && tree_fits_shwi_p (loc
)
14423 && (ret
= address_of_int_loc_descriptor
14424 (int_size_in_bytes (TREE_TYPE (loc
)),
14425 tree_to_shwi (loc
))))
14427 else if (tree_fits_shwi_p (loc
))
14428 ret
= int_loc_descriptor (tree_to_shwi (loc
));
14431 expansion_failed (loc
, NULL_RTX
,
14432 "Integer operand is not host integer");
14441 if ((ret
= cst_pool_loc_descr (loc
)))
14444 /* We can construct small constants here using int_loc_descriptor. */
14445 expansion_failed (loc
, NULL_RTX
,
14446 "constructor or constant not in constant pool");
14449 case TRUTH_AND_EXPR
:
14450 case TRUTH_ANDIF_EXPR
:
14455 case TRUTH_XOR_EXPR
:
14460 case TRUTH_OR_EXPR
:
14461 case TRUTH_ORIF_EXPR
:
14466 case FLOOR_DIV_EXPR
:
14467 case CEIL_DIV_EXPR
:
14468 case ROUND_DIV_EXPR
:
14469 case TRUNC_DIV_EXPR
:
14470 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14479 case FLOOR_MOD_EXPR
:
14480 case CEIL_MOD_EXPR
:
14481 case ROUND_MOD_EXPR
:
14482 case TRUNC_MOD_EXPR
:
14483 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14488 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14489 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14490 if (list_ret
== 0 || list_ret1
== 0)
14493 add_loc_list (&list_ret
, list_ret1
);
14496 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14497 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14498 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14499 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14500 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14512 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14515 case POINTER_PLUS_EXPR
:
14517 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
14519 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14523 loc_list_plus_const (list_ret
, tree_to_shwi (TREE_OPERAND (loc
, 1)));
14531 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14538 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14545 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14552 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14567 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14568 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14569 if (list_ret
== 0 || list_ret1
== 0)
14572 add_loc_list (&list_ret
, list_ret1
);
14575 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14578 case TRUTH_NOT_EXPR
:
14592 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14596 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14602 const enum tree_code code
=
14603 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14605 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14606 build2 (code
, integer_type_node
,
14607 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14608 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14611 /* ... fall through ... */
14615 dw_loc_descr_ref lhs
14616 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
14617 dw_loc_list_ref rhs
14618 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
14619 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
14621 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14622 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
14625 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14626 add_loc_descr_to_each (list_ret
, bra_node
);
14628 add_loc_list (&list_ret
, rhs
);
14629 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14630 add_loc_descr_to_each (list_ret
, jump_node
);
14632 add_loc_descr_to_each (list_ret
, lhs
);
14633 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14634 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
14636 /* ??? Need a node to point the skip at. Use a nop. */
14637 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14638 add_loc_descr_to_each (list_ret
, tmp
);
14639 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14640 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14644 case FIX_TRUNC_EXPR
:
14648 /* Leave front-end specific codes as simply unknown. This comes
14649 up, for instance, with the C STMT_EXPR. */
14650 if ((unsigned int) TREE_CODE (loc
)
14651 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
14653 expansion_failed (loc
, NULL_RTX
,
14654 "language specific tree node");
14658 #ifdef ENABLE_CHECKING
14659 /* Otherwise this is a generic code; we should just lists all of
14660 these explicitly. We forgot one. */
14661 gcc_unreachable ();
14663 /* In a release build, we want to degrade gracefully: better to
14664 generate incomplete debugging information than to crash. */
14669 if (!ret
&& !list_ret
)
14672 if (want_address
== 2 && !have_address
14673 && (dwarf_version
>= 4 || !dwarf_strict
))
14675 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14677 expansion_failed (loc
, NULL_RTX
,
14678 "DWARF address size mismatch");
14682 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14684 add_loc_descr_to_each (list_ret
,
14685 new_loc_descr (DW_OP_stack_value
, 0, 0));
14688 /* Show if we can't fill the request for an address. */
14689 if (want_address
&& !have_address
)
14691 expansion_failed (loc
, NULL_RTX
,
14692 "Want address and only have value");
14696 gcc_assert (!ret
|| !list_ret
);
14698 /* If we've got an address and don't want one, dereference. */
14699 if (!want_address
&& have_address
)
14701 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14703 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14705 expansion_failed (loc
, NULL_RTX
,
14706 "DWARF address size mismatch");
14709 else if (size
== DWARF2_ADDR_SIZE
)
14712 op
= DW_OP_deref_size
;
14715 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
14717 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
14720 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
14725 /* Same as above but return only single location expression. */
14726 static dw_loc_descr_ref
14727 loc_descriptor_from_tree (tree loc
, int want_address
)
14729 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
14732 if (ret
->dw_loc_next
)
14734 expansion_failed (loc
, NULL_RTX
,
14735 "Location list where only loc descriptor needed");
14741 /* Given a value, round it up to the lowest multiple of `boundary'
14742 which is not less than the value itself. */
14744 static inline HOST_WIDE_INT
14745 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
14747 return (((value
+ boundary
- 1) / boundary
) * boundary
);
14750 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14751 pointer to the declared type for the relevant field variable, or return
14752 `integer_type_node' if the given node turns out to be an
14753 ERROR_MARK node. */
14756 field_type (const_tree decl
)
14760 if (TREE_CODE (decl
) == ERROR_MARK
)
14761 return integer_type_node
;
14763 type
= DECL_BIT_FIELD_TYPE (decl
);
14764 if (type
== NULL_TREE
)
14765 type
= TREE_TYPE (decl
);
14770 /* Given a pointer to a tree node, return the alignment in bits for
14771 it, or else return BITS_PER_WORD if the node actually turns out to
14772 be an ERROR_MARK node. */
14774 static inline unsigned
14775 simple_type_align_in_bits (const_tree type
)
14777 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
14780 static inline unsigned
14781 simple_decl_align_in_bits (const_tree decl
)
14783 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
14786 /* Return the result of rounding T up to ALIGN. */
14788 static inline offset_int
14789 round_up_to_align (const offset_int
&t
, unsigned int align
)
14791 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
14794 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14795 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14796 or return 0 if we are unable to determine what that offset is, either
14797 because the argument turns out to be a pointer to an ERROR_MARK node, or
14798 because the offset is actually variable. (We can't handle the latter case
14801 static HOST_WIDE_INT
14802 field_byte_offset (const_tree decl
)
14804 offset_int object_offset_in_bits
;
14805 offset_int object_offset_in_bytes
;
14806 offset_int bitpos_int
;
14808 if (TREE_CODE (decl
) == ERROR_MARK
)
14811 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14813 /* We cannot yet cope with fields whose positions are variable, so
14814 for now, when we see such things, we simply return 0. Someday, we may
14815 be able to handle such cases, but it will be damn difficult. */
14816 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14819 bitpos_int
= wi::to_offset (bit_position (decl
));
14821 #ifdef PCC_BITFIELD_TYPE_MATTERS
14822 if (PCC_BITFIELD_TYPE_MATTERS
)
14825 tree field_size_tree
;
14826 offset_int deepest_bitpos
;
14827 offset_int field_size_in_bits
;
14828 unsigned int type_align_in_bits
;
14829 unsigned int decl_align_in_bits
;
14830 offset_int type_size_in_bits
;
14832 type
= field_type (decl
);
14833 type_size_in_bits
= offset_int_type_size_in_bits (type
);
14834 type_align_in_bits
= simple_type_align_in_bits (type
);
14836 field_size_tree
= DECL_SIZE (decl
);
14838 /* The size could be unspecified if there was an error, or for
14839 a flexible array member. */
14840 if (!field_size_tree
)
14841 field_size_tree
= bitsize_zero_node
;
14843 /* If the size of the field is not constant, use the type size. */
14844 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14845 field_size_in_bits
= wi::to_offset (field_size_tree
);
14847 field_size_in_bits
= type_size_in_bits
;
14849 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14851 /* The GCC front-end doesn't make any attempt to keep track of the
14852 starting bit offset (relative to the start of the containing
14853 structure type) of the hypothetical "containing object" for a
14854 bit-field. Thus, when computing the byte offset value for the
14855 start of the "containing object" of a bit-field, we must deduce
14856 this information on our own. This can be rather tricky to do in
14857 some cases. For example, handling the following structure type
14858 definition when compiling for an i386/i486 target (which only
14859 aligns long long's to 32-bit boundaries) can be very tricky:
14861 struct S { int field1; long long field2:31; };
14863 Fortunately, there is a simple rule-of-thumb which can be used
14864 in such cases. When compiling for an i386/i486, GCC will
14865 allocate 8 bytes for the structure shown above. It decides to
14866 do this based upon one simple rule for bit-field allocation.
14867 GCC allocates each "containing object" for each bit-field at
14868 the first (i.e. lowest addressed) legitimate alignment boundary
14869 (based upon the required minimum alignment for the declared
14870 type of the field) which it can possibly use, subject to the
14871 condition that there is still enough available space remaining
14872 in the containing object (when allocated at the selected point)
14873 to fully accommodate all of the bits of the bit-field itself.
14875 This simple rule makes it obvious why GCC allocates 8 bytes for
14876 each object of the structure type shown above. When looking
14877 for a place to allocate the "containing object" for `field2',
14878 the compiler simply tries to allocate a 64-bit "containing
14879 object" at each successive 32-bit boundary (starting at zero)
14880 until it finds a place to allocate that 64- bit field such that
14881 at least 31 contiguous (and previously unallocated) bits remain
14882 within that selected 64 bit field. (As it turns out, for the
14883 example above, the compiler finds it is OK to allocate the
14884 "containing object" 64-bit field at bit-offset zero within the
14887 Here we attempt to work backwards from the limited set of facts
14888 we're given, and we try to deduce from those facts, where GCC
14889 must have believed that the containing object started (within
14890 the structure type). The value we deduce is then used (by the
14891 callers of this routine) to generate DW_AT_location and
14892 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14893 the case of DW_AT_location, regular fields as well). */
14895 /* Figure out the bit-distance from the start of the structure to
14896 the "deepest" bit of the bit-field. */
14897 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
14899 /* This is the tricky part. Use some fancy footwork to deduce
14900 where the lowest addressed bit of the containing object must
14902 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14904 /* Round up to type_align by default. This works best for
14906 object_offset_in_bits
14907 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
14909 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
14911 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14913 /* Round up to decl_align instead. */
14914 object_offset_in_bits
14915 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
14919 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14920 object_offset_in_bits
= bitpos_int
;
14922 object_offset_in_bytes
14923 = wi::lrshift (object_offset_in_bits
, LOG2_BITS_PER_UNIT
);
14924 return object_offset_in_bytes
.to_shwi ();
14927 /* The following routines define various Dwarf attributes and any data
14928 associated with them. */
14930 /* Add a location description attribute value to a DIE.
14932 This emits location attributes suitable for whole variables and
14933 whole parameters. Note that the location attributes for struct fields are
14934 generated by the routine `data_member_location_attribute' below. */
14937 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
14938 dw_loc_list_ref descr
)
14942 if (single_element_loc_list_p (descr
))
14943 add_AT_loc (die
, attr_kind
, descr
->expr
);
14945 add_AT_loc_list (die
, attr_kind
, descr
);
14948 /* Add DW_AT_accessibility attribute to DIE if needed. */
14951 add_accessibility_attribute (dw_die_ref die
, tree decl
)
14953 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14954 children, otherwise the default is DW_ACCESS_public. In DWARF2
14955 the default has always been DW_ACCESS_public. */
14956 if (TREE_PROTECTED (decl
))
14957 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14958 else if (TREE_PRIVATE (decl
))
14960 if (dwarf_version
== 2
14961 || die
->die_parent
== NULL
14962 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
14963 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
14965 else if (dwarf_version
> 2
14967 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
14968 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14971 /* Attach the specialized form of location attribute used for data members of
14972 struct and union types. In the special case of a FIELD_DECL node which
14973 represents a bit-field, the "offset" part of this special location
14974 descriptor must indicate the distance in bytes from the lowest-addressed
14975 byte of the containing struct or union type to the lowest-addressed byte of
14976 the "containing object" for the bit-field. (See the `field_byte_offset'
14979 For any given bit-field, the "containing object" is a hypothetical object
14980 (of some integral or enum type) within which the given bit-field lives. The
14981 type of this hypothetical "containing object" is always the same as the
14982 declared type of the individual bit-field itself (for GCC anyway... the
14983 DWARF spec doesn't actually mandate this). Note that it is the size (in
14984 bytes) of the hypothetical "containing object" which will be given in the
14985 DW_AT_byte_size attribute for this bit-field. (See the
14986 `byte_size_attribute' function below.) It is also used when calculating the
14987 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14988 function below.) */
14991 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
14993 HOST_WIDE_INT offset
;
14994 dw_loc_descr_ref loc_descr
= 0;
14996 if (TREE_CODE (decl
) == TREE_BINFO
)
14998 /* We're working on the TAG_inheritance for a base class. */
14999 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
15001 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
15002 aren't at a fixed offset from all (sub)objects of the same
15003 type. We need to extract the appropriate offset from our
15004 vtable. The following dwarf expression means
15006 BaseAddr = ObAddr + *((*ObAddr) - Offset)
15008 This is specific to the V3 ABI, of course. */
15010 dw_loc_descr_ref tmp
;
15012 /* Make a copy of the object address. */
15013 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
15014 add_loc_descr (&loc_descr
, tmp
);
15016 /* Extract the vtable address. */
15017 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
15018 add_loc_descr (&loc_descr
, tmp
);
15020 /* Calculate the address of the offset. */
15021 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
15022 gcc_assert (offset
< 0);
15024 tmp
= int_loc_descriptor (-offset
);
15025 add_loc_descr (&loc_descr
, tmp
);
15026 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
15027 add_loc_descr (&loc_descr
, tmp
);
15029 /* Extract the offset. */
15030 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
15031 add_loc_descr (&loc_descr
, tmp
);
15033 /* Add it to the object address. */
15034 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
15035 add_loc_descr (&loc_descr
, tmp
);
15038 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
15041 offset
= field_byte_offset (decl
);
15045 if (dwarf_version
> 2)
15047 /* Don't need to output a location expression, just the constant. */
15049 add_AT_int (die
, DW_AT_data_member_location
, offset
);
15051 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
15056 enum dwarf_location_atom op
;
15058 /* The DWARF2 standard says that we should assume that the structure
15059 address is already on the stack, so we can specify a structure
15060 field address by using DW_OP_plus_uconst. */
15061 op
= DW_OP_plus_uconst
;
15062 loc_descr
= new_loc_descr (op
, offset
, 0);
15066 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
15069 /* Writes integer values to dw_vec_const array. */
15072 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
15076 *dest
++ = val
& 0xff;
15082 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
15084 static HOST_WIDE_INT
15085 extract_int (const unsigned char *src
, unsigned int size
)
15087 HOST_WIDE_INT val
= 0;
15093 val
|= *--src
& 0xff;
15099 /* Writes wide_int values to dw_vec_const array. */
15102 insert_wide_int (const wide_int
&val
, unsigned char *dest
, int elt_size
)
15106 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
15108 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
15112 /* We'd have to extend this code to support odd sizes. */
15113 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
) == 0);
15115 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
15117 if (WORDS_BIG_ENDIAN
)
15118 for (i
= n
- 1; i
>= 0; i
--)
15120 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
15121 dest
+= sizeof (HOST_WIDE_INT
);
15124 for (i
= 0; i
< n
; i
++)
15126 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
15127 dest
+= sizeof (HOST_WIDE_INT
);
15131 /* Writes floating point values to dw_vec_const array. */
15134 insert_float (const_rtx rtl
, unsigned char *array
)
15136 REAL_VALUE_TYPE rv
;
15140 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
15141 real_to_target (val
, &rv
, GET_MODE (rtl
));
15143 /* real_to_target puts 32-bit pieces in each long. Pack them. */
15144 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
15146 insert_int (val
[i
], 4, array
);
15151 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
15152 does not have a "location" either in memory or in a register. These
15153 things can arise in GNU C when a constant is passed as an actual parameter
15154 to an inlined function. They can also arise in C++ where declared
15155 constants do not necessarily get memory "homes". */
15158 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
15160 switch (GET_CODE (rtl
))
15164 HOST_WIDE_INT val
= INTVAL (rtl
);
15167 add_AT_int (die
, DW_AT_const_value
, val
);
15169 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
15173 case CONST_WIDE_INT
:
15174 add_AT_wide (die
, DW_AT_const_value
,
15175 std::make_pair (rtl
, GET_MODE (rtl
)));
15179 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
15180 floating-point constant. A CONST_DOUBLE is used whenever the
15181 constant requires more than one word in order to be adequately
15184 enum machine_mode mode
= GET_MODE (rtl
);
15186 if (TARGET_SUPPORTS_WIDE_INT
== 0 && !SCALAR_FLOAT_MODE_P (mode
))
15187 add_AT_double (die
, DW_AT_const_value
,
15188 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
15191 unsigned int length
= GET_MODE_SIZE (mode
);
15192 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15194 insert_float (rtl
, array
);
15195 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
15202 enum machine_mode mode
= GET_MODE (rtl
);
15203 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
15204 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15205 unsigned char *array
15206 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
15209 enum machine_mode imode
= GET_MODE_INNER (mode
);
15211 switch (GET_MODE_CLASS (mode
))
15213 case MODE_VECTOR_INT
:
15214 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15216 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15217 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
15221 case MODE_VECTOR_FLOAT
:
15222 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15224 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15225 insert_float (elt
, p
);
15230 gcc_unreachable ();
15233 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
15238 if (dwarf_version
>= 4 || !dwarf_strict
)
15240 dw_loc_descr_ref loc_result
;
15241 resolve_one_addr (&rtl
, NULL
);
15243 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15244 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15245 add_AT_loc (die
, DW_AT_location
, loc_result
);
15246 vec_safe_push (used_rtx_array
, rtl
);
15252 if (CONSTANT_P (XEXP (rtl
, 0)))
15253 return add_const_value_attribute (die
, XEXP (rtl
, 0));
15256 if (!const_ok_for_output (rtl
))
15259 if (dwarf_version
>= 4 || !dwarf_strict
)
15264 /* In cases where an inlined instance of an inline function is passed
15265 the address of an `auto' variable (which is local to the caller) we
15266 can get a situation where the DECL_RTL of the artificial local
15267 variable (for the inlining) which acts as a stand-in for the
15268 corresponding formal parameter (of the inline function) will look
15269 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
15270 exactly a compile-time constant expression, but it isn't the address
15271 of the (artificial) local variable either. Rather, it represents the
15272 *value* which the artificial local variable always has during its
15273 lifetime. We currently have no way to represent such quasi-constant
15274 values in Dwarf, so for now we just punt and generate nothing. */
15282 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
15283 && MEM_READONLY_P (rtl
)
15284 && GET_MODE (rtl
) == BLKmode
)
15286 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
15292 /* No other kinds of rtx should be possible here. */
15293 gcc_unreachable ();
15298 /* Determine whether the evaluation of EXPR references any variables
15299 or functions which aren't otherwise used (and therefore may not be
15302 reference_to_unused (tree
* tp
, int * walk_subtrees
,
15303 void * data ATTRIBUTE_UNUSED
)
15305 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
15306 *walk_subtrees
= 0;
15308 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
15309 && ! TREE_ASM_WRITTEN (*tp
))
15311 /* ??? The C++ FE emits debug information for using decls, so
15312 putting gcc_unreachable here falls over. See PR31899. For now
15313 be conservative. */
15314 else if (!cgraph_global_info_ready
15315 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
15317 else if (TREE_CODE (*tp
) == VAR_DECL
)
15319 varpool_node
*node
= varpool_node::get (*tp
);
15320 if (!node
|| !node
->definition
)
15323 else if (TREE_CODE (*tp
) == FUNCTION_DECL
15324 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
15326 /* The call graph machinery must have finished analyzing,
15327 optimizing and gimplifying the CU by now.
15328 So if *TP has no call graph node associated
15329 to it, it means *TP will not be emitted. */
15330 if (!cgraph_node::get (*tp
))
15333 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
15339 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
15340 for use in a later add_const_value_attribute call. */
15343 rtl_for_decl_init (tree init
, tree type
)
15345 rtx rtl
= NULL_RTX
;
15349 /* If a variable is initialized with a string constant without embedded
15350 zeros, build CONST_STRING. */
15351 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
15353 tree enttype
= TREE_TYPE (type
);
15354 tree domain
= TYPE_DOMAIN (type
);
15355 enum machine_mode mode
= TYPE_MODE (enttype
);
15357 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
15359 && integer_zerop (TYPE_MIN_VALUE (domain
))
15360 && compare_tree_int (TYPE_MAX_VALUE (domain
),
15361 TREE_STRING_LENGTH (init
) - 1) == 0
15362 && ((size_t) TREE_STRING_LENGTH (init
)
15363 == strlen (TREE_STRING_POINTER (init
)) + 1))
15365 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
15366 ggc_strdup (TREE_STRING_POINTER (init
)));
15367 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
15368 MEM_READONLY_P (rtl
) = 1;
15371 /* Other aggregates, and complex values, could be represented using
15373 else if (AGGREGATE_TYPE_P (type
)
15374 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
15375 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
15376 || TREE_CODE (type
) == COMPLEX_TYPE
)
15378 /* Vectors only work if their mode is supported by the target.
15379 FIXME: generic vectors ought to work too. */
15380 else if (TREE_CODE (type
) == VECTOR_TYPE
15381 && !VECTOR_MODE_P (TYPE_MODE (type
)))
15383 /* If the initializer is something that we know will expand into an
15384 immediate RTL constant, expand it now. We must be careful not to
15385 reference variables which won't be output. */
15386 else if (initializer_constant_valid_p (init
, type
)
15387 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
15389 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
15391 if (TREE_CODE (type
) == VECTOR_TYPE
)
15392 switch (TREE_CODE (init
))
15397 if (TREE_CONSTANT (init
))
15399 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
15400 bool constant_p
= true;
15402 unsigned HOST_WIDE_INT ix
;
15404 /* Even when ctor is constant, it might contain non-*_CST
15405 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15406 belong into VECTOR_CST nodes. */
15407 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
15408 if (!CONSTANT_CLASS_P (value
))
15410 constant_p
= false;
15416 init
= build_vector_from_ctor (type
, elts
);
15426 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
15428 /* If expand_expr returns a MEM, it wasn't immediate. */
15429 gcc_assert (!rtl
|| !MEM_P (rtl
));
15435 /* Generate RTL for the variable DECL to represent its location. */
15438 rtl_for_decl_location (tree decl
)
15442 /* Here we have to decide where we are going to say the parameter "lives"
15443 (as far as the debugger is concerned). We only have a couple of
15444 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15446 DECL_RTL normally indicates where the parameter lives during most of the
15447 activation of the function. If optimization is enabled however, this
15448 could be either NULL or else a pseudo-reg. Both of those cases indicate
15449 that the parameter doesn't really live anywhere (as far as the code
15450 generation parts of GCC are concerned) during most of the function's
15451 activation. That will happen (for example) if the parameter is never
15452 referenced within the function.
15454 We could just generate a location descriptor here for all non-NULL
15455 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15456 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15457 where DECL_RTL is NULL or is a pseudo-reg.
15459 Note however that we can only get away with using DECL_INCOMING_RTL as
15460 a backup substitute for DECL_RTL in certain limited cases. In cases
15461 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15462 we can be sure that the parameter was passed using the same type as it is
15463 declared to have within the function, and that its DECL_INCOMING_RTL
15464 points us to a place where a value of that type is passed.
15466 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15467 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15468 because in these cases DECL_INCOMING_RTL points us to a value of some
15469 type which is *different* from the type of the parameter itself. Thus,
15470 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15471 such cases, the debugger would end up (for example) trying to fetch a
15472 `float' from a place which actually contains the first part of a
15473 `double'. That would lead to really incorrect and confusing
15474 output at debug-time.
15476 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15477 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15478 are a couple of exceptions however. On little-endian machines we can
15479 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15480 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15481 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15482 when (on a little-endian machine) a non-prototyped function has a
15483 parameter declared to be of type `short' or `char'. In such cases,
15484 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15485 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15486 passed `int' value. If the debugger then uses that address to fetch
15487 a `short' or a `char' (on a little-endian machine) the result will be
15488 the correct data, so we allow for such exceptional cases below.
15490 Note that our goal here is to describe the place where the given formal
15491 parameter lives during most of the function's activation (i.e. between the
15492 end of the prologue and the start of the epilogue). We'll do that as best
15493 as we can. Note however that if the given formal parameter is modified
15494 sometime during the execution of the function, then a stack backtrace (at
15495 debug-time) will show the function as having been called with the *new*
15496 value rather than the value which was originally passed in. This happens
15497 rarely enough that it is not a major problem, but it *is* a problem, and
15498 I'd like to fix it.
15500 A future version of dwarf2out.c may generate two additional attributes for
15501 any given DW_TAG_formal_parameter DIE which will describe the "passed
15502 type" and the "passed location" for the given formal parameter in addition
15503 to the attributes we now generate to indicate the "declared type" and the
15504 "active location" for each parameter. This additional set of attributes
15505 could be used by debuggers for stack backtraces. Separately, note that
15506 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15507 This happens (for example) for inlined-instances of inline function formal
15508 parameters which are never referenced. This really shouldn't be
15509 happening. All PARM_DECL nodes should get valid non-NULL
15510 DECL_INCOMING_RTL values. FIXME. */
15512 /* Use DECL_RTL as the "location" unless we find something better. */
15513 rtl
= DECL_RTL_IF_SET (decl
);
15515 /* When generating abstract instances, ignore everything except
15516 constants, symbols living in memory, and symbols living in
15517 fixed registers. */
15518 if (! reload_completed
)
15521 && (CONSTANT_P (rtl
)
15523 && CONSTANT_P (XEXP (rtl
, 0)))
15525 && TREE_CODE (decl
) == VAR_DECL
15526 && TREE_STATIC (decl
))))
15528 rtl
= targetm
.delegitimize_address (rtl
);
15533 else if (TREE_CODE (decl
) == PARM_DECL
)
15535 if (rtl
== NULL_RTX
15536 || is_pseudo_reg (rtl
)
15538 && is_pseudo_reg (XEXP (rtl
, 0))
15539 && DECL_INCOMING_RTL (decl
)
15540 && MEM_P (DECL_INCOMING_RTL (decl
))
15541 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15543 tree declared_type
= TREE_TYPE (decl
);
15544 tree passed_type
= DECL_ARG_TYPE (decl
);
15545 enum machine_mode dmode
= TYPE_MODE (declared_type
);
15546 enum machine_mode pmode
= TYPE_MODE (passed_type
);
15548 /* This decl represents a formal parameter which was optimized out.
15549 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15550 all cases where (rtl == NULL_RTX) just below. */
15551 if (dmode
== pmode
)
15552 rtl
= DECL_INCOMING_RTL (decl
);
15553 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15554 && SCALAR_INT_MODE_P (dmode
)
15555 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15556 && DECL_INCOMING_RTL (decl
))
15558 rtx inc
= DECL_INCOMING_RTL (decl
);
15561 else if (MEM_P (inc
))
15563 if (BYTES_BIG_ENDIAN
)
15564 rtl
= adjust_address_nv (inc
, dmode
,
15565 GET_MODE_SIZE (pmode
)
15566 - GET_MODE_SIZE (dmode
));
15573 /* If the parm was passed in registers, but lives on the stack, then
15574 make a big endian correction if the mode of the type of the
15575 parameter is not the same as the mode of the rtl. */
15576 /* ??? This is the same series of checks that are made in dbxout.c before
15577 we reach the big endian correction code there. It isn't clear if all
15578 of these checks are necessary here, but keeping them all is the safe
15580 else if (MEM_P (rtl
)
15581 && XEXP (rtl
, 0) != const0_rtx
15582 && ! CONSTANT_P (XEXP (rtl
, 0))
15583 /* Not passed in memory. */
15584 && !MEM_P (DECL_INCOMING_RTL (decl
))
15585 /* Not passed by invisible reference. */
15586 && (!REG_P (XEXP (rtl
, 0))
15587 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15588 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15589 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15590 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15593 /* Big endian correction check. */
15594 && BYTES_BIG_ENDIAN
15595 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15596 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15599 enum machine_mode addr_mode
= get_address_mode (rtl
);
15600 int offset
= (UNITS_PER_WORD
15601 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15603 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15604 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15607 else if (TREE_CODE (decl
) == VAR_DECL
15610 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15611 && BYTES_BIG_ENDIAN
)
15613 enum machine_mode addr_mode
= get_address_mode (rtl
);
15614 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
15615 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
15617 /* If a variable is declared "register" yet is smaller than
15618 a register, then if we store the variable to memory, it
15619 looks like we're storing a register-sized value, when in
15620 fact we are not. We need to adjust the offset of the
15621 storage location to reflect the actual value's bytes,
15622 else gdb will not be able to display it. */
15624 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15625 plus_constant (addr_mode
, XEXP (rtl
, 0),
15629 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15630 and will have been substituted directly into all expressions that use it.
15631 C does not have such a concept, but C++ and other languages do. */
15632 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
15633 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
15636 rtl
= targetm
.delegitimize_address (rtl
);
15638 /* If we don't look past the constant pool, we risk emitting a
15639 reference to a constant pool entry that isn't referenced from
15640 code, and thus is not emitted. */
15642 rtl
= avoid_constant_pool_reference (rtl
);
15644 /* Try harder to get a rtl. If this symbol ends up not being emitted
15645 in the current CU, resolve_addr will remove the expression referencing
15647 if (rtl
== NULL_RTX
15648 && TREE_CODE (decl
) == VAR_DECL
15649 && !DECL_EXTERNAL (decl
)
15650 && TREE_STATIC (decl
)
15651 && DECL_NAME (decl
)
15652 && !DECL_HARD_REGISTER (decl
)
15653 && DECL_MODE (decl
) != VOIDmode
)
15655 rtl
= make_decl_rtl_for_debug (decl
);
15657 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
15658 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
15665 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15666 returned. If so, the decl for the COMMON block is returned, and the
15667 value is the offset into the common block for the symbol. */
15670 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
15672 tree val_expr
, cvar
;
15673 enum machine_mode mode
;
15674 HOST_WIDE_INT bitsize
, bitpos
;
15676 int unsignedp
, volatilep
= 0;
15678 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15679 it does not have a value (the offset into the common area), or if it
15680 is thread local (as opposed to global) then it isn't common, and shouldn't
15681 be handled as such. */
15682 if (TREE_CODE (decl
) != VAR_DECL
15683 || !TREE_STATIC (decl
)
15684 || !DECL_HAS_VALUE_EXPR_P (decl
)
15688 val_expr
= DECL_VALUE_EXPR (decl
);
15689 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
15692 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
15693 &mode
, &unsignedp
, &volatilep
, true);
15695 if (cvar
== NULL_TREE
15696 || TREE_CODE (cvar
) != VAR_DECL
15697 || DECL_ARTIFICIAL (cvar
)
15698 || !TREE_PUBLIC (cvar
))
15702 if (offset
!= NULL
)
15704 if (!tree_fits_shwi_p (offset
))
15706 *value
= tree_to_shwi (offset
);
15709 *value
+= bitpos
/ BITS_PER_UNIT
;
15714 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15715 data attribute for a variable or a parameter. We generate the
15716 DW_AT_const_value attribute only in those cases where the given variable
15717 or parameter does not have a true "location" either in memory or in a
15718 register. This can happen (for example) when a constant is passed as an
15719 actual argument in a call to an inline function. (It's possible that
15720 these things can crop up in other ways also.) Note that one type of
15721 constant value which can be passed into an inlined function is a constant
15722 pointer. This can happen for example if an actual argument in an inlined
15723 function call evaluates to a compile-time constant address.
15725 CACHE_P is true if it is worth caching the location list for DECL,
15726 so that future calls can reuse it rather than regenerate it from scratch.
15727 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15728 since we will need to refer to them each time the function is inlined. */
15731 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
15732 enum dwarf_attribute attr
)
15735 dw_loc_list_ref list
;
15736 var_loc_list
*loc_list
;
15737 cached_dw_loc_list
*cache
;
15740 if (TREE_CODE (decl
) == ERROR_MARK
)
15743 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
15744 || TREE_CODE (decl
) == RESULT_DECL
);
15746 /* Try to get some constant RTL for this decl, and use that as the value of
15749 rtl
= rtl_for_decl_location (decl
);
15750 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15751 && add_const_value_attribute (die
, rtl
))
15754 /* See if we have single element location list that is equivalent to
15755 a constant value. That way we are better to use add_const_value_attribute
15756 rather than expanding constant value equivalent. */
15757 loc_list
= lookup_decl_loc (decl
);
15760 && loc_list
->first
->next
== NULL
15761 && NOTE_P (loc_list
->first
->loc
)
15762 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
15763 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
15765 struct var_loc_node
*node
;
15767 node
= loc_list
->first
;
15768 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
15769 if (GET_CODE (rtl
) == EXPR_LIST
)
15770 rtl
= XEXP (rtl
, 0);
15771 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15772 && add_const_value_attribute (die
, rtl
))
15775 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15776 list several times. See if we've already cached the contents. */
15778 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
15782 cache
= (cached_dw_loc_list
*)
15783 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
15785 list
= cache
->loc_list
;
15789 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
15790 /* It is usually worth caching this result if the decl is from
15791 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15792 if (cache_p
&& list
&& list
->dw_loc_next
)
15794 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
15795 DECL_UID (decl
), INSERT
);
15796 cache
= ggc_cleared_alloc
<cached_dw_loc_list
> ();
15797 cache
->decl_id
= DECL_UID (decl
);
15798 cache
->loc_list
= list
;
15804 add_AT_location_description (die
, attr
, list
);
15807 /* None of that worked, so it must not really have a location;
15808 try adding a constant value attribute from the DECL_INITIAL. */
15809 return tree_add_const_value_attribute_for_decl (die
, decl
);
15812 /* Add VARIABLE and DIE into deferred locations list. */
15815 defer_location (tree variable
, dw_die_ref die
)
15817 deferred_locations entry
;
15818 entry
.variable
= variable
;
15820 vec_safe_push (deferred_locations_list
, entry
);
15823 /* Helper function for tree_add_const_value_attribute. Natively encode
15824 initializer INIT into an array. Return true if successful. */
15827 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15831 if (init
== NULL_TREE
)
15835 switch (TREE_CODE (init
))
15838 type
= TREE_TYPE (init
);
15839 if (TREE_CODE (type
) == ARRAY_TYPE
)
15841 tree enttype
= TREE_TYPE (type
);
15842 enum machine_mode mode
= TYPE_MODE (enttype
);
15844 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15846 if (int_size_in_bytes (type
) != size
)
15848 if (size
> TREE_STRING_LENGTH (init
))
15850 memcpy (array
, TREE_STRING_POINTER (init
),
15851 TREE_STRING_LENGTH (init
));
15852 memset (array
+ TREE_STRING_LENGTH (init
),
15853 '\0', size
- TREE_STRING_LENGTH (init
));
15856 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15861 type
= TREE_TYPE (init
);
15862 if (int_size_in_bytes (type
) != size
)
15864 if (TREE_CODE (type
) == ARRAY_TYPE
)
15866 HOST_WIDE_INT min_index
;
15867 unsigned HOST_WIDE_INT cnt
;
15868 int curpos
= 0, fieldsize
;
15869 constructor_elt
*ce
;
15871 if (TYPE_DOMAIN (type
) == NULL_TREE
15872 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
15875 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15876 if (fieldsize
<= 0)
15879 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
15880 memset (array
, '\0', size
);
15881 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15883 tree val
= ce
->value
;
15884 tree index
= ce
->index
;
15886 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15887 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
15890 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
15895 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
15898 curpos
= pos
+ fieldsize
;
15899 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15901 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
15902 - tree_to_shwi (TREE_OPERAND (index
, 0));
15903 while (count
-- > 0)
15906 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
15907 curpos
+= fieldsize
;
15910 gcc_assert (curpos
<= size
);
15914 else if (TREE_CODE (type
) == RECORD_TYPE
15915 || TREE_CODE (type
) == UNION_TYPE
)
15917 tree field
= NULL_TREE
;
15918 unsigned HOST_WIDE_INT cnt
;
15919 constructor_elt
*ce
;
15921 if (int_size_in_bytes (type
) != size
)
15924 if (TREE_CODE (type
) == RECORD_TYPE
)
15925 field
= TYPE_FIELDS (type
);
15927 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15929 tree val
= ce
->value
;
15930 int pos
, fieldsize
;
15932 if (ce
->index
!= 0)
15938 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
15941 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
15942 && TYPE_DOMAIN (TREE_TYPE (field
))
15943 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
15945 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
15946 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
15948 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
15949 pos
= int_byte_position (field
);
15950 gcc_assert (pos
+ fieldsize
<= size
);
15952 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
15958 case VIEW_CONVERT_EXPR
:
15959 case NON_LVALUE_EXPR
:
15960 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
15962 return native_encode_expr (init
, array
, size
) == size
;
15966 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15967 attribute is the const value T. */
15970 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
15973 tree type
= TREE_TYPE (t
);
15976 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
15980 gcc_assert (!DECL_P (init
));
15982 rtl
= rtl_for_decl_init (init
, type
);
15984 return add_const_value_attribute (die
, rtl
);
15985 /* If the host and target are sane, try harder. */
15986 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
15987 && initializer_constant_valid_p (init
, type
))
15989 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
15990 if (size
> 0 && (int) size
== size
)
15992 unsigned char *array
= ggc_cleared_vec_alloc
<unsigned char> (size
);
15994 if (native_encode_initializer (init
, array
, size
))
15996 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
16005 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
16006 attribute is the const value of T, where T is an integral constant
16007 variable with static storage duration
16008 (so it can't be a PARM_DECL or a RESULT_DECL). */
16011 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
16015 || (TREE_CODE (decl
) != VAR_DECL
16016 && TREE_CODE (decl
) != CONST_DECL
)
16017 || (TREE_CODE (decl
) == VAR_DECL
16018 && !TREE_STATIC (decl
)))
16021 if (TREE_READONLY (decl
)
16022 && ! TREE_THIS_VOLATILE (decl
)
16023 && DECL_INITIAL (decl
))
16028 /* Don't add DW_AT_const_value if abstract origin already has one. */
16029 if (get_AT (var_die
, DW_AT_const_value
))
16032 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
16035 /* Convert the CFI instructions for the current function into a
16036 location list. This is used for DW_AT_frame_base when we targeting
16037 a dwarf2 consumer that does not support the dwarf3
16038 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
16041 static dw_loc_list_ref
16042 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
16046 dw_loc_list_ref list
, *list_tail
;
16048 dw_cfa_location last_cfa
, next_cfa
;
16049 const char *start_label
, *last_label
, *section
;
16050 dw_cfa_location remember
;
16053 gcc_assert (fde
!= NULL
);
16055 section
= secname_for_decl (current_function_decl
);
16059 memset (&next_cfa
, 0, sizeof (next_cfa
));
16060 next_cfa
.reg
= INVALID_REGNUM
;
16061 remember
= next_cfa
;
16063 start_label
= fde
->dw_fde_begin
;
16065 /* ??? Bald assumption that the CIE opcode list does not contain
16066 advance opcodes. */
16067 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
16068 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
16070 last_cfa
= next_cfa
;
16071 last_label
= start_label
;
16073 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
16075 /* If the first partition contained no CFI adjustments, the
16076 CIE opcodes apply to the whole first partition. */
16077 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16078 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
16079 list_tail
=&(*list_tail
)->dw_loc_next
;
16080 start_label
= last_label
= fde
->dw_fde_second_begin
;
16083 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
16085 switch (cfi
->dw_cfi_opc
)
16087 case DW_CFA_set_loc
:
16088 case DW_CFA_advance_loc1
:
16089 case DW_CFA_advance_loc2
:
16090 case DW_CFA_advance_loc4
:
16091 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16093 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16094 start_label
, last_label
, section
);
16096 list_tail
= &(*list_tail
)->dw_loc_next
;
16097 last_cfa
= next_cfa
;
16098 start_label
= last_label
;
16100 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
16103 case DW_CFA_advance_loc
:
16104 /* The encoding is complex enough that we should never emit this. */
16105 gcc_unreachable ();
16108 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
16111 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
16113 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16115 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16116 start_label
, last_label
, section
);
16118 list_tail
= &(*list_tail
)->dw_loc_next
;
16119 last_cfa
= next_cfa
;
16120 start_label
= last_label
;
16122 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16123 start_label
, fde
->dw_fde_end
, section
);
16124 list_tail
= &(*list_tail
)->dw_loc_next
;
16125 start_label
= last_label
= fde
->dw_fde_second_begin
;
16129 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16131 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16132 start_label
, last_label
, section
);
16133 list_tail
= &(*list_tail
)->dw_loc_next
;
16134 start_label
= last_label
;
16137 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
16139 fde
->dw_fde_second_begin
16140 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
16143 if (list
&& list
->dw_loc_next
)
16149 /* Compute a displacement from the "steady-state frame pointer" to the
16150 frame base (often the same as the CFA), and store it in
16151 frame_pointer_fb_offset. OFFSET is added to the displacement
16152 before the latter is negated. */
16155 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
16159 #ifdef FRAME_POINTER_CFA_OFFSET
16160 reg
= frame_pointer_rtx
;
16161 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
16163 reg
= arg_pointer_rtx
;
16164 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
16167 elim
= (ira_use_lra_p
16168 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
16169 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
16170 if (GET_CODE (elim
) == PLUS
)
16172 offset
+= INTVAL (XEXP (elim
, 1));
16173 elim
= XEXP (elim
, 0);
16176 frame_pointer_fb_offset
= -offset
;
16178 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
16179 in which to eliminate. This is because it's stack pointer isn't
16180 directly accessible as a register within the ISA. To work around
16181 this, assume that while we cannot provide a proper value for
16182 frame_pointer_fb_offset, we won't need one either. */
16183 frame_pointer_fb_offset_valid
16184 = ((SUPPORTS_STACK_ALIGNMENT
16185 && (elim
== hard_frame_pointer_rtx
16186 || elim
== stack_pointer_rtx
))
16187 || elim
== (frame_pointer_needed
16188 ? hard_frame_pointer_rtx
16189 : stack_pointer_rtx
));
16192 /* Generate a DW_AT_name attribute given some string value to be included as
16193 the value of the attribute. */
16196 add_name_attribute (dw_die_ref die
, const char *name_string
)
16198 if (name_string
!= NULL
&& *name_string
!= 0)
16200 if (demangle_name_func
)
16201 name_string
= (*demangle_name_func
) (name_string
);
16203 add_AT_string (die
, DW_AT_name
, name_string
);
16207 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
16208 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
16209 of TYPE accordingly.
16211 ??? This is a temporary measure until after we're able to generate
16212 regular DWARF for the complex Ada type system. */
16215 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
16216 dw_die_ref context_die
)
16219 dw_die_ref dtype_die
;
16221 if (!lang_hooks
.types
.descriptive_type
)
16224 dtype
= lang_hooks
.types
.descriptive_type (type
);
16228 dtype_die
= lookup_type_die (dtype
);
16231 gen_type_die (dtype
, context_die
);
16232 dtype_die
= lookup_type_die (dtype
);
16233 gcc_assert (dtype_die
);
16236 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
16239 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
16241 static const char *
16242 comp_dir_string (void)
16246 static const char *cached_wd
= NULL
;
16248 if (cached_wd
!= NULL
)
16251 wd
= get_src_pwd ();
16255 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
16259 wdlen
= strlen (wd
);
16260 wd1
= ggc_vec_alloc
<char> (wdlen
+ 2);
16262 wd1
[wdlen
] = DIR_SEPARATOR
;
16263 wd1
[wdlen
+ 1] = 0;
16267 cached_wd
= remap_debug_filename (wd
);
16271 /* Generate a DW_AT_comp_dir attribute for DIE. */
16274 add_comp_dir_attribute (dw_die_ref die
)
16276 const char * wd
= comp_dir_string ();
16278 add_AT_string (die
, DW_AT_comp_dir
, wd
);
16281 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
16285 lower_bound_default (void)
16287 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
16292 case DW_LANG_C_plus_plus
:
16294 case DW_LANG_ObjC_plus_plus
:
16297 case DW_LANG_Fortran77
:
16298 case DW_LANG_Fortran90
:
16299 case DW_LANG_Fortran95
:
16303 case DW_LANG_Python
:
16304 return dwarf_version
>= 4 ? 0 : -1;
16305 case DW_LANG_Ada95
:
16306 case DW_LANG_Ada83
:
16307 case DW_LANG_Cobol74
:
16308 case DW_LANG_Cobol85
:
16309 case DW_LANG_Pascal83
:
16310 case DW_LANG_Modula2
:
16312 return dwarf_version
>= 4 ? 1 : -1;
16318 /* Given a tree node describing an array bound (either lower or upper) output
16319 a representation for that bound. */
16322 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
16324 switch (TREE_CODE (bound
))
16329 /* All fixed-bounds are represented by INTEGER_CST nodes. */
16332 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
16335 /* Use the default if possible. */
16336 if (bound_attr
== DW_AT_lower_bound
16337 && tree_fits_shwi_p (bound
)
16338 && (dflt
= lower_bound_default ()) != -1
16339 && tree_to_shwi (bound
) == dflt
)
16342 /* If HOST_WIDE_INT is big enough then represent the bound as
16343 a constant value. We need to choose a form based on
16344 whether the type is signed or unsigned. We cannot just
16345 call add_AT_unsigned if the value itself is positive
16346 (add_AT_unsigned might add the unsigned value encoded as
16347 DW_FORM_data[1248]). Some DWARF consumers will lookup the
16348 bounds type and then sign extend any unsigned values found
16349 for signed types. This is needed only for
16350 DW_AT_{lower,upper}_bound, since for most other attributes,
16351 consumers will treat DW_FORM_data[1248] as unsigned values,
16352 regardless of the underlying type. */
16353 else if (prec
<= HOST_BITS_PER_WIDE_INT
16354 || tree_fits_uhwi_p (bound
))
16356 if (TYPE_UNSIGNED (TREE_TYPE (bound
)))
16357 add_AT_unsigned (subrange_die
, bound_attr
,
16358 TREE_INT_CST_LOW (bound
));
16360 add_AT_int (subrange_die
, bound_attr
, TREE_INT_CST_LOW (bound
));
16363 /* Otherwise represent the bound as an unsigned value with
16364 the precision of its type. The precision and signedness
16365 of the type will be necessary to re-interpret it
16367 add_AT_wide (subrange_die
, bound_attr
, bound
);
16372 case VIEW_CONVERT_EXPR
:
16373 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
16383 dw_die_ref decl_die
= lookup_decl_die (bound
);
16385 /* ??? Can this happen, or should the variable have been bound
16386 first? Probably it can, since I imagine that we try to create
16387 the types of parameters in the order in which they exist in
16388 the list, and won't have created a forward reference to a
16389 later parameter. */
16390 if (decl_die
!= NULL
)
16392 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16400 /* Otherwise try to create a stack operation procedure to
16401 evaluate the value of the array bound. */
16403 dw_die_ref ctx
, decl_die
;
16404 dw_loc_list_ref list
;
16406 list
= loc_list_from_tree (bound
, 2);
16407 if (list
== NULL
|| single_element_loc_list_p (list
))
16409 /* If DW_AT_*bound is not a reference nor constant, it is
16410 a DWARF expression rather than location description.
16411 For that loc_list_from_tree (bound, 0) is needed.
16412 If that fails to give a single element list,
16413 fall back to outputting this as a reference anyway. */
16414 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
16415 if (list2
&& single_element_loc_list_p (list2
))
16417 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
16424 if (current_function_decl
== 0)
16425 ctx
= comp_unit_die ();
16427 ctx
= lookup_decl_die (current_function_decl
);
16429 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
16430 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
16431 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
16432 add_AT_location_description (decl_die
, DW_AT_location
, list
);
16433 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16439 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16440 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16441 Note that the block of subscript information for an array type also
16442 includes information about the element type of the given array type. */
16445 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
16447 unsigned dimension_number
;
16449 dw_die_ref subrange_die
;
16451 for (dimension_number
= 0;
16452 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
16453 type
= TREE_TYPE (type
), dimension_number
++)
16455 tree domain
= TYPE_DOMAIN (type
);
16457 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
16460 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16461 and (in GNU C only) variable bounds. Handle all three forms
16463 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
16466 /* We have an array type with specified bounds. */
16467 lower
= TYPE_MIN_VALUE (domain
);
16468 upper
= TYPE_MAX_VALUE (domain
);
16470 /* Define the index type. */
16471 if (TREE_TYPE (domain
))
16473 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16474 TREE_TYPE field. We can't emit debug info for this
16475 because it is an unnamed integral type. */
16476 if (TREE_CODE (domain
) == INTEGER_TYPE
16477 && TYPE_NAME (domain
) == NULL_TREE
16478 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
16479 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
16482 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
16486 /* ??? If upper is NULL, the array has unspecified length,
16487 but it does have a lower bound. This happens with Fortran
16489 Since the debugger is definitely going to need to know N
16490 to produce useful results, go ahead and output the lower
16491 bound solo, and hope the debugger can cope. */
16493 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
16495 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
16498 /* Otherwise we have an array type with an unspecified length. The
16499 DWARF-2 spec does not say how to handle this; let's just leave out the
16504 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
16507 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16509 dw_die_ref decl_die
;
16510 HOST_WIDE_INT size
;
16512 switch (TREE_CODE (tree_node
))
16517 case ENUMERAL_TYPE
:
16520 case QUAL_UNION_TYPE
:
16521 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
16522 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
16524 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
16527 size
= int_size_in_bytes (tree_node
);
16530 /* For a data member of a struct or union, the DW_AT_byte_size is
16531 generally given as the number of bytes normally allocated for an
16532 object of the *declared* type of the member itself. This is true
16533 even for bit-fields. */
16534 size
= int_size_in_bytes (field_type (tree_node
));
16537 gcc_unreachable ();
16540 /* Note that `size' might be -1 when we get to this point. If it is, that
16541 indicates that the byte size of the entity in question is variable. We
16542 have no good way of expressing this fact in Dwarf at the present time,
16543 when location description was not used by the caller code instead. */
16545 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
16548 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16549 which specifies the distance in bits from the highest order bit of the
16550 "containing object" for the bit-field to the highest order bit of the
16553 For any given bit-field, the "containing object" is a hypothetical object
16554 (of some integral or enum type) within which the given bit-field lives. The
16555 type of this hypothetical "containing object" is always the same as the
16556 declared type of the individual bit-field itself. The determination of the
16557 exact location of the "containing object" for a bit-field is rather
16558 complicated. It's handled by the `field_byte_offset' function (above).
16560 Note that it is the size (in bytes) of the hypothetical "containing object"
16561 which will be given in the DW_AT_byte_size attribute for this bit-field.
16562 (See `byte_size_attribute' above). */
16565 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
16567 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
16568 tree type
= DECL_BIT_FIELD_TYPE (decl
);
16569 HOST_WIDE_INT bitpos_int
;
16570 HOST_WIDE_INT highest_order_object_bit_offset
;
16571 HOST_WIDE_INT highest_order_field_bit_offset
;
16572 HOST_WIDE_INT bit_offset
;
16574 /* Must be a field and a bit field. */
16575 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
16577 /* We can't yet handle bit-fields whose offsets are variable, so if we
16578 encounter such things, just return without generating any attribute
16579 whatsoever. Likewise for variable or too large size. */
16580 if (! tree_fits_shwi_p (bit_position (decl
))
16581 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
16584 bitpos_int
= int_bit_position (decl
);
16586 /* Note that the bit offset is always the distance (in bits) from the
16587 highest-order bit of the "containing object" to the highest-order bit of
16588 the bit-field itself. Since the "high-order end" of any object or field
16589 is different on big-endian and little-endian machines, the computation
16590 below must take account of these differences. */
16591 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
16592 highest_order_field_bit_offset
= bitpos_int
;
16594 if (! BYTES_BIG_ENDIAN
)
16596 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
16597 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
16601 = (! BYTES_BIG_ENDIAN
16602 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
16603 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
16605 if (bit_offset
< 0)
16606 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
16608 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
16611 /* For a FIELD_DECL node which represents a bit field, output an attribute
16612 which specifies the length in bits of the given field. */
16615 add_bit_size_attribute (dw_die_ref die
, tree decl
)
16617 /* Must be a field and a bit field. */
16618 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
16619 && DECL_BIT_FIELD_TYPE (decl
));
16621 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
16622 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
16625 /* If the compiled language is ANSI C, then add a 'prototyped'
16626 attribute, if arg types are given for the parameters of a function. */
16629 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
16631 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
16632 && prototype_p (func_type
))
16633 add_AT_flag (die
, DW_AT_prototyped
, 1);
16636 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16637 by looking in either the type declaration or object declaration
16640 static inline dw_die_ref
16641 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
16643 dw_die_ref origin_die
= NULL
;
16645 if (TREE_CODE (origin
) != FUNCTION_DECL
)
16647 /* We may have gotten separated from the block for the inlined
16648 function, if we're in an exception handler or some such; make
16649 sure that the abstract function has been written out.
16651 Doing this for nested functions is wrong, however; functions are
16652 distinct units, and our context might not even be inline. */
16656 fn
= TYPE_STUB_DECL (fn
);
16658 fn
= decl_function_context (fn
);
16660 dwarf2out_abstract_function (fn
);
16663 if (DECL_P (origin
))
16664 origin_die
= lookup_decl_die (origin
);
16665 else if (TYPE_P (origin
))
16666 origin_die
= lookup_type_die (origin
);
16668 /* XXX: Functions that are never lowered don't always have correct block
16669 trees (in the case of java, they simply have no block tree, in some other
16670 languages). For these functions, there is nothing we can really do to
16671 output correct debug info for inlined functions in all cases. Rather
16672 than die, we'll just produce deficient debug info now, in that we will
16673 have variables without a proper abstract origin. In the future, when all
16674 functions are lowered, we should re-add a gcc_assert (origin_die)
16678 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
16682 /* We do not currently support the pure_virtual attribute. */
16685 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
16687 if (DECL_VINDEX (func_decl
))
16689 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
16691 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
16692 add_AT_loc (die
, DW_AT_vtable_elem_location
,
16693 new_loc_descr (DW_OP_constu
,
16694 tree_to_shwi (DECL_VINDEX (func_decl
)),
16697 /* GNU extension: Record what type this method came from originally. */
16698 if (debug_info_level
> DINFO_LEVEL_TERSE
16699 && DECL_CONTEXT (func_decl
))
16700 add_AT_die_ref (die
, DW_AT_containing_type
,
16701 lookup_type_die (DECL_CONTEXT (func_decl
)));
16705 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16706 given decl. This used to be a vendor extension until after DWARF 4
16707 standardized it. */
16710 add_linkage_attr (dw_die_ref die
, tree decl
)
16712 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
16714 /* Mimic what assemble_name_raw does with a leading '*'. */
16715 if (name
[0] == '*')
16718 if (dwarf_version
>= 4)
16719 add_AT_string (die
, DW_AT_linkage_name
, name
);
16721 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
16724 /* Add source coordinate attributes for the given decl. */
16727 add_src_coords_attributes (dw_die_ref die
, tree decl
)
16729 expanded_location s
;
16731 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
16733 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16734 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
16735 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
16738 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16741 add_linkage_name (dw_die_ref die
, tree decl
)
16743 if (debug_info_level
> DINFO_LEVEL_NONE
16744 && (TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
16745 && TREE_PUBLIC (decl
)
16746 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
16747 && die
->die_tag
!= DW_TAG_member
)
16749 /* Defer until we have an assembler name set. */
16750 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
16752 limbo_die_node
*asm_name
;
16754 asm_name
= ggc_cleared_alloc
<limbo_die_node
> ();
16755 asm_name
->die
= die
;
16756 asm_name
->created_for
= decl
;
16757 asm_name
->next
= deferred_asm_name
;
16758 deferred_asm_name
= asm_name
;
16760 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
16761 add_linkage_attr (die
, decl
);
16765 /* Add a DW_AT_name attribute and source coordinate attribute for the
16766 given decl, but only if it actually has a name. */
16769 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
16773 decl_name
= DECL_NAME (decl
);
16774 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
16776 const char *name
= dwarf2_name (decl
, 0);
16778 add_name_attribute (die
, name
);
16779 if (! DECL_ARTIFICIAL (decl
))
16780 add_src_coords_attributes (die
, decl
);
16782 add_linkage_name (die
, decl
);
16785 #ifdef VMS_DEBUGGING_INFO
16786 /* Get the function's name, as described by its RTL. This may be different
16787 from the DECL_NAME name used in the source file. */
16788 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
16790 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
16791 XEXP (DECL_RTL (decl
), 0), false);
16792 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
16794 #endif /* VMS_DEBUGGING_INFO */
16797 #ifdef VMS_DEBUGGING_INFO
16798 /* Output the debug main pointer die for VMS */
16801 dwarf2out_vms_debug_main_pointer (void)
16803 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
16806 /* Allocate the VMS debug main subprogram die. */
16807 die
= ggc_cleared_alloc
<die_node
> ();
16808 die
->die_tag
= DW_TAG_subprogram
;
16809 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
16810 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
16811 current_function_funcdef_no
);
16812 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
16814 /* Make it the first child of comp_unit_die (). */
16815 die
->die_parent
= comp_unit_die ();
16816 if (comp_unit_die ()->die_child
)
16818 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
16819 comp_unit_die ()->die_child
->die_sib
= die
;
16823 die
->die_sib
= die
;
16824 comp_unit_die ()->die_child
= die
;
16827 #endif /* VMS_DEBUGGING_INFO */
16829 /* Push a new declaration scope. */
16832 push_decl_scope (tree scope
)
16834 vec_safe_push (decl_scope_table
, scope
);
16837 /* Pop a declaration scope. */
16840 pop_decl_scope (void)
16842 decl_scope_table
->pop ();
16845 /* walk_tree helper function for uses_local_type, below. */
16848 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
16851 *walk_subtrees
= 0;
16854 tree name
= TYPE_NAME (*tp
);
16855 if (name
&& DECL_P (name
) && decl_function_context (name
))
16861 /* If TYPE involves a function-local type (including a local typedef to a
16862 non-local type), returns that type; otherwise returns NULL_TREE. */
16865 uses_local_type (tree type
)
16867 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
16871 /* Return the DIE for the scope that immediately contains this type.
16872 Non-named types that do not involve a function-local type get global
16873 scope. Named types nested in namespaces or other types get their
16874 containing scope. All other types (i.e. function-local named types) get
16875 the current active scope. */
16878 scope_die_for (tree t
, dw_die_ref context_die
)
16880 dw_die_ref scope_die
= NULL
;
16881 tree containing_scope
;
16883 /* Non-types always go in the current scope. */
16884 gcc_assert (TYPE_P (t
));
16886 /* Use the scope of the typedef, rather than the scope of the type
16888 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
16889 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
16891 containing_scope
= TYPE_CONTEXT (t
);
16893 /* Use the containing namespace if there is one. */
16894 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
16896 if (context_die
== lookup_decl_die (containing_scope
))
16898 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
16899 context_die
= get_context_die (containing_scope
);
16901 containing_scope
= NULL_TREE
;
16904 /* Ignore function type "scopes" from the C frontend. They mean that
16905 a tagged type is local to a parmlist of a function declarator, but
16906 that isn't useful to DWARF. */
16907 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
16908 containing_scope
= NULL_TREE
;
16910 if (SCOPE_FILE_SCOPE_P (containing_scope
))
16912 /* If T uses a local type keep it local as well, to avoid references
16913 to function-local DIEs from outside the function. */
16914 if (current_function_decl
&& uses_local_type (t
))
16915 scope_die
= context_die
;
16917 scope_die
= comp_unit_die ();
16919 else if (TYPE_P (containing_scope
))
16921 /* For types, we can just look up the appropriate DIE. */
16922 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16923 scope_die
= get_context_die (containing_scope
);
16926 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
16927 if (scope_die
== NULL
)
16928 scope_die
= comp_unit_die ();
16932 scope_die
= context_die
;
16937 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16940 local_scope_p (dw_die_ref context_die
)
16942 for (; context_die
; context_die
= context_die
->die_parent
)
16943 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
16944 || context_die
->die_tag
== DW_TAG_subprogram
)
16950 /* Returns nonzero if CONTEXT_DIE is a class. */
16953 class_scope_p (dw_die_ref context_die
)
16955 return (context_die
16956 && (context_die
->die_tag
== DW_TAG_structure_type
16957 || context_die
->die_tag
== DW_TAG_class_type
16958 || context_die
->die_tag
== DW_TAG_interface_type
16959 || context_die
->die_tag
== DW_TAG_union_type
));
16962 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16963 whether or not to treat a DIE in this context as a declaration. */
16966 class_or_namespace_scope_p (dw_die_ref context_die
)
16968 return (class_scope_p (context_die
)
16969 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
16972 /* Many forms of DIEs require a "type description" attribute. This
16973 routine locates the proper "type descriptor" die for the type given
16974 by 'type', and adds a DW_AT_type attribute below the given die. */
16977 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
16978 int decl_volatile
, dw_die_ref context_die
)
16980 enum tree_code code
= TREE_CODE (type
);
16981 dw_die_ref type_die
= NULL
;
16983 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16984 or fixed-point type, use the inner type. This is because we have no
16985 support for unnamed types in base_type_die. This can happen if this is
16986 an Ada subrange type. Correct solution is emit a subrange type die. */
16987 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
16988 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
16989 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
16991 if (code
== ERROR_MARK
16992 /* Handle a special case. For functions whose return type is void, we
16993 generate *no* type attribute. (Note that no object may have type
16994 `void', so this only applies to function return types). */
16995 || code
== VOID_TYPE
)
16998 type_die
= modified_type_die (type
,
16999 decl_const
|| TYPE_READONLY (type
),
17000 decl_volatile
|| TYPE_VOLATILE (type
),
17003 if (type_die
!= NULL
)
17004 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
17007 /* Given an object die, add the calling convention attribute for the
17008 function call type. */
17010 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
17012 enum dwarf_calling_convention value
= DW_CC_normal
;
17014 value
= ((enum dwarf_calling_convention
)
17015 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
17018 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
17020 /* DWARF 2 doesn't provide a way to identify a program's source-level
17021 entry point. DW_AT_calling_convention attributes are only meant
17022 to describe functions' calling conventions. However, lacking a
17023 better way to signal the Fortran main program, we used this for
17024 a long time, following existing custom. Now, DWARF 4 has
17025 DW_AT_main_subprogram, which we add below, but some tools still
17026 rely on the old way, which we thus keep. */
17027 value
= DW_CC_program
;
17029 if (dwarf_version
>= 4 || !dwarf_strict
)
17030 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
17033 /* Only add the attribute if the backend requests it, and
17034 is not DW_CC_normal. */
17035 if (value
&& (value
!= DW_CC_normal
))
17036 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
17039 /* Given a tree pointer to a struct, class, union, or enum type node, return
17040 a pointer to the (string) tag name for the given type, or zero if the type
17041 was declared without a tag. */
17043 static const char *
17044 type_tag (const_tree type
)
17046 const char *name
= 0;
17048 if (TYPE_NAME (type
) != 0)
17052 /* Find the IDENTIFIER_NODE for the type name. */
17053 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
17054 && !TYPE_NAMELESS (type
))
17055 t
= TYPE_NAME (type
);
17057 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
17058 a TYPE_DECL node, regardless of whether or not a `typedef' was
17060 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
17061 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
17063 /* We want to be extra verbose. Don't call dwarf_name if
17064 DECL_NAME isn't set. The default hook for decl_printable_name
17065 doesn't like that, and in this context it's correct to return
17066 0, instead of "<anonymous>" or the like. */
17067 if (DECL_NAME (TYPE_NAME (type
))
17068 && !DECL_NAMELESS (TYPE_NAME (type
)))
17069 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
17072 /* Now get the name as a string, or invent one. */
17073 if (!name
&& t
!= 0)
17074 name
= IDENTIFIER_POINTER (t
);
17077 return (name
== 0 || *name
== '\0') ? 0 : name
;
17080 /* Return the type associated with a data member, make a special check
17081 for bit field types. */
17084 member_declared_type (const_tree member
)
17086 return (DECL_BIT_FIELD_TYPE (member
)
17087 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
17090 /* Get the decl's label, as described by its RTL. This may be different
17091 from the DECL_NAME name used in the source file. */
17094 static const char *
17095 decl_start_label (tree decl
)
17098 const char *fnname
;
17100 x
= DECL_RTL (decl
);
17101 gcc_assert (MEM_P (x
));
17104 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
17106 fnname
= XSTR (x
, 0);
17111 /* These routines generate the internal representation of the DIE's for
17112 the compilation unit. Debugging information is collected by walking
17113 the declaration trees passed in from dwarf2out_decl(). */
17116 gen_array_type_die (tree type
, dw_die_ref context_die
)
17118 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17119 dw_die_ref array_die
;
17121 /* GNU compilers represent multidimensional array types as sequences of one
17122 dimensional array types whose element types are themselves array types.
17123 We sometimes squish that down to a single array_type DIE with multiple
17124 subscripts in the Dwarf debugging info. The draft Dwarf specification
17125 say that we are allowed to do this kind of compression in C, because
17126 there is no difference between an array of arrays and a multidimensional
17127 array. We don't do this for Ada to remain as close as possible to the
17128 actual representation, which is especially important against the language
17129 flexibilty wrt arrays of variable size. */
17131 bool collapse_nested_arrays
= !is_ada ();
17134 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
17135 DW_TAG_string_type doesn't have DW_AT_type attribute). */
17136 if (TYPE_STRING_FLAG (type
)
17137 && TREE_CODE (type
) == ARRAY_TYPE
17139 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
17141 HOST_WIDE_INT size
;
17143 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
17144 add_name_attribute (array_die
, type_tag (type
));
17145 equate_type_number_to_die (type
, array_die
);
17146 size
= int_size_in_bytes (type
);
17148 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17149 else if (TYPE_DOMAIN (type
) != NULL_TREE
17150 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
17151 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
17153 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
17154 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
17156 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
17157 if (loc
&& size
> 0)
17159 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
17160 if (size
!= DWARF2_ADDR_SIZE
)
17161 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17167 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17168 add_name_attribute (array_die
, type_tag (type
));
17169 equate_type_number_to_die (type
, array_die
);
17171 if (TREE_CODE (type
) == VECTOR_TYPE
)
17172 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
17174 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17176 && TREE_CODE (type
) == ARRAY_TYPE
17177 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
17178 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
17179 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17182 /* We default the array ordering. SDB will probably do
17183 the right things even if DW_AT_ordering is not present. It's not even
17184 an issue until we start to get into multidimensional arrays anyway. If
17185 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
17186 then we'll have to put the DW_AT_ordering attribute back in. (But if
17187 and when we find out that we need to put these in, we will only do so
17188 for multidimensional arrays. */
17189 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
17192 if (TREE_CODE (type
) == VECTOR_TYPE
)
17194 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
17195 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17196 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
17197 add_bound_info (subrange_die
, DW_AT_upper_bound
,
17198 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
17201 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
17203 /* Add representation of the type of the elements of this array type and
17204 emit the corresponding DIE if we haven't done it already. */
17205 element_type
= TREE_TYPE (type
);
17206 if (collapse_nested_arrays
)
17207 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
17209 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
17211 element_type
= TREE_TYPE (element_type
);
17214 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
17216 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
17217 if (TYPE_ARTIFICIAL (type
))
17218 add_AT_flag (array_die
, DW_AT_artificial
, 1);
17220 if (get_AT (array_die
, DW_AT_name
))
17221 add_pubtype (type
, array_die
);
17224 static dw_loc_descr_ref
17225 descr_info_loc (tree val
, tree base_decl
)
17227 HOST_WIDE_INT size
;
17228 dw_loc_descr_ref loc
, loc2
;
17229 enum dwarf_location_atom op
;
17231 if (val
== base_decl
)
17232 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
17234 switch (TREE_CODE (val
))
17237 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17239 return loc_descriptor_from_tree (val
, 0);
17241 if (tree_fits_shwi_p (val
))
17242 return int_loc_descriptor (tree_to_shwi (val
));
17245 size
= int_size_in_bytes (TREE_TYPE (val
));
17248 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17251 if (size
== DWARF2_ADDR_SIZE
)
17252 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
17254 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
17256 case POINTER_PLUS_EXPR
:
17258 if (tree_fits_uhwi_p (TREE_OPERAND (val
, 1))
17259 && tree_to_uhwi (TREE_OPERAND (val
, 1)) < 16384)
17261 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17264 loc_descr_plus_const (&loc
, tree_to_shwi (TREE_OPERAND (val
, 1)));
17270 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17273 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
17276 add_loc_descr (&loc
, loc2
);
17277 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
17299 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
17300 tree val
, tree base_decl
)
17302 dw_loc_descr_ref loc
;
17304 if (tree_fits_shwi_p (val
))
17306 add_AT_unsigned (die
, attr
, tree_to_shwi (val
));
17310 loc
= descr_info_loc (val
, base_decl
);
17314 add_AT_loc (die
, attr
, loc
);
17317 /* This routine generates DIE for array with hidden descriptor, details
17318 are filled into *info by a langhook. */
17321 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
17322 dw_die_ref context_die
)
17324 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17325 dw_die_ref array_die
;
17328 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17329 add_name_attribute (array_die
, type_tag (type
));
17330 equate_type_number_to_die (type
, array_die
);
17332 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17334 && info
->ndimensions
>= 2)
17335 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17337 if (info
->data_location
)
17338 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
17340 if (info
->associated
)
17341 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
17343 if (info
->allocated
)
17344 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
17347 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
17349 dw_die_ref subrange_die
17350 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17352 if (info
->dimen
[dim
].lower_bound
)
17354 /* If it is the default value, omit it. */
17357 if (tree_fits_shwi_p (info
->dimen
[dim
].lower_bound
)
17358 && (dflt
= lower_bound_default ()) != -1
17359 && tree_to_shwi (info
->dimen
[dim
].lower_bound
) == dflt
)
17362 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
17363 info
->dimen
[dim
].lower_bound
,
17366 if (info
->dimen
[dim
].upper_bound
)
17367 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
17368 info
->dimen
[dim
].upper_bound
,
17370 if (info
->dimen
[dim
].stride
)
17371 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
17372 info
->dimen
[dim
].stride
,
17376 gen_type_die (info
->element_type
, context_die
);
17377 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
17379 if (get_AT (array_die
, DW_AT_name
))
17380 add_pubtype (type
, array_die
);
17385 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
17387 tree origin
= decl_ultimate_origin (decl
);
17388 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
17390 if (origin
!= NULL
)
17391 add_abstract_origin_attribute (decl_die
, origin
);
17394 add_name_and_src_coords_attributes (decl_die
, decl
);
17395 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
17396 0, 0, context_die
);
17399 if (DECL_ABSTRACT (decl
))
17400 equate_decl_number_to_die (decl
, decl_die
);
17402 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
17406 /* Walk through the list of incomplete types again, trying once more to
17407 emit full debugging info for them. */
17410 retry_incomplete_types (void)
17414 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
17415 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
17416 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
17419 /* Determine what tag to use for a record type. */
17421 static enum dwarf_tag
17422 record_type_tag (tree type
)
17424 if (! lang_hooks
.types
.classify_record
)
17425 return DW_TAG_structure_type
;
17427 switch (lang_hooks
.types
.classify_record (type
))
17429 case RECORD_IS_STRUCT
:
17430 return DW_TAG_structure_type
;
17432 case RECORD_IS_CLASS
:
17433 return DW_TAG_class_type
;
17435 case RECORD_IS_INTERFACE
:
17436 if (dwarf_version
>= 3 || !dwarf_strict
)
17437 return DW_TAG_interface_type
;
17438 return DW_TAG_structure_type
;
17441 gcc_unreachable ();
17445 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17446 include all of the information about the enumeration values also. Each
17447 enumerated type name/value is listed as a child of the enumerated type
17451 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
17453 dw_die_ref type_die
= lookup_type_die (type
);
17455 if (type_die
== NULL
)
17457 type_die
= new_die (DW_TAG_enumeration_type
,
17458 scope_die_for (type
, context_die
), type
);
17459 equate_type_number_to_die (type
, type_die
);
17460 add_name_attribute (type_die
, type_tag (type
));
17461 if (dwarf_version
>= 4 || !dwarf_strict
)
17463 if (ENUM_IS_SCOPED (type
))
17464 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
17465 if (ENUM_IS_OPAQUE (type
))
17466 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17469 else if (! TYPE_SIZE (type
))
17472 remove_AT (type_die
, DW_AT_declaration
);
17474 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17475 given enum type is incomplete, do not generate the DW_AT_byte_size
17476 attribute or the DW_AT_element_list attribute. */
17477 if (TYPE_SIZE (type
))
17481 TREE_ASM_WRITTEN (type
) = 1;
17482 add_byte_size_attribute (type_die
, type
);
17483 if (dwarf_version
>= 3 || !dwarf_strict
)
17485 tree underlying
= lang_hooks
.types
.enum_underlying_base_type (type
);
17486 add_type_attribute (type_die
, underlying
, 0, 0, context_die
);
17488 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17490 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17491 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17494 /* If the first reference to this type was as the return type of an
17495 inline function, then it may not have a parent. Fix this now. */
17496 if (type_die
->die_parent
== NULL
)
17497 add_child_die (scope_die_for (type
, context_die
), type_die
);
17499 for (link
= TYPE_VALUES (type
);
17500 link
!= NULL
; link
= TREE_CHAIN (link
))
17502 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17503 tree value
= TREE_VALUE (link
);
17505 add_name_attribute (enum_die
,
17506 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17508 if (TREE_CODE (value
) == CONST_DECL
)
17509 value
= DECL_INITIAL (value
);
17511 if (simple_type_size_in_bits (TREE_TYPE (value
))
17512 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
17514 /* For constant forms created by add_AT_unsigned DWARF
17515 consumers (GDB, elfutils, etc.) always zero extend
17516 the value. Only when the actual value is negative
17517 do we need to use add_AT_int to generate a constant
17518 form that can represent negative values. */
17519 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
17520 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
17521 add_AT_unsigned (enum_die
, DW_AT_const_value
,
17522 (unsigned HOST_WIDE_INT
) val
);
17524 add_AT_int (enum_die
, DW_AT_const_value
, val
);
17527 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
17528 that here. TODO: This should be re-worked to use correct
17529 signed/unsigned double tags for all cases. */
17530 add_AT_wide (enum_die
, DW_AT_const_value
, value
);
17533 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17534 if (TYPE_ARTIFICIAL (type
))
17535 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17538 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17540 add_pubtype (type
, type_die
);
17545 /* Generate a DIE to represent either a real live formal parameter decl or to
17546 represent just the type of some formal parameter position in some function
17549 Note that this routine is a bit unusual because its argument may be a
17550 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17551 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17552 node. If it's the former then this function is being called to output a
17553 DIE to represent a formal parameter object (or some inlining thereof). If
17554 it's the latter, then this function is only being called to output a
17555 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17556 argument type of some subprogram type.
17557 If EMIT_NAME_P is true, name and source coordinate attributes
17561 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17562 dw_die_ref context_die
)
17564 tree node_or_origin
= node
? node
: origin
;
17565 tree ultimate_origin
;
17566 dw_die_ref parm_die
17567 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
17569 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
17571 case tcc_declaration
:
17572 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
17573 if (node
|| ultimate_origin
)
17574 origin
= ultimate_origin
;
17575 if (origin
!= NULL
)
17576 add_abstract_origin_attribute (parm_die
, origin
);
17577 else if (emit_name_p
)
17578 add_name_and_src_coords_attributes (parm_die
, node
);
17580 || (! DECL_ABSTRACT (node_or_origin
)
17581 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
17582 decl_function_context
17583 (node_or_origin
))))
17585 tree type
= TREE_TYPE (node_or_origin
);
17586 if (decl_by_reference_p (node_or_origin
))
17587 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
17590 add_type_attribute (parm_die
, type
,
17591 TREE_READONLY (node_or_origin
),
17592 TREE_THIS_VOLATILE (node_or_origin
),
17595 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
17596 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17598 if (node
&& node
!= origin
)
17599 equate_decl_number_to_die (node
, parm_die
);
17600 if (! DECL_ABSTRACT (node_or_origin
))
17601 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
17602 node
== NULL
, DW_AT_location
);
17607 /* We were called with some kind of a ..._TYPE node. */
17608 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
17612 gcc_unreachable ();
17618 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17619 children DW_TAG_formal_parameter DIEs representing the arguments of the
17622 PARM_PACK must be a function parameter pack.
17623 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17624 must point to the subsequent arguments of the function PACK_ARG belongs to.
17625 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17626 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17627 following the last one for which a DIE was generated. */
17630 gen_formal_parameter_pack_die (tree parm_pack
,
17632 dw_die_ref subr_die
,
17636 dw_die_ref parm_pack_die
;
17638 gcc_assert (parm_pack
17639 && lang_hooks
.function_parameter_pack_p (parm_pack
)
17642 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
17643 add_src_coords_attributes (parm_pack_die
, parm_pack
);
17645 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
17647 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
17650 gen_formal_parameter_die (arg
, NULL
,
17651 false /* Don't emit name attribute. */,
17656 return parm_pack_die
;
17659 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17660 at the end of an (ANSI prototyped) formal parameters list. */
17663 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
17665 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
17668 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17669 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17670 parameters as specified in some function type specification (except for
17671 those which appear as part of a function *definition*). */
17674 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
17677 tree formal_type
= NULL
;
17678 tree first_parm_type
;
17681 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
17683 arg
= DECL_ARGUMENTS (function_or_method_type
);
17684 function_or_method_type
= TREE_TYPE (function_or_method_type
);
17689 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
17691 /* Make our first pass over the list of formal parameter types and output a
17692 DW_TAG_formal_parameter DIE for each one. */
17693 for (link
= first_parm_type
; link
; )
17695 dw_die_ref parm_die
;
17697 formal_type
= TREE_VALUE (link
);
17698 if (formal_type
== void_type_node
)
17701 /* Output a (nameless) DIE to represent the formal parameter itself. */
17702 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
17703 true /* Emit name attribute. */,
17705 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
17706 && link
== first_parm_type
)
17708 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17709 if (dwarf_version
>= 3 || !dwarf_strict
)
17710 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
17712 else if (arg
&& DECL_ARTIFICIAL (arg
))
17713 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17715 link
= TREE_CHAIN (link
);
17717 arg
= DECL_CHAIN (arg
);
17720 /* If this function type has an ellipsis, add a
17721 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17722 if (formal_type
!= void_type_node
)
17723 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
17725 /* Make our second (and final) pass over the list of formal parameter types
17726 and output DIEs to represent those types (as necessary). */
17727 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
17728 link
&& TREE_VALUE (link
);
17729 link
= TREE_CHAIN (link
))
17730 gen_type_die (TREE_VALUE (link
), context_die
);
17733 /* We want to generate the DIE for TYPE so that we can generate the
17734 die for MEMBER, which has been defined; we will need to refer back
17735 to the member declaration nested within TYPE. If we're trying to
17736 generate minimal debug info for TYPE, processing TYPE won't do the
17737 trick; we need to attach the member declaration by hand. */
17740 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
17742 gen_type_die (type
, context_die
);
17744 /* If we're trying to avoid duplicate debug info, we may not have
17745 emitted the member decl for this function. Emit it now. */
17746 if (TYPE_STUB_DECL (type
)
17747 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
17748 && ! lookup_decl_die (member
))
17750 dw_die_ref type_die
;
17751 gcc_assert (!decl_ultimate_origin (member
));
17753 push_decl_scope (type
);
17754 type_die
= lookup_type_die_strip_naming_typedef (type
);
17755 if (TREE_CODE (member
) == FUNCTION_DECL
)
17756 gen_subprogram_die (member
, type_die
);
17757 else if (TREE_CODE (member
) == FIELD_DECL
)
17759 /* Ignore the nameless fields that are used to skip bits but handle
17760 C++ anonymous unions and structs. */
17761 if (DECL_NAME (member
) != NULL_TREE
17762 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
17763 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
17765 gen_type_die (member_declared_type (member
), type_die
);
17766 gen_field_die (member
, type_die
);
17770 gen_variable_die (member
, NULL_TREE
, type_die
);
17776 /* Forward declare these functions, because they are mutually recursive
17777 with their set_block_* pairing functions. */
17778 static void set_decl_origin_self (tree
);
17779 static void set_decl_abstract_flags (tree
, int);
17781 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
17782 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
17783 that it points to the node itself, thus indicating that the node is its
17784 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
17785 the given node is NULL, recursively descend the decl/block tree which
17786 it is the root of, and for each other ..._DECL or BLOCK node contained
17787 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
17788 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
17789 values to point to themselves. */
17792 set_block_origin_self (tree stmt
)
17794 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
17796 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
17801 for (local_decl
= BLOCK_VARS (stmt
);
17802 local_decl
!= NULL_TREE
;
17803 local_decl
= DECL_CHAIN (local_decl
))
17804 if (! DECL_EXTERNAL (local_decl
))
17805 set_decl_origin_self (local_decl
); /* Potential recursion. */
17811 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17812 subblock
!= NULL_TREE
;
17813 subblock
= BLOCK_CHAIN (subblock
))
17814 set_block_origin_self (subblock
); /* Recurse. */
17819 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
17820 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
17821 node to so that it points to the node itself, thus indicating that the
17822 node represents its own (abstract) origin. Additionally, if the
17823 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
17824 the decl/block tree of which the given node is the root of, and for
17825 each other ..._DECL or BLOCK node contained therein whose
17826 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
17827 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
17828 point to themselves. */
17831 set_decl_origin_self (tree decl
)
17833 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
17835 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
17836 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17840 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17841 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
17842 if (DECL_INITIAL (decl
) != NULL_TREE
17843 && DECL_INITIAL (decl
) != error_mark_node
)
17844 set_block_origin_self (DECL_INITIAL (decl
));
17849 /* Given a pointer to some BLOCK node, and a boolean value to set the
17850 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
17851 the given block, and for all local decls and all local sub-blocks
17852 (recursively) which are contained therein. */
17855 set_block_abstract_flags (tree stmt
, int setting
)
17861 BLOCK_ABSTRACT (stmt
) = setting
;
17863 for (local_decl
= BLOCK_VARS (stmt
);
17864 local_decl
!= NULL_TREE
;
17865 local_decl
= DECL_CHAIN (local_decl
))
17866 if (! DECL_EXTERNAL (local_decl
))
17867 set_decl_abstract_flags (local_decl
, setting
);
17869 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
17871 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
17872 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
17873 || TREE_CODE (local_decl
) == PARM_DECL
)
17874 set_decl_abstract_flags (local_decl
, setting
);
17877 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17878 subblock
!= NULL_TREE
;
17879 subblock
= BLOCK_CHAIN (subblock
))
17880 set_block_abstract_flags (subblock
, setting
);
17883 /* Given a pointer to some ..._DECL node, and a boolean value to set the
17884 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
17885 given decl, and (in the case where the decl is a FUNCTION_DECL) also
17886 set the abstract flags for all of the parameters, local vars, local
17887 blocks and sub-blocks (recursively) to the same setting. */
17890 set_decl_abstract_flags (tree decl
, int setting
)
17892 DECL_ABSTRACT (decl
) = setting
;
17893 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17897 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17898 DECL_ABSTRACT (arg
) = setting
;
17899 if (DECL_INITIAL (decl
) != NULL_TREE
17900 && DECL_INITIAL (decl
) != error_mark_node
)
17901 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
17905 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17906 may later generate inlined and/or out-of-line instances of. */
17909 dwarf2out_abstract_function (tree decl
)
17911 dw_die_ref old_die
;
17915 htab_t old_decl_loc_table
;
17916 htab_t old_cached_dw_loc_list_table
;
17917 int old_call_site_count
, old_tail_call_site_count
;
17918 struct call_arg_loc_node
*old_call_arg_locations
;
17920 /* Make sure we have the actual abstract inline, not a clone. */
17921 decl
= DECL_ORIGIN (decl
);
17923 old_die
= lookup_decl_die (decl
);
17924 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
17925 /* We've already generated the abstract instance. */
17928 /* We can be called while recursively when seeing block defining inlined subroutine
17929 DIE. Be sure to not clobber the outer location table nor use it or we would
17930 get locations in abstract instantces. */
17931 old_decl_loc_table
= decl_loc_table
;
17932 decl_loc_table
= NULL
;
17933 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
17934 cached_dw_loc_list_table
= NULL
;
17935 old_call_arg_locations
= call_arg_locations
;
17936 call_arg_locations
= NULL
;
17937 old_call_site_count
= call_site_count
;
17938 call_site_count
= -1;
17939 old_tail_call_site_count
= tail_call_site_count
;
17940 tail_call_site_count
= -1;
17942 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17943 we don't get confused by DECL_ABSTRACT. */
17944 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17946 context
= decl_class_context (decl
);
17948 gen_type_die_for_member
17949 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
17952 /* Pretend we've just finished compiling this function. */
17953 save_fn
= current_function_decl
;
17954 current_function_decl
= decl
;
17956 was_abstract
= DECL_ABSTRACT (decl
);
17957 set_decl_abstract_flags (decl
, 1);
17958 dwarf2out_decl (decl
);
17959 if (! was_abstract
)
17960 set_decl_abstract_flags (decl
, 0);
17962 current_function_decl
= save_fn
;
17963 decl_loc_table
= old_decl_loc_table
;
17964 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
17965 call_arg_locations
= old_call_arg_locations
;
17966 call_site_count
= old_call_site_count
;
17967 tail_call_site_count
= old_tail_call_site_count
;
17970 /* Helper function of premark_used_types() which gets called through
17973 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17974 marked as unused by prune_unused_types. */
17977 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
17982 type
= (tree
) *slot
;
17983 die
= lookup_type_die (type
);
17985 die
->die_perennial_p
= 1;
17989 /* Helper function of premark_types_used_by_global_vars which gets called
17990 through htab_traverse.
17992 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17993 marked as unused by prune_unused_types. The DIE of the type is marked
17994 only if the global variable using the type will actually be emitted. */
17997 premark_types_used_by_global_vars_helper (void **slot
,
17998 void *data ATTRIBUTE_UNUSED
)
18000 struct types_used_by_vars_entry
*entry
;
18003 entry
= (struct types_used_by_vars_entry
*) *slot
;
18004 gcc_assert (entry
->type
!= NULL
18005 && entry
->var_decl
!= NULL
);
18006 die
= lookup_type_die (entry
->type
);
18009 /* Ask cgraph if the global variable really is to be emitted.
18010 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18011 varpool_node
*node
= varpool_node::get (entry
->var_decl
);
18012 if (node
&& node
->definition
)
18014 die
->die_perennial_p
= 1;
18015 /* Keep the parent DIEs as well. */
18016 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
18017 die
->die_perennial_p
= 1;
18023 /* Mark all members of used_types_hash as perennial. */
18026 premark_used_types (struct function
*fun
)
18028 if (fun
&& fun
->used_types_hash
)
18029 htab_traverse (fun
->used_types_hash
, premark_used_types_helper
, NULL
);
18032 /* Mark all members of types_used_by_vars_entry as perennial. */
18035 premark_types_used_by_global_vars (void)
18037 if (types_used_by_vars_hash
)
18038 htab_traverse (types_used_by_vars_hash
,
18039 premark_types_used_by_global_vars_helper
, NULL
);
18042 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
18043 for CA_LOC call arg loc node. */
18046 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
18047 struct call_arg_loc_node
*ca_loc
)
18049 dw_die_ref stmt_die
= NULL
, die
;
18050 tree block
= ca_loc
->block
;
18053 && block
!= DECL_INITIAL (decl
)
18054 && TREE_CODE (block
) == BLOCK
)
18056 if (block_map
.length () > BLOCK_NUMBER (block
))
18057 stmt_die
= block_map
[BLOCK_NUMBER (block
)];
18060 block
= BLOCK_SUPERCONTEXT (block
);
18062 if (stmt_die
== NULL
)
18063 stmt_die
= subr_die
;
18064 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
18065 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
18066 if (ca_loc
->tail_call_p
)
18067 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
18068 if (ca_loc
->symbol_ref
)
18070 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
18072 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
18074 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
18079 /* Generate a DIE to represent a declared function (either file-scope or
18083 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
18085 tree origin
= decl_ultimate_origin (decl
);
18086 dw_die_ref subr_die
;
18088 dw_die_ref old_die
= lookup_decl_die (decl
);
18089 int declaration
= (current_function_decl
!= decl
18090 || class_or_namespace_scope_p (context_die
));
18092 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
18094 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
18095 started to generate the abstract instance of an inline, decided to output
18096 its containing class, and proceeded to emit the declaration of the inline
18097 from the member list for the class. If so, DECLARATION takes priority;
18098 we'll get back to the abstract instance when done with the class. */
18100 /* The class-scope declaration DIE must be the primary DIE. */
18101 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
18104 gcc_assert (!old_die
);
18107 /* Now that the C++ front end lazily declares artificial member fns, we
18108 might need to retrofit the declaration into its class. */
18109 if (!declaration
&& !origin
&& !old_die
18110 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
18111 && !class_or_namespace_scope_p (context_die
)
18112 && debug_info_level
> DINFO_LEVEL_TERSE
)
18113 old_die
= force_decl_die (decl
);
18115 if (origin
!= NULL
)
18117 gcc_assert (!declaration
|| local_scope_p (context_die
));
18119 /* Fixup die_parent for the abstract instance of a nested
18120 inline function. */
18121 if (old_die
&& old_die
->die_parent
== NULL
)
18122 add_child_die (context_die
, old_die
);
18124 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18125 add_abstract_origin_attribute (subr_die
, origin
);
18126 /* This is where the actual code for a cloned function is.
18127 Let's emit linkage name attribute for it. This helps
18128 debuggers to e.g, set breakpoints into
18129 constructors/destructors when the user asks "break
18131 add_linkage_name (subr_die
, decl
);
18135 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18136 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18138 if (!get_AT_flag (old_die
, DW_AT_declaration
)
18139 /* We can have a normal definition following an inline one in the
18140 case of redefinition of GNU C extern inlines.
18141 It seems reasonable to use AT_specification in this case. */
18142 && !get_AT (old_die
, DW_AT_inline
))
18144 /* Detect and ignore this case, where we are trying to output
18145 something we have already output. */
18149 /* If the definition comes from the same place as the declaration,
18150 maybe use the old DIE. We always want the DIE for this function
18151 that has the *_pc attributes to be under comp_unit_die so the
18152 debugger can find it. We also need to do this for abstract
18153 instances of inlines, since the spec requires the out-of-line copy
18154 to have the same parent. For local class methods, this doesn't
18155 apply; we just use the old DIE. */
18156 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
18157 && (DECL_ARTIFICIAL (decl
)
18158 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
18159 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
18160 == (unsigned) s
.line
))))
18162 subr_die
= old_die
;
18164 /* Clear out the declaration attribute and the formal parameters.
18165 Do not remove all children, because it is possible that this
18166 declaration die was forced using force_decl_die(). In such
18167 cases die that forced declaration die (e.g. TAG_imported_module)
18168 is one of the children that we do not want to remove. */
18169 remove_AT (subr_die
, DW_AT_declaration
);
18170 remove_AT (subr_die
, DW_AT_object_pointer
);
18171 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
18175 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18176 add_AT_specification (subr_die
, old_die
);
18177 add_pubname (decl
, subr_die
);
18178 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18179 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
18180 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18181 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
18183 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
18184 emit the real type on the definition die. */
18185 if (is_cxx() && debug_info_level
> DINFO_LEVEL_TERSE
)
18187 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
18188 if (die
== auto_die
|| die
== decltype_auto_die
)
18189 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18190 0, 0, context_die
);
18196 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18198 if (TREE_PUBLIC (decl
))
18199 add_AT_flag (subr_die
, DW_AT_external
, 1);
18201 add_name_and_src_coords_attributes (subr_die
, decl
);
18202 add_pubname (decl
, subr_die
);
18203 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18205 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
18206 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18207 0, 0, context_die
);
18210 add_pure_or_virtual_attribute (subr_die
, decl
);
18211 if (DECL_ARTIFICIAL (decl
))
18212 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18214 add_accessibility_attribute (subr_die
, decl
);
18219 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18221 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
18223 /* If this is an explicit function declaration then generate
18224 a DW_AT_explicit attribute. */
18225 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
18226 && (dwarf_version
>= 3 || !dwarf_strict
))
18227 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
18229 /* The first time we see a member function, it is in the context of
18230 the class to which it belongs. We make sure of this by emitting
18231 the class first. The next time is the definition, which is
18232 handled above. The two may come from the same source text.
18234 Note that force_decl_die() forces function declaration die. It is
18235 later reused to represent definition. */
18236 equate_decl_number_to_die (decl
, subr_die
);
18239 else if (DECL_ABSTRACT (decl
))
18241 if (DECL_DECLARED_INLINE_P (decl
))
18243 if (cgraph_function_possibly_inlined_p (decl
))
18244 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
18246 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
18250 if (cgraph_function_possibly_inlined_p (decl
))
18251 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
18253 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
18256 if (DECL_DECLARED_INLINE_P (decl
)
18257 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
18258 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18260 equate_decl_number_to_die (decl
, subr_die
);
18262 else if (!DECL_EXTERNAL (decl
))
18264 HOST_WIDE_INT cfa_fb_offset
;
18265 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
18267 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18268 equate_decl_number_to_die (decl
, subr_die
);
18270 gcc_checking_assert (fun
);
18271 if (!flag_reorder_blocks_and_partition
)
18273 dw_fde_ref fde
= fun
->fde
;
18274 if (fde
->dw_fde_begin
)
18276 /* We have already generated the labels. */
18277 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18278 fde
->dw_fde_end
, false);
18282 /* Create start/end labels and add the range. */
18283 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
18284 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18285 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
18286 current_function_funcdef_no
);
18287 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
18288 current_function_funcdef_no
);
18289 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
18293 #if VMS_DEBUGGING_INFO
18294 /* HP OpenVMS Industry Standard 64: DWARF Extensions
18295 Section 2.3 Prologue and Epilogue Attributes:
18296 When a breakpoint is set on entry to a function, it is generally
18297 desirable for execution to be suspended, not on the very first
18298 instruction of the function, but rather at a point after the
18299 function's frame has been set up, after any language defined local
18300 declaration processing has been completed, and before execution of
18301 the first statement of the function begins. Debuggers generally
18302 cannot properly determine where this point is. Similarly for a
18303 breakpoint set on exit from a function. The prologue and epilogue
18304 attributes allow a compiler to communicate the location(s) to use. */
18307 if (fde
->dw_fde_vms_end_prologue
)
18308 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
18309 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
18311 if (fde
->dw_fde_vms_begin_epilogue
)
18312 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
18313 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
18320 /* Generate pubnames entries for the split function code ranges. */
18321 dw_fde_ref fde
= fun
->fde
;
18323 if (fde
->dw_fde_second_begin
)
18325 if (dwarf_version
>= 3 || !dwarf_strict
)
18327 /* We should use ranges for non-contiguous code section
18328 addresses. Use the actual code range for the initial
18329 section, since the HOT/COLD labels might precede an
18330 alignment offset. */
18331 bool range_list_added
= false;
18332 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
18333 fde
->dw_fde_end
, &range_list_added
,
18335 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
18336 fde
->dw_fde_second_end
,
18337 &range_list_added
, false);
18338 if (range_list_added
)
18343 /* There is no real support in DW2 for this .. so we make
18344 a work-around. First, emit the pub name for the segment
18345 containing the function label. Then make and emit a
18346 simplified subprogram DIE for the second segment with the
18347 name pre-fixed by __hot/cold_sect_of_. We use the same
18348 linkage name for the second die so that gdb will find both
18349 sections when given "b foo". */
18350 const char *name
= NULL
;
18351 tree decl_name
= DECL_NAME (decl
);
18352 dw_die_ref seg_die
;
18354 /* Do the 'primary' section. */
18355 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18356 fde
->dw_fde_end
, false);
18358 /* Build a minimal DIE for the secondary section. */
18359 seg_die
= new_die (DW_TAG_subprogram
,
18360 subr_die
->die_parent
, decl
);
18362 if (TREE_PUBLIC (decl
))
18363 add_AT_flag (seg_die
, DW_AT_external
, 1);
18365 if (decl_name
!= NULL
18366 && IDENTIFIER_POINTER (decl_name
) != NULL
)
18368 name
= dwarf2_name (decl
, 1);
18369 if (! DECL_ARTIFICIAL (decl
))
18370 add_src_coords_attributes (seg_die
, decl
);
18372 add_linkage_name (seg_die
, decl
);
18374 gcc_assert (name
!= NULL
);
18375 add_pure_or_virtual_attribute (seg_die
, decl
);
18376 if (DECL_ARTIFICIAL (decl
))
18377 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
18379 name
= concat ("__second_sect_of_", name
, NULL
);
18380 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
18381 fde
->dw_fde_second_end
, false);
18382 add_name_attribute (seg_die
, name
);
18383 if (want_pubnames ())
18384 add_pubname_string (name
, seg_die
);
18388 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
18392 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
18394 /* We define the "frame base" as the function's CFA. This is more
18395 convenient for several reasons: (1) It's stable across the prologue
18396 and epilogue, which makes it better than just a frame pointer,
18397 (2) With dwarf3, there exists a one-byte encoding that allows us
18398 to reference the .debug_frame data by proxy, but failing that,
18399 (3) We can at least reuse the code inspection and interpretation
18400 code that determines the CFA position at various points in the
18402 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
18404 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
18405 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
18409 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
18410 if (list
->dw_loc_next
)
18411 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
18413 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
18416 /* Compute a displacement from the "steady-state frame pointer" to
18417 the CFA. The former is what all stack slots and argument slots
18418 will reference in the rtl; the latter is what we've told the
18419 debugger about. We'll need to adjust all frame_base references
18420 by this displacement. */
18421 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
18423 if (fun
->static_chain_decl
)
18424 add_AT_location_description (subr_die
, DW_AT_static_link
,
18425 loc_list_from_tree (fun
->static_chain_decl
, 2));
18428 /* Generate child dies for template paramaters. */
18429 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18430 gen_generic_params_dies (decl
);
18432 /* Now output descriptions of the arguments for this function. This gets
18433 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
18434 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
18435 `...' at the end of the formal parameter list. In order to find out if
18436 there was a trailing ellipsis or not, we must instead look at the type
18437 associated with the FUNCTION_DECL. This will be a node of type
18438 FUNCTION_TYPE. If the chain of type nodes hanging off of this
18439 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
18440 an ellipsis at the end. */
18442 /* In the case where we are describing a mere function declaration, all we
18443 need to do here (and all we *can* do here) is to describe the *types* of
18444 its formal parameters. */
18445 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
18447 else if (declaration
)
18448 gen_formal_types_die (decl
, subr_die
);
18451 /* Generate DIEs to represent all known formal parameters. */
18452 tree parm
= DECL_ARGUMENTS (decl
);
18453 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
18454 tree generic_decl_parm
= generic_decl
18455 ? DECL_ARGUMENTS (generic_decl
)
18458 /* Now we want to walk the list of parameters of the function and
18459 emit their relevant DIEs.
18461 We consider the case of DECL being an instance of a generic function
18462 as well as it being a normal function.
18464 If DECL is an instance of a generic function we walk the
18465 parameters of the generic function declaration _and_ the parameters of
18466 DECL itself. This is useful because we want to emit specific DIEs for
18467 function parameter packs and those are declared as part of the
18468 generic function declaration. In that particular case,
18469 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
18470 That DIE has children DIEs representing the set of arguments
18471 of the pack. Note that the set of pack arguments can be empty.
18472 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
18475 Otherwise, we just consider the parameters of DECL. */
18476 while (generic_decl_parm
|| parm
)
18478 if (generic_decl_parm
18479 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
18480 gen_formal_parameter_pack_die (generic_decl_parm
,
18485 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
18487 if (parm
== DECL_ARGUMENTS (decl
)
18488 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
18490 && (dwarf_version
>= 3 || !dwarf_strict
))
18491 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
18493 parm
= DECL_CHAIN (parm
);
18496 if (generic_decl_parm
)
18497 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
18500 /* Decide whether we need an unspecified_parameters DIE at the end.
18501 There are 2 more cases to do this for: 1) the ansi ... declaration -
18502 this is detectable when the end of the arg list is not a
18503 void_type_node 2) an unprototyped function declaration (not a
18504 definition). This just means that we have no info about the
18505 parameters at all. */
18506 if (prototype_p (TREE_TYPE (decl
)))
18508 /* This is the prototyped case, check for.... */
18509 if (stdarg_p (TREE_TYPE (decl
)))
18510 gen_unspecified_parameters_die (decl
, subr_die
);
18512 else if (DECL_INITIAL (decl
) == NULL_TREE
)
18513 gen_unspecified_parameters_die (decl
, subr_die
);
18516 /* Output Dwarf info for all of the stuff within the body of the function
18517 (if it has one - it may be just a declaration). */
18518 outer_scope
= DECL_INITIAL (decl
);
18520 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
18521 a function. This BLOCK actually represents the outermost binding contour
18522 for the function, i.e. the contour in which the function's formal
18523 parameters and labels get declared. Curiously, it appears that the front
18524 end doesn't actually put the PARM_DECL nodes for the current function onto
18525 the BLOCK_VARS list for this outer scope, but are strung off of the
18526 DECL_ARGUMENTS list for the function instead.
18528 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
18529 the LABEL_DECL nodes for the function however, and we output DWARF info
18530 for those in decls_for_scope. Just within the `outer_scope' there will be
18531 a BLOCK node representing the function's outermost pair of curly braces,
18532 and any blocks used for the base and member initializers of a C++
18533 constructor function. */
18534 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
18536 int call_site_note_count
= 0;
18537 int tail_call_site_note_count
= 0;
18539 /* Emit a DW_TAG_variable DIE for a named return value. */
18540 if (DECL_NAME (DECL_RESULT (decl
)))
18541 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
18543 current_function_has_inlines
= 0;
18544 decls_for_scope (outer_scope
, subr_die
, 0);
18546 if (call_arg_locations
&& !dwarf_strict
)
18548 struct call_arg_loc_node
*ca_loc
;
18549 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
18551 dw_die_ref die
= NULL
;
18552 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
18555 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
18556 arg
; arg
= next_arg
)
18558 dw_loc_descr_ref reg
, val
;
18559 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
18560 dw_die_ref cdie
, tdie
= NULL
;
18562 next_arg
= XEXP (arg
, 1);
18563 if (REG_P (XEXP (XEXP (arg
, 0), 0))
18565 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
18566 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
18567 && REGNO (XEXP (XEXP (arg
, 0), 0))
18568 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
18569 next_arg
= XEXP (next_arg
, 1);
18570 if (mode
== VOIDmode
)
18572 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
18573 if (mode
== VOIDmode
)
18574 mode
= GET_MODE (XEXP (arg
, 0));
18576 if (mode
== VOIDmode
|| mode
== BLKmode
)
18578 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
18580 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18581 tloc
= XEXP (XEXP (arg
, 0), 1);
18584 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
18585 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
18587 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18588 tlocc
= XEXP (XEXP (arg
, 0), 1);
18592 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
18593 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
18594 VAR_INIT_STATUS_INITIALIZED
);
18595 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
18597 rtx mem
= XEXP (XEXP (arg
, 0), 0);
18598 reg
= mem_loc_descriptor (XEXP (mem
, 0),
18599 get_address_mode (mem
),
18601 VAR_INIT_STATUS_INITIALIZED
);
18603 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
18604 == DEBUG_PARAMETER_REF
)
18607 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
18608 tdie
= lookup_decl_die (tdecl
);
18615 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
18616 != DEBUG_PARAMETER_REF
)
18618 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
18620 VAR_INIT_STATUS_INITIALIZED
);
18624 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18625 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
18628 add_AT_loc (cdie
, DW_AT_location
, reg
);
18629 else if (tdie
!= NULL
)
18630 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
18631 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
18632 if (next_arg
!= XEXP (arg
, 1))
18634 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
18635 if (mode
== VOIDmode
)
18636 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
18637 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
18640 VAR_INIT_STATUS_INITIALIZED
);
18642 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
18646 && (ca_loc
->symbol_ref
|| tloc
))
18647 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18648 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
18650 dw_loc_descr_ref tval
= NULL
;
18652 if (tloc
!= NULL_RTX
)
18653 tval
= mem_loc_descriptor (tloc
,
18654 GET_MODE (tloc
) == VOIDmode
18655 ? Pmode
: GET_MODE (tloc
),
18657 VAR_INIT_STATUS_INITIALIZED
);
18659 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
18660 else if (tlocc
!= NULL_RTX
)
18662 tval
= mem_loc_descriptor (tlocc
,
18663 GET_MODE (tlocc
) == VOIDmode
18664 ? Pmode
: GET_MODE (tlocc
),
18666 VAR_INIT_STATUS_INITIALIZED
);
18668 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
18674 call_site_note_count
++;
18675 if (ca_loc
->tail_call_p
)
18676 tail_call_site_note_count
++;
18680 call_arg_locations
= NULL
;
18681 call_arg_loc_last
= NULL
;
18682 if (tail_call_site_count
>= 0
18683 && tail_call_site_count
== tail_call_site_note_count
18686 if (call_site_count
>= 0
18687 && call_site_count
== call_site_note_count
)
18688 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
18690 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
18692 call_site_count
= -1;
18693 tail_call_site_count
= -1;
18696 if (subr_die
!= old_die
)
18697 /* Add the calling convention attribute if requested. */
18698 add_calling_convention_attribute (subr_die
, decl
);
18701 /* Returns a hash value for X (which really is a die_struct). */
18704 common_block_die_table_hash (const void *x
)
18706 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18707 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
18710 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18711 as decl_id and die_parent of die_struct Y. */
18714 common_block_die_table_eq (const void *x
, const void *y
)
18716 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18717 const_dw_die_ref e
= (const_dw_die_ref
) y
;
18718 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
18721 /* Generate a DIE to represent a declared data object.
18722 Either DECL or ORIGIN must be non-null. */
18725 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
18727 HOST_WIDE_INT off
= 0;
18729 tree decl_or_origin
= decl
? decl
: origin
;
18730 tree ultimate_origin
;
18731 dw_die_ref var_die
;
18732 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
18733 dw_die_ref origin_die
;
18734 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
18735 || class_or_namespace_scope_p (context_die
));
18736 bool specialization_p
= false;
18738 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
18739 if (decl
|| ultimate_origin
)
18740 origin
= ultimate_origin
;
18741 com_decl
= fortran_common (decl_or_origin
, &off
);
18743 /* Symbol in common gets emitted as a child of the common block, in the form
18744 of a data member. */
18747 dw_die_ref com_die
;
18748 dw_loc_list_ref loc
;
18749 die_node com_die_arg
;
18751 var_die
= lookup_decl_die (decl_or_origin
);
18754 if (get_AT (var_die
, DW_AT_location
) == NULL
)
18756 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
18761 /* Optimize the common case. */
18762 if (single_element_loc_list_p (loc
)
18763 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18764 && loc
->expr
->dw_loc_next
== NULL
18765 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
18768 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18769 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18770 = plus_constant (GET_MODE (x
), x
, off
);
18773 loc_list_plus_const (loc
, off
);
18775 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18776 remove_AT (var_die
, DW_AT_declaration
);
18782 if (common_block_die_table
== NULL
)
18783 common_block_die_table
18784 = htab_create_ggc (10, common_block_die_table_hash
,
18785 common_block_die_table_eq
, NULL
);
18787 com_die_arg
.decl_id
= DECL_UID (com_decl
);
18788 com_die_arg
.die_parent
= context_die
;
18789 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
18790 loc
= loc_list_from_tree (com_decl
, 2);
18791 if (com_die
== NULL
)
18794 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
18797 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
18798 add_name_and_src_coords_attributes (com_die
, com_decl
);
18801 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18802 /* Avoid sharing the same loc descriptor between
18803 DW_TAG_common_block and DW_TAG_variable. */
18804 loc
= loc_list_from_tree (com_decl
, 2);
18806 else if (DECL_EXTERNAL (decl
))
18807 add_AT_flag (com_die
, DW_AT_declaration
, 1);
18808 if (want_pubnames ())
18809 add_pubname_string (cnam
, com_die
); /* ??? needed? */
18810 com_die
->decl_id
= DECL_UID (com_decl
);
18811 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
18812 *slot
= (void *) com_die
;
18814 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
18816 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18817 loc
= loc_list_from_tree (com_decl
, 2);
18818 remove_AT (com_die
, DW_AT_declaration
);
18820 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
18821 add_name_and_src_coords_attributes (var_die
, decl
);
18822 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
18823 TREE_THIS_VOLATILE (decl
), context_die
);
18824 add_AT_flag (var_die
, DW_AT_external
, 1);
18829 /* Optimize the common case. */
18830 if (single_element_loc_list_p (loc
)
18831 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18832 && loc
->expr
->dw_loc_next
== NULL
18833 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
18835 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18836 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18837 = plus_constant (GET_MODE (x
), x
, off
);
18840 loc_list_plus_const (loc
, off
);
18842 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18844 else if (DECL_EXTERNAL (decl
))
18845 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18846 equate_decl_number_to_die (decl
, var_die
);
18850 /* If the compiler emitted a definition for the DECL declaration
18851 and if we already emitted a DIE for it, don't emit a second
18852 DIE for it again. Allow re-declarations of DECLs that are
18853 inside functions, though. */
18854 if (old_die
&& declaration
&& !local_scope_p (context_die
))
18857 /* For static data members, the declaration in the class is supposed
18858 to have DW_TAG_member tag; the specification should still be
18859 DW_TAG_variable referencing the DW_TAG_member DIE. */
18860 if (declaration
&& class_scope_p (context_die
))
18861 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
18863 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
18866 if (origin
!= NULL
)
18867 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
18869 /* Loop unrolling can create multiple blocks that refer to the same
18870 static variable, so we must test for the DW_AT_declaration flag.
18872 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18873 copy decls and set the DECL_ABSTRACT flag on them instead of
18876 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18878 ??? The declare_in_namespace support causes us to get two DIEs for one
18879 variable, both of which are declarations. We want to avoid considering
18880 one to be a specification, so we must test that this DIE is not a
18882 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
18883 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
18885 /* This is a definition of a C++ class level static. */
18886 add_AT_specification (var_die
, old_die
);
18887 specialization_p
= true;
18888 if (DECL_NAME (decl
))
18890 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18891 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18893 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18894 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
18896 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18897 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
18899 if (old_die
->die_tag
== DW_TAG_member
)
18900 add_linkage_name (var_die
, decl
);
18904 add_name_and_src_coords_attributes (var_die
, decl
);
18906 if ((origin
== NULL
&& !specialization_p
)
18908 && !DECL_ABSTRACT (decl_or_origin
)
18909 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
18910 decl_function_context
18911 (decl_or_origin
))))
18913 tree type
= TREE_TYPE (decl_or_origin
);
18915 if (decl_by_reference_p (decl_or_origin
))
18916 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
18918 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
18919 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
18922 if (origin
== NULL
&& !specialization_p
)
18924 if (TREE_PUBLIC (decl
))
18925 add_AT_flag (var_die
, DW_AT_external
, 1);
18927 if (DECL_ARTIFICIAL (decl
))
18928 add_AT_flag (var_die
, DW_AT_artificial
, 1);
18930 add_accessibility_attribute (var_die
, decl
);
18934 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18936 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
18937 equate_decl_number_to_die (decl
, var_die
);
18940 && (! DECL_ABSTRACT (decl_or_origin
)
18941 /* Local static vars are shared between all clones/inlines,
18942 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18944 || (TREE_CODE (decl_or_origin
) == VAR_DECL
18945 && TREE_STATIC (decl_or_origin
)
18946 && DECL_RTL_SET_P (decl_or_origin
)))
18947 /* When abstract origin already has DW_AT_location attribute, no need
18948 to add it again. */
18949 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
18951 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
18952 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
18953 defer_location (decl_or_origin
, var_die
);
18955 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
18956 decl
== NULL
, DW_AT_location
);
18957 add_pubname (decl_or_origin
, var_die
);
18960 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
18963 /* Generate a DIE to represent a named constant. */
18966 gen_const_die (tree decl
, dw_die_ref context_die
)
18968 dw_die_ref const_die
;
18969 tree type
= TREE_TYPE (decl
);
18971 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
18972 add_name_and_src_coords_attributes (const_die
, decl
);
18973 add_type_attribute (const_die
, type
, 1, 0, context_die
);
18974 if (TREE_PUBLIC (decl
))
18975 add_AT_flag (const_die
, DW_AT_external
, 1);
18976 if (DECL_ARTIFICIAL (decl
))
18977 add_AT_flag (const_die
, DW_AT_artificial
, 1);
18978 tree_add_const_value_attribute_for_decl (const_die
, decl
);
18981 /* Generate a DIE to represent a label identifier. */
18984 gen_label_die (tree decl
, dw_die_ref context_die
)
18986 tree origin
= decl_ultimate_origin (decl
);
18987 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
18989 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18991 if (origin
!= NULL
)
18992 add_abstract_origin_attribute (lbl_die
, origin
);
18994 add_name_and_src_coords_attributes (lbl_die
, decl
);
18996 if (DECL_ABSTRACT (decl
))
18997 equate_decl_number_to_die (decl
, lbl_die
);
19000 insn
= DECL_RTL_IF_SET (decl
);
19002 /* Deleted labels are programmer specified labels which have been
19003 eliminated because of various optimizations. We still emit them
19004 here so that it is possible to put breakpoints on them. */
19008 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
19010 /* When optimization is enabled (via -O) some parts of the compiler
19011 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19012 represent source-level labels which were explicitly declared by
19013 the user. This really shouldn't be happening though, so catch
19014 it if it ever does happen. */
19015 gcc_assert (!INSN_DELETED_P (insn
));
19017 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
19018 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19022 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
19023 && CODE_LABEL_NUMBER (insn
) != -1)
19025 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
19026 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19031 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19032 attributes to the DIE for a block STMT, to describe where the inlined
19033 function was called from. This is similar to add_src_coords_attributes. */
19036 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
19038 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
19040 if (dwarf_version
>= 3 || !dwarf_strict
)
19042 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
19043 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
19048 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19049 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19052 add_high_low_attributes (tree stmt
, dw_die_ref die
)
19054 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19056 if (BLOCK_FRAGMENT_CHAIN (stmt
)
19057 && (dwarf_version
>= 3 || !dwarf_strict
))
19059 tree chain
, superblock
= NULL_TREE
;
19061 dw_attr_ref attr
= NULL
;
19063 if (inlined_function_outer_scope_p (stmt
))
19065 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19066 BLOCK_NUMBER (stmt
));
19067 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
19070 /* Optimize duplicate .debug_ranges lists or even tails of
19071 lists. If this BLOCK has same ranges as its supercontext,
19072 lookup DW_AT_ranges attribute in the supercontext (and
19073 recursively so), verify that the ranges_table contains the
19074 right values and use it instead of adding a new .debug_range. */
19075 for (chain
= stmt
, pdie
= die
;
19076 BLOCK_SAME_RANGE (chain
);
19077 chain
= BLOCK_SUPERCONTEXT (chain
))
19079 dw_attr_ref new_attr
;
19081 pdie
= pdie
->die_parent
;
19084 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
19086 new_attr
= get_AT (pdie
, DW_AT_ranges
);
19087 if (new_attr
== NULL
19088 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
19091 superblock
= BLOCK_SUPERCONTEXT (chain
);
19094 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
19095 / 2 / DWARF2_ADDR_SIZE
].num
19096 == BLOCK_NUMBER (superblock
))
19097 && BLOCK_FRAGMENT_CHAIN (superblock
))
19099 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
19100 / 2 / DWARF2_ADDR_SIZE
;
19101 unsigned long supercnt
= 0, thiscnt
= 0;
19102 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
19103 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
19106 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
19107 == BLOCK_NUMBER (chain
));
19109 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
19110 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19111 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
19113 gcc_assert (supercnt
>= thiscnt
);
19114 add_AT_range_list (die
, DW_AT_ranges
,
19115 ((off
+ supercnt
- thiscnt
)
19116 * 2 * DWARF2_ADDR_SIZE
),
19121 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
19123 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19126 add_ranges (chain
);
19127 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
19134 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
19135 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19136 BLOCK_NUMBER (stmt
));
19137 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
19138 BLOCK_NUMBER (stmt
));
19139 add_AT_low_high_pc (die
, label
, label_high
, false);
19143 /* Generate a DIE for a lexical block. */
19146 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19148 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
19150 if (call_arg_locations
)
19152 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
19153 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
19154 block_map
[BLOCK_NUMBER (stmt
)] = stmt_die
;
19157 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
19158 add_high_low_attributes (stmt
, stmt_die
);
19160 decls_for_scope (stmt
, stmt_die
, depth
);
19163 /* Generate a DIE for an inlined subprogram. */
19166 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
19170 /* The instance of function that is effectively being inlined shall not
19172 gcc_assert (! BLOCK_ABSTRACT (stmt
));
19174 decl
= block_ultimate_origin (stmt
);
19176 /* Emit info for the abstract instance first, if we haven't yet. We
19177 must emit this even if the block is abstract, otherwise when we
19178 emit the block below (or elsewhere), we may end up trying to emit
19179 a die whose origin die hasn't been emitted, and crashing. */
19180 dwarf2out_abstract_function (decl
);
19182 if (! BLOCK_ABSTRACT (stmt
))
19184 dw_die_ref subr_die
19185 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
19187 if (call_arg_locations
)
19189 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
19190 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
19191 block_map
[BLOCK_NUMBER (stmt
)] = subr_die
;
19193 add_abstract_origin_attribute (subr_die
, decl
);
19194 if (TREE_ASM_WRITTEN (stmt
))
19195 add_high_low_attributes (stmt
, subr_die
);
19196 add_call_src_coords_attributes (stmt
, subr_die
);
19198 decls_for_scope (stmt
, subr_die
, depth
);
19199 current_function_has_inlines
= 1;
19203 /* Generate a DIE for a field in a record, or structure. */
19206 gen_field_die (tree decl
, dw_die_ref context_die
)
19208 dw_die_ref decl_die
;
19210 if (TREE_TYPE (decl
) == error_mark_node
)
19213 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
19214 add_name_and_src_coords_attributes (decl_die
, decl
);
19215 add_type_attribute (decl_die
, member_declared_type (decl
),
19216 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
19219 if (DECL_BIT_FIELD_TYPE (decl
))
19221 add_byte_size_attribute (decl_die
, decl
);
19222 add_bit_size_attribute (decl_die
, decl
);
19223 add_bit_offset_attribute (decl_die
, decl
);
19226 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
19227 add_data_member_location_attribute (decl_die
, decl
);
19229 if (DECL_ARTIFICIAL (decl
))
19230 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19232 add_accessibility_attribute (decl_die
, decl
);
19234 /* Equate decl number to die, so that we can look up this decl later on. */
19235 equate_decl_number_to_die (decl
, decl_die
);
19239 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19240 Use modified_type_die instead.
19241 We keep this code here just in case these types of DIEs may be needed to
19242 represent certain things in other languages (e.g. Pascal) someday. */
19245 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
19248 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
19250 equate_type_number_to_die (type
, ptr_die
);
19251 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19252 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19255 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19256 Use modified_type_die instead.
19257 We keep this code here just in case these types of DIEs may be needed to
19258 represent certain things in other languages (e.g. Pascal) someday. */
19261 gen_reference_type_die (tree type
, dw_die_ref context_die
)
19263 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
19265 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
19266 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
19268 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
19270 equate_type_number_to_die (type
, ref_die
);
19271 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
19272 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19276 /* Generate a DIE for a pointer to a member type. */
19279 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
19282 = new_die (DW_TAG_ptr_to_member_type
,
19283 scope_die_for (type
, context_die
), type
);
19285 equate_type_number_to_die (type
, ptr_die
);
19286 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
19287 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
19288 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19291 typedef const char *dchar_p
; /* For DEF_VEC_P. */
19293 static char *producer_string
;
19295 /* Return a heap allocated producer string including command line options
19296 if -grecord-gcc-switches. */
19299 gen_producer_string (void)
19302 auto_vec
<dchar_p
> switches
;
19303 const char *language_string
= lang_hooks
.name
;
19304 char *producer
, *tail
;
19306 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
19307 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
19309 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
19310 switch (save_decoded_options
[j
].opt_index
)
19317 case OPT_auxbase_strip
:
19326 case OPT_SPECIAL_unknown
:
19327 case OPT_SPECIAL_ignore
:
19328 case OPT_SPECIAL_program_name
:
19329 case OPT_SPECIAL_input_file
:
19330 case OPT_grecord_gcc_switches
:
19331 case OPT_gno_record_gcc_switches
:
19332 case OPT__output_pch_
:
19333 case OPT_fdiagnostics_show_location_
:
19334 case OPT_fdiagnostics_show_option
:
19335 case OPT_fdiagnostics_show_caret
:
19336 case OPT_fdiagnostics_color_
:
19337 case OPT_fverbose_asm
:
19339 case OPT__sysroot_
:
19341 case OPT_nostdinc__
:
19342 /* Ignore these. */
19345 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
19346 & CL_NO_DWARF_RECORD
)
19348 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
19350 switch (save_decoded_options
[j
].canonical_option
[0][1])
19357 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
19364 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
19365 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
19369 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
19371 sprintf (tail
, "%s %s", language_string
, version_string
);
19374 FOR_EACH_VEC_ELT (switches
, j
, p
)
19378 memcpy (tail
+ 1, p
, len
);
19386 /* Generate the DIE for the compilation unit. */
19389 gen_compile_unit_die (const char *filename
)
19392 const char *language_string
= lang_hooks
.name
;
19395 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
19399 add_name_attribute (die
, filename
);
19400 /* Don't add cwd for <built-in>. */
19401 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
19402 add_comp_dir_attribute (die
);
19405 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
19407 /* If our producer is LTO try to figure out a common language to use
19408 from the global list of translation units. */
19409 if (strcmp (language_string
, "GNU GIMPLE") == 0)
19413 const char *common_lang
= NULL
;
19415 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
19417 if (!TRANSLATION_UNIT_LANGUAGE (t
))
19420 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
19421 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
19423 else if (strncmp (common_lang
, "GNU C", 5) == 0
19424 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
19425 /* Mixing C and C++ is ok, use C++ in that case. */
19426 common_lang
= "GNU C++";
19429 /* Fall back to C. */
19430 common_lang
= NULL
;
19436 language_string
= common_lang
;
19439 language
= DW_LANG_C89
;
19440 if (strcmp (language_string
, "GNU C++") == 0)
19441 language
= DW_LANG_C_plus_plus
;
19442 else if (strcmp (language_string
, "GNU F77") == 0)
19443 language
= DW_LANG_Fortran77
;
19444 else if (strcmp (language_string
, "GNU Pascal") == 0)
19445 language
= DW_LANG_Pascal83
;
19446 else if (dwarf_version
>= 3 || !dwarf_strict
)
19448 if (strcmp (language_string
, "GNU Ada") == 0)
19449 language
= DW_LANG_Ada95
;
19450 else if (strcmp (language_string
, "GNU Fortran") == 0)
19451 language
= DW_LANG_Fortran95
;
19452 else if (strcmp (language_string
, "GNU Java") == 0)
19453 language
= DW_LANG_Java
;
19454 else if (strcmp (language_string
, "GNU Objective-C") == 0)
19455 language
= DW_LANG_ObjC
;
19456 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
19457 language
= DW_LANG_ObjC_plus_plus
;
19458 else if (dwarf_version
>= 5 || !dwarf_strict
)
19460 if (strcmp (language_string
, "GNU Go") == 0)
19461 language
= DW_LANG_Go
;
19464 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
19465 else if (strcmp (language_string
, "GNU Fortran") == 0)
19466 language
= DW_LANG_Fortran90
;
19468 add_AT_unsigned (die
, DW_AT_language
, language
);
19472 case DW_LANG_Fortran77
:
19473 case DW_LANG_Fortran90
:
19474 case DW_LANG_Fortran95
:
19475 /* Fortran has case insensitive identifiers and the front-end
19476 lowercases everything. */
19477 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
19480 /* The default DW_ID_case_sensitive doesn't need to be specified. */
19486 /* Generate the DIE for a base class. */
19489 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
19491 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
19493 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
19494 add_data_member_location_attribute (die
, binfo
);
19496 if (BINFO_VIRTUAL_P (binfo
))
19497 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
19499 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19500 children, otherwise the default is DW_ACCESS_public. In DWARF2
19501 the default has always been DW_ACCESS_private. */
19502 if (access
== access_public_node
)
19504 if (dwarf_version
== 2
19505 || context_die
->die_tag
== DW_TAG_class_type
)
19506 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
19508 else if (access
== access_protected_node
)
19509 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19510 else if (dwarf_version
> 2
19511 && context_die
->die_tag
!= DW_TAG_class_type
)
19512 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
19515 /* Generate a DIE for a class member. */
19518 gen_member_die (tree type
, dw_die_ref context_die
)
19521 tree binfo
= TYPE_BINFO (type
);
19524 /* If this is not an incomplete type, output descriptions of each of its
19525 members. Note that as we output the DIEs necessary to represent the
19526 members of this record or union type, we will also be trying to output
19527 DIEs to represent the *types* of those members. However the `type'
19528 function (above) will specifically avoid generating type DIEs for member
19529 types *within* the list of member DIEs for this (containing) type except
19530 for those types (of members) which are explicitly marked as also being
19531 members of this (containing) type themselves. The g++ front- end can
19532 force any given type to be treated as a member of some other (containing)
19533 type by setting the TYPE_CONTEXT of the given (member) type to point to
19534 the TREE node representing the appropriate (containing) type. */
19536 /* First output info about the base classes. */
19539 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
19543 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
19544 gen_inheritance_die (base
,
19545 (accesses
? (*accesses
)[i
] : access_public_node
),
19549 /* Now output info about the data members and type members. */
19550 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
19552 /* If we thought we were generating minimal debug info for TYPE
19553 and then changed our minds, some of the member declarations
19554 may have already been defined. Don't define them again, but
19555 do put them in the right order. */
19557 child
= lookup_decl_die (member
);
19559 splice_child_die (context_die
, child
);
19561 gen_decl_die (member
, NULL
, context_die
);
19564 /* Now output info about the function members (if any). */
19565 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
19567 /* Don't include clones in the member list. */
19568 if (DECL_ABSTRACT_ORIGIN (member
))
19571 child
= lookup_decl_die (member
);
19573 splice_child_die (context_die
, child
);
19575 gen_decl_die (member
, NULL
, context_die
);
19579 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19580 is set, we pretend that the type was never defined, so we only get the
19581 member DIEs needed by later specification DIEs. */
19584 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19585 enum debug_info_usage usage
)
19587 dw_die_ref type_die
= lookup_type_die (type
);
19588 dw_die_ref scope_die
= 0;
19590 int complete
= (TYPE_SIZE (type
)
19591 && (! TYPE_STUB_DECL (type
)
19592 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19593 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19594 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19596 if (type_die
&& ! complete
)
19599 if (TYPE_CONTEXT (type
) != NULL_TREE
19600 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19601 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19604 scope_die
= scope_die_for (type
, context_die
);
19606 /* Generate child dies for template paramaters. */
19607 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19608 schedule_generic_params_dies_gen (type
);
19610 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
19611 /* First occurrence of type or toplevel definition of nested class. */
19613 dw_die_ref old_die
= type_die
;
19615 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19616 ? record_type_tag (type
) : DW_TAG_union_type
,
19618 equate_type_number_to_die (type
, type_die
);
19620 add_AT_specification (type_die
, old_die
);
19622 add_name_attribute (type_die
, type_tag (type
));
19625 remove_AT (type_die
, DW_AT_declaration
);
19627 /* If this type has been completed, then give it a byte_size attribute and
19628 then give a list of members. */
19629 if (complete
&& !ns_decl
)
19631 /* Prevent infinite recursion in cases where the type of some member of
19632 this type is expressed in terms of this type itself. */
19633 TREE_ASM_WRITTEN (type
) = 1;
19634 add_byte_size_attribute (type_die
, type
);
19635 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19637 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19638 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19641 /* If the first reference to this type was as the return type of an
19642 inline function, then it may not have a parent. Fix this now. */
19643 if (type_die
->die_parent
== NULL
)
19644 add_child_die (scope_die
, type_die
);
19646 push_decl_scope (type
);
19647 gen_member_die (type
, type_die
);
19650 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19651 if (TYPE_ARTIFICIAL (type
))
19652 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19654 /* GNU extension: Record what type our vtable lives in. */
19655 if (TYPE_VFIELD (type
))
19657 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19659 gen_type_die (vtype
, context_die
);
19660 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19661 lookup_type_die (vtype
));
19666 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19668 /* We don't need to do this for function-local types. */
19669 if (TYPE_STUB_DECL (type
)
19670 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19671 vec_safe_push (incomplete_types
, type
);
19674 if (get_AT (type_die
, DW_AT_name
))
19675 add_pubtype (type
, type_die
);
19678 /* Generate a DIE for a subroutine _type_. */
19681 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19683 tree return_type
= TREE_TYPE (type
);
19684 dw_die_ref subr_die
19685 = new_die (DW_TAG_subroutine_type
,
19686 scope_die_for (type
, context_die
), type
);
19688 equate_type_number_to_die (type
, subr_die
);
19689 add_prototyped_attribute (subr_die
, type
);
19690 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
19691 gen_formal_types_die (type
, subr_die
);
19693 if (get_AT (subr_die
, DW_AT_name
))
19694 add_pubtype (type
, subr_die
);
19697 /* Generate a DIE for a type definition. */
19700 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19702 dw_die_ref type_die
;
19705 if (TREE_ASM_WRITTEN (decl
))
19708 TREE_ASM_WRITTEN (decl
) = 1;
19709 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19710 origin
= decl_ultimate_origin (decl
);
19711 if (origin
!= NULL
)
19712 add_abstract_origin_attribute (type_die
, origin
);
19717 add_name_and_src_coords_attributes (type_die
, decl
);
19718 if (DECL_ORIGINAL_TYPE (decl
))
19720 type
= DECL_ORIGINAL_TYPE (decl
);
19722 gcc_assert (type
!= TREE_TYPE (decl
));
19723 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19727 type
= TREE_TYPE (decl
);
19729 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19731 /* Here, we are in the case of decl being a typedef naming
19732 an anonymous type, e.g:
19733 typedef struct {...} foo;
19734 In that case TREE_TYPE (decl) is not a typedef variant
19735 type and TYPE_NAME of the anonymous type is set to the
19736 TYPE_DECL of the typedef. This construct is emitted by
19739 TYPE is the anonymous struct named by the typedef
19740 DECL. As we need the DW_AT_type attribute of the
19741 DW_TAG_typedef to point to the DIE of TYPE, let's
19742 generate that DIE right away. add_type_attribute
19743 called below will then pick (via lookup_type_die) that
19744 anonymous struct DIE. */
19745 if (!TREE_ASM_WRITTEN (type
))
19746 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
19748 /* This is a GNU Extension. We are adding a
19749 DW_AT_linkage_name attribute to the DIE of the
19750 anonymous struct TYPE. The value of that attribute
19751 is the name of the typedef decl naming the anonymous
19752 struct. This greatly eases the work of consumers of
19753 this debug info. */
19754 add_linkage_attr (lookup_type_die (type
), decl
);
19758 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
19759 TREE_THIS_VOLATILE (decl
), context_die
);
19761 if (is_naming_typedef_decl (decl
))
19762 /* We want that all subsequent calls to lookup_type_die with
19763 TYPE in argument yield the DW_TAG_typedef we have just
19765 equate_type_number_to_die (type
, type_die
);
19767 add_accessibility_attribute (type_die
, decl
);
19770 if (DECL_ABSTRACT (decl
))
19771 equate_decl_number_to_die (decl
, type_die
);
19773 if (get_AT (type_die
, DW_AT_name
))
19774 add_pubtype (decl
, type_die
);
19777 /* Generate a DIE for a struct, class, enum or union type. */
19780 gen_tagged_type_die (tree type
,
19781 dw_die_ref context_die
,
19782 enum debug_info_usage usage
)
19786 if (type
== NULL_TREE
19787 || !is_tagged_type (type
))
19790 /* If this is a nested type whose containing class hasn't been written
19791 out yet, writing it out will cover this one, too. This does not apply
19792 to instantiations of member class templates; they need to be added to
19793 the containing class as they are generated. FIXME: This hurts the
19794 idea of combining type decls from multiple TUs, since we can't predict
19795 what set of template instantiations we'll get. */
19796 if (TYPE_CONTEXT (type
)
19797 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19798 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
19800 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
19802 if (TREE_ASM_WRITTEN (type
))
19805 /* If that failed, attach ourselves to the stub. */
19806 push_decl_scope (TYPE_CONTEXT (type
));
19807 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
19810 else if (TYPE_CONTEXT (type
) != NULL_TREE
19811 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
19813 /* If this type is local to a function that hasn't been written
19814 out yet, use a NULL context for now; it will be fixed up in
19815 decls_for_scope. */
19816 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
19817 /* A declaration DIE doesn't count; nested types need to go in the
19819 if (context_die
&& is_declaration_die (context_die
))
19820 context_die
= NULL
;
19825 context_die
= declare_in_namespace (type
, context_die
);
19829 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
19831 /* This might have been written out by the call to
19832 declare_in_namespace. */
19833 if (!TREE_ASM_WRITTEN (type
))
19834 gen_enumeration_type_die (type
, context_die
);
19837 gen_struct_or_union_type_die (type
, context_die
, usage
);
19842 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19843 it up if it is ever completed. gen_*_type_die will set it for us
19844 when appropriate. */
19847 /* Generate a type description DIE. */
19850 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
19851 enum debug_info_usage usage
)
19853 struct array_descr_info info
;
19855 if (type
== NULL_TREE
|| type
== error_mark_node
)
19858 if (TYPE_NAME (type
) != NULL_TREE
19859 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19860 && is_redundant_typedef (TYPE_NAME (type
))
19861 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
19862 /* The DECL of this type is a typedef we don't want to emit debug
19863 info for but we want debug info for its underlying typedef.
19864 This can happen for e.g, the injected-class-name of a C++
19866 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
19868 /* If TYPE is a typedef type variant, let's generate debug info
19869 for the parent typedef which TYPE is a type of. */
19870 if (typedef_variant_p (type
))
19872 if (TREE_ASM_WRITTEN (type
))
19875 /* Prevent broken recursion; we can't hand off to the same type. */
19876 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
19878 /* Give typedefs the right scope. */
19879 context_die
= scope_die_for (type
, context_die
);
19881 TREE_ASM_WRITTEN (type
) = 1;
19883 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19887 /* If type is an anonymous tagged type named by a typedef, let's
19888 generate debug info for the typedef. */
19889 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19891 /* Use the DIE of the containing namespace as the parent DIE of
19892 the type description DIE we want to generate. */
19893 if (DECL_CONTEXT (TYPE_NAME (type
))
19894 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
19895 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
19897 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19901 /* If this is an array type with hidden descriptor, handle it first. */
19902 if (!TREE_ASM_WRITTEN (type
)
19903 && lang_hooks
.types
.get_array_descr_info
19904 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
19905 && (dwarf_version
>= 3 || !dwarf_strict
))
19907 gen_descr_array_type_die (type
, &info
, context_die
);
19908 TREE_ASM_WRITTEN (type
) = 1;
19912 /* We are going to output a DIE to represent the unqualified version
19913 of this type (i.e. without any const or volatile qualifiers) so
19914 get the main variant (i.e. the unqualified version) of this type
19915 now. (Vectors are special because the debugging info is in the
19916 cloned type itself). */
19917 if (TREE_CODE (type
) != VECTOR_TYPE
)
19918 type
= type_main_variant (type
);
19920 if (TREE_ASM_WRITTEN (type
))
19923 switch (TREE_CODE (type
))
19929 case REFERENCE_TYPE
:
19930 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19931 ensures that the gen_type_die recursion will terminate even if the
19932 type is recursive. Recursive types are possible in Ada. */
19933 /* ??? We could perhaps do this for all types before the switch
19935 TREE_ASM_WRITTEN (type
) = 1;
19937 /* For these types, all that is required is that we output a DIE (or a
19938 set of DIEs) to represent the "basis" type. */
19939 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19940 DINFO_USAGE_IND_USE
);
19944 /* This code is used for C++ pointer-to-data-member types.
19945 Output a description of the relevant class type. */
19946 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
19947 DINFO_USAGE_IND_USE
);
19949 /* Output a description of the type of the object pointed to. */
19950 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19951 DINFO_USAGE_IND_USE
);
19953 /* Now output a DIE to represent this pointer-to-data-member type
19955 gen_ptr_to_mbr_type_die (type
, context_die
);
19958 case FUNCTION_TYPE
:
19959 /* Force out return type (in case it wasn't forced out already). */
19960 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19961 DINFO_USAGE_DIR_USE
);
19962 gen_subroutine_type_die (type
, context_die
);
19966 /* Force out return type (in case it wasn't forced out already). */
19967 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19968 DINFO_USAGE_DIR_USE
);
19969 gen_subroutine_type_die (type
, context_die
);
19973 gen_array_type_die (type
, context_die
);
19977 gen_array_type_die (type
, context_die
);
19980 case ENUMERAL_TYPE
:
19983 case QUAL_UNION_TYPE
:
19984 gen_tagged_type_die (type
, context_die
, usage
);
19990 case FIXED_POINT_TYPE
:
19993 /* No DIEs needed for fundamental types. */
19998 /* Just use DW_TAG_unspecified_type. */
20000 dw_die_ref type_die
= lookup_type_die (type
);
20001 if (type_die
== NULL
)
20003 tree name
= TYPE_IDENTIFIER (type
);
20004 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
20006 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
20007 equate_type_number_to_die (type
, type_die
);
20013 if (is_cxx_auto (type
))
20015 tree name
= TYPE_IDENTIFIER (type
);
20016 dw_die_ref
*die
= (name
== get_identifier ("auto")
20017 ? &auto_die
: &decltype_auto_die
);
20020 *die
= new_die (DW_TAG_unspecified_type
,
20021 comp_unit_die (), NULL_TREE
);
20022 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
20024 equate_type_number_to_die (type
, *die
);
20027 gcc_unreachable ();
20030 TREE_ASM_WRITTEN (type
) = 1;
20034 gen_type_die (tree type
, dw_die_ref context_die
)
20036 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
20039 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20040 things which are local to the given block. */
20043 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
20045 int must_output_die
= 0;
20048 /* Ignore blocks that are NULL. */
20049 if (stmt
== NULL_TREE
)
20052 inlined_func
= inlined_function_outer_scope_p (stmt
);
20054 /* If the block is one fragment of a non-contiguous block, do not
20055 process the variables, since they will have been done by the
20056 origin block. Do process subblocks. */
20057 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
20061 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
20062 gen_block_die (sub
, context_die
, depth
+ 1);
20067 /* Determine if we need to output any Dwarf DIEs at all to represent this
20070 /* The outer scopes for inlinings *must* always be represented. We
20071 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20072 must_output_die
= 1;
20075 /* Determine if this block directly contains any "significant"
20076 local declarations which we will need to output DIEs for. */
20077 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20078 /* We are not in terse mode so *any* local declaration counts
20079 as being a "significant" one. */
20080 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
20081 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
20082 && (TREE_USED (stmt
)
20083 || TREE_ASM_WRITTEN (stmt
)
20084 || BLOCK_ABSTRACT (stmt
)));
20085 else if ((TREE_USED (stmt
)
20086 || TREE_ASM_WRITTEN (stmt
)
20087 || BLOCK_ABSTRACT (stmt
))
20088 && !dwarf2out_ignore_block (stmt
))
20089 must_output_die
= 1;
20092 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20093 DIE for any block which contains no significant local declarations at
20094 all. Rather, in such cases we just call `decls_for_scope' so that any
20095 needed Dwarf info for any sub-blocks will get properly generated. Note
20096 that in terse mode, our definition of what constitutes a "significant"
20097 local declaration gets restricted to include only inlined function
20098 instances and local (nested) function definitions. */
20099 if (must_output_die
)
20103 /* If STMT block is abstract, that means we have been called
20104 indirectly from dwarf2out_abstract_function.
20105 That function rightfully marks the descendent blocks (of
20106 the abstract function it is dealing with) as being abstract,
20107 precisely to prevent us from emitting any
20108 DW_TAG_inlined_subroutine DIE as a descendent
20109 of an abstract function instance. So in that case, we should
20110 not call gen_inlined_subroutine_die.
20112 Later though, when cgraph asks dwarf2out to emit info
20113 for the concrete instance of the function decl into which
20114 the concrete instance of STMT got inlined, the later will lead
20115 to the generation of a DW_TAG_inlined_subroutine DIE. */
20116 if (! BLOCK_ABSTRACT (stmt
))
20117 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
20120 gen_lexical_block_die (stmt
, context_die
, depth
);
20123 decls_for_scope (stmt
, context_die
, depth
);
20126 /* Process variable DECL (or variable with origin ORIGIN) within
20127 block STMT and add it to CONTEXT_DIE. */
20129 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
20132 tree decl_or_origin
= decl
? decl
: origin
;
20134 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
20135 die
= lookup_decl_die (decl_or_origin
);
20136 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
20137 && TYPE_DECL_IS_STUB (decl_or_origin
))
20138 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
20142 if (die
!= NULL
&& die
->die_parent
== NULL
)
20143 add_child_die (context_die
, die
);
20144 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
20145 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
20146 stmt
, context_die
);
20148 gen_decl_die (decl
, origin
, context_die
);
20151 /* Generate all of the decls declared within a given scope and (recursively)
20152 all of its sub-blocks. */
20155 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
20161 /* Ignore NULL blocks. */
20162 if (stmt
== NULL_TREE
)
20165 /* Output the DIEs to represent all of the data objects and typedefs
20166 declared directly within this block but not within any nested
20167 sub-blocks. Also, nested function and tag DIEs have been
20168 generated with a parent of NULL; fix that up now. We don't
20169 have to do this if we're at -g1. */
20170 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20172 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
20173 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
20174 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
20175 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
20179 /* Even if we're at -g1, we need to process the subblocks in order to get
20180 inlined call information. */
20182 /* Output the DIEs to represent all sub-blocks (and the items declared
20183 therein) of this block. */
20184 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
20186 subblocks
= BLOCK_CHAIN (subblocks
))
20187 gen_block_die (subblocks
, context_die
, depth
+ 1);
20190 /* Is this a typedef we can avoid emitting? */
20193 is_redundant_typedef (const_tree decl
)
20195 if (TYPE_DECL_IS_STUB (decl
))
20198 if (DECL_ARTIFICIAL (decl
)
20199 && DECL_CONTEXT (decl
)
20200 && is_tagged_type (DECL_CONTEXT (decl
))
20201 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
20202 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
20203 /* Also ignore the artificial member typedef for the class name. */
20209 /* Return TRUE if TYPE is a typedef that names a type for linkage
20210 purposes. This kind of typedefs is produced by the C++ FE for
20213 typedef struct {...} foo;
20215 In that case, there is no typedef variant type produced for foo.
20216 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20220 is_naming_typedef_decl (const_tree decl
)
20222 if (decl
== NULL_TREE
20223 || TREE_CODE (decl
) != TYPE_DECL
20224 || !is_tagged_type (TREE_TYPE (decl
))
20225 || DECL_IS_BUILTIN (decl
)
20226 || is_redundant_typedef (decl
)
20227 /* It looks like Ada produces TYPE_DECLs that are very similar
20228 to C++ naming typedefs but that have different
20229 semantics. Let's be specific to c++ for now. */
20233 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
20234 && TYPE_NAME (TREE_TYPE (decl
)) == decl
20235 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
20236 != TYPE_NAME (TREE_TYPE (decl
))));
20239 /* Returns the DIE for a context. */
20241 static inline dw_die_ref
20242 get_context_die (tree context
)
20246 /* Find die that represents this context. */
20247 if (TYPE_P (context
))
20249 context
= TYPE_MAIN_VARIANT (context
);
20250 return strip_naming_typedef (context
, force_type_die (context
));
20253 return force_decl_die (context
);
20255 return comp_unit_die ();
20258 /* Returns the DIE for decl. A DIE will always be returned. */
20261 force_decl_die (tree decl
)
20263 dw_die_ref decl_die
;
20264 unsigned saved_external_flag
;
20265 tree save_fn
= NULL_TREE
;
20266 decl_die
= lookup_decl_die (decl
);
20269 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
20271 decl_die
= lookup_decl_die (decl
);
20275 switch (TREE_CODE (decl
))
20277 case FUNCTION_DECL
:
20278 /* Clear current_function_decl, so that gen_subprogram_die thinks
20279 that this is a declaration. At this point, we just want to force
20280 declaration die. */
20281 save_fn
= current_function_decl
;
20282 current_function_decl
= NULL_TREE
;
20283 gen_subprogram_die (decl
, context_die
);
20284 current_function_decl
= save_fn
;
20288 /* Set external flag to force declaration die. Restore it after
20289 gen_decl_die() call. */
20290 saved_external_flag
= DECL_EXTERNAL (decl
);
20291 DECL_EXTERNAL (decl
) = 1;
20292 gen_decl_die (decl
, NULL
, context_die
);
20293 DECL_EXTERNAL (decl
) = saved_external_flag
;
20296 case NAMESPACE_DECL
:
20297 if (dwarf_version
>= 3 || !dwarf_strict
)
20298 dwarf2out_decl (decl
);
20300 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
20301 decl_die
= comp_unit_die ();
20304 case TRANSLATION_UNIT_DECL
:
20305 decl_die
= comp_unit_die ();
20309 gcc_unreachable ();
20312 /* We should be able to find the DIE now. */
20314 decl_die
= lookup_decl_die (decl
);
20315 gcc_assert (decl_die
);
20321 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
20322 always returned. */
20325 force_type_die (tree type
)
20327 dw_die_ref type_die
;
20329 type_die
= lookup_type_die (type
);
20332 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
20334 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
20335 TYPE_VOLATILE (type
), context_die
);
20336 gcc_assert (type_die
);
20341 /* Force out any required namespaces to be able to output DECL,
20342 and return the new context_die for it, if it's changed. */
20345 setup_namespace_context (tree thing
, dw_die_ref context_die
)
20347 tree context
= (DECL_P (thing
)
20348 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
20349 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
20350 /* Force out the namespace. */
20351 context_die
= force_decl_die (context
);
20353 return context_die
;
20356 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
20357 type) within its namespace, if appropriate.
20359 For compatibility with older debuggers, namespace DIEs only contain
20360 declarations; all definitions are emitted at CU scope. */
20363 declare_in_namespace (tree thing
, dw_die_ref context_die
)
20365 dw_die_ref ns_context
;
20367 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20368 return context_die
;
20370 /* If this decl is from an inlined function, then don't try to emit it in its
20371 namespace, as we will get confused. It would have already been emitted
20372 when the abstract instance of the inline function was emitted anyways. */
20373 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
20374 return context_die
;
20376 ns_context
= setup_namespace_context (thing
, context_die
);
20378 if (ns_context
!= context_die
)
20382 if (DECL_P (thing
))
20383 gen_decl_die (thing
, NULL
, ns_context
);
20385 gen_type_die (thing
, ns_context
);
20387 return context_die
;
20390 /* Generate a DIE for a namespace or namespace alias. */
20393 gen_namespace_die (tree decl
, dw_die_ref context_die
)
20395 dw_die_ref namespace_die
;
20397 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
20398 they are an alias of. */
20399 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
20401 /* Output a real namespace or module. */
20402 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20403 namespace_die
= new_die (is_fortran ()
20404 ? DW_TAG_module
: DW_TAG_namespace
,
20405 context_die
, decl
);
20406 /* For Fortran modules defined in different CU don't add src coords. */
20407 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
20409 const char *name
= dwarf2_name (decl
, 0);
20411 add_name_attribute (namespace_die
, name
);
20414 add_name_and_src_coords_attributes (namespace_die
, decl
);
20415 if (DECL_EXTERNAL (decl
))
20416 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
20417 equate_decl_number_to_die (decl
, namespace_die
);
20421 /* Output a namespace alias. */
20423 /* Force out the namespace we are an alias of, if necessary. */
20424 dw_die_ref origin_die
20425 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
20427 if (DECL_FILE_SCOPE_P (decl
)
20428 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
20429 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20430 /* Now create the namespace alias DIE. */
20431 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
20432 add_name_and_src_coords_attributes (namespace_die
, decl
);
20433 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
20434 equate_decl_number_to_die (decl
, namespace_die
);
20436 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
20437 if (want_pubnames ())
20438 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
20441 /* Generate Dwarf debug information for a decl described by DECL.
20442 The return value is currently only meaningful for PARM_DECLs,
20443 for all other decls it returns NULL. */
20446 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
20448 tree decl_or_origin
= decl
? decl
: origin
;
20449 tree class_origin
= NULL
, ultimate_origin
;
20451 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
20454 switch (TREE_CODE (decl_or_origin
))
20460 if (!is_fortran () && !is_ada ())
20462 /* The individual enumerators of an enum type get output when we output
20463 the Dwarf representation of the relevant enum type itself. */
20467 /* Emit its type. */
20468 gen_type_die (TREE_TYPE (decl
), context_die
);
20470 /* And its containing namespace. */
20471 context_die
= declare_in_namespace (decl
, context_die
);
20473 gen_const_die (decl
, context_die
);
20476 case FUNCTION_DECL
:
20477 /* Don't output any DIEs to represent mere function declarations,
20478 unless they are class members or explicit block externs. */
20479 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
20480 && DECL_FILE_SCOPE_P (decl_or_origin
)
20481 && (current_function_decl
== NULL_TREE
20482 || DECL_ARTIFICIAL (decl_or_origin
)))
20487 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
20488 on local redeclarations of global functions. That seems broken. */
20489 if (current_function_decl
!= decl
)
20490 /* This is only a declaration. */;
20493 /* If we're emitting a clone, emit info for the abstract instance. */
20494 if (origin
|| DECL_ORIGIN (decl
) != decl
)
20495 dwarf2out_abstract_function (origin
20496 ? DECL_ORIGIN (origin
)
20497 : DECL_ABSTRACT_ORIGIN (decl
));
20499 /* If we're emitting an out-of-line copy of an inline function,
20500 emit info for the abstract instance and set up to refer to it. */
20501 else if (cgraph_function_possibly_inlined_p (decl
)
20502 && ! DECL_ABSTRACT (decl
)
20503 && ! class_or_namespace_scope_p (context_die
)
20504 /* dwarf2out_abstract_function won't emit a die if this is just
20505 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
20506 that case, because that works only if we have a die. */
20507 && DECL_INITIAL (decl
) != NULL_TREE
)
20509 dwarf2out_abstract_function (decl
);
20510 set_decl_origin_self (decl
);
20513 /* Otherwise we're emitting the primary DIE for this decl. */
20514 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20516 /* Before we describe the FUNCTION_DECL itself, make sure that we
20517 have its containing type. */
20519 origin
= decl_class_context (decl
);
20520 if (origin
!= NULL_TREE
)
20521 gen_type_die (origin
, context_die
);
20523 /* And its return type. */
20524 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
20526 /* And its virtual context. */
20527 if (DECL_VINDEX (decl
) != NULL_TREE
)
20528 gen_type_die (DECL_CONTEXT (decl
), context_die
);
20530 /* Make sure we have a member DIE for decl. */
20531 if (origin
!= NULL_TREE
)
20532 gen_type_die_for_member (origin
, decl
, context_die
);
20534 /* And its containing namespace. */
20535 context_die
= declare_in_namespace (decl
, context_die
);
20538 /* Now output a DIE to represent the function itself. */
20540 gen_subprogram_die (decl
, context_die
);
20544 /* If we are in terse mode, don't generate any DIEs to represent any
20545 actual typedefs. */
20546 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20549 /* In the special case of a TYPE_DECL node representing the declaration
20550 of some type tag, if the given TYPE_DECL is marked as having been
20551 instantiated from some other (original) TYPE_DECL node (e.g. one which
20552 was generated within the original definition of an inline function) we
20553 used to generate a special (abbreviated) DW_TAG_structure_type,
20554 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20555 should be actually referencing those DIEs, as variable DIEs with that
20556 type would be emitted already in the abstract origin, so it was always
20557 removed during unused type prunning. Don't add anything in this
20559 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
20562 if (is_redundant_typedef (decl
))
20563 gen_type_die (TREE_TYPE (decl
), context_die
);
20565 /* Output a DIE to represent the typedef itself. */
20566 gen_typedef_die (decl
, context_die
);
20570 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
20571 gen_label_die (decl
, context_die
);
20576 /* If we are in terse mode, don't generate any DIEs to represent any
20577 variable declarations or definitions. */
20578 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20581 /* Output any DIEs that are needed to specify the type of this data
20583 if (decl_by_reference_p (decl_or_origin
))
20584 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20586 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20588 /* And its containing type. */
20589 class_origin
= decl_class_context (decl_or_origin
);
20590 if (class_origin
!= NULL_TREE
)
20591 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20593 /* And its containing namespace. */
20594 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20596 /* Now output the DIE to represent the data object itself. This gets
20597 complicated because of the possibility that the VAR_DECL really
20598 represents an inlined instance of a formal parameter for an inline
20600 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20601 if (ultimate_origin
!= NULL_TREE
20602 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20603 gen_formal_parameter_die (decl
, origin
,
20604 true /* Emit name attribute. */,
20607 gen_variable_die (decl
, origin
, context_die
);
20611 /* Ignore the nameless fields that are used to skip bits but handle C++
20612 anonymous unions and structs. */
20613 if (DECL_NAME (decl
) != NULL_TREE
20614 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20615 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20617 gen_type_die (member_declared_type (decl
), context_die
);
20618 gen_field_die (decl
, context_die
);
20623 if (DECL_BY_REFERENCE (decl_or_origin
))
20624 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20626 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20627 return gen_formal_parameter_die (decl
, origin
,
20628 true /* Emit name attribute. */,
20631 case NAMESPACE_DECL
:
20632 case IMPORTED_DECL
:
20633 if (dwarf_version
>= 3 || !dwarf_strict
)
20634 gen_namespace_die (decl
, context_die
);
20637 case NAMELIST_DECL
:
20638 gen_namelist_decl (DECL_NAME (decl
), context_die
,
20639 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
20643 /* Probably some frontend-internal decl. Assume we don't care. */
20644 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20651 /* Output debug information for global decl DECL. Called from toplev.c after
20652 compilation proper has finished. */
20655 dwarf2out_global_decl (tree decl
)
20657 /* Output DWARF2 information for file-scope tentative data object
20658 declarations, file-scope (extern) function declarations (which
20659 had no corresponding body) and file-scope tagged type declarations
20660 and definitions which have not yet been forced out. */
20661 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20662 dwarf2out_decl (decl
);
20665 /* Output debug information for type decl DECL. Called from toplev.c
20666 and from language front ends (to record built-in types). */
20668 dwarf2out_type_decl (tree decl
, int local
)
20671 dwarf2out_decl (decl
);
20674 /* Output debug information for imported module or decl DECL.
20675 NAME is non-NULL name in the lexical block if the decl has been renamed.
20676 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20677 that DECL belongs to.
20678 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20680 dwarf2out_imported_module_or_decl_1 (tree decl
,
20682 tree lexical_block
,
20683 dw_die_ref lexical_block_die
)
20685 expanded_location xloc
;
20686 dw_die_ref imported_die
= NULL
;
20687 dw_die_ref at_import_die
;
20689 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20691 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20692 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20696 xloc
= expand_location (input_location
);
20698 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20700 at_import_die
= force_type_die (TREE_TYPE (decl
));
20701 /* For namespace N { typedef void T; } using N::T; base_type_die
20702 returns NULL, but DW_TAG_imported_declaration requires
20703 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20704 if (!at_import_die
)
20706 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20707 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20708 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20709 gcc_assert (at_import_die
);
20714 at_import_die
= lookup_decl_die (decl
);
20715 if (!at_import_die
)
20717 /* If we're trying to avoid duplicate debug info, we may not have
20718 emitted the member decl for this field. Emit it now. */
20719 if (TREE_CODE (decl
) == FIELD_DECL
)
20721 tree type
= DECL_CONTEXT (decl
);
20723 if (TYPE_CONTEXT (type
)
20724 && TYPE_P (TYPE_CONTEXT (type
))
20725 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20726 DINFO_USAGE_DIR_USE
))
20728 gen_type_die_for_member (type
, decl
,
20729 get_context_die (TYPE_CONTEXT (type
)));
20731 if (TREE_CODE (decl
) == NAMELIST_DECL
)
20732 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
20733 get_context_die (DECL_CONTEXT (decl
)),
20736 at_import_die
= force_decl_die (decl
);
20740 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20742 if (dwarf_version
>= 3 || !dwarf_strict
)
20743 imported_die
= new_die (DW_TAG_imported_module
,
20750 imported_die
= new_die (DW_TAG_imported_declaration
,
20754 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20755 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20757 add_AT_string (imported_die
, DW_AT_name
,
20758 IDENTIFIER_POINTER (name
));
20759 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20762 /* Output debug information for imported module or decl DECL.
20763 NAME is non-NULL name in context if the decl has been renamed.
20764 CHILD is true if decl is one of the renamed decls as part of
20765 importing whole module. */
20768 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20771 /* dw_die_ref at_import_die; */
20772 dw_die_ref scope_die
;
20774 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20779 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20780 We need decl DIE for reference and scope die. First, get DIE for the decl
20783 /* Get the scope die for decl context. Use comp_unit_die for global module
20784 or decl. If die is not found for non globals, force new die. */
20786 && TYPE_P (context
)
20787 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20790 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20793 scope_die
= get_context_die (context
);
20797 gcc_assert (scope_die
->die_child
);
20798 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
20799 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
20800 scope_die
= scope_die
->die_child
;
20803 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20804 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
20808 /* Output debug information for namelists. */
20811 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
20813 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
20817 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20820 gcc_assert (scope_die
!= NULL
);
20821 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
20822 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
20824 /* If there are no item_decls, we have a nondefining namelist, e.g.
20825 with USE association; hence, set DW_AT_declaration. */
20826 if (item_decls
== NULL_TREE
)
20828 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
20832 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
20834 nml_item_ref_die
= lookup_decl_die (value
);
20835 if (!nml_item_ref_die
)
20836 nml_item_ref_die
= force_decl_die (value
);
20838 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
20839 add_AT_die_ref (nml_item_die
, DW_AT_namelist_items
, nml_item_ref_die
);
20845 /* Write the debugging output for DECL. */
20848 dwarf2out_decl (tree decl
)
20850 dw_die_ref context_die
= comp_unit_die ();
20852 switch (TREE_CODE (decl
))
20857 case FUNCTION_DECL
:
20858 /* What we would really like to do here is to filter out all mere
20859 file-scope declarations of file-scope functions which are never
20860 referenced later within this translation unit (and keep all of ones
20861 that *are* referenced later on) but we aren't clairvoyant, so we have
20862 no idea which functions will be referenced in the future (i.e. later
20863 on within the current translation unit). So here we just ignore all
20864 file-scope function declarations which are not also definitions. If
20865 and when the debugger needs to know something about these functions,
20866 it will have to hunt around and find the DWARF information associated
20867 with the definition of the function.
20869 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20870 nodes represent definitions and which ones represent mere
20871 declarations. We have to check DECL_INITIAL instead. That's because
20872 the C front-end supports some weird semantics for "extern inline"
20873 function definitions. These can get inlined within the current
20874 translation unit (and thus, we need to generate Dwarf info for their
20875 abstract instances so that the Dwarf info for the concrete inlined
20876 instances can have something to refer to) but the compiler never
20877 generates any out-of-lines instances of such things (despite the fact
20878 that they *are* definitions).
20880 The important point is that the C front-end marks these "extern
20881 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20882 them anyway. Note that the C++ front-end also plays some similar games
20883 for inline function definitions appearing within include files which
20884 also contain `#pragma interface' pragmas.
20886 If we are called from dwarf2out_abstract_function output a DIE
20887 anyway. We can end up here this way with early inlining and LTO
20888 where the inlined function is output in a different LTRANS unit
20890 if (DECL_INITIAL (decl
) == NULL_TREE
20891 && ! DECL_ABSTRACT (decl
))
20894 /* If we're a nested function, initially use a parent of NULL; if we're
20895 a plain function, this will be fixed up in decls_for_scope. If
20896 we're a method, it will be ignored, since we already have a DIE. */
20897 if (decl_function_context (decl
)
20898 /* But if we're in terse mode, we don't care about scope. */
20899 && debug_info_level
> DINFO_LEVEL_TERSE
)
20900 context_die
= NULL
;
20904 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20905 declaration and if the declaration was never even referenced from
20906 within this entire compilation unit. We suppress these DIEs in
20907 order to save space in the .debug section (by eliminating entries
20908 which are probably useless). Note that we must not suppress
20909 block-local extern declarations (whether used or not) because that
20910 would screw-up the debugger's name lookup mechanism and cause it to
20911 miss things which really ought to be in scope at a given point. */
20912 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
20915 /* For local statics lookup proper context die. */
20916 if (TREE_STATIC (decl
)
20917 && DECL_CONTEXT (decl
)
20918 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
20919 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20921 /* If we are in terse mode, don't generate any DIEs to represent any
20922 variable declarations or definitions. */
20923 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20928 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20930 if (!is_fortran () && !is_ada ())
20932 if (TREE_STATIC (decl
) && decl_function_context (decl
))
20933 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20936 case NAMESPACE_DECL
:
20937 case IMPORTED_DECL
:
20938 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20940 if (lookup_decl_die (decl
) != NULL
)
20945 /* Don't emit stubs for types unless they are needed by other DIEs. */
20946 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
20949 /* Don't bother trying to generate any DIEs to represent any of the
20950 normal built-in types for the language we are compiling. */
20951 if (DECL_IS_BUILTIN (decl
))
20954 /* If we are in terse mode, don't generate any DIEs for types. */
20955 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20958 /* If we're a function-scope tag, initially use a parent of NULL;
20959 this will be fixed up in decls_for_scope. */
20960 if (decl_function_context (decl
))
20961 context_die
= NULL
;
20965 case NAMELIST_DECL
:
20972 gen_decl_die (decl
, NULL
, context_die
);
20975 /* Write the debugging output for DECL. */
20978 dwarf2out_function_decl (tree decl
)
20980 dwarf2out_decl (decl
);
20981 call_arg_locations
= NULL
;
20982 call_arg_loc_last
= NULL
;
20983 call_site_count
= -1;
20984 tail_call_site_count
= -1;
20985 block_map
.release ();
20986 htab_empty (decl_loc_table
);
20987 htab_empty (cached_dw_loc_list_table
);
20990 /* Output a marker (i.e. a label) for the beginning of the generated code for
20991 a lexical block. */
20994 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
20995 unsigned int blocknum
)
20997 switch_to_section (current_function_section ());
20998 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
21001 /* Output a marker (i.e. a label) for the end of the generated code for a
21005 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
21007 switch_to_section (current_function_section ());
21008 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
21011 /* Returns nonzero if it is appropriate not to emit any debugging
21012 information for BLOCK, because it doesn't contain any instructions.
21014 Don't allow this for blocks with nested functions or local classes
21015 as we would end up with orphans, and in the presence of scheduling
21016 we may end up calling them anyway. */
21019 dwarf2out_ignore_block (const_tree block
)
21024 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
21025 if (TREE_CODE (decl
) == FUNCTION_DECL
21026 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
21028 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
21030 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
21031 if (TREE_CODE (decl
) == FUNCTION_DECL
21032 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
21039 /* Hash table routines for file_hash. */
21042 file_table_eq (const void *p1_p
, const void *p2_p
)
21044 const struct dwarf_file_data
*const p1
=
21045 (const struct dwarf_file_data
*) p1_p
;
21046 const char *const p2
= (const char *) p2_p
;
21047 return filename_cmp (p1
->filename
, p2
) == 0;
21051 file_table_hash (const void *p_p
)
21053 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
21054 return htab_hash_string (p
->filename
);
21057 /* Lookup FILE_NAME (in the list of filenames that we know about here in
21058 dwarf2out.c) and return its "index". The index of each (known) filename is
21059 just a unique number which is associated with only that one filename. We
21060 need such numbers for the sake of generating labels (in the .debug_sfnames
21061 section) and references to those files numbers (in the .debug_srcinfo
21062 and.debug_macinfo sections). If the filename given as an argument is not
21063 found in our current list, add it to the list and assign it the next
21064 available unique index number. In order to speed up searches, we remember
21065 the index of the filename was looked up last. This handles the majority of
21068 static struct dwarf_file_data
*
21069 lookup_filename (const char *file_name
)
21072 struct dwarf_file_data
* created
;
21074 /* Check to see if the file name that was searched on the previous
21075 call matches this file name. If so, return the index. */
21076 if (file_table_last_lookup
21077 && (file_name
== file_table_last_lookup
->filename
21078 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
21079 return file_table_last_lookup
;
21081 /* Didn't match the previous lookup, search the table. */
21082 slot
= htab_find_slot_with_hash (file_table
, file_name
,
21083 htab_hash_string (file_name
), INSERT
);
21085 return (struct dwarf_file_data
*) *slot
;
21087 created
= ggc_alloc
<dwarf_file_data
> ();
21088 created
->filename
= file_name
;
21089 created
->emitted_number
= 0;
21094 /* If the assembler will construct the file table, then translate the compiler
21095 internal file table number into the assembler file table number, and emit
21096 a .file directive if we haven't already emitted one yet. The file table
21097 numbers are different because we prune debug info for unused variables and
21098 types, which may include filenames. */
21101 maybe_emit_file (struct dwarf_file_data
* fd
)
21103 if (! fd
->emitted_number
)
21105 if (last_emitted_file
)
21106 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
21108 fd
->emitted_number
= 1;
21109 last_emitted_file
= fd
;
21111 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21113 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
21114 output_quoted_string (asm_out_file
,
21115 remap_debug_filename (fd
->filename
));
21116 fputc ('\n', asm_out_file
);
21120 return fd
->emitted_number
;
21123 /* Schedule generation of a DW_AT_const_value attribute to DIE.
21124 That generation should happen after function debug info has been
21125 generated. The value of the attribute is the constant value of ARG. */
21128 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
21130 die_arg_entry entry
;
21135 if (!tmpl_value_parm_die_table
)
21136 vec_alloc (tmpl_value_parm_die_table
, 32);
21140 vec_safe_push (tmpl_value_parm_die_table
, entry
);
21143 /* Return TRUE if T is an instance of generic type, FALSE
21147 generic_type_p (tree t
)
21149 if (t
== NULL_TREE
|| !TYPE_P (t
))
21151 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
21154 /* Schedule the generation of the generic parameter dies for the
21155 instance of generic type T. The proper generation itself is later
21156 done by gen_scheduled_generic_parms_dies. */
21159 schedule_generic_params_dies_gen (tree t
)
21161 if (!generic_type_p (t
))
21164 if (!generic_type_instances
)
21165 vec_alloc (generic_type_instances
, 256);
21167 vec_safe_push (generic_type_instances
, t
);
21170 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
21171 by append_entry_to_tmpl_value_parm_die_table. This function must
21172 be called after function DIEs have been generated. */
21175 gen_remaining_tmpl_value_param_die_attribute (void)
21177 if (tmpl_value_parm_die_table
)
21182 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
21183 tree_add_const_value_attribute (e
->die
, e
->arg
);
21187 /* Generate generic parameters DIEs for instances of generic types
21188 that have been previously scheduled by
21189 schedule_generic_params_dies_gen. This function must be called
21190 after all the types of the CU have been laid out. */
21193 gen_scheduled_generic_parms_dies (void)
21198 if (!generic_type_instances
)
21201 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
21202 if (COMPLETE_TYPE_P (t
))
21203 gen_generic_params_dies (t
);
21207 /* Replace DW_AT_name for the decl with name. */
21210 dwarf2out_set_name (tree decl
, tree name
)
21216 die
= TYPE_SYMTAB_DIE (decl
);
21220 dname
= dwarf2_name (name
, 0);
21224 attr
= get_AT (die
, DW_AT_name
);
21227 struct indirect_string_node
*node
;
21229 node
= find_AT_string (dname
);
21230 /* replace the string. */
21231 attr
->dw_attr_val
.v
.val_str
= node
;
21235 add_name_attribute (die
, dname
);
21238 /* True if before or during processing of the first function being emitted. */
21239 static bool in_first_function_p
= true;
21240 /* True if loc_note during dwarf2out_var_location call might still be
21241 before first real instruction at address equal to .Ltext0. */
21242 static bool maybe_at_text_label_p
= true;
21243 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
21244 static unsigned int first_loclabel_num_not_at_text_label
;
21246 /* Called by the final INSN scan whenever we see a var location. We
21247 use it to drop labels in the right places, and throw the location in
21248 our lookup table. */
21251 dwarf2out_var_location (rtx loc_note
)
21253 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
21254 struct var_loc_node
*newloc
;
21255 rtx next_real
, next_note
;
21256 static const char *last_label
;
21257 static const char *last_postcall_label
;
21258 static bool last_in_cold_section_p
;
21259 static rtx expected_next_loc_note
;
21263 if (!NOTE_P (loc_note
))
21265 if (CALL_P (loc_note
))
21268 if (SIBLING_CALL_P (loc_note
))
21269 tail_call_site_count
++;
21274 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
21275 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
21278 /* Optimize processing a large consecutive sequence of location
21279 notes so we don't spend too much time in next_real_insn. If the
21280 next insn is another location note, remember the next_real_insn
21281 calculation for next time. */
21282 next_real
= cached_next_real_insn
;
21285 if (expected_next_loc_note
!= loc_note
)
21286 next_real
= NULL_RTX
;
21289 next_note
= NEXT_INSN (loc_note
);
21291 || INSN_DELETED_P (next_note
)
21292 || ! NOTE_P (next_note
)
21293 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
21294 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
21295 next_note
= NULL_RTX
;
21298 next_real
= next_real_insn (loc_note
);
21302 expected_next_loc_note
= next_note
;
21303 cached_next_real_insn
= next_real
;
21306 cached_next_real_insn
= NULL_RTX
;
21308 /* If there are no instructions which would be affected by this note,
21309 don't do anything. */
21311 && next_real
== NULL_RTX
21312 && !NOTE_DURING_CALL_P (loc_note
))
21315 if (next_real
== NULL_RTX
)
21316 next_real
= get_last_insn ();
21318 /* If there were any real insns between note we processed last time
21319 and this note (or if it is the first note), clear
21320 last_{,postcall_}label so that they are not reused this time. */
21321 if (last_var_location_insn
== NULL_RTX
21322 || last_var_location_insn
!= next_real
21323 || last_in_cold_section_p
!= in_cold_section_p
)
21326 last_postcall_label
= NULL
;
21331 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
21332 newloc
= add_var_loc_to_decl (decl
, loc_note
,
21333 NOTE_DURING_CALL_P (loc_note
)
21334 ? last_postcall_label
: last_label
);
21335 if (newloc
== NULL
)
21344 /* If there were no real insns between note we processed last time
21345 and this note, use the label we emitted last time. Otherwise
21346 create a new label and emit it. */
21347 if (last_label
== NULL
)
21349 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
21350 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
21352 last_label
= ggc_strdup (loclabel
);
21353 /* See if loclabel might be equal to .Ltext0. If yes,
21354 bump first_loclabel_num_not_at_text_label. */
21355 if (!have_multiple_function_sections
21356 && in_first_function_p
21357 && maybe_at_text_label_p
)
21359 static rtx last_start
;
21361 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
21362 if (insn
== last_start
)
21364 else if (!NONDEBUG_INSN_P (insn
))
21368 rtx body
= PATTERN (insn
);
21369 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
21371 /* Inline asm could occupy zero bytes. */
21372 else if (GET_CODE (body
) == ASM_INPUT
21373 || asm_noperands (body
) >= 0)
21375 #ifdef HAVE_attr_length
21376 else if (get_attr_min_length (insn
) == 0)
21381 /* Assume insn has non-zero length. */
21382 maybe_at_text_label_p
= false;
21386 if (maybe_at_text_label_p
)
21388 last_start
= loc_note
;
21389 first_loclabel_num_not_at_text_label
= loclabel_num
;
21396 struct call_arg_loc_node
*ca_loc
21397 = ggc_cleared_alloc
<call_arg_loc_node
> ();
21398 rtx prev
= prev_real_insn (loc_note
), x
;
21399 ca_loc
->call_arg_loc_note
= loc_note
;
21400 ca_loc
->next
= NULL
;
21401 ca_loc
->label
= last_label
;
21404 || (NONJUMP_INSN_P (prev
)
21405 && GET_CODE (PATTERN (prev
)) == SEQUENCE
21406 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
21407 if (!CALL_P (prev
))
21408 prev
= XVECEXP (PATTERN (prev
), 0, 0);
21409 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
21410 x
= get_call_rtx_from (PATTERN (prev
));
21413 x
= XEXP (XEXP (x
, 0), 0);
21414 if (GET_CODE (x
) == SYMBOL_REF
21415 && SYMBOL_REF_DECL (x
)
21416 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
21417 ca_loc
->symbol_ref
= x
;
21419 ca_loc
->block
= insn_scope (prev
);
21420 if (call_arg_locations
)
21421 call_arg_loc_last
->next
= ca_loc
;
21423 call_arg_locations
= ca_loc
;
21424 call_arg_loc_last
= ca_loc
;
21426 else if (!NOTE_DURING_CALL_P (loc_note
))
21427 newloc
->label
= last_label
;
21430 if (!last_postcall_label
)
21432 sprintf (loclabel
, "%s-1", last_label
);
21433 last_postcall_label
= ggc_strdup (loclabel
);
21435 newloc
->label
= last_postcall_label
;
21438 last_var_location_insn
= next_real
;
21439 last_in_cold_section_p
= in_cold_section_p
;
21442 /* Note in one location list that text section has changed. */
21445 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
21447 var_loc_list
*list
= (var_loc_list
*) *slot
;
21449 list
->last_before_switch
21450 = list
->last
->next
? list
->last
->next
: list
->last
;
21454 /* Note in all location lists that text section has changed. */
21457 var_location_switch_text_section (void)
21459 if (decl_loc_table
== NULL
)
21462 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
21465 /* Create a new line number table. */
21467 static dw_line_info_table
*
21468 new_line_info_table (void)
21470 dw_line_info_table
*table
;
21472 table
= ggc_cleared_alloc
<dw_line_info_table_struct
> ();
21473 table
->file_num
= 1;
21474 table
->line_num
= 1;
21475 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
21480 /* Lookup the "current" table into which we emit line info, so
21481 that we don't have to do it for every source line. */
21484 set_cur_line_info_table (section
*sec
)
21486 dw_line_info_table
*table
;
21488 if (sec
== text_section
)
21489 table
= text_section_line_info
;
21490 else if (sec
== cold_text_section
)
21492 table
= cold_text_section_line_info
;
21495 cold_text_section_line_info
= table
= new_line_info_table ();
21496 table
->end_label
= cold_end_label
;
21501 const char *end_label
;
21503 if (flag_reorder_blocks_and_partition
)
21505 if (in_cold_section_p
)
21506 end_label
= crtl
->subsections
.cold_section_end_label
;
21508 end_label
= crtl
->subsections
.hot_section_end_label
;
21512 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21513 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
21514 current_function_funcdef_no
);
21515 end_label
= ggc_strdup (label
);
21518 table
= new_line_info_table ();
21519 table
->end_label
= end_label
;
21521 vec_safe_push (separate_line_info
, table
);
21524 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21525 table
->is_stmt
= (cur_line_info_table
21526 ? cur_line_info_table
->is_stmt
21527 : DWARF_LINE_DEFAULT_IS_STMT_START
);
21528 cur_line_info_table
= table
;
21532 /* We need to reset the locations at the beginning of each
21533 function. We can't do this in the end_function hook, because the
21534 declarations that use the locations won't have been output when
21535 that hook is called. Also compute have_multiple_function_sections here. */
21538 dwarf2out_begin_function (tree fun
)
21540 section
*sec
= function_section (fun
);
21542 if (sec
!= text_section
)
21543 have_multiple_function_sections
= true;
21545 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
21547 gcc_assert (current_function_decl
== fun
);
21548 cold_text_section
= unlikely_text_section ();
21549 switch_to_section (cold_text_section
);
21550 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
21551 switch_to_section (sec
);
21554 dwarf2out_note_section_used ();
21555 call_site_count
= 0;
21556 tail_call_site_count
= 0;
21558 set_cur_line_info_table (sec
);
21561 /* Helper function of dwarf2out_end_function, called only after emitting
21562 the very first function into assembly. Check if some .debug_loc range
21563 might end with a .LVL* label that could be equal to .Ltext0.
21564 In that case we must force using absolute addresses in .debug_loc ranges,
21565 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
21566 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
21568 Set have_multiple_function_sections to true in that case and
21569 terminate htab traversal. */
21572 find_empty_loc_ranges_at_text_label (void **slot
, void *)
21574 var_loc_list
*entry
;
21575 struct var_loc_node
*node
;
21577 entry
= (var_loc_list
*) *slot
;
21578 node
= entry
->first
;
21579 if (node
&& node
->next
&& node
->next
->label
)
21582 const char *label
= node
->next
->label
;
21583 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
21585 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
21587 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
21588 if (strcmp (label
, loclabel
) == 0)
21590 have_multiple_function_sections
= true;
21598 /* Hook called after emitting a function into assembly.
21599 This does something only for the very first function emitted. */
21602 dwarf2out_end_function (unsigned int)
21604 if (in_first_function_p
21605 && !have_multiple_function_sections
21606 && first_loclabel_num_not_at_text_label
21608 htab_traverse (decl_loc_table
, find_empty_loc_ranges_at_text_label
,
21610 in_first_function_p
= false;
21611 maybe_at_text_label_p
= false;
21614 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
21617 push_dw_line_info_entry (dw_line_info_table
*table
,
21618 enum dw_line_info_opcode opcode
, unsigned int val
)
21620 dw_line_info_entry e
;
21623 vec_safe_push (table
->entries
, e
);
21626 /* Output a label to mark the beginning of a source code line entry
21627 and record information relating to this source line, in
21628 'line_info_table' for later output of the .debug_line section. */
21629 /* ??? The discriminator parameter ought to be unsigned. */
21632 dwarf2out_source_line (unsigned int line
, const char *filename
,
21633 int discriminator
, bool is_stmt
)
21635 unsigned int file_num
;
21636 dw_line_info_table
*table
;
21638 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
21641 /* The discriminator column was added in dwarf4. Simplify the below
21642 by simply removing it if we're not supposed to output it. */
21643 if (dwarf_version
< 4 && dwarf_strict
)
21646 table
= cur_line_info_table
;
21647 file_num
= maybe_emit_file (lookup_filename (filename
));
21649 /* ??? TODO: Elide duplicate line number entries. Traditionally,
21650 the debugger has used the second (possibly duplicate) line number
21651 at the beginning of the function to mark the end of the prologue.
21652 We could eliminate any other duplicates within the function. For
21653 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
21654 that second line number entry. */
21655 /* Recall that this end-of-prologue indication is *not* the same thing
21656 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
21657 to which the hook corresponds, follows the last insn that was
21658 emitted by gen_prologue. What we need is to precede the first insn
21659 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
21660 insn that corresponds to something the user wrote. These may be
21661 very different locations once scheduling is enabled. */
21663 if (0 && file_num
== table
->file_num
21664 && line
== table
->line_num
21665 && discriminator
== table
->discrim_num
21666 && is_stmt
== table
->is_stmt
)
21669 switch_to_section (current_function_section ());
21671 /* If requested, emit something human-readable. */
21672 if (flag_debug_asm
)
21673 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
21675 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21677 /* Emit the .loc directive understood by GNU as. */
21678 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
21679 file_num, line, is_stmt, discriminator */
21680 fputs ("\t.loc ", asm_out_file
);
21681 fprint_ul (asm_out_file
, file_num
);
21682 putc (' ', asm_out_file
);
21683 fprint_ul (asm_out_file
, line
);
21684 putc (' ', asm_out_file
);
21685 putc ('0', asm_out_file
);
21687 if (is_stmt
!= table
->is_stmt
)
21689 fputs (" is_stmt ", asm_out_file
);
21690 putc (is_stmt
? '1' : '0', asm_out_file
);
21692 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
21694 gcc_assert (discriminator
> 0);
21695 fputs (" discriminator ", asm_out_file
);
21696 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
21698 putc ('\n', asm_out_file
);
21702 unsigned int label_num
= ++line_info_label_num
;
21704 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
21706 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
21707 if (file_num
!= table
->file_num
)
21708 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
21709 if (discriminator
!= table
->discrim_num
)
21710 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
21711 if (is_stmt
!= table
->is_stmt
)
21712 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
21713 push_dw_line_info_entry (table
, LI_set_line
, line
);
21716 table
->file_num
= file_num
;
21717 table
->line_num
= line
;
21718 table
->discrim_num
= discriminator
;
21719 table
->is_stmt
= is_stmt
;
21720 table
->in_use
= true;
21723 /* Record the beginning of a new source file. */
21726 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21728 if (flag_eliminate_dwarf2_dups
)
21730 /* Record the beginning of the file for break_out_includes. */
21731 dw_die_ref bincl_die
;
21733 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
21734 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21737 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21740 e
.code
= DW_MACINFO_start_file
;
21742 e
.info
= ggc_strdup (filename
);
21743 vec_safe_push (macinfo_table
, e
);
21747 /* Record the end of a source file. */
21750 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21752 if (flag_eliminate_dwarf2_dups
)
21753 /* Record the end of the file for break_out_includes. */
21754 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
21756 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21759 e
.code
= DW_MACINFO_end_file
;
21762 vec_safe_push (macinfo_table
, e
);
21766 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21767 the tail part of the directive line, i.e. the part which is past the
21768 initial whitespace, #, whitespace, directive-name, whitespace part. */
21771 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
21772 const char *buffer ATTRIBUTE_UNUSED
)
21774 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21777 /* Insert a dummy first entry to be able to optimize the whole
21778 predefined macro block using DW_MACRO_GNU_transparent_include. */
21779 if (macinfo_table
->is_empty () && lineno
<= 1)
21784 vec_safe_push (macinfo_table
, e
);
21786 e
.code
= DW_MACINFO_define
;
21788 e
.info
= ggc_strdup (buffer
);
21789 vec_safe_push (macinfo_table
, e
);
21793 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21794 the tail part of the directive line, i.e. the part which is past the
21795 initial whitespace, #, whitespace, directive-name, whitespace part. */
21798 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21799 const char *buffer ATTRIBUTE_UNUSED
)
21801 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21804 /* Insert a dummy first entry to be able to optimize the whole
21805 predefined macro block using DW_MACRO_GNU_transparent_include. */
21806 if (macinfo_table
->is_empty () && lineno
<= 1)
21811 vec_safe_push (macinfo_table
, e
);
21813 e
.code
= DW_MACINFO_undef
;
21815 e
.info
= ggc_strdup (buffer
);
21816 vec_safe_push (macinfo_table
, e
);
21820 /* Helpers to manipulate hash table of CUs. */
21822 struct macinfo_entry_hasher
: typed_noop_remove
<macinfo_entry
>
21824 typedef macinfo_entry value_type
;
21825 typedef macinfo_entry compare_type
;
21826 static inline hashval_t
hash (const value_type
*);
21827 static inline bool equal (const value_type
*, const compare_type
*);
21831 macinfo_entry_hasher::hash (const value_type
*entry
)
21833 return htab_hash_string (entry
->info
);
21837 macinfo_entry_hasher::equal (const value_type
*entry1
,
21838 const compare_type
*entry2
)
21840 return !strcmp (entry1
->info
, entry2
->info
);
21843 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
21845 /* Output a single .debug_macinfo entry. */
21848 output_macinfo_op (macinfo_entry
*ref
)
21852 struct indirect_string_node
*node
;
21853 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21854 struct dwarf_file_data
*fd
;
21858 case DW_MACINFO_start_file
:
21859 fd
= lookup_filename (ref
->info
);
21860 file_num
= maybe_emit_file (fd
);
21861 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
21862 dw2_asm_output_data_uleb128 (ref
->lineno
,
21863 "Included from line number %lu",
21864 (unsigned long) ref
->lineno
);
21865 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
21867 case DW_MACINFO_end_file
:
21868 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
21870 case DW_MACINFO_define
:
21871 case DW_MACINFO_undef
:
21872 len
= strlen (ref
->info
) + 1;
21874 && len
> DWARF_OFFSET_SIZE
21875 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21876 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21878 ref
->code
= ref
->code
== DW_MACINFO_define
21879 ? DW_MACRO_GNU_define_indirect
21880 : DW_MACRO_GNU_undef_indirect
;
21881 output_macinfo_op (ref
);
21884 dw2_asm_output_data (1, ref
->code
,
21885 ref
->code
== DW_MACINFO_define
21886 ? "Define macro" : "Undefine macro");
21887 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21888 (unsigned long) ref
->lineno
);
21889 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
21891 case DW_MACRO_GNU_define_indirect
:
21892 case DW_MACRO_GNU_undef_indirect
:
21893 node
= find_AT_string (ref
->info
);
21895 && ((node
->form
== DW_FORM_strp
)
21896 || (node
->form
== DW_FORM_GNU_str_index
)));
21897 dw2_asm_output_data (1, ref
->code
,
21898 ref
->code
== DW_MACRO_GNU_define_indirect
21899 ? "Define macro indirect"
21900 : "Undefine macro indirect");
21901 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21902 (unsigned long) ref
->lineno
);
21903 if (node
->form
== DW_FORM_strp
)
21904 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
21905 debug_str_section
, "The macro: \"%s\"",
21908 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
21911 case DW_MACRO_GNU_transparent_include
:
21912 dw2_asm_output_data (1, ref
->code
, "Transparent include");
21913 ASM_GENERATE_INTERNAL_LABEL (label
,
21914 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
21915 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
21918 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
21919 ASM_COMMENT_START
, (unsigned long) ref
->code
);
21924 /* Attempt to make a sequence of define/undef macinfo ops shareable with
21925 other compilation unit .debug_macinfo sections. IDX is the first
21926 index of a define/undef, return the number of ops that should be
21927 emitted in a comdat .debug_macinfo section and emit
21928 a DW_MACRO_GNU_transparent_include entry referencing it.
21929 If the define/undef entry should be emitted normally, return 0. */
21932 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
21933 macinfo_hash_type
**macinfo_htab
)
21935 macinfo_entry
*first
, *second
, *cur
, *inc
;
21936 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
21937 unsigned char checksum
[16];
21938 struct md5_ctx ctx
;
21939 char *grp_name
, *tail
;
21941 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
21942 macinfo_entry
**slot
;
21944 first
= &(*macinfo_table
)[idx
];
21945 second
= &(*macinfo_table
)[idx
+ 1];
21947 /* Optimize only if there are at least two consecutive define/undef ops,
21948 and either all of them are before first DW_MACINFO_start_file
21949 with lineno {0,1} (i.e. predefined macro block), or all of them are
21950 in some included header file. */
21951 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
21953 if (vec_safe_is_empty (files
))
21955 if (first
->lineno
> 1 || second
->lineno
> 1)
21958 else if (first
->lineno
== 0)
21961 /* Find the last define/undef entry that can be grouped together
21962 with first and at the same time compute md5 checksum of their
21963 codes, linenumbers and strings. */
21964 md5_init_ctx (&ctx
);
21965 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
21966 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
21968 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
21972 unsigned char code
= cur
->code
;
21973 md5_process_bytes (&code
, 1, &ctx
);
21974 checksum_uleb128 (cur
->lineno
, &ctx
);
21975 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
21977 md5_finish_ctx (&ctx
, checksum
);
21980 /* From the containing include filename (if any) pick up just
21981 usable characters from its basename. */
21982 if (vec_safe_is_empty (files
))
21985 base
= lbasename (files
->last ().info
);
21986 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
21987 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21988 encoded_filename_len
++;
21989 /* Count . at the end. */
21990 if (encoded_filename_len
)
21991 encoded_filename_len
++;
21993 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
21994 linebuf_len
= strlen (linebuf
);
21996 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
21997 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
21999 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
22000 tail
= grp_name
+ 4;
22001 if (encoded_filename_len
)
22003 for (i
= 0; base
[i
]; i
++)
22004 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
22008 memcpy (tail
, linebuf
, linebuf_len
);
22009 tail
+= linebuf_len
;
22011 for (i
= 0; i
< 16; i
++)
22012 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
22014 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
22015 in the empty vector entry before the first define/undef. */
22016 inc
= &(*macinfo_table
)[idx
- 1];
22017 inc
->code
= DW_MACRO_GNU_transparent_include
;
22019 inc
->info
= ggc_strdup (grp_name
);
22020 if (!*macinfo_htab
)
22021 *macinfo_htab
= new macinfo_hash_type (10);
22022 /* Avoid emitting duplicates. */
22023 slot
= (*macinfo_htab
)->find_slot (inc
, INSERT
);
22028 /* If such an entry has been used before, just emit
22029 a DW_MACRO_GNU_transparent_include op. */
22031 output_macinfo_op (inc
);
22032 /* And clear all macinfo_entry in the range to avoid emitting them
22033 in the second pass. */
22034 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
22043 inc
->lineno
= (*macinfo_htab
)->elements ();
22044 output_macinfo_op (inc
);
22049 /* Save any strings needed by the macinfo table in the debug str
22050 table. All strings must be collected into the table by the time
22051 index_string is called. */
22054 save_macinfo_strings (void)
22058 macinfo_entry
*ref
;
22060 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
22064 /* Match the logic in output_macinfo_op to decide on
22065 indirect strings. */
22066 case DW_MACINFO_define
:
22067 case DW_MACINFO_undef
:
22068 len
= strlen (ref
->info
) + 1;
22070 && len
> DWARF_OFFSET_SIZE
22071 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
22072 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
22073 set_indirect_string (find_AT_string (ref
->info
));
22075 case DW_MACRO_GNU_define_indirect
:
22076 case DW_MACRO_GNU_undef_indirect
:
22077 set_indirect_string (find_AT_string (ref
->info
));
22085 /* Output macinfo section(s). */
22088 output_macinfo (void)
22091 unsigned long length
= vec_safe_length (macinfo_table
);
22092 macinfo_entry
*ref
;
22093 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
22094 macinfo_hash_type
*macinfo_htab
= NULL
;
22099 /* output_macinfo* uses these interchangeably. */
22100 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
22101 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
22102 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
22103 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
22105 /* For .debug_macro emit the section header. */
22108 dw2_asm_output_data (2, 4, "DWARF macro version number");
22109 if (DWARF_OFFSET_SIZE
== 8)
22110 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
22112 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
22113 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
22114 (!dwarf_split_debug_info
? debug_line_section_label
22115 : debug_skeleton_line_section_label
),
22116 debug_line_section
, NULL
);
22119 /* In the first loop, it emits the primary .debug_macinfo section
22120 and after each emitted op the macinfo_entry is cleared.
22121 If a longer range of define/undef ops can be optimized using
22122 DW_MACRO_GNU_transparent_include, the
22123 DW_MACRO_GNU_transparent_include op is emitted and kept in
22124 the vector before the first define/undef in the range and the
22125 whole range of define/undef ops is not emitted and kept. */
22126 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
22130 case DW_MACINFO_start_file
:
22131 vec_safe_push (files
, *ref
);
22133 case DW_MACINFO_end_file
:
22134 if (!vec_safe_is_empty (files
))
22137 case DW_MACINFO_define
:
22138 case DW_MACINFO_undef
:
22140 && HAVE_COMDAT_GROUP
22141 && vec_safe_length (files
) != 1
22144 && (*macinfo_table
)[i
- 1].code
== 0)
22146 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
22155 /* A dummy entry may be inserted at the beginning to be able
22156 to optimize the whole block of predefined macros. */
22162 output_macinfo_op (ref
);
22170 delete macinfo_htab
;
22171 macinfo_htab
= NULL
;
22173 /* If any DW_MACRO_GNU_transparent_include were used, on those
22174 DW_MACRO_GNU_transparent_include entries terminate the
22175 current chain and switch to a new comdat .debug_macinfo
22176 section and emit the define/undef entries within it. */
22177 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
22182 case DW_MACRO_GNU_transparent_include
:
22184 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22185 tree comdat_key
= get_identifier (ref
->info
);
22186 /* Terminate the previous .debug_macinfo section. */
22187 dw2_asm_output_data (1, 0, "End compilation unit");
22188 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
22190 | SECTION_LINKONCE
,
22192 ASM_GENERATE_INTERNAL_LABEL (label
,
22193 DEBUG_MACRO_SECTION_LABEL
,
22195 ASM_OUTPUT_LABEL (asm_out_file
, label
);
22198 dw2_asm_output_data (2, 4, "DWARF macro version number");
22199 if (DWARF_OFFSET_SIZE
== 8)
22200 dw2_asm_output_data (1, 1, "Flags: 64-bit");
22202 dw2_asm_output_data (1, 0, "Flags: 32-bit");
22205 case DW_MACINFO_define
:
22206 case DW_MACINFO_undef
:
22207 output_macinfo_op (ref
);
22212 gcc_unreachable ();
22216 /* Set up for Dwarf output at the start of compilation. */
22219 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
22221 /* Allocate the file_table. */
22222 file_table
= htab_create_ggc (50, file_table_hash
,
22223 file_table_eq
, NULL
);
22225 /* Allocate the decl_die_table. */
22226 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
22227 decl_die_table_eq
, NULL
);
22229 /* Allocate the decl_loc_table. */
22230 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
22231 decl_loc_table_eq
, NULL
);
22233 /* Allocate the cached_dw_loc_list_table. */
22234 cached_dw_loc_list_table
22235 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
22236 cached_dw_loc_list_table_eq
, NULL
);
22238 /* Allocate the initial hunk of the decl_scope_table. */
22239 vec_alloc (decl_scope_table
, 256);
22241 /* Allocate the initial hunk of the abbrev_die_table. */
22242 abbrev_die_table
= ggc_cleared_vec_alloc
<dw_die_ref
>
22243 (ABBREV_DIE_TABLE_INCREMENT
);
22244 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
22245 /* Zero-th entry is allocated, but unused. */
22246 abbrev_die_table_in_use
= 1;
22248 /* Allocate the pubtypes and pubnames vectors. */
22249 vec_alloc (pubname_table
, 32);
22250 vec_alloc (pubtype_table
, 32);
22252 vec_alloc (incomplete_types
, 64);
22254 vec_alloc (used_rtx_array
, 32);
22256 if (!dwarf_split_debug_info
)
22258 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
22259 SECTION_DEBUG
, NULL
);
22260 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
22261 SECTION_DEBUG
, NULL
);
22262 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
22263 SECTION_DEBUG
, NULL
);
22267 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
22268 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22269 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
22270 SECTION_DEBUG
| SECTION_EXCLUDE
,
22272 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
22273 SECTION_DEBUG
, NULL
);
22274 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
22275 SECTION_DEBUG
, NULL
);
22276 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
22277 SECTION_DEBUG
, NULL
);
22278 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
22279 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
22281 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
22282 the main .o, but the skeleton_line goes into the split off dwo. */
22283 debug_skeleton_line_section
22284 = get_section (DEBUG_DWO_LINE_SECTION
,
22285 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22286 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
22287 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
22288 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
22289 SECTION_DEBUG
| SECTION_EXCLUDE
,
22291 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
22292 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
22293 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
22294 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22295 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
22296 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
22298 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
22299 SECTION_DEBUG
, NULL
);
22300 debug_macinfo_section
= get_section (dwarf_strict
22301 ? DEBUG_MACINFO_SECTION
22302 : DEBUG_MACRO_SECTION
,
22303 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
22304 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
22305 SECTION_DEBUG
, NULL
);
22306 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
22307 SECTION_DEBUG
, NULL
);
22308 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
22309 SECTION_DEBUG
, NULL
);
22310 debug_str_section
= get_section (DEBUG_STR_SECTION
,
22311 DEBUG_STR_SECTION_FLAGS
, NULL
);
22312 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
22313 SECTION_DEBUG
, NULL
);
22314 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
22315 SECTION_DEBUG
, NULL
);
22317 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
22318 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
22319 DEBUG_ABBREV_SECTION_LABEL
, 0);
22320 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
22321 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
22322 COLD_TEXT_SECTION_LABEL
, 0);
22323 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
22325 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
22326 DEBUG_INFO_SECTION_LABEL
, 0);
22327 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
22328 DEBUG_LINE_SECTION_LABEL
, 0);
22329 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
22330 DEBUG_RANGES_SECTION_LABEL
, 0);
22331 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
22332 DEBUG_ADDR_SECTION_LABEL
, 0);
22333 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
22335 ? DEBUG_MACINFO_SECTION_LABEL
22336 : DEBUG_MACRO_SECTION_LABEL
, 0);
22337 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
22339 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22340 vec_alloc (macinfo_table
, 64);
22342 switch_to_section (text_section
);
22343 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
22345 /* Make sure the line number table for .text always exists. */
22346 text_section_line_info
= new_line_info_table ();
22347 text_section_line_info
->end_label
= text_end_label
;
22350 /* Called before compile () starts outputtting functions, variables
22351 and toplevel asms into assembly. */
22354 dwarf2out_assembly_start (void)
22356 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
22357 && dwarf2out_do_cfi_asm ()
22358 && (!(flag_unwind_tables
|| flag_exceptions
)
22359 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
22360 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
22363 /* A helper function for dwarf2out_finish called through
22364 htab_traverse. Assign a string its index. All strings must be
22365 collected into the table by the time index_string is called,
22366 because the indexing code relies on htab_traverse to traverse nodes
22367 in the same order for each run. */
22370 index_string (void **h
, void *v
)
22372 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22373 unsigned int *index
= (unsigned int *) v
;
22375 find_string_form (node
);
22376 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22378 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
22379 node
->index
= *index
;
22385 /* A helper function for output_indirect_strings called through
22386 htab_traverse. Output the offset to a string and update the
22390 output_index_string_offset (void **h
, void *v
)
22392 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22393 unsigned int *offset
= (unsigned int *) v
;
22395 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22397 /* Assert that this node has been assigned an index. */
22398 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
22399 && node
->index
!= NOT_INDEXED
);
22400 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
22401 "indexed string 0x%x: %s", node
->index
, node
->str
);
22402 *offset
+= strlen (node
->str
) + 1;
22407 /* A helper function for dwarf2out_finish called through
22408 htab_traverse. Output the indexed string. */
22411 output_index_string (void **h
, void *v
)
22413 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22414 unsigned int *cur_idx
= (unsigned int *) v
;
22416 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22418 /* Assert that the strings are output in the same order as their
22419 indexes were assigned. */
22420 gcc_assert (*cur_idx
== node
->index
);
22421 assemble_string (node
->str
, strlen (node
->str
) + 1);
22427 /* A helper function for dwarf2out_finish called through
22428 htab_traverse. Emit one queued .debug_str string. */
22431 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
22433 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22435 node
->form
= find_string_form (node
);
22436 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
22438 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
22439 assemble_string (node
->str
, strlen (node
->str
) + 1);
22445 /* Output the indexed string table. */
22448 output_indirect_strings (void)
22450 switch_to_section (debug_str_section
);
22451 if (!dwarf_split_debug_info
)
22452 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
22455 unsigned int offset
= 0;
22456 unsigned int cur_idx
= 0;
22458 htab_traverse (skeleton_debug_str_hash
, output_indirect_string
, NULL
);
22460 switch_to_section (debug_str_offsets_section
);
22461 htab_traverse_noresize (debug_str_hash
,
22462 output_index_string_offset
,
22464 switch_to_section (debug_str_dwo_section
);
22465 htab_traverse_noresize (debug_str_hash
,
22466 output_index_string
,
22471 /* Callback for htab_traverse to assign an index to an entry in the
22472 table, and to write that entry to the .debug_addr section. */
22475 output_addr_table_entry (void **slot
, void *data
)
22477 addr_table_entry
*entry
= (addr_table_entry
*) *slot
;
22478 unsigned int *cur_index
= (unsigned int *)data
;
22480 if (entry
->refcount
== 0)
22482 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
22483 || entry
->index
== NOT_INDEXED
);
22487 gcc_assert (entry
->index
== *cur_index
);
22490 switch (entry
->kind
)
22493 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
22494 "0x%x", entry
->index
);
22496 case ate_kind_rtx_dtprel
:
22497 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
22498 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
22501 fputc ('\n', asm_out_file
);
22503 case ate_kind_label
:
22504 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
22505 "0x%x", entry
->index
);
22508 gcc_unreachable ();
22513 /* Produce the .debug_addr section. */
22516 output_addr_table (void)
22518 unsigned int index
= 0;
22519 if (addr_index_table
== NULL
|| htab_size (addr_index_table
) == 0)
22522 switch_to_section (debug_addr_section
);
22523 htab_traverse_noresize (addr_index_table
, output_addr_table_entry
, &index
);
22526 #if ENABLE_ASSERT_CHECKING
22527 /* Verify that all marks are clear. */
22530 verify_marks_clear (dw_die_ref die
)
22534 gcc_assert (! die
->die_mark
);
22535 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
22537 #endif /* ENABLE_ASSERT_CHECKING */
22539 /* Clear the marks for a die and its children.
22540 Be cool if the mark isn't set. */
22543 prune_unmark_dies (dw_die_ref die
)
22549 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
22552 /* Given DIE that we're marking as used, find any other dies
22553 it references as attributes and mark them as used. */
22556 prune_unused_types_walk_attribs (dw_die_ref die
)
22561 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22563 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
22565 /* A reference to another DIE.
22566 Make sure that it will get emitted.
22567 If it was broken out into a comdat group, don't follow it. */
22568 if (! AT_ref (a
)->comdat_type_p
22569 || a
->dw_attr
== DW_AT_specification
)
22570 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
22572 /* Set the string's refcount to 0 so that prune_unused_types_mark
22573 accounts properly for it. */
22574 if (AT_class (a
) == dw_val_class_str
)
22575 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
22579 /* Mark the generic parameters and arguments children DIEs of DIE. */
22582 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
22586 if (die
== NULL
|| die
->die_child
== NULL
)
22588 c
= die
->die_child
;
22591 if (is_template_parameter (c
))
22592 prune_unused_types_mark (c
, 1);
22594 } while (c
&& c
!= die
->die_child
);
22597 /* Mark DIE as being used. If DOKIDS is true, then walk down
22598 to DIE's children. */
22601 prune_unused_types_mark (dw_die_ref die
, int dokids
)
22605 if (die
->die_mark
== 0)
22607 /* We haven't done this node yet. Mark it as used. */
22609 /* If this is the DIE of a generic type instantiation,
22610 mark the children DIEs that describe its generic parms and
22612 prune_unused_types_mark_generic_parms_dies (die
);
22614 /* We also have to mark its parents as used.
22615 (But we don't want to mark our parent's kids due to this,
22616 unless it is a class.) */
22617 if (die
->die_parent
)
22618 prune_unused_types_mark (die
->die_parent
,
22619 class_scope_p (die
->die_parent
));
22621 /* Mark any referenced nodes. */
22622 prune_unused_types_walk_attribs (die
);
22624 /* If this node is a specification,
22625 also mark the definition, if it exists. */
22626 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
22627 prune_unused_types_mark (die
->die_definition
, 1);
22630 if (dokids
&& die
->die_mark
!= 2)
22632 /* We need to walk the children, but haven't done so yet.
22633 Remember that we've walked the kids. */
22636 /* If this is an array type, we need to make sure our
22637 kids get marked, even if they're types. If we're
22638 breaking out types into comdat sections, do this
22639 for all type definitions. */
22640 if (die
->die_tag
== DW_TAG_array_type
22641 || (use_debug_types
22642 && is_type_die (die
) && ! is_declaration_die (die
)))
22643 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
22645 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22649 /* For local classes, look if any static member functions were emitted
22650 and if so, mark them. */
22653 prune_unused_types_walk_local_classes (dw_die_ref die
)
22657 if (die
->die_mark
== 2)
22660 switch (die
->die_tag
)
22662 case DW_TAG_structure_type
:
22663 case DW_TAG_union_type
:
22664 case DW_TAG_class_type
:
22667 case DW_TAG_subprogram
:
22668 if (!get_AT_flag (die
, DW_AT_declaration
)
22669 || die
->die_definition
!= NULL
)
22670 prune_unused_types_mark (die
, 1);
22677 /* Mark children. */
22678 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
22681 /* Walk the tree DIE and mark types that we actually use. */
22684 prune_unused_types_walk (dw_die_ref die
)
22688 /* Don't do anything if this node is already marked and
22689 children have been marked as well. */
22690 if (die
->die_mark
== 2)
22693 switch (die
->die_tag
)
22695 case DW_TAG_structure_type
:
22696 case DW_TAG_union_type
:
22697 case DW_TAG_class_type
:
22698 if (die
->die_perennial_p
)
22701 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
22702 if (c
->die_tag
== DW_TAG_subprogram
)
22705 /* Finding used static member functions inside of classes
22706 is needed just for local classes, because for other classes
22707 static member function DIEs with DW_AT_specification
22708 are emitted outside of the DW_TAG_*_type. If we ever change
22709 it, we'd need to call this even for non-local classes. */
22711 prune_unused_types_walk_local_classes (die
);
22713 /* It's a type node --- don't mark it. */
22716 case DW_TAG_const_type
:
22717 case DW_TAG_packed_type
:
22718 case DW_TAG_pointer_type
:
22719 case DW_TAG_reference_type
:
22720 case DW_TAG_rvalue_reference_type
:
22721 case DW_TAG_volatile_type
:
22722 case DW_TAG_typedef
:
22723 case DW_TAG_array_type
:
22724 case DW_TAG_interface_type
:
22725 case DW_TAG_friend
:
22726 case DW_TAG_variant_part
:
22727 case DW_TAG_enumeration_type
:
22728 case DW_TAG_subroutine_type
:
22729 case DW_TAG_string_type
:
22730 case DW_TAG_set_type
:
22731 case DW_TAG_subrange_type
:
22732 case DW_TAG_ptr_to_member_type
:
22733 case DW_TAG_file_type
:
22734 if (die
->die_perennial_p
)
22737 /* It's a type node --- don't mark it. */
22741 /* Mark everything else. */
22745 if (die
->die_mark
== 0)
22749 /* Now, mark any dies referenced from here. */
22750 prune_unused_types_walk_attribs (die
);
22755 /* Mark children. */
22756 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22759 /* Increment the string counts on strings referred to from DIE's
22763 prune_unused_types_update_strings (dw_die_ref die
)
22768 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22769 if (AT_class (a
) == dw_val_class_str
)
22771 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22773 /* Avoid unnecessarily putting strings that are used less than
22774 twice in the hash table. */
22776 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22779 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22780 htab_hash_string (s
->str
),
22782 gcc_assert (*slot
== NULL
);
22788 /* Remove from the tree DIE any dies that aren't marked. */
22791 prune_unused_types_prune (dw_die_ref die
)
22795 gcc_assert (die
->die_mark
);
22796 prune_unused_types_update_strings (die
);
22798 if (! die
->die_child
)
22801 c
= die
->die_child
;
22803 dw_die_ref prev
= c
;
22804 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22805 if (c
== die
->die_child
)
22807 /* No marked children between 'prev' and the end of the list. */
22809 /* No marked children at all. */
22810 die
->die_child
= NULL
;
22813 prev
->die_sib
= c
->die_sib
;
22814 die
->die_child
= prev
;
22819 if (c
!= prev
->die_sib
)
22821 prune_unused_types_prune (c
);
22822 } while (c
!= die
->die_child
);
22825 /* Remove dies representing declarations that we never use. */
22828 prune_unused_types (void)
22831 limbo_die_node
*node
;
22832 comdat_type_node
*ctnode
;
22834 dw_die_ref base_type
;
22836 #if ENABLE_ASSERT_CHECKING
22837 /* All the marks should already be clear. */
22838 verify_marks_clear (comp_unit_die ());
22839 for (node
= limbo_die_list
; node
; node
= node
->next
)
22840 verify_marks_clear (node
->die
);
22841 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22842 verify_marks_clear (ctnode
->root_die
);
22843 #endif /* ENABLE_ASSERT_CHECKING */
22845 /* Mark types that are used in global variables. */
22846 premark_types_used_by_global_vars ();
22848 /* Set the mark on nodes that are actually used. */
22849 prune_unused_types_walk (comp_unit_die ());
22850 for (node
= limbo_die_list
; node
; node
= node
->next
)
22851 prune_unused_types_walk (node
->die
);
22852 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22854 prune_unused_types_walk (ctnode
->root_die
);
22855 prune_unused_types_mark (ctnode
->type_die
, 1);
22858 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
22859 are unusual in that they are pubnames that are the children of pubtypes.
22860 They should only be marked via their parent DW_TAG_enumeration_type die,
22861 not as roots in themselves. */
22862 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
22863 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
22864 prune_unused_types_mark (pub
->die
, 1);
22865 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22866 prune_unused_types_mark (base_type
, 1);
22868 if (debug_str_hash
)
22869 htab_empty (debug_str_hash
);
22870 if (skeleton_debug_str_hash
)
22871 htab_empty (skeleton_debug_str_hash
);
22872 prune_unused_types_prune (comp_unit_die ());
22873 for (node
= limbo_die_list
; node
; node
= node
->next
)
22874 prune_unused_types_prune (node
->die
);
22875 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22876 prune_unused_types_prune (ctnode
->root_die
);
22878 /* Leave the marks clear. */
22879 prune_unmark_dies (comp_unit_die ());
22880 for (node
= limbo_die_list
; node
; node
= node
->next
)
22881 prune_unmark_dies (node
->die
);
22882 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22883 prune_unmark_dies (ctnode
->root_die
);
22886 /* Set the parameter to true if there are any relative pathnames in
22889 file_table_relative_p (void ** slot
, void *param
)
22891 bool *p
= (bool *) param
;
22892 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22893 if (!IS_ABSOLUTE_PATH (d
->filename
))
22901 /* Helpers to manipulate hash table of comdat type units. */
22903 struct comdat_type_hasher
: typed_noop_remove
<comdat_type_node
>
22905 typedef comdat_type_node value_type
;
22906 typedef comdat_type_node compare_type
;
22907 static inline hashval_t
hash (const value_type
*);
22908 static inline bool equal (const value_type
*, const compare_type
*);
22912 comdat_type_hasher::hash (const value_type
*type_node
)
22915 memcpy (&h
, type_node
->signature
, sizeof (h
));
22920 comdat_type_hasher::equal (const value_type
*type_node_1
,
22921 const compare_type
*type_node_2
)
22923 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22924 DWARF_TYPE_SIGNATURE_SIZE
));
22927 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22928 to the location it would have been added, should we know its
22929 DECL_ASSEMBLER_NAME when we added other attributes. This will
22930 probably improve compactness of debug info, removing equivalent
22931 abbrevs, and hide any differences caused by deferring the
22932 computation of the assembler name, triggered by e.g. PCH. */
22935 move_linkage_attr (dw_die_ref die
)
22937 unsigned ix
= vec_safe_length (die
->die_attr
);
22938 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
22940 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22941 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22945 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
22947 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22951 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
22953 die
->die_attr
->pop ();
22954 die
->die_attr
->quick_insert (ix
, linkage
);
22958 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
22959 referenced from typed stack ops and count how often they are used. */
22962 mark_base_types (dw_loc_descr_ref loc
)
22964 dw_die_ref base_type
= NULL
;
22966 for (; loc
; loc
= loc
->dw_loc_next
)
22968 switch (loc
->dw_loc_opc
)
22970 case DW_OP_GNU_regval_type
:
22971 case DW_OP_GNU_deref_type
:
22972 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22974 case DW_OP_GNU_convert
:
22975 case DW_OP_GNU_reinterpret
:
22976 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
22979 case DW_OP_GNU_const_type
:
22980 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22982 case DW_OP_GNU_entry_value
:
22983 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
22988 gcc_assert (base_type
->die_parent
== comp_unit_die ());
22989 if (base_type
->die_mark
)
22990 base_type
->die_mark
++;
22993 base_types
.safe_push (base_type
);
22994 base_type
->die_mark
= 1;
22999 /* Comparison function for sorting marked base types. */
23002 base_type_cmp (const void *x
, const void *y
)
23004 dw_die_ref dx
= *(const dw_die_ref
*) x
;
23005 dw_die_ref dy
= *(const dw_die_ref
*) y
;
23006 unsigned int byte_size1
, byte_size2
;
23007 unsigned int encoding1
, encoding2
;
23008 if (dx
->die_mark
> dy
->die_mark
)
23010 if (dx
->die_mark
< dy
->die_mark
)
23012 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
23013 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
23014 if (byte_size1
< byte_size2
)
23016 if (byte_size1
> byte_size2
)
23018 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
23019 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
23020 if (encoding1
< encoding2
)
23022 if (encoding1
> encoding2
)
23027 /* Move base types marked by mark_base_types as early as possible
23028 in the CU, sorted by decreasing usage count both to make the
23029 uleb128 references as small as possible and to make sure they
23030 will have die_offset already computed by calc_die_sizes when
23031 sizes of typed stack loc ops is computed. */
23034 move_marked_base_types (void)
23037 dw_die_ref base_type
, die
, c
;
23039 if (base_types
.is_empty ())
23042 /* Sort by decreasing usage count, they will be added again in that
23044 base_types
.qsort (base_type_cmp
);
23045 die
= comp_unit_die ();
23046 c
= die
->die_child
;
23049 dw_die_ref prev
= c
;
23051 while (c
->die_mark
)
23053 remove_child_with_prev (c
, prev
);
23054 /* As base types got marked, there must be at least
23055 one node other than DW_TAG_base_type. */
23056 gcc_assert (c
!= c
->die_sib
);
23060 while (c
!= die
->die_child
);
23061 gcc_assert (die
->die_child
);
23062 c
= die
->die_child
;
23063 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
23065 base_type
->die_mark
= 0;
23066 base_type
->die_sib
= c
->die_sib
;
23067 c
->die_sib
= base_type
;
23072 /* Helper function for resolve_addr, attempt to resolve
23073 one CONST_STRING, return non-zero if not successful. Similarly verify that
23074 SYMBOL_REFs refer to variables emitted in the current CU. */
23077 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
23081 if (GET_CODE (rtl
) == CONST_STRING
)
23083 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
23084 tree t
= build_string (len
, XSTR (rtl
, 0));
23085 tree tlen
= size_int (len
- 1);
23087 = build_array_type (char_type_node
, build_index_type (tlen
));
23088 rtl
= lookup_constant_def (t
);
23089 if (!rtl
|| !MEM_P (rtl
))
23091 rtl
= XEXP (rtl
, 0);
23092 if (GET_CODE (rtl
) == SYMBOL_REF
23093 && SYMBOL_REF_DECL (rtl
)
23094 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
23096 vec_safe_push (used_rtx_array
, rtl
);
23101 if (GET_CODE (rtl
) == SYMBOL_REF
23102 && SYMBOL_REF_DECL (rtl
))
23104 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
23106 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
23109 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
23113 if (GET_CODE (rtl
) == CONST
23114 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
23120 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
23121 if possible, and create DW_TAG_dwarf_procedure that can be referenced
23122 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
23125 string_cst_pool_decl (tree t
)
23127 rtx rtl
= output_constant_def (t
, 1);
23128 unsigned char *array
;
23129 dw_loc_descr_ref l
;
23134 if (!rtl
|| !MEM_P (rtl
))
23136 rtl
= XEXP (rtl
, 0);
23137 if (GET_CODE (rtl
) != SYMBOL_REF
23138 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
23141 decl
= SYMBOL_REF_DECL (rtl
);
23142 if (!lookup_decl_die (decl
))
23144 len
= TREE_STRING_LENGTH (t
);
23145 vec_safe_push (used_rtx_array
, rtl
);
23146 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
23147 array
= ggc_vec_alloc
<unsigned char> (len
);
23148 memcpy (array
, TREE_STRING_POINTER (t
), len
);
23149 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
23150 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
23151 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
23152 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
23153 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
23154 add_AT_loc (ref
, DW_AT_location
, l
);
23155 equate_decl_number_to_die (decl
, ref
);
23160 /* Helper function of resolve_addr_in_expr. LOC is
23161 a DW_OP_addr followed by DW_OP_stack_value, either at the start
23162 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
23163 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
23164 with DW_OP_GNU_implicit_pointer if possible
23165 and return true, if unsuccessful, return false. */
23168 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
23170 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
23171 HOST_WIDE_INT offset
= 0;
23172 dw_die_ref ref
= NULL
;
23175 if (GET_CODE (rtl
) == CONST
23176 && GET_CODE (XEXP (rtl
, 0)) == PLUS
23177 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
23179 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
23180 rtl
= XEXP (XEXP (rtl
, 0), 0);
23182 if (GET_CODE (rtl
) == CONST_STRING
)
23184 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
23185 tree t
= build_string (len
, XSTR (rtl
, 0));
23186 tree tlen
= size_int (len
- 1);
23189 = build_array_type (char_type_node
, build_index_type (tlen
));
23190 rtl
= string_cst_pool_decl (t
);
23194 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
23196 decl
= SYMBOL_REF_DECL (rtl
);
23197 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
23199 ref
= lookup_decl_die (decl
);
23200 if (ref
&& (get_AT (ref
, DW_AT_location
)
23201 || get_AT (ref
, DW_AT_const_value
)))
23203 loc
->dw_loc_opc
= DW_OP_GNU_implicit_pointer
;
23204 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23205 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
23206 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23207 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23208 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
23209 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
23217 /* Helper function for resolve_addr, handle one location
23218 expression, return false if at least one CONST_STRING or SYMBOL_REF in
23219 the location list couldn't be resolved. */
23222 resolve_addr_in_expr (dw_loc_descr_ref loc
)
23224 dw_loc_descr_ref keep
= NULL
;
23225 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
23226 switch (loc
->dw_loc_opc
)
23229 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
23232 || prev
->dw_loc_opc
== DW_OP_piece
23233 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
23234 && loc
->dw_loc_next
23235 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
23237 && optimize_one_addr_into_implicit_ptr (loc
))
23242 case DW_OP_GNU_addr_index
:
23243 case DW_OP_GNU_const_index
:
23244 if (loc
->dw_loc_opc
== DW_OP_GNU_addr_index
23245 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
23247 rtx rtl
= loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
;
23248 if (resolve_one_addr (&rtl
, NULL
))
23250 remove_addr_table_entry (loc
->dw_loc_oprnd1
.val_entry
);
23251 loc
->dw_loc_oprnd1
.val_entry
=
23252 add_addr_table_entry (rtl
, ate_kind_rtx
);
23255 case DW_OP_const4u
:
23256 case DW_OP_const8u
:
23258 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
23261 case DW_OP_plus_uconst
:
23262 if (size_of_loc_descr (loc
)
23263 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
23265 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
23267 dw_loc_descr_ref repl
23268 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
23269 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
23270 add_loc_descr (&repl
, loc
->dw_loc_next
);
23274 case DW_OP_implicit_value
:
23275 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
23276 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
23279 case DW_OP_GNU_implicit_pointer
:
23280 case DW_OP_GNU_parameter_ref
:
23281 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
23284 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
23287 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23288 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23289 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23292 case DW_OP_GNU_const_type
:
23293 case DW_OP_GNU_regval_type
:
23294 case DW_OP_GNU_deref_type
:
23295 case DW_OP_GNU_convert
:
23296 case DW_OP_GNU_reinterpret
:
23297 while (loc
->dw_loc_next
23298 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
23300 dw_die_ref base1
, base2
;
23301 unsigned enc1
, enc2
, size1
, size2
;
23302 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
23303 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
23304 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
23305 else if (loc
->dw_loc_oprnd1
.val_class
23306 == dw_val_class_unsigned_const
)
23309 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23310 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
23311 == dw_val_class_unsigned_const
)
23313 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23314 gcc_assert (base1
->die_tag
== DW_TAG_base_type
23315 && base2
->die_tag
== DW_TAG_base_type
);
23316 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
23317 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
23318 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
23319 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
23321 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
23322 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
23326 /* Optimize away next DW_OP_GNU_convert after
23327 adjusting LOC's base type die reference. */
23328 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
23329 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
23330 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
23332 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
23333 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
23336 /* Don't change integer DW_OP_GNU_convert after e.g. floating
23337 point typed stack entry. */
23338 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
23339 keep
= loc
->dw_loc_next
;
23349 /* Helper function of resolve_addr. DIE had DW_AT_location of
23350 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
23351 and DW_OP_addr couldn't be resolved. resolve_addr has already
23352 removed the DW_AT_location attribute. This function attempts to
23353 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
23354 to it or DW_AT_const_value attribute, if possible. */
23357 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
23359 if (TREE_CODE (decl
) != VAR_DECL
23360 || lookup_decl_die (decl
) != die
23361 || DECL_EXTERNAL (decl
)
23362 || !TREE_STATIC (decl
)
23363 || DECL_INITIAL (decl
) == NULL_TREE
23364 || DECL_P (DECL_INITIAL (decl
))
23365 || get_AT (die
, DW_AT_const_value
))
23368 tree init
= DECL_INITIAL (decl
);
23369 HOST_WIDE_INT offset
= 0;
23370 /* For variables that have been optimized away and thus
23371 don't have a memory location, see if we can emit
23372 DW_AT_const_value instead. */
23373 if (tree_add_const_value_attribute (die
, init
))
23377 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
23378 and ADDR_EXPR refers to a decl that has DW_AT_location or
23379 DW_AT_const_value (but isn't addressable, otherwise
23380 resolving the original DW_OP_addr wouldn't fail), see if
23381 we can add DW_OP_GNU_implicit_pointer. */
23383 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
23384 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
23386 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
23387 init
= TREE_OPERAND (init
, 0);
23390 if (TREE_CODE (init
) != ADDR_EXPR
)
23392 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
23393 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
23394 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
23395 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
23396 && TREE_OPERAND (init
, 0) != decl
))
23399 dw_loc_descr_ref l
;
23401 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
23403 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
23406 decl
= SYMBOL_REF_DECL (rtl
);
23409 decl
= TREE_OPERAND (init
, 0);
23410 ref
= lookup_decl_die (decl
);
23412 || (!get_AT (ref
, DW_AT_location
)
23413 && !get_AT (ref
, DW_AT_const_value
)))
23415 l
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
23416 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23417 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23418 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23419 add_AT_loc (die
, DW_AT_location
, l
);
23423 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
23424 an address in .rodata section if the string literal is emitted there,
23425 or remove the containing location list or replace DW_AT_const_value
23426 with DW_AT_location and empty location expression, if it isn't found
23427 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
23428 to something that has been emitted in the current CU. */
23431 resolve_addr (dw_die_ref die
)
23435 dw_loc_list_ref
*curr
, *start
, loc
;
23438 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23439 switch (AT_class (a
))
23441 case dw_val_class_loc_list
:
23442 start
= curr
= AT_loc_list_ptr (a
);
23445 /* The same list can be referenced more than once. See if we have
23446 already recorded the result from a previous pass. */
23448 *curr
= loc
->dw_loc_next
;
23449 else if (!loc
->resolved_addr
)
23451 /* As things stand, we do not expect or allow one die to
23452 reference a suffix of another die's location list chain.
23453 References must be identical or completely separate.
23454 There is therefore no need to cache the result of this
23455 pass on any list other than the first; doing so
23456 would lead to unnecessary writes. */
23459 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
23460 if (!resolve_addr_in_expr ((*curr
)->expr
))
23462 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
23463 dw_loc_descr_ref l
= (*curr
)->expr
;
23465 if (next
&& (*curr
)->ll_symbol
)
23467 gcc_assert (!next
->ll_symbol
);
23468 next
->ll_symbol
= (*curr
)->ll_symbol
;
23470 if (dwarf_split_debug_info
)
23471 remove_loc_list_addr_table_entries (l
);
23476 mark_base_types ((*curr
)->expr
);
23477 curr
= &(*curr
)->dw_loc_next
;
23481 loc
->resolved_addr
= 1;
23485 loc
->dw_loc_next
= *start
;
23490 remove_AT (die
, a
->dw_attr
);
23494 case dw_val_class_loc
:
23496 dw_loc_descr_ref l
= AT_loc (a
);
23497 /* For -gdwarf-2 don't attempt to optimize
23498 DW_AT_data_member_location containing
23499 DW_OP_plus_uconst - older consumers might
23500 rely on it being that op instead of a more complex,
23501 but shorter, location description. */
23502 if ((dwarf_version
> 2
23503 || a
->dw_attr
!= DW_AT_data_member_location
23505 || l
->dw_loc_opc
!= DW_OP_plus_uconst
23506 || l
->dw_loc_next
!= NULL
)
23507 && !resolve_addr_in_expr (l
))
23509 if (dwarf_split_debug_info
)
23510 remove_loc_list_addr_table_entries (l
);
23512 && l
->dw_loc_next
== NULL
23513 && l
->dw_loc_opc
== DW_OP_addr
23514 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
23515 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
23516 && a
->dw_attr
== DW_AT_location
)
23518 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
23519 remove_AT (die
, a
->dw_attr
);
23521 optimize_location_into_implicit_ptr (die
, decl
);
23524 remove_AT (die
, a
->dw_attr
);
23528 mark_base_types (l
);
23531 case dw_val_class_addr
:
23532 if (a
->dw_attr
== DW_AT_const_value
23533 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
23535 if (AT_index (a
) != NOT_INDEXED
)
23536 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23537 remove_AT (die
, a
->dw_attr
);
23540 if (die
->die_tag
== DW_TAG_GNU_call_site
23541 && a
->dw_attr
== DW_AT_abstract_origin
)
23543 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
23544 dw_die_ref tdie
= lookup_decl_die (tdecl
);
23546 && DECL_EXTERNAL (tdecl
)
23547 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
23549 force_decl_die (tdecl
);
23550 tdie
= lookup_decl_die (tdecl
);
23554 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
23555 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
23556 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
23560 if (AT_index (a
) != NOT_INDEXED
)
23561 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23562 remove_AT (die
, a
->dw_attr
);
23571 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
23574 /* Helper routines for optimize_location_lists.
23575 This pass tries to share identical local lists in .debug_loc
23578 /* Iteratively hash operands of LOC opcode into HSTATE. */
23581 hash_loc_operands (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
23583 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
23584 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
23586 switch (loc
->dw_loc_opc
)
23588 case DW_OP_const4u
:
23589 case DW_OP_const8u
:
23593 case DW_OP_const1u
:
23594 case DW_OP_const1s
:
23595 case DW_OP_const2u
:
23596 case DW_OP_const2s
:
23597 case DW_OP_const4s
:
23598 case DW_OP_const8s
:
23602 case DW_OP_plus_uconst
:
23638 case DW_OP_deref_size
:
23639 case DW_OP_xderef_size
:
23640 hstate
.add_object (val1
->v
.val_int
);
23647 gcc_assert (val1
->val_class
== dw_val_class_loc
);
23648 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
23649 hstate
.add_object (offset
);
23652 case DW_OP_implicit_value
:
23653 hstate
.add_object (val1
->v
.val_unsigned
);
23654 switch (val2
->val_class
)
23656 case dw_val_class_const
:
23657 hstate
.add_object (val2
->v
.val_int
);
23659 case dw_val_class_vec
:
23661 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23662 unsigned int len
= val2
->v
.val_vec
.length
;
23664 hstate
.add_int (elt_size
);
23665 hstate
.add_int (len
);
23666 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
23669 case dw_val_class_const_double
:
23670 hstate
.add_object (val2
->v
.val_double
.low
);
23671 hstate
.add_object (val2
->v
.val_double
.high
);
23673 case dw_val_class_wide_int
:
23674 hstate
.add_object (*val2
->v
.val_wide
);
23676 case dw_val_class_addr
:
23677 inchash::add_rtx (val2
->v
.val_addr
, hstate
);
23680 gcc_unreachable ();
23684 case DW_OP_bit_piece
:
23685 hstate
.add_object (val1
->v
.val_int
);
23686 hstate
.add_object (val2
->v
.val_int
);
23692 unsigned char dtprel
= 0xd1;
23693 hstate
.add_object (dtprel
);
23695 inchash::add_rtx (val1
->v
.val_addr
, hstate
);
23697 case DW_OP_GNU_addr_index
:
23698 case DW_OP_GNU_const_index
:
23702 unsigned char dtprel
= 0xd1;
23703 hstate
.add_object (dtprel
);
23705 inchash::add_rtx (val1
->val_entry
->addr
.rtl
, hstate
);
23708 case DW_OP_GNU_implicit_pointer
:
23709 hstate
.add_int (val2
->v
.val_int
);
23711 case DW_OP_GNU_entry_value
:
23712 hstate
.add_object (val1
->v
.val_loc
);
23714 case DW_OP_GNU_regval_type
:
23715 case DW_OP_GNU_deref_type
:
23717 unsigned int byte_size
23718 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23719 unsigned int encoding
23720 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
23721 hstate
.add_object (val1
->v
.val_int
);
23722 hstate
.add_object (byte_size
);
23723 hstate
.add_object (encoding
);
23726 case DW_OP_GNU_convert
:
23727 case DW_OP_GNU_reinterpret
:
23728 if (val1
->val_class
== dw_val_class_unsigned_const
)
23730 hstate
.add_object (val1
->v
.val_unsigned
);
23734 case DW_OP_GNU_const_type
:
23736 unsigned int byte_size
23737 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23738 unsigned int encoding
23739 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
23740 hstate
.add_object (byte_size
);
23741 hstate
.add_object (encoding
);
23742 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
23744 hstate
.add_object (val2
->val_class
);
23745 switch (val2
->val_class
)
23747 case dw_val_class_const
:
23748 hstate
.add_object (val2
->v
.val_int
);
23750 case dw_val_class_vec
:
23752 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23753 unsigned int len
= val2
->v
.val_vec
.length
;
23755 hstate
.add_object (elt_size
);
23756 hstate
.add_object (len
);
23757 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
23760 case dw_val_class_const_double
:
23761 hstate
.add_object (val2
->v
.val_double
.low
);
23762 hstate
.add_object (val2
->v
.val_double
.high
);
23764 case dw_val_class_wide_int
:
23765 hstate
.add_object (*val2
->v
.val_wide
);
23768 gcc_unreachable ();
23774 /* Other codes have no operands. */
23779 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
23782 hash_locs (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
23784 dw_loc_descr_ref l
;
23785 bool sizes_computed
= false;
23786 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23787 size_of_locs (loc
);
23789 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
23791 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
23792 hstate
.add_object (opc
);
23793 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
23795 size_of_locs (loc
);
23796 sizes_computed
= true;
23798 hash_loc_operands (l
, hstate
);
23802 /* Compute hash of the whole location list LIST_HEAD. */
23805 hash_loc_list (dw_loc_list_ref list_head
)
23807 dw_loc_list_ref curr
= list_head
;
23808 inchash::hash hstate
;
23810 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23812 hstate
.add (curr
->begin
, strlen (curr
->begin
) + 1);
23813 hstate
.add (curr
->end
, strlen (curr
->end
) + 1);
23815 hstate
.add (curr
->section
, strlen (curr
->section
) + 1);
23816 hash_locs (curr
->expr
, hstate
);
23818 list_head
->hash
= hstate
.end ();
23821 /* Return true if X and Y opcodes have the same operands. */
23824 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23826 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
23827 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
23828 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
23829 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
23831 switch (x
->dw_loc_opc
)
23833 case DW_OP_const4u
:
23834 case DW_OP_const8u
:
23838 case DW_OP_const1u
:
23839 case DW_OP_const1s
:
23840 case DW_OP_const2u
:
23841 case DW_OP_const2s
:
23842 case DW_OP_const4s
:
23843 case DW_OP_const8s
:
23847 case DW_OP_plus_uconst
:
23883 case DW_OP_deref_size
:
23884 case DW_OP_xderef_size
:
23885 return valx1
->v
.val_int
== valy1
->v
.val_int
;
23888 /* If splitting debug info, the use of DW_OP_GNU_addr_index
23889 can cause irrelevant differences in dw_loc_addr. */
23890 gcc_assert (valx1
->val_class
== dw_val_class_loc
23891 && valy1
->val_class
== dw_val_class_loc
23892 && (dwarf_split_debug_info
23893 || x
->dw_loc_addr
== y
->dw_loc_addr
));
23894 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
23895 case DW_OP_implicit_value
:
23896 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
23897 || valx2
->val_class
!= valy2
->val_class
)
23899 switch (valx2
->val_class
)
23901 case dw_val_class_const
:
23902 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23903 case dw_val_class_vec
:
23904 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23905 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23906 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23907 valx2
->v
.val_vec
.elt_size
23908 * valx2
->v
.val_vec
.length
) == 0;
23909 case dw_val_class_const_double
:
23910 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23911 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23912 case dw_val_class_wide_int
:
23913 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
23914 case dw_val_class_addr
:
23915 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
23917 gcc_unreachable ();
23920 case DW_OP_bit_piece
:
23921 return valx1
->v
.val_int
== valy1
->v
.val_int
23922 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23925 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
23926 case DW_OP_GNU_addr_index
:
23927 case DW_OP_GNU_const_index
:
23929 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
23930 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
23931 return rtx_equal_p (ax1
, ay1
);
23933 case DW_OP_GNU_implicit_pointer
:
23934 return valx1
->val_class
== dw_val_class_die_ref
23935 && valx1
->val_class
== valy1
->val_class
23936 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
23937 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23938 case DW_OP_GNU_entry_value
:
23939 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
23940 case DW_OP_GNU_const_type
:
23941 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
23942 || valx2
->val_class
!= valy2
->val_class
)
23944 switch (valx2
->val_class
)
23946 case dw_val_class_const
:
23947 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23948 case dw_val_class_vec
:
23949 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23950 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23951 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23952 valx2
->v
.val_vec
.elt_size
23953 * valx2
->v
.val_vec
.length
) == 0;
23954 case dw_val_class_const_double
:
23955 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23956 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23957 case dw_val_class_wide_int
:
23958 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
23960 gcc_unreachable ();
23962 case DW_OP_GNU_regval_type
:
23963 case DW_OP_GNU_deref_type
:
23964 return valx1
->v
.val_int
== valy1
->v
.val_int
23965 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
23966 case DW_OP_GNU_convert
:
23967 case DW_OP_GNU_reinterpret
:
23968 if (valx1
->val_class
!= valy1
->val_class
)
23970 if (valx1
->val_class
== dw_val_class_unsigned_const
)
23971 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
23972 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23973 case DW_OP_GNU_parameter_ref
:
23974 return valx1
->val_class
== dw_val_class_die_ref
23975 && valx1
->val_class
== valy1
->val_class
23976 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23978 /* Other codes have no operands. */
23983 /* Return true if DWARF location expressions X and Y are the same. */
23986 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23988 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
23989 if (x
->dw_loc_opc
!= y
->dw_loc_opc
23990 || x
->dtprel
!= y
->dtprel
23991 || !compare_loc_operands (x
, y
))
23993 return x
== NULL
&& y
== NULL
;
23996 /* Hashtable helpers. */
23998 struct loc_list_hasher
: typed_noop_remove
<dw_loc_list_struct
>
24000 typedef dw_loc_list_struct value_type
;
24001 typedef dw_loc_list_struct compare_type
;
24002 static inline hashval_t
hash (const value_type
*);
24003 static inline bool equal (const value_type
*, const compare_type
*);
24006 /* Return precomputed hash of location list X. */
24009 loc_list_hasher::hash (const value_type
*x
)
24014 /* Return true if location lists A and B are the same. */
24017 loc_list_hasher::equal (const value_type
*a
, const compare_type
*b
)
24021 if (a
->hash
!= b
->hash
)
24023 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
24024 if (strcmp (a
->begin
, b
->begin
) != 0
24025 || strcmp (a
->end
, b
->end
) != 0
24026 || (a
->section
== NULL
) != (b
->section
== NULL
)
24027 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
24028 || !compare_locs (a
->expr
, b
->expr
))
24030 return a
== NULL
&& b
== NULL
;
24033 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
24036 /* Recursively optimize location lists referenced from DIE
24037 children and share them whenever possible. */
24040 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type
*htab
)
24045 dw_loc_list_struct
**slot
;
24047 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
24048 if (AT_class (a
) == dw_val_class_loc_list
)
24050 dw_loc_list_ref list
= AT_loc_list (a
);
24051 /* TODO: perform some optimizations here, before hashing
24052 it and storing into the hash table. */
24053 hash_loc_list (list
);
24054 slot
= htab
->find_slot_with_hash (list
, list
->hash
, INSERT
);
24058 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
24061 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
24065 /* Recursively assign each location list a unique index into the debug_addr
24069 index_location_lists (dw_die_ref die
)
24075 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
24076 if (AT_class (a
) == dw_val_class_loc_list
)
24078 dw_loc_list_ref list
= AT_loc_list (a
);
24079 dw_loc_list_ref curr
;
24080 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
24082 /* Don't index an entry that has already been indexed
24083 or won't be output. */
24084 if (curr
->begin_entry
!= NULL
24085 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
24089 = add_addr_table_entry (xstrdup (curr
->begin
),
24094 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
24097 /* Optimize location lists referenced from DIE
24098 children and share them whenever possible. */
24101 optimize_location_lists (dw_die_ref die
)
24103 loc_list_hash_type
htab (500);
24104 optimize_location_lists_1 (die
, &htab
);
24107 /* Output stuff that dwarf requires at the end of every file,
24108 and generate the DWARF-2 debugging info. */
24111 dwarf2out_finish (const char *filename
)
24113 limbo_die_node
*node
, *next_node
;
24114 comdat_type_node
*ctnode
;
24116 dw_die_ref main_comp_unit_die
;
24118 /* PCH might result in DW_AT_producer string being restored from the
24119 header compilation, so always fill it with empty string initially
24120 and overwrite only here. */
24121 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
24122 producer_string
= gen_producer_string ();
24123 producer
->dw_attr_val
.v
.val_str
->refcount
--;
24124 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
24126 gen_scheduled_generic_parms_dies ();
24127 gen_remaining_tmpl_value_param_die_attribute ();
24129 /* Add the name for the main input file now. We delayed this from
24130 dwarf2out_init to avoid complications with PCH. */
24131 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
24132 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
24133 add_comp_dir_attribute (comp_unit_die ());
24134 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
24137 htab_traverse (file_table
, file_table_relative_p
, &p
);
24139 add_comp_dir_attribute (comp_unit_die ());
24142 if (deferred_locations_list
)
24143 for (i
= 0; i
< deferred_locations_list
->length (); i
++)
24145 add_location_or_const_value_attribute (
24146 (*deferred_locations_list
)[i
].die
,
24147 (*deferred_locations_list
)[i
].variable
,
24152 /* Traverse the limbo die list, and add parent/child links. The only
24153 dies without parents that should be here are concrete instances of
24154 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
24155 For concrete instances, we can get the parent die from the abstract
24157 for (node
= limbo_die_list
; node
; node
= next_node
)
24159 dw_die_ref die
= node
->die
;
24160 next_node
= node
->next
;
24162 if (die
->die_parent
== NULL
)
24164 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
24166 if (origin
&& origin
->die_parent
)
24167 add_child_die (origin
->die_parent
, die
);
24168 else if (is_cu_die (die
))
24170 else if (seen_error ())
24171 /* It's OK to be confused by errors in the input. */
24172 add_child_die (comp_unit_die (), die
);
24175 /* In certain situations, the lexical block containing a
24176 nested function can be optimized away, which results
24177 in the nested function die being orphaned. Likewise
24178 with the return type of that nested function. Force
24179 this to be a child of the containing function.
24181 It may happen that even the containing function got fully
24182 inlined and optimized out. In that case we are lost and
24183 assign the empty child. This should not be big issue as
24184 the function is likely unreachable too. */
24185 gcc_assert (node
->created_for
);
24187 if (DECL_P (node
->created_for
))
24188 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
24189 else if (TYPE_P (node
->created_for
))
24190 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
24192 origin
= comp_unit_die ();
24194 add_child_die (origin
, die
);
24199 limbo_die_list
= NULL
;
24201 #if ENABLE_ASSERT_CHECKING
24203 dw_die_ref die
= comp_unit_die (), c
;
24204 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
24207 resolve_addr (comp_unit_die ());
24208 move_marked_base_types ();
24210 for (node
= deferred_asm_name
; node
; node
= node
->next
)
24212 tree decl
= node
->created_for
;
24213 /* When generating LTO bytecode we can not generate new assembler
24214 names at this point and all important decls got theirs via
24216 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
24217 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
24219 add_linkage_attr (node
->die
, decl
);
24220 move_linkage_attr (node
->die
);
24224 deferred_asm_name
= NULL
;
24226 /* Walk through the list of incomplete types again, trying once more to
24227 emit full debugging info for them. */
24228 retry_incomplete_types ();
24230 if (flag_eliminate_unused_debug_types
)
24231 prune_unused_types ();
24233 /* Generate separate COMDAT sections for type DIEs. */
24234 if (use_debug_types
)
24236 break_out_comdat_types (comp_unit_die ());
24238 /* Each new type_unit DIE was added to the limbo die list when created.
24239 Since these have all been added to comdat_type_list, clear the
24241 limbo_die_list
= NULL
;
24243 /* For each new comdat type unit, copy declarations for incomplete
24244 types to make the new unit self-contained (i.e., no direct
24245 references to the main compile unit). */
24246 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24247 copy_decls_for_unworthy_types (ctnode
->root_die
);
24248 copy_decls_for_unworthy_types (comp_unit_die ());
24250 /* In the process of copying declarations from one unit to another,
24251 we may have left some declarations behind that are no longer
24252 referenced. Prune them. */
24253 prune_unused_types ();
24256 /* Generate separate CUs for each of the include files we've seen.
24257 They will go into limbo_die_list. */
24258 if (flag_eliminate_dwarf2_dups
)
24259 break_out_includes (comp_unit_die ());
24261 /* Traverse the DIE's and add add sibling attributes to those DIE's
24262 that have children. */
24263 add_sibling_attributes (comp_unit_die ());
24264 for (node
= limbo_die_list
; node
; node
= node
->next
)
24265 add_sibling_attributes (node
->die
);
24266 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24267 add_sibling_attributes (ctnode
->root_die
);
24269 /* When splitting DWARF info, we put some attributes in the
24270 skeleton compile_unit DIE that remains in the .o, while
24271 most attributes go in the DWO compile_unit_die. */
24272 if (dwarf_split_debug_info
)
24273 main_comp_unit_die
= gen_compile_unit_die (NULL
);
24275 main_comp_unit_die
= comp_unit_die ();
24277 /* Output a terminator label for the .text section. */
24278 switch_to_section (text_section
);
24279 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
24280 if (cold_text_section
)
24282 switch_to_section (cold_text_section
);
24283 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
24286 /* We can only use the low/high_pc attributes if all of the code was
24288 if (!have_multiple_function_sections
24289 || (dwarf_version
< 3 && dwarf_strict
))
24291 /* Don't add if the CU has no associated code. */
24292 if (text_section_used
)
24293 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
24294 text_end_label
, true);
24300 bool range_list_added
= false;
24302 if (text_section_used
)
24303 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
24304 text_end_label
, &range_list_added
, true);
24305 if (cold_text_section_used
)
24306 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
24307 cold_end_label
, &range_list_added
, true);
24309 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
24311 if (DECL_IGNORED_P (fde
->decl
))
24313 if (!fde
->in_std_section
)
24314 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
24315 fde
->dw_fde_end
, &range_list_added
,
24317 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
24318 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
24319 fde
->dw_fde_second_end
, &range_list_added
,
24323 if (range_list_added
)
24325 /* We need to give .debug_loc and .debug_ranges an appropriate
24326 "base address". Use zero so that these addresses become
24327 absolute. Historically, we've emitted the unexpected
24328 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
24329 Emit both to give time for other tools to adapt. */
24330 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
24331 if (! dwarf_strict
&& dwarf_version
< 4)
24332 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
24338 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
24339 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
24340 debug_line_section_label
);
24343 add_AT_macptr (comp_unit_die (),
24344 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
24345 macinfo_section_label
);
24347 if (dwarf_split_debug_info
)
24349 /* optimize_location_lists calculates the size of the lists,
24350 so index them first, and assign indices to the entries.
24351 Although optimize_location_lists will remove entries from
24352 the table, it only does so for duplicates, and therefore
24353 only reduces ref_counts to 1. */
24354 index_location_lists (comp_unit_die ());
24356 if (addr_index_table
!= NULL
)
24358 unsigned int index
= 0;
24359 htab_traverse_noresize (addr_index_table
,
24360 index_addr_table_entry
, &index
);
24364 if (have_location_lists
)
24365 optimize_location_lists (comp_unit_die ());
24367 save_macinfo_strings ();
24369 if (dwarf_split_debug_info
)
24371 unsigned int index
= 0;
24373 /* Add attributes common to skeleton compile_units and
24374 type_units. Because these attributes include strings, it
24375 must be done before freezing the string table. Top-level
24376 skeleton die attrs are added when the skeleton type unit is
24377 created, so ensure it is created by this point. */
24378 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
24379 htab_traverse_noresize (debug_str_hash
, index_string
, &index
);
24382 /* Output all of the compilation units. We put the main one last so that
24383 the offsets are available to output_pubnames. */
24384 for (node
= limbo_die_list
; node
; node
= node
->next
)
24385 output_comp_unit (node
->die
, 0);
24387 hash_table
<comdat_type_hasher
> comdat_type_table (100);
24388 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24390 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
24392 /* Don't output duplicate types. */
24393 if (*slot
!= HTAB_EMPTY_ENTRY
)
24396 /* Add a pointer to the line table for the main compilation unit
24397 so that the debugger can make sense of DW_AT_decl_file
24399 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
24400 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
24401 (!dwarf_split_debug_info
24402 ? debug_line_section_label
24403 : debug_skeleton_line_section_label
));
24405 output_comdat_type_unit (ctnode
);
24409 /* The AT_pubnames attribute needs to go in all skeleton dies, including
24410 both the main_cu and all skeleton TUs. Making this call unconditional
24411 would end up either adding a second copy of the AT_pubnames attribute, or
24412 requiring a special case in add_top_level_skeleton_die_attrs. */
24413 if (!dwarf_split_debug_info
)
24414 add_AT_pubnames (comp_unit_die ());
24416 if (dwarf_split_debug_info
)
24419 unsigned char checksum
[16];
24420 struct md5_ctx ctx
;
24422 /* Compute a checksum of the comp_unit to use as the dwo_id. */
24423 md5_init_ctx (&ctx
);
24425 die_checksum (comp_unit_die (), &ctx
, &mark
);
24426 unmark_all_dies (comp_unit_die ());
24427 md5_finish_ctx (&ctx
, checksum
);
24429 /* Use the first 8 bytes of the checksum as the dwo_id,
24430 and add it to both comp-unit DIEs. */
24431 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
24432 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
24434 /* Add the base offset of the ranges table to the skeleton
24436 if (ranges_table_in_use
)
24437 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
24438 ranges_section_label
);
24440 switch_to_section (debug_addr_section
);
24441 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
24442 output_addr_table ();
24445 /* Output the main compilation unit if non-empty or if .debug_macinfo
24446 or .debug_macro will be emitted. */
24447 output_comp_unit (comp_unit_die (), have_macinfo
);
24449 if (dwarf_split_debug_info
&& info_section_emitted
)
24450 output_skeleton_debug_sections (main_comp_unit_die
);
24452 /* Output the abbreviation table. */
24453 if (abbrev_die_table_in_use
!= 1)
24455 switch_to_section (debug_abbrev_section
);
24456 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
24457 output_abbrev_section ();
24460 /* Output location list section if necessary. */
24461 if (have_location_lists
)
24463 /* Output the location lists info. */
24464 switch_to_section (debug_loc_section
);
24465 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
24466 output_location_lists (comp_unit_die ());
24469 output_pubtables ();
24471 /* Output the address range information if a CU (.debug_info section)
24472 was emitted. We output an empty table even if we had no functions
24473 to put in it. This because the consumer has no way to tell the
24474 difference between an empty table that we omitted and failure to
24475 generate a table that would have contained data. */
24476 if (info_section_emitted
)
24478 unsigned long aranges_length
= size_of_aranges ();
24480 switch_to_section (debug_aranges_section
);
24481 output_aranges (aranges_length
);
24484 /* Output ranges section if necessary. */
24485 if (ranges_table_in_use
)
24487 switch_to_section (debug_ranges_section
);
24488 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
24492 /* Have to end the macro section. */
24495 switch_to_section (debug_macinfo_section
);
24496 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
24498 dw2_asm_output_data (1, 0, "End compilation unit");
24501 /* Output the source line correspondence table. We must do this
24502 even if there is no line information. Otherwise, on an empty
24503 translation unit, we will generate a present, but empty,
24504 .debug_info section. IRIX 6.5 `nm' will then complain when
24505 examining the file. This is done late so that any filenames
24506 used by the debug_info section are marked as 'used'. */
24507 switch_to_section (debug_line_section
);
24508 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
24509 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
24510 output_line_info (false);
24512 if (dwarf_split_debug_info
&& info_section_emitted
)
24514 switch_to_section (debug_skeleton_line_section
);
24515 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
24516 output_line_info (true);
24519 /* If we emitted any indirect strings, output the string table too. */
24520 if (debug_str_hash
|| skeleton_debug_str_hash
)
24521 output_indirect_strings ();
24524 #include "gt-dwarf2out.h"