1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 Free Software Foundation, Inc.
5 Contributed by Gary Funck (gary@intrepid.com).
6 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
7 Extensively modified by Jason Merrill (jason@cygnus.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
37 /* DWARF2 Abbreviation Glossary:
39 CFA = Canonical Frame Address
40 a fixed address on the stack which identifies a call frame.
41 We define it to be the value of SP just before the call insn.
42 The CFA register and offset, which may change during the course
43 of the function, are used to calculate its value at runtime.
45 CFI = Call Frame Instruction
46 an instruction for the DWARF2 abstract machine
48 CIE = Common Information Entry
49 information describing information common to one or more FDEs
51 DIE = Debugging Information Entry
53 FDE = Frame Description Entry
54 information describing the stack call frame, in particular,
55 how to restore registers
57 DW_CFA_... = DWARF2 CFA call frame instruction
58 DW_TAG_... = DWARF2 DIE tag */
62 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
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");
883 /* Turn off app to make assembly quicker. */
888 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
891 dwarf2out_do_cfi_startproc (bool second
)
895 rtx personality
= get_personality_function (current_function_decl
);
897 fprintf (asm_out_file
, "\t.cfi_startproc\n");
901 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
904 /* ??? The GAS support isn't entirely consistent. We have to
905 handle indirect support ourselves, but PC-relative is done
906 in the assembler. Further, the assembler can't handle any
907 of the weirder relocation types. */
908 if (enc
& DW_EH_PE_indirect
)
909 ref
= dw2_force_const_mem (ref
, true);
911 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
912 output_addr_const (asm_out_file
, ref
);
913 fputc ('\n', asm_out_file
);
916 if (crtl
->uses_eh_lsda
)
920 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
921 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
922 current_function_funcdef_no
);
923 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
924 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
926 if (enc
& DW_EH_PE_indirect
)
927 ref
= dw2_force_const_mem (ref
, true);
929 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
930 output_addr_const (asm_out_file
, ref
);
931 fputc ('\n', asm_out_file
);
935 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
936 this allocation may be done before pass_final. */
939 dwarf2out_alloc_current_fde (void)
943 fde
= ggc_alloc_cleared_dw_fde_node ();
944 fde
->decl
= current_function_decl
;
945 fde
->funcdef_number
= current_function_funcdef_no
;
946 fde
->fde_index
= VEC_length (dw_fde_ref
, fde_vec
);
947 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
948 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
949 fde
->nothrow
= crtl
->nothrow
;
950 fde
->drap_reg
= INVALID_REGNUM
;
951 fde
->vdrap_reg
= INVALID_REGNUM
;
953 /* Record the FDE associated with this function. */
955 VEC_safe_push (dw_fde_ref
, gc
, fde_vec
, fde
);
960 /* Output a marker (i.e. a label) for the beginning of a function, before
964 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
965 const char *file ATTRIBUTE_UNUSED
)
967 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
973 current_function_func_begin_label
= NULL
;
975 do_frame
= dwarf2out_do_frame ();
977 /* ??? current_function_func_begin_label is also used by except.c for
978 call-site information. We must emit this label if it might be used. */
981 || targetm_common
.except_unwind_info (&global_options
) != UI_TARGET
))
984 fnsec
= function_section (current_function_decl
);
985 switch_to_section (fnsec
);
986 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
987 current_function_funcdef_no
);
988 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
989 current_function_funcdef_no
);
990 dup_label
= xstrdup (label
);
991 current_function_func_begin_label
= dup_label
;
993 /* We can elide the fde allocation if we're not emitting debug info. */
997 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
998 emit insns as rtx but bypass the bulk of rest_of_compilation, which
999 would include pass_dwarf2_frame. If we've not created the FDE yet,
1003 fde
= dwarf2out_alloc_current_fde ();
1005 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1006 fde
->dw_fde_begin
= dup_label
;
1007 fde
->dw_fde_current_label
= dup_label
;
1008 fde
->in_std_section
= (fnsec
== text_section
1009 || (cold_text_section
&& fnsec
== cold_text_section
));
1011 /* We only want to output line number information for the genuine dwarf2
1012 prologue case, not the eh frame case. */
1013 #ifdef DWARF2_DEBUGGING_INFO
1015 dwarf2out_source_line (line
, file
, 0, true);
1018 if (dwarf2out_do_cfi_asm ())
1019 dwarf2out_do_cfi_startproc (false);
1022 rtx personality
= get_personality_function (current_function_decl
);
1023 if (!current_unit_personality
)
1024 current_unit_personality
= personality
;
1026 /* We cannot keep a current personality per function as without CFI
1027 asm, at the point where we emit the CFI data, there is no current
1028 function anymore. */
1029 if (personality
&& current_unit_personality
!= personality
)
1030 sorry ("multiple EH personalities are supported only with assemblers "
1031 "supporting .cfi_personality directive");
1035 /* Output a marker (i.e. a label) for the end of the generated code
1036 for a function prologue. This gets called *after* the prologue code has
1040 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1041 const char *file ATTRIBUTE_UNUSED
)
1043 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1045 /* Output a label to mark the endpoint of the code generated for this
1047 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1048 current_function_funcdef_no
);
1049 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1050 current_function_funcdef_no
);
1051 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1054 /* Output a marker (i.e. a label) for the beginning of the generated code
1055 for a function epilogue. This gets called *before* the prologue code has
1059 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1060 const char *file ATTRIBUTE_UNUSED
)
1062 dw_fde_ref fde
= cfun
->fde
;
1063 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1065 if (fde
->dw_fde_vms_begin_epilogue
)
1068 /* Output a label to mark the endpoint of the code generated for this
1070 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1071 current_function_funcdef_no
);
1072 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1073 current_function_funcdef_no
);
1074 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1077 /* Output a marker (i.e. a label) for the absolute end of the generated code
1078 for a function definition. This gets called *after* the epilogue code has
1082 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1083 const char *file ATTRIBUTE_UNUSED
)
1086 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1088 last_var_location_insn
= NULL_RTX
;
1089 cached_next_real_insn
= NULL_RTX
;
1091 if (dwarf2out_do_cfi_asm ())
1092 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1094 /* Output a label to mark the endpoint of the code generated for this
1096 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1097 current_function_funcdef_no
);
1098 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1100 gcc_assert (fde
!= NULL
);
1101 if (fde
->dw_fde_second_begin
== NULL
)
1102 fde
->dw_fde_end
= xstrdup (label
);
1106 dwarf2out_frame_finish (void)
1108 /* Output call frame information. */
1109 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1110 output_call_frame_info (0);
1112 /* Output another copy for the unwinder. */
1113 if ((flag_unwind_tables
|| flag_exceptions
)
1114 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1115 output_call_frame_info (1);
1118 /* Note that the current function section is being used for code. */
1121 dwarf2out_note_section_used (void)
1123 section
*sec
= current_function_section ();
1124 if (sec
== text_section
)
1125 text_section_used
= true;
1126 else if (sec
== cold_text_section
)
1127 cold_text_section_used
= true;
1130 static void var_location_switch_text_section (void);
1131 static void set_cur_line_info_table (section
*);
1134 dwarf2out_switch_text_section (void)
1137 dw_fde_ref fde
= cfun
->fde
;
1139 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1141 if (!in_cold_section_p
)
1143 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1144 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1145 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1149 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1150 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1151 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1153 have_multiple_function_sections
= true;
1155 /* There is no need to mark used sections when not debugging. */
1156 if (cold_text_section
!= NULL
)
1157 dwarf2out_note_section_used ();
1159 if (dwarf2out_do_cfi_asm ())
1160 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1162 /* Now do the real section switch. */
1163 sect
= current_function_section ();
1164 switch_to_section (sect
);
1166 fde
->second_in_std_section
1167 = (sect
== text_section
1168 || (cold_text_section
&& sect
== cold_text_section
));
1170 if (dwarf2out_do_cfi_asm ())
1171 dwarf2out_do_cfi_startproc (true);
1173 var_location_switch_text_section ();
1175 if (cold_text_section
!= NULL
)
1176 set_cur_line_info_table (sect
);
1179 /* And now, the subset of the debugging information support code necessary
1180 for emitting location expressions. */
1182 /* Data about a single source file. */
1183 struct GTY(()) dwarf_file_data
{
1184 const char * filename
;
1188 typedef struct GTY(()) deferred_locations_struct
1192 } deferred_locations
;
1194 DEF_VEC_O(deferred_locations
);
1195 DEF_VEC_ALLOC_O(deferred_locations
,gc
);
1197 static GTY(()) VEC(deferred_locations
, gc
) *deferred_locations_list
;
1199 DEF_VEC_P(dw_die_ref
);
1200 DEF_VEC_ALLOC_P(dw_die_ref
,heap
);
1202 /* Location lists are ranges + location descriptions for that range,
1203 so you can track variables that are in different places over
1204 their entire life. */
1205 typedef struct GTY(()) dw_loc_list_struct
{
1206 dw_loc_list_ref dw_loc_next
;
1207 const char *begin
; /* Label for begin address of range */
1208 const char *end
; /* Label for end address of range */
1209 char *ll_symbol
; /* Label for beginning of location list.
1210 Only on head of list */
1211 const char *section
; /* Section this loclist is relative to */
1212 dw_loc_descr_ref expr
;
1214 /* True if all addresses in this and subsequent lists are known to be
1217 /* True if this list has been replaced by dw_loc_next. */
1220 /* True if the range should be emitted even if begin and end
1225 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1227 /* Convert a DWARF stack opcode into its string name. */
1230 dwarf_stack_op_name (unsigned int op
)
1235 return "DW_OP_addr";
1237 return "DW_OP_deref";
1239 return "DW_OP_const1u";
1241 return "DW_OP_const1s";
1243 return "DW_OP_const2u";
1245 return "DW_OP_const2s";
1247 return "DW_OP_const4u";
1249 return "DW_OP_const4s";
1251 return "DW_OP_const8u";
1253 return "DW_OP_const8s";
1255 return "DW_OP_constu";
1257 return "DW_OP_consts";
1261 return "DW_OP_drop";
1263 return "DW_OP_over";
1265 return "DW_OP_pick";
1267 return "DW_OP_swap";
1271 return "DW_OP_xderef";
1279 return "DW_OP_minus";
1291 return "DW_OP_plus";
1292 case DW_OP_plus_uconst
:
1293 return "DW_OP_plus_uconst";
1299 return "DW_OP_shra";
1317 return "DW_OP_skip";
1319 return "DW_OP_lit0";
1321 return "DW_OP_lit1";
1323 return "DW_OP_lit2";
1325 return "DW_OP_lit3";
1327 return "DW_OP_lit4";
1329 return "DW_OP_lit5";
1331 return "DW_OP_lit6";
1333 return "DW_OP_lit7";
1335 return "DW_OP_lit8";
1337 return "DW_OP_lit9";
1339 return "DW_OP_lit10";
1341 return "DW_OP_lit11";
1343 return "DW_OP_lit12";
1345 return "DW_OP_lit13";
1347 return "DW_OP_lit14";
1349 return "DW_OP_lit15";
1351 return "DW_OP_lit16";
1353 return "DW_OP_lit17";
1355 return "DW_OP_lit18";
1357 return "DW_OP_lit19";
1359 return "DW_OP_lit20";
1361 return "DW_OP_lit21";
1363 return "DW_OP_lit22";
1365 return "DW_OP_lit23";
1367 return "DW_OP_lit24";
1369 return "DW_OP_lit25";
1371 return "DW_OP_lit26";
1373 return "DW_OP_lit27";
1375 return "DW_OP_lit28";
1377 return "DW_OP_lit29";
1379 return "DW_OP_lit30";
1381 return "DW_OP_lit31";
1383 return "DW_OP_reg0";
1385 return "DW_OP_reg1";
1387 return "DW_OP_reg2";
1389 return "DW_OP_reg3";
1391 return "DW_OP_reg4";
1393 return "DW_OP_reg5";
1395 return "DW_OP_reg6";
1397 return "DW_OP_reg7";
1399 return "DW_OP_reg8";
1401 return "DW_OP_reg9";
1403 return "DW_OP_reg10";
1405 return "DW_OP_reg11";
1407 return "DW_OP_reg12";
1409 return "DW_OP_reg13";
1411 return "DW_OP_reg14";
1413 return "DW_OP_reg15";
1415 return "DW_OP_reg16";
1417 return "DW_OP_reg17";
1419 return "DW_OP_reg18";
1421 return "DW_OP_reg19";
1423 return "DW_OP_reg20";
1425 return "DW_OP_reg21";
1427 return "DW_OP_reg22";
1429 return "DW_OP_reg23";
1431 return "DW_OP_reg24";
1433 return "DW_OP_reg25";
1435 return "DW_OP_reg26";
1437 return "DW_OP_reg27";
1439 return "DW_OP_reg28";
1441 return "DW_OP_reg29";
1443 return "DW_OP_reg30";
1445 return "DW_OP_reg31";
1447 return "DW_OP_breg0";
1449 return "DW_OP_breg1";
1451 return "DW_OP_breg2";
1453 return "DW_OP_breg3";
1455 return "DW_OP_breg4";
1457 return "DW_OP_breg5";
1459 return "DW_OP_breg6";
1461 return "DW_OP_breg7";
1463 return "DW_OP_breg8";
1465 return "DW_OP_breg9";
1467 return "DW_OP_breg10";
1469 return "DW_OP_breg11";
1471 return "DW_OP_breg12";
1473 return "DW_OP_breg13";
1475 return "DW_OP_breg14";
1477 return "DW_OP_breg15";
1479 return "DW_OP_breg16";
1481 return "DW_OP_breg17";
1483 return "DW_OP_breg18";
1485 return "DW_OP_breg19";
1487 return "DW_OP_breg20";
1489 return "DW_OP_breg21";
1491 return "DW_OP_breg22";
1493 return "DW_OP_breg23";
1495 return "DW_OP_breg24";
1497 return "DW_OP_breg25";
1499 return "DW_OP_breg26";
1501 return "DW_OP_breg27";
1503 return "DW_OP_breg28";
1505 return "DW_OP_breg29";
1507 return "DW_OP_breg30";
1509 return "DW_OP_breg31";
1511 return "DW_OP_regx";
1513 return "DW_OP_fbreg";
1515 return "DW_OP_bregx";
1517 return "DW_OP_piece";
1518 case DW_OP_deref_size
:
1519 return "DW_OP_deref_size";
1520 case DW_OP_xderef_size
:
1521 return "DW_OP_xderef_size";
1525 case DW_OP_push_object_address
:
1526 return "DW_OP_push_object_address";
1528 return "DW_OP_call2";
1530 return "DW_OP_call4";
1531 case DW_OP_call_ref
:
1532 return "DW_OP_call_ref";
1533 case DW_OP_implicit_value
:
1534 return "DW_OP_implicit_value";
1535 case DW_OP_stack_value
:
1536 return "DW_OP_stack_value";
1537 case DW_OP_form_tls_address
:
1538 return "DW_OP_form_tls_address";
1539 case DW_OP_call_frame_cfa
:
1540 return "DW_OP_call_frame_cfa";
1541 case DW_OP_bit_piece
:
1542 return "DW_OP_bit_piece";
1544 case DW_OP_GNU_push_tls_address
:
1545 return "DW_OP_GNU_push_tls_address";
1546 case DW_OP_GNU_uninit
:
1547 return "DW_OP_GNU_uninit";
1548 case DW_OP_GNU_encoded_addr
:
1549 return "DW_OP_GNU_encoded_addr";
1550 case DW_OP_GNU_implicit_pointer
:
1551 return "DW_OP_GNU_implicit_pointer";
1552 case DW_OP_GNU_entry_value
:
1553 return "DW_OP_GNU_entry_value";
1554 case DW_OP_GNU_const_type
:
1555 return "DW_OP_GNU_const_type";
1556 case DW_OP_GNU_regval_type
:
1557 return "DW_OP_GNU_regval_type";
1558 case DW_OP_GNU_deref_type
:
1559 return "DW_OP_GNU_deref_type";
1560 case DW_OP_GNU_convert
:
1561 return "DW_OP_GNU_convert";
1562 case DW_OP_GNU_reinterpret
:
1563 return "DW_OP_GNU_reinterpret";
1564 case DW_OP_GNU_parameter_ref
:
1565 return "DW_OP_GNU_parameter_ref";
1568 return "OP_<unknown>";
1572 /* Return a pointer to a newly allocated location description. Location
1573 descriptions are simple expression terms that can be strung
1574 together to form more complicated location (address) descriptions. */
1576 static inline dw_loc_descr_ref
1577 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1578 unsigned HOST_WIDE_INT oprnd2
)
1580 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
1582 descr
->dw_loc_opc
= op
;
1583 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1584 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1585 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1586 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1591 /* Return a pointer to a newly allocated location description for
1594 static inline dw_loc_descr_ref
1595 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1598 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1601 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1604 /* Add a location description term to a location description expression. */
1607 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1609 dw_loc_descr_ref
*d
;
1611 /* Find the end of the chain. */
1612 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1618 /* Compare two location operands for exact equality. */
1621 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1623 if (a
->val_class
!= b
->val_class
)
1625 switch (a
->val_class
)
1627 case dw_val_class_none
:
1629 case dw_val_class_addr
:
1630 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1632 case dw_val_class_offset
:
1633 case dw_val_class_unsigned_const
:
1634 case dw_val_class_const
:
1635 case dw_val_class_range_list
:
1636 case dw_val_class_lineptr
:
1637 case dw_val_class_macptr
:
1638 /* These are all HOST_WIDE_INT, signed or unsigned. */
1639 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1641 case dw_val_class_loc
:
1642 return a
->v
.val_loc
== b
->v
.val_loc
;
1643 case dw_val_class_loc_list
:
1644 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1645 case dw_val_class_die_ref
:
1646 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1647 case dw_val_class_fde_ref
:
1648 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1649 case dw_val_class_lbl_id
:
1650 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1651 case dw_val_class_str
:
1652 return a
->v
.val_str
== b
->v
.val_str
;
1653 case dw_val_class_flag
:
1654 return a
->v
.val_flag
== b
->v
.val_flag
;
1655 case dw_val_class_file
:
1656 return a
->v
.val_file
== b
->v
.val_file
;
1657 case dw_val_class_decl_ref
:
1658 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1660 case dw_val_class_const_double
:
1661 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1662 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1664 case dw_val_class_vec
:
1666 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1667 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1669 return (a_len
== b_len
1670 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1673 case dw_val_class_data8
:
1674 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1676 case dw_val_class_vms_delta
:
1677 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1678 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1683 /* Compare two location atoms for exact equality. */
1686 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1688 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1691 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1692 address size, but since we always allocate cleared storage it
1693 should be zero for other types of locations. */
1694 if (a
->dtprel
!= b
->dtprel
)
1697 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1698 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1701 /* Compare two complete location expressions for exact equality. */
1704 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1710 if (a
== NULL
|| b
== NULL
)
1712 if (!loc_descr_equal_p_1 (a
, b
))
1721 /* Add a constant OFFSET to a location expression. */
1724 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1726 dw_loc_descr_ref loc
;
1729 gcc_assert (*list_head
!= NULL
);
1734 /* Find the end of the chain. */
1735 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1739 if (loc
->dw_loc_opc
== DW_OP_fbreg
1740 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1741 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1742 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1743 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1745 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1746 offset. Don't optimize if an signed integer overflow would happen. */
1748 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1749 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1752 else if (offset
> 0)
1753 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1757 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1758 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1762 /* Add a constant OFFSET to a location list. */
1765 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1768 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1769 loc_descr_plus_const (&d
->expr
, offset
);
1772 #define DWARF_REF_SIZE \
1773 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1775 static unsigned long int get_base_type_offset (dw_die_ref
);
1777 /* Return the size of a location descriptor. */
1779 static unsigned long
1780 size_of_loc_descr (dw_loc_descr_ref loc
)
1782 unsigned long size
= 1;
1784 switch (loc
->dw_loc_opc
)
1787 size
+= DWARF2_ADDR_SIZE
;
1806 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1809 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1814 case DW_OP_plus_uconst
:
1815 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1853 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1856 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1859 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1862 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1863 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1866 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1868 case DW_OP_bit_piece
:
1869 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1870 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1872 case DW_OP_deref_size
:
1873 case DW_OP_xderef_size
:
1882 case DW_OP_call_ref
:
1883 size
+= DWARF_REF_SIZE
;
1885 case DW_OP_implicit_value
:
1886 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1887 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1889 case DW_OP_GNU_implicit_pointer
:
1890 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1892 case DW_OP_GNU_entry_value
:
1894 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1895 size
+= size_of_uleb128 (op_size
) + op_size
;
1898 case DW_OP_GNU_const_type
:
1901 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1902 size
+= size_of_uleb128 (o
) + 1;
1903 switch (loc
->dw_loc_oprnd2
.val_class
)
1905 case dw_val_class_vec
:
1906 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1907 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1909 case dw_val_class_const
:
1910 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1912 case dw_val_class_const_double
:
1913 size
+= 2 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1920 case DW_OP_GNU_regval_type
:
1923 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1924 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1925 + size_of_uleb128 (o
);
1928 case DW_OP_GNU_deref_type
:
1931 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1932 size
+= 1 + size_of_uleb128 (o
);
1935 case DW_OP_GNU_convert
:
1936 case DW_OP_GNU_reinterpret
:
1937 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1938 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1942 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1943 size
+= size_of_uleb128 (o
);
1946 case DW_OP_GNU_parameter_ref
:
1956 /* Return the size of a series of location descriptors. */
1959 size_of_locs (dw_loc_descr_ref loc
)
1964 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1965 field, to avoid writing to a PCH file. */
1966 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1968 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1970 size
+= size_of_loc_descr (l
);
1975 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1977 l
->dw_loc_addr
= size
;
1978 size
+= size_of_loc_descr (l
);
1984 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1985 static void get_ref_die_offset_label (char *, dw_die_ref
);
1986 static unsigned long int get_ref_die_offset (dw_die_ref
);
1988 /* Output location description stack opcode's operands (if any).
1989 The for_eh_or_skip parameter controls whether register numbers are
1990 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1991 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1992 info). This should be suppressed for the cases that have not been converted
1993 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1996 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1998 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1999 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2001 switch (loc
->dw_loc_opc
)
2003 #ifdef DWARF2_DEBUGGING_INFO
2006 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
2011 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
2012 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
2014 fputc ('\n', asm_out_file
);
2019 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
2024 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
2025 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
2027 fputc ('\n', asm_out_file
);
2032 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2033 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
2040 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2041 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2043 dw2_asm_output_data (2, offset
, NULL
);
2046 case DW_OP_implicit_value
:
2047 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2048 switch (val2
->val_class
)
2050 case dw_val_class_const
:
2051 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
2053 case dw_val_class_vec
:
2055 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2056 unsigned int len
= val2
->v
.val_vec
.length
;
2060 if (elt_size
> sizeof (HOST_WIDE_INT
))
2065 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2068 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2069 "fp or vector constant word %u", i
);
2072 case dw_val_class_const_double
:
2074 unsigned HOST_WIDE_INT first
, second
;
2076 if (WORDS_BIG_ENDIAN
)
2078 first
= val2
->v
.val_double
.high
;
2079 second
= val2
->v
.val_double
.low
;
2083 first
= val2
->v
.val_double
.low
;
2084 second
= val2
->v
.val_double
.high
;
2086 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2088 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2092 case dw_val_class_addr
:
2093 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
2094 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
2109 case DW_OP_implicit_value
:
2110 /* We currently don't make any attempt to make sure these are
2111 aligned properly like we do for the main unwind info, so
2112 don't support emitting things larger than a byte if we're
2113 only doing unwinding. */
2118 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2121 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2124 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2127 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2129 case DW_OP_plus_uconst
:
2130 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2164 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2168 unsigned r
= val1
->v
.val_unsigned
;
2169 if (for_eh_or_skip
>= 0)
2170 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2171 gcc_assert (size_of_uleb128 (r
)
2172 == size_of_uleb128 (val1
->v
.val_unsigned
));
2173 dw2_asm_output_data_uleb128 (r
, NULL
);
2177 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2181 unsigned r
= val1
->v
.val_unsigned
;
2182 if (for_eh_or_skip
>= 0)
2183 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2184 gcc_assert (size_of_uleb128 (r
)
2185 == size_of_uleb128 (val1
->v
.val_unsigned
));
2186 dw2_asm_output_data_uleb128 (r
, NULL
);
2187 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2191 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2193 case DW_OP_bit_piece
:
2194 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2195 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
2197 case DW_OP_deref_size
:
2198 case DW_OP_xderef_size
:
2199 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2205 if (targetm
.asm_out
.output_dwarf_dtprel
)
2207 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
2210 fputc ('\n', asm_out_file
);
2217 #ifdef DWARF2_DEBUGGING_INFO
2218 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2225 case DW_OP_GNU_implicit_pointer
:
2227 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2228 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2229 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2230 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2231 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2232 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2236 case DW_OP_GNU_entry_value
:
2237 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2238 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2241 case DW_OP_GNU_const_type
:
2243 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2245 dw2_asm_output_data_uleb128 (o
, NULL
);
2246 switch (val2
->val_class
)
2248 case dw_val_class_const
:
2249 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2250 dw2_asm_output_data (1, l
, NULL
);
2251 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2253 case dw_val_class_vec
:
2255 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2256 unsigned int len
= val2
->v
.val_vec
.length
;
2261 dw2_asm_output_data (1, l
, NULL
);
2262 if (elt_size
> sizeof (HOST_WIDE_INT
))
2267 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2270 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2271 "fp or vector constant word %u", i
);
2274 case dw_val_class_const_double
:
2276 unsigned HOST_WIDE_INT first
, second
;
2277 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2279 dw2_asm_output_data (1, 2 * l
, NULL
);
2280 if (WORDS_BIG_ENDIAN
)
2282 first
= val2
->v
.val_double
.high
;
2283 second
= val2
->v
.val_double
.low
;
2287 first
= val2
->v
.val_double
.low
;
2288 second
= val2
->v
.val_double
.high
;
2290 dw2_asm_output_data (l
, first
, NULL
);
2291 dw2_asm_output_data (l
, second
, NULL
);
2299 case DW_OP_GNU_regval_type
:
2301 unsigned r
= val1
->v
.val_unsigned
;
2302 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2304 if (for_eh_or_skip
>= 0)
2306 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2307 gcc_assert (size_of_uleb128 (r
)
2308 == size_of_uleb128 (val1
->v
.val_unsigned
));
2310 dw2_asm_output_data_uleb128 (r
, NULL
);
2311 dw2_asm_output_data_uleb128 (o
, NULL
);
2314 case DW_OP_GNU_deref_type
:
2316 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2318 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2319 dw2_asm_output_data_uleb128 (o
, NULL
);
2322 case DW_OP_GNU_convert
:
2323 case DW_OP_GNU_reinterpret
:
2324 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2325 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2328 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2330 dw2_asm_output_data_uleb128 (o
, NULL
);
2334 case DW_OP_GNU_parameter_ref
:
2337 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2338 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2339 dw2_asm_output_data (4, o
, NULL
);
2344 /* Other codes have no operands. */
2349 /* Output a sequence of location operations.
2350 The for_eh_or_skip parameter controls whether register numbers are
2351 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2352 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2353 info). This should be suppressed for the cases that have not been converted
2354 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2357 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2359 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2361 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2362 /* Output the opcode. */
2363 if (for_eh_or_skip
>= 0
2364 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2366 unsigned r
= (opc
- DW_OP_breg0
);
2367 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2368 gcc_assert (r
<= 31);
2369 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2371 else if (for_eh_or_skip
>= 0
2372 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2374 unsigned r
= (opc
- DW_OP_reg0
);
2375 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2376 gcc_assert (r
<= 31);
2377 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2380 dw2_asm_output_data (1, opc
,
2381 "%s", dwarf_stack_op_name (opc
));
2383 /* Output the operand(s) (if any). */
2384 output_loc_operands (loc
, for_eh_or_skip
);
2388 /* Output location description stack opcode's operands (if any).
2389 The output is single bytes on a line, suitable for .cfi_escape. */
2392 output_loc_operands_raw (dw_loc_descr_ref loc
)
2394 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2395 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2397 switch (loc
->dw_loc_opc
)
2400 case DW_OP_implicit_value
:
2401 /* We cannot output addresses in .cfi_escape, only bytes. */
2407 case DW_OP_deref_size
:
2408 case DW_OP_xderef_size
:
2409 fputc (',', asm_out_file
);
2410 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2415 fputc (',', asm_out_file
);
2416 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2421 fputc (',', asm_out_file
);
2422 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2427 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2428 fputc (',', asm_out_file
);
2429 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2437 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2438 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2440 fputc (',', asm_out_file
);
2441 dw2_asm_output_data_raw (2, offset
);
2447 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2448 gcc_assert (size_of_uleb128 (r
)
2449 == size_of_uleb128 (val1
->v
.val_unsigned
));
2450 fputc (',', asm_out_file
);
2451 dw2_asm_output_data_uleb128_raw (r
);
2456 case DW_OP_plus_uconst
:
2458 fputc (',', asm_out_file
);
2459 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2462 case DW_OP_bit_piece
:
2463 fputc (',', asm_out_file
);
2464 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2465 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2502 fputc (',', asm_out_file
);
2503 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2508 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2509 gcc_assert (size_of_uleb128 (r
)
2510 == size_of_uleb128 (val1
->v
.val_unsigned
));
2511 fputc (',', asm_out_file
);
2512 dw2_asm_output_data_uleb128_raw (r
);
2513 fputc (',', asm_out_file
);
2514 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2518 case DW_OP_GNU_implicit_pointer
:
2519 case DW_OP_GNU_entry_value
:
2520 case DW_OP_GNU_const_type
:
2521 case DW_OP_GNU_regval_type
:
2522 case DW_OP_GNU_deref_type
:
2523 case DW_OP_GNU_convert
:
2524 case DW_OP_GNU_reinterpret
:
2525 case DW_OP_GNU_parameter_ref
:
2530 /* Other codes have no operands. */
2536 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2540 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2541 /* Output the opcode. */
2542 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2544 unsigned r
= (opc
- DW_OP_breg0
);
2545 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2546 gcc_assert (r
<= 31);
2547 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2549 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2551 unsigned r
= (opc
- DW_OP_reg0
);
2552 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2553 gcc_assert (r
<= 31);
2554 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2556 /* Output the opcode. */
2557 fprintf (asm_out_file
, "%#x", opc
);
2558 output_loc_operands_raw (loc
);
2560 if (!loc
->dw_loc_next
)
2562 loc
= loc
->dw_loc_next
;
2564 fputc (',', asm_out_file
);
2568 /* This function builds a dwarf location descriptor sequence from a
2569 dw_cfa_location, adding the given OFFSET to the result of the
2572 struct dw_loc_descr_struct
*
2573 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2575 struct dw_loc_descr_struct
*head
, *tmp
;
2577 offset
+= cfa
->offset
;
2581 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2582 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2583 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2584 add_loc_descr (&head
, tmp
);
2587 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2588 add_loc_descr (&head
, tmp
);
2592 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2597 /* This function builds a dwarf location descriptor sequence for
2598 the address at OFFSET from the CFA when stack is aligned to
2601 struct dw_loc_descr_struct
*
2602 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2603 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2605 struct dw_loc_descr_struct
*head
;
2606 unsigned int dwarf_fp
2607 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2609 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2610 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2612 head
= new_reg_loc_descr (dwarf_fp
, 0);
2613 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2614 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2615 loc_descr_plus_const (&head
, offset
);
2618 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2622 /* And now, the support for symbolic debugging information. */
2624 /* .debug_str support. */
2625 static int output_indirect_string (void **, void *);
2627 static void dwarf2out_init (const char *);
2628 static void dwarf2out_finish (const char *);
2629 static void dwarf2out_assembly_start (void);
2630 static void dwarf2out_define (unsigned int, const char *);
2631 static void dwarf2out_undef (unsigned int, const char *);
2632 static void dwarf2out_start_source_file (unsigned, const char *);
2633 static void dwarf2out_end_source_file (unsigned);
2634 static void dwarf2out_function_decl (tree
);
2635 static void dwarf2out_begin_block (unsigned, unsigned);
2636 static void dwarf2out_end_block (unsigned, unsigned);
2637 static bool dwarf2out_ignore_block (const_tree
);
2638 static void dwarf2out_global_decl (tree
);
2639 static void dwarf2out_type_decl (tree
, int);
2640 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2641 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2643 static void dwarf2out_abstract_function (tree
);
2644 static void dwarf2out_var_location (rtx
);
2645 static void dwarf2out_begin_function (tree
);
2646 static void dwarf2out_set_name (tree
, tree
);
2648 /* The debug hooks structure. */
2650 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2654 dwarf2out_assembly_start
,
2657 dwarf2out_start_source_file
,
2658 dwarf2out_end_source_file
,
2659 dwarf2out_begin_block
,
2660 dwarf2out_end_block
,
2661 dwarf2out_ignore_block
,
2662 dwarf2out_source_line
,
2663 dwarf2out_begin_prologue
,
2664 #if VMS_DEBUGGING_INFO
2665 dwarf2out_vms_end_prologue
,
2666 dwarf2out_vms_begin_epilogue
,
2668 debug_nothing_int_charstar
,
2669 debug_nothing_int_charstar
,
2671 dwarf2out_end_epilogue
,
2672 dwarf2out_begin_function
,
2673 debug_nothing_int
, /* end_function */
2674 dwarf2out_function_decl
, /* function_decl */
2675 dwarf2out_global_decl
,
2676 dwarf2out_type_decl
, /* type_decl */
2677 dwarf2out_imported_module_or_decl
,
2678 debug_nothing_tree
, /* deferred_inline_function */
2679 /* The DWARF 2 backend tries to reduce debugging bloat by not
2680 emitting the abstract description of inline functions until
2681 something tries to reference them. */
2682 dwarf2out_abstract_function
, /* outlining_inline_function */
2683 debug_nothing_rtx
, /* label */
2684 debug_nothing_int
, /* handle_pch */
2685 dwarf2out_var_location
,
2686 dwarf2out_switch_text_section
,
2688 1, /* start_end_main_source_file */
2689 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2692 /* NOTE: In the comments in this file, many references are made to
2693 "Debugging Information Entries". This term is abbreviated as `DIE'
2694 throughout the remainder of this file. */
2696 /* An internal representation of the DWARF output is built, and then
2697 walked to generate the DWARF debugging info. The walk of the internal
2698 representation is done after the entire program has been compiled.
2699 The types below are used to describe the internal representation. */
2701 /* Whether to put type DIEs into their own section .debug_types instead
2702 of making them part of the .debug_info section. Only supported for
2703 Dwarf V4 or higher and the user didn't disable them through
2704 -fno-debug-types-section. It is more efficient to put them in a
2705 separate comdat sections since the linker will then be able to
2706 remove duplicates. But not all tools support .debug_types sections
2709 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2711 /* Various DIE's use offsets relative to the beginning of the
2712 .debug_info section to refer to each other. */
2714 typedef long int dw_offset
;
2716 /* Define typedefs here to avoid circular dependencies. */
2718 typedef struct dw_attr_struct
*dw_attr_ref
;
2719 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2720 typedef struct pubname_struct
*pubname_ref
;
2721 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2722 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2723 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2725 /* The entries in the line_info table more-or-less mirror the opcodes
2726 that are used in the real dwarf line table. Arrays of these entries
2727 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2730 enum dw_line_info_opcode
{
2731 /* Emit DW_LNE_set_address; the operand is the label index. */
2734 /* Emit a row to the matrix with the given line. This may be done
2735 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2739 /* Emit a DW_LNS_set_file. */
2742 /* Emit a DW_LNS_set_column. */
2745 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2748 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2749 LI_set_prologue_end
,
2750 LI_set_epilogue_begin
,
2752 /* Emit a DW_LNE_set_discriminator. */
2753 LI_set_discriminator
2756 typedef struct GTY(()) dw_line_info_struct
{
2757 enum dw_line_info_opcode opcode
;
2759 } dw_line_info_entry
;
2761 DEF_VEC_O(dw_line_info_entry
);
2762 DEF_VEC_ALLOC_O(dw_line_info_entry
, gc
);
2764 typedef struct GTY(()) dw_line_info_table_struct
{
2765 /* The label that marks the end of this section. */
2766 const char *end_label
;
2768 /* The values for the last row of the matrix, as collected in the table.
2769 These are used to minimize the changes to the next row. */
2770 unsigned int file_num
;
2771 unsigned int line_num
;
2772 unsigned int column_num
;
2777 VEC(dw_line_info_entry
, gc
) *entries
;
2778 } dw_line_info_table
;
2780 typedef dw_line_info_table
*dw_line_info_table_p
;
2782 DEF_VEC_P(dw_line_info_table_p
);
2783 DEF_VEC_ALLOC_P(dw_line_info_table_p
, gc
);
2785 /* Each DIE attribute has a field specifying the attribute kind,
2786 a link to the next attribute in the chain, and an attribute value.
2787 Attributes are typically linked below the DIE they modify. */
2789 typedef struct GTY(()) dw_attr_struct
{
2790 enum dwarf_attribute dw_attr
;
2791 dw_val_node dw_attr_val
;
2795 DEF_VEC_O(dw_attr_node
);
2796 DEF_VEC_ALLOC_O(dw_attr_node
,gc
);
2798 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2799 The children of each node form a circular list linked by
2800 die_sib. die_child points to the node *before* the "first" child node. */
2802 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
2803 union die_symbol_or_type_node
2805 char * GTY ((tag ("0"))) die_symbol
;
2806 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2808 GTY ((desc ("use_debug_types"))) die_id
;
2809 VEC(dw_attr_node
,gc
) * die_attr
;
2810 dw_die_ref die_parent
;
2811 dw_die_ref die_child
;
2813 dw_die_ref die_definition
; /* ref from a specification to its definition */
2814 dw_offset die_offset
;
2815 unsigned long die_abbrev
;
2817 /* Die is used and must not be pruned as unused. */
2818 int die_perennial_p
;
2819 unsigned int decl_id
;
2820 enum dwarf_tag die_tag
;
2824 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2825 #define FOR_EACH_CHILD(die, c, expr) do { \
2826 c = die->die_child; \
2830 } while (c != die->die_child); \
2833 /* The pubname structure */
2835 typedef struct GTY(()) pubname_struct
{
2841 DEF_VEC_O(pubname_entry
);
2842 DEF_VEC_ALLOC_O(pubname_entry
, gc
);
2844 struct GTY(()) dw_ranges_struct
{
2845 /* If this is positive, it's a block number, otherwise it's a
2846 bitwise-negated index into dw_ranges_by_label. */
2850 /* A structure to hold a macinfo entry. */
2852 typedef struct GTY(()) macinfo_struct
{
2854 unsigned HOST_WIDE_INT lineno
;
2859 DEF_VEC_O(macinfo_entry
);
2860 DEF_VEC_ALLOC_O(macinfo_entry
, gc
);
2862 struct GTY(()) dw_ranges_by_label_struct
{
2867 /* The comdat type node structure. */
2868 typedef struct GTY(()) comdat_type_struct
2870 dw_die_ref root_die
;
2871 dw_die_ref type_die
;
2872 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2873 struct comdat_type_struct
*next
;
2877 /* The limbo die list structure. */
2878 typedef struct GTY(()) limbo_die_struct
{
2881 struct limbo_die_struct
*next
;
2885 typedef struct skeleton_chain_struct
2889 struct skeleton_chain_struct
*parent
;
2891 skeleton_chain_node
;
2893 /* Define a macro which returns nonzero for a TYPE_DECL which was
2894 implicitly generated for a type.
2896 Note that, unlike the C front-end (which generates a NULL named
2897 TYPE_DECL node for each complete tagged type, each array type,
2898 and each function type node created) the C++ front-end generates
2899 a _named_ TYPE_DECL node for each tagged type node created.
2900 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2901 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2902 front-end, but for each type, tagged or not. */
2904 #define TYPE_DECL_IS_STUB(decl) \
2905 (DECL_NAME (decl) == NULL_TREE \
2906 || (DECL_ARTIFICIAL (decl) \
2907 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2908 /* This is necessary for stub decls that \
2909 appear in nested inline functions. */ \
2910 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2911 && (decl_ultimate_origin (decl) \
2912 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2914 /* Information concerning the compilation unit's programming
2915 language, and compiler version. */
2917 /* Fixed size portion of the DWARF compilation unit header. */
2918 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2919 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2921 /* Fixed size portion of the DWARF comdat type unit header. */
2922 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2923 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2924 + DWARF_OFFSET_SIZE)
2926 /* Fixed size portion of public names info. */
2927 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2929 /* Fixed size portion of the address range info. */
2930 #define DWARF_ARANGES_HEADER_SIZE \
2931 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2932 DWARF2_ADDR_SIZE * 2) \
2933 - DWARF_INITIAL_LENGTH_SIZE)
2935 /* Size of padding portion in the address range info. It must be
2936 aligned to twice the pointer size. */
2937 #define DWARF_ARANGES_PAD_SIZE \
2938 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2939 DWARF2_ADDR_SIZE * 2) \
2940 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2942 /* Use assembler line directives if available. */
2943 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2944 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2945 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2947 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2951 /* Minimum line offset in a special line info. opcode.
2952 This value was chosen to give a reasonable range of values. */
2953 #define DWARF_LINE_BASE -10
2955 /* First special line opcode - leave room for the standard opcodes. */
2956 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2958 /* Range of line offsets in a special line info. opcode. */
2959 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2961 /* Flag that indicates the initial value of the is_stmt_start flag.
2962 In the present implementation, we do not mark any lines as
2963 the beginning of a source statement, because that information
2964 is not made available by the GCC front-end. */
2965 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2967 /* Maximum number of operations per instruction bundle. */
2968 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2969 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2972 /* This location is used by calc_die_sizes() to keep track
2973 the offset of each DIE within the .debug_info section. */
2974 static unsigned long next_die_offset
;
2976 /* Record the root of the DIE's built for the current compilation unit. */
2977 static GTY(()) dw_die_ref single_comp_unit_die
;
2979 /* A list of type DIEs that have been separated into comdat sections. */
2980 static GTY(()) comdat_type_node
*comdat_type_list
;
2982 /* A list of DIEs with a NULL parent waiting to be relocated. */
2983 static GTY(()) limbo_die_node
*limbo_die_list
;
2985 /* A list of DIEs for which we may have to generate
2986 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2987 static GTY(()) limbo_die_node
*deferred_asm_name
;
2989 /* Filenames referenced by this compilation unit. */
2990 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
2992 /* A hash table of references to DIE's that describe declarations.
2993 The key is a DECL_UID() which is a unique number identifying each decl. */
2994 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
2996 /* A hash table of references to DIE's that describe COMMON blocks.
2997 The key is DECL_UID() ^ die_parent. */
2998 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
3000 typedef struct GTY(()) die_arg_entry_struct
{
3005 DEF_VEC_O(die_arg_entry
);
3006 DEF_VEC_ALLOC_O(die_arg_entry
,gc
);
3008 /* Node of the variable location list. */
3009 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
3010 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
3011 EXPR_LIST chain. For small bitsizes, bitsize is encoded
3012 in mode of the EXPR_LIST node and first EXPR_LIST operand
3013 is either NOTE_INSN_VAR_LOCATION for a piece with a known
3014 location or NULL for padding. For larger bitsizes,
3015 mode is 0 and first operand is a CONCAT with bitsize
3016 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
3017 NULL as second operand. */
3019 const char * GTY (()) label
;
3020 struct var_loc_node
* GTY (()) next
;
3023 /* Variable location list. */
3024 struct GTY (()) var_loc_list_def
{
3025 struct var_loc_node
* GTY (()) first
;
3027 /* Pointer to the last but one or last element of the
3028 chained list. If the list is empty, both first and
3029 last are NULL, if the list contains just one node
3030 or the last node certainly is not redundant, it points
3031 to the last node, otherwise points to the last but one.
3032 Do not mark it for GC because it is marked through the chain. */
3033 struct var_loc_node
* GTY ((skip ("%h"))) last
;
3035 /* Pointer to the last element before section switch,
3036 if NULL, either sections weren't switched or first
3037 is after section switch. */
3038 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
3040 /* DECL_UID of the variable decl. */
3041 unsigned int decl_id
;
3043 typedef struct var_loc_list_def var_loc_list
;
3045 /* Call argument location list. */
3046 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
3047 rtx
GTY (()) call_arg_loc_note
;
3048 const char * GTY (()) label
;
3049 tree
GTY (()) block
;
3051 rtx
GTY (()) symbol_ref
;
3052 struct call_arg_loc_node
* GTY (()) next
;
3056 /* Table of decl location linked lists. */
3057 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
3059 /* Head and tail of call_arg_loc chain. */
3060 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
3061 static struct call_arg_loc_node
*call_arg_loc_last
;
3063 /* Number of call sites in the current function. */
3064 static int call_site_count
= -1;
3065 /* Number of tail call sites in the current function. */
3066 static int tail_call_site_count
= -1;
3068 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
3070 static VEC (dw_die_ref
, heap
) *block_map
;
3072 /* A cached location list. */
3073 struct GTY (()) cached_dw_loc_list_def
{
3074 /* The DECL_UID of the decl that this entry describes. */
3075 unsigned int decl_id
;
3077 /* The cached location list. */
3078 dw_loc_list_ref loc_list
;
3080 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
3082 /* Table of cached location lists. */
3083 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
3085 /* A pointer to the base of a list of references to DIE's that
3086 are uniquely identified by their tag, presence/absence of
3087 children DIE's, and list of attribute/value pairs. */
3088 static GTY((length ("abbrev_die_table_allocated")))
3089 dw_die_ref
*abbrev_die_table
;
3091 /* Number of elements currently allocated for abbrev_die_table. */
3092 static GTY(()) unsigned abbrev_die_table_allocated
;
3094 /* Number of elements in type_die_table currently in use. */
3095 static GTY(()) unsigned abbrev_die_table_in_use
;
3097 /* Size (in elements) of increments by which we may expand the
3098 abbrev_die_table. */
3099 #define ABBREV_DIE_TABLE_INCREMENT 256
3101 /* A global counter for generating labels for line number data. */
3102 static unsigned int line_info_label_num
;
3104 /* The current table to which we should emit line number information
3105 for the current function. This will be set up at the beginning of
3106 assembly for the function. */
3107 static dw_line_info_table
*cur_line_info_table
;
3109 /* The two default tables of line number info. */
3110 static GTY(()) dw_line_info_table
*text_section_line_info
;
3111 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
3113 /* The set of all non-default tables of line number info. */
3114 static GTY(()) VEC (dw_line_info_table_p
, gc
) *separate_line_info
;
3116 /* A flag to tell pubnames/types export if there is an info section to
3118 static bool info_section_emitted
;
3120 /* A pointer to the base of a table that contains a list of publicly
3121 accessible names. */
3122 static GTY (()) VEC (pubname_entry
, gc
) * pubname_table
;
3124 /* A pointer to the base of a table that contains a list of publicly
3125 accessible types. */
3126 static GTY (()) VEC (pubname_entry
, gc
) * pubtype_table
;
3128 /* A pointer to the base of a table that contains a list of macro
3129 defines/undefines (and file start/end markers). */
3130 static GTY (()) VEC (macinfo_entry
, gc
) * macinfo_table
;
3132 /* Array of dies for which we should generate .debug_ranges info. */
3133 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
3135 /* Number of elements currently allocated for ranges_table. */
3136 static GTY(()) unsigned ranges_table_allocated
;
3138 /* Number of elements in ranges_table currently in use. */
3139 static GTY(()) unsigned ranges_table_in_use
;
3141 /* Array of pairs of labels referenced in ranges_table. */
3142 static GTY ((length ("ranges_by_label_allocated")))
3143 dw_ranges_by_label_ref ranges_by_label
;
3145 /* Number of elements currently allocated for ranges_by_label. */
3146 static GTY(()) unsigned ranges_by_label_allocated
;
3148 /* Number of elements in ranges_by_label currently in use. */
3149 static GTY(()) unsigned ranges_by_label_in_use
;
3151 /* Size (in elements) of increments by which we may expand the
3153 #define RANGES_TABLE_INCREMENT 64
3155 /* Whether we have location lists that need outputting */
3156 static GTY(()) bool have_location_lists
;
3158 /* Unique label counter. */
3159 static GTY(()) unsigned int loclabel_num
;
3161 /* Unique label counter for point-of-call tables. */
3162 static GTY(()) unsigned int poc_label_num
;
3164 /* Record whether the function being analyzed contains inlined functions. */
3165 static int current_function_has_inlines
;
3167 /* The last file entry emitted by maybe_emit_file(). */
3168 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3170 /* Number of internal labels generated by gen_internal_sym(). */
3171 static GTY(()) int label_num
;
3173 /* Cached result of previous call to lookup_filename. */
3174 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
3176 static GTY(()) VEC(die_arg_entry
,gc
) *tmpl_value_parm_die_table
;
3178 /* Instances of generic types for which we need to generate debug
3179 info that describe their generic parameters and arguments. That
3180 generation needs to happen once all types are properly laid out so
3181 we do it at the end of compilation. */
3182 static GTY(()) VEC(tree
,gc
) *generic_type_instances
;
3184 /* Offset from the "steady-state frame pointer" to the frame base,
3185 within the current function. */
3186 static HOST_WIDE_INT frame_pointer_fb_offset
;
3187 static bool frame_pointer_fb_offset_valid
;
3189 static VEC (dw_die_ref
, heap
) *base_types
;
3191 /* Forward declarations for functions defined in this file. */
3193 static int is_pseudo_reg (const_rtx
);
3194 static tree
type_main_variant (tree
);
3195 static int is_tagged_type (const_tree
);
3196 static const char *dwarf_tag_name (unsigned);
3197 static const char *dwarf_attr_name (unsigned);
3198 static const char *dwarf_form_name (unsigned);
3199 static tree
decl_ultimate_origin (const_tree
);
3200 static tree
decl_class_context (tree
);
3201 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
3202 static inline enum dw_val_class
AT_class (dw_attr_ref
);
3203 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3204 static inline unsigned AT_flag (dw_attr_ref
);
3205 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3206 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
3207 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3208 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
3209 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3210 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3211 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3212 unsigned int, unsigned char *);
3213 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3214 static hashval_t
debug_str_do_hash (const void *);
3215 static int debug_str_eq (const void *, const void *);
3216 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3217 static inline const char *AT_string (dw_attr_ref
);
3218 static enum dwarf_form
AT_string_form (dw_attr_ref
);
3219 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3220 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3221 static inline dw_die_ref
AT_ref (dw_attr_ref
);
3222 static inline int AT_ref_external (dw_attr_ref
);
3223 static inline void set_AT_ref_external (dw_attr_ref
, int);
3224 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3225 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3226 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
3227 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3229 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
3230 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
3231 static inline rtx
AT_addr (dw_attr_ref
);
3232 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3233 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3234 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3235 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3236 unsigned HOST_WIDE_INT
);
3237 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3239 static inline const char *AT_lbl (dw_attr_ref
);
3240 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
3241 static const char *get_AT_low_pc (dw_die_ref
);
3242 static const char *get_AT_hi_pc (dw_die_ref
);
3243 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3244 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3245 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3246 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3247 static bool is_cxx (void);
3248 static bool is_fortran (void);
3249 static bool is_ada (void);
3250 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
3251 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3252 static void add_child_die (dw_die_ref
, dw_die_ref
);
3253 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3254 static dw_die_ref
lookup_type_die (tree
);
3255 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3256 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3257 static void equate_type_number_to_die (tree
, dw_die_ref
);
3258 static hashval_t
decl_die_table_hash (const void *);
3259 static int decl_die_table_eq (const void *, const void *);
3260 static dw_die_ref
lookup_decl_die (tree
);
3261 static hashval_t
common_block_die_table_hash (const void *);
3262 static int common_block_die_table_eq (const void *, const void *);
3263 static hashval_t
decl_loc_table_hash (const void *);
3264 static int decl_loc_table_eq (const void *, const void *);
3265 static var_loc_list
*lookup_decl_loc (const_tree
);
3266 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3267 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3268 static void print_spaces (FILE *);
3269 static void print_die (dw_die_ref
, FILE *);
3270 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3271 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3272 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3273 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3274 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3275 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3276 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3277 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3278 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
3279 struct md5_ctx
*, int *);
3280 struct checksum_attributes
;
3281 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3282 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3283 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3284 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3285 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3286 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3287 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3288 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3289 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3290 static void compute_section_prefix (dw_die_ref
);
3291 static int is_type_die (dw_die_ref
);
3292 static int is_comdat_die (dw_die_ref
);
3293 static int is_symbol_die (dw_die_ref
);
3294 static void assign_symbol_names (dw_die_ref
);
3295 static void break_out_includes (dw_die_ref
);
3296 static int is_declaration_die (dw_die_ref
);
3297 static int should_move_die_to_comdat (dw_die_ref
);
3298 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3299 static dw_die_ref
clone_die (dw_die_ref
);
3300 static dw_die_ref
clone_tree (dw_die_ref
);
3301 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3302 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3303 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3304 static dw_die_ref
generate_skeleton (dw_die_ref
);
3305 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3308 static void break_out_comdat_types (dw_die_ref
);
3309 static dw_die_ref
copy_ancestor_tree (dw_die_ref
, dw_die_ref
, htab_t
);
3310 static void copy_decls_walk (dw_die_ref
, dw_die_ref
, htab_t
);
3311 static void copy_decls_for_unworthy_types (dw_die_ref
);
3313 static hashval_t
htab_cu_hash (const void *);
3314 static int htab_cu_eq (const void *, const void *);
3315 static void htab_cu_del (void *);
3316 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
3317 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
3318 static void add_sibling_attributes (dw_die_ref
);
3319 static void build_abbrev_table (dw_die_ref
);
3320 static void output_location_lists (dw_die_ref
);
3321 static int constant_size (unsigned HOST_WIDE_INT
);
3322 static unsigned long size_of_die (dw_die_ref
);
3323 static void calc_die_sizes (dw_die_ref
);
3324 static void calc_base_type_die_sizes (void);
3325 static void mark_dies (dw_die_ref
);
3326 static void unmark_dies (dw_die_ref
);
3327 static void unmark_all_dies (dw_die_ref
);
3328 static unsigned long size_of_pubnames (VEC (pubname_entry
,gc
) *);
3329 static unsigned long size_of_aranges (void);
3330 static enum dwarf_form
value_format (dw_attr_ref
);
3331 static void output_value_format (dw_attr_ref
);
3332 static void output_abbrev_section (void);
3333 static void output_die_symbol (dw_die_ref
);
3334 static void output_die (dw_die_ref
);
3335 static void output_compilation_unit_header (void);
3336 static void output_comp_unit (dw_die_ref
, int);
3337 static void output_comdat_type_unit (comdat_type_node
*);
3338 static const char *dwarf2_name (tree
, int);
3339 static void add_pubname (tree
, dw_die_ref
);
3340 static void add_pubname_string (const char *, dw_die_ref
);
3341 static void add_pubtype (tree
, dw_die_ref
);
3342 static void output_pubnames (VEC (pubname_entry
,gc
) *);
3343 static void output_aranges (unsigned long);
3344 static unsigned int add_ranges_num (int);
3345 static unsigned int add_ranges (const_tree
);
3346 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3348 static void output_ranges (void);
3349 static dw_line_info_table
*new_line_info_table (void);
3350 static void output_line_info (void);
3351 static void output_file_names (void);
3352 static dw_die_ref
base_type_die (tree
);
3353 static int is_base_type (tree
);
3354 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3355 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3356 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3357 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3358 static int type_is_enum (const_tree
);
3359 static unsigned int dbx_reg_number (const_rtx
);
3360 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3361 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3362 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3363 enum var_init_status
);
3364 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3365 enum var_init_status
);
3366 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3367 enum var_init_status
);
3368 static int is_based_loc (const_rtx
);
3369 static int resolve_one_addr (rtx
*, void *);
3370 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3371 enum var_init_status
);
3372 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
3373 enum var_init_status
);
3374 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3375 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3376 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3377 static tree
field_type (const_tree
);
3378 static unsigned int simple_type_align_in_bits (const_tree
);
3379 static unsigned int simple_decl_align_in_bits (const_tree
);
3380 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3381 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3382 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3384 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3385 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3386 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3387 static void insert_double (double_int
, unsigned char *);
3388 static void insert_float (const_rtx
, unsigned char *);
3389 static rtx
rtl_for_decl_location (tree
);
3390 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3391 enum dwarf_attribute
);
3392 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3393 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3394 static void add_name_attribute (dw_die_ref
, const char *);
3395 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3396 static void add_comp_dir_attribute (dw_die_ref
);
3397 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3398 static void add_subscript_info (dw_die_ref
, tree
, bool);
3399 static void add_byte_size_attribute (dw_die_ref
, tree
);
3400 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3401 static void add_bit_size_attribute (dw_die_ref
, tree
);
3402 static void add_prototyped_attribute (dw_die_ref
, tree
);
3403 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3404 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3405 static void add_src_coords_attributes (dw_die_ref
, tree
);
3406 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3407 static void push_decl_scope (tree
);
3408 static void pop_decl_scope (void);
3409 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3410 static inline int local_scope_p (dw_die_ref
);
3411 static inline int class_scope_p (dw_die_ref
);
3412 static inline int class_or_namespace_scope_p (dw_die_ref
);
3413 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3414 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3415 static const char *type_tag (const_tree
);
3416 static tree
member_declared_type (const_tree
);
3418 static const char *decl_start_label (tree
);
3420 static void gen_array_type_die (tree
, dw_die_ref
);
3421 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3423 static void gen_entry_point_die (tree
, dw_die_ref
);
3425 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3426 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3427 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3428 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3429 static void gen_formal_types_die (tree
, dw_die_ref
);
3430 static void gen_subprogram_die (tree
, dw_die_ref
);
3431 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3432 static void gen_const_die (tree
, dw_die_ref
);
3433 static void gen_label_die (tree
, dw_die_ref
);
3434 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3435 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3436 static void gen_field_die (tree
, dw_die_ref
);
3437 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3438 static dw_die_ref
gen_compile_unit_die (const char *);
3439 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3440 static void gen_member_die (tree
, dw_die_ref
);
3441 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3442 enum debug_info_usage
);
3443 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3444 static void gen_typedef_die (tree
, dw_die_ref
);
3445 static void gen_type_die (tree
, dw_die_ref
);
3446 static void gen_block_die (tree
, dw_die_ref
, int);
3447 static void decls_for_scope (tree
, dw_die_ref
, int);
3448 static inline int is_redundant_typedef (const_tree
);
3449 static bool is_naming_typedef_decl (const_tree
);
3450 static inline dw_die_ref
get_context_die (tree
);
3451 static void gen_namespace_die (tree
, dw_die_ref
);
3452 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3453 static dw_die_ref
force_decl_die (tree
);
3454 static dw_die_ref
force_type_die (tree
);
3455 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3456 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3457 static struct dwarf_file_data
* lookup_filename (const char *);
3458 static void retry_incomplete_types (void);
3459 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3460 static void gen_generic_params_dies (tree
);
3461 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3462 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3463 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3464 static int file_info_cmp (const void *, const void *);
3465 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3466 const char *, const char *);
3467 static void output_loc_list (dw_loc_list_ref
);
3468 static char *gen_internal_sym (const char *);
3470 static void prune_unmark_dies (dw_die_ref
);
3471 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3472 static void prune_unused_types_mark (dw_die_ref
, int);
3473 static void prune_unused_types_walk (dw_die_ref
);
3474 static void prune_unused_types_walk_attribs (dw_die_ref
);
3475 static void prune_unused_types_prune (dw_die_ref
);
3476 static void prune_unused_types (void);
3477 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3478 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3479 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3480 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3481 const char *, const char *);
3482 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3483 static void gen_remaining_tmpl_value_param_die_attribute (void);
3484 static bool generic_type_p (tree
);
3485 static void schedule_generic_params_dies_gen (tree t
);
3486 static void gen_scheduled_generic_parms_dies (void);
3488 /* Section names used to hold DWARF debugging information. */
3489 #ifndef DEBUG_INFO_SECTION
3490 #define DEBUG_INFO_SECTION ".debug_info"
3492 #ifndef DEBUG_ABBREV_SECTION
3493 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3495 #ifndef DEBUG_ARANGES_SECTION
3496 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3498 #ifndef DEBUG_MACINFO_SECTION
3499 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3501 #ifndef DEBUG_MACRO_SECTION
3502 #define DEBUG_MACRO_SECTION ".debug_macro"
3504 #ifndef DEBUG_LINE_SECTION
3505 #define DEBUG_LINE_SECTION ".debug_line"
3507 #ifndef DEBUG_LOC_SECTION
3508 #define DEBUG_LOC_SECTION ".debug_loc"
3510 #ifndef DEBUG_PUBNAMES_SECTION
3511 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3513 #ifndef DEBUG_PUBTYPES_SECTION
3514 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
3516 #ifndef DEBUG_STR_SECTION
3517 #define DEBUG_STR_SECTION ".debug_str"
3519 #ifndef DEBUG_RANGES_SECTION
3520 #define DEBUG_RANGES_SECTION ".debug_ranges"
3523 /* Standard ELF section names for compiled code and data. */
3524 #ifndef TEXT_SECTION_NAME
3525 #define TEXT_SECTION_NAME ".text"
3528 /* Section flags for .debug_str section. */
3529 #define DEBUG_STR_SECTION_FLAGS \
3530 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3531 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3534 /* Labels we insert at beginning sections we can reference instead of
3535 the section names themselves. */
3537 #ifndef TEXT_SECTION_LABEL
3538 #define TEXT_SECTION_LABEL "Ltext"
3540 #ifndef COLD_TEXT_SECTION_LABEL
3541 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3543 #ifndef DEBUG_LINE_SECTION_LABEL
3544 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3546 #ifndef DEBUG_INFO_SECTION_LABEL
3547 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3549 #ifndef DEBUG_ABBREV_SECTION_LABEL
3550 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3552 #ifndef DEBUG_LOC_SECTION_LABEL
3553 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3555 #ifndef DEBUG_RANGES_SECTION_LABEL
3556 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3558 #ifndef DEBUG_MACINFO_SECTION_LABEL
3559 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3561 #ifndef DEBUG_MACRO_SECTION_LABEL
3562 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3566 /* Definitions of defaults for formats and names of various special
3567 (artificial) labels which may be generated within this file (when the -g
3568 options is used and DWARF2_DEBUGGING_INFO is in effect.
3569 If necessary, these may be overridden from within the tm.h file, but
3570 typically, overriding these defaults is unnecessary. */
3572 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3573 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3574 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3575 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3576 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3577 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3578 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3579 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3580 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3581 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3583 #ifndef TEXT_END_LABEL
3584 #define TEXT_END_LABEL "Letext"
3586 #ifndef COLD_END_LABEL
3587 #define COLD_END_LABEL "Letext_cold"
3589 #ifndef BLOCK_BEGIN_LABEL
3590 #define BLOCK_BEGIN_LABEL "LBB"
3592 #ifndef BLOCK_END_LABEL
3593 #define BLOCK_END_LABEL "LBE"
3595 #ifndef LINE_CODE_LABEL
3596 #define LINE_CODE_LABEL "LM"
3600 /* Return the root of the DIE's built for the current compilation unit. */
3602 comp_unit_die (void)
3604 if (!single_comp_unit_die
)
3605 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3606 return single_comp_unit_die
;
3609 /* We allow a language front-end to designate a function that is to be
3610 called to "demangle" any name before it is put into a DIE. */
3612 static const char *(*demangle_name_func
) (const char *);
3615 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3617 demangle_name_func
= func
;
3620 /* Test if rtl node points to a pseudo register. */
3623 is_pseudo_reg (const_rtx rtl
)
3625 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3626 || (GET_CODE (rtl
) == SUBREG
3627 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3630 /* Return a reference to a type, with its const and volatile qualifiers
3634 type_main_variant (tree type
)
3636 type
= TYPE_MAIN_VARIANT (type
);
3638 /* ??? There really should be only one main variant among any group of
3639 variants of a given type (and all of the MAIN_VARIANT values for all
3640 members of the group should point to that one type) but sometimes the C
3641 front-end messes this up for array types, so we work around that bug
3643 if (TREE_CODE (type
) == ARRAY_TYPE
)
3644 while (type
!= TYPE_MAIN_VARIANT (type
))
3645 type
= TYPE_MAIN_VARIANT (type
);
3650 /* Return nonzero if the given type node represents a tagged type. */
3653 is_tagged_type (const_tree type
)
3655 enum tree_code code
= TREE_CODE (type
);
3657 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3658 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3661 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3664 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3666 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3669 /* Return die_offset of a DIE reference to a base type. */
3671 static unsigned long int
3672 get_base_type_offset (dw_die_ref ref
)
3674 if (ref
->die_offset
)
3675 return ref
->die_offset
;
3676 if (comp_unit_die ()->die_abbrev
)
3678 calc_base_type_die_sizes ();
3679 gcc_assert (ref
->die_offset
);
3681 return ref
->die_offset
;
3684 /* Return die_offset of a DIE reference other than base type. */
3686 static unsigned long int
3687 get_ref_die_offset (dw_die_ref ref
)
3689 gcc_assert (ref
->die_offset
);
3690 return ref
->die_offset
;
3693 /* Convert a DIE tag into its string name. */
3696 dwarf_tag_name (unsigned int tag
)
3700 case DW_TAG_padding
:
3701 return "DW_TAG_padding";
3702 case DW_TAG_array_type
:
3703 return "DW_TAG_array_type";
3704 case DW_TAG_class_type
:
3705 return "DW_TAG_class_type";
3706 case DW_TAG_entry_point
:
3707 return "DW_TAG_entry_point";
3708 case DW_TAG_enumeration_type
:
3709 return "DW_TAG_enumeration_type";
3710 case DW_TAG_formal_parameter
:
3711 return "DW_TAG_formal_parameter";
3712 case DW_TAG_imported_declaration
:
3713 return "DW_TAG_imported_declaration";
3715 return "DW_TAG_label";
3716 case DW_TAG_lexical_block
:
3717 return "DW_TAG_lexical_block";
3719 return "DW_TAG_member";
3720 case DW_TAG_pointer_type
:
3721 return "DW_TAG_pointer_type";
3722 case DW_TAG_reference_type
:
3723 return "DW_TAG_reference_type";
3724 case DW_TAG_compile_unit
:
3725 return "DW_TAG_compile_unit";
3726 case DW_TAG_string_type
:
3727 return "DW_TAG_string_type";
3728 case DW_TAG_structure_type
:
3729 return "DW_TAG_structure_type";
3730 case DW_TAG_subroutine_type
:
3731 return "DW_TAG_subroutine_type";
3732 case DW_TAG_typedef
:
3733 return "DW_TAG_typedef";
3734 case DW_TAG_union_type
:
3735 return "DW_TAG_union_type";
3736 case DW_TAG_unspecified_parameters
:
3737 return "DW_TAG_unspecified_parameters";
3738 case DW_TAG_variant
:
3739 return "DW_TAG_variant";
3740 case DW_TAG_common_block
:
3741 return "DW_TAG_common_block";
3742 case DW_TAG_common_inclusion
:
3743 return "DW_TAG_common_inclusion";
3744 case DW_TAG_inheritance
:
3745 return "DW_TAG_inheritance";
3746 case DW_TAG_inlined_subroutine
:
3747 return "DW_TAG_inlined_subroutine";
3749 return "DW_TAG_module";
3750 case DW_TAG_ptr_to_member_type
:
3751 return "DW_TAG_ptr_to_member_type";
3752 case DW_TAG_set_type
:
3753 return "DW_TAG_set_type";
3754 case DW_TAG_subrange_type
:
3755 return "DW_TAG_subrange_type";
3756 case DW_TAG_with_stmt
:
3757 return "DW_TAG_with_stmt";
3758 case DW_TAG_access_declaration
:
3759 return "DW_TAG_access_declaration";
3760 case DW_TAG_base_type
:
3761 return "DW_TAG_base_type";
3762 case DW_TAG_catch_block
:
3763 return "DW_TAG_catch_block";
3764 case DW_TAG_const_type
:
3765 return "DW_TAG_const_type";
3766 case DW_TAG_constant
:
3767 return "DW_TAG_constant";
3768 case DW_TAG_enumerator
:
3769 return "DW_TAG_enumerator";
3770 case DW_TAG_file_type
:
3771 return "DW_TAG_file_type";
3773 return "DW_TAG_friend";
3774 case DW_TAG_namelist
:
3775 return "DW_TAG_namelist";
3776 case DW_TAG_namelist_item
:
3777 return "DW_TAG_namelist_item";
3778 case DW_TAG_packed_type
:
3779 return "DW_TAG_packed_type";
3780 case DW_TAG_subprogram
:
3781 return "DW_TAG_subprogram";
3782 case DW_TAG_template_type_param
:
3783 return "DW_TAG_template_type_param";
3784 case DW_TAG_template_value_param
:
3785 return "DW_TAG_template_value_param";
3786 case DW_TAG_thrown_type
:
3787 return "DW_TAG_thrown_type";
3788 case DW_TAG_try_block
:
3789 return "DW_TAG_try_block";
3790 case DW_TAG_variant_part
:
3791 return "DW_TAG_variant_part";
3792 case DW_TAG_variable
:
3793 return "DW_TAG_variable";
3794 case DW_TAG_volatile_type
:
3795 return "DW_TAG_volatile_type";
3796 case DW_TAG_dwarf_procedure
:
3797 return "DW_TAG_dwarf_procedure";
3798 case DW_TAG_restrict_type
:
3799 return "DW_TAG_restrict_type";
3800 case DW_TAG_interface_type
:
3801 return "DW_TAG_interface_type";
3802 case DW_TAG_namespace
:
3803 return "DW_TAG_namespace";
3804 case DW_TAG_imported_module
:
3805 return "DW_TAG_imported_module";
3806 case DW_TAG_unspecified_type
:
3807 return "DW_TAG_unspecified_type";
3808 case DW_TAG_partial_unit
:
3809 return "DW_TAG_partial_unit";
3810 case DW_TAG_imported_unit
:
3811 return "DW_TAG_imported_unit";
3812 case DW_TAG_condition
:
3813 return "DW_TAG_condition";
3814 case DW_TAG_shared_type
:
3815 return "DW_TAG_shared_type";
3816 case DW_TAG_type_unit
:
3817 return "DW_TAG_type_unit";
3818 case DW_TAG_rvalue_reference_type
:
3819 return "DW_TAG_rvalue_reference_type";
3820 case DW_TAG_template_alias
:
3821 return "DW_TAG_template_alias";
3822 case DW_TAG_GNU_template_parameter_pack
:
3823 return "DW_TAG_GNU_template_parameter_pack";
3824 case DW_TAG_GNU_formal_parameter_pack
:
3825 return "DW_TAG_GNU_formal_parameter_pack";
3826 case DW_TAG_MIPS_loop
:
3827 return "DW_TAG_MIPS_loop";
3828 case DW_TAG_format_label
:
3829 return "DW_TAG_format_label";
3830 case DW_TAG_function_template
:
3831 return "DW_TAG_function_template";
3832 case DW_TAG_class_template
:
3833 return "DW_TAG_class_template";
3834 case DW_TAG_GNU_BINCL
:
3835 return "DW_TAG_GNU_BINCL";
3836 case DW_TAG_GNU_EINCL
:
3837 return "DW_TAG_GNU_EINCL";
3838 case DW_TAG_GNU_template_template_param
:
3839 return "DW_TAG_GNU_template_template_param";
3840 case DW_TAG_GNU_call_site
:
3841 return "DW_TAG_GNU_call_site";
3842 case DW_TAG_GNU_call_site_parameter
:
3843 return "DW_TAG_GNU_call_site_parameter";
3845 return "DW_TAG_<unknown>";
3849 /* Convert a DWARF attribute code into its string name. */
3852 dwarf_attr_name (unsigned int attr
)
3857 return "DW_AT_sibling";
3858 case DW_AT_location
:
3859 return "DW_AT_location";
3861 return "DW_AT_name";
3862 case DW_AT_ordering
:
3863 return "DW_AT_ordering";
3864 case DW_AT_subscr_data
:
3865 return "DW_AT_subscr_data";
3866 case DW_AT_byte_size
:
3867 return "DW_AT_byte_size";
3868 case DW_AT_bit_offset
:
3869 return "DW_AT_bit_offset";
3870 case DW_AT_bit_size
:
3871 return "DW_AT_bit_size";
3872 case DW_AT_element_list
:
3873 return "DW_AT_element_list";
3874 case DW_AT_stmt_list
:
3875 return "DW_AT_stmt_list";
3877 return "DW_AT_low_pc";
3879 return "DW_AT_high_pc";
3880 case DW_AT_language
:
3881 return "DW_AT_language";
3883 return "DW_AT_member";
3885 return "DW_AT_discr";
3886 case DW_AT_discr_value
:
3887 return "DW_AT_discr_value";
3888 case DW_AT_visibility
:
3889 return "DW_AT_visibility";
3891 return "DW_AT_import";
3892 case DW_AT_string_length
:
3893 return "DW_AT_string_length";
3894 case DW_AT_common_reference
:
3895 return "DW_AT_common_reference";
3896 case DW_AT_comp_dir
:
3897 return "DW_AT_comp_dir";
3898 case DW_AT_const_value
:
3899 return "DW_AT_const_value";
3900 case DW_AT_containing_type
:
3901 return "DW_AT_containing_type";
3902 case DW_AT_default_value
:
3903 return "DW_AT_default_value";
3905 return "DW_AT_inline";
3906 case DW_AT_is_optional
:
3907 return "DW_AT_is_optional";
3908 case DW_AT_lower_bound
:
3909 return "DW_AT_lower_bound";
3910 case DW_AT_producer
:
3911 return "DW_AT_producer";
3912 case DW_AT_prototyped
:
3913 return "DW_AT_prototyped";
3914 case DW_AT_return_addr
:
3915 return "DW_AT_return_addr";
3916 case DW_AT_start_scope
:
3917 return "DW_AT_start_scope";
3918 case DW_AT_bit_stride
:
3919 return "DW_AT_bit_stride";
3920 case DW_AT_upper_bound
:
3921 return "DW_AT_upper_bound";
3922 case DW_AT_abstract_origin
:
3923 return "DW_AT_abstract_origin";
3924 case DW_AT_accessibility
:
3925 return "DW_AT_accessibility";
3926 case DW_AT_address_class
:
3927 return "DW_AT_address_class";
3928 case DW_AT_artificial
:
3929 return "DW_AT_artificial";
3930 case DW_AT_base_types
:
3931 return "DW_AT_base_types";
3932 case DW_AT_calling_convention
:
3933 return "DW_AT_calling_convention";
3935 return "DW_AT_count";
3936 case DW_AT_data_member_location
:
3937 return "DW_AT_data_member_location";
3938 case DW_AT_decl_column
:
3939 return "DW_AT_decl_column";
3940 case DW_AT_decl_file
:
3941 return "DW_AT_decl_file";
3942 case DW_AT_decl_line
:
3943 return "DW_AT_decl_line";
3944 case DW_AT_declaration
:
3945 return "DW_AT_declaration";
3946 case DW_AT_discr_list
:
3947 return "DW_AT_discr_list";
3948 case DW_AT_encoding
:
3949 return "DW_AT_encoding";
3950 case DW_AT_external
:
3951 return "DW_AT_external";
3952 case DW_AT_explicit
:
3953 return "DW_AT_explicit";
3954 case DW_AT_frame_base
:
3955 return "DW_AT_frame_base";
3957 return "DW_AT_friend";
3958 case DW_AT_identifier_case
:
3959 return "DW_AT_identifier_case";
3960 case DW_AT_macro_info
:
3961 return "DW_AT_macro_info";
3962 case DW_AT_namelist_items
:
3963 return "DW_AT_namelist_items";
3964 case DW_AT_priority
:
3965 return "DW_AT_priority";
3967 return "DW_AT_segment";
3968 case DW_AT_specification
:
3969 return "DW_AT_specification";
3970 case DW_AT_static_link
:
3971 return "DW_AT_static_link";
3973 return "DW_AT_type";
3974 case DW_AT_use_location
:
3975 return "DW_AT_use_location";
3976 case DW_AT_variable_parameter
:
3977 return "DW_AT_variable_parameter";
3978 case DW_AT_virtuality
:
3979 return "DW_AT_virtuality";
3980 case DW_AT_vtable_elem_location
:
3981 return "DW_AT_vtable_elem_location";
3983 case DW_AT_allocated
:
3984 return "DW_AT_allocated";
3985 case DW_AT_associated
:
3986 return "DW_AT_associated";
3987 case DW_AT_data_location
:
3988 return "DW_AT_data_location";
3989 case DW_AT_byte_stride
:
3990 return "DW_AT_byte_stride";
3991 case DW_AT_entry_pc
:
3992 return "DW_AT_entry_pc";
3993 case DW_AT_use_UTF8
:
3994 return "DW_AT_use_UTF8";
3995 case DW_AT_extension
:
3996 return "DW_AT_extension";
3998 return "DW_AT_ranges";
3999 case DW_AT_trampoline
:
4000 return "DW_AT_trampoline";
4001 case DW_AT_call_column
:
4002 return "DW_AT_call_column";
4003 case DW_AT_call_file
:
4004 return "DW_AT_call_file";
4005 case DW_AT_call_line
:
4006 return "DW_AT_call_line";
4007 case DW_AT_object_pointer
:
4008 return "DW_AT_object_pointer";
4010 case DW_AT_signature
:
4011 return "DW_AT_signature";
4012 case DW_AT_main_subprogram
:
4013 return "DW_AT_main_subprogram";
4014 case DW_AT_data_bit_offset
:
4015 return "DW_AT_data_bit_offset";
4016 case DW_AT_const_expr
:
4017 return "DW_AT_const_expr";
4018 case DW_AT_enum_class
:
4019 return "DW_AT_enum_class";
4020 case DW_AT_linkage_name
:
4021 return "DW_AT_linkage_name";
4023 case DW_AT_MIPS_fde
:
4024 return "DW_AT_MIPS_fde";
4025 case DW_AT_MIPS_loop_begin
:
4026 return "DW_AT_MIPS_loop_begin";
4027 case DW_AT_MIPS_tail_loop_begin
:
4028 return "DW_AT_MIPS_tail_loop_begin";
4029 case DW_AT_MIPS_epilog_begin
:
4030 return "DW_AT_MIPS_epilog_begin";
4031 #if VMS_DEBUGGING_INFO
4032 case DW_AT_HP_prologue
:
4033 return "DW_AT_HP_prologue";
4035 case DW_AT_MIPS_loop_unroll_factor
:
4036 return "DW_AT_MIPS_loop_unroll_factor";
4038 case DW_AT_MIPS_software_pipeline_depth
:
4039 return "DW_AT_MIPS_software_pipeline_depth";
4040 case DW_AT_MIPS_linkage_name
:
4041 return "DW_AT_MIPS_linkage_name";
4042 #if VMS_DEBUGGING_INFO
4043 case DW_AT_HP_epilogue
:
4044 return "DW_AT_HP_epilogue";
4046 case DW_AT_MIPS_stride
:
4047 return "DW_AT_MIPS_stride";
4049 case DW_AT_MIPS_abstract_name
:
4050 return "DW_AT_MIPS_abstract_name";
4051 case DW_AT_MIPS_clone_origin
:
4052 return "DW_AT_MIPS_clone_origin";
4053 case DW_AT_MIPS_has_inlines
:
4054 return "DW_AT_MIPS_has_inlines";
4056 case DW_AT_sf_names
:
4057 return "DW_AT_sf_names";
4058 case DW_AT_src_info
:
4059 return "DW_AT_src_info";
4060 case DW_AT_mac_info
:
4061 return "DW_AT_mac_info";
4062 case DW_AT_src_coords
:
4063 return "DW_AT_src_coords";
4064 case DW_AT_body_begin
:
4065 return "DW_AT_body_begin";
4066 case DW_AT_body_end
:
4067 return "DW_AT_body_end";
4069 case DW_AT_GNU_vector
:
4070 return "DW_AT_GNU_vector";
4071 case DW_AT_GNU_guarded_by
:
4072 return "DW_AT_GNU_guarded_by";
4073 case DW_AT_GNU_pt_guarded_by
:
4074 return "DW_AT_GNU_pt_guarded_by";
4075 case DW_AT_GNU_guarded
:
4076 return "DW_AT_GNU_guarded";
4077 case DW_AT_GNU_pt_guarded
:
4078 return "DW_AT_GNU_pt_guarded";
4079 case DW_AT_GNU_locks_excluded
:
4080 return "DW_AT_GNU_locks_excluded";
4081 case DW_AT_GNU_exclusive_locks_required
:
4082 return "DW_AT_GNU_exclusive_locks_required";
4083 case DW_AT_GNU_shared_locks_required
:
4084 return "DW_AT_GNU_shared_locks_required";
4085 case DW_AT_GNU_odr_signature
:
4086 return "DW_AT_GNU_odr_signature";
4087 case DW_AT_GNU_template_name
:
4088 return "DW_AT_GNU_template_name";
4089 case DW_AT_GNU_call_site_value
:
4090 return "DW_AT_GNU_call_site_value";
4091 case DW_AT_GNU_call_site_data_value
:
4092 return "DW_AT_GNU_call_site_data_value";
4093 case DW_AT_GNU_call_site_target
:
4094 return "DW_AT_GNU_call_site_target";
4095 case DW_AT_GNU_call_site_target_clobbered
:
4096 return "DW_AT_GNU_call_site_target_clobbered";
4097 case DW_AT_GNU_tail_call
:
4098 return "DW_AT_GNU_tail_call";
4099 case DW_AT_GNU_all_tail_call_sites
:
4100 return "DW_AT_GNU_all_tail_call_sites";
4101 case DW_AT_GNU_all_call_sites
:
4102 return "DW_AT_GNU_all_call_sites";
4103 case DW_AT_GNU_all_source_call_sites
:
4104 return "DW_AT_GNU_all_source_call_sites";
4105 case DW_AT_GNU_macros
:
4106 return "DW_AT_GNU_macros";
4108 case DW_AT_GNAT_descriptive_type
:
4109 return "DW_AT_GNAT_descriptive_type";
4111 case DW_AT_VMS_rtnbeg_pd_address
:
4112 return "DW_AT_VMS_rtnbeg_pd_address";
4115 return "DW_AT_<unknown>";
4119 /* Convert a DWARF value form code into its string name. */
4122 dwarf_form_name (unsigned int form
)
4127 return "DW_FORM_addr";
4128 case DW_FORM_block2
:
4129 return "DW_FORM_block2";
4130 case DW_FORM_block4
:
4131 return "DW_FORM_block4";
4133 return "DW_FORM_data2";
4135 return "DW_FORM_data4";
4137 return "DW_FORM_data8";
4138 case DW_FORM_string
:
4139 return "DW_FORM_string";
4141 return "DW_FORM_block";
4142 case DW_FORM_block1
:
4143 return "DW_FORM_block1";
4145 return "DW_FORM_data1";
4147 return "DW_FORM_flag";
4149 return "DW_FORM_sdata";
4151 return "DW_FORM_strp";
4153 return "DW_FORM_udata";
4154 case DW_FORM_ref_addr
:
4155 return "DW_FORM_ref_addr";
4157 return "DW_FORM_ref1";
4159 return "DW_FORM_ref2";
4161 return "DW_FORM_ref4";
4163 return "DW_FORM_ref8";
4164 case DW_FORM_ref_udata
:
4165 return "DW_FORM_ref_udata";
4166 case DW_FORM_indirect
:
4167 return "DW_FORM_indirect";
4168 case DW_FORM_sec_offset
:
4169 return "DW_FORM_sec_offset";
4170 case DW_FORM_exprloc
:
4171 return "DW_FORM_exprloc";
4172 case DW_FORM_flag_present
:
4173 return "DW_FORM_flag_present";
4174 case DW_FORM_ref_sig8
:
4175 return "DW_FORM_ref_sig8";
4177 return "DW_FORM_<unknown>";
4181 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4182 instance of an inlined instance of a decl which is local to an inline
4183 function, so we have to trace all of the way back through the origin chain
4184 to find out what sort of node actually served as the original seed for the
4188 decl_ultimate_origin (const_tree decl
)
4190 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
4193 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4194 nodes in the function to point to themselves; ignore that if
4195 we're trying to output the abstract instance of this function. */
4196 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4199 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4200 most distant ancestor, this should never happen. */
4201 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
4203 return DECL_ABSTRACT_ORIGIN (decl
);
4206 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4207 of a virtual function may refer to a base class, so we check the 'this'
4211 decl_class_context (tree decl
)
4213 tree context
= NULL_TREE
;
4215 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4216 context
= DECL_CONTEXT (decl
);
4218 context
= TYPE_MAIN_VARIANT
4219 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4221 if (context
&& !TYPE_P (context
))
4222 context
= NULL_TREE
;
4227 /* Add an attribute/value pair to a DIE. */
4230 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
4232 /* Maybe this should be an assert? */
4236 if (die
->die_attr
== NULL
)
4237 die
->die_attr
= VEC_alloc (dw_attr_node
, gc
, 1);
4238 VEC_safe_push (dw_attr_node
, gc
, die
->die_attr
, attr
);
4241 static inline enum dw_val_class
4242 AT_class (dw_attr_ref a
)
4244 return a
->dw_attr_val
.val_class
;
4247 /* Add a flag value attribute to a DIE. */
4250 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
4254 attr
.dw_attr
= attr_kind
;
4255 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
4256 attr
.dw_attr_val
.v
.val_flag
= flag
;
4257 add_dwarf_attr (die
, &attr
);
4260 static inline unsigned
4261 AT_flag (dw_attr_ref a
)
4263 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
4264 return a
->dw_attr_val
.v
.val_flag
;
4267 /* Add a signed integer attribute value to a DIE. */
4270 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
4274 attr
.dw_attr
= attr_kind
;
4275 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
4276 attr
.dw_attr_val
.v
.val_int
= int_val
;
4277 add_dwarf_attr (die
, &attr
);
4280 static inline HOST_WIDE_INT
4281 AT_int (dw_attr_ref a
)
4283 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
4284 return a
->dw_attr_val
.v
.val_int
;
4287 /* Add an unsigned integer attribute value to a DIE. */
4290 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4291 unsigned HOST_WIDE_INT unsigned_val
)
4295 attr
.dw_attr
= attr_kind
;
4296 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4297 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4298 add_dwarf_attr (die
, &attr
);
4301 static inline unsigned HOST_WIDE_INT
4302 AT_unsigned (dw_attr_ref a
)
4304 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
4305 return a
->dw_attr_val
.v
.val_unsigned
;
4308 /* Add an unsigned double integer attribute value to a DIE. */
4311 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4312 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
4316 attr
.dw_attr
= attr_kind
;
4317 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
4318 attr
.dw_attr_val
.v
.val_double
.high
= high
;
4319 attr
.dw_attr_val
.v
.val_double
.low
= low
;
4320 add_dwarf_attr (die
, &attr
);
4323 /* Add a floating point attribute value to a DIE and return it. */
4326 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4327 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
4331 attr
.dw_attr
= attr_kind
;
4332 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
4333 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
4334 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4335 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
4336 add_dwarf_attr (die
, &attr
);
4339 /* Add an 8-byte data attribute value to a DIE. */
4342 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4343 unsigned char data8
[8])
4347 attr
.dw_attr
= attr_kind
;
4348 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
4349 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
4350 add_dwarf_attr (die
, &attr
);
4353 /* Hash and equality functions for debug_str_hash. */
4356 debug_str_do_hash (const void *x
)
4358 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
4362 debug_str_eq (const void *x1
, const void *x2
)
4364 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
4365 (const char *)x2
) == 0;
4368 /* Add STR to the indirect string hash table. */
4370 static struct indirect_string_node
*
4371 find_AT_string (const char *str
)
4373 struct indirect_string_node
*node
;
4376 if (! debug_str_hash
)
4377 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
4378 debug_str_eq
, NULL
);
4380 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
4381 htab_hash_string (str
), INSERT
);
4384 node
= ggc_alloc_cleared_indirect_string_node ();
4385 node
->str
= ggc_strdup (str
);
4389 node
= (struct indirect_string_node
*) *slot
;
4395 /* Add a string attribute value to a DIE. */
4398 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4401 struct indirect_string_node
*node
;
4403 node
= find_AT_string (str
);
4405 attr
.dw_attr
= attr_kind
;
4406 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4407 attr
.dw_attr_val
.v
.val_str
= node
;
4408 add_dwarf_attr (die
, &attr
);
4411 static inline const char *
4412 AT_string (dw_attr_ref a
)
4414 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4415 return a
->dw_attr_val
.v
.val_str
->str
;
4418 /* Find out whether a string should be output inline in DIE
4419 or out-of-line in .debug_str section. */
4421 static enum dwarf_form
4422 AT_string_form (dw_attr_ref a
)
4424 struct indirect_string_node
*node
;
4428 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4430 node
= a
->dw_attr_val
.v
.val_str
;
4434 len
= strlen (node
->str
) + 1;
4436 /* If the string is shorter or equal to the size of the reference, it is
4437 always better to put it inline. */
4438 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4439 return node
->form
= DW_FORM_string
;
4441 /* If we cannot expect the linker to merge strings in .debug_str
4442 section, only put it into .debug_str if it is worth even in this
4444 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4445 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4446 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4447 return node
->form
= DW_FORM_string
;
4449 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4450 ++dw2_string_counter
;
4451 node
->label
= xstrdup (label
);
4453 return node
->form
= DW_FORM_strp
;
4456 /* Add a DIE reference attribute value to a DIE. */
4459 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4463 #ifdef ENABLE_CHECKING
4464 gcc_assert (targ_die
!= NULL
);
4466 /* With LTO we can end up trying to reference something we didn't create
4467 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4468 if (targ_die
== NULL
)
4472 attr
.dw_attr
= attr_kind
;
4473 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4474 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4475 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4476 add_dwarf_attr (die
, &attr
);
4479 /* Add an AT_specification attribute to a DIE, and also make the back
4480 pointer from the specification to the definition. */
4483 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4485 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4486 gcc_assert (!targ_die
->die_definition
);
4487 targ_die
->die_definition
= die
;
4490 static inline dw_die_ref
4491 AT_ref (dw_attr_ref a
)
4493 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4494 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4498 AT_ref_external (dw_attr_ref a
)
4500 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4501 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4507 set_AT_ref_external (dw_attr_ref a
, int i
)
4509 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4510 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4513 /* Add an FDE reference attribute value to a DIE. */
4516 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4520 attr
.dw_attr
= attr_kind
;
4521 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4522 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4523 add_dwarf_attr (die
, &attr
);
4526 /* Add a location description attribute value to a DIE. */
4529 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4533 attr
.dw_attr
= attr_kind
;
4534 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4535 attr
.dw_attr_val
.v
.val_loc
= loc
;
4536 add_dwarf_attr (die
, &attr
);
4539 static inline dw_loc_descr_ref
4540 AT_loc (dw_attr_ref a
)
4542 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4543 return a
->dw_attr_val
.v
.val_loc
;
4547 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4551 attr
.dw_attr
= attr_kind
;
4552 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4553 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4554 add_dwarf_attr (die
, &attr
);
4555 have_location_lists
= true;
4558 static inline dw_loc_list_ref
4559 AT_loc_list (dw_attr_ref a
)
4561 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4562 return a
->dw_attr_val
.v
.val_loc_list
;
4565 static inline dw_loc_list_ref
*
4566 AT_loc_list_ptr (dw_attr_ref a
)
4568 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4569 return &a
->dw_attr_val
.v
.val_loc_list
;
4572 /* Add an address constant attribute value to a DIE. */
4575 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
4579 attr
.dw_attr
= attr_kind
;
4580 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4581 attr
.dw_attr_val
.v
.val_addr
= addr
;
4582 add_dwarf_attr (die
, &attr
);
4585 /* Get the RTX from to an address DIE attribute. */
4588 AT_addr (dw_attr_ref a
)
4590 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4591 return a
->dw_attr_val
.v
.val_addr
;
4594 /* Add a file attribute value to a DIE. */
4597 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4598 struct dwarf_file_data
*fd
)
4602 attr
.dw_attr
= attr_kind
;
4603 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4604 attr
.dw_attr_val
.v
.val_file
= fd
;
4605 add_dwarf_attr (die
, &attr
);
4608 /* Get the dwarf_file_data from a file DIE attribute. */
4610 static inline struct dwarf_file_data
*
4611 AT_file (dw_attr_ref a
)
4613 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4614 return a
->dw_attr_val
.v
.val_file
;
4617 /* Add a vms delta attribute value to a DIE. */
4620 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4621 const char *lbl1
, const char *lbl2
)
4625 attr
.dw_attr
= attr_kind
;
4626 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4627 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4628 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4629 add_dwarf_attr (die
, &attr
);
4632 /* Add a label identifier attribute value to a DIE. */
4635 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
4639 attr
.dw_attr
= attr_kind
;
4640 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4641 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4642 add_dwarf_attr (die
, &attr
);
4645 /* Add a section offset attribute value to a DIE, an offset into the
4646 debug_line section. */
4649 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4654 attr
.dw_attr
= attr_kind
;
4655 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4656 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4657 add_dwarf_attr (die
, &attr
);
4660 /* Add a section offset attribute value to a DIE, an offset into the
4661 debug_macinfo section. */
4664 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4669 attr
.dw_attr
= attr_kind
;
4670 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4671 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4672 add_dwarf_attr (die
, &attr
);
4675 /* Add an offset attribute value to a DIE. */
4678 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4679 unsigned HOST_WIDE_INT offset
)
4683 attr
.dw_attr
= attr_kind
;
4684 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4685 attr
.dw_attr_val
.v
.val_offset
= offset
;
4686 add_dwarf_attr (die
, &attr
);
4689 /* Add an range_list attribute value to a DIE. */
4692 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4693 long unsigned int offset
)
4697 attr
.dw_attr
= attr_kind
;
4698 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4699 attr
.dw_attr_val
.v
.val_offset
= offset
;
4700 add_dwarf_attr (die
, &attr
);
4703 /* Return the start label of a delta attribute. */
4705 static inline const char *
4706 AT_vms_delta1 (dw_attr_ref a
)
4708 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4709 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4712 /* Return the end label of a delta attribute. */
4714 static inline const char *
4715 AT_vms_delta2 (dw_attr_ref a
)
4717 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4718 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4721 static inline const char *
4722 AT_lbl (dw_attr_ref a
)
4724 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4725 || AT_class (a
) == dw_val_class_lineptr
4726 || AT_class (a
) == dw_val_class_macptr
));
4727 return a
->dw_attr_val
.v
.val_lbl_id
;
4730 /* Get the attribute of type attr_kind. */
4733 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4737 dw_die_ref spec
= NULL
;
4742 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
4743 if (a
->dw_attr
== attr_kind
)
4745 else if (a
->dw_attr
== DW_AT_specification
4746 || a
->dw_attr
== DW_AT_abstract_origin
)
4750 return get_AT (spec
, attr_kind
);
4755 /* Return the "low pc" attribute value, typically associated with a subprogram
4756 DIE. Return null if the "low pc" attribute is either not present, or if it
4757 cannot be represented as an assembler label identifier. */
4759 static inline const char *
4760 get_AT_low_pc (dw_die_ref die
)
4762 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4764 return a
? AT_lbl (a
) : NULL
;
4767 /* Return the "high pc" attribute value, typically associated with a subprogram
4768 DIE. Return null if the "high pc" attribute is either not present, or if it
4769 cannot be represented as an assembler label identifier. */
4771 static inline const char *
4772 get_AT_hi_pc (dw_die_ref die
)
4774 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4776 return a
? AT_lbl (a
) : NULL
;
4779 /* Return the value of the string attribute designated by ATTR_KIND, or
4780 NULL if it is not present. */
4782 static inline const char *
4783 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4785 dw_attr_ref a
= get_AT (die
, attr_kind
);
4787 return a
? AT_string (a
) : NULL
;
4790 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4791 if it is not present. */
4794 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4796 dw_attr_ref a
= get_AT (die
, attr_kind
);
4798 return a
? AT_flag (a
) : 0;
4801 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4802 if it is not present. */
4804 static inline unsigned
4805 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4807 dw_attr_ref a
= get_AT (die
, attr_kind
);
4809 return a
? AT_unsigned (a
) : 0;
4812 static inline dw_die_ref
4813 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4815 dw_attr_ref a
= get_AT (die
, attr_kind
);
4817 return a
? AT_ref (a
) : NULL
;
4820 static inline struct dwarf_file_data
*
4821 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4823 dw_attr_ref a
= get_AT (die
, attr_kind
);
4825 return a
? AT_file (a
) : NULL
;
4828 /* Return TRUE if the language is C++. */
4833 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4835 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4838 /* Return TRUE if the language is Fortran. */
4843 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4845 return (lang
== DW_LANG_Fortran77
4846 || lang
== DW_LANG_Fortran90
4847 || lang
== DW_LANG_Fortran95
);
4850 /* Return TRUE if the language is Ada. */
4855 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4857 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4860 /* Remove the specified attribute if present. */
4863 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4871 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
4872 if (a
->dw_attr
== attr_kind
)
4874 if (AT_class (a
) == dw_val_class_str
)
4875 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4876 a
->dw_attr_val
.v
.val_str
->refcount
--;
4878 /* VEC_ordered_remove should help reduce the number of abbrevs
4880 VEC_ordered_remove (dw_attr_node
, die
->die_attr
, ix
);
4885 /* Remove CHILD from its parent. PREV must have the property that
4886 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4889 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4891 gcc_assert (child
->die_parent
== prev
->die_parent
);
4892 gcc_assert (prev
->die_sib
== child
);
4895 gcc_assert (child
->die_parent
->die_child
== child
);
4899 prev
->die_sib
= child
->die_sib
;
4900 if (child
->die_parent
->die_child
== child
)
4901 child
->die_parent
->die_child
= prev
;
4904 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4905 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4908 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4910 dw_die_ref parent
= old_child
->die_parent
;
4912 gcc_assert (parent
== prev
->die_parent
);
4913 gcc_assert (prev
->die_sib
== old_child
);
4915 new_child
->die_parent
= parent
;
4916 if (prev
== old_child
)
4918 gcc_assert (parent
->die_child
== old_child
);
4919 new_child
->die_sib
= new_child
;
4923 prev
->die_sib
= new_child
;
4924 new_child
->die_sib
= old_child
->die_sib
;
4926 if (old_child
->die_parent
->die_child
== old_child
)
4927 old_child
->die_parent
->die_child
= new_child
;
4930 /* Move all children from OLD_PARENT to NEW_PARENT. */
4933 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4936 new_parent
->die_child
= old_parent
->die_child
;
4937 old_parent
->die_child
= NULL
;
4938 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4941 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4945 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4951 dw_die_ref prev
= c
;
4953 while (c
->die_tag
== tag
)
4955 remove_child_with_prev (c
, prev
);
4956 /* Might have removed every child. */
4957 if (c
== c
->die_sib
)
4961 } while (c
!= die
->die_child
);
4964 /* Add a CHILD_DIE as the last child of DIE. */
4967 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4969 /* FIXME this should probably be an assert. */
4970 if (! die
|| ! child_die
)
4972 gcc_assert (die
!= child_die
);
4974 child_die
->die_parent
= die
;
4977 child_die
->die_sib
= die
->die_child
->die_sib
;
4978 die
->die_child
->die_sib
= child_die
;
4981 child_die
->die_sib
= child_die
;
4982 die
->die_child
= child_die
;
4985 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4986 is the specification, to the end of PARENT's list of children.
4987 This is done by removing and re-adding it. */
4990 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4994 /* We want the declaration DIE from inside the class, not the
4995 specification DIE at toplevel. */
4996 if (child
->die_parent
!= parent
)
4998 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5004 gcc_assert (child
->die_parent
== parent
5005 || (child
->die_parent
5006 == get_AT_ref (parent
, DW_AT_specification
)));
5008 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
5009 if (p
->die_sib
== child
)
5011 remove_child_with_prev (child
, p
);
5015 add_child_die (parent
, child
);
5018 /* Return a pointer to a newly created DIE node. */
5020 static inline dw_die_ref
5021 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5023 dw_die_ref die
= ggc_alloc_cleared_die_node ();
5025 die
->die_tag
= tag_value
;
5027 if (parent_die
!= NULL
)
5028 add_child_die (parent_die
, die
);
5031 limbo_die_node
*limbo_node
;
5033 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
5034 limbo_node
->die
= die
;
5035 limbo_node
->created_for
= t
;
5036 limbo_node
->next
= limbo_die_list
;
5037 limbo_die_list
= limbo_node
;
5043 /* Return the DIE associated with the given type specifier. */
5045 static inline dw_die_ref
5046 lookup_type_die (tree type
)
5048 return TYPE_SYMTAB_DIE (type
);
5051 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5052 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5053 anonymous type instead the one of the naming typedef. */
5055 static inline dw_die_ref
5056 strip_naming_typedef (tree type
, dw_die_ref type_die
)
5059 && TREE_CODE (type
) == RECORD_TYPE
5061 && type_die
->die_tag
== DW_TAG_typedef
5062 && is_naming_typedef_decl (TYPE_NAME (type
)))
5063 type_die
= get_AT_ref (type_die
, DW_AT_type
);
5067 /* Like lookup_type_die, but if type is an anonymous type named by a
5068 typedef[1], return the DIE of the anonymous type instead the one of
5069 the naming typedef. This is because in gen_typedef_die, we did
5070 equate the anonymous struct named by the typedef with the DIE of
5071 the naming typedef. So by default, lookup_type_die on an anonymous
5072 struct yields the DIE of the naming typedef.
5074 [1]: Read the comment of is_naming_typedef_decl to learn about what
5075 a naming typedef is. */
5077 static inline dw_die_ref
5078 lookup_type_die_strip_naming_typedef (tree type
)
5080 dw_die_ref die
= lookup_type_die (type
);
5081 return strip_naming_typedef (type
, die
);
5084 /* Equate a DIE to a given type specifier. */
5087 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5089 TYPE_SYMTAB_DIE (type
) = type_die
;
5092 /* Returns a hash value for X (which really is a die_struct). */
5095 decl_die_table_hash (const void *x
)
5097 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
5100 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5103 decl_die_table_eq (const void *x
, const void *y
)
5105 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
5108 /* Return the DIE associated with a given declaration. */
5110 static inline dw_die_ref
5111 lookup_decl_die (tree decl
)
5113 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
5116 /* Returns a hash value for X (which really is a var_loc_list). */
5119 decl_loc_table_hash (const void *x
)
5121 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
5124 /* Return nonzero if decl_id of var_loc_list X is the same as
5128 decl_loc_table_eq (const void *x
, const void *y
)
5130 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
5133 /* Return the var_loc list associated with a given declaration. */
5135 static inline var_loc_list
*
5136 lookup_decl_loc (const_tree decl
)
5138 if (!decl_loc_table
)
5140 return (var_loc_list
*)
5141 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
5144 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5147 cached_dw_loc_list_table_hash (const void *x
)
5149 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
5152 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5156 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
5158 return (((const cached_dw_loc_list
*) x
)->decl_id
5159 == DECL_UID ((const_tree
) y
));
5162 /* Equate a DIE to a particular declaration. */
5165 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5167 unsigned int decl_id
= DECL_UID (decl
);
5170 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
5172 decl_die
->decl_id
= decl_id
;
5175 /* Return how many bits covers PIECE EXPR_LIST. */
5178 decl_piece_bitsize (rtx piece
)
5180 int ret
= (int) GET_MODE (piece
);
5183 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
5184 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5185 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5188 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5191 decl_piece_varloc_ptr (rtx piece
)
5193 if ((int) GET_MODE (piece
))
5194 return &XEXP (piece
, 0);
5196 return &XEXP (XEXP (piece
, 0), 1);
5199 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5200 Next is the chain of following piece nodes. */
5203 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5205 if (bitsize
<= (int) MAX_MACHINE_MODE
)
5206 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5208 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5213 /* Return rtx that should be stored into loc field for
5214 LOC_NOTE and BITPOS/BITSIZE. */
5217 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5218 HOST_WIDE_INT bitsize
)
5222 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5224 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5229 /* This function either modifies location piece list *DEST in
5230 place (if SRC and INNER is NULL), or copies location piece list
5231 *SRC to *DEST while modifying it. Location BITPOS is modified
5232 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5233 not copied and if needed some padding around it is added.
5234 When modifying in place, DEST should point to EXPR_LIST where
5235 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5236 to the start of the whole list and INNER points to the EXPR_LIST
5237 where earlier pieces cover PIECE_BITPOS bits. */
5240 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5241 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5242 HOST_WIDE_INT bitsize
, rtx loc_note
)
5245 bool copy
= inner
!= NULL
;
5249 /* First copy all nodes preceeding the current bitpos. */
5250 while (src
!= inner
)
5252 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5253 decl_piece_bitsize (*src
), NULL_RTX
);
5254 dest
= &XEXP (*dest
, 1);
5255 src
= &XEXP (*src
, 1);
5258 /* Add padding if needed. */
5259 if (bitpos
!= piece_bitpos
)
5261 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5262 copy
? NULL_RTX
: *dest
);
5263 dest
= &XEXP (*dest
, 1);
5265 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5268 /* A piece with correct bitpos and bitsize already exist,
5269 just update the location for it and return. */
5270 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5273 /* Add the piece that changed. */
5274 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5275 dest
= &XEXP (*dest
, 1);
5276 /* Skip over pieces that overlap it. */
5277 diff
= bitpos
- piece_bitpos
+ bitsize
;
5280 while (diff
> 0 && *src
)
5283 diff
-= decl_piece_bitsize (piece
);
5285 src
= &XEXP (piece
, 1);
5288 *src
= XEXP (piece
, 1);
5289 free_EXPR_LIST_node (piece
);
5292 /* Add padding if needed. */
5293 if (diff
< 0 && *src
)
5297 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5298 dest
= &XEXP (*dest
, 1);
5302 /* Finally copy all nodes following it. */
5305 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5306 decl_piece_bitsize (*src
), NULL_RTX
);
5307 dest
= &XEXP (*dest
, 1);
5308 src
= &XEXP (*src
, 1);
5312 /* Add a variable location node to the linked list for DECL. */
5314 static struct var_loc_node
*
5315 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5317 unsigned int decl_id
;
5320 struct var_loc_node
*loc
= NULL
;
5321 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5323 if (DECL_DEBUG_EXPR_IS_FROM (decl
))
5325 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5326 if (realdecl
&& handled_component_p (realdecl
))
5328 HOST_WIDE_INT maxsize
;
5331 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5332 if (!DECL_P (innerdecl
)
5333 || DECL_IGNORED_P (innerdecl
)
5334 || TREE_STATIC (innerdecl
)
5336 || bitpos
+ bitsize
> 256
5337 || bitsize
!= maxsize
)
5343 decl_id
= DECL_UID (decl
);
5344 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5347 temp
= ggc_alloc_cleared_var_loc_list ();
5348 temp
->decl_id
= decl_id
;
5352 temp
= (var_loc_list
*) *slot
;
5354 /* For PARM_DECLs try to keep around the original incoming value,
5355 even if that means we'll emit a zero-range .debug_loc entry. */
5357 && temp
->first
== temp
->last
5358 && TREE_CODE (decl
) == PARM_DECL
5359 && GET_CODE (temp
->first
->loc
) == NOTE
5360 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5361 && DECL_INCOMING_RTL (decl
)
5362 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5363 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5364 == GET_CODE (DECL_INCOMING_RTL (decl
))
5365 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5367 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5368 NOTE_VAR_LOCATION_LOC (loc_note
))
5369 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5370 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5372 loc
= ggc_alloc_cleared_var_loc_node ();
5373 temp
->first
->next
= loc
;
5375 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5377 else if (temp
->last
)
5379 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5380 rtx
*piece_loc
= NULL
, last_loc_note
;
5381 int piece_bitpos
= 0;
5385 gcc_assert (last
->next
== NULL
);
5387 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5389 piece_loc
= &last
->loc
;
5392 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5393 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5395 piece_bitpos
+= cur_bitsize
;
5396 piece_loc
= &XEXP (*piece_loc
, 1);
5400 /* TEMP->LAST here is either pointer to the last but one or
5401 last element in the chained list, LAST is pointer to the
5403 if (label
&& strcmp (last
->label
, label
) == 0)
5405 /* For SRA optimized variables if there weren't any real
5406 insns since last note, just modify the last node. */
5407 if (piece_loc
!= NULL
)
5409 adjust_piece_list (piece_loc
, NULL
, NULL
,
5410 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5413 /* If the last note doesn't cover any instructions, remove it. */
5414 if (temp
->last
!= last
)
5416 temp
->last
->next
= NULL
;
5419 gcc_assert (strcmp (last
->label
, label
) != 0);
5423 gcc_assert (temp
->first
== temp
->last
5424 || (temp
->first
->next
== temp
->last
5425 && TREE_CODE (decl
) == PARM_DECL
));
5426 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5427 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5431 if (bitsize
== -1 && NOTE_P (last
->loc
))
5432 last_loc_note
= last
->loc
;
5433 else if (piece_loc
!= NULL
5434 && *piece_loc
!= NULL_RTX
5435 && piece_bitpos
== bitpos
5436 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5437 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5439 last_loc_note
= NULL_RTX
;
5440 /* If the current location is the same as the end of the list,
5441 and either both or neither of the locations is uninitialized,
5442 we have nothing to do. */
5443 if (last_loc_note
== NULL_RTX
5444 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5445 NOTE_VAR_LOCATION_LOC (loc_note
)))
5446 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5447 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5448 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5449 == VAR_INIT_STATUS_UNINITIALIZED
)
5450 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5451 == VAR_INIT_STATUS_UNINITIALIZED
))))
5453 /* Add LOC to the end of list and update LAST. If the last
5454 element of the list has been removed above, reuse its
5455 memory for the new node, otherwise allocate a new one. */
5459 memset (loc
, '\0', sizeof (*loc
));
5462 loc
= ggc_alloc_cleared_var_loc_node ();
5463 if (bitsize
== -1 || piece_loc
== NULL
)
5464 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5466 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5467 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5469 /* Ensure TEMP->LAST will point either to the new last but one
5470 element of the chain, or to the last element in it. */
5471 if (last
!= temp
->last
)
5479 loc
= ggc_alloc_cleared_var_loc_node ();
5482 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5487 /* Keep track of the number of spaces used to indent the
5488 output of the debugging routines that print the structure of
5489 the DIE internal representation. */
5490 static int print_indent
;
5492 /* Indent the line the number of spaces given by print_indent. */
5495 print_spaces (FILE *outfile
)
5497 fprintf (outfile
, "%*s", print_indent
, "");
5500 /* Print a type signature in hex. */
5503 print_signature (FILE *outfile
, char *sig
)
5507 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5508 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5511 /* Print the information associated with a given DIE, and its children.
5512 This routine is a debugging aid only. */
5515 print_die (dw_die_ref die
, FILE *outfile
)
5521 print_spaces (outfile
);
5522 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5523 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5525 print_spaces (outfile
);
5526 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5527 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5528 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5530 if (use_debug_types
&& die
->die_id
.die_type_node
)
5532 print_spaces (outfile
);
5533 fprintf (outfile
, " signature: ");
5534 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5535 fprintf (outfile
, "\n");
5538 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
5540 print_spaces (outfile
);
5541 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5543 switch (AT_class (a
))
5545 case dw_val_class_addr
:
5546 fprintf (outfile
, "address");
5548 case dw_val_class_offset
:
5549 fprintf (outfile
, "offset");
5551 case dw_val_class_loc
:
5552 fprintf (outfile
, "location descriptor");
5554 case dw_val_class_loc_list
:
5555 fprintf (outfile
, "location list -> label:%s",
5556 AT_loc_list (a
)->ll_symbol
);
5558 case dw_val_class_range_list
:
5559 fprintf (outfile
, "range list");
5561 case dw_val_class_const
:
5562 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5564 case dw_val_class_unsigned_const
:
5565 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5567 case dw_val_class_const_double
:
5568 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
5569 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5570 a
->dw_attr_val
.v
.val_double
.high
,
5571 a
->dw_attr_val
.v
.val_double
.low
);
5573 case dw_val_class_vec
:
5574 fprintf (outfile
, "floating-point or vector constant");
5576 case dw_val_class_flag
:
5577 fprintf (outfile
, "%u", AT_flag (a
));
5579 case dw_val_class_die_ref
:
5580 if (AT_ref (a
) != NULL
)
5582 if (use_debug_types
&& AT_ref (a
)->die_id
.die_type_node
)
5584 fprintf (outfile
, "die -> signature: ");
5585 print_signature (outfile
,
5586 AT_ref (a
)->die_id
.die_type_node
->signature
);
5588 else if (! use_debug_types
&& AT_ref (a
)->die_id
.die_symbol
)
5589 fprintf (outfile
, "die -> label: %s",
5590 AT_ref (a
)->die_id
.die_symbol
);
5592 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
5593 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
5596 fprintf (outfile
, "die -> <null>");
5598 case dw_val_class_vms_delta
:
5599 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5600 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
5602 case dw_val_class_lbl_id
:
5603 case dw_val_class_lineptr
:
5604 case dw_val_class_macptr
:
5605 fprintf (outfile
, "label: %s", AT_lbl (a
));
5607 case dw_val_class_str
:
5608 if (AT_string (a
) != NULL
)
5609 fprintf (outfile
, "\"%s\"", AT_string (a
));
5611 fprintf (outfile
, "<null>");
5613 case dw_val_class_file
:
5614 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
5615 AT_file (a
)->emitted_number
);
5617 case dw_val_class_data8
:
5621 for (i
= 0; i
< 8; i
++)
5622 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
5629 fprintf (outfile
, "\n");
5632 if (die
->die_child
!= NULL
)
5635 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5638 if (print_indent
== 0)
5639 fprintf (outfile
, "\n");
5642 /* Print the information collected for a given DIE. */
5645 debug_dwarf_die (dw_die_ref die
)
5647 print_die (die
, stderr
);
5650 /* Print all DWARF information collected for the compilation unit.
5651 This routine is a debugging aid only. */
5657 print_die (comp_unit_die (), stderr
);
5660 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5661 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5662 DIE that marks the start of the DIEs for this include file. */
5665 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5667 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5668 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5670 new_unit
->die_sib
= old_unit
;
5674 /* Close an include-file CU and reopen the enclosing one. */
5677 pop_compile_unit (dw_die_ref old_unit
)
5679 dw_die_ref new_unit
= old_unit
->die_sib
;
5681 old_unit
->die_sib
= NULL
;
5685 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5686 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5688 /* Calculate the checksum of a location expression. */
5691 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5695 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5697 CHECKSUM (loc
->dw_loc_oprnd1
);
5698 CHECKSUM (loc
->dw_loc_oprnd2
);
5701 /* Calculate the checksum of an attribute. */
5704 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5706 dw_loc_descr_ref loc
;
5709 CHECKSUM (at
->dw_attr
);
5711 /* We don't care that this was compiled with a different compiler
5712 snapshot; if the output is the same, that's what matters. */
5713 if (at
->dw_attr
== DW_AT_producer
)
5716 switch (AT_class (at
))
5718 case dw_val_class_const
:
5719 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5721 case dw_val_class_unsigned_const
:
5722 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5724 case dw_val_class_const_double
:
5725 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5727 case dw_val_class_vec
:
5728 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5730 case dw_val_class_flag
:
5731 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5733 case dw_val_class_str
:
5734 CHECKSUM_STRING (AT_string (at
));
5737 case dw_val_class_addr
:
5739 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5740 CHECKSUM_STRING (XSTR (r
, 0));
5743 case dw_val_class_offset
:
5744 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5747 case dw_val_class_loc
:
5748 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5749 loc_checksum (loc
, ctx
);
5752 case dw_val_class_die_ref
:
5753 die_checksum (AT_ref (at
), ctx
, mark
);
5756 case dw_val_class_fde_ref
:
5757 case dw_val_class_vms_delta
:
5758 case dw_val_class_lbl_id
:
5759 case dw_val_class_lineptr
:
5760 case dw_val_class_macptr
:
5763 case dw_val_class_file
:
5764 CHECKSUM_STRING (AT_file (at
)->filename
);
5767 case dw_val_class_data8
:
5768 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5776 /* Calculate the checksum of a DIE. */
5779 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5785 /* To avoid infinite recursion. */
5788 CHECKSUM (die
->die_mark
);
5791 die
->die_mark
= ++(*mark
);
5793 CHECKSUM (die
->die_tag
);
5795 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
5796 attr_checksum (a
, ctx
, mark
);
5798 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5802 #undef CHECKSUM_STRING
5804 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5805 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5806 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5807 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5808 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5809 #define CHECKSUM_ATTR(FOO) \
5810 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5812 /* Calculate the checksum of a number in signed LEB128 format. */
5815 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5822 byte
= (value
& 0x7f);
5824 more
= !((value
== 0 && (byte
& 0x40) == 0)
5825 || (value
== -1 && (byte
& 0x40) != 0));
5834 /* Calculate the checksum of a number in unsigned LEB128 format. */
5837 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5841 unsigned char byte
= (value
& 0x7f);
5844 /* More bytes to follow. */
5852 /* Checksum the context of the DIE. This adds the names of any
5853 surrounding namespaces or structures to the checksum. */
5856 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5860 int tag
= die
->die_tag
;
5862 if (tag
!= DW_TAG_namespace
5863 && tag
!= DW_TAG_structure_type
5864 && tag
!= DW_TAG_class_type
)
5867 name
= get_AT_string (die
, DW_AT_name
);
5869 spec
= get_AT_ref (die
, DW_AT_specification
);
5873 if (die
->die_parent
!= NULL
)
5874 checksum_die_context (die
->die_parent
, ctx
);
5876 CHECKSUM_ULEB128 ('C');
5877 CHECKSUM_ULEB128 (tag
);
5879 CHECKSUM_STRING (name
);
5882 /* Calculate the checksum of a location expression. */
5885 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5887 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5888 were emitted as a DW_FORM_sdata instead of a location expression. */
5889 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5891 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5892 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5896 /* Otherwise, just checksum the raw location expression. */
5899 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5900 CHECKSUM (loc
->dw_loc_oprnd1
);
5901 CHECKSUM (loc
->dw_loc_oprnd2
);
5902 loc
= loc
->dw_loc_next
;
5906 /* Calculate the checksum of an attribute. */
5909 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5910 struct md5_ctx
*ctx
, int *mark
)
5912 dw_loc_descr_ref loc
;
5915 if (AT_class (at
) == dw_val_class_die_ref
)
5917 dw_die_ref target_die
= AT_ref (at
);
5919 /* For pointer and reference types, we checksum only the (qualified)
5920 name of the target type (if there is a name). For friend entries,
5921 we checksum only the (qualified) name of the target type or function.
5922 This allows the checksum to remain the same whether the target type
5923 is complete or not. */
5924 if ((at
->dw_attr
== DW_AT_type
5925 && (tag
== DW_TAG_pointer_type
5926 || tag
== DW_TAG_reference_type
5927 || tag
== DW_TAG_rvalue_reference_type
5928 || tag
== DW_TAG_ptr_to_member_type
))
5929 || (at
->dw_attr
== DW_AT_friend
5930 && tag
== DW_TAG_friend
))
5932 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5934 if (name_attr
!= NULL
)
5936 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5940 CHECKSUM_ULEB128 ('N');
5941 CHECKSUM_ULEB128 (at
->dw_attr
);
5942 if (decl
->die_parent
!= NULL
)
5943 checksum_die_context (decl
->die_parent
, ctx
);
5944 CHECKSUM_ULEB128 ('E');
5945 CHECKSUM_STRING (AT_string (name_attr
));
5950 /* For all other references to another DIE, we check to see if the
5951 target DIE has already been visited. If it has, we emit a
5952 backward reference; if not, we descend recursively. */
5953 if (target_die
->die_mark
> 0)
5955 CHECKSUM_ULEB128 ('R');
5956 CHECKSUM_ULEB128 (at
->dw_attr
);
5957 CHECKSUM_ULEB128 (target_die
->die_mark
);
5961 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5965 target_die
->die_mark
= ++(*mark
);
5966 CHECKSUM_ULEB128 ('T');
5967 CHECKSUM_ULEB128 (at
->dw_attr
);
5968 if (decl
->die_parent
!= NULL
)
5969 checksum_die_context (decl
->die_parent
, ctx
);
5970 die_checksum_ordered (target_die
, ctx
, mark
);
5975 CHECKSUM_ULEB128 ('A');
5976 CHECKSUM_ULEB128 (at
->dw_attr
);
5978 switch (AT_class (at
))
5980 case dw_val_class_const
:
5981 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5982 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5985 case dw_val_class_unsigned_const
:
5986 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5987 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5990 case dw_val_class_const_double
:
5991 CHECKSUM_ULEB128 (DW_FORM_block
);
5992 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5993 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5996 case dw_val_class_vec
:
5997 CHECKSUM_ULEB128 (DW_FORM_block
);
5998 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_vec
));
5999 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
6002 case dw_val_class_flag
:
6003 CHECKSUM_ULEB128 (DW_FORM_flag
);
6004 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
6007 case dw_val_class_str
:
6008 CHECKSUM_ULEB128 (DW_FORM_string
);
6009 CHECKSUM_STRING (AT_string (at
));
6012 case dw_val_class_addr
:
6014 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6015 CHECKSUM_ULEB128 (DW_FORM_string
);
6016 CHECKSUM_STRING (XSTR (r
, 0));
6019 case dw_val_class_offset
:
6020 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6021 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
6024 case dw_val_class_loc
:
6025 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6026 loc_checksum_ordered (loc
, ctx
);
6029 case dw_val_class_fde_ref
:
6030 case dw_val_class_lbl_id
:
6031 case dw_val_class_lineptr
:
6032 case dw_val_class_macptr
:
6035 case dw_val_class_file
:
6036 CHECKSUM_ULEB128 (DW_FORM_string
);
6037 CHECKSUM_STRING (AT_file (at
)->filename
);
6040 case dw_val_class_data8
:
6041 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6049 struct checksum_attributes
6051 dw_attr_ref at_name
;
6052 dw_attr_ref at_type
;
6053 dw_attr_ref at_friend
;
6054 dw_attr_ref at_accessibility
;
6055 dw_attr_ref at_address_class
;
6056 dw_attr_ref at_allocated
;
6057 dw_attr_ref at_artificial
;
6058 dw_attr_ref at_associated
;
6059 dw_attr_ref at_binary_scale
;
6060 dw_attr_ref at_bit_offset
;
6061 dw_attr_ref at_bit_size
;
6062 dw_attr_ref at_bit_stride
;
6063 dw_attr_ref at_byte_size
;
6064 dw_attr_ref at_byte_stride
;
6065 dw_attr_ref at_const_value
;
6066 dw_attr_ref at_containing_type
;
6067 dw_attr_ref at_count
;
6068 dw_attr_ref at_data_location
;
6069 dw_attr_ref at_data_member_location
;
6070 dw_attr_ref at_decimal_scale
;
6071 dw_attr_ref at_decimal_sign
;
6072 dw_attr_ref at_default_value
;
6073 dw_attr_ref at_digit_count
;
6074 dw_attr_ref at_discr
;
6075 dw_attr_ref at_discr_list
;
6076 dw_attr_ref at_discr_value
;
6077 dw_attr_ref at_encoding
;
6078 dw_attr_ref at_endianity
;
6079 dw_attr_ref at_explicit
;
6080 dw_attr_ref at_is_optional
;
6081 dw_attr_ref at_location
;
6082 dw_attr_ref at_lower_bound
;
6083 dw_attr_ref at_mutable
;
6084 dw_attr_ref at_ordering
;
6085 dw_attr_ref at_picture_string
;
6086 dw_attr_ref at_prototyped
;
6087 dw_attr_ref at_small
;
6088 dw_attr_ref at_segment
;
6089 dw_attr_ref at_string_length
;
6090 dw_attr_ref at_threads_scaled
;
6091 dw_attr_ref at_upper_bound
;
6092 dw_attr_ref at_use_location
;
6093 dw_attr_ref at_use_UTF8
;
6094 dw_attr_ref at_variable_parameter
;
6095 dw_attr_ref at_virtuality
;
6096 dw_attr_ref at_visibility
;
6097 dw_attr_ref at_vtable_elem_location
;
6100 /* Collect the attributes that we will want to use for the checksum. */
6103 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
6108 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6119 attrs
->at_friend
= a
;
6121 case DW_AT_accessibility
:
6122 attrs
->at_accessibility
= a
;
6124 case DW_AT_address_class
:
6125 attrs
->at_address_class
= a
;
6127 case DW_AT_allocated
:
6128 attrs
->at_allocated
= a
;
6130 case DW_AT_artificial
:
6131 attrs
->at_artificial
= a
;
6133 case DW_AT_associated
:
6134 attrs
->at_associated
= a
;
6136 case DW_AT_binary_scale
:
6137 attrs
->at_binary_scale
= a
;
6139 case DW_AT_bit_offset
:
6140 attrs
->at_bit_offset
= a
;
6142 case DW_AT_bit_size
:
6143 attrs
->at_bit_size
= a
;
6145 case DW_AT_bit_stride
:
6146 attrs
->at_bit_stride
= a
;
6148 case DW_AT_byte_size
:
6149 attrs
->at_byte_size
= a
;
6151 case DW_AT_byte_stride
:
6152 attrs
->at_byte_stride
= a
;
6154 case DW_AT_const_value
:
6155 attrs
->at_const_value
= a
;
6157 case DW_AT_containing_type
:
6158 attrs
->at_containing_type
= a
;
6161 attrs
->at_count
= a
;
6163 case DW_AT_data_location
:
6164 attrs
->at_data_location
= a
;
6166 case DW_AT_data_member_location
:
6167 attrs
->at_data_member_location
= a
;
6169 case DW_AT_decimal_scale
:
6170 attrs
->at_decimal_scale
= a
;
6172 case DW_AT_decimal_sign
:
6173 attrs
->at_decimal_sign
= a
;
6175 case DW_AT_default_value
:
6176 attrs
->at_default_value
= a
;
6178 case DW_AT_digit_count
:
6179 attrs
->at_digit_count
= a
;
6182 attrs
->at_discr
= a
;
6184 case DW_AT_discr_list
:
6185 attrs
->at_discr_list
= a
;
6187 case DW_AT_discr_value
:
6188 attrs
->at_discr_value
= a
;
6190 case DW_AT_encoding
:
6191 attrs
->at_encoding
= a
;
6193 case DW_AT_endianity
:
6194 attrs
->at_endianity
= a
;
6196 case DW_AT_explicit
:
6197 attrs
->at_explicit
= a
;
6199 case DW_AT_is_optional
:
6200 attrs
->at_is_optional
= a
;
6202 case DW_AT_location
:
6203 attrs
->at_location
= a
;
6205 case DW_AT_lower_bound
:
6206 attrs
->at_lower_bound
= a
;
6209 attrs
->at_mutable
= a
;
6211 case DW_AT_ordering
:
6212 attrs
->at_ordering
= a
;
6214 case DW_AT_picture_string
:
6215 attrs
->at_picture_string
= a
;
6217 case DW_AT_prototyped
:
6218 attrs
->at_prototyped
= a
;
6221 attrs
->at_small
= a
;
6224 attrs
->at_segment
= a
;
6226 case DW_AT_string_length
:
6227 attrs
->at_string_length
= a
;
6229 case DW_AT_threads_scaled
:
6230 attrs
->at_threads_scaled
= a
;
6232 case DW_AT_upper_bound
:
6233 attrs
->at_upper_bound
= a
;
6235 case DW_AT_use_location
:
6236 attrs
->at_use_location
= a
;
6238 case DW_AT_use_UTF8
:
6239 attrs
->at_use_UTF8
= a
;
6241 case DW_AT_variable_parameter
:
6242 attrs
->at_variable_parameter
= a
;
6244 case DW_AT_virtuality
:
6245 attrs
->at_virtuality
= a
;
6247 case DW_AT_visibility
:
6248 attrs
->at_visibility
= a
;
6250 case DW_AT_vtable_elem_location
:
6251 attrs
->at_vtable_elem_location
= a
;
6259 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6262 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6266 struct checksum_attributes attrs
;
6268 CHECKSUM_ULEB128 ('D');
6269 CHECKSUM_ULEB128 (die
->die_tag
);
6271 memset (&attrs
, 0, sizeof (attrs
));
6273 decl
= get_AT_ref (die
, DW_AT_specification
);
6275 collect_checksum_attributes (&attrs
, decl
);
6276 collect_checksum_attributes (&attrs
, die
);
6278 CHECKSUM_ATTR (attrs
.at_name
);
6279 CHECKSUM_ATTR (attrs
.at_accessibility
);
6280 CHECKSUM_ATTR (attrs
.at_address_class
);
6281 CHECKSUM_ATTR (attrs
.at_allocated
);
6282 CHECKSUM_ATTR (attrs
.at_artificial
);
6283 CHECKSUM_ATTR (attrs
.at_associated
);
6284 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6285 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6286 CHECKSUM_ATTR (attrs
.at_bit_size
);
6287 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6288 CHECKSUM_ATTR (attrs
.at_byte_size
);
6289 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6290 CHECKSUM_ATTR (attrs
.at_const_value
);
6291 CHECKSUM_ATTR (attrs
.at_containing_type
);
6292 CHECKSUM_ATTR (attrs
.at_count
);
6293 CHECKSUM_ATTR (attrs
.at_data_location
);
6294 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6295 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6296 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6297 CHECKSUM_ATTR (attrs
.at_default_value
);
6298 CHECKSUM_ATTR (attrs
.at_digit_count
);
6299 CHECKSUM_ATTR (attrs
.at_discr
);
6300 CHECKSUM_ATTR (attrs
.at_discr_list
);
6301 CHECKSUM_ATTR (attrs
.at_discr_value
);
6302 CHECKSUM_ATTR (attrs
.at_encoding
);
6303 CHECKSUM_ATTR (attrs
.at_endianity
);
6304 CHECKSUM_ATTR (attrs
.at_explicit
);
6305 CHECKSUM_ATTR (attrs
.at_is_optional
);
6306 CHECKSUM_ATTR (attrs
.at_location
);
6307 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6308 CHECKSUM_ATTR (attrs
.at_mutable
);
6309 CHECKSUM_ATTR (attrs
.at_ordering
);
6310 CHECKSUM_ATTR (attrs
.at_picture_string
);
6311 CHECKSUM_ATTR (attrs
.at_prototyped
);
6312 CHECKSUM_ATTR (attrs
.at_small
);
6313 CHECKSUM_ATTR (attrs
.at_segment
);
6314 CHECKSUM_ATTR (attrs
.at_string_length
);
6315 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6316 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6317 CHECKSUM_ATTR (attrs
.at_use_location
);
6318 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6319 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6320 CHECKSUM_ATTR (attrs
.at_virtuality
);
6321 CHECKSUM_ATTR (attrs
.at_visibility
);
6322 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6323 CHECKSUM_ATTR (attrs
.at_type
);
6324 CHECKSUM_ATTR (attrs
.at_friend
);
6326 /* Checksum the child DIEs, except for nested types and member functions. */
6329 dw_attr_ref name_attr
;
6332 name_attr
= get_AT (c
, DW_AT_name
);
6333 if ((is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
)
6334 && name_attr
!= NULL
)
6336 CHECKSUM_ULEB128 ('S');
6337 CHECKSUM_ULEB128 (c
->die_tag
);
6338 CHECKSUM_STRING (AT_string (name_attr
));
6342 /* Mark this DIE so it gets processed when unmarking. */
6343 if (c
->die_mark
== 0)
6345 die_checksum_ordered (c
, ctx
, mark
);
6347 } while (c
!= die
->die_child
);
6349 CHECKSUM_ULEB128 (0);
6353 #undef CHECKSUM_STRING
6354 #undef CHECKSUM_ATTR
6355 #undef CHECKSUM_LEB128
6356 #undef CHECKSUM_ULEB128
6358 /* Generate the type signature for DIE. This is computed by generating an
6359 MD5 checksum over the DIE's tag, its relevant attributes, and its
6360 children. Attributes that are references to other DIEs are processed
6361 by recursion, using the MARK field to prevent infinite recursion.
6362 If the DIE is nested inside a namespace or another type, we also
6363 need to include that context in the signature. The lower 64 bits
6364 of the resulting MD5 checksum comprise the signature. */
6367 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6371 unsigned char checksum
[16];
6375 name
= get_AT_string (die
, DW_AT_name
);
6376 decl
= get_AT_ref (die
, DW_AT_specification
);
6378 /* First, compute a signature for just the type name (and its surrounding
6379 context, if any. This is stored in the type unit DIE for link-time
6380 ODR (one-definition rule) checking. */
6382 if (is_cxx() && name
!= NULL
)
6384 md5_init_ctx (&ctx
);
6386 /* Checksum the names of surrounding namespaces and structures. */
6387 if (decl
!= NULL
&& decl
->die_parent
!= NULL
)
6388 checksum_die_context (decl
->die_parent
, &ctx
);
6390 md5_process_bytes (&die
->die_tag
, sizeof (die
->die_tag
), &ctx
);
6391 md5_process_bytes (name
, strlen (name
) + 1, &ctx
);
6392 md5_finish_ctx (&ctx
, checksum
);
6394 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6397 /* Next, compute the complete type signature. */
6399 md5_init_ctx (&ctx
);
6401 die
->die_mark
= mark
;
6403 /* Checksum the names of surrounding namespaces and structures. */
6404 if (decl
!= NULL
&& decl
->die_parent
!= NULL
)
6405 checksum_die_context (decl
->die_parent
, &ctx
);
6407 /* Checksum the DIE and its children. */
6408 die_checksum_ordered (die
, &ctx
, &mark
);
6409 unmark_all_dies (die
);
6410 md5_finish_ctx (&ctx
, checksum
);
6412 /* Store the signature in the type node and link the type DIE and the
6413 type node together. */
6414 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6415 DWARF_TYPE_SIGNATURE_SIZE
);
6416 die
->die_id
.die_type_node
= type_node
;
6417 type_node
->type_die
= die
;
6419 /* If the DIE is a specification, link its declaration to the type node
6422 decl
->die_id
.die_type_node
= type_node
;
6425 /* Do the location expressions look same? */
6427 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6429 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6430 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6431 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6434 /* Do the values look the same? */
6436 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6438 dw_loc_descr_ref loc1
, loc2
;
6441 if (v1
->val_class
!= v2
->val_class
)
6444 switch (v1
->val_class
)
6446 case dw_val_class_const
:
6447 return v1
->v
.val_int
== v2
->v
.val_int
;
6448 case dw_val_class_unsigned_const
:
6449 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6450 case dw_val_class_const_double
:
6451 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6452 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6453 case dw_val_class_vec
:
6454 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6455 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6457 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6458 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6461 case dw_val_class_flag
:
6462 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6463 case dw_val_class_str
:
6464 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6466 case dw_val_class_addr
:
6467 r1
= v1
->v
.val_addr
;
6468 r2
= v2
->v
.val_addr
;
6469 if (GET_CODE (r1
) != GET_CODE (r2
))
6471 return !rtx_equal_p (r1
, r2
);
6473 case dw_val_class_offset
:
6474 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6476 case dw_val_class_loc
:
6477 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6479 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6480 if (!same_loc_p (loc1
, loc2
, mark
))
6482 return !loc1
&& !loc2
;
6484 case dw_val_class_die_ref
:
6485 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6487 case dw_val_class_fde_ref
:
6488 case dw_val_class_vms_delta
:
6489 case dw_val_class_lbl_id
:
6490 case dw_val_class_lineptr
:
6491 case dw_val_class_macptr
:
6494 case dw_val_class_file
:
6495 return v1
->v
.val_file
== v2
->v
.val_file
;
6497 case dw_val_class_data8
:
6498 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6505 /* Do the attributes look the same? */
6508 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6510 if (at1
->dw_attr
!= at2
->dw_attr
)
6513 /* We don't care that this was compiled with a different compiler
6514 snapshot; if the output is the same, that's what matters. */
6515 if (at1
->dw_attr
== DW_AT_producer
)
6518 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6521 /* Do the dies look the same? */
6524 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6530 /* To avoid infinite recursion. */
6532 return die1
->die_mark
== die2
->die_mark
;
6533 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6535 if (die1
->die_tag
!= die2
->die_tag
)
6538 if (VEC_length (dw_attr_node
, die1
->die_attr
)
6539 != VEC_length (dw_attr_node
, die2
->die_attr
))
6542 FOR_EACH_VEC_ELT (dw_attr_node
, die1
->die_attr
, ix
, a1
)
6543 if (!same_attr_p (a1
, VEC_index (dw_attr_node
, die2
->die_attr
, ix
), mark
))
6546 c1
= die1
->die_child
;
6547 c2
= die2
->die_child
;
6556 if (!same_die_p (c1
, c2
, mark
))
6560 if (c1
== die1
->die_child
)
6562 if (c2
== die2
->die_child
)
6572 /* Do the dies look the same? Wrapper around same_die_p. */
6575 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6578 int ret
= same_die_p (die1
, die2
, &mark
);
6580 unmark_all_dies (die1
);
6581 unmark_all_dies (die2
);
6586 /* The prefix to attach to symbols on DIEs in the current comdat debug
6588 static char *comdat_symbol_id
;
6590 /* The index of the current symbol within the current comdat CU. */
6591 static unsigned int comdat_symbol_number
;
6593 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6594 children, and set comdat_symbol_id accordingly. */
6597 compute_section_prefix (dw_die_ref unit_die
)
6599 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6600 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6601 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6604 unsigned char checksum
[16];
6607 /* Compute the checksum of the DIE, then append part of it as hex digits to
6608 the name filename of the unit. */
6610 md5_init_ctx (&ctx
);
6612 die_checksum (unit_die
, &ctx
, &mark
);
6613 unmark_all_dies (unit_die
);
6614 md5_finish_ctx (&ctx
, checksum
);
6616 sprintf (name
, "%s.", base
);
6617 clean_symbol_name (name
);
6619 p
= name
+ strlen (name
);
6620 for (i
= 0; i
< 4; i
++)
6622 sprintf (p
, "%.2x", checksum
[i
]);
6626 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6627 comdat_symbol_number
= 0;
6630 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6633 is_type_die (dw_die_ref die
)
6635 switch (die
->die_tag
)
6637 case DW_TAG_array_type
:
6638 case DW_TAG_class_type
:
6639 case DW_TAG_interface_type
:
6640 case DW_TAG_enumeration_type
:
6641 case DW_TAG_pointer_type
:
6642 case DW_TAG_reference_type
:
6643 case DW_TAG_rvalue_reference_type
:
6644 case DW_TAG_string_type
:
6645 case DW_TAG_structure_type
:
6646 case DW_TAG_subroutine_type
:
6647 case DW_TAG_union_type
:
6648 case DW_TAG_ptr_to_member_type
:
6649 case DW_TAG_set_type
:
6650 case DW_TAG_subrange_type
:
6651 case DW_TAG_base_type
:
6652 case DW_TAG_const_type
:
6653 case DW_TAG_file_type
:
6654 case DW_TAG_packed_type
:
6655 case DW_TAG_volatile_type
:
6656 case DW_TAG_typedef
:
6663 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6664 Basically, we want to choose the bits that are likely to be shared between
6665 compilations (types) and leave out the bits that are specific to individual
6666 compilations (functions). */
6669 is_comdat_die (dw_die_ref c
)
6671 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6672 we do for stabs. The advantage is a greater likelihood of sharing between
6673 objects that don't include headers in the same order (and therefore would
6674 put the base types in a different comdat). jason 8/28/00 */
6676 if (c
->die_tag
== DW_TAG_base_type
)
6679 if (c
->die_tag
== DW_TAG_pointer_type
6680 || c
->die_tag
== DW_TAG_reference_type
6681 || c
->die_tag
== DW_TAG_rvalue_reference_type
6682 || c
->die_tag
== DW_TAG_const_type
6683 || c
->die_tag
== DW_TAG_volatile_type
)
6685 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6687 return t
? is_comdat_die (t
) : 0;
6690 return is_type_die (c
);
6693 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6694 compilation unit. */
6697 is_symbol_die (dw_die_ref c
)
6699 return (is_type_die (c
)
6700 || is_declaration_die (c
)
6701 || c
->die_tag
== DW_TAG_namespace
6702 || c
->die_tag
== DW_TAG_module
);
6705 /* Returns true iff C is a compile-unit DIE. */
6708 is_cu_die (dw_die_ref c
)
6710 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6714 gen_internal_sym (const char *prefix
)
6718 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6719 return xstrdup (buf
);
6722 /* Assign symbols to all worthy DIEs under DIE. */
6725 assign_symbol_names (dw_die_ref die
)
6729 if (is_symbol_die (die
))
6731 if (comdat_symbol_id
)
6733 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6735 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6736 comdat_symbol_id
, comdat_symbol_number
++);
6737 die
->die_id
.die_symbol
= xstrdup (p
);
6740 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6743 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6746 struct cu_hash_table_entry
6749 unsigned min_comdat_num
, max_comdat_num
;
6750 struct cu_hash_table_entry
*next
;
6753 /* Routines to manipulate hash table of CUs. */
6755 htab_cu_hash (const void *of
)
6757 const struct cu_hash_table_entry
*const entry
=
6758 (const struct cu_hash_table_entry
*) of
;
6760 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6764 htab_cu_eq (const void *of1
, const void *of2
)
6766 const struct cu_hash_table_entry
*const entry1
=
6767 (const struct cu_hash_table_entry
*) of1
;
6768 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
6770 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6774 htab_cu_del (void *what
)
6776 struct cu_hash_table_entry
*next
,
6777 *entry
= (struct cu_hash_table_entry
*) what
;
6787 /* Check whether we have already seen this CU and set up SYM_NUM
6790 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
6792 struct cu_hash_table_entry dummy
;
6793 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6795 dummy
.max_comdat_num
= 0;
6797 slot
= (struct cu_hash_table_entry
**)
6798 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6802 for (; entry
; last
= entry
, entry
= entry
->next
)
6804 if (same_die_p_wrap (cu
, entry
->cu
))
6810 *sym_num
= entry
->min_comdat_num
;
6814 entry
= XCNEW (struct cu_hash_table_entry
);
6816 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6817 entry
->next
= *slot
;
6823 /* Record SYM_NUM to record of CU in HTABLE. */
6825 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
6827 struct cu_hash_table_entry
**slot
, *entry
;
6829 slot
= (struct cu_hash_table_entry
**)
6830 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6834 entry
->max_comdat_num
= sym_num
;
6837 /* Traverse the DIE (which is always comp_unit_die), and set up
6838 additional compilation units for each of the include files we see
6839 bracketed by BINCL/EINCL. */
6842 break_out_includes (dw_die_ref die
)
6845 dw_die_ref unit
= NULL
;
6846 limbo_die_node
*node
, **pnode
;
6847 htab_t cu_hash_table
;
6851 dw_die_ref prev
= c
;
6853 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6854 || (unit
&& is_comdat_die (c
)))
6856 dw_die_ref next
= c
->die_sib
;
6858 /* This DIE is for a secondary CU; remove it from the main one. */
6859 remove_child_with_prev (c
, prev
);
6861 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6862 unit
= push_new_compile_unit (unit
, c
);
6863 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6864 unit
= pop_compile_unit (unit
);
6866 add_child_die (unit
, c
);
6868 if (c
== die
->die_child
)
6871 } while (c
!= die
->die_child
);
6874 /* We can only use this in debugging, since the frontend doesn't check
6875 to make sure that we leave every include file we enter. */
6879 assign_symbol_names (die
);
6880 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
6881 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6887 compute_section_prefix (node
->die
);
6888 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6889 &comdat_symbol_number
);
6890 assign_symbol_names (node
->die
);
6892 *pnode
= node
->next
;
6895 pnode
= &node
->next
;
6896 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6897 comdat_symbol_number
);
6900 htab_delete (cu_hash_table
);
6903 /* Return non-zero if this DIE is a declaration. */
6906 is_declaration_die (dw_die_ref die
)
6911 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6912 if (a
->dw_attr
== DW_AT_declaration
)
6918 /* Return non-zero if this DIE is nested inside a subprogram. */
6921 is_nested_in_subprogram (dw_die_ref die
)
6923 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6927 return local_scope_p (decl
);
6930 /* Return non-zero if this DIE contains a defining declaration of a
6934 contains_subprogram_definition (dw_die_ref die
)
6938 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6940 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition(c
)) return 1);
6944 /* Return non-zero if this is a type DIE that should be moved to a
6945 COMDAT .debug_types section. */
6948 should_move_die_to_comdat (dw_die_ref die
)
6950 switch (die
->die_tag
)
6952 case DW_TAG_class_type
:
6953 case DW_TAG_structure_type
:
6954 case DW_TAG_enumeration_type
:
6955 case DW_TAG_union_type
:
6956 /* Don't move declarations, inlined instances, or types nested in a
6958 if (is_declaration_die (die
)
6959 || get_AT (die
, DW_AT_abstract_origin
)
6960 || is_nested_in_subprogram (die
))
6962 /* A type definition should never contain a subprogram definition. */
6963 gcc_assert (!contains_subprogram_definition (die
));
6965 case DW_TAG_array_type
:
6966 case DW_TAG_interface_type
:
6967 case DW_TAG_pointer_type
:
6968 case DW_TAG_reference_type
:
6969 case DW_TAG_rvalue_reference_type
:
6970 case DW_TAG_string_type
:
6971 case DW_TAG_subroutine_type
:
6972 case DW_TAG_ptr_to_member_type
:
6973 case DW_TAG_set_type
:
6974 case DW_TAG_subrange_type
:
6975 case DW_TAG_base_type
:
6976 case DW_TAG_const_type
:
6977 case DW_TAG_file_type
:
6978 case DW_TAG_packed_type
:
6979 case DW_TAG_volatile_type
:
6980 case DW_TAG_typedef
:
6986 /* Make a clone of DIE. */
6989 clone_die (dw_die_ref die
)
6995 clone
= ggc_alloc_cleared_die_node ();
6996 clone
->die_tag
= die
->die_tag
;
6998 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6999 add_dwarf_attr (clone
, a
);
7004 /* Make a clone of the tree rooted at DIE. */
7007 clone_tree (dw_die_ref die
)
7010 dw_die_ref clone
= clone_die (die
);
7012 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree(c
)));
7017 /* Make a clone of DIE as a declaration. */
7020 clone_as_declaration (dw_die_ref die
)
7027 /* If the DIE is already a declaration, just clone it. */
7028 if (is_declaration_die (die
))
7029 return clone_die (die
);
7031 /* If the DIE is a specification, just clone its declaration DIE. */
7032 decl
= get_AT_ref (die
, DW_AT_specification
);
7034 return clone_die (decl
);
7036 clone
= ggc_alloc_cleared_die_node ();
7037 clone
->die_tag
= die
->die_tag
;
7039 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7041 /* We don't want to copy over all attributes.
7042 For example we don't want DW_AT_byte_size because otherwise we will no
7043 longer have a declaration and GDB will treat it as a definition. */
7047 case DW_AT_artificial
:
7048 case DW_AT_containing_type
:
7049 case DW_AT_external
:
7052 case DW_AT_virtuality
:
7053 case DW_AT_linkage_name
:
7054 case DW_AT_MIPS_linkage_name
:
7055 add_dwarf_attr (clone
, a
);
7057 case DW_AT_byte_size
:
7063 if (die
->die_id
.die_type_node
)
7064 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7066 add_AT_flag (clone
, DW_AT_declaration
, 1);
7070 /* Copy the declaration context to the new type unit DIE. This includes
7071 any surrounding namespace or type declarations. If the DIE has an
7072 AT_specification attribute, it also includes attributes and children
7073 attached to the specification, and returns a pointer to the original
7074 parent of the declaration DIE. Returns NULL otherwise. */
7077 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7080 dw_die_ref new_decl
;
7081 dw_die_ref orig_parent
= NULL
;
7083 decl
= get_AT_ref (die
, DW_AT_specification
);
7092 /* The original DIE will be changed to a declaration, and must
7093 be moved to be a child of the original declaration DIE. */
7094 orig_parent
= decl
->die_parent
;
7096 /* Copy the type node pointer from the new DIE to the original
7097 declaration DIE so we can forward references later. */
7098 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7100 remove_AT (die
, DW_AT_specification
);
7102 FOR_EACH_VEC_ELT (dw_attr_node
, decl
->die_attr
, ix
, a
)
7104 if (a
->dw_attr
!= DW_AT_name
7105 && a
->dw_attr
!= DW_AT_declaration
7106 && a
->dw_attr
!= DW_AT_external
)
7107 add_dwarf_attr (die
, a
);
7110 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree(c
)));
7113 if (decl
->die_parent
!= NULL
7114 && decl
->die_parent
->die_tag
!= DW_TAG_compile_unit
7115 && decl
->die_parent
->die_tag
!= DW_TAG_type_unit
)
7117 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
7118 if (new_decl
!= NULL
)
7120 remove_AT (new_decl
, DW_AT_signature
);
7121 add_AT_specification (die
, new_decl
);
7128 /* Generate the skeleton ancestor tree for the given NODE, then clone
7129 the DIE and add the clone into the tree. */
7132 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7134 if (node
->new_die
!= NULL
)
7137 node
->new_die
= clone_as_declaration (node
->old_die
);
7139 if (node
->parent
!= NULL
)
7141 generate_skeleton_ancestor_tree (node
->parent
);
7142 add_child_die (node
->parent
->new_die
, node
->new_die
);
7146 /* Generate a skeleton tree of DIEs containing any declarations that are
7147 found in the original tree. We traverse the tree looking for declaration
7148 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7151 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7153 skeleton_chain_node node
;
7156 dw_die_ref prev
= NULL
;
7157 dw_die_ref next
= NULL
;
7159 node
.parent
= parent
;
7161 first
= c
= parent
->old_die
->die_child
;
7165 if (prev
== NULL
|| prev
->die_sib
== c
)
7168 next
= (c
== first
? NULL
: c
->die_sib
);
7170 node
.new_die
= NULL
;
7171 if (is_declaration_die (c
))
7173 /* Clone the existing DIE, move the original to the skeleton
7174 tree (which is in the main CU), and put the clone, with
7175 all the original's children, where the original came from. */
7176 dw_die_ref clone
= clone_die (c
);
7177 move_all_children (c
, clone
);
7179 replace_child (c
, clone
, prev
);
7180 generate_skeleton_ancestor_tree (parent
);
7181 add_child_die (parent
->new_die
, c
);
7185 generate_skeleton_bottom_up (&node
);
7186 } while (next
!= NULL
);
7189 /* Wrapper function for generate_skeleton_bottom_up. */
7192 generate_skeleton (dw_die_ref die
)
7194 skeleton_chain_node node
;
7197 node
.new_die
= NULL
;
7200 /* If this type definition is nested inside another type,
7201 always leave at least a declaration in its place. */
7202 if (die
->die_parent
!= NULL
&& is_type_die (die
->die_parent
))
7203 node
.new_die
= clone_as_declaration (die
);
7205 generate_skeleton_bottom_up (&node
);
7206 return node
.new_die
;
7209 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7210 declaration. The original DIE is moved to a new compile unit so that
7211 existing references to it follow it to the new location. If any of the
7212 original DIE's descendants is a declaration, we need to replace the
7213 original DIE with a skeleton tree and move the declarations back into the
7217 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7220 dw_die_ref skeleton
, orig_parent
;
7222 /* Copy the declaration context to the type unit DIE. If the returned
7223 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7225 orig_parent
= copy_declaration_context (unit
, child
);
7227 skeleton
= generate_skeleton (child
);
7228 if (skeleton
== NULL
)
7229 remove_child_with_prev (child
, prev
);
7232 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7234 /* If the original DIE was a specification, we need to put
7235 the skeleton under the parent DIE of the declaration.
7236 This leaves the original declaration in the tree, but
7237 it will be pruned later since there are no longer any
7238 references to it. */
7239 if (orig_parent
!= NULL
)
7241 remove_child_with_prev (child
, prev
);
7242 add_child_die (orig_parent
, skeleton
);
7245 replace_child (child
, skeleton
, prev
);
7251 /* Traverse the DIE and set up additional .debug_types sections for each
7252 type worthy of being placed in a COMDAT section. */
7255 break_out_comdat_types (dw_die_ref die
)
7259 dw_die_ref prev
= NULL
;
7260 dw_die_ref next
= NULL
;
7261 dw_die_ref unit
= NULL
;
7263 first
= c
= die
->die_child
;
7267 if (prev
== NULL
|| prev
->die_sib
== c
)
7270 next
= (c
== first
? NULL
: c
->die_sib
);
7271 if (should_move_die_to_comdat (c
))
7273 dw_die_ref replacement
;
7274 comdat_type_node_ref type_node
;
7276 /* Create a new type unit DIE as the root for the new tree, and
7277 add it to the list of comdat types. */
7278 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7279 add_AT_unsigned (unit
, DW_AT_language
,
7280 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7281 type_node
= ggc_alloc_cleared_comdat_type_node ();
7282 type_node
->root_die
= unit
;
7283 type_node
->next
= comdat_type_list
;
7284 comdat_type_list
= type_node
;
7286 /* Generate the type signature. */
7287 generate_type_signature (c
, type_node
);
7289 /* Copy the declaration context, attributes, and children of the
7290 declaration into the new type unit DIE, then remove this DIE
7291 from the main CU (or replace it with a skeleton if necessary). */
7292 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7294 /* Break out nested types into their own type units. */
7295 break_out_comdat_types (c
);
7297 /* Add the DIE to the new compunit. */
7298 add_child_die (unit
, c
);
7300 if (replacement
!= NULL
)
7303 else if (c
->die_tag
== DW_TAG_namespace
7304 || c
->die_tag
== DW_TAG_class_type
7305 || c
->die_tag
== DW_TAG_structure_type
7306 || c
->die_tag
== DW_TAG_union_type
)
7308 /* Look for nested types that can be broken out. */
7309 break_out_comdat_types (c
);
7311 } while (next
!= NULL
);
7314 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7316 struct decl_table_entry
7322 /* Routines to manipulate hash table of copied declarations. */
7325 htab_decl_hash (const void *of
)
7327 const struct decl_table_entry
*const entry
=
7328 (const struct decl_table_entry
*) of
;
7330 return htab_hash_pointer (entry
->orig
);
7334 htab_decl_eq (const void *of1
, const void *of2
)
7336 const struct decl_table_entry
*const entry1
=
7337 (const struct decl_table_entry
*) of1
;
7338 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
7340 return entry1
->orig
== entry2
;
7344 htab_decl_del (void *what
)
7346 struct decl_table_entry
*entry
= (struct decl_table_entry
*) what
;
7351 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7352 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7353 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7354 to check if the ancestor has already been copied into UNIT. */
7357 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
7359 dw_die_ref parent
= die
->die_parent
;
7360 dw_die_ref new_parent
= unit
;
7363 struct decl_table_entry
*entry
= NULL
;
7367 /* Check if the entry has already been copied to UNIT. */
7368 slot
= htab_find_slot_with_hash (decl_table
, die
,
7369 htab_hash_pointer (die
), INSERT
);
7370 if (*slot
!= HTAB_EMPTY_ENTRY
)
7372 entry
= (struct decl_table_entry
*) *slot
;
7376 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7377 entry
= XCNEW (struct decl_table_entry
);
7385 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7388 if (parent
->die_tag
!= DW_TAG_compile_unit
7389 && parent
->die_tag
!= DW_TAG_type_unit
)
7390 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7393 copy
= clone_as_declaration (die
);
7394 add_child_die (new_parent
, copy
);
7396 if (decl_table
!= NULL
)
7398 /* Record the pointer to the copy. */
7405 /* Like clone_tree, but additionally enter all the children into
7406 the hash table decl_table. */
7409 clone_tree_hash (dw_die_ref die
, htab_t decl_table
)
7412 dw_die_ref clone
= clone_die (die
);
7413 struct decl_table_entry
*entry
;
7414 void **slot
= htab_find_slot_with_hash (decl_table
, die
,
7415 htab_hash_pointer (die
), INSERT
);
7416 /* Assert that DIE isn't in the hash table yet. If it would be there
7417 before, the ancestors would be necessarily there as well, therefore
7418 clone_tree_hash wouldn't be called. */
7419 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7420 entry
= XCNEW (struct decl_table_entry
);
7422 entry
->copy
= clone
;
7425 FOR_EACH_CHILD (die
, c
,
7426 add_child_die (clone
, clone_tree_hash (c
, decl_table
)));
7431 /* Walk the DIE and its children, looking for references to incomplete
7432 or trivial types that are unmarked (i.e., that are not in the current
7436 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
7442 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7444 if (AT_class (a
) == dw_val_class_die_ref
)
7446 dw_die_ref targ
= AT_ref (a
);
7447 comdat_type_node_ref type_node
= targ
->die_id
.die_type_node
;
7449 struct decl_table_entry
*entry
;
7451 if (targ
->die_mark
!= 0 || type_node
!= NULL
)
7454 slot
= htab_find_slot_with_hash (decl_table
, targ
,
7455 htab_hash_pointer (targ
), INSERT
);
7457 if (*slot
!= HTAB_EMPTY_ENTRY
)
7459 /* TARG has already been copied, so we just need to
7460 modify the reference to point to the copy. */
7461 entry
= (struct decl_table_entry
*) *slot
;
7462 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7466 dw_die_ref parent
= unit
;
7467 dw_die_ref copy
= clone_die (targ
);
7469 /* Record in DECL_TABLE that TARG has been copied.
7470 Need to do this now, before the recursive call,
7471 because DECL_TABLE may be expanded and SLOT
7472 would no longer be a valid pointer. */
7473 entry
= XCNEW (struct decl_table_entry
);
7478 FOR_EACH_CHILD (targ
, c
,
7479 add_child_die (copy
,
7480 clone_tree_hash (c
, decl_table
)));
7482 /* Make sure the cloned tree is marked as part of the
7486 /* If TARG has surrounding context, copy its ancestor tree
7487 into the new type unit. */
7488 if (targ
->die_parent
!= NULL
7489 && targ
->die_parent
->die_tag
!= DW_TAG_compile_unit
7490 && targ
->die_parent
->die_tag
!= DW_TAG_type_unit
)
7491 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7494 add_child_die (parent
, copy
);
7495 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7497 /* Make sure the newly-copied DIE is walked. If it was
7498 installed in a previously-added context, it won't
7499 get visited otherwise. */
7502 /* Find the highest point of the newly-added tree,
7503 mark each node along the way, and walk from there. */
7504 parent
->die_mark
= 1;
7505 while (parent
->die_parent
7506 && parent
->die_parent
->die_mark
== 0)
7508 parent
= parent
->die_parent
;
7509 parent
->die_mark
= 1;
7511 copy_decls_walk (unit
, parent
, decl_table
);
7517 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7520 /* Copy declarations for "unworthy" types into the new comdat section.
7521 Incomplete types, modified types, and certain other types aren't broken
7522 out into comdat sections of their own, so they don't have a signature,
7523 and we need to copy the declaration into the same section so that we
7524 don't have an external reference. */
7527 copy_decls_for_unworthy_types (dw_die_ref unit
)
7532 decl_table
= htab_create (10, htab_decl_hash
, htab_decl_eq
, htab_decl_del
);
7533 copy_decls_walk (unit
, unit
, decl_table
);
7534 htab_delete (decl_table
);
7538 /* Traverse the DIE and add a sibling attribute if it may have the
7539 effect of speeding up access to siblings. To save some space,
7540 avoid generating sibling attributes for DIE's without children. */
7543 add_sibling_attributes (dw_die_ref die
)
7547 if (! die
->die_child
)
7550 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7551 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7553 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7556 /* Output all location lists for the DIE and its children. */
7559 output_location_lists (dw_die_ref die
)
7565 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7566 if (AT_class (a
) == dw_val_class_loc_list
)
7567 output_loc_list (AT_loc_list (a
));
7569 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7572 /* The format of each DIE (and its attribute value pairs) is encoded in an
7573 abbreviation table. This routine builds the abbreviation table and assigns
7574 a unique abbreviation id for each abbreviation entry. The children of each
7575 die are visited recursively. */
7578 build_abbrev_table (dw_die_ref die
)
7580 unsigned long abbrev_id
;
7581 unsigned int n_alloc
;
7586 /* Scan the DIE references, and mark as external any that refer to
7587 DIEs from other CUs (i.e. those which are not marked). */
7588 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7589 if (AT_class (a
) == dw_val_class_die_ref
7590 && AT_ref (a
)->die_mark
== 0)
7592 gcc_assert (use_debug_types
|| AT_ref (a
)->die_id
.die_symbol
);
7593 set_AT_ref_external (a
, 1);
7596 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7598 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7599 dw_attr_ref die_a
, abbrev_a
;
7603 if (abbrev
->die_tag
!= die
->die_tag
)
7605 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7608 if (VEC_length (dw_attr_node
, abbrev
->die_attr
)
7609 != VEC_length (dw_attr_node
, die
->die_attr
))
7612 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, die_a
)
7614 abbrev_a
= VEC_index (dw_attr_node
, abbrev
->die_attr
, ix
);
7615 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7616 || (value_format (abbrev_a
) != value_format (die_a
)))
7626 if (abbrev_id
>= abbrev_die_table_in_use
)
7628 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7630 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7631 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7634 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7635 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7636 abbrev_die_table_allocated
= n_alloc
;
7639 ++abbrev_die_table_in_use
;
7640 abbrev_die_table
[abbrev_id
] = die
;
7643 die
->die_abbrev
= abbrev_id
;
7644 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
));
7647 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7650 constant_size (unsigned HOST_WIDE_INT value
)
7657 log
= floor_log2 (value
);
7660 log
= 1 << (floor_log2 (log
) + 1);
7665 /* Return the size of a DIE as it is represented in the
7666 .debug_info section. */
7668 static unsigned long
7669 size_of_die (dw_die_ref die
)
7671 unsigned long size
= 0;
7675 size
+= size_of_uleb128 (die
->die_abbrev
);
7676 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7678 switch (AT_class (a
))
7680 case dw_val_class_addr
:
7681 size
+= DWARF2_ADDR_SIZE
;
7683 case dw_val_class_offset
:
7684 size
+= DWARF_OFFSET_SIZE
;
7686 case dw_val_class_loc
:
7688 unsigned long lsize
= size_of_locs (AT_loc (a
));
7691 if (dwarf_version
>= 4)
7692 size
+= size_of_uleb128 (lsize
);
7694 size
+= constant_size (lsize
);
7698 case dw_val_class_loc_list
:
7699 size
+= DWARF_OFFSET_SIZE
;
7701 case dw_val_class_range_list
:
7702 size
+= DWARF_OFFSET_SIZE
;
7704 case dw_val_class_const
:
7705 size
+= size_of_sleb128 (AT_int (a
));
7707 case dw_val_class_unsigned_const
:
7709 int csize
= constant_size (AT_unsigned (a
));
7710 if (dwarf_version
== 3
7711 && a
->dw_attr
== DW_AT_data_member_location
7713 size
+= size_of_uleb128 (AT_unsigned (a
));
7718 case dw_val_class_const_double
:
7719 size
+= 2 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
7720 if (HOST_BITS_PER_WIDE_INT
>= 64)
7723 case dw_val_class_vec
:
7724 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7725 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7726 + a
->dw_attr_val
.v
.val_vec
.length
7727 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7729 case dw_val_class_flag
:
7730 if (dwarf_version
>= 4)
7731 /* Currently all add_AT_flag calls pass in 1 as last argument,
7732 so DW_FORM_flag_present can be used. If that ever changes,
7733 we'll need to use DW_FORM_flag and have some optimization
7734 in build_abbrev_table that will change those to
7735 DW_FORM_flag_present if it is set to 1 in all DIEs using
7736 the same abbrev entry. */
7737 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7741 case dw_val_class_die_ref
:
7742 if (AT_ref_external (a
))
7744 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7745 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7746 is sized by target address length, whereas in DWARF3
7747 it's always sized as an offset. */
7748 if (use_debug_types
)
7749 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7750 else if (dwarf_version
== 2)
7751 size
+= DWARF2_ADDR_SIZE
;
7753 size
+= DWARF_OFFSET_SIZE
;
7756 size
+= DWARF_OFFSET_SIZE
;
7758 case dw_val_class_fde_ref
:
7759 size
+= DWARF_OFFSET_SIZE
;
7761 case dw_val_class_lbl_id
:
7762 size
+= DWARF2_ADDR_SIZE
;
7764 case dw_val_class_lineptr
:
7765 case dw_val_class_macptr
:
7766 size
+= DWARF_OFFSET_SIZE
;
7768 case dw_val_class_str
:
7769 if (AT_string_form (a
) == DW_FORM_strp
)
7770 size
+= DWARF_OFFSET_SIZE
;
7772 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7774 case dw_val_class_file
:
7775 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7777 case dw_val_class_data8
:
7780 case dw_val_class_vms_delta
:
7781 size
+= DWARF_OFFSET_SIZE
;
7791 /* Size the debugging information associated with a given DIE. Visits the
7792 DIE's children recursively. Updates the global variable next_die_offset, on
7793 each time through. Uses the current value of next_die_offset to update the
7794 die_offset field in each DIE. */
7797 calc_die_sizes (dw_die_ref die
)
7801 gcc_assert (die
->die_offset
== 0
7802 || (unsigned long int) die
->die_offset
== next_die_offset
);
7803 die
->die_offset
= next_die_offset
;
7804 next_die_offset
+= size_of_die (die
);
7806 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7808 if (die
->die_child
!= NULL
)
7809 /* Count the null byte used to terminate sibling lists. */
7810 next_die_offset
+= 1;
7813 /* Size just the base type children at the start of the CU.
7814 This is needed because build_abbrev needs to size locs
7815 and sizing of type based stack ops needs to know die_offset
7816 values for the base types. */
7819 calc_base_type_die_sizes (void)
7821 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7823 dw_die_ref base_type
;
7824 #if ENABLE_ASSERT_CHECKING
7825 dw_die_ref prev
= comp_unit_die ()->die_child
;
7828 die_offset
+= size_of_die (comp_unit_die ());
7829 for (i
= 0; VEC_iterate (dw_die_ref
, base_types
, i
, base_type
); i
++)
7831 #if ENABLE_ASSERT_CHECKING
7832 gcc_assert (base_type
->die_offset
== 0
7833 && prev
->die_sib
== base_type
7834 && base_type
->die_child
== NULL
7835 && base_type
->die_abbrev
);
7838 base_type
->die_offset
= die_offset
;
7839 die_offset
+= size_of_die (base_type
);
7843 /* Set the marks for a die and its children. We do this so
7844 that we know whether or not a reference needs to use FORM_ref_addr; only
7845 DIEs in the same CU will be marked. We used to clear out the offset
7846 and use that as the flag, but ran into ordering problems. */
7849 mark_dies (dw_die_ref die
)
7853 gcc_assert (!die
->die_mark
);
7856 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7859 /* Clear the marks for a die and its children. */
7862 unmark_dies (dw_die_ref die
)
7866 if (! use_debug_types
)
7867 gcc_assert (die
->die_mark
);
7870 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7873 /* Clear the marks for a die, its children and referred dies. */
7876 unmark_all_dies (dw_die_ref die
)
7886 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7888 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7889 if (AT_class (a
) == dw_val_class_die_ref
)
7890 unmark_all_dies (AT_ref (a
));
7893 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7894 generated for the compilation unit. */
7896 static unsigned long
7897 size_of_pubnames (VEC (pubname_entry
, gc
) * names
)
7903 size
= DWARF_PUBNAMES_HEADER_SIZE
;
7904 FOR_EACH_VEC_ELT (pubname_entry
, names
, i
, p
)
7905 if (names
!= pubtype_table
7906 || p
->die
->die_offset
!= 0
7907 || !flag_eliminate_unused_debug_types
)
7908 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
7910 size
+= DWARF_OFFSET_SIZE
;
7914 /* Return the size of the information in the .debug_aranges section. */
7916 static unsigned long
7917 size_of_aranges (void)
7921 size
= DWARF_ARANGES_HEADER_SIZE
;
7923 /* Count the address/length pair for this compilation unit. */
7924 if (text_section_used
)
7925 size
+= 2 * DWARF2_ADDR_SIZE
;
7926 if (cold_text_section_used
)
7927 size
+= 2 * DWARF2_ADDR_SIZE
;
7928 if (have_multiple_function_sections
)
7933 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, fde_idx
, fde
)
7935 if (!fde
->in_std_section
)
7936 size
+= 2 * DWARF2_ADDR_SIZE
;
7937 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
7938 size
+= 2 * DWARF2_ADDR_SIZE
;
7942 /* Count the two zero words used to terminated the address range table. */
7943 size
+= 2 * DWARF2_ADDR_SIZE
;
7947 /* Select the encoding of an attribute value. */
7949 static enum dwarf_form
7950 value_format (dw_attr_ref a
)
7952 switch (a
->dw_attr_val
.val_class
)
7954 case dw_val_class_addr
:
7955 /* Only very few attributes allow DW_FORM_addr. */
7960 case DW_AT_entry_pc
:
7961 case DW_AT_trampoline
:
7962 return DW_FORM_addr
;
7966 switch (DWARF2_ADDR_SIZE
)
7969 return DW_FORM_data1
;
7971 return DW_FORM_data2
;
7973 return DW_FORM_data4
;
7975 return DW_FORM_data8
;
7979 case dw_val_class_range_list
:
7980 case dw_val_class_loc_list
:
7981 if (dwarf_version
>= 4)
7982 return DW_FORM_sec_offset
;
7984 case dw_val_class_vms_delta
:
7985 case dw_val_class_offset
:
7986 switch (DWARF_OFFSET_SIZE
)
7989 return DW_FORM_data4
;
7991 return DW_FORM_data8
;
7995 case dw_val_class_loc
:
7996 if (dwarf_version
>= 4)
7997 return DW_FORM_exprloc
;
7998 switch (constant_size (size_of_locs (AT_loc (a
))))
8001 return DW_FORM_block1
;
8003 return DW_FORM_block2
;
8007 case dw_val_class_const
:
8008 return DW_FORM_sdata
;
8009 case dw_val_class_unsigned_const
:
8010 switch (constant_size (AT_unsigned (a
)))
8013 return DW_FORM_data1
;
8015 return DW_FORM_data2
;
8017 /* In DWARF3 DW_AT_data_member_location with
8018 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8019 constant, so we need to use DW_FORM_udata if we need
8020 a large constant. */
8021 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8022 return DW_FORM_udata
;
8023 return DW_FORM_data4
;
8025 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8026 return DW_FORM_udata
;
8027 return DW_FORM_data8
;
8031 case dw_val_class_const_double
:
8032 switch (HOST_BITS_PER_WIDE_INT
)
8035 return DW_FORM_data2
;
8037 return DW_FORM_data4
;
8039 return DW_FORM_data8
;
8042 return DW_FORM_block1
;
8044 case dw_val_class_vec
:
8045 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8046 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8049 return DW_FORM_block1
;
8051 return DW_FORM_block2
;
8053 return DW_FORM_block4
;
8057 case dw_val_class_flag
:
8058 if (dwarf_version
>= 4)
8060 /* Currently all add_AT_flag calls pass in 1 as last argument,
8061 so DW_FORM_flag_present can be used. If that ever changes,
8062 we'll need to use DW_FORM_flag and have some optimization
8063 in build_abbrev_table that will change those to
8064 DW_FORM_flag_present if it is set to 1 in all DIEs using
8065 the same abbrev entry. */
8066 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8067 return DW_FORM_flag_present
;
8069 return DW_FORM_flag
;
8070 case dw_val_class_die_ref
:
8071 if (AT_ref_external (a
))
8072 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8075 case dw_val_class_fde_ref
:
8076 return DW_FORM_data
;
8077 case dw_val_class_lbl_id
:
8078 return DW_FORM_addr
;
8079 case dw_val_class_lineptr
:
8080 case dw_val_class_macptr
:
8081 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8082 case dw_val_class_str
:
8083 return AT_string_form (a
);
8084 case dw_val_class_file
:
8085 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8088 return DW_FORM_data1
;
8090 return DW_FORM_data2
;
8092 return DW_FORM_data4
;
8097 case dw_val_class_data8
:
8098 return DW_FORM_data8
;
8105 /* Output the encoding of an attribute value. */
8108 output_value_format (dw_attr_ref a
)
8110 enum dwarf_form form
= value_format (a
);
8112 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8115 /* Output the .debug_abbrev section which defines the DIE abbreviation
8119 output_abbrev_section (void)
8121 unsigned long abbrev_id
;
8123 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8125 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
8129 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8130 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8131 dwarf_tag_name (abbrev
->die_tag
));
8133 if (abbrev
->die_child
!= NULL
)
8134 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8136 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8138 for (ix
= 0; VEC_iterate (dw_attr_node
, abbrev
->die_attr
, ix
, a_attr
);
8141 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8142 dwarf_attr_name (a_attr
->dw_attr
));
8143 output_value_format (a_attr
);
8146 dw2_asm_output_data (1, 0, NULL
);
8147 dw2_asm_output_data (1, 0, NULL
);
8150 /* Terminate the table. */
8151 dw2_asm_output_data (1, 0, NULL
);
8154 /* Output a symbol we can use to refer to this DIE from another CU. */
8157 output_die_symbol (dw_die_ref die
)
8159 char *sym
= die
->die_id
.die_symbol
;
8164 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8165 /* We make these global, not weak; if the target doesn't support
8166 .linkonce, it doesn't support combining the sections, so debugging
8168 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8170 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8173 /* Return a new location list, given the begin and end range, and the
8176 static inline dw_loc_list_ref
8177 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8178 const char *section
)
8180 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
8182 retlist
->begin
= begin
;
8184 retlist
->expr
= expr
;
8185 retlist
->section
= section
;
8190 /* Generate a new internal symbol for this location list node, if it
8191 hasn't got one yet. */
8194 gen_llsym (dw_loc_list_ref list
)
8196 gcc_assert (!list
->ll_symbol
);
8197 list
->ll_symbol
= gen_internal_sym ("LLST");
8200 /* Output the location list given to us. */
8203 output_loc_list (dw_loc_list_ref list_head
)
8205 dw_loc_list_ref curr
= list_head
;
8207 if (list_head
->emitted
)
8209 list_head
->emitted
= true;
8211 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8213 /* Walk the location list, and output each range + expression. */
8214 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8217 /* Don't output an entry that starts and ends at the same address. */
8218 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8220 size
= size_of_locs (curr
->expr
);
8221 /* If the expression is too large, drop it on the floor. We could
8222 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8223 in the expression, but >= 64KB expressions for a single value
8224 in a single range are unlikely very useful. */
8227 if (!have_multiple_function_sections
)
8229 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8230 "Location list begin address (%s)",
8231 list_head
->ll_symbol
);
8232 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8233 "Location list end address (%s)",
8234 list_head
->ll_symbol
);
8238 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8239 "Location list begin address (%s)",
8240 list_head
->ll_symbol
);
8241 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8242 "Location list end address (%s)",
8243 list_head
->ll_symbol
);
8246 /* Output the block length for this list of location operations. */
8247 gcc_assert (size
<= 0xffff);
8248 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8250 output_loc_sequence (curr
->expr
, -1);
8253 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8254 "Location list terminator begin (%s)",
8255 list_head
->ll_symbol
);
8256 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8257 "Location list terminator end (%s)",
8258 list_head
->ll_symbol
);
8261 /* Output a type signature. */
8264 output_signature (const char *sig
, const char *name
)
8268 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8269 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8272 /* Output the DIE and its attributes. Called recursively to generate
8273 the definitions of each child DIE. */
8276 output_die (dw_die_ref die
)
8283 /* If someone in another CU might refer to us, set up a symbol for
8284 them to point to. */
8285 if (! use_debug_types
&& die
->die_id
.die_symbol
)
8286 output_die_symbol (die
);
8288 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8289 (unsigned long)die
->die_offset
,
8290 dwarf_tag_name (die
->die_tag
));
8292 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
8294 const char *name
= dwarf_attr_name (a
->dw_attr
);
8296 switch (AT_class (a
))
8298 case dw_val_class_addr
:
8299 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8302 case dw_val_class_offset
:
8303 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8307 case dw_val_class_range_list
:
8309 char *p
= strchr (ranges_section_label
, '\0');
8311 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
8312 a
->dw_attr_val
.v
.val_offset
);
8313 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8314 debug_ranges_section
, "%s", name
);
8319 case dw_val_class_loc
:
8320 size
= size_of_locs (AT_loc (a
));
8322 /* Output the block length for this list of location operations. */
8323 if (dwarf_version
>= 4)
8324 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8326 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8328 output_loc_sequence (AT_loc (a
), -1);
8331 case dw_val_class_const
:
8332 /* ??? It would be slightly more efficient to use a scheme like is
8333 used for unsigned constants below, but gdb 4.x does not sign
8334 extend. Gdb 5.x does sign extend. */
8335 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8338 case dw_val_class_unsigned_const
:
8340 int csize
= constant_size (AT_unsigned (a
));
8341 if (dwarf_version
== 3
8342 && a
->dw_attr
== DW_AT_data_member_location
8344 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8346 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8350 case dw_val_class_const_double
:
8352 unsigned HOST_WIDE_INT first
, second
;
8354 if (HOST_BITS_PER_WIDE_INT
>= 64)
8355 dw2_asm_output_data (1,
8356 2 * HOST_BITS_PER_WIDE_INT
8357 / HOST_BITS_PER_CHAR
,
8360 if (WORDS_BIG_ENDIAN
)
8362 first
= a
->dw_attr_val
.v
.val_double
.high
;
8363 second
= a
->dw_attr_val
.v
.val_double
.low
;
8367 first
= a
->dw_attr_val
.v
.val_double
.low
;
8368 second
= a
->dw_attr_val
.v
.val_double
.high
;
8371 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8373 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8378 case dw_val_class_vec
:
8380 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8381 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8385 dw2_asm_output_data (constant_size (len
* elt_size
),
8386 len
* elt_size
, "%s", name
);
8387 if (elt_size
> sizeof (HOST_WIDE_INT
))
8392 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8395 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8396 "fp or vector constant word %u", i
);
8400 case dw_val_class_flag
:
8401 if (dwarf_version
>= 4)
8403 /* Currently all add_AT_flag calls pass in 1 as last argument,
8404 so DW_FORM_flag_present can be used. If that ever changes,
8405 we'll need to use DW_FORM_flag and have some optimization
8406 in build_abbrev_table that will change those to
8407 DW_FORM_flag_present if it is set to 1 in all DIEs using
8408 the same abbrev entry. */
8409 gcc_assert (AT_flag (a
) == 1);
8411 fprintf (asm_out_file
, "\t\t\t%s %s\n",
8412 ASM_COMMENT_START
, name
);
8415 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8418 case dw_val_class_loc_list
:
8420 char *sym
= AT_loc_list (a
)->ll_symbol
;
8423 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8428 case dw_val_class_die_ref
:
8429 if (AT_ref_external (a
))
8431 if (use_debug_types
)
8433 comdat_type_node_ref type_node
=
8434 AT_ref (a
)->die_id
.die_type_node
;
8436 gcc_assert (type_node
);
8437 output_signature (type_node
->signature
, name
);
8441 char *sym
= AT_ref (a
)->die_id
.die_symbol
;
8445 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8446 length, whereas in DWARF3 it's always sized as an
8448 if (dwarf_version
== 2)
8449 size
= DWARF2_ADDR_SIZE
;
8451 size
= DWARF_OFFSET_SIZE
;
8452 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
8458 gcc_assert (AT_ref (a
)->die_offset
);
8459 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8464 case dw_val_class_fde_ref
:
8468 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8469 a
->dw_attr_val
.v
.val_fde_index
* 2);
8470 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8475 case dw_val_class_vms_delta
:
8476 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
8477 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
8481 case dw_val_class_lbl_id
:
8482 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8485 case dw_val_class_lineptr
:
8486 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8487 debug_line_section
, "%s", name
);
8490 case dw_val_class_macptr
:
8491 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8492 debug_macinfo_section
, "%s", name
);
8495 case dw_val_class_str
:
8496 if (AT_string_form (a
) == DW_FORM_strp
)
8497 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8498 a
->dw_attr_val
.v
.val_str
->label
,
8500 "%s: \"%s\"", name
, AT_string (a
));
8502 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8505 case dw_val_class_file
:
8507 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8509 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8510 a
->dw_attr_val
.v
.val_file
->filename
);
8514 case dw_val_class_data8
:
8518 for (i
= 0; i
< 8; i
++)
8519 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8520 i
== 0 ? "%s" : NULL
, name
);
8529 FOR_EACH_CHILD (die
, c
, output_die (c
));
8531 /* Add null byte to terminate sibling list. */
8532 if (die
->die_child
!= NULL
)
8533 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8534 (unsigned long) die
->die_offset
);
8537 /* Output the compilation unit that appears at the beginning of the
8538 .debug_info section, and precedes the DIE descriptions. */
8541 output_compilation_unit_header (void)
8543 int ver
= dwarf_version
;
8545 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8546 dw2_asm_output_data (4, 0xffffffff,
8547 "Initial length escape value indicating 64-bit DWARF extension");
8548 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8549 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8550 "Length of Compilation Unit Info");
8551 dw2_asm_output_data (2, ver
, "DWARF version number");
8552 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8553 debug_abbrev_section
,
8554 "Offset Into Abbrev. Section");
8555 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8558 /* Output the compilation unit DIE and its children. */
8561 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8563 const char *secname
;
8566 /* Unless we are outputting main CU, we may throw away empty ones. */
8567 if (!output_if_empty
&& die
->die_child
== NULL
)
8570 /* Even if there are no children of this DIE, we must output the information
8571 about the compilation unit. Otherwise, on an empty translation unit, we
8572 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8573 will then complain when examining the file. First mark all the DIEs in
8574 this CU so we know which get local refs. */
8577 build_abbrev_table (die
);
8579 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8580 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8581 calc_die_sizes (die
);
8583 oldsym
= die
->die_id
.die_symbol
;
8586 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8588 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8590 die
->die_id
.die_symbol
= NULL
;
8591 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8595 switch_to_section (debug_info_section
);
8596 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8597 info_section_emitted
= true;
8600 /* Output debugging information. */
8601 output_compilation_unit_header ();
8604 /* Leave the marks on the main CU, so we can check them in
8609 die
->die_id
.die_symbol
= oldsym
;
8613 /* Output a comdat type unit DIE and its children. */
8616 output_comdat_type_unit (comdat_type_node
*node
)
8618 const char *secname
;
8621 #if defined (OBJECT_FORMAT_ELF)
8625 /* First mark all the DIEs in this CU so we know which get local refs. */
8626 mark_dies (node
->root_die
);
8628 build_abbrev_table (node
->root_die
);
8630 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8631 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
8632 calc_die_sizes (node
->root_die
);
8634 #if defined (OBJECT_FORMAT_ELF)
8635 secname
= ".debug_types";
8636 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8637 sprintf (tmp
, "wt.");
8638 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8639 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8640 comdat_key
= get_identifier (tmp
);
8641 targetm
.asm_out
.named_section (secname
,
8642 SECTION_DEBUG
| SECTION_LINKONCE
,
8645 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8646 sprintf (tmp
, ".gnu.linkonce.wt.");
8647 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8648 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8650 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8653 /* Output debugging information. */
8654 output_compilation_unit_header ();
8655 output_signature (node
->signature
, "Type Signature");
8656 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
8657 "Offset to Type DIE");
8658 output_die (node
->root_die
);
8660 unmark_dies (node
->root_die
);
8663 /* Return the DWARF2/3 pubname associated with a decl. */
8666 dwarf2_name (tree decl
, int scope
)
8668 if (DECL_NAMELESS (decl
))
8670 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
8673 /* Add a new entry to .debug_pubnames if appropriate. */
8676 add_pubname_string (const char *str
, dw_die_ref die
)
8678 if (targetm
.want_debug_pub_sections
)
8683 e
.name
= xstrdup (str
);
8684 VEC_safe_push (pubname_entry
, gc
, pubname_table
, &e
);
8689 add_pubname (tree decl
, dw_die_ref die
)
8691 if (targetm
.want_debug_pub_sections
&& TREE_PUBLIC (decl
))
8693 const char *name
= dwarf2_name (decl
, 1);
8695 add_pubname_string (name
, die
);
8699 /* Add a new entry to .debug_pubtypes if appropriate. */
8702 add_pubtype (tree decl
, dw_die_ref die
)
8706 if (!targetm
.want_debug_pub_sections
)
8710 if ((TREE_PUBLIC (decl
)
8711 || is_cu_die (die
->die_parent
))
8712 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
8717 if (TYPE_NAME (decl
))
8719 if (TREE_CODE (TYPE_NAME (decl
)) == IDENTIFIER_NODE
)
8720 e
.name
= IDENTIFIER_POINTER (TYPE_NAME (decl
));
8721 else if (TREE_CODE (TYPE_NAME (decl
)) == TYPE_DECL
8722 && DECL_NAME (TYPE_NAME (decl
)))
8723 e
.name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl
)));
8725 e
.name
= xstrdup ((const char *) get_AT_string (die
, DW_AT_name
));
8730 e
.name
= dwarf2_name (decl
, 1);
8732 e
.name
= xstrdup (e
.name
);
8735 /* If we don't have a name for the type, there's no point in adding
8737 if (e
.name
&& e
.name
[0] != '\0')
8738 VEC_safe_push (pubname_entry
, gc
, pubtype_table
, &e
);
8742 /* Output the public names table used to speed up access to externally
8743 visible names; or the public types table used to find type definitions. */
8746 output_pubnames (VEC (pubname_entry
, gc
) * names
)
8749 unsigned long pubnames_length
= size_of_pubnames (names
);
8752 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8753 dw2_asm_output_data (4, 0xffffffff,
8754 "Initial length escape value indicating 64-bit DWARF extension");
8755 if (names
== pubname_table
)
8756 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8757 "Length of Public Names Info");
8759 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8760 "Length of Public Type Names Info");
8761 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
8762 dw2_asm_output_data (2, 2, "DWARF Version");
8763 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
8765 "Offset of Compilation Unit Info");
8766 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
8767 "Compilation Unit Length");
8769 FOR_EACH_VEC_ELT (pubname_entry
, names
, i
, pub
)
8771 /* We shouldn't see pubnames for DIEs outside of the main CU. */
8772 if (names
== pubname_table
)
8773 gcc_assert (pub
->die
->die_mark
);
8775 if (names
!= pubtype_table
8776 || pub
->die
->die_offset
!= 0
8777 || !flag_eliminate_unused_debug_types
)
8779 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
8782 dw2_asm_output_nstring (pub
->name
, -1, "external name");
8786 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
8789 /* Output the information that goes into the .debug_aranges table.
8790 Namely, define the beginning and ending address range of the
8791 text section generated for this compilation unit. */
8794 output_aranges (unsigned long aranges_length
)
8798 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8799 dw2_asm_output_data (4, 0xffffffff,
8800 "Initial length escape value indicating 64-bit DWARF extension");
8801 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
8802 "Length of Address Ranges Info");
8803 /* Version number for aranges is still 2, even in DWARF3. */
8804 dw2_asm_output_data (2, 2, "DWARF Version");
8805 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
8807 "Offset of Compilation Unit Info");
8808 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
8809 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8811 /* We need to align to twice the pointer size here. */
8812 if (DWARF_ARANGES_PAD_SIZE
)
8814 /* Pad using a 2 byte words so that padding is correct for any
8816 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8817 2 * DWARF2_ADDR_SIZE
);
8818 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
8819 dw2_asm_output_data (2, 0, NULL
);
8822 /* It is necessary not to output these entries if the sections were
8823 not used; if the sections were not used, the length will be 0 and
8824 the address may end up as 0 if the section is discarded by ld
8825 --gc-sections, leaving an invalid (0, 0) entry that can be
8826 confused with the terminator. */
8827 if (text_section_used
)
8829 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
8830 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
8831 text_section_label
, "Length");
8833 if (cold_text_section_used
)
8835 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
8837 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
8838 cold_text_section_label
, "Length");
8841 if (have_multiple_function_sections
)
8846 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, fde_idx
, fde
)
8848 if (!fde
->in_std_section
)
8850 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
8852 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
8853 fde
->dw_fde_begin
, "Length");
8855 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8857 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
8859 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
8860 fde
->dw_fde_second_begin
, "Length");
8865 /* Output the terminator words. */
8866 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8867 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8870 /* Add a new entry to .debug_ranges. Return the offset at which it
8874 add_ranges_num (int num
)
8876 unsigned int in_use
= ranges_table_in_use
;
8878 if (in_use
== ranges_table_allocated
)
8880 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
8881 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
8882 ranges_table_allocated
);
8883 memset (ranges_table
+ ranges_table_in_use
, 0,
8884 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
8887 ranges_table
[in_use
].num
= num
;
8888 ranges_table_in_use
= in_use
+ 1;
8890 return in_use
* 2 * DWARF2_ADDR_SIZE
;
8893 /* Add a new entry to .debug_ranges corresponding to a block, or a
8894 range terminator if BLOCK is NULL. */
8897 add_ranges (const_tree block
)
8899 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
8902 /* Add a new entry to .debug_ranges corresponding to a pair of
8906 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
8909 unsigned int in_use
= ranges_by_label_in_use
;
8910 unsigned int offset
;
8912 if (in_use
== ranges_by_label_allocated
)
8914 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
8915 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
8917 ranges_by_label_allocated
);
8918 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
8919 RANGES_TABLE_INCREMENT
8920 * sizeof (struct dw_ranges_by_label_struct
));
8923 ranges_by_label
[in_use
].begin
= begin
;
8924 ranges_by_label
[in_use
].end
= end
;
8925 ranges_by_label_in_use
= in_use
+ 1;
8927 offset
= add_ranges_num (-(int)in_use
- 1);
8930 add_AT_range_list (die
, DW_AT_ranges
, offset
);
8936 output_ranges (void)
8939 static const char *const start_fmt
= "Offset %#x";
8940 const char *fmt
= start_fmt
;
8942 for (i
= 0; i
< ranges_table_in_use
; i
++)
8944 int block_num
= ranges_table
[i
].num
;
8948 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
8949 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
8951 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
8952 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
8954 /* If all code is in the text section, then the compilation
8955 unit base address defaults to DW_AT_low_pc, which is the
8956 base of the text section. */
8957 if (!have_multiple_function_sections
)
8959 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
8961 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8962 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
8963 text_section_label
, NULL
);
8966 /* Otherwise, the compilation unit base address is zero,
8967 which allows us to use absolute addresses, and not worry
8968 about whether the target supports cross-section
8972 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
8973 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8974 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
8980 /* Negative block_num stands for an index into ranges_by_label. */
8981 else if (block_num
< 0)
8983 int lab_idx
= - block_num
- 1;
8985 if (!have_multiple_function_sections
)
8989 /* If we ever use add_ranges_by_labels () for a single
8990 function section, all we have to do is to take out
8992 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
8993 ranges_by_label
[lab_idx
].begin
,
8995 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8996 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
8997 ranges_by_label
[lab_idx
].end
,
8998 text_section_label
, NULL
);
9003 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9004 ranges_by_label
[lab_idx
].begin
,
9005 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9006 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9007 ranges_by_label
[lab_idx
].end
,
9013 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9014 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9020 /* Data structure containing information about input files. */
9023 const char *path
; /* Complete file name. */
9024 const char *fname
; /* File name part. */
9025 int length
; /* Length of entire string. */
9026 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9027 int dir_idx
; /* Index in directory table. */
9030 /* Data structure containing information about directories with source
9034 const char *path
; /* Path including directory name. */
9035 int length
; /* Path length. */
9036 int prefix
; /* Index of directory entry which is a prefix. */
9037 int count
; /* Number of files in this directory. */
9038 int dir_idx
; /* Index of directory used as base. */
9041 /* Callback function for file_info comparison. We sort by looking at
9042 the directories in the path. */
9045 file_info_cmp (const void *p1
, const void *p2
)
9047 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9048 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9049 const unsigned char *cp1
;
9050 const unsigned char *cp2
;
9052 /* Take care of file names without directories. We need to make sure that
9053 we return consistent values to qsort since some will get confused if
9054 we return the same value when identical operands are passed in opposite
9055 orders. So if neither has a directory, return 0 and otherwise return
9056 1 or -1 depending on which one has the directory. */
9057 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9058 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9060 cp1
= (const unsigned char *) s1
->path
;
9061 cp2
= (const unsigned char *) s2
->path
;
9067 /* Reached the end of the first path? If so, handle like above. */
9068 if ((cp1
== (const unsigned char *) s1
->fname
)
9069 || (cp2
== (const unsigned char *) s2
->fname
))
9070 return ((cp2
== (const unsigned char *) s2
->fname
)
9071 - (cp1
== (const unsigned char *) s1
->fname
));
9073 /* Character of current path component the same? */
9074 else if (*cp1
!= *cp2
)
9079 struct file_name_acquire_data
9081 struct file_info
*files
;
9086 /* Traversal function for the hash table. */
9089 file_name_acquire (void ** slot
, void *data
)
9091 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
9092 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
9093 struct file_info
*fi
;
9096 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9098 if (! d
->emitted_number
)
9101 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9103 fi
= fnad
->files
+ fnad
->used_files
++;
9105 /* Skip all leading "./". */
9107 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9110 /* Create a new array entry. */
9112 fi
->length
= strlen (f
);
9115 /* Search for the file name part. */
9116 f
= strrchr (f
, DIR_SEPARATOR
);
9117 #if defined (DIR_SEPARATOR_2)
9119 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9123 if (f
== NULL
|| f
< g
)
9129 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9133 /* Output the directory table and the file name table. We try to minimize
9134 the total amount of memory needed. A heuristic is used to avoid large
9135 slowdowns with many input files. */
9138 output_file_names (void)
9140 struct file_name_acquire_data fnad
;
9142 struct file_info
*files
;
9143 struct dir_info
*dirs
;
9151 if (!last_emitted_file
)
9153 dw2_asm_output_data (1, 0, "End directory table");
9154 dw2_asm_output_data (1, 0, "End file name table");
9158 numfiles
= last_emitted_file
->emitted_number
;
9160 /* Allocate the various arrays we need. */
9161 files
= XALLOCAVEC (struct file_info
, numfiles
);
9162 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9165 fnad
.used_files
= 0;
9166 fnad
.max_files
= numfiles
;
9167 htab_traverse (file_table
, file_name_acquire
, &fnad
);
9168 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9170 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9172 /* Find all the different directories used. */
9173 dirs
[0].path
= files
[0].path
;
9174 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9175 dirs
[0].prefix
= -1;
9177 dirs
[0].dir_idx
= 0;
9178 files
[0].dir_idx
= 0;
9181 for (i
= 1; i
< numfiles
; i
++)
9182 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9183 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9184 dirs
[ndirs
- 1].length
) == 0)
9186 /* Same directory as last entry. */
9187 files
[i
].dir_idx
= ndirs
- 1;
9188 ++dirs
[ndirs
- 1].count
;
9194 /* This is a new directory. */
9195 dirs
[ndirs
].path
= files
[i
].path
;
9196 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9197 dirs
[ndirs
].count
= 1;
9198 dirs
[ndirs
].dir_idx
= ndirs
;
9199 files
[i
].dir_idx
= ndirs
;
9201 /* Search for a prefix. */
9202 dirs
[ndirs
].prefix
= -1;
9203 for (j
= 0; j
< ndirs
; j
++)
9204 if (dirs
[j
].length
< dirs
[ndirs
].length
9205 && dirs
[j
].length
> 1
9206 && (dirs
[ndirs
].prefix
== -1
9207 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9208 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9209 dirs
[ndirs
].prefix
= j
;
9214 /* Now to the actual work. We have to find a subset of the directories which
9215 allow expressing the file name using references to the directory table
9216 with the least amount of characters. We do not do an exhaustive search
9217 where we would have to check out every combination of every single
9218 possible prefix. Instead we use a heuristic which provides nearly optimal
9219 results in most cases and never is much off. */
9220 saved
= XALLOCAVEC (int, ndirs
);
9221 savehere
= XALLOCAVEC (int, ndirs
);
9223 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9224 for (i
= 0; i
< ndirs
; i
++)
9229 /* We can always save some space for the current directory. But this
9230 does not mean it will be enough to justify adding the directory. */
9231 savehere
[i
] = dirs
[i
].length
;
9232 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9234 for (j
= i
+ 1; j
< ndirs
; j
++)
9237 if (saved
[j
] < dirs
[i
].length
)
9239 /* Determine whether the dirs[i] path is a prefix of the
9244 while (k
!= -1 && k
!= (int) i
)
9249 /* Yes it is. We can possibly save some memory by
9250 writing the filenames in dirs[j] relative to
9252 savehere
[j
] = dirs
[i
].length
;
9253 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9258 /* Check whether we can save enough to justify adding the dirs[i]
9260 if (total
> dirs
[i
].length
+ 1)
9262 /* It's worthwhile adding. */
9263 for (j
= i
; j
< ndirs
; j
++)
9264 if (savehere
[j
] > 0)
9266 /* Remember how much we saved for this directory so far. */
9267 saved
[j
] = savehere
[j
];
9269 /* Remember the prefix directory. */
9270 dirs
[j
].dir_idx
= i
;
9275 /* Emit the directory name table. */
9276 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9277 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9278 dw2_asm_output_nstring (dirs
[i
].path
,
9280 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
9281 "Directory Entry: %#x", i
+ idx_offset
);
9283 dw2_asm_output_data (1, 0, "End directory table");
9285 /* We have to emit them in the order of emitted_number since that's
9286 used in the debug info generation. To do this efficiently we
9287 generate a back-mapping of the indices first. */
9288 backmap
= XALLOCAVEC (int, numfiles
);
9289 for (i
= 0; i
< numfiles
; i
++)
9290 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9292 /* Now write all the file names. */
9293 for (i
= 0; i
< numfiles
; i
++)
9295 int file_idx
= backmap
[i
];
9296 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9298 #ifdef VMS_DEBUGGING_INFO
9299 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9301 /* Setting these fields can lead to debugger miscomparisons,
9302 but VMS Debug requires them to be set correctly. */
9307 int maxfilelen
= strlen (files
[file_idx
].path
)
9308 + dirs
[dir_idx
].length
9309 + MAX_VMS_VERSION_LEN
+ 1;
9310 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
9312 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
9313 snprintf (filebuf
, maxfilelen
, "%s;%d",
9314 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
9316 dw2_asm_output_nstring
9317 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
9319 /* Include directory index. */
9320 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9322 /* Modification time. */
9323 dw2_asm_output_data_uleb128
9324 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
9328 /* File length in bytes. */
9329 dw2_asm_output_data_uleb128
9330 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
9334 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
9335 "File Entry: %#x", (unsigned) i
+ 1);
9337 /* Include directory index. */
9338 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9340 /* Modification time. */
9341 dw2_asm_output_data_uleb128 (0, NULL
);
9343 /* File length in bytes. */
9344 dw2_asm_output_data_uleb128 (0, NULL
);
9345 #endif /* VMS_DEBUGGING_INFO */
9348 dw2_asm_output_data (1, 0, "End file name table");
9352 /* Output one line number table into the .debug_line section. */
9355 output_one_line_info_table (dw_line_info_table
*table
)
9357 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9358 unsigned int current_line
= 1;
9359 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
9360 dw_line_info_entry
*ent
;
9363 FOR_EACH_VEC_ELT (dw_line_info_entry
, table
->entries
, i
, ent
)
9365 switch (ent
->opcode
)
9367 case LI_set_address
:
9368 /* ??? Unfortunately, we have little choice here currently, and
9369 must always use the most general form. GCC does not know the
9370 address delta itself, so we can't use DW_LNS_advance_pc. Many
9371 ports do have length attributes which will give an upper bound
9372 on the address range. We could perhaps use length attributes
9373 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9374 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
9376 /* This can handle any delta. This takes
9377 4+DWARF2_ADDR_SIZE bytes. */
9378 dw2_asm_output_data (1, 0, "set address %s", line_label
);
9379 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9380 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9381 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9385 if (ent
->val
== current_line
)
9387 /* We still need to start a new row, so output a copy insn. */
9388 dw2_asm_output_data (1, DW_LNS_copy
,
9389 "copy line %u", current_line
);
9393 int line_offset
= ent
->val
- current_line
;
9394 int line_delta
= line_offset
- DWARF_LINE_BASE
;
9396 current_line
= ent
->val
;
9397 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9399 /* This can handle deltas from -10 to 234, using the current
9400 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9401 This takes 1 byte. */
9402 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9403 "line %u", current_line
);
9407 /* This can handle any delta. This takes at least 4 bytes,
9408 depending on the value being encoded. */
9409 dw2_asm_output_data (1, DW_LNS_advance_line
,
9410 "advance to line %u", current_line
);
9411 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9412 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
9418 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
9419 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9423 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
9424 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9427 case LI_negate_stmt
:
9428 current_is_stmt
= !current_is_stmt
;
9429 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
9430 "is_stmt %d", current_is_stmt
);
9433 case LI_set_prologue_end
:
9434 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
9435 "set prologue end");
9438 case LI_set_epilogue_begin
:
9439 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
9440 "set epilogue begin");
9443 case LI_set_discriminator
:
9444 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
9445 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
9446 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
9447 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
9452 /* Emit debug info for the address of the end of the table. */
9453 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
9454 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9455 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9456 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
9458 dw2_asm_output_data (1, 0, "end sequence");
9459 dw2_asm_output_data_uleb128 (1, NULL
);
9460 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
9463 /* Output the source line number correspondence information. This
9464 information goes into the .debug_line section. */
9467 output_line_info (void)
9469 char l1
[20], l2
[20], p1
[20], p2
[20];
9470 int ver
= dwarf_version
;
9471 bool saw_one
= false;
9474 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
9475 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
9476 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
9477 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
9479 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9480 dw2_asm_output_data (4, 0xffffffff,
9481 "Initial length escape value indicating 64-bit DWARF extension");
9482 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
9483 "Length of Source Line Info");
9484 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
9486 dw2_asm_output_data (2, ver
, "DWARF Version");
9487 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
9488 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
9490 /* Define the architecture-dependent minimum instruction length (in bytes).
9491 In this implementation of DWARF, this field is used for information
9492 purposes only. Since GCC generates assembly language, we have no
9493 a priori knowledge of how many instruction bytes are generated for each
9494 source line, and therefore can use only the DW_LNE_set_address and
9495 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
9496 this as '1', which is "correct enough" for all architectures,
9497 and don't let the target override. */
9498 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
9501 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
9502 "Maximum Operations Per Instruction");
9503 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
9504 "Default is_stmt_start flag");
9505 dw2_asm_output_data (1, DWARF_LINE_BASE
,
9506 "Line Base Value (Special Opcodes)");
9507 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
9508 "Line Range Value (Special Opcodes)");
9509 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
9510 "Special Opcode Base");
9512 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
9517 case DW_LNS_advance_pc
:
9518 case DW_LNS_advance_line
:
9519 case DW_LNS_set_file
:
9520 case DW_LNS_set_column
:
9521 case DW_LNS_fixed_advance_pc
:
9522 case DW_LNS_set_isa
:
9530 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
9534 /* Write out the information about the files we use. */
9535 output_file_names ();
9536 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
9538 if (separate_line_info
)
9540 dw_line_info_table
*table
;
9543 FOR_EACH_VEC_ELT (dw_line_info_table_p
, separate_line_info
, i
, table
)
9546 output_one_line_info_table (table
);
9550 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
9552 output_one_line_info_table (cold_text_section_line_info
);
9556 /* ??? Some Darwin linkers crash on a .debug_line section with no
9557 sequences. Further, merely a DW_LNE_end_sequence entry is not
9558 sufficient -- the address column must also be initialized.
9559 Make sure to output at least one set_address/end_sequence pair,
9560 choosing .text since that section is always present. */
9561 if (text_section_line_info
->in_use
|| !saw_one
)
9562 output_one_line_info_table (text_section_line_info
);
9564 /* Output the marker for the end of the line number info. */
9565 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9568 /* Given a pointer to a tree node for some base type, return a pointer to
9569 a DIE that describes the given type.
9571 This routine must only be called for GCC type nodes that correspond to
9572 Dwarf base (fundamental) types. */
9575 base_type_die (tree type
)
9577 dw_die_ref base_type_result
;
9578 enum dwarf_type encoding
;
9580 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
9583 /* If this is a subtype that should not be emitted as a subrange type,
9584 use the base type. See subrange_type_for_debug_p. */
9585 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
9586 type
= TREE_TYPE (type
);
9588 switch (TREE_CODE (type
))
9591 if ((dwarf_version
>= 4 || !dwarf_strict
)
9593 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9594 && DECL_IS_BUILTIN (TYPE_NAME (type
))
9595 && DECL_NAME (TYPE_NAME (type
)))
9597 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
9598 if (strcmp (name
, "char16_t") == 0
9599 || strcmp (name
, "char32_t") == 0)
9601 encoding
= DW_ATE_UTF
;
9605 if (TYPE_STRING_FLAG (type
))
9607 if (TYPE_UNSIGNED (type
))
9608 encoding
= DW_ATE_unsigned_char
;
9610 encoding
= DW_ATE_signed_char
;
9612 else if (TYPE_UNSIGNED (type
))
9613 encoding
= DW_ATE_unsigned
;
9615 encoding
= DW_ATE_signed
;
9619 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
9621 if (dwarf_version
>= 3 || !dwarf_strict
)
9622 encoding
= DW_ATE_decimal_float
;
9624 encoding
= DW_ATE_lo_user
;
9627 encoding
= DW_ATE_float
;
9630 case FIXED_POINT_TYPE
:
9631 if (!(dwarf_version
>= 3 || !dwarf_strict
))
9632 encoding
= DW_ATE_lo_user
;
9633 else if (TYPE_UNSIGNED (type
))
9634 encoding
= DW_ATE_unsigned_fixed
;
9636 encoding
= DW_ATE_signed_fixed
;
9639 /* Dwarf2 doesn't know anything about complex ints, so use
9640 a user defined type for it. */
9642 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
9643 encoding
= DW_ATE_complex_float
;
9645 encoding
= DW_ATE_lo_user
;
9649 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9650 encoding
= DW_ATE_boolean
;
9654 /* No other TREE_CODEs are Dwarf fundamental types. */
9658 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
9660 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
9661 int_size_in_bytes (type
));
9662 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
9664 return base_type_result
;
9667 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9668 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9671 is_base_type (tree type
)
9673 switch (TREE_CODE (type
))
9679 case FIXED_POINT_TYPE
:
9687 case QUAL_UNION_TYPE
:
9692 case REFERENCE_TYPE
:
9706 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9707 node, return the size in bits for the type if it is a constant, or else
9708 return the alignment for the type if the type's size is not constant, or
9709 else return BITS_PER_WORD if the type actually turns out to be an
9712 static inline unsigned HOST_WIDE_INT
9713 simple_type_size_in_bits (const_tree type
)
9715 if (TREE_CODE (type
) == ERROR_MARK
)
9716 return BITS_PER_WORD
;
9717 else if (TYPE_SIZE (type
) == NULL_TREE
)
9719 else if (host_integerp (TYPE_SIZE (type
), 1))
9720 return tree_low_cst (TYPE_SIZE (type
), 1);
9722 return TYPE_ALIGN (type
);
9725 /* Similarly, but return a double_int instead of UHWI. */
9727 static inline double_int
9728 double_int_type_size_in_bits (const_tree type
)
9730 if (TREE_CODE (type
) == ERROR_MARK
)
9731 return uhwi_to_double_int (BITS_PER_WORD
);
9732 else if (TYPE_SIZE (type
) == NULL_TREE
)
9733 return double_int_zero
;
9734 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
9735 return tree_to_double_int (TYPE_SIZE (type
));
9737 return uhwi_to_double_int (TYPE_ALIGN (type
));
9740 /* Given a pointer to a tree node for a subrange type, return a pointer
9741 to a DIE that describes the given type. */
9744 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
9746 dw_die_ref subrange_die
;
9747 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
9749 if (context_die
== NULL
)
9750 context_die
= comp_unit_die ();
9752 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
9754 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
9756 /* The size of the subrange type and its base type do not match,
9757 so we need to generate a size attribute for the subrange type. */
9758 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
9762 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
9764 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
9766 return subrange_die
;
9769 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9770 entry that chains various modifiers in front of the given type. */
9773 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
9774 dw_die_ref context_die
)
9776 enum tree_code code
= TREE_CODE (type
);
9777 dw_die_ref mod_type_die
;
9778 dw_die_ref sub_die
= NULL
;
9779 tree item_type
= NULL
;
9780 tree qualified_type
;
9781 tree name
, low
, high
;
9783 if (code
== ERROR_MARK
)
9786 /* See if we already have the appropriately qualified variant of
9789 = get_qualified_type (type
,
9790 ((is_const_type
? TYPE_QUAL_CONST
: 0)
9791 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
9793 if (qualified_type
== sizetype
9794 && TYPE_NAME (qualified_type
)
9795 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
9797 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
9799 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
9800 && TYPE_PRECISION (t
)
9801 == TYPE_PRECISION (qualified_type
)
9802 && TYPE_UNSIGNED (t
)
9803 == TYPE_UNSIGNED (qualified_type
));
9807 /* If we do, then we can just use its DIE, if it exists. */
9810 mod_type_die
= lookup_type_die (qualified_type
);
9812 return mod_type_die
;
9815 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
9817 /* Handle C typedef types. */
9818 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
9819 && !DECL_ARTIFICIAL (name
))
9821 tree dtype
= TREE_TYPE (name
);
9823 if (qualified_type
== dtype
)
9825 /* For a named type, use the typedef. */
9826 gen_type_die (qualified_type
, context_die
);
9827 return lookup_type_die (qualified_type
);
9829 else if (is_const_type
< TYPE_READONLY (dtype
)
9830 || is_volatile_type
< TYPE_VOLATILE (dtype
)
9831 || (is_const_type
<= TYPE_READONLY (dtype
)
9832 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
9833 && DECL_ORIGINAL_TYPE (name
) != type
))
9834 /* cv-unqualified version of named type. Just use the unnamed
9835 type to which it refers. */
9836 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
9837 is_const_type
, is_volatile_type
,
9839 /* Else cv-qualified version of named type; fall through. */
9843 /* If both is_const_type and is_volatile_type, prefer the path
9844 which leads to a qualified type. */
9845 && (!is_volatile_type
9846 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
9847 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
9849 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die (), type
);
9850 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
9852 else if (is_volatile_type
)
9854 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die (), type
);
9855 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
9857 else if (code
== POINTER_TYPE
)
9859 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die (), type
);
9860 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
9861 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
9862 item_type
= TREE_TYPE (type
);
9863 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
9864 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
9865 TYPE_ADDR_SPACE (item_type
));
9867 else if (code
== REFERENCE_TYPE
)
9869 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
9870 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, comp_unit_die (),
9873 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die (), type
);
9874 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
9875 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
9876 item_type
= TREE_TYPE (type
);
9877 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
9878 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
9879 TYPE_ADDR_SPACE (item_type
));
9881 else if (code
== INTEGER_TYPE
9882 && TREE_TYPE (type
) != NULL_TREE
9883 && subrange_type_for_debug_p (type
, &low
, &high
))
9885 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
9886 item_type
= TREE_TYPE (type
);
9888 else if (is_base_type (type
))
9889 mod_type_die
= base_type_die (type
);
9892 gen_type_die (type
, context_die
);
9894 /* We have to get the type_main_variant here (and pass that to the
9895 `lookup_type_die' routine) because the ..._TYPE node we have
9896 might simply be a *copy* of some original type node (where the
9897 copy was created to help us keep track of typedef names) and
9898 that copy might have a different TYPE_UID from the original
9900 if (TREE_CODE (type
) != VECTOR_TYPE
)
9901 return lookup_type_die (type_main_variant (type
));
9903 /* Vectors have the debugging information in the type,
9904 not the main variant. */
9905 return lookup_type_die (type
);
9908 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9909 don't output a DW_TAG_typedef, since there isn't one in the
9910 user's program; just attach a DW_AT_name to the type.
9911 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
9912 if the base type already has the same name. */
9914 && ((TREE_CODE (name
) != TYPE_DECL
9915 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
9916 || (!is_const_type
&& !is_volatile_type
)))
9917 || (TREE_CODE (name
) == TYPE_DECL
9918 && TREE_TYPE (name
) == qualified_type
9919 && DECL_NAME (name
))))
9921 if (TREE_CODE (name
) == TYPE_DECL
)
9922 /* Could just call add_name_and_src_coords_attributes here,
9923 but since this is a builtin type it doesn't have any
9924 useful source coordinates anyway. */
9925 name
= DECL_NAME (name
);
9926 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
9928 /* This probably indicates a bug. */
9929 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
9931 name
= TYPE_NAME (type
);
9933 && TREE_CODE (name
) == TYPE_DECL
)
9934 name
= DECL_NAME (name
);
9935 add_name_attribute (mod_type_die
,
9936 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
9940 equate_type_number_to_die (qualified_type
, mod_type_die
);
9943 /* We must do this after the equate_type_number_to_die call, in case
9944 this is a recursive type. This ensures that the modified_type_die
9945 recursion will terminate even if the type is recursive. Recursive
9946 types are possible in Ada. */
9947 sub_die
= modified_type_die (item_type
,
9948 TYPE_READONLY (item_type
),
9949 TYPE_VOLATILE (item_type
),
9952 if (sub_die
!= NULL
)
9953 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
9955 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
9956 if (TYPE_ARTIFICIAL (type
))
9957 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
9959 return mod_type_die
;
9962 /* Generate DIEs for the generic parameters of T.
9963 T must be either a generic type or a generic function.
9964 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
9967 gen_generic_params_dies (tree t
)
9971 dw_die_ref die
= NULL
;
9973 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
9977 die
= lookup_type_die (t
);
9978 else if (DECL_P (t
))
9979 die
= lookup_decl_die (t
);
9983 parms
= lang_hooks
.get_innermost_generic_parms (t
);
9985 /* T has no generic parameter. It means T is neither a generic type
9986 or function. End of story. */
9989 parms_num
= TREE_VEC_LENGTH (parms
);
9990 args
= lang_hooks
.get_innermost_generic_args (t
);
9991 for (i
= 0; i
< parms_num
; i
++)
9993 tree parm
, arg
, arg_pack_elems
;
9995 parm
= TREE_VEC_ELT (parms
, i
);
9996 arg
= TREE_VEC_ELT (args
, i
);
9997 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
9998 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
10000 if (parm
&& TREE_VALUE (parm
) && arg
)
10002 /* If PARM represents a template parameter pack,
10003 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10004 by DW_TAG_template_*_parameter DIEs for the argument
10005 pack elements of ARG. Note that ARG would then be
10006 an argument pack. */
10007 if (arg_pack_elems
)
10008 template_parameter_pack_die (TREE_VALUE (parm
),
10012 generic_parameter_die (TREE_VALUE (parm
), arg
,
10013 true /* Emit DW_AT_name */, die
);
10018 /* Create and return a DIE for PARM which should be
10019 the representation of a generic type parameter.
10020 For instance, in the C++ front end, PARM would be a template parameter.
10021 ARG is the argument to PARM.
10022 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10024 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10025 as a child node. */
10028 generic_parameter_die (tree parm
, tree arg
,
10030 dw_die_ref parent_die
)
10032 dw_die_ref tmpl_die
= NULL
;
10033 const char *name
= NULL
;
10035 if (!parm
|| !DECL_NAME (parm
) || !arg
)
10038 /* We support non-type generic parameters and arguments,
10039 type generic parameters and arguments, as well as
10040 generic generic parameters (a.k.a. template template parameters in C++)
10042 if (TREE_CODE (parm
) == PARM_DECL
)
10043 /* PARM is a nontype generic parameter */
10044 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
10045 else if (TREE_CODE (parm
) == TYPE_DECL
)
10046 /* PARM is a type generic parameter. */
10047 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
10048 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10049 /* PARM is a generic generic parameter.
10050 Its DIE is a GNU extension. It shall have a
10051 DW_AT_name attribute to represent the name of the template template
10052 parameter, and a DW_AT_GNU_template_name attribute to represent the
10053 name of the template template argument. */
10054 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
10057 gcc_unreachable ();
10063 /* If PARM is a generic parameter pack, it means we are
10064 emitting debug info for a template argument pack element.
10065 In other terms, ARG is a template argument pack element.
10066 In that case, we don't emit any DW_AT_name attribute for
10070 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
10072 add_AT_string (tmpl_die
, DW_AT_name
, name
);
10075 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10077 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10078 TMPL_DIE should have a child DW_AT_type attribute that is set
10079 to the type of the argument to PARM, which is ARG.
10080 If PARM is a type generic parameter, TMPL_DIE should have a
10081 child DW_AT_type that is set to ARG. */
10082 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
10083 add_type_attribute (tmpl_die
, tmpl_type
, 0,
10084 TREE_THIS_VOLATILE (tmpl_type
),
10089 /* So TMPL_DIE is a DIE representing a
10090 a generic generic template parameter, a.k.a template template
10091 parameter in C++ and arg is a template. */
10093 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10094 to the name of the argument. */
10095 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
10097 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
10100 if (TREE_CODE (parm
) == PARM_DECL
)
10101 /* So PARM is a non-type generic parameter.
10102 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10103 attribute of TMPL_DIE which value represents the value
10105 We must be careful here:
10106 The value of ARG might reference some function decls.
10107 We might currently be emitting debug info for a generic
10108 type and types are emitted before function decls, we don't
10109 know if the function decls referenced by ARG will actually be
10110 emitted after cgraph computations.
10111 So must defer the generation of the DW_AT_const_value to
10112 after cgraph is ready. */
10113 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
10119 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10120 PARM_PACK must be a template parameter pack. The returned DIE
10121 will be child DIE of PARENT_DIE. */
10124 template_parameter_pack_die (tree parm_pack
,
10125 tree parm_pack_args
,
10126 dw_die_ref parent_die
)
10131 gcc_assert (parent_die
&& parm_pack
);
10133 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
10134 add_name_and_src_coords_attributes (die
, parm_pack
);
10135 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
10136 generic_parameter_die (parm_pack
,
10137 TREE_VEC_ELT (parm_pack_args
, j
),
10138 false /* Don't emit DW_AT_name */,
10143 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10144 an enumerated type. */
10147 type_is_enum (const_tree type
)
10149 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10152 /* Return the DBX register number described by a given RTL node. */
10154 static unsigned int
10155 dbx_reg_number (const_rtx rtl
)
10157 unsigned regno
= REGNO (rtl
);
10159 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10161 #ifdef LEAF_REG_REMAP
10162 if (current_function_uses_only_leaf_regs
)
10164 int leaf_reg
= LEAF_REG_REMAP (regno
);
10165 if (leaf_reg
!= -1)
10166 regno
= (unsigned) leaf_reg
;
10170 return DBX_REGISTER_NUMBER (regno
);
10173 /* Optionally add a DW_OP_piece term to a location description expression.
10174 DW_OP_piece is only added if the location description expression already
10175 doesn't end with DW_OP_piece. */
10178 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10180 dw_loc_descr_ref loc
;
10182 if (*list_head
!= NULL
)
10184 /* Find the end of the chain. */
10185 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10188 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10189 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10193 /* Return a location descriptor that designates a machine register or
10194 zero if there is none. */
10196 static dw_loc_descr_ref
10197 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10201 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10204 /* We only use "frame base" when we're sure we're talking about the
10205 post-prologue local stack frame. We do this by *not* running
10206 register elimination until this point, and recognizing the special
10207 argument pointer and soft frame pointer rtx's.
10208 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10209 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
10210 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
10212 dw_loc_descr_ref result
= NULL
;
10214 if (dwarf_version
>= 4 || !dwarf_strict
)
10216 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
10219 add_loc_descr (&result
,
10220 new_loc_descr (DW_OP_stack_value
, 0, 0));
10225 regs
= targetm
.dwarf_register_span (rtl
);
10227 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
10228 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
10230 return one_reg_loc_descriptor (dbx_reg_number (rtl
), initialized
);
10233 /* Return a location descriptor that designates a machine register for
10234 a given hard register number. */
10236 static dw_loc_descr_ref
10237 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10239 dw_loc_descr_ref reg_loc_descr
;
10243 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10245 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10247 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10248 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10250 return reg_loc_descr
;
10253 /* Given an RTL of a register, return a location descriptor that
10254 designates a value that spans more than one register. */
10256 static dw_loc_descr_ref
10257 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10258 enum var_init_status initialized
)
10260 int nregs
, size
, i
;
10262 dw_loc_descr_ref loc_result
= NULL
;
10265 #ifdef LEAF_REG_REMAP
10266 if (current_function_uses_only_leaf_regs
)
10268 int leaf_reg
= LEAF_REG_REMAP (reg
);
10269 if (leaf_reg
!= -1)
10270 reg
= (unsigned) leaf_reg
;
10273 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
10274 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
10276 /* Simple, contiguous registers. */
10277 if (regs
== NULL_RTX
)
10279 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
10284 dw_loc_descr_ref t
;
10286 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
10287 VAR_INIT_STATUS_INITIALIZED
);
10288 add_loc_descr (&loc_result
, t
);
10289 add_loc_descr_op_piece (&loc_result
, size
);
10295 /* Now onto stupid register sets in non contiguous locations. */
10297 gcc_assert (GET_CODE (regs
) == PARALLEL
);
10299 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10302 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
10304 dw_loc_descr_ref t
;
10306 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
10307 VAR_INIT_STATUS_INITIALIZED
);
10308 add_loc_descr (&loc_result
, t
);
10309 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10310 add_loc_descr_op_piece (&loc_result
, size
);
10313 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10314 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10318 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
10320 /* Return a location descriptor that designates a constant i,
10321 as a compound operation from constant (i >> shift), constant shift
10324 static dw_loc_descr_ref
10325 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10327 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
10328 add_loc_descr (&ret
, int_loc_descriptor (shift
));
10329 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
10333 /* Return a location descriptor that designates a constant. */
10335 static dw_loc_descr_ref
10336 int_loc_descriptor (HOST_WIDE_INT i
)
10338 enum dwarf_location_atom op
;
10340 /* Pick the smallest representation of a constant, rather than just
10341 defaulting to the LEB encoding. */
10344 int clz
= clz_hwi (i
);
10345 int ctz
= ctz_hwi (i
);
10347 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
10348 else if (i
<= 0xff)
10349 op
= DW_OP_const1u
;
10350 else if (i
<= 0xffff)
10351 op
= DW_OP_const2u
;
10352 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10353 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10354 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10355 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
10356 while DW_OP_const4u is 5 bytes. */
10357 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
10358 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10359 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10360 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10361 while DW_OP_const4u is 5 bytes. */
10362 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10363 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10364 op
= DW_OP_const4u
;
10365 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10366 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10367 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10368 while DW_OP_constu of constant >= 0x100000000 takes at least
10370 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10371 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10372 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
10373 >= HOST_BITS_PER_WIDE_INT
)
10374 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10375 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10376 while DW_OP_constu takes in this case at least 6 bytes. */
10377 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
10378 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10379 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10380 && size_of_uleb128 (i
) > 6)
10381 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10382 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
10389 op
= DW_OP_const1s
;
10390 else if (i
>= -0x8000)
10391 op
= DW_OP_const2s
;
10392 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10394 if (size_of_int_loc_descriptor (i
) < 5)
10396 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10397 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10400 op
= DW_OP_const4s
;
10404 if (size_of_int_loc_descriptor (i
)
10405 < (unsigned long) 1 + size_of_sleb128 (i
))
10407 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10408 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10415 return new_loc_descr (op
, i
, 0);
10418 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10419 without actually allocating it. */
10421 static unsigned long
10422 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10424 return size_of_int_loc_descriptor (i
>> shift
)
10425 + size_of_int_loc_descriptor (shift
)
10429 /* Return size_of_locs (int_loc_descriptor (i)) without
10430 actually allocating it. */
10432 static unsigned long
10433 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
10442 else if (i
<= 0xff)
10444 else if (i
<= 0xffff)
10448 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10449 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10450 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10452 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10453 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10454 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10456 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10458 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
10459 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10460 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10461 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10463 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10464 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
10465 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10467 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10468 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10470 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10479 else if (i
>= -0x8000)
10481 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10483 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10485 s
= size_of_int_loc_descriptor (-i
) + 1;
10493 unsigned long r
= 1 + size_of_sleb128 (i
);
10494 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10496 s
= size_of_int_loc_descriptor (-i
) + 1;
10505 /* Return loc description representing "address" of integer value.
10506 This can appear only as toplevel expression. */
10508 static dw_loc_descr_ref
10509 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
10512 dw_loc_descr_ref loc_result
= NULL
;
10514 if (!(dwarf_version
>= 4 || !dwarf_strict
))
10517 litsize
= size_of_int_loc_descriptor (i
);
10518 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10519 is more compact. For DW_OP_stack_value we need:
10520 litsize + 1 (DW_OP_stack_value)
10521 and for DW_OP_implicit_value:
10522 1 (DW_OP_implicit_value) + 1 (length) + size. */
10523 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
10525 loc_result
= int_loc_descriptor (i
);
10526 add_loc_descr (&loc_result
,
10527 new_loc_descr (DW_OP_stack_value
, 0, 0));
10531 loc_result
= new_loc_descr (DW_OP_implicit_value
,
10533 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
10534 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
10538 /* Return a location descriptor that designates a base+offset location. */
10540 static dw_loc_descr_ref
10541 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
10542 enum var_init_status initialized
)
10544 unsigned int regno
;
10545 dw_loc_descr_ref result
;
10546 dw_fde_ref fde
= cfun
->fde
;
10548 /* We only use "frame base" when we're sure we're talking about the
10549 post-prologue local stack frame. We do this by *not* running
10550 register elimination until this point, and recognizing the special
10551 argument pointer and soft frame pointer rtx's. */
10552 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
10554 rtx elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
10558 if (GET_CODE (elim
) == PLUS
)
10560 offset
+= INTVAL (XEXP (elim
, 1));
10561 elim
= XEXP (elim
, 0);
10563 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10564 && (elim
== hard_frame_pointer_rtx
10565 || elim
== stack_pointer_rtx
))
10566 || elim
== (frame_pointer_needed
10567 ? hard_frame_pointer_rtx
10568 : stack_pointer_rtx
));
10570 /* If drap register is used to align stack, use frame
10571 pointer + offset to access stack variables. If stack
10572 is aligned without drap, use stack pointer + offset to
10573 access stack variables. */
10574 if (crtl
->stack_realign_tried
10575 && reg
== frame_pointer_rtx
)
10578 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
10579 ? HARD_FRAME_POINTER_REGNUM
10581 return new_reg_loc_descr (base_reg
, offset
);
10584 gcc_assert (frame_pointer_fb_offset_valid
);
10585 offset
+= frame_pointer_fb_offset
;
10586 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10590 regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
10592 if (!optimize
&& fde
10593 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
10595 /* Use cfa+offset to represent the location of arguments passed
10596 on the stack when drap is used to align stack.
10597 Only do this when not optimizing, for optimized code var-tracking
10598 is supposed to track where the arguments live and the register
10599 used as vdrap or drap in some spot might be used for something
10600 else in other part of the routine. */
10601 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10605 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
10608 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
10610 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10611 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10616 /* Return true if this RTL expression describes a base+offset calculation. */
10619 is_based_loc (const_rtx rtl
)
10621 return (GET_CODE (rtl
) == PLUS
10622 && ((REG_P (XEXP (rtl
, 0))
10623 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
10624 && CONST_INT_P (XEXP (rtl
, 1)))));
10627 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10630 static dw_loc_descr_ref
10631 tls_mem_loc_descriptor (rtx mem
)
10634 dw_loc_descr_ref loc_result
;
10636 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
10639 base
= get_base_address (MEM_EXPR (mem
));
10641 || TREE_CODE (base
) != VAR_DECL
10642 || !DECL_THREAD_LOCAL_P (base
))
10645 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
10646 if (loc_result
== NULL
)
10649 if (MEM_OFFSET (mem
))
10650 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
10655 /* Output debug info about reason why we failed to expand expression as dwarf
10659 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
10661 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
10663 fprintf (dump_file
, "Failed to expand as dwarf: ");
10665 print_generic_expr (dump_file
, expr
, dump_flags
);
10668 fprintf (dump_file
, "\n");
10669 print_rtl (dump_file
, rtl
);
10671 fprintf (dump_file
, "\nReason: %s\n", reason
);
10675 /* Helper function for const_ok_for_output, called either directly
10676 or via for_each_rtx. */
10679 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
10683 if (GET_CODE (rtl
) == UNSPEC
)
10685 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
10686 we can't express it in the debug info. */
10687 #ifdef ENABLE_CHECKING
10688 /* Don't complain about TLS UNSPECs, those are just too hard to
10690 if (XVECLEN (rtl
, 0) != 1
10691 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
10692 || SYMBOL_REF_DECL (XVECEXP (rtl
, 0, 0)) == NULL
10693 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl
, 0, 0))) != VAR_DECL
10694 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl
, 0, 0))))
10695 inform (current_function_decl
10696 ? DECL_SOURCE_LOCATION (current_function_decl
)
10697 : UNKNOWN_LOCATION
,
10698 #if NUM_UNSPEC_VALUES > 0
10699 "non-delegitimized UNSPEC %s (%d) found in variable location",
10700 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
10701 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
10704 "non-delegitimized UNSPEC %d found in variable location",
10708 expansion_failed (NULL_TREE
, rtl
,
10709 "UNSPEC hasn't been delegitimized.\n");
10713 if (targetm
.const_not_ok_for_debug_p (rtl
))
10715 expansion_failed (NULL_TREE
, rtl
,
10716 "Expression rejected for debug by the backend.\n");
10720 if (GET_CODE (rtl
) != SYMBOL_REF
)
10723 if (CONSTANT_POOL_ADDRESS_P (rtl
))
10726 get_pool_constant_mark (rtl
, &marked
);
10727 /* If all references to this pool constant were optimized away,
10728 it was not output and thus we can't represent it. */
10731 expansion_failed (NULL_TREE
, rtl
,
10732 "Constant was removed from constant pool.\n");
10737 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
10740 /* Avoid references to external symbols in debug info, on several targets
10741 the linker might even refuse to link when linking a shared library,
10742 and in many other cases the relocations for .debug_info/.debug_loc are
10743 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
10744 to be defined within the same shared library or executable are fine. */
10745 if (SYMBOL_REF_EXTERNAL_P (rtl
))
10747 tree decl
= SYMBOL_REF_DECL (rtl
);
10749 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
10751 expansion_failed (NULL_TREE
, rtl
,
10752 "Symbol not defined in current TU.\n");
10760 /* Return true if constant RTL can be emitted in DW_OP_addr or
10761 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
10762 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
10765 const_ok_for_output (rtx rtl
)
10767 if (GET_CODE (rtl
) == SYMBOL_REF
)
10768 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
10770 if (GET_CODE (rtl
) == CONST
)
10771 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
10776 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
10777 if possible, NULL otherwise. */
10780 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
10782 dw_die_ref type_die
;
10783 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
10787 switch (TREE_CODE (type
))
10795 type_die
= lookup_type_die (type
);
10797 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
10798 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
10803 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
10804 type matching MODE, or, if MODE is narrower than or as wide as
10805 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
10808 static dw_loc_descr_ref
10809 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
10811 enum machine_mode outer_mode
= mode
;
10812 dw_die_ref type_die
;
10813 dw_loc_descr_ref cvt
;
10815 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
10817 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
10820 type_die
= base_type_for_mode (outer_mode
, 1);
10821 if (type_die
== NULL
)
10823 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10824 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10825 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10826 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10827 add_loc_descr (&op
, cvt
);
10831 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
10833 static dw_loc_descr_ref
10834 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
10835 dw_loc_descr_ref op1
)
10837 dw_loc_descr_ref ret
= op0
;
10838 add_loc_descr (&ret
, op1
);
10839 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
10840 if (STORE_FLAG_VALUE
!= 1)
10842 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
10843 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
10848 /* Return location descriptor for signed comparison OP RTL. */
10850 static dw_loc_descr_ref
10851 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
10852 enum machine_mode mem_mode
)
10854 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
10855 dw_loc_descr_ref op0
, op1
;
10858 if (op_mode
== VOIDmode
)
10859 op_mode
= GET_MODE (XEXP (rtl
, 1));
10860 if (op_mode
== VOIDmode
)
10864 && (GET_MODE_CLASS (op_mode
) != MODE_INT
10865 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
10868 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
10869 VAR_INIT_STATUS_INITIALIZED
);
10870 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
10871 VAR_INIT_STATUS_INITIALIZED
);
10873 if (op0
== NULL
|| op1
== NULL
)
10876 if (GET_MODE_CLASS (op_mode
) != MODE_INT
10877 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
10878 return compare_loc_descriptor (op
, op0
, op1
);
10880 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
10882 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
10883 dw_loc_descr_ref cvt
;
10885 if (type_die
== NULL
)
10887 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10888 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10889 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10890 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10891 add_loc_descr (&op0
, cvt
);
10892 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10893 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10894 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10895 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10896 add_loc_descr (&op1
, cvt
);
10897 return compare_loc_descriptor (op
, op0
, op1
);
10900 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
10901 /* For eq/ne, if the operands are known to be zero-extended,
10902 there is no need to do the fancy shifting up. */
10903 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
10905 dw_loc_descr_ref last0
, last1
;
10906 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
10908 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
10910 /* deref_size zero extends, and for constants we can check
10911 whether they are zero extended or not. */
10912 if (((last0
->dw_loc_opc
== DW_OP_deref_size
10913 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
10914 || (CONST_INT_P (XEXP (rtl
, 0))
10915 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
10916 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
10917 && ((last1
->dw_loc_opc
== DW_OP_deref_size
10918 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
10919 || (CONST_INT_P (XEXP (rtl
, 1))
10920 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
10921 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
10922 return compare_loc_descriptor (op
, op0
, op1
);
10924 /* EQ/NE comparison against constant in narrower type than
10925 DWARF2_ADDR_SIZE can be performed either as
10926 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
10929 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
10930 DW_OP_{eq,ne}. Pick whatever is shorter. */
10931 if (CONST_INT_P (XEXP (rtl
, 1))
10932 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
10933 && (size_of_int_loc_descriptor (shift
) + 1
10934 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
10935 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
10936 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
10937 & GET_MODE_MASK (op_mode
))))
10939 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
10940 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
10941 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
10942 & GET_MODE_MASK (op_mode
));
10943 return compare_loc_descriptor (op
, op0
, op1
);
10946 add_loc_descr (&op0
, int_loc_descriptor (shift
));
10947 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
10948 if (CONST_INT_P (XEXP (rtl
, 1)))
10949 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
10952 add_loc_descr (&op1
, int_loc_descriptor (shift
));
10953 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
10955 return compare_loc_descriptor (op
, op0
, op1
);
10958 /* Return location descriptor for unsigned comparison OP RTL. */
10960 static dw_loc_descr_ref
10961 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
10962 enum machine_mode mem_mode
)
10964 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
10965 dw_loc_descr_ref op0
, op1
;
10967 if (op_mode
== VOIDmode
)
10968 op_mode
= GET_MODE (XEXP (rtl
, 1));
10969 if (op_mode
== VOIDmode
)
10971 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
10974 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
10977 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
10978 VAR_INIT_STATUS_INITIALIZED
);
10979 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
10980 VAR_INIT_STATUS_INITIALIZED
);
10982 if (op0
== NULL
|| op1
== NULL
)
10985 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
10987 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
10988 dw_loc_descr_ref last0
, last1
;
10989 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
10991 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
10993 if (CONST_INT_P (XEXP (rtl
, 0)))
10994 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
10995 /* deref_size zero extends, so no need to mask it again. */
10996 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
10997 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
10999 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11000 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11002 if (CONST_INT_P (XEXP (rtl
, 1)))
11003 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
11004 /* deref_size zero extends, so no need to mask it again. */
11005 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
11006 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11008 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11009 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11012 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11014 HOST_WIDE_INT bias
= 1;
11015 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11016 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11017 if (CONST_INT_P (XEXP (rtl
, 1)))
11018 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
11019 + INTVAL (XEXP (rtl
, 1)));
11021 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
11024 return compare_loc_descriptor (op
, op0
, op1
);
11027 /* Return location descriptor for {U,S}{MIN,MAX}. */
11029 static dw_loc_descr_ref
11030 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11031 enum machine_mode mem_mode
)
11033 enum dwarf_location_atom op
;
11034 dw_loc_descr_ref op0
, op1
, ret
;
11035 dw_loc_descr_ref bra_node
, drop_node
;
11038 && (GET_MODE_CLASS (mode
) != MODE_INT
11039 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
11042 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11043 VAR_INIT_STATUS_INITIALIZED
);
11044 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11045 VAR_INIT_STATUS_INITIALIZED
);
11047 if (op0
== NULL
|| op1
== NULL
)
11050 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
11051 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
11052 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
11053 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
11055 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11057 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
11058 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11059 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11060 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11061 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11063 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11065 HOST_WIDE_INT bias
= 1;
11066 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11067 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11068 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11071 else if (GET_MODE_CLASS (mode
) == MODE_INT
11072 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11074 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11075 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11076 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11077 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11078 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11080 else if (GET_MODE_CLASS (mode
) == MODE_INT
11081 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11083 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11084 dw_loc_descr_ref cvt
;
11085 if (type_die
== NULL
)
11087 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11088 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11089 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11090 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11091 add_loc_descr (&op0
, cvt
);
11092 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11093 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11094 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11095 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11096 add_loc_descr (&op1
, cvt
);
11099 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11104 add_loc_descr (&ret
, op1
);
11105 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11106 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11107 add_loc_descr (&ret
, bra_node
);
11108 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11109 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11110 add_loc_descr (&ret
, drop_node
);
11111 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11112 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11113 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11114 && GET_MODE_CLASS (mode
) == MODE_INT
11115 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11116 ret
= convert_descriptor_to_mode (mode
, ret
);
11120 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11121 but after converting arguments to type_die, afterwards
11122 convert back to unsigned. */
11124 static dw_loc_descr_ref
11125 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11126 enum machine_mode mode
, enum machine_mode mem_mode
)
11128 dw_loc_descr_ref cvt
, op0
, op1
;
11130 if (type_die
== NULL
)
11132 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11133 VAR_INIT_STATUS_INITIALIZED
);
11134 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11135 VAR_INIT_STATUS_INITIALIZED
);
11136 if (op0
== NULL
|| op1
== NULL
)
11138 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11139 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11140 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11141 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11142 add_loc_descr (&op0
, cvt
);
11143 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11144 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11145 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11146 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11147 add_loc_descr (&op1
, cvt
);
11148 add_loc_descr (&op0
, op1
);
11149 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11150 return convert_descriptor_to_mode (mode
, op0
);
11153 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11154 const0 is DW_OP_lit0 or corresponding typed constant,
11155 const1 is DW_OP_lit1 or corresponding typed constant
11156 and constMSB is constant with just the MSB bit set
11158 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11159 L1: const0 DW_OP_swap
11160 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11161 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11166 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11167 L1: const0 DW_OP_swap
11168 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11169 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11174 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11175 L1: const1 DW_OP_swap
11176 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11177 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11181 static dw_loc_descr_ref
11182 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11183 enum machine_mode mem_mode
)
11185 dw_loc_descr_ref op0
, ret
, tmp
;
11186 HOST_WIDE_INT valv
;
11187 dw_loc_descr_ref l1jump
, l1label
;
11188 dw_loc_descr_ref l2jump
, l2label
;
11189 dw_loc_descr_ref l3jump
, l3label
;
11190 dw_loc_descr_ref l4jump
, l4label
;
11193 if (GET_MODE_CLASS (mode
) != MODE_INT
11194 || GET_MODE (XEXP (rtl
, 0)) != mode
11195 || (GET_CODE (rtl
) == CLZ
11196 && GET_MODE_BITSIZE (mode
) > 2 * HOST_BITS_PER_WIDE_INT
))
11199 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11200 VAR_INIT_STATUS_INITIALIZED
);
11204 if (GET_CODE (rtl
) == CLZ
)
11206 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11207 valv
= GET_MODE_BITSIZE (mode
);
11209 else if (GET_CODE (rtl
) == FFS
)
11211 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11212 valv
= GET_MODE_BITSIZE (mode
);
11213 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11214 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11215 add_loc_descr (&ret
, l1jump
);
11216 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11217 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
11218 VAR_INIT_STATUS_INITIALIZED
);
11221 add_loc_descr (&ret
, tmp
);
11222 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11223 add_loc_descr (&ret
, l4jump
);
11224 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
11225 ? const1_rtx
: const0_rtx
,
11227 VAR_INIT_STATUS_INITIALIZED
);
11228 if (l1label
== NULL
)
11230 add_loc_descr (&ret
, l1label
);
11231 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11232 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
11233 add_loc_descr (&ret
, l2label
);
11234 if (GET_CODE (rtl
) != CLZ
)
11236 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11237 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
11238 << (GET_MODE_BITSIZE (mode
) - 1));
11240 msb
= immed_double_const (0, (unsigned HOST_WIDE_INT
) 1
11241 << (GET_MODE_BITSIZE (mode
)
11242 - HOST_BITS_PER_WIDE_INT
- 1), mode
);
11243 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
11244 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11245 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
11246 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
11248 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
11249 VAR_INIT_STATUS_INITIALIZED
);
11252 add_loc_descr (&ret
, tmp
);
11253 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11254 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11255 add_loc_descr (&ret
, l3jump
);
11256 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11257 VAR_INIT_STATUS_INITIALIZED
);
11260 add_loc_descr (&ret
, tmp
);
11261 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
11262 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
11263 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11264 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
11265 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11266 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11267 add_loc_descr (&ret
, l2jump
);
11268 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
11269 add_loc_descr (&ret
, l3label
);
11270 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
11271 add_loc_descr (&ret
, l4label
);
11272 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11273 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11274 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11275 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11276 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11277 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
11278 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11279 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
11283 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11284 const1 is DW_OP_lit1 or corresponding typed constant):
11286 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11287 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11291 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11292 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11295 static dw_loc_descr_ref
11296 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11297 enum machine_mode mem_mode
)
11299 dw_loc_descr_ref op0
, ret
, tmp
;
11300 dw_loc_descr_ref l1jump
, l1label
;
11301 dw_loc_descr_ref l2jump
, l2label
;
11303 if (GET_MODE_CLASS (mode
) != MODE_INT
11304 || GET_MODE (XEXP (rtl
, 0)) != mode
)
11307 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11308 VAR_INIT_STATUS_INITIALIZED
);
11312 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11313 VAR_INIT_STATUS_INITIALIZED
);
11316 add_loc_descr (&ret
, tmp
);
11317 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11318 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
11319 add_loc_descr (&ret
, l1label
);
11320 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11321 add_loc_descr (&ret
, l2jump
);
11322 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11323 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11324 tmp
= mem_loc_descriptor (const1_rtx
, 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 (GET_CODE (rtl
) == POPCOUNT
11331 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
11332 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11333 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11334 VAR_INIT_STATUS_INITIALIZED
);
11335 add_loc_descr (&ret
, tmp
);
11336 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11337 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11338 add_loc_descr (&ret
, l1jump
);
11339 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11340 add_loc_descr (&ret
, l2label
);
11341 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11342 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11343 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11344 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11348 /* BSWAP (constS is initial shift count, either 56 or 24):
11350 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11351 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11352 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11353 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11354 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11356 static dw_loc_descr_ref
11357 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11358 enum machine_mode mem_mode
)
11360 dw_loc_descr_ref op0
, ret
, tmp
;
11361 dw_loc_descr_ref l1jump
, l1label
;
11362 dw_loc_descr_ref l2jump
, l2label
;
11364 if (GET_MODE_CLASS (mode
) != MODE_INT
11365 || BITS_PER_UNIT
!= 8
11366 || (GET_MODE_BITSIZE (mode
) != 32
11367 && GET_MODE_BITSIZE (mode
) != 64))
11370 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11371 VAR_INIT_STATUS_INITIALIZED
);
11376 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11378 VAR_INIT_STATUS_INITIALIZED
);
11381 add_loc_descr (&ret
, tmp
);
11382 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11383 VAR_INIT_STATUS_INITIALIZED
);
11386 add_loc_descr (&ret
, tmp
);
11387 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
11388 add_loc_descr (&ret
, l1label
);
11389 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11391 VAR_INIT_STATUS_INITIALIZED
);
11392 add_loc_descr (&ret
, tmp
);
11393 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
11394 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11395 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11396 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
11397 VAR_INIT_STATUS_INITIALIZED
);
11400 add_loc_descr (&ret
, tmp
);
11401 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11402 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
11403 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11404 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11405 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11406 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11407 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11408 VAR_INIT_STATUS_INITIALIZED
);
11409 add_loc_descr (&ret
, tmp
);
11410 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
11411 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11412 add_loc_descr (&ret
, l2jump
);
11413 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
11414 VAR_INIT_STATUS_INITIALIZED
);
11415 add_loc_descr (&ret
, tmp
);
11416 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11417 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11418 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11419 add_loc_descr (&ret
, l1jump
);
11420 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11421 add_loc_descr (&ret
, l2label
);
11422 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11423 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11424 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11425 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11426 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11427 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11431 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
11432 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11433 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
11434 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
11436 ROTATERT is similar:
11437 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
11438 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11439 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
11441 static dw_loc_descr_ref
11442 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11443 enum machine_mode mem_mode
)
11445 rtx rtlop1
= XEXP (rtl
, 1);
11446 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
11449 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11452 if (GET_MODE (rtlop1
) != VOIDmode
11453 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
11454 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
11455 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11456 VAR_INIT_STATUS_INITIALIZED
);
11457 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
11458 VAR_INIT_STATUS_INITIALIZED
);
11459 if (op0
== NULL
|| op1
== NULL
)
11461 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11462 for (i
= 0; i
< 2; i
++)
11464 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
11465 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
11467 VAR_INIT_STATUS_INITIALIZED
);
11468 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
11469 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11471 : HOST_BITS_PER_WIDE_INT
== 64
11472 ? DW_OP_const8u
: DW_OP_constu
,
11473 GET_MODE_MASK (mode
), 0);
11476 if (mask
[i
] == NULL
)
11478 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
11481 add_loc_descr (&ret
, op1
);
11482 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11483 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11484 if (GET_CODE (rtl
) == ROTATERT
)
11486 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11487 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11488 GET_MODE_BITSIZE (mode
), 0));
11490 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11491 if (mask
[0] != NULL
)
11492 add_loc_descr (&ret
, mask
[0]);
11493 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11494 if (mask
[1] != NULL
)
11496 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11497 add_loc_descr (&ret
, mask
[1]);
11498 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11500 if (GET_CODE (rtl
) == ROTATE
)
11502 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11503 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11504 GET_MODE_BITSIZE (mode
), 0));
11506 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11507 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11511 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11512 for DEBUG_PARAMETER_REF RTL. */
11514 static dw_loc_descr_ref
11515 parameter_ref_descriptor (rtx rtl
)
11517 dw_loc_descr_ref ret
;
11522 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
11523 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
11524 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
11527 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11528 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
11529 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11533 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
11534 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
11539 /* Helper function to get mode of MEM's address. */
11542 get_address_mode (rtx mem
)
11544 enum machine_mode mode
= GET_MODE (XEXP (mem
, 0));
11545 if (mode
!= VOIDmode
)
11547 return targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (mem
));
11550 /* The following routine converts the RTL for a variable or parameter
11551 (resident in memory) into an equivalent Dwarf representation of a
11552 mechanism for getting the address of that same variable onto the top of a
11553 hypothetical "address evaluation" stack.
11555 When creating memory location descriptors, we are effectively transforming
11556 the RTL for a memory-resident object into its Dwarf postfix expression
11557 equivalent. This routine recursively descends an RTL tree, turning
11558 it into Dwarf postfix code as it goes.
11560 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
11562 MEM_MODE is the mode of the memory reference, needed to handle some
11563 autoincrement addressing modes.
11565 Return 0 if we can't represent the location. */
11568 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11569 enum machine_mode mem_mode
,
11570 enum var_init_status initialized
)
11572 dw_loc_descr_ref mem_loc_result
= NULL
;
11573 enum dwarf_location_atom op
;
11574 dw_loc_descr_ref op0
, op1
;
11576 if (mode
== VOIDmode
)
11577 mode
= GET_MODE (rtl
);
11579 /* Note that for a dynamically sized array, the location we will generate a
11580 description of here will be the lowest numbered location which is
11581 actually within the array. That's *not* necessarily the same as the
11582 zeroth element of the array. */
11584 rtl
= targetm
.delegitimize_address (rtl
);
11586 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
11589 switch (GET_CODE (rtl
))
11594 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
11597 /* The case of a subreg may arise when we have a local (register)
11598 variable or a formal (register) parameter which doesn't quite fill
11599 up an entire register. For now, just assume that it is
11600 legitimate to make the Dwarf info refer to the whole register which
11601 contains the given subreg. */
11602 if (!subreg_lowpart_p (rtl
))
11604 if (GET_MODE_CLASS (mode
) == MODE_INT
11605 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl
))) == MODE_INT
11606 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11607 #ifdef POINTERS_EXTEND_UNSIGNED
11608 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
11611 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
))) <= DWARF2_ADDR_SIZE
)
11613 mem_loc_result
= mem_loc_descriptor (SUBREG_REG (rtl
),
11614 GET_MODE (SUBREG_REG (rtl
)),
11615 mem_mode
, initialized
);
11620 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
))))
11622 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
)))
11623 && (GET_MODE_CLASS (mode
) != MODE_INT
11624 || GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl
))) != MODE_INT
))
11628 dw_die_ref type_die
;
11629 dw_loc_descr_ref cvt
;
11631 mem_loc_result
= mem_loc_descriptor (SUBREG_REG (rtl
),
11632 GET_MODE (SUBREG_REG (rtl
)),
11633 mem_mode
, initialized
);
11634 if (mem_loc_result
== NULL
)
11636 type_die
= base_type_for_mode (mode
,
11637 GET_MODE_CLASS (mode
) == MODE_INT
);
11638 if (type_die
== NULL
)
11640 mem_loc_result
= NULL
;
11643 if (GET_MODE_SIZE (mode
)
11644 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
))))
11645 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11647 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
11648 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11649 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11650 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11651 add_loc_descr (&mem_loc_result
, cvt
);
11656 if (GET_MODE_CLASS (mode
) != MODE_INT
11657 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
11658 #ifdef POINTERS_EXTEND_UNSIGNED
11659 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
11663 dw_die_ref type_die
;
11667 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
11669 type_die
= base_type_for_mode (mode
,
11670 GET_MODE_CLASS (mode
) == MODE_INT
);
11671 if (type_die
== NULL
)
11673 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
11674 dbx_reg_number (rtl
), 0);
11675 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
11676 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
11677 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
11680 /* Whenever a register number forms a part of the description of the
11681 method for calculating the (dynamic) address of a memory resident
11682 object, DWARF rules require the register number be referred to as
11683 a "base register". This distinction is not based in any way upon
11684 what category of register the hardware believes the given register
11685 belongs to. This is strictly DWARF terminology we're dealing with
11686 here. Note that in cases where the location of a memory-resident
11687 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
11688 OP_CONST (0)) the actual DWARF location descriptor that we generate
11689 may just be OP_BASEREG (basereg). This may look deceptively like
11690 the object in question was allocated to a register (rather than in
11691 memory) so DWARF consumers need to be aware of the subtle
11692 distinction between OP_REG and OP_BASEREG. */
11693 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
11694 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
11695 else if (stack_realign_drap
11697 && crtl
->args
.internal_arg_pointer
== rtl
11698 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
11700 /* If RTL is internal_arg_pointer, which has been optimized
11701 out, use DRAP instead. */
11702 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
11703 VAR_INIT_STATUS_INITIALIZED
);
11709 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11711 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
11712 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
11715 else if (GET_CODE (rtl
) == ZERO_EXTEND
11716 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11717 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
11718 < HOST_BITS_PER_WIDE_INT
11719 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
11720 to expand zero extend as two shifts instead of
11722 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
11724 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
11725 mem_loc_result
= op0
;
11726 add_loc_descr (&mem_loc_result
,
11727 int_loc_descriptor (GET_MODE_MASK (imode
)));
11728 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
11730 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11732 int shift
= DWARF2_ADDR_SIZE
11733 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
11734 shift
*= BITS_PER_UNIT
;
11735 if (GET_CODE (rtl
) == SIGN_EXTEND
)
11739 mem_loc_result
= op0
;
11740 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
11741 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
11742 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
11743 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
11745 else if (!dwarf_strict
)
11747 dw_die_ref type_die1
, type_die2
;
11748 dw_loc_descr_ref cvt
;
11750 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
11751 GET_CODE (rtl
) == ZERO_EXTEND
);
11752 if (type_die1
== NULL
)
11754 type_die2
= base_type_for_mode (mode
, 1);
11755 if (type_die2
== NULL
)
11757 mem_loc_result
= op0
;
11758 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11759 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11760 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
11761 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11762 add_loc_descr (&mem_loc_result
, cvt
);
11763 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11764 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11765 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
11766 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11767 add_loc_descr (&mem_loc_result
, cvt
);
11773 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
11774 if (new_rtl
!= rtl
)
11776 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
11778 if (mem_loc_result
!= NULL
)
11779 return mem_loc_result
;
11782 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
11783 get_address_mode (rtl
), mode
,
11784 VAR_INIT_STATUS_INITIALIZED
);
11785 if (mem_loc_result
== NULL
)
11786 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
11787 if (mem_loc_result
!= NULL
)
11789 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
11790 || GET_MODE_CLASS (mode
) != MODE_INT
)
11792 dw_die_ref type_die
;
11793 dw_loc_descr_ref deref
;
11798 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
11799 if (type_die
== NULL
)
11801 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
11802 GET_MODE_SIZE (mode
), 0);
11803 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
11804 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
11805 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
11806 add_loc_descr (&mem_loc_result
, deref
);
11808 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11809 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
11811 add_loc_descr (&mem_loc_result
,
11812 new_loc_descr (DW_OP_deref_size
,
11813 GET_MODE_SIZE (mode
), 0));
11818 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
11821 /* Some ports can transform a symbol ref into a label ref, because
11822 the symbol ref is too far away and has to be dumped into a constant
11826 if (GET_MODE_CLASS (mode
) != MODE_INT
11827 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
11828 #ifdef POINTERS_EXTEND_UNSIGNED
11829 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
11833 if (GET_CODE (rtl
) == SYMBOL_REF
11834 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11836 dw_loc_descr_ref temp
;
11838 /* If this is not defined, we have no way to emit the data. */
11839 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
11842 /* We used to emit DW_OP_addr here, but that's wrong, since
11843 DW_OP_addr should be relocated by the debug info consumer,
11844 while DW_OP_GNU_push_tls_address operand should not. */
11845 temp
= new_loc_descr (DWARF2_ADDR_SIZE
== 4
11846 ? DW_OP_const4u
: DW_OP_const8u
, 0, 0);
11847 temp
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
11848 temp
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
11849 temp
->dtprel
= true;
11851 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
11852 add_loc_descr (&mem_loc_result
, temp
);
11857 if (!const_ok_for_output (rtl
))
11861 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
11862 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
11863 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
11864 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
11870 case DEBUG_IMPLICIT_PTR
:
11871 expansion_failed (NULL_TREE
, rtl
,
11872 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
11878 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
11880 if (GET_MODE_CLASS (mode
) != MODE_INT
11881 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11882 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
11883 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
11886 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl
)),
11887 VAR_INIT_STATUS_INITIALIZED
);
11889 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
11890 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
11892 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
11893 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
11894 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
11898 gcc_unreachable ();
11901 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
11902 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11903 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
11906 case DEBUG_PARAMETER_REF
:
11907 mem_loc_result
= parameter_ref_descriptor (rtl
);
11911 /* Extract the PLUS expression nested inside and fall into
11912 PLUS code below. */
11913 rtl
= XEXP (rtl
, 1);
11918 /* Turn these into a PLUS expression and fall into the PLUS code
11920 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
11921 GEN_INT (GET_CODE (rtl
) == PRE_INC
11922 ? GET_MODE_UNIT_SIZE (mem_mode
)
11923 : -GET_MODE_UNIT_SIZE (mem_mode
)));
11925 /* ... fall through ... */
11929 if (is_based_loc (rtl
)
11930 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11931 && GET_MODE_CLASS (mode
) == MODE_INT
)
11932 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
11933 INTVAL (XEXP (rtl
, 1)),
11934 VAR_INIT_STATUS_INITIALIZED
);
11937 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11938 VAR_INIT_STATUS_INITIALIZED
);
11939 if (mem_loc_result
== 0)
11942 if (CONST_INT_P (XEXP (rtl
, 1))
11943 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11944 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
11947 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11948 VAR_INIT_STATUS_INITIALIZED
);
11951 add_loc_descr (&mem_loc_result
, op1
);
11952 add_loc_descr (&mem_loc_result
,
11953 new_loc_descr (DW_OP_plus
, 0, 0));
11958 /* If a pseudo-reg is optimized away, it is possible for it to
11959 be replaced with a MEM containing a multiply or shift. */
11970 && GET_MODE_CLASS (mode
) == MODE_INT
11971 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11973 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
11974 base_type_for_mode (mode
, 0),
11998 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12000 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12001 VAR_INIT_STATUS_INITIALIZED
);
12003 rtx rtlop1
= XEXP (rtl
, 1);
12004 if (GET_MODE (rtlop1
) != VOIDmode
12005 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
12006 < GET_MODE_BITSIZE (mode
))
12007 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12008 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12009 VAR_INIT_STATUS_INITIALIZED
);
12012 if (op0
== 0 || op1
== 0)
12015 mem_loc_result
= op0
;
12016 add_loc_descr (&mem_loc_result
, op1
);
12017 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12033 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12034 VAR_INIT_STATUS_INITIALIZED
);
12035 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12036 VAR_INIT_STATUS_INITIALIZED
);
12038 if (op0
== 0 || op1
== 0)
12041 mem_loc_result
= op0
;
12042 add_loc_descr (&mem_loc_result
, op1
);
12043 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12047 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
12049 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
12050 base_type_for_mode (mode
, 0),
12055 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12056 VAR_INIT_STATUS_INITIALIZED
);
12057 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12058 VAR_INIT_STATUS_INITIALIZED
);
12060 if (op0
== 0 || op1
== 0)
12063 mem_loc_result
= op0
;
12064 add_loc_descr (&mem_loc_result
, op1
);
12065 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12066 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12067 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
12068 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
12069 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12073 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12075 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12080 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12081 base_type_for_mode (mode
, 1),
12099 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12100 VAR_INIT_STATUS_INITIALIZED
);
12105 mem_loc_result
= op0
;
12106 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12110 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12111 #ifdef POINTERS_EXTEND_UNSIGNED
12113 && mem_mode
!= VOIDmode
12114 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12118 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12122 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12123 || GET_MODE_BITSIZE (mode
) == 2 * HOST_BITS_PER_WIDE_INT
))
12125 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12126 enum machine_mode amode
;
12127 if (type_die
== NULL
)
12129 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12131 if (INTVAL (rtl
) >= 0
12132 && amode
!= BLKmode
12133 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12134 /* const DW_OP_GNU_convert <XXX> vs.
12135 DW_OP_GNU_const_type <XXX, 1, const>. */
12136 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12137 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12139 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12140 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12141 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12142 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12143 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12144 add_loc_descr (&mem_loc_result
, op0
);
12145 return mem_loc_result
;
12147 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12149 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12150 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12151 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12152 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12153 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12156 mem_loc_result
->dw_loc_oprnd2
.val_class
12157 = dw_val_class_const_double
;
12158 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12159 = shwi_to_double_int (INTVAL (rtl
));
12167 dw_die_ref type_die
;
12169 /* Note that a CONST_DOUBLE rtx could represent either an integer
12170 or a floating-point constant. A CONST_DOUBLE is used whenever
12171 the constant requires more than one word in order to be
12172 adequately represented. We output CONST_DOUBLEs as blocks. */
12173 if (mode
== VOIDmode
12174 || (GET_MODE (rtl
) == VOIDmode
12175 && GET_MODE_BITSIZE (mode
) != 2 * HOST_BITS_PER_WIDE_INT
))
12177 type_die
= base_type_for_mode (mode
,
12178 GET_MODE_CLASS (mode
) == MODE_INT
);
12179 if (type_die
== NULL
)
12181 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12182 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12183 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12184 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12185 if (SCALAR_FLOAT_MODE_P (mode
))
12187 unsigned int length
= GET_MODE_SIZE (mode
);
12188 unsigned char *array
12189 = (unsigned char*) ggc_alloc_atomic (length
);
12191 insert_float (rtl
, array
);
12192 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12193 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12194 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12195 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12199 mem_loc_result
->dw_loc_oprnd2
.val_class
12200 = dw_val_class_const_double
;
12201 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12202 = rtx_to_double_int (rtl
);
12208 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
12212 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12216 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12220 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12224 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12228 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
12232 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12236 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12240 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12244 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12249 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12254 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
12259 if (CONST_INT_P (XEXP (rtl
, 1))
12260 && CONST_INT_P (XEXP (rtl
, 2))
12261 && ((unsigned) INTVAL (XEXP (rtl
, 1))
12262 + (unsigned) INTVAL (XEXP (rtl
, 2))
12263 <= GET_MODE_BITSIZE (mode
))
12264 && GET_MODE_CLASS (mode
) == MODE_INT
12265 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12266 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
12269 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12270 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12273 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
12277 mem_loc_result
= op0
;
12278 size
= INTVAL (XEXP (rtl
, 1));
12279 shift
= INTVAL (XEXP (rtl
, 2));
12280 if (BITS_BIG_ENDIAN
)
12281 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12283 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
12285 add_loc_descr (&mem_loc_result
,
12286 int_loc_descriptor (DWARF2_ADDR_SIZE
12288 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12290 if (size
!= (int) DWARF2_ADDR_SIZE
)
12292 add_loc_descr (&mem_loc_result
,
12293 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
12294 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12301 dw_loc_descr_ref op2
, bra_node
, drop_node
;
12302 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
12303 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
12304 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
12305 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12306 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12307 VAR_INIT_STATUS_INITIALIZED
);
12308 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
12309 VAR_INIT_STATUS_INITIALIZED
);
12310 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
12313 mem_loc_result
= op1
;
12314 add_loc_descr (&mem_loc_result
, op2
);
12315 add_loc_descr (&mem_loc_result
, op0
);
12316 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12317 add_loc_descr (&mem_loc_result
, bra_node
);
12318 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
12319 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12320 add_loc_descr (&mem_loc_result
, drop_node
);
12321 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12322 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12327 case FLOAT_TRUNCATE
:
12329 case UNSIGNED_FLOAT
:
12334 dw_die_ref type_die
;
12335 dw_loc_descr_ref cvt
;
12337 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12338 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12341 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
12342 && (GET_CODE (rtl
) == FLOAT
12343 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
12344 <= DWARF2_ADDR_SIZE
))
12346 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12347 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
12348 if (type_die
== NULL
)
12350 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12351 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12352 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12353 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12354 add_loc_descr (&op0
, cvt
);
12356 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
12357 if (type_die
== NULL
)
12359 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12360 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12361 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12362 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12363 add_loc_descr (&op0
, cvt
);
12364 if (GET_MODE_CLASS (mode
) == MODE_INT
12365 && (GET_CODE (rtl
) == FIX
12366 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
12368 op0
= convert_descriptor_to_mode (mode
, op0
);
12372 mem_loc_result
= op0
;
12379 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
12384 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
12388 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
12393 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
12398 /* In theory, we could implement the above. */
12399 /* DWARF cannot represent the unsigned compare operations
12424 case FRACT_CONVERT
:
12425 case UNSIGNED_FRACT_CONVERT
:
12427 case UNSIGNED_SAT_FRACT
:
12433 case VEC_DUPLICATE
:
12437 case STRICT_LOW_PART
:
12441 /* If delegitimize_address couldn't do anything with the UNSPEC, we
12442 can't express it in the debug info. This can happen e.g. with some
12447 resolve_one_addr (&rtl
, NULL
);
12451 #ifdef ENABLE_CHECKING
12452 print_rtl (stderr
, rtl
);
12453 gcc_unreachable ();
12459 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12460 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12462 return mem_loc_result
;
12465 /* Return a descriptor that describes the concatenation of two locations.
12466 This is typically a complex variable. */
12468 static dw_loc_descr_ref
12469 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
12471 dw_loc_descr_ref cc_loc_result
= NULL
;
12472 dw_loc_descr_ref x0_ref
12473 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12474 dw_loc_descr_ref x1_ref
12475 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12477 if (x0_ref
== 0 || x1_ref
== 0)
12480 cc_loc_result
= x0_ref
;
12481 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
12483 add_loc_descr (&cc_loc_result
, x1_ref
);
12484 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
12486 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12487 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12489 return cc_loc_result
;
12492 /* Return a descriptor that describes the concatenation of N
12495 static dw_loc_descr_ref
12496 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
12499 dw_loc_descr_ref cc_loc_result
= NULL
;
12500 unsigned int n
= XVECLEN (concatn
, 0);
12502 for (i
= 0; i
< n
; ++i
)
12504 dw_loc_descr_ref ref
;
12505 rtx x
= XVECEXP (concatn
, 0, i
);
12507 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12511 add_loc_descr (&cc_loc_result
, ref
);
12512 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
12515 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12516 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12518 return cc_loc_result
;
12521 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12522 for DEBUG_IMPLICIT_PTR RTL. */
12524 static dw_loc_descr_ref
12525 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
12527 dw_loc_descr_ref ret
;
12532 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
12533 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
12534 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
12535 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
12536 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
12537 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12540 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12541 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12542 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12546 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12547 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
12552 /* Output a proper Dwarf location descriptor for a variable or parameter
12553 which is either allocated in a register or in a memory location. For a
12554 register, we just generate an OP_REG and the register number. For a
12555 memory location we provide a Dwarf postfix expression describing how to
12556 generate the (dynamic) address of the object onto the address stack.
12558 MODE is mode of the decl if this loc_descriptor is going to be used in
12559 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
12560 allowed, VOIDmode otherwise.
12562 If we don't know how to describe it, return 0. */
12564 static dw_loc_descr_ref
12565 loc_descriptor (rtx rtl
, enum machine_mode mode
,
12566 enum var_init_status initialized
)
12568 dw_loc_descr_ref loc_result
= NULL
;
12570 switch (GET_CODE (rtl
))
12573 /* The case of a subreg may arise when we have a local (register)
12574 variable or a formal (register) parameter which doesn't quite fill
12575 up an entire register. For now, just assume that it is
12576 legitimate to make the Dwarf info refer to the whole register which
12577 contains the given subreg. */
12578 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
12579 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
12580 GET_MODE (SUBREG_REG (rtl
)), initialized
);
12586 loc_result
= reg_loc_descriptor (rtl
, initialized
);
12590 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
12591 GET_MODE (rtl
), initialized
);
12592 if (loc_result
== NULL
)
12593 loc_result
= tls_mem_loc_descriptor (rtl
);
12594 if (loc_result
== NULL
)
12596 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12597 if (new_rtl
!= rtl
)
12598 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
12603 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
12608 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
12613 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
12615 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
12616 if (GET_CODE (loc
) == EXPR_LIST
)
12617 loc
= XEXP (loc
, 0);
12618 loc_result
= loc_descriptor (loc
, mode
, initialized
);
12622 rtl
= XEXP (rtl
, 1);
12627 rtvec par_elems
= XVEC (rtl
, 0);
12628 int num_elem
= GET_NUM_ELEM (par_elems
);
12629 enum machine_mode mode
;
12632 /* Create the first one, so we have something to add to. */
12633 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
12634 VOIDmode
, initialized
);
12635 if (loc_result
== NULL
)
12637 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
12638 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
12639 for (i
= 1; i
< num_elem
; i
++)
12641 dw_loc_descr_ref temp
;
12643 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
12644 VOIDmode
, initialized
);
12647 add_loc_descr (&loc_result
, temp
);
12648 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
12649 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
12655 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
12656 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
12661 if (mode
== VOIDmode
)
12662 mode
= GET_MODE (rtl
);
12664 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
12666 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
12668 /* Note that a CONST_DOUBLE rtx could represent either an integer
12669 or a floating-point constant. A CONST_DOUBLE is used whenever
12670 the constant requires more than one word in order to be
12671 adequately represented. We output CONST_DOUBLEs as blocks. */
12672 loc_result
= new_loc_descr (DW_OP_implicit_value
,
12673 GET_MODE_SIZE (mode
), 0);
12674 if (SCALAR_FLOAT_MODE_P (mode
))
12676 unsigned int length
= GET_MODE_SIZE (mode
);
12677 unsigned char *array
12678 = (unsigned char*) ggc_alloc_atomic (length
);
12680 insert_float (rtl
, array
);
12681 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12682 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12683 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12684 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12688 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
12689 loc_result
->dw_loc_oprnd2
.v
.val_double
12690 = rtx_to_double_int (rtl
);
12696 if (mode
== VOIDmode
)
12697 mode
= GET_MODE (rtl
);
12699 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
12701 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
12702 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
12703 unsigned char *array
= (unsigned char *)
12704 ggc_alloc_atomic (length
* elt_size
);
12708 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
12709 switch (GET_MODE_CLASS (mode
))
12711 case MODE_VECTOR_INT
:
12712 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
12714 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
12715 double_int val
= rtx_to_double_int (elt
);
12717 if (elt_size
<= sizeof (HOST_WIDE_INT
))
12718 insert_int (double_int_to_shwi (val
), elt_size
, p
);
12721 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
12722 insert_double (val
, p
);
12727 case MODE_VECTOR_FLOAT
:
12728 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
12730 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
12731 insert_float (elt
, p
);
12736 gcc_unreachable ();
12739 loc_result
= new_loc_descr (DW_OP_implicit_value
,
12740 length
* elt_size
, 0);
12741 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12742 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
12743 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
12744 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12749 if (mode
== VOIDmode
12750 || GET_CODE (XEXP (rtl
, 0)) == CONST_INT
12751 || GET_CODE (XEXP (rtl
, 0)) == CONST_DOUBLE
12752 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
12754 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
12759 if (!const_ok_for_output (rtl
))
12762 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
12763 && (dwarf_version
>= 4 || !dwarf_strict
))
12765 loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
12766 loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
12767 loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
12768 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
12769 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
12773 case DEBUG_IMPLICIT_PTR
:
12774 loc_result
= implicit_ptr_descriptor (rtl
, 0);
12778 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
12779 && CONST_INT_P (XEXP (rtl
, 1)))
12782 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
12788 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
12789 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
12790 && dwarf_version
>= 4)
12791 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
12793 /* Value expression. */
12794 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
12796 add_loc_descr (&loc_result
,
12797 new_loc_descr (DW_OP_stack_value
, 0, 0));
12805 /* We need to figure out what section we should use as the base for the
12806 address ranges where a given location is valid.
12807 1. If this particular DECL has a section associated with it, use that.
12808 2. If this function has a section associated with it, use that.
12809 3. Otherwise, use the text section.
12810 XXX: If you split a variable across multiple sections, we won't notice. */
12812 static const char *
12813 secname_for_decl (const_tree decl
)
12815 const char *secname
;
12817 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
12819 tree sectree
= DECL_SECTION_NAME (decl
);
12820 secname
= TREE_STRING_POINTER (sectree
);
12822 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
12824 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
12825 secname
= TREE_STRING_POINTER (sectree
);
12827 else if (cfun
&& in_cold_section_p
)
12828 secname
= crtl
->subsections
.cold_section_label
;
12830 secname
= text_section_label
;
12835 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
12838 decl_by_reference_p (tree decl
)
12840 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
12841 || TREE_CODE (decl
) == VAR_DECL
)
12842 && DECL_BY_REFERENCE (decl
));
12845 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
12848 static dw_loc_descr_ref
12849 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
12850 enum var_init_status initialized
)
12852 int have_address
= 0;
12853 dw_loc_descr_ref descr
;
12854 enum machine_mode mode
;
12856 if (want_address
!= 2)
12858 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
12860 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
12862 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
12863 if (GET_CODE (varloc
) == EXPR_LIST
)
12864 varloc
= XEXP (varloc
, 0);
12865 mode
= GET_MODE (varloc
);
12866 if (MEM_P (varloc
))
12868 rtx addr
= XEXP (varloc
, 0);
12869 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
12870 mode
, initialized
);
12875 rtx x
= avoid_constant_pool_reference (varloc
);
12877 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
12882 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
12889 if (GET_CODE (varloc
) == VAR_LOCATION
)
12890 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
12892 mode
= DECL_MODE (loc
);
12893 descr
= loc_descriptor (varloc
, mode
, initialized
);
12900 if (want_address
== 2 && !have_address
12901 && (dwarf_version
>= 4 || !dwarf_strict
))
12903 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
12905 expansion_failed (loc
, NULL_RTX
,
12906 "DWARF address size mismatch");
12909 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
12912 /* Show if we can't fill the request for an address. */
12913 if (want_address
&& !have_address
)
12915 expansion_failed (loc
, NULL_RTX
,
12916 "Want address and only have value");
12920 /* If we've got an address and don't want one, dereference. */
12921 if (!want_address
&& have_address
)
12923 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
12924 enum dwarf_location_atom op
;
12926 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
12928 expansion_failed (loc
, NULL_RTX
,
12929 "DWARF address size mismatch");
12932 else if (size
== DWARF2_ADDR_SIZE
)
12935 op
= DW_OP_deref_size
;
12937 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
12943 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
12944 if it is not possible. */
12946 static dw_loc_descr_ref
12947 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
12949 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
12950 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
12951 else if (dwarf_version
>= 3 || !dwarf_strict
)
12952 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
12957 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
12958 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
12960 static dw_loc_descr_ref
12961 dw_sra_loc_expr (tree decl
, rtx loc
)
12964 unsigned int padsize
= 0;
12965 dw_loc_descr_ref descr
, *descr_tail
;
12966 unsigned HOST_WIDE_INT decl_size
;
12968 enum var_init_status initialized
;
12970 if (DECL_SIZE (decl
) == NULL
12971 || !host_integerp (DECL_SIZE (decl
), 1))
12974 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
12976 descr_tail
= &descr
;
12978 for (p
= loc
; p
; p
= XEXP (p
, 1))
12980 unsigned int bitsize
= decl_piece_bitsize (p
);
12981 rtx loc_note
= *decl_piece_varloc_ptr (p
);
12982 dw_loc_descr_ref cur_descr
;
12983 dw_loc_descr_ref
*tail
, last
= NULL
;
12984 unsigned int opsize
= 0;
12986 if (loc_note
== NULL_RTX
12987 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
12989 padsize
+= bitsize
;
12992 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
12993 varloc
= NOTE_VAR_LOCATION (loc_note
);
12994 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
12995 if (cur_descr
== NULL
)
12997 padsize
+= bitsize
;
13001 /* Check that cur_descr either doesn't use
13002 DW_OP_*piece operations, or their sum is equal
13003 to bitsize. Otherwise we can't embed it. */
13004 for (tail
= &cur_descr
; *tail
!= NULL
;
13005 tail
= &(*tail
)->dw_loc_next
)
13006 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
13008 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
13012 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
13014 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
13018 if (last
!= NULL
&& opsize
!= bitsize
)
13020 padsize
+= bitsize
;
13024 /* If there is a hole, add DW_OP_*piece after empty DWARF
13025 expression, which means that those bits are optimized out. */
13028 if (padsize
> decl_size
)
13030 decl_size
-= padsize
;
13031 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
13032 if (*descr_tail
== NULL
)
13034 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13037 *descr_tail
= cur_descr
;
13039 if (bitsize
> decl_size
)
13041 decl_size
-= bitsize
;
13044 HOST_WIDE_INT offset
= 0;
13045 if (GET_CODE (varloc
) == VAR_LOCATION
13046 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13048 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13049 if (GET_CODE (varloc
) == EXPR_LIST
)
13050 varloc
= XEXP (varloc
, 0);
13054 if (GET_CODE (varloc
) == CONST
13055 || GET_CODE (varloc
) == SIGN_EXTEND
13056 || GET_CODE (varloc
) == ZERO_EXTEND
)
13057 varloc
= XEXP (varloc
, 0);
13058 else if (GET_CODE (varloc
) == SUBREG
)
13059 varloc
= SUBREG_REG (varloc
);
13064 /* DW_OP_bit_size offset should be zero for register
13065 or implicit location descriptions and empty location
13066 descriptions, but for memory addresses needs big endian
13068 if (MEM_P (varloc
))
13070 unsigned HOST_WIDE_INT memsize
13071 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13072 if (memsize
!= bitsize
)
13074 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13075 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13077 if (memsize
< bitsize
)
13079 if (BITS_BIG_ENDIAN
)
13080 offset
= memsize
- bitsize
;
13084 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13085 if (*descr_tail
== NULL
)
13087 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13091 /* If there were any non-empty expressions, add padding till the end of
13093 if (descr
!= NULL
&& decl_size
!= 0)
13095 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13096 if (*descr_tail
== NULL
)
13102 /* Return the dwarf representation of the location list LOC_LIST of
13103 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13106 static dw_loc_list_ref
13107 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13109 const char *endname
, *secname
;
13111 enum var_init_status initialized
;
13112 struct var_loc_node
*node
;
13113 dw_loc_descr_ref descr
;
13114 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13115 dw_loc_list_ref list
= NULL
;
13116 dw_loc_list_ref
*listp
= &list
;
13118 /* Now that we know what section we are using for a base,
13119 actually construct the list of locations.
13120 The first location information is what is passed to the
13121 function that creates the location list, and the remaining
13122 locations just get added on to that list.
13123 Note that we only know the start address for a location
13124 (IE location changes), so to build the range, we use
13125 the range [current location start, next location start].
13126 This means we have to special case the last node, and generate
13127 a range of [last location start, end of function label]. */
13129 secname
= secname_for_decl (decl
);
13131 for (node
= loc_list
->first
; node
; node
= node
->next
)
13132 if (GET_CODE (node
->loc
) == EXPR_LIST
13133 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13135 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13137 /* This requires DW_OP_{,bit_}piece, which is not usable
13138 inside DWARF expressions. */
13139 if (want_address
!= 2)
13141 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13147 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13148 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13149 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
13153 bool range_across_switch
= false;
13154 /* If section switch happens in between node->label
13155 and node->next->label (or end of function) and
13156 we can't emit it as a single entry list,
13157 emit two ranges, first one ending at the end
13158 of first partition and second one starting at the
13159 beginning of second partition. */
13160 if (node
== loc_list
->last_before_switch
13161 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
13162 && current_function_decl
)
13164 endname
= cfun
->fde
->dw_fde_end
;
13165 range_across_switch
= true;
13167 /* The variable has a location between NODE->LABEL and
13168 NODE->NEXT->LABEL. */
13169 else if (node
->next
)
13170 endname
= node
->next
->label
;
13171 /* If the variable has a location at the last label
13172 it keeps its location until the end of function. */
13173 else if (!current_function_decl
)
13174 endname
= text_end_label
;
13177 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13178 current_function_funcdef_no
);
13179 endname
= ggc_strdup (label_id
);
13182 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
13183 if (TREE_CODE (decl
) == PARM_DECL
13184 && node
== loc_list
->first
13185 && GET_CODE (node
->loc
) == NOTE
13186 && strcmp (node
->label
, endname
) == 0)
13187 (*listp
)->force
= true;
13188 listp
= &(*listp
)->dw_loc_next
;
13190 if (range_across_switch
)
13192 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13193 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13196 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13197 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13198 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
13201 gcc_assert (descr
);
13202 /* The variable has a location between NODE->LABEL and
13203 NODE->NEXT->LABEL. */
13205 endname
= node
->next
->label
;
13207 endname
= cfun
->fde
->dw_fde_second_end
;
13208 *listp
= new_loc_list (descr
,
13209 cfun
->fde
->dw_fde_second_begin
,
13211 listp
= &(*listp
)->dw_loc_next
;
13216 /* Try to avoid the overhead of a location list emitting a location
13217 expression instead, but only if we didn't have more than one
13218 location entry in the first place. If some entries were not
13219 representable, we don't want to pretend a single entry that was
13220 applies to the entire scope in which the variable is
13222 if (list
&& loc_list
->first
->next
)
13228 /* Return if the loc_list has only single element and thus can be represented
13229 as location description. */
13232 single_element_loc_list_p (dw_loc_list_ref list
)
13234 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
13235 return !list
->ll_symbol
;
13238 /* To each location in list LIST add loc descr REF. */
13241 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
13243 dw_loc_descr_ref copy
;
13244 add_loc_descr (&list
->expr
, ref
);
13245 list
= list
->dw_loc_next
;
13248 copy
= ggc_alloc_dw_loc_descr_node ();
13249 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
13250 add_loc_descr (&list
->expr
, copy
);
13251 while (copy
->dw_loc_next
)
13253 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
13254 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
13255 copy
->dw_loc_next
= new_copy
;
13258 list
= list
->dw_loc_next
;
13262 /* Given two lists RET and LIST
13263 produce location list that is result of adding expression in LIST
13264 to expression in RET on each possition in program.
13265 Might be destructive on both RET and LIST.
13267 TODO: We handle only simple cases of RET or LIST having at most one
13268 element. General case would inolve sorting the lists in program order
13269 and merging them that will need some additional work.
13270 Adding that will improve quality of debug info especially for SRA-ed
13274 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
13283 if (!list
->dw_loc_next
)
13285 add_loc_descr_to_each (*ret
, list
->expr
);
13288 if (!(*ret
)->dw_loc_next
)
13290 add_loc_descr_to_each (list
, (*ret
)->expr
);
13294 expansion_failed (NULL_TREE
, NULL_RTX
,
13295 "Don't know how to merge two non-trivial"
13296 " location lists.\n");
13301 /* LOC is constant expression. Try a luck, look it up in constant
13302 pool and return its loc_descr of its address. */
13304 static dw_loc_descr_ref
13305 cst_pool_loc_descr (tree loc
)
13307 /* Get an RTL for this, if something has been emitted. */
13308 rtx rtl
= lookup_constant_def (loc
);
13310 if (!rtl
|| !MEM_P (rtl
))
13315 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
13317 /* TODO: We might get more coverage if we was actually delaying expansion
13318 of all expressions till end of compilation when constant pools are fully
13320 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
13322 expansion_failed (loc
, NULL_RTX
,
13323 "CST value in contant pool but not marked.");
13326 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13327 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
13330 /* Return dw_loc_list representing address of addr_expr LOC
13331 by looking for inner INDIRECT_REF expression and turning
13332 it into simple arithmetics. */
13334 static dw_loc_list_ref
13335 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
13338 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13339 enum machine_mode mode
;
13340 int unsignedp
, volatilep
= 0;
13341 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13343 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
13344 &bitsize
, &bitpos
, &offset
, &mode
,
13345 &unsignedp
, &volatilep
, false);
13347 if (bitpos
% BITS_PER_UNIT
)
13349 expansion_failed (loc
, NULL_RTX
, "bitfield access");
13352 if (!INDIRECT_REF_P (obj
))
13354 expansion_failed (obj
,
13355 NULL_RTX
, "no indirect ref in inner refrence");
13358 if (!offset
&& !bitpos
)
13359 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
13361 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
13362 && (dwarf_version
>= 4 || !dwarf_strict
))
13364 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
13369 /* Variable offset. */
13370 list_ret1
= loc_list_from_tree (offset
, 0);
13371 if (list_ret1
== 0)
13373 add_loc_list (&list_ret
, list_ret1
);
13376 add_loc_descr_to_each (list_ret
,
13377 new_loc_descr (DW_OP_plus
, 0, 0));
13379 bytepos
= bitpos
/ BITS_PER_UNIT
;
13381 add_loc_descr_to_each (list_ret
,
13382 new_loc_descr (DW_OP_plus_uconst
,
13384 else if (bytepos
< 0)
13385 loc_list_plus_const (list_ret
, bytepos
);
13386 add_loc_descr_to_each (list_ret
,
13387 new_loc_descr (DW_OP_stack_value
, 0, 0));
13393 /* Generate Dwarf location list representing LOC.
13394 If WANT_ADDRESS is false, expression computing LOC will be computed
13395 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13396 if WANT_ADDRESS is 2, expression computing address useable in location
13397 will be returned (i.e. DW_OP_reg can be used
13398 to refer to register values). */
13400 static dw_loc_list_ref
13401 loc_list_from_tree (tree loc
, int want_address
)
13403 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
13404 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13405 int have_address
= 0;
13406 enum dwarf_location_atom op
;
13408 /* ??? Most of the time we do not take proper care for sign/zero
13409 extending the values properly. Hopefully this won't be a real
13412 switch (TREE_CODE (loc
))
13415 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
13418 case PLACEHOLDER_EXPR
:
13419 /* This case involves extracting fields from an object to determine the
13420 position of other fields. We don't try to encode this here. The
13421 only user of this is Ada, which encodes the needed information using
13422 the names of types. */
13423 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
13427 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
13428 /* There are no opcodes for these operations. */
13431 case PREINCREMENT_EXPR
:
13432 case PREDECREMENT_EXPR
:
13433 case POSTINCREMENT_EXPR
:
13434 case POSTDECREMENT_EXPR
:
13435 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
13436 /* There are no opcodes for these operations. */
13440 /* If we already want an address, see if there is INDIRECT_REF inside
13441 e.g. for &this->field. */
13444 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
13445 (loc
, want_address
== 2);
13448 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
13449 && (ret
= cst_pool_loc_descr (loc
)))
13452 /* Otherwise, process the argument and look for the address. */
13453 if (!list_ret
&& !ret
)
13454 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
13458 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
13464 if (DECL_THREAD_LOCAL_P (loc
))
13467 enum dwarf_location_atom first_op
;
13468 enum dwarf_location_atom second_op
;
13469 bool dtprel
= false;
13471 if (targetm
.have_tls
)
13473 /* If this is not defined, we have no way to emit the
13475 if (!targetm
.asm_out
.output_dwarf_dtprel
)
13478 /* The way DW_OP_GNU_push_tls_address is specified, we
13479 can only look up addresses of objects in the current
13480 module. We used DW_OP_addr as first op, but that's
13481 wrong, because DW_OP_addr is relocated by the debug
13482 info consumer, while DW_OP_GNU_push_tls_address
13483 operand shouldn't be. */
13484 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
13486 first_op
= DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
;
13488 second_op
= DW_OP_GNU_push_tls_address
;
13492 if (!targetm
.emutls
.debug_form_tls_address
13493 || !(dwarf_version
>= 3 || !dwarf_strict
))
13495 /* We stuffed the control variable into the DECL_VALUE_EXPR
13496 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13497 no longer appear in gimple code. We used the control
13498 variable in specific so that we could pick it up here. */
13499 loc
= DECL_VALUE_EXPR (loc
);
13500 first_op
= DW_OP_addr
;
13501 second_op
= DW_OP_form_tls_address
;
13504 rtl
= rtl_for_decl_location (loc
);
13505 if (rtl
== NULL_RTX
)
13510 rtl
= XEXP (rtl
, 0);
13511 if (! CONSTANT_P (rtl
))
13514 ret
= new_loc_descr (first_op
, 0, 0);
13515 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
13516 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
13517 ret
->dtprel
= dtprel
;
13519 ret1
= new_loc_descr (second_op
, 0, 0);
13520 add_loc_descr (&ret
, ret1
);
13529 if (DECL_HAS_VALUE_EXPR_P (loc
))
13530 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
13534 case FUNCTION_DECL
:
13537 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
13539 if (loc_list
&& loc_list
->first
)
13541 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
13542 have_address
= want_address
!= 0;
13545 rtl
= rtl_for_decl_location (loc
);
13546 if (rtl
== NULL_RTX
)
13548 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
13551 else if (CONST_INT_P (rtl
))
13553 HOST_WIDE_INT val
= INTVAL (rtl
);
13554 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13555 val
&= GET_MODE_MASK (DECL_MODE (loc
));
13556 ret
= int_loc_descriptor (val
);
13558 else if (GET_CODE (rtl
) == CONST_STRING
)
13560 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
13563 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
13565 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
13566 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
13567 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
13571 enum machine_mode mode
, mem_mode
;
13573 /* Certain constructs can only be represented at top-level. */
13574 if (want_address
== 2)
13576 ret
= loc_descriptor (rtl
, VOIDmode
,
13577 VAR_INIT_STATUS_INITIALIZED
);
13582 mode
= GET_MODE (rtl
);
13583 mem_mode
= VOIDmode
;
13587 mode
= get_address_mode (rtl
);
13588 rtl
= XEXP (rtl
, 0);
13591 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
13592 VAR_INIT_STATUS_INITIALIZED
);
13595 expansion_failed (loc
, rtl
,
13596 "failed to produce loc descriptor for rtl");
13603 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
13607 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13611 case COMPOUND_EXPR
:
13612 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
13615 case VIEW_CONVERT_EXPR
:
13618 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
13620 case COMPONENT_REF
:
13621 case BIT_FIELD_REF
:
13623 case ARRAY_RANGE_REF
:
13624 case REALPART_EXPR
:
13625 case IMAGPART_EXPR
:
13628 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13629 enum machine_mode mode
;
13630 int unsignedp
, volatilep
= 0;
13632 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
13633 &unsignedp
, &volatilep
, false);
13635 gcc_assert (obj
!= loc
);
13637 list_ret
= loc_list_from_tree (obj
,
13639 && !bitpos
&& !offset
? 2 : 1);
13640 /* TODO: We can extract value of the small expression via shifting even
13641 for nonzero bitpos. */
13644 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
13646 expansion_failed (loc
, NULL_RTX
,
13647 "bitfield access");
13651 if (offset
!= NULL_TREE
)
13653 /* Variable offset. */
13654 list_ret1
= loc_list_from_tree (offset
, 0);
13655 if (list_ret1
== 0)
13657 add_loc_list (&list_ret
, list_ret1
);
13660 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
13663 bytepos
= bitpos
/ BITS_PER_UNIT
;
13665 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
13666 else if (bytepos
< 0)
13667 loc_list_plus_const (list_ret
, bytepos
);
13674 if ((want_address
|| !host_integerp (loc
, 0))
13675 && (ret
= cst_pool_loc_descr (loc
)))
13677 else if (want_address
== 2
13678 && host_integerp (loc
, 0)
13679 && (ret
= address_of_int_loc_descriptor
13680 (int_size_in_bytes (TREE_TYPE (loc
)),
13681 tree_low_cst (loc
, 0))))
13683 else if (host_integerp (loc
, 0))
13684 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
13687 expansion_failed (loc
, NULL_RTX
,
13688 "Integer operand is not host integer");
13697 if ((ret
= cst_pool_loc_descr (loc
)))
13700 /* We can construct small constants here using int_loc_descriptor. */
13701 expansion_failed (loc
, NULL_RTX
,
13702 "constructor or constant not in constant pool");
13705 case TRUTH_AND_EXPR
:
13706 case TRUTH_ANDIF_EXPR
:
13711 case TRUTH_XOR_EXPR
:
13716 case TRUTH_OR_EXPR
:
13717 case TRUTH_ORIF_EXPR
:
13722 case FLOOR_DIV_EXPR
:
13723 case CEIL_DIV_EXPR
:
13724 case ROUND_DIV_EXPR
:
13725 case TRUNC_DIV_EXPR
:
13726 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13735 case FLOOR_MOD_EXPR
:
13736 case CEIL_MOD_EXPR
:
13737 case ROUND_MOD_EXPR
:
13738 case TRUNC_MOD_EXPR
:
13739 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13744 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13745 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
13746 if (list_ret
== 0 || list_ret1
== 0)
13749 add_loc_list (&list_ret
, list_ret1
);
13752 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
13753 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
13754 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
13755 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
13756 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
13768 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
13771 case POINTER_PLUS_EXPR
:
13773 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
13775 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13779 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
13787 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
13794 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
13801 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
13808 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
13823 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13824 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
13825 if (list_ret
== 0 || list_ret1
== 0)
13828 add_loc_list (&list_ret
, list_ret1
);
13831 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
13834 case TRUTH_NOT_EXPR
:
13848 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13852 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
13858 const enum tree_code code
=
13859 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
13861 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
13862 build2 (code
, integer_type_node
,
13863 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
13864 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
13867 /* ... fall through ... */
13871 dw_loc_descr_ref lhs
13872 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
13873 dw_loc_list_ref rhs
13874 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
13875 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
13877 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13878 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
13881 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13882 add_loc_descr_to_each (list_ret
, bra_node
);
13884 add_loc_list (&list_ret
, rhs
);
13885 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
13886 add_loc_descr_to_each (list_ret
, jump_node
);
13888 add_loc_descr_to_each (list_ret
, lhs
);
13889 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13890 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
13892 /* ??? Need a node to point the skip at. Use a nop. */
13893 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
13894 add_loc_descr_to_each (list_ret
, tmp
);
13895 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13896 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
13900 case FIX_TRUNC_EXPR
:
13904 /* Leave front-end specific codes as simply unknown. This comes
13905 up, for instance, with the C STMT_EXPR. */
13906 if ((unsigned int) TREE_CODE (loc
)
13907 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
13909 expansion_failed (loc
, NULL_RTX
,
13910 "language specific tree node");
13914 #ifdef ENABLE_CHECKING
13915 /* Otherwise this is a generic code; we should just lists all of
13916 these explicitly. We forgot one. */
13917 gcc_unreachable ();
13919 /* In a release build, we want to degrade gracefully: better to
13920 generate incomplete debugging information than to crash. */
13925 if (!ret
&& !list_ret
)
13928 if (want_address
== 2 && !have_address
13929 && (dwarf_version
>= 4 || !dwarf_strict
))
13931 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13933 expansion_failed (loc
, NULL_RTX
,
13934 "DWARF address size mismatch");
13938 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13940 add_loc_descr_to_each (list_ret
,
13941 new_loc_descr (DW_OP_stack_value
, 0, 0));
13944 /* Show if we can't fill the request for an address. */
13945 if (want_address
&& !have_address
)
13947 expansion_failed (loc
, NULL_RTX
,
13948 "Want address and only have value");
13952 gcc_assert (!ret
|| !list_ret
);
13954 /* If we've got an address and don't want one, dereference. */
13955 if (!want_address
&& have_address
)
13957 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13959 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13961 expansion_failed (loc
, NULL_RTX
,
13962 "DWARF address size mismatch");
13965 else if (size
== DWARF2_ADDR_SIZE
)
13968 op
= DW_OP_deref_size
;
13971 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
13973 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
13976 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
13981 /* Same as above but return only single location expression. */
13982 static dw_loc_descr_ref
13983 loc_descriptor_from_tree (tree loc
, int want_address
)
13985 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
13988 if (ret
->dw_loc_next
)
13990 expansion_failed (loc
, NULL_RTX
,
13991 "Location list where only loc descriptor needed");
13997 /* Given a value, round it up to the lowest multiple of `boundary'
13998 which is not less than the value itself. */
14000 static inline HOST_WIDE_INT
14001 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
14003 return (((value
+ boundary
- 1) / boundary
) * boundary
);
14006 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14007 pointer to the declared type for the relevant field variable, or return
14008 `integer_type_node' if the given node turns out to be an
14009 ERROR_MARK node. */
14012 field_type (const_tree decl
)
14016 if (TREE_CODE (decl
) == ERROR_MARK
)
14017 return integer_type_node
;
14019 type
= DECL_BIT_FIELD_TYPE (decl
);
14020 if (type
== NULL_TREE
)
14021 type
= TREE_TYPE (decl
);
14026 /* Given a pointer to a tree node, return the alignment in bits for
14027 it, or else return BITS_PER_WORD if the node actually turns out to
14028 be an ERROR_MARK node. */
14030 static inline unsigned
14031 simple_type_align_in_bits (const_tree type
)
14033 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
14036 static inline unsigned
14037 simple_decl_align_in_bits (const_tree decl
)
14039 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
14042 /* Return the result of rounding T up to ALIGN. */
14044 static inline double_int
14045 round_up_to_align (double_int t
, unsigned int align
)
14047 double_int alignd
= uhwi_to_double_int (align
);
14048 t
= double_int_add (t
, alignd
);
14049 t
= double_int_add (t
, double_int_minus_one
);
14050 t
= double_int_div (t
, alignd
, true, TRUNC_DIV_EXPR
);
14051 t
= double_int_mul (t
, alignd
);
14055 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14056 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14057 or return 0 if we are unable to determine what that offset is, either
14058 because the argument turns out to be a pointer to an ERROR_MARK node, or
14059 because the offset is actually variable. (We can't handle the latter case
14062 static HOST_WIDE_INT
14063 field_byte_offset (const_tree decl
)
14065 double_int object_offset_in_bits
;
14066 double_int object_offset_in_bytes
;
14067 double_int bitpos_int
;
14069 if (TREE_CODE (decl
) == ERROR_MARK
)
14072 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14074 /* We cannot yet cope with fields whose positions are variable, so
14075 for now, when we see such things, we simply return 0. Someday, we may
14076 be able to handle such cases, but it will be damn difficult. */
14077 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14080 bitpos_int
= tree_to_double_int (bit_position (decl
));
14082 #ifdef PCC_BITFIELD_TYPE_MATTERS
14083 if (PCC_BITFIELD_TYPE_MATTERS
)
14086 tree field_size_tree
;
14087 double_int deepest_bitpos
;
14088 double_int field_size_in_bits
;
14089 unsigned int type_align_in_bits
;
14090 unsigned int decl_align_in_bits
;
14091 double_int type_size_in_bits
;
14093 type
= field_type (decl
);
14094 type_size_in_bits
= double_int_type_size_in_bits (type
);
14095 type_align_in_bits
= simple_type_align_in_bits (type
);
14097 field_size_tree
= DECL_SIZE (decl
);
14099 /* The size could be unspecified if there was an error, or for
14100 a flexible array member. */
14101 if (!field_size_tree
)
14102 field_size_tree
= bitsize_zero_node
;
14104 /* If the size of the field is not constant, use the type size. */
14105 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14106 field_size_in_bits
= tree_to_double_int (field_size_tree
);
14108 field_size_in_bits
= type_size_in_bits
;
14110 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14112 /* The GCC front-end doesn't make any attempt to keep track of the
14113 starting bit offset (relative to the start of the containing
14114 structure type) of the hypothetical "containing object" for a
14115 bit-field. Thus, when computing the byte offset value for the
14116 start of the "containing object" of a bit-field, we must deduce
14117 this information on our own. This can be rather tricky to do in
14118 some cases. For example, handling the following structure type
14119 definition when compiling for an i386/i486 target (which only
14120 aligns long long's to 32-bit boundaries) can be very tricky:
14122 struct S { int field1; long long field2:31; };
14124 Fortunately, there is a simple rule-of-thumb which can be used
14125 in such cases. When compiling for an i386/i486, GCC will
14126 allocate 8 bytes for the structure shown above. It decides to
14127 do this based upon one simple rule for bit-field allocation.
14128 GCC allocates each "containing object" for each bit-field at
14129 the first (i.e. lowest addressed) legitimate alignment boundary
14130 (based upon the required minimum alignment for the declared
14131 type of the field) which it can possibly use, subject to the
14132 condition that there is still enough available space remaining
14133 in the containing object (when allocated at the selected point)
14134 to fully accommodate all of the bits of the bit-field itself.
14136 This simple rule makes it obvious why GCC allocates 8 bytes for
14137 each object of the structure type shown above. When looking
14138 for a place to allocate the "containing object" for `field2',
14139 the compiler simply tries to allocate a 64-bit "containing
14140 object" at each successive 32-bit boundary (starting at zero)
14141 until it finds a place to allocate that 64- bit field such that
14142 at least 31 contiguous (and previously unallocated) bits remain
14143 within that selected 64 bit field. (As it turns out, for the
14144 example above, the compiler finds it is OK to allocate the
14145 "containing object" 64-bit field at bit-offset zero within the
14148 Here we attempt to work backwards from the limited set of facts
14149 we're given, and we try to deduce from those facts, where GCC
14150 must have believed that the containing object started (within
14151 the structure type). The value we deduce is then used (by the
14152 callers of this routine) to generate DW_AT_location and
14153 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14154 the case of DW_AT_location, regular fields as well). */
14156 /* Figure out the bit-distance from the start of the structure to
14157 the "deepest" bit of the bit-field. */
14158 deepest_bitpos
= double_int_add (bitpos_int
, field_size_in_bits
);
14160 /* This is the tricky part. Use some fancy footwork to deduce
14161 where the lowest addressed bit of the containing object must
14163 object_offset_in_bits
14164 = double_int_sub (deepest_bitpos
, type_size_in_bits
);
14166 /* Round up to type_align by default. This works best for
14168 object_offset_in_bits
14169 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
14171 if (double_int_ucmp (object_offset_in_bits
, bitpos_int
) > 0)
14173 object_offset_in_bits
14174 = double_int_sub (deepest_bitpos
, type_size_in_bits
);
14176 /* Round up to decl_align instead. */
14177 object_offset_in_bits
14178 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
14182 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14183 object_offset_in_bits
= bitpos_int
;
14185 object_offset_in_bytes
14186 = double_int_div (object_offset_in_bits
,
14187 uhwi_to_double_int (BITS_PER_UNIT
), true,
14189 return double_int_to_shwi (object_offset_in_bytes
);
14192 /* The following routines define various Dwarf attributes and any data
14193 associated with them. */
14195 /* Add a location description attribute value to a DIE.
14197 This emits location attributes suitable for whole variables and
14198 whole parameters. Note that the location attributes for struct fields are
14199 generated by the routine `data_member_location_attribute' below. */
14202 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
14203 dw_loc_list_ref descr
)
14207 if (single_element_loc_list_p (descr
))
14208 add_AT_loc (die
, attr_kind
, descr
->expr
);
14210 add_AT_loc_list (die
, attr_kind
, descr
);
14213 /* Add DW_AT_accessibility attribute to DIE if needed. */
14216 add_accessibility_attribute (dw_die_ref die
, tree decl
)
14218 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14219 children, otherwise the default is DW_ACCESS_public. In DWARF2
14220 the default has always been DW_ACCESS_public. */
14221 if (TREE_PROTECTED (decl
))
14222 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14223 else if (TREE_PRIVATE (decl
))
14225 if (dwarf_version
== 2
14226 || die
->die_parent
== NULL
14227 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
14228 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
14230 else if (dwarf_version
> 2
14232 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
14233 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14236 /* Attach the specialized form of location attribute used for data members of
14237 struct and union types. In the special case of a FIELD_DECL node which
14238 represents a bit-field, the "offset" part of this special location
14239 descriptor must indicate the distance in bytes from the lowest-addressed
14240 byte of the containing struct or union type to the lowest-addressed byte of
14241 the "containing object" for the bit-field. (See the `field_byte_offset'
14244 For any given bit-field, the "containing object" is a hypothetical object
14245 (of some integral or enum type) within which the given bit-field lives. The
14246 type of this hypothetical "containing object" is always the same as the
14247 declared type of the individual bit-field itself (for GCC anyway... the
14248 DWARF spec doesn't actually mandate this). Note that it is the size (in
14249 bytes) of the hypothetical "containing object" which will be given in the
14250 DW_AT_byte_size attribute for this bit-field. (See the
14251 `byte_size_attribute' function below.) It is also used when calculating the
14252 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14253 function below.) */
14256 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
14258 HOST_WIDE_INT offset
;
14259 dw_loc_descr_ref loc_descr
= 0;
14261 if (TREE_CODE (decl
) == TREE_BINFO
)
14263 /* We're working on the TAG_inheritance for a base class. */
14264 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
14266 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14267 aren't at a fixed offset from all (sub)objects of the same
14268 type. We need to extract the appropriate offset from our
14269 vtable. The following dwarf expression means
14271 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14273 This is specific to the V3 ABI, of course. */
14275 dw_loc_descr_ref tmp
;
14277 /* Make a copy of the object address. */
14278 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
14279 add_loc_descr (&loc_descr
, tmp
);
14281 /* Extract the vtable address. */
14282 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14283 add_loc_descr (&loc_descr
, tmp
);
14285 /* Calculate the address of the offset. */
14286 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
14287 gcc_assert (offset
< 0);
14289 tmp
= int_loc_descriptor (-offset
);
14290 add_loc_descr (&loc_descr
, tmp
);
14291 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
14292 add_loc_descr (&loc_descr
, tmp
);
14294 /* Extract the offset. */
14295 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14296 add_loc_descr (&loc_descr
, tmp
);
14298 /* Add it to the object address. */
14299 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
14300 add_loc_descr (&loc_descr
, tmp
);
14303 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
14306 offset
= field_byte_offset (decl
);
14310 if (dwarf_version
> 2)
14312 /* Don't need to output a location expression, just the constant. */
14314 add_AT_int (die
, DW_AT_data_member_location
, offset
);
14316 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
14321 enum dwarf_location_atom op
;
14323 /* The DWARF2 standard says that we should assume that the structure
14324 address is already on the stack, so we can specify a structure
14325 field address by using DW_OP_plus_uconst. */
14326 op
= DW_OP_plus_uconst
;
14327 loc_descr
= new_loc_descr (op
, offset
, 0);
14331 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
14334 /* Writes integer values to dw_vec_const array. */
14337 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
14341 *dest
++ = val
& 0xff;
14347 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14349 static HOST_WIDE_INT
14350 extract_int (const unsigned char *src
, unsigned int size
)
14352 HOST_WIDE_INT val
= 0;
14358 val
|= *--src
& 0xff;
14364 /* Writes double_int values to dw_vec_const array. */
14367 insert_double (double_int val
, unsigned char *dest
)
14369 unsigned char *p0
= dest
;
14370 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
14372 if (WORDS_BIG_ENDIAN
)
14378 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
14379 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
14382 /* Writes floating point values to dw_vec_const array. */
14385 insert_float (const_rtx rtl
, unsigned char *array
)
14387 REAL_VALUE_TYPE rv
;
14391 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
14392 real_to_target (val
, &rv
, GET_MODE (rtl
));
14394 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14395 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
14397 insert_int (val
[i
], 4, array
);
14402 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14403 does not have a "location" either in memory or in a register. These
14404 things can arise in GNU C when a constant is passed as an actual parameter
14405 to an inlined function. They can also arise in C++ where declared
14406 constants do not necessarily get memory "homes". */
14409 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
14411 switch (GET_CODE (rtl
))
14415 HOST_WIDE_INT val
= INTVAL (rtl
);
14418 add_AT_int (die
, DW_AT_const_value
, val
);
14420 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
14425 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14426 floating-point constant. A CONST_DOUBLE is used whenever the
14427 constant requires more than one word in order to be adequately
14430 enum machine_mode mode
= GET_MODE (rtl
);
14432 if (SCALAR_FLOAT_MODE_P (mode
))
14434 unsigned int length
= GET_MODE_SIZE (mode
);
14435 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
14437 insert_float (rtl
, array
);
14438 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
14441 add_AT_double (die
, DW_AT_const_value
,
14442 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
14448 enum machine_mode mode
= GET_MODE (rtl
);
14449 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
14450 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
14451 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
14452 (length
* elt_size
);
14456 switch (GET_MODE_CLASS (mode
))
14458 case MODE_VECTOR_INT
:
14459 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14461 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14462 double_int val
= rtx_to_double_int (elt
);
14464 if (elt_size
<= sizeof (HOST_WIDE_INT
))
14465 insert_int (double_int_to_shwi (val
), elt_size
, p
);
14468 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
14469 insert_double (val
, p
);
14474 case MODE_VECTOR_FLOAT
:
14475 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14477 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14478 insert_float (elt
, p
);
14483 gcc_unreachable ();
14486 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
14491 if (dwarf_version
>= 4 || !dwarf_strict
)
14493 dw_loc_descr_ref loc_result
;
14494 resolve_one_addr (&rtl
, NULL
);
14496 loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
14497 loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
14498 loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
14499 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14500 add_AT_loc (die
, DW_AT_location
, loc_result
);
14501 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
14507 if (CONSTANT_P (XEXP (rtl
, 0)))
14508 return add_const_value_attribute (die
, XEXP (rtl
, 0));
14511 if (!const_ok_for_output (rtl
))
14514 if (dwarf_version
>= 4 || !dwarf_strict
)
14519 /* In cases where an inlined instance of an inline function is passed
14520 the address of an `auto' variable (which is local to the caller) we
14521 can get a situation where the DECL_RTL of the artificial local
14522 variable (for the inlining) which acts as a stand-in for the
14523 corresponding formal parameter (of the inline function) will look
14524 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14525 exactly a compile-time constant expression, but it isn't the address
14526 of the (artificial) local variable either. Rather, it represents the
14527 *value* which the artificial local variable always has during its
14528 lifetime. We currently have no way to represent such quasi-constant
14529 values in Dwarf, so for now we just punt and generate nothing. */
14537 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
14538 && MEM_READONLY_P (rtl
)
14539 && GET_MODE (rtl
) == BLKmode
)
14541 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
14547 /* No other kinds of rtx should be possible here. */
14548 gcc_unreachable ();
14553 /* Determine whether the evaluation of EXPR references any variables
14554 or functions which aren't otherwise used (and therefore may not be
14557 reference_to_unused (tree
* tp
, int * walk_subtrees
,
14558 void * data ATTRIBUTE_UNUSED
)
14560 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
14561 *walk_subtrees
= 0;
14563 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
14564 && ! TREE_ASM_WRITTEN (*tp
))
14566 /* ??? The C++ FE emits debug information for using decls, so
14567 putting gcc_unreachable here falls over. See PR31899. For now
14568 be conservative. */
14569 else if (!cgraph_global_info_ready
14570 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
14572 else if (TREE_CODE (*tp
) == VAR_DECL
)
14574 struct varpool_node
*node
= varpool_get_node (*tp
);
14575 if (!node
|| !node
->needed
)
14578 else if (TREE_CODE (*tp
) == FUNCTION_DECL
14579 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
14581 /* The call graph machinery must have finished analyzing,
14582 optimizing and gimplifying the CU by now.
14583 So if *TP has no call graph node associated
14584 to it, it means *TP will not be emitted. */
14585 if (!cgraph_get_node (*tp
))
14588 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
14594 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
14595 for use in a later add_const_value_attribute call. */
14598 rtl_for_decl_init (tree init
, tree type
)
14600 rtx rtl
= NULL_RTX
;
14604 /* If a variable is initialized with a string constant without embedded
14605 zeros, build CONST_STRING. */
14606 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
14608 tree enttype
= TREE_TYPE (type
);
14609 tree domain
= TYPE_DOMAIN (type
);
14610 enum machine_mode mode
= TYPE_MODE (enttype
);
14612 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
14614 && integer_zerop (TYPE_MIN_VALUE (domain
))
14615 && compare_tree_int (TYPE_MAX_VALUE (domain
),
14616 TREE_STRING_LENGTH (init
) - 1) == 0
14617 && ((size_t) TREE_STRING_LENGTH (init
)
14618 == strlen (TREE_STRING_POINTER (init
)) + 1))
14620 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
14621 ggc_strdup (TREE_STRING_POINTER (init
)));
14622 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
14623 MEM_READONLY_P (rtl
) = 1;
14626 /* Other aggregates, and complex values, could be represented using
14628 else if (AGGREGATE_TYPE_P (type
)
14629 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
14630 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
14631 || TREE_CODE (type
) == COMPLEX_TYPE
)
14633 /* Vectors only work if their mode is supported by the target.
14634 FIXME: generic vectors ought to work too. */
14635 else if (TREE_CODE (type
) == VECTOR_TYPE
14636 && !VECTOR_MODE_P (TYPE_MODE (type
)))
14638 /* If the initializer is something that we know will expand into an
14639 immediate RTL constant, expand it now. We must be careful not to
14640 reference variables which won't be output. */
14641 else if (initializer_constant_valid_p (init
, type
)
14642 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
14644 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
14646 if (TREE_CODE (type
) == VECTOR_TYPE
)
14647 switch (TREE_CODE (init
))
14652 if (TREE_CONSTANT (init
))
14654 VEC(constructor_elt
,gc
) *elts
= CONSTRUCTOR_ELTS (init
);
14655 bool constant_p
= true;
14657 unsigned HOST_WIDE_INT ix
;
14659 /* Even when ctor is constant, it might contain non-*_CST
14660 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
14661 belong into VECTOR_CST nodes. */
14662 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
14663 if (!CONSTANT_CLASS_P (value
))
14665 constant_p
= false;
14671 init
= build_vector_from_ctor (type
, elts
);
14681 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
14683 /* If expand_expr returns a MEM, it wasn't immediate. */
14684 gcc_assert (!rtl
|| !MEM_P (rtl
));
14690 /* Generate RTL for the variable DECL to represent its location. */
14693 rtl_for_decl_location (tree decl
)
14697 /* Here we have to decide where we are going to say the parameter "lives"
14698 (as far as the debugger is concerned). We only have a couple of
14699 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
14701 DECL_RTL normally indicates where the parameter lives during most of the
14702 activation of the function. If optimization is enabled however, this
14703 could be either NULL or else a pseudo-reg. Both of those cases indicate
14704 that the parameter doesn't really live anywhere (as far as the code
14705 generation parts of GCC are concerned) during most of the function's
14706 activation. That will happen (for example) if the parameter is never
14707 referenced within the function.
14709 We could just generate a location descriptor here for all non-NULL
14710 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
14711 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
14712 where DECL_RTL is NULL or is a pseudo-reg.
14714 Note however that we can only get away with using DECL_INCOMING_RTL as
14715 a backup substitute for DECL_RTL in certain limited cases. In cases
14716 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
14717 we can be sure that the parameter was passed using the same type as it is
14718 declared to have within the function, and that its DECL_INCOMING_RTL
14719 points us to a place where a value of that type is passed.
14721 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
14722 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
14723 because in these cases DECL_INCOMING_RTL points us to a value of some
14724 type which is *different* from the type of the parameter itself. Thus,
14725 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
14726 such cases, the debugger would end up (for example) trying to fetch a
14727 `float' from a place which actually contains the first part of a
14728 `double'. That would lead to really incorrect and confusing
14729 output at debug-time.
14731 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
14732 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
14733 are a couple of exceptions however. On little-endian machines we can
14734 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
14735 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
14736 an integral type that is smaller than TREE_TYPE (decl). These cases arise
14737 when (on a little-endian machine) a non-prototyped function has a
14738 parameter declared to be of type `short' or `char'. In such cases,
14739 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
14740 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
14741 passed `int' value. If the debugger then uses that address to fetch
14742 a `short' or a `char' (on a little-endian machine) the result will be
14743 the correct data, so we allow for such exceptional cases below.
14745 Note that our goal here is to describe the place where the given formal
14746 parameter lives during most of the function's activation (i.e. between the
14747 end of the prologue and the start of the epilogue). We'll do that as best
14748 as we can. Note however that if the given formal parameter is modified
14749 sometime during the execution of the function, then a stack backtrace (at
14750 debug-time) will show the function as having been called with the *new*
14751 value rather than the value which was originally passed in. This happens
14752 rarely enough that it is not a major problem, but it *is* a problem, and
14753 I'd like to fix it.
14755 A future version of dwarf2out.c may generate two additional attributes for
14756 any given DW_TAG_formal_parameter DIE which will describe the "passed
14757 type" and the "passed location" for the given formal parameter in addition
14758 to the attributes we now generate to indicate the "declared type" and the
14759 "active location" for each parameter. This additional set of attributes
14760 could be used by debuggers for stack backtraces. Separately, note that
14761 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
14762 This happens (for example) for inlined-instances of inline function formal
14763 parameters which are never referenced. This really shouldn't be
14764 happening. All PARM_DECL nodes should get valid non-NULL
14765 DECL_INCOMING_RTL values. FIXME. */
14767 /* Use DECL_RTL as the "location" unless we find something better. */
14768 rtl
= DECL_RTL_IF_SET (decl
);
14770 /* When generating abstract instances, ignore everything except
14771 constants, symbols living in memory, and symbols living in
14772 fixed registers. */
14773 if (! reload_completed
)
14776 && (CONSTANT_P (rtl
)
14778 && CONSTANT_P (XEXP (rtl
, 0)))
14780 && TREE_CODE (decl
) == VAR_DECL
14781 && TREE_STATIC (decl
))))
14783 rtl
= targetm
.delegitimize_address (rtl
);
14788 else if (TREE_CODE (decl
) == PARM_DECL
)
14790 if (rtl
== NULL_RTX
14791 || is_pseudo_reg (rtl
)
14793 && is_pseudo_reg (XEXP (rtl
, 0))
14794 && DECL_INCOMING_RTL (decl
)
14795 && MEM_P (DECL_INCOMING_RTL (decl
))
14796 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
14798 tree declared_type
= TREE_TYPE (decl
);
14799 tree passed_type
= DECL_ARG_TYPE (decl
);
14800 enum machine_mode dmode
= TYPE_MODE (declared_type
);
14801 enum machine_mode pmode
= TYPE_MODE (passed_type
);
14803 /* This decl represents a formal parameter which was optimized out.
14804 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
14805 all cases where (rtl == NULL_RTX) just below. */
14806 if (dmode
== pmode
)
14807 rtl
= DECL_INCOMING_RTL (decl
);
14808 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
14809 && SCALAR_INT_MODE_P (dmode
)
14810 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
14811 && DECL_INCOMING_RTL (decl
))
14813 rtx inc
= DECL_INCOMING_RTL (decl
);
14816 else if (MEM_P (inc
))
14818 if (BYTES_BIG_ENDIAN
)
14819 rtl
= adjust_address_nv (inc
, dmode
,
14820 GET_MODE_SIZE (pmode
)
14821 - GET_MODE_SIZE (dmode
));
14828 /* If the parm was passed in registers, but lives on the stack, then
14829 make a big endian correction if the mode of the type of the
14830 parameter is not the same as the mode of the rtl. */
14831 /* ??? This is the same series of checks that are made in dbxout.c before
14832 we reach the big endian correction code there. It isn't clear if all
14833 of these checks are necessary here, but keeping them all is the safe
14835 else if (MEM_P (rtl
)
14836 && XEXP (rtl
, 0) != const0_rtx
14837 && ! CONSTANT_P (XEXP (rtl
, 0))
14838 /* Not passed in memory. */
14839 && !MEM_P (DECL_INCOMING_RTL (decl
))
14840 /* Not passed by invisible reference. */
14841 && (!REG_P (XEXP (rtl
, 0))
14842 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
14843 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
14844 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
14845 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
14848 /* Big endian correction check. */
14849 && BYTES_BIG_ENDIAN
14850 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
14851 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
14854 int offset
= (UNITS_PER_WORD
14855 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
14857 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
14858 plus_constant (XEXP (rtl
, 0), offset
));
14861 else if (TREE_CODE (decl
) == VAR_DECL
14864 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
14865 && BYTES_BIG_ENDIAN
)
14867 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
14868 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
14870 /* If a variable is declared "register" yet is smaller than
14871 a register, then if we store the variable to memory, it
14872 looks like we're storing a register-sized value, when in
14873 fact we are not. We need to adjust the offset of the
14874 storage location to reflect the actual value's bytes,
14875 else gdb will not be able to display it. */
14877 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
14878 plus_constant (XEXP (rtl
, 0), rsize
-dsize
));
14881 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
14882 and will have been substituted directly into all expressions that use it.
14883 C does not have such a concept, but C++ and other languages do. */
14884 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
14885 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
14888 rtl
= targetm
.delegitimize_address (rtl
);
14890 /* If we don't look past the constant pool, we risk emitting a
14891 reference to a constant pool entry that isn't referenced from
14892 code, and thus is not emitted. */
14894 rtl
= avoid_constant_pool_reference (rtl
);
14896 /* Try harder to get a rtl. If this symbol ends up not being emitted
14897 in the current CU, resolve_addr will remove the expression referencing
14899 if (rtl
== NULL_RTX
14900 && TREE_CODE (decl
) == VAR_DECL
14901 && !DECL_EXTERNAL (decl
)
14902 && TREE_STATIC (decl
)
14903 && DECL_NAME (decl
)
14904 && !DECL_HARD_REGISTER (decl
)
14905 && DECL_MODE (decl
) != VOIDmode
)
14907 rtl
= make_decl_rtl_for_debug (decl
);
14909 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
14910 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
14917 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
14918 returned. If so, the decl for the COMMON block is returned, and the
14919 value is the offset into the common block for the symbol. */
14922 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
14924 tree val_expr
, cvar
;
14925 enum machine_mode mode
;
14926 HOST_WIDE_INT bitsize
, bitpos
;
14928 int unsignedp
, volatilep
= 0;
14930 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
14931 it does not have a value (the offset into the common area), or if it
14932 is thread local (as opposed to global) then it isn't common, and shouldn't
14933 be handled as such. */
14934 if (TREE_CODE (decl
) != VAR_DECL
14935 || !TREE_STATIC (decl
)
14936 || !DECL_HAS_VALUE_EXPR_P (decl
)
14940 val_expr
= DECL_VALUE_EXPR (decl
);
14941 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
14944 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
14945 &mode
, &unsignedp
, &volatilep
, true);
14947 if (cvar
== NULL_TREE
14948 || TREE_CODE (cvar
) != VAR_DECL
14949 || DECL_ARTIFICIAL (cvar
)
14950 || !TREE_PUBLIC (cvar
))
14954 if (offset
!= NULL
)
14956 if (!host_integerp (offset
, 0))
14958 *value
= tree_low_cst (offset
, 0);
14961 *value
+= bitpos
/ BITS_PER_UNIT
;
14966 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
14967 data attribute for a variable or a parameter. We generate the
14968 DW_AT_const_value attribute only in those cases where the given variable
14969 or parameter does not have a true "location" either in memory or in a
14970 register. This can happen (for example) when a constant is passed as an
14971 actual argument in a call to an inline function. (It's possible that
14972 these things can crop up in other ways also.) Note that one type of
14973 constant value which can be passed into an inlined function is a constant
14974 pointer. This can happen for example if an actual argument in an inlined
14975 function call evaluates to a compile-time constant address.
14977 CACHE_P is true if it is worth caching the location list for DECL,
14978 so that future calls can reuse it rather than regenerate it from scratch.
14979 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
14980 since we will need to refer to them each time the function is inlined. */
14983 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
14984 enum dwarf_attribute attr
)
14987 dw_loc_list_ref list
;
14988 var_loc_list
*loc_list
;
14989 cached_dw_loc_list
*cache
;
14992 if (TREE_CODE (decl
) == ERROR_MARK
)
14995 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
14996 || TREE_CODE (decl
) == RESULT_DECL
);
14998 /* Try to get some constant RTL for this decl, and use that as the value of
15001 rtl
= rtl_for_decl_location (decl
);
15002 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15003 && add_const_value_attribute (die
, rtl
))
15006 /* See if we have single element location list that is equivalent to
15007 a constant value. That way we are better to use add_const_value_attribute
15008 rather than expanding constant value equivalent. */
15009 loc_list
= lookup_decl_loc (decl
);
15012 && loc_list
->first
->next
== NULL
15013 && NOTE_P (loc_list
->first
->loc
)
15014 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
15015 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
15017 struct var_loc_node
*node
;
15019 node
= loc_list
->first
;
15020 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
15021 if (GET_CODE (rtl
) == EXPR_LIST
)
15022 rtl
= XEXP (rtl
, 0);
15023 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15024 && add_const_value_attribute (die
, rtl
))
15027 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15028 list several times. See if we've already cached the contents. */
15030 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
15034 cache
= (cached_dw_loc_list
*)
15035 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
15037 list
= cache
->loc_list
;
15041 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
15042 /* It is usually worth caching this result if the decl is from
15043 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15044 if (cache_p
&& list
&& list
->dw_loc_next
)
15046 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
15047 DECL_UID (decl
), INSERT
);
15048 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
15049 cache
->decl_id
= DECL_UID (decl
);
15050 cache
->loc_list
= list
;
15056 add_AT_location_description (die
, attr
, list
);
15059 /* None of that worked, so it must not really have a location;
15060 try adding a constant value attribute from the DECL_INITIAL. */
15061 return tree_add_const_value_attribute_for_decl (die
, decl
);
15064 /* Add VARIABLE and DIE into deferred locations list. */
15067 defer_location (tree variable
, dw_die_ref die
)
15069 deferred_locations entry
;
15070 entry
.variable
= variable
;
15072 VEC_safe_push (deferred_locations
, gc
, deferred_locations_list
, &entry
);
15075 /* Helper function for tree_add_const_value_attribute. Natively encode
15076 initializer INIT into an array. Return true if successful. */
15079 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15083 if (init
== NULL_TREE
)
15087 switch (TREE_CODE (init
))
15090 type
= TREE_TYPE (init
);
15091 if (TREE_CODE (type
) == ARRAY_TYPE
)
15093 tree enttype
= TREE_TYPE (type
);
15094 enum machine_mode mode
= TYPE_MODE (enttype
);
15096 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15098 if (int_size_in_bytes (type
) != size
)
15100 if (size
> TREE_STRING_LENGTH (init
))
15102 memcpy (array
, TREE_STRING_POINTER (init
),
15103 TREE_STRING_LENGTH (init
));
15104 memset (array
+ TREE_STRING_LENGTH (init
),
15105 '\0', size
- TREE_STRING_LENGTH (init
));
15108 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15113 type
= TREE_TYPE (init
);
15114 if (int_size_in_bytes (type
) != size
)
15116 if (TREE_CODE (type
) == ARRAY_TYPE
)
15118 HOST_WIDE_INT min_index
;
15119 unsigned HOST_WIDE_INT cnt
;
15120 int curpos
= 0, fieldsize
;
15121 constructor_elt
*ce
;
15123 if (TYPE_DOMAIN (type
) == NULL_TREE
15124 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
15127 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15128 if (fieldsize
<= 0)
15131 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
15132 memset (array
, '\0', size
);
15133 FOR_EACH_VEC_ELT (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15135 tree val
= ce
->value
;
15136 tree index
= ce
->index
;
15138 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15139 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
15142 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
15147 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
15150 curpos
= pos
+ fieldsize
;
15151 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15153 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
15154 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
15155 while (count
-- > 0)
15158 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
15159 curpos
+= fieldsize
;
15162 gcc_assert (curpos
<= size
);
15166 else if (TREE_CODE (type
) == RECORD_TYPE
15167 || TREE_CODE (type
) == UNION_TYPE
)
15169 tree field
= NULL_TREE
;
15170 unsigned HOST_WIDE_INT cnt
;
15171 constructor_elt
*ce
;
15173 if (int_size_in_bytes (type
) != size
)
15176 if (TREE_CODE (type
) == RECORD_TYPE
)
15177 field
= TYPE_FIELDS (type
);
15179 FOR_EACH_VEC_ELT (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15181 tree val
= ce
->value
;
15182 int pos
, fieldsize
;
15184 if (ce
->index
!= 0)
15190 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
15193 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
15194 && TYPE_DOMAIN (TREE_TYPE (field
))
15195 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
15197 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
15198 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
15200 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
15201 pos
= int_byte_position (field
);
15202 gcc_assert (pos
+ fieldsize
<= size
);
15204 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
15210 case VIEW_CONVERT_EXPR
:
15211 case NON_LVALUE_EXPR
:
15212 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
15214 return native_encode_expr (init
, array
, size
) == size
;
15218 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15219 attribute is the const value T. */
15222 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
15225 tree type
= TREE_TYPE (t
);
15228 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
15232 gcc_assert (!DECL_P (init
));
15234 rtl
= rtl_for_decl_init (init
, type
);
15236 return add_const_value_attribute (die
, rtl
);
15237 /* If the host and target are sane, try harder. */
15238 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
15239 && initializer_constant_valid_p (init
, type
))
15241 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
15242 if (size
> 0 && (int) size
== size
)
15244 unsigned char *array
= (unsigned char *)
15245 ggc_alloc_cleared_atomic (size
);
15247 if (native_encode_initializer (init
, array
, size
))
15249 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
15257 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15258 attribute is the const value of T, where T is an integral constant
15259 variable with static storage duration
15260 (so it can't be a PARM_DECL or a RESULT_DECL). */
15263 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
15267 || (TREE_CODE (decl
) != VAR_DECL
15268 && TREE_CODE (decl
) != CONST_DECL
)
15269 || (TREE_CODE (decl
) == VAR_DECL
15270 && !TREE_STATIC (decl
)))
15273 if (TREE_READONLY (decl
)
15274 && ! TREE_THIS_VOLATILE (decl
)
15275 && DECL_INITIAL (decl
))
15280 /* Don't add DW_AT_const_value if abstract origin already has one. */
15281 if (get_AT (var_die
, DW_AT_const_value
))
15284 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
15287 /* Convert the CFI instructions for the current function into a
15288 location list. This is used for DW_AT_frame_base when we targeting
15289 a dwarf2 consumer that does not support the dwarf3
15290 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15293 static dw_loc_list_ref
15294 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
15298 dw_loc_list_ref list
, *list_tail
;
15300 dw_cfa_location last_cfa
, next_cfa
;
15301 const char *start_label
, *last_label
, *section
;
15302 dw_cfa_location remember
;
15305 gcc_assert (fde
!= NULL
);
15307 section
= secname_for_decl (current_function_decl
);
15311 memset (&next_cfa
, 0, sizeof (next_cfa
));
15312 next_cfa
.reg
= INVALID_REGNUM
;
15313 remember
= next_cfa
;
15315 start_label
= fde
->dw_fde_begin
;
15317 /* ??? Bald assumption that the CIE opcode list does not contain
15318 advance opcodes. */
15319 FOR_EACH_VEC_ELT (dw_cfi_ref
, cie_cfi_vec
, ix
, cfi
)
15320 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15322 last_cfa
= next_cfa
;
15323 last_label
= start_label
;
15325 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
15327 /* If the first partition contained no CFI adjustments, the
15328 CIE opcodes apply to the whole first partition. */
15329 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15330 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
15331 list_tail
=&(*list_tail
)->dw_loc_next
;
15332 start_label
= last_label
= fde
->dw_fde_second_begin
;
15335 FOR_EACH_VEC_ELT (dw_cfi_ref
, fde
->dw_fde_cfi
, ix
, cfi
)
15337 switch (cfi
->dw_cfi_opc
)
15339 case DW_CFA_set_loc
:
15340 case DW_CFA_advance_loc1
:
15341 case DW_CFA_advance_loc2
:
15342 case DW_CFA_advance_loc4
:
15343 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15345 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15346 start_label
, last_label
, section
);
15348 list_tail
= &(*list_tail
)->dw_loc_next
;
15349 last_cfa
= next_cfa
;
15350 start_label
= last_label
;
15352 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
15355 case DW_CFA_advance_loc
:
15356 /* The encoding is complex enough that we should never emit this. */
15357 gcc_unreachable ();
15360 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15363 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
15365 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15367 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15368 start_label
, last_label
, section
);
15370 list_tail
= &(*list_tail
)->dw_loc_next
;
15371 last_cfa
= next_cfa
;
15372 start_label
= last_label
;
15374 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15375 start_label
, fde
->dw_fde_end
, section
);
15376 list_tail
= &(*list_tail
)->dw_loc_next
;
15377 start_label
= last_label
= fde
->dw_fde_second_begin
;
15381 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15383 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15384 start_label
, last_label
, section
);
15385 list_tail
= &(*list_tail
)->dw_loc_next
;
15386 start_label
= last_label
;
15389 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
15391 fde
->dw_fde_second_begin
15392 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
15395 if (list
&& list
->dw_loc_next
)
15401 /* Compute a displacement from the "steady-state frame pointer" to the
15402 frame base (often the same as the CFA), and store it in
15403 frame_pointer_fb_offset. OFFSET is added to the displacement
15404 before the latter is negated. */
15407 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
15411 #ifdef FRAME_POINTER_CFA_OFFSET
15412 reg
= frame_pointer_rtx
;
15413 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
15415 reg
= arg_pointer_rtx
;
15416 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
15419 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
15420 if (GET_CODE (elim
) == PLUS
)
15422 offset
+= INTVAL (XEXP (elim
, 1));
15423 elim
= XEXP (elim
, 0);
15426 frame_pointer_fb_offset
= -offset
;
15428 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15429 in which to eliminate. This is because it's stack pointer isn't
15430 directly accessible as a register within the ISA. To work around
15431 this, assume that while we cannot provide a proper value for
15432 frame_pointer_fb_offset, we won't need one either. */
15433 frame_pointer_fb_offset_valid
15434 = ((SUPPORTS_STACK_ALIGNMENT
15435 && (elim
== hard_frame_pointer_rtx
15436 || elim
== stack_pointer_rtx
))
15437 || elim
== (frame_pointer_needed
15438 ? hard_frame_pointer_rtx
15439 : stack_pointer_rtx
));
15442 /* Generate a DW_AT_name attribute given some string value to be included as
15443 the value of the attribute. */
15446 add_name_attribute (dw_die_ref die
, const char *name_string
)
15448 if (name_string
!= NULL
&& *name_string
!= 0)
15450 if (demangle_name_func
)
15451 name_string
= (*demangle_name_func
) (name_string
);
15453 add_AT_string (die
, DW_AT_name
, name_string
);
15457 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
15458 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
15459 of TYPE accordingly.
15461 ??? This is a temporary measure until after we're able to generate
15462 regular DWARF for the complex Ada type system. */
15465 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
15466 dw_die_ref context_die
)
15469 dw_die_ref dtype_die
;
15471 if (!lang_hooks
.types
.descriptive_type
)
15474 dtype
= lang_hooks
.types
.descriptive_type (type
);
15478 dtype_die
= lookup_type_die (dtype
);
15481 gen_type_die (dtype
, context_die
);
15482 dtype_die
= lookup_type_die (dtype
);
15483 gcc_assert (dtype_die
);
15486 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
15489 /* Generate a DW_AT_comp_dir attribute for DIE. */
15492 add_comp_dir_attribute (dw_die_ref die
)
15494 const char *wd
= get_src_pwd ();
15500 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
15504 wdlen
= strlen (wd
);
15505 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
15507 wd1
[wdlen
] = DIR_SEPARATOR
;
15508 wd1
[wdlen
+ 1] = 0;
15512 add_AT_string (die
, DW_AT_comp_dir
, remap_debug_filename (wd
));
15515 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
15519 lower_bound_default (void)
15521 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
15526 case DW_LANG_C_plus_plus
:
15528 case DW_LANG_ObjC_plus_plus
:
15531 case DW_LANG_Fortran77
:
15532 case DW_LANG_Fortran90
:
15533 case DW_LANG_Fortran95
:
15537 case DW_LANG_Python
:
15538 return dwarf_version
>= 4 ? 0 : -1;
15539 case DW_LANG_Ada95
:
15540 case DW_LANG_Ada83
:
15541 case DW_LANG_Cobol74
:
15542 case DW_LANG_Cobol85
:
15543 case DW_LANG_Pascal83
:
15544 case DW_LANG_Modula2
:
15546 return dwarf_version
>= 4 ? 1 : -1;
15552 /* Given a tree node describing an array bound (either lower or upper) output
15553 a representation for that bound. */
15556 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
15558 switch (TREE_CODE (bound
))
15563 /* All fixed-bounds are represented by INTEGER_CST nodes. */
15566 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
15569 /* Use the default if possible. */
15570 if (bound_attr
== DW_AT_lower_bound
15571 && host_integerp (bound
, 0)
15572 && (dflt
= lower_bound_default ()) != -1
15573 && tree_low_cst (bound
, 0) == dflt
)
15576 /* Otherwise represent the bound as an unsigned value with the
15577 precision of its type. The precision and signedness of the
15578 type will be necessary to re-interpret it unambiguously. */
15579 else if (prec
< HOST_BITS_PER_WIDE_INT
)
15581 unsigned HOST_WIDE_INT mask
15582 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
15583 add_AT_unsigned (subrange_die
, bound_attr
,
15584 TREE_INT_CST_LOW (bound
) & mask
);
15586 else if (prec
== HOST_BITS_PER_WIDE_INT
15587 || TREE_INT_CST_HIGH (bound
) == 0)
15588 add_AT_unsigned (subrange_die
, bound_attr
,
15589 TREE_INT_CST_LOW (bound
));
15591 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
15592 TREE_INT_CST_LOW (bound
));
15597 case VIEW_CONVERT_EXPR
:
15598 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
15608 dw_die_ref decl_die
= lookup_decl_die (bound
);
15610 /* ??? Can this happen, or should the variable have been bound
15611 first? Probably it can, since I imagine that we try to create
15612 the types of parameters in the order in which they exist in
15613 the list, and won't have created a forward reference to a
15614 later parameter. */
15615 if (decl_die
!= NULL
)
15617 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
15625 /* Otherwise try to create a stack operation procedure to
15626 evaluate the value of the array bound. */
15628 dw_die_ref ctx
, decl_die
;
15629 dw_loc_list_ref list
;
15631 list
= loc_list_from_tree (bound
, 2);
15632 if (list
== NULL
|| single_element_loc_list_p (list
))
15634 /* If DW_AT_*bound is not a reference nor constant, it is
15635 a DWARF expression rather than location description.
15636 For that loc_list_from_tree (bound, 0) is needed.
15637 If that fails to give a single element list,
15638 fall back to outputting this as a reference anyway. */
15639 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
15640 if (list2
&& single_element_loc_list_p (list2
))
15642 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
15649 if (current_function_decl
== 0)
15650 ctx
= comp_unit_die ();
15652 ctx
= lookup_decl_die (current_function_decl
);
15654 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
15655 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
15656 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
15657 add_AT_location_description (decl_die
, DW_AT_location
, list
);
15658 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
15664 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
15665 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
15666 Note that the block of subscript information for an array type also
15667 includes information about the element type of the given array type. */
15670 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
15672 unsigned dimension_number
;
15674 dw_die_ref subrange_die
;
15676 for (dimension_number
= 0;
15677 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
15678 type
= TREE_TYPE (type
), dimension_number
++)
15680 tree domain
= TYPE_DOMAIN (type
);
15682 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
15685 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
15686 and (in GNU C only) variable bounds. Handle all three forms
15688 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
15691 /* We have an array type with specified bounds. */
15692 lower
= TYPE_MIN_VALUE (domain
);
15693 upper
= TYPE_MAX_VALUE (domain
);
15695 /* Define the index type. */
15696 if (TREE_TYPE (domain
))
15698 /* ??? This is probably an Ada unnamed subrange type. Ignore the
15699 TREE_TYPE field. We can't emit debug info for this
15700 because it is an unnamed integral type. */
15701 if (TREE_CODE (domain
) == INTEGER_TYPE
15702 && TYPE_NAME (domain
) == NULL_TREE
15703 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
15704 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
15707 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
15711 /* ??? If upper is NULL, the array has unspecified length,
15712 but it does have a lower bound. This happens with Fortran
15714 Since the debugger is definitely going to need to know N
15715 to produce useful results, go ahead and output the lower
15716 bound solo, and hope the debugger can cope. */
15718 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
15720 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
15723 /* Otherwise we have an array type with an unspecified length. The
15724 DWARF-2 spec does not say how to handle this; let's just leave out the
15730 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
15734 switch (TREE_CODE (tree_node
))
15739 case ENUMERAL_TYPE
:
15742 case QUAL_UNION_TYPE
:
15743 size
= int_size_in_bytes (tree_node
);
15746 /* For a data member of a struct or union, the DW_AT_byte_size is
15747 generally given as the number of bytes normally allocated for an
15748 object of the *declared* type of the member itself. This is true
15749 even for bit-fields. */
15750 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
15753 gcc_unreachable ();
15756 /* Note that `size' might be -1 when we get to this point. If it is, that
15757 indicates that the byte size of the entity in question is variable. We
15758 have no good way of expressing this fact in Dwarf at the present time,
15759 so just let the -1 pass on through. */
15760 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
15763 /* For a FIELD_DECL node which represents a bit-field, output an attribute
15764 which specifies the distance in bits from the highest order bit of the
15765 "containing object" for the bit-field to the highest order bit of the
15768 For any given bit-field, the "containing object" is a hypothetical object
15769 (of some integral or enum type) within which the given bit-field lives. The
15770 type of this hypothetical "containing object" is always the same as the
15771 declared type of the individual bit-field itself. The determination of the
15772 exact location of the "containing object" for a bit-field is rather
15773 complicated. It's handled by the `field_byte_offset' function (above).
15775 Note that it is the size (in bytes) of the hypothetical "containing object"
15776 which will be given in the DW_AT_byte_size attribute for this bit-field.
15777 (See `byte_size_attribute' above). */
15780 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
15782 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
15783 tree type
= DECL_BIT_FIELD_TYPE (decl
);
15784 HOST_WIDE_INT bitpos_int
;
15785 HOST_WIDE_INT highest_order_object_bit_offset
;
15786 HOST_WIDE_INT highest_order_field_bit_offset
;
15787 HOST_WIDE_INT bit_offset
;
15789 /* Must be a field and a bit field. */
15790 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
15792 /* We can't yet handle bit-fields whose offsets are variable, so if we
15793 encounter such things, just return without generating any attribute
15794 whatsoever. Likewise for variable or too large size. */
15795 if (! host_integerp (bit_position (decl
), 0)
15796 || ! host_integerp (DECL_SIZE (decl
), 1))
15799 bitpos_int
= int_bit_position (decl
);
15801 /* Note that the bit offset is always the distance (in bits) from the
15802 highest-order bit of the "containing object" to the highest-order bit of
15803 the bit-field itself. Since the "high-order end" of any object or field
15804 is different on big-endian and little-endian machines, the computation
15805 below must take account of these differences. */
15806 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
15807 highest_order_field_bit_offset
= bitpos_int
;
15809 if (! BYTES_BIG_ENDIAN
)
15811 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
15812 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
15816 = (! BYTES_BIG_ENDIAN
15817 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
15818 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
15820 if (bit_offset
< 0)
15821 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
15823 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
15826 /* For a FIELD_DECL node which represents a bit field, output an attribute
15827 which specifies the length in bits of the given field. */
15830 add_bit_size_attribute (dw_die_ref die
, tree decl
)
15832 /* Must be a field and a bit field. */
15833 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
15834 && DECL_BIT_FIELD_TYPE (decl
));
15836 if (host_integerp (DECL_SIZE (decl
), 1))
15837 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
15840 /* If the compiled language is ANSI C, then add a 'prototyped'
15841 attribute, if arg types are given for the parameters of a function. */
15844 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
15846 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
15847 && prototype_p (func_type
))
15848 add_AT_flag (die
, DW_AT_prototyped
, 1);
15851 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
15852 by looking in either the type declaration or object declaration
15855 static inline dw_die_ref
15856 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
15858 dw_die_ref origin_die
= NULL
;
15860 if (TREE_CODE (origin
) != FUNCTION_DECL
)
15862 /* We may have gotten separated from the block for the inlined
15863 function, if we're in an exception handler or some such; make
15864 sure that the abstract function has been written out.
15866 Doing this for nested functions is wrong, however; functions are
15867 distinct units, and our context might not even be inline. */
15871 fn
= TYPE_STUB_DECL (fn
);
15873 fn
= decl_function_context (fn
);
15875 dwarf2out_abstract_function (fn
);
15878 if (DECL_P (origin
))
15879 origin_die
= lookup_decl_die (origin
);
15880 else if (TYPE_P (origin
))
15881 origin_die
= lookup_type_die (origin
);
15883 /* XXX: Functions that are never lowered don't always have correct block
15884 trees (in the case of java, they simply have no block tree, in some other
15885 languages). For these functions, there is nothing we can really do to
15886 output correct debug info for inlined functions in all cases. Rather
15887 than die, we'll just produce deficient debug info now, in that we will
15888 have variables without a proper abstract origin. In the future, when all
15889 functions are lowered, we should re-add a gcc_assert (origin_die)
15893 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
15897 /* We do not currently support the pure_virtual attribute. */
15900 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
15902 if (DECL_VINDEX (func_decl
))
15904 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
15906 if (host_integerp (DECL_VINDEX (func_decl
), 0))
15907 add_AT_loc (die
, DW_AT_vtable_elem_location
,
15908 new_loc_descr (DW_OP_constu
,
15909 tree_low_cst (DECL_VINDEX (func_decl
), 0),
15912 /* GNU extension: Record what type this method came from originally. */
15913 if (debug_info_level
> DINFO_LEVEL_TERSE
15914 && DECL_CONTEXT (func_decl
))
15915 add_AT_die_ref (die
, DW_AT_containing_type
,
15916 lookup_type_die (DECL_CONTEXT (func_decl
)));
15920 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
15921 given decl. This used to be a vendor extension until after DWARF 4
15922 standardized it. */
15925 add_linkage_attr (dw_die_ref die
, tree decl
)
15927 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
15929 /* Mimic what assemble_name_raw does with a leading '*'. */
15930 if (name
[0] == '*')
15933 if (dwarf_version
>= 4)
15934 add_AT_string (die
, DW_AT_linkage_name
, name
);
15936 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
15939 /* Add source coordinate attributes for the given decl. */
15942 add_src_coords_attributes (dw_die_ref die
, tree decl
)
15944 expanded_location s
;
15946 if (DECL_SOURCE_LOCATION (decl
) == UNKNOWN_LOCATION
)
15948 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
15949 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
15950 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
15953 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
15956 add_linkage_name (dw_die_ref die
, tree decl
)
15958 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
15959 && TREE_PUBLIC (decl
)
15960 && !DECL_ABSTRACT (decl
)
15961 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
15962 && die
->die_tag
!= DW_TAG_member
)
15964 /* Defer until we have an assembler name set. */
15965 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
15967 limbo_die_node
*asm_name
;
15969 asm_name
= ggc_alloc_cleared_limbo_die_node ();
15970 asm_name
->die
= die
;
15971 asm_name
->created_for
= decl
;
15972 asm_name
->next
= deferred_asm_name
;
15973 deferred_asm_name
= asm_name
;
15975 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
15976 add_linkage_attr (die
, decl
);
15980 /* Add a DW_AT_name attribute and source coordinate attribute for the
15981 given decl, but only if it actually has a name. */
15984 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
15988 decl_name
= DECL_NAME (decl
);
15989 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
15991 const char *name
= dwarf2_name (decl
, 0);
15993 add_name_attribute (die
, name
);
15994 if (! DECL_ARTIFICIAL (decl
))
15995 add_src_coords_attributes (die
, decl
);
15997 add_linkage_name (die
, decl
);
16000 #ifdef VMS_DEBUGGING_INFO
16001 /* Get the function's name, as described by its RTL. This may be different
16002 from the DECL_NAME name used in the source file. */
16003 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
16005 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
16006 XEXP (DECL_RTL (decl
), 0));
16007 VEC_safe_push (rtx
, gc
, used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
16009 #endif /* VMS_DEBUGGING_INFO */
16012 #ifdef VMS_DEBUGGING_INFO
16013 /* Output the debug main pointer die for VMS */
16016 dwarf2out_vms_debug_main_pointer (void)
16018 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
16021 /* Allocate the VMS debug main subprogram die. */
16022 die
= ggc_alloc_cleared_die_node ();
16023 die
->die_tag
= DW_TAG_subprogram
;
16024 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
16025 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
16026 current_function_funcdef_no
);
16027 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
16029 /* Make it the first child of comp_unit_die (). */
16030 die
->die_parent
= comp_unit_die ();
16031 if (comp_unit_die ()->die_child
)
16033 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
16034 comp_unit_die ()->die_child
->die_sib
= die
;
16038 die
->die_sib
= die
;
16039 comp_unit_die ()->die_child
= die
;
16042 #endif /* VMS_DEBUGGING_INFO */
16044 /* Push a new declaration scope. */
16047 push_decl_scope (tree scope
)
16049 VEC_safe_push (tree
, gc
, decl_scope_table
, scope
);
16052 /* Pop a declaration scope. */
16055 pop_decl_scope (void)
16057 VEC_pop (tree
, decl_scope_table
);
16060 /* Return the DIE for the scope that immediately contains this type.
16061 Non-named types get global scope. Named types nested in other
16062 types get their containing scope if it's open, or global scope
16063 otherwise. All other types (i.e. function-local named types) get
16064 the current active scope. */
16067 scope_die_for (tree t
, dw_die_ref context_die
)
16069 dw_die_ref scope_die
= NULL
;
16070 tree containing_scope
;
16073 /* Non-types always go in the current scope. */
16074 gcc_assert (TYPE_P (t
));
16076 containing_scope
= TYPE_CONTEXT (t
);
16078 /* Use the containing namespace if it was passed in (for a declaration). */
16079 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
16081 if (context_die
== lookup_decl_die (containing_scope
))
16084 containing_scope
= NULL_TREE
;
16087 /* Ignore function type "scopes" from the C frontend. They mean that
16088 a tagged type is local to a parmlist of a function declarator, but
16089 that isn't useful to DWARF. */
16090 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
16091 containing_scope
= NULL_TREE
;
16093 if (SCOPE_FILE_SCOPE_P (containing_scope
))
16094 scope_die
= comp_unit_die ();
16095 else if (TYPE_P (containing_scope
))
16097 /* For types, we can just look up the appropriate DIE. But
16098 first we check to see if we're in the middle of emitting it
16099 so we know where the new DIE should go. */
16100 for (i
= VEC_length (tree
, decl_scope_table
) - 1; i
>= 0; --i
)
16101 if (VEC_index (tree
, decl_scope_table
, i
) == containing_scope
)
16106 gcc_assert (debug_info_level
<= DINFO_LEVEL_TERSE
16107 || TREE_ASM_WRITTEN (containing_scope
));
16108 /*We are not in the middle of emitting the type
16109 CONTAINING_SCOPE. Let's see if it's emitted already. */
16110 scope_die
= lookup_type_die (containing_scope
);
16112 /* If none of the current dies are suitable, we get file scope. */
16113 if (scope_die
== NULL
)
16114 scope_die
= comp_unit_die ();
16117 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
16120 scope_die
= context_die
;
16125 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16128 local_scope_p (dw_die_ref context_die
)
16130 for (; context_die
; context_die
= context_die
->die_parent
)
16131 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
16132 || context_die
->die_tag
== DW_TAG_subprogram
)
16138 /* Returns nonzero if CONTEXT_DIE is a class. */
16141 class_scope_p (dw_die_ref context_die
)
16143 return (context_die
16144 && (context_die
->die_tag
== DW_TAG_structure_type
16145 || context_die
->die_tag
== DW_TAG_class_type
16146 || context_die
->die_tag
== DW_TAG_interface_type
16147 || context_die
->die_tag
== DW_TAG_union_type
));
16150 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16151 whether or not to treat a DIE in this context as a declaration. */
16154 class_or_namespace_scope_p (dw_die_ref context_die
)
16156 return (class_scope_p (context_die
)
16157 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
16160 /* Many forms of DIEs require a "type description" attribute. This
16161 routine locates the proper "type descriptor" die for the type given
16162 by 'type', and adds a DW_AT_type attribute below the given die. */
16165 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
16166 int decl_volatile
, dw_die_ref context_die
)
16168 enum tree_code code
= TREE_CODE (type
);
16169 dw_die_ref type_die
= NULL
;
16171 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16172 or fixed-point type, use the inner type. This is because we have no
16173 support for unnamed types in base_type_die. This can happen if this is
16174 an Ada subrange type. Correct solution is emit a subrange type die. */
16175 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
16176 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
16177 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
16179 if (code
== ERROR_MARK
16180 /* Handle a special case. For functions whose return type is void, we
16181 generate *no* type attribute. (Note that no object may have type
16182 `void', so this only applies to function return types). */
16183 || code
== VOID_TYPE
)
16186 type_die
= modified_type_die (type
,
16187 decl_const
|| TYPE_READONLY (type
),
16188 decl_volatile
|| TYPE_VOLATILE (type
),
16191 if (type_die
!= NULL
)
16192 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
16195 /* Given an object die, add the calling convention attribute for the
16196 function call type. */
16198 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
16200 enum dwarf_calling_convention value
= DW_CC_normal
;
16202 value
= ((enum dwarf_calling_convention
)
16203 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
16206 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
16208 /* DWARF 2 doesn't provide a way to identify a program's source-level
16209 entry point. DW_AT_calling_convention attributes are only meant
16210 to describe functions' calling conventions. However, lacking a
16211 better way to signal the Fortran main program, we used this for
16212 a long time, following existing custom. Now, DWARF 4 has
16213 DW_AT_main_subprogram, which we add below, but some tools still
16214 rely on the old way, which we thus keep. */
16215 value
= DW_CC_program
;
16217 if (dwarf_version
>= 4 || !dwarf_strict
)
16218 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
16221 /* Only add the attribute if the backend requests it, and
16222 is not DW_CC_normal. */
16223 if (value
&& (value
!= DW_CC_normal
))
16224 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
16227 /* Given a tree pointer to a struct, class, union, or enum type node, return
16228 a pointer to the (string) tag name for the given type, or zero if the type
16229 was declared without a tag. */
16231 static const char *
16232 type_tag (const_tree type
)
16234 const char *name
= 0;
16236 if (TYPE_NAME (type
) != 0)
16240 /* Find the IDENTIFIER_NODE for the type name. */
16241 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
16242 && !TYPE_NAMELESS (type
))
16243 t
= TYPE_NAME (type
);
16245 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16246 a TYPE_DECL node, regardless of whether or not a `typedef' was
16248 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
16249 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
16251 /* We want to be extra verbose. Don't call dwarf_name if
16252 DECL_NAME isn't set. The default hook for decl_printable_name
16253 doesn't like that, and in this context it's correct to return
16254 0, instead of "<anonymous>" or the like. */
16255 if (DECL_NAME (TYPE_NAME (type
))
16256 && !DECL_NAMELESS (TYPE_NAME (type
)))
16257 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
16260 /* Now get the name as a string, or invent one. */
16261 if (!name
&& t
!= 0)
16262 name
= IDENTIFIER_POINTER (t
);
16265 return (name
== 0 || *name
== '\0') ? 0 : name
;
16268 /* Return the type associated with a data member, make a special check
16269 for bit field types. */
16272 member_declared_type (const_tree member
)
16274 return (DECL_BIT_FIELD_TYPE (member
)
16275 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
16278 /* Get the decl's label, as described by its RTL. This may be different
16279 from the DECL_NAME name used in the source file. */
16282 static const char *
16283 decl_start_label (tree decl
)
16286 const char *fnname
;
16288 x
= DECL_RTL (decl
);
16289 gcc_assert (MEM_P (x
));
16292 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
16294 fnname
= XSTR (x
, 0);
16299 /* These routines generate the internal representation of the DIE's for
16300 the compilation unit. Debugging information is collected by walking
16301 the declaration trees passed in from dwarf2out_decl(). */
16304 gen_array_type_die (tree type
, dw_die_ref context_die
)
16306 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16307 dw_die_ref array_die
;
16309 /* GNU compilers represent multidimensional array types as sequences of one
16310 dimensional array types whose element types are themselves array types.
16311 We sometimes squish that down to a single array_type DIE with multiple
16312 subscripts in the Dwarf debugging info. The draft Dwarf specification
16313 say that we are allowed to do this kind of compression in C, because
16314 there is no difference between an array of arrays and a multidimensional
16315 array. We don't do this for Ada to remain as close as possible to the
16316 actual representation, which is especially important against the language
16317 flexibilty wrt arrays of variable size. */
16319 bool collapse_nested_arrays
= !is_ada ();
16322 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16323 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16324 if (TYPE_STRING_FLAG (type
)
16325 && TREE_CODE (type
) == ARRAY_TYPE
16327 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
16329 HOST_WIDE_INT size
;
16331 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
16332 add_name_attribute (array_die
, type_tag (type
));
16333 equate_type_number_to_die (type
, array_die
);
16334 size
= int_size_in_bytes (type
);
16336 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16337 else if (TYPE_DOMAIN (type
) != NULL_TREE
16338 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
16339 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
16341 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
16342 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
16344 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
16345 if (loc
&& size
> 0)
16347 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
16348 if (size
!= DWARF2_ADDR_SIZE
)
16349 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16355 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16356 add_name_attribute (array_die
, type_tag (type
));
16357 equate_type_number_to_die (type
, array_die
);
16359 if (TREE_CODE (type
) == VECTOR_TYPE
)
16360 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
16362 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16364 && TREE_CODE (type
) == ARRAY_TYPE
16365 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
16366 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
16367 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16370 /* We default the array ordering. SDB will probably do
16371 the right things even if DW_AT_ordering is not present. It's not even
16372 an issue until we start to get into multidimensional arrays anyway. If
16373 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16374 then we'll have to put the DW_AT_ordering attribute back in. (But if
16375 and when we find out that we need to put these in, we will only do so
16376 for multidimensional arrays. */
16377 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
16380 if (TREE_CODE (type
) == VECTOR_TYPE
)
16382 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
16383 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16384 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
16385 add_bound_info (subrange_die
, DW_AT_upper_bound
,
16386 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
16389 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
16391 /* Add representation of the type of the elements of this array type and
16392 emit the corresponding DIE if we haven't done it already. */
16393 element_type
= TREE_TYPE (type
);
16394 if (collapse_nested_arrays
)
16395 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
16397 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
16399 element_type
= TREE_TYPE (element_type
);
16402 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
16404 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
16405 if (TYPE_ARTIFICIAL (type
))
16406 add_AT_flag (array_die
, DW_AT_artificial
, 1);
16408 if (get_AT (array_die
, DW_AT_name
))
16409 add_pubtype (type
, array_die
);
16412 static dw_loc_descr_ref
16413 descr_info_loc (tree val
, tree base_decl
)
16415 HOST_WIDE_INT size
;
16416 dw_loc_descr_ref loc
, loc2
;
16417 enum dwarf_location_atom op
;
16419 if (val
== base_decl
)
16420 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
16422 switch (TREE_CODE (val
))
16425 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16427 return loc_descriptor_from_tree (val
, 0);
16429 if (host_integerp (val
, 0))
16430 return int_loc_descriptor (tree_low_cst (val
, 0));
16433 size
= int_size_in_bytes (TREE_TYPE (val
));
16436 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16439 if (size
== DWARF2_ADDR_SIZE
)
16440 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
16442 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
16444 case POINTER_PLUS_EXPR
:
16446 if (host_integerp (TREE_OPERAND (val
, 1), 1)
16447 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
16450 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16453 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
16459 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16462 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
16465 add_loc_descr (&loc
, loc2
);
16466 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
16488 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
16489 tree val
, tree base_decl
)
16491 dw_loc_descr_ref loc
;
16493 if (host_integerp (val
, 0))
16495 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
16499 loc
= descr_info_loc (val
, base_decl
);
16503 add_AT_loc (die
, attr
, loc
);
16506 /* This routine generates DIE for array with hidden descriptor, details
16507 are filled into *info by a langhook. */
16510 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
16511 dw_die_ref context_die
)
16513 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16514 dw_die_ref array_die
;
16517 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16518 add_name_attribute (array_die
, type_tag (type
));
16519 equate_type_number_to_die (type
, array_die
);
16521 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16523 && info
->ndimensions
>= 2)
16524 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16526 if (info
->data_location
)
16527 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
16529 if (info
->associated
)
16530 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
16532 if (info
->allocated
)
16533 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
16536 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
16538 dw_die_ref subrange_die
16539 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16541 if (info
->dimen
[dim
].lower_bound
)
16543 /* If it is the default value, omit it. */
16546 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
16547 && (dflt
= lower_bound_default ()) != -1
16548 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
16551 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
16552 info
->dimen
[dim
].lower_bound
,
16555 if (info
->dimen
[dim
].upper_bound
)
16556 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
16557 info
->dimen
[dim
].upper_bound
,
16559 if (info
->dimen
[dim
].stride
)
16560 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
16561 info
->dimen
[dim
].stride
,
16565 gen_type_die (info
->element_type
, context_die
);
16566 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
16568 if (get_AT (array_die
, DW_AT_name
))
16569 add_pubtype (type
, array_die
);
16574 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
16576 tree origin
= decl_ultimate_origin (decl
);
16577 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
16579 if (origin
!= NULL
)
16580 add_abstract_origin_attribute (decl_die
, origin
);
16583 add_name_and_src_coords_attributes (decl_die
, decl
);
16584 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
16585 0, 0, context_die
);
16588 if (DECL_ABSTRACT (decl
))
16589 equate_decl_number_to_die (decl
, decl_die
);
16591 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
16595 /* Walk through the list of incomplete types again, trying once more to
16596 emit full debugging info for them. */
16599 retry_incomplete_types (void)
16603 for (i
= VEC_length (tree
, incomplete_types
) - 1; i
>= 0; i
--)
16604 if (should_emit_struct_debug (VEC_index (tree
, incomplete_types
, i
),
16605 DINFO_USAGE_DIR_USE
))
16606 gen_type_die (VEC_index (tree
, incomplete_types
, i
), comp_unit_die ());
16609 /* Determine what tag to use for a record type. */
16611 static enum dwarf_tag
16612 record_type_tag (tree type
)
16614 if (! lang_hooks
.types
.classify_record
)
16615 return DW_TAG_structure_type
;
16617 switch (lang_hooks
.types
.classify_record (type
))
16619 case RECORD_IS_STRUCT
:
16620 return DW_TAG_structure_type
;
16622 case RECORD_IS_CLASS
:
16623 return DW_TAG_class_type
;
16625 case RECORD_IS_INTERFACE
:
16626 if (dwarf_version
>= 3 || !dwarf_strict
)
16627 return DW_TAG_interface_type
;
16628 return DW_TAG_structure_type
;
16631 gcc_unreachable ();
16635 /* Generate a DIE to represent an enumeration type. Note that these DIEs
16636 include all of the information about the enumeration values also. Each
16637 enumerated type name/value is listed as a child of the enumerated type
16641 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
16643 dw_die_ref type_die
= lookup_type_die (type
);
16645 if (type_die
== NULL
)
16647 type_die
= new_die (DW_TAG_enumeration_type
,
16648 scope_die_for (type
, context_die
), type
);
16649 equate_type_number_to_die (type
, type_die
);
16650 add_name_attribute (type_die
, type_tag (type
));
16651 if (dwarf_version
>= 4 || !dwarf_strict
)
16653 if (ENUM_IS_SCOPED (type
))
16654 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
16655 if (ENUM_IS_OPAQUE (type
))
16656 add_AT_flag (type_die
, DW_AT_declaration
, 1);
16659 else if (! TYPE_SIZE (type
))
16662 remove_AT (type_die
, DW_AT_declaration
);
16664 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
16665 given enum type is incomplete, do not generate the DW_AT_byte_size
16666 attribute or the DW_AT_element_list attribute. */
16667 if (TYPE_SIZE (type
))
16671 TREE_ASM_WRITTEN (type
) = 1;
16672 add_byte_size_attribute (type_die
, type
);
16673 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
16675 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
16676 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
16679 /* If the first reference to this type was as the return type of an
16680 inline function, then it may not have a parent. Fix this now. */
16681 if (type_die
->die_parent
== NULL
)
16682 add_child_die (scope_die_for (type
, context_die
), type_die
);
16684 for (link
= TYPE_VALUES (type
);
16685 link
!= NULL
; link
= TREE_CHAIN (link
))
16687 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
16688 tree value
= TREE_VALUE (link
);
16690 add_name_attribute (enum_die
,
16691 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
16693 if (TREE_CODE (value
) == CONST_DECL
)
16694 value
= DECL_INITIAL (value
);
16696 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
16697 /* DWARF2 does not provide a way of indicating whether or
16698 not enumeration constants are signed or unsigned. GDB
16699 always assumes the values are signed, so we output all
16700 values as if they were signed. That means that
16701 enumeration constants with very large unsigned values
16702 will appear to have negative values in the debugger. */
16703 add_AT_int (enum_die
, DW_AT_const_value
,
16704 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
16707 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
16708 if (TYPE_ARTIFICIAL (type
))
16709 add_AT_flag (type_die
, DW_AT_artificial
, 1);
16712 add_AT_flag (type_die
, DW_AT_declaration
, 1);
16714 if (get_AT (type_die
, DW_AT_name
))
16715 add_pubtype (type
, type_die
);
16720 /* Generate a DIE to represent either a real live formal parameter decl or to
16721 represent just the type of some formal parameter position in some function
16724 Note that this routine is a bit unusual because its argument may be a
16725 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
16726 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
16727 node. If it's the former then this function is being called to output a
16728 DIE to represent a formal parameter object (or some inlining thereof). If
16729 it's the latter, then this function is only being called to output a
16730 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
16731 argument type of some subprogram type.
16732 If EMIT_NAME_P is true, name and source coordinate attributes
16736 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
16737 dw_die_ref context_die
)
16739 tree node_or_origin
= node
? node
: origin
;
16740 tree ultimate_origin
;
16741 dw_die_ref parm_die
16742 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
16744 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
16746 case tcc_declaration
:
16747 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
16748 if (node
|| ultimate_origin
)
16749 origin
= ultimate_origin
;
16750 if (origin
!= NULL
)
16751 add_abstract_origin_attribute (parm_die
, origin
);
16752 else if (emit_name_p
)
16753 add_name_and_src_coords_attributes (parm_die
, node
);
16755 || (! DECL_ABSTRACT (node_or_origin
)
16756 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
16757 decl_function_context
16758 (node_or_origin
))))
16760 tree type
= TREE_TYPE (node_or_origin
);
16761 if (decl_by_reference_p (node_or_origin
))
16762 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
16765 add_type_attribute (parm_die
, type
,
16766 TREE_READONLY (node_or_origin
),
16767 TREE_THIS_VOLATILE (node_or_origin
),
16770 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
16771 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
16773 if (node
&& node
!= origin
)
16774 equate_decl_number_to_die (node
, parm_die
);
16775 if (! DECL_ABSTRACT (node_or_origin
))
16776 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
16777 node
== NULL
, DW_AT_location
);
16782 /* We were called with some kind of a ..._TYPE node. */
16783 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
16787 gcc_unreachable ();
16793 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
16794 children DW_TAG_formal_parameter DIEs representing the arguments of the
16797 PARM_PACK must be a function parameter pack.
16798 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
16799 must point to the subsequent arguments of the function PACK_ARG belongs to.
16800 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
16801 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
16802 following the last one for which a DIE was generated. */
16805 gen_formal_parameter_pack_die (tree parm_pack
,
16807 dw_die_ref subr_die
,
16811 dw_die_ref parm_pack_die
;
16813 gcc_assert (parm_pack
16814 && lang_hooks
.function_parameter_pack_p (parm_pack
)
16817 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
16818 add_src_coords_attributes (parm_pack_die
, parm_pack
);
16820 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
16822 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
16825 gen_formal_parameter_die (arg
, NULL
,
16826 false /* Don't emit name attribute. */,
16831 return parm_pack_die
;
16834 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
16835 at the end of an (ANSI prototyped) formal parameters list. */
16838 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
16840 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
16843 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
16844 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
16845 parameters as specified in some function type specification (except for
16846 those which appear as part of a function *definition*). */
16849 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
16852 tree formal_type
= NULL
;
16853 tree first_parm_type
;
16856 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
16858 arg
= DECL_ARGUMENTS (function_or_method_type
);
16859 function_or_method_type
= TREE_TYPE (function_or_method_type
);
16864 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
16866 /* Make our first pass over the list of formal parameter types and output a
16867 DW_TAG_formal_parameter DIE for each one. */
16868 for (link
= first_parm_type
; link
; )
16870 dw_die_ref parm_die
;
16872 formal_type
= TREE_VALUE (link
);
16873 if (formal_type
== void_type_node
)
16876 /* Output a (nameless) DIE to represent the formal parameter itself. */
16877 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
16878 true /* Emit name attribute. */,
16880 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
16881 && link
== first_parm_type
)
16883 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
16884 if (dwarf_version
>= 3 || !dwarf_strict
)
16885 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
16887 else if (arg
&& DECL_ARTIFICIAL (arg
))
16888 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
16890 link
= TREE_CHAIN (link
);
16892 arg
= DECL_CHAIN (arg
);
16895 /* If this function type has an ellipsis, add a
16896 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
16897 if (formal_type
!= void_type_node
)
16898 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
16900 /* Make our second (and final) pass over the list of formal parameter types
16901 and output DIEs to represent those types (as necessary). */
16902 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
16903 link
&& TREE_VALUE (link
);
16904 link
= TREE_CHAIN (link
))
16905 gen_type_die (TREE_VALUE (link
), context_die
);
16908 /* We want to generate the DIE for TYPE so that we can generate the
16909 die for MEMBER, which has been defined; we will need to refer back
16910 to the member declaration nested within TYPE. If we're trying to
16911 generate minimal debug info for TYPE, processing TYPE won't do the
16912 trick; we need to attach the member declaration by hand. */
16915 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
16917 gen_type_die (type
, context_die
);
16919 /* If we're trying to avoid duplicate debug info, we may not have
16920 emitted the member decl for this function. Emit it now. */
16921 if (TYPE_STUB_DECL (type
)
16922 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
16923 && ! lookup_decl_die (member
))
16925 dw_die_ref type_die
;
16926 gcc_assert (!decl_ultimate_origin (member
));
16928 push_decl_scope (type
);
16929 type_die
= lookup_type_die_strip_naming_typedef (type
);
16930 if (TREE_CODE (member
) == FUNCTION_DECL
)
16931 gen_subprogram_die (member
, type_die
);
16932 else if (TREE_CODE (member
) == FIELD_DECL
)
16934 /* Ignore the nameless fields that are used to skip bits but handle
16935 C++ anonymous unions and structs. */
16936 if (DECL_NAME (member
) != NULL_TREE
16937 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
16938 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
16940 gen_type_die (member_declared_type (member
), type_die
);
16941 gen_field_die (member
, type_die
);
16945 gen_variable_die (member
, NULL_TREE
, type_die
);
16951 /* Generate the DWARF2 info for the "abstract" instance of a function which we
16952 may later generate inlined and/or out-of-line instances of. */
16955 dwarf2out_abstract_function (tree decl
)
16957 dw_die_ref old_die
;
16961 htab_t old_decl_loc_table
;
16962 htab_t old_cached_dw_loc_list_table
;
16963 int old_call_site_count
, old_tail_call_site_count
;
16964 struct call_arg_loc_node
*old_call_arg_locations
;
16966 /* Make sure we have the actual abstract inline, not a clone. */
16967 decl
= DECL_ORIGIN (decl
);
16969 old_die
= lookup_decl_die (decl
);
16970 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
16971 /* We've already generated the abstract instance. */
16974 /* We can be called while recursively when seeing block defining inlined subroutine
16975 DIE. Be sure to not clobber the outer location table nor use it or we would
16976 get locations in abstract instantces. */
16977 old_decl_loc_table
= decl_loc_table
;
16978 decl_loc_table
= NULL
;
16979 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
16980 cached_dw_loc_list_table
= NULL
;
16981 old_call_arg_locations
= call_arg_locations
;
16982 call_arg_locations
= NULL
;
16983 old_call_site_count
= call_site_count
;
16984 call_site_count
= -1;
16985 old_tail_call_site_count
= tail_call_site_count
;
16986 tail_call_site_count
= -1;
16988 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
16989 we don't get confused by DECL_ABSTRACT. */
16990 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16992 context
= decl_class_context (decl
);
16994 gen_type_die_for_member
16995 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
16998 /* Pretend we've just finished compiling this function. */
16999 save_fn
= current_function_decl
;
17000 current_function_decl
= decl
;
17001 push_cfun (DECL_STRUCT_FUNCTION (decl
));
17003 was_abstract
= DECL_ABSTRACT (decl
);
17004 set_decl_abstract_flags (decl
, 1);
17005 dwarf2out_decl (decl
);
17006 if (! was_abstract
)
17007 set_decl_abstract_flags (decl
, 0);
17009 current_function_decl
= save_fn
;
17010 decl_loc_table
= old_decl_loc_table
;
17011 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
17012 call_arg_locations
= old_call_arg_locations
;
17013 call_site_count
= old_call_site_count
;
17014 tail_call_site_count
= old_tail_call_site_count
;
17018 /* Helper function of premark_used_types() which gets called through
17021 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17022 marked as unused by prune_unused_types. */
17025 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
17030 type
= (tree
) *slot
;
17031 die
= lookup_type_die (type
);
17033 die
->die_perennial_p
= 1;
17037 /* Helper function of premark_types_used_by_global_vars which gets called
17038 through htab_traverse.
17040 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17041 marked as unused by prune_unused_types. The DIE of the type is marked
17042 only if the global variable using the type will actually be emitted. */
17045 premark_types_used_by_global_vars_helper (void **slot
,
17046 void *data ATTRIBUTE_UNUSED
)
17048 struct types_used_by_vars_entry
*entry
;
17051 entry
= (struct types_used_by_vars_entry
*) *slot
;
17052 gcc_assert (entry
->type
!= NULL
17053 && entry
->var_decl
!= NULL
);
17054 die
= lookup_type_die (entry
->type
);
17057 /* Ask cgraph if the global variable really is to be emitted.
17058 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17059 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
17060 if (node
&& node
->needed
)
17062 die
->die_perennial_p
= 1;
17063 /* Keep the parent DIEs as well. */
17064 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
17065 die
->die_perennial_p
= 1;
17071 /* Mark all members of used_types_hash as perennial. */
17074 premark_used_types (void)
17076 if (cfun
&& cfun
->used_types_hash
)
17077 htab_traverse (cfun
->used_types_hash
, premark_used_types_helper
, NULL
);
17080 /* Mark all members of types_used_by_vars_entry as perennial. */
17083 premark_types_used_by_global_vars (void)
17085 if (types_used_by_vars_hash
)
17086 htab_traverse (types_used_by_vars_hash
,
17087 premark_types_used_by_global_vars_helper
, NULL
);
17090 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17091 for CA_LOC call arg loc node. */
17094 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
17095 struct call_arg_loc_node
*ca_loc
)
17097 dw_die_ref stmt_die
= NULL
, die
;
17098 tree block
= ca_loc
->block
;
17101 && block
!= DECL_INITIAL (decl
)
17102 && TREE_CODE (block
) == BLOCK
)
17104 if (VEC_length (dw_die_ref
, block_map
) > BLOCK_NUMBER (block
))
17105 stmt_die
= VEC_index (dw_die_ref
, block_map
, BLOCK_NUMBER (block
));
17108 block
= BLOCK_SUPERCONTEXT (block
);
17110 if (stmt_die
== NULL
)
17111 stmt_die
= subr_die
;
17112 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
17113 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
17114 if (ca_loc
->tail_call_p
)
17115 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
17116 if (ca_loc
->symbol_ref
)
17118 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
17120 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
17122 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
);
17127 /* Generate a DIE to represent a declared function (either file-scope or
17131 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
17133 tree origin
= decl_ultimate_origin (decl
);
17134 dw_die_ref subr_die
;
17136 dw_die_ref old_die
= lookup_decl_die (decl
);
17137 int declaration
= (current_function_decl
!= decl
17138 || class_or_namespace_scope_p (context_die
));
17140 premark_used_types ();
17142 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17143 started to generate the abstract instance of an inline, decided to output
17144 its containing class, and proceeded to emit the declaration of the inline
17145 from the member list for the class. If so, DECLARATION takes priority;
17146 we'll get back to the abstract instance when done with the class. */
17148 /* The class-scope declaration DIE must be the primary DIE. */
17149 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
17152 gcc_assert (!old_die
);
17155 /* Now that the C++ front end lazily declares artificial member fns, we
17156 might need to retrofit the declaration into its class. */
17157 if (!declaration
&& !origin
&& !old_die
17158 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
17159 && !class_or_namespace_scope_p (context_die
)
17160 && debug_info_level
> DINFO_LEVEL_TERSE
)
17161 old_die
= force_decl_die (decl
);
17163 if (origin
!= NULL
)
17165 gcc_assert (!declaration
|| local_scope_p (context_die
));
17167 /* Fixup die_parent for the abstract instance of a nested
17168 inline function. */
17169 if (old_die
&& old_die
->die_parent
== NULL
)
17170 add_child_die (context_die
, old_die
);
17172 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17173 add_abstract_origin_attribute (subr_die
, origin
);
17174 /* This is where the actual code for a cloned function is.
17175 Let's emit linkage name attribute for it. This helps
17176 debuggers to e.g, set breakpoints into
17177 constructors/destructors when the user asks "break
17179 add_linkage_name (subr_die
, decl
);
17183 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17184 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17186 if (!get_AT_flag (old_die
, DW_AT_declaration
)
17187 /* We can have a normal definition following an inline one in the
17188 case of redefinition of GNU C extern inlines.
17189 It seems reasonable to use AT_specification in this case. */
17190 && !get_AT (old_die
, DW_AT_inline
))
17192 /* Detect and ignore this case, where we are trying to output
17193 something we have already output. */
17197 /* If the definition comes from the same place as the declaration,
17198 maybe use the old DIE. We always want the DIE for this function
17199 that has the *_pc attributes to be under comp_unit_die so the
17200 debugger can find it. We also need to do this for abstract
17201 instances of inlines, since the spec requires the out-of-line copy
17202 to have the same parent. For local class methods, this doesn't
17203 apply; we just use the old DIE. */
17204 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
17205 && (DECL_ARTIFICIAL (decl
)
17206 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
17207 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
17208 == (unsigned) s
.line
))))
17210 subr_die
= old_die
;
17212 /* Clear out the declaration attribute and the formal parameters.
17213 Do not remove all children, because it is possible that this
17214 declaration die was forced using force_decl_die(). In such
17215 cases die that forced declaration die (e.g. TAG_imported_module)
17216 is one of the children that we do not want to remove. */
17217 remove_AT (subr_die
, DW_AT_declaration
);
17218 remove_AT (subr_die
, DW_AT_object_pointer
);
17219 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
17223 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17224 add_AT_specification (subr_die
, old_die
);
17225 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17226 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
17227 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17228 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
17233 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17235 if (TREE_PUBLIC (decl
))
17236 add_AT_flag (subr_die
, DW_AT_external
, 1);
17238 add_name_and_src_coords_attributes (subr_die
, decl
);
17239 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17241 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
17242 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
17243 0, 0, context_die
);
17246 add_pure_or_virtual_attribute (subr_die
, decl
);
17247 if (DECL_ARTIFICIAL (decl
))
17248 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17250 add_accessibility_attribute (subr_die
, decl
);
17255 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17257 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
17259 /* If this is an explicit function declaration then generate
17260 a DW_AT_explicit attribute. */
17261 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
17262 && (dwarf_version
>= 3 || !dwarf_strict
))
17263 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
17265 /* The first time we see a member function, it is in the context of
17266 the class to which it belongs. We make sure of this by emitting
17267 the class first. The next time is the definition, which is
17268 handled above. The two may come from the same source text.
17270 Note that force_decl_die() forces function declaration die. It is
17271 later reused to represent definition. */
17272 equate_decl_number_to_die (decl
, subr_die
);
17275 else if (DECL_ABSTRACT (decl
))
17277 if (DECL_DECLARED_INLINE_P (decl
))
17279 if (cgraph_function_possibly_inlined_p (decl
))
17280 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
17282 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
17286 if (cgraph_function_possibly_inlined_p (decl
))
17287 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
17289 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
17292 if (DECL_DECLARED_INLINE_P (decl
)
17293 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
17294 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17296 equate_decl_number_to_die (decl
, subr_die
);
17298 else if (!DECL_EXTERNAL (decl
))
17300 HOST_WIDE_INT cfa_fb_offset
;
17302 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17303 equate_decl_number_to_die (decl
, subr_die
);
17305 if (!flag_reorder_blocks_and_partition
)
17307 dw_fde_ref fde
= cfun
->fde
;
17308 if (fde
->dw_fde_begin
)
17310 /* We have already generated the labels. */
17311 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, fde
->dw_fde_begin
);
17312 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, fde
->dw_fde_end
);
17316 /* Create start/end labels and add the range. */
17317 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
17318 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
17319 current_function_funcdef_no
);
17320 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
17321 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
17322 current_function_funcdef_no
);
17323 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
17326 #if VMS_DEBUGGING_INFO
17327 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17328 Section 2.3 Prologue and Epilogue Attributes:
17329 When a breakpoint is set on entry to a function, it is generally
17330 desirable for execution to be suspended, not on the very first
17331 instruction of the function, but rather at a point after the
17332 function's frame has been set up, after any language defined local
17333 declaration processing has been completed, and before execution of
17334 the first statement of the function begins. Debuggers generally
17335 cannot properly determine where this point is. Similarly for a
17336 breakpoint set on exit from a function. The prologue and epilogue
17337 attributes allow a compiler to communicate the location(s) to use. */
17340 if (fde
->dw_fde_vms_end_prologue
)
17341 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
17342 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
17344 if (fde
->dw_fde_vms_begin_epilogue
)
17345 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
17346 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
17350 add_pubname (decl
, subr_die
);
17354 /* Generate pubnames entries for the split function code ranges. */
17355 dw_fde_ref fde
= cfun
->fde
;
17357 if (fde
->dw_fde_second_begin
)
17359 if (dwarf_version
>= 3 || !dwarf_strict
)
17361 /* We should use ranges for non-contiguous code section
17362 addresses. Use the actual code range for the initial
17363 section, since the HOT/COLD labels might precede an
17364 alignment offset. */
17365 bool range_list_added
= false;
17366 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
17367 fde
->dw_fde_end
, &range_list_added
);
17368 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
17369 fde
->dw_fde_second_end
,
17370 &range_list_added
);
17371 add_pubname (decl
, subr_die
);
17372 if (range_list_added
)
17377 /* There is no real support in DW2 for this .. so we make
17378 a work-around. First, emit the pub name for the segment
17379 containing the function label. Then make and emit a
17380 simplified subprogram DIE for the second segment with the
17381 name pre-fixed by __hot/cold_sect_of_. We use the same
17382 linkage name for the second die so that gdb will find both
17383 sections when given "b foo". */
17384 const char *name
= NULL
;
17385 tree decl_name
= DECL_NAME (decl
);
17386 dw_die_ref seg_die
;
17388 /* Do the 'primary' section. */
17389 add_AT_lbl_id (subr_die
, DW_AT_low_pc
,
17390 fde
->dw_fde_begin
);
17391 add_AT_lbl_id (subr_die
, DW_AT_high_pc
,
17394 add_pubname (decl
, subr_die
);
17396 /* Build a minimal DIE for the secondary section. */
17397 seg_die
= new_die (DW_TAG_subprogram
,
17398 subr_die
->die_parent
, decl
);
17400 if (TREE_PUBLIC (decl
))
17401 add_AT_flag (seg_die
, DW_AT_external
, 1);
17403 if (decl_name
!= NULL
17404 && IDENTIFIER_POINTER (decl_name
) != NULL
)
17406 name
= dwarf2_name (decl
, 1);
17407 if (! DECL_ARTIFICIAL (decl
))
17408 add_src_coords_attributes (seg_die
, decl
);
17410 add_linkage_name (seg_die
, decl
);
17412 gcc_assert (name
!= NULL
);
17413 add_pure_or_virtual_attribute (seg_die
, decl
);
17414 if (DECL_ARTIFICIAL (decl
))
17415 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
17417 name
= concat ("__second_sect_of_", name
, NULL
);
17418 add_AT_lbl_id (seg_die
, DW_AT_low_pc
,
17419 fde
->dw_fde_second_begin
);
17420 add_AT_lbl_id (seg_die
, DW_AT_high_pc
,
17421 fde
->dw_fde_second_end
);
17422 add_name_attribute (seg_die
, name
);
17423 add_pubname_string (name
, seg_die
);
17428 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, fde
->dw_fde_begin
);
17429 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, fde
->dw_fde_end
);
17430 add_pubname (decl
, subr_die
);
17434 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
17436 /* We define the "frame base" as the function's CFA. This is more
17437 convenient for several reasons: (1) It's stable across the prologue
17438 and epilogue, which makes it better than just a frame pointer,
17439 (2) With dwarf3, there exists a one-byte encoding that allows us
17440 to reference the .debug_frame data by proxy, but failing that,
17441 (3) We can at least reuse the code inspection and interpretation
17442 code that determines the CFA position at various points in the
17444 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
17446 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
17447 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
17451 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
17452 if (list
->dw_loc_next
)
17453 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
17455 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
17458 /* Compute a displacement from the "steady-state frame pointer" to
17459 the CFA. The former is what all stack slots and argument slots
17460 will reference in the rtl; the later is what we've told the
17461 debugger about. We'll need to adjust all frame_base references
17462 by this displacement. */
17463 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
17465 if (cfun
->static_chain_decl
)
17466 add_AT_location_description (subr_die
, DW_AT_static_link
,
17467 loc_list_from_tree (cfun
->static_chain_decl
, 2));
17470 /* Generate child dies for template paramaters. */
17471 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17472 gen_generic_params_dies (decl
);
17474 /* Now output descriptions of the arguments for this function. This gets
17475 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
17476 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
17477 `...' at the end of the formal parameter list. In order to find out if
17478 there was a trailing ellipsis or not, we must instead look at the type
17479 associated with the FUNCTION_DECL. This will be a node of type
17480 FUNCTION_TYPE. If the chain of type nodes hanging off of this
17481 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
17482 an ellipsis at the end. */
17484 /* In the case where we are describing a mere function declaration, all we
17485 need to do here (and all we *can* do here) is to describe the *types* of
17486 its formal parameters. */
17487 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
17489 else if (declaration
)
17490 gen_formal_types_die (decl
, subr_die
);
17493 /* Generate DIEs to represent all known formal parameters. */
17494 tree parm
= DECL_ARGUMENTS (decl
);
17495 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
17496 tree generic_decl_parm
= generic_decl
17497 ? DECL_ARGUMENTS (generic_decl
)
17500 /* Now we want to walk the list of parameters of the function and
17501 emit their relevant DIEs.
17503 We consider the case of DECL being an instance of a generic function
17504 as well as it being a normal function.
17506 If DECL is an instance of a generic function we walk the
17507 parameters of the generic function declaration _and_ the parameters of
17508 DECL itself. This is useful because we want to emit specific DIEs for
17509 function parameter packs and those are declared as part of the
17510 generic function declaration. In that particular case,
17511 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
17512 That DIE has children DIEs representing the set of arguments
17513 of the pack. Note that the set of pack arguments can be empty.
17514 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
17517 Otherwise, we just consider the parameters of DECL. */
17518 while (generic_decl_parm
|| parm
)
17520 if (generic_decl_parm
17521 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
17522 gen_formal_parameter_pack_die (generic_decl_parm
,
17527 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
17529 if (parm
== DECL_ARGUMENTS (decl
)
17530 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
17532 && (dwarf_version
>= 3 || !dwarf_strict
))
17533 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
17535 parm
= DECL_CHAIN (parm
);
17538 if (generic_decl_parm
)
17539 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
17542 /* Decide whether we need an unspecified_parameters DIE at the end.
17543 There are 2 more cases to do this for: 1) the ansi ... declaration -
17544 this is detectable when the end of the arg list is not a
17545 void_type_node 2) an unprototyped function declaration (not a
17546 definition). This just means that we have no info about the
17547 parameters at all. */
17548 if (prototype_p (TREE_TYPE (decl
)))
17550 /* This is the prototyped case, check for.... */
17551 if (stdarg_p (TREE_TYPE (decl
)))
17552 gen_unspecified_parameters_die (decl
, subr_die
);
17554 else if (DECL_INITIAL (decl
) == NULL_TREE
)
17555 gen_unspecified_parameters_die (decl
, subr_die
);
17558 /* Output Dwarf info for all of the stuff within the body of the function
17559 (if it has one - it may be just a declaration). */
17560 outer_scope
= DECL_INITIAL (decl
);
17562 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
17563 a function. This BLOCK actually represents the outermost binding contour
17564 for the function, i.e. the contour in which the function's formal
17565 parameters and labels get declared. Curiously, it appears that the front
17566 end doesn't actually put the PARM_DECL nodes for the current function onto
17567 the BLOCK_VARS list for this outer scope, but are strung off of the
17568 DECL_ARGUMENTS list for the function instead.
17570 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
17571 the LABEL_DECL nodes for the function however, and we output DWARF info
17572 for those in decls_for_scope. Just within the `outer_scope' there will be
17573 a BLOCK node representing the function's outermost pair of curly braces,
17574 and any blocks used for the base and member initializers of a C++
17575 constructor function. */
17576 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
17578 int call_site_note_count
= 0;
17579 int tail_call_site_note_count
= 0;
17581 /* Emit a DW_TAG_variable DIE for a named return value. */
17582 if (DECL_NAME (DECL_RESULT (decl
)))
17583 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
17585 current_function_has_inlines
= 0;
17586 decls_for_scope (outer_scope
, subr_die
, 0);
17588 if (call_arg_locations
&& !dwarf_strict
)
17590 struct call_arg_loc_node
*ca_loc
;
17591 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
17593 dw_die_ref die
= NULL
;
17594 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
17597 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
17598 arg
; arg
= next_arg
)
17600 dw_loc_descr_ref reg
, val
;
17601 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
17602 dw_die_ref cdie
, tdie
= NULL
;
17604 next_arg
= XEXP (arg
, 1);
17605 if (REG_P (XEXP (XEXP (arg
, 0), 0))
17607 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
17608 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
17609 && REGNO (XEXP (XEXP (arg
, 0), 0))
17610 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
17611 next_arg
= XEXP (next_arg
, 1);
17612 if (mode
== VOIDmode
)
17614 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
17615 if (mode
== VOIDmode
)
17616 mode
= GET_MODE (XEXP (arg
, 0));
17618 if (mode
== VOIDmode
|| mode
== BLKmode
)
17620 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
17622 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
17623 tloc
= XEXP (XEXP (arg
, 0), 1);
17626 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
17627 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
17629 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
17630 tlocc
= XEXP (XEXP (arg
, 0), 1);
17634 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
17635 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
17636 VAR_INIT_STATUS_INITIALIZED
);
17637 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
17639 rtx mem
= XEXP (XEXP (arg
, 0), 0);
17640 reg
= mem_loc_descriptor (XEXP (mem
, 0),
17641 get_address_mode (mem
),
17643 VAR_INIT_STATUS_INITIALIZED
);
17645 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
17646 == DEBUG_PARAMETER_REF
)
17649 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
17650 tdie
= lookup_decl_die (tdecl
);
17657 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
17658 != DEBUG_PARAMETER_REF
)
17660 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
17662 VAR_INIT_STATUS_INITIALIZED
);
17666 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
17667 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
17670 add_AT_loc (cdie
, DW_AT_location
, reg
);
17671 else if (tdie
!= NULL
)
17672 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
17673 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
17674 if (next_arg
!= XEXP (arg
, 1))
17676 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
17677 if (mode
== VOIDmode
)
17678 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
17679 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
17682 VAR_INIT_STATUS_INITIALIZED
);
17684 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
17688 && (ca_loc
->symbol_ref
|| tloc
))
17689 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
17690 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
17692 dw_loc_descr_ref tval
= NULL
;
17694 if (tloc
!= NULL_RTX
)
17695 tval
= mem_loc_descriptor (tloc
,
17696 GET_MODE (tloc
) == VOIDmode
17697 ? Pmode
: GET_MODE (tloc
),
17699 VAR_INIT_STATUS_INITIALIZED
);
17701 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
17702 else if (tlocc
!= NULL_RTX
)
17704 tval
= mem_loc_descriptor (tlocc
,
17705 GET_MODE (tlocc
) == VOIDmode
17706 ? Pmode
: GET_MODE (tlocc
),
17708 VAR_INIT_STATUS_INITIALIZED
);
17710 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
17716 call_site_note_count
++;
17717 if (ca_loc
->tail_call_p
)
17718 tail_call_site_note_count
++;
17722 call_arg_locations
= NULL
;
17723 call_arg_loc_last
= NULL
;
17724 if (tail_call_site_count
>= 0
17725 && tail_call_site_count
== tail_call_site_note_count
17728 if (call_site_count
>= 0
17729 && call_site_count
== call_site_note_count
)
17730 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
17732 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
17734 call_site_count
= -1;
17735 tail_call_site_count
= -1;
17737 /* Add the calling convention attribute if requested. */
17738 add_calling_convention_attribute (subr_die
, decl
);
17742 /* Returns a hash value for X (which really is a die_struct). */
17745 common_block_die_table_hash (const void *x
)
17747 const_dw_die_ref d
= (const_dw_die_ref
) x
;
17748 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
17751 /* Return nonzero if decl_id and die_parent of die_struct X is the same
17752 as decl_id and die_parent of die_struct Y. */
17755 common_block_die_table_eq (const void *x
, const void *y
)
17757 const_dw_die_ref d
= (const_dw_die_ref
) x
;
17758 const_dw_die_ref e
= (const_dw_die_ref
) y
;
17759 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
17762 /* Generate a DIE to represent a declared data object.
17763 Either DECL or ORIGIN must be non-null. */
17766 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
17770 tree decl_or_origin
= decl
? decl
: origin
;
17771 tree ultimate_origin
;
17772 dw_die_ref var_die
;
17773 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
17774 dw_die_ref origin_die
;
17775 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
17776 || class_or_namespace_scope_p (context_die
));
17777 bool specialization_p
= false;
17779 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
17780 if (decl
|| ultimate_origin
)
17781 origin
= ultimate_origin
;
17782 com_decl
= fortran_common (decl_or_origin
, &off
);
17784 /* Symbol in common gets emitted as a child of the common block, in the form
17785 of a data member. */
17788 dw_die_ref com_die
;
17789 dw_loc_list_ref loc
;
17790 die_node com_die_arg
;
17792 var_die
= lookup_decl_die (decl_or_origin
);
17795 if (get_AT (var_die
, DW_AT_location
) == NULL
)
17797 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
17802 /* Optimize the common case. */
17803 if (single_element_loc_list_p (loc
)
17804 && loc
->expr
->dw_loc_opc
== DW_OP_addr
17805 && loc
->expr
->dw_loc_next
== NULL
17806 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
17808 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
17809 = plus_constant (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
, off
);
17811 loc_list_plus_const (loc
, off
);
17813 add_AT_location_description (var_die
, DW_AT_location
, loc
);
17814 remove_AT (var_die
, DW_AT_declaration
);
17820 if (common_block_die_table
== NULL
)
17821 common_block_die_table
17822 = htab_create_ggc (10, common_block_die_table_hash
,
17823 common_block_die_table_eq
, NULL
);
17825 com_die_arg
.decl_id
= DECL_UID (com_decl
);
17826 com_die_arg
.die_parent
= context_die
;
17827 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
17828 loc
= loc_list_from_tree (com_decl
, 2);
17829 if (com_die
== NULL
)
17832 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
17835 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
17836 add_name_and_src_coords_attributes (com_die
, com_decl
);
17839 add_AT_location_description (com_die
, DW_AT_location
, loc
);
17840 /* Avoid sharing the same loc descriptor between
17841 DW_TAG_common_block and DW_TAG_variable. */
17842 loc
= loc_list_from_tree (com_decl
, 2);
17844 else if (DECL_EXTERNAL (decl
))
17845 add_AT_flag (com_die
, DW_AT_declaration
, 1);
17846 add_pubname_string (cnam
, com_die
); /* ??? needed? */
17847 com_die
->decl_id
= DECL_UID (com_decl
);
17848 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
17849 *slot
= (void *) com_die
;
17851 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
17853 add_AT_location_description (com_die
, DW_AT_location
, loc
);
17854 loc
= loc_list_from_tree (com_decl
, 2);
17855 remove_AT (com_die
, DW_AT_declaration
);
17857 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
17858 add_name_and_src_coords_attributes (var_die
, decl
);
17859 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
17860 TREE_THIS_VOLATILE (decl
), context_die
);
17861 add_AT_flag (var_die
, DW_AT_external
, 1);
17866 /* Optimize the common case. */
17867 if (single_element_loc_list_p (loc
)
17868 && loc
->expr
->dw_loc_opc
== DW_OP_addr
17869 && loc
->expr
->dw_loc_next
== NULL
17870 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
17871 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
17872 = plus_constant (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
, off
);
17874 loc_list_plus_const (loc
, off
);
17876 add_AT_location_description (var_die
, DW_AT_location
, loc
);
17878 else if (DECL_EXTERNAL (decl
))
17879 add_AT_flag (var_die
, DW_AT_declaration
, 1);
17880 equate_decl_number_to_die (decl
, var_die
);
17884 /* If the compiler emitted a definition for the DECL declaration
17885 and if we already emitted a DIE for it, don't emit a second
17886 DIE for it again. Allow re-declarations of DECLs that are
17887 inside functions, though. */
17888 if (old_die
&& declaration
&& !local_scope_p (context_die
))
17891 /* For static data members, the declaration in the class is supposed
17892 to have DW_TAG_member tag; the specification should still be
17893 DW_TAG_variable referencing the DW_TAG_member DIE. */
17894 if (declaration
&& class_scope_p (context_die
))
17895 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
17897 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
17900 if (origin
!= NULL
)
17901 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
17903 /* Loop unrolling can create multiple blocks that refer to the same
17904 static variable, so we must test for the DW_AT_declaration flag.
17906 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
17907 copy decls and set the DECL_ABSTRACT flag on them instead of
17910 ??? Duplicated blocks have been rewritten to use .debug_ranges.
17912 ??? The declare_in_namespace support causes us to get two DIEs for one
17913 variable, both of which are declarations. We want to avoid considering
17914 one to be a specification, so we must test that this DIE is not a
17916 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
17917 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
17919 /* This is a definition of a C++ class level static. */
17920 add_AT_specification (var_die
, old_die
);
17921 specialization_p
= true;
17922 if (DECL_NAME (decl
))
17924 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17925 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17927 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17928 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
17930 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17931 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
17933 if (old_die
->die_tag
== DW_TAG_member
)
17934 add_linkage_name (var_die
, decl
);
17938 add_name_and_src_coords_attributes (var_die
, decl
);
17940 if ((origin
== NULL
&& !specialization_p
)
17942 && !DECL_ABSTRACT (decl_or_origin
)
17943 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
17944 decl_function_context
17945 (decl_or_origin
))))
17947 tree type
= TREE_TYPE (decl_or_origin
);
17949 if (decl_by_reference_p (decl_or_origin
))
17950 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
17952 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
17953 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
17956 if (origin
== NULL
&& !specialization_p
)
17958 if (TREE_PUBLIC (decl
))
17959 add_AT_flag (var_die
, DW_AT_external
, 1);
17961 if (DECL_ARTIFICIAL (decl
))
17962 add_AT_flag (var_die
, DW_AT_artificial
, 1);
17964 add_accessibility_attribute (var_die
, decl
);
17968 add_AT_flag (var_die
, DW_AT_declaration
, 1);
17970 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
17971 equate_decl_number_to_die (decl
, var_die
);
17974 && (! DECL_ABSTRACT (decl_or_origin
)
17975 /* Local static vars are shared between all clones/inlines,
17976 so emit DW_AT_location on the abstract DIE if DECL_RTL is
17978 || (TREE_CODE (decl_or_origin
) == VAR_DECL
17979 && TREE_STATIC (decl_or_origin
)
17980 && DECL_RTL_SET_P (decl_or_origin
)))
17981 /* When abstract origin already has DW_AT_location attribute, no need
17982 to add it again. */
17983 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
17985 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
17986 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
17987 defer_location (decl_or_origin
, var_die
);
17989 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
17990 decl
== NULL
, DW_AT_location
);
17991 add_pubname (decl_or_origin
, var_die
);
17994 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
17997 /* Generate a DIE to represent a named constant. */
18000 gen_const_die (tree decl
, dw_die_ref context_die
)
18002 dw_die_ref const_die
;
18003 tree type
= TREE_TYPE (decl
);
18005 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
18006 add_name_and_src_coords_attributes (const_die
, decl
);
18007 add_type_attribute (const_die
, type
, 1, 0, context_die
);
18008 if (TREE_PUBLIC (decl
))
18009 add_AT_flag (const_die
, DW_AT_external
, 1);
18010 if (DECL_ARTIFICIAL (decl
))
18011 add_AT_flag (const_die
, DW_AT_artificial
, 1);
18012 tree_add_const_value_attribute_for_decl (const_die
, decl
);
18015 /* Generate a DIE to represent a label identifier. */
18018 gen_label_die (tree decl
, dw_die_ref context_die
)
18020 tree origin
= decl_ultimate_origin (decl
);
18021 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
18023 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18025 if (origin
!= NULL
)
18026 add_abstract_origin_attribute (lbl_die
, origin
);
18028 add_name_and_src_coords_attributes (lbl_die
, decl
);
18030 if (DECL_ABSTRACT (decl
))
18031 equate_decl_number_to_die (decl
, lbl_die
);
18034 insn
= DECL_RTL_IF_SET (decl
);
18036 /* Deleted labels are programmer specified labels which have been
18037 eliminated because of various optimizations. We still emit them
18038 here so that it is possible to put breakpoints on them. */
18042 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
18044 /* When optimization is enabled (via -O) some parts of the compiler
18045 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18046 represent source-level labels which were explicitly declared by
18047 the user. This really shouldn't be happening though, so catch
18048 it if it ever does happen. */
18049 gcc_assert (!INSN_DELETED_P (insn
));
18051 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
18052 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18056 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
18057 && CODE_LABEL_NUMBER (insn
) != -1)
18059 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
18060 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18065 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18066 attributes to the DIE for a block STMT, to describe where the inlined
18067 function was called from. This is similar to add_src_coords_attributes. */
18070 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
18072 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
18074 if (dwarf_version
>= 3 || !dwarf_strict
)
18076 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
18077 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
18082 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18083 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18086 add_high_low_attributes (tree stmt
, dw_die_ref die
)
18088 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18090 if (BLOCK_FRAGMENT_CHAIN (stmt
)
18091 && (dwarf_version
>= 3 || !dwarf_strict
))
18093 tree chain
, superblock
= NULL_TREE
;
18095 dw_attr_ref attr
= NULL
;
18097 if (inlined_function_outer_scope_p (stmt
))
18099 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18100 BLOCK_NUMBER (stmt
));
18101 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
18104 /* Optimize duplicate .debug_ranges lists or even tails of
18105 lists. If this BLOCK has same ranges as its supercontext,
18106 lookup DW_AT_ranges attribute in the supercontext (and
18107 recursively so), verify that the ranges_table contains the
18108 right values and use it instead of adding a new .debug_range. */
18109 for (chain
= stmt
, pdie
= die
;
18110 BLOCK_SAME_RANGE (chain
);
18111 chain
= BLOCK_SUPERCONTEXT (chain
))
18113 dw_attr_ref new_attr
;
18115 pdie
= pdie
->die_parent
;
18118 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
18120 new_attr
= get_AT (pdie
, DW_AT_ranges
);
18121 if (new_attr
== NULL
18122 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
18125 superblock
= BLOCK_SUPERCONTEXT (chain
);
18128 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
18129 / 2 / DWARF2_ADDR_SIZE
].num
18130 == BLOCK_NUMBER (superblock
))
18131 && BLOCK_FRAGMENT_CHAIN (superblock
))
18133 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
18134 / 2 / DWARF2_ADDR_SIZE
;
18135 unsigned long supercnt
= 0, thiscnt
= 0;
18136 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
18137 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18140 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
18141 == BLOCK_NUMBER (chain
));
18143 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
18144 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18145 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18147 gcc_assert (supercnt
>= thiscnt
);
18148 add_AT_range_list (die
, DW_AT_ranges
,
18149 (off
+ supercnt
- thiscnt
)
18150 * 2 * DWARF2_ADDR_SIZE
);
18154 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
));
18156 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18159 add_ranges (chain
);
18160 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
18167 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18168 BLOCK_NUMBER (stmt
));
18169 add_AT_lbl_id (die
, DW_AT_low_pc
, label
);
18170 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
18171 BLOCK_NUMBER (stmt
));
18172 add_AT_lbl_id (die
, DW_AT_high_pc
, label
);
18176 /* Generate a DIE for a lexical block. */
18179 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
18181 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
18183 if (call_arg_locations
)
18185 if (VEC_length (dw_die_ref
, block_map
) <= BLOCK_NUMBER (stmt
))
18186 VEC_safe_grow_cleared (dw_die_ref
, heap
, block_map
,
18187 BLOCK_NUMBER (stmt
) + 1);
18188 VEC_replace (dw_die_ref
, block_map
, BLOCK_NUMBER (stmt
), stmt_die
);
18191 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
18192 add_high_low_attributes (stmt
, stmt_die
);
18194 decls_for_scope (stmt
, stmt_die
, depth
);
18197 /* Generate a DIE for an inlined subprogram. */
18200 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
18204 /* The instance of function that is effectively being inlined shall not
18206 gcc_assert (! BLOCK_ABSTRACT (stmt
));
18208 decl
= block_ultimate_origin (stmt
);
18210 /* Emit info for the abstract instance first, if we haven't yet. We
18211 must emit this even if the block is abstract, otherwise when we
18212 emit the block below (or elsewhere), we may end up trying to emit
18213 a die whose origin die hasn't been emitted, and crashing. */
18214 dwarf2out_abstract_function (decl
);
18216 if (! BLOCK_ABSTRACT (stmt
))
18218 dw_die_ref subr_die
18219 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
18221 if (call_arg_locations
)
18223 if (VEC_length (dw_die_ref
, block_map
) <= BLOCK_NUMBER (stmt
))
18224 VEC_safe_grow_cleared (dw_die_ref
, heap
, block_map
,
18225 BLOCK_NUMBER (stmt
) + 1);
18226 VEC_replace (dw_die_ref
, block_map
, BLOCK_NUMBER (stmt
), subr_die
);
18228 add_abstract_origin_attribute (subr_die
, decl
);
18229 if (TREE_ASM_WRITTEN (stmt
))
18230 add_high_low_attributes (stmt
, subr_die
);
18231 add_call_src_coords_attributes (stmt
, subr_die
);
18233 decls_for_scope (stmt
, subr_die
, depth
);
18234 current_function_has_inlines
= 1;
18238 /* Generate a DIE for a field in a record, or structure. */
18241 gen_field_die (tree decl
, dw_die_ref context_die
)
18243 dw_die_ref decl_die
;
18245 if (TREE_TYPE (decl
) == error_mark_node
)
18248 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
18249 add_name_and_src_coords_attributes (decl_die
, decl
);
18250 add_type_attribute (decl_die
, member_declared_type (decl
),
18251 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
18254 if (DECL_BIT_FIELD_TYPE (decl
))
18256 add_byte_size_attribute (decl_die
, decl
);
18257 add_bit_size_attribute (decl_die
, decl
);
18258 add_bit_offset_attribute (decl_die
, decl
);
18261 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
18262 add_data_member_location_attribute (decl_die
, decl
);
18264 if (DECL_ARTIFICIAL (decl
))
18265 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
18267 add_accessibility_attribute (decl_die
, decl
);
18269 /* Equate decl number to die, so that we can look up this decl later on. */
18270 equate_decl_number_to_die (decl
, decl_die
);
18274 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18275 Use modified_type_die instead.
18276 We keep this code here just in case these types of DIEs may be needed to
18277 represent certain things in other languages (e.g. Pascal) someday. */
18280 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
18283 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
18285 equate_type_number_to_die (type
, ptr_die
);
18286 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18287 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18290 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18291 Use modified_type_die instead.
18292 We keep this code here just in case these types of DIEs may be needed to
18293 represent certain things in other languages (e.g. Pascal) someday. */
18296 gen_reference_type_die (tree type
, dw_die_ref context_die
)
18298 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
18300 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
18301 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
18303 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
18305 equate_type_number_to_die (type
, ref_die
);
18306 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
18307 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18311 /* Generate a DIE for a pointer to a member type. */
18314 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
18317 = new_die (DW_TAG_ptr_to_member_type
,
18318 scope_die_for (type
, context_die
), type
);
18320 equate_type_number_to_die (type
, ptr_die
);
18321 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
18322 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
18323 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18326 typedef const char *dchar_p
; /* For DEF_VEC_P. */
18327 DEF_VEC_P(dchar_p
);
18328 DEF_VEC_ALLOC_P(dchar_p
,heap
);
18330 static char *producer_string
;
18332 /* Return a heap allocated producer string including command line options
18333 if -grecord-gcc-switches. */
18336 gen_producer_string (void)
18339 VEC(dchar_p
, heap
) *switches
= NULL
;
18340 const char *language_string
= lang_hooks
.name
;
18341 char *producer
, *tail
;
18343 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
18344 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
18346 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
18347 switch (save_decoded_options
[j
].opt_index
)
18354 case OPT_auxbase_strip
:
18363 case OPT_SPECIAL_unknown
:
18364 case OPT_SPECIAL_ignore
:
18365 case OPT_SPECIAL_program_name
:
18366 case OPT_SPECIAL_input_file
:
18367 case OPT_grecord_gcc_switches
:
18368 case OPT_gno_record_gcc_switches
:
18369 case OPT__output_pch_
:
18370 case OPT_fdiagnostics_show_location_
:
18371 case OPT_fdiagnostics_show_option
:
18372 case OPT_fverbose_asm
:
18374 case OPT__sysroot_
:
18376 case OPT_nostdinc__
:
18377 /* Ignore these. */
18380 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
18382 switch (save_decoded_options
[j
].canonical_option
[0][1])
18389 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
18396 VEC_safe_push (dchar_p
, heap
, switches
,
18397 save_decoded_options
[j
].orig_option_with_args_text
);
18398 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
18402 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
18404 sprintf (tail
, "%s %s", language_string
, version_string
);
18407 FOR_EACH_VEC_ELT (dchar_p
, switches
, j
, p
)
18411 memcpy (tail
+ 1, p
, len
);
18416 VEC_free (dchar_p
, heap
, switches
);
18420 /* Generate the DIE for the compilation unit. */
18423 gen_compile_unit_die (const char *filename
)
18426 const char *language_string
= lang_hooks
.name
;
18429 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
18433 add_name_attribute (die
, filename
);
18434 /* Don't add cwd for <built-in>. */
18435 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
18436 add_comp_dir_attribute (die
);
18439 if (producer_string
== NULL
)
18440 producer_string
= gen_producer_string ();
18441 add_AT_string (die
, DW_AT_producer
, producer_string
);
18443 /* If our producer is LTO try to figure out a common language to use
18444 from the global list of translation units. */
18445 if (strcmp (language_string
, "GNU GIMPLE") == 0)
18449 const char *common_lang
= NULL
;
18451 FOR_EACH_VEC_ELT (tree
, all_translation_units
, i
, t
)
18453 if (!TRANSLATION_UNIT_LANGUAGE (t
))
18456 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
18457 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
18459 else if (strncmp (common_lang
, "GNU C", 5) == 0
18460 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
18461 /* Mixing C and C++ is ok, use C++ in that case. */
18462 common_lang
= "GNU C++";
18465 /* Fall back to C. */
18466 common_lang
= NULL
;
18472 language_string
= common_lang
;
18475 language
= DW_LANG_C89
;
18476 if (strcmp (language_string
, "GNU C++") == 0)
18477 language
= DW_LANG_C_plus_plus
;
18478 else if (strcmp (language_string
, "GNU F77") == 0)
18479 language
= DW_LANG_Fortran77
;
18480 else if (strcmp (language_string
, "GNU Pascal") == 0)
18481 language
= DW_LANG_Pascal83
;
18482 else if (dwarf_version
>= 3 || !dwarf_strict
)
18484 if (strcmp (language_string
, "GNU Ada") == 0)
18485 language
= DW_LANG_Ada95
;
18486 else if (strcmp (language_string
, "GNU Fortran") == 0)
18487 language
= DW_LANG_Fortran95
;
18488 else if (strcmp (language_string
, "GNU Java") == 0)
18489 language
= DW_LANG_Java
;
18490 else if (strcmp (language_string
, "GNU Objective-C") == 0)
18491 language
= DW_LANG_ObjC
;
18492 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
18493 language
= DW_LANG_ObjC_plus_plus
;
18494 else if (dwarf_version
>= 5 || !dwarf_strict
)
18496 if (strcmp (language_string
, "GNU Go") == 0)
18497 language
= DW_LANG_Go
;
18501 add_AT_unsigned (die
, DW_AT_language
, language
);
18505 case DW_LANG_Fortran77
:
18506 case DW_LANG_Fortran90
:
18507 case DW_LANG_Fortran95
:
18508 /* Fortran has case insensitive identifiers and the front-end
18509 lowercases everything. */
18510 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
18513 /* The default DW_ID_case_sensitive doesn't need to be specified. */
18519 /* Generate the DIE for a base class. */
18522 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
18524 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
18526 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
18527 add_data_member_location_attribute (die
, binfo
);
18529 if (BINFO_VIRTUAL_P (binfo
))
18530 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
18532 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18533 children, otherwise the default is DW_ACCESS_public. In DWARF2
18534 the default has always been DW_ACCESS_private. */
18535 if (access
== access_public_node
)
18537 if (dwarf_version
== 2
18538 || context_die
->die_tag
== DW_TAG_class_type
)
18539 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
18541 else if (access
== access_protected_node
)
18542 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
18543 else if (dwarf_version
> 2
18544 && context_die
->die_tag
!= DW_TAG_class_type
)
18545 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
18548 /* Generate a DIE for a class member. */
18551 gen_member_die (tree type
, dw_die_ref context_die
)
18554 tree binfo
= TYPE_BINFO (type
);
18557 /* If this is not an incomplete type, output descriptions of each of its
18558 members. Note that as we output the DIEs necessary to represent the
18559 members of this record or union type, we will also be trying to output
18560 DIEs to represent the *types* of those members. However the `type'
18561 function (above) will specifically avoid generating type DIEs for member
18562 types *within* the list of member DIEs for this (containing) type except
18563 for those types (of members) which are explicitly marked as also being
18564 members of this (containing) type themselves. The g++ front- end can
18565 force any given type to be treated as a member of some other (containing)
18566 type by setting the TYPE_CONTEXT of the given (member) type to point to
18567 the TREE node representing the appropriate (containing) type. */
18569 /* First output info about the base classes. */
18572 VEC(tree
,gc
) *accesses
= BINFO_BASE_ACCESSES (binfo
);
18576 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
18577 gen_inheritance_die (base
,
18578 (accesses
? VEC_index (tree
, accesses
, i
)
18579 : access_public_node
), context_die
);
18582 /* Now output info about the data members and type members. */
18583 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
18585 /* If we thought we were generating minimal debug info for TYPE
18586 and then changed our minds, some of the member declarations
18587 may have already been defined. Don't define them again, but
18588 do put them in the right order. */
18590 child
= lookup_decl_die (member
);
18592 splice_child_die (context_die
, child
);
18594 gen_decl_die (member
, NULL
, context_die
);
18597 /* Now output info about the function members (if any). */
18598 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
18600 /* Don't include clones in the member list. */
18601 if (DECL_ABSTRACT_ORIGIN (member
))
18604 child
= lookup_decl_die (member
);
18606 splice_child_die (context_die
, child
);
18608 gen_decl_die (member
, NULL
, context_die
);
18612 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
18613 is set, we pretend that the type was never defined, so we only get the
18614 member DIEs needed by later specification DIEs. */
18617 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
18618 enum debug_info_usage usage
)
18620 dw_die_ref type_die
= lookup_type_die (type
);
18621 dw_die_ref scope_die
= 0;
18623 int complete
= (TYPE_SIZE (type
)
18624 && (! TYPE_STUB_DECL (type
)
18625 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
18626 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
18627 complete
= complete
&& should_emit_struct_debug (type
, usage
);
18629 if (type_die
&& ! complete
)
18632 if (TYPE_CONTEXT (type
) != NULL_TREE
18633 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
18634 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
18637 scope_die
= scope_die_for (type
, context_die
);
18639 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
18640 /* First occurrence of type or toplevel definition of nested class. */
18642 dw_die_ref old_die
= type_die
;
18644 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
18645 ? record_type_tag (type
) : DW_TAG_union_type
,
18647 equate_type_number_to_die (type
, type_die
);
18649 add_AT_specification (type_die
, old_die
);
18651 add_name_attribute (type_die
, type_tag (type
));
18654 remove_AT (type_die
, DW_AT_declaration
);
18656 /* Generate child dies for template paramaters. */
18657 if (debug_info_level
> DINFO_LEVEL_TERSE
18658 && COMPLETE_TYPE_P (type
))
18659 schedule_generic_params_dies_gen (type
);
18661 /* If this type has been completed, then give it a byte_size attribute and
18662 then give a list of members. */
18663 if (complete
&& !ns_decl
)
18665 /* Prevent infinite recursion in cases where the type of some member of
18666 this type is expressed in terms of this type itself. */
18667 TREE_ASM_WRITTEN (type
) = 1;
18668 add_byte_size_attribute (type_die
, type
);
18669 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
18671 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
18672 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
18675 /* If the first reference to this type was as the return type of an
18676 inline function, then it may not have a parent. Fix this now. */
18677 if (type_die
->die_parent
== NULL
)
18678 add_child_die (scope_die
, type_die
);
18680 push_decl_scope (type
);
18681 gen_member_die (type
, type_die
);
18684 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
18685 if (TYPE_ARTIFICIAL (type
))
18686 add_AT_flag (type_die
, DW_AT_artificial
, 1);
18688 /* GNU extension: Record what type our vtable lives in. */
18689 if (TYPE_VFIELD (type
))
18691 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
18693 gen_type_die (vtype
, context_die
);
18694 add_AT_die_ref (type_die
, DW_AT_containing_type
,
18695 lookup_type_die (vtype
));
18700 add_AT_flag (type_die
, DW_AT_declaration
, 1);
18702 /* We don't need to do this for function-local types. */
18703 if (TYPE_STUB_DECL (type
)
18704 && ! decl_function_context (TYPE_STUB_DECL (type
)))
18705 VEC_safe_push (tree
, gc
, incomplete_types
, type
);
18708 if (get_AT (type_die
, DW_AT_name
))
18709 add_pubtype (type
, type_die
);
18712 /* Generate a DIE for a subroutine _type_. */
18715 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
18717 tree return_type
= TREE_TYPE (type
);
18718 dw_die_ref subr_die
18719 = new_die (DW_TAG_subroutine_type
,
18720 scope_die_for (type
, context_die
), type
);
18722 equate_type_number_to_die (type
, subr_die
);
18723 add_prototyped_attribute (subr_die
, type
);
18724 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
18725 gen_formal_types_die (type
, subr_die
);
18727 if (get_AT (subr_die
, DW_AT_name
))
18728 add_pubtype (type
, subr_die
);
18731 /* Generate a DIE for a type definition. */
18734 gen_typedef_die (tree decl
, dw_die_ref context_die
)
18736 dw_die_ref type_die
;
18739 if (TREE_ASM_WRITTEN (decl
))
18742 TREE_ASM_WRITTEN (decl
) = 1;
18743 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
18744 origin
= decl_ultimate_origin (decl
);
18745 if (origin
!= NULL
)
18746 add_abstract_origin_attribute (type_die
, origin
);
18751 add_name_and_src_coords_attributes (type_die
, decl
);
18752 if (DECL_ORIGINAL_TYPE (decl
))
18754 type
= DECL_ORIGINAL_TYPE (decl
);
18756 gcc_assert (type
!= TREE_TYPE (decl
));
18757 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
18761 type
= TREE_TYPE (decl
);
18763 if (is_naming_typedef_decl (TYPE_NAME (type
)))
18765 /* Here, we are in the case of decl being a typedef naming
18766 an anonymous type, e.g:
18767 typedef struct {...} foo;
18768 In that case TREE_TYPE (decl) is not a typedef variant
18769 type and TYPE_NAME of the anonymous type is set to the
18770 TYPE_DECL of the typedef. This construct is emitted by
18773 TYPE is the anonymous struct named by the typedef
18774 DECL. As we need the DW_AT_type attribute of the
18775 DW_TAG_typedef to point to the DIE of TYPE, let's
18776 generate that DIE right away. add_type_attribute
18777 called below will then pick (via lookup_type_die) that
18778 anonymous struct DIE. */
18779 if (!TREE_ASM_WRITTEN (type
))
18780 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
18782 /* This is a GNU Extension. We are adding a
18783 DW_AT_linkage_name attribute to the DIE of the
18784 anonymous struct TYPE. The value of that attribute
18785 is the name of the typedef decl naming the anonymous
18786 struct. This greatly eases the work of consumers of
18787 this debug info. */
18788 add_linkage_attr (lookup_type_die (type
), decl
);
18792 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
18793 TREE_THIS_VOLATILE (decl
), context_die
);
18795 if (is_naming_typedef_decl (decl
))
18796 /* We want that all subsequent calls to lookup_type_die with
18797 TYPE in argument yield the DW_TAG_typedef we have just
18799 equate_type_number_to_die (type
, type_die
);
18801 add_accessibility_attribute (type_die
, decl
);
18804 if (DECL_ABSTRACT (decl
))
18805 equate_decl_number_to_die (decl
, type_die
);
18807 if (get_AT (type_die
, DW_AT_name
))
18808 add_pubtype (decl
, type_die
);
18811 /* Generate a DIE for a struct, class, enum or union type. */
18814 gen_tagged_type_die (tree type
,
18815 dw_die_ref context_die
,
18816 enum debug_info_usage usage
)
18820 if (type
== NULL_TREE
18821 || !is_tagged_type (type
))
18824 /* If this is a nested type whose containing class hasn't been written
18825 out yet, writing it out will cover this one, too. This does not apply
18826 to instantiations of member class templates; they need to be added to
18827 the containing class as they are generated. FIXME: This hurts the
18828 idea of combining type decls from multiple TUs, since we can't predict
18829 what set of template instantiations we'll get. */
18830 if (TYPE_CONTEXT (type
)
18831 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
18832 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
18834 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
18836 if (TREE_ASM_WRITTEN (type
))
18839 /* If that failed, attach ourselves to the stub. */
18840 push_decl_scope (TYPE_CONTEXT (type
));
18841 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
18844 else if (TYPE_CONTEXT (type
) != NULL_TREE
18845 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
18847 /* If this type is local to a function that hasn't been written
18848 out yet, use a NULL context for now; it will be fixed up in
18849 decls_for_scope. */
18850 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
18851 /* A declaration DIE doesn't count; nested types need to go in the
18853 if (context_die
&& is_declaration_die (context_die
))
18854 context_die
= NULL
;
18859 context_die
= declare_in_namespace (type
, context_die
);
18863 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
18865 /* This might have been written out by the call to
18866 declare_in_namespace. */
18867 if (!TREE_ASM_WRITTEN (type
))
18868 gen_enumeration_type_die (type
, context_die
);
18871 gen_struct_or_union_type_die (type
, context_die
, usage
);
18876 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
18877 it up if it is ever completed. gen_*_type_die will set it for us
18878 when appropriate. */
18881 /* Generate a type description DIE. */
18884 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
18885 enum debug_info_usage usage
)
18887 struct array_descr_info info
;
18889 if (type
== NULL_TREE
|| type
== error_mark_node
)
18892 if (TYPE_NAME (type
) != NULL_TREE
18893 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
18894 && is_redundant_typedef (TYPE_NAME (type
))
18895 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
18896 /* The DECL of this type is a typedef we don't want to emit debug
18897 info for but we want debug info for its underlying typedef.
18898 This can happen for e.g, the injected-class-name of a C++
18900 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
18902 /* If TYPE is a typedef type variant, let's generate debug info
18903 for the parent typedef which TYPE is a type of. */
18904 if (typedef_variant_p (type
))
18906 if (TREE_ASM_WRITTEN (type
))
18909 /* Prevent broken recursion; we can't hand off to the same type. */
18910 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
18912 /* Use the DIE of the containing namespace as the parent DIE of
18913 the type description DIE we want to generate. */
18914 if (DECL_FILE_SCOPE_P (TYPE_NAME (type
))
18915 || (DECL_CONTEXT (TYPE_NAME (type
))
18916 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
))
18917 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
18919 TREE_ASM_WRITTEN (type
) = 1;
18921 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
18925 /* If type is an anonymous tagged type named by a typedef, let's
18926 generate debug info for the typedef. */
18927 if (is_naming_typedef_decl (TYPE_NAME (type
)))
18929 /* Use the DIE of the containing namespace as the parent DIE of
18930 the type description DIE we want to generate. */
18931 if (DECL_CONTEXT (TYPE_NAME (type
))
18932 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
18933 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
18935 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
18939 /* If this is an array type with hidden descriptor, handle it first. */
18940 if (!TREE_ASM_WRITTEN (type
)
18941 && lang_hooks
.types
.get_array_descr_info
18942 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
18943 && (dwarf_version
>= 3 || !dwarf_strict
))
18945 gen_descr_array_type_die (type
, &info
, context_die
);
18946 TREE_ASM_WRITTEN (type
) = 1;
18950 /* We are going to output a DIE to represent the unqualified version
18951 of this type (i.e. without any const or volatile qualifiers) so
18952 get the main variant (i.e. the unqualified version) of this type
18953 now. (Vectors are special because the debugging info is in the
18954 cloned type itself). */
18955 if (TREE_CODE (type
) != VECTOR_TYPE
)
18956 type
= type_main_variant (type
);
18958 if (TREE_ASM_WRITTEN (type
))
18961 switch (TREE_CODE (type
))
18967 case REFERENCE_TYPE
:
18968 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
18969 ensures that the gen_type_die recursion will terminate even if the
18970 type is recursive. Recursive types are possible in Ada. */
18971 /* ??? We could perhaps do this for all types before the switch
18973 TREE_ASM_WRITTEN (type
) = 1;
18975 /* For these types, all that is required is that we output a DIE (or a
18976 set of DIEs) to represent the "basis" type. */
18977 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18978 DINFO_USAGE_IND_USE
);
18982 /* This code is used for C++ pointer-to-data-member types.
18983 Output a description of the relevant class type. */
18984 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
18985 DINFO_USAGE_IND_USE
);
18987 /* Output a description of the type of the object pointed to. */
18988 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18989 DINFO_USAGE_IND_USE
);
18991 /* Now output a DIE to represent this pointer-to-data-member type
18993 gen_ptr_to_mbr_type_die (type
, context_die
);
18996 case FUNCTION_TYPE
:
18997 /* Force out return type (in case it wasn't forced out already). */
18998 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18999 DINFO_USAGE_DIR_USE
);
19000 gen_subroutine_type_die (type
, context_die
);
19004 /* Force out return type (in case it wasn't forced out already). */
19005 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19006 DINFO_USAGE_DIR_USE
);
19007 gen_subroutine_type_die (type
, context_die
);
19011 gen_array_type_die (type
, context_die
);
19015 gen_array_type_die (type
, context_die
);
19018 case ENUMERAL_TYPE
:
19021 case QUAL_UNION_TYPE
:
19022 gen_tagged_type_die (type
, context_die
, usage
);
19028 case FIXED_POINT_TYPE
:
19031 /* No DIEs needed for fundamental types. */
19036 /* Just use DW_TAG_unspecified_type. */
19038 dw_die_ref type_die
= lookup_type_die (type
);
19039 if (type_die
== NULL
)
19041 tree name
= TYPE_NAME (type
);
19042 if (TREE_CODE (name
) == TYPE_DECL
)
19043 name
= DECL_NAME (name
);
19044 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
19045 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
19046 equate_type_number_to_die (type
, type_die
);
19052 gcc_unreachable ();
19055 TREE_ASM_WRITTEN (type
) = 1;
19059 gen_type_die (tree type
, dw_die_ref context_die
)
19061 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
19064 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19065 things which are local to the given block. */
19068 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19070 int must_output_die
= 0;
19073 /* Ignore blocks that are NULL. */
19074 if (stmt
== NULL_TREE
)
19077 inlined_func
= inlined_function_outer_scope_p (stmt
);
19079 /* If the block is one fragment of a non-contiguous block, do not
19080 process the variables, since they will have been done by the
19081 origin block. Do process subblocks. */
19082 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
19086 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
19087 gen_block_die (sub
, context_die
, depth
+ 1);
19092 /* Determine if we need to output any Dwarf DIEs at all to represent this
19095 /* The outer scopes for inlinings *must* always be represented. We
19096 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19097 must_output_die
= 1;
19100 /* Determine if this block directly contains any "significant"
19101 local declarations which we will need to output DIEs for. */
19102 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19103 /* We are not in terse mode so *any* local declaration counts
19104 as being a "significant" one. */
19105 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
19106 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
19107 && (TREE_USED (stmt
)
19108 || TREE_ASM_WRITTEN (stmt
)
19109 || BLOCK_ABSTRACT (stmt
)));
19110 else if ((TREE_USED (stmt
)
19111 || TREE_ASM_WRITTEN (stmt
)
19112 || BLOCK_ABSTRACT (stmt
))
19113 && !dwarf2out_ignore_block (stmt
))
19114 must_output_die
= 1;
19117 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19118 DIE for any block which contains no significant local declarations at
19119 all. Rather, in such cases we just call `decls_for_scope' so that any
19120 needed Dwarf info for any sub-blocks will get properly generated. Note
19121 that in terse mode, our definition of what constitutes a "significant"
19122 local declaration gets restricted to include only inlined function
19123 instances and local (nested) function definitions. */
19124 if (must_output_die
)
19128 /* If STMT block is abstract, that means we have been called
19129 indirectly from dwarf2out_abstract_function.
19130 That function rightfully marks the descendent blocks (of
19131 the abstract function it is dealing with) as being abstract,
19132 precisely to prevent us from emitting any
19133 DW_TAG_inlined_subroutine DIE as a descendent
19134 of an abstract function instance. So in that case, we should
19135 not call gen_inlined_subroutine_die.
19137 Later though, when cgraph asks dwarf2out to emit info
19138 for the concrete instance of the function decl into which
19139 the concrete instance of STMT got inlined, the later will lead
19140 to the generation of a DW_TAG_inlined_subroutine DIE. */
19141 if (! BLOCK_ABSTRACT (stmt
))
19142 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
19145 gen_lexical_block_die (stmt
, context_die
, depth
);
19148 decls_for_scope (stmt
, context_die
, depth
);
19151 /* Process variable DECL (or variable with origin ORIGIN) within
19152 block STMT and add it to CONTEXT_DIE. */
19154 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
19157 tree decl_or_origin
= decl
? decl
: origin
;
19159 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
19160 die
= lookup_decl_die (decl_or_origin
);
19161 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
19162 && TYPE_DECL_IS_STUB (decl_or_origin
))
19163 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
19167 if (die
!= NULL
&& die
->die_parent
== NULL
)
19168 add_child_die (context_die
, die
);
19169 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
19170 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
19171 stmt
, context_die
);
19173 gen_decl_die (decl
, origin
, context_die
);
19176 /* Generate all of the decls declared within a given scope and (recursively)
19177 all of its sub-blocks. */
19180 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
19186 /* Ignore NULL blocks. */
19187 if (stmt
== NULL_TREE
)
19190 /* Output the DIEs to represent all of the data objects and typedefs
19191 declared directly within this block but not within any nested
19192 sub-blocks. Also, nested function and tag DIEs have been
19193 generated with a parent of NULL; fix that up now. */
19194 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
19195 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
19196 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
19197 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
19200 /* If we're at -g1, we're not interested in subblocks. */
19201 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19204 /* Output the DIEs to represent all sub-blocks (and the items declared
19205 therein) of this block. */
19206 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
19208 subblocks
= BLOCK_CHAIN (subblocks
))
19209 gen_block_die (subblocks
, context_die
, depth
+ 1);
19212 /* Is this a typedef we can avoid emitting? */
19215 is_redundant_typedef (const_tree decl
)
19217 if (TYPE_DECL_IS_STUB (decl
))
19220 if (DECL_ARTIFICIAL (decl
)
19221 && DECL_CONTEXT (decl
)
19222 && is_tagged_type (DECL_CONTEXT (decl
))
19223 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
19224 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
19225 /* Also ignore the artificial member typedef for the class name. */
19231 /* Return TRUE if TYPE is a typedef that names a type for linkage
19232 purposes. This kind of typedefs is produced by the C++ FE for
19235 typedef struct {...} foo;
19237 In that case, there is no typedef variant type produced for foo.
19238 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
19242 is_naming_typedef_decl (const_tree decl
)
19244 if (decl
== NULL_TREE
19245 || TREE_CODE (decl
) != TYPE_DECL
19246 || !is_tagged_type (TREE_TYPE (decl
))
19247 || DECL_IS_BUILTIN (decl
)
19248 || is_redundant_typedef (decl
)
19249 /* It looks like Ada produces TYPE_DECLs that are very similar
19250 to C++ naming typedefs but that have different
19251 semantics. Let's be specific to c++ for now. */
19255 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
19256 && TYPE_NAME (TREE_TYPE (decl
)) == decl
19257 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
19258 != TYPE_NAME (TREE_TYPE (decl
))));
19261 /* Returns the DIE for a context. */
19263 static inline dw_die_ref
19264 get_context_die (tree context
)
19268 /* Find die that represents this context. */
19269 if (TYPE_P (context
))
19271 context
= TYPE_MAIN_VARIANT (context
);
19272 return strip_naming_typedef (context
, force_type_die (context
));
19275 return force_decl_die (context
);
19277 return comp_unit_die ();
19280 /* Returns the DIE for decl. A DIE will always be returned. */
19283 force_decl_die (tree decl
)
19285 dw_die_ref decl_die
;
19286 unsigned saved_external_flag
;
19287 tree save_fn
= NULL_TREE
;
19288 decl_die
= lookup_decl_die (decl
);
19291 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
19293 decl_die
= lookup_decl_die (decl
);
19297 switch (TREE_CODE (decl
))
19299 case FUNCTION_DECL
:
19300 /* Clear current_function_decl, so that gen_subprogram_die thinks
19301 that this is a declaration. At this point, we just want to force
19302 declaration die. */
19303 save_fn
= current_function_decl
;
19304 current_function_decl
= NULL_TREE
;
19305 gen_subprogram_die (decl
, context_die
);
19306 current_function_decl
= save_fn
;
19310 /* Set external flag to force declaration die. Restore it after
19311 gen_decl_die() call. */
19312 saved_external_flag
= DECL_EXTERNAL (decl
);
19313 DECL_EXTERNAL (decl
) = 1;
19314 gen_decl_die (decl
, NULL
, context_die
);
19315 DECL_EXTERNAL (decl
) = saved_external_flag
;
19318 case NAMESPACE_DECL
:
19319 if (dwarf_version
>= 3 || !dwarf_strict
)
19320 dwarf2out_decl (decl
);
19322 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19323 decl_die
= comp_unit_die ();
19326 case TRANSLATION_UNIT_DECL
:
19327 decl_die
= comp_unit_die ();
19331 gcc_unreachable ();
19334 /* We should be able to find the DIE now. */
19336 decl_die
= lookup_decl_die (decl
);
19337 gcc_assert (decl_die
);
19343 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
19344 always returned. */
19347 force_type_die (tree type
)
19349 dw_die_ref type_die
;
19351 type_die
= lookup_type_die (type
);
19354 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
19356 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
19357 TYPE_VOLATILE (type
), context_die
);
19358 gcc_assert (type_die
);
19363 /* Force out any required namespaces to be able to output DECL,
19364 and return the new context_die for it, if it's changed. */
19367 setup_namespace_context (tree thing
, dw_die_ref context_die
)
19369 tree context
= (DECL_P (thing
)
19370 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
19371 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
19372 /* Force out the namespace. */
19373 context_die
= force_decl_die (context
);
19375 return context_die
;
19378 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
19379 type) within its namespace, if appropriate.
19381 For compatibility with older debuggers, namespace DIEs only contain
19382 declarations; all definitions are emitted at CU scope. */
19385 declare_in_namespace (tree thing
, dw_die_ref context_die
)
19387 dw_die_ref ns_context
;
19389 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19390 return context_die
;
19392 /* If this decl is from an inlined function, then don't try to emit it in its
19393 namespace, as we will get confused. It would have already been emitted
19394 when the abstract instance of the inline function was emitted anyways. */
19395 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
19396 return context_die
;
19398 ns_context
= setup_namespace_context (thing
, context_die
);
19400 if (ns_context
!= context_die
)
19404 if (DECL_P (thing
))
19405 gen_decl_die (thing
, NULL
, ns_context
);
19407 gen_type_die (thing
, ns_context
);
19409 return context_die
;
19412 /* Generate a DIE for a namespace or namespace alias. */
19415 gen_namespace_die (tree decl
, dw_die_ref context_die
)
19417 dw_die_ref namespace_die
;
19419 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
19420 they are an alias of. */
19421 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
19423 /* Output a real namespace or module. */
19424 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19425 namespace_die
= new_die (is_fortran ()
19426 ? DW_TAG_module
: DW_TAG_namespace
,
19427 context_die
, decl
);
19428 /* For Fortran modules defined in different CU don't add src coords. */
19429 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
19431 const char *name
= dwarf2_name (decl
, 0);
19433 add_name_attribute (namespace_die
, name
);
19436 add_name_and_src_coords_attributes (namespace_die
, decl
);
19437 if (DECL_EXTERNAL (decl
))
19438 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
19439 equate_decl_number_to_die (decl
, namespace_die
);
19443 /* Output a namespace alias. */
19445 /* Force out the namespace we are an alias of, if necessary. */
19446 dw_die_ref origin_die
19447 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
19449 if (DECL_FILE_SCOPE_P (decl
)
19450 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
19451 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19452 /* Now create the namespace alias DIE. */
19453 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
19454 add_name_and_src_coords_attributes (namespace_die
, decl
);
19455 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
19456 equate_decl_number_to_die (decl
, namespace_die
);
19460 /* Generate Dwarf debug information for a decl described by DECL.
19461 The return value is currently only meaningful for PARM_DECLs,
19462 for all other decls it returns NULL. */
19465 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
19467 tree decl_or_origin
= decl
? decl
: origin
;
19468 tree class_origin
= NULL
, ultimate_origin
;
19470 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
19473 switch (TREE_CODE (decl_or_origin
))
19479 if (!is_fortran () && !is_ada ())
19481 /* The individual enumerators of an enum type get output when we output
19482 the Dwarf representation of the relevant enum type itself. */
19486 /* Emit its type. */
19487 gen_type_die (TREE_TYPE (decl
), context_die
);
19489 /* And its containing namespace. */
19490 context_die
= declare_in_namespace (decl
, context_die
);
19492 gen_const_die (decl
, context_die
);
19495 case FUNCTION_DECL
:
19496 /* Don't output any DIEs to represent mere function declarations,
19497 unless they are class members or explicit block externs. */
19498 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
19499 && DECL_FILE_SCOPE_P (decl_or_origin
)
19500 && (current_function_decl
== NULL_TREE
19501 || DECL_ARTIFICIAL (decl_or_origin
)))
19506 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
19507 on local redeclarations of global functions. That seems broken. */
19508 if (current_function_decl
!= decl
)
19509 /* This is only a declaration. */;
19512 /* If we're emitting a clone, emit info for the abstract instance. */
19513 if (origin
|| DECL_ORIGIN (decl
) != decl
)
19514 dwarf2out_abstract_function (origin
19515 ? DECL_ORIGIN (origin
)
19516 : DECL_ABSTRACT_ORIGIN (decl
));
19518 /* If we're emitting an out-of-line copy of an inline function,
19519 emit info for the abstract instance and set up to refer to it. */
19520 else if (cgraph_function_possibly_inlined_p (decl
)
19521 && ! DECL_ABSTRACT (decl
)
19522 && ! class_or_namespace_scope_p (context_die
)
19523 /* dwarf2out_abstract_function won't emit a die if this is just
19524 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
19525 that case, because that works only if we have a die. */
19526 && DECL_INITIAL (decl
) != NULL_TREE
)
19528 dwarf2out_abstract_function (decl
);
19529 set_decl_origin_self (decl
);
19532 /* Otherwise we're emitting the primary DIE for this decl. */
19533 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
19535 /* Before we describe the FUNCTION_DECL itself, make sure that we
19536 have its containing type. */
19538 origin
= decl_class_context (decl
);
19539 if (origin
!= NULL_TREE
)
19540 gen_type_die (origin
, context_die
);
19542 /* And its return type. */
19543 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
19545 /* And its virtual context. */
19546 if (DECL_VINDEX (decl
) != NULL_TREE
)
19547 gen_type_die (DECL_CONTEXT (decl
), context_die
);
19549 /* Make sure we have a member DIE for decl. */
19550 if (origin
!= NULL_TREE
)
19551 gen_type_die_for_member (origin
, decl
, context_die
);
19553 /* And its containing namespace. */
19554 context_die
= declare_in_namespace (decl
, context_die
);
19557 /* Now output a DIE to represent the function itself. */
19559 gen_subprogram_die (decl
, context_die
);
19563 /* If we are in terse mode, don't generate any DIEs to represent any
19564 actual typedefs. */
19565 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19568 /* In the special case of a TYPE_DECL node representing the declaration
19569 of some type tag, if the given TYPE_DECL is marked as having been
19570 instantiated from some other (original) TYPE_DECL node (e.g. one which
19571 was generated within the original definition of an inline function) we
19572 used to generate a special (abbreviated) DW_TAG_structure_type,
19573 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
19574 should be actually referencing those DIEs, as variable DIEs with that
19575 type would be emitted already in the abstract origin, so it was always
19576 removed during unused type prunning. Don't add anything in this
19578 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
19581 if (is_redundant_typedef (decl
))
19582 gen_type_die (TREE_TYPE (decl
), context_die
);
19584 /* Output a DIE to represent the typedef itself. */
19585 gen_typedef_die (decl
, context_die
);
19589 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
19590 gen_label_die (decl
, context_die
);
19595 /* If we are in terse mode, don't generate any DIEs to represent any
19596 variable declarations or definitions. */
19597 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19600 /* Output any DIEs that are needed to specify the type of this data
19602 if (decl_by_reference_p (decl_or_origin
))
19603 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
19605 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
19607 /* And its containing type. */
19608 class_origin
= decl_class_context (decl_or_origin
);
19609 if (class_origin
!= NULL_TREE
)
19610 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
19612 /* And its containing namespace. */
19613 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
19615 /* Now output the DIE to represent the data object itself. This gets
19616 complicated because of the possibility that the VAR_DECL really
19617 represents an inlined instance of a formal parameter for an inline
19619 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
19620 if (ultimate_origin
!= NULL_TREE
19621 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
19622 gen_formal_parameter_die (decl
, origin
,
19623 true /* Emit name attribute. */,
19626 gen_variable_die (decl
, origin
, context_die
);
19630 /* Ignore the nameless fields that are used to skip bits but handle C++
19631 anonymous unions and structs. */
19632 if (DECL_NAME (decl
) != NULL_TREE
19633 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
19634 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
19636 gen_type_die (member_declared_type (decl
), context_die
);
19637 gen_field_die (decl
, context_die
);
19642 if (DECL_BY_REFERENCE (decl_or_origin
))
19643 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
19645 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
19646 return gen_formal_parameter_die (decl
, origin
,
19647 true /* Emit name attribute. */,
19650 case NAMESPACE_DECL
:
19651 case IMPORTED_DECL
:
19652 if (dwarf_version
>= 3 || !dwarf_strict
)
19653 gen_namespace_die (decl
, context_die
);
19657 /* Probably some frontend-internal decl. Assume we don't care. */
19658 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
19665 /* Output debug information for global decl DECL. Called from toplev.c after
19666 compilation proper has finished. */
19669 dwarf2out_global_decl (tree decl
)
19671 /* Output DWARF2 information for file-scope tentative data object
19672 declarations, file-scope (extern) function declarations (which
19673 had no corresponding body) and file-scope tagged type declarations
19674 and definitions which have not yet been forced out. */
19675 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
19676 dwarf2out_decl (decl
);
19679 /* Output debug information for type decl DECL. Called from toplev.c
19680 and from language front ends (to record built-in types). */
19682 dwarf2out_type_decl (tree decl
, int local
)
19685 dwarf2out_decl (decl
);
19688 /* Output debug information for imported module or decl DECL.
19689 NAME is non-NULL name in the lexical block if the decl has been renamed.
19690 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
19691 that DECL belongs to.
19692 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
19694 dwarf2out_imported_module_or_decl_1 (tree decl
,
19696 tree lexical_block
,
19697 dw_die_ref lexical_block_die
)
19699 expanded_location xloc
;
19700 dw_die_ref imported_die
= NULL
;
19701 dw_die_ref at_import_die
;
19703 if (TREE_CODE (decl
) == IMPORTED_DECL
)
19705 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
19706 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
19710 xloc
= expand_location (input_location
);
19712 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
19714 at_import_die
= force_type_die (TREE_TYPE (decl
));
19715 /* For namespace N { typedef void T; } using N::T; base_type_die
19716 returns NULL, but DW_TAG_imported_declaration requires
19717 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
19718 if (!at_import_die
)
19720 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
19721 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
19722 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
19723 gcc_assert (at_import_die
);
19728 at_import_die
= lookup_decl_die (decl
);
19729 if (!at_import_die
)
19731 /* If we're trying to avoid duplicate debug info, we may not have
19732 emitted the member decl for this field. Emit it now. */
19733 if (TREE_CODE (decl
) == FIELD_DECL
)
19735 tree type
= DECL_CONTEXT (decl
);
19737 if (TYPE_CONTEXT (type
)
19738 && TYPE_P (TYPE_CONTEXT (type
))
19739 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
19740 DINFO_USAGE_DIR_USE
))
19742 gen_type_die_for_member (type
, decl
,
19743 get_context_die (TYPE_CONTEXT (type
)));
19745 at_import_die
= force_decl_die (decl
);
19749 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
19751 if (dwarf_version
>= 3 || !dwarf_strict
)
19752 imported_die
= new_die (DW_TAG_imported_module
,
19759 imported_die
= new_die (DW_TAG_imported_declaration
,
19763 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
19764 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
19766 add_AT_string (imported_die
, DW_AT_name
,
19767 IDENTIFIER_POINTER (name
));
19768 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
19771 /* Output debug information for imported module or decl DECL.
19772 NAME is non-NULL name in context if the decl has been renamed.
19773 CHILD is true if decl is one of the renamed decls as part of
19774 importing whole module. */
19777 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
19780 /* dw_die_ref at_import_die; */
19781 dw_die_ref scope_die
;
19783 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19788 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
19789 We need decl DIE for reference and scope die. First, get DIE for the decl
19792 /* Get the scope die for decl context. Use comp_unit_die for global module
19793 or decl. If die is not found for non globals, force new die. */
19795 && TYPE_P (context
)
19796 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
19799 if (!(dwarf_version
>= 3 || !dwarf_strict
))
19802 scope_die
= get_context_die (context
);
19806 gcc_assert (scope_die
->die_child
);
19807 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
19808 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
19809 scope_die
= scope_die
->die_child
;
19812 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
19813 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
19817 /* Write the debugging output for DECL. */
19820 dwarf2out_decl (tree decl
)
19822 dw_die_ref context_die
= comp_unit_die ();
19824 switch (TREE_CODE (decl
))
19829 case FUNCTION_DECL
:
19830 /* What we would really like to do here is to filter out all mere
19831 file-scope declarations of file-scope functions which are never
19832 referenced later within this translation unit (and keep all of ones
19833 that *are* referenced later on) but we aren't clairvoyant, so we have
19834 no idea which functions will be referenced in the future (i.e. later
19835 on within the current translation unit). So here we just ignore all
19836 file-scope function declarations which are not also definitions. If
19837 and when the debugger needs to know something about these functions,
19838 it will have to hunt around and find the DWARF information associated
19839 with the definition of the function.
19841 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
19842 nodes represent definitions and which ones represent mere
19843 declarations. We have to check DECL_INITIAL instead. That's because
19844 the C front-end supports some weird semantics for "extern inline"
19845 function definitions. These can get inlined within the current
19846 translation unit (and thus, we need to generate Dwarf info for their
19847 abstract instances so that the Dwarf info for the concrete inlined
19848 instances can have something to refer to) but the compiler never
19849 generates any out-of-lines instances of such things (despite the fact
19850 that they *are* definitions).
19852 The important point is that the C front-end marks these "extern
19853 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
19854 them anyway. Note that the C++ front-end also plays some similar games
19855 for inline function definitions appearing within include files which
19856 also contain `#pragma interface' pragmas. */
19857 if (DECL_INITIAL (decl
) == NULL_TREE
)
19860 /* If we're a nested function, initially use a parent of NULL; if we're
19861 a plain function, this will be fixed up in decls_for_scope. If
19862 we're a method, it will be ignored, since we already have a DIE. */
19863 if (decl_function_context (decl
)
19864 /* But if we're in terse mode, we don't care about scope. */
19865 && debug_info_level
> DINFO_LEVEL_TERSE
)
19866 context_die
= NULL
;
19870 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
19871 declaration and if the declaration was never even referenced from
19872 within this entire compilation unit. We suppress these DIEs in
19873 order to save space in the .debug section (by eliminating entries
19874 which are probably useless). Note that we must not suppress
19875 block-local extern declarations (whether used or not) because that
19876 would screw-up the debugger's name lookup mechanism and cause it to
19877 miss things which really ought to be in scope at a given point. */
19878 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
19881 /* For local statics lookup proper context die. */
19882 if (TREE_STATIC (decl
) && decl_function_context (decl
))
19883 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
19885 /* If we are in terse mode, don't generate any DIEs to represent any
19886 variable declarations or definitions. */
19887 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19892 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19894 if (!is_fortran () && !is_ada ())
19896 if (TREE_STATIC (decl
) && decl_function_context (decl
))
19897 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
19900 case NAMESPACE_DECL
:
19901 case IMPORTED_DECL
:
19902 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19904 if (lookup_decl_die (decl
) != NULL
)
19909 /* Don't emit stubs for types unless they are needed by other DIEs. */
19910 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
19913 /* Don't bother trying to generate any DIEs to represent any of the
19914 normal built-in types for the language we are compiling. */
19915 if (DECL_IS_BUILTIN (decl
))
19918 /* If we are in terse mode, don't generate any DIEs for types. */
19919 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19922 /* If we're a function-scope tag, initially use a parent of NULL;
19923 this will be fixed up in decls_for_scope. */
19924 if (decl_function_context (decl
))
19925 context_die
= NULL
;
19933 gen_decl_die (decl
, NULL
, context_die
);
19936 /* Write the debugging output for DECL. */
19939 dwarf2out_function_decl (tree decl
)
19941 dwarf2out_decl (decl
);
19942 call_arg_locations
= NULL
;
19943 call_arg_loc_last
= NULL
;
19944 call_site_count
= -1;
19945 tail_call_site_count
= -1;
19946 VEC_free (dw_die_ref
, heap
, block_map
);
19947 htab_empty (decl_loc_table
);
19948 htab_empty (cached_dw_loc_list_table
);
19951 /* Output a marker (i.e. a label) for the beginning of the generated code for
19952 a lexical block. */
19955 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
19956 unsigned int blocknum
)
19958 switch_to_section (current_function_section ());
19959 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
19962 /* Output a marker (i.e. a label) for the end of the generated code for a
19966 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
19968 switch_to_section (current_function_section ());
19969 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
19972 /* Returns nonzero if it is appropriate not to emit any debugging
19973 information for BLOCK, because it doesn't contain any instructions.
19975 Don't allow this for blocks with nested functions or local classes
19976 as we would end up with orphans, and in the presence of scheduling
19977 we may end up calling them anyway. */
19980 dwarf2out_ignore_block (const_tree block
)
19985 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
19986 if (TREE_CODE (decl
) == FUNCTION_DECL
19987 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
19989 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
19991 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
19992 if (TREE_CODE (decl
) == FUNCTION_DECL
19993 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20000 /* Hash table routines for file_hash. */
20003 file_table_eq (const void *p1_p
, const void *p2_p
)
20005 const struct dwarf_file_data
*const p1
=
20006 (const struct dwarf_file_data
*) p1_p
;
20007 const char *const p2
= (const char *) p2_p
;
20008 return filename_cmp (p1
->filename
, p2
) == 0;
20012 file_table_hash (const void *p_p
)
20014 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
20015 return htab_hash_string (p
->filename
);
20018 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20019 dwarf2out.c) and return its "index". The index of each (known) filename is
20020 just a unique number which is associated with only that one filename. We
20021 need such numbers for the sake of generating labels (in the .debug_sfnames
20022 section) and references to those files numbers (in the .debug_srcinfo
20023 and.debug_macinfo sections). If the filename given as an argument is not
20024 found in our current list, add it to the list and assign it the next
20025 available unique index number. In order to speed up searches, we remember
20026 the index of the filename was looked up last. This handles the majority of
20029 static struct dwarf_file_data
*
20030 lookup_filename (const char *file_name
)
20033 struct dwarf_file_data
* created
;
20035 /* Check to see if the file name that was searched on the previous
20036 call matches this file name. If so, return the index. */
20037 if (file_table_last_lookup
20038 && (file_name
== file_table_last_lookup
->filename
20039 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
20040 return file_table_last_lookup
;
20042 /* Didn't match the previous lookup, search the table. */
20043 slot
= htab_find_slot_with_hash (file_table
, file_name
,
20044 htab_hash_string (file_name
), INSERT
);
20046 return (struct dwarf_file_data
*) *slot
;
20048 created
= ggc_alloc_dwarf_file_data ();
20049 created
->filename
= file_name
;
20050 created
->emitted_number
= 0;
20055 /* If the assembler will construct the file table, then translate the compiler
20056 internal file table number into the assembler file table number, and emit
20057 a .file directive if we haven't already emitted one yet. The file table
20058 numbers are different because we prune debug info for unused variables and
20059 types, which may include filenames. */
20062 maybe_emit_file (struct dwarf_file_data
* fd
)
20064 if (! fd
->emitted_number
)
20066 if (last_emitted_file
)
20067 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
20069 fd
->emitted_number
= 1;
20070 last_emitted_file
= fd
;
20072 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20074 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
20075 output_quoted_string (asm_out_file
,
20076 remap_debug_filename (fd
->filename
));
20077 fputc ('\n', asm_out_file
);
20081 return fd
->emitted_number
;
20084 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20085 That generation should happen after function debug info has been
20086 generated. The value of the attribute is the constant value of ARG. */
20089 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
20091 die_arg_entry entry
;
20096 if (!tmpl_value_parm_die_table
)
20097 tmpl_value_parm_die_table
20098 = VEC_alloc (die_arg_entry
, gc
, 32);
20102 VEC_safe_push (die_arg_entry
, gc
,
20103 tmpl_value_parm_die_table
,
20107 /* Return TRUE if T is an instance of generic type, FALSE
20111 generic_type_p (tree t
)
20113 if (t
== NULL_TREE
|| !TYPE_P (t
))
20115 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
20118 /* Schedule the generation of the generic parameter dies for the
20119 instance of generic type T. The proper generation itself is later
20120 done by gen_scheduled_generic_parms_dies. */
20123 schedule_generic_params_dies_gen (tree t
)
20125 if (!generic_type_p (t
))
20128 if (generic_type_instances
== NULL
)
20129 generic_type_instances
= VEC_alloc (tree
, gc
, 256);
20131 VEC_safe_push (tree
, gc
, generic_type_instances
, t
);
20134 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20135 by append_entry_to_tmpl_value_parm_die_table. This function must
20136 be called after function DIEs have been generated. */
20139 gen_remaining_tmpl_value_param_die_attribute (void)
20141 if (tmpl_value_parm_die_table
)
20146 FOR_EACH_VEC_ELT (die_arg_entry
, tmpl_value_parm_die_table
, i
, e
)
20147 tree_add_const_value_attribute (e
->die
, e
->arg
);
20151 /* Generate generic parameters DIEs for instances of generic types
20152 that have been previously scheduled by
20153 schedule_generic_params_dies_gen. This function must be called
20154 after all the types of the CU have been laid out. */
20157 gen_scheduled_generic_parms_dies (void)
20162 if (generic_type_instances
== NULL
)
20165 FOR_EACH_VEC_ELT (tree
, generic_type_instances
, i
, t
)
20166 gen_generic_params_dies (t
);
20170 /* Replace DW_AT_name for the decl with name. */
20173 dwarf2out_set_name (tree decl
, tree name
)
20179 die
= TYPE_SYMTAB_DIE (decl
);
20183 dname
= dwarf2_name (name
, 0);
20187 attr
= get_AT (die
, DW_AT_name
);
20190 struct indirect_string_node
*node
;
20192 node
= find_AT_string (dname
);
20193 /* replace the string. */
20194 attr
->dw_attr_val
.v
.val_str
= node
;
20198 add_name_attribute (die
, dname
);
20201 /* Called by the final INSN scan whenever we see a var location. We
20202 use it to drop labels in the right places, and throw the location in
20203 our lookup table. */
20206 dwarf2out_var_location (rtx loc_note
)
20208 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
20209 struct var_loc_node
*newloc
;
20210 rtx next_real
, next_note
;
20211 static const char *last_label
;
20212 static const char *last_postcall_label
;
20213 static bool last_in_cold_section_p
;
20214 static rtx expected_next_loc_note
;
20218 if (!NOTE_P (loc_note
))
20220 if (CALL_P (loc_note
))
20223 if (SIBLING_CALL_P (loc_note
))
20224 tail_call_site_count
++;
20229 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
20230 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
20233 /* Optimize processing a large consecutive sequence of location
20234 notes so we don't spend too much time in next_real_insn. If the
20235 next insn is another location note, remember the next_real_insn
20236 calculation for next time. */
20237 next_real
= cached_next_real_insn
;
20240 if (expected_next_loc_note
!= loc_note
)
20241 next_real
= NULL_RTX
;
20244 next_note
= NEXT_INSN (loc_note
);
20246 || INSN_DELETED_P (next_note
)
20247 || GET_CODE (next_note
) != NOTE
20248 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
20249 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
20250 next_note
= NULL_RTX
;
20253 next_real
= next_real_insn (loc_note
);
20257 expected_next_loc_note
= next_note
;
20258 cached_next_real_insn
= next_real
;
20261 cached_next_real_insn
= NULL_RTX
;
20263 /* If there are no instructions which would be affected by this note,
20264 don't do anything. */
20266 && next_real
== NULL_RTX
20267 && !NOTE_DURING_CALL_P (loc_note
))
20270 if (next_real
== NULL_RTX
)
20271 next_real
= get_last_insn ();
20273 /* If there were any real insns between note we processed last time
20274 and this note (or if it is the first note), clear
20275 last_{,postcall_}label so that they are not reused this time. */
20276 if (last_var_location_insn
== NULL_RTX
20277 || last_var_location_insn
!= next_real
20278 || last_in_cold_section_p
!= in_cold_section_p
)
20281 last_postcall_label
= NULL
;
20286 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
20287 newloc
= add_var_loc_to_decl (decl
, loc_note
,
20288 NOTE_DURING_CALL_P (loc_note
)
20289 ? last_postcall_label
: last_label
);
20290 if (newloc
== NULL
)
20299 /* If there were no real insns between note we processed last time
20300 and this note, use the label we emitted last time. Otherwise
20301 create a new label and emit it. */
20302 if (last_label
== NULL
)
20304 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
20305 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
20307 last_label
= ggc_strdup (loclabel
);
20312 struct call_arg_loc_node
*ca_loc
20313 = ggc_alloc_cleared_call_arg_loc_node ();
20314 rtx prev
= prev_real_insn (loc_note
), x
;
20315 ca_loc
->call_arg_loc_note
= loc_note
;
20316 ca_loc
->next
= NULL
;
20317 ca_loc
->label
= last_label
;
20320 || (NONJUMP_INSN_P (prev
)
20321 && GET_CODE (PATTERN (prev
)) == SEQUENCE
20322 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
20323 if (!CALL_P (prev
))
20324 prev
= XVECEXP (PATTERN (prev
), 0, 0);
20325 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
20326 x
= PATTERN (prev
);
20327 if (GET_CODE (x
) == PARALLEL
)
20328 x
= XVECEXP (x
, 0, 0);
20329 if (GET_CODE (x
) == SET
)
20331 if (GET_CODE (x
) == CALL
&& MEM_P (XEXP (x
, 0)))
20333 x
= XEXP (XEXP (x
, 0), 0);
20334 if (GET_CODE (x
) == SYMBOL_REF
20335 && SYMBOL_REF_DECL (x
)
20336 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
20337 ca_loc
->symbol_ref
= x
;
20339 ca_loc
->block
= insn_scope (prev
);
20340 if (call_arg_locations
)
20341 call_arg_loc_last
->next
= ca_loc
;
20343 call_arg_locations
= ca_loc
;
20344 call_arg_loc_last
= ca_loc
;
20346 else if (!NOTE_DURING_CALL_P (loc_note
))
20347 newloc
->label
= last_label
;
20350 if (!last_postcall_label
)
20352 sprintf (loclabel
, "%s-1", last_label
);
20353 last_postcall_label
= ggc_strdup (loclabel
);
20355 newloc
->label
= last_postcall_label
;
20358 last_var_location_insn
= next_real
;
20359 last_in_cold_section_p
= in_cold_section_p
;
20362 /* Note in one location list that text section has changed. */
20365 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
20367 var_loc_list
*list
= (var_loc_list
*) *slot
;
20369 list
->last_before_switch
20370 = list
->last
->next
? list
->last
->next
: list
->last
;
20374 /* Note in all location lists that text section has changed. */
20377 var_location_switch_text_section (void)
20379 if (decl_loc_table
== NULL
)
20382 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
20385 /* Create a new line number table. */
20387 static dw_line_info_table
*
20388 new_line_info_table (void)
20390 dw_line_info_table
*table
;
20392 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
20393 table
->file_num
= 1;
20394 table
->line_num
= 1;
20395 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
20400 /* Lookup the "current" table into which we emit line info, so
20401 that we don't have to do it for every source line. */
20404 set_cur_line_info_table (section
*sec
)
20406 dw_line_info_table
*table
;
20408 if (sec
== text_section
)
20409 table
= text_section_line_info
;
20410 else if (sec
== cold_text_section
)
20412 table
= cold_text_section_line_info
;
20415 cold_text_section_line_info
= table
= new_line_info_table ();
20416 table
->end_label
= cold_end_label
;
20421 const char *end_label
;
20423 if (flag_reorder_blocks_and_partition
)
20425 if (in_cold_section_p
)
20426 end_label
= crtl
->subsections
.cold_section_end_label
;
20428 end_label
= crtl
->subsections
.hot_section_end_label
;
20432 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20433 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
20434 current_function_funcdef_no
);
20435 end_label
= ggc_strdup (label
);
20438 table
= new_line_info_table ();
20439 table
->end_label
= end_label
;
20441 VEC_safe_push (dw_line_info_table_p
, gc
, separate_line_info
, table
);
20444 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20445 table
->is_stmt
= (cur_line_info_table
20446 ? cur_line_info_table
->is_stmt
20447 : DWARF_LINE_DEFAULT_IS_STMT_START
);
20448 cur_line_info_table
= table
;
20452 /* We need to reset the locations at the beginning of each
20453 function. We can't do this in the end_function hook, because the
20454 declarations that use the locations won't have been output when
20455 that hook is called. Also compute have_multiple_function_sections here. */
20458 dwarf2out_begin_function (tree fun
)
20460 section
*sec
= function_section (fun
);
20462 if (sec
!= text_section
)
20463 have_multiple_function_sections
= true;
20465 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
20467 gcc_assert (current_function_decl
== fun
);
20468 cold_text_section
= unlikely_text_section ();
20469 switch_to_section (cold_text_section
);
20470 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
20471 switch_to_section (sec
);
20474 dwarf2out_note_section_used ();
20475 call_site_count
= 0;
20476 tail_call_site_count
= 0;
20478 set_cur_line_info_table (sec
);
20481 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
20484 push_dw_line_info_entry (dw_line_info_table
*table
,
20485 enum dw_line_info_opcode opcode
, unsigned int val
)
20487 dw_line_info_entry e
;
20490 VEC_safe_push (dw_line_info_entry
, gc
, table
->entries
, &e
);
20493 /* Output a label to mark the beginning of a source code line entry
20494 and record information relating to this source line, in
20495 'line_info_table' for later output of the .debug_line section. */
20496 /* ??? The discriminator parameter ought to be unsigned. */
20499 dwarf2out_source_line (unsigned int line
, const char *filename
,
20500 int discriminator
, bool is_stmt
)
20502 unsigned int file_num
;
20503 dw_line_info_table
*table
;
20505 if (debug_info_level
< DINFO_LEVEL_NORMAL
|| line
== 0)
20508 /* The discriminator column was added in dwarf4. Simplify the below
20509 by simply removing it if we're not supposed to output it. */
20510 if (dwarf_version
< 4 && dwarf_strict
)
20513 table
= cur_line_info_table
;
20514 file_num
= maybe_emit_file (lookup_filename (filename
));
20516 /* ??? TODO: Elide duplicate line number entries. Traditionally,
20517 the debugger has used the second (possibly duplicate) line number
20518 at the beginning of the function to mark the end of the prologue.
20519 We could eliminate any other duplicates within the function. For
20520 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
20521 that second line number entry. */
20522 /* Recall that this end-of-prologue indication is *not* the same thing
20523 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
20524 to which the hook corresponds, follows the last insn that was
20525 emitted by gen_prologue. What we need is to preceed the first insn
20526 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
20527 insn that corresponds to something the user wrote. These may be
20528 very different locations once scheduling is enabled. */
20530 if (0 && file_num
== table
->file_num
20531 && line
== table
->line_num
20532 && discriminator
== table
->discrim_num
20533 && is_stmt
== table
->is_stmt
)
20536 switch_to_section (current_function_section ());
20538 /* If requested, emit something human-readable. */
20539 if (flag_debug_asm
)
20540 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
20542 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20544 /* Emit the .loc directive understood by GNU as. */
20545 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
20546 file_num, line, is_stmt, discriminator */
20547 fputs ("\t.loc ", asm_out_file
);
20548 fprint_ul (asm_out_file
, file_num
);
20549 putc (' ', asm_out_file
);
20550 fprint_ul (asm_out_file
, line
);
20551 putc (' ', asm_out_file
);
20552 putc ('0', asm_out_file
);
20554 if (is_stmt
!= table
->is_stmt
)
20556 fputs (" is_stmt ", asm_out_file
);
20557 putc (is_stmt
? '1' : '0', asm_out_file
);
20559 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
20561 gcc_assert (discriminator
> 0);
20562 fputs (" discriminator ", asm_out_file
);
20563 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
20565 putc ('\n', asm_out_file
);
20569 unsigned int label_num
= ++line_info_label_num
;
20571 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
20573 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
20574 if (file_num
!= table
->file_num
)
20575 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
20576 if (discriminator
!= table
->discrim_num
)
20577 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
20578 if (is_stmt
!= table
->is_stmt
)
20579 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
20580 push_dw_line_info_entry (table
, LI_set_line
, line
);
20583 table
->file_num
= file_num
;
20584 table
->line_num
= line
;
20585 table
->discrim_num
= discriminator
;
20586 table
->is_stmt
= is_stmt
;
20587 table
->in_use
= true;
20590 /* Record the beginning of a new source file. */
20593 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
20595 if (flag_eliminate_dwarf2_dups
&& ! use_debug_types
)
20597 /* Record the beginning of the file for break_out_includes. */
20598 dw_die_ref bincl_die
;
20600 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
20601 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
20604 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20607 e
.code
= DW_MACINFO_start_file
;
20609 e
.info
= ggc_strdup (filename
);
20610 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20614 /* Record the end of a source file. */
20617 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
20619 if (flag_eliminate_dwarf2_dups
&& ! use_debug_types
)
20620 /* Record the end of the file for break_out_includes. */
20621 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
20623 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20626 e
.code
= DW_MACINFO_end_file
;
20629 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20633 /* Called from debug_define in toplev.c. The `buffer' parameter contains
20634 the tail part of the directive line, i.e. the part which is past the
20635 initial whitespace, #, whitespace, directive-name, whitespace part. */
20638 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
20639 const char *buffer ATTRIBUTE_UNUSED
)
20641 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20644 /* Insert a dummy first entry to be able to optimize the whole
20645 predefined macro block using DW_MACRO_GNU_transparent_include. */
20646 if (VEC_empty (macinfo_entry
, macinfo_table
) && lineno
== 0)
20651 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20653 e
.code
= DW_MACINFO_define
;
20655 e
.info
= ggc_strdup (buffer
);
20656 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20660 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
20661 the tail part of the directive line, i.e. the part which is past the
20662 initial whitespace, #, whitespace, directive-name, whitespace part. */
20665 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
20666 const char *buffer ATTRIBUTE_UNUSED
)
20668 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20671 /* Insert a dummy first entry to be able to optimize the whole
20672 predefined macro block using DW_MACRO_GNU_transparent_include. */
20673 if (VEC_empty (macinfo_entry
, macinfo_table
) && lineno
== 0)
20678 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20680 e
.code
= DW_MACINFO_undef
;
20682 e
.info
= ggc_strdup (buffer
);
20683 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20687 /* Routines to manipulate hash table of CUs. */
20690 htab_macinfo_hash (const void *of
)
20692 const macinfo_entry
*const entry
=
20693 (const macinfo_entry
*) of
;
20695 return htab_hash_string (entry
->info
);
20699 htab_macinfo_eq (const void *of1
, const void *of2
)
20701 const macinfo_entry
*const entry1
= (const macinfo_entry
*) of1
;
20702 const macinfo_entry
*const entry2
= (const macinfo_entry
*) of2
;
20704 return !strcmp (entry1
->info
, entry2
->info
);
20707 /* Output a single .debug_macinfo entry. */
20710 output_macinfo_op (macinfo_entry
*ref
)
20714 struct indirect_string_node
*node
;
20715 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20716 struct dwarf_file_data
*fd
;
20720 case DW_MACINFO_start_file
:
20721 fd
= lookup_filename (ref
->info
);
20722 file_num
= maybe_emit_file (fd
);
20723 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
20724 dw2_asm_output_data_uleb128 (ref
->lineno
,
20725 "Included from line number %lu",
20726 (unsigned long) ref
->lineno
);
20727 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
20729 case DW_MACINFO_end_file
:
20730 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
20732 case DW_MACINFO_define
:
20733 case DW_MACINFO_undef
:
20734 len
= strlen (ref
->info
) + 1;
20736 && len
> DWARF_OFFSET_SIZE
20737 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
20738 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
20740 ref
->code
= ref
->code
== DW_MACINFO_define
20741 ? DW_MACRO_GNU_define_indirect
20742 : DW_MACRO_GNU_undef_indirect
;
20743 output_macinfo_op (ref
);
20746 dw2_asm_output_data (1, ref
->code
,
20747 ref
->code
== DW_MACINFO_define
20748 ? "Define macro" : "Undefine macro");
20749 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
20750 (unsigned long) ref
->lineno
);
20751 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
20753 case DW_MACRO_GNU_define_indirect
:
20754 case DW_MACRO_GNU_undef_indirect
:
20755 node
= find_AT_string (ref
->info
);
20756 if (node
->form
!= DW_FORM_strp
)
20759 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
20760 ++dw2_string_counter
;
20761 node
->label
= xstrdup (label
);
20762 node
->form
= DW_FORM_strp
;
20764 dw2_asm_output_data (1, ref
->code
,
20765 ref
->code
== DW_MACRO_GNU_define_indirect
20766 ? "Define macro indirect"
20767 : "Undefine macro indirect");
20768 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
20769 (unsigned long) ref
->lineno
);
20770 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
20771 debug_str_section
, "The macro: \"%s\"",
20774 case DW_MACRO_GNU_transparent_include
:
20775 dw2_asm_output_data (1, ref
->code
, "Transparent include");
20776 ASM_GENERATE_INTERNAL_LABEL (label
,
20777 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
20778 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
20781 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
20782 ASM_COMMENT_START
, (unsigned long) ref
->code
);
20787 /* Attempt to make a sequence of define/undef macinfo ops shareable with
20788 other compilation unit .debug_macinfo sections. IDX is the first
20789 index of a define/undef, return the number of ops that should be
20790 emitted in a comdat .debug_macinfo section and emit
20791 a DW_MACRO_GNU_transparent_include entry referencing it.
20792 If the define/undef entry should be emitted normally, return 0. */
20795 optimize_macinfo_range (unsigned int idx
, VEC (macinfo_entry
, gc
) *files
,
20796 htab_t
*macinfo_htab
)
20798 macinfo_entry
*first
, *second
, *cur
, *inc
;
20799 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
20800 unsigned char checksum
[16];
20801 struct md5_ctx ctx
;
20802 char *grp_name
, *tail
;
20804 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
20807 first
= VEC_index (macinfo_entry
, macinfo_table
, idx
);
20808 second
= VEC_index (macinfo_entry
, macinfo_table
, idx
+ 1);
20810 /* Optimize only if there are at least two consecutive define/undef ops,
20811 and either all of them are before first DW_MACINFO_start_file
20812 with lineno 0 (i.e. predefined macro block), or all of them are
20813 in some included header file. */
20814 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
20816 if (VEC_empty (macinfo_entry
, files
))
20818 if (first
->lineno
!= 0 || second
->lineno
!= 0)
20821 else if (first
->lineno
== 0)
20824 /* Find the last define/undef entry that can be grouped together
20825 with first and at the same time compute md5 checksum of their
20826 codes, linenumbers and strings. */
20827 md5_init_ctx (&ctx
);
20828 for (i
= idx
; VEC_iterate (macinfo_entry
, macinfo_table
, i
, cur
); i
++)
20829 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
20831 else if (first
->lineno
== 0 && cur
->lineno
!= 0)
20835 unsigned char code
= cur
->code
;
20836 md5_process_bytes (&code
, 1, &ctx
);
20837 checksum_uleb128 (cur
->lineno
, &ctx
);
20838 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
20840 md5_finish_ctx (&ctx
, checksum
);
20843 /* From the containing include filename (if any) pick up just
20844 usable characters from its basename. */
20845 if (first
->lineno
== 0)
20848 base
= lbasename (VEC_last (macinfo_entry
, files
)->info
);
20849 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
20850 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
20851 encoded_filename_len
++;
20852 /* Count . at the end. */
20853 if (encoded_filename_len
)
20854 encoded_filename_len
++;
20856 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
20857 linebuf_len
= strlen (linebuf
);
20859 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
20860 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
20862 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
20863 tail
= grp_name
+ 4;
20864 if (encoded_filename_len
)
20866 for (i
= 0; base
[i
]; i
++)
20867 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
20871 memcpy (tail
, linebuf
, linebuf_len
);
20872 tail
+= linebuf_len
;
20874 for (i
= 0; i
< 16; i
++)
20875 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
20877 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
20878 in the empty vector entry before the first define/undef. */
20879 inc
= VEC_index (macinfo_entry
, macinfo_table
, idx
- 1);
20880 inc
->code
= DW_MACRO_GNU_transparent_include
;
20882 inc
->info
= ggc_strdup (grp_name
);
20883 if (*macinfo_htab
== NULL
)
20884 *macinfo_htab
= htab_create (10, htab_macinfo_hash
, htab_macinfo_eq
, NULL
);
20885 /* Avoid emitting duplicates. */
20886 slot
= htab_find_slot (*macinfo_htab
, inc
, INSERT
);
20891 /* If such an entry has been used before, just emit
20892 a DW_MACRO_GNU_transparent_include op. */
20893 inc
= (macinfo_entry
*) *slot
;
20894 output_macinfo_op (inc
);
20895 /* And clear all macinfo_entry in the range to avoid emitting them
20896 in the second pass. */
20898 VEC_iterate (macinfo_entry
, macinfo_table
, i
, cur
)
20899 && i
< idx
+ count
;
20909 inc
->lineno
= htab_elements (*macinfo_htab
);
20910 output_macinfo_op (inc
);
20915 /* Output macinfo section(s). */
20918 output_macinfo (void)
20921 unsigned long length
= VEC_length (macinfo_entry
, macinfo_table
);
20922 macinfo_entry
*ref
;
20923 VEC (macinfo_entry
, gc
) *files
= NULL
;
20924 htab_t macinfo_htab
= NULL
;
20929 /* output_macinfo* uses these interchangeably. */
20930 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
20931 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
20932 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
20933 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
20935 /* For .debug_macro emit the section header. */
20938 dw2_asm_output_data (2, 4, "DWARF macro version number");
20939 if (DWARF_OFFSET_SIZE
== 8)
20940 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
20942 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
20943 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_line_section_label
,
20944 debug_line_section
, NULL
);
20947 /* In the first loop, it emits the primary .debug_macinfo section
20948 and after each emitted op the macinfo_entry is cleared.
20949 If a longer range of define/undef ops can be optimized using
20950 DW_MACRO_GNU_transparent_include, the
20951 DW_MACRO_GNU_transparent_include op is emitted and kept in
20952 the vector before the first define/undef in the range and the
20953 whole range of define/undef ops is not emitted and kept. */
20954 for (i
= 0; VEC_iterate (macinfo_entry
, macinfo_table
, i
, ref
); i
++)
20958 case DW_MACINFO_start_file
:
20959 VEC_safe_push (macinfo_entry
, gc
, files
, ref
);
20961 case DW_MACINFO_end_file
:
20962 if (!VEC_empty (macinfo_entry
, files
))
20963 VEC_pop (macinfo_entry
, files
);
20965 case DW_MACINFO_define
:
20966 case DW_MACINFO_undef
:
20968 && HAVE_COMDAT_GROUP
20969 && VEC_length (macinfo_entry
, files
) != 1
20972 && VEC_index (macinfo_entry
, macinfo_table
, i
- 1)->code
== 0)
20974 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
20983 /* A dummy entry may be inserted at the beginning to be able
20984 to optimize the whole block of predefined macros. */
20990 output_macinfo_op (ref
);
20995 if (macinfo_htab
== NULL
)
20998 htab_delete (macinfo_htab
);
21000 /* If any DW_MACRO_GNU_transparent_include were used, on those
21001 DW_MACRO_GNU_transparent_include entries terminate the
21002 current chain and switch to a new comdat .debug_macinfo
21003 section and emit the define/undef entries within it. */
21004 for (i
= 0; VEC_iterate (macinfo_entry
, macinfo_table
, i
, ref
); i
++)
21009 case DW_MACRO_GNU_transparent_include
:
21011 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21012 tree comdat_key
= get_identifier (ref
->info
);
21013 /* Terminate the previous .debug_macinfo section. */
21014 dw2_asm_output_data (1, 0, "End compilation unit");
21015 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
21017 | SECTION_LINKONCE
,
21019 ASM_GENERATE_INTERNAL_LABEL (label
,
21020 DEBUG_MACRO_SECTION_LABEL
,
21022 ASM_OUTPUT_LABEL (asm_out_file
, label
);
21025 dw2_asm_output_data (2, 4, "DWARF macro version number");
21026 if (DWARF_OFFSET_SIZE
== 8)
21027 dw2_asm_output_data (1, 1, "Flags: 64-bit");
21029 dw2_asm_output_data (1, 0, "Flags: 32-bit");
21032 case DW_MACINFO_define
:
21033 case DW_MACINFO_undef
:
21034 output_macinfo_op (ref
);
21039 gcc_unreachable ();
21043 /* Set up for Dwarf output at the start of compilation. */
21046 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
21048 /* Allocate the file_table. */
21049 file_table
= htab_create_ggc (50, file_table_hash
,
21050 file_table_eq
, NULL
);
21052 /* Allocate the decl_die_table. */
21053 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
21054 decl_die_table_eq
, NULL
);
21056 /* Allocate the decl_loc_table. */
21057 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
21058 decl_loc_table_eq
, NULL
);
21060 /* Allocate the cached_dw_loc_list_table. */
21061 cached_dw_loc_list_table
21062 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
21063 cached_dw_loc_list_table_eq
, NULL
);
21065 /* Allocate the initial hunk of the decl_scope_table. */
21066 decl_scope_table
= VEC_alloc (tree
, gc
, 256);
21068 /* Allocate the initial hunk of the abbrev_die_table. */
21069 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
21070 (ABBREV_DIE_TABLE_INCREMENT
);
21071 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
21072 /* Zero-th entry is allocated, but unused. */
21073 abbrev_die_table_in_use
= 1;
21075 /* Allocate the pubtypes and pubnames vectors. */
21076 pubname_table
= VEC_alloc (pubname_entry
, gc
, 32);
21077 pubtype_table
= VEC_alloc (pubname_entry
, gc
, 32);
21079 incomplete_types
= VEC_alloc (tree
, gc
, 64);
21081 used_rtx_array
= VEC_alloc (rtx
, gc
, 32);
21083 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
21084 SECTION_DEBUG
, NULL
);
21085 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21086 SECTION_DEBUG
, NULL
);
21087 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
21088 SECTION_DEBUG
, NULL
);
21089 debug_macinfo_section
= get_section (dwarf_strict
21090 ? DEBUG_MACINFO_SECTION
21091 : DEBUG_MACRO_SECTION
,
21092 SECTION_DEBUG
, NULL
);
21093 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
21094 SECTION_DEBUG
, NULL
);
21095 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
21096 SECTION_DEBUG
, NULL
);
21097 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
21098 SECTION_DEBUG
, NULL
);
21099 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
21100 SECTION_DEBUG
, NULL
);
21101 debug_str_section
= get_section (DEBUG_STR_SECTION
,
21102 DEBUG_STR_SECTION_FLAGS
, NULL
);
21103 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
21104 SECTION_DEBUG
, NULL
);
21105 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
21106 SECTION_DEBUG
, NULL
);
21108 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
21109 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
21110 DEBUG_ABBREV_SECTION_LABEL
, 0);
21111 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
21112 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
21113 COLD_TEXT_SECTION_LABEL
, 0);
21114 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
21116 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
21117 DEBUG_INFO_SECTION_LABEL
, 0);
21118 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
21119 DEBUG_LINE_SECTION_LABEL
, 0);
21120 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
21121 DEBUG_RANGES_SECTION_LABEL
, 0);
21122 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
21124 ? DEBUG_MACINFO_SECTION_LABEL
21125 : DEBUG_MACRO_SECTION_LABEL
, 0);
21127 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21128 macinfo_table
= VEC_alloc (macinfo_entry
, gc
, 64);
21130 switch_to_section (text_section
);
21131 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
21133 /* Make sure the line number table for .text always exists. */
21134 text_section_line_info
= new_line_info_table ();
21135 text_section_line_info
->end_label
= text_end_label
;
21138 /* Called before cgraph_optimize starts outputtting functions, variables
21139 and toplevel asms into assembly. */
21142 dwarf2out_assembly_start (void)
21144 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
21145 && dwarf2out_do_cfi_asm ()
21146 && (!(flag_unwind_tables
|| flag_exceptions
)
21147 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
21148 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
21151 /* A helper function for dwarf2out_finish called through
21152 htab_traverse. Emit one queued .debug_str string. */
21155 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
21157 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21159 if (node
->form
== DW_FORM_strp
)
21161 switch_to_section (debug_str_section
);
21162 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
21163 assemble_string (node
->str
, strlen (node
->str
) + 1);
21169 #if ENABLE_ASSERT_CHECKING
21170 /* Verify that all marks are clear. */
21173 verify_marks_clear (dw_die_ref die
)
21177 gcc_assert (! die
->die_mark
);
21178 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
21180 #endif /* ENABLE_ASSERT_CHECKING */
21182 /* Clear the marks for a die and its children.
21183 Be cool if the mark isn't set. */
21186 prune_unmark_dies (dw_die_ref die
)
21192 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
21195 /* Given DIE that we're marking as used, find any other dies
21196 it references as attributes and mark them as used. */
21199 prune_unused_types_walk_attribs (dw_die_ref die
)
21204 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
21206 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
21208 /* A reference to another DIE.
21209 Make sure that it will get emitted.
21210 If it was broken out into a comdat group, don't follow it. */
21211 if (! use_debug_types
21212 || a
->dw_attr
== DW_AT_specification
21213 || a
->dw_attr_val
.v
.val_die_ref
.die
->die_id
.die_type_node
== NULL
)
21214 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
21216 /* Set the string's refcount to 0 so that prune_unused_types_mark
21217 accounts properly for it. */
21218 if (AT_class (a
) == dw_val_class_str
)
21219 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
21223 /* Mark the generic parameters and arguments children DIEs of DIE. */
21226 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
21230 if (die
== NULL
|| die
->die_child
== NULL
)
21232 c
= die
->die_child
;
21235 switch (c
->die_tag
)
21237 case DW_TAG_template_type_param
:
21238 case DW_TAG_template_value_param
:
21239 case DW_TAG_GNU_template_template_param
:
21240 case DW_TAG_GNU_template_parameter_pack
:
21241 prune_unused_types_mark (c
, 1);
21247 } while (c
&& c
!= die
->die_child
);
21250 /* Mark DIE as being used. If DOKIDS is true, then walk down
21251 to DIE's children. */
21254 prune_unused_types_mark (dw_die_ref die
, int dokids
)
21258 if (die
->die_mark
== 0)
21260 /* We haven't done this node yet. Mark it as used. */
21262 /* If this is the DIE of a generic type instantiation,
21263 mark the children DIEs that describe its generic parms and
21265 prune_unused_types_mark_generic_parms_dies (die
);
21267 /* We also have to mark its parents as used.
21268 (But we don't want to mark our parents' kids due to this.) */
21269 if (die
->die_parent
)
21270 prune_unused_types_mark (die
->die_parent
, 0);
21272 /* Mark any referenced nodes. */
21273 prune_unused_types_walk_attribs (die
);
21275 /* If this node is a specification,
21276 also mark the definition, if it exists. */
21277 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
21278 prune_unused_types_mark (die
->die_definition
, 1);
21281 if (dokids
&& die
->die_mark
!= 2)
21283 /* We need to walk the children, but haven't done so yet.
21284 Remember that we've walked the kids. */
21287 /* If this is an array type, we need to make sure our
21288 kids get marked, even if they're types. If we're
21289 breaking out types into comdat sections, do this
21290 for all type definitions. */
21291 if (die
->die_tag
== DW_TAG_array_type
21292 || (use_debug_types
21293 && is_type_die (die
) && ! is_declaration_die (die
)))
21294 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
21296 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
21300 /* For local classes, look if any static member functions were emitted
21301 and if so, mark them. */
21304 prune_unused_types_walk_local_classes (dw_die_ref die
)
21308 if (die
->die_mark
== 2)
21311 switch (die
->die_tag
)
21313 case DW_TAG_structure_type
:
21314 case DW_TAG_union_type
:
21315 case DW_TAG_class_type
:
21318 case DW_TAG_subprogram
:
21319 if (!get_AT_flag (die
, DW_AT_declaration
)
21320 || die
->die_definition
!= NULL
)
21321 prune_unused_types_mark (die
, 1);
21328 /* Mark children. */
21329 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
21332 /* Walk the tree DIE and mark types that we actually use. */
21335 prune_unused_types_walk (dw_die_ref die
)
21339 /* Don't do anything if this node is already marked and
21340 children have been marked as well. */
21341 if (die
->die_mark
== 2)
21344 switch (die
->die_tag
)
21346 case DW_TAG_structure_type
:
21347 case DW_TAG_union_type
:
21348 case DW_TAG_class_type
:
21349 if (die
->die_perennial_p
)
21352 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
21353 if (c
->die_tag
== DW_TAG_subprogram
)
21356 /* Finding used static member functions inside of classes
21357 is needed just for local classes, because for other classes
21358 static member function DIEs with DW_AT_specification
21359 are emitted outside of the DW_TAG_*_type. If we ever change
21360 it, we'd need to call this even for non-local classes. */
21362 prune_unused_types_walk_local_classes (die
);
21364 /* It's a type node --- don't mark it. */
21367 case DW_TAG_const_type
:
21368 case DW_TAG_packed_type
:
21369 case DW_TAG_pointer_type
:
21370 case DW_TAG_reference_type
:
21371 case DW_TAG_rvalue_reference_type
:
21372 case DW_TAG_volatile_type
:
21373 case DW_TAG_typedef
:
21374 case DW_TAG_array_type
:
21375 case DW_TAG_interface_type
:
21376 case DW_TAG_friend
:
21377 case DW_TAG_variant_part
:
21378 case DW_TAG_enumeration_type
:
21379 case DW_TAG_subroutine_type
:
21380 case DW_TAG_string_type
:
21381 case DW_TAG_set_type
:
21382 case DW_TAG_subrange_type
:
21383 case DW_TAG_ptr_to_member_type
:
21384 case DW_TAG_file_type
:
21385 if (die
->die_perennial_p
)
21388 /* It's a type node --- don't mark it. */
21392 /* Mark everything else. */
21396 if (die
->die_mark
== 0)
21400 /* Now, mark any dies referenced from here. */
21401 prune_unused_types_walk_attribs (die
);
21406 /* Mark children. */
21407 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
21410 /* Increment the string counts on strings referred to from DIE's
21414 prune_unused_types_update_strings (dw_die_ref die
)
21419 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
21420 if (AT_class (a
) == dw_val_class_str
)
21422 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
21424 /* Avoid unnecessarily putting strings that are used less than
21425 twice in the hash table. */
21427 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
21430 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
21431 htab_hash_string (s
->str
),
21433 gcc_assert (*slot
== NULL
);
21439 /* Remove from the tree DIE any dies that aren't marked. */
21442 prune_unused_types_prune (dw_die_ref die
)
21446 gcc_assert (die
->die_mark
);
21447 prune_unused_types_update_strings (die
);
21449 if (! die
->die_child
)
21452 c
= die
->die_child
;
21454 dw_die_ref prev
= c
;
21455 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
21456 if (c
== die
->die_child
)
21458 /* No marked children between 'prev' and the end of the list. */
21460 /* No marked children at all. */
21461 die
->die_child
= NULL
;
21464 prev
->die_sib
= c
->die_sib
;
21465 die
->die_child
= prev
;
21470 if (c
!= prev
->die_sib
)
21472 prune_unused_types_prune (c
);
21473 } while (c
!= die
->die_child
);
21476 /* Remove dies representing declarations that we never use. */
21479 prune_unused_types (void)
21482 limbo_die_node
*node
;
21483 comdat_type_node
*ctnode
;
21485 dw_die_ref base_type
;
21487 #if ENABLE_ASSERT_CHECKING
21488 /* All the marks should already be clear. */
21489 verify_marks_clear (comp_unit_die ());
21490 for (node
= limbo_die_list
; node
; node
= node
->next
)
21491 verify_marks_clear (node
->die
);
21492 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21493 verify_marks_clear (ctnode
->root_die
);
21494 #endif /* ENABLE_ASSERT_CHECKING */
21496 /* Mark types that are used in global variables. */
21497 premark_types_used_by_global_vars ();
21499 /* Set the mark on nodes that are actually used. */
21500 prune_unused_types_walk (comp_unit_die ());
21501 for (node
= limbo_die_list
; node
; node
= node
->next
)
21502 prune_unused_types_walk (node
->die
);
21503 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21505 prune_unused_types_walk (ctnode
->root_die
);
21506 prune_unused_types_mark (ctnode
->type_die
, 1);
21509 /* Also set the mark on nodes referenced from the
21511 FOR_EACH_VEC_ELT (pubname_entry
, pubname_table
, i
, pub
)
21512 prune_unused_types_mark (pub
->die
, 1);
21513 for (i
= 0; VEC_iterate (dw_die_ref
, base_types
, i
, base_type
); i
++)
21514 prune_unused_types_mark (base_type
, 1);
21516 if (debug_str_hash
)
21517 htab_empty (debug_str_hash
);
21518 prune_unused_types_prune (comp_unit_die ());
21519 for (node
= limbo_die_list
; node
; node
= node
->next
)
21520 prune_unused_types_prune (node
->die
);
21521 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21522 prune_unused_types_prune (ctnode
->root_die
);
21524 /* Leave the marks clear. */
21525 prune_unmark_dies (comp_unit_die ());
21526 for (node
= limbo_die_list
; node
; node
= node
->next
)
21527 prune_unmark_dies (node
->die
);
21528 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21529 prune_unmark_dies (ctnode
->root_die
);
21532 /* Set the parameter to true if there are any relative pathnames in
21535 file_table_relative_p (void ** slot
, void *param
)
21537 bool *p
= (bool *) param
;
21538 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
21539 if (!IS_ABSOLUTE_PATH (d
->filename
))
21547 /* Routines to manipulate hash table of comdat type units. */
21550 htab_ct_hash (const void *of
)
21553 const comdat_type_node
*const type_node
= (const comdat_type_node
*) of
;
21555 memcpy (&h
, type_node
->signature
, sizeof (h
));
21560 htab_ct_eq (const void *of1
, const void *of2
)
21562 const comdat_type_node
*const type_node_1
= (const comdat_type_node
*) of1
;
21563 const comdat_type_node
*const type_node_2
= (const comdat_type_node
*) of2
;
21565 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
21566 DWARF_TYPE_SIGNATURE_SIZE
));
21569 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
21570 to the location it would have been added, should we know its
21571 DECL_ASSEMBLER_NAME when we added other attributes. This will
21572 probably improve compactness of debug info, removing equivalent
21573 abbrevs, and hide any differences caused by deferring the
21574 computation of the assembler name, triggered by e.g. PCH. */
21577 move_linkage_attr (dw_die_ref die
)
21579 unsigned ix
= VEC_length (dw_attr_node
, die
->die_attr
);
21580 dw_attr_node linkage
= *VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
21582 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
21583 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
21587 dw_attr_node
*prev
= VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
21589 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
21593 if (ix
!= VEC_length (dw_attr_node
, die
->die_attr
) - 1)
21595 VEC_pop (dw_attr_node
, die
->die_attr
);
21596 VEC_quick_insert (dw_attr_node
, die
->die_attr
, ix
, &linkage
);
21600 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
21601 referenced from typed stack ops and count how often they are used. */
21604 mark_base_types (dw_loc_descr_ref loc
)
21606 dw_die_ref base_type
= NULL
;
21608 for (; loc
; loc
= loc
->dw_loc_next
)
21610 switch (loc
->dw_loc_opc
)
21612 case DW_OP_GNU_regval_type
:
21613 case DW_OP_GNU_deref_type
:
21614 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
21616 case DW_OP_GNU_convert
:
21617 case DW_OP_GNU_reinterpret
:
21618 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
21621 case DW_OP_GNU_const_type
:
21622 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
21624 case DW_OP_GNU_entry_value
:
21625 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
21630 gcc_assert (base_type
->die_parent
== comp_unit_die ());
21631 if (base_type
->die_mark
)
21632 base_type
->die_mark
++;
21635 VEC_safe_push (dw_die_ref
, heap
, base_types
, base_type
);
21636 base_type
->die_mark
= 1;
21641 /* Comparison function for sorting marked base types. */
21644 base_type_cmp (const void *x
, const void *y
)
21646 dw_die_ref dx
= *(const dw_die_ref
*) x
;
21647 dw_die_ref dy
= *(const dw_die_ref
*) y
;
21648 unsigned int byte_size1
, byte_size2
;
21649 unsigned int encoding1
, encoding2
;
21650 if (dx
->die_mark
> dy
->die_mark
)
21652 if (dx
->die_mark
< dy
->die_mark
)
21654 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
21655 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
21656 if (byte_size1
< byte_size2
)
21658 if (byte_size1
> byte_size2
)
21660 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
21661 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
21662 if (encoding1
< encoding2
)
21664 if (encoding1
> encoding2
)
21669 /* Move base types marked by mark_base_types as early as possible
21670 in the CU, sorted by decreasing usage count both to make the
21671 uleb128 references as small as possible and to make sure they
21672 will have die_offset already computed by calc_die_sizes when
21673 sizes of typed stack loc ops is computed. */
21676 move_marked_base_types (void)
21679 dw_die_ref base_type
, die
, c
;
21681 if (VEC_empty (dw_die_ref
, base_types
))
21684 /* Sort by decreasing usage count, they will be added again in that
21686 VEC_qsort (dw_die_ref
, base_types
, base_type_cmp
);
21687 die
= comp_unit_die ();
21688 c
= die
->die_child
;
21691 dw_die_ref prev
= c
;
21693 while (c
->die_mark
)
21695 remove_child_with_prev (c
, prev
);
21696 /* As base types got marked, there must be at least
21697 one node other than DW_TAG_base_type. */
21698 gcc_assert (c
!= c
->die_sib
);
21702 while (c
!= die
->die_child
);
21703 gcc_assert (die
->die_child
);
21704 c
= die
->die_child
;
21705 for (i
= 0; VEC_iterate (dw_die_ref
, base_types
, i
, base_type
); i
++)
21707 base_type
->die_mark
= 0;
21708 base_type
->die_sib
= c
->die_sib
;
21709 c
->die_sib
= base_type
;
21714 /* Helper function for resolve_addr, attempt to resolve
21715 one CONST_STRING, return non-zero if not successful. Similarly verify that
21716 SYMBOL_REFs refer to variables emitted in the current CU. */
21719 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
21723 if (GET_CODE (rtl
) == CONST_STRING
)
21725 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
21726 tree t
= build_string (len
, XSTR (rtl
, 0));
21727 tree tlen
= size_int (len
- 1);
21729 = build_array_type (char_type_node
, build_index_type (tlen
));
21730 rtl
= lookup_constant_def (t
);
21731 if (!rtl
|| !MEM_P (rtl
))
21733 rtl
= XEXP (rtl
, 0);
21734 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
21739 if (GET_CODE (rtl
) == SYMBOL_REF
21740 && SYMBOL_REF_DECL (rtl
))
21742 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
21744 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
21747 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
21751 if (GET_CODE (rtl
) == CONST
21752 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
21758 /* Helper function for resolve_addr, handle one location
21759 expression, return false if at least one CONST_STRING or SYMBOL_REF in
21760 the location list couldn't be resolved. */
21763 resolve_addr_in_expr (dw_loc_descr_ref loc
)
21765 dw_loc_descr_ref keep
= NULL
;
21766 for (; loc
; loc
= loc
->dw_loc_next
)
21767 switch (loc
->dw_loc_opc
)
21770 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
21773 case DW_OP_const4u
:
21774 case DW_OP_const8u
:
21776 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
21779 case DW_OP_plus_uconst
:
21780 if (size_of_loc_descr (loc
)
21781 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
21783 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
21785 dw_loc_descr_ref repl
21786 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
21787 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
21788 add_loc_descr (&repl
, loc
->dw_loc_next
);
21792 case DW_OP_implicit_value
:
21793 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
21794 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
21797 case DW_OP_GNU_implicit_pointer
:
21798 case DW_OP_GNU_parameter_ref
:
21799 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
21802 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
21805 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
21806 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
21807 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
21810 case DW_OP_GNU_const_type
:
21811 case DW_OP_GNU_regval_type
:
21812 case DW_OP_GNU_deref_type
:
21813 case DW_OP_GNU_convert
:
21814 case DW_OP_GNU_reinterpret
:
21815 while (loc
->dw_loc_next
21816 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
21818 dw_die_ref base1
, base2
;
21819 unsigned enc1
, enc2
, size1
, size2
;
21820 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
21821 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
21822 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
21823 else if (loc
->dw_loc_oprnd1
.val_class
21824 == dw_val_class_unsigned_const
)
21827 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
21828 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
21829 == dw_val_class_unsigned_const
)
21831 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
21832 gcc_assert (base1
->die_tag
== DW_TAG_base_type
21833 && base2
->die_tag
== DW_TAG_base_type
);
21834 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
21835 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
21836 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
21837 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
21839 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
21840 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
21844 /* Optimize away next DW_OP_GNU_convert after
21845 adjusting LOC's base type die reference. */
21846 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
21847 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
21848 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
21850 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
21851 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
21854 /* Don't change integer DW_OP_GNU_convert after e.g. floating
21855 point typed stack entry. */
21856 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
21857 keep
= loc
->dw_loc_next
;
21867 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
21868 an address in .rodata section if the string literal is emitted there,
21869 or remove the containing location list or replace DW_AT_const_value
21870 with DW_AT_location and empty location expression, if it isn't found
21871 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
21872 to something that has been emitted in the current CU. */
21875 resolve_addr (dw_die_ref die
)
21879 dw_loc_list_ref
*curr
, *start
, loc
;
21882 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
21883 switch (AT_class (a
))
21885 case dw_val_class_loc_list
:
21886 start
= curr
= AT_loc_list_ptr (a
);
21889 /* The same list can be referenced more than once. See if we have
21890 already recorded the result from a previous pass. */
21892 *curr
= loc
->dw_loc_next
;
21893 else if (!loc
->resolved_addr
)
21895 /* As things stand, we do not expect or allow one die to
21896 reference a suffix of another die's location list chain.
21897 References must be identical or completely separate.
21898 There is therefore no need to cache the result of this
21899 pass on any list other than the first; doing so
21900 would lead to unnecessary writes. */
21903 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
21904 if (!resolve_addr_in_expr ((*curr
)->expr
))
21906 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
21907 if (next
&& (*curr
)->ll_symbol
)
21909 gcc_assert (!next
->ll_symbol
);
21910 next
->ll_symbol
= (*curr
)->ll_symbol
;
21916 mark_base_types ((*curr
)->expr
);
21917 curr
= &(*curr
)->dw_loc_next
;
21921 loc
->resolved_addr
= 1;
21925 loc
->dw_loc_next
= *start
;
21930 remove_AT (die
, a
->dw_attr
);
21934 case dw_val_class_loc
:
21936 dw_loc_descr_ref l
= AT_loc (a
);
21937 /* For -gdwarf-2 don't attempt to optimize
21938 DW_AT_data_member_location containing
21939 DW_OP_plus_uconst - older consumers might
21940 rely on it being that op instead of a more complex,
21941 but shorter, location description. */
21942 if ((dwarf_version
> 2
21943 || a
->dw_attr
!= DW_AT_data_member_location
21945 || l
->dw_loc_opc
!= DW_OP_plus_uconst
21946 || l
->dw_loc_next
!= NULL
)
21947 && !resolve_addr_in_expr (l
))
21949 remove_AT (die
, a
->dw_attr
);
21953 mark_base_types (l
);
21956 case dw_val_class_addr
:
21957 if (a
->dw_attr
== DW_AT_const_value
21958 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
21960 remove_AT (die
, a
->dw_attr
);
21963 if (die
->die_tag
== DW_TAG_GNU_call_site
21964 && a
->dw_attr
== DW_AT_abstract_origin
)
21966 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
21967 dw_die_ref tdie
= lookup_decl_die (tdecl
);
21969 && DECL_EXTERNAL (tdecl
)
21970 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
21972 force_decl_die (tdecl
);
21973 tdie
= lookup_decl_die (tdecl
);
21977 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
21978 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
21979 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
21983 remove_AT (die
, a
->dw_attr
);
21992 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
21995 /* Helper routines for optimize_location_lists.
21996 This pass tries to share identical local lists in .debug_loc
21999 /* Iteratively hash operands of LOC opcode. */
22001 static inline hashval_t
22002 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
22004 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
22005 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
22007 switch (loc
->dw_loc_opc
)
22009 case DW_OP_const4u
:
22010 case DW_OP_const8u
:
22014 case DW_OP_const1u
:
22015 case DW_OP_const1s
:
22016 case DW_OP_const2u
:
22017 case DW_OP_const2s
:
22018 case DW_OP_const4s
:
22019 case DW_OP_const8s
:
22023 case DW_OP_plus_uconst
:
22059 case DW_OP_deref_size
:
22060 case DW_OP_xderef_size
:
22061 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
22068 gcc_assert (val1
->val_class
== dw_val_class_loc
);
22069 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
22070 hash
= iterative_hash_object (offset
, hash
);
22073 case DW_OP_implicit_value
:
22074 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
22075 switch (val2
->val_class
)
22077 case dw_val_class_const
:
22078 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22080 case dw_val_class_vec
:
22082 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
22083 unsigned int len
= val2
->v
.val_vec
.length
;
22085 hash
= iterative_hash_object (elt_size
, hash
);
22086 hash
= iterative_hash_object (len
, hash
);
22087 hash
= iterative_hash (val2
->v
.val_vec
.array
,
22088 len
* elt_size
, hash
);
22091 case dw_val_class_const_double
:
22092 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
22093 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
22095 case dw_val_class_addr
:
22096 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
22099 gcc_unreachable ();
22103 case DW_OP_bit_piece
:
22104 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
22105 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22111 unsigned char dtprel
= 0xd1;
22112 hash
= iterative_hash_object (dtprel
, hash
);
22114 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
22116 case DW_OP_GNU_implicit_pointer
:
22117 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22119 case DW_OP_GNU_entry_value
:
22120 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
22122 case DW_OP_GNU_regval_type
:
22123 case DW_OP_GNU_deref_type
:
22125 unsigned int byte_size
22126 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
22127 unsigned int encoding
22128 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
22129 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
22130 hash
= iterative_hash_object (byte_size
, hash
);
22131 hash
= iterative_hash_object (encoding
, hash
);
22134 case DW_OP_GNU_convert
:
22135 case DW_OP_GNU_reinterpret
:
22136 if (val1
->val_class
== dw_val_class_unsigned_const
)
22138 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
22142 case DW_OP_GNU_const_type
:
22144 unsigned int byte_size
22145 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
22146 unsigned int encoding
22147 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
22148 hash
= iterative_hash_object (byte_size
, hash
);
22149 hash
= iterative_hash_object (encoding
, hash
);
22150 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
22152 hash
= iterative_hash_object (val2
->val_class
, hash
);
22153 switch (val2
->val_class
)
22155 case dw_val_class_const
:
22156 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22158 case dw_val_class_vec
:
22160 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
22161 unsigned int len
= val2
->v
.val_vec
.length
;
22163 hash
= iterative_hash_object (elt_size
, hash
);
22164 hash
= iterative_hash_object (len
, hash
);
22165 hash
= iterative_hash (val2
->v
.val_vec
.array
,
22166 len
* elt_size
, hash
);
22169 case dw_val_class_const_double
:
22170 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
22171 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
22174 gcc_unreachable ();
22180 /* Other codes have no operands. */
22186 /* Iteratively hash the whole DWARF location expression LOC. */
22188 static inline hashval_t
22189 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
22191 dw_loc_descr_ref l
;
22192 bool sizes_computed
= false;
22193 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
22194 size_of_locs (loc
);
22196 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
22198 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
22199 hash
= iterative_hash_object (opc
, hash
);
22200 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
22202 size_of_locs (loc
);
22203 sizes_computed
= true;
22205 hash
= hash_loc_operands (l
, hash
);
22210 /* Compute hash of the whole location list LIST_HEAD. */
22213 hash_loc_list (dw_loc_list_ref list_head
)
22215 dw_loc_list_ref curr
= list_head
;
22216 hashval_t hash
= 0;
22218 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
22220 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
22221 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
22223 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
22225 hash
= hash_locs (curr
->expr
, hash
);
22227 list_head
->hash
= hash
;
22230 /* Return true if X and Y opcodes have the same operands. */
22233 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
22235 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
22236 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
22237 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
22238 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
22240 switch (x
->dw_loc_opc
)
22242 case DW_OP_const4u
:
22243 case DW_OP_const8u
:
22247 case DW_OP_const1u
:
22248 case DW_OP_const1s
:
22249 case DW_OP_const2u
:
22250 case DW_OP_const2s
:
22251 case DW_OP_const4s
:
22252 case DW_OP_const8s
:
22256 case DW_OP_plus_uconst
:
22292 case DW_OP_deref_size
:
22293 case DW_OP_xderef_size
:
22294 return valx1
->v
.val_int
== valy1
->v
.val_int
;
22297 gcc_assert (valx1
->val_class
== dw_val_class_loc
22298 && valy1
->val_class
== dw_val_class_loc
22299 && x
->dw_loc_addr
== y
->dw_loc_addr
);
22300 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
22301 case DW_OP_implicit_value
:
22302 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
22303 || valx2
->val_class
!= valy2
->val_class
)
22305 switch (valx2
->val_class
)
22307 case dw_val_class_const
:
22308 return valx2
->v
.val_int
== valy2
->v
.val_int
;
22309 case dw_val_class_vec
:
22310 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
22311 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
22312 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
22313 valx2
->v
.val_vec
.elt_size
22314 * valx2
->v
.val_vec
.length
) == 0;
22315 case dw_val_class_const_double
:
22316 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
22317 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
22318 case dw_val_class_addr
:
22319 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
22321 gcc_unreachable ();
22324 case DW_OP_bit_piece
:
22325 return valx1
->v
.val_int
== valy1
->v
.val_int
22326 && valx2
->v
.val_int
== valy2
->v
.val_int
;
22329 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
22330 case DW_OP_GNU_implicit_pointer
:
22331 return valx1
->val_class
== dw_val_class_die_ref
22332 && valx1
->val_class
== valy1
->val_class
22333 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
22334 && valx2
->v
.val_int
== valy2
->v
.val_int
;
22335 case DW_OP_GNU_entry_value
:
22336 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
22337 case DW_OP_GNU_const_type
:
22338 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
22339 || valx2
->val_class
!= valy2
->val_class
)
22341 switch (valx2
->val_class
)
22343 case dw_val_class_const
:
22344 return valx2
->v
.val_int
== valy2
->v
.val_int
;
22345 case dw_val_class_vec
:
22346 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
22347 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
22348 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
22349 valx2
->v
.val_vec
.elt_size
22350 * valx2
->v
.val_vec
.length
) == 0;
22351 case dw_val_class_const_double
:
22352 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
22353 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
22355 gcc_unreachable ();
22357 case DW_OP_GNU_regval_type
:
22358 case DW_OP_GNU_deref_type
:
22359 return valx1
->v
.val_int
== valy1
->v
.val_int
22360 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
22361 case DW_OP_GNU_convert
:
22362 case DW_OP_GNU_reinterpret
:
22363 if (valx1
->val_class
!= valy1
->val_class
)
22365 if (valx1
->val_class
== dw_val_class_unsigned_const
)
22366 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
22367 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
22368 case DW_OP_GNU_parameter_ref
:
22369 return valx1
->val_class
== dw_val_class_die_ref
22370 && valx1
->val_class
== valy1
->val_class
22371 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
22373 /* Other codes have no operands. */
22378 /* Return true if DWARF location expressions X and Y are the same. */
22381 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
22383 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
22384 if (x
->dw_loc_opc
!= y
->dw_loc_opc
22385 || x
->dtprel
!= y
->dtprel
22386 || !compare_loc_operands (x
, y
))
22388 return x
== NULL
&& y
== NULL
;
22391 /* Return precomputed hash of location list X. */
22394 loc_list_hash (const void *x
)
22396 return ((const struct dw_loc_list_struct
*) x
)->hash
;
22399 /* Return 1 if location lists X and Y are the same. */
22402 loc_list_eq (const void *x
, const void *y
)
22404 const struct dw_loc_list_struct
*a
= (const struct dw_loc_list_struct
*) x
;
22405 const struct dw_loc_list_struct
*b
= (const struct dw_loc_list_struct
*) y
;
22408 if (a
->hash
!= b
->hash
)
22410 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
22411 if (strcmp (a
->begin
, b
->begin
) != 0
22412 || strcmp (a
->end
, b
->end
) != 0
22413 || (a
->section
== NULL
) != (b
->section
== NULL
)
22414 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
22415 || !compare_locs (a
->expr
, b
->expr
))
22417 return a
== NULL
&& b
== NULL
;
22420 /* Recursively optimize location lists referenced from DIE
22421 children and share them whenever possible. */
22424 optimize_location_lists_1 (dw_die_ref die
, htab_t htab
)
22431 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
22432 if (AT_class (a
) == dw_val_class_loc_list
)
22434 dw_loc_list_ref list
= AT_loc_list (a
);
22435 /* TODO: perform some optimizations here, before hashing
22436 it and storing into the hash table. */
22437 hash_loc_list (list
);
22438 slot
= htab_find_slot_with_hash (htab
, list
, list
->hash
,
22441 *slot
= (void *) list
;
22443 a
->dw_attr_val
.v
.val_loc_list
= (dw_loc_list_ref
) *slot
;
22446 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
22449 /* Optimize location lists referenced from DIE
22450 children and share them whenever possible. */
22453 optimize_location_lists (dw_die_ref die
)
22455 htab_t htab
= htab_create (500, loc_list_hash
, loc_list_eq
, NULL
);
22456 optimize_location_lists_1 (die
, htab
);
22457 htab_delete (htab
);
22460 /* Output stuff that dwarf requires at the end of every file,
22461 and generate the DWARF-2 debugging info. */
22464 dwarf2out_finish (const char *filename
)
22466 limbo_die_node
*node
, *next_node
;
22467 comdat_type_node
*ctnode
;
22468 htab_t comdat_type_table
;
22471 /* PCH might result in DW_AT_producer string being restored from the
22472 header compilation, fix it up if needed. */
22473 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
22474 if (strcmp (AT_string (producer
), producer_string
) != 0)
22476 struct indirect_string_node
*node
= find_AT_string (producer_string
);
22477 producer
->dw_attr_val
.v
.val_str
= node
;
22480 gen_scheduled_generic_parms_dies ();
22481 gen_remaining_tmpl_value_param_die_attribute ();
22483 /* Add the name for the main input file now. We delayed this from
22484 dwarf2out_init to avoid complications with PCH. */
22485 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
22486 if (!IS_ABSOLUTE_PATH (filename
))
22487 add_comp_dir_attribute (comp_unit_die ());
22488 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
22491 htab_traverse (file_table
, file_table_relative_p
, &p
);
22493 add_comp_dir_attribute (comp_unit_die ());
22496 for (i
= 0; i
< VEC_length (deferred_locations
, deferred_locations_list
); i
++)
22498 add_location_or_const_value_attribute (
22499 VEC_index (deferred_locations
, deferred_locations_list
, i
)->die
,
22500 VEC_index (deferred_locations
, deferred_locations_list
, i
)->variable
,
22505 /* Traverse the limbo die list, and add parent/child links. The only
22506 dies without parents that should be here are concrete instances of
22507 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
22508 For concrete instances, we can get the parent die from the abstract
22510 for (node
= limbo_die_list
; node
; node
= next_node
)
22512 dw_die_ref die
= node
->die
;
22513 next_node
= node
->next
;
22515 if (die
->die_parent
== NULL
)
22517 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
22519 if (origin
&& origin
->die_parent
)
22520 add_child_die (origin
->die_parent
, die
);
22521 else if (is_cu_die (die
))
22523 else if (seen_error ())
22524 /* It's OK to be confused by errors in the input. */
22525 add_child_die (comp_unit_die (), die
);
22528 /* In certain situations, the lexical block containing a
22529 nested function can be optimized away, which results
22530 in the nested function die being orphaned. Likewise
22531 with the return type of that nested function. Force
22532 this to be a child of the containing function.
22534 It may happen that even the containing function got fully
22535 inlined and optimized out. In that case we are lost and
22536 assign the empty child. This should not be big issue as
22537 the function is likely unreachable too. */
22538 tree context
= NULL_TREE
;
22540 gcc_assert (node
->created_for
);
22542 if (DECL_P (node
->created_for
))
22543 context
= DECL_CONTEXT (node
->created_for
);
22544 else if (TYPE_P (node
->created_for
))
22545 context
= TYPE_CONTEXT (node
->created_for
);
22547 origin
= get_context_die (context
);
22548 add_child_die (origin
, die
);
22553 limbo_die_list
= NULL
;
22555 #if ENABLE_ASSERT_CHECKING
22557 dw_die_ref die
= comp_unit_die (), c
;
22558 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
22561 resolve_addr (comp_unit_die ());
22562 move_marked_base_types ();
22564 for (node
= deferred_asm_name
; node
; node
= node
->next
)
22566 tree decl
= node
->created_for
;
22567 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
22569 add_linkage_attr (node
->die
, decl
);
22570 move_linkage_attr (node
->die
);
22574 deferred_asm_name
= NULL
;
22576 /* Walk through the list of incomplete types again, trying once more to
22577 emit full debugging info for them. */
22578 retry_incomplete_types ();
22580 if (flag_eliminate_unused_debug_types
)
22581 prune_unused_types ();
22583 /* Generate separate CUs for each of the include files we've seen.
22584 They will go into limbo_die_list. */
22585 if (flag_eliminate_dwarf2_dups
&& ! use_debug_types
)
22586 break_out_includes (comp_unit_die ());
22588 /* Generate separate COMDAT sections for type DIEs. */
22589 if (use_debug_types
)
22591 break_out_comdat_types (comp_unit_die ());
22593 /* Each new type_unit DIE was added to the limbo die list when created.
22594 Since these have all been added to comdat_type_list, clear the
22596 limbo_die_list
= NULL
;
22598 /* For each new comdat type unit, copy declarations for incomplete
22599 types to make the new unit self-contained (i.e., no direct
22600 references to the main compile unit). */
22601 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22602 copy_decls_for_unworthy_types (ctnode
->root_die
);
22603 copy_decls_for_unworthy_types (comp_unit_die ());
22605 /* In the process of copying declarations from one unit to another,
22606 we may have left some declarations behind that are no longer
22607 referenced. Prune them. */
22608 prune_unused_types ();
22611 /* Traverse the DIE's and add add sibling attributes to those DIE's
22612 that have children. */
22613 add_sibling_attributes (comp_unit_die ());
22614 for (node
= limbo_die_list
; node
; node
= node
->next
)
22615 add_sibling_attributes (node
->die
);
22616 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22617 add_sibling_attributes (ctnode
->root_die
);
22619 /* Output a terminator label for the .text section. */
22620 switch_to_section (text_section
);
22621 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
22622 if (cold_text_section
)
22624 switch_to_section (cold_text_section
);
22625 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
22628 /* We can only use the low/high_pc attributes if all of the code was
22630 if (!have_multiple_function_sections
22631 || (dwarf_version
< 3 && dwarf_strict
))
22633 /* Don't add if the CU has no associated code. */
22634 if (text_section_used
)
22636 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc
, text_section_label
);
22637 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc
, text_end_label
);
22644 bool range_list_added
= false;
22646 if (text_section_used
)
22647 add_ranges_by_labels (comp_unit_die (), text_section_label
,
22648 text_end_label
, &range_list_added
);
22649 if (cold_text_section_used
)
22650 add_ranges_by_labels (comp_unit_die (), cold_text_section_label
,
22651 cold_end_label
, &range_list_added
);
22653 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, fde_idx
, fde
)
22655 if (!fde
->in_std_section
)
22656 add_ranges_by_labels (comp_unit_die (), fde
->dw_fde_begin
,
22657 fde
->dw_fde_end
, &range_list_added
);
22658 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
22659 add_ranges_by_labels (comp_unit_die (), fde
->dw_fde_second_begin
,
22660 fde
->dw_fde_second_end
, &range_list_added
);
22663 if (range_list_added
)
22665 /* We need to give .debug_loc and .debug_ranges an appropriate
22666 "base address". Use zero so that these addresses become
22667 absolute. Historically, we've emitted the unexpected
22668 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
22669 Emit both to give time for other tools to adapt. */
22670 add_AT_addr (comp_unit_die (), DW_AT_low_pc
, const0_rtx
);
22671 if (! dwarf_strict
&& dwarf_version
< 4)
22672 add_AT_addr (comp_unit_die (), DW_AT_entry_pc
, const0_rtx
);
22678 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
22679 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list
,
22680 debug_line_section_label
);
22682 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22683 add_AT_macptr (comp_unit_die (),
22684 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
22685 macinfo_section_label
);
22687 if (have_location_lists
)
22688 optimize_location_lists (comp_unit_die ());
22690 /* Output all of the compilation units. We put the main one last so that
22691 the offsets are available to output_pubnames. */
22692 for (node
= limbo_die_list
; node
; node
= node
->next
)
22693 output_comp_unit (node
->die
, 0);
22695 comdat_type_table
= htab_create (100, htab_ct_hash
, htab_ct_eq
, NULL
);
22696 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22698 void **slot
= htab_find_slot (comdat_type_table
, ctnode
, INSERT
);
22700 /* Don't output duplicate types. */
22701 if (*slot
!= HTAB_EMPTY_ENTRY
)
22704 /* Add a pointer to the line table for the main compilation unit
22705 so that the debugger can make sense of DW_AT_decl_file
22707 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
22708 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
22709 debug_line_section_label
);
22711 output_comdat_type_unit (ctnode
);
22714 htab_delete (comdat_type_table
);
22716 /* Output the main compilation unit if non-empty or if .debug_macinfo
22717 will be emitted. */
22718 output_comp_unit (comp_unit_die (), debug_info_level
>= DINFO_LEVEL_VERBOSE
);
22720 /* Output the abbreviation table. */
22721 if (abbrev_die_table_in_use
!= 1)
22723 switch_to_section (debug_abbrev_section
);
22724 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
22725 output_abbrev_section ();
22728 /* Output location list section if necessary. */
22729 if (have_location_lists
)
22731 /* Output the location lists info. */
22732 switch_to_section (debug_loc_section
);
22733 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
22734 DEBUG_LOC_SECTION_LABEL
, 0);
22735 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
22736 output_location_lists (comp_unit_die ());
22739 /* Output public names table if necessary. */
22740 if (!VEC_empty (pubname_entry
, pubname_table
))
22742 gcc_assert (info_section_emitted
);
22743 switch_to_section (debug_pubnames_section
);
22744 output_pubnames (pubname_table
);
22747 /* Output public types table if necessary. */
22748 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
22749 It shouldn't hurt to emit it always, since pure DWARF2 consumers
22750 simply won't look for the section. */
22751 if (!VEC_empty (pubname_entry
, pubtype_table
))
22753 bool empty
= false;
22755 if (flag_eliminate_unused_debug_types
)
22757 /* The pubtypes table might be emptied by pruning unused items. */
22761 FOR_EACH_VEC_ELT (pubname_entry
, pubtype_table
, i
, p
)
22762 if (p
->die
->die_offset
!= 0)
22770 gcc_assert (info_section_emitted
);
22771 switch_to_section (debug_pubtypes_section
);
22772 output_pubnames (pubtype_table
);
22776 /* Output the address range information if a CU (.debug_info section)
22777 was emitted. We output an empty table even if we had no functions
22778 to put in it. This because the consumer has no way to tell the
22779 difference between an empty table that we omitted and failure to
22780 generate a table that would have contained data. */
22781 if (info_section_emitted
)
22783 unsigned long aranges_length
= size_of_aranges ();
22785 switch_to_section (debug_aranges_section
);
22786 output_aranges (aranges_length
);
22789 /* Output ranges section if necessary. */
22790 if (ranges_table_in_use
)
22792 switch_to_section (debug_ranges_section
);
22793 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
22797 /* Have to end the macro section. */
22798 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22800 switch_to_section (debug_macinfo_section
);
22801 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
22802 if (!VEC_empty (macinfo_entry
, macinfo_table
))
22804 dw2_asm_output_data (1, 0, "End compilation unit");
22807 /* Output the source line correspondence table. We must do this
22808 even if there is no line information. Otherwise, on an empty
22809 translation unit, we will generate a present, but empty,
22810 .debug_info section. IRIX 6.5 `nm' will then complain when
22811 examining the file. This is done late so that any filenames
22812 used by the debug_info section are marked as 'used'. */
22813 switch_to_section (debug_line_section
);
22814 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
22815 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
22816 output_line_info ();
22818 /* If we emitted any DW_FORM_strp form attribute, output the string
22820 if (debug_str_hash
)
22821 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
22824 #include "gt-dwarf2out.h"