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 /* Generate a DIE to represent a declared function (either file-scope or
16832 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
16834 tree origin
= decl_ultimate_origin (decl
);
16835 dw_die_ref subr_die
;
16837 dw_die_ref old_die
= lookup_decl_die (decl
);
16838 int declaration
= (current_function_decl
!= decl
16839 || class_or_namespace_scope_p (context_die
));
16841 premark_used_types ();
16843 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
16844 started to generate the abstract instance of an inline, decided to output
16845 its containing class, and proceeded to emit the declaration of the inline
16846 from the member list for the class. If so, DECLARATION takes priority;
16847 we'll get back to the abstract instance when done with the class. */
16849 /* The class-scope declaration DIE must be the primary DIE. */
16850 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
16853 gcc_assert (!old_die
);
16856 /* Now that the C++ front end lazily declares artificial member fns, we
16857 might need to retrofit the declaration into its class. */
16858 if (!declaration
&& !origin
&& !old_die
16859 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
16860 && !class_or_namespace_scope_p (context_die
)
16861 && debug_info_level
> DINFO_LEVEL_TERSE
)
16862 old_die
= force_decl_die (decl
);
16864 if (origin
!= NULL
)
16866 gcc_assert (!declaration
|| local_scope_p (context_die
));
16868 /* Fixup die_parent for the abstract instance of a nested
16869 inline function. */
16870 if (old_die
&& old_die
->die_parent
== NULL
)
16871 add_child_die (context_die
, old_die
);
16873 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
16874 add_abstract_origin_attribute (subr_die
, origin
);
16875 /* This is where the actual code for a cloned function is.
16876 Let's emit linkage name attribute for it. This helps
16877 debuggers to e.g, set breakpoints into
16878 constructors/destructors when the user asks "break
16880 add_linkage_name (subr_die
, decl
);
16884 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16885 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
16887 if (!get_AT_flag (old_die
, DW_AT_declaration
)
16888 /* We can have a normal definition following an inline one in the
16889 case of redefinition of GNU C extern inlines.
16890 It seems reasonable to use AT_specification in this case. */
16891 && !get_AT (old_die
, DW_AT_inline
))
16893 /* Detect and ignore this case, where we are trying to output
16894 something we have already output. */
16898 /* If the definition comes from the same place as the declaration,
16899 maybe use the old DIE. We always want the DIE for this function
16900 that has the *_pc attributes to be under comp_unit_die so the
16901 debugger can find it. We also need to do this for abstract
16902 instances of inlines, since the spec requires the out-of-line copy
16903 to have the same parent. For local class methods, this doesn't
16904 apply; we just use the old DIE. */
16905 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
16906 && (DECL_ARTIFICIAL (decl
)
16907 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
16908 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
16909 == (unsigned) s
.line
))))
16911 subr_die
= old_die
;
16913 /* Clear out the declaration attribute and the formal parameters.
16914 Do not remove all children, because it is possible that this
16915 declaration die was forced using force_decl_die(). In such
16916 cases die that forced declaration die (e.g. TAG_imported_module)
16917 is one of the children that we do not want to remove. */
16918 remove_AT (subr_die
, DW_AT_declaration
);
16919 remove_AT (subr_die
, DW_AT_object_pointer
);
16920 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
16924 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
16925 add_AT_specification (subr_die
, old_die
);
16926 add_pubname (decl
, subr_die
);
16927 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
16928 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
16929 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
16930 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
16935 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
16937 if (TREE_PUBLIC (decl
))
16938 add_AT_flag (subr_die
, DW_AT_external
, 1);
16940 add_name_and_src_coords_attributes (subr_die
, decl
);
16941 add_pubname (decl
, subr_die
);
16942 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16944 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
16945 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
16946 0, 0, context_die
);
16949 add_pure_or_virtual_attribute (subr_die
, decl
);
16950 if (DECL_ARTIFICIAL (decl
))
16951 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
16953 add_accessibility_attribute (subr_die
, decl
);
16958 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
16960 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
16962 /* If this is an explicit function declaration then generate
16963 a DW_AT_explicit attribute. */
16964 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
16965 && (dwarf_version
>= 3 || !dwarf_strict
))
16966 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
16968 /* The first time we see a member function, it is in the context of
16969 the class to which it belongs. We make sure of this by emitting
16970 the class first. The next time is the definition, which is
16971 handled above. The two may come from the same source text.
16973 Note that force_decl_die() forces function declaration die. It is
16974 later reused to represent definition. */
16975 equate_decl_number_to_die (decl
, subr_die
);
16978 else if (DECL_ABSTRACT (decl
))
16980 if (DECL_DECLARED_INLINE_P (decl
))
16982 if (cgraph_function_possibly_inlined_p (decl
))
16983 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
16985 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
16989 if (cgraph_function_possibly_inlined_p (decl
))
16990 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
16992 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
16995 if (DECL_DECLARED_INLINE_P (decl
)
16996 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
16997 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
16999 equate_decl_number_to_die (decl
, subr_die
);
17001 else if (!DECL_EXTERNAL (decl
))
17003 HOST_WIDE_INT cfa_fb_offset
;
17005 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17006 equate_decl_number_to_die (decl
, subr_die
);
17008 if (!flag_reorder_blocks_and_partition
)
17010 dw_fde_ref fde
= cfun
->fde
;
17011 if (fde
->dw_fde_begin
)
17013 /* We have already generated the labels. */
17014 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, fde
->dw_fde_begin
);
17015 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, fde
->dw_fde_end
);
17019 /* Create start/end labels and add the range. */
17020 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
17021 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
17022 current_function_funcdef_no
);
17023 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
17024 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
17025 current_function_funcdef_no
);
17026 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
17029 #if VMS_DEBUGGING_INFO
17030 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17031 Section 2.3 Prologue and Epilogue Attributes:
17032 When a breakpoint is set on entry to a function, it is generally
17033 desirable for execution to be suspended, not on the very first
17034 instruction of the function, but rather at a point after the
17035 function's frame has been set up, after any language defined local
17036 declaration processing has been completed, and before execution of
17037 the first statement of the function begins. Debuggers generally
17038 cannot properly determine where this point is. Similarly for a
17039 breakpoint set on exit from a function. The prologue and epilogue
17040 attributes allow a compiler to communicate the location(s) to use. */
17043 if (fde
->dw_fde_vms_end_prologue
)
17044 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
17045 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
17047 if (fde
->dw_fde_vms_begin_epilogue
)
17048 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
17049 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
17056 /* Generate pubnames entries for the split function code ranges. */
17057 dw_fde_ref fde
= cfun
->fde
;
17059 if (fde
->dw_fde_second_begin
)
17061 if (dwarf_version
>= 3 || !dwarf_strict
)
17063 /* We should use ranges for non-contiguous code section
17064 addresses. Use the actual code range for the initial
17065 section, since the HOT/COLD labels might precede an
17066 alignment offset. */
17067 bool range_list_added
= false;
17068 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
17069 fde
->dw_fde_end
, &range_list_added
);
17070 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
17071 fde
->dw_fde_second_end
,
17072 &range_list_added
);
17073 if (range_list_added
)
17078 /* There is no real support in DW2 for this .. so we make
17079 a work-around. First, emit the pub name for the segment
17080 containing the function label. Then make and emit a
17081 simplified subprogram DIE for the second segment with the
17082 name pre-fixed by __hot/cold_sect_of_. We use the same
17083 linkage name for the second die so that gdb will find both
17084 sections when given "b foo". */
17085 const char *name
= NULL
;
17086 tree decl_name
= DECL_NAME (decl
);
17087 dw_die_ref seg_die
;
17089 /* Do the 'primary' section. */
17090 add_AT_lbl_id (subr_die
, DW_AT_low_pc
,
17091 fde
->dw_fde_begin
);
17092 add_AT_lbl_id (subr_die
, DW_AT_high_pc
,
17095 /* Build a minimal DIE for the secondary section. */
17096 seg_die
= new_die (DW_TAG_subprogram
,
17097 subr_die
->die_parent
, decl
);
17099 if (TREE_PUBLIC (decl
))
17100 add_AT_flag (seg_die
, DW_AT_external
, 1);
17102 if (decl_name
!= NULL
17103 && IDENTIFIER_POINTER (decl_name
) != NULL
)
17105 name
= dwarf2_name (decl
, 1);
17106 if (! DECL_ARTIFICIAL (decl
))
17107 add_src_coords_attributes (seg_die
, decl
);
17109 add_linkage_name (seg_die
, decl
);
17111 gcc_assert (name
!= NULL
);
17112 add_pure_or_virtual_attribute (seg_die
, decl
);
17113 if (DECL_ARTIFICIAL (decl
))
17114 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
17116 name
= concat ("__second_sect_of_", name
, NULL
);
17117 add_AT_lbl_id (seg_die
, DW_AT_low_pc
,
17118 fde
->dw_fde_second_begin
);
17119 add_AT_lbl_id (seg_die
, DW_AT_high_pc
,
17120 fde
->dw_fde_second_end
);
17121 add_name_attribute (seg_die
, name
);
17122 if (want_pubnames ())
17123 add_pubname_string (name
, seg_die
);
17128 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, fde
->dw_fde_begin
);
17129 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, fde
->dw_fde_end
);
17133 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
17135 /* We define the "frame base" as the function's CFA. This is more
17136 convenient for several reasons: (1) It's stable across the prologue
17137 and epilogue, which makes it better than just a frame pointer,
17138 (2) With dwarf3, there exists a one-byte encoding that allows us
17139 to reference the .debug_frame data by proxy, but failing that,
17140 (3) We can at least reuse the code inspection and interpretation
17141 code that determines the CFA position at various points in the
17143 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
17145 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
17146 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
17150 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
17151 if (list
->dw_loc_next
)
17152 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
17154 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
17157 /* Compute a displacement from the "steady-state frame pointer" to
17158 the CFA. The former is what all stack slots and argument slots
17159 will reference in the rtl; the later is what we've told the
17160 debugger about. We'll need to adjust all frame_base references
17161 by this displacement. */
17162 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
17164 if (cfun
->static_chain_decl
)
17165 add_AT_location_description (subr_die
, DW_AT_static_link
,
17166 loc_list_from_tree (cfun
->static_chain_decl
, 2));
17169 /* Generate child dies for template paramaters. */
17170 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17171 gen_generic_params_dies (decl
);
17173 /* Now output descriptions of the arguments for this function. This gets
17174 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
17175 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
17176 `...' at the end of the formal parameter list. In order to find out if
17177 there was a trailing ellipsis or not, we must instead look at the type
17178 associated with the FUNCTION_DECL. This will be a node of type
17179 FUNCTION_TYPE. If the chain of type nodes hanging off of this
17180 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
17181 an ellipsis at the end. */
17183 /* In the case where we are describing a mere function declaration, all we
17184 need to do here (and all we *can* do here) is to describe the *types* of
17185 its formal parameters. */
17186 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
17188 else if (declaration
)
17189 gen_formal_types_die (decl
, subr_die
);
17192 /* Generate DIEs to represent all known formal parameters. */
17193 tree parm
= DECL_ARGUMENTS (decl
);
17194 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
17195 tree generic_decl_parm
= generic_decl
17196 ? DECL_ARGUMENTS (generic_decl
)
17199 /* Now we want to walk the list of parameters of the function and
17200 emit their relevant DIEs.
17202 We consider the case of DECL being an instance of a generic function
17203 as well as it being a normal function.
17205 If DECL is an instance of a generic function we walk the
17206 parameters of the generic function declaration _and_ the parameters of
17207 DECL itself. This is useful because we want to emit specific DIEs for
17208 function parameter packs and those are declared as part of the
17209 generic function declaration. In that particular case,
17210 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
17211 That DIE has children DIEs representing the set of arguments
17212 of the pack. Note that the set of pack arguments can be empty.
17213 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
17216 Otherwise, we just consider the parameters of DECL. */
17217 while (generic_decl_parm
|| parm
)
17219 if (generic_decl_parm
17220 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
17221 gen_formal_parameter_pack_die (generic_decl_parm
,
17226 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
17228 if (parm
== DECL_ARGUMENTS (decl
)
17229 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
17231 && (dwarf_version
>= 3 || !dwarf_strict
))
17232 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
17234 parm
= DECL_CHAIN (parm
);
17237 if (generic_decl_parm
)
17238 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
17241 /* Decide whether we need an unspecified_parameters DIE at the end.
17242 There are 2 more cases to do this for: 1) the ansi ... declaration -
17243 this is detectable when the end of the arg list is not a
17244 void_type_node 2) an unprototyped function declaration (not a
17245 definition). This just means that we have no info about the
17246 parameters at all. */
17247 if (prototype_p (TREE_TYPE (decl
)))
17249 /* This is the prototyped case, check for.... */
17250 if (stdarg_p (TREE_TYPE (decl
)))
17251 gen_unspecified_parameters_die (decl
, subr_die
);
17253 else if (DECL_INITIAL (decl
) == NULL_TREE
)
17254 gen_unspecified_parameters_die (decl
, subr_die
);
17257 /* Output Dwarf info for all of the stuff within the body of the function
17258 (if it has one - it may be just a declaration). */
17259 outer_scope
= DECL_INITIAL (decl
);
17261 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
17262 a function. This BLOCK actually represents the outermost binding contour
17263 for the function, i.e. the contour in which the function's formal
17264 parameters and labels get declared. Curiously, it appears that the front
17265 end doesn't actually put the PARM_DECL nodes for the current function onto
17266 the BLOCK_VARS list for this outer scope, but are strung off of the
17267 DECL_ARGUMENTS list for the function instead.
17269 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
17270 the LABEL_DECL nodes for the function however, and we output DWARF info
17271 for those in decls_for_scope. Just within the `outer_scope' there will be
17272 a BLOCK node representing the function's outermost pair of curly braces,
17273 and any blocks used for the base and member initializers of a C++
17274 constructor function. */
17275 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
17277 int call_site_note_count
= 0;
17278 int tail_call_site_note_count
= 0;
17280 /* Emit a DW_TAG_variable DIE for a named return value. */
17281 if (DECL_NAME (DECL_RESULT (decl
)))
17282 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
17284 current_function_has_inlines
= 0;
17285 decls_for_scope (outer_scope
, subr_die
, 0);
17287 if (call_arg_locations
&& !dwarf_strict
)
17289 struct call_arg_loc_node
*ca_loc
;
17290 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
17292 dw_die_ref die
= NULL
;
17293 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
17296 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
17297 arg
; arg
= next_arg
)
17299 dw_loc_descr_ref reg
, val
;
17300 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
17301 dw_die_ref cdie
, tdie
= NULL
;
17303 next_arg
= XEXP (arg
, 1);
17304 if (REG_P (XEXP (XEXP (arg
, 0), 0))
17306 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
17307 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
17308 && REGNO (XEXP (XEXP (arg
, 0), 0))
17309 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
17310 next_arg
= XEXP (next_arg
, 1);
17311 if (mode
== VOIDmode
)
17313 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
17314 if (mode
== VOIDmode
)
17315 mode
= GET_MODE (XEXP (arg
, 0));
17317 if (mode
== VOIDmode
|| mode
== BLKmode
)
17319 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
17321 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
17322 tloc
= XEXP (XEXP (arg
, 0), 1);
17325 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
17326 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
17328 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
17329 tlocc
= XEXP (XEXP (arg
, 0), 1);
17333 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
17334 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
17335 VAR_INIT_STATUS_INITIALIZED
);
17336 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
17338 rtx mem
= XEXP (XEXP (arg
, 0), 0);
17339 reg
= mem_loc_descriptor (XEXP (mem
, 0),
17340 get_address_mode (mem
),
17342 VAR_INIT_STATUS_INITIALIZED
);
17344 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
17345 == DEBUG_PARAMETER_REF
)
17348 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
17349 tdie
= lookup_decl_die (tdecl
);
17356 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
17357 != DEBUG_PARAMETER_REF
)
17359 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
17361 VAR_INIT_STATUS_INITIALIZED
);
17365 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
17366 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
17369 add_AT_loc (cdie
, DW_AT_location
, reg
);
17370 else if (tdie
!= NULL
)
17371 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
17372 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
17373 if (next_arg
!= XEXP (arg
, 1))
17375 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
17376 if (mode
== VOIDmode
)
17377 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
17378 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
17381 VAR_INIT_STATUS_INITIALIZED
);
17383 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
17387 && (ca_loc
->symbol_ref
|| tloc
))
17388 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
17389 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
17391 dw_loc_descr_ref tval
= NULL
;
17393 if (tloc
!= NULL_RTX
)
17394 tval
= mem_loc_descriptor (tloc
,
17395 GET_MODE (tloc
) == VOIDmode
17396 ? Pmode
: GET_MODE (tloc
),
17398 VAR_INIT_STATUS_INITIALIZED
);
17400 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
17401 else if (tlocc
!= NULL_RTX
)
17403 tval
= mem_loc_descriptor (tlocc
,
17404 GET_MODE (tlocc
) == VOIDmode
17405 ? Pmode
: GET_MODE (tlocc
),
17407 VAR_INIT_STATUS_INITIALIZED
);
17409 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
17415 call_site_note_count
++;
17416 if (ca_loc
->tail_call_p
)
17417 tail_call_site_note_count
++;
17421 call_arg_locations
= NULL
;
17422 call_arg_loc_last
= NULL
;
17423 if (tail_call_site_count
>= 0
17424 && tail_call_site_count
== tail_call_site_note_count
17427 if (call_site_count
>= 0
17428 && call_site_count
== call_site_note_count
)
17429 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
17431 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
17433 call_site_count
= -1;
17434 tail_call_site_count
= -1;
17436 /* Add the calling convention attribute if requested. */
17437 add_calling_convention_attribute (subr_die
, decl
);
17441 /* Returns a hash value for X (which really is a die_struct). */
17444 common_block_die_table_hash (const void *x
)
17446 const_dw_die_ref d
= (const_dw_die_ref
) x
;
17447 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
17450 /* Return nonzero if decl_id and die_parent of die_struct X is the same
17451 as decl_id and die_parent of die_struct Y. */
17454 common_block_die_table_eq (const void *x
, const void *y
)
17456 const_dw_die_ref d
= (const_dw_die_ref
) x
;
17457 const_dw_die_ref e
= (const_dw_die_ref
) y
;
17458 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
17461 /* Generate a DIE to represent a declared data object.
17462 Either DECL or ORIGIN must be non-null. */
17465 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
17467 HOST_WIDE_INT off
= 0;
17469 tree decl_or_origin
= decl
? decl
: origin
;
17470 tree ultimate_origin
;
17471 dw_die_ref var_die
;
17472 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
17473 dw_die_ref origin_die
;
17474 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
17475 || class_or_namespace_scope_p (context_die
));
17476 bool specialization_p
= false;
17478 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
17479 if (decl
|| ultimate_origin
)
17480 origin
= ultimate_origin
;
17481 com_decl
= fortran_common (decl_or_origin
, &off
);
17483 /* Symbol in common gets emitted as a child of the common block, in the form
17484 of a data member. */
17487 dw_die_ref com_die
;
17488 dw_loc_list_ref loc
;
17489 die_node com_die_arg
;
17491 var_die
= lookup_decl_die (decl_or_origin
);
17494 if (get_AT (var_die
, DW_AT_location
) == NULL
)
17496 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
17501 /* Optimize the common case. */
17502 if (single_element_loc_list_p (loc
)
17503 && loc
->expr
->dw_loc_opc
== DW_OP_addr
17504 && loc
->expr
->dw_loc_next
== NULL
17505 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
17508 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
17509 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
17510 = plus_constant (GET_MODE (x
), x
, off
);
17513 loc_list_plus_const (loc
, off
);
17515 add_AT_location_description (var_die
, DW_AT_location
, loc
);
17516 remove_AT (var_die
, DW_AT_declaration
);
17522 if (common_block_die_table
== NULL
)
17523 common_block_die_table
17524 = htab_create_ggc (10, common_block_die_table_hash
,
17525 common_block_die_table_eq
, NULL
);
17527 com_die_arg
.decl_id
= DECL_UID (com_decl
);
17528 com_die_arg
.die_parent
= context_die
;
17529 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
17530 loc
= loc_list_from_tree (com_decl
, 2);
17531 if (com_die
== NULL
)
17534 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
17537 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
17538 add_name_and_src_coords_attributes (com_die
, com_decl
);
17541 add_AT_location_description (com_die
, DW_AT_location
, loc
);
17542 /* Avoid sharing the same loc descriptor between
17543 DW_TAG_common_block and DW_TAG_variable. */
17544 loc
= loc_list_from_tree (com_decl
, 2);
17546 else if (DECL_EXTERNAL (decl
))
17547 add_AT_flag (com_die
, DW_AT_declaration
, 1);
17548 if (want_pubnames ())
17549 add_pubname_string (cnam
, com_die
); /* ??? needed? */
17550 com_die
->decl_id
= DECL_UID (com_decl
);
17551 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
17552 *slot
= (void *) com_die
;
17554 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
17556 add_AT_location_description (com_die
, DW_AT_location
, loc
);
17557 loc
= loc_list_from_tree (com_decl
, 2);
17558 remove_AT (com_die
, DW_AT_declaration
);
17560 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
17561 add_name_and_src_coords_attributes (var_die
, decl
);
17562 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
17563 TREE_THIS_VOLATILE (decl
), context_die
);
17564 add_AT_flag (var_die
, DW_AT_external
, 1);
17569 /* Optimize the common case. */
17570 if (single_element_loc_list_p (loc
)
17571 && loc
->expr
->dw_loc_opc
== DW_OP_addr
17572 && loc
->expr
->dw_loc_next
== NULL
17573 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
17575 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
17576 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
17577 = plus_constant (GET_MODE (x
), x
, off
);
17580 loc_list_plus_const (loc
, off
);
17582 add_AT_location_description (var_die
, DW_AT_location
, loc
);
17584 else if (DECL_EXTERNAL (decl
))
17585 add_AT_flag (var_die
, DW_AT_declaration
, 1);
17586 equate_decl_number_to_die (decl
, var_die
);
17590 /* If the compiler emitted a definition for the DECL declaration
17591 and if we already emitted a DIE for it, don't emit a second
17592 DIE for it again. Allow re-declarations of DECLs that are
17593 inside functions, though. */
17594 if (old_die
&& declaration
&& !local_scope_p (context_die
))
17597 /* For static data members, the declaration in the class is supposed
17598 to have DW_TAG_member tag; the specification should still be
17599 DW_TAG_variable referencing the DW_TAG_member DIE. */
17600 if (declaration
&& class_scope_p (context_die
))
17601 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
17603 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
17606 if (origin
!= NULL
)
17607 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
17609 /* Loop unrolling can create multiple blocks that refer to the same
17610 static variable, so we must test for the DW_AT_declaration flag.
17612 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
17613 copy decls and set the DECL_ABSTRACT flag on them instead of
17616 ??? Duplicated blocks have been rewritten to use .debug_ranges.
17618 ??? The declare_in_namespace support causes us to get two DIEs for one
17619 variable, both of which are declarations. We want to avoid considering
17620 one to be a specification, so we must test that this DIE is not a
17622 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
17623 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
17625 /* This is a definition of a C++ class level static. */
17626 add_AT_specification (var_die
, old_die
);
17627 specialization_p
= true;
17628 if (DECL_NAME (decl
))
17630 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17631 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17633 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17634 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
17636 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17637 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
17639 if (old_die
->die_tag
== DW_TAG_member
)
17640 add_linkage_name (var_die
, decl
);
17644 add_name_and_src_coords_attributes (var_die
, decl
);
17646 if ((origin
== NULL
&& !specialization_p
)
17648 && !DECL_ABSTRACT (decl_or_origin
)
17649 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
17650 decl_function_context
17651 (decl_or_origin
))))
17653 tree type
= TREE_TYPE (decl_or_origin
);
17655 if (decl_by_reference_p (decl_or_origin
))
17656 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
17658 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
17659 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
17662 if (origin
== NULL
&& !specialization_p
)
17664 if (TREE_PUBLIC (decl
))
17665 add_AT_flag (var_die
, DW_AT_external
, 1);
17667 if (DECL_ARTIFICIAL (decl
))
17668 add_AT_flag (var_die
, DW_AT_artificial
, 1);
17670 add_accessibility_attribute (var_die
, decl
);
17674 add_AT_flag (var_die
, DW_AT_declaration
, 1);
17676 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
17677 equate_decl_number_to_die (decl
, var_die
);
17680 && (! DECL_ABSTRACT (decl_or_origin
)
17681 /* Local static vars are shared between all clones/inlines,
17682 so emit DW_AT_location on the abstract DIE if DECL_RTL is
17684 || (TREE_CODE (decl_or_origin
) == VAR_DECL
17685 && TREE_STATIC (decl_or_origin
)
17686 && DECL_RTL_SET_P (decl_or_origin
)))
17687 /* When abstract origin already has DW_AT_location attribute, no need
17688 to add it again. */
17689 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
17691 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
17692 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
17693 defer_location (decl_or_origin
, var_die
);
17695 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
17696 decl
== NULL
, DW_AT_location
);
17697 add_pubname (decl_or_origin
, var_die
);
17700 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
17703 /* Generate a DIE to represent a named constant. */
17706 gen_const_die (tree decl
, dw_die_ref context_die
)
17708 dw_die_ref const_die
;
17709 tree type
= TREE_TYPE (decl
);
17711 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
17712 add_name_and_src_coords_attributes (const_die
, decl
);
17713 add_type_attribute (const_die
, type
, 1, 0, context_die
);
17714 if (TREE_PUBLIC (decl
))
17715 add_AT_flag (const_die
, DW_AT_external
, 1);
17716 if (DECL_ARTIFICIAL (decl
))
17717 add_AT_flag (const_die
, DW_AT_artificial
, 1);
17718 tree_add_const_value_attribute_for_decl (const_die
, decl
);
17721 /* Generate a DIE to represent a label identifier. */
17724 gen_label_die (tree decl
, dw_die_ref context_die
)
17726 tree origin
= decl_ultimate_origin (decl
);
17727 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
17729 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
17731 if (origin
!= NULL
)
17732 add_abstract_origin_attribute (lbl_die
, origin
);
17734 add_name_and_src_coords_attributes (lbl_die
, decl
);
17736 if (DECL_ABSTRACT (decl
))
17737 equate_decl_number_to_die (decl
, lbl_die
);
17740 insn
= DECL_RTL_IF_SET (decl
);
17742 /* Deleted labels are programmer specified labels which have been
17743 eliminated because of various optimizations. We still emit them
17744 here so that it is possible to put breakpoints on them. */
17748 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
17750 /* When optimization is enabled (via -O) some parts of the compiler
17751 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
17752 represent source-level labels which were explicitly declared by
17753 the user. This really shouldn't be happening though, so catch
17754 it if it ever does happen. */
17755 gcc_assert (!INSN_DELETED_P (insn
));
17757 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
17758 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
17762 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
17763 && CODE_LABEL_NUMBER (insn
) != -1)
17765 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
17766 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
17771 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
17772 attributes to the DIE for a block STMT, to describe where the inlined
17773 function was called from. This is similar to add_src_coords_attributes. */
17776 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
17778 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
17780 if (dwarf_version
>= 3 || !dwarf_strict
)
17782 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
17783 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
17788 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
17789 Add low_pc and high_pc attributes to the DIE for a block STMT. */
17792 add_high_low_attributes (tree stmt
, dw_die_ref die
)
17794 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
17796 if (BLOCK_FRAGMENT_CHAIN (stmt
)
17797 && (dwarf_version
>= 3 || !dwarf_strict
))
17799 tree chain
, superblock
= NULL_TREE
;
17801 dw_attr_ref attr
= NULL
;
17803 if (inlined_function_outer_scope_p (stmt
))
17805 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
17806 BLOCK_NUMBER (stmt
));
17807 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
17810 /* Optimize duplicate .debug_ranges lists or even tails of
17811 lists. If this BLOCK has same ranges as its supercontext,
17812 lookup DW_AT_ranges attribute in the supercontext (and
17813 recursively so), verify that the ranges_table contains the
17814 right values and use it instead of adding a new .debug_range. */
17815 for (chain
= stmt
, pdie
= die
;
17816 BLOCK_SAME_RANGE (chain
);
17817 chain
= BLOCK_SUPERCONTEXT (chain
))
17819 dw_attr_ref new_attr
;
17821 pdie
= pdie
->die_parent
;
17824 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
17826 new_attr
= get_AT (pdie
, DW_AT_ranges
);
17827 if (new_attr
== NULL
17828 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
17831 superblock
= BLOCK_SUPERCONTEXT (chain
);
17834 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
17835 / 2 / DWARF2_ADDR_SIZE
].num
17836 == BLOCK_NUMBER (superblock
))
17837 && BLOCK_FRAGMENT_CHAIN (superblock
))
17839 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
17840 / 2 / DWARF2_ADDR_SIZE
;
17841 unsigned long supercnt
= 0, thiscnt
= 0;
17842 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
17843 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
17846 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
17847 == BLOCK_NUMBER (chain
));
17849 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
17850 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
17851 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
17853 gcc_assert (supercnt
>= thiscnt
);
17854 add_AT_range_list (die
, DW_AT_ranges
,
17855 (off
+ supercnt
- thiscnt
)
17856 * 2 * DWARF2_ADDR_SIZE
);
17860 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
));
17862 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
17865 add_ranges (chain
);
17866 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
17873 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
17874 BLOCK_NUMBER (stmt
));
17875 add_AT_lbl_id (die
, DW_AT_low_pc
, label
);
17876 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
17877 BLOCK_NUMBER (stmt
));
17878 add_AT_lbl_id (die
, DW_AT_high_pc
, label
);
17882 /* Generate a DIE for a lexical block. */
17885 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
17887 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
17889 if (call_arg_locations
)
17891 if (VEC_length (dw_die_ref
, block_map
) <= BLOCK_NUMBER (stmt
))
17892 VEC_safe_grow_cleared (dw_die_ref
, heap
, block_map
,
17893 BLOCK_NUMBER (stmt
) + 1);
17894 VEC_replace (dw_die_ref
, block_map
, BLOCK_NUMBER (stmt
), stmt_die
);
17897 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
17898 add_high_low_attributes (stmt
, stmt_die
);
17900 decls_for_scope (stmt
, stmt_die
, depth
);
17903 /* Generate a DIE for an inlined subprogram. */
17906 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
17910 /* The instance of function that is effectively being inlined shall not
17912 gcc_assert (! BLOCK_ABSTRACT (stmt
));
17914 decl
= block_ultimate_origin (stmt
);
17916 /* Emit info for the abstract instance first, if we haven't yet. We
17917 must emit this even if the block is abstract, otherwise when we
17918 emit the block below (or elsewhere), we may end up trying to emit
17919 a die whose origin die hasn't been emitted, and crashing. */
17920 dwarf2out_abstract_function (decl
);
17922 if (! BLOCK_ABSTRACT (stmt
))
17924 dw_die_ref subr_die
17925 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
17927 if (call_arg_locations
)
17929 if (VEC_length (dw_die_ref
, block_map
) <= BLOCK_NUMBER (stmt
))
17930 VEC_safe_grow_cleared (dw_die_ref
, heap
, block_map
,
17931 BLOCK_NUMBER (stmt
) + 1);
17932 VEC_replace (dw_die_ref
, block_map
, BLOCK_NUMBER (stmt
), subr_die
);
17934 add_abstract_origin_attribute (subr_die
, decl
);
17935 if (TREE_ASM_WRITTEN (stmt
))
17936 add_high_low_attributes (stmt
, subr_die
);
17937 add_call_src_coords_attributes (stmt
, subr_die
);
17939 decls_for_scope (stmt
, subr_die
, depth
);
17940 current_function_has_inlines
= 1;
17944 /* Generate a DIE for a field in a record, or structure. */
17947 gen_field_die (tree decl
, dw_die_ref context_die
)
17949 dw_die_ref decl_die
;
17951 if (TREE_TYPE (decl
) == error_mark_node
)
17954 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
17955 add_name_and_src_coords_attributes (decl_die
, decl
);
17956 add_type_attribute (decl_die
, member_declared_type (decl
),
17957 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
17960 if (DECL_BIT_FIELD_TYPE (decl
))
17962 add_byte_size_attribute (decl_die
, decl
);
17963 add_bit_size_attribute (decl_die
, decl
);
17964 add_bit_offset_attribute (decl_die
, decl
);
17967 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
17968 add_data_member_location_attribute (decl_die
, decl
);
17970 if (DECL_ARTIFICIAL (decl
))
17971 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
17973 add_accessibility_attribute (decl_die
, decl
);
17975 /* Equate decl number to die, so that we can look up this decl later on. */
17976 equate_decl_number_to_die (decl
, decl_die
);
17980 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
17981 Use modified_type_die instead.
17982 We keep this code here just in case these types of DIEs may be needed to
17983 represent certain things in other languages (e.g. Pascal) someday. */
17986 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
17989 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
17991 equate_type_number_to_die (type
, ptr_die
);
17992 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
17993 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
17996 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
17997 Use modified_type_die instead.
17998 We keep this code here just in case these types of DIEs may be needed to
17999 represent certain things in other languages (e.g. Pascal) someday. */
18002 gen_reference_type_die (tree type
, dw_die_ref context_die
)
18004 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
18006 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
18007 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
18009 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
18011 equate_type_number_to_die (type
, ref_die
);
18012 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
18013 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18017 /* Generate a DIE for a pointer to a member type. */
18020 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
18023 = new_die (DW_TAG_ptr_to_member_type
,
18024 scope_die_for (type
, context_die
), type
);
18026 equate_type_number_to_die (type
, ptr_die
);
18027 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
18028 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
18029 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18032 typedef const char *dchar_p
; /* For DEF_VEC_P. */
18033 DEF_VEC_P(dchar_p
);
18034 DEF_VEC_ALLOC_P(dchar_p
,heap
);
18036 static char *producer_string
;
18038 /* Return a heap allocated producer string including command line options
18039 if -grecord-gcc-switches. */
18042 gen_producer_string (void)
18045 VEC(dchar_p
, heap
) *switches
= NULL
;
18046 const char *language_string
= lang_hooks
.name
;
18047 char *producer
, *tail
;
18049 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
18050 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
18052 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
18053 switch (save_decoded_options
[j
].opt_index
)
18060 case OPT_auxbase_strip
:
18069 case OPT_SPECIAL_unknown
:
18070 case OPT_SPECIAL_ignore
:
18071 case OPT_SPECIAL_program_name
:
18072 case OPT_SPECIAL_input_file
:
18073 case OPT_grecord_gcc_switches
:
18074 case OPT_gno_record_gcc_switches
:
18075 case OPT__output_pch_
:
18076 case OPT_fdiagnostics_show_location_
:
18077 case OPT_fdiagnostics_show_option
:
18078 case OPT_fdiagnostics_show_caret
:
18079 case OPT_fverbose_asm
:
18081 case OPT__sysroot_
:
18083 case OPT_nostdinc__
:
18084 /* Ignore these. */
18087 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
18089 switch (save_decoded_options
[j
].canonical_option
[0][1])
18096 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
18103 VEC_safe_push (dchar_p
, heap
, switches
,
18104 save_decoded_options
[j
].orig_option_with_args_text
);
18105 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
18109 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
18111 sprintf (tail
, "%s %s", language_string
, version_string
);
18114 FOR_EACH_VEC_ELT (dchar_p
, switches
, j
, p
)
18118 memcpy (tail
+ 1, p
, len
);
18123 VEC_free (dchar_p
, heap
, switches
);
18127 /* Generate the DIE for the compilation unit. */
18130 gen_compile_unit_die (const char *filename
)
18133 const char *language_string
= lang_hooks
.name
;
18136 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
18140 add_name_attribute (die
, filename
);
18141 /* Don't add cwd for <built-in>. */
18142 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
18143 add_comp_dir_attribute (die
);
18146 if (producer_string
== NULL
)
18147 producer_string
= gen_producer_string ();
18148 add_AT_string (die
, DW_AT_producer
, producer_string
);
18150 /* If our producer is LTO try to figure out a common language to use
18151 from the global list of translation units. */
18152 if (strcmp (language_string
, "GNU GIMPLE") == 0)
18156 const char *common_lang
= NULL
;
18158 FOR_EACH_VEC_ELT (tree
, all_translation_units
, i
, t
)
18160 if (!TRANSLATION_UNIT_LANGUAGE (t
))
18163 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
18164 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
18166 else if (strncmp (common_lang
, "GNU C", 5) == 0
18167 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
18168 /* Mixing C and C++ is ok, use C++ in that case. */
18169 common_lang
= "GNU C++";
18172 /* Fall back to C. */
18173 common_lang
= NULL
;
18179 language_string
= common_lang
;
18182 language
= DW_LANG_C89
;
18183 if (strcmp (language_string
, "GNU C++") == 0)
18184 language
= DW_LANG_C_plus_plus
;
18185 else if (strcmp (language_string
, "GNU F77") == 0)
18186 language
= DW_LANG_Fortran77
;
18187 else if (strcmp (language_string
, "GNU Pascal") == 0)
18188 language
= DW_LANG_Pascal83
;
18189 else if (dwarf_version
>= 3 || !dwarf_strict
)
18191 if (strcmp (language_string
, "GNU Ada") == 0)
18192 language
= DW_LANG_Ada95
;
18193 else if (strcmp (language_string
, "GNU Fortran") == 0)
18194 language
= DW_LANG_Fortran95
;
18195 else if (strcmp (language_string
, "GNU Java") == 0)
18196 language
= DW_LANG_Java
;
18197 else if (strcmp (language_string
, "GNU Objective-C") == 0)
18198 language
= DW_LANG_ObjC
;
18199 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
18200 language
= DW_LANG_ObjC_plus_plus
;
18201 else if (dwarf_version
>= 5 || !dwarf_strict
)
18203 if (strcmp (language_string
, "GNU Go") == 0)
18204 language
= DW_LANG_Go
;
18207 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
18208 else if (strcmp (language_string
, "GNU Fortran") == 0)
18209 language
= DW_LANG_Fortran90
;
18211 add_AT_unsigned (die
, DW_AT_language
, language
);
18215 case DW_LANG_Fortran77
:
18216 case DW_LANG_Fortran90
:
18217 case DW_LANG_Fortran95
:
18218 /* Fortran has case insensitive identifiers and the front-end
18219 lowercases everything. */
18220 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
18223 /* The default DW_ID_case_sensitive doesn't need to be specified. */
18229 /* Generate the DIE for a base class. */
18232 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
18234 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
18236 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
18237 add_data_member_location_attribute (die
, binfo
);
18239 if (BINFO_VIRTUAL_P (binfo
))
18240 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
18242 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18243 children, otherwise the default is DW_ACCESS_public. In DWARF2
18244 the default has always been DW_ACCESS_private. */
18245 if (access
== access_public_node
)
18247 if (dwarf_version
== 2
18248 || context_die
->die_tag
== DW_TAG_class_type
)
18249 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
18251 else if (access
== access_protected_node
)
18252 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
18253 else if (dwarf_version
> 2
18254 && context_die
->die_tag
!= DW_TAG_class_type
)
18255 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
18258 /* Generate a DIE for a class member. */
18261 gen_member_die (tree type
, dw_die_ref context_die
)
18264 tree binfo
= TYPE_BINFO (type
);
18267 /* If this is not an incomplete type, output descriptions of each of its
18268 members. Note that as we output the DIEs necessary to represent the
18269 members of this record or union type, we will also be trying to output
18270 DIEs to represent the *types* of those members. However the `type'
18271 function (above) will specifically avoid generating type DIEs for member
18272 types *within* the list of member DIEs for this (containing) type except
18273 for those types (of members) which are explicitly marked as also being
18274 members of this (containing) type themselves. The g++ front- end can
18275 force any given type to be treated as a member of some other (containing)
18276 type by setting the TYPE_CONTEXT of the given (member) type to point to
18277 the TREE node representing the appropriate (containing) type. */
18279 /* First output info about the base classes. */
18282 VEC(tree
,gc
) *accesses
= BINFO_BASE_ACCESSES (binfo
);
18286 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
18287 gen_inheritance_die (base
,
18288 (accesses
? VEC_index (tree
, accesses
, i
)
18289 : access_public_node
), context_die
);
18292 /* Now output info about the data members and type members. */
18293 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
18295 /* If we thought we were generating minimal debug info for TYPE
18296 and then changed our minds, some of the member declarations
18297 may have already been defined. Don't define them again, but
18298 do put them in the right order. */
18300 child
= lookup_decl_die (member
);
18302 splice_child_die (context_die
, child
);
18304 gen_decl_die (member
, NULL
, context_die
);
18307 /* Now output info about the function members (if any). */
18308 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
18310 /* Don't include clones in the member list. */
18311 if (DECL_ABSTRACT_ORIGIN (member
))
18314 child
= lookup_decl_die (member
);
18316 splice_child_die (context_die
, child
);
18318 gen_decl_die (member
, NULL
, context_die
);
18322 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
18323 is set, we pretend that the type was never defined, so we only get the
18324 member DIEs needed by later specification DIEs. */
18327 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
18328 enum debug_info_usage usage
)
18330 dw_die_ref type_die
= lookup_type_die (type
);
18331 dw_die_ref scope_die
= 0;
18333 int complete
= (TYPE_SIZE (type
)
18334 && (! TYPE_STUB_DECL (type
)
18335 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
18336 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
18337 complete
= complete
&& should_emit_struct_debug (type
, usage
);
18339 if (type_die
&& ! complete
)
18342 if (TYPE_CONTEXT (type
) != NULL_TREE
18343 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
18344 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
18347 scope_die
= scope_die_for (type
, context_die
);
18349 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
18350 /* First occurrence of type or toplevel definition of nested class. */
18352 dw_die_ref old_die
= type_die
;
18354 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
18355 ? record_type_tag (type
) : DW_TAG_union_type
,
18357 equate_type_number_to_die (type
, type_die
);
18359 add_AT_specification (type_die
, old_die
);
18361 add_name_attribute (type_die
, type_tag (type
));
18364 remove_AT (type_die
, DW_AT_declaration
);
18366 /* Generate child dies for template paramaters. */
18367 if (debug_info_level
> DINFO_LEVEL_TERSE
18368 && COMPLETE_TYPE_P (type
))
18369 schedule_generic_params_dies_gen (type
);
18371 /* If this type has been completed, then give it a byte_size attribute and
18372 then give a list of members. */
18373 if (complete
&& !ns_decl
)
18375 /* Prevent infinite recursion in cases where the type of some member of
18376 this type is expressed in terms of this type itself. */
18377 TREE_ASM_WRITTEN (type
) = 1;
18378 add_byte_size_attribute (type_die
, type
);
18379 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
18381 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
18382 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
18385 /* If the first reference to this type was as the return type of an
18386 inline function, then it may not have a parent. Fix this now. */
18387 if (type_die
->die_parent
== NULL
)
18388 add_child_die (scope_die
, type_die
);
18390 push_decl_scope (type
);
18391 gen_member_die (type
, type_die
);
18394 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
18395 if (TYPE_ARTIFICIAL (type
))
18396 add_AT_flag (type_die
, DW_AT_artificial
, 1);
18398 /* GNU extension: Record what type our vtable lives in. */
18399 if (TYPE_VFIELD (type
))
18401 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
18403 gen_type_die (vtype
, context_die
);
18404 add_AT_die_ref (type_die
, DW_AT_containing_type
,
18405 lookup_type_die (vtype
));
18410 add_AT_flag (type_die
, DW_AT_declaration
, 1);
18412 /* We don't need to do this for function-local types. */
18413 if (TYPE_STUB_DECL (type
)
18414 && ! decl_function_context (TYPE_STUB_DECL (type
)))
18415 VEC_safe_push (tree
, gc
, incomplete_types
, type
);
18418 if (get_AT (type_die
, DW_AT_name
))
18419 add_pubtype (type
, type_die
);
18422 /* Generate a DIE for a subroutine _type_. */
18425 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
18427 tree return_type
= TREE_TYPE (type
);
18428 dw_die_ref subr_die
18429 = new_die (DW_TAG_subroutine_type
,
18430 scope_die_for (type
, context_die
), type
);
18432 equate_type_number_to_die (type
, subr_die
);
18433 add_prototyped_attribute (subr_die
, type
);
18434 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
18435 gen_formal_types_die (type
, subr_die
);
18437 if (get_AT (subr_die
, DW_AT_name
))
18438 add_pubtype (type
, subr_die
);
18441 /* Generate a DIE for a type definition. */
18444 gen_typedef_die (tree decl
, dw_die_ref context_die
)
18446 dw_die_ref type_die
;
18449 if (TREE_ASM_WRITTEN (decl
))
18452 TREE_ASM_WRITTEN (decl
) = 1;
18453 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
18454 origin
= decl_ultimate_origin (decl
);
18455 if (origin
!= NULL
)
18456 add_abstract_origin_attribute (type_die
, origin
);
18461 add_name_and_src_coords_attributes (type_die
, decl
);
18462 if (DECL_ORIGINAL_TYPE (decl
))
18464 type
= DECL_ORIGINAL_TYPE (decl
);
18466 gcc_assert (type
!= TREE_TYPE (decl
));
18467 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
18471 type
= TREE_TYPE (decl
);
18473 if (is_naming_typedef_decl (TYPE_NAME (type
)))
18475 /* Here, we are in the case of decl being a typedef naming
18476 an anonymous type, e.g:
18477 typedef struct {...} foo;
18478 In that case TREE_TYPE (decl) is not a typedef variant
18479 type and TYPE_NAME of the anonymous type is set to the
18480 TYPE_DECL of the typedef. This construct is emitted by
18483 TYPE is the anonymous struct named by the typedef
18484 DECL. As we need the DW_AT_type attribute of the
18485 DW_TAG_typedef to point to the DIE of TYPE, let's
18486 generate that DIE right away. add_type_attribute
18487 called below will then pick (via lookup_type_die) that
18488 anonymous struct DIE. */
18489 if (!TREE_ASM_WRITTEN (type
))
18490 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
18492 /* This is a GNU Extension. We are adding a
18493 DW_AT_linkage_name attribute to the DIE of the
18494 anonymous struct TYPE. The value of that attribute
18495 is the name of the typedef decl naming the anonymous
18496 struct. This greatly eases the work of consumers of
18497 this debug info. */
18498 add_linkage_attr (lookup_type_die (type
), decl
);
18502 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
18503 TREE_THIS_VOLATILE (decl
), context_die
);
18505 if (is_naming_typedef_decl (decl
))
18506 /* We want that all subsequent calls to lookup_type_die with
18507 TYPE in argument yield the DW_TAG_typedef we have just
18509 equate_type_number_to_die (type
, type_die
);
18511 add_accessibility_attribute (type_die
, decl
);
18514 if (DECL_ABSTRACT (decl
))
18515 equate_decl_number_to_die (decl
, type_die
);
18517 if (get_AT (type_die
, DW_AT_name
))
18518 add_pubtype (decl
, type_die
);
18521 /* Generate a DIE for a struct, class, enum or union type. */
18524 gen_tagged_type_die (tree type
,
18525 dw_die_ref context_die
,
18526 enum debug_info_usage usage
)
18530 if (type
== NULL_TREE
18531 || !is_tagged_type (type
))
18534 /* If this is a nested type whose containing class hasn't been written
18535 out yet, writing it out will cover this one, too. This does not apply
18536 to instantiations of member class templates; they need to be added to
18537 the containing class as they are generated. FIXME: This hurts the
18538 idea of combining type decls from multiple TUs, since we can't predict
18539 what set of template instantiations we'll get. */
18540 if (TYPE_CONTEXT (type
)
18541 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
18542 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
18544 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
18546 if (TREE_ASM_WRITTEN (type
))
18549 /* If that failed, attach ourselves to the stub. */
18550 push_decl_scope (TYPE_CONTEXT (type
));
18551 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
18554 else if (TYPE_CONTEXT (type
) != NULL_TREE
18555 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
18557 /* If this type is local to a function that hasn't been written
18558 out yet, use a NULL context for now; it will be fixed up in
18559 decls_for_scope. */
18560 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
18561 /* A declaration DIE doesn't count; nested types need to go in the
18563 if (context_die
&& is_declaration_die (context_die
))
18564 context_die
= NULL
;
18569 context_die
= declare_in_namespace (type
, context_die
);
18573 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
18575 /* This might have been written out by the call to
18576 declare_in_namespace. */
18577 if (!TREE_ASM_WRITTEN (type
))
18578 gen_enumeration_type_die (type
, context_die
);
18581 gen_struct_or_union_type_die (type
, context_die
, usage
);
18586 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
18587 it up if it is ever completed. gen_*_type_die will set it for us
18588 when appropriate. */
18591 /* Generate a type description DIE. */
18594 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
18595 enum debug_info_usage usage
)
18597 struct array_descr_info info
;
18599 if (type
== NULL_TREE
|| type
== error_mark_node
)
18602 if (TYPE_NAME (type
) != NULL_TREE
18603 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
18604 && is_redundant_typedef (TYPE_NAME (type
))
18605 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
18606 /* The DECL of this type is a typedef we don't want to emit debug
18607 info for but we want debug info for its underlying typedef.
18608 This can happen for e.g, the injected-class-name of a C++
18610 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
18612 /* If TYPE is a typedef type variant, let's generate debug info
18613 for the parent typedef which TYPE is a type of. */
18614 if (typedef_variant_p (type
))
18616 if (TREE_ASM_WRITTEN (type
))
18619 /* Prevent broken recursion; we can't hand off to the same type. */
18620 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
18622 /* Give typedefs the right scope. */
18623 context_die
= scope_die_for (type
, context_die
);
18625 TREE_ASM_WRITTEN (type
) = 1;
18627 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
18631 /* If type is an anonymous tagged type named by a typedef, let's
18632 generate debug info for the typedef. */
18633 if (is_naming_typedef_decl (TYPE_NAME (type
)))
18635 /* Use the DIE of the containing namespace as the parent DIE of
18636 the type description DIE we want to generate. */
18637 if (DECL_CONTEXT (TYPE_NAME (type
))
18638 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
18639 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
18641 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
18645 /* If this is an array type with hidden descriptor, handle it first. */
18646 if (!TREE_ASM_WRITTEN (type
)
18647 && lang_hooks
.types
.get_array_descr_info
18648 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
18649 && (dwarf_version
>= 3 || !dwarf_strict
))
18651 gen_descr_array_type_die (type
, &info
, context_die
);
18652 TREE_ASM_WRITTEN (type
) = 1;
18656 /* We are going to output a DIE to represent the unqualified version
18657 of this type (i.e. without any const or volatile qualifiers) so
18658 get the main variant (i.e. the unqualified version) of this type
18659 now. (Vectors are special because the debugging info is in the
18660 cloned type itself). */
18661 if (TREE_CODE (type
) != VECTOR_TYPE
)
18662 type
= type_main_variant (type
);
18664 if (TREE_ASM_WRITTEN (type
))
18667 switch (TREE_CODE (type
))
18673 case REFERENCE_TYPE
:
18674 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
18675 ensures that the gen_type_die recursion will terminate even if the
18676 type is recursive. Recursive types are possible in Ada. */
18677 /* ??? We could perhaps do this for all types before the switch
18679 TREE_ASM_WRITTEN (type
) = 1;
18681 /* For these types, all that is required is that we output a DIE (or a
18682 set of DIEs) to represent the "basis" type. */
18683 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18684 DINFO_USAGE_IND_USE
);
18688 /* This code is used for C++ pointer-to-data-member types.
18689 Output a description of the relevant class type. */
18690 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
18691 DINFO_USAGE_IND_USE
);
18693 /* Output a description of the type of the object pointed to. */
18694 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18695 DINFO_USAGE_IND_USE
);
18697 /* Now output a DIE to represent this pointer-to-data-member type
18699 gen_ptr_to_mbr_type_die (type
, context_die
);
18702 case FUNCTION_TYPE
:
18703 /* Force out return type (in case it wasn't forced out already). */
18704 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18705 DINFO_USAGE_DIR_USE
);
18706 gen_subroutine_type_die (type
, context_die
);
18710 /* Force out return type (in case it wasn't forced out already). */
18711 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
18712 DINFO_USAGE_DIR_USE
);
18713 gen_subroutine_type_die (type
, context_die
);
18717 gen_array_type_die (type
, context_die
);
18721 gen_array_type_die (type
, context_die
);
18724 case ENUMERAL_TYPE
:
18727 case QUAL_UNION_TYPE
:
18728 gen_tagged_type_die (type
, context_die
, usage
);
18734 case FIXED_POINT_TYPE
:
18737 /* No DIEs needed for fundamental types. */
18742 /* Just use DW_TAG_unspecified_type. */
18744 dw_die_ref type_die
= lookup_type_die (type
);
18745 if (type_die
== NULL
)
18747 tree name
= TYPE_NAME (type
);
18748 if (TREE_CODE (name
) == TYPE_DECL
)
18749 name
= DECL_NAME (name
);
18750 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
18751 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
18752 equate_type_number_to_die (type
, type_die
);
18758 gcc_unreachable ();
18761 TREE_ASM_WRITTEN (type
) = 1;
18765 gen_type_die (tree type
, dw_die_ref context_die
)
18767 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
18770 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
18771 things which are local to the given block. */
18774 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
18776 int must_output_die
= 0;
18779 /* Ignore blocks that are NULL. */
18780 if (stmt
== NULL_TREE
)
18783 inlined_func
= inlined_function_outer_scope_p (stmt
);
18785 /* If the block is one fragment of a non-contiguous block, do not
18786 process the variables, since they will have been done by the
18787 origin block. Do process subblocks. */
18788 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
18792 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
18793 gen_block_die (sub
, context_die
, depth
+ 1);
18798 /* Determine if we need to output any Dwarf DIEs at all to represent this
18801 /* The outer scopes for inlinings *must* always be represented. We
18802 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
18803 must_output_die
= 1;
18806 /* Determine if this block directly contains any "significant"
18807 local declarations which we will need to output DIEs for. */
18808 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18809 /* We are not in terse mode so *any* local declaration counts
18810 as being a "significant" one. */
18811 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
18812 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
18813 && (TREE_USED (stmt
)
18814 || TREE_ASM_WRITTEN (stmt
)
18815 || BLOCK_ABSTRACT (stmt
)));
18816 else if ((TREE_USED (stmt
)
18817 || TREE_ASM_WRITTEN (stmt
)
18818 || BLOCK_ABSTRACT (stmt
))
18819 && !dwarf2out_ignore_block (stmt
))
18820 must_output_die
= 1;
18823 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
18824 DIE for any block which contains no significant local declarations at
18825 all. Rather, in such cases we just call `decls_for_scope' so that any
18826 needed Dwarf info for any sub-blocks will get properly generated. Note
18827 that in terse mode, our definition of what constitutes a "significant"
18828 local declaration gets restricted to include only inlined function
18829 instances and local (nested) function definitions. */
18830 if (must_output_die
)
18834 /* If STMT block is abstract, that means we have been called
18835 indirectly from dwarf2out_abstract_function.
18836 That function rightfully marks the descendent blocks (of
18837 the abstract function it is dealing with) as being abstract,
18838 precisely to prevent us from emitting any
18839 DW_TAG_inlined_subroutine DIE as a descendent
18840 of an abstract function instance. So in that case, we should
18841 not call gen_inlined_subroutine_die.
18843 Later though, when cgraph asks dwarf2out to emit info
18844 for the concrete instance of the function decl into which
18845 the concrete instance of STMT got inlined, the later will lead
18846 to the generation of a DW_TAG_inlined_subroutine DIE. */
18847 if (! BLOCK_ABSTRACT (stmt
))
18848 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
18851 gen_lexical_block_die (stmt
, context_die
, depth
);
18854 decls_for_scope (stmt
, context_die
, depth
);
18857 /* Process variable DECL (or variable with origin ORIGIN) within
18858 block STMT and add it to CONTEXT_DIE. */
18860 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
18863 tree decl_or_origin
= decl
? decl
: origin
;
18865 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
18866 die
= lookup_decl_die (decl_or_origin
);
18867 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
18868 && TYPE_DECL_IS_STUB (decl_or_origin
))
18869 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
18873 if (die
!= NULL
&& die
->die_parent
== NULL
)
18874 add_child_die (context_die
, die
);
18875 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
18876 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
18877 stmt
, context_die
);
18879 gen_decl_die (decl
, origin
, context_die
);
18882 /* Generate all of the decls declared within a given scope and (recursively)
18883 all of its sub-blocks. */
18886 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
18892 /* Ignore NULL blocks. */
18893 if (stmt
== NULL_TREE
)
18896 /* Output the DIEs to represent all of the data objects and typedefs
18897 declared directly within this block but not within any nested
18898 sub-blocks. Also, nested function and tag DIEs have been
18899 generated with a parent of NULL; fix that up now. */
18900 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
18901 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
18902 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
18903 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
18906 /* If we're at -g1, we're not interested in subblocks. */
18907 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
18910 /* Output the DIEs to represent all sub-blocks (and the items declared
18911 therein) of this block. */
18912 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
18914 subblocks
= BLOCK_CHAIN (subblocks
))
18915 gen_block_die (subblocks
, context_die
, depth
+ 1);
18918 /* Is this a typedef we can avoid emitting? */
18921 is_redundant_typedef (const_tree decl
)
18923 if (TYPE_DECL_IS_STUB (decl
))
18926 if (DECL_ARTIFICIAL (decl
)
18927 && DECL_CONTEXT (decl
)
18928 && is_tagged_type (DECL_CONTEXT (decl
))
18929 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
18930 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
18931 /* Also ignore the artificial member typedef for the class name. */
18937 /* Return TRUE if TYPE is a typedef that names a type for linkage
18938 purposes. This kind of typedefs is produced by the C++ FE for
18941 typedef struct {...} foo;
18943 In that case, there is no typedef variant type produced for foo.
18944 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
18948 is_naming_typedef_decl (const_tree decl
)
18950 if (decl
== NULL_TREE
18951 || TREE_CODE (decl
) != TYPE_DECL
18952 || !is_tagged_type (TREE_TYPE (decl
))
18953 || DECL_IS_BUILTIN (decl
)
18954 || is_redundant_typedef (decl
)
18955 /* It looks like Ada produces TYPE_DECLs that are very similar
18956 to C++ naming typedefs but that have different
18957 semantics. Let's be specific to c++ for now. */
18961 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
18962 && TYPE_NAME (TREE_TYPE (decl
)) == decl
18963 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
18964 != TYPE_NAME (TREE_TYPE (decl
))));
18967 /* Returns the DIE for a context. */
18969 static inline dw_die_ref
18970 get_context_die (tree context
)
18974 /* Find die that represents this context. */
18975 if (TYPE_P (context
))
18977 context
= TYPE_MAIN_VARIANT (context
);
18978 return strip_naming_typedef (context
, force_type_die (context
));
18981 return force_decl_die (context
);
18983 return comp_unit_die ();
18986 /* Returns the DIE for decl. A DIE will always be returned. */
18989 force_decl_die (tree decl
)
18991 dw_die_ref decl_die
;
18992 unsigned saved_external_flag
;
18993 tree save_fn
= NULL_TREE
;
18994 decl_die
= lookup_decl_die (decl
);
18997 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
18999 decl_die
= lookup_decl_die (decl
);
19003 switch (TREE_CODE (decl
))
19005 case FUNCTION_DECL
:
19006 /* Clear current_function_decl, so that gen_subprogram_die thinks
19007 that this is a declaration. At this point, we just want to force
19008 declaration die. */
19009 save_fn
= current_function_decl
;
19010 current_function_decl
= NULL_TREE
;
19011 gen_subprogram_die (decl
, context_die
);
19012 current_function_decl
= save_fn
;
19016 /* Set external flag to force declaration die. Restore it after
19017 gen_decl_die() call. */
19018 saved_external_flag
= DECL_EXTERNAL (decl
);
19019 DECL_EXTERNAL (decl
) = 1;
19020 gen_decl_die (decl
, NULL
, context_die
);
19021 DECL_EXTERNAL (decl
) = saved_external_flag
;
19024 case NAMESPACE_DECL
:
19025 if (dwarf_version
>= 3 || !dwarf_strict
)
19026 dwarf2out_decl (decl
);
19028 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19029 decl_die
= comp_unit_die ();
19032 case TRANSLATION_UNIT_DECL
:
19033 decl_die
= comp_unit_die ();
19037 gcc_unreachable ();
19040 /* We should be able to find the DIE now. */
19042 decl_die
= lookup_decl_die (decl
);
19043 gcc_assert (decl_die
);
19049 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
19050 always returned. */
19053 force_type_die (tree type
)
19055 dw_die_ref type_die
;
19057 type_die
= lookup_type_die (type
);
19060 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
19062 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
19063 TYPE_VOLATILE (type
), context_die
);
19064 gcc_assert (type_die
);
19069 /* Force out any required namespaces to be able to output DECL,
19070 and return the new context_die for it, if it's changed. */
19073 setup_namespace_context (tree thing
, dw_die_ref context_die
)
19075 tree context
= (DECL_P (thing
)
19076 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
19077 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
19078 /* Force out the namespace. */
19079 context_die
= force_decl_die (context
);
19081 return context_die
;
19084 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
19085 type) within its namespace, if appropriate.
19087 For compatibility with older debuggers, namespace DIEs only contain
19088 declarations; all definitions are emitted at CU scope. */
19091 declare_in_namespace (tree thing
, dw_die_ref context_die
)
19093 dw_die_ref ns_context
;
19095 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19096 return context_die
;
19098 /* If this decl is from an inlined function, then don't try to emit it in its
19099 namespace, as we will get confused. It would have already been emitted
19100 when the abstract instance of the inline function was emitted anyways. */
19101 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
19102 return context_die
;
19104 ns_context
= setup_namespace_context (thing
, context_die
);
19106 if (ns_context
!= context_die
)
19110 if (DECL_P (thing
))
19111 gen_decl_die (thing
, NULL
, ns_context
);
19113 gen_type_die (thing
, ns_context
);
19115 return context_die
;
19118 /* Generate a DIE for a namespace or namespace alias. */
19121 gen_namespace_die (tree decl
, dw_die_ref context_die
)
19123 dw_die_ref namespace_die
;
19125 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
19126 they are an alias of. */
19127 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
19129 /* Output a real namespace or module. */
19130 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19131 namespace_die
= new_die (is_fortran ()
19132 ? DW_TAG_module
: DW_TAG_namespace
,
19133 context_die
, decl
);
19134 /* For Fortran modules defined in different CU don't add src coords. */
19135 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
19137 const char *name
= dwarf2_name (decl
, 0);
19139 add_name_attribute (namespace_die
, name
);
19142 add_name_and_src_coords_attributes (namespace_die
, decl
);
19143 if (DECL_EXTERNAL (decl
))
19144 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
19145 equate_decl_number_to_die (decl
, namespace_die
);
19149 /* Output a namespace alias. */
19151 /* Force out the namespace we are an alias of, if necessary. */
19152 dw_die_ref origin_die
19153 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
19155 if (DECL_FILE_SCOPE_P (decl
)
19156 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
19157 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19158 /* Now create the namespace alias DIE. */
19159 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
19160 add_name_and_src_coords_attributes (namespace_die
, decl
);
19161 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
19162 equate_decl_number_to_die (decl
, namespace_die
);
19164 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
19165 if (want_pubnames ())
19166 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
19169 /* Generate Dwarf debug information for a decl described by DECL.
19170 The return value is currently only meaningful for PARM_DECLs,
19171 for all other decls it returns NULL. */
19174 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
19176 tree decl_or_origin
= decl
? decl
: origin
;
19177 tree class_origin
= NULL
, ultimate_origin
;
19179 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
19182 switch (TREE_CODE (decl_or_origin
))
19188 if (!is_fortran () && !is_ada ())
19190 /* The individual enumerators of an enum type get output when we output
19191 the Dwarf representation of the relevant enum type itself. */
19195 /* Emit its type. */
19196 gen_type_die (TREE_TYPE (decl
), context_die
);
19198 /* And its containing namespace. */
19199 context_die
= declare_in_namespace (decl
, context_die
);
19201 gen_const_die (decl
, context_die
);
19204 case FUNCTION_DECL
:
19205 /* Don't output any DIEs to represent mere function declarations,
19206 unless they are class members or explicit block externs. */
19207 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
19208 && DECL_FILE_SCOPE_P (decl_or_origin
)
19209 && (current_function_decl
== NULL_TREE
19210 || DECL_ARTIFICIAL (decl_or_origin
)))
19215 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
19216 on local redeclarations of global functions. That seems broken. */
19217 if (current_function_decl
!= decl
)
19218 /* This is only a declaration. */;
19221 /* If we're emitting a clone, emit info for the abstract instance. */
19222 if (origin
|| DECL_ORIGIN (decl
) != decl
)
19223 dwarf2out_abstract_function (origin
19224 ? DECL_ORIGIN (origin
)
19225 : DECL_ABSTRACT_ORIGIN (decl
));
19227 /* If we're emitting an out-of-line copy of an inline function,
19228 emit info for the abstract instance and set up to refer to it. */
19229 else if (cgraph_function_possibly_inlined_p (decl
)
19230 && ! DECL_ABSTRACT (decl
)
19231 && ! class_or_namespace_scope_p (context_die
)
19232 /* dwarf2out_abstract_function won't emit a die if this is just
19233 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
19234 that case, because that works only if we have a die. */
19235 && DECL_INITIAL (decl
) != NULL_TREE
)
19237 dwarf2out_abstract_function (decl
);
19238 set_decl_origin_self (decl
);
19241 /* Otherwise we're emitting the primary DIE for this decl. */
19242 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
19244 /* Before we describe the FUNCTION_DECL itself, make sure that we
19245 have its containing type. */
19247 origin
= decl_class_context (decl
);
19248 if (origin
!= NULL_TREE
)
19249 gen_type_die (origin
, context_die
);
19251 /* And its return type. */
19252 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
19254 /* And its virtual context. */
19255 if (DECL_VINDEX (decl
) != NULL_TREE
)
19256 gen_type_die (DECL_CONTEXT (decl
), context_die
);
19258 /* Make sure we have a member DIE for decl. */
19259 if (origin
!= NULL_TREE
)
19260 gen_type_die_for_member (origin
, decl
, context_die
);
19262 /* And its containing namespace. */
19263 context_die
= declare_in_namespace (decl
, context_die
);
19266 /* Now output a DIE to represent the function itself. */
19268 gen_subprogram_die (decl
, context_die
);
19272 /* If we are in terse mode, don't generate any DIEs to represent any
19273 actual typedefs. */
19274 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19277 /* In the special case of a TYPE_DECL node representing the declaration
19278 of some type tag, if the given TYPE_DECL is marked as having been
19279 instantiated from some other (original) TYPE_DECL node (e.g. one which
19280 was generated within the original definition of an inline function) we
19281 used to generate a special (abbreviated) DW_TAG_structure_type,
19282 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
19283 should be actually referencing those DIEs, as variable DIEs with that
19284 type would be emitted already in the abstract origin, so it was always
19285 removed during unused type prunning. Don't add anything in this
19287 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
19290 if (is_redundant_typedef (decl
))
19291 gen_type_die (TREE_TYPE (decl
), context_die
);
19293 /* Output a DIE to represent the typedef itself. */
19294 gen_typedef_die (decl
, context_die
);
19298 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
19299 gen_label_die (decl
, context_die
);
19304 /* If we are in terse mode, don't generate any DIEs to represent any
19305 variable declarations or definitions. */
19306 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19309 /* Output any DIEs that are needed to specify the type of this data
19311 if (decl_by_reference_p (decl_or_origin
))
19312 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
19314 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
19316 /* And its containing type. */
19317 class_origin
= decl_class_context (decl_or_origin
);
19318 if (class_origin
!= NULL_TREE
)
19319 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
19321 /* And its containing namespace. */
19322 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
19324 /* Now output the DIE to represent the data object itself. This gets
19325 complicated because of the possibility that the VAR_DECL really
19326 represents an inlined instance of a formal parameter for an inline
19328 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
19329 if (ultimate_origin
!= NULL_TREE
19330 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
19331 gen_formal_parameter_die (decl
, origin
,
19332 true /* Emit name attribute. */,
19335 gen_variable_die (decl
, origin
, context_die
);
19339 /* Ignore the nameless fields that are used to skip bits but handle C++
19340 anonymous unions and structs. */
19341 if (DECL_NAME (decl
) != NULL_TREE
19342 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
19343 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
19345 gen_type_die (member_declared_type (decl
), context_die
);
19346 gen_field_die (decl
, context_die
);
19351 if (DECL_BY_REFERENCE (decl_or_origin
))
19352 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
19354 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
19355 return gen_formal_parameter_die (decl
, origin
,
19356 true /* Emit name attribute. */,
19359 case NAMESPACE_DECL
:
19360 case IMPORTED_DECL
:
19361 if (dwarf_version
>= 3 || !dwarf_strict
)
19362 gen_namespace_die (decl
, context_die
);
19366 /* Probably some frontend-internal decl. Assume we don't care. */
19367 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
19374 /* Output debug information for global decl DECL. Called from toplev.c after
19375 compilation proper has finished. */
19378 dwarf2out_global_decl (tree decl
)
19380 /* Output DWARF2 information for file-scope tentative data object
19381 declarations, file-scope (extern) function declarations (which
19382 had no corresponding body) and file-scope tagged type declarations
19383 and definitions which have not yet been forced out. */
19384 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
19385 dwarf2out_decl (decl
);
19388 /* Output debug information for type decl DECL. Called from toplev.c
19389 and from language front ends (to record built-in types). */
19391 dwarf2out_type_decl (tree decl
, int local
)
19394 dwarf2out_decl (decl
);
19397 /* Output debug information for imported module or decl DECL.
19398 NAME is non-NULL name in the lexical block if the decl has been renamed.
19399 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
19400 that DECL belongs to.
19401 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
19403 dwarf2out_imported_module_or_decl_1 (tree decl
,
19405 tree lexical_block
,
19406 dw_die_ref lexical_block_die
)
19408 expanded_location xloc
;
19409 dw_die_ref imported_die
= NULL
;
19410 dw_die_ref at_import_die
;
19412 if (TREE_CODE (decl
) == IMPORTED_DECL
)
19414 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
19415 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
19419 xloc
= expand_location (input_location
);
19421 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
19423 at_import_die
= force_type_die (TREE_TYPE (decl
));
19424 /* For namespace N { typedef void T; } using N::T; base_type_die
19425 returns NULL, but DW_TAG_imported_declaration requires
19426 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
19427 if (!at_import_die
)
19429 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
19430 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
19431 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
19432 gcc_assert (at_import_die
);
19437 at_import_die
= lookup_decl_die (decl
);
19438 if (!at_import_die
)
19440 /* If we're trying to avoid duplicate debug info, we may not have
19441 emitted the member decl for this field. Emit it now. */
19442 if (TREE_CODE (decl
) == FIELD_DECL
)
19444 tree type
= DECL_CONTEXT (decl
);
19446 if (TYPE_CONTEXT (type
)
19447 && TYPE_P (TYPE_CONTEXT (type
))
19448 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
19449 DINFO_USAGE_DIR_USE
))
19451 gen_type_die_for_member (type
, decl
,
19452 get_context_die (TYPE_CONTEXT (type
)));
19454 at_import_die
= force_decl_die (decl
);
19458 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
19460 if (dwarf_version
>= 3 || !dwarf_strict
)
19461 imported_die
= new_die (DW_TAG_imported_module
,
19468 imported_die
= new_die (DW_TAG_imported_declaration
,
19472 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
19473 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
19475 add_AT_string (imported_die
, DW_AT_name
,
19476 IDENTIFIER_POINTER (name
));
19477 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
19480 /* Output debug information for imported module or decl DECL.
19481 NAME is non-NULL name in context if the decl has been renamed.
19482 CHILD is true if decl is one of the renamed decls as part of
19483 importing whole module. */
19486 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
19489 /* dw_die_ref at_import_die; */
19490 dw_die_ref scope_die
;
19492 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19497 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
19498 We need decl DIE for reference and scope die. First, get DIE for the decl
19501 /* Get the scope die for decl context. Use comp_unit_die for global module
19502 or decl. If die is not found for non globals, force new die. */
19504 && TYPE_P (context
)
19505 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
19508 if (!(dwarf_version
>= 3 || !dwarf_strict
))
19511 scope_die
= get_context_die (context
);
19515 gcc_assert (scope_die
->die_child
);
19516 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
19517 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
19518 scope_die
= scope_die
->die_child
;
19521 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
19522 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
19526 /* Write the debugging output for DECL. */
19529 dwarf2out_decl (tree decl
)
19531 dw_die_ref context_die
= comp_unit_die ();
19533 switch (TREE_CODE (decl
))
19538 case FUNCTION_DECL
:
19539 /* What we would really like to do here is to filter out all mere
19540 file-scope declarations of file-scope functions which are never
19541 referenced later within this translation unit (and keep all of ones
19542 that *are* referenced later on) but we aren't clairvoyant, so we have
19543 no idea which functions will be referenced in the future (i.e. later
19544 on within the current translation unit). So here we just ignore all
19545 file-scope function declarations which are not also definitions. If
19546 and when the debugger needs to know something about these functions,
19547 it will have to hunt around and find the DWARF information associated
19548 with the definition of the function.
19550 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
19551 nodes represent definitions and which ones represent mere
19552 declarations. We have to check DECL_INITIAL instead. That's because
19553 the C front-end supports some weird semantics for "extern inline"
19554 function definitions. These can get inlined within the current
19555 translation unit (and thus, we need to generate Dwarf info for their
19556 abstract instances so that the Dwarf info for the concrete inlined
19557 instances can have something to refer to) but the compiler never
19558 generates any out-of-lines instances of such things (despite the fact
19559 that they *are* definitions).
19561 The important point is that the C front-end marks these "extern
19562 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
19563 them anyway. Note that the C++ front-end also plays some similar games
19564 for inline function definitions appearing within include files which
19565 also contain `#pragma interface' pragmas. */
19566 if (DECL_INITIAL (decl
) == NULL_TREE
)
19569 /* If we're a nested function, initially use a parent of NULL; if we're
19570 a plain function, this will be fixed up in decls_for_scope. If
19571 we're a method, it will be ignored, since we already have a DIE. */
19572 if (decl_function_context (decl
)
19573 /* But if we're in terse mode, we don't care about scope. */
19574 && debug_info_level
> DINFO_LEVEL_TERSE
)
19575 context_die
= NULL
;
19579 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
19580 declaration and if the declaration was never even referenced from
19581 within this entire compilation unit. We suppress these DIEs in
19582 order to save space in the .debug section (by eliminating entries
19583 which are probably useless). Note that we must not suppress
19584 block-local extern declarations (whether used or not) because that
19585 would screw-up the debugger's name lookup mechanism and cause it to
19586 miss things which really ought to be in scope at a given point. */
19587 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
19590 /* For local statics lookup proper context die. */
19591 if (TREE_STATIC (decl
)
19592 && DECL_CONTEXT (decl
)
19593 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
19594 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
19596 /* If we are in terse mode, don't generate any DIEs to represent any
19597 variable declarations or definitions. */
19598 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19603 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19605 if (!is_fortran () && !is_ada ())
19607 if (TREE_STATIC (decl
) && decl_function_context (decl
))
19608 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
19611 case NAMESPACE_DECL
:
19612 case IMPORTED_DECL
:
19613 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19615 if (lookup_decl_die (decl
) != NULL
)
19620 /* Don't emit stubs for types unless they are needed by other DIEs. */
19621 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
19624 /* Don't bother trying to generate any DIEs to represent any of the
19625 normal built-in types for the language we are compiling. */
19626 if (DECL_IS_BUILTIN (decl
))
19629 /* If we are in terse mode, don't generate any DIEs for types. */
19630 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19633 /* If we're a function-scope tag, initially use a parent of NULL;
19634 this will be fixed up in decls_for_scope. */
19635 if (decl_function_context (decl
))
19636 context_die
= NULL
;
19644 gen_decl_die (decl
, NULL
, context_die
);
19647 /* Write the debugging output for DECL. */
19650 dwarf2out_function_decl (tree decl
)
19652 dwarf2out_decl (decl
);
19653 call_arg_locations
= NULL
;
19654 call_arg_loc_last
= NULL
;
19655 call_site_count
= -1;
19656 tail_call_site_count
= -1;
19657 VEC_free (dw_die_ref
, heap
, block_map
);
19658 htab_empty (decl_loc_table
);
19659 htab_empty (cached_dw_loc_list_table
);
19662 /* Output a marker (i.e. a label) for the beginning of the generated code for
19663 a lexical block. */
19666 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
19667 unsigned int blocknum
)
19669 switch_to_section (current_function_section ());
19670 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
19673 /* Output a marker (i.e. a label) for the end of the generated code for a
19677 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
19679 switch_to_section (current_function_section ());
19680 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
19683 /* Returns nonzero if it is appropriate not to emit any debugging
19684 information for BLOCK, because it doesn't contain any instructions.
19686 Don't allow this for blocks with nested functions or local classes
19687 as we would end up with orphans, and in the presence of scheduling
19688 we may end up calling them anyway. */
19691 dwarf2out_ignore_block (const_tree block
)
19696 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
19697 if (TREE_CODE (decl
) == FUNCTION_DECL
19698 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
19700 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
19702 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
19703 if (TREE_CODE (decl
) == FUNCTION_DECL
19704 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
19711 /* Hash table routines for file_hash. */
19714 file_table_eq (const void *p1_p
, const void *p2_p
)
19716 const struct dwarf_file_data
*const p1
=
19717 (const struct dwarf_file_data
*) p1_p
;
19718 const char *const p2
= (const char *) p2_p
;
19719 return filename_cmp (p1
->filename
, p2
) == 0;
19723 file_table_hash (const void *p_p
)
19725 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
19726 return htab_hash_string (p
->filename
);
19729 /* Lookup FILE_NAME (in the list of filenames that we know about here in
19730 dwarf2out.c) and return its "index". The index of each (known) filename is
19731 just a unique number which is associated with only that one filename. We
19732 need such numbers for the sake of generating labels (in the .debug_sfnames
19733 section) and references to those files numbers (in the .debug_srcinfo
19734 and.debug_macinfo sections). If the filename given as an argument is not
19735 found in our current list, add it to the list and assign it the next
19736 available unique index number. In order to speed up searches, we remember
19737 the index of the filename was looked up last. This handles the majority of
19740 static struct dwarf_file_data
*
19741 lookup_filename (const char *file_name
)
19744 struct dwarf_file_data
* created
;
19746 /* Check to see if the file name that was searched on the previous
19747 call matches this file name. If so, return the index. */
19748 if (file_table_last_lookup
19749 && (file_name
== file_table_last_lookup
->filename
19750 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
19751 return file_table_last_lookup
;
19753 /* Didn't match the previous lookup, search the table. */
19754 slot
= htab_find_slot_with_hash (file_table
, file_name
,
19755 htab_hash_string (file_name
), INSERT
);
19757 return (struct dwarf_file_data
*) *slot
;
19759 created
= ggc_alloc_dwarf_file_data ();
19760 created
->filename
= file_name
;
19761 created
->emitted_number
= 0;
19766 /* If the assembler will construct the file table, then translate the compiler
19767 internal file table number into the assembler file table number, and emit
19768 a .file directive if we haven't already emitted one yet. The file table
19769 numbers are different because we prune debug info for unused variables and
19770 types, which may include filenames. */
19773 maybe_emit_file (struct dwarf_file_data
* fd
)
19775 if (! fd
->emitted_number
)
19777 if (last_emitted_file
)
19778 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
19780 fd
->emitted_number
= 1;
19781 last_emitted_file
= fd
;
19783 if (DWARF2_ASM_LINE_DEBUG_INFO
)
19785 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
19786 output_quoted_string (asm_out_file
,
19787 remap_debug_filename (fd
->filename
));
19788 fputc ('\n', asm_out_file
);
19792 return fd
->emitted_number
;
19795 /* Schedule generation of a DW_AT_const_value attribute to DIE.
19796 That generation should happen after function debug info has been
19797 generated. The value of the attribute is the constant value of ARG. */
19800 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
19802 die_arg_entry entry
;
19807 if (!tmpl_value_parm_die_table
)
19808 tmpl_value_parm_die_table
19809 = VEC_alloc (die_arg_entry
, gc
, 32);
19813 VEC_safe_push (die_arg_entry
, gc
,
19814 tmpl_value_parm_die_table
,
19818 /* Return TRUE if T is an instance of generic type, FALSE
19822 generic_type_p (tree t
)
19824 if (t
== NULL_TREE
|| !TYPE_P (t
))
19826 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
19829 /* Schedule the generation of the generic parameter dies for the
19830 instance of generic type T. The proper generation itself is later
19831 done by gen_scheduled_generic_parms_dies. */
19834 schedule_generic_params_dies_gen (tree t
)
19836 if (!generic_type_p (t
))
19839 if (generic_type_instances
== NULL
)
19840 generic_type_instances
= VEC_alloc (tree
, gc
, 256);
19842 VEC_safe_push (tree
, gc
, generic_type_instances
, t
);
19845 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
19846 by append_entry_to_tmpl_value_parm_die_table. This function must
19847 be called after function DIEs have been generated. */
19850 gen_remaining_tmpl_value_param_die_attribute (void)
19852 if (tmpl_value_parm_die_table
)
19857 FOR_EACH_VEC_ELT (die_arg_entry
, tmpl_value_parm_die_table
, i
, e
)
19858 tree_add_const_value_attribute (e
->die
, e
->arg
);
19862 /* Generate generic parameters DIEs for instances of generic types
19863 that have been previously scheduled by
19864 schedule_generic_params_dies_gen. This function must be called
19865 after all the types of the CU have been laid out. */
19868 gen_scheduled_generic_parms_dies (void)
19873 if (generic_type_instances
== NULL
)
19876 FOR_EACH_VEC_ELT (tree
, generic_type_instances
, i
, t
)
19877 gen_generic_params_dies (t
);
19881 /* Replace DW_AT_name for the decl with name. */
19884 dwarf2out_set_name (tree decl
, tree name
)
19890 die
= TYPE_SYMTAB_DIE (decl
);
19894 dname
= dwarf2_name (name
, 0);
19898 attr
= get_AT (die
, DW_AT_name
);
19901 struct indirect_string_node
*node
;
19903 node
= find_AT_string (dname
);
19904 /* replace the string. */
19905 attr
->dw_attr_val
.v
.val_str
= node
;
19909 add_name_attribute (die
, dname
);
19912 /* Called by the final INSN scan whenever we see a var location. We
19913 use it to drop labels in the right places, and throw the location in
19914 our lookup table. */
19917 dwarf2out_var_location (rtx loc_note
)
19919 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
19920 struct var_loc_node
*newloc
;
19921 rtx next_real
, next_note
;
19922 static const char *last_label
;
19923 static const char *last_postcall_label
;
19924 static bool last_in_cold_section_p
;
19925 static rtx expected_next_loc_note
;
19929 if (!NOTE_P (loc_note
))
19931 if (CALL_P (loc_note
))
19934 if (SIBLING_CALL_P (loc_note
))
19935 tail_call_site_count
++;
19940 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
19941 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
19944 /* Optimize processing a large consecutive sequence of location
19945 notes so we don't spend too much time in next_real_insn. If the
19946 next insn is another location note, remember the next_real_insn
19947 calculation for next time. */
19948 next_real
= cached_next_real_insn
;
19951 if (expected_next_loc_note
!= loc_note
)
19952 next_real
= NULL_RTX
;
19955 next_note
= NEXT_INSN (loc_note
);
19957 || INSN_DELETED_P (next_note
)
19958 || GET_CODE (next_note
) != NOTE
19959 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
19960 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
19961 next_note
= NULL_RTX
;
19964 next_real
= next_real_insn (loc_note
);
19968 expected_next_loc_note
= next_note
;
19969 cached_next_real_insn
= next_real
;
19972 cached_next_real_insn
= NULL_RTX
;
19974 /* If there are no instructions which would be affected by this note,
19975 don't do anything. */
19977 && next_real
== NULL_RTX
19978 && !NOTE_DURING_CALL_P (loc_note
))
19981 if (next_real
== NULL_RTX
)
19982 next_real
= get_last_insn ();
19984 /* If there were any real insns between note we processed last time
19985 and this note (or if it is the first note), clear
19986 last_{,postcall_}label so that they are not reused this time. */
19987 if (last_var_location_insn
== NULL_RTX
19988 || last_var_location_insn
!= next_real
19989 || last_in_cold_section_p
!= in_cold_section_p
)
19992 last_postcall_label
= NULL
;
19997 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
19998 newloc
= add_var_loc_to_decl (decl
, loc_note
,
19999 NOTE_DURING_CALL_P (loc_note
)
20000 ? last_postcall_label
: last_label
);
20001 if (newloc
== NULL
)
20010 /* If there were no real insns between note we processed last time
20011 and this note, use the label we emitted last time. Otherwise
20012 create a new label and emit it. */
20013 if (last_label
== NULL
)
20015 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
20016 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
20018 last_label
= ggc_strdup (loclabel
);
20023 struct call_arg_loc_node
*ca_loc
20024 = ggc_alloc_cleared_call_arg_loc_node ();
20025 rtx prev
= prev_real_insn (loc_note
), x
;
20026 ca_loc
->call_arg_loc_note
= loc_note
;
20027 ca_loc
->next
= NULL
;
20028 ca_loc
->label
= last_label
;
20031 || (NONJUMP_INSN_P (prev
)
20032 && GET_CODE (PATTERN (prev
)) == SEQUENCE
20033 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
20034 if (!CALL_P (prev
))
20035 prev
= XVECEXP (PATTERN (prev
), 0, 0);
20036 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
20037 x
= PATTERN (prev
);
20038 if (GET_CODE (x
) == PARALLEL
)
20039 x
= XVECEXP (x
, 0, 0);
20040 if (GET_CODE (x
) == SET
)
20042 if (GET_CODE (x
) == CALL
&& MEM_P (XEXP (x
, 0)))
20044 x
= XEXP (XEXP (x
, 0), 0);
20045 if (GET_CODE (x
) == SYMBOL_REF
20046 && SYMBOL_REF_DECL (x
)
20047 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
20048 ca_loc
->symbol_ref
= x
;
20050 ca_loc
->block
= insn_scope (prev
);
20051 if (call_arg_locations
)
20052 call_arg_loc_last
->next
= ca_loc
;
20054 call_arg_locations
= ca_loc
;
20055 call_arg_loc_last
= ca_loc
;
20057 else if (!NOTE_DURING_CALL_P (loc_note
))
20058 newloc
->label
= last_label
;
20061 if (!last_postcall_label
)
20063 sprintf (loclabel
, "%s-1", last_label
);
20064 last_postcall_label
= ggc_strdup (loclabel
);
20066 newloc
->label
= last_postcall_label
;
20069 last_var_location_insn
= next_real
;
20070 last_in_cold_section_p
= in_cold_section_p
;
20073 /* Note in one location list that text section has changed. */
20076 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
20078 var_loc_list
*list
= (var_loc_list
*) *slot
;
20080 list
->last_before_switch
20081 = list
->last
->next
? list
->last
->next
: list
->last
;
20085 /* Note in all location lists that text section has changed. */
20088 var_location_switch_text_section (void)
20090 if (decl_loc_table
== NULL
)
20093 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
20096 /* Create a new line number table. */
20098 static dw_line_info_table
*
20099 new_line_info_table (void)
20101 dw_line_info_table
*table
;
20103 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
20104 table
->file_num
= 1;
20105 table
->line_num
= 1;
20106 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
20111 /* Lookup the "current" table into which we emit line info, so
20112 that we don't have to do it for every source line. */
20115 set_cur_line_info_table (section
*sec
)
20117 dw_line_info_table
*table
;
20119 if (sec
== text_section
)
20120 table
= text_section_line_info
;
20121 else if (sec
== cold_text_section
)
20123 table
= cold_text_section_line_info
;
20126 cold_text_section_line_info
= table
= new_line_info_table ();
20127 table
->end_label
= cold_end_label
;
20132 const char *end_label
;
20134 if (flag_reorder_blocks_and_partition
)
20136 if (in_cold_section_p
)
20137 end_label
= crtl
->subsections
.cold_section_end_label
;
20139 end_label
= crtl
->subsections
.hot_section_end_label
;
20143 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20144 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
20145 current_function_funcdef_no
);
20146 end_label
= ggc_strdup (label
);
20149 table
= new_line_info_table ();
20150 table
->end_label
= end_label
;
20152 VEC_safe_push (dw_line_info_table_p
, gc
, separate_line_info
, table
);
20155 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20156 table
->is_stmt
= (cur_line_info_table
20157 ? cur_line_info_table
->is_stmt
20158 : DWARF_LINE_DEFAULT_IS_STMT_START
);
20159 cur_line_info_table
= table
;
20163 /* We need to reset the locations at the beginning of each
20164 function. We can't do this in the end_function hook, because the
20165 declarations that use the locations won't have been output when
20166 that hook is called. Also compute have_multiple_function_sections here. */
20169 dwarf2out_begin_function (tree fun
)
20171 section
*sec
= function_section (fun
);
20173 if (sec
!= text_section
)
20174 have_multiple_function_sections
= true;
20176 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
20178 gcc_assert (current_function_decl
== fun
);
20179 cold_text_section
= unlikely_text_section ();
20180 switch_to_section (cold_text_section
);
20181 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
20182 switch_to_section (sec
);
20185 dwarf2out_note_section_used ();
20186 call_site_count
= 0;
20187 tail_call_site_count
= 0;
20189 set_cur_line_info_table (sec
);
20192 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
20195 push_dw_line_info_entry (dw_line_info_table
*table
,
20196 enum dw_line_info_opcode opcode
, unsigned int val
)
20198 dw_line_info_entry e
;
20201 VEC_safe_push (dw_line_info_entry
, gc
, table
->entries
, &e
);
20204 /* Output a label to mark the beginning of a source code line entry
20205 and record information relating to this source line, in
20206 'line_info_table' for later output of the .debug_line section. */
20207 /* ??? The discriminator parameter ought to be unsigned. */
20210 dwarf2out_source_line (unsigned int line
, const char *filename
,
20211 int discriminator
, bool is_stmt
)
20213 unsigned int file_num
;
20214 dw_line_info_table
*table
;
20216 if (debug_info_level
< DINFO_LEVEL_NORMAL
|| line
== 0)
20219 /* The discriminator column was added in dwarf4. Simplify the below
20220 by simply removing it if we're not supposed to output it. */
20221 if (dwarf_version
< 4 && dwarf_strict
)
20224 table
= cur_line_info_table
;
20225 file_num
= maybe_emit_file (lookup_filename (filename
));
20227 /* ??? TODO: Elide duplicate line number entries. Traditionally,
20228 the debugger has used the second (possibly duplicate) line number
20229 at the beginning of the function to mark the end of the prologue.
20230 We could eliminate any other duplicates within the function. For
20231 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
20232 that second line number entry. */
20233 /* Recall that this end-of-prologue indication is *not* the same thing
20234 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
20235 to which the hook corresponds, follows the last insn that was
20236 emitted by gen_prologue. What we need is to precede the first insn
20237 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
20238 insn that corresponds to something the user wrote. These may be
20239 very different locations once scheduling is enabled. */
20241 if (0 && file_num
== table
->file_num
20242 && line
== table
->line_num
20243 && discriminator
== table
->discrim_num
20244 && is_stmt
== table
->is_stmt
)
20247 switch_to_section (current_function_section ());
20249 /* If requested, emit something human-readable. */
20250 if (flag_debug_asm
)
20251 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
20253 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20255 /* Emit the .loc directive understood by GNU as. */
20256 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
20257 file_num, line, is_stmt, discriminator */
20258 fputs ("\t.loc ", asm_out_file
);
20259 fprint_ul (asm_out_file
, file_num
);
20260 putc (' ', asm_out_file
);
20261 fprint_ul (asm_out_file
, line
);
20262 putc (' ', asm_out_file
);
20263 putc ('0', asm_out_file
);
20265 if (is_stmt
!= table
->is_stmt
)
20267 fputs (" is_stmt ", asm_out_file
);
20268 putc (is_stmt
? '1' : '0', asm_out_file
);
20270 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
20272 gcc_assert (discriminator
> 0);
20273 fputs (" discriminator ", asm_out_file
);
20274 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
20276 putc ('\n', asm_out_file
);
20280 unsigned int label_num
= ++line_info_label_num
;
20282 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
20284 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
20285 if (file_num
!= table
->file_num
)
20286 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
20287 if (discriminator
!= table
->discrim_num
)
20288 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
20289 if (is_stmt
!= table
->is_stmt
)
20290 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
20291 push_dw_line_info_entry (table
, LI_set_line
, line
);
20294 table
->file_num
= file_num
;
20295 table
->line_num
= line
;
20296 table
->discrim_num
= discriminator
;
20297 table
->is_stmt
= is_stmt
;
20298 table
->in_use
= true;
20301 /* Record the beginning of a new source file. */
20304 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
20306 if (flag_eliminate_dwarf2_dups
)
20308 /* Record the beginning of the file for break_out_includes. */
20309 dw_die_ref bincl_die
;
20311 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
20312 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
20315 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20318 e
.code
= DW_MACINFO_start_file
;
20320 e
.info
= ggc_strdup (filename
);
20321 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20325 /* Record the end of a source file. */
20328 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
20330 if (flag_eliminate_dwarf2_dups
)
20331 /* Record the end of the file for break_out_includes. */
20332 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
20334 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20337 e
.code
= DW_MACINFO_end_file
;
20340 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20344 /* Called from debug_define in toplev.c. The `buffer' parameter contains
20345 the tail part of the directive line, i.e. the part which is past the
20346 initial whitespace, #, whitespace, directive-name, whitespace part. */
20349 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
20350 const char *buffer ATTRIBUTE_UNUSED
)
20352 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20355 /* Insert a dummy first entry to be able to optimize the whole
20356 predefined macro block using DW_MACRO_GNU_transparent_include. */
20357 if (VEC_empty (macinfo_entry
, macinfo_table
) && lineno
<= 1)
20362 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20364 e
.code
= DW_MACINFO_define
;
20366 e
.info
= ggc_strdup (buffer
);
20367 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20371 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
20372 the tail part of the directive line, i.e. the part which is past the
20373 initial whitespace, #, whitespace, directive-name, whitespace part. */
20376 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
20377 const char *buffer ATTRIBUTE_UNUSED
)
20379 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20382 /* Insert a dummy first entry to be able to optimize the whole
20383 predefined macro block using DW_MACRO_GNU_transparent_include. */
20384 if (VEC_empty (macinfo_entry
, macinfo_table
) && lineno
<= 1)
20389 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20391 e
.code
= DW_MACINFO_undef
;
20393 e
.info
= ggc_strdup (buffer
);
20394 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
20398 /* Routines to manipulate hash table of CUs. */
20401 htab_macinfo_hash (const void *of
)
20403 const macinfo_entry
*const entry
=
20404 (const macinfo_entry
*) of
;
20406 return htab_hash_string (entry
->info
);
20410 htab_macinfo_eq (const void *of1
, const void *of2
)
20412 const macinfo_entry
*const entry1
= (const macinfo_entry
*) of1
;
20413 const macinfo_entry
*const entry2
= (const macinfo_entry
*) of2
;
20415 return !strcmp (entry1
->info
, entry2
->info
);
20418 /* Output a single .debug_macinfo entry. */
20421 output_macinfo_op (macinfo_entry
*ref
)
20425 struct indirect_string_node
*node
;
20426 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20427 struct dwarf_file_data
*fd
;
20431 case DW_MACINFO_start_file
:
20432 fd
= lookup_filename (ref
->info
);
20433 file_num
= maybe_emit_file (fd
);
20434 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
20435 dw2_asm_output_data_uleb128 (ref
->lineno
,
20436 "Included from line number %lu",
20437 (unsigned long) ref
->lineno
);
20438 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
20440 case DW_MACINFO_end_file
:
20441 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
20443 case DW_MACINFO_define
:
20444 case DW_MACINFO_undef
:
20445 len
= strlen (ref
->info
) + 1;
20447 && len
> DWARF_OFFSET_SIZE
20448 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
20449 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
20451 ref
->code
= ref
->code
== DW_MACINFO_define
20452 ? DW_MACRO_GNU_define_indirect
20453 : DW_MACRO_GNU_undef_indirect
;
20454 output_macinfo_op (ref
);
20457 dw2_asm_output_data (1, ref
->code
,
20458 ref
->code
== DW_MACINFO_define
20459 ? "Define macro" : "Undefine macro");
20460 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
20461 (unsigned long) ref
->lineno
);
20462 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
20464 case DW_MACRO_GNU_define_indirect
:
20465 case DW_MACRO_GNU_undef_indirect
:
20466 node
= find_AT_string (ref
->info
);
20467 if (node
->form
!= DW_FORM_strp
)
20470 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
20471 ++dw2_string_counter
;
20472 node
->label
= xstrdup (label
);
20473 node
->form
= DW_FORM_strp
;
20475 dw2_asm_output_data (1, ref
->code
,
20476 ref
->code
== DW_MACRO_GNU_define_indirect
20477 ? "Define macro indirect"
20478 : "Undefine macro indirect");
20479 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
20480 (unsigned long) ref
->lineno
);
20481 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
20482 debug_str_section
, "The macro: \"%s\"",
20485 case DW_MACRO_GNU_transparent_include
:
20486 dw2_asm_output_data (1, ref
->code
, "Transparent include");
20487 ASM_GENERATE_INTERNAL_LABEL (label
,
20488 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
20489 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
20492 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
20493 ASM_COMMENT_START
, (unsigned long) ref
->code
);
20498 /* Attempt to make a sequence of define/undef macinfo ops shareable with
20499 other compilation unit .debug_macinfo sections. IDX is the first
20500 index of a define/undef, return the number of ops that should be
20501 emitted in a comdat .debug_macinfo section and emit
20502 a DW_MACRO_GNU_transparent_include entry referencing it.
20503 If the define/undef entry should be emitted normally, return 0. */
20506 optimize_macinfo_range (unsigned int idx
, VEC (macinfo_entry
, gc
) *files
,
20507 htab_t
*macinfo_htab
)
20509 macinfo_entry
*first
, *second
, *cur
, *inc
;
20510 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
20511 unsigned char checksum
[16];
20512 struct md5_ctx ctx
;
20513 char *grp_name
, *tail
;
20515 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
20518 first
= VEC_index (macinfo_entry
, macinfo_table
, idx
);
20519 second
= VEC_index (macinfo_entry
, macinfo_table
, idx
+ 1);
20521 /* Optimize only if there are at least two consecutive define/undef ops,
20522 and either all of them are before first DW_MACINFO_start_file
20523 with lineno {0,1} (i.e. predefined macro block), or all of them are
20524 in some included header file. */
20525 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
20527 if (VEC_empty (macinfo_entry
, files
))
20529 if (first
->lineno
> 1 || second
->lineno
> 1)
20532 else if (first
->lineno
== 0)
20535 /* Find the last define/undef entry that can be grouped together
20536 with first and at the same time compute md5 checksum of their
20537 codes, linenumbers and strings. */
20538 md5_init_ctx (&ctx
);
20539 for (i
= idx
; VEC_iterate (macinfo_entry
, macinfo_table
, i
, cur
); i
++)
20540 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
20542 else if (VEC_empty (macinfo_entry
, files
) && cur
->lineno
> 1)
20546 unsigned char code
= cur
->code
;
20547 md5_process_bytes (&code
, 1, &ctx
);
20548 checksum_uleb128 (cur
->lineno
, &ctx
);
20549 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
20551 md5_finish_ctx (&ctx
, checksum
);
20554 /* From the containing include filename (if any) pick up just
20555 usable characters from its basename. */
20556 if (VEC_empty (macinfo_entry
, files
))
20559 base
= lbasename (VEC_last (macinfo_entry
, files
)->info
);
20560 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
20561 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
20562 encoded_filename_len
++;
20563 /* Count . at the end. */
20564 if (encoded_filename_len
)
20565 encoded_filename_len
++;
20567 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
20568 linebuf_len
= strlen (linebuf
);
20570 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
20571 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
20573 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
20574 tail
= grp_name
+ 4;
20575 if (encoded_filename_len
)
20577 for (i
= 0; base
[i
]; i
++)
20578 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
20582 memcpy (tail
, linebuf
, linebuf_len
);
20583 tail
+= linebuf_len
;
20585 for (i
= 0; i
< 16; i
++)
20586 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
20588 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
20589 in the empty vector entry before the first define/undef. */
20590 inc
= VEC_index (macinfo_entry
, macinfo_table
, idx
- 1);
20591 inc
->code
= DW_MACRO_GNU_transparent_include
;
20593 inc
->info
= ggc_strdup (grp_name
);
20594 if (*macinfo_htab
== NULL
)
20595 *macinfo_htab
= htab_create (10, htab_macinfo_hash
, htab_macinfo_eq
, NULL
);
20596 /* Avoid emitting duplicates. */
20597 slot
= htab_find_slot (*macinfo_htab
, inc
, INSERT
);
20602 /* If such an entry has been used before, just emit
20603 a DW_MACRO_GNU_transparent_include op. */
20604 inc
= (macinfo_entry
*) *slot
;
20605 output_macinfo_op (inc
);
20606 /* And clear all macinfo_entry in the range to avoid emitting them
20607 in the second pass. */
20609 VEC_iterate (macinfo_entry
, macinfo_table
, i
, cur
)
20610 && i
< idx
+ count
;
20620 inc
->lineno
= htab_elements (*macinfo_htab
);
20621 output_macinfo_op (inc
);
20626 /* Output macinfo section(s). */
20629 output_macinfo (void)
20632 unsigned long length
= VEC_length (macinfo_entry
, macinfo_table
);
20633 macinfo_entry
*ref
;
20634 VEC (macinfo_entry
, gc
) *files
= NULL
;
20635 htab_t macinfo_htab
= NULL
;
20640 /* output_macinfo* uses these interchangeably. */
20641 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
20642 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
20643 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
20644 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
20646 /* For .debug_macro emit the section header. */
20649 dw2_asm_output_data (2, 4, "DWARF macro version number");
20650 if (DWARF_OFFSET_SIZE
== 8)
20651 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
20653 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
20654 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_line_section_label
,
20655 debug_line_section
, NULL
);
20658 /* In the first loop, it emits the primary .debug_macinfo section
20659 and after each emitted op the macinfo_entry is cleared.
20660 If a longer range of define/undef ops can be optimized using
20661 DW_MACRO_GNU_transparent_include, the
20662 DW_MACRO_GNU_transparent_include op is emitted and kept in
20663 the vector before the first define/undef in the range and the
20664 whole range of define/undef ops is not emitted and kept. */
20665 for (i
= 0; VEC_iterate (macinfo_entry
, macinfo_table
, i
, ref
); i
++)
20669 case DW_MACINFO_start_file
:
20670 VEC_safe_push (macinfo_entry
, gc
, files
, ref
);
20672 case DW_MACINFO_end_file
:
20673 if (!VEC_empty (macinfo_entry
, files
))
20674 VEC_pop (macinfo_entry
, files
);
20676 case DW_MACINFO_define
:
20677 case DW_MACINFO_undef
:
20679 && HAVE_COMDAT_GROUP
20680 && VEC_length (macinfo_entry
, files
) != 1
20683 && VEC_index (macinfo_entry
, macinfo_table
, i
- 1)->code
== 0)
20685 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
20694 /* A dummy entry may be inserted at the beginning to be able
20695 to optimize the whole block of predefined macros. */
20701 output_macinfo_op (ref
);
20706 if (macinfo_htab
== NULL
)
20709 htab_delete (macinfo_htab
);
20711 /* If any DW_MACRO_GNU_transparent_include were used, on those
20712 DW_MACRO_GNU_transparent_include entries terminate the
20713 current chain and switch to a new comdat .debug_macinfo
20714 section and emit the define/undef entries within it. */
20715 for (i
= 0; VEC_iterate (macinfo_entry
, macinfo_table
, i
, ref
); i
++)
20720 case DW_MACRO_GNU_transparent_include
:
20722 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20723 tree comdat_key
= get_identifier (ref
->info
);
20724 /* Terminate the previous .debug_macinfo section. */
20725 dw2_asm_output_data (1, 0, "End compilation unit");
20726 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
20728 | SECTION_LINKONCE
,
20730 ASM_GENERATE_INTERNAL_LABEL (label
,
20731 DEBUG_MACRO_SECTION_LABEL
,
20733 ASM_OUTPUT_LABEL (asm_out_file
, label
);
20736 dw2_asm_output_data (2, 4, "DWARF macro version number");
20737 if (DWARF_OFFSET_SIZE
== 8)
20738 dw2_asm_output_data (1, 1, "Flags: 64-bit");
20740 dw2_asm_output_data (1, 0, "Flags: 32-bit");
20743 case DW_MACINFO_define
:
20744 case DW_MACINFO_undef
:
20745 output_macinfo_op (ref
);
20750 gcc_unreachable ();
20754 /* Set up for Dwarf output at the start of compilation. */
20757 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
20759 /* Allocate the file_table. */
20760 file_table
= htab_create_ggc (50, file_table_hash
,
20761 file_table_eq
, NULL
);
20763 /* Allocate the decl_die_table. */
20764 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
20765 decl_die_table_eq
, NULL
);
20767 /* Allocate the decl_loc_table. */
20768 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
20769 decl_loc_table_eq
, NULL
);
20771 /* Allocate the cached_dw_loc_list_table. */
20772 cached_dw_loc_list_table
20773 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
20774 cached_dw_loc_list_table_eq
, NULL
);
20776 /* Allocate the initial hunk of the decl_scope_table. */
20777 decl_scope_table
= VEC_alloc (tree
, gc
, 256);
20779 /* Allocate the initial hunk of the abbrev_die_table. */
20780 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
20781 (ABBREV_DIE_TABLE_INCREMENT
);
20782 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
20783 /* Zero-th entry is allocated, but unused. */
20784 abbrev_die_table_in_use
= 1;
20786 /* Allocate the pubtypes and pubnames vectors. */
20787 pubname_table
= VEC_alloc (pubname_entry
, gc
, 32);
20788 pubtype_table
= VEC_alloc (pubname_entry
, gc
, 32);
20790 incomplete_types
= VEC_alloc (tree
, gc
, 64);
20792 used_rtx_array
= VEC_alloc (rtx
, gc
, 32);
20794 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
20795 SECTION_DEBUG
, NULL
);
20796 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
20797 SECTION_DEBUG
, NULL
);
20798 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
20799 SECTION_DEBUG
, NULL
);
20800 debug_macinfo_section
= get_section (dwarf_strict
20801 ? DEBUG_MACINFO_SECTION
20802 : DEBUG_MACRO_SECTION
,
20803 SECTION_DEBUG
, NULL
);
20804 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
20805 SECTION_DEBUG
, NULL
);
20806 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
20807 SECTION_DEBUG
, NULL
);
20808 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
20809 SECTION_DEBUG
, NULL
);
20810 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
20811 SECTION_DEBUG
, NULL
);
20812 debug_str_section
= get_section (DEBUG_STR_SECTION
,
20813 DEBUG_STR_SECTION_FLAGS
, NULL
);
20814 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
20815 SECTION_DEBUG
, NULL
);
20816 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
20817 SECTION_DEBUG
, NULL
);
20819 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
20820 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
20821 DEBUG_ABBREV_SECTION_LABEL
, 0);
20822 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
20823 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
20824 COLD_TEXT_SECTION_LABEL
, 0);
20825 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
20827 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
20828 DEBUG_INFO_SECTION_LABEL
, 0);
20829 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
20830 DEBUG_LINE_SECTION_LABEL
, 0);
20831 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
20832 DEBUG_RANGES_SECTION_LABEL
, 0);
20833 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
20835 ? DEBUG_MACINFO_SECTION_LABEL
20836 : DEBUG_MACRO_SECTION_LABEL
, 0);
20838 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
20839 macinfo_table
= VEC_alloc (macinfo_entry
, gc
, 64);
20841 switch_to_section (text_section
);
20842 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
20844 /* Make sure the line number table for .text always exists. */
20845 text_section_line_info
= new_line_info_table ();
20846 text_section_line_info
->end_label
= text_end_label
;
20849 /* Called before compile () starts outputtting functions, variables
20850 and toplevel asms into assembly. */
20853 dwarf2out_assembly_start (void)
20855 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
20856 && dwarf2out_do_cfi_asm ()
20857 && (!(flag_unwind_tables
|| flag_exceptions
)
20858 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
20859 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
20862 /* A helper function for dwarf2out_finish called through
20863 htab_traverse. Emit one queued .debug_str string. */
20866 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
20868 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
20870 if (node
->form
== DW_FORM_strp
)
20872 switch_to_section (debug_str_section
);
20873 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
20874 assemble_string (node
->str
, strlen (node
->str
) + 1);
20880 #if ENABLE_ASSERT_CHECKING
20881 /* Verify that all marks are clear. */
20884 verify_marks_clear (dw_die_ref die
)
20888 gcc_assert (! die
->die_mark
);
20889 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
20891 #endif /* ENABLE_ASSERT_CHECKING */
20893 /* Clear the marks for a die and its children.
20894 Be cool if the mark isn't set. */
20897 prune_unmark_dies (dw_die_ref die
)
20903 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
20906 /* Given DIE that we're marking as used, find any other dies
20907 it references as attributes and mark them as used. */
20910 prune_unused_types_walk_attribs (dw_die_ref die
)
20915 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
20917 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
20919 /* A reference to another DIE.
20920 Make sure that it will get emitted.
20921 If it was broken out into a comdat group, don't follow it. */
20922 if (! AT_ref (a
)->comdat_type_p
20923 || a
->dw_attr
== DW_AT_specification
)
20924 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
20926 /* Set the string's refcount to 0 so that prune_unused_types_mark
20927 accounts properly for it. */
20928 if (AT_class (a
) == dw_val_class_str
)
20929 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
20933 /* Mark the generic parameters and arguments children DIEs of DIE. */
20936 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
20940 if (die
== NULL
|| die
->die_child
== NULL
)
20942 c
= die
->die_child
;
20945 switch (c
->die_tag
)
20947 case DW_TAG_template_type_param
:
20948 case DW_TAG_template_value_param
:
20949 case DW_TAG_GNU_template_template_param
:
20950 case DW_TAG_GNU_template_parameter_pack
:
20951 prune_unused_types_mark (c
, 1);
20957 } while (c
&& c
!= die
->die_child
);
20960 /* Mark DIE as being used. If DOKIDS is true, then walk down
20961 to DIE's children. */
20964 prune_unused_types_mark (dw_die_ref die
, int dokids
)
20968 if (die
->die_mark
== 0)
20970 /* We haven't done this node yet. Mark it as used. */
20972 /* If this is the DIE of a generic type instantiation,
20973 mark the children DIEs that describe its generic parms and
20975 prune_unused_types_mark_generic_parms_dies (die
);
20977 /* We also have to mark its parents as used.
20978 (But we don't want to mark our parents' kids due to this.) */
20979 if (die
->die_parent
)
20980 prune_unused_types_mark (die
->die_parent
, 0);
20982 /* Mark any referenced nodes. */
20983 prune_unused_types_walk_attribs (die
);
20985 /* If this node is a specification,
20986 also mark the definition, if it exists. */
20987 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
20988 prune_unused_types_mark (die
->die_definition
, 1);
20991 if (dokids
&& die
->die_mark
!= 2)
20993 /* We need to walk the children, but haven't done so yet.
20994 Remember that we've walked the kids. */
20997 /* If this is an array type, we need to make sure our
20998 kids get marked, even if they're types. If we're
20999 breaking out types into comdat sections, do this
21000 for all type definitions. */
21001 if (die
->die_tag
== DW_TAG_array_type
21002 || (use_debug_types
21003 && is_type_die (die
) && ! is_declaration_die (die
)))
21004 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
21006 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
21010 /* For local classes, look if any static member functions were emitted
21011 and if so, mark them. */
21014 prune_unused_types_walk_local_classes (dw_die_ref die
)
21018 if (die
->die_mark
== 2)
21021 switch (die
->die_tag
)
21023 case DW_TAG_structure_type
:
21024 case DW_TAG_union_type
:
21025 case DW_TAG_class_type
:
21028 case DW_TAG_subprogram
:
21029 if (!get_AT_flag (die
, DW_AT_declaration
)
21030 || die
->die_definition
!= NULL
)
21031 prune_unused_types_mark (die
, 1);
21038 /* Mark children. */
21039 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
21042 /* Walk the tree DIE and mark types that we actually use. */
21045 prune_unused_types_walk (dw_die_ref die
)
21049 /* Don't do anything if this node is already marked and
21050 children have been marked as well. */
21051 if (die
->die_mark
== 2)
21054 switch (die
->die_tag
)
21056 case DW_TAG_structure_type
:
21057 case DW_TAG_union_type
:
21058 case DW_TAG_class_type
:
21059 if (die
->die_perennial_p
)
21062 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
21063 if (c
->die_tag
== DW_TAG_subprogram
)
21066 /* Finding used static member functions inside of classes
21067 is needed just for local classes, because for other classes
21068 static member function DIEs with DW_AT_specification
21069 are emitted outside of the DW_TAG_*_type. If we ever change
21070 it, we'd need to call this even for non-local classes. */
21072 prune_unused_types_walk_local_classes (die
);
21074 /* It's a type node --- don't mark it. */
21077 case DW_TAG_const_type
:
21078 case DW_TAG_packed_type
:
21079 case DW_TAG_pointer_type
:
21080 case DW_TAG_reference_type
:
21081 case DW_TAG_rvalue_reference_type
:
21082 case DW_TAG_volatile_type
:
21083 case DW_TAG_typedef
:
21084 case DW_TAG_array_type
:
21085 case DW_TAG_interface_type
:
21086 case DW_TAG_friend
:
21087 case DW_TAG_variant_part
:
21088 case DW_TAG_enumeration_type
:
21089 case DW_TAG_subroutine_type
:
21090 case DW_TAG_string_type
:
21091 case DW_TAG_set_type
:
21092 case DW_TAG_subrange_type
:
21093 case DW_TAG_ptr_to_member_type
:
21094 case DW_TAG_file_type
:
21095 if (die
->die_perennial_p
)
21098 /* It's a type node --- don't mark it. */
21102 /* Mark everything else. */
21106 if (die
->die_mark
== 0)
21110 /* Now, mark any dies referenced from here. */
21111 prune_unused_types_walk_attribs (die
);
21116 /* Mark children. */
21117 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
21120 /* Increment the string counts on strings referred to from DIE's
21124 prune_unused_types_update_strings (dw_die_ref die
)
21129 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
21130 if (AT_class (a
) == dw_val_class_str
)
21132 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
21134 /* Avoid unnecessarily putting strings that are used less than
21135 twice in the hash table. */
21137 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
21140 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
21141 htab_hash_string (s
->str
),
21143 gcc_assert (*slot
== NULL
);
21149 /* Remove from the tree DIE any dies that aren't marked. */
21152 prune_unused_types_prune (dw_die_ref die
)
21156 gcc_assert (die
->die_mark
);
21157 prune_unused_types_update_strings (die
);
21159 if (! die
->die_child
)
21162 c
= die
->die_child
;
21164 dw_die_ref prev
= c
;
21165 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
21166 if (c
== die
->die_child
)
21168 /* No marked children between 'prev' and the end of the list. */
21170 /* No marked children at all. */
21171 die
->die_child
= NULL
;
21174 prev
->die_sib
= c
->die_sib
;
21175 die
->die_child
= prev
;
21180 if (c
!= prev
->die_sib
)
21182 prune_unused_types_prune (c
);
21183 } while (c
!= die
->die_child
);
21186 /* Remove dies representing declarations that we never use. */
21189 prune_unused_types (void)
21192 limbo_die_node
*node
;
21193 comdat_type_node
*ctnode
;
21195 dw_die_ref base_type
;
21197 #if ENABLE_ASSERT_CHECKING
21198 /* All the marks should already be clear. */
21199 verify_marks_clear (comp_unit_die ());
21200 for (node
= limbo_die_list
; node
; node
= node
->next
)
21201 verify_marks_clear (node
->die
);
21202 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21203 verify_marks_clear (ctnode
->root_die
);
21204 #endif /* ENABLE_ASSERT_CHECKING */
21206 /* Mark types that are used in global variables. */
21207 premark_types_used_by_global_vars ();
21209 /* Set the mark on nodes that are actually used. */
21210 prune_unused_types_walk (comp_unit_die ());
21211 for (node
= limbo_die_list
; node
; node
= node
->next
)
21212 prune_unused_types_walk (node
->die
);
21213 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21215 prune_unused_types_walk (ctnode
->root_die
);
21216 prune_unused_types_mark (ctnode
->type_die
, 1);
21219 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
21220 are unusual in that they are pubnames that are the children of pubtypes.
21221 They should only be marked via their parent DW_TAG_enumeration_type die,
21222 not as roots in themselves. */
21223 FOR_EACH_VEC_ELT (pubname_entry
, pubname_table
, i
, pub
)
21224 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
21225 prune_unused_types_mark (pub
->die
, 1);
21226 for (i
= 0; VEC_iterate (dw_die_ref
, base_types
, i
, base_type
); i
++)
21227 prune_unused_types_mark (base_type
, 1);
21229 if (debug_str_hash
)
21230 htab_empty (debug_str_hash
);
21231 prune_unused_types_prune (comp_unit_die ());
21232 for (node
= limbo_die_list
; node
; node
= node
->next
)
21233 prune_unused_types_prune (node
->die
);
21234 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21235 prune_unused_types_prune (ctnode
->root_die
);
21237 /* Leave the marks clear. */
21238 prune_unmark_dies (comp_unit_die ());
21239 for (node
= limbo_die_list
; node
; node
= node
->next
)
21240 prune_unmark_dies (node
->die
);
21241 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21242 prune_unmark_dies (ctnode
->root_die
);
21245 /* Set the parameter to true if there are any relative pathnames in
21248 file_table_relative_p (void ** slot
, void *param
)
21250 bool *p
= (bool *) param
;
21251 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
21252 if (!IS_ABSOLUTE_PATH (d
->filename
))
21260 /* Routines to manipulate hash table of comdat type units. */
21263 htab_ct_hash (const void *of
)
21266 const comdat_type_node
*const type_node
= (const comdat_type_node
*) of
;
21268 memcpy (&h
, type_node
->signature
, sizeof (h
));
21273 htab_ct_eq (const void *of1
, const void *of2
)
21275 const comdat_type_node
*const type_node_1
= (const comdat_type_node
*) of1
;
21276 const comdat_type_node
*const type_node_2
= (const comdat_type_node
*) of2
;
21278 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
21279 DWARF_TYPE_SIGNATURE_SIZE
));
21282 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
21283 to the location it would have been added, should we know its
21284 DECL_ASSEMBLER_NAME when we added other attributes. This will
21285 probably improve compactness of debug info, removing equivalent
21286 abbrevs, and hide any differences caused by deferring the
21287 computation of the assembler name, triggered by e.g. PCH. */
21290 move_linkage_attr (dw_die_ref die
)
21292 unsigned ix
= VEC_length (dw_attr_node
, die
->die_attr
);
21293 dw_attr_node linkage
= *VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
21295 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
21296 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
21300 dw_attr_node
*prev
= VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
21302 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
21306 if (ix
!= VEC_length (dw_attr_node
, die
->die_attr
) - 1)
21308 VEC_pop (dw_attr_node
, die
->die_attr
);
21309 VEC_quick_insert (dw_attr_node
, die
->die_attr
, ix
, &linkage
);
21313 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
21314 referenced from typed stack ops and count how often they are used. */
21317 mark_base_types (dw_loc_descr_ref loc
)
21319 dw_die_ref base_type
= NULL
;
21321 for (; loc
; loc
= loc
->dw_loc_next
)
21323 switch (loc
->dw_loc_opc
)
21325 case DW_OP_GNU_regval_type
:
21326 case DW_OP_GNU_deref_type
:
21327 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
21329 case DW_OP_GNU_convert
:
21330 case DW_OP_GNU_reinterpret
:
21331 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
21334 case DW_OP_GNU_const_type
:
21335 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
21337 case DW_OP_GNU_entry_value
:
21338 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
21343 gcc_assert (base_type
->die_parent
== comp_unit_die ());
21344 if (base_type
->die_mark
)
21345 base_type
->die_mark
++;
21348 VEC_safe_push (dw_die_ref
, heap
, base_types
, base_type
);
21349 base_type
->die_mark
= 1;
21354 /* Comparison function for sorting marked base types. */
21357 base_type_cmp (const void *x
, const void *y
)
21359 dw_die_ref dx
= *(const dw_die_ref
*) x
;
21360 dw_die_ref dy
= *(const dw_die_ref
*) y
;
21361 unsigned int byte_size1
, byte_size2
;
21362 unsigned int encoding1
, encoding2
;
21363 if (dx
->die_mark
> dy
->die_mark
)
21365 if (dx
->die_mark
< dy
->die_mark
)
21367 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
21368 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
21369 if (byte_size1
< byte_size2
)
21371 if (byte_size1
> byte_size2
)
21373 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
21374 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
21375 if (encoding1
< encoding2
)
21377 if (encoding1
> encoding2
)
21382 /* Move base types marked by mark_base_types as early as possible
21383 in the CU, sorted by decreasing usage count both to make the
21384 uleb128 references as small as possible and to make sure they
21385 will have die_offset already computed by calc_die_sizes when
21386 sizes of typed stack loc ops is computed. */
21389 move_marked_base_types (void)
21392 dw_die_ref base_type
, die
, c
;
21394 if (VEC_empty (dw_die_ref
, base_types
))
21397 /* Sort by decreasing usage count, they will be added again in that
21399 VEC_qsort (dw_die_ref
, base_types
, base_type_cmp
);
21400 die
= comp_unit_die ();
21401 c
= die
->die_child
;
21404 dw_die_ref prev
= c
;
21406 while (c
->die_mark
)
21408 remove_child_with_prev (c
, prev
);
21409 /* As base types got marked, there must be at least
21410 one node other than DW_TAG_base_type. */
21411 gcc_assert (c
!= c
->die_sib
);
21415 while (c
!= die
->die_child
);
21416 gcc_assert (die
->die_child
);
21417 c
= die
->die_child
;
21418 for (i
= 0; VEC_iterate (dw_die_ref
, base_types
, i
, base_type
); i
++)
21420 base_type
->die_mark
= 0;
21421 base_type
->die_sib
= c
->die_sib
;
21422 c
->die_sib
= base_type
;
21427 /* Helper function for resolve_addr, attempt to resolve
21428 one CONST_STRING, return non-zero if not successful. Similarly verify that
21429 SYMBOL_REFs refer to variables emitted in the current CU. */
21432 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
21436 if (GET_CODE (rtl
) == CONST_STRING
)
21438 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
21439 tree t
= build_string (len
, XSTR (rtl
, 0));
21440 tree tlen
= size_int (len
- 1);
21442 = build_array_type (char_type_node
, build_index_type (tlen
));
21443 rtl
= lookup_constant_def (t
);
21444 if (!rtl
|| !MEM_P (rtl
))
21446 rtl
= XEXP (rtl
, 0);
21447 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
21452 if (GET_CODE (rtl
) == SYMBOL_REF
21453 && SYMBOL_REF_DECL (rtl
))
21455 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
21457 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
21460 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
21464 if (GET_CODE (rtl
) == CONST
21465 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
21471 /* Helper function for resolve_addr, handle one location
21472 expression, return false if at least one CONST_STRING or SYMBOL_REF in
21473 the location list couldn't be resolved. */
21476 resolve_addr_in_expr (dw_loc_descr_ref loc
)
21478 dw_loc_descr_ref keep
= NULL
;
21479 for (; loc
; loc
= loc
->dw_loc_next
)
21480 switch (loc
->dw_loc_opc
)
21483 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
21486 case DW_OP_const4u
:
21487 case DW_OP_const8u
:
21489 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
21492 case DW_OP_plus_uconst
:
21493 if (size_of_loc_descr (loc
)
21494 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
21496 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
21498 dw_loc_descr_ref repl
21499 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
21500 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
21501 add_loc_descr (&repl
, loc
->dw_loc_next
);
21505 case DW_OP_implicit_value
:
21506 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
21507 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
21510 case DW_OP_GNU_implicit_pointer
:
21511 case DW_OP_GNU_parameter_ref
:
21512 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
21515 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
21518 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
21519 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
21520 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
21523 case DW_OP_GNU_const_type
:
21524 case DW_OP_GNU_regval_type
:
21525 case DW_OP_GNU_deref_type
:
21526 case DW_OP_GNU_convert
:
21527 case DW_OP_GNU_reinterpret
:
21528 while (loc
->dw_loc_next
21529 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
21531 dw_die_ref base1
, base2
;
21532 unsigned enc1
, enc2
, size1
, size2
;
21533 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
21534 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
21535 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
21536 else if (loc
->dw_loc_oprnd1
.val_class
21537 == dw_val_class_unsigned_const
)
21540 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
21541 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
21542 == dw_val_class_unsigned_const
)
21544 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
21545 gcc_assert (base1
->die_tag
== DW_TAG_base_type
21546 && base2
->die_tag
== DW_TAG_base_type
);
21547 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
21548 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
21549 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
21550 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
21552 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
21553 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
21557 /* Optimize away next DW_OP_GNU_convert after
21558 adjusting LOC's base type die reference. */
21559 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
21560 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
21561 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
21563 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
21564 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
21567 /* Don't change integer DW_OP_GNU_convert after e.g. floating
21568 point typed stack entry. */
21569 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
21570 keep
= loc
->dw_loc_next
;
21580 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
21581 an address in .rodata section if the string literal is emitted there,
21582 or remove the containing location list or replace DW_AT_const_value
21583 with DW_AT_location and empty location expression, if it isn't found
21584 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
21585 to something that has been emitted in the current CU. */
21588 resolve_addr (dw_die_ref die
)
21592 dw_loc_list_ref
*curr
, *start
, loc
;
21595 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
21596 switch (AT_class (a
))
21598 case dw_val_class_loc_list
:
21599 start
= curr
= AT_loc_list_ptr (a
);
21602 /* The same list can be referenced more than once. See if we have
21603 already recorded the result from a previous pass. */
21605 *curr
= loc
->dw_loc_next
;
21606 else if (!loc
->resolved_addr
)
21608 /* As things stand, we do not expect or allow one die to
21609 reference a suffix of another die's location list chain.
21610 References must be identical or completely separate.
21611 There is therefore no need to cache the result of this
21612 pass on any list other than the first; doing so
21613 would lead to unnecessary writes. */
21616 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
21617 if (!resolve_addr_in_expr ((*curr
)->expr
))
21619 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
21620 if (next
&& (*curr
)->ll_symbol
)
21622 gcc_assert (!next
->ll_symbol
);
21623 next
->ll_symbol
= (*curr
)->ll_symbol
;
21629 mark_base_types ((*curr
)->expr
);
21630 curr
= &(*curr
)->dw_loc_next
;
21634 loc
->resolved_addr
= 1;
21638 loc
->dw_loc_next
= *start
;
21643 remove_AT (die
, a
->dw_attr
);
21647 case dw_val_class_loc
:
21649 dw_loc_descr_ref l
= AT_loc (a
);
21650 /* For -gdwarf-2 don't attempt to optimize
21651 DW_AT_data_member_location containing
21652 DW_OP_plus_uconst - older consumers might
21653 rely on it being that op instead of a more complex,
21654 but shorter, location description. */
21655 if ((dwarf_version
> 2
21656 || a
->dw_attr
!= DW_AT_data_member_location
21658 || l
->dw_loc_opc
!= DW_OP_plus_uconst
21659 || l
->dw_loc_next
!= NULL
)
21660 && !resolve_addr_in_expr (l
))
21662 remove_AT (die
, a
->dw_attr
);
21666 mark_base_types (l
);
21669 case dw_val_class_addr
:
21670 if (a
->dw_attr
== DW_AT_const_value
21671 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
21673 remove_AT (die
, a
->dw_attr
);
21676 if (die
->die_tag
== DW_TAG_GNU_call_site
21677 && a
->dw_attr
== DW_AT_abstract_origin
)
21679 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
21680 dw_die_ref tdie
= lookup_decl_die (tdecl
);
21682 && DECL_EXTERNAL (tdecl
)
21683 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
21685 force_decl_die (tdecl
);
21686 tdie
= lookup_decl_die (tdecl
);
21690 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
21691 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
21692 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
21696 remove_AT (die
, a
->dw_attr
);
21705 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
21708 /* Helper routines for optimize_location_lists.
21709 This pass tries to share identical local lists in .debug_loc
21712 /* Iteratively hash operands of LOC opcode. */
21714 static inline hashval_t
21715 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
21717 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
21718 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
21720 switch (loc
->dw_loc_opc
)
21722 case DW_OP_const4u
:
21723 case DW_OP_const8u
:
21727 case DW_OP_const1u
:
21728 case DW_OP_const1s
:
21729 case DW_OP_const2u
:
21730 case DW_OP_const2s
:
21731 case DW_OP_const4s
:
21732 case DW_OP_const8s
:
21736 case DW_OP_plus_uconst
:
21772 case DW_OP_deref_size
:
21773 case DW_OP_xderef_size
:
21774 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
21781 gcc_assert (val1
->val_class
== dw_val_class_loc
);
21782 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
21783 hash
= iterative_hash_object (offset
, hash
);
21786 case DW_OP_implicit_value
:
21787 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
21788 switch (val2
->val_class
)
21790 case dw_val_class_const
:
21791 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
21793 case dw_val_class_vec
:
21795 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
21796 unsigned int len
= val2
->v
.val_vec
.length
;
21798 hash
= iterative_hash_object (elt_size
, hash
);
21799 hash
= iterative_hash_object (len
, hash
);
21800 hash
= iterative_hash (val2
->v
.val_vec
.array
,
21801 len
* elt_size
, hash
);
21804 case dw_val_class_const_double
:
21805 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
21806 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
21808 case dw_val_class_addr
:
21809 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
21812 gcc_unreachable ();
21816 case DW_OP_bit_piece
:
21817 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
21818 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
21824 unsigned char dtprel
= 0xd1;
21825 hash
= iterative_hash_object (dtprel
, hash
);
21827 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
21829 case DW_OP_GNU_implicit_pointer
:
21830 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
21832 case DW_OP_GNU_entry_value
:
21833 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
21835 case DW_OP_GNU_regval_type
:
21836 case DW_OP_GNU_deref_type
:
21838 unsigned int byte_size
21839 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
21840 unsigned int encoding
21841 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
21842 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
21843 hash
= iterative_hash_object (byte_size
, hash
);
21844 hash
= iterative_hash_object (encoding
, hash
);
21847 case DW_OP_GNU_convert
:
21848 case DW_OP_GNU_reinterpret
:
21849 if (val1
->val_class
== dw_val_class_unsigned_const
)
21851 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
21855 case DW_OP_GNU_const_type
:
21857 unsigned int byte_size
21858 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
21859 unsigned int encoding
21860 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
21861 hash
= iterative_hash_object (byte_size
, hash
);
21862 hash
= iterative_hash_object (encoding
, hash
);
21863 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
21865 hash
= iterative_hash_object (val2
->val_class
, hash
);
21866 switch (val2
->val_class
)
21868 case dw_val_class_const
:
21869 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
21871 case dw_val_class_vec
:
21873 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
21874 unsigned int len
= val2
->v
.val_vec
.length
;
21876 hash
= iterative_hash_object (elt_size
, hash
);
21877 hash
= iterative_hash_object (len
, hash
);
21878 hash
= iterative_hash (val2
->v
.val_vec
.array
,
21879 len
* elt_size
, hash
);
21882 case dw_val_class_const_double
:
21883 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
21884 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
21887 gcc_unreachable ();
21893 /* Other codes have no operands. */
21899 /* Iteratively hash the whole DWARF location expression LOC. */
21901 static inline hashval_t
21902 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
21904 dw_loc_descr_ref l
;
21905 bool sizes_computed
= false;
21906 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
21907 size_of_locs (loc
);
21909 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
21911 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
21912 hash
= iterative_hash_object (opc
, hash
);
21913 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
21915 size_of_locs (loc
);
21916 sizes_computed
= true;
21918 hash
= hash_loc_operands (l
, hash
);
21923 /* Compute hash of the whole location list LIST_HEAD. */
21926 hash_loc_list (dw_loc_list_ref list_head
)
21928 dw_loc_list_ref curr
= list_head
;
21929 hashval_t hash
= 0;
21931 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
21933 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
21934 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
21936 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
21938 hash
= hash_locs (curr
->expr
, hash
);
21940 list_head
->hash
= hash
;
21943 /* Return true if X and Y opcodes have the same operands. */
21946 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
21948 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
21949 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
21950 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
21951 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
21953 switch (x
->dw_loc_opc
)
21955 case DW_OP_const4u
:
21956 case DW_OP_const8u
:
21960 case DW_OP_const1u
:
21961 case DW_OP_const1s
:
21962 case DW_OP_const2u
:
21963 case DW_OP_const2s
:
21964 case DW_OP_const4s
:
21965 case DW_OP_const8s
:
21969 case DW_OP_plus_uconst
:
22005 case DW_OP_deref_size
:
22006 case DW_OP_xderef_size
:
22007 return valx1
->v
.val_int
== valy1
->v
.val_int
;
22010 gcc_assert (valx1
->val_class
== dw_val_class_loc
22011 && valy1
->val_class
== dw_val_class_loc
22012 && x
->dw_loc_addr
== y
->dw_loc_addr
);
22013 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
22014 case DW_OP_implicit_value
:
22015 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
22016 || valx2
->val_class
!= valy2
->val_class
)
22018 switch (valx2
->val_class
)
22020 case dw_val_class_const
:
22021 return valx2
->v
.val_int
== valy2
->v
.val_int
;
22022 case dw_val_class_vec
:
22023 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
22024 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
22025 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
22026 valx2
->v
.val_vec
.elt_size
22027 * valx2
->v
.val_vec
.length
) == 0;
22028 case dw_val_class_const_double
:
22029 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
22030 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
22031 case dw_val_class_addr
:
22032 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
22034 gcc_unreachable ();
22037 case DW_OP_bit_piece
:
22038 return valx1
->v
.val_int
== valy1
->v
.val_int
22039 && valx2
->v
.val_int
== valy2
->v
.val_int
;
22042 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
22043 case DW_OP_GNU_implicit_pointer
:
22044 return valx1
->val_class
== dw_val_class_die_ref
22045 && valx1
->val_class
== valy1
->val_class
22046 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
22047 && valx2
->v
.val_int
== valy2
->v
.val_int
;
22048 case DW_OP_GNU_entry_value
:
22049 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
22050 case DW_OP_GNU_const_type
:
22051 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
22052 || valx2
->val_class
!= valy2
->val_class
)
22054 switch (valx2
->val_class
)
22056 case dw_val_class_const
:
22057 return valx2
->v
.val_int
== valy2
->v
.val_int
;
22058 case dw_val_class_vec
:
22059 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
22060 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
22061 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
22062 valx2
->v
.val_vec
.elt_size
22063 * valx2
->v
.val_vec
.length
) == 0;
22064 case dw_val_class_const_double
:
22065 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
22066 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
22068 gcc_unreachable ();
22070 case DW_OP_GNU_regval_type
:
22071 case DW_OP_GNU_deref_type
:
22072 return valx1
->v
.val_int
== valy1
->v
.val_int
22073 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
22074 case DW_OP_GNU_convert
:
22075 case DW_OP_GNU_reinterpret
:
22076 if (valx1
->val_class
!= valy1
->val_class
)
22078 if (valx1
->val_class
== dw_val_class_unsigned_const
)
22079 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
22080 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
22081 case DW_OP_GNU_parameter_ref
:
22082 return valx1
->val_class
== dw_val_class_die_ref
22083 && valx1
->val_class
== valy1
->val_class
22084 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
22086 /* Other codes have no operands. */
22091 /* Return true if DWARF location expressions X and Y are the same. */
22094 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
22096 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
22097 if (x
->dw_loc_opc
!= y
->dw_loc_opc
22098 || x
->dtprel
!= y
->dtprel
22099 || !compare_loc_operands (x
, y
))
22101 return x
== NULL
&& y
== NULL
;
22104 /* Return precomputed hash of location list X. */
22107 loc_list_hash (const void *x
)
22109 return ((const struct dw_loc_list_struct
*) x
)->hash
;
22112 /* Return 1 if location lists X and Y are the same. */
22115 loc_list_eq (const void *x
, const void *y
)
22117 const struct dw_loc_list_struct
*a
= (const struct dw_loc_list_struct
*) x
;
22118 const struct dw_loc_list_struct
*b
= (const struct dw_loc_list_struct
*) y
;
22121 if (a
->hash
!= b
->hash
)
22123 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
22124 if (strcmp (a
->begin
, b
->begin
) != 0
22125 || strcmp (a
->end
, b
->end
) != 0
22126 || (a
->section
== NULL
) != (b
->section
== NULL
)
22127 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
22128 || !compare_locs (a
->expr
, b
->expr
))
22130 return a
== NULL
&& b
== NULL
;
22133 /* Recursively optimize location lists referenced from DIE
22134 children and share them whenever possible. */
22137 optimize_location_lists_1 (dw_die_ref die
, htab_t htab
)
22144 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
22145 if (AT_class (a
) == dw_val_class_loc_list
)
22147 dw_loc_list_ref list
= AT_loc_list (a
);
22148 /* TODO: perform some optimizations here, before hashing
22149 it and storing into the hash table. */
22150 hash_loc_list (list
);
22151 slot
= htab_find_slot_with_hash (htab
, list
, list
->hash
,
22154 *slot
= (void *) list
;
22156 a
->dw_attr_val
.v
.val_loc_list
= (dw_loc_list_ref
) *slot
;
22159 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
22162 /* Optimize location lists referenced from DIE
22163 children and share them whenever possible. */
22166 optimize_location_lists (dw_die_ref die
)
22168 htab_t htab
= htab_create (500, loc_list_hash
, loc_list_eq
, NULL
);
22169 optimize_location_lists_1 (die
, htab
);
22170 htab_delete (htab
);
22173 /* Output stuff that dwarf requires at the end of every file,
22174 and generate the DWARF-2 debugging info. */
22177 dwarf2out_finish (const char *filename
)
22179 limbo_die_node
*node
, *next_node
;
22180 comdat_type_node
*ctnode
;
22181 htab_t comdat_type_table
;
22184 /* PCH might result in DW_AT_producer string being restored from the
22185 header compilation, fix it up if needed. */
22186 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
22187 if (strcmp (AT_string (producer
), producer_string
) != 0)
22189 struct indirect_string_node
*node
= find_AT_string (producer_string
);
22190 producer
->dw_attr_val
.v
.val_str
= node
;
22193 gen_scheduled_generic_parms_dies ();
22194 gen_remaining_tmpl_value_param_die_attribute ();
22196 /* Add the name for the main input file now. We delayed this from
22197 dwarf2out_init to avoid complications with PCH. */
22198 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
22199 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
22200 add_comp_dir_attribute (comp_unit_die ());
22201 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
22204 htab_traverse (file_table
, file_table_relative_p
, &p
);
22206 add_comp_dir_attribute (comp_unit_die ());
22209 for (i
= 0; i
< VEC_length (deferred_locations
, deferred_locations_list
); i
++)
22211 add_location_or_const_value_attribute (
22212 VEC_index (deferred_locations
, deferred_locations_list
, i
)->die
,
22213 VEC_index (deferred_locations
, deferred_locations_list
, i
)->variable
,
22218 /* Traverse the limbo die list, and add parent/child links. The only
22219 dies without parents that should be here are concrete instances of
22220 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
22221 For concrete instances, we can get the parent die from the abstract
22223 for (node
= limbo_die_list
; node
; node
= next_node
)
22225 dw_die_ref die
= node
->die
;
22226 next_node
= node
->next
;
22228 if (die
->die_parent
== NULL
)
22230 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
22232 if (origin
&& origin
->die_parent
)
22233 add_child_die (origin
->die_parent
, die
);
22234 else if (is_cu_die (die
))
22236 else if (seen_error ())
22237 /* It's OK to be confused by errors in the input. */
22238 add_child_die (comp_unit_die (), die
);
22241 /* In certain situations, the lexical block containing a
22242 nested function can be optimized away, which results
22243 in the nested function die being orphaned. Likewise
22244 with the return type of that nested function. Force
22245 this to be a child of the containing function.
22247 It may happen that even the containing function got fully
22248 inlined and optimized out. In that case we are lost and
22249 assign the empty child. This should not be big issue as
22250 the function is likely unreachable too. */
22251 gcc_assert (node
->created_for
);
22253 if (DECL_P (node
->created_for
))
22254 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
22255 else if (TYPE_P (node
->created_for
))
22256 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
22258 origin
= comp_unit_die ();
22260 add_child_die (origin
, die
);
22265 limbo_die_list
= NULL
;
22267 #if ENABLE_ASSERT_CHECKING
22269 dw_die_ref die
= comp_unit_die (), c
;
22270 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
22273 resolve_addr (comp_unit_die ());
22274 move_marked_base_types ();
22276 for (node
= deferred_asm_name
; node
; node
= node
->next
)
22278 tree decl
= node
->created_for
;
22279 /* When generating LTO bytecode we can not generate new assembler
22280 names at this point and all important decls got theirs via
22282 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
22283 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
22285 add_linkage_attr (node
->die
, decl
);
22286 move_linkage_attr (node
->die
);
22290 deferred_asm_name
= NULL
;
22292 /* Walk through the list of incomplete types again, trying once more to
22293 emit full debugging info for them. */
22294 retry_incomplete_types ();
22296 if (flag_eliminate_unused_debug_types
)
22297 prune_unused_types ();
22299 /* Generate separate COMDAT sections for type DIEs. */
22300 if (use_debug_types
)
22302 break_out_comdat_types (comp_unit_die ());
22304 /* Each new type_unit DIE was added to the limbo die list when created.
22305 Since these have all been added to comdat_type_list, clear the
22307 limbo_die_list
= NULL
;
22309 /* For each new comdat type unit, copy declarations for incomplete
22310 types to make the new unit self-contained (i.e., no direct
22311 references to the main compile unit). */
22312 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22313 copy_decls_for_unworthy_types (ctnode
->root_die
);
22314 copy_decls_for_unworthy_types (comp_unit_die ());
22316 /* In the process of copying declarations from one unit to another,
22317 we may have left some declarations behind that are no longer
22318 referenced. Prune them. */
22319 prune_unused_types ();
22322 /* Generate separate CUs for each of the include files we've seen.
22323 They will go into limbo_die_list. */
22324 if (flag_eliminate_dwarf2_dups
)
22325 break_out_includes (comp_unit_die ());
22327 /* Traverse the DIE's and add add sibling attributes to those DIE's
22328 that have children. */
22329 add_sibling_attributes (comp_unit_die ());
22330 for (node
= limbo_die_list
; node
; node
= node
->next
)
22331 add_sibling_attributes (node
->die
);
22332 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22333 add_sibling_attributes (ctnode
->root_die
);
22335 /* Output a terminator label for the .text section. */
22336 switch_to_section (text_section
);
22337 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
22338 if (cold_text_section
)
22340 switch_to_section (cold_text_section
);
22341 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
22344 /* We can only use the low/high_pc attributes if all of the code was
22346 if (!have_multiple_function_sections
22347 || (dwarf_version
< 3 && dwarf_strict
))
22349 /* Don't add if the CU has no associated code. */
22350 if (text_section_used
)
22352 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc
, text_section_label
);
22353 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc
, text_end_label
);
22360 bool range_list_added
= false;
22362 if (text_section_used
)
22363 add_ranges_by_labels (comp_unit_die (), text_section_label
,
22364 text_end_label
, &range_list_added
);
22365 if (cold_text_section_used
)
22366 add_ranges_by_labels (comp_unit_die (), cold_text_section_label
,
22367 cold_end_label
, &range_list_added
);
22369 FOR_EACH_VEC_ELT (dw_fde_ref
, fde_vec
, fde_idx
, fde
)
22371 if (DECL_IGNORED_P (fde
->decl
))
22373 if (!fde
->in_std_section
)
22374 add_ranges_by_labels (comp_unit_die (), fde
->dw_fde_begin
,
22375 fde
->dw_fde_end
, &range_list_added
);
22376 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
22377 add_ranges_by_labels (comp_unit_die (), fde
->dw_fde_second_begin
,
22378 fde
->dw_fde_second_end
, &range_list_added
);
22381 if (range_list_added
)
22383 /* We need to give .debug_loc and .debug_ranges an appropriate
22384 "base address". Use zero so that these addresses become
22385 absolute. Historically, we've emitted the unexpected
22386 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
22387 Emit both to give time for other tools to adapt. */
22388 add_AT_addr (comp_unit_die (), DW_AT_low_pc
, const0_rtx
);
22389 if (! dwarf_strict
&& dwarf_version
< 4)
22390 add_AT_addr (comp_unit_die (), DW_AT_entry_pc
, const0_rtx
);
22396 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
22397 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list
,
22398 debug_line_section_label
);
22401 add_AT_macptr (comp_unit_die (),
22402 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
22403 macinfo_section_label
);
22405 if (have_location_lists
)
22406 optimize_location_lists (comp_unit_die ());
22408 /* Output all of the compilation units. We put the main one last so that
22409 the offsets are available to output_pubnames. */
22410 for (node
= limbo_die_list
; node
; node
= node
->next
)
22411 output_comp_unit (node
->die
, 0);
22413 comdat_type_table
= htab_create (100, htab_ct_hash
, htab_ct_eq
, NULL
);
22414 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22416 void **slot
= htab_find_slot (comdat_type_table
, ctnode
, INSERT
);
22418 /* Don't output duplicate types. */
22419 if (*slot
!= HTAB_EMPTY_ENTRY
)
22422 /* Add a pointer to the line table for the main compilation unit
22423 so that the debugger can make sense of DW_AT_decl_file
22425 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
22426 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
22427 debug_line_section_label
);
22429 output_comdat_type_unit (ctnode
);
22432 htab_delete (comdat_type_table
);
22434 add_AT_pubnames (comp_unit_die ());
22436 /* Output the main compilation unit if non-empty or if .debug_macinfo
22437 or .debug_macro will be emitted. */
22438 output_comp_unit (comp_unit_die (), have_macinfo
);
22440 /* Output the abbreviation table. */
22441 if (abbrev_die_table_in_use
!= 1)
22443 switch_to_section (debug_abbrev_section
);
22444 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
22445 output_abbrev_section ();
22448 /* Output location list section if necessary. */
22449 if (have_location_lists
)
22451 /* Output the location lists info. */
22452 switch_to_section (debug_loc_section
);
22453 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
22454 DEBUG_LOC_SECTION_LABEL
, 0);
22455 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
22456 output_location_lists (comp_unit_die ());
22459 /* Output public names and types tables if necessary. */
22460 output_pubnames (pubname_table
);
22461 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
22462 It shouldn't hurt to emit it always, since pure DWARF2 consumers
22463 simply won't look for the section. */
22464 output_pubnames (pubtype_table
);
22466 /* Output the address range information if a CU (.debug_info section)
22467 was emitted. We output an empty table even if we had no functions
22468 to put in it. This because the consumer has no way to tell the
22469 difference between an empty table that we omitted and failure to
22470 generate a table that would have contained data. */
22471 if (info_section_emitted
)
22473 unsigned long aranges_length
= size_of_aranges ();
22475 switch_to_section (debug_aranges_section
);
22476 output_aranges (aranges_length
);
22479 /* Output ranges section if necessary. */
22480 if (ranges_table_in_use
)
22482 switch_to_section (debug_ranges_section
);
22483 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
22487 /* Have to end the macro section. */
22490 switch_to_section (debug_macinfo_section
);
22491 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
22493 dw2_asm_output_data (1, 0, "End compilation unit");
22496 /* Output the source line correspondence table. We must do this
22497 even if there is no line information. Otherwise, on an empty
22498 translation unit, we will generate a present, but empty,
22499 .debug_info section. IRIX 6.5 `nm' will then complain when
22500 examining the file. This is done late so that any filenames
22501 used by the debug_info section are marked as 'used'. */
22502 switch_to_section (debug_line_section
);
22503 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
22504 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
22505 output_line_info ();
22507 /* If we emitted any DW_FORM_strp form attribute, output the string
22509 if (debug_str_hash
)
22510 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
22513 #include "gt-dwarf2out.h"