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
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"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
84 #include "diagnostic.h"
85 #include "tree-pretty-print.h"
88 #include "common/common-target.h"
89 #include "langhooks.h"
94 #include "tree-pass.h"
95 #include "tree-flow.h"
96 #include "cfglayout.h"
99 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
100 static rtx last_var_location_insn
;
101 static rtx cached_next_real_insn
;
103 #ifdef VMS_DEBUGGING_INFO
104 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
106 /* Define this macro to be a nonzero value if the directory specifications
107 which are output in the debug info should end with a separator. */
108 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
109 /* Define this macro to evaluate to a nonzero value if GCC should refrain
110 from generating indirect strings in DWARF2 debug information, for instance
111 if your target is stuck with an old version of GDB that is unable to
112 process them properly or uses VMS Debug. */
113 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
115 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
116 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
119 /* ??? Poison these here until it can be done generically. They've been
120 totally replaced in this file; make sure it stays that way. */
121 #undef DWARF2_UNWIND_INFO
122 #undef DWARF2_FRAME_INFO
123 #if (GCC_VERSION >= 3000)
124 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
127 /* The size of the target's pointer type. */
129 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
132 /* Array of RTXes referenced by the debugging information, which therefore
133 must be kept around forever. */
134 static GTY(()) VEC(rtx
,gc
) *used_rtx_array
;
136 /* A pointer to the base of a list of incomplete types which might be
137 completed at some later time. incomplete_types_list needs to be a
138 VEC(tree,gc) because we want to tell the garbage collector about
140 static GTY(()) VEC(tree
,gc
) *incomplete_types
;
142 /* A pointer to the base of a table of references to declaration
143 scopes. This table is a display which tracks the nesting
144 of declaration scopes at the current scope and containing
145 scopes. This table is used to find the proper place to
146 define type declaration DIE's. */
147 static GTY(()) VEC(tree
,gc
) *decl_scope_table
;
149 /* Pointers to various DWARF2 sections. */
150 static GTY(()) section
*debug_info_section
;
151 static GTY(()) section
*debug_abbrev_section
;
152 static GTY(()) section
*debug_aranges_section
;
153 static GTY(()) section
*debug_macinfo_section
;
154 static GTY(()) section
*debug_line_section
;
155 static GTY(()) section
*debug_loc_section
;
156 static GTY(()) section
*debug_pubnames_section
;
157 static GTY(()) section
*debug_pubtypes_section
;
158 static GTY(()) section
*debug_str_section
;
159 static GTY(()) section
*debug_ranges_section
;
160 static GTY(()) section
*debug_frame_section
;
162 /* Maximum size (in bytes) of an artificially generated label. */
163 #define MAX_ARTIFICIAL_LABEL_BYTES 30
165 /* According to the (draft) DWARF 3 specification, the initial length
166 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
167 bytes are 0xffffffff, followed by the length stored in the next 8
170 However, the SGI/MIPS ABI uses an initial length which is equal to
171 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
173 #ifndef DWARF_INITIAL_LENGTH_SIZE
174 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
177 /* Round SIZE up to the nearest BOUNDARY. */
178 #define DWARF_ROUND(SIZE,BOUNDARY) \
179 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
181 /* CIE identifier. */
182 #if HOST_BITS_PER_WIDE_INT >= 64
183 #define DWARF_CIE_ID \
184 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
186 #define DWARF_CIE_ID DW_CIE_ID
189 DEF_VEC_P (dw_fde_ref
);
190 DEF_VEC_ALLOC_P (dw_fde_ref
, gc
);
192 /* A vector for a table that contains frame description
193 information for each routine. */
194 static GTY(()) VEC(dw_fde_ref
, gc
) *fde_vec
;
196 struct GTY(()) indirect_string_node
{
198 unsigned int refcount
;
199 enum dwarf_form form
;
203 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
205 static GTY(()) int dw2_string_counter
;
207 /* True if the compilation unit places functions in more than one section. */
208 static GTY(()) bool have_multiple_function_sections
= false;
210 /* Whether the default text and cold text sections have been used at all. */
212 static GTY(()) bool text_section_used
= false;
213 static GTY(()) bool cold_text_section_used
= false;
215 /* The default cold text section. */
216 static GTY(()) section
*cold_text_section
;
218 /* Forward declarations for functions defined in this file. */
220 static char *stripattributes (const char *);
221 static void output_call_frame_info (int);
222 static void dwarf2out_note_section_used (void);
224 /* Personality decl of current unit. Used only when assembler does not support
226 static GTY(()) rtx current_unit_personality
;
228 /* Data and reference forms for relocatable data. */
229 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
230 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
232 #ifndef DEBUG_FRAME_SECTION
233 #define DEBUG_FRAME_SECTION ".debug_frame"
236 #ifndef FUNC_BEGIN_LABEL
237 #define FUNC_BEGIN_LABEL "LFB"
240 #ifndef FUNC_END_LABEL
241 #define FUNC_END_LABEL "LFE"
244 #ifndef PROLOGUE_END_LABEL
245 #define PROLOGUE_END_LABEL "LPE"
248 #ifndef EPILOGUE_BEGIN_LABEL
249 #define EPILOGUE_BEGIN_LABEL "LEB"
252 #ifndef FRAME_BEGIN_LABEL
253 #define FRAME_BEGIN_LABEL "Lframe"
255 #define CIE_AFTER_SIZE_LABEL "LSCIE"
256 #define CIE_END_LABEL "LECIE"
257 #define FDE_LABEL "LSFDE"
258 #define FDE_AFTER_SIZE_LABEL "LASFDE"
259 #define FDE_END_LABEL "LEFDE"
260 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
261 #define LINE_NUMBER_END_LABEL "LELT"
262 #define LN_PROLOG_AS_LABEL "LASLTP"
263 #define LN_PROLOG_END_LABEL "LELTP"
264 #define DIE_LABEL_PREFIX "DW"
266 /* Match the base name of a file to the base name of a compilation unit. */
269 matches_main_base (const char *path
)
271 /* Cache the last query. */
272 static const char *last_path
= NULL
;
273 static int last_match
= 0;
274 if (path
!= last_path
)
277 int length
= base_of_path (path
, &base
);
279 last_match
= (length
== main_input_baselength
280 && memcmp (base
, main_input_basename
, length
) == 0);
285 #ifdef DEBUG_DEBUG_STRUCT
288 dump_struct_debug (tree type
, enum debug_info_usage usage
,
289 enum debug_struct_file criterion
, int generic
,
290 int matches
, int result
)
292 /* Find the type name. */
293 tree type_decl
= TYPE_STUB_DECL (type
);
295 const char *name
= 0;
296 if (TREE_CODE (t
) == TYPE_DECL
)
299 name
= IDENTIFIER_POINTER (t
);
301 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
303 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
304 matches
? "bas" : "hdr",
305 generic
? "gen" : "ord",
306 usage
== DINFO_USAGE_DFN
? ";" :
307 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
309 (void*) type_decl
, name
);
312 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
313 dump_struct_debug (type, usage, criterion, generic, matches, result)
317 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
323 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
325 enum debug_struct_file criterion
;
327 bool generic
= lang_hooks
.types
.generic_p (type
);
330 criterion
= debug_struct_generic
[usage
];
332 criterion
= debug_struct_ordinary
[usage
];
334 if (criterion
== DINFO_STRUCT_FILE_NONE
)
335 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
336 if (criterion
== DINFO_STRUCT_FILE_ANY
)
337 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
339 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
341 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
342 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
344 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
345 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
346 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
349 /* Return a pointer to a copy of the section string name S with all
350 attributes stripped off, and an asterisk prepended (for assemble_name). */
353 stripattributes (const char *s
)
355 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
360 while (*s
&& *s
!= ',')
367 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
368 switch to the data section instead, and write out a synthetic start label
369 for collect2 the first time around. */
372 switch_to_eh_frame_section (bool back
)
376 #ifdef EH_FRAME_SECTION_NAME
377 if (eh_frame_section
== 0)
381 if (EH_TABLES_CAN_BE_READ_ONLY
)
387 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
389 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
391 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
394 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
395 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
396 && (per_encoding
& 0x70) != DW_EH_PE_absptr
397 && (per_encoding
& 0x70) != DW_EH_PE_aligned
398 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
399 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
400 ? 0 : SECTION_WRITE
);
403 flags
= SECTION_WRITE
;
404 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
406 #endif /* EH_FRAME_SECTION_NAME */
408 if (eh_frame_section
)
409 switch_to_section (eh_frame_section
);
412 /* We have no special eh_frame section. Put the information in
413 the data section and emit special labels to guide collect2. */
414 switch_to_section (data_section
);
418 label
= get_file_function_name ("F");
419 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
420 targetm
.asm_out
.globalize_label (asm_out_file
,
421 IDENTIFIER_POINTER (label
));
422 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
427 /* Switch [BACK] to the eh or debug frame table section, depending on
431 switch_to_frame_table_section (int for_eh
, bool back
)
434 switch_to_eh_frame_section (back
);
437 if (!debug_frame_section
)
438 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
439 SECTION_DEBUG
, NULL
);
440 switch_to_section (debug_frame_section
);
444 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
446 enum dw_cfi_oprnd_type
447 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
452 case DW_CFA_GNU_window_save
:
453 case DW_CFA_remember_state
:
454 case DW_CFA_restore_state
:
455 return dw_cfi_oprnd_unused
;
458 case DW_CFA_advance_loc1
:
459 case DW_CFA_advance_loc2
:
460 case DW_CFA_advance_loc4
:
461 case DW_CFA_MIPS_advance_loc8
:
462 return dw_cfi_oprnd_addr
;
465 case DW_CFA_offset_extended
:
467 case DW_CFA_offset_extended_sf
:
468 case DW_CFA_def_cfa_sf
:
470 case DW_CFA_restore_extended
:
471 case DW_CFA_undefined
:
472 case DW_CFA_same_value
:
473 case DW_CFA_def_cfa_register
:
474 case DW_CFA_register
:
475 case DW_CFA_expression
:
476 return dw_cfi_oprnd_reg_num
;
478 case DW_CFA_def_cfa_offset
:
479 case DW_CFA_GNU_args_size
:
480 case DW_CFA_def_cfa_offset_sf
:
481 return dw_cfi_oprnd_offset
;
483 case DW_CFA_def_cfa_expression
:
484 return dw_cfi_oprnd_loc
;
491 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
493 enum dw_cfi_oprnd_type
494 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
499 case DW_CFA_def_cfa_sf
:
501 case DW_CFA_offset_extended_sf
:
502 case DW_CFA_offset_extended
:
503 return dw_cfi_oprnd_offset
;
505 case DW_CFA_register
:
506 return dw_cfi_oprnd_reg_num
;
508 case DW_CFA_expression
:
509 return dw_cfi_oprnd_loc
;
512 return dw_cfi_oprnd_unused
;
516 /* Output one FDE. */
519 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
520 char *section_start_label
, int fde_encoding
, char *augmentation
,
521 bool any_lsda_needed
, int lsda_encoding
)
523 const char *begin
, *end
;
524 static unsigned int j
;
527 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
529 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
531 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
532 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
533 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
534 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
535 " indicating 64-bit DWARF extension");
536 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
538 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
541 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
543 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
544 debug_frame_section
, "FDE CIE offset");
546 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
547 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
551 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
552 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
553 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
554 "FDE initial location");
555 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
556 end
, begin
, "FDE address range");
560 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
561 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
568 int size
= size_of_encoded_value (lsda_encoding
);
570 if (lsda_encoding
== DW_EH_PE_aligned
)
572 int offset
= ( 4 /* Length */
574 + 2 * size_of_encoded_value (fde_encoding
)
575 + 1 /* Augmentation size */ );
576 int pad
= -offset
& (PTR_SIZE
- 1);
579 gcc_assert (size_of_uleb128 (size
) == 1);
582 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
584 if (fde
->uses_eh_lsda
)
586 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
587 fde
->funcdef_number
);
588 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
589 gen_rtx_SYMBOL_REF (Pmode
, l1
),
591 "Language Specific Data Area");
595 if (lsda_encoding
== DW_EH_PE_aligned
)
596 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
597 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
598 "Language Specific Data Area (none)");
602 dw2_asm_output_data_uleb128 (0, "Augmentation size");
605 /* Loop through the Call Frame Instructions associated with this FDE. */
606 fde
->dw_fde_current_label
= begin
;
608 size_t from
, until
, i
;
611 until
= VEC_length (dw_cfi_ref
, fde
->dw_fde_cfi
);
613 if (fde
->dw_fde_second_begin
== NULL
)
616 until
= fde
->dw_fde_switch_cfi_index
;
618 from
= fde
->dw_fde_switch_cfi_index
;
620 for (i
= from
; i
< until
; i
++)
621 output_cfi (VEC_index (dw_cfi_ref
, fde
->dw_fde_cfi
, i
), fde
, for_eh
);
624 /* If we are to emit a ref/link from function bodies to their frame tables,
625 do it now. This is typically performed to make sure that tables
626 associated with functions are dragged with them and not discarded in
627 garbage collecting links. We need to do this on a per function basis to
628 cope with -ffunction-sections. */
630 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
631 /* Switch to the function section, emit the ref to the tables, and
632 switch *back* into the table section. */
633 switch_to_section (function_section (fde
->decl
));
634 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
635 switch_to_frame_table_section (for_eh
, true);
638 /* Pad the FDE out to an address sized boundary. */
639 ASM_OUTPUT_ALIGN (asm_out_file
,
640 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
641 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
646 /* Return true if frame description entry FDE is needed for EH. */
649 fde_needed_for_eh_p (dw_fde_ref fde
)
651 if (flag_asynchronous_unwind_tables
)
654 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
657 if (fde
->uses_eh_lsda
)
660 /* If exceptions are enabled, we have collected nothrow info. */
661 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
667 /* Output the call frame information used to record information
668 that relates to calculating the frame pointer, and records the
669 location of saved registers. */
672 output_call_frame_info (int for_eh
)
677 char l1
[20], l2
[20], section_start_label
[20];
678 bool any_lsda_needed
= false;
679 char augmentation
[6];
680 int augmentation_size
;
681 int fde_encoding
= DW_EH_PE_absptr
;
682 int per_encoding
= DW_EH_PE_absptr
;
683 int lsda_encoding
= DW_EH_PE_absptr
;
685 rtx personality
= NULL
;
688 /* Don't emit a CIE if there won't be any FDEs. */
692 /* Nothing to do if the assembler's doing it all. */
693 if (dwarf2out_do_cfi_asm ())
696 /* If we don't have any functions we'll want to unwind out of, don't emit
697 any EH unwind information. If we make FDEs linkonce, we may have to
698 emit an empty label for an FDE that wouldn't otherwise be emitted. We
699 want to avoid having an FDE kept around when the function it refers to
700 is discarded. Example where this matters: a primary function template
701 in C++ requires EH information, an explicit specialization doesn't. */
704 bool any_eh_needed
= false;
706 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, i
, fde
)
708 if (fde
->uses_eh_lsda
)
709 any_eh_needed
= any_lsda_needed
= true;
710 else if (fde_needed_for_eh_p (fde
))
711 any_eh_needed
= true;
712 else if (TARGET_USES_WEAK_UNWIND_INFO
)
713 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
720 /* We're going to be generating comments, so turn on app. */
724 /* Switch to the proper frame section, first time. */
725 switch_to_frame_table_section (for_eh
, false);
727 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
728 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
730 /* Output the CIE. */
731 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
732 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
733 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
734 dw2_asm_output_data (4, 0xffffffff,
735 "Initial length escape value indicating 64-bit DWARF extension");
736 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
737 "Length of Common Information Entry");
738 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
740 /* Now that the CIE pointer is PC-relative for EH,
741 use 0 to identify the CIE. */
742 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
743 (for_eh
? 0 : DWARF_CIE_ID
),
744 "CIE Identifier Tag");
746 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
747 use CIE version 1, unless that would produce incorrect results
748 due to overflowing the return register column. */
749 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
751 if (return_reg
>= 256 || dwarf_version
> 2)
753 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
756 augmentation_size
= 0;
758 personality
= current_unit_personality
;
764 z Indicates that a uleb128 is present to size the
765 augmentation section.
766 L Indicates the encoding (and thus presence) of
767 an LSDA pointer in the FDE augmentation.
768 R Indicates a non-default pointer encoding for
770 P Indicates the presence of an encoding + language
771 personality routine in the CIE augmentation. */
773 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
774 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
775 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
777 p
= augmentation
+ 1;
781 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
782 assemble_external_libcall (personality
);
787 augmentation_size
+= 1;
789 if (fde_encoding
!= DW_EH_PE_absptr
)
792 augmentation_size
+= 1;
794 if (p
> augmentation
+ 1)
796 augmentation
[0] = 'z';
800 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
801 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
803 int offset
= ( 4 /* Length */
805 + 1 /* CIE version */
806 + strlen (augmentation
) + 1 /* Augmentation */
807 + size_of_uleb128 (1) /* Code alignment */
808 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
810 + 1 /* Augmentation size */
811 + 1 /* Personality encoding */ );
812 int pad
= -offset
& (PTR_SIZE
- 1);
814 augmentation_size
+= pad
;
816 /* Augmentations should be small, so there's scarce need to
817 iterate for a solution. Die if we exceed one uleb128 byte. */
818 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
822 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
823 if (dw_cie_version
>= 4)
825 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
826 dw2_asm_output_data (1, 0, "CIE Segment Size");
828 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
829 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
830 "CIE Data Alignment Factor");
832 if (dw_cie_version
== 1)
833 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
835 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
839 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
842 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
843 eh_data_format_name (per_encoding
));
844 dw2_asm_output_encoded_addr_rtx (per_encoding
,
850 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
851 eh_data_format_name (lsda_encoding
));
853 if (fde_encoding
!= DW_EH_PE_absptr
)
854 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
855 eh_data_format_name (fde_encoding
));
858 FOR_EACH_VEC_ELT (dw_cfi_ref
, cie_cfi_vec
, i
, cfi
)
859 output_cfi (cfi
, NULL
, for_eh
);
861 /* Pad the CIE out to an address sized boundary. */
862 ASM_OUTPUT_ALIGN (asm_out_file
,
863 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
864 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
866 /* Loop through all of the FDE's. */
867 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, i
, fde
)
871 /* Don't emit EH unwind info for leaf functions that don't need it. */
872 if (for_eh
&& !fde_needed_for_eh_p (fde
))
875 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
876 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
877 augmentation
, any_lsda_needed
, lsda_encoding
);
880 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
881 dw2_asm_output_data (4, 0, "End of Table");
882 #ifdef MIPS_DEBUGGING_INFO
883 /* Work around Irix 6 assembler bug whereby labels at the end of a section
884 get a value of 0. Putting .align 0 after the label fixes it. */
885 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
888 /* Turn off app to make assembly quicker. */
893 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
896 dwarf2out_do_cfi_startproc (bool second
)
900 rtx personality
= get_personality_function (current_function_decl
);
902 fprintf (asm_out_file
, "\t.cfi_startproc\n");
906 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
909 /* ??? The GAS support isn't entirely consistent. We have to
910 handle indirect support ourselves, but PC-relative is done
911 in the assembler. Further, the assembler can't handle any
912 of the weirder relocation types. */
913 if (enc
& DW_EH_PE_indirect
)
914 ref
= dw2_force_const_mem (ref
, true);
916 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
917 output_addr_const (asm_out_file
, ref
);
918 fputc ('\n', asm_out_file
);
921 if (crtl
->uses_eh_lsda
)
925 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
926 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
927 current_function_funcdef_no
);
928 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
929 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
931 if (enc
& DW_EH_PE_indirect
)
932 ref
= dw2_force_const_mem (ref
, true);
934 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
935 output_addr_const (asm_out_file
, ref
);
936 fputc ('\n', asm_out_file
);
940 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
941 this allocation may be done before pass_final. */
944 dwarf2out_alloc_current_fde (void)
948 fde
= ggc_alloc_cleared_dw_fde_node ();
949 fde
->decl
= current_function_decl
;
950 fde
->funcdef_number
= current_function_funcdef_no
;
951 fde
->fde_index
= VEC_length (dw_fde_ref
, fde_vec
);
952 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
953 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
954 fde
->nothrow
= crtl
->nothrow
;
955 fde
->drap_reg
= INVALID_REGNUM
;
956 fde
->vdrap_reg
= INVALID_REGNUM
;
958 /* Record the FDE associated with this function. */
960 VEC_safe_push (dw_fde_ref
, gc
, fde_vec
, fde
);
965 /* Output a marker (i.e. a label) for the beginning of a function, before
969 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
970 const char *file ATTRIBUTE_UNUSED
)
972 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
978 current_function_func_begin_label
= NULL
;
980 do_frame
= dwarf2out_do_frame ();
982 /* ??? current_function_func_begin_label is also used by except.c for
983 call-site information. We must emit this label if it might be used. */
986 || targetm_common
.except_unwind_info (&global_options
) != UI_TARGET
))
989 fnsec
= function_section (current_function_decl
);
990 switch_to_section (fnsec
);
991 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
992 current_function_funcdef_no
);
993 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
994 current_function_funcdef_no
);
995 dup_label
= xstrdup (label
);
996 current_function_func_begin_label
= dup_label
;
998 /* We can elide the fde allocation if we're not emitting debug info. */
1002 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1003 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1004 would include pass_dwarf2_frame. If we've not created the FDE yet,
1008 fde
= dwarf2out_alloc_current_fde ();
1010 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1011 fde
->dw_fde_begin
= dup_label
;
1012 fde
->dw_fde_current_label
= dup_label
;
1013 fde
->in_std_section
= (fnsec
== text_section
1014 || (cold_text_section
&& fnsec
== cold_text_section
));
1016 /* We only want to output line number information for the genuine dwarf2
1017 prologue case, not the eh frame case. */
1018 #ifdef DWARF2_DEBUGGING_INFO
1020 dwarf2out_source_line (line
, file
, 0, true);
1023 if (dwarf2out_do_cfi_asm ())
1024 dwarf2out_do_cfi_startproc (false);
1027 rtx personality
= get_personality_function (current_function_decl
);
1028 if (!current_unit_personality
)
1029 current_unit_personality
= personality
;
1031 /* We cannot keep a current personality per function as without CFI
1032 asm, at the point where we emit the CFI data, there is no current
1033 function anymore. */
1034 if (personality
&& current_unit_personality
!= personality
)
1035 sorry ("multiple EH personalities are supported only with assemblers "
1036 "supporting .cfi_personality directive");
1040 /* Output a marker (i.e. a label) for the end of the generated code
1041 for a function prologue. This gets called *after* the prologue code has
1045 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1046 const char *file ATTRIBUTE_UNUSED
)
1048 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1050 /* Output a label to mark the endpoint of the code generated for this
1052 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1053 current_function_funcdef_no
);
1054 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1055 current_function_funcdef_no
);
1056 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1059 /* Output a marker (i.e. a label) for the beginning of the generated code
1060 for a function epilogue. This gets called *before* the prologue code has
1064 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1065 const char *file ATTRIBUTE_UNUSED
)
1067 dw_fde_ref fde
= cfun
->fde
;
1068 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1070 if (fde
->dw_fde_vms_begin_epilogue
)
1073 /* Output a label to mark the endpoint of the code generated for this
1075 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1076 current_function_funcdef_no
);
1077 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1078 current_function_funcdef_no
);
1079 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1082 /* Output a marker (i.e. a label) for the absolute end of the generated code
1083 for a function definition. This gets called *after* the epilogue code has
1087 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1088 const char *file ATTRIBUTE_UNUSED
)
1091 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1093 last_var_location_insn
= NULL_RTX
;
1094 cached_next_real_insn
= NULL_RTX
;
1096 if (dwarf2out_do_cfi_asm ())
1097 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1099 /* Output a label to mark the endpoint of the code generated for this
1101 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1102 current_function_funcdef_no
);
1103 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1105 gcc_assert (fde
!= NULL
);
1106 if (fde
->dw_fde_second_begin
== NULL
)
1107 fde
->dw_fde_end
= xstrdup (label
);
1111 dwarf2out_frame_finish (void)
1113 /* Output call frame information. */
1114 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1115 output_call_frame_info (0);
1117 /* Output another copy for the unwinder. */
1118 if ((flag_unwind_tables
|| flag_exceptions
)
1119 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1120 output_call_frame_info (1);
1123 /* Note that the current function section is being used for code. */
1126 dwarf2out_note_section_used (void)
1128 section
*sec
= current_function_section ();
1129 if (sec
== text_section
)
1130 text_section_used
= true;
1131 else if (sec
== cold_text_section
)
1132 cold_text_section_used
= true;
1135 static void var_location_switch_text_section (void);
1136 static void set_cur_line_info_table (section
*);
1139 dwarf2out_switch_text_section (void)
1142 dw_fde_ref fde
= cfun
->fde
;
1144 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1146 if (!in_cold_section_p
)
1148 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1149 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1150 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1154 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1155 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1156 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1158 have_multiple_function_sections
= true;
1160 /* There is no need to mark used sections when not debugging. */
1161 if (cold_text_section
!= NULL
)
1162 dwarf2out_note_section_used ();
1164 if (dwarf2out_do_cfi_asm ())
1165 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1167 /* Now do the real section switch. */
1168 sect
= current_function_section ();
1169 switch_to_section (sect
);
1171 fde
->second_in_std_section
1172 = (sect
== text_section
1173 || (cold_text_section
&& sect
== cold_text_section
));
1175 if (dwarf2out_do_cfi_asm ())
1176 dwarf2out_do_cfi_startproc (true);
1178 var_location_switch_text_section ();
1180 set_cur_line_info_table (sect
);
1183 /* And now, the subset of the debugging information support code necessary
1184 for emitting location expressions. */
1186 /* Data about a single source file. */
1187 struct GTY(()) dwarf_file_data
{
1188 const char * filename
;
1192 typedef struct GTY(()) deferred_locations_struct
1196 } deferred_locations
;
1198 DEF_VEC_O(deferred_locations
);
1199 DEF_VEC_ALLOC_O(deferred_locations
,gc
);
1201 static GTY(()) VEC(deferred_locations
, gc
) *deferred_locations_list
;
1203 DEF_VEC_P(dw_die_ref
);
1204 DEF_VEC_ALLOC_P(dw_die_ref
,heap
);
1206 /* Location lists are ranges + location descriptions for that range,
1207 so you can track variables that are in different places over
1208 their entire life. */
1209 typedef struct GTY(()) dw_loc_list_struct
{
1210 dw_loc_list_ref dw_loc_next
;
1211 const char *begin
; /* Label for begin address of range */
1212 const char *end
; /* Label for end address of range */
1213 char *ll_symbol
; /* Label for beginning of location list.
1214 Only on head of list */
1215 const char *section
; /* Section this loclist is relative to */
1216 dw_loc_descr_ref expr
;
1218 /* True if all addresses in this and subsequent lists are known to be
1221 /* True if this list has been replaced by dw_loc_next. */
1224 /* True if the range should be emitted even if begin and end
1229 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1231 /* Convert a DWARF stack opcode into its string name. */
1234 dwarf_stack_op_name (unsigned int op
)
1239 return "DW_OP_addr";
1241 return "DW_OP_deref";
1243 return "DW_OP_const1u";
1245 return "DW_OP_const1s";
1247 return "DW_OP_const2u";
1249 return "DW_OP_const2s";
1251 return "DW_OP_const4u";
1253 return "DW_OP_const4s";
1255 return "DW_OP_const8u";
1257 return "DW_OP_const8s";
1259 return "DW_OP_constu";
1261 return "DW_OP_consts";
1265 return "DW_OP_drop";
1267 return "DW_OP_over";
1269 return "DW_OP_pick";
1271 return "DW_OP_swap";
1275 return "DW_OP_xderef";
1283 return "DW_OP_minus";
1295 return "DW_OP_plus";
1296 case DW_OP_plus_uconst
:
1297 return "DW_OP_plus_uconst";
1303 return "DW_OP_shra";
1321 return "DW_OP_skip";
1323 return "DW_OP_lit0";
1325 return "DW_OP_lit1";
1327 return "DW_OP_lit2";
1329 return "DW_OP_lit3";
1331 return "DW_OP_lit4";
1333 return "DW_OP_lit5";
1335 return "DW_OP_lit6";
1337 return "DW_OP_lit7";
1339 return "DW_OP_lit8";
1341 return "DW_OP_lit9";
1343 return "DW_OP_lit10";
1345 return "DW_OP_lit11";
1347 return "DW_OP_lit12";
1349 return "DW_OP_lit13";
1351 return "DW_OP_lit14";
1353 return "DW_OP_lit15";
1355 return "DW_OP_lit16";
1357 return "DW_OP_lit17";
1359 return "DW_OP_lit18";
1361 return "DW_OP_lit19";
1363 return "DW_OP_lit20";
1365 return "DW_OP_lit21";
1367 return "DW_OP_lit22";
1369 return "DW_OP_lit23";
1371 return "DW_OP_lit24";
1373 return "DW_OP_lit25";
1375 return "DW_OP_lit26";
1377 return "DW_OP_lit27";
1379 return "DW_OP_lit28";
1381 return "DW_OP_lit29";
1383 return "DW_OP_lit30";
1385 return "DW_OP_lit31";
1387 return "DW_OP_reg0";
1389 return "DW_OP_reg1";
1391 return "DW_OP_reg2";
1393 return "DW_OP_reg3";
1395 return "DW_OP_reg4";
1397 return "DW_OP_reg5";
1399 return "DW_OP_reg6";
1401 return "DW_OP_reg7";
1403 return "DW_OP_reg8";
1405 return "DW_OP_reg9";
1407 return "DW_OP_reg10";
1409 return "DW_OP_reg11";
1411 return "DW_OP_reg12";
1413 return "DW_OP_reg13";
1415 return "DW_OP_reg14";
1417 return "DW_OP_reg15";
1419 return "DW_OP_reg16";
1421 return "DW_OP_reg17";
1423 return "DW_OP_reg18";
1425 return "DW_OP_reg19";
1427 return "DW_OP_reg20";
1429 return "DW_OP_reg21";
1431 return "DW_OP_reg22";
1433 return "DW_OP_reg23";
1435 return "DW_OP_reg24";
1437 return "DW_OP_reg25";
1439 return "DW_OP_reg26";
1441 return "DW_OP_reg27";
1443 return "DW_OP_reg28";
1445 return "DW_OP_reg29";
1447 return "DW_OP_reg30";
1449 return "DW_OP_reg31";
1451 return "DW_OP_breg0";
1453 return "DW_OP_breg1";
1455 return "DW_OP_breg2";
1457 return "DW_OP_breg3";
1459 return "DW_OP_breg4";
1461 return "DW_OP_breg5";
1463 return "DW_OP_breg6";
1465 return "DW_OP_breg7";
1467 return "DW_OP_breg8";
1469 return "DW_OP_breg9";
1471 return "DW_OP_breg10";
1473 return "DW_OP_breg11";
1475 return "DW_OP_breg12";
1477 return "DW_OP_breg13";
1479 return "DW_OP_breg14";
1481 return "DW_OP_breg15";
1483 return "DW_OP_breg16";
1485 return "DW_OP_breg17";
1487 return "DW_OP_breg18";
1489 return "DW_OP_breg19";
1491 return "DW_OP_breg20";
1493 return "DW_OP_breg21";
1495 return "DW_OP_breg22";
1497 return "DW_OP_breg23";
1499 return "DW_OP_breg24";
1501 return "DW_OP_breg25";
1503 return "DW_OP_breg26";
1505 return "DW_OP_breg27";
1507 return "DW_OP_breg28";
1509 return "DW_OP_breg29";
1511 return "DW_OP_breg30";
1513 return "DW_OP_breg31";
1515 return "DW_OP_regx";
1517 return "DW_OP_fbreg";
1519 return "DW_OP_bregx";
1521 return "DW_OP_piece";
1522 case DW_OP_deref_size
:
1523 return "DW_OP_deref_size";
1524 case DW_OP_xderef_size
:
1525 return "DW_OP_xderef_size";
1529 case DW_OP_push_object_address
:
1530 return "DW_OP_push_object_address";
1532 return "DW_OP_call2";
1534 return "DW_OP_call4";
1535 case DW_OP_call_ref
:
1536 return "DW_OP_call_ref";
1537 case DW_OP_implicit_value
:
1538 return "DW_OP_implicit_value";
1539 case DW_OP_stack_value
:
1540 return "DW_OP_stack_value";
1541 case DW_OP_form_tls_address
:
1542 return "DW_OP_form_tls_address";
1543 case DW_OP_call_frame_cfa
:
1544 return "DW_OP_call_frame_cfa";
1545 case DW_OP_bit_piece
:
1546 return "DW_OP_bit_piece";
1548 case DW_OP_GNU_push_tls_address
:
1549 return "DW_OP_GNU_push_tls_address";
1550 case DW_OP_GNU_uninit
:
1551 return "DW_OP_GNU_uninit";
1552 case DW_OP_GNU_encoded_addr
:
1553 return "DW_OP_GNU_encoded_addr";
1554 case DW_OP_GNU_implicit_pointer
:
1555 return "DW_OP_GNU_implicit_pointer";
1556 case DW_OP_GNU_entry_value
:
1557 return "DW_OP_GNU_entry_value";
1558 case DW_OP_GNU_const_type
:
1559 return "DW_OP_GNU_const_type";
1560 case DW_OP_GNU_regval_type
:
1561 return "DW_OP_GNU_regval_type";
1562 case DW_OP_GNU_deref_type
:
1563 return "DW_OP_GNU_deref_type";
1564 case DW_OP_GNU_convert
:
1565 return "DW_OP_GNU_convert";
1566 case DW_OP_GNU_reinterpret
:
1567 return "DW_OP_GNU_reinterpret";
1568 case DW_OP_GNU_parameter_ref
:
1569 return "DW_OP_GNU_parameter_ref";
1572 return "OP_<unknown>";
1576 /* Return a pointer to a newly allocated location description. Location
1577 descriptions are simple expression terms that can be strung
1578 together to form more complicated location (address) descriptions. */
1580 static inline dw_loc_descr_ref
1581 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1582 unsigned HOST_WIDE_INT oprnd2
)
1584 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
1586 descr
->dw_loc_opc
= op
;
1587 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1588 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1589 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1590 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1595 /* Return a pointer to a newly allocated location description for
1598 static inline dw_loc_descr_ref
1599 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1602 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1605 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1608 /* Add a location description term to a location description expression. */
1611 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1613 dw_loc_descr_ref
*d
;
1615 /* Find the end of the chain. */
1616 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1622 /* Compare two location operands for exact equality. */
1625 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1627 if (a
->val_class
!= b
->val_class
)
1629 switch (a
->val_class
)
1631 case dw_val_class_none
:
1633 case dw_val_class_addr
:
1634 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1636 case dw_val_class_offset
:
1637 case dw_val_class_unsigned_const
:
1638 case dw_val_class_const
:
1639 case dw_val_class_range_list
:
1640 case dw_val_class_lineptr
:
1641 case dw_val_class_macptr
:
1642 /* These are all HOST_WIDE_INT, signed or unsigned. */
1643 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1645 case dw_val_class_loc
:
1646 return a
->v
.val_loc
== b
->v
.val_loc
;
1647 case dw_val_class_loc_list
:
1648 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1649 case dw_val_class_die_ref
:
1650 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1651 case dw_val_class_fde_ref
:
1652 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1653 case dw_val_class_lbl_id
:
1654 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1655 case dw_val_class_str
:
1656 return a
->v
.val_str
== b
->v
.val_str
;
1657 case dw_val_class_flag
:
1658 return a
->v
.val_flag
== b
->v
.val_flag
;
1659 case dw_val_class_file
:
1660 return a
->v
.val_file
== b
->v
.val_file
;
1661 case dw_val_class_decl_ref
:
1662 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1664 case dw_val_class_const_double
:
1665 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1666 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1668 case dw_val_class_vec
:
1670 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1671 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1673 return (a_len
== b_len
1674 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1677 case dw_val_class_data8
:
1678 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1680 case dw_val_class_vms_delta
:
1681 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1682 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1687 /* Compare two location atoms for exact equality. */
1690 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1692 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1695 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1696 address size, but since we always allocate cleared storage it
1697 should be zero for other types of locations. */
1698 if (a
->dtprel
!= b
->dtprel
)
1701 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1702 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1705 /* Compare two complete location expressions for exact equality. */
1708 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1714 if (a
== NULL
|| b
== NULL
)
1716 if (!loc_descr_equal_p_1 (a
, b
))
1725 /* Add a constant OFFSET to a location expression. */
1728 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1730 dw_loc_descr_ref loc
;
1733 gcc_assert (*list_head
!= NULL
);
1738 /* Find the end of the chain. */
1739 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1743 if (loc
->dw_loc_opc
== DW_OP_fbreg
1744 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1745 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1746 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1747 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1749 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1750 offset. Don't optimize if an signed integer overflow would happen. */
1752 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1753 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1756 else if (offset
> 0)
1757 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1761 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1762 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1766 /* Add a constant OFFSET to a location list. */
1769 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1772 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1773 loc_descr_plus_const (&d
->expr
, offset
);
1776 #define DWARF_REF_SIZE \
1777 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1779 static unsigned long int get_base_type_offset (dw_die_ref
);
1781 /* Return the size of a location descriptor. */
1783 static unsigned long
1784 size_of_loc_descr (dw_loc_descr_ref loc
)
1786 unsigned long size
= 1;
1788 switch (loc
->dw_loc_opc
)
1791 size
+= DWARF2_ADDR_SIZE
;
1810 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1813 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1818 case DW_OP_plus_uconst
:
1819 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1857 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1860 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1863 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1866 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1867 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1870 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1872 case DW_OP_bit_piece
:
1873 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1874 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1876 case DW_OP_deref_size
:
1877 case DW_OP_xderef_size
:
1886 case DW_OP_call_ref
:
1887 size
+= DWARF_REF_SIZE
;
1889 case DW_OP_implicit_value
:
1890 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1891 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1893 case DW_OP_GNU_implicit_pointer
:
1894 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1896 case DW_OP_GNU_entry_value
:
1898 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1899 size
+= size_of_uleb128 (op_size
) + op_size
;
1902 case DW_OP_GNU_const_type
:
1905 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1906 size
+= size_of_uleb128 (o
) + 1;
1907 switch (loc
->dw_loc_oprnd2
.val_class
)
1909 case dw_val_class_vec
:
1910 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1911 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1913 case dw_val_class_const
:
1914 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1916 case dw_val_class_const_double
:
1917 size
+= 2 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1924 case DW_OP_GNU_regval_type
:
1927 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1928 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1929 + size_of_uleb128 (o
);
1932 case DW_OP_GNU_deref_type
:
1935 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1936 size
+= 1 + size_of_uleb128 (o
);
1939 case DW_OP_GNU_convert
:
1940 case DW_OP_GNU_reinterpret
:
1941 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1942 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1946 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1947 size
+= size_of_uleb128 (o
);
1950 case DW_OP_GNU_parameter_ref
:
1960 /* Return the size of a series of location descriptors. */
1963 size_of_locs (dw_loc_descr_ref loc
)
1968 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1969 field, to avoid writing to a PCH file. */
1970 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1972 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1974 size
+= size_of_loc_descr (l
);
1979 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1981 l
->dw_loc_addr
= size
;
1982 size
+= size_of_loc_descr (l
);
1988 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1989 static void get_ref_die_offset_label (char *, dw_die_ref
);
1990 static unsigned long int get_ref_die_offset (dw_die_ref
);
1992 /* Output location description stack opcode's operands (if any).
1993 The for_eh_or_skip parameter controls whether register numbers are
1994 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1995 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1996 info). This should be suppressed for the cases that have not been converted
1997 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2000 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2002 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2003 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2005 switch (loc
->dw_loc_opc
)
2007 #ifdef DWARF2_DEBUGGING_INFO
2010 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
2015 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
2016 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
2018 fputc ('\n', asm_out_file
);
2023 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
2028 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
2029 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
2031 fputc ('\n', asm_out_file
);
2036 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2037 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
2044 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2045 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2047 dw2_asm_output_data (2, offset
, NULL
);
2050 case DW_OP_implicit_value
:
2051 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2052 switch (val2
->val_class
)
2054 case dw_val_class_const
:
2055 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
2057 case dw_val_class_vec
:
2059 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2060 unsigned int len
= val2
->v
.val_vec
.length
;
2064 if (elt_size
> sizeof (HOST_WIDE_INT
))
2069 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2072 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2073 "fp or vector constant word %u", i
);
2076 case dw_val_class_const_double
:
2078 unsigned HOST_WIDE_INT first
, second
;
2080 if (WORDS_BIG_ENDIAN
)
2082 first
= val2
->v
.val_double
.high
;
2083 second
= val2
->v
.val_double
.low
;
2087 first
= val2
->v
.val_double
.low
;
2088 second
= val2
->v
.val_double
.high
;
2090 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2092 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2096 case dw_val_class_addr
:
2097 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
2098 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
2113 case DW_OP_implicit_value
:
2114 /* We currently don't make any attempt to make sure these are
2115 aligned properly like we do for the main unwind info, so
2116 don't support emitting things larger than a byte if we're
2117 only doing unwinding. */
2122 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2125 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2128 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2131 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2133 case DW_OP_plus_uconst
:
2134 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2168 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2172 unsigned r
= val1
->v
.val_unsigned
;
2173 if (for_eh_or_skip
>= 0)
2174 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2175 gcc_assert (size_of_uleb128 (r
)
2176 == size_of_uleb128 (val1
->v
.val_unsigned
));
2177 dw2_asm_output_data_uleb128 (r
, NULL
);
2181 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2185 unsigned r
= val1
->v
.val_unsigned
;
2186 if (for_eh_or_skip
>= 0)
2187 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2188 gcc_assert (size_of_uleb128 (r
)
2189 == size_of_uleb128 (val1
->v
.val_unsigned
));
2190 dw2_asm_output_data_uleb128 (r
, NULL
);
2191 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2195 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2197 case DW_OP_bit_piece
:
2198 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2199 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
2201 case DW_OP_deref_size
:
2202 case DW_OP_xderef_size
:
2203 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2209 if (targetm
.asm_out
.output_dwarf_dtprel
)
2211 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
2214 fputc ('\n', asm_out_file
);
2221 #ifdef DWARF2_DEBUGGING_INFO
2222 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2229 case DW_OP_GNU_implicit_pointer
:
2231 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2232 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2233 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2234 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2235 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2236 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2240 case DW_OP_GNU_entry_value
:
2241 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2242 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2245 case DW_OP_GNU_const_type
:
2247 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2249 dw2_asm_output_data_uleb128 (o
, NULL
);
2250 switch (val2
->val_class
)
2252 case dw_val_class_const
:
2253 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2254 dw2_asm_output_data (1, l
, NULL
);
2255 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2257 case dw_val_class_vec
:
2259 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2260 unsigned int len
= val2
->v
.val_vec
.length
;
2265 dw2_asm_output_data (1, l
, NULL
);
2266 if (elt_size
> sizeof (HOST_WIDE_INT
))
2271 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2274 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2275 "fp or vector constant word %u", i
);
2278 case dw_val_class_const_double
:
2280 unsigned HOST_WIDE_INT first
, second
;
2281 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2283 dw2_asm_output_data (1, 2 * l
, NULL
);
2284 if (WORDS_BIG_ENDIAN
)
2286 first
= val2
->v
.val_double
.high
;
2287 second
= val2
->v
.val_double
.low
;
2291 first
= val2
->v
.val_double
.low
;
2292 second
= val2
->v
.val_double
.high
;
2294 dw2_asm_output_data (l
, first
, NULL
);
2295 dw2_asm_output_data (l
, second
, NULL
);
2303 case DW_OP_GNU_regval_type
:
2305 unsigned r
= val1
->v
.val_unsigned
;
2306 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2308 if (for_eh_or_skip
>= 0)
2310 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2311 gcc_assert (size_of_uleb128 (r
)
2312 == size_of_uleb128 (val1
->v
.val_unsigned
));
2314 dw2_asm_output_data_uleb128 (r
, NULL
);
2315 dw2_asm_output_data_uleb128 (o
, NULL
);
2318 case DW_OP_GNU_deref_type
:
2320 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2322 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2323 dw2_asm_output_data_uleb128 (o
, NULL
);
2326 case DW_OP_GNU_convert
:
2327 case DW_OP_GNU_reinterpret
:
2328 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2329 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2332 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2334 dw2_asm_output_data_uleb128 (o
, NULL
);
2338 case DW_OP_GNU_parameter_ref
:
2341 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2342 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2343 dw2_asm_output_data (4, o
, NULL
);
2348 /* Other codes have no operands. */
2353 /* Output a sequence of location operations.
2354 The for_eh_or_skip parameter controls whether register numbers are
2355 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2356 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2357 info). This should be suppressed for the cases that have not been converted
2358 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2361 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2363 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2365 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2366 /* Output the opcode. */
2367 if (for_eh_or_skip
>= 0
2368 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2370 unsigned r
= (opc
- DW_OP_breg0
);
2371 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2372 gcc_assert (r
<= 31);
2373 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2375 else if (for_eh_or_skip
>= 0
2376 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2378 unsigned r
= (opc
- DW_OP_reg0
);
2379 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2380 gcc_assert (r
<= 31);
2381 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2384 dw2_asm_output_data (1, opc
,
2385 "%s", dwarf_stack_op_name (opc
));
2387 /* Output the operand(s) (if any). */
2388 output_loc_operands (loc
, for_eh_or_skip
);
2392 /* Output location description stack opcode's operands (if any).
2393 The output is single bytes on a line, suitable for .cfi_escape. */
2396 output_loc_operands_raw (dw_loc_descr_ref loc
)
2398 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2399 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2401 switch (loc
->dw_loc_opc
)
2404 case DW_OP_implicit_value
:
2405 /* We cannot output addresses in .cfi_escape, only bytes. */
2411 case DW_OP_deref_size
:
2412 case DW_OP_xderef_size
:
2413 fputc (',', asm_out_file
);
2414 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2419 fputc (',', asm_out_file
);
2420 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2425 fputc (',', asm_out_file
);
2426 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2431 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2432 fputc (',', asm_out_file
);
2433 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2441 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2442 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2444 fputc (',', asm_out_file
);
2445 dw2_asm_output_data_raw (2, offset
);
2451 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2452 gcc_assert (size_of_uleb128 (r
)
2453 == size_of_uleb128 (val1
->v
.val_unsigned
));
2454 fputc (',', asm_out_file
);
2455 dw2_asm_output_data_uleb128_raw (r
);
2460 case DW_OP_plus_uconst
:
2462 fputc (',', asm_out_file
);
2463 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2466 case DW_OP_bit_piece
:
2467 fputc (',', asm_out_file
);
2468 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2469 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2506 fputc (',', asm_out_file
);
2507 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2512 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2513 gcc_assert (size_of_uleb128 (r
)
2514 == size_of_uleb128 (val1
->v
.val_unsigned
));
2515 fputc (',', asm_out_file
);
2516 dw2_asm_output_data_uleb128_raw (r
);
2517 fputc (',', asm_out_file
);
2518 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2522 case DW_OP_GNU_implicit_pointer
:
2523 case DW_OP_GNU_entry_value
:
2524 case DW_OP_GNU_const_type
:
2525 case DW_OP_GNU_regval_type
:
2526 case DW_OP_GNU_deref_type
:
2527 case DW_OP_GNU_convert
:
2528 case DW_OP_GNU_reinterpret
:
2529 case DW_OP_GNU_parameter_ref
:
2534 /* Other codes have no operands. */
2540 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2544 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2545 /* Output the opcode. */
2546 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2548 unsigned r
= (opc
- DW_OP_breg0
);
2549 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2550 gcc_assert (r
<= 31);
2551 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2553 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2555 unsigned r
= (opc
- DW_OP_reg0
);
2556 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2557 gcc_assert (r
<= 31);
2558 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2560 /* Output the opcode. */
2561 fprintf (asm_out_file
, "%#x", opc
);
2562 output_loc_operands_raw (loc
);
2564 if (!loc
->dw_loc_next
)
2566 loc
= loc
->dw_loc_next
;
2568 fputc (',', asm_out_file
);
2572 /* This function builds a dwarf location descriptor sequence from a
2573 dw_cfa_location, adding the given OFFSET to the result of the
2576 struct dw_loc_descr_struct
*
2577 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2579 struct dw_loc_descr_struct
*head
, *tmp
;
2581 offset
+= cfa
->offset
;
2585 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2586 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2587 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2588 add_loc_descr (&head
, tmp
);
2591 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2592 add_loc_descr (&head
, tmp
);
2596 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2601 /* This function builds a dwarf location descriptor sequence for
2602 the address at OFFSET from the CFA when stack is aligned to
2605 struct dw_loc_descr_struct
*
2606 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2607 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2609 struct dw_loc_descr_struct
*head
;
2610 unsigned int dwarf_fp
2611 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2613 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2614 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2616 head
= new_reg_loc_descr (dwarf_fp
, 0);
2617 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2618 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2619 loc_descr_plus_const (&head
, offset
);
2622 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2626 /* And now, the support for symbolic debugging information. */
2628 /* .debug_str support. */
2629 static int output_indirect_string (void **, void *);
2631 static void dwarf2out_init (const char *);
2632 static void dwarf2out_finish (const char *);
2633 static void dwarf2out_assembly_start (void);
2634 static void dwarf2out_define (unsigned int, const char *);
2635 static void dwarf2out_undef (unsigned int, const char *);
2636 static void dwarf2out_start_source_file (unsigned, const char *);
2637 static void dwarf2out_end_source_file (unsigned);
2638 static void dwarf2out_function_decl (tree
);
2639 static void dwarf2out_begin_block (unsigned, unsigned);
2640 static void dwarf2out_end_block (unsigned, unsigned);
2641 static bool dwarf2out_ignore_block (const_tree
);
2642 static void dwarf2out_global_decl (tree
);
2643 static void dwarf2out_type_decl (tree
, int);
2644 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2645 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2647 static void dwarf2out_abstract_function (tree
);
2648 static void dwarf2out_var_location (rtx
);
2649 static void dwarf2out_begin_function (tree
);
2650 static void dwarf2out_set_name (tree
, tree
);
2652 /* The debug hooks structure. */
2654 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2658 dwarf2out_assembly_start
,
2661 dwarf2out_start_source_file
,
2662 dwarf2out_end_source_file
,
2663 dwarf2out_begin_block
,
2664 dwarf2out_end_block
,
2665 dwarf2out_ignore_block
,
2666 dwarf2out_source_line
,
2667 dwarf2out_begin_prologue
,
2668 #if VMS_DEBUGGING_INFO
2669 dwarf2out_vms_end_prologue
,
2670 dwarf2out_vms_begin_epilogue
,
2672 debug_nothing_int_charstar
,
2673 debug_nothing_int_charstar
,
2675 dwarf2out_end_epilogue
,
2676 dwarf2out_begin_function
,
2677 debug_nothing_int
, /* end_function */
2678 dwarf2out_function_decl
, /* function_decl */
2679 dwarf2out_global_decl
,
2680 dwarf2out_type_decl
, /* type_decl */
2681 dwarf2out_imported_module_or_decl
,
2682 debug_nothing_tree
, /* deferred_inline_function */
2683 /* The DWARF 2 backend tries to reduce debugging bloat by not
2684 emitting the abstract description of inline functions until
2685 something tries to reference them. */
2686 dwarf2out_abstract_function
, /* outlining_inline_function */
2687 debug_nothing_rtx
, /* label */
2688 debug_nothing_int
, /* handle_pch */
2689 dwarf2out_var_location
,
2690 dwarf2out_switch_text_section
,
2692 1, /* start_end_main_source_file */
2693 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2696 /* NOTE: In the comments in this file, many references are made to
2697 "Debugging Information Entries". This term is abbreviated as `DIE'
2698 throughout the remainder of this file. */
2700 /* An internal representation of the DWARF output is built, and then
2701 walked to generate the DWARF debugging info. The walk of the internal
2702 representation is done after the entire program has been compiled.
2703 The types below are used to describe the internal representation. */
2705 /* Whether to put type DIEs into their own section .debug_types instead
2706 of making them part of the .debug_info section. Only supported for
2707 Dwarf V4 or higher and the user didn't disable them through
2708 -fno-debug-types-section. It is more efficient to put them in a
2709 separate comdat sections since the linker will then be able to
2710 remove duplicates. But not all tools support .debug_types sections
2713 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2715 /* Various DIE's use offsets relative to the beginning of the
2716 .debug_info section to refer to each other. */
2718 typedef long int dw_offset
;
2720 /* Define typedefs here to avoid circular dependencies. */
2722 typedef struct dw_attr_struct
*dw_attr_ref
;
2723 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2724 typedef struct pubname_struct
*pubname_ref
;
2725 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2726 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2727 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2729 /* The entries in the line_info table more-or-less mirror the opcodes
2730 that are used in the real dwarf line table. Arrays of these entries
2731 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2734 enum dw_line_info_opcode
{
2735 /* Emit DW_LNE_set_address; the operand is the label index. */
2738 /* Emit a row to the matrix with the given line. This may be done
2739 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2743 /* Emit a DW_LNS_set_file. */
2746 /* Emit a DW_LNS_set_column. */
2749 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2752 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2753 LI_set_prologue_end
,
2754 LI_set_epilogue_begin
,
2756 /* Emit a DW_LNE_set_discriminator. */
2757 LI_set_discriminator
2760 typedef struct GTY(()) dw_line_info_struct
{
2761 enum dw_line_info_opcode opcode
;
2763 } dw_line_info_entry
;
2765 DEF_VEC_O(dw_line_info_entry
);
2766 DEF_VEC_ALLOC_O(dw_line_info_entry
, gc
);
2768 typedef struct GTY(()) dw_line_info_table_struct
{
2769 /* The label that marks the end of this section. */
2770 const char *end_label
;
2772 /* The values for the last row of the matrix, as collected in the table.
2773 These are used to minimize the changes to the next row. */
2774 unsigned int file_num
;
2775 unsigned int line_num
;
2776 unsigned int column_num
;
2781 VEC(dw_line_info_entry
, gc
) *entries
;
2782 } dw_line_info_table
;
2784 typedef dw_line_info_table
*dw_line_info_table_p
;
2786 DEF_VEC_P(dw_line_info_table_p
);
2787 DEF_VEC_ALLOC_P(dw_line_info_table_p
, gc
);
2789 /* Each DIE attribute has a field specifying the attribute kind,
2790 a link to the next attribute in the chain, and an attribute value.
2791 Attributes are typically linked below the DIE they modify. */
2793 typedef struct GTY(()) dw_attr_struct
{
2794 enum dwarf_attribute dw_attr
;
2795 dw_val_node dw_attr_val
;
2799 DEF_VEC_O(dw_attr_node
);
2800 DEF_VEC_ALLOC_O(dw_attr_node
,gc
);
2802 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2803 The children of each node form a circular list linked by
2804 die_sib. die_child points to the node *before* the "first" child node. */
2806 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
2807 union die_symbol_or_type_node
2809 char * GTY ((tag ("0"))) die_symbol
;
2810 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2812 GTY ((desc ("use_debug_types"))) die_id
;
2813 VEC(dw_attr_node
,gc
) * die_attr
;
2814 dw_die_ref die_parent
;
2815 dw_die_ref die_child
;
2817 dw_die_ref die_definition
; /* ref from a specification to its definition */
2818 dw_offset die_offset
;
2819 unsigned long die_abbrev
;
2821 /* Die is used and must not be pruned as unused. */
2822 int die_perennial_p
;
2823 unsigned int decl_id
;
2824 enum dwarf_tag die_tag
;
2828 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2829 #define FOR_EACH_CHILD(die, c, expr) do { \
2830 c = die->die_child; \
2834 } while (c != die->die_child); \
2837 /* The pubname structure */
2839 typedef struct GTY(()) pubname_struct
{
2845 DEF_VEC_O(pubname_entry
);
2846 DEF_VEC_ALLOC_O(pubname_entry
, gc
);
2848 struct GTY(()) dw_ranges_struct
{
2849 /* If this is positive, it's a block number, otherwise it's a
2850 bitwise-negated index into dw_ranges_by_label. */
2854 /* A structure to hold a macinfo entry. */
2856 typedef struct GTY(()) macinfo_struct
{
2858 unsigned HOST_WIDE_INT lineno
;
2863 DEF_VEC_O(macinfo_entry
);
2864 DEF_VEC_ALLOC_O(macinfo_entry
, gc
);
2866 struct GTY(()) dw_ranges_by_label_struct
{
2871 /* The comdat type node structure. */
2872 typedef struct GTY(()) comdat_type_struct
2874 dw_die_ref root_die
;
2875 dw_die_ref type_die
;
2876 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2877 struct comdat_type_struct
*next
;
2881 /* The limbo die list structure. */
2882 typedef struct GTY(()) limbo_die_struct
{
2885 struct limbo_die_struct
*next
;
2889 typedef struct skeleton_chain_struct
2893 struct skeleton_chain_struct
*parent
;
2895 skeleton_chain_node
;
2897 /* Define a macro which returns nonzero for a TYPE_DECL which was
2898 implicitly generated for a type.
2900 Note that, unlike the C front-end (which generates a NULL named
2901 TYPE_DECL node for each complete tagged type, each array type,
2902 and each function type node created) the C++ front-end generates
2903 a _named_ TYPE_DECL node for each tagged type node created.
2904 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2905 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2906 front-end, but for each type, tagged or not. */
2908 #define TYPE_DECL_IS_STUB(decl) \
2909 (DECL_NAME (decl) == NULL_TREE \
2910 || (DECL_ARTIFICIAL (decl) \
2911 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2912 /* This is necessary for stub decls that \
2913 appear in nested inline functions. */ \
2914 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2915 && (decl_ultimate_origin (decl) \
2916 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2918 /* Information concerning the compilation unit's programming
2919 language, and compiler version. */
2921 /* Fixed size portion of the DWARF compilation unit header. */
2922 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2923 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2925 /* Fixed size portion of the DWARF comdat type unit header. */
2926 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2927 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2928 + DWARF_OFFSET_SIZE)
2930 /* Fixed size portion of public names info. */
2931 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2933 /* Fixed size portion of the address range info. */
2934 #define DWARF_ARANGES_HEADER_SIZE \
2935 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2936 DWARF2_ADDR_SIZE * 2) \
2937 - DWARF_INITIAL_LENGTH_SIZE)
2939 /* Size of padding portion in the address range info. It must be
2940 aligned to twice the pointer size. */
2941 #define DWARF_ARANGES_PAD_SIZE \
2942 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2943 DWARF2_ADDR_SIZE * 2) \
2944 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2946 /* Use assembler line directives if available. */
2947 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2948 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2949 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2951 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2955 /* Minimum line offset in a special line info. opcode.
2956 This value was chosen to give a reasonable range of values. */
2957 #define DWARF_LINE_BASE -10
2959 /* First special line opcode - leave room for the standard opcodes. */
2960 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2962 /* Range of line offsets in a special line info. opcode. */
2963 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2965 /* Flag that indicates the initial value of the is_stmt_start flag.
2966 In the present implementation, we do not mark any lines as
2967 the beginning of a source statement, because that information
2968 is not made available by the GCC front-end. */
2969 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2971 /* Maximum number of operations per instruction bundle. */
2972 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2973 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2976 /* This location is used by calc_die_sizes() to keep track
2977 the offset of each DIE within the .debug_info section. */
2978 static unsigned long next_die_offset
;
2980 /* Record the root of the DIE's built for the current compilation unit. */
2981 static GTY(()) dw_die_ref single_comp_unit_die
;
2983 /* A list of type DIEs that have been separated into comdat sections. */
2984 static GTY(()) comdat_type_node
*comdat_type_list
;
2986 /* A list of DIEs with a NULL parent waiting to be relocated. */
2987 static GTY(()) limbo_die_node
*limbo_die_list
;
2989 /* A list of DIEs for which we may have to generate
2990 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2991 static GTY(()) limbo_die_node
*deferred_asm_name
;
2993 /* Filenames referenced by this compilation unit. */
2994 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
2996 /* A hash table of references to DIE's that describe declarations.
2997 The key is a DECL_UID() which is a unique number identifying each decl. */
2998 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
3000 /* A hash table of references to DIE's that describe COMMON blocks.
3001 The key is DECL_UID() ^ die_parent. */
3002 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
3004 typedef struct GTY(()) die_arg_entry_struct
{
3009 DEF_VEC_O(die_arg_entry
);
3010 DEF_VEC_ALLOC_O(die_arg_entry
,gc
);
3012 /* Node of the variable location list. */
3013 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
3014 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
3015 EXPR_LIST chain. For small bitsizes, bitsize is encoded
3016 in mode of the EXPR_LIST node and first EXPR_LIST operand
3017 is either NOTE_INSN_VAR_LOCATION for a piece with a known
3018 location or NULL for padding. For larger bitsizes,
3019 mode is 0 and first operand is a CONCAT with bitsize
3020 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
3021 NULL as second operand. */
3023 const char * GTY (()) label
;
3024 struct var_loc_node
* GTY (()) next
;
3027 /* Variable location list. */
3028 struct GTY (()) var_loc_list_def
{
3029 struct var_loc_node
* GTY (()) first
;
3031 /* Pointer to the last but one or last element of the
3032 chained list. If the list is empty, both first and
3033 last are NULL, if the list contains just one node
3034 or the last node certainly is not redundant, it points
3035 to the last node, otherwise points to the last but one.
3036 Do not mark it for GC because it is marked through the chain. */
3037 struct var_loc_node
* GTY ((skip ("%h"))) last
;
3039 /* Pointer to the last element before section switch,
3040 if NULL, either sections weren't switched or first
3041 is after section switch. */
3042 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
3044 /* DECL_UID of the variable decl. */
3045 unsigned int decl_id
;
3047 typedef struct var_loc_list_def var_loc_list
;
3049 /* Call argument location list. */
3050 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
3051 rtx
GTY (()) call_arg_loc_note
;
3052 const char * GTY (()) label
;
3053 tree
GTY (()) block
;
3055 rtx
GTY (()) symbol_ref
;
3056 struct call_arg_loc_node
* GTY (()) next
;
3060 /* Table of decl location linked lists. */
3061 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
3063 /* Head and tail of call_arg_loc chain. */
3064 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
3065 static struct call_arg_loc_node
*call_arg_loc_last
;
3067 /* Number of call sites in the current function. */
3068 static int call_site_count
= -1;
3069 /* Number of tail call sites in the current function. */
3070 static int tail_call_site_count
= -1;
3072 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
3074 static VEC (dw_die_ref
, heap
) *block_map
;
3076 /* A cached location list. */
3077 struct GTY (()) cached_dw_loc_list_def
{
3078 /* The DECL_UID of the decl that this entry describes. */
3079 unsigned int decl_id
;
3081 /* The cached location list. */
3082 dw_loc_list_ref loc_list
;
3084 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
3086 /* Table of cached location lists. */
3087 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
3089 /* A pointer to the base of a list of references to DIE's that
3090 are uniquely identified by their tag, presence/absence of
3091 children DIE's, and list of attribute/value pairs. */
3092 static GTY((length ("abbrev_die_table_allocated")))
3093 dw_die_ref
*abbrev_die_table
;
3095 /* Number of elements currently allocated for abbrev_die_table. */
3096 static GTY(()) unsigned abbrev_die_table_allocated
;
3098 /* Number of elements in type_die_table currently in use. */
3099 static GTY(()) unsigned abbrev_die_table_in_use
;
3101 /* Size (in elements) of increments by which we may expand the
3102 abbrev_die_table. */
3103 #define ABBREV_DIE_TABLE_INCREMENT 256
3105 /* A global counter for generating labels for line number data. */
3106 static unsigned int line_info_label_num
;
3108 /* The current table to which we should emit line number information
3109 for the current function. This will be set up at the beginning of
3110 assembly for the function. */
3111 static dw_line_info_table
*cur_line_info_table
;
3113 /* The two default tables of line number info. */
3114 static GTY(()) dw_line_info_table
*text_section_line_info
;
3115 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
3117 /* The set of all non-default tables of line number info. */
3118 static GTY(()) VEC (dw_line_info_table_p
, gc
) *separate_line_info
;
3120 /* A flag to tell pubnames/types export if there is an info section to
3122 static bool info_section_emitted
;
3124 /* A pointer to the base of a table that contains a list of publicly
3125 accessible names. */
3126 static GTY (()) VEC (pubname_entry
, gc
) * pubname_table
;
3128 /* A pointer to the base of a table that contains a list of publicly
3129 accessible types. */
3130 static GTY (()) VEC (pubname_entry
, gc
) * pubtype_table
;
3132 /* A pointer to the base of a table that contains a list of macro
3133 defines/undefines (and file start/end markers). */
3134 static GTY (()) VEC (macinfo_entry
, gc
) * macinfo_table
;
3136 /* Array of dies for which we should generate .debug_ranges info. */
3137 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
3139 /* Number of elements currently allocated for ranges_table. */
3140 static GTY(()) unsigned ranges_table_allocated
;
3142 /* Number of elements in ranges_table currently in use. */
3143 static GTY(()) unsigned ranges_table_in_use
;
3145 /* Array of pairs of labels referenced in ranges_table. */
3146 static GTY ((length ("ranges_by_label_allocated")))
3147 dw_ranges_by_label_ref ranges_by_label
;
3149 /* Number of elements currently allocated for ranges_by_label. */
3150 static GTY(()) unsigned ranges_by_label_allocated
;
3152 /* Number of elements in ranges_by_label currently in use. */
3153 static GTY(()) unsigned ranges_by_label_in_use
;
3155 /* Size (in elements) of increments by which we may expand the
3157 #define RANGES_TABLE_INCREMENT 64
3159 /* Whether we have location lists that need outputting */
3160 static GTY(()) bool have_location_lists
;
3162 /* Unique label counter. */
3163 static GTY(()) unsigned int loclabel_num
;
3165 /* Unique label counter for point-of-call tables. */
3166 static GTY(()) unsigned int poc_label_num
;
3168 /* Record whether the function being analyzed contains inlined functions. */
3169 static int current_function_has_inlines
;
3171 /* The last file entry emitted by maybe_emit_file(). */
3172 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3174 /* Number of internal labels generated by gen_internal_sym(). */
3175 static GTY(()) int label_num
;
3177 /* Cached result of previous call to lookup_filename. */
3178 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
3180 static GTY(()) VEC(die_arg_entry
,gc
) *tmpl_value_parm_die_table
;
3182 /* Instances of generic types for which we need to generate debug
3183 info that describe their generic parameters and arguments. That
3184 generation needs to happen once all types are properly laid out so
3185 we do it at the end of compilation. */
3186 static GTY(()) VEC(tree
,gc
) *generic_type_instances
;
3188 /* Offset from the "steady-state frame pointer" to the frame base,
3189 within the current function. */
3190 static HOST_WIDE_INT frame_pointer_fb_offset
;
3191 static bool frame_pointer_fb_offset_valid
;
3193 static VEC (dw_die_ref
, heap
) *base_types
;
3195 /* Forward declarations for functions defined in this file. */
3197 static int is_pseudo_reg (const_rtx
);
3198 static tree
type_main_variant (tree
);
3199 static int is_tagged_type (const_tree
);
3200 static const char *dwarf_tag_name (unsigned);
3201 static const char *dwarf_attr_name (unsigned);
3202 static const char *dwarf_form_name (unsigned);
3203 static tree
decl_ultimate_origin (const_tree
);
3204 static tree
decl_class_context (tree
);
3205 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
3206 static inline enum dw_val_class
AT_class (dw_attr_ref
);
3207 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3208 static inline unsigned AT_flag (dw_attr_ref
);
3209 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3210 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
3211 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3212 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
3213 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3214 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3215 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3216 unsigned int, unsigned char *);
3217 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3218 static hashval_t
debug_str_do_hash (const void *);
3219 static int debug_str_eq (const void *, const void *);
3220 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3221 static inline const char *AT_string (dw_attr_ref
);
3222 static enum dwarf_form
AT_string_form (dw_attr_ref
);
3223 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3224 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3225 static inline dw_die_ref
AT_ref (dw_attr_ref
);
3226 static inline int AT_ref_external (dw_attr_ref
);
3227 static inline void set_AT_ref_external (dw_attr_ref
, int);
3228 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3229 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3230 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
3231 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3233 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
3234 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
3235 static inline rtx
AT_addr (dw_attr_ref
);
3236 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3237 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3238 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3239 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3240 unsigned HOST_WIDE_INT
);
3241 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3243 static inline const char *AT_lbl (dw_attr_ref
);
3244 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
3245 static const char *get_AT_low_pc (dw_die_ref
);
3246 static const char *get_AT_hi_pc (dw_die_ref
);
3247 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3248 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3249 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3250 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3251 static bool is_cxx (void);
3252 static bool is_fortran (void);
3253 static bool is_ada (void);
3254 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
3255 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3256 static void add_child_die (dw_die_ref
, dw_die_ref
);
3257 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3258 static dw_die_ref
lookup_type_die (tree
);
3259 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3260 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3261 static void equate_type_number_to_die (tree
, dw_die_ref
);
3262 static hashval_t
decl_die_table_hash (const void *);
3263 static int decl_die_table_eq (const void *, const void *);
3264 static dw_die_ref
lookup_decl_die (tree
);
3265 static hashval_t
common_block_die_table_hash (const void *);
3266 static int common_block_die_table_eq (const void *, const void *);
3267 static hashval_t
decl_loc_table_hash (const void *);
3268 static int decl_loc_table_eq (const void *, const void *);
3269 static var_loc_list
*lookup_decl_loc (const_tree
);
3270 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3271 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3272 static void print_spaces (FILE *);
3273 static void print_die (dw_die_ref
, FILE *);
3274 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3275 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3276 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3277 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3278 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3279 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3280 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3281 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3282 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
3283 struct md5_ctx
*, int *);
3284 struct checksum_attributes
;
3285 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3286 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3287 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3288 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3289 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3290 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3291 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3292 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3293 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3294 static void compute_section_prefix (dw_die_ref
);
3295 static int is_type_die (dw_die_ref
);
3296 static int is_comdat_die (dw_die_ref
);
3297 static int is_symbol_die (dw_die_ref
);
3298 static void assign_symbol_names (dw_die_ref
);
3299 static void break_out_includes (dw_die_ref
);
3300 static int is_declaration_die (dw_die_ref
);
3301 static int should_move_die_to_comdat (dw_die_ref
);
3302 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3303 static dw_die_ref
clone_die (dw_die_ref
);
3304 static dw_die_ref
clone_tree (dw_die_ref
);
3305 static void copy_declaration_context (dw_die_ref
, dw_die_ref
);
3306 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3307 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3308 static dw_die_ref
generate_skeleton (dw_die_ref
);
3309 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3311 static void break_out_comdat_types (dw_die_ref
);
3312 static dw_die_ref
copy_ancestor_tree (dw_die_ref
, dw_die_ref
, htab_t
);
3313 static void copy_decls_walk (dw_die_ref
, dw_die_ref
, htab_t
);
3314 static void copy_decls_for_unworthy_types (dw_die_ref
);
3316 static hashval_t
htab_cu_hash (const void *);
3317 static int htab_cu_eq (const void *, const void *);
3318 static void htab_cu_del (void *);
3319 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
3320 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
3321 static void add_sibling_attributes (dw_die_ref
);
3322 static void build_abbrev_table (dw_die_ref
);
3323 static void output_location_lists (dw_die_ref
);
3324 static int constant_size (unsigned HOST_WIDE_INT
);
3325 static unsigned long size_of_die (dw_die_ref
);
3326 static void calc_die_sizes (dw_die_ref
);
3327 static void calc_base_type_die_sizes (void);
3328 static void mark_dies (dw_die_ref
);
3329 static void unmark_dies (dw_die_ref
);
3330 static void unmark_all_dies (dw_die_ref
);
3331 static unsigned long size_of_pubnames (VEC (pubname_entry
,gc
) *);
3332 static unsigned long size_of_aranges (void);
3333 static enum dwarf_form
value_format (dw_attr_ref
);
3334 static void output_value_format (dw_attr_ref
);
3335 static void output_abbrev_section (void);
3336 static void output_die_symbol (dw_die_ref
);
3337 static void output_die (dw_die_ref
);
3338 static void output_compilation_unit_header (void);
3339 static void output_comp_unit (dw_die_ref
, int);
3340 static void output_comdat_type_unit (comdat_type_node
*);
3341 static const char *dwarf2_name (tree
, int);
3342 static void add_pubname (tree
, dw_die_ref
);
3343 static void add_pubname_string (const char *, dw_die_ref
);
3344 static void add_pubtype (tree
, dw_die_ref
);
3345 static void output_pubnames (VEC (pubname_entry
,gc
) *);
3346 static void output_aranges (unsigned long);
3347 static unsigned int add_ranges_num (int);
3348 static unsigned int add_ranges (const_tree
);
3349 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3351 static void output_ranges (void);
3352 static dw_line_info_table
*new_line_info_table (void);
3353 static void output_line_info (void);
3354 static void output_file_names (void);
3355 static dw_die_ref
base_type_die (tree
);
3356 static int is_base_type (tree
);
3357 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3358 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3359 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3360 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3361 static int type_is_enum (const_tree
);
3362 static unsigned int dbx_reg_number (const_rtx
);
3363 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3364 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3365 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3366 enum var_init_status
);
3367 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3368 enum var_init_status
);
3369 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3370 enum var_init_status
);
3371 static int is_based_loc (const_rtx
);
3372 static int resolve_one_addr (rtx
*, void *);
3373 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3374 enum var_init_status
);
3375 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
3376 enum var_init_status
);
3377 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3378 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3379 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3380 static tree
field_type (const_tree
);
3381 static unsigned int simple_type_align_in_bits (const_tree
);
3382 static unsigned int simple_decl_align_in_bits (const_tree
);
3383 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3384 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3385 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3387 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3388 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3389 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3390 static void insert_double (double_int
, unsigned char *);
3391 static void insert_float (const_rtx
, unsigned char *);
3392 static rtx
rtl_for_decl_location (tree
);
3393 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3394 enum dwarf_attribute
);
3395 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3396 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3397 static void add_name_attribute (dw_die_ref
, const char *);
3398 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3399 static void add_comp_dir_attribute (dw_die_ref
);
3400 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3401 static void add_subscript_info (dw_die_ref
, tree
, bool);
3402 static void add_byte_size_attribute (dw_die_ref
, tree
);
3403 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3404 static void add_bit_size_attribute (dw_die_ref
, tree
);
3405 static void add_prototyped_attribute (dw_die_ref
, tree
);
3406 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3407 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3408 static void add_src_coords_attributes (dw_die_ref
, tree
);
3409 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3410 static void push_decl_scope (tree
);
3411 static void pop_decl_scope (void);
3412 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3413 static inline int local_scope_p (dw_die_ref
);
3414 static inline int class_scope_p (dw_die_ref
);
3415 static inline int class_or_namespace_scope_p (dw_die_ref
);
3416 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3417 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3418 static const char *type_tag (const_tree
);
3419 static tree
member_declared_type (const_tree
);
3421 static const char *decl_start_label (tree
);
3423 static void gen_array_type_die (tree
, dw_die_ref
);
3424 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3426 static void gen_entry_point_die (tree
, dw_die_ref
);
3428 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3429 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3430 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3431 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3432 static void gen_formal_types_die (tree
, dw_die_ref
);
3433 static void gen_subprogram_die (tree
, dw_die_ref
);
3434 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3435 static void gen_const_die (tree
, dw_die_ref
);
3436 static void gen_label_die (tree
, dw_die_ref
);
3437 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3438 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3439 static void gen_field_die (tree
, dw_die_ref
);
3440 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3441 static dw_die_ref
gen_compile_unit_die (const char *);
3442 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3443 static void gen_member_die (tree
, dw_die_ref
);
3444 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3445 enum debug_info_usage
);
3446 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3447 static void gen_typedef_die (tree
, dw_die_ref
);
3448 static void gen_type_die (tree
, dw_die_ref
);
3449 static void gen_block_die (tree
, dw_die_ref
, int);
3450 static void decls_for_scope (tree
, dw_die_ref
, int);
3451 static inline int is_redundant_typedef (const_tree
);
3452 static bool is_naming_typedef_decl (const_tree
);
3453 static inline dw_die_ref
get_context_die (tree
);
3454 static void gen_namespace_die (tree
, dw_die_ref
);
3455 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3456 static dw_die_ref
force_decl_die (tree
);
3457 static dw_die_ref
force_type_die (tree
);
3458 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3459 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3460 static struct dwarf_file_data
* lookup_filename (const char *);
3461 static void retry_incomplete_types (void);
3462 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3463 static void gen_generic_params_dies (tree
);
3464 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3465 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3466 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3467 static int file_info_cmp (const void *, const void *);
3468 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3469 const char *, const char *);
3470 static void output_loc_list (dw_loc_list_ref
);
3471 static char *gen_internal_sym (const char *);
3473 static void prune_unmark_dies (dw_die_ref
);
3474 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3475 static void prune_unused_types_mark (dw_die_ref
, int);
3476 static void prune_unused_types_walk (dw_die_ref
);
3477 static void prune_unused_types_walk_attribs (dw_die_ref
);
3478 static void prune_unused_types_prune (dw_die_ref
);
3479 static void prune_unused_types (void);
3480 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3481 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3482 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3483 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3484 const char *, const char *);
3485 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3486 static void gen_remaining_tmpl_value_param_die_attribute (void);
3487 static bool generic_type_p (tree
);
3488 static void schedule_generic_params_dies_gen (tree t
);
3489 static void gen_scheduled_generic_parms_dies (void);
3491 /* Section names used to hold DWARF debugging information. */
3492 #ifndef DEBUG_INFO_SECTION
3493 #define DEBUG_INFO_SECTION ".debug_info"
3495 #ifndef DEBUG_ABBREV_SECTION
3496 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3498 #ifndef DEBUG_ARANGES_SECTION
3499 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3501 #ifndef DEBUG_MACINFO_SECTION
3502 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3504 #ifndef DEBUG_MACRO_SECTION
3505 #define DEBUG_MACRO_SECTION ".debug_macro"
3507 #ifndef DEBUG_LINE_SECTION
3508 #define DEBUG_LINE_SECTION ".debug_line"
3510 #ifndef DEBUG_LOC_SECTION
3511 #define DEBUG_LOC_SECTION ".debug_loc"
3513 #ifndef DEBUG_PUBNAMES_SECTION
3514 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3516 #ifndef DEBUG_PUBTYPES_SECTION
3517 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
3519 #ifndef DEBUG_STR_SECTION
3520 #define DEBUG_STR_SECTION ".debug_str"
3522 #ifndef DEBUG_RANGES_SECTION
3523 #define DEBUG_RANGES_SECTION ".debug_ranges"
3526 /* Standard ELF section names for compiled code and data. */
3527 #ifndef TEXT_SECTION_NAME
3528 #define TEXT_SECTION_NAME ".text"
3531 /* Section flags for .debug_str section. */
3532 #define DEBUG_STR_SECTION_FLAGS \
3533 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3534 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3537 /* Labels we insert at beginning sections we can reference instead of
3538 the section names themselves. */
3540 #ifndef TEXT_SECTION_LABEL
3541 #define TEXT_SECTION_LABEL "Ltext"
3543 #ifndef COLD_TEXT_SECTION_LABEL
3544 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3546 #ifndef DEBUG_LINE_SECTION_LABEL
3547 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3549 #ifndef DEBUG_INFO_SECTION_LABEL
3550 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3552 #ifndef DEBUG_ABBREV_SECTION_LABEL
3553 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3555 #ifndef DEBUG_LOC_SECTION_LABEL
3556 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3558 #ifndef DEBUG_RANGES_SECTION_LABEL
3559 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3561 #ifndef DEBUG_MACINFO_SECTION_LABEL
3562 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3564 #ifndef DEBUG_MACRO_SECTION_LABEL
3565 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3569 /* Definitions of defaults for formats and names of various special
3570 (artificial) labels which may be generated within this file (when the -g
3571 options is used and DWARF2_DEBUGGING_INFO is in effect.
3572 If necessary, these may be overridden from within the tm.h file, but
3573 typically, overriding these defaults is unnecessary. */
3575 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3576 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3577 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3578 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3579 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3580 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3581 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3582 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3583 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3584 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3586 #ifndef TEXT_END_LABEL
3587 #define TEXT_END_LABEL "Letext"
3589 #ifndef COLD_END_LABEL
3590 #define COLD_END_LABEL "Letext_cold"
3592 #ifndef BLOCK_BEGIN_LABEL
3593 #define BLOCK_BEGIN_LABEL "LBB"
3595 #ifndef BLOCK_END_LABEL
3596 #define BLOCK_END_LABEL "LBE"
3598 #ifndef LINE_CODE_LABEL
3599 #define LINE_CODE_LABEL "LM"
3603 /* Return the root of the DIE's built for the current compilation unit. */
3605 comp_unit_die (void)
3607 if (!single_comp_unit_die
)
3608 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3609 return single_comp_unit_die
;
3612 /* We allow a language front-end to designate a function that is to be
3613 called to "demangle" any name before it is put into a DIE. */
3615 static const char *(*demangle_name_func
) (const char *);
3618 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3620 demangle_name_func
= func
;
3623 /* Test if rtl node points to a pseudo register. */
3626 is_pseudo_reg (const_rtx rtl
)
3628 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3629 || (GET_CODE (rtl
) == SUBREG
3630 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3633 /* Return a reference to a type, with its const and volatile qualifiers
3637 type_main_variant (tree type
)
3639 type
= TYPE_MAIN_VARIANT (type
);
3641 /* ??? There really should be only one main variant among any group of
3642 variants of a given type (and all of the MAIN_VARIANT values for all
3643 members of the group should point to that one type) but sometimes the C
3644 front-end messes this up for array types, so we work around that bug
3646 if (TREE_CODE (type
) == ARRAY_TYPE
)
3647 while (type
!= TYPE_MAIN_VARIANT (type
))
3648 type
= TYPE_MAIN_VARIANT (type
);
3653 /* Return nonzero if the given type node represents a tagged type. */
3656 is_tagged_type (const_tree type
)
3658 enum tree_code code
= TREE_CODE (type
);
3660 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3661 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3664 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3667 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3669 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3672 /* Return die_offset of a DIE reference to a base type. */
3674 static unsigned long int
3675 get_base_type_offset (dw_die_ref ref
)
3677 if (ref
->die_offset
)
3678 return ref
->die_offset
;
3679 if (comp_unit_die ()->die_abbrev
)
3681 calc_base_type_die_sizes ();
3682 gcc_assert (ref
->die_offset
);
3684 return ref
->die_offset
;
3687 /* Return die_offset of a DIE reference other than base type. */
3689 static unsigned long int
3690 get_ref_die_offset (dw_die_ref ref
)
3692 gcc_assert (ref
->die_offset
);
3693 return ref
->die_offset
;
3696 /* Convert a DIE tag into its string name. */
3699 dwarf_tag_name (unsigned int tag
)
3703 case DW_TAG_padding
:
3704 return "DW_TAG_padding";
3705 case DW_TAG_array_type
:
3706 return "DW_TAG_array_type";
3707 case DW_TAG_class_type
:
3708 return "DW_TAG_class_type";
3709 case DW_TAG_entry_point
:
3710 return "DW_TAG_entry_point";
3711 case DW_TAG_enumeration_type
:
3712 return "DW_TAG_enumeration_type";
3713 case DW_TAG_formal_parameter
:
3714 return "DW_TAG_formal_parameter";
3715 case DW_TAG_imported_declaration
:
3716 return "DW_TAG_imported_declaration";
3718 return "DW_TAG_label";
3719 case DW_TAG_lexical_block
:
3720 return "DW_TAG_lexical_block";
3722 return "DW_TAG_member";
3723 case DW_TAG_pointer_type
:
3724 return "DW_TAG_pointer_type";
3725 case DW_TAG_reference_type
:
3726 return "DW_TAG_reference_type";
3727 case DW_TAG_compile_unit
:
3728 return "DW_TAG_compile_unit";
3729 case DW_TAG_string_type
:
3730 return "DW_TAG_string_type";
3731 case DW_TAG_structure_type
:
3732 return "DW_TAG_structure_type";
3733 case DW_TAG_subroutine_type
:
3734 return "DW_TAG_subroutine_type";
3735 case DW_TAG_typedef
:
3736 return "DW_TAG_typedef";
3737 case DW_TAG_union_type
:
3738 return "DW_TAG_union_type";
3739 case DW_TAG_unspecified_parameters
:
3740 return "DW_TAG_unspecified_parameters";
3741 case DW_TAG_variant
:
3742 return "DW_TAG_variant";
3743 case DW_TAG_common_block
:
3744 return "DW_TAG_common_block";
3745 case DW_TAG_common_inclusion
:
3746 return "DW_TAG_common_inclusion";
3747 case DW_TAG_inheritance
:
3748 return "DW_TAG_inheritance";
3749 case DW_TAG_inlined_subroutine
:
3750 return "DW_TAG_inlined_subroutine";
3752 return "DW_TAG_module";
3753 case DW_TAG_ptr_to_member_type
:
3754 return "DW_TAG_ptr_to_member_type";
3755 case DW_TAG_set_type
:
3756 return "DW_TAG_set_type";
3757 case DW_TAG_subrange_type
:
3758 return "DW_TAG_subrange_type";
3759 case DW_TAG_with_stmt
:
3760 return "DW_TAG_with_stmt";
3761 case DW_TAG_access_declaration
:
3762 return "DW_TAG_access_declaration";
3763 case DW_TAG_base_type
:
3764 return "DW_TAG_base_type";
3765 case DW_TAG_catch_block
:
3766 return "DW_TAG_catch_block";
3767 case DW_TAG_const_type
:
3768 return "DW_TAG_const_type";
3769 case DW_TAG_constant
:
3770 return "DW_TAG_constant";
3771 case DW_TAG_enumerator
:
3772 return "DW_TAG_enumerator";
3773 case DW_TAG_file_type
:
3774 return "DW_TAG_file_type";
3776 return "DW_TAG_friend";
3777 case DW_TAG_namelist
:
3778 return "DW_TAG_namelist";
3779 case DW_TAG_namelist_item
:
3780 return "DW_TAG_namelist_item";
3781 case DW_TAG_packed_type
:
3782 return "DW_TAG_packed_type";
3783 case DW_TAG_subprogram
:
3784 return "DW_TAG_subprogram";
3785 case DW_TAG_template_type_param
:
3786 return "DW_TAG_template_type_param";
3787 case DW_TAG_template_value_param
:
3788 return "DW_TAG_template_value_param";
3789 case DW_TAG_thrown_type
:
3790 return "DW_TAG_thrown_type";
3791 case DW_TAG_try_block
:
3792 return "DW_TAG_try_block";
3793 case DW_TAG_variant_part
:
3794 return "DW_TAG_variant_part";
3795 case DW_TAG_variable
:
3796 return "DW_TAG_variable";
3797 case DW_TAG_volatile_type
:
3798 return "DW_TAG_volatile_type";
3799 case DW_TAG_dwarf_procedure
:
3800 return "DW_TAG_dwarf_procedure";
3801 case DW_TAG_restrict_type
:
3802 return "DW_TAG_restrict_type";
3803 case DW_TAG_interface_type
:
3804 return "DW_TAG_interface_type";
3805 case DW_TAG_namespace
:
3806 return "DW_TAG_namespace";
3807 case DW_TAG_imported_module
:
3808 return "DW_TAG_imported_module";
3809 case DW_TAG_unspecified_type
:
3810 return "DW_TAG_unspecified_type";
3811 case DW_TAG_partial_unit
:
3812 return "DW_TAG_partial_unit";
3813 case DW_TAG_imported_unit
:
3814 return "DW_TAG_imported_unit";
3815 case DW_TAG_condition
:
3816 return "DW_TAG_condition";
3817 case DW_TAG_shared_type
:
3818 return "DW_TAG_shared_type";
3819 case DW_TAG_type_unit
:
3820 return "DW_TAG_type_unit";
3821 case DW_TAG_rvalue_reference_type
:
3822 return "DW_TAG_rvalue_reference_type";
3823 case DW_TAG_template_alias
:
3824 return "DW_TAG_template_alias";
3825 case DW_TAG_GNU_template_parameter_pack
:
3826 return "DW_TAG_GNU_template_parameter_pack";
3827 case DW_TAG_GNU_formal_parameter_pack
:
3828 return "DW_TAG_GNU_formal_parameter_pack";
3829 case DW_TAG_MIPS_loop
:
3830 return "DW_TAG_MIPS_loop";
3831 case DW_TAG_format_label
:
3832 return "DW_TAG_format_label";
3833 case DW_TAG_function_template
:
3834 return "DW_TAG_function_template";
3835 case DW_TAG_class_template
:
3836 return "DW_TAG_class_template";
3837 case DW_TAG_GNU_BINCL
:
3838 return "DW_TAG_GNU_BINCL";
3839 case DW_TAG_GNU_EINCL
:
3840 return "DW_TAG_GNU_EINCL";
3841 case DW_TAG_GNU_template_template_param
:
3842 return "DW_TAG_GNU_template_template_param";
3843 case DW_TAG_GNU_call_site
:
3844 return "DW_TAG_GNU_call_site";
3845 case DW_TAG_GNU_call_site_parameter
:
3846 return "DW_TAG_GNU_call_site_parameter";
3848 return "DW_TAG_<unknown>";
3852 /* Convert a DWARF attribute code into its string name. */
3855 dwarf_attr_name (unsigned int attr
)
3860 return "DW_AT_sibling";
3861 case DW_AT_location
:
3862 return "DW_AT_location";
3864 return "DW_AT_name";
3865 case DW_AT_ordering
:
3866 return "DW_AT_ordering";
3867 case DW_AT_subscr_data
:
3868 return "DW_AT_subscr_data";
3869 case DW_AT_byte_size
:
3870 return "DW_AT_byte_size";
3871 case DW_AT_bit_offset
:
3872 return "DW_AT_bit_offset";
3873 case DW_AT_bit_size
:
3874 return "DW_AT_bit_size";
3875 case DW_AT_element_list
:
3876 return "DW_AT_element_list";
3877 case DW_AT_stmt_list
:
3878 return "DW_AT_stmt_list";
3880 return "DW_AT_low_pc";
3882 return "DW_AT_high_pc";
3883 case DW_AT_language
:
3884 return "DW_AT_language";
3886 return "DW_AT_member";
3888 return "DW_AT_discr";
3889 case DW_AT_discr_value
:
3890 return "DW_AT_discr_value";
3891 case DW_AT_visibility
:
3892 return "DW_AT_visibility";
3894 return "DW_AT_import";
3895 case DW_AT_string_length
:
3896 return "DW_AT_string_length";
3897 case DW_AT_common_reference
:
3898 return "DW_AT_common_reference";
3899 case DW_AT_comp_dir
:
3900 return "DW_AT_comp_dir";
3901 case DW_AT_const_value
:
3902 return "DW_AT_const_value";
3903 case DW_AT_containing_type
:
3904 return "DW_AT_containing_type";
3905 case DW_AT_default_value
:
3906 return "DW_AT_default_value";
3908 return "DW_AT_inline";
3909 case DW_AT_is_optional
:
3910 return "DW_AT_is_optional";
3911 case DW_AT_lower_bound
:
3912 return "DW_AT_lower_bound";
3913 case DW_AT_producer
:
3914 return "DW_AT_producer";
3915 case DW_AT_prototyped
:
3916 return "DW_AT_prototyped";
3917 case DW_AT_return_addr
:
3918 return "DW_AT_return_addr";
3919 case DW_AT_start_scope
:
3920 return "DW_AT_start_scope";
3921 case DW_AT_bit_stride
:
3922 return "DW_AT_bit_stride";
3923 case DW_AT_upper_bound
:
3924 return "DW_AT_upper_bound";
3925 case DW_AT_abstract_origin
:
3926 return "DW_AT_abstract_origin";
3927 case DW_AT_accessibility
:
3928 return "DW_AT_accessibility";
3929 case DW_AT_address_class
:
3930 return "DW_AT_address_class";
3931 case DW_AT_artificial
:
3932 return "DW_AT_artificial";
3933 case DW_AT_base_types
:
3934 return "DW_AT_base_types";
3935 case DW_AT_calling_convention
:
3936 return "DW_AT_calling_convention";
3938 return "DW_AT_count";
3939 case DW_AT_data_member_location
:
3940 return "DW_AT_data_member_location";
3941 case DW_AT_decl_column
:
3942 return "DW_AT_decl_column";
3943 case DW_AT_decl_file
:
3944 return "DW_AT_decl_file";
3945 case DW_AT_decl_line
:
3946 return "DW_AT_decl_line";
3947 case DW_AT_declaration
:
3948 return "DW_AT_declaration";
3949 case DW_AT_discr_list
:
3950 return "DW_AT_discr_list";
3951 case DW_AT_encoding
:
3952 return "DW_AT_encoding";
3953 case DW_AT_external
:
3954 return "DW_AT_external";
3955 case DW_AT_explicit
:
3956 return "DW_AT_explicit";
3957 case DW_AT_frame_base
:
3958 return "DW_AT_frame_base";
3960 return "DW_AT_friend";
3961 case DW_AT_identifier_case
:
3962 return "DW_AT_identifier_case";
3963 case DW_AT_macro_info
:
3964 return "DW_AT_macro_info";
3965 case DW_AT_namelist_items
:
3966 return "DW_AT_namelist_items";
3967 case DW_AT_priority
:
3968 return "DW_AT_priority";
3970 return "DW_AT_segment";
3971 case DW_AT_specification
:
3972 return "DW_AT_specification";
3973 case DW_AT_static_link
:
3974 return "DW_AT_static_link";
3976 return "DW_AT_type";
3977 case DW_AT_use_location
:
3978 return "DW_AT_use_location";
3979 case DW_AT_variable_parameter
:
3980 return "DW_AT_variable_parameter";
3981 case DW_AT_virtuality
:
3982 return "DW_AT_virtuality";
3983 case DW_AT_vtable_elem_location
:
3984 return "DW_AT_vtable_elem_location";
3986 case DW_AT_allocated
:
3987 return "DW_AT_allocated";
3988 case DW_AT_associated
:
3989 return "DW_AT_associated";
3990 case DW_AT_data_location
:
3991 return "DW_AT_data_location";
3992 case DW_AT_byte_stride
:
3993 return "DW_AT_byte_stride";
3994 case DW_AT_entry_pc
:
3995 return "DW_AT_entry_pc";
3996 case DW_AT_use_UTF8
:
3997 return "DW_AT_use_UTF8";
3998 case DW_AT_extension
:
3999 return "DW_AT_extension";
4001 return "DW_AT_ranges";
4002 case DW_AT_trampoline
:
4003 return "DW_AT_trampoline";
4004 case DW_AT_call_column
:
4005 return "DW_AT_call_column";
4006 case DW_AT_call_file
:
4007 return "DW_AT_call_file";
4008 case DW_AT_call_line
:
4009 return "DW_AT_call_line";
4010 case DW_AT_object_pointer
:
4011 return "DW_AT_object_pointer";
4013 case DW_AT_signature
:
4014 return "DW_AT_signature";
4015 case DW_AT_main_subprogram
:
4016 return "DW_AT_main_subprogram";
4017 case DW_AT_data_bit_offset
:
4018 return "DW_AT_data_bit_offset";
4019 case DW_AT_const_expr
:
4020 return "DW_AT_const_expr";
4021 case DW_AT_enum_class
:
4022 return "DW_AT_enum_class";
4023 case DW_AT_linkage_name
:
4024 return "DW_AT_linkage_name";
4026 case DW_AT_MIPS_fde
:
4027 return "DW_AT_MIPS_fde";
4028 case DW_AT_MIPS_loop_begin
:
4029 return "DW_AT_MIPS_loop_begin";
4030 case DW_AT_MIPS_tail_loop_begin
:
4031 return "DW_AT_MIPS_tail_loop_begin";
4032 case DW_AT_MIPS_epilog_begin
:
4033 return "DW_AT_MIPS_epilog_begin";
4034 #if VMS_DEBUGGING_INFO
4035 case DW_AT_HP_prologue
:
4036 return "DW_AT_HP_prologue";
4038 case DW_AT_MIPS_loop_unroll_factor
:
4039 return "DW_AT_MIPS_loop_unroll_factor";
4041 case DW_AT_MIPS_software_pipeline_depth
:
4042 return "DW_AT_MIPS_software_pipeline_depth";
4043 case DW_AT_MIPS_linkage_name
:
4044 return "DW_AT_MIPS_linkage_name";
4045 #if VMS_DEBUGGING_INFO
4046 case DW_AT_HP_epilogue
:
4047 return "DW_AT_HP_epilogue";
4049 case DW_AT_MIPS_stride
:
4050 return "DW_AT_MIPS_stride";
4052 case DW_AT_MIPS_abstract_name
:
4053 return "DW_AT_MIPS_abstract_name";
4054 case DW_AT_MIPS_clone_origin
:
4055 return "DW_AT_MIPS_clone_origin";
4056 case DW_AT_MIPS_has_inlines
:
4057 return "DW_AT_MIPS_has_inlines";
4059 case DW_AT_sf_names
:
4060 return "DW_AT_sf_names";
4061 case DW_AT_src_info
:
4062 return "DW_AT_src_info";
4063 case DW_AT_mac_info
:
4064 return "DW_AT_mac_info";
4065 case DW_AT_src_coords
:
4066 return "DW_AT_src_coords";
4067 case DW_AT_body_begin
:
4068 return "DW_AT_body_begin";
4069 case DW_AT_body_end
:
4070 return "DW_AT_body_end";
4072 case DW_AT_GNU_vector
:
4073 return "DW_AT_GNU_vector";
4074 case DW_AT_GNU_guarded_by
:
4075 return "DW_AT_GNU_guarded_by";
4076 case DW_AT_GNU_pt_guarded_by
:
4077 return "DW_AT_GNU_pt_guarded_by";
4078 case DW_AT_GNU_guarded
:
4079 return "DW_AT_GNU_guarded";
4080 case DW_AT_GNU_pt_guarded
:
4081 return "DW_AT_GNU_pt_guarded";
4082 case DW_AT_GNU_locks_excluded
:
4083 return "DW_AT_GNU_locks_excluded";
4084 case DW_AT_GNU_exclusive_locks_required
:
4085 return "DW_AT_GNU_exclusive_locks_required";
4086 case DW_AT_GNU_shared_locks_required
:
4087 return "DW_AT_GNU_shared_locks_required";
4088 case DW_AT_GNU_odr_signature
:
4089 return "DW_AT_GNU_odr_signature";
4090 case DW_AT_GNU_template_name
:
4091 return "DW_AT_GNU_template_name";
4092 case DW_AT_GNU_call_site_value
:
4093 return "DW_AT_GNU_call_site_value";
4094 case DW_AT_GNU_call_site_data_value
:
4095 return "DW_AT_GNU_call_site_data_value";
4096 case DW_AT_GNU_call_site_target
:
4097 return "DW_AT_GNU_call_site_target";
4098 case DW_AT_GNU_call_site_target_clobbered
:
4099 return "DW_AT_GNU_call_site_target_clobbered";
4100 case DW_AT_GNU_tail_call
:
4101 return "DW_AT_GNU_tail_call";
4102 case DW_AT_GNU_all_tail_call_sites
:
4103 return "DW_AT_GNU_all_tail_call_sites";
4104 case DW_AT_GNU_all_call_sites
:
4105 return "DW_AT_GNU_all_call_sites";
4106 case DW_AT_GNU_all_source_call_sites
:
4107 return "DW_AT_GNU_all_source_call_sites";
4108 case DW_AT_GNU_macros
:
4109 return "DW_AT_GNU_macros";
4111 case DW_AT_GNAT_descriptive_type
:
4112 return "DW_AT_GNAT_descriptive_type";
4114 case DW_AT_VMS_rtnbeg_pd_address
:
4115 return "DW_AT_VMS_rtnbeg_pd_address";
4118 return "DW_AT_<unknown>";
4122 /* Convert a DWARF value form code into its string name. */
4125 dwarf_form_name (unsigned int form
)
4130 return "DW_FORM_addr";
4131 case DW_FORM_block2
:
4132 return "DW_FORM_block2";
4133 case DW_FORM_block4
:
4134 return "DW_FORM_block4";
4136 return "DW_FORM_data2";
4138 return "DW_FORM_data4";
4140 return "DW_FORM_data8";
4141 case DW_FORM_string
:
4142 return "DW_FORM_string";
4144 return "DW_FORM_block";
4145 case DW_FORM_block1
:
4146 return "DW_FORM_block1";
4148 return "DW_FORM_data1";
4150 return "DW_FORM_flag";
4152 return "DW_FORM_sdata";
4154 return "DW_FORM_strp";
4156 return "DW_FORM_udata";
4157 case DW_FORM_ref_addr
:
4158 return "DW_FORM_ref_addr";
4160 return "DW_FORM_ref1";
4162 return "DW_FORM_ref2";
4164 return "DW_FORM_ref4";
4166 return "DW_FORM_ref8";
4167 case DW_FORM_ref_udata
:
4168 return "DW_FORM_ref_udata";
4169 case DW_FORM_indirect
:
4170 return "DW_FORM_indirect";
4171 case DW_FORM_sec_offset
:
4172 return "DW_FORM_sec_offset";
4173 case DW_FORM_exprloc
:
4174 return "DW_FORM_exprloc";
4175 case DW_FORM_flag_present
:
4176 return "DW_FORM_flag_present";
4177 case DW_FORM_ref_sig8
:
4178 return "DW_FORM_ref_sig8";
4180 return "DW_FORM_<unknown>";
4184 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4185 instance of an inlined instance of a decl which is local to an inline
4186 function, so we have to trace all of the way back through the origin chain
4187 to find out what sort of node actually served as the original seed for the
4191 decl_ultimate_origin (const_tree decl
)
4193 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
4196 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4197 nodes in the function to point to themselves; ignore that if
4198 we're trying to output the abstract instance of this function. */
4199 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4202 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4203 most distant ancestor, this should never happen. */
4204 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
4206 return DECL_ABSTRACT_ORIGIN (decl
);
4209 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4210 of a virtual function may refer to a base class, so we check the 'this'
4214 decl_class_context (tree decl
)
4216 tree context
= NULL_TREE
;
4218 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4219 context
= DECL_CONTEXT (decl
);
4221 context
= TYPE_MAIN_VARIANT
4222 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4224 if (context
&& !TYPE_P (context
))
4225 context
= NULL_TREE
;
4230 /* Add an attribute/value pair to a DIE. */
4233 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
4235 /* Maybe this should be an assert? */
4239 if (die
->die_attr
== NULL
)
4240 die
->die_attr
= VEC_alloc (dw_attr_node
, gc
, 1);
4241 VEC_safe_push (dw_attr_node
, gc
, die
->die_attr
, attr
);
4244 static inline enum dw_val_class
4245 AT_class (dw_attr_ref a
)
4247 return a
->dw_attr_val
.val_class
;
4250 /* Add a flag value attribute to a DIE. */
4253 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
4257 attr
.dw_attr
= attr_kind
;
4258 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
4259 attr
.dw_attr_val
.v
.val_flag
= flag
;
4260 add_dwarf_attr (die
, &attr
);
4263 static inline unsigned
4264 AT_flag (dw_attr_ref a
)
4266 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
4267 return a
->dw_attr_val
.v
.val_flag
;
4270 /* Add a signed integer attribute value to a DIE. */
4273 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
4277 attr
.dw_attr
= attr_kind
;
4278 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
4279 attr
.dw_attr_val
.v
.val_int
= int_val
;
4280 add_dwarf_attr (die
, &attr
);
4283 static inline HOST_WIDE_INT
4284 AT_int (dw_attr_ref a
)
4286 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
4287 return a
->dw_attr_val
.v
.val_int
;
4290 /* Add an unsigned integer attribute value to a DIE. */
4293 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4294 unsigned HOST_WIDE_INT unsigned_val
)
4298 attr
.dw_attr
= attr_kind
;
4299 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4300 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4301 add_dwarf_attr (die
, &attr
);
4304 static inline unsigned HOST_WIDE_INT
4305 AT_unsigned (dw_attr_ref a
)
4307 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
4308 return a
->dw_attr_val
.v
.val_unsigned
;
4311 /* Add an unsigned double integer attribute value to a DIE. */
4314 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4315 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
4319 attr
.dw_attr
= attr_kind
;
4320 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
4321 attr
.dw_attr_val
.v
.val_double
.high
= high
;
4322 attr
.dw_attr_val
.v
.val_double
.low
= low
;
4323 add_dwarf_attr (die
, &attr
);
4326 /* Add a floating point attribute value to a DIE and return it. */
4329 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4330 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
4334 attr
.dw_attr
= attr_kind
;
4335 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
4336 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
4337 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4338 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
4339 add_dwarf_attr (die
, &attr
);
4342 /* Add an 8-byte data attribute value to a DIE. */
4345 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4346 unsigned char data8
[8])
4350 attr
.dw_attr
= attr_kind
;
4351 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
4352 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
4353 add_dwarf_attr (die
, &attr
);
4356 /* Hash and equality functions for debug_str_hash. */
4359 debug_str_do_hash (const void *x
)
4361 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
4365 debug_str_eq (const void *x1
, const void *x2
)
4367 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
4368 (const char *)x2
) == 0;
4371 /* Add STR to the indirect string hash table. */
4373 static struct indirect_string_node
*
4374 find_AT_string (const char *str
)
4376 struct indirect_string_node
*node
;
4379 if (! debug_str_hash
)
4380 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
4381 debug_str_eq
, NULL
);
4383 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
4384 htab_hash_string (str
), INSERT
);
4387 node
= ggc_alloc_cleared_indirect_string_node ();
4388 node
->str
= ggc_strdup (str
);
4392 node
= (struct indirect_string_node
*) *slot
;
4398 /* Add a string attribute value to a DIE. */
4401 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4404 struct indirect_string_node
*node
;
4406 node
= find_AT_string (str
);
4408 attr
.dw_attr
= attr_kind
;
4409 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4410 attr
.dw_attr_val
.v
.val_str
= node
;
4411 add_dwarf_attr (die
, &attr
);
4414 static inline const char *
4415 AT_string (dw_attr_ref a
)
4417 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4418 return a
->dw_attr_val
.v
.val_str
->str
;
4421 /* Find out whether a string should be output inline in DIE
4422 or out-of-line in .debug_str section. */
4424 static enum dwarf_form
4425 AT_string_form (dw_attr_ref a
)
4427 struct indirect_string_node
*node
;
4431 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4433 node
= a
->dw_attr_val
.v
.val_str
;
4437 len
= strlen (node
->str
) + 1;
4439 /* If the string is shorter or equal to the size of the reference, it is
4440 always better to put it inline. */
4441 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4442 return node
->form
= DW_FORM_string
;
4444 /* If we cannot expect the linker to merge strings in .debug_str
4445 section, only put it into .debug_str if it is worth even in this
4447 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4448 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4449 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4450 return node
->form
= DW_FORM_string
;
4452 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4453 ++dw2_string_counter
;
4454 node
->label
= xstrdup (label
);
4456 return node
->form
= DW_FORM_strp
;
4459 /* Add a DIE reference attribute value to a DIE. */
4462 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4466 #ifdef ENABLE_CHECKING
4467 gcc_assert (targ_die
!= NULL
);
4469 /* With LTO we can end up trying to reference something we didn't create
4470 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4471 if (targ_die
== NULL
)
4475 attr
.dw_attr
= attr_kind
;
4476 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4477 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4478 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4479 add_dwarf_attr (die
, &attr
);
4482 /* Add an AT_specification attribute to a DIE, and also make the back
4483 pointer from the specification to the definition. */
4486 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4488 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4489 gcc_assert (!targ_die
->die_definition
);
4490 targ_die
->die_definition
= die
;
4493 static inline dw_die_ref
4494 AT_ref (dw_attr_ref a
)
4496 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4497 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4501 AT_ref_external (dw_attr_ref a
)
4503 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4504 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4510 set_AT_ref_external (dw_attr_ref a
, int i
)
4512 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4513 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4516 /* Add an FDE reference attribute value to a DIE. */
4519 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4523 attr
.dw_attr
= attr_kind
;
4524 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4525 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4526 add_dwarf_attr (die
, &attr
);
4529 /* Add a location description attribute value to a DIE. */
4532 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4536 attr
.dw_attr
= attr_kind
;
4537 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4538 attr
.dw_attr_val
.v
.val_loc
= loc
;
4539 add_dwarf_attr (die
, &attr
);
4542 static inline dw_loc_descr_ref
4543 AT_loc (dw_attr_ref a
)
4545 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4546 return a
->dw_attr_val
.v
.val_loc
;
4550 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4554 attr
.dw_attr
= attr_kind
;
4555 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4556 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4557 add_dwarf_attr (die
, &attr
);
4558 have_location_lists
= true;
4561 static inline dw_loc_list_ref
4562 AT_loc_list (dw_attr_ref a
)
4564 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4565 return a
->dw_attr_val
.v
.val_loc_list
;
4568 static inline dw_loc_list_ref
*
4569 AT_loc_list_ptr (dw_attr_ref a
)
4571 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4572 return &a
->dw_attr_val
.v
.val_loc_list
;
4575 /* Add an address constant attribute value to a DIE. */
4578 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
4582 attr
.dw_attr
= attr_kind
;
4583 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4584 attr
.dw_attr_val
.v
.val_addr
= addr
;
4585 add_dwarf_attr (die
, &attr
);
4588 /* Get the RTX from to an address DIE attribute. */
4591 AT_addr (dw_attr_ref a
)
4593 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4594 return a
->dw_attr_val
.v
.val_addr
;
4597 /* Add a file attribute value to a DIE. */
4600 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4601 struct dwarf_file_data
*fd
)
4605 attr
.dw_attr
= attr_kind
;
4606 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4607 attr
.dw_attr_val
.v
.val_file
= fd
;
4608 add_dwarf_attr (die
, &attr
);
4611 /* Get the dwarf_file_data from a file DIE attribute. */
4613 static inline struct dwarf_file_data
*
4614 AT_file (dw_attr_ref a
)
4616 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4617 return a
->dw_attr_val
.v
.val_file
;
4620 /* Add a vms delta attribute value to a DIE. */
4623 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4624 const char *lbl1
, const char *lbl2
)
4628 attr
.dw_attr
= attr_kind
;
4629 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4630 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4631 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4632 add_dwarf_attr (die
, &attr
);
4635 /* Add a label identifier attribute value to a DIE. */
4638 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
4642 attr
.dw_attr
= attr_kind
;
4643 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4644 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4645 add_dwarf_attr (die
, &attr
);
4648 /* Add a section offset attribute value to a DIE, an offset into the
4649 debug_line section. */
4652 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4657 attr
.dw_attr
= attr_kind
;
4658 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4659 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4660 add_dwarf_attr (die
, &attr
);
4663 /* Add a section offset attribute value to a DIE, an offset into the
4664 debug_macinfo section. */
4667 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4672 attr
.dw_attr
= attr_kind
;
4673 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4674 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4675 add_dwarf_attr (die
, &attr
);
4678 /* Add an offset attribute value to a DIE. */
4681 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4682 unsigned HOST_WIDE_INT offset
)
4686 attr
.dw_attr
= attr_kind
;
4687 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4688 attr
.dw_attr_val
.v
.val_offset
= offset
;
4689 add_dwarf_attr (die
, &attr
);
4692 /* Add an range_list attribute value to a DIE. */
4695 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4696 long unsigned int offset
)
4700 attr
.dw_attr
= attr_kind
;
4701 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4702 attr
.dw_attr_val
.v
.val_offset
= offset
;
4703 add_dwarf_attr (die
, &attr
);
4706 /* Return the start label of a delta attribute. */
4708 static inline const char *
4709 AT_vms_delta1 (dw_attr_ref a
)
4711 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4712 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4715 /* Return the end label of a delta attribute. */
4717 static inline const char *
4718 AT_vms_delta2 (dw_attr_ref a
)
4720 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4721 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4724 static inline const char *
4725 AT_lbl (dw_attr_ref a
)
4727 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4728 || AT_class (a
) == dw_val_class_lineptr
4729 || AT_class (a
) == dw_val_class_macptr
));
4730 return a
->dw_attr_val
.v
.val_lbl_id
;
4733 /* Get the attribute of type attr_kind. */
4736 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4740 dw_die_ref spec
= NULL
;
4745 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
4746 if (a
->dw_attr
== attr_kind
)
4748 else if (a
->dw_attr
== DW_AT_specification
4749 || a
->dw_attr
== DW_AT_abstract_origin
)
4753 return get_AT (spec
, attr_kind
);
4758 /* Return the "low pc" attribute value, typically associated with a subprogram
4759 DIE. Return null if the "low pc" attribute is either not present, or if it
4760 cannot be represented as an assembler label identifier. */
4762 static inline const char *
4763 get_AT_low_pc (dw_die_ref die
)
4765 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4767 return a
? AT_lbl (a
) : NULL
;
4770 /* Return the "high pc" attribute value, typically associated with a subprogram
4771 DIE. Return null if the "high pc" attribute is either not present, or if it
4772 cannot be represented as an assembler label identifier. */
4774 static inline const char *
4775 get_AT_hi_pc (dw_die_ref die
)
4777 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4779 return a
? AT_lbl (a
) : NULL
;
4782 /* Return the value of the string attribute designated by ATTR_KIND, or
4783 NULL if it is not present. */
4785 static inline const char *
4786 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4788 dw_attr_ref a
= get_AT (die
, attr_kind
);
4790 return a
? AT_string (a
) : NULL
;
4793 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4794 if it is not present. */
4797 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4799 dw_attr_ref a
= get_AT (die
, attr_kind
);
4801 return a
? AT_flag (a
) : 0;
4804 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4805 if it is not present. */
4807 static inline unsigned
4808 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4810 dw_attr_ref a
= get_AT (die
, attr_kind
);
4812 return a
? AT_unsigned (a
) : 0;
4815 static inline dw_die_ref
4816 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4818 dw_attr_ref a
= get_AT (die
, attr_kind
);
4820 return a
? AT_ref (a
) : NULL
;
4823 static inline struct dwarf_file_data
*
4824 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4826 dw_attr_ref a
= get_AT (die
, attr_kind
);
4828 return a
? AT_file (a
) : NULL
;
4831 /* Return TRUE if the language is C++. */
4836 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4838 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4841 /* Return TRUE if the language is Fortran. */
4846 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4848 return (lang
== DW_LANG_Fortran77
4849 || lang
== DW_LANG_Fortran90
4850 || lang
== DW_LANG_Fortran95
);
4853 /* Return TRUE if the language is Ada. */
4858 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4860 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4863 /* Remove the specified attribute if present. */
4866 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4874 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
4875 if (a
->dw_attr
== attr_kind
)
4877 if (AT_class (a
) == dw_val_class_str
)
4878 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4879 a
->dw_attr_val
.v
.val_str
->refcount
--;
4881 /* VEC_ordered_remove should help reduce the number of abbrevs
4883 VEC_ordered_remove (dw_attr_node
, die
->die_attr
, ix
);
4888 /* Remove CHILD from its parent. PREV must have the property that
4889 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4892 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4894 gcc_assert (child
->die_parent
== prev
->die_parent
);
4895 gcc_assert (prev
->die_sib
== child
);
4898 gcc_assert (child
->die_parent
->die_child
== child
);
4902 prev
->die_sib
= child
->die_sib
;
4903 if (child
->die_parent
->die_child
== child
)
4904 child
->die_parent
->die_child
= prev
;
4907 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4908 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4911 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4913 dw_die_ref parent
= old_child
->die_parent
;
4915 gcc_assert (parent
== prev
->die_parent
);
4916 gcc_assert (prev
->die_sib
== old_child
);
4918 new_child
->die_parent
= parent
;
4919 if (prev
== old_child
)
4921 gcc_assert (parent
->die_child
== old_child
);
4922 new_child
->die_sib
= new_child
;
4926 prev
->die_sib
= new_child
;
4927 new_child
->die_sib
= old_child
->die_sib
;
4929 if (old_child
->die_parent
->die_child
== old_child
)
4930 old_child
->die_parent
->die_child
= new_child
;
4933 /* Move all children from OLD_PARENT to NEW_PARENT. */
4936 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4939 new_parent
->die_child
= old_parent
->die_child
;
4940 old_parent
->die_child
= NULL
;
4941 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4944 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4948 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4954 dw_die_ref prev
= c
;
4956 while (c
->die_tag
== tag
)
4958 remove_child_with_prev (c
, prev
);
4959 /* Might have removed every child. */
4960 if (c
== c
->die_sib
)
4964 } while (c
!= die
->die_child
);
4967 /* Add a CHILD_DIE as the last child of DIE. */
4970 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4972 /* FIXME this should probably be an assert. */
4973 if (! die
|| ! child_die
)
4975 gcc_assert (die
!= child_die
);
4977 child_die
->die_parent
= die
;
4980 child_die
->die_sib
= die
->die_child
->die_sib
;
4981 die
->die_child
->die_sib
= child_die
;
4984 child_die
->die_sib
= child_die
;
4985 die
->die_child
= child_die
;
4988 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4989 is the specification, to the end of PARENT's list of children.
4990 This is done by removing and re-adding it. */
4993 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4997 /* We want the declaration DIE from inside the class, not the
4998 specification DIE at toplevel. */
4999 if (child
->die_parent
!= parent
)
5001 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5007 gcc_assert (child
->die_parent
== parent
5008 || (child
->die_parent
5009 == get_AT_ref (parent
, DW_AT_specification
)));
5011 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
5012 if (p
->die_sib
== child
)
5014 remove_child_with_prev (child
, p
);
5018 add_child_die (parent
, child
);
5021 /* Return a pointer to a newly created DIE node. */
5023 static inline dw_die_ref
5024 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5026 dw_die_ref die
= ggc_alloc_cleared_die_node ();
5028 die
->die_tag
= tag_value
;
5030 if (parent_die
!= NULL
)
5031 add_child_die (parent_die
, die
);
5034 limbo_die_node
*limbo_node
;
5036 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
5037 limbo_node
->die
= die
;
5038 limbo_node
->created_for
= t
;
5039 limbo_node
->next
= limbo_die_list
;
5040 limbo_die_list
= limbo_node
;
5046 /* Return the DIE associated with the given type specifier. */
5048 static inline dw_die_ref
5049 lookup_type_die (tree type
)
5051 return TYPE_SYMTAB_DIE (type
);
5054 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5055 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5056 anonymous type instead the one of the naming typedef. */
5058 static inline dw_die_ref
5059 strip_naming_typedef (tree type
, dw_die_ref type_die
)
5062 && TREE_CODE (type
) == RECORD_TYPE
5064 && type_die
->die_tag
== DW_TAG_typedef
5065 && is_naming_typedef_decl (TYPE_NAME (type
)))
5066 type_die
= get_AT_ref (type_die
, DW_AT_type
);
5070 /* Like lookup_type_die, but if type is an anonymous type named by a
5071 typedef[1], return the DIE of the anonymous type instead the one of
5072 the naming typedef. This is because in gen_typedef_die, we did
5073 equate the anonymous struct named by the typedef with the DIE of
5074 the naming typedef. So by default, lookup_type_die on an anonymous
5075 struct yields the DIE of the naming typedef.
5077 [1]: Read the comment of is_naming_typedef_decl to learn about what
5078 a naming typedef is. */
5080 static inline dw_die_ref
5081 lookup_type_die_strip_naming_typedef (tree type
)
5083 dw_die_ref die
= lookup_type_die (type
);
5084 return strip_naming_typedef (type
, die
);
5087 /* Equate a DIE to a given type specifier. */
5090 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5092 TYPE_SYMTAB_DIE (type
) = type_die
;
5095 /* Returns a hash value for X (which really is a die_struct). */
5098 decl_die_table_hash (const void *x
)
5100 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
5103 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5106 decl_die_table_eq (const void *x
, const void *y
)
5108 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
5111 /* Return the DIE associated with a given declaration. */
5113 static inline dw_die_ref
5114 lookup_decl_die (tree decl
)
5116 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
5119 /* Returns a hash value for X (which really is a var_loc_list). */
5122 decl_loc_table_hash (const void *x
)
5124 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
5127 /* Return nonzero if decl_id of var_loc_list X is the same as
5131 decl_loc_table_eq (const void *x
, const void *y
)
5133 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
5136 /* Return the var_loc list associated with a given declaration. */
5138 static inline var_loc_list
*
5139 lookup_decl_loc (const_tree decl
)
5141 if (!decl_loc_table
)
5143 return (var_loc_list
*)
5144 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
5147 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5150 cached_dw_loc_list_table_hash (const void *x
)
5152 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
5155 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5159 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
5161 return (((const cached_dw_loc_list
*) x
)->decl_id
5162 == DECL_UID ((const_tree
) y
));
5165 /* Equate a DIE to a particular declaration. */
5168 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5170 unsigned int decl_id
= DECL_UID (decl
);
5173 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
5175 decl_die
->decl_id
= decl_id
;
5178 /* Return how many bits covers PIECE EXPR_LIST. */
5181 decl_piece_bitsize (rtx piece
)
5183 int ret
= (int) GET_MODE (piece
);
5186 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
5187 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5188 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5191 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5194 decl_piece_varloc_ptr (rtx piece
)
5196 if ((int) GET_MODE (piece
))
5197 return &XEXP (piece
, 0);
5199 return &XEXP (XEXP (piece
, 0), 1);
5202 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5203 Next is the chain of following piece nodes. */
5206 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5208 if (bitsize
<= (int) MAX_MACHINE_MODE
)
5209 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5211 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5216 /* Return rtx that should be stored into loc field for
5217 LOC_NOTE and BITPOS/BITSIZE. */
5220 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5221 HOST_WIDE_INT bitsize
)
5225 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5227 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5232 /* This function either modifies location piece list *DEST in
5233 place (if SRC and INNER is NULL), or copies location piece list
5234 *SRC to *DEST while modifying it. Location BITPOS is modified
5235 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5236 not copied and if needed some padding around it is added.
5237 When modifying in place, DEST should point to EXPR_LIST where
5238 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5239 to the start of the whole list and INNER points to the EXPR_LIST
5240 where earlier pieces cover PIECE_BITPOS bits. */
5243 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5244 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5245 HOST_WIDE_INT bitsize
, rtx loc_note
)
5248 bool copy
= inner
!= NULL
;
5252 /* First copy all nodes preceeding the current bitpos. */
5253 while (src
!= inner
)
5255 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5256 decl_piece_bitsize (*src
), NULL_RTX
);
5257 dest
= &XEXP (*dest
, 1);
5258 src
= &XEXP (*src
, 1);
5261 /* Add padding if needed. */
5262 if (bitpos
!= piece_bitpos
)
5264 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5265 copy
? NULL_RTX
: *dest
);
5266 dest
= &XEXP (*dest
, 1);
5268 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5271 /* A piece with correct bitpos and bitsize already exist,
5272 just update the location for it and return. */
5273 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5276 /* Add the piece that changed. */
5277 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5278 dest
= &XEXP (*dest
, 1);
5279 /* Skip over pieces that overlap it. */
5280 diff
= bitpos
- piece_bitpos
+ bitsize
;
5283 while (diff
> 0 && *src
)
5286 diff
-= decl_piece_bitsize (piece
);
5288 src
= &XEXP (piece
, 1);
5291 *src
= XEXP (piece
, 1);
5292 free_EXPR_LIST_node (piece
);
5295 /* Add padding if needed. */
5296 if (diff
< 0 && *src
)
5300 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5301 dest
= &XEXP (*dest
, 1);
5305 /* Finally copy all nodes following it. */
5308 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5309 decl_piece_bitsize (*src
), NULL_RTX
);
5310 dest
= &XEXP (*dest
, 1);
5311 src
= &XEXP (*src
, 1);
5315 /* Add a variable location node to the linked list for DECL. */
5317 static struct var_loc_node
*
5318 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5320 unsigned int decl_id
;
5323 struct var_loc_node
*loc
= NULL
;
5324 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5326 if (DECL_DEBUG_EXPR_IS_FROM (decl
))
5328 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5329 if (realdecl
&& handled_component_p (realdecl
))
5331 HOST_WIDE_INT maxsize
;
5334 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5335 if (!DECL_P (innerdecl
)
5336 || DECL_IGNORED_P (innerdecl
)
5337 || TREE_STATIC (innerdecl
)
5339 || bitpos
+ bitsize
> 256
5340 || bitsize
!= maxsize
)
5346 decl_id
= DECL_UID (decl
);
5347 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5350 temp
= ggc_alloc_cleared_var_loc_list ();
5351 temp
->decl_id
= decl_id
;
5355 temp
= (var_loc_list
*) *slot
;
5357 /* For PARM_DECLs try to keep around the original incoming value,
5358 even if that means we'll emit a zero-range .debug_loc entry. */
5360 && temp
->first
== temp
->last
5361 && TREE_CODE (decl
) == PARM_DECL
5362 && GET_CODE (temp
->first
->loc
) == NOTE
5363 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5364 && DECL_INCOMING_RTL (decl
)
5365 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5366 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5367 == GET_CODE (DECL_INCOMING_RTL (decl
))
5368 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5370 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5371 NOTE_VAR_LOCATION_LOC (loc_note
))
5372 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5373 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5375 loc
= ggc_alloc_cleared_var_loc_node ();
5376 temp
->first
->next
= loc
;
5378 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5380 else if (temp
->last
)
5382 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5383 rtx
*piece_loc
= NULL
, last_loc_note
;
5384 int piece_bitpos
= 0;
5388 gcc_assert (last
->next
== NULL
);
5390 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5392 piece_loc
= &last
->loc
;
5395 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5396 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5398 piece_bitpos
+= cur_bitsize
;
5399 piece_loc
= &XEXP (*piece_loc
, 1);
5403 /* TEMP->LAST here is either pointer to the last but one or
5404 last element in the chained list, LAST is pointer to the
5406 if (label
&& strcmp (last
->label
, label
) == 0)
5408 /* For SRA optimized variables if there weren't any real
5409 insns since last note, just modify the last node. */
5410 if (piece_loc
!= NULL
)
5412 adjust_piece_list (piece_loc
, NULL
, NULL
,
5413 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5416 /* If the last note doesn't cover any instructions, remove it. */
5417 if (temp
->last
!= last
)
5419 temp
->last
->next
= NULL
;
5422 gcc_assert (strcmp (last
->label
, label
) != 0);
5426 gcc_assert (temp
->first
== temp
->last
5427 || (temp
->first
->next
== temp
->last
5428 && TREE_CODE (decl
) == PARM_DECL
));
5429 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5430 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5434 if (bitsize
== -1 && NOTE_P (last
->loc
))
5435 last_loc_note
= last
->loc
;
5436 else if (piece_loc
!= NULL
5437 && *piece_loc
!= NULL_RTX
5438 && piece_bitpos
== bitpos
5439 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5440 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5442 last_loc_note
= NULL_RTX
;
5443 /* If the current location is the same as the end of the list,
5444 and either both or neither of the locations is uninitialized,
5445 we have nothing to do. */
5446 if (last_loc_note
== NULL_RTX
5447 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5448 NOTE_VAR_LOCATION_LOC (loc_note
)))
5449 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5450 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5451 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5452 == VAR_INIT_STATUS_UNINITIALIZED
)
5453 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5454 == VAR_INIT_STATUS_UNINITIALIZED
))))
5456 /* Add LOC to the end of list and update LAST. If the last
5457 element of the list has been removed above, reuse its
5458 memory for the new node, otherwise allocate a new one. */
5462 memset (loc
, '\0', sizeof (*loc
));
5465 loc
= ggc_alloc_cleared_var_loc_node ();
5466 if (bitsize
== -1 || piece_loc
== NULL
)
5467 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5469 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5470 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5472 /* Ensure TEMP->LAST will point either to the new last but one
5473 element of the chain, or to the last element in it. */
5474 if (last
!= temp
->last
)
5482 loc
= ggc_alloc_cleared_var_loc_node ();
5485 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5490 /* Keep track of the number of spaces used to indent the
5491 output of the debugging routines that print the structure of
5492 the DIE internal representation. */
5493 static int print_indent
;
5495 /* Indent the line the number of spaces given by print_indent. */
5498 print_spaces (FILE *outfile
)
5500 fprintf (outfile
, "%*s", print_indent
, "");
5503 /* Print a type signature in hex. */
5506 print_signature (FILE *outfile
, char *sig
)
5510 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5511 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5514 /* Print the information associated with a given DIE, and its children.
5515 This routine is a debugging aid only. */
5518 print_die (dw_die_ref die
, FILE *outfile
)
5524 print_spaces (outfile
);
5525 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5526 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5528 print_spaces (outfile
);
5529 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5530 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5531 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5533 if (use_debug_types
&& die
->die_id
.die_type_node
)
5535 print_spaces (outfile
);
5536 fprintf (outfile
, " signature: ");
5537 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5538 fprintf (outfile
, "\n");
5541 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
5543 print_spaces (outfile
);
5544 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5546 switch (AT_class (a
))
5548 case dw_val_class_addr
:
5549 fprintf (outfile
, "address");
5551 case dw_val_class_offset
:
5552 fprintf (outfile
, "offset");
5554 case dw_val_class_loc
:
5555 fprintf (outfile
, "location descriptor");
5557 case dw_val_class_loc_list
:
5558 fprintf (outfile
, "location list -> label:%s",
5559 AT_loc_list (a
)->ll_symbol
);
5561 case dw_val_class_range_list
:
5562 fprintf (outfile
, "range list");
5564 case dw_val_class_const
:
5565 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5567 case dw_val_class_unsigned_const
:
5568 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5570 case dw_val_class_const_double
:
5571 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
5572 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5573 a
->dw_attr_val
.v
.val_double
.high
,
5574 a
->dw_attr_val
.v
.val_double
.low
);
5576 case dw_val_class_vec
:
5577 fprintf (outfile
, "floating-point or vector constant");
5579 case dw_val_class_flag
:
5580 fprintf (outfile
, "%u", AT_flag (a
));
5582 case dw_val_class_die_ref
:
5583 if (AT_ref (a
) != NULL
)
5585 if (use_debug_types
&& AT_ref (a
)->die_id
.die_type_node
)
5587 fprintf (outfile
, "die -> signature: ");
5588 print_signature (outfile
,
5589 AT_ref (a
)->die_id
.die_type_node
->signature
);
5591 else if (! use_debug_types
&& AT_ref (a
)->die_id
.die_symbol
)
5592 fprintf (outfile
, "die -> label: %s",
5593 AT_ref (a
)->die_id
.die_symbol
);
5595 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
5596 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
5599 fprintf (outfile
, "die -> <null>");
5601 case dw_val_class_vms_delta
:
5602 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5603 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
5605 case dw_val_class_lbl_id
:
5606 case dw_val_class_lineptr
:
5607 case dw_val_class_macptr
:
5608 fprintf (outfile
, "label: %s", AT_lbl (a
));
5610 case dw_val_class_str
:
5611 if (AT_string (a
) != NULL
)
5612 fprintf (outfile
, "\"%s\"", AT_string (a
));
5614 fprintf (outfile
, "<null>");
5616 case dw_val_class_file
:
5617 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
5618 AT_file (a
)->emitted_number
);
5620 case dw_val_class_data8
:
5624 for (i
= 0; i
< 8; i
++)
5625 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
5632 fprintf (outfile
, "\n");
5635 if (die
->die_child
!= NULL
)
5638 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5641 if (print_indent
== 0)
5642 fprintf (outfile
, "\n");
5645 /* Print the information collected for a given DIE. */
5648 debug_dwarf_die (dw_die_ref die
)
5650 print_die (die
, stderr
);
5653 /* Print all DWARF information collected for the compilation unit.
5654 This routine is a debugging aid only. */
5660 print_die (comp_unit_die (), stderr
);
5663 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5664 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5665 DIE that marks the start of the DIEs for this include file. */
5668 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5670 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5671 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5673 new_unit
->die_sib
= old_unit
;
5677 /* Close an include-file CU and reopen the enclosing one. */
5680 pop_compile_unit (dw_die_ref old_unit
)
5682 dw_die_ref new_unit
= old_unit
->die_sib
;
5684 old_unit
->die_sib
= NULL
;
5688 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5689 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5691 /* Calculate the checksum of a location expression. */
5694 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5698 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5700 CHECKSUM (loc
->dw_loc_oprnd1
);
5701 CHECKSUM (loc
->dw_loc_oprnd2
);
5704 /* Calculate the checksum of an attribute. */
5707 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5709 dw_loc_descr_ref loc
;
5712 CHECKSUM (at
->dw_attr
);
5714 /* We don't care that this was compiled with a different compiler
5715 snapshot; if the output is the same, that's what matters. */
5716 if (at
->dw_attr
== DW_AT_producer
)
5719 switch (AT_class (at
))
5721 case dw_val_class_const
:
5722 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5724 case dw_val_class_unsigned_const
:
5725 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5727 case dw_val_class_const_double
:
5728 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5730 case dw_val_class_vec
:
5731 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5733 case dw_val_class_flag
:
5734 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5736 case dw_val_class_str
:
5737 CHECKSUM_STRING (AT_string (at
));
5740 case dw_val_class_addr
:
5742 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5743 CHECKSUM_STRING (XSTR (r
, 0));
5746 case dw_val_class_offset
:
5747 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5750 case dw_val_class_loc
:
5751 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5752 loc_checksum (loc
, ctx
);
5755 case dw_val_class_die_ref
:
5756 die_checksum (AT_ref (at
), ctx
, mark
);
5759 case dw_val_class_fde_ref
:
5760 case dw_val_class_vms_delta
:
5761 case dw_val_class_lbl_id
:
5762 case dw_val_class_lineptr
:
5763 case dw_val_class_macptr
:
5766 case dw_val_class_file
:
5767 CHECKSUM_STRING (AT_file (at
)->filename
);
5770 case dw_val_class_data8
:
5771 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5779 /* Calculate the checksum of a DIE. */
5782 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5788 /* To avoid infinite recursion. */
5791 CHECKSUM (die
->die_mark
);
5794 die
->die_mark
= ++(*mark
);
5796 CHECKSUM (die
->die_tag
);
5798 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
5799 attr_checksum (a
, ctx
, mark
);
5801 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5805 #undef CHECKSUM_STRING
5807 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5808 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5809 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5810 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5811 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5812 #define CHECKSUM_ATTR(FOO) \
5813 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5815 /* Calculate the checksum of a number in signed LEB128 format. */
5818 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5825 byte
= (value
& 0x7f);
5827 more
= !((value
== 0 && (byte
& 0x40) == 0)
5828 || (value
== -1 && (byte
& 0x40) != 0));
5837 /* Calculate the checksum of a number in unsigned LEB128 format. */
5840 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5844 unsigned char byte
= (value
& 0x7f);
5847 /* More bytes to follow. */
5855 /* Checksum the context of the DIE. This adds the names of any
5856 surrounding namespaces or structures to the checksum. */
5859 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5863 int tag
= die
->die_tag
;
5865 if (tag
!= DW_TAG_namespace
5866 && tag
!= DW_TAG_structure_type
5867 && tag
!= DW_TAG_class_type
)
5870 name
= get_AT_string (die
, DW_AT_name
);
5872 spec
= get_AT_ref (die
, DW_AT_specification
);
5876 if (die
->die_parent
!= NULL
)
5877 checksum_die_context (die
->die_parent
, ctx
);
5879 CHECKSUM_ULEB128 ('C');
5880 CHECKSUM_ULEB128 (tag
);
5882 CHECKSUM_STRING (name
);
5885 /* Calculate the checksum of a location expression. */
5888 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5890 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5891 were emitted as a DW_FORM_sdata instead of a location expression. */
5892 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5894 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5895 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5899 /* Otherwise, just checksum the raw location expression. */
5902 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5903 CHECKSUM (loc
->dw_loc_oprnd1
);
5904 CHECKSUM (loc
->dw_loc_oprnd2
);
5905 loc
= loc
->dw_loc_next
;
5909 /* Calculate the checksum of an attribute. */
5912 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5913 struct md5_ctx
*ctx
, int *mark
)
5915 dw_loc_descr_ref loc
;
5918 if (AT_class (at
) == dw_val_class_die_ref
)
5920 dw_die_ref target_die
= AT_ref (at
);
5922 /* For pointer and reference types, we checksum only the (qualified)
5923 name of the target type (if there is a name). For friend entries,
5924 we checksum only the (qualified) name of the target type or function.
5925 This allows the checksum to remain the same whether the target type
5926 is complete or not. */
5927 if ((at
->dw_attr
== DW_AT_type
5928 && (tag
== DW_TAG_pointer_type
5929 || tag
== DW_TAG_reference_type
5930 || tag
== DW_TAG_rvalue_reference_type
5931 || tag
== DW_TAG_ptr_to_member_type
))
5932 || (at
->dw_attr
== DW_AT_friend
5933 && tag
== DW_TAG_friend
))
5935 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5937 if (name_attr
!= NULL
)
5939 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5943 CHECKSUM_ULEB128 ('N');
5944 CHECKSUM_ULEB128 (at
->dw_attr
);
5945 if (decl
->die_parent
!= NULL
)
5946 checksum_die_context (decl
->die_parent
, ctx
);
5947 CHECKSUM_ULEB128 ('E');
5948 CHECKSUM_STRING (AT_string (name_attr
));
5953 /* For all other references to another DIE, we check to see if the
5954 target DIE has already been visited. If it has, we emit a
5955 backward reference; if not, we descend recursively. */
5956 if (target_die
->die_mark
> 0)
5958 CHECKSUM_ULEB128 ('R');
5959 CHECKSUM_ULEB128 (at
->dw_attr
);
5960 CHECKSUM_ULEB128 (target_die
->die_mark
);
5964 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5968 target_die
->die_mark
= ++(*mark
);
5969 CHECKSUM_ULEB128 ('T');
5970 CHECKSUM_ULEB128 (at
->dw_attr
);
5971 if (decl
->die_parent
!= NULL
)
5972 checksum_die_context (decl
->die_parent
, ctx
);
5973 die_checksum_ordered (target_die
, ctx
, mark
);
5978 CHECKSUM_ULEB128 ('A');
5979 CHECKSUM_ULEB128 (at
->dw_attr
);
5981 switch (AT_class (at
))
5983 case dw_val_class_const
:
5984 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5985 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5988 case dw_val_class_unsigned_const
:
5989 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5990 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5993 case dw_val_class_const_double
:
5994 CHECKSUM_ULEB128 (DW_FORM_block
);
5995 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5996 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5999 case dw_val_class_vec
:
6000 CHECKSUM_ULEB128 (DW_FORM_block
);
6001 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_vec
));
6002 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
6005 case dw_val_class_flag
:
6006 CHECKSUM_ULEB128 (DW_FORM_flag
);
6007 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
6010 case dw_val_class_str
:
6011 CHECKSUM_ULEB128 (DW_FORM_string
);
6012 CHECKSUM_STRING (AT_string (at
));
6015 case dw_val_class_addr
:
6017 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6018 CHECKSUM_ULEB128 (DW_FORM_string
);
6019 CHECKSUM_STRING (XSTR (r
, 0));
6022 case dw_val_class_offset
:
6023 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6024 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
6027 case dw_val_class_loc
:
6028 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6029 loc_checksum_ordered (loc
, ctx
);
6032 case dw_val_class_fde_ref
:
6033 case dw_val_class_lbl_id
:
6034 case dw_val_class_lineptr
:
6035 case dw_val_class_macptr
:
6038 case dw_val_class_file
:
6039 CHECKSUM_ULEB128 (DW_FORM_string
);
6040 CHECKSUM_STRING (AT_file (at
)->filename
);
6043 case dw_val_class_data8
:
6044 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6052 struct checksum_attributes
6054 dw_attr_ref at_name
;
6055 dw_attr_ref at_type
;
6056 dw_attr_ref at_friend
;
6057 dw_attr_ref at_accessibility
;
6058 dw_attr_ref at_address_class
;
6059 dw_attr_ref at_allocated
;
6060 dw_attr_ref at_artificial
;
6061 dw_attr_ref at_associated
;
6062 dw_attr_ref at_binary_scale
;
6063 dw_attr_ref at_bit_offset
;
6064 dw_attr_ref at_bit_size
;
6065 dw_attr_ref at_bit_stride
;
6066 dw_attr_ref at_byte_size
;
6067 dw_attr_ref at_byte_stride
;
6068 dw_attr_ref at_const_value
;
6069 dw_attr_ref at_containing_type
;
6070 dw_attr_ref at_count
;
6071 dw_attr_ref at_data_location
;
6072 dw_attr_ref at_data_member_location
;
6073 dw_attr_ref at_decimal_scale
;
6074 dw_attr_ref at_decimal_sign
;
6075 dw_attr_ref at_default_value
;
6076 dw_attr_ref at_digit_count
;
6077 dw_attr_ref at_discr
;
6078 dw_attr_ref at_discr_list
;
6079 dw_attr_ref at_discr_value
;
6080 dw_attr_ref at_encoding
;
6081 dw_attr_ref at_endianity
;
6082 dw_attr_ref at_explicit
;
6083 dw_attr_ref at_is_optional
;
6084 dw_attr_ref at_location
;
6085 dw_attr_ref at_lower_bound
;
6086 dw_attr_ref at_mutable
;
6087 dw_attr_ref at_ordering
;
6088 dw_attr_ref at_picture_string
;
6089 dw_attr_ref at_prototyped
;
6090 dw_attr_ref at_small
;
6091 dw_attr_ref at_segment
;
6092 dw_attr_ref at_string_length
;
6093 dw_attr_ref at_threads_scaled
;
6094 dw_attr_ref at_upper_bound
;
6095 dw_attr_ref at_use_location
;
6096 dw_attr_ref at_use_UTF8
;
6097 dw_attr_ref at_variable_parameter
;
6098 dw_attr_ref at_virtuality
;
6099 dw_attr_ref at_visibility
;
6100 dw_attr_ref at_vtable_elem_location
;
6103 /* Collect the attributes that we will want to use for the checksum. */
6106 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
6111 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6122 attrs
->at_friend
= a
;
6124 case DW_AT_accessibility
:
6125 attrs
->at_accessibility
= a
;
6127 case DW_AT_address_class
:
6128 attrs
->at_address_class
= a
;
6130 case DW_AT_allocated
:
6131 attrs
->at_allocated
= a
;
6133 case DW_AT_artificial
:
6134 attrs
->at_artificial
= a
;
6136 case DW_AT_associated
:
6137 attrs
->at_associated
= a
;
6139 case DW_AT_binary_scale
:
6140 attrs
->at_binary_scale
= a
;
6142 case DW_AT_bit_offset
:
6143 attrs
->at_bit_offset
= a
;
6145 case DW_AT_bit_size
:
6146 attrs
->at_bit_size
= a
;
6148 case DW_AT_bit_stride
:
6149 attrs
->at_bit_stride
= a
;
6151 case DW_AT_byte_size
:
6152 attrs
->at_byte_size
= a
;
6154 case DW_AT_byte_stride
:
6155 attrs
->at_byte_stride
= a
;
6157 case DW_AT_const_value
:
6158 attrs
->at_const_value
= a
;
6160 case DW_AT_containing_type
:
6161 attrs
->at_containing_type
= a
;
6164 attrs
->at_count
= a
;
6166 case DW_AT_data_location
:
6167 attrs
->at_data_location
= a
;
6169 case DW_AT_data_member_location
:
6170 attrs
->at_data_member_location
= a
;
6172 case DW_AT_decimal_scale
:
6173 attrs
->at_decimal_scale
= a
;
6175 case DW_AT_decimal_sign
:
6176 attrs
->at_decimal_sign
= a
;
6178 case DW_AT_default_value
:
6179 attrs
->at_default_value
= a
;
6181 case DW_AT_digit_count
:
6182 attrs
->at_digit_count
= a
;
6185 attrs
->at_discr
= a
;
6187 case DW_AT_discr_list
:
6188 attrs
->at_discr_list
= a
;
6190 case DW_AT_discr_value
:
6191 attrs
->at_discr_value
= a
;
6193 case DW_AT_encoding
:
6194 attrs
->at_encoding
= a
;
6196 case DW_AT_endianity
:
6197 attrs
->at_endianity
= a
;
6199 case DW_AT_explicit
:
6200 attrs
->at_explicit
= a
;
6202 case DW_AT_is_optional
:
6203 attrs
->at_is_optional
= a
;
6205 case DW_AT_location
:
6206 attrs
->at_location
= a
;
6208 case DW_AT_lower_bound
:
6209 attrs
->at_lower_bound
= a
;
6212 attrs
->at_mutable
= a
;
6214 case DW_AT_ordering
:
6215 attrs
->at_ordering
= a
;
6217 case DW_AT_picture_string
:
6218 attrs
->at_picture_string
= a
;
6220 case DW_AT_prototyped
:
6221 attrs
->at_prototyped
= a
;
6224 attrs
->at_small
= a
;
6227 attrs
->at_segment
= a
;
6229 case DW_AT_string_length
:
6230 attrs
->at_string_length
= a
;
6232 case DW_AT_threads_scaled
:
6233 attrs
->at_threads_scaled
= a
;
6235 case DW_AT_upper_bound
:
6236 attrs
->at_upper_bound
= a
;
6238 case DW_AT_use_location
:
6239 attrs
->at_use_location
= a
;
6241 case DW_AT_use_UTF8
:
6242 attrs
->at_use_UTF8
= a
;
6244 case DW_AT_variable_parameter
:
6245 attrs
->at_variable_parameter
= a
;
6247 case DW_AT_virtuality
:
6248 attrs
->at_virtuality
= a
;
6250 case DW_AT_visibility
:
6251 attrs
->at_visibility
= a
;
6253 case DW_AT_vtable_elem_location
:
6254 attrs
->at_vtable_elem_location
= a
;
6262 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6265 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6269 struct checksum_attributes attrs
;
6271 CHECKSUM_ULEB128 ('D');
6272 CHECKSUM_ULEB128 (die
->die_tag
);
6274 memset (&attrs
, 0, sizeof (attrs
));
6276 decl
= get_AT_ref (die
, DW_AT_specification
);
6278 collect_checksum_attributes (&attrs
, decl
);
6279 collect_checksum_attributes (&attrs
, die
);
6281 CHECKSUM_ATTR (attrs
.at_name
);
6282 CHECKSUM_ATTR (attrs
.at_accessibility
);
6283 CHECKSUM_ATTR (attrs
.at_address_class
);
6284 CHECKSUM_ATTR (attrs
.at_allocated
);
6285 CHECKSUM_ATTR (attrs
.at_artificial
);
6286 CHECKSUM_ATTR (attrs
.at_associated
);
6287 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6288 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6289 CHECKSUM_ATTR (attrs
.at_bit_size
);
6290 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6291 CHECKSUM_ATTR (attrs
.at_byte_size
);
6292 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6293 CHECKSUM_ATTR (attrs
.at_const_value
);
6294 CHECKSUM_ATTR (attrs
.at_containing_type
);
6295 CHECKSUM_ATTR (attrs
.at_count
);
6296 CHECKSUM_ATTR (attrs
.at_data_location
);
6297 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6298 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6299 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6300 CHECKSUM_ATTR (attrs
.at_default_value
);
6301 CHECKSUM_ATTR (attrs
.at_digit_count
);
6302 CHECKSUM_ATTR (attrs
.at_discr
);
6303 CHECKSUM_ATTR (attrs
.at_discr_list
);
6304 CHECKSUM_ATTR (attrs
.at_discr_value
);
6305 CHECKSUM_ATTR (attrs
.at_encoding
);
6306 CHECKSUM_ATTR (attrs
.at_endianity
);
6307 CHECKSUM_ATTR (attrs
.at_explicit
);
6308 CHECKSUM_ATTR (attrs
.at_is_optional
);
6309 CHECKSUM_ATTR (attrs
.at_location
);
6310 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6311 CHECKSUM_ATTR (attrs
.at_mutable
);
6312 CHECKSUM_ATTR (attrs
.at_ordering
);
6313 CHECKSUM_ATTR (attrs
.at_picture_string
);
6314 CHECKSUM_ATTR (attrs
.at_prototyped
);
6315 CHECKSUM_ATTR (attrs
.at_small
);
6316 CHECKSUM_ATTR (attrs
.at_segment
);
6317 CHECKSUM_ATTR (attrs
.at_string_length
);
6318 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6319 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6320 CHECKSUM_ATTR (attrs
.at_use_location
);
6321 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6322 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6323 CHECKSUM_ATTR (attrs
.at_virtuality
);
6324 CHECKSUM_ATTR (attrs
.at_visibility
);
6325 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6326 CHECKSUM_ATTR (attrs
.at_type
);
6327 CHECKSUM_ATTR (attrs
.at_friend
);
6329 /* Checksum the child DIEs, except for nested types and member functions. */
6332 dw_attr_ref name_attr
;
6335 name_attr
= get_AT (c
, DW_AT_name
);
6336 if ((is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
)
6337 && name_attr
!= NULL
)
6339 CHECKSUM_ULEB128 ('S');
6340 CHECKSUM_ULEB128 (c
->die_tag
);
6341 CHECKSUM_STRING (AT_string (name_attr
));
6345 /* Mark this DIE so it gets processed when unmarking. */
6346 if (c
->die_mark
== 0)
6348 die_checksum_ordered (c
, ctx
, mark
);
6350 } while (c
!= die
->die_child
);
6352 CHECKSUM_ULEB128 (0);
6356 #undef CHECKSUM_STRING
6357 #undef CHECKSUM_ATTR
6358 #undef CHECKSUM_LEB128
6359 #undef CHECKSUM_ULEB128
6361 /* Generate the type signature for DIE. This is computed by generating an
6362 MD5 checksum over the DIE's tag, its relevant attributes, and its
6363 children. Attributes that are references to other DIEs are processed
6364 by recursion, using the MARK field to prevent infinite recursion.
6365 If the DIE is nested inside a namespace or another type, we also
6366 need to include that context in the signature. The lower 64 bits
6367 of the resulting MD5 checksum comprise the signature. */
6370 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6374 unsigned char checksum
[16];
6378 name
= get_AT_string (die
, DW_AT_name
);
6379 decl
= get_AT_ref (die
, DW_AT_specification
);
6381 /* First, compute a signature for just the type name (and its surrounding
6382 context, if any. This is stored in the type unit DIE for link-time
6383 ODR (one-definition rule) checking. */
6385 if (is_cxx() && name
!= NULL
)
6387 md5_init_ctx (&ctx
);
6389 /* Checksum the names of surrounding namespaces and structures. */
6390 if (decl
!= NULL
&& decl
->die_parent
!= NULL
)
6391 checksum_die_context (decl
->die_parent
, &ctx
);
6393 md5_process_bytes (&die
->die_tag
, sizeof (die
->die_tag
), &ctx
);
6394 md5_process_bytes (name
, strlen (name
) + 1, &ctx
);
6395 md5_finish_ctx (&ctx
, checksum
);
6397 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6400 /* Next, compute the complete type signature. */
6402 md5_init_ctx (&ctx
);
6404 die
->die_mark
= mark
;
6406 /* Checksum the names of surrounding namespaces and structures. */
6407 if (decl
!= NULL
&& decl
->die_parent
!= NULL
)
6408 checksum_die_context (decl
->die_parent
, &ctx
);
6410 /* Checksum the DIE and its children. */
6411 die_checksum_ordered (die
, &ctx
, &mark
);
6412 unmark_all_dies (die
);
6413 md5_finish_ctx (&ctx
, checksum
);
6415 /* Store the signature in the type node and link the type DIE and the
6416 type node together. */
6417 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6418 DWARF_TYPE_SIGNATURE_SIZE
);
6419 die
->die_id
.die_type_node
= type_node
;
6420 type_node
->type_die
= die
;
6422 /* If the DIE is a specification, link its declaration to the type node
6425 decl
->die_id
.die_type_node
= type_node
;
6428 /* Do the location expressions look same? */
6430 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6432 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6433 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6434 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6437 /* Do the values look the same? */
6439 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6441 dw_loc_descr_ref loc1
, loc2
;
6444 if (v1
->val_class
!= v2
->val_class
)
6447 switch (v1
->val_class
)
6449 case dw_val_class_const
:
6450 return v1
->v
.val_int
== v2
->v
.val_int
;
6451 case dw_val_class_unsigned_const
:
6452 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6453 case dw_val_class_const_double
:
6454 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6455 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6456 case dw_val_class_vec
:
6457 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6458 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6460 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6461 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6464 case dw_val_class_flag
:
6465 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6466 case dw_val_class_str
:
6467 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6469 case dw_val_class_addr
:
6470 r1
= v1
->v
.val_addr
;
6471 r2
= v2
->v
.val_addr
;
6472 if (GET_CODE (r1
) != GET_CODE (r2
))
6474 return !rtx_equal_p (r1
, r2
);
6476 case dw_val_class_offset
:
6477 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6479 case dw_val_class_loc
:
6480 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6482 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6483 if (!same_loc_p (loc1
, loc2
, mark
))
6485 return !loc1
&& !loc2
;
6487 case dw_val_class_die_ref
:
6488 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6490 case dw_val_class_fde_ref
:
6491 case dw_val_class_vms_delta
:
6492 case dw_val_class_lbl_id
:
6493 case dw_val_class_lineptr
:
6494 case dw_val_class_macptr
:
6497 case dw_val_class_file
:
6498 return v1
->v
.val_file
== v2
->v
.val_file
;
6500 case dw_val_class_data8
:
6501 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6508 /* Do the attributes look the same? */
6511 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6513 if (at1
->dw_attr
!= at2
->dw_attr
)
6516 /* We don't care that this was compiled with a different compiler
6517 snapshot; if the output is the same, that's what matters. */
6518 if (at1
->dw_attr
== DW_AT_producer
)
6521 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6524 /* Do the dies look the same? */
6527 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6533 /* To avoid infinite recursion. */
6535 return die1
->die_mark
== die2
->die_mark
;
6536 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6538 if (die1
->die_tag
!= die2
->die_tag
)
6541 if (VEC_length (dw_attr_node
, die1
->die_attr
)
6542 != VEC_length (dw_attr_node
, die2
->die_attr
))
6545 FOR_EACH_VEC_ELT (dw_attr_node
, die1
->die_attr
, ix
, a1
)
6546 if (!same_attr_p (a1
, VEC_index (dw_attr_node
, die2
->die_attr
, ix
), mark
))
6549 c1
= die1
->die_child
;
6550 c2
= die2
->die_child
;
6559 if (!same_die_p (c1
, c2
, mark
))
6563 if (c1
== die1
->die_child
)
6565 if (c2
== die2
->die_child
)
6575 /* Do the dies look the same? Wrapper around same_die_p. */
6578 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6581 int ret
= same_die_p (die1
, die2
, &mark
);
6583 unmark_all_dies (die1
);
6584 unmark_all_dies (die2
);
6589 /* The prefix to attach to symbols on DIEs in the current comdat debug
6591 static char *comdat_symbol_id
;
6593 /* The index of the current symbol within the current comdat CU. */
6594 static unsigned int comdat_symbol_number
;
6596 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6597 children, and set comdat_symbol_id accordingly. */
6600 compute_section_prefix (dw_die_ref unit_die
)
6602 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6603 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6604 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6607 unsigned char checksum
[16];
6610 /* Compute the checksum of the DIE, then append part of it as hex digits to
6611 the name filename of the unit. */
6613 md5_init_ctx (&ctx
);
6615 die_checksum (unit_die
, &ctx
, &mark
);
6616 unmark_all_dies (unit_die
);
6617 md5_finish_ctx (&ctx
, checksum
);
6619 sprintf (name
, "%s.", base
);
6620 clean_symbol_name (name
);
6622 p
= name
+ strlen (name
);
6623 for (i
= 0; i
< 4; i
++)
6625 sprintf (p
, "%.2x", checksum
[i
]);
6629 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6630 comdat_symbol_number
= 0;
6633 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6636 is_type_die (dw_die_ref die
)
6638 switch (die
->die_tag
)
6640 case DW_TAG_array_type
:
6641 case DW_TAG_class_type
:
6642 case DW_TAG_interface_type
:
6643 case DW_TAG_enumeration_type
:
6644 case DW_TAG_pointer_type
:
6645 case DW_TAG_reference_type
:
6646 case DW_TAG_rvalue_reference_type
:
6647 case DW_TAG_string_type
:
6648 case DW_TAG_structure_type
:
6649 case DW_TAG_subroutine_type
:
6650 case DW_TAG_union_type
:
6651 case DW_TAG_ptr_to_member_type
:
6652 case DW_TAG_set_type
:
6653 case DW_TAG_subrange_type
:
6654 case DW_TAG_base_type
:
6655 case DW_TAG_const_type
:
6656 case DW_TAG_file_type
:
6657 case DW_TAG_packed_type
:
6658 case DW_TAG_volatile_type
:
6659 case DW_TAG_typedef
:
6666 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6667 Basically, we want to choose the bits that are likely to be shared between
6668 compilations (types) and leave out the bits that are specific to individual
6669 compilations (functions). */
6672 is_comdat_die (dw_die_ref c
)
6674 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6675 we do for stabs. The advantage is a greater likelihood of sharing between
6676 objects that don't include headers in the same order (and therefore would
6677 put the base types in a different comdat). jason 8/28/00 */
6679 if (c
->die_tag
== DW_TAG_base_type
)
6682 if (c
->die_tag
== DW_TAG_pointer_type
6683 || c
->die_tag
== DW_TAG_reference_type
6684 || c
->die_tag
== DW_TAG_rvalue_reference_type
6685 || c
->die_tag
== DW_TAG_const_type
6686 || c
->die_tag
== DW_TAG_volatile_type
)
6688 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6690 return t
? is_comdat_die (t
) : 0;
6693 return is_type_die (c
);
6696 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6697 compilation unit. */
6700 is_symbol_die (dw_die_ref c
)
6702 return (is_type_die (c
)
6703 || is_declaration_die (c
)
6704 || c
->die_tag
== DW_TAG_namespace
6705 || c
->die_tag
== DW_TAG_module
);
6708 /* Returns true iff C is a compile-unit DIE. */
6711 is_cu_die (dw_die_ref c
)
6713 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6717 gen_internal_sym (const char *prefix
)
6721 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6722 return xstrdup (buf
);
6725 /* Assign symbols to all worthy DIEs under DIE. */
6728 assign_symbol_names (dw_die_ref die
)
6732 if (is_symbol_die (die
))
6734 if (comdat_symbol_id
)
6736 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6738 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6739 comdat_symbol_id
, comdat_symbol_number
++);
6740 die
->die_id
.die_symbol
= xstrdup (p
);
6743 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6746 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6749 struct cu_hash_table_entry
6752 unsigned min_comdat_num
, max_comdat_num
;
6753 struct cu_hash_table_entry
*next
;
6756 /* Routines to manipulate hash table of CUs. */
6758 htab_cu_hash (const void *of
)
6760 const struct cu_hash_table_entry
*const entry
=
6761 (const struct cu_hash_table_entry
*) of
;
6763 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6767 htab_cu_eq (const void *of1
, const void *of2
)
6769 const struct cu_hash_table_entry
*const entry1
=
6770 (const struct cu_hash_table_entry
*) of1
;
6771 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
6773 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6777 htab_cu_del (void *what
)
6779 struct cu_hash_table_entry
*next
,
6780 *entry
= (struct cu_hash_table_entry
*) what
;
6790 /* Check whether we have already seen this CU and set up SYM_NUM
6793 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
6795 struct cu_hash_table_entry dummy
;
6796 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6798 dummy
.max_comdat_num
= 0;
6800 slot
= (struct cu_hash_table_entry
**)
6801 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6805 for (; entry
; last
= entry
, entry
= entry
->next
)
6807 if (same_die_p_wrap (cu
, entry
->cu
))
6813 *sym_num
= entry
->min_comdat_num
;
6817 entry
= XCNEW (struct cu_hash_table_entry
);
6819 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6820 entry
->next
= *slot
;
6826 /* Record SYM_NUM to record of CU in HTABLE. */
6828 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
6830 struct cu_hash_table_entry
**slot
, *entry
;
6832 slot
= (struct cu_hash_table_entry
**)
6833 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6837 entry
->max_comdat_num
= sym_num
;
6840 /* Traverse the DIE (which is always comp_unit_die), and set up
6841 additional compilation units for each of the include files we see
6842 bracketed by BINCL/EINCL. */
6845 break_out_includes (dw_die_ref die
)
6848 dw_die_ref unit
= NULL
;
6849 limbo_die_node
*node
, **pnode
;
6850 htab_t cu_hash_table
;
6854 dw_die_ref prev
= c
;
6856 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6857 || (unit
&& is_comdat_die (c
)))
6859 dw_die_ref next
= c
->die_sib
;
6861 /* This DIE is for a secondary CU; remove it from the main one. */
6862 remove_child_with_prev (c
, prev
);
6864 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6865 unit
= push_new_compile_unit (unit
, c
);
6866 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6867 unit
= pop_compile_unit (unit
);
6869 add_child_die (unit
, c
);
6871 if (c
== die
->die_child
)
6874 } while (c
!= die
->die_child
);
6877 /* We can only use this in debugging, since the frontend doesn't check
6878 to make sure that we leave every include file we enter. */
6882 assign_symbol_names (die
);
6883 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
6884 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6890 compute_section_prefix (node
->die
);
6891 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6892 &comdat_symbol_number
);
6893 assign_symbol_names (node
->die
);
6895 *pnode
= node
->next
;
6898 pnode
= &node
->next
;
6899 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6900 comdat_symbol_number
);
6903 htab_delete (cu_hash_table
);
6906 /* Return non-zero if this DIE is a declaration. */
6909 is_declaration_die (dw_die_ref die
)
6914 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6915 if (a
->dw_attr
== DW_AT_declaration
)
6921 /* Return non-zero if this DIE is nested inside a subprogram. */
6924 is_nested_in_subprogram (dw_die_ref die
)
6926 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6930 return local_scope_p (decl
);
6933 /* Return non-zero if this DIE contains a defining declaration of a
6937 contains_subprogram_definition (dw_die_ref die
)
6941 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6943 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition(c
)) return 1);
6947 /* Return non-zero if this is a type DIE that should be moved to a
6948 COMDAT .debug_types section. */
6951 should_move_die_to_comdat (dw_die_ref die
)
6953 switch (die
->die_tag
)
6955 case DW_TAG_class_type
:
6956 case DW_TAG_structure_type
:
6957 case DW_TAG_enumeration_type
:
6958 case DW_TAG_union_type
:
6959 /* Don't move declarations, inlined instances, or types nested in a
6961 if (is_declaration_die (die
)
6962 || get_AT (die
, DW_AT_abstract_origin
)
6963 || is_nested_in_subprogram (die
))
6965 /* A type definition should never contain a subprogram definition. */
6966 gcc_assert (!contains_subprogram_definition (die
));
6968 case DW_TAG_array_type
:
6969 case DW_TAG_interface_type
:
6970 case DW_TAG_pointer_type
:
6971 case DW_TAG_reference_type
:
6972 case DW_TAG_rvalue_reference_type
:
6973 case DW_TAG_string_type
:
6974 case DW_TAG_subroutine_type
:
6975 case DW_TAG_ptr_to_member_type
:
6976 case DW_TAG_set_type
:
6977 case DW_TAG_subrange_type
:
6978 case DW_TAG_base_type
:
6979 case DW_TAG_const_type
:
6980 case DW_TAG_file_type
:
6981 case DW_TAG_packed_type
:
6982 case DW_TAG_volatile_type
:
6983 case DW_TAG_typedef
:
6989 /* Make a clone of DIE. */
6992 clone_die (dw_die_ref die
)
6998 clone
= ggc_alloc_cleared_die_node ();
6999 clone
->die_tag
= die
->die_tag
;
7001 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7002 add_dwarf_attr (clone
, a
);
7007 /* Make a clone of the tree rooted at DIE. */
7010 clone_tree (dw_die_ref die
)
7013 dw_die_ref clone
= clone_die (die
);
7015 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree(c
)));
7020 /* Make a clone of DIE as a declaration. */
7023 clone_as_declaration (dw_die_ref die
)
7030 /* If the DIE is already a declaration, just clone it. */
7031 if (is_declaration_die (die
))
7032 return clone_die (die
);
7034 /* If the DIE is a specification, just clone its declaration DIE. */
7035 decl
= get_AT_ref (die
, DW_AT_specification
);
7037 return clone_die (decl
);
7039 clone
= ggc_alloc_cleared_die_node ();
7040 clone
->die_tag
= die
->die_tag
;
7042 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7044 /* We don't want to copy over all attributes.
7045 For example we don't want DW_AT_byte_size because otherwise we will no
7046 longer have a declaration and GDB will treat it as a definition. */
7050 case DW_AT_artificial
:
7051 case DW_AT_containing_type
:
7052 case DW_AT_external
:
7055 case DW_AT_virtuality
:
7056 case DW_AT_linkage_name
:
7057 case DW_AT_MIPS_linkage_name
:
7058 add_dwarf_attr (clone
, a
);
7060 case DW_AT_byte_size
:
7066 if (die
->die_id
.die_type_node
)
7067 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7069 add_AT_flag (clone
, DW_AT_declaration
, 1);
7073 /* Copy the declaration context to the new compile unit DIE. This includes
7074 any surrounding namespace or type declarations. If the DIE has an
7075 AT_specification attribute, it also includes attributes and children
7076 attached to the specification. */
7079 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7082 dw_die_ref new_decl
;
7084 decl
= get_AT_ref (die
, DW_AT_specification
);
7093 /* Copy the type node pointer from the new DIE to the original
7094 declaration DIE so we can forward references later. */
7095 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7097 remove_AT (die
, DW_AT_specification
);
7099 FOR_EACH_VEC_ELT (dw_attr_node
, decl
->die_attr
, ix
, a
)
7101 if (a
->dw_attr
!= DW_AT_name
7102 && a
->dw_attr
!= DW_AT_declaration
7103 && a
->dw_attr
!= DW_AT_external
)
7104 add_dwarf_attr (die
, a
);
7107 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree(c
)));
7110 if (decl
->die_parent
!= NULL
7111 && decl
->die_parent
->die_tag
!= DW_TAG_compile_unit
7112 && decl
->die_parent
->die_tag
!= DW_TAG_type_unit
)
7114 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
7115 if (new_decl
!= NULL
)
7117 remove_AT (new_decl
, DW_AT_signature
);
7118 add_AT_specification (die
, new_decl
);
7123 /* Generate the skeleton ancestor tree for the given NODE, then clone
7124 the DIE and add the clone into the tree. */
7127 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7129 if (node
->new_die
!= NULL
)
7132 node
->new_die
= clone_as_declaration (node
->old_die
);
7134 if (node
->parent
!= NULL
)
7136 generate_skeleton_ancestor_tree (node
->parent
);
7137 add_child_die (node
->parent
->new_die
, node
->new_die
);
7141 /* Generate a skeleton tree of DIEs containing any declarations that are
7142 found in the original tree. We traverse the tree looking for declaration
7143 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7146 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7148 skeleton_chain_node node
;
7151 dw_die_ref prev
= NULL
;
7152 dw_die_ref next
= NULL
;
7154 node
.parent
= parent
;
7156 first
= c
= parent
->old_die
->die_child
;
7160 if (prev
== NULL
|| prev
->die_sib
== c
)
7163 next
= (c
== first
? NULL
: c
->die_sib
);
7165 node
.new_die
= NULL
;
7166 if (is_declaration_die (c
))
7168 /* Clone the existing DIE, move the original to the skeleton
7169 tree (which is in the main CU), and put the clone, with
7170 all the original's children, where the original came from. */
7171 dw_die_ref clone
= clone_die (c
);
7172 move_all_children (c
, clone
);
7174 replace_child (c
, clone
, prev
);
7175 generate_skeleton_ancestor_tree (parent
);
7176 add_child_die (parent
->new_die
, c
);
7180 generate_skeleton_bottom_up (&node
);
7181 } while (next
!= NULL
);
7184 /* Wrapper function for generate_skeleton_bottom_up. */
7187 generate_skeleton (dw_die_ref die
)
7189 skeleton_chain_node node
;
7192 node
.new_die
= NULL
;
7195 /* If this type definition is nested inside another type,
7196 always leave at least a declaration in its place. */
7197 if (die
->die_parent
!= NULL
&& is_type_die (die
->die_parent
))
7198 node
.new_die
= clone_as_declaration (die
);
7200 generate_skeleton_bottom_up (&node
);
7201 return node
.new_die
;
7204 /* Remove the DIE from its parent, possibly replacing it with a cloned
7205 declaration. The original DIE will be moved to a new compile unit
7206 so that existing references to it follow it to the new location. If
7207 any of the original DIE's descendants is a declaration, we need to
7208 replace the original DIE with a skeleton tree and move the
7209 declarations back into the skeleton tree. */
7212 remove_child_or_replace_with_skeleton (dw_die_ref child
, dw_die_ref prev
)
7214 dw_die_ref skeleton
;
7216 skeleton
= generate_skeleton (child
);
7217 if (skeleton
== NULL
)
7218 remove_child_with_prev (child
, prev
);
7221 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7222 replace_child (child
, skeleton
, prev
);
7228 /* Traverse the DIE and set up additional .debug_types sections for each
7229 type worthy of being placed in a COMDAT section. */
7232 break_out_comdat_types (dw_die_ref die
)
7236 dw_die_ref prev
= NULL
;
7237 dw_die_ref next
= NULL
;
7238 dw_die_ref unit
= NULL
;
7240 first
= c
= die
->die_child
;
7244 if (prev
== NULL
|| prev
->die_sib
== c
)
7247 next
= (c
== first
? NULL
: c
->die_sib
);
7248 if (should_move_die_to_comdat (c
))
7250 dw_die_ref replacement
;
7251 comdat_type_node_ref type_node
;
7253 /* Create a new type unit DIE as the root for the new tree, and
7254 add it to the list of comdat types. */
7255 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7256 add_AT_unsigned (unit
, DW_AT_language
,
7257 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7258 type_node
= ggc_alloc_cleared_comdat_type_node ();
7259 type_node
->root_die
= unit
;
7260 type_node
->next
= comdat_type_list
;
7261 comdat_type_list
= type_node
;
7263 /* Generate the type signature. */
7264 generate_type_signature (c
, type_node
);
7266 /* Copy the declaration context, attributes, and children of the
7267 declaration into the new compile unit DIE. */
7268 copy_declaration_context (unit
, c
);
7270 /* Remove this DIE from the main CU. */
7271 replacement
= remove_child_or_replace_with_skeleton (c
, prev
);
7273 /* Break out nested types into their own type units. */
7274 break_out_comdat_types (c
);
7276 /* Add the DIE to the new compunit. */
7277 add_child_die (unit
, c
);
7279 if (replacement
!= NULL
)
7282 else if (c
->die_tag
== DW_TAG_namespace
7283 || c
->die_tag
== DW_TAG_class_type
7284 || c
->die_tag
== DW_TAG_structure_type
7285 || c
->die_tag
== DW_TAG_union_type
)
7287 /* Look for nested types that can be broken out. */
7288 break_out_comdat_types (c
);
7290 } while (next
!= NULL
);
7293 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7295 struct decl_table_entry
7301 /* Routines to manipulate hash table of copied declarations. */
7304 htab_decl_hash (const void *of
)
7306 const struct decl_table_entry
*const entry
=
7307 (const struct decl_table_entry
*) of
;
7309 return htab_hash_pointer (entry
->orig
);
7313 htab_decl_eq (const void *of1
, const void *of2
)
7315 const struct decl_table_entry
*const entry1
=
7316 (const struct decl_table_entry
*) of1
;
7317 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
7319 return entry1
->orig
== entry2
;
7323 htab_decl_del (void *what
)
7325 struct decl_table_entry
*entry
= (struct decl_table_entry
*) what
;
7330 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7331 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7332 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7333 to check if the ancestor has already been copied into UNIT. */
7336 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
7338 dw_die_ref parent
= die
->die_parent
;
7339 dw_die_ref new_parent
= unit
;
7342 struct decl_table_entry
*entry
= NULL
;
7346 /* Check if the entry has already been copied to UNIT. */
7347 slot
= htab_find_slot_with_hash (decl_table
, die
,
7348 htab_hash_pointer (die
), INSERT
);
7349 if (*slot
!= HTAB_EMPTY_ENTRY
)
7351 entry
= (struct decl_table_entry
*) *slot
;
7355 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7356 entry
= XCNEW (struct decl_table_entry
);
7364 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7367 if (parent
->die_tag
!= DW_TAG_compile_unit
7368 && parent
->die_tag
!= DW_TAG_type_unit
)
7369 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7372 copy
= clone_as_declaration (die
);
7373 add_child_die (new_parent
, copy
);
7375 if (decl_table
!= NULL
)
7377 /* Record the pointer to the copy. */
7384 /* Walk the DIE and its children, looking for references to incomplete
7385 or trivial types that are unmarked (i.e., that are not in the current
7389 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
7395 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7397 if (AT_class (a
) == dw_val_class_die_ref
)
7399 dw_die_ref targ
= AT_ref (a
);
7400 comdat_type_node_ref type_node
= targ
->die_id
.die_type_node
;
7402 struct decl_table_entry
*entry
;
7404 if (targ
->die_mark
!= 0 || type_node
!= NULL
)
7407 slot
= htab_find_slot_with_hash (decl_table
, targ
,
7408 htab_hash_pointer (targ
), INSERT
);
7410 if (*slot
!= HTAB_EMPTY_ENTRY
)
7412 /* TARG has already been copied, so we just need to
7413 modify the reference to point to the copy. */
7414 entry
= (struct decl_table_entry
*) *slot
;
7415 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7419 dw_die_ref parent
= unit
;
7420 dw_die_ref copy
= clone_tree (targ
);
7422 /* Make sure the cloned tree is marked as part of the
7426 /* Record in DECL_TABLE that TARG has been copied.
7427 Need to do this now, before the recursive call,
7428 because DECL_TABLE may be expanded and SLOT
7429 would no longer be a valid pointer. */
7430 entry
= XCNEW (struct decl_table_entry
);
7435 /* If TARG has surrounding context, copy its ancestor tree
7436 into the new type unit. */
7437 if (targ
->die_parent
!= NULL
7438 && targ
->die_parent
->die_tag
!= DW_TAG_compile_unit
7439 && targ
->die_parent
->die_tag
!= DW_TAG_type_unit
)
7440 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7443 add_child_die (parent
, copy
);
7444 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7446 /* Make sure the newly-copied DIE is walked. If it was
7447 installed in a previously-added context, it won't
7448 get visited otherwise. */
7451 /* Find the highest point of the newly-added tree,
7452 mark each node along the way, and walk from there. */
7453 parent
->die_mark
= 1;
7454 while (parent
->die_parent
7455 && parent
->die_parent
->die_mark
== 0)
7457 parent
= parent
->die_parent
;
7458 parent
->die_mark
= 1;
7460 copy_decls_walk (unit
, parent
, decl_table
);
7466 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7469 /* Copy declarations for "unworthy" types into the new comdat section.
7470 Incomplete types, modified types, and certain other types aren't broken
7471 out into comdat sections of their own, so they don't have a signature,
7472 and we need to copy the declaration into the same section so that we
7473 don't have an external reference. */
7476 copy_decls_for_unworthy_types (dw_die_ref unit
)
7481 decl_table
= htab_create (10, htab_decl_hash
, htab_decl_eq
, htab_decl_del
);
7482 copy_decls_walk (unit
, unit
, decl_table
);
7483 htab_delete (decl_table
);
7487 /* Traverse the DIE and add a sibling attribute if it may have the
7488 effect of speeding up access to siblings. To save some space,
7489 avoid generating sibling attributes for DIE's without children. */
7492 add_sibling_attributes (dw_die_ref die
)
7496 if (! die
->die_child
)
7499 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7500 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7502 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7505 /* Output all location lists for the DIE and its children. */
7508 output_location_lists (dw_die_ref die
)
7514 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7515 if (AT_class (a
) == dw_val_class_loc_list
)
7516 output_loc_list (AT_loc_list (a
));
7518 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7521 /* The format of each DIE (and its attribute value pairs) is encoded in an
7522 abbreviation table. This routine builds the abbreviation table and assigns
7523 a unique abbreviation id for each abbreviation entry. The children of each
7524 die are visited recursively. */
7527 build_abbrev_table (dw_die_ref die
)
7529 unsigned long abbrev_id
;
7530 unsigned int n_alloc
;
7535 /* Scan the DIE references, and mark as external any that refer to
7536 DIEs from other CUs (i.e. those which are not marked). */
7537 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7538 if (AT_class (a
) == dw_val_class_die_ref
7539 && AT_ref (a
)->die_mark
== 0)
7541 gcc_assert (use_debug_types
|| AT_ref (a
)->die_id
.die_symbol
);
7542 set_AT_ref_external (a
, 1);
7545 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7547 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7548 dw_attr_ref die_a
, abbrev_a
;
7552 if (abbrev
->die_tag
!= die
->die_tag
)
7554 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7557 if (VEC_length (dw_attr_node
, abbrev
->die_attr
)
7558 != VEC_length (dw_attr_node
, die
->die_attr
))
7561 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, die_a
)
7563 abbrev_a
= VEC_index (dw_attr_node
, abbrev
->die_attr
, ix
);
7564 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7565 || (value_format (abbrev_a
) != value_format (die_a
)))
7575 if (abbrev_id
>= abbrev_die_table_in_use
)
7577 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7579 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7580 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7583 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7584 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7585 abbrev_die_table_allocated
= n_alloc
;
7588 ++abbrev_die_table_in_use
;
7589 abbrev_die_table
[abbrev_id
] = die
;
7592 die
->die_abbrev
= abbrev_id
;
7593 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
));
7596 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7599 constant_size (unsigned HOST_WIDE_INT value
)
7606 log
= floor_log2 (value
);
7609 log
= 1 << (floor_log2 (log
) + 1);
7614 /* Return the size of a DIE as it is represented in the
7615 .debug_info section. */
7617 static unsigned long
7618 size_of_die (dw_die_ref die
)
7620 unsigned long size
= 0;
7624 size
+= size_of_uleb128 (die
->die_abbrev
);
7625 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7627 switch (AT_class (a
))
7629 case dw_val_class_addr
:
7630 size
+= DWARF2_ADDR_SIZE
;
7632 case dw_val_class_offset
:
7633 size
+= DWARF_OFFSET_SIZE
;
7635 case dw_val_class_loc
:
7637 unsigned long lsize
= size_of_locs (AT_loc (a
));
7640 if (dwarf_version
>= 4)
7641 size
+= size_of_uleb128 (lsize
);
7643 size
+= constant_size (lsize
);
7647 case dw_val_class_loc_list
:
7648 size
+= DWARF_OFFSET_SIZE
;
7650 case dw_val_class_range_list
:
7651 size
+= DWARF_OFFSET_SIZE
;
7653 case dw_val_class_const
:
7654 size
+= size_of_sleb128 (AT_int (a
));
7656 case dw_val_class_unsigned_const
:
7658 int csize
= constant_size (AT_unsigned (a
));
7659 if (dwarf_version
== 3
7660 && a
->dw_attr
== DW_AT_data_member_location
7662 size
+= size_of_uleb128 (AT_unsigned (a
));
7667 case dw_val_class_const_double
:
7668 size
+= 2 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
7669 if (HOST_BITS_PER_WIDE_INT
>= 64)
7672 case dw_val_class_vec
:
7673 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7674 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7675 + a
->dw_attr_val
.v
.val_vec
.length
7676 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7678 case dw_val_class_flag
:
7679 if (dwarf_version
>= 4)
7680 /* Currently all add_AT_flag calls pass in 1 as last argument,
7681 so DW_FORM_flag_present can be used. If that ever changes,
7682 we'll need to use DW_FORM_flag and have some optimization
7683 in build_abbrev_table that will change those to
7684 DW_FORM_flag_present if it is set to 1 in all DIEs using
7685 the same abbrev entry. */
7686 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7690 case dw_val_class_die_ref
:
7691 if (AT_ref_external (a
))
7693 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7694 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7695 is sized by target address length, whereas in DWARF3
7696 it's always sized as an offset. */
7697 if (use_debug_types
)
7698 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7699 else if (dwarf_version
== 2)
7700 size
+= DWARF2_ADDR_SIZE
;
7702 size
+= DWARF_OFFSET_SIZE
;
7705 size
+= DWARF_OFFSET_SIZE
;
7707 case dw_val_class_fde_ref
:
7708 size
+= DWARF_OFFSET_SIZE
;
7710 case dw_val_class_lbl_id
:
7711 size
+= DWARF2_ADDR_SIZE
;
7713 case dw_val_class_lineptr
:
7714 case dw_val_class_macptr
:
7715 size
+= DWARF_OFFSET_SIZE
;
7717 case dw_val_class_str
:
7718 if (AT_string_form (a
) == DW_FORM_strp
)
7719 size
+= DWARF_OFFSET_SIZE
;
7721 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7723 case dw_val_class_file
:
7724 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7726 case dw_val_class_data8
:
7729 case dw_val_class_vms_delta
:
7730 size
+= DWARF_OFFSET_SIZE
;
7740 /* Size the debugging information associated with a given DIE. Visits the
7741 DIE's children recursively. Updates the global variable next_die_offset, on
7742 each time through. Uses the current value of next_die_offset to update the
7743 die_offset field in each DIE. */
7746 calc_die_sizes (dw_die_ref die
)
7750 gcc_assert (die
->die_offset
== 0
7751 || (unsigned long int) die
->die_offset
== next_die_offset
);
7752 die
->die_offset
= next_die_offset
;
7753 next_die_offset
+= size_of_die (die
);
7755 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7757 if (die
->die_child
!= NULL
)
7758 /* Count the null byte used to terminate sibling lists. */
7759 next_die_offset
+= 1;
7762 /* Size just the base type children at the start of the CU.
7763 This is needed because build_abbrev needs to size locs
7764 and sizing of type based stack ops needs to know die_offset
7765 values for the base types. */
7768 calc_base_type_die_sizes (void)
7770 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7772 dw_die_ref base_type
;
7773 #if ENABLE_ASSERT_CHECKING
7774 dw_die_ref prev
= comp_unit_die ()->die_child
;
7777 die_offset
+= size_of_die (comp_unit_die ());
7778 for (i
= 0; VEC_iterate (dw_die_ref
, base_types
, i
, base_type
); i
++)
7780 #if ENABLE_ASSERT_CHECKING
7781 gcc_assert (base_type
->die_offset
== 0
7782 && prev
->die_sib
== base_type
7783 && base_type
->die_child
== NULL
7784 && base_type
->die_abbrev
);
7787 base_type
->die_offset
= die_offset
;
7788 die_offset
+= size_of_die (base_type
);
7792 /* Set the marks for a die and its children. We do this so
7793 that we know whether or not a reference needs to use FORM_ref_addr; only
7794 DIEs in the same CU will be marked. We used to clear out the offset
7795 and use that as the flag, but ran into ordering problems. */
7798 mark_dies (dw_die_ref die
)
7802 gcc_assert (!die
->die_mark
);
7805 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7808 /* Clear the marks for a die and its children. */
7811 unmark_dies (dw_die_ref die
)
7815 if (! use_debug_types
)
7816 gcc_assert (die
->die_mark
);
7819 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7822 /* Clear the marks for a die, its children and referred dies. */
7825 unmark_all_dies (dw_die_ref die
)
7835 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7837 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7838 if (AT_class (a
) == dw_val_class_die_ref
)
7839 unmark_all_dies (AT_ref (a
));
7842 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7843 generated for the compilation unit. */
7845 static unsigned long
7846 size_of_pubnames (VEC (pubname_entry
, gc
) * names
)
7852 size
= DWARF_PUBNAMES_HEADER_SIZE
;
7853 FOR_EACH_VEC_ELT (pubname_entry
, names
, i
, p
)
7854 if (names
!= pubtype_table
7855 || p
->die
->die_offset
!= 0
7856 || !flag_eliminate_unused_debug_types
)
7857 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
7859 size
+= DWARF_OFFSET_SIZE
;
7863 /* Return the size of the information in the .debug_aranges section. */
7865 static unsigned long
7866 size_of_aranges (void)
7870 size
= DWARF_ARANGES_HEADER_SIZE
;
7872 /* Count the address/length pair for this compilation unit. */
7873 if (text_section_used
)
7874 size
+= 2 * DWARF2_ADDR_SIZE
;
7875 if (cold_text_section_used
)
7876 size
+= 2 * DWARF2_ADDR_SIZE
;
7877 if (have_multiple_function_sections
)
7882 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, fde_idx
, fde
)
7884 if (!fde
->in_std_section
)
7885 size
+= 2 * DWARF2_ADDR_SIZE
;
7886 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
7887 size
+= 2 * DWARF2_ADDR_SIZE
;
7891 /* Count the two zero words used to terminated the address range table. */
7892 size
+= 2 * DWARF2_ADDR_SIZE
;
7896 /* Select the encoding of an attribute value. */
7898 static enum dwarf_form
7899 value_format (dw_attr_ref a
)
7901 switch (a
->dw_attr_val
.val_class
)
7903 case dw_val_class_addr
:
7904 /* Only very few attributes allow DW_FORM_addr. */
7909 case DW_AT_entry_pc
:
7910 case DW_AT_trampoline
:
7911 return DW_FORM_addr
;
7915 switch (DWARF2_ADDR_SIZE
)
7918 return DW_FORM_data1
;
7920 return DW_FORM_data2
;
7922 return DW_FORM_data4
;
7924 return DW_FORM_data8
;
7928 case dw_val_class_range_list
:
7929 case dw_val_class_loc_list
:
7930 if (dwarf_version
>= 4)
7931 return DW_FORM_sec_offset
;
7933 case dw_val_class_vms_delta
:
7934 case dw_val_class_offset
:
7935 switch (DWARF_OFFSET_SIZE
)
7938 return DW_FORM_data4
;
7940 return DW_FORM_data8
;
7944 case dw_val_class_loc
:
7945 if (dwarf_version
>= 4)
7946 return DW_FORM_exprloc
;
7947 switch (constant_size (size_of_locs (AT_loc (a
))))
7950 return DW_FORM_block1
;
7952 return DW_FORM_block2
;
7956 case dw_val_class_const
:
7957 return DW_FORM_sdata
;
7958 case dw_val_class_unsigned_const
:
7959 switch (constant_size (AT_unsigned (a
)))
7962 return DW_FORM_data1
;
7964 return DW_FORM_data2
;
7966 /* In DWARF3 DW_AT_data_member_location with
7967 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
7968 constant, so we need to use DW_FORM_udata if we need
7969 a large constant. */
7970 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
7971 return DW_FORM_udata
;
7972 return DW_FORM_data4
;
7974 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
7975 return DW_FORM_udata
;
7976 return DW_FORM_data8
;
7980 case dw_val_class_const_double
:
7981 switch (HOST_BITS_PER_WIDE_INT
)
7984 return DW_FORM_data2
;
7986 return DW_FORM_data4
;
7988 return DW_FORM_data8
;
7991 return DW_FORM_block1
;
7993 case dw_val_class_vec
:
7994 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
7995 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
7998 return DW_FORM_block1
;
8000 return DW_FORM_block2
;
8002 return DW_FORM_block4
;
8006 case dw_val_class_flag
:
8007 if (dwarf_version
>= 4)
8009 /* Currently all add_AT_flag calls pass in 1 as last argument,
8010 so DW_FORM_flag_present can be used. If that ever changes,
8011 we'll need to use DW_FORM_flag and have some optimization
8012 in build_abbrev_table that will change those to
8013 DW_FORM_flag_present if it is set to 1 in all DIEs using
8014 the same abbrev entry. */
8015 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8016 return DW_FORM_flag_present
;
8018 return DW_FORM_flag
;
8019 case dw_val_class_die_ref
:
8020 if (AT_ref_external (a
))
8021 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8024 case dw_val_class_fde_ref
:
8025 return DW_FORM_data
;
8026 case dw_val_class_lbl_id
:
8027 return DW_FORM_addr
;
8028 case dw_val_class_lineptr
:
8029 case dw_val_class_macptr
:
8030 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8031 case dw_val_class_str
:
8032 return AT_string_form (a
);
8033 case dw_val_class_file
:
8034 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8037 return DW_FORM_data1
;
8039 return DW_FORM_data2
;
8041 return DW_FORM_data4
;
8046 case dw_val_class_data8
:
8047 return DW_FORM_data8
;
8054 /* Output the encoding of an attribute value. */
8057 output_value_format (dw_attr_ref a
)
8059 enum dwarf_form form
= value_format (a
);
8061 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8064 /* Output the .debug_abbrev section which defines the DIE abbreviation
8068 output_abbrev_section (void)
8070 unsigned long abbrev_id
;
8072 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8074 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
8078 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8079 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8080 dwarf_tag_name (abbrev
->die_tag
));
8082 if (abbrev
->die_child
!= NULL
)
8083 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8085 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8087 for (ix
= 0; VEC_iterate (dw_attr_node
, abbrev
->die_attr
, ix
, a_attr
);
8090 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8091 dwarf_attr_name (a_attr
->dw_attr
));
8092 output_value_format (a_attr
);
8095 dw2_asm_output_data (1, 0, NULL
);
8096 dw2_asm_output_data (1, 0, NULL
);
8099 /* Terminate the table. */
8100 dw2_asm_output_data (1, 0, NULL
);
8103 /* Output a symbol we can use to refer to this DIE from another CU. */
8106 output_die_symbol (dw_die_ref die
)
8108 char *sym
= die
->die_id
.die_symbol
;
8113 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8114 /* We make these global, not weak; if the target doesn't support
8115 .linkonce, it doesn't support combining the sections, so debugging
8117 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8119 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8122 /* Return a new location list, given the begin and end range, and the
8125 static inline dw_loc_list_ref
8126 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8127 const char *section
)
8129 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
8131 retlist
->begin
= begin
;
8133 retlist
->expr
= expr
;
8134 retlist
->section
= section
;
8139 /* Generate a new internal symbol for this location list node, if it
8140 hasn't got one yet. */
8143 gen_llsym (dw_loc_list_ref list
)
8145 gcc_assert (!list
->ll_symbol
);
8146 list
->ll_symbol
= gen_internal_sym ("LLST");
8149 /* Output the location list given to us. */
8152 output_loc_list (dw_loc_list_ref list_head
)
8154 dw_loc_list_ref curr
= list_head
;
8156 if (list_head
->emitted
)
8158 list_head
->emitted
= true;
8160 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8162 /* Walk the location list, and output each range + expression. */
8163 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8166 /* Don't output an entry that starts and ends at the same address. */
8167 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8169 if (!have_multiple_function_sections
)
8171 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8172 "Location list begin address (%s)",
8173 list_head
->ll_symbol
);
8174 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8175 "Location list end address (%s)",
8176 list_head
->ll_symbol
);
8180 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8181 "Location list begin address (%s)",
8182 list_head
->ll_symbol
);
8183 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8184 "Location list end address (%s)",
8185 list_head
->ll_symbol
);
8187 size
= size_of_locs (curr
->expr
);
8189 /* Output the block length for this list of location operations. */
8190 gcc_assert (size
<= 0xffff);
8191 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8193 output_loc_sequence (curr
->expr
, -1);
8196 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8197 "Location list terminator begin (%s)",
8198 list_head
->ll_symbol
);
8199 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8200 "Location list terminator end (%s)",
8201 list_head
->ll_symbol
);
8204 /* Output a type signature. */
8207 output_signature (const char *sig
, const char *name
)
8211 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8212 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8215 /* Output the DIE and its attributes. Called recursively to generate
8216 the definitions of each child DIE. */
8219 output_die (dw_die_ref die
)
8226 /* If someone in another CU might refer to us, set up a symbol for
8227 them to point to. */
8228 if (! use_debug_types
&& die
->die_id
.die_symbol
)
8229 output_die_symbol (die
);
8231 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8232 (unsigned long)die
->die_offset
,
8233 dwarf_tag_name (die
->die_tag
));
8235 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
8237 const char *name
= dwarf_attr_name (a
->dw_attr
);
8239 switch (AT_class (a
))
8241 case dw_val_class_addr
:
8242 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8245 case dw_val_class_offset
:
8246 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8250 case dw_val_class_range_list
:
8252 char *p
= strchr (ranges_section_label
, '\0');
8254 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
8255 a
->dw_attr_val
.v
.val_offset
);
8256 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8257 debug_ranges_section
, "%s", name
);
8262 case dw_val_class_loc
:
8263 size
= size_of_locs (AT_loc (a
));
8265 /* Output the block length for this list of location operations. */
8266 if (dwarf_version
>= 4)
8267 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8269 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8271 output_loc_sequence (AT_loc (a
), -1);
8274 case dw_val_class_const
:
8275 /* ??? It would be slightly more efficient to use a scheme like is
8276 used for unsigned constants below, but gdb 4.x does not sign
8277 extend. Gdb 5.x does sign extend. */
8278 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8281 case dw_val_class_unsigned_const
:
8283 int csize
= constant_size (AT_unsigned (a
));
8284 if (dwarf_version
== 3
8285 && a
->dw_attr
== DW_AT_data_member_location
8287 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8289 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8293 case dw_val_class_const_double
:
8295 unsigned HOST_WIDE_INT first
, second
;
8297 if (HOST_BITS_PER_WIDE_INT
>= 64)
8298 dw2_asm_output_data (1,
8299 2 * HOST_BITS_PER_WIDE_INT
8300 / HOST_BITS_PER_CHAR
,
8303 if (WORDS_BIG_ENDIAN
)
8305 first
= a
->dw_attr_val
.v
.val_double
.high
;
8306 second
= a
->dw_attr_val
.v
.val_double
.low
;
8310 first
= a
->dw_attr_val
.v
.val_double
.low
;
8311 second
= a
->dw_attr_val
.v
.val_double
.high
;
8314 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8316 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8321 case dw_val_class_vec
:
8323 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8324 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8328 dw2_asm_output_data (constant_size (len
* elt_size
),
8329 len
* elt_size
, "%s", name
);
8330 if (elt_size
> sizeof (HOST_WIDE_INT
))
8335 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8338 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8339 "fp or vector constant word %u", i
);
8343 case dw_val_class_flag
:
8344 if (dwarf_version
>= 4)
8346 /* Currently all add_AT_flag calls pass in 1 as last argument,
8347 so DW_FORM_flag_present can be used. If that ever changes,
8348 we'll need to use DW_FORM_flag and have some optimization
8349 in build_abbrev_table that will change those to
8350 DW_FORM_flag_present if it is set to 1 in all DIEs using
8351 the same abbrev entry. */
8352 gcc_assert (AT_flag (a
) == 1);
8354 fprintf (asm_out_file
, "\t\t\t%s %s\n",
8355 ASM_COMMENT_START
, name
);
8358 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8361 case dw_val_class_loc_list
:
8363 char *sym
= AT_loc_list (a
)->ll_symbol
;
8366 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8371 case dw_val_class_die_ref
:
8372 if (AT_ref_external (a
))
8374 if (use_debug_types
)
8376 comdat_type_node_ref type_node
=
8377 AT_ref (a
)->die_id
.die_type_node
;
8379 gcc_assert (type_node
);
8380 output_signature (type_node
->signature
, name
);
8384 char *sym
= AT_ref (a
)->die_id
.die_symbol
;
8388 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8389 length, whereas in DWARF3 it's always sized as an
8391 if (dwarf_version
== 2)
8392 size
= DWARF2_ADDR_SIZE
;
8394 size
= DWARF_OFFSET_SIZE
;
8395 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
8401 gcc_assert (AT_ref (a
)->die_offset
);
8402 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8407 case dw_val_class_fde_ref
:
8411 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8412 a
->dw_attr_val
.v
.val_fde_index
* 2);
8413 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8418 case dw_val_class_vms_delta
:
8419 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
8420 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
8424 case dw_val_class_lbl_id
:
8425 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8428 case dw_val_class_lineptr
:
8429 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8430 debug_line_section
, "%s", name
);
8433 case dw_val_class_macptr
:
8434 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8435 debug_macinfo_section
, "%s", name
);
8438 case dw_val_class_str
:
8439 if (AT_string_form (a
) == DW_FORM_strp
)
8440 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8441 a
->dw_attr_val
.v
.val_str
->label
,
8443 "%s: \"%s\"", name
, AT_string (a
));
8445 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8448 case dw_val_class_file
:
8450 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8452 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8453 a
->dw_attr_val
.v
.val_file
->filename
);
8457 case dw_val_class_data8
:
8461 for (i
= 0; i
< 8; i
++)
8462 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8463 i
== 0 ? "%s" : NULL
, name
);
8472 FOR_EACH_CHILD (die
, c
, output_die (c
));
8474 /* Add null byte to terminate sibling list. */
8475 if (die
->die_child
!= NULL
)
8476 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8477 (unsigned long) die
->die_offset
);
8480 /* Output the compilation unit that appears at the beginning of the
8481 .debug_info section, and precedes the DIE descriptions. */
8484 output_compilation_unit_header (void)
8486 int ver
= dwarf_version
;
8488 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8489 dw2_asm_output_data (4, 0xffffffff,
8490 "Initial length escape value indicating 64-bit DWARF extension");
8491 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8492 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8493 "Length of Compilation Unit Info");
8494 dw2_asm_output_data (2, ver
, "DWARF version number");
8495 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8496 debug_abbrev_section
,
8497 "Offset Into Abbrev. Section");
8498 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8501 /* Output the compilation unit DIE and its children. */
8504 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8506 const char *secname
;
8509 /* Unless we are outputting main CU, we may throw away empty ones. */
8510 if (!output_if_empty
&& die
->die_child
== NULL
)
8513 /* Even if there are no children of this DIE, we must output the information
8514 about the compilation unit. Otherwise, on an empty translation unit, we
8515 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8516 will then complain when examining the file. First mark all the DIEs in
8517 this CU so we know which get local refs. */
8520 build_abbrev_table (die
);
8522 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8523 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8524 calc_die_sizes (die
);
8526 oldsym
= die
->die_id
.die_symbol
;
8529 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8531 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8533 die
->die_id
.die_symbol
= NULL
;
8534 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8538 switch_to_section (debug_info_section
);
8539 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8540 info_section_emitted
= true;
8543 /* Output debugging information. */
8544 output_compilation_unit_header ();
8547 /* Leave the marks on the main CU, so we can check them in
8552 die
->die_id
.die_symbol
= oldsym
;
8556 /* Output a comdat type unit DIE and its children. */
8559 output_comdat_type_unit (comdat_type_node
*node
)
8561 const char *secname
;
8564 #if defined (OBJECT_FORMAT_ELF)
8568 /* First mark all the DIEs in this CU so we know which get local refs. */
8569 mark_dies (node
->root_die
);
8571 build_abbrev_table (node
->root_die
);
8573 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8574 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
8575 calc_die_sizes (node
->root_die
);
8577 #if defined (OBJECT_FORMAT_ELF)
8578 secname
= ".debug_types";
8579 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8580 sprintf (tmp
, "wt.");
8581 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8582 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8583 comdat_key
= get_identifier (tmp
);
8584 targetm
.asm_out
.named_section (secname
,
8585 SECTION_DEBUG
| SECTION_LINKONCE
,
8588 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8589 sprintf (tmp
, ".gnu.linkonce.wt.");
8590 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8591 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8593 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8596 /* Output debugging information. */
8597 output_compilation_unit_header ();
8598 output_signature (node
->signature
, "Type Signature");
8599 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
8600 "Offset to Type DIE");
8601 output_die (node
->root_die
);
8603 unmark_dies (node
->root_die
);
8606 /* Return the DWARF2/3 pubname associated with a decl. */
8609 dwarf2_name (tree decl
, int scope
)
8611 if (DECL_NAMELESS (decl
))
8613 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
8616 /* Add a new entry to .debug_pubnames if appropriate. */
8619 add_pubname_string (const char *str
, dw_die_ref die
)
8621 if (targetm
.want_debug_pub_sections
)
8626 e
.name
= xstrdup (str
);
8627 VEC_safe_push (pubname_entry
, gc
, pubname_table
, &e
);
8632 add_pubname (tree decl
, dw_die_ref die
)
8634 if (targetm
.want_debug_pub_sections
&& TREE_PUBLIC (decl
))
8636 const char *name
= dwarf2_name (decl
, 1);
8638 add_pubname_string (name
, die
);
8642 /* Add a new entry to .debug_pubtypes if appropriate. */
8645 add_pubtype (tree decl
, dw_die_ref die
)
8649 if (!targetm
.want_debug_pub_sections
)
8653 if ((TREE_PUBLIC (decl
)
8654 || is_cu_die (die
->die_parent
))
8655 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
8660 if (TYPE_NAME (decl
))
8662 if (TREE_CODE (TYPE_NAME (decl
)) == IDENTIFIER_NODE
)
8663 e
.name
= IDENTIFIER_POINTER (TYPE_NAME (decl
));
8664 else if (TREE_CODE (TYPE_NAME (decl
)) == TYPE_DECL
8665 && DECL_NAME (TYPE_NAME (decl
)))
8666 e
.name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl
)));
8668 e
.name
= xstrdup ((const char *) get_AT_string (die
, DW_AT_name
));
8673 e
.name
= dwarf2_name (decl
, 1);
8675 e
.name
= xstrdup (e
.name
);
8678 /* If we don't have a name for the type, there's no point in adding
8680 if (e
.name
&& e
.name
[0] != '\0')
8681 VEC_safe_push (pubname_entry
, gc
, pubtype_table
, &e
);
8685 /* Output the public names table used to speed up access to externally
8686 visible names; or the public types table used to find type definitions. */
8689 output_pubnames (VEC (pubname_entry
, gc
) * names
)
8692 unsigned long pubnames_length
= size_of_pubnames (names
);
8695 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8696 dw2_asm_output_data (4, 0xffffffff,
8697 "Initial length escape value indicating 64-bit DWARF extension");
8698 if (names
== pubname_table
)
8699 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8700 "Length of Public Names Info");
8702 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8703 "Length of Public Type Names Info");
8704 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
8705 dw2_asm_output_data (2, 2, "DWARF Version");
8706 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
8708 "Offset of Compilation Unit Info");
8709 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
8710 "Compilation Unit Length");
8712 FOR_EACH_VEC_ELT (pubname_entry
, names
, i
, pub
)
8714 /* We shouldn't see pubnames for DIEs outside of the main CU. */
8715 if (names
== pubname_table
)
8716 gcc_assert (pub
->die
->die_mark
);
8718 if (names
!= pubtype_table
8719 || pub
->die
->die_offset
!= 0
8720 || !flag_eliminate_unused_debug_types
)
8722 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
8725 dw2_asm_output_nstring (pub
->name
, -1, "external name");
8729 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
8732 /* Output the information that goes into the .debug_aranges table.
8733 Namely, define the beginning and ending address range of the
8734 text section generated for this compilation unit. */
8737 output_aranges (unsigned long aranges_length
)
8741 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8742 dw2_asm_output_data (4, 0xffffffff,
8743 "Initial length escape value indicating 64-bit DWARF extension");
8744 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
8745 "Length of Address Ranges Info");
8746 /* Version number for aranges is still 2, even in DWARF3. */
8747 dw2_asm_output_data (2, 2, "DWARF Version");
8748 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
8750 "Offset of Compilation Unit Info");
8751 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
8752 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8754 /* We need to align to twice the pointer size here. */
8755 if (DWARF_ARANGES_PAD_SIZE
)
8757 /* Pad using a 2 byte words so that padding is correct for any
8759 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8760 2 * DWARF2_ADDR_SIZE
);
8761 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
8762 dw2_asm_output_data (2, 0, NULL
);
8765 /* It is necessary not to output these entries if the sections were
8766 not used; if the sections were not used, the length will be 0 and
8767 the address may end up as 0 if the section is discarded by ld
8768 --gc-sections, leaving an invalid (0, 0) entry that can be
8769 confused with the terminator. */
8770 if (text_section_used
)
8772 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
8773 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
8774 text_section_label
, "Length");
8776 if (cold_text_section_used
)
8778 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
8780 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
8781 cold_text_section_label
, "Length");
8784 if (have_multiple_function_sections
)
8789 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, fde_idx
, fde
)
8791 if (!fde
->in_std_section
)
8793 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
8795 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
8796 fde
->dw_fde_begin
, "Length");
8798 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8800 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
8802 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
8803 fde
->dw_fde_second_begin
, "Length");
8808 /* Output the terminator words. */
8809 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8810 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8813 /* Add a new entry to .debug_ranges. Return the offset at which it
8817 add_ranges_num (int num
)
8819 unsigned int in_use
= ranges_table_in_use
;
8821 if (in_use
== ranges_table_allocated
)
8823 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
8824 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
8825 ranges_table_allocated
);
8826 memset (ranges_table
+ ranges_table_in_use
, 0,
8827 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
8830 ranges_table
[in_use
].num
= num
;
8831 ranges_table_in_use
= in_use
+ 1;
8833 return in_use
* 2 * DWARF2_ADDR_SIZE
;
8836 /* Add a new entry to .debug_ranges corresponding to a block, or a
8837 range terminator if BLOCK is NULL. */
8840 add_ranges (const_tree block
)
8842 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
8845 /* Add a new entry to .debug_ranges corresponding to a pair of
8849 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
8852 unsigned int in_use
= ranges_by_label_in_use
;
8853 unsigned int offset
;
8855 if (in_use
== ranges_by_label_allocated
)
8857 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
8858 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
8860 ranges_by_label_allocated
);
8861 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
8862 RANGES_TABLE_INCREMENT
8863 * sizeof (struct dw_ranges_by_label_struct
));
8866 ranges_by_label
[in_use
].begin
= begin
;
8867 ranges_by_label
[in_use
].end
= end
;
8868 ranges_by_label_in_use
= in_use
+ 1;
8870 offset
= add_ranges_num (-(int)in_use
- 1);
8873 add_AT_range_list (die
, DW_AT_ranges
, offset
);
8879 output_ranges (void)
8882 static const char *const start_fmt
= "Offset %#x";
8883 const char *fmt
= start_fmt
;
8885 for (i
= 0; i
< ranges_table_in_use
; i
++)
8887 int block_num
= ranges_table
[i
].num
;
8891 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
8892 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
8894 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
8895 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
8897 /* If all code is in the text section, then the compilation
8898 unit base address defaults to DW_AT_low_pc, which is the
8899 base of the text section. */
8900 if (!have_multiple_function_sections
)
8902 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
8904 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8905 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
8906 text_section_label
, NULL
);
8909 /* Otherwise, the compilation unit base address is zero,
8910 which allows us to use absolute addresses, and not worry
8911 about whether the target supports cross-section
8915 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
8916 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8917 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
8923 /* Negative block_num stands for an index into ranges_by_label. */
8924 else if (block_num
< 0)
8926 int lab_idx
= - block_num
- 1;
8928 if (!have_multiple_function_sections
)
8932 /* If we ever use add_ranges_by_labels () for a single
8933 function section, all we have to do is to take out
8935 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
8936 ranges_by_label
[lab_idx
].begin
,
8938 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8939 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
8940 ranges_by_label
[lab_idx
].end
,
8941 text_section_label
, NULL
);
8946 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
8947 ranges_by_label
[lab_idx
].begin
,
8948 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8949 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
8950 ranges_by_label
[lab_idx
].end
,
8956 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8957 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8963 /* Data structure containing information about input files. */
8966 const char *path
; /* Complete file name. */
8967 const char *fname
; /* File name part. */
8968 int length
; /* Length of entire string. */
8969 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
8970 int dir_idx
; /* Index in directory table. */
8973 /* Data structure containing information about directories with source
8977 const char *path
; /* Path including directory name. */
8978 int length
; /* Path length. */
8979 int prefix
; /* Index of directory entry which is a prefix. */
8980 int count
; /* Number of files in this directory. */
8981 int dir_idx
; /* Index of directory used as base. */
8984 /* Callback function for file_info comparison. We sort by looking at
8985 the directories in the path. */
8988 file_info_cmp (const void *p1
, const void *p2
)
8990 const struct file_info
*const s1
= (const struct file_info
*) p1
;
8991 const struct file_info
*const s2
= (const struct file_info
*) p2
;
8992 const unsigned char *cp1
;
8993 const unsigned char *cp2
;
8995 /* Take care of file names without directories. We need to make sure that
8996 we return consistent values to qsort since some will get confused if
8997 we return the same value when identical operands are passed in opposite
8998 orders. So if neither has a directory, return 0 and otherwise return
8999 1 or -1 depending on which one has the directory. */
9000 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9001 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9003 cp1
= (const unsigned char *) s1
->path
;
9004 cp2
= (const unsigned char *) s2
->path
;
9010 /* Reached the end of the first path? If so, handle like above. */
9011 if ((cp1
== (const unsigned char *) s1
->fname
)
9012 || (cp2
== (const unsigned char *) s2
->fname
))
9013 return ((cp2
== (const unsigned char *) s2
->fname
)
9014 - (cp1
== (const unsigned char *) s1
->fname
));
9016 /* Character of current path component the same? */
9017 else if (*cp1
!= *cp2
)
9022 struct file_name_acquire_data
9024 struct file_info
*files
;
9029 /* Traversal function for the hash table. */
9032 file_name_acquire (void ** slot
, void *data
)
9034 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
9035 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
9036 struct file_info
*fi
;
9039 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9041 if (! d
->emitted_number
)
9044 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9046 fi
= fnad
->files
+ fnad
->used_files
++;
9048 /* Skip all leading "./". */
9050 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9053 /* Create a new array entry. */
9055 fi
->length
= strlen (f
);
9058 /* Search for the file name part. */
9059 f
= strrchr (f
, DIR_SEPARATOR
);
9060 #if defined (DIR_SEPARATOR_2)
9062 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9066 if (f
== NULL
|| f
< g
)
9072 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9076 /* Output the directory table and the file name table. We try to minimize
9077 the total amount of memory needed. A heuristic is used to avoid large
9078 slowdowns with many input files. */
9081 output_file_names (void)
9083 struct file_name_acquire_data fnad
;
9085 struct file_info
*files
;
9086 struct dir_info
*dirs
;
9094 if (!last_emitted_file
)
9096 dw2_asm_output_data (1, 0, "End directory table");
9097 dw2_asm_output_data (1, 0, "End file name table");
9101 numfiles
= last_emitted_file
->emitted_number
;
9103 /* Allocate the various arrays we need. */
9104 files
= XALLOCAVEC (struct file_info
, numfiles
);
9105 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9108 fnad
.used_files
= 0;
9109 fnad
.max_files
= numfiles
;
9110 htab_traverse (file_table
, file_name_acquire
, &fnad
);
9111 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9113 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9115 /* Find all the different directories used. */
9116 dirs
[0].path
= files
[0].path
;
9117 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9118 dirs
[0].prefix
= -1;
9120 dirs
[0].dir_idx
= 0;
9121 files
[0].dir_idx
= 0;
9124 for (i
= 1; i
< numfiles
; i
++)
9125 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9126 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9127 dirs
[ndirs
- 1].length
) == 0)
9129 /* Same directory as last entry. */
9130 files
[i
].dir_idx
= ndirs
- 1;
9131 ++dirs
[ndirs
- 1].count
;
9137 /* This is a new directory. */
9138 dirs
[ndirs
].path
= files
[i
].path
;
9139 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9140 dirs
[ndirs
].count
= 1;
9141 dirs
[ndirs
].dir_idx
= ndirs
;
9142 files
[i
].dir_idx
= ndirs
;
9144 /* Search for a prefix. */
9145 dirs
[ndirs
].prefix
= -1;
9146 for (j
= 0; j
< ndirs
; j
++)
9147 if (dirs
[j
].length
< dirs
[ndirs
].length
9148 && dirs
[j
].length
> 1
9149 && (dirs
[ndirs
].prefix
== -1
9150 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9151 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9152 dirs
[ndirs
].prefix
= j
;
9157 /* Now to the actual work. We have to find a subset of the directories which
9158 allow expressing the file name using references to the directory table
9159 with the least amount of characters. We do not do an exhaustive search
9160 where we would have to check out every combination of every single
9161 possible prefix. Instead we use a heuristic which provides nearly optimal
9162 results in most cases and never is much off. */
9163 saved
= XALLOCAVEC (int, ndirs
);
9164 savehere
= XALLOCAVEC (int, ndirs
);
9166 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9167 for (i
= 0; i
< ndirs
; i
++)
9172 /* We can always save some space for the current directory. But this
9173 does not mean it will be enough to justify adding the directory. */
9174 savehere
[i
] = dirs
[i
].length
;
9175 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9177 for (j
= i
+ 1; j
< ndirs
; j
++)
9180 if (saved
[j
] < dirs
[i
].length
)
9182 /* Determine whether the dirs[i] path is a prefix of the
9187 while (k
!= -1 && k
!= (int) i
)
9192 /* Yes it is. We can possibly save some memory by
9193 writing the filenames in dirs[j] relative to
9195 savehere
[j
] = dirs
[i
].length
;
9196 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9201 /* Check whether we can save enough to justify adding the dirs[i]
9203 if (total
> dirs
[i
].length
+ 1)
9205 /* It's worthwhile adding. */
9206 for (j
= i
; j
< ndirs
; j
++)
9207 if (savehere
[j
] > 0)
9209 /* Remember how much we saved for this directory so far. */
9210 saved
[j
] = savehere
[j
];
9212 /* Remember the prefix directory. */
9213 dirs
[j
].dir_idx
= i
;
9218 /* Emit the directory name table. */
9219 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9220 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9221 dw2_asm_output_nstring (dirs
[i
].path
,
9223 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
9224 "Directory Entry: %#x", i
+ idx_offset
);
9226 dw2_asm_output_data (1, 0, "End directory table");
9228 /* We have to emit them in the order of emitted_number since that's
9229 used in the debug info generation. To do this efficiently we
9230 generate a back-mapping of the indices first. */
9231 backmap
= XALLOCAVEC (int, numfiles
);
9232 for (i
= 0; i
< numfiles
; i
++)
9233 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9235 /* Now write all the file names. */
9236 for (i
= 0; i
< numfiles
; i
++)
9238 int file_idx
= backmap
[i
];
9239 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9241 #ifdef VMS_DEBUGGING_INFO
9242 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9244 /* Setting these fields can lead to debugger miscomparisons,
9245 but VMS Debug requires them to be set correctly. */
9250 int maxfilelen
= strlen (files
[file_idx
].path
)
9251 + dirs
[dir_idx
].length
9252 + MAX_VMS_VERSION_LEN
+ 1;
9253 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
9255 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
9256 snprintf (filebuf
, maxfilelen
, "%s;%d",
9257 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
9259 dw2_asm_output_nstring
9260 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
9262 /* Include directory index. */
9263 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9265 /* Modification time. */
9266 dw2_asm_output_data_uleb128
9267 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
9271 /* File length in bytes. */
9272 dw2_asm_output_data_uleb128
9273 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
9277 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
9278 "File Entry: %#x", (unsigned) i
+ 1);
9280 /* Include directory index. */
9281 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9283 /* Modification time. */
9284 dw2_asm_output_data_uleb128 (0, NULL
);
9286 /* File length in bytes. */
9287 dw2_asm_output_data_uleb128 (0, NULL
);
9288 #endif /* VMS_DEBUGGING_INFO */
9291 dw2_asm_output_data (1, 0, "End file name table");
9295 /* Output one line number table into the .debug_line section. */
9298 output_one_line_info_table (dw_line_info_table
*table
)
9300 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9301 unsigned int current_line
= 1;
9302 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
9303 dw_line_info_entry
*ent
;
9306 FOR_EACH_VEC_ELT (dw_line_info_entry
, table
->entries
, i
, ent
)
9308 switch (ent
->opcode
)
9310 case LI_set_address
:
9311 /* ??? Unfortunately, we have little choice here currently, and
9312 must always use the most general form. GCC does not know the
9313 address delta itself, so we can't use DW_LNS_advance_pc. Many
9314 ports do have length attributes which will give an upper bound
9315 on the address range. We could perhaps use length attributes
9316 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9317 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
9319 /* This can handle any delta. This takes
9320 4+DWARF2_ADDR_SIZE bytes. */
9321 dw2_asm_output_data (1, 0, "set address %s", line_label
);
9322 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9323 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9324 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9328 if (ent
->val
== current_line
)
9330 /* We still need to start a new row, so output a copy insn. */
9331 dw2_asm_output_data (1, DW_LNS_copy
,
9332 "copy line %u", current_line
);
9336 int line_offset
= ent
->val
- current_line
;
9337 int line_delta
= line_offset
- DWARF_LINE_BASE
;
9339 current_line
= ent
->val
;
9340 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9342 /* This can handle deltas from -10 to 234, using the current
9343 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9344 This takes 1 byte. */
9345 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9346 "line %u", current_line
);
9350 /* This can handle any delta. This takes at least 4 bytes,
9351 depending on the value being encoded. */
9352 dw2_asm_output_data (1, DW_LNS_advance_line
,
9353 "advance to line %u", current_line
);
9354 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9355 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
9361 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
9362 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9366 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
9367 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9370 case LI_negate_stmt
:
9371 current_is_stmt
= !current_is_stmt
;
9372 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
9373 "is_stmt %d", current_is_stmt
);
9376 case LI_set_prologue_end
:
9377 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
9378 "set prologue end");
9381 case LI_set_epilogue_begin
:
9382 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
9383 "set epilogue begin");
9386 case LI_set_discriminator
:
9387 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
9388 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
9389 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
9390 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
9395 /* Emit debug info for the address of the end of the table. */
9396 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
9397 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9398 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9399 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
9401 dw2_asm_output_data (1, 0, "end sequence");
9402 dw2_asm_output_data_uleb128 (1, NULL
);
9403 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
9406 /* Output the source line number correspondence information. This
9407 information goes into the .debug_line section. */
9410 output_line_info (void)
9412 char l1
[20], l2
[20], p1
[20], p2
[20];
9413 int ver
= dwarf_version
;
9414 bool saw_one
= false;
9417 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
9418 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
9419 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
9420 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
9422 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9423 dw2_asm_output_data (4, 0xffffffff,
9424 "Initial length escape value indicating 64-bit DWARF extension");
9425 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
9426 "Length of Source Line Info");
9427 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
9429 dw2_asm_output_data (2, ver
, "DWARF Version");
9430 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
9431 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
9433 /* Define the architecture-dependent minimum instruction length (in bytes).
9434 In this implementation of DWARF, this field is used for information
9435 purposes only. Since GCC generates assembly language, we have no
9436 a priori knowledge of how many instruction bytes are generated for each
9437 source line, and therefore can use only the DW_LNE_set_address and
9438 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
9439 this as '1', which is "correct enough" for all architectures,
9440 and don't let the target override. */
9441 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
9444 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
9445 "Maximum Operations Per Instruction");
9446 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
9447 "Default is_stmt_start flag");
9448 dw2_asm_output_data (1, DWARF_LINE_BASE
,
9449 "Line Base Value (Special Opcodes)");
9450 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
9451 "Line Range Value (Special Opcodes)");
9452 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
9453 "Special Opcode Base");
9455 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
9460 case DW_LNS_advance_pc
:
9461 case DW_LNS_advance_line
:
9462 case DW_LNS_set_file
:
9463 case DW_LNS_set_column
:
9464 case DW_LNS_fixed_advance_pc
:
9465 case DW_LNS_set_isa
:
9473 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
9477 /* Write out the information about the files we use. */
9478 output_file_names ();
9479 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
9481 if (separate_line_info
)
9483 dw_line_info_table
*table
;
9486 FOR_EACH_VEC_ELT (dw_line_info_table_p
, separate_line_info
, i
, table
)
9489 output_one_line_info_table (table
);
9493 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
9495 output_one_line_info_table (cold_text_section_line_info
);
9499 /* ??? Some Darwin linkers crash on a .debug_line section with no
9500 sequences. Further, merely a DW_LNE_end_sequence entry is not
9501 sufficient -- the address column must also be initialized.
9502 Make sure to output at least one set_address/end_sequence pair,
9503 choosing .text since that section is always present. */
9504 if (text_section_line_info
->in_use
|| !saw_one
)
9505 output_one_line_info_table (text_section_line_info
);
9507 /* Output the marker for the end of the line number info. */
9508 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9511 /* Given a pointer to a tree node for some base type, return a pointer to
9512 a DIE that describes the given type.
9514 This routine must only be called for GCC type nodes that correspond to
9515 Dwarf base (fundamental) types. */
9518 base_type_die (tree type
)
9520 dw_die_ref base_type_result
;
9521 enum dwarf_type encoding
;
9523 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
9526 /* If this is a subtype that should not be emitted as a subrange type,
9527 use the base type. See subrange_type_for_debug_p. */
9528 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
9529 type
= TREE_TYPE (type
);
9531 switch (TREE_CODE (type
))
9534 if ((dwarf_version
>= 4 || !dwarf_strict
)
9536 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9537 && DECL_IS_BUILTIN (TYPE_NAME (type
))
9538 && DECL_NAME (TYPE_NAME (type
)))
9540 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
9541 if (strcmp (name
, "char16_t") == 0
9542 || strcmp (name
, "char32_t") == 0)
9544 encoding
= DW_ATE_UTF
;
9548 if (TYPE_STRING_FLAG (type
))
9550 if (TYPE_UNSIGNED (type
))
9551 encoding
= DW_ATE_unsigned_char
;
9553 encoding
= DW_ATE_signed_char
;
9555 else if (TYPE_UNSIGNED (type
))
9556 encoding
= DW_ATE_unsigned
;
9558 encoding
= DW_ATE_signed
;
9562 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
9564 if (dwarf_version
>= 3 || !dwarf_strict
)
9565 encoding
= DW_ATE_decimal_float
;
9567 encoding
= DW_ATE_lo_user
;
9570 encoding
= DW_ATE_float
;
9573 case FIXED_POINT_TYPE
:
9574 if (!(dwarf_version
>= 3 || !dwarf_strict
))
9575 encoding
= DW_ATE_lo_user
;
9576 else if (TYPE_UNSIGNED (type
))
9577 encoding
= DW_ATE_unsigned_fixed
;
9579 encoding
= DW_ATE_signed_fixed
;
9582 /* Dwarf2 doesn't know anything about complex ints, so use
9583 a user defined type for it. */
9585 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
9586 encoding
= DW_ATE_complex_float
;
9588 encoding
= DW_ATE_lo_user
;
9592 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9593 encoding
= DW_ATE_boolean
;
9597 /* No other TREE_CODEs are Dwarf fundamental types. */
9601 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
9603 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
9604 int_size_in_bytes (type
));
9605 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
9607 return base_type_result
;
9610 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9611 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9614 is_base_type (tree type
)
9616 switch (TREE_CODE (type
))
9622 case FIXED_POINT_TYPE
:
9630 case QUAL_UNION_TYPE
:
9635 case REFERENCE_TYPE
:
9649 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9650 node, return the size in bits for the type if it is a constant, or else
9651 return the alignment for the type if the type's size is not constant, or
9652 else return BITS_PER_WORD if the type actually turns out to be an
9655 static inline unsigned HOST_WIDE_INT
9656 simple_type_size_in_bits (const_tree type
)
9658 if (TREE_CODE (type
) == ERROR_MARK
)
9659 return BITS_PER_WORD
;
9660 else if (TYPE_SIZE (type
) == NULL_TREE
)
9662 else if (host_integerp (TYPE_SIZE (type
), 1))
9663 return tree_low_cst (TYPE_SIZE (type
), 1);
9665 return TYPE_ALIGN (type
);
9668 /* Similarly, but return a double_int instead of UHWI. */
9670 static inline double_int
9671 double_int_type_size_in_bits (const_tree type
)
9673 if (TREE_CODE (type
) == ERROR_MARK
)
9674 return uhwi_to_double_int (BITS_PER_WORD
);
9675 else if (TYPE_SIZE (type
) == NULL_TREE
)
9676 return double_int_zero
;
9677 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
9678 return tree_to_double_int (TYPE_SIZE (type
));
9680 return uhwi_to_double_int (TYPE_ALIGN (type
));
9683 /* Given a pointer to a tree node for a subrange type, return a pointer
9684 to a DIE that describes the given type. */
9687 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
9689 dw_die_ref subrange_die
;
9690 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
9692 if (context_die
== NULL
)
9693 context_die
= comp_unit_die ();
9695 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
9697 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
9699 /* The size of the subrange type and its base type do not match,
9700 so we need to generate a size attribute for the subrange type. */
9701 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
9705 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
9707 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
9709 return subrange_die
;
9712 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9713 entry that chains various modifiers in front of the given type. */
9716 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
9717 dw_die_ref context_die
)
9719 enum tree_code code
= TREE_CODE (type
);
9720 dw_die_ref mod_type_die
;
9721 dw_die_ref sub_die
= NULL
;
9722 tree item_type
= NULL
;
9723 tree qualified_type
;
9724 tree name
, low
, high
;
9726 if (code
== ERROR_MARK
)
9729 /* See if we already have the appropriately qualified variant of
9732 = get_qualified_type (type
,
9733 ((is_const_type
? TYPE_QUAL_CONST
: 0)
9734 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
9736 if (qualified_type
== sizetype
9737 && TYPE_NAME (qualified_type
)
9738 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
9740 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
9742 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
9743 && TYPE_PRECISION (t
)
9744 == TYPE_PRECISION (qualified_type
)
9745 && TYPE_UNSIGNED (t
)
9746 == TYPE_UNSIGNED (qualified_type
));
9750 /* If we do, then we can just use its DIE, if it exists. */
9753 mod_type_die
= lookup_type_die (qualified_type
);
9755 return mod_type_die
;
9758 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
9760 /* Handle C typedef types. */
9761 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
9762 && !DECL_ARTIFICIAL (name
))
9764 tree dtype
= TREE_TYPE (name
);
9766 if (qualified_type
== dtype
)
9768 /* For a named type, use the typedef. */
9769 gen_type_die (qualified_type
, context_die
);
9770 return lookup_type_die (qualified_type
);
9772 else if (is_const_type
< TYPE_READONLY (dtype
)
9773 || is_volatile_type
< TYPE_VOLATILE (dtype
)
9774 || (is_const_type
<= TYPE_READONLY (dtype
)
9775 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
9776 && DECL_ORIGINAL_TYPE (name
) != type
))
9777 /* cv-unqualified version of named type. Just use the unnamed
9778 type to which it refers. */
9779 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
9780 is_const_type
, is_volatile_type
,
9782 /* Else cv-qualified version of named type; fall through. */
9786 /* If both is_const_type and is_volatile_type, prefer the path
9787 which leads to a qualified type. */
9788 && (!is_volatile_type
9789 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
9790 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
9792 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die (), type
);
9793 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
9795 else if (is_volatile_type
)
9797 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die (), type
);
9798 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
9800 else if (code
== POINTER_TYPE
)
9802 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die (), type
);
9803 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
9804 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
9805 item_type
= TREE_TYPE (type
);
9806 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
9807 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
9808 TYPE_ADDR_SPACE (item_type
));
9810 else if (code
== REFERENCE_TYPE
)
9812 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
9813 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, comp_unit_die (),
9816 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die (), type
);
9817 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
9818 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
9819 item_type
= TREE_TYPE (type
);
9820 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
9821 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
9822 TYPE_ADDR_SPACE (item_type
));
9824 else if (code
== INTEGER_TYPE
9825 && TREE_TYPE (type
) != NULL_TREE
9826 && subrange_type_for_debug_p (type
, &low
, &high
))
9828 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
9829 item_type
= TREE_TYPE (type
);
9831 else if (is_base_type (type
))
9832 mod_type_die
= base_type_die (type
);
9835 gen_type_die (type
, context_die
);
9837 /* We have to get the type_main_variant here (and pass that to the
9838 `lookup_type_die' routine) because the ..._TYPE node we have
9839 might simply be a *copy* of some original type node (where the
9840 copy was created to help us keep track of typedef names) and
9841 that copy might have a different TYPE_UID from the original
9843 if (TREE_CODE (type
) != VECTOR_TYPE
)
9844 return lookup_type_die (type_main_variant (type
));
9846 /* Vectors have the debugging information in the type,
9847 not the main variant. */
9848 return lookup_type_die (type
);
9851 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9852 don't output a DW_TAG_typedef, since there isn't one in the
9853 user's program; just attach a DW_AT_name to the type.
9854 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
9855 if the base type already has the same name. */
9857 && ((TREE_CODE (name
) != TYPE_DECL
9858 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
9859 || (!is_const_type
&& !is_volatile_type
)))
9860 || (TREE_CODE (name
) == TYPE_DECL
9861 && TREE_TYPE (name
) == qualified_type
9862 && DECL_NAME (name
))))
9864 if (TREE_CODE (name
) == TYPE_DECL
)
9865 /* Could just call add_name_and_src_coords_attributes here,
9866 but since this is a builtin type it doesn't have any
9867 useful source coordinates anyway. */
9868 name
= DECL_NAME (name
);
9869 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
9870 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
9871 if (TYPE_ARTIFICIAL (type
))
9872 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
9874 /* This probably indicates a bug. */
9875 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
9876 add_name_attribute (mod_type_die
, "__unknown__");
9879 equate_type_number_to_die (qualified_type
, mod_type_die
);
9882 /* We must do this after the equate_type_number_to_die call, in case
9883 this is a recursive type. This ensures that the modified_type_die
9884 recursion will terminate even if the type is recursive. Recursive
9885 types are possible in Ada. */
9886 sub_die
= modified_type_die (item_type
,
9887 TYPE_READONLY (item_type
),
9888 TYPE_VOLATILE (item_type
),
9891 if (sub_die
!= NULL
)
9892 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
9894 return mod_type_die
;
9897 /* Generate DIEs for the generic parameters of T.
9898 T must be either a generic type or a generic function.
9899 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
9902 gen_generic_params_dies (tree t
)
9906 dw_die_ref die
= NULL
;
9908 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
9912 die
= lookup_type_die (t
);
9913 else if (DECL_P (t
))
9914 die
= lookup_decl_die (t
);
9918 parms
= lang_hooks
.get_innermost_generic_parms (t
);
9920 /* T has no generic parameter. It means T is neither a generic type
9921 or function. End of story. */
9924 parms_num
= TREE_VEC_LENGTH (parms
);
9925 args
= lang_hooks
.get_innermost_generic_args (t
);
9926 for (i
= 0; i
< parms_num
; i
++)
9928 tree parm
, arg
, arg_pack_elems
;
9930 parm
= TREE_VEC_ELT (parms
, i
);
9931 arg
= TREE_VEC_ELT (args
, i
);
9932 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
9933 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
9935 if (parm
&& TREE_VALUE (parm
) && arg
)
9937 /* If PARM represents a template parameter pack,
9938 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
9939 by DW_TAG_template_*_parameter DIEs for the argument
9940 pack elements of ARG. Note that ARG would then be
9941 an argument pack. */
9943 template_parameter_pack_die (TREE_VALUE (parm
),
9947 generic_parameter_die (TREE_VALUE (parm
), arg
,
9948 true /* Emit DW_AT_name */, die
);
9953 /* Create and return a DIE for PARM which should be
9954 the representation of a generic type parameter.
9955 For instance, in the C++ front end, PARM would be a template parameter.
9956 ARG is the argument to PARM.
9957 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
9959 PARENT_DIE is the parent DIE which the new created DIE should be added to,
9963 generic_parameter_die (tree parm
, tree arg
,
9965 dw_die_ref parent_die
)
9967 dw_die_ref tmpl_die
= NULL
;
9968 const char *name
= NULL
;
9970 if (!parm
|| !DECL_NAME (parm
) || !arg
)
9973 /* We support non-type generic parameters and arguments,
9974 type generic parameters and arguments, as well as
9975 generic generic parameters (a.k.a. template template parameters in C++)
9977 if (TREE_CODE (parm
) == PARM_DECL
)
9978 /* PARM is a nontype generic parameter */
9979 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
9980 else if (TREE_CODE (parm
) == TYPE_DECL
)
9981 /* PARM is a type generic parameter. */
9982 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
9983 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
9984 /* PARM is a generic generic parameter.
9985 Its DIE is a GNU extension. It shall have a
9986 DW_AT_name attribute to represent the name of the template template
9987 parameter, and a DW_AT_GNU_template_name attribute to represent the
9988 name of the template template argument. */
9989 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
9998 /* If PARM is a generic parameter pack, it means we are
9999 emitting debug info for a template argument pack element.
10000 In other terms, ARG is a template argument pack element.
10001 In that case, we don't emit any DW_AT_name attribute for
10005 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
10007 add_AT_string (tmpl_die
, DW_AT_name
, name
);
10010 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10012 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10013 TMPL_DIE should have a child DW_AT_type attribute that is set
10014 to the type of the argument to PARM, which is ARG.
10015 If PARM is a type generic parameter, TMPL_DIE should have a
10016 child DW_AT_type that is set to ARG. */
10017 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
10018 add_type_attribute (tmpl_die
, tmpl_type
, 0,
10019 TREE_THIS_VOLATILE (tmpl_type
),
10024 /* So TMPL_DIE is a DIE representing a
10025 a generic generic template parameter, a.k.a template template
10026 parameter in C++ and arg is a template. */
10028 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10029 to the name of the argument. */
10030 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
10032 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
10035 if (TREE_CODE (parm
) == PARM_DECL
)
10036 /* So PARM is a non-type generic parameter.
10037 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10038 attribute of TMPL_DIE which value represents the value
10040 We must be careful here:
10041 The value of ARG might reference some function decls.
10042 We might currently be emitting debug info for a generic
10043 type and types are emitted before function decls, we don't
10044 know if the function decls referenced by ARG will actually be
10045 emitted after cgraph computations.
10046 So must defer the generation of the DW_AT_const_value to
10047 after cgraph is ready. */
10048 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
10054 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10055 PARM_PACK must be a template parameter pack. The returned DIE
10056 will be child DIE of PARENT_DIE. */
10059 template_parameter_pack_die (tree parm_pack
,
10060 tree parm_pack_args
,
10061 dw_die_ref parent_die
)
10066 gcc_assert (parent_die
&& parm_pack
);
10068 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
10069 add_name_and_src_coords_attributes (die
, parm_pack
);
10070 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
10071 generic_parameter_die (parm_pack
,
10072 TREE_VEC_ELT (parm_pack_args
, j
),
10073 false /* Don't emit DW_AT_name */,
10078 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10079 an enumerated type. */
10082 type_is_enum (const_tree type
)
10084 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10087 /* Return the DBX register number described by a given RTL node. */
10089 static unsigned int
10090 dbx_reg_number (const_rtx rtl
)
10092 unsigned regno
= REGNO (rtl
);
10094 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10096 #ifdef LEAF_REG_REMAP
10097 if (current_function_uses_only_leaf_regs
)
10099 int leaf_reg
= LEAF_REG_REMAP (regno
);
10100 if (leaf_reg
!= -1)
10101 regno
= (unsigned) leaf_reg
;
10105 return DBX_REGISTER_NUMBER (regno
);
10108 /* Optionally add a DW_OP_piece term to a location description expression.
10109 DW_OP_piece is only added if the location description expression already
10110 doesn't end with DW_OP_piece. */
10113 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10115 dw_loc_descr_ref loc
;
10117 if (*list_head
!= NULL
)
10119 /* Find the end of the chain. */
10120 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10123 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10124 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10128 /* Return a location descriptor that designates a machine register or
10129 zero if there is none. */
10131 static dw_loc_descr_ref
10132 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10136 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10139 /* We only use "frame base" when we're sure we're talking about the
10140 post-prologue local stack frame. We do this by *not* running
10141 register elimination until this point, and recognizing the special
10142 argument pointer and soft frame pointer rtx's.
10143 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10144 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
10145 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
10147 dw_loc_descr_ref result
= NULL
;
10149 if (dwarf_version
>= 4 || !dwarf_strict
)
10151 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
10154 add_loc_descr (&result
,
10155 new_loc_descr (DW_OP_stack_value
, 0, 0));
10160 regs
= targetm
.dwarf_register_span (rtl
);
10162 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
10163 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
10165 return one_reg_loc_descriptor (dbx_reg_number (rtl
), initialized
);
10168 /* Return a location descriptor that designates a machine register for
10169 a given hard register number. */
10171 static dw_loc_descr_ref
10172 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10174 dw_loc_descr_ref reg_loc_descr
;
10178 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10180 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10182 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10183 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10185 return reg_loc_descr
;
10188 /* Given an RTL of a register, return a location descriptor that
10189 designates a value that spans more than one register. */
10191 static dw_loc_descr_ref
10192 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10193 enum var_init_status initialized
)
10195 int nregs
, size
, i
;
10197 dw_loc_descr_ref loc_result
= NULL
;
10200 #ifdef LEAF_REG_REMAP
10201 if (current_function_uses_only_leaf_regs
)
10203 int leaf_reg
= LEAF_REG_REMAP (reg
);
10204 if (leaf_reg
!= -1)
10205 reg
= (unsigned) leaf_reg
;
10208 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
10209 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
10211 /* Simple, contiguous registers. */
10212 if (regs
== NULL_RTX
)
10214 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
10219 dw_loc_descr_ref t
;
10221 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
10222 VAR_INIT_STATUS_INITIALIZED
);
10223 add_loc_descr (&loc_result
, t
);
10224 add_loc_descr_op_piece (&loc_result
, size
);
10230 /* Now onto stupid register sets in non contiguous locations. */
10232 gcc_assert (GET_CODE (regs
) == PARALLEL
);
10234 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10237 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
10239 dw_loc_descr_ref t
;
10241 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
10242 VAR_INIT_STATUS_INITIALIZED
);
10243 add_loc_descr (&loc_result
, t
);
10244 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10245 add_loc_descr_op_piece (&loc_result
, size
);
10248 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10249 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10253 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
10255 /* Return a location descriptor that designates a constant i,
10256 as a compound operation from constant (i >> shift), constant shift
10259 static dw_loc_descr_ref
10260 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10262 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
10263 add_loc_descr (&ret
, int_loc_descriptor (shift
));
10264 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
10268 /* Return a location descriptor that designates a constant. */
10270 static dw_loc_descr_ref
10271 int_loc_descriptor (HOST_WIDE_INT i
)
10273 enum dwarf_location_atom op
;
10275 /* Pick the smallest representation of a constant, rather than just
10276 defaulting to the LEB encoding. */
10279 int clz
= clz_hwi (i
);
10280 int ctz
= ctz_hwi (i
);
10282 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
10283 else if (i
<= 0xff)
10284 op
= DW_OP_const1u
;
10285 else if (i
<= 0xffff)
10286 op
= DW_OP_const2u
;
10287 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10288 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10289 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10290 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
10291 while DW_OP_const4u is 5 bytes. */
10292 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
10293 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10294 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10295 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10296 while DW_OP_const4u is 5 bytes. */
10297 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10298 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10299 op
= DW_OP_const4u
;
10300 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10301 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10302 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10303 while DW_OP_constu of constant >= 0x100000000 takes at least
10305 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10306 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10307 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
10308 >= HOST_BITS_PER_WIDE_INT
)
10309 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10310 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10311 while DW_OP_constu takes in this case at least 6 bytes. */
10312 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
10313 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10314 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10315 && size_of_uleb128 (i
) > 6)
10316 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10317 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
10324 op
= DW_OP_const1s
;
10325 else if (i
>= -0x8000)
10326 op
= DW_OP_const2s
;
10327 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10329 if (size_of_int_loc_descriptor (i
) < 5)
10331 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10332 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10335 op
= DW_OP_const4s
;
10339 if (size_of_int_loc_descriptor (i
)
10340 < (unsigned long) 1 + size_of_sleb128 (i
))
10342 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10343 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10350 return new_loc_descr (op
, i
, 0);
10353 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10354 without actually allocating it. */
10356 static unsigned long
10357 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10359 return size_of_int_loc_descriptor (i
>> shift
)
10360 + size_of_int_loc_descriptor (shift
)
10364 /* Return size_of_locs (int_loc_descriptor (i)) without
10365 actually allocating it. */
10367 static unsigned long
10368 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
10377 else if (i
<= 0xff)
10379 else if (i
<= 0xffff)
10383 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10384 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10385 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10387 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10388 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10389 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10391 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10393 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
10394 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10395 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10396 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10398 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10399 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
10400 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10402 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10403 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10405 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10414 else if (i
>= -0x8000)
10416 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10418 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10420 s
= size_of_int_loc_descriptor (-i
) + 1;
10428 unsigned long r
= 1 + size_of_sleb128 (i
);
10429 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10431 s
= size_of_int_loc_descriptor (-i
) + 1;
10440 /* Return loc description representing "address" of integer value.
10441 This can appear only as toplevel expression. */
10443 static dw_loc_descr_ref
10444 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
10447 dw_loc_descr_ref loc_result
= NULL
;
10449 if (!(dwarf_version
>= 4 || !dwarf_strict
))
10452 litsize
= size_of_int_loc_descriptor (i
);
10453 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10454 is more compact. For DW_OP_stack_value we need:
10455 litsize + 1 (DW_OP_stack_value)
10456 and for DW_OP_implicit_value:
10457 1 (DW_OP_implicit_value) + 1 (length) + size. */
10458 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
10460 loc_result
= int_loc_descriptor (i
);
10461 add_loc_descr (&loc_result
,
10462 new_loc_descr (DW_OP_stack_value
, 0, 0));
10466 loc_result
= new_loc_descr (DW_OP_implicit_value
,
10468 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
10469 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
10473 /* Return a location descriptor that designates a base+offset location. */
10475 static dw_loc_descr_ref
10476 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
10477 enum var_init_status initialized
)
10479 unsigned int regno
;
10480 dw_loc_descr_ref result
;
10481 dw_fde_ref fde
= cfun
->fde
;
10483 /* We only use "frame base" when we're sure we're talking about the
10484 post-prologue local stack frame. We do this by *not* running
10485 register elimination until this point, and recognizing the special
10486 argument pointer and soft frame pointer rtx's. */
10487 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
10489 rtx elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
10493 if (GET_CODE (elim
) == PLUS
)
10495 offset
+= INTVAL (XEXP (elim
, 1));
10496 elim
= XEXP (elim
, 0);
10498 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10499 && (elim
== hard_frame_pointer_rtx
10500 || elim
== stack_pointer_rtx
))
10501 || elim
== (frame_pointer_needed
10502 ? hard_frame_pointer_rtx
10503 : stack_pointer_rtx
));
10505 /* If drap register is used to align stack, use frame
10506 pointer + offset to access stack variables. If stack
10507 is aligned without drap, use stack pointer + offset to
10508 access stack variables. */
10509 if (crtl
->stack_realign_tried
10510 && reg
== frame_pointer_rtx
)
10513 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
10514 ? HARD_FRAME_POINTER_REGNUM
10516 return new_reg_loc_descr (base_reg
, offset
);
10519 gcc_assert (frame_pointer_fb_offset_valid
);
10520 offset
+= frame_pointer_fb_offset
;
10521 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10525 regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
10527 if (!optimize
&& fde
10528 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
10530 /* Use cfa+offset to represent the location of arguments passed
10531 on the stack when drap is used to align stack.
10532 Only do this when not optimizing, for optimized code var-tracking
10533 is supposed to track where the arguments live and the register
10534 used as vdrap or drap in some spot might be used for something
10535 else in other part of the routine. */
10536 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10540 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
10543 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
10545 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10546 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10551 /* Return true if this RTL expression describes a base+offset calculation. */
10554 is_based_loc (const_rtx rtl
)
10556 return (GET_CODE (rtl
) == PLUS
10557 && ((REG_P (XEXP (rtl
, 0))
10558 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
10559 && CONST_INT_P (XEXP (rtl
, 1)))));
10562 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10565 static dw_loc_descr_ref
10566 tls_mem_loc_descriptor (rtx mem
)
10569 dw_loc_descr_ref loc_result
;
10571 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
10574 base
= get_base_address (MEM_EXPR (mem
));
10576 || TREE_CODE (base
) != VAR_DECL
10577 || !DECL_THREAD_LOCAL_P (base
))
10580 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
10581 if (loc_result
== NULL
)
10584 if (MEM_OFFSET (mem
))
10585 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
10590 /* Output debug info about reason why we failed to expand expression as dwarf
10594 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
10596 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
10598 fprintf (dump_file
, "Failed to expand as dwarf: ");
10600 print_generic_expr (dump_file
, expr
, dump_flags
);
10603 fprintf (dump_file
, "\n");
10604 print_rtl (dump_file
, rtl
);
10606 fprintf (dump_file
, "\nReason: %s\n", reason
);
10610 /* Helper function for const_ok_for_output, called either directly
10611 or via for_each_rtx. */
10614 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
10618 if (GET_CODE (rtl
) == UNSPEC
)
10620 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
10621 we can't express it in the debug info. */
10622 #ifdef ENABLE_CHECKING
10623 /* Don't complain about TLS UNSPECs, those are just too hard to
10625 if (XVECLEN (rtl
, 0) != 1
10626 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
10627 || SYMBOL_REF_DECL (XVECEXP (rtl
, 0, 0)) == NULL
10628 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl
, 0, 0))) != VAR_DECL
10629 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl
, 0, 0))))
10630 inform (current_function_decl
10631 ? DECL_SOURCE_LOCATION (current_function_decl
)
10632 : UNKNOWN_LOCATION
,
10633 #if NUM_UNSPEC_VALUES > 0
10634 "non-delegitimized UNSPEC %s (%d) found in variable location",
10635 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
10636 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
10639 "non-delegitimized UNSPEC %d found in variable location",
10643 expansion_failed (NULL_TREE
, rtl
,
10644 "UNSPEC hasn't been delegitimized.\n");
10648 if (GET_CODE (rtl
) != SYMBOL_REF
)
10651 if (CONSTANT_POOL_ADDRESS_P (rtl
))
10654 get_pool_constant_mark (rtl
, &marked
);
10655 /* If all references to this pool constant were optimized away,
10656 it was not output and thus we can't represent it. */
10659 expansion_failed (NULL_TREE
, rtl
,
10660 "Constant was removed from constant pool.\n");
10665 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
10668 /* Avoid references to external symbols in debug info, on several targets
10669 the linker might even refuse to link when linking a shared library,
10670 and in many other cases the relocations for .debug_info/.debug_loc are
10671 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
10672 to be defined within the same shared library or executable are fine. */
10673 if (SYMBOL_REF_EXTERNAL_P (rtl
))
10675 tree decl
= SYMBOL_REF_DECL (rtl
);
10677 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
10679 expansion_failed (NULL_TREE
, rtl
,
10680 "Symbol not defined in current TU.\n");
10688 /* Return true if constant RTL can be emitted in DW_OP_addr or
10689 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
10690 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
10693 const_ok_for_output (rtx rtl
)
10695 if (GET_CODE (rtl
) == SYMBOL_REF
)
10696 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
10698 if (GET_CODE (rtl
) == CONST
)
10699 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
10704 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
10705 if possible, NULL otherwise. */
10708 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
10710 dw_die_ref type_die
;
10711 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
10715 switch (TREE_CODE (type
))
10723 type_die
= lookup_type_die (type
);
10725 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
10726 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
10731 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
10732 type matching MODE, or, if MODE is narrower than or as wide as
10733 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
10736 static dw_loc_descr_ref
10737 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
10739 enum machine_mode outer_mode
= mode
;
10740 dw_die_ref type_die
;
10741 dw_loc_descr_ref cvt
;
10743 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
10745 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
10748 type_die
= base_type_for_mode (outer_mode
, 1);
10749 if (type_die
== NULL
)
10751 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10752 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10753 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10754 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10755 add_loc_descr (&op
, cvt
);
10759 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
10761 static dw_loc_descr_ref
10762 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
10763 dw_loc_descr_ref op1
)
10765 dw_loc_descr_ref ret
= op0
;
10766 add_loc_descr (&ret
, op1
);
10767 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
10768 if (STORE_FLAG_VALUE
!= 1)
10770 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
10771 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
10776 /* Return location descriptor for signed comparison OP RTL. */
10778 static dw_loc_descr_ref
10779 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
10780 enum machine_mode mem_mode
)
10782 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
10783 dw_loc_descr_ref op0
, op1
;
10786 if (op_mode
== VOIDmode
)
10787 op_mode
= GET_MODE (XEXP (rtl
, 1));
10788 if (op_mode
== VOIDmode
)
10792 && (GET_MODE_CLASS (op_mode
) != MODE_INT
10793 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
10796 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
10797 VAR_INIT_STATUS_INITIALIZED
);
10798 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
10799 VAR_INIT_STATUS_INITIALIZED
);
10801 if (op0
== NULL
|| op1
== NULL
)
10804 if (GET_MODE_CLASS (op_mode
) != MODE_INT
10805 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
10806 return compare_loc_descriptor (op
, op0
, op1
);
10808 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
10810 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
10811 dw_loc_descr_ref cvt
;
10813 if (type_die
== NULL
)
10815 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10816 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10817 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10818 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10819 add_loc_descr (&op0
, cvt
);
10820 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10821 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10822 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10823 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10824 add_loc_descr (&op1
, cvt
);
10825 return compare_loc_descriptor (op
, op0
, op1
);
10828 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
10829 /* For eq/ne, if the operands are known to be zero-extended,
10830 there is no need to do the fancy shifting up. */
10831 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
10833 dw_loc_descr_ref last0
, last1
;
10834 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
10836 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
10838 /* deref_size zero extends, and for constants we can check
10839 whether they are zero extended or not. */
10840 if (((last0
->dw_loc_opc
== DW_OP_deref_size
10841 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
10842 || (CONST_INT_P (XEXP (rtl
, 0))
10843 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
10844 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
10845 && ((last1
->dw_loc_opc
== DW_OP_deref_size
10846 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
10847 || (CONST_INT_P (XEXP (rtl
, 1))
10848 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
10849 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
10850 return compare_loc_descriptor (op
, op0
, op1
);
10852 /* EQ/NE comparison against constant in narrower type than
10853 DWARF2_ADDR_SIZE can be performed either as
10854 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
10857 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
10858 DW_OP_{eq,ne}. Pick whatever is shorter. */
10859 if (CONST_INT_P (XEXP (rtl
, 1))
10860 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
10861 && (size_of_int_loc_descriptor (shift
) + 1
10862 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
10863 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
10864 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
10865 & GET_MODE_MASK (op_mode
))))
10867 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
10868 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
10869 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
10870 & GET_MODE_MASK (op_mode
));
10871 return compare_loc_descriptor (op
, op0
, op1
);
10874 add_loc_descr (&op0
, int_loc_descriptor (shift
));
10875 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
10876 if (CONST_INT_P (XEXP (rtl
, 1)))
10877 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
10880 add_loc_descr (&op1
, int_loc_descriptor (shift
));
10881 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
10883 return compare_loc_descriptor (op
, op0
, op1
);
10886 /* Return location descriptor for unsigned comparison OP RTL. */
10888 static dw_loc_descr_ref
10889 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
10890 enum machine_mode mem_mode
)
10892 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
10893 dw_loc_descr_ref op0
, op1
;
10895 if (op_mode
== VOIDmode
)
10896 op_mode
= GET_MODE (XEXP (rtl
, 1));
10897 if (op_mode
== VOIDmode
)
10899 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
10902 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
10905 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
10906 VAR_INIT_STATUS_INITIALIZED
);
10907 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
10908 VAR_INIT_STATUS_INITIALIZED
);
10910 if (op0
== NULL
|| op1
== NULL
)
10913 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
10915 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
10916 dw_loc_descr_ref last0
, last1
;
10917 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
10919 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
10921 if (CONST_INT_P (XEXP (rtl
, 0)))
10922 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
10923 /* deref_size zero extends, so no need to mask it again. */
10924 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
10925 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
10927 add_loc_descr (&op0
, int_loc_descriptor (mask
));
10928 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
10930 if (CONST_INT_P (XEXP (rtl
, 1)))
10931 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
10932 /* deref_size zero extends, so no need to mask it again. */
10933 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
10934 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
10936 add_loc_descr (&op1
, int_loc_descriptor (mask
));
10937 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
10940 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
10942 HOST_WIDE_INT bias
= 1;
10943 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
10944 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
10945 if (CONST_INT_P (XEXP (rtl
, 1)))
10946 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
10947 + INTVAL (XEXP (rtl
, 1)));
10949 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
10952 return compare_loc_descriptor (op
, op0
, op1
);
10955 /* Return location descriptor for {U,S}{MIN,MAX}. */
10957 static dw_loc_descr_ref
10958 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
10959 enum machine_mode mem_mode
)
10961 enum dwarf_location_atom op
;
10962 dw_loc_descr_ref op0
, op1
, ret
;
10963 dw_loc_descr_ref bra_node
, drop_node
;
10966 && (GET_MODE_CLASS (mode
) != MODE_INT
10967 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
10970 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
10971 VAR_INIT_STATUS_INITIALIZED
);
10972 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
10973 VAR_INIT_STATUS_INITIALIZED
);
10975 if (op0
== NULL
|| op1
== NULL
)
10978 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
10979 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
10980 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
10981 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
10983 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
10985 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
10986 add_loc_descr (&op0
, int_loc_descriptor (mask
));
10987 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
10988 add_loc_descr (&op1
, int_loc_descriptor (mask
));
10989 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
10991 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
10993 HOST_WIDE_INT bias
= 1;
10994 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
10995 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
10996 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
10999 else if (GET_MODE_CLASS (mode
) == MODE_INT
11000 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11002 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11003 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11004 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11005 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11006 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11008 else if (GET_MODE_CLASS (mode
) == MODE_INT
11009 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11011 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11012 dw_loc_descr_ref cvt
;
11013 if (type_die
== NULL
)
11015 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11016 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11017 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11018 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11019 add_loc_descr (&op0
, cvt
);
11020 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11021 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11022 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11023 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11024 add_loc_descr (&op1
, cvt
);
11027 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11032 add_loc_descr (&ret
, op1
);
11033 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11034 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11035 add_loc_descr (&ret
, bra_node
);
11036 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11037 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11038 add_loc_descr (&ret
, drop_node
);
11039 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11040 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11041 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11042 && GET_MODE_CLASS (mode
) == MODE_INT
11043 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11044 ret
= convert_descriptor_to_mode (mode
, ret
);
11048 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11049 but after converting arguments to type_die, afterwards
11050 convert back to unsigned. */
11052 static dw_loc_descr_ref
11053 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11054 enum machine_mode mode
, enum machine_mode mem_mode
)
11056 dw_loc_descr_ref cvt
, op0
, op1
;
11058 if (type_die
== NULL
)
11060 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11061 VAR_INIT_STATUS_INITIALIZED
);
11062 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11063 VAR_INIT_STATUS_INITIALIZED
);
11064 if (op0
== NULL
|| op1
== NULL
)
11066 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11067 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11068 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11069 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11070 add_loc_descr (&op0
, cvt
);
11071 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11072 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11073 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11074 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11075 add_loc_descr (&op1
, cvt
);
11076 add_loc_descr (&op0
, op1
);
11077 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11078 return convert_descriptor_to_mode (mode
, op0
);
11081 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11082 const0 is DW_OP_lit0 or corresponding typed constant,
11083 const1 is DW_OP_lit1 or corresponding typed constant
11084 and constMSB is constant with just the MSB bit set
11086 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11087 L1: const0 DW_OP_swap
11088 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11089 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11094 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11095 L1: const0 DW_OP_swap
11096 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11097 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11102 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11103 L1: const1 DW_OP_swap
11104 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11105 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11109 static dw_loc_descr_ref
11110 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11111 enum machine_mode mem_mode
)
11113 dw_loc_descr_ref op0
, ret
, tmp
;
11114 HOST_WIDE_INT valv
;
11115 dw_loc_descr_ref l1jump
, l1label
;
11116 dw_loc_descr_ref l2jump
, l2label
;
11117 dw_loc_descr_ref l3jump
, l3label
;
11118 dw_loc_descr_ref l4jump
, l4label
;
11121 if (GET_MODE_CLASS (mode
) != MODE_INT
11122 || GET_MODE (XEXP (rtl
, 0)) != mode
11123 || (GET_CODE (rtl
) == CLZ
11124 && GET_MODE_BITSIZE (mode
) > 2 * HOST_BITS_PER_WIDE_INT
))
11127 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11128 VAR_INIT_STATUS_INITIALIZED
);
11132 if (GET_CODE (rtl
) == CLZ
)
11134 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11135 valv
= GET_MODE_BITSIZE (mode
);
11137 else if (GET_CODE (rtl
) == FFS
)
11139 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11140 valv
= GET_MODE_BITSIZE (mode
);
11141 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11142 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11143 add_loc_descr (&ret
, l1jump
);
11144 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11145 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
11146 VAR_INIT_STATUS_INITIALIZED
);
11149 add_loc_descr (&ret
, tmp
);
11150 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11151 add_loc_descr (&ret
, l4jump
);
11152 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
11153 ? const1_rtx
: const0_rtx
,
11155 VAR_INIT_STATUS_INITIALIZED
);
11156 if (l1label
== NULL
)
11158 add_loc_descr (&ret
, l1label
);
11159 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11160 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
11161 add_loc_descr (&ret
, l2label
);
11162 if (GET_CODE (rtl
) != CLZ
)
11164 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11165 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
11166 << (GET_MODE_BITSIZE (mode
) - 1));
11168 msb
= immed_double_const (0, (unsigned HOST_WIDE_INT
) 1
11169 << (GET_MODE_BITSIZE (mode
)
11170 - HOST_BITS_PER_WIDE_INT
- 1), mode
);
11171 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
11172 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11173 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
11174 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
11176 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
11177 VAR_INIT_STATUS_INITIALIZED
);
11180 add_loc_descr (&ret
, tmp
);
11181 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11182 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11183 add_loc_descr (&ret
, l3jump
);
11184 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11185 VAR_INIT_STATUS_INITIALIZED
);
11188 add_loc_descr (&ret
, tmp
);
11189 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
11190 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
11191 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11192 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
11193 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11194 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11195 add_loc_descr (&ret
, l2jump
);
11196 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
11197 add_loc_descr (&ret
, l3label
);
11198 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
11199 add_loc_descr (&ret
, l4label
);
11200 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11201 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11202 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11203 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11204 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11205 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
11206 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11207 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
11211 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11212 const1 is DW_OP_lit1 or corresponding typed constant):
11214 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11215 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11219 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11220 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11223 static dw_loc_descr_ref
11224 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11225 enum machine_mode mem_mode
)
11227 dw_loc_descr_ref op0
, ret
, tmp
;
11228 dw_loc_descr_ref l1jump
, l1label
;
11229 dw_loc_descr_ref l2jump
, l2label
;
11231 if (GET_MODE_CLASS (mode
) != MODE_INT
11232 || GET_MODE (XEXP (rtl
, 0)) != mode
)
11235 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11236 VAR_INIT_STATUS_INITIALIZED
);
11240 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11241 VAR_INIT_STATUS_INITIALIZED
);
11244 add_loc_descr (&ret
, tmp
);
11245 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11246 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
11247 add_loc_descr (&ret
, l1label
);
11248 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11249 add_loc_descr (&ret
, l2jump
);
11250 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11251 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11252 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11253 VAR_INIT_STATUS_INITIALIZED
);
11256 add_loc_descr (&ret
, tmp
);
11257 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11258 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
11259 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
11260 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11261 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11262 VAR_INIT_STATUS_INITIALIZED
);
11263 add_loc_descr (&ret
, tmp
);
11264 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11265 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11266 add_loc_descr (&ret
, l1jump
);
11267 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11268 add_loc_descr (&ret
, l2label
);
11269 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11270 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11271 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11272 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11276 /* BSWAP (constS is initial shift count, either 56 or 24):
11278 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11279 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11280 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11281 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11282 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11284 static dw_loc_descr_ref
11285 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11286 enum machine_mode mem_mode
)
11288 dw_loc_descr_ref op0
, ret
, tmp
;
11289 dw_loc_descr_ref l1jump
, l1label
;
11290 dw_loc_descr_ref l2jump
, l2label
;
11292 if (GET_MODE_CLASS (mode
) != MODE_INT
11293 || BITS_PER_UNIT
!= 8
11294 || (GET_MODE_BITSIZE (mode
) != 32
11295 && GET_MODE_BITSIZE (mode
) != 64))
11298 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11299 VAR_INIT_STATUS_INITIALIZED
);
11304 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11306 VAR_INIT_STATUS_INITIALIZED
);
11309 add_loc_descr (&ret
, tmp
);
11310 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11311 VAR_INIT_STATUS_INITIALIZED
);
11314 add_loc_descr (&ret
, tmp
);
11315 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
11316 add_loc_descr (&ret
, l1label
);
11317 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11319 VAR_INIT_STATUS_INITIALIZED
);
11320 add_loc_descr (&ret
, tmp
);
11321 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
11322 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11323 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11324 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
11325 VAR_INIT_STATUS_INITIALIZED
);
11328 add_loc_descr (&ret
, tmp
);
11329 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11330 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
11331 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11332 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11333 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11334 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11335 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11336 VAR_INIT_STATUS_INITIALIZED
);
11337 add_loc_descr (&ret
, tmp
);
11338 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
11339 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11340 add_loc_descr (&ret
, l2jump
);
11341 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
11342 VAR_INIT_STATUS_INITIALIZED
);
11343 add_loc_descr (&ret
, tmp
);
11344 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11345 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11346 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11347 add_loc_descr (&ret
, l1jump
);
11348 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11349 add_loc_descr (&ret
, l2label
);
11350 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11351 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11352 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11353 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11354 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11355 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11359 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
11360 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11361 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
11362 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
11364 ROTATERT is similar:
11365 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
11366 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11367 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
11369 static dw_loc_descr_ref
11370 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11371 enum machine_mode mem_mode
)
11373 rtx rtlop1
= XEXP (rtl
, 1);
11374 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
11377 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11380 if (GET_MODE (rtlop1
) != VOIDmode
11381 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
11382 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
11383 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11384 VAR_INIT_STATUS_INITIALIZED
);
11385 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
11386 VAR_INIT_STATUS_INITIALIZED
);
11387 if (op0
== NULL
|| op1
== NULL
)
11389 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11390 for (i
= 0; i
< 2; i
++)
11392 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
11393 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
11395 VAR_INIT_STATUS_INITIALIZED
);
11396 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
11397 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11399 : HOST_BITS_PER_WIDE_INT
== 64
11400 ? DW_OP_const8u
: DW_OP_constu
,
11401 GET_MODE_MASK (mode
), 0);
11404 if (mask
[i
] == NULL
)
11406 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
11409 add_loc_descr (&ret
, op1
);
11410 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11411 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11412 if (GET_CODE (rtl
) == ROTATERT
)
11414 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11415 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11416 GET_MODE_BITSIZE (mode
), 0));
11418 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11419 if (mask
[0] != NULL
)
11420 add_loc_descr (&ret
, mask
[0]);
11421 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11422 if (mask
[1] != NULL
)
11424 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11425 add_loc_descr (&ret
, mask
[1]);
11426 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11428 if (GET_CODE (rtl
) == ROTATE
)
11430 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11431 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11432 GET_MODE_BITSIZE (mode
), 0));
11434 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11435 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11439 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11440 for DEBUG_PARAMETER_REF RTL. */
11442 static dw_loc_descr_ref
11443 parameter_ref_descriptor (rtx rtl
)
11445 dw_loc_descr_ref ret
;
11450 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
11451 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
11452 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
11455 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11456 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
11457 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11461 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
11462 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
11467 /* Helper function to get mode of MEM's address. */
11470 get_address_mode (rtx mem
)
11472 enum machine_mode mode
= GET_MODE (XEXP (mem
, 0));
11473 if (mode
!= VOIDmode
)
11475 return targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (mem
));
11478 /* The following routine converts the RTL for a variable or parameter
11479 (resident in memory) into an equivalent Dwarf representation of a
11480 mechanism for getting the address of that same variable onto the top of a
11481 hypothetical "address evaluation" stack.
11483 When creating memory location descriptors, we are effectively transforming
11484 the RTL for a memory-resident object into its Dwarf postfix expression
11485 equivalent. This routine recursively descends an RTL tree, turning
11486 it into Dwarf postfix code as it goes.
11488 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
11490 MEM_MODE is the mode of the memory reference, needed to handle some
11491 autoincrement addressing modes.
11493 Return 0 if we can't represent the location. */
11496 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11497 enum machine_mode mem_mode
,
11498 enum var_init_status initialized
)
11500 dw_loc_descr_ref mem_loc_result
= NULL
;
11501 enum dwarf_location_atom op
;
11502 dw_loc_descr_ref op0
, op1
;
11504 if (mode
== VOIDmode
)
11505 mode
= GET_MODE (rtl
);
11507 /* Note that for a dynamically sized array, the location we will generate a
11508 description of here will be the lowest numbered location which is
11509 actually within the array. That's *not* necessarily the same as the
11510 zeroth element of the array. */
11512 rtl
= targetm
.delegitimize_address (rtl
);
11514 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
11517 switch (GET_CODE (rtl
))
11522 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
11525 /* The case of a subreg may arise when we have a local (register)
11526 variable or a formal (register) parameter which doesn't quite fill
11527 up an entire register. For now, just assume that it is
11528 legitimate to make the Dwarf info refer to the whole register which
11529 contains the given subreg. */
11530 if (!subreg_lowpart_p (rtl
))
11532 if (GET_MODE_CLASS (mode
) == MODE_INT
11533 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl
))) == MODE_INT
11534 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11535 #ifdef POINTERS_EXTEND_UNSIGNED
11536 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
11539 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
))) <= DWARF2_ADDR_SIZE
)
11541 mem_loc_result
= mem_loc_descriptor (SUBREG_REG (rtl
),
11542 GET_MODE (SUBREG_REG (rtl
)),
11543 mem_mode
, initialized
);
11548 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
))))
11550 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
)))
11551 && (GET_MODE_CLASS (mode
) != MODE_INT
11552 || GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl
))) != MODE_INT
))
11556 dw_die_ref type_die
;
11557 dw_loc_descr_ref cvt
;
11559 mem_loc_result
= mem_loc_descriptor (SUBREG_REG (rtl
),
11560 GET_MODE (SUBREG_REG (rtl
)),
11561 mem_mode
, initialized
);
11562 if (mem_loc_result
== NULL
)
11564 type_die
= base_type_for_mode (mode
,
11565 GET_MODE_CLASS (mode
) == MODE_INT
);
11566 if (type_die
== NULL
)
11568 mem_loc_result
= NULL
;
11571 if (GET_MODE_SIZE (mode
)
11572 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
))))
11573 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11575 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
11576 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11577 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11578 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11579 add_loc_descr (&mem_loc_result
, cvt
);
11584 if (GET_MODE_CLASS (mode
) != MODE_INT
11585 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
11586 #ifdef POINTERS_EXTEND_UNSIGNED
11587 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
11591 dw_die_ref type_die
;
11595 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
11597 type_die
= base_type_for_mode (mode
,
11598 GET_MODE_CLASS (mode
) == MODE_INT
);
11599 if (type_die
== NULL
)
11601 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
11602 dbx_reg_number (rtl
), 0);
11603 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
11604 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
11605 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
11608 /* Whenever a register number forms a part of the description of the
11609 method for calculating the (dynamic) address of a memory resident
11610 object, DWARF rules require the register number be referred to as
11611 a "base register". This distinction is not based in any way upon
11612 what category of register the hardware believes the given register
11613 belongs to. This is strictly DWARF terminology we're dealing with
11614 here. Note that in cases where the location of a memory-resident
11615 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
11616 OP_CONST (0)) the actual DWARF location descriptor that we generate
11617 may just be OP_BASEREG (basereg). This may look deceptively like
11618 the object in question was allocated to a register (rather than in
11619 memory) so DWARF consumers need to be aware of the subtle
11620 distinction between OP_REG and OP_BASEREG. */
11621 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
11622 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
11623 else if (stack_realign_drap
11625 && crtl
->args
.internal_arg_pointer
== rtl
11626 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
11628 /* If RTL is internal_arg_pointer, which has been optimized
11629 out, use DRAP instead. */
11630 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
11631 VAR_INIT_STATUS_INITIALIZED
);
11637 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11639 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
11640 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
11643 else if (GET_CODE (rtl
) == ZERO_EXTEND
11644 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11645 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
11646 < HOST_BITS_PER_WIDE_INT
11647 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
11648 to expand zero extend as two shifts instead of
11650 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
11652 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
11653 mem_loc_result
= op0
;
11654 add_loc_descr (&mem_loc_result
,
11655 int_loc_descriptor (GET_MODE_MASK (imode
)));
11656 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
11658 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11660 int shift
= DWARF2_ADDR_SIZE
11661 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
11662 shift
*= BITS_PER_UNIT
;
11663 if (GET_CODE (rtl
) == SIGN_EXTEND
)
11667 mem_loc_result
= op0
;
11668 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
11669 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
11670 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
11671 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
11673 else if (!dwarf_strict
)
11675 dw_die_ref type_die1
, type_die2
;
11676 dw_loc_descr_ref cvt
;
11678 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
11679 GET_CODE (rtl
) == ZERO_EXTEND
);
11680 if (type_die1
== NULL
)
11682 type_die2
= base_type_for_mode (mode
, 1);
11683 if (type_die2
== NULL
)
11685 mem_loc_result
= op0
;
11686 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11687 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11688 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
11689 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11690 add_loc_descr (&mem_loc_result
, cvt
);
11691 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11692 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11693 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
11694 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11695 add_loc_descr (&mem_loc_result
, cvt
);
11701 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
11702 if (new_rtl
!= rtl
)
11704 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
11706 if (mem_loc_result
!= NULL
)
11707 return mem_loc_result
;
11710 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
11711 get_address_mode (rtl
), mode
,
11712 VAR_INIT_STATUS_INITIALIZED
);
11713 if (mem_loc_result
== NULL
)
11714 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
11715 if (mem_loc_result
!= NULL
)
11717 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
11718 || GET_MODE_CLASS (mode
) != MODE_INT
)
11720 dw_die_ref type_die
;
11721 dw_loc_descr_ref deref
;
11726 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
11727 if (type_die
== NULL
)
11729 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
11730 GET_MODE_SIZE (mode
), 0);
11731 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
11732 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
11733 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
11734 add_loc_descr (&mem_loc_result
, deref
);
11736 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11737 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
11739 add_loc_descr (&mem_loc_result
,
11740 new_loc_descr (DW_OP_deref_size
,
11741 GET_MODE_SIZE (mode
), 0));
11746 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
11749 /* Some ports can transform a symbol ref into a label ref, because
11750 the symbol ref is too far away and has to be dumped into a constant
11754 if (GET_MODE_CLASS (mode
) != MODE_INT
11755 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
11756 #ifdef POINTERS_EXTEND_UNSIGNED
11757 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
11761 if (GET_CODE (rtl
) == SYMBOL_REF
11762 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11764 dw_loc_descr_ref temp
;
11766 /* If this is not defined, we have no way to emit the data. */
11767 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
11770 /* We used to emit DW_OP_addr here, but that's wrong, since
11771 DW_OP_addr should be relocated by the debug info consumer,
11772 while DW_OP_GNU_push_tls_address operand should not. */
11773 temp
= new_loc_descr (DWARF2_ADDR_SIZE
== 4
11774 ? DW_OP_const4u
: DW_OP_const8u
, 0, 0);
11775 temp
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
11776 temp
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
11777 temp
->dtprel
= true;
11779 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
11780 add_loc_descr (&mem_loc_result
, temp
);
11785 if (!const_ok_for_output (rtl
))
11789 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
11790 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
11791 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
11792 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
11798 case DEBUG_IMPLICIT_PTR
:
11799 expansion_failed (NULL_TREE
, rtl
,
11800 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
11806 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
11808 if (GET_MODE_CLASS (mode
) != MODE_INT
11809 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11810 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
11811 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
11814 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl
)),
11815 VAR_INIT_STATUS_INITIALIZED
);
11817 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
11818 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
11820 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
11821 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
11822 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
11826 gcc_unreachable ();
11829 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
11830 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11831 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
11834 case DEBUG_PARAMETER_REF
:
11835 mem_loc_result
= parameter_ref_descriptor (rtl
);
11839 /* Extract the PLUS expression nested inside and fall into
11840 PLUS code below. */
11841 rtl
= XEXP (rtl
, 1);
11846 /* Turn these into a PLUS expression and fall into the PLUS code
11848 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
11849 GEN_INT (GET_CODE (rtl
) == PRE_INC
11850 ? GET_MODE_UNIT_SIZE (mem_mode
)
11851 : -GET_MODE_UNIT_SIZE (mem_mode
)));
11853 /* ... fall through ... */
11857 if (is_based_loc (rtl
)
11858 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11859 && GET_MODE_CLASS (mode
) == MODE_INT
)
11860 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
11861 INTVAL (XEXP (rtl
, 1)),
11862 VAR_INIT_STATUS_INITIALIZED
);
11865 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11866 VAR_INIT_STATUS_INITIALIZED
);
11867 if (mem_loc_result
== 0)
11870 if (CONST_INT_P (XEXP (rtl
, 1))
11871 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11872 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
11875 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11876 VAR_INIT_STATUS_INITIALIZED
);
11879 add_loc_descr (&mem_loc_result
, op1
);
11880 add_loc_descr (&mem_loc_result
,
11881 new_loc_descr (DW_OP_plus
, 0, 0));
11886 /* If a pseudo-reg is optimized away, it is possible for it to
11887 be replaced with a MEM containing a multiply or shift. */
11898 && GET_MODE_CLASS (mode
) == MODE_INT
11899 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11901 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
11902 base_type_for_mode (mode
, 0),
11926 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11928 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11929 VAR_INIT_STATUS_INITIALIZED
);
11931 rtx rtlop1
= XEXP (rtl
, 1);
11932 if (GET_MODE (rtlop1
) != VOIDmode
11933 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
11934 < GET_MODE_BITSIZE (mode
))
11935 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
11936 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
11937 VAR_INIT_STATUS_INITIALIZED
);
11940 if (op0
== 0 || op1
== 0)
11943 mem_loc_result
= op0
;
11944 add_loc_descr (&mem_loc_result
, op1
);
11945 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
11961 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11962 VAR_INIT_STATUS_INITIALIZED
);
11963 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11964 VAR_INIT_STATUS_INITIALIZED
);
11966 if (op0
== 0 || op1
== 0)
11969 mem_loc_result
= op0
;
11970 add_loc_descr (&mem_loc_result
, op1
);
11971 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
11975 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
11977 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
11978 base_type_for_mode (mode
, 0),
11983 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11984 VAR_INIT_STATUS_INITIALIZED
);
11985 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11986 VAR_INIT_STATUS_INITIALIZED
);
11988 if (op0
== 0 || op1
== 0)
11991 mem_loc_result
= op0
;
11992 add_loc_descr (&mem_loc_result
, op1
);
11993 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
11994 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
11995 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
11996 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
11997 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12001 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12003 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12008 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12009 base_type_for_mode (mode
, 1),
12027 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12028 VAR_INIT_STATUS_INITIALIZED
);
12033 mem_loc_result
= op0
;
12034 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12038 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12039 #ifdef POINTERS_EXTEND_UNSIGNED
12041 && mem_mode
!= VOIDmode
12042 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12046 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12050 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12051 || GET_MODE_BITSIZE (mode
) == 2 * HOST_BITS_PER_WIDE_INT
))
12053 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12054 enum machine_mode amode
;
12055 if (type_die
== NULL
)
12057 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12059 if (INTVAL (rtl
) >= 0
12060 && amode
!= BLKmode
12061 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12062 /* const DW_OP_GNU_convert <XXX> vs.
12063 DW_OP_GNU_const_type <XXX, 1, const>. */
12064 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12065 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12067 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12068 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12069 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12070 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12071 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12072 add_loc_descr (&mem_loc_result
, op0
);
12073 return mem_loc_result
;
12075 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12077 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12078 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12079 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12080 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12081 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12084 mem_loc_result
->dw_loc_oprnd2
.val_class
12085 = dw_val_class_const_double
;
12086 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12087 = shwi_to_double_int (INTVAL (rtl
));
12095 dw_die_ref type_die
;
12097 /* Note that a CONST_DOUBLE rtx could represent either an integer
12098 or a floating-point constant. A CONST_DOUBLE is used whenever
12099 the constant requires more than one word in order to be
12100 adequately represented. We output CONST_DOUBLEs as blocks. */
12101 if (mode
== VOIDmode
12102 || (GET_MODE (rtl
) == VOIDmode
12103 && GET_MODE_BITSIZE (mode
) != 2 * HOST_BITS_PER_WIDE_INT
))
12105 type_die
= base_type_for_mode (mode
,
12106 GET_MODE_CLASS (mode
) == MODE_INT
);
12107 if (type_die
== NULL
)
12109 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12110 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12111 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12112 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12113 if (SCALAR_FLOAT_MODE_P (mode
))
12115 unsigned int length
= GET_MODE_SIZE (mode
);
12116 unsigned char *array
12117 = (unsigned char*) ggc_alloc_atomic (length
);
12119 insert_float (rtl
, array
);
12120 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12121 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12122 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12123 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12127 mem_loc_result
->dw_loc_oprnd2
.val_class
12128 = dw_val_class_const_double
;
12129 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12130 = rtx_to_double_int (rtl
);
12136 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
12140 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12144 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12148 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12152 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12156 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
12160 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12164 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12168 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12172 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12177 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12182 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
12187 if (CONST_INT_P (XEXP (rtl
, 1))
12188 && CONST_INT_P (XEXP (rtl
, 2))
12189 && ((unsigned) INTVAL (XEXP (rtl
, 1))
12190 + (unsigned) INTVAL (XEXP (rtl
, 2))
12191 <= GET_MODE_BITSIZE (mode
))
12192 && GET_MODE_CLASS (mode
) == MODE_INT
12193 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12194 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
12197 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12198 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12201 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
12205 mem_loc_result
= op0
;
12206 size
= INTVAL (XEXP (rtl
, 1));
12207 shift
= INTVAL (XEXP (rtl
, 2));
12208 if (BITS_BIG_ENDIAN
)
12209 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12211 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
12213 add_loc_descr (&mem_loc_result
,
12214 int_loc_descriptor (DWARF2_ADDR_SIZE
12216 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12218 if (size
!= (int) DWARF2_ADDR_SIZE
)
12220 add_loc_descr (&mem_loc_result
,
12221 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
12222 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12229 dw_loc_descr_ref op2
, bra_node
, drop_node
;
12230 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
12231 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
12232 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
12233 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12234 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12235 VAR_INIT_STATUS_INITIALIZED
);
12236 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
12237 VAR_INIT_STATUS_INITIALIZED
);
12238 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
12241 mem_loc_result
= op1
;
12242 add_loc_descr (&mem_loc_result
, op2
);
12243 add_loc_descr (&mem_loc_result
, op0
);
12244 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12245 add_loc_descr (&mem_loc_result
, bra_node
);
12246 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
12247 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12248 add_loc_descr (&mem_loc_result
, drop_node
);
12249 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12250 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12255 case FLOAT_TRUNCATE
:
12257 case UNSIGNED_FLOAT
:
12262 dw_die_ref type_die
;
12263 dw_loc_descr_ref cvt
;
12265 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12266 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12269 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
12270 && (GET_CODE (rtl
) == FLOAT
12271 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
12272 <= DWARF2_ADDR_SIZE
))
12274 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12275 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
12276 if (type_die
== NULL
)
12278 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12279 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12280 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12281 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12282 add_loc_descr (&op0
, cvt
);
12284 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
12285 if (type_die
== NULL
)
12287 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12288 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12289 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12290 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12291 add_loc_descr (&op0
, cvt
);
12292 if (GET_MODE_CLASS (mode
) == MODE_INT
12293 && (GET_CODE (rtl
) == FIX
12294 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
12296 op0
= convert_descriptor_to_mode (mode
, op0
);
12300 mem_loc_result
= op0
;
12307 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
12312 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
12316 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
12321 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
12326 /* In theory, we could implement the above. */
12327 /* DWARF cannot represent the unsigned compare operations
12352 case FRACT_CONVERT
:
12353 case UNSIGNED_FRACT_CONVERT
:
12355 case UNSIGNED_SAT_FRACT
:
12361 case VEC_DUPLICATE
:
12365 case STRICT_LOW_PART
:
12369 /* If delegitimize_address couldn't do anything with the UNSPEC, we
12370 can't express it in the debug info. This can happen e.g. with some
12375 resolve_one_addr (&rtl
, NULL
);
12379 #ifdef ENABLE_CHECKING
12380 print_rtl (stderr
, rtl
);
12381 gcc_unreachable ();
12387 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12388 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12390 return mem_loc_result
;
12393 /* Return a descriptor that describes the concatenation of two locations.
12394 This is typically a complex variable. */
12396 static dw_loc_descr_ref
12397 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
12399 dw_loc_descr_ref cc_loc_result
= NULL
;
12400 dw_loc_descr_ref x0_ref
12401 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12402 dw_loc_descr_ref x1_ref
12403 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12405 if (x0_ref
== 0 || x1_ref
== 0)
12408 cc_loc_result
= x0_ref
;
12409 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
12411 add_loc_descr (&cc_loc_result
, x1_ref
);
12412 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
12414 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12415 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12417 return cc_loc_result
;
12420 /* Return a descriptor that describes the concatenation of N
12423 static dw_loc_descr_ref
12424 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
12427 dw_loc_descr_ref cc_loc_result
= NULL
;
12428 unsigned int n
= XVECLEN (concatn
, 0);
12430 for (i
= 0; i
< n
; ++i
)
12432 dw_loc_descr_ref ref
;
12433 rtx x
= XVECEXP (concatn
, 0, i
);
12435 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12439 add_loc_descr (&cc_loc_result
, ref
);
12440 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
12443 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12444 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12446 return cc_loc_result
;
12449 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12450 for DEBUG_IMPLICIT_PTR RTL. */
12452 static dw_loc_descr_ref
12453 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
12455 dw_loc_descr_ref ret
;
12460 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
12461 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
12462 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
12463 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
12464 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
12465 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12468 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12469 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12470 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12474 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12475 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
12480 /* Output a proper Dwarf location descriptor for a variable or parameter
12481 which is either allocated in a register or in a memory location. For a
12482 register, we just generate an OP_REG and the register number. For a
12483 memory location we provide a Dwarf postfix expression describing how to
12484 generate the (dynamic) address of the object onto the address stack.
12486 MODE is mode of the decl if this loc_descriptor is going to be used in
12487 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
12488 allowed, VOIDmode otherwise.
12490 If we don't know how to describe it, return 0. */
12492 static dw_loc_descr_ref
12493 loc_descriptor (rtx rtl
, enum machine_mode mode
,
12494 enum var_init_status initialized
)
12496 dw_loc_descr_ref loc_result
= NULL
;
12498 switch (GET_CODE (rtl
))
12501 /* The case of a subreg may arise when we have a local (register)
12502 variable or a formal (register) parameter which doesn't quite fill
12503 up an entire register. For now, just assume that it is
12504 legitimate to make the Dwarf info refer to the whole register which
12505 contains the given subreg. */
12506 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
12507 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
12508 GET_MODE (SUBREG_REG (rtl
)), initialized
);
12514 loc_result
= reg_loc_descriptor (rtl
, initialized
);
12518 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
12519 GET_MODE (rtl
), initialized
);
12520 if (loc_result
== NULL
)
12521 loc_result
= tls_mem_loc_descriptor (rtl
);
12522 if (loc_result
== NULL
)
12524 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12525 if (new_rtl
!= rtl
)
12526 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
12531 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
12536 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
12541 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
12543 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
12544 if (GET_CODE (loc
) == EXPR_LIST
)
12545 loc
= XEXP (loc
, 0);
12546 loc_result
= loc_descriptor (loc
, mode
, initialized
);
12550 rtl
= XEXP (rtl
, 1);
12555 rtvec par_elems
= XVEC (rtl
, 0);
12556 int num_elem
= GET_NUM_ELEM (par_elems
);
12557 enum machine_mode mode
;
12560 /* Create the first one, so we have something to add to. */
12561 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
12562 VOIDmode
, initialized
);
12563 if (loc_result
== NULL
)
12565 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
12566 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
12567 for (i
= 1; i
< num_elem
; i
++)
12569 dw_loc_descr_ref temp
;
12571 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
12572 VOIDmode
, initialized
);
12575 add_loc_descr (&loc_result
, temp
);
12576 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
12577 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
12583 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
12584 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
12589 if (mode
== VOIDmode
)
12590 mode
= GET_MODE (rtl
);
12592 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
12594 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
12596 /* Note that a CONST_DOUBLE rtx could represent either an integer
12597 or a floating-point constant. A CONST_DOUBLE is used whenever
12598 the constant requires more than one word in order to be
12599 adequately represented. We output CONST_DOUBLEs as blocks. */
12600 loc_result
= new_loc_descr (DW_OP_implicit_value
,
12601 GET_MODE_SIZE (mode
), 0);
12602 if (SCALAR_FLOAT_MODE_P (mode
))
12604 unsigned int length
= GET_MODE_SIZE (mode
);
12605 unsigned char *array
12606 = (unsigned char*) ggc_alloc_atomic (length
);
12608 insert_float (rtl
, array
);
12609 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12610 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12611 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12612 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12616 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
12617 loc_result
->dw_loc_oprnd2
.v
.val_double
12618 = rtx_to_double_int (rtl
);
12624 if (mode
== VOIDmode
)
12625 mode
= GET_MODE (rtl
);
12627 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
12629 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
12630 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
12631 unsigned char *array
= (unsigned char *)
12632 ggc_alloc_atomic (length
* elt_size
);
12636 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
12637 switch (GET_MODE_CLASS (mode
))
12639 case MODE_VECTOR_INT
:
12640 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
12642 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
12643 double_int val
= rtx_to_double_int (elt
);
12645 if (elt_size
<= sizeof (HOST_WIDE_INT
))
12646 insert_int (double_int_to_shwi (val
), elt_size
, p
);
12649 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
12650 insert_double (val
, p
);
12655 case MODE_VECTOR_FLOAT
:
12656 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
12658 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
12659 insert_float (elt
, p
);
12664 gcc_unreachable ();
12667 loc_result
= new_loc_descr (DW_OP_implicit_value
,
12668 length
* elt_size
, 0);
12669 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12670 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
12671 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
12672 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12677 if (mode
== VOIDmode
12678 || GET_CODE (XEXP (rtl
, 0)) == CONST_INT
12679 || GET_CODE (XEXP (rtl
, 0)) == CONST_DOUBLE
12680 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
12682 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
12687 if (!const_ok_for_output (rtl
))
12690 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
12691 && (dwarf_version
>= 4 || !dwarf_strict
))
12693 loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
12694 loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
12695 loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
12696 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
12697 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
12701 case DEBUG_IMPLICIT_PTR
:
12702 loc_result
= implicit_ptr_descriptor (rtl
, 0);
12706 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
12707 && CONST_INT_P (XEXP (rtl
, 1)))
12710 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
12716 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
12717 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
12718 && dwarf_version
>= 4)
12719 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
12721 /* Value expression. */
12722 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
12724 add_loc_descr (&loc_result
,
12725 new_loc_descr (DW_OP_stack_value
, 0, 0));
12733 /* We need to figure out what section we should use as the base for the
12734 address ranges where a given location is valid.
12735 1. If this particular DECL has a section associated with it, use that.
12736 2. If this function has a section associated with it, use that.
12737 3. Otherwise, use the text section.
12738 XXX: If you split a variable across multiple sections, we won't notice. */
12740 static const char *
12741 secname_for_decl (const_tree decl
)
12743 const char *secname
;
12745 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
12747 tree sectree
= DECL_SECTION_NAME (decl
);
12748 secname
= TREE_STRING_POINTER (sectree
);
12750 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
12752 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
12753 secname
= TREE_STRING_POINTER (sectree
);
12755 else if (cfun
&& in_cold_section_p
)
12756 secname
= crtl
->subsections
.cold_section_label
;
12758 secname
= text_section_label
;
12763 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
12766 decl_by_reference_p (tree decl
)
12768 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
12769 || TREE_CODE (decl
) == VAR_DECL
)
12770 && DECL_BY_REFERENCE (decl
));
12773 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
12776 static dw_loc_descr_ref
12777 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
12778 enum var_init_status initialized
)
12780 int have_address
= 0;
12781 dw_loc_descr_ref descr
;
12782 enum machine_mode mode
;
12784 if (want_address
!= 2)
12786 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
12788 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
12790 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
12791 if (GET_CODE (varloc
) == EXPR_LIST
)
12792 varloc
= XEXP (varloc
, 0);
12793 mode
= GET_MODE (varloc
);
12794 if (MEM_P (varloc
))
12796 rtx addr
= XEXP (varloc
, 0);
12797 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
12798 mode
, initialized
);
12803 rtx x
= avoid_constant_pool_reference (varloc
);
12805 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
12810 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
12817 if (GET_CODE (varloc
) == VAR_LOCATION
)
12818 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
12820 mode
= DECL_MODE (loc
);
12821 descr
= loc_descriptor (varloc
, mode
, initialized
);
12828 if (want_address
== 2 && !have_address
12829 && (dwarf_version
>= 4 || !dwarf_strict
))
12831 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
12833 expansion_failed (loc
, NULL_RTX
,
12834 "DWARF address size mismatch");
12837 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
12840 /* Show if we can't fill the request for an address. */
12841 if (want_address
&& !have_address
)
12843 expansion_failed (loc
, NULL_RTX
,
12844 "Want address and only have value");
12848 /* If we've got an address and don't want one, dereference. */
12849 if (!want_address
&& have_address
)
12851 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
12852 enum dwarf_location_atom op
;
12854 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
12856 expansion_failed (loc
, NULL_RTX
,
12857 "DWARF address size mismatch");
12860 else if (size
== DWARF2_ADDR_SIZE
)
12863 op
= DW_OP_deref_size
;
12865 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
12871 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
12872 if it is not possible. */
12874 static dw_loc_descr_ref
12875 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
12877 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
12878 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
12879 else if (dwarf_version
>= 3 || !dwarf_strict
)
12880 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
12885 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
12886 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
12888 static dw_loc_descr_ref
12889 dw_sra_loc_expr (tree decl
, rtx loc
)
12892 unsigned int padsize
= 0;
12893 dw_loc_descr_ref descr
, *descr_tail
;
12894 unsigned HOST_WIDE_INT decl_size
;
12896 enum var_init_status initialized
;
12898 if (DECL_SIZE (decl
) == NULL
12899 || !host_integerp (DECL_SIZE (decl
), 1))
12902 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
12904 descr_tail
= &descr
;
12906 for (p
= loc
; p
; p
= XEXP (p
, 1))
12908 unsigned int bitsize
= decl_piece_bitsize (p
);
12909 rtx loc_note
= *decl_piece_varloc_ptr (p
);
12910 dw_loc_descr_ref cur_descr
;
12911 dw_loc_descr_ref
*tail
, last
= NULL
;
12912 unsigned int opsize
= 0;
12914 if (loc_note
== NULL_RTX
12915 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
12917 padsize
+= bitsize
;
12920 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
12921 varloc
= NOTE_VAR_LOCATION (loc_note
);
12922 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
12923 if (cur_descr
== NULL
)
12925 padsize
+= bitsize
;
12929 /* Check that cur_descr either doesn't use
12930 DW_OP_*piece operations, or their sum is equal
12931 to bitsize. Otherwise we can't embed it. */
12932 for (tail
= &cur_descr
; *tail
!= NULL
;
12933 tail
= &(*tail
)->dw_loc_next
)
12934 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
12936 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
12940 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
12942 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
12946 if (last
!= NULL
&& opsize
!= bitsize
)
12948 padsize
+= bitsize
;
12952 /* If there is a hole, add DW_OP_*piece after empty DWARF
12953 expression, which means that those bits are optimized out. */
12956 if (padsize
> decl_size
)
12958 decl_size
-= padsize
;
12959 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
12960 if (*descr_tail
== NULL
)
12962 descr_tail
= &(*descr_tail
)->dw_loc_next
;
12965 *descr_tail
= cur_descr
;
12967 if (bitsize
> decl_size
)
12969 decl_size
-= bitsize
;
12972 HOST_WIDE_INT offset
= 0;
12973 if (GET_CODE (varloc
) == VAR_LOCATION
12974 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
12976 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
12977 if (GET_CODE (varloc
) == EXPR_LIST
)
12978 varloc
= XEXP (varloc
, 0);
12982 if (GET_CODE (varloc
) == CONST
12983 || GET_CODE (varloc
) == SIGN_EXTEND
12984 || GET_CODE (varloc
) == ZERO_EXTEND
)
12985 varloc
= XEXP (varloc
, 0);
12986 else if (GET_CODE (varloc
) == SUBREG
)
12987 varloc
= SUBREG_REG (varloc
);
12992 /* DW_OP_bit_size offset should be zero for register
12993 or implicit location descriptions and empty location
12994 descriptions, but for memory addresses needs big endian
12996 if (MEM_P (varloc
))
12998 unsigned HOST_WIDE_INT memsize
12999 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13000 if (memsize
!= bitsize
)
13002 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13003 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13005 if (memsize
< bitsize
)
13007 if (BITS_BIG_ENDIAN
)
13008 offset
= memsize
- bitsize
;
13012 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13013 if (*descr_tail
== NULL
)
13015 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13019 /* If there were any non-empty expressions, add padding till the end of
13021 if (descr
!= NULL
&& decl_size
!= 0)
13023 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13024 if (*descr_tail
== NULL
)
13030 /* Return the dwarf representation of the location list LOC_LIST of
13031 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13034 static dw_loc_list_ref
13035 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13037 const char *endname
, *secname
;
13039 enum var_init_status initialized
;
13040 struct var_loc_node
*node
;
13041 dw_loc_descr_ref descr
;
13042 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13043 dw_loc_list_ref list
= NULL
;
13044 dw_loc_list_ref
*listp
= &list
;
13046 /* Now that we know what section we are using for a base,
13047 actually construct the list of locations.
13048 The first location information is what is passed to the
13049 function that creates the location list, and the remaining
13050 locations just get added on to that list.
13051 Note that we only know the start address for a location
13052 (IE location changes), so to build the range, we use
13053 the range [current location start, next location start].
13054 This means we have to special case the last node, and generate
13055 a range of [last location start, end of function label]. */
13057 secname
= secname_for_decl (decl
);
13059 for (node
= loc_list
->first
; node
; node
= node
->next
)
13060 if (GET_CODE (node
->loc
) == EXPR_LIST
13061 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13063 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13065 /* This requires DW_OP_{,bit_}piece, which is not usable
13066 inside DWARF expressions. */
13067 if (want_address
!= 2)
13069 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13075 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13076 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13077 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
13081 bool range_across_switch
= false;
13082 /* If section switch happens in between node->label
13083 and node->next->label (or end of function) and
13084 we can't emit it as a single entry list,
13085 emit two ranges, first one ending at the end
13086 of first partition and second one starting at the
13087 beginning of second partition. */
13088 if (node
== loc_list
->last_before_switch
13089 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
13090 && current_function_decl
)
13092 endname
= cfun
->fde
->dw_fde_end
;
13093 range_across_switch
= true;
13095 /* The variable has a location between NODE->LABEL and
13096 NODE->NEXT->LABEL. */
13097 else if (node
->next
)
13098 endname
= node
->next
->label
;
13099 /* If the variable has a location at the last label
13100 it keeps its location until the end of function. */
13101 else if (!current_function_decl
)
13102 endname
= text_end_label
;
13105 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13106 current_function_funcdef_no
);
13107 endname
= ggc_strdup (label_id
);
13110 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
13111 if (TREE_CODE (decl
) == PARM_DECL
13112 && node
== loc_list
->first
13113 && GET_CODE (node
->loc
) == NOTE
13114 && strcmp (node
->label
, endname
) == 0)
13115 (*listp
)->force
= true;
13116 listp
= &(*listp
)->dw_loc_next
;
13118 if (range_across_switch
)
13120 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13121 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13124 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13125 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13126 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
13129 gcc_assert (descr
);
13130 /* The variable has a location between NODE->LABEL and
13131 NODE->NEXT->LABEL. */
13133 endname
= node
->next
->label
;
13135 endname
= cfun
->fde
->dw_fde_second_end
;
13136 *listp
= new_loc_list (descr
,
13137 cfun
->fde
->dw_fde_second_begin
,
13139 listp
= &(*listp
)->dw_loc_next
;
13144 /* Try to avoid the overhead of a location list emitting a location
13145 expression instead, but only if we didn't have more than one
13146 location entry in the first place. If some entries were not
13147 representable, we don't want to pretend a single entry that was
13148 applies to the entire scope in which the variable is
13150 if (list
&& loc_list
->first
->next
)
13156 /* Return if the loc_list has only single element and thus can be represented
13157 as location description. */
13160 single_element_loc_list_p (dw_loc_list_ref list
)
13162 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
13163 return !list
->ll_symbol
;
13166 /* To each location in list LIST add loc descr REF. */
13169 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
13171 dw_loc_descr_ref copy
;
13172 add_loc_descr (&list
->expr
, ref
);
13173 list
= list
->dw_loc_next
;
13176 copy
= ggc_alloc_dw_loc_descr_node ();
13177 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
13178 add_loc_descr (&list
->expr
, copy
);
13179 while (copy
->dw_loc_next
)
13181 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
13182 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
13183 copy
->dw_loc_next
= new_copy
;
13186 list
= list
->dw_loc_next
;
13190 /* Given two lists RET and LIST
13191 produce location list that is result of adding expression in LIST
13192 to expression in RET on each possition in program.
13193 Might be destructive on both RET and LIST.
13195 TODO: We handle only simple cases of RET or LIST having at most one
13196 element. General case would inolve sorting the lists in program order
13197 and merging them that will need some additional work.
13198 Adding that will improve quality of debug info especially for SRA-ed
13202 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
13211 if (!list
->dw_loc_next
)
13213 add_loc_descr_to_each (*ret
, list
->expr
);
13216 if (!(*ret
)->dw_loc_next
)
13218 add_loc_descr_to_each (list
, (*ret
)->expr
);
13222 expansion_failed (NULL_TREE
, NULL_RTX
,
13223 "Don't know how to merge two non-trivial"
13224 " location lists.\n");
13229 /* LOC is constant expression. Try a luck, look it up in constant
13230 pool and return its loc_descr of its address. */
13232 static dw_loc_descr_ref
13233 cst_pool_loc_descr (tree loc
)
13235 /* Get an RTL for this, if something has been emitted. */
13236 rtx rtl
= lookup_constant_def (loc
);
13238 if (!rtl
|| !MEM_P (rtl
))
13243 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
13245 /* TODO: We might get more coverage if we was actually delaying expansion
13246 of all expressions till end of compilation when constant pools are fully
13248 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
13250 expansion_failed (loc
, NULL_RTX
,
13251 "CST value in contant pool but not marked.");
13254 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13255 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
13258 /* Return dw_loc_list representing address of addr_expr LOC
13259 by looking for innder INDIRECT_REF expression and turing it
13260 into simple arithmetics. */
13262 static dw_loc_list_ref
13263 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
13266 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13267 enum machine_mode mode
;
13269 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (loc
));
13270 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13272 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
13273 &bitsize
, &bitpos
, &offset
, &mode
,
13274 &unsignedp
, &volatilep
, false);
13276 if (bitpos
% BITS_PER_UNIT
)
13278 expansion_failed (loc
, NULL_RTX
, "bitfield access");
13281 if (!INDIRECT_REF_P (obj
))
13283 expansion_failed (obj
,
13284 NULL_RTX
, "no indirect ref in inner refrence");
13287 if (!offset
&& !bitpos
)
13288 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
13290 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
13291 && (dwarf_version
>= 4 || !dwarf_strict
))
13293 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
13298 /* Variable offset. */
13299 list_ret1
= loc_list_from_tree (offset
, 0);
13300 if (list_ret1
== 0)
13302 add_loc_list (&list_ret
, list_ret1
);
13305 add_loc_descr_to_each (list_ret
,
13306 new_loc_descr (DW_OP_plus
, 0, 0));
13308 bytepos
= bitpos
/ BITS_PER_UNIT
;
13310 add_loc_descr_to_each (list_ret
,
13311 new_loc_descr (DW_OP_plus_uconst
,
13313 else if (bytepos
< 0)
13314 loc_list_plus_const (list_ret
, bytepos
);
13315 add_loc_descr_to_each (list_ret
,
13316 new_loc_descr (DW_OP_stack_value
, 0, 0));
13322 /* Generate Dwarf location list representing LOC.
13323 If WANT_ADDRESS is false, expression computing LOC will be computed
13324 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13325 if WANT_ADDRESS is 2, expression computing address useable in location
13326 will be returned (i.e. DW_OP_reg can be used
13327 to refer to register values). */
13329 static dw_loc_list_ref
13330 loc_list_from_tree (tree loc
, int want_address
)
13332 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
13333 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13334 int have_address
= 0;
13335 enum dwarf_location_atom op
;
13337 /* ??? Most of the time we do not take proper care for sign/zero
13338 extending the values properly. Hopefully this won't be a real
13341 switch (TREE_CODE (loc
))
13344 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
13347 case PLACEHOLDER_EXPR
:
13348 /* This case involves extracting fields from an object to determine the
13349 position of other fields. We don't try to encode this here. The
13350 only user of this is Ada, which encodes the needed information using
13351 the names of types. */
13352 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
13356 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
13357 /* There are no opcodes for these operations. */
13360 case PREINCREMENT_EXPR
:
13361 case PREDECREMENT_EXPR
:
13362 case POSTINCREMENT_EXPR
:
13363 case POSTDECREMENT_EXPR
:
13364 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
13365 /* There are no opcodes for these operations. */
13369 /* If we already want an address, see if there is INDIRECT_REF inside
13370 e.g. for &this->field. */
13373 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
13374 (loc
, want_address
== 2);
13377 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
13378 && (ret
= cst_pool_loc_descr (loc
)))
13381 /* Otherwise, process the argument and look for the address. */
13382 if (!list_ret
&& !ret
)
13383 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
13387 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
13393 if (DECL_THREAD_LOCAL_P (loc
))
13396 enum dwarf_location_atom first_op
;
13397 enum dwarf_location_atom second_op
;
13398 bool dtprel
= false;
13400 if (targetm
.have_tls
)
13402 /* If this is not defined, we have no way to emit the
13404 if (!targetm
.asm_out
.output_dwarf_dtprel
)
13407 /* The way DW_OP_GNU_push_tls_address is specified, we
13408 can only look up addresses of objects in the current
13409 module. We used DW_OP_addr as first op, but that's
13410 wrong, because DW_OP_addr is relocated by the debug
13411 info consumer, while DW_OP_GNU_push_tls_address
13412 operand shouldn't be. */
13413 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
13415 first_op
= DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
;
13417 second_op
= DW_OP_GNU_push_tls_address
;
13421 if (!targetm
.emutls
.debug_form_tls_address
13422 || !(dwarf_version
>= 3 || !dwarf_strict
))
13424 /* We stuffed the control variable into the DECL_VALUE_EXPR
13425 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13426 no longer appear in gimple code. We used the control
13427 variable in specific so that we could pick it up here. */
13428 loc
= DECL_VALUE_EXPR (loc
);
13429 first_op
= DW_OP_addr
;
13430 second_op
= DW_OP_form_tls_address
;
13433 rtl
= rtl_for_decl_location (loc
);
13434 if (rtl
== NULL_RTX
)
13439 rtl
= XEXP (rtl
, 0);
13440 if (! CONSTANT_P (rtl
))
13443 ret
= new_loc_descr (first_op
, 0, 0);
13444 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
13445 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
13446 ret
->dtprel
= dtprel
;
13448 ret1
= new_loc_descr (second_op
, 0, 0);
13449 add_loc_descr (&ret
, ret1
);
13458 if (DECL_HAS_VALUE_EXPR_P (loc
))
13459 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
13463 case FUNCTION_DECL
:
13466 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
13468 if (loc_list
&& loc_list
->first
)
13470 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
13471 have_address
= want_address
!= 0;
13474 rtl
= rtl_for_decl_location (loc
);
13475 if (rtl
== NULL_RTX
)
13477 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
13480 else if (CONST_INT_P (rtl
))
13482 HOST_WIDE_INT val
= INTVAL (rtl
);
13483 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13484 val
&= GET_MODE_MASK (DECL_MODE (loc
));
13485 ret
= int_loc_descriptor (val
);
13487 else if (GET_CODE (rtl
) == CONST_STRING
)
13489 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
13492 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
13494 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
13495 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
13496 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
13500 enum machine_mode mode
, mem_mode
;
13502 /* Certain constructs can only be represented at top-level. */
13503 if (want_address
== 2)
13505 ret
= loc_descriptor (rtl
, VOIDmode
,
13506 VAR_INIT_STATUS_INITIALIZED
);
13511 mode
= GET_MODE (rtl
);
13512 mem_mode
= VOIDmode
;
13516 mode
= get_address_mode (rtl
);
13517 rtl
= XEXP (rtl
, 0);
13520 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
13521 VAR_INIT_STATUS_INITIALIZED
);
13524 expansion_failed (loc
, rtl
,
13525 "failed to produce loc descriptor for rtl");
13532 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
13536 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13540 case COMPOUND_EXPR
:
13541 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
13544 case VIEW_CONVERT_EXPR
:
13547 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
13549 case COMPONENT_REF
:
13550 case BIT_FIELD_REF
:
13552 case ARRAY_RANGE_REF
:
13553 case REALPART_EXPR
:
13554 case IMAGPART_EXPR
:
13557 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13558 enum machine_mode mode
;
13560 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (loc
));
13562 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
13563 &unsignedp
, &volatilep
, false);
13565 gcc_assert (obj
!= loc
);
13567 list_ret
= loc_list_from_tree (obj
,
13569 && !bitpos
&& !offset
? 2 : 1);
13570 /* TODO: We can extract value of the small expression via shifting even
13571 for nonzero bitpos. */
13574 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
13576 expansion_failed (loc
, NULL_RTX
,
13577 "bitfield access");
13581 if (offset
!= NULL_TREE
)
13583 /* Variable offset. */
13584 list_ret1
= loc_list_from_tree (offset
, 0);
13585 if (list_ret1
== 0)
13587 add_loc_list (&list_ret
, list_ret1
);
13590 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
13593 bytepos
= bitpos
/ BITS_PER_UNIT
;
13595 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
13596 else if (bytepos
< 0)
13597 loc_list_plus_const (list_ret
, bytepos
);
13604 if ((want_address
|| !host_integerp (loc
, 0))
13605 && (ret
= cst_pool_loc_descr (loc
)))
13607 else if (want_address
== 2
13608 && host_integerp (loc
, 0)
13609 && (ret
= address_of_int_loc_descriptor
13610 (int_size_in_bytes (TREE_TYPE (loc
)),
13611 tree_low_cst (loc
, 0))))
13613 else if (host_integerp (loc
, 0))
13614 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
13617 expansion_failed (loc
, NULL_RTX
,
13618 "Integer operand is not host integer");
13627 if ((ret
= cst_pool_loc_descr (loc
)))
13630 /* We can construct small constants here using int_loc_descriptor. */
13631 expansion_failed (loc
, NULL_RTX
,
13632 "constructor or constant not in constant pool");
13635 case TRUTH_AND_EXPR
:
13636 case TRUTH_ANDIF_EXPR
:
13641 case TRUTH_XOR_EXPR
:
13646 case TRUTH_OR_EXPR
:
13647 case TRUTH_ORIF_EXPR
:
13652 case FLOOR_DIV_EXPR
:
13653 case CEIL_DIV_EXPR
:
13654 case ROUND_DIV_EXPR
:
13655 case TRUNC_DIV_EXPR
:
13656 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13665 case FLOOR_MOD_EXPR
:
13666 case CEIL_MOD_EXPR
:
13667 case ROUND_MOD_EXPR
:
13668 case TRUNC_MOD_EXPR
:
13669 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13674 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13675 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
13676 if (list_ret
== 0 || list_ret1
== 0)
13679 add_loc_list (&list_ret
, list_ret1
);
13682 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
13683 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
13684 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
13685 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
13686 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
13698 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
13701 case POINTER_PLUS_EXPR
:
13703 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
13705 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13709 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
13717 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
13724 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
13731 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
13738 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
13753 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13754 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
13755 if (list_ret
== 0 || list_ret1
== 0)
13758 add_loc_list (&list_ret
, list_ret1
);
13761 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
13764 case TRUTH_NOT_EXPR
:
13778 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13782 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
13788 const enum tree_code code
=
13789 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
13791 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
13792 build2 (code
, integer_type_node
,
13793 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
13794 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
13797 /* ... fall through ... */
13801 dw_loc_descr_ref lhs
13802 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
13803 dw_loc_list_ref rhs
13804 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
13805 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
13807 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13808 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
13811 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13812 add_loc_descr_to_each (list_ret
, bra_node
);
13814 add_loc_list (&list_ret
, rhs
);
13815 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
13816 add_loc_descr_to_each (list_ret
, jump_node
);
13818 add_loc_descr_to_each (list_ret
, lhs
);
13819 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13820 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
13822 /* ??? Need a node to point the skip at. Use a nop. */
13823 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
13824 add_loc_descr_to_each (list_ret
, tmp
);
13825 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13826 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
13830 case FIX_TRUNC_EXPR
:
13834 /* Leave front-end specific codes as simply unknown. This comes
13835 up, for instance, with the C STMT_EXPR. */
13836 if ((unsigned int) TREE_CODE (loc
)
13837 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
13839 expansion_failed (loc
, NULL_RTX
,
13840 "language specific tree node");
13844 #ifdef ENABLE_CHECKING
13845 /* Otherwise this is a generic code; we should just lists all of
13846 these explicitly. We forgot one. */
13847 gcc_unreachable ();
13849 /* In a release build, we want to degrade gracefully: better to
13850 generate incomplete debugging information than to crash. */
13855 if (!ret
&& !list_ret
)
13858 if (want_address
== 2 && !have_address
13859 && (dwarf_version
>= 4 || !dwarf_strict
))
13861 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13863 expansion_failed (loc
, NULL_RTX
,
13864 "DWARF address size mismatch");
13868 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13870 add_loc_descr_to_each (list_ret
,
13871 new_loc_descr (DW_OP_stack_value
, 0, 0));
13874 /* Show if we can't fill the request for an address. */
13875 if (want_address
&& !have_address
)
13877 expansion_failed (loc
, NULL_RTX
,
13878 "Want address and only have value");
13882 gcc_assert (!ret
|| !list_ret
);
13884 /* If we've got an address and don't want one, dereference. */
13885 if (!want_address
&& have_address
)
13887 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13889 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13891 expansion_failed (loc
, NULL_RTX
,
13892 "DWARF address size mismatch");
13895 else if (size
== DWARF2_ADDR_SIZE
)
13898 op
= DW_OP_deref_size
;
13901 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
13903 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
13906 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
13911 /* Same as above but return only single location expression. */
13912 static dw_loc_descr_ref
13913 loc_descriptor_from_tree (tree loc
, int want_address
)
13915 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
13918 if (ret
->dw_loc_next
)
13920 expansion_failed (loc
, NULL_RTX
,
13921 "Location list where only loc descriptor needed");
13927 /* Given a value, round it up to the lowest multiple of `boundary'
13928 which is not less than the value itself. */
13930 static inline HOST_WIDE_INT
13931 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
13933 return (((value
+ boundary
- 1) / boundary
) * boundary
);
13936 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
13937 pointer to the declared type for the relevant field variable, or return
13938 `integer_type_node' if the given node turns out to be an
13939 ERROR_MARK node. */
13942 field_type (const_tree decl
)
13946 if (TREE_CODE (decl
) == ERROR_MARK
)
13947 return integer_type_node
;
13949 type
= DECL_BIT_FIELD_TYPE (decl
);
13950 if (type
== NULL_TREE
)
13951 type
= TREE_TYPE (decl
);
13956 /* Given a pointer to a tree node, return the alignment in bits for
13957 it, or else return BITS_PER_WORD if the node actually turns out to
13958 be an ERROR_MARK node. */
13960 static inline unsigned
13961 simple_type_align_in_bits (const_tree type
)
13963 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
13966 static inline unsigned
13967 simple_decl_align_in_bits (const_tree decl
)
13969 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
13972 /* Return the result of rounding T up to ALIGN. */
13974 static inline double_int
13975 round_up_to_align (double_int t
, unsigned int align
)
13977 double_int alignd
= uhwi_to_double_int (align
);
13978 t
= double_int_add (t
, alignd
);
13979 t
= double_int_add (t
, double_int_minus_one
);
13980 t
= double_int_div (t
, alignd
, true, TRUNC_DIV_EXPR
);
13981 t
= double_int_mul (t
, alignd
);
13985 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
13986 lowest addressed byte of the "containing object" for the given FIELD_DECL,
13987 or return 0 if we are unable to determine what that offset is, either
13988 because the argument turns out to be a pointer to an ERROR_MARK node, or
13989 because the offset is actually variable. (We can't handle the latter case
13992 static HOST_WIDE_INT
13993 field_byte_offset (const_tree decl
)
13995 double_int object_offset_in_bits
;
13996 double_int object_offset_in_bytes
;
13997 double_int bitpos_int
;
13999 if (TREE_CODE (decl
) == ERROR_MARK
)
14002 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14004 /* We cannot yet cope with fields whose positions are variable, so
14005 for now, when we see such things, we simply return 0. Someday, we may
14006 be able to handle such cases, but it will be damn difficult. */
14007 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14010 bitpos_int
= tree_to_double_int (bit_position (decl
));
14012 #ifdef PCC_BITFIELD_TYPE_MATTERS
14013 if (PCC_BITFIELD_TYPE_MATTERS
)
14016 tree field_size_tree
;
14017 double_int deepest_bitpos
;
14018 double_int field_size_in_bits
;
14019 unsigned int type_align_in_bits
;
14020 unsigned int decl_align_in_bits
;
14021 double_int type_size_in_bits
;
14023 type
= field_type (decl
);
14024 type_size_in_bits
= double_int_type_size_in_bits (type
);
14025 type_align_in_bits
= simple_type_align_in_bits (type
);
14027 field_size_tree
= DECL_SIZE (decl
);
14029 /* The size could be unspecified if there was an error, or for
14030 a flexible array member. */
14031 if (!field_size_tree
)
14032 field_size_tree
= bitsize_zero_node
;
14034 /* If the size of the field is not constant, use the type size. */
14035 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14036 field_size_in_bits
= tree_to_double_int (field_size_tree
);
14038 field_size_in_bits
= type_size_in_bits
;
14040 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14042 /* The GCC front-end doesn't make any attempt to keep track of the
14043 starting bit offset (relative to the start of the containing
14044 structure type) of the hypothetical "containing object" for a
14045 bit-field. Thus, when computing the byte offset value for the
14046 start of the "containing object" of a bit-field, we must deduce
14047 this information on our own. This can be rather tricky to do in
14048 some cases. For example, handling the following structure type
14049 definition when compiling for an i386/i486 target (which only
14050 aligns long long's to 32-bit boundaries) can be very tricky:
14052 struct S { int field1; long long field2:31; };
14054 Fortunately, there is a simple rule-of-thumb which can be used
14055 in such cases. When compiling for an i386/i486, GCC will
14056 allocate 8 bytes for the structure shown above. It decides to
14057 do this based upon one simple rule for bit-field allocation.
14058 GCC allocates each "containing object" for each bit-field at
14059 the first (i.e. lowest addressed) legitimate alignment boundary
14060 (based upon the required minimum alignment for the declared
14061 type of the field) which it can possibly use, subject to the
14062 condition that there is still enough available space remaining
14063 in the containing object (when allocated at the selected point)
14064 to fully accommodate all of the bits of the bit-field itself.
14066 This simple rule makes it obvious why GCC allocates 8 bytes for
14067 each object of the structure type shown above. When looking
14068 for a place to allocate the "containing object" for `field2',
14069 the compiler simply tries to allocate a 64-bit "containing
14070 object" at each successive 32-bit boundary (starting at zero)
14071 until it finds a place to allocate that 64- bit field such that
14072 at least 31 contiguous (and previously unallocated) bits remain
14073 within that selected 64 bit field. (As it turns out, for the
14074 example above, the compiler finds it is OK to allocate the
14075 "containing object" 64-bit field at bit-offset zero within the
14078 Here we attempt to work backwards from the limited set of facts
14079 we're given, and we try to deduce from those facts, where GCC
14080 must have believed that the containing object started (within
14081 the structure type). The value we deduce is then used (by the
14082 callers of this routine) to generate DW_AT_location and
14083 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14084 the case of DW_AT_location, regular fields as well). */
14086 /* Figure out the bit-distance from the start of the structure to
14087 the "deepest" bit of the bit-field. */
14088 deepest_bitpos
= double_int_add (bitpos_int
, field_size_in_bits
);
14090 /* This is the tricky part. Use some fancy footwork to deduce
14091 where the lowest addressed bit of the containing object must
14093 object_offset_in_bits
14094 = double_int_sub (deepest_bitpos
, type_size_in_bits
);
14096 /* Round up to type_align by default. This works best for
14098 object_offset_in_bits
14099 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
14101 if (double_int_ucmp (object_offset_in_bits
, bitpos_int
) > 0)
14103 object_offset_in_bits
14104 = double_int_sub (deepest_bitpos
, type_size_in_bits
);
14106 /* Round up to decl_align instead. */
14107 object_offset_in_bits
14108 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
14112 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14113 object_offset_in_bits
= bitpos_int
;
14115 object_offset_in_bytes
14116 = double_int_div (object_offset_in_bits
,
14117 uhwi_to_double_int (BITS_PER_UNIT
), true,
14119 return double_int_to_shwi (object_offset_in_bytes
);
14122 /* The following routines define various Dwarf attributes and any data
14123 associated with them. */
14125 /* Add a location description attribute value to a DIE.
14127 This emits location attributes suitable for whole variables and
14128 whole parameters. Note that the location attributes for struct fields are
14129 generated by the routine `data_member_location_attribute' below. */
14132 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
14133 dw_loc_list_ref descr
)
14137 if (single_element_loc_list_p (descr
))
14138 add_AT_loc (die
, attr_kind
, descr
->expr
);
14140 add_AT_loc_list (die
, attr_kind
, descr
);
14143 /* Add DW_AT_accessibility attribute to DIE if needed. */
14146 add_accessibility_attribute (dw_die_ref die
, tree decl
)
14148 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14149 children, otherwise the default is DW_ACCESS_public. In DWARF2
14150 the default has always been DW_ACCESS_public. */
14151 if (TREE_PROTECTED (decl
))
14152 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14153 else if (TREE_PRIVATE (decl
))
14155 if (dwarf_version
== 2
14156 || die
->die_parent
== NULL
14157 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
14158 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
14160 else if (dwarf_version
> 2
14162 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
14163 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14166 /* Attach the specialized form of location attribute used for data members of
14167 struct and union types. In the special case of a FIELD_DECL node which
14168 represents a bit-field, the "offset" part of this special location
14169 descriptor must indicate the distance in bytes from the lowest-addressed
14170 byte of the containing struct or union type to the lowest-addressed byte of
14171 the "containing object" for the bit-field. (See the `field_byte_offset'
14174 For any given bit-field, the "containing object" is a hypothetical object
14175 (of some integral or enum type) within which the given bit-field lives. The
14176 type of this hypothetical "containing object" is always the same as the
14177 declared type of the individual bit-field itself (for GCC anyway... the
14178 DWARF spec doesn't actually mandate this). Note that it is the size (in
14179 bytes) of the hypothetical "containing object" which will be given in the
14180 DW_AT_byte_size attribute for this bit-field. (See the
14181 `byte_size_attribute' function below.) It is also used when calculating the
14182 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14183 function below.) */
14186 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
14188 HOST_WIDE_INT offset
;
14189 dw_loc_descr_ref loc_descr
= 0;
14191 if (TREE_CODE (decl
) == TREE_BINFO
)
14193 /* We're working on the TAG_inheritance for a base class. */
14194 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
14196 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14197 aren't at a fixed offset from all (sub)objects of the same
14198 type. We need to extract the appropriate offset from our
14199 vtable. The following dwarf expression means
14201 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14203 This is specific to the V3 ABI, of course. */
14205 dw_loc_descr_ref tmp
;
14207 /* Make a copy of the object address. */
14208 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
14209 add_loc_descr (&loc_descr
, tmp
);
14211 /* Extract the vtable address. */
14212 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14213 add_loc_descr (&loc_descr
, tmp
);
14215 /* Calculate the address of the offset. */
14216 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
14217 gcc_assert (offset
< 0);
14219 tmp
= int_loc_descriptor (-offset
);
14220 add_loc_descr (&loc_descr
, tmp
);
14221 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
14222 add_loc_descr (&loc_descr
, tmp
);
14224 /* Extract the offset. */
14225 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14226 add_loc_descr (&loc_descr
, tmp
);
14228 /* Add it to the object address. */
14229 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
14230 add_loc_descr (&loc_descr
, tmp
);
14233 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
14236 offset
= field_byte_offset (decl
);
14240 if (dwarf_version
> 2)
14242 /* Don't need to output a location expression, just the constant. */
14244 add_AT_int (die
, DW_AT_data_member_location
, offset
);
14246 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
14251 enum dwarf_location_atom op
;
14253 /* The DWARF2 standard says that we should assume that the structure
14254 address is already on the stack, so we can specify a structure
14255 field address by using DW_OP_plus_uconst. */
14257 #ifdef MIPS_DEBUGGING_INFO
14258 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
14259 operator correctly. It works only if we leave the offset on the
14263 op
= DW_OP_plus_uconst
;
14266 loc_descr
= new_loc_descr (op
, offset
, 0);
14270 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
14273 /* Writes integer values to dw_vec_const array. */
14276 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
14280 *dest
++ = val
& 0xff;
14286 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14288 static HOST_WIDE_INT
14289 extract_int (const unsigned char *src
, unsigned int size
)
14291 HOST_WIDE_INT val
= 0;
14297 val
|= *--src
& 0xff;
14303 /* Writes double_int values to dw_vec_const array. */
14306 insert_double (double_int val
, unsigned char *dest
)
14308 unsigned char *p0
= dest
;
14309 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
14311 if (WORDS_BIG_ENDIAN
)
14317 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
14318 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
14321 /* Writes floating point values to dw_vec_const array. */
14324 insert_float (const_rtx rtl
, unsigned char *array
)
14326 REAL_VALUE_TYPE rv
;
14330 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
14331 real_to_target (val
, &rv
, GET_MODE (rtl
));
14333 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14334 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
14336 insert_int (val
[i
], 4, array
);
14341 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14342 does not have a "location" either in memory or in a register. These
14343 things can arise in GNU C when a constant is passed as an actual parameter
14344 to an inlined function. They can also arise in C++ where declared
14345 constants do not necessarily get memory "homes". */
14348 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
14350 switch (GET_CODE (rtl
))
14354 HOST_WIDE_INT val
= INTVAL (rtl
);
14357 add_AT_int (die
, DW_AT_const_value
, val
);
14359 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
14364 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14365 floating-point constant. A CONST_DOUBLE is used whenever the
14366 constant requires more than one word in order to be adequately
14369 enum machine_mode mode
= GET_MODE (rtl
);
14371 if (SCALAR_FLOAT_MODE_P (mode
))
14373 unsigned int length
= GET_MODE_SIZE (mode
);
14374 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
14376 insert_float (rtl
, array
);
14377 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
14380 add_AT_double (die
, DW_AT_const_value
,
14381 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
14387 enum machine_mode mode
= GET_MODE (rtl
);
14388 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
14389 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
14390 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
14391 (length
* elt_size
);
14395 switch (GET_MODE_CLASS (mode
))
14397 case MODE_VECTOR_INT
:
14398 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14400 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14401 double_int val
= rtx_to_double_int (elt
);
14403 if (elt_size
<= sizeof (HOST_WIDE_INT
))
14404 insert_int (double_int_to_shwi (val
), elt_size
, p
);
14407 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
14408 insert_double (val
, p
);
14413 case MODE_VECTOR_FLOAT
:
14414 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14416 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14417 insert_float (elt
, p
);
14422 gcc_unreachable ();
14425 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
14430 if (dwarf_version
>= 4 || !dwarf_strict
)
14432 dw_loc_descr_ref loc_result
;
14433 resolve_one_addr (&rtl
, NULL
);
14435 loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
14436 loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
14437 loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
14438 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14439 add_AT_loc (die
, DW_AT_location
, loc_result
);
14440 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
14446 if (CONSTANT_P (XEXP (rtl
, 0)))
14447 return add_const_value_attribute (die
, XEXP (rtl
, 0));
14450 if (!const_ok_for_output (rtl
))
14453 if (dwarf_version
>= 4 || !dwarf_strict
)
14458 /* In cases where an inlined instance of an inline function is passed
14459 the address of an `auto' variable (which is local to the caller) we
14460 can get a situation where the DECL_RTL of the artificial local
14461 variable (for the inlining) which acts as a stand-in for the
14462 corresponding formal parameter (of the inline function) will look
14463 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14464 exactly a compile-time constant expression, but it isn't the address
14465 of the (artificial) local variable either. Rather, it represents the
14466 *value* which the artificial local variable always has during its
14467 lifetime. We currently have no way to represent such quasi-constant
14468 values in Dwarf, so for now we just punt and generate nothing. */
14476 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
14477 && MEM_READONLY_P (rtl
)
14478 && GET_MODE (rtl
) == BLKmode
)
14480 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
14486 /* No other kinds of rtx should be possible here. */
14487 gcc_unreachable ();
14492 /* Determine whether the evaluation of EXPR references any variables
14493 or functions which aren't otherwise used (and therefore may not be
14496 reference_to_unused (tree
* tp
, int * walk_subtrees
,
14497 void * data ATTRIBUTE_UNUSED
)
14499 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
14500 *walk_subtrees
= 0;
14502 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
14503 && ! TREE_ASM_WRITTEN (*tp
))
14505 /* ??? The C++ FE emits debug information for using decls, so
14506 putting gcc_unreachable here falls over. See PR31899. For now
14507 be conservative. */
14508 else if (!cgraph_global_info_ready
14509 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
14511 else if (TREE_CODE (*tp
) == VAR_DECL
)
14513 struct varpool_node
*node
= varpool_get_node (*tp
);
14514 if (!node
|| !node
->needed
)
14517 else if (TREE_CODE (*tp
) == FUNCTION_DECL
14518 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
14520 /* The call graph machinery must have finished analyzing,
14521 optimizing and gimplifying the CU by now.
14522 So if *TP has no call graph node associated
14523 to it, it means *TP will not be emitted. */
14524 if (!cgraph_get_node (*tp
))
14527 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
14533 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
14534 for use in a later add_const_value_attribute call. */
14537 rtl_for_decl_init (tree init
, tree type
)
14539 rtx rtl
= NULL_RTX
;
14543 /* If a variable is initialized with a string constant without embedded
14544 zeros, build CONST_STRING. */
14545 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
14547 tree enttype
= TREE_TYPE (type
);
14548 tree domain
= TYPE_DOMAIN (type
);
14549 enum machine_mode mode
= TYPE_MODE (enttype
);
14551 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
14553 && integer_zerop (TYPE_MIN_VALUE (domain
))
14554 && compare_tree_int (TYPE_MAX_VALUE (domain
),
14555 TREE_STRING_LENGTH (init
) - 1) == 0
14556 && ((size_t) TREE_STRING_LENGTH (init
)
14557 == strlen (TREE_STRING_POINTER (init
)) + 1))
14559 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
14560 ggc_strdup (TREE_STRING_POINTER (init
)));
14561 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
14562 MEM_READONLY_P (rtl
) = 1;
14565 /* Other aggregates, and complex values, could be represented using
14567 else if (AGGREGATE_TYPE_P (type
)
14568 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
14569 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
14570 || TREE_CODE (type
) == COMPLEX_TYPE
)
14572 /* Vectors only work if their mode is supported by the target.
14573 FIXME: generic vectors ought to work too. */
14574 else if (TREE_CODE (type
) == VECTOR_TYPE
14575 && !VECTOR_MODE_P (TYPE_MODE (type
)))
14577 /* If the initializer is something that we know will expand into an
14578 immediate RTL constant, expand it now. We must be careful not to
14579 reference variables which won't be output. */
14580 else if (initializer_constant_valid_p (init
, type
)
14581 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
14583 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
14585 if (TREE_CODE (type
) == VECTOR_TYPE
)
14586 switch (TREE_CODE (init
))
14591 if (TREE_CONSTANT (init
))
14593 VEC(constructor_elt
,gc
) *elts
= CONSTRUCTOR_ELTS (init
);
14594 bool constant_p
= true;
14596 unsigned HOST_WIDE_INT ix
;
14598 /* Even when ctor is constant, it might contain non-*_CST
14599 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
14600 belong into VECTOR_CST nodes. */
14601 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
14602 if (!CONSTANT_CLASS_P (value
))
14604 constant_p
= false;
14610 init
= build_vector_from_ctor (type
, elts
);
14620 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
14622 /* If expand_expr returns a MEM, it wasn't immediate. */
14623 gcc_assert (!rtl
|| !MEM_P (rtl
));
14629 /* Generate RTL for the variable DECL to represent its location. */
14632 rtl_for_decl_location (tree decl
)
14636 /* Here we have to decide where we are going to say the parameter "lives"
14637 (as far as the debugger is concerned). We only have a couple of
14638 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
14640 DECL_RTL normally indicates where the parameter lives during most of the
14641 activation of the function. If optimization is enabled however, this
14642 could be either NULL or else a pseudo-reg. Both of those cases indicate
14643 that the parameter doesn't really live anywhere (as far as the code
14644 generation parts of GCC are concerned) during most of the function's
14645 activation. That will happen (for example) if the parameter is never
14646 referenced within the function.
14648 We could just generate a location descriptor here for all non-NULL
14649 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
14650 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
14651 where DECL_RTL is NULL or is a pseudo-reg.
14653 Note however that we can only get away with using DECL_INCOMING_RTL as
14654 a backup substitute for DECL_RTL in certain limited cases. In cases
14655 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
14656 we can be sure that the parameter was passed using the same type as it is
14657 declared to have within the function, and that its DECL_INCOMING_RTL
14658 points us to a place where a value of that type is passed.
14660 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
14661 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
14662 because in these cases DECL_INCOMING_RTL points us to a value of some
14663 type which is *different* from the type of the parameter itself. Thus,
14664 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
14665 such cases, the debugger would end up (for example) trying to fetch a
14666 `float' from a place which actually contains the first part of a
14667 `double'. That would lead to really incorrect and confusing
14668 output at debug-time.
14670 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
14671 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
14672 are a couple of exceptions however. On little-endian machines we can
14673 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
14674 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
14675 an integral type that is smaller than TREE_TYPE (decl). These cases arise
14676 when (on a little-endian machine) a non-prototyped function has a
14677 parameter declared to be of type `short' or `char'. In such cases,
14678 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
14679 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
14680 passed `int' value. If the debugger then uses that address to fetch
14681 a `short' or a `char' (on a little-endian machine) the result will be
14682 the correct data, so we allow for such exceptional cases below.
14684 Note that our goal here is to describe the place where the given formal
14685 parameter lives during most of the function's activation (i.e. between the
14686 end of the prologue and the start of the epilogue). We'll do that as best
14687 as we can. Note however that if the given formal parameter is modified
14688 sometime during the execution of the function, then a stack backtrace (at
14689 debug-time) will show the function as having been called with the *new*
14690 value rather than the value which was originally passed in. This happens
14691 rarely enough that it is not a major problem, but it *is* a problem, and
14692 I'd like to fix it.
14694 A future version of dwarf2out.c may generate two additional attributes for
14695 any given DW_TAG_formal_parameter DIE which will describe the "passed
14696 type" and the "passed location" for the given formal parameter in addition
14697 to the attributes we now generate to indicate the "declared type" and the
14698 "active location" for each parameter. This additional set of attributes
14699 could be used by debuggers for stack backtraces. Separately, note that
14700 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
14701 This happens (for example) for inlined-instances of inline function formal
14702 parameters which are never referenced. This really shouldn't be
14703 happening. All PARM_DECL nodes should get valid non-NULL
14704 DECL_INCOMING_RTL values. FIXME. */
14706 /* Use DECL_RTL as the "location" unless we find something better. */
14707 rtl
= DECL_RTL_IF_SET (decl
);
14709 /* When generating abstract instances, ignore everything except
14710 constants, symbols living in memory, and symbols living in
14711 fixed registers. */
14712 if (! reload_completed
)
14715 && (CONSTANT_P (rtl
)
14717 && CONSTANT_P (XEXP (rtl
, 0)))
14719 && TREE_CODE (decl
) == VAR_DECL
14720 && TREE_STATIC (decl
))))
14722 rtl
= targetm
.delegitimize_address (rtl
);
14727 else if (TREE_CODE (decl
) == PARM_DECL
)
14729 if (rtl
== NULL_RTX
14730 || is_pseudo_reg (rtl
)
14732 && is_pseudo_reg (XEXP (rtl
, 0))
14733 && DECL_INCOMING_RTL (decl
)
14734 && MEM_P (DECL_INCOMING_RTL (decl
))
14735 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
14737 tree declared_type
= TREE_TYPE (decl
);
14738 tree passed_type
= DECL_ARG_TYPE (decl
);
14739 enum machine_mode dmode
= TYPE_MODE (declared_type
);
14740 enum machine_mode pmode
= TYPE_MODE (passed_type
);
14742 /* This decl represents a formal parameter which was optimized out.
14743 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
14744 all cases where (rtl == NULL_RTX) just below. */
14745 if (dmode
== pmode
)
14746 rtl
= DECL_INCOMING_RTL (decl
);
14747 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
14748 && SCALAR_INT_MODE_P (dmode
)
14749 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
14750 && DECL_INCOMING_RTL (decl
))
14752 rtx inc
= DECL_INCOMING_RTL (decl
);
14755 else if (MEM_P (inc
))
14757 if (BYTES_BIG_ENDIAN
)
14758 rtl
= adjust_address_nv (inc
, dmode
,
14759 GET_MODE_SIZE (pmode
)
14760 - GET_MODE_SIZE (dmode
));
14767 /* If the parm was passed in registers, but lives on the stack, then
14768 make a big endian correction if the mode of the type of the
14769 parameter is not the same as the mode of the rtl. */
14770 /* ??? This is the same series of checks that are made in dbxout.c before
14771 we reach the big endian correction code there. It isn't clear if all
14772 of these checks are necessary here, but keeping them all is the safe
14774 else if (MEM_P (rtl
)
14775 && XEXP (rtl
, 0) != const0_rtx
14776 && ! CONSTANT_P (XEXP (rtl
, 0))
14777 /* Not passed in memory. */
14778 && !MEM_P (DECL_INCOMING_RTL (decl
))
14779 /* Not passed by invisible reference. */
14780 && (!REG_P (XEXP (rtl
, 0))
14781 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
14782 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
14783 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
14784 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
14787 /* Big endian correction check. */
14788 && BYTES_BIG_ENDIAN
14789 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
14790 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
14793 int offset
= (UNITS_PER_WORD
14794 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
14796 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
14797 plus_constant (XEXP (rtl
, 0), offset
));
14800 else if (TREE_CODE (decl
) == VAR_DECL
14803 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
14804 && BYTES_BIG_ENDIAN
)
14806 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
14807 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
14809 /* If a variable is declared "register" yet is smaller than
14810 a register, then if we store the variable to memory, it
14811 looks like we're storing a register-sized value, when in
14812 fact we are not. We need to adjust the offset of the
14813 storage location to reflect the actual value's bytes,
14814 else gdb will not be able to display it. */
14816 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
14817 plus_constant (XEXP (rtl
, 0), rsize
-dsize
));
14820 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
14821 and will have been substituted directly into all expressions that use it.
14822 C does not have such a concept, but C++ and other languages do. */
14823 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
14824 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
14827 rtl
= targetm
.delegitimize_address (rtl
);
14829 /* If we don't look past the constant pool, we risk emitting a
14830 reference to a constant pool entry that isn't referenced from
14831 code, and thus is not emitted. */
14833 rtl
= avoid_constant_pool_reference (rtl
);
14835 /* Try harder to get a rtl. If this symbol ends up not being emitted
14836 in the current CU, resolve_addr will remove the expression referencing
14838 if (rtl
== NULL_RTX
14839 && TREE_CODE (decl
) == VAR_DECL
14840 && !DECL_EXTERNAL (decl
)
14841 && TREE_STATIC (decl
)
14842 && DECL_NAME (decl
)
14843 && !DECL_HARD_REGISTER (decl
)
14844 && DECL_MODE (decl
) != VOIDmode
)
14846 rtl
= make_decl_rtl_for_debug (decl
);
14848 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
14849 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
14856 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
14857 returned. If so, the decl for the COMMON block is returned, and the
14858 value is the offset into the common block for the symbol. */
14861 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
14863 tree val_expr
, cvar
;
14864 enum machine_mode mode
;
14865 HOST_WIDE_INT bitsize
, bitpos
;
14867 int volatilep
= 0, unsignedp
= 0;
14869 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
14870 it does not have a value (the offset into the common area), or if it
14871 is thread local (as opposed to global) then it isn't common, and shouldn't
14872 be handled as such. */
14873 if (TREE_CODE (decl
) != VAR_DECL
14874 || !TREE_STATIC (decl
)
14875 || !DECL_HAS_VALUE_EXPR_P (decl
)
14879 val_expr
= DECL_VALUE_EXPR (decl
);
14880 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
14883 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
14884 &mode
, &unsignedp
, &volatilep
, true);
14886 if (cvar
== NULL_TREE
14887 || TREE_CODE (cvar
) != VAR_DECL
14888 || DECL_ARTIFICIAL (cvar
)
14889 || !TREE_PUBLIC (cvar
))
14893 if (offset
!= NULL
)
14895 if (!host_integerp (offset
, 0))
14897 *value
= tree_low_cst (offset
, 0);
14900 *value
+= bitpos
/ BITS_PER_UNIT
;
14905 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
14906 data attribute for a variable or a parameter. We generate the
14907 DW_AT_const_value attribute only in those cases where the given variable
14908 or parameter does not have a true "location" either in memory or in a
14909 register. This can happen (for example) when a constant is passed as an
14910 actual argument in a call to an inline function. (It's possible that
14911 these things can crop up in other ways also.) Note that one type of
14912 constant value which can be passed into an inlined function is a constant
14913 pointer. This can happen for example if an actual argument in an inlined
14914 function call evaluates to a compile-time constant address.
14916 CACHE_P is true if it is worth caching the location list for DECL,
14917 so that future calls can reuse it rather than regenerate it from scratch.
14918 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
14919 since we will need to refer to them each time the function is inlined. */
14922 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
14923 enum dwarf_attribute attr
)
14926 dw_loc_list_ref list
;
14927 var_loc_list
*loc_list
;
14928 cached_dw_loc_list
*cache
;
14931 if (TREE_CODE (decl
) == ERROR_MARK
)
14934 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
14935 || TREE_CODE (decl
) == RESULT_DECL
);
14937 /* Try to get some constant RTL for this decl, and use that as the value of
14940 rtl
= rtl_for_decl_location (decl
);
14941 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
14942 && add_const_value_attribute (die
, rtl
))
14945 /* See if we have single element location list that is equivalent to
14946 a constant value. That way we are better to use add_const_value_attribute
14947 rather than expanding constant value equivalent. */
14948 loc_list
= lookup_decl_loc (decl
);
14951 && loc_list
->first
->next
== NULL
14952 && NOTE_P (loc_list
->first
->loc
)
14953 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
14954 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
14956 struct var_loc_node
*node
;
14958 node
= loc_list
->first
;
14959 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
14960 if (GET_CODE (rtl
) == EXPR_LIST
)
14961 rtl
= XEXP (rtl
, 0);
14962 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
14963 && add_const_value_attribute (die
, rtl
))
14966 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
14967 list several times. See if we've already cached the contents. */
14969 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
14973 cache
= (cached_dw_loc_list
*)
14974 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
14976 list
= cache
->loc_list
;
14980 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
14981 /* It is usually worth caching this result if the decl is from
14982 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
14983 if (cache_p
&& list
&& list
->dw_loc_next
)
14985 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
14986 DECL_UID (decl
), INSERT
);
14987 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
14988 cache
->decl_id
= DECL_UID (decl
);
14989 cache
->loc_list
= list
;
14995 add_AT_location_description (die
, attr
, list
);
14998 /* None of that worked, so it must not really have a location;
14999 try adding a constant value attribute from the DECL_INITIAL. */
15000 return tree_add_const_value_attribute_for_decl (die
, decl
);
15003 /* Add VARIABLE and DIE into deferred locations list. */
15006 defer_location (tree variable
, dw_die_ref die
)
15008 deferred_locations entry
;
15009 entry
.variable
= variable
;
15011 VEC_safe_push (deferred_locations
, gc
, deferred_locations_list
, &entry
);
15014 /* Helper function for tree_add_const_value_attribute. Natively encode
15015 initializer INIT into an array. Return true if successful. */
15018 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15022 if (init
== NULL_TREE
)
15026 switch (TREE_CODE (init
))
15029 type
= TREE_TYPE (init
);
15030 if (TREE_CODE (type
) == ARRAY_TYPE
)
15032 tree enttype
= TREE_TYPE (type
);
15033 enum machine_mode mode
= TYPE_MODE (enttype
);
15035 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15037 if (int_size_in_bytes (type
) != size
)
15039 if (size
> TREE_STRING_LENGTH (init
))
15041 memcpy (array
, TREE_STRING_POINTER (init
),
15042 TREE_STRING_LENGTH (init
));
15043 memset (array
+ TREE_STRING_LENGTH (init
),
15044 '\0', size
- TREE_STRING_LENGTH (init
));
15047 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15052 type
= TREE_TYPE (init
);
15053 if (int_size_in_bytes (type
) != size
)
15055 if (TREE_CODE (type
) == ARRAY_TYPE
)
15057 HOST_WIDE_INT min_index
;
15058 unsigned HOST_WIDE_INT cnt
;
15059 int curpos
= 0, fieldsize
;
15060 constructor_elt
*ce
;
15062 if (TYPE_DOMAIN (type
) == NULL_TREE
15063 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
15066 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15067 if (fieldsize
<= 0)
15070 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
15071 memset (array
, '\0', size
);
15072 FOR_EACH_VEC_ELT (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15074 tree val
= ce
->value
;
15075 tree index
= ce
->index
;
15077 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15078 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
15081 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
15086 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
15089 curpos
= pos
+ fieldsize
;
15090 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15092 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
15093 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
15094 while (count
-- > 0)
15097 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
15098 curpos
+= fieldsize
;
15101 gcc_assert (curpos
<= size
);
15105 else if (TREE_CODE (type
) == RECORD_TYPE
15106 || TREE_CODE (type
) == UNION_TYPE
)
15108 tree field
= NULL_TREE
;
15109 unsigned HOST_WIDE_INT cnt
;
15110 constructor_elt
*ce
;
15112 if (int_size_in_bytes (type
) != size
)
15115 if (TREE_CODE (type
) == RECORD_TYPE
)
15116 field
= TYPE_FIELDS (type
);
15118 FOR_EACH_VEC_ELT (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15120 tree val
= ce
->value
;
15121 int pos
, fieldsize
;
15123 if (ce
->index
!= 0)
15129 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
15132 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
15133 && TYPE_DOMAIN (TREE_TYPE (field
))
15134 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
15136 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
15137 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
15139 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
15140 pos
= int_byte_position (field
);
15141 gcc_assert (pos
+ fieldsize
<= size
);
15143 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
15149 case VIEW_CONVERT_EXPR
:
15150 case NON_LVALUE_EXPR
:
15151 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
15153 return native_encode_expr (init
, array
, size
) == size
;
15157 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15158 attribute is the const value T. */
15161 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
15164 tree type
= TREE_TYPE (t
);
15167 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
15171 gcc_assert (!DECL_P (init
));
15173 rtl
= rtl_for_decl_init (init
, type
);
15175 return add_const_value_attribute (die
, rtl
);
15176 /* If the host and target are sane, try harder. */
15177 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
15178 && initializer_constant_valid_p (init
, type
))
15180 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
15181 if (size
> 0 && (int) size
== size
)
15183 unsigned char *array
= (unsigned char *)
15184 ggc_alloc_cleared_atomic (size
);
15186 if (native_encode_initializer (init
, array
, size
))
15188 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
15196 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15197 attribute is the const value of T, where T is an integral constant
15198 variable with static storage duration
15199 (so it can't be a PARM_DECL or a RESULT_DECL). */
15202 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
15206 || (TREE_CODE (decl
) != VAR_DECL
15207 && TREE_CODE (decl
) != CONST_DECL
)
15208 || (TREE_CODE (decl
) == VAR_DECL
15209 && !TREE_STATIC (decl
)))
15212 if (TREE_READONLY (decl
)
15213 && ! TREE_THIS_VOLATILE (decl
)
15214 && DECL_INITIAL (decl
))
15219 /* Don't add DW_AT_const_value if abstract origin already has one. */
15220 if (get_AT (var_die
, DW_AT_const_value
))
15223 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
15226 /* Convert the CFI instructions for the current function into a
15227 location list. This is used for DW_AT_frame_base when we targeting
15228 a dwarf2 consumer that does not support the dwarf3
15229 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15232 static dw_loc_list_ref
15233 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
15237 dw_loc_list_ref list
, *list_tail
;
15239 dw_cfa_location last_cfa
, next_cfa
;
15240 const char *start_label
, *last_label
, *section
;
15241 dw_cfa_location remember
;
15244 gcc_assert (fde
!= NULL
);
15246 section
= secname_for_decl (current_function_decl
);
15250 memset (&next_cfa
, 0, sizeof (next_cfa
));
15251 next_cfa
.reg
= INVALID_REGNUM
;
15252 remember
= next_cfa
;
15254 start_label
= fde
->dw_fde_begin
;
15256 /* ??? Bald assumption that the CIE opcode list does not contain
15257 advance opcodes. */
15258 FOR_EACH_VEC_ELT (dw_cfi_ref
, cie_cfi_vec
, ix
, cfi
)
15259 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15261 last_cfa
= next_cfa
;
15262 last_label
= start_label
;
15264 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
15266 /* If the first partition contained no CFI adjustments, the
15267 CIE opcodes apply to the whole first partition. */
15268 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15269 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
15270 list_tail
=&(*list_tail
)->dw_loc_next
;
15271 start_label
= last_label
= fde
->dw_fde_second_begin
;
15274 FOR_EACH_VEC_ELT (dw_cfi_ref
, fde
->dw_fde_cfi
, ix
, cfi
)
15276 switch (cfi
->dw_cfi_opc
)
15278 case DW_CFA_set_loc
:
15279 case DW_CFA_advance_loc1
:
15280 case DW_CFA_advance_loc2
:
15281 case DW_CFA_advance_loc4
:
15282 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15284 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15285 start_label
, last_label
, section
);
15287 list_tail
= &(*list_tail
)->dw_loc_next
;
15288 last_cfa
= next_cfa
;
15289 start_label
= last_label
;
15291 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
15294 case DW_CFA_advance_loc
:
15295 /* The encoding is complex enough that we should never emit this. */
15296 gcc_unreachable ();
15299 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15302 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
15304 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15306 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15307 start_label
, last_label
, section
);
15309 list_tail
= &(*list_tail
)->dw_loc_next
;
15310 last_cfa
= next_cfa
;
15311 start_label
= last_label
;
15313 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15314 start_label
, fde
->dw_fde_end
, section
);
15315 list_tail
= &(*list_tail
)->dw_loc_next
;
15316 start_label
= last_label
= fde
->dw_fde_second_begin
;
15320 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15322 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15323 start_label
, last_label
, section
);
15324 list_tail
= &(*list_tail
)->dw_loc_next
;
15325 start_label
= last_label
;
15328 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
15330 fde
->dw_fde_second_begin
15331 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
15334 if (list
&& list
->dw_loc_next
)
15340 /* Compute a displacement from the "steady-state frame pointer" to the
15341 frame base (often the same as the CFA), and store it in
15342 frame_pointer_fb_offset. OFFSET is added to the displacement
15343 before the latter is negated. */
15346 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
15350 #ifdef FRAME_POINTER_CFA_OFFSET
15351 reg
= frame_pointer_rtx
;
15352 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
15354 reg
= arg_pointer_rtx
;
15355 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
15358 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
15359 if (GET_CODE (elim
) == PLUS
)
15361 offset
+= INTVAL (XEXP (elim
, 1));
15362 elim
= XEXP (elim
, 0);
15365 frame_pointer_fb_offset
= -offset
;
15367 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15368 in which to eliminate. This is because it's stack pointer isn't
15369 directly accessible as a register within the ISA. To work around
15370 this, assume that while we cannot provide a proper value for
15371 frame_pointer_fb_offset, we won't need one either. */
15372 frame_pointer_fb_offset_valid
15373 = ((SUPPORTS_STACK_ALIGNMENT
15374 && (elim
== hard_frame_pointer_rtx
15375 || elim
== stack_pointer_rtx
))
15376 || elim
== (frame_pointer_needed
15377 ? hard_frame_pointer_rtx
15378 : stack_pointer_rtx
));
15381 /* Generate a DW_AT_name attribute given some string value to be included as
15382 the value of the attribute. */
15385 add_name_attribute (dw_die_ref die
, const char *name_string
)
15387 if (name_string
!= NULL
&& *name_string
!= 0)
15389 if (demangle_name_func
)
15390 name_string
= (*demangle_name_func
) (name_string
);
15392 add_AT_string (die
, DW_AT_name
, name_string
);
15396 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
15397 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
15398 of TYPE accordingly.
15400 ??? This is a temporary measure until after we're able to generate
15401 regular DWARF for the complex Ada type system. */
15404 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
15405 dw_die_ref context_die
)
15408 dw_die_ref dtype_die
;
15410 if (!lang_hooks
.types
.descriptive_type
)
15413 dtype
= lang_hooks
.types
.descriptive_type (type
);
15417 dtype_die
= lookup_type_die (dtype
);
15420 /* The descriptive type indirectly references TYPE if this is also the
15421 case for TYPE itself. Do not deal with the circularity here. */
15422 TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
)) = 1;
15423 gen_type_die (dtype
, context_die
);
15424 TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
)) = 0;
15425 dtype_die
= lookup_type_die (dtype
);
15426 gcc_assert (dtype_die
);
15429 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
15432 /* Generate a DW_AT_comp_dir attribute for DIE. */
15435 add_comp_dir_attribute (dw_die_ref die
)
15437 const char *wd
= get_src_pwd ();
15443 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
15447 wdlen
= strlen (wd
);
15448 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
15450 wd1
[wdlen
] = DIR_SEPARATOR
;
15451 wd1
[wdlen
+ 1] = 0;
15455 add_AT_string (die
, DW_AT_comp_dir
, remap_debug_filename (wd
));
15458 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
15462 lower_bound_default (void)
15464 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
15469 case DW_LANG_C_plus_plus
:
15471 case DW_LANG_ObjC_plus_plus
:
15474 case DW_LANG_Fortran77
:
15475 case DW_LANG_Fortran90
:
15476 case DW_LANG_Fortran95
:
15480 case DW_LANG_Python
:
15481 return dwarf_version
>= 4 ? 0 : -1;
15482 case DW_LANG_Ada95
:
15483 case DW_LANG_Ada83
:
15484 case DW_LANG_Cobol74
:
15485 case DW_LANG_Cobol85
:
15486 case DW_LANG_Pascal83
:
15487 case DW_LANG_Modula2
:
15489 return dwarf_version
>= 4 ? 1 : -1;
15495 /* Given a tree node describing an array bound (either lower or upper) output
15496 a representation for that bound. */
15499 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
15501 switch (TREE_CODE (bound
))
15506 /* All fixed-bounds are represented by INTEGER_CST nodes. */
15509 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
15512 /* Use the default if possible. */
15513 if (bound_attr
== DW_AT_lower_bound
15514 && host_integerp (bound
, 0)
15515 && (dflt
= lower_bound_default ()) != -1
15516 && tree_low_cst (bound
, 0) == dflt
)
15519 /* Otherwise represent the bound as an unsigned value with the
15520 precision of its type. The precision and signedness of the
15521 type will be necessary to re-interpret it unambiguously. */
15522 else if (prec
< HOST_BITS_PER_WIDE_INT
)
15524 unsigned HOST_WIDE_INT mask
15525 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
15526 add_AT_unsigned (subrange_die
, bound_attr
,
15527 TREE_INT_CST_LOW (bound
) & mask
);
15529 else if (prec
== HOST_BITS_PER_WIDE_INT
15530 || TREE_INT_CST_HIGH (bound
) == 0)
15531 add_AT_unsigned (subrange_die
, bound_attr
,
15532 TREE_INT_CST_LOW (bound
));
15534 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
15535 TREE_INT_CST_LOW (bound
));
15540 case VIEW_CONVERT_EXPR
:
15541 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
15551 dw_die_ref decl_die
= lookup_decl_die (bound
);
15553 /* ??? Can this happen, or should the variable have been bound
15554 first? Probably it can, since I imagine that we try to create
15555 the types of parameters in the order in which they exist in
15556 the list, and won't have created a forward reference to a
15557 later parameter. */
15558 if (decl_die
!= NULL
)
15560 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
15568 /* Otherwise try to create a stack operation procedure to
15569 evaluate the value of the array bound. */
15571 dw_die_ref ctx
, decl_die
;
15572 dw_loc_list_ref list
;
15574 list
= loc_list_from_tree (bound
, 2);
15575 if (list
== NULL
|| single_element_loc_list_p (list
))
15577 /* If DW_AT_*bound is not a reference nor constant, it is
15578 a DWARF expression rather than location description.
15579 For that loc_list_from_tree (bound, 0) is needed.
15580 If that fails to give a single element list,
15581 fall back to outputting this as a reference anyway. */
15582 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
15583 if (list2
&& single_element_loc_list_p (list2
))
15585 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
15592 if (current_function_decl
== 0)
15593 ctx
= comp_unit_die ();
15595 ctx
= lookup_decl_die (current_function_decl
);
15597 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
15598 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
15599 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
15600 add_AT_location_description (decl_die
, DW_AT_location
, list
);
15601 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
15607 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
15608 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
15609 Note that the block of subscript information for an array type also
15610 includes information about the element type of the given array type. */
15613 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
15615 unsigned dimension_number
;
15617 dw_die_ref subrange_die
;
15619 for (dimension_number
= 0;
15620 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
15621 type
= TREE_TYPE (type
), dimension_number
++)
15623 tree domain
= TYPE_DOMAIN (type
);
15625 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
15628 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
15629 and (in GNU C only) variable bounds. Handle all three forms
15631 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
15634 /* We have an array type with specified bounds. */
15635 lower
= TYPE_MIN_VALUE (domain
);
15636 upper
= TYPE_MAX_VALUE (domain
);
15638 /* Define the index type. */
15639 if (TREE_TYPE (domain
))
15641 /* ??? This is probably an Ada unnamed subrange type. Ignore the
15642 TREE_TYPE field. We can't emit debug info for this
15643 because it is an unnamed integral type. */
15644 if (TREE_CODE (domain
) == INTEGER_TYPE
15645 && TYPE_NAME (domain
) == NULL_TREE
15646 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
15647 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
15650 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
15654 /* ??? If upper is NULL, the array has unspecified length,
15655 but it does have a lower bound. This happens with Fortran
15657 Since the debugger is definitely going to need to know N
15658 to produce useful results, go ahead and output the lower
15659 bound solo, and hope the debugger can cope. */
15661 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
15663 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
15666 /* Otherwise we have an array type with an unspecified length. The
15667 DWARF-2 spec does not say how to handle this; let's just leave out the
15673 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
15677 switch (TREE_CODE (tree_node
))
15682 case ENUMERAL_TYPE
:
15685 case QUAL_UNION_TYPE
:
15686 size
= int_size_in_bytes (tree_node
);
15689 /* For a data member of a struct or union, the DW_AT_byte_size is
15690 generally given as the number of bytes normally allocated for an
15691 object of the *declared* type of the member itself. This is true
15692 even for bit-fields. */
15693 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
15696 gcc_unreachable ();
15699 /* Note that `size' might be -1 when we get to this point. If it is, that
15700 indicates that the byte size of the entity in question is variable. We
15701 have no good way of expressing this fact in Dwarf at the present time,
15702 so just let the -1 pass on through. */
15703 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
15706 /* For a FIELD_DECL node which represents a bit-field, output an attribute
15707 which specifies the distance in bits from the highest order bit of the
15708 "containing object" for the bit-field to the highest order bit of the
15711 For any given bit-field, the "containing object" is a hypothetical object
15712 (of some integral or enum type) within which the given bit-field lives. The
15713 type of this hypothetical "containing object" is always the same as the
15714 declared type of the individual bit-field itself. The determination of the
15715 exact location of the "containing object" for a bit-field is rather
15716 complicated. It's handled by the `field_byte_offset' function (above).
15718 Note that it is the size (in bytes) of the hypothetical "containing object"
15719 which will be given in the DW_AT_byte_size attribute for this bit-field.
15720 (See `byte_size_attribute' above). */
15723 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
15725 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
15726 tree type
= DECL_BIT_FIELD_TYPE (decl
);
15727 HOST_WIDE_INT bitpos_int
;
15728 HOST_WIDE_INT highest_order_object_bit_offset
;
15729 HOST_WIDE_INT highest_order_field_bit_offset
;
15730 HOST_WIDE_INT bit_offset
;
15732 /* Must be a field and a bit field. */
15733 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
15735 /* We can't yet handle bit-fields whose offsets are variable, so if we
15736 encounter such things, just return without generating any attribute
15737 whatsoever. Likewise for variable or too large size. */
15738 if (! host_integerp (bit_position (decl
), 0)
15739 || ! host_integerp (DECL_SIZE (decl
), 1))
15742 bitpos_int
= int_bit_position (decl
);
15744 /* Note that the bit offset is always the distance (in bits) from the
15745 highest-order bit of the "containing object" to the highest-order bit of
15746 the bit-field itself. Since the "high-order end" of any object or field
15747 is different on big-endian and little-endian machines, the computation
15748 below must take account of these differences. */
15749 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
15750 highest_order_field_bit_offset
= bitpos_int
;
15752 if (! BYTES_BIG_ENDIAN
)
15754 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
15755 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
15759 = (! BYTES_BIG_ENDIAN
15760 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
15761 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
15763 if (bit_offset
< 0)
15764 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
15766 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
15769 /* For a FIELD_DECL node which represents a bit field, output an attribute
15770 which specifies the length in bits of the given field. */
15773 add_bit_size_attribute (dw_die_ref die
, tree decl
)
15775 /* Must be a field and a bit field. */
15776 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
15777 && DECL_BIT_FIELD_TYPE (decl
));
15779 if (host_integerp (DECL_SIZE (decl
), 1))
15780 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
15783 /* If the compiled language is ANSI C, then add a 'prototyped'
15784 attribute, if arg types are given for the parameters of a function. */
15787 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
15789 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
15790 && prototype_p (func_type
))
15791 add_AT_flag (die
, DW_AT_prototyped
, 1);
15794 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
15795 by looking in either the type declaration or object declaration
15798 static inline dw_die_ref
15799 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
15801 dw_die_ref origin_die
= NULL
;
15803 if (TREE_CODE (origin
) != FUNCTION_DECL
)
15805 /* We may have gotten separated from the block for the inlined
15806 function, if we're in an exception handler or some such; make
15807 sure that the abstract function has been written out.
15809 Doing this for nested functions is wrong, however; functions are
15810 distinct units, and our context might not even be inline. */
15814 fn
= TYPE_STUB_DECL (fn
);
15816 fn
= decl_function_context (fn
);
15818 dwarf2out_abstract_function (fn
);
15821 if (DECL_P (origin
))
15822 origin_die
= lookup_decl_die (origin
);
15823 else if (TYPE_P (origin
))
15824 origin_die
= lookup_type_die (origin
);
15826 /* XXX: Functions that are never lowered don't always have correct block
15827 trees (in the case of java, they simply have no block tree, in some other
15828 languages). For these functions, there is nothing we can really do to
15829 output correct debug info for inlined functions in all cases. Rather
15830 than die, we'll just produce deficient debug info now, in that we will
15831 have variables without a proper abstract origin. In the future, when all
15832 functions are lowered, we should re-add a gcc_assert (origin_die)
15836 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
15840 /* We do not currently support the pure_virtual attribute. */
15843 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
15845 if (DECL_VINDEX (func_decl
))
15847 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
15849 if (host_integerp (DECL_VINDEX (func_decl
), 0))
15850 add_AT_loc (die
, DW_AT_vtable_elem_location
,
15851 new_loc_descr (DW_OP_constu
,
15852 tree_low_cst (DECL_VINDEX (func_decl
), 0),
15855 /* GNU extension: Record what type this method came from originally. */
15856 if (debug_info_level
> DINFO_LEVEL_TERSE
15857 && DECL_CONTEXT (func_decl
))
15858 add_AT_die_ref (die
, DW_AT_containing_type
,
15859 lookup_type_die (DECL_CONTEXT (func_decl
)));
15863 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
15864 given decl. This used to be a vendor extension until after DWARF 4
15865 standardized it. */
15868 add_linkage_attr (dw_die_ref die
, tree decl
)
15870 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
15872 /* Mimic what assemble_name_raw does with a leading '*'. */
15873 if (name
[0] == '*')
15876 if (dwarf_version
>= 4)
15877 add_AT_string (die
, DW_AT_linkage_name
, name
);
15879 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
15882 /* Add source coordinate attributes for the given decl. */
15885 add_src_coords_attributes (dw_die_ref die
, tree decl
)
15887 expanded_location s
;
15889 if (DECL_SOURCE_LOCATION (decl
) == UNKNOWN_LOCATION
)
15891 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
15892 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
15893 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
15896 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
15899 add_linkage_name (dw_die_ref die
, tree decl
)
15901 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
15902 && TREE_PUBLIC (decl
)
15903 && !DECL_ABSTRACT (decl
)
15904 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
15905 && die
->die_tag
!= DW_TAG_member
)
15907 /* Defer until we have an assembler name set. */
15908 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
15910 limbo_die_node
*asm_name
;
15912 asm_name
= ggc_alloc_cleared_limbo_die_node ();
15913 asm_name
->die
= die
;
15914 asm_name
->created_for
= decl
;
15915 asm_name
->next
= deferred_asm_name
;
15916 deferred_asm_name
= asm_name
;
15918 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
15919 add_linkage_attr (die
, decl
);
15923 /* Add a DW_AT_name attribute and source coordinate attribute for the
15924 given decl, but only if it actually has a name. */
15927 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
15931 decl_name
= DECL_NAME (decl
);
15932 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
15934 const char *name
= dwarf2_name (decl
, 0);
15936 add_name_attribute (die
, name
);
15937 if (! DECL_ARTIFICIAL (decl
))
15938 add_src_coords_attributes (die
, decl
);
15940 add_linkage_name (die
, decl
);
15943 #ifdef VMS_DEBUGGING_INFO
15944 /* Get the function's name, as described by its RTL. This may be different
15945 from the DECL_NAME name used in the source file. */
15946 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
15948 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
15949 XEXP (DECL_RTL (decl
), 0));
15950 VEC_safe_push (rtx
, gc
, used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
15952 #endif /* VMS_DEBUGGING_INFO */
15955 #ifdef VMS_DEBUGGING_INFO
15956 /* Output the debug main pointer die for VMS */
15959 dwarf2out_vms_debug_main_pointer (void)
15961 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
15964 /* Allocate the VMS debug main subprogram die. */
15965 die
= ggc_alloc_cleared_die_node ();
15966 die
->die_tag
= DW_TAG_subprogram
;
15967 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
15968 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
15969 current_function_funcdef_no
);
15970 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
15972 /* Make it the first child of comp_unit_die (). */
15973 die
->die_parent
= comp_unit_die ();
15974 if (comp_unit_die ()->die_child
)
15976 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
15977 comp_unit_die ()->die_child
->die_sib
= die
;
15981 die
->die_sib
= die
;
15982 comp_unit_die ()->die_child
= die
;
15985 #endif /* VMS_DEBUGGING_INFO */
15987 /* Push a new declaration scope. */
15990 push_decl_scope (tree scope
)
15992 VEC_safe_push (tree
, gc
, decl_scope_table
, scope
);
15995 /* Pop a declaration scope. */
15998 pop_decl_scope (void)
16000 VEC_pop (tree
, decl_scope_table
);
16003 /* Return the DIE for the scope that immediately contains this type.
16004 Non-named types get global scope. Named types nested in other
16005 types get their containing scope if it's open, or global scope
16006 otherwise. All other types (i.e. function-local named types) get
16007 the current active scope. */
16010 scope_die_for (tree t
, dw_die_ref context_die
)
16012 dw_die_ref scope_die
= NULL
;
16013 tree containing_scope
;
16016 /* Non-types always go in the current scope. */
16017 gcc_assert (TYPE_P (t
));
16019 containing_scope
= TYPE_CONTEXT (t
);
16021 /* Use the containing namespace if it was passed in (for a declaration). */
16022 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
16024 if (context_die
== lookup_decl_die (containing_scope
))
16027 containing_scope
= NULL_TREE
;
16030 /* Ignore function type "scopes" from the C frontend. They mean that
16031 a tagged type is local to a parmlist of a function declarator, but
16032 that isn't useful to DWARF. */
16033 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
16034 containing_scope
= NULL_TREE
;
16036 if (SCOPE_FILE_SCOPE_P (containing_scope
))
16037 scope_die
= comp_unit_die ();
16038 else if (TYPE_P (containing_scope
))
16040 /* For types, we can just look up the appropriate DIE. But
16041 first we check to see if we're in the middle of emitting it
16042 so we know where the new DIE should go. */
16043 for (i
= VEC_length (tree
, decl_scope_table
) - 1; i
>= 0; --i
)
16044 if (VEC_index (tree
, decl_scope_table
, i
) == containing_scope
)
16049 gcc_assert (debug_info_level
<= DINFO_LEVEL_TERSE
16050 || TREE_ASM_WRITTEN (containing_scope
));
16051 /*We are not in the middle of emitting the type
16052 CONTAINING_SCOPE. Let's see if it's emitted already. */
16053 scope_die
= lookup_type_die (containing_scope
);
16055 /* If none of the current dies are suitable, we get file scope. */
16056 if (scope_die
== NULL
)
16057 scope_die
= comp_unit_die ();
16060 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
16063 scope_die
= context_die
;
16068 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16071 local_scope_p (dw_die_ref context_die
)
16073 for (; context_die
; context_die
= context_die
->die_parent
)
16074 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
16075 || context_die
->die_tag
== DW_TAG_subprogram
)
16081 /* Returns nonzero if CONTEXT_DIE is a class. */
16084 class_scope_p (dw_die_ref context_die
)
16086 return (context_die
16087 && (context_die
->die_tag
== DW_TAG_structure_type
16088 || context_die
->die_tag
== DW_TAG_class_type
16089 || context_die
->die_tag
== DW_TAG_interface_type
16090 || context_die
->die_tag
== DW_TAG_union_type
));
16093 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16094 whether or not to treat a DIE in this context as a declaration. */
16097 class_or_namespace_scope_p (dw_die_ref context_die
)
16099 return (class_scope_p (context_die
)
16100 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
16103 /* Many forms of DIEs require a "type description" attribute. This
16104 routine locates the proper "type descriptor" die for the type given
16105 by 'type', and adds a DW_AT_type attribute below the given die. */
16108 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
16109 int decl_volatile
, dw_die_ref context_die
)
16111 enum tree_code code
= TREE_CODE (type
);
16112 dw_die_ref type_die
= NULL
;
16114 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16115 or fixed-point type, use the inner type. This is because we have no
16116 support for unnamed types in base_type_die. This can happen if this is
16117 an Ada subrange type. Correct solution is emit a subrange type die. */
16118 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
16119 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
16120 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
16122 if (code
== ERROR_MARK
16123 /* Handle a special case. For functions whose return type is void, we
16124 generate *no* type attribute. (Note that no object may have type
16125 `void', so this only applies to function return types). */
16126 || code
== VOID_TYPE
)
16129 type_die
= modified_type_die (type
,
16130 decl_const
|| TYPE_READONLY (type
),
16131 decl_volatile
|| TYPE_VOLATILE (type
),
16134 if (type_die
!= NULL
)
16135 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
16138 /* Given an object die, add the calling convention attribute for the
16139 function call type. */
16141 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
16143 enum dwarf_calling_convention value
= DW_CC_normal
;
16145 value
= ((enum dwarf_calling_convention
)
16146 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
16149 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
16151 /* DWARF 2 doesn't provide a way to identify a program's source-level
16152 entry point. DW_AT_calling_convention attributes are only meant
16153 to describe functions' calling conventions. However, lacking a
16154 better way to signal the Fortran main program, we used this for
16155 a long time, following existing custom. Now, DWARF 4 has
16156 DW_AT_main_subprogram, which we add below, but some tools still
16157 rely on the old way, which we thus keep. */
16158 value
= DW_CC_program
;
16160 if (dwarf_version
>= 4 || !dwarf_strict
)
16161 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
16164 /* Only add the attribute if the backend requests it, and
16165 is not DW_CC_normal. */
16166 if (value
&& (value
!= DW_CC_normal
))
16167 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
16170 /* Given a tree pointer to a struct, class, union, or enum type node, return
16171 a pointer to the (string) tag name for the given type, or zero if the type
16172 was declared without a tag. */
16174 static const char *
16175 type_tag (const_tree type
)
16177 const char *name
= 0;
16179 if (TYPE_NAME (type
) != 0)
16183 /* Find the IDENTIFIER_NODE for the type name. */
16184 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
16185 && !TYPE_NAMELESS (type
))
16186 t
= TYPE_NAME (type
);
16188 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16189 a TYPE_DECL node, regardless of whether or not a `typedef' was
16191 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
16192 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
16194 /* We want to be extra verbose. Don't call dwarf_name if
16195 DECL_NAME isn't set. The default hook for decl_printable_name
16196 doesn't like that, and in this context it's correct to return
16197 0, instead of "<anonymous>" or the like. */
16198 if (DECL_NAME (TYPE_NAME (type
))
16199 && !DECL_NAMELESS (TYPE_NAME (type
)))
16200 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
16203 /* Now get the name as a string, or invent one. */
16204 if (!name
&& t
!= 0)
16205 name
= IDENTIFIER_POINTER (t
);
16208 return (name
== 0 || *name
== '\0') ? 0 : name
;
16211 /* Return the type associated with a data member, make a special check
16212 for bit field types. */
16215 member_declared_type (const_tree member
)
16217 return (DECL_BIT_FIELD_TYPE (member
)
16218 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
16221 /* Get the decl's label, as described by its RTL. This may be different
16222 from the DECL_NAME name used in the source file. */
16225 static const char *
16226 decl_start_label (tree decl
)
16229 const char *fnname
;
16231 x
= DECL_RTL (decl
);
16232 gcc_assert (MEM_P (x
));
16235 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
16237 fnname
= XSTR (x
, 0);
16242 /* These routines generate the internal representation of the DIE's for
16243 the compilation unit. Debugging information is collected by walking
16244 the declaration trees passed in from dwarf2out_decl(). */
16247 gen_array_type_die (tree type
, dw_die_ref context_die
)
16249 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16250 dw_die_ref array_die
;
16252 /* GNU compilers represent multidimensional array types as sequences of one
16253 dimensional array types whose element types are themselves array types.
16254 We sometimes squish that down to a single array_type DIE with multiple
16255 subscripts in the Dwarf debugging info. The draft Dwarf specification
16256 say that we are allowed to do this kind of compression in C, because
16257 there is no difference between an array of arrays and a multidimensional
16258 array. We don't do this for Ada to remain as close as possible to the
16259 actual representation, which is especially important against the language
16260 flexibilty wrt arrays of variable size. */
16262 bool collapse_nested_arrays
= !is_ada ();
16265 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16266 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16267 if (TYPE_STRING_FLAG (type
)
16268 && TREE_CODE (type
) == ARRAY_TYPE
16270 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
16272 HOST_WIDE_INT size
;
16274 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
16275 add_name_attribute (array_die
, type_tag (type
));
16276 equate_type_number_to_die (type
, array_die
);
16277 size
= int_size_in_bytes (type
);
16279 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16280 else if (TYPE_DOMAIN (type
) != NULL_TREE
16281 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
16282 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
16284 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
16285 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
16287 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
16288 if (loc
&& size
> 0)
16290 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
16291 if (size
!= DWARF2_ADDR_SIZE
)
16292 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16298 /* ??? The SGI dwarf reader fails for array of array of enum types
16299 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
16300 array type comes before the outer array type. We thus call gen_type_die
16301 before we new_die and must prevent nested array types collapsing for this
16304 #ifdef MIPS_DEBUGGING_INFO
16305 gen_type_die (TREE_TYPE (type
), context_die
);
16306 collapse_nested_arrays
= false;
16309 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16310 add_name_attribute (array_die
, type_tag (type
));
16311 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
16312 if (TYPE_ARTIFICIAL (type
))
16313 add_AT_flag (array_die
, DW_AT_artificial
, 1);
16314 equate_type_number_to_die (type
, array_die
);
16316 if (TREE_CODE (type
) == VECTOR_TYPE
)
16317 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
16319 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16321 && TREE_CODE (type
) == ARRAY_TYPE
16322 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
16323 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
16324 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16327 /* We default the array ordering. SDB will probably do
16328 the right things even if DW_AT_ordering is not present. It's not even
16329 an issue until we start to get into multidimensional arrays anyway. If
16330 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16331 then we'll have to put the DW_AT_ordering attribute back in. (But if
16332 and when we find out that we need to put these in, we will only do so
16333 for multidimensional arrays. */
16334 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
16337 #ifdef MIPS_DEBUGGING_INFO
16338 /* The SGI compilers handle arrays of unknown bound by setting
16339 AT_declaration and not emitting any subrange DIEs. */
16340 if (TREE_CODE (type
) == ARRAY_TYPE
16341 && ! TYPE_DOMAIN (type
))
16342 add_AT_flag (array_die
, DW_AT_declaration
, 1);
16345 if (TREE_CODE (type
) == VECTOR_TYPE
)
16347 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
16348 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16349 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
16350 add_bound_info (subrange_die
, DW_AT_upper_bound
,
16351 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
16354 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
16356 /* Add representation of the type of the elements of this array type and
16357 emit the corresponding DIE if we haven't done it already. */
16358 element_type
= TREE_TYPE (type
);
16359 if (collapse_nested_arrays
)
16360 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
16362 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
16364 element_type
= TREE_TYPE (element_type
);
16367 #ifndef MIPS_DEBUGGING_INFO
16368 gen_type_die (element_type
, context_die
);
16371 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
16373 if (get_AT (array_die
, DW_AT_name
))
16374 add_pubtype (type
, array_die
);
16377 static dw_loc_descr_ref
16378 descr_info_loc (tree val
, tree base_decl
)
16380 HOST_WIDE_INT size
;
16381 dw_loc_descr_ref loc
, loc2
;
16382 enum dwarf_location_atom op
;
16384 if (val
== base_decl
)
16385 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
16387 switch (TREE_CODE (val
))
16390 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16392 return loc_descriptor_from_tree (val
, 0);
16394 if (host_integerp (val
, 0))
16395 return int_loc_descriptor (tree_low_cst (val
, 0));
16398 size
= int_size_in_bytes (TREE_TYPE (val
));
16401 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16404 if (size
== DWARF2_ADDR_SIZE
)
16405 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
16407 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
16409 case POINTER_PLUS_EXPR
:
16411 if (host_integerp (TREE_OPERAND (val
, 1), 1)
16412 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
16415 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16418 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
16424 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16427 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
16430 add_loc_descr (&loc
, loc2
);
16431 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
16453 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
16454 tree val
, tree base_decl
)
16456 dw_loc_descr_ref loc
;
16458 if (host_integerp (val
, 0))
16460 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
16464 loc
= descr_info_loc (val
, base_decl
);
16468 add_AT_loc (die
, attr
, loc
);
16471 /* This routine generates DIE for array with hidden descriptor, details
16472 are filled into *info by a langhook. */
16475 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
16476 dw_die_ref context_die
)
16478 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16479 dw_die_ref array_die
;
16482 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16483 add_name_attribute (array_die
, type_tag (type
));
16484 equate_type_number_to_die (type
, array_die
);
16486 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16488 && info
->ndimensions
>= 2)
16489 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16491 if (info
->data_location
)
16492 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
16494 if (info
->associated
)
16495 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
16497 if (info
->allocated
)
16498 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
16501 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
16503 dw_die_ref subrange_die
16504 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16506 if (info
->dimen
[dim
].lower_bound
)
16508 /* If it is the default value, omit it. */
16511 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
16512 && (dflt
= lower_bound_default ()) != -1
16513 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
16516 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
16517 info
->dimen
[dim
].lower_bound
,
16520 if (info
->dimen
[dim
].upper_bound
)
16521 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
16522 info
->dimen
[dim
].upper_bound
,
16524 if (info
->dimen
[dim
].stride
)
16525 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
16526 info
->dimen
[dim
].stride
,
16530 gen_type_die (info
->element_type
, context_die
);
16531 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
16533 if (get_AT (array_die
, DW_AT_name
))
16534 add_pubtype (type
, array_die
);
16539 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
16541 tree origin
= decl_ultimate_origin (decl
);
16542 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
16544 if (origin
!= NULL
)
16545 add_abstract_origin_attribute (decl_die
, origin
);
16548 add_name_and_src_coords_attributes (decl_die
, decl
);
16549 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
16550 0, 0, context_die
);
16553 if (DECL_ABSTRACT (decl
))
16554 equate_decl_number_to_die (decl
, decl_die
);
16556 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
16560 /* Walk through the list of incomplete types again, trying once more to
16561 emit full debugging info for them. */
16564 retry_incomplete_types (void)
16568 for (i
= VEC_length (tree
, incomplete_types
) - 1; i
>= 0; i
--)
16569 if (should_emit_struct_debug (VEC_index (tree
, incomplete_types
, i
),
16570 DINFO_USAGE_DIR_USE
))
16571 gen_type_die (VEC_index (tree
, incomplete_types
, i
), comp_unit_die ());
16574 /* Determine what tag to use for a record type. */
16576 static enum dwarf_tag
16577 record_type_tag (tree type
)
16579 if (! lang_hooks
.types
.classify_record
)
16580 return DW_TAG_structure_type
;
16582 switch (lang_hooks
.types
.classify_record (type
))
16584 case RECORD_IS_STRUCT
:
16585 return DW_TAG_structure_type
;
16587 case RECORD_IS_CLASS
:
16588 return DW_TAG_class_type
;
16590 case RECORD_IS_INTERFACE
:
16591 if (dwarf_version
>= 3 || !dwarf_strict
)
16592 return DW_TAG_interface_type
;
16593 return DW_TAG_structure_type
;
16596 gcc_unreachable ();
16600 /* Generate a DIE to represent an enumeration type. Note that these DIEs
16601 include all of the information about the enumeration values also. Each
16602 enumerated type name/value is listed as a child of the enumerated type
16606 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
16608 dw_die_ref type_die
= lookup_type_die (type
);
16610 if (type_die
== NULL
)
16612 type_die
= new_die (DW_TAG_enumeration_type
,
16613 scope_die_for (type
, context_die
), type
);
16614 equate_type_number_to_die (type
, type_die
);
16615 add_name_attribute (type_die
, type_tag (type
));
16616 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
16617 if (TYPE_ARTIFICIAL (type
))
16618 add_AT_flag (type_die
, DW_AT_artificial
, 1);
16619 if (dwarf_version
>= 4 || !dwarf_strict
)
16621 if (ENUM_IS_SCOPED (type
))
16622 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
16623 if (ENUM_IS_OPAQUE (type
))
16624 add_AT_flag (type_die
, DW_AT_declaration
, 1);
16627 else if (! TYPE_SIZE (type
))
16630 remove_AT (type_die
, DW_AT_declaration
);
16632 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
16633 given enum type is incomplete, do not generate the DW_AT_byte_size
16634 attribute or the DW_AT_element_list attribute. */
16635 if (TYPE_SIZE (type
))
16639 TREE_ASM_WRITTEN (type
) = 1;
16640 add_byte_size_attribute (type_die
, type
);
16641 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
16643 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
16644 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
16647 /* If the first reference to this type was as the return type of an
16648 inline function, then it may not have a parent. Fix this now. */
16649 if (type_die
->die_parent
== NULL
)
16650 add_child_die (scope_die_for (type
, context_die
), type_die
);
16652 for (link
= TYPE_VALUES (type
);
16653 link
!= NULL
; link
= TREE_CHAIN (link
))
16655 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
16656 tree value
= TREE_VALUE (link
);
16658 add_name_attribute (enum_die
,
16659 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
16661 if (TREE_CODE (value
) == CONST_DECL
)
16662 value
= DECL_INITIAL (value
);
16664 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
16665 /* DWARF2 does not provide a way of indicating whether or
16666 not enumeration constants are signed or unsigned. GDB
16667 always assumes the values are signed, so we output all
16668 values as if they were signed. That means that
16669 enumeration constants with very large unsigned values
16670 will appear to have negative values in the debugger. */
16671 add_AT_int (enum_die
, DW_AT_const_value
,
16672 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
16676 add_AT_flag (type_die
, DW_AT_declaration
, 1);
16678 if (get_AT (type_die
, DW_AT_name
))
16679 add_pubtype (type
, type_die
);
16684 /* Generate a DIE to represent either a real live formal parameter decl or to
16685 represent just the type of some formal parameter position in some function
16688 Note that this routine is a bit unusual because its argument may be a
16689 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
16690 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
16691 node. If it's the former then this function is being called to output a
16692 DIE to represent a formal parameter object (or some inlining thereof). If
16693 it's the latter, then this function is only being called to output a
16694 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
16695 argument type of some subprogram type.
16696 If EMIT_NAME_P is true, name and source coordinate attributes
16700 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
16701 dw_die_ref context_die
)
16703 tree node_or_origin
= node
? node
: origin
;
16704 tree ultimate_origin
;
16705 dw_die_ref parm_die
16706 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
16708 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
16710 case tcc_declaration
:
16711 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
16712 if (node
|| ultimate_origin
)
16713 origin
= ultimate_origin
;
16714 if (origin
!= NULL
)
16715 add_abstract_origin_attribute (parm_die
, origin
);
16716 else if (emit_name_p
)
16717 add_name_and_src_coords_attributes (parm_die
, node
);
16719 || (! DECL_ABSTRACT (node_or_origin
)
16720 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
16721 decl_function_context
16722 (node_or_origin
))))
16724 tree type
= TREE_TYPE (node_or_origin
);
16725 if (decl_by_reference_p (node_or_origin
))
16726 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
16729 add_type_attribute (parm_die
, type
,
16730 TREE_READONLY (node_or_origin
),
16731 TREE_THIS_VOLATILE (node_or_origin
),
16734 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
16735 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
16737 if (node
&& node
!= origin
)
16738 equate_decl_number_to_die (node
, parm_die
);
16739 if (! DECL_ABSTRACT (node_or_origin
))
16740 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
16741 node
== NULL
, DW_AT_location
);
16746 /* We were called with some kind of a ..._TYPE node. */
16747 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
16751 gcc_unreachable ();
16757 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
16758 children DW_TAG_formal_parameter DIEs representing the arguments of the
16761 PARM_PACK must be a function parameter pack.
16762 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
16763 must point to the subsequent arguments of the function PACK_ARG belongs to.
16764 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
16765 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
16766 following the last one for which a DIE was generated. */
16769 gen_formal_parameter_pack_die (tree parm_pack
,
16771 dw_die_ref subr_die
,
16775 dw_die_ref parm_pack_die
;
16777 gcc_assert (parm_pack
16778 && lang_hooks
.function_parameter_pack_p (parm_pack
)
16781 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
16782 add_src_coords_attributes (parm_pack_die
, parm_pack
);
16784 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
16786 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
16789 gen_formal_parameter_die (arg
, NULL
,
16790 false /* Don't emit name attribute. */,
16795 return parm_pack_die
;
16798 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
16799 at the end of an (ANSI prototyped) formal parameters list. */
16802 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
16804 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
16807 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
16808 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
16809 parameters as specified in some function type specification (except for
16810 those which appear as part of a function *definition*). */
16813 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
16816 tree formal_type
= NULL
;
16817 tree first_parm_type
;
16820 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
16822 arg
= DECL_ARGUMENTS (function_or_method_type
);
16823 function_or_method_type
= TREE_TYPE (function_or_method_type
);
16828 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
16830 /* Make our first pass over the list of formal parameter types and output a
16831 DW_TAG_formal_parameter DIE for each one. */
16832 for (link
= first_parm_type
; link
; )
16834 dw_die_ref parm_die
;
16836 formal_type
= TREE_VALUE (link
);
16837 if (formal_type
== void_type_node
)
16840 /* Output a (nameless) DIE to represent the formal parameter itself. */
16841 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
16842 true /* Emit name attribute. */,
16844 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
16845 && link
== first_parm_type
)
16847 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
16848 if (dwarf_version
>= 3 || !dwarf_strict
)
16849 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
16851 else if (arg
&& DECL_ARTIFICIAL (arg
))
16852 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
16854 link
= TREE_CHAIN (link
);
16856 arg
= DECL_CHAIN (arg
);
16859 /* If this function type has an ellipsis, add a
16860 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
16861 if (formal_type
!= void_type_node
)
16862 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
16864 /* Make our second (and final) pass over the list of formal parameter types
16865 and output DIEs to represent those types (as necessary). */
16866 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
16867 link
&& TREE_VALUE (link
);
16868 link
= TREE_CHAIN (link
))
16869 gen_type_die (TREE_VALUE (link
), context_die
);
16872 /* We want to generate the DIE for TYPE so that we can generate the
16873 die for MEMBER, which has been defined; we will need to refer back
16874 to the member declaration nested within TYPE. If we're trying to
16875 generate minimal debug info for TYPE, processing TYPE won't do the
16876 trick; we need to attach the member declaration by hand. */
16879 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
16881 gen_type_die (type
, context_die
);
16883 /* If we're trying to avoid duplicate debug info, we may not have
16884 emitted the member decl for this function. Emit it now. */
16885 if (TYPE_STUB_DECL (type
)
16886 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
16887 && ! lookup_decl_die (member
))
16889 dw_die_ref type_die
;
16890 gcc_assert (!decl_ultimate_origin (member
));
16892 push_decl_scope (type
);
16893 type_die
= lookup_type_die_strip_naming_typedef (type
);
16894 if (TREE_CODE (member
) == FUNCTION_DECL
)
16895 gen_subprogram_die (member
, type_die
);
16896 else if (TREE_CODE (member
) == FIELD_DECL
)
16898 /* Ignore the nameless fields that are used to skip bits but handle
16899 C++ anonymous unions and structs. */
16900 if (DECL_NAME (member
) != NULL_TREE
16901 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
16902 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
16904 gen_type_die (member_declared_type (member
), type_die
);
16905 gen_field_die (member
, type_die
);
16909 gen_variable_die (member
, NULL_TREE
, type_die
);
16915 /* Generate the DWARF2 info for the "abstract" instance of a function which we
16916 may later generate inlined and/or out-of-line instances of. */
16919 dwarf2out_abstract_function (tree decl
)
16921 dw_die_ref old_die
;
16925 htab_t old_decl_loc_table
;
16926 htab_t old_cached_dw_loc_list_table
;
16927 int old_call_site_count
, old_tail_call_site_count
;
16928 struct call_arg_loc_node
*old_call_arg_locations
;
16930 /* Make sure we have the actual abstract inline, not a clone. */
16931 decl
= DECL_ORIGIN (decl
);
16933 old_die
= lookup_decl_die (decl
);
16934 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
16935 /* We've already generated the abstract instance. */
16938 /* We can be called while recursively when seeing block defining inlined subroutine
16939 DIE. Be sure to not clobber the outer location table nor use it or we would
16940 get locations in abstract instantces. */
16941 old_decl_loc_table
= decl_loc_table
;
16942 decl_loc_table
= NULL
;
16943 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
16944 cached_dw_loc_list_table
= NULL
;
16945 old_call_arg_locations
= call_arg_locations
;
16946 call_arg_locations
= NULL
;
16947 old_call_site_count
= call_site_count
;
16948 call_site_count
= -1;
16949 old_tail_call_site_count
= tail_call_site_count
;
16950 tail_call_site_count
= -1;
16952 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
16953 we don't get confused by DECL_ABSTRACT. */
16954 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16956 context
= decl_class_context (decl
);
16958 gen_type_die_for_member
16959 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
16962 /* Pretend we've just finished compiling this function. */
16963 save_fn
= current_function_decl
;
16964 current_function_decl
= decl
;
16965 push_cfun (DECL_STRUCT_FUNCTION (decl
));
16967 was_abstract
= DECL_ABSTRACT (decl
);
16968 set_decl_abstract_flags (decl
, 1);
16969 dwarf2out_decl (decl
);
16970 if (! was_abstract
)
16971 set_decl_abstract_flags (decl
, 0);
16973 current_function_decl
= save_fn
;
16974 decl_loc_table
= old_decl_loc_table
;
16975 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
16976 call_arg_locations
= old_call_arg_locations
;
16977 call_site_count
= old_call_site_count
;
16978 tail_call_site_count
= old_tail_call_site_count
;
16982 /* Helper function of premark_used_types() which gets called through
16985 Marks the DIE of a given type in *SLOT as perennial, so it never gets
16986 marked as unused by prune_unused_types. */
16989 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
16994 type
= (tree
) *slot
;
16995 die
= lookup_type_die (type
);
16997 die
->die_perennial_p
= 1;
17001 /* Helper function of premark_types_used_by_global_vars which gets called
17002 through htab_traverse.
17004 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17005 marked as unused by prune_unused_types. The DIE of the type is marked
17006 only if the global variable using the type will actually be emitted. */
17009 premark_types_used_by_global_vars_helper (void **slot
,
17010 void *data ATTRIBUTE_UNUSED
)
17012 struct types_used_by_vars_entry
*entry
;
17015 entry
= (struct types_used_by_vars_entry
*) *slot
;
17016 gcc_assert (entry
->type
!= NULL
17017 && entry
->var_decl
!= NULL
);
17018 die
= lookup_type_die (entry
->type
);
17021 /* Ask cgraph if the global variable really is to be emitted.
17022 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17023 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
17024 if (node
&& node
->needed
)
17026 die
->die_perennial_p
= 1;
17027 /* Keep the parent DIEs as well. */
17028 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
17029 die
->die_perennial_p
= 1;
17035 /* Mark all members of used_types_hash as perennial. */
17038 premark_used_types (void)
17040 if (cfun
&& cfun
->used_types_hash
)
17041 htab_traverse (cfun
->used_types_hash
, premark_used_types_helper
, NULL
);
17044 /* Mark all members of types_used_by_vars_entry as perennial. */
17047 premark_types_used_by_global_vars (void)
17049 if (types_used_by_vars_hash
)
17050 htab_traverse (types_used_by_vars_hash
,
17051 premark_types_used_by_global_vars_helper
, NULL
);
17054 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17055 for CA_LOC call arg loc node. */
17058 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
17059 struct call_arg_loc_node
*ca_loc
)
17061 dw_die_ref stmt_die
= NULL
, die
;
17062 tree block
= ca_loc
->block
;
17065 && block
!= DECL_INITIAL (decl
)
17066 && TREE_CODE (block
) == BLOCK
)
17068 if (VEC_length (dw_die_ref
, block_map
) > BLOCK_NUMBER (block
))
17069 stmt_die
= VEC_index (dw_die_ref
, block_map
, BLOCK_NUMBER (block
));
17072 block
= BLOCK_SUPERCONTEXT (block
);
17074 if (stmt_die
== NULL
)
17075 stmt_die
= subr_die
;
17076 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
17077 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
17078 if (ca_loc
->tail_call_p
)
17079 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
17080 if (ca_loc
->symbol_ref
)
17082 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
17084 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
17086 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
);
17091 /* Generate a DIE to represent a declared function (either file-scope or
17095 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
17097 tree origin
= decl_ultimate_origin (decl
);
17098 dw_die_ref subr_die
;
17100 dw_die_ref old_die
= lookup_decl_die (decl
);
17101 int declaration
= (current_function_decl
!= decl
17102 || class_or_namespace_scope_p (context_die
));
17104 premark_used_types ();
17106 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17107 started to generate the abstract instance of an inline, decided to output
17108 its containing class, and proceeded to emit the declaration of the inline
17109 from the member list for the class. If so, DECLARATION takes priority;
17110 we'll get back to the abstract instance when done with the class. */
17112 /* The class-scope declaration DIE must be the primary DIE. */
17113 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
17116 gcc_assert (!old_die
);
17119 /* Now that the C++ front end lazily declares artificial member fns, we
17120 might need to retrofit the declaration into its class. */
17121 if (!declaration
&& !origin
&& !old_die
17122 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
17123 && !class_or_namespace_scope_p (context_die
)
17124 && debug_info_level
> DINFO_LEVEL_TERSE
)
17125 old_die
= force_decl_die (decl
);
17127 if (origin
!= NULL
)
17129 gcc_assert (!declaration
|| local_scope_p (context_die
));
17131 /* Fixup die_parent for the abstract instance of a nested
17132 inline function. */
17133 if (old_die
&& old_die
->die_parent
== NULL
)
17134 add_child_die (context_die
, old_die
);
17136 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17137 add_abstract_origin_attribute (subr_die
, origin
);
17138 /* This is where the actual code for a cloned function is.
17139 Let's emit linkage name attribute for it. This helps
17140 debuggers to e.g, set breakpoints into
17141 constructors/destructors when the user asks "break
17143 add_linkage_name (subr_die
, decl
);
17147 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17148 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17150 if (!get_AT_flag (old_die
, DW_AT_declaration
)
17151 /* We can have a normal definition following an inline one in the
17152 case of redefinition of GNU C extern inlines.
17153 It seems reasonable to use AT_specification in this case. */
17154 && !get_AT (old_die
, DW_AT_inline
))
17156 /* Detect and ignore this case, where we are trying to output
17157 something we have already output. */
17161 /* If the definition comes from the same place as the declaration,
17162 maybe use the old DIE. We always want the DIE for this function
17163 that has the *_pc attributes to be under comp_unit_die so the
17164 debugger can find it. We also need to do this for abstract
17165 instances of inlines, since the spec requires the out-of-line copy
17166 to have the same parent. For local class methods, this doesn't
17167 apply; we just use the old DIE. */
17168 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
17169 && (DECL_ARTIFICIAL (decl
)
17170 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
17171 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
17172 == (unsigned) s
.line
))))
17174 subr_die
= old_die
;
17176 /* Clear out the declaration attribute and the formal parameters.
17177 Do not remove all children, because it is possible that this
17178 declaration die was forced using force_decl_die(). In such
17179 cases die that forced declaration die (e.g. TAG_imported_module)
17180 is one of the children that we do not want to remove. */
17181 remove_AT (subr_die
, DW_AT_declaration
);
17182 remove_AT (subr_die
, DW_AT_object_pointer
);
17183 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
17187 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17188 add_AT_specification (subr_die
, old_die
);
17189 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17190 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
17191 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17192 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
17197 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17199 if (TREE_PUBLIC (decl
))
17200 add_AT_flag (subr_die
, DW_AT_external
, 1);
17202 add_name_and_src_coords_attributes (subr_die
, decl
);
17203 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17205 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
17206 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
17207 0, 0, context_die
);
17210 add_pure_or_virtual_attribute (subr_die
, decl
);
17211 if (DECL_ARTIFICIAL (decl
))
17212 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17214 add_accessibility_attribute (subr_die
, decl
);
17219 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17221 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
17223 /* If this is an explicit function declaration then generate
17224 a DW_AT_explicit attribute. */
17225 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
17226 && (dwarf_version
>= 3 || !dwarf_strict
))
17227 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
17229 /* The first time we see a member function, it is in the context of
17230 the class to which it belongs. We make sure of this by emitting
17231 the class first. The next time is the definition, which is
17232 handled above. The two may come from the same source text.
17234 Note that force_decl_die() forces function declaration die. It is
17235 later reused to represent definition. */
17236 equate_decl_number_to_die (decl
, subr_die
);
17239 else if (DECL_ABSTRACT (decl
))
17241 if (DECL_DECLARED_INLINE_P (decl
))
17243 if (cgraph_function_possibly_inlined_p (decl
))
17244 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
17246 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
17250 if (cgraph_function_possibly_inlined_p (decl
))
17251 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
17253 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
17256 if (DECL_DECLARED_INLINE_P (decl
)
17257 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
17258 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17260 equate_decl_number_to_die (decl
, subr_die
);
17262 else if (!DECL_EXTERNAL (decl
))
17264 HOST_WIDE_INT cfa_fb_offset
;
17266 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17267 equate_decl_number_to_die (decl
, subr_die
);
17269 if (!flag_reorder_blocks_and_partition
)
17271 dw_fde_ref fde
= cfun
->fde
;
17272 if (fde
->dw_fde_begin
)
17274 /* We have already generated the labels. */
17275 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, fde
->dw_fde_begin
);
17276 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, fde
->dw_fde_end
);
17280 /* Create start/end labels and add the range. */
17281 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
17282 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
17283 current_function_funcdef_no
);
17284 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
17285 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
17286 current_function_funcdef_no
);
17287 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
17290 #if VMS_DEBUGGING_INFO
17291 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17292 Section 2.3 Prologue and Epilogue Attributes:
17293 When a breakpoint is set on entry to a function, it is generally
17294 desirable for execution to be suspended, not on the very first
17295 instruction of the function, but rather at a point after the
17296 function's frame has been set up, after any language defined local
17297 declaration processing has been completed, and before execution of
17298 the first statement of the function begins. Debuggers generally
17299 cannot properly determine where this point is. Similarly for a
17300 breakpoint set on exit from a function. The prologue and epilogue
17301 attributes allow a compiler to communicate the location(s) to use. */
17304 if (fde
->dw_fde_vms_end_prologue
)
17305 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
17306 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
17308 if (fde
->dw_fde_vms_begin_epilogue
)
17309 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
17310 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
17314 add_pubname (decl
, subr_die
);
17318 /* Generate pubnames entries for the split function code ranges. */
17319 dw_fde_ref fde
= cfun
->fde
;
17321 if (fde
->dw_fde_second_begin
)
17323 if (dwarf_version
>= 3 || !dwarf_strict
)
17325 /* We should use ranges for non-contiguous code section
17326 addresses. Use the actual code range for the initial
17327 section, since the HOT/COLD labels might precede an
17328 alignment offset. */
17329 bool range_list_added
= false;
17330 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
17331 fde
->dw_fde_end
, &range_list_added
);
17332 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
17333 fde
->dw_fde_second_end
,
17334 &range_list_added
);
17335 add_pubname (decl
, subr_die
);
17336 if (range_list_added
)
17341 /* There is no real support in DW2 for this .. so we make
17342 a work-around. First, emit the pub name for the segment
17343 containing the function label. Then make and emit a
17344 simplified subprogram DIE for the second segment with the
17345 name pre-fixed by __hot/cold_sect_of_. We use the same
17346 linkage name for the second die so that gdb will find both
17347 sections when given "b foo". */
17348 const char *name
= NULL
;
17349 tree decl_name
= DECL_NAME (decl
);
17350 dw_die_ref seg_die
;
17352 /* Do the 'primary' section. */
17353 add_AT_lbl_id (subr_die
, DW_AT_low_pc
,
17354 fde
->dw_fde_begin
);
17355 add_AT_lbl_id (subr_die
, DW_AT_high_pc
,
17358 add_pubname (decl
, subr_die
);
17360 /* Build a minimal DIE for the secondary section. */
17361 seg_die
= new_die (DW_TAG_subprogram
,
17362 subr_die
->die_parent
, decl
);
17364 if (TREE_PUBLIC (decl
))
17365 add_AT_flag (seg_die
, DW_AT_external
, 1);
17367 if (decl_name
!= NULL
17368 && IDENTIFIER_POINTER (decl_name
) != NULL
)
17370 name
= dwarf2_name (decl
, 1);
17371 if (! DECL_ARTIFICIAL (decl
))
17372 add_src_coords_attributes (seg_die
, decl
);
17374 add_linkage_name (seg_die
, decl
);
17376 gcc_assert (name
!= NULL
);
17377 add_pure_or_virtual_attribute (seg_die
, decl
);
17378 if (DECL_ARTIFICIAL (decl
))
17379 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
17381 name
= concat ("__second_sect_of_", name
, NULL
);
17382 add_AT_lbl_id (seg_die
, DW_AT_low_pc
,
17383 fde
->dw_fde_second_begin
);
17384 add_AT_lbl_id (seg_die
, DW_AT_high_pc
,
17385 fde
->dw_fde_second_end
);
17386 add_name_attribute (seg_die
, name
);
17387 add_pubname_string (name
, seg_die
);
17392 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, fde
->dw_fde_begin
);
17393 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, fde
->dw_fde_end
);
17394 add_pubname (decl
, subr_die
);
17398 #ifdef MIPS_DEBUGGING_INFO
17399 /* Add a reference to the FDE for this routine. */
17400 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, cfun
->fde
->fde_index
);
17403 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
17405 /* We define the "frame base" as the function's CFA. This is more
17406 convenient for several reasons: (1) It's stable across the prologue
17407 and epilogue, which makes it better than just a frame pointer,
17408 (2) With dwarf3, there exists a one-byte encoding that allows us
17409 to reference the .debug_frame data by proxy, but failing that,
17410 (3) We can at least reuse the code inspection and interpretation
17411 code that determines the CFA position at various points in the
17413 if (dwarf_version
>= 3)
17415 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
17416 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
17420 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
17421 if (list
->dw_loc_next
)
17422 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
17424 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
17427 /* Compute a displacement from the "steady-state frame pointer" to
17428 the CFA. The former is what all stack slots and argument slots
17429 will reference in the rtl; the later is what we've told the
17430 debugger about. We'll need to adjust all frame_base references
17431 by this displacement. */
17432 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
17434 if (cfun
->static_chain_decl
)
17435 add_AT_location_description (subr_die
, DW_AT_static_link
,
17436 loc_list_from_tree (cfun
->static_chain_decl
, 2));
17439 /* Generate child dies for template paramaters. */
17440 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17441 gen_generic_params_dies (decl
);
17443 /* Now output descriptions of the arguments for this function. This gets
17444 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
17445 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
17446 `...' at the end of the formal parameter list. In order to find out if
17447 there was a trailing ellipsis or not, we must instead look at the type
17448 associated with the FUNCTION_DECL. This will be a node of type
17449 FUNCTION_TYPE. If the chain of type nodes hanging off of this
17450 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
17451 an ellipsis at the end. */
17453 /* In the case where we are describing a mere function declaration, all we
17454 need to do here (and all we *can* do here) is to describe the *types* of
17455 its formal parameters. */
17456 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
17458 else if (declaration
)
17459 gen_formal_types_die (decl
, subr_die
);
17462 /* Generate DIEs to represent all known formal parameters. */
17463 tree parm
= DECL_ARGUMENTS (decl
);
17464 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
17465 tree generic_decl_parm
= generic_decl
17466 ? DECL_ARGUMENTS (generic_decl
)
17469 /* Now we want to walk the list of parameters of the function and
17470 emit their relevant DIEs.
17472 We consider the case of DECL being an instance of a generic function
17473 as well as it being a normal function.
17475 If DECL is an instance of a generic function we walk the
17476 parameters of the generic function declaration _and_ the parameters of
17477 DECL itself. This is useful because we want to emit specific DIEs for
17478 function parameter packs and those are declared as part of the
17479 generic function declaration. In that particular case,
17480 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
17481 That DIE has children DIEs representing the set of arguments
17482 of the pack. Note that the set of pack arguments can be empty.
17483 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
17486 Otherwise, we just consider the parameters of DECL. */
17487 while (generic_decl_parm
|| parm
)
17489 if (generic_decl_parm
17490 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
17491 gen_formal_parameter_pack_die (generic_decl_parm
,
17496 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
17498 if (parm
== DECL_ARGUMENTS (decl
)
17499 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
17501 && (dwarf_version
>= 3 || !dwarf_strict
))
17502 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
17504 parm
= DECL_CHAIN (parm
);
17507 if (generic_decl_parm
)
17508 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
17511 /* Decide whether we need an unspecified_parameters DIE at the end.
17512 There are 2 more cases to do this for: 1) the ansi ... declaration -
17513 this is detectable when the end of the arg list is not a
17514 void_type_node 2) an unprototyped function declaration (not a
17515 definition). This just means that we have no info about the
17516 parameters at all. */
17517 if (prototype_p (TREE_TYPE (decl
)))
17519 /* This is the prototyped case, check for.... */
17520 if (stdarg_p (TREE_TYPE (decl
)))
17521 gen_unspecified_parameters_die (decl
, subr_die
);
17523 else if (DECL_INITIAL (decl
) == NULL_TREE
)
17524 gen_unspecified_parameters_die (decl
, subr_die
);
17527 /* Output Dwarf info for all of the stuff within the body of the function
17528 (if it has one - it may be just a declaration). */
17529 outer_scope
= DECL_INITIAL (decl
);
17531 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
17532 a function. This BLOCK actually represents the outermost binding contour
17533 for the function, i.e. the contour in which the function's formal
17534 parameters and labels get declared. Curiously, it appears that the front
17535 end doesn't actually put the PARM_DECL nodes for the current function onto
17536 the BLOCK_VARS list for this outer scope, but are strung off of the
17537 DECL_ARGUMENTS list for the function instead.
17539 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
17540 the LABEL_DECL nodes for the function however, and we output DWARF info
17541 for those in decls_for_scope. Just within the `outer_scope' there will be
17542 a BLOCK node representing the function's outermost pair of curly braces,
17543 and any blocks used for the base and member initializers of a C++
17544 constructor function. */
17545 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
17547 int call_site_note_count
= 0;
17548 int tail_call_site_note_count
= 0;
17550 /* Emit a DW_TAG_variable DIE for a named return value. */
17551 if (DECL_NAME (DECL_RESULT (decl
)))
17552 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
17554 current_function_has_inlines
= 0;
17555 decls_for_scope (outer_scope
, subr_die
, 0);
17557 if (call_arg_locations
&& !dwarf_strict
)
17559 struct call_arg_loc_node
*ca_loc
;
17560 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
17562 dw_die_ref die
= NULL
;
17563 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
17566 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
17567 arg
; arg
= next_arg
)
17569 dw_loc_descr_ref reg
, val
;
17570 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
17571 dw_die_ref cdie
, tdie
= NULL
;
17573 next_arg
= XEXP (arg
, 1);
17574 if (REG_P (XEXP (XEXP (arg
, 0), 0))
17576 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
17577 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
17578 && REGNO (XEXP (XEXP (arg
, 0), 0))
17579 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
17580 next_arg
= XEXP (next_arg
, 1);
17581 if (mode
== VOIDmode
)
17583 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
17584 if (mode
== VOIDmode
)
17585 mode
= GET_MODE (XEXP (arg
, 0));
17587 if (mode
== VOIDmode
|| mode
== BLKmode
)
17589 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
17591 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
17592 tloc
= XEXP (XEXP (arg
, 0), 1);
17595 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
17596 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
17598 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
17599 tlocc
= XEXP (XEXP (arg
, 0), 1);
17603 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
17604 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
17605 VAR_INIT_STATUS_INITIALIZED
);
17606 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
17608 rtx mem
= XEXP (XEXP (arg
, 0), 0);
17609 reg
= mem_loc_descriptor (XEXP (mem
, 0),
17610 get_address_mode (mem
),
17612 VAR_INIT_STATUS_INITIALIZED
);
17614 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
17615 == DEBUG_PARAMETER_REF
)
17618 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
17619 tdie
= lookup_decl_die (tdecl
);
17626 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
17627 != DEBUG_PARAMETER_REF
)
17629 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
17631 VAR_INIT_STATUS_INITIALIZED
);
17635 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
17636 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
17639 add_AT_loc (cdie
, DW_AT_location
, reg
);
17640 else if (tdie
!= NULL
)
17641 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
17642 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
17643 if (next_arg
!= XEXP (arg
, 1))
17645 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
17646 if (mode
== VOIDmode
)
17647 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
17648 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
17651 VAR_INIT_STATUS_INITIALIZED
);
17653 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
17657 && (ca_loc
->symbol_ref
|| tloc
))
17658 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
17659 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
17661 dw_loc_descr_ref tval
= NULL
;
17663 if (tloc
!= NULL_RTX
)
17664 tval
= mem_loc_descriptor (tloc
,
17665 GET_MODE (tloc
) == VOIDmode
17666 ? Pmode
: GET_MODE (tloc
),
17668 VAR_INIT_STATUS_INITIALIZED
);
17670 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
17671 else if (tlocc
!= NULL_RTX
)
17673 tval
= mem_loc_descriptor (tlocc
,
17674 GET_MODE (tlocc
) == VOIDmode
17675 ? Pmode
: GET_MODE (tlocc
),
17677 VAR_INIT_STATUS_INITIALIZED
);
17679 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
17685 call_site_note_count
++;
17686 if (ca_loc
->tail_call_p
)
17687 tail_call_site_note_count
++;
17691 call_arg_locations
= NULL
;
17692 call_arg_loc_last
= NULL
;
17693 if (tail_call_site_count
>= 0
17694 && tail_call_site_count
== tail_call_site_note_count
17697 if (call_site_count
>= 0
17698 && call_site_count
== call_site_note_count
)
17699 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
17701 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
17703 call_site_count
= -1;
17704 tail_call_site_count
= -1;
17706 /* Add the calling convention attribute if requested. */
17707 add_calling_convention_attribute (subr_die
, decl
);
17711 /* Returns a hash value for X (which really is a die_struct). */
17714 common_block_die_table_hash (const void *x
)
17716 const_dw_die_ref d
= (const_dw_die_ref
) x
;
17717 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
17720 /* Return nonzero if decl_id and die_parent of die_struct X is the same
17721 as decl_id and die_parent of die_struct Y. */
17724 common_block_die_table_eq (const void *x
, const void *y
)
17726 const_dw_die_ref d
= (const_dw_die_ref
) x
;
17727 const_dw_die_ref e
= (const_dw_die_ref
) y
;
17728 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
17731 /* Generate a DIE to represent a declared data object.
17732 Either DECL or ORIGIN must be non-null. */
17735 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
17739 tree decl_or_origin
= decl
? decl
: origin
;
17740 tree ultimate_origin
;
17741 dw_die_ref var_die
;
17742 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
17743 dw_die_ref origin_die
;
17744 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
17745 || class_or_namespace_scope_p (context_die
));
17746 bool specialization_p
= false;
17748 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
17749 if (decl
|| ultimate_origin
)
17750 origin
= ultimate_origin
;
17751 com_decl
= fortran_common (decl_or_origin
, &off
);
17753 /* Symbol in common gets emitted as a child of the common block, in the form
17754 of a data member. */
17757 dw_die_ref com_die
;
17758 dw_loc_list_ref loc
;
17759 die_node com_die_arg
;
17761 var_die
= lookup_decl_die (decl_or_origin
);
17764 if (get_AT (var_die
, DW_AT_location
) == NULL
)
17766 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
17771 /* Optimize the common case. */
17772 if (single_element_loc_list_p (loc
)
17773 && loc
->expr
->dw_loc_opc
== DW_OP_addr
17774 && loc
->expr
->dw_loc_next
== NULL
17775 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
17777 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
17778 = plus_constant (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
, off
);
17780 loc_list_plus_const (loc
, off
);
17782 add_AT_location_description (var_die
, DW_AT_location
, loc
);
17783 remove_AT (var_die
, DW_AT_declaration
);
17789 if (common_block_die_table
== NULL
)
17790 common_block_die_table
17791 = htab_create_ggc (10, common_block_die_table_hash
,
17792 common_block_die_table_eq
, NULL
);
17794 com_die_arg
.decl_id
= DECL_UID (com_decl
);
17795 com_die_arg
.die_parent
= context_die
;
17796 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
17797 loc
= loc_list_from_tree (com_decl
, 2);
17798 if (com_die
== NULL
)
17801 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
17804 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
17805 add_name_and_src_coords_attributes (com_die
, com_decl
);
17808 add_AT_location_description (com_die
, DW_AT_location
, loc
);
17809 /* Avoid sharing the same loc descriptor between
17810 DW_TAG_common_block and DW_TAG_variable. */
17811 loc
= loc_list_from_tree (com_decl
, 2);
17813 else if (DECL_EXTERNAL (decl
))
17814 add_AT_flag (com_die
, DW_AT_declaration
, 1);
17815 add_pubname_string (cnam
, com_die
); /* ??? needed? */
17816 com_die
->decl_id
= DECL_UID (com_decl
);
17817 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
17818 *slot
= (void *) com_die
;
17820 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
17822 add_AT_location_description (com_die
, DW_AT_location
, loc
);
17823 loc
= loc_list_from_tree (com_decl
, 2);
17824 remove_AT (com_die
, DW_AT_declaration
);
17826 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
17827 add_name_and_src_coords_attributes (var_die
, decl
);
17828 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
17829 TREE_THIS_VOLATILE (decl
), context_die
);
17830 add_AT_flag (var_die
, DW_AT_external
, 1);
17835 /* Optimize the common case. */
17836 if (single_element_loc_list_p (loc
)
17837 && loc
->expr
->dw_loc_opc
== DW_OP_addr
17838 && loc
->expr
->dw_loc_next
== NULL
17839 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
17840 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
17841 = plus_constant (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
, off
);
17843 loc_list_plus_const (loc
, off
);
17845 add_AT_location_description (var_die
, DW_AT_location
, loc
);
17847 else if (DECL_EXTERNAL (decl
))
17848 add_AT_flag (var_die
, DW_AT_declaration
, 1);
17849 equate_decl_number_to_die (decl
, var_die
);
17853 /* If the compiler emitted a definition for the DECL declaration
17854 and if we already emitted a DIE for it, don't emit a second
17855 DIE for it again. Allow re-declarations of DECLs that are
17856 inside functions, though. */
17857 if (old_die
&& declaration
&& !local_scope_p (context_die
))
17860 /* For static data members, the declaration in the class is supposed
17861 to have DW_TAG_member tag; the specification should still be
17862 DW_TAG_variable referencing the DW_TAG_member DIE. */
17863 if (declaration
&& class_scope_p (context_die
))
17864 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
17866 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
17869 if (origin
!= NULL
)
17870 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
17872 /* Loop unrolling can create multiple blocks that refer to the same
17873 static variable, so we must test for the DW_AT_declaration flag.
17875 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
17876 copy decls and set the DECL_ABSTRACT flag on them instead of
17879 ??? Duplicated blocks have been rewritten to use .debug_ranges.
17881 ??? The declare_in_namespace support causes us to get two DIEs for one
17882 variable, both of which are declarations. We want to avoid considering
17883 one to be a specification, so we must test that this DIE is not a
17885 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
17886 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
17888 /* This is a definition of a C++ class level static. */
17889 add_AT_specification (var_die
, old_die
);
17890 specialization_p
= true;
17891 if (DECL_NAME (decl
))
17893 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17894 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17896 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17897 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
17899 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17900 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
17902 if (old_die
->die_tag
== DW_TAG_member
)
17903 add_linkage_name (var_die
, decl
);
17907 add_name_and_src_coords_attributes (var_die
, decl
);
17909 if ((origin
== NULL
&& !specialization_p
)
17911 && !DECL_ABSTRACT (decl_or_origin
)
17912 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
17913 decl_function_context
17914 (decl_or_origin
))))
17916 tree type
= TREE_TYPE (decl_or_origin
);
17918 if (decl_by_reference_p (decl_or_origin
))
17919 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
17921 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
17922 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
17925 if (origin
== NULL
&& !specialization_p
)
17927 if (TREE_PUBLIC (decl
))
17928 add_AT_flag (var_die
, DW_AT_external
, 1);
17930 if (DECL_ARTIFICIAL (decl
))
17931 add_AT_flag (var_die
, DW_AT_artificial
, 1);
17933 add_accessibility_attribute (var_die
, decl
);
17937 add_AT_flag (var_die
, DW_AT_declaration
, 1);
17939 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
17940 equate_decl_number_to_die (decl
, var_die
);
17943 && (! DECL_ABSTRACT (decl_or_origin
)
17944 /* Local static vars are shared between all clones/inlines,
17945 so emit DW_AT_location on the abstract DIE if DECL_RTL is
17947 || (TREE_CODE (decl_or_origin
) == VAR_DECL
17948 && TREE_STATIC (decl_or_origin
)
17949 && DECL_RTL_SET_P (decl_or_origin
)))
17950 /* When abstract origin already has DW_AT_location attribute, no need
17951 to add it again. */
17952 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
17954 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
17955 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
17956 defer_location (decl_or_origin
, var_die
);
17958 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
17959 decl
== NULL
, DW_AT_location
);
17960 add_pubname (decl_or_origin
, var_die
);
17963 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
17966 /* Generate a DIE to represent a named constant. */
17969 gen_const_die (tree decl
, dw_die_ref context_die
)
17971 dw_die_ref const_die
;
17972 tree type
= TREE_TYPE (decl
);
17974 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
17975 add_name_and_src_coords_attributes (const_die
, decl
);
17976 add_type_attribute (const_die
, type
, 1, 0, context_die
);
17977 if (TREE_PUBLIC (decl
))
17978 add_AT_flag (const_die
, DW_AT_external
, 1);
17979 if (DECL_ARTIFICIAL (decl
))
17980 add_AT_flag (const_die
, DW_AT_artificial
, 1);
17981 tree_add_const_value_attribute_for_decl (const_die
, decl
);
17984 /* Generate a DIE to represent a label identifier. */
17987 gen_label_die (tree decl
, dw_die_ref context_die
)
17989 tree origin
= decl_ultimate_origin (decl
);
17990 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
17992 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
17994 if (origin
!= NULL
)
17995 add_abstract_origin_attribute (lbl_die
, origin
);
17997 add_name_and_src_coords_attributes (lbl_die
, decl
);
17999 if (DECL_ABSTRACT (decl
))
18000 equate_decl_number_to_die (decl
, lbl_die
);
18003 insn
= DECL_RTL_IF_SET (decl
);
18005 /* Deleted labels are programmer specified labels which have been
18006 eliminated because of various optimizations. We still emit them
18007 here so that it is possible to put breakpoints on them. */
18011 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
18013 /* When optimization is enabled (via -O) some parts of the compiler
18014 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18015 represent source-level labels which were explicitly declared by
18016 the user. This really shouldn't be happening though, so catch
18017 it if it ever does happen. */
18018 gcc_assert (!INSN_DELETED_P (insn
));
18020 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
18021 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18025 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
18026 && CODE_LABEL_NUMBER (insn
) != -1)
18028 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
18029 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18034 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18035 attributes to the DIE for a block STMT, to describe where the inlined
18036 function was called from. This is similar to add_src_coords_attributes. */
18039 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
18041 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
18043 if (dwarf_version
>= 3 || !dwarf_strict
)
18045 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
18046 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
18051 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18052 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18055 add_high_low_attributes (tree stmt
, dw_die_ref die
)
18057 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18059 if (BLOCK_FRAGMENT_CHAIN (stmt
)
18060 && (dwarf_version
>= 3 || !dwarf_strict
))
18064 if (inlined_function_outer_scope_p (stmt
))
18066 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18067 BLOCK_NUMBER (stmt
));
18068 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
18071 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
));
18073 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18076 add_ranges (chain
);
18077 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
18084 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18085 BLOCK_NUMBER (stmt
));
18086 add_AT_lbl_id (die
, DW_AT_low_pc
, label
);
18087 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
18088 BLOCK_NUMBER (stmt
));
18089 add_AT_lbl_id (die
, DW_AT_high_pc
, label
);
18093 /* Generate a DIE for a lexical block. */
18096 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
18098 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
18100 if (call_arg_locations
)
18102 if (VEC_length (dw_die_ref
, block_map
) <= BLOCK_NUMBER (stmt
))
18103 VEC_safe_grow_cleared (dw_die_ref
, heap
, block_map
,
18104 BLOCK_NUMBER (stmt
) + 1);
18105 VEC_replace (dw_die_ref
, block_map
, BLOCK_NUMBER (stmt
), stmt_die
);
18108 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
18109 add_high_low_attributes (stmt
, stmt_die
);
18111 decls_for_scope (stmt
, stmt_die
, depth
);
18114 /* Generate a DIE for an inlined subprogram. */
18117 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
18121 /* The instance of function that is effectively being inlined shall not
18123 gcc_assert (! BLOCK_ABSTRACT (stmt
));
18125 decl
= block_ultimate_origin (stmt
);
18127 /* Emit info for the abstract instance first, if we haven't yet. We
18128 must emit this even if the block is abstract, otherwise when we
18129 emit the block below (or elsewhere), we may end up trying to emit
18130 a die whose origin die hasn't been emitted, and crashing. */
18131 dwarf2out_abstract_function (decl
);
18133 if (! BLOCK_ABSTRACT (stmt
))
18135 dw_die_ref subr_die
18136 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
18138 if (call_arg_locations
)
18140 if (VEC_length (dw_die_ref
, block_map
) <= BLOCK_NUMBER (stmt
))
18141 VEC_safe_grow_cleared (dw_die_ref
, heap
, block_map
,
18142 BLOCK_NUMBER (stmt
) + 1);
18143 VEC_replace (dw_die_ref
, block_map
, BLOCK_NUMBER (stmt
), subr_die
);
18145 add_abstract_origin_attribute (subr_die
, decl
);
18146 if (TREE_ASM_WRITTEN (stmt
))
18147 add_high_low_attributes (stmt
, subr_die
);
18148 add_call_src_coords_attributes (stmt
, subr_die
);
18150 decls_for_scope (stmt
, subr_die
, depth
);
18151 current_function_has_inlines
= 1;
18155 /* Generate a DIE for a field in a record, or structure. */
18158 gen_field_die (tree decl
, dw_die_ref context_die
)
18160 dw_die_ref decl_die
;
18162 if (TREE_TYPE (decl
) == error_mark_node
)
18165 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
18166 add_name_and_src_coords_attributes (decl_die
, decl
);
18167 add_type_attribute (decl_die
, member_declared_type (decl
),
18168 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
18171 if (DECL_BIT_FIELD_TYPE (decl
))
18173 add_byte_size_attribute (decl_die
, decl
);
18174 add_bit_size_attribute (decl_die
, decl
);
18175 add_bit_offset_attribute (decl_die
, decl
);
18178 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
18179 add_data_member_location_attribute (decl_die
, decl
);
18181 if (DECL_ARTIFICIAL (decl
))
18182 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
18184 add_accessibility_attribute (decl_die
, decl
);
18186 /* Equate decl number to die, so that we can look up this decl later on. */
18187 equate_decl_number_to_die (decl
, decl_die
);
18191 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18192 Use modified_type_die instead.
18193 We keep this code here just in case these types of DIEs may be needed to
18194 represent certain things in other languages (e.g. Pascal) someday. */
18197 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
18200 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
18202 equate_type_number_to_die (type
, ptr_die
);
18203 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18204 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18207 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18208 Use modified_type_die instead.
18209 We keep this code here just in case these types of DIEs may be needed to
18210 represent certain things in other languages (e.g. Pascal) someday. */
18213 gen_reference_type_die (tree type
, dw_die_ref context_die
)
18215 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
18217 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
18218 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
18220 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
18222 equate_type_number_to_die (type
, ref_die
);
18223 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
18224 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18228 /* Generate a DIE for a pointer to a member type. */
18231 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
18234 = new_die (DW_TAG_ptr_to_member_type
,
18235 scope_die_for (type
, context_die
), type
);
18237 equate_type_number_to_die (type
, ptr_die
);
18238 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
18239 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
18240 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18243 typedef const char *dchar_p
; /* For DEF_VEC_P. */
18244 DEF_VEC_P(dchar_p
);
18245 DEF_VEC_ALLOC_P(dchar_p
,heap
);
18247 static char *producer_string
;
18249 /* Return a heap allocated producer string including command line options
18250 if -grecord-gcc-switches. */
18253 gen_producer_string (void)
18256 VEC(dchar_p
, heap
) *switches
= NULL
;
18257 const char *language_string
= lang_hooks
.name
;
18258 char *producer
, *tail
;
18260 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
18261 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
18263 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
18264 switch (save_decoded_options
[j
].opt_index
)
18271 case OPT_auxbase_strip
:
18280 case OPT_SPECIAL_unknown
:
18281 case OPT_SPECIAL_ignore
:
18282 case OPT_SPECIAL_program_name
:
18283 case OPT_SPECIAL_input_file
:
18284 case OPT_grecord_gcc_switches
:
18285 case OPT_gno_record_gcc_switches
:
18286 case OPT__output_pch_
:
18287 case OPT_fdiagnostics_show_location_
:
18288 case OPT_fdiagnostics_show_option
:
18289 case OPT_fverbose_asm
:
18291 case OPT__sysroot_
:
18293 case OPT_nostdinc__
:
18294 /* Ignore these. */
18297 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
18299 switch (save_decoded_options
[j
].canonical_option
[0][1])
18306 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
18313 VEC_safe_push (dchar_p
, heap
, switches
,
18314 save_decoded_options
[j
].orig_option_with_args_text
);
18315 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
18319 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
18321 sprintf (tail
, "%s %s", language_string
, version_string
);
18324 if (!dwarf_record_gcc_switches
)
18326 #ifdef MIPS_DEBUGGING_INFO
18327 /* The MIPS/SGI compilers place the 'cc' command line options in the
18328 producer string. The SGI debugger looks for -g, -g1, -g2, or -g3;
18329 if they do not appear in the producer string, the debugger reaches
18330 the conclusion that the object file is stripped and has no debugging
18331 information. To get the MIPS/SGI debugger to believe that there is
18332 debugging information in the object file, we add a -g to the producer
18334 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18336 memcpy (tail
, " -g", 3);
18342 FOR_EACH_VEC_ELT (dchar_p
, switches
, j
, p
)
18346 memcpy (tail
+ 1, p
, len
);
18351 VEC_free (dchar_p
, heap
, switches
);
18355 /* Generate the DIE for the compilation unit. */
18358 gen_compile_unit_die (const char *filename
)
18361 const char *language_string
= lang_hooks
.name
;
18364 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
18368 add_name_attribute (die
, filename
);
18369 /* Don't add cwd for <built-in>. */
18370 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
18371 add_comp_dir_attribute (die
);
18374 if (producer_string
== NULL
)
18375 producer_string
= gen_producer_string ();
18376 add_AT_string (die
, DW_AT_producer
, producer_string
);
18378 /* If our producer is LTO try to figure out a common language to use
18379 from the global list of translation units. */
18380 if (strcmp (language_string
, "GNU GIMPLE") == 0)
18384 const char *common_lang
= NULL
;
18386 FOR_EACH_VEC_ELT (tree
, all_translation_units
, i
, t
)
18388 if (!TRANSLATION_UNIT_LANGUAGE (t
))
18391 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
18392 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
18394 else if (strncmp (common_lang
, "GNU C", 5) == 0
18395 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
18396 /* Mixing C and C++ is ok, use C++ in that case. */
18397 common_lang
= "GNU C++";
18400 /* Fall back to C. */
18401 common_lang
= NULL
;
18407 language_string
= common_lang
;
18410 language
= DW_LANG_C89
;
18411 if (strcmp (language_string
, "GNU C++") == 0)
18412 language
= DW_LANG_C_plus_plus
;
18413 else if (strcmp (language_string
, "GNU F77") == 0)
18414 language
= DW_LANG_Fortran77
;
18415 else if (strcmp (language_string
, "GNU Pascal") == 0)
18416 language
= DW_LANG_Pascal83
;
18417 else if (dwarf_version
>= 3 || !dwarf_strict
)
18419 if (strcmp (language_string
, "GNU Ada") == 0)
18420 language
= DW_LANG_Ada95
;
18421 else if (strcmp (language_string
, "GNU Fortran") == 0)
18422 language
= DW_LANG_Fortran95
;
18423 else if (strcmp (language_string
, "GNU Java") == 0)
18424 language
= DW_LANG_Java
;
18425 else if (strcmp (language_string
, "GNU Objective-C") == 0)
18426 language
= DW_LANG_ObjC
;
18427 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
18428 language
= DW_LANG_ObjC_plus_plus
;
18431 add_AT_unsigned (die
, DW_AT_language
, language
);
18435 case DW_LANG_Fortran77
:
18436 case DW_LANG_Fortran90
:
18437 case DW_LANG_Fortran95
:
18438 /* Fortran has case insensitive identifiers and the front-end
18439 lowercases everything. */
18440 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
18443 /* The default DW_ID_case_sensitive doesn't need to be specified. */
18449 /* Generate the DIE for a base class. */
18452 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
18454 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
18456 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
18457 add_data_member_location_attribute (die
, binfo
);
18459 if (BINFO_VIRTUAL_P (binfo
))
18460 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
18462 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18463 children, otherwise the default is DW_ACCESS_public. In DWARF2
18464 the default has always been DW_ACCESS_private. */
18465 if (access
== access_public_node
)
18467 if (dwarf_version
== 2
18468 || context_die
->die_tag
== DW_TAG_class_type
)
18469 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
18471 else if (access
== access_protected_node
)
18472 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
18473 else if (dwarf_version
> 2
18474 && context_die
->die_tag
!= DW_TAG_class_type
)
18475 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
18478 /* Generate a DIE for a class member. */
18481 gen_member_die (tree type
, dw_die_ref context_die
)
18484 tree binfo
= TYPE_BINFO (type
);
18487 /* If this is not an incomplete type, output descriptions of each of its
18488 members. Note that as we output the DIEs necessary to represent the
18489 members of this record or union type, we will also be trying to output
18490 DIEs to represent the *types* of those members. However the `type'
18491 function (above) will specifically avoid generating type DIEs for member
18492 types *within* the list of member DIEs for this (containing) type except
18493 for those types (of members) which are explicitly marked as also being
18494 members of this (containing) type themselves. The g++ front- end can
18495 force any given type to be treated as a member of some other (containing)
18496 type by setting the TYPE_CONTEXT of the given (member) type to point to
18497 the TREE node representing the appropriate (containing) type. */
18499 /* First output info about the base classes. */
18502 VEC(tree
,gc
) *accesses
= BINFO_BASE_ACCESSES (binfo
);
18506 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
18507 gen_inheritance_die (base
,
18508 (accesses
? VEC_index (tree
, accesses
, i
)
18509 : access_public_node
), context_die
);
18512 /* Now output info about the data members and type members. */
18513 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
18515 /* If we thought we were generating minimal debug info for TYPE
18516 and then changed our minds, some of the member declarations
18517 may have already been defined. Don't define them again, but
18518 do put them in the right order. */
18520 child
= lookup_decl_die (member
);
18522 splice_child_die (context_die
, child
);
18524 gen_decl_die (member
, NULL
, context_die
);
18527 /* Now output info about the function members (if any). */
18528 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
18530 /* Don't include clones in the member list. */
18531 if (DECL_ABSTRACT_ORIGIN (member
))
18534 child
= lookup_decl_die (member
);
18536 splice_child_die (context_die
, child
);
18538 gen_decl_die (member
, NULL
, context_die
);
18542 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
18543 is set, we pretend that the type was never defined, so we only get the
18544 member DIEs needed by later specification DIEs. */
18547 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
18548 enum debug_info_usage usage
)
18550 dw_die_ref type_die
= lookup_type_die (type
);
18551 dw_die_ref scope_die
= 0;
18553 int complete
= (TYPE_SIZE (type
)
18554 && (! TYPE_STUB_DECL (type
)
18555 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
18556 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
18557 complete
= complete
&& should_emit_struct_debug (type
, usage
);
18559 if (type_die
&& ! complete
)
18562 if (TYPE_CONTEXT (type
) != NULL_TREE
18563 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
18564 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
18567 scope_die
= scope_die_for (type
, context_die
);
18569 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
18570 /* First occurrence of type or toplevel definition of nested class. */
18572 dw_die_ref old_die
= type_die
;
18574 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
18575 ? record_type_tag (type
) : DW_TAG_union_type
,
18577 equate_type_number_to_die (type
, type_die
);
18579 add_AT_specification (type_die
, old_die
);
18582 add_name_attribute (type_die
, type_tag (type
));
18583 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
18584 if (TYPE_ARTIFICIAL (type
))
18585 add_AT_flag (type_die
, DW_AT_artificial
, 1);
18589 remove_AT (type_die
, DW_AT_declaration
);
18591 /* Generate child dies for template paramaters. */
18592 if (debug_info_level
> DINFO_LEVEL_TERSE
18593 && COMPLETE_TYPE_P (type
))
18594 schedule_generic_params_dies_gen (type
);
18596 /* If this type has been completed, then give it a byte_size attribute and
18597 then give a list of members. */
18598 if (complete
&& !ns_decl
)
18600 /* Prevent infinite recursion in cases where the type of some member of
18601 this type is expressed in terms of this type itself. */
18602 TREE_ASM_WRITTEN (type
) = 1;
18603 add_byte_size_attribute (type_die
, type
);
18604 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
18606 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
18607 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
18610 /* If the first reference to this type was as the return type of an
18611 inline function, then it may not have a parent. Fix this now. */
18612 if (type_die
->die_parent
== NULL
)
18613 add_child_die (scope_die
, type_die
);
18615 push_decl_scope (type
);
18616 gen_member_die (type
, type_die
);
18619 /* GNU extension: Record what type our vtable lives in. */
18620 if (TYPE_VFIELD (type
))
18622 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
18624 gen_type_die (vtype
, context_die
);
18625 add_AT_die_ref (type_die
, DW_AT_containing_type
,
18626 lookup_type_die (vtype
));
18631 add_AT_flag (type_die
, DW_AT_declaration
, 1);
18633 /* We don't need to do this for function-local types. */
18634 if (TYPE_STUB_DECL (type
)
18635 && ! decl_function_context (TYPE_STUB_DECL (type
)))
18636 VEC_safe_push (tree
, gc
, incomplete_types
, type
);
18639 if (get_AT (type_die
, DW_AT_name
))
18640 add_pubtype (type
, type_die
);
18643 /* Generate a DIE for a subroutine _type_. */
18646 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
18648 tree return_type
= TREE_TYPE (type
);
18649 dw_die_ref subr_die
18650 = new_die (DW_TAG_subroutine_type
,
18651 scope_die_for (type
, context_die
), type
);
18653 equate_type_number_to_die (type
, subr_die
);
18654 add_prototyped_attribute (subr_die
, type
);
18655 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
18656 gen_formal_types_die (type
, subr_die
);
18658 if (get_AT (subr_die
, DW_AT_name
))
18659 add_pubtype (type
, subr_die
);
18662 /* Generate a DIE for a type definition. */
18665 gen_typedef_die (tree decl
, dw_die_ref context_die
)
18667 dw_die_ref type_die
;
18670 if (TREE_ASM_WRITTEN (decl
))
18673 TREE_ASM_WRITTEN (decl
) = 1;
18674 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
18675 origin
= decl_ultimate_origin (decl
);
18676 if (origin
!= NULL
)
18677 add_abstract_origin_attribute (type_die
, origin
);
18682 add_name_and_src_coords_attributes (type_die
, decl
);
18683 if (DECL_ORIGINAL_TYPE (decl
))
18685 type
= DECL_ORIGINAL_TYPE (decl
);
18687 gcc_assert (type
!= TREE_TYPE (decl
));
18688 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
18692 type
= TREE_TYPE (decl
);
18694 if (is_naming_typedef_decl (TYPE_NAME (type
)))
18696 /* Here, we are in the case of decl being a typedef naming
18697 an anonymous type, e.g:
18698 typedef struct {...} foo;
18699 In that case TREE_TYPE (decl) is not a typedef variant
18700 type and TYPE_NAME of the anonymous type is set to the
18701 TYPE_DECL of the typedef. This construct is emitted by
18704 TYPE is the anonymous struct named by the typedef
18705 DECL. As we need the DW_AT_type attribute of the
18706 DW_TAG_typedef to point to the DIE of TYPE, let's
18707 generate that DIE right away. add_type_attribute
18708 called below will then pick (via lookup_type_die) that
18709 anonymous struct DIE. */
18710 if (!TREE_ASM_WRITTEN (type
))
18711 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
18713 /* This is a GNU Extension. We are adding a
18714 DW_AT_linkage_name attribute to the DIE of the
18715 anonymous struct TYPE. The value of that attribute
18716 is the name of the typedef decl naming the anonymous
18717 struct. This greatly eases the work of consumers of
18718 this debug info. */
18719 add_linkage_attr (lookup_type_die (type
), decl
);
18723 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
18724 TREE_THIS_VOLATILE (decl
), context_die
);
18726 if (is_naming_typedef_decl (decl
))
18727 /* We want that all subsequent calls to lookup_type_die with
18728 TYPE in argument yield the DW_TAG_typedef we have just
18730 equate_type_number_to_die (type
, type_die
);
18732 add_accessibility_attribute (type_die
, decl
);
18735 if (DECL_ABSTRACT (decl
))
18736 equate_decl_number_to_die (decl
, type_die
);
18738 if (get_AT (type_die
, DW_AT_name
))
18739 add_pubtype (decl
, type_die
);
18742 /* Generate a DIE for a struct, class, enum or union type. */
18745 gen_tagged_type_die (tree type
,
18746 dw_die_ref context_die
,
18747 enum debug_info_usage usage
)
18751 if (type
== NULL_TREE
18752 || !is_tagged_type (type
))
18755 /* If this is a nested type whose containing class hasn't been written
18756 out yet, writing it out will cover this one, too. This does not apply
18757 to instantiations of member class templates; they need to be added to
18758 the containing class as they are generated. FIXME: This hurts the
18759 idea of combining type decls from multiple TUs, since we can't predict
18760 what set of template instantiations we'll get. */
18761 if (TYPE_CONTEXT (type
)
18762 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
18763 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
18765 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
18767 if (TREE_ASM_WRITTEN (type
))
18770 /* If that failed, attach ourselves to the stub. */
18771 push_decl_scope (TYPE_CONTEXT (type
));
18772 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
18775 else if (TYPE_CONTEXT (type
) != NULL_TREE
18776 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
18778 /* If this type is local to a function that hasn't been written
18779 out yet, use a NULL context for now; it will be fixed up in
18780 decls_for_scope. */
18781 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
18782 /* A declaration DIE doesn't count; nested types need to go in the
18784 if (context_die
&& is_declaration_die (context_die
))
18785 context_die
= NULL
;
18790 context_die
= declare_in_namespace (type
, context_die
);
18794 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
18796 /* This might have been written out by the call to
18797 declare_in_namespace. */
18798 if (!TREE_ASM_WRITTEN (type
))
18799 gen_enumeration_type_die (type
, context_die
);
18802 gen_struct_or_union_type_die (type
, context_die
, usage
);
18807 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
18808 it up if it is ever completed. gen_*_type_die will set it for us
18809 when appropriate. */
18812 /* Generate a type description DIE. */
18815 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
18816 enum debug_info_usage usage
)
18818 struct array_descr_info info
;
18820 if (type
== NULL_TREE
|| type
== error_mark_node
)
18823 if (TYPE_NAME (type
) != NULL_TREE
18824 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
18825 && is_redundant_typedef (TYPE_NAME (type
))
18826 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
18827 /* The DECL of this type is a typedef we don't want to emit debug
18828 info for but we want debug info for its underlying typedef.
18829 This can happen for e.g, the injected-class-name of a C++
18831 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
18833 /* If TYPE is a typedef type variant, let's generate debug info
18834 for the parent typedef which TYPE is a type of. */
18835 if (typedef_variant_p (type
))
18837 if (TREE_ASM_WRITTEN (type
))
18840 /* Prevent broken recursion; we can't hand off to the same type. */
18841 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
18843 /* Use the DIE of the containing namespace as the parent DIE of
18844 the type description DIE we want to generate. */
18845 if (DECL_CONTEXT (TYPE_NAME (type
))
18846 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
18847 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
18849 TREE_ASM_WRITTEN (type
) = 1;
18851 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
18855 /* If type is an anonymous tagged type named by a typedef, let's
18856 generate debug info for the typedef. */
18857 if (is_naming_typedef_decl (TYPE_NAME (type
)))
18859 /* Use the DIE of the containing namespace as the parent DIE of
18860 the type description DIE we want to generate. */
18861 if (DECL_CONTEXT (TYPE_NAME (type
))
18862 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
18863 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
18865 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
18869 /* If this is an array type with hidden descriptor, handle it first. */
18870 if (!TREE_ASM_WRITTEN (type
)
18871 && lang_hooks
.types
.get_array_descr_info
18872 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
18873 && (dwarf_version
>= 3 || !dwarf_strict
))
18875 gen_descr_array_type_die (type
, &info
, context_die
);
18876 TREE_ASM_WRITTEN (type
) = 1;
18880 /* We are going to output a DIE to represent the unqualified version
18881 of this type (i.e. without any const or volatile qualifiers) so
18882 get the main variant (i.e. the unqualified version) of this type
18883 now. (Vectors are special because the debugging info is in the
18884 cloned type itself). */
18885 if (TREE_CODE (type
) != VECTOR_TYPE
)
18886 type
= type_main_variant (type
);
18888 if (TREE_ASM_WRITTEN (type
))
18891 switch (TREE_CODE (type
))
18897 case REFERENCE_TYPE
:
18898 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
18899 ensures that the gen_type_die recursion will terminate even if the
18900 type is recursive. Recursive types are possible in Ada. */
18901 /* ??? We could perhaps do this for all types before the switch
18903 TREE_ASM_WRITTEN (type
) = 1;
18905 /* For these types, all that is required is that we output a DIE (or a
18906 set of DIEs) to represent the "basis" type. */
18907 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18908 DINFO_USAGE_IND_USE
);
18912 /* This code is used for C++ pointer-to-data-member types.
18913 Output a description of the relevant class type. */
18914 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
18915 DINFO_USAGE_IND_USE
);
18917 /* Output a description of the type of the object pointed to. */
18918 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18919 DINFO_USAGE_IND_USE
);
18921 /* Now output a DIE to represent this pointer-to-data-member type
18923 gen_ptr_to_mbr_type_die (type
, context_die
);
18926 case FUNCTION_TYPE
:
18927 /* Force out return type (in case it wasn't forced out already). */
18928 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18929 DINFO_USAGE_DIR_USE
);
18930 gen_subroutine_type_die (type
, context_die
);
18934 /* Force out return type (in case it wasn't forced out already). */
18935 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18936 DINFO_USAGE_DIR_USE
);
18937 gen_subroutine_type_die (type
, context_die
);
18941 gen_array_type_die (type
, context_die
);
18945 gen_array_type_die (type
, context_die
);
18948 case ENUMERAL_TYPE
:
18951 case QUAL_UNION_TYPE
:
18952 gen_tagged_type_die (type
, context_die
, usage
);
18958 case FIXED_POINT_TYPE
:
18961 /* No DIEs needed for fundamental types. */
18966 /* Just use DW_TAG_unspecified_type. */
18968 dw_die_ref type_die
= lookup_type_die (type
);
18969 if (type_die
== NULL
)
18971 tree name
= TYPE_NAME (type
);
18972 if (TREE_CODE (name
) == TYPE_DECL
)
18973 name
= DECL_NAME (name
);
18974 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
18975 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
18976 equate_type_number_to_die (type
, type_die
);
18982 gcc_unreachable ();
18985 TREE_ASM_WRITTEN (type
) = 1;
18989 gen_type_die (tree type
, dw_die_ref context_die
)
18991 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
18994 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
18995 things which are local to the given block. */
18998 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19000 int must_output_die
= 0;
19003 /* Ignore blocks that are NULL. */
19004 if (stmt
== NULL_TREE
)
19007 inlined_func
= inlined_function_outer_scope_p (stmt
);
19009 /* If the block is one fragment of a non-contiguous block, do not
19010 process the variables, since they will have been done by the
19011 origin block. Do process subblocks. */
19012 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
19016 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
19017 gen_block_die (sub
, context_die
, depth
+ 1);
19022 /* Determine if we need to output any Dwarf DIEs at all to represent this
19025 /* The outer scopes for inlinings *must* always be represented. We
19026 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19027 must_output_die
= 1;
19030 /* Determine if this block directly contains any "significant"
19031 local declarations which we will need to output DIEs for. */
19032 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19033 /* We are not in terse mode so *any* local declaration counts
19034 as being a "significant" one. */
19035 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
19036 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
19037 && (TREE_USED (stmt
)
19038 || TREE_ASM_WRITTEN (stmt
)
19039 || BLOCK_ABSTRACT (stmt
)));
19040 else if ((TREE_USED (stmt
)
19041 || TREE_ASM_WRITTEN (stmt
)
19042 || BLOCK_ABSTRACT (stmt
))
19043 && !dwarf2out_ignore_block (stmt
))
19044 must_output_die
= 1;
19047 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19048 DIE for any block which contains no significant local declarations at
19049 all. Rather, in such cases we just call `decls_for_scope' so that any
19050 needed Dwarf info for any sub-blocks will get properly generated. Note
19051 that in terse mode, our definition of what constitutes a "significant"
19052 local declaration gets restricted to include only inlined function
19053 instances and local (nested) function definitions. */
19054 if (must_output_die
)
19058 /* If STMT block is abstract, that means we have been called
19059 indirectly from dwarf2out_abstract_function.
19060 That function rightfully marks the descendent blocks (of
19061 the abstract function it is dealing with) as being abstract,
19062 precisely to prevent us from emitting any
19063 DW_TAG_inlined_subroutine DIE as a descendent
19064 of an abstract function instance. So in that case, we should
19065 not call gen_inlined_subroutine_die.
19067 Later though, when cgraph asks dwarf2out to emit info
19068 for the concrete instance of the function decl into which
19069 the concrete instance of STMT got inlined, the later will lead
19070 to the generation of a DW_TAG_inlined_subroutine DIE. */
19071 if (! BLOCK_ABSTRACT (stmt
))
19072 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
19075 gen_lexical_block_die (stmt
, context_die
, depth
);
19078 decls_for_scope (stmt
, context_die
, depth
);
19081 /* Process variable DECL (or variable with origin ORIGIN) within
19082 block STMT and add it to CONTEXT_DIE. */
19084 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
19087 tree decl_or_origin
= decl
? decl
: origin
;
19089 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
19090 die
= lookup_decl_die (decl_or_origin
);
19091 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
19092 && TYPE_DECL_IS_STUB (decl_or_origin
))
19093 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
19097 if (die
!= NULL
&& die
->die_parent
== NULL
)
19098 add_child_die (context_die
, die
);
19099 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
19100 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
19101 stmt
, context_die
);
19103 gen_decl_die (decl
, origin
, context_die
);
19106 /* Generate all of the decls declared within a given scope and (recursively)
19107 all of its sub-blocks. */
19110 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
19116 /* Ignore NULL blocks. */
19117 if (stmt
== NULL_TREE
)
19120 /* Output the DIEs to represent all of the data objects and typedefs
19121 declared directly within this block but not within any nested
19122 sub-blocks. Also, nested function and tag DIEs have been
19123 generated with a parent of NULL; fix that up now. */
19124 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
19125 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
19126 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
19127 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
19130 /* If we're at -g1, we're not interested in subblocks. */
19131 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19134 /* Output the DIEs to represent all sub-blocks (and the items declared
19135 therein) of this block. */
19136 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
19138 subblocks
= BLOCK_CHAIN (subblocks
))
19139 gen_block_die (subblocks
, context_die
, depth
+ 1);
19142 /* Is this a typedef we can avoid emitting? */
19145 is_redundant_typedef (const_tree decl
)
19147 if (TYPE_DECL_IS_STUB (decl
))
19150 if (DECL_ARTIFICIAL (decl
)
19151 && DECL_CONTEXT (decl
)
19152 && is_tagged_type (DECL_CONTEXT (decl
))
19153 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
19154 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
19155 /* Also ignore the artificial member typedef for the class name. */
19161 /* Return TRUE if TYPE is a typedef that names a type for linkage
19162 purposes. This kind of typedefs is produced by the C++ FE for
19165 typedef struct {...} foo;
19167 In that case, there is no typedef variant type produced for foo.
19168 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
19172 is_naming_typedef_decl (const_tree decl
)
19174 if (decl
== NULL_TREE
19175 || TREE_CODE (decl
) != TYPE_DECL
19176 || !is_tagged_type (TREE_TYPE (decl
))
19177 || DECL_IS_BUILTIN (decl
)
19178 || is_redundant_typedef (decl
)
19179 /* It looks like Ada produces TYPE_DECLs that are very similar
19180 to C++ naming typedefs but that have different
19181 semantics. Let's be specific to c++ for now. */
19185 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
19186 && TYPE_NAME (TREE_TYPE (decl
)) == decl
19187 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
19188 != TYPE_NAME (TREE_TYPE (decl
))));
19191 /* Returns the DIE for a context. */
19193 static inline dw_die_ref
19194 get_context_die (tree context
)
19198 /* Find die that represents this context. */
19199 if (TYPE_P (context
))
19201 context
= TYPE_MAIN_VARIANT (context
);
19202 return strip_naming_typedef (context
, force_type_die (context
));
19205 return force_decl_die (context
);
19207 return comp_unit_die ();
19210 /* Returns the DIE for decl. A DIE will always be returned. */
19213 force_decl_die (tree decl
)
19215 dw_die_ref decl_die
;
19216 unsigned saved_external_flag
;
19217 tree save_fn
= NULL_TREE
;
19218 decl_die
= lookup_decl_die (decl
);
19221 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
19223 decl_die
= lookup_decl_die (decl
);
19227 switch (TREE_CODE (decl
))
19229 case FUNCTION_DECL
:
19230 /* Clear current_function_decl, so that gen_subprogram_die thinks
19231 that this is a declaration. At this point, we just want to force
19232 declaration die. */
19233 save_fn
= current_function_decl
;
19234 current_function_decl
= NULL_TREE
;
19235 gen_subprogram_die (decl
, context_die
);
19236 current_function_decl
= save_fn
;
19240 /* Set external flag to force declaration die. Restore it after
19241 gen_decl_die() call. */
19242 saved_external_flag
= DECL_EXTERNAL (decl
);
19243 DECL_EXTERNAL (decl
) = 1;
19244 gen_decl_die (decl
, NULL
, context_die
);
19245 DECL_EXTERNAL (decl
) = saved_external_flag
;
19248 case NAMESPACE_DECL
:
19249 if (dwarf_version
>= 3 || !dwarf_strict
)
19250 dwarf2out_decl (decl
);
19252 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19253 decl_die
= comp_unit_die ();
19256 case TRANSLATION_UNIT_DECL
:
19257 decl_die
= comp_unit_die ();
19261 gcc_unreachable ();
19264 /* We should be able to find the DIE now. */
19266 decl_die
= lookup_decl_die (decl
);
19267 gcc_assert (decl_die
);
19273 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
19274 always returned. */
19277 force_type_die (tree type
)
19279 dw_die_ref type_die
;
19281 type_die
= lookup_type_die (type
);
19284 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
19286 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
19287 TYPE_VOLATILE (type
), context_die
);
19288 gcc_assert (type_die
);
19293 /* Force out any required namespaces to be able to output DECL,
19294 and return the new context_die for it, if it's changed. */
19297 setup_namespace_context (tree thing
, dw_die_ref context_die
)
19299 tree context
= (DECL_P (thing
)
19300 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
19301 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
19302 /* Force out the namespace. */
19303 context_die
= force_decl_die (context
);
19305 return context_die
;
19308 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
19309 type) within its namespace, if appropriate.
19311 For compatibility with older debuggers, namespace DIEs only contain
19312 declarations; all definitions are emitted at CU scope. */
19315 declare_in_namespace (tree thing
, dw_die_ref context_die
)
19317 dw_die_ref ns_context
;
19319 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19320 return context_die
;
19322 /* If this decl is from an inlined function, then don't try to emit it in its
19323 namespace, as we will get confused. It would have already been emitted
19324 when the abstract instance of the inline function was emitted anyways. */
19325 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
19326 return context_die
;
19328 ns_context
= setup_namespace_context (thing
, context_die
);
19330 if (ns_context
!= context_die
)
19334 if (DECL_P (thing
))
19335 gen_decl_die (thing
, NULL
, ns_context
);
19337 gen_type_die (thing
, ns_context
);
19339 return context_die
;
19342 /* Generate a DIE for a namespace or namespace alias. */
19345 gen_namespace_die (tree decl
, dw_die_ref context_die
)
19347 dw_die_ref namespace_die
;
19349 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
19350 they are an alias of. */
19351 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
19353 /* Output a real namespace or module. */
19354 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19355 namespace_die
= new_die (is_fortran ()
19356 ? DW_TAG_module
: DW_TAG_namespace
,
19357 context_die
, decl
);
19358 /* For Fortran modules defined in different CU don't add src coords. */
19359 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
19361 const char *name
= dwarf2_name (decl
, 0);
19363 add_name_attribute (namespace_die
, name
);
19366 add_name_and_src_coords_attributes (namespace_die
, decl
);
19367 if (DECL_EXTERNAL (decl
))
19368 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
19369 equate_decl_number_to_die (decl
, namespace_die
);
19373 /* Output a namespace alias. */
19375 /* Force out the namespace we are an alias of, if necessary. */
19376 dw_die_ref origin_die
19377 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
19379 if (DECL_FILE_SCOPE_P (decl
)
19380 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
19381 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19382 /* Now create the namespace alias DIE. */
19383 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
19384 add_name_and_src_coords_attributes (namespace_die
, decl
);
19385 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
19386 equate_decl_number_to_die (decl
, namespace_die
);
19390 /* Generate Dwarf debug information for a decl described by DECL.
19391 The return value is currently only meaningful for PARM_DECLs,
19392 for all other decls it returns NULL. */
19395 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
19397 tree decl_or_origin
= decl
? decl
: origin
;
19398 tree class_origin
= NULL
, ultimate_origin
;
19400 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
19403 switch (TREE_CODE (decl_or_origin
))
19409 if (!is_fortran () && !is_ada ())
19411 /* The individual enumerators of an enum type get output when we output
19412 the Dwarf representation of the relevant enum type itself. */
19416 /* Emit its type. */
19417 gen_type_die (TREE_TYPE (decl
), context_die
);
19419 /* And its containing namespace. */
19420 context_die
= declare_in_namespace (decl
, context_die
);
19422 gen_const_die (decl
, context_die
);
19425 case FUNCTION_DECL
:
19426 /* Don't output any DIEs to represent mere function declarations,
19427 unless they are class members or explicit block externs. */
19428 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
19429 && DECL_FILE_SCOPE_P (decl_or_origin
)
19430 && (current_function_decl
== NULL_TREE
19431 || DECL_ARTIFICIAL (decl_or_origin
)))
19436 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
19437 on local redeclarations of global functions. That seems broken. */
19438 if (current_function_decl
!= decl
)
19439 /* This is only a declaration. */;
19442 /* If we're emitting a clone, emit info for the abstract instance. */
19443 if (origin
|| DECL_ORIGIN (decl
) != decl
)
19444 dwarf2out_abstract_function (origin
19445 ? DECL_ORIGIN (origin
)
19446 : DECL_ABSTRACT_ORIGIN (decl
));
19448 /* If we're emitting an out-of-line copy of an inline function,
19449 emit info for the abstract instance and set up to refer to it. */
19450 else if (cgraph_function_possibly_inlined_p (decl
)
19451 && ! DECL_ABSTRACT (decl
)
19452 && ! class_or_namespace_scope_p (context_die
)
19453 /* dwarf2out_abstract_function won't emit a die if this is just
19454 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
19455 that case, because that works only if we have a die. */
19456 && DECL_INITIAL (decl
) != NULL_TREE
)
19458 dwarf2out_abstract_function (decl
);
19459 set_decl_origin_self (decl
);
19462 /* Otherwise we're emitting the primary DIE for this decl. */
19463 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
19465 /* Before we describe the FUNCTION_DECL itself, make sure that we
19466 have its containing type. */
19468 origin
= decl_class_context (decl
);
19469 if (origin
!= NULL_TREE
)
19470 gen_type_die (origin
, context_die
);
19472 /* And its return type. */
19473 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
19475 /* And its virtual context. */
19476 if (DECL_VINDEX (decl
) != NULL_TREE
)
19477 gen_type_die (DECL_CONTEXT (decl
), context_die
);
19479 /* Make sure we have a member DIE for decl. */
19480 if (origin
!= NULL_TREE
)
19481 gen_type_die_for_member (origin
, decl
, context_die
);
19483 /* And its containing namespace. */
19484 context_die
= declare_in_namespace (decl
, context_die
);
19487 /* Now output a DIE to represent the function itself. */
19489 gen_subprogram_die (decl
, context_die
);
19493 /* If we are in terse mode, don't generate any DIEs to represent any
19494 actual typedefs. */
19495 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19498 /* In the special case of a TYPE_DECL node representing the declaration
19499 of some type tag, if the given TYPE_DECL is marked as having been
19500 instantiated from some other (original) TYPE_DECL node (e.g. one which
19501 was generated within the original definition of an inline function) we
19502 used to generate a special (abbreviated) DW_TAG_structure_type,
19503 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
19504 should be actually referencing those DIEs, as variable DIEs with that
19505 type would be emitted already in the abstract origin, so it was always
19506 removed during unused type prunning. Don't add anything in this
19508 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
19511 if (is_redundant_typedef (decl
))
19512 gen_type_die (TREE_TYPE (decl
), context_die
);
19514 /* Output a DIE to represent the typedef itself. */
19515 gen_typedef_die (decl
, context_die
);
19519 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
19520 gen_label_die (decl
, context_die
);
19525 /* If we are in terse mode, don't generate any DIEs to represent any
19526 variable declarations or definitions. */
19527 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19530 /* Output any DIEs that are needed to specify the type of this data
19532 if (decl_by_reference_p (decl_or_origin
))
19533 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
19535 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
19537 /* And its containing type. */
19538 class_origin
= decl_class_context (decl_or_origin
);
19539 if (class_origin
!= NULL_TREE
)
19540 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
19542 /* And its containing namespace. */
19543 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
19545 /* Now output the DIE to represent the data object itself. This gets
19546 complicated because of the possibility that the VAR_DECL really
19547 represents an inlined instance of a formal parameter for an inline
19549 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
19550 if (ultimate_origin
!= NULL_TREE
19551 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
19552 gen_formal_parameter_die (decl
, origin
,
19553 true /* Emit name attribute. */,
19556 gen_variable_die (decl
, origin
, context_die
);
19560 /* Ignore the nameless fields that are used to skip bits but handle C++
19561 anonymous unions and structs. */
19562 if (DECL_NAME (decl
) != NULL_TREE
19563 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
19564 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
19566 gen_type_die (member_declared_type (decl
), context_die
);
19567 gen_field_die (decl
, context_die
);
19572 if (DECL_BY_REFERENCE (decl_or_origin
))
19573 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
19575 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
19576 return gen_formal_parameter_die (decl
, origin
,
19577 true /* Emit name attribute. */,
19580 case NAMESPACE_DECL
:
19581 case IMPORTED_DECL
:
19582 if (dwarf_version
>= 3 || !dwarf_strict
)
19583 gen_namespace_die (decl
, context_die
);
19587 /* Probably some frontend-internal decl. Assume we don't care. */
19588 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
19595 /* Output debug information for global decl DECL. Called from toplev.c after
19596 compilation proper has finished. */
19599 dwarf2out_global_decl (tree decl
)
19601 /* Output DWARF2 information for file-scope tentative data object
19602 declarations, file-scope (extern) function declarations (which
19603 had no corresponding body) and file-scope tagged type declarations
19604 and definitions which have not yet been forced out. */
19605 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
19606 dwarf2out_decl (decl
);
19609 /* Output debug information for type decl DECL. Called from toplev.c
19610 and from language front ends (to record built-in types). */
19612 dwarf2out_type_decl (tree decl
, int local
)
19615 dwarf2out_decl (decl
);
19618 /* Output debug information for imported module or decl DECL.
19619 NAME is non-NULL name in the lexical block if the decl has been renamed.
19620 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
19621 that DECL belongs to.
19622 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
19624 dwarf2out_imported_module_or_decl_1 (tree decl
,
19626 tree lexical_block
,
19627 dw_die_ref lexical_block_die
)
19629 expanded_location xloc
;
19630 dw_die_ref imported_die
= NULL
;
19631 dw_die_ref at_import_die
;
19633 if (TREE_CODE (decl
) == IMPORTED_DECL
)
19635 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
19636 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
19640 xloc
= expand_location (input_location
);
19642 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
19644 at_import_die
= force_type_die (TREE_TYPE (decl
));
19645 /* For namespace N { typedef void T; } using N::T; base_type_die
19646 returns NULL, but DW_TAG_imported_declaration requires
19647 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
19648 if (!at_import_die
)
19650 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
19651 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
19652 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
19653 gcc_assert (at_import_die
);
19658 at_import_die
= lookup_decl_die (decl
);
19659 if (!at_import_die
)
19661 /* If we're trying to avoid duplicate debug info, we may not have
19662 emitted the member decl for this field. Emit it now. */
19663 if (TREE_CODE (decl
) == FIELD_DECL
)
19665 tree type
= DECL_CONTEXT (decl
);
19667 if (TYPE_CONTEXT (type
)
19668 && TYPE_P (TYPE_CONTEXT (type
))
19669 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
19670 DINFO_USAGE_DIR_USE
))
19672 gen_type_die_for_member (type
, decl
,
19673 get_context_die (TYPE_CONTEXT (type
)));
19675 at_import_die
= force_decl_die (decl
);
19679 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
19681 if (dwarf_version
>= 3 || !dwarf_strict
)
19682 imported_die
= new_die (DW_TAG_imported_module
,
19689 imported_die
= new_die (DW_TAG_imported_declaration
,
19693 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
19694 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
19696 add_AT_string (imported_die
, DW_AT_name
,
19697 IDENTIFIER_POINTER (name
));
19698 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
19701 /* Output debug information for imported module or decl DECL.
19702 NAME is non-NULL name in context if the decl has been renamed.
19703 CHILD is true if decl is one of the renamed decls as part of
19704 importing whole module. */
19707 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
19710 /* dw_die_ref at_import_die; */
19711 dw_die_ref scope_die
;
19713 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19718 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
19719 We need decl DIE for reference and scope die. First, get DIE for the decl
19722 /* Get the scope die for decl context. Use comp_unit_die for global module
19723 or decl. If die is not found for non globals, force new die. */
19725 && TYPE_P (context
)
19726 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
19729 if (!(dwarf_version
>= 3 || !dwarf_strict
))
19732 scope_die
= get_context_die (context
);
19736 gcc_assert (scope_die
->die_child
);
19737 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
19738 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
19739 scope_die
= scope_die
->die_child
;
19742 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
19743 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
19747 /* Write the debugging output for DECL. */
19750 dwarf2out_decl (tree decl
)
19752 dw_die_ref context_die
= comp_unit_die ();
19754 switch (TREE_CODE (decl
))
19759 case FUNCTION_DECL
:
19760 /* What we would really like to do here is to filter out all mere
19761 file-scope declarations of file-scope functions which are never
19762 referenced later within this translation unit (and keep all of ones
19763 that *are* referenced later on) but we aren't clairvoyant, so we have
19764 no idea which functions will be referenced in the future (i.e. later
19765 on within the current translation unit). So here we just ignore all
19766 file-scope function declarations which are not also definitions. If
19767 and when the debugger needs to know something about these functions,
19768 it will have to hunt around and find the DWARF information associated
19769 with the definition of the function.
19771 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
19772 nodes represent definitions and which ones represent mere
19773 declarations. We have to check DECL_INITIAL instead. That's because
19774 the C front-end supports some weird semantics for "extern inline"
19775 function definitions. These can get inlined within the current
19776 translation unit (and thus, we need to generate Dwarf info for their
19777 abstract instances so that the Dwarf info for the concrete inlined
19778 instances can have something to refer to) but the compiler never
19779 generates any out-of-lines instances of such things (despite the fact
19780 that they *are* definitions).
19782 The important point is that the C front-end marks these "extern
19783 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
19784 them anyway. Note that the C++ front-end also plays some similar games
19785 for inline function definitions appearing within include files which
19786 also contain `#pragma interface' pragmas. */
19787 if (DECL_INITIAL (decl
) == NULL_TREE
)
19790 /* If we're a nested function, initially use a parent of NULL; if we're
19791 a plain function, this will be fixed up in decls_for_scope. If
19792 we're a method, it will be ignored, since we already have a DIE. */
19793 if (decl_function_context (decl
)
19794 /* But if we're in terse mode, we don't care about scope. */
19795 && debug_info_level
> DINFO_LEVEL_TERSE
)
19796 context_die
= NULL
;
19800 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
19801 declaration and if the declaration was never even referenced from
19802 within this entire compilation unit. We suppress these DIEs in
19803 order to save space in the .debug section (by eliminating entries
19804 which are probably useless). Note that we must not suppress
19805 block-local extern declarations (whether used or not) because that
19806 would screw-up the debugger's name lookup mechanism and cause it to
19807 miss things which really ought to be in scope at a given point. */
19808 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
19811 /* For local statics lookup proper context die. */
19812 if (TREE_STATIC (decl
) && decl_function_context (decl
))
19813 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
19815 /* If we are in terse mode, don't generate any DIEs to represent any
19816 variable declarations or definitions. */
19817 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19822 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19824 if (!is_fortran () && !is_ada ())
19826 if (TREE_STATIC (decl
) && decl_function_context (decl
))
19827 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
19830 case NAMESPACE_DECL
:
19831 case IMPORTED_DECL
:
19832 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19834 if (lookup_decl_die (decl
) != NULL
)
19839 /* Don't emit stubs for types unless they are needed by other DIEs. */
19840 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
19843 /* Don't bother trying to generate any DIEs to represent any of the
19844 normal built-in types for the language we are compiling. */
19845 if (DECL_IS_BUILTIN (decl
))
19848 /* If we are in terse mode, don't generate any DIEs for types. */
19849 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19852 /* If we're a function-scope tag, initially use a parent of NULL;
19853 this will be fixed up in decls_for_scope. */
19854 if (decl_function_context (decl
))
19855 context_die
= NULL
;
19863 gen_decl_die (decl
, NULL
, context_die
);
19866 /* Write the debugging output for DECL. */
19869 dwarf2out_function_decl (tree decl
)
19871 dwarf2out_decl (decl
);
19872 call_arg_locations
= NULL
;
19873 call_arg_loc_last
= NULL
;
19874 call_site_count
= -1;
19875 tail_call_site_count
= -1;
19876 VEC_free (dw_die_ref
, heap
, block_map
);
19877 htab_empty (decl_loc_table
);
19878 htab_empty (cached_dw_loc_list_table
);
19881 /* Output a marker (i.e. a label) for the beginning of the generated code for
19882 a lexical block. */
19885 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
19886 unsigned int blocknum
)
19888 switch_to_section (current_function_section ());
19889 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
19892 /* Output a marker (i.e. a label) for the end of the generated code for a
19896 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
19898 switch_to_section (current_function_section ());
19899 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
19902 /* Returns nonzero if it is appropriate not to emit any debugging
19903 information for BLOCK, because it doesn't contain any instructions.
19905 Don't allow this for blocks with nested functions or local classes
19906 as we would end up with orphans, and in the presence of scheduling
19907 we may end up calling them anyway. */
19910 dwarf2out_ignore_block (const_tree block
)
19915 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
19916 if (TREE_CODE (decl
) == FUNCTION_DECL
19917 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
19919 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
19921 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
19922 if (TREE_CODE (decl
) == FUNCTION_DECL
19923 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
19930 /* Hash table routines for file_hash. */
19933 file_table_eq (const void *p1_p
, const void *p2_p
)
19935 const struct dwarf_file_data
*const p1
=
19936 (const struct dwarf_file_data
*) p1_p
;
19937 const char *const p2
= (const char *) p2_p
;
19938 return filename_cmp (p1
->filename
, p2
) == 0;
19942 file_table_hash (const void *p_p
)
19944 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
19945 return htab_hash_string (p
->filename
);
19948 /* Lookup FILE_NAME (in the list of filenames that we know about here in
19949 dwarf2out.c) and return its "index". The index of each (known) filename is
19950 just a unique number which is associated with only that one filename. We
19951 need such numbers for the sake of generating labels (in the .debug_sfnames
19952 section) and references to those files numbers (in the .debug_srcinfo
19953 and.debug_macinfo sections). If the filename given as an argument is not
19954 found in our current list, add it to the list and assign it the next
19955 available unique index number. In order to speed up searches, we remember
19956 the index of the filename was looked up last. This handles the majority of
19959 static struct dwarf_file_data
*
19960 lookup_filename (const char *file_name
)
19963 struct dwarf_file_data
* created
;
19965 /* Check to see if the file name that was searched on the previous
19966 call matches this file name. If so, return the index. */
19967 if (file_table_last_lookup
19968 && (file_name
== file_table_last_lookup
->filename
19969 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
19970 return file_table_last_lookup
;
19972 /* Didn't match the previous lookup, search the table. */
19973 slot
= htab_find_slot_with_hash (file_table
, file_name
,
19974 htab_hash_string (file_name
), INSERT
);
19976 return (struct dwarf_file_data
*) *slot
;
19978 created
= ggc_alloc_dwarf_file_data ();
19979 created
->filename
= file_name
;
19980 created
->emitted_number
= 0;
19985 /* If the assembler will construct the file table, then translate the compiler
19986 internal file table number into the assembler file table number, and emit
19987 a .file directive if we haven't already emitted one yet. The file table
19988 numbers are different because we prune debug info for unused variables and
19989 types, which may include filenames. */
19992 maybe_emit_file (struct dwarf_file_data
* fd
)
19994 if (! fd
->emitted_number
)
19996 if (last_emitted_file
)
19997 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
19999 fd
->emitted_number
= 1;
20000 last_emitted_file
= fd
;
20002 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20004 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
20005 output_quoted_string (asm_out_file
,
20006 remap_debug_filename (fd
->filename
));
20007 fputc ('\n', asm_out_file
);
20011 return fd
->emitted_number
;
20014 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20015 That generation should happen after function debug info has been
20016 generated. The value of the attribute is the constant value of ARG. */
20019 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
20021 die_arg_entry entry
;
20026 if (!tmpl_value_parm_die_table
)
20027 tmpl_value_parm_die_table
20028 = VEC_alloc (die_arg_entry
, gc
, 32);
20032 VEC_safe_push (die_arg_entry
, gc
,
20033 tmpl_value_parm_die_table
,
20037 /* Return TRUE if T is an instance of generic type, FALSE
20041 generic_type_p (tree t
)
20043 if (t
== NULL_TREE
|| !TYPE_P (t
))
20045 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
20048 /* Schedule the generation of the generic parameter dies for the
20049 instance of generic type T. The proper generation itself is later
20050 done by gen_scheduled_generic_parms_dies. */
20053 schedule_generic_params_dies_gen (tree t
)
20055 if (!generic_type_p (t
))
20058 if (generic_type_instances
== NULL
)
20059 generic_type_instances
= VEC_alloc (tree
, gc
, 256);
20061 VEC_safe_push (tree
, gc
, generic_type_instances
, t
);
20064 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20065 by append_entry_to_tmpl_value_parm_die_table. This function must
20066 be called after function DIEs have been generated. */
20069 gen_remaining_tmpl_value_param_die_attribute (void)
20071 if (tmpl_value_parm_die_table
)
20076 FOR_EACH_VEC_ELT (die_arg_entry
, tmpl_value_parm_die_table
, i
, e
)
20077 tree_add_const_value_attribute (e
->die
, e
->arg
);
20081 /* Generate generic parameters DIEs for instances of generic types
20082 that have been previously scheduled by
20083 schedule_generic_params_dies_gen. This function must be called
20084 after all the types of the CU have been laid out. */
20087 gen_scheduled_generic_parms_dies (void)
20092 if (generic_type_instances
== NULL
)
20095 FOR_EACH_VEC_ELT (tree
, generic_type_instances
, i
, t
)
20096 gen_generic_params_dies (t
);
20100 /* Replace DW_AT_name for the decl with name. */
20103 dwarf2out_set_name (tree decl
, tree name
)
20109 die
= TYPE_SYMTAB_DIE (decl
);
20113 dname
= dwarf2_name (name
, 0);
20117 attr
= get_AT (die
, DW_AT_name
);
20120 struct indirect_string_node
*node
;
20122 node
= find_AT_string (dname
);
20123 /* replace the string. */
20124 attr
->dw_attr_val
.v
.val_str
= node
;
20128 add_name_attribute (die
, dname
);
20131 /* Called by the final INSN scan whenever we see a var location. We
20132 use it to drop labels in the right places, and throw the location in
20133 our lookup table. */
20136 dwarf2out_var_location (rtx loc_note
)
20138 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
20139 struct var_loc_node
*newloc
;
20140 rtx next_real
, next_note
;
20141 static const char *last_label
;
20142 static const char *last_postcall_label
;
20143 static bool last_in_cold_section_p
;
20144 static rtx expected_next_loc_note
;
20148 if (!NOTE_P (loc_note
))
20150 if (CALL_P (loc_note
))
20153 if (SIBLING_CALL_P (loc_note
))
20154 tail_call_site_count
++;
20159 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
20160 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
20163 /* Optimize processing a large consecutive sequence of location
20164 notes so we don't spend too much time in next_real_insn. If the
20165 next insn is another location note, remember the next_real_insn
20166 calculation for next time. */
20167 next_real
= cached_next_real_insn
;
20170 if (expected_next_loc_note
!= loc_note
)
20171 next_real
= NULL_RTX
;
20174 next_note
= NEXT_INSN (loc_note
);
20176 || INSN_DELETED_P (next_note
)
20177 || GET_CODE (next_note
) != NOTE
20178 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
20179 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
20180 next_note
= NULL_RTX
;
20183 next_real
= next_real_insn (loc_note
);
20187 expected_next_loc_note
= next_note
;
20188 cached_next_real_insn
= next_real
;
20191 cached_next_real_insn
= NULL_RTX
;
20193 /* If there are no instructions which would be affected by this note,
20194 don't do anything. */
20196 && next_real
== NULL_RTX
20197 && !NOTE_DURING_CALL_P (loc_note
))
20200 if (next_real
== NULL_RTX
)
20201 next_real
= get_last_insn ();
20203 /* If there were any real insns between note we processed last time
20204 and this note (or if it is the first note), clear
20205 last_{,postcall_}label so that they are not reused this time. */
20206 if (last_var_location_insn
== NULL_RTX
20207 || last_var_location_insn
!= next_real
20208 || last_in_cold_section_p
!= in_cold_section_p
)
20211 last_postcall_label
= NULL
;
20216 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
20217 newloc
= add_var_loc_to_decl (decl
, loc_note
,
20218 NOTE_DURING_CALL_P (loc_note
)
20219 ? last_postcall_label
: last_label
);
20220 if (newloc
== NULL
)
20229 /* If there were no real insns between note we processed last time
20230 and this note, use the label we emitted last time. Otherwise
20231 create a new label and emit it. */
20232 if (last_label
== NULL
)
20234 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
20235 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
20237 last_label
= ggc_strdup (loclabel
);
20242 struct call_arg_loc_node
*ca_loc
20243 = ggc_alloc_cleared_call_arg_loc_node ();
20244 rtx prev
= prev_real_insn (loc_note
), x
;
20245 ca_loc
->call_arg_loc_note
= loc_note
;
20246 ca_loc
->next
= NULL
;
20247 ca_loc
->label
= last_label
;
20250 || (NONJUMP_INSN_P (prev
)
20251 && GET_CODE (PATTERN (prev
)) == SEQUENCE
20252 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
20253 if (!CALL_P (prev
))
20254 prev
= XVECEXP (PATTERN (prev
), 0, 0);
20255 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
20256 x
= PATTERN (prev
);
20257 if (GET_CODE (x
) == PARALLEL
)
20258 x
= XVECEXP (x
, 0, 0);
20259 if (GET_CODE (x
) == SET
)
20261 if (GET_CODE (x
) == CALL
&& MEM_P (XEXP (x
, 0)))
20263 x
= XEXP (XEXP (x
, 0), 0);
20264 if (GET_CODE (x
) == SYMBOL_REF
20265 && SYMBOL_REF_DECL (x
)
20266 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
20267 ca_loc
->symbol_ref
= x
;
20269 ca_loc
->block
= insn_scope (prev
);
20270 if (call_arg_locations
)
20271 call_arg_loc_last
->next
= ca_loc
;
20273 call_arg_locations
= ca_loc
;
20274 call_arg_loc_last
= ca_loc
;
20276 else if (!NOTE_DURING_CALL_P (loc_note
))
20277 newloc
->label
= last_label
;
20280 if (!last_postcall_label
)
20282 sprintf (loclabel
, "%s-1", last_label
);
20283 last_postcall_label
= ggc_strdup (loclabel
);
20285 newloc
->label
= last_postcall_label
;
20288 last_var_location_insn
= next_real
;
20289 last_in_cold_section_p
= in_cold_section_p
;
20292 /* Note in one location list that text section has changed. */
20295 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
20297 var_loc_list
*list
= (var_loc_list
*) *slot
;
20299 list
->last_before_switch
20300 = list
->last
->next
? list
->last
->next
: list
->last
;
20304 /* Note in all location lists that text section has changed. */
20307 var_location_switch_text_section (void)
20309 if (decl_loc_table
== NULL
)
20312 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
20315 /* Create a new line number table. */
20317 static dw_line_info_table
*
20318 new_line_info_table (void)
20320 dw_line_info_table
*table
;
20322 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
20323 table
->file_num
= 1;
20324 table
->line_num
= 1;
20325 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
20330 /* Lookup the "current" table into which we emit line info, so
20331 that we don't have to do it for every source line. */
20334 set_cur_line_info_table (section
*sec
)
20336 dw_line_info_table
*table
;
20338 if (sec
== text_section
)
20339 table
= text_section_line_info
;
20340 else if (sec
== cold_text_section
)
20342 table
= cold_text_section_line_info
;
20345 cold_text_section_line_info
= table
= new_line_info_table ();
20346 table
->end_label
= cold_end_label
;
20351 const char *end_label
;
20353 if (flag_reorder_blocks_and_partition
)
20355 if (in_cold_section_p
)
20356 end_label
= crtl
->subsections
.cold_section_end_label
;
20358 end_label
= crtl
->subsections
.hot_section_end_label
;
20362 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20363 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
20364 current_function_funcdef_no
);
20365 end_label
= ggc_strdup (label
);
20368 table
= new_line_info_table ();
20369 table
->end_label
= end_label
;
20371 VEC_safe_push (dw_line_info_table_p
, gc
, separate_line_info
, table
);
20374 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20375 table
->is_stmt
= (cur_line_info_table
20376 ? cur_line_info_table
->is_stmt
20377 : DWARF_LINE_DEFAULT_IS_STMT_START
);
20378 cur_line_info_table
= table
;
20382 /* We need to reset the locations at the beginning of each
20383 function. We can't do this in the end_function hook, because the
20384 declarations that use the locations won't have been output when
20385 that hook is called. Also compute have_multiple_function_sections here. */
20388 dwarf2out_begin_function (tree fun
)
20390 section
*sec
= function_section (fun
);
20392 if (sec
!= text_section
)
20393 have_multiple_function_sections
= true;
20395 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
20397 gcc_assert (current_function_decl
== fun
);
20398 cold_text_section
= unlikely_text_section ();
20399 switch_to_section (cold_text_section
);
20400 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
20401 switch_to_section (sec
);
20404 dwarf2out_note_section_used ();
20405 call_site_count
= 0;
20406 tail_call_site_count
= 0;
20408 set_cur_line_info_table (sec
);
20411 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
20414 push_dw_line_info_entry (dw_line_info_table
*table
,
20415 enum dw_line_info_opcode opcode
, unsigned int val
)
20417 dw_line_info_entry e
;
20420 VEC_safe_push (dw_line_info_entry
, gc
, table
->entries
, &e
);
20423 /* Output a label to mark the beginning of a source code line entry
20424 and record information relating to this source line, in
20425 'line_info_table' for later output of the .debug_line section. */
20426 /* ??? The discriminator parameter ought to be unsigned. */
20429 dwarf2out_source_line (unsigned int line
, const char *filename
,
20430 int discriminator
, bool is_stmt
)
20432 unsigned int file_num
;
20433 dw_line_info_table
*table
;
20435 if (debug_info_level
< DINFO_LEVEL_NORMAL
|| line
== 0)
20438 /* The discriminator column was added in dwarf4. Simplify the below
20439 by simply removing it if we're not supposed to output it. */
20440 if (dwarf_version
< 4 && dwarf_strict
)
20443 table
= cur_line_info_table
;
20444 file_num
= maybe_emit_file (lookup_filename (filename
));
20446 /* ??? TODO: Elide duplicate line number entries. Traditionally,
20447 the debugger has used the second (possibly duplicate) line number
20448 at the beginning of the function to mark the end of the prologue.
20449 We could eliminate any other duplicates within the function. For
20450 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
20451 that second line number entry. */
20452 /* Recall that this end-of-prologue indication is *not* the same thing
20453 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
20454 to which the hook corresponds, follows the last insn that was
20455 emitted by gen_prologue. What we need is to preceed the first insn
20456 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
20457 insn that corresponds to something the user wrote. These may be
20458 very different locations once scheduling is enabled. */
20460 if (0 && file_num
== table
->file_num
20461 && line
== table
->line_num
20462 && discriminator
== table
->discrim_num
20463 && is_stmt
== table
->is_stmt
)
20466 switch_to_section (current_function_section ());
20468 /* If requested, emit something human-readable. */
20469 if (flag_debug_asm
)
20470 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
20472 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20474 /* Emit the .loc directive understood by GNU as. */
20475 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
20476 file_num, line, is_stmt, discriminator */
20477 fputs ("\t.loc ", asm_out_file
);
20478 fprint_ul (asm_out_file
, file_num
);
20479 putc (' ', asm_out_file
);
20480 fprint_ul (asm_out_file
, line
);
20481 putc (' ', asm_out_file
);
20482 putc ('0', asm_out_file
);
20484 if (is_stmt
!= table
->is_stmt
)
20486 fputs (" is_stmt ", asm_out_file
);
20487 putc (is_stmt
? '1' : '0', asm_out_file
);
20489 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
20491 gcc_assert (discriminator
> 0);
20492 fputs (" discriminator ", asm_out_file
);
20493 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
20495 putc ('\n', asm_out_file
);
20499 unsigned int label_num
= ++line_info_label_num
;
20501 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
20503 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
20504 if (file_num
!= table
->file_num
)
20505 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
20506 if (discriminator
!= table
->discrim_num
)
20507 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
20508 if (is_stmt
!= table
->is_stmt
)
20509 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
20510 push_dw_line_info_entry (table
, LI_set_line
, line
);
20513 table
->file_num
= file_num
;
20514 table
->line_num
= line
;
20515 table
->discrim_num
= discriminator
;
20516 table
->is_stmt
= is_stmt
;
20517 table
->in_use
= true;
20520 /* Record the beginning of a new source file. */
20523 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
20525 if (flag_eliminate_dwarf2_dups
&& ! use_debug_types
)
20527 /* Record the beginning of the file for break_out_includes. */
20528 dw_die_ref bincl_die
;
20530 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
20531 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
20534 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20537 e
.code
= DW_MACINFO_start_file
;
20539 e
.info
= xstrdup (filename
);
20540 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20544 /* Record the end of a source file. */
20547 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
20549 if (flag_eliminate_dwarf2_dups
&& ! use_debug_types
)
20550 /* Record the end of the file for break_out_includes. */
20551 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
20553 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20556 e
.code
= DW_MACINFO_end_file
;
20559 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20563 /* Called from debug_define in toplev.c. The `buffer' parameter contains
20564 the tail part of the directive line, i.e. the part which is past the
20565 initial whitespace, #, whitespace, directive-name, whitespace part. */
20568 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
20569 const char *buffer ATTRIBUTE_UNUSED
)
20571 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20574 /* Insert a dummy first entry to be able to optimize the whole
20575 predefined macro block using DW_MACRO_GNU_transparent_include. */
20576 if (VEC_empty (macinfo_entry
, macinfo_table
) && lineno
== 0)
20581 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20583 e
.code
= DW_MACINFO_define
;
20585 e
.info
= xstrdup (buffer
);;
20586 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20590 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
20591 the tail part of the directive line, i.e. the part which is past the
20592 initial whitespace, #, whitespace, directive-name, whitespace part. */
20595 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
20596 const char *buffer ATTRIBUTE_UNUSED
)
20598 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20601 /* Insert a dummy first entry to be able to optimize the whole
20602 predefined macro block using DW_MACRO_GNU_transparent_include. */
20603 if (VEC_empty (macinfo_entry
, macinfo_table
) && lineno
== 0)
20608 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20610 e
.code
= DW_MACINFO_undef
;
20612 e
.info
= xstrdup (buffer
);
20613 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20617 /* Routines to manipulate hash table of CUs. */
20620 htab_macinfo_hash (const void *of
)
20622 const macinfo_entry
*const entry
=
20623 (const macinfo_entry
*) of
;
20625 return htab_hash_string (entry
->info
);
20629 htab_macinfo_eq (const void *of1
, const void *of2
)
20631 const macinfo_entry
*const entry1
= (const macinfo_entry
*) of1
;
20632 const macinfo_entry
*const entry2
= (const macinfo_entry
*) of2
;
20634 return !strcmp (entry1
->info
, entry2
->info
);
20637 /* Output a single .debug_macinfo entry. */
20640 output_macinfo_op (macinfo_entry
*ref
)
20644 struct indirect_string_node
*node
;
20645 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20646 struct dwarf_file_data
*fd
;
20650 case DW_MACINFO_start_file
:
20651 fd
= lookup_filename (ref
->info
);
20652 if (fd
->filename
== ref
->info
)
20653 fd
->filename
= ggc_strdup (fd
->filename
);
20654 file_num
= maybe_emit_file (fd
);
20655 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
20656 dw2_asm_output_data_uleb128 (ref
->lineno
,
20657 "Included from line number %lu",
20658 (unsigned long) ref
->lineno
);
20659 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
20661 case DW_MACINFO_end_file
:
20662 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
20664 case DW_MACINFO_define
:
20665 case DW_MACINFO_undef
:
20666 len
= strlen (ref
->info
) + 1;
20668 && len
> DWARF_OFFSET_SIZE
20669 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
20670 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
20672 ref
->code
= ref
->code
== DW_MACINFO_define
20673 ? DW_MACRO_GNU_define_indirect
20674 : DW_MACRO_GNU_undef_indirect
;
20675 output_macinfo_op (ref
);
20678 dw2_asm_output_data (1, ref
->code
,
20679 ref
->code
== DW_MACINFO_define
20680 ? "Define macro" : "Undefine macro");
20681 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
20682 (unsigned long) ref
->lineno
);
20683 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
20685 case DW_MACRO_GNU_define_indirect
:
20686 case DW_MACRO_GNU_undef_indirect
:
20687 node
= find_AT_string (ref
->info
);
20688 if (node
->form
!= DW_FORM_strp
)
20691 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
20692 ++dw2_string_counter
;
20693 node
->label
= xstrdup (label
);
20694 node
->form
= DW_FORM_strp
;
20696 dw2_asm_output_data (1, ref
->code
,
20697 ref
->code
== DW_MACRO_GNU_define_indirect
20698 ? "Define macro indirect"
20699 : "Undefine macro indirect");
20700 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
20701 (unsigned long) ref
->lineno
);
20702 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
20703 debug_str_section
, "The macro: \"%s\"",
20706 case DW_MACRO_GNU_transparent_include
:
20707 dw2_asm_output_data (1, ref
->code
, "Transparent include");
20708 ASM_GENERATE_INTERNAL_LABEL (label
,
20709 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
20710 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
20713 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
20714 ASM_COMMENT_START
, (unsigned long) ref
->code
);
20719 /* Attempt to make a sequence of define/undef macinfo ops shareable with
20720 other compilation unit .debug_macinfo sections. IDX is the first
20721 index of a define/undef, return the number of ops that should be
20722 emitted in a comdat .debug_macinfo section and emit
20723 a DW_MACRO_GNU_transparent_include entry referencing it.
20724 If the define/undef entry should be emitted normally, return 0. */
20727 optimize_macinfo_range (unsigned int idx
, VEC (macinfo_entry
, gc
) *files
,
20728 htab_t
*macinfo_htab
)
20730 macinfo_entry
*first
, *second
, *cur
, *inc
;
20731 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
20732 unsigned char checksum
[16];
20733 struct md5_ctx ctx
;
20734 char *grp_name
, *tail
;
20736 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
20739 first
= VEC_index (macinfo_entry
, macinfo_table
, idx
);
20740 second
= VEC_index (macinfo_entry
, macinfo_table
, idx
+ 1);
20742 /* Optimize only if there are at least two consecutive define/undef ops,
20743 and either all of them are before first DW_MACINFO_start_file
20744 with lineno 0 (i.e. predefined macro block), or all of them are
20745 in some included header file. */
20746 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
20748 if (VEC_empty (macinfo_entry
, files
))
20750 if (first
->lineno
!= 0 || second
->lineno
!= 0)
20753 else if (first
->lineno
== 0)
20756 /* Find the last define/undef entry that can be grouped together
20757 with first and at the same time compute md5 checksum of their
20758 codes, linenumbers and strings. */
20759 md5_init_ctx (&ctx
);
20760 for (i
= idx
; VEC_iterate (macinfo_entry
, macinfo_table
, i
, cur
); i
++)
20761 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
20763 else if (first
->lineno
== 0 && cur
->lineno
!= 0)
20767 unsigned char code
= cur
->code
;
20768 md5_process_bytes (&code
, 1, &ctx
);
20769 checksum_uleb128 (cur
->lineno
, &ctx
);
20770 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
20772 md5_finish_ctx (&ctx
, checksum
);
20775 /* From the containing include filename (if any) pick up just
20776 usable characters from its basename. */
20777 if (first
->lineno
== 0)
20780 base
= lbasename (VEC_last (macinfo_entry
, files
)->info
);
20781 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
20782 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
20783 encoded_filename_len
++;
20784 /* Count . at the end. */
20785 if (encoded_filename_len
)
20786 encoded_filename_len
++;
20788 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
20789 linebuf_len
= strlen (linebuf
);
20791 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
20792 grp_name
= XNEWVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
20794 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
20795 tail
= grp_name
+ 4;
20796 if (encoded_filename_len
)
20798 for (i
= 0; base
[i
]; i
++)
20799 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
20803 memcpy (tail
, linebuf
, linebuf_len
);
20804 tail
+= linebuf_len
;
20806 for (i
= 0; i
< 16; i
++)
20807 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
20809 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
20810 in the empty vector entry before the first define/undef. */
20811 inc
= VEC_index (macinfo_entry
, macinfo_table
, idx
- 1);
20812 inc
->code
= DW_MACRO_GNU_transparent_include
;
20814 inc
->info
= grp_name
;
20815 if (*macinfo_htab
== NULL
)
20816 *macinfo_htab
= htab_create (10, htab_macinfo_hash
, htab_macinfo_eq
, NULL
);
20817 /* Avoid emitting duplicates. */
20818 slot
= htab_find_slot (*macinfo_htab
, inc
, INSERT
);
20821 free (CONST_CAST (char *, inc
->info
));
20824 /* If such an entry has been used before, just emit
20825 a DW_MACRO_GNU_transparent_include op. */
20826 inc
= (macinfo_entry
*) *slot
;
20827 output_macinfo_op (inc
);
20828 /* And clear all macinfo_entry in the range to avoid emitting them
20829 in the second pass. */
20831 VEC_iterate (macinfo_entry
, macinfo_table
, i
, cur
)
20832 && i
< idx
+ count
;
20836 free (CONST_CAST (char *, cur
->info
));
20843 inc
->lineno
= htab_elements (*macinfo_htab
);
20844 output_macinfo_op (inc
);
20849 /* Output macinfo section(s). */
20852 output_macinfo (void)
20855 unsigned long length
= VEC_length (macinfo_entry
, macinfo_table
);
20856 macinfo_entry
*ref
;
20857 VEC (macinfo_entry
, gc
) *files
= NULL
;
20858 htab_t macinfo_htab
= NULL
;
20863 /* output_macinfo* uses these interchangeably. */
20864 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
20865 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
20866 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
20867 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
20869 /* For .debug_macro emit the section header. */
20872 dw2_asm_output_data (2, 4, "DWARF macro version number");
20873 if (DWARF_OFFSET_SIZE
== 8)
20874 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
20876 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
20877 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_line_section_label
,
20878 debug_line_section
, NULL
);
20881 /* In the first loop, it emits the primary .debug_macinfo section
20882 and after each emitted op the macinfo_entry is cleared.
20883 If a longer range of define/undef ops can be optimized using
20884 DW_MACRO_GNU_transparent_include, the
20885 DW_MACRO_GNU_transparent_include op is emitted and kept in
20886 the vector before the first define/undef in the range and the
20887 whole range of define/undef ops is not emitted and kept. */
20888 for (i
= 0; VEC_iterate (macinfo_entry
, macinfo_table
, i
, ref
); i
++)
20892 case DW_MACINFO_start_file
:
20893 VEC_safe_push (macinfo_entry
, gc
, files
, ref
);
20895 case DW_MACINFO_end_file
:
20896 if (!VEC_empty (macinfo_entry
, files
))
20898 macinfo_entry
*file
= VEC_last (macinfo_entry
, files
);
20899 free (CONST_CAST (char *, file
->info
));
20900 VEC_pop (macinfo_entry
, files
);
20903 case DW_MACINFO_define
:
20904 case DW_MACINFO_undef
:
20906 && HAVE_COMDAT_GROUP
20907 && VEC_length (macinfo_entry
, files
) != 1
20910 && VEC_index (macinfo_entry
, macinfo_table
, i
- 1)->code
== 0)
20912 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
20921 /* A dummy entry may be inserted at the beginning to be able
20922 to optimize the whole block of predefined macros. */
20928 output_macinfo_op (ref
);
20929 /* For DW_MACINFO_start_file ref->info has been copied into files
20931 if (ref
->code
!= DW_MACINFO_start_file
)
20932 free (CONST_CAST (char *, ref
->info
));
20937 if (macinfo_htab
== NULL
)
20940 htab_delete (macinfo_htab
);
20942 /* If any DW_MACRO_GNU_transparent_include were used, on those
20943 DW_MACRO_GNU_transparent_include entries terminate the
20944 current chain and switch to a new comdat .debug_macinfo
20945 section and emit the define/undef entries within it. */
20946 for (i
= 0; VEC_iterate (macinfo_entry
, macinfo_table
, i
, ref
); i
++)
20951 case DW_MACRO_GNU_transparent_include
:
20953 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20954 tree comdat_key
= get_identifier (ref
->info
);
20955 /* Terminate the previous .debug_macinfo section. */
20956 dw2_asm_output_data (1, 0, "End compilation unit");
20957 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
20959 | SECTION_LINKONCE
,
20961 ASM_GENERATE_INTERNAL_LABEL (label
,
20962 DEBUG_MACRO_SECTION_LABEL
,
20964 ASM_OUTPUT_LABEL (asm_out_file
, label
);
20966 free (CONST_CAST (char *, ref
->info
));
20968 dw2_asm_output_data (2, 4, "DWARF macro version number");
20969 if (DWARF_OFFSET_SIZE
== 8)
20970 dw2_asm_output_data (1, 1, "Flags: 64-bit");
20972 dw2_asm_output_data (1, 0, "Flags: 32-bit");
20975 case DW_MACINFO_define
:
20976 case DW_MACINFO_undef
:
20977 output_macinfo_op (ref
);
20979 free (CONST_CAST (char *, ref
->info
));
20983 gcc_unreachable ();
20987 /* Set up for Dwarf output at the start of compilation. */
20990 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
20992 /* Allocate the file_table. */
20993 file_table
= htab_create_ggc (50, file_table_hash
,
20994 file_table_eq
, NULL
);
20996 /* Allocate the decl_die_table. */
20997 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
20998 decl_die_table_eq
, NULL
);
21000 /* Allocate the decl_loc_table. */
21001 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
21002 decl_loc_table_eq
, NULL
);
21004 /* Allocate the cached_dw_loc_list_table. */
21005 cached_dw_loc_list_table
21006 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
21007 cached_dw_loc_list_table_eq
, NULL
);
21009 /* Allocate the initial hunk of the decl_scope_table. */
21010 decl_scope_table
= VEC_alloc (tree
, gc
, 256);
21012 /* Allocate the initial hunk of the abbrev_die_table. */
21013 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
21014 (ABBREV_DIE_TABLE_INCREMENT
);
21015 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
21016 /* Zero-th entry is allocated, but unused. */
21017 abbrev_die_table_in_use
= 1;
21019 /* Allocate the pubtypes and pubnames vectors. */
21020 pubname_table
= VEC_alloc (pubname_entry
, gc
, 32);
21021 pubtype_table
= VEC_alloc (pubname_entry
, gc
, 32);
21023 incomplete_types
= VEC_alloc (tree
, gc
, 64);
21025 used_rtx_array
= VEC_alloc (rtx
, gc
, 32);
21027 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
21028 SECTION_DEBUG
, NULL
);
21029 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21030 SECTION_DEBUG
, NULL
);
21031 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
21032 SECTION_DEBUG
, NULL
);
21033 debug_macinfo_section
= get_section (dwarf_strict
21034 ? DEBUG_MACINFO_SECTION
21035 : DEBUG_MACRO_SECTION
,
21036 SECTION_DEBUG
, NULL
);
21037 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
21038 SECTION_DEBUG
, NULL
);
21039 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
21040 SECTION_DEBUG
, NULL
);
21041 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
21042 SECTION_DEBUG
, NULL
);
21043 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
21044 SECTION_DEBUG
, NULL
);
21045 debug_str_section
= get_section (DEBUG_STR_SECTION
,
21046 DEBUG_STR_SECTION_FLAGS
, NULL
);
21047 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
21048 SECTION_DEBUG
, NULL
);
21049 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
21050 SECTION_DEBUG
, NULL
);
21052 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
21053 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
21054 DEBUG_ABBREV_SECTION_LABEL
, 0);
21055 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
21056 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
21057 COLD_TEXT_SECTION_LABEL
, 0);
21058 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
21060 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
21061 DEBUG_INFO_SECTION_LABEL
, 0);
21062 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
21063 DEBUG_LINE_SECTION_LABEL
, 0);
21064 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
21065 DEBUG_RANGES_SECTION_LABEL
, 0);
21066 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
21068 ? DEBUG_MACINFO_SECTION_LABEL
21069 : DEBUG_MACRO_SECTION_LABEL
, 0);
21071 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21072 macinfo_table
= VEC_alloc (macinfo_entry
, gc
, 64);
21074 switch_to_section (text_section
);
21075 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
21077 /* Make sure the line number table for .text always exists. */
21078 text_section_line_info
= new_line_info_table ();
21079 text_section_line_info
->end_label
= text_end_label
;
21082 /* Called before cgraph_optimize starts outputtting functions, variables
21083 and toplevel asms into assembly. */
21086 dwarf2out_assembly_start (void)
21088 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
21089 && dwarf2out_do_cfi_asm ()
21090 && (!(flag_unwind_tables
|| flag_exceptions
)
21091 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
21092 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
21095 /* A helper function for dwarf2out_finish called through
21096 htab_traverse. Emit one queued .debug_str string. */
21099 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
21101 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21103 if (node
->form
== DW_FORM_strp
)
21105 switch_to_section (debug_str_section
);
21106 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
21107 assemble_string (node
->str
, strlen (node
->str
) + 1);
21113 #if ENABLE_ASSERT_CHECKING
21114 /* Verify that all marks are clear. */
21117 verify_marks_clear (dw_die_ref die
)
21121 gcc_assert (! die
->die_mark
);
21122 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
21124 #endif /* ENABLE_ASSERT_CHECKING */
21126 /* Clear the marks for a die and its children.
21127 Be cool if the mark isn't set. */
21130 prune_unmark_dies (dw_die_ref die
)
21136 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
21139 /* Given DIE that we're marking as used, find any other dies
21140 it references as attributes and mark them as used. */
21143 prune_unused_types_walk_attribs (dw_die_ref die
)
21148 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
21150 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
21152 /* A reference to another DIE.
21153 Make sure that it will get emitted.
21154 If it was broken out into a comdat group, don't follow it. */
21155 if (! use_debug_types
21156 || a
->dw_attr
== DW_AT_specification
21157 || a
->dw_attr_val
.v
.val_die_ref
.die
->die_id
.die_type_node
== NULL
)
21158 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
21160 /* Set the string's refcount to 0 so that prune_unused_types_mark
21161 accounts properly for it. */
21162 if (AT_class (a
) == dw_val_class_str
)
21163 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
21167 /* Mark the generic parameters and arguments children DIEs of DIE. */
21170 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
21174 if (die
== NULL
|| die
->die_child
== NULL
)
21176 c
= die
->die_child
;
21179 switch (c
->die_tag
)
21181 case DW_TAG_template_type_param
:
21182 case DW_TAG_template_value_param
:
21183 case DW_TAG_GNU_template_template_param
:
21184 case DW_TAG_GNU_template_parameter_pack
:
21185 prune_unused_types_mark (c
, 1);
21191 } while (c
&& c
!= die
->die_child
);
21194 /* Mark DIE as being used. If DOKIDS is true, then walk down
21195 to DIE's children. */
21198 prune_unused_types_mark (dw_die_ref die
, int dokids
)
21202 if (die
->die_mark
== 0)
21204 /* We haven't done this node yet. Mark it as used. */
21206 /* If this is the DIE of a generic type instantiation,
21207 mark the children DIEs that describe its generic parms and
21209 prune_unused_types_mark_generic_parms_dies (die
);
21211 /* We also have to mark its parents as used.
21212 (But we don't want to mark our parents' kids due to this.) */
21213 if (die
->die_parent
)
21214 prune_unused_types_mark (die
->die_parent
, 0);
21216 /* Mark any referenced nodes. */
21217 prune_unused_types_walk_attribs (die
);
21219 /* If this node is a specification,
21220 also mark the definition, if it exists. */
21221 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
21222 prune_unused_types_mark (die
->die_definition
, 1);
21225 if (dokids
&& die
->die_mark
!= 2)
21227 /* We need to walk the children, but haven't done so yet.
21228 Remember that we've walked the kids. */
21231 /* If this is an array type, we need to make sure our
21232 kids get marked, even if they're types. If we're
21233 breaking out types into comdat sections, do this
21234 for all type definitions. */
21235 if (die
->die_tag
== DW_TAG_array_type
21236 || (use_debug_types
21237 && is_type_die (die
) && ! is_declaration_die (die
)))
21238 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
21240 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
21244 /* For local classes, look if any static member functions were emitted
21245 and if so, mark them. */
21248 prune_unused_types_walk_local_classes (dw_die_ref die
)
21252 if (die
->die_mark
== 2)
21255 switch (die
->die_tag
)
21257 case DW_TAG_structure_type
:
21258 case DW_TAG_union_type
:
21259 case DW_TAG_class_type
:
21262 case DW_TAG_subprogram
:
21263 if (!get_AT_flag (die
, DW_AT_declaration
)
21264 || die
->die_definition
!= NULL
)
21265 prune_unused_types_mark (die
, 1);
21272 /* Mark children. */
21273 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
21276 /* Walk the tree DIE and mark types that we actually use. */
21279 prune_unused_types_walk (dw_die_ref die
)
21283 /* Don't do anything if this node is already marked and
21284 children have been marked as well. */
21285 if (die
->die_mark
== 2)
21288 switch (die
->die_tag
)
21290 case DW_TAG_structure_type
:
21291 case DW_TAG_union_type
:
21292 case DW_TAG_class_type
:
21293 if (die
->die_perennial_p
)
21296 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
21297 if (c
->die_tag
== DW_TAG_subprogram
)
21300 /* Finding used static member functions inside of classes
21301 is needed just for local classes, because for other classes
21302 static member function DIEs with DW_AT_specification
21303 are emitted outside of the DW_TAG_*_type. If we ever change
21304 it, we'd need to call this even for non-local classes. */
21306 prune_unused_types_walk_local_classes (die
);
21308 /* It's a type node --- don't mark it. */
21311 case DW_TAG_const_type
:
21312 case DW_TAG_packed_type
:
21313 case DW_TAG_pointer_type
:
21314 case DW_TAG_reference_type
:
21315 case DW_TAG_rvalue_reference_type
:
21316 case DW_TAG_volatile_type
:
21317 case DW_TAG_typedef
:
21318 case DW_TAG_array_type
:
21319 case DW_TAG_interface_type
:
21320 case DW_TAG_friend
:
21321 case DW_TAG_variant_part
:
21322 case DW_TAG_enumeration_type
:
21323 case DW_TAG_subroutine_type
:
21324 case DW_TAG_string_type
:
21325 case DW_TAG_set_type
:
21326 case DW_TAG_subrange_type
:
21327 case DW_TAG_ptr_to_member_type
:
21328 case DW_TAG_file_type
:
21329 if (die
->die_perennial_p
)
21332 /* It's a type node --- don't mark it. */
21336 /* Mark everything else. */
21340 if (die
->die_mark
== 0)
21344 /* Now, mark any dies referenced from here. */
21345 prune_unused_types_walk_attribs (die
);
21350 /* Mark children. */
21351 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
21354 /* Increment the string counts on strings referred to from DIE's
21358 prune_unused_types_update_strings (dw_die_ref die
)
21363 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
21364 if (AT_class (a
) == dw_val_class_str
)
21366 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
21368 /* Avoid unnecessarily putting strings that are used less than
21369 twice in the hash table. */
21371 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
21374 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
21375 htab_hash_string (s
->str
),
21377 gcc_assert (*slot
== NULL
);
21383 /* Remove from the tree DIE any dies that aren't marked. */
21386 prune_unused_types_prune (dw_die_ref die
)
21390 gcc_assert (die
->die_mark
);
21391 prune_unused_types_update_strings (die
);
21393 if (! die
->die_child
)
21396 c
= die
->die_child
;
21398 dw_die_ref prev
= c
;
21399 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
21400 if (c
== die
->die_child
)
21402 /* No marked children between 'prev' and the end of the list. */
21404 /* No marked children at all. */
21405 die
->die_child
= NULL
;
21408 prev
->die_sib
= c
->die_sib
;
21409 die
->die_child
= prev
;
21414 if (c
!= prev
->die_sib
)
21416 prune_unused_types_prune (c
);
21417 } while (c
!= die
->die_child
);
21420 /* Remove dies representing declarations that we never use. */
21423 prune_unused_types (void)
21426 limbo_die_node
*node
;
21427 comdat_type_node
*ctnode
;
21429 dw_die_ref base_type
;
21431 #if ENABLE_ASSERT_CHECKING
21432 /* All the marks should already be clear. */
21433 verify_marks_clear (comp_unit_die ());
21434 for (node
= limbo_die_list
; node
; node
= node
->next
)
21435 verify_marks_clear (node
->die
);
21436 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21437 verify_marks_clear (ctnode
->root_die
);
21438 #endif /* ENABLE_ASSERT_CHECKING */
21440 /* Mark types that are used in global variables. */
21441 premark_types_used_by_global_vars ();
21443 /* Set the mark on nodes that are actually used. */
21444 prune_unused_types_walk (comp_unit_die ());
21445 for (node
= limbo_die_list
; node
; node
= node
->next
)
21446 prune_unused_types_walk (node
->die
);
21447 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21449 prune_unused_types_walk (ctnode
->root_die
);
21450 prune_unused_types_mark (ctnode
->type_die
, 1);
21453 /* Also set the mark on nodes referenced from the
21455 FOR_EACH_VEC_ELT (pubname_entry
, pubname_table
, i
, pub
)
21456 prune_unused_types_mark (pub
->die
, 1);
21457 for (i
= 0; VEC_iterate (dw_die_ref
, base_types
, i
, base_type
); i
++)
21458 prune_unused_types_mark (base_type
, 1);
21460 if (debug_str_hash
)
21461 htab_empty (debug_str_hash
);
21462 prune_unused_types_prune (comp_unit_die ());
21463 for (node
= limbo_die_list
; node
; node
= node
->next
)
21464 prune_unused_types_prune (node
->die
);
21465 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21466 prune_unused_types_prune (ctnode
->root_die
);
21468 /* Leave the marks clear. */
21469 prune_unmark_dies (comp_unit_die ());
21470 for (node
= limbo_die_list
; node
; node
= node
->next
)
21471 prune_unmark_dies (node
->die
);
21472 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21473 prune_unmark_dies (ctnode
->root_die
);
21476 /* Set the parameter to true if there are any relative pathnames in
21479 file_table_relative_p (void ** slot
, void *param
)
21481 bool *p
= (bool *) param
;
21482 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
21483 if (!IS_ABSOLUTE_PATH (d
->filename
))
21491 /* Routines to manipulate hash table of comdat type units. */
21494 htab_ct_hash (const void *of
)
21497 const comdat_type_node
*const type_node
= (const comdat_type_node
*) of
;
21499 memcpy (&h
, type_node
->signature
, sizeof (h
));
21504 htab_ct_eq (const void *of1
, const void *of2
)
21506 const comdat_type_node
*const type_node_1
= (const comdat_type_node
*) of1
;
21507 const comdat_type_node
*const type_node_2
= (const comdat_type_node
*) of2
;
21509 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
21510 DWARF_TYPE_SIGNATURE_SIZE
));
21513 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
21514 to the location it would have been added, should we know its
21515 DECL_ASSEMBLER_NAME when we added other attributes. This will
21516 probably improve compactness of debug info, removing equivalent
21517 abbrevs, and hide any differences caused by deferring the
21518 computation of the assembler name, triggered by e.g. PCH. */
21521 move_linkage_attr (dw_die_ref die
)
21523 unsigned ix
= VEC_length (dw_attr_node
, die
->die_attr
);
21524 dw_attr_node linkage
= *VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
21526 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
21527 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
21531 dw_attr_node
*prev
= VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
21533 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
21537 if (ix
!= VEC_length (dw_attr_node
, die
->die_attr
) - 1)
21539 VEC_pop (dw_attr_node
, die
->die_attr
);
21540 VEC_quick_insert (dw_attr_node
, die
->die_attr
, ix
, &linkage
);
21544 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
21545 referenced from typed stack ops and count how often they are used. */
21548 mark_base_types (dw_loc_descr_ref loc
)
21550 dw_die_ref base_type
= NULL
;
21552 for (; loc
; loc
= loc
->dw_loc_next
)
21554 switch (loc
->dw_loc_opc
)
21556 case DW_OP_GNU_regval_type
:
21557 case DW_OP_GNU_deref_type
:
21558 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
21560 case DW_OP_GNU_convert
:
21561 case DW_OP_GNU_reinterpret
:
21562 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
21565 case DW_OP_GNU_const_type
:
21566 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
21568 case DW_OP_GNU_entry_value
:
21569 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
21574 gcc_assert (base_type
->die_parent
== comp_unit_die ());
21575 if (base_type
->die_mark
)
21576 base_type
->die_mark
++;
21579 VEC_safe_push (dw_die_ref
, heap
, base_types
, base_type
);
21580 base_type
->die_mark
= 1;
21585 /* Comparison function for sorting marked base types. */
21588 base_type_cmp (const void *x
, const void *y
)
21590 dw_die_ref dx
= *(const dw_die_ref
*) x
;
21591 dw_die_ref dy
= *(const dw_die_ref
*) y
;
21592 unsigned int byte_size1
, byte_size2
;
21593 unsigned int encoding1
, encoding2
;
21594 if (dx
->die_mark
> dy
->die_mark
)
21596 if (dx
->die_mark
< dy
->die_mark
)
21598 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
21599 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
21600 if (byte_size1
< byte_size2
)
21602 if (byte_size1
> byte_size2
)
21604 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
21605 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
21606 if (encoding1
< encoding2
)
21608 if (encoding1
> encoding2
)
21613 /* Move base types marked by mark_base_types as early as possible
21614 in the CU, sorted by decreasing usage count both to make the
21615 uleb128 references as small as possible and to make sure they
21616 will have die_offset already computed by calc_die_sizes when
21617 sizes of typed stack loc ops is computed. */
21620 move_marked_base_types (void)
21623 dw_die_ref base_type
, die
, c
;
21625 if (VEC_empty (dw_die_ref
, base_types
))
21628 /* Sort by decreasing usage count, they will be added again in that
21630 VEC_qsort (dw_die_ref
, base_types
, base_type_cmp
);
21631 die
= comp_unit_die ();
21632 c
= die
->die_child
;
21635 dw_die_ref prev
= c
;
21637 while (c
->die_mark
)
21639 remove_child_with_prev (c
, prev
);
21640 /* As base types got marked, there must be at least
21641 one node other than DW_TAG_base_type. */
21642 gcc_assert (c
!= c
->die_sib
);
21646 while (c
!= die
->die_child
);
21647 gcc_assert (die
->die_child
);
21648 c
= die
->die_child
;
21649 for (i
= 0; VEC_iterate (dw_die_ref
, base_types
, i
, base_type
); i
++)
21651 base_type
->die_mark
= 0;
21652 base_type
->die_sib
= c
->die_sib
;
21653 c
->die_sib
= base_type
;
21658 /* Helper function for resolve_addr, attempt to resolve
21659 one CONST_STRING, return non-zero if not successful. Similarly verify that
21660 SYMBOL_REFs refer to variables emitted in the current CU. */
21663 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
21667 if (GET_CODE (rtl
) == CONST_STRING
)
21669 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
21670 tree t
= build_string (len
, XSTR (rtl
, 0));
21671 tree tlen
= size_int (len
- 1);
21673 = build_array_type (char_type_node
, build_index_type (tlen
));
21674 rtl
= lookup_constant_def (t
);
21675 if (!rtl
|| !MEM_P (rtl
))
21677 rtl
= XEXP (rtl
, 0);
21678 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
21683 if (GET_CODE (rtl
) == SYMBOL_REF
21684 && SYMBOL_REF_DECL (rtl
))
21686 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
21688 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
21691 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
21695 if (GET_CODE (rtl
) == CONST
21696 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
21702 /* Helper function for resolve_addr, handle one location
21703 expression, return false if at least one CONST_STRING or SYMBOL_REF in
21704 the location list couldn't be resolved. */
21707 resolve_addr_in_expr (dw_loc_descr_ref loc
)
21709 dw_loc_descr_ref keep
= NULL
;
21710 for (; loc
; loc
= loc
->dw_loc_next
)
21711 switch (loc
->dw_loc_opc
)
21714 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
21717 case DW_OP_const4u
:
21718 case DW_OP_const8u
:
21720 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
21723 case DW_OP_plus_uconst
:
21724 if (size_of_loc_descr (loc
)
21725 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
21727 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
21729 dw_loc_descr_ref repl
21730 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
21731 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
21732 add_loc_descr (&repl
, loc
->dw_loc_next
);
21736 case DW_OP_implicit_value
:
21737 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
21738 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
21741 case DW_OP_GNU_implicit_pointer
:
21742 case DW_OP_GNU_parameter_ref
:
21743 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
21746 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
21749 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
21750 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
21751 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
21754 case DW_OP_GNU_const_type
:
21755 case DW_OP_GNU_regval_type
:
21756 case DW_OP_GNU_deref_type
:
21757 case DW_OP_GNU_convert
:
21758 case DW_OP_GNU_reinterpret
:
21759 while (loc
->dw_loc_next
21760 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
21762 dw_die_ref base1
, base2
;
21763 unsigned enc1
, enc2
, size1
, size2
;
21764 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
21765 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
21766 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
21767 else if (loc
->dw_loc_oprnd1
.val_class
21768 == dw_val_class_unsigned_const
)
21771 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
21772 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
21773 == dw_val_class_unsigned_const
)
21775 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
21776 gcc_assert (base1
->die_tag
== DW_TAG_base_type
21777 && base2
->die_tag
== DW_TAG_base_type
);
21778 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
21779 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
21780 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
21781 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
21783 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
21784 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
21788 /* Optimize away next DW_OP_GNU_convert after
21789 adjusting LOC's base type die reference. */
21790 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
21791 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
21792 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
21794 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
21795 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
21798 /* Don't change integer DW_OP_GNU_convert after e.g. floating
21799 point typed stack entry. */
21800 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
21801 keep
= loc
->dw_loc_next
;
21811 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
21812 an address in .rodata section if the string literal is emitted there,
21813 or remove the containing location list or replace DW_AT_const_value
21814 with DW_AT_location and empty location expression, if it isn't found
21815 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
21816 to something that has been emitted in the current CU. */
21819 resolve_addr (dw_die_ref die
)
21823 dw_loc_list_ref
*curr
, *start
, loc
;
21826 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
21827 switch (AT_class (a
))
21829 case dw_val_class_loc_list
:
21830 start
= curr
= AT_loc_list_ptr (a
);
21833 /* The same list can be referenced more than once. See if we have
21834 already recorded the result from a previous pass. */
21836 *curr
= loc
->dw_loc_next
;
21837 else if (!loc
->resolved_addr
)
21839 /* As things stand, we do not expect or allow one die to
21840 reference a suffix of another die's location list chain.
21841 References must be identical or completely separate.
21842 There is therefore no need to cache the result of this
21843 pass on any list other than the first; doing so
21844 would lead to unnecessary writes. */
21847 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
21848 if (!resolve_addr_in_expr ((*curr
)->expr
))
21850 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
21851 if (next
&& (*curr
)->ll_symbol
)
21853 gcc_assert (!next
->ll_symbol
);
21854 next
->ll_symbol
= (*curr
)->ll_symbol
;
21860 mark_base_types ((*curr
)->expr
);
21861 curr
= &(*curr
)->dw_loc_next
;
21865 loc
->resolved_addr
= 1;
21869 loc
->dw_loc_next
= *start
;
21874 remove_AT (die
, a
->dw_attr
);
21878 case dw_val_class_loc
:
21880 dw_loc_descr_ref l
= AT_loc (a
);
21881 /* For -gdwarf-2 don't attempt to optimize
21882 DW_AT_data_member_location containing
21883 DW_OP_plus_uconst - older consumers might
21884 rely on it being that op instead of a more complex,
21885 but shorter, location description. */
21886 if ((dwarf_version
> 2
21887 || a
->dw_attr
!= DW_AT_data_member_location
21889 || l
->dw_loc_opc
!= DW_OP_plus_uconst
21890 || l
->dw_loc_next
!= NULL
)
21891 && !resolve_addr_in_expr (l
))
21893 remove_AT (die
, a
->dw_attr
);
21897 mark_base_types (l
);
21900 case dw_val_class_addr
:
21901 if (a
->dw_attr
== DW_AT_const_value
21902 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
21904 remove_AT (die
, a
->dw_attr
);
21907 if (die
->die_tag
== DW_TAG_GNU_call_site
21908 && a
->dw_attr
== DW_AT_abstract_origin
)
21910 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
21911 dw_die_ref tdie
= lookup_decl_die (tdecl
);
21913 && DECL_EXTERNAL (tdecl
)
21914 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
21916 force_decl_die (tdecl
);
21917 tdie
= lookup_decl_die (tdecl
);
21921 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
21922 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
21923 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
21927 remove_AT (die
, a
->dw_attr
);
21936 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
21939 /* Helper routines for optimize_location_lists.
21940 This pass tries to share identical local lists in .debug_loc
21943 /* Iteratively hash operands of LOC opcode. */
21945 static inline hashval_t
21946 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
21948 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
21949 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
21951 switch (loc
->dw_loc_opc
)
21953 case DW_OP_const4u
:
21954 case DW_OP_const8u
:
21958 case DW_OP_const1u
:
21959 case DW_OP_const1s
:
21960 case DW_OP_const2u
:
21961 case DW_OP_const2s
:
21962 case DW_OP_const4s
:
21963 case DW_OP_const8s
:
21967 case DW_OP_plus_uconst
:
22003 case DW_OP_deref_size
:
22004 case DW_OP_xderef_size
:
22005 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
22012 gcc_assert (val1
->val_class
== dw_val_class_loc
);
22013 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
22014 hash
= iterative_hash_object (offset
, hash
);
22017 case DW_OP_implicit_value
:
22018 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
22019 switch (val2
->val_class
)
22021 case dw_val_class_const
:
22022 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22024 case dw_val_class_vec
:
22026 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
22027 unsigned int len
= val2
->v
.val_vec
.length
;
22029 hash
= iterative_hash_object (elt_size
, hash
);
22030 hash
= iterative_hash_object (len
, hash
);
22031 hash
= iterative_hash (val2
->v
.val_vec
.array
,
22032 len
* elt_size
, hash
);
22035 case dw_val_class_const_double
:
22036 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
22037 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
22039 case dw_val_class_addr
:
22040 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
22043 gcc_unreachable ();
22047 case DW_OP_bit_piece
:
22048 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
22049 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22055 unsigned char dtprel
= 0xd1;
22056 hash
= iterative_hash_object (dtprel
, hash
);
22058 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
22060 case DW_OP_GNU_implicit_pointer
:
22061 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22063 case DW_OP_GNU_entry_value
:
22064 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
22066 case DW_OP_GNU_regval_type
:
22067 case DW_OP_GNU_deref_type
:
22069 unsigned int byte_size
22070 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
22071 unsigned int encoding
22072 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
22073 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
22074 hash
= iterative_hash_object (byte_size
, hash
);
22075 hash
= iterative_hash_object (encoding
, hash
);
22078 case DW_OP_GNU_convert
:
22079 case DW_OP_GNU_reinterpret
:
22080 if (val1
->val_class
== dw_val_class_unsigned_const
)
22082 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
22086 case DW_OP_GNU_const_type
:
22088 unsigned int byte_size
22089 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
22090 unsigned int encoding
22091 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
22092 hash
= iterative_hash_object (byte_size
, hash
);
22093 hash
= iterative_hash_object (encoding
, hash
);
22094 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
22096 hash
= iterative_hash_object (val2
->val_class
, hash
);
22097 switch (val2
->val_class
)
22099 case dw_val_class_const
:
22100 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22102 case dw_val_class_vec
:
22104 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
22105 unsigned int len
= val2
->v
.val_vec
.length
;
22107 hash
= iterative_hash_object (elt_size
, hash
);
22108 hash
= iterative_hash_object (len
, hash
);
22109 hash
= iterative_hash (val2
->v
.val_vec
.array
,
22110 len
* elt_size
, hash
);
22113 case dw_val_class_const_double
:
22114 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
22115 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
22118 gcc_unreachable ();
22124 /* Other codes have no operands. */
22130 /* Iteratively hash the whole DWARF location expression LOC. */
22132 static inline hashval_t
22133 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
22135 dw_loc_descr_ref l
;
22136 bool sizes_computed
= false;
22137 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
22138 size_of_locs (loc
);
22140 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
22142 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
22143 hash
= iterative_hash_object (opc
, hash
);
22144 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
22146 size_of_locs (loc
);
22147 sizes_computed
= true;
22149 hash
= hash_loc_operands (l
, hash
);
22154 /* Compute hash of the whole location list LIST_HEAD. */
22157 hash_loc_list (dw_loc_list_ref list_head
)
22159 dw_loc_list_ref curr
= list_head
;
22160 hashval_t hash
= 0;
22162 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
22164 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
22165 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
22167 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
22169 hash
= hash_locs (curr
->expr
, hash
);
22171 list_head
->hash
= hash
;
22174 /* Return true if X and Y opcodes have the same operands. */
22177 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
22179 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
22180 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
22181 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
22182 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
22184 switch (x
->dw_loc_opc
)
22186 case DW_OP_const4u
:
22187 case DW_OP_const8u
:
22191 case DW_OP_const1u
:
22192 case DW_OP_const1s
:
22193 case DW_OP_const2u
:
22194 case DW_OP_const2s
:
22195 case DW_OP_const4s
:
22196 case DW_OP_const8s
:
22200 case DW_OP_plus_uconst
:
22236 case DW_OP_deref_size
:
22237 case DW_OP_xderef_size
:
22238 return valx1
->v
.val_int
== valy1
->v
.val_int
;
22241 gcc_assert (valx1
->val_class
== dw_val_class_loc
22242 && valy1
->val_class
== dw_val_class_loc
22243 && x
->dw_loc_addr
== y
->dw_loc_addr
);
22244 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
22245 case DW_OP_implicit_value
:
22246 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
22247 || valx2
->val_class
!= valy2
->val_class
)
22249 switch (valx2
->val_class
)
22251 case dw_val_class_const
:
22252 return valx2
->v
.val_int
== valy2
->v
.val_int
;
22253 case dw_val_class_vec
:
22254 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
22255 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
22256 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
22257 valx2
->v
.val_vec
.elt_size
22258 * valx2
->v
.val_vec
.length
) == 0;
22259 case dw_val_class_const_double
:
22260 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
22261 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
22262 case dw_val_class_addr
:
22263 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
22265 gcc_unreachable ();
22268 case DW_OP_bit_piece
:
22269 return valx1
->v
.val_int
== valy1
->v
.val_int
22270 && valx2
->v
.val_int
== valy2
->v
.val_int
;
22273 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
22274 case DW_OP_GNU_implicit_pointer
:
22275 return valx1
->val_class
== dw_val_class_die_ref
22276 && valx1
->val_class
== valy1
->val_class
22277 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
22278 && valx2
->v
.val_int
== valy2
->v
.val_int
;
22279 case DW_OP_GNU_entry_value
:
22280 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
22281 case DW_OP_GNU_const_type
:
22282 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
22283 || valx2
->val_class
!= valy2
->val_class
)
22285 switch (valx2
->val_class
)
22287 case dw_val_class_const
:
22288 return valx2
->v
.val_int
== valy2
->v
.val_int
;
22289 case dw_val_class_vec
:
22290 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
22291 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
22292 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
22293 valx2
->v
.val_vec
.elt_size
22294 * valx2
->v
.val_vec
.length
) == 0;
22295 case dw_val_class_const_double
:
22296 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
22297 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
22299 gcc_unreachable ();
22301 case DW_OP_GNU_regval_type
:
22302 case DW_OP_GNU_deref_type
:
22303 return valx1
->v
.val_int
== valy1
->v
.val_int
22304 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
22305 case DW_OP_GNU_convert
:
22306 case DW_OP_GNU_reinterpret
:
22307 if (valx1
->val_class
!= valy1
->val_class
)
22309 if (valx1
->val_class
== dw_val_class_unsigned_const
)
22310 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
22311 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
22312 case DW_OP_GNU_parameter_ref
:
22313 return valx1
->val_class
== dw_val_class_die_ref
22314 && valx1
->val_class
== valy1
->val_class
22315 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
22317 /* Other codes have no operands. */
22322 /* Return true if DWARF location expressions X and Y are the same. */
22325 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
22327 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
22328 if (x
->dw_loc_opc
!= y
->dw_loc_opc
22329 || x
->dtprel
!= y
->dtprel
22330 || !compare_loc_operands (x
, y
))
22332 return x
== NULL
&& y
== NULL
;
22335 /* Return precomputed hash of location list X. */
22338 loc_list_hash (const void *x
)
22340 return ((const struct dw_loc_list_struct
*) x
)->hash
;
22343 /* Return 1 if location lists X and Y are the same. */
22346 loc_list_eq (const void *x
, const void *y
)
22348 const struct dw_loc_list_struct
*a
= (const struct dw_loc_list_struct
*) x
;
22349 const struct dw_loc_list_struct
*b
= (const struct dw_loc_list_struct
*) y
;
22352 if (a
->hash
!= b
->hash
)
22354 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
22355 if (strcmp (a
->begin
, b
->begin
) != 0
22356 || strcmp (a
->end
, b
->end
) != 0
22357 || (a
->section
== NULL
) != (b
->section
== NULL
)
22358 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
22359 || !compare_locs (a
->expr
, b
->expr
))
22361 return a
== NULL
&& b
== NULL
;
22364 /* Recursively optimize location lists referenced from DIE
22365 children and share them whenever possible. */
22368 optimize_location_lists_1 (dw_die_ref die
, htab_t htab
)
22375 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
22376 if (AT_class (a
) == dw_val_class_loc_list
)
22378 dw_loc_list_ref list
= AT_loc_list (a
);
22379 /* TODO: perform some optimizations here, before hashing
22380 it and storing into the hash table. */
22381 hash_loc_list (list
);
22382 slot
= htab_find_slot_with_hash (htab
, list
, list
->hash
,
22385 *slot
= (void *) list
;
22387 a
->dw_attr_val
.v
.val_loc_list
= (dw_loc_list_ref
) *slot
;
22390 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
22393 /* Optimize location lists referenced from DIE
22394 children and share them whenever possible. */
22397 optimize_location_lists (dw_die_ref die
)
22399 htab_t htab
= htab_create (500, loc_list_hash
, loc_list_eq
, NULL
);
22400 optimize_location_lists_1 (die
, htab
);
22401 htab_delete (htab
);
22404 /* Output stuff that dwarf requires at the end of every file,
22405 and generate the DWARF-2 debugging info. */
22408 dwarf2out_finish (const char *filename
)
22410 limbo_die_node
*node
, *next_node
;
22411 comdat_type_node
*ctnode
;
22412 htab_t comdat_type_table
;
22415 /* PCH might result in DW_AT_producer string being restored from the
22416 header compilation, fix it up if needed. */
22417 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
22418 if (strcmp (AT_string (producer
), producer_string
) != 0)
22420 struct indirect_string_node
*node
= find_AT_string (producer_string
);
22421 producer
->dw_attr_val
.v
.val_str
= node
;
22424 gen_scheduled_generic_parms_dies ();
22425 gen_remaining_tmpl_value_param_die_attribute ();
22427 /* Add the name for the main input file now. We delayed this from
22428 dwarf2out_init to avoid complications with PCH. */
22429 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
22430 if (!IS_ABSOLUTE_PATH (filename
))
22431 add_comp_dir_attribute (comp_unit_die ());
22432 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
22435 htab_traverse (file_table
, file_table_relative_p
, &p
);
22437 add_comp_dir_attribute (comp_unit_die ());
22440 for (i
= 0; i
< VEC_length (deferred_locations
, deferred_locations_list
); i
++)
22442 add_location_or_const_value_attribute (
22443 VEC_index (deferred_locations
, deferred_locations_list
, i
)->die
,
22444 VEC_index (deferred_locations
, deferred_locations_list
, i
)->variable
,
22449 /* Traverse the limbo die list, and add parent/child links. The only
22450 dies without parents that should be here are concrete instances of
22451 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
22452 For concrete instances, we can get the parent die from the abstract
22454 for (node
= limbo_die_list
; node
; node
= next_node
)
22456 dw_die_ref die
= node
->die
;
22457 next_node
= node
->next
;
22459 if (die
->die_parent
== NULL
)
22461 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
22463 if (origin
&& origin
->die_parent
)
22464 add_child_die (origin
->die_parent
, die
);
22465 else if (is_cu_die (die
))
22467 else if (seen_error ())
22468 /* It's OK to be confused by errors in the input. */
22469 add_child_die (comp_unit_die (), die
);
22472 /* In certain situations, the lexical block containing a
22473 nested function can be optimized away, which results
22474 in the nested function die being orphaned. Likewise
22475 with the return type of that nested function. Force
22476 this to be a child of the containing function.
22478 It may happen that even the containing function got fully
22479 inlined and optimized out. In that case we are lost and
22480 assign the empty child. This should not be big issue as
22481 the function is likely unreachable too. */
22482 tree context
= NULL_TREE
;
22484 gcc_assert (node
->created_for
);
22486 if (DECL_P (node
->created_for
))
22487 context
= DECL_CONTEXT (node
->created_for
);
22488 else if (TYPE_P (node
->created_for
))
22489 context
= TYPE_CONTEXT (node
->created_for
);
22491 gcc_assert (context
22492 && (TREE_CODE (context
) == FUNCTION_DECL
22493 || TREE_CODE (context
) == NAMESPACE_DECL
));
22495 origin
= lookup_decl_die (context
);
22497 add_child_die (origin
, die
);
22499 add_child_die (comp_unit_die (), die
);
22504 limbo_die_list
= NULL
;
22506 #if ENABLE_ASSERT_CHECKING
22508 dw_die_ref die
= comp_unit_die (), c
;
22509 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
22512 resolve_addr (comp_unit_die ());
22513 move_marked_base_types ();
22515 for (node
= deferred_asm_name
; node
; node
= node
->next
)
22517 tree decl
= node
->created_for
;
22518 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
22520 add_linkage_attr (node
->die
, decl
);
22521 move_linkage_attr (node
->die
);
22525 deferred_asm_name
= NULL
;
22527 /* Walk through the list of incomplete types again, trying once more to
22528 emit full debugging info for them. */
22529 retry_incomplete_types ();
22531 if (flag_eliminate_unused_debug_types
)
22532 prune_unused_types ();
22534 /* Generate separate CUs for each of the include files we've seen.
22535 They will go into limbo_die_list. */
22536 if (flag_eliminate_dwarf2_dups
&& ! use_debug_types
)
22537 break_out_includes (comp_unit_die ());
22539 /* Generate separate COMDAT sections for type DIEs. */
22540 if (use_debug_types
)
22542 break_out_comdat_types (comp_unit_die ());
22544 /* Each new type_unit DIE was added to the limbo die list when created.
22545 Since these have all been added to comdat_type_list, clear the
22547 limbo_die_list
= NULL
;
22549 /* For each new comdat type unit, copy declarations for incomplete
22550 types to make the new unit self-contained (i.e., no direct
22551 references to the main compile unit). */
22552 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22553 copy_decls_for_unworthy_types (ctnode
->root_die
);
22554 copy_decls_for_unworthy_types (comp_unit_die ());
22556 /* In the process of copying declarations from one unit to another,
22557 we may have left some declarations behind that are no longer
22558 referenced. Prune them. */
22559 prune_unused_types ();
22562 /* Traverse the DIE's and add add sibling attributes to those DIE's
22563 that have children. */
22564 add_sibling_attributes (comp_unit_die ());
22565 for (node
= limbo_die_list
; node
; node
= node
->next
)
22566 add_sibling_attributes (node
->die
);
22567 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22568 add_sibling_attributes (ctnode
->root_die
);
22570 /* Output a terminator label for the .text section. */
22571 switch_to_section (text_section
);
22572 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
22573 if (cold_text_section
)
22575 switch_to_section (cold_text_section
);
22576 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
22579 /* We can only use the low/high_pc attributes if all of the code was
22581 if (!have_multiple_function_sections
22582 || (dwarf_version
< 3 && dwarf_strict
))
22584 /* Don't add if the CU has no associated code. */
22585 if (text_section_used
)
22587 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc
, text_section_label
);
22588 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc
, text_end_label
);
22595 bool range_list_added
= false;
22597 if (text_section_used
)
22598 add_ranges_by_labels (comp_unit_die (), text_section_label
,
22599 text_end_label
, &range_list_added
);
22600 if (cold_text_section_used
)
22601 add_ranges_by_labels (comp_unit_die (), cold_text_section_label
,
22602 cold_end_label
, &range_list_added
);
22604 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, fde_idx
, fde
)
22606 if (!fde
->in_std_section
)
22607 add_ranges_by_labels (comp_unit_die (), fde
->dw_fde_begin
,
22608 fde
->dw_fde_end
, &range_list_added
);
22609 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
22610 add_ranges_by_labels (comp_unit_die (), fde
->dw_fde_second_begin
,
22611 fde
->dw_fde_second_end
, &range_list_added
);
22614 if (range_list_added
)
22616 /* We need to give .debug_loc and .debug_ranges an appropriate
22617 "base address". Use zero so that these addresses become
22618 absolute. Historically, we've emitted the unexpected
22619 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
22620 Emit both to give time for other tools to adapt. */
22621 add_AT_addr (comp_unit_die (), DW_AT_low_pc
, const0_rtx
);
22622 if (! dwarf_strict
&& dwarf_version
< 4)
22623 add_AT_addr (comp_unit_die (), DW_AT_entry_pc
, const0_rtx
);
22629 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
22630 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list
,
22631 debug_line_section_label
);
22633 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22634 add_AT_macptr (comp_unit_die (),
22635 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
22636 macinfo_section_label
);
22638 if (have_location_lists
)
22639 optimize_location_lists (comp_unit_die ());
22641 /* Output all of the compilation units. We put the main one last so that
22642 the offsets are available to output_pubnames. */
22643 for (node
= limbo_die_list
; node
; node
= node
->next
)
22644 output_comp_unit (node
->die
, 0);
22646 comdat_type_table
= htab_create (100, htab_ct_hash
, htab_ct_eq
, NULL
);
22647 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22649 void **slot
= htab_find_slot (comdat_type_table
, ctnode
, INSERT
);
22651 /* Don't output duplicate types. */
22652 if (*slot
!= HTAB_EMPTY_ENTRY
)
22655 /* Add a pointer to the line table for the main compilation unit
22656 so that the debugger can make sense of DW_AT_decl_file
22658 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
22659 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
22660 debug_line_section_label
);
22662 output_comdat_type_unit (ctnode
);
22665 htab_delete (comdat_type_table
);
22667 /* Output the main compilation unit if non-empty or if .debug_macinfo
22668 will be emitted. */
22669 output_comp_unit (comp_unit_die (), debug_info_level
>= DINFO_LEVEL_VERBOSE
);
22671 /* Output the abbreviation table. */
22672 if (abbrev_die_table_in_use
!= 1)
22674 switch_to_section (debug_abbrev_section
);
22675 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
22676 output_abbrev_section ();
22679 /* Output location list section if necessary. */
22680 if (have_location_lists
)
22682 /* Output the location lists info. */
22683 switch_to_section (debug_loc_section
);
22684 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
22685 DEBUG_LOC_SECTION_LABEL
, 0);
22686 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
22687 output_location_lists (comp_unit_die ());
22690 /* Output public names table if necessary. */
22691 if (!VEC_empty (pubname_entry
, pubname_table
))
22693 gcc_assert (info_section_emitted
);
22694 switch_to_section (debug_pubnames_section
);
22695 output_pubnames (pubname_table
);
22698 /* Output public types table if necessary. */
22699 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
22700 It shouldn't hurt to emit it always, since pure DWARF2 consumers
22701 simply won't look for the section. */
22702 if (!VEC_empty (pubname_entry
, pubtype_table
))
22704 bool empty
= false;
22706 if (flag_eliminate_unused_debug_types
)
22708 /* The pubtypes table might be emptied by pruning unused items. */
22712 FOR_EACH_VEC_ELT (pubname_entry
, pubtype_table
, i
, p
)
22713 if (p
->die
->die_offset
!= 0)
22721 gcc_assert (info_section_emitted
);
22722 switch_to_section (debug_pubtypes_section
);
22723 output_pubnames (pubtype_table
);
22727 /* Output the address range information if a CU (.debug_info section)
22728 was emitted. We output an empty table even if we had no functions
22729 to put in it. This because the consumer has no way to tell the
22730 difference between an empty table that we omitted and failure to
22731 generate a table that would have contained data. */
22732 if (info_section_emitted
)
22734 unsigned long aranges_length
= size_of_aranges ();
22736 switch_to_section (debug_aranges_section
);
22737 output_aranges (aranges_length
);
22740 /* Output ranges section if necessary. */
22741 if (ranges_table_in_use
)
22743 switch_to_section (debug_ranges_section
);
22744 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
22748 /* Have to end the macro section. */
22749 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22751 switch_to_section (debug_macinfo_section
);
22752 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
22753 if (!VEC_empty (macinfo_entry
, macinfo_table
))
22755 dw2_asm_output_data (1, 0, "End compilation unit");
22758 /* Output the source line correspondence table. We must do this
22759 even if there is no line information. Otherwise, on an empty
22760 translation unit, we will generate a present, but empty,
22761 .debug_info section. IRIX 6.5 `nm' will then complain when
22762 examining the file. This is done late so that any filenames
22763 used by the debug_info section are marked as 'used'. */
22764 switch_to_section (debug_line_section
);
22765 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
22766 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
22767 output_line_info ();
22769 /* If we emitted any DW_FORM_strp form attribute, output the string
22771 if (debug_str_hash
)
22772 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
22775 #include "gt-dwarf2out.h"