1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 Free Software Foundation, Inc.
5 Contributed by Gary Funck (gary@intrepid.com).
6 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
7 Extensively modified by Jason Merrill (jason@cygnus.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
37 /* DWARF2 Abbreviation Glossary:
39 CFA = Canonical Frame Address
40 a fixed address on the stack which identifies a call frame.
41 We define it to be the value of SP just before the call insn.
42 The CFA register and offset, which may change during the course
43 of the function, are used to calculate its value at runtime.
45 CFI = Call Frame Instruction
46 an instruction for the DWARF2 abstract machine
48 CIE = Common Information Entry
49 information describing information common to one or more FDEs
51 DIE = Debugging Information Entry
53 FDE = Frame Description Entry
54 information describing the stack call frame, in particular,
55 how to restore registers
57 DW_CFA_... = DWARF2 CFA call frame instruction
58 DW_TAG_... = DWARF2 DIE tag */
62 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
77 #include "dwarf2out.h"
78 #include "dwarf2asm.h"
83 #include "diagnostic.h"
84 #include "tree-pretty-print.h"
87 #include "common/common-target.h"
88 #include "langhooks.h"
98 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
99 static rtx last_var_location_insn
;
100 static rtx cached_next_real_insn
;
102 #ifdef VMS_DEBUGGING_INFO
103 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
105 /* Define this macro to be a nonzero value if the directory specifications
106 which are output in the debug info should end with a separator. */
107 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
108 /* Define this macro to evaluate to a nonzero value if GCC should refrain
109 from generating indirect strings in DWARF2 debug information, for instance
110 if your target is stuck with an old version of GDB that is unable to
111 process them properly or uses VMS Debug. */
112 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
114 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
115 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
118 /* ??? Poison these here until it can be done generically. They've been
119 totally replaced in this file; make sure it stays that way. */
120 #undef DWARF2_UNWIND_INFO
121 #undef DWARF2_FRAME_INFO
122 #if (GCC_VERSION >= 3000)
123 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
126 /* The size of the target's pointer type. */
128 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
131 /* Array of RTXes referenced by the debugging information, which therefore
132 must be kept around forever. */
133 static GTY(()) VEC(rtx
,gc
) *used_rtx_array
;
135 /* A pointer to the base of a list of incomplete types which might be
136 completed at some later time. incomplete_types_list needs to be a
137 VEC(tree,gc) because we want to tell the garbage collector about
139 static GTY(()) VEC(tree
,gc
) *incomplete_types
;
141 /* A pointer to the base of a table of references to declaration
142 scopes. This table is a display which tracks the nesting
143 of declaration scopes at the current scope and containing
144 scopes. This table is used to find the proper place to
145 define type declaration DIE's. */
146 static GTY(()) VEC(tree
,gc
) *decl_scope_table
;
148 /* Pointers to various DWARF2 sections. */
149 static GTY(()) section
*debug_info_section
;
150 static GTY(()) section
*debug_abbrev_section
;
151 static GTY(()) section
*debug_aranges_section
;
152 static GTY(()) section
*debug_macinfo_section
;
153 static GTY(()) section
*debug_line_section
;
154 static GTY(()) section
*debug_loc_section
;
155 static GTY(()) section
*debug_pubnames_section
;
156 static GTY(()) section
*debug_pubtypes_section
;
157 static GTY(()) section
*debug_str_section
;
158 static GTY(()) section
*debug_ranges_section
;
159 static GTY(()) section
*debug_frame_section
;
161 /* Maximum size (in bytes) of an artificially generated label. */
162 #define MAX_ARTIFICIAL_LABEL_BYTES 30
164 /* According to the (draft) DWARF 3 specification, the initial length
165 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
166 bytes are 0xffffffff, followed by the length stored in the next 8
169 However, the SGI/MIPS ABI uses an initial length which is equal to
170 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
172 #ifndef DWARF_INITIAL_LENGTH_SIZE
173 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
176 /* Round SIZE up to the nearest BOUNDARY. */
177 #define DWARF_ROUND(SIZE,BOUNDARY) \
178 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
180 /* CIE identifier. */
181 #if HOST_BITS_PER_WIDE_INT >= 64
182 #define DWARF_CIE_ID \
183 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
185 #define DWARF_CIE_ID DW_CIE_ID
188 DEF_VEC_P (dw_fde_ref
);
189 DEF_VEC_ALLOC_P (dw_fde_ref
, gc
);
191 /* A vector for a table that contains frame description
192 information for each routine. */
193 static GTY(()) VEC(dw_fde_ref
, gc
) *fde_vec
;
195 struct GTY(()) indirect_string_node
{
197 unsigned int refcount
;
198 enum dwarf_form form
;
202 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
204 static GTY(()) int dw2_string_counter
;
206 /* True if the compilation unit places functions in more than one section. */
207 static GTY(()) bool have_multiple_function_sections
= false;
209 /* Whether the default text and cold text sections have been used at all. */
211 static GTY(()) bool text_section_used
= false;
212 static GTY(()) bool cold_text_section_used
= false;
214 /* The default cold text section. */
215 static GTY(()) section
*cold_text_section
;
217 /* Forward declarations for functions defined in this file. */
219 static char *stripattributes (const char *);
220 static void output_call_frame_info (int);
221 static void dwarf2out_note_section_used (void);
223 /* Personality decl of current unit. Used only when assembler does not support
225 static GTY(()) rtx current_unit_personality
;
227 /* Data and reference forms for relocatable data. */
228 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
229 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
231 #ifndef DEBUG_FRAME_SECTION
232 #define DEBUG_FRAME_SECTION ".debug_frame"
235 #ifndef FUNC_BEGIN_LABEL
236 #define FUNC_BEGIN_LABEL "LFB"
239 #ifndef FUNC_END_LABEL
240 #define FUNC_END_LABEL "LFE"
243 #ifndef PROLOGUE_END_LABEL
244 #define PROLOGUE_END_LABEL "LPE"
247 #ifndef EPILOGUE_BEGIN_LABEL
248 #define EPILOGUE_BEGIN_LABEL "LEB"
251 #ifndef FRAME_BEGIN_LABEL
252 #define FRAME_BEGIN_LABEL "Lframe"
254 #define CIE_AFTER_SIZE_LABEL "LSCIE"
255 #define CIE_END_LABEL "LECIE"
256 #define FDE_LABEL "LSFDE"
257 #define FDE_AFTER_SIZE_LABEL "LASFDE"
258 #define FDE_END_LABEL "LEFDE"
259 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
260 #define LINE_NUMBER_END_LABEL "LELT"
261 #define LN_PROLOG_AS_LABEL "LASLTP"
262 #define LN_PROLOG_END_LABEL "LELTP"
263 #define DIE_LABEL_PREFIX "DW"
265 /* Match the base name of a file to the base name of a compilation unit. */
268 matches_main_base (const char *path
)
270 /* Cache the last query. */
271 static const char *last_path
= NULL
;
272 static int last_match
= 0;
273 if (path
!= last_path
)
276 int length
= base_of_path (path
, &base
);
278 last_match
= (length
== main_input_baselength
279 && memcmp (base
, main_input_basename
, length
) == 0);
284 #ifdef DEBUG_DEBUG_STRUCT
287 dump_struct_debug (tree type
, enum debug_info_usage usage
,
288 enum debug_struct_file criterion
, int generic
,
289 int matches
, int result
)
291 /* Find the type name. */
292 tree type_decl
= TYPE_STUB_DECL (type
);
294 const char *name
= 0;
295 if (TREE_CODE (t
) == TYPE_DECL
)
298 name
= IDENTIFIER_POINTER (t
);
300 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
302 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
303 matches
? "bas" : "hdr",
304 generic
? "gen" : "ord",
305 usage
== DINFO_USAGE_DFN
? ";" :
306 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
308 (void*) type_decl
, name
);
311 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
312 dump_struct_debug (type, usage, criterion, generic, matches, result)
316 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
322 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
324 enum debug_struct_file criterion
;
326 bool generic
= lang_hooks
.types
.generic_p (type
);
329 criterion
= debug_struct_generic
[usage
];
331 criterion
= debug_struct_ordinary
[usage
];
333 if (criterion
== DINFO_STRUCT_FILE_NONE
)
334 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
335 if (criterion
== DINFO_STRUCT_FILE_ANY
)
336 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
338 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
340 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
341 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
343 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
344 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
345 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
348 /* Return a pointer to a copy of the section string name S with all
349 attributes stripped off, and an asterisk prepended (for assemble_name). */
352 stripattributes (const char *s
)
354 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
359 while (*s
&& *s
!= ',')
366 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
367 switch to the data section instead, and write out a synthetic start label
368 for collect2 the first time around. */
371 switch_to_eh_frame_section (bool back
)
375 #ifdef EH_FRAME_SECTION_NAME
376 if (eh_frame_section
== 0)
380 if (EH_TABLES_CAN_BE_READ_ONLY
)
386 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
388 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
390 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
393 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
394 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
395 && (per_encoding
& 0x70) != DW_EH_PE_absptr
396 && (per_encoding
& 0x70) != DW_EH_PE_aligned
397 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
398 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
399 ? 0 : SECTION_WRITE
);
402 flags
= SECTION_WRITE
;
403 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
405 #endif /* EH_FRAME_SECTION_NAME */
407 if (eh_frame_section
)
408 switch_to_section (eh_frame_section
);
411 /* We have no special eh_frame section. Put the information in
412 the data section and emit special labels to guide collect2. */
413 switch_to_section (data_section
);
417 label
= get_file_function_name ("F");
418 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
419 targetm
.asm_out
.globalize_label (asm_out_file
,
420 IDENTIFIER_POINTER (label
));
421 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
426 /* Switch [BACK] to the eh or debug frame table section, depending on
430 switch_to_frame_table_section (int for_eh
, bool back
)
433 switch_to_eh_frame_section (back
);
436 if (!debug_frame_section
)
437 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
438 SECTION_DEBUG
, NULL
);
439 switch_to_section (debug_frame_section
);
443 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
445 enum dw_cfi_oprnd_type
446 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
451 case DW_CFA_GNU_window_save
:
452 case DW_CFA_remember_state
:
453 case DW_CFA_restore_state
:
454 return dw_cfi_oprnd_unused
;
457 case DW_CFA_advance_loc1
:
458 case DW_CFA_advance_loc2
:
459 case DW_CFA_advance_loc4
:
460 case DW_CFA_MIPS_advance_loc8
:
461 return dw_cfi_oprnd_addr
;
464 case DW_CFA_offset_extended
:
466 case DW_CFA_offset_extended_sf
:
467 case DW_CFA_def_cfa_sf
:
469 case DW_CFA_restore_extended
:
470 case DW_CFA_undefined
:
471 case DW_CFA_same_value
:
472 case DW_CFA_def_cfa_register
:
473 case DW_CFA_register
:
474 case DW_CFA_expression
:
475 return dw_cfi_oprnd_reg_num
;
477 case DW_CFA_def_cfa_offset
:
478 case DW_CFA_GNU_args_size
:
479 case DW_CFA_def_cfa_offset_sf
:
480 return dw_cfi_oprnd_offset
;
482 case DW_CFA_def_cfa_expression
:
483 return dw_cfi_oprnd_loc
;
490 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
492 enum dw_cfi_oprnd_type
493 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
498 case DW_CFA_def_cfa_sf
:
500 case DW_CFA_offset_extended_sf
:
501 case DW_CFA_offset_extended
:
502 return dw_cfi_oprnd_offset
;
504 case DW_CFA_register
:
505 return dw_cfi_oprnd_reg_num
;
507 case DW_CFA_expression
:
508 return dw_cfi_oprnd_loc
;
511 return dw_cfi_oprnd_unused
;
515 /* Output one FDE. */
518 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
519 char *section_start_label
, int fde_encoding
, char *augmentation
,
520 bool any_lsda_needed
, int lsda_encoding
)
522 const char *begin
, *end
;
523 static unsigned int j
;
526 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
528 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
530 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
531 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
532 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
533 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
534 " indicating 64-bit DWARF extension");
535 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
537 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
540 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
542 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
543 debug_frame_section
, "FDE CIE offset");
545 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
546 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
550 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
551 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
552 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
553 "FDE initial location");
554 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
555 end
, begin
, "FDE address range");
559 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
560 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
567 int size
= size_of_encoded_value (lsda_encoding
);
569 if (lsda_encoding
== DW_EH_PE_aligned
)
571 int offset
= ( 4 /* Length */
573 + 2 * size_of_encoded_value (fde_encoding
)
574 + 1 /* Augmentation size */ );
575 int pad
= -offset
& (PTR_SIZE
- 1);
578 gcc_assert (size_of_uleb128 (size
) == 1);
581 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
583 if (fde
->uses_eh_lsda
)
585 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
586 fde
->funcdef_number
);
587 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
588 gen_rtx_SYMBOL_REF (Pmode
, l1
),
590 "Language Specific Data Area");
594 if (lsda_encoding
== DW_EH_PE_aligned
)
595 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
596 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
597 "Language Specific Data Area (none)");
601 dw2_asm_output_data_uleb128 (0, "Augmentation size");
604 /* Loop through the Call Frame Instructions associated with this FDE. */
605 fde
->dw_fde_current_label
= begin
;
607 size_t from
, until
, i
;
610 until
= VEC_length (dw_cfi_ref
, fde
->dw_fde_cfi
);
612 if (fde
->dw_fde_second_begin
== NULL
)
615 until
= fde
->dw_fde_switch_cfi_index
;
617 from
= fde
->dw_fde_switch_cfi_index
;
619 for (i
= from
; i
< until
; i
++)
620 output_cfi (VEC_index (dw_cfi_ref
, fde
->dw_fde_cfi
, i
), fde
, for_eh
);
623 /* If we are to emit a ref/link from function bodies to their frame tables,
624 do it now. This is typically performed to make sure that tables
625 associated with functions are dragged with them and not discarded in
626 garbage collecting links. We need to do this on a per function basis to
627 cope with -ffunction-sections. */
629 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
630 /* Switch to the function section, emit the ref to the tables, and
631 switch *back* into the table section. */
632 switch_to_section (function_section (fde
->decl
));
633 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
634 switch_to_frame_table_section (for_eh
, true);
637 /* Pad the FDE out to an address sized boundary. */
638 ASM_OUTPUT_ALIGN (asm_out_file
,
639 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
640 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
645 /* Return true if frame description entry FDE is needed for EH. */
648 fde_needed_for_eh_p (dw_fde_ref fde
)
650 if (flag_asynchronous_unwind_tables
)
653 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
656 if (fde
->uses_eh_lsda
)
659 /* If exceptions are enabled, we have collected nothrow info. */
660 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
666 /* Output the call frame information used to record information
667 that relates to calculating the frame pointer, and records the
668 location of saved registers. */
671 output_call_frame_info (int for_eh
)
676 char l1
[20], l2
[20], section_start_label
[20];
677 bool any_lsda_needed
= false;
678 char augmentation
[6];
679 int augmentation_size
;
680 int fde_encoding
= DW_EH_PE_absptr
;
681 int per_encoding
= DW_EH_PE_absptr
;
682 int lsda_encoding
= DW_EH_PE_absptr
;
684 rtx personality
= NULL
;
687 /* Don't emit a CIE if there won't be any FDEs. */
691 /* Nothing to do if the assembler's doing it all. */
692 if (dwarf2out_do_cfi_asm ())
695 /* If we don't have any functions we'll want to unwind out of, don't emit
696 any EH unwind information. If we make FDEs linkonce, we may have to
697 emit an empty label for an FDE that wouldn't otherwise be emitted. We
698 want to avoid having an FDE kept around when the function it refers to
699 is discarded. Example where this matters: a primary function template
700 in C++ requires EH information, an explicit specialization doesn't. */
703 bool any_eh_needed
= false;
705 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, i
, fde
)
707 if (fde
->uses_eh_lsda
)
708 any_eh_needed
= any_lsda_needed
= true;
709 else if (fde_needed_for_eh_p (fde
))
710 any_eh_needed
= true;
711 else if (TARGET_USES_WEAK_UNWIND_INFO
)
712 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
719 /* We're going to be generating comments, so turn on app. */
723 /* Switch to the proper frame section, first time. */
724 switch_to_frame_table_section (for_eh
, false);
726 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
727 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
729 /* Output the CIE. */
730 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
731 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
732 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
733 dw2_asm_output_data (4, 0xffffffff,
734 "Initial length escape value indicating 64-bit DWARF extension");
735 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
736 "Length of Common Information Entry");
737 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
739 /* Now that the CIE pointer is PC-relative for EH,
740 use 0 to identify the CIE. */
741 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
742 (for_eh
? 0 : DWARF_CIE_ID
),
743 "CIE Identifier Tag");
745 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
746 use CIE version 1, unless that would produce incorrect results
747 due to overflowing the return register column. */
748 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
750 if (return_reg
>= 256 || dwarf_version
> 2)
752 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
755 augmentation_size
= 0;
757 personality
= current_unit_personality
;
763 z Indicates that a uleb128 is present to size the
764 augmentation section.
765 L Indicates the encoding (and thus presence) of
766 an LSDA pointer in the FDE augmentation.
767 R Indicates a non-default pointer encoding for
769 P Indicates the presence of an encoding + language
770 personality routine in the CIE augmentation. */
772 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
773 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
774 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
776 p
= augmentation
+ 1;
780 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
781 assemble_external_libcall (personality
);
786 augmentation_size
+= 1;
788 if (fde_encoding
!= DW_EH_PE_absptr
)
791 augmentation_size
+= 1;
793 if (p
> augmentation
+ 1)
795 augmentation
[0] = 'z';
799 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
800 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
802 int offset
= ( 4 /* Length */
804 + 1 /* CIE version */
805 + strlen (augmentation
) + 1 /* Augmentation */
806 + size_of_uleb128 (1) /* Code alignment */
807 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
809 + 1 /* Augmentation size */
810 + 1 /* Personality encoding */ );
811 int pad
= -offset
& (PTR_SIZE
- 1);
813 augmentation_size
+= pad
;
815 /* Augmentations should be small, so there's scarce need to
816 iterate for a solution. Die if we exceed one uleb128 byte. */
817 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
821 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
822 if (dw_cie_version
>= 4)
824 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
825 dw2_asm_output_data (1, 0, "CIE Segment Size");
827 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
828 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
829 "CIE Data Alignment Factor");
831 if (dw_cie_version
== 1)
832 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
834 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
838 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
841 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
842 eh_data_format_name (per_encoding
));
843 dw2_asm_output_encoded_addr_rtx (per_encoding
,
849 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
850 eh_data_format_name (lsda_encoding
));
852 if (fde_encoding
!= DW_EH_PE_absptr
)
853 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
854 eh_data_format_name (fde_encoding
));
857 FOR_EACH_VEC_ELT (dw_cfi_ref
, cie_cfi_vec
, i
, cfi
)
858 output_cfi (cfi
, NULL
, for_eh
);
860 /* Pad the CIE out to an address sized boundary. */
861 ASM_OUTPUT_ALIGN (asm_out_file
,
862 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
863 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
865 /* Loop through all of the FDE's. */
866 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, i
, fde
)
870 /* Don't emit EH unwind info for leaf functions that don't need it. */
871 if (for_eh
&& !fde_needed_for_eh_p (fde
))
874 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
875 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
876 augmentation
, any_lsda_needed
, lsda_encoding
);
879 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
880 dw2_asm_output_data (4, 0, "End of Table");
882 /* Turn off app to make assembly quicker. */
887 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
890 dwarf2out_do_cfi_startproc (bool second
)
894 rtx personality
= get_personality_function (current_function_decl
);
896 fprintf (asm_out_file
, "\t.cfi_startproc\n");
900 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
903 /* ??? The GAS support isn't entirely consistent. We have to
904 handle indirect support ourselves, but PC-relative is done
905 in the assembler. Further, the assembler can't handle any
906 of the weirder relocation types. */
907 if (enc
& DW_EH_PE_indirect
)
908 ref
= dw2_force_const_mem (ref
, true);
910 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
911 output_addr_const (asm_out_file
, ref
);
912 fputc ('\n', asm_out_file
);
915 if (crtl
->uses_eh_lsda
)
919 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
920 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
921 current_function_funcdef_no
);
922 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
923 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
925 if (enc
& DW_EH_PE_indirect
)
926 ref
= dw2_force_const_mem (ref
, true);
928 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
929 output_addr_const (asm_out_file
, ref
);
930 fputc ('\n', asm_out_file
);
934 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
935 this allocation may be done before pass_final. */
938 dwarf2out_alloc_current_fde (void)
942 fde
= ggc_alloc_cleared_dw_fde_node ();
943 fde
->decl
= current_function_decl
;
944 fde
->funcdef_number
= current_function_funcdef_no
;
945 fde
->fde_index
= VEC_length (dw_fde_ref
, fde_vec
);
946 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
947 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
948 fde
->nothrow
= crtl
->nothrow
;
949 fde
->drap_reg
= INVALID_REGNUM
;
950 fde
->vdrap_reg
= INVALID_REGNUM
;
952 /* Record the FDE associated with this function. */
954 VEC_safe_push (dw_fde_ref
, gc
, fde_vec
, fde
);
959 /* Output a marker (i.e. a label) for the beginning of a function, before
963 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
964 const char *file ATTRIBUTE_UNUSED
)
966 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
972 current_function_func_begin_label
= NULL
;
974 do_frame
= dwarf2out_do_frame ();
976 /* ??? current_function_func_begin_label is also used by except.c for
977 call-site information. We must emit this label if it might be used. */
980 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
983 fnsec
= function_section (current_function_decl
);
984 switch_to_section (fnsec
);
985 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
986 current_function_funcdef_no
);
987 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
988 current_function_funcdef_no
);
989 dup_label
= xstrdup (label
);
990 current_function_func_begin_label
= dup_label
;
992 /* We can elide the fde allocation if we're not emitting debug info. */
996 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
997 emit insns as rtx but bypass the bulk of rest_of_compilation, which
998 would include pass_dwarf2_frame. If we've not created the FDE yet,
1002 fde
= dwarf2out_alloc_current_fde ();
1004 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1005 fde
->dw_fde_begin
= dup_label
;
1006 fde
->dw_fde_current_label
= dup_label
;
1007 fde
->in_std_section
= (fnsec
== text_section
1008 || (cold_text_section
&& fnsec
== cold_text_section
));
1010 /* We only want to output line number information for the genuine dwarf2
1011 prologue case, not the eh frame case. */
1012 #ifdef DWARF2_DEBUGGING_INFO
1014 dwarf2out_source_line (line
, file
, 0, true);
1017 if (dwarf2out_do_cfi_asm ())
1018 dwarf2out_do_cfi_startproc (false);
1021 rtx personality
= get_personality_function (current_function_decl
);
1022 if (!current_unit_personality
)
1023 current_unit_personality
= personality
;
1025 /* We cannot keep a current personality per function as without CFI
1026 asm, at the point where we emit the CFI data, there is no current
1027 function anymore. */
1028 if (personality
&& current_unit_personality
!= personality
)
1029 sorry ("multiple EH personalities are supported only with assemblers "
1030 "supporting .cfi_personality directive");
1034 /* Output a marker (i.e. a label) for the end of the generated code
1035 for a function prologue. This gets called *after* the prologue code has
1039 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1040 const char *file ATTRIBUTE_UNUSED
)
1042 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1044 /* Output a label to mark the endpoint of the code generated for this
1046 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1047 current_function_funcdef_no
);
1048 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1049 current_function_funcdef_no
);
1050 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1053 /* Output a marker (i.e. a label) for the beginning of the generated code
1054 for a function epilogue. This gets called *before* the prologue code has
1058 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1059 const char *file ATTRIBUTE_UNUSED
)
1061 dw_fde_ref fde
= cfun
->fde
;
1062 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1064 if (fde
->dw_fde_vms_begin_epilogue
)
1067 /* Output a label to mark the endpoint of the code generated for this
1069 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1070 current_function_funcdef_no
);
1071 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1072 current_function_funcdef_no
);
1073 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1076 /* Output a marker (i.e. a label) for the absolute end of the generated code
1077 for a function definition. This gets called *after* the epilogue code has
1081 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1082 const char *file ATTRIBUTE_UNUSED
)
1085 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1087 last_var_location_insn
= NULL_RTX
;
1088 cached_next_real_insn
= NULL_RTX
;
1090 if (dwarf2out_do_cfi_asm ())
1091 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1093 /* Output a label to mark the endpoint of the code generated for this
1095 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1096 current_function_funcdef_no
);
1097 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1099 gcc_assert (fde
!= NULL
);
1100 if (fde
->dw_fde_second_begin
== NULL
)
1101 fde
->dw_fde_end
= xstrdup (label
);
1105 dwarf2out_frame_finish (void)
1107 /* Output call frame information. */
1108 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1109 output_call_frame_info (0);
1111 /* Output another copy for the unwinder. */
1112 if ((flag_unwind_tables
|| flag_exceptions
)
1113 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1114 output_call_frame_info (1);
1117 /* Note that the current function section is being used for code. */
1120 dwarf2out_note_section_used (void)
1122 section
*sec
= current_function_section ();
1123 if (sec
== text_section
)
1124 text_section_used
= true;
1125 else if (sec
== cold_text_section
)
1126 cold_text_section_used
= true;
1129 static void var_location_switch_text_section (void);
1130 static void set_cur_line_info_table (section
*);
1133 dwarf2out_switch_text_section (void)
1136 dw_fde_ref fde
= cfun
->fde
;
1138 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1140 if (!in_cold_section_p
)
1142 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1143 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1144 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1148 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1149 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1150 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1152 have_multiple_function_sections
= true;
1154 /* There is no need to mark used sections when not debugging. */
1155 if (cold_text_section
!= NULL
)
1156 dwarf2out_note_section_used ();
1158 if (dwarf2out_do_cfi_asm ())
1159 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1161 /* Now do the real section switch. */
1162 sect
= current_function_section ();
1163 switch_to_section (sect
);
1165 fde
->second_in_std_section
1166 = (sect
== text_section
1167 || (cold_text_section
&& sect
== cold_text_section
));
1169 if (dwarf2out_do_cfi_asm ())
1170 dwarf2out_do_cfi_startproc (true);
1172 var_location_switch_text_section ();
1174 if (cold_text_section
!= NULL
)
1175 set_cur_line_info_table (sect
);
1178 /* And now, the subset of the debugging information support code necessary
1179 for emitting location expressions. */
1181 /* Data about a single source file. */
1182 struct GTY(()) dwarf_file_data
{
1183 const char * filename
;
1187 typedef struct GTY(()) deferred_locations_struct
1191 } deferred_locations
;
1193 DEF_VEC_O(deferred_locations
);
1194 DEF_VEC_ALLOC_O(deferred_locations
,gc
);
1196 static GTY(()) VEC(deferred_locations
, gc
) *deferred_locations_list
;
1198 DEF_VEC_P(dw_die_ref
);
1199 DEF_VEC_ALLOC_P(dw_die_ref
,heap
);
1201 /* Location lists are ranges + location descriptions for that range,
1202 so you can track variables that are in different places over
1203 their entire life. */
1204 typedef struct GTY(()) dw_loc_list_struct
{
1205 dw_loc_list_ref dw_loc_next
;
1206 const char *begin
; /* Label for begin address of range */
1207 const char *end
; /* Label for end address of range */
1208 char *ll_symbol
; /* Label for beginning of location list.
1209 Only on head of list */
1210 const char *section
; /* Section this loclist is relative to */
1211 dw_loc_descr_ref expr
;
1213 /* True if all addresses in this and subsequent lists are known to be
1216 /* True if this list has been replaced by dw_loc_next. */
1219 /* True if the range should be emitted even if begin and end
1224 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1226 /* Convert a DWARF stack opcode into its string name. */
1229 dwarf_stack_op_name (unsigned int op
)
1231 const char *name
= get_DW_OP_name (op
);
1236 return "OP_<unknown>";
1239 /* Return a pointer to a newly allocated location description. Location
1240 descriptions are simple expression terms that can be strung
1241 together to form more complicated location (address) descriptions. */
1243 static inline dw_loc_descr_ref
1244 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1245 unsigned HOST_WIDE_INT oprnd2
)
1247 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
1249 descr
->dw_loc_opc
= op
;
1250 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1251 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1252 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1253 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1258 /* Return a pointer to a newly allocated location description for
1261 static inline dw_loc_descr_ref
1262 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1265 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1268 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1271 /* Add a location description term to a location description expression. */
1274 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1276 dw_loc_descr_ref
*d
;
1278 /* Find the end of the chain. */
1279 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1285 /* Compare two location operands for exact equality. */
1288 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1290 if (a
->val_class
!= b
->val_class
)
1292 switch (a
->val_class
)
1294 case dw_val_class_none
:
1296 case dw_val_class_addr
:
1297 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1299 case dw_val_class_offset
:
1300 case dw_val_class_unsigned_const
:
1301 case dw_val_class_const
:
1302 case dw_val_class_range_list
:
1303 case dw_val_class_lineptr
:
1304 case dw_val_class_macptr
:
1305 /* These are all HOST_WIDE_INT, signed or unsigned. */
1306 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1308 case dw_val_class_loc
:
1309 return a
->v
.val_loc
== b
->v
.val_loc
;
1310 case dw_val_class_loc_list
:
1311 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1312 case dw_val_class_die_ref
:
1313 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1314 case dw_val_class_fde_ref
:
1315 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1316 case dw_val_class_lbl_id
:
1317 case dw_val_class_high_pc
:
1318 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1319 case dw_val_class_str
:
1320 return a
->v
.val_str
== b
->v
.val_str
;
1321 case dw_val_class_flag
:
1322 return a
->v
.val_flag
== b
->v
.val_flag
;
1323 case dw_val_class_file
:
1324 return a
->v
.val_file
== b
->v
.val_file
;
1325 case dw_val_class_decl_ref
:
1326 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1328 case dw_val_class_const_double
:
1329 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1330 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1332 case dw_val_class_vec
:
1334 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1335 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1337 return (a_len
== b_len
1338 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1341 case dw_val_class_data8
:
1342 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1344 case dw_val_class_vms_delta
:
1345 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1346 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1351 /* Compare two location atoms for exact equality. */
1354 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1356 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1359 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1360 address size, but since we always allocate cleared storage it
1361 should be zero for other types of locations. */
1362 if (a
->dtprel
!= b
->dtprel
)
1365 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1366 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1369 /* Compare two complete location expressions for exact equality. */
1372 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1378 if (a
== NULL
|| b
== NULL
)
1380 if (!loc_descr_equal_p_1 (a
, b
))
1389 /* Add a constant OFFSET to a location expression. */
1392 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1394 dw_loc_descr_ref loc
;
1397 gcc_assert (*list_head
!= NULL
);
1402 /* Find the end of the chain. */
1403 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1407 if (loc
->dw_loc_opc
== DW_OP_fbreg
1408 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1409 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1410 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1411 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1413 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1414 offset. Don't optimize if an signed integer overflow would happen. */
1416 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1417 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1420 else if (offset
> 0)
1421 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1425 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1426 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1430 /* Add a constant OFFSET to a location list. */
1433 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1436 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1437 loc_descr_plus_const (&d
->expr
, offset
);
1440 #define DWARF_REF_SIZE \
1441 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1443 static unsigned long int get_base_type_offset (dw_die_ref
);
1445 /* Return the size of a location descriptor. */
1447 static unsigned long
1448 size_of_loc_descr (dw_loc_descr_ref loc
)
1450 unsigned long size
= 1;
1452 switch (loc
->dw_loc_opc
)
1455 size
+= DWARF2_ADDR_SIZE
;
1474 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1477 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1482 case DW_OP_plus_uconst
:
1483 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1521 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1524 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1527 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1530 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1531 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1534 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1536 case DW_OP_bit_piece
:
1537 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1538 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1540 case DW_OP_deref_size
:
1541 case DW_OP_xderef_size
:
1550 case DW_OP_call_ref
:
1551 size
+= DWARF_REF_SIZE
;
1553 case DW_OP_implicit_value
:
1554 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1555 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1557 case DW_OP_GNU_implicit_pointer
:
1558 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1560 case DW_OP_GNU_entry_value
:
1562 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1563 size
+= size_of_uleb128 (op_size
) + op_size
;
1566 case DW_OP_GNU_const_type
:
1569 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1570 size
+= size_of_uleb128 (o
) + 1;
1571 switch (loc
->dw_loc_oprnd2
.val_class
)
1573 case dw_val_class_vec
:
1574 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1575 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1577 case dw_val_class_const
:
1578 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1580 case dw_val_class_const_double
:
1581 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1588 case DW_OP_GNU_regval_type
:
1591 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1592 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1593 + size_of_uleb128 (o
);
1596 case DW_OP_GNU_deref_type
:
1599 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1600 size
+= 1 + size_of_uleb128 (o
);
1603 case DW_OP_GNU_convert
:
1604 case DW_OP_GNU_reinterpret
:
1605 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1606 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1610 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1611 size
+= size_of_uleb128 (o
);
1614 case DW_OP_GNU_parameter_ref
:
1624 /* Return the size of a series of location descriptors. */
1627 size_of_locs (dw_loc_descr_ref loc
)
1632 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1633 field, to avoid writing to a PCH file. */
1634 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1636 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1638 size
+= size_of_loc_descr (l
);
1643 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1645 l
->dw_loc_addr
= size
;
1646 size
+= size_of_loc_descr (l
);
1652 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1653 static void get_ref_die_offset_label (char *, dw_die_ref
);
1654 static unsigned long int get_ref_die_offset (dw_die_ref
);
1656 /* Output location description stack opcode's operands (if any).
1657 The for_eh_or_skip parameter controls whether register numbers are
1658 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1659 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1660 info). This should be suppressed for the cases that have not been converted
1661 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1664 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1666 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1667 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1669 switch (loc
->dw_loc_opc
)
1671 #ifdef DWARF2_DEBUGGING_INFO
1674 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1679 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1680 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1682 fputc ('\n', asm_out_file
);
1687 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1692 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1693 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1695 fputc ('\n', asm_out_file
);
1700 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1701 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1708 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1709 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1711 dw2_asm_output_data (2, offset
, NULL
);
1714 case DW_OP_implicit_value
:
1715 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1716 switch (val2
->val_class
)
1718 case dw_val_class_const
:
1719 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1721 case dw_val_class_vec
:
1723 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1724 unsigned int len
= val2
->v
.val_vec
.length
;
1728 if (elt_size
> sizeof (HOST_WIDE_INT
))
1733 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1736 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1737 "fp or vector constant word %u", i
);
1740 case dw_val_class_const_double
:
1742 unsigned HOST_WIDE_INT first
, second
;
1744 if (WORDS_BIG_ENDIAN
)
1746 first
= val2
->v
.val_double
.high
;
1747 second
= val2
->v
.val_double
.low
;
1751 first
= val2
->v
.val_double
.low
;
1752 second
= val2
->v
.val_double
.high
;
1754 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1756 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1760 case dw_val_class_addr
:
1761 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1762 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1777 case DW_OP_implicit_value
:
1778 /* We currently don't make any attempt to make sure these are
1779 aligned properly like we do for the main unwind info, so
1780 don't support emitting things larger than a byte if we're
1781 only doing unwinding. */
1786 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1789 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1792 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1795 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1797 case DW_OP_plus_uconst
:
1798 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1832 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1836 unsigned r
= val1
->v
.val_unsigned
;
1837 if (for_eh_or_skip
>= 0)
1838 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1839 gcc_assert (size_of_uleb128 (r
)
1840 == size_of_uleb128 (val1
->v
.val_unsigned
));
1841 dw2_asm_output_data_uleb128 (r
, NULL
);
1845 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1849 unsigned r
= val1
->v
.val_unsigned
;
1850 if (for_eh_or_skip
>= 0)
1851 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1852 gcc_assert (size_of_uleb128 (r
)
1853 == size_of_uleb128 (val1
->v
.val_unsigned
));
1854 dw2_asm_output_data_uleb128 (r
, NULL
);
1855 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1859 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1861 case DW_OP_bit_piece
:
1862 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1863 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1865 case DW_OP_deref_size
:
1866 case DW_OP_xderef_size
:
1867 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1873 if (targetm
.asm_out
.output_dwarf_dtprel
)
1875 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1878 fputc ('\n', asm_out_file
);
1885 #ifdef DWARF2_DEBUGGING_INFO
1886 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
1893 case DW_OP_GNU_implicit_pointer
:
1895 char label
[MAX_ARTIFICIAL_LABEL_BYTES
1896 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
1897 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
1898 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
1899 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
1900 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1904 case DW_OP_GNU_entry_value
:
1905 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
1906 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
1909 case DW_OP_GNU_const_type
:
1911 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
1913 dw2_asm_output_data_uleb128 (o
, NULL
);
1914 switch (val2
->val_class
)
1916 case dw_val_class_const
:
1917 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
1918 dw2_asm_output_data (1, l
, NULL
);
1919 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
1921 case dw_val_class_vec
:
1923 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1924 unsigned int len
= val2
->v
.val_vec
.length
;
1929 dw2_asm_output_data (1, l
, NULL
);
1930 if (elt_size
> sizeof (HOST_WIDE_INT
))
1935 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1938 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1939 "fp or vector constant word %u", i
);
1942 case dw_val_class_const_double
:
1944 unsigned HOST_WIDE_INT first
, second
;
1945 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
1947 dw2_asm_output_data (1, 2 * l
, NULL
);
1948 if (WORDS_BIG_ENDIAN
)
1950 first
= val2
->v
.val_double
.high
;
1951 second
= val2
->v
.val_double
.low
;
1955 first
= val2
->v
.val_double
.low
;
1956 second
= val2
->v
.val_double
.high
;
1958 dw2_asm_output_data (l
, first
, NULL
);
1959 dw2_asm_output_data (l
, second
, NULL
);
1967 case DW_OP_GNU_regval_type
:
1969 unsigned r
= val1
->v
.val_unsigned
;
1970 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
1972 if (for_eh_or_skip
>= 0)
1974 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1975 gcc_assert (size_of_uleb128 (r
)
1976 == size_of_uleb128 (val1
->v
.val_unsigned
));
1978 dw2_asm_output_data_uleb128 (r
, NULL
);
1979 dw2_asm_output_data_uleb128 (o
, NULL
);
1982 case DW_OP_GNU_deref_type
:
1984 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
1986 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1987 dw2_asm_output_data_uleb128 (o
, NULL
);
1990 case DW_OP_GNU_convert
:
1991 case DW_OP_GNU_reinterpret
:
1992 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1993 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1996 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
1998 dw2_asm_output_data_uleb128 (o
, NULL
);
2002 case DW_OP_GNU_parameter_ref
:
2005 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2006 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2007 dw2_asm_output_data (4, o
, NULL
);
2012 /* Other codes have no operands. */
2017 /* Output a sequence of location operations.
2018 The for_eh_or_skip parameter controls whether register numbers are
2019 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2020 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2021 info). This should be suppressed for the cases that have not been converted
2022 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2025 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2027 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2029 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2030 /* Output the opcode. */
2031 if (for_eh_or_skip
>= 0
2032 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2034 unsigned r
= (opc
- DW_OP_breg0
);
2035 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2036 gcc_assert (r
<= 31);
2037 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2039 else if (for_eh_or_skip
>= 0
2040 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2042 unsigned r
= (opc
- DW_OP_reg0
);
2043 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2044 gcc_assert (r
<= 31);
2045 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2048 dw2_asm_output_data (1, opc
,
2049 "%s", dwarf_stack_op_name (opc
));
2051 /* Output the operand(s) (if any). */
2052 output_loc_operands (loc
, for_eh_or_skip
);
2056 /* Output location description stack opcode's operands (if any).
2057 The output is single bytes on a line, suitable for .cfi_escape. */
2060 output_loc_operands_raw (dw_loc_descr_ref loc
)
2062 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2063 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2065 switch (loc
->dw_loc_opc
)
2068 case DW_OP_implicit_value
:
2069 /* We cannot output addresses in .cfi_escape, only bytes. */
2075 case DW_OP_deref_size
:
2076 case DW_OP_xderef_size
:
2077 fputc (',', asm_out_file
);
2078 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2083 fputc (',', asm_out_file
);
2084 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2089 fputc (',', asm_out_file
);
2090 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2095 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2096 fputc (',', asm_out_file
);
2097 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2105 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2106 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2108 fputc (',', asm_out_file
);
2109 dw2_asm_output_data_raw (2, offset
);
2115 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2116 gcc_assert (size_of_uleb128 (r
)
2117 == size_of_uleb128 (val1
->v
.val_unsigned
));
2118 fputc (',', asm_out_file
);
2119 dw2_asm_output_data_uleb128_raw (r
);
2124 case DW_OP_plus_uconst
:
2126 fputc (',', asm_out_file
);
2127 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2130 case DW_OP_bit_piece
:
2131 fputc (',', asm_out_file
);
2132 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2133 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2170 fputc (',', asm_out_file
);
2171 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2176 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2177 gcc_assert (size_of_uleb128 (r
)
2178 == size_of_uleb128 (val1
->v
.val_unsigned
));
2179 fputc (',', asm_out_file
);
2180 dw2_asm_output_data_uleb128_raw (r
);
2181 fputc (',', asm_out_file
);
2182 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2186 case DW_OP_GNU_implicit_pointer
:
2187 case DW_OP_GNU_entry_value
:
2188 case DW_OP_GNU_const_type
:
2189 case DW_OP_GNU_regval_type
:
2190 case DW_OP_GNU_deref_type
:
2191 case DW_OP_GNU_convert
:
2192 case DW_OP_GNU_reinterpret
:
2193 case DW_OP_GNU_parameter_ref
:
2198 /* Other codes have no operands. */
2204 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2208 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2209 /* Output the opcode. */
2210 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2212 unsigned r
= (opc
- DW_OP_breg0
);
2213 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2214 gcc_assert (r
<= 31);
2215 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2217 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2219 unsigned r
= (opc
- DW_OP_reg0
);
2220 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2221 gcc_assert (r
<= 31);
2222 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2224 /* Output the opcode. */
2225 fprintf (asm_out_file
, "%#x", opc
);
2226 output_loc_operands_raw (loc
);
2228 if (!loc
->dw_loc_next
)
2230 loc
= loc
->dw_loc_next
;
2232 fputc (',', asm_out_file
);
2236 /* This function builds a dwarf location descriptor sequence from a
2237 dw_cfa_location, adding the given OFFSET to the result of the
2240 struct dw_loc_descr_struct
*
2241 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2243 struct dw_loc_descr_struct
*head
, *tmp
;
2245 offset
+= cfa
->offset
;
2249 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2250 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2251 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2252 add_loc_descr (&head
, tmp
);
2255 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2256 add_loc_descr (&head
, tmp
);
2260 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2265 /* This function builds a dwarf location descriptor sequence for
2266 the address at OFFSET from the CFA when stack is aligned to
2269 struct dw_loc_descr_struct
*
2270 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2271 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2273 struct dw_loc_descr_struct
*head
;
2274 unsigned int dwarf_fp
2275 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2277 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2278 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2280 head
= new_reg_loc_descr (dwarf_fp
, 0);
2281 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2282 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2283 loc_descr_plus_const (&head
, offset
);
2286 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2290 /* And now, the support for symbolic debugging information. */
2292 /* .debug_str support. */
2293 static int output_indirect_string (void **, void *);
2295 static void dwarf2out_init (const char *);
2296 static void dwarf2out_finish (const char *);
2297 static void dwarf2out_assembly_start (void);
2298 static void dwarf2out_define (unsigned int, const char *);
2299 static void dwarf2out_undef (unsigned int, const char *);
2300 static void dwarf2out_start_source_file (unsigned, const char *);
2301 static void dwarf2out_end_source_file (unsigned);
2302 static void dwarf2out_function_decl (tree
);
2303 static void dwarf2out_begin_block (unsigned, unsigned);
2304 static void dwarf2out_end_block (unsigned, unsigned);
2305 static bool dwarf2out_ignore_block (const_tree
);
2306 static void dwarf2out_global_decl (tree
);
2307 static void dwarf2out_type_decl (tree
, int);
2308 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2309 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2311 static void dwarf2out_abstract_function (tree
);
2312 static void dwarf2out_var_location (rtx
);
2313 static void dwarf2out_begin_function (tree
);
2314 static void dwarf2out_set_name (tree
, tree
);
2316 /* The debug hooks structure. */
2318 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2322 dwarf2out_assembly_start
,
2325 dwarf2out_start_source_file
,
2326 dwarf2out_end_source_file
,
2327 dwarf2out_begin_block
,
2328 dwarf2out_end_block
,
2329 dwarf2out_ignore_block
,
2330 dwarf2out_source_line
,
2331 dwarf2out_begin_prologue
,
2332 #if VMS_DEBUGGING_INFO
2333 dwarf2out_vms_end_prologue
,
2334 dwarf2out_vms_begin_epilogue
,
2336 debug_nothing_int_charstar
,
2337 debug_nothing_int_charstar
,
2339 dwarf2out_end_epilogue
,
2340 dwarf2out_begin_function
,
2341 debug_nothing_int
, /* end_function */
2342 dwarf2out_function_decl
, /* function_decl */
2343 dwarf2out_global_decl
,
2344 dwarf2out_type_decl
, /* type_decl */
2345 dwarf2out_imported_module_or_decl
,
2346 debug_nothing_tree
, /* deferred_inline_function */
2347 /* The DWARF 2 backend tries to reduce debugging bloat by not
2348 emitting the abstract description of inline functions until
2349 something tries to reference them. */
2350 dwarf2out_abstract_function
, /* outlining_inline_function */
2351 debug_nothing_rtx
, /* label */
2352 debug_nothing_int
, /* handle_pch */
2353 dwarf2out_var_location
,
2354 dwarf2out_switch_text_section
,
2356 1, /* start_end_main_source_file */
2357 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2360 /* NOTE: In the comments in this file, many references are made to
2361 "Debugging Information Entries". This term is abbreviated as `DIE'
2362 throughout the remainder of this file. */
2364 /* An internal representation of the DWARF output is built, and then
2365 walked to generate the DWARF debugging info. The walk of the internal
2366 representation is done after the entire program has been compiled.
2367 The types below are used to describe the internal representation. */
2369 /* Whether to put type DIEs into their own section .debug_types instead
2370 of making them part of the .debug_info section. Only supported for
2371 Dwarf V4 or higher and the user didn't disable them through
2372 -fno-debug-types-section. It is more efficient to put them in a
2373 separate comdat sections since the linker will then be able to
2374 remove duplicates. But not all tools support .debug_types sections
2377 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2379 /* Various DIE's use offsets relative to the beginning of the
2380 .debug_info section to refer to each other. */
2382 typedef long int dw_offset
;
2384 /* Define typedefs here to avoid circular dependencies. */
2386 typedef struct dw_attr_struct
*dw_attr_ref
;
2387 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2388 typedef struct pubname_struct
*pubname_ref
;
2389 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2390 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2391 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2393 /* The entries in the line_info table more-or-less mirror the opcodes
2394 that are used in the real dwarf line table. Arrays of these entries
2395 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2398 enum dw_line_info_opcode
{
2399 /* Emit DW_LNE_set_address; the operand is the label index. */
2402 /* Emit a row to the matrix with the given line. This may be done
2403 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2407 /* Emit a DW_LNS_set_file. */
2410 /* Emit a DW_LNS_set_column. */
2413 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2416 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2417 LI_set_prologue_end
,
2418 LI_set_epilogue_begin
,
2420 /* Emit a DW_LNE_set_discriminator. */
2421 LI_set_discriminator
2424 typedef struct GTY(()) dw_line_info_struct
{
2425 enum dw_line_info_opcode opcode
;
2427 } dw_line_info_entry
;
2429 DEF_VEC_O(dw_line_info_entry
);
2430 DEF_VEC_ALLOC_O(dw_line_info_entry
, gc
);
2432 typedef struct GTY(()) dw_line_info_table_struct
{
2433 /* The label that marks the end of this section. */
2434 const char *end_label
;
2436 /* The values for the last row of the matrix, as collected in the table.
2437 These are used to minimize the changes to the next row. */
2438 unsigned int file_num
;
2439 unsigned int line_num
;
2440 unsigned int column_num
;
2445 VEC(dw_line_info_entry
, gc
) *entries
;
2446 } dw_line_info_table
;
2448 typedef dw_line_info_table
*dw_line_info_table_p
;
2450 DEF_VEC_P(dw_line_info_table_p
);
2451 DEF_VEC_ALLOC_P(dw_line_info_table_p
, gc
);
2453 /* Each DIE attribute has a field specifying the attribute kind,
2454 a link to the next attribute in the chain, and an attribute value.
2455 Attributes are typically linked below the DIE they modify. */
2457 typedef struct GTY(()) dw_attr_struct
{
2458 enum dwarf_attribute dw_attr
;
2459 dw_val_node dw_attr_val
;
2463 DEF_VEC_O(dw_attr_node
);
2464 DEF_VEC_ALLOC_O(dw_attr_node
,gc
);
2466 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2467 The children of each node form a circular list linked by
2468 die_sib. die_child points to the node *before* the "first" child node. */
2470 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
2471 union die_symbol_or_type_node
2473 const char * GTY ((tag ("0"))) die_symbol
;
2474 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2476 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2477 VEC(dw_attr_node
,gc
) * die_attr
;
2478 dw_die_ref die_parent
;
2479 dw_die_ref die_child
;
2481 dw_die_ref die_definition
; /* ref from a specification to its definition */
2482 dw_offset die_offset
;
2483 unsigned long die_abbrev
;
2485 unsigned int decl_id
;
2486 enum dwarf_tag die_tag
;
2487 /* Die is used and must not be pruned as unused. */
2488 BOOL_BITFIELD die_perennial_p
: 1;
2489 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2490 /* Lots of spare bits. */
2494 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2495 #define FOR_EACH_CHILD(die, c, expr) do { \
2496 c = die->die_child; \
2500 } while (c != die->die_child); \
2503 /* The pubname structure */
2505 typedef struct GTY(()) pubname_struct
{
2511 DEF_VEC_O(pubname_entry
);
2512 DEF_VEC_ALLOC_O(pubname_entry
, gc
);
2514 struct GTY(()) dw_ranges_struct
{
2515 /* If this is positive, it's a block number, otherwise it's a
2516 bitwise-negated index into dw_ranges_by_label. */
2520 /* A structure to hold a macinfo entry. */
2522 typedef struct GTY(()) macinfo_struct
{
2524 unsigned HOST_WIDE_INT lineno
;
2529 DEF_VEC_O(macinfo_entry
);
2530 DEF_VEC_ALLOC_O(macinfo_entry
, gc
);
2532 struct GTY(()) dw_ranges_by_label_struct
{
2537 /* The comdat type node structure. */
2538 typedef struct GTY(()) comdat_type_struct
2540 dw_die_ref root_die
;
2541 dw_die_ref type_die
;
2542 dw_die_ref skeleton_die
;
2543 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2544 struct comdat_type_struct
*next
;
2548 /* The limbo die list structure. */
2549 typedef struct GTY(()) limbo_die_struct
{
2552 struct limbo_die_struct
*next
;
2556 typedef struct skeleton_chain_struct
2560 struct skeleton_chain_struct
*parent
;
2562 skeleton_chain_node
;
2564 /* Define a macro which returns nonzero for a TYPE_DECL which was
2565 implicitly generated for a type.
2567 Note that, unlike the C front-end (which generates a NULL named
2568 TYPE_DECL node for each complete tagged type, each array type,
2569 and each function type node created) the C++ front-end generates
2570 a _named_ TYPE_DECL node for each tagged type node created.
2571 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2572 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2573 front-end, but for each type, tagged or not. */
2575 #define TYPE_DECL_IS_STUB(decl) \
2576 (DECL_NAME (decl) == NULL_TREE \
2577 || (DECL_ARTIFICIAL (decl) \
2578 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2579 /* This is necessary for stub decls that \
2580 appear in nested inline functions. */ \
2581 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2582 && (decl_ultimate_origin (decl) \
2583 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2585 /* Information concerning the compilation unit's programming
2586 language, and compiler version. */
2588 /* Fixed size portion of the DWARF compilation unit header. */
2589 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2590 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2592 /* Fixed size portion of the DWARF comdat type unit header. */
2593 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2594 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2595 + DWARF_OFFSET_SIZE)
2597 /* Fixed size portion of public names info. */
2598 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2600 /* Fixed size portion of the address range info. */
2601 #define DWARF_ARANGES_HEADER_SIZE \
2602 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2603 DWARF2_ADDR_SIZE * 2) \
2604 - DWARF_INITIAL_LENGTH_SIZE)
2606 /* Size of padding portion in the address range info. It must be
2607 aligned to twice the pointer size. */
2608 #define DWARF_ARANGES_PAD_SIZE \
2609 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2610 DWARF2_ADDR_SIZE * 2) \
2611 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2613 /* Use assembler line directives if available. */
2614 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2615 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2616 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2618 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2622 /* Minimum line offset in a special line info. opcode.
2623 This value was chosen to give a reasonable range of values. */
2624 #define DWARF_LINE_BASE -10
2626 /* First special line opcode - leave room for the standard opcodes. */
2627 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2629 /* Range of line offsets in a special line info. opcode. */
2630 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2632 /* Flag that indicates the initial value of the is_stmt_start flag.
2633 In the present implementation, we do not mark any lines as
2634 the beginning of a source statement, because that information
2635 is not made available by the GCC front-end. */
2636 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2638 /* Maximum number of operations per instruction bundle. */
2639 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2640 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2643 /* This location is used by calc_die_sizes() to keep track
2644 the offset of each DIE within the .debug_info section. */
2645 static unsigned long next_die_offset
;
2647 /* Record the root of the DIE's built for the current compilation unit. */
2648 static GTY(()) dw_die_ref single_comp_unit_die
;
2650 /* A list of type DIEs that have been separated into comdat sections. */
2651 static GTY(()) comdat_type_node
*comdat_type_list
;
2653 /* A list of DIEs with a NULL parent waiting to be relocated. */
2654 static GTY(()) limbo_die_node
*limbo_die_list
;
2656 /* A list of DIEs for which we may have to generate
2657 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2658 static GTY(()) limbo_die_node
*deferred_asm_name
;
2660 /* Filenames referenced by this compilation unit. */
2661 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
2663 /* A hash table of references to DIE's that describe declarations.
2664 The key is a DECL_UID() which is a unique number identifying each decl. */
2665 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
2667 /* A hash table of references to DIE's that describe COMMON blocks.
2668 The key is DECL_UID() ^ die_parent. */
2669 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
2671 typedef struct GTY(()) die_arg_entry_struct
{
2676 DEF_VEC_O(die_arg_entry
);
2677 DEF_VEC_ALLOC_O(die_arg_entry
,gc
);
2679 /* Node of the variable location list. */
2680 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2681 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2682 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2683 in mode of the EXPR_LIST node and first EXPR_LIST operand
2684 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2685 location or NULL for padding. For larger bitsizes,
2686 mode is 0 and first operand is a CONCAT with bitsize
2687 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2688 NULL as second operand. */
2690 const char * GTY (()) label
;
2691 struct var_loc_node
* GTY (()) next
;
2694 /* Variable location list. */
2695 struct GTY (()) var_loc_list_def
{
2696 struct var_loc_node
* GTY (()) first
;
2698 /* Pointer to the last but one or last element of the
2699 chained list. If the list is empty, both first and
2700 last are NULL, if the list contains just one node
2701 or the last node certainly is not redundant, it points
2702 to the last node, otherwise points to the last but one.
2703 Do not mark it for GC because it is marked through the chain. */
2704 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2706 /* Pointer to the last element before section switch,
2707 if NULL, either sections weren't switched or first
2708 is after section switch. */
2709 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2711 /* DECL_UID of the variable decl. */
2712 unsigned int decl_id
;
2714 typedef struct var_loc_list_def var_loc_list
;
2716 /* Call argument location list. */
2717 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2718 rtx
GTY (()) call_arg_loc_note
;
2719 const char * GTY (()) label
;
2720 tree
GTY (()) block
;
2722 rtx
GTY (()) symbol_ref
;
2723 struct call_arg_loc_node
* GTY (()) next
;
2727 /* Table of decl location linked lists. */
2728 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
2730 /* Head and tail of call_arg_loc chain. */
2731 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2732 static struct call_arg_loc_node
*call_arg_loc_last
;
2734 /* Number of call sites in the current function. */
2735 static int call_site_count
= -1;
2736 /* Number of tail call sites in the current function. */
2737 static int tail_call_site_count
= -1;
2739 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2741 static VEC (dw_die_ref
, heap
) *block_map
;
2743 /* A cached location list. */
2744 struct GTY (()) cached_dw_loc_list_def
{
2745 /* The DECL_UID of the decl that this entry describes. */
2746 unsigned int decl_id
;
2748 /* The cached location list. */
2749 dw_loc_list_ref loc_list
;
2751 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2753 /* Table of cached location lists. */
2754 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
2756 /* A pointer to the base of a list of references to DIE's that
2757 are uniquely identified by their tag, presence/absence of
2758 children DIE's, and list of attribute/value pairs. */
2759 static GTY((length ("abbrev_die_table_allocated")))
2760 dw_die_ref
*abbrev_die_table
;
2762 /* Number of elements currently allocated for abbrev_die_table. */
2763 static GTY(()) unsigned abbrev_die_table_allocated
;
2765 /* Number of elements in type_die_table currently in use. */
2766 static GTY(()) unsigned abbrev_die_table_in_use
;
2768 /* Size (in elements) of increments by which we may expand the
2769 abbrev_die_table. */
2770 #define ABBREV_DIE_TABLE_INCREMENT 256
2772 /* A global counter for generating labels for line number data. */
2773 static unsigned int line_info_label_num
;
2775 /* The current table to which we should emit line number information
2776 for the current function. This will be set up at the beginning of
2777 assembly for the function. */
2778 static dw_line_info_table
*cur_line_info_table
;
2780 /* The two default tables of line number info. */
2781 static GTY(()) dw_line_info_table
*text_section_line_info
;
2782 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2784 /* The set of all non-default tables of line number info. */
2785 static GTY(()) VEC (dw_line_info_table_p
, gc
) *separate_line_info
;
2787 /* A flag to tell pubnames/types export if there is an info section to
2789 static bool info_section_emitted
;
2791 /* A pointer to the base of a table that contains a list of publicly
2792 accessible names. */
2793 static GTY (()) VEC (pubname_entry
, gc
) * pubname_table
;
2795 /* A pointer to the base of a table that contains a list of publicly
2796 accessible types. */
2797 static GTY (()) VEC (pubname_entry
, gc
) * pubtype_table
;
2799 /* A pointer to the base of a table that contains a list of macro
2800 defines/undefines (and file start/end markers). */
2801 static GTY (()) VEC (macinfo_entry
, gc
) * macinfo_table
;
2803 /* True if .debug_macinfo or .debug_macros section is going to be
2805 #define have_macinfo \
2806 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2807 && !VEC_empty (macinfo_entry, macinfo_table))
2809 /* Array of dies for which we should generate .debug_ranges info. */
2810 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2812 /* Number of elements currently allocated for ranges_table. */
2813 static GTY(()) unsigned ranges_table_allocated
;
2815 /* Number of elements in ranges_table currently in use. */
2816 static GTY(()) unsigned ranges_table_in_use
;
2818 /* Array of pairs of labels referenced in ranges_table. */
2819 static GTY ((length ("ranges_by_label_allocated")))
2820 dw_ranges_by_label_ref ranges_by_label
;
2822 /* Number of elements currently allocated for ranges_by_label. */
2823 static GTY(()) unsigned ranges_by_label_allocated
;
2825 /* Number of elements in ranges_by_label currently in use. */
2826 static GTY(()) unsigned ranges_by_label_in_use
;
2828 /* Size (in elements) of increments by which we may expand the
2830 #define RANGES_TABLE_INCREMENT 64
2832 /* Whether we have location lists that need outputting */
2833 static GTY(()) bool have_location_lists
;
2835 /* Unique label counter. */
2836 static GTY(()) unsigned int loclabel_num
;
2838 /* Unique label counter for point-of-call tables. */
2839 static GTY(()) unsigned int poc_label_num
;
2841 /* Record whether the function being analyzed contains inlined functions. */
2842 static int current_function_has_inlines
;
2844 /* The last file entry emitted by maybe_emit_file(). */
2845 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
2847 /* Number of internal labels generated by gen_internal_sym(). */
2848 static GTY(()) int label_num
;
2850 /* Cached result of previous call to lookup_filename. */
2851 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
2853 static GTY(()) VEC(die_arg_entry
,gc
) *tmpl_value_parm_die_table
;
2855 /* Instances of generic types for which we need to generate debug
2856 info that describe their generic parameters and arguments. That
2857 generation needs to happen once all types are properly laid out so
2858 we do it at the end of compilation. */
2859 static GTY(()) VEC(tree
,gc
) *generic_type_instances
;
2861 /* Offset from the "steady-state frame pointer" to the frame base,
2862 within the current function. */
2863 static HOST_WIDE_INT frame_pointer_fb_offset
;
2864 static bool frame_pointer_fb_offset_valid
;
2866 static VEC (dw_die_ref
, heap
) *base_types
;
2868 /* Forward declarations for functions defined in this file. */
2870 static int is_pseudo_reg (const_rtx
);
2871 static tree
type_main_variant (tree
);
2872 static int is_tagged_type (const_tree
);
2873 static const char *dwarf_tag_name (unsigned);
2874 static const char *dwarf_attr_name (unsigned);
2875 static const char *dwarf_form_name (unsigned);
2876 static tree
decl_ultimate_origin (const_tree
);
2877 static tree
decl_class_context (tree
);
2878 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
2879 static inline enum dw_val_class
AT_class (dw_attr_ref
);
2880 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
2881 static inline unsigned AT_flag (dw_attr_ref
);
2882 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
2883 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
2884 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
2885 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
2886 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
2887 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2888 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
2889 unsigned int, unsigned char *);
2890 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
2891 static hashval_t
debug_str_do_hash (const void *);
2892 static int debug_str_eq (const void *, const void *);
2893 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
2894 static inline const char *AT_string (dw_attr_ref
);
2895 static enum dwarf_form
AT_string_form (dw_attr_ref
);
2896 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
2897 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
2898 static inline dw_die_ref
AT_ref (dw_attr_ref
);
2899 static inline int AT_ref_external (dw_attr_ref
);
2900 static inline void set_AT_ref_external (dw_attr_ref
, int);
2901 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
2902 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
2903 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
2904 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
2906 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
2907 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
2908 static inline rtx
AT_addr (dw_attr_ref
);
2909 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
2910 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2911 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2912 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
2913 unsigned HOST_WIDE_INT
);
2914 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
2916 static inline const char *AT_lbl (dw_attr_ref
);
2917 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
2918 static const char *get_AT_low_pc (dw_die_ref
);
2919 static const char *get_AT_hi_pc (dw_die_ref
);
2920 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
2921 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
2922 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
2923 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
2924 static bool is_cxx (void);
2925 static bool is_fortran (void);
2926 static bool is_ada (void);
2927 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
2928 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
2929 static void add_child_die (dw_die_ref
, dw_die_ref
);
2930 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
2931 static dw_die_ref
lookup_type_die (tree
);
2932 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
2933 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
2934 static void equate_type_number_to_die (tree
, dw_die_ref
);
2935 static hashval_t
decl_die_table_hash (const void *);
2936 static int decl_die_table_eq (const void *, const void *);
2937 static dw_die_ref
lookup_decl_die (tree
);
2938 static hashval_t
common_block_die_table_hash (const void *);
2939 static int common_block_die_table_eq (const void *, const void *);
2940 static hashval_t
decl_loc_table_hash (const void *);
2941 static int decl_loc_table_eq (const void *, const void *);
2942 static var_loc_list
*lookup_decl_loc (const_tree
);
2943 static void equate_decl_number_to_die (tree
, dw_die_ref
);
2944 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
2945 static void print_spaces (FILE *);
2946 static void print_die (dw_die_ref
, FILE *);
2947 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
2948 static dw_die_ref
pop_compile_unit (dw_die_ref
);
2949 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
2950 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
2951 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
2952 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
2953 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
2954 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
2955 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
2956 struct md5_ctx
*, int *);
2957 struct checksum_attributes
;
2958 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
2959 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
2960 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
2961 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
2962 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
2963 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
2964 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
2965 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
2966 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
2967 static void compute_section_prefix (dw_die_ref
);
2968 static int is_type_die (dw_die_ref
);
2969 static int is_comdat_die (dw_die_ref
);
2970 static int is_symbol_die (dw_die_ref
);
2971 static void assign_symbol_names (dw_die_ref
);
2972 static void break_out_includes (dw_die_ref
);
2973 static int is_declaration_die (dw_die_ref
);
2974 static int should_move_die_to_comdat (dw_die_ref
);
2975 static dw_die_ref
clone_as_declaration (dw_die_ref
);
2976 static dw_die_ref
clone_die (dw_die_ref
);
2977 static dw_die_ref
clone_tree (dw_die_ref
);
2978 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
2979 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
2980 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
2981 static dw_die_ref
generate_skeleton (dw_die_ref
);
2982 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
2985 static void break_out_comdat_types (dw_die_ref
);
2986 static dw_die_ref
copy_ancestor_tree (dw_die_ref
, dw_die_ref
, htab_t
);
2987 static void copy_decls_walk (dw_die_ref
, dw_die_ref
, htab_t
);
2988 static void copy_decls_for_unworthy_types (dw_die_ref
);
2990 static hashval_t
htab_cu_hash (const void *);
2991 static int htab_cu_eq (const void *, const void *);
2992 static void htab_cu_del (void *);
2993 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
2994 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
2995 static void add_sibling_attributes (dw_die_ref
);
2996 static void build_abbrev_table (dw_die_ref
, htab_t
);
2997 static void output_location_lists (dw_die_ref
);
2998 static int constant_size (unsigned HOST_WIDE_INT
);
2999 static unsigned long size_of_die (dw_die_ref
);
3000 static void calc_die_sizes (dw_die_ref
);
3001 static void calc_base_type_die_sizes (void);
3002 static void mark_dies (dw_die_ref
);
3003 static void unmark_dies (dw_die_ref
);
3004 static void unmark_all_dies (dw_die_ref
);
3005 static unsigned long size_of_pubnames (VEC (pubname_entry
,gc
) *);
3006 static unsigned long size_of_aranges (void);
3007 static enum dwarf_form
value_format (dw_attr_ref
);
3008 static void output_value_format (dw_attr_ref
);
3009 static void output_abbrev_section (void);
3010 static void output_die_symbol (dw_die_ref
);
3011 static void output_die (dw_die_ref
);
3012 static void output_compilation_unit_header (void);
3013 static void output_comp_unit (dw_die_ref
, int);
3014 static void output_comdat_type_unit (comdat_type_node
*);
3015 static const char *dwarf2_name (tree
, int);
3016 static void add_pubname (tree
, dw_die_ref
);
3017 static void add_enumerator_pubname (const char *, dw_die_ref
);
3018 static void add_pubname_string (const char *, dw_die_ref
);
3019 static void add_pubtype (tree
, dw_die_ref
);
3020 static void output_pubnames (VEC (pubname_entry
,gc
) *);
3021 static void output_aranges (unsigned long);
3022 static unsigned int add_ranges_num (int);
3023 static unsigned int add_ranges (const_tree
);
3024 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3026 static void output_ranges (void);
3027 static dw_line_info_table
*new_line_info_table (void);
3028 static void output_line_info (void);
3029 static void output_file_names (void);
3030 static dw_die_ref
base_type_die (tree
);
3031 static int is_base_type (tree
);
3032 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3033 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3034 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3035 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3036 static int type_is_enum (const_tree
);
3037 static unsigned int dbx_reg_number (const_rtx
);
3038 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3039 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3040 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3041 enum var_init_status
);
3042 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3043 enum var_init_status
);
3044 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3045 enum var_init_status
);
3046 static int is_based_loc (const_rtx
);
3047 static int resolve_one_addr (rtx
*, void *);
3048 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3049 enum var_init_status
);
3050 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
3051 enum var_init_status
);
3052 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3053 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3054 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3055 static tree
field_type (const_tree
);
3056 static unsigned int simple_type_align_in_bits (const_tree
);
3057 static unsigned int simple_decl_align_in_bits (const_tree
);
3058 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3059 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3060 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3062 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3063 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3064 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3065 static void insert_double (double_int
, unsigned char *);
3066 static void insert_float (const_rtx
, unsigned char *);
3067 static rtx
rtl_for_decl_location (tree
);
3068 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3069 enum dwarf_attribute
);
3070 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3071 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3072 static void add_name_attribute (dw_die_ref
, const char *);
3073 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3074 static void add_comp_dir_attribute (dw_die_ref
);
3075 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3076 static void add_subscript_info (dw_die_ref
, tree
, bool);
3077 static void add_byte_size_attribute (dw_die_ref
, tree
);
3078 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3079 static void add_bit_size_attribute (dw_die_ref
, tree
);
3080 static void add_prototyped_attribute (dw_die_ref
, tree
);
3081 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3082 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3083 static void add_src_coords_attributes (dw_die_ref
, tree
);
3084 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3085 static void push_decl_scope (tree
);
3086 static void pop_decl_scope (void);
3087 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3088 static inline int local_scope_p (dw_die_ref
);
3089 static inline int class_scope_p (dw_die_ref
);
3090 static inline int class_or_namespace_scope_p (dw_die_ref
);
3091 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3092 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3093 static const char *type_tag (const_tree
);
3094 static tree
member_declared_type (const_tree
);
3096 static const char *decl_start_label (tree
);
3098 static void gen_array_type_die (tree
, dw_die_ref
);
3099 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3101 static void gen_entry_point_die (tree
, dw_die_ref
);
3103 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3104 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3105 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3106 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3107 static void gen_formal_types_die (tree
, dw_die_ref
);
3108 static void gen_subprogram_die (tree
, dw_die_ref
);
3109 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3110 static void gen_const_die (tree
, dw_die_ref
);
3111 static void gen_label_die (tree
, dw_die_ref
);
3112 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3113 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3114 static void gen_field_die (tree
, dw_die_ref
);
3115 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3116 static dw_die_ref
gen_compile_unit_die (const char *);
3117 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3118 static void gen_member_die (tree
, dw_die_ref
);
3119 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3120 enum debug_info_usage
);
3121 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3122 static void gen_typedef_die (tree
, dw_die_ref
);
3123 static void gen_type_die (tree
, dw_die_ref
);
3124 static void gen_block_die (tree
, dw_die_ref
, int);
3125 static void decls_for_scope (tree
, dw_die_ref
, int);
3126 static inline int is_redundant_typedef (const_tree
);
3127 static bool is_naming_typedef_decl (const_tree
);
3128 static inline dw_die_ref
get_context_die (tree
);
3129 static void gen_namespace_die (tree
, dw_die_ref
);
3130 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3131 static dw_die_ref
force_decl_die (tree
);
3132 static dw_die_ref
force_type_die (tree
);
3133 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3134 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3135 static struct dwarf_file_data
* lookup_filename (const char *);
3136 static void retry_incomplete_types (void);
3137 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3138 static void gen_generic_params_dies (tree
);
3139 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3140 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3141 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3142 static int file_info_cmp (const void *, const void *);
3143 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3144 const char *, const char *);
3145 static void output_loc_list (dw_loc_list_ref
);
3146 static char *gen_internal_sym (const char *);
3147 static bool want_pubnames (void);
3149 static void prune_unmark_dies (dw_die_ref
);
3150 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3151 static void prune_unused_types_mark (dw_die_ref
, int);
3152 static void prune_unused_types_walk (dw_die_ref
);
3153 static void prune_unused_types_walk_attribs (dw_die_ref
);
3154 static void prune_unused_types_prune (dw_die_ref
);
3155 static void prune_unused_types (void);
3156 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3157 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3158 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3159 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3160 const char *, const char *);
3161 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3162 static void gen_remaining_tmpl_value_param_die_attribute (void);
3163 static bool generic_type_p (tree
);
3164 static void schedule_generic_params_dies_gen (tree t
);
3165 static void gen_scheduled_generic_parms_dies (void);
3167 /* Section names used to hold DWARF debugging information. */
3168 #ifndef DEBUG_INFO_SECTION
3169 #define DEBUG_INFO_SECTION ".debug_info"
3171 #ifndef DEBUG_ABBREV_SECTION
3172 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3174 #ifndef DEBUG_ARANGES_SECTION
3175 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3177 #ifndef DEBUG_MACINFO_SECTION
3178 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3180 #ifndef DEBUG_MACRO_SECTION
3181 #define DEBUG_MACRO_SECTION ".debug_macro"
3183 #ifndef DEBUG_LINE_SECTION
3184 #define DEBUG_LINE_SECTION ".debug_line"
3186 #ifndef DEBUG_LOC_SECTION
3187 #define DEBUG_LOC_SECTION ".debug_loc"
3189 #ifndef DEBUG_PUBNAMES_SECTION
3190 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3192 #ifndef DEBUG_PUBTYPES_SECTION
3193 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
3195 #ifndef DEBUG_STR_SECTION
3196 #define DEBUG_STR_SECTION ".debug_str"
3198 #ifndef DEBUG_RANGES_SECTION
3199 #define DEBUG_RANGES_SECTION ".debug_ranges"
3202 /* Standard ELF section names for compiled code and data. */
3203 #ifndef TEXT_SECTION_NAME
3204 #define TEXT_SECTION_NAME ".text"
3207 /* Section flags for .debug_str section. */
3208 #define DEBUG_STR_SECTION_FLAGS \
3209 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3210 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3213 /* Labels we insert at beginning sections we can reference instead of
3214 the section names themselves. */
3216 #ifndef TEXT_SECTION_LABEL
3217 #define TEXT_SECTION_LABEL "Ltext"
3219 #ifndef COLD_TEXT_SECTION_LABEL
3220 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3222 #ifndef DEBUG_LINE_SECTION_LABEL
3223 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3225 #ifndef DEBUG_INFO_SECTION_LABEL
3226 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3228 #ifndef DEBUG_ABBREV_SECTION_LABEL
3229 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3231 #ifndef DEBUG_LOC_SECTION_LABEL
3232 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3234 #ifndef DEBUG_RANGES_SECTION_LABEL
3235 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3237 #ifndef DEBUG_MACINFO_SECTION_LABEL
3238 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3240 #ifndef DEBUG_MACRO_SECTION_LABEL
3241 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3245 /* Definitions of defaults for formats and names of various special
3246 (artificial) labels which may be generated within this file (when the -g
3247 options is used and DWARF2_DEBUGGING_INFO is in effect.
3248 If necessary, these may be overridden from within the tm.h file, but
3249 typically, overriding these defaults is unnecessary. */
3251 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3252 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3253 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3254 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3255 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3256 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3257 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3258 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3259 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3260 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3262 #ifndef TEXT_END_LABEL
3263 #define TEXT_END_LABEL "Letext"
3265 #ifndef COLD_END_LABEL
3266 #define COLD_END_LABEL "Letext_cold"
3268 #ifndef BLOCK_BEGIN_LABEL
3269 #define BLOCK_BEGIN_LABEL "LBB"
3271 #ifndef BLOCK_END_LABEL
3272 #define BLOCK_END_LABEL "LBE"
3274 #ifndef LINE_CODE_LABEL
3275 #define LINE_CODE_LABEL "LM"
3279 /* Return the root of the DIE's built for the current compilation unit. */
3281 comp_unit_die (void)
3283 if (!single_comp_unit_die
)
3284 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3285 return single_comp_unit_die
;
3288 /* We allow a language front-end to designate a function that is to be
3289 called to "demangle" any name before it is put into a DIE. */
3291 static const char *(*demangle_name_func
) (const char *);
3294 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3296 demangle_name_func
= func
;
3299 /* Test if rtl node points to a pseudo register. */
3302 is_pseudo_reg (const_rtx rtl
)
3304 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3305 || (GET_CODE (rtl
) == SUBREG
3306 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3309 /* Return a reference to a type, with its const and volatile qualifiers
3313 type_main_variant (tree type
)
3315 type
= TYPE_MAIN_VARIANT (type
);
3317 /* ??? There really should be only one main variant among any group of
3318 variants of a given type (and all of the MAIN_VARIANT values for all
3319 members of the group should point to that one type) but sometimes the C
3320 front-end messes this up for array types, so we work around that bug
3322 if (TREE_CODE (type
) == ARRAY_TYPE
)
3323 while (type
!= TYPE_MAIN_VARIANT (type
))
3324 type
= TYPE_MAIN_VARIANT (type
);
3329 /* Return nonzero if the given type node represents a tagged type. */
3332 is_tagged_type (const_tree type
)
3334 enum tree_code code
= TREE_CODE (type
);
3336 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3337 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3340 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3343 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3345 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3348 /* Return die_offset of a DIE reference to a base type. */
3350 static unsigned long int
3351 get_base_type_offset (dw_die_ref ref
)
3353 if (ref
->die_offset
)
3354 return ref
->die_offset
;
3355 if (comp_unit_die ()->die_abbrev
)
3357 calc_base_type_die_sizes ();
3358 gcc_assert (ref
->die_offset
);
3360 return ref
->die_offset
;
3363 /* Return die_offset of a DIE reference other than base type. */
3365 static unsigned long int
3366 get_ref_die_offset (dw_die_ref ref
)
3368 gcc_assert (ref
->die_offset
);
3369 return ref
->die_offset
;
3372 /* Convert a DIE tag into its string name. */
3375 dwarf_tag_name (unsigned int tag
)
3377 const char *name
= get_DW_TAG_name (tag
);
3382 return "DW_TAG_<unknown>";
3385 /* Convert a DWARF attribute code into its string name. */
3388 dwarf_attr_name (unsigned int attr
)
3394 #if VMS_DEBUGGING_INFO
3395 case DW_AT_HP_prologue
:
3396 return "DW_AT_HP_prologue";
3398 case DW_AT_MIPS_loop_unroll_factor
:
3399 return "DW_AT_MIPS_loop_unroll_factor";
3402 #if VMS_DEBUGGING_INFO
3403 case DW_AT_HP_epilogue
:
3404 return "DW_AT_HP_epilogue";
3406 case DW_AT_MIPS_stride
:
3407 return "DW_AT_MIPS_stride";
3411 name
= get_DW_AT_name (attr
);
3416 return "DW_AT_<unknown>";
3419 /* Convert a DWARF value form code into its string name. */
3422 dwarf_form_name (unsigned int form
)
3424 const char *name
= get_DW_FORM_name (form
);
3429 return "DW_FORM_<unknown>";
3432 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3433 instance of an inlined instance of a decl which is local to an inline
3434 function, so we have to trace all of the way back through the origin chain
3435 to find out what sort of node actually served as the original seed for the
3439 decl_ultimate_origin (const_tree decl
)
3441 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3444 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3445 nodes in the function to point to themselves; ignore that if
3446 we're trying to output the abstract instance of this function. */
3447 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3450 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3451 most distant ancestor, this should never happen. */
3452 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3454 return DECL_ABSTRACT_ORIGIN (decl
);
3457 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3458 of a virtual function may refer to a base class, so we check the 'this'
3462 decl_class_context (tree decl
)
3464 tree context
= NULL_TREE
;
3466 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3467 context
= DECL_CONTEXT (decl
);
3469 context
= TYPE_MAIN_VARIANT
3470 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3472 if (context
&& !TYPE_P (context
))
3473 context
= NULL_TREE
;
3478 /* Add an attribute/value pair to a DIE. */
3481 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3483 /* Maybe this should be an assert? */
3487 if (die
->die_attr
== NULL
)
3488 die
->die_attr
= VEC_alloc (dw_attr_node
, gc
, 1);
3489 VEC_safe_push (dw_attr_node
, gc
, die
->die_attr
, *attr
);
3492 static inline enum dw_val_class
3493 AT_class (dw_attr_ref a
)
3495 return a
->dw_attr_val
.val_class
;
3498 /* Add a flag value attribute to a DIE. */
3501 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3505 attr
.dw_attr
= attr_kind
;
3506 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3507 attr
.dw_attr_val
.v
.val_flag
= flag
;
3508 add_dwarf_attr (die
, &attr
);
3511 static inline unsigned
3512 AT_flag (dw_attr_ref a
)
3514 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3515 return a
->dw_attr_val
.v
.val_flag
;
3518 /* Add a signed integer attribute value to a DIE. */
3521 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3525 attr
.dw_attr
= attr_kind
;
3526 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3527 attr
.dw_attr_val
.v
.val_int
= int_val
;
3528 add_dwarf_attr (die
, &attr
);
3531 static inline HOST_WIDE_INT
3532 AT_int (dw_attr_ref a
)
3534 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3535 return a
->dw_attr_val
.v
.val_int
;
3538 /* Add an unsigned integer attribute value to a DIE. */
3541 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3542 unsigned HOST_WIDE_INT unsigned_val
)
3546 attr
.dw_attr
= attr_kind
;
3547 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3548 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3549 add_dwarf_attr (die
, &attr
);
3552 static inline unsigned HOST_WIDE_INT
3553 AT_unsigned (dw_attr_ref a
)
3555 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3556 return a
->dw_attr_val
.v
.val_unsigned
;
3559 /* Add an unsigned double integer attribute value to a DIE. */
3562 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3563 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3567 attr
.dw_attr
= attr_kind
;
3568 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3569 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3570 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3571 add_dwarf_attr (die
, &attr
);
3574 /* Add a floating point attribute value to a DIE and return it. */
3577 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3578 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3582 attr
.dw_attr
= attr_kind
;
3583 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3584 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3585 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3586 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3587 add_dwarf_attr (die
, &attr
);
3590 /* Add an 8-byte data attribute value to a DIE. */
3593 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3594 unsigned char data8
[8])
3598 attr
.dw_attr
= attr_kind
;
3599 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3600 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3601 add_dwarf_attr (die
, &attr
);
3604 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. */
3606 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
)
3610 attr
.dw_attr
= DW_AT_low_pc
;
3611 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3612 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_low
);
3613 add_dwarf_attr (die
, &attr
);
3615 attr
.dw_attr
= DW_AT_high_pc
;
3616 if (dwarf_version
< 4)
3617 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3619 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3620 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_high
);
3621 add_dwarf_attr (die
, &attr
);
3624 /* Hash and equality functions for debug_str_hash. */
3627 debug_str_do_hash (const void *x
)
3629 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
3633 debug_str_eq (const void *x1
, const void *x2
)
3635 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
3636 (const char *)x2
) == 0;
3639 /* Add STR to the indirect string hash table. */
3641 static struct indirect_string_node
*
3642 find_AT_string (const char *str
)
3644 struct indirect_string_node
*node
;
3647 if (! debug_str_hash
)
3648 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
3649 debug_str_eq
, NULL
);
3651 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
3652 htab_hash_string (str
), INSERT
);
3655 node
= ggc_alloc_cleared_indirect_string_node ();
3656 node
->str
= ggc_strdup (str
);
3660 node
= (struct indirect_string_node
*) *slot
;
3666 /* Add a string attribute value to a DIE. */
3669 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
3672 struct indirect_string_node
*node
;
3674 node
= find_AT_string (str
);
3676 attr
.dw_attr
= attr_kind
;
3677 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
3678 attr
.dw_attr_val
.v
.val_str
= node
;
3679 add_dwarf_attr (die
, &attr
);
3682 static inline const char *
3683 AT_string (dw_attr_ref a
)
3685 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3686 return a
->dw_attr_val
.v
.val_str
->str
;
3689 /* Find out whether a string should be output inline in DIE
3690 or out-of-line in .debug_str section. */
3692 static enum dwarf_form
3693 AT_string_form (dw_attr_ref a
)
3695 struct indirect_string_node
*node
;
3699 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3701 node
= a
->dw_attr_val
.v
.val_str
;
3705 len
= strlen (node
->str
) + 1;
3707 /* If the string is shorter or equal to the size of the reference, it is
3708 always better to put it inline. */
3709 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
3710 return node
->form
= DW_FORM_string
;
3712 /* If we cannot expect the linker to merge strings in .debug_str
3713 section, only put it into .debug_str if it is worth even in this
3715 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
3716 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
3717 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
3718 return node
->form
= DW_FORM_string
;
3720 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
3721 ++dw2_string_counter
;
3722 node
->label
= xstrdup (label
);
3724 return node
->form
= DW_FORM_strp
;
3727 /* Add a DIE reference attribute value to a DIE. */
3730 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
3734 #ifdef ENABLE_CHECKING
3735 gcc_assert (targ_die
!= NULL
);
3737 /* With LTO we can end up trying to reference something we didn't create
3738 a DIE for. Avoid crashing later on a NULL referenced DIE. */
3739 if (targ_die
== NULL
)
3743 attr
.dw_attr
= attr_kind
;
3744 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
3745 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
3746 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
3747 add_dwarf_attr (die
, &attr
);
3750 /* Change DIE reference REF to point to NEW_DIE instead. */
3753 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
3755 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
3756 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
3757 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
3760 /* Add an AT_specification attribute to a DIE, and also make the back
3761 pointer from the specification to the definition. */
3764 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
3766 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
3767 gcc_assert (!targ_die
->die_definition
);
3768 targ_die
->die_definition
= die
;
3771 static inline dw_die_ref
3772 AT_ref (dw_attr_ref a
)
3774 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
3775 return a
->dw_attr_val
.v
.val_die_ref
.die
;
3779 AT_ref_external (dw_attr_ref a
)
3781 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
3782 return a
->dw_attr_val
.v
.val_die_ref
.external
;
3788 set_AT_ref_external (dw_attr_ref a
, int i
)
3790 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
3791 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
3794 /* Add an FDE reference attribute value to a DIE. */
3797 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
3801 attr
.dw_attr
= attr_kind
;
3802 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
3803 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
3804 add_dwarf_attr (die
, &attr
);
3807 /* Add a location description attribute value to a DIE. */
3810 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
3814 attr
.dw_attr
= attr_kind
;
3815 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
3816 attr
.dw_attr_val
.v
.val_loc
= loc
;
3817 add_dwarf_attr (die
, &attr
);
3820 static inline dw_loc_descr_ref
3821 AT_loc (dw_attr_ref a
)
3823 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
3824 return a
->dw_attr_val
.v
.val_loc
;
3828 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
3832 attr
.dw_attr
= attr_kind
;
3833 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
3834 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
3835 add_dwarf_attr (die
, &attr
);
3836 have_location_lists
= true;
3839 static inline dw_loc_list_ref
3840 AT_loc_list (dw_attr_ref a
)
3842 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
3843 return a
->dw_attr_val
.v
.val_loc_list
;
3846 static inline dw_loc_list_ref
*
3847 AT_loc_list_ptr (dw_attr_ref a
)
3849 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
3850 return &a
->dw_attr_val
.v
.val_loc_list
;
3853 /* Add an address constant attribute value to a DIE. */
3856 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
3860 attr
.dw_attr
= attr_kind
;
3861 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
3862 attr
.dw_attr_val
.v
.val_addr
= addr
;
3863 add_dwarf_attr (die
, &attr
);
3866 /* Get the RTX from to an address DIE attribute. */
3869 AT_addr (dw_attr_ref a
)
3871 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
3872 return a
->dw_attr_val
.v
.val_addr
;
3875 /* Add a file attribute value to a DIE. */
3878 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3879 struct dwarf_file_data
*fd
)
3883 attr
.dw_attr
= attr_kind
;
3884 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
3885 attr
.dw_attr_val
.v
.val_file
= fd
;
3886 add_dwarf_attr (die
, &attr
);
3889 /* Get the dwarf_file_data from a file DIE attribute. */
3891 static inline struct dwarf_file_data
*
3892 AT_file (dw_attr_ref a
)
3894 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
3895 return a
->dw_attr_val
.v
.val_file
;
3898 /* Add a vms delta attribute value to a DIE. */
3901 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3902 const char *lbl1
, const char *lbl2
)
3906 attr
.dw_attr
= attr_kind
;
3907 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
3908 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
3909 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
3910 add_dwarf_attr (die
, &attr
);
3913 /* Add a label identifier attribute value to a DIE. */
3916 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
3920 attr
.dw_attr
= attr_kind
;
3921 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3922 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
3923 add_dwarf_attr (die
, &attr
);
3926 /* Add a section offset attribute value to a DIE, an offset into the
3927 debug_line section. */
3930 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3935 attr
.dw_attr
= attr_kind
;
3936 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
3937 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
3938 add_dwarf_attr (die
, &attr
);
3941 /* Add a section offset attribute value to a DIE, an offset into the
3942 debug_macinfo section. */
3945 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3950 attr
.dw_attr
= attr_kind
;
3951 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
3952 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
3953 add_dwarf_attr (die
, &attr
);
3956 /* Add an offset attribute value to a DIE. */
3959 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3960 unsigned HOST_WIDE_INT offset
)
3964 attr
.dw_attr
= attr_kind
;
3965 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
3966 attr
.dw_attr_val
.v
.val_offset
= offset
;
3967 add_dwarf_attr (die
, &attr
);
3970 /* Add an range_list attribute value to a DIE. */
3973 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3974 long unsigned int offset
)
3978 attr
.dw_attr
= attr_kind
;
3979 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
3980 attr
.dw_attr_val
.v
.val_offset
= offset
;
3981 add_dwarf_attr (die
, &attr
);
3984 /* Return the start label of a delta attribute. */
3986 static inline const char *
3987 AT_vms_delta1 (dw_attr_ref a
)
3989 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
3990 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
3993 /* Return the end label of a delta attribute. */
3995 static inline const char *
3996 AT_vms_delta2 (dw_attr_ref a
)
3998 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
3999 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4002 static inline const char *
4003 AT_lbl (dw_attr_ref a
)
4005 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4006 || AT_class (a
) == dw_val_class_lineptr
4007 || AT_class (a
) == dw_val_class_macptr
4008 || AT_class (a
) == dw_val_class_high_pc
));
4009 return a
->dw_attr_val
.v
.val_lbl_id
;
4012 /* Get the attribute of type attr_kind. */
4015 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4019 dw_die_ref spec
= NULL
;
4024 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
4025 if (a
->dw_attr
== attr_kind
)
4027 else if (a
->dw_attr
== DW_AT_specification
4028 || a
->dw_attr
== DW_AT_abstract_origin
)
4032 return get_AT (spec
, attr_kind
);
4037 /* Returns the parent of the declaration of DIE. */
4040 get_die_parent (dw_die_ref die
)
4047 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4048 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4051 return die
->die_parent
;
4054 /* Return the "low pc" attribute value, typically associated with a subprogram
4055 DIE. Return null if the "low pc" attribute is either not present, or if it
4056 cannot be represented as an assembler label identifier. */
4058 static inline const char *
4059 get_AT_low_pc (dw_die_ref die
)
4061 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4063 return a
? AT_lbl (a
) : NULL
;
4066 /* Return the "high pc" attribute value, typically associated with a subprogram
4067 DIE. Return null if the "high pc" attribute is either not present, or if it
4068 cannot be represented as an assembler label identifier. */
4070 static inline const char *
4071 get_AT_hi_pc (dw_die_ref die
)
4073 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4075 return a
? AT_lbl (a
) : NULL
;
4078 /* Return the value of the string attribute designated by ATTR_KIND, or
4079 NULL if it is not present. */
4081 static inline const char *
4082 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4084 dw_attr_ref a
= get_AT (die
, attr_kind
);
4086 return a
? AT_string (a
) : NULL
;
4089 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4090 if it is not present. */
4093 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4095 dw_attr_ref a
= get_AT (die
, attr_kind
);
4097 return a
? AT_flag (a
) : 0;
4100 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4101 if it is not present. */
4103 static inline unsigned
4104 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4106 dw_attr_ref a
= get_AT (die
, attr_kind
);
4108 return a
? AT_unsigned (a
) : 0;
4111 static inline dw_die_ref
4112 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4114 dw_attr_ref a
= get_AT (die
, attr_kind
);
4116 return a
? AT_ref (a
) : NULL
;
4119 static inline struct dwarf_file_data
*
4120 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4122 dw_attr_ref a
= get_AT (die
, attr_kind
);
4124 return a
? AT_file (a
) : NULL
;
4127 /* Return TRUE if the language is C++. */
4132 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4134 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4137 /* Return TRUE if the language is Fortran. */
4142 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4144 return (lang
== DW_LANG_Fortran77
4145 || lang
== DW_LANG_Fortran90
4146 || lang
== DW_LANG_Fortran95
);
4149 /* Return TRUE if the language is Ada. */
4154 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4156 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4159 /* Remove the specified attribute if present. */
4162 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4170 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
4171 if (a
->dw_attr
== attr_kind
)
4173 if (AT_class (a
) == dw_val_class_str
)
4174 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4175 a
->dw_attr_val
.v
.val_str
->refcount
--;
4177 /* VEC_ordered_remove should help reduce the number of abbrevs
4179 VEC_ordered_remove (dw_attr_node
, die
->die_attr
, ix
);
4184 /* Remove CHILD from its parent. PREV must have the property that
4185 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4188 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4190 gcc_assert (child
->die_parent
== prev
->die_parent
);
4191 gcc_assert (prev
->die_sib
== child
);
4194 gcc_assert (child
->die_parent
->die_child
== child
);
4198 prev
->die_sib
= child
->die_sib
;
4199 if (child
->die_parent
->die_child
== child
)
4200 child
->die_parent
->die_child
= prev
;
4203 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4204 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4207 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4209 dw_die_ref parent
= old_child
->die_parent
;
4211 gcc_assert (parent
== prev
->die_parent
);
4212 gcc_assert (prev
->die_sib
== old_child
);
4214 new_child
->die_parent
= parent
;
4215 if (prev
== old_child
)
4217 gcc_assert (parent
->die_child
== old_child
);
4218 new_child
->die_sib
= new_child
;
4222 prev
->die_sib
= new_child
;
4223 new_child
->die_sib
= old_child
->die_sib
;
4225 if (old_child
->die_parent
->die_child
== old_child
)
4226 old_child
->die_parent
->die_child
= new_child
;
4229 /* Move all children from OLD_PARENT to NEW_PARENT. */
4232 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4235 new_parent
->die_child
= old_parent
->die_child
;
4236 old_parent
->die_child
= NULL
;
4237 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4240 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4244 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4250 dw_die_ref prev
= c
;
4252 while (c
->die_tag
== tag
)
4254 remove_child_with_prev (c
, prev
);
4255 /* Might have removed every child. */
4256 if (c
== c
->die_sib
)
4260 } while (c
!= die
->die_child
);
4263 /* Add a CHILD_DIE as the last child of DIE. */
4266 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4268 /* FIXME this should probably be an assert. */
4269 if (! die
|| ! child_die
)
4271 gcc_assert (die
!= child_die
);
4273 child_die
->die_parent
= die
;
4276 child_die
->die_sib
= die
->die_child
->die_sib
;
4277 die
->die_child
->die_sib
= child_die
;
4280 child_die
->die_sib
= child_die
;
4281 die
->die_child
= child_die
;
4284 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4285 is the specification, to the end of PARENT's list of children.
4286 This is done by removing and re-adding it. */
4289 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4293 /* We want the declaration DIE from inside the class, not the
4294 specification DIE at toplevel. */
4295 if (child
->die_parent
!= parent
)
4297 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4303 gcc_assert (child
->die_parent
== parent
4304 || (child
->die_parent
4305 == get_AT_ref (parent
, DW_AT_specification
)));
4307 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4308 if (p
->die_sib
== child
)
4310 remove_child_with_prev (child
, p
);
4314 add_child_die (parent
, child
);
4317 /* Return a pointer to a newly created DIE node. */
4319 static inline dw_die_ref
4320 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4322 dw_die_ref die
= ggc_alloc_cleared_die_node ();
4324 die
->die_tag
= tag_value
;
4326 if (parent_die
!= NULL
)
4327 add_child_die (parent_die
, die
);
4330 limbo_die_node
*limbo_node
;
4332 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
4333 limbo_node
->die
= die
;
4334 limbo_node
->created_for
= t
;
4335 limbo_node
->next
= limbo_die_list
;
4336 limbo_die_list
= limbo_node
;
4342 /* Return the DIE associated with the given type specifier. */
4344 static inline dw_die_ref
4345 lookup_type_die (tree type
)
4347 return TYPE_SYMTAB_DIE (type
);
4350 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4351 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4352 anonymous type instead the one of the naming typedef. */
4354 static inline dw_die_ref
4355 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4358 && TREE_CODE (type
) == RECORD_TYPE
4360 && type_die
->die_tag
== DW_TAG_typedef
4361 && is_naming_typedef_decl (TYPE_NAME (type
)))
4362 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4366 /* Like lookup_type_die, but if type is an anonymous type named by a
4367 typedef[1], return the DIE of the anonymous type instead the one of
4368 the naming typedef. This is because in gen_typedef_die, we did
4369 equate the anonymous struct named by the typedef with the DIE of
4370 the naming typedef. So by default, lookup_type_die on an anonymous
4371 struct yields the DIE of the naming typedef.
4373 [1]: Read the comment of is_naming_typedef_decl to learn about what
4374 a naming typedef is. */
4376 static inline dw_die_ref
4377 lookup_type_die_strip_naming_typedef (tree type
)
4379 dw_die_ref die
= lookup_type_die (type
);
4380 return strip_naming_typedef (type
, die
);
4383 /* Equate a DIE to a given type specifier. */
4386 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
4388 TYPE_SYMTAB_DIE (type
) = type_die
;
4391 /* Returns a hash value for X (which really is a die_struct). */
4394 decl_die_table_hash (const void *x
)
4396 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
4399 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
4402 decl_die_table_eq (const void *x
, const void *y
)
4404 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4407 /* Return the DIE associated with a given declaration. */
4409 static inline dw_die_ref
4410 lookup_decl_die (tree decl
)
4412 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
4415 /* Returns a hash value for X (which really is a var_loc_list). */
4418 decl_loc_table_hash (const void *x
)
4420 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
4423 /* Return nonzero if decl_id of var_loc_list X is the same as
4427 decl_loc_table_eq (const void *x
, const void *y
)
4429 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4432 /* Return the var_loc list associated with a given declaration. */
4434 static inline var_loc_list
*
4435 lookup_decl_loc (const_tree decl
)
4437 if (!decl_loc_table
)
4439 return (var_loc_list
*)
4440 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
4443 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
4446 cached_dw_loc_list_table_hash (const void *x
)
4448 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
4451 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
4455 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
4457 return (((const cached_dw_loc_list
*) x
)->decl_id
4458 == DECL_UID ((const_tree
) y
));
4461 /* Equate a DIE to a particular declaration. */
4464 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
4466 unsigned int decl_id
= DECL_UID (decl
);
4469 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
4471 decl_die
->decl_id
= decl_id
;
4474 /* Return how many bits covers PIECE EXPR_LIST. */
4477 decl_piece_bitsize (rtx piece
)
4479 int ret
= (int) GET_MODE (piece
);
4482 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
4483 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
4484 return INTVAL (XEXP (XEXP (piece
, 0), 0));
4487 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
4490 decl_piece_varloc_ptr (rtx piece
)
4492 if ((int) GET_MODE (piece
))
4493 return &XEXP (piece
, 0);
4495 return &XEXP (XEXP (piece
, 0), 1);
4498 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
4499 Next is the chain of following piece nodes. */
4502 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
4504 if (bitsize
<= (int) MAX_MACHINE_MODE
)
4505 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
4507 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
4512 /* Return rtx that should be stored into loc field for
4513 LOC_NOTE and BITPOS/BITSIZE. */
4516 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
4517 HOST_WIDE_INT bitsize
)
4521 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
4523 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
4528 /* This function either modifies location piece list *DEST in
4529 place (if SRC and INNER is NULL), or copies location piece list
4530 *SRC to *DEST while modifying it. Location BITPOS is modified
4531 to contain LOC_NOTE, any pieces overlapping it are removed resp.
4532 not copied and if needed some padding around it is added.
4533 When modifying in place, DEST should point to EXPR_LIST where
4534 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
4535 to the start of the whole list and INNER points to the EXPR_LIST
4536 where earlier pieces cover PIECE_BITPOS bits. */
4539 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
4540 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
4541 HOST_WIDE_INT bitsize
, rtx loc_note
)
4544 bool copy
= inner
!= NULL
;
4548 /* First copy all nodes preceding the current bitpos. */
4549 while (src
!= inner
)
4551 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
4552 decl_piece_bitsize (*src
), NULL_RTX
);
4553 dest
= &XEXP (*dest
, 1);
4554 src
= &XEXP (*src
, 1);
4557 /* Add padding if needed. */
4558 if (bitpos
!= piece_bitpos
)
4560 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
4561 copy
? NULL_RTX
: *dest
);
4562 dest
= &XEXP (*dest
, 1);
4564 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
4567 /* A piece with correct bitpos and bitsize already exist,
4568 just update the location for it and return. */
4569 *decl_piece_varloc_ptr (*dest
) = loc_note
;
4572 /* Add the piece that changed. */
4573 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
4574 dest
= &XEXP (*dest
, 1);
4575 /* Skip over pieces that overlap it. */
4576 diff
= bitpos
- piece_bitpos
+ bitsize
;
4579 while (diff
> 0 && *src
)
4582 diff
-= decl_piece_bitsize (piece
);
4584 src
= &XEXP (piece
, 1);
4587 *src
= XEXP (piece
, 1);
4588 free_EXPR_LIST_node (piece
);
4591 /* Add padding if needed. */
4592 if (diff
< 0 && *src
)
4596 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
4597 dest
= &XEXP (*dest
, 1);
4601 /* Finally copy all nodes following it. */
4604 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
4605 decl_piece_bitsize (*src
), NULL_RTX
);
4606 dest
= &XEXP (*dest
, 1);
4607 src
= &XEXP (*src
, 1);
4611 /* Add a variable location node to the linked list for DECL. */
4613 static struct var_loc_node
*
4614 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
4616 unsigned int decl_id
;
4619 struct var_loc_node
*loc
= NULL
;
4620 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
4622 if (DECL_DEBUG_EXPR_IS_FROM (decl
))
4624 tree realdecl
= DECL_DEBUG_EXPR (decl
);
4626 && (handled_component_p (realdecl
)
4627 || (TREE_CODE (realdecl
) == MEM_REF
4628 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
)))
4630 HOST_WIDE_INT maxsize
;
4633 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
4634 if (!DECL_P (innerdecl
)
4635 || DECL_IGNORED_P (innerdecl
)
4636 || TREE_STATIC (innerdecl
)
4638 || bitpos
+ bitsize
> 256
4639 || bitsize
!= maxsize
)
4645 decl_id
= DECL_UID (decl
);
4646 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
4649 temp
= ggc_alloc_cleared_var_loc_list ();
4650 temp
->decl_id
= decl_id
;
4654 temp
= (var_loc_list
*) *slot
;
4656 /* For PARM_DECLs try to keep around the original incoming value,
4657 even if that means we'll emit a zero-range .debug_loc entry. */
4659 && temp
->first
== temp
->last
4660 && TREE_CODE (decl
) == PARM_DECL
4661 && GET_CODE (temp
->first
->loc
) == NOTE
4662 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
4663 && DECL_INCOMING_RTL (decl
)
4664 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
4665 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
4666 == GET_CODE (DECL_INCOMING_RTL (decl
))
4667 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
4669 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
4670 NOTE_VAR_LOCATION_LOC (loc_note
))
4671 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
4672 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
4674 loc
= ggc_alloc_cleared_var_loc_node ();
4675 temp
->first
->next
= loc
;
4677 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
4679 else if (temp
->last
)
4681 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
4682 rtx
*piece_loc
= NULL
, last_loc_note
;
4683 int piece_bitpos
= 0;
4687 gcc_assert (last
->next
== NULL
);
4689 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
4691 piece_loc
= &last
->loc
;
4694 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
4695 if (piece_bitpos
+ cur_bitsize
> bitpos
)
4697 piece_bitpos
+= cur_bitsize
;
4698 piece_loc
= &XEXP (*piece_loc
, 1);
4702 /* TEMP->LAST here is either pointer to the last but one or
4703 last element in the chained list, LAST is pointer to the
4705 if (label
&& strcmp (last
->label
, label
) == 0)
4707 /* For SRA optimized variables if there weren't any real
4708 insns since last note, just modify the last node. */
4709 if (piece_loc
!= NULL
)
4711 adjust_piece_list (piece_loc
, NULL
, NULL
,
4712 bitpos
, piece_bitpos
, bitsize
, loc_note
);
4715 /* If the last note doesn't cover any instructions, remove it. */
4716 if (temp
->last
!= last
)
4718 temp
->last
->next
= NULL
;
4721 gcc_assert (strcmp (last
->label
, label
) != 0);
4725 gcc_assert (temp
->first
== temp
->last
4726 || (temp
->first
->next
== temp
->last
4727 && TREE_CODE (decl
) == PARM_DECL
));
4728 memset (temp
->last
, '\0', sizeof (*temp
->last
));
4729 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
4733 if (bitsize
== -1 && NOTE_P (last
->loc
))
4734 last_loc_note
= last
->loc
;
4735 else if (piece_loc
!= NULL
4736 && *piece_loc
!= NULL_RTX
4737 && piece_bitpos
== bitpos
4738 && decl_piece_bitsize (*piece_loc
) == bitsize
)
4739 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
4741 last_loc_note
= NULL_RTX
;
4742 /* If the current location is the same as the end of the list,
4743 and either both or neither of the locations is uninitialized,
4744 we have nothing to do. */
4745 if (last_loc_note
== NULL_RTX
4746 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
4747 NOTE_VAR_LOCATION_LOC (loc_note
)))
4748 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
4749 != NOTE_VAR_LOCATION_STATUS (loc_note
))
4750 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
4751 == VAR_INIT_STATUS_UNINITIALIZED
)
4752 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
4753 == VAR_INIT_STATUS_UNINITIALIZED
))))
4755 /* Add LOC to the end of list and update LAST. If the last
4756 element of the list has been removed above, reuse its
4757 memory for the new node, otherwise allocate a new one. */
4761 memset (loc
, '\0', sizeof (*loc
));
4764 loc
= ggc_alloc_cleared_var_loc_node ();
4765 if (bitsize
== -1 || piece_loc
== NULL
)
4766 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
4768 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
4769 bitpos
, piece_bitpos
, bitsize
, loc_note
);
4771 /* Ensure TEMP->LAST will point either to the new last but one
4772 element of the chain, or to the last element in it. */
4773 if (last
!= temp
->last
)
4781 loc
= ggc_alloc_cleared_var_loc_node ();
4784 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
4789 /* Keep track of the number of spaces used to indent the
4790 output of the debugging routines that print the structure of
4791 the DIE internal representation. */
4792 static int print_indent
;
4794 /* Indent the line the number of spaces given by print_indent. */
4797 print_spaces (FILE *outfile
)
4799 fprintf (outfile
, "%*s", print_indent
, "");
4802 /* Print a type signature in hex. */
4805 print_signature (FILE *outfile
, char *sig
)
4809 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
4810 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
4813 /* Print the information associated with a given DIE, and its children.
4814 This routine is a debugging aid only. */
4817 print_die (dw_die_ref die
, FILE *outfile
)
4823 print_spaces (outfile
);
4824 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
4825 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
4827 print_spaces (outfile
);
4828 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
4829 fprintf (outfile
, " offset: %ld", die
->die_offset
);
4830 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
4832 if (die
->comdat_type_p
)
4834 print_spaces (outfile
);
4835 fprintf (outfile
, " signature: ");
4836 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
4837 fprintf (outfile
, "\n");
4840 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
4842 print_spaces (outfile
);
4843 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
4845 switch (AT_class (a
))
4847 case dw_val_class_addr
:
4848 fprintf (outfile
, "address");
4850 case dw_val_class_offset
:
4851 fprintf (outfile
, "offset");
4853 case dw_val_class_loc
:
4854 fprintf (outfile
, "location descriptor");
4856 case dw_val_class_loc_list
:
4857 fprintf (outfile
, "location list -> label:%s",
4858 AT_loc_list (a
)->ll_symbol
);
4860 case dw_val_class_range_list
:
4861 fprintf (outfile
, "range list");
4863 case dw_val_class_const
:
4864 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
4866 case dw_val_class_unsigned_const
:
4867 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
4869 case dw_val_class_const_double
:
4870 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
4871 HOST_WIDE_INT_PRINT_UNSIGNED
")",
4872 a
->dw_attr_val
.v
.val_double
.high
,
4873 a
->dw_attr_val
.v
.val_double
.low
);
4875 case dw_val_class_vec
:
4876 fprintf (outfile
, "floating-point or vector constant");
4878 case dw_val_class_flag
:
4879 fprintf (outfile
, "%u", AT_flag (a
));
4881 case dw_val_class_die_ref
:
4882 if (AT_ref (a
) != NULL
)
4884 if (AT_ref (a
)->comdat_type_p
)
4886 fprintf (outfile
, "die -> signature: ");
4887 print_signature (outfile
,
4888 AT_ref (a
)->die_id
.die_type_node
->signature
);
4890 else if (AT_ref (a
)->die_id
.die_symbol
)
4891 fprintf (outfile
, "die -> label: %s",
4892 AT_ref (a
)->die_id
.die_symbol
);
4894 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
4895 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
4898 fprintf (outfile
, "die -> <null>");
4900 case dw_val_class_vms_delta
:
4901 fprintf (outfile
, "delta: @slotcount(%s-%s)",
4902 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
4904 case dw_val_class_lbl_id
:
4905 case dw_val_class_lineptr
:
4906 case dw_val_class_macptr
:
4907 case dw_val_class_high_pc
:
4908 fprintf (outfile
, "label: %s", AT_lbl (a
));
4910 case dw_val_class_str
:
4911 if (AT_string (a
) != NULL
)
4912 fprintf (outfile
, "\"%s\"", AT_string (a
));
4914 fprintf (outfile
, "<null>");
4916 case dw_val_class_file
:
4917 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
4918 AT_file (a
)->emitted_number
);
4920 case dw_val_class_data8
:
4924 for (i
= 0; i
< 8; i
++)
4925 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
4932 fprintf (outfile
, "\n");
4935 if (die
->die_child
!= NULL
)
4938 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
4941 if (print_indent
== 0)
4942 fprintf (outfile
, "\n");
4945 /* Print the information collected for a given DIE. */
4948 debug_dwarf_die (dw_die_ref die
)
4950 print_die (die
, stderr
);
4953 /* Print all DWARF information collected for the compilation unit.
4954 This routine is a debugging aid only. */
4960 print_die (comp_unit_die (), stderr
);
4963 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
4964 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
4965 DIE that marks the start of the DIEs for this include file. */
4968 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
4970 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
4971 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
4973 new_unit
->die_sib
= old_unit
;
4977 /* Close an include-file CU and reopen the enclosing one. */
4980 pop_compile_unit (dw_die_ref old_unit
)
4982 dw_die_ref new_unit
= old_unit
->die_sib
;
4984 old_unit
->die_sib
= NULL
;
4988 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
4989 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
4991 /* Calculate the checksum of a location expression. */
4994 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
4998 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5000 CHECKSUM (loc
->dw_loc_oprnd1
);
5001 CHECKSUM (loc
->dw_loc_oprnd2
);
5004 /* Calculate the checksum of an attribute. */
5007 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5009 dw_loc_descr_ref loc
;
5012 CHECKSUM (at
->dw_attr
);
5014 /* We don't care that this was compiled with a different compiler
5015 snapshot; if the output is the same, that's what matters. */
5016 if (at
->dw_attr
== DW_AT_producer
)
5019 switch (AT_class (at
))
5021 case dw_val_class_const
:
5022 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5024 case dw_val_class_unsigned_const
:
5025 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5027 case dw_val_class_const_double
:
5028 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5030 case dw_val_class_vec
:
5031 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5033 case dw_val_class_flag
:
5034 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5036 case dw_val_class_str
:
5037 CHECKSUM_STRING (AT_string (at
));
5040 case dw_val_class_addr
:
5042 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5043 CHECKSUM_STRING (XSTR (r
, 0));
5046 case dw_val_class_offset
:
5047 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5050 case dw_val_class_loc
:
5051 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5052 loc_checksum (loc
, ctx
);
5055 case dw_val_class_die_ref
:
5056 die_checksum (AT_ref (at
), ctx
, mark
);
5059 case dw_val_class_fde_ref
:
5060 case dw_val_class_vms_delta
:
5061 case dw_val_class_lbl_id
:
5062 case dw_val_class_lineptr
:
5063 case dw_val_class_macptr
:
5064 case dw_val_class_high_pc
:
5067 case dw_val_class_file
:
5068 CHECKSUM_STRING (AT_file (at
)->filename
);
5071 case dw_val_class_data8
:
5072 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5080 /* Calculate the checksum of a DIE. */
5083 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5089 /* To avoid infinite recursion. */
5092 CHECKSUM (die
->die_mark
);
5095 die
->die_mark
= ++(*mark
);
5097 CHECKSUM (die
->die_tag
);
5099 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
5100 attr_checksum (a
, ctx
, mark
);
5102 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5106 #undef CHECKSUM_STRING
5108 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5109 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5110 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5111 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5112 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5113 #define CHECKSUM_ATTR(FOO) \
5114 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5116 /* Calculate the checksum of a number in signed LEB128 format. */
5119 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5126 byte
= (value
& 0x7f);
5128 more
= !((value
== 0 && (byte
& 0x40) == 0)
5129 || (value
== -1 && (byte
& 0x40) != 0));
5138 /* Calculate the checksum of a number in unsigned LEB128 format. */
5141 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5145 unsigned char byte
= (value
& 0x7f);
5148 /* More bytes to follow. */
5156 /* Checksum the context of the DIE. This adds the names of any
5157 surrounding namespaces or structures to the checksum. */
5160 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5164 int tag
= die
->die_tag
;
5166 if (tag
!= DW_TAG_namespace
5167 && tag
!= DW_TAG_structure_type
5168 && tag
!= DW_TAG_class_type
)
5171 name
= get_AT_string (die
, DW_AT_name
);
5173 spec
= get_AT_ref (die
, DW_AT_specification
);
5177 if (die
->die_parent
!= NULL
)
5178 checksum_die_context (die
->die_parent
, ctx
);
5180 CHECKSUM_ULEB128 ('C');
5181 CHECKSUM_ULEB128 (tag
);
5183 CHECKSUM_STRING (name
);
5186 /* Calculate the checksum of a location expression. */
5189 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5191 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5192 were emitted as a DW_FORM_sdata instead of a location expression. */
5193 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5195 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5196 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5200 /* Otherwise, just checksum the raw location expression. */
5203 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5204 CHECKSUM (loc
->dw_loc_oprnd1
);
5205 CHECKSUM (loc
->dw_loc_oprnd2
);
5206 loc
= loc
->dw_loc_next
;
5210 /* Calculate the checksum of an attribute. */
5213 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5214 struct md5_ctx
*ctx
, int *mark
)
5216 dw_loc_descr_ref loc
;
5219 if (AT_class (at
) == dw_val_class_die_ref
)
5221 dw_die_ref target_die
= AT_ref (at
);
5223 /* For pointer and reference types, we checksum only the (qualified)
5224 name of the target type (if there is a name). For friend entries,
5225 we checksum only the (qualified) name of the target type or function.
5226 This allows the checksum to remain the same whether the target type
5227 is complete or not. */
5228 if ((at
->dw_attr
== DW_AT_type
5229 && (tag
== DW_TAG_pointer_type
5230 || tag
== DW_TAG_reference_type
5231 || tag
== DW_TAG_rvalue_reference_type
5232 || tag
== DW_TAG_ptr_to_member_type
))
5233 || (at
->dw_attr
== DW_AT_friend
5234 && tag
== DW_TAG_friend
))
5236 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5238 if (name_attr
!= NULL
)
5240 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5244 CHECKSUM_ULEB128 ('N');
5245 CHECKSUM_ULEB128 (at
->dw_attr
);
5246 if (decl
->die_parent
!= NULL
)
5247 checksum_die_context (decl
->die_parent
, ctx
);
5248 CHECKSUM_ULEB128 ('E');
5249 CHECKSUM_STRING (AT_string (name_attr
));
5254 /* For all other references to another DIE, we check to see if the
5255 target DIE has already been visited. If it has, we emit a
5256 backward reference; if not, we descend recursively. */
5257 if (target_die
->die_mark
> 0)
5259 CHECKSUM_ULEB128 ('R');
5260 CHECKSUM_ULEB128 (at
->dw_attr
);
5261 CHECKSUM_ULEB128 (target_die
->die_mark
);
5265 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5269 target_die
->die_mark
= ++(*mark
);
5270 CHECKSUM_ULEB128 ('T');
5271 CHECKSUM_ULEB128 (at
->dw_attr
);
5272 if (decl
->die_parent
!= NULL
)
5273 checksum_die_context (decl
->die_parent
, ctx
);
5274 die_checksum_ordered (target_die
, ctx
, mark
);
5279 CHECKSUM_ULEB128 ('A');
5280 CHECKSUM_ULEB128 (at
->dw_attr
);
5282 switch (AT_class (at
))
5284 case dw_val_class_const
:
5285 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5286 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5289 case dw_val_class_unsigned_const
:
5290 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5291 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5294 case dw_val_class_const_double
:
5295 CHECKSUM_ULEB128 (DW_FORM_block
);
5296 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5297 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5300 case dw_val_class_vec
:
5301 CHECKSUM_ULEB128 (DW_FORM_block
);
5302 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_vec
));
5303 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5306 case dw_val_class_flag
:
5307 CHECKSUM_ULEB128 (DW_FORM_flag
);
5308 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
5311 case dw_val_class_str
:
5312 CHECKSUM_ULEB128 (DW_FORM_string
);
5313 CHECKSUM_STRING (AT_string (at
));
5316 case dw_val_class_addr
:
5318 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5319 CHECKSUM_ULEB128 (DW_FORM_string
);
5320 CHECKSUM_STRING (XSTR (r
, 0));
5323 case dw_val_class_offset
:
5324 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5325 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
5328 case dw_val_class_loc
:
5329 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5330 loc_checksum_ordered (loc
, ctx
);
5333 case dw_val_class_fde_ref
:
5334 case dw_val_class_lbl_id
:
5335 case dw_val_class_lineptr
:
5336 case dw_val_class_macptr
:
5337 case dw_val_class_high_pc
:
5340 case dw_val_class_file
:
5341 CHECKSUM_ULEB128 (DW_FORM_string
);
5342 CHECKSUM_STRING (AT_file (at
)->filename
);
5345 case dw_val_class_data8
:
5346 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5354 struct checksum_attributes
5356 dw_attr_ref at_name
;
5357 dw_attr_ref at_type
;
5358 dw_attr_ref at_friend
;
5359 dw_attr_ref at_accessibility
;
5360 dw_attr_ref at_address_class
;
5361 dw_attr_ref at_allocated
;
5362 dw_attr_ref at_artificial
;
5363 dw_attr_ref at_associated
;
5364 dw_attr_ref at_binary_scale
;
5365 dw_attr_ref at_bit_offset
;
5366 dw_attr_ref at_bit_size
;
5367 dw_attr_ref at_bit_stride
;
5368 dw_attr_ref at_byte_size
;
5369 dw_attr_ref at_byte_stride
;
5370 dw_attr_ref at_const_value
;
5371 dw_attr_ref at_containing_type
;
5372 dw_attr_ref at_count
;
5373 dw_attr_ref at_data_location
;
5374 dw_attr_ref at_data_member_location
;
5375 dw_attr_ref at_decimal_scale
;
5376 dw_attr_ref at_decimal_sign
;
5377 dw_attr_ref at_default_value
;
5378 dw_attr_ref at_digit_count
;
5379 dw_attr_ref at_discr
;
5380 dw_attr_ref at_discr_list
;
5381 dw_attr_ref at_discr_value
;
5382 dw_attr_ref at_encoding
;
5383 dw_attr_ref at_endianity
;
5384 dw_attr_ref at_explicit
;
5385 dw_attr_ref at_is_optional
;
5386 dw_attr_ref at_location
;
5387 dw_attr_ref at_lower_bound
;
5388 dw_attr_ref at_mutable
;
5389 dw_attr_ref at_ordering
;
5390 dw_attr_ref at_picture_string
;
5391 dw_attr_ref at_prototyped
;
5392 dw_attr_ref at_small
;
5393 dw_attr_ref at_segment
;
5394 dw_attr_ref at_string_length
;
5395 dw_attr_ref at_threads_scaled
;
5396 dw_attr_ref at_upper_bound
;
5397 dw_attr_ref at_use_location
;
5398 dw_attr_ref at_use_UTF8
;
5399 dw_attr_ref at_variable_parameter
;
5400 dw_attr_ref at_virtuality
;
5401 dw_attr_ref at_visibility
;
5402 dw_attr_ref at_vtable_elem_location
;
5405 /* Collect the attributes that we will want to use for the checksum. */
5408 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
5413 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
5424 attrs
->at_friend
= a
;
5426 case DW_AT_accessibility
:
5427 attrs
->at_accessibility
= a
;
5429 case DW_AT_address_class
:
5430 attrs
->at_address_class
= a
;
5432 case DW_AT_allocated
:
5433 attrs
->at_allocated
= a
;
5435 case DW_AT_artificial
:
5436 attrs
->at_artificial
= a
;
5438 case DW_AT_associated
:
5439 attrs
->at_associated
= a
;
5441 case DW_AT_binary_scale
:
5442 attrs
->at_binary_scale
= a
;
5444 case DW_AT_bit_offset
:
5445 attrs
->at_bit_offset
= a
;
5447 case DW_AT_bit_size
:
5448 attrs
->at_bit_size
= a
;
5450 case DW_AT_bit_stride
:
5451 attrs
->at_bit_stride
= a
;
5453 case DW_AT_byte_size
:
5454 attrs
->at_byte_size
= a
;
5456 case DW_AT_byte_stride
:
5457 attrs
->at_byte_stride
= a
;
5459 case DW_AT_const_value
:
5460 attrs
->at_const_value
= a
;
5462 case DW_AT_containing_type
:
5463 attrs
->at_containing_type
= a
;
5466 attrs
->at_count
= a
;
5468 case DW_AT_data_location
:
5469 attrs
->at_data_location
= a
;
5471 case DW_AT_data_member_location
:
5472 attrs
->at_data_member_location
= a
;
5474 case DW_AT_decimal_scale
:
5475 attrs
->at_decimal_scale
= a
;
5477 case DW_AT_decimal_sign
:
5478 attrs
->at_decimal_sign
= a
;
5480 case DW_AT_default_value
:
5481 attrs
->at_default_value
= a
;
5483 case DW_AT_digit_count
:
5484 attrs
->at_digit_count
= a
;
5487 attrs
->at_discr
= a
;
5489 case DW_AT_discr_list
:
5490 attrs
->at_discr_list
= a
;
5492 case DW_AT_discr_value
:
5493 attrs
->at_discr_value
= a
;
5495 case DW_AT_encoding
:
5496 attrs
->at_encoding
= a
;
5498 case DW_AT_endianity
:
5499 attrs
->at_endianity
= a
;
5501 case DW_AT_explicit
:
5502 attrs
->at_explicit
= a
;
5504 case DW_AT_is_optional
:
5505 attrs
->at_is_optional
= a
;
5507 case DW_AT_location
:
5508 attrs
->at_location
= a
;
5510 case DW_AT_lower_bound
:
5511 attrs
->at_lower_bound
= a
;
5514 attrs
->at_mutable
= a
;
5516 case DW_AT_ordering
:
5517 attrs
->at_ordering
= a
;
5519 case DW_AT_picture_string
:
5520 attrs
->at_picture_string
= a
;
5522 case DW_AT_prototyped
:
5523 attrs
->at_prototyped
= a
;
5526 attrs
->at_small
= a
;
5529 attrs
->at_segment
= a
;
5531 case DW_AT_string_length
:
5532 attrs
->at_string_length
= a
;
5534 case DW_AT_threads_scaled
:
5535 attrs
->at_threads_scaled
= a
;
5537 case DW_AT_upper_bound
:
5538 attrs
->at_upper_bound
= a
;
5540 case DW_AT_use_location
:
5541 attrs
->at_use_location
= a
;
5543 case DW_AT_use_UTF8
:
5544 attrs
->at_use_UTF8
= a
;
5546 case DW_AT_variable_parameter
:
5547 attrs
->at_variable_parameter
= a
;
5549 case DW_AT_virtuality
:
5550 attrs
->at_virtuality
= a
;
5552 case DW_AT_visibility
:
5553 attrs
->at_visibility
= a
;
5555 case DW_AT_vtable_elem_location
:
5556 attrs
->at_vtable_elem_location
= a
;
5564 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
5567 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5571 struct checksum_attributes attrs
;
5573 CHECKSUM_ULEB128 ('D');
5574 CHECKSUM_ULEB128 (die
->die_tag
);
5576 memset (&attrs
, 0, sizeof (attrs
));
5578 decl
= get_AT_ref (die
, DW_AT_specification
);
5580 collect_checksum_attributes (&attrs
, decl
);
5581 collect_checksum_attributes (&attrs
, die
);
5583 CHECKSUM_ATTR (attrs
.at_name
);
5584 CHECKSUM_ATTR (attrs
.at_accessibility
);
5585 CHECKSUM_ATTR (attrs
.at_address_class
);
5586 CHECKSUM_ATTR (attrs
.at_allocated
);
5587 CHECKSUM_ATTR (attrs
.at_artificial
);
5588 CHECKSUM_ATTR (attrs
.at_associated
);
5589 CHECKSUM_ATTR (attrs
.at_binary_scale
);
5590 CHECKSUM_ATTR (attrs
.at_bit_offset
);
5591 CHECKSUM_ATTR (attrs
.at_bit_size
);
5592 CHECKSUM_ATTR (attrs
.at_bit_stride
);
5593 CHECKSUM_ATTR (attrs
.at_byte_size
);
5594 CHECKSUM_ATTR (attrs
.at_byte_stride
);
5595 CHECKSUM_ATTR (attrs
.at_const_value
);
5596 CHECKSUM_ATTR (attrs
.at_containing_type
);
5597 CHECKSUM_ATTR (attrs
.at_count
);
5598 CHECKSUM_ATTR (attrs
.at_data_location
);
5599 CHECKSUM_ATTR (attrs
.at_data_member_location
);
5600 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
5601 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
5602 CHECKSUM_ATTR (attrs
.at_default_value
);
5603 CHECKSUM_ATTR (attrs
.at_digit_count
);
5604 CHECKSUM_ATTR (attrs
.at_discr
);
5605 CHECKSUM_ATTR (attrs
.at_discr_list
);
5606 CHECKSUM_ATTR (attrs
.at_discr_value
);
5607 CHECKSUM_ATTR (attrs
.at_encoding
);
5608 CHECKSUM_ATTR (attrs
.at_endianity
);
5609 CHECKSUM_ATTR (attrs
.at_explicit
);
5610 CHECKSUM_ATTR (attrs
.at_is_optional
);
5611 CHECKSUM_ATTR (attrs
.at_location
);
5612 CHECKSUM_ATTR (attrs
.at_lower_bound
);
5613 CHECKSUM_ATTR (attrs
.at_mutable
);
5614 CHECKSUM_ATTR (attrs
.at_ordering
);
5615 CHECKSUM_ATTR (attrs
.at_picture_string
);
5616 CHECKSUM_ATTR (attrs
.at_prototyped
);
5617 CHECKSUM_ATTR (attrs
.at_small
);
5618 CHECKSUM_ATTR (attrs
.at_segment
);
5619 CHECKSUM_ATTR (attrs
.at_string_length
);
5620 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
5621 CHECKSUM_ATTR (attrs
.at_upper_bound
);
5622 CHECKSUM_ATTR (attrs
.at_use_location
);
5623 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
5624 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
5625 CHECKSUM_ATTR (attrs
.at_virtuality
);
5626 CHECKSUM_ATTR (attrs
.at_visibility
);
5627 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
5628 CHECKSUM_ATTR (attrs
.at_type
);
5629 CHECKSUM_ATTR (attrs
.at_friend
);
5631 /* Checksum the child DIEs, except for nested types and member functions. */
5634 dw_attr_ref name_attr
;
5637 name_attr
= get_AT (c
, DW_AT_name
);
5638 if ((is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
)
5639 && name_attr
!= NULL
)
5641 CHECKSUM_ULEB128 ('S');
5642 CHECKSUM_ULEB128 (c
->die_tag
);
5643 CHECKSUM_STRING (AT_string (name_attr
));
5647 /* Mark this DIE so it gets processed when unmarking. */
5648 if (c
->die_mark
== 0)
5650 die_checksum_ordered (c
, ctx
, mark
);
5652 } while (c
!= die
->die_child
);
5654 CHECKSUM_ULEB128 (0);
5658 #undef CHECKSUM_STRING
5659 #undef CHECKSUM_ATTR
5660 #undef CHECKSUM_LEB128
5661 #undef CHECKSUM_ULEB128
5663 /* Generate the type signature for DIE. This is computed by generating an
5664 MD5 checksum over the DIE's tag, its relevant attributes, and its
5665 children. Attributes that are references to other DIEs are processed
5666 by recursion, using the MARK field to prevent infinite recursion.
5667 If the DIE is nested inside a namespace or another type, we also
5668 need to include that context in the signature. The lower 64 bits
5669 of the resulting MD5 checksum comprise the signature. */
5672 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
5676 unsigned char checksum
[16];
5681 name
= get_AT_string (die
, DW_AT_name
);
5682 decl
= get_AT_ref (die
, DW_AT_specification
);
5683 parent
= get_die_parent (die
);
5685 /* First, compute a signature for just the type name (and its surrounding
5686 context, if any. This is stored in the type unit DIE for link-time
5687 ODR (one-definition rule) checking. */
5689 if (is_cxx() && name
!= NULL
)
5691 md5_init_ctx (&ctx
);
5693 /* Checksum the names of surrounding namespaces and structures. */
5695 checksum_die_context (parent
, &ctx
);
5697 md5_process_bytes (&die
->die_tag
, sizeof (die
->die_tag
), &ctx
);
5698 md5_process_bytes (name
, strlen (name
) + 1, &ctx
);
5699 md5_finish_ctx (&ctx
, checksum
);
5701 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
5704 /* Next, compute the complete type signature. */
5706 md5_init_ctx (&ctx
);
5708 die
->die_mark
= mark
;
5710 /* Checksum the names of surrounding namespaces and structures. */
5712 checksum_die_context (parent
, &ctx
);
5714 /* Checksum the DIE and its children. */
5715 die_checksum_ordered (die
, &ctx
, &mark
);
5716 unmark_all_dies (die
);
5717 md5_finish_ctx (&ctx
, checksum
);
5719 /* Store the signature in the type node and link the type DIE and the
5720 type node together. */
5721 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
5722 DWARF_TYPE_SIGNATURE_SIZE
);
5723 die
->comdat_type_p
= true;
5724 die
->die_id
.die_type_node
= type_node
;
5725 type_node
->type_die
= die
;
5727 /* If the DIE is a specification, link its declaration to the type node
5731 decl
->comdat_type_p
= true;
5732 decl
->die_id
.die_type_node
= type_node
;
5736 /* Do the location expressions look same? */
5738 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
5740 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
5741 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
5742 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
5745 /* Do the values look the same? */
5747 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
5749 dw_loc_descr_ref loc1
, loc2
;
5752 if (v1
->val_class
!= v2
->val_class
)
5755 switch (v1
->val_class
)
5757 case dw_val_class_const
:
5758 return v1
->v
.val_int
== v2
->v
.val_int
;
5759 case dw_val_class_unsigned_const
:
5760 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
5761 case dw_val_class_const_double
:
5762 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
5763 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
5764 case dw_val_class_vec
:
5765 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
5766 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
5768 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
5769 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
5772 case dw_val_class_flag
:
5773 return v1
->v
.val_flag
== v2
->v
.val_flag
;
5774 case dw_val_class_str
:
5775 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
5777 case dw_val_class_addr
:
5778 r1
= v1
->v
.val_addr
;
5779 r2
= v2
->v
.val_addr
;
5780 if (GET_CODE (r1
) != GET_CODE (r2
))
5782 return !rtx_equal_p (r1
, r2
);
5784 case dw_val_class_offset
:
5785 return v1
->v
.val_offset
== v2
->v
.val_offset
;
5787 case dw_val_class_loc
:
5788 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
5790 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
5791 if (!same_loc_p (loc1
, loc2
, mark
))
5793 return !loc1
&& !loc2
;
5795 case dw_val_class_die_ref
:
5796 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
5798 case dw_val_class_fde_ref
:
5799 case dw_val_class_vms_delta
:
5800 case dw_val_class_lbl_id
:
5801 case dw_val_class_lineptr
:
5802 case dw_val_class_macptr
:
5803 case dw_val_class_high_pc
:
5806 case dw_val_class_file
:
5807 return v1
->v
.val_file
== v2
->v
.val_file
;
5809 case dw_val_class_data8
:
5810 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
5817 /* Do the attributes look the same? */
5820 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
5822 if (at1
->dw_attr
!= at2
->dw_attr
)
5825 /* We don't care that this was compiled with a different compiler
5826 snapshot; if the output is the same, that's what matters. */
5827 if (at1
->dw_attr
== DW_AT_producer
)
5830 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
5833 /* Do the dies look the same? */
5836 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
5842 /* To avoid infinite recursion. */
5844 return die1
->die_mark
== die2
->die_mark
;
5845 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
5847 if (die1
->die_tag
!= die2
->die_tag
)
5850 if (VEC_length (dw_attr_node
, die1
->die_attr
)
5851 != VEC_length (dw_attr_node
, die2
->die_attr
))
5854 FOR_EACH_VEC_ELT (dw_attr_node
, die1
->die_attr
, ix
, a1
)
5855 if (!same_attr_p (a1
, &VEC_index (dw_attr_node
, die2
->die_attr
, ix
), mark
))
5858 c1
= die1
->die_child
;
5859 c2
= die2
->die_child
;
5868 if (!same_die_p (c1
, c2
, mark
))
5872 if (c1
== die1
->die_child
)
5874 if (c2
== die2
->die_child
)
5884 /* Do the dies look the same? Wrapper around same_die_p. */
5887 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
5890 int ret
= same_die_p (die1
, die2
, &mark
);
5892 unmark_all_dies (die1
);
5893 unmark_all_dies (die2
);
5898 /* The prefix to attach to symbols on DIEs in the current comdat debug
5900 static const char *comdat_symbol_id
;
5902 /* The index of the current symbol within the current comdat CU. */
5903 static unsigned int comdat_symbol_number
;
5905 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5906 children, and set comdat_symbol_id accordingly. */
5909 compute_section_prefix (dw_die_ref unit_die
)
5911 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
5912 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
5913 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
5916 unsigned char checksum
[16];
5919 /* Compute the checksum of the DIE, then append part of it as hex digits to
5920 the name filename of the unit. */
5922 md5_init_ctx (&ctx
);
5924 die_checksum (unit_die
, &ctx
, &mark
);
5925 unmark_all_dies (unit_die
);
5926 md5_finish_ctx (&ctx
, checksum
);
5928 sprintf (name
, "%s.", base
);
5929 clean_symbol_name (name
);
5931 p
= name
+ strlen (name
);
5932 for (i
= 0; i
< 4; i
++)
5934 sprintf (p
, "%.2x", checksum
[i
]);
5938 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
5939 comdat_symbol_number
= 0;
5942 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5945 is_type_die (dw_die_ref die
)
5947 switch (die
->die_tag
)
5949 case DW_TAG_array_type
:
5950 case DW_TAG_class_type
:
5951 case DW_TAG_interface_type
:
5952 case DW_TAG_enumeration_type
:
5953 case DW_TAG_pointer_type
:
5954 case DW_TAG_reference_type
:
5955 case DW_TAG_rvalue_reference_type
:
5956 case DW_TAG_string_type
:
5957 case DW_TAG_structure_type
:
5958 case DW_TAG_subroutine_type
:
5959 case DW_TAG_union_type
:
5960 case DW_TAG_ptr_to_member_type
:
5961 case DW_TAG_set_type
:
5962 case DW_TAG_subrange_type
:
5963 case DW_TAG_base_type
:
5964 case DW_TAG_const_type
:
5965 case DW_TAG_file_type
:
5966 case DW_TAG_packed_type
:
5967 case DW_TAG_volatile_type
:
5968 case DW_TAG_typedef
:
5975 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5976 Basically, we want to choose the bits that are likely to be shared between
5977 compilations (types) and leave out the bits that are specific to individual
5978 compilations (functions). */
5981 is_comdat_die (dw_die_ref c
)
5983 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5984 we do for stabs. The advantage is a greater likelihood of sharing between
5985 objects that don't include headers in the same order (and therefore would
5986 put the base types in a different comdat). jason 8/28/00 */
5988 if (c
->die_tag
== DW_TAG_base_type
)
5991 if (c
->die_tag
== DW_TAG_pointer_type
5992 || c
->die_tag
== DW_TAG_reference_type
5993 || c
->die_tag
== DW_TAG_rvalue_reference_type
5994 || c
->die_tag
== DW_TAG_const_type
5995 || c
->die_tag
== DW_TAG_volatile_type
)
5997 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
5999 return t
? is_comdat_die (t
) : 0;
6002 return is_type_die (c
);
6005 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6006 compilation unit. */
6009 is_symbol_die (dw_die_ref c
)
6011 return (is_type_die (c
)
6012 || is_declaration_die (c
)
6013 || c
->die_tag
== DW_TAG_namespace
6014 || c
->die_tag
== DW_TAG_module
);
6017 /* Returns true iff C is a compile-unit DIE. */
6020 is_cu_die (dw_die_ref c
)
6022 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6025 /* Returns true iff C is a unit DIE of some sort. */
6028 is_unit_die (dw_die_ref c
)
6030 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6031 || c
->die_tag
== DW_TAG_partial_unit
6032 || c
->die_tag
== DW_TAG_type_unit
);
6035 /* Returns true iff C is a namespace DIE. */
6038 is_namespace_die (dw_die_ref c
)
6040 return c
&& c
->die_tag
== DW_TAG_namespace
;
6043 /* Returns true iff C is a class or structure DIE. */
6046 is_class_die (dw_die_ref c
)
6048 return c
&& (c
->die_tag
== DW_TAG_class_type
6049 || c
->die_tag
== DW_TAG_structure_type
);
6053 gen_internal_sym (const char *prefix
)
6057 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6058 return xstrdup (buf
);
6061 /* Assign symbols to all worthy DIEs under DIE. */
6064 assign_symbol_names (dw_die_ref die
)
6068 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6070 if (comdat_symbol_id
)
6072 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6074 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6075 comdat_symbol_id
, comdat_symbol_number
++);
6076 die
->die_id
.die_symbol
= xstrdup (p
);
6079 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6082 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6085 struct cu_hash_table_entry
6088 unsigned min_comdat_num
, max_comdat_num
;
6089 struct cu_hash_table_entry
*next
;
6092 /* Routines to manipulate hash table of CUs. */
6094 htab_cu_hash (const void *of
)
6096 const struct cu_hash_table_entry
*const entry
=
6097 (const struct cu_hash_table_entry
*) of
;
6099 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6103 htab_cu_eq (const void *of1
, const void *of2
)
6105 const struct cu_hash_table_entry
*const entry1
=
6106 (const struct cu_hash_table_entry
*) of1
;
6107 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
6109 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6113 htab_cu_del (void *what
)
6115 struct cu_hash_table_entry
*next
,
6116 *entry
= (struct cu_hash_table_entry
*) what
;
6126 /* Check whether we have already seen this CU and set up SYM_NUM
6129 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
6131 struct cu_hash_table_entry dummy
;
6132 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6134 dummy
.max_comdat_num
= 0;
6136 slot
= (struct cu_hash_table_entry
**)
6137 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6141 for (; entry
; last
= entry
, entry
= entry
->next
)
6143 if (same_die_p_wrap (cu
, entry
->cu
))
6149 *sym_num
= entry
->min_comdat_num
;
6153 entry
= XCNEW (struct cu_hash_table_entry
);
6155 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6156 entry
->next
= *slot
;
6162 /* Record SYM_NUM to record of CU in HTABLE. */
6164 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
6166 struct cu_hash_table_entry
**slot
, *entry
;
6168 slot
= (struct cu_hash_table_entry
**)
6169 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6173 entry
->max_comdat_num
= sym_num
;
6176 /* Traverse the DIE (which is always comp_unit_die), and set up
6177 additional compilation units for each of the include files we see
6178 bracketed by BINCL/EINCL. */
6181 break_out_includes (dw_die_ref die
)
6184 dw_die_ref unit
= NULL
;
6185 limbo_die_node
*node
, **pnode
;
6186 htab_t cu_hash_table
;
6190 dw_die_ref prev
= c
;
6192 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6193 || (unit
&& is_comdat_die (c
)))
6195 dw_die_ref next
= c
->die_sib
;
6197 /* This DIE is for a secondary CU; remove it from the main one. */
6198 remove_child_with_prev (c
, prev
);
6200 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6201 unit
= push_new_compile_unit (unit
, c
);
6202 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6203 unit
= pop_compile_unit (unit
);
6205 add_child_die (unit
, c
);
6207 if (c
== die
->die_child
)
6210 } while (c
!= die
->die_child
);
6213 /* We can only use this in debugging, since the frontend doesn't check
6214 to make sure that we leave every include file we enter. */
6218 assign_symbol_names (die
);
6219 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
6220 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6226 compute_section_prefix (node
->die
);
6227 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6228 &comdat_symbol_number
);
6229 assign_symbol_names (node
->die
);
6231 *pnode
= node
->next
;
6234 pnode
= &node
->next
;
6235 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6236 comdat_symbol_number
);
6239 htab_delete (cu_hash_table
);
6242 /* Return non-zero if this DIE is a declaration. */
6245 is_declaration_die (dw_die_ref die
)
6250 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6251 if (a
->dw_attr
== DW_AT_declaration
)
6257 /* Return non-zero if this DIE is nested inside a subprogram. */
6260 is_nested_in_subprogram (dw_die_ref die
)
6262 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6266 return local_scope_p (decl
);
6269 /* Return non-zero if this DIE contains a defining declaration of a
6273 contains_subprogram_definition (dw_die_ref die
)
6277 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6279 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition(c
)) return 1);
6283 /* Return non-zero if this is a type DIE that should be moved to a
6284 COMDAT .debug_types section. */
6287 should_move_die_to_comdat (dw_die_ref die
)
6289 switch (die
->die_tag
)
6291 case DW_TAG_class_type
:
6292 case DW_TAG_structure_type
:
6293 case DW_TAG_enumeration_type
:
6294 case DW_TAG_union_type
:
6295 /* Don't move declarations, inlined instances, or types nested in a
6297 if (is_declaration_die (die
)
6298 || get_AT (die
, DW_AT_abstract_origin
)
6299 || is_nested_in_subprogram (die
))
6301 /* A type definition should never contain a subprogram definition. */
6302 gcc_assert (!contains_subprogram_definition (die
));
6304 case DW_TAG_array_type
:
6305 case DW_TAG_interface_type
:
6306 case DW_TAG_pointer_type
:
6307 case DW_TAG_reference_type
:
6308 case DW_TAG_rvalue_reference_type
:
6309 case DW_TAG_string_type
:
6310 case DW_TAG_subroutine_type
:
6311 case DW_TAG_ptr_to_member_type
:
6312 case DW_TAG_set_type
:
6313 case DW_TAG_subrange_type
:
6314 case DW_TAG_base_type
:
6315 case DW_TAG_const_type
:
6316 case DW_TAG_file_type
:
6317 case DW_TAG_packed_type
:
6318 case DW_TAG_volatile_type
:
6319 case DW_TAG_typedef
:
6325 /* Make a clone of DIE. */
6328 clone_die (dw_die_ref die
)
6334 clone
= ggc_alloc_cleared_die_node ();
6335 clone
->die_tag
= die
->die_tag
;
6337 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6338 add_dwarf_attr (clone
, a
);
6343 /* Make a clone of the tree rooted at DIE. */
6346 clone_tree (dw_die_ref die
)
6349 dw_die_ref clone
= clone_die (die
);
6351 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree(c
)));
6356 /* Make a clone of DIE as a declaration. */
6359 clone_as_declaration (dw_die_ref die
)
6366 /* If the DIE is already a declaration, just clone it. */
6367 if (is_declaration_die (die
))
6368 return clone_die (die
);
6370 /* If the DIE is a specification, just clone its declaration DIE. */
6371 decl
= get_AT_ref (die
, DW_AT_specification
);
6374 clone
= clone_die (decl
);
6375 if (die
->comdat_type_p
)
6376 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6380 clone
= ggc_alloc_cleared_die_node ();
6381 clone
->die_tag
= die
->die_tag
;
6383 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6385 /* We don't want to copy over all attributes.
6386 For example we don't want DW_AT_byte_size because otherwise we will no
6387 longer have a declaration and GDB will treat it as a definition. */
6391 case DW_AT_artificial
:
6392 case DW_AT_containing_type
:
6393 case DW_AT_external
:
6396 case DW_AT_virtuality
:
6397 case DW_AT_linkage_name
:
6398 case DW_AT_MIPS_linkage_name
:
6399 add_dwarf_attr (clone
, a
);
6401 case DW_AT_byte_size
:
6407 if (die
->comdat_type_p
)
6408 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6410 add_AT_flag (clone
, DW_AT_declaration
, 1);
6414 /* Copy the declaration context to the new type unit DIE. This includes
6415 any surrounding namespace or type declarations. If the DIE has an
6416 AT_specification attribute, it also includes attributes and children
6417 attached to the specification, and returns a pointer to the original
6418 parent of the declaration DIE. Returns NULL otherwise. */
6421 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
6424 dw_die_ref new_decl
;
6425 dw_die_ref orig_parent
= NULL
;
6427 decl
= get_AT_ref (die
, DW_AT_specification
);
6436 /* The original DIE will be changed to a declaration, and must
6437 be moved to be a child of the original declaration DIE. */
6438 orig_parent
= decl
->die_parent
;
6440 /* Copy the type node pointer from the new DIE to the original
6441 declaration DIE so we can forward references later. */
6442 decl
->comdat_type_p
= true;
6443 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
6445 remove_AT (die
, DW_AT_specification
);
6447 FOR_EACH_VEC_ELT (dw_attr_node
, decl
->die_attr
, ix
, a
)
6449 if (a
->dw_attr
!= DW_AT_name
6450 && a
->dw_attr
!= DW_AT_declaration
6451 && a
->dw_attr
!= DW_AT_external
)
6452 add_dwarf_attr (die
, a
);
6455 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree(c
)));
6458 if (decl
->die_parent
!= NULL
6459 && !is_unit_die (decl
->die_parent
))
6461 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
6462 if (new_decl
!= NULL
)
6464 remove_AT (new_decl
, DW_AT_signature
);
6465 add_AT_specification (die
, new_decl
);
6472 /* Generate the skeleton ancestor tree for the given NODE, then clone
6473 the DIE and add the clone into the tree. */
6476 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
6478 if (node
->new_die
!= NULL
)
6481 node
->new_die
= clone_as_declaration (node
->old_die
);
6483 if (node
->parent
!= NULL
)
6485 generate_skeleton_ancestor_tree (node
->parent
);
6486 add_child_die (node
->parent
->new_die
, node
->new_die
);
6490 /* Generate a skeleton tree of DIEs containing any declarations that are
6491 found in the original tree. We traverse the tree looking for declaration
6492 DIEs, and construct the skeleton from the bottom up whenever we find one. */
6495 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
6497 skeleton_chain_node node
;
6500 dw_die_ref prev
= NULL
;
6501 dw_die_ref next
= NULL
;
6503 node
.parent
= parent
;
6505 first
= c
= parent
->old_die
->die_child
;
6509 if (prev
== NULL
|| prev
->die_sib
== c
)
6512 next
= (c
== first
? NULL
: c
->die_sib
);
6514 node
.new_die
= NULL
;
6515 if (is_declaration_die (c
))
6517 /* Clone the existing DIE, move the original to the skeleton
6518 tree (which is in the main CU), and put the clone, with
6519 all the original's children, where the original came from. */
6520 dw_die_ref clone
= clone_die (c
);
6521 move_all_children (c
, clone
);
6523 replace_child (c
, clone
, prev
);
6524 generate_skeleton_ancestor_tree (parent
);
6525 add_child_die (parent
->new_die
, c
);
6529 generate_skeleton_bottom_up (&node
);
6530 } while (next
!= NULL
);
6533 /* Wrapper function for generate_skeleton_bottom_up. */
6536 generate_skeleton (dw_die_ref die
)
6538 skeleton_chain_node node
;
6541 node
.new_die
= NULL
;
6544 /* If this type definition is nested inside another type,
6545 always leave at least a declaration in its place. */
6546 if (die
->die_parent
!= NULL
&& is_type_die (die
->die_parent
))
6547 node
.new_die
= clone_as_declaration (die
);
6549 generate_skeleton_bottom_up (&node
);
6550 return node
.new_die
;
6553 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
6554 declaration. The original DIE is moved to a new compile unit so that
6555 existing references to it follow it to the new location. If any of the
6556 original DIE's descendants is a declaration, we need to replace the
6557 original DIE with a skeleton tree and move the declarations back into the
6561 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
6564 dw_die_ref skeleton
, orig_parent
;
6566 /* Copy the declaration context to the type unit DIE. If the returned
6567 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
6569 orig_parent
= copy_declaration_context (unit
, child
);
6571 skeleton
= generate_skeleton (child
);
6572 if (skeleton
== NULL
)
6573 remove_child_with_prev (child
, prev
);
6576 skeleton
->comdat_type_p
= true;
6577 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
6579 /* If the original DIE was a specification, we need to put
6580 the skeleton under the parent DIE of the declaration.
6581 This leaves the original declaration in the tree, but
6582 it will be pruned later since there are no longer any
6583 references to it. */
6584 if (orig_parent
!= NULL
)
6586 remove_child_with_prev (child
, prev
);
6587 add_child_die (orig_parent
, skeleton
);
6590 replace_child (child
, skeleton
, prev
);
6596 /* Traverse the DIE and set up additional .debug_types sections for each
6597 type worthy of being placed in a COMDAT section. */
6600 break_out_comdat_types (dw_die_ref die
)
6604 dw_die_ref prev
= NULL
;
6605 dw_die_ref next
= NULL
;
6606 dw_die_ref unit
= NULL
;
6608 first
= c
= die
->die_child
;
6612 if (prev
== NULL
|| prev
->die_sib
== c
)
6615 next
= (c
== first
? NULL
: c
->die_sib
);
6616 if (should_move_die_to_comdat (c
))
6618 dw_die_ref replacement
;
6619 comdat_type_node_ref type_node
;
6621 /* Create a new type unit DIE as the root for the new tree, and
6622 add it to the list of comdat types. */
6623 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
6624 add_AT_unsigned (unit
, DW_AT_language
,
6625 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
6626 type_node
= ggc_alloc_cleared_comdat_type_node ();
6627 type_node
->root_die
= unit
;
6628 type_node
->next
= comdat_type_list
;
6629 comdat_type_list
= type_node
;
6631 /* Generate the type signature. */
6632 generate_type_signature (c
, type_node
);
6634 /* Copy the declaration context, attributes, and children of the
6635 declaration into the new type unit DIE, then remove this DIE
6636 from the main CU (or replace it with a skeleton if necessary). */
6637 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
6638 type_node
->skeleton_die
= replacement
;
6640 /* Break out nested types into their own type units. */
6641 break_out_comdat_types (c
);
6643 /* Add the DIE to the new compunit. */
6644 add_child_die (unit
, c
);
6646 if (replacement
!= NULL
)
6649 else if (c
->die_tag
== DW_TAG_namespace
6650 || c
->die_tag
== DW_TAG_class_type
6651 || c
->die_tag
== DW_TAG_structure_type
6652 || c
->die_tag
== DW_TAG_union_type
)
6654 /* Look for nested types that can be broken out. */
6655 break_out_comdat_types (c
);
6657 } while (next
!= NULL
);
6660 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
6662 struct decl_table_entry
6668 /* Routines to manipulate hash table of copied declarations. */
6671 htab_decl_hash (const void *of
)
6673 const struct decl_table_entry
*const entry
=
6674 (const struct decl_table_entry
*) of
;
6676 return htab_hash_pointer (entry
->orig
);
6680 htab_decl_eq (const void *of1
, const void *of2
)
6682 const struct decl_table_entry
*const entry1
=
6683 (const struct decl_table_entry
*) of1
;
6684 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
6686 return entry1
->orig
== entry2
;
6690 htab_decl_del (void *what
)
6692 struct decl_table_entry
*entry
= (struct decl_table_entry
*) what
;
6697 /* Copy DIE and its ancestors, up to, but not including, the compile unit
6698 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
6699 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
6700 to check if the ancestor has already been copied into UNIT. */
6703 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
6705 dw_die_ref parent
= die
->die_parent
;
6706 dw_die_ref new_parent
= unit
;
6709 struct decl_table_entry
*entry
= NULL
;
6713 /* Check if the entry has already been copied to UNIT. */
6714 slot
= htab_find_slot_with_hash (decl_table
, die
,
6715 htab_hash_pointer (die
), INSERT
);
6716 if (*slot
!= HTAB_EMPTY_ENTRY
)
6718 entry
= (struct decl_table_entry
*) *slot
;
6722 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
6723 entry
= XCNEW (struct decl_table_entry
);
6731 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
6734 if (!is_unit_die (parent
))
6735 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
6738 copy
= clone_as_declaration (die
);
6739 add_child_die (new_parent
, copy
);
6741 if (decl_table
!= NULL
)
6743 /* Record the pointer to the copy. */
6750 /* Like clone_tree, but additionally enter all the children into
6751 the hash table decl_table. */
6754 clone_tree_hash (dw_die_ref die
, htab_t decl_table
)
6757 dw_die_ref clone
= clone_die (die
);
6758 struct decl_table_entry
*entry
;
6759 void **slot
= htab_find_slot_with_hash (decl_table
, die
,
6760 htab_hash_pointer (die
), INSERT
);
6761 /* Assert that DIE isn't in the hash table yet. If it would be there
6762 before, the ancestors would be necessarily there as well, therefore
6763 clone_tree_hash wouldn't be called. */
6764 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
6765 entry
= XCNEW (struct decl_table_entry
);
6767 entry
->copy
= clone
;
6770 FOR_EACH_CHILD (die
, c
,
6771 add_child_die (clone
, clone_tree_hash (c
, decl_table
)));
6776 /* Walk the DIE and its children, looking for references to incomplete
6777 or trivial types that are unmarked (i.e., that are not in the current
6781 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
6787 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6789 if (AT_class (a
) == dw_val_class_die_ref
)
6791 dw_die_ref targ
= AT_ref (a
);
6793 struct decl_table_entry
*entry
;
6795 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
6798 slot
= htab_find_slot_with_hash (decl_table
, targ
,
6799 htab_hash_pointer (targ
), INSERT
);
6801 if (*slot
!= HTAB_EMPTY_ENTRY
)
6803 /* TARG has already been copied, so we just need to
6804 modify the reference to point to the copy. */
6805 entry
= (struct decl_table_entry
*) *slot
;
6806 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
6810 dw_die_ref parent
= unit
;
6811 dw_die_ref copy
= clone_die (targ
);
6813 /* Record in DECL_TABLE that TARG has been copied.
6814 Need to do this now, before the recursive call,
6815 because DECL_TABLE may be expanded and SLOT
6816 would no longer be a valid pointer. */
6817 entry
= XCNEW (struct decl_table_entry
);
6822 FOR_EACH_CHILD (targ
, c
,
6823 add_child_die (copy
,
6824 clone_tree_hash (c
, decl_table
)));
6826 /* Make sure the cloned tree is marked as part of the
6830 /* If TARG has surrounding context, copy its ancestor tree
6831 into the new type unit. */
6832 if (targ
->die_parent
!= NULL
6833 && !is_unit_die (targ
->die_parent
))
6834 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
6837 add_child_die (parent
, copy
);
6838 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
6840 /* Make sure the newly-copied DIE is walked. If it was
6841 installed in a previously-added context, it won't
6842 get visited otherwise. */
6845 /* Find the highest point of the newly-added tree,
6846 mark each node along the way, and walk from there. */
6847 parent
->die_mark
= 1;
6848 while (parent
->die_parent
6849 && parent
->die_parent
->die_mark
== 0)
6851 parent
= parent
->die_parent
;
6852 parent
->die_mark
= 1;
6854 copy_decls_walk (unit
, parent
, decl_table
);
6860 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
6863 /* Copy declarations for "unworthy" types into the new comdat section.
6864 Incomplete types, modified types, and certain other types aren't broken
6865 out into comdat sections of their own, so they don't have a signature,
6866 and we need to copy the declaration into the same section so that we
6867 don't have an external reference. */
6870 copy_decls_for_unworthy_types (dw_die_ref unit
)
6875 decl_table
= htab_create (10, htab_decl_hash
, htab_decl_eq
, htab_decl_del
);
6876 copy_decls_walk (unit
, unit
, decl_table
);
6877 htab_delete (decl_table
);
6881 /* Traverse the DIE and add a sibling attribute if it may have the
6882 effect of speeding up access to siblings. To save some space,
6883 avoid generating sibling attributes for DIE's without children. */
6886 add_sibling_attributes (dw_die_ref die
)
6890 if (! die
->die_child
)
6893 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
6894 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
6896 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
6899 /* Output all location lists for the DIE and its children. */
6902 output_location_lists (dw_die_ref die
)
6908 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6909 if (AT_class (a
) == dw_val_class_loc_list
)
6910 output_loc_list (AT_loc_list (a
));
6912 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
6915 /* We want to limit the number of external references, because they are
6916 larger than local references: a relocation takes multiple words, and
6917 even a sig8 reference is always eight bytes, whereas a local reference
6918 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
6919 So if we encounter multiple external references to the same type DIE, we
6920 make a local typedef stub for it and redirect all references there.
6922 This is the element of the hash table for keeping track of these
6932 /* Hash an external_ref. */
6935 hash_external_ref (const void *p
)
6937 const struct external_ref
*r
= (const struct external_ref
*)p
;
6938 return htab_hash_pointer (r
->type
);
6941 /* Compare external_refs. */
6944 external_ref_eq (const void *p1
, const void *p2
)
6946 const struct external_ref
*r1
= (const struct external_ref
*)p1
;
6947 const struct external_ref
*r2
= (const struct external_ref
*)p2
;
6948 return r1
->type
== r2
->type
;
6951 /* Return a pointer to the external_ref for references to DIE. */
6953 static struct external_ref
*
6954 lookup_external_ref (htab_t map
, dw_die_ref die
)
6956 struct external_ref ref
, *ref_p
;
6960 slot
= htab_find_slot (map
, &ref
, INSERT
);
6961 if (*slot
!= HTAB_EMPTY_ENTRY
)
6962 return (struct external_ref
*) *slot
;
6964 ref_p
= XCNEW (struct external_ref
);
6970 /* Subroutine of optimize_external_refs, below.
6972 If we see a type skeleton, record it as our stub. If we see external
6973 references, remember how many we've seen. */
6976 optimize_external_refs_1 (dw_die_ref die
, htab_t map
)
6981 struct external_ref
*ref_p
;
6983 if (is_type_die (die
)
6984 && (c
= get_AT_ref (die
, DW_AT_signature
)))
6986 /* This is a local skeleton; use it for local references. */
6987 ref_p
= lookup_external_ref (map
, c
);
6991 /* Scan the DIE references, and remember any that refer to DIEs from
6992 other CUs (i.e. those which are not marked). */
6993 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6994 if (AT_class (a
) == dw_val_class_die_ref
6995 && (c
= AT_ref (a
))->die_mark
== 0
6998 ref_p
= lookup_external_ref (map
, c
);
7002 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7005 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7006 points to an external_ref, DATA is the CU we're processing. If we don't
7007 already have a local stub, and we have multiple refs, build a stub. */
7010 build_local_stub (void **slot
, void *data
)
7012 struct external_ref
*ref_p
= (struct external_ref
*)*slot
;
7014 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7016 /* We have multiple references to this type, so build a small stub.
7017 Both of these forms are a bit dodgy from the perspective of the
7018 DWARF standard, since technically they should have names. */
7019 dw_die_ref cu
= (dw_die_ref
) data
;
7020 dw_die_ref type
= ref_p
->type
;
7021 dw_die_ref stub
= NULL
;
7023 if (type
->comdat_type_p
)
7025 /* If we refer to this type via sig8, use AT_signature. */
7026 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7027 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7031 /* Otherwise, use a typedef with no name. */
7032 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7033 add_AT_die_ref (stub
, DW_AT_type
, type
);
7042 /* DIE is a unit; look through all the DIE references to see if there are
7043 any external references to types, and if so, create local stubs for
7044 them which will be applied in build_abbrev_table. This is useful because
7045 references to local DIEs are smaller. */
7048 optimize_external_refs (dw_die_ref die
)
7050 htab_t map
= htab_create (10, hash_external_ref
, external_ref_eq
, free
);
7051 optimize_external_refs_1 (die
, map
);
7052 htab_traverse (map
, build_local_stub
, die
);
7056 /* The format of each DIE (and its attribute value pairs) is encoded in an
7057 abbreviation table. This routine builds the abbreviation table and assigns
7058 a unique abbreviation id for each abbreviation entry. The children of each
7059 die are visited recursively. */
7062 build_abbrev_table (dw_die_ref die
, htab_t extern_map
)
7064 unsigned long abbrev_id
;
7065 unsigned int n_alloc
;
7070 /* Scan the DIE references, and replace any that refer to
7071 DIEs from other CUs (i.e. those which are not marked) with
7072 the local stubs we built in optimize_external_refs. */
7073 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7074 if (AT_class (a
) == dw_val_class_die_ref
7075 && (c
= AT_ref (a
))->die_mark
== 0)
7077 struct external_ref
*ref_p
;
7078 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7080 ref_p
= lookup_external_ref (extern_map
, c
);
7081 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7082 change_AT_die_ref (a
, ref_p
->stub
);
7084 /* We aren't changing this reference, so mark it external. */
7085 set_AT_ref_external (a
, 1);
7088 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7090 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7091 dw_attr_ref die_a
, abbrev_a
;
7095 if (abbrev
->die_tag
!= die
->die_tag
)
7097 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7100 if (VEC_length (dw_attr_node
, abbrev
->die_attr
)
7101 != VEC_length (dw_attr_node
, die
->die_attr
))
7104 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, die_a
)
7106 abbrev_a
= &VEC_index (dw_attr_node
, abbrev
->die_attr
, ix
);
7107 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7108 || (value_format (abbrev_a
) != value_format (die_a
)))
7118 if (abbrev_id
>= abbrev_die_table_in_use
)
7120 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7122 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7123 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7126 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7127 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7128 abbrev_die_table_allocated
= n_alloc
;
7131 ++abbrev_die_table_in_use
;
7132 abbrev_die_table
[abbrev_id
] = die
;
7135 die
->die_abbrev
= abbrev_id
;
7136 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
7139 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7142 constant_size (unsigned HOST_WIDE_INT value
)
7149 log
= floor_log2 (value
);
7152 log
= 1 << (floor_log2 (log
) + 1);
7157 /* Return the size of a DIE as it is represented in the
7158 .debug_info section. */
7160 static unsigned long
7161 size_of_die (dw_die_ref die
)
7163 unsigned long size
= 0;
7167 size
+= size_of_uleb128 (die
->die_abbrev
);
7168 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7170 switch (AT_class (a
))
7172 case dw_val_class_addr
:
7173 size
+= DWARF2_ADDR_SIZE
;
7175 case dw_val_class_offset
:
7176 size
+= DWARF_OFFSET_SIZE
;
7178 case dw_val_class_loc
:
7180 unsigned long lsize
= size_of_locs (AT_loc (a
));
7183 if (dwarf_version
>= 4)
7184 size
+= size_of_uleb128 (lsize
);
7186 size
+= constant_size (lsize
);
7190 case dw_val_class_loc_list
:
7191 size
+= DWARF_OFFSET_SIZE
;
7193 case dw_val_class_range_list
:
7194 size
+= DWARF_OFFSET_SIZE
;
7196 case dw_val_class_const
:
7197 size
+= size_of_sleb128 (AT_int (a
));
7199 case dw_val_class_unsigned_const
:
7201 int csize
= constant_size (AT_unsigned (a
));
7202 if (dwarf_version
== 3
7203 && a
->dw_attr
== DW_AT_data_member_location
7205 size
+= size_of_uleb128 (AT_unsigned (a
));
7210 case dw_val_class_const_double
:
7211 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
7212 if (HOST_BITS_PER_WIDE_INT
>= 64)
7215 case dw_val_class_vec
:
7216 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7217 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7218 + a
->dw_attr_val
.v
.val_vec
.length
7219 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7221 case dw_val_class_flag
:
7222 if (dwarf_version
>= 4)
7223 /* Currently all add_AT_flag calls pass in 1 as last argument,
7224 so DW_FORM_flag_present can be used. If that ever changes,
7225 we'll need to use DW_FORM_flag and have some optimization
7226 in build_abbrev_table that will change those to
7227 DW_FORM_flag_present if it is set to 1 in all DIEs using
7228 the same abbrev entry. */
7229 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7233 case dw_val_class_die_ref
:
7234 if (AT_ref_external (a
))
7236 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7237 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7238 is sized by target address length, whereas in DWARF3
7239 it's always sized as an offset. */
7240 if (use_debug_types
)
7241 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7242 else if (dwarf_version
== 2)
7243 size
+= DWARF2_ADDR_SIZE
;
7245 size
+= DWARF_OFFSET_SIZE
;
7248 size
+= DWARF_OFFSET_SIZE
;
7250 case dw_val_class_fde_ref
:
7251 size
+= DWARF_OFFSET_SIZE
;
7253 case dw_val_class_lbl_id
:
7254 size
+= DWARF2_ADDR_SIZE
;
7256 case dw_val_class_lineptr
:
7257 case dw_val_class_macptr
:
7258 size
+= DWARF_OFFSET_SIZE
;
7260 case dw_val_class_str
:
7261 if (AT_string_form (a
) == DW_FORM_strp
)
7262 size
+= DWARF_OFFSET_SIZE
;
7264 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7266 case dw_val_class_file
:
7267 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7269 case dw_val_class_data8
:
7272 case dw_val_class_vms_delta
:
7273 size
+= DWARF_OFFSET_SIZE
;
7275 case dw_val_class_high_pc
:
7276 size
+= DWARF2_ADDR_SIZE
;
7286 /* Size the debugging information associated with a given DIE. Visits the
7287 DIE's children recursively. Updates the global variable next_die_offset, on
7288 each time through. Uses the current value of next_die_offset to update the
7289 die_offset field in each DIE. */
7292 calc_die_sizes (dw_die_ref die
)
7296 gcc_assert (die
->die_offset
== 0
7297 || (unsigned long int) die
->die_offset
== next_die_offset
);
7298 die
->die_offset
= next_die_offset
;
7299 next_die_offset
+= size_of_die (die
);
7301 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7303 if (die
->die_child
!= NULL
)
7304 /* Count the null byte used to terminate sibling lists. */
7305 next_die_offset
+= 1;
7308 /* Size just the base type children at the start of the CU.
7309 This is needed because build_abbrev needs to size locs
7310 and sizing of type based stack ops needs to know die_offset
7311 values for the base types. */
7314 calc_base_type_die_sizes (void)
7316 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7318 dw_die_ref base_type
;
7319 #if ENABLE_ASSERT_CHECKING
7320 dw_die_ref prev
= comp_unit_die ()->die_child
;
7323 die_offset
+= size_of_die (comp_unit_die ());
7324 for (i
= 0; VEC_iterate (dw_die_ref
, base_types
, i
, base_type
); i
++)
7326 #if ENABLE_ASSERT_CHECKING
7327 gcc_assert (base_type
->die_offset
== 0
7328 && prev
->die_sib
== base_type
7329 && base_type
->die_child
== NULL
7330 && base_type
->die_abbrev
);
7333 base_type
->die_offset
= die_offset
;
7334 die_offset
+= size_of_die (base_type
);
7338 /* Set the marks for a die and its children. We do this so
7339 that we know whether or not a reference needs to use FORM_ref_addr; only
7340 DIEs in the same CU will be marked. We used to clear out the offset
7341 and use that as the flag, but ran into ordering problems. */
7344 mark_dies (dw_die_ref die
)
7348 gcc_assert (!die
->die_mark
);
7351 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7354 /* Clear the marks for a die and its children. */
7357 unmark_dies (dw_die_ref die
)
7361 if (! use_debug_types
)
7362 gcc_assert (die
->die_mark
);
7365 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7368 /* Clear the marks for a die, its children and referred dies. */
7371 unmark_all_dies (dw_die_ref die
)
7381 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7383 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7384 if (AT_class (a
) == dw_val_class_die_ref
)
7385 unmark_all_dies (AT_ref (a
));
7388 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7389 generated for the compilation unit. */
7391 static unsigned long
7392 size_of_pubnames (VEC (pubname_entry
, gc
) * names
)
7398 size
= DWARF_PUBNAMES_HEADER_SIZE
;
7399 FOR_EACH_VEC_ELT (pubname_entry
, names
, i
, p
)
7400 if (names
!= pubtype_table
7401 || p
->die
->die_offset
!= 0
7402 || !flag_eliminate_unused_debug_types
)
7403 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
7405 size
+= DWARF_OFFSET_SIZE
;
7409 /* Return the size of the information in the .debug_aranges section. */
7411 static unsigned long
7412 size_of_aranges (void)
7416 size
= DWARF_ARANGES_HEADER_SIZE
;
7418 /* Count the address/length pair for this compilation unit. */
7419 if (text_section_used
)
7420 size
+= 2 * DWARF2_ADDR_SIZE
;
7421 if (cold_text_section_used
)
7422 size
+= 2 * DWARF2_ADDR_SIZE
;
7423 if (have_multiple_function_sections
)
7428 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, fde_idx
, fde
)
7430 if (!fde
->in_std_section
)
7431 size
+= 2 * DWARF2_ADDR_SIZE
;
7432 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
7433 size
+= 2 * DWARF2_ADDR_SIZE
;
7437 /* Count the two zero words used to terminated the address range table. */
7438 size
+= 2 * DWARF2_ADDR_SIZE
;
7442 /* Select the encoding of an attribute value. */
7444 static enum dwarf_form
7445 value_format (dw_attr_ref a
)
7447 switch (a
->dw_attr_val
.val_class
)
7449 case dw_val_class_addr
:
7450 /* Only very few attributes allow DW_FORM_addr. */
7455 case DW_AT_entry_pc
:
7456 case DW_AT_trampoline
:
7457 return DW_FORM_addr
;
7461 switch (DWARF2_ADDR_SIZE
)
7464 return DW_FORM_data1
;
7466 return DW_FORM_data2
;
7468 return DW_FORM_data4
;
7470 return DW_FORM_data8
;
7474 case dw_val_class_range_list
:
7475 case dw_val_class_loc_list
:
7476 if (dwarf_version
>= 4)
7477 return DW_FORM_sec_offset
;
7479 case dw_val_class_vms_delta
:
7480 case dw_val_class_offset
:
7481 switch (DWARF_OFFSET_SIZE
)
7484 return DW_FORM_data4
;
7486 return DW_FORM_data8
;
7490 case dw_val_class_loc
:
7491 if (dwarf_version
>= 4)
7492 return DW_FORM_exprloc
;
7493 switch (constant_size (size_of_locs (AT_loc (a
))))
7496 return DW_FORM_block1
;
7498 return DW_FORM_block2
;
7500 return DW_FORM_block4
;
7504 case dw_val_class_const
:
7505 return DW_FORM_sdata
;
7506 case dw_val_class_unsigned_const
:
7507 switch (constant_size (AT_unsigned (a
)))
7510 return DW_FORM_data1
;
7512 return DW_FORM_data2
;
7514 /* In DWARF3 DW_AT_data_member_location with
7515 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
7516 constant, so we need to use DW_FORM_udata if we need
7517 a large constant. */
7518 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
7519 return DW_FORM_udata
;
7520 return DW_FORM_data4
;
7522 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
7523 return DW_FORM_udata
;
7524 return DW_FORM_data8
;
7528 case dw_val_class_const_double
:
7529 switch (HOST_BITS_PER_WIDE_INT
)
7532 return DW_FORM_data2
;
7534 return DW_FORM_data4
;
7536 return DW_FORM_data8
;
7539 return DW_FORM_block1
;
7541 case dw_val_class_vec
:
7542 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
7543 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
7546 return DW_FORM_block1
;
7548 return DW_FORM_block2
;
7550 return DW_FORM_block4
;
7554 case dw_val_class_flag
:
7555 if (dwarf_version
>= 4)
7557 /* Currently all add_AT_flag calls pass in 1 as last argument,
7558 so DW_FORM_flag_present can be used. If that ever changes,
7559 we'll need to use DW_FORM_flag and have some optimization
7560 in build_abbrev_table that will change those to
7561 DW_FORM_flag_present if it is set to 1 in all DIEs using
7562 the same abbrev entry. */
7563 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7564 return DW_FORM_flag_present
;
7566 return DW_FORM_flag
;
7567 case dw_val_class_die_ref
:
7568 if (AT_ref_external (a
))
7569 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
7572 case dw_val_class_fde_ref
:
7573 return DW_FORM_data
;
7574 case dw_val_class_lbl_id
:
7575 return DW_FORM_addr
;
7576 case dw_val_class_lineptr
:
7577 case dw_val_class_macptr
:
7578 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
7579 case dw_val_class_str
:
7580 return AT_string_form (a
);
7581 case dw_val_class_file
:
7582 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
7585 return DW_FORM_data1
;
7587 return DW_FORM_data2
;
7589 return DW_FORM_data4
;
7594 case dw_val_class_data8
:
7595 return DW_FORM_data8
;
7597 case dw_val_class_high_pc
:
7598 switch (DWARF2_ADDR_SIZE
)
7601 return DW_FORM_data4
;
7603 return DW_FORM_data8
;
7613 /* Output the encoding of an attribute value. */
7616 output_value_format (dw_attr_ref a
)
7618 enum dwarf_form form
= value_format (a
);
7620 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
7623 /* Output the .debug_abbrev section which defines the DIE abbreviation
7627 output_abbrev_section (void)
7629 unsigned long abbrev_id
;
7631 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7633 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7637 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
7638 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
7639 dwarf_tag_name (abbrev
->die_tag
));
7641 if (abbrev
->die_child
!= NULL
)
7642 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
7644 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
7646 for (ix
= 0; VEC_iterate (dw_attr_node
, abbrev
->die_attr
, ix
, a_attr
);
7649 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
7650 dwarf_attr_name (a_attr
->dw_attr
));
7651 output_value_format (a_attr
);
7654 dw2_asm_output_data (1, 0, NULL
);
7655 dw2_asm_output_data (1, 0, NULL
);
7658 /* Terminate the table. */
7659 dw2_asm_output_data (1, 0, NULL
);
7662 /* Output a symbol we can use to refer to this DIE from another CU. */
7665 output_die_symbol (dw_die_ref die
)
7667 const char *sym
= die
->die_id
.die_symbol
;
7669 gcc_assert (!die
->comdat_type_p
);
7674 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
7675 /* We make these global, not weak; if the target doesn't support
7676 .linkonce, it doesn't support combining the sections, so debugging
7678 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
7680 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
7683 /* Return a new location list, given the begin and end range, and the
7686 static inline dw_loc_list_ref
7687 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
7688 const char *section
)
7690 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
7692 retlist
->begin
= begin
;
7694 retlist
->expr
= expr
;
7695 retlist
->section
= section
;
7700 /* Generate a new internal symbol for this location list node, if it
7701 hasn't got one yet. */
7704 gen_llsym (dw_loc_list_ref list
)
7706 gcc_assert (!list
->ll_symbol
);
7707 list
->ll_symbol
= gen_internal_sym ("LLST");
7710 /* Output the location list given to us. */
7713 output_loc_list (dw_loc_list_ref list_head
)
7715 dw_loc_list_ref curr
= list_head
;
7717 if (list_head
->emitted
)
7719 list_head
->emitted
= true;
7721 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
7723 /* Walk the location list, and output each range + expression. */
7724 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
7727 /* Don't output an entry that starts and ends at the same address. */
7728 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
7730 size
= size_of_locs (curr
->expr
);
7731 /* If the expression is too large, drop it on the floor. We could
7732 perhaps put it into DW_TAG_dwarf_procedure and refer to that
7733 in the expression, but >= 64KB expressions for a single value
7734 in a single range are unlikely very useful. */
7737 if (!have_multiple_function_sections
)
7739 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
7740 "Location list begin address (%s)",
7741 list_head
->ll_symbol
);
7742 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
7743 "Location list end address (%s)",
7744 list_head
->ll_symbol
);
7748 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
7749 "Location list begin address (%s)",
7750 list_head
->ll_symbol
);
7751 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
7752 "Location list end address (%s)",
7753 list_head
->ll_symbol
);
7756 /* Output the block length for this list of location operations. */
7757 gcc_assert (size
<= 0xffff);
7758 dw2_asm_output_data (2, size
, "%s", "Location expression size");
7760 output_loc_sequence (curr
->expr
, -1);
7763 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
7764 "Location list terminator begin (%s)",
7765 list_head
->ll_symbol
);
7766 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
7767 "Location list terminator end (%s)",
7768 list_head
->ll_symbol
);
7771 /* Output a type signature. */
7774 output_signature (const char *sig
, const char *name
)
7778 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
7779 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
7782 /* Output the DIE and its attributes. Called recursively to generate
7783 the definitions of each child DIE. */
7786 output_die (dw_die_ref die
)
7793 /* If someone in another CU might refer to us, set up a symbol for
7794 them to point to. */
7795 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
7796 output_die_symbol (die
);
7798 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
7799 (unsigned long)die
->die_offset
,
7800 dwarf_tag_name (die
->die_tag
));
7802 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7804 const char *name
= dwarf_attr_name (a
->dw_attr
);
7806 switch (AT_class (a
))
7808 case dw_val_class_addr
:
7809 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
7812 case dw_val_class_offset
:
7813 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
7817 case dw_val_class_range_list
:
7819 char *p
= strchr (ranges_section_label
, '\0');
7821 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
7822 a
->dw_attr_val
.v
.val_offset
);
7823 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
7824 debug_ranges_section
, "%s", name
);
7829 case dw_val_class_loc
:
7830 size
= size_of_locs (AT_loc (a
));
7832 /* Output the block length for this list of location operations. */
7833 if (dwarf_version
>= 4)
7834 dw2_asm_output_data_uleb128 (size
, "%s", name
);
7836 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
7838 output_loc_sequence (AT_loc (a
), -1);
7841 case dw_val_class_const
:
7842 /* ??? It would be slightly more efficient to use a scheme like is
7843 used for unsigned constants below, but gdb 4.x does not sign
7844 extend. Gdb 5.x does sign extend. */
7845 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
7848 case dw_val_class_unsigned_const
:
7850 int csize
= constant_size (AT_unsigned (a
));
7851 if (dwarf_version
== 3
7852 && a
->dw_attr
== DW_AT_data_member_location
7854 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
7856 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
7860 case dw_val_class_const_double
:
7862 unsigned HOST_WIDE_INT first
, second
;
7864 if (HOST_BITS_PER_WIDE_INT
>= 64)
7865 dw2_asm_output_data (1,
7866 HOST_BITS_PER_DOUBLE_INT
7867 / HOST_BITS_PER_CHAR
,
7870 if (WORDS_BIG_ENDIAN
)
7872 first
= a
->dw_attr_val
.v
.val_double
.high
;
7873 second
= a
->dw_attr_val
.v
.val_double
.low
;
7877 first
= a
->dw_attr_val
.v
.val_double
.low
;
7878 second
= a
->dw_attr_val
.v
.val_double
.high
;
7881 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
7883 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
7888 case dw_val_class_vec
:
7890 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
7891 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
7895 dw2_asm_output_data (constant_size (len
* elt_size
),
7896 len
* elt_size
, "%s", name
);
7897 if (elt_size
> sizeof (HOST_WIDE_INT
))
7902 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
7905 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
7906 "fp or vector constant word %u", i
);
7910 case dw_val_class_flag
:
7911 if (dwarf_version
>= 4)
7913 /* Currently all add_AT_flag calls pass in 1 as last argument,
7914 so DW_FORM_flag_present can be used. If that ever changes,
7915 we'll need to use DW_FORM_flag and have some optimization
7916 in build_abbrev_table that will change those to
7917 DW_FORM_flag_present if it is set to 1 in all DIEs using
7918 the same abbrev entry. */
7919 gcc_assert (AT_flag (a
) == 1);
7921 fprintf (asm_out_file
, "\t\t\t%s %s\n",
7922 ASM_COMMENT_START
, name
);
7925 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
7928 case dw_val_class_loc_list
:
7930 char *sym
= AT_loc_list (a
)->ll_symbol
;
7933 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
7938 case dw_val_class_die_ref
:
7939 if (AT_ref_external (a
))
7941 if (AT_ref (a
)->comdat_type_p
)
7943 comdat_type_node_ref type_node
=
7944 AT_ref (a
)->die_id
.die_type_node
;
7946 gcc_assert (type_node
);
7947 output_signature (type_node
->signature
, name
);
7951 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
7955 /* In DWARF2, DW_FORM_ref_addr is sized by target address
7956 length, whereas in DWARF3 it's always sized as an
7958 if (dwarf_version
== 2)
7959 size
= DWARF2_ADDR_SIZE
;
7961 size
= DWARF_OFFSET_SIZE
;
7962 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
7968 gcc_assert (AT_ref (a
)->die_offset
);
7969 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
7974 case dw_val_class_fde_ref
:
7978 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
7979 a
->dw_attr_val
.v
.val_fde_index
* 2);
7980 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
7985 case dw_val_class_vms_delta
:
7986 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
7987 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
7991 case dw_val_class_lbl_id
:
7992 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
7995 case dw_val_class_lineptr
:
7996 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
7997 debug_line_section
, "%s", name
);
8000 case dw_val_class_macptr
:
8001 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8002 debug_macinfo_section
, "%s", name
);
8005 case dw_val_class_str
:
8006 if (AT_string_form (a
) == DW_FORM_strp
)
8007 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8008 a
->dw_attr_val
.v
.val_str
->label
,
8010 "%s: \"%s\"", name
, AT_string (a
));
8012 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8015 case dw_val_class_file
:
8017 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8019 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8020 a
->dw_attr_val
.v
.val_file
->filename
);
8024 case dw_val_class_data8
:
8028 for (i
= 0; i
< 8; i
++)
8029 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8030 i
== 0 ? "%s" : NULL
, name
);
8034 case dw_val_class_high_pc
:
8035 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
8036 get_AT_low_pc (die
), "DW_AT_high_pc");
8044 FOR_EACH_CHILD (die
, c
, output_die (c
));
8046 /* Add null byte to terminate sibling list. */
8047 if (die
->die_child
!= NULL
)
8048 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8049 (unsigned long) die
->die_offset
);
8052 /* Output the compilation unit that appears at the beginning of the
8053 .debug_info section, and precedes the DIE descriptions. */
8056 output_compilation_unit_header (void)
8058 int ver
= dwarf_version
;
8060 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8061 dw2_asm_output_data (4, 0xffffffff,
8062 "Initial length escape value indicating 64-bit DWARF extension");
8063 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8064 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8065 "Length of Compilation Unit Info");
8066 dw2_asm_output_data (2, ver
, "DWARF version number");
8067 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8068 debug_abbrev_section
,
8069 "Offset Into Abbrev. Section");
8070 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8073 /* Output the compilation unit DIE and its children. */
8076 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8078 const char *secname
, *oldsym
;
8082 /* Unless we are outputting main CU, we may throw away empty ones. */
8083 if (!output_if_empty
&& die
->die_child
== NULL
)
8086 /* Even if there are no children of this DIE, we must output the information
8087 about the compilation unit. Otherwise, on an empty translation unit, we
8088 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8089 will then complain when examining the file. First mark all the DIEs in
8090 this CU so we know which get local refs. */
8093 extern_map
= optimize_external_refs (die
);
8095 build_abbrev_table (die
, extern_map
);
8097 htab_delete (extern_map
);
8099 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8100 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8101 calc_die_sizes (die
);
8103 oldsym
= die
->die_id
.die_symbol
;
8106 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8108 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8110 die
->die_id
.die_symbol
= NULL
;
8111 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8115 switch_to_section (debug_info_section
);
8116 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8117 info_section_emitted
= true;
8120 /* Output debugging information. */
8121 output_compilation_unit_header ();
8124 /* Leave the marks on the main CU, so we can check them in
8129 die
->die_id
.die_symbol
= oldsym
;
8133 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
8134 and .debug_pubtypes. This is configured per-target, but can be
8135 overridden by the -gpubnames or -gno-pubnames options. */
8138 want_pubnames (void)
8140 return (debug_generate_pub_sections
!= -1
8141 ? debug_generate_pub_sections
8142 : targetm
.want_debug_pub_sections
);
8145 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
8148 add_AT_pubnames (dw_die_ref die
)
8150 if (want_pubnames ())
8151 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
8154 /* Output a comdat type unit DIE and its children. */
8157 output_comdat_type_unit (comdat_type_node
*node
)
8159 const char *secname
;
8162 #if defined (OBJECT_FORMAT_ELF)
8167 /* First mark all the DIEs in this CU so we know which get local refs. */
8168 mark_dies (node
->root_die
);
8170 extern_map
= optimize_external_refs (node
->root_die
);
8172 build_abbrev_table (node
->root_die
, extern_map
);
8174 htab_delete (extern_map
);
8176 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8177 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
8178 calc_die_sizes (node
->root_die
);
8180 #if defined (OBJECT_FORMAT_ELF)
8181 secname
= ".debug_types";
8182 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8183 sprintf (tmp
, "wt.");
8184 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8185 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8186 comdat_key
= get_identifier (tmp
);
8187 targetm
.asm_out
.named_section (secname
,
8188 SECTION_DEBUG
| SECTION_LINKONCE
,
8191 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8192 sprintf (tmp
, ".gnu.linkonce.wt.");
8193 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8194 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8196 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8199 /* Output debugging information. */
8200 output_compilation_unit_header ();
8201 output_signature (node
->signature
, "Type Signature");
8202 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
8203 "Offset to Type DIE");
8204 output_die (node
->root_die
);
8206 unmark_dies (node
->root_die
);
8209 /* Return the DWARF2/3 pubname associated with a decl. */
8212 dwarf2_name (tree decl
, int scope
)
8214 if (DECL_NAMELESS (decl
))
8216 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
8219 /* Add a new entry to .debug_pubnames if appropriate. */
8222 add_pubname_string (const char *str
, dw_die_ref die
)
8227 e
.name
= xstrdup (str
);
8228 VEC_safe_push (pubname_entry
, gc
, pubname_table
, e
);
8232 add_pubname (tree decl
, dw_die_ref die
)
8234 if (!want_pubnames ())
8237 /* Don't add items to the table when we expect that the consumer will have
8238 just read the enclosing die. For example, if the consumer is looking at a
8239 class_member, it will either be inside the class already, or will have just
8240 looked up the class to find the member. Either way, searching the class is
8241 faster than searching the index. */
8242 if ((TREE_PUBLIC (decl
) && !is_class_die (die
->die_parent
))
8243 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
8245 const char *name
= dwarf2_name (decl
, 1);
8248 add_pubname_string (name
, die
);
8252 /* Add an enumerator to the pubnames section. */
8255 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
8259 gcc_assert (scope_name
);
8260 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
8262 VEC_safe_push (pubname_entry
, gc
, pubname_table
, e
);
8265 /* Add a new entry to .debug_pubtypes if appropriate. */
8268 add_pubtype (tree decl
, dw_die_ref die
)
8272 if (!want_pubnames ())
8275 if ((TREE_PUBLIC (decl
)
8276 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
8277 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
8280 const char *scope_name
= "";
8281 const char *sep
= is_cxx () ? "::" : ".";
8284 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
8285 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
8287 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
8288 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
8289 scope_name
= concat (scope_name
, sep
, NULL
);
8295 name
= type_tag (decl
);
8297 name
= lang_hooks
.dwarf_name (decl
, 1);
8299 /* If we don't have a name for the type, there's no point in adding
8301 if (name
!= NULL
&& name
[0] != '\0')
8304 e
.name
= concat (scope_name
, name
, NULL
);
8305 VEC_safe_push (pubname_entry
, gc
, pubtype_table
, e
);
8308 /* Although it might be more consistent to add the pubinfo for the
8309 enumerators as their dies are created, they should only be added if the
8310 enum type meets the criteria above. So rather than re-check the parent
8311 enum type whenever an enumerator die is created, just output them all
8312 here. This isn't protected by the name conditional because anonymous
8313 enums don't have names. */
8314 if (die
->die_tag
== DW_TAG_enumeration_type
)
8318 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
8323 /* Output the public names table used to speed up access to externally
8324 visible names; or the public types table used to find type definitions. */
8327 output_pubnames (VEC (pubname_entry
, gc
) * names
)
8330 unsigned long pubnames_length
= size_of_pubnames (names
);
8333 if (!want_pubnames () || !info_section_emitted
)
8335 if (names
== pubname_table
)
8336 switch_to_section (debug_pubnames_section
);
8338 switch_to_section (debug_pubtypes_section
);
8339 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8340 dw2_asm_output_data (4, 0xffffffff,
8341 "Initial length escape value indicating 64-bit DWARF extension");
8342 if (names
== pubname_table
)
8343 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8344 "Length of Public Names Info");
8346 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8347 "Length of Public Type Names Info");
8348 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
8349 dw2_asm_output_data (2, 2, "DWARF Version");
8350 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
8352 "Offset of Compilation Unit Info");
8353 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
8354 "Compilation Unit Length");
8356 FOR_EACH_VEC_ELT (pubname_entry
, names
, i
, pub
)
8358 /* Enumerator names are part of the pubname table, but the parent
8359 DW_TAG_enumeration_type die may have been pruned. Don't output
8360 them if that is the case. */
8361 if (pub
->die
->die_tag
== DW_TAG_enumerator
&& !pub
->die
->die_mark
)
8364 /* We shouldn't see pubnames for DIEs outside of the main CU. */
8365 if (names
== pubname_table
)
8366 gcc_assert (pub
->die
->die_mark
);
8368 if (names
!= pubtype_table
8369 || pub
->die
->die_offset
!= 0
8370 || !flag_eliminate_unused_debug_types
)
8372 dw_offset die_offset
= pub
->die
->die_offset
;
8374 /* If we're putting types in their own .debug_types sections,
8375 the .debug_pubtypes table will still point to the compile
8376 unit (not the type unit), so we want to use the offset of
8377 the skeleton DIE (if there is one). */
8378 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
8380 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
8382 if (type_node
!= NULL
)
8383 die_offset
= (type_node
->skeleton_die
!= NULL
8384 ? type_node
->skeleton_die
->die_offset
8388 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
8390 dw2_asm_output_nstring (pub
->name
, -1, "external name");
8394 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
8397 /* Output the information that goes into the .debug_aranges table.
8398 Namely, define the beginning and ending address range of the
8399 text section generated for this compilation unit. */
8402 output_aranges (unsigned long aranges_length
)
8406 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8407 dw2_asm_output_data (4, 0xffffffff,
8408 "Initial length escape value indicating 64-bit DWARF extension");
8409 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
8410 "Length of Address Ranges Info");
8411 /* Version number for aranges is still 2, even in DWARF3. */
8412 dw2_asm_output_data (2, 2, "DWARF Version");
8413 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
8415 "Offset of Compilation Unit Info");
8416 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
8417 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8419 /* We need to align to twice the pointer size here. */
8420 if (DWARF_ARANGES_PAD_SIZE
)
8422 /* Pad using a 2 byte words so that padding is correct for any
8424 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8425 2 * DWARF2_ADDR_SIZE
);
8426 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
8427 dw2_asm_output_data (2, 0, NULL
);
8430 /* It is necessary not to output these entries if the sections were
8431 not used; if the sections were not used, the length will be 0 and
8432 the address may end up as 0 if the section is discarded by ld
8433 --gc-sections, leaving an invalid (0, 0) entry that can be
8434 confused with the terminator. */
8435 if (text_section_used
)
8437 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
8438 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
8439 text_section_label
, "Length");
8441 if (cold_text_section_used
)
8443 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
8445 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
8446 cold_text_section_label
, "Length");
8449 if (have_multiple_function_sections
)
8454 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, fde_idx
, fde
)
8456 if (DECL_IGNORED_P (fde
->decl
))
8458 if (!fde
->in_std_section
)
8460 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
8462 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
8463 fde
->dw_fde_begin
, "Length");
8465 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8467 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
8469 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
8470 fde
->dw_fde_second_begin
, "Length");
8475 /* Output the terminator words. */
8476 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8477 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8480 /* Add a new entry to .debug_ranges. Return the offset at which it
8484 add_ranges_num (int num
)
8486 unsigned int in_use
= ranges_table_in_use
;
8488 if (in_use
== ranges_table_allocated
)
8490 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
8491 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
8492 ranges_table_allocated
);
8493 memset (ranges_table
+ ranges_table_in_use
, 0,
8494 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
8497 ranges_table
[in_use
].num
= num
;
8498 ranges_table_in_use
= in_use
+ 1;
8500 return in_use
* 2 * DWARF2_ADDR_SIZE
;
8503 /* Add a new entry to .debug_ranges corresponding to a block, or a
8504 range terminator if BLOCK is NULL. */
8507 add_ranges (const_tree block
)
8509 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
8512 /* Add a new entry to .debug_ranges corresponding to a pair of
8516 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
8519 unsigned int in_use
= ranges_by_label_in_use
;
8520 unsigned int offset
;
8522 if (in_use
== ranges_by_label_allocated
)
8524 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
8525 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
8527 ranges_by_label_allocated
);
8528 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
8529 RANGES_TABLE_INCREMENT
8530 * sizeof (struct dw_ranges_by_label_struct
));
8533 ranges_by_label
[in_use
].begin
= begin
;
8534 ranges_by_label
[in_use
].end
= end
;
8535 ranges_by_label_in_use
= in_use
+ 1;
8537 offset
= add_ranges_num (-(int)in_use
- 1);
8540 add_AT_range_list (die
, DW_AT_ranges
, offset
);
8546 output_ranges (void)
8549 static const char *const start_fmt
= "Offset %#x";
8550 const char *fmt
= start_fmt
;
8552 for (i
= 0; i
< ranges_table_in_use
; i
++)
8554 int block_num
= ranges_table
[i
].num
;
8558 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
8559 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
8561 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
8562 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
8564 /* If all code is in the text section, then the compilation
8565 unit base address defaults to DW_AT_low_pc, which is the
8566 base of the text section. */
8567 if (!have_multiple_function_sections
)
8569 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
8571 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8572 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
8573 text_section_label
, NULL
);
8576 /* Otherwise, the compilation unit base address is zero,
8577 which allows us to use absolute addresses, and not worry
8578 about whether the target supports cross-section
8582 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
8583 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8584 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
8590 /* Negative block_num stands for an index into ranges_by_label. */
8591 else if (block_num
< 0)
8593 int lab_idx
= - block_num
- 1;
8595 if (!have_multiple_function_sections
)
8599 /* If we ever use add_ranges_by_labels () for a single
8600 function section, all we have to do is to take out
8602 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
8603 ranges_by_label
[lab_idx
].begin
,
8605 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8606 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
8607 ranges_by_label
[lab_idx
].end
,
8608 text_section_label
, NULL
);
8613 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
8614 ranges_by_label
[lab_idx
].begin
,
8615 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8616 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
8617 ranges_by_label
[lab_idx
].end
,
8623 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8624 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8630 /* Data structure containing information about input files. */
8633 const char *path
; /* Complete file name. */
8634 const char *fname
; /* File name part. */
8635 int length
; /* Length of entire string. */
8636 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
8637 int dir_idx
; /* Index in directory table. */
8640 /* Data structure containing information about directories with source
8644 const char *path
; /* Path including directory name. */
8645 int length
; /* Path length. */
8646 int prefix
; /* Index of directory entry which is a prefix. */
8647 int count
; /* Number of files in this directory. */
8648 int dir_idx
; /* Index of directory used as base. */
8651 /* Callback function for file_info comparison. We sort by looking at
8652 the directories in the path. */
8655 file_info_cmp (const void *p1
, const void *p2
)
8657 const struct file_info
*const s1
= (const struct file_info
*) p1
;
8658 const struct file_info
*const s2
= (const struct file_info
*) p2
;
8659 const unsigned char *cp1
;
8660 const unsigned char *cp2
;
8662 /* Take care of file names without directories. We need to make sure that
8663 we return consistent values to qsort since some will get confused if
8664 we return the same value when identical operands are passed in opposite
8665 orders. So if neither has a directory, return 0 and otherwise return
8666 1 or -1 depending on which one has the directory. */
8667 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
8668 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
8670 cp1
= (const unsigned char *) s1
->path
;
8671 cp2
= (const unsigned char *) s2
->path
;
8677 /* Reached the end of the first path? If so, handle like above. */
8678 if ((cp1
== (const unsigned char *) s1
->fname
)
8679 || (cp2
== (const unsigned char *) s2
->fname
))
8680 return ((cp2
== (const unsigned char *) s2
->fname
)
8681 - (cp1
== (const unsigned char *) s1
->fname
));
8683 /* Character of current path component the same? */
8684 else if (*cp1
!= *cp2
)
8689 struct file_name_acquire_data
8691 struct file_info
*files
;
8696 /* Traversal function for the hash table. */
8699 file_name_acquire (void ** slot
, void *data
)
8701 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
8702 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
8703 struct file_info
*fi
;
8706 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
8708 if (! d
->emitted_number
)
8711 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
8713 fi
= fnad
->files
+ fnad
->used_files
++;
8715 /* Skip all leading "./". */
8717 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
8720 /* Create a new array entry. */
8722 fi
->length
= strlen (f
);
8725 /* Search for the file name part. */
8726 f
= strrchr (f
, DIR_SEPARATOR
);
8727 #if defined (DIR_SEPARATOR_2)
8729 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
8733 if (f
== NULL
|| f
< g
)
8739 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
8743 /* Output the directory table and the file name table. We try to minimize
8744 the total amount of memory needed. A heuristic is used to avoid large
8745 slowdowns with many input files. */
8748 output_file_names (void)
8750 struct file_name_acquire_data fnad
;
8752 struct file_info
*files
;
8753 struct dir_info
*dirs
;
8761 if (!last_emitted_file
)
8763 dw2_asm_output_data (1, 0, "End directory table");
8764 dw2_asm_output_data (1, 0, "End file name table");
8768 numfiles
= last_emitted_file
->emitted_number
;
8770 /* Allocate the various arrays we need. */
8771 files
= XALLOCAVEC (struct file_info
, numfiles
);
8772 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
8775 fnad
.used_files
= 0;
8776 fnad
.max_files
= numfiles
;
8777 htab_traverse (file_table
, file_name_acquire
, &fnad
);
8778 gcc_assert (fnad
.used_files
== fnad
.max_files
);
8780 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
8782 /* Find all the different directories used. */
8783 dirs
[0].path
= files
[0].path
;
8784 dirs
[0].length
= files
[0].fname
- files
[0].path
;
8785 dirs
[0].prefix
= -1;
8787 dirs
[0].dir_idx
= 0;
8788 files
[0].dir_idx
= 0;
8791 for (i
= 1; i
< numfiles
; i
++)
8792 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
8793 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
8794 dirs
[ndirs
- 1].length
) == 0)
8796 /* Same directory as last entry. */
8797 files
[i
].dir_idx
= ndirs
- 1;
8798 ++dirs
[ndirs
- 1].count
;
8804 /* This is a new directory. */
8805 dirs
[ndirs
].path
= files
[i
].path
;
8806 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
8807 dirs
[ndirs
].count
= 1;
8808 dirs
[ndirs
].dir_idx
= ndirs
;
8809 files
[i
].dir_idx
= ndirs
;
8811 /* Search for a prefix. */
8812 dirs
[ndirs
].prefix
= -1;
8813 for (j
= 0; j
< ndirs
; j
++)
8814 if (dirs
[j
].length
< dirs
[ndirs
].length
8815 && dirs
[j
].length
> 1
8816 && (dirs
[ndirs
].prefix
== -1
8817 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
8818 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
8819 dirs
[ndirs
].prefix
= j
;
8824 /* Now to the actual work. We have to find a subset of the directories which
8825 allow expressing the file name using references to the directory table
8826 with the least amount of characters. We do not do an exhaustive search
8827 where we would have to check out every combination of every single
8828 possible prefix. Instead we use a heuristic which provides nearly optimal
8829 results in most cases and never is much off. */
8830 saved
= XALLOCAVEC (int, ndirs
);
8831 savehere
= XALLOCAVEC (int, ndirs
);
8833 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
8834 for (i
= 0; i
< ndirs
; i
++)
8839 /* We can always save some space for the current directory. But this
8840 does not mean it will be enough to justify adding the directory. */
8841 savehere
[i
] = dirs
[i
].length
;
8842 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
8844 for (j
= i
+ 1; j
< ndirs
; j
++)
8847 if (saved
[j
] < dirs
[i
].length
)
8849 /* Determine whether the dirs[i] path is a prefix of the
8854 while (k
!= -1 && k
!= (int) i
)
8859 /* Yes it is. We can possibly save some memory by
8860 writing the filenames in dirs[j] relative to
8862 savehere
[j
] = dirs
[i
].length
;
8863 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
8868 /* Check whether we can save enough to justify adding the dirs[i]
8870 if (total
> dirs
[i
].length
+ 1)
8872 /* It's worthwhile adding. */
8873 for (j
= i
; j
< ndirs
; j
++)
8874 if (savehere
[j
] > 0)
8876 /* Remember how much we saved for this directory so far. */
8877 saved
[j
] = savehere
[j
];
8879 /* Remember the prefix directory. */
8880 dirs
[j
].dir_idx
= i
;
8885 /* Emit the directory name table. */
8886 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
8887 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
8888 dw2_asm_output_nstring (dirs
[i
].path
,
8890 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
8891 "Directory Entry: %#x", i
+ idx_offset
);
8893 dw2_asm_output_data (1, 0, "End directory table");
8895 /* We have to emit them in the order of emitted_number since that's
8896 used in the debug info generation. To do this efficiently we
8897 generate a back-mapping of the indices first. */
8898 backmap
= XALLOCAVEC (int, numfiles
);
8899 for (i
= 0; i
< numfiles
; i
++)
8900 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
8902 /* Now write all the file names. */
8903 for (i
= 0; i
< numfiles
; i
++)
8905 int file_idx
= backmap
[i
];
8906 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
8908 #ifdef VMS_DEBUGGING_INFO
8909 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
8911 /* Setting these fields can lead to debugger miscomparisons,
8912 but VMS Debug requires them to be set correctly. */
8917 int maxfilelen
= strlen (files
[file_idx
].path
)
8918 + dirs
[dir_idx
].length
8919 + MAX_VMS_VERSION_LEN
+ 1;
8920 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
8922 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
8923 snprintf (filebuf
, maxfilelen
, "%s;%d",
8924 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
8926 dw2_asm_output_nstring
8927 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
8929 /* Include directory index. */
8930 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
8932 /* Modification time. */
8933 dw2_asm_output_data_uleb128
8934 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
8938 /* File length in bytes. */
8939 dw2_asm_output_data_uleb128
8940 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
8944 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
8945 "File Entry: %#x", (unsigned) i
+ 1);
8947 /* Include directory index. */
8948 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
8950 /* Modification time. */
8951 dw2_asm_output_data_uleb128 (0, NULL
);
8953 /* File length in bytes. */
8954 dw2_asm_output_data_uleb128 (0, NULL
);
8955 #endif /* VMS_DEBUGGING_INFO */
8958 dw2_asm_output_data (1, 0, "End file name table");
8962 /* Output one line number table into the .debug_line section. */
8965 output_one_line_info_table (dw_line_info_table
*table
)
8967 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8968 unsigned int current_line
= 1;
8969 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
8970 dw_line_info_entry
*ent
;
8973 FOR_EACH_VEC_ELT (dw_line_info_entry
, table
->entries
, i
, ent
)
8975 switch (ent
->opcode
)
8977 case LI_set_address
:
8978 /* ??? Unfortunately, we have little choice here currently, and
8979 must always use the most general form. GCC does not know the
8980 address delta itself, so we can't use DW_LNS_advance_pc. Many
8981 ports do have length attributes which will give an upper bound
8982 on the address range. We could perhaps use length attributes
8983 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
8984 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
8986 /* This can handle any delta. This takes
8987 4+DWARF2_ADDR_SIZE bytes. */
8988 dw2_asm_output_data (1, 0, "set address %s", line_label
);
8989 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8990 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8991 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
8995 if (ent
->val
== current_line
)
8997 /* We still need to start a new row, so output a copy insn. */
8998 dw2_asm_output_data (1, DW_LNS_copy
,
8999 "copy line %u", current_line
);
9003 int line_offset
= ent
->val
- current_line
;
9004 int line_delta
= line_offset
- DWARF_LINE_BASE
;
9006 current_line
= ent
->val
;
9007 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9009 /* This can handle deltas from -10 to 234, using the current
9010 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9011 This takes 1 byte. */
9012 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9013 "line %u", current_line
);
9017 /* This can handle any delta. This takes at least 4 bytes,
9018 depending on the value being encoded. */
9019 dw2_asm_output_data (1, DW_LNS_advance_line
,
9020 "advance to line %u", current_line
);
9021 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9022 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
9028 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
9029 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9033 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
9034 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9037 case LI_negate_stmt
:
9038 current_is_stmt
= !current_is_stmt
;
9039 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
9040 "is_stmt %d", current_is_stmt
);
9043 case LI_set_prologue_end
:
9044 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
9045 "set prologue end");
9048 case LI_set_epilogue_begin
:
9049 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
9050 "set epilogue begin");
9053 case LI_set_discriminator
:
9054 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
9055 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
9056 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
9057 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
9062 /* Emit debug info for the address of the end of the table. */
9063 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
9064 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9065 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9066 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
9068 dw2_asm_output_data (1, 0, "end sequence");
9069 dw2_asm_output_data_uleb128 (1, NULL
);
9070 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
9073 /* Output the source line number correspondence information. This
9074 information goes into the .debug_line section. */
9077 output_line_info (void)
9079 char l1
[20], l2
[20], p1
[20], p2
[20];
9080 int ver
= dwarf_version
;
9081 bool saw_one
= false;
9084 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
9085 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
9086 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
9087 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
9089 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9090 dw2_asm_output_data (4, 0xffffffff,
9091 "Initial length escape value indicating 64-bit DWARF extension");
9092 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
9093 "Length of Source Line Info");
9094 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
9096 dw2_asm_output_data (2, ver
, "DWARF Version");
9097 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
9098 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
9100 /* Define the architecture-dependent minimum instruction length (in bytes).
9101 In this implementation of DWARF, this field is used for information
9102 purposes only. Since GCC generates assembly language, we have no
9103 a priori knowledge of how many instruction bytes are generated for each
9104 source line, and therefore can use only the DW_LNE_set_address and
9105 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
9106 this as '1', which is "correct enough" for all architectures,
9107 and don't let the target override. */
9108 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
9111 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
9112 "Maximum Operations Per Instruction");
9113 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
9114 "Default is_stmt_start flag");
9115 dw2_asm_output_data (1, DWARF_LINE_BASE
,
9116 "Line Base Value (Special Opcodes)");
9117 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
9118 "Line Range Value (Special Opcodes)");
9119 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
9120 "Special Opcode Base");
9122 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
9127 case DW_LNS_advance_pc
:
9128 case DW_LNS_advance_line
:
9129 case DW_LNS_set_file
:
9130 case DW_LNS_set_column
:
9131 case DW_LNS_fixed_advance_pc
:
9132 case DW_LNS_set_isa
:
9140 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
9144 /* Write out the information about the files we use. */
9145 output_file_names ();
9146 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
9148 if (separate_line_info
)
9150 dw_line_info_table
*table
;
9153 FOR_EACH_VEC_ELT (dw_line_info_table_p
, separate_line_info
, i
, table
)
9156 output_one_line_info_table (table
);
9160 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
9162 output_one_line_info_table (cold_text_section_line_info
);
9166 /* ??? Some Darwin linkers crash on a .debug_line section with no
9167 sequences. Further, merely a DW_LNE_end_sequence entry is not
9168 sufficient -- the address column must also be initialized.
9169 Make sure to output at least one set_address/end_sequence pair,
9170 choosing .text since that section is always present. */
9171 if (text_section_line_info
->in_use
|| !saw_one
)
9172 output_one_line_info_table (text_section_line_info
);
9174 /* Output the marker for the end of the line number info. */
9175 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9178 /* Given a pointer to a tree node for some base type, return a pointer to
9179 a DIE that describes the given type.
9181 This routine must only be called for GCC type nodes that correspond to
9182 Dwarf base (fundamental) types. */
9185 base_type_die (tree type
)
9187 dw_die_ref base_type_result
;
9188 enum dwarf_type encoding
;
9190 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
9193 /* If this is a subtype that should not be emitted as a subrange type,
9194 use the base type. See subrange_type_for_debug_p. */
9195 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
9196 type
= TREE_TYPE (type
);
9198 switch (TREE_CODE (type
))
9201 if ((dwarf_version
>= 4 || !dwarf_strict
)
9203 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9204 && DECL_IS_BUILTIN (TYPE_NAME (type
))
9205 && DECL_NAME (TYPE_NAME (type
)))
9207 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
9208 if (strcmp (name
, "char16_t") == 0
9209 || strcmp (name
, "char32_t") == 0)
9211 encoding
= DW_ATE_UTF
;
9215 if (TYPE_STRING_FLAG (type
))
9217 if (TYPE_UNSIGNED (type
))
9218 encoding
= DW_ATE_unsigned_char
;
9220 encoding
= DW_ATE_signed_char
;
9222 else if (TYPE_UNSIGNED (type
))
9223 encoding
= DW_ATE_unsigned
;
9225 encoding
= DW_ATE_signed
;
9229 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
9231 if (dwarf_version
>= 3 || !dwarf_strict
)
9232 encoding
= DW_ATE_decimal_float
;
9234 encoding
= DW_ATE_lo_user
;
9237 encoding
= DW_ATE_float
;
9240 case FIXED_POINT_TYPE
:
9241 if (!(dwarf_version
>= 3 || !dwarf_strict
))
9242 encoding
= DW_ATE_lo_user
;
9243 else if (TYPE_UNSIGNED (type
))
9244 encoding
= DW_ATE_unsigned_fixed
;
9246 encoding
= DW_ATE_signed_fixed
;
9249 /* Dwarf2 doesn't know anything about complex ints, so use
9250 a user defined type for it. */
9252 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
9253 encoding
= DW_ATE_complex_float
;
9255 encoding
= DW_ATE_lo_user
;
9259 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9260 encoding
= DW_ATE_boolean
;
9264 /* No other TREE_CODEs are Dwarf fundamental types. */
9268 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
9270 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
9271 int_size_in_bytes (type
));
9272 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
9273 add_pubtype (type
, base_type_result
);
9275 return base_type_result
;
9278 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9279 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9282 is_base_type (tree type
)
9284 switch (TREE_CODE (type
))
9290 case FIXED_POINT_TYPE
:
9298 case QUAL_UNION_TYPE
:
9303 case REFERENCE_TYPE
:
9317 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9318 node, return the size in bits for the type if it is a constant, or else
9319 return the alignment for the type if the type's size is not constant, or
9320 else return BITS_PER_WORD if the type actually turns out to be an
9323 static inline unsigned HOST_WIDE_INT
9324 simple_type_size_in_bits (const_tree type
)
9326 if (TREE_CODE (type
) == ERROR_MARK
)
9327 return BITS_PER_WORD
;
9328 else if (TYPE_SIZE (type
) == NULL_TREE
)
9330 else if (host_integerp (TYPE_SIZE (type
), 1))
9331 return tree_low_cst (TYPE_SIZE (type
), 1);
9333 return TYPE_ALIGN (type
);
9336 /* Similarly, but return a double_int instead of UHWI. */
9338 static inline double_int
9339 double_int_type_size_in_bits (const_tree type
)
9341 if (TREE_CODE (type
) == ERROR_MARK
)
9342 return double_int::from_uhwi (BITS_PER_WORD
);
9343 else if (TYPE_SIZE (type
) == NULL_TREE
)
9344 return double_int_zero
;
9345 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
9346 return tree_to_double_int (TYPE_SIZE (type
));
9348 return double_int::from_uhwi (TYPE_ALIGN (type
));
9351 /* Given a pointer to a tree node for a subrange type, return a pointer
9352 to a DIE that describes the given type. */
9355 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
9357 dw_die_ref subrange_die
;
9358 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
9360 if (context_die
== NULL
)
9361 context_die
= comp_unit_die ();
9363 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
9365 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
9367 /* The size of the subrange type and its base type do not match,
9368 so we need to generate a size attribute for the subrange type. */
9369 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
9373 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
9375 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
9377 return subrange_die
;
9380 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9381 entry that chains various modifiers in front of the given type. */
9384 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
9385 dw_die_ref context_die
)
9387 enum tree_code code
= TREE_CODE (type
);
9388 dw_die_ref mod_type_die
;
9389 dw_die_ref sub_die
= NULL
;
9390 tree item_type
= NULL
;
9391 tree qualified_type
;
9392 tree name
, low
, high
;
9393 dw_die_ref mod_scope
;
9395 if (code
== ERROR_MARK
)
9398 /* See if we already have the appropriately qualified variant of
9401 = get_qualified_type (type
,
9402 ((is_const_type
? TYPE_QUAL_CONST
: 0)
9403 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
9405 if (qualified_type
== sizetype
9406 && TYPE_NAME (qualified_type
)
9407 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
9409 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
9411 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
9412 && TYPE_PRECISION (t
)
9413 == TYPE_PRECISION (qualified_type
)
9414 && TYPE_UNSIGNED (t
)
9415 == TYPE_UNSIGNED (qualified_type
));
9419 /* If we do, then we can just use its DIE, if it exists. */
9422 mod_type_die
= lookup_type_die (qualified_type
);
9424 return mod_type_die
;
9427 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
9429 /* Handle C typedef types. */
9430 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
9431 && !DECL_ARTIFICIAL (name
))
9433 tree dtype
= TREE_TYPE (name
);
9435 if (qualified_type
== dtype
)
9437 /* For a named type, use the typedef. */
9438 gen_type_die (qualified_type
, context_die
);
9439 return lookup_type_die (qualified_type
);
9441 else if (is_const_type
< TYPE_READONLY (dtype
)
9442 || is_volatile_type
< TYPE_VOLATILE (dtype
)
9443 || (is_const_type
<= TYPE_READONLY (dtype
)
9444 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
9445 && DECL_ORIGINAL_TYPE (name
) != type
))
9446 /* cv-unqualified version of named type. Just use the unnamed
9447 type to which it refers. */
9448 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
9449 is_const_type
, is_volatile_type
,
9451 /* Else cv-qualified version of named type; fall through. */
9454 mod_scope
= scope_die_for (type
, context_die
);
9457 /* If both is_const_type and is_volatile_type, prefer the path
9458 which leads to a qualified type. */
9459 && (!is_volatile_type
9460 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
9461 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
9463 mod_type_die
= new_die (DW_TAG_const_type
, mod_scope
, type
);
9464 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
9466 else if (is_volatile_type
)
9468 mod_type_die
= new_die (DW_TAG_volatile_type
, mod_scope
, type
);
9469 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
9471 else if (code
== POINTER_TYPE
)
9473 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
9474 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
9475 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
9476 item_type
= TREE_TYPE (type
);
9477 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
9478 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
9479 TYPE_ADDR_SPACE (item_type
));
9481 else if (code
== REFERENCE_TYPE
)
9483 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
9484 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
9487 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
9488 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
9489 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
9490 item_type
= TREE_TYPE (type
);
9491 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
9492 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
9493 TYPE_ADDR_SPACE (item_type
));
9495 else if (code
== INTEGER_TYPE
9496 && TREE_TYPE (type
) != NULL_TREE
9497 && subrange_type_for_debug_p (type
, &low
, &high
))
9499 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
9500 item_type
= TREE_TYPE (type
);
9502 else if (is_base_type (type
))
9503 mod_type_die
= base_type_die (type
);
9506 gen_type_die (type
, context_die
);
9508 /* We have to get the type_main_variant here (and pass that to the
9509 `lookup_type_die' routine) because the ..._TYPE node we have
9510 might simply be a *copy* of some original type node (where the
9511 copy was created to help us keep track of typedef names) and
9512 that copy might have a different TYPE_UID from the original
9514 if (TREE_CODE (type
) != VECTOR_TYPE
)
9515 return lookup_type_die (type_main_variant (type
));
9517 /* Vectors have the debugging information in the type,
9518 not the main variant. */
9519 return lookup_type_die (type
);
9522 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9523 don't output a DW_TAG_typedef, since there isn't one in the
9524 user's program; just attach a DW_AT_name to the type.
9525 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
9526 if the base type already has the same name. */
9528 && ((TREE_CODE (name
) != TYPE_DECL
9529 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
9530 || (!is_const_type
&& !is_volatile_type
)))
9531 || (TREE_CODE (name
) == TYPE_DECL
9532 && TREE_TYPE (name
) == qualified_type
9533 && DECL_NAME (name
))))
9535 if (TREE_CODE (name
) == TYPE_DECL
)
9536 /* Could just call add_name_and_src_coords_attributes here,
9537 but since this is a builtin type it doesn't have any
9538 useful source coordinates anyway. */
9539 name
= DECL_NAME (name
);
9540 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
9542 /* This probably indicates a bug. */
9543 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
9545 name
= TYPE_NAME (type
);
9547 && TREE_CODE (name
) == TYPE_DECL
)
9548 name
= DECL_NAME (name
);
9549 add_name_attribute (mod_type_die
,
9550 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
9554 equate_type_number_to_die (qualified_type
, mod_type_die
);
9557 /* We must do this after the equate_type_number_to_die call, in case
9558 this is a recursive type. This ensures that the modified_type_die
9559 recursion will terminate even if the type is recursive. Recursive
9560 types are possible in Ada. */
9561 sub_die
= modified_type_die (item_type
,
9562 TYPE_READONLY (item_type
),
9563 TYPE_VOLATILE (item_type
),
9566 if (sub_die
!= NULL
)
9567 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
9569 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
9570 if (TYPE_ARTIFICIAL (type
))
9571 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
9573 return mod_type_die
;
9576 /* Generate DIEs for the generic parameters of T.
9577 T must be either a generic type or a generic function.
9578 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
9581 gen_generic_params_dies (tree t
)
9585 dw_die_ref die
= NULL
;
9587 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
9591 die
= lookup_type_die (t
);
9592 else if (DECL_P (t
))
9593 die
= lookup_decl_die (t
);
9597 parms
= lang_hooks
.get_innermost_generic_parms (t
);
9599 /* T has no generic parameter. It means T is neither a generic type
9600 or function. End of story. */
9603 parms_num
= TREE_VEC_LENGTH (parms
);
9604 args
= lang_hooks
.get_innermost_generic_args (t
);
9605 for (i
= 0; i
< parms_num
; i
++)
9607 tree parm
, arg
, arg_pack_elems
;
9609 parm
= TREE_VEC_ELT (parms
, i
);
9610 arg
= TREE_VEC_ELT (args
, i
);
9611 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
9612 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
9614 if (parm
&& TREE_VALUE (parm
) && arg
)
9616 /* If PARM represents a template parameter pack,
9617 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
9618 by DW_TAG_template_*_parameter DIEs for the argument
9619 pack elements of ARG. Note that ARG would then be
9620 an argument pack. */
9622 template_parameter_pack_die (TREE_VALUE (parm
),
9626 generic_parameter_die (TREE_VALUE (parm
), arg
,
9627 true /* Emit DW_AT_name */, die
);
9632 /* Create and return a DIE for PARM which should be
9633 the representation of a generic type parameter.
9634 For instance, in the C++ front end, PARM would be a template parameter.
9635 ARG is the argument to PARM.
9636 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
9638 PARENT_DIE is the parent DIE which the new created DIE should be added to,
9642 generic_parameter_die (tree parm
, tree arg
,
9644 dw_die_ref parent_die
)
9646 dw_die_ref tmpl_die
= NULL
;
9647 const char *name
= NULL
;
9649 if (!parm
|| !DECL_NAME (parm
) || !arg
)
9652 /* We support non-type generic parameters and arguments,
9653 type generic parameters and arguments, as well as
9654 generic generic parameters (a.k.a. template template parameters in C++)
9656 if (TREE_CODE (parm
) == PARM_DECL
)
9657 /* PARM is a nontype generic parameter */
9658 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
9659 else if (TREE_CODE (parm
) == TYPE_DECL
)
9660 /* PARM is a type generic parameter. */
9661 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
9662 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
9663 /* PARM is a generic generic parameter.
9664 Its DIE is a GNU extension. It shall have a
9665 DW_AT_name attribute to represent the name of the template template
9666 parameter, and a DW_AT_GNU_template_name attribute to represent the
9667 name of the template template argument. */
9668 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
9677 /* If PARM is a generic parameter pack, it means we are
9678 emitting debug info for a template argument pack element.
9679 In other terms, ARG is a template argument pack element.
9680 In that case, we don't emit any DW_AT_name attribute for
9684 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
9686 add_AT_string (tmpl_die
, DW_AT_name
, name
);
9689 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
9691 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
9692 TMPL_DIE should have a child DW_AT_type attribute that is set
9693 to the type of the argument to PARM, which is ARG.
9694 If PARM is a type generic parameter, TMPL_DIE should have a
9695 child DW_AT_type that is set to ARG. */
9696 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
9697 add_type_attribute (tmpl_die
, tmpl_type
, 0,
9698 TREE_THIS_VOLATILE (tmpl_type
),
9703 /* So TMPL_DIE is a DIE representing a
9704 a generic generic template parameter, a.k.a template template
9705 parameter in C++ and arg is a template. */
9707 /* The DW_AT_GNU_template_name attribute of the DIE must be set
9708 to the name of the argument. */
9709 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
9711 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
9714 if (TREE_CODE (parm
) == PARM_DECL
)
9715 /* So PARM is a non-type generic parameter.
9716 DWARF3 5.6.8 says we must set a DW_AT_const_value child
9717 attribute of TMPL_DIE which value represents the value
9719 We must be careful here:
9720 The value of ARG might reference some function decls.
9721 We might currently be emitting debug info for a generic
9722 type and types are emitted before function decls, we don't
9723 know if the function decls referenced by ARG will actually be
9724 emitted after cgraph computations.
9725 So must defer the generation of the DW_AT_const_value to
9726 after cgraph is ready. */
9727 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
9733 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
9734 PARM_PACK must be a template parameter pack. The returned DIE
9735 will be child DIE of PARENT_DIE. */
9738 template_parameter_pack_die (tree parm_pack
,
9739 tree parm_pack_args
,
9740 dw_die_ref parent_die
)
9745 gcc_assert (parent_die
&& parm_pack
);
9747 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
9748 add_name_and_src_coords_attributes (die
, parm_pack
);
9749 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
9750 generic_parameter_die (parm_pack
,
9751 TREE_VEC_ELT (parm_pack_args
, j
),
9752 false /* Don't emit DW_AT_name */,
9757 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
9758 an enumerated type. */
9761 type_is_enum (const_tree type
)
9763 return TREE_CODE (type
) == ENUMERAL_TYPE
;
9766 /* Return the DBX register number described by a given RTL node. */
9769 dbx_reg_number (const_rtx rtl
)
9771 unsigned regno
= REGNO (rtl
);
9773 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
9775 #ifdef LEAF_REG_REMAP
9776 if (crtl
->uses_only_leaf_regs
)
9778 int leaf_reg
= LEAF_REG_REMAP (regno
);
9780 regno
= (unsigned) leaf_reg
;
9784 regno
= DBX_REGISTER_NUMBER (regno
);
9785 gcc_assert (regno
!= INVALID_REGNUM
);
9789 /* Optionally add a DW_OP_piece term to a location description expression.
9790 DW_OP_piece is only added if the location description expression already
9791 doesn't end with DW_OP_piece. */
9794 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
9796 dw_loc_descr_ref loc
;
9798 if (*list_head
!= NULL
)
9800 /* Find the end of the chain. */
9801 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
9804 if (loc
->dw_loc_opc
!= DW_OP_piece
)
9805 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
9809 /* Return a location descriptor that designates a machine register or
9810 zero if there is none. */
9812 static dw_loc_descr_ref
9813 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
9817 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
9820 /* We only use "frame base" when we're sure we're talking about the
9821 post-prologue local stack frame. We do this by *not* running
9822 register elimination until this point, and recognizing the special
9823 argument pointer and soft frame pointer rtx's.
9824 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
9825 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
9826 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
9828 dw_loc_descr_ref result
= NULL
;
9830 if (dwarf_version
>= 4 || !dwarf_strict
)
9832 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
9835 add_loc_descr (&result
,
9836 new_loc_descr (DW_OP_stack_value
, 0, 0));
9841 regs
= targetm
.dwarf_register_span (rtl
);
9843 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
9844 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
9846 return one_reg_loc_descriptor (dbx_reg_number (rtl
), initialized
);
9849 /* Return a location descriptor that designates a machine register for
9850 a given hard register number. */
9852 static dw_loc_descr_ref
9853 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
9855 dw_loc_descr_ref reg_loc_descr
;
9859 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
9861 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
9863 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9864 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9866 return reg_loc_descr
;
9869 /* Given an RTL of a register, return a location descriptor that
9870 designates a value that spans more than one register. */
9872 static dw_loc_descr_ref
9873 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
9874 enum var_init_status initialized
)
9878 dw_loc_descr_ref loc_result
= NULL
;
9881 #ifdef LEAF_REG_REMAP
9882 if (crtl
->uses_only_leaf_regs
)
9884 int leaf_reg
= LEAF_REG_REMAP (reg
);
9886 reg
= (unsigned) leaf_reg
;
9889 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
9890 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
9892 /* Simple, contiguous registers. */
9893 if (regs
== NULL_RTX
)
9895 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
9902 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
9903 VAR_INIT_STATUS_INITIALIZED
);
9904 add_loc_descr (&loc_result
, t
);
9905 add_loc_descr_op_piece (&loc_result
, size
);
9911 /* Now onto stupid register sets in non contiguous locations. */
9913 gcc_assert (GET_CODE (regs
) == PARALLEL
);
9915 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
9918 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
9922 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
9923 VAR_INIT_STATUS_INITIALIZED
);
9924 add_loc_descr (&loc_result
, t
);
9925 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
9926 add_loc_descr_op_piece (&loc_result
, size
);
9929 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9930 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9934 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
9936 /* Return a location descriptor that designates a constant i,
9937 as a compound operation from constant (i >> shift), constant shift
9940 static dw_loc_descr_ref
9941 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
9943 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
9944 add_loc_descr (&ret
, int_loc_descriptor (shift
));
9945 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
9949 /* Return a location descriptor that designates a constant. */
9951 static dw_loc_descr_ref
9952 int_loc_descriptor (HOST_WIDE_INT i
)
9954 enum dwarf_location_atom op
;
9956 /* Pick the smallest representation of a constant, rather than just
9957 defaulting to the LEB encoding. */
9960 int clz
= clz_hwi (i
);
9961 int ctz
= ctz_hwi (i
);
9963 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
9966 else if (i
<= 0xffff)
9968 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
9969 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
9970 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
9971 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
9972 while DW_OP_const4u is 5 bytes. */
9973 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
9974 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
9975 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
9976 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
9977 while DW_OP_const4u is 5 bytes. */
9978 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
9979 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
9981 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
9982 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
9983 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
9984 while DW_OP_constu of constant >= 0x100000000 takes at least
9986 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
9987 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
9988 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
9989 >= HOST_BITS_PER_WIDE_INT
)
9990 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
9991 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
9992 while DW_OP_constu takes in this case at least 6 bytes. */
9993 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
9994 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
9995 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
9996 && size_of_uleb128 (i
) > 6)
9997 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
9998 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
10005 op
= DW_OP_const1s
;
10006 else if (i
>= -0x8000)
10007 op
= DW_OP_const2s
;
10008 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10010 if (size_of_int_loc_descriptor (i
) < 5)
10012 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10013 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10016 op
= DW_OP_const4s
;
10020 if (size_of_int_loc_descriptor (i
)
10021 < (unsigned long) 1 + size_of_sleb128 (i
))
10023 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10024 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10031 return new_loc_descr (op
, i
, 0);
10034 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10035 without actually allocating it. */
10037 static unsigned long
10038 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10040 return size_of_int_loc_descriptor (i
>> shift
)
10041 + size_of_int_loc_descriptor (shift
)
10045 /* Return size_of_locs (int_loc_descriptor (i)) without
10046 actually allocating it. */
10048 static unsigned long
10049 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
10058 else if (i
<= 0xff)
10060 else if (i
<= 0xffff)
10064 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10065 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10066 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10068 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10069 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10070 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10072 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10074 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
10075 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10076 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10077 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10079 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10080 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
10081 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10083 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10084 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10086 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10095 else if (i
>= -0x8000)
10097 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10099 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10101 s
= size_of_int_loc_descriptor (-i
) + 1;
10109 unsigned long r
= 1 + size_of_sleb128 (i
);
10110 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10112 s
= size_of_int_loc_descriptor (-i
) + 1;
10121 /* Return loc description representing "address" of integer value.
10122 This can appear only as toplevel expression. */
10124 static dw_loc_descr_ref
10125 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
10128 dw_loc_descr_ref loc_result
= NULL
;
10130 if (!(dwarf_version
>= 4 || !dwarf_strict
))
10133 litsize
= size_of_int_loc_descriptor (i
);
10134 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10135 is more compact. For DW_OP_stack_value we need:
10136 litsize + 1 (DW_OP_stack_value)
10137 and for DW_OP_implicit_value:
10138 1 (DW_OP_implicit_value) + 1 (length) + size. */
10139 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
10141 loc_result
= int_loc_descriptor (i
);
10142 add_loc_descr (&loc_result
,
10143 new_loc_descr (DW_OP_stack_value
, 0, 0));
10147 loc_result
= new_loc_descr (DW_OP_implicit_value
,
10149 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
10150 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
10154 /* Return a location descriptor that designates a base+offset location. */
10156 static dw_loc_descr_ref
10157 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
10158 enum var_init_status initialized
)
10160 unsigned int regno
;
10161 dw_loc_descr_ref result
;
10162 dw_fde_ref fde
= cfun
->fde
;
10164 /* We only use "frame base" when we're sure we're talking about the
10165 post-prologue local stack frame. We do this by *not* running
10166 register elimination until this point, and recognizing the special
10167 argument pointer and soft frame pointer rtx's. */
10168 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
10170 rtx elim
= (ira_use_lra_p
10171 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
10172 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
10176 if (GET_CODE (elim
) == PLUS
)
10178 offset
+= INTVAL (XEXP (elim
, 1));
10179 elim
= XEXP (elim
, 0);
10181 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10182 && (elim
== hard_frame_pointer_rtx
10183 || elim
== stack_pointer_rtx
))
10184 || elim
== (frame_pointer_needed
10185 ? hard_frame_pointer_rtx
10186 : stack_pointer_rtx
));
10188 /* If drap register is used to align stack, use frame
10189 pointer + offset to access stack variables. If stack
10190 is aligned without drap, use stack pointer + offset to
10191 access stack variables. */
10192 if (crtl
->stack_realign_tried
10193 && reg
== frame_pointer_rtx
)
10196 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
10197 ? HARD_FRAME_POINTER_REGNUM
10199 return new_reg_loc_descr (base_reg
, offset
);
10202 gcc_assert (frame_pointer_fb_offset_valid
);
10203 offset
+= frame_pointer_fb_offset
;
10204 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10208 regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
10210 if (!optimize
&& fde
10211 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
10213 /* Use cfa+offset to represent the location of arguments passed
10214 on the stack when drap is used to align stack.
10215 Only do this when not optimizing, for optimized code var-tracking
10216 is supposed to track where the arguments live and the register
10217 used as vdrap or drap in some spot might be used for something
10218 else in other part of the routine. */
10219 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10223 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
10226 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
10228 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10229 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10234 /* Return true if this RTL expression describes a base+offset calculation. */
10237 is_based_loc (const_rtx rtl
)
10239 return (GET_CODE (rtl
) == PLUS
10240 && ((REG_P (XEXP (rtl
, 0))
10241 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
10242 && CONST_INT_P (XEXP (rtl
, 1)))));
10245 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10248 static dw_loc_descr_ref
10249 tls_mem_loc_descriptor (rtx mem
)
10252 dw_loc_descr_ref loc_result
;
10254 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
10257 base
= get_base_address (MEM_EXPR (mem
));
10259 || TREE_CODE (base
) != VAR_DECL
10260 || !DECL_THREAD_LOCAL_P (base
))
10263 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
10264 if (loc_result
== NULL
)
10267 if (MEM_OFFSET (mem
))
10268 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
10273 /* Output debug info about reason why we failed to expand expression as dwarf
10277 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
10279 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
10281 fprintf (dump_file
, "Failed to expand as dwarf: ");
10283 print_generic_expr (dump_file
, expr
, dump_flags
);
10286 fprintf (dump_file
, "\n");
10287 print_rtl (dump_file
, rtl
);
10289 fprintf (dump_file
, "\nReason: %s\n", reason
);
10293 /* Helper function for const_ok_for_output, called either directly
10294 or via for_each_rtx. */
10297 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
10301 if (GET_CODE (rtl
) == UNSPEC
)
10303 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
10304 we can't express it in the debug info. */
10305 #ifdef ENABLE_CHECKING
10306 /* Don't complain about TLS UNSPECs, those are just too hard to
10307 delegitimize. Note this could be a non-decl SYMBOL_REF such as
10308 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
10309 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
10310 if (XVECLEN (rtl
, 0) == 0
10311 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
10312 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
10313 inform (current_function_decl
10314 ? DECL_SOURCE_LOCATION (current_function_decl
)
10315 : UNKNOWN_LOCATION
,
10316 #if NUM_UNSPEC_VALUES > 0
10317 "non-delegitimized UNSPEC %s (%d) found in variable location",
10318 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
10319 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
10322 "non-delegitimized UNSPEC %d found in variable location",
10326 expansion_failed (NULL_TREE
, rtl
,
10327 "UNSPEC hasn't been delegitimized.\n");
10331 if (targetm
.const_not_ok_for_debug_p (rtl
))
10333 expansion_failed (NULL_TREE
, rtl
,
10334 "Expression rejected for debug by the backend.\n");
10338 if (GET_CODE (rtl
) != SYMBOL_REF
)
10341 if (CONSTANT_POOL_ADDRESS_P (rtl
))
10344 get_pool_constant_mark (rtl
, &marked
);
10345 /* If all references to this pool constant were optimized away,
10346 it was not output and thus we can't represent it. */
10349 expansion_failed (NULL_TREE
, rtl
,
10350 "Constant was removed from constant pool.\n");
10355 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
10358 /* Avoid references to external symbols in debug info, on several targets
10359 the linker might even refuse to link when linking a shared library,
10360 and in many other cases the relocations for .debug_info/.debug_loc are
10361 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
10362 to be defined within the same shared library or executable are fine. */
10363 if (SYMBOL_REF_EXTERNAL_P (rtl
))
10365 tree decl
= SYMBOL_REF_DECL (rtl
);
10367 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
10369 expansion_failed (NULL_TREE
, rtl
,
10370 "Symbol not defined in current TU.\n");
10378 /* Return true if constant RTL can be emitted in DW_OP_addr or
10379 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
10380 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
10383 const_ok_for_output (rtx rtl
)
10385 if (GET_CODE (rtl
) == SYMBOL_REF
)
10386 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
10388 if (GET_CODE (rtl
) == CONST
)
10389 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
10394 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
10395 if possible, NULL otherwise. */
10398 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
10400 dw_die_ref type_die
;
10401 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
10405 switch (TREE_CODE (type
))
10413 type_die
= lookup_type_die (type
);
10415 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
10416 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
10421 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
10422 type matching MODE, or, if MODE is narrower than or as wide as
10423 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
10426 static dw_loc_descr_ref
10427 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
10429 enum machine_mode outer_mode
= mode
;
10430 dw_die_ref type_die
;
10431 dw_loc_descr_ref cvt
;
10433 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
10435 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
10438 type_die
= base_type_for_mode (outer_mode
, 1);
10439 if (type_die
== NULL
)
10441 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10442 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10443 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10444 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10445 add_loc_descr (&op
, cvt
);
10449 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
10451 static dw_loc_descr_ref
10452 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
10453 dw_loc_descr_ref op1
)
10455 dw_loc_descr_ref ret
= op0
;
10456 add_loc_descr (&ret
, op1
);
10457 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
10458 if (STORE_FLAG_VALUE
!= 1)
10460 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
10461 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
10466 /* Return location descriptor for signed comparison OP RTL. */
10468 static dw_loc_descr_ref
10469 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
10470 enum machine_mode mem_mode
)
10472 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
10473 dw_loc_descr_ref op0
, op1
;
10476 if (op_mode
== VOIDmode
)
10477 op_mode
= GET_MODE (XEXP (rtl
, 1));
10478 if (op_mode
== VOIDmode
)
10482 && (GET_MODE_CLASS (op_mode
) != MODE_INT
10483 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
10486 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
10487 VAR_INIT_STATUS_INITIALIZED
);
10488 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
10489 VAR_INIT_STATUS_INITIALIZED
);
10491 if (op0
== NULL
|| op1
== NULL
)
10494 if (GET_MODE_CLASS (op_mode
) != MODE_INT
10495 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
10496 return compare_loc_descriptor (op
, op0
, op1
);
10498 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
10500 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
10501 dw_loc_descr_ref cvt
;
10503 if (type_die
== NULL
)
10505 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10506 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10507 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10508 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10509 add_loc_descr (&op0
, cvt
);
10510 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10511 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10512 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10513 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10514 add_loc_descr (&op1
, cvt
);
10515 return compare_loc_descriptor (op
, op0
, op1
);
10518 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
10519 /* For eq/ne, if the operands are known to be zero-extended,
10520 there is no need to do the fancy shifting up. */
10521 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
10523 dw_loc_descr_ref last0
, last1
;
10524 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
10526 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
10528 /* deref_size zero extends, and for constants we can check
10529 whether they are zero extended or not. */
10530 if (((last0
->dw_loc_opc
== DW_OP_deref_size
10531 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
10532 || (CONST_INT_P (XEXP (rtl
, 0))
10533 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
10534 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
10535 && ((last1
->dw_loc_opc
== DW_OP_deref_size
10536 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
10537 || (CONST_INT_P (XEXP (rtl
, 1))
10538 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
10539 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
10540 return compare_loc_descriptor (op
, op0
, op1
);
10542 /* EQ/NE comparison against constant in narrower type than
10543 DWARF2_ADDR_SIZE can be performed either as
10544 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
10547 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
10548 DW_OP_{eq,ne}. Pick whatever is shorter. */
10549 if (CONST_INT_P (XEXP (rtl
, 1))
10550 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
10551 && (size_of_int_loc_descriptor (shift
) + 1
10552 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
10553 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
10554 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
10555 & GET_MODE_MASK (op_mode
))))
10557 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
10558 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
10559 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
10560 & GET_MODE_MASK (op_mode
));
10561 return compare_loc_descriptor (op
, op0
, op1
);
10564 add_loc_descr (&op0
, int_loc_descriptor (shift
));
10565 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
10566 if (CONST_INT_P (XEXP (rtl
, 1)))
10567 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
10570 add_loc_descr (&op1
, int_loc_descriptor (shift
));
10571 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
10573 return compare_loc_descriptor (op
, op0
, op1
);
10576 /* Return location descriptor for unsigned comparison OP RTL. */
10578 static dw_loc_descr_ref
10579 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
10580 enum machine_mode mem_mode
)
10582 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
10583 dw_loc_descr_ref op0
, op1
;
10585 if (op_mode
== VOIDmode
)
10586 op_mode
= GET_MODE (XEXP (rtl
, 1));
10587 if (op_mode
== VOIDmode
)
10589 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
10592 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
10595 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
10596 VAR_INIT_STATUS_INITIALIZED
);
10597 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
10598 VAR_INIT_STATUS_INITIALIZED
);
10600 if (op0
== NULL
|| op1
== NULL
)
10603 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
10605 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
10606 dw_loc_descr_ref last0
, last1
;
10607 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
10609 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
10611 if (CONST_INT_P (XEXP (rtl
, 0)))
10612 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
10613 /* deref_size zero extends, so no need to mask it again. */
10614 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
10615 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
10617 add_loc_descr (&op0
, int_loc_descriptor (mask
));
10618 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
10620 if (CONST_INT_P (XEXP (rtl
, 1)))
10621 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
10622 /* deref_size zero extends, so no need to mask it again. */
10623 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
10624 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
10626 add_loc_descr (&op1
, int_loc_descriptor (mask
));
10627 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
10630 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
10632 HOST_WIDE_INT bias
= 1;
10633 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
10634 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
10635 if (CONST_INT_P (XEXP (rtl
, 1)))
10636 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
10637 + INTVAL (XEXP (rtl
, 1)));
10639 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
10642 return compare_loc_descriptor (op
, op0
, op1
);
10645 /* Return location descriptor for {U,S}{MIN,MAX}. */
10647 static dw_loc_descr_ref
10648 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
10649 enum machine_mode mem_mode
)
10651 enum dwarf_location_atom op
;
10652 dw_loc_descr_ref op0
, op1
, ret
;
10653 dw_loc_descr_ref bra_node
, drop_node
;
10656 && (GET_MODE_CLASS (mode
) != MODE_INT
10657 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
10660 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
10661 VAR_INIT_STATUS_INITIALIZED
);
10662 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
10663 VAR_INIT_STATUS_INITIALIZED
);
10665 if (op0
== NULL
|| op1
== NULL
)
10668 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
10669 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
10670 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
10671 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
10673 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
10675 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
10676 add_loc_descr (&op0
, int_loc_descriptor (mask
));
10677 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
10678 add_loc_descr (&op1
, int_loc_descriptor (mask
));
10679 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
10681 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
10683 HOST_WIDE_INT bias
= 1;
10684 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
10685 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
10686 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
10689 else if (GET_MODE_CLASS (mode
) == MODE_INT
10690 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
10692 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
10693 add_loc_descr (&op0
, int_loc_descriptor (shift
));
10694 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
10695 add_loc_descr (&op1
, int_loc_descriptor (shift
));
10696 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
10698 else if (GET_MODE_CLASS (mode
) == MODE_INT
10699 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
10701 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
10702 dw_loc_descr_ref cvt
;
10703 if (type_die
== NULL
)
10705 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10706 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10707 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10708 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10709 add_loc_descr (&op0
, cvt
);
10710 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10711 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10712 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10713 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10714 add_loc_descr (&op1
, cvt
);
10717 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
10722 add_loc_descr (&ret
, op1
);
10723 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
10724 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
10725 add_loc_descr (&ret
, bra_node
);
10726 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
10727 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
10728 add_loc_descr (&ret
, drop_node
);
10729 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10730 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
10731 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
10732 && GET_MODE_CLASS (mode
) == MODE_INT
10733 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
10734 ret
= convert_descriptor_to_mode (mode
, ret
);
10738 /* Helper function for mem_loc_descriptor. Perform OP binary op,
10739 but after converting arguments to type_die, afterwards
10740 convert back to unsigned. */
10742 static dw_loc_descr_ref
10743 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
10744 enum machine_mode mode
, enum machine_mode mem_mode
)
10746 dw_loc_descr_ref cvt
, op0
, op1
;
10748 if (type_die
== NULL
)
10750 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
10751 VAR_INIT_STATUS_INITIALIZED
);
10752 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
10753 VAR_INIT_STATUS_INITIALIZED
);
10754 if (op0
== NULL
|| op1
== NULL
)
10756 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10757 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10758 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10759 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10760 add_loc_descr (&op0
, cvt
);
10761 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10762 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10763 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10764 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10765 add_loc_descr (&op1
, cvt
);
10766 add_loc_descr (&op0
, op1
);
10767 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
10768 return convert_descriptor_to_mode (mode
, op0
);
10771 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
10772 const0 is DW_OP_lit0 or corresponding typed constant,
10773 const1 is DW_OP_lit1 or corresponding typed constant
10774 and constMSB is constant with just the MSB bit set
10776 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
10777 L1: const0 DW_OP_swap
10778 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
10779 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
10784 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
10785 L1: const0 DW_OP_swap
10786 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
10787 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
10792 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
10793 L1: const1 DW_OP_swap
10794 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
10795 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
10799 static dw_loc_descr_ref
10800 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
10801 enum machine_mode mem_mode
)
10803 dw_loc_descr_ref op0
, ret
, tmp
;
10804 HOST_WIDE_INT valv
;
10805 dw_loc_descr_ref l1jump
, l1label
;
10806 dw_loc_descr_ref l2jump
, l2label
;
10807 dw_loc_descr_ref l3jump
, l3label
;
10808 dw_loc_descr_ref l4jump
, l4label
;
10811 if (GET_MODE_CLASS (mode
) != MODE_INT
10812 || GET_MODE (XEXP (rtl
, 0)) != mode
10813 || (GET_CODE (rtl
) == CLZ
10814 && GET_MODE_BITSIZE (mode
) > HOST_BITS_PER_DOUBLE_INT
))
10817 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
10818 VAR_INIT_STATUS_INITIALIZED
);
10822 if (GET_CODE (rtl
) == CLZ
)
10824 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
10825 valv
= GET_MODE_BITSIZE (mode
);
10827 else if (GET_CODE (rtl
) == FFS
)
10829 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
10830 valv
= GET_MODE_BITSIZE (mode
);
10831 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
10832 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
10833 add_loc_descr (&ret
, l1jump
);
10834 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
10835 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
10836 VAR_INIT_STATUS_INITIALIZED
);
10839 add_loc_descr (&ret
, tmp
);
10840 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
10841 add_loc_descr (&ret
, l4jump
);
10842 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
10843 ? const1_rtx
: const0_rtx
,
10845 VAR_INIT_STATUS_INITIALIZED
);
10846 if (l1label
== NULL
)
10848 add_loc_descr (&ret
, l1label
);
10849 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
10850 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
10851 add_loc_descr (&ret
, l2label
);
10852 if (GET_CODE (rtl
) != CLZ
)
10854 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
10855 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
10856 << (GET_MODE_BITSIZE (mode
) - 1));
10858 msb
= immed_double_const (0, (unsigned HOST_WIDE_INT
) 1
10859 << (GET_MODE_BITSIZE (mode
)
10860 - HOST_BITS_PER_WIDE_INT
- 1), mode
);
10861 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
10862 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
10863 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
10864 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
10866 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
10867 VAR_INIT_STATUS_INITIALIZED
);
10870 add_loc_descr (&ret
, tmp
);
10871 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
10872 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
10873 add_loc_descr (&ret
, l3jump
);
10874 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
10875 VAR_INIT_STATUS_INITIALIZED
);
10878 add_loc_descr (&ret
, tmp
);
10879 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
10880 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
10881 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
10882 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
10883 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
10884 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
10885 add_loc_descr (&ret
, l2jump
);
10886 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
10887 add_loc_descr (&ret
, l3label
);
10888 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
10889 add_loc_descr (&ret
, l4label
);
10890 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10891 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
10892 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10893 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
10894 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10895 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
10896 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10897 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
10901 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
10902 const1 is DW_OP_lit1 or corresponding typed constant):
10904 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
10905 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
10909 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
10910 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
10913 static dw_loc_descr_ref
10914 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
10915 enum machine_mode mem_mode
)
10917 dw_loc_descr_ref op0
, ret
, tmp
;
10918 dw_loc_descr_ref l1jump
, l1label
;
10919 dw_loc_descr_ref l2jump
, l2label
;
10921 if (GET_MODE_CLASS (mode
) != MODE_INT
10922 || GET_MODE (XEXP (rtl
, 0)) != mode
)
10925 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
10926 VAR_INIT_STATUS_INITIALIZED
);
10930 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
10931 VAR_INIT_STATUS_INITIALIZED
);
10934 add_loc_descr (&ret
, tmp
);
10935 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
10936 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
10937 add_loc_descr (&ret
, l1label
);
10938 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
10939 add_loc_descr (&ret
, l2jump
);
10940 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
10941 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
10942 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
10943 VAR_INIT_STATUS_INITIALIZED
);
10946 add_loc_descr (&ret
, tmp
);
10947 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
10948 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
10949 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
10950 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
10951 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
10952 VAR_INIT_STATUS_INITIALIZED
);
10953 add_loc_descr (&ret
, tmp
);
10954 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
10955 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
10956 add_loc_descr (&ret
, l1jump
);
10957 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
10958 add_loc_descr (&ret
, l2label
);
10959 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10960 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
10961 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10962 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
10966 /* BSWAP (constS is initial shift count, either 56 or 24):
10968 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
10969 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
10970 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
10971 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
10972 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
10974 static dw_loc_descr_ref
10975 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
10976 enum machine_mode mem_mode
)
10978 dw_loc_descr_ref op0
, ret
, tmp
;
10979 dw_loc_descr_ref l1jump
, l1label
;
10980 dw_loc_descr_ref l2jump
, l2label
;
10982 if (GET_MODE_CLASS (mode
) != MODE_INT
10983 || BITS_PER_UNIT
!= 8
10984 || (GET_MODE_BITSIZE (mode
) != 32
10985 && GET_MODE_BITSIZE (mode
) != 64))
10988 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
10989 VAR_INIT_STATUS_INITIALIZED
);
10994 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
10996 VAR_INIT_STATUS_INITIALIZED
);
10999 add_loc_descr (&ret
, tmp
);
11000 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11001 VAR_INIT_STATUS_INITIALIZED
);
11004 add_loc_descr (&ret
, tmp
);
11005 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
11006 add_loc_descr (&ret
, l1label
);
11007 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11009 VAR_INIT_STATUS_INITIALIZED
);
11010 add_loc_descr (&ret
, tmp
);
11011 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
11012 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11013 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11014 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
11015 VAR_INIT_STATUS_INITIALIZED
);
11018 add_loc_descr (&ret
, tmp
);
11019 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11020 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
11021 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11022 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11023 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11024 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11025 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11026 VAR_INIT_STATUS_INITIALIZED
);
11027 add_loc_descr (&ret
, tmp
);
11028 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
11029 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11030 add_loc_descr (&ret
, l2jump
);
11031 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
11032 VAR_INIT_STATUS_INITIALIZED
);
11033 add_loc_descr (&ret
, tmp
);
11034 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11035 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11036 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11037 add_loc_descr (&ret
, l1jump
);
11038 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11039 add_loc_descr (&ret
, l2label
);
11040 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11041 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11042 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11043 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11044 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11045 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11049 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
11050 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11051 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
11052 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
11054 ROTATERT is similar:
11055 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
11056 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11057 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
11059 static dw_loc_descr_ref
11060 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11061 enum machine_mode mem_mode
)
11063 rtx rtlop1
= XEXP (rtl
, 1);
11064 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
11067 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11070 if (GET_MODE (rtlop1
) != VOIDmode
11071 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
11072 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
11073 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11074 VAR_INIT_STATUS_INITIALIZED
);
11075 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
11076 VAR_INIT_STATUS_INITIALIZED
);
11077 if (op0
== NULL
|| op1
== NULL
)
11079 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11080 for (i
= 0; i
< 2; i
++)
11082 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
11083 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
11085 VAR_INIT_STATUS_INITIALIZED
);
11086 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
11087 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11089 : HOST_BITS_PER_WIDE_INT
== 64
11090 ? DW_OP_const8u
: DW_OP_constu
,
11091 GET_MODE_MASK (mode
), 0);
11094 if (mask
[i
] == NULL
)
11096 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
11099 add_loc_descr (&ret
, op1
);
11100 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11101 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11102 if (GET_CODE (rtl
) == ROTATERT
)
11104 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11105 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11106 GET_MODE_BITSIZE (mode
), 0));
11108 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11109 if (mask
[0] != NULL
)
11110 add_loc_descr (&ret
, mask
[0]);
11111 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11112 if (mask
[1] != NULL
)
11114 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11115 add_loc_descr (&ret
, mask
[1]);
11116 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11118 if (GET_CODE (rtl
) == ROTATE
)
11120 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11121 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11122 GET_MODE_BITSIZE (mode
), 0));
11124 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11125 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11129 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11130 for DEBUG_PARAMETER_REF RTL. */
11132 static dw_loc_descr_ref
11133 parameter_ref_descriptor (rtx rtl
)
11135 dw_loc_descr_ref ret
;
11140 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
11141 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
11142 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
11145 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11146 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
11147 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11151 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
11152 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
11157 /* The following routine converts the RTL for a variable or parameter
11158 (resident in memory) into an equivalent Dwarf representation of a
11159 mechanism for getting the address of that same variable onto the top of a
11160 hypothetical "address evaluation" stack.
11162 When creating memory location descriptors, we are effectively transforming
11163 the RTL for a memory-resident object into its Dwarf postfix expression
11164 equivalent. This routine recursively descends an RTL tree, turning
11165 it into Dwarf postfix code as it goes.
11167 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
11169 MEM_MODE is the mode of the memory reference, needed to handle some
11170 autoincrement addressing modes.
11172 Return 0 if we can't represent the location. */
11175 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11176 enum machine_mode mem_mode
,
11177 enum var_init_status initialized
)
11179 dw_loc_descr_ref mem_loc_result
= NULL
;
11180 enum dwarf_location_atom op
;
11181 dw_loc_descr_ref op0
, op1
;
11183 if (mode
== VOIDmode
)
11184 mode
= GET_MODE (rtl
);
11186 /* Note that for a dynamically sized array, the location we will generate a
11187 description of here will be the lowest numbered location which is
11188 actually within the array. That's *not* necessarily the same as the
11189 zeroth element of the array. */
11191 rtl
= targetm
.delegitimize_address (rtl
);
11193 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
11196 switch (GET_CODE (rtl
))
11201 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
11204 /* The case of a subreg may arise when we have a local (register)
11205 variable or a formal (register) parameter which doesn't quite fill
11206 up an entire register. For now, just assume that it is
11207 legitimate to make the Dwarf info refer to the whole register which
11208 contains the given subreg. */
11209 if (!subreg_lowpart_p (rtl
))
11211 if (GET_MODE_CLASS (mode
) == MODE_INT
11212 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl
))) == MODE_INT
11213 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11214 #ifdef POINTERS_EXTEND_UNSIGNED
11215 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
11218 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
))) <= DWARF2_ADDR_SIZE
)
11220 mem_loc_result
= mem_loc_descriptor (SUBREG_REG (rtl
),
11221 GET_MODE (SUBREG_REG (rtl
)),
11222 mem_mode
, initialized
);
11227 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
))))
11229 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
)))
11230 && (GET_MODE_CLASS (mode
) != MODE_INT
11231 || GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl
))) != MODE_INT
))
11235 dw_die_ref type_die
;
11236 dw_loc_descr_ref cvt
;
11238 mem_loc_result
= mem_loc_descriptor (SUBREG_REG (rtl
),
11239 GET_MODE (SUBREG_REG (rtl
)),
11240 mem_mode
, initialized
);
11241 if (mem_loc_result
== NULL
)
11243 type_die
= base_type_for_mode (mode
,
11244 GET_MODE_CLASS (mode
) == MODE_INT
);
11245 if (type_die
== NULL
)
11247 mem_loc_result
= NULL
;
11250 if (GET_MODE_SIZE (mode
)
11251 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
))))
11252 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11254 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
11255 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11256 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11257 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11258 add_loc_descr (&mem_loc_result
, cvt
);
11263 if (GET_MODE_CLASS (mode
) != MODE_INT
11264 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
11265 && rtl
!= arg_pointer_rtx
11266 && rtl
!= frame_pointer_rtx
11267 #ifdef POINTERS_EXTEND_UNSIGNED
11268 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
11272 dw_die_ref type_die
;
11276 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
11278 type_die
= base_type_for_mode (mode
,
11279 GET_MODE_CLASS (mode
) == MODE_INT
);
11280 if (type_die
== NULL
)
11282 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
11283 dbx_reg_number (rtl
), 0);
11284 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
11285 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
11286 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
11289 /* Whenever a register number forms a part of the description of the
11290 method for calculating the (dynamic) address of a memory resident
11291 object, DWARF rules require the register number be referred to as
11292 a "base register". This distinction is not based in any way upon
11293 what category of register the hardware believes the given register
11294 belongs to. This is strictly DWARF terminology we're dealing with
11295 here. Note that in cases where the location of a memory-resident
11296 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
11297 OP_CONST (0)) the actual DWARF location descriptor that we generate
11298 may just be OP_BASEREG (basereg). This may look deceptively like
11299 the object in question was allocated to a register (rather than in
11300 memory) so DWARF consumers need to be aware of the subtle
11301 distinction between OP_REG and OP_BASEREG. */
11302 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
11303 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
11304 else if (stack_realign_drap
11306 && crtl
->args
.internal_arg_pointer
== rtl
11307 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
11309 /* If RTL is internal_arg_pointer, which has been optimized
11310 out, use DRAP instead. */
11311 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
11312 VAR_INIT_STATUS_INITIALIZED
);
11318 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11320 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
11321 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
11324 else if (GET_CODE (rtl
) == ZERO_EXTEND
11325 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11326 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
11327 < HOST_BITS_PER_WIDE_INT
11328 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
11329 to expand zero extend as two shifts instead of
11331 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
11333 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
11334 mem_loc_result
= op0
;
11335 add_loc_descr (&mem_loc_result
,
11336 int_loc_descriptor (GET_MODE_MASK (imode
)));
11337 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
11339 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11341 int shift
= DWARF2_ADDR_SIZE
11342 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
11343 shift
*= BITS_PER_UNIT
;
11344 if (GET_CODE (rtl
) == SIGN_EXTEND
)
11348 mem_loc_result
= op0
;
11349 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
11350 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
11351 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
11352 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
11354 else if (!dwarf_strict
)
11356 dw_die_ref type_die1
, type_die2
;
11357 dw_loc_descr_ref cvt
;
11359 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
11360 GET_CODE (rtl
) == ZERO_EXTEND
);
11361 if (type_die1
== NULL
)
11363 type_die2
= base_type_for_mode (mode
, 1);
11364 if (type_die2
== NULL
)
11366 mem_loc_result
= op0
;
11367 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11368 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11369 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
11370 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11371 add_loc_descr (&mem_loc_result
, cvt
);
11372 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11373 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11374 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
11375 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11376 add_loc_descr (&mem_loc_result
, cvt
);
11382 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
11383 if (new_rtl
!= rtl
)
11385 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
11387 if (mem_loc_result
!= NULL
)
11388 return mem_loc_result
;
11391 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
11392 get_address_mode (rtl
), mode
,
11393 VAR_INIT_STATUS_INITIALIZED
);
11394 if (mem_loc_result
== NULL
)
11395 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
11396 if (mem_loc_result
!= NULL
)
11398 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
11399 || GET_MODE_CLASS (mode
) != MODE_INT
)
11401 dw_die_ref type_die
;
11402 dw_loc_descr_ref deref
;
11407 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
11408 if (type_die
== NULL
)
11410 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
11411 GET_MODE_SIZE (mode
), 0);
11412 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
11413 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
11414 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
11415 add_loc_descr (&mem_loc_result
, deref
);
11417 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11418 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
11420 add_loc_descr (&mem_loc_result
,
11421 new_loc_descr (DW_OP_deref_size
,
11422 GET_MODE_SIZE (mode
), 0));
11427 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
11430 /* Some ports can transform a symbol ref into a label ref, because
11431 the symbol ref is too far away and has to be dumped into a constant
11435 if (GET_MODE_CLASS (mode
) != MODE_INT
11436 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
11437 #ifdef POINTERS_EXTEND_UNSIGNED
11438 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
11442 if (GET_CODE (rtl
) == SYMBOL_REF
11443 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11445 dw_loc_descr_ref temp
;
11447 /* If this is not defined, we have no way to emit the data. */
11448 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
11451 /* We used to emit DW_OP_addr here, but that's wrong, since
11452 DW_OP_addr should be relocated by the debug info consumer,
11453 while DW_OP_GNU_push_tls_address operand should not. */
11454 temp
= new_loc_descr (DWARF2_ADDR_SIZE
== 4
11455 ? DW_OP_const4u
: DW_OP_const8u
, 0, 0);
11456 temp
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
11457 temp
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
11458 temp
->dtprel
= true;
11460 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
11461 add_loc_descr (&mem_loc_result
, temp
);
11466 if (!const_ok_for_output (rtl
))
11470 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
11471 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
11472 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
11473 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
11479 case DEBUG_IMPLICIT_PTR
:
11480 expansion_failed (NULL_TREE
, rtl
,
11481 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
11487 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
11489 if (GET_MODE_CLASS (mode
) != MODE_INT
11490 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11491 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
11492 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
11495 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl
)),
11496 VAR_INIT_STATUS_INITIALIZED
);
11498 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
11499 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
11501 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
11502 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
11503 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
11507 gcc_unreachable ();
11510 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
11511 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11512 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
11515 case DEBUG_PARAMETER_REF
:
11516 mem_loc_result
= parameter_ref_descriptor (rtl
);
11520 /* Extract the PLUS expression nested inside and fall into
11521 PLUS code below. */
11522 rtl
= XEXP (rtl
, 1);
11527 /* Turn these into a PLUS expression and fall into the PLUS code
11529 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
11530 GEN_INT (GET_CODE (rtl
) == PRE_INC
11531 ? GET_MODE_UNIT_SIZE (mem_mode
)
11532 : -GET_MODE_UNIT_SIZE (mem_mode
)));
11534 /* ... fall through ... */
11538 if (is_based_loc (rtl
)
11539 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11540 || XEXP (rtl
, 0) == arg_pointer_rtx
11541 || XEXP (rtl
, 0) == frame_pointer_rtx
)
11542 && GET_MODE_CLASS (mode
) == MODE_INT
)
11543 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
11544 INTVAL (XEXP (rtl
, 1)),
11545 VAR_INIT_STATUS_INITIALIZED
);
11548 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11549 VAR_INIT_STATUS_INITIALIZED
);
11550 if (mem_loc_result
== 0)
11553 if (CONST_INT_P (XEXP (rtl
, 1))
11554 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11555 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
11558 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11559 VAR_INIT_STATUS_INITIALIZED
);
11562 add_loc_descr (&mem_loc_result
, op1
);
11563 add_loc_descr (&mem_loc_result
,
11564 new_loc_descr (DW_OP_plus
, 0, 0));
11569 /* If a pseudo-reg is optimized away, it is possible for it to
11570 be replaced with a MEM containing a multiply or shift. */
11581 && GET_MODE_CLASS (mode
) == MODE_INT
11582 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11584 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
11585 base_type_for_mode (mode
, 0),
11609 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11611 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11612 VAR_INIT_STATUS_INITIALIZED
);
11614 rtx rtlop1
= XEXP (rtl
, 1);
11615 if (GET_MODE (rtlop1
) != VOIDmode
11616 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
11617 < GET_MODE_BITSIZE (mode
))
11618 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
11619 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
11620 VAR_INIT_STATUS_INITIALIZED
);
11623 if (op0
== 0 || op1
== 0)
11626 mem_loc_result
= op0
;
11627 add_loc_descr (&mem_loc_result
, op1
);
11628 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
11644 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11645 VAR_INIT_STATUS_INITIALIZED
);
11646 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11647 VAR_INIT_STATUS_INITIALIZED
);
11649 if (op0
== 0 || op1
== 0)
11652 mem_loc_result
= op0
;
11653 add_loc_descr (&mem_loc_result
, op1
);
11654 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
11658 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
11660 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
11661 base_type_for_mode (mode
, 0),
11666 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11667 VAR_INIT_STATUS_INITIALIZED
);
11668 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11669 VAR_INIT_STATUS_INITIALIZED
);
11671 if (op0
== 0 || op1
== 0)
11674 mem_loc_result
= op0
;
11675 add_loc_descr (&mem_loc_result
, op1
);
11676 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
11677 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
11678 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
11679 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
11680 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
11684 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
11686 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
11691 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
11692 base_type_for_mode (mode
, 1),
11710 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11711 VAR_INIT_STATUS_INITIALIZED
);
11716 mem_loc_result
= op0
;
11717 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
11721 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11722 #ifdef POINTERS_EXTEND_UNSIGNED
11724 && mem_mode
!= VOIDmode
11725 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
11729 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
11733 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
11734 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
11736 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
11737 enum machine_mode amode
;
11738 if (type_die
== NULL
)
11740 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
11742 if (INTVAL (rtl
) >= 0
11743 && amode
!= BLKmode
11744 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
11745 /* const DW_OP_GNU_convert <XXX> vs.
11746 DW_OP_GNU_const_type <XXX, 1, const>. */
11747 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
11748 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
11750 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
11751 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11752 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11753 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11754 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11755 add_loc_descr (&mem_loc_result
, op0
);
11756 return mem_loc_result
;
11758 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
11760 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11761 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11762 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11763 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
11764 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
11767 mem_loc_result
->dw_loc_oprnd2
.val_class
11768 = dw_val_class_const_double
;
11769 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
11770 = double_int::from_shwi (INTVAL (rtl
));
11778 dw_die_ref type_die
;
11780 /* Note that a CONST_DOUBLE rtx could represent either an integer
11781 or a floating-point constant. A CONST_DOUBLE is used whenever
11782 the constant requires more than one word in order to be
11783 adequately represented. We output CONST_DOUBLEs as blocks. */
11784 if (mode
== VOIDmode
11785 || (GET_MODE (rtl
) == VOIDmode
11786 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
11788 type_die
= base_type_for_mode (mode
,
11789 GET_MODE_CLASS (mode
) == MODE_INT
);
11790 if (type_die
== NULL
)
11792 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
11793 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11794 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11795 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11796 if (SCALAR_FLOAT_MODE_P (mode
))
11798 unsigned int length
= GET_MODE_SIZE (mode
);
11799 unsigned char *array
11800 = (unsigned char*) ggc_alloc_atomic (length
);
11802 insert_float (rtl
, array
);
11803 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
11804 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
11805 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
11806 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
11810 mem_loc_result
->dw_loc_oprnd2
.val_class
11811 = dw_val_class_const_double
;
11812 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
11813 = rtx_to_double_int (rtl
);
11819 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
11823 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
11827 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
11831 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
11835 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
11839 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
11843 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
11847 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
11851 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
11855 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
11860 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11865 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
11870 if (CONST_INT_P (XEXP (rtl
, 1))
11871 && CONST_INT_P (XEXP (rtl
, 2))
11872 && ((unsigned) INTVAL (XEXP (rtl
, 1))
11873 + (unsigned) INTVAL (XEXP (rtl
, 2))
11874 <= GET_MODE_BITSIZE (mode
))
11875 && GET_MODE_CLASS (mode
) == MODE_INT
11876 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11877 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
11880 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
11881 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
11884 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
11888 mem_loc_result
= op0
;
11889 size
= INTVAL (XEXP (rtl
, 1));
11890 shift
= INTVAL (XEXP (rtl
, 2));
11891 if (BITS_BIG_ENDIAN
)
11892 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
11894 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
11896 add_loc_descr (&mem_loc_result
,
11897 int_loc_descriptor (DWARF2_ADDR_SIZE
11899 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
11901 if (size
!= (int) DWARF2_ADDR_SIZE
)
11903 add_loc_descr (&mem_loc_result
,
11904 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
11905 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
11912 dw_loc_descr_ref op2
, bra_node
, drop_node
;
11913 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
11914 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
11915 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
11916 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
11917 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11918 VAR_INIT_STATUS_INITIALIZED
);
11919 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
11920 VAR_INIT_STATUS_INITIALIZED
);
11921 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
11924 mem_loc_result
= op1
;
11925 add_loc_descr (&mem_loc_result
, op2
);
11926 add_loc_descr (&mem_loc_result
, op0
);
11927 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11928 add_loc_descr (&mem_loc_result
, bra_node
);
11929 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
11930 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11931 add_loc_descr (&mem_loc_result
, drop_node
);
11932 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11933 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11938 case FLOAT_TRUNCATE
:
11940 case UNSIGNED_FLOAT
:
11945 dw_die_ref type_die
;
11946 dw_loc_descr_ref cvt
;
11948 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
11949 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
11952 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
11953 && (GET_CODE (rtl
) == FLOAT
11954 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
11955 <= DWARF2_ADDR_SIZE
))
11957 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
11958 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
11959 if (type_die
== NULL
)
11961 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11962 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11963 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11964 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11965 add_loc_descr (&op0
, cvt
);
11967 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
11968 if (type_die
== NULL
)
11970 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11971 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11972 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11973 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11974 add_loc_descr (&op0
, cvt
);
11975 if (GET_MODE_CLASS (mode
) == MODE_INT
11976 && (GET_CODE (rtl
) == FIX
11977 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
11979 op0
= convert_descriptor_to_mode (mode
, op0
);
11983 mem_loc_result
= op0
;
11990 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
11995 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
11999 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
12004 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
12009 /* In theory, we could implement the above. */
12010 /* DWARF cannot represent the unsigned compare operations
12035 case FRACT_CONVERT
:
12036 case UNSIGNED_FRACT_CONVERT
:
12038 case UNSIGNED_SAT_FRACT
:
12044 case VEC_DUPLICATE
:
12048 case STRICT_LOW_PART
:
12052 /* If delegitimize_address couldn't do anything with the UNSPEC, we
12053 can't express it in the debug info. This can happen e.g. with some
12058 resolve_one_addr (&rtl
, NULL
);
12062 #ifdef ENABLE_CHECKING
12063 print_rtl (stderr
, rtl
);
12064 gcc_unreachable ();
12070 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12071 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12073 return mem_loc_result
;
12076 /* Return a descriptor that describes the concatenation of two locations.
12077 This is typically a complex variable. */
12079 static dw_loc_descr_ref
12080 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
12082 dw_loc_descr_ref cc_loc_result
= NULL
;
12083 dw_loc_descr_ref x0_ref
12084 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12085 dw_loc_descr_ref x1_ref
12086 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12088 if (x0_ref
== 0 || x1_ref
== 0)
12091 cc_loc_result
= x0_ref
;
12092 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
12094 add_loc_descr (&cc_loc_result
, x1_ref
);
12095 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
12097 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12098 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12100 return cc_loc_result
;
12103 /* Return a descriptor that describes the concatenation of N
12106 static dw_loc_descr_ref
12107 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
12110 dw_loc_descr_ref cc_loc_result
= NULL
;
12111 unsigned int n
= XVECLEN (concatn
, 0);
12113 for (i
= 0; i
< n
; ++i
)
12115 dw_loc_descr_ref ref
;
12116 rtx x
= XVECEXP (concatn
, 0, i
);
12118 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12122 add_loc_descr (&cc_loc_result
, ref
);
12123 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
12126 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12127 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12129 return cc_loc_result
;
12132 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12133 for DEBUG_IMPLICIT_PTR RTL. */
12135 static dw_loc_descr_ref
12136 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
12138 dw_loc_descr_ref ret
;
12143 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
12144 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
12145 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
12146 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
12147 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
12148 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12151 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12152 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12153 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12157 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12158 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
12163 /* Output a proper Dwarf location descriptor for a variable or parameter
12164 which is either allocated in a register or in a memory location. For a
12165 register, we just generate an OP_REG and the register number. For a
12166 memory location we provide a Dwarf postfix expression describing how to
12167 generate the (dynamic) address of the object onto the address stack.
12169 MODE is mode of the decl if this loc_descriptor is going to be used in
12170 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
12171 allowed, VOIDmode otherwise.
12173 If we don't know how to describe it, return 0. */
12175 static dw_loc_descr_ref
12176 loc_descriptor (rtx rtl
, enum machine_mode mode
,
12177 enum var_init_status initialized
)
12179 dw_loc_descr_ref loc_result
= NULL
;
12181 switch (GET_CODE (rtl
))
12184 /* The case of a subreg may arise when we have a local (register)
12185 variable or a formal (register) parameter which doesn't quite fill
12186 up an entire register. For now, just assume that it is
12187 legitimate to make the Dwarf info refer to the whole register which
12188 contains the given subreg. */
12189 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
12190 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
12191 GET_MODE (SUBREG_REG (rtl
)), initialized
);
12197 loc_result
= reg_loc_descriptor (rtl
, initialized
);
12201 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
12202 GET_MODE (rtl
), initialized
);
12203 if (loc_result
== NULL
)
12204 loc_result
= tls_mem_loc_descriptor (rtl
);
12205 if (loc_result
== NULL
)
12207 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12208 if (new_rtl
!= rtl
)
12209 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
12214 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
12219 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
12224 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
12226 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
12227 if (GET_CODE (loc
) == EXPR_LIST
)
12228 loc
= XEXP (loc
, 0);
12229 loc_result
= loc_descriptor (loc
, mode
, initialized
);
12233 rtl
= XEXP (rtl
, 1);
12238 rtvec par_elems
= XVEC (rtl
, 0);
12239 int num_elem
= GET_NUM_ELEM (par_elems
);
12240 enum machine_mode mode
;
12243 /* Create the first one, so we have something to add to. */
12244 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
12245 VOIDmode
, initialized
);
12246 if (loc_result
== NULL
)
12248 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
12249 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
12250 for (i
= 1; i
< num_elem
; i
++)
12252 dw_loc_descr_ref temp
;
12254 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
12255 VOIDmode
, initialized
);
12258 add_loc_descr (&loc_result
, temp
);
12259 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
12260 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
12266 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
12267 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
12272 if (mode
== VOIDmode
)
12273 mode
= GET_MODE (rtl
);
12275 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
12277 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
12279 /* Note that a CONST_DOUBLE rtx could represent either an integer
12280 or a floating-point constant. A CONST_DOUBLE is used whenever
12281 the constant requires more than one word in order to be
12282 adequately represented. We output CONST_DOUBLEs as blocks. */
12283 loc_result
= new_loc_descr (DW_OP_implicit_value
,
12284 GET_MODE_SIZE (mode
), 0);
12285 if (SCALAR_FLOAT_MODE_P (mode
))
12287 unsigned int length
= GET_MODE_SIZE (mode
);
12288 unsigned char *array
12289 = (unsigned char*) ggc_alloc_atomic (length
);
12291 insert_float (rtl
, array
);
12292 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12293 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12294 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12295 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12299 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
12300 loc_result
->dw_loc_oprnd2
.v
.val_double
12301 = rtx_to_double_int (rtl
);
12307 if (mode
== VOIDmode
)
12308 mode
= GET_MODE (rtl
);
12310 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
12312 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
12313 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
12314 unsigned char *array
= (unsigned char *)
12315 ggc_alloc_atomic (length
* elt_size
);
12319 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
12320 switch (GET_MODE_CLASS (mode
))
12322 case MODE_VECTOR_INT
:
12323 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
12325 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
12326 double_int val
= rtx_to_double_int (elt
);
12328 if (elt_size
<= sizeof (HOST_WIDE_INT
))
12329 insert_int (val
.to_shwi (), elt_size
, p
);
12332 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
12333 insert_double (val
, p
);
12338 case MODE_VECTOR_FLOAT
:
12339 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
12341 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
12342 insert_float (elt
, p
);
12347 gcc_unreachable ();
12350 loc_result
= new_loc_descr (DW_OP_implicit_value
,
12351 length
* elt_size
, 0);
12352 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12353 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
12354 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
12355 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12360 if (mode
== VOIDmode
12361 || GET_CODE (XEXP (rtl
, 0)) == CONST_INT
12362 || GET_CODE (XEXP (rtl
, 0)) == CONST_DOUBLE
12363 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
12365 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
12370 if (!const_ok_for_output (rtl
))
12373 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
12374 && (dwarf_version
>= 4 || !dwarf_strict
))
12376 loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
12377 loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
12378 loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
12379 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
12380 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
12384 case DEBUG_IMPLICIT_PTR
:
12385 loc_result
= implicit_ptr_descriptor (rtl
, 0);
12389 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
12390 && CONST_INT_P (XEXP (rtl
, 1)))
12393 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
12399 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
12400 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
12401 && dwarf_version
>= 4)
12402 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
12404 /* Value expression. */
12405 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
12407 add_loc_descr (&loc_result
,
12408 new_loc_descr (DW_OP_stack_value
, 0, 0));
12416 /* We need to figure out what section we should use as the base for the
12417 address ranges where a given location is valid.
12418 1. If this particular DECL has a section associated with it, use that.
12419 2. If this function has a section associated with it, use that.
12420 3. Otherwise, use the text section.
12421 XXX: If you split a variable across multiple sections, we won't notice. */
12423 static const char *
12424 secname_for_decl (const_tree decl
)
12426 const char *secname
;
12428 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
12430 tree sectree
= DECL_SECTION_NAME (decl
);
12431 secname
= TREE_STRING_POINTER (sectree
);
12433 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
12435 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
12436 secname
= TREE_STRING_POINTER (sectree
);
12438 else if (cfun
&& in_cold_section_p
)
12439 secname
= crtl
->subsections
.cold_section_label
;
12441 secname
= text_section_label
;
12446 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
12449 decl_by_reference_p (tree decl
)
12451 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
12452 || TREE_CODE (decl
) == VAR_DECL
)
12453 && DECL_BY_REFERENCE (decl
));
12456 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
12459 static dw_loc_descr_ref
12460 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
12461 enum var_init_status initialized
)
12463 int have_address
= 0;
12464 dw_loc_descr_ref descr
;
12465 enum machine_mode mode
;
12467 if (want_address
!= 2)
12469 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
12471 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
12473 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
12474 if (GET_CODE (varloc
) == EXPR_LIST
)
12475 varloc
= XEXP (varloc
, 0);
12476 mode
= GET_MODE (varloc
);
12477 if (MEM_P (varloc
))
12479 rtx addr
= XEXP (varloc
, 0);
12480 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
12481 mode
, initialized
);
12486 rtx x
= avoid_constant_pool_reference (varloc
);
12488 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
12493 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
12500 if (GET_CODE (varloc
) == VAR_LOCATION
)
12501 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
12503 mode
= DECL_MODE (loc
);
12504 descr
= loc_descriptor (varloc
, mode
, initialized
);
12511 if (want_address
== 2 && !have_address
12512 && (dwarf_version
>= 4 || !dwarf_strict
))
12514 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
12516 expansion_failed (loc
, NULL_RTX
,
12517 "DWARF address size mismatch");
12520 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
12523 /* Show if we can't fill the request for an address. */
12524 if (want_address
&& !have_address
)
12526 expansion_failed (loc
, NULL_RTX
,
12527 "Want address and only have value");
12531 /* If we've got an address and don't want one, dereference. */
12532 if (!want_address
&& have_address
)
12534 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
12535 enum dwarf_location_atom op
;
12537 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
12539 expansion_failed (loc
, NULL_RTX
,
12540 "DWARF address size mismatch");
12543 else if (size
== DWARF2_ADDR_SIZE
)
12546 op
= DW_OP_deref_size
;
12548 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
12554 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
12555 if it is not possible. */
12557 static dw_loc_descr_ref
12558 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
12560 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
12561 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
12562 else if (dwarf_version
>= 3 || !dwarf_strict
)
12563 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
12568 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
12569 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
12571 static dw_loc_descr_ref
12572 dw_sra_loc_expr (tree decl
, rtx loc
)
12575 unsigned int padsize
= 0;
12576 dw_loc_descr_ref descr
, *descr_tail
;
12577 unsigned HOST_WIDE_INT decl_size
;
12579 enum var_init_status initialized
;
12581 if (DECL_SIZE (decl
) == NULL
12582 || !host_integerp (DECL_SIZE (decl
), 1))
12585 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
12587 descr_tail
= &descr
;
12589 for (p
= loc
; p
; p
= XEXP (p
, 1))
12591 unsigned int bitsize
= decl_piece_bitsize (p
);
12592 rtx loc_note
= *decl_piece_varloc_ptr (p
);
12593 dw_loc_descr_ref cur_descr
;
12594 dw_loc_descr_ref
*tail
, last
= NULL
;
12595 unsigned int opsize
= 0;
12597 if (loc_note
== NULL_RTX
12598 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
12600 padsize
+= bitsize
;
12603 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
12604 varloc
= NOTE_VAR_LOCATION (loc_note
);
12605 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
12606 if (cur_descr
== NULL
)
12608 padsize
+= bitsize
;
12612 /* Check that cur_descr either doesn't use
12613 DW_OP_*piece operations, or their sum is equal
12614 to bitsize. Otherwise we can't embed it. */
12615 for (tail
= &cur_descr
; *tail
!= NULL
;
12616 tail
= &(*tail
)->dw_loc_next
)
12617 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
12619 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
12623 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
12625 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
12629 if (last
!= NULL
&& opsize
!= bitsize
)
12631 padsize
+= bitsize
;
12635 /* If there is a hole, add DW_OP_*piece after empty DWARF
12636 expression, which means that those bits are optimized out. */
12639 if (padsize
> decl_size
)
12641 decl_size
-= padsize
;
12642 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
12643 if (*descr_tail
== NULL
)
12645 descr_tail
= &(*descr_tail
)->dw_loc_next
;
12648 *descr_tail
= cur_descr
;
12650 if (bitsize
> decl_size
)
12652 decl_size
-= bitsize
;
12655 HOST_WIDE_INT offset
= 0;
12656 if (GET_CODE (varloc
) == VAR_LOCATION
12657 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
12659 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
12660 if (GET_CODE (varloc
) == EXPR_LIST
)
12661 varloc
= XEXP (varloc
, 0);
12665 if (GET_CODE (varloc
) == CONST
12666 || GET_CODE (varloc
) == SIGN_EXTEND
12667 || GET_CODE (varloc
) == ZERO_EXTEND
)
12668 varloc
= XEXP (varloc
, 0);
12669 else if (GET_CODE (varloc
) == SUBREG
)
12670 varloc
= SUBREG_REG (varloc
);
12675 /* DW_OP_bit_size offset should be zero for register
12676 or implicit location descriptions and empty location
12677 descriptions, but for memory addresses needs big endian
12679 if (MEM_P (varloc
))
12681 unsigned HOST_WIDE_INT memsize
12682 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
12683 if (memsize
!= bitsize
)
12685 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
12686 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
12688 if (memsize
< bitsize
)
12690 if (BITS_BIG_ENDIAN
)
12691 offset
= memsize
- bitsize
;
12695 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
12696 if (*descr_tail
== NULL
)
12698 descr_tail
= &(*descr_tail
)->dw_loc_next
;
12702 /* If there were any non-empty expressions, add padding till the end of
12704 if (descr
!= NULL
&& decl_size
!= 0)
12706 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
12707 if (*descr_tail
== NULL
)
12713 /* Return the dwarf representation of the location list LOC_LIST of
12714 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
12717 static dw_loc_list_ref
12718 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
12720 const char *endname
, *secname
;
12722 enum var_init_status initialized
;
12723 struct var_loc_node
*node
;
12724 dw_loc_descr_ref descr
;
12725 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
12726 dw_loc_list_ref list
= NULL
;
12727 dw_loc_list_ref
*listp
= &list
;
12729 /* Now that we know what section we are using for a base,
12730 actually construct the list of locations.
12731 The first location information is what is passed to the
12732 function that creates the location list, and the remaining
12733 locations just get added on to that list.
12734 Note that we only know the start address for a location
12735 (IE location changes), so to build the range, we use
12736 the range [current location start, next location start].
12737 This means we have to special case the last node, and generate
12738 a range of [last location start, end of function label]. */
12740 secname
= secname_for_decl (decl
);
12742 for (node
= loc_list
->first
; node
; node
= node
->next
)
12743 if (GET_CODE (node
->loc
) == EXPR_LIST
12744 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
12746 if (GET_CODE (node
->loc
) == EXPR_LIST
)
12748 /* This requires DW_OP_{,bit_}piece, which is not usable
12749 inside DWARF expressions. */
12750 if (want_address
!= 2)
12752 descr
= dw_sra_loc_expr (decl
, node
->loc
);
12758 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
12759 varloc
= NOTE_VAR_LOCATION (node
->loc
);
12760 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
12764 bool range_across_switch
= false;
12765 /* If section switch happens in between node->label
12766 and node->next->label (or end of function) and
12767 we can't emit it as a single entry list,
12768 emit two ranges, first one ending at the end
12769 of first partition and second one starting at the
12770 beginning of second partition. */
12771 if (node
== loc_list
->last_before_switch
12772 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
12773 && current_function_decl
)
12775 endname
= cfun
->fde
->dw_fde_end
;
12776 range_across_switch
= true;
12778 /* The variable has a location between NODE->LABEL and
12779 NODE->NEXT->LABEL. */
12780 else if (node
->next
)
12781 endname
= node
->next
->label
;
12782 /* If the variable has a location at the last label
12783 it keeps its location until the end of function. */
12784 else if (!current_function_decl
)
12785 endname
= text_end_label
;
12788 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
12789 current_function_funcdef_no
);
12790 endname
= ggc_strdup (label_id
);
12793 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
12794 if (TREE_CODE (decl
) == PARM_DECL
12795 && node
== loc_list
->first
12796 && GET_CODE (node
->loc
) == NOTE
12797 && strcmp (node
->label
, endname
) == 0)
12798 (*listp
)->force
= true;
12799 listp
= &(*listp
)->dw_loc_next
;
12801 if (range_across_switch
)
12803 if (GET_CODE (node
->loc
) == EXPR_LIST
)
12804 descr
= dw_sra_loc_expr (decl
, node
->loc
);
12807 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
12808 varloc
= NOTE_VAR_LOCATION (node
->loc
);
12809 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
12812 gcc_assert (descr
);
12813 /* The variable has a location between NODE->LABEL and
12814 NODE->NEXT->LABEL. */
12816 endname
= node
->next
->label
;
12818 endname
= cfun
->fde
->dw_fde_second_end
;
12819 *listp
= new_loc_list (descr
,
12820 cfun
->fde
->dw_fde_second_begin
,
12822 listp
= &(*listp
)->dw_loc_next
;
12827 /* Try to avoid the overhead of a location list emitting a location
12828 expression instead, but only if we didn't have more than one
12829 location entry in the first place. If some entries were not
12830 representable, we don't want to pretend a single entry that was
12831 applies to the entire scope in which the variable is
12833 if (list
&& loc_list
->first
->next
)
12839 /* Return if the loc_list has only single element and thus can be represented
12840 as location description. */
12843 single_element_loc_list_p (dw_loc_list_ref list
)
12845 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
12846 return !list
->ll_symbol
;
12849 /* To each location in list LIST add loc descr REF. */
12852 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
12854 dw_loc_descr_ref copy
;
12855 add_loc_descr (&list
->expr
, ref
);
12856 list
= list
->dw_loc_next
;
12859 copy
= ggc_alloc_dw_loc_descr_node ();
12860 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
12861 add_loc_descr (&list
->expr
, copy
);
12862 while (copy
->dw_loc_next
)
12864 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
12865 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
12866 copy
->dw_loc_next
= new_copy
;
12869 list
= list
->dw_loc_next
;
12873 /* Given two lists RET and LIST
12874 produce location list that is result of adding expression in LIST
12875 to expression in RET on each position in program.
12876 Might be destructive on both RET and LIST.
12878 TODO: We handle only simple cases of RET or LIST having at most one
12879 element. General case would inolve sorting the lists in program order
12880 and merging them that will need some additional work.
12881 Adding that will improve quality of debug info especially for SRA-ed
12885 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
12894 if (!list
->dw_loc_next
)
12896 add_loc_descr_to_each (*ret
, list
->expr
);
12899 if (!(*ret
)->dw_loc_next
)
12901 add_loc_descr_to_each (list
, (*ret
)->expr
);
12905 expansion_failed (NULL_TREE
, NULL_RTX
,
12906 "Don't know how to merge two non-trivial"
12907 " location lists.\n");
12912 /* LOC is constant expression. Try a luck, look it up in constant
12913 pool and return its loc_descr of its address. */
12915 static dw_loc_descr_ref
12916 cst_pool_loc_descr (tree loc
)
12918 /* Get an RTL for this, if something has been emitted. */
12919 rtx rtl
= lookup_constant_def (loc
);
12921 if (!rtl
|| !MEM_P (rtl
))
12926 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
12928 /* TODO: We might get more coverage if we was actually delaying expansion
12929 of all expressions till end of compilation when constant pools are fully
12931 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
12933 expansion_failed (loc
, NULL_RTX
,
12934 "CST value in contant pool but not marked.");
12937 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
12938 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
12941 /* Return dw_loc_list representing address of addr_expr LOC
12942 by looking for inner INDIRECT_REF expression and turning
12943 it into simple arithmetics. */
12945 static dw_loc_list_ref
12946 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
12949 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
12950 enum machine_mode mode
;
12951 int unsignedp
, volatilep
= 0;
12952 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
12954 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
12955 &bitsize
, &bitpos
, &offset
, &mode
,
12956 &unsignedp
, &volatilep
, false);
12958 if (bitpos
% BITS_PER_UNIT
)
12960 expansion_failed (loc
, NULL_RTX
, "bitfield access");
12963 if (!INDIRECT_REF_P (obj
))
12965 expansion_failed (obj
,
12966 NULL_RTX
, "no indirect ref in inner refrence");
12969 if (!offset
&& !bitpos
)
12970 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
12972 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
12973 && (dwarf_version
>= 4 || !dwarf_strict
))
12975 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
12980 /* Variable offset. */
12981 list_ret1
= loc_list_from_tree (offset
, 0);
12982 if (list_ret1
== 0)
12984 add_loc_list (&list_ret
, list_ret1
);
12987 add_loc_descr_to_each (list_ret
,
12988 new_loc_descr (DW_OP_plus
, 0, 0));
12990 bytepos
= bitpos
/ BITS_PER_UNIT
;
12992 add_loc_descr_to_each (list_ret
,
12993 new_loc_descr (DW_OP_plus_uconst
,
12995 else if (bytepos
< 0)
12996 loc_list_plus_const (list_ret
, bytepos
);
12997 add_loc_descr_to_each (list_ret
,
12998 new_loc_descr (DW_OP_stack_value
, 0, 0));
13004 /* Generate Dwarf location list representing LOC.
13005 If WANT_ADDRESS is false, expression computing LOC will be computed
13006 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13007 if WANT_ADDRESS is 2, expression computing address useable in location
13008 will be returned (i.e. DW_OP_reg can be used
13009 to refer to register values). */
13011 static dw_loc_list_ref
13012 loc_list_from_tree (tree loc
, int want_address
)
13014 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
13015 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13016 int have_address
= 0;
13017 enum dwarf_location_atom op
;
13019 /* ??? Most of the time we do not take proper care for sign/zero
13020 extending the values properly. Hopefully this won't be a real
13023 switch (TREE_CODE (loc
))
13026 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
13029 case PLACEHOLDER_EXPR
:
13030 /* This case involves extracting fields from an object to determine the
13031 position of other fields. We don't try to encode this here. The
13032 only user of this is Ada, which encodes the needed information using
13033 the names of types. */
13034 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
13038 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
13039 /* There are no opcodes for these operations. */
13042 case PREINCREMENT_EXPR
:
13043 case PREDECREMENT_EXPR
:
13044 case POSTINCREMENT_EXPR
:
13045 case POSTDECREMENT_EXPR
:
13046 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
13047 /* There are no opcodes for these operations. */
13051 /* If we already want an address, see if there is INDIRECT_REF inside
13052 e.g. for &this->field. */
13055 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
13056 (loc
, want_address
== 2);
13059 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
13060 && (ret
= cst_pool_loc_descr (loc
)))
13063 /* Otherwise, process the argument and look for the address. */
13064 if (!list_ret
&& !ret
)
13065 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
13069 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
13075 if (DECL_THREAD_LOCAL_P (loc
))
13078 enum dwarf_location_atom first_op
;
13079 enum dwarf_location_atom second_op
;
13080 bool dtprel
= false;
13082 if (targetm
.have_tls
)
13084 /* If this is not defined, we have no way to emit the
13086 if (!targetm
.asm_out
.output_dwarf_dtprel
)
13089 /* The way DW_OP_GNU_push_tls_address is specified, we
13090 can only look up addresses of objects in the current
13091 module. We used DW_OP_addr as first op, but that's
13092 wrong, because DW_OP_addr is relocated by the debug
13093 info consumer, while DW_OP_GNU_push_tls_address
13094 operand shouldn't be. */
13095 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
13097 first_op
= DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
;
13099 second_op
= DW_OP_GNU_push_tls_address
;
13103 if (!targetm
.emutls
.debug_form_tls_address
13104 || !(dwarf_version
>= 3 || !dwarf_strict
))
13106 /* We stuffed the control variable into the DECL_VALUE_EXPR
13107 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13108 no longer appear in gimple code. We used the control
13109 variable in specific so that we could pick it up here. */
13110 loc
= DECL_VALUE_EXPR (loc
);
13111 first_op
= DW_OP_addr
;
13112 second_op
= DW_OP_form_tls_address
;
13115 rtl
= rtl_for_decl_location (loc
);
13116 if (rtl
== NULL_RTX
)
13121 rtl
= XEXP (rtl
, 0);
13122 if (! CONSTANT_P (rtl
))
13125 ret
= new_loc_descr (first_op
, 0, 0);
13126 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
13127 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
13128 ret
->dtprel
= dtprel
;
13130 ret1
= new_loc_descr (second_op
, 0, 0);
13131 add_loc_descr (&ret
, ret1
);
13140 if (DECL_HAS_VALUE_EXPR_P (loc
))
13141 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
13145 case FUNCTION_DECL
:
13148 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
13150 if (loc_list
&& loc_list
->first
)
13152 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
13153 have_address
= want_address
!= 0;
13156 rtl
= rtl_for_decl_location (loc
);
13157 if (rtl
== NULL_RTX
)
13159 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
13162 else if (CONST_INT_P (rtl
))
13164 HOST_WIDE_INT val
= INTVAL (rtl
);
13165 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13166 val
&= GET_MODE_MASK (DECL_MODE (loc
));
13167 ret
= int_loc_descriptor (val
);
13169 else if (GET_CODE (rtl
) == CONST_STRING
)
13171 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
13174 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
13176 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
13177 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
13178 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
13182 enum machine_mode mode
, mem_mode
;
13184 /* Certain constructs can only be represented at top-level. */
13185 if (want_address
== 2)
13187 ret
= loc_descriptor (rtl
, VOIDmode
,
13188 VAR_INIT_STATUS_INITIALIZED
);
13193 mode
= GET_MODE (rtl
);
13194 mem_mode
= VOIDmode
;
13198 mode
= get_address_mode (rtl
);
13199 rtl
= XEXP (rtl
, 0);
13202 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
13203 VAR_INIT_STATUS_INITIALIZED
);
13206 expansion_failed (loc
, rtl
,
13207 "failed to produce loc descriptor for rtl");
13214 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
13218 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13222 case COMPOUND_EXPR
:
13223 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
13226 case VIEW_CONVERT_EXPR
:
13229 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
13231 case COMPONENT_REF
:
13232 case BIT_FIELD_REF
:
13234 case ARRAY_RANGE_REF
:
13235 case REALPART_EXPR
:
13236 case IMAGPART_EXPR
:
13239 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13240 enum machine_mode mode
;
13241 int unsignedp
, volatilep
= 0;
13243 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
13244 &unsignedp
, &volatilep
, false);
13246 gcc_assert (obj
!= loc
);
13248 list_ret
= loc_list_from_tree (obj
,
13250 && !bitpos
&& !offset
? 2 : 1);
13251 /* TODO: We can extract value of the small expression via shifting even
13252 for nonzero bitpos. */
13255 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
13257 expansion_failed (loc
, NULL_RTX
,
13258 "bitfield access");
13262 if (offset
!= NULL_TREE
)
13264 /* Variable offset. */
13265 list_ret1
= loc_list_from_tree (offset
, 0);
13266 if (list_ret1
== 0)
13268 add_loc_list (&list_ret
, list_ret1
);
13271 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
13274 bytepos
= bitpos
/ BITS_PER_UNIT
;
13276 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
13277 else if (bytepos
< 0)
13278 loc_list_plus_const (list_ret
, bytepos
);
13285 if ((want_address
|| !host_integerp (loc
, 0))
13286 && (ret
= cst_pool_loc_descr (loc
)))
13288 else if (want_address
== 2
13289 && host_integerp (loc
, 0)
13290 && (ret
= address_of_int_loc_descriptor
13291 (int_size_in_bytes (TREE_TYPE (loc
)),
13292 tree_low_cst (loc
, 0))))
13294 else if (host_integerp (loc
, 0))
13295 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
13298 expansion_failed (loc
, NULL_RTX
,
13299 "Integer operand is not host integer");
13308 if ((ret
= cst_pool_loc_descr (loc
)))
13311 /* We can construct small constants here using int_loc_descriptor. */
13312 expansion_failed (loc
, NULL_RTX
,
13313 "constructor or constant not in constant pool");
13316 case TRUTH_AND_EXPR
:
13317 case TRUTH_ANDIF_EXPR
:
13322 case TRUTH_XOR_EXPR
:
13327 case TRUTH_OR_EXPR
:
13328 case TRUTH_ORIF_EXPR
:
13333 case FLOOR_DIV_EXPR
:
13334 case CEIL_DIV_EXPR
:
13335 case ROUND_DIV_EXPR
:
13336 case TRUNC_DIV_EXPR
:
13337 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13346 case FLOOR_MOD_EXPR
:
13347 case CEIL_MOD_EXPR
:
13348 case ROUND_MOD_EXPR
:
13349 case TRUNC_MOD_EXPR
:
13350 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13355 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13356 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
13357 if (list_ret
== 0 || list_ret1
== 0)
13360 add_loc_list (&list_ret
, list_ret1
);
13363 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
13364 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
13365 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
13366 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
13367 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
13379 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
13382 case POINTER_PLUS_EXPR
:
13384 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
13386 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13390 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
13398 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
13405 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
13412 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
13419 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
13434 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13435 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
13436 if (list_ret
== 0 || list_ret1
== 0)
13439 add_loc_list (&list_ret
, list_ret1
);
13442 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
13445 case TRUTH_NOT_EXPR
:
13459 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13463 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
13469 const enum tree_code code
=
13470 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
13472 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
13473 build2 (code
, integer_type_node
,
13474 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
13475 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
13478 /* ... fall through ... */
13482 dw_loc_descr_ref lhs
13483 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
13484 dw_loc_list_ref rhs
13485 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
13486 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
13488 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13489 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
13492 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13493 add_loc_descr_to_each (list_ret
, bra_node
);
13495 add_loc_list (&list_ret
, rhs
);
13496 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
13497 add_loc_descr_to_each (list_ret
, jump_node
);
13499 add_loc_descr_to_each (list_ret
, lhs
);
13500 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13501 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
13503 /* ??? Need a node to point the skip at. Use a nop. */
13504 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
13505 add_loc_descr_to_each (list_ret
, tmp
);
13506 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13507 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
13511 case FIX_TRUNC_EXPR
:
13515 /* Leave front-end specific codes as simply unknown. This comes
13516 up, for instance, with the C STMT_EXPR. */
13517 if ((unsigned int) TREE_CODE (loc
)
13518 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
13520 expansion_failed (loc
, NULL_RTX
,
13521 "language specific tree node");
13525 #ifdef ENABLE_CHECKING
13526 /* Otherwise this is a generic code; we should just lists all of
13527 these explicitly. We forgot one. */
13528 gcc_unreachable ();
13530 /* In a release build, we want to degrade gracefully: better to
13531 generate incomplete debugging information than to crash. */
13536 if (!ret
&& !list_ret
)
13539 if (want_address
== 2 && !have_address
13540 && (dwarf_version
>= 4 || !dwarf_strict
))
13542 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13544 expansion_failed (loc
, NULL_RTX
,
13545 "DWARF address size mismatch");
13549 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13551 add_loc_descr_to_each (list_ret
,
13552 new_loc_descr (DW_OP_stack_value
, 0, 0));
13555 /* Show if we can't fill the request for an address. */
13556 if (want_address
&& !have_address
)
13558 expansion_failed (loc
, NULL_RTX
,
13559 "Want address and only have value");
13563 gcc_assert (!ret
|| !list_ret
);
13565 /* If we've got an address and don't want one, dereference. */
13566 if (!want_address
&& have_address
)
13568 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13570 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13572 expansion_failed (loc
, NULL_RTX
,
13573 "DWARF address size mismatch");
13576 else if (size
== DWARF2_ADDR_SIZE
)
13579 op
= DW_OP_deref_size
;
13582 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
13584 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
13587 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
13592 /* Same as above but return only single location expression. */
13593 static dw_loc_descr_ref
13594 loc_descriptor_from_tree (tree loc
, int want_address
)
13596 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
13599 if (ret
->dw_loc_next
)
13601 expansion_failed (loc
, NULL_RTX
,
13602 "Location list where only loc descriptor needed");
13608 /* Given a value, round it up to the lowest multiple of `boundary'
13609 which is not less than the value itself. */
13611 static inline HOST_WIDE_INT
13612 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
13614 return (((value
+ boundary
- 1) / boundary
) * boundary
);
13617 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
13618 pointer to the declared type for the relevant field variable, or return
13619 `integer_type_node' if the given node turns out to be an
13620 ERROR_MARK node. */
13623 field_type (const_tree decl
)
13627 if (TREE_CODE (decl
) == ERROR_MARK
)
13628 return integer_type_node
;
13630 type
= DECL_BIT_FIELD_TYPE (decl
);
13631 if (type
== NULL_TREE
)
13632 type
= TREE_TYPE (decl
);
13637 /* Given a pointer to a tree node, return the alignment in bits for
13638 it, or else return BITS_PER_WORD if the node actually turns out to
13639 be an ERROR_MARK node. */
13641 static inline unsigned
13642 simple_type_align_in_bits (const_tree type
)
13644 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
13647 static inline unsigned
13648 simple_decl_align_in_bits (const_tree decl
)
13650 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
13653 /* Return the result of rounding T up to ALIGN. */
13655 static inline double_int
13656 round_up_to_align (double_int t
, unsigned int align
)
13658 double_int alignd
= double_int::from_uhwi (align
);
13660 t
+= double_int_minus_one
;
13661 t
= t
.div (alignd
, true, TRUNC_DIV_EXPR
);
13666 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
13667 lowest addressed byte of the "containing object" for the given FIELD_DECL,
13668 or return 0 if we are unable to determine what that offset is, either
13669 because the argument turns out to be a pointer to an ERROR_MARK node, or
13670 because the offset is actually variable. (We can't handle the latter case
13673 static HOST_WIDE_INT
13674 field_byte_offset (const_tree decl
)
13676 double_int object_offset_in_bits
;
13677 double_int object_offset_in_bytes
;
13678 double_int bitpos_int
;
13680 if (TREE_CODE (decl
) == ERROR_MARK
)
13683 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
13685 /* We cannot yet cope with fields whose positions are variable, so
13686 for now, when we see such things, we simply return 0. Someday, we may
13687 be able to handle such cases, but it will be damn difficult. */
13688 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
13691 bitpos_int
= tree_to_double_int (bit_position (decl
));
13693 #ifdef PCC_BITFIELD_TYPE_MATTERS
13694 if (PCC_BITFIELD_TYPE_MATTERS
)
13697 tree field_size_tree
;
13698 double_int deepest_bitpos
;
13699 double_int field_size_in_bits
;
13700 unsigned int type_align_in_bits
;
13701 unsigned int decl_align_in_bits
;
13702 double_int type_size_in_bits
;
13704 type
= field_type (decl
);
13705 type_size_in_bits
= double_int_type_size_in_bits (type
);
13706 type_align_in_bits
= simple_type_align_in_bits (type
);
13708 field_size_tree
= DECL_SIZE (decl
);
13710 /* The size could be unspecified if there was an error, or for
13711 a flexible array member. */
13712 if (!field_size_tree
)
13713 field_size_tree
= bitsize_zero_node
;
13715 /* If the size of the field is not constant, use the type size. */
13716 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
13717 field_size_in_bits
= tree_to_double_int (field_size_tree
);
13719 field_size_in_bits
= type_size_in_bits
;
13721 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
13723 /* The GCC front-end doesn't make any attempt to keep track of the
13724 starting bit offset (relative to the start of the containing
13725 structure type) of the hypothetical "containing object" for a
13726 bit-field. Thus, when computing the byte offset value for the
13727 start of the "containing object" of a bit-field, we must deduce
13728 this information on our own. This can be rather tricky to do in
13729 some cases. For example, handling the following structure type
13730 definition when compiling for an i386/i486 target (which only
13731 aligns long long's to 32-bit boundaries) can be very tricky:
13733 struct S { int field1; long long field2:31; };
13735 Fortunately, there is a simple rule-of-thumb which can be used
13736 in such cases. When compiling for an i386/i486, GCC will
13737 allocate 8 bytes for the structure shown above. It decides to
13738 do this based upon one simple rule for bit-field allocation.
13739 GCC allocates each "containing object" for each bit-field at
13740 the first (i.e. lowest addressed) legitimate alignment boundary
13741 (based upon the required minimum alignment for the declared
13742 type of the field) which it can possibly use, subject to the
13743 condition that there is still enough available space remaining
13744 in the containing object (when allocated at the selected point)
13745 to fully accommodate all of the bits of the bit-field itself.
13747 This simple rule makes it obvious why GCC allocates 8 bytes for
13748 each object of the structure type shown above. When looking
13749 for a place to allocate the "containing object" for `field2',
13750 the compiler simply tries to allocate a 64-bit "containing
13751 object" at each successive 32-bit boundary (starting at zero)
13752 until it finds a place to allocate that 64- bit field such that
13753 at least 31 contiguous (and previously unallocated) bits remain
13754 within that selected 64 bit field. (As it turns out, for the
13755 example above, the compiler finds it is OK to allocate the
13756 "containing object" 64-bit field at bit-offset zero within the
13759 Here we attempt to work backwards from the limited set of facts
13760 we're given, and we try to deduce from those facts, where GCC
13761 must have believed that the containing object started (within
13762 the structure type). The value we deduce is then used (by the
13763 callers of this routine) to generate DW_AT_location and
13764 DW_AT_bit_offset attributes for fields (both bit-fields and, in
13765 the case of DW_AT_location, regular fields as well). */
13767 /* Figure out the bit-distance from the start of the structure to
13768 the "deepest" bit of the bit-field. */
13769 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
13771 /* This is the tricky part. Use some fancy footwork to deduce
13772 where the lowest addressed bit of the containing object must
13774 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
13776 /* Round up to type_align by default. This works best for
13778 object_offset_in_bits
13779 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
13781 if (object_offset_in_bits
.ugt (bitpos_int
))
13783 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
13785 /* Round up to decl_align instead. */
13786 object_offset_in_bits
13787 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
13791 #endif /* PCC_BITFIELD_TYPE_MATTERS */
13792 object_offset_in_bits
= bitpos_int
;
13794 object_offset_in_bytes
13795 = object_offset_in_bits
.div (double_int::from_uhwi (BITS_PER_UNIT
),
13796 true, TRUNC_DIV_EXPR
);
13797 return object_offset_in_bytes
.to_shwi ();
13800 /* The following routines define various Dwarf attributes and any data
13801 associated with them. */
13803 /* Add a location description attribute value to a DIE.
13805 This emits location attributes suitable for whole variables and
13806 whole parameters. Note that the location attributes for struct fields are
13807 generated by the routine `data_member_location_attribute' below. */
13810 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
13811 dw_loc_list_ref descr
)
13815 if (single_element_loc_list_p (descr
))
13816 add_AT_loc (die
, attr_kind
, descr
->expr
);
13818 add_AT_loc_list (die
, attr_kind
, descr
);
13821 /* Add DW_AT_accessibility attribute to DIE if needed. */
13824 add_accessibility_attribute (dw_die_ref die
, tree decl
)
13826 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
13827 children, otherwise the default is DW_ACCESS_public. In DWARF2
13828 the default has always been DW_ACCESS_public. */
13829 if (TREE_PROTECTED (decl
))
13830 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
13831 else if (TREE_PRIVATE (decl
))
13833 if (dwarf_version
== 2
13834 || die
->die_parent
== NULL
13835 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
13836 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
13838 else if (dwarf_version
> 2
13840 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
13841 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
13844 /* Attach the specialized form of location attribute used for data members of
13845 struct and union types. In the special case of a FIELD_DECL node which
13846 represents a bit-field, the "offset" part of this special location
13847 descriptor must indicate the distance in bytes from the lowest-addressed
13848 byte of the containing struct or union type to the lowest-addressed byte of
13849 the "containing object" for the bit-field. (See the `field_byte_offset'
13852 For any given bit-field, the "containing object" is a hypothetical object
13853 (of some integral or enum type) within which the given bit-field lives. The
13854 type of this hypothetical "containing object" is always the same as the
13855 declared type of the individual bit-field itself (for GCC anyway... the
13856 DWARF spec doesn't actually mandate this). Note that it is the size (in
13857 bytes) of the hypothetical "containing object" which will be given in the
13858 DW_AT_byte_size attribute for this bit-field. (See the
13859 `byte_size_attribute' function below.) It is also used when calculating the
13860 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
13861 function below.) */
13864 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
13866 HOST_WIDE_INT offset
;
13867 dw_loc_descr_ref loc_descr
= 0;
13869 if (TREE_CODE (decl
) == TREE_BINFO
)
13871 /* We're working on the TAG_inheritance for a base class. */
13872 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
13874 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
13875 aren't at a fixed offset from all (sub)objects of the same
13876 type. We need to extract the appropriate offset from our
13877 vtable. The following dwarf expression means
13879 BaseAddr = ObAddr + *((*ObAddr) - Offset)
13881 This is specific to the V3 ABI, of course. */
13883 dw_loc_descr_ref tmp
;
13885 /* Make a copy of the object address. */
13886 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
13887 add_loc_descr (&loc_descr
, tmp
);
13889 /* Extract the vtable address. */
13890 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
13891 add_loc_descr (&loc_descr
, tmp
);
13893 /* Calculate the address of the offset. */
13894 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
13895 gcc_assert (offset
< 0);
13897 tmp
= int_loc_descriptor (-offset
);
13898 add_loc_descr (&loc_descr
, tmp
);
13899 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
13900 add_loc_descr (&loc_descr
, tmp
);
13902 /* Extract the offset. */
13903 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
13904 add_loc_descr (&loc_descr
, tmp
);
13906 /* Add it to the object address. */
13907 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
13908 add_loc_descr (&loc_descr
, tmp
);
13911 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
13914 offset
= field_byte_offset (decl
);
13918 if (dwarf_version
> 2)
13920 /* Don't need to output a location expression, just the constant. */
13922 add_AT_int (die
, DW_AT_data_member_location
, offset
);
13924 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
13929 enum dwarf_location_atom op
;
13931 /* The DWARF2 standard says that we should assume that the structure
13932 address is already on the stack, so we can specify a structure
13933 field address by using DW_OP_plus_uconst. */
13934 op
= DW_OP_plus_uconst
;
13935 loc_descr
= new_loc_descr (op
, offset
, 0);
13939 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
13942 /* Writes integer values to dw_vec_const array. */
13945 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
13949 *dest
++ = val
& 0xff;
13955 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
13957 static HOST_WIDE_INT
13958 extract_int (const unsigned char *src
, unsigned int size
)
13960 HOST_WIDE_INT val
= 0;
13966 val
|= *--src
& 0xff;
13972 /* Writes double_int values to dw_vec_const array. */
13975 insert_double (double_int val
, unsigned char *dest
)
13977 unsigned char *p0
= dest
;
13978 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
13980 if (WORDS_BIG_ENDIAN
)
13986 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
13987 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
13990 /* Writes floating point values to dw_vec_const array. */
13993 insert_float (const_rtx rtl
, unsigned char *array
)
13995 REAL_VALUE_TYPE rv
;
13999 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
14000 real_to_target (val
, &rv
, GET_MODE (rtl
));
14002 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14003 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
14005 insert_int (val
[i
], 4, array
);
14010 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14011 does not have a "location" either in memory or in a register. These
14012 things can arise in GNU C when a constant is passed as an actual parameter
14013 to an inlined function. They can also arise in C++ where declared
14014 constants do not necessarily get memory "homes". */
14017 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
14019 switch (GET_CODE (rtl
))
14023 HOST_WIDE_INT val
= INTVAL (rtl
);
14026 add_AT_int (die
, DW_AT_const_value
, val
);
14028 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
14033 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14034 floating-point constant. A CONST_DOUBLE is used whenever the
14035 constant requires more than one word in order to be adequately
14038 enum machine_mode mode
= GET_MODE (rtl
);
14040 if (SCALAR_FLOAT_MODE_P (mode
))
14042 unsigned int length
= GET_MODE_SIZE (mode
);
14043 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
14045 insert_float (rtl
, array
);
14046 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
14049 add_AT_double (die
, DW_AT_const_value
,
14050 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
14056 enum machine_mode mode
= GET_MODE (rtl
);
14057 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
14058 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
14059 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
14060 (length
* elt_size
);
14064 switch (GET_MODE_CLASS (mode
))
14066 case MODE_VECTOR_INT
:
14067 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14069 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14070 double_int val
= rtx_to_double_int (elt
);
14072 if (elt_size
<= sizeof (HOST_WIDE_INT
))
14073 insert_int (val
.to_shwi (), elt_size
, p
);
14076 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
14077 insert_double (val
, p
);
14082 case MODE_VECTOR_FLOAT
:
14083 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14085 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14086 insert_float (elt
, p
);
14091 gcc_unreachable ();
14094 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
14099 if (dwarf_version
>= 4 || !dwarf_strict
)
14101 dw_loc_descr_ref loc_result
;
14102 resolve_one_addr (&rtl
, NULL
);
14104 loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
14105 loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
14106 loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
14107 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14108 add_AT_loc (die
, DW_AT_location
, loc_result
);
14109 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
14115 if (CONSTANT_P (XEXP (rtl
, 0)))
14116 return add_const_value_attribute (die
, XEXP (rtl
, 0));
14119 if (!const_ok_for_output (rtl
))
14122 if (dwarf_version
>= 4 || !dwarf_strict
)
14127 /* In cases where an inlined instance of an inline function is passed
14128 the address of an `auto' variable (which is local to the caller) we
14129 can get a situation where the DECL_RTL of the artificial local
14130 variable (for the inlining) which acts as a stand-in for the
14131 corresponding formal parameter (of the inline function) will look
14132 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14133 exactly a compile-time constant expression, but it isn't the address
14134 of the (artificial) local variable either. Rather, it represents the
14135 *value* which the artificial local variable always has during its
14136 lifetime. We currently have no way to represent such quasi-constant
14137 values in Dwarf, so for now we just punt and generate nothing. */
14145 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
14146 && MEM_READONLY_P (rtl
)
14147 && GET_MODE (rtl
) == BLKmode
)
14149 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
14155 /* No other kinds of rtx should be possible here. */
14156 gcc_unreachable ();
14161 /* Determine whether the evaluation of EXPR references any variables
14162 or functions which aren't otherwise used (and therefore may not be
14165 reference_to_unused (tree
* tp
, int * walk_subtrees
,
14166 void * data ATTRIBUTE_UNUSED
)
14168 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
14169 *walk_subtrees
= 0;
14171 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
14172 && ! TREE_ASM_WRITTEN (*tp
))
14174 /* ??? The C++ FE emits debug information for using decls, so
14175 putting gcc_unreachable here falls over. See PR31899. For now
14176 be conservative. */
14177 else if (!cgraph_global_info_ready
14178 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
14180 else if (TREE_CODE (*tp
) == VAR_DECL
)
14182 struct varpool_node
*node
= varpool_get_node (*tp
);
14183 if (!node
|| !node
->analyzed
)
14186 else if (TREE_CODE (*tp
) == FUNCTION_DECL
14187 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
14189 /* The call graph machinery must have finished analyzing,
14190 optimizing and gimplifying the CU by now.
14191 So if *TP has no call graph node associated
14192 to it, it means *TP will not be emitted. */
14193 if (!cgraph_get_node (*tp
))
14196 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
14202 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
14203 for use in a later add_const_value_attribute call. */
14206 rtl_for_decl_init (tree init
, tree type
)
14208 rtx rtl
= NULL_RTX
;
14212 /* If a variable is initialized with a string constant without embedded
14213 zeros, build CONST_STRING. */
14214 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
14216 tree enttype
= TREE_TYPE (type
);
14217 tree domain
= TYPE_DOMAIN (type
);
14218 enum machine_mode mode
= TYPE_MODE (enttype
);
14220 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
14222 && integer_zerop (TYPE_MIN_VALUE (domain
))
14223 && compare_tree_int (TYPE_MAX_VALUE (domain
),
14224 TREE_STRING_LENGTH (init
) - 1) == 0
14225 && ((size_t) TREE_STRING_LENGTH (init
)
14226 == strlen (TREE_STRING_POINTER (init
)) + 1))
14228 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
14229 ggc_strdup (TREE_STRING_POINTER (init
)));
14230 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
14231 MEM_READONLY_P (rtl
) = 1;
14234 /* Other aggregates, and complex values, could be represented using
14236 else if (AGGREGATE_TYPE_P (type
)
14237 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
14238 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
14239 || TREE_CODE (type
) == COMPLEX_TYPE
)
14241 /* Vectors only work if their mode is supported by the target.
14242 FIXME: generic vectors ought to work too. */
14243 else if (TREE_CODE (type
) == VECTOR_TYPE
14244 && !VECTOR_MODE_P (TYPE_MODE (type
)))
14246 /* If the initializer is something that we know will expand into an
14247 immediate RTL constant, expand it now. We must be careful not to
14248 reference variables which won't be output. */
14249 else if (initializer_constant_valid_p (init
, type
)
14250 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
14252 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
14254 if (TREE_CODE (type
) == VECTOR_TYPE
)
14255 switch (TREE_CODE (init
))
14260 if (TREE_CONSTANT (init
))
14262 VEC(constructor_elt
,gc
) *elts
= CONSTRUCTOR_ELTS (init
);
14263 bool constant_p
= true;
14265 unsigned HOST_WIDE_INT ix
;
14267 /* Even when ctor is constant, it might contain non-*_CST
14268 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
14269 belong into VECTOR_CST nodes. */
14270 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
14271 if (!CONSTANT_CLASS_P (value
))
14273 constant_p
= false;
14279 init
= build_vector_from_ctor (type
, elts
);
14289 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
14291 /* If expand_expr returns a MEM, it wasn't immediate. */
14292 gcc_assert (!rtl
|| !MEM_P (rtl
));
14298 /* Generate RTL for the variable DECL to represent its location. */
14301 rtl_for_decl_location (tree decl
)
14305 /* Here we have to decide where we are going to say the parameter "lives"
14306 (as far as the debugger is concerned). We only have a couple of
14307 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
14309 DECL_RTL normally indicates where the parameter lives during most of the
14310 activation of the function. If optimization is enabled however, this
14311 could be either NULL or else a pseudo-reg. Both of those cases indicate
14312 that the parameter doesn't really live anywhere (as far as the code
14313 generation parts of GCC are concerned) during most of the function's
14314 activation. That will happen (for example) if the parameter is never
14315 referenced within the function.
14317 We could just generate a location descriptor here for all non-NULL
14318 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
14319 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
14320 where DECL_RTL is NULL or is a pseudo-reg.
14322 Note however that we can only get away with using DECL_INCOMING_RTL as
14323 a backup substitute for DECL_RTL in certain limited cases. In cases
14324 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
14325 we can be sure that the parameter was passed using the same type as it is
14326 declared to have within the function, and that its DECL_INCOMING_RTL
14327 points us to a place where a value of that type is passed.
14329 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
14330 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
14331 because in these cases DECL_INCOMING_RTL points us to a value of some
14332 type which is *different* from the type of the parameter itself. Thus,
14333 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
14334 such cases, the debugger would end up (for example) trying to fetch a
14335 `float' from a place which actually contains the first part of a
14336 `double'. That would lead to really incorrect and confusing
14337 output at debug-time.
14339 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
14340 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
14341 are a couple of exceptions however. On little-endian machines we can
14342 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
14343 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
14344 an integral type that is smaller than TREE_TYPE (decl). These cases arise
14345 when (on a little-endian machine) a non-prototyped function has a
14346 parameter declared to be of type `short' or `char'. In such cases,
14347 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
14348 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
14349 passed `int' value. If the debugger then uses that address to fetch
14350 a `short' or a `char' (on a little-endian machine) the result will be
14351 the correct data, so we allow for such exceptional cases below.
14353 Note that our goal here is to describe the place where the given formal
14354 parameter lives during most of the function's activation (i.e. between the
14355 end of the prologue and the start of the epilogue). We'll do that as best
14356 as we can. Note however that if the given formal parameter is modified
14357 sometime during the execution of the function, then a stack backtrace (at
14358 debug-time) will show the function as having been called with the *new*
14359 value rather than the value which was originally passed in. This happens
14360 rarely enough that it is not a major problem, but it *is* a problem, and
14361 I'd like to fix it.
14363 A future version of dwarf2out.c may generate two additional attributes for
14364 any given DW_TAG_formal_parameter DIE which will describe the "passed
14365 type" and the "passed location" for the given formal parameter in addition
14366 to the attributes we now generate to indicate the "declared type" and the
14367 "active location" for each parameter. This additional set of attributes
14368 could be used by debuggers for stack backtraces. Separately, note that
14369 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
14370 This happens (for example) for inlined-instances of inline function formal
14371 parameters which are never referenced. This really shouldn't be
14372 happening. All PARM_DECL nodes should get valid non-NULL
14373 DECL_INCOMING_RTL values. FIXME. */
14375 /* Use DECL_RTL as the "location" unless we find something better. */
14376 rtl
= DECL_RTL_IF_SET (decl
);
14378 /* When generating abstract instances, ignore everything except
14379 constants, symbols living in memory, and symbols living in
14380 fixed registers. */
14381 if (! reload_completed
)
14384 && (CONSTANT_P (rtl
)
14386 && CONSTANT_P (XEXP (rtl
, 0)))
14388 && TREE_CODE (decl
) == VAR_DECL
14389 && TREE_STATIC (decl
))))
14391 rtl
= targetm
.delegitimize_address (rtl
);
14396 else if (TREE_CODE (decl
) == PARM_DECL
)
14398 if (rtl
== NULL_RTX
14399 || is_pseudo_reg (rtl
)
14401 && is_pseudo_reg (XEXP (rtl
, 0))
14402 && DECL_INCOMING_RTL (decl
)
14403 && MEM_P (DECL_INCOMING_RTL (decl
))
14404 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
14406 tree declared_type
= TREE_TYPE (decl
);
14407 tree passed_type
= DECL_ARG_TYPE (decl
);
14408 enum machine_mode dmode
= TYPE_MODE (declared_type
);
14409 enum machine_mode pmode
= TYPE_MODE (passed_type
);
14411 /* This decl represents a formal parameter which was optimized out.
14412 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
14413 all cases where (rtl == NULL_RTX) just below. */
14414 if (dmode
== pmode
)
14415 rtl
= DECL_INCOMING_RTL (decl
);
14416 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
14417 && SCALAR_INT_MODE_P (dmode
)
14418 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
14419 && DECL_INCOMING_RTL (decl
))
14421 rtx inc
= DECL_INCOMING_RTL (decl
);
14424 else if (MEM_P (inc
))
14426 if (BYTES_BIG_ENDIAN
)
14427 rtl
= adjust_address_nv (inc
, dmode
,
14428 GET_MODE_SIZE (pmode
)
14429 - GET_MODE_SIZE (dmode
));
14436 /* If the parm was passed in registers, but lives on the stack, then
14437 make a big endian correction if the mode of the type of the
14438 parameter is not the same as the mode of the rtl. */
14439 /* ??? This is the same series of checks that are made in dbxout.c before
14440 we reach the big endian correction code there. It isn't clear if all
14441 of these checks are necessary here, but keeping them all is the safe
14443 else if (MEM_P (rtl
)
14444 && XEXP (rtl
, 0) != const0_rtx
14445 && ! CONSTANT_P (XEXP (rtl
, 0))
14446 /* Not passed in memory. */
14447 && !MEM_P (DECL_INCOMING_RTL (decl
))
14448 /* Not passed by invisible reference. */
14449 && (!REG_P (XEXP (rtl
, 0))
14450 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
14451 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
14452 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
14453 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
14456 /* Big endian correction check. */
14457 && BYTES_BIG_ENDIAN
14458 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
14459 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
14462 enum machine_mode addr_mode
= get_address_mode (rtl
);
14463 int offset
= (UNITS_PER_WORD
14464 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
14466 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
14467 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
14470 else if (TREE_CODE (decl
) == VAR_DECL
14473 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
14474 && BYTES_BIG_ENDIAN
)
14476 enum machine_mode addr_mode
= get_address_mode (rtl
);
14477 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
14478 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
14480 /* If a variable is declared "register" yet is smaller than
14481 a register, then if we store the variable to memory, it
14482 looks like we're storing a register-sized value, when in
14483 fact we are not. We need to adjust the offset of the
14484 storage location to reflect the actual value's bytes,
14485 else gdb will not be able to display it. */
14487 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
14488 plus_constant (addr_mode
, XEXP (rtl
, 0),
14492 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
14493 and will have been substituted directly into all expressions that use it.
14494 C does not have such a concept, but C++ and other languages do. */
14495 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
14496 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
14499 rtl
= targetm
.delegitimize_address (rtl
);
14501 /* If we don't look past the constant pool, we risk emitting a
14502 reference to a constant pool entry that isn't referenced from
14503 code, and thus is not emitted. */
14505 rtl
= avoid_constant_pool_reference (rtl
);
14507 /* Try harder to get a rtl. If this symbol ends up not being emitted
14508 in the current CU, resolve_addr will remove the expression referencing
14510 if (rtl
== NULL_RTX
14511 && TREE_CODE (decl
) == VAR_DECL
14512 && !DECL_EXTERNAL (decl
)
14513 && TREE_STATIC (decl
)
14514 && DECL_NAME (decl
)
14515 && !DECL_HARD_REGISTER (decl
)
14516 && DECL_MODE (decl
) != VOIDmode
)
14518 rtl
= make_decl_rtl_for_debug (decl
);
14520 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
14521 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
14528 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
14529 returned. If so, the decl for the COMMON block is returned, and the
14530 value is the offset into the common block for the symbol. */
14533 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
14535 tree val_expr
, cvar
;
14536 enum machine_mode mode
;
14537 HOST_WIDE_INT bitsize
, bitpos
;
14539 int unsignedp
, volatilep
= 0;
14541 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
14542 it does not have a value (the offset into the common area), or if it
14543 is thread local (as opposed to global) then it isn't common, and shouldn't
14544 be handled as such. */
14545 if (TREE_CODE (decl
) != VAR_DECL
14546 || !TREE_STATIC (decl
)
14547 || !DECL_HAS_VALUE_EXPR_P (decl
)
14551 val_expr
= DECL_VALUE_EXPR (decl
);
14552 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
14555 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
14556 &mode
, &unsignedp
, &volatilep
, true);
14558 if (cvar
== NULL_TREE
14559 || TREE_CODE (cvar
) != VAR_DECL
14560 || DECL_ARTIFICIAL (cvar
)
14561 || !TREE_PUBLIC (cvar
))
14565 if (offset
!= NULL
)
14567 if (!host_integerp (offset
, 0))
14569 *value
= tree_low_cst (offset
, 0);
14572 *value
+= bitpos
/ BITS_PER_UNIT
;
14577 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
14578 data attribute for a variable or a parameter. We generate the
14579 DW_AT_const_value attribute only in those cases where the given variable
14580 or parameter does not have a true "location" either in memory or in a
14581 register. This can happen (for example) when a constant is passed as an
14582 actual argument in a call to an inline function. (It's possible that
14583 these things can crop up in other ways also.) Note that one type of
14584 constant value which can be passed into an inlined function is a constant
14585 pointer. This can happen for example if an actual argument in an inlined
14586 function call evaluates to a compile-time constant address.
14588 CACHE_P is true if it is worth caching the location list for DECL,
14589 so that future calls can reuse it rather than regenerate it from scratch.
14590 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
14591 since we will need to refer to them each time the function is inlined. */
14594 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
14595 enum dwarf_attribute attr
)
14598 dw_loc_list_ref list
;
14599 var_loc_list
*loc_list
;
14600 cached_dw_loc_list
*cache
;
14603 if (TREE_CODE (decl
) == ERROR_MARK
)
14606 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
14607 || TREE_CODE (decl
) == RESULT_DECL
);
14609 /* Try to get some constant RTL for this decl, and use that as the value of
14612 rtl
= rtl_for_decl_location (decl
);
14613 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
14614 && add_const_value_attribute (die
, rtl
))
14617 /* See if we have single element location list that is equivalent to
14618 a constant value. That way we are better to use add_const_value_attribute
14619 rather than expanding constant value equivalent. */
14620 loc_list
= lookup_decl_loc (decl
);
14623 && loc_list
->first
->next
== NULL
14624 && NOTE_P (loc_list
->first
->loc
)
14625 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
14626 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
14628 struct var_loc_node
*node
;
14630 node
= loc_list
->first
;
14631 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
14632 if (GET_CODE (rtl
) == EXPR_LIST
)
14633 rtl
= XEXP (rtl
, 0);
14634 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
14635 && add_const_value_attribute (die
, rtl
))
14638 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
14639 list several times. See if we've already cached the contents. */
14641 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
14645 cache
= (cached_dw_loc_list
*)
14646 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
14648 list
= cache
->loc_list
;
14652 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
14653 /* It is usually worth caching this result if the decl is from
14654 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
14655 if (cache_p
&& list
&& list
->dw_loc_next
)
14657 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
14658 DECL_UID (decl
), INSERT
);
14659 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
14660 cache
->decl_id
= DECL_UID (decl
);
14661 cache
->loc_list
= list
;
14667 add_AT_location_description (die
, attr
, list
);
14670 /* None of that worked, so it must not really have a location;
14671 try adding a constant value attribute from the DECL_INITIAL. */
14672 return tree_add_const_value_attribute_for_decl (die
, decl
);
14675 /* Add VARIABLE and DIE into deferred locations list. */
14678 defer_location (tree variable
, dw_die_ref die
)
14680 deferred_locations entry
;
14681 entry
.variable
= variable
;
14683 VEC_safe_push (deferred_locations
, gc
, deferred_locations_list
, entry
);
14686 /* Helper function for tree_add_const_value_attribute. Natively encode
14687 initializer INIT into an array. Return true if successful. */
14690 native_encode_initializer (tree init
, unsigned char *array
, int size
)
14694 if (init
== NULL_TREE
)
14698 switch (TREE_CODE (init
))
14701 type
= TREE_TYPE (init
);
14702 if (TREE_CODE (type
) == ARRAY_TYPE
)
14704 tree enttype
= TREE_TYPE (type
);
14705 enum machine_mode mode
= TYPE_MODE (enttype
);
14707 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
14709 if (int_size_in_bytes (type
) != size
)
14711 if (size
> TREE_STRING_LENGTH (init
))
14713 memcpy (array
, TREE_STRING_POINTER (init
),
14714 TREE_STRING_LENGTH (init
));
14715 memset (array
+ TREE_STRING_LENGTH (init
),
14716 '\0', size
- TREE_STRING_LENGTH (init
));
14719 memcpy (array
, TREE_STRING_POINTER (init
), size
);
14724 type
= TREE_TYPE (init
);
14725 if (int_size_in_bytes (type
) != size
)
14727 if (TREE_CODE (type
) == ARRAY_TYPE
)
14729 HOST_WIDE_INT min_index
;
14730 unsigned HOST_WIDE_INT cnt
;
14731 int curpos
= 0, fieldsize
;
14732 constructor_elt
*ce
;
14734 if (TYPE_DOMAIN (type
) == NULL_TREE
14735 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
14738 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
14739 if (fieldsize
<= 0)
14742 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
14743 memset (array
, '\0', size
);
14744 FOR_EACH_VEC_ELT (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
)
14746 tree val
= ce
->value
;
14747 tree index
= ce
->index
;
14749 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
14750 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
14753 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
14758 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
14761 curpos
= pos
+ fieldsize
;
14762 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
14764 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
14765 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
14766 while (count
-- > 0)
14769 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
14770 curpos
+= fieldsize
;
14773 gcc_assert (curpos
<= size
);
14777 else if (TREE_CODE (type
) == RECORD_TYPE
14778 || TREE_CODE (type
) == UNION_TYPE
)
14780 tree field
= NULL_TREE
;
14781 unsigned HOST_WIDE_INT cnt
;
14782 constructor_elt
*ce
;
14784 if (int_size_in_bytes (type
) != size
)
14787 if (TREE_CODE (type
) == RECORD_TYPE
)
14788 field
= TYPE_FIELDS (type
);
14790 FOR_EACH_VEC_ELT (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
)
14792 tree val
= ce
->value
;
14793 int pos
, fieldsize
;
14795 if (ce
->index
!= 0)
14801 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
14804 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
14805 && TYPE_DOMAIN (TREE_TYPE (field
))
14806 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
14808 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
14809 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
14811 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
14812 pos
= int_byte_position (field
);
14813 gcc_assert (pos
+ fieldsize
<= size
);
14815 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
14821 case VIEW_CONVERT_EXPR
:
14822 case NON_LVALUE_EXPR
:
14823 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
14825 return native_encode_expr (init
, array
, size
) == size
;
14829 /* Attach a DW_AT_const_value attribute to DIE. The value of the
14830 attribute is the const value T. */
14833 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
14836 tree type
= TREE_TYPE (t
);
14839 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
14843 gcc_assert (!DECL_P (init
));
14845 rtl
= rtl_for_decl_init (init
, type
);
14847 return add_const_value_attribute (die
, rtl
);
14848 /* If the host and target are sane, try harder. */
14849 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
14850 && initializer_constant_valid_p (init
, type
))
14852 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
14853 if (size
> 0 && (int) size
== size
)
14855 unsigned char *array
= (unsigned char *)
14856 ggc_alloc_cleared_atomic (size
);
14858 if (native_encode_initializer (init
, array
, size
))
14860 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
14868 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
14869 attribute is the const value of T, where T is an integral constant
14870 variable with static storage duration
14871 (so it can't be a PARM_DECL or a RESULT_DECL). */
14874 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
14878 || (TREE_CODE (decl
) != VAR_DECL
14879 && TREE_CODE (decl
) != CONST_DECL
)
14880 || (TREE_CODE (decl
) == VAR_DECL
14881 && !TREE_STATIC (decl
)))
14884 if (TREE_READONLY (decl
)
14885 && ! TREE_THIS_VOLATILE (decl
)
14886 && DECL_INITIAL (decl
))
14891 /* Don't add DW_AT_const_value if abstract origin already has one. */
14892 if (get_AT (var_die
, DW_AT_const_value
))
14895 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
14898 /* Convert the CFI instructions for the current function into a
14899 location list. This is used for DW_AT_frame_base when we targeting
14900 a dwarf2 consumer that does not support the dwarf3
14901 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
14904 static dw_loc_list_ref
14905 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
14909 dw_loc_list_ref list
, *list_tail
;
14911 dw_cfa_location last_cfa
, next_cfa
;
14912 const char *start_label
, *last_label
, *section
;
14913 dw_cfa_location remember
;
14916 gcc_assert (fde
!= NULL
);
14918 section
= secname_for_decl (current_function_decl
);
14922 memset (&next_cfa
, 0, sizeof (next_cfa
));
14923 next_cfa
.reg
= INVALID_REGNUM
;
14924 remember
= next_cfa
;
14926 start_label
= fde
->dw_fde_begin
;
14928 /* ??? Bald assumption that the CIE opcode list does not contain
14929 advance opcodes. */
14930 FOR_EACH_VEC_ELT (dw_cfi_ref
, cie_cfi_vec
, ix
, cfi
)
14931 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
14933 last_cfa
= next_cfa
;
14934 last_label
= start_label
;
14936 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
14938 /* If the first partition contained no CFI adjustments, the
14939 CIE opcodes apply to the whole first partition. */
14940 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
14941 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
14942 list_tail
=&(*list_tail
)->dw_loc_next
;
14943 start_label
= last_label
= fde
->dw_fde_second_begin
;
14946 FOR_EACH_VEC_ELT (dw_cfi_ref
, fde
->dw_fde_cfi
, ix
, cfi
)
14948 switch (cfi
->dw_cfi_opc
)
14950 case DW_CFA_set_loc
:
14951 case DW_CFA_advance_loc1
:
14952 case DW_CFA_advance_loc2
:
14953 case DW_CFA_advance_loc4
:
14954 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
14956 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
14957 start_label
, last_label
, section
);
14959 list_tail
= &(*list_tail
)->dw_loc_next
;
14960 last_cfa
= next_cfa
;
14961 start_label
= last_label
;
14963 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
14966 case DW_CFA_advance_loc
:
14967 /* The encoding is complex enough that we should never emit this. */
14968 gcc_unreachable ();
14971 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
14974 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
14976 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
14978 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
14979 start_label
, last_label
, section
);
14981 list_tail
= &(*list_tail
)->dw_loc_next
;
14982 last_cfa
= next_cfa
;
14983 start_label
= last_label
;
14985 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
14986 start_label
, fde
->dw_fde_end
, section
);
14987 list_tail
= &(*list_tail
)->dw_loc_next
;
14988 start_label
= last_label
= fde
->dw_fde_second_begin
;
14992 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
14994 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
14995 start_label
, last_label
, section
);
14996 list_tail
= &(*list_tail
)->dw_loc_next
;
14997 start_label
= last_label
;
15000 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
15002 fde
->dw_fde_second_begin
15003 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
15006 if (list
&& list
->dw_loc_next
)
15012 /* Compute a displacement from the "steady-state frame pointer" to the
15013 frame base (often the same as the CFA), and store it in
15014 frame_pointer_fb_offset. OFFSET is added to the displacement
15015 before the latter is negated. */
15018 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
15022 #ifdef FRAME_POINTER_CFA_OFFSET
15023 reg
= frame_pointer_rtx
;
15024 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
15026 reg
= arg_pointer_rtx
;
15027 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
15030 elim
= (ira_use_lra_p
15031 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
15032 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
15033 if (GET_CODE (elim
) == PLUS
)
15035 offset
+= INTVAL (XEXP (elim
, 1));
15036 elim
= XEXP (elim
, 0);
15039 frame_pointer_fb_offset
= -offset
;
15041 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15042 in which to eliminate. This is because it's stack pointer isn't
15043 directly accessible as a register within the ISA. To work around
15044 this, assume that while we cannot provide a proper value for
15045 frame_pointer_fb_offset, we won't need one either. */
15046 frame_pointer_fb_offset_valid
15047 = ((SUPPORTS_STACK_ALIGNMENT
15048 && (elim
== hard_frame_pointer_rtx
15049 || elim
== stack_pointer_rtx
))
15050 || elim
== (frame_pointer_needed
15051 ? hard_frame_pointer_rtx
15052 : stack_pointer_rtx
));
15055 /* Generate a DW_AT_name attribute given some string value to be included as
15056 the value of the attribute. */
15059 add_name_attribute (dw_die_ref die
, const char *name_string
)
15061 if (name_string
!= NULL
&& *name_string
!= 0)
15063 if (demangle_name_func
)
15064 name_string
= (*demangle_name_func
) (name_string
);
15066 add_AT_string (die
, DW_AT_name
, name_string
);
15070 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
15071 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
15072 of TYPE accordingly.
15074 ??? This is a temporary measure until after we're able to generate
15075 regular DWARF for the complex Ada type system. */
15078 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
15079 dw_die_ref context_die
)
15082 dw_die_ref dtype_die
;
15084 if (!lang_hooks
.types
.descriptive_type
)
15087 dtype
= lang_hooks
.types
.descriptive_type (type
);
15091 dtype_die
= lookup_type_die (dtype
);
15094 gen_type_die (dtype
, context_die
);
15095 dtype_die
= lookup_type_die (dtype
);
15096 gcc_assert (dtype_die
);
15099 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
15102 /* Generate a DW_AT_comp_dir attribute for DIE. */
15105 add_comp_dir_attribute (dw_die_ref die
)
15107 const char *wd
= get_src_pwd ();
15113 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
15117 wdlen
= strlen (wd
);
15118 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
15120 wd1
[wdlen
] = DIR_SEPARATOR
;
15121 wd1
[wdlen
+ 1] = 0;
15125 add_AT_string (die
, DW_AT_comp_dir
, remap_debug_filename (wd
));
15128 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
15132 lower_bound_default (void)
15134 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
15139 case DW_LANG_C_plus_plus
:
15141 case DW_LANG_ObjC_plus_plus
:
15144 case DW_LANG_Fortran77
:
15145 case DW_LANG_Fortran90
:
15146 case DW_LANG_Fortran95
:
15150 case DW_LANG_Python
:
15151 return dwarf_version
>= 4 ? 0 : -1;
15152 case DW_LANG_Ada95
:
15153 case DW_LANG_Ada83
:
15154 case DW_LANG_Cobol74
:
15155 case DW_LANG_Cobol85
:
15156 case DW_LANG_Pascal83
:
15157 case DW_LANG_Modula2
:
15159 return dwarf_version
>= 4 ? 1 : -1;
15165 /* Given a tree node describing an array bound (either lower or upper) output
15166 a representation for that bound. */
15169 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
15171 switch (TREE_CODE (bound
))
15176 /* All fixed-bounds are represented by INTEGER_CST nodes. */
15179 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
15182 /* Use the default if possible. */
15183 if (bound_attr
== DW_AT_lower_bound
15184 && host_integerp (bound
, 0)
15185 && (dflt
= lower_bound_default ()) != -1
15186 && tree_low_cst (bound
, 0) == dflt
)
15189 /* Otherwise represent the bound as an unsigned value with the
15190 precision of its type. The precision and signedness of the
15191 type will be necessary to re-interpret it unambiguously. */
15192 else if (prec
< HOST_BITS_PER_WIDE_INT
)
15194 unsigned HOST_WIDE_INT mask
15195 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
15196 add_AT_unsigned (subrange_die
, bound_attr
,
15197 TREE_INT_CST_LOW (bound
) & mask
);
15199 else if (prec
== HOST_BITS_PER_WIDE_INT
15200 || TREE_INT_CST_HIGH (bound
) == 0)
15201 add_AT_unsigned (subrange_die
, bound_attr
,
15202 TREE_INT_CST_LOW (bound
));
15204 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
15205 TREE_INT_CST_LOW (bound
));
15210 case VIEW_CONVERT_EXPR
:
15211 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
15221 dw_die_ref decl_die
= lookup_decl_die (bound
);
15223 /* ??? Can this happen, or should the variable have been bound
15224 first? Probably it can, since I imagine that we try to create
15225 the types of parameters in the order in which they exist in
15226 the list, and won't have created a forward reference to a
15227 later parameter. */
15228 if (decl_die
!= NULL
)
15230 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
15238 /* Otherwise try to create a stack operation procedure to
15239 evaluate the value of the array bound. */
15241 dw_die_ref ctx
, decl_die
;
15242 dw_loc_list_ref list
;
15244 list
= loc_list_from_tree (bound
, 2);
15245 if (list
== NULL
|| single_element_loc_list_p (list
))
15247 /* If DW_AT_*bound is not a reference nor constant, it is
15248 a DWARF expression rather than location description.
15249 For that loc_list_from_tree (bound, 0) is needed.
15250 If that fails to give a single element list,
15251 fall back to outputting this as a reference anyway. */
15252 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
15253 if (list2
&& single_element_loc_list_p (list2
))
15255 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
15262 if (current_function_decl
== 0)
15263 ctx
= comp_unit_die ();
15265 ctx
= lookup_decl_die (current_function_decl
);
15267 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
15268 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
15269 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
15270 add_AT_location_description (decl_die
, DW_AT_location
, list
);
15271 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
15277 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
15278 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
15279 Note that the block of subscript information for an array type also
15280 includes information about the element type of the given array type. */
15283 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
15285 unsigned dimension_number
;
15287 dw_die_ref subrange_die
;
15289 for (dimension_number
= 0;
15290 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
15291 type
= TREE_TYPE (type
), dimension_number
++)
15293 tree domain
= TYPE_DOMAIN (type
);
15295 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
15298 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
15299 and (in GNU C only) variable bounds. Handle all three forms
15301 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
15304 /* We have an array type with specified bounds. */
15305 lower
= TYPE_MIN_VALUE (domain
);
15306 upper
= TYPE_MAX_VALUE (domain
);
15308 /* Define the index type. */
15309 if (TREE_TYPE (domain
))
15311 /* ??? This is probably an Ada unnamed subrange type. Ignore the
15312 TREE_TYPE field. We can't emit debug info for this
15313 because it is an unnamed integral type. */
15314 if (TREE_CODE (domain
) == INTEGER_TYPE
15315 && TYPE_NAME (domain
) == NULL_TREE
15316 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
15317 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
15320 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
15324 /* ??? If upper is NULL, the array has unspecified length,
15325 but it does have a lower bound. This happens with Fortran
15327 Since the debugger is definitely going to need to know N
15328 to produce useful results, go ahead and output the lower
15329 bound solo, and hope the debugger can cope. */
15331 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
15333 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
15336 /* Otherwise we have an array type with an unspecified length. The
15337 DWARF-2 spec does not say how to handle this; let's just leave out the
15343 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
15345 dw_die_ref decl_die
;
15348 switch (TREE_CODE (tree_node
))
15353 case ENUMERAL_TYPE
:
15356 case QUAL_UNION_TYPE
:
15357 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
15358 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
15360 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
15363 size
= int_size_in_bytes (tree_node
);
15366 /* For a data member of a struct or union, the DW_AT_byte_size is
15367 generally given as the number of bytes normally allocated for an
15368 object of the *declared* type of the member itself. This is true
15369 even for bit-fields. */
15370 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
15373 gcc_unreachable ();
15376 /* Note that `size' might be -1 when we get to this point. If it is, that
15377 indicates that the byte size of the entity in question is variable. We
15378 have no good way of expressing this fact in Dwarf at the present time,
15379 so just let the -1 pass on through. */
15380 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
15383 /* For a FIELD_DECL node which represents a bit-field, output an attribute
15384 which specifies the distance in bits from the highest order bit of the
15385 "containing object" for the bit-field to the highest order bit of the
15388 For any given bit-field, the "containing object" is a hypothetical object
15389 (of some integral or enum type) within which the given bit-field lives. The
15390 type of this hypothetical "containing object" is always the same as the
15391 declared type of the individual bit-field itself. The determination of the
15392 exact location of the "containing object" for a bit-field is rather
15393 complicated. It's handled by the `field_byte_offset' function (above).
15395 Note that it is the size (in bytes) of the hypothetical "containing object"
15396 which will be given in the DW_AT_byte_size attribute for this bit-field.
15397 (See `byte_size_attribute' above). */
15400 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
15402 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
15403 tree type
= DECL_BIT_FIELD_TYPE (decl
);
15404 HOST_WIDE_INT bitpos_int
;
15405 HOST_WIDE_INT highest_order_object_bit_offset
;
15406 HOST_WIDE_INT highest_order_field_bit_offset
;
15407 HOST_WIDE_INT bit_offset
;
15409 /* Must be a field and a bit field. */
15410 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
15412 /* We can't yet handle bit-fields whose offsets are variable, so if we
15413 encounter such things, just return without generating any attribute
15414 whatsoever. Likewise for variable or too large size. */
15415 if (! host_integerp (bit_position (decl
), 0)
15416 || ! host_integerp (DECL_SIZE (decl
), 1))
15419 bitpos_int
= int_bit_position (decl
);
15421 /* Note that the bit offset is always the distance (in bits) from the
15422 highest-order bit of the "containing object" to the highest-order bit of
15423 the bit-field itself. Since the "high-order end" of any object or field
15424 is different on big-endian and little-endian machines, the computation
15425 below must take account of these differences. */
15426 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
15427 highest_order_field_bit_offset
= bitpos_int
;
15429 if (! BYTES_BIG_ENDIAN
)
15431 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
15432 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
15436 = (! BYTES_BIG_ENDIAN
15437 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
15438 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
15440 if (bit_offset
< 0)
15441 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
15443 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
15446 /* For a FIELD_DECL node which represents a bit field, output an attribute
15447 which specifies the length in bits of the given field. */
15450 add_bit_size_attribute (dw_die_ref die
, tree decl
)
15452 /* Must be a field and a bit field. */
15453 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
15454 && DECL_BIT_FIELD_TYPE (decl
));
15456 if (host_integerp (DECL_SIZE (decl
), 1))
15457 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
15460 /* If the compiled language is ANSI C, then add a 'prototyped'
15461 attribute, if arg types are given for the parameters of a function. */
15464 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
15466 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
15467 && prototype_p (func_type
))
15468 add_AT_flag (die
, DW_AT_prototyped
, 1);
15471 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
15472 by looking in either the type declaration or object declaration
15475 static inline dw_die_ref
15476 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
15478 dw_die_ref origin_die
= NULL
;
15480 if (TREE_CODE (origin
) != FUNCTION_DECL
)
15482 /* We may have gotten separated from the block for the inlined
15483 function, if we're in an exception handler or some such; make
15484 sure that the abstract function has been written out.
15486 Doing this for nested functions is wrong, however; functions are
15487 distinct units, and our context might not even be inline. */
15491 fn
= TYPE_STUB_DECL (fn
);
15493 fn
= decl_function_context (fn
);
15495 dwarf2out_abstract_function (fn
);
15498 if (DECL_P (origin
))
15499 origin_die
= lookup_decl_die (origin
);
15500 else if (TYPE_P (origin
))
15501 origin_die
= lookup_type_die (origin
);
15503 /* XXX: Functions that are never lowered don't always have correct block
15504 trees (in the case of java, they simply have no block tree, in some other
15505 languages). For these functions, there is nothing we can really do to
15506 output correct debug info for inlined functions in all cases. Rather
15507 than die, we'll just produce deficient debug info now, in that we will
15508 have variables without a proper abstract origin. In the future, when all
15509 functions are lowered, we should re-add a gcc_assert (origin_die)
15513 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
15517 /* We do not currently support the pure_virtual attribute. */
15520 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
15522 if (DECL_VINDEX (func_decl
))
15524 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
15526 if (host_integerp (DECL_VINDEX (func_decl
), 0))
15527 add_AT_loc (die
, DW_AT_vtable_elem_location
,
15528 new_loc_descr (DW_OP_constu
,
15529 tree_low_cst (DECL_VINDEX (func_decl
), 0),
15532 /* GNU extension: Record what type this method came from originally. */
15533 if (debug_info_level
> DINFO_LEVEL_TERSE
15534 && DECL_CONTEXT (func_decl
))
15535 add_AT_die_ref (die
, DW_AT_containing_type
,
15536 lookup_type_die (DECL_CONTEXT (func_decl
)));
15540 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
15541 given decl. This used to be a vendor extension until after DWARF 4
15542 standardized it. */
15545 add_linkage_attr (dw_die_ref die
, tree decl
)
15547 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
15549 /* Mimic what assemble_name_raw does with a leading '*'. */
15550 if (name
[0] == '*')
15553 if (dwarf_version
>= 4)
15554 add_AT_string (die
, DW_AT_linkage_name
, name
);
15556 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
15559 /* Add source coordinate attributes for the given decl. */
15562 add_src_coords_attributes (dw_die_ref die
, tree decl
)
15564 expanded_location s
;
15566 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
15568 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
15569 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
15570 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
15573 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
15576 add_linkage_name (dw_die_ref die
, tree decl
)
15578 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
15579 && TREE_PUBLIC (decl
)
15580 && !DECL_ABSTRACT (decl
)
15581 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
15582 && die
->die_tag
!= DW_TAG_member
)
15584 /* Defer until we have an assembler name set. */
15585 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
15587 limbo_die_node
*asm_name
;
15589 asm_name
= ggc_alloc_cleared_limbo_die_node ();
15590 asm_name
->die
= die
;
15591 asm_name
->created_for
= decl
;
15592 asm_name
->next
= deferred_asm_name
;
15593 deferred_asm_name
= asm_name
;
15595 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
15596 add_linkage_attr (die
, decl
);
15600 /* Add a DW_AT_name attribute and source coordinate attribute for the
15601 given decl, but only if it actually has a name. */
15604 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
15608 decl_name
= DECL_NAME (decl
);
15609 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
15611 const char *name
= dwarf2_name (decl
, 0);
15613 add_name_attribute (die
, name
);
15614 if (! DECL_ARTIFICIAL (decl
))
15615 add_src_coords_attributes (die
, decl
);
15617 add_linkage_name (die
, decl
);
15620 #ifdef VMS_DEBUGGING_INFO
15621 /* Get the function's name, as described by its RTL. This may be different
15622 from the DECL_NAME name used in the source file. */
15623 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
15625 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
15626 XEXP (DECL_RTL (decl
), 0));
15627 VEC_safe_push (rtx
, gc
, used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
15629 #endif /* VMS_DEBUGGING_INFO */
15632 #ifdef VMS_DEBUGGING_INFO
15633 /* Output the debug main pointer die for VMS */
15636 dwarf2out_vms_debug_main_pointer (void)
15638 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
15641 /* Allocate the VMS debug main subprogram die. */
15642 die
= ggc_alloc_cleared_die_node ();
15643 die
->die_tag
= DW_TAG_subprogram
;
15644 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
15645 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
15646 current_function_funcdef_no
);
15647 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
15649 /* Make it the first child of comp_unit_die (). */
15650 die
->die_parent
= comp_unit_die ();
15651 if (comp_unit_die ()->die_child
)
15653 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
15654 comp_unit_die ()->die_child
->die_sib
= die
;
15658 die
->die_sib
= die
;
15659 comp_unit_die ()->die_child
= die
;
15662 #endif /* VMS_DEBUGGING_INFO */
15664 /* Push a new declaration scope. */
15667 push_decl_scope (tree scope
)
15669 VEC_safe_push (tree
, gc
, decl_scope_table
, scope
);
15672 /* Pop a declaration scope. */
15675 pop_decl_scope (void)
15677 VEC_pop (tree
, decl_scope_table
);
15680 /* walk_tree helper function for uses_local_type, below. */
15683 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
15686 *walk_subtrees
= 0;
15689 tree name
= TYPE_NAME (*tp
);
15690 if (name
&& DECL_P (name
) && decl_function_context (name
))
15696 /* If TYPE involves a function-local type (including a local typedef to a
15697 non-local type), returns that type; otherwise returns NULL_TREE. */
15700 uses_local_type (tree type
)
15702 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
15706 /* Return the DIE for the scope that immediately contains this type.
15707 Non-named types that do not involve a function-local type get global
15708 scope. Named types nested in namespaces or other types get their
15709 containing scope. All other types (i.e. function-local named types) get
15710 the current active scope. */
15713 scope_die_for (tree t
, dw_die_ref context_die
)
15715 dw_die_ref scope_die
= NULL
;
15716 tree containing_scope
;
15718 /* Non-types always go in the current scope. */
15719 gcc_assert (TYPE_P (t
));
15721 /* Use the scope of the typedef, rather than the scope of the type
15723 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
15724 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
15726 containing_scope
= TYPE_CONTEXT (t
);
15728 /* Use the containing namespace if there is one. */
15729 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
15731 if (context_die
== lookup_decl_die (containing_scope
))
15733 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
15734 context_die
= get_context_die (containing_scope
);
15736 containing_scope
= NULL_TREE
;
15739 /* Ignore function type "scopes" from the C frontend. They mean that
15740 a tagged type is local to a parmlist of a function declarator, but
15741 that isn't useful to DWARF. */
15742 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
15743 containing_scope
= NULL_TREE
;
15745 if (SCOPE_FILE_SCOPE_P (containing_scope
))
15747 /* If T uses a local type keep it local as well, to avoid references
15748 to function-local DIEs from outside the function. */
15749 if (current_function_decl
&& uses_local_type (t
))
15750 scope_die
= context_die
;
15752 scope_die
= comp_unit_die ();
15754 else if (TYPE_P (containing_scope
))
15756 /* For types, we can just look up the appropriate DIE. */
15757 if (debug_info_level
> DINFO_LEVEL_TERSE
)
15758 scope_die
= get_context_die (containing_scope
);
15761 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
15762 if (scope_die
== NULL
)
15763 scope_die
= comp_unit_die ();
15767 scope_die
= context_die
;
15772 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
15775 local_scope_p (dw_die_ref context_die
)
15777 for (; context_die
; context_die
= context_die
->die_parent
)
15778 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
15779 || context_die
->die_tag
== DW_TAG_subprogram
)
15785 /* Returns nonzero if CONTEXT_DIE is a class. */
15788 class_scope_p (dw_die_ref context_die
)
15790 return (context_die
15791 && (context_die
->die_tag
== DW_TAG_structure_type
15792 || context_die
->die_tag
== DW_TAG_class_type
15793 || context_die
->die_tag
== DW_TAG_interface_type
15794 || context_die
->die_tag
== DW_TAG_union_type
));
15797 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
15798 whether or not to treat a DIE in this context as a declaration. */
15801 class_or_namespace_scope_p (dw_die_ref context_die
)
15803 return (class_scope_p (context_die
)
15804 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
15807 /* Many forms of DIEs require a "type description" attribute. This
15808 routine locates the proper "type descriptor" die for the type given
15809 by 'type', and adds a DW_AT_type attribute below the given die. */
15812 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
15813 int decl_volatile
, dw_die_ref context_die
)
15815 enum tree_code code
= TREE_CODE (type
);
15816 dw_die_ref type_die
= NULL
;
15818 /* ??? If this type is an unnamed subrange type of an integral, floating-point
15819 or fixed-point type, use the inner type. This is because we have no
15820 support for unnamed types in base_type_die. This can happen if this is
15821 an Ada subrange type. Correct solution is emit a subrange type die. */
15822 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
15823 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
15824 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
15826 if (code
== ERROR_MARK
15827 /* Handle a special case. For functions whose return type is void, we
15828 generate *no* type attribute. (Note that no object may have type
15829 `void', so this only applies to function return types). */
15830 || code
== VOID_TYPE
)
15833 type_die
= modified_type_die (type
,
15834 decl_const
|| TYPE_READONLY (type
),
15835 decl_volatile
|| TYPE_VOLATILE (type
),
15838 if (type_die
!= NULL
)
15839 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
15842 /* Given an object die, add the calling convention attribute for the
15843 function call type. */
15845 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
15847 enum dwarf_calling_convention value
= DW_CC_normal
;
15849 value
= ((enum dwarf_calling_convention
)
15850 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
15853 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
15855 /* DWARF 2 doesn't provide a way to identify a program's source-level
15856 entry point. DW_AT_calling_convention attributes are only meant
15857 to describe functions' calling conventions. However, lacking a
15858 better way to signal the Fortran main program, we used this for
15859 a long time, following existing custom. Now, DWARF 4 has
15860 DW_AT_main_subprogram, which we add below, but some tools still
15861 rely on the old way, which we thus keep. */
15862 value
= DW_CC_program
;
15864 if (dwarf_version
>= 4 || !dwarf_strict
)
15865 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
15868 /* Only add the attribute if the backend requests it, and
15869 is not DW_CC_normal. */
15870 if (value
&& (value
!= DW_CC_normal
))
15871 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
15874 /* Given a tree pointer to a struct, class, union, or enum type node, return
15875 a pointer to the (string) tag name for the given type, or zero if the type
15876 was declared without a tag. */
15878 static const char *
15879 type_tag (const_tree type
)
15881 const char *name
= 0;
15883 if (TYPE_NAME (type
) != 0)
15887 /* Find the IDENTIFIER_NODE for the type name. */
15888 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
15889 && !TYPE_NAMELESS (type
))
15890 t
= TYPE_NAME (type
);
15892 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
15893 a TYPE_DECL node, regardless of whether or not a `typedef' was
15895 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
15896 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
15898 /* We want to be extra verbose. Don't call dwarf_name if
15899 DECL_NAME isn't set. The default hook for decl_printable_name
15900 doesn't like that, and in this context it's correct to return
15901 0, instead of "<anonymous>" or the like. */
15902 if (DECL_NAME (TYPE_NAME (type
))
15903 && !DECL_NAMELESS (TYPE_NAME (type
)))
15904 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
15907 /* Now get the name as a string, or invent one. */
15908 if (!name
&& t
!= 0)
15909 name
= IDENTIFIER_POINTER (t
);
15912 return (name
== 0 || *name
== '\0') ? 0 : name
;
15915 /* Return the type associated with a data member, make a special check
15916 for bit field types. */
15919 member_declared_type (const_tree member
)
15921 return (DECL_BIT_FIELD_TYPE (member
)
15922 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
15925 /* Get the decl's label, as described by its RTL. This may be different
15926 from the DECL_NAME name used in the source file. */
15929 static const char *
15930 decl_start_label (tree decl
)
15933 const char *fnname
;
15935 x
= DECL_RTL (decl
);
15936 gcc_assert (MEM_P (x
));
15939 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
15941 fnname
= XSTR (x
, 0);
15946 /* These routines generate the internal representation of the DIE's for
15947 the compilation unit. Debugging information is collected by walking
15948 the declaration trees passed in from dwarf2out_decl(). */
15951 gen_array_type_die (tree type
, dw_die_ref context_die
)
15953 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
15954 dw_die_ref array_die
;
15956 /* GNU compilers represent multidimensional array types as sequences of one
15957 dimensional array types whose element types are themselves array types.
15958 We sometimes squish that down to a single array_type DIE with multiple
15959 subscripts in the Dwarf debugging info. The draft Dwarf specification
15960 say that we are allowed to do this kind of compression in C, because
15961 there is no difference between an array of arrays and a multidimensional
15962 array. We don't do this for Ada to remain as close as possible to the
15963 actual representation, which is especially important against the language
15964 flexibilty wrt arrays of variable size. */
15966 bool collapse_nested_arrays
= !is_ada ();
15969 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
15970 DW_TAG_string_type doesn't have DW_AT_type attribute). */
15971 if (TYPE_STRING_FLAG (type
)
15972 && TREE_CODE (type
) == ARRAY_TYPE
15974 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
15976 HOST_WIDE_INT size
;
15978 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
15979 add_name_attribute (array_die
, type_tag (type
));
15980 equate_type_number_to_die (type
, array_die
);
15981 size
= int_size_in_bytes (type
);
15983 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
15984 else if (TYPE_DOMAIN (type
) != NULL_TREE
15985 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
15986 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
15988 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
15989 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
15991 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
15992 if (loc
&& size
> 0)
15994 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
15995 if (size
!= DWARF2_ADDR_SIZE
)
15996 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16002 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16003 add_name_attribute (array_die
, type_tag (type
));
16004 equate_type_number_to_die (type
, array_die
);
16006 if (TREE_CODE (type
) == VECTOR_TYPE
)
16007 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
16009 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16011 && TREE_CODE (type
) == ARRAY_TYPE
16012 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
16013 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
16014 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16017 /* We default the array ordering. SDB will probably do
16018 the right things even if DW_AT_ordering is not present. It's not even
16019 an issue until we start to get into multidimensional arrays anyway. If
16020 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16021 then we'll have to put the DW_AT_ordering attribute back in. (But if
16022 and when we find out that we need to put these in, we will only do so
16023 for multidimensional arrays. */
16024 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
16027 if (TREE_CODE (type
) == VECTOR_TYPE
)
16029 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
16030 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16031 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
16032 add_bound_info (subrange_die
, DW_AT_upper_bound
,
16033 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
16036 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
16038 /* Add representation of the type of the elements of this array type and
16039 emit the corresponding DIE if we haven't done it already. */
16040 element_type
= TREE_TYPE (type
);
16041 if (collapse_nested_arrays
)
16042 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
16044 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
16046 element_type
= TREE_TYPE (element_type
);
16049 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
16051 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
16052 if (TYPE_ARTIFICIAL (type
))
16053 add_AT_flag (array_die
, DW_AT_artificial
, 1);
16055 if (get_AT (array_die
, DW_AT_name
))
16056 add_pubtype (type
, array_die
);
16059 static dw_loc_descr_ref
16060 descr_info_loc (tree val
, tree base_decl
)
16062 HOST_WIDE_INT size
;
16063 dw_loc_descr_ref loc
, loc2
;
16064 enum dwarf_location_atom op
;
16066 if (val
== base_decl
)
16067 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
16069 switch (TREE_CODE (val
))
16072 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16074 return loc_descriptor_from_tree (val
, 0);
16076 if (host_integerp (val
, 0))
16077 return int_loc_descriptor (tree_low_cst (val
, 0));
16080 size
= int_size_in_bytes (TREE_TYPE (val
));
16083 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16086 if (size
== DWARF2_ADDR_SIZE
)
16087 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
16089 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
16091 case POINTER_PLUS_EXPR
:
16093 if (host_integerp (TREE_OPERAND (val
, 1), 1)
16094 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
16097 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16100 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
16106 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16109 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
16112 add_loc_descr (&loc
, loc2
);
16113 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
16135 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
16136 tree val
, tree base_decl
)
16138 dw_loc_descr_ref loc
;
16140 if (host_integerp (val
, 0))
16142 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
16146 loc
= descr_info_loc (val
, base_decl
);
16150 add_AT_loc (die
, attr
, loc
);
16153 /* This routine generates DIE for array with hidden descriptor, details
16154 are filled into *info by a langhook. */
16157 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
16158 dw_die_ref context_die
)
16160 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16161 dw_die_ref array_die
;
16164 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16165 add_name_attribute (array_die
, type_tag (type
));
16166 equate_type_number_to_die (type
, array_die
);
16168 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16170 && info
->ndimensions
>= 2)
16171 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16173 if (info
->data_location
)
16174 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
16176 if (info
->associated
)
16177 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
16179 if (info
->allocated
)
16180 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
16183 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
16185 dw_die_ref subrange_die
16186 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16188 if (info
->dimen
[dim
].lower_bound
)
16190 /* If it is the default value, omit it. */
16193 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
16194 && (dflt
= lower_bound_default ()) != -1
16195 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
16198 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
16199 info
->dimen
[dim
].lower_bound
,
16202 if (info
->dimen
[dim
].upper_bound
)
16203 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
16204 info
->dimen
[dim
].upper_bound
,
16206 if (info
->dimen
[dim
].stride
)
16207 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
16208 info
->dimen
[dim
].stride
,
16212 gen_type_die (info
->element_type
, context_die
);
16213 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
16215 if (get_AT (array_die
, DW_AT_name
))
16216 add_pubtype (type
, array_die
);
16221 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
16223 tree origin
= decl_ultimate_origin (decl
);
16224 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
16226 if (origin
!= NULL
)
16227 add_abstract_origin_attribute (decl_die
, origin
);
16230 add_name_and_src_coords_attributes (decl_die
, decl
);
16231 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
16232 0, 0, context_die
);
16235 if (DECL_ABSTRACT (decl
))
16236 equate_decl_number_to_die (decl
, decl_die
);
16238 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
16242 /* Walk through the list of incomplete types again, trying once more to
16243 emit full debugging info for them. */
16246 retry_incomplete_types (void)
16250 for (i
= VEC_length (tree
, incomplete_types
) - 1; i
>= 0; i
--)
16251 if (should_emit_struct_debug (VEC_index (tree
, incomplete_types
, i
),
16252 DINFO_USAGE_DIR_USE
))
16253 gen_type_die (VEC_index (tree
, incomplete_types
, i
), comp_unit_die ());
16256 /* Determine what tag to use for a record type. */
16258 static enum dwarf_tag
16259 record_type_tag (tree type
)
16261 if (! lang_hooks
.types
.classify_record
)
16262 return DW_TAG_structure_type
;
16264 switch (lang_hooks
.types
.classify_record (type
))
16266 case RECORD_IS_STRUCT
:
16267 return DW_TAG_structure_type
;
16269 case RECORD_IS_CLASS
:
16270 return DW_TAG_class_type
;
16272 case RECORD_IS_INTERFACE
:
16273 if (dwarf_version
>= 3 || !dwarf_strict
)
16274 return DW_TAG_interface_type
;
16275 return DW_TAG_structure_type
;
16278 gcc_unreachable ();
16282 /* Generate a DIE to represent an enumeration type. Note that these DIEs
16283 include all of the information about the enumeration values also. Each
16284 enumerated type name/value is listed as a child of the enumerated type
16288 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
16290 dw_die_ref type_die
= lookup_type_die (type
);
16292 if (type_die
== NULL
)
16294 type_die
= new_die (DW_TAG_enumeration_type
,
16295 scope_die_for (type
, context_die
), type
);
16296 equate_type_number_to_die (type
, type_die
);
16297 add_name_attribute (type_die
, type_tag (type
));
16298 if (dwarf_version
>= 4 || !dwarf_strict
)
16300 if (ENUM_IS_SCOPED (type
))
16301 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
16302 if (ENUM_IS_OPAQUE (type
))
16303 add_AT_flag (type_die
, DW_AT_declaration
, 1);
16306 else if (! TYPE_SIZE (type
))
16309 remove_AT (type_die
, DW_AT_declaration
);
16311 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
16312 given enum type is incomplete, do not generate the DW_AT_byte_size
16313 attribute or the DW_AT_element_list attribute. */
16314 if (TYPE_SIZE (type
))
16318 TREE_ASM_WRITTEN (type
) = 1;
16319 add_byte_size_attribute (type_die
, type
);
16320 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
16322 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
16323 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
16326 /* If the first reference to this type was as the return type of an
16327 inline function, then it may not have a parent. Fix this now. */
16328 if (type_die
->die_parent
== NULL
)
16329 add_child_die (scope_die_for (type
, context_die
), type_die
);
16331 for (link
= TYPE_VALUES (type
);
16332 link
!= NULL
; link
= TREE_CHAIN (link
))
16334 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
16335 tree value
= TREE_VALUE (link
);
16337 add_name_attribute (enum_die
,
16338 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
16340 if (TREE_CODE (value
) == CONST_DECL
)
16341 value
= DECL_INITIAL (value
);
16343 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
16344 /* DWARF2 does not provide a way of indicating whether or
16345 not enumeration constants are signed or unsigned. GDB
16346 always assumes the values are signed, so we output all
16347 values as if they were signed. That means that
16348 enumeration constants with very large unsigned values
16349 will appear to have negative values in the debugger. */
16350 add_AT_int (enum_die
, DW_AT_const_value
,
16351 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
16354 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
16355 if (TYPE_ARTIFICIAL (type
))
16356 add_AT_flag (type_die
, DW_AT_artificial
, 1);
16359 add_AT_flag (type_die
, DW_AT_declaration
, 1);
16361 add_pubtype (type
, type_die
);
16366 /* Generate a DIE to represent either a real live formal parameter decl or to
16367 represent just the type of some formal parameter position in some function
16370 Note that this routine is a bit unusual because its argument may be a
16371 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
16372 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
16373 node. If it's the former then this function is being called to output a
16374 DIE to represent a formal parameter object (or some inlining thereof). If
16375 it's the latter, then this function is only being called to output a
16376 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
16377 argument type of some subprogram type.
16378 If EMIT_NAME_P is true, name and source coordinate attributes
16382 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
16383 dw_die_ref context_die
)
16385 tree node_or_origin
= node
? node
: origin
;
16386 tree ultimate_origin
;
16387 dw_die_ref parm_die
16388 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
16390 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
16392 case tcc_declaration
:
16393 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
16394 if (node
|| ultimate_origin
)
16395 origin
= ultimate_origin
;
16396 if (origin
!= NULL
)
16397 add_abstract_origin_attribute (parm_die
, origin
);
16398 else if (emit_name_p
)
16399 add_name_and_src_coords_attributes (parm_die
, node
);
16401 || (! DECL_ABSTRACT (node_or_origin
)
16402 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
16403 decl_function_context
16404 (node_or_origin
))))
16406 tree type
= TREE_TYPE (node_or_origin
);
16407 if (decl_by_reference_p (node_or_origin
))
16408 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
16411 add_type_attribute (parm_die
, type
,
16412 TREE_READONLY (node_or_origin
),
16413 TREE_THIS_VOLATILE (node_or_origin
),
16416 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
16417 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
16419 if (node
&& node
!= origin
)
16420 equate_decl_number_to_die (node
, parm_die
);
16421 if (! DECL_ABSTRACT (node_or_origin
))
16422 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
16423 node
== NULL
, DW_AT_location
);
16428 /* We were called with some kind of a ..._TYPE node. */
16429 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
16433 gcc_unreachable ();
16439 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
16440 children DW_TAG_formal_parameter DIEs representing the arguments of the
16443 PARM_PACK must be a function parameter pack.
16444 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
16445 must point to the subsequent arguments of the function PACK_ARG belongs to.
16446 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
16447 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
16448 following the last one for which a DIE was generated. */
16451 gen_formal_parameter_pack_die (tree parm_pack
,
16453 dw_die_ref subr_die
,
16457 dw_die_ref parm_pack_die
;
16459 gcc_assert (parm_pack
16460 && lang_hooks
.function_parameter_pack_p (parm_pack
)
16463 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
16464 add_src_coords_attributes (parm_pack_die
, parm_pack
);
16466 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
16468 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
16471 gen_formal_parameter_die (arg
, NULL
,
16472 false /* Don't emit name attribute. */,
16477 return parm_pack_die
;
16480 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
16481 at the end of an (ANSI prototyped) formal parameters list. */
16484 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
16486 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
16489 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
16490 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
16491 parameters as specified in some function type specification (except for
16492 those which appear as part of a function *definition*). */
16495 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
16498 tree formal_type
= NULL
;
16499 tree first_parm_type
;
16502 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
16504 arg
= DECL_ARGUMENTS (function_or_method_type
);
16505 function_or_method_type
= TREE_TYPE (function_or_method_type
);
16510 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
16512 /* Make our first pass over the list of formal parameter types and output a
16513 DW_TAG_formal_parameter DIE for each one. */
16514 for (link
= first_parm_type
; link
; )
16516 dw_die_ref parm_die
;
16518 formal_type
= TREE_VALUE (link
);
16519 if (formal_type
== void_type_node
)
16522 /* Output a (nameless) DIE to represent the formal parameter itself. */
16523 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
16524 true /* Emit name attribute. */,
16526 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
16527 && link
== first_parm_type
)
16529 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
16530 if (dwarf_version
>= 3 || !dwarf_strict
)
16531 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
16533 else if (arg
&& DECL_ARTIFICIAL (arg
))
16534 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
16536 link
= TREE_CHAIN (link
);
16538 arg
= DECL_CHAIN (arg
);
16541 /* If this function type has an ellipsis, add a
16542 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
16543 if (formal_type
!= void_type_node
)
16544 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
16546 /* Make our second (and final) pass over the list of formal parameter types
16547 and output DIEs to represent those types (as necessary). */
16548 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
16549 link
&& TREE_VALUE (link
);
16550 link
= TREE_CHAIN (link
))
16551 gen_type_die (TREE_VALUE (link
), context_die
);
16554 /* We want to generate the DIE for TYPE so that we can generate the
16555 die for MEMBER, which has been defined; we will need to refer back
16556 to the member declaration nested within TYPE. If we're trying to
16557 generate minimal debug info for TYPE, processing TYPE won't do the
16558 trick; we need to attach the member declaration by hand. */
16561 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
16563 gen_type_die (type
, context_die
);
16565 /* If we're trying to avoid duplicate debug info, we may not have
16566 emitted the member decl for this function. Emit it now. */
16567 if (TYPE_STUB_DECL (type
)
16568 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
16569 && ! lookup_decl_die (member
))
16571 dw_die_ref type_die
;
16572 gcc_assert (!decl_ultimate_origin (member
));
16574 push_decl_scope (type
);
16575 type_die
= lookup_type_die_strip_naming_typedef (type
);
16576 if (TREE_CODE (member
) == FUNCTION_DECL
)
16577 gen_subprogram_die (member
, type_die
);
16578 else if (TREE_CODE (member
) == FIELD_DECL
)
16580 /* Ignore the nameless fields that are used to skip bits but handle
16581 C++ anonymous unions and structs. */
16582 if (DECL_NAME (member
) != NULL_TREE
16583 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
16584 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
16586 gen_type_die (member_declared_type (member
), type_die
);
16587 gen_field_die (member
, type_die
);
16591 gen_variable_die (member
, NULL_TREE
, type_die
);
16597 /* Forward declare these functions, because they are mutually recursive
16598 with their set_block_* pairing functions. */
16599 static void set_decl_origin_self (tree
);
16600 static void set_decl_abstract_flags (tree
, int);
16602 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
16603 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
16604 that it points to the node itself, thus indicating that the node is its
16605 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
16606 the given node is NULL, recursively descend the decl/block tree which
16607 it is the root of, and for each other ..._DECL or BLOCK node contained
16608 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
16609 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
16610 values to point to themselves. */
16613 set_block_origin_self (tree stmt
)
16615 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
16617 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
16622 for (local_decl
= BLOCK_VARS (stmt
);
16623 local_decl
!= NULL_TREE
;
16624 local_decl
= DECL_CHAIN (local_decl
))
16625 if (! DECL_EXTERNAL (local_decl
))
16626 set_decl_origin_self (local_decl
); /* Potential recursion. */
16632 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
16633 subblock
!= NULL_TREE
;
16634 subblock
= BLOCK_CHAIN (subblock
))
16635 set_block_origin_self (subblock
); /* Recurse. */
16640 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
16641 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
16642 node to so that it points to the node itself, thus indicating that the
16643 node represents its own (abstract) origin. Additionally, if the
16644 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
16645 the decl/block tree of which the given node is the root of, and for
16646 each other ..._DECL or BLOCK node contained therein whose
16647 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
16648 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
16649 point to themselves. */
16652 set_decl_origin_self (tree decl
)
16654 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
16656 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
16657 if (TREE_CODE (decl
) == FUNCTION_DECL
)
16661 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
16662 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
16663 if (DECL_INITIAL (decl
) != NULL_TREE
16664 && DECL_INITIAL (decl
) != error_mark_node
)
16665 set_block_origin_self (DECL_INITIAL (decl
));
16670 /* Given a pointer to some BLOCK node, and a boolean value to set the
16671 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
16672 the given block, and for all local decls and all local sub-blocks
16673 (recursively) which are contained therein. */
16676 set_block_abstract_flags (tree stmt
, int setting
)
16682 BLOCK_ABSTRACT (stmt
) = setting
;
16684 for (local_decl
= BLOCK_VARS (stmt
);
16685 local_decl
!= NULL_TREE
;
16686 local_decl
= DECL_CHAIN (local_decl
))
16687 if (! DECL_EXTERNAL (local_decl
))
16688 set_decl_abstract_flags (local_decl
, setting
);
16690 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
16692 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
16693 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
16694 || TREE_CODE (local_decl
) == PARM_DECL
)
16695 set_decl_abstract_flags (local_decl
, setting
);
16698 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
16699 subblock
!= NULL_TREE
;
16700 subblock
= BLOCK_CHAIN (subblock
))
16701 set_block_abstract_flags (subblock
, setting
);
16704 /* Given a pointer to some ..._DECL node, and a boolean value to set the
16705 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
16706 given decl, and (in the case where the decl is a FUNCTION_DECL) also
16707 set the abstract flags for all of the parameters, local vars, local
16708 blocks and sub-blocks (recursively) to the same setting. */
16711 set_decl_abstract_flags (tree decl
, int setting
)
16713 DECL_ABSTRACT (decl
) = setting
;
16714 if (TREE_CODE (decl
) == FUNCTION_DECL
)
16718 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
16719 DECL_ABSTRACT (arg
) = setting
;
16720 if (DECL_INITIAL (decl
) != NULL_TREE
16721 && DECL_INITIAL (decl
) != error_mark_node
)
16722 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
16726 /* Generate the DWARF2 info for the "abstract" instance of a function which we
16727 may later generate inlined and/or out-of-line instances of. */
16730 dwarf2out_abstract_function (tree decl
)
16732 dw_die_ref old_die
;
16736 htab_t old_decl_loc_table
;
16737 htab_t old_cached_dw_loc_list_table
;
16738 int old_call_site_count
, old_tail_call_site_count
;
16739 struct call_arg_loc_node
*old_call_arg_locations
;
16741 /* Make sure we have the actual abstract inline, not a clone. */
16742 decl
= DECL_ORIGIN (decl
);
16744 old_die
= lookup_decl_die (decl
);
16745 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
16746 /* We've already generated the abstract instance. */
16749 /* We can be called while recursively when seeing block defining inlined subroutine
16750 DIE. Be sure to not clobber the outer location table nor use it or we would
16751 get locations in abstract instantces. */
16752 old_decl_loc_table
= decl_loc_table
;
16753 decl_loc_table
= NULL
;
16754 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
16755 cached_dw_loc_list_table
= NULL
;
16756 old_call_arg_locations
= call_arg_locations
;
16757 call_arg_locations
= NULL
;
16758 old_call_site_count
= call_site_count
;
16759 call_site_count
= -1;
16760 old_tail_call_site_count
= tail_call_site_count
;
16761 tail_call_site_count
= -1;
16763 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
16764 we don't get confused by DECL_ABSTRACT. */
16765 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16767 context
= decl_class_context (decl
);
16769 gen_type_die_for_member
16770 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
16773 /* Pretend we've just finished compiling this function. */
16774 save_fn
= current_function_decl
;
16775 current_function_decl
= decl
;
16777 was_abstract
= DECL_ABSTRACT (decl
);
16778 set_decl_abstract_flags (decl
, 1);
16779 dwarf2out_decl (decl
);
16780 if (! was_abstract
)
16781 set_decl_abstract_flags (decl
, 0);
16783 current_function_decl
= save_fn
;
16784 decl_loc_table
= old_decl_loc_table
;
16785 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
16786 call_arg_locations
= old_call_arg_locations
;
16787 call_site_count
= old_call_site_count
;
16788 tail_call_site_count
= old_tail_call_site_count
;
16791 /* Helper function of premark_used_types() which gets called through
16794 Marks the DIE of a given type in *SLOT as perennial, so it never gets
16795 marked as unused by prune_unused_types. */
16798 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
16803 type
= (tree
) *slot
;
16804 die
= lookup_type_die (type
);
16806 die
->die_perennial_p
= 1;
16810 /* Helper function of premark_types_used_by_global_vars which gets called
16811 through htab_traverse.
16813 Marks the DIE of a given type in *SLOT as perennial, so it never gets
16814 marked as unused by prune_unused_types. The DIE of the type is marked
16815 only if the global variable using the type will actually be emitted. */
16818 premark_types_used_by_global_vars_helper (void **slot
,
16819 void *data ATTRIBUTE_UNUSED
)
16821 struct types_used_by_vars_entry
*entry
;
16824 entry
= (struct types_used_by_vars_entry
*) *slot
;
16825 gcc_assert (entry
->type
!= NULL
16826 && entry
->var_decl
!= NULL
);
16827 die
= lookup_type_die (entry
->type
);
16830 /* Ask cgraph if the global variable really is to be emitted.
16831 If yes, then we'll keep the DIE of ENTRY->TYPE. */
16832 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
16833 if (node
&& node
->analyzed
)
16835 die
->die_perennial_p
= 1;
16836 /* Keep the parent DIEs as well. */
16837 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
16838 die
->die_perennial_p
= 1;
16844 /* Mark all members of used_types_hash as perennial. */
16847 premark_used_types (struct function
*fun
)
16849 if (fun
&& fun
->used_types_hash
)
16850 htab_traverse (fun
->used_types_hash
, premark_used_types_helper
, NULL
);
16853 /* Mark all members of types_used_by_vars_entry as perennial. */
16856 premark_types_used_by_global_vars (void)
16858 if (types_used_by_vars_hash
)
16859 htab_traverse (types_used_by_vars_hash
,
16860 premark_types_used_by_global_vars_helper
, NULL
);
16863 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
16864 for CA_LOC call arg loc node. */
16867 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
16868 struct call_arg_loc_node
*ca_loc
)
16870 dw_die_ref stmt_die
= NULL
, die
;
16871 tree block
= ca_loc
->block
;
16874 && block
!= DECL_INITIAL (decl
)
16875 && TREE_CODE (block
) == BLOCK
)
16877 if (VEC_length (dw_die_ref
, block_map
) > BLOCK_NUMBER (block
))
16878 stmt_die
= VEC_index (dw_die_ref
, block_map
, BLOCK_NUMBER (block
));
16881 block
= BLOCK_SUPERCONTEXT (block
);
16883 if (stmt_die
== NULL
)
16884 stmt_die
= subr_die
;
16885 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
16886 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
16887 if (ca_loc
->tail_call_p
)
16888 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
16889 if (ca_loc
->symbol_ref
)
16891 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
16893 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
16895 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
);
16900 /* Generate a DIE to represent a declared function (either file-scope or
16904 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
16906 tree origin
= decl_ultimate_origin (decl
);
16907 dw_die_ref subr_die
;
16909 dw_die_ref old_die
= lookup_decl_die (decl
);
16910 int declaration
= (current_function_decl
!= decl
16911 || class_or_namespace_scope_p (context_die
));
16913 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
16915 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
16916 started to generate the abstract instance of an inline, decided to output
16917 its containing class, and proceeded to emit the declaration of the inline
16918 from the member list for the class. If so, DECLARATION takes priority;
16919 we'll get back to the abstract instance when done with the class. */
16921 /* The class-scope declaration DIE must be the primary DIE. */
16922 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
16925 gcc_assert (!old_die
);
16928 /* Now that the C++ front end lazily declares artificial member fns, we
16929 might need to retrofit the declaration into its class. */
16930 if (!declaration
&& !origin
&& !old_die
16931 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
16932 && !class_or_namespace_scope_p (context_die
)
16933 && debug_info_level
> DINFO_LEVEL_TERSE
)
16934 old_die
= force_decl_die (decl
);
16936 if (origin
!= NULL
)
16938 gcc_assert (!declaration
|| local_scope_p (context_die
));
16940 /* Fixup die_parent for the abstract instance of a nested
16941 inline function. */
16942 if (old_die
&& old_die
->die_parent
== NULL
)
16943 add_child_die (context_die
, old_die
);
16945 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
16946 add_abstract_origin_attribute (subr_die
, origin
);
16947 /* This is where the actual code for a cloned function is.
16948 Let's emit linkage name attribute for it. This helps
16949 debuggers to e.g, set breakpoints into
16950 constructors/destructors when the user asks "break
16952 add_linkage_name (subr_die
, decl
);
16956 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16957 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
16959 if (!get_AT_flag (old_die
, DW_AT_declaration
)
16960 /* We can have a normal definition following an inline one in the
16961 case of redefinition of GNU C extern inlines.
16962 It seems reasonable to use AT_specification in this case. */
16963 && !get_AT (old_die
, DW_AT_inline
))
16965 /* Detect and ignore this case, where we are trying to output
16966 something we have already output. */
16970 /* If the definition comes from the same place as the declaration,
16971 maybe use the old DIE. We always want the DIE for this function
16972 that has the *_pc attributes to be under comp_unit_die so the
16973 debugger can find it. We also need to do this for abstract
16974 instances of inlines, since the spec requires the out-of-line copy
16975 to have the same parent. For local class methods, this doesn't
16976 apply; we just use the old DIE. */
16977 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
16978 && (DECL_ARTIFICIAL (decl
)
16979 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
16980 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
16981 == (unsigned) s
.line
))))
16983 subr_die
= old_die
;
16985 /* Clear out the declaration attribute and the formal parameters.
16986 Do not remove all children, because it is possible that this
16987 declaration die was forced using force_decl_die(). In such
16988 cases die that forced declaration die (e.g. TAG_imported_module)
16989 is one of the children that we do not want to remove. */
16990 remove_AT (subr_die
, DW_AT_declaration
);
16991 remove_AT (subr_die
, DW_AT_object_pointer
);
16992 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
16996 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
16997 add_AT_specification (subr_die
, old_die
);
16998 add_pubname (decl
, subr_die
);
16999 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17000 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
17001 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17002 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
17007 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17009 if (TREE_PUBLIC (decl
))
17010 add_AT_flag (subr_die
, DW_AT_external
, 1);
17012 add_name_and_src_coords_attributes (subr_die
, decl
);
17013 add_pubname (decl
, subr_die
);
17014 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17016 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
17017 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
17018 0, 0, context_die
);
17021 add_pure_or_virtual_attribute (subr_die
, decl
);
17022 if (DECL_ARTIFICIAL (decl
))
17023 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17025 add_accessibility_attribute (subr_die
, decl
);
17030 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17032 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
17034 /* If this is an explicit function declaration then generate
17035 a DW_AT_explicit attribute. */
17036 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
17037 && (dwarf_version
>= 3 || !dwarf_strict
))
17038 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
17040 /* The first time we see a member function, it is in the context of
17041 the class to which it belongs. We make sure of this by emitting
17042 the class first. The next time is the definition, which is
17043 handled above. The two may come from the same source text.
17045 Note that force_decl_die() forces function declaration die. It is
17046 later reused to represent definition. */
17047 equate_decl_number_to_die (decl
, subr_die
);
17050 else if (DECL_ABSTRACT (decl
))
17052 if (DECL_DECLARED_INLINE_P (decl
))
17054 if (cgraph_function_possibly_inlined_p (decl
))
17055 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
17057 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
17061 if (cgraph_function_possibly_inlined_p (decl
))
17062 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
17064 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
17067 if (DECL_DECLARED_INLINE_P (decl
)
17068 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
17069 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17071 equate_decl_number_to_die (decl
, subr_die
);
17073 else if (!DECL_EXTERNAL (decl
))
17075 HOST_WIDE_INT cfa_fb_offset
;
17076 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
17078 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17079 equate_decl_number_to_die (decl
, subr_die
);
17081 gcc_checking_assert (fun
);
17082 if (!flag_reorder_blocks_and_partition
)
17084 dw_fde_ref fde
= fun
->fde
;
17085 if (fde
->dw_fde_begin
)
17087 /* We have already generated the labels. */
17088 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
);
17092 /* Create start/end labels and add the range. */
17093 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
17094 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
17095 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
17096 current_function_funcdef_no
);
17097 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
17098 current_function_funcdef_no
);
17099 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
);
17102 #if VMS_DEBUGGING_INFO
17103 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17104 Section 2.3 Prologue and Epilogue Attributes:
17105 When a breakpoint is set on entry to a function, it is generally
17106 desirable for execution to be suspended, not on the very first
17107 instruction of the function, but rather at a point after the
17108 function's frame has been set up, after any language defined local
17109 declaration processing has been completed, and before execution of
17110 the first statement of the function begins. Debuggers generally
17111 cannot properly determine where this point is. Similarly for a
17112 breakpoint set on exit from a function. The prologue and epilogue
17113 attributes allow a compiler to communicate the location(s) to use. */
17116 if (fde
->dw_fde_vms_end_prologue
)
17117 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
17118 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
17120 if (fde
->dw_fde_vms_begin_epilogue
)
17121 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
17122 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
17129 /* Generate pubnames entries for the split function code ranges. */
17130 dw_fde_ref fde
= fun
->fde
;
17132 if (fde
->dw_fde_second_begin
)
17134 if (dwarf_version
>= 3 || !dwarf_strict
)
17136 /* We should use ranges for non-contiguous code section
17137 addresses. Use the actual code range for the initial
17138 section, since the HOT/COLD labels might precede an
17139 alignment offset. */
17140 bool range_list_added
= false;
17141 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
17142 fde
->dw_fde_end
, &range_list_added
);
17143 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
17144 fde
->dw_fde_second_end
,
17145 &range_list_added
);
17146 if (range_list_added
)
17151 /* There is no real support in DW2 for this .. so we make
17152 a work-around. First, emit the pub name for the segment
17153 containing the function label. Then make and emit a
17154 simplified subprogram DIE for the second segment with the
17155 name pre-fixed by __hot/cold_sect_of_. We use the same
17156 linkage name for the second die so that gdb will find both
17157 sections when given "b foo". */
17158 const char *name
= NULL
;
17159 tree decl_name
= DECL_NAME (decl
);
17160 dw_die_ref seg_die
;
17162 /* Do the 'primary' section. */
17163 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
17166 /* Build a minimal DIE for the secondary section. */
17167 seg_die
= new_die (DW_TAG_subprogram
,
17168 subr_die
->die_parent
, decl
);
17170 if (TREE_PUBLIC (decl
))
17171 add_AT_flag (seg_die
, DW_AT_external
, 1);
17173 if (decl_name
!= NULL
17174 && IDENTIFIER_POINTER (decl_name
) != NULL
)
17176 name
= dwarf2_name (decl
, 1);
17177 if (! DECL_ARTIFICIAL (decl
))
17178 add_src_coords_attributes (seg_die
, decl
);
17180 add_linkage_name (seg_die
, decl
);
17182 gcc_assert (name
!= NULL
);
17183 add_pure_or_virtual_attribute (seg_die
, decl
);
17184 if (DECL_ARTIFICIAL (decl
))
17185 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
17187 name
= concat ("__second_sect_of_", name
, NULL
);
17188 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
17189 fde
->dw_fde_second_end
);
17190 add_name_attribute (seg_die
, name
);
17191 if (want_pubnames ())
17192 add_pubname_string (name
, seg_die
);
17196 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
);
17199 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
17201 /* We define the "frame base" as the function's CFA. This is more
17202 convenient for several reasons: (1) It's stable across the prologue
17203 and epilogue, which makes it better than just a frame pointer,
17204 (2) With dwarf3, there exists a one-byte encoding that allows us
17205 to reference the .debug_frame data by proxy, but failing that,
17206 (3) We can at least reuse the code inspection and interpretation
17207 code that determines the CFA position at various points in the
17209 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
17211 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
17212 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
17216 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
17217 if (list
->dw_loc_next
)
17218 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
17220 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
17223 /* Compute a displacement from the "steady-state frame pointer" to
17224 the CFA. The former is what all stack slots and argument slots
17225 will reference in the rtl; the later is what we've told the
17226 debugger about. We'll need to adjust all frame_base references
17227 by this displacement. */
17228 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
17230 if (fun
->static_chain_decl
)
17231 add_AT_location_description (subr_die
, DW_AT_static_link
,
17232 loc_list_from_tree (fun
->static_chain_decl
, 2));
17235 /* Generate child dies for template paramaters. */
17236 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17237 gen_generic_params_dies (decl
);
17239 /* Now output descriptions of the arguments for this function. This gets
17240 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
17241 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
17242 `...' at the end of the formal parameter list. In order to find out if
17243 there was a trailing ellipsis or not, we must instead look at the type
17244 associated with the FUNCTION_DECL. This will be a node of type
17245 FUNCTION_TYPE. If the chain of type nodes hanging off of this
17246 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
17247 an ellipsis at the end. */
17249 /* In the case where we are describing a mere function declaration, all we
17250 need to do here (and all we *can* do here) is to describe the *types* of
17251 its formal parameters. */
17252 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
17254 else if (declaration
)
17255 gen_formal_types_die (decl
, subr_die
);
17258 /* Generate DIEs to represent all known formal parameters. */
17259 tree parm
= DECL_ARGUMENTS (decl
);
17260 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
17261 tree generic_decl_parm
= generic_decl
17262 ? DECL_ARGUMENTS (generic_decl
)
17265 /* Now we want to walk the list of parameters of the function and
17266 emit their relevant DIEs.
17268 We consider the case of DECL being an instance of a generic function
17269 as well as it being a normal function.
17271 If DECL is an instance of a generic function we walk the
17272 parameters of the generic function declaration _and_ the parameters of
17273 DECL itself. This is useful because we want to emit specific DIEs for
17274 function parameter packs and those are declared as part of the
17275 generic function declaration. In that particular case,
17276 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
17277 That DIE has children DIEs representing the set of arguments
17278 of the pack. Note that the set of pack arguments can be empty.
17279 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
17282 Otherwise, we just consider the parameters of DECL. */
17283 while (generic_decl_parm
|| parm
)
17285 if (generic_decl_parm
17286 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
17287 gen_formal_parameter_pack_die (generic_decl_parm
,
17292 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
17294 if (parm
== DECL_ARGUMENTS (decl
)
17295 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
17297 && (dwarf_version
>= 3 || !dwarf_strict
))
17298 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
17300 parm
= DECL_CHAIN (parm
);
17303 if (generic_decl_parm
)
17304 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
17307 /* Decide whether we need an unspecified_parameters DIE at the end.
17308 There are 2 more cases to do this for: 1) the ansi ... declaration -
17309 this is detectable when the end of the arg list is not a
17310 void_type_node 2) an unprototyped function declaration (not a
17311 definition). This just means that we have no info about the
17312 parameters at all. */
17313 if (prototype_p (TREE_TYPE (decl
)))
17315 /* This is the prototyped case, check for.... */
17316 if (stdarg_p (TREE_TYPE (decl
)))
17317 gen_unspecified_parameters_die (decl
, subr_die
);
17319 else if (DECL_INITIAL (decl
) == NULL_TREE
)
17320 gen_unspecified_parameters_die (decl
, subr_die
);
17323 /* Output Dwarf info for all of the stuff within the body of the function
17324 (if it has one - it may be just a declaration). */
17325 outer_scope
= DECL_INITIAL (decl
);
17327 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
17328 a function. This BLOCK actually represents the outermost binding contour
17329 for the function, i.e. the contour in which the function's formal
17330 parameters and labels get declared. Curiously, it appears that the front
17331 end doesn't actually put the PARM_DECL nodes for the current function onto
17332 the BLOCK_VARS list for this outer scope, but are strung off of the
17333 DECL_ARGUMENTS list for the function instead.
17335 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
17336 the LABEL_DECL nodes for the function however, and we output DWARF info
17337 for those in decls_for_scope. Just within the `outer_scope' there will be
17338 a BLOCK node representing the function's outermost pair of curly braces,
17339 and any blocks used for the base and member initializers of a C++
17340 constructor function. */
17341 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
17343 int call_site_note_count
= 0;
17344 int tail_call_site_note_count
= 0;
17346 /* Emit a DW_TAG_variable DIE for a named return value. */
17347 if (DECL_NAME (DECL_RESULT (decl
)))
17348 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
17350 current_function_has_inlines
= 0;
17351 decls_for_scope (outer_scope
, subr_die
, 0);
17353 if (call_arg_locations
&& !dwarf_strict
)
17355 struct call_arg_loc_node
*ca_loc
;
17356 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
17358 dw_die_ref die
= NULL
;
17359 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
17362 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
17363 arg
; arg
= next_arg
)
17365 dw_loc_descr_ref reg
, val
;
17366 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
17367 dw_die_ref cdie
, tdie
= NULL
;
17369 next_arg
= XEXP (arg
, 1);
17370 if (REG_P (XEXP (XEXP (arg
, 0), 0))
17372 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
17373 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
17374 && REGNO (XEXP (XEXP (arg
, 0), 0))
17375 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
17376 next_arg
= XEXP (next_arg
, 1);
17377 if (mode
== VOIDmode
)
17379 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
17380 if (mode
== VOIDmode
)
17381 mode
= GET_MODE (XEXP (arg
, 0));
17383 if (mode
== VOIDmode
|| mode
== BLKmode
)
17385 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
17387 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
17388 tloc
= XEXP (XEXP (arg
, 0), 1);
17391 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
17392 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
17394 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
17395 tlocc
= XEXP (XEXP (arg
, 0), 1);
17399 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
17400 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
17401 VAR_INIT_STATUS_INITIALIZED
);
17402 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
17404 rtx mem
= XEXP (XEXP (arg
, 0), 0);
17405 reg
= mem_loc_descriptor (XEXP (mem
, 0),
17406 get_address_mode (mem
),
17408 VAR_INIT_STATUS_INITIALIZED
);
17410 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
17411 == DEBUG_PARAMETER_REF
)
17414 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
17415 tdie
= lookup_decl_die (tdecl
);
17422 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
17423 != DEBUG_PARAMETER_REF
)
17425 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
17427 VAR_INIT_STATUS_INITIALIZED
);
17431 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
17432 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
17435 add_AT_loc (cdie
, DW_AT_location
, reg
);
17436 else if (tdie
!= NULL
)
17437 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
17438 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
17439 if (next_arg
!= XEXP (arg
, 1))
17441 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
17442 if (mode
== VOIDmode
)
17443 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
17444 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
17447 VAR_INIT_STATUS_INITIALIZED
);
17449 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
17453 && (ca_loc
->symbol_ref
|| tloc
))
17454 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
17455 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
17457 dw_loc_descr_ref tval
= NULL
;
17459 if (tloc
!= NULL_RTX
)
17460 tval
= mem_loc_descriptor (tloc
,
17461 GET_MODE (tloc
) == VOIDmode
17462 ? Pmode
: GET_MODE (tloc
),
17464 VAR_INIT_STATUS_INITIALIZED
);
17466 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
17467 else if (tlocc
!= NULL_RTX
)
17469 tval
= mem_loc_descriptor (tlocc
,
17470 GET_MODE (tlocc
) == VOIDmode
17471 ? Pmode
: GET_MODE (tlocc
),
17473 VAR_INIT_STATUS_INITIALIZED
);
17475 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
17481 call_site_note_count
++;
17482 if (ca_loc
->tail_call_p
)
17483 tail_call_site_note_count
++;
17487 call_arg_locations
= NULL
;
17488 call_arg_loc_last
= NULL
;
17489 if (tail_call_site_count
>= 0
17490 && tail_call_site_count
== tail_call_site_note_count
17493 if (call_site_count
>= 0
17494 && call_site_count
== call_site_note_count
)
17495 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
17497 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
17499 call_site_count
= -1;
17500 tail_call_site_count
= -1;
17502 /* Add the calling convention attribute if requested. */
17503 add_calling_convention_attribute (subr_die
, decl
);
17507 /* Returns a hash value for X (which really is a die_struct). */
17510 common_block_die_table_hash (const void *x
)
17512 const_dw_die_ref d
= (const_dw_die_ref
) x
;
17513 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
17516 /* Return nonzero if decl_id and die_parent of die_struct X is the same
17517 as decl_id and die_parent of die_struct Y. */
17520 common_block_die_table_eq (const void *x
, const void *y
)
17522 const_dw_die_ref d
= (const_dw_die_ref
) x
;
17523 const_dw_die_ref e
= (const_dw_die_ref
) y
;
17524 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
17527 /* Generate a DIE to represent a declared data object.
17528 Either DECL or ORIGIN must be non-null. */
17531 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
17533 HOST_WIDE_INT off
= 0;
17535 tree decl_or_origin
= decl
? decl
: origin
;
17536 tree ultimate_origin
;
17537 dw_die_ref var_die
;
17538 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
17539 dw_die_ref origin_die
;
17540 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
17541 || class_or_namespace_scope_p (context_die
));
17542 bool specialization_p
= false;
17544 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
17545 if (decl
|| ultimate_origin
)
17546 origin
= ultimate_origin
;
17547 com_decl
= fortran_common (decl_or_origin
, &off
);
17549 /* Symbol in common gets emitted as a child of the common block, in the form
17550 of a data member. */
17553 dw_die_ref com_die
;
17554 dw_loc_list_ref loc
;
17555 die_node com_die_arg
;
17557 var_die
= lookup_decl_die (decl_or_origin
);
17560 if (get_AT (var_die
, DW_AT_location
) == NULL
)
17562 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
17567 /* Optimize the common case. */
17568 if (single_element_loc_list_p (loc
)
17569 && loc
->expr
->dw_loc_opc
== DW_OP_addr
17570 && loc
->expr
->dw_loc_next
== NULL
17571 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
17574 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
17575 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
17576 = plus_constant (GET_MODE (x
), x
, off
);
17579 loc_list_plus_const (loc
, off
);
17581 add_AT_location_description (var_die
, DW_AT_location
, loc
);
17582 remove_AT (var_die
, DW_AT_declaration
);
17588 if (common_block_die_table
== NULL
)
17589 common_block_die_table
17590 = htab_create_ggc (10, common_block_die_table_hash
,
17591 common_block_die_table_eq
, NULL
);
17593 com_die_arg
.decl_id
= DECL_UID (com_decl
);
17594 com_die_arg
.die_parent
= context_die
;
17595 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
17596 loc
= loc_list_from_tree (com_decl
, 2);
17597 if (com_die
== NULL
)
17600 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
17603 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
17604 add_name_and_src_coords_attributes (com_die
, com_decl
);
17607 add_AT_location_description (com_die
, DW_AT_location
, loc
);
17608 /* Avoid sharing the same loc descriptor between
17609 DW_TAG_common_block and DW_TAG_variable. */
17610 loc
= loc_list_from_tree (com_decl
, 2);
17612 else if (DECL_EXTERNAL (decl
))
17613 add_AT_flag (com_die
, DW_AT_declaration
, 1);
17614 if (want_pubnames ())
17615 add_pubname_string (cnam
, com_die
); /* ??? needed? */
17616 com_die
->decl_id
= DECL_UID (com_decl
);
17617 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
17618 *slot
= (void *) com_die
;
17620 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
17622 add_AT_location_description (com_die
, DW_AT_location
, loc
);
17623 loc
= loc_list_from_tree (com_decl
, 2);
17624 remove_AT (com_die
, DW_AT_declaration
);
17626 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
17627 add_name_and_src_coords_attributes (var_die
, decl
);
17628 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
17629 TREE_THIS_VOLATILE (decl
), context_die
);
17630 add_AT_flag (var_die
, DW_AT_external
, 1);
17635 /* Optimize the common case. */
17636 if (single_element_loc_list_p (loc
)
17637 && loc
->expr
->dw_loc_opc
== DW_OP_addr
17638 && loc
->expr
->dw_loc_next
== NULL
17639 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
17641 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
17642 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
17643 = plus_constant (GET_MODE (x
), x
, off
);
17646 loc_list_plus_const (loc
, off
);
17648 add_AT_location_description (var_die
, DW_AT_location
, loc
);
17650 else if (DECL_EXTERNAL (decl
))
17651 add_AT_flag (var_die
, DW_AT_declaration
, 1);
17652 equate_decl_number_to_die (decl
, var_die
);
17656 /* If the compiler emitted a definition for the DECL declaration
17657 and if we already emitted a DIE for it, don't emit a second
17658 DIE for it again. Allow re-declarations of DECLs that are
17659 inside functions, though. */
17660 if (old_die
&& declaration
&& !local_scope_p (context_die
))
17663 /* For static data members, the declaration in the class is supposed
17664 to have DW_TAG_member tag; the specification should still be
17665 DW_TAG_variable referencing the DW_TAG_member DIE. */
17666 if (declaration
&& class_scope_p (context_die
))
17667 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
17669 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
17672 if (origin
!= NULL
)
17673 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
17675 /* Loop unrolling can create multiple blocks that refer to the same
17676 static variable, so we must test for the DW_AT_declaration flag.
17678 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
17679 copy decls and set the DECL_ABSTRACT flag on them instead of
17682 ??? Duplicated blocks have been rewritten to use .debug_ranges.
17684 ??? The declare_in_namespace support causes us to get two DIEs for one
17685 variable, both of which are declarations. We want to avoid considering
17686 one to be a specification, so we must test that this DIE is not a
17688 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
17689 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
17691 /* This is a definition of a C++ class level static. */
17692 add_AT_specification (var_die
, old_die
);
17693 specialization_p
= true;
17694 if (DECL_NAME (decl
))
17696 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17697 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17699 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17700 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
17702 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17703 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
17705 if (old_die
->die_tag
== DW_TAG_member
)
17706 add_linkage_name (var_die
, decl
);
17710 add_name_and_src_coords_attributes (var_die
, decl
);
17712 if ((origin
== NULL
&& !specialization_p
)
17714 && !DECL_ABSTRACT (decl_or_origin
)
17715 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
17716 decl_function_context
17717 (decl_or_origin
))))
17719 tree type
= TREE_TYPE (decl_or_origin
);
17721 if (decl_by_reference_p (decl_or_origin
))
17722 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
17724 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
17725 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
17728 if (origin
== NULL
&& !specialization_p
)
17730 if (TREE_PUBLIC (decl
))
17731 add_AT_flag (var_die
, DW_AT_external
, 1);
17733 if (DECL_ARTIFICIAL (decl
))
17734 add_AT_flag (var_die
, DW_AT_artificial
, 1);
17736 add_accessibility_attribute (var_die
, decl
);
17740 add_AT_flag (var_die
, DW_AT_declaration
, 1);
17742 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
17743 equate_decl_number_to_die (decl
, var_die
);
17746 && (! DECL_ABSTRACT (decl_or_origin
)
17747 /* Local static vars are shared between all clones/inlines,
17748 so emit DW_AT_location on the abstract DIE if DECL_RTL is
17750 || (TREE_CODE (decl_or_origin
) == VAR_DECL
17751 && TREE_STATIC (decl_or_origin
)
17752 && DECL_RTL_SET_P (decl_or_origin
)))
17753 /* When abstract origin already has DW_AT_location attribute, no need
17754 to add it again. */
17755 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
17757 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
17758 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
17759 defer_location (decl_or_origin
, var_die
);
17761 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
17762 decl
== NULL
, DW_AT_location
);
17763 add_pubname (decl_or_origin
, var_die
);
17766 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
17769 /* Generate a DIE to represent a named constant. */
17772 gen_const_die (tree decl
, dw_die_ref context_die
)
17774 dw_die_ref const_die
;
17775 tree type
= TREE_TYPE (decl
);
17777 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
17778 add_name_and_src_coords_attributes (const_die
, decl
);
17779 add_type_attribute (const_die
, type
, 1, 0, context_die
);
17780 if (TREE_PUBLIC (decl
))
17781 add_AT_flag (const_die
, DW_AT_external
, 1);
17782 if (DECL_ARTIFICIAL (decl
))
17783 add_AT_flag (const_die
, DW_AT_artificial
, 1);
17784 tree_add_const_value_attribute_for_decl (const_die
, decl
);
17787 /* Generate a DIE to represent a label identifier. */
17790 gen_label_die (tree decl
, dw_die_ref context_die
)
17792 tree origin
= decl_ultimate_origin (decl
);
17793 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
17795 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
17797 if (origin
!= NULL
)
17798 add_abstract_origin_attribute (lbl_die
, origin
);
17800 add_name_and_src_coords_attributes (lbl_die
, decl
);
17802 if (DECL_ABSTRACT (decl
))
17803 equate_decl_number_to_die (decl
, lbl_die
);
17806 insn
= DECL_RTL_IF_SET (decl
);
17808 /* Deleted labels are programmer specified labels which have been
17809 eliminated because of various optimizations. We still emit them
17810 here so that it is possible to put breakpoints on them. */
17814 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
17816 /* When optimization is enabled (via -O) some parts of the compiler
17817 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
17818 represent source-level labels which were explicitly declared by
17819 the user. This really shouldn't be happening though, so catch
17820 it if it ever does happen. */
17821 gcc_assert (!INSN_DELETED_P (insn
));
17823 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
17824 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
17828 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
17829 && CODE_LABEL_NUMBER (insn
) != -1)
17831 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
17832 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
17837 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
17838 attributes to the DIE for a block STMT, to describe where the inlined
17839 function was called from. This is similar to add_src_coords_attributes. */
17842 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
17844 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
17846 if (dwarf_version
>= 3 || !dwarf_strict
)
17848 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
17849 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
17854 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
17855 Add low_pc and high_pc attributes to the DIE for a block STMT. */
17858 add_high_low_attributes (tree stmt
, dw_die_ref die
)
17860 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
17862 if (BLOCK_FRAGMENT_CHAIN (stmt
)
17863 && (dwarf_version
>= 3 || !dwarf_strict
))
17865 tree chain
, superblock
= NULL_TREE
;
17867 dw_attr_ref attr
= NULL
;
17869 if (inlined_function_outer_scope_p (stmt
))
17871 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
17872 BLOCK_NUMBER (stmt
));
17873 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
17876 /* Optimize duplicate .debug_ranges lists or even tails of
17877 lists. If this BLOCK has same ranges as its supercontext,
17878 lookup DW_AT_ranges attribute in the supercontext (and
17879 recursively so), verify that the ranges_table contains the
17880 right values and use it instead of adding a new .debug_range. */
17881 for (chain
= stmt
, pdie
= die
;
17882 BLOCK_SAME_RANGE (chain
);
17883 chain
= BLOCK_SUPERCONTEXT (chain
))
17885 dw_attr_ref new_attr
;
17887 pdie
= pdie
->die_parent
;
17890 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
17892 new_attr
= get_AT (pdie
, DW_AT_ranges
);
17893 if (new_attr
== NULL
17894 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
17897 superblock
= BLOCK_SUPERCONTEXT (chain
);
17900 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
17901 / 2 / DWARF2_ADDR_SIZE
].num
17902 == BLOCK_NUMBER (superblock
))
17903 && BLOCK_FRAGMENT_CHAIN (superblock
))
17905 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
17906 / 2 / DWARF2_ADDR_SIZE
;
17907 unsigned long supercnt
= 0, thiscnt
= 0;
17908 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
17909 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
17912 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
17913 == BLOCK_NUMBER (chain
));
17915 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
17916 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
17917 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
17919 gcc_assert (supercnt
>= thiscnt
);
17920 add_AT_range_list (die
, DW_AT_ranges
,
17921 (off
+ supercnt
- thiscnt
)
17922 * 2 * DWARF2_ADDR_SIZE
);
17926 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
));
17928 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
17931 add_ranges (chain
);
17932 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
17939 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
17940 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
17941 BLOCK_NUMBER (stmt
));
17942 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
17943 BLOCK_NUMBER (stmt
));
17944 add_AT_low_high_pc (die
, label
, label_high
);
17948 /* Generate a DIE for a lexical block. */
17951 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
17953 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
17955 if (call_arg_locations
)
17957 if (VEC_length (dw_die_ref
, block_map
) <= BLOCK_NUMBER (stmt
))
17958 VEC_safe_grow_cleared (dw_die_ref
, heap
, block_map
,
17959 BLOCK_NUMBER (stmt
) + 1);
17960 VEC_replace (dw_die_ref
, block_map
, BLOCK_NUMBER (stmt
), stmt_die
);
17963 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
17964 add_high_low_attributes (stmt
, stmt_die
);
17966 decls_for_scope (stmt
, stmt_die
, depth
);
17969 /* Generate a DIE for an inlined subprogram. */
17972 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
17976 /* The instance of function that is effectively being inlined shall not
17978 gcc_assert (! BLOCK_ABSTRACT (stmt
));
17980 decl
= block_ultimate_origin (stmt
);
17982 /* Emit info for the abstract instance first, if we haven't yet. We
17983 must emit this even if the block is abstract, otherwise when we
17984 emit the block below (or elsewhere), we may end up trying to emit
17985 a die whose origin die hasn't been emitted, and crashing. */
17986 dwarf2out_abstract_function (decl
);
17988 if (! BLOCK_ABSTRACT (stmt
))
17990 dw_die_ref subr_die
17991 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
17993 if (call_arg_locations
)
17995 if (VEC_length (dw_die_ref
, block_map
) <= BLOCK_NUMBER (stmt
))
17996 VEC_safe_grow_cleared (dw_die_ref
, heap
, block_map
,
17997 BLOCK_NUMBER (stmt
) + 1);
17998 VEC_replace (dw_die_ref
, block_map
, BLOCK_NUMBER (stmt
), subr_die
);
18000 add_abstract_origin_attribute (subr_die
, decl
);
18001 if (TREE_ASM_WRITTEN (stmt
))
18002 add_high_low_attributes (stmt
, subr_die
);
18003 add_call_src_coords_attributes (stmt
, subr_die
);
18005 decls_for_scope (stmt
, subr_die
, depth
);
18006 current_function_has_inlines
= 1;
18010 /* Generate a DIE for a field in a record, or structure. */
18013 gen_field_die (tree decl
, dw_die_ref context_die
)
18015 dw_die_ref decl_die
;
18017 if (TREE_TYPE (decl
) == error_mark_node
)
18020 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
18021 add_name_and_src_coords_attributes (decl_die
, decl
);
18022 add_type_attribute (decl_die
, member_declared_type (decl
),
18023 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
18026 if (DECL_BIT_FIELD_TYPE (decl
))
18028 add_byte_size_attribute (decl_die
, decl
);
18029 add_bit_size_attribute (decl_die
, decl
);
18030 add_bit_offset_attribute (decl_die
, decl
);
18033 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
18034 add_data_member_location_attribute (decl_die
, decl
);
18036 if (DECL_ARTIFICIAL (decl
))
18037 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
18039 add_accessibility_attribute (decl_die
, decl
);
18041 /* Equate decl number to die, so that we can look up this decl later on. */
18042 equate_decl_number_to_die (decl
, decl_die
);
18046 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18047 Use modified_type_die instead.
18048 We keep this code here just in case these types of DIEs may be needed to
18049 represent certain things in other languages (e.g. Pascal) someday. */
18052 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
18055 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
18057 equate_type_number_to_die (type
, ptr_die
);
18058 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18059 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18062 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18063 Use modified_type_die instead.
18064 We keep this code here just in case these types of DIEs may be needed to
18065 represent certain things in other languages (e.g. Pascal) someday. */
18068 gen_reference_type_die (tree type
, dw_die_ref context_die
)
18070 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
18072 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
18073 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
18075 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
18077 equate_type_number_to_die (type
, ref_die
);
18078 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
18079 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18083 /* Generate a DIE for a pointer to a member type. */
18086 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
18089 = new_die (DW_TAG_ptr_to_member_type
,
18090 scope_die_for (type
, context_die
), type
);
18092 equate_type_number_to_die (type
, ptr_die
);
18093 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
18094 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
18095 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18098 typedef const char *dchar_p
; /* For DEF_VEC_P. */
18099 DEF_VEC_P(dchar_p
);
18100 DEF_VEC_ALLOC_P(dchar_p
,heap
);
18102 static char *producer_string
;
18104 /* Return a heap allocated producer string including command line options
18105 if -grecord-gcc-switches. */
18108 gen_producer_string (void)
18111 VEC(dchar_p
, heap
) *switches
= NULL
;
18112 const char *language_string
= lang_hooks
.name
;
18113 char *producer
, *tail
;
18115 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
18116 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
18118 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
18119 switch (save_decoded_options
[j
].opt_index
)
18126 case OPT_auxbase_strip
:
18135 case OPT_SPECIAL_unknown
:
18136 case OPT_SPECIAL_ignore
:
18137 case OPT_SPECIAL_program_name
:
18138 case OPT_SPECIAL_input_file
:
18139 case OPT_grecord_gcc_switches
:
18140 case OPT_gno_record_gcc_switches
:
18141 case OPT__output_pch_
:
18142 case OPT_fdiagnostics_show_location_
:
18143 case OPT_fdiagnostics_show_option
:
18144 case OPT_fdiagnostics_show_caret
:
18145 case OPT_fverbose_asm
:
18147 case OPT__sysroot_
:
18149 case OPT_nostdinc__
:
18150 /* Ignore these. */
18153 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
18154 & CL_NO_DWARF_RECORD
)
18156 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
18158 switch (save_decoded_options
[j
].canonical_option
[0][1])
18165 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
18172 VEC_safe_push (dchar_p
, heap
, switches
,
18173 save_decoded_options
[j
].orig_option_with_args_text
);
18174 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
18178 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
18180 sprintf (tail
, "%s %s", language_string
, version_string
);
18183 FOR_EACH_VEC_ELT (dchar_p
, switches
, j
, p
)
18187 memcpy (tail
+ 1, p
, len
);
18192 VEC_free (dchar_p
, heap
, switches
);
18196 /* Generate the DIE for the compilation unit. */
18199 gen_compile_unit_die (const char *filename
)
18202 const char *language_string
= lang_hooks
.name
;
18205 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
18209 add_name_attribute (die
, filename
);
18210 /* Don't add cwd for <built-in>. */
18211 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
18212 add_comp_dir_attribute (die
);
18215 if (producer_string
== NULL
)
18216 producer_string
= gen_producer_string ();
18217 add_AT_string (die
, DW_AT_producer
, producer_string
);
18219 /* If our producer is LTO try to figure out a common language to use
18220 from the global list of translation units. */
18221 if (strcmp (language_string
, "GNU GIMPLE") == 0)
18225 const char *common_lang
= NULL
;
18227 FOR_EACH_VEC_ELT (tree
, all_translation_units
, i
, t
)
18229 if (!TRANSLATION_UNIT_LANGUAGE (t
))
18232 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
18233 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
18235 else if (strncmp (common_lang
, "GNU C", 5) == 0
18236 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
18237 /* Mixing C and C++ is ok, use C++ in that case. */
18238 common_lang
= "GNU C++";
18241 /* Fall back to C. */
18242 common_lang
= NULL
;
18248 language_string
= common_lang
;
18251 language
= DW_LANG_C89
;
18252 if (strcmp (language_string
, "GNU C++") == 0)
18253 language
= DW_LANG_C_plus_plus
;
18254 else if (strcmp (language_string
, "GNU F77") == 0)
18255 language
= DW_LANG_Fortran77
;
18256 else if (strcmp (language_string
, "GNU Pascal") == 0)
18257 language
= DW_LANG_Pascal83
;
18258 else if (dwarf_version
>= 3 || !dwarf_strict
)
18260 if (strcmp (language_string
, "GNU Ada") == 0)
18261 language
= DW_LANG_Ada95
;
18262 else if (strcmp (language_string
, "GNU Fortran") == 0)
18263 language
= DW_LANG_Fortran95
;
18264 else if (strcmp (language_string
, "GNU Java") == 0)
18265 language
= DW_LANG_Java
;
18266 else if (strcmp (language_string
, "GNU Objective-C") == 0)
18267 language
= DW_LANG_ObjC
;
18268 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
18269 language
= DW_LANG_ObjC_plus_plus
;
18270 else if (dwarf_version
>= 5 || !dwarf_strict
)
18272 if (strcmp (language_string
, "GNU Go") == 0)
18273 language
= DW_LANG_Go
;
18276 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
18277 else if (strcmp (language_string
, "GNU Fortran") == 0)
18278 language
= DW_LANG_Fortran90
;
18280 add_AT_unsigned (die
, DW_AT_language
, language
);
18284 case DW_LANG_Fortran77
:
18285 case DW_LANG_Fortran90
:
18286 case DW_LANG_Fortran95
:
18287 /* Fortran has case insensitive identifiers and the front-end
18288 lowercases everything. */
18289 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
18292 /* The default DW_ID_case_sensitive doesn't need to be specified. */
18298 /* Generate the DIE for a base class. */
18301 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
18303 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
18305 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
18306 add_data_member_location_attribute (die
, binfo
);
18308 if (BINFO_VIRTUAL_P (binfo
))
18309 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
18311 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18312 children, otherwise the default is DW_ACCESS_public. In DWARF2
18313 the default has always been DW_ACCESS_private. */
18314 if (access
== access_public_node
)
18316 if (dwarf_version
== 2
18317 || context_die
->die_tag
== DW_TAG_class_type
)
18318 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
18320 else if (access
== access_protected_node
)
18321 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
18322 else if (dwarf_version
> 2
18323 && context_die
->die_tag
!= DW_TAG_class_type
)
18324 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
18327 /* Generate a DIE for a class member. */
18330 gen_member_die (tree type
, dw_die_ref context_die
)
18333 tree binfo
= TYPE_BINFO (type
);
18336 /* If this is not an incomplete type, output descriptions of each of its
18337 members. Note that as we output the DIEs necessary to represent the
18338 members of this record or union type, we will also be trying to output
18339 DIEs to represent the *types* of those members. However the `type'
18340 function (above) will specifically avoid generating type DIEs for member
18341 types *within* the list of member DIEs for this (containing) type except
18342 for those types (of members) which are explicitly marked as also being
18343 members of this (containing) type themselves. The g++ front- end can
18344 force any given type to be treated as a member of some other (containing)
18345 type by setting the TYPE_CONTEXT of the given (member) type to point to
18346 the TREE node representing the appropriate (containing) type. */
18348 /* First output info about the base classes. */
18351 VEC(tree
,gc
) *accesses
= BINFO_BASE_ACCESSES (binfo
);
18355 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
18356 gen_inheritance_die (base
,
18357 (accesses
? VEC_index (tree
, accesses
, i
)
18358 : access_public_node
), context_die
);
18361 /* Now output info about the data members and type members. */
18362 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
18364 /* If we thought we were generating minimal debug info for TYPE
18365 and then changed our minds, some of the member declarations
18366 may have already been defined. Don't define them again, but
18367 do put them in the right order. */
18369 child
= lookup_decl_die (member
);
18371 splice_child_die (context_die
, child
);
18373 gen_decl_die (member
, NULL
, context_die
);
18376 /* Now output info about the function members (if any). */
18377 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
18379 /* Don't include clones in the member list. */
18380 if (DECL_ABSTRACT_ORIGIN (member
))
18383 child
= lookup_decl_die (member
);
18385 splice_child_die (context_die
, child
);
18387 gen_decl_die (member
, NULL
, context_die
);
18391 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
18392 is set, we pretend that the type was never defined, so we only get the
18393 member DIEs needed by later specification DIEs. */
18396 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
18397 enum debug_info_usage usage
)
18399 dw_die_ref type_die
= lookup_type_die (type
);
18400 dw_die_ref scope_die
= 0;
18402 int complete
= (TYPE_SIZE (type
)
18403 && (! TYPE_STUB_DECL (type
)
18404 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
18405 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
18406 complete
= complete
&& should_emit_struct_debug (type
, usage
);
18408 if (type_die
&& ! complete
)
18411 if (TYPE_CONTEXT (type
) != NULL_TREE
18412 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
18413 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
18416 scope_die
= scope_die_for (type
, context_die
);
18418 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
18419 /* First occurrence of type or toplevel definition of nested class. */
18421 dw_die_ref old_die
= type_die
;
18423 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
18424 ? record_type_tag (type
) : DW_TAG_union_type
,
18426 equate_type_number_to_die (type
, type_die
);
18428 add_AT_specification (type_die
, old_die
);
18430 add_name_attribute (type_die
, type_tag (type
));
18433 remove_AT (type_die
, DW_AT_declaration
);
18435 /* Generate child dies for template paramaters. */
18436 if (debug_info_level
> DINFO_LEVEL_TERSE
18437 && COMPLETE_TYPE_P (type
))
18438 schedule_generic_params_dies_gen (type
);
18440 /* If this type has been completed, then give it a byte_size attribute and
18441 then give a list of members. */
18442 if (complete
&& !ns_decl
)
18444 /* Prevent infinite recursion in cases where the type of some member of
18445 this type is expressed in terms of this type itself. */
18446 TREE_ASM_WRITTEN (type
) = 1;
18447 add_byte_size_attribute (type_die
, type
);
18448 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
18450 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
18451 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
18454 /* If the first reference to this type was as the return type of an
18455 inline function, then it may not have a parent. Fix this now. */
18456 if (type_die
->die_parent
== NULL
)
18457 add_child_die (scope_die
, type_die
);
18459 push_decl_scope (type
);
18460 gen_member_die (type
, type_die
);
18463 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
18464 if (TYPE_ARTIFICIAL (type
))
18465 add_AT_flag (type_die
, DW_AT_artificial
, 1);
18467 /* GNU extension: Record what type our vtable lives in. */
18468 if (TYPE_VFIELD (type
))
18470 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
18472 gen_type_die (vtype
, context_die
);
18473 add_AT_die_ref (type_die
, DW_AT_containing_type
,
18474 lookup_type_die (vtype
));
18479 add_AT_flag (type_die
, DW_AT_declaration
, 1);
18481 /* We don't need to do this for function-local types. */
18482 if (TYPE_STUB_DECL (type
)
18483 && ! decl_function_context (TYPE_STUB_DECL (type
)))
18484 VEC_safe_push (tree
, gc
, incomplete_types
, type
);
18487 if (get_AT (type_die
, DW_AT_name
))
18488 add_pubtype (type
, type_die
);
18491 /* Generate a DIE for a subroutine _type_. */
18494 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
18496 tree return_type
= TREE_TYPE (type
);
18497 dw_die_ref subr_die
18498 = new_die (DW_TAG_subroutine_type
,
18499 scope_die_for (type
, context_die
), type
);
18501 equate_type_number_to_die (type
, subr_die
);
18502 add_prototyped_attribute (subr_die
, type
);
18503 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
18504 gen_formal_types_die (type
, subr_die
);
18506 if (get_AT (subr_die
, DW_AT_name
))
18507 add_pubtype (type
, subr_die
);
18510 /* Generate a DIE for a type definition. */
18513 gen_typedef_die (tree decl
, dw_die_ref context_die
)
18515 dw_die_ref type_die
;
18518 if (TREE_ASM_WRITTEN (decl
))
18521 TREE_ASM_WRITTEN (decl
) = 1;
18522 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
18523 origin
= decl_ultimate_origin (decl
);
18524 if (origin
!= NULL
)
18525 add_abstract_origin_attribute (type_die
, origin
);
18530 add_name_and_src_coords_attributes (type_die
, decl
);
18531 if (DECL_ORIGINAL_TYPE (decl
))
18533 type
= DECL_ORIGINAL_TYPE (decl
);
18535 gcc_assert (type
!= TREE_TYPE (decl
));
18536 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
18540 type
= TREE_TYPE (decl
);
18542 if (is_naming_typedef_decl (TYPE_NAME (type
)))
18544 /* Here, we are in the case of decl being a typedef naming
18545 an anonymous type, e.g:
18546 typedef struct {...} foo;
18547 In that case TREE_TYPE (decl) is not a typedef variant
18548 type and TYPE_NAME of the anonymous type is set to the
18549 TYPE_DECL of the typedef. This construct is emitted by
18552 TYPE is the anonymous struct named by the typedef
18553 DECL. As we need the DW_AT_type attribute of the
18554 DW_TAG_typedef to point to the DIE of TYPE, let's
18555 generate that DIE right away. add_type_attribute
18556 called below will then pick (via lookup_type_die) that
18557 anonymous struct DIE. */
18558 if (!TREE_ASM_WRITTEN (type
))
18559 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
18561 /* This is a GNU Extension. We are adding a
18562 DW_AT_linkage_name attribute to the DIE of the
18563 anonymous struct TYPE. The value of that attribute
18564 is the name of the typedef decl naming the anonymous
18565 struct. This greatly eases the work of consumers of
18566 this debug info. */
18567 add_linkage_attr (lookup_type_die (type
), decl
);
18571 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
18572 TREE_THIS_VOLATILE (decl
), context_die
);
18574 if (is_naming_typedef_decl (decl
))
18575 /* We want that all subsequent calls to lookup_type_die with
18576 TYPE in argument yield the DW_TAG_typedef we have just
18578 equate_type_number_to_die (type
, type_die
);
18580 add_accessibility_attribute (type_die
, decl
);
18583 if (DECL_ABSTRACT (decl
))
18584 equate_decl_number_to_die (decl
, type_die
);
18586 if (get_AT (type_die
, DW_AT_name
))
18587 add_pubtype (decl
, type_die
);
18590 /* Generate a DIE for a struct, class, enum or union type. */
18593 gen_tagged_type_die (tree type
,
18594 dw_die_ref context_die
,
18595 enum debug_info_usage usage
)
18599 if (type
== NULL_TREE
18600 || !is_tagged_type (type
))
18603 /* If this is a nested type whose containing class hasn't been written
18604 out yet, writing it out will cover this one, too. This does not apply
18605 to instantiations of member class templates; they need to be added to
18606 the containing class as they are generated. FIXME: This hurts the
18607 idea of combining type decls from multiple TUs, since we can't predict
18608 what set of template instantiations we'll get. */
18609 if (TYPE_CONTEXT (type
)
18610 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
18611 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
18613 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
18615 if (TREE_ASM_WRITTEN (type
))
18618 /* If that failed, attach ourselves to the stub. */
18619 push_decl_scope (TYPE_CONTEXT (type
));
18620 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
18623 else if (TYPE_CONTEXT (type
) != NULL_TREE
18624 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
18626 /* If this type is local to a function that hasn't been written
18627 out yet, use a NULL context for now; it will be fixed up in
18628 decls_for_scope. */
18629 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
18630 /* A declaration DIE doesn't count; nested types need to go in the
18632 if (context_die
&& is_declaration_die (context_die
))
18633 context_die
= NULL
;
18638 context_die
= declare_in_namespace (type
, context_die
);
18642 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
18644 /* This might have been written out by the call to
18645 declare_in_namespace. */
18646 if (!TREE_ASM_WRITTEN (type
))
18647 gen_enumeration_type_die (type
, context_die
);
18650 gen_struct_or_union_type_die (type
, context_die
, usage
);
18655 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
18656 it up if it is ever completed. gen_*_type_die will set it for us
18657 when appropriate. */
18660 /* Generate a type description DIE. */
18663 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
18664 enum debug_info_usage usage
)
18666 struct array_descr_info info
;
18668 if (type
== NULL_TREE
|| type
== error_mark_node
)
18671 if (TYPE_NAME (type
) != NULL_TREE
18672 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
18673 && is_redundant_typedef (TYPE_NAME (type
))
18674 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
18675 /* The DECL of this type is a typedef we don't want to emit debug
18676 info for but we want debug info for its underlying typedef.
18677 This can happen for e.g, the injected-class-name of a C++
18679 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
18681 /* If TYPE is a typedef type variant, let's generate debug info
18682 for the parent typedef which TYPE is a type of. */
18683 if (typedef_variant_p (type
))
18685 if (TREE_ASM_WRITTEN (type
))
18688 /* Prevent broken recursion; we can't hand off to the same type. */
18689 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
18691 /* Give typedefs the right scope. */
18692 context_die
= scope_die_for (type
, context_die
);
18694 TREE_ASM_WRITTEN (type
) = 1;
18696 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
18700 /* If type is an anonymous tagged type named by a typedef, let's
18701 generate debug info for the typedef. */
18702 if (is_naming_typedef_decl (TYPE_NAME (type
)))
18704 /* Use the DIE of the containing namespace as the parent DIE of
18705 the type description DIE we want to generate. */
18706 if (DECL_CONTEXT (TYPE_NAME (type
))
18707 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
18708 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
18710 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
18714 /* If this is an array type with hidden descriptor, handle it first. */
18715 if (!TREE_ASM_WRITTEN (type
)
18716 && lang_hooks
.types
.get_array_descr_info
18717 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
18718 && (dwarf_version
>= 3 || !dwarf_strict
))
18720 gen_descr_array_type_die (type
, &info
, context_die
);
18721 TREE_ASM_WRITTEN (type
) = 1;
18725 /* We are going to output a DIE to represent the unqualified version
18726 of this type (i.e. without any const or volatile qualifiers) so
18727 get the main variant (i.e. the unqualified version) of this type
18728 now. (Vectors are special because the debugging info is in the
18729 cloned type itself). */
18730 if (TREE_CODE (type
) != VECTOR_TYPE
)
18731 type
= type_main_variant (type
);
18733 if (TREE_ASM_WRITTEN (type
))
18736 switch (TREE_CODE (type
))
18742 case REFERENCE_TYPE
:
18743 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
18744 ensures that the gen_type_die recursion will terminate even if the
18745 type is recursive. Recursive types are possible in Ada. */
18746 /* ??? We could perhaps do this for all types before the switch
18748 TREE_ASM_WRITTEN (type
) = 1;
18750 /* For these types, all that is required is that we output a DIE (or a
18751 set of DIEs) to represent the "basis" type. */
18752 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18753 DINFO_USAGE_IND_USE
);
18757 /* This code is used for C++ pointer-to-data-member types.
18758 Output a description of the relevant class type. */
18759 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
18760 DINFO_USAGE_IND_USE
);
18762 /* Output a description of the type of the object pointed to. */
18763 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18764 DINFO_USAGE_IND_USE
);
18766 /* Now output a DIE to represent this pointer-to-data-member type
18768 gen_ptr_to_mbr_type_die (type
, context_die
);
18771 case FUNCTION_TYPE
:
18772 /* Force out return type (in case it wasn't forced out already). */
18773 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18774 DINFO_USAGE_DIR_USE
);
18775 gen_subroutine_type_die (type
, context_die
);
18779 /* Force out return type (in case it wasn't forced out already). */
18780 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18781 DINFO_USAGE_DIR_USE
);
18782 gen_subroutine_type_die (type
, context_die
);
18786 gen_array_type_die (type
, context_die
);
18790 gen_array_type_die (type
, context_die
);
18793 case ENUMERAL_TYPE
:
18796 case QUAL_UNION_TYPE
:
18797 gen_tagged_type_die (type
, context_die
, usage
);
18803 case FIXED_POINT_TYPE
:
18806 /* No DIEs needed for fundamental types. */
18811 /* Just use DW_TAG_unspecified_type. */
18813 dw_die_ref type_die
= lookup_type_die (type
);
18814 if (type_die
== NULL
)
18816 tree name
= TYPE_NAME (type
);
18817 if (TREE_CODE (name
) == TYPE_DECL
)
18818 name
= DECL_NAME (name
);
18819 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
18820 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
18821 equate_type_number_to_die (type
, type_die
);
18827 gcc_unreachable ();
18830 TREE_ASM_WRITTEN (type
) = 1;
18834 gen_type_die (tree type
, dw_die_ref context_die
)
18836 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
18839 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
18840 things which are local to the given block. */
18843 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
18845 int must_output_die
= 0;
18848 /* Ignore blocks that are NULL. */
18849 if (stmt
== NULL_TREE
)
18852 inlined_func
= inlined_function_outer_scope_p (stmt
);
18854 /* If the block is one fragment of a non-contiguous block, do not
18855 process the variables, since they will have been done by the
18856 origin block. Do process subblocks. */
18857 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
18861 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
18862 gen_block_die (sub
, context_die
, depth
+ 1);
18867 /* Determine if we need to output any Dwarf DIEs at all to represent this
18870 /* The outer scopes for inlinings *must* always be represented. We
18871 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
18872 must_output_die
= 1;
18875 /* Determine if this block directly contains any "significant"
18876 local declarations which we will need to output DIEs for. */
18877 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18878 /* We are not in terse mode so *any* local declaration counts
18879 as being a "significant" one. */
18880 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
18881 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
18882 && (TREE_USED (stmt
)
18883 || TREE_ASM_WRITTEN (stmt
)
18884 || BLOCK_ABSTRACT (stmt
)));
18885 else if ((TREE_USED (stmt
)
18886 || TREE_ASM_WRITTEN (stmt
)
18887 || BLOCK_ABSTRACT (stmt
))
18888 && !dwarf2out_ignore_block (stmt
))
18889 must_output_die
= 1;
18892 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
18893 DIE for any block which contains no significant local declarations at
18894 all. Rather, in such cases we just call `decls_for_scope' so that any
18895 needed Dwarf info for any sub-blocks will get properly generated. Note
18896 that in terse mode, our definition of what constitutes a "significant"
18897 local declaration gets restricted to include only inlined function
18898 instances and local (nested) function definitions. */
18899 if (must_output_die
)
18903 /* If STMT block is abstract, that means we have been called
18904 indirectly from dwarf2out_abstract_function.
18905 That function rightfully marks the descendent blocks (of
18906 the abstract function it is dealing with) as being abstract,
18907 precisely to prevent us from emitting any
18908 DW_TAG_inlined_subroutine DIE as a descendent
18909 of an abstract function instance. So in that case, we should
18910 not call gen_inlined_subroutine_die.
18912 Later though, when cgraph asks dwarf2out to emit info
18913 for the concrete instance of the function decl into which
18914 the concrete instance of STMT got inlined, the later will lead
18915 to the generation of a DW_TAG_inlined_subroutine DIE. */
18916 if (! BLOCK_ABSTRACT (stmt
))
18917 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
18920 gen_lexical_block_die (stmt
, context_die
, depth
);
18923 decls_for_scope (stmt
, context_die
, depth
);
18926 /* Process variable DECL (or variable with origin ORIGIN) within
18927 block STMT and add it to CONTEXT_DIE. */
18929 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
18932 tree decl_or_origin
= decl
? decl
: origin
;
18934 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
18935 die
= lookup_decl_die (decl_or_origin
);
18936 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
18937 && TYPE_DECL_IS_STUB (decl_or_origin
))
18938 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
18942 if (die
!= NULL
&& die
->die_parent
== NULL
)
18943 add_child_die (context_die
, die
);
18944 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
18945 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
18946 stmt
, context_die
);
18948 gen_decl_die (decl
, origin
, context_die
);
18951 /* Generate all of the decls declared within a given scope and (recursively)
18952 all of its sub-blocks. */
18955 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
18961 /* Ignore NULL blocks. */
18962 if (stmt
== NULL_TREE
)
18965 /* Output the DIEs to represent all of the data objects and typedefs
18966 declared directly within this block but not within any nested
18967 sub-blocks. Also, nested function and tag DIEs have been
18968 generated with a parent of NULL; fix that up now. */
18969 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
18970 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
18971 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
18972 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
18975 /* If we're at -g1, we're not interested in subblocks. */
18976 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
18979 /* Output the DIEs to represent all sub-blocks (and the items declared
18980 therein) of this block. */
18981 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
18983 subblocks
= BLOCK_CHAIN (subblocks
))
18984 gen_block_die (subblocks
, context_die
, depth
+ 1);
18987 /* Is this a typedef we can avoid emitting? */
18990 is_redundant_typedef (const_tree decl
)
18992 if (TYPE_DECL_IS_STUB (decl
))
18995 if (DECL_ARTIFICIAL (decl
)
18996 && DECL_CONTEXT (decl
)
18997 && is_tagged_type (DECL_CONTEXT (decl
))
18998 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
18999 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
19000 /* Also ignore the artificial member typedef for the class name. */
19006 /* Return TRUE if TYPE is a typedef that names a type for linkage
19007 purposes. This kind of typedefs is produced by the C++ FE for
19010 typedef struct {...} foo;
19012 In that case, there is no typedef variant type produced for foo.
19013 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
19017 is_naming_typedef_decl (const_tree decl
)
19019 if (decl
== NULL_TREE
19020 || TREE_CODE (decl
) != TYPE_DECL
19021 || !is_tagged_type (TREE_TYPE (decl
))
19022 || DECL_IS_BUILTIN (decl
)
19023 || is_redundant_typedef (decl
)
19024 /* It looks like Ada produces TYPE_DECLs that are very similar
19025 to C++ naming typedefs but that have different
19026 semantics. Let's be specific to c++ for now. */
19030 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
19031 && TYPE_NAME (TREE_TYPE (decl
)) == decl
19032 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
19033 != TYPE_NAME (TREE_TYPE (decl
))));
19036 /* Returns the DIE for a context. */
19038 static inline dw_die_ref
19039 get_context_die (tree context
)
19043 /* Find die that represents this context. */
19044 if (TYPE_P (context
))
19046 context
= TYPE_MAIN_VARIANT (context
);
19047 return strip_naming_typedef (context
, force_type_die (context
));
19050 return force_decl_die (context
);
19052 return comp_unit_die ();
19055 /* Returns the DIE for decl. A DIE will always be returned. */
19058 force_decl_die (tree decl
)
19060 dw_die_ref decl_die
;
19061 unsigned saved_external_flag
;
19062 tree save_fn
= NULL_TREE
;
19063 decl_die
= lookup_decl_die (decl
);
19066 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
19068 decl_die
= lookup_decl_die (decl
);
19072 switch (TREE_CODE (decl
))
19074 case FUNCTION_DECL
:
19075 /* Clear current_function_decl, so that gen_subprogram_die thinks
19076 that this is a declaration. At this point, we just want to force
19077 declaration die. */
19078 save_fn
= current_function_decl
;
19079 current_function_decl
= NULL_TREE
;
19080 gen_subprogram_die (decl
, context_die
);
19081 current_function_decl
= save_fn
;
19085 /* Set external flag to force declaration die. Restore it after
19086 gen_decl_die() call. */
19087 saved_external_flag
= DECL_EXTERNAL (decl
);
19088 DECL_EXTERNAL (decl
) = 1;
19089 gen_decl_die (decl
, NULL
, context_die
);
19090 DECL_EXTERNAL (decl
) = saved_external_flag
;
19093 case NAMESPACE_DECL
:
19094 if (dwarf_version
>= 3 || !dwarf_strict
)
19095 dwarf2out_decl (decl
);
19097 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19098 decl_die
= comp_unit_die ();
19101 case TRANSLATION_UNIT_DECL
:
19102 decl_die
= comp_unit_die ();
19106 gcc_unreachable ();
19109 /* We should be able to find the DIE now. */
19111 decl_die
= lookup_decl_die (decl
);
19112 gcc_assert (decl_die
);
19118 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
19119 always returned. */
19122 force_type_die (tree type
)
19124 dw_die_ref type_die
;
19126 type_die
= lookup_type_die (type
);
19129 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
19131 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
19132 TYPE_VOLATILE (type
), context_die
);
19133 gcc_assert (type_die
);
19138 /* Force out any required namespaces to be able to output DECL,
19139 and return the new context_die for it, if it's changed. */
19142 setup_namespace_context (tree thing
, dw_die_ref context_die
)
19144 tree context
= (DECL_P (thing
)
19145 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
19146 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
19147 /* Force out the namespace. */
19148 context_die
= force_decl_die (context
);
19150 return context_die
;
19153 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
19154 type) within its namespace, if appropriate.
19156 For compatibility with older debuggers, namespace DIEs only contain
19157 declarations; all definitions are emitted at CU scope. */
19160 declare_in_namespace (tree thing
, dw_die_ref context_die
)
19162 dw_die_ref ns_context
;
19164 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19165 return context_die
;
19167 /* If this decl is from an inlined function, then don't try to emit it in its
19168 namespace, as we will get confused. It would have already been emitted
19169 when the abstract instance of the inline function was emitted anyways. */
19170 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
19171 return context_die
;
19173 ns_context
= setup_namespace_context (thing
, context_die
);
19175 if (ns_context
!= context_die
)
19179 if (DECL_P (thing
))
19180 gen_decl_die (thing
, NULL
, ns_context
);
19182 gen_type_die (thing
, ns_context
);
19184 return context_die
;
19187 /* Generate a DIE for a namespace or namespace alias. */
19190 gen_namespace_die (tree decl
, dw_die_ref context_die
)
19192 dw_die_ref namespace_die
;
19194 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
19195 they are an alias of. */
19196 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
19198 /* Output a real namespace or module. */
19199 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19200 namespace_die
= new_die (is_fortran ()
19201 ? DW_TAG_module
: DW_TAG_namespace
,
19202 context_die
, decl
);
19203 /* For Fortran modules defined in different CU don't add src coords. */
19204 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
19206 const char *name
= dwarf2_name (decl
, 0);
19208 add_name_attribute (namespace_die
, name
);
19211 add_name_and_src_coords_attributes (namespace_die
, decl
);
19212 if (DECL_EXTERNAL (decl
))
19213 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
19214 equate_decl_number_to_die (decl
, namespace_die
);
19218 /* Output a namespace alias. */
19220 /* Force out the namespace we are an alias of, if necessary. */
19221 dw_die_ref origin_die
19222 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
19224 if (DECL_FILE_SCOPE_P (decl
)
19225 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
19226 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19227 /* Now create the namespace alias DIE. */
19228 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
19229 add_name_and_src_coords_attributes (namespace_die
, decl
);
19230 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
19231 equate_decl_number_to_die (decl
, namespace_die
);
19233 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
19234 if (want_pubnames ())
19235 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
19238 /* Generate Dwarf debug information for a decl described by DECL.
19239 The return value is currently only meaningful for PARM_DECLs,
19240 for all other decls it returns NULL. */
19243 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
19245 tree decl_or_origin
= decl
? decl
: origin
;
19246 tree class_origin
= NULL
, ultimate_origin
;
19248 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
19251 switch (TREE_CODE (decl_or_origin
))
19257 if (!is_fortran () && !is_ada ())
19259 /* The individual enumerators of an enum type get output when we output
19260 the Dwarf representation of the relevant enum type itself. */
19264 /* Emit its type. */
19265 gen_type_die (TREE_TYPE (decl
), context_die
);
19267 /* And its containing namespace. */
19268 context_die
= declare_in_namespace (decl
, context_die
);
19270 gen_const_die (decl
, context_die
);
19273 case FUNCTION_DECL
:
19274 /* Don't output any DIEs to represent mere function declarations,
19275 unless they are class members or explicit block externs. */
19276 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
19277 && DECL_FILE_SCOPE_P (decl_or_origin
)
19278 && (current_function_decl
== NULL_TREE
19279 || DECL_ARTIFICIAL (decl_or_origin
)))
19284 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
19285 on local redeclarations of global functions. That seems broken. */
19286 if (current_function_decl
!= decl
)
19287 /* This is only a declaration. */;
19290 /* If we're emitting a clone, emit info for the abstract instance. */
19291 if (origin
|| DECL_ORIGIN (decl
) != decl
)
19292 dwarf2out_abstract_function (origin
19293 ? DECL_ORIGIN (origin
)
19294 : DECL_ABSTRACT_ORIGIN (decl
));
19296 /* If we're emitting an out-of-line copy of an inline function,
19297 emit info for the abstract instance and set up to refer to it. */
19298 else if (cgraph_function_possibly_inlined_p (decl
)
19299 && ! DECL_ABSTRACT (decl
)
19300 && ! class_or_namespace_scope_p (context_die
)
19301 /* dwarf2out_abstract_function won't emit a die if this is just
19302 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
19303 that case, because that works only if we have a die. */
19304 && DECL_INITIAL (decl
) != NULL_TREE
)
19306 dwarf2out_abstract_function (decl
);
19307 set_decl_origin_self (decl
);
19310 /* Otherwise we're emitting the primary DIE for this decl. */
19311 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
19313 /* Before we describe the FUNCTION_DECL itself, make sure that we
19314 have its containing type. */
19316 origin
= decl_class_context (decl
);
19317 if (origin
!= NULL_TREE
)
19318 gen_type_die (origin
, context_die
);
19320 /* And its return type. */
19321 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
19323 /* And its virtual context. */
19324 if (DECL_VINDEX (decl
) != NULL_TREE
)
19325 gen_type_die (DECL_CONTEXT (decl
), context_die
);
19327 /* Make sure we have a member DIE for decl. */
19328 if (origin
!= NULL_TREE
)
19329 gen_type_die_for_member (origin
, decl
, context_die
);
19331 /* And its containing namespace. */
19332 context_die
= declare_in_namespace (decl
, context_die
);
19335 /* Now output a DIE to represent the function itself. */
19337 gen_subprogram_die (decl
, context_die
);
19341 /* If we are in terse mode, don't generate any DIEs to represent any
19342 actual typedefs. */
19343 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19346 /* In the special case of a TYPE_DECL node representing the declaration
19347 of some type tag, if the given TYPE_DECL is marked as having been
19348 instantiated from some other (original) TYPE_DECL node (e.g. one which
19349 was generated within the original definition of an inline function) we
19350 used to generate a special (abbreviated) DW_TAG_structure_type,
19351 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
19352 should be actually referencing those DIEs, as variable DIEs with that
19353 type would be emitted already in the abstract origin, so it was always
19354 removed during unused type prunning. Don't add anything in this
19356 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
19359 if (is_redundant_typedef (decl
))
19360 gen_type_die (TREE_TYPE (decl
), context_die
);
19362 /* Output a DIE to represent the typedef itself. */
19363 gen_typedef_die (decl
, context_die
);
19367 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
19368 gen_label_die (decl
, context_die
);
19373 /* If we are in terse mode, don't generate any DIEs to represent any
19374 variable declarations or definitions. */
19375 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19378 /* Output any DIEs that are needed to specify the type of this data
19380 if (decl_by_reference_p (decl_or_origin
))
19381 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
19383 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
19385 /* And its containing type. */
19386 class_origin
= decl_class_context (decl_or_origin
);
19387 if (class_origin
!= NULL_TREE
)
19388 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
19390 /* And its containing namespace. */
19391 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
19393 /* Now output the DIE to represent the data object itself. This gets
19394 complicated because of the possibility that the VAR_DECL really
19395 represents an inlined instance of a formal parameter for an inline
19397 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
19398 if (ultimate_origin
!= NULL_TREE
19399 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
19400 gen_formal_parameter_die (decl
, origin
,
19401 true /* Emit name attribute. */,
19404 gen_variable_die (decl
, origin
, context_die
);
19408 /* Ignore the nameless fields that are used to skip bits but handle C++
19409 anonymous unions and structs. */
19410 if (DECL_NAME (decl
) != NULL_TREE
19411 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
19412 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
19414 gen_type_die (member_declared_type (decl
), context_die
);
19415 gen_field_die (decl
, context_die
);
19420 if (DECL_BY_REFERENCE (decl_or_origin
))
19421 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
19423 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
19424 return gen_formal_parameter_die (decl
, origin
,
19425 true /* Emit name attribute. */,
19428 case NAMESPACE_DECL
:
19429 case IMPORTED_DECL
:
19430 if (dwarf_version
>= 3 || !dwarf_strict
)
19431 gen_namespace_die (decl
, context_die
);
19435 /* Probably some frontend-internal decl. Assume we don't care. */
19436 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
19443 /* Output debug information for global decl DECL. Called from toplev.c after
19444 compilation proper has finished. */
19447 dwarf2out_global_decl (tree decl
)
19449 /* Output DWARF2 information for file-scope tentative data object
19450 declarations, file-scope (extern) function declarations (which
19451 had no corresponding body) and file-scope tagged type declarations
19452 and definitions which have not yet been forced out. */
19453 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
19454 dwarf2out_decl (decl
);
19457 /* Output debug information for type decl DECL. Called from toplev.c
19458 and from language front ends (to record built-in types). */
19460 dwarf2out_type_decl (tree decl
, int local
)
19463 dwarf2out_decl (decl
);
19466 /* Output debug information for imported module or decl DECL.
19467 NAME is non-NULL name in the lexical block if the decl has been renamed.
19468 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
19469 that DECL belongs to.
19470 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
19472 dwarf2out_imported_module_or_decl_1 (tree decl
,
19474 tree lexical_block
,
19475 dw_die_ref lexical_block_die
)
19477 expanded_location xloc
;
19478 dw_die_ref imported_die
= NULL
;
19479 dw_die_ref at_import_die
;
19481 if (TREE_CODE (decl
) == IMPORTED_DECL
)
19483 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
19484 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
19488 xloc
= expand_location (input_location
);
19490 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
19492 at_import_die
= force_type_die (TREE_TYPE (decl
));
19493 /* For namespace N { typedef void T; } using N::T; base_type_die
19494 returns NULL, but DW_TAG_imported_declaration requires
19495 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
19496 if (!at_import_die
)
19498 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
19499 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
19500 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
19501 gcc_assert (at_import_die
);
19506 at_import_die
= lookup_decl_die (decl
);
19507 if (!at_import_die
)
19509 /* If we're trying to avoid duplicate debug info, we may not have
19510 emitted the member decl for this field. Emit it now. */
19511 if (TREE_CODE (decl
) == FIELD_DECL
)
19513 tree type
= DECL_CONTEXT (decl
);
19515 if (TYPE_CONTEXT (type
)
19516 && TYPE_P (TYPE_CONTEXT (type
))
19517 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
19518 DINFO_USAGE_DIR_USE
))
19520 gen_type_die_for_member (type
, decl
,
19521 get_context_die (TYPE_CONTEXT (type
)));
19523 at_import_die
= force_decl_die (decl
);
19527 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
19529 if (dwarf_version
>= 3 || !dwarf_strict
)
19530 imported_die
= new_die (DW_TAG_imported_module
,
19537 imported_die
= new_die (DW_TAG_imported_declaration
,
19541 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
19542 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
19544 add_AT_string (imported_die
, DW_AT_name
,
19545 IDENTIFIER_POINTER (name
));
19546 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
19549 /* Output debug information for imported module or decl DECL.
19550 NAME is non-NULL name in context if the decl has been renamed.
19551 CHILD is true if decl is one of the renamed decls as part of
19552 importing whole module. */
19555 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
19558 /* dw_die_ref at_import_die; */
19559 dw_die_ref scope_die
;
19561 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19566 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
19567 We need decl DIE for reference and scope die. First, get DIE for the decl
19570 /* Get the scope die for decl context. Use comp_unit_die for global module
19571 or decl. If die is not found for non globals, force new die. */
19573 && TYPE_P (context
)
19574 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
19577 if (!(dwarf_version
>= 3 || !dwarf_strict
))
19580 scope_die
= get_context_die (context
);
19584 gcc_assert (scope_die
->die_child
);
19585 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
19586 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
19587 scope_die
= scope_die
->die_child
;
19590 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
19591 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
19595 /* Write the debugging output for DECL. */
19598 dwarf2out_decl (tree decl
)
19600 dw_die_ref context_die
= comp_unit_die ();
19602 switch (TREE_CODE (decl
))
19607 case FUNCTION_DECL
:
19608 /* What we would really like to do here is to filter out all mere
19609 file-scope declarations of file-scope functions which are never
19610 referenced later within this translation unit (and keep all of ones
19611 that *are* referenced later on) but we aren't clairvoyant, so we have
19612 no idea which functions will be referenced in the future (i.e. later
19613 on within the current translation unit). So here we just ignore all
19614 file-scope function declarations which are not also definitions. If
19615 and when the debugger needs to know something about these functions,
19616 it will have to hunt around and find the DWARF information associated
19617 with the definition of the function.
19619 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
19620 nodes represent definitions and which ones represent mere
19621 declarations. We have to check DECL_INITIAL instead. That's because
19622 the C front-end supports some weird semantics for "extern inline"
19623 function definitions. These can get inlined within the current
19624 translation unit (and thus, we need to generate Dwarf info for their
19625 abstract instances so that the Dwarf info for the concrete inlined
19626 instances can have something to refer to) but the compiler never
19627 generates any out-of-lines instances of such things (despite the fact
19628 that they *are* definitions).
19630 The important point is that the C front-end marks these "extern
19631 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
19632 them anyway. Note that the C++ front-end also plays some similar games
19633 for inline function definitions appearing within include files which
19634 also contain `#pragma interface' pragmas.
19636 If we are called from dwarf2out_abstract_function output a DIE
19637 anyway. We can end up here this way with early inlining and LTO
19638 where the inlined function is output in a different LTRANS unit
19640 if (DECL_INITIAL (decl
) == NULL_TREE
19641 && ! DECL_ABSTRACT (decl
))
19644 /* If we're a nested function, initially use a parent of NULL; if we're
19645 a plain function, this will be fixed up in decls_for_scope. If
19646 we're a method, it will be ignored, since we already have a DIE. */
19647 if (decl_function_context (decl
)
19648 /* But if we're in terse mode, we don't care about scope. */
19649 && debug_info_level
> DINFO_LEVEL_TERSE
)
19650 context_die
= NULL
;
19654 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
19655 declaration and if the declaration was never even referenced from
19656 within this entire compilation unit. We suppress these DIEs in
19657 order to save space in the .debug section (by eliminating entries
19658 which are probably useless). Note that we must not suppress
19659 block-local extern declarations (whether used or not) because that
19660 would screw-up the debugger's name lookup mechanism and cause it to
19661 miss things which really ought to be in scope at a given point. */
19662 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
19665 /* For local statics lookup proper context die. */
19666 if (TREE_STATIC (decl
)
19667 && DECL_CONTEXT (decl
)
19668 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
19669 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
19671 /* If we are in terse mode, don't generate any DIEs to represent any
19672 variable declarations or definitions. */
19673 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19678 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19680 if (!is_fortran () && !is_ada ())
19682 if (TREE_STATIC (decl
) && decl_function_context (decl
))
19683 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
19686 case NAMESPACE_DECL
:
19687 case IMPORTED_DECL
:
19688 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19690 if (lookup_decl_die (decl
) != NULL
)
19695 /* Don't emit stubs for types unless they are needed by other DIEs. */
19696 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
19699 /* Don't bother trying to generate any DIEs to represent any of the
19700 normal built-in types for the language we are compiling. */
19701 if (DECL_IS_BUILTIN (decl
))
19704 /* If we are in terse mode, don't generate any DIEs for types. */
19705 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19708 /* If we're a function-scope tag, initially use a parent of NULL;
19709 this will be fixed up in decls_for_scope. */
19710 if (decl_function_context (decl
))
19711 context_die
= NULL
;
19719 gen_decl_die (decl
, NULL
, context_die
);
19722 /* Write the debugging output for DECL. */
19725 dwarf2out_function_decl (tree decl
)
19727 dwarf2out_decl (decl
);
19728 call_arg_locations
= NULL
;
19729 call_arg_loc_last
= NULL
;
19730 call_site_count
= -1;
19731 tail_call_site_count
= -1;
19732 VEC_free (dw_die_ref
, heap
, block_map
);
19733 htab_empty (decl_loc_table
);
19734 htab_empty (cached_dw_loc_list_table
);
19737 /* Output a marker (i.e. a label) for the beginning of the generated code for
19738 a lexical block. */
19741 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
19742 unsigned int blocknum
)
19744 switch_to_section (current_function_section ());
19745 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
19748 /* Output a marker (i.e. a label) for the end of the generated code for a
19752 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
19754 switch_to_section (current_function_section ());
19755 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
19758 /* Returns nonzero if it is appropriate not to emit any debugging
19759 information for BLOCK, because it doesn't contain any instructions.
19761 Don't allow this for blocks with nested functions or local classes
19762 as we would end up with orphans, and in the presence of scheduling
19763 we may end up calling them anyway. */
19766 dwarf2out_ignore_block (const_tree block
)
19771 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
19772 if (TREE_CODE (decl
) == FUNCTION_DECL
19773 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
19775 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
19777 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
19778 if (TREE_CODE (decl
) == FUNCTION_DECL
19779 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
19786 /* Hash table routines for file_hash. */
19789 file_table_eq (const void *p1_p
, const void *p2_p
)
19791 const struct dwarf_file_data
*const p1
=
19792 (const struct dwarf_file_data
*) p1_p
;
19793 const char *const p2
= (const char *) p2_p
;
19794 return filename_cmp (p1
->filename
, p2
) == 0;
19798 file_table_hash (const void *p_p
)
19800 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
19801 return htab_hash_string (p
->filename
);
19804 /* Lookup FILE_NAME (in the list of filenames that we know about here in
19805 dwarf2out.c) and return its "index". The index of each (known) filename is
19806 just a unique number which is associated with only that one filename. We
19807 need such numbers for the sake of generating labels (in the .debug_sfnames
19808 section) and references to those files numbers (in the .debug_srcinfo
19809 and.debug_macinfo sections). If the filename given as an argument is not
19810 found in our current list, add it to the list and assign it the next
19811 available unique index number. In order to speed up searches, we remember
19812 the index of the filename was looked up last. This handles the majority of
19815 static struct dwarf_file_data
*
19816 lookup_filename (const char *file_name
)
19819 struct dwarf_file_data
* created
;
19821 /* Check to see if the file name that was searched on the previous
19822 call matches this file name. If so, return the index. */
19823 if (file_table_last_lookup
19824 && (file_name
== file_table_last_lookup
->filename
19825 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
19826 return file_table_last_lookup
;
19828 /* Didn't match the previous lookup, search the table. */
19829 slot
= htab_find_slot_with_hash (file_table
, file_name
,
19830 htab_hash_string (file_name
), INSERT
);
19832 return (struct dwarf_file_data
*) *slot
;
19834 created
= ggc_alloc_dwarf_file_data ();
19835 created
->filename
= file_name
;
19836 created
->emitted_number
= 0;
19841 /* If the assembler will construct the file table, then translate the compiler
19842 internal file table number into the assembler file table number, and emit
19843 a .file directive if we haven't already emitted one yet. The file table
19844 numbers are different because we prune debug info for unused variables and
19845 types, which may include filenames. */
19848 maybe_emit_file (struct dwarf_file_data
* fd
)
19850 if (! fd
->emitted_number
)
19852 if (last_emitted_file
)
19853 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
19855 fd
->emitted_number
= 1;
19856 last_emitted_file
= fd
;
19858 if (DWARF2_ASM_LINE_DEBUG_INFO
)
19860 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
19861 output_quoted_string (asm_out_file
,
19862 remap_debug_filename (fd
->filename
));
19863 fputc ('\n', asm_out_file
);
19867 return fd
->emitted_number
;
19870 /* Schedule generation of a DW_AT_const_value attribute to DIE.
19871 That generation should happen after function debug info has been
19872 generated. The value of the attribute is the constant value of ARG. */
19875 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
19877 die_arg_entry entry
;
19882 if (!tmpl_value_parm_die_table
)
19883 tmpl_value_parm_die_table
19884 = VEC_alloc (die_arg_entry
, gc
, 32);
19888 VEC_safe_push (die_arg_entry
, gc
,
19889 tmpl_value_parm_die_table
,
19893 /* Return TRUE if T is an instance of generic type, FALSE
19897 generic_type_p (tree t
)
19899 if (t
== NULL_TREE
|| !TYPE_P (t
))
19901 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
19904 /* Schedule the generation of the generic parameter dies for the
19905 instance of generic type T. The proper generation itself is later
19906 done by gen_scheduled_generic_parms_dies. */
19909 schedule_generic_params_dies_gen (tree t
)
19911 if (!generic_type_p (t
))
19914 if (generic_type_instances
== NULL
)
19915 generic_type_instances
= VEC_alloc (tree
, gc
, 256);
19917 VEC_safe_push (tree
, gc
, generic_type_instances
, t
);
19920 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
19921 by append_entry_to_tmpl_value_parm_die_table. This function must
19922 be called after function DIEs have been generated. */
19925 gen_remaining_tmpl_value_param_die_attribute (void)
19927 if (tmpl_value_parm_die_table
)
19932 FOR_EACH_VEC_ELT (die_arg_entry
, tmpl_value_parm_die_table
, i
, e
)
19933 tree_add_const_value_attribute (e
->die
, e
->arg
);
19937 /* Generate generic parameters DIEs for instances of generic types
19938 that have been previously scheduled by
19939 schedule_generic_params_dies_gen. This function must be called
19940 after all the types of the CU have been laid out. */
19943 gen_scheduled_generic_parms_dies (void)
19948 if (generic_type_instances
== NULL
)
19951 FOR_EACH_VEC_ELT (tree
, generic_type_instances
, i
, t
)
19952 gen_generic_params_dies (t
);
19956 /* Replace DW_AT_name for the decl with name. */
19959 dwarf2out_set_name (tree decl
, tree name
)
19965 die
= TYPE_SYMTAB_DIE (decl
);
19969 dname
= dwarf2_name (name
, 0);
19973 attr
= get_AT (die
, DW_AT_name
);
19976 struct indirect_string_node
*node
;
19978 node
= find_AT_string (dname
);
19979 /* replace the string. */
19980 attr
->dw_attr_val
.v
.val_str
= node
;
19984 add_name_attribute (die
, dname
);
19987 /* Called by the final INSN scan whenever we see a var location. We
19988 use it to drop labels in the right places, and throw the location in
19989 our lookup table. */
19992 dwarf2out_var_location (rtx loc_note
)
19994 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
19995 struct var_loc_node
*newloc
;
19996 rtx next_real
, next_note
;
19997 static const char *last_label
;
19998 static const char *last_postcall_label
;
19999 static bool last_in_cold_section_p
;
20000 static rtx expected_next_loc_note
;
20004 if (!NOTE_P (loc_note
))
20006 if (CALL_P (loc_note
))
20009 if (SIBLING_CALL_P (loc_note
))
20010 tail_call_site_count
++;
20015 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
20016 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
20019 /* Optimize processing a large consecutive sequence of location
20020 notes so we don't spend too much time in next_real_insn. If the
20021 next insn is another location note, remember the next_real_insn
20022 calculation for next time. */
20023 next_real
= cached_next_real_insn
;
20026 if (expected_next_loc_note
!= loc_note
)
20027 next_real
= NULL_RTX
;
20030 next_note
= NEXT_INSN (loc_note
);
20032 || INSN_DELETED_P (next_note
)
20033 || GET_CODE (next_note
) != NOTE
20034 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
20035 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
20036 next_note
= NULL_RTX
;
20039 next_real
= next_real_insn (loc_note
);
20043 expected_next_loc_note
= next_note
;
20044 cached_next_real_insn
= next_real
;
20047 cached_next_real_insn
= NULL_RTX
;
20049 /* If there are no instructions which would be affected by this note,
20050 don't do anything. */
20052 && next_real
== NULL_RTX
20053 && !NOTE_DURING_CALL_P (loc_note
))
20056 if (next_real
== NULL_RTX
)
20057 next_real
= get_last_insn ();
20059 /* If there were any real insns between note we processed last time
20060 and this note (or if it is the first note), clear
20061 last_{,postcall_}label so that they are not reused this time. */
20062 if (last_var_location_insn
== NULL_RTX
20063 || last_var_location_insn
!= next_real
20064 || last_in_cold_section_p
!= in_cold_section_p
)
20067 last_postcall_label
= NULL
;
20072 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
20073 newloc
= add_var_loc_to_decl (decl
, loc_note
,
20074 NOTE_DURING_CALL_P (loc_note
)
20075 ? last_postcall_label
: last_label
);
20076 if (newloc
== NULL
)
20085 /* If there were no real insns between note we processed last time
20086 and this note, use the label we emitted last time. Otherwise
20087 create a new label and emit it. */
20088 if (last_label
== NULL
)
20090 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
20091 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
20093 last_label
= ggc_strdup (loclabel
);
20098 struct call_arg_loc_node
*ca_loc
20099 = ggc_alloc_cleared_call_arg_loc_node ();
20100 rtx prev
= prev_real_insn (loc_note
), x
;
20101 ca_loc
->call_arg_loc_note
= loc_note
;
20102 ca_loc
->next
= NULL
;
20103 ca_loc
->label
= last_label
;
20106 || (NONJUMP_INSN_P (prev
)
20107 && GET_CODE (PATTERN (prev
)) == SEQUENCE
20108 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
20109 if (!CALL_P (prev
))
20110 prev
= XVECEXP (PATTERN (prev
), 0, 0);
20111 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
20112 x
= get_call_rtx_from (PATTERN (prev
));
20115 x
= XEXP (XEXP (x
, 0), 0);
20116 if (GET_CODE (x
) == SYMBOL_REF
20117 && SYMBOL_REF_DECL (x
)
20118 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
20119 ca_loc
->symbol_ref
= x
;
20121 ca_loc
->block
= insn_scope (prev
);
20122 if (call_arg_locations
)
20123 call_arg_loc_last
->next
= ca_loc
;
20125 call_arg_locations
= ca_loc
;
20126 call_arg_loc_last
= ca_loc
;
20128 else if (!NOTE_DURING_CALL_P (loc_note
))
20129 newloc
->label
= last_label
;
20132 if (!last_postcall_label
)
20134 sprintf (loclabel
, "%s-1", last_label
);
20135 last_postcall_label
= ggc_strdup (loclabel
);
20137 newloc
->label
= last_postcall_label
;
20140 last_var_location_insn
= next_real
;
20141 last_in_cold_section_p
= in_cold_section_p
;
20144 /* Note in one location list that text section has changed. */
20147 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
20149 var_loc_list
*list
= (var_loc_list
*) *slot
;
20151 list
->last_before_switch
20152 = list
->last
->next
? list
->last
->next
: list
->last
;
20156 /* Note in all location lists that text section has changed. */
20159 var_location_switch_text_section (void)
20161 if (decl_loc_table
== NULL
)
20164 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
20167 /* Create a new line number table. */
20169 static dw_line_info_table
*
20170 new_line_info_table (void)
20172 dw_line_info_table
*table
;
20174 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
20175 table
->file_num
= 1;
20176 table
->line_num
= 1;
20177 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
20182 /* Lookup the "current" table into which we emit line info, so
20183 that we don't have to do it for every source line. */
20186 set_cur_line_info_table (section
*sec
)
20188 dw_line_info_table
*table
;
20190 if (sec
== text_section
)
20191 table
= text_section_line_info
;
20192 else if (sec
== cold_text_section
)
20194 table
= cold_text_section_line_info
;
20197 cold_text_section_line_info
= table
= new_line_info_table ();
20198 table
->end_label
= cold_end_label
;
20203 const char *end_label
;
20205 if (flag_reorder_blocks_and_partition
)
20207 if (in_cold_section_p
)
20208 end_label
= crtl
->subsections
.cold_section_end_label
;
20210 end_label
= crtl
->subsections
.hot_section_end_label
;
20214 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20215 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
20216 current_function_funcdef_no
);
20217 end_label
= ggc_strdup (label
);
20220 table
= new_line_info_table ();
20221 table
->end_label
= end_label
;
20223 VEC_safe_push (dw_line_info_table_p
, gc
, separate_line_info
, table
);
20226 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20227 table
->is_stmt
= (cur_line_info_table
20228 ? cur_line_info_table
->is_stmt
20229 : DWARF_LINE_DEFAULT_IS_STMT_START
);
20230 cur_line_info_table
= table
;
20234 /* We need to reset the locations at the beginning of each
20235 function. We can't do this in the end_function hook, because the
20236 declarations that use the locations won't have been output when
20237 that hook is called. Also compute have_multiple_function_sections here. */
20240 dwarf2out_begin_function (tree fun
)
20242 section
*sec
= function_section (fun
);
20244 if (sec
!= text_section
)
20245 have_multiple_function_sections
= true;
20247 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
20249 gcc_assert (current_function_decl
== fun
);
20250 cold_text_section
= unlikely_text_section ();
20251 switch_to_section (cold_text_section
);
20252 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
20253 switch_to_section (sec
);
20256 dwarf2out_note_section_used ();
20257 call_site_count
= 0;
20258 tail_call_site_count
= 0;
20260 set_cur_line_info_table (sec
);
20263 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
20266 push_dw_line_info_entry (dw_line_info_table
*table
,
20267 enum dw_line_info_opcode opcode
, unsigned int val
)
20269 dw_line_info_entry e
;
20272 VEC_safe_push (dw_line_info_entry
, gc
, table
->entries
, e
);
20275 /* Output a label to mark the beginning of a source code line entry
20276 and record information relating to this source line, in
20277 'line_info_table' for later output of the .debug_line section. */
20278 /* ??? The discriminator parameter ought to be unsigned. */
20281 dwarf2out_source_line (unsigned int line
, const char *filename
,
20282 int discriminator
, bool is_stmt
)
20284 unsigned int file_num
;
20285 dw_line_info_table
*table
;
20287 if (debug_info_level
< DINFO_LEVEL_NORMAL
|| line
== 0)
20290 /* The discriminator column was added in dwarf4. Simplify the below
20291 by simply removing it if we're not supposed to output it. */
20292 if (dwarf_version
< 4 && dwarf_strict
)
20295 table
= cur_line_info_table
;
20296 file_num
= maybe_emit_file (lookup_filename (filename
));
20298 /* ??? TODO: Elide duplicate line number entries. Traditionally,
20299 the debugger has used the second (possibly duplicate) line number
20300 at the beginning of the function to mark the end of the prologue.
20301 We could eliminate any other duplicates within the function. For
20302 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
20303 that second line number entry. */
20304 /* Recall that this end-of-prologue indication is *not* the same thing
20305 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
20306 to which the hook corresponds, follows the last insn that was
20307 emitted by gen_prologue. What we need is to precede the first insn
20308 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
20309 insn that corresponds to something the user wrote. These may be
20310 very different locations once scheduling is enabled. */
20312 if (0 && file_num
== table
->file_num
20313 && line
== table
->line_num
20314 && discriminator
== table
->discrim_num
20315 && is_stmt
== table
->is_stmt
)
20318 switch_to_section (current_function_section ());
20320 /* If requested, emit something human-readable. */
20321 if (flag_debug_asm
)
20322 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
20324 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20326 /* Emit the .loc directive understood by GNU as. */
20327 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
20328 file_num, line, is_stmt, discriminator */
20329 fputs ("\t.loc ", asm_out_file
);
20330 fprint_ul (asm_out_file
, file_num
);
20331 putc (' ', asm_out_file
);
20332 fprint_ul (asm_out_file
, line
);
20333 putc (' ', asm_out_file
);
20334 putc ('0', asm_out_file
);
20336 if (is_stmt
!= table
->is_stmt
)
20338 fputs (" is_stmt ", asm_out_file
);
20339 putc (is_stmt
? '1' : '0', asm_out_file
);
20341 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
20343 gcc_assert (discriminator
> 0);
20344 fputs (" discriminator ", asm_out_file
);
20345 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
20347 putc ('\n', asm_out_file
);
20351 unsigned int label_num
= ++line_info_label_num
;
20353 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
20355 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
20356 if (file_num
!= table
->file_num
)
20357 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
20358 if (discriminator
!= table
->discrim_num
)
20359 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
20360 if (is_stmt
!= table
->is_stmt
)
20361 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
20362 push_dw_line_info_entry (table
, LI_set_line
, line
);
20365 table
->file_num
= file_num
;
20366 table
->line_num
= line
;
20367 table
->discrim_num
= discriminator
;
20368 table
->is_stmt
= is_stmt
;
20369 table
->in_use
= true;
20372 /* Record the beginning of a new source file. */
20375 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
20377 if (flag_eliminate_dwarf2_dups
)
20379 /* Record the beginning of the file for break_out_includes. */
20380 dw_die_ref bincl_die
;
20382 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
20383 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
20386 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20389 e
.code
= DW_MACINFO_start_file
;
20391 e
.info
= ggc_strdup (filename
);
20392 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, e
);
20396 /* Record the end of a source file. */
20399 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
20401 if (flag_eliminate_dwarf2_dups
)
20402 /* Record the end of the file for break_out_includes. */
20403 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
20405 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20408 e
.code
= DW_MACINFO_end_file
;
20411 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, e
);
20415 /* Called from debug_define in toplev.c. The `buffer' parameter contains
20416 the tail part of the directive line, i.e. the part which is past the
20417 initial whitespace, #, whitespace, directive-name, whitespace part. */
20420 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
20421 const char *buffer ATTRIBUTE_UNUSED
)
20423 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20426 /* Insert a dummy first entry to be able to optimize the whole
20427 predefined macro block using DW_MACRO_GNU_transparent_include. */
20428 if (VEC_empty (macinfo_entry
, macinfo_table
) && lineno
<= 1)
20433 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, e
);
20435 e
.code
= DW_MACINFO_define
;
20437 e
.info
= ggc_strdup (buffer
);
20438 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, e
);
20442 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
20443 the tail part of the directive line, i.e. the part which is past the
20444 initial whitespace, #, whitespace, directive-name, whitespace part. */
20447 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
20448 const char *buffer ATTRIBUTE_UNUSED
)
20450 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20453 /* Insert a dummy first entry to be able to optimize the whole
20454 predefined macro block using DW_MACRO_GNU_transparent_include. */
20455 if (VEC_empty (macinfo_entry
, macinfo_table
) && lineno
<= 1)
20460 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, e
);
20462 e
.code
= DW_MACINFO_undef
;
20464 e
.info
= ggc_strdup (buffer
);
20465 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, e
);
20469 /* Routines to manipulate hash table of CUs. */
20472 htab_macinfo_hash (const void *of
)
20474 const macinfo_entry
*const entry
=
20475 (const macinfo_entry
*) of
;
20477 return htab_hash_string (entry
->info
);
20481 htab_macinfo_eq (const void *of1
, const void *of2
)
20483 const macinfo_entry
*const entry1
= (const macinfo_entry
*) of1
;
20484 const macinfo_entry
*const entry2
= (const macinfo_entry
*) of2
;
20486 return !strcmp (entry1
->info
, entry2
->info
);
20489 /* Output a single .debug_macinfo entry. */
20492 output_macinfo_op (macinfo_entry
*ref
)
20496 struct indirect_string_node
*node
;
20497 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20498 struct dwarf_file_data
*fd
;
20502 case DW_MACINFO_start_file
:
20503 fd
= lookup_filename (ref
->info
);
20504 file_num
= maybe_emit_file (fd
);
20505 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
20506 dw2_asm_output_data_uleb128 (ref
->lineno
,
20507 "Included from line number %lu",
20508 (unsigned long) ref
->lineno
);
20509 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
20511 case DW_MACINFO_end_file
:
20512 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
20514 case DW_MACINFO_define
:
20515 case DW_MACINFO_undef
:
20516 len
= strlen (ref
->info
) + 1;
20518 && len
> DWARF_OFFSET_SIZE
20519 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
20520 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
20522 ref
->code
= ref
->code
== DW_MACINFO_define
20523 ? DW_MACRO_GNU_define_indirect
20524 : DW_MACRO_GNU_undef_indirect
;
20525 output_macinfo_op (ref
);
20528 dw2_asm_output_data (1, ref
->code
,
20529 ref
->code
== DW_MACINFO_define
20530 ? "Define macro" : "Undefine macro");
20531 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
20532 (unsigned long) ref
->lineno
);
20533 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
20535 case DW_MACRO_GNU_define_indirect
:
20536 case DW_MACRO_GNU_undef_indirect
:
20537 node
= find_AT_string (ref
->info
);
20538 if (node
->form
!= DW_FORM_strp
)
20541 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
20542 ++dw2_string_counter
;
20543 node
->label
= xstrdup (label
);
20544 node
->form
= DW_FORM_strp
;
20546 dw2_asm_output_data (1, ref
->code
,
20547 ref
->code
== DW_MACRO_GNU_define_indirect
20548 ? "Define macro indirect"
20549 : "Undefine macro indirect");
20550 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
20551 (unsigned long) ref
->lineno
);
20552 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
20553 debug_str_section
, "The macro: \"%s\"",
20556 case DW_MACRO_GNU_transparent_include
:
20557 dw2_asm_output_data (1, ref
->code
, "Transparent include");
20558 ASM_GENERATE_INTERNAL_LABEL (label
,
20559 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
20560 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
20563 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
20564 ASM_COMMENT_START
, (unsigned long) ref
->code
);
20569 /* Attempt to make a sequence of define/undef macinfo ops shareable with
20570 other compilation unit .debug_macinfo sections. IDX is the first
20571 index of a define/undef, return the number of ops that should be
20572 emitted in a comdat .debug_macinfo section and emit
20573 a DW_MACRO_GNU_transparent_include entry referencing it.
20574 If the define/undef entry should be emitted normally, return 0. */
20577 optimize_macinfo_range (unsigned int idx
, VEC (macinfo_entry
, gc
) *files
,
20578 htab_t
*macinfo_htab
)
20580 macinfo_entry
*first
, *second
, *cur
, *inc
;
20581 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
20582 unsigned char checksum
[16];
20583 struct md5_ctx ctx
;
20584 char *grp_name
, *tail
;
20586 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
20589 first
= &VEC_index (macinfo_entry
, macinfo_table
, idx
);
20590 second
= &VEC_index (macinfo_entry
, macinfo_table
, idx
+ 1);
20592 /* Optimize only if there are at least two consecutive define/undef ops,
20593 and either all of them are before first DW_MACINFO_start_file
20594 with lineno {0,1} (i.e. predefined macro block), or all of them are
20595 in some included header file. */
20596 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
20598 if (VEC_empty (macinfo_entry
, files
))
20600 if (first
->lineno
> 1 || second
->lineno
> 1)
20603 else if (first
->lineno
== 0)
20606 /* Find the last define/undef entry that can be grouped together
20607 with first and at the same time compute md5 checksum of their
20608 codes, linenumbers and strings. */
20609 md5_init_ctx (&ctx
);
20610 for (i
= idx
; VEC_iterate (macinfo_entry
, macinfo_table
, i
, cur
); i
++)
20611 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
20613 else if (VEC_empty (macinfo_entry
, files
) && cur
->lineno
> 1)
20617 unsigned char code
= cur
->code
;
20618 md5_process_bytes (&code
, 1, &ctx
);
20619 checksum_uleb128 (cur
->lineno
, &ctx
);
20620 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
20622 md5_finish_ctx (&ctx
, checksum
);
20625 /* From the containing include filename (if any) pick up just
20626 usable characters from its basename. */
20627 if (VEC_empty (macinfo_entry
, files
))
20630 base
= lbasename (VEC_last (macinfo_entry
, files
).info
);
20631 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
20632 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
20633 encoded_filename_len
++;
20634 /* Count . at the end. */
20635 if (encoded_filename_len
)
20636 encoded_filename_len
++;
20638 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
20639 linebuf_len
= strlen (linebuf
);
20641 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
20642 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
20644 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
20645 tail
= grp_name
+ 4;
20646 if (encoded_filename_len
)
20648 for (i
= 0; base
[i
]; i
++)
20649 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
20653 memcpy (tail
, linebuf
, linebuf_len
);
20654 tail
+= linebuf_len
;
20656 for (i
= 0; i
< 16; i
++)
20657 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
20659 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
20660 in the empty vector entry before the first define/undef. */
20661 inc
= &VEC_index (macinfo_entry
, macinfo_table
, idx
- 1);
20662 inc
->code
= DW_MACRO_GNU_transparent_include
;
20664 inc
->info
= ggc_strdup (grp_name
);
20665 if (*macinfo_htab
== NULL
)
20666 *macinfo_htab
= htab_create (10, htab_macinfo_hash
, htab_macinfo_eq
, NULL
);
20667 /* Avoid emitting duplicates. */
20668 slot
= htab_find_slot (*macinfo_htab
, inc
, INSERT
);
20673 /* If such an entry has been used before, just emit
20674 a DW_MACRO_GNU_transparent_include op. */
20675 inc
= (macinfo_entry
*) *slot
;
20676 output_macinfo_op (inc
);
20677 /* And clear all macinfo_entry in the range to avoid emitting them
20678 in the second pass. */
20680 VEC_iterate (macinfo_entry
, macinfo_table
, i
, cur
)
20681 && i
< idx
+ count
;
20691 inc
->lineno
= htab_elements (*macinfo_htab
);
20692 output_macinfo_op (inc
);
20697 /* Output macinfo section(s). */
20700 output_macinfo (void)
20703 unsigned long length
= VEC_length (macinfo_entry
, macinfo_table
);
20704 macinfo_entry
*ref
;
20705 VEC (macinfo_entry
, gc
) *files
= NULL
;
20706 htab_t macinfo_htab
= NULL
;
20711 /* output_macinfo* uses these interchangeably. */
20712 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
20713 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
20714 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
20715 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
20717 /* For .debug_macro emit the section header. */
20720 dw2_asm_output_data (2, 4, "DWARF macro version number");
20721 if (DWARF_OFFSET_SIZE
== 8)
20722 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
20724 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
20725 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_line_section_label
,
20726 debug_line_section
, NULL
);
20729 /* In the first loop, it emits the primary .debug_macinfo section
20730 and after each emitted op the macinfo_entry is cleared.
20731 If a longer range of define/undef ops can be optimized using
20732 DW_MACRO_GNU_transparent_include, the
20733 DW_MACRO_GNU_transparent_include op is emitted and kept in
20734 the vector before the first define/undef in the range and the
20735 whole range of define/undef ops is not emitted and kept. */
20736 for (i
= 0; VEC_iterate (macinfo_entry
, macinfo_table
, i
, ref
); i
++)
20740 case DW_MACINFO_start_file
:
20741 VEC_safe_push (macinfo_entry
, gc
, files
, *ref
);
20743 case DW_MACINFO_end_file
:
20744 if (!VEC_empty (macinfo_entry
, files
))
20745 VEC_pop (macinfo_entry
, files
);
20747 case DW_MACINFO_define
:
20748 case DW_MACINFO_undef
:
20750 && HAVE_COMDAT_GROUP
20751 && VEC_length (macinfo_entry
, files
) != 1
20754 && VEC_index (macinfo_entry
, macinfo_table
, i
- 1).code
== 0)
20756 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
20765 /* A dummy entry may be inserted at the beginning to be able
20766 to optimize the whole block of predefined macros. */
20772 output_macinfo_op (ref
);
20777 if (macinfo_htab
== NULL
)
20780 htab_delete (macinfo_htab
);
20782 /* If any DW_MACRO_GNU_transparent_include were used, on those
20783 DW_MACRO_GNU_transparent_include entries terminate the
20784 current chain and switch to a new comdat .debug_macinfo
20785 section and emit the define/undef entries within it. */
20786 for (i
= 0; VEC_iterate (macinfo_entry
, macinfo_table
, i
, ref
); i
++)
20791 case DW_MACRO_GNU_transparent_include
:
20793 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20794 tree comdat_key
= get_identifier (ref
->info
);
20795 /* Terminate the previous .debug_macinfo section. */
20796 dw2_asm_output_data (1, 0, "End compilation unit");
20797 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
20799 | SECTION_LINKONCE
,
20801 ASM_GENERATE_INTERNAL_LABEL (label
,
20802 DEBUG_MACRO_SECTION_LABEL
,
20804 ASM_OUTPUT_LABEL (asm_out_file
, label
);
20807 dw2_asm_output_data (2, 4, "DWARF macro version number");
20808 if (DWARF_OFFSET_SIZE
== 8)
20809 dw2_asm_output_data (1, 1, "Flags: 64-bit");
20811 dw2_asm_output_data (1, 0, "Flags: 32-bit");
20814 case DW_MACINFO_define
:
20815 case DW_MACINFO_undef
:
20816 output_macinfo_op (ref
);
20821 gcc_unreachable ();
20825 /* Set up for Dwarf output at the start of compilation. */
20828 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
20830 /* Allocate the file_table. */
20831 file_table
= htab_create_ggc (50, file_table_hash
,
20832 file_table_eq
, NULL
);
20834 /* Allocate the decl_die_table. */
20835 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
20836 decl_die_table_eq
, NULL
);
20838 /* Allocate the decl_loc_table. */
20839 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
20840 decl_loc_table_eq
, NULL
);
20842 /* Allocate the cached_dw_loc_list_table. */
20843 cached_dw_loc_list_table
20844 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
20845 cached_dw_loc_list_table_eq
, NULL
);
20847 /* Allocate the initial hunk of the decl_scope_table. */
20848 decl_scope_table
= VEC_alloc (tree
, gc
, 256);
20850 /* Allocate the initial hunk of the abbrev_die_table. */
20851 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
20852 (ABBREV_DIE_TABLE_INCREMENT
);
20853 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
20854 /* Zero-th entry is allocated, but unused. */
20855 abbrev_die_table_in_use
= 1;
20857 /* Allocate the pubtypes and pubnames vectors. */
20858 pubname_table
= VEC_alloc (pubname_entry
, gc
, 32);
20859 pubtype_table
= VEC_alloc (pubname_entry
, gc
, 32);
20861 incomplete_types
= VEC_alloc (tree
, gc
, 64);
20863 used_rtx_array
= VEC_alloc (rtx
, gc
, 32);
20865 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
20866 SECTION_DEBUG
, NULL
);
20867 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
20868 SECTION_DEBUG
, NULL
);
20869 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
20870 SECTION_DEBUG
, NULL
);
20871 debug_macinfo_section
= get_section (dwarf_strict
20872 ? DEBUG_MACINFO_SECTION
20873 : DEBUG_MACRO_SECTION
,
20874 SECTION_DEBUG
, NULL
);
20875 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
20876 SECTION_DEBUG
, NULL
);
20877 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
20878 SECTION_DEBUG
, NULL
);
20879 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
20880 SECTION_DEBUG
, NULL
);
20881 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
20882 SECTION_DEBUG
, NULL
);
20883 debug_str_section
= get_section (DEBUG_STR_SECTION
,
20884 DEBUG_STR_SECTION_FLAGS
, NULL
);
20885 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
20886 SECTION_DEBUG
, NULL
);
20887 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
20888 SECTION_DEBUG
, NULL
);
20890 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
20891 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
20892 DEBUG_ABBREV_SECTION_LABEL
, 0);
20893 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
20894 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
20895 COLD_TEXT_SECTION_LABEL
, 0);
20896 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
20898 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
20899 DEBUG_INFO_SECTION_LABEL
, 0);
20900 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
20901 DEBUG_LINE_SECTION_LABEL
, 0);
20902 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
20903 DEBUG_RANGES_SECTION_LABEL
, 0);
20904 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
20906 ? DEBUG_MACINFO_SECTION_LABEL
20907 : DEBUG_MACRO_SECTION_LABEL
, 0);
20909 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20910 macinfo_table
= VEC_alloc (macinfo_entry
, gc
, 64);
20912 switch_to_section (text_section
);
20913 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
20915 /* Make sure the line number table for .text always exists. */
20916 text_section_line_info
= new_line_info_table ();
20917 text_section_line_info
->end_label
= text_end_label
;
20920 /* Called before compile () starts outputtting functions, variables
20921 and toplevel asms into assembly. */
20924 dwarf2out_assembly_start (void)
20926 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
20927 && dwarf2out_do_cfi_asm ()
20928 && (!(flag_unwind_tables
|| flag_exceptions
)
20929 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
20930 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
20933 /* A helper function for dwarf2out_finish called through
20934 htab_traverse. Emit one queued .debug_str string. */
20937 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
20939 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
20941 if (node
->form
== DW_FORM_strp
)
20943 switch_to_section (debug_str_section
);
20944 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
20945 assemble_string (node
->str
, strlen (node
->str
) + 1);
20951 #if ENABLE_ASSERT_CHECKING
20952 /* Verify that all marks are clear. */
20955 verify_marks_clear (dw_die_ref die
)
20959 gcc_assert (! die
->die_mark
);
20960 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
20962 #endif /* ENABLE_ASSERT_CHECKING */
20964 /* Clear the marks for a die and its children.
20965 Be cool if the mark isn't set. */
20968 prune_unmark_dies (dw_die_ref die
)
20974 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
20977 /* Given DIE that we're marking as used, find any other dies
20978 it references as attributes and mark them as used. */
20981 prune_unused_types_walk_attribs (dw_die_ref die
)
20986 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
20988 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
20990 /* A reference to another DIE.
20991 Make sure that it will get emitted.
20992 If it was broken out into a comdat group, don't follow it. */
20993 if (! AT_ref (a
)->comdat_type_p
20994 || a
->dw_attr
== DW_AT_specification
)
20995 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
20997 /* Set the string's refcount to 0 so that prune_unused_types_mark
20998 accounts properly for it. */
20999 if (AT_class (a
) == dw_val_class_str
)
21000 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
21004 /* Mark the generic parameters and arguments children DIEs of DIE. */
21007 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
21011 if (die
== NULL
|| die
->die_child
== NULL
)
21013 c
= die
->die_child
;
21016 switch (c
->die_tag
)
21018 case DW_TAG_template_type_param
:
21019 case DW_TAG_template_value_param
:
21020 case DW_TAG_GNU_template_template_param
:
21021 case DW_TAG_GNU_template_parameter_pack
:
21022 prune_unused_types_mark (c
, 1);
21028 } while (c
&& c
!= die
->die_child
);
21031 /* Mark DIE as being used. If DOKIDS is true, then walk down
21032 to DIE's children. */
21035 prune_unused_types_mark (dw_die_ref die
, int dokids
)
21039 if (die
->die_mark
== 0)
21041 /* We haven't done this node yet. Mark it as used. */
21043 /* If this is the DIE of a generic type instantiation,
21044 mark the children DIEs that describe its generic parms and
21046 prune_unused_types_mark_generic_parms_dies (die
);
21048 /* We also have to mark its parents as used.
21049 (But we don't want to mark our parents' kids due to this.) */
21050 if (die
->die_parent
)
21051 prune_unused_types_mark (die
->die_parent
, 0);
21053 /* Mark any referenced nodes. */
21054 prune_unused_types_walk_attribs (die
);
21056 /* If this node is a specification,
21057 also mark the definition, if it exists. */
21058 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
21059 prune_unused_types_mark (die
->die_definition
, 1);
21062 if (dokids
&& die
->die_mark
!= 2)
21064 /* We need to walk the children, but haven't done so yet.
21065 Remember that we've walked the kids. */
21068 /* If this is an array type, we need to make sure our
21069 kids get marked, even if they're types. If we're
21070 breaking out types into comdat sections, do this
21071 for all type definitions. */
21072 if (die
->die_tag
== DW_TAG_array_type
21073 || (use_debug_types
21074 && is_type_die (die
) && ! is_declaration_die (die
)))
21075 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
21077 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
21081 /* For local classes, look if any static member functions were emitted
21082 and if so, mark them. */
21085 prune_unused_types_walk_local_classes (dw_die_ref die
)
21089 if (die
->die_mark
== 2)
21092 switch (die
->die_tag
)
21094 case DW_TAG_structure_type
:
21095 case DW_TAG_union_type
:
21096 case DW_TAG_class_type
:
21099 case DW_TAG_subprogram
:
21100 if (!get_AT_flag (die
, DW_AT_declaration
)
21101 || die
->die_definition
!= NULL
)
21102 prune_unused_types_mark (die
, 1);
21109 /* Mark children. */
21110 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
21113 /* Walk the tree DIE and mark types that we actually use. */
21116 prune_unused_types_walk (dw_die_ref die
)
21120 /* Don't do anything if this node is already marked and
21121 children have been marked as well. */
21122 if (die
->die_mark
== 2)
21125 switch (die
->die_tag
)
21127 case DW_TAG_structure_type
:
21128 case DW_TAG_union_type
:
21129 case DW_TAG_class_type
:
21130 if (die
->die_perennial_p
)
21133 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
21134 if (c
->die_tag
== DW_TAG_subprogram
)
21137 /* Finding used static member functions inside of classes
21138 is needed just for local classes, because for other classes
21139 static member function DIEs with DW_AT_specification
21140 are emitted outside of the DW_TAG_*_type. If we ever change
21141 it, we'd need to call this even for non-local classes. */
21143 prune_unused_types_walk_local_classes (die
);
21145 /* It's a type node --- don't mark it. */
21148 case DW_TAG_const_type
:
21149 case DW_TAG_packed_type
:
21150 case DW_TAG_pointer_type
:
21151 case DW_TAG_reference_type
:
21152 case DW_TAG_rvalue_reference_type
:
21153 case DW_TAG_volatile_type
:
21154 case DW_TAG_typedef
:
21155 case DW_TAG_array_type
:
21156 case DW_TAG_interface_type
:
21157 case DW_TAG_friend
:
21158 case DW_TAG_variant_part
:
21159 case DW_TAG_enumeration_type
:
21160 case DW_TAG_subroutine_type
:
21161 case DW_TAG_string_type
:
21162 case DW_TAG_set_type
:
21163 case DW_TAG_subrange_type
:
21164 case DW_TAG_ptr_to_member_type
:
21165 case DW_TAG_file_type
:
21166 if (die
->die_perennial_p
)
21169 /* It's a type node --- don't mark it. */
21173 /* Mark everything else. */
21177 if (die
->die_mark
== 0)
21181 /* Now, mark any dies referenced from here. */
21182 prune_unused_types_walk_attribs (die
);
21187 /* Mark children. */
21188 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
21191 /* Increment the string counts on strings referred to from DIE's
21195 prune_unused_types_update_strings (dw_die_ref die
)
21200 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
21201 if (AT_class (a
) == dw_val_class_str
)
21203 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
21205 /* Avoid unnecessarily putting strings that are used less than
21206 twice in the hash table. */
21208 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
21211 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
21212 htab_hash_string (s
->str
),
21214 gcc_assert (*slot
== NULL
);
21220 /* Remove from the tree DIE any dies that aren't marked. */
21223 prune_unused_types_prune (dw_die_ref die
)
21228 gcc_assert (die
->die_mark
);
21229 prune_unused_types_update_strings (die
);
21231 if (! die
->die_child
)
21234 c
= die
->die_child
;
21236 dw_die_ref prev
= c
;
21237 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
21238 if (c
== die
->die_child
)
21240 /* No marked children between 'prev' and the end of the list. */
21242 /* No marked children at all. */
21243 die
->die_child
= NULL
;
21246 prev
->die_sib
= c
->die_sib
;
21247 die
->die_child
= prev
;
21253 if (c
!= prev
->die_sib
)
21258 prune_unused_types_prune (c
);
21259 } while (c
!= die
->die_child
);
21262 /* If we pruned children, and this is a class, mark it as a
21263 declaration to inform debuggers that this is not a complete
21264 class definition. */
21265 if (pruned
&& die
->die_mark
== 1 && class_scope_p (die
)
21266 && ! is_declaration_die (die
))
21267 add_AT_flag (die
, DW_AT_declaration
, 1);
21270 /* Remove dies representing declarations that we never use. */
21273 prune_unused_types (void)
21276 limbo_die_node
*node
;
21277 comdat_type_node
*ctnode
;
21279 dw_die_ref base_type
;
21281 #if ENABLE_ASSERT_CHECKING
21282 /* All the marks should already be clear. */
21283 verify_marks_clear (comp_unit_die ());
21284 for (node
= limbo_die_list
; node
; node
= node
->next
)
21285 verify_marks_clear (node
->die
);
21286 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21287 verify_marks_clear (ctnode
->root_die
);
21288 #endif /* ENABLE_ASSERT_CHECKING */
21290 /* Mark types that are used in global variables. */
21291 premark_types_used_by_global_vars ();
21293 /* Set the mark on nodes that are actually used. */
21294 prune_unused_types_walk (comp_unit_die ());
21295 for (node
= limbo_die_list
; node
; node
= node
->next
)
21296 prune_unused_types_walk (node
->die
);
21297 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21299 prune_unused_types_walk (ctnode
->root_die
);
21300 prune_unused_types_mark (ctnode
->type_die
, 1);
21303 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
21304 are unusual in that they are pubnames that are the children of pubtypes.
21305 They should only be marked via their parent DW_TAG_enumeration_type die,
21306 not as roots in themselves. */
21307 FOR_EACH_VEC_ELT (pubname_entry
, pubname_table
, i
, pub
)
21308 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
21309 prune_unused_types_mark (pub
->die
, 1);
21310 for (i
= 0; VEC_iterate (dw_die_ref
, base_types
, i
, base_type
); i
++)
21311 prune_unused_types_mark (base_type
, 1);
21313 if (debug_str_hash
)
21314 htab_empty (debug_str_hash
);
21315 prune_unused_types_prune (comp_unit_die ());
21316 for (node
= limbo_die_list
; node
; node
= node
->next
)
21317 prune_unused_types_prune (node
->die
);
21318 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21319 prune_unused_types_prune (ctnode
->root_die
);
21321 /* Leave the marks clear. */
21322 prune_unmark_dies (comp_unit_die ());
21323 for (node
= limbo_die_list
; node
; node
= node
->next
)
21324 prune_unmark_dies (node
->die
);
21325 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21326 prune_unmark_dies (ctnode
->root_die
);
21329 /* Set the parameter to true if there are any relative pathnames in
21332 file_table_relative_p (void ** slot
, void *param
)
21334 bool *p
= (bool *) param
;
21335 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
21336 if (!IS_ABSOLUTE_PATH (d
->filename
))
21344 /* Routines to manipulate hash table of comdat type units. */
21347 htab_ct_hash (const void *of
)
21350 const comdat_type_node
*const type_node
= (const comdat_type_node
*) of
;
21352 memcpy (&h
, type_node
->signature
, sizeof (h
));
21357 htab_ct_eq (const void *of1
, const void *of2
)
21359 const comdat_type_node
*const type_node_1
= (const comdat_type_node
*) of1
;
21360 const comdat_type_node
*const type_node_2
= (const comdat_type_node
*) of2
;
21362 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
21363 DWARF_TYPE_SIGNATURE_SIZE
));
21366 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
21367 to the location it would have been added, should we know its
21368 DECL_ASSEMBLER_NAME when we added other attributes. This will
21369 probably improve compactness of debug info, removing equivalent
21370 abbrevs, and hide any differences caused by deferring the
21371 computation of the assembler name, triggered by e.g. PCH. */
21374 move_linkage_attr (dw_die_ref die
)
21376 unsigned ix
= VEC_length (dw_attr_node
, die
->die_attr
);
21377 dw_attr_node linkage
= VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
21379 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
21380 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
21384 dw_attr_node
*prev
= &VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
21386 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
21390 if (ix
!= VEC_length (dw_attr_node
, die
->die_attr
) - 1)
21392 VEC_pop (dw_attr_node
, die
->die_attr
);
21393 VEC_quick_insert (dw_attr_node
, die
->die_attr
, ix
, linkage
);
21397 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
21398 referenced from typed stack ops and count how often they are used. */
21401 mark_base_types (dw_loc_descr_ref loc
)
21403 dw_die_ref base_type
= NULL
;
21405 for (; loc
; loc
= loc
->dw_loc_next
)
21407 switch (loc
->dw_loc_opc
)
21409 case DW_OP_GNU_regval_type
:
21410 case DW_OP_GNU_deref_type
:
21411 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
21413 case DW_OP_GNU_convert
:
21414 case DW_OP_GNU_reinterpret
:
21415 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
21418 case DW_OP_GNU_const_type
:
21419 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
21421 case DW_OP_GNU_entry_value
:
21422 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
21427 gcc_assert (base_type
->die_parent
== comp_unit_die ());
21428 if (base_type
->die_mark
)
21429 base_type
->die_mark
++;
21432 VEC_safe_push (dw_die_ref
, heap
, base_types
, base_type
);
21433 base_type
->die_mark
= 1;
21438 /* Comparison function for sorting marked base types. */
21441 base_type_cmp (const void *x
, const void *y
)
21443 dw_die_ref dx
= *(const dw_die_ref
*) x
;
21444 dw_die_ref dy
= *(const dw_die_ref
*) y
;
21445 unsigned int byte_size1
, byte_size2
;
21446 unsigned int encoding1
, encoding2
;
21447 if (dx
->die_mark
> dy
->die_mark
)
21449 if (dx
->die_mark
< dy
->die_mark
)
21451 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
21452 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
21453 if (byte_size1
< byte_size2
)
21455 if (byte_size1
> byte_size2
)
21457 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
21458 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
21459 if (encoding1
< encoding2
)
21461 if (encoding1
> encoding2
)
21466 /* Move base types marked by mark_base_types as early as possible
21467 in the CU, sorted by decreasing usage count both to make the
21468 uleb128 references as small as possible and to make sure they
21469 will have die_offset already computed by calc_die_sizes when
21470 sizes of typed stack loc ops is computed. */
21473 move_marked_base_types (void)
21476 dw_die_ref base_type
, die
, c
;
21478 if (VEC_empty (dw_die_ref
, base_types
))
21481 /* Sort by decreasing usage count, they will be added again in that
21483 VEC_qsort (dw_die_ref
, base_types
, base_type_cmp
);
21484 die
= comp_unit_die ();
21485 c
= die
->die_child
;
21488 dw_die_ref prev
= c
;
21490 while (c
->die_mark
)
21492 remove_child_with_prev (c
, prev
);
21493 /* As base types got marked, there must be at least
21494 one node other than DW_TAG_base_type. */
21495 gcc_assert (c
!= c
->die_sib
);
21499 while (c
!= die
->die_child
);
21500 gcc_assert (die
->die_child
);
21501 c
= die
->die_child
;
21502 for (i
= 0; VEC_iterate (dw_die_ref
, base_types
, i
, base_type
); i
++)
21504 base_type
->die_mark
= 0;
21505 base_type
->die_sib
= c
->die_sib
;
21506 c
->die_sib
= base_type
;
21511 /* Helper function for resolve_addr, attempt to resolve
21512 one CONST_STRING, return non-zero if not successful. Similarly verify that
21513 SYMBOL_REFs refer to variables emitted in the current CU. */
21516 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
21520 if (GET_CODE (rtl
) == CONST_STRING
)
21522 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
21523 tree t
= build_string (len
, XSTR (rtl
, 0));
21524 tree tlen
= size_int (len
- 1);
21526 = build_array_type (char_type_node
, build_index_type (tlen
));
21527 rtl
= lookup_constant_def (t
);
21528 if (!rtl
|| !MEM_P (rtl
))
21530 rtl
= XEXP (rtl
, 0);
21531 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
21536 if (GET_CODE (rtl
) == SYMBOL_REF
21537 && SYMBOL_REF_DECL (rtl
))
21539 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
21541 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
21544 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
21548 if (GET_CODE (rtl
) == CONST
21549 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
21555 /* Helper function for resolve_addr, handle one location
21556 expression, return false if at least one CONST_STRING or SYMBOL_REF in
21557 the location list couldn't be resolved. */
21560 resolve_addr_in_expr (dw_loc_descr_ref loc
)
21562 dw_loc_descr_ref keep
= NULL
;
21563 for (; loc
; loc
= loc
->dw_loc_next
)
21564 switch (loc
->dw_loc_opc
)
21567 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
21570 case DW_OP_const4u
:
21571 case DW_OP_const8u
:
21573 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
21576 case DW_OP_plus_uconst
:
21577 if (size_of_loc_descr (loc
)
21578 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
21580 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
21582 dw_loc_descr_ref repl
21583 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
21584 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
21585 add_loc_descr (&repl
, loc
->dw_loc_next
);
21589 case DW_OP_implicit_value
:
21590 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
21591 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
21594 case DW_OP_GNU_implicit_pointer
:
21595 case DW_OP_GNU_parameter_ref
:
21596 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
21599 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
21602 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
21603 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
21604 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
21607 case DW_OP_GNU_const_type
:
21608 case DW_OP_GNU_regval_type
:
21609 case DW_OP_GNU_deref_type
:
21610 case DW_OP_GNU_convert
:
21611 case DW_OP_GNU_reinterpret
:
21612 while (loc
->dw_loc_next
21613 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
21615 dw_die_ref base1
, base2
;
21616 unsigned enc1
, enc2
, size1
, size2
;
21617 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
21618 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
21619 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
21620 else if (loc
->dw_loc_oprnd1
.val_class
21621 == dw_val_class_unsigned_const
)
21624 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
21625 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
21626 == dw_val_class_unsigned_const
)
21628 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
21629 gcc_assert (base1
->die_tag
== DW_TAG_base_type
21630 && base2
->die_tag
== DW_TAG_base_type
);
21631 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
21632 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
21633 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
21634 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
21636 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
21637 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
21641 /* Optimize away next DW_OP_GNU_convert after
21642 adjusting LOC's base type die reference. */
21643 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
21644 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
21645 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
21647 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
21648 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
21651 /* Don't change integer DW_OP_GNU_convert after e.g. floating
21652 point typed stack entry. */
21653 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
21654 keep
= loc
->dw_loc_next
;
21664 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
21665 an address in .rodata section if the string literal is emitted there,
21666 or remove the containing location list or replace DW_AT_const_value
21667 with DW_AT_location and empty location expression, if it isn't found
21668 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
21669 to something that has been emitted in the current CU. */
21672 resolve_addr (dw_die_ref die
)
21676 dw_loc_list_ref
*curr
, *start
, loc
;
21679 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
21680 switch (AT_class (a
))
21682 case dw_val_class_loc_list
:
21683 start
= curr
= AT_loc_list_ptr (a
);
21686 /* The same list can be referenced more than once. See if we have
21687 already recorded the result from a previous pass. */
21689 *curr
= loc
->dw_loc_next
;
21690 else if (!loc
->resolved_addr
)
21692 /* As things stand, we do not expect or allow one die to
21693 reference a suffix of another die's location list chain.
21694 References must be identical or completely separate.
21695 There is therefore no need to cache the result of this
21696 pass on any list other than the first; doing so
21697 would lead to unnecessary writes. */
21700 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
21701 if (!resolve_addr_in_expr ((*curr
)->expr
))
21703 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
21704 if (next
&& (*curr
)->ll_symbol
)
21706 gcc_assert (!next
->ll_symbol
);
21707 next
->ll_symbol
= (*curr
)->ll_symbol
;
21713 mark_base_types ((*curr
)->expr
);
21714 curr
= &(*curr
)->dw_loc_next
;
21718 loc
->resolved_addr
= 1;
21722 loc
->dw_loc_next
= *start
;
21727 remove_AT (die
, a
->dw_attr
);
21731 case dw_val_class_loc
:
21733 dw_loc_descr_ref l
= AT_loc (a
);
21734 /* For -gdwarf-2 don't attempt to optimize
21735 DW_AT_data_member_location containing
21736 DW_OP_plus_uconst - older consumers might
21737 rely on it being that op instead of a more complex,
21738 but shorter, location description. */
21739 if ((dwarf_version
> 2
21740 || a
->dw_attr
!= DW_AT_data_member_location
21742 || l
->dw_loc_opc
!= DW_OP_plus_uconst
21743 || l
->dw_loc_next
!= NULL
)
21744 && !resolve_addr_in_expr (l
))
21746 remove_AT (die
, a
->dw_attr
);
21750 mark_base_types (l
);
21753 case dw_val_class_addr
:
21754 if (a
->dw_attr
== DW_AT_const_value
21755 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
21757 remove_AT (die
, a
->dw_attr
);
21760 if (die
->die_tag
== DW_TAG_GNU_call_site
21761 && a
->dw_attr
== DW_AT_abstract_origin
)
21763 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
21764 dw_die_ref tdie
= lookup_decl_die (tdecl
);
21766 && DECL_EXTERNAL (tdecl
)
21767 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
21769 force_decl_die (tdecl
);
21770 tdie
= lookup_decl_die (tdecl
);
21774 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
21775 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
21776 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
21780 remove_AT (die
, a
->dw_attr
);
21789 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
21792 /* Helper routines for optimize_location_lists.
21793 This pass tries to share identical local lists in .debug_loc
21796 /* Iteratively hash operands of LOC opcode. */
21798 static inline hashval_t
21799 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
21801 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
21802 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
21804 switch (loc
->dw_loc_opc
)
21806 case DW_OP_const4u
:
21807 case DW_OP_const8u
:
21811 case DW_OP_const1u
:
21812 case DW_OP_const1s
:
21813 case DW_OP_const2u
:
21814 case DW_OP_const2s
:
21815 case DW_OP_const4s
:
21816 case DW_OP_const8s
:
21820 case DW_OP_plus_uconst
:
21856 case DW_OP_deref_size
:
21857 case DW_OP_xderef_size
:
21858 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
21865 gcc_assert (val1
->val_class
== dw_val_class_loc
);
21866 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
21867 hash
= iterative_hash_object (offset
, hash
);
21870 case DW_OP_implicit_value
:
21871 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
21872 switch (val2
->val_class
)
21874 case dw_val_class_const
:
21875 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
21877 case dw_val_class_vec
:
21879 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
21880 unsigned int len
= val2
->v
.val_vec
.length
;
21882 hash
= iterative_hash_object (elt_size
, hash
);
21883 hash
= iterative_hash_object (len
, hash
);
21884 hash
= iterative_hash (val2
->v
.val_vec
.array
,
21885 len
* elt_size
, hash
);
21888 case dw_val_class_const_double
:
21889 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
21890 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
21892 case dw_val_class_addr
:
21893 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
21896 gcc_unreachable ();
21900 case DW_OP_bit_piece
:
21901 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
21902 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
21908 unsigned char dtprel
= 0xd1;
21909 hash
= iterative_hash_object (dtprel
, hash
);
21911 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
21913 case DW_OP_GNU_implicit_pointer
:
21914 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
21916 case DW_OP_GNU_entry_value
:
21917 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
21919 case DW_OP_GNU_regval_type
:
21920 case DW_OP_GNU_deref_type
:
21922 unsigned int byte_size
21923 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
21924 unsigned int encoding
21925 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
21926 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
21927 hash
= iterative_hash_object (byte_size
, hash
);
21928 hash
= iterative_hash_object (encoding
, hash
);
21931 case DW_OP_GNU_convert
:
21932 case DW_OP_GNU_reinterpret
:
21933 if (val1
->val_class
== dw_val_class_unsigned_const
)
21935 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
21939 case DW_OP_GNU_const_type
:
21941 unsigned int byte_size
21942 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
21943 unsigned int encoding
21944 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
21945 hash
= iterative_hash_object (byte_size
, hash
);
21946 hash
= iterative_hash_object (encoding
, hash
);
21947 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
21949 hash
= iterative_hash_object (val2
->val_class
, hash
);
21950 switch (val2
->val_class
)
21952 case dw_val_class_const
:
21953 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
21955 case dw_val_class_vec
:
21957 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
21958 unsigned int len
= val2
->v
.val_vec
.length
;
21960 hash
= iterative_hash_object (elt_size
, hash
);
21961 hash
= iterative_hash_object (len
, hash
);
21962 hash
= iterative_hash (val2
->v
.val_vec
.array
,
21963 len
* elt_size
, hash
);
21966 case dw_val_class_const_double
:
21967 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
21968 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
21971 gcc_unreachable ();
21977 /* Other codes have no operands. */
21983 /* Iteratively hash the whole DWARF location expression LOC. */
21985 static inline hashval_t
21986 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
21988 dw_loc_descr_ref l
;
21989 bool sizes_computed
= false;
21990 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
21991 size_of_locs (loc
);
21993 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
21995 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
21996 hash
= iterative_hash_object (opc
, hash
);
21997 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
21999 size_of_locs (loc
);
22000 sizes_computed
= true;
22002 hash
= hash_loc_operands (l
, hash
);
22007 /* Compute hash of the whole location list LIST_HEAD. */
22010 hash_loc_list (dw_loc_list_ref list_head
)
22012 dw_loc_list_ref curr
= list_head
;
22013 hashval_t hash
= 0;
22015 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
22017 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
22018 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
22020 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
22022 hash
= hash_locs (curr
->expr
, hash
);
22024 list_head
->hash
= hash
;
22027 /* Return true if X and Y opcodes have the same operands. */
22030 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
22032 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
22033 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
22034 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
22035 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
22037 switch (x
->dw_loc_opc
)
22039 case DW_OP_const4u
:
22040 case DW_OP_const8u
:
22044 case DW_OP_const1u
:
22045 case DW_OP_const1s
:
22046 case DW_OP_const2u
:
22047 case DW_OP_const2s
:
22048 case DW_OP_const4s
:
22049 case DW_OP_const8s
:
22053 case DW_OP_plus_uconst
:
22089 case DW_OP_deref_size
:
22090 case DW_OP_xderef_size
:
22091 return valx1
->v
.val_int
== valy1
->v
.val_int
;
22094 gcc_assert (valx1
->val_class
== dw_val_class_loc
22095 && valy1
->val_class
== dw_val_class_loc
22096 && x
->dw_loc_addr
== y
->dw_loc_addr
);
22097 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
22098 case DW_OP_implicit_value
:
22099 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
22100 || valx2
->val_class
!= valy2
->val_class
)
22102 switch (valx2
->val_class
)
22104 case dw_val_class_const
:
22105 return valx2
->v
.val_int
== valy2
->v
.val_int
;
22106 case dw_val_class_vec
:
22107 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
22108 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
22109 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
22110 valx2
->v
.val_vec
.elt_size
22111 * valx2
->v
.val_vec
.length
) == 0;
22112 case dw_val_class_const_double
:
22113 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
22114 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
22115 case dw_val_class_addr
:
22116 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
22118 gcc_unreachable ();
22121 case DW_OP_bit_piece
:
22122 return valx1
->v
.val_int
== valy1
->v
.val_int
22123 && valx2
->v
.val_int
== valy2
->v
.val_int
;
22126 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
22127 case DW_OP_GNU_implicit_pointer
:
22128 return valx1
->val_class
== dw_val_class_die_ref
22129 && valx1
->val_class
== valy1
->val_class
22130 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
22131 && valx2
->v
.val_int
== valy2
->v
.val_int
;
22132 case DW_OP_GNU_entry_value
:
22133 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
22134 case DW_OP_GNU_const_type
:
22135 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
22136 || valx2
->val_class
!= valy2
->val_class
)
22138 switch (valx2
->val_class
)
22140 case dw_val_class_const
:
22141 return valx2
->v
.val_int
== valy2
->v
.val_int
;
22142 case dw_val_class_vec
:
22143 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
22144 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
22145 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
22146 valx2
->v
.val_vec
.elt_size
22147 * valx2
->v
.val_vec
.length
) == 0;
22148 case dw_val_class_const_double
:
22149 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
22150 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
22152 gcc_unreachable ();
22154 case DW_OP_GNU_regval_type
:
22155 case DW_OP_GNU_deref_type
:
22156 return valx1
->v
.val_int
== valy1
->v
.val_int
22157 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
22158 case DW_OP_GNU_convert
:
22159 case DW_OP_GNU_reinterpret
:
22160 if (valx1
->val_class
!= valy1
->val_class
)
22162 if (valx1
->val_class
== dw_val_class_unsigned_const
)
22163 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
22164 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
22165 case DW_OP_GNU_parameter_ref
:
22166 return valx1
->val_class
== dw_val_class_die_ref
22167 && valx1
->val_class
== valy1
->val_class
22168 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
22170 /* Other codes have no operands. */
22175 /* Return true if DWARF location expressions X and Y are the same. */
22178 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
22180 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
22181 if (x
->dw_loc_opc
!= y
->dw_loc_opc
22182 || x
->dtprel
!= y
->dtprel
22183 || !compare_loc_operands (x
, y
))
22185 return x
== NULL
&& y
== NULL
;
22188 /* Return precomputed hash of location list X. */
22191 loc_list_hash (const void *x
)
22193 return ((const struct dw_loc_list_struct
*) x
)->hash
;
22196 /* Return 1 if location lists X and Y are the same. */
22199 loc_list_eq (const void *x
, const void *y
)
22201 const struct dw_loc_list_struct
*a
= (const struct dw_loc_list_struct
*) x
;
22202 const struct dw_loc_list_struct
*b
= (const struct dw_loc_list_struct
*) y
;
22205 if (a
->hash
!= b
->hash
)
22207 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
22208 if (strcmp (a
->begin
, b
->begin
) != 0
22209 || strcmp (a
->end
, b
->end
) != 0
22210 || (a
->section
== NULL
) != (b
->section
== NULL
)
22211 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
22212 || !compare_locs (a
->expr
, b
->expr
))
22214 return a
== NULL
&& b
== NULL
;
22217 /* Recursively optimize location lists referenced from DIE
22218 children and share them whenever possible. */
22221 optimize_location_lists_1 (dw_die_ref die
, htab_t htab
)
22228 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
22229 if (AT_class (a
) == dw_val_class_loc_list
)
22231 dw_loc_list_ref list
= AT_loc_list (a
);
22232 /* TODO: perform some optimizations here, before hashing
22233 it and storing into the hash table. */
22234 hash_loc_list (list
);
22235 slot
= htab_find_slot_with_hash (htab
, list
, list
->hash
,
22238 *slot
= (void *) list
;
22240 a
->dw_attr_val
.v
.val_loc_list
= (dw_loc_list_ref
) *slot
;
22243 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
22246 /* Optimize location lists referenced from DIE
22247 children and share them whenever possible. */
22250 optimize_location_lists (dw_die_ref die
)
22252 htab_t htab
= htab_create (500, loc_list_hash
, loc_list_eq
, NULL
);
22253 optimize_location_lists_1 (die
, htab
);
22254 htab_delete (htab
);
22257 /* Output stuff that dwarf requires at the end of every file,
22258 and generate the DWARF-2 debugging info. */
22261 dwarf2out_finish (const char *filename
)
22263 limbo_die_node
*node
, *next_node
;
22264 comdat_type_node
*ctnode
;
22265 htab_t comdat_type_table
;
22268 /* PCH might result in DW_AT_producer string being restored from the
22269 header compilation, fix it up if needed. */
22270 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
22271 if (strcmp (AT_string (producer
), producer_string
) != 0)
22273 struct indirect_string_node
*node
= find_AT_string (producer_string
);
22274 producer
->dw_attr_val
.v
.val_str
= node
;
22277 gen_scheduled_generic_parms_dies ();
22278 gen_remaining_tmpl_value_param_die_attribute ();
22280 /* Add the name for the main input file now. We delayed this from
22281 dwarf2out_init to avoid complications with PCH. */
22282 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
22283 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
22284 add_comp_dir_attribute (comp_unit_die ());
22285 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
22288 htab_traverse (file_table
, file_table_relative_p
, &p
);
22290 add_comp_dir_attribute (comp_unit_die ());
22293 for (i
= 0; i
< VEC_length (deferred_locations
, deferred_locations_list
); i
++)
22295 add_location_or_const_value_attribute (
22296 VEC_index (deferred_locations
, deferred_locations_list
, i
).die
,
22297 VEC_index (deferred_locations
, deferred_locations_list
, i
).variable
,
22302 /* Traverse the limbo die list, and add parent/child links. The only
22303 dies without parents that should be here are concrete instances of
22304 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
22305 For concrete instances, we can get the parent die from the abstract
22307 for (node
= limbo_die_list
; node
; node
= next_node
)
22309 dw_die_ref die
= node
->die
;
22310 next_node
= node
->next
;
22312 if (die
->die_parent
== NULL
)
22314 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
22316 if (origin
&& origin
->die_parent
)
22317 add_child_die (origin
->die_parent
, die
);
22318 else if (is_cu_die (die
))
22320 else if (seen_error ())
22321 /* It's OK to be confused by errors in the input. */
22322 add_child_die (comp_unit_die (), die
);
22325 /* In certain situations, the lexical block containing a
22326 nested function can be optimized away, which results
22327 in the nested function die being orphaned. Likewise
22328 with the return type of that nested function. Force
22329 this to be a child of the containing function.
22331 It may happen that even the containing function got fully
22332 inlined and optimized out. In that case we are lost and
22333 assign the empty child. This should not be big issue as
22334 the function is likely unreachable too. */
22335 gcc_assert (node
->created_for
);
22337 if (DECL_P (node
->created_for
))
22338 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
22339 else if (TYPE_P (node
->created_for
))
22340 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
22342 origin
= comp_unit_die ();
22344 add_child_die (origin
, die
);
22349 limbo_die_list
= NULL
;
22351 #if ENABLE_ASSERT_CHECKING
22353 dw_die_ref die
= comp_unit_die (), c
;
22354 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
22357 resolve_addr (comp_unit_die ());
22358 move_marked_base_types ();
22360 for (node
= deferred_asm_name
; node
; node
= node
->next
)
22362 tree decl
= node
->created_for
;
22363 /* When generating LTO bytecode we can not generate new assembler
22364 names at this point and all important decls got theirs via
22366 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
22367 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
22369 add_linkage_attr (node
->die
, decl
);
22370 move_linkage_attr (node
->die
);
22374 deferred_asm_name
= NULL
;
22376 /* Walk through the list of incomplete types again, trying once more to
22377 emit full debugging info for them. */
22378 retry_incomplete_types ();
22380 if (flag_eliminate_unused_debug_types
)
22381 prune_unused_types ();
22383 /* Generate separate COMDAT sections for type DIEs. */
22384 if (use_debug_types
)
22386 break_out_comdat_types (comp_unit_die ());
22388 /* Each new type_unit DIE was added to the limbo die list when created.
22389 Since these have all been added to comdat_type_list, clear the
22391 limbo_die_list
= NULL
;
22393 /* For each new comdat type unit, copy declarations for incomplete
22394 types to make the new unit self-contained (i.e., no direct
22395 references to the main compile unit). */
22396 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22397 copy_decls_for_unworthy_types (ctnode
->root_die
);
22398 copy_decls_for_unworthy_types (comp_unit_die ());
22400 /* In the process of copying declarations from one unit to another,
22401 we may have left some declarations behind that are no longer
22402 referenced. Prune them. */
22403 prune_unused_types ();
22406 /* Generate separate CUs for each of the include files we've seen.
22407 They will go into limbo_die_list. */
22408 if (flag_eliminate_dwarf2_dups
)
22409 break_out_includes (comp_unit_die ());
22411 /* Traverse the DIE's and add add sibling attributes to those DIE's
22412 that have children. */
22413 add_sibling_attributes (comp_unit_die ());
22414 for (node
= limbo_die_list
; node
; node
= node
->next
)
22415 add_sibling_attributes (node
->die
);
22416 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22417 add_sibling_attributes (ctnode
->root_die
);
22419 /* Output a terminator label for the .text section. */
22420 switch_to_section (text_section
);
22421 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
22422 if (cold_text_section
)
22424 switch_to_section (cold_text_section
);
22425 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
22428 /* We can only use the low/high_pc attributes if all of the code was
22430 if (!have_multiple_function_sections
22431 || (dwarf_version
< 3 && dwarf_strict
))
22433 /* Don't add if the CU has no associated code. */
22434 if (text_section_used
)
22435 add_AT_low_high_pc (comp_unit_die (), text_section_label
,
22442 bool range_list_added
= false;
22444 if (text_section_used
)
22445 add_ranges_by_labels (comp_unit_die (), text_section_label
,
22446 text_end_label
, &range_list_added
);
22447 if (cold_text_section_used
)
22448 add_ranges_by_labels (comp_unit_die (), cold_text_section_label
,
22449 cold_end_label
, &range_list_added
);
22451 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, fde_idx
, fde
)
22453 if (DECL_IGNORED_P (fde
->decl
))
22455 if (!fde
->in_std_section
)
22456 add_ranges_by_labels (comp_unit_die (), fde
->dw_fde_begin
,
22457 fde
->dw_fde_end
, &range_list_added
);
22458 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
22459 add_ranges_by_labels (comp_unit_die (), fde
->dw_fde_second_begin
,
22460 fde
->dw_fde_second_end
, &range_list_added
);
22463 if (range_list_added
)
22465 /* We need to give .debug_loc and .debug_ranges an appropriate
22466 "base address". Use zero so that these addresses become
22467 absolute. Historically, we've emitted the unexpected
22468 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
22469 Emit both to give time for other tools to adapt. */
22470 add_AT_addr (comp_unit_die (), DW_AT_low_pc
, const0_rtx
);
22471 if (! dwarf_strict
&& dwarf_version
< 4)
22472 add_AT_addr (comp_unit_die (), DW_AT_entry_pc
, const0_rtx
);
22478 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
22479 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list
,
22480 debug_line_section_label
);
22483 add_AT_macptr (comp_unit_die (),
22484 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
22485 macinfo_section_label
);
22487 if (have_location_lists
)
22488 optimize_location_lists (comp_unit_die ());
22490 /* Output all of the compilation units. We put the main one last so that
22491 the offsets are available to output_pubnames. */
22492 for (node
= limbo_die_list
; node
; node
= node
->next
)
22493 output_comp_unit (node
->die
, 0);
22495 comdat_type_table
= htab_create (100, htab_ct_hash
, htab_ct_eq
, NULL
);
22496 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22498 void **slot
= htab_find_slot (comdat_type_table
, ctnode
, INSERT
);
22500 /* Don't output duplicate types. */
22501 if (*slot
!= HTAB_EMPTY_ENTRY
)
22504 /* Add a pointer to the line table for the main compilation unit
22505 so that the debugger can make sense of DW_AT_decl_file
22507 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
22508 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
22509 debug_line_section_label
);
22511 output_comdat_type_unit (ctnode
);
22514 htab_delete (comdat_type_table
);
22516 add_AT_pubnames (comp_unit_die ());
22518 /* Output the main compilation unit if non-empty or if .debug_macinfo
22519 or .debug_macro will be emitted. */
22520 output_comp_unit (comp_unit_die (), have_macinfo
);
22522 /* Output the abbreviation table. */
22523 if (abbrev_die_table_in_use
!= 1)
22525 switch_to_section (debug_abbrev_section
);
22526 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
22527 output_abbrev_section ();
22530 /* Output location list section if necessary. */
22531 if (have_location_lists
)
22533 /* Output the location lists info. */
22534 switch_to_section (debug_loc_section
);
22535 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
22536 DEBUG_LOC_SECTION_LABEL
, 0);
22537 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
22538 output_location_lists (comp_unit_die ());
22541 /* Output public names and types tables if necessary. */
22542 output_pubnames (pubname_table
);
22543 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
22544 It shouldn't hurt to emit it always, since pure DWARF2 consumers
22545 simply won't look for the section. */
22546 output_pubnames (pubtype_table
);
22548 /* Output the address range information if a CU (.debug_info section)
22549 was emitted. We output an empty table even if we had no functions
22550 to put in it. This because the consumer has no way to tell the
22551 difference between an empty table that we omitted and failure to
22552 generate a table that would have contained data. */
22553 if (info_section_emitted
)
22555 unsigned long aranges_length
= size_of_aranges ();
22557 switch_to_section (debug_aranges_section
);
22558 output_aranges (aranges_length
);
22561 /* Output ranges section if necessary. */
22562 if (ranges_table_in_use
)
22564 switch_to_section (debug_ranges_section
);
22565 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
22569 /* Have to end the macro section. */
22572 switch_to_section (debug_macinfo_section
);
22573 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
22575 dw2_asm_output_data (1, 0, "End compilation unit");
22578 /* Output the source line correspondence table. We must do this
22579 even if there is no line information. Otherwise, on an empty
22580 translation unit, we will generate a present, but empty,
22581 .debug_info section. IRIX 6.5 `nm' will then complain when
22582 examining the file. This is done late so that any filenames
22583 used by the debug_info section are marked as 'used'. */
22584 switch_to_section (debug_line_section
);
22585 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
22586 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
22587 output_line_info ();
22589 /* If we emitted any DW_FORM_strp form attribute, output the string
22591 if (debug_str_hash
)
22592 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
22595 #include "gt-dwarf2out.h"