1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 Free Software Foundation, Inc.
5 Contributed by Gary Funck (gary@intrepid.com).
6 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
7 Extensively modified by Jason Merrill (jason@cygnus.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
37 /* DWARF2 Abbreviation Glossary:
39 CFA = Canonical Frame Address
40 a fixed address on the stack which identifies a call frame.
41 We define it to be the value of SP just before the call insn.
42 The CFA register and offset, which may change during the course
43 of the function, are used to calculate its value at runtime.
45 CFI = Call Frame Instruction
46 an instruction for the DWARF2 abstract machine
48 CIE = Common Information Entry
49 information describing information common to one or more FDEs
51 DIE = Debugging Information Entry
53 FDE = Frame Description Entry
54 information describing the stack call frame, in particular,
55 how to restore registers
57 DW_CFA_... = DWARF2 CFA call frame instruction
58 DW_TAG_... = DWARF2 DIE tag */
62 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
77 #include "dwarf2out.h"
78 #include "dwarf2asm.h"
83 #include "diagnostic.h"
84 #include "tree-pretty-print.h"
87 #include "common/common-target.h"
88 #include "langhooks.h"
96 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
97 static rtx last_var_location_insn
;
98 static rtx cached_next_real_insn
;
100 #ifdef VMS_DEBUGGING_INFO
101 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
103 /* Define this macro to be a nonzero value if the directory specifications
104 which are output in the debug info should end with a separator. */
105 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
106 /* Define this macro to evaluate to a nonzero value if GCC should refrain
107 from generating indirect strings in DWARF2 debug information, for instance
108 if your target is stuck with an old version of GDB that is unable to
109 process them properly or uses VMS Debug. */
110 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
112 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
113 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
116 /* ??? Poison these here until it can be done generically. They've been
117 totally replaced in this file; make sure it stays that way. */
118 #undef DWARF2_UNWIND_INFO
119 #undef DWARF2_FRAME_INFO
120 #if (GCC_VERSION >= 3000)
121 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
124 /* The size of the target's pointer type. */
126 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
129 /* Array of RTXes referenced by the debugging information, which therefore
130 must be kept around forever. */
131 static GTY(()) VEC(rtx
,gc
) *used_rtx_array
;
133 /* A pointer to the base of a list of incomplete types which might be
134 completed at some later time. incomplete_types_list needs to be a
135 VEC(tree,gc) because we want to tell the garbage collector about
137 static GTY(()) VEC(tree
,gc
) *incomplete_types
;
139 /* A pointer to the base of a table of references to declaration
140 scopes. This table is a display which tracks the nesting
141 of declaration scopes at the current scope and containing
142 scopes. This table is used to find the proper place to
143 define type declaration DIE's. */
144 static GTY(()) VEC(tree
,gc
) *decl_scope_table
;
146 /* Pointers to various DWARF2 sections. */
147 static GTY(()) section
*debug_info_section
;
148 static GTY(()) section
*debug_abbrev_section
;
149 static GTY(()) section
*debug_aranges_section
;
150 static GTY(()) section
*debug_macinfo_section
;
151 static GTY(()) section
*debug_line_section
;
152 static GTY(()) section
*debug_loc_section
;
153 static GTY(()) section
*debug_pubnames_section
;
154 static GTY(()) section
*debug_pubtypes_section
;
155 static GTY(()) section
*debug_str_section
;
156 static GTY(()) section
*debug_ranges_section
;
157 static GTY(()) section
*debug_frame_section
;
159 /* Maximum size (in bytes) of an artificially generated label. */
160 #define MAX_ARTIFICIAL_LABEL_BYTES 30
162 /* According to the (draft) DWARF 3 specification, the initial length
163 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
164 bytes are 0xffffffff, followed by the length stored in the next 8
167 However, the SGI/MIPS ABI uses an initial length which is equal to
168 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
170 #ifndef DWARF_INITIAL_LENGTH_SIZE
171 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
174 /* Round SIZE up to the nearest BOUNDARY. */
175 #define DWARF_ROUND(SIZE,BOUNDARY) \
176 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
178 /* CIE identifier. */
179 #if HOST_BITS_PER_WIDE_INT >= 64
180 #define DWARF_CIE_ID \
181 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
183 #define DWARF_CIE_ID DW_CIE_ID
186 DEF_VEC_P (dw_fde_ref
);
187 DEF_VEC_ALLOC_P (dw_fde_ref
, gc
);
189 /* A vector for a table that contains frame description
190 information for each routine. */
191 static GTY(()) VEC(dw_fde_ref
, gc
) *fde_vec
;
193 struct GTY(()) indirect_string_node
{
195 unsigned int refcount
;
196 enum dwarf_form form
;
200 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
202 static GTY(()) int dw2_string_counter
;
204 /* True if the compilation unit places functions in more than one section. */
205 static GTY(()) bool have_multiple_function_sections
= false;
207 /* Whether the default text and cold text sections have been used at all. */
209 static GTY(()) bool text_section_used
= false;
210 static GTY(()) bool cold_text_section_used
= false;
212 /* The default cold text section. */
213 static GTY(()) section
*cold_text_section
;
215 /* Forward declarations for functions defined in this file. */
217 static char *stripattributes (const char *);
218 static void output_call_frame_info (int);
219 static void dwarf2out_note_section_used (void);
221 /* Personality decl of current unit. Used only when assembler does not support
223 static GTY(()) rtx current_unit_personality
;
225 /* Data and reference forms for relocatable data. */
226 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
227 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
229 #ifndef DEBUG_FRAME_SECTION
230 #define DEBUG_FRAME_SECTION ".debug_frame"
233 #ifndef FUNC_BEGIN_LABEL
234 #define FUNC_BEGIN_LABEL "LFB"
237 #ifndef FUNC_END_LABEL
238 #define FUNC_END_LABEL "LFE"
241 #ifndef PROLOGUE_END_LABEL
242 #define PROLOGUE_END_LABEL "LPE"
245 #ifndef EPILOGUE_BEGIN_LABEL
246 #define EPILOGUE_BEGIN_LABEL "LEB"
249 #ifndef FRAME_BEGIN_LABEL
250 #define FRAME_BEGIN_LABEL "Lframe"
252 #define CIE_AFTER_SIZE_LABEL "LSCIE"
253 #define CIE_END_LABEL "LECIE"
254 #define FDE_LABEL "LSFDE"
255 #define FDE_AFTER_SIZE_LABEL "LASFDE"
256 #define FDE_END_LABEL "LEFDE"
257 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
258 #define LINE_NUMBER_END_LABEL "LELT"
259 #define LN_PROLOG_AS_LABEL "LASLTP"
260 #define LN_PROLOG_END_LABEL "LELTP"
261 #define DIE_LABEL_PREFIX "DW"
263 /* Match the base name of a file to the base name of a compilation unit. */
266 matches_main_base (const char *path
)
268 /* Cache the last query. */
269 static const char *last_path
= NULL
;
270 static int last_match
= 0;
271 if (path
!= last_path
)
274 int length
= base_of_path (path
, &base
);
276 last_match
= (length
== main_input_baselength
277 && memcmp (base
, main_input_basename
, length
) == 0);
282 #ifdef DEBUG_DEBUG_STRUCT
285 dump_struct_debug (tree type
, enum debug_info_usage usage
,
286 enum debug_struct_file criterion
, int generic
,
287 int matches
, int result
)
289 /* Find the type name. */
290 tree type_decl
= TYPE_STUB_DECL (type
);
292 const char *name
= 0;
293 if (TREE_CODE (t
) == TYPE_DECL
)
296 name
= IDENTIFIER_POINTER (t
);
298 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
300 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
301 matches
? "bas" : "hdr",
302 generic
? "gen" : "ord",
303 usage
== DINFO_USAGE_DFN
? ";" :
304 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
306 (void*) type_decl
, name
);
309 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
310 dump_struct_debug (type, usage, criterion, generic, matches, result)
314 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
320 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
322 enum debug_struct_file criterion
;
324 bool generic
= lang_hooks
.types
.generic_p (type
);
327 criterion
= debug_struct_generic
[usage
];
329 criterion
= debug_struct_ordinary
[usage
];
331 if (criterion
== DINFO_STRUCT_FILE_NONE
)
332 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
333 if (criterion
== DINFO_STRUCT_FILE_ANY
)
334 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
336 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
338 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
339 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
341 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
342 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
343 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
346 /* Return a pointer to a copy of the section string name S with all
347 attributes stripped off, and an asterisk prepended (for assemble_name). */
350 stripattributes (const char *s
)
352 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
357 while (*s
&& *s
!= ',')
364 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
365 switch to the data section instead, and write out a synthetic start label
366 for collect2 the first time around. */
369 switch_to_eh_frame_section (bool back
)
373 #ifdef EH_FRAME_SECTION_NAME
374 if (eh_frame_section
== 0)
378 if (EH_TABLES_CAN_BE_READ_ONLY
)
384 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
386 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
388 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
391 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
392 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
393 && (per_encoding
& 0x70) != DW_EH_PE_absptr
394 && (per_encoding
& 0x70) != DW_EH_PE_aligned
395 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
396 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
397 ? 0 : SECTION_WRITE
);
400 flags
= SECTION_WRITE
;
401 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
403 #endif /* EH_FRAME_SECTION_NAME */
405 if (eh_frame_section
)
406 switch_to_section (eh_frame_section
);
409 /* We have no special eh_frame section. Put the information in
410 the data section and emit special labels to guide collect2. */
411 switch_to_section (data_section
);
415 label
= get_file_function_name ("F");
416 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
417 targetm
.asm_out
.globalize_label (asm_out_file
,
418 IDENTIFIER_POINTER (label
));
419 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
424 /* Switch [BACK] to the eh or debug frame table section, depending on
428 switch_to_frame_table_section (int for_eh
, bool back
)
431 switch_to_eh_frame_section (back
);
434 if (!debug_frame_section
)
435 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
436 SECTION_DEBUG
, NULL
);
437 switch_to_section (debug_frame_section
);
441 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
443 enum dw_cfi_oprnd_type
444 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
449 case DW_CFA_GNU_window_save
:
450 case DW_CFA_remember_state
:
451 case DW_CFA_restore_state
:
452 return dw_cfi_oprnd_unused
;
455 case DW_CFA_advance_loc1
:
456 case DW_CFA_advance_loc2
:
457 case DW_CFA_advance_loc4
:
458 case DW_CFA_MIPS_advance_loc8
:
459 return dw_cfi_oprnd_addr
;
462 case DW_CFA_offset_extended
:
464 case DW_CFA_offset_extended_sf
:
465 case DW_CFA_def_cfa_sf
:
467 case DW_CFA_restore_extended
:
468 case DW_CFA_undefined
:
469 case DW_CFA_same_value
:
470 case DW_CFA_def_cfa_register
:
471 case DW_CFA_register
:
472 case DW_CFA_expression
:
473 return dw_cfi_oprnd_reg_num
;
475 case DW_CFA_def_cfa_offset
:
476 case DW_CFA_GNU_args_size
:
477 case DW_CFA_def_cfa_offset_sf
:
478 return dw_cfi_oprnd_offset
;
480 case DW_CFA_def_cfa_expression
:
481 return dw_cfi_oprnd_loc
;
488 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
490 enum dw_cfi_oprnd_type
491 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
496 case DW_CFA_def_cfa_sf
:
498 case DW_CFA_offset_extended_sf
:
499 case DW_CFA_offset_extended
:
500 return dw_cfi_oprnd_offset
;
502 case DW_CFA_register
:
503 return dw_cfi_oprnd_reg_num
;
505 case DW_CFA_expression
:
506 return dw_cfi_oprnd_loc
;
509 return dw_cfi_oprnd_unused
;
513 /* Output one FDE. */
516 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
517 char *section_start_label
, int fde_encoding
, char *augmentation
,
518 bool any_lsda_needed
, int lsda_encoding
)
520 const char *begin
, *end
;
521 static unsigned int j
;
524 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
526 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
528 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
529 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
530 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
531 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
532 " indicating 64-bit DWARF extension");
533 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
535 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
538 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
540 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
541 debug_frame_section
, "FDE CIE offset");
543 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
544 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
548 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
549 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
550 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
551 "FDE initial location");
552 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
553 end
, begin
, "FDE address range");
557 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
558 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
565 int size
= size_of_encoded_value (lsda_encoding
);
567 if (lsda_encoding
== DW_EH_PE_aligned
)
569 int offset
= ( 4 /* Length */
571 + 2 * size_of_encoded_value (fde_encoding
)
572 + 1 /* Augmentation size */ );
573 int pad
= -offset
& (PTR_SIZE
- 1);
576 gcc_assert (size_of_uleb128 (size
) == 1);
579 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
581 if (fde
->uses_eh_lsda
)
583 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
584 fde
->funcdef_number
);
585 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
586 gen_rtx_SYMBOL_REF (Pmode
, l1
),
588 "Language Specific Data Area");
592 if (lsda_encoding
== DW_EH_PE_aligned
)
593 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
594 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
595 "Language Specific Data Area (none)");
599 dw2_asm_output_data_uleb128 (0, "Augmentation size");
602 /* Loop through the Call Frame Instructions associated with this FDE. */
603 fde
->dw_fde_current_label
= begin
;
605 size_t from
, until
, i
;
608 until
= VEC_length (dw_cfi_ref
, fde
->dw_fde_cfi
);
610 if (fde
->dw_fde_second_begin
== NULL
)
613 until
= fde
->dw_fde_switch_cfi_index
;
615 from
= fde
->dw_fde_switch_cfi_index
;
617 for (i
= from
; i
< until
; i
++)
618 output_cfi (VEC_index (dw_cfi_ref
, fde
->dw_fde_cfi
, i
), fde
, for_eh
);
621 /* If we are to emit a ref/link from function bodies to their frame tables,
622 do it now. This is typically performed to make sure that tables
623 associated with functions are dragged with them and not discarded in
624 garbage collecting links. We need to do this on a per function basis to
625 cope with -ffunction-sections. */
627 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
628 /* Switch to the function section, emit the ref to the tables, and
629 switch *back* into the table section. */
630 switch_to_section (function_section (fde
->decl
));
631 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
632 switch_to_frame_table_section (for_eh
, true);
635 /* Pad the FDE out to an address sized boundary. */
636 ASM_OUTPUT_ALIGN (asm_out_file
,
637 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
638 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
643 /* Return true if frame description entry FDE is needed for EH. */
646 fde_needed_for_eh_p (dw_fde_ref fde
)
648 if (flag_asynchronous_unwind_tables
)
651 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
654 if (fde
->uses_eh_lsda
)
657 /* If exceptions are enabled, we have collected nothrow info. */
658 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
664 /* Output the call frame information used to record information
665 that relates to calculating the frame pointer, and records the
666 location of saved registers. */
669 output_call_frame_info (int for_eh
)
674 char l1
[20], l2
[20], section_start_label
[20];
675 bool any_lsda_needed
= false;
676 char augmentation
[6];
677 int augmentation_size
;
678 int fde_encoding
= DW_EH_PE_absptr
;
679 int per_encoding
= DW_EH_PE_absptr
;
680 int lsda_encoding
= DW_EH_PE_absptr
;
682 rtx personality
= NULL
;
685 /* Don't emit a CIE if there won't be any FDEs. */
689 /* Nothing to do if the assembler's doing it all. */
690 if (dwarf2out_do_cfi_asm ())
693 /* If we don't have any functions we'll want to unwind out of, don't emit
694 any EH unwind information. If we make FDEs linkonce, we may have to
695 emit an empty label for an FDE that wouldn't otherwise be emitted. We
696 want to avoid having an FDE kept around when the function it refers to
697 is discarded. Example where this matters: a primary function template
698 in C++ requires EH information, an explicit specialization doesn't. */
701 bool any_eh_needed
= false;
703 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, i
, fde
)
705 if (fde
->uses_eh_lsda
)
706 any_eh_needed
= any_lsda_needed
= true;
707 else if (fde_needed_for_eh_p (fde
))
708 any_eh_needed
= true;
709 else if (TARGET_USES_WEAK_UNWIND_INFO
)
710 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
717 /* We're going to be generating comments, so turn on app. */
721 /* Switch to the proper frame section, first time. */
722 switch_to_frame_table_section (for_eh
, false);
724 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
725 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
727 /* Output the CIE. */
728 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
729 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
730 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
731 dw2_asm_output_data (4, 0xffffffff,
732 "Initial length escape value indicating 64-bit DWARF extension");
733 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
734 "Length of Common Information Entry");
735 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
737 /* Now that the CIE pointer is PC-relative for EH,
738 use 0 to identify the CIE. */
739 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
740 (for_eh
? 0 : DWARF_CIE_ID
),
741 "CIE Identifier Tag");
743 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
744 use CIE version 1, unless that would produce incorrect results
745 due to overflowing the return register column. */
746 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
748 if (return_reg
>= 256 || dwarf_version
> 2)
750 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
753 augmentation_size
= 0;
755 personality
= current_unit_personality
;
761 z Indicates that a uleb128 is present to size the
762 augmentation section.
763 L Indicates the encoding (and thus presence) of
764 an LSDA pointer in the FDE augmentation.
765 R Indicates a non-default pointer encoding for
767 P Indicates the presence of an encoding + language
768 personality routine in the CIE augmentation. */
770 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
771 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
772 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
774 p
= augmentation
+ 1;
778 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
779 assemble_external_libcall (personality
);
784 augmentation_size
+= 1;
786 if (fde_encoding
!= DW_EH_PE_absptr
)
789 augmentation_size
+= 1;
791 if (p
> augmentation
+ 1)
793 augmentation
[0] = 'z';
797 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
798 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
800 int offset
= ( 4 /* Length */
802 + 1 /* CIE version */
803 + strlen (augmentation
) + 1 /* Augmentation */
804 + size_of_uleb128 (1) /* Code alignment */
805 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
807 + 1 /* Augmentation size */
808 + 1 /* Personality encoding */ );
809 int pad
= -offset
& (PTR_SIZE
- 1);
811 augmentation_size
+= pad
;
813 /* Augmentations should be small, so there's scarce need to
814 iterate for a solution. Die if we exceed one uleb128 byte. */
815 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
819 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
820 if (dw_cie_version
>= 4)
822 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
823 dw2_asm_output_data (1, 0, "CIE Segment Size");
825 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
826 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
827 "CIE Data Alignment Factor");
829 if (dw_cie_version
== 1)
830 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
832 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
836 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
839 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
840 eh_data_format_name (per_encoding
));
841 dw2_asm_output_encoded_addr_rtx (per_encoding
,
847 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
848 eh_data_format_name (lsda_encoding
));
850 if (fde_encoding
!= DW_EH_PE_absptr
)
851 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
852 eh_data_format_name (fde_encoding
));
855 FOR_EACH_VEC_ELT (dw_cfi_ref
, cie_cfi_vec
, i
, cfi
)
856 output_cfi (cfi
, NULL
, for_eh
);
858 /* Pad the CIE out to an address sized boundary. */
859 ASM_OUTPUT_ALIGN (asm_out_file
,
860 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
861 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
863 /* Loop through all of the FDE's. */
864 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, i
, fde
)
868 /* Don't emit EH unwind info for leaf functions that don't need it. */
869 if (for_eh
&& !fde_needed_for_eh_p (fde
))
872 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
873 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
874 augmentation
, any_lsda_needed
, lsda_encoding
);
877 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
878 dw2_asm_output_data (4, 0, "End of Table");
880 /* Turn off app to make assembly quicker. */
885 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
888 dwarf2out_do_cfi_startproc (bool second
)
892 rtx personality
= get_personality_function (current_function_decl
);
894 fprintf (asm_out_file
, "\t.cfi_startproc\n");
898 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
901 /* ??? The GAS support isn't entirely consistent. We have to
902 handle indirect support ourselves, but PC-relative is done
903 in the assembler. Further, the assembler can't handle any
904 of the weirder relocation types. */
905 if (enc
& DW_EH_PE_indirect
)
906 ref
= dw2_force_const_mem (ref
, true);
908 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
909 output_addr_const (asm_out_file
, ref
);
910 fputc ('\n', asm_out_file
);
913 if (crtl
->uses_eh_lsda
)
917 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
918 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
919 current_function_funcdef_no
);
920 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
921 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
923 if (enc
& DW_EH_PE_indirect
)
924 ref
= dw2_force_const_mem (ref
, true);
926 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
927 output_addr_const (asm_out_file
, ref
);
928 fputc ('\n', asm_out_file
);
932 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
933 this allocation may be done before pass_final. */
936 dwarf2out_alloc_current_fde (void)
940 fde
= ggc_alloc_cleared_dw_fde_node ();
941 fde
->decl
= current_function_decl
;
942 fde
->funcdef_number
= current_function_funcdef_no
;
943 fde
->fde_index
= VEC_length (dw_fde_ref
, fde_vec
);
944 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
945 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
946 fde
->nothrow
= crtl
->nothrow
;
947 fde
->drap_reg
= INVALID_REGNUM
;
948 fde
->vdrap_reg
= INVALID_REGNUM
;
950 /* Record the FDE associated with this function. */
952 VEC_safe_push (dw_fde_ref
, gc
, fde_vec
, fde
);
957 /* Output a marker (i.e. a label) for the beginning of a function, before
961 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
962 const char *file ATTRIBUTE_UNUSED
)
964 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
970 current_function_func_begin_label
= NULL
;
972 do_frame
= dwarf2out_do_frame ();
974 /* ??? current_function_func_begin_label is also used by except.c for
975 call-site information. We must emit this label if it might be used. */
978 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
981 fnsec
= function_section (current_function_decl
);
982 switch_to_section (fnsec
);
983 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
984 current_function_funcdef_no
);
985 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
986 current_function_funcdef_no
);
987 dup_label
= xstrdup (label
);
988 current_function_func_begin_label
= dup_label
;
990 /* We can elide the fde allocation if we're not emitting debug info. */
994 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
995 emit insns as rtx but bypass the bulk of rest_of_compilation, which
996 would include pass_dwarf2_frame. If we've not created the FDE yet,
1000 fde
= dwarf2out_alloc_current_fde ();
1002 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1003 fde
->dw_fde_begin
= dup_label
;
1004 fde
->dw_fde_current_label
= dup_label
;
1005 fde
->in_std_section
= (fnsec
== text_section
1006 || (cold_text_section
&& fnsec
== cold_text_section
));
1008 /* We only want to output line number information for the genuine dwarf2
1009 prologue case, not the eh frame case. */
1010 #ifdef DWARF2_DEBUGGING_INFO
1012 dwarf2out_source_line (line
, file
, 0, true);
1015 if (dwarf2out_do_cfi_asm ())
1016 dwarf2out_do_cfi_startproc (false);
1019 rtx personality
= get_personality_function (current_function_decl
);
1020 if (!current_unit_personality
)
1021 current_unit_personality
= personality
;
1023 /* We cannot keep a current personality per function as without CFI
1024 asm, at the point where we emit the CFI data, there is no current
1025 function anymore. */
1026 if (personality
&& current_unit_personality
!= personality
)
1027 sorry ("multiple EH personalities are supported only with assemblers "
1028 "supporting .cfi_personality directive");
1032 /* Output a marker (i.e. a label) for the end of the generated code
1033 for a function prologue. This gets called *after* the prologue code has
1037 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1038 const char *file ATTRIBUTE_UNUSED
)
1040 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1042 /* Output a label to mark the endpoint of the code generated for this
1044 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1045 current_function_funcdef_no
);
1046 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1047 current_function_funcdef_no
);
1048 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1051 /* Output a marker (i.e. a label) for the beginning of the generated code
1052 for a function epilogue. This gets called *before* the prologue code has
1056 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1057 const char *file ATTRIBUTE_UNUSED
)
1059 dw_fde_ref fde
= cfun
->fde
;
1060 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1062 if (fde
->dw_fde_vms_begin_epilogue
)
1065 /* Output a label to mark the endpoint of the code generated for this
1067 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1068 current_function_funcdef_no
);
1069 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1070 current_function_funcdef_no
);
1071 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1074 /* Output a marker (i.e. a label) for the absolute end of the generated code
1075 for a function definition. This gets called *after* the epilogue code has
1079 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1080 const char *file ATTRIBUTE_UNUSED
)
1083 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1085 last_var_location_insn
= NULL_RTX
;
1086 cached_next_real_insn
= NULL_RTX
;
1088 if (dwarf2out_do_cfi_asm ())
1089 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1091 /* Output a label to mark the endpoint of the code generated for this
1093 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1094 current_function_funcdef_no
);
1095 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1097 gcc_assert (fde
!= NULL
);
1098 if (fde
->dw_fde_second_begin
== NULL
)
1099 fde
->dw_fde_end
= xstrdup (label
);
1103 dwarf2out_frame_finish (void)
1105 /* Output call frame information. */
1106 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1107 output_call_frame_info (0);
1109 /* Output another copy for the unwinder. */
1110 if ((flag_unwind_tables
|| flag_exceptions
)
1111 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1112 output_call_frame_info (1);
1115 /* Note that the current function section is being used for code. */
1118 dwarf2out_note_section_used (void)
1120 section
*sec
= current_function_section ();
1121 if (sec
== text_section
)
1122 text_section_used
= true;
1123 else if (sec
== cold_text_section
)
1124 cold_text_section_used
= true;
1127 static void var_location_switch_text_section (void);
1128 static void set_cur_line_info_table (section
*);
1131 dwarf2out_switch_text_section (void)
1134 dw_fde_ref fde
= cfun
->fde
;
1136 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1138 if (!in_cold_section_p
)
1140 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1141 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1142 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1146 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1147 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1148 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1150 have_multiple_function_sections
= true;
1152 /* There is no need to mark used sections when not debugging. */
1153 if (cold_text_section
!= NULL
)
1154 dwarf2out_note_section_used ();
1156 if (dwarf2out_do_cfi_asm ())
1157 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1159 /* Now do the real section switch. */
1160 sect
= current_function_section ();
1161 switch_to_section (sect
);
1163 fde
->second_in_std_section
1164 = (sect
== text_section
1165 || (cold_text_section
&& sect
== cold_text_section
));
1167 if (dwarf2out_do_cfi_asm ())
1168 dwarf2out_do_cfi_startproc (true);
1170 var_location_switch_text_section ();
1172 if (cold_text_section
!= NULL
)
1173 set_cur_line_info_table (sect
);
1176 /* And now, the subset of the debugging information support code necessary
1177 for emitting location expressions. */
1179 /* Data about a single source file. */
1180 struct GTY(()) dwarf_file_data
{
1181 const char * filename
;
1185 typedef struct GTY(()) deferred_locations_struct
1189 } deferred_locations
;
1191 DEF_VEC_O(deferred_locations
);
1192 DEF_VEC_ALLOC_O(deferred_locations
,gc
);
1194 static GTY(()) VEC(deferred_locations
, gc
) *deferred_locations_list
;
1196 DEF_VEC_P(dw_die_ref
);
1197 DEF_VEC_ALLOC_P(dw_die_ref
,heap
);
1199 /* Location lists are ranges + location descriptions for that range,
1200 so you can track variables that are in different places over
1201 their entire life. */
1202 typedef struct GTY(()) dw_loc_list_struct
{
1203 dw_loc_list_ref dw_loc_next
;
1204 const char *begin
; /* Label for begin address of range */
1205 const char *end
; /* Label for end address of range */
1206 char *ll_symbol
; /* Label for beginning of location list.
1207 Only on head of list */
1208 const char *section
; /* Section this loclist is relative to */
1209 dw_loc_descr_ref expr
;
1211 /* True if all addresses in this and subsequent lists are known to be
1214 /* True if this list has been replaced by dw_loc_next. */
1217 /* True if the range should be emitted even if begin and end
1222 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1224 /* Convert a DWARF stack opcode into its string name. */
1227 dwarf_stack_op_name (unsigned int op
)
1229 const char *name
= get_DW_OP_name (op
);
1234 return "OP_<unknown>";
1237 /* Return a pointer to a newly allocated location description. Location
1238 descriptions are simple expression terms that can be strung
1239 together to form more complicated location (address) descriptions. */
1241 static inline dw_loc_descr_ref
1242 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1243 unsigned HOST_WIDE_INT oprnd2
)
1245 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
1247 descr
->dw_loc_opc
= op
;
1248 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1249 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1250 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1251 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1256 /* Return a pointer to a newly allocated location description for
1259 static inline dw_loc_descr_ref
1260 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1263 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1266 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1269 /* Add a location description term to a location description expression. */
1272 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1274 dw_loc_descr_ref
*d
;
1276 /* Find the end of the chain. */
1277 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1283 /* Compare two location operands for exact equality. */
1286 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1288 if (a
->val_class
!= b
->val_class
)
1290 switch (a
->val_class
)
1292 case dw_val_class_none
:
1294 case dw_val_class_addr
:
1295 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1297 case dw_val_class_offset
:
1298 case dw_val_class_unsigned_const
:
1299 case dw_val_class_const
:
1300 case dw_val_class_range_list
:
1301 case dw_val_class_lineptr
:
1302 case dw_val_class_macptr
:
1303 /* These are all HOST_WIDE_INT, signed or unsigned. */
1304 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1306 case dw_val_class_loc
:
1307 return a
->v
.val_loc
== b
->v
.val_loc
;
1308 case dw_val_class_loc_list
:
1309 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1310 case dw_val_class_die_ref
:
1311 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1312 case dw_val_class_fde_ref
:
1313 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1314 case dw_val_class_lbl_id
:
1315 case dw_val_class_high_pc
:
1316 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1317 case dw_val_class_str
:
1318 return a
->v
.val_str
== b
->v
.val_str
;
1319 case dw_val_class_flag
:
1320 return a
->v
.val_flag
== b
->v
.val_flag
;
1321 case dw_val_class_file
:
1322 return a
->v
.val_file
== b
->v
.val_file
;
1323 case dw_val_class_decl_ref
:
1324 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1326 case dw_val_class_const_double
:
1327 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1328 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1330 case dw_val_class_vec
:
1332 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1333 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1335 return (a_len
== b_len
1336 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1339 case dw_val_class_data8
:
1340 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1342 case dw_val_class_vms_delta
:
1343 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1344 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1349 /* Compare two location atoms for exact equality. */
1352 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1354 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1357 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1358 address size, but since we always allocate cleared storage it
1359 should be zero for other types of locations. */
1360 if (a
->dtprel
!= b
->dtprel
)
1363 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1364 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1367 /* Compare two complete location expressions for exact equality. */
1370 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1376 if (a
== NULL
|| b
== NULL
)
1378 if (!loc_descr_equal_p_1 (a
, b
))
1387 /* Add a constant OFFSET to a location expression. */
1390 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1392 dw_loc_descr_ref loc
;
1395 gcc_assert (*list_head
!= NULL
);
1400 /* Find the end of the chain. */
1401 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1405 if (loc
->dw_loc_opc
== DW_OP_fbreg
1406 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1407 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1408 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1409 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1411 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1412 offset. Don't optimize if an signed integer overflow would happen. */
1414 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1415 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1418 else if (offset
> 0)
1419 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1423 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1424 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1428 /* Add a constant OFFSET to a location list. */
1431 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1434 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1435 loc_descr_plus_const (&d
->expr
, offset
);
1438 #define DWARF_REF_SIZE \
1439 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1441 static unsigned long int get_base_type_offset (dw_die_ref
);
1443 /* Return the size of a location descriptor. */
1445 static unsigned long
1446 size_of_loc_descr (dw_loc_descr_ref loc
)
1448 unsigned long size
= 1;
1450 switch (loc
->dw_loc_opc
)
1453 size
+= DWARF2_ADDR_SIZE
;
1472 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1475 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1480 case DW_OP_plus_uconst
:
1481 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1519 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1522 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1525 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1528 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1529 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1532 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1534 case DW_OP_bit_piece
:
1535 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1536 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1538 case DW_OP_deref_size
:
1539 case DW_OP_xderef_size
:
1548 case DW_OP_call_ref
:
1549 size
+= DWARF_REF_SIZE
;
1551 case DW_OP_implicit_value
:
1552 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1553 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1555 case DW_OP_GNU_implicit_pointer
:
1556 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1558 case DW_OP_GNU_entry_value
:
1560 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1561 size
+= size_of_uleb128 (op_size
) + op_size
;
1564 case DW_OP_GNU_const_type
:
1567 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1568 size
+= size_of_uleb128 (o
) + 1;
1569 switch (loc
->dw_loc_oprnd2
.val_class
)
1571 case dw_val_class_vec
:
1572 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1573 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1575 case dw_val_class_const
:
1576 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1578 case dw_val_class_const_double
:
1579 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1586 case DW_OP_GNU_regval_type
:
1589 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1590 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1591 + size_of_uleb128 (o
);
1594 case DW_OP_GNU_deref_type
:
1597 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1598 size
+= 1 + size_of_uleb128 (o
);
1601 case DW_OP_GNU_convert
:
1602 case DW_OP_GNU_reinterpret
:
1603 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1604 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1608 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1609 size
+= size_of_uleb128 (o
);
1612 case DW_OP_GNU_parameter_ref
:
1622 /* Return the size of a series of location descriptors. */
1625 size_of_locs (dw_loc_descr_ref loc
)
1630 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1631 field, to avoid writing to a PCH file. */
1632 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1634 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1636 size
+= size_of_loc_descr (l
);
1641 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1643 l
->dw_loc_addr
= size
;
1644 size
+= size_of_loc_descr (l
);
1650 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1651 static void get_ref_die_offset_label (char *, dw_die_ref
);
1652 static unsigned long int get_ref_die_offset (dw_die_ref
);
1654 /* Output location description stack opcode's operands (if any).
1655 The for_eh_or_skip parameter controls whether register numbers are
1656 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1657 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1658 info). This should be suppressed for the cases that have not been converted
1659 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1662 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1664 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1665 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1667 switch (loc
->dw_loc_opc
)
1669 #ifdef DWARF2_DEBUGGING_INFO
1672 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1677 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1678 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1680 fputc ('\n', asm_out_file
);
1685 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1690 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1691 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1693 fputc ('\n', asm_out_file
);
1698 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1699 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1706 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1707 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1709 dw2_asm_output_data (2, offset
, NULL
);
1712 case DW_OP_implicit_value
:
1713 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1714 switch (val2
->val_class
)
1716 case dw_val_class_const
:
1717 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1719 case dw_val_class_vec
:
1721 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1722 unsigned int len
= val2
->v
.val_vec
.length
;
1726 if (elt_size
> sizeof (HOST_WIDE_INT
))
1731 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1734 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1735 "fp or vector constant word %u", i
);
1738 case dw_val_class_const_double
:
1740 unsigned HOST_WIDE_INT first
, second
;
1742 if (WORDS_BIG_ENDIAN
)
1744 first
= val2
->v
.val_double
.high
;
1745 second
= val2
->v
.val_double
.low
;
1749 first
= val2
->v
.val_double
.low
;
1750 second
= val2
->v
.val_double
.high
;
1752 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1754 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1758 case dw_val_class_addr
:
1759 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1760 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1775 case DW_OP_implicit_value
:
1776 /* We currently don't make any attempt to make sure these are
1777 aligned properly like we do for the main unwind info, so
1778 don't support emitting things larger than a byte if we're
1779 only doing unwinding. */
1784 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1787 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1790 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1793 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1795 case DW_OP_plus_uconst
:
1796 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1830 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1834 unsigned r
= val1
->v
.val_unsigned
;
1835 if (for_eh_or_skip
>= 0)
1836 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1837 gcc_assert (size_of_uleb128 (r
)
1838 == size_of_uleb128 (val1
->v
.val_unsigned
));
1839 dw2_asm_output_data_uleb128 (r
, NULL
);
1843 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1847 unsigned r
= val1
->v
.val_unsigned
;
1848 if (for_eh_or_skip
>= 0)
1849 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1850 gcc_assert (size_of_uleb128 (r
)
1851 == size_of_uleb128 (val1
->v
.val_unsigned
));
1852 dw2_asm_output_data_uleb128 (r
, NULL
);
1853 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1857 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1859 case DW_OP_bit_piece
:
1860 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1861 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1863 case DW_OP_deref_size
:
1864 case DW_OP_xderef_size
:
1865 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1871 if (targetm
.asm_out
.output_dwarf_dtprel
)
1873 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1876 fputc ('\n', asm_out_file
);
1883 #ifdef DWARF2_DEBUGGING_INFO
1884 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
1891 case DW_OP_GNU_implicit_pointer
:
1893 char label
[MAX_ARTIFICIAL_LABEL_BYTES
1894 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
1895 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
1896 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
1897 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
1898 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1902 case DW_OP_GNU_entry_value
:
1903 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
1904 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
1907 case DW_OP_GNU_const_type
:
1909 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
1911 dw2_asm_output_data_uleb128 (o
, NULL
);
1912 switch (val2
->val_class
)
1914 case dw_val_class_const
:
1915 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
1916 dw2_asm_output_data (1, l
, NULL
);
1917 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
1919 case dw_val_class_vec
:
1921 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1922 unsigned int len
= val2
->v
.val_vec
.length
;
1927 dw2_asm_output_data (1, l
, NULL
);
1928 if (elt_size
> sizeof (HOST_WIDE_INT
))
1933 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1936 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1937 "fp or vector constant word %u", i
);
1940 case dw_val_class_const_double
:
1942 unsigned HOST_WIDE_INT first
, second
;
1943 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
1945 dw2_asm_output_data (1, 2 * l
, NULL
);
1946 if (WORDS_BIG_ENDIAN
)
1948 first
= val2
->v
.val_double
.high
;
1949 second
= val2
->v
.val_double
.low
;
1953 first
= val2
->v
.val_double
.low
;
1954 second
= val2
->v
.val_double
.high
;
1956 dw2_asm_output_data (l
, first
, NULL
);
1957 dw2_asm_output_data (l
, second
, NULL
);
1965 case DW_OP_GNU_regval_type
:
1967 unsigned r
= val1
->v
.val_unsigned
;
1968 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
1970 if (for_eh_or_skip
>= 0)
1972 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1973 gcc_assert (size_of_uleb128 (r
)
1974 == size_of_uleb128 (val1
->v
.val_unsigned
));
1976 dw2_asm_output_data_uleb128 (r
, NULL
);
1977 dw2_asm_output_data_uleb128 (o
, NULL
);
1980 case DW_OP_GNU_deref_type
:
1982 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
1984 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1985 dw2_asm_output_data_uleb128 (o
, NULL
);
1988 case DW_OP_GNU_convert
:
1989 case DW_OP_GNU_reinterpret
:
1990 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1991 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1994 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
1996 dw2_asm_output_data_uleb128 (o
, NULL
);
2000 case DW_OP_GNU_parameter_ref
:
2003 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2004 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2005 dw2_asm_output_data (4, o
, NULL
);
2010 /* Other codes have no operands. */
2015 /* Output a sequence of location operations.
2016 The for_eh_or_skip parameter controls whether register numbers are
2017 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2018 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2019 info). This should be suppressed for the cases that have not been converted
2020 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2023 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2025 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2027 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2028 /* Output the opcode. */
2029 if (for_eh_or_skip
>= 0
2030 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2032 unsigned r
= (opc
- DW_OP_breg0
);
2033 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2034 gcc_assert (r
<= 31);
2035 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2037 else if (for_eh_or_skip
>= 0
2038 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2040 unsigned r
= (opc
- DW_OP_reg0
);
2041 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2042 gcc_assert (r
<= 31);
2043 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2046 dw2_asm_output_data (1, opc
,
2047 "%s", dwarf_stack_op_name (opc
));
2049 /* Output the operand(s) (if any). */
2050 output_loc_operands (loc
, for_eh_or_skip
);
2054 /* Output location description stack opcode's operands (if any).
2055 The output is single bytes on a line, suitable for .cfi_escape. */
2058 output_loc_operands_raw (dw_loc_descr_ref loc
)
2060 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2061 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2063 switch (loc
->dw_loc_opc
)
2066 case DW_OP_implicit_value
:
2067 /* We cannot output addresses in .cfi_escape, only bytes. */
2073 case DW_OP_deref_size
:
2074 case DW_OP_xderef_size
:
2075 fputc (',', asm_out_file
);
2076 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2081 fputc (',', asm_out_file
);
2082 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2087 fputc (',', asm_out_file
);
2088 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2093 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2094 fputc (',', asm_out_file
);
2095 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2103 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2104 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2106 fputc (',', asm_out_file
);
2107 dw2_asm_output_data_raw (2, offset
);
2113 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2114 gcc_assert (size_of_uleb128 (r
)
2115 == size_of_uleb128 (val1
->v
.val_unsigned
));
2116 fputc (',', asm_out_file
);
2117 dw2_asm_output_data_uleb128_raw (r
);
2122 case DW_OP_plus_uconst
:
2124 fputc (',', asm_out_file
);
2125 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2128 case DW_OP_bit_piece
:
2129 fputc (',', asm_out_file
);
2130 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2131 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2168 fputc (',', asm_out_file
);
2169 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2174 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2175 gcc_assert (size_of_uleb128 (r
)
2176 == size_of_uleb128 (val1
->v
.val_unsigned
));
2177 fputc (',', asm_out_file
);
2178 dw2_asm_output_data_uleb128_raw (r
);
2179 fputc (',', asm_out_file
);
2180 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2184 case DW_OP_GNU_implicit_pointer
:
2185 case DW_OP_GNU_entry_value
:
2186 case DW_OP_GNU_const_type
:
2187 case DW_OP_GNU_regval_type
:
2188 case DW_OP_GNU_deref_type
:
2189 case DW_OP_GNU_convert
:
2190 case DW_OP_GNU_reinterpret
:
2191 case DW_OP_GNU_parameter_ref
:
2196 /* Other codes have no operands. */
2202 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2206 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2207 /* Output the opcode. */
2208 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2210 unsigned r
= (opc
- DW_OP_breg0
);
2211 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2212 gcc_assert (r
<= 31);
2213 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2215 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2217 unsigned r
= (opc
- DW_OP_reg0
);
2218 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2219 gcc_assert (r
<= 31);
2220 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2222 /* Output the opcode. */
2223 fprintf (asm_out_file
, "%#x", opc
);
2224 output_loc_operands_raw (loc
);
2226 if (!loc
->dw_loc_next
)
2228 loc
= loc
->dw_loc_next
;
2230 fputc (',', asm_out_file
);
2234 /* This function builds a dwarf location descriptor sequence from a
2235 dw_cfa_location, adding the given OFFSET to the result of the
2238 struct dw_loc_descr_struct
*
2239 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2241 struct dw_loc_descr_struct
*head
, *tmp
;
2243 offset
+= cfa
->offset
;
2247 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2248 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2249 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2250 add_loc_descr (&head
, tmp
);
2253 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2254 add_loc_descr (&head
, tmp
);
2258 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2263 /* This function builds a dwarf location descriptor sequence for
2264 the address at OFFSET from the CFA when stack is aligned to
2267 struct dw_loc_descr_struct
*
2268 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2269 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2271 struct dw_loc_descr_struct
*head
;
2272 unsigned int dwarf_fp
2273 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2275 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2276 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2278 head
= new_reg_loc_descr (dwarf_fp
, 0);
2279 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2280 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2281 loc_descr_plus_const (&head
, offset
);
2284 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2288 /* And now, the support for symbolic debugging information. */
2290 /* .debug_str support. */
2291 static int output_indirect_string (void **, void *);
2293 static void dwarf2out_init (const char *);
2294 static void dwarf2out_finish (const char *);
2295 static void dwarf2out_assembly_start (void);
2296 static void dwarf2out_define (unsigned int, const char *);
2297 static void dwarf2out_undef (unsigned int, const char *);
2298 static void dwarf2out_start_source_file (unsigned, const char *);
2299 static void dwarf2out_end_source_file (unsigned);
2300 static void dwarf2out_function_decl (tree
);
2301 static void dwarf2out_begin_block (unsigned, unsigned);
2302 static void dwarf2out_end_block (unsigned, unsigned);
2303 static bool dwarf2out_ignore_block (const_tree
);
2304 static void dwarf2out_global_decl (tree
);
2305 static void dwarf2out_type_decl (tree
, int);
2306 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2307 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2309 static void dwarf2out_abstract_function (tree
);
2310 static void dwarf2out_var_location (rtx
);
2311 static void dwarf2out_begin_function (tree
);
2312 static void dwarf2out_set_name (tree
, tree
);
2314 /* The debug hooks structure. */
2316 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2320 dwarf2out_assembly_start
,
2323 dwarf2out_start_source_file
,
2324 dwarf2out_end_source_file
,
2325 dwarf2out_begin_block
,
2326 dwarf2out_end_block
,
2327 dwarf2out_ignore_block
,
2328 dwarf2out_source_line
,
2329 dwarf2out_begin_prologue
,
2330 #if VMS_DEBUGGING_INFO
2331 dwarf2out_vms_end_prologue
,
2332 dwarf2out_vms_begin_epilogue
,
2334 debug_nothing_int_charstar
,
2335 debug_nothing_int_charstar
,
2337 dwarf2out_end_epilogue
,
2338 dwarf2out_begin_function
,
2339 debug_nothing_int
, /* end_function */
2340 dwarf2out_function_decl
, /* function_decl */
2341 dwarf2out_global_decl
,
2342 dwarf2out_type_decl
, /* type_decl */
2343 dwarf2out_imported_module_or_decl
,
2344 debug_nothing_tree
, /* deferred_inline_function */
2345 /* The DWARF 2 backend tries to reduce debugging bloat by not
2346 emitting the abstract description of inline functions until
2347 something tries to reference them. */
2348 dwarf2out_abstract_function
, /* outlining_inline_function */
2349 debug_nothing_rtx
, /* label */
2350 debug_nothing_int
, /* handle_pch */
2351 dwarf2out_var_location
,
2352 dwarf2out_switch_text_section
,
2354 1, /* start_end_main_source_file */
2355 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2358 /* NOTE: In the comments in this file, many references are made to
2359 "Debugging Information Entries". This term is abbreviated as `DIE'
2360 throughout the remainder of this file. */
2362 /* An internal representation of the DWARF output is built, and then
2363 walked to generate the DWARF debugging info. The walk of the internal
2364 representation is done after the entire program has been compiled.
2365 The types below are used to describe the internal representation. */
2367 /* Whether to put type DIEs into their own section .debug_types instead
2368 of making them part of the .debug_info section. Only supported for
2369 Dwarf V4 or higher and the user didn't disable them through
2370 -fno-debug-types-section. It is more efficient to put them in a
2371 separate comdat sections since the linker will then be able to
2372 remove duplicates. But not all tools support .debug_types sections
2375 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2377 /* Various DIE's use offsets relative to the beginning of the
2378 .debug_info section to refer to each other. */
2380 typedef long int dw_offset
;
2382 /* Define typedefs here to avoid circular dependencies. */
2384 typedef struct dw_attr_struct
*dw_attr_ref
;
2385 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2386 typedef struct pubname_struct
*pubname_ref
;
2387 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2388 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2389 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2391 /* The entries in the line_info table more-or-less mirror the opcodes
2392 that are used in the real dwarf line table. Arrays of these entries
2393 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2396 enum dw_line_info_opcode
{
2397 /* Emit DW_LNE_set_address; the operand is the label index. */
2400 /* Emit a row to the matrix with the given line. This may be done
2401 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2405 /* Emit a DW_LNS_set_file. */
2408 /* Emit a DW_LNS_set_column. */
2411 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2414 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2415 LI_set_prologue_end
,
2416 LI_set_epilogue_begin
,
2418 /* Emit a DW_LNE_set_discriminator. */
2419 LI_set_discriminator
2422 typedef struct GTY(()) dw_line_info_struct
{
2423 enum dw_line_info_opcode opcode
;
2425 } dw_line_info_entry
;
2427 DEF_VEC_O(dw_line_info_entry
);
2428 DEF_VEC_ALLOC_O(dw_line_info_entry
, gc
);
2430 typedef struct GTY(()) dw_line_info_table_struct
{
2431 /* The label that marks the end of this section. */
2432 const char *end_label
;
2434 /* The values for the last row of the matrix, as collected in the table.
2435 These are used to minimize the changes to the next row. */
2436 unsigned int file_num
;
2437 unsigned int line_num
;
2438 unsigned int column_num
;
2443 VEC(dw_line_info_entry
, gc
) *entries
;
2444 } dw_line_info_table
;
2446 typedef dw_line_info_table
*dw_line_info_table_p
;
2448 DEF_VEC_P(dw_line_info_table_p
);
2449 DEF_VEC_ALLOC_P(dw_line_info_table_p
, gc
);
2451 /* Each DIE attribute has a field specifying the attribute kind,
2452 a link to the next attribute in the chain, and an attribute value.
2453 Attributes are typically linked below the DIE they modify. */
2455 typedef struct GTY(()) dw_attr_struct
{
2456 enum dwarf_attribute dw_attr
;
2457 dw_val_node dw_attr_val
;
2461 DEF_VEC_O(dw_attr_node
);
2462 DEF_VEC_ALLOC_O(dw_attr_node
,gc
);
2464 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2465 The children of each node form a circular list linked by
2466 die_sib. die_child points to the node *before* the "first" child node. */
2468 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
2469 union die_symbol_or_type_node
2471 const char * GTY ((tag ("0"))) die_symbol
;
2472 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2474 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2475 VEC(dw_attr_node
,gc
) * die_attr
;
2476 dw_die_ref die_parent
;
2477 dw_die_ref die_child
;
2479 dw_die_ref die_definition
; /* ref from a specification to its definition */
2480 dw_offset die_offset
;
2481 unsigned long die_abbrev
;
2483 unsigned int decl_id
;
2484 enum dwarf_tag die_tag
;
2485 /* Die is used and must not be pruned as unused. */
2486 BOOL_BITFIELD die_perennial_p
: 1;
2487 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2488 /* Lots of spare bits. */
2492 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2493 #define FOR_EACH_CHILD(die, c, expr) do { \
2494 c = die->die_child; \
2498 } while (c != die->die_child); \
2501 /* The pubname structure */
2503 typedef struct GTY(()) pubname_struct
{
2509 DEF_VEC_O(pubname_entry
);
2510 DEF_VEC_ALLOC_O(pubname_entry
, gc
);
2512 struct GTY(()) dw_ranges_struct
{
2513 /* If this is positive, it's a block number, otherwise it's a
2514 bitwise-negated index into dw_ranges_by_label. */
2518 /* A structure to hold a macinfo entry. */
2520 typedef struct GTY(()) macinfo_struct
{
2522 unsigned HOST_WIDE_INT lineno
;
2527 DEF_VEC_O(macinfo_entry
);
2528 DEF_VEC_ALLOC_O(macinfo_entry
, gc
);
2530 struct GTY(()) dw_ranges_by_label_struct
{
2535 /* The comdat type node structure. */
2536 typedef struct GTY(()) comdat_type_struct
2538 dw_die_ref root_die
;
2539 dw_die_ref type_die
;
2540 dw_die_ref skeleton_die
;
2541 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2542 struct comdat_type_struct
*next
;
2546 /* The limbo die list structure. */
2547 typedef struct GTY(()) limbo_die_struct
{
2550 struct limbo_die_struct
*next
;
2554 typedef struct skeleton_chain_struct
2558 struct skeleton_chain_struct
*parent
;
2560 skeleton_chain_node
;
2562 /* Define a macro which returns nonzero for a TYPE_DECL which was
2563 implicitly generated for a type.
2565 Note that, unlike the C front-end (which generates a NULL named
2566 TYPE_DECL node for each complete tagged type, each array type,
2567 and each function type node created) the C++ front-end generates
2568 a _named_ TYPE_DECL node for each tagged type node created.
2569 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2570 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2571 front-end, but for each type, tagged or not. */
2573 #define TYPE_DECL_IS_STUB(decl) \
2574 (DECL_NAME (decl) == NULL_TREE \
2575 || (DECL_ARTIFICIAL (decl) \
2576 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2577 /* This is necessary for stub decls that \
2578 appear in nested inline functions. */ \
2579 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2580 && (decl_ultimate_origin (decl) \
2581 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2583 /* Information concerning the compilation unit's programming
2584 language, and compiler version. */
2586 /* Fixed size portion of the DWARF compilation unit header. */
2587 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2588 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2590 /* Fixed size portion of the DWARF comdat type unit header. */
2591 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2592 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2593 + DWARF_OFFSET_SIZE)
2595 /* Fixed size portion of public names info. */
2596 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2598 /* Fixed size portion of the address range info. */
2599 #define DWARF_ARANGES_HEADER_SIZE \
2600 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2601 DWARF2_ADDR_SIZE * 2) \
2602 - DWARF_INITIAL_LENGTH_SIZE)
2604 /* Size of padding portion in the address range info. It must be
2605 aligned to twice the pointer size. */
2606 #define DWARF_ARANGES_PAD_SIZE \
2607 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2608 DWARF2_ADDR_SIZE * 2) \
2609 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2611 /* Use assembler line directives if available. */
2612 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2613 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2614 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2616 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2620 /* Minimum line offset in a special line info. opcode.
2621 This value was chosen to give a reasonable range of values. */
2622 #define DWARF_LINE_BASE -10
2624 /* First special line opcode - leave room for the standard opcodes. */
2625 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2627 /* Range of line offsets in a special line info. opcode. */
2628 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2630 /* Flag that indicates the initial value of the is_stmt_start flag.
2631 In the present implementation, we do not mark any lines as
2632 the beginning of a source statement, because that information
2633 is not made available by the GCC front-end. */
2634 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2636 /* Maximum number of operations per instruction bundle. */
2637 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2638 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2641 /* This location is used by calc_die_sizes() to keep track
2642 the offset of each DIE within the .debug_info section. */
2643 static unsigned long next_die_offset
;
2645 /* Record the root of the DIE's built for the current compilation unit. */
2646 static GTY(()) dw_die_ref single_comp_unit_die
;
2648 /* A list of type DIEs that have been separated into comdat sections. */
2649 static GTY(()) comdat_type_node
*comdat_type_list
;
2651 /* A list of DIEs with a NULL parent waiting to be relocated. */
2652 static GTY(()) limbo_die_node
*limbo_die_list
;
2654 /* A list of DIEs for which we may have to generate
2655 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2656 static GTY(()) limbo_die_node
*deferred_asm_name
;
2658 /* Filenames referenced by this compilation unit. */
2659 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
2661 /* A hash table of references to DIE's that describe declarations.
2662 The key is a DECL_UID() which is a unique number identifying each decl. */
2663 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
2665 /* A hash table of references to DIE's that describe COMMON blocks.
2666 The key is DECL_UID() ^ die_parent. */
2667 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
2669 typedef struct GTY(()) die_arg_entry_struct
{
2674 DEF_VEC_O(die_arg_entry
);
2675 DEF_VEC_ALLOC_O(die_arg_entry
,gc
);
2677 /* Node of the variable location list. */
2678 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2679 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2680 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2681 in mode of the EXPR_LIST node and first EXPR_LIST operand
2682 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2683 location or NULL for padding. For larger bitsizes,
2684 mode is 0 and first operand is a CONCAT with bitsize
2685 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2686 NULL as second operand. */
2688 const char * GTY (()) label
;
2689 struct var_loc_node
* GTY (()) next
;
2692 /* Variable location list. */
2693 struct GTY (()) var_loc_list_def
{
2694 struct var_loc_node
* GTY (()) first
;
2696 /* Pointer to the last but one or last element of the
2697 chained list. If the list is empty, both first and
2698 last are NULL, if the list contains just one node
2699 or the last node certainly is not redundant, it points
2700 to the last node, otherwise points to the last but one.
2701 Do not mark it for GC because it is marked through the chain. */
2702 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2704 /* Pointer to the last element before section switch,
2705 if NULL, either sections weren't switched or first
2706 is after section switch. */
2707 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2709 /* DECL_UID of the variable decl. */
2710 unsigned int decl_id
;
2712 typedef struct var_loc_list_def var_loc_list
;
2714 /* Call argument location list. */
2715 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2716 rtx
GTY (()) call_arg_loc_note
;
2717 const char * GTY (()) label
;
2718 tree
GTY (()) block
;
2720 rtx
GTY (()) symbol_ref
;
2721 struct call_arg_loc_node
* GTY (()) next
;
2725 /* Table of decl location linked lists. */
2726 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
2728 /* Head and tail of call_arg_loc chain. */
2729 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2730 static struct call_arg_loc_node
*call_arg_loc_last
;
2732 /* Number of call sites in the current function. */
2733 static int call_site_count
= -1;
2734 /* Number of tail call sites in the current function. */
2735 static int tail_call_site_count
= -1;
2737 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2739 static VEC (dw_die_ref
, heap
) *block_map
;
2741 /* A cached location list. */
2742 struct GTY (()) cached_dw_loc_list_def
{
2743 /* The DECL_UID of the decl that this entry describes. */
2744 unsigned int decl_id
;
2746 /* The cached location list. */
2747 dw_loc_list_ref loc_list
;
2749 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2751 /* Table of cached location lists. */
2752 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
2754 /* A pointer to the base of a list of references to DIE's that
2755 are uniquely identified by their tag, presence/absence of
2756 children DIE's, and list of attribute/value pairs. */
2757 static GTY((length ("abbrev_die_table_allocated")))
2758 dw_die_ref
*abbrev_die_table
;
2760 /* Number of elements currently allocated for abbrev_die_table. */
2761 static GTY(()) unsigned abbrev_die_table_allocated
;
2763 /* Number of elements in type_die_table currently in use. */
2764 static GTY(()) unsigned abbrev_die_table_in_use
;
2766 /* Size (in elements) of increments by which we may expand the
2767 abbrev_die_table. */
2768 #define ABBREV_DIE_TABLE_INCREMENT 256
2770 /* A global counter for generating labels for line number data. */
2771 static unsigned int line_info_label_num
;
2773 /* The current table to which we should emit line number information
2774 for the current function. This will be set up at the beginning of
2775 assembly for the function. */
2776 static dw_line_info_table
*cur_line_info_table
;
2778 /* The two default tables of line number info. */
2779 static GTY(()) dw_line_info_table
*text_section_line_info
;
2780 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2782 /* The set of all non-default tables of line number info. */
2783 static GTY(()) VEC (dw_line_info_table_p
, gc
) *separate_line_info
;
2785 /* A flag to tell pubnames/types export if there is an info section to
2787 static bool info_section_emitted
;
2789 /* A pointer to the base of a table that contains a list of publicly
2790 accessible names. */
2791 static GTY (()) VEC (pubname_entry
, gc
) * pubname_table
;
2793 /* A pointer to the base of a table that contains a list of publicly
2794 accessible types. */
2795 static GTY (()) VEC (pubname_entry
, gc
) * pubtype_table
;
2797 /* A pointer to the base of a table that contains a list of macro
2798 defines/undefines (and file start/end markers). */
2799 static GTY (()) VEC (macinfo_entry
, gc
) * macinfo_table
;
2801 /* True if .debug_macinfo or .debug_macros section is going to be
2803 #define have_macinfo \
2804 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2805 && !VEC_empty (macinfo_entry, macinfo_table))
2807 /* Array of dies for which we should generate .debug_ranges info. */
2808 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2810 /* Number of elements currently allocated for ranges_table. */
2811 static GTY(()) unsigned ranges_table_allocated
;
2813 /* Number of elements in ranges_table currently in use. */
2814 static GTY(()) unsigned ranges_table_in_use
;
2816 /* Array of pairs of labels referenced in ranges_table. */
2817 static GTY ((length ("ranges_by_label_allocated")))
2818 dw_ranges_by_label_ref ranges_by_label
;
2820 /* Number of elements currently allocated for ranges_by_label. */
2821 static GTY(()) unsigned ranges_by_label_allocated
;
2823 /* Number of elements in ranges_by_label currently in use. */
2824 static GTY(()) unsigned ranges_by_label_in_use
;
2826 /* Size (in elements) of increments by which we may expand the
2828 #define RANGES_TABLE_INCREMENT 64
2830 /* Whether we have location lists that need outputting */
2831 static GTY(()) bool have_location_lists
;
2833 /* Unique label counter. */
2834 static GTY(()) unsigned int loclabel_num
;
2836 /* Unique label counter for point-of-call tables. */
2837 static GTY(()) unsigned int poc_label_num
;
2839 /* Record whether the function being analyzed contains inlined functions. */
2840 static int current_function_has_inlines
;
2842 /* The last file entry emitted by maybe_emit_file(). */
2843 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
2845 /* Number of internal labels generated by gen_internal_sym(). */
2846 static GTY(()) int label_num
;
2848 /* Cached result of previous call to lookup_filename. */
2849 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
2851 static GTY(()) VEC(die_arg_entry
,gc
) *tmpl_value_parm_die_table
;
2853 /* Instances of generic types for which we need to generate debug
2854 info that describe their generic parameters and arguments. That
2855 generation needs to happen once all types are properly laid out so
2856 we do it at the end of compilation. */
2857 static GTY(()) VEC(tree
,gc
) *generic_type_instances
;
2859 /* Offset from the "steady-state frame pointer" to the frame base,
2860 within the current function. */
2861 static HOST_WIDE_INT frame_pointer_fb_offset
;
2862 static bool frame_pointer_fb_offset_valid
;
2864 static VEC (dw_die_ref
, heap
) *base_types
;
2866 /* Forward declarations for functions defined in this file. */
2868 static int is_pseudo_reg (const_rtx
);
2869 static tree
type_main_variant (tree
);
2870 static int is_tagged_type (const_tree
);
2871 static const char *dwarf_tag_name (unsigned);
2872 static const char *dwarf_attr_name (unsigned);
2873 static const char *dwarf_form_name (unsigned);
2874 static tree
decl_ultimate_origin (const_tree
);
2875 static tree
decl_class_context (tree
);
2876 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
2877 static inline enum dw_val_class
AT_class (dw_attr_ref
);
2878 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
2879 static inline unsigned AT_flag (dw_attr_ref
);
2880 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
2881 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
2882 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
2883 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
2884 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
2885 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2886 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
2887 unsigned int, unsigned char *);
2888 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
2889 static hashval_t
debug_str_do_hash (const void *);
2890 static int debug_str_eq (const void *, const void *);
2891 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
2892 static inline const char *AT_string (dw_attr_ref
);
2893 static enum dwarf_form
AT_string_form (dw_attr_ref
);
2894 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
2895 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
2896 static inline dw_die_ref
AT_ref (dw_attr_ref
);
2897 static inline int AT_ref_external (dw_attr_ref
);
2898 static inline void set_AT_ref_external (dw_attr_ref
, int);
2899 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
2900 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
2901 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
2902 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
2904 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
2905 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
2906 static inline rtx
AT_addr (dw_attr_ref
);
2907 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
2908 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2909 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2910 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
2911 unsigned HOST_WIDE_INT
);
2912 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
2914 static inline const char *AT_lbl (dw_attr_ref
);
2915 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
2916 static const char *get_AT_low_pc (dw_die_ref
);
2917 static const char *get_AT_hi_pc (dw_die_ref
);
2918 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
2919 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
2920 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
2921 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
2922 static bool is_cxx (void);
2923 static bool is_fortran (void);
2924 static bool is_ada (void);
2925 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
2926 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
2927 static void add_child_die (dw_die_ref
, dw_die_ref
);
2928 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
2929 static dw_die_ref
lookup_type_die (tree
);
2930 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
2931 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
2932 static void equate_type_number_to_die (tree
, dw_die_ref
);
2933 static hashval_t
decl_die_table_hash (const void *);
2934 static int decl_die_table_eq (const void *, const void *);
2935 static dw_die_ref
lookup_decl_die (tree
);
2936 static hashval_t
common_block_die_table_hash (const void *);
2937 static int common_block_die_table_eq (const void *, const void *);
2938 static hashval_t
decl_loc_table_hash (const void *);
2939 static int decl_loc_table_eq (const void *, const void *);
2940 static var_loc_list
*lookup_decl_loc (const_tree
);
2941 static void equate_decl_number_to_die (tree
, dw_die_ref
);
2942 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
2943 static void print_spaces (FILE *);
2944 static void print_die (dw_die_ref
, FILE *);
2945 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
2946 static dw_die_ref
pop_compile_unit (dw_die_ref
);
2947 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
2948 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
2949 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
2950 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
2951 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
2952 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
2953 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
2954 struct md5_ctx
*, int *);
2955 struct checksum_attributes
;
2956 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
2957 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
2958 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
2959 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
2960 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
2961 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
2962 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
2963 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
2964 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
2965 static void compute_section_prefix (dw_die_ref
);
2966 static int is_type_die (dw_die_ref
);
2967 static int is_comdat_die (dw_die_ref
);
2968 static int is_symbol_die (dw_die_ref
);
2969 static void assign_symbol_names (dw_die_ref
);
2970 static void break_out_includes (dw_die_ref
);
2971 static int is_declaration_die (dw_die_ref
);
2972 static int should_move_die_to_comdat (dw_die_ref
);
2973 static dw_die_ref
clone_as_declaration (dw_die_ref
);
2974 static dw_die_ref
clone_die (dw_die_ref
);
2975 static dw_die_ref
clone_tree (dw_die_ref
);
2976 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
2977 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
2978 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
2979 static dw_die_ref
generate_skeleton (dw_die_ref
);
2980 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
2983 static void break_out_comdat_types (dw_die_ref
);
2984 static dw_die_ref
copy_ancestor_tree (dw_die_ref
, dw_die_ref
, htab_t
);
2985 static void copy_decls_walk (dw_die_ref
, dw_die_ref
, htab_t
);
2986 static void copy_decls_for_unworthy_types (dw_die_ref
);
2988 static hashval_t
htab_cu_hash (const void *);
2989 static int htab_cu_eq (const void *, const void *);
2990 static void htab_cu_del (void *);
2991 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
2992 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
2993 static void add_sibling_attributes (dw_die_ref
);
2994 static void build_abbrev_table (dw_die_ref
, htab_t
);
2995 static void output_location_lists (dw_die_ref
);
2996 static int constant_size (unsigned HOST_WIDE_INT
);
2997 static unsigned long size_of_die (dw_die_ref
);
2998 static void calc_die_sizes (dw_die_ref
);
2999 static void calc_base_type_die_sizes (void);
3000 static void mark_dies (dw_die_ref
);
3001 static void unmark_dies (dw_die_ref
);
3002 static void unmark_all_dies (dw_die_ref
);
3003 static unsigned long size_of_pubnames (VEC (pubname_entry
,gc
) *);
3004 static unsigned long size_of_aranges (void);
3005 static enum dwarf_form
value_format (dw_attr_ref
);
3006 static void output_value_format (dw_attr_ref
);
3007 static void output_abbrev_section (void);
3008 static void output_die_symbol (dw_die_ref
);
3009 static void output_die (dw_die_ref
);
3010 static void output_compilation_unit_header (void);
3011 static void output_comp_unit (dw_die_ref
, int);
3012 static void output_comdat_type_unit (comdat_type_node
*);
3013 static const char *dwarf2_name (tree
, int);
3014 static void add_pubname (tree
, dw_die_ref
);
3015 static void add_enumerator_pubname (const char *, dw_die_ref
);
3016 static void add_pubname_string (const char *, dw_die_ref
);
3017 static void add_pubtype (tree
, dw_die_ref
);
3018 static void output_pubnames (VEC (pubname_entry
,gc
) *);
3019 static void output_aranges (unsigned long);
3020 static unsigned int add_ranges_num (int);
3021 static unsigned int add_ranges (const_tree
);
3022 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3024 static void output_ranges (void);
3025 static dw_line_info_table
*new_line_info_table (void);
3026 static void output_line_info (void);
3027 static void output_file_names (void);
3028 static dw_die_ref
base_type_die (tree
);
3029 static int is_base_type (tree
);
3030 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3031 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3032 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3033 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3034 static int type_is_enum (const_tree
);
3035 static unsigned int dbx_reg_number (const_rtx
);
3036 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3037 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3038 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3039 enum var_init_status
);
3040 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3041 enum var_init_status
);
3042 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3043 enum var_init_status
);
3044 static int is_based_loc (const_rtx
);
3045 static int resolve_one_addr (rtx
*, void *);
3046 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3047 enum var_init_status
);
3048 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
3049 enum var_init_status
);
3050 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3051 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3052 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3053 static tree
field_type (const_tree
);
3054 static unsigned int simple_type_align_in_bits (const_tree
);
3055 static unsigned int simple_decl_align_in_bits (const_tree
);
3056 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3057 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3058 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3060 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3061 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3062 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3063 static void insert_double (double_int
, unsigned char *);
3064 static void insert_float (const_rtx
, unsigned char *);
3065 static rtx
rtl_for_decl_location (tree
);
3066 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3067 enum dwarf_attribute
);
3068 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3069 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3070 static void add_name_attribute (dw_die_ref
, const char *);
3071 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3072 static void add_comp_dir_attribute (dw_die_ref
);
3073 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3074 static void add_subscript_info (dw_die_ref
, tree
, bool);
3075 static void add_byte_size_attribute (dw_die_ref
, tree
);
3076 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3077 static void add_bit_size_attribute (dw_die_ref
, tree
);
3078 static void add_prototyped_attribute (dw_die_ref
, tree
);
3079 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3080 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3081 static void add_src_coords_attributes (dw_die_ref
, tree
);
3082 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3083 static void push_decl_scope (tree
);
3084 static void pop_decl_scope (void);
3085 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3086 static inline int local_scope_p (dw_die_ref
);
3087 static inline int class_scope_p (dw_die_ref
);
3088 static inline int class_or_namespace_scope_p (dw_die_ref
);
3089 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3090 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3091 static const char *type_tag (const_tree
);
3092 static tree
member_declared_type (const_tree
);
3094 static const char *decl_start_label (tree
);
3096 static void gen_array_type_die (tree
, dw_die_ref
);
3097 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3099 static void gen_entry_point_die (tree
, dw_die_ref
);
3101 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3102 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3103 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3104 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3105 static void gen_formal_types_die (tree
, dw_die_ref
);
3106 static void gen_subprogram_die (tree
, dw_die_ref
);
3107 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3108 static void gen_const_die (tree
, dw_die_ref
);
3109 static void gen_label_die (tree
, dw_die_ref
);
3110 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3111 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3112 static void gen_field_die (tree
, dw_die_ref
);
3113 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3114 static dw_die_ref
gen_compile_unit_die (const char *);
3115 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3116 static void gen_member_die (tree
, dw_die_ref
);
3117 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3118 enum debug_info_usage
);
3119 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3120 static void gen_typedef_die (tree
, dw_die_ref
);
3121 static void gen_type_die (tree
, dw_die_ref
);
3122 static void gen_block_die (tree
, dw_die_ref
, int);
3123 static void decls_for_scope (tree
, dw_die_ref
, int);
3124 static inline int is_redundant_typedef (const_tree
);
3125 static bool is_naming_typedef_decl (const_tree
);
3126 static inline dw_die_ref
get_context_die (tree
);
3127 static void gen_namespace_die (tree
, dw_die_ref
);
3128 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3129 static dw_die_ref
force_decl_die (tree
);
3130 static dw_die_ref
force_type_die (tree
);
3131 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3132 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3133 static struct dwarf_file_data
* lookup_filename (const char *);
3134 static void retry_incomplete_types (void);
3135 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3136 static void gen_generic_params_dies (tree
);
3137 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3138 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3139 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3140 static int file_info_cmp (const void *, const void *);
3141 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3142 const char *, const char *);
3143 static void output_loc_list (dw_loc_list_ref
);
3144 static char *gen_internal_sym (const char *);
3145 static bool want_pubnames (void);
3147 static void prune_unmark_dies (dw_die_ref
);
3148 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3149 static void prune_unused_types_mark (dw_die_ref
, int);
3150 static void prune_unused_types_walk (dw_die_ref
);
3151 static void prune_unused_types_walk_attribs (dw_die_ref
);
3152 static void prune_unused_types_prune (dw_die_ref
);
3153 static void prune_unused_types (void);
3154 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3155 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3156 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3157 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3158 const char *, const char *);
3159 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3160 static void gen_remaining_tmpl_value_param_die_attribute (void);
3161 static bool generic_type_p (tree
);
3162 static void schedule_generic_params_dies_gen (tree t
);
3163 static void gen_scheduled_generic_parms_dies (void);
3165 /* Section names used to hold DWARF debugging information. */
3166 #ifndef DEBUG_INFO_SECTION
3167 #define DEBUG_INFO_SECTION ".debug_info"
3169 #ifndef DEBUG_ABBREV_SECTION
3170 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3172 #ifndef DEBUG_ARANGES_SECTION
3173 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3175 #ifndef DEBUG_MACINFO_SECTION
3176 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3178 #ifndef DEBUG_MACRO_SECTION
3179 #define DEBUG_MACRO_SECTION ".debug_macro"
3181 #ifndef DEBUG_LINE_SECTION
3182 #define DEBUG_LINE_SECTION ".debug_line"
3184 #ifndef DEBUG_LOC_SECTION
3185 #define DEBUG_LOC_SECTION ".debug_loc"
3187 #ifndef DEBUG_PUBNAMES_SECTION
3188 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3190 #ifndef DEBUG_PUBTYPES_SECTION
3191 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
3193 #ifndef DEBUG_STR_SECTION
3194 #define DEBUG_STR_SECTION ".debug_str"
3196 #ifndef DEBUG_RANGES_SECTION
3197 #define DEBUG_RANGES_SECTION ".debug_ranges"
3200 /* Standard ELF section names for compiled code and data. */
3201 #ifndef TEXT_SECTION_NAME
3202 #define TEXT_SECTION_NAME ".text"
3205 /* Section flags for .debug_str section. */
3206 #define DEBUG_STR_SECTION_FLAGS \
3207 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3208 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3211 /* Labels we insert at beginning sections we can reference instead of
3212 the section names themselves. */
3214 #ifndef TEXT_SECTION_LABEL
3215 #define TEXT_SECTION_LABEL "Ltext"
3217 #ifndef COLD_TEXT_SECTION_LABEL
3218 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3220 #ifndef DEBUG_LINE_SECTION_LABEL
3221 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3223 #ifndef DEBUG_INFO_SECTION_LABEL
3224 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3226 #ifndef DEBUG_ABBREV_SECTION_LABEL
3227 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3229 #ifndef DEBUG_LOC_SECTION_LABEL
3230 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3232 #ifndef DEBUG_RANGES_SECTION_LABEL
3233 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3235 #ifndef DEBUG_MACINFO_SECTION_LABEL
3236 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3238 #ifndef DEBUG_MACRO_SECTION_LABEL
3239 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3243 /* Definitions of defaults for formats and names of various special
3244 (artificial) labels which may be generated within this file (when the -g
3245 options is used and DWARF2_DEBUGGING_INFO is in effect.
3246 If necessary, these may be overridden from within the tm.h file, but
3247 typically, overriding these defaults is unnecessary. */
3249 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3250 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3251 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3252 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3253 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3254 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3255 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3256 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3257 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3258 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3260 #ifndef TEXT_END_LABEL
3261 #define TEXT_END_LABEL "Letext"
3263 #ifndef COLD_END_LABEL
3264 #define COLD_END_LABEL "Letext_cold"
3266 #ifndef BLOCK_BEGIN_LABEL
3267 #define BLOCK_BEGIN_LABEL "LBB"
3269 #ifndef BLOCK_END_LABEL
3270 #define BLOCK_END_LABEL "LBE"
3272 #ifndef LINE_CODE_LABEL
3273 #define LINE_CODE_LABEL "LM"
3277 /* Return the root of the DIE's built for the current compilation unit. */
3279 comp_unit_die (void)
3281 if (!single_comp_unit_die
)
3282 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3283 return single_comp_unit_die
;
3286 /* We allow a language front-end to designate a function that is to be
3287 called to "demangle" any name before it is put into a DIE. */
3289 static const char *(*demangle_name_func
) (const char *);
3292 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3294 demangle_name_func
= func
;
3297 /* Test if rtl node points to a pseudo register. */
3300 is_pseudo_reg (const_rtx rtl
)
3302 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3303 || (GET_CODE (rtl
) == SUBREG
3304 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3307 /* Return a reference to a type, with its const and volatile qualifiers
3311 type_main_variant (tree type
)
3313 type
= TYPE_MAIN_VARIANT (type
);
3315 /* ??? There really should be only one main variant among any group of
3316 variants of a given type (and all of the MAIN_VARIANT values for all
3317 members of the group should point to that one type) but sometimes the C
3318 front-end messes this up for array types, so we work around that bug
3320 if (TREE_CODE (type
) == ARRAY_TYPE
)
3321 while (type
!= TYPE_MAIN_VARIANT (type
))
3322 type
= TYPE_MAIN_VARIANT (type
);
3327 /* Return nonzero if the given type node represents a tagged type. */
3330 is_tagged_type (const_tree type
)
3332 enum tree_code code
= TREE_CODE (type
);
3334 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3335 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3338 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3341 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3343 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3346 /* Return die_offset of a DIE reference to a base type. */
3348 static unsigned long int
3349 get_base_type_offset (dw_die_ref ref
)
3351 if (ref
->die_offset
)
3352 return ref
->die_offset
;
3353 if (comp_unit_die ()->die_abbrev
)
3355 calc_base_type_die_sizes ();
3356 gcc_assert (ref
->die_offset
);
3358 return ref
->die_offset
;
3361 /* Return die_offset of a DIE reference other than base type. */
3363 static unsigned long int
3364 get_ref_die_offset (dw_die_ref ref
)
3366 gcc_assert (ref
->die_offset
);
3367 return ref
->die_offset
;
3370 /* Convert a DIE tag into its string name. */
3373 dwarf_tag_name (unsigned int tag
)
3375 const char *name
= get_DW_TAG_name (tag
);
3380 return "DW_TAG_<unknown>";
3383 /* Convert a DWARF attribute code into its string name. */
3386 dwarf_attr_name (unsigned int attr
)
3392 #if VMS_DEBUGGING_INFO
3393 case DW_AT_HP_prologue
:
3394 return "DW_AT_HP_prologue";
3396 case DW_AT_MIPS_loop_unroll_factor
:
3397 return "DW_AT_MIPS_loop_unroll_factor";
3400 #if VMS_DEBUGGING_INFO
3401 case DW_AT_HP_epilogue
:
3402 return "DW_AT_HP_epilogue";
3404 case DW_AT_MIPS_stride
:
3405 return "DW_AT_MIPS_stride";
3409 name
= get_DW_AT_name (attr
);
3414 return "DW_AT_<unknown>";
3417 /* Convert a DWARF value form code into its string name. */
3420 dwarf_form_name (unsigned int form
)
3422 const char *name
= get_DW_FORM_name (form
);
3427 return "DW_FORM_<unknown>";
3430 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3431 instance of an inlined instance of a decl which is local to an inline
3432 function, so we have to trace all of the way back through the origin chain
3433 to find out what sort of node actually served as the original seed for the
3437 decl_ultimate_origin (const_tree decl
)
3439 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3442 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3443 nodes in the function to point to themselves; ignore that if
3444 we're trying to output the abstract instance of this function. */
3445 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3448 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3449 most distant ancestor, this should never happen. */
3450 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3452 return DECL_ABSTRACT_ORIGIN (decl
);
3455 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3456 of a virtual function may refer to a base class, so we check the 'this'
3460 decl_class_context (tree decl
)
3462 tree context
= NULL_TREE
;
3464 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3465 context
= DECL_CONTEXT (decl
);
3467 context
= TYPE_MAIN_VARIANT
3468 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3470 if (context
&& !TYPE_P (context
))
3471 context
= NULL_TREE
;
3476 /* Add an attribute/value pair to a DIE. */
3479 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3481 /* Maybe this should be an assert? */
3485 if (die
->die_attr
== NULL
)
3486 die
->die_attr
= VEC_alloc (dw_attr_node
, gc
, 1);
3487 VEC_safe_push (dw_attr_node
, gc
, die
->die_attr
, *attr
);
3490 static inline enum dw_val_class
3491 AT_class (dw_attr_ref a
)
3493 return a
->dw_attr_val
.val_class
;
3496 /* Add a flag value attribute to a DIE. */
3499 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3503 attr
.dw_attr
= attr_kind
;
3504 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3505 attr
.dw_attr_val
.v
.val_flag
= flag
;
3506 add_dwarf_attr (die
, &attr
);
3509 static inline unsigned
3510 AT_flag (dw_attr_ref a
)
3512 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3513 return a
->dw_attr_val
.v
.val_flag
;
3516 /* Add a signed integer attribute value to a DIE. */
3519 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3523 attr
.dw_attr
= attr_kind
;
3524 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3525 attr
.dw_attr_val
.v
.val_int
= int_val
;
3526 add_dwarf_attr (die
, &attr
);
3529 static inline HOST_WIDE_INT
3530 AT_int (dw_attr_ref a
)
3532 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3533 return a
->dw_attr_val
.v
.val_int
;
3536 /* Add an unsigned integer attribute value to a DIE. */
3539 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3540 unsigned HOST_WIDE_INT unsigned_val
)
3544 attr
.dw_attr
= attr_kind
;
3545 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3546 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3547 add_dwarf_attr (die
, &attr
);
3550 static inline unsigned HOST_WIDE_INT
3551 AT_unsigned (dw_attr_ref a
)
3553 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3554 return a
->dw_attr_val
.v
.val_unsigned
;
3557 /* Add an unsigned double integer attribute value to a DIE. */
3560 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3561 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3565 attr
.dw_attr
= attr_kind
;
3566 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3567 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3568 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3569 add_dwarf_attr (die
, &attr
);
3572 /* Add a floating point attribute value to a DIE and return it. */
3575 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3576 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3580 attr
.dw_attr
= attr_kind
;
3581 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3582 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3583 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3584 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3585 add_dwarf_attr (die
, &attr
);
3588 /* Add an 8-byte data attribute value to a DIE. */
3591 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3592 unsigned char data8
[8])
3596 attr
.dw_attr
= attr_kind
;
3597 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3598 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3599 add_dwarf_attr (die
, &attr
);
3602 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. */
3604 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
)
3608 attr
.dw_attr
= DW_AT_low_pc
;
3609 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3610 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_low
);
3611 add_dwarf_attr (die
, &attr
);
3613 attr
.dw_attr
= DW_AT_high_pc
;
3614 if (dwarf_version
< 4)
3615 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3617 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3618 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_high
);
3619 add_dwarf_attr (die
, &attr
);
3622 /* Hash and equality functions for debug_str_hash. */
3625 debug_str_do_hash (const void *x
)
3627 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
3631 debug_str_eq (const void *x1
, const void *x2
)
3633 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
3634 (const char *)x2
) == 0;
3637 /* Add STR to the indirect string hash table. */
3639 static struct indirect_string_node
*
3640 find_AT_string (const char *str
)
3642 struct indirect_string_node
*node
;
3645 if (! debug_str_hash
)
3646 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
3647 debug_str_eq
, NULL
);
3649 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
3650 htab_hash_string (str
), INSERT
);
3653 node
= ggc_alloc_cleared_indirect_string_node ();
3654 node
->str
= ggc_strdup (str
);
3658 node
= (struct indirect_string_node
*) *slot
;
3664 /* Add a string attribute value to a DIE. */
3667 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
3670 struct indirect_string_node
*node
;
3672 node
= find_AT_string (str
);
3674 attr
.dw_attr
= attr_kind
;
3675 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
3676 attr
.dw_attr_val
.v
.val_str
= node
;
3677 add_dwarf_attr (die
, &attr
);
3680 static inline const char *
3681 AT_string (dw_attr_ref a
)
3683 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3684 return a
->dw_attr_val
.v
.val_str
->str
;
3687 /* Find out whether a string should be output inline in DIE
3688 or out-of-line in .debug_str section. */
3690 static enum dwarf_form
3691 AT_string_form (dw_attr_ref a
)
3693 struct indirect_string_node
*node
;
3697 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3699 node
= a
->dw_attr_val
.v
.val_str
;
3703 len
= strlen (node
->str
) + 1;
3705 /* If the string is shorter or equal to the size of the reference, it is
3706 always better to put it inline. */
3707 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
3708 return node
->form
= DW_FORM_string
;
3710 /* If we cannot expect the linker to merge strings in .debug_str
3711 section, only put it into .debug_str if it is worth even in this
3713 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
3714 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
3715 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
3716 return node
->form
= DW_FORM_string
;
3718 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
3719 ++dw2_string_counter
;
3720 node
->label
= xstrdup (label
);
3722 return node
->form
= DW_FORM_strp
;
3725 /* Add a DIE reference attribute value to a DIE. */
3728 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
3732 #ifdef ENABLE_CHECKING
3733 gcc_assert (targ_die
!= NULL
);
3735 /* With LTO we can end up trying to reference something we didn't create
3736 a DIE for. Avoid crashing later on a NULL referenced DIE. */
3737 if (targ_die
== NULL
)
3741 attr
.dw_attr
= attr_kind
;
3742 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
3743 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
3744 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
3745 add_dwarf_attr (die
, &attr
);
3748 /* Change DIE reference REF to point to NEW_DIE instead. */
3751 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
3753 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
3754 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
3755 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
3758 /* Add an AT_specification attribute to a DIE, and also make the back
3759 pointer from the specification to the definition. */
3762 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
3764 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
3765 gcc_assert (!targ_die
->die_definition
);
3766 targ_die
->die_definition
= die
;
3769 static inline dw_die_ref
3770 AT_ref (dw_attr_ref a
)
3772 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
3773 return a
->dw_attr_val
.v
.val_die_ref
.die
;
3777 AT_ref_external (dw_attr_ref a
)
3779 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
3780 return a
->dw_attr_val
.v
.val_die_ref
.external
;
3786 set_AT_ref_external (dw_attr_ref a
, int i
)
3788 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
3789 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
3792 /* Add an FDE reference attribute value to a DIE. */
3795 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
3799 attr
.dw_attr
= attr_kind
;
3800 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
3801 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
3802 add_dwarf_attr (die
, &attr
);
3805 /* Add a location description attribute value to a DIE. */
3808 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
3812 attr
.dw_attr
= attr_kind
;
3813 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
3814 attr
.dw_attr_val
.v
.val_loc
= loc
;
3815 add_dwarf_attr (die
, &attr
);
3818 static inline dw_loc_descr_ref
3819 AT_loc (dw_attr_ref a
)
3821 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
3822 return a
->dw_attr_val
.v
.val_loc
;
3826 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
3830 attr
.dw_attr
= attr_kind
;
3831 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
3832 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
3833 add_dwarf_attr (die
, &attr
);
3834 have_location_lists
= true;
3837 static inline dw_loc_list_ref
3838 AT_loc_list (dw_attr_ref a
)
3840 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
3841 return a
->dw_attr_val
.v
.val_loc_list
;
3844 static inline dw_loc_list_ref
*
3845 AT_loc_list_ptr (dw_attr_ref a
)
3847 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
3848 return &a
->dw_attr_val
.v
.val_loc_list
;
3851 /* Add an address constant attribute value to a DIE. */
3854 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
3858 attr
.dw_attr
= attr_kind
;
3859 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
3860 attr
.dw_attr_val
.v
.val_addr
= addr
;
3861 add_dwarf_attr (die
, &attr
);
3864 /* Get the RTX from to an address DIE attribute. */
3867 AT_addr (dw_attr_ref a
)
3869 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
3870 return a
->dw_attr_val
.v
.val_addr
;
3873 /* Add a file attribute value to a DIE. */
3876 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3877 struct dwarf_file_data
*fd
)
3881 attr
.dw_attr
= attr_kind
;
3882 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
3883 attr
.dw_attr_val
.v
.val_file
= fd
;
3884 add_dwarf_attr (die
, &attr
);
3887 /* Get the dwarf_file_data from a file DIE attribute. */
3889 static inline struct dwarf_file_data
*
3890 AT_file (dw_attr_ref a
)
3892 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
3893 return a
->dw_attr_val
.v
.val_file
;
3896 /* Add a vms delta attribute value to a DIE. */
3899 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3900 const char *lbl1
, const char *lbl2
)
3904 attr
.dw_attr
= attr_kind
;
3905 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
3906 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
3907 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
3908 add_dwarf_attr (die
, &attr
);
3911 /* Add a label identifier attribute value to a DIE. */
3914 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
3918 attr
.dw_attr
= attr_kind
;
3919 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3920 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
3921 add_dwarf_attr (die
, &attr
);
3924 /* Add a section offset attribute value to a DIE, an offset into the
3925 debug_line section. */
3928 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3933 attr
.dw_attr
= attr_kind
;
3934 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
3935 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
3936 add_dwarf_attr (die
, &attr
);
3939 /* Add a section offset attribute value to a DIE, an offset into the
3940 debug_macinfo section. */
3943 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3948 attr
.dw_attr
= attr_kind
;
3949 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
3950 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
3951 add_dwarf_attr (die
, &attr
);
3954 /* Add an offset attribute value to a DIE. */
3957 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3958 unsigned HOST_WIDE_INT offset
)
3962 attr
.dw_attr
= attr_kind
;
3963 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
3964 attr
.dw_attr_val
.v
.val_offset
= offset
;
3965 add_dwarf_attr (die
, &attr
);
3968 /* Add an range_list attribute value to a DIE. */
3971 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3972 long unsigned int offset
)
3976 attr
.dw_attr
= attr_kind
;
3977 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
3978 attr
.dw_attr_val
.v
.val_offset
= offset
;
3979 add_dwarf_attr (die
, &attr
);
3982 /* Return the start label of a delta attribute. */
3984 static inline const char *
3985 AT_vms_delta1 (dw_attr_ref a
)
3987 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
3988 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
3991 /* Return the end label of a delta attribute. */
3993 static inline const char *
3994 AT_vms_delta2 (dw_attr_ref a
)
3996 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
3997 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4000 static inline const char *
4001 AT_lbl (dw_attr_ref a
)
4003 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4004 || AT_class (a
) == dw_val_class_lineptr
4005 || AT_class (a
) == dw_val_class_macptr
4006 || AT_class (a
) == dw_val_class_high_pc
));
4007 return a
->dw_attr_val
.v
.val_lbl_id
;
4010 /* Get the attribute of type attr_kind. */
4013 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4017 dw_die_ref spec
= NULL
;
4022 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
4023 if (a
->dw_attr
== attr_kind
)
4025 else if (a
->dw_attr
== DW_AT_specification
4026 || a
->dw_attr
== DW_AT_abstract_origin
)
4030 return get_AT (spec
, attr_kind
);
4035 /* Returns the parent of the declaration of DIE. */
4038 get_die_parent (dw_die_ref die
)
4045 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4046 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4049 return die
->die_parent
;
4052 /* Return the "low pc" attribute value, typically associated with a subprogram
4053 DIE. Return null if the "low pc" attribute is either not present, or if it
4054 cannot be represented as an assembler label identifier. */
4056 static inline const char *
4057 get_AT_low_pc (dw_die_ref die
)
4059 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4061 return a
? AT_lbl (a
) : NULL
;
4064 /* Return the "high pc" attribute value, typically associated with a subprogram
4065 DIE. Return null if the "high pc" attribute is either not present, or if it
4066 cannot be represented as an assembler label identifier. */
4068 static inline const char *
4069 get_AT_hi_pc (dw_die_ref die
)
4071 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4073 return a
? AT_lbl (a
) : NULL
;
4076 /* Return the value of the string attribute designated by ATTR_KIND, or
4077 NULL if it is not present. */
4079 static inline const char *
4080 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4082 dw_attr_ref a
= get_AT (die
, attr_kind
);
4084 return a
? AT_string (a
) : NULL
;
4087 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4088 if it is not present. */
4091 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4093 dw_attr_ref a
= get_AT (die
, attr_kind
);
4095 return a
? AT_flag (a
) : 0;
4098 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4099 if it is not present. */
4101 static inline unsigned
4102 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4104 dw_attr_ref a
= get_AT (die
, attr_kind
);
4106 return a
? AT_unsigned (a
) : 0;
4109 static inline dw_die_ref
4110 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4112 dw_attr_ref a
= get_AT (die
, attr_kind
);
4114 return a
? AT_ref (a
) : NULL
;
4117 static inline struct dwarf_file_data
*
4118 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4120 dw_attr_ref a
= get_AT (die
, attr_kind
);
4122 return a
? AT_file (a
) : NULL
;
4125 /* Return TRUE if the language is C++. */
4130 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4132 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4135 /* Return TRUE if the language is Fortran. */
4140 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4142 return (lang
== DW_LANG_Fortran77
4143 || lang
== DW_LANG_Fortran90
4144 || lang
== DW_LANG_Fortran95
);
4147 /* Return TRUE if the language is Ada. */
4152 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4154 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4157 /* Remove the specified attribute if present. */
4160 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4168 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
4169 if (a
->dw_attr
== attr_kind
)
4171 if (AT_class (a
) == dw_val_class_str
)
4172 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4173 a
->dw_attr_val
.v
.val_str
->refcount
--;
4175 /* VEC_ordered_remove should help reduce the number of abbrevs
4177 VEC_ordered_remove (dw_attr_node
, die
->die_attr
, ix
);
4182 /* Remove CHILD from its parent. PREV must have the property that
4183 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4186 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4188 gcc_assert (child
->die_parent
== prev
->die_parent
);
4189 gcc_assert (prev
->die_sib
== child
);
4192 gcc_assert (child
->die_parent
->die_child
== child
);
4196 prev
->die_sib
= child
->die_sib
;
4197 if (child
->die_parent
->die_child
== child
)
4198 child
->die_parent
->die_child
= prev
;
4201 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4202 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4205 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4207 dw_die_ref parent
= old_child
->die_parent
;
4209 gcc_assert (parent
== prev
->die_parent
);
4210 gcc_assert (prev
->die_sib
== old_child
);
4212 new_child
->die_parent
= parent
;
4213 if (prev
== old_child
)
4215 gcc_assert (parent
->die_child
== old_child
);
4216 new_child
->die_sib
= new_child
;
4220 prev
->die_sib
= new_child
;
4221 new_child
->die_sib
= old_child
->die_sib
;
4223 if (old_child
->die_parent
->die_child
== old_child
)
4224 old_child
->die_parent
->die_child
= new_child
;
4227 /* Move all children from OLD_PARENT to NEW_PARENT. */
4230 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4233 new_parent
->die_child
= old_parent
->die_child
;
4234 old_parent
->die_child
= NULL
;
4235 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4238 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4242 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4248 dw_die_ref prev
= c
;
4250 while (c
->die_tag
== tag
)
4252 remove_child_with_prev (c
, prev
);
4253 /* Might have removed every child. */
4254 if (c
== c
->die_sib
)
4258 } while (c
!= die
->die_child
);
4261 /* Add a CHILD_DIE as the last child of DIE. */
4264 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4266 /* FIXME this should probably be an assert. */
4267 if (! die
|| ! child_die
)
4269 gcc_assert (die
!= child_die
);
4271 child_die
->die_parent
= die
;
4274 child_die
->die_sib
= die
->die_child
->die_sib
;
4275 die
->die_child
->die_sib
= child_die
;
4278 child_die
->die_sib
= child_die
;
4279 die
->die_child
= child_die
;
4282 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4283 is the specification, to the end of PARENT's list of children.
4284 This is done by removing and re-adding it. */
4287 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4291 /* We want the declaration DIE from inside the class, not the
4292 specification DIE at toplevel. */
4293 if (child
->die_parent
!= parent
)
4295 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4301 gcc_assert (child
->die_parent
== parent
4302 || (child
->die_parent
4303 == get_AT_ref (parent
, DW_AT_specification
)));
4305 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4306 if (p
->die_sib
== child
)
4308 remove_child_with_prev (child
, p
);
4312 add_child_die (parent
, child
);
4315 /* Return a pointer to a newly created DIE node. */
4317 static inline dw_die_ref
4318 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4320 dw_die_ref die
= ggc_alloc_cleared_die_node ();
4322 die
->die_tag
= tag_value
;
4324 if (parent_die
!= NULL
)
4325 add_child_die (parent_die
, die
);
4328 limbo_die_node
*limbo_node
;
4330 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
4331 limbo_node
->die
= die
;
4332 limbo_node
->created_for
= t
;
4333 limbo_node
->next
= limbo_die_list
;
4334 limbo_die_list
= limbo_node
;
4340 /* Return the DIE associated with the given type specifier. */
4342 static inline dw_die_ref
4343 lookup_type_die (tree type
)
4345 return TYPE_SYMTAB_DIE (type
);
4348 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4349 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4350 anonymous type instead the one of the naming typedef. */
4352 static inline dw_die_ref
4353 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4356 && TREE_CODE (type
) == RECORD_TYPE
4358 && type_die
->die_tag
== DW_TAG_typedef
4359 && is_naming_typedef_decl (TYPE_NAME (type
)))
4360 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4364 /* Like lookup_type_die, but if type is an anonymous type named by a
4365 typedef[1], return the DIE of the anonymous type instead the one of
4366 the naming typedef. This is because in gen_typedef_die, we did
4367 equate the anonymous struct named by the typedef with the DIE of
4368 the naming typedef. So by default, lookup_type_die on an anonymous
4369 struct yields the DIE of the naming typedef.
4371 [1]: Read the comment of is_naming_typedef_decl to learn about what
4372 a naming typedef is. */
4374 static inline dw_die_ref
4375 lookup_type_die_strip_naming_typedef (tree type
)
4377 dw_die_ref die
= lookup_type_die (type
);
4378 return strip_naming_typedef (type
, die
);
4381 /* Equate a DIE to a given type specifier. */
4384 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
4386 TYPE_SYMTAB_DIE (type
) = type_die
;
4389 /* Returns a hash value for X (which really is a die_struct). */
4392 decl_die_table_hash (const void *x
)
4394 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
4397 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
4400 decl_die_table_eq (const void *x
, const void *y
)
4402 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4405 /* Return the DIE associated with a given declaration. */
4407 static inline dw_die_ref
4408 lookup_decl_die (tree decl
)
4410 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
4413 /* Returns a hash value for X (which really is a var_loc_list). */
4416 decl_loc_table_hash (const void *x
)
4418 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
4421 /* Return nonzero if decl_id of var_loc_list X is the same as
4425 decl_loc_table_eq (const void *x
, const void *y
)
4427 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4430 /* Return the var_loc list associated with a given declaration. */
4432 static inline var_loc_list
*
4433 lookup_decl_loc (const_tree decl
)
4435 if (!decl_loc_table
)
4437 return (var_loc_list
*)
4438 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
4441 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
4444 cached_dw_loc_list_table_hash (const void *x
)
4446 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
4449 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
4453 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
4455 return (((const cached_dw_loc_list
*) x
)->decl_id
4456 == DECL_UID ((const_tree
) y
));
4459 /* Equate a DIE to a particular declaration. */
4462 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
4464 unsigned int decl_id
= DECL_UID (decl
);
4467 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
4469 decl_die
->decl_id
= decl_id
;
4472 /* Return how many bits covers PIECE EXPR_LIST. */
4475 decl_piece_bitsize (rtx piece
)
4477 int ret
= (int) GET_MODE (piece
);
4480 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
4481 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
4482 return INTVAL (XEXP (XEXP (piece
, 0), 0));
4485 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
4488 decl_piece_varloc_ptr (rtx piece
)
4490 if ((int) GET_MODE (piece
))
4491 return &XEXP (piece
, 0);
4493 return &XEXP (XEXP (piece
, 0), 1);
4496 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
4497 Next is the chain of following piece nodes. */
4500 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
4502 if (bitsize
<= (int) MAX_MACHINE_MODE
)
4503 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
4505 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
4510 /* Return rtx that should be stored into loc field for
4511 LOC_NOTE and BITPOS/BITSIZE. */
4514 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
4515 HOST_WIDE_INT bitsize
)
4519 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
4521 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
4526 /* This function either modifies location piece list *DEST in
4527 place (if SRC and INNER is NULL), or copies location piece list
4528 *SRC to *DEST while modifying it. Location BITPOS is modified
4529 to contain LOC_NOTE, any pieces overlapping it are removed resp.
4530 not copied and if needed some padding around it is added.
4531 When modifying in place, DEST should point to EXPR_LIST where
4532 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
4533 to the start of the whole list and INNER points to the EXPR_LIST
4534 where earlier pieces cover PIECE_BITPOS bits. */
4537 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
4538 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
4539 HOST_WIDE_INT bitsize
, rtx loc_note
)
4542 bool copy
= inner
!= NULL
;
4546 /* First copy all nodes preceding the current bitpos. */
4547 while (src
!= inner
)
4549 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
4550 decl_piece_bitsize (*src
), NULL_RTX
);
4551 dest
= &XEXP (*dest
, 1);
4552 src
= &XEXP (*src
, 1);
4555 /* Add padding if needed. */
4556 if (bitpos
!= piece_bitpos
)
4558 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
4559 copy
? NULL_RTX
: *dest
);
4560 dest
= &XEXP (*dest
, 1);
4562 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
4565 /* A piece with correct bitpos and bitsize already exist,
4566 just update the location for it and return. */
4567 *decl_piece_varloc_ptr (*dest
) = loc_note
;
4570 /* Add the piece that changed. */
4571 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
4572 dest
= &XEXP (*dest
, 1);
4573 /* Skip over pieces that overlap it. */
4574 diff
= bitpos
- piece_bitpos
+ bitsize
;
4577 while (diff
> 0 && *src
)
4580 diff
-= decl_piece_bitsize (piece
);
4582 src
= &XEXP (piece
, 1);
4585 *src
= XEXP (piece
, 1);
4586 free_EXPR_LIST_node (piece
);
4589 /* Add padding if needed. */
4590 if (diff
< 0 && *src
)
4594 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
4595 dest
= &XEXP (*dest
, 1);
4599 /* Finally copy all nodes following it. */
4602 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
4603 decl_piece_bitsize (*src
), NULL_RTX
);
4604 dest
= &XEXP (*dest
, 1);
4605 src
= &XEXP (*src
, 1);
4609 /* Add a variable location node to the linked list for DECL. */
4611 static struct var_loc_node
*
4612 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
4614 unsigned int decl_id
;
4617 struct var_loc_node
*loc
= NULL
;
4618 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
4620 if (DECL_DEBUG_EXPR_IS_FROM (decl
))
4622 tree realdecl
= DECL_DEBUG_EXPR (decl
);
4623 if (realdecl
&& handled_component_p (realdecl
))
4625 HOST_WIDE_INT maxsize
;
4628 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
4629 if (!DECL_P (innerdecl
)
4630 || DECL_IGNORED_P (innerdecl
)
4631 || TREE_STATIC (innerdecl
)
4633 || bitpos
+ bitsize
> 256
4634 || bitsize
!= maxsize
)
4640 decl_id
= DECL_UID (decl
);
4641 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
4644 temp
= ggc_alloc_cleared_var_loc_list ();
4645 temp
->decl_id
= decl_id
;
4649 temp
= (var_loc_list
*) *slot
;
4651 /* For PARM_DECLs try to keep around the original incoming value,
4652 even if that means we'll emit a zero-range .debug_loc entry. */
4654 && temp
->first
== temp
->last
4655 && TREE_CODE (decl
) == PARM_DECL
4656 && GET_CODE (temp
->first
->loc
) == NOTE
4657 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
4658 && DECL_INCOMING_RTL (decl
)
4659 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
4660 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
4661 == GET_CODE (DECL_INCOMING_RTL (decl
))
4662 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
4664 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
4665 NOTE_VAR_LOCATION_LOC (loc_note
))
4666 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
4667 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
4669 loc
= ggc_alloc_cleared_var_loc_node ();
4670 temp
->first
->next
= loc
;
4672 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
4674 else if (temp
->last
)
4676 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
4677 rtx
*piece_loc
= NULL
, last_loc_note
;
4678 int piece_bitpos
= 0;
4682 gcc_assert (last
->next
== NULL
);
4684 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
4686 piece_loc
= &last
->loc
;
4689 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
4690 if (piece_bitpos
+ cur_bitsize
> bitpos
)
4692 piece_bitpos
+= cur_bitsize
;
4693 piece_loc
= &XEXP (*piece_loc
, 1);
4697 /* TEMP->LAST here is either pointer to the last but one or
4698 last element in the chained list, LAST is pointer to the
4700 if (label
&& strcmp (last
->label
, label
) == 0)
4702 /* For SRA optimized variables if there weren't any real
4703 insns since last note, just modify the last node. */
4704 if (piece_loc
!= NULL
)
4706 adjust_piece_list (piece_loc
, NULL
, NULL
,
4707 bitpos
, piece_bitpos
, bitsize
, loc_note
);
4710 /* If the last note doesn't cover any instructions, remove it. */
4711 if (temp
->last
!= last
)
4713 temp
->last
->next
= NULL
;
4716 gcc_assert (strcmp (last
->label
, label
) != 0);
4720 gcc_assert (temp
->first
== temp
->last
4721 || (temp
->first
->next
== temp
->last
4722 && TREE_CODE (decl
) == PARM_DECL
));
4723 memset (temp
->last
, '\0', sizeof (*temp
->last
));
4724 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
4728 if (bitsize
== -1 && NOTE_P (last
->loc
))
4729 last_loc_note
= last
->loc
;
4730 else if (piece_loc
!= NULL
4731 && *piece_loc
!= NULL_RTX
4732 && piece_bitpos
== bitpos
4733 && decl_piece_bitsize (*piece_loc
) == bitsize
)
4734 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
4736 last_loc_note
= NULL_RTX
;
4737 /* If the current location is the same as the end of the list,
4738 and either both or neither of the locations is uninitialized,
4739 we have nothing to do. */
4740 if (last_loc_note
== NULL_RTX
4741 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
4742 NOTE_VAR_LOCATION_LOC (loc_note
)))
4743 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
4744 != NOTE_VAR_LOCATION_STATUS (loc_note
))
4745 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
4746 == VAR_INIT_STATUS_UNINITIALIZED
)
4747 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
4748 == VAR_INIT_STATUS_UNINITIALIZED
))))
4750 /* Add LOC to the end of list and update LAST. If the last
4751 element of the list has been removed above, reuse its
4752 memory for the new node, otherwise allocate a new one. */
4756 memset (loc
, '\0', sizeof (*loc
));
4759 loc
= ggc_alloc_cleared_var_loc_node ();
4760 if (bitsize
== -1 || piece_loc
== NULL
)
4761 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
4763 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
4764 bitpos
, piece_bitpos
, bitsize
, loc_note
);
4766 /* Ensure TEMP->LAST will point either to the new last but one
4767 element of the chain, or to the last element in it. */
4768 if (last
!= temp
->last
)
4776 loc
= ggc_alloc_cleared_var_loc_node ();
4779 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
4784 /* Keep track of the number of spaces used to indent the
4785 output of the debugging routines that print the structure of
4786 the DIE internal representation. */
4787 static int print_indent
;
4789 /* Indent the line the number of spaces given by print_indent. */
4792 print_spaces (FILE *outfile
)
4794 fprintf (outfile
, "%*s", print_indent
, "");
4797 /* Print a type signature in hex. */
4800 print_signature (FILE *outfile
, char *sig
)
4804 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
4805 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
4808 /* Print the information associated with a given DIE, and its children.
4809 This routine is a debugging aid only. */
4812 print_die (dw_die_ref die
, FILE *outfile
)
4818 print_spaces (outfile
);
4819 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
4820 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
4822 print_spaces (outfile
);
4823 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
4824 fprintf (outfile
, " offset: %ld", die
->die_offset
);
4825 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
4827 if (die
->comdat_type_p
)
4829 print_spaces (outfile
);
4830 fprintf (outfile
, " signature: ");
4831 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
4832 fprintf (outfile
, "\n");
4835 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
4837 print_spaces (outfile
);
4838 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
4840 switch (AT_class (a
))
4842 case dw_val_class_addr
:
4843 fprintf (outfile
, "address");
4845 case dw_val_class_offset
:
4846 fprintf (outfile
, "offset");
4848 case dw_val_class_loc
:
4849 fprintf (outfile
, "location descriptor");
4851 case dw_val_class_loc_list
:
4852 fprintf (outfile
, "location list -> label:%s",
4853 AT_loc_list (a
)->ll_symbol
);
4855 case dw_val_class_range_list
:
4856 fprintf (outfile
, "range list");
4858 case dw_val_class_const
:
4859 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
4861 case dw_val_class_unsigned_const
:
4862 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
4864 case dw_val_class_const_double
:
4865 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
4866 HOST_WIDE_INT_PRINT_UNSIGNED
")",
4867 a
->dw_attr_val
.v
.val_double
.high
,
4868 a
->dw_attr_val
.v
.val_double
.low
);
4870 case dw_val_class_vec
:
4871 fprintf (outfile
, "floating-point or vector constant");
4873 case dw_val_class_flag
:
4874 fprintf (outfile
, "%u", AT_flag (a
));
4876 case dw_val_class_die_ref
:
4877 if (AT_ref (a
) != NULL
)
4879 if (AT_ref (a
)->comdat_type_p
)
4881 fprintf (outfile
, "die -> signature: ");
4882 print_signature (outfile
,
4883 AT_ref (a
)->die_id
.die_type_node
->signature
);
4885 else if (AT_ref (a
)->die_id
.die_symbol
)
4886 fprintf (outfile
, "die -> label: %s",
4887 AT_ref (a
)->die_id
.die_symbol
);
4889 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
4890 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
4893 fprintf (outfile
, "die -> <null>");
4895 case dw_val_class_vms_delta
:
4896 fprintf (outfile
, "delta: @slotcount(%s-%s)",
4897 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
4899 case dw_val_class_lbl_id
:
4900 case dw_val_class_lineptr
:
4901 case dw_val_class_macptr
:
4902 case dw_val_class_high_pc
:
4903 fprintf (outfile
, "label: %s", AT_lbl (a
));
4905 case dw_val_class_str
:
4906 if (AT_string (a
) != NULL
)
4907 fprintf (outfile
, "\"%s\"", AT_string (a
));
4909 fprintf (outfile
, "<null>");
4911 case dw_val_class_file
:
4912 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
4913 AT_file (a
)->emitted_number
);
4915 case dw_val_class_data8
:
4919 for (i
= 0; i
< 8; i
++)
4920 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
4927 fprintf (outfile
, "\n");
4930 if (die
->die_child
!= NULL
)
4933 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
4936 if (print_indent
== 0)
4937 fprintf (outfile
, "\n");
4940 /* Print the information collected for a given DIE. */
4943 debug_dwarf_die (dw_die_ref die
)
4945 print_die (die
, stderr
);
4948 /* Print all DWARF information collected for the compilation unit.
4949 This routine is a debugging aid only. */
4955 print_die (comp_unit_die (), stderr
);
4958 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
4959 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
4960 DIE that marks the start of the DIEs for this include file. */
4963 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
4965 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
4966 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
4968 new_unit
->die_sib
= old_unit
;
4972 /* Close an include-file CU and reopen the enclosing one. */
4975 pop_compile_unit (dw_die_ref old_unit
)
4977 dw_die_ref new_unit
= old_unit
->die_sib
;
4979 old_unit
->die_sib
= NULL
;
4983 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
4984 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
4986 /* Calculate the checksum of a location expression. */
4989 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
4993 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
4995 CHECKSUM (loc
->dw_loc_oprnd1
);
4996 CHECKSUM (loc
->dw_loc_oprnd2
);
4999 /* Calculate the checksum of an attribute. */
5002 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5004 dw_loc_descr_ref loc
;
5007 CHECKSUM (at
->dw_attr
);
5009 /* We don't care that this was compiled with a different compiler
5010 snapshot; if the output is the same, that's what matters. */
5011 if (at
->dw_attr
== DW_AT_producer
)
5014 switch (AT_class (at
))
5016 case dw_val_class_const
:
5017 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5019 case dw_val_class_unsigned_const
:
5020 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5022 case dw_val_class_const_double
:
5023 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5025 case dw_val_class_vec
:
5026 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5028 case dw_val_class_flag
:
5029 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5031 case dw_val_class_str
:
5032 CHECKSUM_STRING (AT_string (at
));
5035 case dw_val_class_addr
:
5037 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5038 CHECKSUM_STRING (XSTR (r
, 0));
5041 case dw_val_class_offset
:
5042 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5045 case dw_val_class_loc
:
5046 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5047 loc_checksum (loc
, ctx
);
5050 case dw_val_class_die_ref
:
5051 die_checksum (AT_ref (at
), ctx
, mark
);
5054 case dw_val_class_fde_ref
:
5055 case dw_val_class_vms_delta
:
5056 case dw_val_class_lbl_id
:
5057 case dw_val_class_lineptr
:
5058 case dw_val_class_macptr
:
5059 case dw_val_class_high_pc
:
5062 case dw_val_class_file
:
5063 CHECKSUM_STRING (AT_file (at
)->filename
);
5066 case dw_val_class_data8
:
5067 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5075 /* Calculate the checksum of a DIE. */
5078 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5084 /* To avoid infinite recursion. */
5087 CHECKSUM (die
->die_mark
);
5090 die
->die_mark
= ++(*mark
);
5092 CHECKSUM (die
->die_tag
);
5094 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
5095 attr_checksum (a
, ctx
, mark
);
5097 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5101 #undef CHECKSUM_STRING
5103 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5104 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5105 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5106 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5107 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5108 #define CHECKSUM_ATTR(FOO) \
5109 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5111 /* Calculate the checksum of a number in signed LEB128 format. */
5114 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5121 byte
= (value
& 0x7f);
5123 more
= !((value
== 0 && (byte
& 0x40) == 0)
5124 || (value
== -1 && (byte
& 0x40) != 0));
5133 /* Calculate the checksum of a number in unsigned LEB128 format. */
5136 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5140 unsigned char byte
= (value
& 0x7f);
5143 /* More bytes to follow. */
5151 /* Checksum the context of the DIE. This adds the names of any
5152 surrounding namespaces or structures to the checksum. */
5155 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5159 int tag
= die
->die_tag
;
5161 if (tag
!= DW_TAG_namespace
5162 && tag
!= DW_TAG_structure_type
5163 && tag
!= DW_TAG_class_type
)
5166 name
= get_AT_string (die
, DW_AT_name
);
5168 spec
= get_AT_ref (die
, DW_AT_specification
);
5172 if (die
->die_parent
!= NULL
)
5173 checksum_die_context (die
->die_parent
, ctx
);
5175 CHECKSUM_ULEB128 ('C');
5176 CHECKSUM_ULEB128 (tag
);
5178 CHECKSUM_STRING (name
);
5181 /* Calculate the checksum of a location expression. */
5184 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5186 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5187 were emitted as a DW_FORM_sdata instead of a location expression. */
5188 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5190 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5191 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5195 /* Otherwise, just checksum the raw location expression. */
5198 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5199 CHECKSUM (loc
->dw_loc_oprnd1
);
5200 CHECKSUM (loc
->dw_loc_oprnd2
);
5201 loc
= loc
->dw_loc_next
;
5205 /* Calculate the checksum of an attribute. */
5208 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5209 struct md5_ctx
*ctx
, int *mark
)
5211 dw_loc_descr_ref loc
;
5214 if (AT_class (at
) == dw_val_class_die_ref
)
5216 dw_die_ref target_die
= AT_ref (at
);
5218 /* For pointer and reference types, we checksum only the (qualified)
5219 name of the target type (if there is a name). For friend entries,
5220 we checksum only the (qualified) name of the target type or function.
5221 This allows the checksum to remain the same whether the target type
5222 is complete or not. */
5223 if ((at
->dw_attr
== DW_AT_type
5224 && (tag
== DW_TAG_pointer_type
5225 || tag
== DW_TAG_reference_type
5226 || tag
== DW_TAG_rvalue_reference_type
5227 || tag
== DW_TAG_ptr_to_member_type
))
5228 || (at
->dw_attr
== DW_AT_friend
5229 && tag
== DW_TAG_friend
))
5231 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5233 if (name_attr
!= NULL
)
5235 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5239 CHECKSUM_ULEB128 ('N');
5240 CHECKSUM_ULEB128 (at
->dw_attr
);
5241 if (decl
->die_parent
!= NULL
)
5242 checksum_die_context (decl
->die_parent
, ctx
);
5243 CHECKSUM_ULEB128 ('E');
5244 CHECKSUM_STRING (AT_string (name_attr
));
5249 /* For all other references to another DIE, we check to see if the
5250 target DIE has already been visited. If it has, we emit a
5251 backward reference; if not, we descend recursively. */
5252 if (target_die
->die_mark
> 0)
5254 CHECKSUM_ULEB128 ('R');
5255 CHECKSUM_ULEB128 (at
->dw_attr
);
5256 CHECKSUM_ULEB128 (target_die
->die_mark
);
5260 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5264 target_die
->die_mark
= ++(*mark
);
5265 CHECKSUM_ULEB128 ('T');
5266 CHECKSUM_ULEB128 (at
->dw_attr
);
5267 if (decl
->die_parent
!= NULL
)
5268 checksum_die_context (decl
->die_parent
, ctx
);
5269 die_checksum_ordered (target_die
, ctx
, mark
);
5274 CHECKSUM_ULEB128 ('A');
5275 CHECKSUM_ULEB128 (at
->dw_attr
);
5277 switch (AT_class (at
))
5279 case dw_val_class_const
:
5280 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5281 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5284 case dw_val_class_unsigned_const
:
5285 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5286 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5289 case dw_val_class_const_double
:
5290 CHECKSUM_ULEB128 (DW_FORM_block
);
5291 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5292 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5295 case dw_val_class_vec
:
5296 CHECKSUM_ULEB128 (DW_FORM_block
);
5297 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_vec
));
5298 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5301 case dw_val_class_flag
:
5302 CHECKSUM_ULEB128 (DW_FORM_flag
);
5303 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
5306 case dw_val_class_str
:
5307 CHECKSUM_ULEB128 (DW_FORM_string
);
5308 CHECKSUM_STRING (AT_string (at
));
5311 case dw_val_class_addr
:
5313 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5314 CHECKSUM_ULEB128 (DW_FORM_string
);
5315 CHECKSUM_STRING (XSTR (r
, 0));
5318 case dw_val_class_offset
:
5319 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5320 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
5323 case dw_val_class_loc
:
5324 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5325 loc_checksum_ordered (loc
, ctx
);
5328 case dw_val_class_fde_ref
:
5329 case dw_val_class_lbl_id
:
5330 case dw_val_class_lineptr
:
5331 case dw_val_class_macptr
:
5332 case dw_val_class_high_pc
:
5335 case dw_val_class_file
:
5336 CHECKSUM_ULEB128 (DW_FORM_string
);
5337 CHECKSUM_STRING (AT_file (at
)->filename
);
5340 case dw_val_class_data8
:
5341 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5349 struct checksum_attributes
5351 dw_attr_ref at_name
;
5352 dw_attr_ref at_type
;
5353 dw_attr_ref at_friend
;
5354 dw_attr_ref at_accessibility
;
5355 dw_attr_ref at_address_class
;
5356 dw_attr_ref at_allocated
;
5357 dw_attr_ref at_artificial
;
5358 dw_attr_ref at_associated
;
5359 dw_attr_ref at_binary_scale
;
5360 dw_attr_ref at_bit_offset
;
5361 dw_attr_ref at_bit_size
;
5362 dw_attr_ref at_bit_stride
;
5363 dw_attr_ref at_byte_size
;
5364 dw_attr_ref at_byte_stride
;
5365 dw_attr_ref at_const_value
;
5366 dw_attr_ref at_containing_type
;
5367 dw_attr_ref at_count
;
5368 dw_attr_ref at_data_location
;
5369 dw_attr_ref at_data_member_location
;
5370 dw_attr_ref at_decimal_scale
;
5371 dw_attr_ref at_decimal_sign
;
5372 dw_attr_ref at_default_value
;
5373 dw_attr_ref at_digit_count
;
5374 dw_attr_ref at_discr
;
5375 dw_attr_ref at_discr_list
;
5376 dw_attr_ref at_discr_value
;
5377 dw_attr_ref at_encoding
;
5378 dw_attr_ref at_endianity
;
5379 dw_attr_ref at_explicit
;
5380 dw_attr_ref at_is_optional
;
5381 dw_attr_ref at_location
;
5382 dw_attr_ref at_lower_bound
;
5383 dw_attr_ref at_mutable
;
5384 dw_attr_ref at_ordering
;
5385 dw_attr_ref at_picture_string
;
5386 dw_attr_ref at_prototyped
;
5387 dw_attr_ref at_small
;
5388 dw_attr_ref at_segment
;
5389 dw_attr_ref at_string_length
;
5390 dw_attr_ref at_threads_scaled
;
5391 dw_attr_ref at_upper_bound
;
5392 dw_attr_ref at_use_location
;
5393 dw_attr_ref at_use_UTF8
;
5394 dw_attr_ref at_variable_parameter
;
5395 dw_attr_ref at_virtuality
;
5396 dw_attr_ref at_visibility
;
5397 dw_attr_ref at_vtable_elem_location
;
5400 /* Collect the attributes that we will want to use for the checksum. */
5403 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
5408 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
5419 attrs
->at_friend
= a
;
5421 case DW_AT_accessibility
:
5422 attrs
->at_accessibility
= a
;
5424 case DW_AT_address_class
:
5425 attrs
->at_address_class
= a
;
5427 case DW_AT_allocated
:
5428 attrs
->at_allocated
= a
;
5430 case DW_AT_artificial
:
5431 attrs
->at_artificial
= a
;
5433 case DW_AT_associated
:
5434 attrs
->at_associated
= a
;
5436 case DW_AT_binary_scale
:
5437 attrs
->at_binary_scale
= a
;
5439 case DW_AT_bit_offset
:
5440 attrs
->at_bit_offset
= a
;
5442 case DW_AT_bit_size
:
5443 attrs
->at_bit_size
= a
;
5445 case DW_AT_bit_stride
:
5446 attrs
->at_bit_stride
= a
;
5448 case DW_AT_byte_size
:
5449 attrs
->at_byte_size
= a
;
5451 case DW_AT_byte_stride
:
5452 attrs
->at_byte_stride
= a
;
5454 case DW_AT_const_value
:
5455 attrs
->at_const_value
= a
;
5457 case DW_AT_containing_type
:
5458 attrs
->at_containing_type
= a
;
5461 attrs
->at_count
= a
;
5463 case DW_AT_data_location
:
5464 attrs
->at_data_location
= a
;
5466 case DW_AT_data_member_location
:
5467 attrs
->at_data_member_location
= a
;
5469 case DW_AT_decimal_scale
:
5470 attrs
->at_decimal_scale
= a
;
5472 case DW_AT_decimal_sign
:
5473 attrs
->at_decimal_sign
= a
;
5475 case DW_AT_default_value
:
5476 attrs
->at_default_value
= a
;
5478 case DW_AT_digit_count
:
5479 attrs
->at_digit_count
= a
;
5482 attrs
->at_discr
= a
;
5484 case DW_AT_discr_list
:
5485 attrs
->at_discr_list
= a
;
5487 case DW_AT_discr_value
:
5488 attrs
->at_discr_value
= a
;
5490 case DW_AT_encoding
:
5491 attrs
->at_encoding
= a
;
5493 case DW_AT_endianity
:
5494 attrs
->at_endianity
= a
;
5496 case DW_AT_explicit
:
5497 attrs
->at_explicit
= a
;
5499 case DW_AT_is_optional
:
5500 attrs
->at_is_optional
= a
;
5502 case DW_AT_location
:
5503 attrs
->at_location
= a
;
5505 case DW_AT_lower_bound
:
5506 attrs
->at_lower_bound
= a
;
5509 attrs
->at_mutable
= a
;
5511 case DW_AT_ordering
:
5512 attrs
->at_ordering
= a
;
5514 case DW_AT_picture_string
:
5515 attrs
->at_picture_string
= a
;
5517 case DW_AT_prototyped
:
5518 attrs
->at_prototyped
= a
;
5521 attrs
->at_small
= a
;
5524 attrs
->at_segment
= a
;
5526 case DW_AT_string_length
:
5527 attrs
->at_string_length
= a
;
5529 case DW_AT_threads_scaled
:
5530 attrs
->at_threads_scaled
= a
;
5532 case DW_AT_upper_bound
:
5533 attrs
->at_upper_bound
= a
;
5535 case DW_AT_use_location
:
5536 attrs
->at_use_location
= a
;
5538 case DW_AT_use_UTF8
:
5539 attrs
->at_use_UTF8
= a
;
5541 case DW_AT_variable_parameter
:
5542 attrs
->at_variable_parameter
= a
;
5544 case DW_AT_virtuality
:
5545 attrs
->at_virtuality
= a
;
5547 case DW_AT_visibility
:
5548 attrs
->at_visibility
= a
;
5550 case DW_AT_vtable_elem_location
:
5551 attrs
->at_vtable_elem_location
= a
;
5559 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
5562 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5566 struct checksum_attributes attrs
;
5568 CHECKSUM_ULEB128 ('D');
5569 CHECKSUM_ULEB128 (die
->die_tag
);
5571 memset (&attrs
, 0, sizeof (attrs
));
5573 decl
= get_AT_ref (die
, DW_AT_specification
);
5575 collect_checksum_attributes (&attrs
, decl
);
5576 collect_checksum_attributes (&attrs
, die
);
5578 CHECKSUM_ATTR (attrs
.at_name
);
5579 CHECKSUM_ATTR (attrs
.at_accessibility
);
5580 CHECKSUM_ATTR (attrs
.at_address_class
);
5581 CHECKSUM_ATTR (attrs
.at_allocated
);
5582 CHECKSUM_ATTR (attrs
.at_artificial
);
5583 CHECKSUM_ATTR (attrs
.at_associated
);
5584 CHECKSUM_ATTR (attrs
.at_binary_scale
);
5585 CHECKSUM_ATTR (attrs
.at_bit_offset
);
5586 CHECKSUM_ATTR (attrs
.at_bit_size
);
5587 CHECKSUM_ATTR (attrs
.at_bit_stride
);
5588 CHECKSUM_ATTR (attrs
.at_byte_size
);
5589 CHECKSUM_ATTR (attrs
.at_byte_stride
);
5590 CHECKSUM_ATTR (attrs
.at_const_value
);
5591 CHECKSUM_ATTR (attrs
.at_containing_type
);
5592 CHECKSUM_ATTR (attrs
.at_count
);
5593 CHECKSUM_ATTR (attrs
.at_data_location
);
5594 CHECKSUM_ATTR (attrs
.at_data_member_location
);
5595 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
5596 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
5597 CHECKSUM_ATTR (attrs
.at_default_value
);
5598 CHECKSUM_ATTR (attrs
.at_digit_count
);
5599 CHECKSUM_ATTR (attrs
.at_discr
);
5600 CHECKSUM_ATTR (attrs
.at_discr_list
);
5601 CHECKSUM_ATTR (attrs
.at_discr_value
);
5602 CHECKSUM_ATTR (attrs
.at_encoding
);
5603 CHECKSUM_ATTR (attrs
.at_endianity
);
5604 CHECKSUM_ATTR (attrs
.at_explicit
);
5605 CHECKSUM_ATTR (attrs
.at_is_optional
);
5606 CHECKSUM_ATTR (attrs
.at_location
);
5607 CHECKSUM_ATTR (attrs
.at_lower_bound
);
5608 CHECKSUM_ATTR (attrs
.at_mutable
);
5609 CHECKSUM_ATTR (attrs
.at_ordering
);
5610 CHECKSUM_ATTR (attrs
.at_picture_string
);
5611 CHECKSUM_ATTR (attrs
.at_prototyped
);
5612 CHECKSUM_ATTR (attrs
.at_small
);
5613 CHECKSUM_ATTR (attrs
.at_segment
);
5614 CHECKSUM_ATTR (attrs
.at_string_length
);
5615 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
5616 CHECKSUM_ATTR (attrs
.at_upper_bound
);
5617 CHECKSUM_ATTR (attrs
.at_use_location
);
5618 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
5619 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
5620 CHECKSUM_ATTR (attrs
.at_virtuality
);
5621 CHECKSUM_ATTR (attrs
.at_visibility
);
5622 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
5623 CHECKSUM_ATTR (attrs
.at_type
);
5624 CHECKSUM_ATTR (attrs
.at_friend
);
5626 /* Checksum the child DIEs, except for nested types and member functions. */
5629 dw_attr_ref name_attr
;
5632 name_attr
= get_AT (c
, DW_AT_name
);
5633 if ((is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
)
5634 && name_attr
!= NULL
)
5636 CHECKSUM_ULEB128 ('S');
5637 CHECKSUM_ULEB128 (c
->die_tag
);
5638 CHECKSUM_STRING (AT_string (name_attr
));
5642 /* Mark this DIE so it gets processed when unmarking. */
5643 if (c
->die_mark
== 0)
5645 die_checksum_ordered (c
, ctx
, mark
);
5647 } while (c
!= die
->die_child
);
5649 CHECKSUM_ULEB128 (0);
5653 #undef CHECKSUM_STRING
5654 #undef CHECKSUM_ATTR
5655 #undef CHECKSUM_LEB128
5656 #undef CHECKSUM_ULEB128
5658 /* Generate the type signature for DIE. This is computed by generating an
5659 MD5 checksum over the DIE's tag, its relevant attributes, and its
5660 children. Attributes that are references to other DIEs are processed
5661 by recursion, using the MARK field to prevent infinite recursion.
5662 If the DIE is nested inside a namespace or another type, we also
5663 need to include that context in the signature. The lower 64 bits
5664 of the resulting MD5 checksum comprise the signature. */
5667 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
5671 unsigned char checksum
[16];
5676 name
= get_AT_string (die
, DW_AT_name
);
5677 decl
= get_AT_ref (die
, DW_AT_specification
);
5678 parent
= get_die_parent (die
);
5680 /* First, compute a signature for just the type name (and its surrounding
5681 context, if any. This is stored in the type unit DIE for link-time
5682 ODR (one-definition rule) checking. */
5684 if (is_cxx() && name
!= NULL
)
5686 md5_init_ctx (&ctx
);
5688 /* Checksum the names of surrounding namespaces and structures. */
5690 checksum_die_context (parent
, &ctx
);
5692 md5_process_bytes (&die
->die_tag
, sizeof (die
->die_tag
), &ctx
);
5693 md5_process_bytes (name
, strlen (name
) + 1, &ctx
);
5694 md5_finish_ctx (&ctx
, checksum
);
5696 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
5699 /* Next, compute the complete type signature. */
5701 md5_init_ctx (&ctx
);
5703 die
->die_mark
= mark
;
5705 /* Checksum the names of surrounding namespaces and structures. */
5707 checksum_die_context (parent
, &ctx
);
5709 /* Checksum the DIE and its children. */
5710 die_checksum_ordered (die
, &ctx
, &mark
);
5711 unmark_all_dies (die
);
5712 md5_finish_ctx (&ctx
, checksum
);
5714 /* Store the signature in the type node and link the type DIE and the
5715 type node together. */
5716 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
5717 DWARF_TYPE_SIGNATURE_SIZE
);
5718 die
->comdat_type_p
= true;
5719 die
->die_id
.die_type_node
= type_node
;
5720 type_node
->type_die
= die
;
5722 /* If the DIE is a specification, link its declaration to the type node
5726 decl
->comdat_type_p
= true;
5727 decl
->die_id
.die_type_node
= type_node
;
5731 /* Do the location expressions look same? */
5733 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
5735 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
5736 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
5737 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
5740 /* Do the values look the same? */
5742 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
5744 dw_loc_descr_ref loc1
, loc2
;
5747 if (v1
->val_class
!= v2
->val_class
)
5750 switch (v1
->val_class
)
5752 case dw_val_class_const
:
5753 return v1
->v
.val_int
== v2
->v
.val_int
;
5754 case dw_val_class_unsigned_const
:
5755 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
5756 case dw_val_class_const_double
:
5757 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
5758 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
5759 case dw_val_class_vec
:
5760 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
5761 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
5763 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
5764 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
5767 case dw_val_class_flag
:
5768 return v1
->v
.val_flag
== v2
->v
.val_flag
;
5769 case dw_val_class_str
:
5770 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
5772 case dw_val_class_addr
:
5773 r1
= v1
->v
.val_addr
;
5774 r2
= v2
->v
.val_addr
;
5775 if (GET_CODE (r1
) != GET_CODE (r2
))
5777 return !rtx_equal_p (r1
, r2
);
5779 case dw_val_class_offset
:
5780 return v1
->v
.val_offset
== v2
->v
.val_offset
;
5782 case dw_val_class_loc
:
5783 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
5785 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
5786 if (!same_loc_p (loc1
, loc2
, mark
))
5788 return !loc1
&& !loc2
;
5790 case dw_val_class_die_ref
:
5791 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
5793 case dw_val_class_fde_ref
:
5794 case dw_val_class_vms_delta
:
5795 case dw_val_class_lbl_id
:
5796 case dw_val_class_lineptr
:
5797 case dw_val_class_macptr
:
5798 case dw_val_class_high_pc
:
5801 case dw_val_class_file
:
5802 return v1
->v
.val_file
== v2
->v
.val_file
;
5804 case dw_val_class_data8
:
5805 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
5812 /* Do the attributes look the same? */
5815 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
5817 if (at1
->dw_attr
!= at2
->dw_attr
)
5820 /* We don't care that this was compiled with a different compiler
5821 snapshot; if the output is the same, that's what matters. */
5822 if (at1
->dw_attr
== DW_AT_producer
)
5825 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
5828 /* Do the dies look the same? */
5831 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
5837 /* To avoid infinite recursion. */
5839 return die1
->die_mark
== die2
->die_mark
;
5840 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
5842 if (die1
->die_tag
!= die2
->die_tag
)
5845 if (VEC_length (dw_attr_node
, die1
->die_attr
)
5846 != VEC_length (dw_attr_node
, die2
->die_attr
))
5849 FOR_EACH_VEC_ELT (dw_attr_node
, die1
->die_attr
, ix
, a1
)
5850 if (!same_attr_p (a1
, &VEC_index (dw_attr_node
, die2
->die_attr
, ix
), mark
))
5853 c1
= die1
->die_child
;
5854 c2
= die2
->die_child
;
5863 if (!same_die_p (c1
, c2
, mark
))
5867 if (c1
== die1
->die_child
)
5869 if (c2
== die2
->die_child
)
5879 /* Do the dies look the same? Wrapper around same_die_p. */
5882 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
5885 int ret
= same_die_p (die1
, die2
, &mark
);
5887 unmark_all_dies (die1
);
5888 unmark_all_dies (die2
);
5893 /* The prefix to attach to symbols on DIEs in the current comdat debug
5895 static const char *comdat_symbol_id
;
5897 /* The index of the current symbol within the current comdat CU. */
5898 static unsigned int comdat_symbol_number
;
5900 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5901 children, and set comdat_symbol_id accordingly. */
5904 compute_section_prefix (dw_die_ref unit_die
)
5906 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
5907 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
5908 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
5911 unsigned char checksum
[16];
5914 /* Compute the checksum of the DIE, then append part of it as hex digits to
5915 the name filename of the unit. */
5917 md5_init_ctx (&ctx
);
5919 die_checksum (unit_die
, &ctx
, &mark
);
5920 unmark_all_dies (unit_die
);
5921 md5_finish_ctx (&ctx
, checksum
);
5923 sprintf (name
, "%s.", base
);
5924 clean_symbol_name (name
);
5926 p
= name
+ strlen (name
);
5927 for (i
= 0; i
< 4; i
++)
5929 sprintf (p
, "%.2x", checksum
[i
]);
5933 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
5934 comdat_symbol_number
= 0;
5937 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5940 is_type_die (dw_die_ref die
)
5942 switch (die
->die_tag
)
5944 case DW_TAG_array_type
:
5945 case DW_TAG_class_type
:
5946 case DW_TAG_interface_type
:
5947 case DW_TAG_enumeration_type
:
5948 case DW_TAG_pointer_type
:
5949 case DW_TAG_reference_type
:
5950 case DW_TAG_rvalue_reference_type
:
5951 case DW_TAG_string_type
:
5952 case DW_TAG_structure_type
:
5953 case DW_TAG_subroutine_type
:
5954 case DW_TAG_union_type
:
5955 case DW_TAG_ptr_to_member_type
:
5956 case DW_TAG_set_type
:
5957 case DW_TAG_subrange_type
:
5958 case DW_TAG_base_type
:
5959 case DW_TAG_const_type
:
5960 case DW_TAG_file_type
:
5961 case DW_TAG_packed_type
:
5962 case DW_TAG_volatile_type
:
5963 case DW_TAG_typedef
:
5970 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5971 Basically, we want to choose the bits that are likely to be shared between
5972 compilations (types) and leave out the bits that are specific to individual
5973 compilations (functions). */
5976 is_comdat_die (dw_die_ref c
)
5978 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5979 we do for stabs. The advantage is a greater likelihood of sharing between
5980 objects that don't include headers in the same order (and therefore would
5981 put the base types in a different comdat). jason 8/28/00 */
5983 if (c
->die_tag
== DW_TAG_base_type
)
5986 if (c
->die_tag
== DW_TAG_pointer_type
5987 || c
->die_tag
== DW_TAG_reference_type
5988 || c
->die_tag
== DW_TAG_rvalue_reference_type
5989 || c
->die_tag
== DW_TAG_const_type
5990 || c
->die_tag
== DW_TAG_volatile_type
)
5992 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
5994 return t
? is_comdat_die (t
) : 0;
5997 return is_type_die (c
);
6000 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6001 compilation unit. */
6004 is_symbol_die (dw_die_ref c
)
6006 return (is_type_die (c
)
6007 || is_declaration_die (c
)
6008 || c
->die_tag
== DW_TAG_namespace
6009 || c
->die_tag
== DW_TAG_module
);
6012 /* Returns true iff C is a compile-unit DIE. */
6015 is_cu_die (dw_die_ref c
)
6017 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6020 /* Returns true iff C is a unit DIE of some sort. */
6023 is_unit_die (dw_die_ref c
)
6025 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6026 || c
->die_tag
== DW_TAG_partial_unit
6027 || c
->die_tag
== DW_TAG_type_unit
);
6030 /* Returns true iff C is a namespace DIE. */
6033 is_namespace_die (dw_die_ref c
)
6035 return c
&& c
->die_tag
== DW_TAG_namespace
;
6038 /* Returns true iff C is a class or structure DIE. */
6041 is_class_die (dw_die_ref c
)
6043 return c
&& (c
->die_tag
== DW_TAG_class_type
6044 || c
->die_tag
== DW_TAG_structure_type
);
6048 gen_internal_sym (const char *prefix
)
6052 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6053 return xstrdup (buf
);
6056 /* Assign symbols to all worthy DIEs under DIE. */
6059 assign_symbol_names (dw_die_ref die
)
6063 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6065 if (comdat_symbol_id
)
6067 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6069 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6070 comdat_symbol_id
, comdat_symbol_number
++);
6071 die
->die_id
.die_symbol
= xstrdup (p
);
6074 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6077 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6080 struct cu_hash_table_entry
6083 unsigned min_comdat_num
, max_comdat_num
;
6084 struct cu_hash_table_entry
*next
;
6087 /* Routines to manipulate hash table of CUs. */
6089 htab_cu_hash (const void *of
)
6091 const struct cu_hash_table_entry
*const entry
=
6092 (const struct cu_hash_table_entry
*) of
;
6094 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6098 htab_cu_eq (const void *of1
, const void *of2
)
6100 const struct cu_hash_table_entry
*const entry1
=
6101 (const struct cu_hash_table_entry
*) of1
;
6102 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
6104 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6108 htab_cu_del (void *what
)
6110 struct cu_hash_table_entry
*next
,
6111 *entry
= (struct cu_hash_table_entry
*) what
;
6121 /* Check whether we have already seen this CU and set up SYM_NUM
6124 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
6126 struct cu_hash_table_entry dummy
;
6127 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6129 dummy
.max_comdat_num
= 0;
6131 slot
= (struct cu_hash_table_entry
**)
6132 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6136 for (; entry
; last
= entry
, entry
= entry
->next
)
6138 if (same_die_p_wrap (cu
, entry
->cu
))
6144 *sym_num
= entry
->min_comdat_num
;
6148 entry
= XCNEW (struct cu_hash_table_entry
);
6150 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6151 entry
->next
= *slot
;
6157 /* Record SYM_NUM to record of CU in HTABLE. */
6159 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
6161 struct cu_hash_table_entry
**slot
, *entry
;
6163 slot
= (struct cu_hash_table_entry
**)
6164 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6168 entry
->max_comdat_num
= sym_num
;
6171 /* Traverse the DIE (which is always comp_unit_die), and set up
6172 additional compilation units for each of the include files we see
6173 bracketed by BINCL/EINCL. */
6176 break_out_includes (dw_die_ref die
)
6179 dw_die_ref unit
= NULL
;
6180 limbo_die_node
*node
, **pnode
;
6181 htab_t cu_hash_table
;
6185 dw_die_ref prev
= c
;
6187 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6188 || (unit
&& is_comdat_die (c
)))
6190 dw_die_ref next
= c
->die_sib
;
6192 /* This DIE is for a secondary CU; remove it from the main one. */
6193 remove_child_with_prev (c
, prev
);
6195 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6196 unit
= push_new_compile_unit (unit
, c
);
6197 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6198 unit
= pop_compile_unit (unit
);
6200 add_child_die (unit
, c
);
6202 if (c
== die
->die_child
)
6205 } while (c
!= die
->die_child
);
6208 /* We can only use this in debugging, since the frontend doesn't check
6209 to make sure that we leave every include file we enter. */
6213 assign_symbol_names (die
);
6214 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
6215 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6221 compute_section_prefix (node
->die
);
6222 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6223 &comdat_symbol_number
);
6224 assign_symbol_names (node
->die
);
6226 *pnode
= node
->next
;
6229 pnode
= &node
->next
;
6230 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6231 comdat_symbol_number
);
6234 htab_delete (cu_hash_table
);
6237 /* Return non-zero if this DIE is a declaration. */
6240 is_declaration_die (dw_die_ref die
)
6245 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6246 if (a
->dw_attr
== DW_AT_declaration
)
6252 /* Return non-zero if this DIE is nested inside a subprogram. */
6255 is_nested_in_subprogram (dw_die_ref die
)
6257 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6261 return local_scope_p (decl
);
6264 /* Return non-zero if this DIE contains a defining declaration of a
6268 contains_subprogram_definition (dw_die_ref die
)
6272 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6274 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition(c
)) return 1);
6278 /* Return non-zero if this is a type DIE that should be moved to a
6279 COMDAT .debug_types section. */
6282 should_move_die_to_comdat (dw_die_ref die
)
6284 switch (die
->die_tag
)
6286 case DW_TAG_class_type
:
6287 case DW_TAG_structure_type
:
6288 case DW_TAG_enumeration_type
:
6289 case DW_TAG_union_type
:
6290 /* Don't move declarations, inlined instances, or types nested in a
6292 if (is_declaration_die (die
)
6293 || get_AT (die
, DW_AT_abstract_origin
)
6294 || is_nested_in_subprogram (die
))
6296 /* A type definition should never contain a subprogram definition. */
6297 gcc_assert (!contains_subprogram_definition (die
));
6299 case DW_TAG_array_type
:
6300 case DW_TAG_interface_type
:
6301 case DW_TAG_pointer_type
:
6302 case DW_TAG_reference_type
:
6303 case DW_TAG_rvalue_reference_type
:
6304 case DW_TAG_string_type
:
6305 case DW_TAG_subroutine_type
:
6306 case DW_TAG_ptr_to_member_type
:
6307 case DW_TAG_set_type
:
6308 case DW_TAG_subrange_type
:
6309 case DW_TAG_base_type
:
6310 case DW_TAG_const_type
:
6311 case DW_TAG_file_type
:
6312 case DW_TAG_packed_type
:
6313 case DW_TAG_volatile_type
:
6314 case DW_TAG_typedef
:
6320 /* Make a clone of DIE. */
6323 clone_die (dw_die_ref die
)
6329 clone
= ggc_alloc_cleared_die_node ();
6330 clone
->die_tag
= die
->die_tag
;
6332 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6333 add_dwarf_attr (clone
, a
);
6338 /* Make a clone of the tree rooted at DIE. */
6341 clone_tree (dw_die_ref die
)
6344 dw_die_ref clone
= clone_die (die
);
6346 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree(c
)));
6351 /* Make a clone of DIE as a declaration. */
6354 clone_as_declaration (dw_die_ref die
)
6361 /* If the DIE is already a declaration, just clone it. */
6362 if (is_declaration_die (die
))
6363 return clone_die (die
);
6365 /* If the DIE is a specification, just clone its declaration DIE. */
6366 decl
= get_AT_ref (die
, DW_AT_specification
);
6369 clone
= clone_die (decl
);
6370 if (die
->comdat_type_p
)
6371 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6375 clone
= ggc_alloc_cleared_die_node ();
6376 clone
->die_tag
= die
->die_tag
;
6378 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6380 /* We don't want to copy over all attributes.
6381 For example we don't want DW_AT_byte_size because otherwise we will no
6382 longer have a declaration and GDB will treat it as a definition. */
6386 case DW_AT_artificial
:
6387 case DW_AT_containing_type
:
6388 case DW_AT_external
:
6391 case DW_AT_virtuality
:
6392 case DW_AT_linkage_name
:
6393 case DW_AT_MIPS_linkage_name
:
6394 add_dwarf_attr (clone
, a
);
6396 case DW_AT_byte_size
:
6402 if (die
->comdat_type_p
)
6403 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6405 add_AT_flag (clone
, DW_AT_declaration
, 1);
6409 /* Copy the declaration context to the new type unit DIE. This includes
6410 any surrounding namespace or type declarations. If the DIE has an
6411 AT_specification attribute, it also includes attributes and children
6412 attached to the specification, and returns a pointer to the original
6413 parent of the declaration DIE. Returns NULL otherwise. */
6416 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
6419 dw_die_ref new_decl
;
6420 dw_die_ref orig_parent
= NULL
;
6422 decl
= get_AT_ref (die
, DW_AT_specification
);
6431 /* The original DIE will be changed to a declaration, and must
6432 be moved to be a child of the original declaration DIE. */
6433 orig_parent
= decl
->die_parent
;
6435 /* Copy the type node pointer from the new DIE to the original
6436 declaration DIE so we can forward references later. */
6437 decl
->comdat_type_p
= true;
6438 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
6440 remove_AT (die
, DW_AT_specification
);
6442 FOR_EACH_VEC_ELT (dw_attr_node
, decl
->die_attr
, ix
, a
)
6444 if (a
->dw_attr
!= DW_AT_name
6445 && a
->dw_attr
!= DW_AT_declaration
6446 && a
->dw_attr
!= DW_AT_external
)
6447 add_dwarf_attr (die
, a
);
6450 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree(c
)));
6453 if (decl
->die_parent
!= NULL
6454 && !is_unit_die (decl
->die_parent
))
6456 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
6457 if (new_decl
!= NULL
)
6459 remove_AT (new_decl
, DW_AT_signature
);
6460 add_AT_specification (die
, new_decl
);
6467 /* Generate the skeleton ancestor tree for the given NODE, then clone
6468 the DIE and add the clone into the tree. */
6471 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
6473 if (node
->new_die
!= NULL
)
6476 node
->new_die
= clone_as_declaration (node
->old_die
);
6478 if (node
->parent
!= NULL
)
6480 generate_skeleton_ancestor_tree (node
->parent
);
6481 add_child_die (node
->parent
->new_die
, node
->new_die
);
6485 /* Generate a skeleton tree of DIEs containing any declarations that are
6486 found in the original tree. We traverse the tree looking for declaration
6487 DIEs, and construct the skeleton from the bottom up whenever we find one. */
6490 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
6492 skeleton_chain_node node
;
6495 dw_die_ref prev
= NULL
;
6496 dw_die_ref next
= NULL
;
6498 node
.parent
= parent
;
6500 first
= c
= parent
->old_die
->die_child
;
6504 if (prev
== NULL
|| prev
->die_sib
== c
)
6507 next
= (c
== first
? NULL
: c
->die_sib
);
6509 node
.new_die
= NULL
;
6510 if (is_declaration_die (c
))
6512 /* Clone the existing DIE, move the original to the skeleton
6513 tree (which is in the main CU), and put the clone, with
6514 all the original's children, where the original came from. */
6515 dw_die_ref clone
= clone_die (c
);
6516 move_all_children (c
, clone
);
6518 replace_child (c
, clone
, prev
);
6519 generate_skeleton_ancestor_tree (parent
);
6520 add_child_die (parent
->new_die
, c
);
6524 generate_skeleton_bottom_up (&node
);
6525 } while (next
!= NULL
);
6528 /* Wrapper function for generate_skeleton_bottom_up. */
6531 generate_skeleton (dw_die_ref die
)
6533 skeleton_chain_node node
;
6536 node
.new_die
= NULL
;
6539 /* If this type definition is nested inside another type,
6540 always leave at least a declaration in its place. */
6541 if (die
->die_parent
!= NULL
&& is_type_die (die
->die_parent
))
6542 node
.new_die
= clone_as_declaration (die
);
6544 generate_skeleton_bottom_up (&node
);
6545 return node
.new_die
;
6548 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
6549 declaration. The original DIE is moved to a new compile unit so that
6550 existing references to it follow it to the new location. If any of the
6551 original DIE's descendants is a declaration, we need to replace the
6552 original DIE with a skeleton tree and move the declarations back into the
6556 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
6559 dw_die_ref skeleton
, orig_parent
;
6561 /* Copy the declaration context to the type unit DIE. If the returned
6562 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
6564 orig_parent
= copy_declaration_context (unit
, child
);
6566 skeleton
= generate_skeleton (child
);
6567 if (skeleton
== NULL
)
6568 remove_child_with_prev (child
, prev
);
6571 skeleton
->comdat_type_p
= true;
6572 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
6574 /* If the original DIE was a specification, we need to put
6575 the skeleton under the parent DIE of the declaration.
6576 This leaves the original declaration in the tree, but
6577 it will be pruned later since there are no longer any
6578 references to it. */
6579 if (orig_parent
!= NULL
)
6581 remove_child_with_prev (child
, prev
);
6582 add_child_die (orig_parent
, skeleton
);
6585 replace_child (child
, skeleton
, prev
);
6591 /* Traverse the DIE and set up additional .debug_types sections for each
6592 type worthy of being placed in a COMDAT section. */
6595 break_out_comdat_types (dw_die_ref die
)
6599 dw_die_ref prev
= NULL
;
6600 dw_die_ref next
= NULL
;
6601 dw_die_ref unit
= NULL
;
6603 first
= c
= die
->die_child
;
6607 if (prev
== NULL
|| prev
->die_sib
== c
)
6610 next
= (c
== first
? NULL
: c
->die_sib
);
6611 if (should_move_die_to_comdat (c
))
6613 dw_die_ref replacement
;
6614 comdat_type_node_ref type_node
;
6616 /* Create a new type unit DIE as the root for the new tree, and
6617 add it to the list of comdat types. */
6618 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
6619 add_AT_unsigned (unit
, DW_AT_language
,
6620 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
6621 type_node
= ggc_alloc_cleared_comdat_type_node ();
6622 type_node
->root_die
= unit
;
6623 type_node
->next
= comdat_type_list
;
6624 comdat_type_list
= type_node
;
6626 /* Generate the type signature. */
6627 generate_type_signature (c
, type_node
);
6629 /* Copy the declaration context, attributes, and children of the
6630 declaration into the new type unit DIE, then remove this DIE
6631 from the main CU (or replace it with a skeleton if necessary). */
6632 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
6633 type_node
->skeleton_die
= replacement
;
6635 /* Break out nested types into their own type units. */
6636 break_out_comdat_types (c
);
6638 /* Add the DIE to the new compunit. */
6639 add_child_die (unit
, c
);
6641 if (replacement
!= NULL
)
6644 else if (c
->die_tag
== DW_TAG_namespace
6645 || c
->die_tag
== DW_TAG_class_type
6646 || c
->die_tag
== DW_TAG_structure_type
6647 || c
->die_tag
== DW_TAG_union_type
)
6649 /* Look for nested types that can be broken out. */
6650 break_out_comdat_types (c
);
6652 } while (next
!= NULL
);
6655 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
6657 struct decl_table_entry
6663 /* Routines to manipulate hash table of copied declarations. */
6666 htab_decl_hash (const void *of
)
6668 const struct decl_table_entry
*const entry
=
6669 (const struct decl_table_entry
*) of
;
6671 return htab_hash_pointer (entry
->orig
);
6675 htab_decl_eq (const void *of1
, const void *of2
)
6677 const struct decl_table_entry
*const entry1
=
6678 (const struct decl_table_entry
*) of1
;
6679 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
6681 return entry1
->orig
== entry2
;
6685 htab_decl_del (void *what
)
6687 struct decl_table_entry
*entry
= (struct decl_table_entry
*) what
;
6692 /* Copy DIE and its ancestors, up to, but not including, the compile unit
6693 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
6694 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
6695 to check if the ancestor has already been copied into UNIT. */
6698 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
6700 dw_die_ref parent
= die
->die_parent
;
6701 dw_die_ref new_parent
= unit
;
6704 struct decl_table_entry
*entry
= NULL
;
6708 /* Check if the entry has already been copied to UNIT. */
6709 slot
= htab_find_slot_with_hash (decl_table
, die
,
6710 htab_hash_pointer (die
), INSERT
);
6711 if (*slot
!= HTAB_EMPTY_ENTRY
)
6713 entry
= (struct decl_table_entry
*) *slot
;
6717 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
6718 entry
= XCNEW (struct decl_table_entry
);
6726 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
6729 if (!is_unit_die (parent
))
6730 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
6733 copy
= clone_as_declaration (die
);
6734 add_child_die (new_parent
, copy
);
6736 if (decl_table
!= NULL
)
6738 /* Record the pointer to the copy. */
6745 /* Like clone_tree, but additionally enter all the children into
6746 the hash table decl_table. */
6749 clone_tree_hash (dw_die_ref die
, htab_t decl_table
)
6752 dw_die_ref clone
= clone_die (die
);
6753 struct decl_table_entry
*entry
;
6754 void **slot
= htab_find_slot_with_hash (decl_table
, die
,
6755 htab_hash_pointer (die
), INSERT
);
6756 /* Assert that DIE isn't in the hash table yet. If it would be there
6757 before, the ancestors would be necessarily there as well, therefore
6758 clone_tree_hash wouldn't be called. */
6759 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
6760 entry
= XCNEW (struct decl_table_entry
);
6762 entry
->copy
= clone
;
6765 FOR_EACH_CHILD (die
, c
,
6766 add_child_die (clone
, clone_tree_hash (c
, decl_table
)));
6771 /* Walk the DIE and its children, looking for references to incomplete
6772 or trivial types that are unmarked (i.e., that are not in the current
6776 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
6782 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6784 if (AT_class (a
) == dw_val_class_die_ref
)
6786 dw_die_ref targ
= AT_ref (a
);
6788 struct decl_table_entry
*entry
;
6790 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
6793 slot
= htab_find_slot_with_hash (decl_table
, targ
,
6794 htab_hash_pointer (targ
), INSERT
);
6796 if (*slot
!= HTAB_EMPTY_ENTRY
)
6798 /* TARG has already been copied, so we just need to
6799 modify the reference to point to the copy. */
6800 entry
= (struct decl_table_entry
*) *slot
;
6801 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
6805 dw_die_ref parent
= unit
;
6806 dw_die_ref copy
= clone_die (targ
);
6808 /* Record in DECL_TABLE that TARG has been copied.
6809 Need to do this now, before the recursive call,
6810 because DECL_TABLE may be expanded and SLOT
6811 would no longer be a valid pointer. */
6812 entry
= XCNEW (struct decl_table_entry
);
6817 FOR_EACH_CHILD (targ
, c
,
6818 add_child_die (copy
,
6819 clone_tree_hash (c
, decl_table
)));
6821 /* Make sure the cloned tree is marked as part of the
6825 /* If TARG has surrounding context, copy its ancestor tree
6826 into the new type unit. */
6827 if (targ
->die_parent
!= NULL
6828 && !is_unit_die (targ
->die_parent
))
6829 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
6832 add_child_die (parent
, copy
);
6833 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
6835 /* Make sure the newly-copied DIE is walked. If it was
6836 installed in a previously-added context, it won't
6837 get visited otherwise. */
6840 /* Find the highest point of the newly-added tree,
6841 mark each node along the way, and walk from there. */
6842 parent
->die_mark
= 1;
6843 while (parent
->die_parent
6844 && parent
->die_parent
->die_mark
== 0)
6846 parent
= parent
->die_parent
;
6847 parent
->die_mark
= 1;
6849 copy_decls_walk (unit
, parent
, decl_table
);
6855 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
6858 /* Copy declarations for "unworthy" types into the new comdat section.
6859 Incomplete types, modified types, and certain other types aren't broken
6860 out into comdat sections of their own, so they don't have a signature,
6861 and we need to copy the declaration into the same section so that we
6862 don't have an external reference. */
6865 copy_decls_for_unworthy_types (dw_die_ref unit
)
6870 decl_table
= htab_create (10, htab_decl_hash
, htab_decl_eq
, htab_decl_del
);
6871 copy_decls_walk (unit
, unit
, decl_table
);
6872 htab_delete (decl_table
);
6876 /* Traverse the DIE and add a sibling attribute if it may have the
6877 effect of speeding up access to siblings. To save some space,
6878 avoid generating sibling attributes for DIE's without children. */
6881 add_sibling_attributes (dw_die_ref die
)
6885 if (! die
->die_child
)
6888 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
6889 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
6891 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
6894 /* Output all location lists for the DIE and its children. */
6897 output_location_lists (dw_die_ref die
)
6903 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6904 if (AT_class (a
) == dw_val_class_loc_list
)
6905 output_loc_list (AT_loc_list (a
));
6907 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
6910 /* We want to limit the number of external references, because they are
6911 larger than local references: a relocation takes multiple words, and
6912 even a sig8 reference is always eight bytes, whereas a local reference
6913 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
6914 So if we encounter multiple external references to the same type DIE, we
6915 make a local typedef stub for it and redirect all references there.
6917 This is the element of the hash table for keeping track of these
6927 /* Hash an external_ref. */
6930 hash_external_ref (const void *p
)
6932 const struct external_ref
*r
= (const struct external_ref
*)p
;
6933 return htab_hash_pointer (r
->type
);
6936 /* Compare external_refs. */
6939 external_ref_eq (const void *p1
, const void *p2
)
6941 const struct external_ref
*r1
= (const struct external_ref
*)p1
;
6942 const struct external_ref
*r2
= (const struct external_ref
*)p2
;
6943 return r1
->type
== r2
->type
;
6946 /* Return a pointer to the external_ref for references to DIE. */
6948 static struct external_ref
*
6949 lookup_external_ref (htab_t map
, dw_die_ref die
)
6951 struct external_ref ref
, *ref_p
;
6955 slot
= htab_find_slot (map
, &ref
, INSERT
);
6956 if (*slot
!= HTAB_EMPTY_ENTRY
)
6957 return (struct external_ref
*) *slot
;
6959 ref_p
= XCNEW (struct external_ref
);
6965 /* Subroutine of optimize_external_refs, below.
6967 If we see a type skeleton, record it as our stub. If we see external
6968 references, remember how many we've seen. */
6971 optimize_external_refs_1 (dw_die_ref die
, htab_t map
)
6976 struct external_ref
*ref_p
;
6978 if (is_type_die (die
)
6979 && (c
= get_AT_ref (die
, DW_AT_signature
)))
6981 /* This is a local skeleton; use it for local references. */
6982 ref_p
= lookup_external_ref (map
, c
);
6986 /* Scan the DIE references, and remember any that refer to DIEs from
6987 other CUs (i.e. those which are not marked). */
6988 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6989 if (AT_class (a
) == dw_val_class_die_ref
6990 && (c
= AT_ref (a
))->die_mark
== 0
6993 ref_p
= lookup_external_ref (map
, c
);
6997 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7000 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7001 points to an external_ref, DATA is the CU we're processing. If we don't
7002 already have a local stub, and we have multiple refs, build a stub. */
7005 build_local_stub (void **slot
, void *data
)
7007 struct external_ref
*ref_p
= (struct external_ref
*)*slot
;
7009 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7011 /* We have multiple references to this type, so build a small stub.
7012 Both of these forms are a bit dodgy from the perspective of the
7013 DWARF standard, since technically they should have names. */
7014 dw_die_ref cu
= (dw_die_ref
) data
;
7015 dw_die_ref type
= ref_p
->type
;
7016 dw_die_ref stub
= NULL
;
7018 if (type
->comdat_type_p
)
7020 /* If we refer to this type via sig8, use AT_signature. */
7021 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7022 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7026 /* Otherwise, use a typedef with no name. */
7027 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7028 add_AT_die_ref (stub
, DW_AT_type
, type
);
7037 /* DIE is a unit; look through all the DIE references to see if there are
7038 any external references to types, and if so, create local stubs for
7039 them which will be applied in build_abbrev_table. This is useful because
7040 references to local DIEs are smaller. */
7043 optimize_external_refs (dw_die_ref die
)
7045 htab_t map
= htab_create (10, hash_external_ref
, external_ref_eq
, free
);
7046 optimize_external_refs_1 (die
, map
);
7047 htab_traverse (map
, build_local_stub
, die
);
7051 /* The format of each DIE (and its attribute value pairs) is encoded in an
7052 abbreviation table. This routine builds the abbreviation table and assigns
7053 a unique abbreviation id for each abbreviation entry. The children of each
7054 die are visited recursively. */
7057 build_abbrev_table (dw_die_ref die
, htab_t extern_map
)
7059 unsigned long abbrev_id
;
7060 unsigned int n_alloc
;
7065 /* Scan the DIE references, and replace any that refer to
7066 DIEs from other CUs (i.e. those which are not marked) with
7067 the local stubs we built in optimize_external_refs. */
7068 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7069 if (AT_class (a
) == dw_val_class_die_ref
7070 && (c
= AT_ref (a
))->die_mark
== 0)
7072 struct external_ref
*ref_p
;
7073 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7075 ref_p
= lookup_external_ref (extern_map
, c
);
7076 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7077 change_AT_die_ref (a
, ref_p
->stub
);
7079 /* We aren't changing this reference, so mark it external. */
7080 set_AT_ref_external (a
, 1);
7083 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7085 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7086 dw_attr_ref die_a
, abbrev_a
;
7090 if (abbrev
->die_tag
!= die
->die_tag
)
7092 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7095 if (VEC_length (dw_attr_node
, abbrev
->die_attr
)
7096 != VEC_length (dw_attr_node
, die
->die_attr
))
7099 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, die_a
)
7101 abbrev_a
= &VEC_index (dw_attr_node
, abbrev
->die_attr
, ix
);
7102 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7103 || (value_format (abbrev_a
) != value_format (die_a
)))
7113 if (abbrev_id
>= abbrev_die_table_in_use
)
7115 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7117 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7118 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7121 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7122 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7123 abbrev_die_table_allocated
= n_alloc
;
7126 ++abbrev_die_table_in_use
;
7127 abbrev_die_table
[abbrev_id
] = die
;
7130 die
->die_abbrev
= abbrev_id
;
7131 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
7134 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7137 constant_size (unsigned HOST_WIDE_INT value
)
7144 log
= floor_log2 (value
);
7147 log
= 1 << (floor_log2 (log
) + 1);
7152 /* Return the size of a DIE as it is represented in the
7153 .debug_info section. */
7155 static unsigned long
7156 size_of_die (dw_die_ref die
)
7158 unsigned long size
= 0;
7162 size
+= size_of_uleb128 (die
->die_abbrev
);
7163 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7165 switch (AT_class (a
))
7167 case dw_val_class_addr
:
7168 size
+= DWARF2_ADDR_SIZE
;
7170 case dw_val_class_offset
:
7171 size
+= DWARF_OFFSET_SIZE
;
7173 case dw_val_class_loc
:
7175 unsigned long lsize
= size_of_locs (AT_loc (a
));
7178 if (dwarf_version
>= 4)
7179 size
+= size_of_uleb128 (lsize
);
7181 size
+= constant_size (lsize
);
7185 case dw_val_class_loc_list
:
7186 size
+= DWARF_OFFSET_SIZE
;
7188 case dw_val_class_range_list
:
7189 size
+= DWARF_OFFSET_SIZE
;
7191 case dw_val_class_const
:
7192 size
+= size_of_sleb128 (AT_int (a
));
7194 case dw_val_class_unsigned_const
:
7196 int csize
= constant_size (AT_unsigned (a
));
7197 if (dwarf_version
== 3
7198 && a
->dw_attr
== DW_AT_data_member_location
7200 size
+= size_of_uleb128 (AT_unsigned (a
));
7205 case dw_val_class_const_double
:
7206 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
7207 if (HOST_BITS_PER_WIDE_INT
>= 64)
7210 case dw_val_class_vec
:
7211 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7212 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7213 + a
->dw_attr_val
.v
.val_vec
.length
7214 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7216 case dw_val_class_flag
:
7217 if (dwarf_version
>= 4)
7218 /* Currently all add_AT_flag calls pass in 1 as last argument,
7219 so DW_FORM_flag_present can be used. If that ever changes,
7220 we'll need to use DW_FORM_flag and have some optimization
7221 in build_abbrev_table that will change those to
7222 DW_FORM_flag_present if it is set to 1 in all DIEs using
7223 the same abbrev entry. */
7224 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7228 case dw_val_class_die_ref
:
7229 if (AT_ref_external (a
))
7231 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7232 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7233 is sized by target address length, whereas in DWARF3
7234 it's always sized as an offset. */
7235 if (use_debug_types
)
7236 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7237 else if (dwarf_version
== 2)
7238 size
+= DWARF2_ADDR_SIZE
;
7240 size
+= DWARF_OFFSET_SIZE
;
7243 size
+= DWARF_OFFSET_SIZE
;
7245 case dw_val_class_fde_ref
:
7246 size
+= DWARF_OFFSET_SIZE
;
7248 case dw_val_class_lbl_id
:
7249 size
+= DWARF2_ADDR_SIZE
;
7251 case dw_val_class_lineptr
:
7252 case dw_val_class_macptr
:
7253 size
+= DWARF_OFFSET_SIZE
;
7255 case dw_val_class_str
:
7256 if (AT_string_form (a
) == DW_FORM_strp
)
7257 size
+= DWARF_OFFSET_SIZE
;
7259 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7261 case dw_val_class_file
:
7262 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7264 case dw_val_class_data8
:
7267 case dw_val_class_vms_delta
:
7268 size
+= DWARF_OFFSET_SIZE
;
7270 case dw_val_class_high_pc
:
7271 size
+= DWARF2_ADDR_SIZE
;
7281 /* Size the debugging information associated with a given DIE. Visits the
7282 DIE's children recursively. Updates the global variable next_die_offset, on
7283 each time through. Uses the current value of next_die_offset to update the
7284 die_offset field in each DIE. */
7287 calc_die_sizes (dw_die_ref die
)
7291 gcc_assert (die
->die_offset
== 0
7292 || (unsigned long int) die
->die_offset
== next_die_offset
);
7293 die
->die_offset
= next_die_offset
;
7294 next_die_offset
+= size_of_die (die
);
7296 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7298 if (die
->die_child
!= NULL
)
7299 /* Count the null byte used to terminate sibling lists. */
7300 next_die_offset
+= 1;
7303 /* Size just the base type children at the start of the CU.
7304 This is needed because build_abbrev needs to size locs
7305 and sizing of type based stack ops needs to know die_offset
7306 values for the base types. */
7309 calc_base_type_die_sizes (void)
7311 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7313 dw_die_ref base_type
;
7314 #if ENABLE_ASSERT_CHECKING
7315 dw_die_ref prev
= comp_unit_die ()->die_child
;
7318 die_offset
+= size_of_die (comp_unit_die ());
7319 for (i
= 0; VEC_iterate (dw_die_ref
, base_types
, i
, base_type
); i
++)
7321 #if ENABLE_ASSERT_CHECKING
7322 gcc_assert (base_type
->die_offset
== 0
7323 && prev
->die_sib
== base_type
7324 && base_type
->die_child
== NULL
7325 && base_type
->die_abbrev
);
7328 base_type
->die_offset
= die_offset
;
7329 die_offset
+= size_of_die (base_type
);
7333 /* Set the marks for a die and its children. We do this so
7334 that we know whether or not a reference needs to use FORM_ref_addr; only
7335 DIEs in the same CU will be marked. We used to clear out the offset
7336 and use that as the flag, but ran into ordering problems. */
7339 mark_dies (dw_die_ref die
)
7343 gcc_assert (!die
->die_mark
);
7346 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7349 /* Clear the marks for a die and its children. */
7352 unmark_dies (dw_die_ref die
)
7356 if (! use_debug_types
)
7357 gcc_assert (die
->die_mark
);
7360 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7363 /* Clear the marks for a die, its children and referred dies. */
7366 unmark_all_dies (dw_die_ref die
)
7376 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7378 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7379 if (AT_class (a
) == dw_val_class_die_ref
)
7380 unmark_all_dies (AT_ref (a
));
7383 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7384 generated for the compilation unit. */
7386 static unsigned long
7387 size_of_pubnames (VEC (pubname_entry
, gc
) * names
)
7393 size
= DWARF_PUBNAMES_HEADER_SIZE
;
7394 FOR_EACH_VEC_ELT (pubname_entry
, names
, i
, p
)
7395 if (names
!= pubtype_table
7396 || p
->die
->die_offset
!= 0
7397 || !flag_eliminate_unused_debug_types
)
7398 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
7400 size
+= DWARF_OFFSET_SIZE
;
7404 /* Return the size of the information in the .debug_aranges section. */
7406 static unsigned long
7407 size_of_aranges (void)
7411 size
= DWARF_ARANGES_HEADER_SIZE
;
7413 /* Count the address/length pair for this compilation unit. */
7414 if (text_section_used
)
7415 size
+= 2 * DWARF2_ADDR_SIZE
;
7416 if (cold_text_section_used
)
7417 size
+= 2 * DWARF2_ADDR_SIZE
;
7418 if (have_multiple_function_sections
)
7423 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, fde_idx
, fde
)
7425 if (!fde
->in_std_section
)
7426 size
+= 2 * DWARF2_ADDR_SIZE
;
7427 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
7428 size
+= 2 * DWARF2_ADDR_SIZE
;
7432 /* Count the two zero words used to terminated the address range table. */
7433 size
+= 2 * DWARF2_ADDR_SIZE
;
7437 /* Select the encoding of an attribute value. */
7439 static enum dwarf_form
7440 value_format (dw_attr_ref a
)
7442 switch (a
->dw_attr_val
.val_class
)
7444 case dw_val_class_addr
:
7445 /* Only very few attributes allow DW_FORM_addr. */
7450 case DW_AT_entry_pc
:
7451 case DW_AT_trampoline
:
7452 return DW_FORM_addr
;
7456 switch (DWARF2_ADDR_SIZE
)
7459 return DW_FORM_data1
;
7461 return DW_FORM_data2
;
7463 return DW_FORM_data4
;
7465 return DW_FORM_data8
;
7469 case dw_val_class_range_list
:
7470 case dw_val_class_loc_list
:
7471 if (dwarf_version
>= 4)
7472 return DW_FORM_sec_offset
;
7474 case dw_val_class_vms_delta
:
7475 case dw_val_class_offset
:
7476 switch (DWARF_OFFSET_SIZE
)
7479 return DW_FORM_data4
;
7481 return DW_FORM_data8
;
7485 case dw_val_class_loc
:
7486 if (dwarf_version
>= 4)
7487 return DW_FORM_exprloc
;
7488 switch (constant_size (size_of_locs (AT_loc (a
))))
7491 return DW_FORM_block1
;
7493 return DW_FORM_block2
;
7495 return DW_FORM_block4
;
7499 case dw_val_class_const
:
7500 return DW_FORM_sdata
;
7501 case dw_val_class_unsigned_const
:
7502 switch (constant_size (AT_unsigned (a
)))
7505 return DW_FORM_data1
;
7507 return DW_FORM_data2
;
7509 /* In DWARF3 DW_AT_data_member_location with
7510 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
7511 constant, so we need to use DW_FORM_udata if we need
7512 a large constant. */
7513 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
7514 return DW_FORM_udata
;
7515 return DW_FORM_data4
;
7517 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
7518 return DW_FORM_udata
;
7519 return DW_FORM_data8
;
7523 case dw_val_class_const_double
:
7524 switch (HOST_BITS_PER_WIDE_INT
)
7527 return DW_FORM_data2
;
7529 return DW_FORM_data4
;
7531 return DW_FORM_data8
;
7534 return DW_FORM_block1
;
7536 case dw_val_class_vec
:
7537 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
7538 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
7541 return DW_FORM_block1
;
7543 return DW_FORM_block2
;
7545 return DW_FORM_block4
;
7549 case dw_val_class_flag
:
7550 if (dwarf_version
>= 4)
7552 /* Currently all add_AT_flag calls pass in 1 as last argument,
7553 so DW_FORM_flag_present can be used. If that ever changes,
7554 we'll need to use DW_FORM_flag and have some optimization
7555 in build_abbrev_table that will change those to
7556 DW_FORM_flag_present if it is set to 1 in all DIEs using
7557 the same abbrev entry. */
7558 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7559 return DW_FORM_flag_present
;
7561 return DW_FORM_flag
;
7562 case dw_val_class_die_ref
:
7563 if (AT_ref_external (a
))
7564 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
7567 case dw_val_class_fde_ref
:
7568 return DW_FORM_data
;
7569 case dw_val_class_lbl_id
:
7570 return DW_FORM_addr
;
7571 case dw_val_class_lineptr
:
7572 case dw_val_class_macptr
:
7573 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
7574 case dw_val_class_str
:
7575 return AT_string_form (a
);
7576 case dw_val_class_file
:
7577 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
7580 return DW_FORM_data1
;
7582 return DW_FORM_data2
;
7584 return DW_FORM_data4
;
7589 case dw_val_class_data8
:
7590 return DW_FORM_data8
;
7592 case dw_val_class_high_pc
:
7593 switch (DWARF2_ADDR_SIZE
)
7596 return DW_FORM_data4
;
7598 return DW_FORM_data8
;
7608 /* Output the encoding of an attribute value. */
7611 output_value_format (dw_attr_ref a
)
7613 enum dwarf_form form
= value_format (a
);
7615 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
7618 /* Output the .debug_abbrev section which defines the DIE abbreviation
7622 output_abbrev_section (void)
7624 unsigned long abbrev_id
;
7626 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7628 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7632 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
7633 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
7634 dwarf_tag_name (abbrev
->die_tag
));
7636 if (abbrev
->die_child
!= NULL
)
7637 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
7639 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
7641 for (ix
= 0; VEC_iterate (dw_attr_node
, abbrev
->die_attr
, ix
, a_attr
);
7644 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
7645 dwarf_attr_name (a_attr
->dw_attr
));
7646 output_value_format (a_attr
);
7649 dw2_asm_output_data (1, 0, NULL
);
7650 dw2_asm_output_data (1, 0, NULL
);
7653 /* Terminate the table. */
7654 dw2_asm_output_data (1, 0, NULL
);
7657 /* Output a symbol we can use to refer to this DIE from another CU. */
7660 output_die_symbol (dw_die_ref die
)
7662 const char *sym
= die
->die_id
.die_symbol
;
7664 gcc_assert (!die
->comdat_type_p
);
7669 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
7670 /* We make these global, not weak; if the target doesn't support
7671 .linkonce, it doesn't support combining the sections, so debugging
7673 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
7675 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
7678 /* Return a new location list, given the begin and end range, and the
7681 static inline dw_loc_list_ref
7682 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
7683 const char *section
)
7685 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
7687 retlist
->begin
= begin
;
7689 retlist
->expr
= expr
;
7690 retlist
->section
= section
;
7695 /* Generate a new internal symbol for this location list node, if it
7696 hasn't got one yet. */
7699 gen_llsym (dw_loc_list_ref list
)
7701 gcc_assert (!list
->ll_symbol
);
7702 list
->ll_symbol
= gen_internal_sym ("LLST");
7705 /* Output the location list given to us. */
7708 output_loc_list (dw_loc_list_ref list_head
)
7710 dw_loc_list_ref curr
= list_head
;
7712 if (list_head
->emitted
)
7714 list_head
->emitted
= true;
7716 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
7718 /* Walk the location list, and output each range + expression. */
7719 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
7722 /* Don't output an entry that starts and ends at the same address. */
7723 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
7725 size
= size_of_locs (curr
->expr
);
7726 /* If the expression is too large, drop it on the floor. We could
7727 perhaps put it into DW_TAG_dwarf_procedure and refer to that
7728 in the expression, but >= 64KB expressions for a single value
7729 in a single range are unlikely very useful. */
7732 if (!have_multiple_function_sections
)
7734 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
7735 "Location list begin address (%s)",
7736 list_head
->ll_symbol
);
7737 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
7738 "Location list end address (%s)",
7739 list_head
->ll_symbol
);
7743 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
7744 "Location list begin address (%s)",
7745 list_head
->ll_symbol
);
7746 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
7747 "Location list end address (%s)",
7748 list_head
->ll_symbol
);
7751 /* Output the block length for this list of location operations. */
7752 gcc_assert (size
<= 0xffff);
7753 dw2_asm_output_data (2, size
, "%s", "Location expression size");
7755 output_loc_sequence (curr
->expr
, -1);
7758 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
7759 "Location list terminator begin (%s)",
7760 list_head
->ll_symbol
);
7761 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
7762 "Location list terminator end (%s)",
7763 list_head
->ll_symbol
);
7766 /* Output a type signature. */
7769 output_signature (const char *sig
, const char *name
)
7773 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
7774 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
7777 /* Output the DIE and its attributes. Called recursively to generate
7778 the definitions of each child DIE. */
7781 output_die (dw_die_ref die
)
7788 /* If someone in another CU might refer to us, set up a symbol for
7789 them to point to. */
7790 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
7791 output_die_symbol (die
);
7793 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
7794 (unsigned long)die
->die_offset
,
7795 dwarf_tag_name (die
->die_tag
));
7797 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7799 const char *name
= dwarf_attr_name (a
->dw_attr
);
7801 switch (AT_class (a
))
7803 case dw_val_class_addr
:
7804 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
7807 case dw_val_class_offset
:
7808 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
7812 case dw_val_class_range_list
:
7814 char *p
= strchr (ranges_section_label
, '\0');
7816 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
7817 a
->dw_attr_val
.v
.val_offset
);
7818 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
7819 debug_ranges_section
, "%s", name
);
7824 case dw_val_class_loc
:
7825 size
= size_of_locs (AT_loc (a
));
7827 /* Output the block length for this list of location operations. */
7828 if (dwarf_version
>= 4)
7829 dw2_asm_output_data_uleb128 (size
, "%s", name
);
7831 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
7833 output_loc_sequence (AT_loc (a
), -1);
7836 case dw_val_class_const
:
7837 /* ??? It would be slightly more efficient to use a scheme like is
7838 used for unsigned constants below, but gdb 4.x does not sign
7839 extend. Gdb 5.x does sign extend. */
7840 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
7843 case dw_val_class_unsigned_const
:
7845 int csize
= constant_size (AT_unsigned (a
));
7846 if (dwarf_version
== 3
7847 && a
->dw_attr
== DW_AT_data_member_location
7849 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
7851 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
7855 case dw_val_class_const_double
:
7857 unsigned HOST_WIDE_INT first
, second
;
7859 if (HOST_BITS_PER_WIDE_INT
>= 64)
7860 dw2_asm_output_data (1,
7861 HOST_BITS_PER_DOUBLE_INT
7862 / HOST_BITS_PER_CHAR
,
7865 if (WORDS_BIG_ENDIAN
)
7867 first
= a
->dw_attr_val
.v
.val_double
.high
;
7868 second
= a
->dw_attr_val
.v
.val_double
.low
;
7872 first
= a
->dw_attr_val
.v
.val_double
.low
;
7873 second
= a
->dw_attr_val
.v
.val_double
.high
;
7876 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
7878 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
7883 case dw_val_class_vec
:
7885 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
7886 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
7890 dw2_asm_output_data (constant_size (len
* elt_size
),
7891 len
* elt_size
, "%s", name
);
7892 if (elt_size
> sizeof (HOST_WIDE_INT
))
7897 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
7900 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
7901 "fp or vector constant word %u", i
);
7905 case dw_val_class_flag
:
7906 if (dwarf_version
>= 4)
7908 /* Currently all add_AT_flag calls pass in 1 as last argument,
7909 so DW_FORM_flag_present can be used. If that ever changes,
7910 we'll need to use DW_FORM_flag and have some optimization
7911 in build_abbrev_table that will change those to
7912 DW_FORM_flag_present if it is set to 1 in all DIEs using
7913 the same abbrev entry. */
7914 gcc_assert (AT_flag (a
) == 1);
7916 fprintf (asm_out_file
, "\t\t\t%s %s\n",
7917 ASM_COMMENT_START
, name
);
7920 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
7923 case dw_val_class_loc_list
:
7925 char *sym
= AT_loc_list (a
)->ll_symbol
;
7928 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
7933 case dw_val_class_die_ref
:
7934 if (AT_ref_external (a
))
7936 if (AT_ref (a
)->comdat_type_p
)
7938 comdat_type_node_ref type_node
=
7939 AT_ref (a
)->die_id
.die_type_node
;
7941 gcc_assert (type_node
);
7942 output_signature (type_node
->signature
, name
);
7946 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
7950 /* In DWARF2, DW_FORM_ref_addr is sized by target address
7951 length, whereas in DWARF3 it's always sized as an
7953 if (dwarf_version
== 2)
7954 size
= DWARF2_ADDR_SIZE
;
7956 size
= DWARF_OFFSET_SIZE
;
7957 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
7963 gcc_assert (AT_ref (a
)->die_offset
);
7964 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
7969 case dw_val_class_fde_ref
:
7973 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
7974 a
->dw_attr_val
.v
.val_fde_index
* 2);
7975 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
7980 case dw_val_class_vms_delta
:
7981 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
7982 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
7986 case dw_val_class_lbl_id
:
7987 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
7990 case dw_val_class_lineptr
:
7991 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
7992 debug_line_section
, "%s", name
);
7995 case dw_val_class_macptr
:
7996 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
7997 debug_macinfo_section
, "%s", name
);
8000 case dw_val_class_str
:
8001 if (AT_string_form (a
) == DW_FORM_strp
)
8002 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8003 a
->dw_attr_val
.v
.val_str
->label
,
8005 "%s: \"%s\"", name
, AT_string (a
));
8007 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8010 case dw_val_class_file
:
8012 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8014 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8015 a
->dw_attr_val
.v
.val_file
->filename
);
8019 case dw_val_class_data8
:
8023 for (i
= 0; i
< 8; i
++)
8024 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8025 i
== 0 ? "%s" : NULL
, name
);
8029 case dw_val_class_high_pc
:
8030 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
8031 get_AT_low_pc (die
), "DW_AT_high_pc");
8039 FOR_EACH_CHILD (die
, c
, output_die (c
));
8041 /* Add null byte to terminate sibling list. */
8042 if (die
->die_child
!= NULL
)
8043 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8044 (unsigned long) die
->die_offset
);
8047 /* Output the compilation unit that appears at the beginning of the
8048 .debug_info section, and precedes the DIE descriptions. */
8051 output_compilation_unit_header (void)
8053 int ver
= dwarf_version
;
8055 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8056 dw2_asm_output_data (4, 0xffffffff,
8057 "Initial length escape value indicating 64-bit DWARF extension");
8058 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8059 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8060 "Length of Compilation Unit Info");
8061 dw2_asm_output_data (2, ver
, "DWARF version number");
8062 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8063 debug_abbrev_section
,
8064 "Offset Into Abbrev. Section");
8065 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8068 /* Output the compilation unit DIE and its children. */
8071 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8073 const char *secname
, *oldsym
;
8077 /* Unless we are outputting main CU, we may throw away empty ones. */
8078 if (!output_if_empty
&& die
->die_child
== NULL
)
8081 /* Even if there are no children of this DIE, we must output the information
8082 about the compilation unit. Otherwise, on an empty translation unit, we
8083 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8084 will then complain when examining the file. First mark all the DIEs in
8085 this CU so we know which get local refs. */
8088 extern_map
= optimize_external_refs (die
);
8090 build_abbrev_table (die
, extern_map
);
8092 htab_delete (extern_map
);
8094 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8095 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8096 calc_die_sizes (die
);
8098 oldsym
= die
->die_id
.die_symbol
;
8101 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8103 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8105 die
->die_id
.die_symbol
= NULL
;
8106 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8110 switch_to_section (debug_info_section
);
8111 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8112 info_section_emitted
= true;
8115 /* Output debugging information. */
8116 output_compilation_unit_header ();
8119 /* Leave the marks on the main CU, so we can check them in
8124 die
->die_id
.die_symbol
= oldsym
;
8128 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
8129 and .debug_pubtypes. This is configured per-target, but can be
8130 overridden by the -gpubnames or -gno-pubnames options. */
8133 want_pubnames (void)
8135 return (debug_generate_pub_sections
!= -1
8136 ? debug_generate_pub_sections
8137 : targetm
.want_debug_pub_sections
);
8140 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
8143 add_AT_pubnames (dw_die_ref die
)
8145 if (want_pubnames ())
8146 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
8149 /* Output a comdat type unit DIE and its children. */
8152 output_comdat_type_unit (comdat_type_node
*node
)
8154 const char *secname
;
8157 #if defined (OBJECT_FORMAT_ELF)
8162 /* First mark all the DIEs in this CU so we know which get local refs. */
8163 mark_dies (node
->root_die
);
8165 extern_map
= optimize_external_refs (node
->root_die
);
8167 build_abbrev_table (node
->root_die
, extern_map
);
8169 htab_delete (extern_map
);
8171 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8172 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
8173 calc_die_sizes (node
->root_die
);
8175 #if defined (OBJECT_FORMAT_ELF)
8176 secname
= ".debug_types";
8177 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8178 sprintf (tmp
, "wt.");
8179 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8180 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8181 comdat_key
= get_identifier (tmp
);
8182 targetm
.asm_out
.named_section (secname
,
8183 SECTION_DEBUG
| SECTION_LINKONCE
,
8186 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8187 sprintf (tmp
, ".gnu.linkonce.wt.");
8188 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8189 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8191 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8194 /* Output debugging information. */
8195 output_compilation_unit_header ();
8196 output_signature (node
->signature
, "Type Signature");
8197 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
8198 "Offset to Type DIE");
8199 output_die (node
->root_die
);
8201 unmark_dies (node
->root_die
);
8204 /* Return the DWARF2/3 pubname associated with a decl. */
8207 dwarf2_name (tree decl
, int scope
)
8209 if (DECL_NAMELESS (decl
))
8211 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
8214 /* Add a new entry to .debug_pubnames if appropriate. */
8217 add_pubname_string (const char *str
, dw_die_ref die
)
8222 e
.name
= xstrdup (str
);
8223 VEC_safe_push (pubname_entry
, gc
, pubname_table
, e
);
8227 add_pubname (tree decl
, dw_die_ref die
)
8229 if (!want_pubnames ())
8232 /* Don't add items to the table when we expect that the consumer will have
8233 just read the enclosing die. For example, if the consumer is looking at a
8234 class_member, it will either be inside the class already, or will have just
8235 looked up the class to find the member. Either way, searching the class is
8236 faster than searching the index. */
8237 if ((TREE_PUBLIC (decl
) && !is_class_die (die
->die_parent
))
8238 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
8240 const char *name
= dwarf2_name (decl
, 1);
8243 add_pubname_string (name
, die
);
8247 /* Add an enumerator to the pubnames section. */
8250 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
8254 gcc_assert (scope_name
);
8255 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
8257 VEC_safe_push (pubname_entry
, gc
, pubname_table
, e
);
8260 /* Add a new entry to .debug_pubtypes if appropriate. */
8263 add_pubtype (tree decl
, dw_die_ref die
)
8267 if (!want_pubnames ())
8270 if ((TREE_PUBLIC (decl
)
8271 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
8272 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
8275 const char *scope_name
= "";
8276 const char *sep
= is_cxx () ? "::" : ".";
8279 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
8280 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
8282 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
8283 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
8284 scope_name
= concat (scope_name
, sep
, NULL
);
8290 name
= type_tag (decl
);
8292 name
= lang_hooks
.dwarf_name (decl
, 1);
8294 /* If we don't have a name for the type, there's no point in adding
8296 if (name
!= NULL
&& name
[0] != '\0')
8299 e
.name
= concat (scope_name
, name
, NULL
);
8300 VEC_safe_push (pubname_entry
, gc
, pubtype_table
, e
);
8303 /* Although it might be more consistent to add the pubinfo for the
8304 enumerators as their dies are created, they should only be added if the
8305 enum type meets the criteria above. So rather than re-check the parent
8306 enum type whenever an enumerator die is created, just output them all
8307 here. This isn't protected by the name conditional because anonymous
8308 enums don't have names. */
8309 if (die
->die_tag
== DW_TAG_enumeration_type
)
8313 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
8318 /* Output the public names table used to speed up access to externally
8319 visible names; or the public types table used to find type definitions. */
8322 output_pubnames (VEC (pubname_entry
, gc
) * names
)
8325 unsigned long pubnames_length
= size_of_pubnames (names
);
8328 if (!want_pubnames () || !info_section_emitted
)
8330 if (names
== pubname_table
)
8331 switch_to_section (debug_pubnames_section
);
8333 switch_to_section (debug_pubtypes_section
);
8334 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8335 dw2_asm_output_data (4, 0xffffffff,
8336 "Initial length escape value indicating 64-bit DWARF extension");
8337 if (names
== pubname_table
)
8338 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8339 "Length of Public Names Info");
8341 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8342 "Length of Public Type Names Info");
8343 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
8344 dw2_asm_output_data (2, 2, "DWARF Version");
8345 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
8347 "Offset of Compilation Unit Info");
8348 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
8349 "Compilation Unit Length");
8351 FOR_EACH_VEC_ELT (pubname_entry
, names
, i
, pub
)
8353 /* Enumerator names are part of the pubname table, but the parent
8354 DW_TAG_enumeration_type die may have been pruned. Don't output
8355 them if that is the case. */
8356 if (pub
->die
->die_tag
== DW_TAG_enumerator
&& !pub
->die
->die_mark
)
8359 /* We shouldn't see pubnames for DIEs outside of the main CU. */
8360 if (names
== pubname_table
)
8361 gcc_assert (pub
->die
->die_mark
);
8363 if (names
!= pubtype_table
8364 || pub
->die
->die_offset
!= 0
8365 || !flag_eliminate_unused_debug_types
)
8367 dw_offset die_offset
= pub
->die
->die_offset
;
8369 /* If we're putting types in their own .debug_types sections,
8370 the .debug_pubtypes table will still point to the compile
8371 unit (not the type unit), so we want to use the offset of
8372 the skeleton DIE (if there is one). */
8373 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
8375 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
8377 if (type_node
!= NULL
)
8378 die_offset
= (type_node
->skeleton_die
!= NULL
8379 ? type_node
->skeleton_die
->die_offset
8383 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
8385 dw2_asm_output_nstring (pub
->name
, -1, "external name");
8389 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
8392 /* Output the information that goes into the .debug_aranges table.
8393 Namely, define the beginning and ending address range of the
8394 text section generated for this compilation unit. */
8397 output_aranges (unsigned long aranges_length
)
8401 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8402 dw2_asm_output_data (4, 0xffffffff,
8403 "Initial length escape value indicating 64-bit DWARF extension");
8404 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
8405 "Length of Address Ranges Info");
8406 /* Version number for aranges is still 2, even in DWARF3. */
8407 dw2_asm_output_data (2, 2, "DWARF Version");
8408 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
8410 "Offset of Compilation Unit Info");
8411 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
8412 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8414 /* We need to align to twice the pointer size here. */
8415 if (DWARF_ARANGES_PAD_SIZE
)
8417 /* Pad using a 2 byte words so that padding is correct for any
8419 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8420 2 * DWARF2_ADDR_SIZE
);
8421 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
8422 dw2_asm_output_data (2, 0, NULL
);
8425 /* It is necessary not to output these entries if the sections were
8426 not used; if the sections were not used, the length will be 0 and
8427 the address may end up as 0 if the section is discarded by ld
8428 --gc-sections, leaving an invalid (0, 0) entry that can be
8429 confused with the terminator. */
8430 if (text_section_used
)
8432 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
8433 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
8434 text_section_label
, "Length");
8436 if (cold_text_section_used
)
8438 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
8440 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
8441 cold_text_section_label
, "Length");
8444 if (have_multiple_function_sections
)
8449 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, fde_idx
, fde
)
8451 if (DECL_IGNORED_P (fde
->decl
))
8453 if (!fde
->in_std_section
)
8455 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
8457 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
8458 fde
->dw_fde_begin
, "Length");
8460 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8462 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
8464 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
8465 fde
->dw_fde_second_begin
, "Length");
8470 /* Output the terminator words. */
8471 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8472 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8475 /* Add a new entry to .debug_ranges. Return the offset at which it
8479 add_ranges_num (int num
)
8481 unsigned int in_use
= ranges_table_in_use
;
8483 if (in_use
== ranges_table_allocated
)
8485 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
8486 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
8487 ranges_table_allocated
);
8488 memset (ranges_table
+ ranges_table_in_use
, 0,
8489 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
8492 ranges_table
[in_use
].num
= num
;
8493 ranges_table_in_use
= in_use
+ 1;
8495 return in_use
* 2 * DWARF2_ADDR_SIZE
;
8498 /* Add a new entry to .debug_ranges corresponding to a block, or a
8499 range terminator if BLOCK is NULL. */
8502 add_ranges (const_tree block
)
8504 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
8507 /* Add a new entry to .debug_ranges corresponding to a pair of
8511 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
8514 unsigned int in_use
= ranges_by_label_in_use
;
8515 unsigned int offset
;
8517 if (in_use
== ranges_by_label_allocated
)
8519 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
8520 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
8522 ranges_by_label_allocated
);
8523 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
8524 RANGES_TABLE_INCREMENT
8525 * sizeof (struct dw_ranges_by_label_struct
));
8528 ranges_by_label
[in_use
].begin
= begin
;
8529 ranges_by_label
[in_use
].end
= end
;
8530 ranges_by_label_in_use
= in_use
+ 1;
8532 offset
= add_ranges_num (-(int)in_use
- 1);
8535 add_AT_range_list (die
, DW_AT_ranges
, offset
);
8541 output_ranges (void)
8544 static const char *const start_fmt
= "Offset %#x";
8545 const char *fmt
= start_fmt
;
8547 for (i
= 0; i
< ranges_table_in_use
; i
++)
8549 int block_num
= ranges_table
[i
].num
;
8553 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
8554 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
8556 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
8557 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
8559 /* If all code is in the text section, then the compilation
8560 unit base address defaults to DW_AT_low_pc, which is the
8561 base of the text section. */
8562 if (!have_multiple_function_sections
)
8564 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
8566 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8567 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
8568 text_section_label
, NULL
);
8571 /* Otherwise, the compilation unit base address is zero,
8572 which allows us to use absolute addresses, and not worry
8573 about whether the target supports cross-section
8577 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
8578 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8579 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
8585 /* Negative block_num stands for an index into ranges_by_label. */
8586 else if (block_num
< 0)
8588 int lab_idx
= - block_num
- 1;
8590 if (!have_multiple_function_sections
)
8594 /* If we ever use add_ranges_by_labels () for a single
8595 function section, all we have to do is to take out
8597 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
8598 ranges_by_label
[lab_idx
].begin
,
8600 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8601 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
8602 ranges_by_label
[lab_idx
].end
,
8603 text_section_label
, NULL
);
8608 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
8609 ranges_by_label
[lab_idx
].begin
,
8610 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8611 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
8612 ranges_by_label
[lab_idx
].end
,
8618 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8619 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8625 /* Data structure containing information about input files. */
8628 const char *path
; /* Complete file name. */
8629 const char *fname
; /* File name part. */
8630 int length
; /* Length of entire string. */
8631 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
8632 int dir_idx
; /* Index in directory table. */
8635 /* Data structure containing information about directories with source
8639 const char *path
; /* Path including directory name. */
8640 int length
; /* Path length. */
8641 int prefix
; /* Index of directory entry which is a prefix. */
8642 int count
; /* Number of files in this directory. */
8643 int dir_idx
; /* Index of directory used as base. */
8646 /* Callback function for file_info comparison. We sort by looking at
8647 the directories in the path. */
8650 file_info_cmp (const void *p1
, const void *p2
)
8652 const struct file_info
*const s1
= (const struct file_info
*) p1
;
8653 const struct file_info
*const s2
= (const struct file_info
*) p2
;
8654 const unsigned char *cp1
;
8655 const unsigned char *cp2
;
8657 /* Take care of file names without directories. We need to make sure that
8658 we return consistent values to qsort since some will get confused if
8659 we return the same value when identical operands are passed in opposite
8660 orders. So if neither has a directory, return 0 and otherwise return
8661 1 or -1 depending on which one has the directory. */
8662 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
8663 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
8665 cp1
= (const unsigned char *) s1
->path
;
8666 cp2
= (const unsigned char *) s2
->path
;
8672 /* Reached the end of the first path? If so, handle like above. */
8673 if ((cp1
== (const unsigned char *) s1
->fname
)
8674 || (cp2
== (const unsigned char *) s2
->fname
))
8675 return ((cp2
== (const unsigned char *) s2
->fname
)
8676 - (cp1
== (const unsigned char *) s1
->fname
));
8678 /* Character of current path component the same? */
8679 else if (*cp1
!= *cp2
)
8684 struct file_name_acquire_data
8686 struct file_info
*files
;
8691 /* Traversal function for the hash table. */
8694 file_name_acquire (void ** slot
, void *data
)
8696 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
8697 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
8698 struct file_info
*fi
;
8701 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
8703 if (! d
->emitted_number
)
8706 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
8708 fi
= fnad
->files
+ fnad
->used_files
++;
8710 /* Skip all leading "./". */
8712 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
8715 /* Create a new array entry. */
8717 fi
->length
= strlen (f
);
8720 /* Search for the file name part. */
8721 f
= strrchr (f
, DIR_SEPARATOR
);
8722 #if defined (DIR_SEPARATOR_2)
8724 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
8728 if (f
== NULL
|| f
< g
)
8734 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
8738 /* Output the directory table and the file name table. We try to minimize
8739 the total amount of memory needed. A heuristic is used to avoid large
8740 slowdowns with many input files. */
8743 output_file_names (void)
8745 struct file_name_acquire_data fnad
;
8747 struct file_info
*files
;
8748 struct dir_info
*dirs
;
8756 if (!last_emitted_file
)
8758 dw2_asm_output_data (1, 0, "End directory table");
8759 dw2_asm_output_data (1, 0, "End file name table");
8763 numfiles
= last_emitted_file
->emitted_number
;
8765 /* Allocate the various arrays we need. */
8766 files
= XALLOCAVEC (struct file_info
, numfiles
);
8767 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
8770 fnad
.used_files
= 0;
8771 fnad
.max_files
= numfiles
;
8772 htab_traverse (file_table
, file_name_acquire
, &fnad
);
8773 gcc_assert (fnad
.used_files
== fnad
.max_files
);
8775 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
8777 /* Find all the different directories used. */
8778 dirs
[0].path
= files
[0].path
;
8779 dirs
[0].length
= files
[0].fname
- files
[0].path
;
8780 dirs
[0].prefix
= -1;
8782 dirs
[0].dir_idx
= 0;
8783 files
[0].dir_idx
= 0;
8786 for (i
= 1; i
< numfiles
; i
++)
8787 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
8788 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
8789 dirs
[ndirs
- 1].length
) == 0)
8791 /* Same directory as last entry. */
8792 files
[i
].dir_idx
= ndirs
- 1;
8793 ++dirs
[ndirs
- 1].count
;
8799 /* This is a new directory. */
8800 dirs
[ndirs
].path
= files
[i
].path
;
8801 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
8802 dirs
[ndirs
].count
= 1;
8803 dirs
[ndirs
].dir_idx
= ndirs
;
8804 files
[i
].dir_idx
= ndirs
;
8806 /* Search for a prefix. */
8807 dirs
[ndirs
].prefix
= -1;
8808 for (j
= 0; j
< ndirs
; j
++)
8809 if (dirs
[j
].length
< dirs
[ndirs
].length
8810 && dirs
[j
].length
> 1
8811 && (dirs
[ndirs
].prefix
== -1
8812 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
8813 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
8814 dirs
[ndirs
].prefix
= j
;
8819 /* Now to the actual work. We have to find a subset of the directories which
8820 allow expressing the file name using references to the directory table
8821 with the least amount of characters. We do not do an exhaustive search
8822 where we would have to check out every combination of every single
8823 possible prefix. Instead we use a heuristic which provides nearly optimal
8824 results in most cases and never is much off. */
8825 saved
= XALLOCAVEC (int, ndirs
);
8826 savehere
= XALLOCAVEC (int, ndirs
);
8828 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
8829 for (i
= 0; i
< ndirs
; i
++)
8834 /* We can always save some space for the current directory. But this
8835 does not mean it will be enough to justify adding the directory. */
8836 savehere
[i
] = dirs
[i
].length
;
8837 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
8839 for (j
= i
+ 1; j
< ndirs
; j
++)
8842 if (saved
[j
] < dirs
[i
].length
)
8844 /* Determine whether the dirs[i] path is a prefix of the
8849 while (k
!= -1 && k
!= (int) i
)
8854 /* Yes it is. We can possibly save some memory by
8855 writing the filenames in dirs[j] relative to
8857 savehere
[j
] = dirs
[i
].length
;
8858 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
8863 /* Check whether we can save enough to justify adding the dirs[i]
8865 if (total
> dirs
[i
].length
+ 1)
8867 /* It's worthwhile adding. */
8868 for (j
= i
; j
< ndirs
; j
++)
8869 if (savehere
[j
] > 0)
8871 /* Remember how much we saved for this directory so far. */
8872 saved
[j
] = savehere
[j
];
8874 /* Remember the prefix directory. */
8875 dirs
[j
].dir_idx
= i
;
8880 /* Emit the directory name table. */
8881 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
8882 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
8883 dw2_asm_output_nstring (dirs
[i
].path
,
8885 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
8886 "Directory Entry: %#x", i
+ idx_offset
);
8888 dw2_asm_output_data (1, 0, "End directory table");
8890 /* We have to emit them in the order of emitted_number since that's
8891 used in the debug info generation. To do this efficiently we
8892 generate a back-mapping of the indices first. */
8893 backmap
= XALLOCAVEC (int, numfiles
);
8894 for (i
= 0; i
< numfiles
; i
++)
8895 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
8897 /* Now write all the file names. */
8898 for (i
= 0; i
< numfiles
; i
++)
8900 int file_idx
= backmap
[i
];
8901 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
8903 #ifdef VMS_DEBUGGING_INFO
8904 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
8906 /* Setting these fields can lead to debugger miscomparisons,
8907 but VMS Debug requires them to be set correctly. */
8912 int maxfilelen
= strlen (files
[file_idx
].path
)
8913 + dirs
[dir_idx
].length
8914 + MAX_VMS_VERSION_LEN
+ 1;
8915 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
8917 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
8918 snprintf (filebuf
, maxfilelen
, "%s;%d",
8919 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
8921 dw2_asm_output_nstring
8922 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
8924 /* Include directory index. */
8925 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
8927 /* Modification time. */
8928 dw2_asm_output_data_uleb128
8929 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
8933 /* File length in bytes. */
8934 dw2_asm_output_data_uleb128
8935 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
8939 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
8940 "File Entry: %#x", (unsigned) i
+ 1);
8942 /* Include directory index. */
8943 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
8945 /* Modification time. */
8946 dw2_asm_output_data_uleb128 (0, NULL
);
8948 /* File length in bytes. */
8949 dw2_asm_output_data_uleb128 (0, NULL
);
8950 #endif /* VMS_DEBUGGING_INFO */
8953 dw2_asm_output_data (1, 0, "End file name table");
8957 /* Output one line number table into the .debug_line section. */
8960 output_one_line_info_table (dw_line_info_table
*table
)
8962 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8963 unsigned int current_line
= 1;
8964 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
8965 dw_line_info_entry
*ent
;
8968 FOR_EACH_VEC_ELT (dw_line_info_entry
, table
->entries
, i
, ent
)
8970 switch (ent
->opcode
)
8972 case LI_set_address
:
8973 /* ??? Unfortunately, we have little choice here currently, and
8974 must always use the most general form. GCC does not know the
8975 address delta itself, so we can't use DW_LNS_advance_pc. Many
8976 ports do have length attributes which will give an upper bound
8977 on the address range. We could perhaps use length attributes
8978 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
8979 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
8981 /* This can handle any delta. This takes
8982 4+DWARF2_ADDR_SIZE bytes. */
8983 dw2_asm_output_data (1, 0, "set address %s", line_label
);
8984 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8985 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8986 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
8990 if (ent
->val
== current_line
)
8992 /* We still need to start a new row, so output a copy insn. */
8993 dw2_asm_output_data (1, DW_LNS_copy
,
8994 "copy line %u", current_line
);
8998 int line_offset
= ent
->val
- current_line
;
8999 int line_delta
= line_offset
- DWARF_LINE_BASE
;
9001 current_line
= ent
->val
;
9002 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9004 /* This can handle deltas from -10 to 234, using the current
9005 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9006 This takes 1 byte. */
9007 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9008 "line %u", current_line
);
9012 /* This can handle any delta. This takes at least 4 bytes,
9013 depending on the value being encoded. */
9014 dw2_asm_output_data (1, DW_LNS_advance_line
,
9015 "advance to line %u", current_line
);
9016 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9017 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
9023 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
9024 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9028 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
9029 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9032 case LI_negate_stmt
:
9033 current_is_stmt
= !current_is_stmt
;
9034 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
9035 "is_stmt %d", current_is_stmt
);
9038 case LI_set_prologue_end
:
9039 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
9040 "set prologue end");
9043 case LI_set_epilogue_begin
:
9044 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
9045 "set epilogue begin");
9048 case LI_set_discriminator
:
9049 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
9050 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
9051 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
9052 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
9057 /* Emit debug info for the address of the end of the table. */
9058 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
9059 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9060 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9061 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
9063 dw2_asm_output_data (1, 0, "end sequence");
9064 dw2_asm_output_data_uleb128 (1, NULL
);
9065 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
9068 /* Output the source line number correspondence information. This
9069 information goes into the .debug_line section. */
9072 output_line_info (void)
9074 char l1
[20], l2
[20], p1
[20], p2
[20];
9075 int ver
= dwarf_version
;
9076 bool saw_one
= false;
9079 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
9080 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
9081 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
9082 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
9084 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9085 dw2_asm_output_data (4, 0xffffffff,
9086 "Initial length escape value indicating 64-bit DWARF extension");
9087 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
9088 "Length of Source Line Info");
9089 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
9091 dw2_asm_output_data (2, ver
, "DWARF Version");
9092 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
9093 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
9095 /* Define the architecture-dependent minimum instruction length (in bytes).
9096 In this implementation of DWARF, this field is used for information
9097 purposes only. Since GCC generates assembly language, we have no
9098 a priori knowledge of how many instruction bytes are generated for each
9099 source line, and therefore can use only the DW_LNE_set_address and
9100 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
9101 this as '1', which is "correct enough" for all architectures,
9102 and don't let the target override. */
9103 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
9106 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
9107 "Maximum Operations Per Instruction");
9108 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
9109 "Default is_stmt_start flag");
9110 dw2_asm_output_data (1, DWARF_LINE_BASE
,
9111 "Line Base Value (Special Opcodes)");
9112 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
9113 "Line Range Value (Special Opcodes)");
9114 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
9115 "Special Opcode Base");
9117 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
9122 case DW_LNS_advance_pc
:
9123 case DW_LNS_advance_line
:
9124 case DW_LNS_set_file
:
9125 case DW_LNS_set_column
:
9126 case DW_LNS_fixed_advance_pc
:
9127 case DW_LNS_set_isa
:
9135 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
9139 /* Write out the information about the files we use. */
9140 output_file_names ();
9141 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
9143 if (separate_line_info
)
9145 dw_line_info_table
*table
;
9148 FOR_EACH_VEC_ELT (dw_line_info_table_p
, separate_line_info
, i
, table
)
9151 output_one_line_info_table (table
);
9155 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
9157 output_one_line_info_table (cold_text_section_line_info
);
9161 /* ??? Some Darwin linkers crash on a .debug_line section with no
9162 sequences. Further, merely a DW_LNE_end_sequence entry is not
9163 sufficient -- the address column must also be initialized.
9164 Make sure to output at least one set_address/end_sequence pair,
9165 choosing .text since that section is always present. */
9166 if (text_section_line_info
->in_use
|| !saw_one
)
9167 output_one_line_info_table (text_section_line_info
);
9169 /* Output the marker for the end of the line number info. */
9170 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9173 /* Given a pointer to a tree node for some base type, return a pointer to
9174 a DIE that describes the given type.
9176 This routine must only be called for GCC type nodes that correspond to
9177 Dwarf base (fundamental) types. */
9180 base_type_die (tree type
)
9182 dw_die_ref base_type_result
;
9183 enum dwarf_type encoding
;
9185 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
9188 /* If this is a subtype that should not be emitted as a subrange type,
9189 use the base type. See subrange_type_for_debug_p. */
9190 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
9191 type
= TREE_TYPE (type
);
9193 switch (TREE_CODE (type
))
9196 if ((dwarf_version
>= 4 || !dwarf_strict
)
9198 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9199 && DECL_IS_BUILTIN (TYPE_NAME (type
))
9200 && DECL_NAME (TYPE_NAME (type
)))
9202 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
9203 if (strcmp (name
, "char16_t") == 0
9204 || strcmp (name
, "char32_t") == 0)
9206 encoding
= DW_ATE_UTF
;
9210 if (TYPE_STRING_FLAG (type
))
9212 if (TYPE_UNSIGNED (type
))
9213 encoding
= DW_ATE_unsigned_char
;
9215 encoding
= DW_ATE_signed_char
;
9217 else if (TYPE_UNSIGNED (type
))
9218 encoding
= DW_ATE_unsigned
;
9220 encoding
= DW_ATE_signed
;
9224 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
9226 if (dwarf_version
>= 3 || !dwarf_strict
)
9227 encoding
= DW_ATE_decimal_float
;
9229 encoding
= DW_ATE_lo_user
;
9232 encoding
= DW_ATE_float
;
9235 case FIXED_POINT_TYPE
:
9236 if (!(dwarf_version
>= 3 || !dwarf_strict
))
9237 encoding
= DW_ATE_lo_user
;
9238 else if (TYPE_UNSIGNED (type
))
9239 encoding
= DW_ATE_unsigned_fixed
;
9241 encoding
= DW_ATE_signed_fixed
;
9244 /* Dwarf2 doesn't know anything about complex ints, so use
9245 a user defined type for it. */
9247 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
9248 encoding
= DW_ATE_complex_float
;
9250 encoding
= DW_ATE_lo_user
;
9254 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9255 encoding
= DW_ATE_boolean
;
9259 /* No other TREE_CODEs are Dwarf fundamental types. */
9263 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
9265 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
9266 int_size_in_bytes (type
));
9267 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
9268 add_pubtype (type
, base_type_result
);
9270 return base_type_result
;
9273 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9274 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9277 is_base_type (tree type
)
9279 switch (TREE_CODE (type
))
9285 case FIXED_POINT_TYPE
:
9293 case QUAL_UNION_TYPE
:
9298 case REFERENCE_TYPE
:
9312 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9313 node, return the size in bits for the type if it is a constant, or else
9314 return the alignment for the type if the type's size is not constant, or
9315 else return BITS_PER_WORD if the type actually turns out to be an
9318 static inline unsigned HOST_WIDE_INT
9319 simple_type_size_in_bits (const_tree type
)
9321 if (TREE_CODE (type
) == ERROR_MARK
)
9322 return BITS_PER_WORD
;
9323 else if (TYPE_SIZE (type
) == NULL_TREE
)
9325 else if (host_integerp (TYPE_SIZE (type
), 1))
9326 return tree_low_cst (TYPE_SIZE (type
), 1);
9328 return TYPE_ALIGN (type
);
9331 /* Similarly, but return a double_int instead of UHWI. */
9333 static inline double_int
9334 double_int_type_size_in_bits (const_tree type
)
9336 if (TREE_CODE (type
) == ERROR_MARK
)
9337 return double_int::from_uhwi (BITS_PER_WORD
);
9338 else if (TYPE_SIZE (type
) == NULL_TREE
)
9339 return double_int_zero
;
9340 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
9341 return tree_to_double_int (TYPE_SIZE (type
));
9343 return double_int::from_uhwi (TYPE_ALIGN (type
));
9346 /* Given a pointer to a tree node for a subrange type, return a pointer
9347 to a DIE that describes the given type. */
9350 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
9352 dw_die_ref subrange_die
;
9353 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
9355 if (context_die
== NULL
)
9356 context_die
= comp_unit_die ();
9358 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
9360 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
9362 /* The size of the subrange type and its base type do not match,
9363 so we need to generate a size attribute for the subrange type. */
9364 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
9368 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
9370 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
9372 return subrange_die
;
9375 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9376 entry that chains various modifiers in front of the given type. */
9379 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
9380 dw_die_ref context_die
)
9382 enum tree_code code
= TREE_CODE (type
);
9383 dw_die_ref mod_type_die
;
9384 dw_die_ref sub_die
= NULL
;
9385 tree item_type
= NULL
;
9386 tree qualified_type
;
9387 tree name
, low
, high
;
9388 dw_die_ref mod_scope
;
9390 if (code
== ERROR_MARK
)
9393 /* See if we already have the appropriately qualified variant of
9396 = get_qualified_type (type
,
9397 ((is_const_type
? TYPE_QUAL_CONST
: 0)
9398 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
9400 if (qualified_type
== sizetype
9401 && TYPE_NAME (qualified_type
)
9402 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
9404 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
9406 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
9407 && TYPE_PRECISION (t
)
9408 == TYPE_PRECISION (qualified_type
)
9409 && TYPE_UNSIGNED (t
)
9410 == TYPE_UNSIGNED (qualified_type
));
9414 /* If we do, then we can just use its DIE, if it exists. */
9417 mod_type_die
= lookup_type_die (qualified_type
);
9419 return mod_type_die
;
9422 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
9424 /* Handle C typedef types. */
9425 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
9426 && !DECL_ARTIFICIAL (name
))
9428 tree dtype
= TREE_TYPE (name
);
9430 if (qualified_type
== dtype
)
9432 /* For a named type, use the typedef. */
9433 gen_type_die (qualified_type
, context_die
);
9434 return lookup_type_die (qualified_type
);
9436 else if (is_const_type
< TYPE_READONLY (dtype
)
9437 || is_volatile_type
< TYPE_VOLATILE (dtype
)
9438 || (is_const_type
<= TYPE_READONLY (dtype
)
9439 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
9440 && DECL_ORIGINAL_TYPE (name
) != type
))
9441 /* cv-unqualified version of named type. Just use the unnamed
9442 type to which it refers. */
9443 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
9444 is_const_type
, is_volatile_type
,
9446 /* Else cv-qualified version of named type; fall through. */
9449 mod_scope
= scope_die_for (type
, context_die
);
9452 /* If both is_const_type and is_volatile_type, prefer the path
9453 which leads to a qualified type. */
9454 && (!is_volatile_type
9455 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
9456 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
9458 mod_type_die
= new_die (DW_TAG_const_type
, mod_scope
, type
);
9459 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
9461 else if (is_volatile_type
)
9463 mod_type_die
= new_die (DW_TAG_volatile_type
, mod_scope
, type
);
9464 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
9466 else if (code
== POINTER_TYPE
)
9468 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
9469 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
9470 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
9471 item_type
= TREE_TYPE (type
);
9472 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
9473 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
9474 TYPE_ADDR_SPACE (item_type
));
9476 else if (code
== REFERENCE_TYPE
)
9478 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
9479 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
9482 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
9483 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
9484 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
9485 item_type
= TREE_TYPE (type
);
9486 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
9487 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
9488 TYPE_ADDR_SPACE (item_type
));
9490 else if (code
== INTEGER_TYPE
9491 && TREE_TYPE (type
) != NULL_TREE
9492 && subrange_type_for_debug_p (type
, &low
, &high
))
9494 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
9495 item_type
= TREE_TYPE (type
);
9497 else if (is_base_type (type
))
9498 mod_type_die
= base_type_die (type
);
9501 gen_type_die (type
, context_die
);
9503 /* We have to get the type_main_variant here (and pass that to the
9504 `lookup_type_die' routine) because the ..._TYPE node we have
9505 might simply be a *copy* of some original type node (where the
9506 copy was created to help us keep track of typedef names) and
9507 that copy might have a different TYPE_UID from the original
9509 if (TREE_CODE (type
) != VECTOR_TYPE
)
9510 return lookup_type_die (type_main_variant (type
));
9512 /* Vectors have the debugging information in the type,
9513 not the main variant. */
9514 return lookup_type_die (type
);
9517 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9518 don't output a DW_TAG_typedef, since there isn't one in the
9519 user's program; just attach a DW_AT_name to the type.
9520 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
9521 if the base type already has the same name. */
9523 && ((TREE_CODE (name
) != TYPE_DECL
9524 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
9525 || (!is_const_type
&& !is_volatile_type
)))
9526 || (TREE_CODE (name
) == TYPE_DECL
9527 && TREE_TYPE (name
) == qualified_type
9528 && DECL_NAME (name
))))
9530 if (TREE_CODE (name
) == TYPE_DECL
)
9531 /* Could just call add_name_and_src_coords_attributes here,
9532 but since this is a builtin type it doesn't have any
9533 useful source coordinates anyway. */
9534 name
= DECL_NAME (name
);
9535 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
9537 /* This probably indicates a bug. */
9538 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
9540 name
= TYPE_NAME (type
);
9542 && TREE_CODE (name
) == TYPE_DECL
)
9543 name
= DECL_NAME (name
);
9544 add_name_attribute (mod_type_die
,
9545 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
9549 equate_type_number_to_die (qualified_type
, mod_type_die
);
9552 /* We must do this after the equate_type_number_to_die call, in case
9553 this is a recursive type. This ensures that the modified_type_die
9554 recursion will terminate even if the type is recursive. Recursive
9555 types are possible in Ada. */
9556 sub_die
= modified_type_die (item_type
,
9557 TYPE_READONLY (item_type
),
9558 TYPE_VOLATILE (item_type
),
9561 if (sub_die
!= NULL
)
9562 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
9564 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
9565 if (TYPE_ARTIFICIAL (type
))
9566 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
9568 return mod_type_die
;
9571 /* Generate DIEs for the generic parameters of T.
9572 T must be either a generic type or a generic function.
9573 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
9576 gen_generic_params_dies (tree t
)
9580 dw_die_ref die
= NULL
;
9582 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
9586 die
= lookup_type_die (t
);
9587 else if (DECL_P (t
))
9588 die
= lookup_decl_die (t
);
9592 parms
= lang_hooks
.get_innermost_generic_parms (t
);
9594 /* T has no generic parameter. It means T is neither a generic type
9595 or function. End of story. */
9598 parms_num
= TREE_VEC_LENGTH (parms
);
9599 args
= lang_hooks
.get_innermost_generic_args (t
);
9600 for (i
= 0; i
< parms_num
; i
++)
9602 tree parm
, arg
, arg_pack_elems
;
9604 parm
= TREE_VEC_ELT (parms
, i
);
9605 arg
= TREE_VEC_ELT (args
, i
);
9606 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
9607 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
9609 if (parm
&& TREE_VALUE (parm
) && arg
)
9611 /* If PARM represents a template parameter pack,
9612 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
9613 by DW_TAG_template_*_parameter DIEs for the argument
9614 pack elements of ARG. Note that ARG would then be
9615 an argument pack. */
9617 template_parameter_pack_die (TREE_VALUE (parm
),
9621 generic_parameter_die (TREE_VALUE (parm
), arg
,
9622 true /* Emit DW_AT_name */, die
);
9627 /* Create and return a DIE for PARM which should be
9628 the representation of a generic type parameter.
9629 For instance, in the C++ front end, PARM would be a template parameter.
9630 ARG is the argument to PARM.
9631 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
9633 PARENT_DIE is the parent DIE which the new created DIE should be added to,
9637 generic_parameter_die (tree parm
, tree arg
,
9639 dw_die_ref parent_die
)
9641 dw_die_ref tmpl_die
= NULL
;
9642 const char *name
= NULL
;
9644 if (!parm
|| !DECL_NAME (parm
) || !arg
)
9647 /* We support non-type generic parameters and arguments,
9648 type generic parameters and arguments, as well as
9649 generic generic parameters (a.k.a. template template parameters in C++)
9651 if (TREE_CODE (parm
) == PARM_DECL
)
9652 /* PARM is a nontype generic parameter */
9653 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
9654 else if (TREE_CODE (parm
) == TYPE_DECL
)
9655 /* PARM is a type generic parameter. */
9656 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
9657 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
9658 /* PARM is a generic generic parameter.
9659 Its DIE is a GNU extension. It shall have a
9660 DW_AT_name attribute to represent the name of the template template
9661 parameter, and a DW_AT_GNU_template_name attribute to represent the
9662 name of the template template argument. */
9663 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
9672 /* If PARM is a generic parameter pack, it means we are
9673 emitting debug info for a template argument pack element.
9674 In other terms, ARG is a template argument pack element.
9675 In that case, we don't emit any DW_AT_name attribute for
9679 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
9681 add_AT_string (tmpl_die
, DW_AT_name
, name
);
9684 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
9686 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
9687 TMPL_DIE should have a child DW_AT_type attribute that is set
9688 to the type of the argument to PARM, which is ARG.
9689 If PARM is a type generic parameter, TMPL_DIE should have a
9690 child DW_AT_type that is set to ARG. */
9691 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
9692 add_type_attribute (tmpl_die
, tmpl_type
, 0,
9693 TREE_THIS_VOLATILE (tmpl_type
),
9698 /* So TMPL_DIE is a DIE representing a
9699 a generic generic template parameter, a.k.a template template
9700 parameter in C++ and arg is a template. */
9702 /* The DW_AT_GNU_template_name attribute of the DIE must be set
9703 to the name of the argument. */
9704 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
9706 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
9709 if (TREE_CODE (parm
) == PARM_DECL
)
9710 /* So PARM is a non-type generic parameter.
9711 DWARF3 5.6.8 says we must set a DW_AT_const_value child
9712 attribute of TMPL_DIE which value represents the value
9714 We must be careful here:
9715 The value of ARG might reference some function decls.
9716 We might currently be emitting debug info for a generic
9717 type and types are emitted before function decls, we don't
9718 know if the function decls referenced by ARG will actually be
9719 emitted after cgraph computations.
9720 So must defer the generation of the DW_AT_const_value to
9721 after cgraph is ready. */
9722 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
9728 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
9729 PARM_PACK must be a template parameter pack. The returned DIE
9730 will be child DIE of PARENT_DIE. */
9733 template_parameter_pack_die (tree parm_pack
,
9734 tree parm_pack_args
,
9735 dw_die_ref parent_die
)
9740 gcc_assert (parent_die
&& parm_pack
);
9742 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
9743 add_name_and_src_coords_attributes (die
, parm_pack
);
9744 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
9745 generic_parameter_die (parm_pack
,
9746 TREE_VEC_ELT (parm_pack_args
, j
),
9747 false /* Don't emit DW_AT_name */,
9752 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
9753 an enumerated type. */
9756 type_is_enum (const_tree type
)
9758 return TREE_CODE (type
) == ENUMERAL_TYPE
;
9761 /* Return the DBX register number described by a given RTL node. */
9764 dbx_reg_number (const_rtx rtl
)
9766 unsigned regno
= REGNO (rtl
);
9768 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
9770 #ifdef LEAF_REG_REMAP
9771 if (crtl
->uses_only_leaf_regs
)
9773 int leaf_reg
= LEAF_REG_REMAP (regno
);
9775 regno
= (unsigned) leaf_reg
;
9779 regno
= DBX_REGISTER_NUMBER (regno
);
9780 gcc_assert (regno
!= INVALID_REGNUM
);
9784 /* Optionally add a DW_OP_piece term to a location description expression.
9785 DW_OP_piece is only added if the location description expression already
9786 doesn't end with DW_OP_piece. */
9789 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
9791 dw_loc_descr_ref loc
;
9793 if (*list_head
!= NULL
)
9795 /* Find the end of the chain. */
9796 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
9799 if (loc
->dw_loc_opc
!= DW_OP_piece
)
9800 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
9804 /* Return a location descriptor that designates a machine register or
9805 zero if there is none. */
9807 static dw_loc_descr_ref
9808 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
9812 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
9815 /* We only use "frame base" when we're sure we're talking about the
9816 post-prologue local stack frame. We do this by *not* running
9817 register elimination until this point, and recognizing the special
9818 argument pointer and soft frame pointer rtx's.
9819 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
9820 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
9821 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
9823 dw_loc_descr_ref result
= NULL
;
9825 if (dwarf_version
>= 4 || !dwarf_strict
)
9827 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
9830 add_loc_descr (&result
,
9831 new_loc_descr (DW_OP_stack_value
, 0, 0));
9836 regs
= targetm
.dwarf_register_span (rtl
);
9838 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
9839 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
9841 return one_reg_loc_descriptor (dbx_reg_number (rtl
), initialized
);
9844 /* Return a location descriptor that designates a machine register for
9845 a given hard register number. */
9847 static dw_loc_descr_ref
9848 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
9850 dw_loc_descr_ref reg_loc_descr
;
9854 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
9856 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
9858 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9859 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9861 return reg_loc_descr
;
9864 /* Given an RTL of a register, return a location descriptor that
9865 designates a value that spans more than one register. */
9867 static dw_loc_descr_ref
9868 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
9869 enum var_init_status initialized
)
9873 dw_loc_descr_ref loc_result
= NULL
;
9876 #ifdef LEAF_REG_REMAP
9877 if (crtl
->uses_only_leaf_regs
)
9879 int leaf_reg
= LEAF_REG_REMAP (reg
);
9881 reg
= (unsigned) leaf_reg
;
9884 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
9885 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
9887 /* Simple, contiguous registers. */
9888 if (regs
== NULL_RTX
)
9890 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
9897 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
9898 VAR_INIT_STATUS_INITIALIZED
);
9899 add_loc_descr (&loc_result
, t
);
9900 add_loc_descr_op_piece (&loc_result
, size
);
9906 /* Now onto stupid register sets in non contiguous locations. */
9908 gcc_assert (GET_CODE (regs
) == PARALLEL
);
9910 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
9913 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
9917 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
9918 VAR_INIT_STATUS_INITIALIZED
);
9919 add_loc_descr (&loc_result
, t
);
9920 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
9921 add_loc_descr_op_piece (&loc_result
, size
);
9924 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9925 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9929 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
9931 /* Return a location descriptor that designates a constant i,
9932 as a compound operation from constant (i >> shift), constant shift
9935 static dw_loc_descr_ref
9936 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
9938 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
9939 add_loc_descr (&ret
, int_loc_descriptor (shift
));
9940 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
9944 /* Return a location descriptor that designates a constant. */
9946 static dw_loc_descr_ref
9947 int_loc_descriptor (HOST_WIDE_INT i
)
9949 enum dwarf_location_atom op
;
9951 /* Pick the smallest representation of a constant, rather than just
9952 defaulting to the LEB encoding. */
9955 int clz
= clz_hwi (i
);
9956 int ctz
= ctz_hwi (i
);
9958 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
9961 else if (i
<= 0xffff)
9963 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
9964 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
9965 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
9966 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
9967 while DW_OP_const4u is 5 bytes. */
9968 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
9969 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
9970 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
9971 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
9972 while DW_OP_const4u is 5 bytes. */
9973 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
9974 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
9976 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
9977 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
9978 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
9979 while DW_OP_constu of constant >= 0x100000000 takes at least
9981 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
9982 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
9983 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
9984 >= HOST_BITS_PER_WIDE_INT
)
9985 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
9986 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
9987 while DW_OP_constu takes in this case at least 6 bytes. */
9988 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
9989 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
9990 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
9991 && size_of_uleb128 (i
) > 6)
9992 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
9993 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
10000 op
= DW_OP_const1s
;
10001 else if (i
>= -0x8000)
10002 op
= DW_OP_const2s
;
10003 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10005 if (size_of_int_loc_descriptor (i
) < 5)
10007 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10008 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10011 op
= DW_OP_const4s
;
10015 if (size_of_int_loc_descriptor (i
)
10016 < (unsigned long) 1 + size_of_sleb128 (i
))
10018 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10019 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10026 return new_loc_descr (op
, i
, 0);
10029 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10030 without actually allocating it. */
10032 static unsigned long
10033 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10035 return size_of_int_loc_descriptor (i
>> shift
)
10036 + size_of_int_loc_descriptor (shift
)
10040 /* Return size_of_locs (int_loc_descriptor (i)) without
10041 actually allocating it. */
10043 static unsigned long
10044 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
10053 else if (i
<= 0xff)
10055 else if (i
<= 0xffff)
10059 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10060 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10061 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10063 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10064 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10065 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10067 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10069 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
10070 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10071 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10072 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10074 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10075 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
10076 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10078 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10079 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10081 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10090 else if (i
>= -0x8000)
10092 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10094 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10096 s
= size_of_int_loc_descriptor (-i
) + 1;
10104 unsigned long r
= 1 + size_of_sleb128 (i
);
10105 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10107 s
= size_of_int_loc_descriptor (-i
) + 1;
10116 /* Return loc description representing "address" of integer value.
10117 This can appear only as toplevel expression. */
10119 static dw_loc_descr_ref
10120 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
10123 dw_loc_descr_ref loc_result
= NULL
;
10125 if (!(dwarf_version
>= 4 || !dwarf_strict
))
10128 litsize
= size_of_int_loc_descriptor (i
);
10129 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10130 is more compact. For DW_OP_stack_value we need:
10131 litsize + 1 (DW_OP_stack_value)
10132 and for DW_OP_implicit_value:
10133 1 (DW_OP_implicit_value) + 1 (length) + size. */
10134 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
10136 loc_result
= int_loc_descriptor (i
);
10137 add_loc_descr (&loc_result
,
10138 new_loc_descr (DW_OP_stack_value
, 0, 0));
10142 loc_result
= new_loc_descr (DW_OP_implicit_value
,
10144 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
10145 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
10149 /* Return a location descriptor that designates a base+offset location. */
10151 static dw_loc_descr_ref
10152 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
10153 enum var_init_status initialized
)
10155 unsigned int regno
;
10156 dw_loc_descr_ref result
;
10157 dw_fde_ref fde
= cfun
->fde
;
10159 /* We only use "frame base" when we're sure we're talking about the
10160 post-prologue local stack frame. We do this by *not* running
10161 register elimination until this point, and recognizing the special
10162 argument pointer and soft frame pointer rtx's. */
10163 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
10165 rtx elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
10169 if (GET_CODE (elim
) == PLUS
)
10171 offset
+= INTVAL (XEXP (elim
, 1));
10172 elim
= XEXP (elim
, 0);
10174 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10175 && (elim
== hard_frame_pointer_rtx
10176 || elim
== stack_pointer_rtx
))
10177 || elim
== (frame_pointer_needed
10178 ? hard_frame_pointer_rtx
10179 : stack_pointer_rtx
));
10181 /* If drap register is used to align stack, use frame
10182 pointer + offset to access stack variables. If stack
10183 is aligned without drap, use stack pointer + offset to
10184 access stack variables. */
10185 if (crtl
->stack_realign_tried
10186 && reg
== frame_pointer_rtx
)
10189 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
10190 ? HARD_FRAME_POINTER_REGNUM
10192 return new_reg_loc_descr (base_reg
, offset
);
10195 gcc_assert (frame_pointer_fb_offset_valid
);
10196 offset
+= frame_pointer_fb_offset
;
10197 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10201 regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
10203 if (!optimize
&& fde
10204 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
10206 /* Use cfa+offset to represent the location of arguments passed
10207 on the stack when drap is used to align stack.
10208 Only do this when not optimizing, for optimized code var-tracking
10209 is supposed to track where the arguments live and the register
10210 used as vdrap or drap in some spot might be used for something
10211 else in other part of the routine. */
10212 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10216 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
10219 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
10221 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10222 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10227 /* Return true if this RTL expression describes a base+offset calculation. */
10230 is_based_loc (const_rtx rtl
)
10232 return (GET_CODE (rtl
) == PLUS
10233 && ((REG_P (XEXP (rtl
, 0))
10234 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
10235 && CONST_INT_P (XEXP (rtl
, 1)))));
10238 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10241 static dw_loc_descr_ref
10242 tls_mem_loc_descriptor (rtx mem
)
10245 dw_loc_descr_ref loc_result
;
10247 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
10250 base
= get_base_address (MEM_EXPR (mem
));
10252 || TREE_CODE (base
) != VAR_DECL
10253 || !DECL_THREAD_LOCAL_P (base
))
10256 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
10257 if (loc_result
== NULL
)
10260 if (MEM_OFFSET (mem
))
10261 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
10266 /* Output debug info about reason why we failed to expand expression as dwarf
10270 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
10272 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
10274 fprintf (dump_file
, "Failed to expand as dwarf: ");
10276 print_generic_expr (dump_file
, expr
, dump_flags
);
10279 fprintf (dump_file
, "\n");
10280 print_rtl (dump_file
, rtl
);
10282 fprintf (dump_file
, "\nReason: %s\n", reason
);
10286 /* Helper function for const_ok_for_output, called either directly
10287 or via for_each_rtx. */
10290 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
10294 if (GET_CODE (rtl
) == UNSPEC
)
10296 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
10297 we can't express it in the debug info. */
10298 #ifdef ENABLE_CHECKING
10299 /* Don't complain about TLS UNSPECs, those are just too hard to
10300 delegitimize. Note this could be a non-decl SYMBOL_REF such as
10301 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
10302 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
10303 if (XVECLEN (rtl
, 0) == 0
10304 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
10305 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
10306 inform (current_function_decl
10307 ? DECL_SOURCE_LOCATION (current_function_decl
)
10308 : UNKNOWN_LOCATION
,
10309 #if NUM_UNSPEC_VALUES > 0
10310 "non-delegitimized UNSPEC %s (%d) found in variable location",
10311 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
10312 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
10315 "non-delegitimized UNSPEC %d found in variable location",
10319 expansion_failed (NULL_TREE
, rtl
,
10320 "UNSPEC hasn't been delegitimized.\n");
10324 if (targetm
.const_not_ok_for_debug_p (rtl
))
10326 expansion_failed (NULL_TREE
, rtl
,
10327 "Expression rejected for debug by the backend.\n");
10331 if (GET_CODE (rtl
) != SYMBOL_REF
)
10334 if (CONSTANT_POOL_ADDRESS_P (rtl
))
10337 get_pool_constant_mark (rtl
, &marked
);
10338 /* If all references to this pool constant were optimized away,
10339 it was not output and thus we can't represent it. */
10342 expansion_failed (NULL_TREE
, rtl
,
10343 "Constant was removed from constant pool.\n");
10348 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
10351 /* Avoid references to external symbols in debug info, on several targets
10352 the linker might even refuse to link when linking a shared library,
10353 and in many other cases the relocations for .debug_info/.debug_loc are
10354 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
10355 to be defined within the same shared library or executable are fine. */
10356 if (SYMBOL_REF_EXTERNAL_P (rtl
))
10358 tree decl
= SYMBOL_REF_DECL (rtl
);
10360 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
10362 expansion_failed (NULL_TREE
, rtl
,
10363 "Symbol not defined in current TU.\n");
10371 /* Return true if constant RTL can be emitted in DW_OP_addr or
10372 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
10373 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
10376 const_ok_for_output (rtx rtl
)
10378 if (GET_CODE (rtl
) == SYMBOL_REF
)
10379 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
10381 if (GET_CODE (rtl
) == CONST
)
10382 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
10387 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
10388 if possible, NULL otherwise. */
10391 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
10393 dw_die_ref type_die
;
10394 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
10398 switch (TREE_CODE (type
))
10406 type_die
= lookup_type_die (type
);
10408 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
10409 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
10414 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
10415 type matching MODE, or, if MODE is narrower than or as wide as
10416 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
10419 static dw_loc_descr_ref
10420 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
10422 enum machine_mode outer_mode
= mode
;
10423 dw_die_ref type_die
;
10424 dw_loc_descr_ref cvt
;
10426 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
10428 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
10431 type_die
= base_type_for_mode (outer_mode
, 1);
10432 if (type_die
== NULL
)
10434 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10435 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10436 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10437 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10438 add_loc_descr (&op
, cvt
);
10442 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
10444 static dw_loc_descr_ref
10445 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
10446 dw_loc_descr_ref op1
)
10448 dw_loc_descr_ref ret
= op0
;
10449 add_loc_descr (&ret
, op1
);
10450 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
10451 if (STORE_FLAG_VALUE
!= 1)
10453 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
10454 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
10459 /* Return location descriptor for signed comparison OP RTL. */
10461 static dw_loc_descr_ref
10462 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
10463 enum machine_mode mem_mode
)
10465 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
10466 dw_loc_descr_ref op0
, op1
;
10469 if (op_mode
== VOIDmode
)
10470 op_mode
= GET_MODE (XEXP (rtl
, 1));
10471 if (op_mode
== VOIDmode
)
10475 && (GET_MODE_CLASS (op_mode
) != MODE_INT
10476 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
10479 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
10480 VAR_INIT_STATUS_INITIALIZED
);
10481 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
10482 VAR_INIT_STATUS_INITIALIZED
);
10484 if (op0
== NULL
|| op1
== NULL
)
10487 if (GET_MODE_CLASS (op_mode
) != MODE_INT
10488 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
10489 return compare_loc_descriptor (op
, op0
, op1
);
10491 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
10493 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
10494 dw_loc_descr_ref cvt
;
10496 if (type_die
== NULL
)
10498 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10499 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10500 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10501 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10502 add_loc_descr (&op0
, cvt
);
10503 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10504 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10505 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10506 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10507 add_loc_descr (&op1
, cvt
);
10508 return compare_loc_descriptor (op
, op0
, op1
);
10511 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
10512 /* For eq/ne, if the operands are known to be zero-extended,
10513 there is no need to do the fancy shifting up. */
10514 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
10516 dw_loc_descr_ref last0
, last1
;
10517 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
10519 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
10521 /* deref_size zero extends, and for constants we can check
10522 whether they are zero extended or not. */
10523 if (((last0
->dw_loc_opc
== DW_OP_deref_size
10524 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
10525 || (CONST_INT_P (XEXP (rtl
, 0))
10526 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
10527 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
10528 && ((last1
->dw_loc_opc
== DW_OP_deref_size
10529 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
10530 || (CONST_INT_P (XEXP (rtl
, 1))
10531 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
10532 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
10533 return compare_loc_descriptor (op
, op0
, op1
);
10535 /* EQ/NE comparison against constant in narrower type than
10536 DWARF2_ADDR_SIZE can be performed either as
10537 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
10540 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
10541 DW_OP_{eq,ne}. Pick whatever is shorter. */
10542 if (CONST_INT_P (XEXP (rtl
, 1))
10543 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
10544 && (size_of_int_loc_descriptor (shift
) + 1
10545 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
10546 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
10547 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
10548 & GET_MODE_MASK (op_mode
))))
10550 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
10551 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
10552 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
10553 & GET_MODE_MASK (op_mode
));
10554 return compare_loc_descriptor (op
, op0
, op1
);
10557 add_loc_descr (&op0
, int_loc_descriptor (shift
));
10558 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
10559 if (CONST_INT_P (XEXP (rtl
, 1)))
10560 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
10563 add_loc_descr (&op1
, int_loc_descriptor (shift
));
10564 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
10566 return compare_loc_descriptor (op
, op0
, op1
);
10569 /* Return location descriptor for unsigned comparison OP RTL. */
10571 static dw_loc_descr_ref
10572 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
10573 enum machine_mode mem_mode
)
10575 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
10576 dw_loc_descr_ref op0
, op1
;
10578 if (op_mode
== VOIDmode
)
10579 op_mode
= GET_MODE (XEXP (rtl
, 1));
10580 if (op_mode
== VOIDmode
)
10582 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
10585 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
10588 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
10589 VAR_INIT_STATUS_INITIALIZED
);
10590 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
10591 VAR_INIT_STATUS_INITIALIZED
);
10593 if (op0
== NULL
|| op1
== NULL
)
10596 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
10598 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
10599 dw_loc_descr_ref last0
, last1
;
10600 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
10602 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
10604 if (CONST_INT_P (XEXP (rtl
, 0)))
10605 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
10606 /* deref_size zero extends, so no need to mask it again. */
10607 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
10608 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
10610 add_loc_descr (&op0
, int_loc_descriptor (mask
));
10611 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
10613 if (CONST_INT_P (XEXP (rtl
, 1)))
10614 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
10615 /* deref_size zero extends, so no need to mask it again. */
10616 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
10617 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
10619 add_loc_descr (&op1
, int_loc_descriptor (mask
));
10620 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
10623 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
10625 HOST_WIDE_INT bias
= 1;
10626 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
10627 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
10628 if (CONST_INT_P (XEXP (rtl
, 1)))
10629 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
10630 + INTVAL (XEXP (rtl
, 1)));
10632 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
10635 return compare_loc_descriptor (op
, op0
, op1
);
10638 /* Return location descriptor for {U,S}{MIN,MAX}. */
10640 static dw_loc_descr_ref
10641 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
10642 enum machine_mode mem_mode
)
10644 enum dwarf_location_atom op
;
10645 dw_loc_descr_ref op0
, op1
, ret
;
10646 dw_loc_descr_ref bra_node
, drop_node
;
10649 && (GET_MODE_CLASS (mode
) != MODE_INT
10650 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
10653 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
10654 VAR_INIT_STATUS_INITIALIZED
);
10655 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
10656 VAR_INIT_STATUS_INITIALIZED
);
10658 if (op0
== NULL
|| op1
== NULL
)
10661 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
10662 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
10663 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
10664 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
10666 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
10668 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
10669 add_loc_descr (&op0
, int_loc_descriptor (mask
));
10670 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
10671 add_loc_descr (&op1
, int_loc_descriptor (mask
));
10672 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
10674 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
10676 HOST_WIDE_INT bias
= 1;
10677 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
10678 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
10679 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
10682 else if (GET_MODE_CLASS (mode
) == MODE_INT
10683 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
10685 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
10686 add_loc_descr (&op0
, int_loc_descriptor (shift
));
10687 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
10688 add_loc_descr (&op1
, int_loc_descriptor (shift
));
10689 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
10691 else if (GET_MODE_CLASS (mode
) == MODE_INT
10692 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
10694 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
10695 dw_loc_descr_ref cvt
;
10696 if (type_die
== NULL
)
10698 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10699 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10700 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10701 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10702 add_loc_descr (&op0
, cvt
);
10703 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10704 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10705 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10706 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10707 add_loc_descr (&op1
, cvt
);
10710 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
10715 add_loc_descr (&ret
, op1
);
10716 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
10717 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
10718 add_loc_descr (&ret
, bra_node
);
10719 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
10720 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
10721 add_loc_descr (&ret
, drop_node
);
10722 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10723 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
10724 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
10725 && GET_MODE_CLASS (mode
) == MODE_INT
10726 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
10727 ret
= convert_descriptor_to_mode (mode
, ret
);
10731 /* Helper function for mem_loc_descriptor. Perform OP binary op,
10732 but after converting arguments to type_die, afterwards
10733 convert back to unsigned. */
10735 static dw_loc_descr_ref
10736 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
10737 enum machine_mode mode
, enum machine_mode mem_mode
)
10739 dw_loc_descr_ref cvt
, op0
, op1
;
10741 if (type_die
== NULL
)
10743 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
10744 VAR_INIT_STATUS_INITIALIZED
);
10745 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
10746 VAR_INIT_STATUS_INITIALIZED
);
10747 if (op0
== NULL
|| op1
== NULL
)
10749 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10750 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10751 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10752 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10753 add_loc_descr (&op0
, cvt
);
10754 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10755 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10756 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10757 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10758 add_loc_descr (&op1
, cvt
);
10759 add_loc_descr (&op0
, op1
);
10760 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
10761 return convert_descriptor_to_mode (mode
, op0
);
10764 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
10765 const0 is DW_OP_lit0 or corresponding typed constant,
10766 const1 is DW_OP_lit1 or corresponding typed constant
10767 and constMSB is constant with just the MSB bit set
10769 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
10770 L1: const0 DW_OP_swap
10771 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
10772 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
10777 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
10778 L1: const0 DW_OP_swap
10779 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
10780 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
10785 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
10786 L1: const1 DW_OP_swap
10787 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
10788 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
10792 static dw_loc_descr_ref
10793 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
10794 enum machine_mode mem_mode
)
10796 dw_loc_descr_ref op0
, ret
, tmp
;
10797 HOST_WIDE_INT valv
;
10798 dw_loc_descr_ref l1jump
, l1label
;
10799 dw_loc_descr_ref l2jump
, l2label
;
10800 dw_loc_descr_ref l3jump
, l3label
;
10801 dw_loc_descr_ref l4jump
, l4label
;
10804 if (GET_MODE_CLASS (mode
) != MODE_INT
10805 || GET_MODE (XEXP (rtl
, 0)) != mode
10806 || (GET_CODE (rtl
) == CLZ
10807 && GET_MODE_BITSIZE (mode
) > HOST_BITS_PER_DOUBLE_INT
))
10810 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
10811 VAR_INIT_STATUS_INITIALIZED
);
10815 if (GET_CODE (rtl
) == CLZ
)
10817 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
10818 valv
= GET_MODE_BITSIZE (mode
);
10820 else if (GET_CODE (rtl
) == FFS
)
10822 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
10823 valv
= GET_MODE_BITSIZE (mode
);
10824 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
10825 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
10826 add_loc_descr (&ret
, l1jump
);
10827 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
10828 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
10829 VAR_INIT_STATUS_INITIALIZED
);
10832 add_loc_descr (&ret
, tmp
);
10833 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
10834 add_loc_descr (&ret
, l4jump
);
10835 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
10836 ? const1_rtx
: const0_rtx
,
10838 VAR_INIT_STATUS_INITIALIZED
);
10839 if (l1label
== NULL
)
10841 add_loc_descr (&ret
, l1label
);
10842 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
10843 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
10844 add_loc_descr (&ret
, l2label
);
10845 if (GET_CODE (rtl
) != CLZ
)
10847 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
10848 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
10849 << (GET_MODE_BITSIZE (mode
) - 1));
10851 msb
= immed_double_const (0, (unsigned HOST_WIDE_INT
) 1
10852 << (GET_MODE_BITSIZE (mode
)
10853 - HOST_BITS_PER_WIDE_INT
- 1), mode
);
10854 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
10855 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
10856 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
10857 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
10859 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
10860 VAR_INIT_STATUS_INITIALIZED
);
10863 add_loc_descr (&ret
, tmp
);
10864 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
10865 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
10866 add_loc_descr (&ret
, l3jump
);
10867 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
10868 VAR_INIT_STATUS_INITIALIZED
);
10871 add_loc_descr (&ret
, tmp
);
10872 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
10873 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
10874 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
10875 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
10876 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
10877 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
10878 add_loc_descr (&ret
, l2jump
);
10879 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
10880 add_loc_descr (&ret
, l3label
);
10881 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
10882 add_loc_descr (&ret
, l4label
);
10883 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10884 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
10885 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10886 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
10887 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10888 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
10889 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10890 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
10894 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
10895 const1 is DW_OP_lit1 or corresponding typed constant):
10897 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
10898 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
10902 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
10903 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
10906 static dw_loc_descr_ref
10907 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
10908 enum machine_mode mem_mode
)
10910 dw_loc_descr_ref op0
, ret
, tmp
;
10911 dw_loc_descr_ref l1jump
, l1label
;
10912 dw_loc_descr_ref l2jump
, l2label
;
10914 if (GET_MODE_CLASS (mode
) != MODE_INT
10915 || GET_MODE (XEXP (rtl
, 0)) != mode
)
10918 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
10919 VAR_INIT_STATUS_INITIALIZED
);
10923 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
10924 VAR_INIT_STATUS_INITIALIZED
);
10927 add_loc_descr (&ret
, tmp
);
10928 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
10929 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
10930 add_loc_descr (&ret
, l1label
);
10931 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
10932 add_loc_descr (&ret
, l2jump
);
10933 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
10934 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
10935 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
10936 VAR_INIT_STATUS_INITIALIZED
);
10939 add_loc_descr (&ret
, tmp
);
10940 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
10941 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
10942 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
10943 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
10944 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
10945 VAR_INIT_STATUS_INITIALIZED
);
10946 add_loc_descr (&ret
, tmp
);
10947 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
10948 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
10949 add_loc_descr (&ret
, l1jump
);
10950 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
10951 add_loc_descr (&ret
, l2label
);
10952 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10953 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
10954 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10955 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
10959 /* BSWAP (constS is initial shift count, either 56 or 24):
10961 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
10962 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
10963 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
10964 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
10965 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
10967 static dw_loc_descr_ref
10968 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
10969 enum machine_mode mem_mode
)
10971 dw_loc_descr_ref op0
, ret
, tmp
;
10972 dw_loc_descr_ref l1jump
, l1label
;
10973 dw_loc_descr_ref l2jump
, l2label
;
10975 if (GET_MODE_CLASS (mode
) != MODE_INT
10976 || BITS_PER_UNIT
!= 8
10977 || (GET_MODE_BITSIZE (mode
) != 32
10978 && GET_MODE_BITSIZE (mode
) != 64))
10981 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
10982 VAR_INIT_STATUS_INITIALIZED
);
10987 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
10989 VAR_INIT_STATUS_INITIALIZED
);
10992 add_loc_descr (&ret
, tmp
);
10993 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
10994 VAR_INIT_STATUS_INITIALIZED
);
10997 add_loc_descr (&ret
, tmp
);
10998 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
10999 add_loc_descr (&ret
, l1label
);
11000 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11002 VAR_INIT_STATUS_INITIALIZED
);
11003 add_loc_descr (&ret
, tmp
);
11004 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
11005 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11006 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11007 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
11008 VAR_INIT_STATUS_INITIALIZED
);
11011 add_loc_descr (&ret
, tmp
);
11012 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11013 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
11014 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11015 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11016 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11017 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11018 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11019 VAR_INIT_STATUS_INITIALIZED
);
11020 add_loc_descr (&ret
, tmp
);
11021 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
11022 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11023 add_loc_descr (&ret
, l2jump
);
11024 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
11025 VAR_INIT_STATUS_INITIALIZED
);
11026 add_loc_descr (&ret
, tmp
);
11027 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11028 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11029 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11030 add_loc_descr (&ret
, l1jump
);
11031 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11032 add_loc_descr (&ret
, l2label
);
11033 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11034 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11035 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11036 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11037 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11038 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11042 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
11043 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11044 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
11045 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
11047 ROTATERT is similar:
11048 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
11049 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11050 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
11052 static dw_loc_descr_ref
11053 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11054 enum machine_mode mem_mode
)
11056 rtx rtlop1
= XEXP (rtl
, 1);
11057 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
11060 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11063 if (GET_MODE (rtlop1
) != VOIDmode
11064 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
11065 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
11066 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11067 VAR_INIT_STATUS_INITIALIZED
);
11068 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
11069 VAR_INIT_STATUS_INITIALIZED
);
11070 if (op0
== NULL
|| op1
== NULL
)
11072 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11073 for (i
= 0; i
< 2; i
++)
11075 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
11076 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
11078 VAR_INIT_STATUS_INITIALIZED
);
11079 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
11080 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11082 : HOST_BITS_PER_WIDE_INT
== 64
11083 ? DW_OP_const8u
: DW_OP_constu
,
11084 GET_MODE_MASK (mode
), 0);
11087 if (mask
[i
] == NULL
)
11089 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
11092 add_loc_descr (&ret
, op1
);
11093 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11094 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11095 if (GET_CODE (rtl
) == ROTATERT
)
11097 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11098 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11099 GET_MODE_BITSIZE (mode
), 0));
11101 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11102 if (mask
[0] != NULL
)
11103 add_loc_descr (&ret
, mask
[0]);
11104 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11105 if (mask
[1] != NULL
)
11107 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11108 add_loc_descr (&ret
, mask
[1]);
11109 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11111 if (GET_CODE (rtl
) == ROTATE
)
11113 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11114 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11115 GET_MODE_BITSIZE (mode
), 0));
11117 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11118 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11122 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11123 for DEBUG_PARAMETER_REF RTL. */
11125 static dw_loc_descr_ref
11126 parameter_ref_descriptor (rtx rtl
)
11128 dw_loc_descr_ref ret
;
11133 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
11134 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
11135 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
11138 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11139 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
11140 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11144 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
11145 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
11150 /* The following routine converts the RTL for a variable or parameter
11151 (resident in memory) into an equivalent Dwarf representation of a
11152 mechanism for getting the address of that same variable onto the top of a
11153 hypothetical "address evaluation" stack.
11155 When creating memory location descriptors, we are effectively transforming
11156 the RTL for a memory-resident object into its Dwarf postfix expression
11157 equivalent. This routine recursively descends an RTL tree, turning
11158 it into Dwarf postfix code as it goes.
11160 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
11162 MEM_MODE is the mode of the memory reference, needed to handle some
11163 autoincrement addressing modes.
11165 Return 0 if we can't represent the location. */
11168 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11169 enum machine_mode mem_mode
,
11170 enum var_init_status initialized
)
11172 dw_loc_descr_ref mem_loc_result
= NULL
;
11173 enum dwarf_location_atom op
;
11174 dw_loc_descr_ref op0
, op1
;
11176 if (mode
== VOIDmode
)
11177 mode
= GET_MODE (rtl
);
11179 /* Note that for a dynamically sized array, the location we will generate a
11180 description of here will be the lowest numbered location which is
11181 actually within the array. That's *not* necessarily the same as the
11182 zeroth element of the array. */
11184 rtl
= targetm
.delegitimize_address (rtl
);
11186 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
11189 switch (GET_CODE (rtl
))
11194 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
11197 /* The case of a subreg may arise when we have a local (register)
11198 variable or a formal (register) parameter which doesn't quite fill
11199 up an entire register. For now, just assume that it is
11200 legitimate to make the Dwarf info refer to the whole register which
11201 contains the given subreg. */
11202 if (!subreg_lowpart_p (rtl
))
11204 if (GET_MODE_CLASS (mode
) == MODE_INT
11205 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl
))) == MODE_INT
11206 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11207 #ifdef POINTERS_EXTEND_UNSIGNED
11208 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
11211 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
))) <= DWARF2_ADDR_SIZE
)
11213 mem_loc_result
= mem_loc_descriptor (SUBREG_REG (rtl
),
11214 GET_MODE (SUBREG_REG (rtl
)),
11215 mem_mode
, initialized
);
11220 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
))))
11222 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
)))
11223 && (GET_MODE_CLASS (mode
) != MODE_INT
11224 || GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl
))) != MODE_INT
))
11228 dw_die_ref type_die
;
11229 dw_loc_descr_ref cvt
;
11231 mem_loc_result
= mem_loc_descriptor (SUBREG_REG (rtl
),
11232 GET_MODE (SUBREG_REG (rtl
)),
11233 mem_mode
, initialized
);
11234 if (mem_loc_result
== NULL
)
11236 type_die
= base_type_for_mode (mode
,
11237 GET_MODE_CLASS (mode
) == MODE_INT
);
11238 if (type_die
== NULL
)
11240 mem_loc_result
= NULL
;
11243 if (GET_MODE_SIZE (mode
)
11244 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
))))
11245 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11247 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
11248 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11249 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11250 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11251 add_loc_descr (&mem_loc_result
, cvt
);
11256 if (GET_MODE_CLASS (mode
) != MODE_INT
11257 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
11258 && rtl
!= arg_pointer_rtx
11259 && rtl
!= frame_pointer_rtx
11260 #ifdef POINTERS_EXTEND_UNSIGNED
11261 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
11265 dw_die_ref type_die
;
11269 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
11271 type_die
= base_type_for_mode (mode
,
11272 GET_MODE_CLASS (mode
) == MODE_INT
);
11273 if (type_die
== NULL
)
11275 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
11276 dbx_reg_number (rtl
), 0);
11277 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
11278 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
11279 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
11282 /* Whenever a register number forms a part of the description of the
11283 method for calculating the (dynamic) address of a memory resident
11284 object, DWARF rules require the register number be referred to as
11285 a "base register". This distinction is not based in any way upon
11286 what category of register the hardware believes the given register
11287 belongs to. This is strictly DWARF terminology we're dealing with
11288 here. Note that in cases where the location of a memory-resident
11289 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
11290 OP_CONST (0)) the actual DWARF location descriptor that we generate
11291 may just be OP_BASEREG (basereg). This may look deceptively like
11292 the object in question was allocated to a register (rather than in
11293 memory) so DWARF consumers need to be aware of the subtle
11294 distinction between OP_REG and OP_BASEREG. */
11295 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
11296 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
11297 else if (stack_realign_drap
11299 && crtl
->args
.internal_arg_pointer
== rtl
11300 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
11302 /* If RTL is internal_arg_pointer, which has been optimized
11303 out, use DRAP instead. */
11304 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
11305 VAR_INIT_STATUS_INITIALIZED
);
11311 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11313 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
11314 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
11317 else if (GET_CODE (rtl
) == ZERO_EXTEND
11318 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11319 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
11320 < HOST_BITS_PER_WIDE_INT
11321 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
11322 to expand zero extend as two shifts instead of
11324 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
11326 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
11327 mem_loc_result
= op0
;
11328 add_loc_descr (&mem_loc_result
,
11329 int_loc_descriptor (GET_MODE_MASK (imode
)));
11330 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
11332 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11334 int shift
= DWARF2_ADDR_SIZE
11335 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
11336 shift
*= BITS_PER_UNIT
;
11337 if (GET_CODE (rtl
) == SIGN_EXTEND
)
11341 mem_loc_result
= op0
;
11342 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
11343 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
11344 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
11345 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
11347 else if (!dwarf_strict
)
11349 dw_die_ref type_die1
, type_die2
;
11350 dw_loc_descr_ref cvt
;
11352 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
11353 GET_CODE (rtl
) == ZERO_EXTEND
);
11354 if (type_die1
== NULL
)
11356 type_die2
= base_type_for_mode (mode
, 1);
11357 if (type_die2
== NULL
)
11359 mem_loc_result
= op0
;
11360 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11361 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11362 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
11363 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11364 add_loc_descr (&mem_loc_result
, cvt
);
11365 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11366 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11367 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
11368 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11369 add_loc_descr (&mem_loc_result
, cvt
);
11375 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
11376 if (new_rtl
!= rtl
)
11378 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
11380 if (mem_loc_result
!= NULL
)
11381 return mem_loc_result
;
11384 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
11385 get_address_mode (rtl
), mode
,
11386 VAR_INIT_STATUS_INITIALIZED
);
11387 if (mem_loc_result
== NULL
)
11388 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
11389 if (mem_loc_result
!= NULL
)
11391 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
11392 || GET_MODE_CLASS (mode
) != MODE_INT
)
11394 dw_die_ref type_die
;
11395 dw_loc_descr_ref deref
;
11400 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
11401 if (type_die
== NULL
)
11403 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
11404 GET_MODE_SIZE (mode
), 0);
11405 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
11406 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
11407 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
11408 add_loc_descr (&mem_loc_result
, deref
);
11410 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11411 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
11413 add_loc_descr (&mem_loc_result
,
11414 new_loc_descr (DW_OP_deref_size
,
11415 GET_MODE_SIZE (mode
), 0));
11420 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
11423 /* Some ports can transform a symbol ref into a label ref, because
11424 the symbol ref is too far away and has to be dumped into a constant
11428 if (GET_MODE_CLASS (mode
) != MODE_INT
11429 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
11430 #ifdef POINTERS_EXTEND_UNSIGNED
11431 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
11435 if (GET_CODE (rtl
) == SYMBOL_REF
11436 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11438 dw_loc_descr_ref temp
;
11440 /* If this is not defined, we have no way to emit the data. */
11441 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
11444 /* We used to emit DW_OP_addr here, but that's wrong, since
11445 DW_OP_addr should be relocated by the debug info consumer,
11446 while DW_OP_GNU_push_tls_address operand should not. */
11447 temp
= new_loc_descr (DWARF2_ADDR_SIZE
== 4
11448 ? DW_OP_const4u
: DW_OP_const8u
, 0, 0);
11449 temp
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
11450 temp
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
11451 temp
->dtprel
= true;
11453 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
11454 add_loc_descr (&mem_loc_result
, temp
);
11459 if (!const_ok_for_output (rtl
))
11463 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
11464 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
11465 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
11466 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
11472 case DEBUG_IMPLICIT_PTR
:
11473 expansion_failed (NULL_TREE
, rtl
,
11474 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
11480 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
11482 if (GET_MODE_CLASS (mode
) != MODE_INT
11483 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11484 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
11485 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
11488 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl
)),
11489 VAR_INIT_STATUS_INITIALIZED
);
11491 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
11492 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
11494 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
11495 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
11496 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
11500 gcc_unreachable ();
11503 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
11504 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11505 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
11508 case DEBUG_PARAMETER_REF
:
11509 mem_loc_result
= parameter_ref_descriptor (rtl
);
11513 /* Extract the PLUS expression nested inside and fall into
11514 PLUS code below. */
11515 rtl
= XEXP (rtl
, 1);
11520 /* Turn these into a PLUS expression and fall into the PLUS code
11522 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
11523 GEN_INT (GET_CODE (rtl
) == PRE_INC
11524 ? GET_MODE_UNIT_SIZE (mem_mode
)
11525 : -GET_MODE_UNIT_SIZE (mem_mode
)));
11527 /* ... fall through ... */
11531 if (is_based_loc (rtl
)
11532 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11533 || XEXP (rtl
, 0) == arg_pointer_rtx
11534 || XEXP (rtl
, 0) == frame_pointer_rtx
)
11535 && GET_MODE_CLASS (mode
) == MODE_INT
)
11536 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
11537 INTVAL (XEXP (rtl
, 1)),
11538 VAR_INIT_STATUS_INITIALIZED
);
11541 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11542 VAR_INIT_STATUS_INITIALIZED
);
11543 if (mem_loc_result
== 0)
11546 if (CONST_INT_P (XEXP (rtl
, 1))
11547 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11548 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
11551 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11552 VAR_INIT_STATUS_INITIALIZED
);
11555 add_loc_descr (&mem_loc_result
, op1
);
11556 add_loc_descr (&mem_loc_result
,
11557 new_loc_descr (DW_OP_plus
, 0, 0));
11562 /* If a pseudo-reg is optimized away, it is possible for it to
11563 be replaced with a MEM containing a multiply or shift. */
11574 && GET_MODE_CLASS (mode
) == MODE_INT
11575 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11577 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
11578 base_type_for_mode (mode
, 0),
11602 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11604 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11605 VAR_INIT_STATUS_INITIALIZED
);
11607 rtx rtlop1
= XEXP (rtl
, 1);
11608 if (GET_MODE (rtlop1
) != VOIDmode
11609 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
11610 < GET_MODE_BITSIZE (mode
))
11611 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
11612 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
11613 VAR_INIT_STATUS_INITIALIZED
);
11616 if (op0
== 0 || op1
== 0)
11619 mem_loc_result
= op0
;
11620 add_loc_descr (&mem_loc_result
, op1
);
11621 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
11637 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11638 VAR_INIT_STATUS_INITIALIZED
);
11639 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11640 VAR_INIT_STATUS_INITIALIZED
);
11642 if (op0
== 0 || op1
== 0)
11645 mem_loc_result
= op0
;
11646 add_loc_descr (&mem_loc_result
, op1
);
11647 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
11651 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
11653 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
11654 base_type_for_mode (mode
, 0),
11659 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11660 VAR_INIT_STATUS_INITIALIZED
);
11661 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11662 VAR_INIT_STATUS_INITIALIZED
);
11664 if (op0
== 0 || op1
== 0)
11667 mem_loc_result
= op0
;
11668 add_loc_descr (&mem_loc_result
, op1
);
11669 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
11670 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
11671 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
11672 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
11673 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
11677 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
11679 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
11684 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
11685 base_type_for_mode (mode
, 1),
11703 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11704 VAR_INIT_STATUS_INITIALIZED
);
11709 mem_loc_result
= op0
;
11710 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
11714 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11715 #ifdef POINTERS_EXTEND_UNSIGNED
11717 && mem_mode
!= VOIDmode
11718 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
11722 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
11726 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
11727 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
11729 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
11730 enum machine_mode amode
;
11731 if (type_die
== NULL
)
11733 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
11735 if (INTVAL (rtl
) >= 0
11736 && amode
!= BLKmode
11737 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
11738 /* const DW_OP_GNU_convert <XXX> vs.
11739 DW_OP_GNU_const_type <XXX, 1, const>. */
11740 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
11741 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
11743 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
11744 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11745 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11746 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11747 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11748 add_loc_descr (&mem_loc_result
, op0
);
11749 return mem_loc_result
;
11751 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
11753 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11754 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11755 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11756 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
11757 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
11760 mem_loc_result
->dw_loc_oprnd2
.val_class
11761 = dw_val_class_const_double
;
11762 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
11763 = double_int::from_shwi (INTVAL (rtl
));
11771 dw_die_ref type_die
;
11773 /* Note that a CONST_DOUBLE rtx could represent either an integer
11774 or a floating-point constant. A CONST_DOUBLE is used whenever
11775 the constant requires more than one word in order to be
11776 adequately represented. We output CONST_DOUBLEs as blocks. */
11777 if (mode
== VOIDmode
11778 || (GET_MODE (rtl
) == VOIDmode
11779 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
11781 type_die
= base_type_for_mode (mode
,
11782 GET_MODE_CLASS (mode
) == MODE_INT
);
11783 if (type_die
== NULL
)
11785 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
11786 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11787 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11788 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11789 if (SCALAR_FLOAT_MODE_P (mode
))
11791 unsigned int length
= GET_MODE_SIZE (mode
);
11792 unsigned char *array
11793 = (unsigned char*) ggc_alloc_atomic (length
);
11795 insert_float (rtl
, array
);
11796 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
11797 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
11798 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
11799 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
11803 mem_loc_result
->dw_loc_oprnd2
.val_class
11804 = dw_val_class_const_double
;
11805 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
11806 = rtx_to_double_int (rtl
);
11812 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
11816 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
11820 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
11824 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
11828 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
11832 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
11836 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
11840 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
11844 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
11848 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
11853 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11858 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
11863 if (CONST_INT_P (XEXP (rtl
, 1))
11864 && CONST_INT_P (XEXP (rtl
, 2))
11865 && ((unsigned) INTVAL (XEXP (rtl
, 1))
11866 + (unsigned) INTVAL (XEXP (rtl
, 2))
11867 <= GET_MODE_BITSIZE (mode
))
11868 && GET_MODE_CLASS (mode
) == MODE_INT
11869 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11870 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
11873 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
11874 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
11877 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
11881 mem_loc_result
= op0
;
11882 size
= INTVAL (XEXP (rtl
, 1));
11883 shift
= INTVAL (XEXP (rtl
, 2));
11884 if (BITS_BIG_ENDIAN
)
11885 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
11887 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
11889 add_loc_descr (&mem_loc_result
,
11890 int_loc_descriptor (DWARF2_ADDR_SIZE
11892 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
11894 if (size
!= (int) DWARF2_ADDR_SIZE
)
11896 add_loc_descr (&mem_loc_result
,
11897 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
11898 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
11905 dw_loc_descr_ref op2
, bra_node
, drop_node
;
11906 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
11907 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
11908 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
11909 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
11910 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11911 VAR_INIT_STATUS_INITIALIZED
);
11912 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
11913 VAR_INIT_STATUS_INITIALIZED
);
11914 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
11917 mem_loc_result
= op1
;
11918 add_loc_descr (&mem_loc_result
, op2
);
11919 add_loc_descr (&mem_loc_result
, op0
);
11920 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11921 add_loc_descr (&mem_loc_result
, bra_node
);
11922 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
11923 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11924 add_loc_descr (&mem_loc_result
, drop_node
);
11925 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11926 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11931 case FLOAT_TRUNCATE
:
11933 case UNSIGNED_FLOAT
:
11938 dw_die_ref type_die
;
11939 dw_loc_descr_ref cvt
;
11941 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
11942 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
11945 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
11946 && (GET_CODE (rtl
) == FLOAT
11947 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
11948 <= DWARF2_ADDR_SIZE
))
11950 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
11951 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
11952 if (type_die
== NULL
)
11954 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11955 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11956 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11957 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11958 add_loc_descr (&op0
, cvt
);
11960 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
11961 if (type_die
== NULL
)
11963 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11964 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11965 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11966 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11967 add_loc_descr (&op0
, cvt
);
11968 if (GET_MODE_CLASS (mode
) == MODE_INT
11969 && (GET_CODE (rtl
) == FIX
11970 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
11972 op0
= convert_descriptor_to_mode (mode
, op0
);
11976 mem_loc_result
= op0
;
11983 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
11988 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
11992 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
11997 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
12002 /* In theory, we could implement the above. */
12003 /* DWARF cannot represent the unsigned compare operations
12028 case FRACT_CONVERT
:
12029 case UNSIGNED_FRACT_CONVERT
:
12031 case UNSIGNED_SAT_FRACT
:
12037 case VEC_DUPLICATE
:
12041 case STRICT_LOW_PART
:
12045 /* If delegitimize_address couldn't do anything with the UNSPEC, we
12046 can't express it in the debug info. This can happen e.g. with some
12051 resolve_one_addr (&rtl
, NULL
);
12055 #ifdef ENABLE_CHECKING
12056 print_rtl (stderr
, rtl
);
12057 gcc_unreachable ();
12063 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12064 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12066 return mem_loc_result
;
12069 /* Return a descriptor that describes the concatenation of two locations.
12070 This is typically a complex variable. */
12072 static dw_loc_descr_ref
12073 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
12075 dw_loc_descr_ref cc_loc_result
= NULL
;
12076 dw_loc_descr_ref x0_ref
12077 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12078 dw_loc_descr_ref x1_ref
12079 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12081 if (x0_ref
== 0 || x1_ref
== 0)
12084 cc_loc_result
= x0_ref
;
12085 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
12087 add_loc_descr (&cc_loc_result
, x1_ref
);
12088 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
12090 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12091 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12093 return cc_loc_result
;
12096 /* Return a descriptor that describes the concatenation of N
12099 static dw_loc_descr_ref
12100 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
12103 dw_loc_descr_ref cc_loc_result
= NULL
;
12104 unsigned int n
= XVECLEN (concatn
, 0);
12106 for (i
= 0; i
< n
; ++i
)
12108 dw_loc_descr_ref ref
;
12109 rtx x
= XVECEXP (concatn
, 0, i
);
12111 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12115 add_loc_descr (&cc_loc_result
, ref
);
12116 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
12119 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12120 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12122 return cc_loc_result
;
12125 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12126 for DEBUG_IMPLICIT_PTR RTL. */
12128 static dw_loc_descr_ref
12129 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
12131 dw_loc_descr_ref ret
;
12136 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
12137 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
12138 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
12139 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
12140 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
12141 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12144 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12145 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12146 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12150 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12151 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
12156 /* Output a proper Dwarf location descriptor for a variable or parameter
12157 which is either allocated in a register or in a memory location. For a
12158 register, we just generate an OP_REG and the register number. For a
12159 memory location we provide a Dwarf postfix expression describing how to
12160 generate the (dynamic) address of the object onto the address stack.
12162 MODE is mode of the decl if this loc_descriptor is going to be used in
12163 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
12164 allowed, VOIDmode otherwise.
12166 If we don't know how to describe it, return 0. */
12168 static dw_loc_descr_ref
12169 loc_descriptor (rtx rtl
, enum machine_mode mode
,
12170 enum var_init_status initialized
)
12172 dw_loc_descr_ref loc_result
= NULL
;
12174 switch (GET_CODE (rtl
))
12177 /* The case of a subreg may arise when we have a local (register)
12178 variable or a formal (register) parameter which doesn't quite fill
12179 up an entire register. For now, just assume that it is
12180 legitimate to make the Dwarf info refer to the whole register which
12181 contains the given subreg. */
12182 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
12183 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
12184 GET_MODE (SUBREG_REG (rtl
)), initialized
);
12190 loc_result
= reg_loc_descriptor (rtl
, initialized
);
12194 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
12195 GET_MODE (rtl
), initialized
);
12196 if (loc_result
== NULL
)
12197 loc_result
= tls_mem_loc_descriptor (rtl
);
12198 if (loc_result
== NULL
)
12200 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12201 if (new_rtl
!= rtl
)
12202 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
12207 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
12212 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
12217 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
12219 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
12220 if (GET_CODE (loc
) == EXPR_LIST
)
12221 loc
= XEXP (loc
, 0);
12222 loc_result
= loc_descriptor (loc
, mode
, initialized
);
12226 rtl
= XEXP (rtl
, 1);
12231 rtvec par_elems
= XVEC (rtl
, 0);
12232 int num_elem
= GET_NUM_ELEM (par_elems
);
12233 enum machine_mode mode
;
12236 /* Create the first one, so we have something to add to. */
12237 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
12238 VOIDmode
, initialized
);
12239 if (loc_result
== NULL
)
12241 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
12242 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
12243 for (i
= 1; i
< num_elem
; i
++)
12245 dw_loc_descr_ref temp
;
12247 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
12248 VOIDmode
, initialized
);
12251 add_loc_descr (&loc_result
, temp
);
12252 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
12253 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
12259 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
12260 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
12265 if (mode
== VOIDmode
)
12266 mode
= GET_MODE (rtl
);
12268 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
12270 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
12272 /* Note that a CONST_DOUBLE rtx could represent either an integer
12273 or a floating-point constant. A CONST_DOUBLE is used whenever
12274 the constant requires more than one word in order to be
12275 adequately represented. We output CONST_DOUBLEs as blocks. */
12276 loc_result
= new_loc_descr (DW_OP_implicit_value
,
12277 GET_MODE_SIZE (mode
), 0);
12278 if (SCALAR_FLOAT_MODE_P (mode
))
12280 unsigned int length
= GET_MODE_SIZE (mode
);
12281 unsigned char *array
12282 = (unsigned char*) ggc_alloc_atomic (length
);
12284 insert_float (rtl
, array
);
12285 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12286 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12287 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12288 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12292 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
12293 loc_result
->dw_loc_oprnd2
.v
.val_double
12294 = rtx_to_double_int (rtl
);
12300 if (mode
== VOIDmode
)
12301 mode
= GET_MODE (rtl
);
12303 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
12305 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
12306 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
12307 unsigned char *array
= (unsigned char *)
12308 ggc_alloc_atomic (length
* elt_size
);
12312 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
12313 switch (GET_MODE_CLASS (mode
))
12315 case MODE_VECTOR_INT
:
12316 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
12318 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
12319 double_int val
= rtx_to_double_int (elt
);
12321 if (elt_size
<= sizeof (HOST_WIDE_INT
))
12322 insert_int (val
.to_shwi (), elt_size
, p
);
12325 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
12326 insert_double (val
, p
);
12331 case MODE_VECTOR_FLOAT
:
12332 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
12334 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
12335 insert_float (elt
, p
);
12340 gcc_unreachable ();
12343 loc_result
= new_loc_descr (DW_OP_implicit_value
,
12344 length
* elt_size
, 0);
12345 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12346 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
12347 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
12348 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12353 if (mode
== VOIDmode
12354 || GET_CODE (XEXP (rtl
, 0)) == CONST_INT
12355 || GET_CODE (XEXP (rtl
, 0)) == CONST_DOUBLE
12356 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
12358 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
12363 if (!const_ok_for_output (rtl
))
12366 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
12367 && (dwarf_version
>= 4 || !dwarf_strict
))
12369 loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
12370 loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
12371 loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
12372 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
12373 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
12377 case DEBUG_IMPLICIT_PTR
:
12378 loc_result
= implicit_ptr_descriptor (rtl
, 0);
12382 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
12383 && CONST_INT_P (XEXP (rtl
, 1)))
12386 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
12392 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
12393 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
12394 && dwarf_version
>= 4)
12395 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
12397 /* Value expression. */
12398 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
12400 add_loc_descr (&loc_result
,
12401 new_loc_descr (DW_OP_stack_value
, 0, 0));
12409 /* We need to figure out what section we should use as the base for the
12410 address ranges where a given location is valid.
12411 1. If this particular DECL has a section associated with it, use that.
12412 2. If this function has a section associated with it, use that.
12413 3. Otherwise, use the text section.
12414 XXX: If you split a variable across multiple sections, we won't notice. */
12416 static const char *
12417 secname_for_decl (const_tree decl
)
12419 const char *secname
;
12421 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
12423 tree sectree
= DECL_SECTION_NAME (decl
);
12424 secname
= TREE_STRING_POINTER (sectree
);
12426 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
12428 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
12429 secname
= TREE_STRING_POINTER (sectree
);
12431 else if (cfun
&& in_cold_section_p
)
12432 secname
= crtl
->subsections
.cold_section_label
;
12434 secname
= text_section_label
;
12439 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
12442 decl_by_reference_p (tree decl
)
12444 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
12445 || TREE_CODE (decl
) == VAR_DECL
)
12446 && DECL_BY_REFERENCE (decl
));
12449 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
12452 static dw_loc_descr_ref
12453 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
12454 enum var_init_status initialized
)
12456 int have_address
= 0;
12457 dw_loc_descr_ref descr
;
12458 enum machine_mode mode
;
12460 if (want_address
!= 2)
12462 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
12464 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
12466 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
12467 if (GET_CODE (varloc
) == EXPR_LIST
)
12468 varloc
= XEXP (varloc
, 0);
12469 mode
= GET_MODE (varloc
);
12470 if (MEM_P (varloc
))
12472 rtx addr
= XEXP (varloc
, 0);
12473 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
12474 mode
, initialized
);
12479 rtx x
= avoid_constant_pool_reference (varloc
);
12481 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
12486 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
12493 if (GET_CODE (varloc
) == VAR_LOCATION
)
12494 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
12496 mode
= DECL_MODE (loc
);
12497 descr
= loc_descriptor (varloc
, mode
, initialized
);
12504 if (want_address
== 2 && !have_address
12505 && (dwarf_version
>= 4 || !dwarf_strict
))
12507 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
12509 expansion_failed (loc
, NULL_RTX
,
12510 "DWARF address size mismatch");
12513 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
12516 /* Show if we can't fill the request for an address. */
12517 if (want_address
&& !have_address
)
12519 expansion_failed (loc
, NULL_RTX
,
12520 "Want address and only have value");
12524 /* If we've got an address and don't want one, dereference. */
12525 if (!want_address
&& have_address
)
12527 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
12528 enum dwarf_location_atom op
;
12530 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
12532 expansion_failed (loc
, NULL_RTX
,
12533 "DWARF address size mismatch");
12536 else if (size
== DWARF2_ADDR_SIZE
)
12539 op
= DW_OP_deref_size
;
12541 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
12547 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
12548 if it is not possible. */
12550 static dw_loc_descr_ref
12551 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
12553 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
12554 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
12555 else if (dwarf_version
>= 3 || !dwarf_strict
)
12556 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
12561 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
12562 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
12564 static dw_loc_descr_ref
12565 dw_sra_loc_expr (tree decl
, rtx loc
)
12568 unsigned int padsize
= 0;
12569 dw_loc_descr_ref descr
, *descr_tail
;
12570 unsigned HOST_WIDE_INT decl_size
;
12572 enum var_init_status initialized
;
12574 if (DECL_SIZE (decl
) == NULL
12575 || !host_integerp (DECL_SIZE (decl
), 1))
12578 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
12580 descr_tail
= &descr
;
12582 for (p
= loc
; p
; p
= XEXP (p
, 1))
12584 unsigned int bitsize
= decl_piece_bitsize (p
);
12585 rtx loc_note
= *decl_piece_varloc_ptr (p
);
12586 dw_loc_descr_ref cur_descr
;
12587 dw_loc_descr_ref
*tail
, last
= NULL
;
12588 unsigned int opsize
= 0;
12590 if (loc_note
== NULL_RTX
12591 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
12593 padsize
+= bitsize
;
12596 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
12597 varloc
= NOTE_VAR_LOCATION (loc_note
);
12598 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
12599 if (cur_descr
== NULL
)
12601 padsize
+= bitsize
;
12605 /* Check that cur_descr either doesn't use
12606 DW_OP_*piece operations, or their sum is equal
12607 to bitsize. Otherwise we can't embed it. */
12608 for (tail
= &cur_descr
; *tail
!= NULL
;
12609 tail
= &(*tail
)->dw_loc_next
)
12610 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
12612 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
12616 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
12618 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
12622 if (last
!= NULL
&& opsize
!= bitsize
)
12624 padsize
+= bitsize
;
12628 /* If there is a hole, add DW_OP_*piece after empty DWARF
12629 expression, which means that those bits are optimized out. */
12632 if (padsize
> decl_size
)
12634 decl_size
-= padsize
;
12635 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
12636 if (*descr_tail
== NULL
)
12638 descr_tail
= &(*descr_tail
)->dw_loc_next
;
12641 *descr_tail
= cur_descr
;
12643 if (bitsize
> decl_size
)
12645 decl_size
-= bitsize
;
12648 HOST_WIDE_INT offset
= 0;
12649 if (GET_CODE (varloc
) == VAR_LOCATION
12650 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
12652 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
12653 if (GET_CODE (varloc
) == EXPR_LIST
)
12654 varloc
= XEXP (varloc
, 0);
12658 if (GET_CODE (varloc
) == CONST
12659 || GET_CODE (varloc
) == SIGN_EXTEND
12660 || GET_CODE (varloc
) == ZERO_EXTEND
)
12661 varloc
= XEXP (varloc
, 0);
12662 else if (GET_CODE (varloc
) == SUBREG
)
12663 varloc
= SUBREG_REG (varloc
);
12668 /* DW_OP_bit_size offset should be zero for register
12669 or implicit location descriptions and empty location
12670 descriptions, but for memory addresses needs big endian
12672 if (MEM_P (varloc
))
12674 unsigned HOST_WIDE_INT memsize
12675 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
12676 if (memsize
!= bitsize
)
12678 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
12679 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
12681 if (memsize
< bitsize
)
12683 if (BITS_BIG_ENDIAN
)
12684 offset
= memsize
- bitsize
;
12688 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
12689 if (*descr_tail
== NULL
)
12691 descr_tail
= &(*descr_tail
)->dw_loc_next
;
12695 /* If there were any non-empty expressions, add padding till the end of
12697 if (descr
!= NULL
&& decl_size
!= 0)
12699 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
12700 if (*descr_tail
== NULL
)
12706 /* Return the dwarf representation of the location list LOC_LIST of
12707 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
12710 static dw_loc_list_ref
12711 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
12713 const char *endname
, *secname
;
12715 enum var_init_status initialized
;
12716 struct var_loc_node
*node
;
12717 dw_loc_descr_ref descr
;
12718 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
12719 dw_loc_list_ref list
= NULL
;
12720 dw_loc_list_ref
*listp
= &list
;
12722 /* Now that we know what section we are using for a base,
12723 actually construct the list of locations.
12724 The first location information is what is passed to the
12725 function that creates the location list, and the remaining
12726 locations just get added on to that list.
12727 Note that we only know the start address for a location
12728 (IE location changes), so to build the range, we use
12729 the range [current location start, next location start].
12730 This means we have to special case the last node, and generate
12731 a range of [last location start, end of function label]. */
12733 secname
= secname_for_decl (decl
);
12735 for (node
= loc_list
->first
; node
; node
= node
->next
)
12736 if (GET_CODE (node
->loc
) == EXPR_LIST
12737 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
12739 if (GET_CODE (node
->loc
) == EXPR_LIST
)
12741 /* This requires DW_OP_{,bit_}piece, which is not usable
12742 inside DWARF expressions. */
12743 if (want_address
!= 2)
12745 descr
= dw_sra_loc_expr (decl
, node
->loc
);
12751 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
12752 varloc
= NOTE_VAR_LOCATION (node
->loc
);
12753 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
12757 bool range_across_switch
= false;
12758 /* If section switch happens in between node->label
12759 and node->next->label (or end of function) and
12760 we can't emit it as a single entry list,
12761 emit two ranges, first one ending at the end
12762 of first partition and second one starting at the
12763 beginning of second partition. */
12764 if (node
== loc_list
->last_before_switch
12765 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
12766 && current_function_decl
)
12768 endname
= cfun
->fde
->dw_fde_end
;
12769 range_across_switch
= true;
12771 /* The variable has a location between NODE->LABEL and
12772 NODE->NEXT->LABEL. */
12773 else if (node
->next
)
12774 endname
= node
->next
->label
;
12775 /* If the variable has a location at the last label
12776 it keeps its location until the end of function. */
12777 else if (!current_function_decl
)
12778 endname
= text_end_label
;
12781 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
12782 current_function_funcdef_no
);
12783 endname
= ggc_strdup (label_id
);
12786 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
12787 if (TREE_CODE (decl
) == PARM_DECL
12788 && node
== loc_list
->first
12789 && GET_CODE (node
->loc
) == NOTE
12790 && strcmp (node
->label
, endname
) == 0)
12791 (*listp
)->force
= true;
12792 listp
= &(*listp
)->dw_loc_next
;
12794 if (range_across_switch
)
12796 if (GET_CODE (node
->loc
) == EXPR_LIST
)
12797 descr
= dw_sra_loc_expr (decl
, node
->loc
);
12800 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
12801 varloc
= NOTE_VAR_LOCATION (node
->loc
);
12802 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
12805 gcc_assert (descr
);
12806 /* The variable has a location between NODE->LABEL and
12807 NODE->NEXT->LABEL. */
12809 endname
= node
->next
->label
;
12811 endname
= cfun
->fde
->dw_fde_second_end
;
12812 *listp
= new_loc_list (descr
,
12813 cfun
->fde
->dw_fde_second_begin
,
12815 listp
= &(*listp
)->dw_loc_next
;
12820 /* Try to avoid the overhead of a location list emitting a location
12821 expression instead, but only if we didn't have more than one
12822 location entry in the first place. If some entries were not
12823 representable, we don't want to pretend a single entry that was
12824 applies to the entire scope in which the variable is
12826 if (list
&& loc_list
->first
->next
)
12832 /* Return if the loc_list has only single element and thus can be represented
12833 as location description. */
12836 single_element_loc_list_p (dw_loc_list_ref list
)
12838 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
12839 return !list
->ll_symbol
;
12842 /* To each location in list LIST add loc descr REF. */
12845 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
12847 dw_loc_descr_ref copy
;
12848 add_loc_descr (&list
->expr
, ref
);
12849 list
= list
->dw_loc_next
;
12852 copy
= ggc_alloc_dw_loc_descr_node ();
12853 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
12854 add_loc_descr (&list
->expr
, copy
);
12855 while (copy
->dw_loc_next
)
12857 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
12858 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
12859 copy
->dw_loc_next
= new_copy
;
12862 list
= list
->dw_loc_next
;
12866 /* Given two lists RET and LIST
12867 produce location list that is result of adding expression in LIST
12868 to expression in RET on each position in program.
12869 Might be destructive on both RET and LIST.
12871 TODO: We handle only simple cases of RET or LIST having at most one
12872 element. General case would inolve sorting the lists in program order
12873 and merging them that will need some additional work.
12874 Adding that will improve quality of debug info especially for SRA-ed
12878 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
12887 if (!list
->dw_loc_next
)
12889 add_loc_descr_to_each (*ret
, list
->expr
);
12892 if (!(*ret
)->dw_loc_next
)
12894 add_loc_descr_to_each (list
, (*ret
)->expr
);
12898 expansion_failed (NULL_TREE
, NULL_RTX
,
12899 "Don't know how to merge two non-trivial"
12900 " location lists.\n");
12905 /* LOC is constant expression. Try a luck, look it up in constant
12906 pool and return its loc_descr of its address. */
12908 static dw_loc_descr_ref
12909 cst_pool_loc_descr (tree loc
)
12911 /* Get an RTL for this, if something has been emitted. */
12912 rtx rtl
= lookup_constant_def (loc
);
12914 if (!rtl
|| !MEM_P (rtl
))
12919 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
12921 /* TODO: We might get more coverage if we was actually delaying expansion
12922 of all expressions till end of compilation when constant pools are fully
12924 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
12926 expansion_failed (loc
, NULL_RTX
,
12927 "CST value in contant pool but not marked.");
12930 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
12931 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
12934 /* Return dw_loc_list representing address of addr_expr LOC
12935 by looking for inner INDIRECT_REF expression and turning
12936 it into simple arithmetics. */
12938 static dw_loc_list_ref
12939 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
12942 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
12943 enum machine_mode mode
;
12944 int unsignedp
, volatilep
= 0;
12945 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
12947 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
12948 &bitsize
, &bitpos
, &offset
, &mode
,
12949 &unsignedp
, &volatilep
, false);
12951 if (bitpos
% BITS_PER_UNIT
)
12953 expansion_failed (loc
, NULL_RTX
, "bitfield access");
12956 if (!INDIRECT_REF_P (obj
))
12958 expansion_failed (obj
,
12959 NULL_RTX
, "no indirect ref in inner refrence");
12962 if (!offset
&& !bitpos
)
12963 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
12965 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
12966 && (dwarf_version
>= 4 || !dwarf_strict
))
12968 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
12973 /* Variable offset. */
12974 list_ret1
= loc_list_from_tree (offset
, 0);
12975 if (list_ret1
== 0)
12977 add_loc_list (&list_ret
, list_ret1
);
12980 add_loc_descr_to_each (list_ret
,
12981 new_loc_descr (DW_OP_plus
, 0, 0));
12983 bytepos
= bitpos
/ BITS_PER_UNIT
;
12985 add_loc_descr_to_each (list_ret
,
12986 new_loc_descr (DW_OP_plus_uconst
,
12988 else if (bytepos
< 0)
12989 loc_list_plus_const (list_ret
, bytepos
);
12990 add_loc_descr_to_each (list_ret
,
12991 new_loc_descr (DW_OP_stack_value
, 0, 0));
12997 /* Generate Dwarf location list representing LOC.
12998 If WANT_ADDRESS is false, expression computing LOC will be computed
12999 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13000 if WANT_ADDRESS is 2, expression computing address useable in location
13001 will be returned (i.e. DW_OP_reg can be used
13002 to refer to register values). */
13004 static dw_loc_list_ref
13005 loc_list_from_tree (tree loc
, int want_address
)
13007 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
13008 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13009 int have_address
= 0;
13010 enum dwarf_location_atom op
;
13012 /* ??? Most of the time we do not take proper care for sign/zero
13013 extending the values properly. Hopefully this won't be a real
13016 switch (TREE_CODE (loc
))
13019 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
13022 case PLACEHOLDER_EXPR
:
13023 /* This case involves extracting fields from an object to determine the
13024 position of other fields. We don't try to encode this here. The
13025 only user of this is Ada, which encodes the needed information using
13026 the names of types. */
13027 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
13031 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
13032 /* There are no opcodes for these operations. */
13035 case PREINCREMENT_EXPR
:
13036 case PREDECREMENT_EXPR
:
13037 case POSTINCREMENT_EXPR
:
13038 case POSTDECREMENT_EXPR
:
13039 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
13040 /* There are no opcodes for these operations. */
13044 /* If we already want an address, see if there is INDIRECT_REF inside
13045 e.g. for &this->field. */
13048 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
13049 (loc
, want_address
== 2);
13052 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
13053 && (ret
= cst_pool_loc_descr (loc
)))
13056 /* Otherwise, process the argument and look for the address. */
13057 if (!list_ret
&& !ret
)
13058 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
13062 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
13068 if (DECL_THREAD_LOCAL_P (loc
))
13071 enum dwarf_location_atom first_op
;
13072 enum dwarf_location_atom second_op
;
13073 bool dtprel
= false;
13075 if (targetm
.have_tls
)
13077 /* If this is not defined, we have no way to emit the
13079 if (!targetm
.asm_out
.output_dwarf_dtprel
)
13082 /* The way DW_OP_GNU_push_tls_address is specified, we
13083 can only look up addresses of objects in the current
13084 module. We used DW_OP_addr as first op, but that's
13085 wrong, because DW_OP_addr is relocated by the debug
13086 info consumer, while DW_OP_GNU_push_tls_address
13087 operand shouldn't be. */
13088 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
13090 first_op
= DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
;
13092 second_op
= DW_OP_GNU_push_tls_address
;
13096 if (!targetm
.emutls
.debug_form_tls_address
13097 || !(dwarf_version
>= 3 || !dwarf_strict
))
13099 /* We stuffed the control variable into the DECL_VALUE_EXPR
13100 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13101 no longer appear in gimple code. We used the control
13102 variable in specific so that we could pick it up here. */
13103 loc
= DECL_VALUE_EXPR (loc
);
13104 first_op
= DW_OP_addr
;
13105 second_op
= DW_OP_form_tls_address
;
13108 rtl
= rtl_for_decl_location (loc
);
13109 if (rtl
== NULL_RTX
)
13114 rtl
= XEXP (rtl
, 0);
13115 if (! CONSTANT_P (rtl
))
13118 ret
= new_loc_descr (first_op
, 0, 0);
13119 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
13120 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
13121 ret
->dtprel
= dtprel
;
13123 ret1
= new_loc_descr (second_op
, 0, 0);
13124 add_loc_descr (&ret
, ret1
);
13133 if (DECL_HAS_VALUE_EXPR_P (loc
))
13134 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
13138 case FUNCTION_DECL
:
13141 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
13143 if (loc_list
&& loc_list
->first
)
13145 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
13146 have_address
= want_address
!= 0;
13149 rtl
= rtl_for_decl_location (loc
);
13150 if (rtl
== NULL_RTX
)
13152 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
13155 else if (CONST_INT_P (rtl
))
13157 HOST_WIDE_INT val
= INTVAL (rtl
);
13158 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13159 val
&= GET_MODE_MASK (DECL_MODE (loc
));
13160 ret
= int_loc_descriptor (val
);
13162 else if (GET_CODE (rtl
) == CONST_STRING
)
13164 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
13167 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
13169 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
13170 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
13171 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
13175 enum machine_mode mode
, mem_mode
;
13177 /* Certain constructs can only be represented at top-level. */
13178 if (want_address
== 2)
13180 ret
= loc_descriptor (rtl
, VOIDmode
,
13181 VAR_INIT_STATUS_INITIALIZED
);
13186 mode
= GET_MODE (rtl
);
13187 mem_mode
= VOIDmode
;
13191 mode
= get_address_mode (rtl
);
13192 rtl
= XEXP (rtl
, 0);
13195 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
13196 VAR_INIT_STATUS_INITIALIZED
);
13199 expansion_failed (loc
, rtl
,
13200 "failed to produce loc descriptor for rtl");
13207 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
13211 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13215 case COMPOUND_EXPR
:
13216 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
13219 case VIEW_CONVERT_EXPR
:
13222 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
13224 case COMPONENT_REF
:
13225 case BIT_FIELD_REF
:
13227 case ARRAY_RANGE_REF
:
13228 case REALPART_EXPR
:
13229 case IMAGPART_EXPR
:
13232 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13233 enum machine_mode mode
;
13234 int unsignedp
, volatilep
= 0;
13236 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
13237 &unsignedp
, &volatilep
, false);
13239 gcc_assert (obj
!= loc
);
13241 list_ret
= loc_list_from_tree (obj
,
13243 && !bitpos
&& !offset
? 2 : 1);
13244 /* TODO: We can extract value of the small expression via shifting even
13245 for nonzero bitpos. */
13248 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
13250 expansion_failed (loc
, NULL_RTX
,
13251 "bitfield access");
13255 if (offset
!= NULL_TREE
)
13257 /* Variable offset. */
13258 list_ret1
= loc_list_from_tree (offset
, 0);
13259 if (list_ret1
== 0)
13261 add_loc_list (&list_ret
, list_ret1
);
13264 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
13267 bytepos
= bitpos
/ BITS_PER_UNIT
;
13269 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
13270 else if (bytepos
< 0)
13271 loc_list_plus_const (list_ret
, bytepos
);
13278 if ((want_address
|| !host_integerp (loc
, 0))
13279 && (ret
= cst_pool_loc_descr (loc
)))
13281 else if (want_address
== 2
13282 && host_integerp (loc
, 0)
13283 && (ret
= address_of_int_loc_descriptor
13284 (int_size_in_bytes (TREE_TYPE (loc
)),
13285 tree_low_cst (loc
, 0))))
13287 else if (host_integerp (loc
, 0))
13288 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
13291 expansion_failed (loc
, NULL_RTX
,
13292 "Integer operand is not host integer");
13301 if ((ret
= cst_pool_loc_descr (loc
)))
13304 /* We can construct small constants here using int_loc_descriptor. */
13305 expansion_failed (loc
, NULL_RTX
,
13306 "constructor or constant not in constant pool");
13309 case TRUTH_AND_EXPR
:
13310 case TRUTH_ANDIF_EXPR
:
13315 case TRUTH_XOR_EXPR
:
13320 case TRUTH_OR_EXPR
:
13321 case TRUTH_ORIF_EXPR
:
13326 case FLOOR_DIV_EXPR
:
13327 case CEIL_DIV_EXPR
:
13328 case ROUND_DIV_EXPR
:
13329 case TRUNC_DIV_EXPR
:
13330 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13339 case FLOOR_MOD_EXPR
:
13340 case CEIL_MOD_EXPR
:
13341 case ROUND_MOD_EXPR
:
13342 case TRUNC_MOD_EXPR
:
13343 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13348 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13349 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
13350 if (list_ret
== 0 || list_ret1
== 0)
13353 add_loc_list (&list_ret
, list_ret1
);
13356 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
13357 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
13358 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
13359 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
13360 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
13372 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
13375 case POINTER_PLUS_EXPR
:
13377 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
13379 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13383 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
13391 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
13398 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
13405 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
13412 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
13427 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13428 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
13429 if (list_ret
== 0 || list_ret1
== 0)
13432 add_loc_list (&list_ret
, list_ret1
);
13435 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
13438 case TRUTH_NOT_EXPR
:
13452 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13456 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
13462 const enum tree_code code
=
13463 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
13465 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
13466 build2 (code
, integer_type_node
,
13467 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
13468 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
13471 /* ... fall through ... */
13475 dw_loc_descr_ref lhs
13476 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
13477 dw_loc_list_ref rhs
13478 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
13479 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
13481 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13482 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
13485 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13486 add_loc_descr_to_each (list_ret
, bra_node
);
13488 add_loc_list (&list_ret
, rhs
);
13489 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
13490 add_loc_descr_to_each (list_ret
, jump_node
);
13492 add_loc_descr_to_each (list_ret
, lhs
);
13493 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13494 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
13496 /* ??? Need a node to point the skip at. Use a nop. */
13497 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
13498 add_loc_descr_to_each (list_ret
, tmp
);
13499 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13500 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
13504 case FIX_TRUNC_EXPR
:
13508 /* Leave front-end specific codes as simply unknown. This comes
13509 up, for instance, with the C STMT_EXPR. */
13510 if ((unsigned int) TREE_CODE (loc
)
13511 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
13513 expansion_failed (loc
, NULL_RTX
,
13514 "language specific tree node");
13518 #ifdef ENABLE_CHECKING
13519 /* Otherwise this is a generic code; we should just lists all of
13520 these explicitly. We forgot one. */
13521 gcc_unreachable ();
13523 /* In a release build, we want to degrade gracefully: better to
13524 generate incomplete debugging information than to crash. */
13529 if (!ret
&& !list_ret
)
13532 if (want_address
== 2 && !have_address
13533 && (dwarf_version
>= 4 || !dwarf_strict
))
13535 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13537 expansion_failed (loc
, NULL_RTX
,
13538 "DWARF address size mismatch");
13542 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13544 add_loc_descr_to_each (list_ret
,
13545 new_loc_descr (DW_OP_stack_value
, 0, 0));
13548 /* Show if we can't fill the request for an address. */
13549 if (want_address
&& !have_address
)
13551 expansion_failed (loc
, NULL_RTX
,
13552 "Want address and only have value");
13556 gcc_assert (!ret
|| !list_ret
);
13558 /* If we've got an address and don't want one, dereference. */
13559 if (!want_address
&& have_address
)
13561 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13563 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13565 expansion_failed (loc
, NULL_RTX
,
13566 "DWARF address size mismatch");
13569 else if (size
== DWARF2_ADDR_SIZE
)
13572 op
= DW_OP_deref_size
;
13575 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
13577 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
13580 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
13585 /* Same as above but return only single location expression. */
13586 static dw_loc_descr_ref
13587 loc_descriptor_from_tree (tree loc
, int want_address
)
13589 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
13592 if (ret
->dw_loc_next
)
13594 expansion_failed (loc
, NULL_RTX
,
13595 "Location list where only loc descriptor needed");
13601 /* Given a value, round it up to the lowest multiple of `boundary'
13602 which is not less than the value itself. */
13604 static inline HOST_WIDE_INT
13605 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
13607 return (((value
+ boundary
- 1) / boundary
) * boundary
);
13610 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
13611 pointer to the declared type for the relevant field variable, or return
13612 `integer_type_node' if the given node turns out to be an
13613 ERROR_MARK node. */
13616 field_type (const_tree decl
)
13620 if (TREE_CODE (decl
) == ERROR_MARK
)
13621 return integer_type_node
;
13623 type
= DECL_BIT_FIELD_TYPE (decl
);
13624 if (type
== NULL_TREE
)
13625 type
= TREE_TYPE (decl
);
13630 /* Given a pointer to a tree node, return the alignment in bits for
13631 it, or else return BITS_PER_WORD if the node actually turns out to
13632 be an ERROR_MARK node. */
13634 static inline unsigned
13635 simple_type_align_in_bits (const_tree type
)
13637 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
13640 static inline unsigned
13641 simple_decl_align_in_bits (const_tree decl
)
13643 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
13646 /* Return the result of rounding T up to ALIGN. */
13648 static inline double_int
13649 round_up_to_align (double_int t
, unsigned int align
)
13651 double_int alignd
= double_int::from_uhwi (align
);
13653 t
+= double_int_minus_one
;
13654 t
= t
.div (alignd
, true, TRUNC_DIV_EXPR
);
13659 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
13660 lowest addressed byte of the "containing object" for the given FIELD_DECL,
13661 or return 0 if we are unable to determine what that offset is, either
13662 because the argument turns out to be a pointer to an ERROR_MARK node, or
13663 because the offset is actually variable. (We can't handle the latter case
13666 static HOST_WIDE_INT
13667 field_byte_offset (const_tree decl
)
13669 double_int object_offset_in_bits
;
13670 double_int object_offset_in_bytes
;
13671 double_int bitpos_int
;
13673 if (TREE_CODE (decl
) == ERROR_MARK
)
13676 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
13678 /* We cannot yet cope with fields whose positions are variable, so
13679 for now, when we see such things, we simply return 0. Someday, we may
13680 be able to handle such cases, but it will be damn difficult. */
13681 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
13684 bitpos_int
= tree_to_double_int (bit_position (decl
));
13686 #ifdef PCC_BITFIELD_TYPE_MATTERS
13687 if (PCC_BITFIELD_TYPE_MATTERS
)
13690 tree field_size_tree
;
13691 double_int deepest_bitpos
;
13692 double_int field_size_in_bits
;
13693 unsigned int type_align_in_bits
;
13694 unsigned int decl_align_in_bits
;
13695 double_int type_size_in_bits
;
13697 type
= field_type (decl
);
13698 type_size_in_bits
= double_int_type_size_in_bits (type
);
13699 type_align_in_bits
= simple_type_align_in_bits (type
);
13701 field_size_tree
= DECL_SIZE (decl
);
13703 /* The size could be unspecified if there was an error, or for
13704 a flexible array member. */
13705 if (!field_size_tree
)
13706 field_size_tree
= bitsize_zero_node
;
13708 /* If the size of the field is not constant, use the type size. */
13709 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
13710 field_size_in_bits
= tree_to_double_int (field_size_tree
);
13712 field_size_in_bits
= type_size_in_bits
;
13714 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
13716 /* The GCC front-end doesn't make any attempt to keep track of the
13717 starting bit offset (relative to the start of the containing
13718 structure type) of the hypothetical "containing object" for a
13719 bit-field. Thus, when computing the byte offset value for the
13720 start of the "containing object" of a bit-field, we must deduce
13721 this information on our own. This can be rather tricky to do in
13722 some cases. For example, handling the following structure type
13723 definition when compiling for an i386/i486 target (which only
13724 aligns long long's to 32-bit boundaries) can be very tricky:
13726 struct S { int field1; long long field2:31; };
13728 Fortunately, there is a simple rule-of-thumb which can be used
13729 in such cases. When compiling for an i386/i486, GCC will
13730 allocate 8 bytes for the structure shown above. It decides to
13731 do this based upon one simple rule for bit-field allocation.
13732 GCC allocates each "containing object" for each bit-field at
13733 the first (i.e. lowest addressed) legitimate alignment boundary
13734 (based upon the required minimum alignment for the declared
13735 type of the field) which it can possibly use, subject to the
13736 condition that there is still enough available space remaining
13737 in the containing object (when allocated at the selected point)
13738 to fully accommodate all of the bits of the bit-field itself.
13740 This simple rule makes it obvious why GCC allocates 8 bytes for
13741 each object of the structure type shown above. When looking
13742 for a place to allocate the "containing object" for `field2',
13743 the compiler simply tries to allocate a 64-bit "containing
13744 object" at each successive 32-bit boundary (starting at zero)
13745 until it finds a place to allocate that 64- bit field such that
13746 at least 31 contiguous (and previously unallocated) bits remain
13747 within that selected 64 bit field. (As it turns out, for the
13748 example above, the compiler finds it is OK to allocate the
13749 "containing object" 64-bit field at bit-offset zero within the
13752 Here we attempt to work backwards from the limited set of facts
13753 we're given, and we try to deduce from those facts, where GCC
13754 must have believed that the containing object started (within
13755 the structure type). The value we deduce is then used (by the
13756 callers of this routine) to generate DW_AT_location and
13757 DW_AT_bit_offset attributes for fields (both bit-fields and, in
13758 the case of DW_AT_location, regular fields as well). */
13760 /* Figure out the bit-distance from the start of the structure to
13761 the "deepest" bit of the bit-field. */
13762 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
13764 /* This is the tricky part. Use some fancy footwork to deduce
13765 where the lowest addressed bit of the containing object must
13767 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
13769 /* Round up to type_align by default. This works best for
13771 object_offset_in_bits
13772 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
13774 if (object_offset_in_bits
.ugt (bitpos_int
))
13776 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
13778 /* Round up to decl_align instead. */
13779 object_offset_in_bits
13780 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
13784 #endif /* PCC_BITFIELD_TYPE_MATTERS */
13785 object_offset_in_bits
= bitpos_int
;
13787 object_offset_in_bytes
13788 = object_offset_in_bits
.div (double_int::from_uhwi (BITS_PER_UNIT
),
13789 true, TRUNC_DIV_EXPR
);
13790 return object_offset_in_bytes
.to_shwi ();
13793 /* The following routines define various Dwarf attributes and any data
13794 associated with them. */
13796 /* Add a location description attribute value to a DIE.
13798 This emits location attributes suitable for whole variables and
13799 whole parameters. Note that the location attributes for struct fields are
13800 generated by the routine `data_member_location_attribute' below. */
13803 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
13804 dw_loc_list_ref descr
)
13808 if (single_element_loc_list_p (descr
))
13809 add_AT_loc (die
, attr_kind
, descr
->expr
);
13811 add_AT_loc_list (die
, attr_kind
, descr
);
13814 /* Add DW_AT_accessibility attribute to DIE if needed. */
13817 add_accessibility_attribute (dw_die_ref die
, tree decl
)
13819 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
13820 children, otherwise the default is DW_ACCESS_public. In DWARF2
13821 the default has always been DW_ACCESS_public. */
13822 if (TREE_PROTECTED (decl
))
13823 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
13824 else if (TREE_PRIVATE (decl
))
13826 if (dwarf_version
== 2
13827 || die
->die_parent
== NULL
13828 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
13829 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
13831 else if (dwarf_version
> 2
13833 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
13834 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
13837 /* Attach the specialized form of location attribute used for data members of
13838 struct and union types. In the special case of a FIELD_DECL node which
13839 represents a bit-field, the "offset" part of this special location
13840 descriptor must indicate the distance in bytes from the lowest-addressed
13841 byte of the containing struct or union type to the lowest-addressed byte of
13842 the "containing object" for the bit-field. (See the `field_byte_offset'
13845 For any given bit-field, the "containing object" is a hypothetical object
13846 (of some integral or enum type) within which the given bit-field lives. The
13847 type of this hypothetical "containing object" is always the same as the
13848 declared type of the individual bit-field itself (for GCC anyway... the
13849 DWARF spec doesn't actually mandate this). Note that it is the size (in
13850 bytes) of the hypothetical "containing object" which will be given in the
13851 DW_AT_byte_size attribute for this bit-field. (See the
13852 `byte_size_attribute' function below.) It is also used when calculating the
13853 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
13854 function below.) */
13857 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
13859 HOST_WIDE_INT offset
;
13860 dw_loc_descr_ref loc_descr
= 0;
13862 if (TREE_CODE (decl
) == TREE_BINFO
)
13864 /* We're working on the TAG_inheritance for a base class. */
13865 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
13867 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
13868 aren't at a fixed offset from all (sub)objects of the same
13869 type. We need to extract the appropriate offset from our
13870 vtable. The following dwarf expression means
13872 BaseAddr = ObAddr + *((*ObAddr) - Offset)
13874 This is specific to the V3 ABI, of course. */
13876 dw_loc_descr_ref tmp
;
13878 /* Make a copy of the object address. */
13879 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
13880 add_loc_descr (&loc_descr
, tmp
);
13882 /* Extract the vtable address. */
13883 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
13884 add_loc_descr (&loc_descr
, tmp
);
13886 /* Calculate the address of the offset. */
13887 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
13888 gcc_assert (offset
< 0);
13890 tmp
= int_loc_descriptor (-offset
);
13891 add_loc_descr (&loc_descr
, tmp
);
13892 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
13893 add_loc_descr (&loc_descr
, tmp
);
13895 /* Extract the offset. */
13896 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
13897 add_loc_descr (&loc_descr
, tmp
);
13899 /* Add it to the object address. */
13900 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
13901 add_loc_descr (&loc_descr
, tmp
);
13904 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
13907 offset
= field_byte_offset (decl
);
13911 if (dwarf_version
> 2)
13913 /* Don't need to output a location expression, just the constant. */
13915 add_AT_int (die
, DW_AT_data_member_location
, offset
);
13917 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
13922 enum dwarf_location_atom op
;
13924 /* The DWARF2 standard says that we should assume that the structure
13925 address is already on the stack, so we can specify a structure
13926 field address by using DW_OP_plus_uconst. */
13927 op
= DW_OP_plus_uconst
;
13928 loc_descr
= new_loc_descr (op
, offset
, 0);
13932 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
13935 /* Writes integer values to dw_vec_const array. */
13938 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
13942 *dest
++ = val
& 0xff;
13948 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
13950 static HOST_WIDE_INT
13951 extract_int (const unsigned char *src
, unsigned int size
)
13953 HOST_WIDE_INT val
= 0;
13959 val
|= *--src
& 0xff;
13965 /* Writes double_int values to dw_vec_const array. */
13968 insert_double (double_int val
, unsigned char *dest
)
13970 unsigned char *p0
= dest
;
13971 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
13973 if (WORDS_BIG_ENDIAN
)
13979 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
13980 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
13983 /* Writes floating point values to dw_vec_const array. */
13986 insert_float (const_rtx rtl
, unsigned char *array
)
13988 REAL_VALUE_TYPE rv
;
13992 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
13993 real_to_target (val
, &rv
, GET_MODE (rtl
));
13995 /* real_to_target puts 32-bit pieces in each long. Pack them. */
13996 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
13998 insert_int (val
[i
], 4, array
);
14003 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14004 does not have a "location" either in memory or in a register. These
14005 things can arise in GNU C when a constant is passed as an actual parameter
14006 to an inlined function. They can also arise in C++ where declared
14007 constants do not necessarily get memory "homes". */
14010 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
14012 switch (GET_CODE (rtl
))
14016 HOST_WIDE_INT val
= INTVAL (rtl
);
14019 add_AT_int (die
, DW_AT_const_value
, val
);
14021 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
14026 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14027 floating-point constant. A CONST_DOUBLE is used whenever the
14028 constant requires more than one word in order to be adequately
14031 enum machine_mode mode
= GET_MODE (rtl
);
14033 if (SCALAR_FLOAT_MODE_P (mode
))
14035 unsigned int length
= GET_MODE_SIZE (mode
);
14036 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
14038 insert_float (rtl
, array
);
14039 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
14042 add_AT_double (die
, DW_AT_const_value
,
14043 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
14049 enum machine_mode mode
= GET_MODE (rtl
);
14050 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
14051 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
14052 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
14053 (length
* elt_size
);
14057 switch (GET_MODE_CLASS (mode
))
14059 case MODE_VECTOR_INT
:
14060 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14062 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14063 double_int val
= rtx_to_double_int (elt
);
14065 if (elt_size
<= sizeof (HOST_WIDE_INT
))
14066 insert_int (val
.to_shwi (), elt_size
, p
);
14069 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
14070 insert_double (val
, p
);
14075 case MODE_VECTOR_FLOAT
:
14076 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14078 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14079 insert_float (elt
, p
);
14084 gcc_unreachable ();
14087 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
14092 if (dwarf_version
>= 4 || !dwarf_strict
)
14094 dw_loc_descr_ref loc_result
;
14095 resolve_one_addr (&rtl
, NULL
);
14097 loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
14098 loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
14099 loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
14100 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14101 add_AT_loc (die
, DW_AT_location
, loc_result
);
14102 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
14108 if (CONSTANT_P (XEXP (rtl
, 0)))
14109 return add_const_value_attribute (die
, XEXP (rtl
, 0));
14112 if (!const_ok_for_output (rtl
))
14115 if (dwarf_version
>= 4 || !dwarf_strict
)
14120 /* In cases where an inlined instance of an inline function is passed
14121 the address of an `auto' variable (which is local to the caller) we
14122 can get a situation where the DECL_RTL of the artificial local
14123 variable (for the inlining) which acts as a stand-in for the
14124 corresponding formal parameter (of the inline function) will look
14125 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14126 exactly a compile-time constant expression, but it isn't the address
14127 of the (artificial) local variable either. Rather, it represents the
14128 *value* which the artificial local variable always has during its
14129 lifetime. We currently have no way to represent such quasi-constant
14130 values in Dwarf, so for now we just punt and generate nothing. */
14138 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
14139 && MEM_READONLY_P (rtl
)
14140 && GET_MODE (rtl
) == BLKmode
)
14142 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
14148 /* No other kinds of rtx should be possible here. */
14149 gcc_unreachable ();
14154 /* Determine whether the evaluation of EXPR references any variables
14155 or functions which aren't otherwise used (and therefore may not be
14158 reference_to_unused (tree
* tp
, int * walk_subtrees
,
14159 void * data ATTRIBUTE_UNUSED
)
14161 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
14162 *walk_subtrees
= 0;
14164 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
14165 && ! TREE_ASM_WRITTEN (*tp
))
14167 /* ??? The C++ FE emits debug information for using decls, so
14168 putting gcc_unreachable here falls over. See PR31899. For now
14169 be conservative. */
14170 else if (!cgraph_global_info_ready
14171 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
14173 else if (TREE_CODE (*tp
) == VAR_DECL
)
14175 struct varpool_node
*node
= varpool_get_node (*tp
);
14176 if (!node
|| !node
->analyzed
)
14179 else if (TREE_CODE (*tp
) == FUNCTION_DECL
14180 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
14182 /* The call graph machinery must have finished analyzing,
14183 optimizing and gimplifying the CU by now.
14184 So if *TP has no call graph node associated
14185 to it, it means *TP will not be emitted. */
14186 if (!cgraph_get_node (*tp
))
14189 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
14195 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
14196 for use in a later add_const_value_attribute call. */
14199 rtl_for_decl_init (tree init
, tree type
)
14201 rtx rtl
= NULL_RTX
;
14205 /* If a variable is initialized with a string constant without embedded
14206 zeros, build CONST_STRING. */
14207 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
14209 tree enttype
= TREE_TYPE (type
);
14210 tree domain
= TYPE_DOMAIN (type
);
14211 enum machine_mode mode
= TYPE_MODE (enttype
);
14213 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
14215 && integer_zerop (TYPE_MIN_VALUE (domain
))
14216 && compare_tree_int (TYPE_MAX_VALUE (domain
),
14217 TREE_STRING_LENGTH (init
) - 1) == 0
14218 && ((size_t) TREE_STRING_LENGTH (init
)
14219 == strlen (TREE_STRING_POINTER (init
)) + 1))
14221 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
14222 ggc_strdup (TREE_STRING_POINTER (init
)));
14223 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
14224 MEM_READONLY_P (rtl
) = 1;
14227 /* Other aggregates, and complex values, could be represented using
14229 else if (AGGREGATE_TYPE_P (type
)
14230 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
14231 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
14232 || TREE_CODE (type
) == COMPLEX_TYPE
)
14234 /* Vectors only work if their mode is supported by the target.
14235 FIXME: generic vectors ought to work too. */
14236 else if (TREE_CODE (type
) == VECTOR_TYPE
14237 && !VECTOR_MODE_P (TYPE_MODE (type
)))
14239 /* If the initializer is something that we know will expand into an
14240 immediate RTL constant, expand it now. We must be careful not to
14241 reference variables which won't be output. */
14242 else if (initializer_constant_valid_p (init
, type
)
14243 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
14245 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
14247 if (TREE_CODE (type
) == VECTOR_TYPE
)
14248 switch (TREE_CODE (init
))
14253 if (TREE_CONSTANT (init
))
14255 VEC(constructor_elt
,gc
) *elts
= CONSTRUCTOR_ELTS (init
);
14256 bool constant_p
= true;
14258 unsigned HOST_WIDE_INT ix
;
14260 /* Even when ctor is constant, it might contain non-*_CST
14261 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
14262 belong into VECTOR_CST nodes. */
14263 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
14264 if (!CONSTANT_CLASS_P (value
))
14266 constant_p
= false;
14272 init
= build_vector_from_ctor (type
, elts
);
14282 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
14284 /* If expand_expr returns a MEM, it wasn't immediate. */
14285 gcc_assert (!rtl
|| !MEM_P (rtl
));
14291 /* Generate RTL for the variable DECL to represent its location. */
14294 rtl_for_decl_location (tree decl
)
14298 /* Here we have to decide where we are going to say the parameter "lives"
14299 (as far as the debugger is concerned). We only have a couple of
14300 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
14302 DECL_RTL normally indicates where the parameter lives during most of the
14303 activation of the function. If optimization is enabled however, this
14304 could be either NULL or else a pseudo-reg. Both of those cases indicate
14305 that the parameter doesn't really live anywhere (as far as the code
14306 generation parts of GCC are concerned) during most of the function's
14307 activation. That will happen (for example) if the parameter is never
14308 referenced within the function.
14310 We could just generate a location descriptor here for all non-NULL
14311 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
14312 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
14313 where DECL_RTL is NULL or is a pseudo-reg.
14315 Note however that we can only get away with using DECL_INCOMING_RTL as
14316 a backup substitute for DECL_RTL in certain limited cases. In cases
14317 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
14318 we can be sure that the parameter was passed using the same type as it is
14319 declared to have within the function, and that its DECL_INCOMING_RTL
14320 points us to a place where a value of that type is passed.
14322 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
14323 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
14324 because in these cases DECL_INCOMING_RTL points us to a value of some
14325 type which is *different* from the type of the parameter itself. Thus,
14326 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
14327 such cases, the debugger would end up (for example) trying to fetch a
14328 `float' from a place which actually contains the first part of a
14329 `double'. That would lead to really incorrect and confusing
14330 output at debug-time.
14332 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
14333 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
14334 are a couple of exceptions however. On little-endian machines we can
14335 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
14336 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
14337 an integral type that is smaller than TREE_TYPE (decl). These cases arise
14338 when (on a little-endian machine) a non-prototyped function has a
14339 parameter declared to be of type `short' or `char'. In such cases,
14340 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
14341 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
14342 passed `int' value. If the debugger then uses that address to fetch
14343 a `short' or a `char' (on a little-endian machine) the result will be
14344 the correct data, so we allow for such exceptional cases below.
14346 Note that our goal here is to describe the place where the given formal
14347 parameter lives during most of the function's activation (i.e. between the
14348 end of the prologue and the start of the epilogue). We'll do that as best
14349 as we can. Note however that if the given formal parameter is modified
14350 sometime during the execution of the function, then a stack backtrace (at
14351 debug-time) will show the function as having been called with the *new*
14352 value rather than the value which was originally passed in. This happens
14353 rarely enough that it is not a major problem, but it *is* a problem, and
14354 I'd like to fix it.
14356 A future version of dwarf2out.c may generate two additional attributes for
14357 any given DW_TAG_formal_parameter DIE which will describe the "passed
14358 type" and the "passed location" for the given formal parameter in addition
14359 to the attributes we now generate to indicate the "declared type" and the
14360 "active location" for each parameter. This additional set of attributes
14361 could be used by debuggers for stack backtraces. Separately, note that
14362 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
14363 This happens (for example) for inlined-instances of inline function formal
14364 parameters which are never referenced. This really shouldn't be
14365 happening. All PARM_DECL nodes should get valid non-NULL
14366 DECL_INCOMING_RTL values. FIXME. */
14368 /* Use DECL_RTL as the "location" unless we find something better. */
14369 rtl
= DECL_RTL_IF_SET (decl
);
14371 /* When generating abstract instances, ignore everything except
14372 constants, symbols living in memory, and symbols living in
14373 fixed registers. */
14374 if (! reload_completed
)
14377 && (CONSTANT_P (rtl
)
14379 && CONSTANT_P (XEXP (rtl
, 0)))
14381 && TREE_CODE (decl
) == VAR_DECL
14382 && TREE_STATIC (decl
))))
14384 rtl
= targetm
.delegitimize_address (rtl
);
14389 else if (TREE_CODE (decl
) == PARM_DECL
)
14391 if (rtl
== NULL_RTX
14392 || is_pseudo_reg (rtl
)
14394 && is_pseudo_reg (XEXP (rtl
, 0))
14395 && DECL_INCOMING_RTL (decl
)
14396 && MEM_P (DECL_INCOMING_RTL (decl
))
14397 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
14399 tree declared_type
= TREE_TYPE (decl
);
14400 tree passed_type
= DECL_ARG_TYPE (decl
);
14401 enum machine_mode dmode
= TYPE_MODE (declared_type
);
14402 enum machine_mode pmode
= TYPE_MODE (passed_type
);
14404 /* This decl represents a formal parameter which was optimized out.
14405 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
14406 all cases where (rtl == NULL_RTX) just below. */
14407 if (dmode
== pmode
)
14408 rtl
= DECL_INCOMING_RTL (decl
);
14409 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
14410 && SCALAR_INT_MODE_P (dmode
)
14411 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
14412 && DECL_INCOMING_RTL (decl
))
14414 rtx inc
= DECL_INCOMING_RTL (decl
);
14417 else if (MEM_P (inc
))
14419 if (BYTES_BIG_ENDIAN
)
14420 rtl
= adjust_address_nv (inc
, dmode
,
14421 GET_MODE_SIZE (pmode
)
14422 - GET_MODE_SIZE (dmode
));
14429 /* If the parm was passed in registers, but lives on the stack, then
14430 make a big endian correction if the mode of the type of the
14431 parameter is not the same as the mode of the rtl. */
14432 /* ??? This is the same series of checks that are made in dbxout.c before
14433 we reach the big endian correction code there. It isn't clear if all
14434 of these checks are necessary here, but keeping them all is the safe
14436 else if (MEM_P (rtl
)
14437 && XEXP (rtl
, 0) != const0_rtx
14438 && ! CONSTANT_P (XEXP (rtl
, 0))
14439 /* Not passed in memory. */
14440 && !MEM_P (DECL_INCOMING_RTL (decl
))
14441 /* Not passed by invisible reference. */
14442 && (!REG_P (XEXP (rtl
, 0))
14443 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
14444 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
14445 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
14446 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
14449 /* Big endian correction check. */
14450 && BYTES_BIG_ENDIAN
14451 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
14452 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
14455 enum machine_mode addr_mode
= get_address_mode (rtl
);
14456 int offset
= (UNITS_PER_WORD
14457 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
14459 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
14460 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
14463 else if (TREE_CODE (decl
) == VAR_DECL
14466 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
14467 && BYTES_BIG_ENDIAN
)
14469 enum machine_mode addr_mode
= get_address_mode (rtl
);
14470 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
14471 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
14473 /* If a variable is declared "register" yet is smaller than
14474 a register, then if we store the variable to memory, it
14475 looks like we're storing a register-sized value, when in
14476 fact we are not. We need to adjust the offset of the
14477 storage location to reflect the actual value's bytes,
14478 else gdb will not be able to display it. */
14480 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
14481 plus_constant (addr_mode
, XEXP (rtl
, 0),
14485 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
14486 and will have been substituted directly into all expressions that use it.
14487 C does not have such a concept, but C++ and other languages do. */
14488 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
14489 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
14492 rtl
= targetm
.delegitimize_address (rtl
);
14494 /* If we don't look past the constant pool, we risk emitting a
14495 reference to a constant pool entry that isn't referenced from
14496 code, and thus is not emitted. */
14498 rtl
= avoid_constant_pool_reference (rtl
);
14500 /* Try harder to get a rtl. If this symbol ends up not being emitted
14501 in the current CU, resolve_addr will remove the expression referencing
14503 if (rtl
== NULL_RTX
14504 && TREE_CODE (decl
) == VAR_DECL
14505 && !DECL_EXTERNAL (decl
)
14506 && TREE_STATIC (decl
)
14507 && DECL_NAME (decl
)
14508 && !DECL_HARD_REGISTER (decl
)
14509 && DECL_MODE (decl
) != VOIDmode
)
14511 rtl
= make_decl_rtl_for_debug (decl
);
14513 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
14514 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
14521 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
14522 returned. If so, the decl for the COMMON block is returned, and the
14523 value is the offset into the common block for the symbol. */
14526 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
14528 tree val_expr
, cvar
;
14529 enum machine_mode mode
;
14530 HOST_WIDE_INT bitsize
, bitpos
;
14532 int unsignedp
, volatilep
= 0;
14534 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
14535 it does not have a value (the offset into the common area), or if it
14536 is thread local (as opposed to global) then it isn't common, and shouldn't
14537 be handled as such. */
14538 if (TREE_CODE (decl
) != VAR_DECL
14539 || !TREE_STATIC (decl
)
14540 || !DECL_HAS_VALUE_EXPR_P (decl
)
14544 val_expr
= DECL_VALUE_EXPR (decl
);
14545 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
14548 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
14549 &mode
, &unsignedp
, &volatilep
, true);
14551 if (cvar
== NULL_TREE
14552 || TREE_CODE (cvar
) != VAR_DECL
14553 || DECL_ARTIFICIAL (cvar
)
14554 || !TREE_PUBLIC (cvar
))
14558 if (offset
!= NULL
)
14560 if (!host_integerp (offset
, 0))
14562 *value
= tree_low_cst (offset
, 0);
14565 *value
+= bitpos
/ BITS_PER_UNIT
;
14570 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
14571 data attribute for a variable or a parameter. We generate the
14572 DW_AT_const_value attribute only in those cases where the given variable
14573 or parameter does not have a true "location" either in memory or in a
14574 register. This can happen (for example) when a constant is passed as an
14575 actual argument in a call to an inline function. (It's possible that
14576 these things can crop up in other ways also.) Note that one type of
14577 constant value which can be passed into an inlined function is a constant
14578 pointer. This can happen for example if an actual argument in an inlined
14579 function call evaluates to a compile-time constant address.
14581 CACHE_P is true if it is worth caching the location list for DECL,
14582 so that future calls can reuse it rather than regenerate it from scratch.
14583 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
14584 since we will need to refer to them each time the function is inlined. */
14587 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
14588 enum dwarf_attribute attr
)
14591 dw_loc_list_ref list
;
14592 var_loc_list
*loc_list
;
14593 cached_dw_loc_list
*cache
;
14596 if (TREE_CODE (decl
) == ERROR_MARK
)
14599 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
14600 || TREE_CODE (decl
) == RESULT_DECL
);
14602 /* Try to get some constant RTL for this decl, and use that as the value of
14605 rtl
= rtl_for_decl_location (decl
);
14606 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
14607 && add_const_value_attribute (die
, rtl
))
14610 /* See if we have single element location list that is equivalent to
14611 a constant value. That way we are better to use add_const_value_attribute
14612 rather than expanding constant value equivalent. */
14613 loc_list
= lookup_decl_loc (decl
);
14616 && loc_list
->first
->next
== NULL
14617 && NOTE_P (loc_list
->first
->loc
)
14618 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
14619 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
14621 struct var_loc_node
*node
;
14623 node
= loc_list
->first
;
14624 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
14625 if (GET_CODE (rtl
) == EXPR_LIST
)
14626 rtl
= XEXP (rtl
, 0);
14627 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
14628 && add_const_value_attribute (die
, rtl
))
14631 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
14632 list several times. See if we've already cached the contents. */
14634 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
14638 cache
= (cached_dw_loc_list
*)
14639 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
14641 list
= cache
->loc_list
;
14645 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
14646 /* It is usually worth caching this result if the decl is from
14647 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
14648 if (cache_p
&& list
&& list
->dw_loc_next
)
14650 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
14651 DECL_UID (decl
), INSERT
);
14652 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
14653 cache
->decl_id
= DECL_UID (decl
);
14654 cache
->loc_list
= list
;
14660 add_AT_location_description (die
, attr
, list
);
14663 /* None of that worked, so it must not really have a location;
14664 try adding a constant value attribute from the DECL_INITIAL. */
14665 return tree_add_const_value_attribute_for_decl (die
, decl
);
14668 /* Add VARIABLE and DIE into deferred locations list. */
14671 defer_location (tree variable
, dw_die_ref die
)
14673 deferred_locations entry
;
14674 entry
.variable
= variable
;
14676 VEC_safe_push (deferred_locations
, gc
, deferred_locations_list
, entry
);
14679 /* Helper function for tree_add_const_value_attribute. Natively encode
14680 initializer INIT into an array. Return true if successful. */
14683 native_encode_initializer (tree init
, unsigned char *array
, int size
)
14687 if (init
== NULL_TREE
)
14691 switch (TREE_CODE (init
))
14694 type
= TREE_TYPE (init
);
14695 if (TREE_CODE (type
) == ARRAY_TYPE
)
14697 tree enttype
= TREE_TYPE (type
);
14698 enum machine_mode mode
= TYPE_MODE (enttype
);
14700 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
14702 if (int_size_in_bytes (type
) != size
)
14704 if (size
> TREE_STRING_LENGTH (init
))
14706 memcpy (array
, TREE_STRING_POINTER (init
),
14707 TREE_STRING_LENGTH (init
));
14708 memset (array
+ TREE_STRING_LENGTH (init
),
14709 '\0', size
- TREE_STRING_LENGTH (init
));
14712 memcpy (array
, TREE_STRING_POINTER (init
), size
);
14717 type
= TREE_TYPE (init
);
14718 if (int_size_in_bytes (type
) != size
)
14720 if (TREE_CODE (type
) == ARRAY_TYPE
)
14722 HOST_WIDE_INT min_index
;
14723 unsigned HOST_WIDE_INT cnt
;
14724 int curpos
= 0, fieldsize
;
14725 constructor_elt
*ce
;
14727 if (TYPE_DOMAIN (type
) == NULL_TREE
14728 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
14731 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
14732 if (fieldsize
<= 0)
14735 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
14736 memset (array
, '\0', size
);
14737 FOR_EACH_VEC_ELT (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
)
14739 tree val
= ce
->value
;
14740 tree index
= ce
->index
;
14742 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
14743 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
14746 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
14751 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
14754 curpos
= pos
+ fieldsize
;
14755 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
14757 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
14758 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
14759 while (count
-- > 0)
14762 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
14763 curpos
+= fieldsize
;
14766 gcc_assert (curpos
<= size
);
14770 else if (TREE_CODE (type
) == RECORD_TYPE
14771 || TREE_CODE (type
) == UNION_TYPE
)
14773 tree field
= NULL_TREE
;
14774 unsigned HOST_WIDE_INT cnt
;
14775 constructor_elt
*ce
;
14777 if (int_size_in_bytes (type
) != size
)
14780 if (TREE_CODE (type
) == RECORD_TYPE
)
14781 field
= TYPE_FIELDS (type
);
14783 FOR_EACH_VEC_ELT (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
)
14785 tree val
= ce
->value
;
14786 int pos
, fieldsize
;
14788 if (ce
->index
!= 0)
14794 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
14797 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
14798 && TYPE_DOMAIN (TREE_TYPE (field
))
14799 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
14801 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
14802 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
14804 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
14805 pos
= int_byte_position (field
);
14806 gcc_assert (pos
+ fieldsize
<= size
);
14808 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
14814 case VIEW_CONVERT_EXPR
:
14815 case NON_LVALUE_EXPR
:
14816 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
14818 return native_encode_expr (init
, array
, size
) == size
;
14822 /* Attach a DW_AT_const_value attribute to DIE. The value of the
14823 attribute is the const value T. */
14826 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
14829 tree type
= TREE_TYPE (t
);
14832 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
14836 gcc_assert (!DECL_P (init
));
14838 rtl
= rtl_for_decl_init (init
, type
);
14840 return add_const_value_attribute (die
, rtl
);
14841 /* If the host and target are sane, try harder. */
14842 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
14843 && initializer_constant_valid_p (init
, type
))
14845 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
14846 if (size
> 0 && (int) size
== size
)
14848 unsigned char *array
= (unsigned char *)
14849 ggc_alloc_cleared_atomic (size
);
14851 if (native_encode_initializer (init
, array
, size
))
14853 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
14861 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
14862 attribute is the const value of T, where T is an integral constant
14863 variable with static storage duration
14864 (so it can't be a PARM_DECL or a RESULT_DECL). */
14867 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
14871 || (TREE_CODE (decl
) != VAR_DECL
14872 && TREE_CODE (decl
) != CONST_DECL
)
14873 || (TREE_CODE (decl
) == VAR_DECL
14874 && !TREE_STATIC (decl
)))
14877 if (TREE_READONLY (decl
)
14878 && ! TREE_THIS_VOLATILE (decl
)
14879 && DECL_INITIAL (decl
))
14884 /* Don't add DW_AT_const_value if abstract origin already has one. */
14885 if (get_AT (var_die
, DW_AT_const_value
))
14888 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
14891 /* Convert the CFI instructions for the current function into a
14892 location list. This is used for DW_AT_frame_base when we targeting
14893 a dwarf2 consumer that does not support the dwarf3
14894 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
14897 static dw_loc_list_ref
14898 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
14902 dw_loc_list_ref list
, *list_tail
;
14904 dw_cfa_location last_cfa
, next_cfa
;
14905 const char *start_label
, *last_label
, *section
;
14906 dw_cfa_location remember
;
14909 gcc_assert (fde
!= NULL
);
14911 section
= secname_for_decl (current_function_decl
);
14915 memset (&next_cfa
, 0, sizeof (next_cfa
));
14916 next_cfa
.reg
= INVALID_REGNUM
;
14917 remember
= next_cfa
;
14919 start_label
= fde
->dw_fde_begin
;
14921 /* ??? Bald assumption that the CIE opcode list does not contain
14922 advance opcodes. */
14923 FOR_EACH_VEC_ELT (dw_cfi_ref
, cie_cfi_vec
, ix
, cfi
)
14924 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
14926 last_cfa
= next_cfa
;
14927 last_label
= start_label
;
14929 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
14931 /* If the first partition contained no CFI adjustments, the
14932 CIE opcodes apply to the whole first partition. */
14933 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
14934 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
14935 list_tail
=&(*list_tail
)->dw_loc_next
;
14936 start_label
= last_label
= fde
->dw_fde_second_begin
;
14939 FOR_EACH_VEC_ELT (dw_cfi_ref
, fde
->dw_fde_cfi
, ix
, cfi
)
14941 switch (cfi
->dw_cfi_opc
)
14943 case DW_CFA_set_loc
:
14944 case DW_CFA_advance_loc1
:
14945 case DW_CFA_advance_loc2
:
14946 case DW_CFA_advance_loc4
:
14947 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
14949 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
14950 start_label
, last_label
, section
);
14952 list_tail
= &(*list_tail
)->dw_loc_next
;
14953 last_cfa
= next_cfa
;
14954 start_label
= last_label
;
14956 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
14959 case DW_CFA_advance_loc
:
14960 /* The encoding is complex enough that we should never emit this. */
14961 gcc_unreachable ();
14964 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
14967 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
14969 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
14971 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
14972 start_label
, last_label
, section
);
14974 list_tail
= &(*list_tail
)->dw_loc_next
;
14975 last_cfa
= next_cfa
;
14976 start_label
= last_label
;
14978 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
14979 start_label
, fde
->dw_fde_end
, section
);
14980 list_tail
= &(*list_tail
)->dw_loc_next
;
14981 start_label
= last_label
= fde
->dw_fde_second_begin
;
14985 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
14987 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
14988 start_label
, last_label
, section
);
14989 list_tail
= &(*list_tail
)->dw_loc_next
;
14990 start_label
= last_label
;
14993 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
14995 fde
->dw_fde_second_begin
14996 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
14999 if (list
&& list
->dw_loc_next
)
15005 /* Compute a displacement from the "steady-state frame pointer" to the
15006 frame base (often the same as the CFA), and store it in
15007 frame_pointer_fb_offset. OFFSET is added to the displacement
15008 before the latter is negated. */
15011 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
15015 #ifdef FRAME_POINTER_CFA_OFFSET
15016 reg
= frame_pointer_rtx
;
15017 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
15019 reg
= arg_pointer_rtx
;
15020 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
15023 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
15024 if (GET_CODE (elim
) == PLUS
)
15026 offset
+= INTVAL (XEXP (elim
, 1));
15027 elim
= XEXP (elim
, 0);
15030 frame_pointer_fb_offset
= -offset
;
15032 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15033 in which to eliminate. This is because it's stack pointer isn't
15034 directly accessible as a register within the ISA. To work around
15035 this, assume that while we cannot provide a proper value for
15036 frame_pointer_fb_offset, we won't need one either. */
15037 frame_pointer_fb_offset_valid
15038 = ((SUPPORTS_STACK_ALIGNMENT
15039 && (elim
== hard_frame_pointer_rtx
15040 || elim
== stack_pointer_rtx
))
15041 || elim
== (frame_pointer_needed
15042 ? hard_frame_pointer_rtx
15043 : stack_pointer_rtx
));
15046 /* Generate a DW_AT_name attribute given some string value to be included as
15047 the value of the attribute. */
15050 add_name_attribute (dw_die_ref die
, const char *name_string
)
15052 if (name_string
!= NULL
&& *name_string
!= 0)
15054 if (demangle_name_func
)
15055 name_string
= (*demangle_name_func
) (name_string
);
15057 add_AT_string (die
, DW_AT_name
, name_string
);
15061 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
15062 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
15063 of TYPE accordingly.
15065 ??? This is a temporary measure until after we're able to generate
15066 regular DWARF for the complex Ada type system. */
15069 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
15070 dw_die_ref context_die
)
15073 dw_die_ref dtype_die
;
15075 if (!lang_hooks
.types
.descriptive_type
)
15078 dtype
= lang_hooks
.types
.descriptive_type (type
);
15082 dtype_die
= lookup_type_die (dtype
);
15085 gen_type_die (dtype
, context_die
);
15086 dtype_die
= lookup_type_die (dtype
);
15087 gcc_assert (dtype_die
);
15090 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
15093 /* Generate a DW_AT_comp_dir attribute for DIE. */
15096 add_comp_dir_attribute (dw_die_ref die
)
15098 const char *wd
= get_src_pwd ();
15104 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
15108 wdlen
= strlen (wd
);
15109 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
15111 wd1
[wdlen
] = DIR_SEPARATOR
;
15112 wd1
[wdlen
+ 1] = 0;
15116 add_AT_string (die
, DW_AT_comp_dir
, remap_debug_filename (wd
));
15119 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
15123 lower_bound_default (void)
15125 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
15130 case DW_LANG_C_plus_plus
:
15132 case DW_LANG_ObjC_plus_plus
:
15135 case DW_LANG_Fortran77
:
15136 case DW_LANG_Fortran90
:
15137 case DW_LANG_Fortran95
:
15141 case DW_LANG_Python
:
15142 return dwarf_version
>= 4 ? 0 : -1;
15143 case DW_LANG_Ada95
:
15144 case DW_LANG_Ada83
:
15145 case DW_LANG_Cobol74
:
15146 case DW_LANG_Cobol85
:
15147 case DW_LANG_Pascal83
:
15148 case DW_LANG_Modula2
:
15150 return dwarf_version
>= 4 ? 1 : -1;
15156 /* Given a tree node describing an array bound (either lower or upper) output
15157 a representation for that bound. */
15160 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
15162 switch (TREE_CODE (bound
))
15167 /* All fixed-bounds are represented by INTEGER_CST nodes. */
15170 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
15173 /* Use the default if possible. */
15174 if (bound_attr
== DW_AT_lower_bound
15175 && host_integerp (bound
, 0)
15176 && (dflt
= lower_bound_default ()) != -1
15177 && tree_low_cst (bound
, 0) == dflt
)
15180 /* Otherwise represent the bound as an unsigned value with the
15181 precision of its type. The precision and signedness of the
15182 type will be necessary to re-interpret it unambiguously. */
15183 else if (prec
< HOST_BITS_PER_WIDE_INT
)
15185 unsigned HOST_WIDE_INT mask
15186 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
15187 add_AT_unsigned (subrange_die
, bound_attr
,
15188 TREE_INT_CST_LOW (bound
) & mask
);
15190 else if (prec
== HOST_BITS_PER_WIDE_INT
15191 || TREE_INT_CST_HIGH (bound
) == 0)
15192 add_AT_unsigned (subrange_die
, bound_attr
,
15193 TREE_INT_CST_LOW (bound
));
15195 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
15196 TREE_INT_CST_LOW (bound
));
15201 case VIEW_CONVERT_EXPR
:
15202 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
15212 dw_die_ref decl_die
= lookup_decl_die (bound
);
15214 /* ??? Can this happen, or should the variable have been bound
15215 first? Probably it can, since I imagine that we try to create
15216 the types of parameters in the order in which they exist in
15217 the list, and won't have created a forward reference to a
15218 later parameter. */
15219 if (decl_die
!= NULL
)
15221 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
15229 /* Otherwise try to create a stack operation procedure to
15230 evaluate the value of the array bound. */
15232 dw_die_ref ctx
, decl_die
;
15233 dw_loc_list_ref list
;
15235 list
= loc_list_from_tree (bound
, 2);
15236 if (list
== NULL
|| single_element_loc_list_p (list
))
15238 /* If DW_AT_*bound is not a reference nor constant, it is
15239 a DWARF expression rather than location description.
15240 For that loc_list_from_tree (bound, 0) is needed.
15241 If that fails to give a single element list,
15242 fall back to outputting this as a reference anyway. */
15243 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
15244 if (list2
&& single_element_loc_list_p (list2
))
15246 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
15253 if (current_function_decl
== 0)
15254 ctx
= comp_unit_die ();
15256 ctx
= lookup_decl_die (current_function_decl
);
15258 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
15259 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
15260 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
15261 add_AT_location_description (decl_die
, DW_AT_location
, list
);
15262 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
15268 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
15269 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
15270 Note that the block of subscript information for an array type also
15271 includes information about the element type of the given array type. */
15274 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
15276 unsigned dimension_number
;
15278 dw_die_ref subrange_die
;
15280 for (dimension_number
= 0;
15281 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
15282 type
= TREE_TYPE (type
), dimension_number
++)
15284 tree domain
= TYPE_DOMAIN (type
);
15286 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
15289 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
15290 and (in GNU C only) variable bounds. Handle all three forms
15292 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
15295 /* We have an array type with specified bounds. */
15296 lower
= TYPE_MIN_VALUE (domain
);
15297 upper
= TYPE_MAX_VALUE (domain
);
15299 /* Define the index type. */
15300 if (TREE_TYPE (domain
))
15302 /* ??? This is probably an Ada unnamed subrange type. Ignore the
15303 TREE_TYPE field. We can't emit debug info for this
15304 because it is an unnamed integral type. */
15305 if (TREE_CODE (domain
) == INTEGER_TYPE
15306 && TYPE_NAME (domain
) == NULL_TREE
15307 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
15308 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
15311 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
15315 /* ??? If upper is NULL, the array has unspecified length,
15316 but it does have a lower bound. This happens with Fortran
15318 Since the debugger is definitely going to need to know N
15319 to produce useful results, go ahead and output the lower
15320 bound solo, and hope the debugger can cope. */
15322 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
15324 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
15327 /* Otherwise we have an array type with an unspecified length. The
15328 DWARF-2 spec does not say how to handle this; let's just leave out the
15334 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
15336 dw_die_ref decl_die
;
15339 switch (TREE_CODE (tree_node
))
15344 case ENUMERAL_TYPE
:
15347 case QUAL_UNION_TYPE
:
15348 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
15349 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
15351 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
15354 size
= int_size_in_bytes (tree_node
);
15357 /* For a data member of a struct or union, the DW_AT_byte_size is
15358 generally given as the number of bytes normally allocated for an
15359 object of the *declared* type of the member itself. This is true
15360 even for bit-fields. */
15361 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
15364 gcc_unreachable ();
15367 /* Note that `size' might be -1 when we get to this point. If it is, that
15368 indicates that the byte size of the entity in question is variable. We
15369 have no good way of expressing this fact in Dwarf at the present time,
15370 so just let the -1 pass on through. */
15371 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
15374 /* For a FIELD_DECL node which represents a bit-field, output an attribute
15375 which specifies the distance in bits from the highest order bit of the
15376 "containing object" for the bit-field to the highest order bit of the
15379 For any given bit-field, the "containing object" is a hypothetical object
15380 (of some integral or enum type) within which the given bit-field lives. The
15381 type of this hypothetical "containing object" is always the same as the
15382 declared type of the individual bit-field itself. The determination of the
15383 exact location of the "containing object" for a bit-field is rather
15384 complicated. It's handled by the `field_byte_offset' function (above).
15386 Note that it is the size (in bytes) of the hypothetical "containing object"
15387 which will be given in the DW_AT_byte_size attribute for this bit-field.
15388 (See `byte_size_attribute' above). */
15391 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
15393 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
15394 tree type
= DECL_BIT_FIELD_TYPE (decl
);
15395 HOST_WIDE_INT bitpos_int
;
15396 HOST_WIDE_INT highest_order_object_bit_offset
;
15397 HOST_WIDE_INT highest_order_field_bit_offset
;
15398 HOST_WIDE_INT bit_offset
;
15400 /* Must be a field and a bit field. */
15401 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
15403 /* We can't yet handle bit-fields whose offsets are variable, so if we
15404 encounter such things, just return without generating any attribute
15405 whatsoever. Likewise for variable or too large size. */
15406 if (! host_integerp (bit_position (decl
), 0)
15407 || ! host_integerp (DECL_SIZE (decl
), 1))
15410 bitpos_int
= int_bit_position (decl
);
15412 /* Note that the bit offset is always the distance (in bits) from the
15413 highest-order bit of the "containing object" to the highest-order bit of
15414 the bit-field itself. Since the "high-order end" of any object or field
15415 is different on big-endian and little-endian machines, the computation
15416 below must take account of these differences. */
15417 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
15418 highest_order_field_bit_offset
= bitpos_int
;
15420 if (! BYTES_BIG_ENDIAN
)
15422 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
15423 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
15427 = (! BYTES_BIG_ENDIAN
15428 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
15429 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
15431 if (bit_offset
< 0)
15432 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
15434 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
15437 /* For a FIELD_DECL node which represents a bit field, output an attribute
15438 which specifies the length in bits of the given field. */
15441 add_bit_size_attribute (dw_die_ref die
, tree decl
)
15443 /* Must be a field and a bit field. */
15444 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
15445 && DECL_BIT_FIELD_TYPE (decl
));
15447 if (host_integerp (DECL_SIZE (decl
), 1))
15448 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
15451 /* If the compiled language is ANSI C, then add a 'prototyped'
15452 attribute, if arg types are given for the parameters of a function. */
15455 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
15457 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
15458 && prototype_p (func_type
))
15459 add_AT_flag (die
, DW_AT_prototyped
, 1);
15462 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
15463 by looking in either the type declaration or object declaration
15466 static inline dw_die_ref
15467 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
15469 dw_die_ref origin_die
= NULL
;
15471 if (TREE_CODE (origin
) != FUNCTION_DECL
)
15473 /* We may have gotten separated from the block for the inlined
15474 function, if we're in an exception handler or some such; make
15475 sure that the abstract function has been written out.
15477 Doing this for nested functions is wrong, however; functions are
15478 distinct units, and our context might not even be inline. */
15482 fn
= TYPE_STUB_DECL (fn
);
15484 fn
= decl_function_context (fn
);
15486 dwarf2out_abstract_function (fn
);
15489 if (DECL_P (origin
))
15490 origin_die
= lookup_decl_die (origin
);
15491 else if (TYPE_P (origin
))
15492 origin_die
= lookup_type_die (origin
);
15494 /* XXX: Functions that are never lowered don't always have correct block
15495 trees (in the case of java, they simply have no block tree, in some other
15496 languages). For these functions, there is nothing we can really do to
15497 output correct debug info for inlined functions in all cases. Rather
15498 than die, we'll just produce deficient debug info now, in that we will
15499 have variables without a proper abstract origin. In the future, when all
15500 functions are lowered, we should re-add a gcc_assert (origin_die)
15504 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
15508 /* We do not currently support the pure_virtual attribute. */
15511 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
15513 if (DECL_VINDEX (func_decl
))
15515 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
15517 if (host_integerp (DECL_VINDEX (func_decl
), 0))
15518 add_AT_loc (die
, DW_AT_vtable_elem_location
,
15519 new_loc_descr (DW_OP_constu
,
15520 tree_low_cst (DECL_VINDEX (func_decl
), 0),
15523 /* GNU extension: Record what type this method came from originally. */
15524 if (debug_info_level
> DINFO_LEVEL_TERSE
15525 && DECL_CONTEXT (func_decl
))
15526 add_AT_die_ref (die
, DW_AT_containing_type
,
15527 lookup_type_die (DECL_CONTEXT (func_decl
)));
15531 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
15532 given decl. This used to be a vendor extension until after DWARF 4
15533 standardized it. */
15536 add_linkage_attr (dw_die_ref die
, tree decl
)
15538 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
15540 /* Mimic what assemble_name_raw does with a leading '*'. */
15541 if (name
[0] == '*')
15544 if (dwarf_version
>= 4)
15545 add_AT_string (die
, DW_AT_linkage_name
, name
);
15547 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
15550 /* Add source coordinate attributes for the given decl. */
15553 add_src_coords_attributes (dw_die_ref die
, tree decl
)
15555 expanded_location s
;
15557 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
15559 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
15560 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
15561 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
15564 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
15567 add_linkage_name (dw_die_ref die
, tree decl
)
15569 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
15570 && TREE_PUBLIC (decl
)
15571 && !DECL_ABSTRACT (decl
)
15572 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
15573 && die
->die_tag
!= DW_TAG_member
)
15575 /* Defer until we have an assembler name set. */
15576 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
15578 limbo_die_node
*asm_name
;
15580 asm_name
= ggc_alloc_cleared_limbo_die_node ();
15581 asm_name
->die
= die
;
15582 asm_name
->created_for
= decl
;
15583 asm_name
->next
= deferred_asm_name
;
15584 deferred_asm_name
= asm_name
;
15586 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
15587 add_linkage_attr (die
, decl
);
15591 /* Add a DW_AT_name attribute and source coordinate attribute for the
15592 given decl, but only if it actually has a name. */
15595 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
15599 decl_name
= DECL_NAME (decl
);
15600 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
15602 const char *name
= dwarf2_name (decl
, 0);
15604 add_name_attribute (die
, name
);
15605 if (! DECL_ARTIFICIAL (decl
))
15606 add_src_coords_attributes (die
, decl
);
15608 add_linkage_name (die
, decl
);
15611 #ifdef VMS_DEBUGGING_INFO
15612 /* Get the function's name, as described by its RTL. This may be different
15613 from the DECL_NAME name used in the source file. */
15614 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
15616 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
15617 XEXP (DECL_RTL (decl
), 0));
15618 VEC_safe_push (rtx
, gc
, used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
15620 #endif /* VMS_DEBUGGING_INFO */
15623 #ifdef VMS_DEBUGGING_INFO
15624 /* Output the debug main pointer die for VMS */
15627 dwarf2out_vms_debug_main_pointer (void)
15629 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
15632 /* Allocate the VMS debug main subprogram die. */
15633 die
= ggc_alloc_cleared_die_node ();
15634 die
->die_tag
= DW_TAG_subprogram
;
15635 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
15636 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
15637 current_function_funcdef_no
);
15638 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
15640 /* Make it the first child of comp_unit_die (). */
15641 die
->die_parent
= comp_unit_die ();
15642 if (comp_unit_die ()->die_child
)
15644 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
15645 comp_unit_die ()->die_child
->die_sib
= die
;
15649 die
->die_sib
= die
;
15650 comp_unit_die ()->die_child
= die
;
15653 #endif /* VMS_DEBUGGING_INFO */
15655 /* Push a new declaration scope. */
15658 push_decl_scope (tree scope
)
15660 VEC_safe_push (tree
, gc
, decl_scope_table
, scope
);
15663 /* Pop a declaration scope. */
15666 pop_decl_scope (void)
15668 VEC_pop (tree
, decl_scope_table
);
15671 /* walk_tree helper function for uses_local_type, below. */
15674 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
15677 *walk_subtrees
= 0;
15680 tree name
= TYPE_NAME (*tp
);
15681 if (name
&& DECL_P (name
) && decl_function_context (name
))
15687 /* If TYPE involves a function-local type (including a local typedef to a
15688 non-local type), returns that type; otherwise returns NULL_TREE. */
15691 uses_local_type (tree type
)
15693 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
15697 /* Return the DIE for the scope that immediately contains this type.
15698 Non-named types that do not involve a function-local type get global
15699 scope. Named types nested in namespaces or other types get their
15700 containing scope. All other types (i.e. function-local named types) get
15701 the current active scope. */
15704 scope_die_for (tree t
, dw_die_ref context_die
)
15706 dw_die_ref scope_die
= NULL
;
15707 tree containing_scope
;
15709 /* Non-types always go in the current scope. */
15710 gcc_assert (TYPE_P (t
));
15712 /* Use the scope of the typedef, rather than the scope of the type
15714 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
15715 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
15717 containing_scope
= TYPE_CONTEXT (t
);
15719 /* Use the containing namespace if there is one. */
15720 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
15722 if (context_die
== lookup_decl_die (containing_scope
))
15724 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
15725 context_die
= get_context_die (containing_scope
);
15727 containing_scope
= NULL_TREE
;
15730 /* Ignore function type "scopes" from the C frontend. They mean that
15731 a tagged type is local to a parmlist of a function declarator, but
15732 that isn't useful to DWARF. */
15733 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
15734 containing_scope
= NULL_TREE
;
15736 if (SCOPE_FILE_SCOPE_P (containing_scope
))
15738 /* If T uses a local type keep it local as well, to avoid references
15739 to function-local DIEs from outside the function. */
15740 if (current_function_decl
&& uses_local_type (t
))
15741 scope_die
= context_die
;
15743 scope_die
= comp_unit_die ();
15745 else if (TYPE_P (containing_scope
))
15747 /* For types, we can just look up the appropriate DIE. */
15748 if (debug_info_level
> DINFO_LEVEL_TERSE
)
15749 scope_die
= get_context_die (containing_scope
);
15752 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
15753 if (scope_die
== NULL
)
15754 scope_die
= comp_unit_die ();
15758 scope_die
= context_die
;
15763 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
15766 local_scope_p (dw_die_ref context_die
)
15768 for (; context_die
; context_die
= context_die
->die_parent
)
15769 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
15770 || context_die
->die_tag
== DW_TAG_subprogram
)
15776 /* Returns nonzero if CONTEXT_DIE is a class. */
15779 class_scope_p (dw_die_ref context_die
)
15781 return (context_die
15782 && (context_die
->die_tag
== DW_TAG_structure_type
15783 || context_die
->die_tag
== DW_TAG_class_type
15784 || context_die
->die_tag
== DW_TAG_interface_type
15785 || context_die
->die_tag
== DW_TAG_union_type
));
15788 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
15789 whether or not to treat a DIE in this context as a declaration. */
15792 class_or_namespace_scope_p (dw_die_ref context_die
)
15794 return (class_scope_p (context_die
)
15795 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
15798 /* Many forms of DIEs require a "type description" attribute. This
15799 routine locates the proper "type descriptor" die for the type given
15800 by 'type', and adds a DW_AT_type attribute below the given die. */
15803 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
15804 int decl_volatile
, dw_die_ref context_die
)
15806 enum tree_code code
= TREE_CODE (type
);
15807 dw_die_ref type_die
= NULL
;
15809 /* ??? If this type is an unnamed subrange type of an integral, floating-point
15810 or fixed-point type, use the inner type. This is because we have no
15811 support for unnamed types in base_type_die. This can happen if this is
15812 an Ada subrange type. Correct solution is emit a subrange type die. */
15813 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
15814 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
15815 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
15817 if (code
== ERROR_MARK
15818 /* Handle a special case. For functions whose return type is void, we
15819 generate *no* type attribute. (Note that no object may have type
15820 `void', so this only applies to function return types). */
15821 || code
== VOID_TYPE
)
15824 type_die
= modified_type_die (type
,
15825 decl_const
|| TYPE_READONLY (type
),
15826 decl_volatile
|| TYPE_VOLATILE (type
),
15829 if (type_die
!= NULL
)
15830 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
15833 /* Given an object die, add the calling convention attribute for the
15834 function call type. */
15836 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
15838 enum dwarf_calling_convention value
= DW_CC_normal
;
15840 value
= ((enum dwarf_calling_convention
)
15841 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
15844 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
15846 /* DWARF 2 doesn't provide a way to identify a program's source-level
15847 entry point. DW_AT_calling_convention attributes are only meant
15848 to describe functions' calling conventions. However, lacking a
15849 better way to signal the Fortran main program, we used this for
15850 a long time, following existing custom. Now, DWARF 4 has
15851 DW_AT_main_subprogram, which we add below, but some tools still
15852 rely on the old way, which we thus keep. */
15853 value
= DW_CC_program
;
15855 if (dwarf_version
>= 4 || !dwarf_strict
)
15856 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
15859 /* Only add the attribute if the backend requests it, and
15860 is not DW_CC_normal. */
15861 if (value
&& (value
!= DW_CC_normal
))
15862 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
15865 /* Given a tree pointer to a struct, class, union, or enum type node, return
15866 a pointer to the (string) tag name for the given type, or zero if the type
15867 was declared without a tag. */
15869 static const char *
15870 type_tag (const_tree type
)
15872 const char *name
= 0;
15874 if (TYPE_NAME (type
) != 0)
15878 /* Find the IDENTIFIER_NODE for the type name. */
15879 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
15880 && !TYPE_NAMELESS (type
))
15881 t
= TYPE_NAME (type
);
15883 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
15884 a TYPE_DECL node, regardless of whether or not a `typedef' was
15886 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
15887 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
15889 /* We want to be extra verbose. Don't call dwarf_name if
15890 DECL_NAME isn't set. The default hook for decl_printable_name
15891 doesn't like that, and in this context it's correct to return
15892 0, instead of "<anonymous>" or the like. */
15893 if (DECL_NAME (TYPE_NAME (type
))
15894 && !DECL_NAMELESS (TYPE_NAME (type
)))
15895 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
15898 /* Now get the name as a string, or invent one. */
15899 if (!name
&& t
!= 0)
15900 name
= IDENTIFIER_POINTER (t
);
15903 return (name
== 0 || *name
== '\0') ? 0 : name
;
15906 /* Return the type associated with a data member, make a special check
15907 for bit field types. */
15910 member_declared_type (const_tree member
)
15912 return (DECL_BIT_FIELD_TYPE (member
)
15913 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
15916 /* Get the decl's label, as described by its RTL. This may be different
15917 from the DECL_NAME name used in the source file. */
15920 static const char *
15921 decl_start_label (tree decl
)
15924 const char *fnname
;
15926 x
= DECL_RTL (decl
);
15927 gcc_assert (MEM_P (x
));
15930 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
15932 fnname
= XSTR (x
, 0);
15937 /* These routines generate the internal representation of the DIE's for
15938 the compilation unit. Debugging information is collected by walking
15939 the declaration trees passed in from dwarf2out_decl(). */
15942 gen_array_type_die (tree type
, dw_die_ref context_die
)
15944 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
15945 dw_die_ref array_die
;
15947 /* GNU compilers represent multidimensional array types as sequences of one
15948 dimensional array types whose element types are themselves array types.
15949 We sometimes squish that down to a single array_type DIE with multiple
15950 subscripts in the Dwarf debugging info. The draft Dwarf specification
15951 say that we are allowed to do this kind of compression in C, because
15952 there is no difference between an array of arrays and a multidimensional
15953 array. We don't do this for Ada to remain as close as possible to the
15954 actual representation, which is especially important against the language
15955 flexibilty wrt arrays of variable size. */
15957 bool collapse_nested_arrays
= !is_ada ();
15960 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
15961 DW_TAG_string_type doesn't have DW_AT_type attribute). */
15962 if (TYPE_STRING_FLAG (type
)
15963 && TREE_CODE (type
) == ARRAY_TYPE
15965 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
15967 HOST_WIDE_INT size
;
15969 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
15970 add_name_attribute (array_die
, type_tag (type
));
15971 equate_type_number_to_die (type
, array_die
);
15972 size
= int_size_in_bytes (type
);
15974 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
15975 else if (TYPE_DOMAIN (type
) != NULL_TREE
15976 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
15977 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
15979 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
15980 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
15982 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
15983 if (loc
&& size
> 0)
15985 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
15986 if (size
!= DWARF2_ADDR_SIZE
)
15987 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
15993 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
15994 add_name_attribute (array_die
, type_tag (type
));
15995 equate_type_number_to_die (type
, array_die
);
15997 if (TREE_CODE (type
) == VECTOR_TYPE
)
15998 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
16000 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16002 && TREE_CODE (type
) == ARRAY_TYPE
16003 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
16004 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
16005 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16008 /* We default the array ordering. SDB will probably do
16009 the right things even if DW_AT_ordering is not present. It's not even
16010 an issue until we start to get into multidimensional arrays anyway. If
16011 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16012 then we'll have to put the DW_AT_ordering attribute back in. (But if
16013 and when we find out that we need to put these in, we will only do so
16014 for multidimensional arrays. */
16015 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
16018 if (TREE_CODE (type
) == VECTOR_TYPE
)
16020 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
16021 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16022 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
16023 add_bound_info (subrange_die
, DW_AT_upper_bound
,
16024 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
16027 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
16029 /* Add representation of the type of the elements of this array type and
16030 emit the corresponding DIE if we haven't done it already. */
16031 element_type
= TREE_TYPE (type
);
16032 if (collapse_nested_arrays
)
16033 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
16035 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
16037 element_type
= TREE_TYPE (element_type
);
16040 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
16042 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
16043 if (TYPE_ARTIFICIAL (type
))
16044 add_AT_flag (array_die
, DW_AT_artificial
, 1);
16046 if (get_AT (array_die
, DW_AT_name
))
16047 add_pubtype (type
, array_die
);
16050 static dw_loc_descr_ref
16051 descr_info_loc (tree val
, tree base_decl
)
16053 HOST_WIDE_INT size
;
16054 dw_loc_descr_ref loc
, loc2
;
16055 enum dwarf_location_atom op
;
16057 if (val
== base_decl
)
16058 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
16060 switch (TREE_CODE (val
))
16063 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16065 return loc_descriptor_from_tree (val
, 0);
16067 if (host_integerp (val
, 0))
16068 return int_loc_descriptor (tree_low_cst (val
, 0));
16071 size
= int_size_in_bytes (TREE_TYPE (val
));
16074 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16077 if (size
== DWARF2_ADDR_SIZE
)
16078 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
16080 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
16082 case POINTER_PLUS_EXPR
:
16084 if (host_integerp (TREE_OPERAND (val
, 1), 1)
16085 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
16088 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16091 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
16097 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16100 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
16103 add_loc_descr (&loc
, loc2
);
16104 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
16126 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
16127 tree val
, tree base_decl
)
16129 dw_loc_descr_ref loc
;
16131 if (host_integerp (val
, 0))
16133 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
16137 loc
= descr_info_loc (val
, base_decl
);
16141 add_AT_loc (die
, attr
, loc
);
16144 /* This routine generates DIE for array with hidden descriptor, details
16145 are filled into *info by a langhook. */
16148 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
16149 dw_die_ref context_die
)
16151 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16152 dw_die_ref array_die
;
16155 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16156 add_name_attribute (array_die
, type_tag (type
));
16157 equate_type_number_to_die (type
, array_die
);
16159 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16161 && info
->ndimensions
>= 2)
16162 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16164 if (info
->data_location
)
16165 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
16167 if (info
->associated
)
16168 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
16170 if (info
->allocated
)
16171 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
16174 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
16176 dw_die_ref subrange_die
16177 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16179 if (info
->dimen
[dim
].lower_bound
)
16181 /* If it is the default value, omit it. */
16184 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
16185 && (dflt
= lower_bound_default ()) != -1
16186 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
16189 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
16190 info
->dimen
[dim
].lower_bound
,
16193 if (info
->dimen
[dim
].upper_bound
)
16194 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
16195 info
->dimen
[dim
].upper_bound
,
16197 if (info
->dimen
[dim
].stride
)
16198 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
16199 info
->dimen
[dim
].stride
,
16203 gen_type_die (info
->element_type
, context_die
);
16204 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
16206 if (get_AT (array_die
, DW_AT_name
))
16207 add_pubtype (type
, array_die
);
16212 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
16214 tree origin
= decl_ultimate_origin (decl
);
16215 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
16217 if (origin
!= NULL
)
16218 add_abstract_origin_attribute (decl_die
, origin
);
16221 add_name_and_src_coords_attributes (decl_die
, decl
);
16222 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
16223 0, 0, context_die
);
16226 if (DECL_ABSTRACT (decl
))
16227 equate_decl_number_to_die (decl
, decl_die
);
16229 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
16233 /* Walk through the list of incomplete types again, trying once more to
16234 emit full debugging info for them. */
16237 retry_incomplete_types (void)
16241 for (i
= VEC_length (tree
, incomplete_types
) - 1; i
>= 0; i
--)
16242 if (should_emit_struct_debug (VEC_index (tree
, incomplete_types
, i
),
16243 DINFO_USAGE_DIR_USE
))
16244 gen_type_die (VEC_index (tree
, incomplete_types
, i
), comp_unit_die ());
16247 /* Determine what tag to use for a record type. */
16249 static enum dwarf_tag
16250 record_type_tag (tree type
)
16252 if (! lang_hooks
.types
.classify_record
)
16253 return DW_TAG_structure_type
;
16255 switch (lang_hooks
.types
.classify_record (type
))
16257 case RECORD_IS_STRUCT
:
16258 return DW_TAG_structure_type
;
16260 case RECORD_IS_CLASS
:
16261 return DW_TAG_class_type
;
16263 case RECORD_IS_INTERFACE
:
16264 if (dwarf_version
>= 3 || !dwarf_strict
)
16265 return DW_TAG_interface_type
;
16266 return DW_TAG_structure_type
;
16269 gcc_unreachable ();
16273 /* Generate a DIE to represent an enumeration type. Note that these DIEs
16274 include all of the information about the enumeration values also. Each
16275 enumerated type name/value is listed as a child of the enumerated type
16279 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
16281 dw_die_ref type_die
= lookup_type_die (type
);
16283 if (type_die
== NULL
)
16285 type_die
= new_die (DW_TAG_enumeration_type
,
16286 scope_die_for (type
, context_die
), type
);
16287 equate_type_number_to_die (type
, type_die
);
16288 add_name_attribute (type_die
, type_tag (type
));
16289 if (dwarf_version
>= 4 || !dwarf_strict
)
16291 if (ENUM_IS_SCOPED (type
))
16292 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
16293 if (ENUM_IS_OPAQUE (type
))
16294 add_AT_flag (type_die
, DW_AT_declaration
, 1);
16297 else if (! TYPE_SIZE (type
))
16300 remove_AT (type_die
, DW_AT_declaration
);
16302 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
16303 given enum type is incomplete, do not generate the DW_AT_byte_size
16304 attribute or the DW_AT_element_list attribute. */
16305 if (TYPE_SIZE (type
))
16309 TREE_ASM_WRITTEN (type
) = 1;
16310 add_byte_size_attribute (type_die
, type
);
16311 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
16313 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
16314 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
16317 /* If the first reference to this type was as the return type of an
16318 inline function, then it may not have a parent. Fix this now. */
16319 if (type_die
->die_parent
== NULL
)
16320 add_child_die (scope_die_for (type
, context_die
), type_die
);
16322 for (link
= TYPE_VALUES (type
);
16323 link
!= NULL
; link
= TREE_CHAIN (link
))
16325 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
16326 tree value
= TREE_VALUE (link
);
16328 add_name_attribute (enum_die
,
16329 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
16331 if (TREE_CODE (value
) == CONST_DECL
)
16332 value
= DECL_INITIAL (value
);
16334 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
16335 /* DWARF2 does not provide a way of indicating whether or
16336 not enumeration constants are signed or unsigned. GDB
16337 always assumes the values are signed, so we output all
16338 values as if they were signed. That means that
16339 enumeration constants with very large unsigned values
16340 will appear to have negative values in the debugger. */
16341 add_AT_int (enum_die
, DW_AT_const_value
,
16342 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
16345 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
16346 if (TYPE_ARTIFICIAL (type
))
16347 add_AT_flag (type_die
, DW_AT_artificial
, 1);
16350 add_AT_flag (type_die
, DW_AT_declaration
, 1);
16352 add_pubtype (type
, type_die
);
16357 /* Generate a DIE to represent either a real live formal parameter decl or to
16358 represent just the type of some formal parameter position in some function
16361 Note that this routine is a bit unusual because its argument may be a
16362 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
16363 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
16364 node. If it's the former then this function is being called to output a
16365 DIE to represent a formal parameter object (or some inlining thereof). If
16366 it's the latter, then this function is only being called to output a
16367 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
16368 argument type of some subprogram type.
16369 If EMIT_NAME_P is true, name and source coordinate attributes
16373 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
16374 dw_die_ref context_die
)
16376 tree node_or_origin
= node
? node
: origin
;
16377 tree ultimate_origin
;
16378 dw_die_ref parm_die
16379 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
16381 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
16383 case tcc_declaration
:
16384 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
16385 if (node
|| ultimate_origin
)
16386 origin
= ultimate_origin
;
16387 if (origin
!= NULL
)
16388 add_abstract_origin_attribute (parm_die
, origin
);
16389 else if (emit_name_p
)
16390 add_name_and_src_coords_attributes (parm_die
, node
);
16392 || (! DECL_ABSTRACT (node_or_origin
)
16393 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
16394 decl_function_context
16395 (node_or_origin
))))
16397 tree type
= TREE_TYPE (node_or_origin
);
16398 if (decl_by_reference_p (node_or_origin
))
16399 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
16402 add_type_attribute (parm_die
, type
,
16403 TREE_READONLY (node_or_origin
),
16404 TREE_THIS_VOLATILE (node_or_origin
),
16407 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
16408 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
16410 if (node
&& node
!= origin
)
16411 equate_decl_number_to_die (node
, parm_die
);
16412 if (! DECL_ABSTRACT (node_or_origin
))
16413 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
16414 node
== NULL
, DW_AT_location
);
16419 /* We were called with some kind of a ..._TYPE node. */
16420 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
16424 gcc_unreachable ();
16430 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
16431 children DW_TAG_formal_parameter DIEs representing the arguments of the
16434 PARM_PACK must be a function parameter pack.
16435 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
16436 must point to the subsequent arguments of the function PACK_ARG belongs to.
16437 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
16438 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
16439 following the last one for which a DIE was generated. */
16442 gen_formal_parameter_pack_die (tree parm_pack
,
16444 dw_die_ref subr_die
,
16448 dw_die_ref parm_pack_die
;
16450 gcc_assert (parm_pack
16451 && lang_hooks
.function_parameter_pack_p (parm_pack
)
16454 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
16455 add_src_coords_attributes (parm_pack_die
, parm_pack
);
16457 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
16459 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
16462 gen_formal_parameter_die (arg
, NULL
,
16463 false /* Don't emit name attribute. */,
16468 return parm_pack_die
;
16471 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
16472 at the end of an (ANSI prototyped) formal parameters list. */
16475 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
16477 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
16480 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
16481 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
16482 parameters as specified in some function type specification (except for
16483 those which appear as part of a function *definition*). */
16486 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
16489 tree formal_type
= NULL
;
16490 tree first_parm_type
;
16493 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
16495 arg
= DECL_ARGUMENTS (function_or_method_type
);
16496 function_or_method_type
= TREE_TYPE (function_or_method_type
);
16501 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
16503 /* Make our first pass over the list of formal parameter types and output a
16504 DW_TAG_formal_parameter DIE for each one. */
16505 for (link
= first_parm_type
; link
; )
16507 dw_die_ref parm_die
;
16509 formal_type
= TREE_VALUE (link
);
16510 if (formal_type
== void_type_node
)
16513 /* Output a (nameless) DIE to represent the formal parameter itself. */
16514 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
16515 true /* Emit name attribute. */,
16517 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
16518 && link
== first_parm_type
)
16520 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
16521 if (dwarf_version
>= 3 || !dwarf_strict
)
16522 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
16524 else if (arg
&& DECL_ARTIFICIAL (arg
))
16525 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
16527 link
= TREE_CHAIN (link
);
16529 arg
= DECL_CHAIN (arg
);
16532 /* If this function type has an ellipsis, add a
16533 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
16534 if (formal_type
!= void_type_node
)
16535 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
16537 /* Make our second (and final) pass over the list of formal parameter types
16538 and output DIEs to represent those types (as necessary). */
16539 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
16540 link
&& TREE_VALUE (link
);
16541 link
= TREE_CHAIN (link
))
16542 gen_type_die (TREE_VALUE (link
), context_die
);
16545 /* We want to generate the DIE for TYPE so that we can generate the
16546 die for MEMBER, which has been defined; we will need to refer back
16547 to the member declaration nested within TYPE. If we're trying to
16548 generate minimal debug info for TYPE, processing TYPE won't do the
16549 trick; we need to attach the member declaration by hand. */
16552 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
16554 gen_type_die (type
, context_die
);
16556 /* If we're trying to avoid duplicate debug info, we may not have
16557 emitted the member decl for this function. Emit it now. */
16558 if (TYPE_STUB_DECL (type
)
16559 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
16560 && ! lookup_decl_die (member
))
16562 dw_die_ref type_die
;
16563 gcc_assert (!decl_ultimate_origin (member
));
16565 push_decl_scope (type
);
16566 type_die
= lookup_type_die_strip_naming_typedef (type
);
16567 if (TREE_CODE (member
) == FUNCTION_DECL
)
16568 gen_subprogram_die (member
, type_die
);
16569 else if (TREE_CODE (member
) == FIELD_DECL
)
16571 /* Ignore the nameless fields that are used to skip bits but handle
16572 C++ anonymous unions and structs. */
16573 if (DECL_NAME (member
) != NULL_TREE
16574 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
16575 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
16577 gen_type_die (member_declared_type (member
), type_die
);
16578 gen_field_die (member
, type_die
);
16582 gen_variable_die (member
, NULL_TREE
, type_die
);
16588 /* Forward declare these functions, because they are mutually recursive
16589 with their set_block_* pairing functions. */
16590 static void set_decl_origin_self (tree
);
16591 static void set_decl_abstract_flags (tree
, int);
16593 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
16594 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
16595 that it points to the node itself, thus indicating that the node is its
16596 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
16597 the given node is NULL, recursively descend the decl/block tree which
16598 it is the root of, and for each other ..._DECL or BLOCK node contained
16599 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
16600 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
16601 values to point to themselves. */
16604 set_block_origin_self (tree stmt
)
16606 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
16608 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
16613 for (local_decl
= BLOCK_VARS (stmt
);
16614 local_decl
!= NULL_TREE
;
16615 local_decl
= DECL_CHAIN (local_decl
))
16616 if (! DECL_EXTERNAL (local_decl
))
16617 set_decl_origin_self (local_decl
); /* Potential recursion. */
16623 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
16624 subblock
!= NULL_TREE
;
16625 subblock
= BLOCK_CHAIN (subblock
))
16626 set_block_origin_self (subblock
); /* Recurse. */
16631 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
16632 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
16633 node to so that it points to the node itself, thus indicating that the
16634 node represents its own (abstract) origin. Additionally, if the
16635 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
16636 the decl/block tree of which the given node is the root of, and for
16637 each other ..._DECL or BLOCK node contained therein whose
16638 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
16639 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
16640 point to themselves. */
16643 set_decl_origin_self (tree decl
)
16645 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
16647 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
16648 if (TREE_CODE (decl
) == FUNCTION_DECL
)
16652 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
16653 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
16654 if (DECL_INITIAL (decl
) != NULL_TREE
16655 && DECL_INITIAL (decl
) != error_mark_node
)
16656 set_block_origin_self (DECL_INITIAL (decl
));
16661 /* Given a pointer to some BLOCK node, and a boolean value to set the
16662 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
16663 the given block, and for all local decls and all local sub-blocks
16664 (recursively) which are contained therein. */
16667 set_block_abstract_flags (tree stmt
, int setting
)
16673 BLOCK_ABSTRACT (stmt
) = setting
;
16675 for (local_decl
= BLOCK_VARS (stmt
);
16676 local_decl
!= NULL_TREE
;
16677 local_decl
= DECL_CHAIN (local_decl
))
16678 if (! DECL_EXTERNAL (local_decl
))
16679 set_decl_abstract_flags (local_decl
, setting
);
16681 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
16683 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
16684 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
16685 || TREE_CODE (local_decl
) == PARM_DECL
)
16686 set_decl_abstract_flags (local_decl
, setting
);
16689 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
16690 subblock
!= NULL_TREE
;
16691 subblock
= BLOCK_CHAIN (subblock
))
16692 set_block_abstract_flags (subblock
, setting
);
16695 /* Given a pointer to some ..._DECL node, and a boolean value to set the
16696 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
16697 given decl, and (in the case where the decl is a FUNCTION_DECL) also
16698 set the abstract flags for all of the parameters, local vars, local
16699 blocks and sub-blocks (recursively) to the same setting. */
16702 set_decl_abstract_flags (tree decl
, int setting
)
16704 DECL_ABSTRACT (decl
) = setting
;
16705 if (TREE_CODE (decl
) == FUNCTION_DECL
)
16709 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
16710 DECL_ABSTRACT (arg
) = setting
;
16711 if (DECL_INITIAL (decl
) != NULL_TREE
16712 && DECL_INITIAL (decl
) != error_mark_node
)
16713 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
16717 /* Generate the DWARF2 info for the "abstract" instance of a function which we
16718 may later generate inlined and/or out-of-line instances of. */
16721 dwarf2out_abstract_function (tree decl
)
16723 dw_die_ref old_die
;
16727 htab_t old_decl_loc_table
;
16728 htab_t old_cached_dw_loc_list_table
;
16729 int old_call_site_count
, old_tail_call_site_count
;
16730 struct call_arg_loc_node
*old_call_arg_locations
;
16732 /* Make sure we have the actual abstract inline, not a clone. */
16733 decl
= DECL_ORIGIN (decl
);
16735 old_die
= lookup_decl_die (decl
);
16736 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
16737 /* We've already generated the abstract instance. */
16740 /* We can be called while recursively when seeing block defining inlined subroutine
16741 DIE. Be sure to not clobber the outer location table nor use it or we would
16742 get locations in abstract instantces. */
16743 old_decl_loc_table
= decl_loc_table
;
16744 decl_loc_table
= NULL
;
16745 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
16746 cached_dw_loc_list_table
= NULL
;
16747 old_call_arg_locations
= call_arg_locations
;
16748 call_arg_locations
= NULL
;
16749 old_call_site_count
= call_site_count
;
16750 call_site_count
= -1;
16751 old_tail_call_site_count
= tail_call_site_count
;
16752 tail_call_site_count
= -1;
16754 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
16755 we don't get confused by DECL_ABSTRACT. */
16756 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16758 context
= decl_class_context (decl
);
16760 gen_type_die_for_member
16761 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
16764 /* Pretend we've just finished compiling this function. */
16765 save_fn
= current_function_decl
;
16766 current_function_decl
= decl
;
16768 was_abstract
= DECL_ABSTRACT (decl
);
16769 set_decl_abstract_flags (decl
, 1);
16770 dwarf2out_decl (decl
);
16771 if (! was_abstract
)
16772 set_decl_abstract_flags (decl
, 0);
16774 current_function_decl
= save_fn
;
16775 decl_loc_table
= old_decl_loc_table
;
16776 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
16777 call_arg_locations
= old_call_arg_locations
;
16778 call_site_count
= old_call_site_count
;
16779 tail_call_site_count
= old_tail_call_site_count
;
16782 /* Helper function of premark_used_types() which gets called through
16785 Marks the DIE of a given type in *SLOT as perennial, so it never gets
16786 marked as unused by prune_unused_types. */
16789 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
16794 type
= (tree
) *slot
;
16795 die
= lookup_type_die (type
);
16797 die
->die_perennial_p
= 1;
16801 /* Helper function of premark_types_used_by_global_vars which gets called
16802 through htab_traverse.
16804 Marks the DIE of a given type in *SLOT as perennial, so it never gets
16805 marked as unused by prune_unused_types. The DIE of the type is marked
16806 only if the global variable using the type will actually be emitted. */
16809 premark_types_used_by_global_vars_helper (void **slot
,
16810 void *data ATTRIBUTE_UNUSED
)
16812 struct types_used_by_vars_entry
*entry
;
16815 entry
= (struct types_used_by_vars_entry
*) *slot
;
16816 gcc_assert (entry
->type
!= NULL
16817 && entry
->var_decl
!= NULL
);
16818 die
= lookup_type_die (entry
->type
);
16821 /* Ask cgraph if the global variable really is to be emitted.
16822 If yes, then we'll keep the DIE of ENTRY->TYPE. */
16823 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
16824 if (node
&& node
->analyzed
)
16826 die
->die_perennial_p
= 1;
16827 /* Keep the parent DIEs as well. */
16828 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
16829 die
->die_perennial_p
= 1;
16835 /* Mark all members of used_types_hash as perennial. */
16838 premark_used_types (struct function
*fun
)
16840 if (fun
&& fun
->used_types_hash
)
16841 htab_traverse (fun
->used_types_hash
, premark_used_types_helper
, NULL
);
16844 /* Mark all members of types_used_by_vars_entry as perennial. */
16847 premark_types_used_by_global_vars (void)
16849 if (types_used_by_vars_hash
)
16850 htab_traverse (types_used_by_vars_hash
,
16851 premark_types_used_by_global_vars_helper
, NULL
);
16854 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
16855 for CA_LOC call arg loc node. */
16858 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
16859 struct call_arg_loc_node
*ca_loc
)
16861 dw_die_ref stmt_die
= NULL
, die
;
16862 tree block
= ca_loc
->block
;
16865 && block
!= DECL_INITIAL (decl
)
16866 && TREE_CODE (block
) == BLOCK
)
16868 if (VEC_length (dw_die_ref
, block_map
) > BLOCK_NUMBER (block
))
16869 stmt_die
= VEC_index (dw_die_ref
, block_map
, BLOCK_NUMBER (block
));
16872 block
= BLOCK_SUPERCONTEXT (block
);
16874 if (stmt_die
== NULL
)
16875 stmt_die
= subr_die
;
16876 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
16877 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
16878 if (ca_loc
->tail_call_p
)
16879 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
16880 if (ca_loc
->symbol_ref
)
16882 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
16884 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
16886 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
);
16891 /* Generate a DIE to represent a declared function (either file-scope or
16895 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
16897 tree origin
= decl_ultimate_origin (decl
);
16898 dw_die_ref subr_die
;
16900 dw_die_ref old_die
= lookup_decl_die (decl
);
16901 int declaration
= (current_function_decl
!= decl
16902 || class_or_namespace_scope_p (context_die
));
16904 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
16906 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
16907 started to generate the abstract instance of an inline, decided to output
16908 its containing class, and proceeded to emit the declaration of the inline
16909 from the member list for the class. If so, DECLARATION takes priority;
16910 we'll get back to the abstract instance when done with the class. */
16912 /* The class-scope declaration DIE must be the primary DIE. */
16913 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
16916 gcc_assert (!old_die
);
16919 /* Now that the C++ front end lazily declares artificial member fns, we
16920 might need to retrofit the declaration into its class. */
16921 if (!declaration
&& !origin
&& !old_die
16922 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
16923 && !class_or_namespace_scope_p (context_die
)
16924 && debug_info_level
> DINFO_LEVEL_TERSE
)
16925 old_die
= force_decl_die (decl
);
16927 if (origin
!= NULL
)
16929 gcc_assert (!declaration
|| local_scope_p (context_die
));
16931 /* Fixup die_parent for the abstract instance of a nested
16932 inline function. */
16933 if (old_die
&& old_die
->die_parent
== NULL
)
16934 add_child_die (context_die
, old_die
);
16936 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
16937 add_abstract_origin_attribute (subr_die
, origin
);
16938 /* This is where the actual code for a cloned function is.
16939 Let's emit linkage name attribute for it. This helps
16940 debuggers to e.g, set breakpoints into
16941 constructors/destructors when the user asks "break
16943 add_linkage_name (subr_die
, decl
);
16947 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16948 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
16950 if (!get_AT_flag (old_die
, DW_AT_declaration
)
16951 /* We can have a normal definition following an inline one in the
16952 case of redefinition of GNU C extern inlines.
16953 It seems reasonable to use AT_specification in this case. */
16954 && !get_AT (old_die
, DW_AT_inline
))
16956 /* Detect and ignore this case, where we are trying to output
16957 something we have already output. */
16961 /* If the definition comes from the same place as the declaration,
16962 maybe use the old DIE. We always want the DIE for this function
16963 that has the *_pc attributes to be under comp_unit_die so the
16964 debugger can find it. We also need to do this for abstract
16965 instances of inlines, since the spec requires the out-of-line copy
16966 to have the same parent. For local class methods, this doesn't
16967 apply; we just use the old DIE. */
16968 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
16969 && (DECL_ARTIFICIAL (decl
)
16970 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
16971 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
16972 == (unsigned) s
.line
))))
16974 subr_die
= old_die
;
16976 /* Clear out the declaration attribute and the formal parameters.
16977 Do not remove all children, because it is possible that this
16978 declaration die was forced using force_decl_die(). In such
16979 cases die that forced declaration die (e.g. TAG_imported_module)
16980 is one of the children that we do not want to remove. */
16981 remove_AT (subr_die
, DW_AT_declaration
);
16982 remove_AT (subr_die
, DW_AT_object_pointer
);
16983 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
16987 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
16988 add_AT_specification (subr_die
, old_die
);
16989 add_pubname (decl
, subr_die
);
16990 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
16991 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
16992 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
16993 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
16998 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17000 if (TREE_PUBLIC (decl
))
17001 add_AT_flag (subr_die
, DW_AT_external
, 1);
17003 add_name_and_src_coords_attributes (subr_die
, decl
);
17004 add_pubname (decl
, subr_die
);
17005 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17007 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
17008 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
17009 0, 0, context_die
);
17012 add_pure_or_virtual_attribute (subr_die
, decl
);
17013 if (DECL_ARTIFICIAL (decl
))
17014 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17016 add_accessibility_attribute (subr_die
, decl
);
17021 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17023 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
17025 /* If this is an explicit function declaration then generate
17026 a DW_AT_explicit attribute. */
17027 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
17028 && (dwarf_version
>= 3 || !dwarf_strict
))
17029 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
17031 /* The first time we see a member function, it is in the context of
17032 the class to which it belongs. We make sure of this by emitting
17033 the class first. The next time is the definition, which is
17034 handled above. The two may come from the same source text.
17036 Note that force_decl_die() forces function declaration die. It is
17037 later reused to represent definition. */
17038 equate_decl_number_to_die (decl
, subr_die
);
17041 else if (DECL_ABSTRACT (decl
))
17043 if (DECL_DECLARED_INLINE_P (decl
))
17045 if (cgraph_function_possibly_inlined_p (decl
))
17046 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
17048 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
17052 if (cgraph_function_possibly_inlined_p (decl
))
17053 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
17055 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
17058 if (DECL_DECLARED_INLINE_P (decl
)
17059 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
17060 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17062 equate_decl_number_to_die (decl
, subr_die
);
17064 else if (!DECL_EXTERNAL (decl
))
17066 HOST_WIDE_INT cfa_fb_offset
;
17067 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
17069 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17070 equate_decl_number_to_die (decl
, subr_die
);
17072 gcc_checking_assert (fun
);
17073 if (!flag_reorder_blocks_and_partition
)
17075 dw_fde_ref fde
= fun
->fde
;
17076 if (fde
->dw_fde_begin
)
17078 /* We have already generated the labels. */
17079 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
);
17083 /* Create start/end labels and add the range. */
17084 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
17085 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
17086 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
17087 current_function_funcdef_no
);
17088 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
17089 current_function_funcdef_no
);
17090 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
);
17093 #if VMS_DEBUGGING_INFO
17094 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17095 Section 2.3 Prologue and Epilogue Attributes:
17096 When a breakpoint is set on entry to a function, it is generally
17097 desirable for execution to be suspended, not on the very first
17098 instruction of the function, but rather at a point after the
17099 function's frame has been set up, after any language defined local
17100 declaration processing has been completed, and before execution of
17101 the first statement of the function begins. Debuggers generally
17102 cannot properly determine where this point is. Similarly for a
17103 breakpoint set on exit from a function. The prologue and epilogue
17104 attributes allow a compiler to communicate the location(s) to use. */
17107 if (fde
->dw_fde_vms_end_prologue
)
17108 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
17109 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
17111 if (fde
->dw_fde_vms_begin_epilogue
)
17112 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
17113 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
17120 /* Generate pubnames entries for the split function code ranges. */
17121 dw_fde_ref fde
= fun
->fde
;
17123 if (fde
->dw_fde_second_begin
)
17125 if (dwarf_version
>= 3 || !dwarf_strict
)
17127 /* We should use ranges for non-contiguous code section
17128 addresses. Use the actual code range for the initial
17129 section, since the HOT/COLD labels might precede an
17130 alignment offset. */
17131 bool range_list_added
= false;
17132 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
17133 fde
->dw_fde_end
, &range_list_added
);
17134 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
17135 fde
->dw_fde_second_end
,
17136 &range_list_added
);
17137 if (range_list_added
)
17142 /* There is no real support in DW2 for this .. so we make
17143 a work-around. First, emit the pub name for the segment
17144 containing the function label. Then make and emit a
17145 simplified subprogram DIE for the second segment with the
17146 name pre-fixed by __hot/cold_sect_of_. We use the same
17147 linkage name for the second die so that gdb will find both
17148 sections when given "b foo". */
17149 const char *name
= NULL
;
17150 tree decl_name
= DECL_NAME (decl
);
17151 dw_die_ref seg_die
;
17153 /* Do the 'primary' section. */
17154 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
17157 /* Build a minimal DIE for the secondary section. */
17158 seg_die
= new_die (DW_TAG_subprogram
,
17159 subr_die
->die_parent
, decl
);
17161 if (TREE_PUBLIC (decl
))
17162 add_AT_flag (seg_die
, DW_AT_external
, 1);
17164 if (decl_name
!= NULL
17165 && IDENTIFIER_POINTER (decl_name
) != NULL
)
17167 name
= dwarf2_name (decl
, 1);
17168 if (! DECL_ARTIFICIAL (decl
))
17169 add_src_coords_attributes (seg_die
, decl
);
17171 add_linkage_name (seg_die
, decl
);
17173 gcc_assert (name
!= NULL
);
17174 add_pure_or_virtual_attribute (seg_die
, decl
);
17175 if (DECL_ARTIFICIAL (decl
))
17176 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
17178 name
= concat ("__second_sect_of_", name
, NULL
);
17179 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
17180 fde
->dw_fde_second_end
);
17181 add_name_attribute (seg_die
, name
);
17182 if (want_pubnames ())
17183 add_pubname_string (name
, seg_die
);
17187 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
);
17190 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
17192 /* We define the "frame base" as the function's CFA. This is more
17193 convenient for several reasons: (1) It's stable across the prologue
17194 and epilogue, which makes it better than just a frame pointer,
17195 (2) With dwarf3, there exists a one-byte encoding that allows us
17196 to reference the .debug_frame data by proxy, but failing that,
17197 (3) We can at least reuse the code inspection and interpretation
17198 code that determines the CFA position at various points in the
17200 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
17202 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
17203 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
17207 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
17208 if (list
->dw_loc_next
)
17209 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
17211 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
17214 /* Compute a displacement from the "steady-state frame pointer" to
17215 the CFA. The former is what all stack slots and argument slots
17216 will reference in the rtl; the later is what we've told the
17217 debugger about. We'll need to adjust all frame_base references
17218 by this displacement. */
17219 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
17221 if (fun
->static_chain_decl
)
17222 add_AT_location_description (subr_die
, DW_AT_static_link
,
17223 loc_list_from_tree (fun
->static_chain_decl
, 2));
17226 /* Generate child dies for template paramaters. */
17227 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17228 gen_generic_params_dies (decl
);
17230 /* Now output descriptions of the arguments for this function. This gets
17231 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
17232 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
17233 `...' at the end of the formal parameter list. In order to find out if
17234 there was a trailing ellipsis or not, we must instead look at the type
17235 associated with the FUNCTION_DECL. This will be a node of type
17236 FUNCTION_TYPE. If the chain of type nodes hanging off of this
17237 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
17238 an ellipsis at the end. */
17240 /* In the case where we are describing a mere function declaration, all we
17241 need to do here (and all we *can* do here) is to describe the *types* of
17242 its formal parameters. */
17243 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
17245 else if (declaration
)
17246 gen_formal_types_die (decl
, subr_die
);
17249 /* Generate DIEs to represent all known formal parameters. */
17250 tree parm
= DECL_ARGUMENTS (decl
);
17251 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
17252 tree generic_decl_parm
= generic_decl
17253 ? DECL_ARGUMENTS (generic_decl
)
17256 /* Now we want to walk the list of parameters of the function and
17257 emit their relevant DIEs.
17259 We consider the case of DECL being an instance of a generic function
17260 as well as it being a normal function.
17262 If DECL is an instance of a generic function we walk the
17263 parameters of the generic function declaration _and_ the parameters of
17264 DECL itself. This is useful because we want to emit specific DIEs for
17265 function parameter packs and those are declared as part of the
17266 generic function declaration. In that particular case,
17267 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
17268 That DIE has children DIEs representing the set of arguments
17269 of the pack. Note that the set of pack arguments can be empty.
17270 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
17273 Otherwise, we just consider the parameters of DECL. */
17274 while (generic_decl_parm
|| parm
)
17276 if (generic_decl_parm
17277 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
17278 gen_formal_parameter_pack_die (generic_decl_parm
,
17283 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
17285 if (parm
== DECL_ARGUMENTS (decl
)
17286 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
17288 && (dwarf_version
>= 3 || !dwarf_strict
))
17289 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
17291 parm
= DECL_CHAIN (parm
);
17294 if (generic_decl_parm
)
17295 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
17298 /* Decide whether we need an unspecified_parameters DIE at the end.
17299 There are 2 more cases to do this for: 1) the ansi ... declaration -
17300 this is detectable when the end of the arg list is not a
17301 void_type_node 2) an unprototyped function declaration (not a
17302 definition). This just means that we have no info about the
17303 parameters at all. */
17304 if (prototype_p (TREE_TYPE (decl
)))
17306 /* This is the prototyped case, check for.... */
17307 if (stdarg_p (TREE_TYPE (decl
)))
17308 gen_unspecified_parameters_die (decl
, subr_die
);
17310 else if (DECL_INITIAL (decl
) == NULL_TREE
)
17311 gen_unspecified_parameters_die (decl
, subr_die
);
17314 /* Output Dwarf info for all of the stuff within the body of the function
17315 (if it has one - it may be just a declaration). */
17316 outer_scope
= DECL_INITIAL (decl
);
17318 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
17319 a function. This BLOCK actually represents the outermost binding contour
17320 for the function, i.e. the contour in which the function's formal
17321 parameters and labels get declared. Curiously, it appears that the front
17322 end doesn't actually put the PARM_DECL nodes for the current function onto
17323 the BLOCK_VARS list for this outer scope, but are strung off of the
17324 DECL_ARGUMENTS list for the function instead.
17326 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
17327 the LABEL_DECL nodes for the function however, and we output DWARF info
17328 for those in decls_for_scope. Just within the `outer_scope' there will be
17329 a BLOCK node representing the function's outermost pair of curly braces,
17330 and any blocks used for the base and member initializers of a C++
17331 constructor function. */
17332 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
17334 int call_site_note_count
= 0;
17335 int tail_call_site_note_count
= 0;
17337 /* Emit a DW_TAG_variable DIE for a named return value. */
17338 if (DECL_NAME (DECL_RESULT (decl
)))
17339 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
17341 current_function_has_inlines
= 0;
17342 decls_for_scope (outer_scope
, subr_die
, 0);
17344 if (call_arg_locations
&& !dwarf_strict
)
17346 struct call_arg_loc_node
*ca_loc
;
17347 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
17349 dw_die_ref die
= NULL
;
17350 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
17353 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
17354 arg
; arg
= next_arg
)
17356 dw_loc_descr_ref reg
, val
;
17357 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
17358 dw_die_ref cdie
, tdie
= NULL
;
17360 next_arg
= XEXP (arg
, 1);
17361 if (REG_P (XEXP (XEXP (arg
, 0), 0))
17363 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
17364 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
17365 && REGNO (XEXP (XEXP (arg
, 0), 0))
17366 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
17367 next_arg
= XEXP (next_arg
, 1);
17368 if (mode
== VOIDmode
)
17370 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
17371 if (mode
== VOIDmode
)
17372 mode
= GET_MODE (XEXP (arg
, 0));
17374 if (mode
== VOIDmode
|| mode
== BLKmode
)
17376 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
17378 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
17379 tloc
= XEXP (XEXP (arg
, 0), 1);
17382 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
17383 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
17385 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
17386 tlocc
= XEXP (XEXP (arg
, 0), 1);
17390 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
17391 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
17392 VAR_INIT_STATUS_INITIALIZED
);
17393 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
17395 rtx mem
= XEXP (XEXP (arg
, 0), 0);
17396 reg
= mem_loc_descriptor (XEXP (mem
, 0),
17397 get_address_mode (mem
),
17399 VAR_INIT_STATUS_INITIALIZED
);
17401 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
17402 == DEBUG_PARAMETER_REF
)
17405 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
17406 tdie
= lookup_decl_die (tdecl
);
17413 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
17414 != DEBUG_PARAMETER_REF
)
17416 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
17418 VAR_INIT_STATUS_INITIALIZED
);
17422 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
17423 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
17426 add_AT_loc (cdie
, DW_AT_location
, reg
);
17427 else if (tdie
!= NULL
)
17428 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
17429 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
17430 if (next_arg
!= XEXP (arg
, 1))
17432 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
17433 if (mode
== VOIDmode
)
17434 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
17435 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
17438 VAR_INIT_STATUS_INITIALIZED
);
17440 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
17444 && (ca_loc
->symbol_ref
|| tloc
))
17445 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
17446 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
17448 dw_loc_descr_ref tval
= NULL
;
17450 if (tloc
!= NULL_RTX
)
17451 tval
= mem_loc_descriptor (tloc
,
17452 GET_MODE (tloc
) == VOIDmode
17453 ? Pmode
: GET_MODE (tloc
),
17455 VAR_INIT_STATUS_INITIALIZED
);
17457 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
17458 else if (tlocc
!= NULL_RTX
)
17460 tval
= mem_loc_descriptor (tlocc
,
17461 GET_MODE (tlocc
) == VOIDmode
17462 ? Pmode
: GET_MODE (tlocc
),
17464 VAR_INIT_STATUS_INITIALIZED
);
17466 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
17472 call_site_note_count
++;
17473 if (ca_loc
->tail_call_p
)
17474 tail_call_site_note_count
++;
17478 call_arg_locations
= NULL
;
17479 call_arg_loc_last
= NULL
;
17480 if (tail_call_site_count
>= 0
17481 && tail_call_site_count
== tail_call_site_note_count
17484 if (call_site_count
>= 0
17485 && call_site_count
== call_site_note_count
)
17486 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
17488 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
17490 call_site_count
= -1;
17491 tail_call_site_count
= -1;
17493 /* Add the calling convention attribute if requested. */
17494 add_calling_convention_attribute (subr_die
, decl
);
17498 /* Returns a hash value for X (which really is a die_struct). */
17501 common_block_die_table_hash (const void *x
)
17503 const_dw_die_ref d
= (const_dw_die_ref
) x
;
17504 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
17507 /* Return nonzero if decl_id and die_parent of die_struct X is the same
17508 as decl_id and die_parent of die_struct Y. */
17511 common_block_die_table_eq (const void *x
, const void *y
)
17513 const_dw_die_ref d
= (const_dw_die_ref
) x
;
17514 const_dw_die_ref e
= (const_dw_die_ref
) y
;
17515 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
17518 /* Generate a DIE to represent a declared data object.
17519 Either DECL or ORIGIN must be non-null. */
17522 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
17524 HOST_WIDE_INT off
= 0;
17526 tree decl_or_origin
= decl
? decl
: origin
;
17527 tree ultimate_origin
;
17528 dw_die_ref var_die
;
17529 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
17530 dw_die_ref origin_die
;
17531 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
17532 || class_or_namespace_scope_p (context_die
));
17533 bool specialization_p
= false;
17535 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
17536 if (decl
|| ultimate_origin
)
17537 origin
= ultimate_origin
;
17538 com_decl
= fortran_common (decl_or_origin
, &off
);
17540 /* Symbol in common gets emitted as a child of the common block, in the form
17541 of a data member. */
17544 dw_die_ref com_die
;
17545 dw_loc_list_ref loc
;
17546 die_node com_die_arg
;
17548 var_die
= lookup_decl_die (decl_or_origin
);
17551 if (get_AT (var_die
, DW_AT_location
) == NULL
)
17553 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
17558 /* Optimize the common case. */
17559 if (single_element_loc_list_p (loc
)
17560 && loc
->expr
->dw_loc_opc
== DW_OP_addr
17561 && loc
->expr
->dw_loc_next
== NULL
17562 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
17565 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
17566 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
17567 = plus_constant (GET_MODE (x
), x
, off
);
17570 loc_list_plus_const (loc
, off
);
17572 add_AT_location_description (var_die
, DW_AT_location
, loc
);
17573 remove_AT (var_die
, DW_AT_declaration
);
17579 if (common_block_die_table
== NULL
)
17580 common_block_die_table
17581 = htab_create_ggc (10, common_block_die_table_hash
,
17582 common_block_die_table_eq
, NULL
);
17584 com_die_arg
.decl_id
= DECL_UID (com_decl
);
17585 com_die_arg
.die_parent
= context_die
;
17586 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
17587 loc
= loc_list_from_tree (com_decl
, 2);
17588 if (com_die
== NULL
)
17591 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
17594 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
17595 add_name_and_src_coords_attributes (com_die
, com_decl
);
17598 add_AT_location_description (com_die
, DW_AT_location
, loc
);
17599 /* Avoid sharing the same loc descriptor between
17600 DW_TAG_common_block and DW_TAG_variable. */
17601 loc
= loc_list_from_tree (com_decl
, 2);
17603 else if (DECL_EXTERNAL (decl
))
17604 add_AT_flag (com_die
, DW_AT_declaration
, 1);
17605 if (want_pubnames ())
17606 add_pubname_string (cnam
, com_die
); /* ??? needed? */
17607 com_die
->decl_id
= DECL_UID (com_decl
);
17608 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
17609 *slot
= (void *) com_die
;
17611 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
17613 add_AT_location_description (com_die
, DW_AT_location
, loc
);
17614 loc
= loc_list_from_tree (com_decl
, 2);
17615 remove_AT (com_die
, DW_AT_declaration
);
17617 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
17618 add_name_and_src_coords_attributes (var_die
, decl
);
17619 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
17620 TREE_THIS_VOLATILE (decl
), context_die
);
17621 add_AT_flag (var_die
, DW_AT_external
, 1);
17626 /* Optimize the common case. */
17627 if (single_element_loc_list_p (loc
)
17628 && loc
->expr
->dw_loc_opc
== DW_OP_addr
17629 && loc
->expr
->dw_loc_next
== NULL
17630 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
17632 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
17633 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
17634 = plus_constant (GET_MODE (x
), x
, off
);
17637 loc_list_plus_const (loc
, off
);
17639 add_AT_location_description (var_die
, DW_AT_location
, loc
);
17641 else if (DECL_EXTERNAL (decl
))
17642 add_AT_flag (var_die
, DW_AT_declaration
, 1);
17643 equate_decl_number_to_die (decl
, var_die
);
17647 /* If the compiler emitted a definition for the DECL declaration
17648 and if we already emitted a DIE for it, don't emit a second
17649 DIE for it again. Allow re-declarations of DECLs that are
17650 inside functions, though. */
17651 if (old_die
&& declaration
&& !local_scope_p (context_die
))
17654 /* For static data members, the declaration in the class is supposed
17655 to have DW_TAG_member tag; the specification should still be
17656 DW_TAG_variable referencing the DW_TAG_member DIE. */
17657 if (declaration
&& class_scope_p (context_die
))
17658 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
17660 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
17663 if (origin
!= NULL
)
17664 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
17666 /* Loop unrolling can create multiple blocks that refer to the same
17667 static variable, so we must test for the DW_AT_declaration flag.
17669 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
17670 copy decls and set the DECL_ABSTRACT flag on them instead of
17673 ??? Duplicated blocks have been rewritten to use .debug_ranges.
17675 ??? The declare_in_namespace support causes us to get two DIEs for one
17676 variable, both of which are declarations. We want to avoid considering
17677 one to be a specification, so we must test that this DIE is not a
17679 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
17680 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
17682 /* This is a definition of a C++ class level static. */
17683 add_AT_specification (var_die
, old_die
);
17684 specialization_p
= true;
17685 if (DECL_NAME (decl
))
17687 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17688 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17690 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17691 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
17693 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17694 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
17696 if (old_die
->die_tag
== DW_TAG_member
)
17697 add_linkage_name (var_die
, decl
);
17701 add_name_and_src_coords_attributes (var_die
, decl
);
17703 if ((origin
== NULL
&& !specialization_p
)
17705 && !DECL_ABSTRACT (decl_or_origin
)
17706 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
17707 decl_function_context
17708 (decl_or_origin
))))
17710 tree type
= TREE_TYPE (decl_or_origin
);
17712 if (decl_by_reference_p (decl_or_origin
))
17713 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
17715 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
17716 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
17719 if (origin
== NULL
&& !specialization_p
)
17721 if (TREE_PUBLIC (decl
))
17722 add_AT_flag (var_die
, DW_AT_external
, 1);
17724 if (DECL_ARTIFICIAL (decl
))
17725 add_AT_flag (var_die
, DW_AT_artificial
, 1);
17727 add_accessibility_attribute (var_die
, decl
);
17731 add_AT_flag (var_die
, DW_AT_declaration
, 1);
17733 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
17734 equate_decl_number_to_die (decl
, var_die
);
17737 && (! DECL_ABSTRACT (decl_or_origin
)
17738 /* Local static vars are shared between all clones/inlines,
17739 so emit DW_AT_location on the abstract DIE if DECL_RTL is
17741 || (TREE_CODE (decl_or_origin
) == VAR_DECL
17742 && TREE_STATIC (decl_or_origin
)
17743 && DECL_RTL_SET_P (decl_or_origin
)))
17744 /* When abstract origin already has DW_AT_location attribute, no need
17745 to add it again. */
17746 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
17748 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
17749 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
17750 defer_location (decl_or_origin
, var_die
);
17752 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
17753 decl
== NULL
, DW_AT_location
);
17754 add_pubname (decl_or_origin
, var_die
);
17757 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
17760 /* Generate a DIE to represent a named constant. */
17763 gen_const_die (tree decl
, dw_die_ref context_die
)
17765 dw_die_ref const_die
;
17766 tree type
= TREE_TYPE (decl
);
17768 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
17769 add_name_and_src_coords_attributes (const_die
, decl
);
17770 add_type_attribute (const_die
, type
, 1, 0, context_die
);
17771 if (TREE_PUBLIC (decl
))
17772 add_AT_flag (const_die
, DW_AT_external
, 1);
17773 if (DECL_ARTIFICIAL (decl
))
17774 add_AT_flag (const_die
, DW_AT_artificial
, 1);
17775 tree_add_const_value_attribute_for_decl (const_die
, decl
);
17778 /* Generate a DIE to represent a label identifier. */
17781 gen_label_die (tree decl
, dw_die_ref context_die
)
17783 tree origin
= decl_ultimate_origin (decl
);
17784 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
17786 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
17788 if (origin
!= NULL
)
17789 add_abstract_origin_attribute (lbl_die
, origin
);
17791 add_name_and_src_coords_attributes (lbl_die
, decl
);
17793 if (DECL_ABSTRACT (decl
))
17794 equate_decl_number_to_die (decl
, lbl_die
);
17797 insn
= DECL_RTL_IF_SET (decl
);
17799 /* Deleted labels are programmer specified labels which have been
17800 eliminated because of various optimizations. We still emit them
17801 here so that it is possible to put breakpoints on them. */
17805 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
17807 /* When optimization is enabled (via -O) some parts of the compiler
17808 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
17809 represent source-level labels which were explicitly declared by
17810 the user. This really shouldn't be happening though, so catch
17811 it if it ever does happen. */
17812 gcc_assert (!INSN_DELETED_P (insn
));
17814 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
17815 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
17819 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
17820 && CODE_LABEL_NUMBER (insn
) != -1)
17822 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
17823 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
17828 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
17829 attributes to the DIE for a block STMT, to describe where the inlined
17830 function was called from. This is similar to add_src_coords_attributes. */
17833 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
17835 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
17837 if (dwarf_version
>= 3 || !dwarf_strict
)
17839 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
17840 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
17845 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
17846 Add low_pc and high_pc attributes to the DIE for a block STMT. */
17849 add_high_low_attributes (tree stmt
, dw_die_ref die
)
17851 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
17853 if (BLOCK_FRAGMENT_CHAIN (stmt
)
17854 && (dwarf_version
>= 3 || !dwarf_strict
))
17856 tree chain
, superblock
= NULL_TREE
;
17858 dw_attr_ref attr
= NULL
;
17860 if (inlined_function_outer_scope_p (stmt
))
17862 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
17863 BLOCK_NUMBER (stmt
));
17864 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
17867 /* Optimize duplicate .debug_ranges lists or even tails of
17868 lists. If this BLOCK has same ranges as its supercontext,
17869 lookup DW_AT_ranges attribute in the supercontext (and
17870 recursively so), verify that the ranges_table contains the
17871 right values and use it instead of adding a new .debug_range. */
17872 for (chain
= stmt
, pdie
= die
;
17873 BLOCK_SAME_RANGE (chain
);
17874 chain
= BLOCK_SUPERCONTEXT (chain
))
17876 dw_attr_ref new_attr
;
17878 pdie
= pdie
->die_parent
;
17881 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
17883 new_attr
= get_AT (pdie
, DW_AT_ranges
);
17884 if (new_attr
== NULL
17885 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
17888 superblock
= BLOCK_SUPERCONTEXT (chain
);
17891 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
17892 / 2 / DWARF2_ADDR_SIZE
].num
17893 == BLOCK_NUMBER (superblock
))
17894 && BLOCK_FRAGMENT_CHAIN (superblock
))
17896 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
17897 / 2 / DWARF2_ADDR_SIZE
;
17898 unsigned long supercnt
= 0, thiscnt
= 0;
17899 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
17900 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
17903 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
17904 == BLOCK_NUMBER (chain
));
17906 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
17907 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
17908 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
17910 gcc_assert (supercnt
>= thiscnt
);
17911 add_AT_range_list (die
, DW_AT_ranges
,
17912 (off
+ supercnt
- thiscnt
)
17913 * 2 * DWARF2_ADDR_SIZE
);
17917 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
));
17919 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
17922 add_ranges (chain
);
17923 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
17930 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
17931 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
17932 BLOCK_NUMBER (stmt
));
17933 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
17934 BLOCK_NUMBER (stmt
));
17935 add_AT_low_high_pc (die
, label
, label_high
);
17939 /* Generate a DIE for a lexical block. */
17942 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
17944 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
17946 if (call_arg_locations
)
17948 if (VEC_length (dw_die_ref
, block_map
) <= BLOCK_NUMBER (stmt
))
17949 VEC_safe_grow_cleared (dw_die_ref
, heap
, block_map
,
17950 BLOCK_NUMBER (stmt
) + 1);
17951 VEC_replace (dw_die_ref
, block_map
, BLOCK_NUMBER (stmt
), stmt_die
);
17954 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
17955 add_high_low_attributes (stmt
, stmt_die
);
17957 decls_for_scope (stmt
, stmt_die
, depth
);
17960 /* Generate a DIE for an inlined subprogram. */
17963 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
17967 /* The instance of function that is effectively being inlined shall not
17969 gcc_assert (! BLOCK_ABSTRACT (stmt
));
17971 decl
= block_ultimate_origin (stmt
);
17973 /* Emit info for the abstract instance first, if we haven't yet. We
17974 must emit this even if the block is abstract, otherwise when we
17975 emit the block below (or elsewhere), we may end up trying to emit
17976 a die whose origin die hasn't been emitted, and crashing. */
17977 dwarf2out_abstract_function (decl
);
17979 if (! BLOCK_ABSTRACT (stmt
))
17981 dw_die_ref subr_die
17982 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
17984 if (call_arg_locations
)
17986 if (VEC_length (dw_die_ref
, block_map
) <= BLOCK_NUMBER (stmt
))
17987 VEC_safe_grow_cleared (dw_die_ref
, heap
, block_map
,
17988 BLOCK_NUMBER (stmt
) + 1);
17989 VEC_replace (dw_die_ref
, block_map
, BLOCK_NUMBER (stmt
), subr_die
);
17991 add_abstract_origin_attribute (subr_die
, decl
);
17992 if (TREE_ASM_WRITTEN (stmt
))
17993 add_high_low_attributes (stmt
, subr_die
);
17994 add_call_src_coords_attributes (stmt
, subr_die
);
17996 decls_for_scope (stmt
, subr_die
, depth
);
17997 current_function_has_inlines
= 1;
18001 /* Generate a DIE for a field in a record, or structure. */
18004 gen_field_die (tree decl
, dw_die_ref context_die
)
18006 dw_die_ref decl_die
;
18008 if (TREE_TYPE (decl
) == error_mark_node
)
18011 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
18012 add_name_and_src_coords_attributes (decl_die
, decl
);
18013 add_type_attribute (decl_die
, member_declared_type (decl
),
18014 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
18017 if (DECL_BIT_FIELD_TYPE (decl
))
18019 add_byte_size_attribute (decl_die
, decl
);
18020 add_bit_size_attribute (decl_die
, decl
);
18021 add_bit_offset_attribute (decl_die
, decl
);
18024 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
18025 add_data_member_location_attribute (decl_die
, decl
);
18027 if (DECL_ARTIFICIAL (decl
))
18028 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
18030 add_accessibility_attribute (decl_die
, decl
);
18032 /* Equate decl number to die, so that we can look up this decl later on. */
18033 equate_decl_number_to_die (decl
, decl_die
);
18037 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18038 Use modified_type_die instead.
18039 We keep this code here just in case these types of DIEs may be needed to
18040 represent certain things in other languages (e.g. Pascal) someday. */
18043 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
18046 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
18048 equate_type_number_to_die (type
, ptr_die
);
18049 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18050 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18053 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18054 Use modified_type_die instead.
18055 We keep this code here just in case these types of DIEs may be needed to
18056 represent certain things in other languages (e.g. Pascal) someday. */
18059 gen_reference_type_die (tree type
, dw_die_ref context_die
)
18061 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
18063 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
18064 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
18066 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
18068 equate_type_number_to_die (type
, ref_die
);
18069 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
18070 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18074 /* Generate a DIE for a pointer to a member type. */
18077 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
18080 = new_die (DW_TAG_ptr_to_member_type
,
18081 scope_die_for (type
, context_die
), type
);
18083 equate_type_number_to_die (type
, ptr_die
);
18084 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
18085 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
18086 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18089 typedef const char *dchar_p
; /* For DEF_VEC_P. */
18090 DEF_VEC_P(dchar_p
);
18091 DEF_VEC_ALLOC_P(dchar_p
,heap
);
18093 static char *producer_string
;
18095 /* Return a heap allocated producer string including command line options
18096 if -grecord-gcc-switches. */
18099 gen_producer_string (void)
18102 VEC(dchar_p
, heap
) *switches
= NULL
;
18103 const char *language_string
= lang_hooks
.name
;
18104 char *producer
, *tail
;
18106 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
18107 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
18109 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
18110 switch (save_decoded_options
[j
].opt_index
)
18117 case OPT_auxbase_strip
:
18126 case OPT_SPECIAL_unknown
:
18127 case OPT_SPECIAL_ignore
:
18128 case OPT_SPECIAL_program_name
:
18129 case OPT_SPECIAL_input_file
:
18130 case OPT_grecord_gcc_switches
:
18131 case OPT_gno_record_gcc_switches
:
18132 case OPT__output_pch_
:
18133 case OPT_fdiagnostics_show_location_
:
18134 case OPT_fdiagnostics_show_option
:
18135 case OPT_fdiagnostics_show_caret
:
18136 case OPT_fverbose_asm
:
18138 case OPT__sysroot_
:
18140 case OPT_nostdinc__
:
18141 /* Ignore these. */
18144 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
18145 & CL_NO_DWARF_RECORD
)
18147 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
18149 switch (save_decoded_options
[j
].canonical_option
[0][1])
18156 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
18163 VEC_safe_push (dchar_p
, heap
, switches
,
18164 save_decoded_options
[j
].orig_option_with_args_text
);
18165 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
18169 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
18171 sprintf (tail
, "%s %s", language_string
, version_string
);
18174 FOR_EACH_VEC_ELT (dchar_p
, switches
, j
, p
)
18178 memcpy (tail
+ 1, p
, len
);
18183 VEC_free (dchar_p
, heap
, switches
);
18187 /* Generate the DIE for the compilation unit. */
18190 gen_compile_unit_die (const char *filename
)
18193 const char *language_string
= lang_hooks
.name
;
18196 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
18200 add_name_attribute (die
, filename
);
18201 /* Don't add cwd for <built-in>. */
18202 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
18203 add_comp_dir_attribute (die
);
18206 if (producer_string
== NULL
)
18207 producer_string
= gen_producer_string ();
18208 add_AT_string (die
, DW_AT_producer
, producer_string
);
18210 /* If our producer is LTO try to figure out a common language to use
18211 from the global list of translation units. */
18212 if (strcmp (language_string
, "GNU GIMPLE") == 0)
18216 const char *common_lang
= NULL
;
18218 FOR_EACH_VEC_ELT (tree
, all_translation_units
, i
, t
)
18220 if (!TRANSLATION_UNIT_LANGUAGE (t
))
18223 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
18224 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
18226 else if (strncmp (common_lang
, "GNU C", 5) == 0
18227 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
18228 /* Mixing C and C++ is ok, use C++ in that case. */
18229 common_lang
= "GNU C++";
18232 /* Fall back to C. */
18233 common_lang
= NULL
;
18239 language_string
= common_lang
;
18242 language
= DW_LANG_C89
;
18243 if (strcmp (language_string
, "GNU C++") == 0)
18244 language
= DW_LANG_C_plus_plus
;
18245 else if (strcmp (language_string
, "GNU F77") == 0)
18246 language
= DW_LANG_Fortran77
;
18247 else if (strcmp (language_string
, "GNU Pascal") == 0)
18248 language
= DW_LANG_Pascal83
;
18249 else if (dwarf_version
>= 3 || !dwarf_strict
)
18251 if (strcmp (language_string
, "GNU Ada") == 0)
18252 language
= DW_LANG_Ada95
;
18253 else if (strcmp (language_string
, "GNU Fortran") == 0)
18254 language
= DW_LANG_Fortran95
;
18255 else if (strcmp (language_string
, "GNU Java") == 0)
18256 language
= DW_LANG_Java
;
18257 else if (strcmp (language_string
, "GNU Objective-C") == 0)
18258 language
= DW_LANG_ObjC
;
18259 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
18260 language
= DW_LANG_ObjC_plus_plus
;
18261 else if (dwarf_version
>= 5 || !dwarf_strict
)
18263 if (strcmp (language_string
, "GNU Go") == 0)
18264 language
= DW_LANG_Go
;
18267 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
18268 else if (strcmp (language_string
, "GNU Fortran") == 0)
18269 language
= DW_LANG_Fortran90
;
18271 add_AT_unsigned (die
, DW_AT_language
, language
);
18275 case DW_LANG_Fortran77
:
18276 case DW_LANG_Fortran90
:
18277 case DW_LANG_Fortran95
:
18278 /* Fortran has case insensitive identifiers and the front-end
18279 lowercases everything. */
18280 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
18283 /* The default DW_ID_case_sensitive doesn't need to be specified. */
18289 /* Generate the DIE for a base class. */
18292 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
18294 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
18296 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
18297 add_data_member_location_attribute (die
, binfo
);
18299 if (BINFO_VIRTUAL_P (binfo
))
18300 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
18302 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18303 children, otherwise the default is DW_ACCESS_public. In DWARF2
18304 the default has always been DW_ACCESS_private. */
18305 if (access
== access_public_node
)
18307 if (dwarf_version
== 2
18308 || context_die
->die_tag
== DW_TAG_class_type
)
18309 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
18311 else if (access
== access_protected_node
)
18312 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
18313 else if (dwarf_version
> 2
18314 && context_die
->die_tag
!= DW_TAG_class_type
)
18315 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
18318 /* Generate a DIE for a class member. */
18321 gen_member_die (tree type
, dw_die_ref context_die
)
18324 tree binfo
= TYPE_BINFO (type
);
18327 /* If this is not an incomplete type, output descriptions of each of its
18328 members. Note that as we output the DIEs necessary to represent the
18329 members of this record or union type, we will also be trying to output
18330 DIEs to represent the *types* of those members. However the `type'
18331 function (above) will specifically avoid generating type DIEs for member
18332 types *within* the list of member DIEs for this (containing) type except
18333 for those types (of members) which are explicitly marked as also being
18334 members of this (containing) type themselves. The g++ front- end can
18335 force any given type to be treated as a member of some other (containing)
18336 type by setting the TYPE_CONTEXT of the given (member) type to point to
18337 the TREE node representing the appropriate (containing) type. */
18339 /* First output info about the base classes. */
18342 VEC(tree
,gc
) *accesses
= BINFO_BASE_ACCESSES (binfo
);
18346 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
18347 gen_inheritance_die (base
,
18348 (accesses
? VEC_index (tree
, accesses
, i
)
18349 : access_public_node
), context_die
);
18352 /* Now output info about the data members and type members. */
18353 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
18355 /* If we thought we were generating minimal debug info for TYPE
18356 and then changed our minds, some of the member declarations
18357 may have already been defined. Don't define them again, but
18358 do put them in the right order. */
18360 child
= lookup_decl_die (member
);
18362 splice_child_die (context_die
, child
);
18364 gen_decl_die (member
, NULL
, context_die
);
18367 /* Now output info about the function members (if any). */
18368 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
18370 /* Don't include clones in the member list. */
18371 if (DECL_ABSTRACT_ORIGIN (member
))
18374 child
= lookup_decl_die (member
);
18376 splice_child_die (context_die
, child
);
18378 gen_decl_die (member
, NULL
, context_die
);
18382 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
18383 is set, we pretend that the type was never defined, so we only get the
18384 member DIEs needed by later specification DIEs. */
18387 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
18388 enum debug_info_usage usage
)
18390 dw_die_ref type_die
= lookup_type_die (type
);
18391 dw_die_ref scope_die
= 0;
18393 int complete
= (TYPE_SIZE (type
)
18394 && (! TYPE_STUB_DECL (type
)
18395 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
18396 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
18397 complete
= complete
&& should_emit_struct_debug (type
, usage
);
18399 if (type_die
&& ! complete
)
18402 if (TYPE_CONTEXT (type
) != NULL_TREE
18403 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
18404 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
18407 scope_die
= scope_die_for (type
, context_die
);
18409 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
18410 /* First occurrence of type or toplevel definition of nested class. */
18412 dw_die_ref old_die
= type_die
;
18414 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
18415 ? record_type_tag (type
) : DW_TAG_union_type
,
18417 equate_type_number_to_die (type
, type_die
);
18419 add_AT_specification (type_die
, old_die
);
18421 add_name_attribute (type_die
, type_tag (type
));
18424 remove_AT (type_die
, DW_AT_declaration
);
18426 /* Generate child dies for template paramaters. */
18427 if (debug_info_level
> DINFO_LEVEL_TERSE
18428 && COMPLETE_TYPE_P (type
))
18429 schedule_generic_params_dies_gen (type
);
18431 /* If this type has been completed, then give it a byte_size attribute and
18432 then give a list of members. */
18433 if (complete
&& !ns_decl
)
18435 /* Prevent infinite recursion in cases where the type of some member of
18436 this type is expressed in terms of this type itself. */
18437 TREE_ASM_WRITTEN (type
) = 1;
18438 add_byte_size_attribute (type_die
, type
);
18439 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
18441 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
18442 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
18445 /* If the first reference to this type was as the return type of an
18446 inline function, then it may not have a parent. Fix this now. */
18447 if (type_die
->die_parent
== NULL
)
18448 add_child_die (scope_die
, type_die
);
18450 push_decl_scope (type
);
18451 gen_member_die (type
, type_die
);
18454 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
18455 if (TYPE_ARTIFICIAL (type
))
18456 add_AT_flag (type_die
, DW_AT_artificial
, 1);
18458 /* GNU extension: Record what type our vtable lives in. */
18459 if (TYPE_VFIELD (type
))
18461 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
18463 gen_type_die (vtype
, context_die
);
18464 add_AT_die_ref (type_die
, DW_AT_containing_type
,
18465 lookup_type_die (vtype
));
18470 add_AT_flag (type_die
, DW_AT_declaration
, 1);
18472 /* We don't need to do this for function-local types. */
18473 if (TYPE_STUB_DECL (type
)
18474 && ! decl_function_context (TYPE_STUB_DECL (type
)))
18475 VEC_safe_push (tree
, gc
, incomplete_types
, type
);
18478 if (get_AT (type_die
, DW_AT_name
))
18479 add_pubtype (type
, type_die
);
18482 /* Generate a DIE for a subroutine _type_. */
18485 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
18487 tree return_type
= TREE_TYPE (type
);
18488 dw_die_ref subr_die
18489 = new_die (DW_TAG_subroutine_type
,
18490 scope_die_for (type
, context_die
), type
);
18492 equate_type_number_to_die (type
, subr_die
);
18493 add_prototyped_attribute (subr_die
, type
);
18494 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
18495 gen_formal_types_die (type
, subr_die
);
18497 if (get_AT (subr_die
, DW_AT_name
))
18498 add_pubtype (type
, subr_die
);
18501 /* Generate a DIE for a type definition. */
18504 gen_typedef_die (tree decl
, dw_die_ref context_die
)
18506 dw_die_ref type_die
;
18509 if (TREE_ASM_WRITTEN (decl
))
18512 TREE_ASM_WRITTEN (decl
) = 1;
18513 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
18514 origin
= decl_ultimate_origin (decl
);
18515 if (origin
!= NULL
)
18516 add_abstract_origin_attribute (type_die
, origin
);
18521 add_name_and_src_coords_attributes (type_die
, decl
);
18522 if (DECL_ORIGINAL_TYPE (decl
))
18524 type
= DECL_ORIGINAL_TYPE (decl
);
18526 gcc_assert (type
!= TREE_TYPE (decl
));
18527 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
18531 type
= TREE_TYPE (decl
);
18533 if (is_naming_typedef_decl (TYPE_NAME (type
)))
18535 /* Here, we are in the case of decl being a typedef naming
18536 an anonymous type, e.g:
18537 typedef struct {...} foo;
18538 In that case TREE_TYPE (decl) is not a typedef variant
18539 type and TYPE_NAME of the anonymous type is set to the
18540 TYPE_DECL of the typedef. This construct is emitted by
18543 TYPE is the anonymous struct named by the typedef
18544 DECL. As we need the DW_AT_type attribute of the
18545 DW_TAG_typedef to point to the DIE of TYPE, let's
18546 generate that DIE right away. add_type_attribute
18547 called below will then pick (via lookup_type_die) that
18548 anonymous struct DIE. */
18549 if (!TREE_ASM_WRITTEN (type
))
18550 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
18552 /* This is a GNU Extension. We are adding a
18553 DW_AT_linkage_name attribute to the DIE of the
18554 anonymous struct TYPE. The value of that attribute
18555 is the name of the typedef decl naming the anonymous
18556 struct. This greatly eases the work of consumers of
18557 this debug info. */
18558 add_linkage_attr (lookup_type_die (type
), decl
);
18562 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
18563 TREE_THIS_VOLATILE (decl
), context_die
);
18565 if (is_naming_typedef_decl (decl
))
18566 /* We want that all subsequent calls to lookup_type_die with
18567 TYPE in argument yield the DW_TAG_typedef we have just
18569 equate_type_number_to_die (type
, type_die
);
18571 add_accessibility_attribute (type_die
, decl
);
18574 if (DECL_ABSTRACT (decl
))
18575 equate_decl_number_to_die (decl
, type_die
);
18577 if (get_AT (type_die
, DW_AT_name
))
18578 add_pubtype (decl
, type_die
);
18581 /* Generate a DIE for a struct, class, enum or union type. */
18584 gen_tagged_type_die (tree type
,
18585 dw_die_ref context_die
,
18586 enum debug_info_usage usage
)
18590 if (type
== NULL_TREE
18591 || !is_tagged_type (type
))
18594 /* If this is a nested type whose containing class hasn't been written
18595 out yet, writing it out will cover this one, too. This does not apply
18596 to instantiations of member class templates; they need to be added to
18597 the containing class as they are generated. FIXME: This hurts the
18598 idea of combining type decls from multiple TUs, since we can't predict
18599 what set of template instantiations we'll get. */
18600 if (TYPE_CONTEXT (type
)
18601 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
18602 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
18604 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
18606 if (TREE_ASM_WRITTEN (type
))
18609 /* If that failed, attach ourselves to the stub. */
18610 push_decl_scope (TYPE_CONTEXT (type
));
18611 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
18614 else if (TYPE_CONTEXT (type
) != NULL_TREE
18615 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
18617 /* If this type is local to a function that hasn't been written
18618 out yet, use a NULL context for now; it will be fixed up in
18619 decls_for_scope. */
18620 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
18621 /* A declaration DIE doesn't count; nested types need to go in the
18623 if (context_die
&& is_declaration_die (context_die
))
18624 context_die
= NULL
;
18629 context_die
= declare_in_namespace (type
, context_die
);
18633 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
18635 /* This might have been written out by the call to
18636 declare_in_namespace. */
18637 if (!TREE_ASM_WRITTEN (type
))
18638 gen_enumeration_type_die (type
, context_die
);
18641 gen_struct_or_union_type_die (type
, context_die
, usage
);
18646 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
18647 it up if it is ever completed. gen_*_type_die will set it for us
18648 when appropriate. */
18651 /* Generate a type description DIE. */
18654 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
18655 enum debug_info_usage usage
)
18657 struct array_descr_info info
;
18659 if (type
== NULL_TREE
|| type
== error_mark_node
)
18662 if (TYPE_NAME (type
) != NULL_TREE
18663 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
18664 && is_redundant_typedef (TYPE_NAME (type
))
18665 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
18666 /* The DECL of this type is a typedef we don't want to emit debug
18667 info for but we want debug info for its underlying typedef.
18668 This can happen for e.g, the injected-class-name of a C++
18670 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
18672 /* If TYPE is a typedef type variant, let's generate debug info
18673 for the parent typedef which TYPE is a type of. */
18674 if (typedef_variant_p (type
))
18676 if (TREE_ASM_WRITTEN (type
))
18679 /* Prevent broken recursion; we can't hand off to the same type. */
18680 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
18682 /* Give typedefs the right scope. */
18683 context_die
= scope_die_for (type
, context_die
);
18685 TREE_ASM_WRITTEN (type
) = 1;
18687 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
18691 /* If type is an anonymous tagged type named by a typedef, let's
18692 generate debug info for the typedef. */
18693 if (is_naming_typedef_decl (TYPE_NAME (type
)))
18695 /* Use the DIE of the containing namespace as the parent DIE of
18696 the type description DIE we want to generate. */
18697 if (DECL_CONTEXT (TYPE_NAME (type
))
18698 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
18699 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
18701 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
18705 /* If this is an array type with hidden descriptor, handle it first. */
18706 if (!TREE_ASM_WRITTEN (type
)
18707 && lang_hooks
.types
.get_array_descr_info
18708 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
18709 && (dwarf_version
>= 3 || !dwarf_strict
))
18711 gen_descr_array_type_die (type
, &info
, context_die
);
18712 TREE_ASM_WRITTEN (type
) = 1;
18716 /* We are going to output a DIE to represent the unqualified version
18717 of this type (i.e. without any const or volatile qualifiers) so
18718 get the main variant (i.e. the unqualified version) of this type
18719 now. (Vectors are special because the debugging info is in the
18720 cloned type itself). */
18721 if (TREE_CODE (type
) != VECTOR_TYPE
)
18722 type
= type_main_variant (type
);
18724 if (TREE_ASM_WRITTEN (type
))
18727 switch (TREE_CODE (type
))
18733 case REFERENCE_TYPE
:
18734 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
18735 ensures that the gen_type_die recursion will terminate even if the
18736 type is recursive. Recursive types are possible in Ada. */
18737 /* ??? We could perhaps do this for all types before the switch
18739 TREE_ASM_WRITTEN (type
) = 1;
18741 /* For these types, all that is required is that we output a DIE (or a
18742 set of DIEs) to represent the "basis" type. */
18743 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18744 DINFO_USAGE_IND_USE
);
18748 /* This code is used for C++ pointer-to-data-member types.
18749 Output a description of the relevant class type. */
18750 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
18751 DINFO_USAGE_IND_USE
);
18753 /* Output a description of the type of the object pointed to. */
18754 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18755 DINFO_USAGE_IND_USE
);
18757 /* Now output a DIE to represent this pointer-to-data-member type
18759 gen_ptr_to_mbr_type_die (type
, context_die
);
18762 case FUNCTION_TYPE
:
18763 /* Force out return type (in case it wasn't forced out already). */
18764 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18765 DINFO_USAGE_DIR_USE
);
18766 gen_subroutine_type_die (type
, context_die
);
18770 /* Force out return type (in case it wasn't forced out already). */
18771 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18772 DINFO_USAGE_DIR_USE
);
18773 gen_subroutine_type_die (type
, context_die
);
18777 gen_array_type_die (type
, context_die
);
18781 gen_array_type_die (type
, context_die
);
18784 case ENUMERAL_TYPE
:
18787 case QUAL_UNION_TYPE
:
18788 gen_tagged_type_die (type
, context_die
, usage
);
18794 case FIXED_POINT_TYPE
:
18797 /* No DIEs needed for fundamental types. */
18802 /* Just use DW_TAG_unspecified_type. */
18804 dw_die_ref type_die
= lookup_type_die (type
);
18805 if (type_die
== NULL
)
18807 tree name
= TYPE_NAME (type
);
18808 if (TREE_CODE (name
) == TYPE_DECL
)
18809 name
= DECL_NAME (name
);
18810 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
18811 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
18812 equate_type_number_to_die (type
, type_die
);
18818 gcc_unreachable ();
18821 TREE_ASM_WRITTEN (type
) = 1;
18825 gen_type_die (tree type
, dw_die_ref context_die
)
18827 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
18830 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
18831 things which are local to the given block. */
18834 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
18836 int must_output_die
= 0;
18839 /* Ignore blocks that are NULL. */
18840 if (stmt
== NULL_TREE
)
18843 inlined_func
= inlined_function_outer_scope_p (stmt
);
18845 /* If the block is one fragment of a non-contiguous block, do not
18846 process the variables, since they will have been done by the
18847 origin block. Do process subblocks. */
18848 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
18852 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
18853 gen_block_die (sub
, context_die
, depth
+ 1);
18858 /* Determine if we need to output any Dwarf DIEs at all to represent this
18861 /* The outer scopes for inlinings *must* always be represented. We
18862 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
18863 must_output_die
= 1;
18866 /* Determine if this block directly contains any "significant"
18867 local declarations which we will need to output DIEs for. */
18868 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18869 /* We are not in terse mode so *any* local declaration counts
18870 as being a "significant" one. */
18871 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
18872 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
18873 && (TREE_USED (stmt
)
18874 || TREE_ASM_WRITTEN (stmt
)
18875 || BLOCK_ABSTRACT (stmt
)));
18876 else if ((TREE_USED (stmt
)
18877 || TREE_ASM_WRITTEN (stmt
)
18878 || BLOCK_ABSTRACT (stmt
))
18879 && !dwarf2out_ignore_block (stmt
))
18880 must_output_die
= 1;
18883 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
18884 DIE for any block which contains no significant local declarations at
18885 all. Rather, in such cases we just call `decls_for_scope' so that any
18886 needed Dwarf info for any sub-blocks will get properly generated. Note
18887 that in terse mode, our definition of what constitutes a "significant"
18888 local declaration gets restricted to include only inlined function
18889 instances and local (nested) function definitions. */
18890 if (must_output_die
)
18894 /* If STMT block is abstract, that means we have been called
18895 indirectly from dwarf2out_abstract_function.
18896 That function rightfully marks the descendent blocks (of
18897 the abstract function it is dealing with) as being abstract,
18898 precisely to prevent us from emitting any
18899 DW_TAG_inlined_subroutine DIE as a descendent
18900 of an abstract function instance. So in that case, we should
18901 not call gen_inlined_subroutine_die.
18903 Later though, when cgraph asks dwarf2out to emit info
18904 for the concrete instance of the function decl into which
18905 the concrete instance of STMT got inlined, the later will lead
18906 to the generation of a DW_TAG_inlined_subroutine DIE. */
18907 if (! BLOCK_ABSTRACT (stmt
))
18908 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
18911 gen_lexical_block_die (stmt
, context_die
, depth
);
18914 decls_for_scope (stmt
, context_die
, depth
);
18917 /* Process variable DECL (or variable with origin ORIGIN) within
18918 block STMT and add it to CONTEXT_DIE. */
18920 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
18923 tree decl_or_origin
= decl
? decl
: origin
;
18925 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
18926 die
= lookup_decl_die (decl_or_origin
);
18927 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
18928 && TYPE_DECL_IS_STUB (decl_or_origin
))
18929 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
18933 if (die
!= NULL
&& die
->die_parent
== NULL
)
18934 add_child_die (context_die
, die
);
18935 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
18936 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
18937 stmt
, context_die
);
18939 gen_decl_die (decl
, origin
, context_die
);
18942 /* Generate all of the decls declared within a given scope and (recursively)
18943 all of its sub-blocks. */
18946 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
18952 /* Ignore NULL blocks. */
18953 if (stmt
== NULL_TREE
)
18956 /* Output the DIEs to represent all of the data objects and typedefs
18957 declared directly within this block but not within any nested
18958 sub-blocks. Also, nested function and tag DIEs have been
18959 generated with a parent of NULL; fix that up now. */
18960 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
18961 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
18962 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
18963 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
18966 /* If we're at -g1, we're not interested in subblocks. */
18967 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
18970 /* Output the DIEs to represent all sub-blocks (and the items declared
18971 therein) of this block. */
18972 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
18974 subblocks
= BLOCK_CHAIN (subblocks
))
18975 gen_block_die (subblocks
, context_die
, depth
+ 1);
18978 /* Is this a typedef we can avoid emitting? */
18981 is_redundant_typedef (const_tree decl
)
18983 if (TYPE_DECL_IS_STUB (decl
))
18986 if (DECL_ARTIFICIAL (decl
)
18987 && DECL_CONTEXT (decl
)
18988 && is_tagged_type (DECL_CONTEXT (decl
))
18989 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
18990 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
18991 /* Also ignore the artificial member typedef for the class name. */
18997 /* Return TRUE if TYPE is a typedef that names a type for linkage
18998 purposes. This kind of typedefs is produced by the C++ FE for
19001 typedef struct {...} foo;
19003 In that case, there is no typedef variant type produced for foo.
19004 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
19008 is_naming_typedef_decl (const_tree decl
)
19010 if (decl
== NULL_TREE
19011 || TREE_CODE (decl
) != TYPE_DECL
19012 || !is_tagged_type (TREE_TYPE (decl
))
19013 || DECL_IS_BUILTIN (decl
)
19014 || is_redundant_typedef (decl
)
19015 /* It looks like Ada produces TYPE_DECLs that are very similar
19016 to C++ naming typedefs but that have different
19017 semantics. Let's be specific to c++ for now. */
19021 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
19022 && TYPE_NAME (TREE_TYPE (decl
)) == decl
19023 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
19024 != TYPE_NAME (TREE_TYPE (decl
))));
19027 /* Returns the DIE for a context. */
19029 static inline dw_die_ref
19030 get_context_die (tree context
)
19034 /* Find die that represents this context. */
19035 if (TYPE_P (context
))
19037 context
= TYPE_MAIN_VARIANT (context
);
19038 return strip_naming_typedef (context
, force_type_die (context
));
19041 return force_decl_die (context
);
19043 return comp_unit_die ();
19046 /* Returns the DIE for decl. A DIE will always be returned. */
19049 force_decl_die (tree decl
)
19051 dw_die_ref decl_die
;
19052 unsigned saved_external_flag
;
19053 tree save_fn
= NULL_TREE
;
19054 decl_die
= lookup_decl_die (decl
);
19057 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
19059 decl_die
= lookup_decl_die (decl
);
19063 switch (TREE_CODE (decl
))
19065 case FUNCTION_DECL
:
19066 /* Clear current_function_decl, so that gen_subprogram_die thinks
19067 that this is a declaration. At this point, we just want to force
19068 declaration die. */
19069 save_fn
= current_function_decl
;
19070 current_function_decl
= NULL_TREE
;
19071 gen_subprogram_die (decl
, context_die
);
19072 current_function_decl
= save_fn
;
19076 /* Set external flag to force declaration die. Restore it after
19077 gen_decl_die() call. */
19078 saved_external_flag
= DECL_EXTERNAL (decl
);
19079 DECL_EXTERNAL (decl
) = 1;
19080 gen_decl_die (decl
, NULL
, context_die
);
19081 DECL_EXTERNAL (decl
) = saved_external_flag
;
19084 case NAMESPACE_DECL
:
19085 if (dwarf_version
>= 3 || !dwarf_strict
)
19086 dwarf2out_decl (decl
);
19088 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19089 decl_die
= comp_unit_die ();
19092 case TRANSLATION_UNIT_DECL
:
19093 decl_die
= comp_unit_die ();
19097 gcc_unreachable ();
19100 /* We should be able to find the DIE now. */
19102 decl_die
= lookup_decl_die (decl
);
19103 gcc_assert (decl_die
);
19109 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
19110 always returned. */
19113 force_type_die (tree type
)
19115 dw_die_ref type_die
;
19117 type_die
= lookup_type_die (type
);
19120 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
19122 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
19123 TYPE_VOLATILE (type
), context_die
);
19124 gcc_assert (type_die
);
19129 /* Force out any required namespaces to be able to output DECL,
19130 and return the new context_die for it, if it's changed. */
19133 setup_namespace_context (tree thing
, dw_die_ref context_die
)
19135 tree context
= (DECL_P (thing
)
19136 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
19137 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
19138 /* Force out the namespace. */
19139 context_die
= force_decl_die (context
);
19141 return context_die
;
19144 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
19145 type) within its namespace, if appropriate.
19147 For compatibility with older debuggers, namespace DIEs only contain
19148 declarations; all definitions are emitted at CU scope. */
19151 declare_in_namespace (tree thing
, dw_die_ref context_die
)
19153 dw_die_ref ns_context
;
19155 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19156 return context_die
;
19158 /* If this decl is from an inlined function, then don't try to emit it in its
19159 namespace, as we will get confused. It would have already been emitted
19160 when the abstract instance of the inline function was emitted anyways. */
19161 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
19162 return context_die
;
19164 ns_context
= setup_namespace_context (thing
, context_die
);
19166 if (ns_context
!= context_die
)
19170 if (DECL_P (thing
))
19171 gen_decl_die (thing
, NULL
, ns_context
);
19173 gen_type_die (thing
, ns_context
);
19175 return context_die
;
19178 /* Generate a DIE for a namespace or namespace alias. */
19181 gen_namespace_die (tree decl
, dw_die_ref context_die
)
19183 dw_die_ref namespace_die
;
19185 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
19186 they are an alias of. */
19187 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
19189 /* Output a real namespace or module. */
19190 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19191 namespace_die
= new_die (is_fortran ()
19192 ? DW_TAG_module
: DW_TAG_namespace
,
19193 context_die
, decl
);
19194 /* For Fortran modules defined in different CU don't add src coords. */
19195 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
19197 const char *name
= dwarf2_name (decl
, 0);
19199 add_name_attribute (namespace_die
, name
);
19202 add_name_and_src_coords_attributes (namespace_die
, decl
);
19203 if (DECL_EXTERNAL (decl
))
19204 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
19205 equate_decl_number_to_die (decl
, namespace_die
);
19209 /* Output a namespace alias. */
19211 /* Force out the namespace we are an alias of, if necessary. */
19212 dw_die_ref origin_die
19213 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
19215 if (DECL_FILE_SCOPE_P (decl
)
19216 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
19217 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19218 /* Now create the namespace alias DIE. */
19219 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
19220 add_name_and_src_coords_attributes (namespace_die
, decl
);
19221 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
19222 equate_decl_number_to_die (decl
, namespace_die
);
19224 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
19225 if (want_pubnames ())
19226 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
19229 /* Generate Dwarf debug information for a decl described by DECL.
19230 The return value is currently only meaningful for PARM_DECLs,
19231 for all other decls it returns NULL. */
19234 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
19236 tree decl_or_origin
= decl
? decl
: origin
;
19237 tree class_origin
= NULL
, ultimate_origin
;
19239 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
19242 switch (TREE_CODE (decl_or_origin
))
19248 if (!is_fortran () && !is_ada ())
19250 /* The individual enumerators of an enum type get output when we output
19251 the Dwarf representation of the relevant enum type itself. */
19255 /* Emit its type. */
19256 gen_type_die (TREE_TYPE (decl
), context_die
);
19258 /* And its containing namespace. */
19259 context_die
= declare_in_namespace (decl
, context_die
);
19261 gen_const_die (decl
, context_die
);
19264 case FUNCTION_DECL
:
19265 /* Don't output any DIEs to represent mere function declarations,
19266 unless they are class members or explicit block externs. */
19267 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
19268 && DECL_FILE_SCOPE_P (decl_or_origin
)
19269 && (current_function_decl
== NULL_TREE
19270 || DECL_ARTIFICIAL (decl_or_origin
)))
19275 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
19276 on local redeclarations of global functions. That seems broken. */
19277 if (current_function_decl
!= decl
)
19278 /* This is only a declaration. */;
19281 /* If we're emitting a clone, emit info for the abstract instance. */
19282 if (origin
|| DECL_ORIGIN (decl
) != decl
)
19283 dwarf2out_abstract_function (origin
19284 ? DECL_ORIGIN (origin
)
19285 : DECL_ABSTRACT_ORIGIN (decl
));
19287 /* If we're emitting an out-of-line copy of an inline function,
19288 emit info for the abstract instance and set up to refer to it. */
19289 else if (cgraph_function_possibly_inlined_p (decl
)
19290 && ! DECL_ABSTRACT (decl
)
19291 && ! class_or_namespace_scope_p (context_die
)
19292 /* dwarf2out_abstract_function won't emit a die if this is just
19293 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
19294 that case, because that works only if we have a die. */
19295 && DECL_INITIAL (decl
) != NULL_TREE
)
19297 dwarf2out_abstract_function (decl
);
19298 set_decl_origin_self (decl
);
19301 /* Otherwise we're emitting the primary DIE for this decl. */
19302 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
19304 /* Before we describe the FUNCTION_DECL itself, make sure that we
19305 have its containing type. */
19307 origin
= decl_class_context (decl
);
19308 if (origin
!= NULL_TREE
)
19309 gen_type_die (origin
, context_die
);
19311 /* And its return type. */
19312 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
19314 /* And its virtual context. */
19315 if (DECL_VINDEX (decl
) != NULL_TREE
)
19316 gen_type_die (DECL_CONTEXT (decl
), context_die
);
19318 /* Make sure we have a member DIE for decl. */
19319 if (origin
!= NULL_TREE
)
19320 gen_type_die_for_member (origin
, decl
, context_die
);
19322 /* And its containing namespace. */
19323 context_die
= declare_in_namespace (decl
, context_die
);
19326 /* Now output a DIE to represent the function itself. */
19328 gen_subprogram_die (decl
, context_die
);
19332 /* If we are in terse mode, don't generate any DIEs to represent any
19333 actual typedefs. */
19334 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19337 /* In the special case of a TYPE_DECL node representing the declaration
19338 of some type tag, if the given TYPE_DECL is marked as having been
19339 instantiated from some other (original) TYPE_DECL node (e.g. one which
19340 was generated within the original definition of an inline function) we
19341 used to generate a special (abbreviated) DW_TAG_structure_type,
19342 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
19343 should be actually referencing those DIEs, as variable DIEs with that
19344 type would be emitted already in the abstract origin, so it was always
19345 removed during unused type prunning. Don't add anything in this
19347 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
19350 if (is_redundant_typedef (decl
))
19351 gen_type_die (TREE_TYPE (decl
), context_die
);
19353 /* Output a DIE to represent the typedef itself. */
19354 gen_typedef_die (decl
, context_die
);
19358 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
19359 gen_label_die (decl
, context_die
);
19364 /* If we are in terse mode, don't generate any DIEs to represent any
19365 variable declarations or definitions. */
19366 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19369 /* Output any DIEs that are needed to specify the type of this data
19371 if (decl_by_reference_p (decl_or_origin
))
19372 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
19374 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
19376 /* And its containing type. */
19377 class_origin
= decl_class_context (decl_or_origin
);
19378 if (class_origin
!= NULL_TREE
)
19379 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
19381 /* And its containing namespace. */
19382 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
19384 /* Now output the DIE to represent the data object itself. This gets
19385 complicated because of the possibility that the VAR_DECL really
19386 represents an inlined instance of a formal parameter for an inline
19388 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
19389 if (ultimate_origin
!= NULL_TREE
19390 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
19391 gen_formal_parameter_die (decl
, origin
,
19392 true /* Emit name attribute. */,
19395 gen_variable_die (decl
, origin
, context_die
);
19399 /* Ignore the nameless fields that are used to skip bits but handle C++
19400 anonymous unions and structs. */
19401 if (DECL_NAME (decl
) != NULL_TREE
19402 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
19403 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
19405 gen_type_die (member_declared_type (decl
), context_die
);
19406 gen_field_die (decl
, context_die
);
19411 if (DECL_BY_REFERENCE (decl_or_origin
))
19412 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
19414 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
19415 return gen_formal_parameter_die (decl
, origin
,
19416 true /* Emit name attribute. */,
19419 case NAMESPACE_DECL
:
19420 case IMPORTED_DECL
:
19421 if (dwarf_version
>= 3 || !dwarf_strict
)
19422 gen_namespace_die (decl
, context_die
);
19426 /* Probably some frontend-internal decl. Assume we don't care. */
19427 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
19434 /* Output debug information for global decl DECL. Called from toplev.c after
19435 compilation proper has finished. */
19438 dwarf2out_global_decl (tree decl
)
19440 /* Output DWARF2 information for file-scope tentative data object
19441 declarations, file-scope (extern) function declarations (which
19442 had no corresponding body) and file-scope tagged type declarations
19443 and definitions which have not yet been forced out. */
19444 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
19445 dwarf2out_decl (decl
);
19448 /* Output debug information for type decl DECL. Called from toplev.c
19449 and from language front ends (to record built-in types). */
19451 dwarf2out_type_decl (tree decl
, int local
)
19454 dwarf2out_decl (decl
);
19457 /* Output debug information for imported module or decl DECL.
19458 NAME is non-NULL name in the lexical block if the decl has been renamed.
19459 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
19460 that DECL belongs to.
19461 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
19463 dwarf2out_imported_module_or_decl_1 (tree decl
,
19465 tree lexical_block
,
19466 dw_die_ref lexical_block_die
)
19468 expanded_location xloc
;
19469 dw_die_ref imported_die
= NULL
;
19470 dw_die_ref at_import_die
;
19472 if (TREE_CODE (decl
) == IMPORTED_DECL
)
19474 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
19475 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
19479 xloc
= expand_location (input_location
);
19481 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
19483 at_import_die
= force_type_die (TREE_TYPE (decl
));
19484 /* For namespace N { typedef void T; } using N::T; base_type_die
19485 returns NULL, but DW_TAG_imported_declaration requires
19486 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
19487 if (!at_import_die
)
19489 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
19490 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
19491 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
19492 gcc_assert (at_import_die
);
19497 at_import_die
= lookup_decl_die (decl
);
19498 if (!at_import_die
)
19500 /* If we're trying to avoid duplicate debug info, we may not have
19501 emitted the member decl for this field. Emit it now. */
19502 if (TREE_CODE (decl
) == FIELD_DECL
)
19504 tree type
= DECL_CONTEXT (decl
);
19506 if (TYPE_CONTEXT (type
)
19507 && TYPE_P (TYPE_CONTEXT (type
))
19508 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
19509 DINFO_USAGE_DIR_USE
))
19511 gen_type_die_for_member (type
, decl
,
19512 get_context_die (TYPE_CONTEXT (type
)));
19514 at_import_die
= force_decl_die (decl
);
19518 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
19520 if (dwarf_version
>= 3 || !dwarf_strict
)
19521 imported_die
= new_die (DW_TAG_imported_module
,
19528 imported_die
= new_die (DW_TAG_imported_declaration
,
19532 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
19533 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
19535 add_AT_string (imported_die
, DW_AT_name
,
19536 IDENTIFIER_POINTER (name
));
19537 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
19540 /* Output debug information for imported module or decl DECL.
19541 NAME is non-NULL name in context if the decl has been renamed.
19542 CHILD is true if decl is one of the renamed decls as part of
19543 importing whole module. */
19546 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
19549 /* dw_die_ref at_import_die; */
19550 dw_die_ref scope_die
;
19552 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19557 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
19558 We need decl DIE for reference and scope die. First, get DIE for the decl
19561 /* Get the scope die for decl context. Use comp_unit_die for global module
19562 or decl. If die is not found for non globals, force new die. */
19564 && TYPE_P (context
)
19565 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
19568 if (!(dwarf_version
>= 3 || !dwarf_strict
))
19571 scope_die
= get_context_die (context
);
19575 gcc_assert (scope_die
->die_child
);
19576 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
19577 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
19578 scope_die
= scope_die
->die_child
;
19581 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
19582 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
19586 /* Write the debugging output for DECL. */
19589 dwarf2out_decl (tree decl
)
19591 dw_die_ref context_die
= comp_unit_die ();
19593 switch (TREE_CODE (decl
))
19598 case FUNCTION_DECL
:
19599 /* What we would really like to do here is to filter out all mere
19600 file-scope declarations of file-scope functions which are never
19601 referenced later within this translation unit (and keep all of ones
19602 that *are* referenced later on) but we aren't clairvoyant, so we have
19603 no idea which functions will be referenced in the future (i.e. later
19604 on within the current translation unit). So here we just ignore all
19605 file-scope function declarations which are not also definitions. If
19606 and when the debugger needs to know something about these functions,
19607 it will have to hunt around and find the DWARF information associated
19608 with the definition of the function.
19610 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
19611 nodes represent definitions and which ones represent mere
19612 declarations. We have to check DECL_INITIAL instead. That's because
19613 the C front-end supports some weird semantics for "extern inline"
19614 function definitions. These can get inlined within the current
19615 translation unit (and thus, we need to generate Dwarf info for their
19616 abstract instances so that the Dwarf info for the concrete inlined
19617 instances can have something to refer to) but the compiler never
19618 generates any out-of-lines instances of such things (despite the fact
19619 that they *are* definitions).
19621 The important point is that the C front-end marks these "extern
19622 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
19623 them anyway. Note that the C++ front-end also plays some similar games
19624 for inline function definitions appearing within include files which
19625 also contain `#pragma interface' pragmas.
19627 If we are called from dwarf2out_abstract_function output a DIE
19628 anyway. We can end up here this way with early inlining and LTO
19629 where the inlined function is output in a different LTRANS unit
19631 if (DECL_INITIAL (decl
) == NULL_TREE
19632 && ! DECL_ABSTRACT (decl
))
19635 /* If we're a nested function, initially use a parent of NULL; if we're
19636 a plain function, this will be fixed up in decls_for_scope. If
19637 we're a method, it will be ignored, since we already have a DIE. */
19638 if (decl_function_context (decl
)
19639 /* But if we're in terse mode, we don't care about scope. */
19640 && debug_info_level
> DINFO_LEVEL_TERSE
)
19641 context_die
= NULL
;
19645 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
19646 declaration and if the declaration was never even referenced from
19647 within this entire compilation unit. We suppress these DIEs in
19648 order to save space in the .debug section (by eliminating entries
19649 which are probably useless). Note that we must not suppress
19650 block-local extern declarations (whether used or not) because that
19651 would screw-up the debugger's name lookup mechanism and cause it to
19652 miss things which really ought to be in scope at a given point. */
19653 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
19656 /* For local statics lookup proper context die. */
19657 if (TREE_STATIC (decl
)
19658 && DECL_CONTEXT (decl
)
19659 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
19660 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
19662 /* If we are in terse mode, don't generate any DIEs to represent any
19663 variable declarations or definitions. */
19664 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19669 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19671 if (!is_fortran () && !is_ada ())
19673 if (TREE_STATIC (decl
) && decl_function_context (decl
))
19674 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
19677 case NAMESPACE_DECL
:
19678 case IMPORTED_DECL
:
19679 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19681 if (lookup_decl_die (decl
) != NULL
)
19686 /* Don't emit stubs for types unless they are needed by other DIEs. */
19687 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
19690 /* Don't bother trying to generate any DIEs to represent any of the
19691 normal built-in types for the language we are compiling. */
19692 if (DECL_IS_BUILTIN (decl
))
19695 /* If we are in terse mode, don't generate any DIEs for types. */
19696 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19699 /* If we're a function-scope tag, initially use a parent of NULL;
19700 this will be fixed up in decls_for_scope. */
19701 if (decl_function_context (decl
))
19702 context_die
= NULL
;
19710 gen_decl_die (decl
, NULL
, context_die
);
19713 /* Write the debugging output for DECL. */
19716 dwarf2out_function_decl (tree decl
)
19718 dwarf2out_decl (decl
);
19719 call_arg_locations
= NULL
;
19720 call_arg_loc_last
= NULL
;
19721 call_site_count
= -1;
19722 tail_call_site_count
= -1;
19723 VEC_free (dw_die_ref
, heap
, block_map
);
19724 htab_empty (decl_loc_table
);
19725 htab_empty (cached_dw_loc_list_table
);
19728 /* Output a marker (i.e. a label) for the beginning of the generated code for
19729 a lexical block. */
19732 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
19733 unsigned int blocknum
)
19735 switch_to_section (current_function_section ());
19736 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
19739 /* Output a marker (i.e. a label) for the end of the generated code for a
19743 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
19745 switch_to_section (current_function_section ());
19746 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
19749 /* Returns nonzero if it is appropriate not to emit any debugging
19750 information for BLOCK, because it doesn't contain any instructions.
19752 Don't allow this for blocks with nested functions or local classes
19753 as we would end up with orphans, and in the presence of scheduling
19754 we may end up calling them anyway. */
19757 dwarf2out_ignore_block (const_tree block
)
19762 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
19763 if (TREE_CODE (decl
) == FUNCTION_DECL
19764 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
19766 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
19768 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
19769 if (TREE_CODE (decl
) == FUNCTION_DECL
19770 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
19777 /* Hash table routines for file_hash. */
19780 file_table_eq (const void *p1_p
, const void *p2_p
)
19782 const struct dwarf_file_data
*const p1
=
19783 (const struct dwarf_file_data
*) p1_p
;
19784 const char *const p2
= (const char *) p2_p
;
19785 return filename_cmp (p1
->filename
, p2
) == 0;
19789 file_table_hash (const void *p_p
)
19791 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
19792 return htab_hash_string (p
->filename
);
19795 /* Lookup FILE_NAME (in the list of filenames that we know about here in
19796 dwarf2out.c) and return its "index". The index of each (known) filename is
19797 just a unique number which is associated with only that one filename. We
19798 need such numbers for the sake of generating labels (in the .debug_sfnames
19799 section) and references to those files numbers (in the .debug_srcinfo
19800 and.debug_macinfo sections). If the filename given as an argument is not
19801 found in our current list, add it to the list and assign it the next
19802 available unique index number. In order to speed up searches, we remember
19803 the index of the filename was looked up last. This handles the majority of
19806 static struct dwarf_file_data
*
19807 lookup_filename (const char *file_name
)
19810 struct dwarf_file_data
* created
;
19812 /* Check to see if the file name that was searched on the previous
19813 call matches this file name. If so, return the index. */
19814 if (file_table_last_lookup
19815 && (file_name
== file_table_last_lookup
->filename
19816 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
19817 return file_table_last_lookup
;
19819 /* Didn't match the previous lookup, search the table. */
19820 slot
= htab_find_slot_with_hash (file_table
, file_name
,
19821 htab_hash_string (file_name
), INSERT
);
19823 return (struct dwarf_file_data
*) *slot
;
19825 created
= ggc_alloc_dwarf_file_data ();
19826 created
->filename
= file_name
;
19827 created
->emitted_number
= 0;
19832 /* If the assembler will construct the file table, then translate the compiler
19833 internal file table number into the assembler file table number, and emit
19834 a .file directive if we haven't already emitted one yet. The file table
19835 numbers are different because we prune debug info for unused variables and
19836 types, which may include filenames. */
19839 maybe_emit_file (struct dwarf_file_data
* fd
)
19841 if (! fd
->emitted_number
)
19843 if (last_emitted_file
)
19844 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
19846 fd
->emitted_number
= 1;
19847 last_emitted_file
= fd
;
19849 if (DWARF2_ASM_LINE_DEBUG_INFO
)
19851 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
19852 output_quoted_string (asm_out_file
,
19853 remap_debug_filename (fd
->filename
));
19854 fputc ('\n', asm_out_file
);
19858 return fd
->emitted_number
;
19861 /* Schedule generation of a DW_AT_const_value attribute to DIE.
19862 That generation should happen after function debug info has been
19863 generated. The value of the attribute is the constant value of ARG. */
19866 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
19868 die_arg_entry entry
;
19873 if (!tmpl_value_parm_die_table
)
19874 tmpl_value_parm_die_table
19875 = VEC_alloc (die_arg_entry
, gc
, 32);
19879 VEC_safe_push (die_arg_entry
, gc
,
19880 tmpl_value_parm_die_table
,
19884 /* Return TRUE if T is an instance of generic type, FALSE
19888 generic_type_p (tree t
)
19890 if (t
== NULL_TREE
|| !TYPE_P (t
))
19892 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
19895 /* Schedule the generation of the generic parameter dies for the
19896 instance of generic type T. The proper generation itself is later
19897 done by gen_scheduled_generic_parms_dies. */
19900 schedule_generic_params_dies_gen (tree t
)
19902 if (!generic_type_p (t
))
19905 if (generic_type_instances
== NULL
)
19906 generic_type_instances
= VEC_alloc (tree
, gc
, 256);
19908 VEC_safe_push (tree
, gc
, generic_type_instances
, t
);
19911 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
19912 by append_entry_to_tmpl_value_parm_die_table. This function must
19913 be called after function DIEs have been generated. */
19916 gen_remaining_tmpl_value_param_die_attribute (void)
19918 if (tmpl_value_parm_die_table
)
19923 FOR_EACH_VEC_ELT (die_arg_entry
, tmpl_value_parm_die_table
, i
, e
)
19924 tree_add_const_value_attribute (e
->die
, e
->arg
);
19928 /* Generate generic parameters DIEs for instances of generic types
19929 that have been previously scheduled by
19930 schedule_generic_params_dies_gen. This function must be called
19931 after all the types of the CU have been laid out. */
19934 gen_scheduled_generic_parms_dies (void)
19939 if (generic_type_instances
== NULL
)
19942 FOR_EACH_VEC_ELT (tree
, generic_type_instances
, i
, t
)
19943 gen_generic_params_dies (t
);
19947 /* Replace DW_AT_name for the decl with name. */
19950 dwarf2out_set_name (tree decl
, tree name
)
19956 die
= TYPE_SYMTAB_DIE (decl
);
19960 dname
= dwarf2_name (name
, 0);
19964 attr
= get_AT (die
, DW_AT_name
);
19967 struct indirect_string_node
*node
;
19969 node
= find_AT_string (dname
);
19970 /* replace the string. */
19971 attr
->dw_attr_val
.v
.val_str
= node
;
19975 add_name_attribute (die
, dname
);
19978 /* Called by the final INSN scan whenever we see a var location. We
19979 use it to drop labels in the right places, and throw the location in
19980 our lookup table. */
19983 dwarf2out_var_location (rtx loc_note
)
19985 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
19986 struct var_loc_node
*newloc
;
19987 rtx next_real
, next_note
;
19988 static const char *last_label
;
19989 static const char *last_postcall_label
;
19990 static bool last_in_cold_section_p
;
19991 static rtx expected_next_loc_note
;
19995 if (!NOTE_P (loc_note
))
19997 if (CALL_P (loc_note
))
20000 if (SIBLING_CALL_P (loc_note
))
20001 tail_call_site_count
++;
20006 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
20007 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
20010 /* Optimize processing a large consecutive sequence of location
20011 notes so we don't spend too much time in next_real_insn. If the
20012 next insn is another location note, remember the next_real_insn
20013 calculation for next time. */
20014 next_real
= cached_next_real_insn
;
20017 if (expected_next_loc_note
!= loc_note
)
20018 next_real
= NULL_RTX
;
20021 next_note
= NEXT_INSN (loc_note
);
20023 || INSN_DELETED_P (next_note
)
20024 || GET_CODE (next_note
) != NOTE
20025 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
20026 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
20027 next_note
= NULL_RTX
;
20030 next_real
= next_real_insn (loc_note
);
20034 expected_next_loc_note
= next_note
;
20035 cached_next_real_insn
= next_real
;
20038 cached_next_real_insn
= NULL_RTX
;
20040 /* If there are no instructions which would be affected by this note,
20041 don't do anything. */
20043 && next_real
== NULL_RTX
20044 && !NOTE_DURING_CALL_P (loc_note
))
20047 if (next_real
== NULL_RTX
)
20048 next_real
= get_last_insn ();
20050 /* If there were any real insns between note we processed last time
20051 and this note (or if it is the first note), clear
20052 last_{,postcall_}label so that they are not reused this time. */
20053 if (last_var_location_insn
== NULL_RTX
20054 || last_var_location_insn
!= next_real
20055 || last_in_cold_section_p
!= in_cold_section_p
)
20058 last_postcall_label
= NULL
;
20063 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
20064 newloc
= add_var_loc_to_decl (decl
, loc_note
,
20065 NOTE_DURING_CALL_P (loc_note
)
20066 ? last_postcall_label
: last_label
);
20067 if (newloc
== NULL
)
20076 /* If there were no real insns between note we processed last time
20077 and this note, use the label we emitted last time. Otherwise
20078 create a new label and emit it. */
20079 if (last_label
== NULL
)
20081 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
20082 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
20084 last_label
= ggc_strdup (loclabel
);
20089 struct call_arg_loc_node
*ca_loc
20090 = ggc_alloc_cleared_call_arg_loc_node ();
20091 rtx prev
= prev_real_insn (loc_note
), x
;
20092 ca_loc
->call_arg_loc_note
= loc_note
;
20093 ca_loc
->next
= NULL
;
20094 ca_loc
->label
= last_label
;
20097 || (NONJUMP_INSN_P (prev
)
20098 && GET_CODE (PATTERN (prev
)) == SEQUENCE
20099 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
20100 if (!CALL_P (prev
))
20101 prev
= XVECEXP (PATTERN (prev
), 0, 0);
20102 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
20103 x
= get_call_rtx_from (PATTERN (prev
));
20106 x
= XEXP (XEXP (x
, 0), 0);
20107 if (GET_CODE (x
) == SYMBOL_REF
20108 && SYMBOL_REF_DECL (x
)
20109 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
20110 ca_loc
->symbol_ref
= x
;
20112 ca_loc
->block
= insn_scope (prev
);
20113 if (call_arg_locations
)
20114 call_arg_loc_last
->next
= ca_loc
;
20116 call_arg_locations
= ca_loc
;
20117 call_arg_loc_last
= ca_loc
;
20119 else if (!NOTE_DURING_CALL_P (loc_note
))
20120 newloc
->label
= last_label
;
20123 if (!last_postcall_label
)
20125 sprintf (loclabel
, "%s-1", last_label
);
20126 last_postcall_label
= ggc_strdup (loclabel
);
20128 newloc
->label
= last_postcall_label
;
20131 last_var_location_insn
= next_real
;
20132 last_in_cold_section_p
= in_cold_section_p
;
20135 /* Note in one location list that text section has changed. */
20138 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
20140 var_loc_list
*list
= (var_loc_list
*) *slot
;
20142 list
->last_before_switch
20143 = list
->last
->next
? list
->last
->next
: list
->last
;
20147 /* Note in all location lists that text section has changed. */
20150 var_location_switch_text_section (void)
20152 if (decl_loc_table
== NULL
)
20155 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
20158 /* Create a new line number table. */
20160 static dw_line_info_table
*
20161 new_line_info_table (void)
20163 dw_line_info_table
*table
;
20165 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
20166 table
->file_num
= 1;
20167 table
->line_num
= 1;
20168 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
20173 /* Lookup the "current" table into which we emit line info, so
20174 that we don't have to do it for every source line. */
20177 set_cur_line_info_table (section
*sec
)
20179 dw_line_info_table
*table
;
20181 if (sec
== text_section
)
20182 table
= text_section_line_info
;
20183 else if (sec
== cold_text_section
)
20185 table
= cold_text_section_line_info
;
20188 cold_text_section_line_info
= table
= new_line_info_table ();
20189 table
->end_label
= cold_end_label
;
20194 const char *end_label
;
20196 if (flag_reorder_blocks_and_partition
)
20198 if (in_cold_section_p
)
20199 end_label
= crtl
->subsections
.cold_section_end_label
;
20201 end_label
= crtl
->subsections
.hot_section_end_label
;
20205 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20206 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
20207 current_function_funcdef_no
);
20208 end_label
= ggc_strdup (label
);
20211 table
= new_line_info_table ();
20212 table
->end_label
= end_label
;
20214 VEC_safe_push (dw_line_info_table_p
, gc
, separate_line_info
, table
);
20217 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20218 table
->is_stmt
= (cur_line_info_table
20219 ? cur_line_info_table
->is_stmt
20220 : DWARF_LINE_DEFAULT_IS_STMT_START
);
20221 cur_line_info_table
= table
;
20225 /* We need to reset the locations at the beginning of each
20226 function. We can't do this in the end_function hook, because the
20227 declarations that use the locations won't have been output when
20228 that hook is called. Also compute have_multiple_function_sections here. */
20231 dwarf2out_begin_function (tree fun
)
20233 section
*sec
= function_section (fun
);
20235 if (sec
!= text_section
)
20236 have_multiple_function_sections
= true;
20238 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
20240 gcc_assert (current_function_decl
== fun
);
20241 cold_text_section
= unlikely_text_section ();
20242 switch_to_section (cold_text_section
);
20243 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
20244 switch_to_section (sec
);
20247 dwarf2out_note_section_used ();
20248 call_site_count
= 0;
20249 tail_call_site_count
= 0;
20251 set_cur_line_info_table (sec
);
20254 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
20257 push_dw_line_info_entry (dw_line_info_table
*table
,
20258 enum dw_line_info_opcode opcode
, unsigned int val
)
20260 dw_line_info_entry e
;
20263 VEC_safe_push (dw_line_info_entry
, gc
, table
->entries
, e
);
20266 /* Output a label to mark the beginning of a source code line entry
20267 and record information relating to this source line, in
20268 'line_info_table' for later output of the .debug_line section. */
20269 /* ??? The discriminator parameter ought to be unsigned. */
20272 dwarf2out_source_line (unsigned int line
, const char *filename
,
20273 int discriminator
, bool is_stmt
)
20275 unsigned int file_num
;
20276 dw_line_info_table
*table
;
20278 if (debug_info_level
< DINFO_LEVEL_NORMAL
|| line
== 0)
20281 /* The discriminator column was added in dwarf4. Simplify the below
20282 by simply removing it if we're not supposed to output it. */
20283 if (dwarf_version
< 4 && dwarf_strict
)
20286 table
= cur_line_info_table
;
20287 file_num
= maybe_emit_file (lookup_filename (filename
));
20289 /* ??? TODO: Elide duplicate line number entries. Traditionally,
20290 the debugger has used the second (possibly duplicate) line number
20291 at the beginning of the function to mark the end of the prologue.
20292 We could eliminate any other duplicates within the function. For
20293 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
20294 that second line number entry. */
20295 /* Recall that this end-of-prologue indication is *not* the same thing
20296 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
20297 to which the hook corresponds, follows the last insn that was
20298 emitted by gen_prologue. What we need is to precede the first insn
20299 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
20300 insn that corresponds to something the user wrote. These may be
20301 very different locations once scheduling is enabled. */
20303 if (0 && file_num
== table
->file_num
20304 && line
== table
->line_num
20305 && discriminator
== table
->discrim_num
20306 && is_stmt
== table
->is_stmt
)
20309 switch_to_section (current_function_section ());
20311 /* If requested, emit something human-readable. */
20312 if (flag_debug_asm
)
20313 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
20315 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20317 /* Emit the .loc directive understood by GNU as. */
20318 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
20319 file_num, line, is_stmt, discriminator */
20320 fputs ("\t.loc ", asm_out_file
);
20321 fprint_ul (asm_out_file
, file_num
);
20322 putc (' ', asm_out_file
);
20323 fprint_ul (asm_out_file
, line
);
20324 putc (' ', asm_out_file
);
20325 putc ('0', asm_out_file
);
20327 if (is_stmt
!= table
->is_stmt
)
20329 fputs (" is_stmt ", asm_out_file
);
20330 putc (is_stmt
? '1' : '0', asm_out_file
);
20332 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
20334 gcc_assert (discriminator
> 0);
20335 fputs (" discriminator ", asm_out_file
);
20336 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
20338 putc ('\n', asm_out_file
);
20342 unsigned int label_num
= ++line_info_label_num
;
20344 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
20346 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
20347 if (file_num
!= table
->file_num
)
20348 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
20349 if (discriminator
!= table
->discrim_num
)
20350 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
20351 if (is_stmt
!= table
->is_stmt
)
20352 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
20353 push_dw_line_info_entry (table
, LI_set_line
, line
);
20356 table
->file_num
= file_num
;
20357 table
->line_num
= line
;
20358 table
->discrim_num
= discriminator
;
20359 table
->is_stmt
= is_stmt
;
20360 table
->in_use
= true;
20363 /* Record the beginning of a new source file. */
20366 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
20368 if (flag_eliminate_dwarf2_dups
)
20370 /* Record the beginning of the file for break_out_includes. */
20371 dw_die_ref bincl_die
;
20373 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
20374 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
20377 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20380 e
.code
= DW_MACINFO_start_file
;
20382 e
.info
= ggc_strdup (filename
);
20383 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, e
);
20387 /* Record the end of a source file. */
20390 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
20392 if (flag_eliminate_dwarf2_dups
)
20393 /* Record the end of the file for break_out_includes. */
20394 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
20396 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20399 e
.code
= DW_MACINFO_end_file
;
20402 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, e
);
20406 /* Called from debug_define in toplev.c. The `buffer' parameter contains
20407 the tail part of the directive line, i.e. the part which is past the
20408 initial whitespace, #, whitespace, directive-name, whitespace part. */
20411 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
20412 const char *buffer ATTRIBUTE_UNUSED
)
20414 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20417 /* Insert a dummy first entry to be able to optimize the whole
20418 predefined macro block using DW_MACRO_GNU_transparent_include. */
20419 if (VEC_empty (macinfo_entry
, macinfo_table
) && lineno
<= 1)
20424 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, e
);
20426 e
.code
= DW_MACINFO_define
;
20428 e
.info
= ggc_strdup (buffer
);
20429 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, e
);
20433 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
20434 the tail part of the directive line, i.e. the part which is past the
20435 initial whitespace, #, whitespace, directive-name, whitespace part. */
20438 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
20439 const char *buffer ATTRIBUTE_UNUSED
)
20441 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20444 /* Insert a dummy first entry to be able to optimize the whole
20445 predefined macro block using DW_MACRO_GNU_transparent_include. */
20446 if (VEC_empty (macinfo_entry
, macinfo_table
) && lineno
<= 1)
20451 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, e
);
20453 e
.code
= DW_MACINFO_undef
;
20455 e
.info
= ggc_strdup (buffer
);
20456 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, e
);
20460 /* Routines to manipulate hash table of CUs. */
20463 htab_macinfo_hash (const void *of
)
20465 const macinfo_entry
*const entry
=
20466 (const macinfo_entry
*) of
;
20468 return htab_hash_string (entry
->info
);
20472 htab_macinfo_eq (const void *of1
, const void *of2
)
20474 const macinfo_entry
*const entry1
= (const macinfo_entry
*) of1
;
20475 const macinfo_entry
*const entry2
= (const macinfo_entry
*) of2
;
20477 return !strcmp (entry1
->info
, entry2
->info
);
20480 /* Output a single .debug_macinfo entry. */
20483 output_macinfo_op (macinfo_entry
*ref
)
20487 struct indirect_string_node
*node
;
20488 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20489 struct dwarf_file_data
*fd
;
20493 case DW_MACINFO_start_file
:
20494 fd
= lookup_filename (ref
->info
);
20495 file_num
= maybe_emit_file (fd
);
20496 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
20497 dw2_asm_output_data_uleb128 (ref
->lineno
,
20498 "Included from line number %lu",
20499 (unsigned long) ref
->lineno
);
20500 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
20502 case DW_MACINFO_end_file
:
20503 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
20505 case DW_MACINFO_define
:
20506 case DW_MACINFO_undef
:
20507 len
= strlen (ref
->info
) + 1;
20509 && len
> DWARF_OFFSET_SIZE
20510 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
20511 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
20513 ref
->code
= ref
->code
== DW_MACINFO_define
20514 ? DW_MACRO_GNU_define_indirect
20515 : DW_MACRO_GNU_undef_indirect
;
20516 output_macinfo_op (ref
);
20519 dw2_asm_output_data (1, ref
->code
,
20520 ref
->code
== DW_MACINFO_define
20521 ? "Define macro" : "Undefine macro");
20522 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
20523 (unsigned long) ref
->lineno
);
20524 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
20526 case DW_MACRO_GNU_define_indirect
:
20527 case DW_MACRO_GNU_undef_indirect
:
20528 node
= find_AT_string (ref
->info
);
20529 if (node
->form
!= DW_FORM_strp
)
20532 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
20533 ++dw2_string_counter
;
20534 node
->label
= xstrdup (label
);
20535 node
->form
= DW_FORM_strp
;
20537 dw2_asm_output_data (1, ref
->code
,
20538 ref
->code
== DW_MACRO_GNU_define_indirect
20539 ? "Define macro indirect"
20540 : "Undefine macro indirect");
20541 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
20542 (unsigned long) ref
->lineno
);
20543 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
20544 debug_str_section
, "The macro: \"%s\"",
20547 case DW_MACRO_GNU_transparent_include
:
20548 dw2_asm_output_data (1, ref
->code
, "Transparent include");
20549 ASM_GENERATE_INTERNAL_LABEL (label
,
20550 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
20551 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
20554 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
20555 ASM_COMMENT_START
, (unsigned long) ref
->code
);
20560 /* Attempt to make a sequence of define/undef macinfo ops shareable with
20561 other compilation unit .debug_macinfo sections. IDX is the first
20562 index of a define/undef, return the number of ops that should be
20563 emitted in a comdat .debug_macinfo section and emit
20564 a DW_MACRO_GNU_transparent_include entry referencing it.
20565 If the define/undef entry should be emitted normally, return 0. */
20568 optimize_macinfo_range (unsigned int idx
, VEC (macinfo_entry
, gc
) *files
,
20569 htab_t
*macinfo_htab
)
20571 macinfo_entry
*first
, *second
, *cur
, *inc
;
20572 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
20573 unsigned char checksum
[16];
20574 struct md5_ctx ctx
;
20575 char *grp_name
, *tail
;
20577 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
20580 first
= &VEC_index (macinfo_entry
, macinfo_table
, idx
);
20581 second
= &VEC_index (macinfo_entry
, macinfo_table
, idx
+ 1);
20583 /* Optimize only if there are at least two consecutive define/undef ops,
20584 and either all of them are before first DW_MACINFO_start_file
20585 with lineno {0,1} (i.e. predefined macro block), or all of them are
20586 in some included header file. */
20587 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
20589 if (VEC_empty (macinfo_entry
, files
))
20591 if (first
->lineno
> 1 || second
->lineno
> 1)
20594 else if (first
->lineno
== 0)
20597 /* Find the last define/undef entry that can be grouped together
20598 with first and at the same time compute md5 checksum of their
20599 codes, linenumbers and strings. */
20600 md5_init_ctx (&ctx
);
20601 for (i
= idx
; VEC_iterate (macinfo_entry
, macinfo_table
, i
, cur
); i
++)
20602 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
20604 else if (VEC_empty (macinfo_entry
, files
) && cur
->lineno
> 1)
20608 unsigned char code
= cur
->code
;
20609 md5_process_bytes (&code
, 1, &ctx
);
20610 checksum_uleb128 (cur
->lineno
, &ctx
);
20611 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
20613 md5_finish_ctx (&ctx
, checksum
);
20616 /* From the containing include filename (if any) pick up just
20617 usable characters from its basename. */
20618 if (VEC_empty (macinfo_entry
, files
))
20621 base
= lbasename (VEC_last (macinfo_entry
, files
).info
);
20622 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
20623 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
20624 encoded_filename_len
++;
20625 /* Count . at the end. */
20626 if (encoded_filename_len
)
20627 encoded_filename_len
++;
20629 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
20630 linebuf_len
= strlen (linebuf
);
20632 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
20633 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
20635 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
20636 tail
= grp_name
+ 4;
20637 if (encoded_filename_len
)
20639 for (i
= 0; base
[i
]; i
++)
20640 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
20644 memcpy (tail
, linebuf
, linebuf_len
);
20645 tail
+= linebuf_len
;
20647 for (i
= 0; i
< 16; i
++)
20648 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
20650 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
20651 in the empty vector entry before the first define/undef. */
20652 inc
= &VEC_index (macinfo_entry
, macinfo_table
, idx
- 1);
20653 inc
->code
= DW_MACRO_GNU_transparent_include
;
20655 inc
->info
= ggc_strdup (grp_name
);
20656 if (*macinfo_htab
== NULL
)
20657 *macinfo_htab
= htab_create (10, htab_macinfo_hash
, htab_macinfo_eq
, NULL
);
20658 /* Avoid emitting duplicates. */
20659 slot
= htab_find_slot (*macinfo_htab
, inc
, INSERT
);
20664 /* If such an entry has been used before, just emit
20665 a DW_MACRO_GNU_transparent_include op. */
20666 inc
= (macinfo_entry
*) *slot
;
20667 output_macinfo_op (inc
);
20668 /* And clear all macinfo_entry in the range to avoid emitting them
20669 in the second pass. */
20671 VEC_iterate (macinfo_entry
, macinfo_table
, i
, cur
)
20672 && i
< idx
+ count
;
20682 inc
->lineno
= htab_elements (*macinfo_htab
);
20683 output_macinfo_op (inc
);
20688 /* Output macinfo section(s). */
20691 output_macinfo (void)
20694 unsigned long length
= VEC_length (macinfo_entry
, macinfo_table
);
20695 macinfo_entry
*ref
;
20696 VEC (macinfo_entry
, gc
) *files
= NULL
;
20697 htab_t macinfo_htab
= NULL
;
20702 /* output_macinfo* uses these interchangeably. */
20703 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
20704 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
20705 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
20706 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
20708 /* For .debug_macro emit the section header. */
20711 dw2_asm_output_data (2, 4, "DWARF macro version number");
20712 if (DWARF_OFFSET_SIZE
== 8)
20713 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
20715 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
20716 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_line_section_label
,
20717 debug_line_section
, NULL
);
20720 /* In the first loop, it emits the primary .debug_macinfo section
20721 and after each emitted op the macinfo_entry is cleared.
20722 If a longer range of define/undef ops can be optimized using
20723 DW_MACRO_GNU_transparent_include, the
20724 DW_MACRO_GNU_transparent_include op is emitted and kept in
20725 the vector before the first define/undef in the range and the
20726 whole range of define/undef ops is not emitted and kept. */
20727 for (i
= 0; VEC_iterate (macinfo_entry
, macinfo_table
, i
, ref
); i
++)
20731 case DW_MACINFO_start_file
:
20732 VEC_safe_push (macinfo_entry
, gc
, files
, *ref
);
20734 case DW_MACINFO_end_file
:
20735 if (!VEC_empty (macinfo_entry
, files
))
20736 VEC_pop (macinfo_entry
, files
);
20738 case DW_MACINFO_define
:
20739 case DW_MACINFO_undef
:
20741 && HAVE_COMDAT_GROUP
20742 && VEC_length (macinfo_entry
, files
) != 1
20745 && VEC_index (macinfo_entry
, macinfo_table
, i
- 1).code
== 0)
20747 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
20756 /* A dummy entry may be inserted at the beginning to be able
20757 to optimize the whole block of predefined macros. */
20763 output_macinfo_op (ref
);
20768 if (macinfo_htab
== NULL
)
20771 htab_delete (macinfo_htab
);
20773 /* If any DW_MACRO_GNU_transparent_include were used, on those
20774 DW_MACRO_GNU_transparent_include entries terminate the
20775 current chain and switch to a new comdat .debug_macinfo
20776 section and emit the define/undef entries within it. */
20777 for (i
= 0; VEC_iterate (macinfo_entry
, macinfo_table
, i
, ref
); i
++)
20782 case DW_MACRO_GNU_transparent_include
:
20784 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20785 tree comdat_key
= get_identifier (ref
->info
);
20786 /* Terminate the previous .debug_macinfo section. */
20787 dw2_asm_output_data (1, 0, "End compilation unit");
20788 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
20790 | SECTION_LINKONCE
,
20792 ASM_GENERATE_INTERNAL_LABEL (label
,
20793 DEBUG_MACRO_SECTION_LABEL
,
20795 ASM_OUTPUT_LABEL (asm_out_file
, label
);
20798 dw2_asm_output_data (2, 4, "DWARF macro version number");
20799 if (DWARF_OFFSET_SIZE
== 8)
20800 dw2_asm_output_data (1, 1, "Flags: 64-bit");
20802 dw2_asm_output_data (1, 0, "Flags: 32-bit");
20805 case DW_MACINFO_define
:
20806 case DW_MACINFO_undef
:
20807 output_macinfo_op (ref
);
20812 gcc_unreachable ();
20816 /* Set up for Dwarf output at the start of compilation. */
20819 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
20821 /* Allocate the file_table. */
20822 file_table
= htab_create_ggc (50, file_table_hash
,
20823 file_table_eq
, NULL
);
20825 /* Allocate the decl_die_table. */
20826 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
20827 decl_die_table_eq
, NULL
);
20829 /* Allocate the decl_loc_table. */
20830 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
20831 decl_loc_table_eq
, NULL
);
20833 /* Allocate the cached_dw_loc_list_table. */
20834 cached_dw_loc_list_table
20835 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
20836 cached_dw_loc_list_table_eq
, NULL
);
20838 /* Allocate the initial hunk of the decl_scope_table. */
20839 decl_scope_table
= VEC_alloc (tree
, gc
, 256);
20841 /* Allocate the initial hunk of the abbrev_die_table. */
20842 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
20843 (ABBREV_DIE_TABLE_INCREMENT
);
20844 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
20845 /* Zero-th entry is allocated, but unused. */
20846 abbrev_die_table_in_use
= 1;
20848 /* Allocate the pubtypes and pubnames vectors. */
20849 pubname_table
= VEC_alloc (pubname_entry
, gc
, 32);
20850 pubtype_table
= VEC_alloc (pubname_entry
, gc
, 32);
20852 incomplete_types
= VEC_alloc (tree
, gc
, 64);
20854 used_rtx_array
= VEC_alloc (rtx
, gc
, 32);
20856 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
20857 SECTION_DEBUG
, NULL
);
20858 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
20859 SECTION_DEBUG
, NULL
);
20860 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
20861 SECTION_DEBUG
, NULL
);
20862 debug_macinfo_section
= get_section (dwarf_strict
20863 ? DEBUG_MACINFO_SECTION
20864 : DEBUG_MACRO_SECTION
,
20865 SECTION_DEBUG
, NULL
);
20866 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
20867 SECTION_DEBUG
, NULL
);
20868 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
20869 SECTION_DEBUG
, NULL
);
20870 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
20871 SECTION_DEBUG
, NULL
);
20872 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
20873 SECTION_DEBUG
, NULL
);
20874 debug_str_section
= get_section (DEBUG_STR_SECTION
,
20875 DEBUG_STR_SECTION_FLAGS
, NULL
);
20876 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
20877 SECTION_DEBUG
, NULL
);
20878 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
20879 SECTION_DEBUG
, NULL
);
20881 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
20882 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
20883 DEBUG_ABBREV_SECTION_LABEL
, 0);
20884 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
20885 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
20886 COLD_TEXT_SECTION_LABEL
, 0);
20887 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
20889 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
20890 DEBUG_INFO_SECTION_LABEL
, 0);
20891 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
20892 DEBUG_LINE_SECTION_LABEL
, 0);
20893 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
20894 DEBUG_RANGES_SECTION_LABEL
, 0);
20895 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
20897 ? DEBUG_MACINFO_SECTION_LABEL
20898 : DEBUG_MACRO_SECTION_LABEL
, 0);
20900 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20901 macinfo_table
= VEC_alloc (macinfo_entry
, gc
, 64);
20903 switch_to_section (text_section
);
20904 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
20906 /* Make sure the line number table for .text always exists. */
20907 text_section_line_info
= new_line_info_table ();
20908 text_section_line_info
->end_label
= text_end_label
;
20911 /* Called before compile () starts outputtting functions, variables
20912 and toplevel asms into assembly. */
20915 dwarf2out_assembly_start (void)
20917 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
20918 && dwarf2out_do_cfi_asm ()
20919 && (!(flag_unwind_tables
|| flag_exceptions
)
20920 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
20921 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
20924 /* A helper function for dwarf2out_finish called through
20925 htab_traverse. Emit one queued .debug_str string. */
20928 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
20930 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
20932 if (node
->form
== DW_FORM_strp
)
20934 switch_to_section (debug_str_section
);
20935 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
20936 assemble_string (node
->str
, strlen (node
->str
) + 1);
20942 #if ENABLE_ASSERT_CHECKING
20943 /* Verify that all marks are clear. */
20946 verify_marks_clear (dw_die_ref die
)
20950 gcc_assert (! die
->die_mark
);
20951 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
20953 #endif /* ENABLE_ASSERT_CHECKING */
20955 /* Clear the marks for a die and its children.
20956 Be cool if the mark isn't set. */
20959 prune_unmark_dies (dw_die_ref die
)
20965 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
20968 /* Given DIE that we're marking as used, find any other dies
20969 it references as attributes and mark them as used. */
20972 prune_unused_types_walk_attribs (dw_die_ref die
)
20977 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
20979 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
20981 /* A reference to another DIE.
20982 Make sure that it will get emitted.
20983 If it was broken out into a comdat group, don't follow it. */
20984 if (! AT_ref (a
)->comdat_type_p
20985 || a
->dw_attr
== DW_AT_specification
)
20986 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
20988 /* Set the string's refcount to 0 so that prune_unused_types_mark
20989 accounts properly for it. */
20990 if (AT_class (a
) == dw_val_class_str
)
20991 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
20995 /* Mark the generic parameters and arguments children DIEs of DIE. */
20998 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
21002 if (die
== NULL
|| die
->die_child
== NULL
)
21004 c
= die
->die_child
;
21007 switch (c
->die_tag
)
21009 case DW_TAG_template_type_param
:
21010 case DW_TAG_template_value_param
:
21011 case DW_TAG_GNU_template_template_param
:
21012 case DW_TAG_GNU_template_parameter_pack
:
21013 prune_unused_types_mark (c
, 1);
21019 } while (c
&& c
!= die
->die_child
);
21022 /* Mark DIE as being used. If DOKIDS is true, then walk down
21023 to DIE's children. */
21026 prune_unused_types_mark (dw_die_ref die
, int dokids
)
21030 if (die
->die_mark
== 0)
21032 /* We haven't done this node yet. Mark it as used. */
21034 /* If this is the DIE of a generic type instantiation,
21035 mark the children DIEs that describe its generic parms and
21037 prune_unused_types_mark_generic_parms_dies (die
);
21039 /* We also have to mark its parents as used.
21040 (But we don't want to mark our parents' kids due to this.) */
21041 if (die
->die_parent
)
21042 prune_unused_types_mark (die
->die_parent
, 0);
21044 /* Mark any referenced nodes. */
21045 prune_unused_types_walk_attribs (die
);
21047 /* If this node is a specification,
21048 also mark the definition, if it exists. */
21049 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
21050 prune_unused_types_mark (die
->die_definition
, 1);
21053 if (dokids
&& die
->die_mark
!= 2)
21055 /* We need to walk the children, but haven't done so yet.
21056 Remember that we've walked the kids. */
21059 /* If this is an array type, we need to make sure our
21060 kids get marked, even if they're types. If we're
21061 breaking out types into comdat sections, do this
21062 for all type definitions. */
21063 if (die
->die_tag
== DW_TAG_array_type
21064 || (use_debug_types
21065 && is_type_die (die
) && ! is_declaration_die (die
)))
21066 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
21068 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
21072 /* For local classes, look if any static member functions were emitted
21073 and if so, mark them. */
21076 prune_unused_types_walk_local_classes (dw_die_ref die
)
21080 if (die
->die_mark
== 2)
21083 switch (die
->die_tag
)
21085 case DW_TAG_structure_type
:
21086 case DW_TAG_union_type
:
21087 case DW_TAG_class_type
:
21090 case DW_TAG_subprogram
:
21091 if (!get_AT_flag (die
, DW_AT_declaration
)
21092 || die
->die_definition
!= NULL
)
21093 prune_unused_types_mark (die
, 1);
21100 /* Mark children. */
21101 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
21104 /* Walk the tree DIE and mark types that we actually use. */
21107 prune_unused_types_walk (dw_die_ref die
)
21111 /* Don't do anything if this node is already marked and
21112 children have been marked as well. */
21113 if (die
->die_mark
== 2)
21116 switch (die
->die_tag
)
21118 case DW_TAG_structure_type
:
21119 case DW_TAG_union_type
:
21120 case DW_TAG_class_type
:
21121 if (die
->die_perennial_p
)
21124 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
21125 if (c
->die_tag
== DW_TAG_subprogram
)
21128 /* Finding used static member functions inside of classes
21129 is needed just for local classes, because for other classes
21130 static member function DIEs with DW_AT_specification
21131 are emitted outside of the DW_TAG_*_type. If we ever change
21132 it, we'd need to call this even for non-local classes. */
21134 prune_unused_types_walk_local_classes (die
);
21136 /* It's a type node --- don't mark it. */
21139 case DW_TAG_const_type
:
21140 case DW_TAG_packed_type
:
21141 case DW_TAG_pointer_type
:
21142 case DW_TAG_reference_type
:
21143 case DW_TAG_rvalue_reference_type
:
21144 case DW_TAG_volatile_type
:
21145 case DW_TAG_typedef
:
21146 case DW_TAG_array_type
:
21147 case DW_TAG_interface_type
:
21148 case DW_TAG_friend
:
21149 case DW_TAG_variant_part
:
21150 case DW_TAG_enumeration_type
:
21151 case DW_TAG_subroutine_type
:
21152 case DW_TAG_string_type
:
21153 case DW_TAG_set_type
:
21154 case DW_TAG_subrange_type
:
21155 case DW_TAG_ptr_to_member_type
:
21156 case DW_TAG_file_type
:
21157 if (die
->die_perennial_p
)
21160 /* It's a type node --- don't mark it. */
21164 /* Mark everything else. */
21168 if (die
->die_mark
== 0)
21172 /* Now, mark any dies referenced from here. */
21173 prune_unused_types_walk_attribs (die
);
21178 /* Mark children. */
21179 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
21182 /* Increment the string counts on strings referred to from DIE's
21186 prune_unused_types_update_strings (dw_die_ref die
)
21191 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
21192 if (AT_class (a
) == dw_val_class_str
)
21194 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
21196 /* Avoid unnecessarily putting strings that are used less than
21197 twice in the hash table. */
21199 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
21202 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
21203 htab_hash_string (s
->str
),
21205 gcc_assert (*slot
== NULL
);
21211 /* Remove from the tree DIE any dies that aren't marked. */
21214 prune_unused_types_prune (dw_die_ref die
)
21218 gcc_assert (die
->die_mark
);
21219 prune_unused_types_update_strings (die
);
21221 if (! die
->die_child
)
21224 c
= die
->die_child
;
21226 dw_die_ref prev
= c
;
21227 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
21228 if (c
== die
->die_child
)
21230 /* No marked children between 'prev' and the end of the list. */
21232 /* No marked children at all. */
21233 die
->die_child
= NULL
;
21236 prev
->die_sib
= c
->die_sib
;
21237 die
->die_child
= prev
;
21242 if (c
!= prev
->die_sib
)
21244 prune_unused_types_prune (c
);
21245 } while (c
!= die
->die_child
);
21248 /* Remove dies representing declarations that we never use. */
21251 prune_unused_types (void)
21254 limbo_die_node
*node
;
21255 comdat_type_node
*ctnode
;
21257 dw_die_ref base_type
;
21259 #if ENABLE_ASSERT_CHECKING
21260 /* All the marks should already be clear. */
21261 verify_marks_clear (comp_unit_die ());
21262 for (node
= limbo_die_list
; node
; node
= node
->next
)
21263 verify_marks_clear (node
->die
);
21264 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21265 verify_marks_clear (ctnode
->root_die
);
21266 #endif /* ENABLE_ASSERT_CHECKING */
21268 /* Mark types that are used in global variables. */
21269 premark_types_used_by_global_vars ();
21271 /* Set the mark on nodes that are actually used. */
21272 prune_unused_types_walk (comp_unit_die ());
21273 for (node
= limbo_die_list
; node
; node
= node
->next
)
21274 prune_unused_types_walk (node
->die
);
21275 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21277 prune_unused_types_walk (ctnode
->root_die
);
21278 prune_unused_types_mark (ctnode
->type_die
, 1);
21281 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
21282 are unusual in that they are pubnames that are the children of pubtypes.
21283 They should only be marked via their parent DW_TAG_enumeration_type die,
21284 not as roots in themselves. */
21285 FOR_EACH_VEC_ELT (pubname_entry
, pubname_table
, i
, pub
)
21286 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
21287 prune_unused_types_mark (pub
->die
, 1);
21288 for (i
= 0; VEC_iterate (dw_die_ref
, base_types
, i
, base_type
); i
++)
21289 prune_unused_types_mark (base_type
, 1);
21291 if (debug_str_hash
)
21292 htab_empty (debug_str_hash
);
21293 prune_unused_types_prune (comp_unit_die ());
21294 for (node
= limbo_die_list
; node
; node
= node
->next
)
21295 prune_unused_types_prune (node
->die
);
21296 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21297 prune_unused_types_prune (ctnode
->root_die
);
21299 /* Leave the marks clear. */
21300 prune_unmark_dies (comp_unit_die ());
21301 for (node
= limbo_die_list
; node
; node
= node
->next
)
21302 prune_unmark_dies (node
->die
);
21303 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21304 prune_unmark_dies (ctnode
->root_die
);
21307 /* Set the parameter to true if there are any relative pathnames in
21310 file_table_relative_p (void ** slot
, void *param
)
21312 bool *p
= (bool *) param
;
21313 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
21314 if (!IS_ABSOLUTE_PATH (d
->filename
))
21322 /* Routines to manipulate hash table of comdat type units. */
21325 htab_ct_hash (const void *of
)
21328 const comdat_type_node
*const type_node
= (const comdat_type_node
*) of
;
21330 memcpy (&h
, type_node
->signature
, sizeof (h
));
21335 htab_ct_eq (const void *of1
, const void *of2
)
21337 const comdat_type_node
*const type_node_1
= (const comdat_type_node
*) of1
;
21338 const comdat_type_node
*const type_node_2
= (const comdat_type_node
*) of2
;
21340 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
21341 DWARF_TYPE_SIGNATURE_SIZE
));
21344 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
21345 to the location it would have been added, should we know its
21346 DECL_ASSEMBLER_NAME when we added other attributes. This will
21347 probably improve compactness of debug info, removing equivalent
21348 abbrevs, and hide any differences caused by deferring the
21349 computation of the assembler name, triggered by e.g. PCH. */
21352 move_linkage_attr (dw_die_ref die
)
21354 unsigned ix
= VEC_length (dw_attr_node
, die
->die_attr
);
21355 dw_attr_node linkage
= VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
21357 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
21358 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
21362 dw_attr_node
*prev
= &VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
21364 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
21368 if (ix
!= VEC_length (dw_attr_node
, die
->die_attr
) - 1)
21370 VEC_pop (dw_attr_node
, die
->die_attr
);
21371 VEC_quick_insert (dw_attr_node
, die
->die_attr
, ix
, linkage
);
21375 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
21376 referenced from typed stack ops and count how often they are used. */
21379 mark_base_types (dw_loc_descr_ref loc
)
21381 dw_die_ref base_type
= NULL
;
21383 for (; loc
; loc
= loc
->dw_loc_next
)
21385 switch (loc
->dw_loc_opc
)
21387 case DW_OP_GNU_regval_type
:
21388 case DW_OP_GNU_deref_type
:
21389 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
21391 case DW_OP_GNU_convert
:
21392 case DW_OP_GNU_reinterpret
:
21393 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
21396 case DW_OP_GNU_const_type
:
21397 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
21399 case DW_OP_GNU_entry_value
:
21400 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
21405 gcc_assert (base_type
->die_parent
== comp_unit_die ());
21406 if (base_type
->die_mark
)
21407 base_type
->die_mark
++;
21410 VEC_safe_push (dw_die_ref
, heap
, base_types
, base_type
);
21411 base_type
->die_mark
= 1;
21416 /* Comparison function for sorting marked base types. */
21419 base_type_cmp (const void *x
, const void *y
)
21421 dw_die_ref dx
= *(const dw_die_ref
*) x
;
21422 dw_die_ref dy
= *(const dw_die_ref
*) y
;
21423 unsigned int byte_size1
, byte_size2
;
21424 unsigned int encoding1
, encoding2
;
21425 if (dx
->die_mark
> dy
->die_mark
)
21427 if (dx
->die_mark
< dy
->die_mark
)
21429 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
21430 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
21431 if (byte_size1
< byte_size2
)
21433 if (byte_size1
> byte_size2
)
21435 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
21436 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
21437 if (encoding1
< encoding2
)
21439 if (encoding1
> encoding2
)
21444 /* Move base types marked by mark_base_types as early as possible
21445 in the CU, sorted by decreasing usage count both to make the
21446 uleb128 references as small as possible and to make sure they
21447 will have die_offset already computed by calc_die_sizes when
21448 sizes of typed stack loc ops is computed. */
21451 move_marked_base_types (void)
21454 dw_die_ref base_type
, die
, c
;
21456 if (VEC_empty (dw_die_ref
, base_types
))
21459 /* Sort by decreasing usage count, they will be added again in that
21461 VEC_qsort (dw_die_ref
, base_types
, base_type_cmp
);
21462 die
= comp_unit_die ();
21463 c
= die
->die_child
;
21466 dw_die_ref prev
= c
;
21468 while (c
->die_mark
)
21470 remove_child_with_prev (c
, prev
);
21471 /* As base types got marked, there must be at least
21472 one node other than DW_TAG_base_type. */
21473 gcc_assert (c
!= c
->die_sib
);
21477 while (c
!= die
->die_child
);
21478 gcc_assert (die
->die_child
);
21479 c
= die
->die_child
;
21480 for (i
= 0; VEC_iterate (dw_die_ref
, base_types
, i
, base_type
); i
++)
21482 base_type
->die_mark
= 0;
21483 base_type
->die_sib
= c
->die_sib
;
21484 c
->die_sib
= base_type
;
21489 /* Helper function for resolve_addr, attempt to resolve
21490 one CONST_STRING, return non-zero if not successful. Similarly verify that
21491 SYMBOL_REFs refer to variables emitted in the current CU. */
21494 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
21498 if (GET_CODE (rtl
) == CONST_STRING
)
21500 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
21501 tree t
= build_string (len
, XSTR (rtl
, 0));
21502 tree tlen
= size_int (len
- 1);
21504 = build_array_type (char_type_node
, build_index_type (tlen
));
21505 rtl
= lookup_constant_def (t
);
21506 if (!rtl
|| !MEM_P (rtl
))
21508 rtl
= XEXP (rtl
, 0);
21509 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
21514 if (GET_CODE (rtl
) == SYMBOL_REF
21515 && SYMBOL_REF_DECL (rtl
))
21517 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
21519 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
21522 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
21526 if (GET_CODE (rtl
) == CONST
21527 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
21533 /* Helper function for resolve_addr, handle one location
21534 expression, return false if at least one CONST_STRING or SYMBOL_REF in
21535 the location list couldn't be resolved. */
21538 resolve_addr_in_expr (dw_loc_descr_ref loc
)
21540 dw_loc_descr_ref keep
= NULL
;
21541 for (; loc
; loc
= loc
->dw_loc_next
)
21542 switch (loc
->dw_loc_opc
)
21545 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
21548 case DW_OP_const4u
:
21549 case DW_OP_const8u
:
21551 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
21554 case DW_OP_plus_uconst
:
21555 if (size_of_loc_descr (loc
)
21556 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
21558 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
21560 dw_loc_descr_ref repl
21561 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
21562 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
21563 add_loc_descr (&repl
, loc
->dw_loc_next
);
21567 case DW_OP_implicit_value
:
21568 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
21569 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
21572 case DW_OP_GNU_implicit_pointer
:
21573 case DW_OP_GNU_parameter_ref
:
21574 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
21577 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
21580 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
21581 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
21582 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
21585 case DW_OP_GNU_const_type
:
21586 case DW_OP_GNU_regval_type
:
21587 case DW_OP_GNU_deref_type
:
21588 case DW_OP_GNU_convert
:
21589 case DW_OP_GNU_reinterpret
:
21590 while (loc
->dw_loc_next
21591 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
21593 dw_die_ref base1
, base2
;
21594 unsigned enc1
, enc2
, size1
, size2
;
21595 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
21596 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
21597 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
21598 else if (loc
->dw_loc_oprnd1
.val_class
21599 == dw_val_class_unsigned_const
)
21602 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
21603 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
21604 == dw_val_class_unsigned_const
)
21606 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
21607 gcc_assert (base1
->die_tag
== DW_TAG_base_type
21608 && base2
->die_tag
== DW_TAG_base_type
);
21609 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
21610 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
21611 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
21612 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
21614 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
21615 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
21619 /* Optimize away next DW_OP_GNU_convert after
21620 adjusting LOC's base type die reference. */
21621 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
21622 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
21623 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
21625 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
21626 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
21629 /* Don't change integer DW_OP_GNU_convert after e.g. floating
21630 point typed stack entry. */
21631 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
21632 keep
= loc
->dw_loc_next
;
21642 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
21643 an address in .rodata section if the string literal is emitted there,
21644 or remove the containing location list or replace DW_AT_const_value
21645 with DW_AT_location and empty location expression, if it isn't found
21646 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
21647 to something that has been emitted in the current CU. */
21650 resolve_addr (dw_die_ref die
)
21654 dw_loc_list_ref
*curr
, *start
, loc
;
21657 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
21658 switch (AT_class (a
))
21660 case dw_val_class_loc_list
:
21661 start
= curr
= AT_loc_list_ptr (a
);
21664 /* The same list can be referenced more than once. See if we have
21665 already recorded the result from a previous pass. */
21667 *curr
= loc
->dw_loc_next
;
21668 else if (!loc
->resolved_addr
)
21670 /* As things stand, we do not expect or allow one die to
21671 reference a suffix of another die's location list chain.
21672 References must be identical or completely separate.
21673 There is therefore no need to cache the result of this
21674 pass on any list other than the first; doing so
21675 would lead to unnecessary writes. */
21678 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
21679 if (!resolve_addr_in_expr ((*curr
)->expr
))
21681 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
21682 if (next
&& (*curr
)->ll_symbol
)
21684 gcc_assert (!next
->ll_symbol
);
21685 next
->ll_symbol
= (*curr
)->ll_symbol
;
21691 mark_base_types ((*curr
)->expr
);
21692 curr
= &(*curr
)->dw_loc_next
;
21696 loc
->resolved_addr
= 1;
21700 loc
->dw_loc_next
= *start
;
21705 remove_AT (die
, a
->dw_attr
);
21709 case dw_val_class_loc
:
21711 dw_loc_descr_ref l
= AT_loc (a
);
21712 /* For -gdwarf-2 don't attempt to optimize
21713 DW_AT_data_member_location containing
21714 DW_OP_plus_uconst - older consumers might
21715 rely on it being that op instead of a more complex,
21716 but shorter, location description. */
21717 if ((dwarf_version
> 2
21718 || a
->dw_attr
!= DW_AT_data_member_location
21720 || l
->dw_loc_opc
!= DW_OP_plus_uconst
21721 || l
->dw_loc_next
!= NULL
)
21722 && !resolve_addr_in_expr (l
))
21724 remove_AT (die
, a
->dw_attr
);
21728 mark_base_types (l
);
21731 case dw_val_class_addr
:
21732 if (a
->dw_attr
== DW_AT_const_value
21733 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
21735 remove_AT (die
, a
->dw_attr
);
21738 if (die
->die_tag
== DW_TAG_GNU_call_site
21739 && a
->dw_attr
== DW_AT_abstract_origin
)
21741 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
21742 dw_die_ref tdie
= lookup_decl_die (tdecl
);
21744 && DECL_EXTERNAL (tdecl
)
21745 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
21747 force_decl_die (tdecl
);
21748 tdie
= lookup_decl_die (tdecl
);
21752 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
21753 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
21754 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
21758 remove_AT (die
, a
->dw_attr
);
21767 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
21770 /* Helper routines for optimize_location_lists.
21771 This pass tries to share identical local lists in .debug_loc
21774 /* Iteratively hash operands of LOC opcode. */
21776 static inline hashval_t
21777 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
21779 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
21780 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
21782 switch (loc
->dw_loc_opc
)
21784 case DW_OP_const4u
:
21785 case DW_OP_const8u
:
21789 case DW_OP_const1u
:
21790 case DW_OP_const1s
:
21791 case DW_OP_const2u
:
21792 case DW_OP_const2s
:
21793 case DW_OP_const4s
:
21794 case DW_OP_const8s
:
21798 case DW_OP_plus_uconst
:
21834 case DW_OP_deref_size
:
21835 case DW_OP_xderef_size
:
21836 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
21843 gcc_assert (val1
->val_class
== dw_val_class_loc
);
21844 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
21845 hash
= iterative_hash_object (offset
, hash
);
21848 case DW_OP_implicit_value
:
21849 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
21850 switch (val2
->val_class
)
21852 case dw_val_class_const
:
21853 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
21855 case dw_val_class_vec
:
21857 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
21858 unsigned int len
= val2
->v
.val_vec
.length
;
21860 hash
= iterative_hash_object (elt_size
, hash
);
21861 hash
= iterative_hash_object (len
, hash
);
21862 hash
= iterative_hash (val2
->v
.val_vec
.array
,
21863 len
* elt_size
, hash
);
21866 case dw_val_class_const_double
:
21867 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
21868 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
21870 case dw_val_class_addr
:
21871 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
21874 gcc_unreachable ();
21878 case DW_OP_bit_piece
:
21879 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
21880 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
21886 unsigned char dtprel
= 0xd1;
21887 hash
= iterative_hash_object (dtprel
, hash
);
21889 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
21891 case DW_OP_GNU_implicit_pointer
:
21892 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
21894 case DW_OP_GNU_entry_value
:
21895 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
21897 case DW_OP_GNU_regval_type
:
21898 case DW_OP_GNU_deref_type
:
21900 unsigned int byte_size
21901 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
21902 unsigned int encoding
21903 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
21904 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
21905 hash
= iterative_hash_object (byte_size
, hash
);
21906 hash
= iterative_hash_object (encoding
, hash
);
21909 case DW_OP_GNU_convert
:
21910 case DW_OP_GNU_reinterpret
:
21911 if (val1
->val_class
== dw_val_class_unsigned_const
)
21913 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
21917 case DW_OP_GNU_const_type
:
21919 unsigned int byte_size
21920 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
21921 unsigned int encoding
21922 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
21923 hash
= iterative_hash_object (byte_size
, hash
);
21924 hash
= iterative_hash_object (encoding
, hash
);
21925 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
21927 hash
= iterative_hash_object (val2
->val_class
, hash
);
21928 switch (val2
->val_class
)
21930 case dw_val_class_const
:
21931 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
21933 case dw_val_class_vec
:
21935 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
21936 unsigned int len
= val2
->v
.val_vec
.length
;
21938 hash
= iterative_hash_object (elt_size
, hash
);
21939 hash
= iterative_hash_object (len
, hash
);
21940 hash
= iterative_hash (val2
->v
.val_vec
.array
,
21941 len
* elt_size
, hash
);
21944 case dw_val_class_const_double
:
21945 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
21946 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
21949 gcc_unreachable ();
21955 /* Other codes have no operands. */
21961 /* Iteratively hash the whole DWARF location expression LOC. */
21963 static inline hashval_t
21964 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
21966 dw_loc_descr_ref l
;
21967 bool sizes_computed
= false;
21968 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
21969 size_of_locs (loc
);
21971 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
21973 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
21974 hash
= iterative_hash_object (opc
, hash
);
21975 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
21977 size_of_locs (loc
);
21978 sizes_computed
= true;
21980 hash
= hash_loc_operands (l
, hash
);
21985 /* Compute hash of the whole location list LIST_HEAD. */
21988 hash_loc_list (dw_loc_list_ref list_head
)
21990 dw_loc_list_ref curr
= list_head
;
21991 hashval_t hash
= 0;
21993 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
21995 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
21996 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
21998 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
22000 hash
= hash_locs (curr
->expr
, hash
);
22002 list_head
->hash
= hash
;
22005 /* Return true if X and Y opcodes have the same operands. */
22008 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
22010 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
22011 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
22012 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
22013 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
22015 switch (x
->dw_loc_opc
)
22017 case DW_OP_const4u
:
22018 case DW_OP_const8u
:
22022 case DW_OP_const1u
:
22023 case DW_OP_const1s
:
22024 case DW_OP_const2u
:
22025 case DW_OP_const2s
:
22026 case DW_OP_const4s
:
22027 case DW_OP_const8s
:
22031 case DW_OP_plus_uconst
:
22067 case DW_OP_deref_size
:
22068 case DW_OP_xderef_size
:
22069 return valx1
->v
.val_int
== valy1
->v
.val_int
;
22072 gcc_assert (valx1
->val_class
== dw_val_class_loc
22073 && valy1
->val_class
== dw_val_class_loc
22074 && x
->dw_loc_addr
== y
->dw_loc_addr
);
22075 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
22076 case DW_OP_implicit_value
:
22077 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
22078 || valx2
->val_class
!= valy2
->val_class
)
22080 switch (valx2
->val_class
)
22082 case dw_val_class_const
:
22083 return valx2
->v
.val_int
== valy2
->v
.val_int
;
22084 case dw_val_class_vec
:
22085 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
22086 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
22087 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
22088 valx2
->v
.val_vec
.elt_size
22089 * valx2
->v
.val_vec
.length
) == 0;
22090 case dw_val_class_const_double
:
22091 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
22092 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
22093 case dw_val_class_addr
:
22094 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
22096 gcc_unreachable ();
22099 case DW_OP_bit_piece
:
22100 return valx1
->v
.val_int
== valy1
->v
.val_int
22101 && valx2
->v
.val_int
== valy2
->v
.val_int
;
22104 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
22105 case DW_OP_GNU_implicit_pointer
:
22106 return valx1
->val_class
== dw_val_class_die_ref
22107 && valx1
->val_class
== valy1
->val_class
22108 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
22109 && valx2
->v
.val_int
== valy2
->v
.val_int
;
22110 case DW_OP_GNU_entry_value
:
22111 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
22112 case DW_OP_GNU_const_type
:
22113 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
22114 || valx2
->val_class
!= valy2
->val_class
)
22116 switch (valx2
->val_class
)
22118 case dw_val_class_const
:
22119 return valx2
->v
.val_int
== valy2
->v
.val_int
;
22120 case dw_val_class_vec
:
22121 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
22122 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
22123 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
22124 valx2
->v
.val_vec
.elt_size
22125 * valx2
->v
.val_vec
.length
) == 0;
22126 case dw_val_class_const_double
:
22127 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
22128 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
22130 gcc_unreachable ();
22132 case DW_OP_GNU_regval_type
:
22133 case DW_OP_GNU_deref_type
:
22134 return valx1
->v
.val_int
== valy1
->v
.val_int
22135 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
22136 case DW_OP_GNU_convert
:
22137 case DW_OP_GNU_reinterpret
:
22138 if (valx1
->val_class
!= valy1
->val_class
)
22140 if (valx1
->val_class
== dw_val_class_unsigned_const
)
22141 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
22142 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
22143 case DW_OP_GNU_parameter_ref
:
22144 return valx1
->val_class
== dw_val_class_die_ref
22145 && valx1
->val_class
== valy1
->val_class
22146 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
22148 /* Other codes have no operands. */
22153 /* Return true if DWARF location expressions X and Y are the same. */
22156 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
22158 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
22159 if (x
->dw_loc_opc
!= y
->dw_loc_opc
22160 || x
->dtprel
!= y
->dtprel
22161 || !compare_loc_operands (x
, y
))
22163 return x
== NULL
&& y
== NULL
;
22166 /* Return precomputed hash of location list X. */
22169 loc_list_hash (const void *x
)
22171 return ((const struct dw_loc_list_struct
*) x
)->hash
;
22174 /* Return 1 if location lists X and Y are the same. */
22177 loc_list_eq (const void *x
, const void *y
)
22179 const struct dw_loc_list_struct
*a
= (const struct dw_loc_list_struct
*) x
;
22180 const struct dw_loc_list_struct
*b
= (const struct dw_loc_list_struct
*) y
;
22183 if (a
->hash
!= b
->hash
)
22185 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
22186 if (strcmp (a
->begin
, b
->begin
) != 0
22187 || strcmp (a
->end
, b
->end
) != 0
22188 || (a
->section
== NULL
) != (b
->section
== NULL
)
22189 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
22190 || !compare_locs (a
->expr
, b
->expr
))
22192 return a
== NULL
&& b
== NULL
;
22195 /* Recursively optimize location lists referenced from DIE
22196 children and share them whenever possible. */
22199 optimize_location_lists_1 (dw_die_ref die
, htab_t htab
)
22206 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
22207 if (AT_class (a
) == dw_val_class_loc_list
)
22209 dw_loc_list_ref list
= AT_loc_list (a
);
22210 /* TODO: perform some optimizations here, before hashing
22211 it and storing into the hash table. */
22212 hash_loc_list (list
);
22213 slot
= htab_find_slot_with_hash (htab
, list
, list
->hash
,
22216 *slot
= (void *) list
;
22218 a
->dw_attr_val
.v
.val_loc_list
= (dw_loc_list_ref
) *slot
;
22221 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
22224 /* Optimize location lists referenced from DIE
22225 children and share them whenever possible. */
22228 optimize_location_lists (dw_die_ref die
)
22230 htab_t htab
= htab_create (500, loc_list_hash
, loc_list_eq
, NULL
);
22231 optimize_location_lists_1 (die
, htab
);
22232 htab_delete (htab
);
22235 /* Output stuff that dwarf requires at the end of every file,
22236 and generate the DWARF-2 debugging info. */
22239 dwarf2out_finish (const char *filename
)
22241 limbo_die_node
*node
, *next_node
;
22242 comdat_type_node
*ctnode
;
22243 htab_t comdat_type_table
;
22246 /* PCH might result in DW_AT_producer string being restored from the
22247 header compilation, fix it up if needed. */
22248 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
22249 if (strcmp (AT_string (producer
), producer_string
) != 0)
22251 struct indirect_string_node
*node
= find_AT_string (producer_string
);
22252 producer
->dw_attr_val
.v
.val_str
= node
;
22255 gen_scheduled_generic_parms_dies ();
22256 gen_remaining_tmpl_value_param_die_attribute ();
22258 /* Add the name for the main input file now. We delayed this from
22259 dwarf2out_init to avoid complications with PCH. */
22260 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
22261 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
22262 add_comp_dir_attribute (comp_unit_die ());
22263 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
22266 htab_traverse (file_table
, file_table_relative_p
, &p
);
22268 add_comp_dir_attribute (comp_unit_die ());
22271 for (i
= 0; i
< VEC_length (deferred_locations
, deferred_locations_list
); i
++)
22273 add_location_or_const_value_attribute (
22274 VEC_index (deferred_locations
, deferred_locations_list
, i
).die
,
22275 VEC_index (deferred_locations
, deferred_locations_list
, i
).variable
,
22280 /* Traverse the limbo die list, and add parent/child links. The only
22281 dies without parents that should be here are concrete instances of
22282 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
22283 For concrete instances, we can get the parent die from the abstract
22285 for (node
= limbo_die_list
; node
; node
= next_node
)
22287 dw_die_ref die
= node
->die
;
22288 next_node
= node
->next
;
22290 if (die
->die_parent
== NULL
)
22292 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
22294 if (origin
&& origin
->die_parent
)
22295 add_child_die (origin
->die_parent
, die
);
22296 else if (is_cu_die (die
))
22298 else if (seen_error ())
22299 /* It's OK to be confused by errors in the input. */
22300 add_child_die (comp_unit_die (), die
);
22303 /* In certain situations, the lexical block containing a
22304 nested function can be optimized away, which results
22305 in the nested function die being orphaned. Likewise
22306 with the return type of that nested function. Force
22307 this to be a child of the containing function.
22309 It may happen that even the containing function got fully
22310 inlined and optimized out. In that case we are lost and
22311 assign the empty child. This should not be big issue as
22312 the function is likely unreachable too. */
22313 gcc_assert (node
->created_for
);
22315 if (DECL_P (node
->created_for
))
22316 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
22317 else if (TYPE_P (node
->created_for
))
22318 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
22320 origin
= comp_unit_die ();
22322 add_child_die (origin
, die
);
22327 limbo_die_list
= NULL
;
22329 #if ENABLE_ASSERT_CHECKING
22331 dw_die_ref die
= comp_unit_die (), c
;
22332 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
22335 resolve_addr (comp_unit_die ());
22336 move_marked_base_types ();
22338 for (node
= deferred_asm_name
; node
; node
= node
->next
)
22340 tree decl
= node
->created_for
;
22341 /* When generating LTO bytecode we can not generate new assembler
22342 names at this point and all important decls got theirs via
22344 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
22345 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
22347 add_linkage_attr (node
->die
, decl
);
22348 move_linkage_attr (node
->die
);
22352 deferred_asm_name
= NULL
;
22354 /* Walk through the list of incomplete types again, trying once more to
22355 emit full debugging info for them. */
22356 retry_incomplete_types ();
22358 if (flag_eliminate_unused_debug_types
)
22359 prune_unused_types ();
22361 /* Generate separate COMDAT sections for type DIEs. */
22362 if (use_debug_types
)
22364 break_out_comdat_types (comp_unit_die ());
22366 /* Each new type_unit DIE was added to the limbo die list when created.
22367 Since these have all been added to comdat_type_list, clear the
22369 limbo_die_list
= NULL
;
22371 /* For each new comdat type unit, copy declarations for incomplete
22372 types to make the new unit self-contained (i.e., no direct
22373 references to the main compile unit). */
22374 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22375 copy_decls_for_unworthy_types (ctnode
->root_die
);
22376 copy_decls_for_unworthy_types (comp_unit_die ());
22378 /* In the process of copying declarations from one unit to another,
22379 we may have left some declarations behind that are no longer
22380 referenced. Prune them. */
22381 prune_unused_types ();
22384 /* Generate separate CUs for each of the include files we've seen.
22385 They will go into limbo_die_list. */
22386 if (flag_eliminate_dwarf2_dups
)
22387 break_out_includes (comp_unit_die ());
22389 /* Traverse the DIE's and add add sibling attributes to those DIE's
22390 that have children. */
22391 add_sibling_attributes (comp_unit_die ());
22392 for (node
= limbo_die_list
; node
; node
= node
->next
)
22393 add_sibling_attributes (node
->die
);
22394 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22395 add_sibling_attributes (ctnode
->root_die
);
22397 /* Output a terminator label for the .text section. */
22398 switch_to_section (text_section
);
22399 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
22400 if (cold_text_section
)
22402 switch_to_section (cold_text_section
);
22403 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
22406 /* We can only use the low/high_pc attributes if all of the code was
22408 if (!have_multiple_function_sections
22409 || (dwarf_version
< 3 && dwarf_strict
))
22411 /* Don't add if the CU has no associated code. */
22412 if (text_section_used
)
22413 add_AT_low_high_pc (comp_unit_die (), text_section_label
,
22420 bool range_list_added
= false;
22422 if (text_section_used
)
22423 add_ranges_by_labels (comp_unit_die (), text_section_label
,
22424 text_end_label
, &range_list_added
);
22425 if (cold_text_section_used
)
22426 add_ranges_by_labels (comp_unit_die (), cold_text_section_label
,
22427 cold_end_label
, &range_list_added
);
22429 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, fde_idx
, fde
)
22431 if (DECL_IGNORED_P (fde
->decl
))
22433 if (!fde
->in_std_section
)
22434 add_ranges_by_labels (comp_unit_die (), fde
->dw_fde_begin
,
22435 fde
->dw_fde_end
, &range_list_added
);
22436 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
22437 add_ranges_by_labels (comp_unit_die (), fde
->dw_fde_second_begin
,
22438 fde
->dw_fde_second_end
, &range_list_added
);
22441 if (range_list_added
)
22443 /* We need to give .debug_loc and .debug_ranges an appropriate
22444 "base address". Use zero so that these addresses become
22445 absolute. Historically, we've emitted the unexpected
22446 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
22447 Emit both to give time for other tools to adapt. */
22448 add_AT_addr (comp_unit_die (), DW_AT_low_pc
, const0_rtx
);
22449 if (! dwarf_strict
&& dwarf_version
< 4)
22450 add_AT_addr (comp_unit_die (), DW_AT_entry_pc
, const0_rtx
);
22456 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
22457 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list
,
22458 debug_line_section_label
);
22461 add_AT_macptr (comp_unit_die (),
22462 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
22463 macinfo_section_label
);
22465 if (have_location_lists
)
22466 optimize_location_lists (comp_unit_die ());
22468 /* Output all of the compilation units. We put the main one last so that
22469 the offsets are available to output_pubnames. */
22470 for (node
= limbo_die_list
; node
; node
= node
->next
)
22471 output_comp_unit (node
->die
, 0);
22473 comdat_type_table
= htab_create (100, htab_ct_hash
, htab_ct_eq
, NULL
);
22474 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22476 void **slot
= htab_find_slot (comdat_type_table
, ctnode
, INSERT
);
22478 /* Don't output duplicate types. */
22479 if (*slot
!= HTAB_EMPTY_ENTRY
)
22482 /* Add a pointer to the line table for the main compilation unit
22483 so that the debugger can make sense of DW_AT_decl_file
22485 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
22486 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
22487 debug_line_section_label
);
22489 output_comdat_type_unit (ctnode
);
22492 htab_delete (comdat_type_table
);
22494 add_AT_pubnames (comp_unit_die ());
22496 /* Output the main compilation unit if non-empty or if .debug_macinfo
22497 or .debug_macro will be emitted. */
22498 output_comp_unit (comp_unit_die (), have_macinfo
);
22500 /* Output the abbreviation table. */
22501 if (abbrev_die_table_in_use
!= 1)
22503 switch_to_section (debug_abbrev_section
);
22504 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
22505 output_abbrev_section ();
22508 /* Output location list section if necessary. */
22509 if (have_location_lists
)
22511 /* Output the location lists info. */
22512 switch_to_section (debug_loc_section
);
22513 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
22514 DEBUG_LOC_SECTION_LABEL
, 0);
22515 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
22516 output_location_lists (comp_unit_die ());
22519 /* Output public names and types tables if necessary. */
22520 output_pubnames (pubname_table
);
22521 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
22522 It shouldn't hurt to emit it always, since pure DWARF2 consumers
22523 simply won't look for the section. */
22524 output_pubnames (pubtype_table
);
22526 /* Output the address range information if a CU (.debug_info section)
22527 was emitted. We output an empty table even if we had no functions
22528 to put in it. This because the consumer has no way to tell the
22529 difference between an empty table that we omitted and failure to
22530 generate a table that would have contained data. */
22531 if (info_section_emitted
)
22533 unsigned long aranges_length
= size_of_aranges ();
22535 switch_to_section (debug_aranges_section
);
22536 output_aranges (aranges_length
);
22539 /* Output ranges section if necessary. */
22540 if (ranges_table_in_use
)
22542 switch_to_section (debug_ranges_section
);
22543 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
22547 /* Have to end the macro section. */
22550 switch_to_section (debug_macinfo_section
);
22551 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
22553 dw2_asm_output_data (1, 0, "End compilation unit");
22556 /* Output the source line correspondence table. We must do this
22557 even if there is no line information. Otherwise, on an empty
22558 translation unit, we will generate a present, but empty,
22559 .debug_info section. IRIX 6.5 `nm' will then complain when
22560 examining the file. This is done late so that any filenames
22561 used by the debug_info section are marked as 'used'. */
22562 switch_to_section (debug_line_section
);
22563 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
22564 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
22565 output_line_info ();
22567 /* If we emitted any DW_FORM_strp form attribute, output the string
22569 if (debug_str_hash
)
22570 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
22573 #include "gt-dwarf2out.h"