1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 Free Software Foundation, Inc.
5 Contributed by Gary Funck (gary@intrepid.com).
6 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
7 Extensively modified by Jason Merrill (jason@cygnus.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
37 /* DWARF2 Abbreviation Glossary:
39 CFA = Canonical Frame Address
40 a fixed address on the stack which identifies a call frame.
41 We define it to be the value of SP just before the call insn.
42 The CFA register and offset, which may change during the course
43 of the function, are used to calculate its value at runtime.
45 CFI = Call Frame Instruction
46 an instruction for the DWARF2 abstract machine
48 CIE = Common Information Entry
49 information describing information common to one or more FDEs
51 DIE = Debugging Information Entry
53 FDE = Frame Description Entry
54 information describing the stack call frame, in particular,
55 how to restore registers
57 DW_CFA_... = DWARF2 CFA call frame instruction
58 DW_TAG_... = DWARF2 DIE tag */
62 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
84 #include "diagnostic.h"
85 #include "tree-pretty-print.h"
88 #include "common/common-target.h"
89 #include "langhooks.h"
94 #include "tree-pass.h"
95 #include "tree-flow.h"
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_TARGET
))
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 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1318 case dw_val_class_str
:
1319 return a
->v
.val_str
== b
->v
.val_str
;
1320 case dw_val_class_flag
:
1321 return a
->v
.val_flag
== b
->v
.val_flag
;
1322 case dw_val_class_file
:
1323 return a
->v
.val_file
== b
->v
.val_file
;
1324 case dw_val_class_decl_ref
:
1325 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1327 case dw_val_class_const_double
:
1328 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1329 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1331 case dw_val_class_vec
:
1333 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1334 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1336 return (a_len
== b_len
1337 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1340 case dw_val_class_data8
:
1341 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1343 case dw_val_class_vms_delta
:
1344 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1345 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1350 /* Compare two location atoms for exact equality. */
1353 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1355 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1358 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1359 address size, but since we always allocate cleared storage it
1360 should be zero for other types of locations. */
1361 if (a
->dtprel
!= b
->dtprel
)
1364 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1365 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1368 /* Compare two complete location expressions for exact equality. */
1371 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1377 if (a
== NULL
|| b
== NULL
)
1379 if (!loc_descr_equal_p_1 (a
, b
))
1388 /* Add a constant OFFSET to a location expression. */
1391 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1393 dw_loc_descr_ref loc
;
1396 gcc_assert (*list_head
!= NULL
);
1401 /* Find the end of the chain. */
1402 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1406 if (loc
->dw_loc_opc
== DW_OP_fbreg
1407 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1408 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1409 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1410 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1412 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1413 offset. Don't optimize if an signed integer overflow would happen. */
1415 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1416 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1419 else if (offset
> 0)
1420 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1424 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1425 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1429 /* Add a constant OFFSET to a location list. */
1432 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1435 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1436 loc_descr_plus_const (&d
->expr
, offset
);
1439 #define DWARF_REF_SIZE \
1440 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1442 static unsigned long int get_base_type_offset (dw_die_ref
);
1444 /* Return the size of a location descriptor. */
1446 static unsigned long
1447 size_of_loc_descr (dw_loc_descr_ref loc
)
1449 unsigned long size
= 1;
1451 switch (loc
->dw_loc_opc
)
1454 size
+= DWARF2_ADDR_SIZE
;
1473 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1476 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1481 case DW_OP_plus_uconst
:
1482 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1520 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1523 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1526 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1529 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1530 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1533 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1535 case DW_OP_bit_piece
:
1536 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1537 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1539 case DW_OP_deref_size
:
1540 case DW_OP_xderef_size
:
1549 case DW_OP_call_ref
:
1550 size
+= DWARF_REF_SIZE
;
1552 case DW_OP_implicit_value
:
1553 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1554 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1556 case DW_OP_GNU_implicit_pointer
:
1557 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1559 case DW_OP_GNU_entry_value
:
1561 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1562 size
+= size_of_uleb128 (op_size
) + op_size
;
1565 case DW_OP_GNU_const_type
:
1568 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1569 size
+= size_of_uleb128 (o
) + 1;
1570 switch (loc
->dw_loc_oprnd2
.val_class
)
1572 case dw_val_class_vec
:
1573 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1574 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1576 case dw_val_class_const
:
1577 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1579 case dw_val_class_const_double
:
1580 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1587 case DW_OP_GNU_regval_type
:
1590 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1591 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1592 + size_of_uleb128 (o
);
1595 case DW_OP_GNU_deref_type
:
1598 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1599 size
+= 1 + size_of_uleb128 (o
);
1602 case DW_OP_GNU_convert
:
1603 case DW_OP_GNU_reinterpret
:
1604 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1605 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1609 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1610 size
+= size_of_uleb128 (o
);
1613 case DW_OP_GNU_parameter_ref
:
1623 /* Return the size of a series of location descriptors. */
1626 size_of_locs (dw_loc_descr_ref loc
)
1631 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1632 field, to avoid writing to a PCH file. */
1633 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1635 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1637 size
+= size_of_loc_descr (l
);
1642 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1644 l
->dw_loc_addr
= size
;
1645 size
+= size_of_loc_descr (l
);
1651 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1652 static void get_ref_die_offset_label (char *, dw_die_ref
);
1653 static unsigned long int get_ref_die_offset (dw_die_ref
);
1655 /* Output location description stack opcode's operands (if any).
1656 The for_eh_or_skip parameter controls whether register numbers are
1657 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1658 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1659 info). This should be suppressed for the cases that have not been converted
1660 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1663 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1665 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1666 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1668 switch (loc
->dw_loc_opc
)
1670 #ifdef DWARF2_DEBUGGING_INFO
1673 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1678 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1679 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1681 fputc ('\n', asm_out_file
);
1686 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1691 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1692 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1694 fputc ('\n', asm_out_file
);
1699 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1700 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1707 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1708 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1710 dw2_asm_output_data (2, offset
, NULL
);
1713 case DW_OP_implicit_value
:
1714 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1715 switch (val2
->val_class
)
1717 case dw_val_class_const
:
1718 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1720 case dw_val_class_vec
:
1722 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1723 unsigned int len
= val2
->v
.val_vec
.length
;
1727 if (elt_size
> sizeof (HOST_WIDE_INT
))
1732 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1735 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1736 "fp or vector constant word %u", i
);
1739 case dw_val_class_const_double
:
1741 unsigned HOST_WIDE_INT first
, second
;
1743 if (WORDS_BIG_ENDIAN
)
1745 first
= val2
->v
.val_double
.high
;
1746 second
= val2
->v
.val_double
.low
;
1750 first
= val2
->v
.val_double
.low
;
1751 second
= val2
->v
.val_double
.high
;
1753 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1755 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1759 case dw_val_class_addr
:
1760 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1761 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1776 case DW_OP_implicit_value
:
1777 /* We currently don't make any attempt to make sure these are
1778 aligned properly like we do for the main unwind info, so
1779 don't support emitting things larger than a byte if we're
1780 only doing unwinding. */
1785 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1788 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1791 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1794 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1796 case DW_OP_plus_uconst
:
1797 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1831 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1835 unsigned r
= val1
->v
.val_unsigned
;
1836 if (for_eh_or_skip
>= 0)
1837 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1838 gcc_assert (size_of_uleb128 (r
)
1839 == size_of_uleb128 (val1
->v
.val_unsigned
));
1840 dw2_asm_output_data_uleb128 (r
, NULL
);
1844 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1848 unsigned r
= val1
->v
.val_unsigned
;
1849 if (for_eh_or_skip
>= 0)
1850 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1851 gcc_assert (size_of_uleb128 (r
)
1852 == size_of_uleb128 (val1
->v
.val_unsigned
));
1853 dw2_asm_output_data_uleb128 (r
, NULL
);
1854 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1858 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1860 case DW_OP_bit_piece
:
1861 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1862 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1864 case DW_OP_deref_size
:
1865 case DW_OP_xderef_size
:
1866 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1872 if (targetm
.asm_out
.output_dwarf_dtprel
)
1874 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1877 fputc ('\n', asm_out_file
);
1884 #ifdef DWARF2_DEBUGGING_INFO
1885 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
1892 case DW_OP_GNU_implicit_pointer
:
1894 char label
[MAX_ARTIFICIAL_LABEL_BYTES
1895 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
1896 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
1897 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
1898 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
1899 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1903 case DW_OP_GNU_entry_value
:
1904 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
1905 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
1908 case DW_OP_GNU_const_type
:
1910 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
1912 dw2_asm_output_data_uleb128 (o
, NULL
);
1913 switch (val2
->val_class
)
1915 case dw_val_class_const
:
1916 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
1917 dw2_asm_output_data (1, l
, NULL
);
1918 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
1920 case dw_val_class_vec
:
1922 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1923 unsigned int len
= val2
->v
.val_vec
.length
;
1928 dw2_asm_output_data (1, l
, NULL
);
1929 if (elt_size
> sizeof (HOST_WIDE_INT
))
1934 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1937 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1938 "fp or vector constant word %u", i
);
1941 case dw_val_class_const_double
:
1943 unsigned HOST_WIDE_INT first
, second
;
1944 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
1946 dw2_asm_output_data (1, 2 * l
, NULL
);
1947 if (WORDS_BIG_ENDIAN
)
1949 first
= val2
->v
.val_double
.high
;
1950 second
= val2
->v
.val_double
.low
;
1954 first
= val2
->v
.val_double
.low
;
1955 second
= val2
->v
.val_double
.high
;
1957 dw2_asm_output_data (l
, first
, NULL
);
1958 dw2_asm_output_data (l
, second
, NULL
);
1966 case DW_OP_GNU_regval_type
:
1968 unsigned r
= val1
->v
.val_unsigned
;
1969 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
1971 if (for_eh_or_skip
>= 0)
1973 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1974 gcc_assert (size_of_uleb128 (r
)
1975 == size_of_uleb128 (val1
->v
.val_unsigned
));
1977 dw2_asm_output_data_uleb128 (r
, NULL
);
1978 dw2_asm_output_data_uleb128 (o
, NULL
);
1981 case DW_OP_GNU_deref_type
:
1983 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
1985 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1986 dw2_asm_output_data_uleb128 (o
, NULL
);
1989 case DW_OP_GNU_convert
:
1990 case DW_OP_GNU_reinterpret
:
1991 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1992 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1995 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
1997 dw2_asm_output_data_uleb128 (o
, NULL
);
2001 case DW_OP_GNU_parameter_ref
:
2004 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2005 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2006 dw2_asm_output_data (4, o
, NULL
);
2011 /* Other codes have no operands. */
2016 /* Output a sequence of location operations.
2017 The for_eh_or_skip parameter controls whether register numbers are
2018 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2019 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2020 info). This should be suppressed for the cases that have not been converted
2021 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2024 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2026 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2028 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2029 /* Output the opcode. */
2030 if (for_eh_or_skip
>= 0
2031 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2033 unsigned r
= (opc
- DW_OP_breg0
);
2034 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2035 gcc_assert (r
<= 31);
2036 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2038 else if (for_eh_or_skip
>= 0
2039 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2041 unsigned r
= (opc
- DW_OP_reg0
);
2042 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2043 gcc_assert (r
<= 31);
2044 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2047 dw2_asm_output_data (1, opc
,
2048 "%s", dwarf_stack_op_name (opc
));
2050 /* Output the operand(s) (if any). */
2051 output_loc_operands (loc
, for_eh_or_skip
);
2055 /* Output location description stack opcode's operands (if any).
2056 The output is single bytes on a line, suitable for .cfi_escape. */
2059 output_loc_operands_raw (dw_loc_descr_ref loc
)
2061 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2062 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2064 switch (loc
->dw_loc_opc
)
2067 case DW_OP_implicit_value
:
2068 /* We cannot output addresses in .cfi_escape, only bytes. */
2074 case DW_OP_deref_size
:
2075 case DW_OP_xderef_size
:
2076 fputc (',', asm_out_file
);
2077 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2082 fputc (',', asm_out_file
);
2083 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2088 fputc (',', asm_out_file
);
2089 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2094 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2095 fputc (',', asm_out_file
);
2096 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2104 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2105 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2107 fputc (',', asm_out_file
);
2108 dw2_asm_output_data_raw (2, offset
);
2114 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2115 gcc_assert (size_of_uleb128 (r
)
2116 == size_of_uleb128 (val1
->v
.val_unsigned
));
2117 fputc (',', asm_out_file
);
2118 dw2_asm_output_data_uleb128_raw (r
);
2123 case DW_OP_plus_uconst
:
2125 fputc (',', asm_out_file
);
2126 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2129 case DW_OP_bit_piece
:
2130 fputc (',', asm_out_file
);
2131 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2132 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2169 fputc (',', asm_out_file
);
2170 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2175 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2176 gcc_assert (size_of_uleb128 (r
)
2177 == size_of_uleb128 (val1
->v
.val_unsigned
));
2178 fputc (',', asm_out_file
);
2179 dw2_asm_output_data_uleb128_raw (r
);
2180 fputc (',', asm_out_file
);
2181 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2185 case DW_OP_GNU_implicit_pointer
:
2186 case DW_OP_GNU_entry_value
:
2187 case DW_OP_GNU_const_type
:
2188 case DW_OP_GNU_regval_type
:
2189 case DW_OP_GNU_deref_type
:
2190 case DW_OP_GNU_convert
:
2191 case DW_OP_GNU_reinterpret
:
2192 case DW_OP_GNU_parameter_ref
:
2197 /* Other codes have no operands. */
2203 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2207 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2208 /* Output the opcode. */
2209 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2211 unsigned r
= (opc
- DW_OP_breg0
);
2212 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2213 gcc_assert (r
<= 31);
2214 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2216 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2218 unsigned r
= (opc
- DW_OP_reg0
);
2219 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2220 gcc_assert (r
<= 31);
2221 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2223 /* Output the opcode. */
2224 fprintf (asm_out_file
, "%#x", opc
);
2225 output_loc_operands_raw (loc
);
2227 if (!loc
->dw_loc_next
)
2229 loc
= loc
->dw_loc_next
;
2231 fputc (',', asm_out_file
);
2235 /* This function builds a dwarf location descriptor sequence from a
2236 dw_cfa_location, adding the given OFFSET to the result of the
2239 struct dw_loc_descr_struct
*
2240 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2242 struct dw_loc_descr_struct
*head
, *tmp
;
2244 offset
+= cfa
->offset
;
2248 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2249 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2250 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2251 add_loc_descr (&head
, tmp
);
2254 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2255 add_loc_descr (&head
, tmp
);
2259 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2264 /* This function builds a dwarf location descriptor sequence for
2265 the address at OFFSET from the CFA when stack is aligned to
2268 struct dw_loc_descr_struct
*
2269 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2270 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2272 struct dw_loc_descr_struct
*head
;
2273 unsigned int dwarf_fp
2274 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2276 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2277 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2279 head
= new_reg_loc_descr (dwarf_fp
, 0);
2280 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2281 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2282 loc_descr_plus_const (&head
, offset
);
2285 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2289 /* And now, the support for symbolic debugging information. */
2291 /* .debug_str support. */
2292 static int output_indirect_string (void **, void *);
2294 static void dwarf2out_init (const char *);
2295 static void dwarf2out_finish (const char *);
2296 static void dwarf2out_assembly_start (void);
2297 static void dwarf2out_define (unsigned int, const char *);
2298 static void dwarf2out_undef (unsigned int, const char *);
2299 static void dwarf2out_start_source_file (unsigned, const char *);
2300 static void dwarf2out_end_source_file (unsigned);
2301 static void dwarf2out_function_decl (tree
);
2302 static void dwarf2out_begin_block (unsigned, unsigned);
2303 static void dwarf2out_end_block (unsigned, unsigned);
2304 static bool dwarf2out_ignore_block (const_tree
);
2305 static void dwarf2out_global_decl (tree
);
2306 static void dwarf2out_type_decl (tree
, int);
2307 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2308 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2310 static void dwarf2out_abstract_function (tree
);
2311 static void dwarf2out_var_location (rtx
);
2312 static void dwarf2out_begin_function (tree
);
2313 static void dwarf2out_set_name (tree
, tree
);
2315 /* The debug hooks structure. */
2317 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2321 dwarf2out_assembly_start
,
2324 dwarf2out_start_source_file
,
2325 dwarf2out_end_source_file
,
2326 dwarf2out_begin_block
,
2327 dwarf2out_end_block
,
2328 dwarf2out_ignore_block
,
2329 dwarf2out_source_line
,
2330 dwarf2out_begin_prologue
,
2331 #if VMS_DEBUGGING_INFO
2332 dwarf2out_vms_end_prologue
,
2333 dwarf2out_vms_begin_epilogue
,
2335 debug_nothing_int_charstar
,
2336 debug_nothing_int_charstar
,
2338 dwarf2out_end_epilogue
,
2339 dwarf2out_begin_function
,
2340 debug_nothing_int
, /* end_function */
2341 dwarf2out_function_decl
, /* function_decl */
2342 dwarf2out_global_decl
,
2343 dwarf2out_type_decl
, /* type_decl */
2344 dwarf2out_imported_module_or_decl
,
2345 debug_nothing_tree
, /* deferred_inline_function */
2346 /* The DWARF 2 backend tries to reduce debugging bloat by not
2347 emitting the abstract description of inline functions until
2348 something tries to reference them. */
2349 dwarf2out_abstract_function
, /* outlining_inline_function */
2350 debug_nothing_rtx
, /* label */
2351 debug_nothing_int
, /* handle_pch */
2352 dwarf2out_var_location
,
2353 dwarf2out_switch_text_section
,
2355 1, /* start_end_main_source_file */
2356 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2359 /* NOTE: In the comments in this file, many references are made to
2360 "Debugging Information Entries". This term is abbreviated as `DIE'
2361 throughout the remainder of this file. */
2363 /* An internal representation of the DWARF output is built, and then
2364 walked to generate the DWARF debugging info. The walk of the internal
2365 representation is done after the entire program has been compiled.
2366 The types below are used to describe the internal representation. */
2368 /* Whether to put type DIEs into their own section .debug_types instead
2369 of making them part of the .debug_info section. Only supported for
2370 Dwarf V4 or higher and the user didn't disable them through
2371 -fno-debug-types-section. It is more efficient to put them in a
2372 separate comdat sections since the linker will then be able to
2373 remove duplicates. But not all tools support .debug_types sections
2376 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2378 /* Various DIE's use offsets relative to the beginning of the
2379 .debug_info section to refer to each other. */
2381 typedef long int dw_offset
;
2383 /* Define typedefs here to avoid circular dependencies. */
2385 typedef struct dw_attr_struct
*dw_attr_ref
;
2386 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2387 typedef struct pubname_struct
*pubname_ref
;
2388 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2389 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2390 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2392 /* The entries in the line_info table more-or-less mirror the opcodes
2393 that are used in the real dwarf line table. Arrays of these entries
2394 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2397 enum dw_line_info_opcode
{
2398 /* Emit DW_LNE_set_address; the operand is the label index. */
2401 /* Emit a row to the matrix with the given line. This may be done
2402 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2406 /* Emit a DW_LNS_set_file. */
2409 /* Emit a DW_LNS_set_column. */
2412 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2415 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2416 LI_set_prologue_end
,
2417 LI_set_epilogue_begin
,
2419 /* Emit a DW_LNE_set_discriminator. */
2420 LI_set_discriminator
2423 typedef struct GTY(()) dw_line_info_struct
{
2424 enum dw_line_info_opcode opcode
;
2426 } dw_line_info_entry
;
2428 DEF_VEC_O(dw_line_info_entry
);
2429 DEF_VEC_ALLOC_O(dw_line_info_entry
, gc
);
2431 typedef struct GTY(()) dw_line_info_table_struct
{
2432 /* The label that marks the end of this section. */
2433 const char *end_label
;
2435 /* The values for the last row of the matrix, as collected in the table.
2436 These are used to minimize the changes to the next row. */
2437 unsigned int file_num
;
2438 unsigned int line_num
;
2439 unsigned int column_num
;
2444 VEC(dw_line_info_entry
, gc
) *entries
;
2445 } dw_line_info_table
;
2447 typedef dw_line_info_table
*dw_line_info_table_p
;
2449 DEF_VEC_P(dw_line_info_table_p
);
2450 DEF_VEC_ALLOC_P(dw_line_info_table_p
, gc
);
2452 /* Each DIE attribute has a field specifying the attribute kind,
2453 a link to the next attribute in the chain, and an attribute value.
2454 Attributes are typically linked below the DIE they modify. */
2456 typedef struct GTY(()) dw_attr_struct
{
2457 enum dwarf_attribute dw_attr
;
2458 dw_val_node dw_attr_val
;
2462 DEF_VEC_O(dw_attr_node
);
2463 DEF_VEC_ALLOC_O(dw_attr_node
,gc
);
2465 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2466 The children of each node form a circular list linked by
2467 die_sib. die_child points to the node *before* the "first" child node. */
2469 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
2470 union die_symbol_or_type_node
2472 const char * GTY ((tag ("0"))) die_symbol
;
2473 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2475 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2476 VEC(dw_attr_node
,gc
) * die_attr
;
2477 dw_die_ref die_parent
;
2478 dw_die_ref die_child
;
2480 dw_die_ref die_definition
; /* ref from a specification to its definition */
2481 dw_offset die_offset
;
2482 unsigned long die_abbrev
;
2484 unsigned int decl_id
;
2485 enum dwarf_tag die_tag
;
2486 /* Die is used and must not be pruned as unused. */
2487 BOOL_BITFIELD die_perennial_p
: 1;
2488 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2489 /* Lots of spare bits. */
2493 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2494 #define FOR_EACH_CHILD(die, c, expr) do { \
2495 c = die->die_child; \
2499 } while (c != die->die_child); \
2502 /* The pubname structure */
2504 typedef struct GTY(()) pubname_struct
{
2510 DEF_VEC_O(pubname_entry
);
2511 DEF_VEC_ALLOC_O(pubname_entry
, gc
);
2513 struct GTY(()) dw_ranges_struct
{
2514 /* If this is positive, it's a block number, otherwise it's a
2515 bitwise-negated index into dw_ranges_by_label. */
2519 /* A structure to hold a macinfo entry. */
2521 typedef struct GTY(()) macinfo_struct
{
2523 unsigned HOST_WIDE_INT lineno
;
2528 DEF_VEC_O(macinfo_entry
);
2529 DEF_VEC_ALLOC_O(macinfo_entry
, gc
);
2531 struct GTY(()) dw_ranges_by_label_struct
{
2536 /* The comdat type node structure. */
2537 typedef struct GTY(()) comdat_type_struct
2539 dw_die_ref root_die
;
2540 dw_die_ref type_die
;
2541 dw_die_ref skeleton_die
;
2542 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2543 struct comdat_type_struct
*next
;
2547 /* The limbo die list structure. */
2548 typedef struct GTY(()) limbo_die_struct
{
2551 struct limbo_die_struct
*next
;
2555 typedef struct skeleton_chain_struct
2559 struct skeleton_chain_struct
*parent
;
2561 skeleton_chain_node
;
2563 /* Define a macro which returns nonzero for a TYPE_DECL which was
2564 implicitly generated for a type.
2566 Note that, unlike the C front-end (which generates a NULL named
2567 TYPE_DECL node for each complete tagged type, each array type,
2568 and each function type node created) the C++ front-end generates
2569 a _named_ TYPE_DECL node for each tagged type node created.
2570 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2571 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2572 front-end, but for each type, tagged or not. */
2574 #define TYPE_DECL_IS_STUB(decl) \
2575 (DECL_NAME (decl) == NULL_TREE \
2576 || (DECL_ARTIFICIAL (decl) \
2577 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2578 /* This is necessary for stub decls that \
2579 appear in nested inline functions. */ \
2580 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2581 && (decl_ultimate_origin (decl) \
2582 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2584 /* Information concerning the compilation unit's programming
2585 language, and compiler version. */
2587 /* Fixed size portion of the DWARF compilation unit header. */
2588 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2589 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2591 /* Fixed size portion of the DWARF comdat type unit header. */
2592 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2593 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2594 + DWARF_OFFSET_SIZE)
2596 /* Fixed size portion of public names info. */
2597 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2599 /* Fixed size portion of the address range info. */
2600 #define DWARF_ARANGES_HEADER_SIZE \
2601 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2602 DWARF2_ADDR_SIZE * 2) \
2603 - DWARF_INITIAL_LENGTH_SIZE)
2605 /* Size of padding portion in the address range info. It must be
2606 aligned to twice the pointer size. */
2607 #define DWARF_ARANGES_PAD_SIZE \
2608 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2609 DWARF2_ADDR_SIZE * 2) \
2610 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2612 /* Use assembler line directives if available. */
2613 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2614 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2615 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2617 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2621 /* Minimum line offset in a special line info. opcode.
2622 This value was chosen to give a reasonable range of values. */
2623 #define DWARF_LINE_BASE -10
2625 /* First special line opcode - leave room for the standard opcodes. */
2626 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2628 /* Range of line offsets in a special line info. opcode. */
2629 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2631 /* Flag that indicates the initial value of the is_stmt_start flag.
2632 In the present implementation, we do not mark any lines as
2633 the beginning of a source statement, because that information
2634 is not made available by the GCC front-end. */
2635 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2637 /* Maximum number of operations per instruction bundle. */
2638 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2639 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2642 /* This location is used by calc_die_sizes() to keep track
2643 the offset of each DIE within the .debug_info section. */
2644 static unsigned long next_die_offset
;
2646 /* Record the root of the DIE's built for the current compilation unit. */
2647 static GTY(()) dw_die_ref single_comp_unit_die
;
2649 /* A list of type DIEs that have been separated into comdat sections. */
2650 static GTY(()) comdat_type_node
*comdat_type_list
;
2652 /* A list of DIEs with a NULL parent waiting to be relocated. */
2653 static GTY(()) limbo_die_node
*limbo_die_list
;
2655 /* A list of DIEs for which we may have to generate
2656 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2657 static GTY(()) limbo_die_node
*deferred_asm_name
;
2659 /* Filenames referenced by this compilation unit. */
2660 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
2662 /* A hash table of references to DIE's that describe declarations.
2663 The key is a DECL_UID() which is a unique number identifying each decl. */
2664 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
2666 /* A hash table of references to DIE's that describe COMMON blocks.
2667 The key is DECL_UID() ^ die_parent. */
2668 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
2670 typedef struct GTY(()) die_arg_entry_struct
{
2675 DEF_VEC_O(die_arg_entry
);
2676 DEF_VEC_ALLOC_O(die_arg_entry
,gc
);
2678 /* Node of the variable location list. */
2679 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2680 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2681 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2682 in mode of the EXPR_LIST node and first EXPR_LIST operand
2683 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2684 location or NULL for padding. For larger bitsizes,
2685 mode is 0 and first operand is a CONCAT with bitsize
2686 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2687 NULL as second operand. */
2689 const char * GTY (()) label
;
2690 struct var_loc_node
* GTY (()) next
;
2693 /* Variable location list. */
2694 struct GTY (()) var_loc_list_def
{
2695 struct var_loc_node
* GTY (()) first
;
2697 /* Pointer to the last but one or last element of the
2698 chained list. If the list is empty, both first and
2699 last are NULL, if the list contains just one node
2700 or the last node certainly is not redundant, it points
2701 to the last node, otherwise points to the last but one.
2702 Do not mark it for GC because it is marked through the chain. */
2703 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2705 /* Pointer to the last element before section switch,
2706 if NULL, either sections weren't switched or first
2707 is after section switch. */
2708 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2710 /* DECL_UID of the variable decl. */
2711 unsigned int decl_id
;
2713 typedef struct var_loc_list_def var_loc_list
;
2715 /* Call argument location list. */
2716 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2717 rtx
GTY (()) call_arg_loc_note
;
2718 const char * GTY (()) label
;
2719 tree
GTY (()) block
;
2721 rtx
GTY (()) symbol_ref
;
2722 struct call_arg_loc_node
* GTY (()) next
;
2726 /* Table of decl location linked lists. */
2727 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
2729 /* Head and tail of call_arg_loc chain. */
2730 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2731 static struct call_arg_loc_node
*call_arg_loc_last
;
2733 /* Number of call sites in the current function. */
2734 static int call_site_count
= -1;
2735 /* Number of tail call sites in the current function. */
2736 static int tail_call_site_count
= -1;
2738 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2740 static VEC (dw_die_ref
, heap
) *block_map
;
2742 /* A cached location list. */
2743 struct GTY (()) cached_dw_loc_list_def
{
2744 /* The DECL_UID of the decl that this entry describes. */
2745 unsigned int decl_id
;
2747 /* The cached location list. */
2748 dw_loc_list_ref loc_list
;
2750 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2752 /* Table of cached location lists. */
2753 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
2755 /* A pointer to the base of a list of references to DIE's that
2756 are uniquely identified by their tag, presence/absence of
2757 children DIE's, and list of attribute/value pairs. */
2758 static GTY((length ("abbrev_die_table_allocated")))
2759 dw_die_ref
*abbrev_die_table
;
2761 /* Number of elements currently allocated for abbrev_die_table. */
2762 static GTY(()) unsigned abbrev_die_table_allocated
;
2764 /* Number of elements in type_die_table currently in use. */
2765 static GTY(()) unsigned abbrev_die_table_in_use
;
2767 /* Size (in elements) of increments by which we may expand the
2768 abbrev_die_table. */
2769 #define ABBREV_DIE_TABLE_INCREMENT 256
2771 /* A global counter for generating labels for line number data. */
2772 static unsigned int line_info_label_num
;
2774 /* The current table to which we should emit line number information
2775 for the current function. This will be set up at the beginning of
2776 assembly for the function. */
2777 static dw_line_info_table
*cur_line_info_table
;
2779 /* The two default tables of line number info. */
2780 static GTY(()) dw_line_info_table
*text_section_line_info
;
2781 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2783 /* The set of all non-default tables of line number info. */
2784 static GTY(()) VEC (dw_line_info_table_p
, gc
) *separate_line_info
;
2786 /* A flag to tell pubnames/types export if there is an info section to
2788 static bool info_section_emitted
;
2790 /* A pointer to the base of a table that contains a list of publicly
2791 accessible names. */
2792 static GTY (()) VEC (pubname_entry
, gc
) * pubname_table
;
2794 /* A pointer to the base of a table that contains a list of publicly
2795 accessible types. */
2796 static GTY (()) VEC (pubname_entry
, gc
) * pubtype_table
;
2798 /* A pointer to the base of a table that contains a list of macro
2799 defines/undefines (and file start/end markers). */
2800 static GTY (()) VEC (macinfo_entry
, gc
) * macinfo_table
;
2802 /* True if .debug_macinfo or .debug_macros section is going to be
2804 #define have_macinfo \
2805 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2806 && !VEC_empty (macinfo_entry, macinfo_table))
2808 /* Array of dies for which we should generate .debug_ranges info. */
2809 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2811 /* Number of elements currently allocated for ranges_table. */
2812 static GTY(()) unsigned ranges_table_allocated
;
2814 /* Number of elements in ranges_table currently in use. */
2815 static GTY(()) unsigned ranges_table_in_use
;
2817 /* Array of pairs of labels referenced in ranges_table. */
2818 static GTY ((length ("ranges_by_label_allocated")))
2819 dw_ranges_by_label_ref ranges_by_label
;
2821 /* Number of elements currently allocated for ranges_by_label. */
2822 static GTY(()) unsigned ranges_by_label_allocated
;
2824 /* Number of elements in ranges_by_label currently in use. */
2825 static GTY(()) unsigned ranges_by_label_in_use
;
2827 /* Size (in elements) of increments by which we may expand the
2829 #define RANGES_TABLE_INCREMENT 64
2831 /* Whether we have location lists that need outputting */
2832 static GTY(()) bool have_location_lists
;
2834 /* Unique label counter. */
2835 static GTY(()) unsigned int loclabel_num
;
2837 /* Unique label counter for point-of-call tables. */
2838 static GTY(()) unsigned int poc_label_num
;
2840 /* Record whether the function being analyzed contains inlined functions. */
2841 static int current_function_has_inlines
;
2843 /* The last file entry emitted by maybe_emit_file(). */
2844 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
2846 /* Number of internal labels generated by gen_internal_sym(). */
2847 static GTY(()) int label_num
;
2849 /* Cached result of previous call to lookup_filename. */
2850 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
2852 static GTY(()) VEC(die_arg_entry
,gc
) *tmpl_value_parm_die_table
;
2854 /* Instances of generic types for which we need to generate debug
2855 info that describe their generic parameters and arguments. That
2856 generation needs to happen once all types are properly laid out so
2857 we do it at the end of compilation. */
2858 static GTY(()) VEC(tree
,gc
) *generic_type_instances
;
2860 /* Offset from the "steady-state frame pointer" to the frame base,
2861 within the current function. */
2862 static HOST_WIDE_INT frame_pointer_fb_offset
;
2863 static bool frame_pointer_fb_offset_valid
;
2865 static VEC (dw_die_ref
, heap
) *base_types
;
2867 /* Forward declarations for functions defined in this file. */
2869 static int is_pseudo_reg (const_rtx
);
2870 static tree
type_main_variant (tree
);
2871 static int is_tagged_type (const_tree
);
2872 static const char *dwarf_tag_name (unsigned);
2873 static const char *dwarf_attr_name (unsigned);
2874 static const char *dwarf_form_name (unsigned);
2875 static tree
decl_ultimate_origin (const_tree
);
2876 static tree
decl_class_context (tree
);
2877 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
2878 static inline enum dw_val_class
AT_class (dw_attr_ref
);
2879 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
2880 static inline unsigned AT_flag (dw_attr_ref
);
2881 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
2882 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
2883 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
2884 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
2885 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
2886 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2887 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
2888 unsigned int, unsigned char *);
2889 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
2890 static hashval_t
debug_str_do_hash (const void *);
2891 static int debug_str_eq (const void *, const void *);
2892 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
2893 static inline const char *AT_string (dw_attr_ref
);
2894 static enum dwarf_form
AT_string_form (dw_attr_ref
);
2895 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
2896 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
2897 static inline dw_die_ref
AT_ref (dw_attr_ref
);
2898 static inline int AT_ref_external (dw_attr_ref
);
2899 static inline void set_AT_ref_external (dw_attr_ref
, int);
2900 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
2901 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
2902 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
2903 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
2905 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
2906 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
2907 static inline rtx
AT_addr (dw_attr_ref
);
2908 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
2909 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2910 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2911 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
2912 unsigned HOST_WIDE_INT
);
2913 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
2915 static inline const char *AT_lbl (dw_attr_ref
);
2916 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
2917 static const char *get_AT_low_pc (dw_die_ref
);
2918 static const char *get_AT_hi_pc (dw_die_ref
);
2919 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
2920 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
2921 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
2922 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
2923 static bool is_cxx (void);
2924 static bool is_fortran (void);
2925 static bool is_ada (void);
2926 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
2927 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
2928 static void add_child_die (dw_die_ref
, dw_die_ref
);
2929 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
2930 static dw_die_ref
lookup_type_die (tree
);
2931 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
2932 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
2933 static void equate_type_number_to_die (tree
, dw_die_ref
);
2934 static hashval_t
decl_die_table_hash (const void *);
2935 static int decl_die_table_eq (const void *, const void *);
2936 static dw_die_ref
lookup_decl_die (tree
);
2937 static hashval_t
common_block_die_table_hash (const void *);
2938 static int common_block_die_table_eq (const void *, const void *);
2939 static hashval_t
decl_loc_table_hash (const void *);
2940 static int decl_loc_table_eq (const void *, const void *);
2941 static var_loc_list
*lookup_decl_loc (const_tree
);
2942 static void equate_decl_number_to_die (tree
, dw_die_ref
);
2943 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
2944 static void print_spaces (FILE *);
2945 static void print_die (dw_die_ref
, FILE *);
2946 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
2947 static dw_die_ref
pop_compile_unit (dw_die_ref
);
2948 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
2949 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
2950 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
2951 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
2952 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
2953 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
2954 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
2955 struct md5_ctx
*, int *);
2956 struct checksum_attributes
;
2957 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
2958 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
2959 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
2960 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
2961 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
2962 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
2963 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
2964 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
2965 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
2966 static void compute_section_prefix (dw_die_ref
);
2967 static int is_type_die (dw_die_ref
);
2968 static int is_comdat_die (dw_die_ref
);
2969 static int is_symbol_die (dw_die_ref
);
2970 static void assign_symbol_names (dw_die_ref
);
2971 static void break_out_includes (dw_die_ref
);
2972 static int is_declaration_die (dw_die_ref
);
2973 static int should_move_die_to_comdat (dw_die_ref
);
2974 static dw_die_ref
clone_as_declaration (dw_die_ref
);
2975 static dw_die_ref
clone_die (dw_die_ref
);
2976 static dw_die_ref
clone_tree (dw_die_ref
);
2977 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
2978 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
2979 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
2980 static dw_die_ref
generate_skeleton (dw_die_ref
);
2981 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
2984 static void break_out_comdat_types (dw_die_ref
);
2985 static dw_die_ref
copy_ancestor_tree (dw_die_ref
, dw_die_ref
, htab_t
);
2986 static void copy_decls_walk (dw_die_ref
, dw_die_ref
, htab_t
);
2987 static void copy_decls_for_unworthy_types (dw_die_ref
);
2989 static hashval_t
htab_cu_hash (const void *);
2990 static int htab_cu_eq (const void *, const void *);
2991 static void htab_cu_del (void *);
2992 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
2993 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
2994 static void add_sibling_attributes (dw_die_ref
);
2995 static void build_abbrev_table (dw_die_ref
, htab_t
);
2996 static void output_location_lists (dw_die_ref
);
2997 static int constant_size (unsigned HOST_WIDE_INT
);
2998 static unsigned long size_of_die (dw_die_ref
);
2999 static void calc_die_sizes (dw_die_ref
);
3000 static void calc_base_type_die_sizes (void);
3001 static void mark_dies (dw_die_ref
);
3002 static void unmark_dies (dw_die_ref
);
3003 static void unmark_all_dies (dw_die_ref
);
3004 static unsigned long size_of_pubnames (VEC (pubname_entry
,gc
) *);
3005 static unsigned long size_of_aranges (void);
3006 static enum dwarf_form
value_format (dw_attr_ref
);
3007 static void output_value_format (dw_attr_ref
);
3008 static void output_abbrev_section (void);
3009 static void output_die_symbol (dw_die_ref
);
3010 static void output_die (dw_die_ref
);
3011 static void output_compilation_unit_header (void);
3012 static void output_comp_unit (dw_die_ref
, int);
3013 static void output_comdat_type_unit (comdat_type_node
*);
3014 static const char *dwarf2_name (tree
, int);
3015 static void add_pubname (tree
, dw_die_ref
);
3016 static void add_enumerator_pubname (const char *, dw_die_ref
);
3017 static void add_pubname_string (const char *, dw_die_ref
);
3018 static void add_pubtype (tree
, dw_die_ref
);
3019 static void output_pubnames (VEC (pubname_entry
,gc
) *);
3020 static void output_aranges (unsigned long);
3021 static unsigned int add_ranges_num (int);
3022 static unsigned int add_ranges (const_tree
);
3023 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3025 static void output_ranges (void);
3026 static dw_line_info_table
*new_line_info_table (void);
3027 static void output_line_info (void);
3028 static void output_file_names (void);
3029 static dw_die_ref
base_type_die (tree
);
3030 static int is_base_type (tree
);
3031 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3032 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3033 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3034 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3035 static int type_is_enum (const_tree
);
3036 static unsigned int dbx_reg_number (const_rtx
);
3037 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3038 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3039 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3040 enum var_init_status
);
3041 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3042 enum var_init_status
);
3043 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3044 enum var_init_status
);
3045 static int is_based_loc (const_rtx
);
3046 static int resolve_one_addr (rtx
*, void *);
3047 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3048 enum var_init_status
);
3049 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
3050 enum var_init_status
);
3051 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3052 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3053 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3054 static tree
field_type (const_tree
);
3055 static unsigned int simple_type_align_in_bits (const_tree
);
3056 static unsigned int simple_decl_align_in_bits (const_tree
);
3057 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3058 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3059 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3061 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3062 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3063 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3064 static void insert_double (double_int
, unsigned char *);
3065 static void insert_float (const_rtx
, unsigned char *);
3066 static rtx
rtl_for_decl_location (tree
);
3067 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3068 enum dwarf_attribute
);
3069 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3070 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3071 static void add_name_attribute (dw_die_ref
, const char *);
3072 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3073 static void add_comp_dir_attribute (dw_die_ref
);
3074 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3075 static void add_subscript_info (dw_die_ref
, tree
, bool);
3076 static void add_byte_size_attribute (dw_die_ref
, tree
);
3077 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3078 static void add_bit_size_attribute (dw_die_ref
, tree
);
3079 static void add_prototyped_attribute (dw_die_ref
, tree
);
3080 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3081 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3082 static void add_src_coords_attributes (dw_die_ref
, tree
);
3083 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3084 static void push_decl_scope (tree
);
3085 static void pop_decl_scope (void);
3086 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3087 static inline int local_scope_p (dw_die_ref
);
3088 static inline int class_scope_p (dw_die_ref
);
3089 static inline int class_or_namespace_scope_p (dw_die_ref
);
3090 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3091 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3092 static const char *type_tag (const_tree
);
3093 static tree
member_declared_type (const_tree
);
3095 static const char *decl_start_label (tree
);
3097 static void gen_array_type_die (tree
, dw_die_ref
);
3098 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3100 static void gen_entry_point_die (tree
, dw_die_ref
);
3102 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3103 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3104 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3105 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3106 static void gen_formal_types_die (tree
, dw_die_ref
);
3107 static void gen_subprogram_die (tree
, dw_die_ref
);
3108 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3109 static void gen_const_die (tree
, dw_die_ref
);
3110 static void gen_label_die (tree
, dw_die_ref
);
3111 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3112 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3113 static void gen_field_die (tree
, dw_die_ref
);
3114 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3115 static dw_die_ref
gen_compile_unit_die (const char *);
3116 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3117 static void gen_member_die (tree
, dw_die_ref
);
3118 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3119 enum debug_info_usage
);
3120 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3121 static void gen_typedef_die (tree
, dw_die_ref
);
3122 static void gen_type_die (tree
, dw_die_ref
);
3123 static void gen_block_die (tree
, dw_die_ref
, int);
3124 static void decls_for_scope (tree
, dw_die_ref
, int);
3125 static inline int is_redundant_typedef (const_tree
);
3126 static bool is_naming_typedef_decl (const_tree
);
3127 static inline dw_die_ref
get_context_die (tree
);
3128 static void gen_namespace_die (tree
, dw_die_ref
);
3129 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3130 static dw_die_ref
force_decl_die (tree
);
3131 static dw_die_ref
force_type_die (tree
);
3132 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3133 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3134 static struct dwarf_file_data
* lookup_filename (const char *);
3135 static void retry_incomplete_types (void);
3136 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3137 static void gen_generic_params_dies (tree
);
3138 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3139 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3140 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3141 static int file_info_cmp (const void *, const void *);
3142 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3143 const char *, const char *);
3144 static void output_loc_list (dw_loc_list_ref
);
3145 static char *gen_internal_sym (const char *);
3146 static bool want_pubnames (void);
3148 static void prune_unmark_dies (dw_die_ref
);
3149 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3150 static void prune_unused_types_mark (dw_die_ref
, int);
3151 static void prune_unused_types_walk (dw_die_ref
);
3152 static void prune_unused_types_walk_attribs (dw_die_ref
);
3153 static void prune_unused_types_prune (dw_die_ref
);
3154 static void prune_unused_types (void);
3155 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3156 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3157 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3158 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3159 const char *, const char *);
3160 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3161 static void gen_remaining_tmpl_value_param_die_attribute (void);
3162 static bool generic_type_p (tree
);
3163 static void schedule_generic_params_dies_gen (tree t
);
3164 static void gen_scheduled_generic_parms_dies (void);
3166 /* Section names used to hold DWARF debugging information. */
3167 #ifndef DEBUG_INFO_SECTION
3168 #define DEBUG_INFO_SECTION ".debug_info"
3170 #ifndef DEBUG_ABBREV_SECTION
3171 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3173 #ifndef DEBUG_ARANGES_SECTION
3174 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3176 #ifndef DEBUG_MACINFO_SECTION
3177 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3179 #ifndef DEBUG_MACRO_SECTION
3180 #define DEBUG_MACRO_SECTION ".debug_macro"
3182 #ifndef DEBUG_LINE_SECTION
3183 #define DEBUG_LINE_SECTION ".debug_line"
3185 #ifndef DEBUG_LOC_SECTION
3186 #define DEBUG_LOC_SECTION ".debug_loc"
3188 #ifndef DEBUG_PUBNAMES_SECTION
3189 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3191 #ifndef DEBUG_PUBTYPES_SECTION
3192 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
3194 #ifndef DEBUG_STR_SECTION
3195 #define DEBUG_STR_SECTION ".debug_str"
3197 #ifndef DEBUG_RANGES_SECTION
3198 #define DEBUG_RANGES_SECTION ".debug_ranges"
3201 /* Standard ELF section names for compiled code and data. */
3202 #ifndef TEXT_SECTION_NAME
3203 #define TEXT_SECTION_NAME ".text"
3206 /* Section flags for .debug_str section. */
3207 #define DEBUG_STR_SECTION_FLAGS \
3208 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3209 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3212 /* Labels we insert at beginning sections we can reference instead of
3213 the section names themselves. */
3215 #ifndef TEXT_SECTION_LABEL
3216 #define TEXT_SECTION_LABEL "Ltext"
3218 #ifndef COLD_TEXT_SECTION_LABEL
3219 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3221 #ifndef DEBUG_LINE_SECTION_LABEL
3222 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3224 #ifndef DEBUG_INFO_SECTION_LABEL
3225 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3227 #ifndef DEBUG_ABBREV_SECTION_LABEL
3228 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3230 #ifndef DEBUG_LOC_SECTION_LABEL
3231 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3233 #ifndef DEBUG_RANGES_SECTION_LABEL
3234 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3236 #ifndef DEBUG_MACINFO_SECTION_LABEL
3237 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3239 #ifndef DEBUG_MACRO_SECTION_LABEL
3240 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3244 /* Definitions of defaults for formats and names of various special
3245 (artificial) labels which may be generated within this file (when the -g
3246 options is used and DWARF2_DEBUGGING_INFO is in effect.
3247 If necessary, these may be overridden from within the tm.h file, but
3248 typically, overriding these defaults is unnecessary. */
3250 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3251 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3252 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3253 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3254 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3255 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3256 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3257 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3258 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3259 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3261 #ifndef TEXT_END_LABEL
3262 #define TEXT_END_LABEL "Letext"
3264 #ifndef COLD_END_LABEL
3265 #define COLD_END_LABEL "Letext_cold"
3267 #ifndef BLOCK_BEGIN_LABEL
3268 #define BLOCK_BEGIN_LABEL "LBB"
3270 #ifndef BLOCK_END_LABEL
3271 #define BLOCK_END_LABEL "LBE"
3273 #ifndef LINE_CODE_LABEL
3274 #define LINE_CODE_LABEL "LM"
3278 /* Return the root of the DIE's built for the current compilation unit. */
3280 comp_unit_die (void)
3282 if (!single_comp_unit_die
)
3283 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3284 return single_comp_unit_die
;
3287 /* We allow a language front-end to designate a function that is to be
3288 called to "demangle" any name before it is put into a DIE. */
3290 static const char *(*demangle_name_func
) (const char *);
3293 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3295 demangle_name_func
= func
;
3298 /* Test if rtl node points to a pseudo register. */
3301 is_pseudo_reg (const_rtx rtl
)
3303 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3304 || (GET_CODE (rtl
) == SUBREG
3305 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3308 /* Return a reference to a type, with its const and volatile qualifiers
3312 type_main_variant (tree type
)
3314 type
= TYPE_MAIN_VARIANT (type
);
3316 /* ??? There really should be only one main variant among any group of
3317 variants of a given type (and all of the MAIN_VARIANT values for all
3318 members of the group should point to that one type) but sometimes the C
3319 front-end messes this up for array types, so we work around that bug
3321 if (TREE_CODE (type
) == ARRAY_TYPE
)
3322 while (type
!= TYPE_MAIN_VARIANT (type
))
3323 type
= TYPE_MAIN_VARIANT (type
);
3328 /* Return nonzero if the given type node represents a tagged type. */
3331 is_tagged_type (const_tree type
)
3333 enum tree_code code
= TREE_CODE (type
);
3335 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3336 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3339 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3342 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3344 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3347 /* Return die_offset of a DIE reference to a base type. */
3349 static unsigned long int
3350 get_base_type_offset (dw_die_ref ref
)
3352 if (ref
->die_offset
)
3353 return ref
->die_offset
;
3354 if (comp_unit_die ()->die_abbrev
)
3356 calc_base_type_die_sizes ();
3357 gcc_assert (ref
->die_offset
);
3359 return ref
->die_offset
;
3362 /* Return die_offset of a DIE reference other than base type. */
3364 static unsigned long int
3365 get_ref_die_offset (dw_die_ref ref
)
3367 gcc_assert (ref
->die_offset
);
3368 return ref
->die_offset
;
3371 /* Convert a DIE tag into its string name. */
3374 dwarf_tag_name (unsigned int tag
)
3376 const char *name
= get_DW_TAG_name (tag
);
3381 return "DW_TAG_<unknown>";
3384 /* Convert a DWARF attribute code into its string name. */
3387 dwarf_attr_name (unsigned int attr
)
3393 #if VMS_DEBUGGING_INFO
3394 case DW_AT_HP_prologue
:
3395 return "DW_AT_HP_prologue";
3397 case DW_AT_MIPS_loop_unroll_factor
:
3398 return "DW_AT_MIPS_loop_unroll_factor";
3401 #if VMS_DEBUGGING_INFO
3402 case DW_AT_HP_epilogue
:
3403 return "DW_AT_HP_epilogue";
3405 case DW_AT_MIPS_stride
:
3406 return "DW_AT_MIPS_stride";
3410 name
= get_DW_AT_name (attr
);
3415 return "DW_AT_<unknown>";
3418 /* Convert a DWARF value form code into its string name. */
3421 dwarf_form_name (unsigned int form
)
3423 const char *name
= get_DW_FORM_name (form
);
3428 return "DW_FORM_<unknown>";
3431 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3432 instance of an inlined instance of a decl which is local to an inline
3433 function, so we have to trace all of the way back through the origin chain
3434 to find out what sort of node actually served as the original seed for the
3438 decl_ultimate_origin (const_tree decl
)
3440 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3443 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3444 nodes in the function to point to themselves; ignore that if
3445 we're trying to output the abstract instance of this function. */
3446 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3449 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3450 most distant ancestor, this should never happen. */
3451 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3453 return DECL_ABSTRACT_ORIGIN (decl
);
3456 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3457 of a virtual function may refer to a base class, so we check the 'this'
3461 decl_class_context (tree decl
)
3463 tree context
= NULL_TREE
;
3465 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3466 context
= DECL_CONTEXT (decl
);
3468 context
= TYPE_MAIN_VARIANT
3469 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3471 if (context
&& !TYPE_P (context
))
3472 context
= NULL_TREE
;
3477 /* Add an attribute/value pair to a DIE. */
3480 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3482 /* Maybe this should be an assert? */
3486 if (die
->die_attr
== NULL
)
3487 die
->die_attr
= VEC_alloc (dw_attr_node
, gc
, 1);
3488 VEC_safe_push (dw_attr_node
, gc
, die
->die_attr
, attr
);
3491 static inline enum dw_val_class
3492 AT_class (dw_attr_ref a
)
3494 return a
->dw_attr_val
.val_class
;
3497 /* Add a flag value attribute to a DIE. */
3500 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3504 attr
.dw_attr
= attr_kind
;
3505 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3506 attr
.dw_attr_val
.v
.val_flag
= flag
;
3507 add_dwarf_attr (die
, &attr
);
3510 static inline unsigned
3511 AT_flag (dw_attr_ref a
)
3513 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3514 return a
->dw_attr_val
.v
.val_flag
;
3517 /* Add a signed integer attribute value to a DIE. */
3520 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3524 attr
.dw_attr
= attr_kind
;
3525 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3526 attr
.dw_attr_val
.v
.val_int
= int_val
;
3527 add_dwarf_attr (die
, &attr
);
3530 static inline HOST_WIDE_INT
3531 AT_int (dw_attr_ref a
)
3533 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3534 return a
->dw_attr_val
.v
.val_int
;
3537 /* Add an unsigned integer attribute value to a DIE. */
3540 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3541 unsigned HOST_WIDE_INT unsigned_val
)
3545 attr
.dw_attr
= attr_kind
;
3546 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3547 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3548 add_dwarf_attr (die
, &attr
);
3551 static inline unsigned HOST_WIDE_INT
3552 AT_unsigned (dw_attr_ref a
)
3554 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3555 return a
->dw_attr_val
.v
.val_unsigned
;
3558 /* Add an unsigned double integer attribute value to a DIE. */
3561 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3562 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3566 attr
.dw_attr
= attr_kind
;
3567 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3568 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3569 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3570 add_dwarf_attr (die
, &attr
);
3573 /* Add a floating point attribute value to a DIE and return it. */
3576 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3577 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3581 attr
.dw_attr
= attr_kind
;
3582 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3583 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3584 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3585 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3586 add_dwarf_attr (die
, &attr
);
3589 /* Add an 8-byte data attribute value to a DIE. */
3592 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3593 unsigned char data8
[8])
3597 attr
.dw_attr
= attr_kind
;
3598 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3599 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3600 add_dwarf_attr (die
, &attr
);
3603 /* Hash and equality functions for debug_str_hash. */
3606 debug_str_do_hash (const void *x
)
3608 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
3612 debug_str_eq (const void *x1
, const void *x2
)
3614 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
3615 (const char *)x2
) == 0;
3618 /* Add STR to the indirect string hash table. */
3620 static struct indirect_string_node
*
3621 find_AT_string (const char *str
)
3623 struct indirect_string_node
*node
;
3626 if (! debug_str_hash
)
3627 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
3628 debug_str_eq
, NULL
);
3630 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
3631 htab_hash_string (str
), INSERT
);
3634 node
= ggc_alloc_cleared_indirect_string_node ();
3635 node
->str
= ggc_strdup (str
);
3639 node
= (struct indirect_string_node
*) *slot
;
3645 /* Add a string attribute value to a DIE. */
3648 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
3651 struct indirect_string_node
*node
;
3653 node
= find_AT_string (str
);
3655 attr
.dw_attr
= attr_kind
;
3656 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
3657 attr
.dw_attr_val
.v
.val_str
= node
;
3658 add_dwarf_attr (die
, &attr
);
3661 static inline const char *
3662 AT_string (dw_attr_ref a
)
3664 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3665 return a
->dw_attr_val
.v
.val_str
->str
;
3668 /* Find out whether a string should be output inline in DIE
3669 or out-of-line in .debug_str section. */
3671 static enum dwarf_form
3672 AT_string_form (dw_attr_ref a
)
3674 struct indirect_string_node
*node
;
3678 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3680 node
= a
->dw_attr_val
.v
.val_str
;
3684 len
= strlen (node
->str
) + 1;
3686 /* If the string is shorter or equal to the size of the reference, it is
3687 always better to put it inline. */
3688 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
3689 return node
->form
= DW_FORM_string
;
3691 /* If we cannot expect the linker to merge strings in .debug_str
3692 section, only put it into .debug_str if it is worth even in this
3694 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
3695 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
3696 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
3697 return node
->form
= DW_FORM_string
;
3699 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
3700 ++dw2_string_counter
;
3701 node
->label
= xstrdup (label
);
3703 return node
->form
= DW_FORM_strp
;
3706 /* Add a DIE reference attribute value to a DIE. */
3709 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
3713 #ifdef ENABLE_CHECKING
3714 gcc_assert (targ_die
!= NULL
);
3716 /* With LTO we can end up trying to reference something we didn't create
3717 a DIE for. Avoid crashing later on a NULL referenced DIE. */
3718 if (targ_die
== NULL
)
3722 attr
.dw_attr
= attr_kind
;
3723 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
3724 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
3725 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
3726 add_dwarf_attr (die
, &attr
);
3729 /* Change DIE reference REF to point to NEW_DIE instead. */
3732 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
3734 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
3735 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
3736 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
3739 /* Add an AT_specification attribute to a DIE, and also make the back
3740 pointer from the specification to the definition. */
3743 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
3745 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
3746 gcc_assert (!targ_die
->die_definition
);
3747 targ_die
->die_definition
= die
;
3750 static inline dw_die_ref
3751 AT_ref (dw_attr_ref a
)
3753 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
3754 return a
->dw_attr_val
.v
.val_die_ref
.die
;
3758 AT_ref_external (dw_attr_ref a
)
3760 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
3761 return a
->dw_attr_val
.v
.val_die_ref
.external
;
3767 set_AT_ref_external (dw_attr_ref a
, int i
)
3769 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
3770 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
3773 /* Add an FDE reference attribute value to a DIE. */
3776 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
3780 attr
.dw_attr
= attr_kind
;
3781 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
3782 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
3783 add_dwarf_attr (die
, &attr
);
3786 /* Add a location description attribute value to a DIE. */
3789 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
3793 attr
.dw_attr
= attr_kind
;
3794 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
3795 attr
.dw_attr_val
.v
.val_loc
= loc
;
3796 add_dwarf_attr (die
, &attr
);
3799 static inline dw_loc_descr_ref
3800 AT_loc (dw_attr_ref a
)
3802 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
3803 return a
->dw_attr_val
.v
.val_loc
;
3807 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
3811 attr
.dw_attr
= attr_kind
;
3812 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
3813 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
3814 add_dwarf_attr (die
, &attr
);
3815 have_location_lists
= true;
3818 static inline dw_loc_list_ref
3819 AT_loc_list (dw_attr_ref a
)
3821 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
3822 return a
->dw_attr_val
.v
.val_loc_list
;
3825 static inline dw_loc_list_ref
*
3826 AT_loc_list_ptr (dw_attr_ref a
)
3828 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
3829 return &a
->dw_attr_val
.v
.val_loc_list
;
3832 /* Add an address constant attribute value to a DIE. */
3835 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
3839 attr
.dw_attr
= attr_kind
;
3840 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
3841 attr
.dw_attr_val
.v
.val_addr
= addr
;
3842 add_dwarf_attr (die
, &attr
);
3845 /* Get the RTX from to an address DIE attribute. */
3848 AT_addr (dw_attr_ref a
)
3850 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
3851 return a
->dw_attr_val
.v
.val_addr
;
3854 /* Add a file attribute value to a DIE. */
3857 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3858 struct dwarf_file_data
*fd
)
3862 attr
.dw_attr
= attr_kind
;
3863 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
3864 attr
.dw_attr_val
.v
.val_file
= fd
;
3865 add_dwarf_attr (die
, &attr
);
3868 /* Get the dwarf_file_data from a file DIE attribute. */
3870 static inline struct dwarf_file_data
*
3871 AT_file (dw_attr_ref a
)
3873 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
3874 return a
->dw_attr_val
.v
.val_file
;
3877 /* Add a vms delta attribute value to a DIE. */
3880 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3881 const char *lbl1
, const char *lbl2
)
3885 attr
.dw_attr
= attr_kind
;
3886 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
3887 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
3888 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
3889 add_dwarf_attr (die
, &attr
);
3892 /* Add a label identifier attribute value to a DIE. */
3895 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
3899 attr
.dw_attr
= attr_kind
;
3900 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3901 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
3902 add_dwarf_attr (die
, &attr
);
3905 /* Add a section offset attribute value to a DIE, an offset into the
3906 debug_line section. */
3909 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3914 attr
.dw_attr
= attr_kind
;
3915 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
3916 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
3917 add_dwarf_attr (die
, &attr
);
3920 /* Add a section offset attribute value to a DIE, an offset into the
3921 debug_macinfo section. */
3924 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3929 attr
.dw_attr
= attr_kind
;
3930 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
3931 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
3932 add_dwarf_attr (die
, &attr
);
3935 /* Add an offset attribute value to a DIE. */
3938 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3939 unsigned HOST_WIDE_INT offset
)
3943 attr
.dw_attr
= attr_kind
;
3944 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
3945 attr
.dw_attr_val
.v
.val_offset
= offset
;
3946 add_dwarf_attr (die
, &attr
);
3949 /* Add an range_list attribute value to a DIE. */
3952 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3953 long unsigned int offset
)
3957 attr
.dw_attr
= attr_kind
;
3958 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
3959 attr
.dw_attr_val
.v
.val_offset
= offset
;
3960 add_dwarf_attr (die
, &attr
);
3963 /* Return the start label of a delta attribute. */
3965 static inline const char *
3966 AT_vms_delta1 (dw_attr_ref a
)
3968 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
3969 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
3972 /* Return the end label of a delta attribute. */
3974 static inline const char *
3975 AT_vms_delta2 (dw_attr_ref a
)
3977 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
3978 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
3981 static inline const char *
3982 AT_lbl (dw_attr_ref a
)
3984 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
3985 || AT_class (a
) == dw_val_class_lineptr
3986 || AT_class (a
) == dw_val_class_macptr
));
3987 return a
->dw_attr_val
.v
.val_lbl_id
;
3990 /* Get the attribute of type attr_kind. */
3993 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
3997 dw_die_ref spec
= NULL
;
4002 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
4003 if (a
->dw_attr
== attr_kind
)
4005 else if (a
->dw_attr
== DW_AT_specification
4006 || a
->dw_attr
== DW_AT_abstract_origin
)
4010 return get_AT (spec
, attr_kind
);
4015 /* Return the "low pc" attribute value, typically associated with a subprogram
4016 DIE. Return null if the "low pc" attribute is either not present, or if it
4017 cannot be represented as an assembler label identifier. */
4019 static inline const char *
4020 get_AT_low_pc (dw_die_ref die
)
4022 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4024 return a
? AT_lbl (a
) : NULL
;
4027 /* Return the "high pc" attribute value, typically associated with a subprogram
4028 DIE. Return null if the "high pc" attribute is either not present, or if it
4029 cannot be represented as an assembler label identifier. */
4031 static inline const char *
4032 get_AT_hi_pc (dw_die_ref die
)
4034 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4036 return a
? AT_lbl (a
) : NULL
;
4039 /* Return the value of the string attribute designated by ATTR_KIND, or
4040 NULL if it is not present. */
4042 static inline const char *
4043 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4045 dw_attr_ref a
= get_AT (die
, attr_kind
);
4047 return a
? AT_string (a
) : NULL
;
4050 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4051 if it is not present. */
4054 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4056 dw_attr_ref a
= get_AT (die
, attr_kind
);
4058 return a
? AT_flag (a
) : 0;
4061 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4062 if it is not present. */
4064 static inline unsigned
4065 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4067 dw_attr_ref a
= get_AT (die
, attr_kind
);
4069 return a
? AT_unsigned (a
) : 0;
4072 static inline dw_die_ref
4073 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4075 dw_attr_ref a
= get_AT (die
, attr_kind
);
4077 return a
? AT_ref (a
) : NULL
;
4080 static inline struct dwarf_file_data
*
4081 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4083 dw_attr_ref a
= get_AT (die
, attr_kind
);
4085 return a
? AT_file (a
) : NULL
;
4088 /* Return TRUE if the language is C++. */
4093 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4095 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4098 /* Return TRUE if the language is Fortran. */
4103 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4105 return (lang
== DW_LANG_Fortran77
4106 || lang
== DW_LANG_Fortran90
4107 || lang
== DW_LANG_Fortran95
);
4110 /* Return TRUE if the language is Ada. */
4115 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4117 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4120 /* Remove the specified attribute if present. */
4123 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4131 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
4132 if (a
->dw_attr
== attr_kind
)
4134 if (AT_class (a
) == dw_val_class_str
)
4135 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4136 a
->dw_attr_val
.v
.val_str
->refcount
--;
4138 /* VEC_ordered_remove should help reduce the number of abbrevs
4140 VEC_ordered_remove (dw_attr_node
, die
->die_attr
, ix
);
4145 /* Remove CHILD from its parent. PREV must have the property that
4146 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4149 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4151 gcc_assert (child
->die_parent
== prev
->die_parent
);
4152 gcc_assert (prev
->die_sib
== child
);
4155 gcc_assert (child
->die_parent
->die_child
== child
);
4159 prev
->die_sib
= child
->die_sib
;
4160 if (child
->die_parent
->die_child
== child
)
4161 child
->die_parent
->die_child
= prev
;
4164 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4165 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4168 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4170 dw_die_ref parent
= old_child
->die_parent
;
4172 gcc_assert (parent
== prev
->die_parent
);
4173 gcc_assert (prev
->die_sib
== old_child
);
4175 new_child
->die_parent
= parent
;
4176 if (prev
== old_child
)
4178 gcc_assert (parent
->die_child
== old_child
);
4179 new_child
->die_sib
= new_child
;
4183 prev
->die_sib
= new_child
;
4184 new_child
->die_sib
= old_child
->die_sib
;
4186 if (old_child
->die_parent
->die_child
== old_child
)
4187 old_child
->die_parent
->die_child
= new_child
;
4190 /* Move all children from OLD_PARENT to NEW_PARENT. */
4193 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4196 new_parent
->die_child
= old_parent
->die_child
;
4197 old_parent
->die_child
= NULL
;
4198 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4201 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4205 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4211 dw_die_ref prev
= c
;
4213 while (c
->die_tag
== tag
)
4215 remove_child_with_prev (c
, prev
);
4216 /* Might have removed every child. */
4217 if (c
== c
->die_sib
)
4221 } while (c
!= die
->die_child
);
4224 /* Add a CHILD_DIE as the last child of DIE. */
4227 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4229 /* FIXME this should probably be an assert. */
4230 if (! die
|| ! child_die
)
4232 gcc_assert (die
!= child_die
);
4234 child_die
->die_parent
= die
;
4237 child_die
->die_sib
= die
->die_child
->die_sib
;
4238 die
->die_child
->die_sib
= child_die
;
4241 child_die
->die_sib
= child_die
;
4242 die
->die_child
= child_die
;
4245 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4246 is the specification, to the end of PARENT's list of children.
4247 This is done by removing and re-adding it. */
4250 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4254 /* We want the declaration DIE from inside the class, not the
4255 specification DIE at toplevel. */
4256 if (child
->die_parent
!= parent
)
4258 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4264 gcc_assert (child
->die_parent
== parent
4265 || (child
->die_parent
4266 == get_AT_ref (parent
, DW_AT_specification
)));
4268 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4269 if (p
->die_sib
== child
)
4271 remove_child_with_prev (child
, p
);
4275 add_child_die (parent
, child
);
4278 /* Return a pointer to a newly created DIE node. */
4280 static inline dw_die_ref
4281 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4283 dw_die_ref die
= ggc_alloc_cleared_die_node ();
4285 die
->die_tag
= tag_value
;
4287 if (parent_die
!= NULL
)
4288 add_child_die (parent_die
, die
);
4291 limbo_die_node
*limbo_node
;
4293 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
4294 limbo_node
->die
= die
;
4295 limbo_node
->created_for
= t
;
4296 limbo_node
->next
= limbo_die_list
;
4297 limbo_die_list
= limbo_node
;
4303 /* Return the DIE associated with the given type specifier. */
4305 static inline dw_die_ref
4306 lookup_type_die (tree type
)
4308 return TYPE_SYMTAB_DIE (type
);
4311 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4312 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4313 anonymous type instead the one of the naming typedef. */
4315 static inline dw_die_ref
4316 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4319 && TREE_CODE (type
) == RECORD_TYPE
4321 && type_die
->die_tag
== DW_TAG_typedef
4322 && is_naming_typedef_decl (TYPE_NAME (type
)))
4323 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4327 /* Like lookup_type_die, but if type is an anonymous type named by a
4328 typedef[1], return the DIE of the anonymous type instead the one of
4329 the naming typedef. This is because in gen_typedef_die, we did
4330 equate the anonymous struct named by the typedef with the DIE of
4331 the naming typedef. So by default, lookup_type_die on an anonymous
4332 struct yields the DIE of the naming typedef.
4334 [1]: Read the comment of is_naming_typedef_decl to learn about what
4335 a naming typedef is. */
4337 static inline dw_die_ref
4338 lookup_type_die_strip_naming_typedef (tree type
)
4340 dw_die_ref die
= lookup_type_die (type
);
4341 return strip_naming_typedef (type
, die
);
4344 /* Equate a DIE to a given type specifier. */
4347 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
4349 TYPE_SYMTAB_DIE (type
) = type_die
;
4352 /* Returns a hash value for X (which really is a die_struct). */
4355 decl_die_table_hash (const void *x
)
4357 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
4360 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
4363 decl_die_table_eq (const void *x
, const void *y
)
4365 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4368 /* Return the DIE associated with a given declaration. */
4370 static inline dw_die_ref
4371 lookup_decl_die (tree decl
)
4373 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
4376 /* Returns a hash value for X (which really is a var_loc_list). */
4379 decl_loc_table_hash (const void *x
)
4381 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
4384 /* Return nonzero if decl_id of var_loc_list X is the same as
4388 decl_loc_table_eq (const void *x
, const void *y
)
4390 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4393 /* Return the var_loc list associated with a given declaration. */
4395 static inline var_loc_list
*
4396 lookup_decl_loc (const_tree decl
)
4398 if (!decl_loc_table
)
4400 return (var_loc_list
*)
4401 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
4404 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
4407 cached_dw_loc_list_table_hash (const void *x
)
4409 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
4412 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
4416 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
4418 return (((const cached_dw_loc_list
*) x
)->decl_id
4419 == DECL_UID ((const_tree
) y
));
4422 /* Equate a DIE to a particular declaration. */
4425 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
4427 unsigned int decl_id
= DECL_UID (decl
);
4430 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
4432 decl_die
->decl_id
= decl_id
;
4435 /* Return how many bits covers PIECE EXPR_LIST. */
4438 decl_piece_bitsize (rtx piece
)
4440 int ret
= (int) GET_MODE (piece
);
4443 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
4444 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
4445 return INTVAL (XEXP (XEXP (piece
, 0), 0));
4448 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
4451 decl_piece_varloc_ptr (rtx piece
)
4453 if ((int) GET_MODE (piece
))
4454 return &XEXP (piece
, 0);
4456 return &XEXP (XEXP (piece
, 0), 1);
4459 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
4460 Next is the chain of following piece nodes. */
4463 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
4465 if (bitsize
<= (int) MAX_MACHINE_MODE
)
4466 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
4468 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
4473 /* Return rtx that should be stored into loc field for
4474 LOC_NOTE and BITPOS/BITSIZE. */
4477 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
4478 HOST_WIDE_INT bitsize
)
4482 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
4484 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
4489 /* This function either modifies location piece list *DEST in
4490 place (if SRC and INNER is NULL), or copies location piece list
4491 *SRC to *DEST while modifying it. Location BITPOS is modified
4492 to contain LOC_NOTE, any pieces overlapping it are removed resp.
4493 not copied and if needed some padding around it is added.
4494 When modifying in place, DEST should point to EXPR_LIST where
4495 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
4496 to the start of the whole list and INNER points to the EXPR_LIST
4497 where earlier pieces cover PIECE_BITPOS bits. */
4500 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
4501 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
4502 HOST_WIDE_INT bitsize
, rtx loc_note
)
4505 bool copy
= inner
!= NULL
;
4509 /* First copy all nodes preceding the current bitpos. */
4510 while (src
!= inner
)
4512 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
4513 decl_piece_bitsize (*src
), NULL_RTX
);
4514 dest
= &XEXP (*dest
, 1);
4515 src
= &XEXP (*src
, 1);
4518 /* Add padding if needed. */
4519 if (bitpos
!= piece_bitpos
)
4521 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
4522 copy
? NULL_RTX
: *dest
);
4523 dest
= &XEXP (*dest
, 1);
4525 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
4528 /* A piece with correct bitpos and bitsize already exist,
4529 just update the location for it and return. */
4530 *decl_piece_varloc_ptr (*dest
) = loc_note
;
4533 /* Add the piece that changed. */
4534 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
4535 dest
= &XEXP (*dest
, 1);
4536 /* Skip over pieces that overlap it. */
4537 diff
= bitpos
- piece_bitpos
+ bitsize
;
4540 while (diff
> 0 && *src
)
4543 diff
-= decl_piece_bitsize (piece
);
4545 src
= &XEXP (piece
, 1);
4548 *src
= XEXP (piece
, 1);
4549 free_EXPR_LIST_node (piece
);
4552 /* Add padding if needed. */
4553 if (diff
< 0 && *src
)
4557 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
4558 dest
= &XEXP (*dest
, 1);
4562 /* Finally copy all nodes following it. */
4565 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
4566 decl_piece_bitsize (*src
), NULL_RTX
);
4567 dest
= &XEXP (*dest
, 1);
4568 src
= &XEXP (*src
, 1);
4572 /* Add a variable location node to the linked list for DECL. */
4574 static struct var_loc_node
*
4575 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
4577 unsigned int decl_id
;
4580 struct var_loc_node
*loc
= NULL
;
4581 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
4583 if (DECL_DEBUG_EXPR_IS_FROM (decl
))
4585 tree realdecl
= DECL_DEBUG_EXPR (decl
);
4586 if (realdecl
&& handled_component_p (realdecl
))
4588 HOST_WIDE_INT maxsize
;
4591 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
4592 if (!DECL_P (innerdecl
)
4593 || DECL_IGNORED_P (innerdecl
)
4594 || TREE_STATIC (innerdecl
)
4596 || bitpos
+ bitsize
> 256
4597 || bitsize
!= maxsize
)
4603 decl_id
= DECL_UID (decl
);
4604 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
4607 temp
= ggc_alloc_cleared_var_loc_list ();
4608 temp
->decl_id
= decl_id
;
4612 temp
= (var_loc_list
*) *slot
;
4614 /* For PARM_DECLs try to keep around the original incoming value,
4615 even if that means we'll emit a zero-range .debug_loc entry. */
4617 && temp
->first
== temp
->last
4618 && TREE_CODE (decl
) == PARM_DECL
4619 && GET_CODE (temp
->first
->loc
) == NOTE
4620 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
4621 && DECL_INCOMING_RTL (decl
)
4622 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
4623 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
4624 == GET_CODE (DECL_INCOMING_RTL (decl
))
4625 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
4627 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
4628 NOTE_VAR_LOCATION_LOC (loc_note
))
4629 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
4630 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
4632 loc
= ggc_alloc_cleared_var_loc_node ();
4633 temp
->first
->next
= loc
;
4635 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
4637 else if (temp
->last
)
4639 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
4640 rtx
*piece_loc
= NULL
, last_loc_note
;
4641 int piece_bitpos
= 0;
4645 gcc_assert (last
->next
== NULL
);
4647 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
4649 piece_loc
= &last
->loc
;
4652 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
4653 if (piece_bitpos
+ cur_bitsize
> bitpos
)
4655 piece_bitpos
+= cur_bitsize
;
4656 piece_loc
= &XEXP (*piece_loc
, 1);
4660 /* TEMP->LAST here is either pointer to the last but one or
4661 last element in the chained list, LAST is pointer to the
4663 if (label
&& strcmp (last
->label
, label
) == 0)
4665 /* For SRA optimized variables if there weren't any real
4666 insns since last note, just modify the last node. */
4667 if (piece_loc
!= NULL
)
4669 adjust_piece_list (piece_loc
, NULL
, NULL
,
4670 bitpos
, piece_bitpos
, bitsize
, loc_note
);
4673 /* If the last note doesn't cover any instructions, remove it. */
4674 if (temp
->last
!= last
)
4676 temp
->last
->next
= NULL
;
4679 gcc_assert (strcmp (last
->label
, label
) != 0);
4683 gcc_assert (temp
->first
== temp
->last
4684 || (temp
->first
->next
== temp
->last
4685 && TREE_CODE (decl
) == PARM_DECL
));
4686 memset (temp
->last
, '\0', sizeof (*temp
->last
));
4687 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
4691 if (bitsize
== -1 && NOTE_P (last
->loc
))
4692 last_loc_note
= last
->loc
;
4693 else if (piece_loc
!= NULL
4694 && *piece_loc
!= NULL_RTX
4695 && piece_bitpos
== bitpos
4696 && decl_piece_bitsize (*piece_loc
) == bitsize
)
4697 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
4699 last_loc_note
= NULL_RTX
;
4700 /* If the current location is the same as the end of the list,
4701 and either both or neither of the locations is uninitialized,
4702 we have nothing to do. */
4703 if (last_loc_note
== NULL_RTX
4704 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
4705 NOTE_VAR_LOCATION_LOC (loc_note
)))
4706 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
4707 != NOTE_VAR_LOCATION_STATUS (loc_note
))
4708 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
4709 == VAR_INIT_STATUS_UNINITIALIZED
)
4710 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
4711 == VAR_INIT_STATUS_UNINITIALIZED
))))
4713 /* Add LOC to the end of list and update LAST. If the last
4714 element of the list has been removed above, reuse its
4715 memory for the new node, otherwise allocate a new one. */
4719 memset (loc
, '\0', sizeof (*loc
));
4722 loc
= ggc_alloc_cleared_var_loc_node ();
4723 if (bitsize
== -1 || piece_loc
== NULL
)
4724 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
4726 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
4727 bitpos
, piece_bitpos
, bitsize
, loc_note
);
4729 /* Ensure TEMP->LAST will point either to the new last but one
4730 element of the chain, or to the last element in it. */
4731 if (last
!= temp
->last
)
4739 loc
= ggc_alloc_cleared_var_loc_node ();
4742 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
4747 /* Keep track of the number of spaces used to indent the
4748 output of the debugging routines that print the structure of
4749 the DIE internal representation. */
4750 static int print_indent
;
4752 /* Indent the line the number of spaces given by print_indent. */
4755 print_spaces (FILE *outfile
)
4757 fprintf (outfile
, "%*s", print_indent
, "");
4760 /* Print a type signature in hex. */
4763 print_signature (FILE *outfile
, char *sig
)
4767 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
4768 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
4771 /* Print the information associated with a given DIE, and its children.
4772 This routine is a debugging aid only. */
4775 print_die (dw_die_ref die
, FILE *outfile
)
4781 print_spaces (outfile
);
4782 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
4783 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
4785 print_spaces (outfile
);
4786 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
4787 fprintf (outfile
, " offset: %ld", die
->die_offset
);
4788 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
4790 if (die
->comdat_type_p
)
4792 print_spaces (outfile
);
4793 fprintf (outfile
, " signature: ");
4794 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
4795 fprintf (outfile
, "\n");
4798 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
4800 print_spaces (outfile
);
4801 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
4803 switch (AT_class (a
))
4805 case dw_val_class_addr
:
4806 fprintf (outfile
, "address");
4808 case dw_val_class_offset
:
4809 fprintf (outfile
, "offset");
4811 case dw_val_class_loc
:
4812 fprintf (outfile
, "location descriptor");
4814 case dw_val_class_loc_list
:
4815 fprintf (outfile
, "location list -> label:%s",
4816 AT_loc_list (a
)->ll_symbol
);
4818 case dw_val_class_range_list
:
4819 fprintf (outfile
, "range list");
4821 case dw_val_class_const
:
4822 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
4824 case dw_val_class_unsigned_const
:
4825 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
4827 case dw_val_class_const_double
:
4828 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
4829 HOST_WIDE_INT_PRINT_UNSIGNED
")",
4830 a
->dw_attr_val
.v
.val_double
.high
,
4831 a
->dw_attr_val
.v
.val_double
.low
);
4833 case dw_val_class_vec
:
4834 fprintf (outfile
, "floating-point or vector constant");
4836 case dw_val_class_flag
:
4837 fprintf (outfile
, "%u", AT_flag (a
));
4839 case dw_val_class_die_ref
:
4840 if (AT_ref (a
) != NULL
)
4842 if (AT_ref (a
)->comdat_type_p
)
4844 fprintf (outfile
, "die -> signature: ");
4845 print_signature (outfile
,
4846 AT_ref (a
)->die_id
.die_type_node
->signature
);
4848 else if (AT_ref (a
)->die_id
.die_symbol
)
4849 fprintf (outfile
, "die -> label: %s",
4850 AT_ref (a
)->die_id
.die_symbol
);
4852 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
4853 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
4856 fprintf (outfile
, "die -> <null>");
4858 case dw_val_class_vms_delta
:
4859 fprintf (outfile
, "delta: @slotcount(%s-%s)",
4860 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
4862 case dw_val_class_lbl_id
:
4863 case dw_val_class_lineptr
:
4864 case dw_val_class_macptr
:
4865 fprintf (outfile
, "label: %s", AT_lbl (a
));
4867 case dw_val_class_str
:
4868 if (AT_string (a
) != NULL
)
4869 fprintf (outfile
, "\"%s\"", AT_string (a
));
4871 fprintf (outfile
, "<null>");
4873 case dw_val_class_file
:
4874 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
4875 AT_file (a
)->emitted_number
);
4877 case dw_val_class_data8
:
4881 for (i
= 0; i
< 8; i
++)
4882 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
4889 fprintf (outfile
, "\n");
4892 if (die
->die_child
!= NULL
)
4895 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
4898 if (print_indent
== 0)
4899 fprintf (outfile
, "\n");
4902 /* Print the information collected for a given DIE. */
4905 debug_dwarf_die (dw_die_ref die
)
4907 print_die (die
, stderr
);
4910 /* Print all DWARF information collected for the compilation unit.
4911 This routine is a debugging aid only. */
4917 print_die (comp_unit_die (), stderr
);
4920 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
4921 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
4922 DIE that marks the start of the DIEs for this include file. */
4925 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
4927 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
4928 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
4930 new_unit
->die_sib
= old_unit
;
4934 /* Close an include-file CU and reopen the enclosing one. */
4937 pop_compile_unit (dw_die_ref old_unit
)
4939 dw_die_ref new_unit
= old_unit
->die_sib
;
4941 old_unit
->die_sib
= NULL
;
4945 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
4946 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
4948 /* Calculate the checksum of a location expression. */
4951 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
4955 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
4957 CHECKSUM (loc
->dw_loc_oprnd1
);
4958 CHECKSUM (loc
->dw_loc_oprnd2
);
4961 /* Calculate the checksum of an attribute. */
4964 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
4966 dw_loc_descr_ref loc
;
4969 CHECKSUM (at
->dw_attr
);
4971 /* We don't care that this was compiled with a different compiler
4972 snapshot; if the output is the same, that's what matters. */
4973 if (at
->dw_attr
== DW_AT_producer
)
4976 switch (AT_class (at
))
4978 case dw_val_class_const
:
4979 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
4981 case dw_val_class_unsigned_const
:
4982 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
4984 case dw_val_class_const_double
:
4985 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
4987 case dw_val_class_vec
:
4988 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
4990 case dw_val_class_flag
:
4991 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
4993 case dw_val_class_str
:
4994 CHECKSUM_STRING (AT_string (at
));
4997 case dw_val_class_addr
:
4999 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5000 CHECKSUM_STRING (XSTR (r
, 0));
5003 case dw_val_class_offset
:
5004 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5007 case dw_val_class_loc
:
5008 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5009 loc_checksum (loc
, ctx
);
5012 case dw_val_class_die_ref
:
5013 die_checksum (AT_ref (at
), ctx
, mark
);
5016 case dw_val_class_fde_ref
:
5017 case dw_val_class_vms_delta
:
5018 case dw_val_class_lbl_id
:
5019 case dw_val_class_lineptr
:
5020 case dw_val_class_macptr
:
5023 case dw_val_class_file
:
5024 CHECKSUM_STRING (AT_file (at
)->filename
);
5027 case dw_val_class_data8
:
5028 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5036 /* Calculate the checksum of a DIE. */
5039 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5045 /* To avoid infinite recursion. */
5048 CHECKSUM (die
->die_mark
);
5051 die
->die_mark
= ++(*mark
);
5053 CHECKSUM (die
->die_tag
);
5055 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
5056 attr_checksum (a
, ctx
, mark
);
5058 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5062 #undef CHECKSUM_STRING
5064 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5065 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5066 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5067 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5068 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5069 #define CHECKSUM_ATTR(FOO) \
5070 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5072 /* Calculate the checksum of a number in signed LEB128 format. */
5075 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5082 byte
= (value
& 0x7f);
5084 more
= !((value
== 0 && (byte
& 0x40) == 0)
5085 || (value
== -1 && (byte
& 0x40) != 0));
5094 /* Calculate the checksum of a number in unsigned LEB128 format. */
5097 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5101 unsigned char byte
= (value
& 0x7f);
5104 /* More bytes to follow. */
5112 /* Checksum the context of the DIE. This adds the names of any
5113 surrounding namespaces or structures to the checksum. */
5116 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5120 int tag
= die
->die_tag
;
5122 if (tag
!= DW_TAG_namespace
5123 && tag
!= DW_TAG_structure_type
5124 && tag
!= DW_TAG_class_type
)
5127 name
= get_AT_string (die
, DW_AT_name
);
5129 spec
= get_AT_ref (die
, DW_AT_specification
);
5133 if (die
->die_parent
!= NULL
)
5134 checksum_die_context (die
->die_parent
, ctx
);
5136 CHECKSUM_ULEB128 ('C');
5137 CHECKSUM_ULEB128 (tag
);
5139 CHECKSUM_STRING (name
);
5142 /* Calculate the checksum of a location expression. */
5145 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5147 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5148 were emitted as a DW_FORM_sdata instead of a location expression. */
5149 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5151 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5152 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5156 /* Otherwise, just checksum the raw location expression. */
5159 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5160 CHECKSUM (loc
->dw_loc_oprnd1
);
5161 CHECKSUM (loc
->dw_loc_oprnd2
);
5162 loc
= loc
->dw_loc_next
;
5166 /* Calculate the checksum of an attribute. */
5169 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5170 struct md5_ctx
*ctx
, int *mark
)
5172 dw_loc_descr_ref loc
;
5175 if (AT_class (at
) == dw_val_class_die_ref
)
5177 dw_die_ref target_die
= AT_ref (at
);
5179 /* For pointer and reference types, we checksum only the (qualified)
5180 name of the target type (if there is a name). For friend entries,
5181 we checksum only the (qualified) name of the target type or function.
5182 This allows the checksum to remain the same whether the target type
5183 is complete or not. */
5184 if ((at
->dw_attr
== DW_AT_type
5185 && (tag
== DW_TAG_pointer_type
5186 || tag
== DW_TAG_reference_type
5187 || tag
== DW_TAG_rvalue_reference_type
5188 || tag
== DW_TAG_ptr_to_member_type
))
5189 || (at
->dw_attr
== DW_AT_friend
5190 && tag
== DW_TAG_friend
))
5192 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5194 if (name_attr
!= NULL
)
5196 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5200 CHECKSUM_ULEB128 ('N');
5201 CHECKSUM_ULEB128 (at
->dw_attr
);
5202 if (decl
->die_parent
!= NULL
)
5203 checksum_die_context (decl
->die_parent
, ctx
);
5204 CHECKSUM_ULEB128 ('E');
5205 CHECKSUM_STRING (AT_string (name_attr
));
5210 /* For all other references to another DIE, we check to see if the
5211 target DIE has already been visited. If it has, we emit a
5212 backward reference; if not, we descend recursively. */
5213 if (target_die
->die_mark
> 0)
5215 CHECKSUM_ULEB128 ('R');
5216 CHECKSUM_ULEB128 (at
->dw_attr
);
5217 CHECKSUM_ULEB128 (target_die
->die_mark
);
5221 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5225 target_die
->die_mark
= ++(*mark
);
5226 CHECKSUM_ULEB128 ('T');
5227 CHECKSUM_ULEB128 (at
->dw_attr
);
5228 if (decl
->die_parent
!= NULL
)
5229 checksum_die_context (decl
->die_parent
, ctx
);
5230 die_checksum_ordered (target_die
, ctx
, mark
);
5235 CHECKSUM_ULEB128 ('A');
5236 CHECKSUM_ULEB128 (at
->dw_attr
);
5238 switch (AT_class (at
))
5240 case dw_val_class_const
:
5241 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5242 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5245 case dw_val_class_unsigned_const
:
5246 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5247 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5250 case dw_val_class_const_double
:
5251 CHECKSUM_ULEB128 (DW_FORM_block
);
5252 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5253 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5256 case dw_val_class_vec
:
5257 CHECKSUM_ULEB128 (DW_FORM_block
);
5258 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_vec
));
5259 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5262 case dw_val_class_flag
:
5263 CHECKSUM_ULEB128 (DW_FORM_flag
);
5264 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
5267 case dw_val_class_str
:
5268 CHECKSUM_ULEB128 (DW_FORM_string
);
5269 CHECKSUM_STRING (AT_string (at
));
5272 case dw_val_class_addr
:
5274 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5275 CHECKSUM_ULEB128 (DW_FORM_string
);
5276 CHECKSUM_STRING (XSTR (r
, 0));
5279 case dw_val_class_offset
:
5280 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5281 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
5284 case dw_val_class_loc
:
5285 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5286 loc_checksum_ordered (loc
, ctx
);
5289 case dw_val_class_fde_ref
:
5290 case dw_val_class_lbl_id
:
5291 case dw_val_class_lineptr
:
5292 case dw_val_class_macptr
:
5295 case dw_val_class_file
:
5296 CHECKSUM_ULEB128 (DW_FORM_string
);
5297 CHECKSUM_STRING (AT_file (at
)->filename
);
5300 case dw_val_class_data8
:
5301 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5309 struct checksum_attributes
5311 dw_attr_ref at_name
;
5312 dw_attr_ref at_type
;
5313 dw_attr_ref at_friend
;
5314 dw_attr_ref at_accessibility
;
5315 dw_attr_ref at_address_class
;
5316 dw_attr_ref at_allocated
;
5317 dw_attr_ref at_artificial
;
5318 dw_attr_ref at_associated
;
5319 dw_attr_ref at_binary_scale
;
5320 dw_attr_ref at_bit_offset
;
5321 dw_attr_ref at_bit_size
;
5322 dw_attr_ref at_bit_stride
;
5323 dw_attr_ref at_byte_size
;
5324 dw_attr_ref at_byte_stride
;
5325 dw_attr_ref at_const_value
;
5326 dw_attr_ref at_containing_type
;
5327 dw_attr_ref at_count
;
5328 dw_attr_ref at_data_location
;
5329 dw_attr_ref at_data_member_location
;
5330 dw_attr_ref at_decimal_scale
;
5331 dw_attr_ref at_decimal_sign
;
5332 dw_attr_ref at_default_value
;
5333 dw_attr_ref at_digit_count
;
5334 dw_attr_ref at_discr
;
5335 dw_attr_ref at_discr_list
;
5336 dw_attr_ref at_discr_value
;
5337 dw_attr_ref at_encoding
;
5338 dw_attr_ref at_endianity
;
5339 dw_attr_ref at_explicit
;
5340 dw_attr_ref at_is_optional
;
5341 dw_attr_ref at_location
;
5342 dw_attr_ref at_lower_bound
;
5343 dw_attr_ref at_mutable
;
5344 dw_attr_ref at_ordering
;
5345 dw_attr_ref at_picture_string
;
5346 dw_attr_ref at_prototyped
;
5347 dw_attr_ref at_small
;
5348 dw_attr_ref at_segment
;
5349 dw_attr_ref at_string_length
;
5350 dw_attr_ref at_threads_scaled
;
5351 dw_attr_ref at_upper_bound
;
5352 dw_attr_ref at_use_location
;
5353 dw_attr_ref at_use_UTF8
;
5354 dw_attr_ref at_variable_parameter
;
5355 dw_attr_ref at_virtuality
;
5356 dw_attr_ref at_visibility
;
5357 dw_attr_ref at_vtable_elem_location
;
5360 /* Collect the attributes that we will want to use for the checksum. */
5363 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
5368 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
5379 attrs
->at_friend
= a
;
5381 case DW_AT_accessibility
:
5382 attrs
->at_accessibility
= a
;
5384 case DW_AT_address_class
:
5385 attrs
->at_address_class
= a
;
5387 case DW_AT_allocated
:
5388 attrs
->at_allocated
= a
;
5390 case DW_AT_artificial
:
5391 attrs
->at_artificial
= a
;
5393 case DW_AT_associated
:
5394 attrs
->at_associated
= a
;
5396 case DW_AT_binary_scale
:
5397 attrs
->at_binary_scale
= a
;
5399 case DW_AT_bit_offset
:
5400 attrs
->at_bit_offset
= a
;
5402 case DW_AT_bit_size
:
5403 attrs
->at_bit_size
= a
;
5405 case DW_AT_bit_stride
:
5406 attrs
->at_bit_stride
= a
;
5408 case DW_AT_byte_size
:
5409 attrs
->at_byte_size
= a
;
5411 case DW_AT_byte_stride
:
5412 attrs
->at_byte_stride
= a
;
5414 case DW_AT_const_value
:
5415 attrs
->at_const_value
= a
;
5417 case DW_AT_containing_type
:
5418 attrs
->at_containing_type
= a
;
5421 attrs
->at_count
= a
;
5423 case DW_AT_data_location
:
5424 attrs
->at_data_location
= a
;
5426 case DW_AT_data_member_location
:
5427 attrs
->at_data_member_location
= a
;
5429 case DW_AT_decimal_scale
:
5430 attrs
->at_decimal_scale
= a
;
5432 case DW_AT_decimal_sign
:
5433 attrs
->at_decimal_sign
= a
;
5435 case DW_AT_default_value
:
5436 attrs
->at_default_value
= a
;
5438 case DW_AT_digit_count
:
5439 attrs
->at_digit_count
= a
;
5442 attrs
->at_discr
= a
;
5444 case DW_AT_discr_list
:
5445 attrs
->at_discr_list
= a
;
5447 case DW_AT_discr_value
:
5448 attrs
->at_discr_value
= a
;
5450 case DW_AT_encoding
:
5451 attrs
->at_encoding
= a
;
5453 case DW_AT_endianity
:
5454 attrs
->at_endianity
= a
;
5456 case DW_AT_explicit
:
5457 attrs
->at_explicit
= a
;
5459 case DW_AT_is_optional
:
5460 attrs
->at_is_optional
= a
;
5462 case DW_AT_location
:
5463 attrs
->at_location
= a
;
5465 case DW_AT_lower_bound
:
5466 attrs
->at_lower_bound
= a
;
5469 attrs
->at_mutable
= a
;
5471 case DW_AT_ordering
:
5472 attrs
->at_ordering
= a
;
5474 case DW_AT_picture_string
:
5475 attrs
->at_picture_string
= a
;
5477 case DW_AT_prototyped
:
5478 attrs
->at_prototyped
= a
;
5481 attrs
->at_small
= a
;
5484 attrs
->at_segment
= a
;
5486 case DW_AT_string_length
:
5487 attrs
->at_string_length
= a
;
5489 case DW_AT_threads_scaled
:
5490 attrs
->at_threads_scaled
= a
;
5492 case DW_AT_upper_bound
:
5493 attrs
->at_upper_bound
= a
;
5495 case DW_AT_use_location
:
5496 attrs
->at_use_location
= a
;
5498 case DW_AT_use_UTF8
:
5499 attrs
->at_use_UTF8
= a
;
5501 case DW_AT_variable_parameter
:
5502 attrs
->at_variable_parameter
= a
;
5504 case DW_AT_virtuality
:
5505 attrs
->at_virtuality
= a
;
5507 case DW_AT_visibility
:
5508 attrs
->at_visibility
= a
;
5510 case DW_AT_vtable_elem_location
:
5511 attrs
->at_vtable_elem_location
= a
;
5519 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
5522 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5526 struct checksum_attributes attrs
;
5528 CHECKSUM_ULEB128 ('D');
5529 CHECKSUM_ULEB128 (die
->die_tag
);
5531 memset (&attrs
, 0, sizeof (attrs
));
5533 decl
= get_AT_ref (die
, DW_AT_specification
);
5535 collect_checksum_attributes (&attrs
, decl
);
5536 collect_checksum_attributes (&attrs
, die
);
5538 CHECKSUM_ATTR (attrs
.at_name
);
5539 CHECKSUM_ATTR (attrs
.at_accessibility
);
5540 CHECKSUM_ATTR (attrs
.at_address_class
);
5541 CHECKSUM_ATTR (attrs
.at_allocated
);
5542 CHECKSUM_ATTR (attrs
.at_artificial
);
5543 CHECKSUM_ATTR (attrs
.at_associated
);
5544 CHECKSUM_ATTR (attrs
.at_binary_scale
);
5545 CHECKSUM_ATTR (attrs
.at_bit_offset
);
5546 CHECKSUM_ATTR (attrs
.at_bit_size
);
5547 CHECKSUM_ATTR (attrs
.at_bit_stride
);
5548 CHECKSUM_ATTR (attrs
.at_byte_size
);
5549 CHECKSUM_ATTR (attrs
.at_byte_stride
);
5550 CHECKSUM_ATTR (attrs
.at_const_value
);
5551 CHECKSUM_ATTR (attrs
.at_containing_type
);
5552 CHECKSUM_ATTR (attrs
.at_count
);
5553 CHECKSUM_ATTR (attrs
.at_data_location
);
5554 CHECKSUM_ATTR (attrs
.at_data_member_location
);
5555 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
5556 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
5557 CHECKSUM_ATTR (attrs
.at_default_value
);
5558 CHECKSUM_ATTR (attrs
.at_digit_count
);
5559 CHECKSUM_ATTR (attrs
.at_discr
);
5560 CHECKSUM_ATTR (attrs
.at_discr_list
);
5561 CHECKSUM_ATTR (attrs
.at_discr_value
);
5562 CHECKSUM_ATTR (attrs
.at_encoding
);
5563 CHECKSUM_ATTR (attrs
.at_endianity
);
5564 CHECKSUM_ATTR (attrs
.at_explicit
);
5565 CHECKSUM_ATTR (attrs
.at_is_optional
);
5566 CHECKSUM_ATTR (attrs
.at_location
);
5567 CHECKSUM_ATTR (attrs
.at_lower_bound
);
5568 CHECKSUM_ATTR (attrs
.at_mutable
);
5569 CHECKSUM_ATTR (attrs
.at_ordering
);
5570 CHECKSUM_ATTR (attrs
.at_picture_string
);
5571 CHECKSUM_ATTR (attrs
.at_prototyped
);
5572 CHECKSUM_ATTR (attrs
.at_small
);
5573 CHECKSUM_ATTR (attrs
.at_segment
);
5574 CHECKSUM_ATTR (attrs
.at_string_length
);
5575 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
5576 CHECKSUM_ATTR (attrs
.at_upper_bound
);
5577 CHECKSUM_ATTR (attrs
.at_use_location
);
5578 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
5579 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
5580 CHECKSUM_ATTR (attrs
.at_virtuality
);
5581 CHECKSUM_ATTR (attrs
.at_visibility
);
5582 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
5583 CHECKSUM_ATTR (attrs
.at_type
);
5584 CHECKSUM_ATTR (attrs
.at_friend
);
5586 /* Checksum the child DIEs, except for nested types and member functions. */
5589 dw_attr_ref name_attr
;
5592 name_attr
= get_AT (c
, DW_AT_name
);
5593 if ((is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
)
5594 && name_attr
!= NULL
)
5596 CHECKSUM_ULEB128 ('S');
5597 CHECKSUM_ULEB128 (c
->die_tag
);
5598 CHECKSUM_STRING (AT_string (name_attr
));
5602 /* Mark this DIE so it gets processed when unmarking. */
5603 if (c
->die_mark
== 0)
5605 die_checksum_ordered (c
, ctx
, mark
);
5607 } while (c
!= die
->die_child
);
5609 CHECKSUM_ULEB128 (0);
5613 #undef CHECKSUM_STRING
5614 #undef CHECKSUM_ATTR
5615 #undef CHECKSUM_LEB128
5616 #undef CHECKSUM_ULEB128
5618 /* Generate the type signature for DIE. This is computed by generating an
5619 MD5 checksum over the DIE's tag, its relevant attributes, and its
5620 children. Attributes that are references to other DIEs are processed
5621 by recursion, using the MARK field to prevent infinite recursion.
5622 If the DIE is nested inside a namespace or another type, we also
5623 need to include that context in the signature. The lower 64 bits
5624 of the resulting MD5 checksum comprise the signature. */
5627 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
5631 unsigned char checksum
[16];
5635 name
= get_AT_string (die
, DW_AT_name
);
5636 decl
= get_AT_ref (die
, DW_AT_specification
);
5638 /* First, compute a signature for just the type name (and its surrounding
5639 context, if any. This is stored in the type unit DIE for link-time
5640 ODR (one-definition rule) checking. */
5642 if (is_cxx() && name
!= NULL
)
5644 md5_init_ctx (&ctx
);
5646 /* Checksum the names of surrounding namespaces and structures. */
5647 if (decl
!= NULL
&& decl
->die_parent
!= NULL
)
5648 checksum_die_context (decl
->die_parent
, &ctx
);
5650 md5_process_bytes (&die
->die_tag
, sizeof (die
->die_tag
), &ctx
);
5651 md5_process_bytes (name
, strlen (name
) + 1, &ctx
);
5652 md5_finish_ctx (&ctx
, checksum
);
5654 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
5657 /* Next, compute the complete type signature. */
5659 md5_init_ctx (&ctx
);
5661 die
->die_mark
= mark
;
5663 /* Checksum the names of surrounding namespaces and structures. */
5664 if (decl
!= NULL
&& decl
->die_parent
!= NULL
)
5665 checksum_die_context (decl
->die_parent
, &ctx
);
5667 /* Checksum the DIE and its children. */
5668 die_checksum_ordered (die
, &ctx
, &mark
);
5669 unmark_all_dies (die
);
5670 md5_finish_ctx (&ctx
, checksum
);
5672 /* Store the signature in the type node and link the type DIE and the
5673 type node together. */
5674 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
5675 DWARF_TYPE_SIGNATURE_SIZE
);
5676 die
->comdat_type_p
= true;
5677 die
->die_id
.die_type_node
= type_node
;
5678 type_node
->type_die
= die
;
5680 /* If the DIE is a specification, link its declaration to the type node
5684 decl
->comdat_type_p
= true;
5685 decl
->die_id
.die_type_node
= type_node
;
5689 /* Do the location expressions look same? */
5691 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
5693 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
5694 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
5695 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
5698 /* Do the values look the same? */
5700 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
5702 dw_loc_descr_ref loc1
, loc2
;
5705 if (v1
->val_class
!= v2
->val_class
)
5708 switch (v1
->val_class
)
5710 case dw_val_class_const
:
5711 return v1
->v
.val_int
== v2
->v
.val_int
;
5712 case dw_val_class_unsigned_const
:
5713 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
5714 case dw_val_class_const_double
:
5715 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
5716 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
5717 case dw_val_class_vec
:
5718 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
5719 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
5721 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
5722 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
5725 case dw_val_class_flag
:
5726 return v1
->v
.val_flag
== v2
->v
.val_flag
;
5727 case dw_val_class_str
:
5728 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
5730 case dw_val_class_addr
:
5731 r1
= v1
->v
.val_addr
;
5732 r2
= v2
->v
.val_addr
;
5733 if (GET_CODE (r1
) != GET_CODE (r2
))
5735 return !rtx_equal_p (r1
, r2
);
5737 case dw_val_class_offset
:
5738 return v1
->v
.val_offset
== v2
->v
.val_offset
;
5740 case dw_val_class_loc
:
5741 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
5743 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
5744 if (!same_loc_p (loc1
, loc2
, mark
))
5746 return !loc1
&& !loc2
;
5748 case dw_val_class_die_ref
:
5749 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
5751 case dw_val_class_fde_ref
:
5752 case dw_val_class_vms_delta
:
5753 case dw_val_class_lbl_id
:
5754 case dw_val_class_lineptr
:
5755 case dw_val_class_macptr
:
5758 case dw_val_class_file
:
5759 return v1
->v
.val_file
== v2
->v
.val_file
;
5761 case dw_val_class_data8
:
5762 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
5769 /* Do the attributes look the same? */
5772 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
5774 if (at1
->dw_attr
!= at2
->dw_attr
)
5777 /* We don't care that this was compiled with a different compiler
5778 snapshot; if the output is the same, that's what matters. */
5779 if (at1
->dw_attr
== DW_AT_producer
)
5782 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
5785 /* Do the dies look the same? */
5788 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
5794 /* To avoid infinite recursion. */
5796 return die1
->die_mark
== die2
->die_mark
;
5797 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
5799 if (die1
->die_tag
!= die2
->die_tag
)
5802 if (VEC_length (dw_attr_node
, die1
->die_attr
)
5803 != VEC_length (dw_attr_node
, die2
->die_attr
))
5806 FOR_EACH_VEC_ELT (dw_attr_node
, die1
->die_attr
, ix
, a1
)
5807 if (!same_attr_p (a1
, VEC_index (dw_attr_node
, die2
->die_attr
, ix
), mark
))
5810 c1
= die1
->die_child
;
5811 c2
= die2
->die_child
;
5820 if (!same_die_p (c1
, c2
, mark
))
5824 if (c1
== die1
->die_child
)
5826 if (c2
== die2
->die_child
)
5836 /* Do the dies look the same? Wrapper around same_die_p. */
5839 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
5842 int ret
= same_die_p (die1
, die2
, &mark
);
5844 unmark_all_dies (die1
);
5845 unmark_all_dies (die2
);
5850 /* The prefix to attach to symbols on DIEs in the current comdat debug
5852 static const char *comdat_symbol_id
;
5854 /* The index of the current symbol within the current comdat CU. */
5855 static unsigned int comdat_symbol_number
;
5857 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5858 children, and set comdat_symbol_id accordingly. */
5861 compute_section_prefix (dw_die_ref unit_die
)
5863 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
5864 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
5865 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
5868 unsigned char checksum
[16];
5871 /* Compute the checksum of the DIE, then append part of it as hex digits to
5872 the name filename of the unit. */
5874 md5_init_ctx (&ctx
);
5876 die_checksum (unit_die
, &ctx
, &mark
);
5877 unmark_all_dies (unit_die
);
5878 md5_finish_ctx (&ctx
, checksum
);
5880 sprintf (name
, "%s.", base
);
5881 clean_symbol_name (name
);
5883 p
= name
+ strlen (name
);
5884 for (i
= 0; i
< 4; i
++)
5886 sprintf (p
, "%.2x", checksum
[i
]);
5890 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
5891 comdat_symbol_number
= 0;
5894 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5897 is_type_die (dw_die_ref die
)
5899 switch (die
->die_tag
)
5901 case DW_TAG_array_type
:
5902 case DW_TAG_class_type
:
5903 case DW_TAG_interface_type
:
5904 case DW_TAG_enumeration_type
:
5905 case DW_TAG_pointer_type
:
5906 case DW_TAG_reference_type
:
5907 case DW_TAG_rvalue_reference_type
:
5908 case DW_TAG_string_type
:
5909 case DW_TAG_structure_type
:
5910 case DW_TAG_subroutine_type
:
5911 case DW_TAG_union_type
:
5912 case DW_TAG_ptr_to_member_type
:
5913 case DW_TAG_set_type
:
5914 case DW_TAG_subrange_type
:
5915 case DW_TAG_base_type
:
5916 case DW_TAG_const_type
:
5917 case DW_TAG_file_type
:
5918 case DW_TAG_packed_type
:
5919 case DW_TAG_volatile_type
:
5920 case DW_TAG_typedef
:
5927 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5928 Basically, we want to choose the bits that are likely to be shared between
5929 compilations (types) and leave out the bits that are specific to individual
5930 compilations (functions). */
5933 is_comdat_die (dw_die_ref c
)
5935 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5936 we do for stabs. The advantage is a greater likelihood of sharing between
5937 objects that don't include headers in the same order (and therefore would
5938 put the base types in a different comdat). jason 8/28/00 */
5940 if (c
->die_tag
== DW_TAG_base_type
)
5943 if (c
->die_tag
== DW_TAG_pointer_type
5944 || c
->die_tag
== DW_TAG_reference_type
5945 || c
->die_tag
== DW_TAG_rvalue_reference_type
5946 || c
->die_tag
== DW_TAG_const_type
5947 || c
->die_tag
== DW_TAG_volatile_type
)
5949 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
5951 return t
? is_comdat_die (t
) : 0;
5954 return is_type_die (c
);
5957 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5958 compilation unit. */
5961 is_symbol_die (dw_die_ref c
)
5963 return (is_type_die (c
)
5964 || is_declaration_die (c
)
5965 || c
->die_tag
== DW_TAG_namespace
5966 || c
->die_tag
== DW_TAG_module
);
5969 /* Returns true iff C is a compile-unit DIE. */
5972 is_cu_die (dw_die_ref c
)
5974 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
5977 /* Returns true iff C is a unit DIE of some sort. */
5980 is_unit_die (dw_die_ref c
)
5982 return c
&& (c
->die_tag
== DW_TAG_compile_unit
5983 || c
->die_tag
== DW_TAG_partial_unit
5984 || c
->die_tag
== DW_TAG_type_unit
);
5987 /* Returns true iff C is a namespace DIE. */
5990 is_namespace_die (dw_die_ref c
)
5992 return c
&& c
->die_tag
== DW_TAG_namespace
;
5995 /* Returns true iff C is a class or structure DIE. */
5998 is_class_die (dw_die_ref c
)
6000 return c
&& (c
->die_tag
== DW_TAG_class_type
6001 || c
->die_tag
== DW_TAG_structure_type
);
6005 gen_internal_sym (const char *prefix
)
6009 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6010 return xstrdup (buf
);
6013 /* Assign symbols to all worthy DIEs under DIE. */
6016 assign_symbol_names (dw_die_ref die
)
6020 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6022 if (comdat_symbol_id
)
6024 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6026 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6027 comdat_symbol_id
, comdat_symbol_number
++);
6028 die
->die_id
.die_symbol
= xstrdup (p
);
6031 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6034 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6037 struct cu_hash_table_entry
6040 unsigned min_comdat_num
, max_comdat_num
;
6041 struct cu_hash_table_entry
*next
;
6044 /* Routines to manipulate hash table of CUs. */
6046 htab_cu_hash (const void *of
)
6048 const struct cu_hash_table_entry
*const entry
=
6049 (const struct cu_hash_table_entry
*) of
;
6051 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6055 htab_cu_eq (const void *of1
, const void *of2
)
6057 const struct cu_hash_table_entry
*const entry1
=
6058 (const struct cu_hash_table_entry
*) of1
;
6059 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
6061 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6065 htab_cu_del (void *what
)
6067 struct cu_hash_table_entry
*next
,
6068 *entry
= (struct cu_hash_table_entry
*) what
;
6078 /* Check whether we have already seen this CU and set up SYM_NUM
6081 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
6083 struct cu_hash_table_entry dummy
;
6084 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6086 dummy
.max_comdat_num
= 0;
6088 slot
= (struct cu_hash_table_entry
**)
6089 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6093 for (; entry
; last
= entry
, entry
= entry
->next
)
6095 if (same_die_p_wrap (cu
, entry
->cu
))
6101 *sym_num
= entry
->min_comdat_num
;
6105 entry
= XCNEW (struct cu_hash_table_entry
);
6107 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6108 entry
->next
= *slot
;
6114 /* Record SYM_NUM to record of CU in HTABLE. */
6116 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
6118 struct cu_hash_table_entry
**slot
, *entry
;
6120 slot
= (struct cu_hash_table_entry
**)
6121 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6125 entry
->max_comdat_num
= sym_num
;
6128 /* Traverse the DIE (which is always comp_unit_die), and set up
6129 additional compilation units for each of the include files we see
6130 bracketed by BINCL/EINCL. */
6133 break_out_includes (dw_die_ref die
)
6136 dw_die_ref unit
= NULL
;
6137 limbo_die_node
*node
, **pnode
;
6138 htab_t cu_hash_table
;
6142 dw_die_ref prev
= c
;
6144 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6145 || (unit
&& is_comdat_die (c
)))
6147 dw_die_ref next
= c
->die_sib
;
6149 /* This DIE is for a secondary CU; remove it from the main one. */
6150 remove_child_with_prev (c
, prev
);
6152 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6153 unit
= push_new_compile_unit (unit
, c
);
6154 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6155 unit
= pop_compile_unit (unit
);
6157 add_child_die (unit
, c
);
6159 if (c
== die
->die_child
)
6162 } while (c
!= die
->die_child
);
6165 /* We can only use this in debugging, since the frontend doesn't check
6166 to make sure that we leave every include file we enter. */
6170 assign_symbol_names (die
);
6171 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
6172 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6178 compute_section_prefix (node
->die
);
6179 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6180 &comdat_symbol_number
);
6181 assign_symbol_names (node
->die
);
6183 *pnode
= node
->next
;
6186 pnode
= &node
->next
;
6187 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6188 comdat_symbol_number
);
6191 htab_delete (cu_hash_table
);
6194 /* Return non-zero if this DIE is a declaration. */
6197 is_declaration_die (dw_die_ref die
)
6202 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6203 if (a
->dw_attr
== DW_AT_declaration
)
6209 /* Return non-zero if this DIE is nested inside a subprogram. */
6212 is_nested_in_subprogram (dw_die_ref die
)
6214 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6218 return local_scope_p (decl
);
6221 /* Return non-zero if this DIE contains a defining declaration of a
6225 contains_subprogram_definition (dw_die_ref die
)
6229 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6231 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition(c
)) return 1);
6235 /* Return non-zero if this is a type DIE that should be moved to a
6236 COMDAT .debug_types section. */
6239 should_move_die_to_comdat (dw_die_ref die
)
6241 switch (die
->die_tag
)
6243 case DW_TAG_class_type
:
6244 case DW_TAG_structure_type
:
6245 case DW_TAG_enumeration_type
:
6246 case DW_TAG_union_type
:
6247 /* Don't move declarations, inlined instances, or types nested in a
6249 if (is_declaration_die (die
)
6250 || get_AT (die
, DW_AT_abstract_origin
)
6251 || is_nested_in_subprogram (die
))
6253 /* A type definition should never contain a subprogram definition. */
6254 gcc_assert (!contains_subprogram_definition (die
));
6256 case DW_TAG_array_type
:
6257 case DW_TAG_interface_type
:
6258 case DW_TAG_pointer_type
:
6259 case DW_TAG_reference_type
:
6260 case DW_TAG_rvalue_reference_type
:
6261 case DW_TAG_string_type
:
6262 case DW_TAG_subroutine_type
:
6263 case DW_TAG_ptr_to_member_type
:
6264 case DW_TAG_set_type
:
6265 case DW_TAG_subrange_type
:
6266 case DW_TAG_base_type
:
6267 case DW_TAG_const_type
:
6268 case DW_TAG_file_type
:
6269 case DW_TAG_packed_type
:
6270 case DW_TAG_volatile_type
:
6271 case DW_TAG_typedef
:
6277 /* Make a clone of DIE. */
6280 clone_die (dw_die_ref die
)
6286 clone
= ggc_alloc_cleared_die_node ();
6287 clone
->die_tag
= die
->die_tag
;
6289 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6290 add_dwarf_attr (clone
, a
);
6295 /* Make a clone of the tree rooted at DIE. */
6298 clone_tree (dw_die_ref die
)
6301 dw_die_ref clone
= clone_die (die
);
6303 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree(c
)));
6308 /* Make a clone of DIE as a declaration. */
6311 clone_as_declaration (dw_die_ref die
)
6318 /* If the DIE is already a declaration, just clone it. */
6319 if (is_declaration_die (die
))
6320 return clone_die (die
);
6322 /* If the DIE is a specification, just clone its declaration DIE. */
6323 decl
= get_AT_ref (die
, DW_AT_specification
);
6326 clone
= clone_die (decl
);
6327 if (die
->comdat_type_p
)
6328 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6332 clone
= ggc_alloc_cleared_die_node ();
6333 clone
->die_tag
= die
->die_tag
;
6335 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6337 /* We don't want to copy over all attributes.
6338 For example we don't want DW_AT_byte_size because otherwise we will no
6339 longer have a declaration and GDB will treat it as a definition. */
6343 case DW_AT_artificial
:
6344 case DW_AT_containing_type
:
6345 case DW_AT_external
:
6348 case DW_AT_virtuality
:
6349 case DW_AT_linkage_name
:
6350 case DW_AT_MIPS_linkage_name
:
6351 add_dwarf_attr (clone
, a
);
6353 case DW_AT_byte_size
:
6359 if (die
->comdat_type_p
)
6360 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6362 add_AT_flag (clone
, DW_AT_declaration
, 1);
6366 /* Copy the declaration context to the new type unit DIE. This includes
6367 any surrounding namespace or type declarations. If the DIE has an
6368 AT_specification attribute, it also includes attributes and children
6369 attached to the specification, and returns a pointer to the original
6370 parent of the declaration DIE. Returns NULL otherwise. */
6373 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
6376 dw_die_ref new_decl
;
6377 dw_die_ref orig_parent
= NULL
;
6379 decl
= get_AT_ref (die
, DW_AT_specification
);
6388 /* The original DIE will be changed to a declaration, and must
6389 be moved to be a child of the original declaration DIE. */
6390 orig_parent
= decl
->die_parent
;
6392 /* Copy the type node pointer from the new DIE to the original
6393 declaration DIE so we can forward references later. */
6394 decl
->comdat_type_p
= true;
6395 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
6397 remove_AT (die
, DW_AT_specification
);
6399 FOR_EACH_VEC_ELT (dw_attr_node
, decl
->die_attr
, ix
, a
)
6401 if (a
->dw_attr
!= DW_AT_name
6402 && a
->dw_attr
!= DW_AT_declaration
6403 && a
->dw_attr
!= DW_AT_external
)
6404 add_dwarf_attr (die
, a
);
6407 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree(c
)));
6410 if (decl
->die_parent
!= NULL
6411 && !is_unit_die (decl
->die_parent
))
6413 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
6414 if (new_decl
!= NULL
)
6416 remove_AT (new_decl
, DW_AT_signature
);
6417 add_AT_specification (die
, new_decl
);
6424 /* Generate the skeleton ancestor tree for the given NODE, then clone
6425 the DIE and add the clone into the tree. */
6428 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
6430 if (node
->new_die
!= NULL
)
6433 node
->new_die
= clone_as_declaration (node
->old_die
);
6435 if (node
->parent
!= NULL
)
6437 generate_skeleton_ancestor_tree (node
->parent
);
6438 add_child_die (node
->parent
->new_die
, node
->new_die
);
6442 /* Generate a skeleton tree of DIEs containing any declarations that are
6443 found in the original tree. We traverse the tree looking for declaration
6444 DIEs, and construct the skeleton from the bottom up whenever we find one. */
6447 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
6449 skeleton_chain_node node
;
6452 dw_die_ref prev
= NULL
;
6453 dw_die_ref next
= NULL
;
6455 node
.parent
= parent
;
6457 first
= c
= parent
->old_die
->die_child
;
6461 if (prev
== NULL
|| prev
->die_sib
== c
)
6464 next
= (c
== first
? NULL
: c
->die_sib
);
6466 node
.new_die
= NULL
;
6467 if (is_declaration_die (c
))
6469 /* Clone the existing DIE, move the original to the skeleton
6470 tree (which is in the main CU), and put the clone, with
6471 all the original's children, where the original came from. */
6472 dw_die_ref clone
= clone_die (c
);
6473 move_all_children (c
, clone
);
6475 replace_child (c
, clone
, prev
);
6476 generate_skeleton_ancestor_tree (parent
);
6477 add_child_die (parent
->new_die
, c
);
6481 generate_skeleton_bottom_up (&node
);
6482 } while (next
!= NULL
);
6485 /* Wrapper function for generate_skeleton_bottom_up. */
6488 generate_skeleton (dw_die_ref die
)
6490 skeleton_chain_node node
;
6493 node
.new_die
= NULL
;
6496 /* If this type definition is nested inside another type,
6497 always leave at least a declaration in its place. */
6498 if (die
->die_parent
!= NULL
&& is_type_die (die
->die_parent
))
6499 node
.new_die
= clone_as_declaration (die
);
6501 generate_skeleton_bottom_up (&node
);
6502 return node
.new_die
;
6505 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
6506 declaration. The original DIE is moved to a new compile unit so that
6507 existing references to it follow it to the new location. If any of the
6508 original DIE's descendants is a declaration, we need to replace the
6509 original DIE with a skeleton tree and move the declarations back into the
6513 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
6516 dw_die_ref skeleton
, orig_parent
;
6518 /* Copy the declaration context to the type unit DIE. If the returned
6519 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
6521 orig_parent
= copy_declaration_context (unit
, child
);
6523 skeleton
= generate_skeleton (child
);
6524 if (skeleton
== NULL
)
6525 remove_child_with_prev (child
, prev
);
6528 skeleton
->comdat_type_p
= true;
6529 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
6531 /* If the original DIE was a specification, we need to put
6532 the skeleton under the parent DIE of the declaration.
6533 This leaves the original declaration in the tree, but
6534 it will be pruned later since there are no longer any
6535 references to it. */
6536 if (orig_parent
!= NULL
)
6538 remove_child_with_prev (child
, prev
);
6539 add_child_die (orig_parent
, skeleton
);
6542 replace_child (child
, skeleton
, prev
);
6548 /* Traverse the DIE and set up additional .debug_types sections for each
6549 type worthy of being placed in a COMDAT section. */
6552 break_out_comdat_types (dw_die_ref die
)
6556 dw_die_ref prev
= NULL
;
6557 dw_die_ref next
= NULL
;
6558 dw_die_ref unit
= NULL
;
6560 first
= c
= die
->die_child
;
6564 if (prev
== NULL
|| prev
->die_sib
== c
)
6567 next
= (c
== first
? NULL
: c
->die_sib
);
6568 if (should_move_die_to_comdat (c
))
6570 dw_die_ref replacement
;
6571 comdat_type_node_ref type_node
;
6573 /* Create a new type unit DIE as the root for the new tree, and
6574 add it to the list of comdat types. */
6575 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
6576 add_AT_unsigned (unit
, DW_AT_language
,
6577 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
6578 type_node
= ggc_alloc_cleared_comdat_type_node ();
6579 type_node
->root_die
= unit
;
6580 type_node
->next
= comdat_type_list
;
6581 comdat_type_list
= type_node
;
6583 /* Generate the type signature. */
6584 generate_type_signature (c
, type_node
);
6586 /* Copy the declaration context, attributes, and children of the
6587 declaration into the new type unit DIE, then remove this DIE
6588 from the main CU (or replace it with a skeleton if necessary). */
6589 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
6590 type_node
->skeleton_die
= replacement
;
6592 /* Break out nested types into their own type units. */
6593 break_out_comdat_types (c
);
6595 /* Add the DIE to the new compunit. */
6596 add_child_die (unit
, c
);
6598 if (replacement
!= NULL
)
6601 else if (c
->die_tag
== DW_TAG_namespace
6602 || c
->die_tag
== DW_TAG_class_type
6603 || c
->die_tag
== DW_TAG_structure_type
6604 || c
->die_tag
== DW_TAG_union_type
)
6606 /* Look for nested types that can be broken out. */
6607 break_out_comdat_types (c
);
6609 } while (next
!= NULL
);
6612 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
6614 struct decl_table_entry
6620 /* Routines to manipulate hash table of copied declarations. */
6623 htab_decl_hash (const void *of
)
6625 const struct decl_table_entry
*const entry
=
6626 (const struct decl_table_entry
*) of
;
6628 return htab_hash_pointer (entry
->orig
);
6632 htab_decl_eq (const void *of1
, const void *of2
)
6634 const struct decl_table_entry
*const entry1
=
6635 (const struct decl_table_entry
*) of1
;
6636 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
6638 return entry1
->orig
== entry2
;
6642 htab_decl_del (void *what
)
6644 struct decl_table_entry
*entry
= (struct decl_table_entry
*) what
;
6649 /* Copy DIE and its ancestors, up to, but not including, the compile unit
6650 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
6651 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
6652 to check if the ancestor has already been copied into UNIT. */
6655 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
6657 dw_die_ref parent
= die
->die_parent
;
6658 dw_die_ref new_parent
= unit
;
6661 struct decl_table_entry
*entry
= NULL
;
6665 /* Check if the entry has already been copied to UNIT. */
6666 slot
= htab_find_slot_with_hash (decl_table
, die
,
6667 htab_hash_pointer (die
), INSERT
);
6668 if (*slot
!= HTAB_EMPTY_ENTRY
)
6670 entry
= (struct decl_table_entry
*) *slot
;
6674 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
6675 entry
= XCNEW (struct decl_table_entry
);
6683 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
6686 if (!is_unit_die (parent
))
6687 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
6690 copy
= clone_as_declaration (die
);
6691 add_child_die (new_parent
, copy
);
6693 if (decl_table
!= NULL
)
6695 /* Record the pointer to the copy. */
6702 /* Like clone_tree, but additionally enter all the children into
6703 the hash table decl_table. */
6706 clone_tree_hash (dw_die_ref die
, htab_t decl_table
)
6709 dw_die_ref clone
= clone_die (die
);
6710 struct decl_table_entry
*entry
;
6711 void **slot
= htab_find_slot_with_hash (decl_table
, die
,
6712 htab_hash_pointer (die
), INSERT
);
6713 /* Assert that DIE isn't in the hash table yet. If it would be there
6714 before, the ancestors would be necessarily there as well, therefore
6715 clone_tree_hash wouldn't be called. */
6716 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
6717 entry
= XCNEW (struct decl_table_entry
);
6719 entry
->copy
= clone
;
6722 FOR_EACH_CHILD (die
, c
,
6723 add_child_die (clone
, clone_tree_hash (c
, decl_table
)));
6728 /* Walk the DIE and its children, looking for references to incomplete
6729 or trivial types that are unmarked (i.e., that are not in the current
6733 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
6739 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6741 if (AT_class (a
) == dw_val_class_die_ref
)
6743 dw_die_ref targ
= AT_ref (a
);
6745 struct decl_table_entry
*entry
;
6747 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
6750 slot
= htab_find_slot_with_hash (decl_table
, targ
,
6751 htab_hash_pointer (targ
), INSERT
);
6753 if (*slot
!= HTAB_EMPTY_ENTRY
)
6755 /* TARG has already been copied, so we just need to
6756 modify the reference to point to the copy. */
6757 entry
= (struct decl_table_entry
*) *slot
;
6758 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
6762 dw_die_ref parent
= unit
;
6763 dw_die_ref copy
= clone_die (targ
);
6765 /* Record in DECL_TABLE that TARG has been copied.
6766 Need to do this now, before the recursive call,
6767 because DECL_TABLE may be expanded and SLOT
6768 would no longer be a valid pointer. */
6769 entry
= XCNEW (struct decl_table_entry
);
6774 FOR_EACH_CHILD (targ
, c
,
6775 add_child_die (copy
,
6776 clone_tree_hash (c
, decl_table
)));
6778 /* Make sure the cloned tree is marked as part of the
6782 /* If TARG has surrounding context, copy its ancestor tree
6783 into the new type unit. */
6784 if (targ
->die_parent
!= NULL
6785 && !is_unit_die (targ
->die_parent
))
6786 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
6789 add_child_die (parent
, copy
);
6790 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
6792 /* Make sure the newly-copied DIE is walked. If it was
6793 installed in a previously-added context, it won't
6794 get visited otherwise. */
6797 /* Find the highest point of the newly-added tree,
6798 mark each node along the way, and walk from there. */
6799 parent
->die_mark
= 1;
6800 while (parent
->die_parent
6801 && parent
->die_parent
->die_mark
== 0)
6803 parent
= parent
->die_parent
;
6804 parent
->die_mark
= 1;
6806 copy_decls_walk (unit
, parent
, decl_table
);
6812 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
6815 /* Copy declarations for "unworthy" types into the new comdat section.
6816 Incomplete types, modified types, and certain other types aren't broken
6817 out into comdat sections of their own, so they don't have a signature,
6818 and we need to copy the declaration into the same section so that we
6819 don't have an external reference. */
6822 copy_decls_for_unworthy_types (dw_die_ref unit
)
6827 decl_table
= htab_create (10, htab_decl_hash
, htab_decl_eq
, htab_decl_del
);
6828 copy_decls_walk (unit
, unit
, decl_table
);
6829 htab_delete (decl_table
);
6833 /* Traverse the DIE and add a sibling attribute if it may have the
6834 effect of speeding up access to siblings. To save some space,
6835 avoid generating sibling attributes for DIE's without children. */
6838 add_sibling_attributes (dw_die_ref die
)
6842 if (! die
->die_child
)
6845 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
6846 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
6848 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
6851 /* Output all location lists for the DIE and its children. */
6854 output_location_lists (dw_die_ref die
)
6860 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6861 if (AT_class (a
) == dw_val_class_loc_list
)
6862 output_loc_list (AT_loc_list (a
));
6864 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
6867 /* We want to limit the number of external references, because they are
6868 larger than local references: a relocation takes multiple words, and
6869 even a sig8 reference is always eight bytes, whereas a local reference
6870 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
6871 So if we encounter multiple external references to the same type DIE, we
6872 make a local typedef stub for it and redirect all references there.
6874 This is the element of the hash table for keeping track of these
6884 /* Hash an external_ref. */
6887 hash_external_ref (const void *p
)
6889 const struct external_ref
*r
= (const struct external_ref
*)p
;
6890 return htab_hash_pointer (r
->type
);
6893 /* Compare external_refs. */
6896 external_ref_eq (const void *p1
, const void *p2
)
6898 const struct external_ref
*r1
= (const struct external_ref
*)p1
;
6899 const struct external_ref
*r2
= (const struct external_ref
*)p2
;
6900 return r1
->type
== r2
->type
;
6903 /* Return a pointer to the external_ref for references to DIE. */
6905 static struct external_ref
*
6906 lookup_external_ref (htab_t map
, dw_die_ref die
)
6908 struct external_ref ref
, *ref_p
;
6912 slot
= htab_find_slot (map
, &ref
, INSERT
);
6913 if (*slot
!= HTAB_EMPTY_ENTRY
)
6914 return (struct external_ref
*) *slot
;
6916 ref_p
= XCNEW (struct external_ref
);
6922 /* Subroutine of optimize_external_refs, below.
6924 If we see a type skeleton, record it as our stub. If we see external
6925 references, remember how many we've seen. */
6928 optimize_external_refs_1 (dw_die_ref die
, htab_t map
)
6933 struct external_ref
*ref_p
;
6935 if (is_type_die (die
)
6936 && (c
= get_AT_ref (die
, DW_AT_signature
)))
6938 /* This is a local skeleton; use it for local references. */
6939 ref_p
= lookup_external_ref (map
, c
);
6943 /* Scan the DIE references, and remember any that refer to DIEs from
6944 other CUs (i.e. those which are not marked). */
6945 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
6946 if (AT_class (a
) == dw_val_class_die_ref
6947 && (c
= AT_ref (a
))->die_mark
== 0
6950 ref_p
= lookup_external_ref (map
, c
);
6954 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
6957 /* htab_traverse callback function for optimize_external_refs, below. SLOT
6958 points to an external_ref, DATA is the CU we're processing. If we don't
6959 already have a local stub, and we have multiple refs, build a stub. */
6962 build_local_stub (void **slot
, void *data
)
6964 struct external_ref
*ref_p
= (struct external_ref
*)*slot
;
6966 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
6968 /* We have multiple references to this type, so build a small stub.
6969 Both of these forms are a bit dodgy from the perspective of the
6970 DWARF standard, since technically they should have names. */
6971 dw_die_ref cu
= (dw_die_ref
) data
;
6972 dw_die_ref type
= ref_p
->type
;
6973 dw_die_ref stub
= NULL
;
6975 if (type
->comdat_type_p
)
6977 /* If we refer to this type via sig8, use AT_signature. */
6978 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
6979 add_AT_die_ref (stub
, DW_AT_signature
, type
);
6983 /* Otherwise, use a typedef with no name. */
6984 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
6985 add_AT_die_ref (stub
, DW_AT_type
, type
);
6994 /* DIE is a unit; look through all the DIE references to see if there are
6995 any external references to types, and if so, create local stubs for
6996 them which will be applied in build_abbrev_table. This is useful because
6997 references to local DIEs are smaller. */
7000 optimize_external_refs (dw_die_ref die
)
7002 htab_t map
= htab_create (10, hash_external_ref
, external_ref_eq
, free
);
7003 optimize_external_refs_1 (die
, map
);
7004 htab_traverse (map
, build_local_stub
, die
);
7008 /* The format of each DIE (and its attribute value pairs) is encoded in an
7009 abbreviation table. This routine builds the abbreviation table and assigns
7010 a unique abbreviation id for each abbreviation entry. The children of each
7011 die are visited recursively. */
7014 build_abbrev_table (dw_die_ref die
, htab_t extern_map
)
7016 unsigned long abbrev_id
;
7017 unsigned int n_alloc
;
7022 /* Scan the DIE references, and replace any that refer to
7023 DIEs from other CUs (i.e. those which are not marked) with
7024 the local stubs we built in optimize_external_refs. */
7025 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7026 if (AT_class (a
) == dw_val_class_die_ref
7027 && (c
= AT_ref (a
))->die_mark
== 0)
7029 struct external_ref
*ref_p
;
7030 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7032 ref_p
= lookup_external_ref (extern_map
, c
);
7033 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7034 change_AT_die_ref (a
, ref_p
->stub
);
7036 /* We aren't changing this reference, so mark it external. */
7037 set_AT_ref_external (a
, 1);
7040 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7042 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7043 dw_attr_ref die_a
, abbrev_a
;
7047 if (abbrev
->die_tag
!= die
->die_tag
)
7049 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7052 if (VEC_length (dw_attr_node
, abbrev
->die_attr
)
7053 != VEC_length (dw_attr_node
, die
->die_attr
))
7056 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, die_a
)
7058 abbrev_a
= VEC_index (dw_attr_node
, abbrev
->die_attr
, ix
);
7059 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7060 || (value_format (abbrev_a
) != value_format (die_a
)))
7070 if (abbrev_id
>= abbrev_die_table_in_use
)
7072 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7074 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7075 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7078 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7079 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7080 abbrev_die_table_allocated
= n_alloc
;
7083 ++abbrev_die_table_in_use
;
7084 abbrev_die_table
[abbrev_id
] = die
;
7087 die
->die_abbrev
= abbrev_id
;
7088 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
7091 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7094 constant_size (unsigned HOST_WIDE_INT value
)
7101 log
= floor_log2 (value
);
7104 log
= 1 << (floor_log2 (log
) + 1);
7109 /* Return the size of a DIE as it is represented in the
7110 .debug_info section. */
7112 static unsigned long
7113 size_of_die (dw_die_ref die
)
7115 unsigned long size
= 0;
7119 size
+= size_of_uleb128 (die
->die_abbrev
);
7120 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7122 switch (AT_class (a
))
7124 case dw_val_class_addr
:
7125 size
+= DWARF2_ADDR_SIZE
;
7127 case dw_val_class_offset
:
7128 size
+= DWARF_OFFSET_SIZE
;
7130 case dw_val_class_loc
:
7132 unsigned long lsize
= size_of_locs (AT_loc (a
));
7135 if (dwarf_version
>= 4)
7136 size
+= size_of_uleb128 (lsize
);
7138 size
+= constant_size (lsize
);
7142 case dw_val_class_loc_list
:
7143 size
+= DWARF_OFFSET_SIZE
;
7145 case dw_val_class_range_list
:
7146 size
+= DWARF_OFFSET_SIZE
;
7148 case dw_val_class_const
:
7149 size
+= size_of_sleb128 (AT_int (a
));
7151 case dw_val_class_unsigned_const
:
7153 int csize
= constant_size (AT_unsigned (a
));
7154 if (dwarf_version
== 3
7155 && a
->dw_attr
== DW_AT_data_member_location
7157 size
+= size_of_uleb128 (AT_unsigned (a
));
7162 case dw_val_class_const_double
:
7163 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
7164 if (HOST_BITS_PER_WIDE_INT
>= 64)
7167 case dw_val_class_vec
:
7168 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7169 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7170 + a
->dw_attr_val
.v
.val_vec
.length
7171 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7173 case dw_val_class_flag
:
7174 if (dwarf_version
>= 4)
7175 /* Currently all add_AT_flag calls pass in 1 as last argument,
7176 so DW_FORM_flag_present can be used. If that ever changes,
7177 we'll need to use DW_FORM_flag and have some optimization
7178 in build_abbrev_table that will change those to
7179 DW_FORM_flag_present if it is set to 1 in all DIEs using
7180 the same abbrev entry. */
7181 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7185 case dw_val_class_die_ref
:
7186 if (AT_ref_external (a
))
7188 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7189 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7190 is sized by target address length, whereas in DWARF3
7191 it's always sized as an offset. */
7192 if (use_debug_types
)
7193 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7194 else if (dwarf_version
== 2)
7195 size
+= DWARF2_ADDR_SIZE
;
7197 size
+= DWARF_OFFSET_SIZE
;
7200 size
+= DWARF_OFFSET_SIZE
;
7202 case dw_val_class_fde_ref
:
7203 size
+= DWARF_OFFSET_SIZE
;
7205 case dw_val_class_lbl_id
:
7206 size
+= DWARF2_ADDR_SIZE
;
7208 case dw_val_class_lineptr
:
7209 case dw_val_class_macptr
:
7210 size
+= DWARF_OFFSET_SIZE
;
7212 case dw_val_class_str
:
7213 if (AT_string_form (a
) == DW_FORM_strp
)
7214 size
+= DWARF_OFFSET_SIZE
;
7216 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7218 case dw_val_class_file
:
7219 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7221 case dw_val_class_data8
:
7224 case dw_val_class_vms_delta
:
7225 size
+= DWARF_OFFSET_SIZE
;
7235 /* Size the debugging information associated with a given DIE. Visits the
7236 DIE's children recursively. Updates the global variable next_die_offset, on
7237 each time through. Uses the current value of next_die_offset to update the
7238 die_offset field in each DIE. */
7241 calc_die_sizes (dw_die_ref die
)
7245 gcc_assert (die
->die_offset
== 0
7246 || (unsigned long int) die
->die_offset
== next_die_offset
);
7247 die
->die_offset
= next_die_offset
;
7248 next_die_offset
+= size_of_die (die
);
7250 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7252 if (die
->die_child
!= NULL
)
7253 /* Count the null byte used to terminate sibling lists. */
7254 next_die_offset
+= 1;
7257 /* Size just the base type children at the start of the CU.
7258 This is needed because build_abbrev needs to size locs
7259 and sizing of type based stack ops needs to know die_offset
7260 values for the base types. */
7263 calc_base_type_die_sizes (void)
7265 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7267 dw_die_ref base_type
;
7268 #if ENABLE_ASSERT_CHECKING
7269 dw_die_ref prev
= comp_unit_die ()->die_child
;
7272 die_offset
+= size_of_die (comp_unit_die ());
7273 for (i
= 0; VEC_iterate (dw_die_ref
, base_types
, i
, base_type
); i
++)
7275 #if ENABLE_ASSERT_CHECKING
7276 gcc_assert (base_type
->die_offset
== 0
7277 && prev
->die_sib
== base_type
7278 && base_type
->die_child
== NULL
7279 && base_type
->die_abbrev
);
7282 base_type
->die_offset
= die_offset
;
7283 die_offset
+= size_of_die (base_type
);
7287 /* Set the marks for a die and its children. We do this so
7288 that we know whether or not a reference needs to use FORM_ref_addr; only
7289 DIEs in the same CU will be marked. We used to clear out the offset
7290 and use that as the flag, but ran into ordering problems. */
7293 mark_dies (dw_die_ref die
)
7297 gcc_assert (!die
->die_mark
);
7300 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7303 /* Clear the marks for a die and its children. */
7306 unmark_dies (dw_die_ref die
)
7310 if (! use_debug_types
)
7311 gcc_assert (die
->die_mark
);
7314 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7317 /* Clear the marks for a die, its children and referred dies. */
7320 unmark_all_dies (dw_die_ref die
)
7330 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7332 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7333 if (AT_class (a
) == dw_val_class_die_ref
)
7334 unmark_all_dies (AT_ref (a
));
7337 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7338 generated for the compilation unit. */
7340 static unsigned long
7341 size_of_pubnames (VEC (pubname_entry
, gc
) * names
)
7347 size
= DWARF_PUBNAMES_HEADER_SIZE
;
7348 FOR_EACH_VEC_ELT (pubname_entry
, names
, i
, p
)
7349 if (names
!= pubtype_table
7350 || p
->die
->die_offset
!= 0
7351 || !flag_eliminate_unused_debug_types
)
7352 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
7354 size
+= DWARF_OFFSET_SIZE
;
7358 /* Return the size of the information in the .debug_aranges section. */
7360 static unsigned long
7361 size_of_aranges (void)
7365 size
= DWARF_ARANGES_HEADER_SIZE
;
7367 /* Count the address/length pair for this compilation unit. */
7368 if (text_section_used
)
7369 size
+= 2 * DWARF2_ADDR_SIZE
;
7370 if (cold_text_section_used
)
7371 size
+= 2 * DWARF2_ADDR_SIZE
;
7372 if (have_multiple_function_sections
)
7377 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, fde_idx
, fde
)
7379 if (!fde
->in_std_section
)
7380 size
+= 2 * DWARF2_ADDR_SIZE
;
7381 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
7382 size
+= 2 * DWARF2_ADDR_SIZE
;
7386 /* Count the two zero words used to terminated the address range table. */
7387 size
+= 2 * DWARF2_ADDR_SIZE
;
7391 /* Select the encoding of an attribute value. */
7393 static enum dwarf_form
7394 value_format (dw_attr_ref a
)
7396 switch (a
->dw_attr_val
.val_class
)
7398 case dw_val_class_addr
:
7399 /* Only very few attributes allow DW_FORM_addr. */
7404 case DW_AT_entry_pc
:
7405 case DW_AT_trampoline
:
7406 return DW_FORM_addr
;
7410 switch (DWARF2_ADDR_SIZE
)
7413 return DW_FORM_data1
;
7415 return DW_FORM_data2
;
7417 return DW_FORM_data4
;
7419 return DW_FORM_data8
;
7423 case dw_val_class_range_list
:
7424 case dw_val_class_loc_list
:
7425 if (dwarf_version
>= 4)
7426 return DW_FORM_sec_offset
;
7428 case dw_val_class_vms_delta
:
7429 case dw_val_class_offset
:
7430 switch (DWARF_OFFSET_SIZE
)
7433 return DW_FORM_data4
;
7435 return DW_FORM_data8
;
7439 case dw_val_class_loc
:
7440 if (dwarf_version
>= 4)
7441 return DW_FORM_exprloc
;
7442 switch (constant_size (size_of_locs (AT_loc (a
))))
7445 return DW_FORM_block1
;
7447 return DW_FORM_block2
;
7451 case dw_val_class_const
:
7452 return DW_FORM_sdata
;
7453 case dw_val_class_unsigned_const
:
7454 switch (constant_size (AT_unsigned (a
)))
7457 return DW_FORM_data1
;
7459 return DW_FORM_data2
;
7461 /* In DWARF3 DW_AT_data_member_location with
7462 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
7463 constant, so we need to use DW_FORM_udata if we need
7464 a large constant. */
7465 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
7466 return DW_FORM_udata
;
7467 return DW_FORM_data4
;
7469 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
7470 return DW_FORM_udata
;
7471 return DW_FORM_data8
;
7475 case dw_val_class_const_double
:
7476 switch (HOST_BITS_PER_WIDE_INT
)
7479 return DW_FORM_data2
;
7481 return DW_FORM_data4
;
7483 return DW_FORM_data8
;
7486 return DW_FORM_block1
;
7488 case dw_val_class_vec
:
7489 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
7490 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
7493 return DW_FORM_block1
;
7495 return DW_FORM_block2
;
7497 return DW_FORM_block4
;
7501 case dw_val_class_flag
:
7502 if (dwarf_version
>= 4)
7504 /* Currently all add_AT_flag calls pass in 1 as last argument,
7505 so DW_FORM_flag_present can be used. If that ever changes,
7506 we'll need to use DW_FORM_flag and have some optimization
7507 in build_abbrev_table that will change those to
7508 DW_FORM_flag_present if it is set to 1 in all DIEs using
7509 the same abbrev entry. */
7510 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7511 return DW_FORM_flag_present
;
7513 return DW_FORM_flag
;
7514 case dw_val_class_die_ref
:
7515 if (AT_ref_external (a
))
7516 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
7519 case dw_val_class_fde_ref
:
7520 return DW_FORM_data
;
7521 case dw_val_class_lbl_id
:
7522 return DW_FORM_addr
;
7523 case dw_val_class_lineptr
:
7524 case dw_val_class_macptr
:
7525 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
7526 case dw_val_class_str
:
7527 return AT_string_form (a
);
7528 case dw_val_class_file
:
7529 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
7532 return DW_FORM_data1
;
7534 return DW_FORM_data2
;
7536 return DW_FORM_data4
;
7541 case dw_val_class_data8
:
7542 return DW_FORM_data8
;
7549 /* Output the encoding of an attribute value. */
7552 output_value_format (dw_attr_ref a
)
7554 enum dwarf_form form
= value_format (a
);
7556 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
7559 /* Output the .debug_abbrev section which defines the DIE abbreviation
7563 output_abbrev_section (void)
7565 unsigned long abbrev_id
;
7567 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7569 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7573 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
7574 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
7575 dwarf_tag_name (abbrev
->die_tag
));
7577 if (abbrev
->die_child
!= NULL
)
7578 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
7580 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
7582 for (ix
= 0; VEC_iterate (dw_attr_node
, abbrev
->die_attr
, ix
, a_attr
);
7585 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
7586 dwarf_attr_name (a_attr
->dw_attr
));
7587 output_value_format (a_attr
);
7590 dw2_asm_output_data (1, 0, NULL
);
7591 dw2_asm_output_data (1, 0, NULL
);
7594 /* Terminate the table. */
7595 dw2_asm_output_data (1, 0, NULL
);
7598 /* Output a symbol we can use to refer to this DIE from another CU. */
7601 output_die_symbol (dw_die_ref die
)
7603 const char *sym
= die
->die_id
.die_symbol
;
7605 gcc_assert (!die
->comdat_type_p
);
7610 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
7611 /* We make these global, not weak; if the target doesn't support
7612 .linkonce, it doesn't support combining the sections, so debugging
7614 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
7616 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
7619 /* Return a new location list, given the begin and end range, and the
7622 static inline dw_loc_list_ref
7623 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
7624 const char *section
)
7626 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
7628 retlist
->begin
= begin
;
7630 retlist
->expr
= expr
;
7631 retlist
->section
= section
;
7636 /* Generate a new internal symbol for this location list node, if it
7637 hasn't got one yet. */
7640 gen_llsym (dw_loc_list_ref list
)
7642 gcc_assert (!list
->ll_symbol
);
7643 list
->ll_symbol
= gen_internal_sym ("LLST");
7646 /* Output the location list given to us. */
7649 output_loc_list (dw_loc_list_ref list_head
)
7651 dw_loc_list_ref curr
= list_head
;
7653 if (list_head
->emitted
)
7655 list_head
->emitted
= true;
7657 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
7659 /* Walk the location list, and output each range + expression. */
7660 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
7663 /* Don't output an entry that starts and ends at the same address. */
7664 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
7666 size
= size_of_locs (curr
->expr
);
7667 /* If the expression is too large, drop it on the floor. We could
7668 perhaps put it into DW_TAG_dwarf_procedure and refer to that
7669 in the expression, but >= 64KB expressions for a single value
7670 in a single range are unlikely very useful. */
7673 if (!have_multiple_function_sections
)
7675 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
7676 "Location list begin address (%s)",
7677 list_head
->ll_symbol
);
7678 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
7679 "Location list end address (%s)",
7680 list_head
->ll_symbol
);
7684 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
7685 "Location list begin address (%s)",
7686 list_head
->ll_symbol
);
7687 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
7688 "Location list end address (%s)",
7689 list_head
->ll_symbol
);
7692 /* Output the block length for this list of location operations. */
7693 gcc_assert (size
<= 0xffff);
7694 dw2_asm_output_data (2, size
, "%s", "Location expression size");
7696 output_loc_sequence (curr
->expr
, -1);
7699 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
7700 "Location list terminator begin (%s)",
7701 list_head
->ll_symbol
);
7702 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
7703 "Location list terminator end (%s)",
7704 list_head
->ll_symbol
);
7707 /* Output a type signature. */
7710 output_signature (const char *sig
, const char *name
)
7714 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
7715 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
7718 /* Output the DIE and its attributes. Called recursively to generate
7719 the definitions of each child DIE. */
7722 output_die (dw_die_ref die
)
7729 /* If someone in another CU might refer to us, set up a symbol for
7730 them to point to. */
7731 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
7732 output_die_symbol (die
);
7734 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
7735 (unsigned long)die
->die_offset
,
7736 dwarf_tag_name (die
->die_tag
));
7738 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7740 const char *name
= dwarf_attr_name (a
->dw_attr
);
7742 switch (AT_class (a
))
7744 case dw_val_class_addr
:
7745 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
7748 case dw_val_class_offset
:
7749 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
7753 case dw_val_class_range_list
:
7755 char *p
= strchr (ranges_section_label
, '\0');
7757 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
7758 a
->dw_attr_val
.v
.val_offset
);
7759 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
7760 debug_ranges_section
, "%s", name
);
7765 case dw_val_class_loc
:
7766 size
= size_of_locs (AT_loc (a
));
7768 /* Output the block length for this list of location operations. */
7769 if (dwarf_version
>= 4)
7770 dw2_asm_output_data_uleb128 (size
, "%s", name
);
7772 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
7774 output_loc_sequence (AT_loc (a
), -1);
7777 case dw_val_class_const
:
7778 /* ??? It would be slightly more efficient to use a scheme like is
7779 used for unsigned constants below, but gdb 4.x does not sign
7780 extend. Gdb 5.x does sign extend. */
7781 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
7784 case dw_val_class_unsigned_const
:
7786 int csize
= constant_size (AT_unsigned (a
));
7787 if (dwarf_version
== 3
7788 && a
->dw_attr
== DW_AT_data_member_location
7790 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
7792 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
7796 case dw_val_class_const_double
:
7798 unsigned HOST_WIDE_INT first
, second
;
7800 if (HOST_BITS_PER_WIDE_INT
>= 64)
7801 dw2_asm_output_data (1,
7802 HOST_BITS_PER_DOUBLE_INT
7803 / HOST_BITS_PER_CHAR
,
7806 if (WORDS_BIG_ENDIAN
)
7808 first
= a
->dw_attr_val
.v
.val_double
.high
;
7809 second
= a
->dw_attr_val
.v
.val_double
.low
;
7813 first
= a
->dw_attr_val
.v
.val_double
.low
;
7814 second
= a
->dw_attr_val
.v
.val_double
.high
;
7817 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
7819 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
7824 case dw_val_class_vec
:
7826 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
7827 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
7831 dw2_asm_output_data (constant_size (len
* elt_size
),
7832 len
* elt_size
, "%s", name
);
7833 if (elt_size
> sizeof (HOST_WIDE_INT
))
7838 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
7841 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
7842 "fp or vector constant word %u", i
);
7846 case dw_val_class_flag
:
7847 if (dwarf_version
>= 4)
7849 /* Currently all add_AT_flag calls pass in 1 as last argument,
7850 so DW_FORM_flag_present can be used. If that ever changes,
7851 we'll need to use DW_FORM_flag and have some optimization
7852 in build_abbrev_table that will change those to
7853 DW_FORM_flag_present if it is set to 1 in all DIEs using
7854 the same abbrev entry. */
7855 gcc_assert (AT_flag (a
) == 1);
7857 fprintf (asm_out_file
, "\t\t\t%s %s\n",
7858 ASM_COMMENT_START
, name
);
7861 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
7864 case dw_val_class_loc_list
:
7866 char *sym
= AT_loc_list (a
)->ll_symbol
;
7869 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
7874 case dw_val_class_die_ref
:
7875 if (AT_ref_external (a
))
7877 if (AT_ref (a
)->comdat_type_p
)
7879 comdat_type_node_ref type_node
=
7880 AT_ref (a
)->die_id
.die_type_node
;
7882 gcc_assert (type_node
);
7883 output_signature (type_node
->signature
, name
);
7887 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
7891 /* In DWARF2, DW_FORM_ref_addr is sized by target address
7892 length, whereas in DWARF3 it's always sized as an
7894 if (dwarf_version
== 2)
7895 size
= DWARF2_ADDR_SIZE
;
7897 size
= DWARF_OFFSET_SIZE
;
7898 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
7904 gcc_assert (AT_ref (a
)->die_offset
);
7905 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
7910 case dw_val_class_fde_ref
:
7914 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
7915 a
->dw_attr_val
.v
.val_fde_index
* 2);
7916 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
7921 case dw_val_class_vms_delta
:
7922 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
7923 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
7927 case dw_val_class_lbl_id
:
7928 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
7931 case dw_val_class_lineptr
:
7932 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
7933 debug_line_section
, "%s", name
);
7936 case dw_val_class_macptr
:
7937 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
7938 debug_macinfo_section
, "%s", name
);
7941 case dw_val_class_str
:
7942 if (AT_string_form (a
) == DW_FORM_strp
)
7943 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
7944 a
->dw_attr_val
.v
.val_str
->label
,
7946 "%s: \"%s\"", name
, AT_string (a
));
7948 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
7951 case dw_val_class_file
:
7953 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
7955 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
7956 a
->dw_attr_val
.v
.val_file
->filename
);
7960 case dw_val_class_data8
:
7964 for (i
= 0; i
< 8; i
++)
7965 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
7966 i
== 0 ? "%s" : NULL
, name
);
7975 FOR_EACH_CHILD (die
, c
, output_die (c
));
7977 /* Add null byte to terminate sibling list. */
7978 if (die
->die_child
!= NULL
)
7979 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
7980 (unsigned long) die
->die_offset
);
7983 /* Output the compilation unit that appears at the beginning of the
7984 .debug_info section, and precedes the DIE descriptions. */
7987 output_compilation_unit_header (void)
7989 int ver
= dwarf_version
;
7991 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7992 dw2_asm_output_data (4, 0xffffffff,
7993 "Initial length escape value indicating 64-bit DWARF extension");
7994 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
7995 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
7996 "Length of Compilation Unit Info");
7997 dw2_asm_output_data (2, ver
, "DWARF version number");
7998 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
7999 debug_abbrev_section
,
8000 "Offset Into Abbrev. Section");
8001 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8004 /* Output the compilation unit DIE and its children. */
8007 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8009 const char *secname
, *oldsym
;
8013 /* Unless we are outputting main CU, we may throw away empty ones. */
8014 if (!output_if_empty
&& die
->die_child
== NULL
)
8017 /* Even if there are no children of this DIE, we must output the information
8018 about the compilation unit. Otherwise, on an empty translation unit, we
8019 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8020 will then complain when examining the file. First mark all the DIEs in
8021 this CU so we know which get local refs. */
8024 extern_map
= optimize_external_refs (die
);
8026 build_abbrev_table (die
, extern_map
);
8028 htab_delete (extern_map
);
8030 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8031 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8032 calc_die_sizes (die
);
8034 oldsym
= die
->die_id
.die_symbol
;
8037 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8039 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8041 die
->die_id
.die_symbol
= NULL
;
8042 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8046 switch_to_section (debug_info_section
);
8047 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8048 info_section_emitted
= true;
8051 /* Output debugging information. */
8052 output_compilation_unit_header ();
8055 /* Leave the marks on the main CU, so we can check them in
8060 die
->die_id
.die_symbol
= oldsym
;
8064 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
8065 and .debug_pubtypes. This is configured per-target, but can be
8066 overridden by the -gpubnames or -gno-pubnames options. */
8069 want_pubnames (void)
8071 return (debug_generate_pub_sections
!= -1
8072 ? debug_generate_pub_sections
8073 : targetm
.want_debug_pub_sections
);
8076 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
8079 add_AT_pubnames (dw_die_ref die
)
8081 if (want_pubnames ())
8082 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
8085 /* Output a comdat type unit DIE and its children. */
8088 output_comdat_type_unit (comdat_type_node
*node
)
8090 const char *secname
;
8093 #if defined (OBJECT_FORMAT_ELF)
8098 /* First mark all the DIEs in this CU so we know which get local refs. */
8099 mark_dies (node
->root_die
);
8101 extern_map
= optimize_external_refs (node
->root_die
);
8103 build_abbrev_table (node
->root_die
, extern_map
);
8105 htab_delete (extern_map
);
8107 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8108 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
8109 calc_die_sizes (node
->root_die
);
8111 #if defined (OBJECT_FORMAT_ELF)
8112 secname
= ".debug_types";
8113 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8114 sprintf (tmp
, "wt.");
8115 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8116 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8117 comdat_key
= get_identifier (tmp
);
8118 targetm
.asm_out
.named_section (secname
,
8119 SECTION_DEBUG
| SECTION_LINKONCE
,
8122 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8123 sprintf (tmp
, ".gnu.linkonce.wt.");
8124 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8125 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8127 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8130 /* Output debugging information. */
8131 output_compilation_unit_header ();
8132 output_signature (node
->signature
, "Type Signature");
8133 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
8134 "Offset to Type DIE");
8135 output_die (node
->root_die
);
8137 unmark_dies (node
->root_die
);
8140 /* Return the DWARF2/3 pubname associated with a decl. */
8143 dwarf2_name (tree decl
, int scope
)
8145 if (DECL_NAMELESS (decl
))
8147 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
8150 /* Add a new entry to .debug_pubnames if appropriate. */
8153 add_pubname_string (const char *str
, dw_die_ref die
)
8158 e
.name
= xstrdup (str
);
8159 VEC_safe_push (pubname_entry
, gc
, pubname_table
, &e
);
8163 add_pubname (tree decl
, dw_die_ref die
)
8165 if (!want_pubnames ())
8168 /* Don't add items to the table when we expect that the consumer will have
8169 just read the enclosing die. For example, if the consumer is looking at a
8170 class_member, it will either be inside the class already, or will have just
8171 looked up the class to find the member. Either way, searching the class is
8172 faster than searching the index. */
8173 if ((TREE_PUBLIC (decl
) && !is_class_die (die
->die_parent
))
8174 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
8176 const char *name
= dwarf2_name (decl
, 1);
8179 add_pubname_string (name
, die
);
8183 /* Add an enumerator to the pubnames section. */
8186 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
8190 gcc_assert (scope_name
);
8191 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
8193 VEC_safe_push (pubname_entry
, gc
, pubname_table
, &e
);
8196 /* Add a new entry to .debug_pubtypes if appropriate. */
8199 add_pubtype (tree decl
, dw_die_ref die
)
8203 if (!want_pubnames ())
8206 if ((TREE_PUBLIC (decl
)
8207 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
8208 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
8211 const char *scope_name
= "";
8212 const char *sep
= is_cxx () ? "::" : ".";
8215 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
8216 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
8218 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
8219 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
8220 scope_name
= concat (scope_name
, sep
, NULL
);
8226 name
= type_tag (decl
);
8228 name
= lang_hooks
.dwarf_name (decl
, 1);
8230 /* If we don't have a name for the type, there's no point in adding
8232 if (name
!= NULL
&& name
[0] != '\0')
8235 e
.name
= concat (scope_name
, name
, NULL
);
8236 VEC_safe_push (pubname_entry
, gc
, pubtype_table
, &e
);
8239 /* Although it might be more consistent to add the pubinfo for the
8240 enumerators as their dies are created, they should only be added if the
8241 enum type meets the criteria above. So rather than re-check the parent
8242 enum type whenever an enumerator die is created, just output them all
8243 here. This isn't protected by the name conditional because anonymous
8244 enums don't have names. */
8245 if (die
->die_tag
== DW_TAG_enumeration_type
)
8249 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
8254 /* Output the public names table used to speed up access to externally
8255 visible names; or the public types table used to find type definitions. */
8258 output_pubnames (VEC (pubname_entry
, gc
) * names
)
8261 unsigned long pubnames_length
= size_of_pubnames (names
);
8264 if (!want_pubnames () || !info_section_emitted
)
8266 if (names
== pubname_table
)
8267 switch_to_section (debug_pubnames_section
);
8269 switch_to_section (debug_pubtypes_section
);
8270 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8271 dw2_asm_output_data (4, 0xffffffff,
8272 "Initial length escape value indicating 64-bit DWARF extension");
8273 if (names
== pubname_table
)
8274 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8275 "Length of Public Names Info");
8277 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8278 "Length of Public Type Names Info");
8279 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
8280 dw2_asm_output_data (2, 2, "DWARF Version");
8281 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
8283 "Offset of Compilation Unit Info");
8284 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
8285 "Compilation Unit Length");
8287 FOR_EACH_VEC_ELT (pubname_entry
, names
, i
, pub
)
8289 /* Enumerator names are part of the pubname table, but the parent
8290 DW_TAG_enumeration_type die may have been pruned. Don't output
8291 them if that is the case. */
8292 if (pub
->die
->die_tag
== DW_TAG_enumerator
&& !pub
->die
->die_mark
)
8295 /* We shouldn't see pubnames for DIEs outside of the main CU. */
8296 if (names
== pubname_table
)
8297 gcc_assert (pub
->die
->die_mark
);
8299 if (names
!= pubtype_table
8300 || pub
->die
->die_offset
!= 0
8301 || !flag_eliminate_unused_debug_types
)
8303 dw_offset die_offset
= pub
->die
->die_offset
;
8305 /* If we're putting types in their own .debug_types sections,
8306 the .debug_pubtypes table will still point to the compile
8307 unit (not the type unit), so we want to use the offset of
8308 the skeleton DIE (if there is one). */
8309 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
8311 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
8313 if (type_node
!= NULL
)
8314 die_offset
= (type_node
->skeleton_die
!= NULL
8315 ? type_node
->skeleton_die
->die_offset
8319 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
8321 dw2_asm_output_nstring (pub
->name
, -1, "external name");
8325 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
8328 /* Output the information that goes into the .debug_aranges table.
8329 Namely, define the beginning and ending address range of the
8330 text section generated for this compilation unit. */
8333 output_aranges (unsigned long aranges_length
)
8337 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8338 dw2_asm_output_data (4, 0xffffffff,
8339 "Initial length escape value indicating 64-bit DWARF extension");
8340 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
8341 "Length of Address Ranges Info");
8342 /* Version number for aranges is still 2, even in DWARF3. */
8343 dw2_asm_output_data (2, 2, "DWARF Version");
8344 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
8346 "Offset of Compilation Unit Info");
8347 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
8348 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8350 /* We need to align to twice the pointer size here. */
8351 if (DWARF_ARANGES_PAD_SIZE
)
8353 /* Pad using a 2 byte words so that padding is correct for any
8355 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8356 2 * DWARF2_ADDR_SIZE
);
8357 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
8358 dw2_asm_output_data (2, 0, NULL
);
8361 /* It is necessary not to output these entries if the sections were
8362 not used; if the sections were not used, the length will be 0 and
8363 the address may end up as 0 if the section is discarded by ld
8364 --gc-sections, leaving an invalid (0, 0) entry that can be
8365 confused with the terminator. */
8366 if (text_section_used
)
8368 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
8369 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
8370 text_section_label
, "Length");
8372 if (cold_text_section_used
)
8374 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
8376 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
8377 cold_text_section_label
, "Length");
8380 if (have_multiple_function_sections
)
8385 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, fde_idx
, fde
)
8387 if (DECL_IGNORED_P (fde
->decl
))
8389 if (!fde
->in_std_section
)
8391 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
8393 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
8394 fde
->dw_fde_begin
, "Length");
8396 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8398 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
8400 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
8401 fde
->dw_fde_second_begin
, "Length");
8406 /* Output the terminator words. */
8407 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8408 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8411 /* Add a new entry to .debug_ranges. Return the offset at which it
8415 add_ranges_num (int num
)
8417 unsigned int in_use
= ranges_table_in_use
;
8419 if (in_use
== ranges_table_allocated
)
8421 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
8422 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
8423 ranges_table_allocated
);
8424 memset (ranges_table
+ ranges_table_in_use
, 0,
8425 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
8428 ranges_table
[in_use
].num
= num
;
8429 ranges_table_in_use
= in_use
+ 1;
8431 return in_use
* 2 * DWARF2_ADDR_SIZE
;
8434 /* Add a new entry to .debug_ranges corresponding to a block, or a
8435 range terminator if BLOCK is NULL. */
8438 add_ranges (const_tree block
)
8440 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
8443 /* Add a new entry to .debug_ranges corresponding to a pair of
8447 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
8450 unsigned int in_use
= ranges_by_label_in_use
;
8451 unsigned int offset
;
8453 if (in_use
== ranges_by_label_allocated
)
8455 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
8456 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
8458 ranges_by_label_allocated
);
8459 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
8460 RANGES_TABLE_INCREMENT
8461 * sizeof (struct dw_ranges_by_label_struct
));
8464 ranges_by_label
[in_use
].begin
= begin
;
8465 ranges_by_label
[in_use
].end
= end
;
8466 ranges_by_label_in_use
= in_use
+ 1;
8468 offset
= add_ranges_num (-(int)in_use
- 1);
8471 add_AT_range_list (die
, DW_AT_ranges
, offset
);
8477 output_ranges (void)
8480 static const char *const start_fmt
= "Offset %#x";
8481 const char *fmt
= start_fmt
;
8483 for (i
= 0; i
< ranges_table_in_use
; i
++)
8485 int block_num
= ranges_table
[i
].num
;
8489 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
8490 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
8492 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
8493 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
8495 /* If all code is in the text section, then the compilation
8496 unit base address defaults to DW_AT_low_pc, which is the
8497 base of the text section. */
8498 if (!have_multiple_function_sections
)
8500 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
8502 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8503 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
8504 text_section_label
, NULL
);
8507 /* Otherwise, the compilation unit base address is zero,
8508 which allows us to use absolute addresses, and not worry
8509 about whether the target supports cross-section
8513 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
8514 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8515 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
8521 /* Negative block_num stands for an index into ranges_by_label. */
8522 else if (block_num
< 0)
8524 int lab_idx
= - block_num
- 1;
8526 if (!have_multiple_function_sections
)
8530 /* If we ever use add_ranges_by_labels () for a single
8531 function section, all we have to do is to take out
8533 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
8534 ranges_by_label
[lab_idx
].begin
,
8536 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8537 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
8538 ranges_by_label
[lab_idx
].end
,
8539 text_section_label
, NULL
);
8544 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
8545 ranges_by_label
[lab_idx
].begin
,
8546 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8547 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
8548 ranges_by_label
[lab_idx
].end
,
8554 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8555 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8561 /* Data structure containing information about input files. */
8564 const char *path
; /* Complete file name. */
8565 const char *fname
; /* File name part. */
8566 int length
; /* Length of entire string. */
8567 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
8568 int dir_idx
; /* Index in directory table. */
8571 /* Data structure containing information about directories with source
8575 const char *path
; /* Path including directory name. */
8576 int length
; /* Path length. */
8577 int prefix
; /* Index of directory entry which is a prefix. */
8578 int count
; /* Number of files in this directory. */
8579 int dir_idx
; /* Index of directory used as base. */
8582 /* Callback function for file_info comparison. We sort by looking at
8583 the directories in the path. */
8586 file_info_cmp (const void *p1
, const void *p2
)
8588 const struct file_info
*const s1
= (const struct file_info
*) p1
;
8589 const struct file_info
*const s2
= (const struct file_info
*) p2
;
8590 const unsigned char *cp1
;
8591 const unsigned char *cp2
;
8593 /* Take care of file names without directories. We need to make sure that
8594 we return consistent values to qsort since some will get confused if
8595 we return the same value when identical operands are passed in opposite
8596 orders. So if neither has a directory, return 0 and otherwise return
8597 1 or -1 depending on which one has the directory. */
8598 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
8599 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
8601 cp1
= (const unsigned char *) s1
->path
;
8602 cp2
= (const unsigned char *) s2
->path
;
8608 /* Reached the end of the first path? If so, handle like above. */
8609 if ((cp1
== (const unsigned char *) s1
->fname
)
8610 || (cp2
== (const unsigned char *) s2
->fname
))
8611 return ((cp2
== (const unsigned char *) s2
->fname
)
8612 - (cp1
== (const unsigned char *) s1
->fname
));
8614 /* Character of current path component the same? */
8615 else if (*cp1
!= *cp2
)
8620 struct file_name_acquire_data
8622 struct file_info
*files
;
8627 /* Traversal function for the hash table. */
8630 file_name_acquire (void ** slot
, void *data
)
8632 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
8633 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
8634 struct file_info
*fi
;
8637 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
8639 if (! d
->emitted_number
)
8642 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
8644 fi
= fnad
->files
+ fnad
->used_files
++;
8646 /* Skip all leading "./". */
8648 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
8651 /* Create a new array entry. */
8653 fi
->length
= strlen (f
);
8656 /* Search for the file name part. */
8657 f
= strrchr (f
, DIR_SEPARATOR
);
8658 #if defined (DIR_SEPARATOR_2)
8660 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
8664 if (f
== NULL
|| f
< g
)
8670 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
8674 /* Output the directory table and the file name table. We try to minimize
8675 the total amount of memory needed. A heuristic is used to avoid large
8676 slowdowns with many input files. */
8679 output_file_names (void)
8681 struct file_name_acquire_data fnad
;
8683 struct file_info
*files
;
8684 struct dir_info
*dirs
;
8692 if (!last_emitted_file
)
8694 dw2_asm_output_data (1, 0, "End directory table");
8695 dw2_asm_output_data (1, 0, "End file name table");
8699 numfiles
= last_emitted_file
->emitted_number
;
8701 /* Allocate the various arrays we need. */
8702 files
= XALLOCAVEC (struct file_info
, numfiles
);
8703 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
8706 fnad
.used_files
= 0;
8707 fnad
.max_files
= numfiles
;
8708 htab_traverse (file_table
, file_name_acquire
, &fnad
);
8709 gcc_assert (fnad
.used_files
== fnad
.max_files
);
8711 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
8713 /* Find all the different directories used. */
8714 dirs
[0].path
= files
[0].path
;
8715 dirs
[0].length
= files
[0].fname
- files
[0].path
;
8716 dirs
[0].prefix
= -1;
8718 dirs
[0].dir_idx
= 0;
8719 files
[0].dir_idx
= 0;
8722 for (i
= 1; i
< numfiles
; i
++)
8723 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
8724 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
8725 dirs
[ndirs
- 1].length
) == 0)
8727 /* Same directory as last entry. */
8728 files
[i
].dir_idx
= ndirs
- 1;
8729 ++dirs
[ndirs
- 1].count
;
8735 /* This is a new directory. */
8736 dirs
[ndirs
].path
= files
[i
].path
;
8737 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
8738 dirs
[ndirs
].count
= 1;
8739 dirs
[ndirs
].dir_idx
= ndirs
;
8740 files
[i
].dir_idx
= ndirs
;
8742 /* Search for a prefix. */
8743 dirs
[ndirs
].prefix
= -1;
8744 for (j
= 0; j
< ndirs
; j
++)
8745 if (dirs
[j
].length
< dirs
[ndirs
].length
8746 && dirs
[j
].length
> 1
8747 && (dirs
[ndirs
].prefix
== -1
8748 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
8749 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
8750 dirs
[ndirs
].prefix
= j
;
8755 /* Now to the actual work. We have to find a subset of the directories which
8756 allow expressing the file name using references to the directory table
8757 with the least amount of characters. We do not do an exhaustive search
8758 where we would have to check out every combination of every single
8759 possible prefix. Instead we use a heuristic which provides nearly optimal
8760 results in most cases and never is much off. */
8761 saved
= XALLOCAVEC (int, ndirs
);
8762 savehere
= XALLOCAVEC (int, ndirs
);
8764 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
8765 for (i
= 0; i
< ndirs
; i
++)
8770 /* We can always save some space for the current directory. But this
8771 does not mean it will be enough to justify adding the directory. */
8772 savehere
[i
] = dirs
[i
].length
;
8773 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
8775 for (j
= i
+ 1; j
< ndirs
; j
++)
8778 if (saved
[j
] < dirs
[i
].length
)
8780 /* Determine whether the dirs[i] path is a prefix of the
8785 while (k
!= -1 && k
!= (int) i
)
8790 /* Yes it is. We can possibly save some memory by
8791 writing the filenames in dirs[j] relative to
8793 savehere
[j
] = dirs
[i
].length
;
8794 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
8799 /* Check whether we can save enough to justify adding the dirs[i]
8801 if (total
> dirs
[i
].length
+ 1)
8803 /* It's worthwhile adding. */
8804 for (j
= i
; j
< ndirs
; j
++)
8805 if (savehere
[j
] > 0)
8807 /* Remember how much we saved for this directory so far. */
8808 saved
[j
] = savehere
[j
];
8810 /* Remember the prefix directory. */
8811 dirs
[j
].dir_idx
= i
;
8816 /* Emit the directory name table. */
8817 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
8818 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
8819 dw2_asm_output_nstring (dirs
[i
].path
,
8821 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
8822 "Directory Entry: %#x", i
+ idx_offset
);
8824 dw2_asm_output_data (1, 0, "End directory table");
8826 /* We have to emit them in the order of emitted_number since that's
8827 used in the debug info generation. To do this efficiently we
8828 generate a back-mapping of the indices first. */
8829 backmap
= XALLOCAVEC (int, numfiles
);
8830 for (i
= 0; i
< numfiles
; i
++)
8831 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
8833 /* Now write all the file names. */
8834 for (i
= 0; i
< numfiles
; i
++)
8836 int file_idx
= backmap
[i
];
8837 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
8839 #ifdef VMS_DEBUGGING_INFO
8840 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
8842 /* Setting these fields can lead to debugger miscomparisons,
8843 but VMS Debug requires them to be set correctly. */
8848 int maxfilelen
= strlen (files
[file_idx
].path
)
8849 + dirs
[dir_idx
].length
8850 + MAX_VMS_VERSION_LEN
+ 1;
8851 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
8853 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
8854 snprintf (filebuf
, maxfilelen
, "%s;%d",
8855 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
8857 dw2_asm_output_nstring
8858 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
8860 /* Include directory index. */
8861 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
8863 /* Modification time. */
8864 dw2_asm_output_data_uleb128
8865 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
8869 /* File length in bytes. */
8870 dw2_asm_output_data_uleb128
8871 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
8875 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
8876 "File Entry: %#x", (unsigned) i
+ 1);
8878 /* Include directory index. */
8879 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
8881 /* Modification time. */
8882 dw2_asm_output_data_uleb128 (0, NULL
);
8884 /* File length in bytes. */
8885 dw2_asm_output_data_uleb128 (0, NULL
);
8886 #endif /* VMS_DEBUGGING_INFO */
8889 dw2_asm_output_data (1, 0, "End file name table");
8893 /* Output one line number table into the .debug_line section. */
8896 output_one_line_info_table (dw_line_info_table
*table
)
8898 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8899 unsigned int current_line
= 1;
8900 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
8901 dw_line_info_entry
*ent
;
8904 FOR_EACH_VEC_ELT (dw_line_info_entry
, table
->entries
, i
, ent
)
8906 switch (ent
->opcode
)
8908 case LI_set_address
:
8909 /* ??? Unfortunately, we have little choice here currently, and
8910 must always use the most general form. GCC does not know the
8911 address delta itself, so we can't use DW_LNS_advance_pc. Many
8912 ports do have length attributes which will give an upper bound
8913 on the address range. We could perhaps use length attributes
8914 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
8915 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
8917 /* This can handle any delta. This takes
8918 4+DWARF2_ADDR_SIZE bytes. */
8919 dw2_asm_output_data (1, 0, "set address %s", line_label
);
8920 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8921 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8922 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
8926 if (ent
->val
== current_line
)
8928 /* We still need to start a new row, so output a copy insn. */
8929 dw2_asm_output_data (1, DW_LNS_copy
,
8930 "copy line %u", current_line
);
8934 int line_offset
= ent
->val
- current_line
;
8935 int line_delta
= line_offset
- DWARF_LINE_BASE
;
8937 current_line
= ent
->val
;
8938 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
8940 /* This can handle deltas from -10 to 234, using the current
8941 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
8942 This takes 1 byte. */
8943 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
8944 "line %u", current_line
);
8948 /* This can handle any delta. This takes at least 4 bytes,
8949 depending on the value being encoded. */
8950 dw2_asm_output_data (1, DW_LNS_advance_line
,
8951 "advance to line %u", current_line
);
8952 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
8953 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
8959 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
8960 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
8964 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
8965 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
8968 case LI_negate_stmt
:
8969 current_is_stmt
= !current_is_stmt
;
8970 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
8971 "is_stmt %d", current_is_stmt
);
8974 case LI_set_prologue_end
:
8975 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
8976 "set prologue end");
8979 case LI_set_epilogue_begin
:
8980 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
8981 "set epilogue begin");
8984 case LI_set_discriminator
:
8985 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
8986 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
8987 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
8988 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
8993 /* Emit debug info for the address of the end of the table. */
8994 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
8995 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8996 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8997 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
8999 dw2_asm_output_data (1, 0, "end sequence");
9000 dw2_asm_output_data_uleb128 (1, NULL
);
9001 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
9004 /* Output the source line number correspondence information. This
9005 information goes into the .debug_line section. */
9008 output_line_info (void)
9010 char l1
[20], l2
[20], p1
[20], p2
[20];
9011 int ver
= dwarf_version
;
9012 bool saw_one
= false;
9015 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
9016 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
9017 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
9018 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
9020 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9021 dw2_asm_output_data (4, 0xffffffff,
9022 "Initial length escape value indicating 64-bit DWARF extension");
9023 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
9024 "Length of Source Line Info");
9025 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
9027 dw2_asm_output_data (2, ver
, "DWARF Version");
9028 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
9029 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
9031 /* Define the architecture-dependent minimum instruction length (in bytes).
9032 In this implementation of DWARF, this field is used for information
9033 purposes only. Since GCC generates assembly language, we have no
9034 a priori knowledge of how many instruction bytes are generated for each
9035 source line, and therefore can use only the DW_LNE_set_address and
9036 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
9037 this as '1', which is "correct enough" for all architectures,
9038 and don't let the target override. */
9039 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
9042 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
9043 "Maximum Operations Per Instruction");
9044 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
9045 "Default is_stmt_start flag");
9046 dw2_asm_output_data (1, DWARF_LINE_BASE
,
9047 "Line Base Value (Special Opcodes)");
9048 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
9049 "Line Range Value (Special Opcodes)");
9050 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
9051 "Special Opcode Base");
9053 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
9058 case DW_LNS_advance_pc
:
9059 case DW_LNS_advance_line
:
9060 case DW_LNS_set_file
:
9061 case DW_LNS_set_column
:
9062 case DW_LNS_fixed_advance_pc
:
9063 case DW_LNS_set_isa
:
9071 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
9075 /* Write out the information about the files we use. */
9076 output_file_names ();
9077 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
9079 if (separate_line_info
)
9081 dw_line_info_table
*table
;
9084 FOR_EACH_VEC_ELT (dw_line_info_table_p
, separate_line_info
, i
, table
)
9087 output_one_line_info_table (table
);
9091 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
9093 output_one_line_info_table (cold_text_section_line_info
);
9097 /* ??? Some Darwin linkers crash on a .debug_line section with no
9098 sequences. Further, merely a DW_LNE_end_sequence entry is not
9099 sufficient -- the address column must also be initialized.
9100 Make sure to output at least one set_address/end_sequence pair,
9101 choosing .text since that section is always present. */
9102 if (text_section_line_info
->in_use
|| !saw_one
)
9103 output_one_line_info_table (text_section_line_info
);
9105 /* Output the marker for the end of the line number info. */
9106 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9109 /* Given a pointer to a tree node for some base type, return a pointer to
9110 a DIE that describes the given type.
9112 This routine must only be called for GCC type nodes that correspond to
9113 Dwarf base (fundamental) types. */
9116 base_type_die (tree type
)
9118 dw_die_ref base_type_result
;
9119 enum dwarf_type encoding
;
9121 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
9124 /* If this is a subtype that should not be emitted as a subrange type,
9125 use the base type. See subrange_type_for_debug_p. */
9126 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
9127 type
= TREE_TYPE (type
);
9129 switch (TREE_CODE (type
))
9132 if ((dwarf_version
>= 4 || !dwarf_strict
)
9134 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9135 && DECL_IS_BUILTIN (TYPE_NAME (type
))
9136 && DECL_NAME (TYPE_NAME (type
)))
9138 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
9139 if (strcmp (name
, "char16_t") == 0
9140 || strcmp (name
, "char32_t") == 0)
9142 encoding
= DW_ATE_UTF
;
9146 if (TYPE_STRING_FLAG (type
))
9148 if (TYPE_UNSIGNED (type
))
9149 encoding
= DW_ATE_unsigned_char
;
9151 encoding
= DW_ATE_signed_char
;
9153 else if (TYPE_UNSIGNED (type
))
9154 encoding
= DW_ATE_unsigned
;
9156 encoding
= DW_ATE_signed
;
9160 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
9162 if (dwarf_version
>= 3 || !dwarf_strict
)
9163 encoding
= DW_ATE_decimal_float
;
9165 encoding
= DW_ATE_lo_user
;
9168 encoding
= DW_ATE_float
;
9171 case FIXED_POINT_TYPE
:
9172 if (!(dwarf_version
>= 3 || !dwarf_strict
))
9173 encoding
= DW_ATE_lo_user
;
9174 else if (TYPE_UNSIGNED (type
))
9175 encoding
= DW_ATE_unsigned_fixed
;
9177 encoding
= DW_ATE_signed_fixed
;
9180 /* Dwarf2 doesn't know anything about complex ints, so use
9181 a user defined type for it. */
9183 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
9184 encoding
= DW_ATE_complex_float
;
9186 encoding
= DW_ATE_lo_user
;
9190 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9191 encoding
= DW_ATE_boolean
;
9195 /* No other TREE_CODEs are Dwarf fundamental types. */
9199 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
9201 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
9202 int_size_in_bytes (type
));
9203 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
9204 add_pubtype (type
, base_type_result
);
9206 return base_type_result
;
9209 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9210 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9213 is_base_type (tree type
)
9215 switch (TREE_CODE (type
))
9221 case FIXED_POINT_TYPE
:
9229 case QUAL_UNION_TYPE
:
9234 case REFERENCE_TYPE
:
9248 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9249 node, return the size in bits for the type if it is a constant, or else
9250 return the alignment for the type if the type's size is not constant, or
9251 else return BITS_PER_WORD if the type actually turns out to be an
9254 static inline unsigned HOST_WIDE_INT
9255 simple_type_size_in_bits (const_tree type
)
9257 if (TREE_CODE (type
) == ERROR_MARK
)
9258 return BITS_PER_WORD
;
9259 else if (TYPE_SIZE (type
) == NULL_TREE
)
9261 else if (host_integerp (TYPE_SIZE (type
), 1))
9262 return tree_low_cst (TYPE_SIZE (type
), 1);
9264 return TYPE_ALIGN (type
);
9267 /* Similarly, but return a double_int instead of UHWI. */
9269 static inline double_int
9270 double_int_type_size_in_bits (const_tree type
)
9272 if (TREE_CODE (type
) == ERROR_MARK
)
9273 return uhwi_to_double_int (BITS_PER_WORD
);
9274 else if (TYPE_SIZE (type
) == NULL_TREE
)
9275 return double_int_zero
;
9276 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
9277 return tree_to_double_int (TYPE_SIZE (type
));
9279 return uhwi_to_double_int (TYPE_ALIGN (type
));
9282 /* Given a pointer to a tree node for a subrange type, return a pointer
9283 to a DIE that describes the given type. */
9286 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
9288 dw_die_ref subrange_die
;
9289 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
9291 if (context_die
== NULL
)
9292 context_die
= comp_unit_die ();
9294 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
9296 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
9298 /* The size of the subrange type and its base type do not match,
9299 so we need to generate a size attribute for the subrange type. */
9300 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
9304 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
9306 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
9308 return subrange_die
;
9311 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9312 entry that chains various modifiers in front of the given type. */
9315 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
9316 dw_die_ref context_die
)
9318 enum tree_code code
= TREE_CODE (type
);
9319 dw_die_ref mod_type_die
;
9320 dw_die_ref sub_die
= NULL
;
9321 tree item_type
= NULL
;
9322 tree qualified_type
;
9323 tree name
, low
, high
;
9324 dw_die_ref mod_scope
;
9326 if (code
== ERROR_MARK
)
9329 /* See if we already have the appropriately qualified variant of
9332 = get_qualified_type (type
,
9333 ((is_const_type
? TYPE_QUAL_CONST
: 0)
9334 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
9336 if (qualified_type
== sizetype
9337 && TYPE_NAME (qualified_type
)
9338 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
9340 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
9342 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
9343 && TYPE_PRECISION (t
)
9344 == TYPE_PRECISION (qualified_type
)
9345 && TYPE_UNSIGNED (t
)
9346 == TYPE_UNSIGNED (qualified_type
));
9350 /* If we do, then we can just use its DIE, if it exists. */
9353 mod_type_die
= lookup_type_die (qualified_type
);
9355 return mod_type_die
;
9358 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
9360 /* Handle C typedef types. */
9361 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
9362 && !DECL_ARTIFICIAL (name
))
9364 tree dtype
= TREE_TYPE (name
);
9366 if (qualified_type
== dtype
)
9368 /* For a named type, use the typedef. */
9369 gen_type_die (qualified_type
, context_die
);
9370 return lookup_type_die (qualified_type
);
9372 else if (is_const_type
< TYPE_READONLY (dtype
)
9373 || is_volatile_type
< TYPE_VOLATILE (dtype
)
9374 || (is_const_type
<= TYPE_READONLY (dtype
)
9375 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
9376 && DECL_ORIGINAL_TYPE (name
) != type
))
9377 /* cv-unqualified version of named type. Just use the unnamed
9378 type to which it refers. */
9379 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
9380 is_const_type
, is_volatile_type
,
9382 /* Else cv-qualified version of named type; fall through. */
9385 mod_scope
= scope_die_for (type
, context_die
);
9388 /* If both is_const_type and is_volatile_type, prefer the path
9389 which leads to a qualified type. */
9390 && (!is_volatile_type
9391 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
9392 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
9394 mod_type_die
= new_die (DW_TAG_const_type
, mod_scope
, type
);
9395 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
9397 else if (is_volatile_type
)
9399 mod_type_die
= new_die (DW_TAG_volatile_type
, mod_scope
, type
);
9400 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
9402 else if (code
== POINTER_TYPE
)
9404 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
9405 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
9406 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
9407 item_type
= TREE_TYPE (type
);
9408 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
9409 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
9410 TYPE_ADDR_SPACE (item_type
));
9412 else if (code
== REFERENCE_TYPE
)
9414 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
9415 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
9418 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
9419 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
9420 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
9421 item_type
= TREE_TYPE (type
);
9422 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
9423 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
9424 TYPE_ADDR_SPACE (item_type
));
9426 else if (code
== INTEGER_TYPE
9427 && TREE_TYPE (type
) != NULL_TREE
9428 && subrange_type_for_debug_p (type
, &low
, &high
))
9430 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
9431 item_type
= TREE_TYPE (type
);
9433 else if (is_base_type (type
))
9434 mod_type_die
= base_type_die (type
);
9437 gen_type_die (type
, context_die
);
9439 /* We have to get the type_main_variant here (and pass that to the
9440 `lookup_type_die' routine) because the ..._TYPE node we have
9441 might simply be a *copy* of some original type node (where the
9442 copy was created to help us keep track of typedef names) and
9443 that copy might have a different TYPE_UID from the original
9445 if (TREE_CODE (type
) != VECTOR_TYPE
)
9446 return lookup_type_die (type_main_variant (type
));
9448 /* Vectors have the debugging information in the type,
9449 not the main variant. */
9450 return lookup_type_die (type
);
9453 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9454 don't output a DW_TAG_typedef, since there isn't one in the
9455 user's program; just attach a DW_AT_name to the type.
9456 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
9457 if the base type already has the same name. */
9459 && ((TREE_CODE (name
) != TYPE_DECL
9460 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
9461 || (!is_const_type
&& !is_volatile_type
)))
9462 || (TREE_CODE (name
) == TYPE_DECL
9463 && TREE_TYPE (name
) == qualified_type
9464 && DECL_NAME (name
))))
9466 if (TREE_CODE (name
) == TYPE_DECL
)
9467 /* Could just call add_name_and_src_coords_attributes here,
9468 but since this is a builtin type it doesn't have any
9469 useful source coordinates anyway. */
9470 name
= DECL_NAME (name
);
9471 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
9473 /* This probably indicates a bug. */
9474 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
9476 name
= TYPE_NAME (type
);
9478 && TREE_CODE (name
) == TYPE_DECL
)
9479 name
= DECL_NAME (name
);
9480 add_name_attribute (mod_type_die
,
9481 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
9485 equate_type_number_to_die (qualified_type
, mod_type_die
);
9488 /* We must do this after the equate_type_number_to_die call, in case
9489 this is a recursive type. This ensures that the modified_type_die
9490 recursion will terminate even if the type is recursive. Recursive
9491 types are possible in Ada. */
9492 sub_die
= modified_type_die (item_type
,
9493 TYPE_READONLY (item_type
),
9494 TYPE_VOLATILE (item_type
),
9497 if (sub_die
!= NULL
)
9498 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
9500 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
9501 if (TYPE_ARTIFICIAL (type
))
9502 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
9504 return mod_type_die
;
9507 /* Generate DIEs for the generic parameters of T.
9508 T must be either a generic type or a generic function.
9509 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
9512 gen_generic_params_dies (tree t
)
9516 dw_die_ref die
= NULL
;
9518 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
9522 die
= lookup_type_die (t
);
9523 else if (DECL_P (t
))
9524 die
= lookup_decl_die (t
);
9528 parms
= lang_hooks
.get_innermost_generic_parms (t
);
9530 /* T has no generic parameter. It means T is neither a generic type
9531 or function. End of story. */
9534 parms_num
= TREE_VEC_LENGTH (parms
);
9535 args
= lang_hooks
.get_innermost_generic_args (t
);
9536 for (i
= 0; i
< parms_num
; i
++)
9538 tree parm
, arg
, arg_pack_elems
;
9540 parm
= TREE_VEC_ELT (parms
, i
);
9541 arg
= TREE_VEC_ELT (args
, i
);
9542 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
9543 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
9545 if (parm
&& TREE_VALUE (parm
) && arg
)
9547 /* If PARM represents a template parameter pack,
9548 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
9549 by DW_TAG_template_*_parameter DIEs for the argument
9550 pack elements of ARG. Note that ARG would then be
9551 an argument pack. */
9553 template_parameter_pack_die (TREE_VALUE (parm
),
9557 generic_parameter_die (TREE_VALUE (parm
), arg
,
9558 true /* Emit DW_AT_name */, die
);
9563 /* Create and return a DIE for PARM which should be
9564 the representation of a generic type parameter.
9565 For instance, in the C++ front end, PARM would be a template parameter.
9566 ARG is the argument to PARM.
9567 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
9569 PARENT_DIE is the parent DIE which the new created DIE should be added to,
9573 generic_parameter_die (tree parm
, tree arg
,
9575 dw_die_ref parent_die
)
9577 dw_die_ref tmpl_die
= NULL
;
9578 const char *name
= NULL
;
9580 if (!parm
|| !DECL_NAME (parm
) || !arg
)
9583 /* We support non-type generic parameters and arguments,
9584 type generic parameters and arguments, as well as
9585 generic generic parameters (a.k.a. template template parameters in C++)
9587 if (TREE_CODE (parm
) == PARM_DECL
)
9588 /* PARM is a nontype generic parameter */
9589 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
9590 else if (TREE_CODE (parm
) == TYPE_DECL
)
9591 /* PARM is a type generic parameter. */
9592 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
9593 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
9594 /* PARM is a generic generic parameter.
9595 Its DIE is a GNU extension. It shall have a
9596 DW_AT_name attribute to represent the name of the template template
9597 parameter, and a DW_AT_GNU_template_name attribute to represent the
9598 name of the template template argument. */
9599 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
9608 /* If PARM is a generic parameter pack, it means we are
9609 emitting debug info for a template argument pack element.
9610 In other terms, ARG is a template argument pack element.
9611 In that case, we don't emit any DW_AT_name attribute for
9615 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
9617 add_AT_string (tmpl_die
, DW_AT_name
, name
);
9620 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
9622 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
9623 TMPL_DIE should have a child DW_AT_type attribute that is set
9624 to the type of the argument to PARM, which is ARG.
9625 If PARM is a type generic parameter, TMPL_DIE should have a
9626 child DW_AT_type that is set to ARG. */
9627 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
9628 add_type_attribute (tmpl_die
, tmpl_type
, 0,
9629 TREE_THIS_VOLATILE (tmpl_type
),
9634 /* So TMPL_DIE is a DIE representing a
9635 a generic generic template parameter, a.k.a template template
9636 parameter in C++ and arg is a template. */
9638 /* The DW_AT_GNU_template_name attribute of the DIE must be set
9639 to the name of the argument. */
9640 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
9642 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
9645 if (TREE_CODE (parm
) == PARM_DECL
)
9646 /* So PARM is a non-type generic parameter.
9647 DWARF3 5.6.8 says we must set a DW_AT_const_value child
9648 attribute of TMPL_DIE which value represents the value
9650 We must be careful here:
9651 The value of ARG might reference some function decls.
9652 We might currently be emitting debug info for a generic
9653 type and types are emitted before function decls, we don't
9654 know if the function decls referenced by ARG will actually be
9655 emitted after cgraph computations.
9656 So must defer the generation of the DW_AT_const_value to
9657 after cgraph is ready. */
9658 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
9664 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
9665 PARM_PACK must be a template parameter pack. The returned DIE
9666 will be child DIE of PARENT_DIE. */
9669 template_parameter_pack_die (tree parm_pack
,
9670 tree parm_pack_args
,
9671 dw_die_ref parent_die
)
9676 gcc_assert (parent_die
&& parm_pack
);
9678 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
9679 add_name_and_src_coords_attributes (die
, parm_pack
);
9680 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
9681 generic_parameter_die (parm_pack
,
9682 TREE_VEC_ELT (parm_pack_args
, j
),
9683 false /* Don't emit DW_AT_name */,
9688 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
9689 an enumerated type. */
9692 type_is_enum (const_tree type
)
9694 return TREE_CODE (type
) == ENUMERAL_TYPE
;
9697 /* Return the DBX register number described by a given RTL node. */
9700 dbx_reg_number (const_rtx rtl
)
9702 unsigned regno
= REGNO (rtl
);
9704 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
9706 #ifdef LEAF_REG_REMAP
9707 if (crtl
->uses_only_leaf_regs
)
9709 int leaf_reg
= LEAF_REG_REMAP (regno
);
9711 regno
= (unsigned) leaf_reg
;
9715 regno
= DBX_REGISTER_NUMBER (regno
);
9716 gcc_assert (regno
!= INVALID_REGNUM
);
9720 /* Optionally add a DW_OP_piece term to a location description expression.
9721 DW_OP_piece is only added if the location description expression already
9722 doesn't end with DW_OP_piece. */
9725 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
9727 dw_loc_descr_ref loc
;
9729 if (*list_head
!= NULL
)
9731 /* Find the end of the chain. */
9732 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
9735 if (loc
->dw_loc_opc
!= DW_OP_piece
)
9736 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
9740 /* Return a location descriptor that designates a machine register or
9741 zero if there is none. */
9743 static dw_loc_descr_ref
9744 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
9748 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
9751 /* We only use "frame base" when we're sure we're talking about the
9752 post-prologue local stack frame. We do this by *not* running
9753 register elimination until this point, and recognizing the special
9754 argument pointer and soft frame pointer rtx's.
9755 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
9756 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
9757 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
9759 dw_loc_descr_ref result
= NULL
;
9761 if (dwarf_version
>= 4 || !dwarf_strict
)
9763 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
9766 add_loc_descr (&result
,
9767 new_loc_descr (DW_OP_stack_value
, 0, 0));
9772 regs
= targetm
.dwarf_register_span (rtl
);
9774 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
9775 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
9777 return one_reg_loc_descriptor (dbx_reg_number (rtl
), initialized
);
9780 /* Return a location descriptor that designates a machine register for
9781 a given hard register number. */
9783 static dw_loc_descr_ref
9784 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
9786 dw_loc_descr_ref reg_loc_descr
;
9790 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
9792 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
9794 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9795 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9797 return reg_loc_descr
;
9800 /* Given an RTL of a register, return a location descriptor that
9801 designates a value that spans more than one register. */
9803 static dw_loc_descr_ref
9804 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
9805 enum var_init_status initialized
)
9809 dw_loc_descr_ref loc_result
= NULL
;
9812 #ifdef LEAF_REG_REMAP
9813 if (crtl
->uses_only_leaf_regs
)
9815 int leaf_reg
= LEAF_REG_REMAP (reg
);
9817 reg
= (unsigned) leaf_reg
;
9820 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
9821 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
9823 /* Simple, contiguous registers. */
9824 if (regs
== NULL_RTX
)
9826 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
9833 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
9834 VAR_INIT_STATUS_INITIALIZED
);
9835 add_loc_descr (&loc_result
, t
);
9836 add_loc_descr_op_piece (&loc_result
, size
);
9842 /* Now onto stupid register sets in non contiguous locations. */
9844 gcc_assert (GET_CODE (regs
) == PARALLEL
);
9846 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
9849 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
9853 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
9854 VAR_INIT_STATUS_INITIALIZED
);
9855 add_loc_descr (&loc_result
, t
);
9856 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
9857 add_loc_descr_op_piece (&loc_result
, size
);
9860 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9861 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9865 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
9867 /* Return a location descriptor that designates a constant i,
9868 as a compound operation from constant (i >> shift), constant shift
9871 static dw_loc_descr_ref
9872 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
9874 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
9875 add_loc_descr (&ret
, int_loc_descriptor (shift
));
9876 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
9880 /* Return a location descriptor that designates a constant. */
9882 static dw_loc_descr_ref
9883 int_loc_descriptor (HOST_WIDE_INT i
)
9885 enum dwarf_location_atom op
;
9887 /* Pick the smallest representation of a constant, rather than just
9888 defaulting to the LEB encoding. */
9891 int clz
= clz_hwi (i
);
9892 int ctz
= ctz_hwi (i
);
9894 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
9897 else if (i
<= 0xffff)
9899 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
9900 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
9901 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
9902 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
9903 while DW_OP_const4u is 5 bytes. */
9904 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
9905 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
9906 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
9907 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
9908 while DW_OP_const4u is 5 bytes. */
9909 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
9910 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
9912 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
9913 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
9914 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
9915 while DW_OP_constu of constant >= 0x100000000 takes at least
9917 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
9918 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
9919 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
9920 >= HOST_BITS_PER_WIDE_INT
)
9921 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
9922 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
9923 while DW_OP_constu takes in this case at least 6 bytes. */
9924 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
9925 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
9926 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
9927 && size_of_uleb128 (i
) > 6)
9928 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
9929 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
9937 else if (i
>= -0x8000)
9939 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
9941 if (size_of_int_loc_descriptor (i
) < 5)
9943 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
9944 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
9951 if (size_of_int_loc_descriptor (i
)
9952 < (unsigned long) 1 + size_of_sleb128 (i
))
9954 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
9955 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
9962 return new_loc_descr (op
, i
, 0);
9965 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
9966 without actually allocating it. */
9968 static unsigned long
9969 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
9971 return size_of_int_loc_descriptor (i
>> shift
)
9972 + size_of_int_loc_descriptor (shift
)
9976 /* Return size_of_locs (int_loc_descriptor (i)) without
9977 actually allocating it. */
9979 static unsigned long
9980 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
9991 else if (i
<= 0xffff)
9995 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
9996 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
9997 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
9999 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10000 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10001 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10003 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10005 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
10006 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10007 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10008 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10010 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10011 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
10012 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10014 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10015 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10017 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10026 else if (i
>= -0x8000)
10028 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10030 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10032 s
= size_of_int_loc_descriptor (-i
) + 1;
10040 unsigned long r
= 1 + size_of_sleb128 (i
);
10041 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10043 s
= size_of_int_loc_descriptor (-i
) + 1;
10052 /* Return loc description representing "address" of integer value.
10053 This can appear only as toplevel expression. */
10055 static dw_loc_descr_ref
10056 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
10059 dw_loc_descr_ref loc_result
= NULL
;
10061 if (!(dwarf_version
>= 4 || !dwarf_strict
))
10064 litsize
= size_of_int_loc_descriptor (i
);
10065 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10066 is more compact. For DW_OP_stack_value we need:
10067 litsize + 1 (DW_OP_stack_value)
10068 and for DW_OP_implicit_value:
10069 1 (DW_OP_implicit_value) + 1 (length) + size. */
10070 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
10072 loc_result
= int_loc_descriptor (i
);
10073 add_loc_descr (&loc_result
,
10074 new_loc_descr (DW_OP_stack_value
, 0, 0));
10078 loc_result
= new_loc_descr (DW_OP_implicit_value
,
10080 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
10081 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
10085 /* Return a location descriptor that designates a base+offset location. */
10087 static dw_loc_descr_ref
10088 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
10089 enum var_init_status initialized
)
10091 unsigned int regno
;
10092 dw_loc_descr_ref result
;
10093 dw_fde_ref fde
= cfun
->fde
;
10095 /* We only use "frame base" when we're sure we're talking about the
10096 post-prologue local stack frame. We do this by *not* running
10097 register elimination until this point, and recognizing the special
10098 argument pointer and soft frame pointer rtx's. */
10099 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
10101 rtx elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
10105 if (GET_CODE (elim
) == PLUS
)
10107 offset
+= INTVAL (XEXP (elim
, 1));
10108 elim
= XEXP (elim
, 0);
10110 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10111 && (elim
== hard_frame_pointer_rtx
10112 || elim
== stack_pointer_rtx
))
10113 || elim
== (frame_pointer_needed
10114 ? hard_frame_pointer_rtx
10115 : stack_pointer_rtx
));
10117 /* If drap register is used to align stack, use frame
10118 pointer + offset to access stack variables. If stack
10119 is aligned without drap, use stack pointer + offset to
10120 access stack variables. */
10121 if (crtl
->stack_realign_tried
10122 && reg
== frame_pointer_rtx
)
10125 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
10126 ? HARD_FRAME_POINTER_REGNUM
10128 return new_reg_loc_descr (base_reg
, offset
);
10131 gcc_assert (frame_pointer_fb_offset_valid
);
10132 offset
+= frame_pointer_fb_offset
;
10133 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10137 regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
10139 if (!optimize
&& fde
10140 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
10142 /* Use cfa+offset to represent the location of arguments passed
10143 on the stack when drap is used to align stack.
10144 Only do this when not optimizing, for optimized code var-tracking
10145 is supposed to track where the arguments live and the register
10146 used as vdrap or drap in some spot might be used for something
10147 else in other part of the routine. */
10148 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10152 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
10155 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
10157 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10158 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10163 /* Return true if this RTL expression describes a base+offset calculation. */
10166 is_based_loc (const_rtx rtl
)
10168 return (GET_CODE (rtl
) == PLUS
10169 && ((REG_P (XEXP (rtl
, 0))
10170 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
10171 && CONST_INT_P (XEXP (rtl
, 1)))));
10174 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10177 static dw_loc_descr_ref
10178 tls_mem_loc_descriptor (rtx mem
)
10181 dw_loc_descr_ref loc_result
;
10183 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
10186 base
= get_base_address (MEM_EXPR (mem
));
10188 || TREE_CODE (base
) != VAR_DECL
10189 || !DECL_THREAD_LOCAL_P (base
))
10192 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
10193 if (loc_result
== NULL
)
10196 if (MEM_OFFSET (mem
))
10197 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
10202 /* Output debug info about reason why we failed to expand expression as dwarf
10206 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
10208 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
10210 fprintf (dump_file
, "Failed to expand as dwarf: ");
10212 print_generic_expr (dump_file
, expr
, dump_flags
);
10215 fprintf (dump_file
, "\n");
10216 print_rtl (dump_file
, rtl
);
10218 fprintf (dump_file
, "\nReason: %s\n", reason
);
10222 /* Helper function for const_ok_for_output, called either directly
10223 or via for_each_rtx. */
10226 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
10230 if (GET_CODE (rtl
) == UNSPEC
)
10232 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
10233 we can't express it in the debug info. */
10234 #ifdef ENABLE_CHECKING
10235 /* Don't complain about TLS UNSPECs, those are just too hard to
10236 delegitimize. Note this could be a non-decl SYMBOL_REF such as
10237 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
10238 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
10239 if (XVECLEN (rtl
, 0) == 0
10240 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
10241 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
10242 inform (current_function_decl
10243 ? DECL_SOURCE_LOCATION (current_function_decl
)
10244 : UNKNOWN_LOCATION
,
10245 #if NUM_UNSPEC_VALUES > 0
10246 "non-delegitimized UNSPEC %s (%d) found in variable location",
10247 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
10248 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
10251 "non-delegitimized UNSPEC %d found in variable location",
10255 expansion_failed (NULL_TREE
, rtl
,
10256 "UNSPEC hasn't been delegitimized.\n");
10260 if (targetm
.const_not_ok_for_debug_p (rtl
))
10262 expansion_failed (NULL_TREE
, rtl
,
10263 "Expression rejected for debug by the backend.\n");
10267 if (GET_CODE (rtl
) != SYMBOL_REF
)
10270 if (CONSTANT_POOL_ADDRESS_P (rtl
))
10273 get_pool_constant_mark (rtl
, &marked
);
10274 /* If all references to this pool constant were optimized away,
10275 it was not output and thus we can't represent it. */
10278 expansion_failed (NULL_TREE
, rtl
,
10279 "Constant was removed from constant pool.\n");
10284 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
10287 /* Avoid references to external symbols in debug info, on several targets
10288 the linker might even refuse to link when linking a shared library,
10289 and in many other cases the relocations for .debug_info/.debug_loc are
10290 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
10291 to be defined within the same shared library or executable are fine. */
10292 if (SYMBOL_REF_EXTERNAL_P (rtl
))
10294 tree decl
= SYMBOL_REF_DECL (rtl
);
10296 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
10298 expansion_failed (NULL_TREE
, rtl
,
10299 "Symbol not defined in current TU.\n");
10307 /* Return true if constant RTL can be emitted in DW_OP_addr or
10308 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
10309 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
10312 const_ok_for_output (rtx rtl
)
10314 if (GET_CODE (rtl
) == SYMBOL_REF
)
10315 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
10317 if (GET_CODE (rtl
) == CONST
)
10318 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
10323 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
10324 if possible, NULL otherwise. */
10327 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
10329 dw_die_ref type_die
;
10330 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
10334 switch (TREE_CODE (type
))
10342 type_die
= lookup_type_die (type
);
10344 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
10345 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
10350 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
10351 type matching MODE, or, if MODE is narrower than or as wide as
10352 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
10355 static dw_loc_descr_ref
10356 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
10358 enum machine_mode outer_mode
= mode
;
10359 dw_die_ref type_die
;
10360 dw_loc_descr_ref cvt
;
10362 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
10364 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
10367 type_die
= base_type_for_mode (outer_mode
, 1);
10368 if (type_die
== NULL
)
10370 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10371 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10372 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10373 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10374 add_loc_descr (&op
, cvt
);
10378 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
10380 static dw_loc_descr_ref
10381 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
10382 dw_loc_descr_ref op1
)
10384 dw_loc_descr_ref ret
= op0
;
10385 add_loc_descr (&ret
, op1
);
10386 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
10387 if (STORE_FLAG_VALUE
!= 1)
10389 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
10390 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
10395 /* Return location descriptor for signed comparison OP RTL. */
10397 static dw_loc_descr_ref
10398 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
10399 enum machine_mode mem_mode
)
10401 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
10402 dw_loc_descr_ref op0
, op1
;
10405 if (op_mode
== VOIDmode
)
10406 op_mode
= GET_MODE (XEXP (rtl
, 1));
10407 if (op_mode
== VOIDmode
)
10411 && (GET_MODE_CLASS (op_mode
) != MODE_INT
10412 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
10415 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
10416 VAR_INIT_STATUS_INITIALIZED
);
10417 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
10418 VAR_INIT_STATUS_INITIALIZED
);
10420 if (op0
== NULL
|| op1
== NULL
)
10423 if (GET_MODE_CLASS (op_mode
) != MODE_INT
10424 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
10425 return compare_loc_descriptor (op
, op0
, op1
);
10427 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
10429 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
10430 dw_loc_descr_ref cvt
;
10432 if (type_die
== NULL
)
10434 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10435 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10436 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10437 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10438 add_loc_descr (&op0
, cvt
);
10439 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10440 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10441 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10442 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10443 add_loc_descr (&op1
, cvt
);
10444 return compare_loc_descriptor (op
, op0
, op1
);
10447 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
10448 /* For eq/ne, if the operands are known to be zero-extended,
10449 there is no need to do the fancy shifting up. */
10450 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
10452 dw_loc_descr_ref last0
, last1
;
10453 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
10455 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
10457 /* deref_size zero extends, and for constants we can check
10458 whether they are zero extended or not. */
10459 if (((last0
->dw_loc_opc
== DW_OP_deref_size
10460 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
10461 || (CONST_INT_P (XEXP (rtl
, 0))
10462 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
10463 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
10464 && ((last1
->dw_loc_opc
== DW_OP_deref_size
10465 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
10466 || (CONST_INT_P (XEXP (rtl
, 1))
10467 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
10468 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
10469 return compare_loc_descriptor (op
, op0
, op1
);
10471 /* EQ/NE comparison against constant in narrower type than
10472 DWARF2_ADDR_SIZE can be performed either as
10473 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
10476 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
10477 DW_OP_{eq,ne}. Pick whatever is shorter. */
10478 if (CONST_INT_P (XEXP (rtl
, 1))
10479 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
10480 && (size_of_int_loc_descriptor (shift
) + 1
10481 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
10482 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
10483 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
10484 & GET_MODE_MASK (op_mode
))))
10486 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
10487 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
10488 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
10489 & GET_MODE_MASK (op_mode
));
10490 return compare_loc_descriptor (op
, op0
, op1
);
10493 add_loc_descr (&op0
, int_loc_descriptor (shift
));
10494 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
10495 if (CONST_INT_P (XEXP (rtl
, 1)))
10496 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
10499 add_loc_descr (&op1
, int_loc_descriptor (shift
));
10500 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
10502 return compare_loc_descriptor (op
, op0
, op1
);
10505 /* Return location descriptor for unsigned comparison OP RTL. */
10507 static dw_loc_descr_ref
10508 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
10509 enum machine_mode mem_mode
)
10511 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
10512 dw_loc_descr_ref op0
, op1
;
10514 if (op_mode
== VOIDmode
)
10515 op_mode
= GET_MODE (XEXP (rtl
, 1));
10516 if (op_mode
== VOIDmode
)
10518 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
10521 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
10524 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
10525 VAR_INIT_STATUS_INITIALIZED
);
10526 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
10527 VAR_INIT_STATUS_INITIALIZED
);
10529 if (op0
== NULL
|| op1
== NULL
)
10532 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
10534 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
10535 dw_loc_descr_ref last0
, last1
;
10536 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
10538 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
10540 if (CONST_INT_P (XEXP (rtl
, 0)))
10541 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
10542 /* deref_size zero extends, so no need to mask it again. */
10543 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
10544 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
10546 add_loc_descr (&op0
, int_loc_descriptor (mask
));
10547 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
10549 if (CONST_INT_P (XEXP (rtl
, 1)))
10550 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
10551 /* deref_size zero extends, so no need to mask it again. */
10552 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
10553 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
10555 add_loc_descr (&op1
, int_loc_descriptor (mask
));
10556 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
10559 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
10561 HOST_WIDE_INT bias
= 1;
10562 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
10563 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
10564 if (CONST_INT_P (XEXP (rtl
, 1)))
10565 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
10566 + INTVAL (XEXP (rtl
, 1)));
10568 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
10571 return compare_loc_descriptor (op
, op0
, op1
);
10574 /* Return location descriptor for {U,S}{MIN,MAX}. */
10576 static dw_loc_descr_ref
10577 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
10578 enum machine_mode mem_mode
)
10580 enum dwarf_location_atom op
;
10581 dw_loc_descr_ref op0
, op1
, ret
;
10582 dw_loc_descr_ref bra_node
, drop_node
;
10585 && (GET_MODE_CLASS (mode
) != MODE_INT
10586 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
10589 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
10590 VAR_INIT_STATUS_INITIALIZED
);
10591 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
10592 VAR_INIT_STATUS_INITIALIZED
);
10594 if (op0
== NULL
|| op1
== NULL
)
10597 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
10598 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
10599 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
10600 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
10602 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
10604 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
10605 add_loc_descr (&op0
, int_loc_descriptor (mask
));
10606 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
10607 add_loc_descr (&op1
, int_loc_descriptor (mask
));
10608 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
10610 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
10612 HOST_WIDE_INT bias
= 1;
10613 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
10614 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
10615 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
10618 else if (GET_MODE_CLASS (mode
) == MODE_INT
10619 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
10621 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
10622 add_loc_descr (&op0
, int_loc_descriptor (shift
));
10623 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
10624 add_loc_descr (&op1
, int_loc_descriptor (shift
));
10625 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
10627 else if (GET_MODE_CLASS (mode
) == MODE_INT
10628 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
10630 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
10631 dw_loc_descr_ref cvt
;
10632 if (type_die
== NULL
)
10634 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10635 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10636 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10637 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10638 add_loc_descr (&op0
, cvt
);
10639 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10640 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10641 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10642 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10643 add_loc_descr (&op1
, cvt
);
10646 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
10651 add_loc_descr (&ret
, op1
);
10652 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
10653 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
10654 add_loc_descr (&ret
, bra_node
);
10655 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
10656 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
10657 add_loc_descr (&ret
, drop_node
);
10658 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10659 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
10660 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
10661 && GET_MODE_CLASS (mode
) == MODE_INT
10662 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
10663 ret
= convert_descriptor_to_mode (mode
, ret
);
10667 /* Helper function for mem_loc_descriptor. Perform OP binary op,
10668 but after converting arguments to type_die, afterwards
10669 convert back to unsigned. */
10671 static dw_loc_descr_ref
10672 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
10673 enum machine_mode mode
, enum machine_mode mem_mode
)
10675 dw_loc_descr_ref cvt
, op0
, op1
;
10677 if (type_die
== NULL
)
10679 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
10680 VAR_INIT_STATUS_INITIALIZED
);
10681 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
10682 VAR_INIT_STATUS_INITIALIZED
);
10683 if (op0
== NULL
|| op1
== NULL
)
10685 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10686 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10687 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10688 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10689 add_loc_descr (&op0
, cvt
);
10690 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
10691 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
10692 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
10693 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
10694 add_loc_descr (&op1
, cvt
);
10695 add_loc_descr (&op0
, op1
);
10696 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
10697 return convert_descriptor_to_mode (mode
, op0
);
10700 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
10701 const0 is DW_OP_lit0 or corresponding typed constant,
10702 const1 is DW_OP_lit1 or corresponding typed constant
10703 and constMSB is constant with just the MSB bit set
10705 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
10706 L1: const0 DW_OP_swap
10707 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
10708 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
10713 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
10714 L1: const0 DW_OP_swap
10715 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
10716 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
10721 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
10722 L1: const1 DW_OP_swap
10723 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
10724 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
10728 static dw_loc_descr_ref
10729 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
10730 enum machine_mode mem_mode
)
10732 dw_loc_descr_ref op0
, ret
, tmp
;
10733 HOST_WIDE_INT valv
;
10734 dw_loc_descr_ref l1jump
, l1label
;
10735 dw_loc_descr_ref l2jump
, l2label
;
10736 dw_loc_descr_ref l3jump
, l3label
;
10737 dw_loc_descr_ref l4jump
, l4label
;
10740 if (GET_MODE_CLASS (mode
) != MODE_INT
10741 || GET_MODE (XEXP (rtl
, 0)) != mode
10742 || (GET_CODE (rtl
) == CLZ
10743 && GET_MODE_BITSIZE (mode
) > HOST_BITS_PER_DOUBLE_INT
))
10746 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
10747 VAR_INIT_STATUS_INITIALIZED
);
10751 if (GET_CODE (rtl
) == CLZ
)
10753 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
10754 valv
= GET_MODE_BITSIZE (mode
);
10756 else if (GET_CODE (rtl
) == FFS
)
10758 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
10759 valv
= GET_MODE_BITSIZE (mode
);
10760 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
10761 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
10762 add_loc_descr (&ret
, l1jump
);
10763 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
10764 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
10765 VAR_INIT_STATUS_INITIALIZED
);
10768 add_loc_descr (&ret
, tmp
);
10769 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
10770 add_loc_descr (&ret
, l4jump
);
10771 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
10772 ? const1_rtx
: const0_rtx
,
10774 VAR_INIT_STATUS_INITIALIZED
);
10775 if (l1label
== NULL
)
10777 add_loc_descr (&ret
, l1label
);
10778 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
10779 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
10780 add_loc_descr (&ret
, l2label
);
10781 if (GET_CODE (rtl
) != CLZ
)
10783 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
10784 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
10785 << (GET_MODE_BITSIZE (mode
) - 1));
10787 msb
= immed_double_const (0, (unsigned HOST_WIDE_INT
) 1
10788 << (GET_MODE_BITSIZE (mode
)
10789 - HOST_BITS_PER_WIDE_INT
- 1), mode
);
10790 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
10791 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
10792 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
10793 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
10795 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
10796 VAR_INIT_STATUS_INITIALIZED
);
10799 add_loc_descr (&ret
, tmp
);
10800 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
10801 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
10802 add_loc_descr (&ret
, l3jump
);
10803 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
10804 VAR_INIT_STATUS_INITIALIZED
);
10807 add_loc_descr (&ret
, tmp
);
10808 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
10809 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
10810 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
10811 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
10812 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
10813 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
10814 add_loc_descr (&ret
, l2jump
);
10815 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
10816 add_loc_descr (&ret
, l3label
);
10817 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
10818 add_loc_descr (&ret
, l4label
);
10819 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10820 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
10821 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10822 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
10823 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10824 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
10825 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10826 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
10830 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
10831 const1 is DW_OP_lit1 or corresponding typed constant):
10833 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
10834 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
10838 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
10839 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
10842 static dw_loc_descr_ref
10843 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
10844 enum machine_mode mem_mode
)
10846 dw_loc_descr_ref op0
, ret
, tmp
;
10847 dw_loc_descr_ref l1jump
, l1label
;
10848 dw_loc_descr_ref l2jump
, l2label
;
10850 if (GET_MODE_CLASS (mode
) != MODE_INT
10851 || GET_MODE (XEXP (rtl
, 0)) != mode
)
10854 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
10855 VAR_INIT_STATUS_INITIALIZED
);
10859 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
10860 VAR_INIT_STATUS_INITIALIZED
);
10863 add_loc_descr (&ret
, tmp
);
10864 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
10865 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
10866 add_loc_descr (&ret
, l1label
);
10867 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
10868 add_loc_descr (&ret
, l2jump
);
10869 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
10870 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
10871 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
10872 VAR_INIT_STATUS_INITIALIZED
);
10875 add_loc_descr (&ret
, tmp
);
10876 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
10877 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
10878 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
10879 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
10880 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
10881 VAR_INIT_STATUS_INITIALIZED
);
10882 add_loc_descr (&ret
, tmp
);
10883 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
10884 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
10885 add_loc_descr (&ret
, l1jump
);
10886 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
10887 add_loc_descr (&ret
, l2label
);
10888 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10889 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
10890 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10891 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
10895 /* BSWAP (constS is initial shift count, either 56 or 24):
10897 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
10898 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
10899 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
10900 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
10901 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
10903 static dw_loc_descr_ref
10904 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
10905 enum machine_mode mem_mode
)
10907 dw_loc_descr_ref op0
, ret
, tmp
;
10908 dw_loc_descr_ref l1jump
, l1label
;
10909 dw_loc_descr_ref l2jump
, l2label
;
10911 if (GET_MODE_CLASS (mode
) != MODE_INT
10912 || BITS_PER_UNIT
!= 8
10913 || (GET_MODE_BITSIZE (mode
) != 32
10914 && GET_MODE_BITSIZE (mode
) != 64))
10917 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
10918 VAR_INIT_STATUS_INITIALIZED
);
10923 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
10925 VAR_INIT_STATUS_INITIALIZED
);
10928 add_loc_descr (&ret
, tmp
);
10929 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
10930 VAR_INIT_STATUS_INITIALIZED
);
10933 add_loc_descr (&ret
, tmp
);
10934 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
10935 add_loc_descr (&ret
, l1label
);
10936 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
10938 VAR_INIT_STATUS_INITIALIZED
);
10939 add_loc_descr (&ret
, tmp
);
10940 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
10941 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
10942 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
10943 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
10944 VAR_INIT_STATUS_INITIALIZED
);
10947 add_loc_descr (&ret
, tmp
);
10948 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
10949 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
10950 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
10951 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
10952 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
10953 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
10954 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
10955 VAR_INIT_STATUS_INITIALIZED
);
10956 add_loc_descr (&ret
, tmp
);
10957 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
10958 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
10959 add_loc_descr (&ret
, l2jump
);
10960 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
10961 VAR_INIT_STATUS_INITIALIZED
);
10962 add_loc_descr (&ret
, tmp
);
10963 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
10964 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
10965 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
10966 add_loc_descr (&ret
, l1jump
);
10967 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
10968 add_loc_descr (&ret
, l2label
);
10969 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
10970 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
10971 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10972 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
10973 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10974 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
10978 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
10979 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
10980 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
10981 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
10983 ROTATERT is similar:
10984 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
10985 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
10986 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
10988 static dw_loc_descr_ref
10989 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
10990 enum machine_mode mem_mode
)
10992 rtx rtlop1
= XEXP (rtl
, 1);
10993 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
10996 if (GET_MODE_CLASS (mode
) != MODE_INT
)
10999 if (GET_MODE (rtlop1
) != VOIDmode
11000 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
11001 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
11002 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11003 VAR_INIT_STATUS_INITIALIZED
);
11004 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
11005 VAR_INIT_STATUS_INITIALIZED
);
11006 if (op0
== NULL
|| op1
== NULL
)
11008 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11009 for (i
= 0; i
< 2; i
++)
11011 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
11012 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
11014 VAR_INIT_STATUS_INITIALIZED
);
11015 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
11016 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11018 : HOST_BITS_PER_WIDE_INT
== 64
11019 ? DW_OP_const8u
: DW_OP_constu
,
11020 GET_MODE_MASK (mode
), 0);
11023 if (mask
[i
] == NULL
)
11025 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
11028 add_loc_descr (&ret
, op1
);
11029 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11030 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11031 if (GET_CODE (rtl
) == ROTATERT
)
11033 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11034 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11035 GET_MODE_BITSIZE (mode
), 0));
11037 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11038 if (mask
[0] != NULL
)
11039 add_loc_descr (&ret
, mask
[0]);
11040 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11041 if (mask
[1] != NULL
)
11043 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11044 add_loc_descr (&ret
, mask
[1]);
11045 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11047 if (GET_CODE (rtl
) == ROTATE
)
11049 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11050 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11051 GET_MODE_BITSIZE (mode
), 0));
11053 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11054 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11058 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11059 for DEBUG_PARAMETER_REF RTL. */
11061 static dw_loc_descr_ref
11062 parameter_ref_descriptor (rtx rtl
)
11064 dw_loc_descr_ref ret
;
11069 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
11070 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
11071 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
11074 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11075 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
11076 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11080 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
11081 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
11086 /* The following routine converts the RTL for a variable or parameter
11087 (resident in memory) into an equivalent Dwarf representation of a
11088 mechanism for getting the address of that same variable onto the top of a
11089 hypothetical "address evaluation" stack.
11091 When creating memory location descriptors, we are effectively transforming
11092 the RTL for a memory-resident object into its Dwarf postfix expression
11093 equivalent. This routine recursively descends an RTL tree, turning
11094 it into Dwarf postfix code as it goes.
11096 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
11098 MEM_MODE is the mode of the memory reference, needed to handle some
11099 autoincrement addressing modes.
11101 Return 0 if we can't represent the location. */
11104 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11105 enum machine_mode mem_mode
,
11106 enum var_init_status initialized
)
11108 dw_loc_descr_ref mem_loc_result
= NULL
;
11109 enum dwarf_location_atom op
;
11110 dw_loc_descr_ref op0
, op1
;
11112 if (mode
== VOIDmode
)
11113 mode
= GET_MODE (rtl
);
11115 /* Note that for a dynamically sized array, the location we will generate a
11116 description of here will be the lowest numbered location which is
11117 actually within the array. That's *not* necessarily the same as the
11118 zeroth element of the array. */
11120 rtl
= targetm
.delegitimize_address (rtl
);
11122 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
11125 switch (GET_CODE (rtl
))
11130 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
11133 /* The case of a subreg may arise when we have a local (register)
11134 variable or a formal (register) parameter which doesn't quite fill
11135 up an entire register. For now, just assume that it is
11136 legitimate to make the Dwarf info refer to the whole register which
11137 contains the given subreg. */
11138 if (!subreg_lowpart_p (rtl
))
11140 if (GET_MODE_CLASS (mode
) == MODE_INT
11141 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl
))) == MODE_INT
11142 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11143 #ifdef POINTERS_EXTEND_UNSIGNED
11144 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
11147 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
))) <= DWARF2_ADDR_SIZE
)
11149 mem_loc_result
= mem_loc_descriptor (SUBREG_REG (rtl
),
11150 GET_MODE (SUBREG_REG (rtl
)),
11151 mem_mode
, initialized
);
11156 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
))))
11158 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
)))
11159 && (GET_MODE_CLASS (mode
) != MODE_INT
11160 || GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl
))) != MODE_INT
))
11164 dw_die_ref type_die
;
11165 dw_loc_descr_ref cvt
;
11167 mem_loc_result
= mem_loc_descriptor (SUBREG_REG (rtl
),
11168 GET_MODE (SUBREG_REG (rtl
)),
11169 mem_mode
, initialized
);
11170 if (mem_loc_result
== NULL
)
11172 type_die
= base_type_for_mode (mode
,
11173 GET_MODE_CLASS (mode
) == MODE_INT
);
11174 if (type_die
== NULL
)
11176 mem_loc_result
= NULL
;
11179 if (GET_MODE_SIZE (mode
)
11180 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
))))
11181 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11183 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
11184 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11185 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11186 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11187 add_loc_descr (&mem_loc_result
, cvt
);
11192 if (GET_MODE_CLASS (mode
) != MODE_INT
11193 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
11194 #ifdef POINTERS_EXTEND_UNSIGNED
11195 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
11199 dw_die_ref type_die
;
11203 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
11205 type_die
= base_type_for_mode (mode
,
11206 GET_MODE_CLASS (mode
) == MODE_INT
);
11207 if (type_die
== NULL
)
11209 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
11210 dbx_reg_number (rtl
), 0);
11211 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
11212 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
11213 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
11216 /* Whenever a register number forms a part of the description of the
11217 method for calculating the (dynamic) address of a memory resident
11218 object, DWARF rules require the register number be referred to as
11219 a "base register". This distinction is not based in any way upon
11220 what category of register the hardware believes the given register
11221 belongs to. This is strictly DWARF terminology we're dealing with
11222 here. Note that in cases where the location of a memory-resident
11223 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
11224 OP_CONST (0)) the actual DWARF location descriptor that we generate
11225 may just be OP_BASEREG (basereg). This may look deceptively like
11226 the object in question was allocated to a register (rather than in
11227 memory) so DWARF consumers need to be aware of the subtle
11228 distinction between OP_REG and OP_BASEREG. */
11229 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
11230 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
11231 else if (stack_realign_drap
11233 && crtl
->args
.internal_arg_pointer
== rtl
11234 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
11236 /* If RTL is internal_arg_pointer, which has been optimized
11237 out, use DRAP instead. */
11238 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
11239 VAR_INIT_STATUS_INITIALIZED
);
11245 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11247 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
11248 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
11251 else if (GET_CODE (rtl
) == ZERO_EXTEND
11252 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11253 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
11254 < HOST_BITS_PER_WIDE_INT
11255 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
11256 to expand zero extend as two shifts instead of
11258 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
11260 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
11261 mem_loc_result
= op0
;
11262 add_loc_descr (&mem_loc_result
,
11263 int_loc_descriptor (GET_MODE_MASK (imode
)));
11264 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
11266 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11268 int shift
= DWARF2_ADDR_SIZE
11269 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
11270 shift
*= BITS_PER_UNIT
;
11271 if (GET_CODE (rtl
) == SIGN_EXTEND
)
11275 mem_loc_result
= op0
;
11276 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
11277 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
11278 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
11279 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
11281 else if (!dwarf_strict
)
11283 dw_die_ref type_die1
, type_die2
;
11284 dw_loc_descr_ref cvt
;
11286 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
11287 GET_CODE (rtl
) == ZERO_EXTEND
);
11288 if (type_die1
== NULL
)
11290 type_die2
= base_type_for_mode (mode
, 1);
11291 if (type_die2
== NULL
)
11293 mem_loc_result
= op0
;
11294 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11295 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11296 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
11297 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11298 add_loc_descr (&mem_loc_result
, cvt
);
11299 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11300 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11301 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
11302 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11303 add_loc_descr (&mem_loc_result
, cvt
);
11309 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
11310 if (new_rtl
!= rtl
)
11312 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
11314 if (mem_loc_result
!= NULL
)
11315 return mem_loc_result
;
11318 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
11319 get_address_mode (rtl
), mode
,
11320 VAR_INIT_STATUS_INITIALIZED
);
11321 if (mem_loc_result
== NULL
)
11322 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
11323 if (mem_loc_result
!= NULL
)
11325 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
11326 || GET_MODE_CLASS (mode
) != MODE_INT
)
11328 dw_die_ref type_die
;
11329 dw_loc_descr_ref deref
;
11334 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
11335 if (type_die
== NULL
)
11337 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
11338 GET_MODE_SIZE (mode
), 0);
11339 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
11340 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
11341 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
11342 add_loc_descr (&mem_loc_result
, deref
);
11344 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11345 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
11347 add_loc_descr (&mem_loc_result
,
11348 new_loc_descr (DW_OP_deref_size
,
11349 GET_MODE_SIZE (mode
), 0));
11354 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
11357 /* Some ports can transform a symbol ref into a label ref, because
11358 the symbol ref is too far away and has to be dumped into a constant
11362 if (GET_MODE_CLASS (mode
) != MODE_INT
11363 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
11364 #ifdef POINTERS_EXTEND_UNSIGNED
11365 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
11369 if (GET_CODE (rtl
) == SYMBOL_REF
11370 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11372 dw_loc_descr_ref temp
;
11374 /* If this is not defined, we have no way to emit the data. */
11375 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
11378 /* We used to emit DW_OP_addr here, but that's wrong, since
11379 DW_OP_addr should be relocated by the debug info consumer,
11380 while DW_OP_GNU_push_tls_address operand should not. */
11381 temp
= new_loc_descr (DWARF2_ADDR_SIZE
== 4
11382 ? DW_OP_const4u
: DW_OP_const8u
, 0, 0);
11383 temp
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
11384 temp
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
11385 temp
->dtprel
= true;
11387 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
11388 add_loc_descr (&mem_loc_result
, temp
);
11393 if (!const_ok_for_output (rtl
))
11397 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
11398 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
11399 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
11400 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
11406 case DEBUG_IMPLICIT_PTR
:
11407 expansion_failed (NULL_TREE
, rtl
,
11408 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
11414 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
11416 if (GET_MODE_CLASS (mode
) != MODE_INT
11417 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11418 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
11419 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
11422 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl
)),
11423 VAR_INIT_STATUS_INITIALIZED
);
11425 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
11426 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
11428 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
11429 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
11430 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
11434 gcc_unreachable ();
11437 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
11438 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11439 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
11442 case DEBUG_PARAMETER_REF
:
11443 mem_loc_result
= parameter_ref_descriptor (rtl
);
11447 /* Extract the PLUS expression nested inside and fall into
11448 PLUS code below. */
11449 rtl
= XEXP (rtl
, 1);
11454 /* Turn these into a PLUS expression and fall into the PLUS code
11456 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
11457 GEN_INT (GET_CODE (rtl
) == PRE_INC
11458 ? GET_MODE_UNIT_SIZE (mem_mode
)
11459 : -GET_MODE_UNIT_SIZE (mem_mode
)));
11461 /* ... fall through ... */
11465 if (is_based_loc (rtl
)
11466 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11467 && GET_MODE_CLASS (mode
) == MODE_INT
)
11468 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
11469 INTVAL (XEXP (rtl
, 1)),
11470 VAR_INIT_STATUS_INITIALIZED
);
11473 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11474 VAR_INIT_STATUS_INITIALIZED
);
11475 if (mem_loc_result
== 0)
11478 if (CONST_INT_P (XEXP (rtl
, 1))
11479 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11480 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
11483 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11484 VAR_INIT_STATUS_INITIALIZED
);
11487 add_loc_descr (&mem_loc_result
, op1
);
11488 add_loc_descr (&mem_loc_result
,
11489 new_loc_descr (DW_OP_plus
, 0, 0));
11494 /* If a pseudo-reg is optimized away, it is possible for it to
11495 be replaced with a MEM containing a multiply or shift. */
11506 && GET_MODE_CLASS (mode
) == MODE_INT
11507 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11509 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
11510 base_type_for_mode (mode
, 0),
11534 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11536 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11537 VAR_INIT_STATUS_INITIALIZED
);
11539 rtx rtlop1
= XEXP (rtl
, 1);
11540 if (GET_MODE (rtlop1
) != VOIDmode
11541 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
11542 < GET_MODE_BITSIZE (mode
))
11543 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
11544 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
11545 VAR_INIT_STATUS_INITIALIZED
);
11548 if (op0
== 0 || op1
== 0)
11551 mem_loc_result
= op0
;
11552 add_loc_descr (&mem_loc_result
, op1
);
11553 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
11569 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11570 VAR_INIT_STATUS_INITIALIZED
);
11571 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11572 VAR_INIT_STATUS_INITIALIZED
);
11574 if (op0
== 0 || op1
== 0)
11577 mem_loc_result
= op0
;
11578 add_loc_descr (&mem_loc_result
, op1
);
11579 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
11583 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
11585 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
11586 base_type_for_mode (mode
, 0),
11591 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11592 VAR_INIT_STATUS_INITIALIZED
);
11593 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11594 VAR_INIT_STATUS_INITIALIZED
);
11596 if (op0
== 0 || op1
== 0)
11599 mem_loc_result
= op0
;
11600 add_loc_descr (&mem_loc_result
, op1
);
11601 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
11602 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
11603 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
11604 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
11605 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
11609 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
11611 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
11616 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
11617 base_type_for_mode (mode
, 1),
11635 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11636 VAR_INIT_STATUS_INITIALIZED
);
11641 mem_loc_result
= op0
;
11642 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
11646 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11647 #ifdef POINTERS_EXTEND_UNSIGNED
11649 && mem_mode
!= VOIDmode
11650 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
11654 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
11658 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
11659 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
11661 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
11662 enum machine_mode amode
;
11663 if (type_die
== NULL
)
11665 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
11667 if (INTVAL (rtl
) >= 0
11668 && amode
!= BLKmode
11669 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
11670 /* const DW_OP_GNU_convert <XXX> vs.
11671 DW_OP_GNU_const_type <XXX, 1, const>. */
11672 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
11673 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
11675 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
11676 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11677 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11678 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11679 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11680 add_loc_descr (&mem_loc_result
, op0
);
11681 return mem_loc_result
;
11683 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
11685 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11686 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11687 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11688 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
11689 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
11692 mem_loc_result
->dw_loc_oprnd2
.val_class
11693 = dw_val_class_const_double
;
11694 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
11695 = shwi_to_double_int (INTVAL (rtl
));
11703 dw_die_ref type_die
;
11705 /* Note that a CONST_DOUBLE rtx could represent either an integer
11706 or a floating-point constant. A CONST_DOUBLE is used whenever
11707 the constant requires more than one word in order to be
11708 adequately represented. We output CONST_DOUBLEs as blocks. */
11709 if (mode
== VOIDmode
11710 || (GET_MODE (rtl
) == VOIDmode
11711 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
11713 type_die
= base_type_for_mode (mode
,
11714 GET_MODE_CLASS (mode
) == MODE_INT
);
11715 if (type_die
== NULL
)
11717 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
11718 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11719 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11720 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11721 if (SCALAR_FLOAT_MODE_P (mode
))
11723 unsigned int length
= GET_MODE_SIZE (mode
);
11724 unsigned char *array
11725 = (unsigned char*) ggc_alloc_atomic (length
);
11727 insert_float (rtl
, array
);
11728 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
11729 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
11730 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
11731 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
11735 mem_loc_result
->dw_loc_oprnd2
.val_class
11736 = dw_val_class_const_double
;
11737 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
11738 = rtx_to_double_int (rtl
);
11744 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
11748 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
11752 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
11756 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
11760 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
11764 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
11768 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
11772 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
11776 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
11780 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
11785 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11790 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
11795 if (CONST_INT_P (XEXP (rtl
, 1))
11796 && CONST_INT_P (XEXP (rtl
, 2))
11797 && ((unsigned) INTVAL (XEXP (rtl
, 1))
11798 + (unsigned) INTVAL (XEXP (rtl
, 2))
11799 <= GET_MODE_BITSIZE (mode
))
11800 && GET_MODE_CLASS (mode
) == MODE_INT
11801 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11802 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
11805 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
11806 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
11809 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
11813 mem_loc_result
= op0
;
11814 size
= INTVAL (XEXP (rtl
, 1));
11815 shift
= INTVAL (XEXP (rtl
, 2));
11816 if (BITS_BIG_ENDIAN
)
11817 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
11819 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
11821 add_loc_descr (&mem_loc_result
,
11822 int_loc_descriptor (DWARF2_ADDR_SIZE
11824 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
11826 if (size
!= (int) DWARF2_ADDR_SIZE
)
11828 add_loc_descr (&mem_loc_result
,
11829 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
11830 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
11837 dw_loc_descr_ref op2
, bra_node
, drop_node
;
11838 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
11839 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
11840 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
11841 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
11842 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11843 VAR_INIT_STATUS_INITIALIZED
);
11844 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
11845 VAR_INIT_STATUS_INITIALIZED
);
11846 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
11849 mem_loc_result
= op1
;
11850 add_loc_descr (&mem_loc_result
, op2
);
11851 add_loc_descr (&mem_loc_result
, op0
);
11852 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11853 add_loc_descr (&mem_loc_result
, bra_node
);
11854 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
11855 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11856 add_loc_descr (&mem_loc_result
, drop_node
);
11857 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11858 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11863 case FLOAT_TRUNCATE
:
11865 case UNSIGNED_FLOAT
:
11870 dw_die_ref type_die
;
11871 dw_loc_descr_ref cvt
;
11873 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
11874 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
11877 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
11878 && (GET_CODE (rtl
) == FLOAT
11879 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
11880 <= DWARF2_ADDR_SIZE
))
11882 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
11883 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
11884 if (type_die
== NULL
)
11886 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11887 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11888 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11889 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11890 add_loc_descr (&op0
, cvt
);
11892 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
11893 if (type_die
== NULL
)
11895 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11896 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11897 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11898 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11899 add_loc_descr (&op0
, cvt
);
11900 if (GET_MODE_CLASS (mode
) == MODE_INT
11901 && (GET_CODE (rtl
) == FIX
11902 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
11904 op0
= convert_descriptor_to_mode (mode
, op0
);
11908 mem_loc_result
= op0
;
11915 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
11920 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
11924 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
11929 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
11934 /* In theory, we could implement the above. */
11935 /* DWARF cannot represent the unsigned compare operations
11960 case FRACT_CONVERT
:
11961 case UNSIGNED_FRACT_CONVERT
:
11963 case UNSIGNED_SAT_FRACT
:
11969 case VEC_DUPLICATE
:
11973 case STRICT_LOW_PART
:
11977 /* If delegitimize_address couldn't do anything with the UNSPEC, we
11978 can't express it in the debug info. This can happen e.g. with some
11983 resolve_one_addr (&rtl
, NULL
);
11987 #ifdef ENABLE_CHECKING
11988 print_rtl (stderr
, rtl
);
11989 gcc_unreachable ();
11995 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11996 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11998 return mem_loc_result
;
12001 /* Return a descriptor that describes the concatenation of two locations.
12002 This is typically a complex variable. */
12004 static dw_loc_descr_ref
12005 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
12007 dw_loc_descr_ref cc_loc_result
= NULL
;
12008 dw_loc_descr_ref x0_ref
12009 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12010 dw_loc_descr_ref x1_ref
12011 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12013 if (x0_ref
== 0 || x1_ref
== 0)
12016 cc_loc_result
= x0_ref
;
12017 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
12019 add_loc_descr (&cc_loc_result
, x1_ref
);
12020 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
12022 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12023 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12025 return cc_loc_result
;
12028 /* Return a descriptor that describes the concatenation of N
12031 static dw_loc_descr_ref
12032 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
12035 dw_loc_descr_ref cc_loc_result
= NULL
;
12036 unsigned int n
= XVECLEN (concatn
, 0);
12038 for (i
= 0; i
< n
; ++i
)
12040 dw_loc_descr_ref ref
;
12041 rtx x
= XVECEXP (concatn
, 0, i
);
12043 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12047 add_loc_descr (&cc_loc_result
, ref
);
12048 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
12051 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12052 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12054 return cc_loc_result
;
12057 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12058 for DEBUG_IMPLICIT_PTR RTL. */
12060 static dw_loc_descr_ref
12061 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
12063 dw_loc_descr_ref ret
;
12068 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
12069 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
12070 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
12071 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
12072 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
12073 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12076 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12077 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12078 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12082 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12083 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
12088 /* Output a proper Dwarf location descriptor for a variable or parameter
12089 which is either allocated in a register or in a memory location. For a
12090 register, we just generate an OP_REG and the register number. For a
12091 memory location we provide a Dwarf postfix expression describing how to
12092 generate the (dynamic) address of the object onto the address stack.
12094 MODE is mode of the decl if this loc_descriptor is going to be used in
12095 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
12096 allowed, VOIDmode otherwise.
12098 If we don't know how to describe it, return 0. */
12100 static dw_loc_descr_ref
12101 loc_descriptor (rtx rtl
, enum machine_mode mode
,
12102 enum var_init_status initialized
)
12104 dw_loc_descr_ref loc_result
= NULL
;
12106 switch (GET_CODE (rtl
))
12109 /* The case of a subreg may arise when we have a local (register)
12110 variable or a formal (register) parameter which doesn't quite fill
12111 up an entire register. For now, just assume that it is
12112 legitimate to make the Dwarf info refer to the whole register which
12113 contains the given subreg. */
12114 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
12115 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
12116 GET_MODE (SUBREG_REG (rtl
)), initialized
);
12122 loc_result
= reg_loc_descriptor (rtl
, initialized
);
12126 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
12127 GET_MODE (rtl
), initialized
);
12128 if (loc_result
== NULL
)
12129 loc_result
= tls_mem_loc_descriptor (rtl
);
12130 if (loc_result
== NULL
)
12132 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12133 if (new_rtl
!= rtl
)
12134 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
12139 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
12144 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
12149 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
12151 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
12152 if (GET_CODE (loc
) == EXPR_LIST
)
12153 loc
= XEXP (loc
, 0);
12154 loc_result
= loc_descriptor (loc
, mode
, initialized
);
12158 rtl
= XEXP (rtl
, 1);
12163 rtvec par_elems
= XVEC (rtl
, 0);
12164 int num_elem
= GET_NUM_ELEM (par_elems
);
12165 enum machine_mode mode
;
12168 /* Create the first one, so we have something to add to. */
12169 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
12170 VOIDmode
, initialized
);
12171 if (loc_result
== NULL
)
12173 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
12174 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
12175 for (i
= 1; i
< num_elem
; i
++)
12177 dw_loc_descr_ref temp
;
12179 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
12180 VOIDmode
, initialized
);
12183 add_loc_descr (&loc_result
, temp
);
12184 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
12185 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
12191 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
12192 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
12197 if (mode
== VOIDmode
)
12198 mode
= GET_MODE (rtl
);
12200 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
12202 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
12204 /* Note that a CONST_DOUBLE rtx could represent either an integer
12205 or a floating-point constant. A CONST_DOUBLE is used whenever
12206 the constant requires more than one word in order to be
12207 adequately represented. We output CONST_DOUBLEs as blocks. */
12208 loc_result
= new_loc_descr (DW_OP_implicit_value
,
12209 GET_MODE_SIZE (mode
), 0);
12210 if (SCALAR_FLOAT_MODE_P (mode
))
12212 unsigned int length
= GET_MODE_SIZE (mode
);
12213 unsigned char *array
12214 = (unsigned char*) ggc_alloc_atomic (length
);
12216 insert_float (rtl
, array
);
12217 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12218 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12219 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12220 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12224 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
12225 loc_result
->dw_loc_oprnd2
.v
.val_double
12226 = rtx_to_double_int (rtl
);
12232 if (mode
== VOIDmode
)
12233 mode
= GET_MODE (rtl
);
12235 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
12237 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
12238 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
12239 unsigned char *array
= (unsigned char *)
12240 ggc_alloc_atomic (length
* elt_size
);
12244 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
12245 switch (GET_MODE_CLASS (mode
))
12247 case MODE_VECTOR_INT
:
12248 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
12250 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
12251 double_int val
= rtx_to_double_int (elt
);
12253 if (elt_size
<= sizeof (HOST_WIDE_INT
))
12254 insert_int (double_int_to_shwi (val
), elt_size
, p
);
12257 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
12258 insert_double (val
, p
);
12263 case MODE_VECTOR_FLOAT
:
12264 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
12266 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
12267 insert_float (elt
, p
);
12272 gcc_unreachable ();
12275 loc_result
= new_loc_descr (DW_OP_implicit_value
,
12276 length
* elt_size
, 0);
12277 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12278 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
12279 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
12280 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12285 if (mode
== VOIDmode
12286 || GET_CODE (XEXP (rtl
, 0)) == CONST_INT
12287 || GET_CODE (XEXP (rtl
, 0)) == CONST_DOUBLE
12288 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
12290 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
12295 if (!const_ok_for_output (rtl
))
12298 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
12299 && (dwarf_version
>= 4 || !dwarf_strict
))
12301 loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
12302 loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
12303 loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
12304 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
12305 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
12309 case DEBUG_IMPLICIT_PTR
:
12310 loc_result
= implicit_ptr_descriptor (rtl
, 0);
12314 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
12315 && CONST_INT_P (XEXP (rtl
, 1)))
12318 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
12324 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
12325 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
12326 && dwarf_version
>= 4)
12327 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
12329 /* Value expression. */
12330 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
12332 add_loc_descr (&loc_result
,
12333 new_loc_descr (DW_OP_stack_value
, 0, 0));
12341 /* We need to figure out what section we should use as the base for the
12342 address ranges where a given location is valid.
12343 1. If this particular DECL has a section associated with it, use that.
12344 2. If this function has a section associated with it, use that.
12345 3. Otherwise, use the text section.
12346 XXX: If you split a variable across multiple sections, we won't notice. */
12348 static const char *
12349 secname_for_decl (const_tree decl
)
12351 const char *secname
;
12353 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
12355 tree sectree
= DECL_SECTION_NAME (decl
);
12356 secname
= TREE_STRING_POINTER (sectree
);
12358 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
12360 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
12361 secname
= TREE_STRING_POINTER (sectree
);
12363 else if (cfun
&& in_cold_section_p
)
12364 secname
= crtl
->subsections
.cold_section_label
;
12366 secname
= text_section_label
;
12371 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
12374 decl_by_reference_p (tree decl
)
12376 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
12377 || TREE_CODE (decl
) == VAR_DECL
)
12378 && DECL_BY_REFERENCE (decl
));
12381 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
12384 static dw_loc_descr_ref
12385 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
12386 enum var_init_status initialized
)
12388 int have_address
= 0;
12389 dw_loc_descr_ref descr
;
12390 enum machine_mode mode
;
12392 if (want_address
!= 2)
12394 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
12396 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
12398 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
12399 if (GET_CODE (varloc
) == EXPR_LIST
)
12400 varloc
= XEXP (varloc
, 0);
12401 mode
= GET_MODE (varloc
);
12402 if (MEM_P (varloc
))
12404 rtx addr
= XEXP (varloc
, 0);
12405 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
12406 mode
, initialized
);
12411 rtx x
= avoid_constant_pool_reference (varloc
);
12413 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
12418 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
12425 if (GET_CODE (varloc
) == VAR_LOCATION
)
12426 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
12428 mode
= DECL_MODE (loc
);
12429 descr
= loc_descriptor (varloc
, mode
, initialized
);
12436 if (want_address
== 2 && !have_address
12437 && (dwarf_version
>= 4 || !dwarf_strict
))
12439 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
12441 expansion_failed (loc
, NULL_RTX
,
12442 "DWARF address size mismatch");
12445 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
12448 /* Show if we can't fill the request for an address. */
12449 if (want_address
&& !have_address
)
12451 expansion_failed (loc
, NULL_RTX
,
12452 "Want address and only have value");
12456 /* If we've got an address and don't want one, dereference. */
12457 if (!want_address
&& have_address
)
12459 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
12460 enum dwarf_location_atom op
;
12462 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
12464 expansion_failed (loc
, NULL_RTX
,
12465 "DWARF address size mismatch");
12468 else if (size
== DWARF2_ADDR_SIZE
)
12471 op
= DW_OP_deref_size
;
12473 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
12479 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
12480 if it is not possible. */
12482 static dw_loc_descr_ref
12483 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
12485 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
12486 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
12487 else if (dwarf_version
>= 3 || !dwarf_strict
)
12488 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
12493 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
12494 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
12496 static dw_loc_descr_ref
12497 dw_sra_loc_expr (tree decl
, rtx loc
)
12500 unsigned int padsize
= 0;
12501 dw_loc_descr_ref descr
, *descr_tail
;
12502 unsigned HOST_WIDE_INT decl_size
;
12504 enum var_init_status initialized
;
12506 if (DECL_SIZE (decl
) == NULL
12507 || !host_integerp (DECL_SIZE (decl
), 1))
12510 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
12512 descr_tail
= &descr
;
12514 for (p
= loc
; p
; p
= XEXP (p
, 1))
12516 unsigned int bitsize
= decl_piece_bitsize (p
);
12517 rtx loc_note
= *decl_piece_varloc_ptr (p
);
12518 dw_loc_descr_ref cur_descr
;
12519 dw_loc_descr_ref
*tail
, last
= NULL
;
12520 unsigned int opsize
= 0;
12522 if (loc_note
== NULL_RTX
12523 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
12525 padsize
+= bitsize
;
12528 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
12529 varloc
= NOTE_VAR_LOCATION (loc_note
);
12530 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
12531 if (cur_descr
== NULL
)
12533 padsize
+= bitsize
;
12537 /* Check that cur_descr either doesn't use
12538 DW_OP_*piece operations, or their sum is equal
12539 to bitsize. Otherwise we can't embed it. */
12540 for (tail
= &cur_descr
; *tail
!= NULL
;
12541 tail
= &(*tail
)->dw_loc_next
)
12542 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
12544 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
12548 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
12550 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
12554 if (last
!= NULL
&& opsize
!= bitsize
)
12556 padsize
+= bitsize
;
12560 /* If there is a hole, add DW_OP_*piece after empty DWARF
12561 expression, which means that those bits are optimized out. */
12564 if (padsize
> decl_size
)
12566 decl_size
-= padsize
;
12567 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
12568 if (*descr_tail
== NULL
)
12570 descr_tail
= &(*descr_tail
)->dw_loc_next
;
12573 *descr_tail
= cur_descr
;
12575 if (bitsize
> decl_size
)
12577 decl_size
-= bitsize
;
12580 HOST_WIDE_INT offset
= 0;
12581 if (GET_CODE (varloc
) == VAR_LOCATION
12582 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
12584 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
12585 if (GET_CODE (varloc
) == EXPR_LIST
)
12586 varloc
= XEXP (varloc
, 0);
12590 if (GET_CODE (varloc
) == CONST
12591 || GET_CODE (varloc
) == SIGN_EXTEND
12592 || GET_CODE (varloc
) == ZERO_EXTEND
)
12593 varloc
= XEXP (varloc
, 0);
12594 else if (GET_CODE (varloc
) == SUBREG
)
12595 varloc
= SUBREG_REG (varloc
);
12600 /* DW_OP_bit_size offset should be zero for register
12601 or implicit location descriptions and empty location
12602 descriptions, but for memory addresses needs big endian
12604 if (MEM_P (varloc
))
12606 unsigned HOST_WIDE_INT memsize
12607 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
12608 if (memsize
!= bitsize
)
12610 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
12611 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
12613 if (memsize
< bitsize
)
12615 if (BITS_BIG_ENDIAN
)
12616 offset
= memsize
- bitsize
;
12620 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
12621 if (*descr_tail
== NULL
)
12623 descr_tail
= &(*descr_tail
)->dw_loc_next
;
12627 /* If there were any non-empty expressions, add padding till the end of
12629 if (descr
!= NULL
&& decl_size
!= 0)
12631 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
12632 if (*descr_tail
== NULL
)
12638 /* Return the dwarf representation of the location list LOC_LIST of
12639 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
12642 static dw_loc_list_ref
12643 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
12645 const char *endname
, *secname
;
12647 enum var_init_status initialized
;
12648 struct var_loc_node
*node
;
12649 dw_loc_descr_ref descr
;
12650 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
12651 dw_loc_list_ref list
= NULL
;
12652 dw_loc_list_ref
*listp
= &list
;
12654 /* Now that we know what section we are using for a base,
12655 actually construct the list of locations.
12656 The first location information is what is passed to the
12657 function that creates the location list, and the remaining
12658 locations just get added on to that list.
12659 Note that we only know the start address for a location
12660 (IE location changes), so to build the range, we use
12661 the range [current location start, next location start].
12662 This means we have to special case the last node, and generate
12663 a range of [last location start, end of function label]. */
12665 secname
= secname_for_decl (decl
);
12667 for (node
= loc_list
->first
; node
; node
= node
->next
)
12668 if (GET_CODE (node
->loc
) == EXPR_LIST
12669 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
12671 if (GET_CODE (node
->loc
) == EXPR_LIST
)
12673 /* This requires DW_OP_{,bit_}piece, which is not usable
12674 inside DWARF expressions. */
12675 if (want_address
!= 2)
12677 descr
= dw_sra_loc_expr (decl
, node
->loc
);
12683 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
12684 varloc
= NOTE_VAR_LOCATION (node
->loc
);
12685 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
12689 bool range_across_switch
= false;
12690 /* If section switch happens in between node->label
12691 and node->next->label (or end of function) and
12692 we can't emit it as a single entry list,
12693 emit two ranges, first one ending at the end
12694 of first partition and second one starting at the
12695 beginning of second partition. */
12696 if (node
== loc_list
->last_before_switch
12697 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
12698 && current_function_decl
)
12700 endname
= cfun
->fde
->dw_fde_end
;
12701 range_across_switch
= true;
12703 /* The variable has a location between NODE->LABEL and
12704 NODE->NEXT->LABEL. */
12705 else if (node
->next
)
12706 endname
= node
->next
->label
;
12707 /* If the variable has a location at the last label
12708 it keeps its location until the end of function. */
12709 else if (!current_function_decl
)
12710 endname
= text_end_label
;
12713 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
12714 current_function_funcdef_no
);
12715 endname
= ggc_strdup (label_id
);
12718 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
12719 if (TREE_CODE (decl
) == PARM_DECL
12720 && node
== loc_list
->first
12721 && GET_CODE (node
->loc
) == NOTE
12722 && strcmp (node
->label
, endname
) == 0)
12723 (*listp
)->force
= true;
12724 listp
= &(*listp
)->dw_loc_next
;
12726 if (range_across_switch
)
12728 if (GET_CODE (node
->loc
) == EXPR_LIST
)
12729 descr
= dw_sra_loc_expr (decl
, node
->loc
);
12732 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
12733 varloc
= NOTE_VAR_LOCATION (node
->loc
);
12734 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
12737 gcc_assert (descr
);
12738 /* The variable has a location between NODE->LABEL and
12739 NODE->NEXT->LABEL. */
12741 endname
= node
->next
->label
;
12743 endname
= cfun
->fde
->dw_fde_second_end
;
12744 *listp
= new_loc_list (descr
,
12745 cfun
->fde
->dw_fde_second_begin
,
12747 listp
= &(*listp
)->dw_loc_next
;
12752 /* Try to avoid the overhead of a location list emitting a location
12753 expression instead, but only if we didn't have more than one
12754 location entry in the first place. If some entries were not
12755 representable, we don't want to pretend a single entry that was
12756 applies to the entire scope in which the variable is
12758 if (list
&& loc_list
->first
->next
)
12764 /* Return if the loc_list has only single element and thus can be represented
12765 as location description. */
12768 single_element_loc_list_p (dw_loc_list_ref list
)
12770 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
12771 return !list
->ll_symbol
;
12774 /* To each location in list LIST add loc descr REF. */
12777 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
12779 dw_loc_descr_ref copy
;
12780 add_loc_descr (&list
->expr
, ref
);
12781 list
= list
->dw_loc_next
;
12784 copy
= ggc_alloc_dw_loc_descr_node ();
12785 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
12786 add_loc_descr (&list
->expr
, copy
);
12787 while (copy
->dw_loc_next
)
12789 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
12790 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
12791 copy
->dw_loc_next
= new_copy
;
12794 list
= list
->dw_loc_next
;
12798 /* Given two lists RET and LIST
12799 produce location list that is result of adding expression in LIST
12800 to expression in RET on each position in program.
12801 Might be destructive on both RET and LIST.
12803 TODO: We handle only simple cases of RET or LIST having at most one
12804 element. General case would inolve sorting the lists in program order
12805 and merging them that will need some additional work.
12806 Adding that will improve quality of debug info especially for SRA-ed
12810 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
12819 if (!list
->dw_loc_next
)
12821 add_loc_descr_to_each (*ret
, list
->expr
);
12824 if (!(*ret
)->dw_loc_next
)
12826 add_loc_descr_to_each (list
, (*ret
)->expr
);
12830 expansion_failed (NULL_TREE
, NULL_RTX
,
12831 "Don't know how to merge two non-trivial"
12832 " location lists.\n");
12837 /* LOC is constant expression. Try a luck, look it up in constant
12838 pool and return its loc_descr of its address. */
12840 static dw_loc_descr_ref
12841 cst_pool_loc_descr (tree loc
)
12843 /* Get an RTL for this, if something has been emitted. */
12844 rtx rtl
= lookup_constant_def (loc
);
12846 if (!rtl
|| !MEM_P (rtl
))
12851 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
12853 /* TODO: We might get more coverage if we was actually delaying expansion
12854 of all expressions till end of compilation when constant pools are fully
12856 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
12858 expansion_failed (loc
, NULL_RTX
,
12859 "CST value in contant pool but not marked.");
12862 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
12863 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
12866 /* Return dw_loc_list representing address of addr_expr LOC
12867 by looking for inner INDIRECT_REF expression and turning
12868 it into simple arithmetics. */
12870 static dw_loc_list_ref
12871 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
12874 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
12875 enum machine_mode mode
;
12876 int unsignedp
, volatilep
= 0;
12877 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
12879 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
12880 &bitsize
, &bitpos
, &offset
, &mode
,
12881 &unsignedp
, &volatilep
, false);
12883 if (bitpos
% BITS_PER_UNIT
)
12885 expansion_failed (loc
, NULL_RTX
, "bitfield access");
12888 if (!INDIRECT_REF_P (obj
))
12890 expansion_failed (obj
,
12891 NULL_RTX
, "no indirect ref in inner refrence");
12894 if (!offset
&& !bitpos
)
12895 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
12897 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
12898 && (dwarf_version
>= 4 || !dwarf_strict
))
12900 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
12905 /* Variable offset. */
12906 list_ret1
= loc_list_from_tree (offset
, 0);
12907 if (list_ret1
== 0)
12909 add_loc_list (&list_ret
, list_ret1
);
12912 add_loc_descr_to_each (list_ret
,
12913 new_loc_descr (DW_OP_plus
, 0, 0));
12915 bytepos
= bitpos
/ BITS_PER_UNIT
;
12917 add_loc_descr_to_each (list_ret
,
12918 new_loc_descr (DW_OP_plus_uconst
,
12920 else if (bytepos
< 0)
12921 loc_list_plus_const (list_ret
, bytepos
);
12922 add_loc_descr_to_each (list_ret
,
12923 new_loc_descr (DW_OP_stack_value
, 0, 0));
12929 /* Generate Dwarf location list representing LOC.
12930 If WANT_ADDRESS is false, expression computing LOC will be computed
12931 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
12932 if WANT_ADDRESS is 2, expression computing address useable in location
12933 will be returned (i.e. DW_OP_reg can be used
12934 to refer to register values). */
12936 static dw_loc_list_ref
12937 loc_list_from_tree (tree loc
, int want_address
)
12939 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
12940 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
12941 int have_address
= 0;
12942 enum dwarf_location_atom op
;
12944 /* ??? Most of the time we do not take proper care for sign/zero
12945 extending the values properly. Hopefully this won't be a real
12948 switch (TREE_CODE (loc
))
12951 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
12954 case PLACEHOLDER_EXPR
:
12955 /* This case involves extracting fields from an object to determine the
12956 position of other fields. We don't try to encode this here. The
12957 only user of this is Ada, which encodes the needed information using
12958 the names of types. */
12959 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
12963 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
12964 /* There are no opcodes for these operations. */
12967 case PREINCREMENT_EXPR
:
12968 case PREDECREMENT_EXPR
:
12969 case POSTINCREMENT_EXPR
:
12970 case POSTDECREMENT_EXPR
:
12971 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
12972 /* There are no opcodes for these operations. */
12976 /* If we already want an address, see if there is INDIRECT_REF inside
12977 e.g. for &this->field. */
12980 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
12981 (loc
, want_address
== 2);
12984 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
12985 && (ret
= cst_pool_loc_descr (loc
)))
12988 /* Otherwise, process the argument and look for the address. */
12989 if (!list_ret
&& !ret
)
12990 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
12994 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
13000 if (DECL_THREAD_LOCAL_P (loc
))
13003 enum dwarf_location_atom first_op
;
13004 enum dwarf_location_atom second_op
;
13005 bool dtprel
= false;
13007 if (targetm
.have_tls
)
13009 /* If this is not defined, we have no way to emit the
13011 if (!targetm
.asm_out
.output_dwarf_dtprel
)
13014 /* The way DW_OP_GNU_push_tls_address is specified, we
13015 can only look up addresses of objects in the current
13016 module. We used DW_OP_addr as first op, but that's
13017 wrong, because DW_OP_addr is relocated by the debug
13018 info consumer, while DW_OP_GNU_push_tls_address
13019 operand shouldn't be. */
13020 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
13022 first_op
= DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
;
13024 second_op
= DW_OP_GNU_push_tls_address
;
13028 if (!targetm
.emutls
.debug_form_tls_address
13029 || !(dwarf_version
>= 3 || !dwarf_strict
))
13031 /* We stuffed the control variable into the DECL_VALUE_EXPR
13032 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13033 no longer appear in gimple code. We used the control
13034 variable in specific so that we could pick it up here. */
13035 loc
= DECL_VALUE_EXPR (loc
);
13036 first_op
= DW_OP_addr
;
13037 second_op
= DW_OP_form_tls_address
;
13040 rtl
= rtl_for_decl_location (loc
);
13041 if (rtl
== NULL_RTX
)
13046 rtl
= XEXP (rtl
, 0);
13047 if (! CONSTANT_P (rtl
))
13050 ret
= new_loc_descr (first_op
, 0, 0);
13051 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
13052 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
13053 ret
->dtprel
= dtprel
;
13055 ret1
= new_loc_descr (second_op
, 0, 0);
13056 add_loc_descr (&ret
, ret1
);
13065 if (DECL_HAS_VALUE_EXPR_P (loc
))
13066 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
13070 case FUNCTION_DECL
:
13073 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
13075 if (loc_list
&& loc_list
->first
)
13077 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
13078 have_address
= want_address
!= 0;
13081 rtl
= rtl_for_decl_location (loc
);
13082 if (rtl
== NULL_RTX
)
13084 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
13087 else if (CONST_INT_P (rtl
))
13089 HOST_WIDE_INT val
= INTVAL (rtl
);
13090 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13091 val
&= GET_MODE_MASK (DECL_MODE (loc
));
13092 ret
= int_loc_descriptor (val
);
13094 else if (GET_CODE (rtl
) == CONST_STRING
)
13096 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
13099 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
13101 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
13102 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
13103 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
13107 enum machine_mode mode
, mem_mode
;
13109 /* Certain constructs can only be represented at top-level. */
13110 if (want_address
== 2)
13112 ret
= loc_descriptor (rtl
, VOIDmode
,
13113 VAR_INIT_STATUS_INITIALIZED
);
13118 mode
= GET_MODE (rtl
);
13119 mem_mode
= VOIDmode
;
13123 mode
= get_address_mode (rtl
);
13124 rtl
= XEXP (rtl
, 0);
13127 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
13128 VAR_INIT_STATUS_INITIALIZED
);
13131 expansion_failed (loc
, rtl
,
13132 "failed to produce loc descriptor for rtl");
13139 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
13143 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13147 case COMPOUND_EXPR
:
13148 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
13151 case VIEW_CONVERT_EXPR
:
13154 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
13156 case COMPONENT_REF
:
13157 case BIT_FIELD_REF
:
13159 case ARRAY_RANGE_REF
:
13160 case REALPART_EXPR
:
13161 case IMAGPART_EXPR
:
13164 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13165 enum machine_mode mode
;
13166 int unsignedp
, volatilep
= 0;
13168 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
13169 &unsignedp
, &volatilep
, false);
13171 gcc_assert (obj
!= loc
);
13173 list_ret
= loc_list_from_tree (obj
,
13175 && !bitpos
&& !offset
? 2 : 1);
13176 /* TODO: We can extract value of the small expression via shifting even
13177 for nonzero bitpos. */
13180 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
13182 expansion_failed (loc
, NULL_RTX
,
13183 "bitfield access");
13187 if (offset
!= NULL_TREE
)
13189 /* Variable offset. */
13190 list_ret1
= loc_list_from_tree (offset
, 0);
13191 if (list_ret1
== 0)
13193 add_loc_list (&list_ret
, list_ret1
);
13196 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
13199 bytepos
= bitpos
/ BITS_PER_UNIT
;
13201 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
13202 else if (bytepos
< 0)
13203 loc_list_plus_const (list_ret
, bytepos
);
13210 if ((want_address
|| !host_integerp (loc
, 0))
13211 && (ret
= cst_pool_loc_descr (loc
)))
13213 else if (want_address
== 2
13214 && host_integerp (loc
, 0)
13215 && (ret
= address_of_int_loc_descriptor
13216 (int_size_in_bytes (TREE_TYPE (loc
)),
13217 tree_low_cst (loc
, 0))))
13219 else if (host_integerp (loc
, 0))
13220 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
13223 expansion_failed (loc
, NULL_RTX
,
13224 "Integer operand is not host integer");
13233 if ((ret
= cst_pool_loc_descr (loc
)))
13236 /* We can construct small constants here using int_loc_descriptor. */
13237 expansion_failed (loc
, NULL_RTX
,
13238 "constructor or constant not in constant pool");
13241 case TRUTH_AND_EXPR
:
13242 case TRUTH_ANDIF_EXPR
:
13247 case TRUTH_XOR_EXPR
:
13252 case TRUTH_OR_EXPR
:
13253 case TRUTH_ORIF_EXPR
:
13258 case FLOOR_DIV_EXPR
:
13259 case CEIL_DIV_EXPR
:
13260 case ROUND_DIV_EXPR
:
13261 case TRUNC_DIV_EXPR
:
13262 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13271 case FLOOR_MOD_EXPR
:
13272 case CEIL_MOD_EXPR
:
13273 case ROUND_MOD_EXPR
:
13274 case TRUNC_MOD_EXPR
:
13275 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13280 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13281 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
13282 if (list_ret
== 0 || list_ret1
== 0)
13285 add_loc_list (&list_ret
, list_ret1
);
13288 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
13289 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
13290 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
13291 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
13292 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
13304 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
13307 case POINTER_PLUS_EXPR
:
13309 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
13311 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13315 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
13323 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
13330 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
13337 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
13344 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
13359 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13360 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
13361 if (list_ret
== 0 || list_ret1
== 0)
13364 add_loc_list (&list_ret
, list_ret1
);
13367 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
13370 case TRUTH_NOT_EXPR
:
13384 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13388 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
13394 const enum tree_code code
=
13395 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
13397 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
13398 build2 (code
, integer_type_node
,
13399 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
13400 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
13403 /* ... fall through ... */
13407 dw_loc_descr_ref lhs
13408 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
13409 dw_loc_list_ref rhs
13410 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
13411 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
13413 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13414 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
13417 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13418 add_loc_descr_to_each (list_ret
, bra_node
);
13420 add_loc_list (&list_ret
, rhs
);
13421 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
13422 add_loc_descr_to_each (list_ret
, jump_node
);
13424 add_loc_descr_to_each (list_ret
, lhs
);
13425 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13426 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
13428 /* ??? Need a node to point the skip at. Use a nop. */
13429 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
13430 add_loc_descr_to_each (list_ret
, tmp
);
13431 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13432 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
13436 case FIX_TRUNC_EXPR
:
13440 /* Leave front-end specific codes as simply unknown. This comes
13441 up, for instance, with the C STMT_EXPR. */
13442 if ((unsigned int) TREE_CODE (loc
)
13443 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
13445 expansion_failed (loc
, NULL_RTX
,
13446 "language specific tree node");
13450 #ifdef ENABLE_CHECKING
13451 /* Otherwise this is a generic code; we should just lists all of
13452 these explicitly. We forgot one. */
13453 gcc_unreachable ();
13455 /* In a release build, we want to degrade gracefully: better to
13456 generate incomplete debugging information than to crash. */
13461 if (!ret
&& !list_ret
)
13464 if (want_address
== 2 && !have_address
13465 && (dwarf_version
>= 4 || !dwarf_strict
))
13467 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13469 expansion_failed (loc
, NULL_RTX
,
13470 "DWARF address size mismatch");
13474 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13476 add_loc_descr_to_each (list_ret
,
13477 new_loc_descr (DW_OP_stack_value
, 0, 0));
13480 /* Show if we can't fill the request for an address. */
13481 if (want_address
&& !have_address
)
13483 expansion_failed (loc
, NULL_RTX
,
13484 "Want address and only have value");
13488 gcc_assert (!ret
|| !list_ret
);
13490 /* If we've got an address and don't want one, dereference. */
13491 if (!want_address
&& have_address
)
13493 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13495 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13497 expansion_failed (loc
, NULL_RTX
,
13498 "DWARF address size mismatch");
13501 else if (size
== DWARF2_ADDR_SIZE
)
13504 op
= DW_OP_deref_size
;
13507 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
13509 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
13512 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
13517 /* Same as above but return only single location expression. */
13518 static dw_loc_descr_ref
13519 loc_descriptor_from_tree (tree loc
, int want_address
)
13521 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
13524 if (ret
->dw_loc_next
)
13526 expansion_failed (loc
, NULL_RTX
,
13527 "Location list where only loc descriptor needed");
13533 /* Given a value, round it up to the lowest multiple of `boundary'
13534 which is not less than the value itself. */
13536 static inline HOST_WIDE_INT
13537 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
13539 return (((value
+ boundary
- 1) / boundary
) * boundary
);
13542 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
13543 pointer to the declared type for the relevant field variable, or return
13544 `integer_type_node' if the given node turns out to be an
13545 ERROR_MARK node. */
13548 field_type (const_tree decl
)
13552 if (TREE_CODE (decl
) == ERROR_MARK
)
13553 return integer_type_node
;
13555 type
= DECL_BIT_FIELD_TYPE (decl
);
13556 if (type
== NULL_TREE
)
13557 type
= TREE_TYPE (decl
);
13562 /* Given a pointer to a tree node, return the alignment in bits for
13563 it, or else return BITS_PER_WORD if the node actually turns out to
13564 be an ERROR_MARK node. */
13566 static inline unsigned
13567 simple_type_align_in_bits (const_tree type
)
13569 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
13572 static inline unsigned
13573 simple_decl_align_in_bits (const_tree decl
)
13575 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
13578 /* Return the result of rounding T up to ALIGN. */
13580 static inline double_int
13581 round_up_to_align (double_int t
, unsigned int align
)
13583 double_int alignd
= uhwi_to_double_int (align
);
13584 t
= double_int_add (t
, alignd
);
13585 t
= double_int_add (t
, double_int_minus_one
);
13586 t
= double_int_div (t
, alignd
, true, TRUNC_DIV_EXPR
);
13587 t
= double_int_mul (t
, alignd
);
13591 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
13592 lowest addressed byte of the "containing object" for the given FIELD_DECL,
13593 or return 0 if we are unable to determine what that offset is, either
13594 because the argument turns out to be a pointer to an ERROR_MARK node, or
13595 because the offset is actually variable. (We can't handle the latter case
13598 static HOST_WIDE_INT
13599 field_byte_offset (const_tree decl
)
13601 double_int object_offset_in_bits
;
13602 double_int object_offset_in_bytes
;
13603 double_int bitpos_int
;
13605 if (TREE_CODE (decl
) == ERROR_MARK
)
13608 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
13610 /* We cannot yet cope with fields whose positions are variable, so
13611 for now, when we see such things, we simply return 0. Someday, we may
13612 be able to handle such cases, but it will be damn difficult. */
13613 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
13616 bitpos_int
= tree_to_double_int (bit_position (decl
));
13618 #ifdef PCC_BITFIELD_TYPE_MATTERS
13619 if (PCC_BITFIELD_TYPE_MATTERS
)
13622 tree field_size_tree
;
13623 double_int deepest_bitpos
;
13624 double_int field_size_in_bits
;
13625 unsigned int type_align_in_bits
;
13626 unsigned int decl_align_in_bits
;
13627 double_int type_size_in_bits
;
13629 type
= field_type (decl
);
13630 type_size_in_bits
= double_int_type_size_in_bits (type
);
13631 type_align_in_bits
= simple_type_align_in_bits (type
);
13633 field_size_tree
= DECL_SIZE (decl
);
13635 /* The size could be unspecified if there was an error, or for
13636 a flexible array member. */
13637 if (!field_size_tree
)
13638 field_size_tree
= bitsize_zero_node
;
13640 /* If the size of the field is not constant, use the type size. */
13641 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
13642 field_size_in_bits
= tree_to_double_int (field_size_tree
);
13644 field_size_in_bits
= type_size_in_bits
;
13646 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
13648 /* The GCC front-end doesn't make any attempt to keep track of the
13649 starting bit offset (relative to the start of the containing
13650 structure type) of the hypothetical "containing object" for a
13651 bit-field. Thus, when computing the byte offset value for the
13652 start of the "containing object" of a bit-field, we must deduce
13653 this information on our own. This can be rather tricky to do in
13654 some cases. For example, handling the following structure type
13655 definition when compiling for an i386/i486 target (which only
13656 aligns long long's to 32-bit boundaries) can be very tricky:
13658 struct S { int field1; long long field2:31; };
13660 Fortunately, there is a simple rule-of-thumb which can be used
13661 in such cases. When compiling for an i386/i486, GCC will
13662 allocate 8 bytes for the structure shown above. It decides to
13663 do this based upon one simple rule for bit-field allocation.
13664 GCC allocates each "containing object" for each bit-field at
13665 the first (i.e. lowest addressed) legitimate alignment boundary
13666 (based upon the required minimum alignment for the declared
13667 type of the field) which it can possibly use, subject to the
13668 condition that there is still enough available space remaining
13669 in the containing object (when allocated at the selected point)
13670 to fully accommodate all of the bits of the bit-field itself.
13672 This simple rule makes it obvious why GCC allocates 8 bytes for
13673 each object of the structure type shown above. When looking
13674 for a place to allocate the "containing object" for `field2',
13675 the compiler simply tries to allocate a 64-bit "containing
13676 object" at each successive 32-bit boundary (starting at zero)
13677 until it finds a place to allocate that 64- bit field such that
13678 at least 31 contiguous (and previously unallocated) bits remain
13679 within that selected 64 bit field. (As it turns out, for the
13680 example above, the compiler finds it is OK to allocate the
13681 "containing object" 64-bit field at bit-offset zero within the
13684 Here we attempt to work backwards from the limited set of facts
13685 we're given, and we try to deduce from those facts, where GCC
13686 must have believed that the containing object started (within
13687 the structure type). The value we deduce is then used (by the
13688 callers of this routine) to generate DW_AT_location and
13689 DW_AT_bit_offset attributes for fields (both bit-fields and, in
13690 the case of DW_AT_location, regular fields as well). */
13692 /* Figure out the bit-distance from the start of the structure to
13693 the "deepest" bit of the bit-field. */
13694 deepest_bitpos
= double_int_add (bitpos_int
, field_size_in_bits
);
13696 /* This is the tricky part. Use some fancy footwork to deduce
13697 where the lowest addressed bit of the containing object must
13699 object_offset_in_bits
13700 = double_int_sub (deepest_bitpos
, type_size_in_bits
);
13702 /* Round up to type_align by default. This works best for
13704 object_offset_in_bits
13705 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
13707 if (double_int_ucmp (object_offset_in_bits
, bitpos_int
) > 0)
13709 object_offset_in_bits
13710 = double_int_sub (deepest_bitpos
, type_size_in_bits
);
13712 /* Round up to decl_align instead. */
13713 object_offset_in_bits
13714 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
13718 #endif /* PCC_BITFIELD_TYPE_MATTERS */
13719 object_offset_in_bits
= bitpos_int
;
13721 object_offset_in_bytes
13722 = double_int_div (object_offset_in_bits
,
13723 uhwi_to_double_int (BITS_PER_UNIT
), true,
13725 return double_int_to_shwi (object_offset_in_bytes
);
13728 /* The following routines define various Dwarf attributes and any data
13729 associated with them. */
13731 /* Add a location description attribute value to a DIE.
13733 This emits location attributes suitable for whole variables and
13734 whole parameters. Note that the location attributes for struct fields are
13735 generated by the routine `data_member_location_attribute' below. */
13738 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
13739 dw_loc_list_ref descr
)
13743 if (single_element_loc_list_p (descr
))
13744 add_AT_loc (die
, attr_kind
, descr
->expr
);
13746 add_AT_loc_list (die
, attr_kind
, descr
);
13749 /* Add DW_AT_accessibility attribute to DIE if needed. */
13752 add_accessibility_attribute (dw_die_ref die
, tree decl
)
13754 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
13755 children, otherwise the default is DW_ACCESS_public. In DWARF2
13756 the default has always been DW_ACCESS_public. */
13757 if (TREE_PROTECTED (decl
))
13758 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
13759 else if (TREE_PRIVATE (decl
))
13761 if (dwarf_version
== 2
13762 || die
->die_parent
== NULL
13763 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
13764 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
13766 else if (dwarf_version
> 2
13768 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
13769 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
13772 /* Attach the specialized form of location attribute used for data members of
13773 struct and union types. In the special case of a FIELD_DECL node which
13774 represents a bit-field, the "offset" part of this special location
13775 descriptor must indicate the distance in bytes from the lowest-addressed
13776 byte of the containing struct or union type to the lowest-addressed byte of
13777 the "containing object" for the bit-field. (See the `field_byte_offset'
13780 For any given bit-field, the "containing object" is a hypothetical object
13781 (of some integral or enum type) within which the given bit-field lives. The
13782 type of this hypothetical "containing object" is always the same as the
13783 declared type of the individual bit-field itself (for GCC anyway... the
13784 DWARF spec doesn't actually mandate this). Note that it is the size (in
13785 bytes) of the hypothetical "containing object" which will be given in the
13786 DW_AT_byte_size attribute for this bit-field. (See the
13787 `byte_size_attribute' function below.) It is also used when calculating the
13788 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
13789 function below.) */
13792 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
13794 HOST_WIDE_INT offset
;
13795 dw_loc_descr_ref loc_descr
= 0;
13797 if (TREE_CODE (decl
) == TREE_BINFO
)
13799 /* We're working on the TAG_inheritance for a base class. */
13800 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
13802 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
13803 aren't at a fixed offset from all (sub)objects of the same
13804 type. We need to extract the appropriate offset from our
13805 vtable. The following dwarf expression means
13807 BaseAddr = ObAddr + *((*ObAddr) - Offset)
13809 This is specific to the V3 ABI, of course. */
13811 dw_loc_descr_ref tmp
;
13813 /* Make a copy of the object address. */
13814 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
13815 add_loc_descr (&loc_descr
, tmp
);
13817 /* Extract the vtable address. */
13818 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
13819 add_loc_descr (&loc_descr
, tmp
);
13821 /* Calculate the address of the offset. */
13822 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
13823 gcc_assert (offset
< 0);
13825 tmp
= int_loc_descriptor (-offset
);
13826 add_loc_descr (&loc_descr
, tmp
);
13827 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
13828 add_loc_descr (&loc_descr
, tmp
);
13830 /* Extract the offset. */
13831 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
13832 add_loc_descr (&loc_descr
, tmp
);
13834 /* Add it to the object address. */
13835 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
13836 add_loc_descr (&loc_descr
, tmp
);
13839 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
13842 offset
= field_byte_offset (decl
);
13846 if (dwarf_version
> 2)
13848 /* Don't need to output a location expression, just the constant. */
13850 add_AT_int (die
, DW_AT_data_member_location
, offset
);
13852 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
13857 enum dwarf_location_atom op
;
13859 /* The DWARF2 standard says that we should assume that the structure
13860 address is already on the stack, so we can specify a structure
13861 field address by using DW_OP_plus_uconst. */
13862 op
= DW_OP_plus_uconst
;
13863 loc_descr
= new_loc_descr (op
, offset
, 0);
13867 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
13870 /* Writes integer values to dw_vec_const array. */
13873 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
13877 *dest
++ = val
& 0xff;
13883 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
13885 static HOST_WIDE_INT
13886 extract_int (const unsigned char *src
, unsigned int size
)
13888 HOST_WIDE_INT val
= 0;
13894 val
|= *--src
& 0xff;
13900 /* Writes double_int values to dw_vec_const array. */
13903 insert_double (double_int val
, unsigned char *dest
)
13905 unsigned char *p0
= dest
;
13906 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
13908 if (WORDS_BIG_ENDIAN
)
13914 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
13915 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
13918 /* Writes floating point values to dw_vec_const array. */
13921 insert_float (const_rtx rtl
, unsigned char *array
)
13923 REAL_VALUE_TYPE rv
;
13927 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
13928 real_to_target (val
, &rv
, GET_MODE (rtl
));
13930 /* real_to_target puts 32-bit pieces in each long. Pack them. */
13931 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
13933 insert_int (val
[i
], 4, array
);
13938 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
13939 does not have a "location" either in memory or in a register. These
13940 things can arise in GNU C when a constant is passed as an actual parameter
13941 to an inlined function. They can also arise in C++ where declared
13942 constants do not necessarily get memory "homes". */
13945 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
13947 switch (GET_CODE (rtl
))
13951 HOST_WIDE_INT val
= INTVAL (rtl
);
13954 add_AT_int (die
, DW_AT_const_value
, val
);
13956 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
13961 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
13962 floating-point constant. A CONST_DOUBLE is used whenever the
13963 constant requires more than one word in order to be adequately
13966 enum machine_mode mode
= GET_MODE (rtl
);
13968 if (SCALAR_FLOAT_MODE_P (mode
))
13970 unsigned int length
= GET_MODE_SIZE (mode
);
13971 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
13973 insert_float (rtl
, array
);
13974 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
13977 add_AT_double (die
, DW_AT_const_value
,
13978 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
13984 enum machine_mode mode
= GET_MODE (rtl
);
13985 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
13986 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13987 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
13988 (length
* elt_size
);
13992 switch (GET_MODE_CLASS (mode
))
13994 case MODE_VECTOR_INT
:
13995 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13997 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13998 double_int val
= rtx_to_double_int (elt
);
14000 if (elt_size
<= sizeof (HOST_WIDE_INT
))
14001 insert_int (double_int_to_shwi (val
), elt_size
, p
);
14004 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
14005 insert_double (val
, p
);
14010 case MODE_VECTOR_FLOAT
:
14011 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14013 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14014 insert_float (elt
, p
);
14019 gcc_unreachable ();
14022 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
14027 if (dwarf_version
>= 4 || !dwarf_strict
)
14029 dw_loc_descr_ref loc_result
;
14030 resolve_one_addr (&rtl
, NULL
);
14032 loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
14033 loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
14034 loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
14035 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14036 add_AT_loc (die
, DW_AT_location
, loc_result
);
14037 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
14043 if (CONSTANT_P (XEXP (rtl
, 0)))
14044 return add_const_value_attribute (die
, XEXP (rtl
, 0));
14047 if (!const_ok_for_output (rtl
))
14050 if (dwarf_version
>= 4 || !dwarf_strict
)
14055 /* In cases where an inlined instance of an inline function is passed
14056 the address of an `auto' variable (which is local to the caller) we
14057 can get a situation where the DECL_RTL of the artificial local
14058 variable (for the inlining) which acts as a stand-in for the
14059 corresponding formal parameter (of the inline function) will look
14060 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14061 exactly a compile-time constant expression, but it isn't the address
14062 of the (artificial) local variable either. Rather, it represents the
14063 *value* which the artificial local variable always has during its
14064 lifetime. We currently have no way to represent such quasi-constant
14065 values in Dwarf, so for now we just punt and generate nothing. */
14073 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
14074 && MEM_READONLY_P (rtl
)
14075 && GET_MODE (rtl
) == BLKmode
)
14077 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
14083 /* No other kinds of rtx should be possible here. */
14084 gcc_unreachable ();
14089 /* Determine whether the evaluation of EXPR references any variables
14090 or functions which aren't otherwise used (and therefore may not be
14093 reference_to_unused (tree
* tp
, int * walk_subtrees
,
14094 void * data ATTRIBUTE_UNUSED
)
14096 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
14097 *walk_subtrees
= 0;
14099 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
14100 && ! TREE_ASM_WRITTEN (*tp
))
14102 /* ??? The C++ FE emits debug information for using decls, so
14103 putting gcc_unreachable here falls over. See PR31899. For now
14104 be conservative. */
14105 else if (!cgraph_global_info_ready
14106 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
14108 else if (TREE_CODE (*tp
) == VAR_DECL
)
14110 struct varpool_node
*node
= varpool_get_node (*tp
);
14111 if (!node
|| !node
->analyzed
)
14114 else if (TREE_CODE (*tp
) == FUNCTION_DECL
14115 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
14117 /* The call graph machinery must have finished analyzing,
14118 optimizing and gimplifying the CU by now.
14119 So if *TP has no call graph node associated
14120 to it, it means *TP will not be emitted. */
14121 if (!cgraph_get_node (*tp
))
14124 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
14130 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
14131 for use in a later add_const_value_attribute call. */
14134 rtl_for_decl_init (tree init
, tree type
)
14136 rtx rtl
= NULL_RTX
;
14140 /* If a variable is initialized with a string constant without embedded
14141 zeros, build CONST_STRING. */
14142 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
14144 tree enttype
= TREE_TYPE (type
);
14145 tree domain
= TYPE_DOMAIN (type
);
14146 enum machine_mode mode
= TYPE_MODE (enttype
);
14148 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
14150 && integer_zerop (TYPE_MIN_VALUE (domain
))
14151 && compare_tree_int (TYPE_MAX_VALUE (domain
),
14152 TREE_STRING_LENGTH (init
) - 1) == 0
14153 && ((size_t) TREE_STRING_LENGTH (init
)
14154 == strlen (TREE_STRING_POINTER (init
)) + 1))
14156 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
14157 ggc_strdup (TREE_STRING_POINTER (init
)));
14158 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
14159 MEM_READONLY_P (rtl
) = 1;
14162 /* Other aggregates, and complex values, could be represented using
14164 else if (AGGREGATE_TYPE_P (type
)
14165 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
14166 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
14167 || TREE_CODE (type
) == COMPLEX_TYPE
)
14169 /* Vectors only work if their mode is supported by the target.
14170 FIXME: generic vectors ought to work too. */
14171 else if (TREE_CODE (type
) == VECTOR_TYPE
14172 && !VECTOR_MODE_P (TYPE_MODE (type
)))
14174 /* If the initializer is something that we know will expand into an
14175 immediate RTL constant, expand it now. We must be careful not to
14176 reference variables which won't be output. */
14177 else if (initializer_constant_valid_p (init
, type
)
14178 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
14180 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
14182 if (TREE_CODE (type
) == VECTOR_TYPE
)
14183 switch (TREE_CODE (init
))
14188 if (TREE_CONSTANT (init
))
14190 VEC(constructor_elt
,gc
) *elts
= CONSTRUCTOR_ELTS (init
);
14191 bool constant_p
= true;
14193 unsigned HOST_WIDE_INT ix
;
14195 /* Even when ctor is constant, it might contain non-*_CST
14196 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
14197 belong into VECTOR_CST nodes. */
14198 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
14199 if (!CONSTANT_CLASS_P (value
))
14201 constant_p
= false;
14207 init
= build_vector_from_ctor (type
, elts
);
14217 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
14219 /* If expand_expr returns a MEM, it wasn't immediate. */
14220 gcc_assert (!rtl
|| !MEM_P (rtl
));
14226 /* Generate RTL for the variable DECL to represent its location. */
14229 rtl_for_decl_location (tree decl
)
14233 /* Here we have to decide where we are going to say the parameter "lives"
14234 (as far as the debugger is concerned). We only have a couple of
14235 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
14237 DECL_RTL normally indicates where the parameter lives during most of the
14238 activation of the function. If optimization is enabled however, this
14239 could be either NULL or else a pseudo-reg. Both of those cases indicate
14240 that the parameter doesn't really live anywhere (as far as the code
14241 generation parts of GCC are concerned) during most of the function's
14242 activation. That will happen (for example) if the parameter is never
14243 referenced within the function.
14245 We could just generate a location descriptor here for all non-NULL
14246 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
14247 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
14248 where DECL_RTL is NULL or is a pseudo-reg.
14250 Note however that we can only get away with using DECL_INCOMING_RTL as
14251 a backup substitute for DECL_RTL in certain limited cases. In cases
14252 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
14253 we can be sure that the parameter was passed using the same type as it is
14254 declared to have within the function, and that its DECL_INCOMING_RTL
14255 points us to a place where a value of that type is passed.
14257 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
14258 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
14259 because in these cases DECL_INCOMING_RTL points us to a value of some
14260 type which is *different* from the type of the parameter itself. Thus,
14261 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
14262 such cases, the debugger would end up (for example) trying to fetch a
14263 `float' from a place which actually contains the first part of a
14264 `double'. That would lead to really incorrect and confusing
14265 output at debug-time.
14267 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
14268 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
14269 are a couple of exceptions however. On little-endian machines we can
14270 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
14271 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
14272 an integral type that is smaller than TREE_TYPE (decl). These cases arise
14273 when (on a little-endian machine) a non-prototyped function has a
14274 parameter declared to be of type `short' or `char'. In such cases,
14275 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
14276 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
14277 passed `int' value. If the debugger then uses that address to fetch
14278 a `short' or a `char' (on a little-endian machine) the result will be
14279 the correct data, so we allow for such exceptional cases below.
14281 Note that our goal here is to describe the place where the given formal
14282 parameter lives during most of the function's activation (i.e. between the
14283 end of the prologue and the start of the epilogue). We'll do that as best
14284 as we can. Note however that if the given formal parameter is modified
14285 sometime during the execution of the function, then a stack backtrace (at
14286 debug-time) will show the function as having been called with the *new*
14287 value rather than the value which was originally passed in. This happens
14288 rarely enough that it is not a major problem, but it *is* a problem, and
14289 I'd like to fix it.
14291 A future version of dwarf2out.c may generate two additional attributes for
14292 any given DW_TAG_formal_parameter DIE which will describe the "passed
14293 type" and the "passed location" for the given formal parameter in addition
14294 to the attributes we now generate to indicate the "declared type" and the
14295 "active location" for each parameter. This additional set of attributes
14296 could be used by debuggers for stack backtraces. Separately, note that
14297 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
14298 This happens (for example) for inlined-instances of inline function formal
14299 parameters which are never referenced. This really shouldn't be
14300 happening. All PARM_DECL nodes should get valid non-NULL
14301 DECL_INCOMING_RTL values. FIXME. */
14303 /* Use DECL_RTL as the "location" unless we find something better. */
14304 rtl
= DECL_RTL_IF_SET (decl
);
14306 /* When generating abstract instances, ignore everything except
14307 constants, symbols living in memory, and symbols living in
14308 fixed registers. */
14309 if (! reload_completed
)
14312 && (CONSTANT_P (rtl
)
14314 && CONSTANT_P (XEXP (rtl
, 0)))
14316 && TREE_CODE (decl
) == VAR_DECL
14317 && TREE_STATIC (decl
))))
14319 rtl
= targetm
.delegitimize_address (rtl
);
14324 else if (TREE_CODE (decl
) == PARM_DECL
)
14326 if (rtl
== NULL_RTX
14327 || is_pseudo_reg (rtl
)
14329 && is_pseudo_reg (XEXP (rtl
, 0))
14330 && DECL_INCOMING_RTL (decl
)
14331 && MEM_P (DECL_INCOMING_RTL (decl
))
14332 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
14334 tree declared_type
= TREE_TYPE (decl
);
14335 tree passed_type
= DECL_ARG_TYPE (decl
);
14336 enum machine_mode dmode
= TYPE_MODE (declared_type
);
14337 enum machine_mode pmode
= TYPE_MODE (passed_type
);
14339 /* This decl represents a formal parameter which was optimized out.
14340 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
14341 all cases where (rtl == NULL_RTX) just below. */
14342 if (dmode
== pmode
)
14343 rtl
= DECL_INCOMING_RTL (decl
);
14344 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
14345 && SCALAR_INT_MODE_P (dmode
)
14346 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
14347 && DECL_INCOMING_RTL (decl
))
14349 rtx inc
= DECL_INCOMING_RTL (decl
);
14352 else if (MEM_P (inc
))
14354 if (BYTES_BIG_ENDIAN
)
14355 rtl
= adjust_address_nv (inc
, dmode
,
14356 GET_MODE_SIZE (pmode
)
14357 - GET_MODE_SIZE (dmode
));
14364 /* If the parm was passed in registers, but lives on the stack, then
14365 make a big endian correction if the mode of the type of the
14366 parameter is not the same as the mode of the rtl. */
14367 /* ??? This is the same series of checks that are made in dbxout.c before
14368 we reach the big endian correction code there. It isn't clear if all
14369 of these checks are necessary here, but keeping them all is the safe
14371 else if (MEM_P (rtl
)
14372 && XEXP (rtl
, 0) != const0_rtx
14373 && ! CONSTANT_P (XEXP (rtl
, 0))
14374 /* Not passed in memory. */
14375 && !MEM_P (DECL_INCOMING_RTL (decl
))
14376 /* Not passed by invisible reference. */
14377 && (!REG_P (XEXP (rtl
, 0))
14378 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
14379 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
14380 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
14381 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
14384 /* Big endian correction check. */
14385 && BYTES_BIG_ENDIAN
14386 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
14387 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
14390 enum machine_mode addr_mode
= get_address_mode (rtl
);
14391 int offset
= (UNITS_PER_WORD
14392 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
14394 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
14395 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
14398 else if (TREE_CODE (decl
) == VAR_DECL
14401 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
14402 && BYTES_BIG_ENDIAN
)
14404 enum machine_mode addr_mode
= get_address_mode (rtl
);
14405 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
14406 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
14408 /* If a variable is declared "register" yet is smaller than
14409 a register, then if we store the variable to memory, it
14410 looks like we're storing a register-sized value, when in
14411 fact we are not. We need to adjust the offset of the
14412 storage location to reflect the actual value's bytes,
14413 else gdb will not be able to display it. */
14415 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
14416 plus_constant (addr_mode
, XEXP (rtl
, 0),
14420 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
14421 and will have been substituted directly into all expressions that use it.
14422 C does not have such a concept, but C++ and other languages do. */
14423 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
14424 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
14427 rtl
= targetm
.delegitimize_address (rtl
);
14429 /* If we don't look past the constant pool, we risk emitting a
14430 reference to a constant pool entry that isn't referenced from
14431 code, and thus is not emitted. */
14433 rtl
= avoid_constant_pool_reference (rtl
);
14435 /* Try harder to get a rtl. If this symbol ends up not being emitted
14436 in the current CU, resolve_addr will remove the expression referencing
14438 if (rtl
== NULL_RTX
14439 && TREE_CODE (decl
) == VAR_DECL
14440 && !DECL_EXTERNAL (decl
)
14441 && TREE_STATIC (decl
)
14442 && DECL_NAME (decl
)
14443 && !DECL_HARD_REGISTER (decl
)
14444 && DECL_MODE (decl
) != VOIDmode
)
14446 rtl
= make_decl_rtl_for_debug (decl
);
14448 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
14449 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
14456 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
14457 returned. If so, the decl for the COMMON block is returned, and the
14458 value is the offset into the common block for the symbol. */
14461 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
14463 tree val_expr
, cvar
;
14464 enum machine_mode mode
;
14465 HOST_WIDE_INT bitsize
, bitpos
;
14467 int unsignedp
, volatilep
= 0;
14469 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
14470 it does not have a value (the offset into the common area), or if it
14471 is thread local (as opposed to global) then it isn't common, and shouldn't
14472 be handled as such. */
14473 if (TREE_CODE (decl
) != VAR_DECL
14474 || !TREE_STATIC (decl
)
14475 || !DECL_HAS_VALUE_EXPR_P (decl
)
14479 val_expr
= DECL_VALUE_EXPR (decl
);
14480 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
14483 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
14484 &mode
, &unsignedp
, &volatilep
, true);
14486 if (cvar
== NULL_TREE
14487 || TREE_CODE (cvar
) != VAR_DECL
14488 || DECL_ARTIFICIAL (cvar
)
14489 || !TREE_PUBLIC (cvar
))
14493 if (offset
!= NULL
)
14495 if (!host_integerp (offset
, 0))
14497 *value
= tree_low_cst (offset
, 0);
14500 *value
+= bitpos
/ BITS_PER_UNIT
;
14505 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
14506 data attribute for a variable or a parameter. We generate the
14507 DW_AT_const_value attribute only in those cases where the given variable
14508 or parameter does not have a true "location" either in memory or in a
14509 register. This can happen (for example) when a constant is passed as an
14510 actual argument in a call to an inline function. (It's possible that
14511 these things can crop up in other ways also.) Note that one type of
14512 constant value which can be passed into an inlined function is a constant
14513 pointer. This can happen for example if an actual argument in an inlined
14514 function call evaluates to a compile-time constant address.
14516 CACHE_P is true if it is worth caching the location list for DECL,
14517 so that future calls can reuse it rather than regenerate it from scratch.
14518 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
14519 since we will need to refer to them each time the function is inlined. */
14522 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
14523 enum dwarf_attribute attr
)
14526 dw_loc_list_ref list
;
14527 var_loc_list
*loc_list
;
14528 cached_dw_loc_list
*cache
;
14531 if (TREE_CODE (decl
) == ERROR_MARK
)
14534 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
14535 || TREE_CODE (decl
) == RESULT_DECL
);
14537 /* Try to get some constant RTL for this decl, and use that as the value of
14540 rtl
= rtl_for_decl_location (decl
);
14541 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
14542 && add_const_value_attribute (die
, rtl
))
14545 /* See if we have single element location list that is equivalent to
14546 a constant value. That way we are better to use add_const_value_attribute
14547 rather than expanding constant value equivalent. */
14548 loc_list
= lookup_decl_loc (decl
);
14551 && loc_list
->first
->next
== NULL
14552 && NOTE_P (loc_list
->first
->loc
)
14553 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
14554 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
14556 struct var_loc_node
*node
;
14558 node
= loc_list
->first
;
14559 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
14560 if (GET_CODE (rtl
) == EXPR_LIST
)
14561 rtl
= XEXP (rtl
, 0);
14562 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
14563 && add_const_value_attribute (die
, rtl
))
14566 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
14567 list several times. See if we've already cached the contents. */
14569 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
14573 cache
= (cached_dw_loc_list
*)
14574 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
14576 list
= cache
->loc_list
;
14580 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
14581 /* It is usually worth caching this result if the decl is from
14582 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
14583 if (cache_p
&& list
&& list
->dw_loc_next
)
14585 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
14586 DECL_UID (decl
), INSERT
);
14587 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
14588 cache
->decl_id
= DECL_UID (decl
);
14589 cache
->loc_list
= list
;
14595 add_AT_location_description (die
, attr
, list
);
14598 /* None of that worked, so it must not really have a location;
14599 try adding a constant value attribute from the DECL_INITIAL. */
14600 return tree_add_const_value_attribute_for_decl (die
, decl
);
14603 /* Add VARIABLE and DIE into deferred locations list. */
14606 defer_location (tree variable
, dw_die_ref die
)
14608 deferred_locations entry
;
14609 entry
.variable
= variable
;
14611 VEC_safe_push (deferred_locations
, gc
, deferred_locations_list
, &entry
);
14614 /* Helper function for tree_add_const_value_attribute. Natively encode
14615 initializer INIT into an array. Return true if successful. */
14618 native_encode_initializer (tree init
, unsigned char *array
, int size
)
14622 if (init
== NULL_TREE
)
14626 switch (TREE_CODE (init
))
14629 type
= TREE_TYPE (init
);
14630 if (TREE_CODE (type
) == ARRAY_TYPE
)
14632 tree enttype
= TREE_TYPE (type
);
14633 enum machine_mode mode
= TYPE_MODE (enttype
);
14635 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
14637 if (int_size_in_bytes (type
) != size
)
14639 if (size
> TREE_STRING_LENGTH (init
))
14641 memcpy (array
, TREE_STRING_POINTER (init
),
14642 TREE_STRING_LENGTH (init
));
14643 memset (array
+ TREE_STRING_LENGTH (init
),
14644 '\0', size
- TREE_STRING_LENGTH (init
));
14647 memcpy (array
, TREE_STRING_POINTER (init
), size
);
14652 type
= TREE_TYPE (init
);
14653 if (int_size_in_bytes (type
) != size
)
14655 if (TREE_CODE (type
) == ARRAY_TYPE
)
14657 HOST_WIDE_INT min_index
;
14658 unsigned HOST_WIDE_INT cnt
;
14659 int curpos
= 0, fieldsize
;
14660 constructor_elt
*ce
;
14662 if (TYPE_DOMAIN (type
) == NULL_TREE
14663 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
14666 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
14667 if (fieldsize
<= 0)
14670 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
14671 memset (array
, '\0', size
);
14672 FOR_EACH_VEC_ELT (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
)
14674 tree val
= ce
->value
;
14675 tree index
= ce
->index
;
14677 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
14678 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
14681 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
14686 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
14689 curpos
= pos
+ fieldsize
;
14690 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
14692 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
14693 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
14694 while (count
-- > 0)
14697 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
14698 curpos
+= fieldsize
;
14701 gcc_assert (curpos
<= size
);
14705 else if (TREE_CODE (type
) == RECORD_TYPE
14706 || TREE_CODE (type
) == UNION_TYPE
)
14708 tree field
= NULL_TREE
;
14709 unsigned HOST_WIDE_INT cnt
;
14710 constructor_elt
*ce
;
14712 if (int_size_in_bytes (type
) != size
)
14715 if (TREE_CODE (type
) == RECORD_TYPE
)
14716 field
= TYPE_FIELDS (type
);
14718 FOR_EACH_VEC_ELT (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
)
14720 tree val
= ce
->value
;
14721 int pos
, fieldsize
;
14723 if (ce
->index
!= 0)
14729 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
14732 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
14733 && TYPE_DOMAIN (TREE_TYPE (field
))
14734 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
14736 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
14737 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
14739 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
14740 pos
= int_byte_position (field
);
14741 gcc_assert (pos
+ fieldsize
<= size
);
14743 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
14749 case VIEW_CONVERT_EXPR
:
14750 case NON_LVALUE_EXPR
:
14751 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
14753 return native_encode_expr (init
, array
, size
) == size
;
14757 /* Attach a DW_AT_const_value attribute to DIE. The value of the
14758 attribute is the const value T. */
14761 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
14764 tree type
= TREE_TYPE (t
);
14767 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
14771 gcc_assert (!DECL_P (init
));
14773 rtl
= rtl_for_decl_init (init
, type
);
14775 return add_const_value_attribute (die
, rtl
);
14776 /* If the host and target are sane, try harder. */
14777 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
14778 && initializer_constant_valid_p (init
, type
))
14780 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
14781 if (size
> 0 && (int) size
== size
)
14783 unsigned char *array
= (unsigned char *)
14784 ggc_alloc_cleared_atomic (size
);
14786 if (native_encode_initializer (init
, array
, size
))
14788 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
14796 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
14797 attribute is the const value of T, where T is an integral constant
14798 variable with static storage duration
14799 (so it can't be a PARM_DECL or a RESULT_DECL). */
14802 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
14806 || (TREE_CODE (decl
) != VAR_DECL
14807 && TREE_CODE (decl
) != CONST_DECL
)
14808 || (TREE_CODE (decl
) == VAR_DECL
14809 && !TREE_STATIC (decl
)))
14812 if (TREE_READONLY (decl
)
14813 && ! TREE_THIS_VOLATILE (decl
)
14814 && DECL_INITIAL (decl
))
14819 /* Don't add DW_AT_const_value if abstract origin already has one. */
14820 if (get_AT (var_die
, DW_AT_const_value
))
14823 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
14826 /* Convert the CFI instructions for the current function into a
14827 location list. This is used for DW_AT_frame_base when we targeting
14828 a dwarf2 consumer that does not support the dwarf3
14829 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
14832 static dw_loc_list_ref
14833 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
14837 dw_loc_list_ref list
, *list_tail
;
14839 dw_cfa_location last_cfa
, next_cfa
;
14840 const char *start_label
, *last_label
, *section
;
14841 dw_cfa_location remember
;
14844 gcc_assert (fde
!= NULL
);
14846 section
= secname_for_decl (current_function_decl
);
14850 memset (&next_cfa
, 0, sizeof (next_cfa
));
14851 next_cfa
.reg
= INVALID_REGNUM
;
14852 remember
= next_cfa
;
14854 start_label
= fde
->dw_fde_begin
;
14856 /* ??? Bald assumption that the CIE opcode list does not contain
14857 advance opcodes. */
14858 FOR_EACH_VEC_ELT (dw_cfi_ref
, cie_cfi_vec
, ix
, cfi
)
14859 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
14861 last_cfa
= next_cfa
;
14862 last_label
= start_label
;
14864 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
14866 /* If the first partition contained no CFI adjustments, the
14867 CIE opcodes apply to the whole first partition. */
14868 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
14869 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
14870 list_tail
=&(*list_tail
)->dw_loc_next
;
14871 start_label
= last_label
= fde
->dw_fde_second_begin
;
14874 FOR_EACH_VEC_ELT (dw_cfi_ref
, fde
->dw_fde_cfi
, ix
, cfi
)
14876 switch (cfi
->dw_cfi_opc
)
14878 case DW_CFA_set_loc
:
14879 case DW_CFA_advance_loc1
:
14880 case DW_CFA_advance_loc2
:
14881 case DW_CFA_advance_loc4
:
14882 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
14884 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
14885 start_label
, last_label
, section
);
14887 list_tail
= &(*list_tail
)->dw_loc_next
;
14888 last_cfa
= next_cfa
;
14889 start_label
= last_label
;
14891 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
14894 case DW_CFA_advance_loc
:
14895 /* The encoding is complex enough that we should never emit this. */
14896 gcc_unreachable ();
14899 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
14902 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
14904 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
14906 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
14907 start_label
, last_label
, section
);
14909 list_tail
= &(*list_tail
)->dw_loc_next
;
14910 last_cfa
= next_cfa
;
14911 start_label
= last_label
;
14913 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
14914 start_label
, fde
->dw_fde_end
, section
);
14915 list_tail
= &(*list_tail
)->dw_loc_next
;
14916 start_label
= last_label
= fde
->dw_fde_second_begin
;
14920 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
14922 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
14923 start_label
, last_label
, section
);
14924 list_tail
= &(*list_tail
)->dw_loc_next
;
14925 start_label
= last_label
;
14928 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
14930 fde
->dw_fde_second_begin
14931 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
14934 if (list
&& list
->dw_loc_next
)
14940 /* Compute a displacement from the "steady-state frame pointer" to the
14941 frame base (often the same as the CFA), and store it in
14942 frame_pointer_fb_offset. OFFSET is added to the displacement
14943 before the latter is negated. */
14946 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
14950 #ifdef FRAME_POINTER_CFA_OFFSET
14951 reg
= frame_pointer_rtx
;
14952 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
14954 reg
= arg_pointer_rtx
;
14955 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
14958 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
14959 if (GET_CODE (elim
) == PLUS
)
14961 offset
+= INTVAL (XEXP (elim
, 1));
14962 elim
= XEXP (elim
, 0);
14965 frame_pointer_fb_offset
= -offset
;
14967 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
14968 in which to eliminate. This is because it's stack pointer isn't
14969 directly accessible as a register within the ISA. To work around
14970 this, assume that while we cannot provide a proper value for
14971 frame_pointer_fb_offset, we won't need one either. */
14972 frame_pointer_fb_offset_valid
14973 = ((SUPPORTS_STACK_ALIGNMENT
14974 && (elim
== hard_frame_pointer_rtx
14975 || elim
== stack_pointer_rtx
))
14976 || elim
== (frame_pointer_needed
14977 ? hard_frame_pointer_rtx
14978 : stack_pointer_rtx
));
14981 /* Generate a DW_AT_name attribute given some string value to be included as
14982 the value of the attribute. */
14985 add_name_attribute (dw_die_ref die
, const char *name_string
)
14987 if (name_string
!= NULL
&& *name_string
!= 0)
14989 if (demangle_name_func
)
14990 name_string
= (*demangle_name_func
) (name_string
);
14992 add_AT_string (die
, DW_AT_name
, name_string
);
14996 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
14997 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
14998 of TYPE accordingly.
15000 ??? This is a temporary measure until after we're able to generate
15001 regular DWARF for the complex Ada type system. */
15004 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
15005 dw_die_ref context_die
)
15008 dw_die_ref dtype_die
;
15010 if (!lang_hooks
.types
.descriptive_type
)
15013 dtype
= lang_hooks
.types
.descriptive_type (type
);
15017 dtype_die
= lookup_type_die (dtype
);
15020 gen_type_die (dtype
, context_die
);
15021 dtype_die
= lookup_type_die (dtype
);
15022 gcc_assert (dtype_die
);
15025 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
15028 /* Generate a DW_AT_comp_dir attribute for DIE. */
15031 add_comp_dir_attribute (dw_die_ref die
)
15033 const char *wd
= get_src_pwd ();
15039 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
15043 wdlen
= strlen (wd
);
15044 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
15046 wd1
[wdlen
] = DIR_SEPARATOR
;
15047 wd1
[wdlen
+ 1] = 0;
15051 add_AT_string (die
, DW_AT_comp_dir
, remap_debug_filename (wd
));
15054 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
15058 lower_bound_default (void)
15060 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
15065 case DW_LANG_C_plus_plus
:
15067 case DW_LANG_ObjC_plus_plus
:
15070 case DW_LANG_Fortran77
:
15071 case DW_LANG_Fortran90
:
15072 case DW_LANG_Fortran95
:
15076 case DW_LANG_Python
:
15077 return dwarf_version
>= 4 ? 0 : -1;
15078 case DW_LANG_Ada95
:
15079 case DW_LANG_Ada83
:
15080 case DW_LANG_Cobol74
:
15081 case DW_LANG_Cobol85
:
15082 case DW_LANG_Pascal83
:
15083 case DW_LANG_Modula2
:
15085 return dwarf_version
>= 4 ? 1 : -1;
15091 /* Given a tree node describing an array bound (either lower or upper) output
15092 a representation for that bound. */
15095 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
15097 switch (TREE_CODE (bound
))
15102 /* All fixed-bounds are represented by INTEGER_CST nodes. */
15105 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
15108 /* Use the default if possible. */
15109 if (bound_attr
== DW_AT_lower_bound
15110 && host_integerp (bound
, 0)
15111 && (dflt
= lower_bound_default ()) != -1
15112 && tree_low_cst (bound
, 0) == dflt
)
15115 /* Otherwise represent the bound as an unsigned value with the
15116 precision of its type. The precision and signedness of the
15117 type will be necessary to re-interpret it unambiguously. */
15118 else if (prec
< HOST_BITS_PER_WIDE_INT
)
15120 unsigned HOST_WIDE_INT mask
15121 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
15122 add_AT_unsigned (subrange_die
, bound_attr
,
15123 TREE_INT_CST_LOW (bound
) & mask
);
15125 else if (prec
== HOST_BITS_PER_WIDE_INT
15126 || TREE_INT_CST_HIGH (bound
) == 0)
15127 add_AT_unsigned (subrange_die
, bound_attr
,
15128 TREE_INT_CST_LOW (bound
));
15130 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
15131 TREE_INT_CST_LOW (bound
));
15136 case VIEW_CONVERT_EXPR
:
15137 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
15147 dw_die_ref decl_die
= lookup_decl_die (bound
);
15149 /* ??? Can this happen, or should the variable have been bound
15150 first? Probably it can, since I imagine that we try to create
15151 the types of parameters in the order in which they exist in
15152 the list, and won't have created a forward reference to a
15153 later parameter. */
15154 if (decl_die
!= NULL
)
15156 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
15164 /* Otherwise try to create a stack operation procedure to
15165 evaluate the value of the array bound. */
15167 dw_die_ref ctx
, decl_die
;
15168 dw_loc_list_ref list
;
15170 list
= loc_list_from_tree (bound
, 2);
15171 if (list
== NULL
|| single_element_loc_list_p (list
))
15173 /* If DW_AT_*bound is not a reference nor constant, it is
15174 a DWARF expression rather than location description.
15175 For that loc_list_from_tree (bound, 0) is needed.
15176 If that fails to give a single element list,
15177 fall back to outputting this as a reference anyway. */
15178 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
15179 if (list2
&& single_element_loc_list_p (list2
))
15181 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
15188 if (current_function_decl
== 0)
15189 ctx
= comp_unit_die ();
15191 ctx
= lookup_decl_die (current_function_decl
);
15193 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
15194 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
15195 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
15196 add_AT_location_description (decl_die
, DW_AT_location
, list
);
15197 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
15203 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
15204 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
15205 Note that the block of subscript information for an array type also
15206 includes information about the element type of the given array type. */
15209 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
15211 unsigned dimension_number
;
15213 dw_die_ref subrange_die
;
15215 for (dimension_number
= 0;
15216 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
15217 type
= TREE_TYPE (type
), dimension_number
++)
15219 tree domain
= TYPE_DOMAIN (type
);
15221 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
15224 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
15225 and (in GNU C only) variable bounds. Handle all three forms
15227 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
15230 /* We have an array type with specified bounds. */
15231 lower
= TYPE_MIN_VALUE (domain
);
15232 upper
= TYPE_MAX_VALUE (domain
);
15234 /* Define the index type. */
15235 if (TREE_TYPE (domain
))
15237 /* ??? This is probably an Ada unnamed subrange type. Ignore the
15238 TREE_TYPE field. We can't emit debug info for this
15239 because it is an unnamed integral type. */
15240 if (TREE_CODE (domain
) == INTEGER_TYPE
15241 && TYPE_NAME (domain
) == NULL_TREE
15242 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
15243 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
15246 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
15250 /* ??? If upper is NULL, the array has unspecified length,
15251 but it does have a lower bound. This happens with Fortran
15253 Since the debugger is definitely going to need to know N
15254 to produce useful results, go ahead and output the lower
15255 bound solo, and hope the debugger can cope. */
15257 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
15259 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
15262 /* Otherwise we have an array type with an unspecified length. The
15263 DWARF-2 spec does not say how to handle this; let's just leave out the
15269 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
15271 dw_die_ref decl_die
;
15274 switch (TREE_CODE (tree_node
))
15279 case ENUMERAL_TYPE
:
15282 case QUAL_UNION_TYPE
:
15283 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
15284 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
15286 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
15289 size
= int_size_in_bytes (tree_node
);
15292 /* For a data member of a struct or union, the DW_AT_byte_size is
15293 generally given as the number of bytes normally allocated for an
15294 object of the *declared* type of the member itself. This is true
15295 even for bit-fields. */
15296 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
15299 gcc_unreachable ();
15302 /* Note that `size' might be -1 when we get to this point. If it is, that
15303 indicates that the byte size of the entity in question is variable. We
15304 have no good way of expressing this fact in Dwarf at the present time,
15305 so just let the -1 pass on through. */
15306 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
15309 /* For a FIELD_DECL node which represents a bit-field, output an attribute
15310 which specifies the distance in bits from the highest order bit of the
15311 "containing object" for the bit-field to the highest order bit of the
15314 For any given bit-field, the "containing object" is a hypothetical object
15315 (of some integral or enum type) within which the given bit-field lives. The
15316 type of this hypothetical "containing object" is always the same as the
15317 declared type of the individual bit-field itself. The determination of the
15318 exact location of the "containing object" for a bit-field is rather
15319 complicated. It's handled by the `field_byte_offset' function (above).
15321 Note that it is the size (in bytes) of the hypothetical "containing object"
15322 which will be given in the DW_AT_byte_size attribute for this bit-field.
15323 (See `byte_size_attribute' above). */
15326 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
15328 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
15329 tree type
= DECL_BIT_FIELD_TYPE (decl
);
15330 HOST_WIDE_INT bitpos_int
;
15331 HOST_WIDE_INT highest_order_object_bit_offset
;
15332 HOST_WIDE_INT highest_order_field_bit_offset
;
15333 HOST_WIDE_INT bit_offset
;
15335 /* Must be a field and a bit field. */
15336 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
15338 /* We can't yet handle bit-fields whose offsets are variable, so if we
15339 encounter such things, just return without generating any attribute
15340 whatsoever. Likewise for variable or too large size. */
15341 if (! host_integerp (bit_position (decl
), 0)
15342 || ! host_integerp (DECL_SIZE (decl
), 1))
15345 bitpos_int
= int_bit_position (decl
);
15347 /* Note that the bit offset is always the distance (in bits) from the
15348 highest-order bit of the "containing object" to the highest-order bit of
15349 the bit-field itself. Since the "high-order end" of any object or field
15350 is different on big-endian and little-endian machines, the computation
15351 below must take account of these differences. */
15352 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
15353 highest_order_field_bit_offset
= bitpos_int
;
15355 if (! BYTES_BIG_ENDIAN
)
15357 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
15358 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
15362 = (! BYTES_BIG_ENDIAN
15363 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
15364 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
15366 if (bit_offset
< 0)
15367 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
15369 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
15372 /* For a FIELD_DECL node which represents a bit field, output an attribute
15373 which specifies the length in bits of the given field. */
15376 add_bit_size_attribute (dw_die_ref die
, tree decl
)
15378 /* Must be a field and a bit field. */
15379 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
15380 && DECL_BIT_FIELD_TYPE (decl
));
15382 if (host_integerp (DECL_SIZE (decl
), 1))
15383 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
15386 /* If the compiled language is ANSI C, then add a 'prototyped'
15387 attribute, if arg types are given for the parameters of a function. */
15390 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
15392 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
15393 && prototype_p (func_type
))
15394 add_AT_flag (die
, DW_AT_prototyped
, 1);
15397 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
15398 by looking in either the type declaration or object declaration
15401 static inline dw_die_ref
15402 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
15404 dw_die_ref origin_die
= NULL
;
15406 if (TREE_CODE (origin
) != FUNCTION_DECL
)
15408 /* We may have gotten separated from the block for the inlined
15409 function, if we're in an exception handler or some such; make
15410 sure that the abstract function has been written out.
15412 Doing this for nested functions is wrong, however; functions are
15413 distinct units, and our context might not even be inline. */
15417 fn
= TYPE_STUB_DECL (fn
);
15419 fn
= decl_function_context (fn
);
15421 dwarf2out_abstract_function (fn
);
15424 if (DECL_P (origin
))
15425 origin_die
= lookup_decl_die (origin
);
15426 else if (TYPE_P (origin
))
15427 origin_die
= lookup_type_die (origin
);
15429 /* XXX: Functions that are never lowered don't always have correct block
15430 trees (in the case of java, they simply have no block tree, in some other
15431 languages). For these functions, there is nothing we can really do to
15432 output correct debug info for inlined functions in all cases. Rather
15433 than die, we'll just produce deficient debug info now, in that we will
15434 have variables without a proper abstract origin. In the future, when all
15435 functions are lowered, we should re-add a gcc_assert (origin_die)
15439 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
15443 /* We do not currently support the pure_virtual attribute. */
15446 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
15448 if (DECL_VINDEX (func_decl
))
15450 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
15452 if (host_integerp (DECL_VINDEX (func_decl
), 0))
15453 add_AT_loc (die
, DW_AT_vtable_elem_location
,
15454 new_loc_descr (DW_OP_constu
,
15455 tree_low_cst (DECL_VINDEX (func_decl
), 0),
15458 /* GNU extension: Record what type this method came from originally. */
15459 if (debug_info_level
> DINFO_LEVEL_TERSE
15460 && DECL_CONTEXT (func_decl
))
15461 add_AT_die_ref (die
, DW_AT_containing_type
,
15462 lookup_type_die (DECL_CONTEXT (func_decl
)));
15466 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
15467 given decl. This used to be a vendor extension until after DWARF 4
15468 standardized it. */
15471 add_linkage_attr (dw_die_ref die
, tree decl
)
15473 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
15475 /* Mimic what assemble_name_raw does with a leading '*'. */
15476 if (name
[0] == '*')
15479 if (dwarf_version
>= 4)
15480 add_AT_string (die
, DW_AT_linkage_name
, name
);
15482 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
15485 /* Add source coordinate attributes for the given decl. */
15488 add_src_coords_attributes (dw_die_ref die
, tree decl
)
15490 expanded_location s
;
15492 if (DECL_SOURCE_LOCATION (decl
) == UNKNOWN_LOCATION
)
15494 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
15495 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
15496 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
15499 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
15502 add_linkage_name (dw_die_ref die
, tree decl
)
15504 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
15505 && TREE_PUBLIC (decl
)
15506 && !DECL_ABSTRACT (decl
)
15507 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
15508 && die
->die_tag
!= DW_TAG_member
)
15510 /* Defer until we have an assembler name set. */
15511 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
15513 limbo_die_node
*asm_name
;
15515 asm_name
= ggc_alloc_cleared_limbo_die_node ();
15516 asm_name
->die
= die
;
15517 asm_name
->created_for
= decl
;
15518 asm_name
->next
= deferred_asm_name
;
15519 deferred_asm_name
= asm_name
;
15521 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
15522 add_linkage_attr (die
, decl
);
15526 /* Add a DW_AT_name attribute and source coordinate attribute for the
15527 given decl, but only if it actually has a name. */
15530 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
15534 decl_name
= DECL_NAME (decl
);
15535 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
15537 const char *name
= dwarf2_name (decl
, 0);
15539 add_name_attribute (die
, name
);
15540 if (! DECL_ARTIFICIAL (decl
))
15541 add_src_coords_attributes (die
, decl
);
15543 add_linkage_name (die
, decl
);
15546 #ifdef VMS_DEBUGGING_INFO
15547 /* Get the function's name, as described by its RTL. This may be different
15548 from the DECL_NAME name used in the source file. */
15549 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
15551 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
15552 XEXP (DECL_RTL (decl
), 0));
15553 VEC_safe_push (rtx
, gc
, used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
15555 #endif /* VMS_DEBUGGING_INFO */
15558 #ifdef VMS_DEBUGGING_INFO
15559 /* Output the debug main pointer die for VMS */
15562 dwarf2out_vms_debug_main_pointer (void)
15564 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
15567 /* Allocate the VMS debug main subprogram die. */
15568 die
= ggc_alloc_cleared_die_node ();
15569 die
->die_tag
= DW_TAG_subprogram
;
15570 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
15571 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
15572 current_function_funcdef_no
);
15573 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
15575 /* Make it the first child of comp_unit_die (). */
15576 die
->die_parent
= comp_unit_die ();
15577 if (comp_unit_die ()->die_child
)
15579 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
15580 comp_unit_die ()->die_child
->die_sib
= die
;
15584 die
->die_sib
= die
;
15585 comp_unit_die ()->die_child
= die
;
15588 #endif /* VMS_DEBUGGING_INFO */
15590 /* Push a new declaration scope. */
15593 push_decl_scope (tree scope
)
15595 VEC_safe_push (tree
, gc
, decl_scope_table
, scope
);
15598 /* Pop a declaration scope. */
15601 pop_decl_scope (void)
15603 VEC_pop (tree
, decl_scope_table
);
15606 /* walk_tree helper function for uses_local_type, below. */
15609 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
15612 *walk_subtrees
= 0;
15615 tree name
= TYPE_NAME (*tp
);
15616 if (name
&& DECL_P (name
) && decl_function_context (name
))
15622 /* If TYPE involves a function-local type (including a local typedef to a
15623 non-local type), returns that type; otherwise returns NULL_TREE. */
15626 uses_local_type (tree type
)
15628 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
15632 /* Return the DIE for the scope that immediately contains this type.
15633 Non-named types that do not involve a function-local type get global
15634 scope. Named types nested in namespaces or other types get their
15635 containing scope. All other types (i.e. function-local named types) get
15636 the current active scope. */
15639 scope_die_for (tree t
, dw_die_ref context_die
)
15641 dw_die_ref scope_die
= NULL
;
15642 tree containing_scope
;
15644 /* Non-types always go in the current scope. */
15645 gcc_assert (TYPE_P (t
));
15647 /* Use the scope of the typedef, rather than the scope of the type
15649 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
15650 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
15652 containing_scope
= TYPE_CONTEXT (t
);
15654 /* Use the containing namespace if there is one. */
15655 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
15657 if (context_die
== lookup_decl_die (containing_scope
))
15659 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
15660 context_die
= get_context_die (containing_scope
);
15662 containing_scope
= NULL_TREE
;
15665 /* Ignore function type "scopes" from the C frontend. They mean that
15666 a tagged type is local to a parmlist of a function declarator, but
15667 that isn't useful to DWARF. */
15668 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
15669 containing_scope
= NULL_TREE
;
15671 if (SCOPE_FILE_SCOPE_P (containing_scope
))
15673 /* If T uses a local type keep it local as well, to avoid references
15674 to function-local DIEs from outside the function. */
15675 if (current_function_decl
&& uses_local_type (t
))
15676 scope_die
= context_die
;
15678 scope_die
= comp_unit_die ();
15680 else if (TYPE_P (containing_scope
))
15682 /* For types, we can just look up the appropriate DIE. */
15683 if (debug_info_level
> DINFO_LEVEL_TERSE
)
15684 scope_die
= get_context_die (containing_scope
);
15687 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
15688 if (scope_die
== NULL
)
15689 scope_die
= comp_unit_die ();
15693 scope_die
= context_die
;
15698 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
15701 local_scope_p (dw_die_ref context_die
)
15703 for (; context_die
; context_die
= context_die
->die_parent
)
15704 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
15705 || context_die
->die_tag
== DW_TAG_subprogram
)
15711 /* Returns nonzero if CONTEXT_DIE is a class. */
15714 class_scope_p (dw_die_ref context_die
)
15716 return (context_die
15717 && (context_die
->die_tag
== DW_TAG_structure_type
15718 || context_die
->die_tag
== DW_TAG_class_type
15719 || context_die
->die_tag
== DW_TAG_interface_type
15720 || context_die
->die_tag
== DW_TAG_union_type
));
15723 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
15724 whether or not to treat a DIE in this context as a declaration. */
15727 class_or_namespace_scope_p (dw_die_ref context_die
)
15729 return (class_scope_p (context_die
)
15730 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
15733 /* Many forms of DIEs require a "type description" attribute. This
15734 routine locates the proper "type descriptor" die for the type given
15735 by 'type', and adds a DW_AT_type attribute below the given die. */
15738 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
15739 int decl_volatile
, dw_die_ref context_die
)
15741 enum tree_code code
= TREE_CODE (type
);
15742 dw_die_ref type_die
= NULL
;
15744 /* ??? If this type is an unnamed subrange type of an integral, floating-point
15745 or fixed-point type, use the inner type. This is because we have no
15746 support for unnamed types in base_type_die. This can happen if this is
15747 an Ada subrange type. Correct solution is emit a subrange type die. */
15748 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
15749 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
15750 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
15752 if (code
== ERROR_MARK
15753 /* Handle a special case. For functions whose return type is void, we
15754 generate *no* type attribute. (Note that no object may have type
15755 `void', so this only applies to function return types). */
15756 || code
== VOID_TYPE
)
15759 type_die
= modified_type_die (type
,
15760 decl_const
|| TYPE_READONLY (type
),
15761 decl_volatile
|| TYPE_VOLATILE (type
),
15764 if (type_die
!= NULL
)
15765 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
15768 /* Given an object die, add the calling convention attribute for the
15769 function call type. */
15771 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
15773 enum dwarf_calling_convention value
= DW_CC_normal
;
15775 value
= ((enum dwarf_calling_convention
)
15776 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
15779 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
15781 /* DWARF 2 doesn't provide a way to identify a program's source-level
15782 entry point. DW_AT_calling_convention attributes are only meant
15783 to describe functions' calling conventions. However, lacking a
15784 better way to signal the Fortran main program, we used this for
15785 a long time, following existing custom. Now, DWARF 4 has
15786 DW_AT_main_subprogram, which we add below, but some tools still
15787 rely on the old way, which we thus keep. */
15788 value
= DW_CC_program
;
15790 if (dwarf_version
>= 4 || !dwarf_strict
)
15791 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
15794 /* Only add the attribute if the backend requests it, and
15795 is not DW_CC_normal. */
15796 if (value
&& (value
!= DW_CC_normal
))
15797 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
15800 /* Given a tree pointer to a struct, class, union, or enum type node, return
15801 a pointer to the (string) tag name for the given type, or zero if the type
15802 was declared without a tag. */
15804 static const char *
15805 type_tag (const_tree type
)
15807 const char *name
= 0;
15809 if (TYPE_NAME (type
) != 0)
15813 /* Find the IDENTIFIER_NODE for the type name. */
15814 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
15815 && !TYPE_NAMELESS (type
))
15816 t
= TYPE_NAME (type
);
15818 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
15819 a TYPE_DECL node, regardless of whether or not a `typedef' was
15821 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
15822 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
15824 /* We want to be extra verbose. Don't call dwarf_name if
15825 DECL_NAME isn't set. The default hook for decl_printable_name
15826 doesn't like that, and in this context it's correct to return
15827 0, instead of "<anonymous>" or the like. */
15828 if (DECL_NAME (TYPE_NAME (type
))
15829 && !DECL_NAMELESS (TYPE_NAME (type
)))
15830 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
15833 /* Now get the name as a string, or invent one. */
15834 if (!name
&& t
!= 0)
15835 name
= IDENTIFIER_POINTER (t
);
15838 return (name
== 0 || *name
== '\0') ? 0 : name
;
15841 /* Return the type associated with a data member, make a special check
15842 for bit field types. */
15845 member_declared_type (const_tree member
)
15847 return (DECL_BIT_FIELD_TYPE (member
)
15848 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
15851 /* Get the decl's label, as described by its RTL. This may be different
15852 from the DECL_NAME name used in the source file. */
15855 static const char *
15856 decl_start_label (tree decl
)
15859 const char *fnname
;
15861 x
= DECL_RTL (decl
);
15862 gcc_assert (MEM_P (x
));
15865 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
15867 fnname
= XSTR (x
, 0);
15872 /* These routines generate the internal representation of the DIE's for
15873 the compilation unit. Debugging information is collected by walking
15874 the declaration trees passed in from dwarf2out_decl(). */
15877 gen_array_type_die (tree type
, dw_die_ref context_die
)
15879 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
15880 dw_die_ref array_die
;
15882 /* GNU compilers represent multidimensional array types as sequences of one
15883 dimensional array types whose element types are themselves array types.
15884 We sometimes squish that down to a single array_type DIE with multiple
15885 subscripts in the Dwarf debugging info. The draft Dwarf specification
15886 say that we are allowed to do this kind of compression in C, because
15887 there is no difference between an array of arrays and a multidimensional
15888 array. We don't do this for Ada to remain as close as possible to the
15889 actual representation, which is especially important against the language
15890 flexibilty wrt arrays of variable size. */
15892 bool collapse_nested_arrays
= !is_ada ();
15895 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
15896 DW_TAG_string_type doesn't have DW_AT_type attribute). */
15897 if (TYPE_STRING_FLAG (type
)
15898 && TREE_CODE (type
) == ARRAY_TYPE
15900 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
15902 HOST_WIDE_INT size
;
15904 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
15905 add_name_attribute (array_die
, type_tag (type
));
15906 equate_type_number_to_die (type
, array_die
);
15907 size
= int_size_in_bytes (type
);
15909 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
15910 else if (TYPE_DOMAIN (type
) != NULL_TREE
15911 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
15912 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
15914 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
15915 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
15917 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
15918 if (loc
&& size
> 0)
15920 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
15921 if (size
!= DWARF2_ADDR_SIZE
)
15922 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
15928 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
15929 add_name_attribute (array_die
, type_tag (type
));
15930 equate_type_number_to_die (type
, array_die
);
15932 if (TREE_CODE (type
) == VECTOR_TYPE
)
15933 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
15935 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
15937 && TREE_CODE (type
) == ARRAY_TYPE
15938 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
15939 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
15940 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
15943 /* We default the array ordering. SDB will probably do
15944 the right things even if DW_AT_ordering is not present. It's not even
15945 an issue until we start to get into multidimensional arrays anyway. If
15946 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
15947 then we'll have to put the DW_AT_ordering attribute back in. (But if
15948 and when we find out that we need to put these in, we will only do so
15949 for multidimensional arrays. */
15950 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
15953 if (TREE_CODE (type
) == VECTOR_TYPE
)
15955 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
15956 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
15957 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
15958 add_bound_info (subrange_die
, DW_AT_upper_bound
,
15959 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
15962 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
15964 /* Add representation of the type of the elements of this array type and
15965 emit the corresponding DIE if we haven't done it already. */
15966 element_type
= TREE_TYPE (type
);
15967 if (collapse_nested_arrays
)
15968 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
15970 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
15972 element_type
= TREE_TYPE (element_type
);
15975 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
15977 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
15978 if (TYPE_ARTIFICIAL (type
))
15979 add_AT_flag (array_die
, DW_AT_artificial
, 1);
15981 if (get_AT (array_die
, DW_AT_name
))
15982 add_pubtype (type
, array_die
);
15985 static dw_loc_descr_ref
15986 descr_info_loc (tree val
, tree base_decl
)
15988 HOST_WIDE_INT size
;
15989 dw_loc_descr_ref loc
, loc2
;
15990 enum dwarf_location_atom op
;
15992 if (val
== base_decl
)
15993 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
15995 switch (TREE_CODE (val
))
15998 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16000 return loc_descriptor_from_tree (val
, 0);
16002 if (host_integerp (val
, 0))
16003 return int_loc_descriptor (tree_low_cst (val
, 0));
16006 size
= int_size_in_bytes (TREE_TYPE (val
));
16009 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16012 if (size
== DWARF2_ADDR_SIZE
)
16013 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
16015 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
16017 case POINTER_PLUS_EXPR
:
16019 if (host_integerp (TREE_OPERAND (val
, 1), 1)
16020 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
16023 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16026 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
16032 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16035 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
16038 add_loc_descr (&loc
, loc2
);
16039 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
16061 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
16062 tree val
, tree base_decl
)
16064 dw_loc_descr_ref loc
;
16066 if (host_integerp (val
, 0))
16068 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
16072 loc
= descr_info_loc (val
, base_decl
);
16076 add_AT_loc (die
, attr
, loc
);
16079 /* This routine generates DIE for array with hidden descriptor, details
16080 are filled into *info by a langhook. */
16083 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
16084 dw_die_ref context_die
)
16086 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16087 dw_die_ref array_die
;
16090 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16091 add_name_attribute (array_die
, type_tag (type
));
16092 equate_type_number_to_die (type
, array_die
);
16094 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16096 && info
->ndimensions
>= 2)
16097 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16099 if (info
->data_location
)
16100 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
16102 if (info
->associated
)
16103 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
16105 if (info
->allocated
)
16106 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
16109 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
16111 dw_die_ref subrange_die
16112 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16114 if (info
->dimen
[dim
].lower_bound
)
16116 /* If it is the default value, omit it. */
16119 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
16120 && (dflt
= lower_bound_default ()) != -1
16121 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
16124 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
16125 info
->dimen
[dim
].lower_bound
,
16128 if (info
->dimen
[dim
].upper_bound
)
16129 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
16130 info
->dimen
[dim
].upper_bound
,
16132 if (info
->dimen
[dim
].stride
)
16133 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
16134 info
->dimen
[dim
].stride
,
16138 gen_type_die (info
->element_type
, context_die
);
16139 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
16141 if (get_AT (array_die
, DW_AT_name
))
16142 add_pubtype (type
, array_die
);
16147 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
16149 tree origin
= decl_ultimate_origin (decl
);
16150 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
16152 if (origin
!= NULL
)
16153 add_abstract_origin_attribute (decl_die
, origin
);
16156 add_name_and_src_coords_attributes (decl_die
, decl
);
16157 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
16158 0, 0, context_die
);
16161 if (DECL_ABSTRACT (decl
))
16162 equate_decl_number_to_die (decl
, decl_die
);
16164 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
16168 /* Walk through the list of incomplete types again, trying once more to
16169 emit full debugging info for them. */
16172 retry_incomplete_types (void)
16176 for (i
= VEC_length (tree
, incomplete_types
) - 1; i
>= 0; i
--)
16177 if (should_emit_struct_debug (VEC_index (tree
, incomplete_types
, i
),
16178 DINFO_USAGE_DIR_USE
))
16179 gen_type_die (VEC_index (tree
, incomplete_types
, i
), comp_unit_die ());
16182 /* Determine what tag to use for a record type. */
16184 static enum dwarf_tag
16185 record_type_tag (tree type
)
16187 if (! lang_hooks
.types
.classify_record
)
16188 return DW_TAG_structure_type
;
16190 switch (lang_hooks
.types
.classify_record (type
))
16192 case RECORD_IS_STRUCT
:
16193 return DW_TAG_structure_type
;
16195 case RECORD_IS_CLASS
:
16196 return DW_TAG_class_type
;
16198 case RECORD_IS_INTERFACE
:
16199 if (dwarf_version
>= 3 || !dwarf_strict
)
16200 return DW_TAG_interface_type
;
16201 return DW_TAG_structure_type
;
16204 gcc_unreachable ();
16208 /* Generate a DIE to represent an enumeration type. Note that these DIEs
16209 include all of the information about the enumeration values also. Each
16210 enumerated type name/value is listed as a child of the enumerated type
16214 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
16216 dw_die_ref type_die
= lookup_type_die (type
);
16218 if (type_die
== NULL
)
16220 type_die
= new_die (DW_TAG_enumeration_type
,
16221 scope_die_for (type
, context_die
), type
);
16222 equate_type_number_to_die (type
, type_die
);
16223 add_name_attribute (type_die
, type_tag (type
));
16224 if (dwarf_version
>= 4 || !dwarf_strict
)
16226 if (ENUM_IS_SCOPED (type
))
16227 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
16228 if (ENUM_IS_OPAQUE (type
))
16229 add_AT_flag (type_die
, DW_AT_declaration
, 1);
16232 else if (! TYPE_SIZE (type
))
16235 remove_AT (type_die
, DW_AT_declaration
);
16237 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
16238 given enum type is incomplete, do not generate the DW_AT_byte_size
16239 attribute or the DW_AT_element_list attribute. */
16240 if (TYPE_SIZE (type
))
16244 TREE_ASM_WRITTEN (type
) = 1;
16245 add_byte_size_attribute (type_die
, type
);
16246 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
16248 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
16249 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
16252 /* If the first reference to this type was as the return type of an
16253 inline function, then it may not have a parent. Fix this now. */
16254 if (type_die
->die_parent
== NULL
)
16255 add_child_die (scope_die_for (type
, context_die
), type_die
);
16257 for (link
= TYPE_VALUES (type
);
16258 link
!= NULL
; link
= TREE_CHAIN (link
))
16260 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
16261 tree value
= TREE_VALUE (link
);
16263 add_name_attribute (enum_die
,
16264 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
16266 if (TREE_CODE (value
) == CONST_DECL
)
16267 value
= DECL_INITIAL (value
);
16269 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
16270 /* DWARF2 does not provide a way of indicating whether or
16271 not enumeration constants are signed or unsigned. GDB
16272 always assumes the values are signed, so we output all
16273 values as if they were signed. That means that
16274 enumeration constants with very large unsigned values
16275 will appear to have negative values in the debugger. */
16276 add_AT_int (enum_die
, DW_AT_const_value
,
16277 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
16280 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
16281 if (TYPE_ARTIFICIAL (type
))
16282 add_AT_flag (type_die
, DW_AT_artificial
, 1);
16285 add_AT_flag (type_die
, DW_AT_declaration
, 1);
16287 add_pubtype (type
, type_die
);
16292 /* Generate a DIE to represent either a real live formal parameter decl or to
16293 represent just the type of some formal parameter position in some function
16296 Note that this routine is a bit unusual because its argument may be a
16297 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
16298 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
16299 node. If it's the former then this function is being called to output a
16300 DIE to represent a formal parameter object (or some inlining thereof). If
16301 it's the latter, then this function is only being called to output a
16302 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
16303 argument type of some subprogram type.
16304 If EMIT_NAME_P is true, name and source coordinate attributes
16308 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
16309 dw_die_ref context_die
)
16311 tree node_or_origin
= node
? node
: origin
;
16312 tree ultimate_origin
;
16313 dw_die_ref parm_die
16314 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
16316 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
16318 case tcc_declaration
:
16319 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
16320 if (node
|| ultimate_origin
)
16321 origin
= ultimate_origin
;
16322 if (origin
!= NULL
)
16323 add_abstract_origin_attribute (parm_die
, origin
);
16324 else if (emit_name_p
)
16325 add_name_and_src_coords_attributes (parm_die
, node
);
16327 || (! DECL_ABSTRACT (node_or_origin
)
16328 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
16329 decl_function_context
16330 (node_or_origin
))))
16332 tree type
= TREE_TYPE (node_or_origin
);
16333 if (decl_by_reference_p (node_or_origin
))
16334 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
16337 add_type_attribute (parm_die
, type
,
16338 TREE_READONLY (node_or_origin
),
16339 TREE_THIS_VOLATILE (node_or_origin
),
16342 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
16343 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
16345 if (node
&& node
!= origin
)
16346 equate_decl_number_to_die (node
, parm_die
);
16347 if (! DECL_ABSTRACT (node_or_origin
))
16348 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
16349 node
== NULL
, DW_AT_location
);
16354 /* We were called with some kind of a ..._TYPE node. */
16355 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
16359 gcc_unreachable ();
16365 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
16366 children DW_TAG_formal_parameter DIEs representing the arguments of the
16369 PARM_PACK must be a function parameter pack.
16370 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
16371 must point to the subsequent arguments of the function PACK_ARG belongs to.
16372 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
16373 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
16374 following the last one for which a DIE was generated. */
16377 gen_formal_parameter_pack_die (tree parm_pack
,
16379 dw_die_ref subr_die
,
16383 dw_die_ref parm_pack_die
;
16385 gcc_assert (parm_pack
16386 && lang_hooks
.function_parameter_pack_p (parm_pack
)
16389 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
16390 add_src_coords_attributes (parm_pack_die
, parm_pack
);
16392 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
16394 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
16397 gen_formal_parameter_die (arg
, NULL
,
16398 false /* Don't emit name attribute. */,
16403 return parm_pack_die
;
16406 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
16407 at the end of an (ANSI prototyped) formal parameters list. */
16410 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
16412 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
16415 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
16416 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
16417 parameters as specified in some function type specification (except for
16418 those which appear as part of a function *definition*). */
16421 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
16424 tree formal_type
= NULL
;
16425 tree first_parm_type
;
16428 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
16430 arg
= DECL_ARGUMENTS (function_or_method_type
);
16431 function_or_method_type
= TREE_TYPE (function_or_method_type
);
16436 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
16438 /* Make our first pass over the list of formal parameter types and output a
16439 DW_TAG_formal_parameter DIE for each one. */
16440 for (link
= first_parm_type
; link
; )
16442 dw_die_ref parm_die
;
16444 formal_type
= TREE_VALUE (link
);
16445 if (formal_type
== void_type_node
)
16448 /* Output a (nameless) DIE to represent the formal parameter itself. */
16449 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
16450 true /* Emit name attribute. */,
16452 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
16453 && link
== first_parm_type
)
16455 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
16456 if (dwarf_version
>= 3 || !dwarf_strict
)
16457 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
16459 else if (arg
&& DECL_ARTIFICIAL (arg
))
16460 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
16462 link
= TREE_CHAIN (link
);
16464 arg
= DECL_CHAIN (arg
);
16467 /* If this function type has an ellipsis, add a
16468 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
16469 if (formal_type
!= void_type_node
)
16470 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
16472 /* Make our second (and final) pass over the list of formal parameter types
16473 and output DIEs to represent those types (as necessary). */
16474 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
16475 link
&& TREE_VALUE (link
);
16476 link
= TREE_CHAIN (link
))
16477 gen_type_die (TREE_VALUE (link
), context_die
);
16480 /* We want to generate the DIE for TYPE so that we can generate the
16481 die for MEMBER, which has been defined; we will need to refer back
16482 to the member declaration nested within TYPE. If we're trying to
16483 generate minimal debug info for TYPE, processing TYPE won't do the
16484 trick; we need to attach the member declaration by hand. */
16487 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
16489 gen_type_die (type
, context_die
);
16491 /* If we're trying to avoid duplicate debug info, we may not have
16492 emitted the member decl for this function. Emit it now. */
16493 if (TYPE_STUB_DECL (type
)
16494 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
16495 && ! lookup_decl_die (member
))
16497 dw_die_ref type_die
;
16498 gcc_assert (!decl_ultimate_origin (member
));
16500 push_decl_scope (type
);
16501 type_die
= lookup_type_die_strip_naming_typedef (type
);
16502 if (TREE_CODE (member
) == FUNCTION_DECL
)
16503 gen_subprogram_die (member
, type_die
);
16504 else if (TREE_CODE (member
) == FIELD_DECL
)
16506 /* Ignore the nameless fields that are used to skip bits but handle
16507 C++ anonymous unions and structs. */
16508 if (DECL_NAME (member
) != NULL_TREE
16509 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
16510 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
16512 gen_type_die (member_declared_type (member
), type_die
);
16513 gen_field_die (member
, type_die
);
16517 gen_variable_die (member
, NULL_TREE
, type_die
);
16523 /* Forward declare these functions, because they are mutually recursive
16524 with their set_block_* pairing functions. */
16525 static void set_decl_origin_self (tree
);
16526 static void set_decl_abstract_flags (tree
, int);
16528 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
16529 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
16530 that it points to the node itself, thus indicating that the node is its
16531 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
16532 the given node is NULL, recursively descend the decl/block tree which
16533 it is the root of, and for each other ..._DECL or BLOCK node contained
16534 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
16535 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
16536 values to point to themselves. */
16539 set_block_origin_self (tree stmt
)
16541 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
16543 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
16548 for (local_decl
= BLOCK_VARS (stmt
);
16549 local_decl
!= NULL_TREE
;
16550 local_decl
= DECL_CHAIN (local_decl
))
16551 if (! DECL_EXTERNAL (local_decl
))
16552 set_decl_origin_self (local_decl
); /* Potential recursion. */
16558 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
16559 subblock
!= NULL_TREE
;
16560 subblock
= BLOCK_CHAIN (subblock
))
16561 set_block_origin_self (subblock
); /* Recurse. */
16566 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
16567 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
16568 node to so that it points to the node itself, thus indicating that the
16569 node represents its own (abstract) origin. Additionally, if the
16570 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
16571 the decl/block tree of which the given node is the root of, and for
16572 each other ..._DECL or BLOCK node contained therein whose
16573 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
16574 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
16575 point to themselves. */
16578 set_decl_origin_self (tree decl
)
16580 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
16582 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
16583 if (TREE_CODE (decl
) == FUNCTION_DECL
)
16587 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
16588 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
16589 if (DECL_INITIAL (decl
) != NULL_TREE
16590 && DECL_INITIAL (decl
) != error_mark_node
)
16591 set_block_origin_self (DECL_INITIAL (decl
));
16596 /* Given a pointer to some BLOCK node, and a boolean value to set the
16597 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
16598 the given block, and for all local decls and all local sub-blocks
16599 (recursively) which are contained therein. */
16602 set_block_abstract_flags (tree stmt
, int setting
)
16608 BLOCK_ABSTRACT (stmt
) = setting
;
16610 for (local_decl
= BLOCK_VARS (stmt
);
16611 local_decl
!= NULL_TREE
;
16612 local_decl
= DECL_CHAIN (local_decl
))
16613 if (! DECL_EXTERNAL (local_decl
))
16614 set_decl_abstract_flags (local_decl
, setting
);
16616 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
16618 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
16619 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
16620 || TREE_CODE (local_decl
) == PARM_DECL
)
16621 set_decl_abstract_flags (local_decl
, setting
);
16624 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
16625 subblock
!= NULL_TREE
;
16626 subblock
= BLOCK_CHAIN (subblock
))
16627 set_block_abstract_flags (subblock
, setting
);
16630 /* Given a pointer to some ..._DECL node, and a boolean value to set the
16631 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
16632 given decl, and (in the case where the decl is a FUNCTION_DECL) also
16633 set the abstract flags for all of the parameters, local vars, local
16634 blocks and sub-blocks (recursively) to the same setting. */
16637 set_decl_abstract_flags (tree decl
, int setting
)
16639 DECL_ABSTRACT (decl
) = setting
;
16640 if (TREE_CODE (decl
) == FUNCTION_DECL
)
16644 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
16645 DECL_ABSTRACT (arg
) = setting
;
16646 if (DECL_INITIAL (decl
) != NULL_TREE
16647 && DECL_INITIAL (decl
) != error_mark_node
)
16648 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
16652 /* Generate the DWARF2 info for the "abstract" instance of a function which we
16653 may later generate inlined and/or out-of-line instances of. */
16656 dwarf2out_abstract_function (tree decl
)
16658 dw_die_ref old_die
;
16662 htab_t old_decl_loc_table
;
16663 htab_t old_cached_dw_loc_list_table
;
16664 int old_call_site_count
, old_tail_call_site_count
;
16665 struct call_arg_loc_node
*old_call_arg_locations
;
16667 /* Make sure we have the actual abstract inline, not a clone. */
16668 decl
= DECL_ORIGIN (decl
);
16670 old_die
= lookup_decl_die (decl
);
16671 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
16672 /* We've already generated the abstract instance. */
16675 /* We can be called while recursively when seeing block defining inlined subroutine
16676 DIE. Be sure to not clobber the outer location table nor use it or we would
16677 get locations in abstract instantces. */
16678 old_decl_loc_table
= decl_loc_table
;
16679 decl_loc_table
= NULL
;
16680 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
16681 cached_dw_loc_list_table
= NULL
;
16682 old_call_arg_locations
= call_arg_locations
;
16683 call_arg_locations
= NULL
;
16684 old_call_site_count
= call_site_count
;
16685 call_site_count
= -1;
16686 old_tail_call_site_count
= tail_call_site_count
;
16687 tail_call_site_count
= -1;
16689 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
16690 we don't get confused by DECL_ABSTRACT. */
16691 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16693 context
= decl_class_context (decl
);
16695 gen_type_die_for_member
16696 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
16699 /* Pretend we've just finished compiling this function. */
16700 save_fn
= current_function_decl
;
16701 current_function_decl
= decl
;
16702 push_cfun (DECL_STRUCT_FUNCTION (decl
));
16704 was_abstract
= DECL_ABSTRACT (decl
);
16705 set_decl_abstract_flags (decl
, 1);
16706 dwarf2out_decl (decl
);
16707 if (! was_abstract
)
16708 set_decl_abstract_flags (decl
, 0);
16710 current_function_decl
= save_fn
;
16711 decl_loc_table
= old_decl_loc_table
;
16712 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
16713 call_arg_locations
= old_call_arg_locations
;
16714 call_site_count
= old_call_site_count
;
16715 tail_call_site_count
= old_tail_call_site_count
;
16719 /* Helper function of premark_used_types() which gets called through
16722 Marks the DIE of a given type in *SLOT as perennial, so it never gets
16723 marked as unused by prune_unused_types. */
16726 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
16731 type
= (tree
) *slot
;
16732 die
= lookup_type_die (type
);
16734 die
->die_perennial_p
= 1;
16738 /* Helper function of premark_types_used_by_global_vars which gets called
16739 through htab_traverse.
16741 Marks the DIE of a given type in *SLOT as perennial, so it never gets
16742 marked as unused by prune_unused_types. The DIE of the type is marked
16743 only if the global variable using the type will actually be emitted. */
16746 premark_types_used_by_global_vars_helper (void **slot
,
16747 void *data ATTRIBUTE_UNUSED
)
16749 struct types_used_by_vars_entry
*entry
;
16752 entry
= (struct types_used_by_vars_entry
*) *slot
;
16753 gcc_assert (entry
->type
!= NULL
16754 && entry
->var_decl
!= NULL
);
16755 die
= lookup_type_die (entry
->type
);
16758 /* Ask cgraph if the global variable really is to be emitted.
16759 If yes, then we'll keep the DIE of ENTRY->TYPE. */
16760 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
16761 if (node
&& node
->analyzed
)
16763 die
->die_perennial_p
= 1;
16764 /* Keep the parent DIEs as well. */
16765 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
16766 die
->die_perennial_p
= 1;
16772 /* Mark all members of used_types_hash as perennial. */
16775 premark_used_types (void)
16777 if (cfun
&& cfun
->used_types_hash
)
16778 htab_traverse (cfun
->used_types_hash
, premark_used_types_helper
, NULL
);
16781 /* Mark all members of types_used_by_vars_entry as perennial. */
16784 premark_types_used_by_global_vars (void)
16786 if (types_used_by_vars_hash
)
16787 htab_traverse (types_used_by_vars_hash
,
16788 premark_types_used_by_global_vars_helper
, NULL
);
16791 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
16792 for CA_LOC call arg loc node. */
16795 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
16796 struct call_arg_loc_node
*ca_loc
)
16798 dw_die_ref stmt_die
= NULL
, die
;
16799 tree block
= ca_loc
->block
;
16802 && block
!= DECL_INITIAL (decl
)
16803 && TREE_CODE (block
) == BLOCK
)
16805 if (VEC_length (dw_die_ref
, block_map
) > BLOCK_NUMBER (block
))
16806 stmt_die
= VEC_index (dw_die_ref
, block_map
, BLOCK_NUMBER (block
));
16809 block
= BLOCK_SUPERCONTEXT (block
);
16811 if (stmt_die
== NULL
)
16812 stmt_die
= subr_die
;
16813 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
16814 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
16815 if (ca_loc
->tail_call_p
)
16816 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
16817 if (ca_loc
->symbol_ref
)
16819 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
16821 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
16823 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
);
16828 /* Return true if an abstract instance of function DECL can be generated in
16829 the debug information. */
16832 function_possibly_abstracted_p (tree decl
)
16834 /* An abstract instance of DECL can be generated if DECL can be inlined or
16835 is nested in a function that can be inlined, recursively. */
16838 if (cgraph_function_possibly_inlined_p (decl
))
16840 decl
= decl_function_context (decl
);
16841 /* Do not consider Fortran subroutines as nested in the main program. */
16844 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
16852 /* Generate a DIE to represent a declared function (either file-scope or
16856 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
16858 tree origin
= decl_ultimate_origin (decl
);
16859 dw_die_ref subr_die
;
16861 dw_die_ref old_die
= lookup_decl_die (decl
);
16862 int declaration
= (current_function_decl
!= decl
16863 || class_or_namespace_scope_p (context_die
));
16865 premark_used_types ();
16867 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
16868 started to generate the abstract instance of an inline, decided to output
16869 its containing class, and proceeded to emit the declaration of the inline
16870 from the member list for the class. If so, DECLARATION takes priority;
16871 we'll get back to the abstract instance when done with the class. */
16873 /* The class-scope declaration DIE must be the primary DIE. */
16874 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
16877 gcc_assert (!old_die
);
16880 /* Now that the C++ front end lazily declares artificial member fns, we
16881 might need to retrofit the declaration into its class. */
16882 if (!declaration
&& !origin
&& !old_die
16883 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
16884 && !class_or_namespace_scope_p (context_die
)
16885 && debug_info_level
> DINFO_LEVEL_TERSE
)
16886 old_die
= force_decl_die (decl
);
16888 if (origin
!= NULL
)
16890 gcc_assert (!declaration
|| local_scope_p (context_die
));
16892 /* Fixup die_parent for the abstract instance of a nested
16893 inline function. */
16894 if (old_die
&& old_die
->die_parent
== NULL
)
16895 add_child_die (context_die
, old_die
);
16897 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
16898 add_abstract_origin_attribute (subr_die
, origin
);
16899 /* This is where the actual code for a cloned function is.
16900 Let's emit linkage name attribute for it. This helps
16901 debuggers to e.g, set breakpoints into
16902 constructors/destructors when the user asks "break
16904 add_linkage_name (subr_die
, decl
);
16908 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16909 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
16911 if (!get_AT_flag (old_die
, DW_AT_declaration
)
16912 /* We can have a normal definition following an inline one in the
16913 case of redefinition of GNU C extern inlines.
16914 It seems reasonable to use AT_specification in this case. */
16915 && !get_AT (old_die
, DW_AT_inline
))
16917 /* Detect and ignore this case, where we are trying to output
16918 something we have already output. */
16922 /* If the definition comes from the same place as the declaration,
16923 maybe use the old DIE. We always want the DIE for this function
16924 that has the *_pc attributes to be under comp_unit_die so the
16925 debugger can find it. We also need to do this for abstract
16926 instances of inlines, since the spec requires the out-of-line copy
16927 to have the same parent. For local class methods, this doesn't
16928 apply; we just use the old DIE. */
16929 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
16930 && (DECL_ARTIFICIAL (decl
)
16931 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
16932 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
16933 == (unsigned) s
.line
))))
16935 subr_die
= old_die
;
16937 /* Clear out the declaration attribute and the formal parameters.
16938 Do not remove all children, because it is possible that this
16939 declaration die was forced using force_decl_die(). In such
16940 cases die that forced declaration die (e.g. TAG_imported_module)
16941 is one of the children that we do not want to remove. */
16942 remove_AT (subr_die
, DW_AT_declaration
);
16943 remove_AT (subr_die
, DW_AT_object_pointer
);
16944 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
16948 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
16949 add_AT_specification (subr_die
, old_die
);
16950 add_pubname (decl
, subr_die
);
16951 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
16952 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
16953 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
16954 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
16959 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
16961 if (TREE_PUBLIC (decl
))
16962 add_AT_flag (subr_die
, DW_AT_external
, 1);
16964 add_name_and_src_coords_attributes (subr_die
, decl
);
16965 add_pubname (decl
, subr_die
);
16966 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16968 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
16969 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
16970 0, 0, context_die
);
16973 add_pure_or_virtual_attribute (subr_die
, decl
);
16974 if (DECL_ARTIFICIAL (decl
))
16975 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
16977 add_accessibility_attribute (subr_die
, decl
);
16982 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
16984 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
16986 /* If this is an explicit function declaration then generate
16987 a DW_AT_explicit attribute. */
16988 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
16989 && (dwarf_version
>= 3 || !dwarf_strict
))
16990 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
16992 /* The first time we see a member function, it is in the context of
16993 the class to which it belongs. We make sure of this by emitting
16994 the class first. The next time is the definition, which is
16995 handled above. The two may come from the same source text.
16997 Note that force_decl_die() forces function declaration die. It is
16998 later reused to represent definition. */
16999 equate_decl_number_to_die (decl
, subr_die
);
17002 else if (DECL_ABSTRACT (decl
))
17004 if (DECL_DECLARED_INLINE_P (decl
))
17006 if (function_possibly_abstracted_p (decl
))
17007 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
17009 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
17013 if (function_possibly_abstracted_p (decl
))
17014 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
17016 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
17019 if (DECL_DECLARED_INLINE_P (decl
)
17020 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
17021 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17023 equate_decl_number_to_die (decl
, subr_die
);
17025 else if (!DECL_EXTERNAL (decl
))
17027 HOST_WIDE_INT cfa_fb_offset
;
17029 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17030 equate_decl_number_to_die (decl
, subr_die
);
17032 if (!flag_reorder_blocks_and_partition
)
17034 dw_fde_ref fde
= cfun
->fde
;
17035 if (fde
->dw_fde_begin
)
17037 /* We have already generated the labels. */
17038 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, fde
->dw_fde_begin
);
17039 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, fde
->dw_fde_end
);
17043 /* Create start/end labels and add the range. */
17044 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
17045 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
17046 current_function_funcdef_no
);
17047 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
17048 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
17049 current_function_funcdef_no
);
17050 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
17053 #if VMS_DEBUGGING_INFO
17054 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17055 Section 2.3 Prologue and Epilogue Attributes:
17056 When a breakpoint is set on entry to a function, it is generally
17057 desirable for execution to be suspended, not on the very first
17058 instruction of the function, but rather at a point after the
17059 function's frame has been set up, after any language defined local
17060 declaration processing has been completed, and before execution of
17061 the first statement of the function begins. Debuggers generally
17062 cannot properly determine where this point is. Similarly for a
17063 breakpoint set on exit from a function. The prologue and epilogue
17064 attributes allow a compiler to communicate the location(s) to use. */
17067 if (fde
->dw_fde_vms_end_prologue
)
17068 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
17069 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
17071 if (fde
->dw_fde_vms_begin_epilogue
)
17072 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
17073 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
17080 /* Generate pubnames entries for the split function code ranges. */
17081 dw_fde_ref fde
= cfun
->fde
;
17083 if (fde
->dw_fde_second_begin
)
17085 if (dwarf_version
>= 3 || !dwarf_strict
)
17087 /* We should use ranges for non-contiguous code section
17088 addresses. Use the actual code range for the initial
17089 section, since the HOT/COLD labels might precede an
17090 alignment offset. */
17091 bool range_list_added
= false;
17092 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
17093 fde
->dw_fde_end
, &range_list_added
);
17094 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
17095 fde
->dw_fde_second_end
,
17096 &range_list_added
);
17097 if (range_list_added
)
17102 /* There is no real support in DW2 for this .. so we make
17103 a work-around. First, emit the pub name for the segment
17104 containing the function label. Then make and emit a
17105 simplified subprogram DIE for the second segment with the
17106 name pre-fixed by __hot/cold_sect_of_. We use the same
17107 linkage name for the second die so that gdb will find both
17108 sections when given "b foo". */
17109 const char *name
= NULL
;
17110 tree decl_name
= DECL_NAME (decl
);
17111 dw_die_ref seg_die
;
17113 /* Do the 'primary' section. */
17114 add_AT_lbl_id (subr_die
, DW_AT_low_pc
,
17115 fde
->dw_fde_begin
);
17116 add_AT_lbl_id (subr_die
, DW_AT_high_pc
,
17119 /* Build a minimal DIE for the secondary section. */
17120 seg_die
= new_die (DW_TAG_subprogram
,
17121 subr_die
->die_parent
, decl
);
17123 if (TREE_PUBLIC (decl
))
17124 add_AT_flag (seg_die
, DW_AT_external
, 1);
17126 if (decl_name
!= NULL
17127 && IDENTIFIER_POINTER (decl_name
) != NULL
)
17129 name
= dwarf2_name (decl
, 1);
17130 if (! DECL_ARTIFICIAL (decl
))
17131 add_src_coords_attributes (seg_die
, decl
);
17133 add_linkage_name (seg_die
, decl
);
17135 gcc_assert (name
!= NULL
);
17136 add_pure_or_virtual_attribute (seg_die
, decl
);
17137 if (DECL_ARTIFICIAL (decl
))
17138 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
17140 name
= concat ("__second_sect_of_", name
, NULL
);
17141 add_AT_lbl_id (seg_die
, DW_AT_low_pc
,
17142 fde
->dw_fde_second_begin
);
17143 add_AT_lbl_id (seg_die
, DW_AT_high_pc
,
17144 fde
->dw_fde_second_end
);
17145 add_name_attribute (seg_die
, name
);
17146 if (want_pubnames ())
17147 add_pubname_string (name
, seg_die
);
17152 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, fde
->dw_fde_begin
);
17153 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, fde
->dw_fde_end
);
17157 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
17159 /* We define the "frame base" as the function's CFA. This is more
17160 convenient for several reasons: (1) It's stable across the prologue
17161 and epilogue, which makes it better than just a frame pointer,
17162 (2) With dwarf3, there exists a one-byte encoding that allows us
17163 to reference the .debug_frame data by proxy, but failing that,
17164 (3) We can at least reuse the code inspection and interpretation
17165 code that determines the CFA position at various points in the
17167 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
17169 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
17170 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
17174 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
17175 if (list
->dw_loc_next
)
17176 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
17178 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
17181 /* Compute a displacement from the "steady-state frame pointer" to
17182 the CFA. The former is what all stack slots and argument slots
17183 will reference in the rtl; the later is what we've told the
17184 debugger about. We'll need to adjust all frame_base references
17185 by this displacement. */
17186 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
17188 if (cfun
->static_chain_decl
)
17189 add_AT_location_description (subr_die
, DW_AT_static_link
,
17190 loc_list_from_tree (cfun
->static_chain_decl
, 2));
17193 /* Generate child dies for template paramaters. */
17194 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17195 gen_generic_params_dies (decl
);
17197 /* Now output descriptions of the arguments for this function. This gets
17198 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
17199 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
17200 `...' at the end of the formal parameter list. In order to find out if
17201 there was a trailing ellipsis or not, we must instead look at the type
17202 associated with the FUNCTION_DECL. This will be a node of type
17203 FUNCTION_TYPE. If the chain of type nodes hanging off of this
17204 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
17205 an ellipsis at the end. */
17207 /* In the case where we are describing a mere function declaration, all we
17208 need to do here (and all we *can* do here) is to describe the *types* of
17209 its formal parameters. */
17210 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
17212 else if (declaration
)
17213 gen_formal_types_die (decl
, subr_die
);
17216 /* Generate DIEs to represent all known formal parameters. */
17217 tree parm
= DECL_ARGUMENTS (decl
);
17218 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
17219 tree generic_decl_parm
= generic_decl
17220 ? DECL_ARGUMENTS (generic_decl
)
17223 /* Now we want to walk the list of parameters of the function and
17224 emit their relevant DIEs.
17226 We consider the case of DECL being an instance of a generic function
17227 as well as it being a normal function.
17229 If DECL is an instance of a generic function we walk the
17230 parameters of the generic function declaration _and_ the parameters of
17231 DECL itself. This is useful because we want to emit specific DIEs for
17232 function parameter packs and those are declared as part of the
17233 generic function declaration. In that particular case,
17234 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
17235 That DIE has children DIEs representing the set of arguments
17236 of the pack. Note that the set of pack arguments can be empty.
17237 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
17240 Otherwise, we just consider the parameters of DECL. */
17241 while (generic_decl_parm
|| parm
)
17243 if (generic_decl_parm
17244 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
17245 gen_formal_parameter_pack_die (generic_decl_parm
,
17250 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
17252 if (parm
== DECL_ARGUMENTS (decl
)
17253 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
17255 && (dwarf_version
>= 3 || !dwarf_strict
))
17256 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
17258 parm
= DECL_CHAIN (parm
);
17261 if (generic_decl_parm
)
17262 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
17265 /* Decide whether we need an unspecified_parameters DIE at the end.
17266 There are 2 more cases to do this for: 1) the ansi ... declaration -
17267 this is detectable when the end of the arg list is not a
17268 void_type_node 2) an unprototyped function declaration (not a
17269 definition). This just means that we have no info about the
17270 parameters at all. */
17271 if (prototype_p (TREE_TYPE (decl
)))
17273 /* This is the prototyped case, check for.... */
17274 if (stdarg_p (TREE_TYPE (decl
)))
17275 gen_unspecified_parameters_die (decl
, subr_die
);
17277 else if (DECL_INITIAL (decl
) == NULL_TREE
)
17278 gen_unspecified_parameters_die (decl
, subr_die
);
17281 /* Output Dwarf info for all of the stuff within the body of the function
17282 (if it has one - it may be just a declaration). */
17283 outer_scope
= DECL_INITIAL (decl
);
17285 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
17286 a function. This BLOCK actually represents the outermost binding contour
17287 for the function, i.e. the contour in which the function's formal
17288 parameters and labels get declared. Curiously, it appears that the front
17289 end doesn't actually put the PARM_DECL nodes for the current function onto
17290 the BLOCK_VARS list for this outer scope, but are strung off of the
17291 DECL_ARGUMENTS list for the function instead.
17293 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
17294 the LABEL_DECL nodes for the function however, and we output DWARF info
17295 for those in decls_for_scope. Just within the `outer_scope' there will be
17296 a BLOCK node representing the function's outermost pair of curly braces,
17297 and any blocks used for the base and member initializers of a C++
17298 constructor function. */
17299 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
17301 int call_site_note_count
= 0;
17302 int tail_call_site_note_count
= 0;
17304 /* Emit a DW_TAG_variable DIE for a named return value. */
17305 if (DECL_NAME (DECL_RESULT (decl
)))
17306 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
17308 current_function_has_inlines
= 0;
17309 decls_for_scope (outer_scope
, subr_die
, 0);
17311 if (call_arg_locations
&& !dwarf_strict
)
17313 struct call_arg_loc_node
*ca_loc
;
17314 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
17316 dw_die_ref die
= NULL
;
17317 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
17320 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
17321 arg
; arg
= next_arg
)
17323 dw_loc_descr_ref reg
, val
;
17324 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
17325 dw_die_ref cdie
, tdie
= NULL
;
17327 next_arg
= XEXP (arg
, 1);
17328 if (REG_P (XEXP (XEXP (arg
, 0), 0))
17330 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
17331 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
17332 && REGNO (XEXP (XEXP (arg
, 0), 0))
17333 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
17334 next_arg
= XEXP (next_arg
, 1);
17335 if (mode
== VOIDmode
)
17337 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
17338 if (mode
== VOIDmode
)
17339 mode
= GET_MODE (XEXP (arg
, 0));
17341 if (mode
== VOIDmode
|| mode
== BLKmode
)
17343 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
17345 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
17346 tloc
= XEXP (XEXP (arg
, 0), 1);
17349 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
17350 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
17352 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
17353 tlocc
= XEXP (XEXP (arg
, 0), 1);
17357 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
17358 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
17359 VAR_INIT_STATUS_INITIALIZED
);
17360 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
17362 rtx mem
= XEXP (XEXP (arg
, 0), 0);
17363 reg
= mem_loc_descriptor (XEXP (mem
, 0),
17364 get_address_mode (mem
),
17366 VAR_INIT_STATUS_INITIALIZED
);
17368 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
17369 == DEBUG_PARAMETER_REF
)
17372 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
17373 tdie
= lookup_decl_die (tdecl
);
17380 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
17381 != DEBUG_PARAMETER_REF
)
17383 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
17385 VAR_INIT_STATUS_INITIALIZED
);
17389 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
17390 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
17393 add_AT_loc (cdie
, DW_AT_location
, reg
);
17394 else if (tdie
!= NULL
)
17395 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
17396 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
17397 if (next_arg
!= XEXP (arg
, 1))
17399 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
17400 if (mode
== VOIDmode
)
17401 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
17402 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
17405 VAR_INIT_STATUS_INITIALIZED
);
17407 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
17411 && (ca_loc
->symbol_ref
|| tloc
))
17412 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
17413 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
17415 dw_loc_descr_ref tval
= NULL
;
17417 if (tloc
!= NULL_RTX
)
17418 tval
= mem_loc_descriptor (tloc
,
17419 GET_MODE (tloc
) == VOIDmode
17420 ? Pmode
: GET_MODE (tloc
),
17422 VAR_INIT_STATUS_INITIALIZED
);
17424 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
17425 else if (tlocc
!= NULL_RTX
)
17427 tval
= mem_loc_descriptor (tlocc
,
17428 GET_MODE (tlocc
) == VOIDmode
17429 ? Pmode
: GET_MODE (tlocc
),
17431 VAR_INIT_STATUS_INITIALIZED
);
17433 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
17439 call_site_note_count
++;
17440 if (ca_loc
->tail_call_p
)
17441 tail_call_site_note_count
++;
17445 call_arg_locations
= NULL
;
17446 call_arg_loc_last
= NULL
;
17447 if (tail_call_site_count
>= 0
17448 && tail_call_site_count
== tail_call_site_note_count
17451 if (call_site_count
>= 0
17452 && call_site_count
== call_site_note_count
)
17453 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
17455 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
17457 call_site_count
= -1;
17458 tail_call_site_count
= -1;
17460 /* Add the calling convention attribute if requested. */
17461 add_calling_convention_attribute (subr_die
, decl
);
17465 /* Returns a hash value for X (which really is a die_struct). */
17468 common_block_die_table_hash (const void *x
)
17470 const_dw_die_ref d
= (const_dw_die_ref
) x
;
17471 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
17474 /* Return nonzero if decl_id and die_parent of die_struct X is the same
17475 as decl_id and die_parent of die_struct Y. */
17478 common_block_die_table_eq (const void *x
, const void *y
)
17480 const_dw_die_ref d
= (const_dw_die_ref
) x
;
17481 const_dw_die_ref e
= (const_dw_die_ref
) y
;
17482 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
17485 /* Generate a DIE to represent a declared data object.
17486 Either DECL or ORIGIN must be non-null. */
17489 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
17491 HOST_WIDE_INT off
= 0;
17493 tree decl_or_origin
= decl
? decl
: origin
;
17494 tree ultimate_origin
;
17495 dw_die_ref var_die
;
17496 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
17497 dw_die_ref origin_die
;
17498 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
17499 || class_or_namespace_scope_p (context_die
));
17500 bool specialization_p
= false;
17502 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
17503 if (decl
|| ultimate_origin
)
17504 origin
= ultimate_origin
;
17505 com_decl
= fortran_common (decl_or_origin
, &off
);
17507 /* Symbol in common gets emitted as a child of the common block, in the form
17508 of a data member. */
17511 dw_die_ref com_die
;
17512 dw_loc_list_ref loc
;
17513 die_node com_die_arg
;
17515 var_die
= lookup_decl_die (decl_or_origin
);
17518 if (get_AT (var_die
, DW_AT_location
) == NULL
)
17520 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
17525 /* Optimize the common case. */
17526 if (single_element_loc_list_p (loc
)
17527 && loc
->expr
->dw_loc_opc
== DW_OP_addr
17528 && loc
->expr
->dw_loc_next
== NULL
17529 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
17532 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
17533 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
17534 = plus_constant (GET_MODE (x
), x
, off
);
17537 loc_list_plus_const (loc
, off
);
17539 add_AT_location_description (var_die
, DW_AT_location
, loc
);
17540 remove_AT (var_die
, DW_AT_declaration
);
17546 if (common_block_die_table
== NULL
)
17547 common_block_die_table
17548 = htab_create_ggc (10, common_block_die_table_hash
,
17549 common_block_die_table_eq
, NULL
);
17551 com_die_arg
.decl_id
= DECL_UID (com_decl
);
17552 com_die_arg
.die_parent
= context_die
;
17553 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
17554 loc
= loc_list_from_tree (com_decl
, 2);
17555 if (com_die
== NULL
)
17558 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
17561 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
17562 add_name_and_src_coords_attributes (com_die
, com_decl
);
17565 add_AT_location_description (com_die
, DW_AT_location
, loc
);
17566 /* Avoid sharing the same loc descriptor between
17567 DW_TAG_common_block and DW_TAG_variable. */
17568 loc
= loc_list_from_tree (com_decl
, 2);
17570 else if (DECL_EXTERNAL (decl
))
17571 add_AT_flag (com_die
, DW_AT_declaration
, 1);
17572 if (want_pubnames ())
17573 add_pubname_string (cnam
, com_die
); /* ??? needed? */
17574 com_die
->decl_id
= DECL_UID (com_decl
);
17575 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
17576 *slot
= (void *) com_die
;
17578 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
17580 add_AT_location_description (com_die
, DW_AT_location
, loc
);
17581 loc
= loc_list_from_tree (com_decl
, 2);
17582 remove_AT (com_die
, DW_AT_declaration
);
17584 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
17585 add_name_and_src_coords_attributes (var_die
, decl
);
17586 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
17587 TREE_THIS_VOLATILE (decl
), context_die
);
17588 add_AT_flag (var_die
, DW_AT_external
, 1);
17593 /* Optimize the common case. */
17594 if (single_element_loc_list_p (loc
)
17595 && loc
->expr
->dw_loc_opc
== DW_OP_addr
17596 && loc
->expr
->dw_loc_next
== NULL
17597 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
17599 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
17600 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
17601 = plus_constant (GET_MODE (x
), x
, off
);
17604 loc_list_plus_const (loc
, off
);
17606 add_AT_location_description (var_die
, DW_AT_location
, loc
);
17608 else if (DECL_EXTERNAL (decl
))
17609 add_AT_flag (var_die
, DW_AT_declaration
, 1);
17610 equate_decl_number_to_die (decl
, var_die
);
17614 /* If the compiler emitted a definition for the DECL declaration
17615 and if we already emitted a DIE for it, don't emit a second
17616 DIE for it again. Allow re-declarations of DECLs that are
17617 inside functions, though. */
17618 if (old_die
&& declaration
&& !local_scope_p (context_die
))
17621 /* For static data members, the declaration in the class is supposed
17622 to have DW_TAG_member tag; the specification should still be
17623 DW_TAG_variable referencing the DW_TAG_member DIE. */
17624 if (declaration
&& class_scope_p (context_die
))
17625 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
17627 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
17630 if (origin
!= NULL
)
17631 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
17633 /* Loop unrolling can create multiple blocks that refer to the same
17634 static variable, so we must test for the DW_AT_declaration flag.
17636 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
17637 copy decls and set the DECL_ABSTRACT flag on them instead of
17640 ??? Duplicated blocks have been rewritten to use .debug_ranges.
17642 ??? The declare_in_namespace support causes us to get two DIEs for one
17643 variable, both of which are declarations. We want to avoid considering
17644 one to be a specification, so we must test that this DIE is not a
17646 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
17647 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
17649 /* This is a definition of a C++ class level static. */
17650 add_AT_specification (var_die
, old_die
);
17651 specialization_p
= true;
17652 if (DECL_NAME (decl
))
17654 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17655 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17657 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17658 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
17660 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17661 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
17663 if (old_die
->die_tag
== DW_TAG_member
)
17664 add_linkage_name (var_die
, decl
);
17668 add_name_and_src_coords_attributes (var_die
, decl
);
17670 if ((origin
== NULL
&& !specialization_p
)
17672 && !DECL_ABSTRACT (decl_or_origin
)
17673 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
17674 decl_function_context
17675 (decl_or_origin
))))
17677 tree type
= TREE_TYPE (decl_or_origin
);
17679 if (decl_by_reference_p (decl_or_origin
))
17680 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
17682 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
17683 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
17686 if (origin
== NULL
&& !specialization_p
)
17688 if (TREE_PUBLIC (decl
))
17689 add_AT_flag (var_die
, DW_AT_external
, 1);
17691 if (DECL_ARTIFICIAL (decl
))
17692 add_AT_flag (var_die
, DW_AT_artificial
, 1);
17694 add_accessibility_attribute (var_die
, decl
);
17698 add_AT_flag (var_die
, DW_AT_declaration
, 1);
17700 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
17701 equate_decl_number_to_die (decl
, var_die
);
17704 && (! DECL_ABSTRACT (decl_or_origin
)
17705 /* Local static vars are shared between all clones/inlines,
17706 so emit DW_AT_location on the abstract DIE if DECL_RTL is
17708 || (TREE_CODE (decl_or_origin
) == VAR_DECL
17709 && TREE_STATIC (decl_or_origin
)
17710 && DECL_RTL_SET_P (decl_or_origin
)))
17711 /* When abstract origin already has DW_AT_location attribute, no need
17712 to add it again. */
17713 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
17715 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
17716 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
17717 defer_location (decl_or_origin
, var_die
);
17719 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
17720 decl
== NULL
, DW_AT_location
);
17721 add_pubname (decl_or_origin
, var_die
);
17724 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
17727 /* Generate a DIE to represent a named constant. */
17730 gen_const_die (tree decl
, dw_die_ref context_die
)
17732 dw_die_ref const_die
;
17733 tree type
= TREE_TYPE (decl
);
17735 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
17736 add_name_and_src_coords_attributes (const_die
, decl
);
17737 add_type_attribute (const_die
, type
, 1, 0, context_die
);
17738 if (TREE_PUBLIC (decl
))
17739 add_AT_flag (const_die
, DW_AT_external
, 1);
17740 if (DECL_ARTIFICIAL (decl
))
17741 add_AT_flag (const_die
, DW_AT_artificial
, 1);
17742 tree_add_const_value_attribute_for_decl (const_die
, decl
);
17745 /* Generate a DIE to represent a label identifier. */
17748 gen_label_die (tree decl
, dw_die_ref context_die
)
17750 tree origin
= decl_ultimate_origin (decl
);
17751 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
17753 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
17755 if (origin
!= NULL
)
17756 add_abstract_origin_attribute (lbl_die
, origin
);
17758 add_name_and_src_coords_attributes (lbl_die
, decl
);
17760 if (DECL_ABSTRACT (decl
))
17761 equate_decl_number_to_die (decl
, lbl_die
);
17764 insn
= DECL_RTL_IF_SET (decl
);
17766 /* Deleted labels are programmer specified labels which have been
17767 eliminated because of various optimizations. We still emit them
17768 here so that it is possible to put breakpoints on them. */
17772 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
17774 /* When optimization is enabled (via -O) some parts of the compiler
17775 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
17776 represent source-level labels which were explicitly declared by
17777 the user. This really shouldn't be happening though, so catch
17778 it if it ever does happen. */
17779 gcc_assert (!INSN_DELETED_P (insn
));
17781 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
17782 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
17786 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
17787 && CODE_LABEL_NUMBER (insn
) != -1)
17789 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
17790 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
17795 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
17796 attributes to the DIE for a block STMT, to describe where the inlined
17797 function was called from. This is similar to add_src_coords_attributes. */
17800 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
17802 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
17804 if (dwarf_version
>= 3 || !dwarf_strict
)
17806 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
17807 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
17812 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
17813 Add low_pc and high_pc attributes to the DIE for a block STMT. */
17816 add_high_low_attributes (tree stmt
, dw_die_ref die
)
17818 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
17820 if (BLOCK_FRAGMENT_CHAIN (stmt
)
17821 && (dwarf_version
>= 3 || !dwarf_strict
))
17823 tree chain
, superblock
= NULL_TREE
;
17825 dw_attr_ref attr
= NULL
;
17827 if (inlined_function_outer_scope_p (stmt
))
17829 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
17830 BLOCK_NUMBER (stmt
));
17831 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
17834 /* Optimize duplicate .debug_ranges lists or even tails of
17835 lists. If this BLOCK has same ranges as its supercontext,
17836 lookup DW_AT_ranges attribute in the supercontext (and
17837 recursively so), verify that the ranges_table contains the
17838 right values and use it instead of adding a new .debug_range. */
17839 for (chain
= stmt
, pdie
= die
;
17840 BLOCK_SAME_RANGE (chain
);
17841 chain
= BLOCK_SUPERCONTEXT (chain
))
17843 dw_attr_ref new_attr
;
17845 pdie
= pdie
->die_parent
;
17848 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
17850 new_attr
= get_AT (pdie
, DW_AT_ranges
);
17851 if (new_attr
== NULL
17852 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
17855 superblock
= BLOCK_SUPERCONTEXT (chain
);
17858 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
17859 / 2 / DWARF2_ADDR_SIZE
].num
17860 == BLOCK_NUMBER (superblock
))
17861 && BLOCK_FRAGMENT_CHAIN (superblock
))
17863 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
17864 / 2 / DWARF2_ADDR_SIZE
;
17865 unsigned long supercnt
= 0, thiscnt
= 0;
17866 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
17867 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
17870 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
17871 == BLOCK_NUMBER (chain
));
17873 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
17874 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
17875 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
17877 gcc_assert (supercnt
>= thiscnt
);
17878 add_AT_range_list (die
, DW_AT_ranges
,
17879 (off
+ supercnt
- thiscnt
)
17880 * 2 * DWARF2_ADDR_SIZE
);
17884 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
));
17886 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
17889 add_ranges (chain
);
17890 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
17897 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
17898 BLOCK_NUMBER (stmt
));
17899 add_AT_lbl_id (die
, DW_AT_low_pc
, label
);
17900 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
17901 BLOCK_NUMBER (stmt
));
17902 add_AT_lbl_id (die
, DW_AT_high_pc
, label
);
17906 /* Generate a DIE for a lexical block. */
17909 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
17911 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
17913 if (call_arg_locations
)
17915 if (VEC_length (dw_die_ref
, block_map
) <= BLOCK_NUMBER (stmt
))
17916 VEC_safe_grow_cleared (dw_die_ref
, heap
, block_map
,
17917 BLOCK_NUMBER (stmt
) + 1);
17918 VEC_replace (dw_die_ref
, block_map
, BLOCK_NUMBER (stmt
), stmt_die
);
17921 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
17922 add_high_low_attributes (stmt
, stmt_die
);
17924 decls_for_scope (stmt
, stmt_die
, depth
);
17927 /* Generate a DIE for an inlined subprogram. */
17930 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
17934 /* The instance of function that is effectively being inlined shall not
17936 gcc_assert (! BLOCK_ABSTRACT (stmt
));
17938 decl
= block_ultimate_origin (stmt
);
17939 if (DECL_IGNORED_P (decl
))
17942 /* Emit info for the abstract instance first, if we haven't yet. We
17943 must emit this even if the block is abstract, otherwise when we
17944 emit the block below (or elsewhere), we may end up trying to emit
17945 a die whose origin die hasn't been emitted, and crashing. */
17946 dwarf2out_abstract_function (decl
);
17948 if (! BLOCK_ABSTRACT (stmt
))
17950 dw_die_ref subr_die
17951 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
17953 if (call_arg_locations
)
17955 if (VEC_length (dw_die_ref
, block_map
) <= BLOCK_NUMBER (stmt
))
17956 VEC_safe_grow_cleared (dw_die_ref
, heap
, block_map
,
17957 BLOCK_NUMBER (stmt
) + 1);
17958 VEC_replace (dw_die_ref
, block_map
, BLOCK_NUMBER (stmt
), subr_die
);
17960 add_abstract_origin_attribute (subr_die
, decl
);
17961 if (TREE_ASM_WRITTEN (stmt
))
17962 add_high_low_attributes (stmt
, subr_die
);
17963 add_call_src_coords_attributes (stmt
, subr_die
);
17965 decls_for_scope (stmt
, subr_die
, depth
);
17966 current_function_has_inlines
= 1;
17970 /* Generate a DIE for a field in a record, or structure. */
17973 gen_field_die (tree decl
, dw_die_ref context_die
)
17975 dw_die_ref decl_die
;
17977 if (TREE_TYPE (decl
) == error_mark_node
)
17980 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
17981 add_name_and_src_coords_attributes (decl_die
, decl
);
17982 add_type_attribute (decl_die
, member_declared_type (decl
),
17983 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
17986 if (DECL_BIT_FIELD_TYPE (decl
))
17988 add_byte_size_attribute (decl_die
, decl
);
17989 add_bit_size_attribute (decl_die
, decl
);
17990 add_bit_offset_attribute (decl_die
, decl
);
17993 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
17994 add_data_member_location_attribute (decl_die
, decl
);
17996 if (DECL_ARTIFICIAL (decl
))
17997 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
17999 add_accessibility_attribute (decl_die
, decl
);
18001 /* Equate decl number to die, so that we can look up this decl later on. */
18002 equate_decl_number_to_die (decl
, decl_die
);
18006 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18007 Use modified_type_die instead.
18008 We keep this code here just in case these types of DIEs may be needed to
18009 represent certain things in other languages (e.g. Pascal) someday. */
18012 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
18015 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
18017 equate_type_number_to_die (type
, ptr_die
);
18018 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18019 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18022 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18023 Use modified_type_die instead.
18024 We keep this code here just in case these types of DIEs may be needed to
18025 represent certain things in other languages (e.g. Pascal) someday. */
18028 gen_reference_type_die (tree type
, dw_die_ref context_die
)
18030 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
18032 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
18033 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
18035 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
18037 equate_type_number_to_die (type
, ref_die
);
18038 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
18039 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18043 /* Generate a DIE for a pointer to a member type. */
18046 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
18049 = new_die (DW_TAG_ptr_to_member_type
,
18050 scope_die_for (type
, context_die
), type
);
18052 equate_type_number_to_die (type
, ptr_die
);
18053 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
18054 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
18055 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18058 typedef const char *dchar_p
; /* For DEF_VEC_P. */
18059 DEF_VEC_P(dchar_p
);
18060 DEF_VEC_ALLOC_P(dchar_p
,heap
);
18062 static char *producer_string
;
18064 /* Return a heap allocated producer string including command line options
18065 if -grecord-gcc-switches. */
18068 gen_producer_string (void)
18071 VEC(dchar_p
, heap
) *switches
= NULL
;
18072 const char *language_string
= lang_hooks
.name
;
18073 char *producer
, *tail
;
18075 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
18076 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
18078 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
18079 switch (save_decoded_options
[j
].opt_index
)
18086 case OPT_auxbase_strip
:
18095 case OPT_SPECIAL_unknown
:
18096 case OPT_SPECIAL_ignore
:
18097 case OPT_SPECIAL_program_name
:
18098 case OPT_SPECIAL_input_file
:
18099 case OPT_grecord_gcc_switches
:
18100 case OPT_gno_record_gcc_switches
:
18101 case OPT__output_pch_
:
18102 case OPT_fdiagnostics_show_location_
:
18103 case OPT_fdiagnostics_show_option
:
18104 case OPT_fdiagnostics_show_caret
:
18105 case OPT_fverbose_asm
:
18107 case OPT__sysroot_
:
18109 case OPT_nostdinc__
:
18110 /* Ignore these. */
18113 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
18115 switch (save_decoded_options
[j
].canonical_option
[0][1])
18122 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
18129 VEC_safe_push (dchar_p
, heap
, switches
,
18130 save_decoded_options
[j
].orig_option_with_args_text
);
18131 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
18135 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
18137 sprintf (tail
, "%s %s", language_string
, version_string
);
18140 FOR_EACH_VEC_ELT (dchar_p
, switches
, j
, p
)
18144 memcpy (tail
+ 1, p
, len
);
18149 VEC_free (dchar_p
, heap
, switches
);
18153 /* Generate the DIE for the compilation unit. */
18156 gen_compile_unit_die (const char *filename
)
18159 const char *language_string
= lang_hooks
.name
;
18162 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
18166 add_name_attribute (die
, filename
);
18167 /* Don't add cwd for <built-in>. */
18168 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
18169 add_comp_dir_attribute (die
);
18172 if (producer_string
== NULL
)
18173 producer_string
= gen_producer_string ();
18174 add_AT_string (die
, DW_AT_producer
, producer_string
);
18176 /* If our producer is LTO try to figure out a common language to use
18177 from the global list of translation units. */
18178 if (strcmp (language_string
, "GNU GIMPLE") == 0)
18182 const char *common_lang
= NULL
;
18184 FOR_EACH_VEC_ELT (tree
, all_translation_units
, i
, t
)
18186 if (!TRANSLATION_UNIT_LANGUAGE (t
))
18189 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
18190 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
18192 else if (strncmp (common_lang
, "GNU C", 5) == 0
18193 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
18194 /* Mixing C and C++ is ok, use C++ in that case. */
18195 common_lang
= "GNU C++";
18198 /* Fall back to C. */
18199 common_lang
= NULL
;
18205 language_string
= common_lang
;
18208 language
= DW_LANG_C89
;
18209 if (strcmp (language_string
, "GNU C++") == 0)
18210 language
= DW_LANG_C_plus_plus
;
18211 else if (strcmp (language_string
, "GNU F77") == 0)
18212 language
= DW_LANG_Fortran77
;
18213 else if (strcmp (language_string
, "GNU Pascal") == 0)
18214 language
= DW_LANG_Pascal83
;
18215 else if (dwarf_version
>= 3 || !dwarf_strict
)
18217 if (strcmp (language_string
, "GNU Ada") == 0)
18218 language
= DW_LANG_Ada95
;
18219 else if (strcmp (language_string
, "GNU Fortran") == 0)
18220 language
= DW_LANG_Fortran95
;
18221 else if (strcmp (language_string
, "GNU Java") == 0)
18222 language
= DW_LANG_Java
;
18223 else if (strcmp (language_string
, "GNU Objective-C") == 0)
18224 language
= DW_LANG_ObjC
;
18225 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
18226 language
= DW_LANG_ObjC_plus_plus
;
18227 else if (dwarf_version
>= 5 || !dwarf_strict
)
18229 if (strcmp (language_string
, "GNU Go") == 0)
18230 language
= DW_LANG_Go
;
18233 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
18234 else if (strcmp (language_string
, "GNU Fortran") == 0)
18235 language
= DW_LANG_Fortran90
;
18237 add_AT_unsigned (die
, DW_AT_language
, language
);
18241 case DW_LANG_Fortran77
:
18242 case DW_LANG_Fortran90
:
18243 case DW_LANG_Fortran95
:
18244 /* Fortran has case insensitive identifiers and the front-end
18245 lowercases everything. */
18246 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
18249 /* The default DW_ID_case_sensitive doesn't need to be specified. */
18255 /* Generate the DIE for a base class. */
18258 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
18260 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
18262 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
18263 add_data_member_location_attribute (die
, binfo
);
18265 if (BINFO_VIRTUAL_P (binfo
))
18266 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
18268 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18269 children, otherwise the default is DW_ACCESS_public. In DWARF2
18270 the default has always been DW_ACCESS_private. */
18271 if (access
== access_public_node
)
18273 if (dwarf_version
== 2
18274 || context_die
->die_tag
== DW_TAG_class_type
)
18275 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
18277 else if (access
== access_protected_node
)
18278 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
18279 else if (dwarf_version
> 2
18280 && context_die
->die_tag
!= DW_TAG_class_type
)
18281 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
18284 /* Generate a DIE for a class member. */
18287 gen_member_die (tree type
, dw_die_ref context_die
)
18290 tree binfo
= TYPE_BINFO (type
);
18293 /* If this is not an incomplete type, output descriptions of each of its
18294 members. Note that as we output the DIEs necessary to represent the
18295 members of this record or union type, we will also be trying to output
18296 DIEs to represent the *types* of those members. However the `type'
18297 function (above) will specifically avoid generating type DIEs for member
18298 types *within* the list of member DIEs for this (containing) type except
18299 for those types (of members) which are explicitly marked as also being
18300 members of this (containing) type themselves. The g++ front- end can
18301 force any given type to be treated as a member of some other (containing)
18302 type by setting the TYPE_CONTEXT of the given (member) type to point to
18303 the TREE node representing the appropriate (containing) type. */
18305 /* First output info about the base classes. */
18308 VEC(tree
,gc
) *accesses
= BINFO_BASE_ACCESSES (binfo
);
18312 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
18313 gen_inheritance_die (base
,
18314 (accesses
? VEC_index (tree
, accesses
, i
)
18315 : access_public_node
), context_die
);
18318 /* Now output info about the data members and type members. */
18319 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
18321 /* If we thought we were generating minimal debug info for TYPE
18322 and then changed our minds, some of the member declarations
18323 may have already been defined. Don't define them again, but
18324 do put them in the right order. */
18326 child
= lookup_decl_die (member
);
18328 splice_child_die (context_die
, child
);
18330 gen_decl_die (member
, NULL
, context_die
);
18333 /* Now output info about the function members (if any). */
18334 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
18336 /* Don't include clones in the member list. */
18337 if (DECL_ABSTRACT_ORIGIN (member
))
18340 child
= lookup_decl_die (member
);
18342 splice_child_die (context_die
, child
);
18344 gen_decl_die (member
, NULL
, context_die
);
18348 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
18349 is set, we pretend that the type was never defined, so we only get the
18350 member DIEs needed by later specification DIEs. */
18353 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
18354 enum debug_info_usage usage
)
18356 dw_die_ref type_die
= lookup_type_die (type
);
18357 dw_die_ref scope_die
= 0;
18359 int complete
= (TYPE_SIZE (type
)
18360 && (! TYPE_STUB_DECL (type
)
18361 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
18362 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
18363 complete
= complete
&& should_emit_struct_debug (type
, usage
);
18365 if (type_die
&& ! complete
)
18368 if (TYPE_CONTEXT (type
) != NULL_TREE
18369 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
18370 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
18373 scope_die
= scope_die_for (type
, context_die
);
18375 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
18376 /* First occurrence of type or toplevel definition of nested class. */
18378 dw_die_ref old_die
= type_die
;
18380 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
18381 ? record_type_tag (type
) : DW_TAG_union_type
,
18383 equate_type_number_to_die (type
, type_die
);
18385 add_AT_specification (type_die
, old_die
);
18387 add_name_attribute (type_die
, type_tag (type
));
18390 remove_AT (type_die
, DW_AT_declaration
);
18392 /* Generate child dies for template paramaters. */
18393 if (debug_info_level
> DINFO_LEVEL_TERSE
18394 && COMPLETE_TYPE_P (type
))
18395 schedule_generic_params_dies_gen (type
);
18397 /* If this type has been completed, then give it a byte_size attribute and
18398 then give a list of members. */
18399 if (complete
&& !ns_decl
)
18401 /* Prevent infinite recursion in cases where the type of some member of
18402 this type is expressed in terms of this type itself. */
18403 TREE_ASM_WRITTEN (type
) = 1;
18404 add_byte_size_attribute (type_die
, type
);
18405 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
18407 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
18408 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
18411 /* If the first reference to this type was as the return type of an
18412 inline function, then it may not have a parent. Fix this now. */
18413 if (type_die
->die_parent
== NULL
)
18414 add_child_die (scope_die
, type_die
);
18416 push_decl_scope (type
);
18417 gen_member_die (type
, type_die
);
18420 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
18421 if (TYPE_ARTIFICIAL (type
))
18422 add_AT_flag (type_die
, DW_AT_artificial
, 1);
18424 /* GNU extension: Record what type our vtable lives in. */
18425 if (TYPE_VFIELD (type
))
18427 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
18429 gen_type_die (vtype
, context_die
);
18430 add_AT_die_ref (type_die
, DW_AT_containing_type
,
18431 lookup_type_die (vtype
));
18436 add_AT_flag (type_die
, DW_AT_declaration
, 1);
18438 /* We don't need to do this for function-local types. */
18439 if (TYPE_STUB_DECL (type
)
18440 && ! decl_function_context (TYPE_STUB_DECL (type
)))
18441 VEC_safe_push (tree
, gc
, incomplete_types
, type
);
18444 if (get_AT (type_die
, DW_AT_name
))
18445 add_pubtype (type
, type_die
);
18448 /* Generate a DIE for a subroutine _type_. */
18451 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
18453 tree return_type
= TREE_TYPE (type
);
18454 dw_die_ref subr_die
18455 = new_die (DW_TAG_subroutine_type
,
18456 scope_die_for (type
, context_die
), type
);
18458 equate_type_number_to_die (type
, subr_die
);
18459 add_prototyped_attribute (subr_die
, type
);
18460 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
18461 gen_formal_types_die (type
, subr_die
);
18463 if (get_AT (subr_die
, DW_AT_name
))
18464 add_pubtype (type
, subr_die
);
18467 /* Generate a DIE for a type definition. */
18470 gen_typedef_die (tree decl
, dw_die_ref context_die
)
18472 dw_die_ref type_die
;
18475 if (TREE_ASM_WRITTEN (decl
))
18478 TREE_ASM_WRITTEN (decl
) = 1;
18479 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
18480 origin
= decl_ultimate_origin (decl
);
18481 if (origin
!= NULL
)
18482 add_abstract_origin_attribute (type_die
, origin
);
18487 add_name_and_src_coords_attributes (type_die
, decl
);
18488 if (DECL_ORIGINAL_TYPE (decl
))
18490 type
= DECL_ORIGINAL_TYPE (decl
);
18492 gcc_assert (type
!= TREE_TYPE (decl
));
18493 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
18497 type
= TREE_TYPE (decl
);
18499 if (is_naming_typedef_decl (TYPE_NAME (type
)))
18501 /* Here, we are in the case of decl being a typedef naming
18502 an anonymous type, e.g:
18503 typedef struct {...} foo;
18504 In that case TREE_TYPE (decl) is not a typedef variant
18505 type and TYPE_NAME of the anonymous type is set to the
18506 TYPE_DECL of the typedef. This construct is emitted by
18509 TYPE is the anonymous struct named by the typedef
18510 DECL. As we need the DW_AT_type attribute of the
18511 DW_TAG_typedef to point to the DIE of TYPE, let's
18512 generate that DIE right away. add_type_attribute
18513 called below will then pick (via lookup_type_die) that
18514 anonymous struct DIE. */
18515 if (!TREE_ASM_WRITTEN (type
))
18516 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
18518 /* This is a GNU Extension. We are adding a
18519 DW_AT_linkage_name attribute to the DIE of the
18520 anonymous struct TYPE. The value of that attribute
18521 is the name of the typedef decl naming the anonymous
18522 struct. This greatly eases the work of consumers of
18523 this debug info. */
18524 add_linkage_attr (lookup_type_die (type
), decl
);
18528 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
18529 TREE_THIS_VOLATILE (decl
), context_die
);
18531 if (is_naming_typedef_decl (decl
))
18532 /* We want that all subsequent calls to lookup_type_die with
18533 TYPE in argument yield the DW_TAG_typedef we have just
18535 equate_type_number_to_die (type
, type_die
);
18537 add_accessibility_attribute (type_die
, decl
);
18540 if (DECL_ABSTRACT (decl
))
18541 equate_decl_number_to_die (decl
, type_die
);
18543 if (get_AT (type_die
, DW_AT_name
))
18544 add_pubtype (decl
, type_die
);
18547 /* Generate a DIE for a struct, class, enum or union type. */
18550 gen_tagged_type_die (tree type
,
18551 dw_die_ref context_die
,
18552 enum debug_info_usage usage
)
18556 if (type
== NULL_TREE
18557 || !is_tagged_type (type
))
18560 /* If this is a nested type whose containing class hasn't been written
18561 out yet, writing it out will cover this one, too. This does not apply
18562 to instantiations of member class templates; they need to be added to
18563 the containing class as they are generated. FIXME: This hurts the
18564 idea of combining type decls from multiple TUs, since we can't predict
18565 what set of template instantiations we'll get. */
18566 if (TYPE_CONTEXT (type
)
18567 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
18568 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
18570 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
18572 if (TREE_ASM_WRITTEN (type
))
18575 /* If that failed, attach ourselves to the stub. */
18576 push_decl_scope (TYPE_CONTEXT (type
));
18577 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
18580 else if (TYPE_CONTEXT (type
) != NULL_TREE
18581 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
18583 /* If this type is local to a function that hasn't been written
18584 out yet, use a NULL context for now; it will be fixed up in
18585 decls_for_scope. */
18586 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
18587 /* A declaration DIE doesn't count; nested types need to go in the
18589 if (context_die
&& is_declaration_die (context_die
))
18590 context_die
= NULL
;
18595 context_die
= declare_in_namespace (type
, context_die
);
18599 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
18601 /* This might have been written out by the call to
18602 declare_in_namespace. */
18603 if (!TREE_ASM_WRITTEN (type
))
18604 gen_enumeration_type_die (type
, context_die
);
18607 gen_struct_or_union_type_die (type
, context_die
, usage
);
18612 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
18613 it up if it is ever completed. gen_*_type_die will set it for us
18614 when appropriate. */
18617 /* Generate a type description DIE. */
18620 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
18621 enum debug_info_usage usage
)
18623 struct array_descr_info info
;
18625 if (type
== NULL_TREE
|| type
== error_mark_node
)
18628 if (TYPE_NAME (type
) != NULL_TREE
18629 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
18630 && is_redundant_typedef (TYPE_NAME (type
))
18631 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
18632 /* The DECL of this type is a typedef we don't want to emit debug
18633 info for but we want debug info for its underlying typedef.
18634 This can happen for e.g, the injected-class-name of a C++
18636 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
18638 /* If TYPE is a typedef type variant, let's generate debug info
18639 for the parent typedef which TYPE is a type of. */
18640 if (typedef_variant_p (type
))
18642 if (TREE_ASM_WRITTEN (type
))
18645 /* Prevent broken recursion; we can't hand off to the same type. */
18646 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
18648 /* Give typedefs the right scope. */
18649 context_die
= scope_die_for (type
, context_die
);
18651 TREE_ASM_WRITTEN (type
) = 1;
18653 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
18657 /* If type is an anonymous tagged type named by a typedef, let's
18658 generate debug info for the typedef. */
18659 if (is_naming_typedef_decl (TYPE_NAME (type
)))
18661 /* Use the DIE of the containing namespace as the parent DIE of
18662 the type description DIE we want to generate. */
18663 if (DECL_CONTEXT (TYPE_NAME (type
))
18664 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
18665 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
18667 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
18671 /* If this is an array type with hidden descriptor, handle it first. */
18672 if (!TREE_ASM_WRITTEN (type
)
18673 && lang_hooks
.types
.get_array_descr_info
18674 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
18675 && (dwarf_version
>= 3 || !dwarf_strict
))
18677 gen_descr_array_type_die (type
, &info
, context_die
);
18678 TREE_ASM_WRITTEN (type
) = 1;
18682 /* We are going to output a DIE to represent the unqualified version
18683 of this type (i.e. without any const or volatile qualifiers) so
18684 get the main variant (i.e. the unqualified version) of this type
18685 now. (Vectors are special because the debugging info is in the
18686 cloned type itself). */
18687 if (TREE_CODE (type
) != VECTOR_TYPE
)
18688 type
= type_main_variant (type
);
18690 if (TREE_ASM_WRITTEN (type
))
18693 switch (TREE_CODE (type
))
18699 case REFERENCE_TYPE
:
18700 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
18701 ensures that the gen_type_die recursion will terminate even if the
18702 type is recursive. Recursive types are possible in Ada. */
18703 /* ??? We could perhaps do this for all types before the switch
18705 TREE_ASM_WRITTEN (type
) = 1;
18707 /* For these types, all that is required is that we output a DIE (or a
18708 set of DIEs) to represent the "basis" type. */
18709 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18710 DINFO_USAGE_IND_USE
);
18714 /* This code is used for C++ pointer-to-data-member types.
18715 Output a description of the relevant class type. */
18716 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
18717 DINFO_USAGE_IND_USE
);
18719 /* Output a description of the type of the object pointed to. */
18720 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18721 DINFO_USAGE_IND_USE
);
18723 /* Now output a DIE to represent this pointer-to-data-member type
18725 gen_ptr_to_mbr_type_die (type
, context_die
);
18728 case FUNCTION_TYPE
:
18729 /* Force out return type (in case it wasn't forced out already). */
18730 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18731 DINFO_USAGE_DIR_USE
);
18732 gen_subroutine_type_die (type
, context_die
);
18736 /* Force out return type (in case it wasn't forced out already). */
18737 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18738 DINFO_USAGE_DIR_USE
);
18739 gen_subroutine_type_die (type
, context_die
);
18743 gen_array_type_die (type
, context_die
);
18747 gen_array_type_die (type
, context_die
);
18750 case ENUMERAL_TYPE
:
18753 case QUAL_UNION_TYPE
:
18754 gen_tagged_type_die (type
, context_die
, usage
);
18760 case FIXED_POINT_TYPE
:
18763 /* No DIEs needed for fundamental types. */
18768 /* Just use DW_TAG_unspecified_type. */
18770 dw_die_ref type_die
= lookup_type_die (type
);
18771 if (type_die
== NULL
)
18773 tree name
= TYPE_NAME (type
);
18774 if (TREE_CODE (name
) == TYPE_DECL
)
18775 name
= DECL_NAME (name
);
18776 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
18777 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
18778 equate_type_number_to_die (type
, type_die
);
18784 gcc_unreachable ();
18787 TREE_ASM_WRITTEN (type
) = 1;
18791 gen_type_die (tree type
, dw_die_ref context_die
)
18793 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
18796 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
18797 things which are local to the given block. */
18800 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
18802 int must_output_die
= 0;
18805 /* Ignore blocks that are NULL. */
18806 if (stmt
== NULL_TREE
)
18809 inlined_func
= inlined_function_outer_scope_p (stmt
);
18811 /* If the block is one fragment of a non-contiguous block, do not
18812 process the variables, since they will have been done by the
18813 origin block. Do process subblocks. */
18814 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
18818 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
18819 gen_block_die (sub
, context_die
, depth
+ 1);
18824 /* Determine if we need to output any Dwarf DIEs at all to represent this
18827 /* The outer scopes for inlinings *must* always be represented. We
18828 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
18829 must_output_die
= 1;
18832 /* Determine if this block directly contains any "significant"
18833 local declarations which we will need to output DIEs for. */
18834 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18835 /* We are not in terse mode so *any* local declaration counts
18836 as being a "significant" one. */
18837 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
18838 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
18839 && (TREE_USED (stmt
)
18840 || TREE_ASM_WRITTEN (stmt
)
18841 || BLOCK_ABSTRACT (stmt
)));
18842 else if ((TREE_USED (stmt
)
18843 || TREE_ASM_WRITTEN (stmt
)
18844 || BLOCK_ABSTRACT (stmt
))
18845 && !dwarf2out_ignore_block (stmt
))
18846 must_output_die
= 1;
18849 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
18850 DIE for any block which contains no significant local declarations at
18851 all. Rather, in such cases we just call `decls_for_scope' so that any
18852 needed Dwarf info for any sub-blocks will get properly generated. Note
18853 that in terse mode, our definition of what constitutes a "significant"
18854 local declaration gets restricted to include only inlined function
18855 instances and local (nested) function definitions. */
18856 if (must_output_die
)
18860 /* If STMT block is abstract, that means we have been called
18861 indirectly from dwarf2out_abstract_function.
18862 That function rightfully marks the descendent blocks (of
18863 the abstract function it is dealing with) as being abstract,
18864 precisely to prevent us from emitting any
18865 DW_TAG_inlined_subroutine DIE as a descendent
18866 of an abstract function instance. So in that case, we should
18867 not call gen_inlined_subroutine_die.
18869 Later though, when cgraph asks dwarf2out to emit info
18870 for the concrete instance of the function decl into which
18871 the concrete instance of STMT got inlined, the later will lead
18872 to the generation of a DW_TAG_inlined_subroutine DIE. */
18873 if (! BLOCK_ABSTRACT (stmt
))
18874 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
18877 gen_lexical_block_die (stmt
, context_die
, depth
);
18880 decls_for_scope (stmt
, context_die
, depth
);
18883 /* Process variable DECL (or variable with origin ORIGIN) within
18884 block STMT and add it to CONTEXT_DIE. */
18887 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
18890 tree decl_or_origin
= decl
? decl
: origin
;
18892 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
18893 die
= lookup_decl_die (decl_or_origin
);
18894 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
18895 && TYPE_DECL_IS_STUB (decl_or_origin
))
18896 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
18900 if (die
!= NULL
&& die
->die_parent
== NULL
)
18901 add_child_die (context_die
, die
);
18902 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
18903 dwarf2out_imported_module_or_decl_1 (decl_or_origin
,
18904 DECL_NAME (decl_or_origin
),
18905 stmt
, context_die
);
18906 /* Do not emit concrete instances of abstracted nested functions within
18907 concrete instances of parent functions. */
18908 else if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
18910 && get_AT (die
, DW_AT_inline
))
18913 gen_decl_die (decl
, origin
, context_die
);
18916 /* Generate all of the decls declared within a given scope and (recursively)
18917 all of its sub-blocks. */
18920 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
18926 /* Ignore NULL blocks. */
18927 if (stmt
== NULL_TREE
)
18930 /* Output the DIEs to represent all of the data objects and typedefs
18931 declared directly within this block but not within any nested
18932 sub-blocks. Also, nested function and tag DIEs have been
18933 generated with a parent of NULL; fix that up now. */
18934 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
18935 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
18936 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
18937 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
18940 /* If we're at -g1, we're not interested in subblocks. */
18941 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
18944 /* Output the DIEs to represent all sub-blocks (and the items declared
18945 therein) of this block. */
18946 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
18948 subblocks
= BLOCK_CHAIN (subblocks
))
18949 gen_block_die (subblocks
, context_die
, depth
+ 1);
18952 /* Is this a typedef we can avoid emitting? */
18955 is_redundant_typedef (const_tree decl
)
18957 if (TYPE_DECL_IS_STUB (decl
))
18960 if (DECL_ARTIFICIAL (decl
)
18961 && DECL_CONTEXT (decl
)
18962 && is_tagged_type (DECL_CONTEXT (decl
))
18963 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
18964 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
18965 /* Also ignore the artificial member typedef for the class name. */
18971 /* Return TRUE if TYPE is a typedef that names a type for linkage
18972 purposes. This kind of typedefs is produced by the C++ FE for
18975 typedef struct {...} foo;
18977 In that case, there is no typedef variant type produced for foo.
18978 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
18982 is_naming_typedef_decl (const_tree decl
)
18984 if (decl
== NULL_TREE
18985 || TREE_CODE (decl
) != TYPE_DECL
18986 || !is_tagged_type (TREE_TYPE (decl
))
18987 || DECL_IS_BUILTIN (decl
)
18988 || is_redundant_typedef (decl
)
18989 /* It looks like Ada produces TYPE_DECLs that are very similar
18990 to C++ naming typedefs but that have different
18991 semantics. Let's be specific to c++ for now. */
18995 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
18996 && TYPE_NAME (TREE_TYPE (decl
)) == decl
18997 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
18998 != TYPE_NAME (TREE_TYPE (decl
))));
19001 /* Returns the DIE for a context. */
19003 static inline dw_die_ref
19004 get_context_die (tree context
)
19008 /* Find die that represents this context. */
19009 if (TYPE_P (context
))
19011 context
= TYPE_MAIN_VARIANT (context
);
19012 return strip_naming_typedef (context
, force_type_die (context
));
19015 return force_decl_die (context
);
19017 return comp_unit_die ();
19020 /* Returns the DIE for decl. A DIE will always be returned. */
19023 force_decl_die (tree decl
)
19025 dw_die_ref decl_die
;
19026 unsigned saved_external_flag
;
19027 tree save_fn
= NULL_TREE
;
19028 decl_die
= lookup_decl_die (decl
);
19031 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
19033 decl_die
= lookup_decl_die (decl
);
19037 switch (TREE_CODE (decl
))
19039 case FUNCTION_DECL
:
19040 /* Clear current_function_decl, so that gen_subprogram_die thinks
19041 that this is a declaration. At this point, we just want to force
19042 declaration die. */
19043 save_fn
= current_function_decl
;
19044 current_function_decl
= NULL_TREE
;
19045 gen_subprogram_die (decl
, context_die
);
19046 current_function_decl
= save_fn
;
19050 /* Set external flag to force declaration die. Restore it after
19051 gen_decl_die() call. */
19052 saved_external_flag
= DECL_EXTERNAL (decl
);
19053 DECL_EXTERNAL (decl
) = 1;
19054 gen_decl_die (decl
, NULL
, context_die
);
19055 DECL_EXTERNAL (decl
) = saved_external_flag
;
19058 case NAMESPACE_DECL
:
19059 if (dwarf_version
>= 3 || !dwarf_strict
)
19060 dwarf2out_decl (decl
);
19062 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19063 decl_die
= comp_unit_die ();
19066 case TRANSLATION_UNIT_DECL
:
19067 decl_die
= comp_unit_die ();
19071 gcc_unreachable ();
19074 /* We should be able to find the DIE now. */
19076 decl_die
= lookup_decl_die (decl
);
19077 gcc_assert (decl_die
);
19083 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
19084 always returned. */
19087 force_type_die (tree type
)
19089 dw_die_ref type_die
;
19091 type_die
= lookup_type_die (type
);
19094 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
19096 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
19097 TYPE_VOLATILE (type
), context_die
);
19098 gcc_assert (type_die
);
19103 /* Force out any required namespaces to be able to output DECL,
19104 and return the new context_die for it, if it's changed. */
19107 setup_namespace_context (tree thing
, dw_die_ref context_die
)
19109 tree context
= (DECL_P (thing
)
19110 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
19111 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
19112 /* Force out the namespace. */
19113 context_die
= force_decl_die (context
);
19115 return context_die
;
19118 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
19119 type) within its namespace, if appropriate.
19121 For compatibility with older debuggers, namespace DIEs only contain
19122 declarations; all definitions are emitted at CU scope. */
19125 declare_in_namespace (tree thing
, dw_die_ref context_die
)
19127 dw_die_ref ns_context
;
19129 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19130 return context_die
;
19132 /* If this decl is from an inlined function, then don't try to emit it in its
19133 namespace, as we will get confused. It would have already been emitted
19134 when the abstract instance of the inline function was emitted anyways. */
19135 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
19136 return context_die
;
19138 ns_context
= setup_namespace_context (thing
, context_die
);
19140 if (ns_context
!= context_die
)
19144 if (DECL_P (thing
))
19145 gen_decl_die (thing
, NULL
, ns_context
);
19147 gen_type_die (thing
, ns_context
);
19149 return context_die
;
19152 /* Generate a DIE for a namespace or namespace alias. */
19155 gen_namespace_die (tree decl
, dw_die_ref context_die
)
19157 dw_die_ref namespace_die
;
19159 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
19160 they are an alias of. */
19161 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
19163 /* Output a real namespace or module. */
19164 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19165 namespace_die
= new_die (is_fortran ()
19166 ? DW_TAG_module
: DW_TAG_namespace
,
19167 context_die
, decl
);
19168 /* For Fortran modules defined in different CU don't add src coords. */
19169 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
19171 const char *name
= dwarf2_name (decl
, 0);
19173 add_name_attribute (namespace_die
, name
);
19176 add_name_and_src_coords_attributes (namespace_die
, decl
);
19177 if (DECL_EXTERNAL (decl
))
19178 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
19179 equate_decl_number_to_die (decl
, namespace_die
);
19183 /* Output a namespace alias. */
19185 /* Force out the namespace we are an alias of, if necessary. */
19186 dw_die_ref origin_die
19187 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
19189 if (DECL_FILE_SCOPE_P (decl
)
19190 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
19191 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19192 /* Now create the namespace alias DIE. */
19193 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
19194 add_name_and_src_coords_attributes (namespace_die
, decl
);
19195 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
19196 equate_decl_number_to_die (decl
, namespace_die
);
19198 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
19199 if (want_pubnames ())
19200 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
19203 /* Generate Dwarf debug information for a decl described by DECL.
19204 The return value is currently only meaningful for PARM_DECLs,
19205 for all other decls it returns NULL. */
19208 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
19210 tree decl_or_origin
= decl
? decl
: origin
;
19211 tree class_origin
= NULL
, ultimate_origin
;
19213 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
19216 switch (TREE_CODE (decl_or_origin
))
19222 if (!is_fortran () && !is_ada ())
19224 /* The individual enumerators of an enum type get output when we output
19225 the Dwarf representation of the relevant enum type itself. */
19229 /* Emit its type. */
19230 gen_type_die (TREE_TYPE (decl
), context_die
);
19232 /* And its containing namespace. */
19233 context_die
= declare_in_namespace (decl
, context_die
);
19235 gen_const_die (decl
, context_die
);
19238 case FUNCTION_DECL
:
19239 /* Don't output any DIEs to represent mere function declarations,
19240 unless they are class members or explicit block externs. */
19241 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
19242 && DECL_FILE_SCOPE_P (decl_or_origin
)
19243 && (current_function_decl
== NULL_TREE
19244 || DECL_ARTIFICIAL (decl_or_origin
)))
19249 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
19250 on local redeclarations of global functions. That seems broken. */
19251 if (current_function_decl
!= decl
)
19252 /* This is only a declaration. */;
19255 /* If we're emitting a clone, emit info for the abstract instance. */
19256 if (origin
|| DECL_ORIGIN (decl
) != decl
)
19257 dwarf2out_abstract_function (origin
19258 ? DECL_ORIGIN (origin
)
19259 : DECL_ABSTRACT_ORIGIN (decl
));
19261 /* If we're emitting an out-of-line copy of an abstracted function,
19262 emit info for the abstract instance and set up to refer to it. */
19263 else if (!DECL_ABSTRACT (decl
)
19264 && function_possibly_abstracted_p (decl
)
19265 && !class_or_namespace_scope_p (context_die
)
19266 /* dwarf2out_abstract_function won't emit a die if this is just
19267 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
19268 that case, because that works only if we have a die. */
19269 && DECL_INITIAL (decl
) != NULL_TREE
)
19271 dwarf2out_abstract_function (decl
);
19272 set_decl_origin_self (decl
);
19275 /* Otherwise we're emitting the primary DIE for this decl. */
19276 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
19278 /* Before we describe the FUNCTION_DECL itself, make sure that we
19279 have its containing type. */
19281 origin
= decl_class_context (decl
);
19282 if (origin
!= NULL_TREE
)
19283 gen_type_die (origin
, context_die
);
19285 /* And its return type. */
19286 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
19288 /* And its virtual context. */
19289 if (DECL_VINDEX (decl
) != NULL_TREE
)
19290 gen_type_die (DECL_CONTEXT (decl
), context_die
);
19292 /* Make sure we have a member DIE for decl. */
19293 if (origin
!= NULL_TREE
)
19294 gen_type_die_for_member (origin
, decl
, context_die
);
19296 /* And its containing namespace. */
19297 context_die
= declare_in_namespace (decl
, context_die
);
19300 /* Now output a DIE to represent the function itself. */
19302 gen_subprogram_die (decl
, context_die
);
19306 /* If we are in terse mode, don't generate any DIEs to represent any
19307 actual typedefs. */
19308 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19311 /* In the special case of a TYPE_DECL node representing the declaration
19312 of some type tag, if the given TYPE_DECL is marked as having been
19313 instantiated from some other (original) TYPE_DECL node (e.g. one which
19314 was generated within the original definition of an inline function) we
19315 used to generate a special (abbreviated) DW_TAG_structure_type,
19316 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
19317 should be actually referencing those DIEs, as variable DIEs with that
19318 type would be emitted already in the abstract origin, so it was always
19319 removed during unused type prunning. Don't add anything in this
19321 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
19324 if (is_redundant_typedef (decl
))
19325 gen_type_die (TREE_TYPE (decl
), context_die
);
19327 /* Output a DIE to represent the typedef itself. */
19328 gen_typedef_die (decl
, context_die
);
19332 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
19333 gen_label_die (decl
, context_die
);
19338 /* If we are in terse mode, don't generate any DIEs to represent any
19339 variable declarations or definitions. */
19340 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19343 /* Output any DIEs that are needed to specify the type of this data
19345 if (decl_by_reference_p (decl_or_origin
))
19346 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
19348 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
19350 /* And its containing type. */
19351 class_origin
= decl_class_context (decl_or_origin
);
19352 if (class_origin
!= NULL_TREE
)
19353 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
19355 /* And its containing namespace. */
19356 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
19358 /* Now output the DIE to represent the data object itself. This gets
19359 complicated because of the possibility that the VAR_DECL really
19360 represents an inlined instance of a formal parameter for an inline
19362 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
19363 if (ultimate_origin
!= NULL_TREE
19364 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
19365 gen_formal_parameter_die (decl
, origin
,
19366 true /* Emit name attribute. */,
19369 gen_variable_die (decl
, origin
, context_die
);
19373 /* Ignore the nameless fields that are used to skip bits but handle C++
19374 anonymous unions and structs. */
19375 if (DECL_NAME (decl
) != NULL_TREE
19376 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
19377 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
19379 gen_type_die (member_declared_type (decl
), context_die
);
19380 gen_field_die (decl
, context_die
);
19385 if (DECL_BY_REFERENCE (decl_or_origin
))
19386 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
19388 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
19389 return gen_formal_parameter_die (decl
, origin
,
19390 true /* Emit name attribute. */,
19393 case NAMESPACE_DECL
:
19394 case IMPORTED_DECL
:
19395 if (dwarf_version
>= 3 || !dwarf_strict
)
19396 gen_namespace_die (decl
, context_die
);
19400 /* Probably some frontend-internal decl. Assume we don't care. */
19401 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
19408 /* Output debug information for global decl DECL. Called from toplev.c after
19409 compilation proper has finished. */
19412 dwarf2out_global_decl (tree decl
)
19414 /* Output DWARF2 information for file-scope tentative data object
19415 declarations, file-scope (extern) function declarations (which
19416 had no corresponding body) and file-scope tagged type declarations
19417 and definitions which have not yet been forced out. */
19418 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
19419 dwarf2out_decl (decl
);
19422 /* Output debug information for type decl DECL. Called from toplev.c
19423 and from language front ends (to record built-in types). */
19425 dwarf2out_type_decl (tree decl
, int local
)
19428 dwarf2out_decl (decl
);
19431 /* Output debug information for imported module or decl DECL.
19432 NAME is non-NULL name in the lexical block if the decl has been renamed.
19433 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
19434 that DECL belongs to.
19435 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
19437 dwarf2out_imported_module_or_decl_1 (tree decl
,
19439 tree lexical_block
,
19440 dw_die_ref lexical_block_die
)
19442 expanded_location xloc
;
19443 dw_die_ref imported_die
= NULL
;
19444 dw_die_ref at_import_die
;
19446 if (TREE_CODE (decl
) == IMPORTED_DECL
)
19448 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
19449 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
19453 xloc
= expand_location (input_location
);
19455 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
19457 at_import_die
= force_type_die (TREE_TYPE (decl
));
19458 /* For namespace N { typedef void T; } using N::T; base_type_die
19459 returns NULL, but DW_TAG_imported_declaration requires
19460 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
19461 if (!at_import_die
)
19463 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
19464 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
19465 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
19466 gcc_assert (at_import_die
);
19471 at_import_die
= lookup_decl_die (decl
);
19472 if (!at_import_die
)
19474 /* If we're trying to avoid duplicate debug info, we may not have
19475 emitted the member decl for this field. Emit it now. */
19476 if (TREE_CODE (decl
) == FIELD_DECL
)
19478 tree type
= DECL_CONTEXT (decl
);
19480 if (TYPE_CONTEXT (type
)
19481 && TYPE_P (TYPE_CONTEXT (type
))
19482 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
19483 DINFO_USAGE_DIR_USE
))
19485 gen_type_die_for_member (type
, decl
,
19486 get_context_die (TYPE_CONTEXT (type
)));
19488 at_import_die
= force_decl_die (decl
);
19492 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
19494 if (dwarf_version
>= 3 || !dwarf_strict
)
19495 imported_die
= new_die (DW_TAG_imported_module
,
19502 imported_die
= new_die (DW_TAG_imported_declaration
,
19506 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
19507 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
19509 add_AT_string (imported_die
, DW_AT_name
,
19510 IDENTIFIER_POINTER (name
));
19511 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
19514 /* Output debug information for imported module or decl DECL.
19515 NAME is non-NULL name in context if the decl has been renamed.
19516 CHILD is true if decl is one of the renamed decls as part of
19517 importing whole module. */
19520 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
19523 /* dw_die_ref at_import_die; */
19524 dw_die_ref scope_die
;
19526 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19531 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
19532 We need decl DIE for reference and scope die. First, get DIE for the decl
19535 /* Get the scope die for decl context. Use comp_unit_die for global module
19536 or decl. If die is not found for non globals, force new die. */
19538 && TYPE_P (context
)
19539 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
19542 if (!(dwarf_version
>= 3 || !dwarf_strict
))
19545 scope_die
= get_context_die (context
);
19549 gcc_assert (scope_die
->die_child
);
19550 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
19551 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
19552 scope_die
= scope_die
->die_child
;
19555 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
19556 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
19560 /* Write the debugging output for DECL. */
19563 dwarf2out_decl (tree decl
)
19565 dw_die_ref context_die
= comp_unit_die ();
19567 switch (TREE_CODE (decl
))
19572 case FUNCTION_DECL
:
19573 /* What we would really like to do here is to filter out all mere
19574 file-scope declarations of file-scope functions which are never
19575 referenced later within this translation unit (and keep all of ones
19576 that *are* referenced later on) but we aren't clairvoyant, so we have
19577 no idea which functions will be referenced in the future (i.e. later
19578 on within the current translation unit). So here we just ignore all
19579 file-scope function declarations which are not also definitions. If
19580 and when the debugger needs to know something about these functions,
19581 it will have to hunt around and find the DWARF information associated
19582 with the definition of the function.
19584 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
19585 nodes represent definitions and which ones represent mere
19586 declarations. We have to check DECL_INITIAL instead. That's because
19587 the C front-end supports some weird semantics for "extern inline"
19588 function definitions. These can get inlined within the current
19589 translation unit (and thus, we need to generate Dwarf info for their
19590 abstract instances so that the Dwarf info for the concrete inlined
19591 instances can have something to refer to) but the compiler never
19592 generates any out-of-lines instances of such things (despite the fact
19593 that they *are* definitions).
19595 The important point is that the C front-end marks these "extern
19596 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
19597 them anyway. Note that the C++ front-end also plays some similar games
19598 for inline function definitions appearing within include files which
19599 also contain `#pragma interface' pragmas. */
19600 if (DECL_INITIAL (decl
) == NULL_TREE
)
19603 /* If we're a nested function, initially use a parent of NULL; if we're
19604 a plain function, this will be fixed up in decls_for_scope. If
19605 we're a method, it will be ignored, since we already have a DIE. */
19606 if (decl_function_context (decl
)
19607 /* But if we're in terse mode, we don't care about scope. */
19608 && debug_info_level
> DINFO_LEVEL_TERSE
)
19609 context_die
= NULL
;
19613 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
19614 declaration and if the declaration was never even referenced from
19615 within this entire compilation unit. We suppress these DIEs in
19616 order to save space in the .debug section (by eliminating entries
19617 which are probably useless). Note that we must not suppress
19618 block-local extern declarations (whether used or not) because that
19619 would screw-up the debugger's name lookup mechanism and cause it to
19620 miss things which really ought to be in scope at a given point. */
19621 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
19624 /* For local statics lookup proper context die. */
19625 if (TREE_STATIC (decl
)
19626 && DECL_CONTEXT (decl
)
19627 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
19628 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
19630 /* If we are in terse mode, don't generate any DIEs to represent any
19631 variable declarations or definitions. */
19632 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19637 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19639 if (!is_fortran () && !is_ada ())
19641 if (TREE_STATIC (decl
) && decl_function_context (decl
))
19642 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
19645 case NAMESPACE_DECL
:
19646 case IMPORTED_DECL
:
19647 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19649 if (lookup_decl_die (decl
) != NULL
)
19654 /* Don't emit stubs for types unless they are needed by other DIEs. */
19655 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
19658 /* Don't bother trying to generate any DIEs to represent any of the
19659 normal built-in types for the language we are compiling. */
19660 if (DECL_IS_BUILTIN (decl
))
19663 /* If we are in terse mode, don't generate any DIEs for types. */
19664 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19667 /* If we're a function-scope tag, initially use a parent of NULL;
19668 this will be fixed up in decls_for_scope. */
19669 if (decl_function_context (decl
))
19670 context_die
= NULL
;
19678 gen_decl_die (decl
, NULL
, context_die
);
19681 /* Write the debugging output for DECL. */
19684 dwarf2out_function_decl (tree decl
)
19686 dwarf2out_decl (decl
);
19687 call_arg_locations
= NULL
;
19688 call_arg_loc_last
= NULL
;
19689 call_site_count
= -1;
19690 tail_call_site_count
= -1;
19691 VEC_free (dw_die_ref
, heap
, block_map
);
19692 htab_empty (decl_loc_table
);
19693 htab_empty (cached_dw_loc_list_table
);
19696 /* Output a marker (i.e. a label) for the beginning of the generated code for
19697 a lexical block. */
19700 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
19701 unsigned int blocknum
)
19703 switch_to_section (current_function_section ());
19704 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
19707 /* Output a marker (i.e. a label) for the end of the generated code for a
19711 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
19713 switch_to_section (current_function_section ());
19714 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
19717 /* Returns nonzero if it is appropriate not to emit any debugging
19718 information for BLOCK, because it doesn't contain any instructions.
19720 Don't allow this for blocks with nested functions or local classes
19721 as we would end up with orphans, and in the presence of scheduling
19722 we may end up calling them anyway. */
19725 dwarf2out_ignore_block (const_tree block
)
19730 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
19731 if (TREE_CODE (decl
) == FUNCTION_DECL
19732 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
19734 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
19736 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
19737 if (TREE_CODE (decl
) == FUNCTION_DECL
19738 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
19745 /* Hash table routines for file_hash. */
19748 file_table_eq (const void *p1_p
, const void *p2_p
)
19750 const struct dwarf_file_data
*const p1
=
19751 (const struct dwarf_file_data
*) p1_p
;
19752 const char *const p2
= (const char *) p2_p
;
19753 return filename_cmp (p1
->filename
, p2
) == 0;
19757 file_table_hash (const void *p_p
)
19759 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
19760 return htab_hash_string (p
->filename
);
19763 /* Lookup FILE_NAME (in the list of filenames that we know about here in
19764 dwarf2out.c) and return its "index". The index of each (known) filename is
19765 just a unique number which is associated with only that one filename. We
19766 need such numbers for the sake of generating labels (in the .debug_sfnames
19767 section) and references to those files numbers (in the .debug_srcinfo
19768 and.debug_macinfo sections). If the filename given as an argument is not
19769 found in our current list, add it to the list and assign it the next
19770 available unique index number. In order to speed up searches, we remember
19771 the index of the filename was looked up last. This handles the majority of
19774 static struct dwarf_file_data
*
19775 lookup_filename (const char *file_name
)
19778 struct dwarf_file_data
* created
;
19780 /* Check to see if the file name that was searched on the previous
19781 call matches this file name. If so, return the index. */
19782 if (file_table_last_lookup
19783 && (file_name
== file_table_last_lookup
->filename
19784 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
19785 return file_table_last_lookup
;
19787 /* Didn't match the previous lookup, search the table. */
19788 slot
= htab_find_slot_with_hash (file_table
, file_name
,
19789 htab_hash_string (file_name
), INSERT
);
19791 return (struct dwarf_file_data
*) *slot
;
19793 created
= ggc_alloc_dwarf_file_data ();
19794 created
->filename
= file_name
;
19795 created
->emitted_number
= 0;
19800 /* If the assembler will construct the file table, then translate the compiler
19801 internal file table number into the assembler file table number, and emit
19802 a .file directive if we haven't already emitted one yet. The file table
19803 numbers are different because we prune debug info for unused variables and
19804 types, which may include filenames. */
19807 maybe_emit_file (struct dwarf_file_data
* fd
)
19809 if (! fd
->emitted_number
)
19811 if (last_emitted_file
)
19812 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
19814 fd
->emitted_number
= 1;
19815 last_emitted_file
= fd
;
19817 if (DWARF2_ASM_LINE_DEBUG_INFO
)
19819 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
19820 output_quoted_string (asm_out_file
,
19821 remap_debug_filename (fd
->filename
));
19822 fputc ('\n', asm_out_file
);
19826 return fd
->emitted_number
;
19829 /* Schedule generation of a DW_AT_const_value attribute to DIE.
19830 That generation should happen after function debug info has been
19831 generated. The value of the attribute is the constant value of ARG. */
19834 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
19836 die_arg_entry entry
;
19841 if (!tmpl_value_parm_die_table
)
19842 tmpl_value_parm_die_table
19843 = VEC_alloc (die_arg_entry
, gc
, 32);
19847 VEC_safe_push (die_arg_entry
, gc
,
19848 tmpl_value_parm_die_table
,
19852 /* Return TRUE if T is an instance of generic type, FALSE
19856 generic_type_p (tree t
)
19858 if (t
== NULL_TREE
|| !TYPE_P (t
))
19860 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
19863 /* Schedule the generation of the generic parameter dies for the
19864 instance of generic type T. The proper generation itself is later
19865 done by gen_scheduled_generic_parms_dies. */
19868 schedule_generic_params_dies_gen (tree t
)
19870 if (!generic_type_p (t
))
19873 if (generic_type_instances
== NULL
)
19874 generic_type_instances
= VEC_alloc (tree
, gc
, 256);
19876 VEC_safe_push (tree
, gc
, generic_type_instances
, t
);
19879 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
19880 by append_entry_to_tmpl_value_parm_die_table. This function must
19881 be called after function DIEs have been generated. */
19884 gen_remaining_tmpl_value_param_die_attribute (void)
19886 if (tmpl_value_parm_die_table
)
19891 FOR_EACH_VEC_ELT (die_arg_entry
, tmpl_value_parm_die_table
, i
, e
)
19892 tree_add_const_value_attribute (e
->die
, e
->arg
);
19896 /* Generate generic parameters DIEs for instances of generic types
19897 that have been previously scheduled by
19898 schedule_generic_params_dies_gen. This function must be called
19899 after all the types of the CU have been laid out. */
19902 gen_scheduled_generic_parms_dies (void)
19907 if (generic_type_instances
== NULL
)
19910 FOR_EACH_VEC_ELT (tree
, generic_type_instances
, i
, t
)
19911 gen_generic_params_dies (t
);
19915 /* Replace DW_AT_name for the decl with name. */
19918 dwarf2out_set_name (tree decl
, tree name
)
19924 die
= TYPE_SYMTAB_DIE (decl
);
19928 dname
= dwarf2_name (name
, 0);
19932 attr
= get_AT (die
, DW_AT_name
);
19935 struct indirect_string_node
*node
;
19937 node
= find_AT_string (dname
);
19938 /* replace the string. */
19939 attr
->dw_attr_val
.v
.val_str
= node
;
19943 add_name_attribute (die
, dname
);
19946 /* Called by the final INSN scan whenever we see a var location. We
19947 use it to drop labels in the right places, and throw the location in
19948 our lookup table. */
19951 dwarf2out_var_location (rtx loc_note
)
19953 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
19954 struct var_loc_node
*newloc
;
19955 rtx next_real
, next_note
;
19956 static const char *last_label
;
19957 static const char *last_postcall_label
;
19958 static bool last_in_cold_section_p
;
19959 static rtx expected_next_loc_note
;
19963 if (!NOTE_P (loc_note
))
19965 if (CALL_P (loc_note
))
19968 if (SIBLING_CALL_P (loc_note
))
19969 tail_call_site_count
++;
19974 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
19975 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
19978 /* Optimize processing a large consecutive sequence of location
19979 notes so we don't spend too much time in next_real_insn. If the
19980 next insn is another location note, remember the next_real_insn
19981 calculation for next time. */
19982 next_real
= cached_next_real_insn
;
19985 if (expected_next_loc_note
!= loc_note
)
19986 next_real
= NULL_RTX
;
19989 next_note
= NEXT_INSN (loc_note
);
19991 || INSN_DELETED_P (next_note
)
19992 || GET_CODE (next_note
) != NOTE
19993 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
19994 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
19995 next_note
= NULL_RTX
;
19998 next_real
= next_real_insn (loc_note
);
20002 expected_next_loc_note
= next_note
;
20003 cached_next_real_insn
= next_real
;
20006 cached_next_real_insn
= NULL_RTX
;
20008 /* If there are no instructions which would be affected by this note,
20009 don't do anything. */
20011 && next_real
== NULL_RTX
20012 && !NOTE_DURING_CALL_P (loc_note
))
20015 if (next_real
== NULL_RTX
)
20016 next_real
= get_last_insn ();
20018 /* If there were any real insns between note we processed last time
20019 and this note (or if it is the first note), clear
20020 last_{,postcall_}label so that they are not reused this time. */
20021 if (last_var_location_insn
== NULL_RTX
20022 || last_var_location_insn
!= next_real
20023 || last_in_cold_section_p
!= in_cold_section_p
)
20026 last_postcall_label
= NULL
;
20031 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
20032 newloc
= add_var_loc_to_decl (decl
, loc_note
,
20033 NOTE_DURING_CALL_P (loc_note
)
20034 ? last_postcall_label
: last_label
);
20035 if (newloc
== NULL
)
20044 /* If there were no real insns between note we processed last time
20045 and this note, use the label we emitted last time. Otherwise
20046 create a new label and emit it. */
20047 if (last_label
== NULL
)
20049 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
20050 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
20052 last_label
= ggc_strdup (loclabel
);
20057 struct call_arg_loc_node
*ca_loc
20058 = ggc_alloc_cleared_call_arg_loc_node ();
20059 rtx prev
= prev_real_insn (loc_note
), x
;
20060 ca_loc
->call_arg_loc_note
= loc_note
;
20061 ca_loc
->next
= NULL
;
20062 ca_loc
->label
= last_label
;
20065 || (NONJUMP_INSN_P (prev
)
20066 && GET_CODE (PATTERN (prev
)) == SEQUENCE
20067 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
20068 if (!CALL_P (prev
))
20069 prev
= XVECEXP (PATTERN (prev
), 0, 0);
20070 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
20071 x
= PATTERN (prev
);
20072 if (GET_CODE (x
) == PARALLEL
)
20073 x
= XVECEXP (x
, 0, 0);
20074 if (GET_CODE (x
) == SET
)
20076 if (GET_CODE (x
) == CALL
&& MEM_P (XEXP (x
, 0)))
20078 x
= XEXP (XEXP (x
, 0), 0);
20079 if (GET_CODE (x
) == SYMBOL_REF
20080 && SYMBOL_REF_DECL (x
)
20081 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
20082 ca_loc
->symbol_ref
= x
;
20084 ca_loc
->block
= insn_scope (prev
);
20085 if (call_arg_locations
)
20086 call_arg_loc_last
->next
= ca_loc
;
20088 call_arg_locations
= ca_loc
;
20089 call_arg_loc_last
= ca_loc
;
20091 else if (!NOTE_DURING_CALL_P (loc_note
))
20092 newloc
->label
= last_label
;
20095 if (!last_postcall_label
)
20097 sprintf (loclabel
, "%s-1", last_label
);
20098 last_postcall_label
= ggc_strdup (loclabel
);
20100 newloc
->label
= last_postcall_label
;
20103 last_var_location_insn
= next_real
;
20104 last_in_cold_section_p
= in_cold_section_p
;
20107 /* Note in one location list that text section has changed. */
20110 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
20112 var_loc_list
*list
= (var_loc_list
*) *slot
;
20114 list
->last_before_switch
20115 = list
->last
->next
? list
->last
->next
: list
->last
;
20119 /* Note in all location lists that text section has changed. */
20122 var_location_switch_text_section (void)
20124 if (decl_loc_table
== NULL
)
20127 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
20130 /* Create a new line number table. */
20132 static dw_line_info_table
*
20133 new_line_info_table (void)
20135 dw_line_info_table
*table
;
20137 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
20138 table
->file_num
= 1;
20139 table
->line_num
= 1;
20140 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
20145 /* Lookup the "current" table into which we emit line info, so
20146 that we don't have to do it for every source line. */
20149 set_cur_line_info_table (section
*sec
)
20151 dw_line_info_table
*table
;
20153 if (sec
== text_section
)
20154 table
= text_section_line_info
;
20155 else if (sec
== cold_text_section
)
20157 table
= cold_text_section_line_info
;
20160 cold_text_section_line_info
= table
= new_line_info_table ();
20161 table
->end_label
= cold_end_label
;
20166 const char *end_label
;
20168 if (flag_reorder_blocks_and_partition
)
20170 if (in_cold_section_p
)
20171 end_label
= crtl
->subsections
.cold_section_end_label
;
20173 end_label
= crtl
->subsections
.hot_section_end_label
;
20177 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20178 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
20179 current_function_funcdef_no
);
20180 end_label
= ggc_strdup (label
);
20183 table
= new_line_info_table ();
20184 table
->end_label
= end_label
;
20186 VEC_safe_push (dw_line_info_table_p
, gc
, separate_line_info
, table
);
20189 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20190 table
->is_stmt
= (cur_line_info_table
20191 ? cur_line_info_table
->is_stmt
20192 : DWARF_LINE_DEFAULT_IS_STMT_START
);
20193 cur_line_info_table
= table
;
20197 /* We need to reset the locations at the beginning of each
20198 function. We can't do this in the end_function hook, because the
20199 declarations that use the locations won't have been output when
20200 that hook is called. Also compute have_multiple_function_sections here. */
20203 dwarf2out_begin_function (tree fun
)
20205 section
*sec
= function_section (fun
);
20207 if (sec
!= text_section
)
20208 have_multiple_function_sections
= true;
20210 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
20212 gcc_assert (current_function_decl
== fun
);
20213 cold_text_section
= unlikely_text_section ();
20214 switch_to_section (cold_text_section
);
20215 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
20216 switch_to_section (sec
);
20219 dwarf2out_note_section_used ();
20220 call_site_count
= 0;
20221 tail_call_site_count
= 0;
20223 set_cur_line_info_table (sec
);
20226 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
20229 push_dw_line_info_entry (dw_line_info_table
*table
,
20230 enum dw_line_info_opcode opcode
, unsigned int val
)
20232 dw_line_info_entry e
;
20235 VEC_safe_push (dw_line_info_entry
, gc
, table
->entries
, &e
);
20238 /* Output a label to mark the beginning of a source code line entry
20239 and record information relating to this source line, in
20240 'line_info_table' for later output of the .debug_line section. */
20241 /* ??? The discriminator parameter ought to be unsigned. */
20244 dwarf2out_source_line (unsigned int line
, const char *filename
,
20245 int discriminator
, bool is_stmt
)
20247 unsigned int file_num
;
20248 dw_line_info_table
*table
;
20250 if (debug_info_level
< DINFO_LEVEL_NORMAL
|| line
== 0)
20253 /* The discriminator column was added in dwarf4. Simplify the below
20254 by simply removing it if we're not supposed to output it. */
20255 if (dwarf_version
< 4 && dwarf_strict
)
20258 table
= cur_line_info_table
;
20259 file_num
= maybe_emit_file (lookup_filename (filename
));
20261 /* ??? TODO: Elide duplicate line number entries. Traditionally,
20262 the debugger has used the second (possibly duplicate) line number
20263 at the beginning of the function to mark the end of the prologue.
20264 We could eliminate any other duplicates within the function. For
20265 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
20266 that second line number entry. */
20267 /* Recall that this end-of-prologue indication is *not* the same thing
20268 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
20269 to which the hook corresponds, follows the last insn that was
20270 emitted by gen_prologue. What we need is to precede the first insn
20271 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
20272 insn that corresponds to something the user wrote. These may be
20273 very different locations once scheduling is enabled. */
20275 if (0 && file_num
== table
->file_num
20276 && line
== table
->line_num
20277 && discriminator
== table
->discrim_num
20278 && is_stmt
== table
->is_stmt
)
20281 switch_to_section (current_function_section ());
20283 /* If requested, emit something human-readable. */
20284 if (flag_debug_asm
)
20285 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
20287 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20289 /* Emit the .loc directive understood by GNU as. */
20290 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
20291 file_num, line, is_stmt, discriminator */
20292 fputs ("\t.loc ", asm_out_file
);
20293 fprint_ul (asm_out_file
, file_num
);
20294 putc (' ', asm_out_file
);
20295 fprint_ul (asm_out_file
, line
);
20296 putc (' ', asm_out_file
);
20297 putc ('0', asm_out_file
);
20299 if (is_stmt
!= table
->is_stmt
)
20301 fputs (" is_stmt ", asm_out_file
);
20302 putc (is_stmt
? '1' : '0', asm_out_file
);
20304 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
20306 gcc_assert (discriminator
> 0);
20307 fputs (" discriminator ", asm_out_file
);
20308 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
20310 putc ('\n', asm_out_file
);
20314 unsigned int label_num
= ++line_info_label_num
;
20316 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
20318 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
20319 if (file_num
!= table
->file_num
)
20320 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
20321 if (discriminator
!= table
->discrim_num
)
20322 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
20323 if (is_stmt
!= table
->is_stmt
)
20324 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
20325 push_dw_line_info_entry (table
, LI_set_line
, line
);
20328 table
->file_num
= file_num
;
20329 table
->line_num
= line
;
20330 table
->discrim_num
= discriminator
;
20331 table
->is_stmt
= is_stmt
;
20332 table
->in_use
= true;
20335 /* Record the beginning of a new source file. */
20338 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
20340 if (flag_eliminate_dwarf2_dups
)
20342 /* Record the beginning of the file for break_out_includes. */
20343 dw_die_ref bincl_die
;
20345 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
20346 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
20349 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20352 e
.code
= DW_MACINFO_start_file
;
20354 e
.info
= ggc_strdup (filename
);
20355 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20359 /* Record the end of a source file. */
20362 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
20364 if (flag_eliminate_dwarf2_dups
)
20365 /* Record the end of the file for break_out_includes. */
20366 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
20368 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20371 e
.code
= DW_MACINFO_end_file
;
20374 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20378 /* Called from debug_define in toplev.c. The `buffer' parameter contains
20379 the tail part of the directive line, i.e. the part which is past the
20380 initial whitespace, #, whitespace, directive-name, whitespace part. */
20383 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
20384 const char *buffer ATTRIBUTE_UNUSED
)
20386 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20389 /* Insert a dummy first entry to be able to optimize the whole
20390 predefined macro block using DW_MACRO_GNU_transparent_include. */
20391 if (VEC_empty (macinfo_entry
, macinfo_table
) && lineno
<= 1)
20396 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20398 e
.code
= DW_MACINFO_define
;
20400 e
.info
= ggc_strdup (buffer
);
20401 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20405 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
20406 the tail part of the directive line, i.e. the part which is past the
20407 initial whitespace, #, whitespace, directive-name, whitespace part. */
20410 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
20411 const char *buffer ATTRIBUTE_UNUSED
)
20413 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20416 /* Insert a dummy first entry to be able to optimize the whole
20417 predefined macro block using DW_MACRO_GNU_transparent_include. */
20418 if (VEC_empty (macinfo_entry
, macinfo_table
) && lineno
<= 1)
20423 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20425 e
.code
= DW_MACINFO_undef
;
20427 e
.info
= ggc_strdup (buffer
);
20428 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20432 /* Routines to manipulate hash table of CUs. */
20435 htab_macinfo_hash (const void *of
)
20437 const macinfo_entry
*const entry
=
20438 (const macinfo_entry
*) of
;
20440 return htab_hash_string (entry
->info
);
20444 htab_macinfo_eq (const void *of1
, const void *of2
)
20446 const macinfo_entry
*const entry1
= (const macinfo_entry
*) of1
;
20447 const macinfo_entry
*const entry2
= (const macinfo_entry
*) of2
;
20449 return !strcmp (entry1
->info
, entry2
->info
);
20452 /* Output a single .debug_macinfo entry. */
20455 output_macinfo_op (macinfo_entry
*ref
)
20459 struct indirect_string_node
*node
;
20460 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20461 struct dwarf_file_data
*fd
;
20465 case DW_MACINFO_start_file
:
20466 fd
= lookup_filename (ref
->info
);
20467 file_num
= maybe_emit_file (fd
);
20468 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
20469 dw2_asm_output_data_uleb128 (ref
->lineno
,
20470 "Included from line number %lu",
20471 (unsigned long) ref
->lineno
);
20472 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
20474 case DW_MACINFO_end_file
:
20475 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
20477 case DW_MACINFO_define
:
20478 case DW_MACINFO_undef
:
20479 len
= strlen (ref
->info
) + 1;
20481 && len
> DWARF_OFFSET_SIZE
20482 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
20483 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
20485 ref
->code
= ref
->code
== DW_MACINFO_define
20486 ? DW_MACRO_GNU_define_indirect
20487 : DW_MACRO_GNU_undef_indirect
;
20488 output_macinfo_op (ref
);
20491 dw2_asm_output_data (1, ref
->code
,
20492 ref
->code
== DW_MACINFO_define
20493 ? "Define macro" : "Undefine macro");
20494 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
20495 (unsigned long) ref
->lineno
);
20496 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
20498 case DW_MACRO_GNU_define_indirect
:
20499 case DW_MACRO_GNU_undef_indirect
:
20500 node
= find_AT_string (ref
->info
);
20501 if (node
->form
!= DW_FORM_strp
)
20504 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
20505 ++dw2_string_counter
;
20506 node
->label
= xstrdup (label
);
20507 node
->form
= DW_FORM_strp
;
20509 dw2_asm_output_data (1, ref
->code
,
20510 ref
->code
== DW_MACRO_GNU_define_indirect
20511 ? "Define macro indirect"
20512 : "Undefine macro indirect");
20513 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
20514 (unsigned long) ref
->lineno
);
20515 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
20516 debug_str_section
, "The macro: \"%s\"",
20519 case DW_MACRO_GNU_transparent_include
:
20520 dw2_asm_output_data (1, ref
->code
, "Transparent include");
20521 ASM_GENERATE_INTERNAL_LABEL (label
,
20522 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
20523 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
20526 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
20527 ASM_COMMENT_START
, (unsigned long) ref
->code
);
20532 /* Attempt to make a sequence of define/undef macinfo ops shareable with
20533 other compilation unit .debug_macinfo sections. IDX is the first
20534 index of a define/undef, return the number of ops that should be
20535 emitted in a comdat .debug_macinfo section and emit
20536 a DW_MACRO_GNU_transparent_include entry referencing it.
20537 If the define/undef entry should be emitted normally, return 0. */
20540 optimize_macinfo_range (unsigned int idx
, VEC (macinfo_entry
, gc
) *files
,
20541 htab_t
*macinfo_htab
)
20543 macinfo_entry
*first
, *second
, *cur
, *inc
;
20544 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
20545 unsigned char checksum
[16];
20546 struct md5_ctx ctx
;
20547 char *grp_name
, *tail
;
20549 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
20552 first
= VEC_index (macinfo_entry
, macinfo_table
, idx
);
20553 second
= VEC_index (macinfo_entry
, macinfo_table
, idx
+ 1);
20555 /* Optimize only if there are at least two consecutive define/undef ops,
20556 and either all of them are before first DW_MACINFO_start_file
20557 with lineno {0,1} (i.e. predefined macro block), or all of them are
20558 in some included header file. */
20559 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
20561 if (VEC_empty (macinfo_entry
, files
))
20563 if (first
->lineno
> 1 || second
->lineno
> 1)
20566 else if (first
->lineno
== 0)
20569 /* Find the last define/undef entry that can be grouped together
20570 with first and at the same time compute md5 checksum of their
20571 codes, linenumbers and strings. */
20572 md5_init_ctx (&ctx
);
20573 for (i
= idx
; VEC_iterate (macinfo_entry
, macinfo_table
, i
, cur
); i
++)
20574 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
20576 else if (VEC_empty (macinfo_entry
, files
) && cur
->lineno
> 1)
20580 unsigned char code
= cur
->code
;
20581 md5_process_bytes (&code
, 1, &ctx
);
20582 checksum_uleb128 (cur
->lineno
, &ctx
);
20583 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
20585 md5_finish_ctx (&ctx
, checksum
);
20588 /* From the containing include filename (if any) pick up just
20589 usable characters from its basename. */
20590 if (VEC_empty (macinfo_entry
, files
))
20593 base
= lbasename (VEC_last (macinfo_entry
, files
)->info
);
20594 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
20595 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
20596 encoded_filename_len
++;
20597 /* Count . at the end. */
20598 if (encoded_filename_len
)
20599 encoded_filename_len
++;
20601 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
20602 linebuf_len
= strlen (linebuf
);
20604 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
20605 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
20607 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
20608 tail
= grp_name
+ 4;
20609 if (encoded_filename_len
)
20611 for (i
= 0; base
[i
]; i
++)
20612 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
20616 memcpy (tail
, linebuf
, linebuf_len
);
20617 tail
+= linebuf_len
;
20619 for (i
= 0; i
< 16; i
++)
20620 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
20622 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
20623 in the empty vector entry before the first define/undef. */
20624 inc
= VEC_index (macinfo_entry
, macinfo_table
, idx
- 1);
20625 inc
->code
= DW_MACRO_GNU_transparent_include
;
20627 inc
->info
= ggc_strdup (grp_name
);
20628 if (*macinfo_htab
== NULL
)
20629 *macinfo_htab
= htab_create (10, htab_macinfo_hash
, htab_macinfo_eq
, NULL
);
20630 /* Avoid emitting duplicates. */
20631 slot
= htab_find_slot (*macinfo_htab
, inc
, INSERT
);
20636 /* If such an entry has been used before, just emit
20637 a DW_MACRO_GNU_transparent_include op. */
20638 inc
= (macinfo_entry
*) *slot
;
20639 output_macinfo_op (inc
);
20640 /* And clear all macinfo_entry in the range to avoid emitting them
20641 in the second pass. */
20643 VEC_iterate (macinfo_entry
, macinfo_table
, i
, cur
)
20644 && i
< idx
+ count
;
20654 inc
->lineno
= htab_elements (*macinfo_htab
);
20655 output_macinfo_op (inc
);
20660 /* Output macinfo section(s). */
20663 output_macinfo (void)
20666 unsigned long length
= VEC_length (macinfo_entry
, macinfo_table
);
20667 macinfo_entry
*ref
;
20668 VEC (macinfo_entry
, gc
) *files
= NULL
;
20669 htab_t macinfo_htab
= NULL
;
20674 /* output_macinfo* uses these interchangeably. */
20675 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
20676 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
20677 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
20678 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
20680 /* For .debug_macro emit the section header. */
20683 dw2_asm_output_data (2, 4, "DWARF macro version number");
20684 if (DWARF_OFFSET_SIZE
== 8)
20685 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
20687 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
20688 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_line_section_label
,
20689 debug_line_section
, NULL
);
20692 /* In the first loop, it emits the primary .debug_macinfo section
20693 and after each emitted op the macinfo_entry is cleared.
20694 If a longer range of define/undef ops can be optimized using
20695 DW_MACRO_GNU_transparent_include, the
20696 DW_MACRO_GNU_transparent_include op is emitted and kept in
20697 the vector before the first define/undef in the range and the
20698 whole range of define/undef ops is not emitted and kept. */
20699 for (i
= 0; VEC_iterate (macinfo_entry
, macinfo_table
, i
, ref
); i
++)
20703 case DW_MACINFO_start_file
:
20704 VEC_safe_push (macinfo_entry
, gc
, files
, ref
);
20706 case DW_MACINFO_end_file
:
20707 if (!VEC_empty (macinfo_entry
, files
))
20708 VEC_pop (macinfo_entry
, files
);
20710 case DW_MACINFO_define
:
20711 case DW_MACINFO_undef
:
20713 && HAVE_COMDAT_GROUP
20714 && VEC_length (macinfo_entry
, files
) != 1
20717 && VEC_index (macinfo_entry
, macinfo_table
, i
- 1)->code
== 0)
20719 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
20728 /* A dummy entry may be inserted at the beginning to be able
20729 to optimize the whole block of predefined macros. */
20735 output_macinfo_op (ref
);
20740 if (macinfo_htab
== NULL
)
20743 htab_delete (macinfo_htab
);
20745 /* If any DW_MACRO_GNU_transparent_include were used, on those
20746 DW_MACRO_GNU_transparent_include entries terminate the
20747 current chain and switch to a new comdat .debug_macinfo
20748 section and emit the define/undef entries within it. */
20749 for (i
= 0; VEC_iterate (macinfo_entry
, macinfo_table
, i
, ref
); i
++)
20754 case DW_MACRO_GNU_transparent_include
:
20756 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20757 tree comdat_key
= get_identifier (ref
->info
);
20758 /* Terminate the previous .debug_macinfo section. */
20759 dw2_asm_output_data (1, 0, "End compilation unit");
20760 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
20762 | SECTION_LINKONCE
,
20764 ASM_GENERATE_INTERNAL_LABEL (label
,
20765 DEBUG_MACRO_SECTION_LABEL
,
20767 ASM_OUTPUT_LABEL (asm_out_file
, label
);
20770 dw2_asm_output_data (2, 4, "DWARF macro version number");
20771 if (DWARF_OFFSET_SIZE
== 8)
20772 dw2_asm_output_data (1, 1, "Flags: 64-bit");
20774 dw2_asm_output_data (1, 0, "Flags: 32-bit");
20777 case DW_MACINFO_define
:
20778 case DW_MACINFO_undef
:
20779 output_macinfo_op (ref
);
20784 gcc_unreachable ();
20788 /* Set up for Dwarf output at the start of compilation. */
20791 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
20793 /* Allocate the file_table. */
20794 file_table
= htab_create_ggc (50, file_table_hash
,
20795 file_table_eq
, NULL
);
20797 /* Allocate the decl_die_table. */
20798 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
20799 decl_die_table_eq
, NULL
);
20801 /* Allocate the decl_loc_table. */
20802 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
20803 decl_loc_table_eq
, NULL
);
20805 /* Allocate the cached_dw_loc_list_table. */
20806 cached_dw_loc_list_table
20807 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
20808 cached_dw_loc_list_table_eq
, NULL
);
20810 /* Allocate the initial hunk of the decl_scope_table. */
20811 decl_scope_table
= VEC_alloc (tree
, gc
, 256);
20813 /* Allocate the initial hunk of the abbrev_die_table. */
20814 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
20815 (ABBREV_DIE_TABLE_INCREMENT
);
20816 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
20817 /* Zero-th entry is allocated, but unused. */
20818 abbrev_die_table_in_use
= 1;
20820 /* Allocate the pubtypes and pubnames vectors. */
20821 pubname_table
= VEC_alloc (pubname_entry
, gc
, 32);
20822 pubtype_table
= VEC_alloc (pubname_entry
, gc
, 32);
20824 incomplete_types
= VEC_alloc (tree
, gc
, 64);
20826 used_rtx_array
= VEC_alloc (rtx
, gc
, 32);
20828 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
20829 SECTION_DEBUG
, NULL
);
20830 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
20831 SECTION_DEBUG
, NULL
);
20832 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
20833 SECTION_DEBUG
, NULL
);
20834 debug_macinfo_section
= get_section (dwarf_strict
20835 ? DEBUG_MACINFO_SECTION
20836 : DEBUG_MACRO_SECTION
,
20837 SECTION_DEBUG
, NULL
);
20838 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
20839 SECTION_DEBUG
, NULL
);
20840 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
20841 SECTION_DEBUG
, NULL
);
20842 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
20843 SECTION_DEBUG
, NULL
);
20844 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
20845 SECTION_DEBUG
, NULL
);
20846 debug_str_section
= get_section (DEBUG_STR_SECTION
,
20847 DEBUG_STR_SECTION_FLAGS
, NULL
);
20848 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
20849 SECTION_DEBUG
, NULL
);
20850 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
20851 SECTION_DEBUG
, NULL
);
20853 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
20854 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
20855 DEBUG_ABBREV_SECTION_LABEL
, 0);
20856 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
20857 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
20858 COLD_TEXT_SECTION_LABEL
, 0);
20859 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
20861 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
20862 DEBUG_INFO_SECTION_LABEL
, 0);
20863 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
20864 DEBUG_LINE_SECTION_LABEL
, 0);
20865 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
20866 DEBUG_RANGES_SECTION_LABEL
, 0);
20867 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
20869 ? DEBUG_MACINFO_SECTION_LABEL
20870 : DEBUG_MACRO_SECTION_LABEL
, 0);
20872 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20873 macinfo_table
= VEC_alloc (macinfo_entry
, gc
, 64);
20875 switch_to_section (text_section
);
20876 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
20878 /* Make sure the line number table for .text always exists. */
20879 text_section_line_info
= new_line_info_table ();
20880 text_section_line_info
->end_label
= text_end_label
;
20883 /* Called before compile () starts outputtting functions, variables
20884 and toplevel asms into assembly. */
20887 dwarf2out_assembly_start (void)
20889 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
20890 && dwarf2out_do_cfi_asm ()
20891 && (!(flag_unwind_tables
|| flag_exceptions
)
20892 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
20893 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
20896 /* A helper function for dwarf2out_finish called through
20897 htab_traverse. Emit one queued .debug_str string. */
20900 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
20902 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
20904 if (node
->form
== DW_FORM_strp
)
20906 switch_to_section (debug_str_section
);
20907 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
20908 assemble_string (node
->str
, strlen (node
->str
) + 1);
20914 #if ENABLE_ASSERT_CHECKING
20915 /* Verify that all marks are clear. */
20918 verify_marks_clear (dw_die_ref die
)
20922 gcc_assert (! die
->die_mark
);
20923 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
20925 #endif /* ENABLE_ASSERT_CHECKING */
20927 /* Clear the marks for a die and its children.
20928 Be cool if the mark isn't set. */
20931 prune_unmark_dies (dw_die_ref die
)
20937 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
20940 /* Given DIE that we're marking as used, find any other dies
20941 it references as attributes and mark them as used. */
20944 prune_unused_types_walk_attribs (dw_die_ref die
)
20949 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
20951 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
20953 /* A reference to another DIE.
20954 Make sure that it will get emitted.
20955 If it was broken out into a comdat group, don't follow it. */
20956 if (! AT_ref (a
)->comdat_type_p
20957 || a
->dw_attr
== DW_AT_specification
)
20958 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
20960 /* Set the string's refcount to 0 so that prune_unused_types_mark
20961 accounts properly for it. */
20962 if (AT_class (a
) == dw_val_class_str
)
20963 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
20967 /* Mark the generic parameters and arguments children DIEs of DIE. */
20970 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
20974 if (die
== NULL
|| die
->die_child
== NULL
)
20976 c
= die
->die_child
;
20979 switch (c
->die_tag
)
20981 case DW_TAG_template_type_param
:
20982 case DW_TAG_template_value_param
:
20983 case DW_TAG_GNU_template_template_param
:
20984 case DW_TAG_GNU_template_parameter_pack
:
20985 prune_unused_types_mark (c
, 1);
20991 } while (c
&& c
!= die
->die_child
);
20994 /* Mark DIE as being used. If DOKIDS is true, then walk down
20995 to DIE's children. */
20998 prune_unused_types_mark (dw_die_ref die
, int dokids
)
21002 if (die
->die_mark
== 0)
21004 /* We haven't done this node yet. Mark it as used. */
21006 /* If this is the DIE of a generic type instantiation,
21007 mark the children DIEs that describe its generic parms and
21009 prune_unused_types_mark_generic_parms_dies (die
);
21011 /* We also have to mark its parents as used.
21012 (But we don't want to mark our parents' kids due to this.) */
21013 if (die
->die_parent
)
21014 prune_unused_types_mark (die
->die_parent
, 0);
21016 /* Mark any referenced nodes. */
21017 prune_unused_types_walk_attribs (die
);
21019 /* If this node is a specification,
21020 also mark the definition, if it exists. */
21021 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
21022 prune_unused_types_mark (die
->die_definition
, 1);
21025 if (dokids
&& die
->die_mark
!= 2)
21027 /* We need to walk the children, but haven't done so yet.
21028 Remember that we've walked the kids. */
21031 /* If this is an array type, we need to make sure our
21032 kids get marked, even if they're types. If we're
21033 breaking out types into comdat sections, do this
21034 for all type definitions. */
21035 if (die
->die_tag
== DW_TAG_array_type
21036 || (use_debug_types
21037 && is_type_die (die
) && ! is_declaration_die (die
)))
21038 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
21040 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
21044 /* For local classes, look if any static member functions were emitted
21045 and if so, mark them. */
21048 prune_unused_types_walk_local_classes (dw_die_ref die
)
21052 if (die
->die_mark
== 2)
21055 switch (die
->die_tag
)
21057 case DW_TAG_structure_type
:
21058 case DW_TAG_union_type
:
21059 case DW_TAG_class_type
:
21062 case DW_TAG_subprogram
:
21063 if (!get_AT_flag (die
, DW_AT_declaration
)
21064 || die
->die_definition
!= NULL
)
21065 prune_unused_types_mark (die
, 1);
21072 /* Mark children. */
21073 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
21076 /* Walk the tree DIE and mark types that we actually use. */
21079 prune_unused_types_walk (dw_die_ref die
)
21083 /* Don't do anything if this node is already marked and
21084 children have been marked as well. */
21085 if (die
->die_mark
== 2)
21088 switch (die
->die_tag
)
21090 case DW_TAG_structure_type
:
21091 case DW_TAG_union_type
:
21092 case DW_TAG_class_type
:
21093 if (die
->die_perennial_p
)
21096 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
21097 if (c
->die_tag
== DW_TAG_subprogram
)
21100 /* Finding used static member functions inside of classes
21101 is needed just for local classes, because for other classes
21102 static member function DIEs with DW_AT_specification
21103 are emitted outside of the DW_TAG_*_type. If we ever change
21104 it, we'd need to call this even for non-local classes. */
21106 prune_unused_types_walk_local_classes (die
);
21108 /* It's a type node --- don't mark it. */
21111 case DW_TAG_const_type
:
21112 case DW_TAG_packed_type
:
21113 case DW_TAG_pointer_type
:
21114 case DW_TAG_reference_type
:
21115 case DW_TAG_rvalue_reference_type
:
21116 case DW_TAG_volatile_type
:
21117 case DW_TAG_typedef
:
21118 case DW_TAG_array_type
:
21119 case DW_TAG_interface_type
:
21120 case DW_TAG_friend
:
21121 case DW_TAG_variant_part
:
21122 case DW_TAG_enumeration_type
:
21123 case DW_TAG_subroutine_type
:
21124 case DW_TAG_string_type
:
21125 case DW_TAG_set_type
:
21126 case DW_TAG_subrange_type
:
21127 case DW_TAG_ptr_to_member_type
:
21128 case DW_TAG_file_type
:
21129 if (die
->die_perennial_p
)
21132 /* It's a type node --- don't mark it. */
21136 /* Mark everything else. */
21140 if (die
->die_mark
== 0)
21144 /* Now, mark any dies referenced from here. */
21145 prune_unused_types_walk_attribs (die
);
21150 /* Mark children. */
21151 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
21154 /* Increment the string counts on strings referred to from DIE's
21158 prune_unused_types_update_strings (dw_die_ref die
)
21163 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
21164 if (AT_class (a
) == dw_val_class_str
)
21166 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
21168 /* Avoid unnecessarily putting strings that are used less than
21169 twice in the hash table. */
21171 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
21174 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
21175 htab_hash_string (s
->str
),
21177 gcc_assert (*slot
== NULL
);
21183 /* Remove from the tree DIE any dies that aren't marked. */
21186 prune_unused_types_prune (dw_die_ref die
)
21190 gcc_assert (die
->die_mark
);
21191 prune_unused_types_update_strings (die
);
21193 if (! die
->die_child
)
21196 c
= die
->die_child
;
21198 dw_die_ref prev
= c
;
21199 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
21200 if (c
== die
->die_child
)
21202 /* No marked children between 'prev' and the end of the list. */
21204 /* No marked children at all. */
21205 die
->die_child
= NULL
;
21208 prev
->die_sib
= c
->die_sib
;
21209 die
->die_child
= prev
;
21214 if (c
!= prev
->die_sib
)
21216 prune_unused_types_prune (c
);
21217 } while (c
!= die
->die_child
);
21220 /* Remove dies representing declarations that we never use. */
21223 prune_unused_types (void)
21226 limbo_die_node
*node
;
21227 comdat_type_node
*ctnode
;
21229 dw_die_ref base_type
;
21231 #if ENABLE_ASSERT_CHECKING
21232 /* All the marks should already be clear. */
21233 verify_marks_clear (comp_unit_die ());
21234 for (node
= limbo_die_list
; node
; node
= node
->next
)
21235 verify_marks_clear (node
->die
);
21236 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21237 verify_marks_clear (ctnode
->root_die
);
21238 #endif /* ENABLE_ASSERT_CHECKING */
21240 /* Mark types that are used in global variables. */
21241 premark_types_used_by_global_vars ();
21243 /* Set the mark on nodes that are actually used. */
21244 prune_unused_types_walk (comp_unit_die ());
21245 for (node
= limbo_die_list
; node
; node
= node
->next
)
21246 prune_unused_types_walk (node
->die
);
21247 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21249 prune_unused_types_walk (ctnode
->root_die
);
21250 prune_unused_types_mark (ctnode
->type_die
, 1);
21253 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
21254 are unusual in that they are pubnames that are the children of pubtypes.
21255 They should only be marked via their parent DW_TAG_enumeration_type die,
21256 not as roots in themselves. */
21257 FOR_EACH_VEC_ELT (pubname_entry
, pubname_table
, i
, pub
)
21258 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
21259 prune_unused_types_mark (pub
->die
, 1);
21260 for (i
= 0; VEC_iterate (dw_die_ref
, base_types
, i
, base_type
); i
++)
21261 prune_unused_types_mark (base_type
, 1);
21263 if (debug_str_hash
)
21264 htab_empty (debug_str_hash
);
21265 prune_unused_types_prune (comp_unit_die ());
21266 for (node
= limbo_die_list
; node
; node
= node
->next
)
21267 prune_unused_types_prune (node
->die
);
21268 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21269 prune_unused_types_prune (ctnode
->root_die
);
21271 /* Leave the marks clear. */
21272 prune_unmark_dies (comp_unit_die ());
21273 for (node
= limbo_die_list
; node
; node
= node
->next
)
21274 prune_unmark_dies (node
->die
);
21275 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21276 prune_unmark_dies (ctnode
->root_die
);
21279 /* Set the parameter to true if there are any relative pathnames in
21282 file_table_relative_p (void ** slot
, void *param
)
21284 bool *p
= (bool *) param
;
21285 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
21286 if (!IS_ABSOLUTE_PATH (d
->filename
))
21294 /* Routines to manipulate hash table of comdat type units. */
21297 htab_ct_hash (const void *of
)
21300 const comdat_type_node
*const type_node
= (const comdat_type_node
*) of
;
21302 memcpy (&h
, type_node
->signature
, sizeof (h
));
21307 htab_ct_eq (const void *of1
, const void *of2
)
21309 const comdat_type_node
*const type_node_1
= (const comdat_type_node
*) of1
;
21310 const comdat_type_node
*const type_node_2
= (const comdat_type_node
*) of2
;
21312 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
21313 DWARF_TYPE_SIGNATURE_SIZE
));
21316 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
21317 to the location it would have been added, should we know its
21318 DECL_ASSEMBLER_NAME when we added other attributes. This will
21319 probably improve compactness of debug info, removing equivalent
21320 abbrevs, and hide any differences caused by deferring the
21321 computation of the assembler name, triggered by e.g. PCH. */
21324 move_linkage_attr (dw_die_ref die
)
21326 unsigned ix
= VEC_length (dw_attr_node
, die
->die_attr
);
21327 dw_attr_node linkage
= *VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
21329 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
21330 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
21334 dw_attr_node
*prev
= VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
21336 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
21340 if (ix
!= VEC_length (dw_attr_node
, die
->die_attr
) - 1)
21342 VEC_pop (dw_attr_node
, die
->die_attr
);
21343 VEC_quick_insert (dw_attr_node
, die
->die_attr
, ix
, &linkage
);
21347 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
21348 referenced from typed stack ops and count how often they are used. */
21351 mark_base_types (dw_loc_descr_ref loc
)
21353 dw_die_ref base_type
= NULL
;
21355 for (; loc
; loc
= loc
->dw_loc_next
)
21357 switch (loc
->dw_loc_opc
)
21359 case DW_OP_GNU_regval_type
:
21360 case DW_OP_GNU_deref_type
:
21361 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
21363 case DW_OP_GNU_convert
:
21364 case DW_OP_GNU_reinterpret
:
21365 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
21368 case DW_OP_GNU_const_type
:
21369 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
21371 case DW_OP_GNU_entry_value
:
21372 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
21377 gcc_assert (base_type
->die_parent
== comp_unit_die ());
21378 if (base_type
->die_mark
)
21379 base_type
->die_mark
++;
21382 VEC_safe_push (dw_die_ref
, heap
, base_types
, base_type
);
21383 base_type
->die_mark
= 1;
21388 /* Comparison function for sorting marked base types. */
21391 base_type_cmp (const void *x
, const void *y
)
21393 dw_die_ref dx
= *(const dw_die_ref
*) x
;
21394 dw_die_ref dy
= *(const dw_die_ref
*) y
;
21395 unsigned int byte_size1
, byte_size2
;
21396 unsigned int encoding1
, encoding2
;
21397 if (dx
->die_mark
> dy
->die_mark
)
21399 if (dx
->die_mark
< dy
->die_mark
)
21401 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
21402 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
21403 if (byte_size1
< byte_size2
)
21405 if (byte_size1
> byte_size2
)
21407 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
21408 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
21409 if (encoding1
< encoding2
)
21411 if (encoding1
> encoding2
)
21416 /* Move base types marked by mark_base_types as early as possible
21417 in the CU, sorted by decreasing usage count both to make the
21418 uleb128 references as small as possible and to make sure they
21419 will have die_offset already computed by calc_die_sizes when
21420 sizes of typed stack loc ops is computed. */
21423 move_marked_base_types (void)
21426 dw_die_ref base_type
, die
, c
;
21428 if (VEC_empty (dw_die_ref
, base_types
))
21431 /* Sort by decreasing usage count, they will be added again in that
21433 VEC_qsort (dw_die_ref
, base_types
, base_type_cmp
);
21434 die
= comp_unit_die ();
21435 c
= die
->die_child
;
21438 dw_die_ref prev
= c
;
21440 while (c
->die_mark
)
21442 remove_child_with_prev (c
, prev
);
21443 /* As base types got marked, there must be at least
21444 one node other than DW_TAG_base_type. */
21445 gcc_assert (c
!= c
->die_sib
);
21449 while (c
!= die
->die_child
);
21450 gcc_assert (die
->die_child
);
21451 c
= die
->die_child
;
21452 for (i
= 0; VEC_iterate (dw_die_ref
, base_types
, i
, base_type
); i
++)
21454 base_type
->die_mark
= 0;
21455 base_type
->die_sib
= c
->die_sib
;
21456 c
->die_sib
= base_type
;
21461 /* Helper function for resolve_addr, attempt to resolve
21462 one CONST_STRING, return non-zero if not successful. Similarly verify that
21463 SYMBOL_REFs refer to variables emitted in the current CU. */
21466 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
21470 if (GET_CODE (rtl
) == CONST_STRING
)
21472 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
21473 tree t
= build_string (len
, XSTR (rtl
, 0));
21474 tree tlen
= size_int (len
- 1);
21476 = build_array_type (char_type_node
, build_index_type (tlen
));
21477 rtl
= lookup_constant_def (t
);
21478 if (!rtl
|| !MEM_P (rtl
))
21480 rtl
= XEXP (rtl
, 0);
21481 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
21486 if (GET_CODE (rtl
) == SYMBOL_REF
21487 && SYMBOL_REF_DECL (rtl
))
21489 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
21491 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
21494 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
21498 if (GET_CODE (rtl
) == CONST
21499 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
21505 /* Helper function for resolve_addr, handle one location
21506 expression, return false if at least one CONST_STRING or SYMBOL_REF in
21507 the location list couldn't be resolved. */
21510 resolve_addr_in_expr (dw_loc_descr_ref loc
)
21512 dw_loc_descr_ref keep
= NULL
;
21513 for (; loc
; loc
= loc
->dw_loc_next
)
21514 switch (loc
->dw_loc_opc
)
21517 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
21520 case DW_OP_const4u
:
21521 case DW_OP_const8u
:
21523 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
21526 case DW_OP_plus_uconst
:
21527 if (size_of_loc_descr (loc
)
21528 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
21530 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
21532 dw_loc_descr_ref repl
21533 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
21534 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
21535 add_loc_descr (&repl
, loc
->dw_loc_next
);
21539 case DW_OP_implicit_value
:
21540 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
21541 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
21544 case DW_OP_GNU_implicit_pointer
:
21545 case DW_OP_GNU_parameter_ref
:
21546 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
21549 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
21552 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
21553 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
21554 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
21557 case DW_OP_GNU_const_type
:
21558 case DW_OP_GNU_regval_type
:
21559 case DW_OP_GNU_deref_type
:
21560 case DW_OP_GNU_convert
:
21561 case DW_OP_GNU_reinterpret
:
21562 while (loc
->dw_loc_next
21563 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
21565 dw_die_ref base1
, base2
;
21566 unsigned enc1
, enc2
, size1
, size2
;
21567 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
21568 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
21569 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
21570 else if (loc
->dw_loc_oprnd1
.val_class
21571 == dw_val_class_unsigned_const
)
21574 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
21575 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
21576 == dw_val_class_unsigned_const
)
21578 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
21579 gcc_assert (base1
->die_tag
== DW_TAG_base_type
21580 && base2
->die_tag
== DW_TAG_base_type
);
21581 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
21582 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
21583 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
21584 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
21586 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
21587 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
21591 /* Optimize away next DW_OP_GNU_convert after
21592 adjusting LOC's base type die reference. */
21593 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
21594 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
21595 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
21597 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
21598 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
21601 /* Don't change integer DW_OP_GNU_convert after e.g. floating
21602 point typed stack entry. */
21603 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
21604 keep
= loc
->dw_loc_next
;
21614 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
21615 an address in .rodata section if the string literal is emitted there,
21616 or remove the containing location list or replace DW_AT_const_value
21617 with DW_AT_location and empty location expression, if it isn't found
21618 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
21619 to something that has been emitted in the current CU. */
21622 resolve_addr (dw_die_ref die
)
21626 dw_loc_list_ref
*curr
, *start
, loc
;
21629 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
21630 switch (AT_class (a
))
21632 case dw_val_class_loc_list
:
21633 start
= curr
= AT_loc_list_ptr (a
);
21636 /* The same list can be referenced more than once. See if we have
21637 already recorded the result from a previous pass. */
21639 *curr
= loc
->dw_loc_next
;
21640 else if (!loc
->resolved_addr
)
21642 /* As things stand, we do not expect or allow one die to
21643 reference a suffix of another die's location list chain.
21644 References must be identical or completely separate.
21645 There is therefore no need to cache the result of this
21646 pass on any list other than the first; doing so
21647 would lead to unnecessary writes. */
21650 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
21651 if (!resolve_addr_in_expr ((*curr
)->expr
))
21653 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
21654 if (next
&& (*curr
)->ll_symbol
)
21656 gcc_assert (!next
->ll_symbol
);
21657 next
->ll_symbol
= (*curr
)->ll_symbol
;
21663 mark_base_types ((*curr
)->expr
);
21664 curr
= &(*curr
)->dw_loc_next
;
21668 loc
->resolved_addr
= 1;
21672 loc
->dw_loc_next
= *start
;
21677 remove_AT (die
, a
->dw_attr
);
21681 case dw_val_class_loc
:
21683 dw_loc_descr_ref l
= AT_loc (a
);
21684 /* For -gdwarf-2 don't attempt to optimize
21685 DW_AT_data_member_location containing
21686 DW_OP_plus_uconst - older consumers might
21687 rely on it being that op instead of a more complex,
21688 but shorter, location description. */
21689 if ((dwarf_version
> 2
21690 || a
->dw_attr
!= DW_AT_data_member_location
21692 || l
->dw_loc_opc
!= DW_OP_plus_uconst
21693 || l
->dw_loc_next
!= NULL
)
21694 && !resolve_addr_in_expr (l
))
21696 remove_AT (die
, a
->dw_attr
);
21700 mark_base_types (l
);
21703 case dw_val_class_addr
:
21704 if (a
->dw_attr
== DW_AT_const_value
21705 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
21707 remove_AT (die
, a
->dw_attr
);
21710 if (die
->die_tag
== DW_TAG_GNU_call_site
21711 && a
->dw_attr
== DW_AT_abstract_origin
)
21713 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
21714 dw_die_ref tdie
= lookup_decl_die (tdecl
);
21716 && DECL_EXTERNAL (tdecl
)
21717 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
21719 force_decl_die (tdecl
);
21720 tdie
= lookup_decl_die (tdecl
);
21724 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
21725 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
21726 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
21730 remove_AT (die
, a
->dw_attr
);
21739 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
21742 /* Helper routines for optimize_location_lists.
21743 This pass tries to share identical local lists in .debug_loc
21746 /* Iteratively hash operands of LOC opcode. */
21748 static inline hashval_t
21749 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
21751 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
21752 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
21754 switch (loc
->dw_loc_opc
)
21756 case DW_OP_const4u
:
21757 case DW_OP_const8u
:
21761 case DW_OP_const1u
:
21762 case DW_OP_const1s
:
21763 case DW_OP_const2u
:
21764 case DW_OP_const2s
:
21765 case DW_OP_const4s
:
21766 case DW_OP_const8s
:
21770 case DW_OP_plus_uconst
:
21806 case DW_OP_deref_size
:
21807 case DW_OP_xderef_size
:
21808 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
21815 gcc_assert (val1
->val_class
== dw_val_class_loc
);
21816 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
21817 hash
= iterative_hash_object (offset
, hash
);
21820 case DW_OP_implicit_value
:
21821 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
21822 switch (val2
->val_class
)
21824 case dw_val_class_const
:
21825 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
21827 case dw_val_class_vec
:
21829 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
21830 unsigned int len
= val2
->v
.val_vec
.length
;
21832 hash
= iterative_hash_object (elt_size
, hash
);
21833 hash
= iterative_hash_object (len
, hash
);
21834 hash
= iterative_hash (val2
->v
.val_vec
.array
,
21835 len
* elt_size
, hash
);
21838 case dw_val_class_const_double
:
21839 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
21840 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
21842 case dw_val_class_addr
:
21843 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
21846 gcc_unreachable ();
21850 case DW_OP_bit_piece
:
21851 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
21852 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
21858 unsigned char dtprel
= 0xd1;
21859 hash
= iterative_hash_object (dtprel
, hash
);
21861 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
21863 case DW_OP_GNU_implicit_pointer
:
21864 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
21866 case DW_OP_GNU_entry_value
:
21867 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
21869 case DW_OP_GNU_regval_type
:
21870 case DW_OP_GNU_deref_type
:
21872 unsigned int byte_size
21873 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
21874 unsigned int encoding
21875 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
21876 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
21877 hash
= iterative_hash_object (byte_size
, hash
);
21878 hash
= iterative_hash_object (encoding
, hash
);
21881 case DW_OP_GNU_convert
:
21882 case DW_OP_GNU_reinterpret
:
21883 if (val1
->val_class
== dw_val_class_unsigned_const
)
21885 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
21889 case DW_OP_GNU_const_type
:
21891 unsigned int byte_size
21892 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
21893 unsigned int encoding
21894 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
21895 hash
= iterative_hash_object (byte_size
, hash
);
21896 hash
= iterative_hash_object (encoding
, hash
);
21897 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
21899 hash
= iterative_hash_object (val2
->val_class
, hash
);
21900 switch (val2
->val_class
)
21902 case dw_val_class_const
:
21903 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
21905 case dw_val_class_vec
:
21907 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
21908 unsigned int len
= val2
->v
.val_vec
.length
;
21910 hash
= iterative_hash_object (elt_size
, hash
);
21911 hash
= iterative_hash_object (len
, hash
);
21912 hash
= iterative_hash (val2
->v
.val_vec
.array
,
21913 len
* elt_size
, hash
);
21916 case dw_val_class_const_double
:
21917 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
21918 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
21921 gcc_unreachable ();
21927 /* Other codes have no operands. */
21933 /* Iteratively hash the whole DWARF location expression LOC. */
21935 static inline hashval_t
21936 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
21938 dw_loc_descr_ref l
;
21939 bool sizes_computed
= false;
21940 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
21941 size_of_locs (loc
);
21943 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
21945 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
21946 hash
= iterative_hash_object (opc
, hash
);
21947 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
21949 size_of_locs (loc
);
21950 sizes_computed
= true;
21952 hash
= hash_loc_operands (l
, hash
);
21957 /* Compute hash of the whole location list LIST_HEAD. */
21960 hash_loc_list (dw_loc_list_ref list_head
)
21962 dw_loc_list_ref curr
= list_head
;
21963 hashval_t hash
= 0;
21965 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
21967 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
21968 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
21970 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
21972 hash
= hash_locs (curr
->expr
, hash
);
21974 list_head
->hash
= hash
;
21977 /* Return true if X and Y opcodes have the same operands. */
21980 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
21982 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
21983 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
21984 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
21985 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
21987 switch (x
->dw_loc_opc
)
21989 case DW_OP_const4u
:
21990 case DW_OP_const8u
:
21994 case DW_OP_const1u
:
21995 case DW_OP_const1s
:
21996 case DW_OP_const2u
:
21997 case DW_OP_const2s
:
21998 case DW_OP_const4s
:
21999 case DW_OP_const8s
:
22003 case DW_OP_plus_uconst
:
22039 case DW_OP_deref_size
:
22040 case DW_OP_xderef_size
:
22041 return valx1
->v
.val_int
== valy1
->v
.val_int
;
22044 gcc_assert (valx1
->val_class
== dw_val_class_loc
22045 && valy1
->val_class
== dw_val_class_loc
22046 && x
->dw_loc_addr
== y
->dw_loc_addr
);
22047 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
22048 case DW_OP_implicit_value
:
22049 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
22050 || valx2
->val_class
!= valy2
->val_class
)
22052 switch (valx2
->val_class
)
22054 case dw_val_class_const
:
22055 return valx2
->v
.val_int
== valy2
->v
.val_int
;
22056 case dw_val_class_vec
:
22057 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
22058 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
22059 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
22060 valx2
->v
.val_vec
.elt_size
22061 * valx2
->v
.val_vec
.length
) == 0;
22062 case dw_val_class_const_double
:
22063 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
22064 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
22065 case dw_val_class_addr
:
22066 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
22068 gcc_unreachable ();
22071 case DW_OP_bit_piece
:
22072 return valx1
->v
.val_int
== valy1
->v
.val_int
22073 && valx2
->v
.val_int
== valy2
->v
.val_int
;
22076 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
22077 case DW_OP_GNU_implicit_pointer
:
22078 return valx1
->val_class
== dw_val_class_die_ref
22079 && valx1
->val_class
== valy1
->val_class
22080 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
22081 && valx2
->v
.val_int
== valy2
->v
.val_int
;
22082 case DW_OP_GNU_entry_value
:
22083 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
22084 case DW_OP_GNU_const_type
:
22085 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
22086 || valx2
->val_class
!= valy2
->val_class
)
22088 switch (valx2
->val_class
)
22090 case dw_val_class_const
:
22091 return valx2
->v
.val_int
== valy2
->v
.val_int
;
22092 case dw_val_class_vec
:
22093 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
22094 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
22095 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
22096 valx2
->v
.val_vec
.elt_size
22097 * valx2
->v
.val_vec
.length
) == 0;
22098 case dw_val_class_const_double
:
22099 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
22100 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
22102 gcc_unreachable ();
22104 case DW_OP_GNU_regval_type
:
22105 case DW_OP_GNU_deref_type
:
22106 return valx1
->v
.val_int
== valy1
->v
.val_int
22107 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
22108 case DW_OP_GNU_convert
:
22109 case DW_OP_GNU_reinterpret
:
22110 if (valx1
->val_class
!= valy1
->val_class
)
22112 if (valx1
->val_class
== dw_val_class_unsigned_const
)
22113 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
22114 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
22115 case DW_OP_GNU_parameter_ref
:
22116 return valx1
->val_class
== dw_val_class_die_ref
22117 && valx1
->val_class
== valy1
->val_class
22118 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
22120 /* Other codes have no operands. */
22125 /* Return true if DWARF location expressions X and Y are the same. */
22128 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
22130 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
22131 if (x
->dw_loc_opc
!= y
->dw_loc_opc
22132 || x
->dtprel
!= y
->dtprel
22133 || !compare_loc_operands (x
, y
))
22135 return x
== NULL
&& y
== NULL
;
22138 /* Return precomputed hash of location list X. */
22141 loc_list_hash (const void *x
)
22143 return ((const struct dw_loc_list_struct
*) x
)->hash
;
22146 /* Return 1 if location lists X and Y are the same. */
22149 loc_list_eq (const void *x
, const void *y
)
22151 const struct dw_loc_list_struct
*a
= (const struct dw_loc_list_struct
*) x
;
22152 const struct dw_loc_list_struct
*b
= (const struct dw_loc_list_struct
*) y
;
22155 if (a
->hash
!= b
->hash
)
22157 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
22158 if (strcmp (a
->begin
, b
->begin
) != 0
22159 || strcmp (a
->end
, b
->end
) != 0
22160 || (a
->section
== NULL
) != (b
->section
== NULL
)
22161 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
22162 || !compare_locs (a
->expr
, b
->expr
))
22164 return a
== NULL
&& b
== NULL
;
22167 /* Recursively optimize location lists referenced from DIE
22168 children and share them whenever possible. */
22171 optimize_location_lists_1 (dw_die_ref die
, htab_t htab
)
22178 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
22179 if (AT_class (a
) == dw_val_class_loc_list
)
22181 dw_loc_list_ref list
= AT_loc_list (a
);
22182 /* TODO: perform some optimizations here, before hashing
22183 it and storing into the hash table. */
22184 hash_loc_list (list
);
22185 slot
= htab_find_slot_with_hash (htab
, list
, list
->hash
,
22188 *slot
= (void *) list
;
22190 a
->dw_attr_val
.v
.val_loc_list
= (dw_loc_list_ref
) *slot
;
22193 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
22196 /* Optimize location lists referenced from DIE
22197 children and share them whenever possible. */
22200 optimize_location_lists (dw_die_ref die
)
22202 htab_t htab
= htab_create (500, loc_list_hash
, loc_list_eq
, NULL
);
22203 optimize_location_lists_1 (die
, htab
);
22204 htab_delete (htab
);
22207 /* Output stuff that dwarf requires at the end of every file,
22208 and generate the DWARF-2 debugging info. */
22211 dwarf2out_finish (const char *filename
)
22213 limbo_die_node
*node
, *next_node
;
22214 comdat_type_node
*ctnode
;
22215 htab_t comdat_type_table
;
22218 /* PCH might result in DW_AT_producer string being restored from the
22219 header compilation, fix it up if needed. */
22220 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
22221 if (strcmp (AT_string (producer
), producer_string
) != 0)
22223 struct indirect_string_node
*node
= find_AT_string (producer_string
);
22224 producer
->dw_attr_val
.v
.val_str
= node
;
22227 gen_scheduled_generic_parms_dies ();
22228 gen_remaining_tmpl_value_param_die_attribute ();
22230 /* Add the name for the main input file now. We delayed this from
22231 dwarf2out_init to avoid complications with PCH. */
22232 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
22233 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
22234 add_comp_dir_attribute (comp_unit_die ());
22235 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
22238 htab_traverse (file_table
, file_table_relative_p
, &p
);
22240 add_comp_dir_attribute (comp_unit_die ());
22243 for (i
= 0; i
< VEC_length (deferred_locations
, deferred_locations_list
); i
++)
22245 add_location_or_const_value_attribute (
22246 VEC_index (deferred_locations
, deferred_locations_list
, i
)->die
,
22247 VEC_index (deferred_locations
, deferred_locations_list
, i
)->variable
,
22252 /* Traverse the limbo die list, and add parent/child links. The only
22253 dies without parents that should be here are concrete instances of
22254 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
22255 For concrete instances, we can get the parent die from the abstract
22257 for (node
= limbo_die_list
; node
; node
= next_node
)
22259 dw_die_ref die
= node
->die
;
22260 next_node
= node
->next
;
22262 if (die
->die_parent
== NULL
)
22264 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
22268 /* Find the first non-abstract parent instance. */
22270 origin
= origin
->die_parent
;
22272 && (origin
->die_tag
!= DW_TAG_subprogram
22273 || get_AT (origin
, DW_AT_inline
)));
22275 add_child_die (origin
, die
);
22277 add_child_die (comp_unit_die (), die
);
22279 else if (is_cu_die (die
))
22281 else if (seen_error ())
22282 /* It's OK to be confused by errors in the input. */
22283 add_child_die (comp_unit_die (), die
);
22286 /* In certain situations, the lexical block containing a
22287 nested function can be optimized away, which results
22288 in the nested function die being orphaned. Likewise
22289 with the return type of that nested function. Force
22290 this to be a child of the containing function.
22292 It may happen that even the containing function got fully
22293 inlined and optimized out. In that case we are lost and
22294 assign the empty child. This should not be big issue as
22295 the function is likely unreachable too. */
22296 gcc_assert (node
->created_for
);
22298 if (DECL_P (node
->created_for
))
22299 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
22300 else if (TYPE_P (node
->created_for
))
22301 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
22303 origin
= comp_unit_die ();
22305 add_child_die (origin
, die
);
22310 limbo_die_list
= NULL
;
22312 #if ENABLE_ASSERT_CHECKING
22314 dw_die_ref die
= comp_unit_die (), c
;
22315 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
22318 resolve_addr (comp_unit_die ());
22319 move_marked_base_types ();
22321 for (node
= deferred_asm_name
; node
; node
= node
->next
)
22323 tree decl
= node
->created_for
;
22324 /* When generating LTO bytecode we can not generate new assembler
22325 names at this point and all important decls got theirs via
22327 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
22328 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
22330 add_linkage_attr (node
->die
, decl
);
22331 move_linkage_attr (node
->die
);
22335 deferred_asm_name
= NULL
;
22337 /* Walk through the list of incomplete types again, trying once more to
22338 emit full debugging info for them. */
22339 retry_incomplete_types ();
22341 if (flag_eliminate_unused_debug_types
)
22342 prune_unused_types ();
22344 /* Generate separate COMDAT sections for type DIEs. */
22345 if (use_debug_types
)
22347 break_out_comdat_types (comp_unit_die ());
22349 /* Each new type_unit DIE was added to the limbo die list when created.
22350 Since these have all been added to comdat_type_list, clear the
22352 limbo_die_list
= NULL
;
22354 /* For each new comdat type unit, copy declarations for incomplete
22355 types to make the new unit self-contained (i.e., no direct
22356 references to the main compile unit). */
22357 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22358 copy_decls_for_unworthy_types (ctnode
->root_die
);
22359 copy_decls_for_unworthy_types (comp_unit_die ());
22361 /* In the process of copying declarations from one unit to another,
22362 we may have left some declarations behind that are no longer
22363 referenced. Prune them. */
22364 prune_unused_types ();
22367 /* Generate separate CUs for each of the include files we've seen.
22368 They will go into limbo_die_list. */
22369 if (flag_eliminate_dwarf2_dups
)
22370 break_out_includes (comp_unit_die ());
22372 /* Traverse the DIE's and add add sibling attributes to those DIE's
22373 that have children. */
22374 add_sibling_attributes (comp_unit_die ());
22375 for (node
= limbo_die_list
; node
; node
= node
->next
)
22376 add_sibling_attributes (node
->die
);
22377 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22378 add_sibling_attributes (ctnode
->root_die
);
22380 /* Output a terminator label for the .text section. */
22381 switch_to_section (text_section
);
22382 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
22383 if (cold_text_section
)
22385 switch_to_section (cold_text_section
);
22386 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
22389 /* We can only use the low/high_pc attributes if all of the code was
22391 if (!have_multiple_function_sections
22392 || (dwarf_version
< 3 && dwarf_strict
))
22394 /* Don't add if the CU has no associated code. */
22395 if (text_section_used
)
22397 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc
, text_section_label
);
22398 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc
, text_end_label
);
22405 bool range_list_added
= false;
22407 if (text_section_used
)
22408 add_ranges_by_labels (comp_unit_die (), text_section_label
,
22409 text_end_label
, &range_list_added
);
22410 if (cold_text_section_used
)
22411 add_ranges_by_labels (comp_unit_die (), cold_text_section_label
,
22412 cold_end_label
, &range_list_added
);
22414 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, fde_idx
, fde
)
22416 if (DECL_IGNORED_P (fde
->decl
))
22418 if (!fde
->in_std_section
)
22419 add_ranges_by_labels (comp_unit_die (), fde
->dw_fde_begin
,
22420 fde
->dw_fde_end
, &range_list_added
);
22421 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
22422 add_ranges_by_labels (comp_unit_die (), fde
->dw_fde_second_begin
,
22423 fde
->dw_fde_second_end
, &range_list_added
);
22426 if (range_list_added
)
22428 /* We need to give .debug_loc and .debug_ranges an appropriate
22429 "base address". Use zero so that these addresses become
22430 absolute. Historically, we've emitted the unexpected
22431 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
22432 Emit both to give time for other tools to adapt. */
22433 add_AT_addr (comp_unit_die (), DW_AT_low_pc
, const0_rtx
);
22434 if (! dwarf_strict
&& dwarf_version
< 4)
22435 add_AT_addr (comp_unit_die (), DW_AT_entry_pc
, const0_rtx
);
22441 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
22442 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list
,
22443 debug_line_section_label
);
22446 add_AT_macptr (comp_unit_die (),
22447 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
22448 macinfo_section_label
);
22450 if (have_location_lists
)
22451 optimize_location_lists (comp_unit_die ());
22453 /* Output all of the compilation units. We put the main one last so that
22454 the offsets are available to output_pubnames. */
22455 for (node
= limbo_die_list
; node
; node
= node
->next
)
22456 output_comp_unit (node
->die
, 0);
22458 comdat_type_table
= htab_create (100, htab_ct_hash
, htab_ct_eq
, NULL
);
22459 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22461 void **slot
= htab_find_slot (comdat_type_table
, ctnode
, INSERT
);
22463 /* Don't output duplicate types. */
22464 if (*slot
!= HTAB_EMPTY_ENTRY
)
22467 /* Add a pointer to the line table for the main compilation unit
22468 so that the debugger can make sense of DW_AT_decl_file
22470 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
22471 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
22472 debug_line_section_label
);
22474 output_comdat_type_unit (ctnode
);
22477 htab_delete (comdat_type_table
);
22479 add_AT_pubnames (comp_unit_die ());
22481 /* Output the main compilation unit if non-empty or if .debug_macinfo
22482 or .debug_macro will be emitted. */
22483 output_comp_unit (comp_unit_die (), have_macinfo
);
22485 /* Output the abbreviation table. */
22486 if (abbrev_die_table_in_use
!= 1)
22488 switch_to_section (debug_abbrev_section
);
22489 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
22490 output_abbrev_section ();
22493 /* Output location list section if necessary. */
22494 if (have_location_lists
)
22496 /* Output the location lists info. */
22497 switch_to_section (debug_loc_section
);
22498 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
22499 DEBUG_LOC_SECTION_LABEL
, 0);
22500 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
22501 output_location_lists (comp_unit_die ());
22504 /* Output public names and types tables if necessary. */
22505 output_pubnames (pubname_table
);
22506 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
22507 It shouldn't hurt to emit it always, since pure DWARF2 consumers
22508 simply won't look for the section. */
22509 output_pubnames (pubtype_table
);
22511 /* Output the address range information if a CU (.debug_info section)
22512 was emitted. We output an empty table even if we had no functions
22513 to put in it. This because the consumer has no way to tell the
22514 difference between an empty table that we omitted and failure to
22515 generate a table that would have contained data. */
22516 if (info_section_emitted
)
22518 unsigned long aranges_length
= size_of_aranges ();
22520 switch_to_section (debug_aranges_section
);
22521 output_aranges (aranges_length
);
22524 /* Output ranges section if necessary. */
22525 if (ranges_table_in_use
)
22527 switch_to_section (debug_ranges_section
);
22528 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
22532 /* Have to end the macro section. */
22535 switch_to_section (debug_macinfo_section
);
22536 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
22538 dw2_asm_output_data (1, 0, "End compilation unit");
22541 /* Output the source line correspondence table. We must do this
22542 even if there is no line information. Otherwise, on an empty
22543 translation unit, we will generate a present, but empty,
22544 .debug_info section. IRIX 6.5 `nm' will then complain when
22545 examining the file. This is done late so that any filenames
22546 used by the debug_info section are marked as 'used'. */
22547 switch_to_section (debug_line_section
);
22548 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
22549 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
22550 output_line_info ();
22552 /* If we emitted any DW_FORM_strp form attribute, output the string
22554 if (debug_str_hash
)
22555 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
22558 #include "gt-dwarf2out.h"