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
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 "langhooks.h"
93 #include "tree-pass.h"
94 #include "tree-flow.h"
96 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
97 static rtx last_var_location_insn
;
99 #ifdef VMS_DEBUGGING_INFO
100 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
102 /* Define this macro to be a nonzero value if the directory specifications
103 which are output in the debug info should end with a separator. */
104 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
105 /* Define this macro to evaluate to a nonzero value if GCC should refrain
106 from generating indirect strings in DWARF2 debug information, for instance
107 if your target is stuck with an old version of GDB that is unable to
108 process them properly or uses VMS Debug. */
109 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
111 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
112 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
115 /* ??? Poison these here until it can be done generically. They've been
116 totally replaced in this file; make sure it stays that way. */
117 #undef DWARF2_UNWIND_INFO
118 #undef DWARF2_FRAME_INFO
119 #if (GCC_VERSION >= 3000)
120 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
123 #ifndef INCOMING_RETURN_ADDR_RTX
124 #define INCOMING_RETURN_ADDR_RTX (gcc_unreachable (), NULL_RTX)
127 /* Map register numbers held in the call frame info that gcc has
128 collected using DWARF_FRAME_REGNUM to those that should be output in
129 .debug_frame and .eh_frame. */
130 #ifndef DWARF2_FRAME_REG_OUT
131 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
134 /* Save the result of dwarf2out_do_frame across PCH. */
135 static GTY(()) bool saved_do_cfi_asm
= 0;
137 /* Decide whether we want to emit frame unwind information for the current
141 dwarf2out_do_frame (void)
143 /* We want to emit correct CFA location expressions or lists, so we
144 have to return true if we're going to output debug info, even if
145 we're not going to output frame or unwind info. */
146 if (write_symbols
== DWARF2_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
149 if (saved_do_cfi_asm
)
152 if (targetm
.debug_unwind_info () == UI_DWARF2
)
155 if ((flag_unwind_tables
|| flag_exceptions
)
156 && targetm
.except_unwind_info () == UI_DWARF2
)
162 /* Decide whether to emit frame unwind via assembler directives. */
165 dwarf2out_do_cfi_asm (void)
169 #ifdef MIPS_DEBUGGING_INFO
172 if (saved_do_cfi_asm
)
174 if (!flag_dwarf2_cfi_asm
|| !dwarf2out_do_frame ())
176 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE
)
179 /* Make sure the personality encoding is one the assembler can support.
180 In particular, aligned addresses can't be handled. */
181 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
182 if ((enc
& 0x70) != 0 && (enc
& 0x70) != DW_EH_PE_pcrel
)
184 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
185 if ((enc
& 0x70) != 0 && (enc
& 0x70) != DW_EH_PE_pcrel
)
188 /* If we can't get the assembler to emit only .debug_frame, and we don't need
189 dwarf2 unwind info for exceptions, then emit .debug_frame by hand. */
190 if (!HAVE_GAS_CFI_SECTIONS_DIRECTIVE
191 && !flag_unwind_tables
&& !flag_exceptions
192 && targetm
.except_unwind_info () != UI_DWARF2
)
195 saved_do_cfi_asm
= true;
199 /* The size of the target's pointer type. */
201 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
204 /* Array of RTXes referenced by the debugging information, which therefore
205 must be kept around forever. */
206 static GTY(()) VEC(rtx
,gc
) *used_rtx_array
;
208 /* A pointer to the base of a list of incomplete types which might be
209 completed at some later time. incomplete_types_list needs to be a
210 VEC(tree,gc) because we want to tell the garbage collector about
212 static GTY(()) VEC(tree
,gc
) *incomplete_types
;
214 /* A pointer to the base of a table of references to declaration
215 scopes. This table is a display which tracks the nesting
216 of declaration scopes at the current scope and containing
217 scopes. This table is used to find the proper place to
218 define type declaration DIE's. */
219 static GTY(()) VEC(tree
,gc
) *decl_scope_table
;
221 /* Pointers to various DWARF2 sections. */
222 static GTY(()) section
*debug_info_section
;
223 static GTY(()) section
*debug_abbrev_section
;
224 static GTY(()) section
*debug_aranges_section
;
225 static GTY(()) section
*debug_macinfo_section
;
226 static GTY(()) section
*debug_line_section
;
227 static GTY(()) section
*debug_loc_section
;
228 static GTY(()) section
*debug_pubnames_section
;
229 static GTY(()) section
*debug_pubtypes_section
;
230 static GTY(()) section
*debug_dcall_section
;
231 static GTY(()) section
*debug_vcall_section
;
232 static GTY(()) section
*debug_str_section
;
233 static GTY(()) section
*debug_ranges_section
;
234 static GTY(()) section
*debug_frame_section
;
236 /* Personality decl of current unit. Used only when assembler does not support
238 static GTY(()) rtx current_unit_personality
;
240 /* How to start an assembler comment. */
241 #ifndef ASM_COMMENT_START
242 #define ASM_COMMENT_START ";#"
245 typedef struct dw_cfi_struct
*dw_cfi_ref
;
246 typedef struct dw_fde_struct
*dw_fde_ref
;
247 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
249 /* Call frames are described using a sequence of Call Frame
250 Information instructions. The register number, offset
251 and address fields are provided as possible operands;
252 their use is selected by the opcode field. */
254 enum dw_cfi_oprnd_type
{
256 dw_cfi_oprnd_reg_num
,
262 typedef union GTY(()) dw_cfi_oprnd_struct
{
263 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num
;
264 HOST_WIDE_INT
GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset
;
265 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr
;
266 struct dw_loc_descr_struct
* GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc
;
270 typedef struct GTY(()) dw_cfi_struct
{
271 dw_cfi_ref dw_cfi_next
;
272 enum dwarf_call_frame_info dw_cfi_opc
;
273 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
275 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
280 /* This is how we define the location of the CFA. We use to handle it
281 as REG + OFFSET all the time, but now it can be more complex.
282 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
283 Instead of passing around REG and OFFSET, we pass a copy
284 of this structure. */
285 typedef struct GTY(()) cfa_loc
{
286 HOST_WIDE_INT offset
;
287 HOST_WIDE_INT base_offset
;
289 BOOL_BITFIELD indirect
: 1; /* 1 if CFA is accessed via a dereference. */
290 BOOL_BITFIELD in_use
: 1; /* 1 if a saved cfa is stored here. */
293 /* All call frame descriptions (FDE's) in the GCC generated DWARF
294 refer to a single Common Information Entry (CIE), defined at
295 the beginning of the .debug_frame section. This use of a single
296 CIE obviates the need to keep track of multiple CIE's
297 in the DWARF generation routines below. */
299 typedef struct GTY(()) dw_fde_struct
{
301 const char *dw_fde_begin
;
302 const char *dw_fde_current_label
;
303 const char *dw_fde_end
;
304 const char *dw_fde_vms_end_prologue
;
305 const char *dw_fde_vms_begin_epilogue
;
306 const char *dw_fde_hot_section_label
;
307 const char *dw_fde_hot_section_end_label
;
308 const char *dw_fde_unlikely_section_label
;
309 const char *dw_fde_unlikely_section_end_label
;
310 dw_cfi_ref dw_fde_cfi
;
311 dw_cfi_ref dw_fde_switch_cfi
; /* Last CFI before switching sections. */
312 HOST_WIDE_INT stack_realignment
;
313 unsigned funcdef_number
;
314 /* Dynamic realign argument pointer register. */
315 unsigned int drap_reg
;
316 /* Virtual dynamic realign argument pointer register. */
317 unsigned int vdrap_reg
;
318 /* These 3 flags are copied from rtl_data in function.h. */
319 unsigned all_throwers_are_sibcalls
: 1;
320 unsigned uses_eh_lsda
: 1;
321 unsigned nothrow
: 1;
322 /* Whether we did stack realign in this call frame. */
323 unsigned stack_realign
: 1;
324 /* Whether dynamic realign argument pointer register has been saved. */
325 unsigned drap_reg_saved
: 1;
326 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
327 unsigned in_std_section
: 1;
328 /* True iff dw_fde_unlikely_section_label is in text_section or
329 cold_text_section. */
330 unsigned cold_in_std_section
: 1;
331 /* True iff switched sections. */
332 unsigned dw_fde_switched_sections
: 1;
333 /* True iff switching from cold to hot section. */
334 unsigned dw_fde_switched_cold_to_hot
: 1;
338 /* Maximum size (in bytes) of an artificially generated label. */
339 #define MAX_ARTIFICIAL_LABEL_BYTES 30
341 /* The size of addresses as they appear in the Dwarf 2 data.
342 Some architectures use word addresses to refer to code locations,
343 but Dwarf 2 info always uses byte addresses. On such machines,
344 Dwarf 2 addresses need to be larger than the architecture's
346 #ifndef DWARF2_ADDR_SIZE
347 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
350 /* The size in bytes of a DWARF field indicating an offset or length
351 relative to a debug info section, specified to be 4 bytes in the
352 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
355 #ifndef DWARF_OFFSET_SIZE
356 #define DWARF_OFFSET_SIZE 4
359 /* The size in bytes of a DWARF 4 type signature. */
361 #ifndef DWARF_TYPE_SIGNATURE_SIZE
362 #define DWARF_TYPE_SIGNATURE_SIZE 8
365 /* According to the (draft) DWARF 3 specification, the initial length
366 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
367 bytes are 0xffffffff, followed by the length stored in the next 8
370 However, the SGI/MIPS ABI uses an initial length which is equal to
371 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
373 #ifndef DWARF_INITIAL_LENGTH_SIZE
374 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
377 /* Round SIZE up to the nearest BOUNDARY. */
378 #define DWARF_ROUND(SIZE,BOUNDARY) \
379 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
381 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
382 #ifndef DWARF_CIE_DATA_ALIGNMENT
383 #ifdef STACK_GROWS_DOWNWARD
384 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
386 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
390 /* CIE identifier. */
391 #if HOST_BITS_PER_WIDE_INT >= 64
392 #define DWARF_CIE_ID \
393 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
395 #define DWARF_CIE_ID DW_CIE_ID
398 /* A pointer to the base of a table that contains frame description
399 information for each routine. */
400 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table
;
402 /* Number of elements currently allocated for fde_table. */
403 static GTY(()) unsigned fde_table_allocated
;
405 /* Number of elements in fde_table currently in use. */
406 static GTY(()) unsigned fde_table_in_use
;
408 /* Size (in elements) of increments by which we may expand the
410 #define FDE_TABLE_INCREMENT 256
412 /* Get the current fde_table entry we should use. */
414 static inline dw_fde_ref
417 return fde_table_in_use
? &fde_table
[fde_table_in_use
- 1] : NULL
;
420 /* A list of call frame insns for the CIE. */
421 static GTY(()) dw_cfi_ref cie_cfi_head
;
423 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
424 attribute that accelerates the lookup of the FDE associated
425 with the subprogram. This variable holds the table index of the FDE
426 associated with the current function (body) definition. */
427 static unsigned current_funcdef_fde
;
429 struct GTY(()) indirect_string_node
{
431 unsigned int refcount
;
432 enum dwarf_form form
;
436 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
438 /* True if the compilation unit has location entries that reference
440 static GTY(()) bool debug_str_hash_forced
= false;
442 static GTY(()) int dw2_string_counter
;
443 static GTY(()) unsigned long dwarf2out_cfi_label_num
;
445 /* True if the compilation unit places functions in more than one section. */
446 static GTY(()) bool have_multiple_function_sections
= false;
448 /* Whether the default text and cold text sections have been used at all. */
450 static GTY(()) bool text_section_used
= false;
451 static GTY(()) bool cold_text_section_used
= false;
453 /* The default cold text section. */
454 static GTY(()) section
*cold_text_section
;
456 /* Forward declarations for functions defined in this file. */
458 static char *stripattributes (const char *);
459 static const char *dwarf_cfi_name (unsigned);
460 static dw_cfi_ref
new_cfi (void);
461 static void add_cfi (dw_cfi_ref
*, dw_cfi_ref
);
462 static void add_fde_cfi (const char *, dw_cfi_ref
);
463 static void lookup_cfa_1 (dw_cfi_ref
, dw_cfa_location
*, dw_cfa_location
*);
464 static void lookup_cfa (dw_cfa_location
*);
465 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT
);
466 static void initial_return_save (rtx
);
467 static HOST_WIDE_INT
stack_adjust_offset (const_rtx
, HOST_WIDE_INT
,
469 static void output_cfi (dw_cfi_ref
, dw_fde_ref
, int);
470 static void output_cfi_directive (dw_cfi_ref
);
471 static void output_call_frame_info (int);
472 static void dwarf2out_note_section_used (void);
473 static bool clobbers_queued_reg_save (const_rtx
);
474 static void dwarf2out_frame_debug_expr (rtx
, const char *);
476 /* Support for complex CFA locations. */
477 static void output_cfa_loc (dw_cfi_ref
);
478 static void output_cfa_loc_raw (dw_cfi_ref
);
479 static void get_cfa_from_loc_descr (dw_cfa_location
*,
480 struct dw_loc_descr_struct
*);
481 static struct dw_loc_descr_struct
*build_cfa_loc
482 (dw_cfa_location
*, HOST_WIDE_INT
);
483 static struct dw_loc_descr_struct
*build_cfa_aligned_loc
484 (HOST_WIDE_INT
, HOST_WIDE_INT
);
485 static void def_cfa_1 (const char *, dw_cfa_location
*);
486 static struct dw_loc_descr_struct
*mem_loc_descriptor
487 (rtx
, enum machine_mode mode
, enum var_init_status
);
489 /* How to start an assembler comment. */
490 #ifndef ASM_COMMENT_START
491 #define ASM_COMMENT_START ";#"
494 /* Data and reference forms for relocatable data. */
495 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
496 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
498 #ifndef DEBUG_FRAME_SECTION
499 #define DEBUG_FRAME_SECTION ".debug_frame"
502 #ifndef FUNC_BEGIN_LABEL
503 #define FUNC_BEGIN_LABEL "LFB"
506 #ifndef FUNC_END_LABEL
507 #define FUNC_END_LABEL "LFE"
510 #ifndef PROLOGUE_END_LABEL
511 #define PROLOGUE_END_LABEL "LPE"
514 #ifndef EPILOGUE_BEGIN_LABEL
515 #define EPILOGUE_BEGIN_LABEL "LEB"
518 #ifndef FRAME_BEGIN_LABEL
519 #define FRAME_BEGIN_LABEL "Lframe"
521 #define CIE_AFTER_SIZE_LABEL "LSCIE"
522 #define CIE_END_LABEL "LECIE"
523 #define FDE_LABEL "LSFDE"
524 #define FDE_AFTER_SIZE_LABEL "LASFDE"
525 #define FDE_END_LABEL "LEFDE"
526 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
527 #define LINE_NUMBER_END_LABEL "LELT"
528 #define LN_PROLOG_AS_LABEL "LASLTP"
529 #define LN_PROLOG_END_LABEL "LELTP"
530 #define DIE_LABEL_PREFIX "DW"
532 /* The DWARF 2 CFA column which tracks the return address. Normally this
533 is the column for PC, or the first column after all of the hard
535 #ifndef DWARF_FRAME_RETURN_COLUMN
537 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
539 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
543 /* The mapping from gcc register number to DWARF 2 CFA column number. By
544 default, we just provide columns for all registers. */
545 #ifndef DWARF_FRAME_REGNUM
546 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
549 /* Hook used by __throw. */
552 expand_builtin_dwarf_sp_column (void)
554 unsigned int dwarf_regnum
= DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
);
555 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum
, 1));
558 /* Return a pointer to a copy of the section string name S with all
559 attributes stripped off, and an asterisk prepended (for assemble_name). */
562 stripattributes (const char *s
)
564 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
569 while (*s
&& *s
!= ',')
576 /* MEM is a memory reference for the register size table, each element of
577 which has mode MODE. Initialize column C as a return address column. */
580 init_return_column_size (enum machine_mode mode
, rtx mem
, unsigned int c
)
582 HOST_WIDE_INT offset
= c
* GET_MODE_SIZE (mode
);
583 HOST_WIDE_INT size
= GET_MODE_SIZE (Pmode
);
584 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
587 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
589 static inline HOST_WIDE_INT
590 div_data_align (HOST_WIDE_INT off
)
592 HOST_WIDE_INT r
= off
/ DWARF_CIE_DATA_ALIGNMENT
;
593 gcc_assert (r
* DWARF_CIE_DATA_ALIGNMENT
== off
);
597 /* Return true if we need a signed version of a given opcode
598 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
601 need_data_align_sf_opcode (HOST_WIDE_INT off
)
603 return DWARF_CIE_DATA_ALIGNMENT
< 0 ? off
> 0 : off
< 0;
606 /* Generate code to initialize the register size table. */
609 expand_builtin_init_dwarf_reg_sizes (tree address
)
612 enum machine_mode mode
= TYPE_MODE (char_type_node
);
613 rtx addr
= expand_normal (address
);
614 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
615 bool wrote_return_column
= false;
617 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
619 int rnum
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i
), 1);
621 if (rnum
< DWARF_FRAME_REGISTERS
)
623 HOST_WIDE_INT offset
= rnum
* GET_MODE_SIZE (mode
);
624 enum machine_mode save_mode
= reg_raw_mode
[i
];
627 if (HARD_REGNO_CALL_PART_CLOBBERED (i
, save_mode
))
628 save_mode
= choose_hard_reg_mode (i
, 1, true);
629 if (DWARF_FRAME_REGNUM (i
) == DWARF_FRAME_RETURN_COLUMN
)
631 if (save_mode
== VOIDmode
)
633 wrote_return_column
= true;
635 size
= GET_MODE_SIZE (save_mode
);
639 emit_move_insn (adjust_address (mem
, mode
, offset
),
640 gen_int_mode (size
, mode
));
644 if (!wrote_return_column
)
645 init_return_column_size (mode
, mem
, DWARF_FRAME_RETURN_COLUMN
);
647 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
648 init_return_column_size (mode
, mem
, DWARF_ALT_FRAME_RETURN_COLUMN
);
651 targetm
.init_dwarf_reg_sizes_extra (address
);
654 /* Convert a DWARF call frame info. operation to its string name */
657 dwarf_cfi_name (unsigned int cfi_opc
)
661 case DW_CFA_advance_loc
:
662 return "DW_CFA_advance_loc";
664 return "DW_CFA_offset";
666 return "DW_CFA_restore";
670 return "DW_CFA_set_loc";
671 case DW_CFA_advance_loc1
:
672 return "DW_CFA_advance_loc1";
673 case DW_CFA_advance_loc2
:
674 return "DW_CFA_advance_loc2";
675 case DW_CFA_advance_loc4
:
676 return "DW_CFA_advance_loc4";
677 case DW_CFA_offset_extended
:
678 return "DW_CFA_offset_extended";
679 case DW_CFA_restore_extended
:
680 return "DW_CFA_restore_extended";
681 case DW_CFA_undefined
:
682 return "DW_CFA_undefined";
683 case DW_CFA_same_value
:
684 return "DW_CFA_same_value";
685 case DW_CFA_register
:
686 return "DW_CFA_register";
687 case DW_CFA_remember_state
:
688 return "DW_CFA_remember_state";
689 case DW_CFA_restore_state
:
690 return "DW_CFA_restore_state";
692 return "DW_CFA_def_cfa";
693 case DW_CFA_def_cfa_register
:
694 return "DW_CFA_def_cfa_register";
695 case DW_CFA_def_cfa_offset
:
696 return "DW_CFA_def_cfa_offset";
699 case DW_CFA_def_cfa_expression
:
700 return "DW_CFA_def_cfa_expression";
701 case DW_CFA_expression
:
702 return "DW_CFA_expression";
703 case DW_CFA_offset_extended_sf
:
704 return "DW_CFA_offset_extended_sf";
705 case DW_CFA_def_cfa_sf
:
706 return "DW_CFA_def_cfa_sf";
707 case DW_CFA_def_cfa_offset_sf
:
708 return "DW_CFA_def_cfa_offset_sf";
710 /* SGI/MIPS specific */
711 case DW_CFA_MIPS_advance_loc8
:
712 return "DW_CFA_MIPS_advance_loc8";
715 case DW_CFA_GNU_window_save
:
716 return "DW_CFA_GNU_window_save";
717 case DW_CFA_GNU_args_size
:
718 return "DW_CFA_GNU_args_size";
719 case DW_CFA_GNU_negative_offset_extended
:
720 return "DW_CFA_GNU_negative_offset_extended";
723 return "DW_CFA_<unknown>";
727 /* Return a pointer to a newly allocated Call Frame Instruction. */
729 static inline dw_cfi_ref
732 dw_cfi_ref cfi
= ggc_alloc_dw_cfi_node ();
734 cfi
->dw_cfi_next
= NULL
;
735 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
736 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
741 /* Add a Call Frame Instruction to list of instructions. */
744 add_cfi (dw_cfi_ref
*list_head
, dw_cfi_ref cfi
)
747 dw_fde_ref fde
= current_fde ();
749 /* When DRAP is used, CFA is defined with an expression. Redefine
750 CFA may lead to a different CFA value. */
751 /* ??? Of course, this heuristic fails when we're annotating epilogues,
752 because of course we'll always want to redefine the CFA back to the
753 stack pointer on the way out. Where should we move this check? */
754 if (0 && fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
755 switch (cfi
->dw_cfi_opc
)
757 case DW_CFA_def_cfa_register
:
758 case DW_CFA_def_cfa_offset
:
759 case DW_CFA_def_cfa_offset_sf
:
761 case DW_CFA_def_cfa_sf
:
768 /* Find the end of the chain. */
769 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
775 /* Generate a new label for the CFI info to refer to. FORCE is true
776 if a label needs to be output even when using .cfi_* directives. */
779 dwarf2out_cfi_label (bool force
)
781 static char label
[20];
783 if (!force
&& dwarf2out_do_cfi_asm ())
785 /* In this case, we will be emitting the asm directive instead of
786 the label, so just return a placeholder to keep the rest of the
788 strcpy (label
, "<do not output>");
792 int num
= dwarf2out_cfi_label_num
++;
793 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", num
);
794 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LCFI", num
);
800 /* True if remember_state should be emitted before following CFI directive. */
801 static bool emit_cfa_remember
;
803 /* True if any CFI directives were emitted at the current insn. */
804 static bool any_cfis_emitted
;
806 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
807 or to the CIE if LABEL is NULL. */
810 add_fde_cfi (const char *label
, dw_cfi_ref cfi
)
812 dw_cfi_ref
*list_head
;
814 if (emit_cfa_remember
)
816 dw_cfi_ref cfi_remember
;
818 /* Emit the state save. */
819 emit_cfa_remember
= false;
820 cfi_remember
= new_cfi ();
821 cfi_remember
->dw_cfi_opc
= DW_CFA_remember_state
;
822 add_fde_cfi (label
, cfi_remember
);
825 list_head
= &cie_cfi_head
;
827 if (dwarf2out_do_cfi_asm ())
831 dw_fde_ref fde
= current_fde ();
833 gcc_assert (fde
!= NULL
);
835 /* We still have to add the cfi to the list so that lookup_cfa
836 works later on. When -g2 and above we even need to force
837 emitting of CFI labels and add to list a DW_CFA_set_loc for
838 convert_cfa_to_fb_loc_list purposes. If we're generating
839 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
840 convert_cfa_to_fb_loc_list. */
841 if (dwarf_version
== 2
842 && debug_info_level
> DINFO_LEVEL_TERSE
843 && (write_symbols
== DWARF2_DEBUG
844 || write_symbols
== VMS_AND_DWARF2_DEBUG
))
846 switch (cfi
->dw_cfi_opc
)
848 case DW_CFA_def_cfa_offset
:
849 case DW_CFA_def_cfa_offset_sf
:
850 case DW_CFA_def_cfa_register
:
852 case DW_CFA_def_cfa_sf
:
853 case DW_CFA_def_cfa_expression
:
854 case DW_CFA_restore_state
:
855 if (*label
== 0 || strcmp (label
, "<do not output>") == 0)
856 label
= dwarf2out_cfi_label (true);
858 if (fde
->dw_fde_current_label
== NULL
859 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
863 label
= xstrdup (label
);
865 /* Set the location counter to the new label. */
867 /* It doesn't metter whether DW_CFA_set_loc
868 or DW_CFA_advance_loc4 is added here, those aren't
869 emitted into assembly, only looked up by
870 convert_cfa_to_fb_loc_list. */
871 xcfi
->dw_cfi_opc
= DW_CFA_set_loc
;
872 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
873 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
874 fde
->dw_fde_current_label
= label
;
882 output_cfi_directive (cfi
);
884 list_head
= &fde
->dw_fde_cfi
;
885 any_cfis_emitted
= true;
887 /* ??? If this is a CFI for the CIE, we don't emit. This
888 assumes that the standard CIE contents that the assembler
889 uses matches the standard CIE contents that the compiler
890 uses. This is probably a bad assumption. I'm not quite
891 sure how to address this for now. */
895 dw_fde_ref fde
= current_fde ();
897 gcc_assert (fde
!= NULL
);
900 label
= dwarf2out_cfi_label (false);
902 if (fde
->dw_fde_current_label
== NULL
903 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
907 label
= xstrdup (label
);
909 /* Set the location counter to the new label. */
911 /* If we have a current label, advance from there, otherwise
912 set the location directly using set_loc. */
913 xcfi
->dw_cfi_opc
= fde
->dw_fde_current_label
914 ? DW_CFA_advance_loc4
916 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
917 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
919 fde
->dw_fde_current_label
= label
;
922 list_head
= &fde
->dw_fde_cfi
;
923 any_cfis_emitted
= true;
926 add_cfi (list_head
, cfi
);
929 /* Subroutine of lookup_cfa. */
932 lookup_cfa_1 (dw_cfi_ref cfi
, dw_cfa_location
*loc
, dw_cfa_location
*remember
)
934 switch (cfi
->dw_cfi_opc
)
936 case DW_CFA_def_cfa_offset
:
937 case DW_CFA_def_cfa_offset_sf
:
938 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
940 case DW_CFA_def_cfa_register
:
941 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
944 case DW_CFA_def_cfa_sf
:
945 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
946 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
948 case DW_CFA_def_cfa_expression
:
949 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
952 case DW_CFA_remember_state
:
953 gcc_assert (!remember
->in_use
);
955 remember
->in_use
= 1;
957 case DW_CFA_restore_state
:
958 gcc_assert (remember
->in_use
);
960 remember
->in_use
= 0;
968 /* Find the previous value for the CFA. */
971 lookup_cfa (dw_cfa_location
*loc
)
975 dw_cfa_location remember
;
977 memset (loc
, 0, sizeof (*loc
));
978 loc
->reg
= INVALID_REGNUM
;
981 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
982 lookup_cfa_1 (cfi
, loc
, &remember
);
984 fde
= current_fde ();
986 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
987 lookup_cfa_1 (cfi
, loc
, &remember
);
990 /* The current rule for calculating the DWARF2 canonical frame address. */
991 static dw_cfa_location cfa
;
993 /* The register used for saving registers to the stack, and its offset
995 static dw_cfa_location cfa_store
;
997 /* The current save location around an epilogue. */
998 static dw_cfa_location cfa_remember
;
1000 /* The running total of the size of arguments pushed onto the stack. */
1001 static HOST_WIDE_INT args_size
;
1003 /* The last args_size we actually output. */
1004 static HOST_WIDE_INT old_args_size
;
1006 /* Entry point to update the canonical frame address (CFA).
1007 LABEL is passed to add_fde_cfi. The value of CFA is now to be
1008 calculated from REG+OFFSET. */
1011 dwarf2out_def_cfa (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
1013 dw_cfa_location loc
;
1015 loc
.base_offset
= 0;
1017 loc
.offset
= offset
;
1018 def_cfa_1 (label
, &loc
);
1021 /* Determine if two dw_cfa_location structures define the same data. */
1024 cfa_equal_p (const dw_cfa_location
*loc1
, const dw_cfa_location
*loc2
)
1026 return (loc1
->reg
== loc2
->reg
1027 && loc1
->offset
== loc2
->offset
1028 && loc1
->indirect
== loc2
->indirect
1029 && (loc1
->indirect
== 0
1030 || loc1
->base_offset
== loc2
->base_offset
));
1033 /* This routine does the actual work. The CFA is now calculated from
1034 the dw_cfa_location structure. */
1037 def_cfa_1 (const char *label
, dw_cfa_location
*loc_p
)
1040 dw_cfa_location old_cfa
, loc
;
1045 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
1046 cfa_store
.offset
= loc
.offset
;
1048 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
1049 lookup_cfa (&old_cfa
);
1051 /* If nothing changed, no need to issue any call frame instructions. */
1052 if (cfa_equal_p (&loc
, &old_cfa
))
1057 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
&& !old_cfa
.indirect
)
1059 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1060 the CFA register did not change but the offset did. The data
1061 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1062 in the assembler via the .cfi_def_cfa_offset directive. */
1064 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset_sf
;
1066 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
1067 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
1070 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1071 else if (loc
.offset
== old_cfa
.offset
1072 && old_cfa
.reg
!= INVALID_REGNUM
1074 && !old_cfa
.indirect
)
1076 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1077 indicating the CFA register has changed to <register> but the
1078 offset has not changed. */
1079 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
1080 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
1084 else if (loc
.indirect
== 0)
1086 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1087 indicating the CFA register has changed to <register> with
1088 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1089 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1092 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_sf
;
1094 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
1095 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
1096 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
1100 /* Construct a DW_CFA_def_cfa_expression instruction to
1101 calculate the CFA using a full location expression since no
1102 register-offset pair is available. */
1103 struct dw_loc_descr_struct
*loc_list
;
1105 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
1106 loc_list
= build_cfa_loc (&loc
, 0);
1107 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
1110 add_fde_cfi (label
, cfi
);
1113 /* Add the CFI for saving a register. REG is the CFA column number.
1114 LABEL is passed to add_fde_cfi.
1115 If SREG is -1, the register is saved at OFFSET from the CFA;
1116 otherwise it is saved in SREG. */
1119 reg_save (const char *label
, unsigned int reg
, unsigned int sreg
, HOST_WIDE_INT offset
)
1121 dw_cfi_ref cfi
= new_cfi ();
1122 dw_fde_ref fde
= current_fde ();
1124 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
1126 /* When stack is aligned, store REG using DW_CFA_expression with
1129 && fde
->stack_realign
1130 && sreg
== INVALID_REGNUM
)
1132 cfi
->dw_cfi_opc
= DW_CFA_expression
;
1133 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
1134 cfi
->dw_cfi_oprnd2
.dw_cfi_loc
1135 = build_cfa_aligned_loc (offset
, fde
->stack_realignment
);
1137 else if (sreg
== INVALID_REGNUM
)
1139 if (need_data_align_sf_opcode (offset
))
1140 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
1141 else if (reg
& ~0x3f)
1142 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
1144 cfi
->dw_cfi_opc
= DW_CFA_offset
;
1145 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
1147 else if (sreg
== reg
)
1148 cfi
->dw_cfi_opc
= DW_CFA_same_value
;
1151 cfi
->dw_cfi_opc
= DW_CFA_register
;
1152 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
1155 add_fde_cfi (label
, cfi
);
1158 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1159 This CFI tells the unwinder that it needs to restore the window registers
1160 from the previous frame's window save area.
1162 ??? Perhaps we should note in the CIE where windows are saved (instead of
1163 assuming 0(cfa)) and what registers are in the window. */
1166 dwarf2out_window_save (const char *label
)
1168 dw_cfi_ref cfi
= new_cfi ();
1170 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
1171 add_fde_cfi (label
, cfi
);
1174 /* Entry point for saving a register to the stack. REG is the GCC register
1175 number. LABEL and OFFSET are passed to reg_save. */
1178 dwarf2out_reg_save (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
1180 reg_save (label
, DWARF_FRAME_REGNUM (reg
), INVALID_REGNUM
, offset
);
1183 /* Entry point for saving the return address in the stack.
1184 LABEL and OFFSET are passed to reg_save. */
1187 dwarf2out_return_save (const char *label
, HOST_WIDE_INT offset
)
1189 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, INVALID_REGNUM
, offset
);
1192 /* Entry point for saving the return address in a register.
1193 LABEL and SREG are passed to reg_save. */
1196 dwarf2out_return_reg (const char *label
, unsigned int sreg
)
1198 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, DWARF_FRAME_REGNUM (sreg
), 0);
1201 /* Record the initial position of the return address. RTL is
1202 INCOMING_RETURN_ADDR_RTX. */
1205 initial_return_save (rtx rtl
)
1207 unsigned int reg
= INVALID_REGNUM
;
1208 HOST_WIDE_INT offset
= 0;
1210 switch (GET_CODE (rtl
))
1213 /* RA is in a register. */
1214 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
1218 /* RA is on the stack. */
1219 rtl
= XEXP (rtl
, 0);
1220 switch (GET_CODE (rtl
))
1223 gcc_assert (REGNO (rtl
) == STACK_POINTER_REGNUM
);
1228 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
1229 offset
= INTVAL (XEXP (rtl
, 1));
1233 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
1234 offset
= -INTVAL (XEXP (rtl
, 1));
1244 /* The return address is at some offset from any value we can
1245 actually load. For instance, on the SPARC it is in %i7+8. Just
1246 ignore the offset for now; it doesn't matter for unwinding frames. */
1247 gcc_assert (CONST_INT_P (XEXP (rtl
, 1)));
1248 initial_return_save (XEXP (rtl
, 0));
1255 if (reg
!= DWARF_FRAME_RETURN_COLUMN
)
1256 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
1259 /* Given a SET, calculate the amount of stack adjustment it
1262 static HOST_WIDE_INT
1263 stack_adjust_offset (const_rtx pattern
, HOST_WIDE_INT cur_args_size
,
1264 HOST_WIDE_INT cur_offset
)
1266 const_rtx src
= SET_SRC (pattern
);
1267 const_rtx dest
= SET_DEST (pattern
);
1268 HOST_WIDE_INT offset
= 0;
1271 if (dest
== stack_pointer_rtx
)
1273 code
= GET_CODE (src
);
1275 /* Assume (set (reg sp) (reg whatever)) sets args_size
1277 if (code
== REG
&& src
!= stack_pointer_rtx
)
1279 offset
= -cur_args_size
;
1280 #ifndef STACK_GROWS_DOWNWARD
1283 return offset
- cur_offset
;
1286 if (! (code
== PLUS
|| code
== MINUS
)
1287 || XEXP (src
, 0) != stack_pointer_rtx
1288 || !CONST_INT_P (XEXP (src
, 1)))
1291 /* (set (reg sp) (plus (reg sp) (const_int))) */
1292 offset
= INTVAL (XEXP (src
, 1));
1298 if (MEM_P (src
) && !MEM_P (dest
))
1302 /* (set (mem (pre_dec (reg sp))) (foo)) */
1303 src
= XEXP (dest
, 0);
1304 code
= GET_CODE (src
);
1310 if (XEXP (src
, 0) == stack_pointer_rtx
)
1312 rtx val
= XEXP (XEXP (src
, 1), 1);
1313 /* We handle only adjustments by constant amount. */
1314 gcc_assert (GET_CODE (XEXP (src
, 1)) == PLUS
1315 && CONST_INT_P (val
));
1316 offset
= -INTVAL (val
);
1323 if (XEXP (src
, 0) == stack_pointer_rtx
)
1325 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1332 if (XEXP (src
, 0) == stack_pointer_rtx
)
1334 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
1349 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1350 indexed by INSN_UID. */
1352 static HOST_WIDE_INT
*barrier_args_size
;
1354 /* Helper function for compute_barrier_args_size. Handle one insn. */
1356 static HOST_WIDE_INT
1357 compute_barrier_args_size_1 (rtx insn
, HOST_WIDE_INT cur_args_size
,
1358 VEC (rtx
, heap
) **next
)
1360 HOST_WIDE_INT offset
= 0;
1363 if (! RTX_FRAME_RELATED_P (insn
))
1365 if (prologue_epilogue_contains (insn
))
1367 else if (GET_CODE (PATTERN (insn
)) == SET
)
1368 offset
= stack_adjust_offset (PATTERN (insn
), cur_args_size
, 0);
1369 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1370 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1372 /* There may be stack adjustments inside compound insns. Search
1374 for (i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1375 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1376 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
),
1377 cur_args_size
, offset
);
1382 rtx expr
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1386 expr
= XEXP (expr
, 0);
1387 if (GET_CODE (expr
) == PARALLEL
1388 || GET_CODE (expr
) == SEQUENCE
)
1389 for (i
= 1; i
< XVECLEN (expr
, 0); i
++)
1391 rtx elem
= XVECEXP (expr
, 0, i
);
1393 if (GET_CODE (elem
) == SET
&& !RTX_FRAME_RELATED_P (elem
))
1394 offset
+= stack_adjust_offset (elem
, cur_args_size
, offset
);
1399 #ifndef STACK_GROWS_DOWNWARD
1403 cur_args_size
+= offset
;
1404 if (cur_args_size
< 0)
1409 rtx dest
= JUMP_LABEL (insn
);
1413 if (barrier_args_size
[INSN_UID (dest
)] < 0)
1415 barrier_args_size
[INSN_UID (dest
)] = cur_args_size
;
1416 VEC_safe_push (rtx
, heap
, *next
, dest
);
1421 return cur_args_size
;
1424 /* Walk the whole function and compute args_size on BARRIERs. */
1427 compute_barrier_args_size (void)
1429 int max_uid
= get_max_uid (), i
;
1431 VEC (rtx
, heap
) *worklist
, *next
, *tmp
;
1433 barrier_args_size
= XNEWVEC (HOST_WIDE_INT
, max_uid
);
1434 for (i
= 0; i
< max_uid
; i
++)
1435 barrier_args_size
[i
] = -1;
1437 worklist
= VEC_alloc (rtx
, heap
, 20);
1438 next
= VEC_alloc (rtx
, heap
, 20);
1439 insn
= get_insns ();
1440 barrier_args_size
[INSN_UID (insn
)] = 0;
1441 VEC_quick_push (rtx
, worklist
, insn
);
1444 while (!VEC_empty (rtx
, worklist
))
1446 rtx prev
, body
, first_insn
;
1447 HOST_WIDE_INT cur_args_size
;
1449 first_insn
= insn
= VEC_pop (rtx
, worklist
);
1450 cur_args_size
= barrier_args_size
[INSN_UID (insn
)];
1451 prev
= prev_nonnote_insn (insn
);
1452 if (prev
&& BARRIER_P (prev
))
1453 barrier_args_size
[INSN_UID (prev
)] = cur_args_size
;
1455 for (; insn
; insn
= NEXT_INSN (insn
))
1457 if (INSN_DELETED_P (insn
) || NOTE_P (insn
))
1459 if (BARRIER_P (insn
))
1464 if (insn
== first_insn
)
1466 else if (barrier_args_size
[INSN_UID (insn
)] < 0)
1468 barrier_args_size
[INSN_UID (insn
)] = cur_args_size
;
1473 /* The insns starting with this label have been
1474 already scanned or are in the worklist. */
1479 body
= PATTERN (insn
);
1480 if (GET_CODE (body
) == SEQUENCE
)
1482 HOST_WIDE_INT dest_args_size
= cur_args_size
;
1483 for (i
= 1; i
< XVECLEN (body
, 0); i
++)
1484 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body
, 0, 0))
1485 && INSN_FROM_TARGET_P (XVECEXP (body
, 0, i
)))
1487 = compute_barrier_args_size_1 (XVECEXP (body
, 0, i
),
1488 dest_args_size
, &next
);
1491 = compute_barrier_args_size_1 (XVECEXP (body
, 0, i
),
1492 cur_args_size
, &next
);
1494 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body
, 0, 0)))
1495 compute_barrier_args_size_1 (XVECEXP (body
, 0, 0),
1496 dest_args_size
, &next
);
1499 = compute_barrier_args_size_1 (XVECEXP (body
, 0, 0),
1500 cur_args_size
, &next
);
1504 = compute_barrier_args_size_1 (insn
, cur_args_size
, &next
);
1508 if (VEC_empty (rtx
, next
))
1511 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1515 VEC_truncate (rtx
, next
, 0);
1518 VEC_free (rtx
, heap
, worklist
);
1519 VEC_free (rtx
, heap
, next
);
1522 /* Add a CFI to update the running total of the size of arguments
1523 pushed onto the stack. */
1526 dwarf2out_args_size (const char *label
, HOST_WIDE_INT size
)
1530 if (size
== old_args_size
)
1533 old_args_size
= size
;
1536 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
1537 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
1538 add_fde_cfi (label
, cfi
);
1541 /* Record a stack adjustment of OFFSET bytes. */
1544 dwarf2out_stack_adjust (HOST_WIDE_INT offset
, const char *label
)
1546 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1547 cfa
.offset
+= offset
;
1549 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1550 cfa_store
.offset
+= offset
;
1552 if (ACCUMULATE_OUTGOING_ARGS
)
1555 #ifndef STACK_GROWS_DOWNWARD
1559 args_size
+= offset
;
1563 def_cfa_1 (label
, &cfa
);
1564 if (flag_asynchronous_unwind_tables
)
1565 dwarf2out_args_size (label
, args_size
);
1568 /* Check INSN to see if it looks like a push or a stack adjustment, and
1569 make a note of it if it does. EH uses this information to find out
1570 how much extra space it needs to pop off the stack. */
1573 dwarf2out_notice_stack_adjust (rtx insn
, bool after_p
)
1575 HOST_WIDE_INT offset
;
1579 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1580 with this function. Proper support would require all frame-related
1581 insns to be marked, and to be able to handle saving state around
1582 epilogues textually in the middle of the function. */
1583 if (prologue_epilogue_contains (insn
))
1586 /* If INSN is an instruction from target of an annulled branch, the
1587 effects are for the target only and so current argument size
1588 shouldn't change at all. */
1590 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence
, 0, 0))
1591 && INSN_FROM_TARGET_P (insn
))
1594 /* If only calls can throw, and we have a frame pointer,
1595 save up adjustments until we see the CALL_INSN. */
1596 if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1598 if (CALL_P (insn
) && !after_p
)
1600 /* Extract the size of the args from the CALL rtx itself. */
1601 insn
= PATTERN (insn
);
1602 if (GET_CODE (insn
) == PARALLEL
)
1603 insn
= XVECEXP (insn
, 0, 0);
1604 if (GET_CODE (insn
) == SET
)
1605 insn
= SET_SRC (insn
);
1606 gcc_assert (GET_CODE (insn
) == CALL
);
1607 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1612 if (CALL_P (insn
) && !after_p
)
1614 if (!flag_asynchronous_unwind_tables
)
1615 dwarf2out_args_size ("", args_size
);
1618 else if (BARRIER_P (insn
))
1620 /* Don't call compute_barrier_args_size () if the only
1621 BARRIER is at the end of function. */
1622 if (barrier_args_size
== NULL
&& next_nonnote_insn (insn
))
1623 compute_barrier_args_size ();
1624 if (barrier_args_size
== NULL
)
1628 offset
= barrier_args_size
[INSN_UID (insn
)];
1633 offset
-= args_size
;
1634 #ifndef STACK_GROWS_DOWNWARD
1638 else if (GET_CODE (PATTERN (insn
)) == SET
)
1639 offset
= stack_adjust_offset (PATTERN (insn
), args_size
, 0);
1640 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1641 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1643 /* There may be stack adjustments inside compound insns. Search
1645 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1646 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1647 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
),
1656 label
= dwarf2out_cfi_label (false);
1657 dwarf2out_stack_adjust (offset
, label
);
1660 /* We delay emitting a register save until either (a) we reach the end
1661 of the prologue or (b) the register is clobbered. This clusters
1662 register saves so that there are fewer pc advances. */
1664 struct GTY(()) queued_reg_save
{
1665 struct queued_reg_save
*next
;
1667 HOST_WIDE_INT cfa_offset
;
1671 static GTY(()) struct queued_reg_save
*queued_reg_saves
;
1673 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1674 struct GTY(()) reg_saved_in_data
{
1679 /* A list of registers saved in other registers.
1680 The list intentionally has a small maximum capacity of 4; if your
1681 port needs more than that, you might consider implementing a
1682 more efficient data structure. */
1683 static GTY(()) struct reg_saved_in_data regs_saved_in_regs
[4];
1684 static GTY(()) size_t num_regs_saved_in_regs
;
1686 static const char *last_reg_save_label
;
1688 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1689 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1692 queue_reg_save (const char *label
, rtx reg
, rtx sreg
, HOST_WIDE_INT offset
)
1694 struct queued_reg_save
*q
;
1696 /* Duplicates waste space, but it's also necessary to remove them
1697 for correctness, since the queue gets output in reverse
1699 for (q
= queued_reg_saves
; q
!= NULL
; q
= q
->next
)
1700 if (REGNO (q
->reg
) == REGNO (reg
))
1705 q
= ggc_alloc_queued_reg_save ();
1706 q
->next
= queued_reg_saves
;
1707 queued_reg_saves
= q
;
1711 q
->cfa_offset
= offset
;
1712 q
->saved_reg
= sreg
;
1714 last_reg_save_label
= label
;
1717 /* Output all the entries in QUEUED_REG_SAVES. */
1720 dwarf2out_flush_queued_reg_saves (void)
1722 struct queued_reg_save
*q
;
1724 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1727 unsigned int reg
, sreg
;
1729 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1730 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (q
->reg
))
1732 if (q
->saved_reg
&& i
== num_regs_saved_in_regs
)
1734 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1735 num_regs_saved_in_regs
++;
1737 if (i
!= num_regs_saved_in_regs
)
1739 regs_saved_in_regs
[i
].orig_reg
= q
->reg
;
1740 regs_saved_in_regs
[i
].saved_in_reg
= q
->saved_reg
;
1743 reg
= DWARF_FRAME_REGNUM (REGNO (q
->reg
));
1745 sreg
= DWARF_FRAME_REGNUM (REGNO (q
->saved_reg
));
1747 sreg
= INVALID_REGNUM
;
1748 reg_save (last_reg_save_label
, reg
, sreg
, q
->cfa_offset
);
1751 queued_reg_saves
= NULL
;
1752 last_reg_save_label
= NULL
;
1755 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1756 location for? Or, does it clobber a register which we've previously
1757 said that some other register is saved in, and for which we now
1758 have a new location for? */
1761 clobbers_queued_reg_save (const_rtx insn
)
1763 struct queued_reg_save
*q
;
1765 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1768 if (modified_in_p (q
->reg
, insn
))
1770 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1771 if (REGNO (q
->reg
) == REGNO (regs_saved_in_regs
[i
].orig_reg
)
1772 && modified_in_p (regs_saved_in_regs
[i
].saved_in_reg
, insn
))
1779 /* Entry point for saving the first register into the second. */
1782 dwarf2out_reg_save_reg (const char *label
, rtx reg
, rtx sreg
)
1785 unsigned int regno
, sregno
;
1787 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1788 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (reg
))
1790 if (i
== num_regs_saved_in_regs
)
1792 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1793 num_regs_saved_in_regs
++;
1795 regs_saved_in_regs
[i
].orig_reg
= reg
;
1796 regs_saved_in_regs
[i
].saved_in_reg
= sreg
;
1798 regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
1799 sregno
= DWARF_FRAME_REGNUM (REGNO (sreg
));
1800 reg_save (label
, regno
, sregno
, 0);
1803 /* What register, if any, is currently saved in REG? */
1806 reg_saved_in (rtx reg
)
1808 unsigned int regn
= REGNO (reg
);
1810 struct queued_reg_save
*q
;
1812 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1813 if (q
->saved_reg
&& regn
== REGNO (q
->saved_reg
))
1816 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1817 if (regs_saved_in_regs
[i
].saved_in_reg
1818 && regn
== REGNO (regs_saved_in_regs
[i
].saved_in_reg
))
1819 return regs_saved_in_regs
[i
].orig_reg
;
1825 /* A temporary register holding an integral value used in adjusting SP
1826 or setting up the store_reg. The "offset" field holds the integer
1827 value, not an offset. */
1828 static dw_cfa_location cfa_temp
;
1830 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1833 dwarf2out_frame_debug_def_cfa (rtx pat
, const char *label
)
1835 memset (&cfa
, 0, sizeof (cfa
));
1837 switch (GET_CODE (pat
))
1840 cfa
.reg
= REGNO (XEXP (pat
, 0));
1841 cfa
.offset
= INTVAL (XEXP (pat
, 1));
1845 cfa
.reg
= REGNO (pat
);
1850 pat
= XEXP (pat
, 0);
1851 if (GET_CODE (pat
) == PLUS
)
1853 cfa
.base_offset
= INTVAL (XEXP (pat
, 1));
1854 pat
= XEXP (pat
, 0);
1856 cfa
.reg
= REGNO (pat
);
1860 /* Recurse and define an expression. */
1864 def_cfa_1 (label
, &cfa
);
1867 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1870 dwarf2out_frame_debug_adjust_cfa (rtx pat
, const char *label
)
1874 gcc_assert (GET_CODE (pat
) == SET
);
1875 dest
= XEXP (pat
, 0);
1876 src
= XEXP (pat
, 1);
1878 switch (GET_CODE (src
))
1881 gcc_assert (REGNO (XEXP (src
, 0)) == cfa
.reg
);
1882 cfa
.offset
-= INTVAL (XEXP (src
, 1));
1892 cfa
.reg
= REGNO (dest
);
1893 gcc_assert (cfa
.indirect
== 0);
1895 def_cfa_1 (label
, &cfa
);
1898 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1901 dwarf2out_frame_debug_cfa_offset (rtx set
, const char *label
)
1903 HOST_WIDE_INT offset
;
1904 rtx src
, addr
, span
;
1906 src
= XEXP (set
, 1);
1907 addr
= XEXP (set
, 0);
1908 gcc_assert (MEM_P (addr
));
1909 addr
= XEXP (addr
, 0);
1911 /* As documented, only consider extremely simple addresses. */
1912 switch (GET_CODE (addr
))
1915 gcc_assert (REGNO (addr
) == cfa
.reg
);
1916 offset
= -cfa
.offset
;
1919 gcc_assert (REGNO (XEXP (addr
, 0)) == cfa
.reg
);
1920 offset
= INTVAL (XEXP (addr
, 1)) - cfa
.offset
;
1926 span
= targetm
.dwarf_register_span (src
);
1928 /* ??? We'd like to use queue_reg_save, but we need to come up with
1929 a different flushing heuristic for epilogues. */
1931 reg_save (label
, DWARF_FRAME_REGNUM (REGNO (src
)), INVALID_REGNUM
, offset
);
1934 /* We have a PARALLEL describing where the contents of SRC live.
1935 Queue register saves for each piece of the PARALLEL. */
1938 HOST_WIDE_INT span_offset
= offset
;
1940 gcc_assert (GET_CODE (span
) == PARALLEL
);
1942 limit
= XVECLEN (span
, 0);
1943 for (par_index
= 0; par_index
< limit
; par_index
++)
1945 rtx elem
= XVECEXP (span
, 0, par_index
);
1947 reg_save (label
, DWARF_FRAME_REGNUM (REGNO (elem
)),
1948 INVALID_REGNUM
, span_offset
);
1949 span_offset
+= GET_MODE_SIZE (GET_MODE (elem
));
1954 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
1957 dwarf2out_frame_debug_cfa_register (rtx set
, const char *label
)
1960 unsigned sregno
, dregno
;
1962 src
= XEXP (set
, 1);
1963 dest
= XEXP (set
, 0);
1966 sregno
= DWARF_FRAME_RETURN_COLUMN
;
1968 sregno
= DWARF_FRAME_REGNUM (REGNO (src
));
1970 dregno
= DWARF_FRAME_REGNUM (REGNO (dest
));
1972 /* ??? We'd like to use queue_reg_save, but we need to come up with
1973 a different flushing heuristic for epilogues. */
1974 reg_save (label
, sregno
, dregno
, 0);
1977 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
1980 dwarf2out_frame_debug_cfa_expression (rtx set
, const char *label
)
1982 rtx src
, dest
, span
;
1983 dw_cfi_ref cfi
= new_cfi ();
1985 dest
= SET_DEST (set
);
1986 src
= SET_SRC (set
);
1988 gcc_assert (REG_P (src
));
1989 gcc_assert (MEM_P (dest
));
1991 span
= targetm
.dwarf_register_span (src
);
1994 cfi
->dw_cfi_opc
= DW_CFA_expression
;
1995 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= DWARF_FRAME_REGNUM (REGNO (src
));
1996 cfi
->dw_cfi_oprnd2
.dw_cfi_loc
1997 = mem_loc_descriptor (XEXP (dest
, 0), GET_MODE (dest
),
1998 VAR_INIT_STATUS_INITIALIZED
);
2000 /* ??? We'd like to use queue_reg_save, were the interface different,
2001 and, as above, we could manage flushing for epilogues. */
2002 add_fde_cfi (label
, cfi
);
2005 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
2008 dwarf2out_frame_debug_cfa_restore (rtx reg
, const char *label
)
2010 dw_cfi_ref cfi
= new_cfi ();
2011 unsigned int regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
2013 cfi
->dw_cfi_opc
= (regno
& ~0x3f ? DW_CFA_restore_extended
: DW_CFA_restore
);
2014 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= regno
;
2016 add_fde_cfi (label
, cfi
);
2019 /* Record call frame debugging information for an expression EXPR,
2020 which either sets SP or FP (adjusting how we calculate the frame
2021 address) or saves a register to the stack or another register.
2022 LABEL indicates the address of EXPR.
2024 This function encodes a state machine mapping rtxes to actions on
2025 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
2026 users need not read the source code.
2028 The High-Level Picture
2030 Changes in the register we use to calculate the CFA: Currently we
2031 assume that if you copy the CFA register into another register, we
2032 should take the other one as the new CFA register; this seems to
2033 work pretty well. If it's wrong for some target, it's simple
2034 enough not to set RTX_FRAME_RELATED_P on the insn in question.
2036 Changes in the register we use for saving registers to the stack:
2037 This is usually SP, but not always. Again, we deduce that if you
2038 copy SP into another register (and SP is not the CFA register),
2039 then the new register is the one we will be using for register
2040 saves. This also seems to work.
2042 Register saves: There's not much guesswork about this one; if
2043 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
2044 register save, and the register used to calculate the destination
2045 had better be the one we think we're using for this purpose.
2046 It's also assumed that a copy from a call-saved register to another
2047 register is saving that register if RTX_FRAME_RELATED_P is set on
2048 that instruction. If the copy is from a call-saved register to
2049 the *same* register, that means that the register is now the same
2050 value as in the caller.
2052 Except: If the register being saved is the CFA register, and the
2053 offset is nonzero, we are saving the CFA, so we assume we have to
2054 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
2055 the intent is to save the value of SP from the previous frame.
2057 In addition, if a register has previously been saved to a different
2060 Invariants / Summaries of Rules
2062 cfa current rule for calculating the CFA. It usually
2063 consists of a register and an offset.
2064 cfa_store register used by prologue code to save things to the stack
2065 cfa_store.offset is the offset from the value of
2066 cfa_store.reg to the actual CFA
2067 cfa_temp register holding an integral value. cfa_temp.offset
2068 stores the value, which will be used to adjust the
2069 stack pointer. cfa_temp is also used like cfa_store,
2070 to track stores to the stack via fp or a temp reg.
2072 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2073 with cfa.reg as the first operand changes the cfa.reg and its
2074 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2077 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2078 expression yielding a constant. This sets cfa_temp.reg
2079 and cfa_temp.offset.
2081 Rule 5: Create a new register cfa_store used to save items to the
2084 Rules 10-14: Save a register to the stack. Define offset as the
2085 difference of the original location and cfa_store's
2086 location (or cfa_temp's location if cfa_temp is used).
2088 Rules 16-20: If AND operation happens on sp in prologue, we assume
2089 stack is realigned. We will use a group of DW_OP_XXX
2090 expressions to represent the location of the stored
2091 register instead of CFA+offset.
2095 "{a,b}" indicates a choice of a xor b.
2096 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2099 (set <reg1> <reg2>:cfa.reg)
2100 effects: cfa.reg = <reg1>
2101 cfa.offset unchanged
2102 cfa_temp.reg = <reg1>
2103 cfa_temp.offset = cfa.offset
2106 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2107 {<const_int>,<reg>:cfa_temp.reg}))
2108 effects: cfa.reg = sp if fp used
2109 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2110 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2111 if cfa_store.reg==sp
2114 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2115 effects: cfa.reg = fp
2116 cfa_offset += +/- <const_int>
2119 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2120 constraints: <reg1> != fp
2122 effects: cfa.reg = <reg1>
2123 cfa_temp.reg = <reg1>
2124 cfa_temp.offset = cfa.offset
2127 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2128 constraints: <reg1> != fp
2130 effects: cfa_store.reg = <reg1>
2131 cfa_store.offset = cfa.offset - cfa_temp.offset
2134 (set <reg> <const_int>)
2135 effects: cfa_temp.reg = <reg>
2136 cfa_temp.offset = <const_int>
2139 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2140 effects: cfa_temp.reg = <reg1>
2141 cfa_temp.offset |= <const_int>
2144 (set <reg> (high <exp>))
2148 (set <reg> (lo_sum <exp> <const_int>))
2149 effects: cfa_temp.reg = <reg>
2150 cfa_temp.offset = <const_int>
2153 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2154 effects: cfa_store.offset -= <const_int>
2155 cfa.offset = cfa_store.offset if cfa.reg == sp
2157 cfa.base_offset = -cfa_store.offset
2160 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
2161 effects: cfa_store.offset += -/+ mode_size(mem)
2162 cfa.offset = cfa_store.offset if cfa.reg == sp
2164 cfa.base_offset = -cfa_store.offset
2167 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2170 effects: cfa.reg = <reg1>
2171 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2174 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2175 effects: cfa.reg = <reg1>
2176 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2179 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
2180 effects: cfa.reg = <reg1>
2181 cfa.base_offset = -cfa_temp.offset
2182 cfa_temp.offset -= mode_size(mem)
2185 (set <reg> {unspec, unspec_volatile})
2186 effects: target-dependent
2189 (set sp (and: sp <const_int>))
2190 constraints: cfa_store.reg == sp
2191 effects: current_fde.stack_realign = 1
2192 cfa_store.offset = 0
2193 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2196 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2197 effects: cfa_store.offset += -/+ mode_size(mem)
2200 (set (mem ({pre_inc, pre_dec} sp)) fp)
2201 constraints: fde->stack_realign == 1
2202 effects: cfa_store.offset = 0
2203 cfa.reg != HARD_FRAME_POINTER_REGNUM
2206 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2207 constraints: fde->stack_realign == 1
2209 && cfa.indirect == 0
2210 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2211 effects: Use DW_CFA_def_cfa_expression to define cfa
2212 cfa.reg == fde->drap_reg */
2215 dwarf2out_frame_debug_expr (rtx expr
, const char *label
)
2217 rtx src
, dest
, span
;
2218 HOST_WIDE_INT offset
;
2221 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2222 the PARALLEL independently. The first element is always processed if
2223 it is a SET. This is for backward compatibility. Other elements
2224 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2225 flag is set in them. */
2226 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
2229 int limit
= XVECLEN (expr
, 0);
2232 /* PARALLELs have strict read-modify-write semantics, so we
2233 ought to evaluate every rvalue before changing any lvalue.
2234 It's cumbersome to do that in general, but there's an
2235 easy approximation that is enough for all current users:
2236 handle register saves before register assignments. */
2237 if (GET_CODE (expr
) == PARALLEL
)
2238 for (par_index
= 0; par_index
< limit
; par_index
++)
2240 elem
= XVECEXP (expr
, 0, par_index
);
2241 if (GET_CODE (elem
) == SET
2242 && MEM_P (SET_DEST (elem
))
2243 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
2244 dwarf2out_frame_debug_expr (elem
, label
);
2247 for (par_index
= 0; par_index
< limit
; par_index
++)
2249 elem
= XVECEXP (expr
, 0, par_index
);
2250 if (GET_CODE (elem
) == SET
2251 && (!MEM_P (SET_DEST (elem
)) || GET_CODE (expr
) == SEQUENCE
)
2252 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
2253 dwarf2out_frame_debug_expr (elem
, label
);
2254 else if (GET_CODE (elem
) == SET
2256 && !RTX_FRAME_RELATED_P (elem
))
2258 /* Stack adjustment combining might combine some post-prologue
2259 stack adjustment into a prologue stack adjustment. */
2260 HOST_WIDE_INT offset
= stack_adjust_offset (elem
, args_size
, 0);
2263 dwarf2out_stack_adjust (offset
, label
);
2269 gcc_assert (GET_CODE (expr
) == SET
);
2271 src
= SET_SRC (expr
);
2272 dest
= SET_DEST (expr
);
2276 rtx rsi
= reg_saved_in (src
);
2281 fde
= current_fde ();
2283 switch (GET_CODE (dest
))
2286 switch (GET_CODE (src
))
2288 /* Setting FP from SP. */
2290 if (cfa
.reg
== (unsigned) REGNO (src
))
2293 /* Update the CFA rule wrt SP or FP. Make sure src is
2294 relative to the current CFA register.
2296 We used to require that dest be either SP or FP, but the
2297 ARM copies SP to a temporary register, and from there to
2298 FP. So we just rely on the backends to only set
2299 RTX_FRAME_RELATED_P on appropriate insns. */
2300 cfa
.reg
= REGNO (dest
);
2301 cfa_temp
.reg
= cfa
.reg
;
2302 cfa_temp
.offset
= cfa
.offset
;
2306 /* Saving a register in a register. */
2307 gcc_assert (!fixed_regs
[REGNO (dest
)]
2308 /* For the SPARC and its register window. */
2309 || (DWARF_FRAME_REGNUM (REGNO (src
))
2310 == DWARF_FRAME_RETURN_COLUMN
));
2312 /* After stack is aligned, we can only save SP in FP
2313 if drap register is used. In this case, we have
2314 to restore stack pointer with the CFA value and we
2315 don't generate this DWARF information. */
2317 && fde
->stack_realign
2318 && REGNO (src
) == STACK_POINTER_REGNUM
)
2319 gcc_assert (REGNO (dest
) == HARD_FRAME_POINTER_REGNUM
2320 && fde
->drap_reg
!= INVALID_REGNUM
2321 && cfa
.reg
!= REGNO (src
));
2323 queue_reg_save (label
, src
, dest
, 0);
2330 if (dest
== stack_pointer_rtx
)
2334 switch (GET_CODE (XEXP (src
, 1)))
2337 offset
= INTVAL (XEXP (src
, 1));
2340 gcc_assert ((unsigned) REGNO (XEXP (src
, 1))
2342 offset
= cfa_temp
.offset
;
2348 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
2350 /* Restoring SP from FP in the epilogue. */
2351 gcc_assert (cfa
.reg
== (unsigned) HARD_FRAME_POINTER_REGNUM
);
2352 cfa
.reg
= STACK_POINTER_REGNUM
;
2354 else if (GET_CODE (src
) == LO_SUM
)
2355 /* Assume we've set the source reg of the LO_SUM from sp. */
2358 gcc_assert (XEXP (src
, 0) == stack_pointer_rtx
);
2360 if (GET_CODE (src
) != MINUS
)
2362 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2363 cfa
.offset
+= offset
;
2364 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
2365 cfa_store
.offset
+= offset
;
2367 else if (dest
== hard_frame_pointer_rtx
)
2370 /* Either setting the FP from an offset of the SP,
2371 or adjusting the FP */
2372 gcc_assert (frame_pointer_needed
);
2374 gcc_assert (REG_P (XEXP (src
, 0))
2375 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
2376 && CONST_INT_P (XEXP (src
, 1)));
2377 offset
= INTVAL (XEXP (src
, 1));
2378 if (GET_CODE (src
) != MINUS
)
2380 cfa
.offset
+= offset
;
2381 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
2385 gcc_assert (GET_CODE (src
) != MINUS
);
2388 if (REG_P (XEXP (src
, 0))
2389 && REGNO (XEXP (src
, 0)) == cfa
.reg
2390 && CONST_INT_P (XEXP (src
, 1)))
2392 /* Setting a temporary CFA register that will be copied
2393 into the FP later on. */
2394 offset
= - INTVAL (XEXP (src
, 1));
2395 cfa
.offset
+= offset
;
2396 cfa
.reg
= REGNO (dest
);
2397 /* Or used to save regs to the stack. */
2398 cfa_temp
.reg
= cfa
.reg
;
2399 cfa_temp
.offset
= cfa
.offset
;
2403 else if (REG_P (XEXP (src
, 0))
2404 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
2405 && XEXP (src
, 1) == stack_pointer_rtx
)
2407 /* Setting a scratch register that we will use instead
2408 of SP for saving registers to the stack. */
2409 gcc_assert (cfa
.reg
== STACK_POINTER_REGNUM
);
2410 cfa_store
.reg
= REGNO (dest
);
2411 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
2415 else if (GET_CODE (src
) == LO_SUM
2416 && CONST_INT_P (XEXP (src
, 1)))
2418 cfa_temp
.reg
= REGNO (dest
);
2419 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
2428 cfa_temp
.reg
= REGNO (dest
);
2429 cfa_temp
.offset
= INTVAL (src
);
2434 gcc_assert (REG_P (XEXP (src
, 0))
2435 && (unsigned) REGNO (XEXP (src
, 0)) == cfa_temp
.reg
2436 && CONST_INT_P (XEXP (src
, 1)));
2438 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
2439 cfa_temp
.reg
= REGNO (dest
);
2440 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
2443 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2444 which will fill in all of the bits. */
2451 case UNSPEC_VOLATILE
:
2452 gcc_assert (targetm
.dwarf_handle_frame_unspec
);
2453 targetm
.dwarf_handle_frame_unspec (label
, expr
, XINT (src
, 1));
2458 /* If this AND operation happens on stack pointer in prologue,
2459 we assume the stack is realigned and we extract the
2461 if (fde
&& XEXP (src
, 0) == stack_pointer_rtx
)
2463 /* We interpret reg_save differently with stack_realign set.
2464 Thus we must flush whatever we have queued first. */
2465 dwarf2out_flush_queued_reg_saves ();
2467 gcc_assert (cfa_store
.reg
== REGNO (XEXP (src
, 0)));
2468 fde
->stack_realign
= 1;
2469 fde
->stack_realignment
= INTVAL (XEXP (src
, 1));
2470 cfa_store
.offset
= 0;
2472 if (cfa
.reg
!= STACK_POINTER_REGNUM
2473 && cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
)
2474 fde
->drap_reg
= cfa
.reg
;
2482 def_cfa_1 (label
, &cfa
);
2487 /* Saving a register to the stack. Make sure dest is relative to the
2489 switch (GET_CODE (XEXP (dest
, 0)))
2494 /* We can't handle variable size modifications. */
2495 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1))
2497 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
2499 gcc_assert (REGNO (XEXP (XEXP (dest
, 0), 0)) == STACK_POINTER_REGNUM
2500 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
2502 cfa_store
.offset
+= offset
;
2503 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2504 cfa
.offset
= cfa_store
.offset
;
2506 offset
= -cfa_store
.offset
;
2512 offset
= GET_MODE_SIZE (GET_MODE (dest
));
2513 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
2516 gcc_assert ((REGNO (XEXP (XEXP (dest
, 0), 0))
2517 == STACK_POINTER_REGNUM
)
2518 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
2520 cfa_store
.offset
+= offset
;
2522 /* Rule 18: If stack is aligned, we will use FP as a
2523 reference to represent the address of the stored
2526 && fde
->stack_realign
2527 && src
== hard_frame_pointer_rtx
)
2529 gcc_assert (cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
);
2530 cfa_store
.offset
= 0;
2533 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2534 cfa
.offset
= cfa_store
.offset
;
2536 offset
= -cfa_store
.offset
;
2540 /* With an offset. */
2547 gcc_assert (CONST_INT_P (XEXP (XEXP (dest
, 0), 1))
2548 && REG_P (XEXP (XEXP (dest
, 0), 0)));
2549 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
2550 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
2553 regno
= REGNO (XEXP (XEXP (dest
, 0), 0));
2555 if (cfa
.reg
== (unsigned) regno
)
2556 offset
-= cfa
.offset
;
2557 else if (cfa_store
.reg
== (unsigned) regno
)
2558 offset
-= cfa_store
.offset
;
2561 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
2562 offset
-= cfa_temp
.offset
;
2568 /* Without an offset. */
2571 int regno
= REGNO (XEXP (dest
, 0));
2573 if (cfa
.reg
== (unsigned) regno
)
2574 offset
= -cfa
.offset
;
2575 else if (cfa_store
.reg
== (unsigned) regno
)
2576 offset
= -cfa_store
.offset
;
2579 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
2580 offset
= -cfa_temp
.offset
;
2587 gcc_assert (cfa_temp
.reg
2588 == (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)));
2589 offset
= -cfa_temp
.offset
;
2590 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
2598 /* If the source operand of this MEM operation is not a
2599 register, basically the source is return address. Here
2600 we only care how much stack grew and we don't save it. */
2604 if (REGNO (src
) != STACK_POINTER_REGNUM
2605 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
2606 && (unsigned) REGNO (src
) == cfa
.reg
)
2608 /* We're storing the current CFA reg into the stack. */
2610 if (cfa
.offset
== 0)
2613 /* If stack is aligned, putting CFA reg into stack means
2614 we can no longer use reg + offset to represent CFA.
2615 Here we use DW_CFA_def_cfa_expression instead. The
2616 result of this expression equals to the original CFA
2619 && fde
->stack_realign
2620 && cfa
.indirect
== 0
2621 && cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
)
2623 dw_cfa_location cfa_exp
;
2625 gcc_assert (fde
->drap_reg
== cfa
.reg
);
2627 cfa_exp
.indirect
= 1;
2628 cfa_exp
.reg
= HARD_FRAME_POINTER_REGNUM
;
2629 cfa_exp
.base_offset
= offset
;
2632 fde
->drap_reg_saved
= 1;
2634 def_cfa_1 (label
, &cfa_exp
);
2638 /* If the source register is exactly the CFA, assume
2639 we're saving SP like any other register; this happens
2641 def_cfa_1 (label
, &cfa
);
2642 queue_reg_save (label
, stack_pointer_rtx
, NULL_RTX
, offset
);
2647 /* Otherwise, we'll need to look in the stack to
2648 calculate the CFA. */
2649 rtx x
= XEXP (dest
, 0);
2653 gcc_assert (REG_P (x
));
2655 cfa
.reg
= REGNO (x
);
2656 cfa
.base_offset
= offset
;
2658 def_cfa_1 (label
, &cfa
);
2663 def_cfa_1 (label
, &cfa
);
2665 span
= targetm
.dwarf_register_span (src
);
2668 queue_reg_save (label
, src
, NULL_RTX
, offset
);
2671 /* We have a PARALLEL describing where the contents of SRC
2672 live. Queue register saves for each piece of the
2676 HOST_WIDE_INT span_offset
= offset
;
2678 gcc_assert (GET_CODE (span
) == PARALLEL
);
2680 limit
= XVECLEN (span
, 0);
2681 for (par_index
= 0; par_index
< limit
; par_index
++)
2683 rtx elem
= XVECEXP (span
, 0, par_index
);
2685 queue_reg_save (label
, elem
, NULL_RTX
, span_offset
);
2686 span_offset
+= GET_MODE_SIZE (GET_MODE (elem
));
2697 /* Record call frame debugging information for INSN, which either
2698 sets SP or FP (adjusting how we calculate the frame address) or saves a
2699 register to the stack. If INSN is NULL_RTX, initialize our state.
2701 If AFTER_P is false, we're being called before the insn is emitted,
2702 otherwise after. Call instructions get invoked twice. */
2705 dwarf2out_frame_debug (rtx insn
, bool after_p
)
2709 bool handled_one
= false;
2711 if (insn
== NULL_RTX
)
2715 /* Flush any queued register saves. */
2716 dwarf2out_flush_queued_reg_saves ();
2718 /* Set up state for generating call frame debug info. */
2721 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
));
2723 cfa
.reg
= STACK_POINTER_REGNUM
;
2726 cfa_temp
.offset
= 0;
2728 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
2730 regs_saved_in_regs
[i
].orig_reg
= NULL_RTX
;
2731 regs_saved_in_regs
[i
].saved_in_reg
= NULL_RTX
;
2733 num_regs_saved_in_regs
= 0;
2735 if (barrier_args_size
)
2737 XDELETEVEC (barrier_args_size
);
2738 barrier_args_size
= NULL
;
2743 if (!NONJUMP_INSN_P (insn
) || clobbers_queued_reg_save (insn
))
2744 dwarf2out_flush_queued_reg_saves ();
2746 if (!RTX_FRAME_RELATED_P (insn
))
2748 /* ??? This should be done unconditionally since stack adjustments
2749 matter if the stack pointer is not the CFA register anymore but
2750 is still used to save registers. */
2751 if (!ACCUMULATE_OUTGOING_ARGS
)
2752 dwarf2out_notice_stack_adjust (insn
, after_p
);
2756 label
= dwarf2out_cfi_label (false);
2757 any_cfis_emitted
= false;
2759 for (note
= REG_NOTES (insn
); note
; note
= XEXP (note
, 1))
2760 switch (REG_NOTE_KIND (note
))
2762 case REG_FRAME_RELATED_EXPR
:
2763 insn
= XEXP (note
, 0);
2766 case REG_CFA_DEF_CFA
:
2767 dwarf2out_frame_debug_def_cfa (XEXP (note
, 0), label
);
2771 case REG_CFA_ADJUST_CFA
:
2776 if (GET_CODE (n
) == PARALLEL
)
2777 n
= XVECEXP (n
, 0, 0);
2779 dwarf2out_frame_debug_adjust_cfa (n
, label
);
2783 case REG_CFA_OFFSET
:
2786 n
= single_set (insn
);
2787 dwarf2out_frame_debug_cfa_offset (n
, label
);
2791 case REG_CFA_REGISTER
:
2796 if (GET_CODE (n
) == PARALLEL
)
2797 n
= XVECEXP (n
, 0, 0);
2799 dwarf2out_frame_debug_cfa_register (n
, label
);
2803 case REG_CFA_EXPRESSION
:
2806 n
= single_set (insn
);
2807 dwarf2out_frame_debug_cfa_expression (n
, label
);
2811 case REG_CFA_RESTORE
:
2816 if (GET_CODE (n
) == PARALLEL
)
2817 n
= XVECEXP (n
, 0, 0);
2820 dwarf2out_frame_debug_cfa_restore (n
, label
);
2824 case REG_CFA_SET_VDRAP
:
2828 dw_fde_ref fde
= current_fde ();
2831 gcc_assert (fde
->vdrap_reg
== INVALID_REGNUM
);
2833 fde
->vdrap_reg
= REGNO (n
);
2844 if (any_cfis_emitted
)
2845 dwarf2out_flush_queued_reg_saves ();
2849 insn
= PATTERN (insn
);
2851 dwarf2out_frame_debug_expr (insn
, label
);
2853 /* Check again. A parallel can save and update the same register.
2854 We could probably check just once, here, but this is safer than
2855 removing the check above. */
2856 if (any_cfis_emitted
|| clobbers_queued_reg_save (insn
))
2857 dwarf2out_flush_queued_reg_saves ();
2860 /* Determine if we need to save and restore CFI information around this
2861 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2862 we do need to save/restore, then emit the save now, and insert a
2863 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2866 dwarf2out_cfi_begin_epilogue (rtx insn
)
2868 bool saw_frp
= false;
2871 /* Scan forward to the return insn, noticing if there are possible
2872 frame related insns. */
2873 for (i
= NEXT_INSN (insn
); i
; i
= NEXT_INSN (i
))
2878 /* Look for both regular and sibcalls to end the block. */
2879 if (returnjump_p (i
))
2881 if (CALL_P (i
) && SIBLING_CALL_P (i
))
2884 if (GET_CODE (PATTERN (i
)) == SEQUENCE
)
2887 rtx seq
= PATTERN (i
);
2889 if (returnjump_p (XVECEXP (seq
, 0, 0)))
2891 if (CALL_P (XVECEXP (seq
, 0, 0))
2892 && SIBLING_CALL_P (XVECEXP (seq
, 0, 0)))
2895 for (idx
= 0; idx
< XVECLEN (seq
, 0); idx
++)
2896 if (RTX_FRAME_RELATED_P (XVECEXP (seq
, 0, idx
)))
2900 if (RTX_FRAME_RELATED_P (i
))
2904 /* If the port doesn't emit epilogue unwind info, we don't need a
2905 save/restore pair. */
2909 /* Otherwise, search forward to see if the return insn was the last
2910 basic block of the function. If so, we don't need save/restore. */
2911 gcc_assert (i
!= NULL
);
2912 i
= next_real_insn (i
);
2916 /* Insert the restore before that next real insn in the stream, and before
2917 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
2918 properly nested. This should be after any label or alignment. This
2919 will be pushed into the CFI stream by the function below. */
2922 rtx p
= PREV_INSN (i
);
2925 if (NOTE_KIND (p
) == NOTE_INSN_BASIC_BLOCK
)
2929 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE
, i
);
2931 emit_cfa_remember
= true;
2933 /* And emulate the state save. */
2934 gcc_assert (!cfa_remember
.in_use
);
2936 cfa_remember
.in_use
= 1;
2939 /* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
2943 dwarf2out_frame_debug_restore_state (void)
2945 dw_cfi_ref cfi
= new_cfi ();
2946 const char *label
= dwarf2out_cfi_label (false);
2948 cfi
->dw_cfi_opc
= DW_CFA_restore_state
;
2949 add_fde_cfi (label
, cfi
);
2951 gcc_assert (cfa_remember
.in_use
);
2953 cfa_remember
.in_use
= 0;
2956 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2957 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2958 (enum dwarf_call_frame_info cfi
);
2960 static enum dw_cfi_oprnd_type
2961 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
2966 case DW_CFA_GNU_window_save
:
2967 case DW_CFA_remember_state
:
2968 case DW_CFA_restore_state
:
2969 return dw_cfi_oprnd_unused
;
2971 case DW_CFA_set_loc
:
2972 case DW_CFA_advance_loc1
:
2973 case DW_CFA_advance_loc2
:
2974 case DW_CFA_advance_loc4
:
2975 case DW_CFA_MIPS_advance_loc8
:
2976 return dw_cfi_oprnd_addr
;
2979 case DW_CFA_offset_extended
:
2980 case DW_CFA_def_cfa
:
2981 case DW_CFA_offset_extended_sf
:
2982 case DW_CFA_def_cfa_sf
:
2983 case DW_CFA_restore
:
2984 case DW_CFA_restore_extended
:
2985 case DW_CFA_undefined
:
2986 case DW_CFA_same_value
:
2987 case DW_CFA_def_cfa_register
:
2988 case DW_CFA_register
:
2989 case DW_CFA_expression
:
2990 return dw_cfi_oprnd_reg_num
;
2992 case DW_CFA_def_cfa_offset
:
2993 case DW_CFA_GNU_args_size
:
2994 case DW_CFA_def_cfa_offset_sf
:
2995 return dw_cfi_oprnd_offset
;
2997 case DW_CFA_def_cfa_expression
:
2998 return dw_cfi_oprnd_loc
;
3005 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
3006 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
3007 (enum dwarf_call_frame_info cfi
);
3009 static enum dw_cfi_oprnd_type
3010 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
3014 case DW_CFA_def_cfa
:
3015 case DW_CFA_def_cfa_sf
:
3017 case DW_CFA_offset_extended_sf
:
3018 case DW_CFA_offset_extended
:
3019 return dw_cfi_oprnd_offset
;
3021 case DW_CFA_register
:
3022 return dw_cfi_oprnd_reg_num
;
3024 case DW_CFA_expression
:
3025 return dw_cfi_oprnd_loc
;
3028 return dw_cfi_oprnd_unused
;
3032 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
3033 switch to the data section instead, and write out a synthetic start label
3034 for collect2 the first time around. */
3037 switch_to_eh_frame_section (bool back
)
3041 #ifdef EH_FRAME_SECTION_NAME
3042 if (eh_frame_section
== 0)
3046 if (EH_TABLES_CAN_BE_READ_ONLY
)
3052 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
3054 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
3056 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
3058 flags
= ((! flag_pic
3059 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
3060 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
3061 && (per_encoding
& 0x70) != DW_EH_PE_absptr
3062 && (per_encoding
& 0x70) != DW_EH_PE_aligned
3063 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
3064 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
3065 ? 0 : SECTION_WRITE
);
3068 flags
= SECTION_WRITE
;
3069 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
3071 #endif /* EH_FRAME_SECTION_NAME */
3073 if (eh_frame_section
)
3074 switch_to_section (eh_frame_section
);
3077 /* We have no special eh_frame section. Put the information in
3078 the data section and emit special labels to guide collect2. */
3079 switch_to_section (data_section
);
3083 label
= get_file_function_name ("F");
3084 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
3085 targetm
.asm_out
.globalize_label (asm_out_file
,
3086 IDENTIFIER_POINTER (label
));
3087 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
3092 /* Switch [BACK] to the eh or debug frame table section, depending on
3096 switch_to_frame_table_section (int for_eh
, bool back
)
3099 switch_to_eh_frame_section (back
);
3102 if (!debug_frame_section
)
3103 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
3104 SECTION_DEBUG
, NULL
);
3105 switch_to_section (debug_frame_section
);
3109 /* Output a Call Frame Information opcode and its operand(s). */
3112 output_cfi (dw_cfi_ref cfi
, dw_fde_ref fde
, int for_eh
)
3117 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
3118 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
3119 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
3120 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX
,
3121 ((unsigned HOST_WIDE_INT
)
3122 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
));
3123 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
3125 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3126 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
3127 "DW_CFA_offset, column %#lx", r
);
3128 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3129 dw2_asm_output_data_uleb128 (off
, NULL
);
3131 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
3133 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3134 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
3135 "DW_CFA_restore, column %#lx", r
);
3139 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
3140 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
3142 switch (cfi
->dw_cfi_opc
)
3144 case DW_CFA_set_loc
:
3146 dw2_asm_output_encoded_addr_rtx (
3147 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3148 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
3151 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
3152 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
3153 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3156 case DW_CFA_advance_loc1
:
3157 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3158 fde
->dw_fde_current_label
, NULL
);
3159 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3162 case DW_CFA_advance_loc2
:
3163 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3164 fde
->dw_fde_current_label
, NULL
);
3165 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3168 case DW_CFA_advance_loc4
:
3169 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3170 fde
->dw_fde_current_label
, NULL
);
3171 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3174 case DW_CFA_MIPS_advance_loc8
:
3175 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3176 fde
->dw_fde_current_label
, NULL
);
3177 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3180 case DW_CFA_offset_extended
:
3181 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3182 dw2_asm_output_data_uleb128 (r
, NULL
);
3183 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3184 dw2_asm_output_data_uleb128 (off
, NULL
);
3187 case DW_CFA_def_cfa
:
3188 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3189 dw2_asm_output_data_uleb128 (r
, NULL
);
3190 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
3193 case DW_CFA_offset_extended_sf
:
3194 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3195 dw2_asm_output_data_uleb128 (r
, NULL
);
3196 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3197 dw2_asm_output_data_sleb128 (off
, NULL
);
3200 case DW_CFA_def_cfa_sf
:
3201 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3202 dw2_asm_output_data_uleb128 (r
, NULL
);
3203 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3204 dw2_asm_output_data_sleb128 (off
, NULL
);
3207 case DW_CFA_restore_extended
:
3208 case DW_CFA_undefined
:
3209 case DW_CFA_same_value
:
3210 case DW_CFA_def_cfa_register
:
3211 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3212 dw2_asm_output_data_uleb128 (r
, NULL
);
3215 case DW_CFA_register
:
3216 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3217 dw2_asm_output_data_uleb128 (r
, NULL
);
3218 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, for_eh
);
3219 dw2_asm_output_data_uleb128 (r
, NULL
);
3222 case DW_CFA_def_cfa_offset
:
3223 case DW_CFA_GNU_args_size
:
3224 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
3227 case DW_CFA_def_cfa_offset_sf
:
3228 off
= div_data_align (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3229 dw2_asm_output_data_sleb128 (off
, NULL
);
3232 case DW_CFA_GNU_window_save
:
3235 case DW_CFA_def_cfa_expression
:
3236 case DW_CFA_expression
:
3237 output_cfa_loc (cfi
);
3240 case DW_CFA_GNU_negative_offset_extended
:
3241 /* Obsoleted by DW_CFA_offset_extended_sf. */
3250 /* Similar, but do it via assembler directives instead. */
3253 output_cfi_directive (dw_cfi_ref cfi
)
3255 unsigned long r
, r2
;
3257 switch (cfi
->dw_cfi_opc
)
3259 case DW_CFA_advance_loc
:
3260 case DW_CFA_advance_loc1
:
3261 case DW_CFA_advance_loc2
:
3262 case DW_CFA_advance_loc4
:
3263 case DW_CFA_MIPS_advance_loc8
:
3264 case DW_CFA_set_loc
:
3265 /* Should only be created by add_fde_cfi in a code path not
3266 followed when emitting via directives. The assembler is
3267 going to take care of this for us. */
3271 case DW_CFA_offset_extended
:
3272 case DW_CFA_offset_extended_sf
:
3273 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3274 fprintf (asm_out_file
, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC
"\n",
3275 r
, cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3278 case DW_CFA_restore
:
3279 case DW_CFA_restore_extended
:
3280 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3281 fprintf (asm_out_file
, "\t.cfi_restore %lu\n", r
);
3284 case DW_CFA_undefined
:
3285 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3286 fprintf (asm_out_file
, "\t.cfi_undefined %lu\n", r
);
3289 case DW_CFA_same_value
:
3290 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3291 fprintf (asm_out_file
, "\t.cfi_same_value %lu\n", r
);
3294 case DW_CFA_def_cfa
:
3295 case DW_CFA_def_cfa_sf
:
3296 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3297 fprintf (asm_out_file
, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC
"\n",
3298 r
, cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3301 case DW_CFA_def_cfa_register
:
3302 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3303 fprintf (asm_out_file
, "\t.cfi_def_cfa_register %lu\n", r
);
3306 case DW_CFA_register
:
3307 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3308 r2
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, 1);
3309 fprintf (asm_out_file
, "\t.cfi_register %lu, %lu\n", r
, r2
);
3312 case DW_CFA_def_cfa_offset
:
3313 case DW_CFA_def_cfa_offset_sf
:
3314 fprintf (asm_out_file
, "\t.cfi_def_cfa_offset "
3315 HOST_WIDE_INT_PRINT_DEC
"\n",
3316 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3319 case DW_CFA_remember_state
:
3320 fprintf (asm_out_file
, "\t.cfi_remember_state\n");
3322 case DW_CFA_restore_state
:
3323 fprintf (asm_out_file
, "\t.cfi_restore_state\n");
3326 case DW_CFA_GNU_args_size
:
3327 fprintf (asm_out_file
, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size
);
3328 dw2_asm_output_data_uleb128_raw (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3330 fprintf (asm_out_file
, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC
,
3331 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3332 fputc ('\n', asm_out_file
);
3335 case DW_CFA_GNU_window_save
:
3336 fprintf (asm_out_file
, "\t.cfi_window_save\n");
3339 case DW_CFA_def_cfa_expression
:
3340 case DW_CFA_expression
:
3341 fprintf (asm_out_file
, "\t.cfi_escape %#x,", cfi
->dw_cfi_opc
);
3342 output_cfa_loc_raw (cfi
);
3343 fputc ('\n', asm_out_file
);
3351 DEF_VEC_P (dw_cfi_ref
);
3352 DEF_VEC_ALLOC_P (dw_cfi_ref
, heap
);
3354 /* Output CFIs to bring current FDE to the same state as after executing
3355 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3356 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3357 other arguments to pass to output_cfi. */
3360 output_cfis (dw_cfi_ref cfi
, bool do_cfi_asm
, dw_fde_ref fde
, bool for_eh
)
3362 struct dw_cfi_struct cfi_buf
;
3364 dw_cfi_ref cfi_args_size
= NULL
, cfi_cfa
= NULL
, cfi_cfa_offset
= NULL
;
3365 VEC (dw_cfi_ref
, heap
) *regs
= VEC_alloc (dw_cfi_ref
, heap
, 32);
3366 unsigned int len
, idx
;
3368 for (;; cfi
= cfi
->dw_cfi_next
)
3369 switch (cfi
? cfi
->dw_cfi_opc
: DW_CFA_nop
)
3371 case DW_CFA_advance_loc
:
3372 case DW_CFA_advance_loc1
:
3373 case DW_CFA_advance_loc2
:
3374 case DW_CFA_advance_loc4
:
3375 case DW_CFA_MIPS_advance_loc8
:
3376 case DW_CFA_set_loc
:
3377 /* All advances should be ignored. */
3379 case DW_CFA_remember_state
:
3381 dw_cfi_ref args_size
= cfi_args_size
;
3383 /* Skip everything between .cfi_remember_state and
3384 .cfi_restore_state. */
3385 for (cfi2
= cfi
->dw_cfi_next
; cfi2
; cfi2
= cfi2
->dw_cfi_next
)
3386 if (cfi2
->dw_cfi_opc
== DW_CFA_restore_state
)
3388 else if (cfi2
->dw_cfi_opc
== DW_CFA_GNU_args_size
)
3391 gcc_assert (cfi2
->dw_cfi_opc
!= DW_CFA_remember_state
);
3398 cfi_args_size
= args_size
;
3402 case DW_CFA_GNU_args_size
:
3403 cfi_args_size
= cfi
;
3405 case DW_CFA_GNU_window_save
:
3408 case DW_CFA_offset_extended
:
3409 case DW_CFA_offset_extended_sf
:
3410 case DW_CFA_restore
:
3411 case DW_CFA_restore_extended
:
3412 case DW_CFA_undefined
:
3413 case DW_CFA_same_value
:
3414 case DW_CFA_register
:
3415 case DW_CFA_val_offset
:
3416 case DW_CFA_val_offset_sf
:
3417 case DW_CFA_expression
:
3418 case DW_CFA_val_expression
:
3419 case DW_CFA_GNU_negative_offset_extended
:
3420 if (VEC_length (dw_cfi_ref
, regs
) <= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
)
3421 VEC_safe_grow_cleared (dw_cfi_ref
, heap
, regs
,
3422 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
+ 1);
3423 VEC_replace (dw_cfi_ref
, regs
, cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, cfi
);
3425 case DW_CFA_def_cfa
:
3426 case DW_CFA_def_cfa_sf
:
3427 case DW_CFA_def_cfa_expression
:
3429 cfi_cfa_offset
= cfi
;
3431 case DW_CFA_def_cfa_register
:
3434 case DW_CFA_def_cfa_offset
:
3435 case DW_CFA_def_cfa_offset_sf
:
3436 cfi_cfa_offset
= cfi
;
3439 gcc_assert (cfi
== NULL
);
3441 len
= VEC_length (dw_cfi_ref
, regs
);
3442 for (idx
= 0; idx
< len
; idx
++)
3444 cfi2
= VEC_replace (dw_cfi_ref
, regs
, idx
, NULL
);
3446 && cfi2
->dw_cfi_opc
!= DW_CFA_restore
3447 && cfi2
->dw_cfi_opc
!= DW_CFA_restore_extended
)
3450 output_cfi_directive (cfi2
);
3452 output_cfi (cfi2
, fde
, for_eh
);
3455 if (cfi_cfa
&& cfi_cfa_offset
&& cfi_cfa_offset
!= cfi_cfa
)
3457 gcc_assert (cfi_cfa
->dw_cfi_opc
!= DW_CFA_def_cfa_expression
);
3459 switch (cfi_cfa_offset
->dw_cfi_opc
)
3461 case DW_CFA_def_cfa_offset
:
3462 cfi_buf
.dw_cfi_opc
= DW_CFA_def_cfa
;
3463 cfi_buf
.dw_cfi_oprnd2
= cfi_cfa_offset
->dw_cfi_oprnd1
;
3465 case DW_CFA_def_cfa_offset_sf
:
3466 cfi_buf
.dw_cfi_opc
= DW_CFA_def_cfa_sf
;
3467 cfi_buf
.dw_cfi_oprnd2
= cfi_cfa_offset
->dw_cfi_oprnd1
;
3469 case DW_CFA_def_cfa
:
3470 case DW_CFA_def_cfa_sf
:
3471 cfi_buf
.dw_cfi_opc
= cfi_cfa_offset
->dw_cfi_opc
;
3472 cfi_buf
.dw_cfi_oprnd2
= cfi_cfa_offset
->dw_cfi_oprnd2
;
3479 else if (cfi_cfa_offset
)
3480 cfi_cfa
= cfi_cfa_offset
;
3484 output_cfi_directive (cfi_cfa
);
3486 output_cfi (cfi_cfa
, fde
, for_eh
);
3489 cfi_cfa_offset
= NULL
;
3491 && cfi_args_size
->dw_cfi_oprnd1
.dw_cfi_offset
)
3494 output_cfi_directive (cfi_args_size
);
3496 output_cfi (cfi_args_size
, fde
, for_eh
);
3498 cfi_args_size
= NULL
;
3501 VEC_free (dw_cfi_ref
, heap
, regs
);
3504 else if (do_cfi_asm
)
3505 output_cfi_directive (cfi
);
3507 output_cfi (cfi
, fde
, for_eh
);
3514 /* Output one FDE. */
3517 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
3518 char *section_start_label
, int fde_encoding
, char *augmentation
,
3519 bool any_lsda_needed
, int lsda_encoding
)
3521 const char *begin
, *end
;
3522 static unsigned int j
;
3523 char l1
[20], l2
[20];
3526 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
3528 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
3530 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
3531 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
3532 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
3533 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3534 " indicating 64-bit DWARF extension");
3535 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
3537 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
3540 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
3542 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
3543 debug_frame_section
, "FDE CIE offset");
3545 if (!fde
->dw_fde_switched_sections
)
3547 begin
= fde
->dw_fde_begin
;
3548 end
= fde
->dw_fde_end
;
3552 /* For the first section, prefer dw_fde_begin over
3553 dw_fde_{hot,cold}_section_label, as the latter
3554 might be separated from the real start of the
3555 function by alignment padding. */
3557 begin
= fde
->dw_fde_begin
;
3558 else if (fde
->dw_fde_switched_cold_to_hot
)
3559 begin
= fde
->dw_fde_hot_section_label
;
3561 begin
= fde
->dw_fde_unlikely_section_label
;
3562 if (second
^ fde
->dw_fde_switched_cold_to_hot
)
3563 end
= fde
->dw_fde_unlikely_section_end_label
;
3565 end
= fde
->dw_fde_hot_section_end_label
;
3570 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
3571 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
3572 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
3573 "FDE initial location");
3574 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
3575 end
, begin
, "FDE address range");
3579 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
3580 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
3583 if (augmentation
[0])
3585 if (any_lsda_needed
)
3587 int size
= size_of_encoded_value (lsda_encoding
);
3589 if (lsda_encoding
== DW_EH_PE_aligned
)
3591 int offset
= ( 4 /* Length */
3592 + 4 /* CIE offset */
3593 + 2 * size_of_encoded_value (fde_encoding
)
3594 + 1 /* Augmentation size */ );
3595 int pad
= -offset
& (PTR_SIZE
- 1);
3598 gcc_assert (size_of_uleb128 (size
) == 1);
3601 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
3603 if (fde
->uses_eh_lsda
)
3605 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
3606 fde
->funcdef_number
);
3607 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
3608 gen_rtx_SYMBOL_REF (Pmode
, l1
),
3610 "Language Specific Data Area");
3614 if (lsda_encoding
== DW_EH_PE_aligned
)
3615 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
3616 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
3617 "Language Specific Data Area (none)");
3621 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3624 /* Loop through the Call Frame Instructions associated with
3626 fde
->dw_fde_current_label
= begin
;
3627 if (!fde
->dw_fde_switched_sections
)
3628 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
3629 output_cfi (cfi
, fde
, for_eh
);
3632 if (fde
->dw_fde_switch_cfi
)
3633 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
3635 output_cfi (cfi
, fde
, for_eh
);
3636 if (cfi
== fde
->dw_fde_switch_cfi
)
3642 dw_cfi_ref cfi_next
= fde
->dw_fde_cfi
;
3644 if (fde
->dw_fde_switch_cfi
)
3646 cfi_next
= fde
->dw_fde_switch_cfi
->dw_cfi_next
;
3647 fde
->dw_fde_switch_cfi
->dw_cfi_next
= NULL
;
3648 output_cfis (fde
->dw_fde_cfi
, false, fde
, for_eh
);
3649 fde
->dw_fde_switch_cfi
->dw_cfi_next
= cfi_next
;
3651 for (cfi
= cfi_next
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
3652 output_cfi (cfi
, fde
, for_eh
);
3655 /* If we are to emit a ref/link from function bodies to their frame tables,
3656 do it now. This is typically performed to make sure that tables
3657 associated with functions are dragged with them and not discarded in
3658 garbage collecting links. We need to do this on a per function basis to
3659 cope with -ffunction-sections. */
3661 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3662 /* Switch to the function section, emit the ref to the tables, and
3663 switch *back* into the table section. */
3664 switch_to_section (function_section (fde
->decl
));
3665 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
3666 switch_to_frame_table_section (for_eh
, true);
3669 /* Pad the FDE out to an address sized boundary. */
3670 ASM_OUTPUT_ALIGN (asm_out_file
,
3671 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
3672 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
3677 /* Return true if frame description entry FDE is needed for EH. */
3680 fde_needed_for_eh_p (dw_fde_ref fde
)
3682 if (flag_asynchronous_unwind_tables
)
3685 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
3688 if (fde
->uses_eh_lsda
)
3691 /* If exceptions are enabled, we have collected nothrow info. */
3692 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
3698 /* Output the call frame information used to record information
3699 that relates to calculating the frame pointer, and records the
3700 location of saved registers. */
3703 output_call_frame_info (int for_eh
)
3708 char l1
[20], l2
[20], section_start_label
[20];
3709 bool any_lsda_needed
= false;
3710 char augmentation
[6];
3711 int augmentation_size
;
3712 int fde_encoding
= DW_EH_PE_absptr
;
3713 int per_encoding
= DW_EH_PE_absptr
;
3714 int lsda_encoding
= DW_EH_PE_absptr
;
3716 rtx personality
= NULL
;
3719 /* Don't emit a CIE if there won't be any FDEs. */
3720 if (fde_table_in_use
== 0)
3723 /* Nothing to do if the assembler's doing it all. */
3724 if (dwarf2out_do_cfi_asm ())
3727 /* If we don't have any functions we'll want to unwind out of, don't emit
3728 any EH unwind information. If we make FDEs linkonce, we may have to
3729 emit an empty label for an FDE that wouldn't otherwise be emitted. We
3730 want to avoid having an FDE kept around when the function it refers to
3731 is discarded. Example where this matters: a primary function template
3732 in C++ requires EH information, an explicit specialization doesn't. */
3735 bool any_eh_needed
= false;
3737 for (i
= 0; i
< fde_table_in_use
; i
++)
3738 if (fde_table
[i
].uses_eh_lsda
)
3739 any_eh_needed
= any_lsda_needed
= true;
3740 else if (fde_needed_for_eh_p (&fde_table
[i
]))
3741 any_eh_needed
= true;
3742 else if (TARGET_USES_WEAK_UNWIND_INFO
)
3743 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde_table
[i
].decl
,
3750 /* We're going to be generating comments, so turn on app. */
3754 /* Switch to the proper frame section, first time. */
3755 switch_to_frame_table_section (for_eh
, false);
3757 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
3758 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
3760 /* Output the CIE. */
3761 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
3762 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
3763 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
3764 dw2_asm_output_data (4, 0xffffffff,
3765 "Initial length escape value indicating 64-bit DWARF extension");
3766 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
3767 "Length of Common Information Entry");
3768 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
3770 /* Now that the CIE pointer is PC-relative for EH,
3771 use 0 to identify the CIE. */
3772 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
3773 (for_eh
? 0 : DWARF_CIE_ID
),
3774 "CIE Identifier Tag");
3776 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3777 use CIE version 1, unless that would produce incorrect results
3778 due to overflowing the return register column. */
3779 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
3781 if (return_reg
>= 256 || dwarf_version
> 2)
3783 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
3785 augmentation
[0] = 0;
3786 augmentation_size
= 0;
3788 personality
= current_unit_personality
;
3794 z Indicates that a uleb128 is present to size the
3795 augmentation section.
3796 L Indicates the encoding (and thus presence) of
3797 an LSDA pointer in the FDE augmentation.
3798 R Indicates a non-default pointer encoding for
3800 P Indicates the presence of an encoding + language
3801 personality routine in the CIE augmentation. */
3803 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3804 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3805 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3807 p
= augmentation
+ 1;
3811 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
3812 assemble_external_libcall (personality
);
3814 if (any_lsda_needed
)
3817 augmentation_size
+= 1;
3819 if (fde_encoding
!= DW_EH_PE_absptr
)
3822 augmentation_size
+= 1;
3824 if (p
> augmentation
+ 1)
3826 augmentation
[0] = 'z';
3830 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3831 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
3833 int offset
= ( 4 /* Length */
3835 + 1 /* CIE version */
3836 + strlen (augmentation
) + 1 /* Augmentation */
3837 + size_of_uleb128 (1) /* Code alignment */
3838 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
3840 + 1 /* Augmentation size */
3841 + 1 /* Personality encoding */ );
3842 int pad
= -offset
& (PTR_SIZE
- 1);
3844 augmentation_size
+= pad
;
3846 /* Augmentations should be small, so there's scarce need to
3847 iterate for a solution. Die if we exceed one uleb128 byte. */
3848 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
3852 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
3853 if (dw_cie_version
>= 4)
3855 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
3856 dw2_asm_output_data (1, 0, "CIE Segment Size");
3858 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3859 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
3860 "CIE Data Alignment Factor");
3862 if (dw_cie_version
== 1)
3863 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
3865 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
3867 if (augmentation
[0])
3869 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
3872 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
3873 eh_data_format_name (per_encoding
));
3874 dw2_asm_output_encoded_addr_rtx (per_encoding
,
3879 if (any_lsda_needed
)
3880 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
3881 eh_data_format_name (lsda_encoding
));
3883 if (fde_encoding
!= DW_EH_PE_absptr
)
3884 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
3885 eh_data_format_name (fde_encoding
));
3888 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
3889 output_cfi (cfi
, NULL
, for_eh
);
3891 /* Pad the CIE out to an address sized boundary. */
3892 ASM_OUTPUT_ALIGN (asm_out_file
,
3893 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
3894 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
3896 /* Loop through all of the FDE's. */
3897 for (i
= 0; i
< fde_table_in_use
; i
++)
3900 fde
= &fde_table
[i
];
3902 /* Don't emit EH unwind info for leaf functions that don't need it. */
3903 if (for_eh
&& !fde_needed_for_eh_p (fde
))
3906 for (k
= 0; k
< (fde
->dw_fde_switched_sections
? 2 : 1); k
++)
3907 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
3908 augmentation
, any_lsda_needed
, lsda_encoding
);
3911 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
3912 dw2_asm_output_data (4, 0, "End of Table");
3913 #ifdef MIPS_DEBUGGING_INFO
3914 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3915 get a value of 0. Putting .align 0 after the label fixes it. */
3916 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
3919 /* Turn off app to make assembly quicker. */
3924 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
3927 dwarf2out_do_cfi_startproc (bool second
)
3931 rtx personality
= get_personality_function (current_function_decl
);
3933 fprintf (asm_out_file
, "\t.cfi_startproc\n");
3937 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3940 /* ??? The GAS support isn't entirely consistent. We have to
3941 handle indirect support ourselves, but PC-relative is done
3942 in the assembler. Further, the assembler can't handle any
3943 of the weirder relocation types. */
3944 if (enc
& DW_EH_PE_indirect
)
3945 ref
= dw2_force_const_mem (ref
, true);
3947 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
3948 output_addr_const (asm_out_file
, ref
);
3949 fputc ('\n', asm_out_file
);
3952 if (crtl
->uses_eh_lsda
)
3956 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3957 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
3958 current_function_funcdef_no
);
3959 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
3960 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
3962 if (enc
& DW_EH_PE_indirect
)
3963 ref
= dw2_force_const_mem (ref
, true);
3965 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
3966 output_addr_const (asm_out_file
, ref
);
3967 fputc ('\n', asm_out_file
);
3971 /* Output a marker (i.e. a label) for the beginning of a function, before
3975 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
3976 const char *file ATTRIBUTE_UNUSED
)
3978 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3984 current_function_func_begin_label
= NULL
;
3986 do_frame
= dwarf2out_do_frame ();
3988 /* ??? current_function_func_begin_label is also used by except.c for
3989 call-site information. We must emit this label if it might be used. */
3991 && (!flag_exceptions
3992 || targetm
.except_unwind_info () != UI_TARGET
))
3995 fnsec
= function_section (current_function_decl
);
3996 switch_to_section (fnsec
);
3997 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
3998 current_function_funcdef_no
);
3999 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
4000 current_function_funcdef_no
);
4001 dup_label
= xstrdup (label
);
4002 current_function_func_begin_label
= dup_label
;
4004 /* We can elide the fde allocation if we're not emitting debug info. */
4008 /* Expand the fde table if necessary. */
4009 if (fde_table_in_use
== fde_table_allocated
)
4011 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
4012 fde_table
= GGC_RESIZEVEC (dw_fde_node
, fde_table
, fde_table_allocated
);
4013 memset (fde_table
+ fde_table_in_use
, 0,
4014 FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
4017 /* Record the FDE associated with this function. */
4018 current_funcdef_fde
= fde_table_in_use
;
4020 /* Add the new FDE at the end of the fde_table. */
4021 fde
= &fde_table
[fde_table_in_use
++];
4022 fde
->decl
= current_function_decl
;
4023 fde
->dw_fde_begin
= dup_label
;
4024 fde
->dw_fde_current_label
= dup_label
;
4025 fde
->dw_fde_hot_section_label
= NULL
;
4026 fde
->dw_fde_hot_section_end_label
= NULL
;
4027 fde
->dw_fde_unlikely_section_label
= NULL
;
4028 fde
->dw_fde_unlikely_section_end_label
= NULL
;
4029 fde
->dw_fde_switched_sections
= 0;
4030 fde
->dw_fde_switched_cold_to_hot
= 0;
4031 fde
->dw_fde_end
= NULL
;
4032 fde
->dw_fde_vms_end_prologue
= NULL
;
4033 fde
->dw_fde_vms_begin_epilogue
= NULL
;
4034 fde
->dw_fde_cfi
= NULL
;
4035 fde
->dw_fde_switch_cfi
= NULL
;
4036 fde
->funcdef_number
= current_function_funcdef_no
;
4037 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
4038 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
4039 fde
->nothrow
= crtl
->nothrow
;
4040 fde
->drap_reg
= INVALID_REGNUM
;
4041 fde
->vdrap_reg
= INVALID_REGNUM
;
4042 if (flag_reorder_blocks_and_partition
)
4044 section
*unlikelysec
;
4045 if (first_function_block_is_cold
)
4046 fde
->in_std_section
= 1;
4049 = (fnsec
== text_section
4050 || (cold_text_section
&& fnsec
== cold_text_section
));
4051 unlikelysec
= unlikely_text_section ();
4052 fde
->cold_in_std_section
4053 = (unlikelysec
== text_section
4054 || (cold_text_section
&& unlikelysec
== cold_text_section
));
4059 = (fnsec
== text_section
4060 || (cold_text_section
&& fnsec
== cold_text_section
));
4061 fde
->cold_in_std_section
= 0;
4064 args_size
= old_args_size
= 0;
4066 /* We only want to output line number information for the genuine dwarf2
4067 prologue case, not the eh frame case. */
4068 #ifdef DWARF2_DEBUGGING_INFO
4070 dwarf2out_source_line (line
, file
, 0, true);
4073 if (dwarf2out_do_cfi_asm ())
4074 dwarf2out_do_cfi_startproc (false);
4077 rtx personality
= get_personality_function (current_function_decl
);
4078 if (!current_unit_personality
)
4079 current_unit_personality
= personality
;
4081 /* We cannot keep a current personality per function as without CFI
4082 asm, at the point where we emit the CFI data, there is no current
4083 function anymore. */
4084 if (personality
&& current_unit_personality
!= personality
)
4085 sorry ("multiple EH personalities are supported only with assemblers "
4086 "supporting .cfi_personality directive");
4090 /* Output a marker (i.e. a label) for the end of the generated code
4091 for a function prologue. This gets called *after* the prologue code has
4095 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
4096 const char *file ATTRIBUTE_UNUSED
)
4099 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4101 /* Output a label to mark the endpoint of the code generated for this
4103 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
4104 current_function_funcdef_no
);
4105 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
4106 current_function_funcdef_no
);
4107 fde
= &fde_table
[fde_table_in_use
- 1];
4108 fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
4111 /* Output a marker (i.e. a label) for the beginning of the generated code
4112 for a function epilogue. This gets called *before* the prologue code has
4116 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
4117 const char *file ATTRIBUTE_UNUSED
)
4120 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4122 fde
= &fde_table
[fde_table_in_use
- 1];
4123 if (fde
->dw_fde_vms_begin_epilogue
)
4126 /* Output a label to mark the endpoint of the code generated for this
4128 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
4129 current_function_funcdef_no
);
4130 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
4131 current_function_funcdef_no
);
4132 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
4135 /* Output a marker (i.e. a label) for the absolute end of the generated code
4136 for a function definition. This gets called *after* the epilogue code has
4140 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
4141 const char *file ATTRIBUTE_UNUSED
)
4144 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4146 last_var_location_insn
= NULL_RTX
;
4148 if (dwarf2out_do_cfi_asm ())
4149 fprintf (asm_out_file
, "\t.cfi_endproc\n");
4151 /* Output a label to mark the endpoint of the code generated for this
4153 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
4154 current_function_funcdef_no
);
4155 ASM_OUTPUT_LABEL (asm_out_file
, label
);
4156 fde
= current_fde ();
4157 gcc_assert (fde
!= NULL
);
4158 fde
->dw_fde_end
= xstrdup (label
);
4162 dwarf2out_frame_init (void)
4164 /* Allocate the initial hunk of the fde_table. */
4165 fde_table
= ggc_alloc_cleared_vec_dw_fde_node (FDE_TABLE_INCREMENT
);
4166 fde_table_allocated
= FDE_TABLE_INCREMENT
;
4167 fde_table_in_use
= 0;
4169 /* Generate the CFA instructions common to all FDE's. Do it now for the
4170 sake of lookup_cfa. */
4172 /* On entry, the Canonical Frame Address is at SP. */
4173 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
4175 if (targetm
.debug_unwind_info () == UI_DWARF2
4176 || targetm
.except_unwind_info () == UI_DWARF2
)
4177 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
4181 dwarf2out_frame_finish (void)
4183 /* Output call frame information. */
4184 if (targetm
.debug_unwind_info () == UI_DWARF2
)
4185 output_call_frame_info (0);
4187 /* Output another copy for the unwinder. */
4188 if ((flag_unwind_tables
|| flag_exceptions
)
4189 && targetm
.except_unwind_info () == UI_DWARF2
)
4190 output_call_frame_info (1);
4193 /* Note that the current function section is being used for code. */
4196 dwarf2out_note_section_used (void)
4198 section
*sec
= current_function_section ();
4199 if (sec
== text_section
)
4200 text_section_used
= true;
4201 else if (sec
== cold_text_section
)
4202 cold_text_section_used
= true;
4206 dwarf2out_switch_text_section (void)
4208 dw_fde_ref fde
= current_fde ();
4210 gcc_assert (cfun
&& fde
&& !fde
->dw_fde_switched_sections
);
4212 fde
->dw_fde_switched_sections
= 1;
4213 fde
->dw_fde_switched_cold_to_hot
= !in_cold_section_p
;
4215 fde
->dw_fde_hot_section_label
= crtl
->subsections
.hot_section_label
;
4216 fde
->dw_fde_hot_section_end_label
= crtl
->subsections
.hot_section_end_label
;
4217 fde
->dw_fde_unlikely_section_label
= crtl
->subsections
.cold_section_label
;
4218 fde
->dw_fde_unlikely_section_end_label
= crtl
->subsections
.cold_section_end_label
;
4219 have_multiple_function_sections
= true;
4221 /* Reset the current label on switching text sections, so that we
4222 don't attempt to advance_loc4 between labels in different sections. */
4223 fde
->dw_fde_current_label
= NULL
;
4225 /* There is no need to mark used sections when not debugging. */
4226 if (cold_text_section
!= NULL
)
4227 dwarf2out_note_section_used ();
4229 if (dwarf2out_do_cfi_asm ())
4230 fprintf (asm_out_file
, "\t.cfi_endproc\n");
4232 /* Now do the real section switch. */
4233 switch_to_section (current_function_section ());
4235 if (dwarf2out_do_cfi_asm ())
4237 dwarf2out_do_cfi_startproc (true);
4238 /* As this is a different FDE, insert all current CFI instructions
4240 output_cfis (fde
->dw_fde_cfi
, true, fde
, true);
4244 dw_cfi_ref cfi
= fde
->dw_fde_cfi
;
4246 cfi
= fde
->dw_fde_cfi
;
4248 while (cfi
->dw_cfi_next
!= NULL
)
4249 cfi
= cfi
->dw_cfi_next
;
4250 fde
->dw_fde_switch_cfi
= cfi
;
4254 /* And now, the subset of the debugging information support code necessary
4255 for emitting location expressions. */
4257 /* Data about a single source file. */
4258 struct GTY(()) dwarf_file_data
{
4259 const char * filename
;
4263 typedef struct dw_val_struct
*dw_val_ref
;
4264 typedef struct die_struct
*dw_die_ref
;
4265 typedef const struct die_struct
*const_dw_die_ref
;
4266 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
4267 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
4269 typedef struct GTY(()) deferred_locations_struct
4273 } deferred_locations
;
4275 DEF_VEC_O(deferred_locations
);
4276 DEF_VEC_ALLOC_O(deferred_locations
,gc
);
4278 static GTY(()) VEC(deferred_locations
, gc
) *deferred_locations_list
;
4280 DEF_VEC_P(dw_die_ref
);
4281 DEF_VEC_ALLOC_P(dw_die_ref
,heap
);
4283 /* Each DIE may have a series of attribute/value pairs. Values
4284 can take on several forms. The forms that are used in this
4285 implementation are listed below. */
4290 dw_val_class_offset
,
4292 dw_val_class_loc_list
,
4293 dw_val_class_range_list
,
4295 dw_val_class_unsigned_const
,
4296 dw_val_class_const_double
,
4299 dw_val_class_die_ref
,
4300 dw_val_class_fde_ref
,
4301 dw_val_class_lbl_id
,
4302 dw_val_class_lineptr
,
4304 dw_val_class_macptr
,
4307 dw_val_class_decl_ref
,
4308 dw_val_class_vms_delta
4311 /* Describe a floating point constant value, or a vector constant value. */
4313 typedef struct GTY(()) dw_vec_struct
{
4314 unsigned char * GTY((length ("%h.length"))) array
;
4320 /* The dw_val_node describes an attribute's value, as it is
4321 represented internally. */
4323 typedef struct GTY(()) dw_val_struct
{
4324 enum dw_val_class val_class
;
4325 union dw_val_struct_union
4327 rtx
GTY ((tag ("dw_val_class_addr"))) val_addr
;
4328 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_offset"))) val_offset
;
4329 dw_loc_list_ref
GTY ((tag ("dw_val_class_loc_list"))) val_loc_list
;
4330 dw_loc_descr_ref
GTY ((tag ("dw_val_class_loc"))) val_loc
;
4331 HOST_WIDE_INT
GTY ((default)) val_int
;
4332 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned
;
4333 double_int
GTY ((tag ("dw_val_class_const_double"))) val_double
;
4334 dw_vec_const
GTY ((tag ("dw_val_class_vec"))) val_vec
;
4335 struct dw_val_die_union
4339 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref
;
4340 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index
;
4341 struct indirect_string_node
* GTY ((tag ("dw_val_class_str"))) val_str
;
4342 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id
;
4343 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag
;
4344 struct dwarf_file_data
* GTY ((tag ("dw_val_class_file"))) val_file
;
4345 unsigned char GTY ((tag ("dw_val_class_data8"))) val_data8
[8];
4346 tree
GTY ((tag ("dw_val_class_decl_ref"))) val_decl_ref
;
4347 struct dw_val_vms_delta_union
4351 } GTY ((tag ("dw_val_class_vms_delta"))) val_vms_delta
;
4353 GTY ((desc ("%1.val_class"))) v
;
4357 /* Locations in memory are described using a sequence of stack machine
4360 typedef struct GTY(()) dw_loc_descr_struct
{
4361 dw_loc_descr_ref dw_loc_next
;
4362 ENUM_BITFIELD (dwarf_location_atom
) dw_loc_opc
: 8;
4363 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4364 from DW_OP_addr with a dtp-relative symbol relocation. */
4365 unsigned int dtprel
: 1;
4367 dw_val_node dw_loc_oprnd1
;
4368 dw_val_node dw_loc_oprnd2
;
4372 /* Location lists are ranges + location descriptions for that range,
4373 so you can track variables that are in different places over
4374 their entire life. */
4375 typedef struct GTY(()) dw_loc_list_struct
{
4376 dw_loc_list_ref dw_loc_next
;
4377 const char *begin
; /* Label for begin address of range */
4378 const char *end
; /* Label for end address of range */
4379 char *ll_symbol
; /* Label for beginning of location list.
4380 Only on head of list */
4381 const char *section
; /* Section this loclist is relative to */
4382 dw_loc_descr_ref expr
;
4387 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
4389 /* Convert a DWARF stack opcode into its string name. */
4392 dwarf_stack_op_name (unsigned int op
)
4397 return "DW_OP_addr";
4399 return "DW_OP_deref";
4401 return "DW_OP_const1u";
4403 return "DW_OP_const1s";
4405 return "DW_OP_const2u";
4407 return "DW_OP_const2s";
4409 return "DW_OP_const4u";
4411 return "DW_OP_const4s";
4413 return "DW_OP_const8u";
4415 return "DW_OP_const8s";
4417 return "DW_OP_constu";
4419 return "DW_OP_consts";
4423 return "DW_OP_drop";
4425 return "DW_OP_over";
4427 return "DW_OP_pick";
4429 return "DW_OP_swap";
4433 return "DW_OP_xderef";
4441 return "DW_OP_minus";
4453 return "DW_OP_plus";
4454 case DW_OP_plus_uconst
:
4455 return "DW_OP_plus_uconst";
4461 return "DW_OP_shra";
4479 return "DW_OP_skip";
4481 return "DW_OP_lit0";
4483 return "DW_OP_lit1";
4485 return "DW_OP_lit2";
4487 return "DW_OP_lit3";
4489 return "DW_OP_lit4";
4491 return "DW_OP_lit5";
4493 return "DW_OP_lit6";
4495 return "DW_OP_lit7";
4497 return "DW_OP_lit8";
4499 return "DW_OP_lit9";
4501 return "DW_OP_lit10";
4503 return "DW_OP_lit11";
4505 return "DW_OP_lit12";
4507 return "DW_OP_lit13";
4509 return "DW_OP_lit14";
4511 return "DW_OP_lit15";
4513 return "DW_OP_lit16";
4515 return "DW_OP_lit17";
4517 return "DW_OP_lit18";
4519 return "DW_OP_lit19";
4521 return "DW_OP_lit20";
4523 return "DW_OP_lit21";
4525 return "DW_OP_lit22";
4527 return "DW_OP_lit23";
4529 return "DW_OP_lit24";
4531 return "DW_OP_lit25";
4533 return "DW_OP_lit26";
4535 return "DW_OP_lit27";
4537 return "DW_OP_lit28";
4539 return "DW_OP_lit29";
4541 return "DW_OP_lit30";
4543 return "DW_OP_lit31";
4545 return "DW_OP_reg0";
4547 return "DW_OP_reg1";
4549 return "DW_OP_reg2";
4551 return "DW_OP_reg3";
4553 return "DW_OP_reg4";
4555 return "DW_OP_reg5";
4557 return "DW_OP_reg6";
4559 return "DW_OP_reg7";
4561 return "DW_OP_reg8";
4563 return "DW_OP_reg9";
4565 return "DW_OP_reg10";
4567 return "DW_OP_reg11";
4569 return "DW_OP_reg12";
4571 return "DW_OP_reg13";
4573 return "DW_OP_reg14";
4575 return "DW_OP_reg15";
4577 return "DW_OP_reg16";
4579 return "DW_OP_reg17";
4581 return "DW_OP_reg18";
4583 return "DW_OP_reg19";
4585 return "DW_OP_reg20";
4587 return "DW_OP_reg21";
4589 return "DW_OP_reg22";
4591 return "DW_OP_reg23";
4593 return "DW_OP_reg24";
4595 return "DW_OP_reg25";
4597 return "DW_OP_reg26";
4599 return "DW_OP_reg27";
4601 return "DW_OP_reg28";
4603 return "DW_OP_reg29";
4605 return "DW_OP_reg30";
4607 return "DW_OP_reg31";
4609 return "DW_OP_breg0";
4611 return "DW_OP_breg1";
4613 return "DW_OP_breg2";
4615 return "DW_OP_breg3";
4617 return "DW_OP_breg4";
4619 return "DW_OP_breg5";
4621 return "DW_OP_breg6";
4623 return "DW_OP_breg7";
4625 return "DW_OP_breg8";
4627 return "DW_OP_breg9";
4629 return "DW_OP_breg10";
4631 return "DW_OP_breg11";
4633 return "DW_OP_breg12";
4635 return "DW_OP_breg13";
4637 return "DW_OP_breg14";
4639 return "DW_OP_breg15";
4641 return "DW_OP_breg16";
4643 return "DW_OP_breg17";
4645 return "DW_OP_breg18";
4647 return "DW_OP_breg19";
4649 return "DW_OP_breg20";
4651 return "DW_OP_breg21";
4653 return "DW_OP_breg22";
4655 return "DW_OP_breg23";
4657 return "DW_OP_breg24";
4659 return "DW_OP_breg25";
4661 return "DW_OP_breg26";
4663 return "DW_OP_breg27";
4665 return "DW_OP_breg28";
4667 return "DW_OP_breg29";
4669 return "DW_OP_breg30";
4671 return "DW_OP_breg31";
4673 return "DW_OP_regx";
4675 return "DW_OP_fbreg";
4677 return "DW_OP_bregx";
4679 return "DW_OP_piece";
4680 case DW_OP_deref_size
:
4681 return "DW_OP_deref_size";
4682 case DW_OP_xderef_size
:
4683 return "DW_OP_xderef_size";
4687 case DW_OP_push_object_address
:
4688 return "DW_OP_push_object_address";
4690 return "DW_OP_call2";
4692 return "DW_OP_call4";
4693 case DW_OP_call_ref
:
4694 return "DW_OP_call_ref";
4695 case DW_OP_implicit_value
:
4696 return "DW_OP_implicit_value";
4697 case DW_OP_stack_value
:
4698 return "DW_OP_stack_value";
4699 case DW_OP_form_tls_address
:
4700 return "DW_OP_form_tls_address";
4701 case DW_OP_call_frame_cfa
:
4702 return "DW_OP_call_frame_cfa";
4703 case DW_OP_bit_piece
:
4704 return "DW_OP_bit_piece";
4706 case DW_OP_GNU_push_tls_address
:
4707 return "DW_OP_GNU_push_tls_address";
4708 case DW_OP_GNU_uninit
:
4709 return "DW_OP_GNU_uninit";
4710 case DW_OP_GNU_encoded_addr
:
4711 return "DW_OP_GNU_encoded_addr";
4712 case DW_OP_GNU_implicit_pointer
:
4713 return "DW_OP_GNU_implicit_pointer";
4716 return "OP_<unknown>";
4720 /* Return a pointer to a newly allocated location description. Location
4721 descriptions are simple expression terms that can be strung
4722 together to form more complicated location (address) descriptions. */
4724 static inline dw_loc_descr_ref
4725 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
4726 unsigned HOST_WIDE_INT oprnd2
)
4728 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
4730 descr
->dw_loc_opc
= op
;
4731 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
4732 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
4733 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
4734 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
4739 /* Return a pointer to a newly allocated location description for
4742 static inline dw_loc_descr_ref
4743 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
4746 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
4749 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
4752 /* Add a location description term to a location description expression. */
4755 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
4757 dw_loc_descr_ref
*d
;
4759 /* Find the end of the chain. */
4760 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
4766 /* Add a constant OFFSET to a location expression. */
4769 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
4771 dw_loc_descr_ref loc
;
4774 gcc_assert (*list_head
!= NULL
);
4779 /* Find the end of the chain. */
4780 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
4784 if (loc
->dw_loc_opc
== DW_OP_fbreg
4785 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
4786 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
4787 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
4788 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
4790 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4791 offset. Don't optimize if an signed integer overflow would happen. */
4793 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
4794 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
4797 else if (offset
> 0)
4798 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
4802 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
4803 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
4807 /* Add a constant OFFSET to a location list. */
4810 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
4813 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
4814 loc_descr_plus_const (&d
->expr
, offset
);
4817 #define DWARF_REF_SIZE \
4818 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
4820 /* Return the size of a location descriptor. */
4822 static unsigned long
4823 size_of_loc_descr (dw_loc_descr_ref loc
)
4825 unsigned long size
= 1;
4827 switch (loc
->dw_loc_opc
)
4830 size
+= DWARF2_ADDR_SIZE
;
4849 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4852 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4857 case DW_OP_plus_uconst
:
4858 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4896 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4899 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4902 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4905 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4906 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
4909 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4911 case DW_OP_bit_piece
:
4912 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4913 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
4915 case DW_OP_deref_size
:
4916 case DW_OP_xderef_size
:
4925 case DW_OP_call_ref
:
4926 size
+= DWARF_REF_SIZE
;
4928 case DW_OP_implicit_value
:
4929 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
4930 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
4932 case DW_OP_GNU_implicit_pointer
:
4933 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
4942 /* Return the size of a series of location descriptors. */
4944 static unsigned long
4945 size_of_locs (dw_loc_descr_ref loc
)
4950 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
4951 field, to avoid writing to a PCH file. */
4952 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
4954 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
4956 size
+= size_of_loc_descr (l
);
4961 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
4963 l
->dw_loc_addr
= size
;
4964 size
+= size_of_loc_descr (l
);
4970 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
4971 static void get_ref_die_offset_label (char *, dw_die_ref
);
4973 /* Output location description stack opcode's operands (if any). */
4976 output_loc_operands (dw_loc_descr_ref loc
)
4978 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
4979 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
4981 switch (loc
->dw_loc_opc
)
4983 #ifdef DWARF2_DEBUGGING_INFO
4986 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
4991 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
4992 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
4994 fputc ('\n', asm_out_file
);
4999 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
5004 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
5005 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
5007 fputc ('\n', asm_out_file
);
5012 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
5013 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
5020 gcc_assert (val1
->val_class
== dw_val_class_loc
);
5021 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
5023 dw2_asm_output_data (2, offset
, NULL
);
5026 case DW_OP_implicit_value
:
5027 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5028 switch (val2
->val_class
)
5030 case dw_val_class_const
:
5031 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
5033 case dw_val_class_vec
:
5035 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
5036 unsigned int len
= val2
->v
.val_vec
.length
;
5040 if (elt_size
> sizeof (HOST_WIDE_INT
))
5045 for (i
= 0, p
= val2
->v
.val_vec
.array
;
5048 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
5049 "fp or vector constant word %u", i
);
5052 case dw_val_class_const_double
:
5054 unsigned HOST_WIDE_INT first
, second
;
5056 if (WORDS_BIG_ENDIAN
)
5058 first
= val2
->v
.val_double
.high
;
5059 second
= val2
->v
.val_double
.low
;
5063 first
= val2
->v
.val_double
.low
;
5064 second
= val2
->v
.val_double
.high
;
5066 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
5068 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
5072 case dw_val_class_addr
:
5073 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
5074 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
5089 case DW_OP_implicit_value
:
5090 /* We currently don't make any attempt to make sure these are
5091 aligned properly like we do for the main unwind info, so
5092 don't support emitting things larger than a byte if we're
5093 only doing unwinding. */
5098 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
5101 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5104 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
5107 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
5109 case DW_OP_plus_uconst
:
5110 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5144 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
5147 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5150 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
5153 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5154 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
5157 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5159 case DW_OP_bit_piece
:
5160 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5161 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
5163 case DW_OP_deref_size
:
5164 case DW_OP_xderef_size
:
5165 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
5171 if (targetm
.asm_out
.output_dwarf_dtprel
)
5173 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
5176 fputc ('\n', asm_out_file
);
5183 #ifdef DWARF2_DEBUGGING_INFO
5184 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
5191 case DW_OP_GNU_implicit_pointer
:
5193 char label
[MAX_ARTIFICIAL_LABEL_BYTES
5194 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
5195 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
5196 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
5197 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
5198 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
5203 /* Other codes have no operands. */
5208 /* Output a sequence of location operations. */
5211 output_loc_sequence (dw_loc_descr_ref loc
)
5213 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
5215 /* Output the opcode. */
5216 dw2_asm_output_data (1, loc
->dw_loc_opc
,
5217 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
5219 /* Output the operand(s) (if any). */
5220 output_loc_operands (loc
);
5224 /* Output location description stack opcode's operands (if any).
5225 The output is single bytes on a line, suitable for .cfi_escape. */
5228 output_loc_operands_raw (dw_loc_descr_ref loc
)
5230 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
5231 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
5233 switch (loc
->dw_loc_opc
)
5236 case DW_OP_implicit_value
:
5237 /* We cannot output addresses in .cfi_escape, only bytes. */
5243 case DW_OP_deref_size
:
5244 case DW_OP_xderef_size
:
5245 fputc (',', asm_out_file
);
5246 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
5251 fputc (',', asm_out_file
);
5252 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
5257 fputc (',', asm_out_file
);
5258 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
5263 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
5264 fputc (',', asm_out_file
);
5265 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
5273 gcc_assert (val1
->val_class
== dw_val_class_loc
);
5274 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
5276 fputc (',', asm_out_file
);
5277 dw2_asm_output_data_raw (2, offset
);
5282 case DW_OP_plus_uconst
:
5285 fputc (',', asm_out_file
);
5286 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
5289 case DW_OP_bit_piece
:
5290 fputc (',', asm_out_file
);
5291 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
5292 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
5329 fputc (',', asm_out_file
);
5330 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
5334 fputc (',', asm_out_file
);
5335 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
5336 fputc (',', asm_out_file
);
5337 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
5340 case DW_OP_GNU_implicit_pointer
:
5345 /* Other codes have no operands. */
5351 output_loc_sequence_raw (dw_loc_descr_ref loc
)
5355 /* Output the opcode. */
5356 fprintf (asm_out_file
, "%#x", loc
->dw_loc_opc
);
5357 output_loc_operands_raw (loc
);
5359 if (!loc
->dw_loc_next
)
5361 loc
= loc
->dw_loc_next
;
5363 fputc (',', asm_out_file
);
5367 /* This routine will generate the correct assembly data for a location
5368 description based on a cfi entry with a complex address. */
5371 output_cfa_loc (dw_cfi_ref cfi
)
5373 dw_loc_descr_ref loc
;
5376 if (cfi
->dw_cfi_opc
== DW_CFA_expression
)
5378 dw2_asm_output_data (1, cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, NULL
);
5379 loc
= cfi
->dw_cfi_oprnd2
.dw_cfi_loc
;
5382 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
5384 /* Output the size of the block. */
5385 size
= size_of_locs (loc
);
5386 dw2_asm_output_data_uleb128 (size
, NULL
);
5388 /* Now output the operations themselves. */
5389 output_loc_sequence (loc
);
5392 /* Similar, but used for .cfi_escape. */
5395 output_cfa_loc_raw (dw_cfi_ref cfi
)
5397 dw_loc_descr_ref loc
;
5400 if (cfi
->dw_cfi_opc
== DW_CFA_expression
)
5402 fprintf (asm_out_file
, "%#x,", cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
5403 loc
= cfi
->dw_cfi_oprnd2
.dw_cfi_loc
;
5406 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
5408 /* Output the size of the block. */
5409 size
= size_of_locs (loc
);
5410 dw2_asm_output_data_uleb128_raw (size
);
5411 fputc (',', asm_out_file
);
5413 /* Now output the operations themselves. */
5414 output_loc_sequence_raw (loc
);
5417 /* This function builds a dwarf location descriptor sequence from a
5418 dw_cfa_location, adding the given OFFSET to the result of the
5421 static struct dw_loc_descr_struct
*
5422 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
5424 struct dw_loc_descr_struct
*head
, *tmp
;
5426 offset
+= cfa
->offset
;
5430 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
5431 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
5432 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
5433 add_loc_descr (&head
, tmp
);
5436 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
5437 add_loc_descr (&head
, tmp
);
5441 head
= new_reg_loc_descr (cfa
->reg
, offset
);
5446 /* This function builds a dwarf location descriptor sequence for
5447 the address at OFFSET from the CFA when stack is aligned to
5450 static struct dw_loc_descr_struct
*
5451 build_cfa_aligned_loc (HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
5453 struct dw_loc_descr_struct
*head
;
5454 unsigned int dwarf_fp
5455 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
5457 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5458 if (cfa
.reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
.indirect
== 0)
5460 head
= new_reg_loc_descr (dwarf_fp
, 0);
5461 add_loc_descr (&head
, int_loc_descriptor (alignment
));
5462 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
5463 loc_descr_plus_const (&head
, offset
);
5466 head
= new_reg_loc_descr (dwarf_fp
, offset
);
5470 /* This function fills in aa dw_cfa_location structure from a dwarf location
5471 descriptor sequence. */
5474 get_cfa_from_loc_descr (dw_cfa_location
*cfa
, struct dw_loc_descr_struct
*loc
)
5476 struct dw_loc_descr_struct
*ptr
;
5478 cfa
->base_offset
= 0;
5482 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
5484 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
5520 cfa
->reg
= op
- DW_OP_reg0
;
5523 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
5557 cfa
->reg
= op
- DW_OP_breg0
;
5558 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
5561 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
5562 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
5567 case DW_OP_plus_uconst
:
5568 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
5571 internal_error ("DW_LOC_OP %s not implemented",
5572 dwarf_stack_op_name (ptr
->dw_loc_opc
));
5577 /* And now, the support for symbolic debugging information. */
5579 /* .debug_str support. */
5580 static int output_indirect_string (void **, void *);
5582 static void dwarf2out_init (const char *);
5583 static void dwarf2out_finish (const char *);
5584 static void dwarf2out_assembly_start (void);
5585 static void dwarf2out_define (unsigned int, const char *);
5586 static void dwarf2out_undef (unsigned int, const char *);
5587 static void dwarf2out_start_source_file (unsigned, const char *);
5588 static void dwarf2out_end_source_file (unsigned);
5589 static void dwarf2out_function_decl (tree
);
5590 static void dwarf2out_begin_block (unsigned, unsigned);
5591 static void dwarf2out_end_block (unsigned, unsigned);
5592 static bool dwarf2out_ignore_block (const_tree
);
5593 static void dwarf2out_global_decl (tree
);
5594 static void dwarf2out_type_decl (tree
, int);
5595 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
5596 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
5598 static void dwarf2out_abstract_function (tree
);
5599 static void dwarf2out_var_location (rtx
);
5600 static void dwarf2out_direct_call (tree
);
5601 static void dwarf2out_virtual_call_token (tree
, int);
5602 static void dwarf2out_copy_call_info (rtx
, rtx
);
5603 static void dwarf2out_virtual_call (int);
5604 static void dwarf2out_begin_function (tree
);
5605 static void dwarf2out_set_name (tree
, tree
);
5607 /* The debug hooks structure. */
5609 const struct gcc_debug_hooks dwarf2_debug_hooks
=
5613 dwarf2out_assembly_start
,
5616 dwarf2out_start_source_file
,
5617 dwarf2out_end_source_file
,
5618 dwarf2out_begin_block
,
5619 dwarf2out_end_block
,
5620 dwarf2out_ignore_block
,
5621 dwarf2out_source_line
,
5622 dwarf2out_begin_prologue
,
5623 #if VMS_DEBUGGING_INFO
5624 dwarf2out_vms_end_prologue
,
5625 dwarf2out_vms_begin_epilogue
,
5627 debug_nothing_int_charstar
,
5628 debug_nothing_int_charstar
,
5630 dwarf2out_end_epilogue
,
5631 dwarf2out_begin_function
,
5632 debug_nothing_int
, /* end_function */
5633 dwarf2out_function_decl
, /* function_decl */
5634 dwarf2out_global_decl
,
5635 dwarf2out_type_decl
, /* type_decl */
5636 dwarf2out_imported_module_or_decl
,
5637 debug_nothing_tree
, /* deferred_inline_function */
5638 /* The DWARF 2 backend tries to reduce debugging bloat by not
5639 emitting the abstract description of inline functions until
5640 something tries to reference them. */
5641 dwarf2out_abstract_function
, /* outlining_inline_function */
5642 debug_nothing_rtx
, /* label */
5643 debug_nothing_int
, /* handle_pch */
5644 dwarf2out_var_location
,
5645 dwarf2out_switch_text_section
,
5646 dwarf2out_direct_call
,
5647 dwarf2out_virtual_call_token
,
5648 dwarf2out_copy_call_info
,
5649 dwarf2out_virtual_call
,
5651 1 /* start_end_main_source_file */
5654 /* NOTE: In the comments in this file, many references are made to
5655 "Debugging Information Entries". This term is abbreviated as `DIE'
5656 throughout the remainder of this file. */
5658 /* An internal representation of the DWARF output is built, and then
5659 walked to generate the DWARF debugging info. The walk of the internal
5660 representation is done after the entire program has been compiled.
5661 The types below are used to describe the internal representation. */
5663 /* Various DIE's use offsets relative to the beginning of the
5664 .debug_info section to refer to each other. */
5666 typedef long int dw_offset
;
5668 /* Define typedefs here to avoid circular dependencies. */
5670 typedef struct dw_attr_struct
*dw_attr_ref
;
5671 typedef struct dw_line_info_struct
*dw_line_info_ref
;
5672 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
5673 typedef struct pubname_struct
*pubname_ref
;
5674 typedef struct dw_ranges_struct
*dw_ranges_ref
;
5675 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
5676 typedef struct comdat_type_struct
*comdat_type_node_ref
;
5678 /* Each entry in the line_info_table maintains the file and
5679 line number associated with the label generated for that
5680 entry. The label gives the PC value associated with
5681 the line number entry. */
5683 typedef struct GTY(()) dw_line_info_struct
{
5684 unsigned long dw_file_num
;
5685 unsigned long dw_line_num
;
5689 /* Line information for functions in separate sections; each one gets its
5691 typedef struct GTY(()) dw_separate_line_info_struct
{
5692 unsigned long dw_file_num
;
5693 unsigned long dw_line_num
;
5694 unsigned long function
;
5696 dw_separate_line_info_entry
;
5698 /* Each DIE attribute has a field specifying the attribute kind,
5699 a link to the next attribute in the chain, and an attribute value.
5700 Attributes are typically linked below the DIE they modify. */
5702 typedef struct GTY(()) dw_attr_struct
{
5703 enum dwarf_attribute dw_attr
;
5704 dw_val_node dw_attr_val
;
5708 DEF_VEC_O(dw_attr_node
);
5709 DEF_VEC_ALLOC_O(dw_attr_node
,gc
);
5711 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5712 The children of each node form a circular list linked by
5713 die_sib. die_child points to the node *before* the "first" child node. */
5715 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
5716 union die_symbol_or_type_node
5718 char * GTY ((tag ("0"))) die_symbol
;
5719 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
5721 GTY ((desc ("dwarf_version >= 4"))) die_id
;
5722 VEC(dw_attr_node
,gc
) * die_attr
;
5723 dw_die_ref die_parent
;
5724 dw_die_ref die_child
;
5726 dw_die_ref die_definition
; /* ref from a specification to its definition */
5727 dw_offset die_offset
;
5728 unsigned long die_abbrev
;
5730 /* Die is used and must not be pruned as unused. */
5731 int die_perennial_p
;
5732 unsigned int decl_id
;
5733 enum dwarf_tag die_tag
;
5737 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5738 #define FOR_EACH_CHILD(die, c, expr) do { \
5739 c = die->die_child; \
5743 } while (c != die->die_child); \
5746 /* The pubname structure */
5748 typedef struct GTY(()) pubname_struct
{
5754 DEF_VEC_O(pubname_entry
);
5755 DEF_VEC_ALLOC_O(pubname_entry
, gc
);
5757 struct GTY(()) dw_ranges_struct
{
5758 /* If this is positive, it's a block number, otherwise it's a
5759 bitwise-negated index into dw_ranges_by_label. */
5763 struct GTY(()) dw_ranges_by_label_struct
{
5768 /* The comdat type node structure. */
5769 typedef struct GTY(()) comdat_type_struct
5771 dw_die_ref root_die
;
5772 dw_die_ref type_die
;
5773 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
5774 struct comdat_type_struct
*next
;
5778 /* The limbo die list structure. */
5779 typedef struct GTY(()) limbo_die_struct
{
5782 struct limbo_die_struct
*next
;
5786 typedef struct GTY(()) skeleton_chain_struct
5790 struct skeleton_chain_struct
*parent
;
5792 skeleton_chain_node
;
5794 /* How to start an assembler comment. */
5795 #ifndef ASM_COMMENT_START
5796 #define ASM_COMMENT_START ";#"
5799 /* Define a macro which returns nonzero for a TYPE_DECL which was
5800 implicitly generated for a tagged type.
5802 Note that unlike the gcc front end (which generates a NULL named
5803 TYPE_DECL node for each complete tagged type, each array type, and
5804 each function type node created) the g++ front end generates a
5805 _named_ TYPE_DECL node for each tagged type node created.
5806 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
5807 generate a DW_TAG_typedef DIE for them. */
5809 #define TYPE_DECL_IS_STUB(decl) \
5810 (DECL_NAME (decl) == NULL_TREE \
5811 || (DECL_ARTIFICIAL (decl) \
5812 && is_tagged_type (TREE_TYPE (decl)) \
5813 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
5814 /* This is necessary for stub decls that \
5815 appear in nested inline functions. */ \
5816 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
5817 && (decl_ultimate_origin (decl) \
5818 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
5820 /* Information concerning the compilation unit's programming
5821 language, and compiler version. */
5823 /* Fixed size portion of the DWARF compilation unit header. */
5824 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
5825 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
5827 /* Fixed size portion of the DWARF comdat type unit header. */
5828 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
5829 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
5830 + DWARF_OFFSET_SIZE)
5832 /* Fixed size portion of public names info. */
5833 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
5835 /* Fixed size portion of the address range info. */
5836 #define DWARF_ARANGES_HEADER_SIZE \
5837 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5838 DWARF2_ADDR_SIZE * 2) \
5839 - DWARF_INITIAL_LENGTH_SIZE)
5841 /* Size of padding portion in the address range info. It must be
5842 aligned to twice the pointer size. */
5843 #define DWARF_ARANGES_PAD_SIZE \
5844 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5845 DWARF2_ADDR_SIZE * 2) \
5846 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
5848 /* Use assembler line directives if available. */
5849 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
5850 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
5851 #define DWARF2_ASM_LINE_DEBUG_INFO 1
5853 #define DWARF2_ASM_LINE_DEBUG_INFO 0
5857 /* Minimum line offset in a special line info. opcode.
5858 This value was chosen to give a reasonable range of values. */
5859 #define DWARF_LINE_BASE -10
5861 /* First special line opcode - leave room for the standard opcodes. */
5862 #define DWARF_LINE_OPCODE_BASE 10
5864 /* Range of line offsets in a special line info. opcode. */
5865 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
5867 /* Flag that indicates the initial value of the is_stmt_start flag.
5868 In the present implementation, we do not mark any lines as
5869 the beginning of a source statement, because that information
5870 is not made available by the GCC front-end. */
5871 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
5873 /* Maximum number of operations per instruction bundle. */
5874 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
5875 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
5878 /* This location is used by calc_die_sizes() to keep track
5879 the offset of each DIE within the .debug_info section. */
5880 static unsigned long next_die_offset
;
5882 /* Record the root of the DIE's built for the current compilation unit. */
5883 static GTY(()) dw_die_ref single_comp_unit_die
;
5885 /* A list of type DIEs that have been separated into comdat sections. */
5886 static GTY(()) comdat_type_node
*comdat_type_list
;
5888 /* A list of DIEs with a NULL parent waiting to be relocated. */
5889 static GTY(()) limbo_die_node
*limbo_die_list
;
5891 /* A list of DIEs for which we may have to generate
5892 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
5893 static GTY(()) limbo_die_node
*deferred_asm_name
;
5895 /* Filenames referenced by this compilation unit. */
5896 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
5898 /* A hash table of references to DIE's that describe declarations.
5899 The key is a DECL_UID() which is a unique number identifying each decl. */
5900 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
5902 /* A hash table of references to DIE's that describe COMMON blocks.
5903 The key is DECL_UID() ^ die_parent. */
5904 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
5906 typedef struct GTY(()) die_arg_entry_struct
{
5911 DEF_VEC_O(die_arg_entry
);
5912 DEF_VEC_ALLOC_O(die_arg_entry
,gc
);
5914 /* Node of the variable location list. */
5915 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
5916 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
5917 EXPR_LIST chain. For small bitsizes, bitsize is encoded
5918 in mode of the EXPR_LIST node and first EXPR_LIST operand
5919 is either NOTE_INSN_VAR_LOCATION for a piece with a known
5920 location or NULL for padding. For larger bitsizes,
5921 mode is 0 and first operand is a CONCAT with bitsize
5922 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
5923 NULL as second operand. */
5925 const char * GTY (()) label
;
5926 struct var_loc_node
* GTY (()) next
;
5929 /* Variable location list. */
5930 struct GTY (()) var_loc_list_def
{
5931 struct var_loc_node
* GTY (()) first
;
5933 /* Pointer to the last but one or last element of the
5934 chained list. If the list is empty, both first and
5935 last are NULL, if the list contains just one node
5936 or the last node certainly is not redundant, it points
5937 to the last node, otherwise points to the last but one.
5938 Do not mark it for GC because it is marked through the chain. */
5939 struct var_loc_node
* GTY ((skip ("%h"))) last
;
5941 /* DECL_UID of the variable decl. */
5942 unsigned int decl_id
;
5944 typedef struct var_loc_list_def var_loc_list
;
5947 /* Table of decl location linked lists. */
5948 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
5950 /* A pointer to the base of a list of references to DIE's that
5951 are uniquely identified by their tag, presence/absence of
5952 children DIE's, and list of attribute/value pairs. */
5953 static GTY((length ("abbrev_die_table_allocated")))
5954 dw_die_ref
*abbrev_die_table
;
5956 /* Number of elements currently allocated for abbrev_die_table. */
5957 static GTY(()) unsigned abbrev_die_table_allocated
;
5959 /* Number of elements in type_die_table currently in use. */
5960 static GTY(()) unsigned abbrev_die_table_in_use
;
5962 /* Size (in elements) of increments by which we may expand the
5963 abbrev_die_table. */
5964 #define ABBREV_DIE_TABLE_INCREMENT 256
5966 /* A pointer to the base of a table that contains line information
5967 for each source code line in .text in the compilation unit. */
5968 static GTY((length ("line_info_table_allocated")))
5969 dw_line_info_ref line_info_table
;
5971 /* Number of elements currently allocated for line_info_table. */
5972 static GTY(()) unsigned line_info_table_allocated
;
5974 /* Number of elements in line_info_table currently in use. */
5975 static GTY(()) unsigned line_info_table_in_use
;
5977 /* A pointer to the base of a table that contains line information
5978 for each source code line outside of .text in the compilation unit. */
5979 static GTY ((length ("separate_line_info_table_allocated")))
5980 dw_separate_line_info_ref separate_line_info_table
;
5982 /* Number of elements currently allocated for separate_line_info_table. */
5983 static GTY(()) unsigned separate_line_info_table_allocated
;
5985 /* Number of elements in separate_line_info_table currently in use. */
5986 static GTY(()) unsigned separate_line_info_table_in_use
;
5988 /* Size (in elements) of increments by which we may expand the
5990 #define LINE_INFO_TABLE_INCREMENT 1024
5992 /* A pointer to the base of a table that contains a list of publicly
5993 accessible names. */
5994 static GTY (()) VEC (pubname_entry
, gc
) * pubname_table
;
5996 /* A pointer to the base of a table that contains a list of publicly
5997 accessible types. */
5998 static GTY (()) VEC (pubname_entry
, gc
) * pubtype_table
;
6000 /* Array of dies for which we should generate .debug_arange info. */
6001 static GTY((length ("arange_table_allocated"))) dw_die_ref
*arange_table
;
6003 /* Number of elements currently allocated for arange_table. */
6004 static GTY(()) unsigned arange_table_allocated
;
6006 /* Number of elements in arange_table currently in use. */
6007 static GTY(()) unsigned arange_table_in_use
;
6009 /* Size (in elements) of increments by which we may expand the
6011 #define ARANGE_TABLE_INCREMENT 64
6013 /* Array of dies for which we should generate .debug_ranges info. */
6014 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
6016 /* Number of elements currently allocated for ranges_table. */
6017 static GTY(()) unsigned ranges_table_allocated
;
6019 /* Number of elements in ranges_table currently in use. */
6020 static GTY(()) unsigned ranges_table_in_use
;
6022 /* Array of pairs of labels referenced in ranges_table. */
6023 static GTY ((length ("ranges_by_label_allocated")))
6024 dw_ranges_by_label_ref ranges_by_label
;
6026 /* Number of elements currently allocated for ranges_by_label. */
6027 static GTY(()) unsigned ranges_by_label_allocated
;
6029 /* Number of elements in ranges_by_label currently in use. */
6030 static GTY(()) unsigned ranges_by_label_in_use
;
6032 /* Size (in elements) of increments by which we may expand the
6034 #define RANGES_TABLE_INCREMENT 64
6036 /* Whether we have location lists that need outputting */
6037 static GTY(()) bool have_location_lists
;
6039 /* Unique label counter. */
6040 static GTY(()) unsigned int loclabel_num
;
6042 /* Unique label counter for point-of-call tables. */
6043 static GTY(()) unsigned int poc_label_num
;
6045 /* The direct call table structure. */
6047 typedef struct GTY(()) dcall_struct
{
6048 unsigned int poc_label_num
;
6050 dw_die_ref targ_die
;
6054 DEF_VEC_O(dcall_entry
);
6055 DEF_VEC_ALLOC_O(dcall_entry
, gc
);
6057 /* The virtual call table structure. */
6059 typedef struct GTY(()) vcall_struct
{
6060 unsigned int poc_label_num
;
6061 unsigned int vtable_slot
;
6065 DEF_VEC_O(vcall_entry
);
6066 DEF_VEC_ALLOC_O(vcall_entry
, gc
);
6068 /* Pointers to the direct and virtual call tables. */
6069 static GTY (()) VEC (dcall_entry
, gc
) * dcall_table
= NULL
;
6070 static GTY (()) VEC (vcall_entry
, gc
) * vcall_table
= NULL
;
6072 /* A hash table to map INSN_UIDs to vtable slot indexes. */
6074 struct GTY (()) vcall_insn
{
6076 unsigned int vtable_slot
;
6079 static GTY ((param_is (struct vcall_insn
))) htab_t vcall_insn_table
;
6081 /* Record whether the function being analyzed contains inlined functions. */
6082 static int current_function_has_inlines
;
6084 /* The last file entry emitted by maybe_emit_file(). */
6085 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
6087 /* Number of internal labels generated by gen_internal_sym(). */
6088 static GTY(()) int label_num
;
6090 /* Cached result of previous call to lookup_filename. */
6091 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
6093 static GTY(()) VEC(die_arg_entry
,gc
) *tmpl_value_parm_die_table
;
6095 /* Offset from the "steady-state frame pointer" to the frame base,
6096 within the current function. */
6097 static HOST_WIDE_INT frame_pointer_fb_offset
;
6099 /* Forward declarations for functions defined in this file. */
6101 static int is_pseudo_reg (const_rtx
);
6102 static tree
type_main_variant (tree
);
6103 static int is_tagged_type (const_tree
);
6104 static const char *dwarf_tag_name (unsigned);
6105 static const char *dwarf_attr_name (unsigned);
6106 static const char *dwarf_form_name (unsigned);
6107 static tree
decl_ultimate_origin (const_tree
);
6108 static tree
decl_class_context (tree
);
6109 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
6110 static inline enum dw_val_class
AT_class (dw_attr_ref
);
6111 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
6112 static inline unsigned AT_flag (dw_attr_ref
);
6113 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
6114 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
6115 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
6116 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
6117 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
6118 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
6119 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
6120 unsigned int, unsigned char *);
6121 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
6122 static hashval_t
debug_str_do_hash (const void *);
6123 static int debug_str_eq (const void *, const void *);
6124 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
6125 static inline const char *AT_string (dw_attr_ref
);
6126 static enum dwarf_form
AT_string_form (dw_attr_ref
);
6127 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
6128 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
6129 static inline dw_die_ref
AT_ref (dw_attr_ref
);
6130 static inline int AT_ref_external (dw_attr_ref
);
6131 static inline void set_AT_ref_external (dw_attr_ref
, int);
6132 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
6133 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
6134 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
6135 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
6137 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
6138 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
6139 static inline rtx
AT_addr (dw_attr_ref
);
6140 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
6141 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
6142 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
6143 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
6144 unsigned HOST_WIDE_INT
);
6145 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
6147 static inline const char *AT_lbl (dw_attr_ref
);
6148 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
6149 static const char *get_AT_low_pc (dw_die_ref
);
6150 static const char *get_AT_hi_pc (dw_die_ref
);
6151 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
6152 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
6153 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
6154 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
6155 static bool is_cxx (void);
6156 static bool is_fortran (void);
6157 static bool is_ada (void);
6158 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
6159 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
6160 static void add_child_die (dw_die_ref
, dw_die_ref
);
6161 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
6162 static dw_die_ref
lookup_type_die (tree
);
6163 static void equate_type_number_to_die (tree
, dw_die_ref
);
6164 static hashval_t
decl_die_table_hash (const void *);
6165 static int decl_die_table_eq (const void *, const void *);
6166 static dw_die_ref
lookup_decl_die (tree
);
6167 static hashval_t
common_block_die_table_hash (const void *);
6168 static int common_block_die_table_eq (const void *, const void *);
6169 static hashval_t
decl_loc_table_hash (const void *);
6170 static int decl_loc_table_eq (const void *, const void *);
6171 static var_loc_list
*lookup_decl_loc (const_tree
);
6172 static void equate_decl_number_to_die (tree
, dw_die_ref
);
6173 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
6174 static void print_spaces (FILE *);
6175 static void print_die (dw_die_ref
, FILE *);
6176 static void print_dwarf_line_table (FILE *);
6177 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
6178 static dw_die_ref
pop_compile_unit (dw_die_ref
);
6179 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
6180 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
6181 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
6182 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
6183 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
6184 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
6185 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
6186 struct md5_ctx
*, int *);
6187 struct checksum_attributes
;
6188 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
6189 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
6190 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
6191 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
6192 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
6193 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
6194 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
6195 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
6196 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
6197 static void compute_section_prefix (dw_die_ref
);
6198 static int is_type_die (dw_die_ref
);
6199 static int is_comdat_die (dw_die_ref
);
6200 static int is_symbol_die (dw_die_ref
);
6201 static void assign_symbol_names (dw_die_ref
);
6202 static void break_out_includes (dw_die_ref
);
6203 static int is_declaration_die (dw_die_ref
);
6204 static int should_move_die_to_comdat (dw_die_ref
);
6205 static dw_die_ref
clone_as_declaration (dw_die_ref
);
6206 static dw_die_ref
clone_die (dw_die_ref
);
6207 static dw_die_ref
clone_tree (dw_die_ref
);
6208 static void copy_declaration_context (dw_die_ref
, dw_die_ref
);
6209 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
6210 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
6211 static dw_die_ref
generate_skeleton (dw_die_ref
);
6212 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
6214 static void break_out_comdat_types (dw_die_ref
);
6215 static dw_die_ref
copy_ancestor_tree (dw_die_ref
, dw_die_ref
, htab_t
);
6216 static void copy_decls_walk (dw_die_ref
, dw_die_ref
, htab_t
);
6217 static void copy_decls_for_unworthy_types (dw_die_ref
);
6219 static hashval_t
htab_cu_hash (const void *);
6220 static int htab_cu_eq (const void *, const void *);
6221 static void htab_cu_del (void *);
6222 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
6223 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
6224 static void add_sibling_attributes (dw_die_ref
);
6225 static void build_abbrev_table (dw_die_ref
);
6226 static void output_location_lists (dw_die_ref
);
6227 static int constant_size (unsigned HOST_WIDE_INT
);
6228 static unsigned long size_of_die (dw_die_ref
);
6229 static void calc_die_sizes (dw_die_ref
);
6230 static void mark_dies (dw_die_ref
);
6231 static void unmark_dies (dw_die_ref
);
6232 static void unmark_all_dies (dw_die_ref
);
6233 static unsigned long size_of_pubnames (VEC (pubname_entry
,gc
) *);
6234 static unsigned long size_of_aranges (void);
6235 static enum dwarf_form
value_format (dw_attr_ref
);
6236 static void output_value_format (dw_attr_ref
);
6237 static void output_abbrev_section (void);
6238 static void output_die_symbol (dw_die_ref
);
6239 static void output_die (dw_die_ref
);
6240 static void output_compilation_unit_header (void);
6241 static void output_comp_unit (dw_die_ref
, int);
6242 static void output_comdat_type_unit (comdat_type_node
*);
6243 static const char *dwarf2_name (tree
, int);
6244 static void add_pubname (tree
, dw_die_ref
);
6245 static void add_pubname_string (const char *, dw_die_ref
);
6246 static void add_pubtype (tree
, dw_die_ref
);
6247 static void output_pubnames (VEC (pubname_entry
,gc
) *);
6248 static void add_arange (tree
, dw_die_ref
);
6249 static void output_aranges (void);
6250 static unsigned int add_ranges_num (int);
6251 static unsigned int add_ranges (const_tree
);
6252 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
6254 static void output_ranges (void);
6255 static void output_line_info (void);
6256 static void output_file_names (void);
6257 static dw_die_ref
base_type_die (tree
);
6258 static int is_base_type (tree
);
6259 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
6260 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
6261 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
6262 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
6263 static int type_is_enum (const_tree
);
6264 static unsigned int dbx_reg_number (const_rtx
);
6265 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
6266 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
6267 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
6268 enum var_init_status
);
6269 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
6270 enum var_init_status
);
6271 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
6272 enum var_init_status
);
6273 static int is_based_loc (const_rtx
);
6274 static int resolve_one_addr (rtx
*, void *);
6275 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
6276 enum var_init_status
);
6277 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
6278 enum var_init_status
);
6279 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
6280 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
6281 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
6282 static tree
field_type (const_tree
);
6283 static unsigned int simple_type_align_in_bits (const_tree
);
6284 static unsigned int simple_decl_align_in_bits (const_tree
);
6285 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
6286 static HOST_WIDE_INT
field_byte_offset (const_tree
);
6287 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
6289 static void add_data_member_location_attribute (dw_die_ref
, tree
);
6290 static bool add_const_value_attribute (dw_die_ref
, rtx
);
6291 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
6292 static void insert_double (double_int
, unsigned char *);
6293 static void insert_float (const_rtx
, unsigned char *);
6294 static rtx
rtl_for_decl_location (tree
);
6295 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
,
6296 enum dwarf_attribute
);
6297 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
6298 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
6299 static void add_name_attribute (dw_die_ref
, const char *);
6300 static void add_comp_dir_attribute (dw_die_ref
);
6301 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
6302 static void add_subscript_info (dw_die_ref
, tree
, bool);
6303 static void add_byte_size_attribute (dw_die_ref
, tree
);
6304 static void add_bit_offset_attribute (dw_die_ref
, tree
);
6305 static void add_bit_size_attribute (dw_die_ref
, tree
);
6306 static void add_prototyped_attribute (dw_die_ref
, tree
);
6307 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
6308 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
6309 static void add_src_coords_attributes (dw_die_ref
, tree
);
6310 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
6311 static void push_decl_scope (tree
);
6312 static void pop_decl_scope (void);
6313 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
6314 static inline int local_scope_p (dw_die_ref
);
6315 static inline int class_scope_p (dw_die_ref
);
6316 static inline int class_or_namespace_scope_p (dw_die_ref
);
6317 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
6318 static void add_calling_convention_attribute (dw_die_ref
, tree
);
6319 static const char *type_tag (const_tree
);
6320 static tree
member_declared_type (const_tree
);
6322 static const char *decl_start_label (tree
);
6324 static void gen_array_type_die (tree
, dw_die_ref
);
6325 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
6327 static void gen_entry_point_die (tree
, dw_die_ref
);
6329 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
6330 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
6331 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
6332 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
6333 static void gen_formal_types_die (tree
, dw_die_ref
);
6334 static void gen_subprogram_die (tree
, dw_die_ref
);
6335 static void gen_variable_die (tree
, tree
, dw_die_ref
);
6336 static void gen_const_die (tree
, dw_die_ref
);
6337 static void gen_label_die (tree
, dw_die_ref
);
6338 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
6339 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
6340 static void gen_field_die (tree
, dw_die_ref
);
6341 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
6342 static dw_die_ref
gen_compile_unit_die (const char *);
6343 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
6344 static void gen_member_die (tree
, dw_die_ref
);
6345 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
6346 enum debug_info_usage
);
6347 static void gen_subroutine_type_die (tree
, dw_die_ref
);
6348 static void gen_typedef_die (tree
, dw_die_ref
);
6349 static void gen_type_die (tree
, dw_die_ref
);
6350 static void gen_block_die (tree
, dw_die_ref
, int);
6351 static void decls_for_scope (tree
, dw_die_ref
, int);
6352 static int is_redundant_typedef (const_tree
);
6353 static bool is_naming_typedef_decl (const_tree
);
6354 static inline dw_die_ref
get_context_die (tree
);
6355 static void gen_namespace_die (tree
, dw_die_ref
);
6356 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
6357 static dw_die_ref
force_decl_die (tree
);
6358 static dw_die_ref
force_type_die (tree
);
6359 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
6360 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
6361 static struct dwarf_file_data
* lookup_filename (const char *);
6362 static void retry_incomplete_types (void);
6363 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
6364 static void gen_generic_params_dies (tree
);
6365 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
6366 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
6367 static void splice_child_die (dw_die_ref
, dw_die_ref
);
6368 static int file_info_cmp (const void *, const void *);
6369 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
6370 const char *, const char *);
6371 static void output_loc_list (dw_loc_list_ref
);
6372 static char *gen_internal_sym (const char *);
6374 static void prune_unmark_dies (dw_die_ref
);
6375 static void prune_unused_types_mark (dw_die_ref
, int);
6376 static void prune_unused_types_walk (dw_die_ref
);
6377 static void prune_unused_types_walk_attribs (dw_die_ref
);
6378 static void prune_unused_types_prune (dw_die_ref
);
6379 static void prune_unused_types (void);
6380 static int maybe_emit_file (struct dwarf_file_data
*fd
);
6381 static inline const char *AT_vms_delta1 (dw_attr_ref
);
6382 static inline const char *AT_vms_delta2 (dw_attr_ref
);
6383 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
6384 const char *, const char *);
6385 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
6386 static void gen_remaining_tmpl_value_param_die_attribute (void);
6388 /* Section names used to hold DWARF debugging information. */
6389 #ifndef DEBUG_INFO_SECTION
6390 #define DEBUG_INFO_SECTION ".debug_info"
6392 #ifndef DEBUG_ABBREV_SECTION
6393 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6395 #ifndef DEBUG_ARANGES_SECTION
6396 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6398 #ifndef DEBUG_MACINFO_SECTION
6399 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6401 #ifndef DEBUG_LINE_SECTION
6402 #define DEBUG_LINE_SECTION ".debug_line"
6404 #ifndef DEBUG_LOC_SECTION
6405 #define DEBUG_LOC_SECTION ".debug_loc"
6407 #ifndef DEBUG_PUBNAMES_SECTION
6408 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6410 #ifndef DEBUG_PUBTYPES_SECTION
6411 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6413 #ifndef DEBUG_DCALL_SECTION
6414 #define DEBUG_DCALL_SECTION ".debug_dcall"
6416 #ifndef DEBUG_VCALL_SECTION
6417 #define DEBUG_VCALL_SECTION ".debug_vcall"
6419 #ifndef DEBUG_STR_SECTION
6420 #define DEBUG_STR_SECTION ".debug_str"
6422 #ifndef DEBUG_RANGES_SECTION
6423 #define DEBUG_RANGES_SECTION ".debug_ranges"
6426 /* Standard ELF section names for compiled code and data. */
6427 #ifndef TEXT_SECTION_NAME
6428 #define TEXT_SECTION_NAME ".text"
6431 /* Section flags for .debug_str section. */
6432 #define DEBUG_STR_SECTION_FLAGS \
6433 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6434 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6437 /* Labels we insert at beginning sections we can reference instead of
6438 the section names themselves. */
6440 #ifndef TEXT_SECTION_LABEL
6441 #define TEXT_SECTION_LABEL "Ltext"
6443 #ifndef COLD_TEXT_SECTION_LABEL
6444 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6446 #ifndef DEBUG_LINE_SECTION_LABEL
6447 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6449 #ifndef DEBUG_INFO_SECTION_LABEL
6450 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6452 #ifndef DEBUG_ABBREV_SECTION_LABEL
6453 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6455 #ifndef DEBUG_LOC_SECTION_LABEL
6456 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6458 #ifndef DEBUG_RANGES_SECTION_LABEL
6459 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6461 #ifndef DEBUG_MACINFO_SECTION_LABEL
6462 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6466 /* Definitions of defaults for formats and names of various special
6467 (artificial) labels which may be generated within this file (when the -g
6468 options is used and DWARF2_DEBUGGING_INFO is in effect.
6469 If necessary, these may be overridden from within the tm.h file, but
6470 typically, overriding these defaults is unnecessary. */
6472 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6473 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6474 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6475 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6476 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6477 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6478 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6479 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6480 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6481 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
6483 #ifndef TEXT_END_LABEL
6484 #define TEXT_END_LABEL "Letext"
6486 #ifndef COLD_END_LABEL
6487 #define COLD_END_LABEL "Letext_cold"
6489 #ifndef BLOCK_BEGIN_LABEL
6490 #define BLOCK_BEGIN_LABEL "LBB"
6492 #ifndef BLOCK_END_LABEL
6493 #define BLOCK_END_LABEL "LBE"
6495 #ifndef LINE_CODE_LABEL
6496 #define LINE_CODE_LABEL "LM"
6498 #ifndef SEPARATE_LINE_CODE_LABEL
6499 #define SEPARATE_LINE_CODE_LABEL "LSM"
6503 /* Return the root of the DIE's built for the current compilation unit. */
6505 comp_unit_die (void)
6507 if (!single_comp_unit_die
)
6508 single_comp_unit_die
= gen_compile_unit_die (NULL
);
6509 return single_comp_unit_die
;
6512 /* We allow a language front-end to designate a function that is to be
6513 called to "demangle" any name before it is put into a DIE. */
6515 static const char *(*demangle_name_func
) (const char *);
6518 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
6520 demangle_name_func
= func
;
6523 /* Test if rtl node points to a pseudo register. */
6526 is_pseudo_reg (const_rtx rtl
)
6528 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
6529 || (GET_CODE (rtl
) == SUBREG
6530 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
6533 /* Return a reference to a type, with its const and volatile qualifiers
6537 type_main_variant (tree type
)
6539 type
= TYPE_MAIN_VARIANT (type
);
6541 /* ??? There really should be only one main variant among any group of
6542 variants of a given type (and all of the MAIN_VARIANT values for all
6543 members of the group should point to that one type) but sometimes the C
6544 front-end messes this up for array types, so we work around that bug
6546 if (TREE_CODE (type
) == ARRAY_TYPE
)
6547 while (type
!= TYPE_MAIN_VARIANT (type
))
6548 type
= TYPE_MAIN_VARIANT (type
);
6553 /* Return nonzero if the given type node represents a tagged type. */
6556 is_tagged_type (const_tree type
)
6558 enum tree_code code
= TREE_CODE (type
);
6560 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
6561 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
6564 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
6567 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
6569 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
6572 /* Convert a DIE tag into its string name. */
6575 dwarf_tag_name (unsigned int tag
)
6579 case DW_TAG_padding
:
6580 return "DW_TAG_padding";
6581 case DW_TAG_array_type
:
6582 return "DW_TAG_array_type";
6583 case DW_TAG_class_type
:
6584 return "DW_TAG_class_type";
6585 case DW_TAG_entry_point
:
6586 return "DW_TAG_entry_point";
6587 case DW_TAG_enumeration_type
:
6588 return "DW_TAG_enumeration_type";
6589 case DW_TAG_formal_parameter
:
6590 return "DW_TAG_formal_parameter";
6591 case DW_TAG_imported_declaration
:
6592 return "DW_TAG_imported_declaration";
6594 return "DW_TAG_label";
6595 case DW_TAG_lexical_block
:
6596 return "DW_TAG_lexical_block";
6598 return "DW_TAG_member";
6599 case DW_TAG_pointer_type
:
6600 return "DW_TAG_pointer_type";
6601 case DW_TAG_reference_type
:
6602 return "DW_TAG_reference_type";
6603 case DW_TAG_compile_unit
:
6604 return "DW_TAG_compile_unit";
6605 case DW_TAG_string_type
:
6606 return "DW_TAG_string_type";
6607 case DW_TAG_structure_type
:
6608 return "DW_TAG_structure_type";
6609 case DW_TAG_subroutine_type
:
6610 return "DW_TAG_subroutine_type";
6611 case DW_TAG_typedef
:
6612 return "DW_TAG_typedef";
6613 case DW_TAG_union_type
:
6614 return "DW_TAG_union_type";
6615 case DW_TAG_unspecified_parameters
:
6616 return "DW_TAG_unspecified_parameters";
6617 case DW_TAG_variant
:
6618 return "DW_TAG_variant";
6619 case DW_TAG_common_block
:
6620 return "DW_TAG_common_block";
6621 case DW_TAG_common_inclusion
:
6622 return "DW_TAG_common_inclusion";
6623 case DW_TAG_inheritance
:
6624 return "DW_TAG_inheritance";
6625 case DW_TAG_inlined_subroutine
:
6626 return "DW_TAG_inlined_subroutine";
6628 return "DW_TAG_module";
6629 case DW_TAG_ptr_to_member_type
:
6630 return "DW_TAG_ptr_to_member_type";
6631 case DW_TAG_set_type
:
6632 return "DW_TAG_set_type";
6633 case DW_TAG_subrange_type
:
6634 return "DW_TAG_subrange_type";
6635 case DW_TAG_with_stmt
:
6636 return "DW_TAG_with_stmt";
6637 case DW_TAG_access_declaration
:
6638 return "DW_TAG_access_declaration";
6639 case DW_TAG_base_type
:
6640 return "DW_TAG_base_type";
6641 case DW_TAG_catch_block
:
6642 return "DW_TAG_catch_block";
6643 case DW_TAG_const_type
:
6644 return "DW_TAG_const_type";
6645 case DW_TAG_constant
:
6646 return "DW_TAG_constant";
6647 case DW_TAG_enumerator
:
6648 return "DW_TAG_enumerator";
6649 case DW_TAG_file_type
:
6650 return "DW_TAG_file_type";
6652 return "DW_TAG_friend";
6653 case DW_TAG_namelist
:
6654 return "DW_TAG_namelist";
6655 case DW_TAG_namelist_item
:
6656 return "DW_TAG_namelist_item";
6657 case DW_TAG_packed_type
:
6658 return "DW_TAG_packed_type";
6659 case DW_TAG_subprogram
:
6660 return "DW_TAG_subprogram";
6661 case DW_TAG_template_type_param
:
6662 return "DW_TAG_template_type_param";
6663 case DW_TAG_template_value_param
:
6664 return "DW_TAG_template_value_param";
6665 case DW_TAG_thrown_type
:
6666 return "DW_TAG_thrown_type";
6667 case DW_TAG_try_block
:
6668 return "DW_TAG_try_block";
6669 case DW_TAG_variant_part
:
6670 return "DW_TAG_variant_part";
6671 case DW_TAG_variable
:
6672 return "DW_TAG_variable";
6673 case DW_TAG_volatile_type
:
6674 return "DW_TAG_volatile_type";
6675 case DW_TAG_dwarf_procedure
:
6676 return "DW_TAG_dwarf_procedure";
6677 case DW_TAG_restrict_type
:
6678 return "DW_TAG_restrict_type";
6679 case DW_TAG_interface_type
:
6680 return "DW_TAG_interface_type";
6681 case DW_TAG_namespace
:
6682 return "DW_TAG_namespace";
6683 case DW_TAG_imported_module
:
6684 return "DW_TAG_imported_module";
6685 case DW_TAG_unspecified_type
:
6686 return "DW_TAG_unspecified_type";
6687 case DW_TAG_partial_unit
:
6688 return "DW_TAG_partial_unit";
6689 case DW_TAG_imported_unit
:
6690 return "DW_TAG_imported_unit";
6691 case DW_TAG_condition
:
6692 return "DW_TAG_condition";
6693 case DW_TAG_shared_type
:
6694 return "DW_TAG_shared_type";
6695 case DW_TAG_type_unit
:
6696 return "DW_TAG_type_unit";
6697 case DW_TAG_rvalue_reference_type
:
6698 return "DW_TAG_rvalue_reference_type";
6699 case DW_TAG_template_alias
:
6700 return "DW_TAG_template_alias";
6701 case DW_TAG_GNU_template_parameter_pack
:
6702 return "DW_TAG_GNU_template_parameter_pack";
6703 case DW_TAG_GNU_formal_parameter_pack
:
6704 return "DW_TAG_GNU_formal_parameter_pack";
6705 case DW_TAG_MIPS_loop
:
6706 return "DW_TAG_MIPS_loop";
6707 case DW_TAG_format_label
:
6708 return "DW_TAG_format_label";
6709 case DW_TAG_function_template
:
6710 return "DW_TAG_function_template";
6711 case DW_TAG_class_template
:
6712 return "DW_TAG_class_template";
6713 case DW_TAG_GNU_BINCL
:
6714 return "DW_TAG_GNU_BINCL";
6715 case DW_TAG_GNU_EINCL
:
6716 return "DW_TAG_GNU_EINCL";
6717 case DW_TAG_GNU_template_template_param
:
6718 return "DW_TAG_GNU_template_template_param";
6720 return "DW_TAG_<unknown>";
6724 /* Convert a DWARF attribute code into its string name. */
6727 dwarf_attr_name (unsigned int attr
)
6732 return "DW_AT_sibling";
6733 case DW_AT_location
:
6734 return "DW_AT_location";
6736 return "DW_AT_name";
6737 case DW_AT_ordering
:
6738 return "DW_AT_ordering";
6739 case DW_AT_subscr_data
:
6740 return "DW_AT_subscr_data";
6741 case DW_AT_byte_size
:
6742 return "DW_AT_byte_size";
6743 case DW_AT_bit_offset
:
6744 return "DW_AT_bit_offset";
6745 case DW_AT_bit_size
:
6746 return "DW_AT_bit_size";
6747 case DW_AT_element_list
:
6748 return "DW_AT_element_list";
6749 case DW_AT_stmt_list
:
6750 return "DW_AT_stmt_list";
6752 return "DW_AT_low_pc";
6754 return "DW_AT_high_pc";
6755 case DW_AT_language
:
6756 return "DW_AT_language";
6758 return "DW_AT_member";
6760 return "DW_AT_discr";
6761 case DW_AT_discr_value
:
6762 return "DW_AT_discr_value";
6763 case DW_AT_visibility
:
6764 return "DW_AT_visibility";
6766 return "DW_AT_import";
6767 case DW_AT_string_length
:
6768 return "DW_AT_string_length";
6769 case DW_AT_common_reference
:
6770 return "DW_AT_common_reference";
6771 case DW_AT_comp_dir
:
6772 return "DW_AT_comp_dir";
6773 case DW_AT_const_value
:
6774 return "DW_AT_const_value";
6775 case DW_AT_containing_type
:
6776 return "DW_AT_containing_type";
6777 case DW_AT_default_value
:
6778 return "DW_AT_default_value";
6780 return "DW_AT_inline";
6781 case DW_AT_is_optional
:
6782 return "DW_AT_is_optional";
6783 case DW_AT_lower_bound
:
6784 return "DW_AT_lower_bound";
6785 case DW_AT_producer
:
6786 return "DW_AT_producer";
6787 case DW_AT_prototyped
:
6788 return "DW_AT_prototyped";
6789 case DW_AT_return_addr
:
6790 return "DW_AT_return_addr";
6791 case DW_AT_start_scope
:
6792 return "DW_AT_start_scope";
6793 case DW_AT_bit_stride
:
6794 return "DW_AT_bit_stride";
6795 case DW_AT_upper_bound
:
6796 return "DW_AT_upper_bound";
6797 case DW_AT_abstract_origin
:
6798 return "DW_AT_abstract_origin";
6799 case DW_AT_accessibility
:
6800 return "DW_AT_accessibility";
6801 case DW_AT_address_class
:
6802 return "DW_AT_address_class";
6803 case DW_AT_artificial
:
6804 return "DW_AT_artificial";
6805 case DW_AT_base_types
:
6806 return "DW_AT_base_types";
6807 case DW_AT_calling_convention
:
6808 return "DW_AT_calling_convention";
6810 return "DW_AT_count";
6811 case DW_AT_data_member_location
:
6812 return "DW_AT_data_member_location";
6813 case DW_AT_decl_column
:
6814 return "DW_AT_decl_column";
6815 case DW_AT_decl_file
:
6816 return "DW_AT_decl_file";
6817 case DW_AT_decl_line
:
6818 return "DW_AT_decl_line";
6819 case DW_AT_declaration
:
6820 return "DW_AT_declaration";
6821 case DW_AT_discr_list
:
6822 return "DW_AT_discr_list";
6823 case DW_AT_encoding
:
6824 return "DW_AT_encoding";
6825 case DW_AT_external
:
6826 return "DW_AT_external";
6827 case DW_AT_explicit
:
6828 return "DW_AT_explicit";
6829 case DW_AT_frame_base
:
6830 return "DW_AT_frame_base";
6832 return "DW_AT_friend";
6833 case DW_AT_identifier_case
:
6834 return "DW_AT_identifier_case";
6835 case DW_AT_macro_info
:
6836 return "DW_AT_macro_info";
6837 case DW_AT_namelist_items
:
6838 return "DW_AT_namelist_items";
6839 case DW_AT_priority
:
6840 return "DW_AT_priority";
6842 return "DW_AT_segment";
6843 case DW_AT_specification
:
6844 return "DW_AT_specification";
6845 case DW_AT_static_link
:
6846 return "DW_AT_static_link";
6848 return "DW_AT_type";
6849 case DW_AT_use_location
:
6850 return "DW_AT_use_location";
6851 case DW_AT_variable_parameter
:
6852 return "DW_AT_variable_parameter";
6853 case DW_AT_virtuality
:
6854 return "DW_AT_virtuality";
6855 case DW_AT_vtable_elem_location
:
6856 return "DW_AT_vtable_elem_location";
6858 case DW_AT_allocated
:
6859 return "DW_AT_allocated";
6860 case DW_AT_associated
:
6861 return "DW_AT_associated";
6862 case DW_AT_data_location
:
6863 return "DW_AT_data_location";
6864 case DW_AT_byte_stride
:
6865 return "DW_AT_byte_stride";
6866 case DW_AT_entry_pc
:
6867 return "DW_AT_entry_pc";
6868 case DW_AT_use_UTF8
:
6869 return "DW_AT_use_UTF8";
6870 case DW_AT_extension
:
6871 return "DW_AT_extension";
6873 return "DW_AT_ranges";
6874 case DW_AT_trampoline
:
6875 return "DW_AT_trampoline";
6876 case DW_AT_call_column
:
6877 return "DW_AT_call_column";
6878 case DW_AT_call_file
:
6879 return "DW_AT_call_file";
6880 case DW_AT_call_line
:
6881 return "DW_AT_call_line";
6882 case DW_AT_object_pointer
:
6883 return "DW_AT_object_pointer";
6885 case DW_AT_signature
:
6886 return "DW_AT_signature";
6887 case DW_AT_main_subprogram
:
6888 return "DW_AT_main_subprogram";
6889 case DW_AT_data_bit_offset
:
6890 return "DW_AT_data_bit_offset";
6891 case DW_AT_const_expr
:
6892 return "DW_AT_const_expr";
6893 case DW_AT_enum_class
:
6894 return "DW_AT_enum_class";
6895 case DW_AT_linkage_name
:
6896 return "DW_AT_linkage_name";
6898 case DW_AT_MIPS_fde
:
6899 return "DW_AT_MIPS_fde";
6900 case DW_AT_MIPS_loop_begin
:
6901 return "DW_AT_MIPS_loop_begin";
6902 case DW_AT_MIPS_tail_loop_begin
:
6903 return "DW_AT_MIPS_tail_loop_begin";
6904 case DW_AT_MIPS_epilog_begin
:
6905 return "DW_AT_MIPS_epilog_begin";
6906 #if VMS_DEBUGGING_INFO
6907 case DW_AT_HP_prologue
:
6908 return "DW_AT_HP_prologue";
6910 case DW_AT_MIPS_loop_unroll_factor
:
6911 return "DW_AT_MIPS_loop_unroll_factor";
6913 case DW_AT_MIPS_software_pipeline_depth
:
6914 return "DW_AT_MIPS_software_pipeline_depth";
6915 case DW_AT_MIPS_linkage_name
:
6916 return "DW_AT_MIPS_linkage_name";
6917 #if VMS_DEBUGGING_INFO
6918 case DW_AT_HP_epilogue
:
6919 return "DW_AT_HP_epilogue";
6921 case DW_AT_MIPS_stride
:
6922 return "DW_AT_MIPS_stride";
6924 case DW_AT_MIPS_abstract_name
:
6925 return "DW_AT_MIPS_abstract_name";
6926 case DW_AT_MIPS_clone_origin
:
6927 return "DW_AT_MIPS_clone_origin";
6928 case DW_AT_MIPS_has_inlines
:
6929 return "DW_AT_MIPS_has_inlines";
6931 case DW_AT_sf_names
:
6932 return "DW_AT_sf_names";
6933 case DW_AT_src_info
:
6934 return "DW_AT_src_info";
6935 case DW_AT_mac_info
:
6936 return "DW_AT_mac_info";
6937 case DW_AT_src_coords
:
6938 return "DW_AT_src_coords";
6939 case DW_AT_body_begin
:
6940 return "DW_AT_body_begin";
6941 case DW_AT_body_end
:
6942 return "DW_AT_body_end";
6943 case DW_AT_GNU_vector
:
6944 return "DW_AT_GNU_vector";
6945 case DW_AT_GNU_guarded_by
:
6946 return "DW_AT_GNU_guarded_by";
6947 case DW_AT_GNU_pt_guarded_by
:
6948 return "DW_AT_GNU_pt_guarded_by";
6949 case DW_AT_GNU_guarded
:
6950 return "DW_AT_GNU_guarded";
6951 case DW_AT_GNU_pt_guarded
:
6952 return "DW_AT_GNU_pt_guarded";
6953 case DW_AT_GNU_locks_excluded
:
6954 return "DW_AT_GNU_locks_excluded";
6955 case DW_AT_GNU_exclusive_locks_required
:
6956 return "DW_AT_GNU_exclusive_locks_required";
6957 case DW_AT_GNU_shared_locks_required
:
6958 return "DW_AT_GNU_shared_locks_required";
6959 case DW_AT_GNU_odr_signature
:
6960 return "DW_AT_GNU_odr_signature";
6961 case DW_AT_GNU_template_name
:
6962 return "DW_AT_GNU_template_name";
6964 case DW_AT_VMS_rtnbeg_pd_address
:
6965 return "DW_AT_VMS_rtnbeg_pd_address";
6968 return "DW_AT_<unknown>";
6972 /* Convert a DWARF value form code into its string name. */
6975 dwarf_form_name (unsigned int form
)
6980 return "DW_FORM_addr";
6981 case DW_FORM_block2
:
6982 return "DW_FORM_block2";
6983 case DW_FORM_block4
:
6984 return "DW_FORM_block4";
6986 return "DW_FORM_data2";
6988 return "DW_FORM_data4";
6990 return "DW_FORM_data8";
6991 case DW_FORM_string
:
6992 return "DW_FORM_string";
6994 return "DW_FORM_block";
6995 case DW_FORM_block1
:
6996 return "DW_FORM_block1";
6998 return "DW_FORM_data1";
7000 return "DW_FORM_flag";
7002 return "DW_FORM_sdata";
7004 return "DW_FORM_strp";
7006 return "DW_FORM_udata";
7007 case DW_FORM_ref_addr
:
7008 return "DW_FORM_ref_addr";
7010 return "DW_FORM_ref1";
7012 return "DW_FORM_ref2";
7014 return "DW_FORM_ref4";
7016 return "DW_FORM_ref8";
7017 case DW_FORM_ref_udata
:
7018 return "DW_FORM_ref_udata";
7019 case DW_FORM_indirect
:
7020 return "DW_FORM_indirect";
7021 case DW_FORM_sec_offset
:
7022 return "DW_FORM_sec_offset";
7023 case DW_FORM_exprloc
:
7024 return "DW_FORM_exprloc";
7025 case DW_FORM_flag_present
:
7026 return "DW_FORM_flag_present";
7027 case DW_FORM_ref_sig8
:
7028 return "DW_FORM_ref_sig8";
7030 return "DW_FORM_<unknown>";
7034 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
7035 instance of an inlined instance of a decl which is local to an inline
7036 function, so we have to trace all of the way back through the origin chain
7037 to find out what sort of node actually served as the original seed for the
7041 decl_ultimate_origin (const_tree decl
)
7043 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
7046 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
7047 nodes in the function to point to themselves; ignore that if
7048 we're trying to output the abstract instance of this function. */
7049 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
7052 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
7053 most distant ancestor, this should never happen. */
7054 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
7056 return DECL_ABSTRACT_ORIGIN (decl
);
7059 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
7060 of a virtual function may refer to a base class, so we check the 'this'
7064 decl_class_context (tree decl
)
7066 tree context
= NULL_TREE
;
7068 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
7069 context
= DECL_CONTEXT (decl
);
7071 context
= TYPE_MAIN_VARIANT
7072 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
7074 if (context
&& !TYPE_P (context
))
7075 context
= NULL_TREE
;
7080 /* Add an attribute/value pair to a DIE. */
7083 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
7085 /* Maybe this should be an assert? */
7089 if (die
->die_attr
== NULL
)
7090 die
->die_attr
= VEC_alloc (dw_attr_node
, gc
, 1);
7091 VEC_safe_push (dw_attr_node
, gc
, die
->die_attr
, attr
);
7094 static inline enum dw_val_class
7095 AT_class (dw_attr_ref a
)
7097 return a
->dw_attr_val
.val_class
;
7100 /* Add a flag value attribute to a DIE. */
7103 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
7107 attr
.dw_attr
= attr_kind
;
7108 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
7109 attr
.dw_attr_val
.v
.val_flag
= flag
;
7110 add_dwarf_attr (die
, &attr
);
7113 static inline unsigned
7114 AT_flag (dw_attr_ref a
)
7116 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
7117 return a
->dw_attr_val
.v
.val_flag
;
7120 /* Add a signed integer attribute value to a DIE. */
7123 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
7127 attr
.dw_attr
= attr_kind
;
7128 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
7129 attr
.dw_attr_val
.v
.val_int
= int_val
;
7130 add_dwarf_attr (die
, &attr
);
7133 static inline HOST_WIDE_INT
7134 AT_int (dw_attr_ref a
)
7136 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
7137 return a
->dw_attr_val
.v
.val_int
;
7140 /* Add an unsigned integer attribute value to a DIE. */
7143 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7144 unsigned HOST_WIDE_INT unsigned_val
)
7148 attr
.dw_attr
= attr_kind
;
7149 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
7150 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
7151 add_dwarf_attr (die
, &attr
);
7154 static inline unsigned HOST_WIDE_INT
7155 AT_unsigned (dw_attr_ref a
)
7157 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
7158 return a
->dw_attr_val
.v
.val_unsigned
;
7161 /* Add an unsigned double integer attribute value to a DIE. */
7164 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7165 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
7169 attr
.dw_attr
= attr_kind
;
7170 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
7171 attr
.dw_attr_val
.v
.val_double
.high
= high
;
7172 attr
.dw_attr_val
.v
.val_double
.low
= low
;
7173 add_dwarf_attr (die
, &attr
);
7176 /* Add a floating point attribute value to a DIE and return it. */
7179 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7180 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
7184 attr
.dw_attr
= attr_kind
;
7185 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
7186 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
7187 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
7188 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
7189 add_dwarf_attr (die
, &attr
);
7192 /* Add an 8-byte data attribute value to a DIE. */
7195 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7196 unsigned char data8
[8])
7200 attr
.dw_attr
= attr_kind
;
7201 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
7202 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
7203 add_dwarf_attr (die
, &attr
);
7206 /* Hash and equality functions for debug_str_hash. */
7209 debug_str_do_hash (const void *x
)
7211 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
7215 debug_str_eq (const void *x1
, const void *x2
)
7217 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
7218 (const char *)x2
) == 0;
7221 /* Add STR to the indirect string hash table. */
7223 static struct indirect_string_node
*
7224 find_AT_string (const char *str
)
7226 struct indirect_string_node
*node
;
7229 if (! debug_str_hash
)
7230 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
7231 debug_str_eq
, NULL
);
7233 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
7234 htab_hash_string (str
), INSERT
);
7237 node
= ggc_alloc_cleared_indirect_string_node ();
7238 node
->str
= ggc_strdup (str
);
7242 node
= (struct indirect_string_node
*) *slot
;
7248 /* Add a string attribute value to a DIE. */
7251 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
7254 struct indirect_string_node
*node
;
7256 node
= find_AT_string (str
);
7258 attr
.dw_attr
= attr_kind
;
7259 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
7260 attr
.dw_attr_val
.v
.val_str
= node
;
7261 add_dwarf_attr (die
, &attr
);
7264 /* Create a label for an indirect string node, ensuring it is going to
7265 be output, unless its reference count goes down to zero. */
7268 gen_label_for_indirect_string (struct indirect_string_node
*node
)
7275 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
7276 ++dw2_string_counter
;
7277 node
->label
= xstrdup (label
);
7280 /* Create a SYMBOL_REF rtx whose value is the initial address of a
7281 debug string STR. */
7284 get_debug_string_label (const char *str
)
7286 struct indirect_string_node
*node
= find_AT_string (str
);
7288 debug_str_hash_forced
= true;
7290 gen_label_for_indirect_string (node
);
7292 return gen_rtx_SYMBOL_REF (Pmode
, node
->label
);
7295 static inline const char *
7296 AT_string (dw_attr_ref a
)
7298 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
7299 return a
->dw_attr_val
.v
.val_str
->str
;
7302 /* Find out whether a string should be output inline in DIE
7303 or out-of-line in .debug_str section. */
7305 static enum dwarf_form
7306 AT_string_form (dw_attr_ref a
)
7308 struct indirect_string_node
*node
;
7311 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
7313 node
= a
->dw_attr_val
.v
.val_str
;
7317 len
= strlen (node
->str
) + 1;
7319 /* If the string is shorter or equal to the size of the reference, it is
7320 always better to put it inline. */
7321 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
7322 return node
->form
= DW_FORM_string
;
7324 /* If we cannot expect the linker to merge strings in .debug_str
7325 section, only put it into .debug_str if it is worth even in this
7327 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
7328 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
7329 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
7330 return node
->form
= DW_FORM_string
;
7332 gen_label_for_indirect_string (node
);
7334 return node
->form
= DW_FORM_strp
;
7337 /* Add a DIE reference attribute value to a DIE. */
7340 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
7344 attr
.dw_attr
= attr_kind
;
7345 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
7346 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
7347 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
7348 add_dwarf_attr (die
, &attr
);
7351 /* Add an AT_specification attribute to a DIE, and also make the back
7352 pointer from the specification to the definition. */
7355 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
7357 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
7358 gcc_assert (!targ_die
->die_definition
);
7359 targ_die
->die_definition
= die
;
7362 static inline dw_die_ref
7363 AT_ref (dw_attr_ref a
)
7365 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
7366 return a
->dw_attr_val
.v
.val_die_ref
.die
;
7370 AT_ref_external (dw_attr_ref a
)
7372 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
7373 return a
->dw_attr_val
.v
.val_die_ref
.external
;
7379 set_AT_ref_external (dw_attr_ref a
, int i
)
7381 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
7382 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
7385 /* Add an FDE reference attribute value to a DIE. */
7388 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
7392 attr
.dw_attr
= attr_kind
;
7393 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
7394 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
7395 add_dwarf_attr (die
, &attr
);
7398 /* Add a location description attribute value to a DIE. */
7401 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
7405 attr
.dw_attr
= attr_kind
;
7406 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
7407 attr
.dw_attr_val
.v
.val_loc
= loc
;
7408 add_dwarf_attr (die
, &attr
);
7411 static inline dw_loc_descr_ref
7412 AT_loc (dw_attr_ref a
)
7414 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
7415 return a
->dw_attr_val
.v
.val_loc
;
7419 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
7423 attr
.dw_attr
= attr_kind
;
7424 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
7425 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
7426 add_dwarf_attr (die
, &attr
);
7427 have_location_lists
= true;
7430 static inline dw_loc_list_ref
7431 AT_loc_list (dw_attr_ref a
)
7433 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
7434 return a
->dw_attr_val
.v
.val_loc_list
;
7437 static inline dw_loc_list_ref
*
7438 AT_loc_list_ptr (dw_attr_ref a
)
7440 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
7441 return &a
->dw_attr_val
.v
.val_loc_list
;
7444 /* Add an address constant attribute value to a DIE. */
7447 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
7451 attr
.dw_attr
= attr_kind
;
7452 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
7453 attr
.dw_attr_val
.v
.val_addr
= addr
;
7454 add_dwarf_attr (die
, &attr
);
7457 /* Get the RTX from to an address DIE attribute. */
7460 AT_addr (dw_attr_ref a
)
7462 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
7463 return a
->dw_attr_val
.v
.val_addr
;
7466 /* Add a file attribute value to a DIE. */
7469 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7470 struct dwarf_file_data
*fd
)
7474 attr
.dw_attr
= attr_kind
;
7475 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
7476 attr
.dw_attr_val
.v
.val_file
= fd
;
7477 add_dwarf_attr (die
, &attr
);
7480 /* Get the dwarf_file_data from a file DIE attribute. */
7482 static inline struct dwarf_file_data
*
7483 AT_file (dw_attr_ref a
)
7485 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
7486 return a
->dw_attr_val
.v
.val_file
;
7489 /* Add a vms delta attribute value to a DIE. */
7492 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7493 const char *lbl1
, const char *lbl2
)
7497 attr
.dw_attr
= attr_kind
;
7498 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
7499 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
7500 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
7501 add_dwarf_attr (die
, &attr
);
7504 /* Add a label identifier attribute value to a DIE. */
7507 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
7511 attr
.dw_attr
= attr_kind
;
7512 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
7513 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
7514 add_dwarf_attr (die
, &attr
);
7517 /* Add a section offset attribute value to a DIE, an offset into the
7518 debug_line section. */
7521 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7526 attr
.dw_attr
= attr_kind
;
7527 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
7528 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
7529 add_dwarf_attr (die
, &attr
);
7532 /* Add a section offset attribute value to a DIE, an offset into the
7533 debug_macinfo section. */
7536 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7541 attr
.dw_attr
= attr_kind
;
7542 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
7543 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
7544 add_dwarf_attr (die
, &attr
);
7547 /* Add an offset attribute value to a DIE. */
7550 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7551 unsigned HOST_WIDE_INT offset
)
7555 attr
.dw_attr
= attr_kind
;
7556 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
7557 attr
.dw_attr_val
.v
.val_offset
= offset
;
7558 add_dwarf_attr (die
, &attr
);
7561 /* Add an range_list attribute value to a DIE. */
7564 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7565 long unsigned int offset
)
7569 attr
.dw_attr
= attr_kind
;
7570 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
7571 attr
.dw_attr_val
.v
.val_offset
= offset
;
7572 add_dwarf_attr (die
, &attr
);
7575 /* Return the start label of a delta attribute. */
7577 static inline const char *
7578 AT_vms_delta1 (dw_attr_ref a
)
7580 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
7581 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
7584 /* Return the end label of a delta attribute. */
7586 static inline const char *
7587 AT_vms_delta2 (dw_attr_ref a
)
7589 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
7590 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
7593 static inline const char *
7594 AT_lbl (dw_attr_ref a
)
7596 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
7597 || AT_class (a
) == dw_val_class_lineptr
7598 || AT_class (a
) == dw_val_class_macptr
));
7599 return a
->dw_attr_val
.v
.val_lbl_id
;
7602 /* Get the attribute of type attr_kind. */
7605 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7609 dw_die_ref spec
= NULL
;
7614 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7615 if (a
->dw_attr
== attr_kind
)
7617 else if (a
->dw_attr
== DW_AT_specification
7618 || a
->dw_attr
== DW_AT_abstract_origin
)
7622 return get_AT (spec
, attr_kind
);
7627 /* Return the "low pc" attribute value, typically associated with a subprogram
7628 DIE. Return null if the "low pc" attribute is either not present, or if it
7629 cannot be represented as an assembler label identifier. */
7631 static inline const char *
7632 get_AT_low_pc (dw_die_ref die
)
7634 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
7636 return a
? AT_lbl (a
) : NULL
;
7639 /* Return the "high pc" attribute value, typically associated with a subprogram
7640 DIE. Return null if the "high pc" attribute is either not present, or if it
7641 cannot be represented as an assembler label identifier. */
7643 static inline const char *
7644 get_AT_hi_pc (dw_die_ref die
)
7646 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
7648 return a
? AT_lbl (a
) : NULL
;
7651 /* Return the value of the string attribute designated by ATTR_KIND, or
7652 NULL if it is not present. */
7654 static inline const char *
7655 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7657 dw_attr_ref a
= get_AT (die
, attr_kind
);
7659 return a
? AT_string (a
) : NULL
;
7662 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
7663 if it is not present. */
7666 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7668 dw_attr_ref a
= get_AT (die
, attr_kind
);
7670 return a
? AT_flag (a
) : 0;
7673 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
7674 if it is not present. */
7676 static inline unsigned
7677 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7679 dw_attr_ref a
= get_AT (die
, attr_kind
);
7681 return a
? AT_unsigned (a
) : 0;
7684 static inline dw_die_ref
7685 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7687 dw_attr_ref a
= get_AT (die
, attr_kind
);
7689 return a
? AT_ref (a
) : NULL
;
7692 static inline struct dwarf_file_data
*
7693 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7695 dw_attr_ref a
= get_AT (die
, attr_kind
);
7697 return a
? AT_file (a
) : NULL
;
7700 /* Return TRUE if the language is C++. */
7705 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
7707 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
7710 /* Return TRUE if the language is Fortran. */
7715 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
7717 return (lang
== DW_LANG_Fortran77
7718 || lang
== DW_LANG_Fortran90
7719 || lang
== DW_LANG_Fortran95
);
7722 /* Return TRUE if the language is Ada. */
7727 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
7729 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
7732 /* Remove the specified attribute if present. */
7735 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7743 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7744 if (a
->dw_attr
== attr_kind
)
7746 if (AT_class (a
) == dw_val_class_str
)
7747 if (a
->dw_attr_val
.v
.val_str
->refcount
)
7748 a
->dw_attr_val
.v
.val_str
->refcount
--;
7750 /* VEC_ordered_remove should help reduce the number of abbrevs
7752 VEC_ordered_remove (dw_attr_node
, die
->die_attr
, ix
);
7757 /* Remove CHILD from its parent. PREV must have the property that
7758 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
7761 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
7763 gcc_assert (child
->die_parent
== prev
->die_parent
);
7764 gcc_assert (prev
->die_sib
== child
);
7767 gcc_assert (child
->die_parent
->die_child
== child
);
7771 prev
->die_sib
= child
->die_sib
;
7772 if (child
->die_parent
->die_child
== child
)
7773 child
->die_parent
->die_child
= prev
;
7776 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
7777 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
7780 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
7782 dw_die_ref parent
= old_child
->die_parent
;
7784 gcc_assert (parent
== prev
->die_parent
);
7785 gcc_assert (prev
->die_sib
== old_child
);
7787 new_child
->die_parent
= parent
;
7788 if (prev
== old_child
)
7790 gcc_assert (parent
->die_child
== old_child
);
7791 new_child
->die_sib
= new_child
;
7795 prev
->die_sib
= new_child
;
7796 new_child
->die_sib
= old_child
->die_sib
;
7798 if (old_child
->die_parent
->die_child
== old_child
)
7799 old_child
->die_parent
->die_child
= new_child
;
7802 /* Move all children from OLD_PARENT to NEW_PARENT. */
7805 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
7808 new_parent
->die_child
= old_parent
->die_child
;
7809 old_parent
->die_child
= NULL
;
7810 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
7813 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
7817 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
7823 dw_die_ref prev
= c
;
7825 while (c
->die_tag
== tag
)
7827 remove_child_with_prev (c
, prev
);
7828 /* Might have removed every child. */
7829 if (c
== c
->die_sib
)
7833 } while (c
!= die
->die_child
);
7836 /* Add a CHILD_DIE as the last child of DIE. */
7839 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
7841 /* FIXME this should probably be an assert. */
7842 if (! die
|| ! child_die
)
7844 gcc_assert (die
!= child_die
);
7846 child_die
->die_parent
= die
;
7849 child_die
->die_sib
= die
->die_child
->die_sib
;
7850 die
->die_child
->die_sib
= child_die
;
7853 child_die
->die_sib
= child_die
;
7854 die
->die_child
= child_die
;
7857 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
7858 is the specification, to the end of PARENT's list of children.
7859 This is done by removing and re-adding it. */
7862 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
7866 /* We want the declaration DIE from inside the class, not the
7867 specification DIE at toplevel. */
7868 if (child
->die_parent
!= parent
)
7870 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
7876 gcc_assert (child
->die_parent
== parent
7877 || (child
->die_parent
7878 == get_AT_ref (parent
, DW_AT_specification
)));
7880 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
7881 if (p
->die_sib
== child
)
7883 remove_child_with_prev (child
, p
);
7887 add_child_die (parent
, child
);
7890 /* Return a pointer to a newly created DIE node. */
7892 static inline dw_die_ref
7893 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
7895 dw_die_ref die
= ggc_alloc_cleared_die_node ();
7897 die
->die_tag
= tag_value
;
7899 if (parent_die
!= NULL
)
7900 add_child_die (parent_die
, die
);
7903 limbo_die_node
*limbo_node
;
7905 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
7906 limbo_node
->die
= die
;
7907 limbo_node
->created_for
= t
;
7908 limbo_node
->next
= limbo_die_list
;
7909 limbo_die_list
= limbo_node
;
7915 /* Return the DIE associated with the given type specifier. */
7917 static inline dw_die_ref
7918 lookup_type_die (tree type
)
7920 return TYPE_SYMTAB_DIE (type
);
7923 /* Equate a DIE to a given type specifier. */
7926 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
7928 TYPE_SYMTAB_DIE (type
) = type_die
;
7931 /* Returns a hash value for X (which really is a die_struct). */
7934 decl_die_table_hash (const void *x
)
7936 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
7939 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
7942 decl_die_table_eq (const void *x
, const void *y
)
7944 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
7947 /* Return the DIE associated with a given declaration. */
7949 static inline dw_die_ref
7950 lookup_decl_die (tree decl
)
7952 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
7955 /* Returns a hash value for X (which really is a var_loc_list). */
7958 decl_loc_table_hash (const void *x
)
7960 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
7963 /* Return nonzero if decl_id of var_loc_list X is the same as
7967 decl_loc_table_eq (const void *x
, const void *y
)
7969 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
7972 /* Return the var_loc list associated with a given declaration. */
7974 static inline var_loc_list
*
7975 lookup_decl_loc (const_tree decl
)
7977 if (!decl_loc_table
)
7979 return (var_loc_list
*)
7980 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
7983 /* Equate a DIE to a particular declaration. */
7986 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
7988 unsigned int decl_id
= DECL_UID (decl
);
7991 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
7993 decl_die
->decl_id
= decl_id
;
7996 /* Return how many bits covers PIECE EXPR_LIST. */
7999 decl_piece_bitsize (rtx piece
)
8001 int ret
= (int) GET_MODE (piece
);
8004 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
8005 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
8006 return INTVAL (XEXP (XEXP (piece
, 0), 0));
8009 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
8012 decl_piece_varloc_ptr (rtx piece
)
8014 if ((int) GET_MODE (piece
))
8015 return &XEXP (piece
, 0);
8017 return &XEXP (XEXP (piece
, 0), 1);
8020 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
8021 Next is the chain of following piece nodes. */
8024 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
8026 if (bitsize
<= (int) MAX_MACHINE_MODE
)
8027 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
8029 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
8034 /* Return rtx that should be stored into loc field for
8035 LOC_NOTE and BITPOS/BITSIZE. */
8038 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
8039 HOST_WIDE_INT bitsize
)
8043 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
8045 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
8050 /* This function either modifies location piece list *DEST in
8051 place (if SRC and INNER is NULL), or copies location piece list
8052 *SRC to *DEST while modifying it. Location BITPOS is modified
8053 to contain LOC_NOTE, any pieces overlapping it are removed resp.
8054 not copied and if needed some padding around it is added.
8055 When modifying in place, DEST should point to EXPR_LIST where
8056 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
8057 to the start of the whole list and INNER points to the EXPR_LIST
8058 where earlier pieces cover PIECE_BITPOS bits. */
8061 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
8062 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
8063 HOST_WIDE_INT bitsize
, rtx loc_note
)
8066 bool copy
= inner
!= NULL
;
8070 /* First copy all nodes preceeding the current bitpos. */
8071 while (src
!= inner
)
8073 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
8074 decl_piece_bitsize (*src
), NULL_RTX
);
8075 dest
= &XEXP (*dest
, 1);
8076 src
= &XEXP (*src
, 1);
8079 /* Add padding if needed. */
8080 if (bitpos
!= piece_bitpos
)
8082 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
8083 copy
? NULL_RTX
: *dest
);
8084 dest
= &XEXP (*dest
, 1);
8086 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
8089 /* A piece with correct bitpos and bitsize already exist,
8090 just update the location for it and return. */
8091 *decl_piece_varloc_ptr (*dest
) = loc_note
;
8094 /* Add the piece that changed. */
8095 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
8096 dest
= &XEXP (*dest
, 1);
8097 /* Skip over pieces that overlap it. */
8098 diff
= bitpos
- piece_bitpos
+ bitsize
;
8101 while (diff
> 0 && *src
)
8104 diff
-= decl_piece_bitsize (piece
);
8106 src
= &XEXP (piece
, 1);
8109 *src
= XEXP (piece
, 1);
8110 free_EXPR_LIST_node (piece
);
8113 /* Add padding if needed. */
8114 if (diff
< 0 && *src
)
8118 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
8119 dest
= &XEXP (*dest
, 1);
8123 /* Finally copy all nodes following it. */
8126 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
8127 decl_piece_bitsize (*src
), NULL_RTX
);
8128 dest
= &XEXP (*dest
, 1);
8129 src
= &XEXP (*src
, 1);
8133 /* Add a variable location node to the linked list for DECL. */
8135 static struct var_loc_node
*
8136 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
8138 unsigned int decl_id
;
8141 struct var_loc_node
*loc
= NULL
;
8142 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
8144 if (DECL_DEBUG_EXPR_IS_FROM (decl
))
8146 tree realdecl
= DECL_DEBUG_EXPR (decl
);
8147 if (realdecl
&& handled_component_p (realdecl
))
8149 HOST_WIDE_INT maxsize
;
8152 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
8153 if (!DECL_P (innerdecl
)
8154 || DECL_IGNORED_P (innerdecl
)
8155 || TREE_STATIC (innerdecl
)
8157 || bitpos
+ bitsize
> 256
8158 || bitsize
!= maxsize
)
8164 decl_id
= DECL_UID (decl
);
8165 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
8168 temp
= ggc_alloc_cleared_var_loc_list ();
8169 temp
->decl_id
= decl_id
;
8173 temp
= (var_loc_list
*) *slot
;
8177 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
8178 rtx
*piece_loc
= NULL
, last_loc_note
;
8179 int piece_bitpos
= 0;
8183 gcc_assert (last
->next
== NULL
);
8185 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
8187 piece_loc
= &last
->loc
;
8190 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
8191 if (piece_bitpos
+ cur_bitsize
> bitpos
)
8193 piece_bitpos
+= cur_bitsize
;
8194 piece_loc
= &XEXP (*piece_loc
, 1);
8198 /* TEMP->LAST here is either pointer to the last but one or
8199 last element in the chained list, LAST is pointer to the
8201 if (label
&& strcmp (last
->label
, label
) == 0)
8203 /* For SRA optimized variables if there weren't any real
8204 insns since last note, just modify the last node. */
8205 if (piece_loc
!= NULL
)
8207 adjust_piece_list (piece_loc
, NULL
, NULL
,
8208 bitpos
, piece_bitpos
, bitsize
, loc_note
);
8211 /* If the last note doesn't cover any instructions, remove it. */
8212 if (temp
->last
!= last
)
8214 temp
->last
->next
= NULL
;
8217 gcc_assert (strcmp (last
->label
, label
) != 0);
8221 gcc_assert (temp
->first
== temp
->last
);
8222 memset (temp
->last
, '\0', sizeof (*temp
->last
));
8223 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
8227 if (bitsize
== -1 && NOTE_P (last
->loc
))
8228 last_loc_note
= last
->loc
;
8229 else if (piece_loc
!= NULL
8230 && *piece_loc
!= NULL_RTX
8231 && piece_bitpos
== bitpos
8232 && decl_piece_bitsize (*piece_loc
) == bitsize
)
8233 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
8235 last_loc_note
= NULL_RTX
;
8236 /* If the current location is the same as the end of the list,
8237 and either both or neither of the locations is uninitialized,
8238 we have nothing to do. */
8239 if (last_loc_note
== NULL_RTX
8240 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
8241 NOTE_VAR_LOCATION_LOC (loc_note
)))
8242 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
8243 != NOTE_VAR_LOCATION_STATUS (loc_note
))
8244 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
8245 == VAR_INIT_STATUS_UNINITIALIZED
)
8246 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
8247 == VAR_INIT_STATUS_UNINITIALIZED
))))
8249 /* Add LOC to the end of list and update LAST. If the last
8250 element of the list has been removed above, reuse its
8251 memory for the new node, otherwise allocate a new one. */
8255 memset (loc
, '\0', sizeof (*loc
));
8258 loc
= ggc_alloc_cleared_var_loc_node ();
8259 if (bitsize
== -1 || piece_loc
== NULL
)
8260 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
8262 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
8263 bitpos
, piece_bitpos
, bitsize
, loc_note
);
8265 /* Ensure TEMP->LAST will point either to the new last but one
8266 element of the chain, or to the last element in it. */
8267 if (last
!= temp
->last
)
8275 loc
= ggc_alloc_cleared_var_loc_node ();
8278 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
8283 /* Keep track of the number of spaces used to indent the
8284 output of the debugging routines that print the structure of
8285 the DIE internal representation. */
8286 static int print_indent
;
8288 /* Indent the line the number of spaces given by print_indent. */
8291 print_spaces (FILE *outfile
)
8293 fprintf (outfile
, "%*s", print_indent
, "");
8296 /* Print a type signature in hex. */
8299 print_signature (FILE *outfile
, char *sig
)
8303 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8304 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
8307 /* Print the information associated with a given DIE, and its children.
8308 This routine is a debugging aid only. */
8311 print_die (dw_die_ref die
, FILE *outfile
)
8317 print_spaces (outfile
);
8318 fprintf (outfile
, "DIE %4ld: %s\n",
8319 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
8320 print_spaces (outfile
);
8321 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
8322 fprintf (outfile
, " offset: %ld\n", die
->die_offset
);
8323 if (dwarf_version
>= 4 && die
->die_id
.die_type_node
)
8325 print_spaces (outfile
);
8326 fprintf (outfile
, " signature: ");
8327 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
8328 fprintf (outfile
, "\n");
8331 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
8333 print_spaces (outfile
);
8334 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
8336 switch (AT_class (a
))
8338 case dw_val_class_addr
:
8339 fprintf (outfile
, "address");
8341 case dw_val_class_offset
:
8342 fprintf (outfile
, "offset");
8344 case dw_val_class_loc
:
8345 fprintf (outfile
, "location descriptor");
8347 case dw_val_class_loc_list
:
8348 fprintf (outfile
, "location list -> label:%s",
8349 AT_loc_list (a
)->ll_symbol
);
8351 case dw_val_class_range_list
:
8352 fprintf (outfile
, "range list");
8354 case dw_val_class_const
:
8355 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
8357 case dw_val_class_unsigned_const
:
8358 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
8360 case dw_val_class_const_double
:
8361 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
8362 HOST_WIDE_INT_PRINT_UNSIGNED
")",
8363 a
->dw_attr_val
.v
.val_double
.high
,
8364 a
->dw_attr_val
.v
.val_double
.low
);
8366 case dw_val_class_vec
:
8367 fprintf (outfile
, "floating-point or vector constant");
8369 case dw_val_class_flag
:
8370 fprintf (outfile
, "%u", AT_flag (a
));
8372 case dw_val_class_die_ref
:
8373 if (AT_ref (a
) != NULL
)
8375 if (dwarf_version
>= 4 && AT_ref (a
)->die_id
.die_type_node
)
8377 fprintf (outfile
, "die -> signature: ");
8378 print_signature (outfile
,
8379 AT_ref (a
)->die_id
.die_type_node
->signature
);
8381 else if (dwarf_version
< 4 && AT_ref (a
)->die_id
.die_symbol
)
8382 fprintf (outfile
, "die -> label: %s",
8383 AT_ref (a
)->die_id
.die_symbol
);
8385 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
8388 fprintf (outfile
, "die -> <null>");
8390 case dw_val_class_vms_delta
:
8391 fprintf (outfile
, "delta: @slotcount(%s-%s)",
8392 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
8394 case dw_val_class_lbl_id
:
8395 case dw_val_class_lineptr
:
8396 case dw_val_class_macptr
:
8397 fprintf (outfile
, "label: %s", AT_lbl (a
));
8399 case dw_val_class_str
:
8400 if (AT_string (a
) != NULL
)
8401 fprintf (outfile
, "\"%s\"", AT_string (a
));
8403 fprintf (outfile
, "<null>");
8405 case dw_val_class_file
:
8406 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
8407 AT_file (a
)->emitted_number
);
8409 case dw_val_class_data8
:
8413 for (i
= 0; i
< 8; i
++)
8414 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
8421 fprintf (outfile
, "\n");
8424 if (die
->die_child
!= NULL
)
8427 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
8430 if (print_indent
== 0)
8431 fprintf (outfile
, "\n");
8434 /* Print the contents of the source code line number correspondence table.
8435 This routine is a debugging aid only. */
8438 print_dwarf_line_table (FILE *outfile
)
8441 dw_line_info_ref line_info
;
8443 fprintf (outfile
, "\n\nDWARF source line information\n");
8444 for (i
= 1; i
< line_info_table_in_use
; i
++)
8446 line_info
= &line_info_table
[i
];
8447 fprintf (outfile
, "%5d: %4ld %6ld\n", i
,
8448 line_info
->dw_file_num
,
8449 line_info
->dw_line_num
);
8452 fprintf (outfile
, "\n\n");
8455 /* Print the information collected for a given DIE. */
8458 debug_dwarf_die (dw_die_ref die
)
8460 print_die (die
, stderr
);
8463 /* Print all DWARF information collected for the compilation unit.
8464 This routine is a debugging aid only. */
8470 print_die (comp_unit_die (), stderr
);
8471 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
8472 print_dwarf_line_table (stderr
);
8475 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
8476 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
8477 DIE that marks the start of the DIEs for this include file. */
8480 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
8482 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
8483 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
8485 new_unit
->die_sib
= old_unit
;
8489 /* Close an include-file CU and reopen the enclosing one. */
8492 pop_compile_unit (dw_die_ref old_unit
)
8494 dw_die_ref new_unit
= old_unit
->die_sib
;
8496 old_unit
->die_sib
= NULL
;
8500 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8501 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
8503 /* Calculate the checksum of a location expression. */
8506 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
8510 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
8512 CHECKSUM (loc
->dw_loc_oprnd1
);
8513 CHECKSUM (loc
->dw_loc_oprnd2
);
8516 /* Calculate the checksum of an attribute. */
8519 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
8521 dw_loc_descr_ref loc
;
8524 CHECKSUM (at
->dw_attr
);
8526 /* We don't care that this was compiled with a different compiler
8527 snapshot; if the output is the same, that's what matters. */
8528 if (at
->dw_attr
== DW_AT_producer
)
8531 switch (AT_class (at
))
8533 case dw_val_class_const
:
8534 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
8536 case dw_val_class_unsigned_const
:
8537 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
8539 case dw_val_class_const_double
:
8540 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
8542 case dw_val_class_vec
:
8543 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
8545 case dw_val_class_flag
:
8546 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
8548 case dw_val_class_str
:
8549 CHECKSUM_STRING (AT_string (at
));
8552 case dw_val_class_addr
:
8554 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
8555 CHECKSUM_STRING (XSTR (r
, 0));
8558 case dw_val_class_offset
:
8559 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
8562 case dw_val_class_loc
:
8563 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
8564 loc_checksum (loc
, ctx
);
8567 case dw_val_class_die_ref
:
8568 die_checksum (AT_ref (at
), ctx
, mark
);
8571 case dw_val_class_fde_ref
:
8572 case dw_val_class_vms_delta
:
8573 case dw_val_class_lbl_id
:
8574 case dw_val_class_lineptr
:
8575 case dw_val_class_macptr
:
8578 case dw_val_class_file
:
8579 CHECKSUM_STRING (AT_file (at
)->filename
);
8582 case dw_val_class_data8
:
8583 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
8591 /* Calculate the checksum of a DIE. */
8594 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
8600 /* To avoid infinite recursion. */
8603 CHECKSUM (die
->die_mark
);
8606 die
->die_mark
= ++(*mark
);
8608 CHECKSUM (die
->die_tag
);
8610 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
8611 attr_checksum (a
, ctx
, mark
);
8613 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
8617 #undef CHECKSUM_STRING
8619 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
8620 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8621 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
8622 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
8623 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
8624 #define CHECKSUM_ATTR(FOO) \
8625 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
8627 /* Calculate the checksum of a number in signed LEB128 format. */
8630 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
8637 byte
= (value
& 0x7f);
8639 more
= !((value
== 0 && (byte
& 0x40) == 0)
8640 || (value
== -1 && (byte
& 0x40) != 0));
8649 /* Calculate the checksum of a number in unsigned LEB128 format. */
8652 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
8656 unsigned char byte
= (value
& 0x7f);
8659 /* More bytes to follow. */
8667 /* Checksum the context of the DIE. This adds the names of any
8668 surrounding namespaces or structures to the checksum. */
8671 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
8675 int tag
= die
->die_tag
;
8677 if (tag
!= DW_TAG_namespace
8678 && tag
!= DW_TAG_structure_type
8679 && tag
!= DW_TAG_class_type
)
8682 name
= get_AT_string (die
, DW_AT_name
);
8684 spec
= get_AT_ref (die
, DW_AT_specification
);
8688 if (die
->die_parent
!= NULL
)
8689 checksum_die_context (die
->die_parent
, ctx
);
8691 CHECKSUM_ULEB128 ('C');
8692 CHECKSUM_ULEB128 (tag
);
8694 CHECKSUM_STRING (name
);
8697 /* Calculate the checksum of a location expression. */
8700 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
8702 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
8703 were emitted as a DW_FORM_sdata instead of a location expression. */
8704 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
8706 CHECKSUM_ULEB128 (DW_FORM_sdata
);
8707 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
8711 /* Otherwise, just checksum the raw location expression. */
8714 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
8715 CHECKSUM (loc
->dw_loc_oprnd1
);
8716 CHECKSUM (loc
->dw_loc_oprnd2
);
8717 loc
= loc
->dw_loc_next
;
8721 /* Calculate the checksum of an attribute. */
8724 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
8725 struct md5_ctx
*ctx
, int *mark
)
8727 dw_loc_descr_ref loc
;
8730 if (AT_class (at
) == dw_val_class_die_ref
)
8732 dw_die_ref target_die
= AT_ref (at
);
8734 /* For pointer and reference types, we checksum only the (qualified)
8735 name of the target type (if there is a name). For friend entries,
8736 we checksum only the (qualified) name of the target type or function.
8737 This allows the checksum to remain the same whether the target type
8738 is complete or not. */
8739 if ((at
->dw_attr
== DW_AT_type
8740 && (tag
== DW_TAG_pointer_type
8741 || tag
== DW_TAG_reference_type
8742 || tag
== DW_TAG_rvalue_reference_type
8743 || tag
== DW_TAG_ptr_to_member_type
))
8744 || (at
->dw_attr
== DW_AT_friend
8745 && tag
== DW_TAG_friend
))
8747 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
8749 if (name_attr
!= NULL
)
8751 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
8755 CHECKSUM_ULEB128 ('N');
8756 CHECKSUM_ULEB128 (at
->dw_attr
);
8757 if (decl
->die_parent
!= NULL
)
8758 checksum_die_context (decl
->die_parent
, ctx
);
8759 CHECKSUM_ULEB128 ('E');
8760 CHECKSUM_STRING (AT_string (name_attr
));
8765 /* For all other references to another DIE, we check to see if the
8766 target DIE has already been visited. If it has, we emit a
8767 backward reference; if not, we descend recursively. */
8768 if (target_die
->die_mark
> 0)
8770 CHECKSUM_ULEB128 ('R');
8771 CHECKSUM_ULEB128 (at
->dw_attr
);
8772 CHECKSUM_ULEB128 (target_die
->die_mark
);
8776 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
8780 target_die
->die_mark
= ++(*mark
);
8781 CHECKSUM_ULEB128 ('T');
8782 CHECKSUM_ULEB128 (at
->dw_attr
);
8783 if (decl
->die_parent
!= NULL
)
8784 checksum_die_context (decl
->die_parent
, ctx
);
8785 die_checksum_ordered (target_die
, ctx
, mark
);
8790 CHECKSUM_ULEB128 ('A');
8791 CHECKSUM_ULEB128 (at
->dw_attr
);
8793 switch (AT_class (at
))
8795 case dw_val_class_const
:
8796 CHECKSUM_ULEB128 (DW_FORM_sdata
);
8797 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
8800 case dw_val_class_unsigned_const
:
8801 CHECKSUM_ULEB128 (DW_FORM_sdata
);
8802 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
8805 case dw_val_class_const_double
:
8806 CHECKSUM_ULEB128 (DW_FORM_block
);
8807 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
8808 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
8811 case dw_val_class_vec
:
8812 CHECKSUM_ULEB128 (DW_FORM_block
);
8813 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_vec
));
8814 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
8817 case dw_val_class_flag
:
8818 CHECKSUM_ULEB128 (DW_FORM_flag
);
8819 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
8822 case dw_val_class_str
:
8823 CHECKSUM_ULEB128 (DW_FORM_string
);
8824 CHECKSUM_STRING (AT_string (at
));
8827 case dw_val_class_addr
:
8829 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
8830 CHECKSUM_ULEB128 (DW_FORM_string
);
8831 CHECKSUM_STRING (XSTR (r
, 0));
8834 case dw_val_class_offset
:
8835 CHECKSUM_ULEB128 (DW_FORM_sdata
);
8836 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
8839 case dw_val_class_loc
:
8840 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
8841 loc_checksum_ordered (loc
, ctx
);
8844 case dw_val_class_fde_ref
:
8845 case dw_val_class_lbl_id
:
8846 case dw_val_class_lineptr
:
8847 case dw_val_class_macptr
:
8850 case dw_val_class_file
:
8851 CHECKSUM_ULEB128 (DW_FORM_string
);
8852 CHECKSUM_STRING (AT_file (at
)->filename
);
8855 case dw_val_class_data8
:
8856 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
8864 struct checksum_attributes
8866 dw_attr_ref at_name
;
8867 dw_attr_ref at_type
;
8868 dw_attr_ref at_friend
;
8869 dw_attr_ref at_accessibility
;
8870 dw_attr_ref at_address_class
;
8871 dw_attr_ref at_allocated
;
8872 dw_attr_ref at_artificial
;
8873 dw_attr_ref at_associated
;
8874 dw_attr_ref at_binary_scale
;
8875 dw_attr_ref at_bit_offset
;
8876 dw_attr_ref at_bit_size
;
8877 dw_attr_ref at_bit_stride
;
8878 dw_attr_ref at_byte_size
;
8879 dw_attr_ref at_byte_stride
;
8880 dw_attr_ref at_const_value
;
8881 dw_attr_ref at_containing_type
;
8882 dw_attr_ref at_count
;
8883 dw_attr_ref at_data_location
;
8884 dw_attr_ref at_data_member_location
;
8885 dw_attr_ref at_decimal_scale
;
8886 dw_attr_ref at_decimal_sign
;
8887 dw_attr_ref at_default_value
;
8888 dw_attr_ref at_digit_count
;
8889 dw_attr_ref at_discr
;
8890 dw_attr_ref at_discr_list
;
8891 dw_attr_ref at_discr_value
;
8892 dw_attr_ref at_encoding
;
8893 dw_attr_ref at_endianity
;
8894 dw_attr_ref at_explicit
;
8895 dw_attr_ref at_is_optional
;
8896 dw_attr_ref at_location
;
8897 dw_attr_ref at_lower_bound
;
8898 dw_attr_ref at_mutable
;
8899 dw_attr_ref at_ordering
;
8900 dw_attr_ref at_picture_string
;
8901 dw_attr_ref at_prototyped
;
8902 dw_attr_ref at_small
;
8903 dw_attr_ref at_segment
;
8904 dw_attr_ref at_string_length
;
8905 dw_attr_ref at_threads_scaled
;
8906 dw_attr_ref at_upper_bound
;
8907 dw_attr_ref at_use_location
;
8908 dw_attr_ref at_use_UTF8
;
8909 dw_attr_ref at_variable_parameter
;
8910 dw_attr_ref at_virtuality
;
8911 dw_attr_ref at_visibility
;
8912 dw_attr_ref at_vtable_elem_location
;
8915 /* Collect the attributes that we will want to use for the checksum. */
8918 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
8923 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
8934 attrs
->at_friend
= a
;
8936 case DW_AT_accessibility
:
8937 attrs
->at_accessibility
= a
;
8939 case DW_AT_address_class
:
8940 attrs
->at_address_class
= a
;
8942 case DW_AT_allocated
:
8943 attrs
->at_allocated
= a
;
8945 case DW_AT_artificial
:
8946 attrs
->at_artificial
= a
;
8948 case DW_AT_associated
:
8949 attrs
->at_associated
= a
;
8951 case DW_AT_binary_scale
:
8952 attrs
->at_binary_scale
= a
;
8954 case DW_AT_bit_offset
:
8955 attrs
->at_bit_offset
= a
;
8957 case DW_AT_bit_size
:
8958 attrs
->at_bit_size
= a
;
8960 case DW_AT_bit_stride
:
8961 attrs
->at_bit_stride
= a
;
8963 case DW_AT_byte_size
:
8964 attrs
->at_byte_size
= a
;
8966 case DW_AT_byte_stride
:
8967 attrs
->at_byte_stride
= a
;
8969 case DW_AT_const_value
:
8970 attrs
->at_const_value
= a
;
8972 case DW_AT_containing_type
:
8973 attrs
->at_containing_type
= a
;
8976 attrs
->at_count
= a
;
8978 case DW_AT_data_location
:
8979 attrs
->at_data_location
= a
;
8981 case DW_AT_data_member_location
:
8982 attrs
->at_data_member_location
= a
;
8984 case DW_AT_decimal_scale
:
8985 attrs
->at_decimal_scale
= a
;
8987 case DW_AT_decimal_sign
:
8988 attrs
->at_decimal_sign
= a
;
8990 case DW_AT_default_value
:
8991 attrs
->at_default_value
= a
;
8993 case DW_AT_digit_count
:
8994 attrs
->at_digit_count
= a
;
8997 attrs
->at_discr
= a
;
8999 case DW_AT_discr_list
:
9000 attrs
->at_discr_list
= a
;
9002 case DW_AT_discr_value
:
9003 attrs
->at_discr_value
= a
;
9005 case DW_AT_encoding
:
9006 attrs
->at_encoding
= a
;
9008 case DW_AT_endianity
:
9009 attrs
->at_endianity
= a
;
9011 case DW_AT_explicit
:
9012 attrs
->at_explicit
= a
;
9014 case DW_AT_is_optional
:
9015 attrs
->at_is_optional
= a
;
9017 case DW_AT_location
:
9018 attrs
->at_location
= a
;
9020 case DW_AT_lower_bound
:
9021 attrs
->at_lower_bound
= a
;
9024 attrs
->at_mutable
= a
;
9026 case DW_AT_ordering
:
9027 attrs
->at_ordering
= a
;
9029 case DW_AT_picture_string
:
9030 attrs
->at_picture_string
= a
;
9032 case DW_AT_prototyped
:
9033 attrs
->at_prototyped
= a
;
9036 attrs
->at_small
= a
;
9039 attrs
->at_segment
= a
;
9041 case DW_AT_string_length
:
9042 attrs
->at_string_length
= a
;
9044 case DW_AT_threads_scaled
:
9045 attrs
->at_threads_scaled
= a
;
9047 case DW_AT_upper_bound
:
9048 attrs
->at_upper_bound
= a
;
9050 case DW_AT_use_location
:
9051 attrs
->at_use_location
= a
;
9053 case DW_AT_use_UTF8
:
9054 attrs
->at_use_UTF8
= a
;
9056 case DW_AT_variable_parameter
:
9057 attrs
->at_variable_parameter
= a
;
9059 case DW_AT_virtuality
:
9060 attrs
->at_virtuality
= a
;
9062 case DW_AT_visibility
:
9063 attrs
->at_visibility
= a
;
9065 case DW_AT_vtable_elem_location
:
9066 attrs
->at_vtable_elem_location
= a
;
9074 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
9077 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
9081 struct checksum_attributes attrs
;
9083 CHECKSUM_ULEB128 ('D');
9084 CHECKSUM_ULEB128 (die
->die_tag
);
9086 memset (&attrs
, 0, sizeof (attrs
));
9088 decl
= get_AT_ref (die
, DW_AT_specification
);
9090 collect_checksum_attributes (&attrs
, decl
);
9091 collect_checksum_attributes (&attrs
, die
);
9093 CHECKSUM_ATTR (attrs
.at_name
);
9094 CHECKSUM_ATTR (attrs
.at_accessibility
);
9095 CHECKSUM_ATTR (attrs
.at_address_class
);
9096 CHECKSUM_ATTR (attrs
.at_allocated
);
9097 CHECKSUM_ATTR (attrs
.at_artificial
);
9098 CHECKSUM_ATTR (attrs
.at_associated
);
9099 CHECKSUM_ATTR (attrs
.at_binary_scale
);
9100 CHECKSUM_ATTR (attrs
.at_bit_offset
);
9101 CHECKSUM_ATTR (attrs
.at_bit_size
);
9102 CHECKSUM_ATTR (attrs
.at_bit_stride
);
9103 CHECKSUM_ATTR (attrs
.at_byte_size
);
9104 CHECKSUM_ATTR (attrs
.at_byte_stride
);
9105 CHECKSUM_ATTR (attrs
.at_const_value
);
9106 CHECKSUM_ATTR (attrs
.at_containing_type
);
9107 CHECKSUM_ATTR (attrs
.at_count
);
9108 CHECKSUM_ATTR (attrs
.at_data_location
);
9109 CHECKSUM_ATTR (attrs
.at_data_member_location
);
9110 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
9111 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
9112 CHECKSUM_ATTR (attrs
.at_default_value
);
9113 CHECKSUM_ATTR (attrs
.at_digit_count
);
9114 CHECKSUM_ATTR (attrs
.at_discr
);
9115 CHECKSUM_ATTR (attrs
.at_discr_list
);
9116 CHECKSUM_ATTR (attrs
.at_discr_value
);
9117 CHECKSUM_ATTR (attrs
.at_encoding
);
9118 CHECKSUM_ATTR (attrs
.at_endianity
);
9119 CHECKSUM_ATTR (attrs
.at_explicit
);
9120 CHECKSUM_ATTR (attrs
.at_is_optional
);
9121 CHECKSUM_ATTR (attrs
.at_location
);
9122 CHECKSUM_ATTR (attrs
.at_lower_bound
);
9123 CHECKSUM_ATTR (attrs
.at_mutable
);
9124 CHECKSUM_ATTR (attrs
.at_ordering
);
9125 CHECKSUM_ATTR (attrs
.at_picture_string
);
9126 CHECKSUM_ATTR (attrs
.at_prototyped
);
9127 CHECKSUM_ATTR (attrs
.at_small
);
9128 CHECKSUM_ATTR (attrs
.at_segment
);
9129 CHECKSUM_ATTR (attrs
.at_string_length
);
9130 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
9131 CHECKSUM_ATTR (attrs
.at_upper_bound
);
9132 CHECKSUM_ATTR (attrs
.at_use_location
);
9133 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
9134 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
9135 CHECKSUM_ATTR (attrs
.at_virtuality
);
9136 CHECKSUM_ATTR (attrs
.at_visibility
);
9137 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
9138 CHECKSUM_ATTR (attrs
.at_type
);
9139 CHECKSUM_ATTR (attrs
.at_friend
);
9141 /* Checksum the child DIEs, except for nested types and member functions. */
9144 dw_attr_ref name_attr
;
9147 name_attr
= get_AT (c
, DW_AT_name
);
9148 if ((is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
)
9149 && name_attr
!= NULL
)
9151 CHECKSUM_ULEB128 ('S');
9152 CHECKSUM_ULEB128 (c
->die_tag
);
9153 CHECKSUM_STRING (AT_string (name_attr
));
9157 /* Mark this DIE so it gets processed when unmarking. */
9158 if (c
->die_mark
== 0)
9160 die_checksum_ordered (c
, ctx
, mark
);
9162 } while (c
!= die
->die_child
);
9164 CHECKSUM_ULEB128 (0);
9168 #undef CHECKSUM_STRING
9169 #undef CHECKSUM_ATTR
9170 #undef CHECKSUM_LEB128
9171 #undef CHECKSUM_ULEB128
9173 /* Generate the type signature for DIE. This is computed by generating an
9174 MD5 checksum over the DIE's tag, its relevant attributes, and its
9175 children. Attributes that are references to other DIEs are processed
9176 by recursion, using the MARK field to prevent infinite recursion.
9177 If the DIE is nested inside a namespace or another type, we also
9178 need to include that context in the signature. The lower 64 bits
9179 of the resulting MD5 checksum comprise the signature. */
9182 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
9186 unsigned char checksum
[16];
9190 name
= get_AT_string (die
, DW_AT_name
);
9191 decl
= get_AT_ref (die
, DW_AT_specification
);
9193 /* First, compute a signature for just the type name (and its surrounding
9194 context, if any. This is stored in the type unit DIE for link-time
9195 ODR (one-definition rule) checking. */
9197 if (is_cxx() && name
!= NULL
)
9199 md5_init_ctx (&ctx
);
9201 /* Checksum the names of surrounding namespaces and structures. */
9202 if (decl
!= NULL
&& decl
->die_parent
!= NULL
)
9203 checksum_die_context (decl
->die_parent
, &ctx
);
9205 md5_process_bytes (&die
->die_tag
, sizeof (die
->die_tag
), &ctx
);
9206 md5_process_bytes (name
, strlen (name
) + 1, &ctx
);
9207 md5_finish_ctx (&ctx
, checksum
);
9209 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
9212 /* Next, compute the complete type signature. */
9214 md5_init_ctx (&ctx
);
9216 die
->die_mark
= mark
;
9218 /* Checksum the names of surrounding namespaces and structures. */
9219 if (decl
!= NULL
&& decl
->die_parent
!= NULL
)
9220 checksum_die_context (decl
->die_parent
, &ctx
);
9222 /* Checksum the DIE and its children. */
9223 die_checksum_ordered (die
, &ctx
, &mark
);
9224 unmark_all_dies (die
);
9225 md5_finish_ctx (&ctx
, checksum
);
9227 /* Store the signature in the type node and link the type DIE and the
9228 type node together. */
9229 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
9230 DWARF_TYPE_SIGNATURE_SIZE
);
9231 die
->die_id
.die_type_node
= type_node
;
9232 type_node
->type_die
= die
;
9234 /* If the DIE is a specification, link its declaration to the type node
9237 decl
->die_id
.die_type_node
= type_node
;
9240 /* Do the location expressions look same? */
9242 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
9244 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
9245 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
9246 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
9249 /* Do the values look the same? */
9251 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
9253 dw_loc_descr_ref loc1
, loc2
;
9256 if (v1
->val_class
!= v2
->val_class
)
9259 switch (v1
->val_class
)
9261 case dw_val_class_const
:
9262 return v1
->v
.val_int
== v2
->v
.val_int
;
9263 case dw_val_class_unsigned_const
:
9264 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
9265 case dw_val_class_const_double
:
9266 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
9267 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
9268 case dw_val_class_vec
:
9269 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
9270 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
9272 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
9273 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
9276 case dw_val_class_flag
:
9277 return v1
->v
.val_flag
== v2
->v
.val_flag
;
9278 case dw_val_class_str
:
9279 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
9281 case dw_val_class_addr
:
9282 r1
= v1
->v
.val_addr
;
9283 r2
= v2
->v
.val_addr
;
9284 if (GET_CODE (r1
) != GET_CODE (r2
))
9286 return !rtx_equal_p (r1
, r2
);
9288 case dw_val_class_offset
:
9289 return v1
->v
.val_offset
== v2
->v
.val_offset
;
9291 case dw_val_class_loc
:
9292 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
9294 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
9295 if (!same_loc_p (loc1
, loc2
, mark
))
9297 return !loc1
&& !loc2
;
9299 case dw_val_class_die_ref
:
9300 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
9302 case dw_val_class_fde_ref
:
9303 case dw_val_class_vms_delta
:
9304 case dw_val_class_lbl_id
:
9305 case dw_val_class_lineptr
:
9306 case dw_val_class_macptr
:
9309 case dw_val_class_file
:
9310 return v1
->v
.val_file
== v2
->v
.val_file
;
9312 case dw_val_class_data8
:
9313 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
9320 /* Do the attributes look the same? */
9323 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
9325 if (at1
->dw_attr
!= at2
->dw_attr
)
9328 /* We don't care that this was compiled with a different compiler
9329 snapshot; if the output is the same, that's what matters. */
9330 if (at1
->dw_attr
== DW_AT_producer
)
9333 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
9336 /* Do the dies look the same? */
9339 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
9345 /* To avoid infinite recursion. */
9347 return die1
->die_mark
== die2
->die_mark
;
9348 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
9350 if (die1
->die_tag
!= die2
->die_tag
)
9353 if (VEC_length (dw_attr_node
, die1
->die_attr
)
9354 != VEC_length (dw_attr_node
, die2
->die_attr
))
9357 FOR_EACH_VEC_ELT (dw_attr_node
, die1
->die_attr
, ix
, a1
)
9358 if (!same_attr_p (a1
, VEC_index (dw_attr_node
, die2
->die_attr
, ix
), mark
))
9361 c1
= die1
->die_child
;
9362 c2
= die2
->die_child
;
9371 if (!same_die_p (c1
, c2
, mark
))
9375 if (c1
== die1
->die_child
)
9377 if (c2
== die2
->die_child
)
9387 /* Do the dies look the same? Wrapper around same_die_p. */
9390 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
9393 int ret
= same_die_p (die1
, die2
, &mark
);
9395 unmark_all_dies (die1
);
9396 unmark_all_dies (die2
);
9401 /* The prefix to attach to symbols on DIEs in the current comdat debug
9403 static char *comdat_symbol_id
;
9405 /* The index of the current symbol within the current comdat CU. */
9406 static unsigned int comdat_symbol_number
;
9408 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
9409 children, and set comdat_symbol_id accordingly. */
9412 compute_section_prefix (dw_die_ref unit_die
)
9414 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
9415 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
9416 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
9419 unsigned char checksum
[16];
9422 /* Compute the checksum of the DIE, then append part of it as hex digits to
9423 the name filename of the unit. */
9425 md5_init_ctx (&ctx
);
9427 die_checksum (unit_die
, &ctx
, &mark
);
9428 unmark_all_dies (unit_die
);
9429 md5_finish_ctx (&ctx
, checksum
);
9431 sprintf (name
, "%s.", base
);
9432 clean_symbol_name (name
);
9434 p
= name
+ strlen (name
);
9435 for (i
= 0; i
< 4; i
++)
9437 sprintf (p
, "%.2x", checksum
[i
]);
9441 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
9442 comdat_symbol_number
= 0;
9445 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
9448 is_type_die (dw_die_ref die
)
9450 switch (die
->die_tag
)
9452 case DW_TAG_array_type
:
9453 case DW_TAG_class_type
:
9454 case DW_TAG_interface_type
:
9455 case DW_TAG_enumeration_type
:
9456 case DW_TAG_pointer_type
:
9457 case DW_TAG_reference_type
:
9458 case DW_TAG_rvalue_reference_type
:
9459 case DW_TAG_string_type
:
9460 case DW_TAG_structure_type
:
9461 case DW_TAG_subroutine_type
:
9462 case DW_TAG_union_type
:
9463 case DW_TAG_ptr_to_member_type
:
9464 case DW_TAG_set_type
:
9465 case DW_TAG_subrange_type
:
9466 case DW_TAG_base_type
:
9467 case DW_TAG_const_type
:
9468 case DW_TAG_file_type
:
9469 case DW_TAG_packed_type
:
9470 case DW_TAG_volatile_type
:
9471 case DW_TAG_typedef
:
9478 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
9479 Basically, we want to choose the bits that are likely to be shared between
9480 compilations (types) and leave out the bits that are specific to individual
9481 compilations (functions). */
9484 is_comdat_die (dw_die_ref c
)
9486 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
9487 we do for stabs. The advantage is a greater likelihood of sharing between
9488 objects that don't include headers in the same order (and therefore would
9489 put the base types in a different comdat). jason 8/28/00 */
9491 if (c
->die_tag
== DW_TAG_base_type
)
9494 if (c
->die_tag
== DW_TAG_pointer_type
9495 || c
->die_tag
== DW_TAG_reference_type
9496 || c
->die_tag
== DW_TAG_rvalue_reference_type
9497 || c
->die_tag
== DW_TAG_const_type
9498 || c
->die_tag
== DW_TAG_volatile_type
)
9500 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
9502 return t
? is_comdat_die (t
) : 0;
9505 return is_type_die (c
);
9508 /* Returns 1 iff C is the sort of DIE that might be referred to from another
9509 compilation unit. */
9512 is_symbol_die (dw_die_ref c
)
9514 return (is_type_die (c
)
9515 || is_declaration_die (c
)
9516 || c
->die_tag
== DW_TAG_namespace
9517 || c
->die_tag
== DW_TAG_module
);
9520 /* Returns true iff C is a compile-unit DIE. */
9523 is_cu_die (dw_die_ref c
)
9525 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
9529 gen_internal_sym (const char *prefix
)
9533 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
9534 return xstrdup (buf
);
9537 /* Assign symbols to all worthy DIEs under DIE. */
9540 assign_symbol_names (dw_die_ref die
)
9544 if (is_symbol_die (die
))
9546 if (comdat_symbol_id
)
9548 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
9550 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
9551 comdat_symbol_id
, comdat_symbol_number
++);
9552 die
->die_id
.die_symbol
= xstrdup (p
);
9555 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
9558 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
9561 struct cu_hash_table_entry
9564 unsigned min_comdat_num
, max_comdat_num
;
9565 struct cu_hash_table_entry
*next
;
9568 /* Routines to manipulate hash table of CUs. */
9570 htab_cu_hash (const void *of
)
9572 const struct cu_hash_table_entry
*const entry
=
9573 (const struct cu_hash_table_entry
*) of
;
9575 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
9579 htab_cu_eq (const void *of1
, const void *of2
)
9581 const struct cu_hash_table_entry
*const entry1
=
9582 (const struct cu_hash_table_entry
*) of1
;
9583 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
9585 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
9589 htab_cu_del (void *what
)
9591 struct cu_hash_table_entry
*next
,
9592 *entry
= (struct cu_hash_table_entry
*) what
;
9602 /* Check whether we have already seen this CU and set up SYM_NUM
9605 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
9607 struct cu_hash_table_entry dummy
;
9608 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
9610 dummy
.max_comdat_num
= 0;
9612 slot
= (struct cu_hash_table_entry
**)
9613 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
9617 for (; entry
; last
= entry
, entry
= entry
->next
)
9619 if (same_die_p_wrap (cu
, entry
->cu
))
9625 *sym_num
= entry
->min_comdat_num
;
9629 entry
= XCNEW (struct cu_hash_table_entry
);
9631 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
9632 entry
->next
= *slot
;
9638 /* Record SYM_NUM to record of CU in HTABLE. */
9640 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
9642 struct cu_hash_table_entry
**slot
, *entry
;
9644 slot
= (struct cu_hash_table_entry
**)
9645 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
9649 entry
->max_comdat_num
= sym_num
;
9652 /* Traverse the DIE (which is always comp_unit_die), and set up
9653 additional compilation units for each of the include files we see
9654 bracketed by BINCL/EINCL. */
9657 break_out_includes (dw_die_ref die
)
9660 dw_die_ref unit
= NULL
;
9661 limbo_die_node
*node
, **pnode
;
9662 htab_t cu_hash_table
;
9666 dw_die_ref prev
= c
;
9668 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
9669 || (unit
&& is_comdat_die (c
)))
9671 dw_die_ref next
= c
->die_sib
;
9673 /* This DIE is for a secondary CU; remove it from the main one. */
9674 remove_child_with_prev (c
, prev
);
9676 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
9677 unit
= push_new_compile_unit (unit
, c
);
9678 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
9679 unit
= pop_compile_unit (unit
);
9681 add_child_die (unit
, c
);
9683 if (c
== die
->die_child
)
9686 } while (c
!= die
->die_child
);
9689 /* We can only use this in debugging, since the frontend doesn't check
9690 to make sure that we leave every include file we enter. */
9694 assign_symbol_names (die
);
9695 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
9696 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
9702 compute_section_prefix (node
->die
);
9703 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
9704 &comdat_symbol_number
);
9705 assign_symbol_names (node
->die
);
9707 *pnode
= node
->next
;
9710 pnode
= &node
->next
;
9711 record_comdat_symbol_number (node
->die
, cu_hash_table
,
9712 comdat_symbol_number
);
9715 htab_delete (cu_hash_table
);
9718 /* Return non-zero if this DIE is a declaration. */
9721 is_declaration_die (dw_die_ref die
)
9726 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
9727 if (a
->dw_attr
== DW_AT_declaration
)
9733 /* Return non-zero if this DIE is nested inside a subprogram. */
9736 is_nested_in_subprogram (dw_die_ref die
)
9738 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
9742 return local_scope_p (decl
);
9745 /* Return non-zero if this is a type DIE that should be moved to a
9746 COMDAT .debug_types section. */
9749 should_move_die_to_comdat (dw_die_ref die
)
9751 switch (die
->die_tag
)
9753 case DW_TAG_class_type
:
9754 case DW_TAG_structure_type
:
9755 case DW_TAG_enumeration_type
:
9756 case DW_TAG_union_type
:
9757 /* Don't move declarations, inlined instances, or types nested in a
9759 if (is_declaration_die (die
)
9760 || get_AT (die
, DW_AT_abstract_origin
)
9761 || is_nested_in_subprogram (die
))
9764 case DW_TAG_array_type
:
9765 case DW_TAG_interface_type
:
9766 case DW_TAG_pointer_type
:
9767 case DW_TAG_reference_type
:
9768 case DW_TAG_rvalue_reference_type
:
9769 case DW_TAG_string_type
:
9770 case DW_TAG_subroutine_type
:
9771 case DW_TAG_ptr_to_member_type
:
9772 case DW_TAG_set_type
:
9773 case DW_TAG_subrange_type
:
9774 case DW_TAG_base_type
:
9775 case DW_TAG_const_type
:
9776 case DW_TAG_file_type
:
9777 case DW_TAG_packed_type
:
9778 case DW_TAG_volatile_type
:
9779 case DW_TAG_typedef
:
9785 /* Make a clone of DIE. */
9788 clone_die (dw_die_ref die
)
9794 clone
= ggc_alloc_cleared_die_node ();
9795 clone
->die_tag
= die
->die_tag
;
9797 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
9798 add_dwarf_attr (clone
, a
);
9803 /* Make a clone of the tree rooted at DIE. */
9806 clone_tree (dw_die_ref die
)
9809 dw_die_ref clone
= clone_die (die
);
9811 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree(c
)));
9816 /* Make a clone of DIE as a declaration. */
9819 clone_as_declaration (dw_die_ref die
)
9826 /* If the DIE is already a declaration, just clone it. */
9827 if (is_declaration_die (die
))
9828 return clone_die (die
);
9830 /* If the DIE is a specification, just clone its declaration DIE. */
9831 decl
= get_AT_ref (die
, DW_AT_specification
);
9833 return clone_die (decl
);
9835 clone
= ggc_alloc_cleared_die_node ();
9836 clone
->die_tag
= die
->die_tag
;
9838 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
9840 /* We don't want to copy over all attributes.
9841 For example we don't want DW_AT_byte_size because otherwise we will no
9842 longer have a declaration and GDB will treat it as a definition. */
9846 case DW_AT_artificial
:
9847 case DW_AT_containing_type
:
9848 case DW_AT_external
:
9851 case DW_AT_virtuality
:
9852 case DW_AT_linkage_name
:
9853 case DW_AT_MIPS_linkage_name
:
9854 add_dwarf_attr (clone
, a
);
9856 case DW_AT_byte_size
:
9862 if (die
->die_id
.die_type_node
)
9863 add_AT_die_ref (clone
, DW_AT_signature
, die
);
9865 add_AT_flag (clone
, DW_AT_declaration
, 1);
9869 /* Copy the declaration context to the new compile unit DIE. This includes
9870 any surrounding namespace or type declarations. If the DIE has an
9871 AT_specification attribute, it also includes attributes and children
9872 attached to the specification. */
9875 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
9878 dw_die_ref new_decl
;
9880 decl
= get_AT_ref (die
, DW_AT_specification
);
9889 /* Copy the type node pointer from the new DIE to the original
9890 declaration DIE so we can forward references later. */
9891 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
9893 remove_AT (die
, DW_AT_specification
);
9895 FOR_EACH_VEC_ELT (dw_attr_node
, decl
->die_attr
, ix
, a
)
9897 if (a
->dw_attr
!= DW_AT_name
9898 && a
->dw_attr
!= DW_AT_declaration
9899 && a
->dw_attr
!= DW_AT_external
)
9900 add_dwarf_attr (die
, a
);
9903 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree(c
)));
9906 if (decl
->die_parent
!= NULL
9907 && decl
->die_parent
->die_tag
!= DW_TAG_compile_unit
9908 && decl
->die_parent
->die_tag
!= DW_TAG_type_unit
)
9910 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
9911 if (new_decl
!= NULL
)
9913 remove_AT (new_decl
, DW_AT_signature
);
9914 add_AT_specification (die
, new_decl
);
9919 /* Generate the skeleton ancestor tree for the given NODE, then clone
9920 the DIE and add the clone into the tree. */
9923 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
9925 if (node
->new_die
!= NULL
)
9928 node
->new_die
= clone_as_declaration (node
->old_die
);
9930 if (node
->parent
!= NULL
)
9932 generate_skeleton_ancestor_tree (node
->parent
);
9933 add_child_die (node
->parent
->new_die
, node
->new_die
);
9937 /* Generate a skeleton tree of DIEs containing any declarations that are
9938 found in the original tree. We traverse the tree looking for declaration
9939 DIEs, and construct the skeleton from the bottom up whenever we find one. */
9942 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
9944 skeleton_chain_node node
;
9947 dw_die_ref prev
= NULL
;
9948 dw_die_ref next
= NULL
;
9950 node
.parent
= parent
;
9952 first
= c
= parent
->old_die
->die_child
;
9956 if (prev
== NULL
|| prev
->die_sib
== c
)
9959 next
= (c
== first
? NULL
: c
->die_sib
);
9961 node
.new_die
= NULL
;
9962 if (is_declaration_die (c
))
9964 /* Clone the existing DIE, move the original to the skeleton
9965 tree (which is in the main CU), and put the clone, with
9966 all the original's children, where the original came from. */
9967 dw_die_ref clone
= clone_die (c
);
9968 move_all_children (c
, clone
);
9970 replace_child (c
, clone
, prev
);
9971 generate_skeleton_ancestor_tree (parent
);
9972 add_child_die (parent
->new_die
, c
);
9976 generate_skeleton_bottom_up (&node
);
9977 } while (next
!= NULL
);
9980 /* Wrapper function for generate_skeleton_bottom_up. */
9983 generate_skeleton (dw_die_ref die
)
9985 skeleton_chain_node node
;
9988 node
.new_die
= NULL
;
9991 /* If this type definition is nested inside another type,
9992 always leave at least a declaration in its place. */
9993 if (die
->die_parent
!= NULL
&& is_type_die (die
->die_parent
))
9994 node
.new_die
= clone_as_declaration (die
);
9996 generate_skeleton_bottom_up (&node
);
9997 return node
.new_die
;
10000 /* Remove the DIE from its parent, possibly replacing it with a cloned
10001 declaration. The original DIE will be moved to a new compile unit
10002 so that existing references to it follow it to the new location. If
10003 any of the original DIE's descendants is a declaration, we need to
10004 replace the original DIE with a skeleton tree and move the
10005 declarations back into the skeleton tree. */
10008 remove_child_or_replace_with_skeleton (dw_die_ref child
, dw_die_ref prev
)
10010 dw_die_ref skeleton
;
10012 skeleton
= generate_skeleton (child
);
10013 if (skeleton
== NULL
)
10014 remove_child_with_prev (child
, prev
);
10017 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
10018 replace_child (child
, skeleton
, prev
);
10024 /* Traverse the DIE and set up additional .debug_types sections for each
10025 type worthy of being placed in a COMDAT section. */
10028 break_out_comdat_types (dw_die_ref die
)
10032 dw_die_ref prev
= NULL
;
10033 dw_die_ref next
= NULL
;
10034 dw_die_ref unit
= NULL
;
10036 first
= c
= die
->die_child
;
10040 if (prev
== NULL
|| prev
->die_sib
== c
)
10043 next
= (c
== first
? NULL
: c
->die_sib
);
10044 if (should_move_die_to_comdat (c
))
10046 dw_die_ref replacement
;
10047 comdat_type_node_ref type_node
;
10049 /* Create a new type unit DIE as the root for the new tree, and
10050 add it to the list of comdat types. */
10051 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
10052 add_AT_unsigned (unit
, DW_AT_language
,
10053 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
10054 type_node
= ggc_alloc_cleared_comdat_type_node ();
10055 type_node
->root_die
= unit
;
10056 type_node
->next
= comdat_type_list
;
10057 comdat_type_list
= type_node
;
10059 /* Generate the type signature. */
10060 generate_type_signature (c
, type_node
);
10062 /* Copy the declaration context, attributes, and children of the
10063 declaration into the new compile unit DIE. */
10064 copy_declaration_context (unit
, c
);
10066 /* Remove this DIE from the main CU. */
10067 replacement
= remove_child_or_replace_with_skeleton (c
, prev
);
10069 /* Break out nested types into their own type units. */
10070 break_out_comdat_types (c
);
10072 /* Add the DIE to the new compunit. */
10073 add_child_die (unit
, c
);
10075 if (replacement
!= NULL
)
10078 else if (c
->die_tag
== DW_TAG_namespace
10079 || c
->die_tag
== DW_TAG_class_type
10080 || c
->die_tag
== DW_TAG_structure_type
10081 || c
->die_tag
== DW_TAG_union_type
)
10083 /* Look for nested types that can be broken out. */
10084 break_out_comdat_types (c
);
10086 } while (next
!= NULL
);
10089 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
10091 struct decl_table_entry
10097 /* Routines to manipulate hash table of copied declarations. */
10100 htab_decl_hash (const void *of
)
10102 const struct decl_table_entry
*const entry
=
10103 (const struct decl_table_entry
*) of
;
10105 return htab_hash_pointer (entry
->orig
);
10109 htab_decl_eq (const void *of1
, const void *of2
)
10111 const struct decl_table_entry
*const entry1
=
10112 (const struct decl_table_entry
*) of1
;
10113 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
10115 return entry1
->orig
== entry2
;
10119 htab_decl_del (void *what
)
10121 struct decl_table_entry
*entry
= (struct decl_table_entry
*) what
;
10126 /* Copy DIE and its ancestors, up to, but not including, the compile unit
10127 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
10128 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
10129 to check if the ancestor has already been copied into UNIT. */
10132 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
10134 dw_die_ref parent
= die
->die_parent
;
10135 dw_die_ref new_parent
= unit
;
10137 void **slot
= NULL
;
10138 struct decl_table_entry
*entry
= NULL
;
10142 /* Check if the entry has already been copied to UNIT. */
10143 slot
= htab_find_slot_with_hash (decl_table
, die
,
10144 htab_hash_pointer (die
), INSERT
);
10145 if (*slot
!= HTAB_EMPTY_ENTRY
)
10147 entry
= (struct decl_table_entry
*) *slot
;
10148 return entry
->copy
;
10151 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
10152 entry
= XCNEW (struct decl_table_entry
);
10154 entry
->copy
= NULL
;
10158 if (parent
!= NULL
)
10160 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
10163 if (parent
->die_tag
!= DW_TAG_compile_unit
10164 && parent
->die_tag
!= DW_TAG_type_unit
)
10165 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
10168 copy
= clone_as_declaration (die
);
10169 add_child_die (new_parent
, copy
);
10171 if (decl_table
!= NULL
)
10173 /* Record the pointer to the copy. */
10174 entry
->copy
= copy
;
10180 /* Walk the DIE and its children, looking for references to incomplete
10181 or trivial types that are unmarked (i.e., that are not in the current
10185 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
10191 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
10193 if (AT_class (a
) == dw_val_class_die_ref
)
10195 dw_die_ref targ
= AT_ref (a
);
10196 comdat_type_node_ref type_node
= targ
->die_id
.die_type_node
;
10198 struct decl_table_entry
*entry
;
10200 if (targ
->die_mark
!= 0 || type_node
!= NULL
)
10203 slot
= htab_find_slot_with_hash (decl_table
, targ
,
10204 htab_hash_pointer (targ
), INSERT
);
10206 if (*slot
!= HTAB_EMPTY_ENTRY
)
10208 /* TARG has already been copied, so we just need to
10209 modify the reference to point to the copy. */
10210 entry
= (struct decl_table_entry
*) *slot
;
10211 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
10215 dw_die_ref parent
= unit
;
10216 dw_die_ref copy
= clone_tree (targ
);
10218 /* Make sure the cloned tree is marked as part of the
10222 /* Record in DECL_TABLE that TARG has been copied.
10223 Need to do this now, before the recursive call,
10224 because DECL_TABLE may be expanded and SLOT
10225 would no longer be a valid pointer. */
10226 entry
= XCNEW (struct decl_table_entry
);
10227 entry
->orig
= targ
;
10228 entry
->copy
= copy
;
10231 /* If TARG has surrounding context, copy its ancestor tree
10232 into the new type unit. */
10233 if (targ
->die_parent
!= NULL
10234 && targ
->die_parent
->die_tag
!= DW_TAG_compile_unit
10235 && targ
->die_parent
->die_tag
!= DW_TAG_type_unit
)
10236 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
10239 add_child_die (parent
, copy
);
10240 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
10242 /* Make sure the newly-copied DIE is walked. If it was
10243 installed in a previously-added context, it won't
10244 get visited otherwise. */
10245 if (parent
!= unit
)
10247 /* Find the highest point of the newly-added tree,
10248 mark each node along the way, and walk from there. */
10249 parent
->die_mark
= 1;
10250 while (parent
->die_parent
10251 && parent
->die_parent
->die_mark
== 0)
10253 parent
= parent
->die_parent
;
10254 parent
->die_mark
= 1;
10256 copy_decls_walk (unit
, parent
, decl_table
);
10262 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
10265 /* Copy declarations for "unworthy" types into the new comdat section.
10266 Incomplete types, modified types, and certain other types aren't broken
10267 out into comdat sections of their own, so they don't have a signature,
10268 and we need to copy the declaration into the same section so that we
10269 don't have an external reference. */
10272 copy_decls_for_unworthy_types (dw_die_ref unit
)
10277 decl_table
= htab_create (10, htab_decl_hash
, htab_decl_eq
, htab_decl_del
);
10278 copy_decls_walk (unit
, unit
, decl_table
);
10279 htab_delete (decl_table
);
10280 unmark_dies (unit
);
10283 /* Traverse the DIE and add a sibling attribute if it may have the
10284 effect of speeding up access to siblings. To save some space,
10285 avoid generating sibling attributes for DIE's without children. */
10288 add_sibling_attributes (dw_die_ref die
)
10292 if (! die
->die_child
)
10295 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
10296 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
10298 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
10301 /* Output all location lists for the DIE and its children. */
10304 output_location_lists (dw_die_ref die
)
10310 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
10311 if (AT_class (a
) == dw_val_class_loc_list
)
10312 output_loc_list (AT_loc_list (a
));
10314 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
10317 /* The format of each DIE (and its attribute value pairs) is encoded in an
10318 abbreviation table. This routine builds the abbreviation table and assigns
10319 a unique abbreviation id for each abbreviation entry. The children of each
10320 die are visited recursively. */
10323 build_abbrev_table (dw_die_ref die
)
10325 unsigned long abbrev_id
;
10326 unsigned int n_alloc
;
10331 /* Scan the DIE references, and mark as external any that refer to
10332 DIEs from other CUs (i.e. those which are not marked). */
10333 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
10334 if (AT_class (a
) == dw_val_class_die_ref
10335 && AT_ref (a
)->die_mark
== 0)
10337 gcc_assert (dwarf_version
>= 4 || AT_ref (a
)->die_id
.die_symbol
);
10338 set_AT_ref_external (a
, 1);
10341 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
10343 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
10344 dw_attr_ref die_a
, abbrev_a
;
10348 if (abbrev
->die_tag
!= die
->die_tag
)
10350 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
10353 if (VEC_length (dw_attr_node
, abbrev
->die_attr
)
10354 != VEC_length (dw_attr_node
, die
->die_attr
))
10357 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, die_a
)
10359 abbrev_a
= VEC_index (dw_attr_node
, abbrev
->die_attr
, ix
);
10360 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
10361 || (value_format (abbrev_a
) != value_format (die_a
)))
10371 if (abbrev_id
>= abbrev_die_table_in_use
)
10373 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
10375 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
10376 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
10379 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
10380 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
10381 abbrev_die_table_allocated
= n_alloc
;
10384 ++abbrev_die_table_in_use
;
10385 abbrev_die_table
[abbrev_id
] = die
;
10388 die
->die_abbrev
= abbrev_id
;
10389 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
));
10392 /* Return the power-of-two number of bytes necessary to represent VALUE. */
10395 constant_size (unsigned HOST_WIDE_INT value
)
10402 log
= floor_log2 (value
);
10405 log
= 1 << (floor_log2 (log
) + 1);
10410 /* Return the size of a DIE as it is represented in the
10411 .debug_info section. */
10413 static unsigned long
10414 size_of_die (dw_die_ref die
)
10416 unsigned long size
= 0;
10420 size
+= size_of_uleb128 (die
->die_abbrev
);
10421 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
10423 switch (AT_class (a
))
10425 case dw_val_class_addr
:
10426 size
+= DWARF2_ADDR_SIZE
;
10428 case dw_val_class_offset
:
10429 size
+= DWARF_OFFSET_SIZE
;
10431 case dw_val_class_loc
:
10433 unsigned long lsize
= size_of_locs (AT_loc (a
));
10435 /* Block length. */
10436 if (dwarf_version
>= 4)
10437 size
+= size_of_uleb128 (lsize
);
10439 size
+= constant_size (lsize
);
10443 case dw_val_class_loc_list
:
10444 size
+= DWARF_OFFSET_SIZE
;
10446 case dw_val_class_range_list
:
10447 size
+= DWARF_OFFSET_SIZE
;
10449 case dw_val_class_const
:
10450 size
+= size_of_sleb128 (AT_int (a
));
10452 case dw_val_class_unsigned_const
:
10453 size
+= constant_size (AT_unsigned (a
));
10455 case dw_val_class_const_double
:
10456 size
+= 2 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
10457 if (HOST_BITS_PER_WIDE_INT
>= 64)
10458 size
++; /* block */
10460 case dw_val_class_vec
:
10461 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
10462 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
10463 + a
->dw_attr_val
.v
.val_vec
.length
10464 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
10466 case dw_val_class_flag
:
10467 if (dwarf_version
>= 4)
10468 /* Currently all add_AT_flag calls pass in 1 as last argument,
10469 so DW_FORM_flag_present can be used. If that ever changes,
10470 we'll need to use DW_FORM_flag and have some optimization
10471 in build_abbrev_table that will change those to
10472 DW_FORM_flag_present if it is set to 1 in all DIEs using
10473 the same abbrev entry. */
10474 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
10478 case dw_val_class_die_ref
:
10479 if (AT_ref_external (a
))
10481 /* In DWARF4, we use DW_FORM_sig8; for earlier versions
10482 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
10483 is sized by target address length, whereas in DWARF3
10484 it's always sized as an offset. */
10485 if (dwarf_version
>= 4)
10486 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
10487 else if (dwarf_version
== 2)
10488 size
+= DWARF2_ADDR_SIZE
;
10490 size
+= DWARF_OFFSET_SIZE
;
10493 size
+= DWARF_OFFSET_SIZE
;
10495 case dw_val_class_fde_ref
:
10496 size
+= DWARF_OFFSET_SIZE
;
10498 case dw_val_class_lbl_id
:
10499 size
+= DWARF2_ADDR_SIZE
;
10501 case dw_val_class_lineptr
:
10502 case dw_val_class_macptr
:
10503 size
+= DWARF_OFFSET_SIZE
;
10505 case dw_val_class_str
:
10506 if (AT_string_form (a
) == DW_FORM_strp
)
10507 size
+= DWARF_OFFSET_SIZE
;
10509 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
10511 case dw_val_class_file
:
10512 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
10514 case dw_val_class_data8
:
10517 case dw_val_class_vms_delta
:
10518 size
+= DWARF_OFFSET_SIZE
;
10521 gcc_unreachable ();
10528 /* Size the debugging information associated with a given DIE. Visits the
10529 DIE's children recursively. Updates the global variable next_die_offset, on
10530 each time through. Uses the current value of next_die_offset to update the
10531 die_offset field in each DIE. */
10534 calc_die_sizes (dw_die_ref die
)
10538 die
->die_offset
= next_die_offset
;
10539 next_die_offset
+= size_of_die (die
);
10541 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
10543 if (die
->die_child
!= NULL
)
10544 /* Count the null byte used to terminate sibling lists. */
10545 next_die_offset
+= 1;
10548 /* Set the marks for a die and its children. We do this so
10549 that we know whether or not a reference needs to use FORM_ref_addr; only
10550 DIEs in the same CU will be marked. We used to clear out the offset
10551 and use that as the flag, but ran into ordering problems. */
10554 mark_dies (dw_die_ref die
)
10558 gcc_assert (!die
->die_mark
);
10561 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
10564 /* Clear the marks for a die and its children. */
10567 unmark_dies (dw_die_ref die
)
10571 if (dwarf_version
< 4)
10572 gcc_assert (die
->die_mark
);
10575 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
10578 /* Clear the marks for a die, its children and referred dies. */
10581 unmark_all_dies (dw_die_ref die
)
10587 if (!die
->die_mark
)
10591 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
10593 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
10594 if (AT_class (a
) == dw_val_class_die_ref
)
10595 unmark_all_dies (AT_ref (a
));
10598 /* Return the size of the .debug_pubnames or .debug_pubtypes table
10599 generated for the compilation unit. */
10601 static unsigned long
10602 size_of_pubnames (VEC (pubname_entry
, gc
) * names
)
10604 unsigned long size
;
10608 size
= DWARF_PUBNAMES_HEADER_SIZE
;
10609 FOR_EACH_VEC_ELT (pubname_entry
, names
, i
, p
)
10610 if (names
!= pubtype_table
10611 || p
->die
->die_offset
!= 0
10612 || !flag_eliminate_unused_debug_types
)
10613 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
10615 size
+= DWARF_OFFSET_SIZE
;
10619 /* Return the size of the information in the .debug_aranges section. */
10621 static unsigned long
10622 size_of_aranges (void)
10624 unsigned long size
;
10626 size
= DWARF_ARANGES_HEADER_SIZE
;
10628 /* Count the address/length pair for this compilation unit. */
10629 if (text_section_used
)
10630 size
+= 2 * DWARF2_ADDR_SIZE
;
10631 if (cold_text_section_used
)
10632 size
+= 2 * DWARF2_ADDR_SIZE
;
10633 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
10635 /* Count the two zero words used to terminated the address range table. */
10636 size
+= 2 * DWARF2_ADDR_SIZE
;
10640 /* Select the encoding of an attribute value. */
10642 static enum dwarf_form
10643 value_format (dw_attr_ref a
)
10645 switch (a
->dw_attr_val
.val_class
)
10647 case dw_val_class_addr
:
10648 /* Only very few attributes allow DW_FORM_addr. */
10649 switch (a
->dw_attr
)
10652 case DW_AT_high_pc
:
10653 case DW_AT_entry_pc
:
10654 case DW_AT_trampoline
:
10655 return DW_FORM_addr
;
10659 switch (DWARF2_ADDR_SIZE
)
10662 return DW_FORM_data1
;
10664 return DW_FORM_data2
;
10666 return DW_FORM_data4
;
10668 return DW_FORM_data8
;
10670 gcc_unreachable ();
10672 case dw_val_class_range_list
:
10673 case dw_val_class_loc_list
:
10674 if (dwarf_version
>= 4)
10675 return DW_FORM_sec_offset
;
10677 case dw_val_class_vms_delta
:
10678 case dw_val_class_offset
:
10679 switch (DWARF_OFFSET_SIZE
)
10682 return DW_FORM_data4
;
10684 return DW_FORM_data8
;
10686 gcc_unreachable ();
10688 case dw_val_class_loc
:
10689 if (dwarf_version
>= 4)
10690 return DW_FORM_exprloc
;
10691 switch (constant_size (size_of_locs (AT_loc (a
))))
10694 return DW_FORM_block1
;
10696 return DW_FORM_block2
;
10698 gcc_unreachable ();
10700 case dw_val_class_const
:
10701 return DW_FORM_sdata
;
10702 case dw_val_class_unsigned_const
:
10703 switch (constant_size (AT_unsigned (a
)))
10706 return DW_FORM_data1
;
10708 return DW_FORM_data2
;
10710 return DW_FORM_data4
;
10712 return DW_FORM_data8
;
10714 gcc_unreachable ();
10716 case dw_val_class_const_double
:
10717 switch (HOST_BITS_PER_WIDE_INT
)
10720 return DW_FORM_data2
;
10722 return DW_FORM_data4
;
10724 return DW_FORM_data8
;
10727 return DW_FORM_block1
;
10729 case dw_val_class_vec
:
10730 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
10731 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
10734 return DW_FORM_block1
;
10736 return DW_FORM_block2
;
10738 return DW_FORM_block4
;
10740 gcc_unreachable ();
10742 case dw_val_class_flag
:
10743 if (dwarf_version
>= 4)
10745 /* Currently all add_AT_flag calls pass in 1 as last argument,
10746 so DW_FORM_flag_present can be used. If that ever changes,
10747 we'll need to use DW_FORM_flag and have some optimization
10748 in build_abbrev_table that will change those to
10749 DW_FORM_flag_present if it is set to 1 in all DIEs using
10750 the same abbrev entry. */
10751 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
10752 return DW_FORM_flag_present
;
10754 return DW_FORM_flag
;
10755 case dw_val_class_die_ref
:
10756 if (AT_ref_external (a
))
10757 return dwarf_version
>= 4 ? DW_FORM_sig8
: DW_FORM_ref_addr
;
10759 return DW_FORM_ref
;
10760 case dw_val_class_fde_ref
:
10761 return DW_FORM_data
;
10762 case dw_val_class_lbl_id
:
10763 return DW_FORM_addr
;
10764 case dw_val_class_lineptr
:
10765 case dw_val_class_macptr
:
10766 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
10767 case dw_val_class_str
:
10768 return AT_string_form (a
);
10769 case dw_val_class_file
:
10770 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
10773 return DW_FORM_data1
;
10775 return DW_FORM_data2
;
10777 return DW_FORM_data4
;
10779 gcc_unreachable ();
10782 case dw_val_class_data8
:
10783 return DW_FORM_data8
;
10786 gcc_unreachable ();
10790 /* Output the encoding of an attribute value. */
10793 output_value_format (dw_attr_ref a
)
10795 enum dwarf_form form
= value_format (a
);
10797 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
10800 /* Output the .debug_abbrev section which defines the DIE abbreviation
10804 output_abbrev_section (void)
10806 unsigned long abbrev_id
;
10808 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
10810 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
10812 dw_attr_ref a_attr
;
10814 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
10815 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
10816 dwarf_tag_name (abbrev
->die_tag
));
10818 if (abbrev
->die_child
!= NULL
)
10819 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
10821 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
10823 for (ix
= 0; VEC_iterate (dw_attr_node
, abbrev
->die_attr
, ix
, a_attr
);
10826 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
10827 dwarf_attr_name (a_attr
->dw_attr
));
10828 output_value_format (a_attr
);
10831 dw2_asm_output_data (1, 0, NULL
);
10832 dw2_asm_output_data (1, 0, NULL
);
10835 /* Terminate the table. */
10836 dw2_asm_output_data (1, 0, NULL
);
10839 /* Output a symbol we can use to refer to this DIE from another CU. */
10842 output_die_symbol (dw_die_ref die
)
10844 char *sym
= die
->die_id
.die_symbol
;
10849 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
10850 /* We make these global, not weak; if the target doesn't support
10851 .linkonce, it doesn't support combining the sections, so debugging
10853 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
10855 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
10858 /* Return a new location list, given the begin and end range, and the
10861 static inline dw_loc_list_ref
10862 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
10863 const char *section
)
10865 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
10867 retlist
->begin
= begin
;
10868 retlist
->end
= end
;
10869 retlist
->expr
= expr
;
10870 retlist
->section
= section
;
10875 /* Generate a new internal symbol for this location list node, if it
10876 hasn't got one yet. */
10879 gen_llsym (dw_loc_list_ref list
)
10881 gcc_assert (!list
->ll_symbol
);
10882 list
->ll_symbol
= gen_internal_sym ("LLST");
10885 /* Output the location list given to us. */
10888 output_loc_list (dw_loc_list_ref list_head
)
10890 dw_loc_list_ref curr
= list_head
;
10892 if (list_head
->emitted
)
10894 list_head
->emitted
= true;
10896 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
10898 /* Walk the location list, and output each range + expression. */
10899 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
10901 unsigned long size
;
10902 /* Don't output an entry that starts and ends at the same address. */
10903 if (strcmp (curr
->begin
, curr
->end
) == 0)
10905 if (!have_multiple_function_sections
)
10907 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
10908 "Location list begin address (%s)",
10909 list_head
->ll_symbol
);
10910 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
10911 "Location list end address (%s)",
10912 list_head
->ll_symbol
);
10916 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
10917 "Location list begin address (%s)",
10918 list_head
->ll_symbol
);
10919 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
10920 "Location list end address (%s)",
10921 list_head
->ll_symbol
);
10923 size
= size_of_locs (curr
->expr
);
10925 /* Output the block length for this list of location operations. */
10926 gcc_assert (size
<= 0xffff);
10927 dw2_asm_output_data (2, size
, "%s", "Location expression size");
10929 output_loc_sequence (curr
->expr
);
10932 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
10933 "Location list terminator begin (%s)",
10934 list_head
->ll_symbol
);
10935 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
10936 "Location list terminator end (%s)",
10937 list_head
->ll_symbol
);
10940 /* Output a type signature. */
10943 output_signature (const char *sig
, const char *name
)
10947 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
10948 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
10951 /* Output the DIE and its attributes. Called recursively to generate
10952 the definitions of each child DIE. */
10955 output_die (dw_die_ref die
)
10959 unsigned long size
;
10962 /* If someone in another CU might refer to us, set up a symbol for
10963 them to point to. */
10964 if (dwarf_version
< 4 && die
->die_id
.die_symbol
)
10965 output_die_symbol (die
);
10967 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
10968 (unsigned long)die
->die_offset
,
10969 dwarf_tag_name (die
->die_tag
));
10971 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
10973 const char *name
= dwarf_attr_name (a
->dw_attr
);
10975 switch (AT_class (a
))
10977 case dw_val_class_addr
:
10978 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
10981 case dw_val_class_offset
:
10982 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
10986 case dw_val_class_range_list
:
10988 char *p
= strchr (ranges_section_label
, '\0');
10990 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
10991 a
->dw_attr_val
.v
.val_offset
);
10992 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
10993 debug_ranges_section
, "%s", name
);
10998 case dw_val_class_loc
:
10999 size
= size_of_locs (AT_loc (a
));
11001 /* Output the block length for this list of location operations. */
11002 if (dwarf_version
>= 4)
11003 dw2_asm_output_data_uleb128 (size
, "%s", name
);
11005 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
11007 output_loc_sequence (AT_loc (a
));
11010 case dw_val_class_const
:
11011 /* ??? It would be slightly more efficient to use a scheme like is
11012 used for unsigned constants below, but gdb 4.x does not sign
11013 extend. Gdb 5.x does sign extend. */
11014 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
11017 case dw_val_class_unsigned_const
:
11018 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
11019 AT_unsigned (a
), "%s", name
);
11022 case dw_val_class_const_double
:
11024 unsigned HOST_WIDE_INT first
, second
;
11026 if (HOST_BITS_PER_WIDE_INT
>= 64)
11027 dw2_asm_output_data (1,
11028 2 * HOST_BITS_PER_WIDE_INT
11029 / HOST_BITS_PER_CHAR
,
11032 if (WORDS_BIG_ENDIAN
)
11034 first
= a
->dw_attr_val
.v
.val_double
.high
;
11035 second
= a
->dw_attr_val
.v
.val_double
.low
;
11039 first
= a
->dw_attr_val
.v
.val_double
.low
;
11040 second
= a
->dw_attr_val
.v
.val_double
.high
;
11043 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
11045 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
11050 case dw_val_class_vec
:
11052 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
11053 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
11057 dw2_asm_output_data (constant_size (len
* elt_size
),
11058 len
* elt_size
, "%s", name
);
11059 if (elt_size
> sizeof (HOST_WIDE_INT
))
11064 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
11066 i
++, p
+= elt_size
)
11067 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
11068 "fp or vector constant word %u", i
);
11072 case dw_val_class_flag
:
11073 if (dwarf_version
>= 4)
11075 /* Currently all add_AT_flag calls pass in 1 as last argument,
11076 so DW_FORM_flag_present can be used. If that ever changes,
11077 we'll need to use DW_FORM_flag and have some optimization
11078 in build_abbrev_table that will change those to
11079 DW_FORM_flag_present if it is set to 1 in all DIEs using
11080 the same abbrev entry. */
11081 gcc_assert (AT_flag (a
) == 1);
11082 if (flag_debug_asm
)
11083 fprintf (asm_out_file
, "\t\t\t%s %s\n",
11084 ASM_COMMENT_START
, name
);
11087 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
11090 case dw_val_class_loc_list
:
11092 char *sym
= AT_loc_list (a
)->ll_symbol
;
11095 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
11100 case dw_val_class_die_ref
:
11101 if (AT_ref_external (a
))
11103 if (dwarf_version
>= 4)
11105 comdat_type_node_ref type_node
=
11106 AT_ref (a
)->die_id
.die_type_node
;
11108 gcc_assert (type_node
);
11109 output_signature (type_node
->signature
, name
);
11113 char *sym
= AT_ref (a
)->die_id
.die_symbol
;
11117 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11118 length, whereas in DWARF3 it's always sized as an
11120 if (dwarf_version
== 2)
11121 size
= DWARF2_ADDR_SIZE
;
11123 size
= DWARF_OFFSET_SIZE
;
11124 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
11130 gcc_assert (AT_ref (a
)->die_offset
);
11131 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
11136 case dw_val_class_fde_ref
:
11140 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
11141 a
->dw_attr_val
.v
.val_fde_index
* 2);
11142 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
11147 case dw_val_class_vms_delta
:
11148 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
11149 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
11153 case dw_val_class_lbl_id
:
11154 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
11157 case dw_val_class_lineptr
:
11158 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
11159 debug_line_section
, "%s", name
);
11162 case dw_val_class_macptr
:
11163 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
11164 debug_macinfo_section
, "%s", name
);
11167 case dw_val_class_str
:
11168 if (AT_string_form (a
) == DW_FORM_strp
)
11169 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
11170 a
->dw_attr_val
.v
.val_str
->label
,
11172 "%s: \"%s\"", name
, AT_string (a
));
11174 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
11177 case dw_val_class_file
:
11179 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
11181 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
11182 a
->dw_attr_val
.v
.val_file
->filename
);
11186 case dw_val_class_data8
:
11190 for (i
= 0; i
< 8; i
++)
11191 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
11192 i
== 0 ? "%s" : NULL
, name
);
11197 gcc_unreachable ();
11201 FOR_EACH_CHILD (die
, c
, output_die (c
));
11203 /* Add null byte to terminate sibling list. */
11204 if (die
->die_child
!= NULL
)
11205 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11206 (unsigned long) die
->die_offset
);
11209 /* Output the compilation unit that appears at the beginning of the
11210 .debug_info section, and precedes the DIE descriptions. */
11213 output_compilation_unit_header (void)
11215 int ver
= dwarf_version
;
11217 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11218 dw2_asm_output_data (4, 0xffffffff,
11219 "Initial length escape value indicating 64-bit DWARF extension");
11220 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
11221 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
11222 "Length of Compilation Unit Info");
11223 dw2_asm_output_data (2, ver
, "DWARF version number");
11224 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
11225 debug_abbrev_section
,
11226 "Offset Into Abbrev. Section");
11227 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
11230 /* Output the compilation unit DIE and its children. */
11233 output_comp_unit (dw_die_ref die
, int output_if_empty
)
11235 const char *secname
;
11236 char *oldsym
, *tmp
;
11238 /* Unless we are outputting main CU, we may throw away empty ones. */
11239 if (!output_if_empty
&& die
->die_child
== NULL
)
11242 /* Even if there are no children of this DIE, we must output the information
11243 about the compilation unit. Otherwise, on an empty translation unit, we
11244 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11245 will then complain when examining the file. First mark all the DIEs in
11246 this CU so we know which get local refs. */
11249 build_abbrev_table (die
);
11251 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11252 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
11253 calc_die_sizes (die
);
11255 oldsym
= die
->die_id
.die_symbol
;
11258 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
11260 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
11262 die
->die_id
.die_symbol
= NULL
;
11263 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
11266 switch_to_section (debug_info_section
);
11268 /* Output debugging information. */
11269 output_compilation_unit_header ();
11272 /* Leave the marks on the main CU, so we can check them in
11273 output_pubnames. */
11277 die
->die_id
.die_symbol
= oldsym
;
11281 /* Output a comdat type unit DIE and its children. */
11284 output_comdat_type_unit (comdat_type_node
*node
)
11286 const char *secname
;
11289 #if defined (OBJECT_FORMAT_ELF)
11293 /* First mark all the DIEs in this CU so we know which get local refs. */
11294 mark_dies (node
->root_die
);
11296 build_abbrev_table (node
->root_die
);
11298 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11299 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
11300 calc_die_sizes (node
->root_die
);
11302 #if defined (OBJECT_FORMAT_ELF)
11303 secname
= ".debug_types";
11304 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
11305 sprintf (tmp
, "wt.");
11306 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
11307 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
11308 comdat_key
= get_identifier (tmp
);
11309 targetm
.asm_out
.named_section (secname
,
11310 SECTION_DEBUG
| SECTION_LINKONCE
,
11313 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
11314 sprintf (tmp
, ".gnu.linkonce.wt.");
11315 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
11316 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
11318 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
11321 /* Output debugging information. */
11322 output_compilation_unit_header ();
11323 output_signature (node
->signature
, "Type Signature");
11324 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
11325 "Offset to Type DIE");
11326 output_die (node
->root_die
);
11328 unmark_dies (node
->root_die
);
11331 /* Return the DWARF2/3 pubname associated with a decl. */
11333 static const char *
11334 dwarf2_name (tree decl
, int scope
)
11336 if (DECL_NAMELESS (decl
))
11338 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
11341 /* Add a new entry to .debug_pubnames if appropriate. */
11344 add_pubname_string (const char *str
, dw_die_ref die
)
11346 if (targetm
.want_debug_pub_sections
)
11351 e
.name
= xstrdup (str
);
11352 VEC_safe_push (pubname_entry
, gc
, pubname_table
, &e
);
11357 add_pubname (tree decl
, dw_die_ref die
)
11359 if (targetm
.want_debug_pub_sections
&& TREE_PUBLIC (decl
))
11361 const char *name
= dwarf2_name (decl
, 1);
11363 add_pubname_string (name
, die
);
11367 /* Add a new entry to .debug_pubtypes if appropriate. */
11370 add_pubtype (tree decl
, dw_die_ref die
)
11374 if (!targetm
.want_debug_pub_sections
)
11378 if ((TREE_PUBLIC (decl
)
11379 || is_cu_die (die
->die_parent
))
11380 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
11385 if (TYPE_NAME (decl
))
11387 if (TREE_CODE (TYPE_NAME (decl
)) == IDENTIFIER_NODE
)
11388 e
.name
= IDENTIFIER_POINTER (TYPE_NAME (decl
));
11389 else if (TREE_CODE (TYPE_NAME (decl
)) == TYPE_DECL
11390 && DECL_NAME (TYPE_NAME (decl
)))
11391 e
.name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl
)));
11393 e
.name
= xstrdup ((const char *) get_AT_string (die
, DW_AT_name
));
11398 e
.name
= dwarf2_name (decl
, 1);
11400 e
.name
= xstrdup (e
.name
);
11403 /* If we don't have a name for the type, there's no point in adding
11404 it to the table. */
11405 if (e
.name
&& e
.name
[0] != '\0')
11406 VEC_safe_push (pubname_entry
, gc
, pubtype_table
, &e
);
11410 /* Output the public names table used to speed up access to externally
11411 visible names; or the public types table used to find type definitions. */
11414 output_pubnames (VEC (pubname_entry
, gc
) * names
)
11417 unsigned long pubnames_length
= size_of_pubnames (names
);
11420 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11421 dw2_asm_output_data (4, 0xffffffff,
11422 "Initial length escape value indicating 64-bit DWARF extension");
11423 if (names
== pubname_table
)
11424 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
11425 "Length of Public Names Info");
11427 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
11428 "Length of Public Type Names Info");
11429 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
11430 dw2_asm_output_data (2, 2, "DWARF Version");
11431 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
11432 debug_info_section
,
11433 "Offset of Compilation Unit Info");
11434 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
11435 "Compilation Unit Length");
11437 FOR_EACH_VEC_ELT (pubname_entry
, names
, i
, pub
)
11439 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11440 if (names
== pubname_table
)
11441 gcc_assert (pub
->die
->die_mark
);
11443 if (names
!= pubtype_table
11444 || pub
->die
->die_offset
!= 0
11445 || !flag_eliminate_unused_debug_types
)
11447 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
11450 dw2_asm_output_nstring (pub
->name
, -1, "external name");
11454 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
11457 /* Add a new entry to .debug_aranges if appropriate. */
11460 add_arange (tree decl
, dw_die_ref die
)
11462 if (! DECL_SECTION_NAME (decl
))
11465 if (arange_table_in_use
== arange_table_allocated
)
11467 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
11468 arange_table
= GGC_RESIZEVEC (dw_die_ref
, arange_table
,
11469 arange_table_allocated
);
11470 memset (arange_table
+ arange_table_in_use
, 0,
11471 ARANGE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
11474 arange_table
[arange_table_in_use
++] = die
;
11477 /* Output the information that goes into the .debug_aranges table.
11478 Namely, define the beginning and ending address range of the
11479 text section generated for this compilation unit. */
11482 output_aranges (void)
11485 unsigned long aranges_length
= size_of_aranges ();
11487 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11488 dw2_asm_output_data (4, 0xffffffff,
11489 "Initial length escape value indicating 64-bit DWARF extension");
11490 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
11491 "Length of Address Ranges Info");
11492 /* Version number for aranges is still 2, even in DWARF3. */
11493 dw2_asm_output_data (2, 2, "DWARF Version");
11494 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
11495 debug_info_section
,
11496 "Offset of Compilation Unit Info");
11497 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
11498 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11500 /* We need to align to twice the pointer size here. */
11501 if (DWARF_ARANGES_PAD_SIZE
)
11503 /* Pad using a 2 byte words so that padding is correct for any
11505 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11506 2 * DWARF2_ADDR_SIZE
);
11507 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
11508 dw2_asm_output_data (2, 0, NULL
);
11511 /* It is necessary not to output these entries if the sections were
11512 not used; if the sections were not used, the length will be 0 and
11513 the address may end up as 0 if the section is discarded by ld
11514 --gc-sections, leaving an invalid (0, 0) entry that can be
11515 confused with the terminator. */
11516 if (text_section_used
)
11518 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
11519 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
11520 text_section_label
, "Length");
11522 if (cold_text_section_used
)
11524 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
11526 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
11527 cold_text_section_label
, "Length");
11530 for (i
= 0; i
< arange_table_in_use
; i
++)
11532 dw_die_ref die
= arange_table
[i
];
11534 /* We shouldn't see aranges for DIEs outside of the main CU. */
11535 gcc_assert (die
->die_mark
);
11537 if (die
->die_tag
== DW_TAG_subprogram
)
11539 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
11541 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
11542 get_AT_low_pc (die
), "Length");
11546 /* A static variable; extract the symbol from DW_AT_location.
11547 Note that this code isn't currently hit, as we only emit
11548 aranges for functions (jason 9/23/99). */
11549 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
11550 dw_loc_descr_ref loc
;
11552 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
11555 gcc_assert (loc
->dw_loc_opc
== DW_OP_addr
);
11557 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
11558 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
11559 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
11560 get_AT_unsigned (die
, DW_AT_byte_size
),
11565 /* Output the terminator words. */
11566 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11567 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11570 /* Add a new entry to .debug_ranges. Return the offset at which it
11573 static unsigned int
11574 add_ranges_num (int num
)
11576 unsigned int in_use
= ranges_table_in_use
;
11578 if (in_use
== ranges_table_allocated
)
11580 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
11581 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
11582 ranges_table_allocated
);
11583 memset (ranges_table
+ ranges_table_in_use
, 0,
11584 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
11587 ranges_table
[in_use
].num
= num
;
11588 ranges_table_in_use
= in_use
+ 1;
11590 return in_use
* 2 * DWARF2_ADDR_SIZE
;
11593 /* Add a new entry to .debug_ranges corresponding to a block, or a
11594 range terminator if BLOCK is NULL. */
11596 static unsigned int
11597 add_ranges (const_tree block
)
11599 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
11602 /* Add a new entry to .debug_ranges corresponding to a pair of
11606 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
11609 unsigned int in_use
= ranges_by_label_in_use
;
11610 unsigned int offset
;
11612 if (in_use
== ranges_by_label_allocated
)
11614 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
11615 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
11617 ranges_by_label_allocated
);
11618 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
11619 RANGES_TABLE_INCREMENT
11620 * sizeof (struct dw_ranges_by_label_struct
));
11623 ranges_by_label
[in_use
].begin
= begin
;
11624 ranges_by_label
[in_use
].end
= end
;
11625 ranges_by_label_in_use
= in_use
+ 1;
11627 offset
= add_ranges_num (-(int)in_use
- 1);
11630 add_AT_range_list (die
, DW_AT_ranges
, offset
);
11636 output_ranges (void)
11639 static const char *const start_fmt
= "Offset %#x";
11640 const char *fmt
= start_fmt
;
11642 for (i
= 0; i
< ranges_table_in_use
; i
++)
11644 int block_num
= ranges_table
[i
].num
;
11648 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11649 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11651 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
11652 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
11654 /* If all code is in the text section, then the compilation
11655 unit base address defaults to DW_AT_low_pc, which is the
11656 base of the text section. */
11657 if (!have_multiple_function_sections
)
11659 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
11660 text_section_label
,
11661 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11662 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
11663 text_section_label
, NULL
);
11666 /* Otherwise, the compilation unit base address is zero,
11667 which allows us to use absolute addresses, and not worry
11668 about whether the target supports cross-section
11672 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11673 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11674 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
11680 /* Negative block_num stands for an index into ranges_by_label. */
11681 else if (block_num
< 0)
11683 int lab_idx
= - block_num
- 1;
11685 if (!have_multiple_function_sections
)
11687 gcc_unreachable ();
11689 /* If we ever use add_ranges_by_labels () for a single
11690 function section, all we have to do is to take out
11691 the #if 0 above. */
11692 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11693 ranges_by_label
[lab_idx
].begin
,
11694 text_section_label
,
11695 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11696 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11697 ranges_by_label
[lab_idx
].end
,
11698 text_section_label
, NULL
);
11703 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11704 ranges_by_label
[lab_idx
].begin
,
11705 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11706 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11707 ranges_by_label
[lab_idx
].end
,
11713 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11714 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11720 /* Data structure containing information about input files. */
11723 const char *path
; /* Complete file name. */
11724 const char *fname
; /* File name part. */
11725 int length
; /* Length of entire string. */
11726 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
11727 int dir_idx
; /* Index in directory table. */
11730 /* Data structure containing information about directories with source
11734 const char *path
; /* Path including directory name. */
11735 int length
; /* Path length. */
11736 int prefix
; /* Index of directory entry which is a prefix. */
11737 int count
; /* Number of files in this directory. */
11738 int dir_idx
; /* Index of directory used as base. */
11741 /* Callback function for file_info comparison. We sort by looking at
11742 the directories in the path. */
11745 file_info_cmp (const void *p1
, const void *p2
)
11747 const struct file_info
*const s1
= (const struct file_info
*) p1
;
11748 const struct file_info
*const s2
= (const struct file_info
*) p2
;
11749 const unsigned char *cp1
;
11750 const unsigned char *cp2
;
11752 /* Take care of file names without directories. We need to make sure that
11753 we return consistent values to qsort since some will get confused if
11754 we return the same value when identical operands are passed in opposite
11755 orders. So if neither has a directory, return 0 and otherwise return
11756 1 or -1 depending on which one has the directory. */
11757 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
11758 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
11760 cp1
= (const unsigned char *) s1
->path
;
11761 cp2
= (const unsigned char *) s2
->path
;
11767 /* Reached the end of the first path? If so, handle like above. */
11768 if ((cp1
== (const unsigned char *) s1
->fname
)
11769 || (cp2
== (const unsigned char *) s2
->fname
))
11770 return ((cp2
== (const unsigned char *) s2
->fname
)
11771 - (cp1
== (const unsigned char *) s1
->fname
));
11773 /* Character of current path component the same? */
11774 else if (*cp1
!= *cp2
)
11775 return *cp1
- *cp2
;
11779 struct file_name_acquire_data
11781 struct file_info
*files
;
11786 /* Traversal function for the hash table. */
11789 file_name_acquire (void ** slot
, void *data
)
11791 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
11792 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
11793 struct file_info
*fi
;
11796 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
11798 if (! d
->emitted_number
)
11801 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
11803 fi
= fnad
->files
+ fnad
->used_files
++;
11805 /* Skip all leading "./". */
11807 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
11810 /* Create a new array entry. */
11812 fi
->length
= strlen (f
);
11815 /* Search for the file name part. */
11816 f
= strrchr (f
, DIR_SEPARATOR
);
11817 #if defined (DIR_SEPARATOR_2)
11819 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
11823 if (f
== NULL
|| f
< g
)
11829 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
11833 /* Output the directory table and the file name table. We try to minimize
11834 the total amount of memory needed. A heuristic is used to avoid large
11835 slowdowns with many input files. */
11838 output_file_names (void)
11840 struct file_name_acquire_data fnad
;
11842 struct file_info
*files
;
11843 struct dir_info
*dirs
;
11851 if (!last_emitted_file
)
11853 dw2_asm_output_data (1, 0, "End directory table");
11854 dw2_asm_output_data (1, 0, "End file name table");
11858 numfiles
= last_emitted_file
->emitted_number
;
11860 /* Allocate the various arrays we need. */
11861 files
= XALLOCAVEC (struct file_info
, numfiles
);
11862 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
11864 fnad
.files
= files
;
11865 fnad
.used_files
= 0;
11866 fnad
.max_files
= numfiles
;
11867 htab_traverse (file_table
, file_name_acquire
, &fnad
);
11868 gcc_assert (fnad
.used_files
== fnad
.max_files
);
11870 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
11872 /* Find all the different directories used. */
11873 dirs
[0].path
= files
[0].path
;
11874 dirs
[0].length
= files
[0].fname
- files
[0].path
;
11875 dirs
[0].prefix
= -1;
11877 dirs
[0].dir_idx
= 0;
11878 files
[0].dir_idx
= 0;
11881 for (i
= 1; i
< numfiles
; i
++)
11882 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
11883 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
11884 dirs
[ndirs
- 1].length
) == 0)
11886 /* Same directory as last entry. */
11887 files
[i
].dir_idx
= ndirs
- 1;
11888 ++dirs
[ndirs
- 1].count
;
11894 /* This is a new directory. */
11895 dirs
[ndirs
].path
= files
[i
].path
;
11896 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
11897 dirs
[ndirs
].count
= 1;
11898 dirs
[ndirs
].dir_idx
= ndirs
;
11899 files
[i
].dir_idx
= ndirs
;
11901 /* Search for a prefix. */
11902 dirs
[ndirs
].prefix
= -1;
11903 for (j
= 0; j
< ndirs
; j
++)
11904 if (dirs
[j
].length
< dirs
[ndirs
].length
11905 && dirs
[j
].length
> 1
11906 && (dirs
[ndirs
].prefix
== -1
11907 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
11908 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
11909 dirs
[ndirs
].prefix
= j
;
11914 /* Now to the actual work. We have to find a subset of the directories which
11915 allow expressing the file name using references to the directory table
11916 with the least amount of characters. We do not do an exhaustive search
11917 where we would have to check out every combination of every single
11918 possible prefix. Instead we use a heuristic which provides nearly optimal
11919 results in most cases and never is much off. */
11920 saved
= XALLOCAVEC (int, ndirs
);
11921 savehere
= XALLOCAVEC (int, ndirs
);
11923 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
11924 for (i
= 0; i
< ndirs
; i
++)
11929 /* We can always save some space for the current directory. But this
11930 does not mean it will be enough to justify adding the directory. */
11931 savehere
[i
] = dirs
[i
].length
;
11932 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
11934 for (j
= i
+ 1; j
< ndirs
; j
++)
11937 if (saved
[j
] < dirs
[i
].length
)
11939 /* Determine whether the dirs[i] path is a prefix of the
11943 k
= dirs
[j
].prefix
;
11944 while (k
!= -1 && k
!= (int) i
)
11945 k
= dirs
[k
].prefix
;
11949 /* Yes it is. We can possibly save some memory by
11950 writing the filenames in dirs[j] relative to
11952 savehere
[j
] = dirs
[i
].length
;
11953 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
11958 /* Check whether we can save enough to justify adding the dirs[i]
11960 if (total
> dirs
[i
].length
+ 1)
11962 /* It's worthwhile adding. */
11963 for (j
= i
; j
< ndirs
; j
++)
11964 if (savehere
[j
] > 0)
11966 /* Remember how much we saved for this directory so far. */
11967 saved
[j
] = savehere
[j
];
11969 /* Remember the prefix directory. */
11970 dirs
[j
].dir_idx
= i
;
11975 /* Emit the directory name table. */
11976 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
11977 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11978 dw2_asm_output_nstring (dirs
[i
].path
,
11980 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
11981 "Directory Entry: %#x", i
+ idx_offset
);
11983 dw2_asm_output_data (1, 0, "End directory table");
11985 /* We have to emit them in the order of emitted_number since that's
11986 used in the debug info generation. To do this efficiently we
11987 generate a back-mapping of the indices first. */
11988 backmap
= XALLOCAVEC (int, numfiles
);
11989 for (i
= 0; i
< numfiles
; i
++)
11990 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
11992 /* Now write all the file names. */
11993 for (i
= 0; i
< numfiles
; i
++)
11995 int file_idx
= backmap
[i
];
11996 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
11998 #ifdef VMS_DEBUGGING_INFO
11999 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12001 /* Setting these fields can lead to debugger miscomparisons,
12002 but VMS Debug requires them to be set correctly. */
12007 int maxfilelen
= strlen (files
[file_idx
].path
)
12008 + dirs
[dir_idx
].length
12009 + MAX_VMS_VERSION_LEN
+ 1;
12010 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
12012 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
12013 snprintf (filebuf
, maxfilelen
, "%s;%d",
12014 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
12016 dw2_asm_output_nstring
12017 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
12019 /* Include directory index. */
12020 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
12022 /* Modification time. */
12023 dw2_asm_output_data_uleb128
12024 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
12028 /* File length in bytes. */
12029 dw2_asm_output_data_uleb128
12030 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
12034 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
12035 "File Entry: %#x", (unsigned) i
+ 1);
12037 /* Include directory index. */
12038 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
12040 /* Modification time. */
12041 dw2_asm_output_data_uleb128 (0, NULL
);
12043 /* File length in bytes. */
12044 dw2_asm_output_data_uleb128 (0, NULL
);
12045 #endif /* VMS_DEBUGGING_INFO */
12048 dw2_asm_output_data (1, 0, "End file name table");
12052 /* Output the source line number correspondence information. This
12053 information goes into the .debug_line section. */
12056 output_line_info (void)
12058 char l1
[20], l2
[20], p1
[20], p2
[20];
12059 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
12060 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
12062 unsigned n_op_args
;
12063 unsigned long lt_index
;
12064 unsigned long current_line
;
12067 unsigned long current_file
;
12068 unsigned long function
;
12069 int ver
= dwarf_version
;
12071 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
12072 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
12073 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
12074 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
12076 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
12077 dw2_asm_output_data (4, 0xffffffff,
12078 "Initial length escape value indicating 64-bit DWARF extension");
12079 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
12080 "Length of Source Line Info");
12081 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
12083 dw2_asm_output_data (2, ver
, "DWARF Version");
12084 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
12085 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
12087 /* Define the architecture-dependent minimum instruction length (in
12088 bytes). In this implementation of DWARF, this field is used for
12089 information purposes only. Since GCC generates assembly language,
12090 we have no a priori knowledge of how many instruction bytes are
12091 generated for each source line, and therefore can use only the
12092 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
12093 commands. Accordingly, we fix this as `1', which is "correct
12094 enough" for all architectures, and don't let the target override. */
12095 dw2_asm_output_data (1, 1,
12096 "Minimum Instruction Length");
12099 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
12100 "Maximum Operations Per Instruction");
12101 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
12102 "Default is_stmt_start flag");
12103 dw2_asm_output_data (1, DWARF_LINE_BASE
,
12104 "Line Base Value (Special Opcodes)");
12105 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
12106 "Line Range Value (Special Opcodes)");
12107 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
12108 "Special Opcode Base");
12110 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
12114 case DW_LNS_advance_pc
:
12115 case DW_LNS_advance_line
:
12116 case DW_LNS_set_file
:
12117 case DW_LNS_set_column
:
12118 case DW_LNS_fixed_advance_pc
:
12126 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
12130 /* Write out the information about the files we use. */
12131 output_file_names ();
12132 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
12134 /* We used to set the address register to the first location in the text
12135 section here, but that didn't accomplish anything since we already
12136 have a line note for the opening brace of the first function. */
12138 /* Generate the line number to PC correspondence table, encoded as
12139 a series of state machine operations. */
12143 if (cfun
&& in_cold_section_p
)
12144 strcpy (prev_line_label
, crtl
->subsections
.cold_section_label
);
12146 strcpy (prev_line_label
, text_section_label
);
12147 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
12149 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
12152 /* Disable this optimization for now; GDB wants to see two line notes
12153 at the beginning of a function so it can find the end of the
12156 /* Don't emit anything for redundant notes. Just updating the
12157 address doesn't accomplish anything, because we already assume
12158 that anything after the last address is this line. */
12159 if (line_info
->dw_line_num
== current_line
12160 && line_info
->dw_file_num
== current_file
)
12164 /* Emit debug info for the address of the current line.
12166 Unfortunately, we have little choice here currently, and must always
12167 use the most general form. GCC does not know the address delta
12168 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
12169 attributes which will give an upper bound on the address range. We
12170 could perhaps use length attributes to determine when it is safe to
12171 use DW_LNS_fixed_advance_pc. */
12173 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
12176 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
12177 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
12178 "DW_LNS_fixed_advance_pc");
12179 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
12183 /* This can handle any delta. This takes
12184 4+DWARF2_ADDR_SIZE bytes. */
12185 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12186 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12187 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12188 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
12191 strcpy (prev_line_label
, line_label
);
12193 /* Emit debug info for the source file of the current line, if
12194 different from the previous line. */
12195 if (line_info
->dw_file_num
!= current_file
)
12197 current_file
= line_info
->dw_file_num
;
12198 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
12199 dw2_asm_output_data_uleb128 (current_file
, "%lu", current_file
);
12202 /* Emit debug info for the current line number, choosing the encoding
12203 that uses the least amount of space. */
12204 if (line_info
->dw_line_num
!= current_line
)
12206 line_offset
= line_info
->dw_line_num
- current_line
;
12207 line_delta
= line_offset
- DWARF_LINE_BASE
;
12208 current_line
= line_info
->dw_line_num
;
12209 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
12210 /* This can handle deltas from -10 to 234, using the current
12211 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
12213 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
12214 "line %lu", current_line
);
12217 /* This can handle any delta. This takes at least 4 bytes,
12218 depending on the value being encoded. */
12219 dw2_asm_output_data (1, DW_LNS_advance_line
,
12220 "advance to line %lu", current_line
);
12221 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
12222 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
12226 /* We still need to start a new row, so output a copy insn. */
12227 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
12230 /* Emit debug info for the address of the end of the function. */
12233 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
12234 "DW_LNS_fixed_advance_pc");
12235 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
12239 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12240 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12241 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12242 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
12245 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12246 dw2_asm_output_data_uleb128 (1, NULL
);
12247 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
12252 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
12254 dw_separate_line_info_ref line_info
12255 = &separate_line_info_table
[lt_index
];
12258 /* Don't emit anything for redundant notes. */
12259 if (line_info
->dw_line_num
== current_line
12260 && line_info
->dw_file_num
== current_file
12261 && line_info
->function
== function
)
12265 /* Emit debug info for the address of the current line. If this is
12266 a new function, or the first line of a function, then we need
12267 to handle it differently. */
12268 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
12270 if (function
!= line_info
->function
)
12272 function
= line_info
->function
;
12274 /* Set the address register to the first line in the function. */
12275 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12276 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12277 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12278 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
12282 /* ??? See the DW_LNS_advance_pc comment above. */
12285 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
12286 "DW_LNS_fixed_advance_pc");
12287 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
12291 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12292 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12293 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12294 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
12298 strcpy (prev_line_label
, line_label
);
12300 /* Emit debug info for the source file of the current line, if
12301 different from the previous line. */
12302 if (line_info
->dw_file_num
!= current_file
)
12304 current_file
= line_info
->dw_file_num
;
12305 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
12306 dw2_asm_output_data_uleb128 (current_file
, "%lu", current_file
);
12309 /* Emit debug info for the current line number, choosing the encoding
12310 that uses the least amount of space. */
12311 if (line_info
->dw_line_num
!= current_line
)
12313 line_offset
= line_info
->dw_line_num
- current_line
;
12314 line_delta
= line_offset
- DWARF_LINE_BASE
;
12315 current_line
= line_info
->dw_line_num
;
12316 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
12317 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
12318 "line %lu", current_line
);
12321 dw2_asm_output_data (1, DW_LNS_advance_line
,
12322 "advance to line %lu", current_line
);
12323 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
12324 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
12328 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
12336 /* If we're done with a function, end its sequence. */
12337 if (lt_index
== separate_line_info_table_in_use
12338 || separate_line_info_table
[lt_index
].function
!= function
)
12343 /* Emit debug info for the address of the end of the function. */
12344 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
12347 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
12348 "DW_LNS_fixed_advance_pc");
12349 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
12353 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12354 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12355 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12356 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
12359 /* Output the marker for the end of this sequence. */
12360 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12361 dw2_asm_output_data_uleb128 (1, NULL
);
12362 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
12366 /* Output the marker for the end of the line number info. */
12367 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
12370 /* Return the size of the .debug_dcall table for the compilation unit. */
12372 static unsigned long
12373 size_of_dcall_table (void)
12375 unsigned long size
;
12378 tree last_poc_decl
= NULL
;
12380 /* Header: version + debug info section pointer + pointer size. */
12381 size
= 2 + DWARF_OFFSET_SIZE
+ 1;
12383 /* Each entry: code label + DIE offset. */
12384 FOR_EACH_VEC_ELT (dcall_entry
, dcall_table
, i
, p
)
12386 gcc_assert (p
->targ_die
!= NULL
);
12387 /* Insert a "from" entry when the point-of-call DIE offset changes. */
12388 if (p
->poc_decl
!= last_poc_decl
)
12390 dw_die_ref poc_die
= lookup_decl_die (p
->poc_decl
);
12391 gcc_assert (poc_die
);
12392 last_poc_decl
= p
->poc_decl
;
12394 size
+= (DWARF_OFFSET_SIZE
12395 + size_of_uleb128 (poc_die
->die_offset
));
12397 size
+= DWARF_OFFSET_SIZE
+ size_of_uleb128 (p
->targ_die
->die_offset
);
12403 /* Output the direct call table used to disambiguate PC values when
12404 identical function have been merged. */
12407 output_dcall_table (void)
12410 unsigned long dcall_length
= size_of_dcall_table ();
12412 char poc_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
12413 tree last_poc_decl
= NULL
;
12415 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
12416 dw2_asm_output_data (4, 0xffffffff,
12417 "Initial length escape value indicating 64-bit DWARF extension");
12418 dw2_asm_output_data (DWARF_OFFSET_SIZE
, dcall_length
,
12419 "Length of Direct Call Table");
12420 dw2_asm_output_data (2, 4, "Version number");
12421 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
12422 debug_info_section
,
12423 "Offset of Compilation Unit Info");
12424 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
12426 FOR_EACH_VEC_ELT (dcall_entry
, dcall_table
, i
, p
)
12428 /* Insert a "from" entry when the point-of-call DIE offset changes. */
12429 if (p
->poc_decl
!= last_poc_decl
)
12431 dw_die_ref poc_die
= lookup_decl_die (p
->poc_decl
);
12432 last_poc_decl
= p
->poc_decl
;
12435 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, "New caller");
12436 dw2_asm_output_data_uleb128 (poc_die
->die_offset
,
12437 "Caller DIE offset");
12440 ASM_GENERATE_INTERNAL_LABEL (poc_label
, "LPOC", p
->poc_label_num
);
12441 dw2_asm_output_addr (DWARF_OFFSET_SIZE
, poc_label
, "Point of call");
12442 dw2_asm_output_data_uleb128 (p
->targ_die
->die_offset
,
12443 "Callee DIE offset");
12447 /* Return the size of the .debug_vcall table for the compilation unit. */
12449 static unsigned long
12450 size_of_vcall_table (void)
12452 unsigned long size
;
12456 /* Header: version + pointer size. */
12459 /* Each entry: code label + vtable slot index. */
12460 FOR_EACH_VEC_ELT (vcall_entry
, vcall_table
, i
, p
)
12461 size
+= DWARF_OFFSET_SIZE
+ size_of_uleb128 (p
->vtable_slot
);
12466 /* Output the virtual call table used to disambiguate PC values when
12467 identical function have been merged. */
12470 output_vcall_table (void)
12473 unsigned long vcall_length
= size_of_vcall_table ();
12475 char poc_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
12477 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
12478 dw2_asm_output_data (4, 0xffffffff,
12479 "Initial length escape value indicating 64-bit DWARF extension");
12480 dw2_asm_output_data (DWARF_OFFSET_SIZE
, vcall_length
,
12481 "Length of Virtual Call Table");
12482 dw2_asm_output_data (2, 4, "Version number");
12483 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
12485 FOR_EACH_VEC_ELT (vcall_entry
, vcall_table
, i
, p
)
12487 ASM_GENERATE_INTERNAL_LABEL (poc_label
, "LPOC", p
->poc_label_num
);
12488 dw2_asm_output_addr (DWARF_OFFSET_SIZE
, poc_label
, "Point of call");
12489 dw2_asm_output_data_uleb128 (p
->vtable_slot
, "Vtable slot");
12493 /* Given a pointer to a tree node for some base type, return a pointer to
12494 a DIE that describes the given type.
12496 This routine must only be called for GCC type nodes that correspond to
12497 Dwarf base (fundamental) types. */
12500 base_type_die (tree type
)
12502 dw_die_ref base_type_result
;
12503 enum dwarf_type encoding
;
12505 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
12508 /* If this is a subtype that should not be emitted as a subrange type,
12509 use the base type. See subrange_type_for_debug_p. */
12510 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
12511 type
= TREE_TYPE (type
);
12513 switch (TREE_CODE (type
))
12516 if ((dwarf_version
>= 4 || !dwarf_strict
)
12517 && TYPE_NAME (type
)
12518 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12519 && DECL_IS_BUILTIN (TYPE_NAME (type
))
12520 && DECL_NAME (TYPE_NAME (type
)))
12522 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
12523 if (strcmp (name
, "char16_t") == 0
12524 || strcmp (name
, "char32_t") == 0)
12526 encoding
= DW_ATE_UTF
;
12530 if (TYPE_STRING_FLAG (type
))
12532 if (TYPE_UNSIGNED (type
))
12533 encoding
= DW_ATE_unsigned_char
;
12535 encoding
= DW_ATE_signed_char
;
12537 else if (TYPE_UNSIGNED (type
))
12538 encoding
= DW_ATE_unsigned
;
12540 encoding
= DW_ATE_signed
;
12544 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
12546 if (dwarf_version
>= 3 || !dwarf_strict
)
12547 encoding
= DW_ATE_decimal_float
;
12549 encoding
= DW_ATE_lo_user
;
12552 encoding
= DW_ATE_float
;
12555 case FIXED_POINT_TYPE
:
12556 if (!(dwarf_version
>= 3 || !dwarf_strict
))
12557 encoding
= DW_ATE_lo_user
;
12558 else if (TYPE_UNSIGNED (type
))
12559 encoding
= DW_ATE_unsigned_fixed
;
12561 encoding
= DW_ATE_signed_fixed
;
12564 /* Dwarf2 doesn't know anything about complex ints, so use
12565 a user defined type for it. */
12567 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
12568 encoding
= DW_ATE_complex_float
;
12570 encoding
= DW_ATE_lo_user
;
12574 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12575 encoding
= DW_ATE_boolean
;
12579 /* No other TREE_CODEs are Dwarf fundamental types. */
12580 gcc_unreachable ();
12583 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
12585 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
12586 int_size_in_bytes (type
));
12587 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
12589 return base_type_result
;
12592 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12593 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12596 is_base_type (tree type
)
12598 switch (TREE_CODE (type
))
12604 case FIXED_POINT_TYPE
:
12612 case QUAL_UNION_TYPE
:
12613 case ENUMERAL_TYPE
:
12614 case FUNCTION_TYPE
:
12617 case REFERENCE_TYPE
:
12625 gcc_unreachable ();
12631 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12632 node, return the size in bits for the type if it is a constant, or else
12633 return the alignment for the type if the type's size is not constant, or
12634 else return BITS_PER_WORD if the type actually turns out to be an
12635 ERROR_MARK node. */
12637 static inline unsigned HOST_WIDE_INT
12638 simple_type_size_in_bits (const_tree type
)
12640 if (TREE_CODE (type
) == ERROR_MARK
)
12641 return BITS_PER_WORD
;
12642 else if (TYPE_SIZE (type
) == NULL_TREE
)
12644 else if (host_integerp (TYPE_SIZE (type
), 1))
12645 return tree_low_cst (TYPE_SIZE (type
), 1);
12647 return TYPE_ALIGN (type
);
12650 /* Similarly, but return a double_int instead of UHWI. */
12652 static inline double_int
12653 double_int_type_size_in_bits (const_tree type
)
12655 if (TREE_CODE (type
) == ERROR_MARK
)
12656 return uhwi_to_double_int (BITS_PER_WORD
);
12657 else if (TYPE_SIZE (type
) == NULL_TREE
)
12658 return double_int_zero
;
12659 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
12660 return tree_to_double_int (TYPE_SIZE (type
));
12662 return uhwi_to_double_int (TYPE_ALIGN (type
));
12665 /* Given a pointer to a tree node for a subrange type, return a pointer
12666 to a DIE that describes the given type. */
12669 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
12671 dw_die_ref subrange_die
;
12672 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
12674 if (context_die
== NULL
)
12675 context_die
= comp_unit_die ();
12677 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
12679 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
12681 /* The size of the subrange type and its base type do not match,
12682 so we need to generate a size attribute for the subrange type. */
12683 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
12687 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
12689 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
12691 return subrange_die
;
12694 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12695 entry that chains various modifiers in front of the given type. */
12698 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
12699 dw_die_ref context_die
)
12701 enum tree_code code
= TREE_CODE (type
);
12702 dw_die_ref mod_type_die
;
12703 dw_die_ref sub_die
= NULL
;
12704 tree item_type
= NULL
;
12705 tree qualified_type
;
12706 tree name
, low
, high
;
12708 if (code
== ERROR_MARK
)
12711 /* See if we already have the appropriately qualified variant of
12714 = get_qualified_type (type
,
12715 ((is_const_type
? TYPE_QUAL_CONST
: 0)
12716 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
12718 if (qualified_type
== sizetype
12719 && TYPE_NAME (qualified_type
)
12720 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
12722 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
12724 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
12725 && TYPE_PRECISION (t
)
12726 == TYPE_PRECISION (qualified_type
)
12727 && TYPE_UNSIGNED (t
)
12728 == TYPE_UNSIGNED (qualified_type
));
12729 qualified_type
= t
;
12732 /* If we do, then we can just use its DIE, if it exists. */
12733 if (qualified_type
)
12735 mod_type_die
= lookup_type_die (qualified_type
);
12737 return mod_type_die
;
12740 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
12742 /* Handle C typedef types. */
12743 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
12744 && !DECL_ARTIFICIAL (name
))
12746 tree dtype
= TREE_TYPE (name
);
12748 if (qualified_type
== dtype
)
12750 /* For a named type, use the typedef. */
12751 gen_type_die (qualified_type
, context_die
);
12752 return lookup_type_die (qualified_type
);
12754 else if (is_const_type
< TYPE_READONLY (dtype
)
12755 || is_volatile_type
< TYPE_VOLATILE (dtype
)
12756 || (is_const_type
<= TYPE_READONLY (dtype
)
12757 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
12758 && DECL_ORIGINAL_TYPE (name
) != type
))
12759 /* cv-unqualified version of named type. Just use the unnamed
12760 type to which it refers. */
12761 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
12762 is_const_type
, is_volatile_type
,
12764 /* Else cv-qualified version of named type; fall through. */
12769 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die (), type
);
12770 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
12772 else if (is_volatile_type
)
12774 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die (), type
);
12775 sub_die
= modified_type_die (type
, 0, 0, context_die
);
12777 else if (code
== POINTER_TYPE
)
12779 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die (), type
);
12780 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
12781 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
12782 item_type
= TREE_TYPE (type
);
12783 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
12784 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
12785 TYPE_ADDR_SPACE (item_type
));
12787 else if (code
== REFERENCE_TYPE
)
12789 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
12790 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, comp_unit_die (),
12793 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die (), type
);
12794 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
12795 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
12796 item_type
= TREE_TYPE (type
);
12797 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
12798 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
12799 TYPE_ADDR_SPACE (item_type
));
12801 else if (code
== INTEGER_TYPE
12802 && TREE_TYPE (type
) != NULL_TREE
12803 && subrange_type_for_debug_p (type
, &low
, &high
))
12805 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
12806 item_type
= TREE_TYPE (type
);
12808 else if (is_base_type (type
))
12809 mod_type_die
= base_type_die (type
);
12812 gen_type_die (type
, context_die
);
12814 /* We have to get the type_main_variant here (and pass that to the
12815 `lookup_type_die' routine) because the ..._TYPE node we have
12816 might simply be a *copy* of some original type node (where the
12817 copy was created to help us keep track of typedef names) and
12818 that copy might have a different TYPE_UID from the original
12820 if (TREE_CODE (type
) != VECTOR_TYPE
)
12821 return lookup_type_die (type_main_variant (type
));
12823 /* Vectors have the debugging information in the type,
12824 not the main variant. */
12825 return lookup_type_die (type
);
12828 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
12829 don't output a DW_TAG_typedef, since there isn't one in the
12830 user's program; just attach a DW_AT_name to the type.
12831 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
12832 if the base type already has the same name. */
12834 && ((TREE_CODE (name
) != TYPE_DECL
12835 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
12836 || (!is_const_type
&& !is_volatile_type
)))
12837 || (TREE_CODE (name
) == TYPE_DECL
12838 && TREE_TYPE (name
) == qualified_type
12839 && DECL_NAME (name
))))
12841 if (TREE_CODE (name
) == TYPE_DECL
)
12842 /* Could just call add_name_and_src_coords_attributes here,
12843 but since this is a builtin type it doesn't have any
12844 useful source coordinates anyway. */
12845 name
= DECL_NAME (name
);
12846 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
12848 /* This probably indicates a bug. */
12849 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
12850 add_name_attribute (mod_type_die
, "__unknown__");
12852 if (qualified_type
)
12853 equate_type_number_to_die (qualified_type
, mod_type_die
);
12856 /* We must do this after the equate_type_number_to_die call, in case
12857 this is a recursive type. This ensures that the modified_type_die
12858 recursion will terminate even if the type is recursive. Recursive
12859 types are possible in Ada. */
12860 sub_die
= modified_type_die (item_type
,
12861 TYPE_READONLY (item_type
),
12862 TYPE_VOLATILE (item_type
),
12865 if (sub_die
!= NULL
)
12866 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
12868 return mod_type_die
;
12871 /* Generate DIEs for the generic parameters of T.
12872 T must be either a generic type or a generic function.
12873 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
12876 gen_generic_params_dies (tree t
)
12880 dw_die_ref die
= NULL
;
12882 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
12886 die
= lookup_type_die (t
);
12887 else if (DECL_P (t
))
12888 die
= lookup_decl_die (t
);
12892 parms
= lang_hooks
.get_innermost_generic_parms (t
);
12894 /* T has no generic parameter. It means T is neither a generic type
12895 or function. End of story. */
12898 parms_num
= TREE_VEC_LENGTH (parms
);
12899 args
= lang_hooks
.get_innermost_generic_args (t
);
12900 for (i
= 0; i
< parms_num
; i
++)
12902 tree parm
, arg
, arg_pack_elems
;
12904 parm
= TREE_VEC_ELT (parms
, i
);
12905 arg
= TREE_VEC_ELT (args
, i
);
12906 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
12907 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
12909 if (parm
&& TREE_VALUE (parm
) && arg
)
12911 /* If PARM represents a template parameter pack,
12912 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
12913 by DW_TAG_template_*_parameter DIEs for the argument
12914 pack elements of ARG. Note that ARG would then be
12915 an argument pack. */
12916 if (arg_pack_elems
)
12917 template_parameter_pack_die (TREE_VALUE (parm
),
12921 generic_parameter_die (TREE_VALUE (parm
), arg
,
12922 true /* Emit DW_AT_name */, die
);
12927 /* Create and return a DIE for PARM which should be
12928 the representation of a generic type parameter.
12929 For instance, in the C++ front end, PARM would be a template parameter.
12930 ARG is the argument to PARM.
12931 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
12933 PARENT_DIE is the parent DIE which the new created DIE should be added to,
12934 as a child node. */
12937 generic_parameter_die (tree parm
, tree arg
,
12939 dw_die_ref parent_die
)
12941 dw_die_ref tmpl_die
= NULL
;
12942 const char *name
= NULL
;
12944 if (!parm
|| !DECL_NAME (parm
) || !arg
)
12947 /* We support non-type generic parameters and arguments,
12948 type generic parameters and arguments, as well as
12949 generic generic parameters (a.k.a. template template parameters in C++)
12951 if (TREE_CODE (parm
) == PARM_DECL
)
12952 /* PARM is a nontype generic parameter */
12953 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
12954 else if (TREE_CODE (parm
) == TYPE_DECL
)
12955 /* PARM is a type generic parameter. */
12956 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
12957 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
12958 /* PARM is a generic generic parameter.
12959 Its DIE is a GNU extension. It shall have a
12960 DW_AT_name attribute to represent the name of the template template
12961 parameter, and a DW_AT_GNU_template_name attribute to represent the
12962 name of the template template argument. */
12963 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
12966 gcc_unreachable ();
12972 /* If PARM is a generic parameter pack, it means we are
12973 emitting debug info for a template argument pack element.
12974 In other terms, ARG is a template argument pack element.
12975 In that case, we don't emit any DW_AT_name attribute for
12979 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
12981 add_AT_string (tmpl_die
, DW_AT_name
, name
);
12984 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
12986 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
12987 TMPL_DIE should have a child DW_AT_type attribute that is set
12988 to the type of the argument to PARM, which is ARG.
12989 If PARM is a type generic parameter, TMPL_DIE should have a
12990 child DW_AT_type that is set to ARG. */
12991 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
12992 add_type_attribute (tmpl_die
, tmpl_type
, 0,
12993 TREE_THIS_VOLATILE (tmpl_type
),
12998 /* So TMPL_DIE is a DIE representing a
12999 a generic generic template parameter, a.k.a template template
13000 parameter in C++ and arg is a template. */
13002 /* The DW_AT_GNU_template_name attribute of the DIE must be set
13003 to the name of the argument. */
13004 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
13006 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
13009 if (TREE_CODE (parm
) == PARM_DECL
)
13010 /* So PARM is a non-type generic parameter.
13011 DWARF3 5.6.8 says we must set a DW_AT_const_value child
13012 attribute of TMPL_DIE which value represents the value
13014 We must be careful here:
13015 The value of ARG might reference some function decls.
13016 We might currently be emitting debug info for a generic
13017 type and types are emitted before function decls, we don't
13018 know if the function decls referenced by ARG will actually be
13019 emitted after cgraph computations.
13020 So must defer the generation of the DW_AT_const_value to
13021 after cgraph is ready. */
13022 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
13028 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
13029 PARM_PACK must be a template parameter pack. The returned DIE
13030 will be child DIE of PARENT_DIE. */
13033 template_parameter_pack_die (tree parm_pack
,
13034 tree parm_pack_args
,
13035 dw_die_ref parent_die
)
13040 gcc_assert (parent_die
&& parm_pack
);
13042 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
13043 add_name_and_src_coords_attributes (die
, parm_pack
);
13044 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
13045 generic_parameter_die (parm_pack
,
13046 TREE_VEC_ELT (parm_pack_args
, j
),
13047 false /* Don't emit DW_AT_name */,
13052 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
13053 an enumerated type. */
13056 type_is_enum (const_tree type
)
13058 return TREE_CODE (type
) == ENUMERAL_TYPE
;
13061 /* Return the DBX register number described by a given RTL node. */
13063 static unsigned int
13064 dbx_reg_number (const_rtx rtl
)
13066 unsigned regno
= REGNO (rtl
);
13068 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
13070 #ifdef LEAF_REG_REMAP
13071 if (current_function_uses_only_leaf_regs
)
13073 int leaf_reg
= LEAF_REG_REMAP (regno
);
13074 if (leaf_reg
!= -1)
13075 regno
= (unsigned) leaf_reg
;
13079 return DBX_REGISTER_NUMBER (regno
);
13082 /* Optionally add a DW_OP_piece term to a location description expression.
13083 DW_OP_piece is only added if the location description expression already
13084 doesn't end with DW_OP_piece. */
13087 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
13089 dw_loc_descr_ref loc
;
13091 if (*list_head
!= NULL
)
13093 /* Find the end of the chain. */
13094 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
13097 if (loc
->dw_loc_opc
!= DW_OP_piece
)
13098 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
13102 /* Return a location descriptor that designates a machine register or
13103 zero if there is none. */
13105 static dw_loc_descr_ref
13106 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
13110 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
13113 /* We only use "frame base" when we're sure we're talking about the
13114 post-prologue local stack frame. We do this by *not* running
13115 register elimination until this point, and recognizing the special
13116 argument pointer and soft frame pointer rtx's.
13117 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13118 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
13119 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
13121 dw_loc_descr_ref result
= NULL
;
13123 if (dwarf_version
>= 4 || !dwarf_strict
)
13125 result
= mem_loc_descriptor (rtl
, VOIDmode
, initialized
);
13127 add_loc_descr (&result
,
13128 new_loc_descr (DW_OP_stack_value
, 0, 0));
13133 regs
= targetm
.dwarf_register_span (rtl
);
13135 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
13136 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
13138 return one_reg_loc_descriptor (dbx_reg_number (rtl
), initialized
);
13141 /* Return a location descriptor that designates a machine register for
13142 a given hard register number. */
13144 static dw_loc_descr_ref
13145 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
13147 dw_loc_descr_ref reg_loc_descr
;
13151 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
13153 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
13155 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13156 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13158 return reg_loc_descr
;
13161 /* Given an RTL of a register, return a location descriptor that
13162 designates a value that spans more than one register. */
13164 static dw_loc_descr_ref
13165 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
13166 enum var_init_status initialized
)
13168 int nregs
, size
, i
;
13170 dw_loc_descr_ref loc_result
= NULL
;
13173 #ifdef LEAF_REG_REMAP
13174 if (current_function_uses_only_leaf_regs
)
13176 int leaf_reg
= LEAF_REG_REMAP (reg
);
13177 if (leaf_reg
!= -1)
13178 reg
= (unsigned) leaf_reg
;
13181 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
13182 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
13184 /* Simple, contiguous registers. */
13185 if (regs
== NULL_RTX
)
13187 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
13192 dw_loc_descr_ref t
;
13194 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
13195 VAR_INIT_STATUS_INITIALIZED
);
13196 add_loc_descr (&loc_result
, t
);
13197 add_loc_descr_op_piece (&loc_result
, size
);
13203 /* Now onto stupid register sets in non contiguous locations. */
13205 gcc_assert (GET_CODE (regs
) == PARALLEL
);
13207 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
13210 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
13212 dw_loc_descr_ref t
;
13214 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
13215 VAR_INIT_STATUS_INITIALIZED
);
13216 add_loc_descr (&loc_result
, t
);
13217 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
13218 add_loc_descr_op_piece (&loc_result
, size
);
13221 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13222 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13226 /* Return a location descriptor that designates a constant. */
13228 static dw_loc_descr_ref
13229 int_loc_descriptor (HOST_WIDE_INT i
)
13231 enum dwarf_location_atom op
;
13233 /* Pick the smallest representation of a constant, rather than just
13234 defaulting to the LEB encoding. */
13238 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
13239 else if (i
<= 0xff)
13240 op
= DW_OP_const1u
;
13241 else if (i
<= 0xffff)
13242 op
= DW_OP_const2u
;
13243 else if (HOST_BITS_PER_WIDE_INT
== 32
13244 || i
<= 0xffffffff)
13245 op
= DW_OP_const4u
;
13252 op
= DW_OP_const1s
;
13253 else if (i
>= -0x8000)
13254 op
= DW_OP_const2s
;
13255 else if (HOST_BITS_PER_WIDE_INT
== 32
13256 || i
>= -0x80000000)
13257 op
= DW_OP_const4s
;
13262 return new_loc_descr (op
, i
, 0);
13265 /* Return loc description representing "address" of integer value.
13266 This can appear only as toplevel expression. */
13268 static dw_loc_descr_ref
13269 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
13272 dw_loc_descr_ref loc_result
= NULL
;
13274 if (!(dwarf_version
>= 4 || !dwarf_strict
))
13281 else if (i
<= 0xff)
13283 else if (i
<= 0xffff)
13285 else if (HOST_BITS_PER_WIDE_INT
== 32
13286 || i
<= 0xffffffff)
13289 litsize
= 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
13295 else if (i
>= -0x8000)
13297 else if (HOST_BITS_PER_WIDE_INT
== 32
13298 || i
>= -0x80000000)
13301 litsize
= 1 + size_of_sleb128 (i
);
13303 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13304 is more compact. For DW_OP_stack_value we need:
13305 litsize + 1 (DW_OP_stack_value)
13306 and for DW_OP_implicit_value:
13307 1 (DW_OP_implicit_value) + 1 (length) + size. */
13308 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
13310 loc_result
= int_loc_descriptor (i
);
13311 add_loc_descr (&loc_result
,
13312 new_loc_descr (DW_OP_stack_value
, 0, 0));
13316 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13318 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13319 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
13323 /* Return a location descriptor that designates a base+offset location. */
13325 static dw_loc_descr_ref
13326 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
13327 enum var_init_status initialized
)
13329 unsigned int regno
;
13330 dw_loc_descr_ref result
;
13331 dw_fde_ref fde
= current_fde ();
13333 /* We only use "frame base" when we're sure we're talking about the
13334 post-prologue local stack frame. We do this by *not* running
13335 register elimination until this point, and recognizing the special
13336 argument pointer and soft frame pointer rtx's. */
13337 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
13339 rtx elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
13343 if (GET_CODE (elim
) == PLUS
)
13345 offset
+= INTVAL (XEXP (elim
, 1));
13346 elim
= XEXP (elim
, 0);
13348 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13349 && (elim
== hard_frame_pointer_rtx
13350 || elim
== stack_pointer_rtx
))
13351 || elim
== (frame_pointer_needed
13352 ? hard_frame_pointer_rtx
13353 : stack_pointer_rtx
));
13355 /* If drap register is used to align stack, use frame
13356 pointer + offset to access stack variables. If stack
13357 is aligned without drap, use stack pointer + offset to
13358 access stack variables. */
13359 if (crtl
->stack_realign_tried
13360 && reg
== frame_pointer_rtx
)
13363 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
13364 ? HARD_FRAME_POINTER_REGNUM
13365 : STACK_POINTER_REGNUM
);
13366 return new_reg_loc_descr (base_reg
, offset
);
13369 offset
+= frame_pointer_fb_offset
;
13370 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
13375 && (fde
->drap_reg
== REGNO (reg
)
13376 || fde
->vdrap_reg
== REGNO (reg
)))
13378 /* Use cfa+offset to represent the location of arguments passed
13379 on the stack when drap is used to align stack.
13380 Only do this when not optimizing, for optimized code var-tracking
13381 is supposed to track where the arguments live and the register
13382 used as vdrap or drap in some spot might be used for something
13383 else in other part of the routine. */
13384 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
13387 regno
= dbx_reg_number (reg
);
13389 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
13392 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
13394 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13395 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13400 /* Return true if this RTL expression describes a base+offset calculation. */
13403 is_based_loc (const_rtx rtl
)
13405 return (GET_CODE (rtl
) == PLUS
13406 && ((REG_P (XEXP (rtl
, 0))
13407 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
13408 && CONST_INT_P (XEXP (rtl
, 1)))));
13411 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13414 static dw_loc_descr_ref
13415 tls_mem_loc_descriptor (rtx mem
)
13418 dw_loc_descr_ref loc_result
;
13420 if (MEM_EXPR (mem
) == NULL_TREE
|| MEM_OFFSET (mem
) == NULL_RTX
)
13423 base
= get_base_address (MEM_EXPR (mem
));
13425 || TREE_CODE (base
) != VAR_DECL
13426 || !DECL_THREAD_LOCAL_P (base
))
13429 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
13430 if (loc_result
== NULL
)
13433 if (INTVAL (MEM_OFFSET (mem
)))
13434 loc_descr_plus_const (&loc_result
, INTVAL (MEM_OFFSET (mem
)));
13439 /* Output debug info about reason why we failed to expand expression as dwarf
13443 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
13445 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
13447 fprintf (dump_file
, "Failed to expand as dwarf: ");
13449 print_generic_expr (dump_file
, expr
, dump_flags
);
13452 fprintf (dump_file
, "\n");
13453 print_rtl (dump_file
, rtl
);
13455 fprintf (dump_file
, "\nReason: %s\n", reason
);
13459 /* Helper function for const_ok_for_output, called either directly
13460 or via for_each_rtx. */
13463 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
13467 if (GET_CODE (rtl
) == UNSPEC
)
13469 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13470 we can't express it in the debug info. */
13471 #ifdef ENABLE_CHECKING
13472 inform (current_function_decl
13473 ? DECL_SOURCE_LOCATION (current_function_decl
)
13474 : UNKNOWN_LOCATION
,
13475 "non-delegitimized UNSPEC %d found in variable location",
13478 expansion_failed (NULL_TREE
, rtl
,
13479 "UNSPEC hasn't been delegitimized.\n");
13483 if (GET_CODE (rtl
) != SYMBOL_REF
)
13486 if (CONSTANT_POOL_ADDRESS_P (rtl
))
13489 get_pool_constant_mark (rtl
, &marked
);
13490 /* If all references to this pool constant were optimized away,
13491 it was not output and thus we can't represent it. */
13494 expansion_failed (NULL_TREE
, rtl
,
13495 "Constant was removed from constant pool.\n");
13500 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
13503 /* Avoid references to external symbols in debug info, on several targets
13504 the linker might even refuse to link when linking a shared library,
13505 and in many other cases the relocations for .debug_info/.debug_loc are
13506 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13507 to be defined within the same shared library or executable are fine. */
13508 if (SYMBOL_REF_EXTERNAL_P (rtl
))
13510 tree decl
= SYMBOL_REF_DECL (rtl
);
13512 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
13514 expansion_failed (NULL_TREE
, rtl
,
13515 "Symbol not defined in current TU.\n");
13523 /* Return true if constant RTL can be emitted in DW_OP_addr or
13524 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13525 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13528 const_ok_for_output (rtx rtl
)
13530 if (GET_CODE (rtl
) == SYMBOL_REF
)
13531 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
13533 if (GET_CODE (rtl
) == CONST
)
13534 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
13539 /* The following routine converts the RTL for a variable or parameter
13540 (resident in memory) into an equivalent Dwarf representation of a
13541 mechanism for getting the address of that same variable onto the top of a
13542 hypothetical "address evaluation" stack.
13544 When creating memory location descriptors, we are effectively transforming
13545 the RTL for a memory-resident object into its Dwarf postfix expression
13546 equivalent. This routine recursively descends an RTL tree, turning
13547 it into Dwarf postfix code as it goes.
13549 MODE is the mode of the memory reference, needed to handle some
13550 autoincrement addressing modes.
13552 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
13553 location list for RTL.
13555 Return 0 if we can't represent the location. */
13557 static dw_loc_descr_ref
13558 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
13559 enum var_init_status initialized
)
13561 dw_loc_descr_ref mem_loc_result
= NULL
;
13562 enum dwarf_location_atom op
;
13563 dw_loc_descr_ref op0
, op1
;
13565 /* Note that for a dynamically sized array, the location we will generate a
13566 description of here will be the lowest numbered location which is
13567 actually within the array. That's *not* necessarily the same as the
13568 zeroth element of the array. */
13570 rtl
= targetm
.delegitimize_address (rtl
);
13572 switch (GET_CODE (rtl
))
13577 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13580 /* The case of a subreg may arise when we have a local (register)
13581 variable or a formal (register) parameter which doesn't quite fill
13582 up an entire register. For now, just assume that it is
13583 legitimate to make the Dwarf info refer to the whole register which
13584 contains the given subreg. */
13585 if (!subreg_lowpart_p (rtl
))
13587 rtl
= SUBREG_REG (rtl
);
13588 if (GET_MODE_SIZE (GET_MODE (rtl
)) > DWARF2_ADDR_SIZE
)
13590 if (GET_MODE_CLASS (GET_MODE (rtl
)) != MODE_INT
)
13592 mem_loc_result
= mem_loc_descriptor (rtl
, mode
, initialized
);
13596 /* Whenever a register number forms a part of the description of the
13597 method for calculating the (dynamic) address of a memory resident
13598 object, DWARF rules require the register number be referred to as
13599 a "base register". This distinction is not based in any way upon
13600 what category of register the hardware believes the given register
13601 belongs to. This is strictly DWARF terminology we're dealing with
13602 here. Note that in cases where the location of a memory-resident
13603 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
13604 OP_CONST (0)) the actual DWARF location descriptor that we generate
13605 may just be OP_BASEREG (basereg). This may look deceptively like
13606 the object in question was allocated to a register (rather than in
13607 memory) so DWARF consumers need to be aware of the subtle
13608 distinction between OP_REG and OP_BASEREG. */
13609 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
13610 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
13611 else if (stack_realign_drap
13613 && crtl
->args
.internal_arg_pointer
== rtl
13614 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
13616 /* If RTL is internal_arg_pointer, which has been optimized
13617 out, use DRAP instead. */
13618 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
13619 VAR_INIT_STATUS_INITIALIZED
);
13625 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13626 VAR_INIT_STATUS_INITIALIZED
);
13631 int shift
= DWARF2_ADDR_SIZE
13632 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
13633 shift
*= BITS_PER_UNIT
;
13634 if (GET_CODE (rtl
) == SIGN_EXTEND
)
13638 mem_loc_result
= op0
;
13639 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
13640 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
13641 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
13642 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13647 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
13648 VAR_INIT_STATUS_INITIALIZED
);
13649 if (mem_loc_result
== NULL
)
13650 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
13651 if (mem_loc_result
!= 0)
13653 if (GET_MODE_SIZE (GET_MODE (rtl
)) > DWARF2_ADDR_SIZE
)
13655 expansion_failed (NULL_TREE
, rtl
, "DWARF address size mismatch");
13658 else if (GET_MODE_SIZE (GET_MODE (rtl
)) == DWARF2_ADDR_SIZE
)
13659 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
13661 add_loc_descr (&mem_loc_result
,
13662 new_loc_descr (DW_OP_deref_size
,
13663 GET_MODE_SIZE (GET_MODE (rtl
)), 0));
13667 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13668 if (new_rtl
!= rtl
)
13669 return mem_loc_descriptor (new_rtl
, mode
, initialized
);
13674 rtl
= XEXP (rtl
, 1);
13676 /* ... fall through ... */
13679 /* Some ports can transform a symbol ref into a label ref, because
13680 the symbol ref is too far away and has to be dumped into a constant
13684 if (GET_CODE (rtl
) == SYMBOL_REF
13685 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
13687 dw_loc_descr_ref temp
;
13689 /* If this is not defined, we have no way to emit the data. */
13690 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
13693 /* We used to emit DW_OP_addr here, but that's wrong, since
13694 DW_OP_addr should be relocated by the debug info consumer,
13695 while DW_OP_GNU_push_tls_address operand should not. */
13696 temp
= new_loc_descr (DWARF2_ADDR_SIZE
== 4
13697 ? DW_OP_const4u
: DW_OP_const8u
, 0, 0);
13698 temp
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
13699 temp
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
13700 temp
->dtprel
= true;
13702 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
13703 add_loc_descr (&mem_loc_result
, temp
);
13708 if (!const_ok_for_output (rtl
))
13712 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
13713 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
13714 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
13715 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
13721 case DEBUG_IMPLICIT_PTR
:
13722 expansion_failed (NULL_TREE
, rtl
,
13723 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
13727 /* Extract the PLUS expression nested inside and fall into
13728 PLUS code below. */
13729 rtl
= XEXP (rtl
, 1);
13734 /* Turn these into a PLUS expression and fall into the PLUS code
13736 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
13737 GEN_INT (GET_CODE (rtl
) == PRE_INC
13738 ? GET_MODE_UNIT_SIZE (mode
)
13739 : -GET_MODE_UNIT_SIZE (mode
)));
13741 /* ... fall through ... */
13745 if (is_based_loc (rtl
))
13746 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
13747 INTVAL (XEXP (rtl
, 1)),
13748 VAR_INIT_STATUS_INITIALIZED
);
13751 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13752 VAR_INIT_STATUS_INITIALIZED
);
13753 if (mem_loc_result
== 0)
13756 if (CONST_INT_P (XEXP (rtl
, 1)))
13757 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
13760 dw_loc_descr_ref mem_loc_result2
13761 = mem_loc_descriptor (XEXP (rtl
, 1), mode
,
13762 VAR_INIT_STATUS_INITIALIZED
);
13763 if (mem_loc_result2
== 0)
13765 add_loc_descr (&mem_loc_result
, mem_loc_result2
);
13766 add_loc_descr (&mem_loc_result
,
13767 new_loc_descr (DW_OP_plus
, 0, 0));
13772 /* If a pseudo-reg is optimized away, it is possible for it to
13773 be replaced with a MEM containing a multiply or shift. */
13815 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13816 VAR_INIT_STATUS_INITIALIZED
);
13817 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
13818 VAR_INIT_STATUS_INITIALIZED
);
13820 if (op0
== 0 || op1
== 0)
13823 mem_loc_result
= op0
;
13824 add_loc_descr (&mem_loc_result
, op1
);
13825 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13829 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13830 VAR_INIT_STATUS_INITIALIZED
);
13831 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
13832 VAR_INIT_STATUS_INITIALIZED
);
13834 if (op0
== 0 || op1
== 0)
13837 mem_loc_result
= op0
;
13838 add_loc_descr (&mem_loc_result
, op1
);
13839 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13840 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13841 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
13842 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
13843 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
13859 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13860 VAR_INIT_STATUS_INITIALIZED
);
13865 mem_loc_result
= op0
;
13866 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13870 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
13898 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) > DWARF2_ADDR_SIZE
13899 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 1))) > DWARF2_ADDR_SIZE
)
13903 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
13905 if (op_mode
== VOIDmode
)
13906 op_mode
= GET_MODE (XEXP (rtl
, 1));
13907 if (op_mode
!= VOIDmode
&& GET_MODE_CLASS (op_mode
) != MODE_INT
)
13910 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13911 VAR_INIT_STATUS_INITIALIZED
);
13912 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
13913 VAR_INIT_STATUS_INITIALIZED
);
13915 if (op0
== 0 || op1
== 0)
13918 if (op_mode
!= VOIDmode
13919 && GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
13921 int shift
= DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
);
13922 shift
*= BITS_PER_UNIT
;
13923 /* For eq/ne, if the operands are known to be zero-extended,
13924 there is no need to do the fancy shifting up. */
13925 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
13927 dw_loc_descr_ref last0
, last1
;
13929 last0
->dw_loc_next
!= NULL
;
13930 last0
= last0
->dw_loc_next
)
13933 last1
->dw_loc_next
!= NULL
;
13934 last1
= last1
->dw_loc_next
)
13936 /* deref_size zero extends, and for constants we can check
13937 whether they are zero extended or not. */
13938 if (((last0
->dw_loc_opc
== DW_OP_deref_size
13939 && last0
->dw_loc_oprnd1
.v
.val_int
13940 <= GET_MODE_SIZE (op_mode
))
13941 || (CONST_INT_P (XEXP (rtl
, 0))
13942 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
13943 == (INTVAL (XEXP (rtl
, 0))
13944 & GET_MODE_MASK (op_mode
))))
13945 && ((last1
->dw_loc_opc
== DW_OP_deref_size
13946 && last1
->dw_loc_oprnd1
.v
.val_int
13947 <= GET_MODE_SIZE (op_mode
))
13948 || (CONST_INT_P (XEXP (rtl
, 1))
13949 && (unsigned HOST_WIDE_INT
)
13950 INTVAL (XEXP (rtl
, 1))
13951 == (INTVAL (XEXP (rtl
, 1))
13952 & GET_MODE_MASK (op_mode
)))))
13955 add_loc_descr (&op0
, int_loc_descriptor (shift
));
13956 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
13957 if (CONST_INT_P (XEXP (rtl
, 1)))
13958 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
13961 add_loc_descr (&op1
, int_loc_descriptor (shift
));
13962 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
13968 mem_loc_result
= op0
;
13969 add_loc_descr (&mem_loc_result
, op1
);
13970 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13971 if (STORE_FLAG_VALUE
!= 1)
13973 add_loc_descr (&mem_loc_result
,
13974 int_loc_descriptor (STORE_FLAG_VALUE
));
13975 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
13996 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) > DWARF2_ADDR_SIZE
13997 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 1))) > DWARF2_ADDR_SIZE
)
14001 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
14003 if (op_mode
== VOIDmode
)
14004 op_mode
= GET_MODE (XEXP (rtl
, 1));
14005 if (op_mode
!= VOIDmode
&& GET_MODE_CLASS (op_mode
) != MODE_INT
)
14008 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
14009 VAR_INIT_STATUS_INITIALIZED
);
14010 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
14011 VAR_INIT_STATUS_INITIALIZED
);
14013 if (op0
== 0 || op1
== 0)
14016 if (op_mode
!= VOIDmode
14017 && GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
14019 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
14020 dw_loc_descr_ref last0
, last1
;
14022 last0
->dw_loc_next
!= NULL
;
14023 last0
= last0
->dw_loc_next
)
14026 last1
->dw_loc_next
!= NULL
;
14027 last1
= last1
->dw_loc_next
)
14029 if (CONST_INT_P (XEXP (rtl
, 0)))
14030 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
14031 /* deref_size zero extends, so no need to mask it again. */
14032 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
14033 || last0
->dw_loc_oprnd1
.v
.val_int
14034 > GET_MODE_SIZE (op_mode
))
14036 add_loc_descr (&op0
, int_loc_descriptor (mask
));
14037 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14039 if (CONST_INT_P (XEXP (rtl
, 1)))
14040 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
14041 /* deref_size zero extends, so no need to mask it again. */
14042 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
14043 || last1
->dw_loc_oprnd1
.v
.val_int
14044 > GET_MODE_SIZE (op_mode
))
14046 add_loc_descr (&op1
, int_loc_descriptor (mask
));
14047 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
14052 HOST_WIDE_INT bias
= 1;
14053 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
14054 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14055 if (CONST_INT_P (XEXP (rtl
, 1)))
14056 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
14057 + INTVAL (XEXP (rtl
, 1)));
14059 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
14069 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) != MODE_INT
14070 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) > DWARF2_ADDR_SIZE
14071 || GET_MODE (XEXP (rtl
, 0)) != GET_MODE (XEXP (rtl
, 1)))
14074 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
14075 VAR_INIT_STATUS_INITIALIZED
);
14076 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
14077 VAR_INIT_STATUS_INITIALIZED
);
14079 if (op0
== 0 || op1
== 0)
14082 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
14083 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
14084 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
14085 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
14087 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) < DWARF2_ADDR_SIZE
)
14089 HOST_WIDE_INT mask
= GET_MODE_MASK (GET_MODE (XEXP (rtl
, 0)));
14090 add_loc_descr (&op0
, int_loc_descriptor (mask
));
14091 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14092 add_loc_descr (&op1
, int_loc_descriptor (mask
));
14093 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
14097 HOST_WIDE_INT bias
= 1;
14098 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
14099 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14100 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14103 else if (GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) < DWARF2_ADDR_SIZE
)
14105 int shift
= DWARF2_ADDR_SIZE
14106 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
14107 shift
*= BITS_PER_UNIT
;
14108 add_loc_descr (&op0
, int_loc_descriptor (shift
));
14109 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
14110 add_loc_descr (&op1
, int_loc_descriptor (shift
));
14111 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
14114 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
14118 mem_loc_result
= op0
;
14119 add_loc_descr (&mem_loc_result
, op1
);
14120 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14122 dw_loc_descr_ref bra_node
, drop_node
;
14124 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14125 add_loc_descr (&mem_loc_result
, bra_node
);
14126 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
14127 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
14128 add_loc_descr (&mem_loc_result
, drop_node
);
14129 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14130 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
14136 if (CONST_INT_P (XEXP (rtl
, 1))
14137 && CONST_INT_P (XEXP (rtl
, 2))
14138 && ((unsigned) INTVAL (XEXP (rtl
, 1))
14139 + (unsigned) INTVAL (XEXP (rtl
, 2))
14140 <= GET_MODE_BITSIZE (GET_MODE (rtl
)))
14141 && GET_MODE_BITSIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
14142 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
14145 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
14146 VAR_INIT_STATUS_INITIALIZED
);
14149 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
14153 mem_loc_result
= op0
;
14154 size
= INTVAL (XEXP (rtl
, 1));
14155 shift
= INTVAL (XEXP (rtl
, 2));
14156 if (BITS_BIG_ENDIAN
)
14157 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
14159 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
14161 add_loc_descr (&mem_loc_result
,
14162 int_loc_descriptor (DWARF2_ADDR_SIZE
14164 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
14166 if (size
!= (int) DWARF2_ADDR_SIZE
)
14168 add_loc_descr (&mem_loc_result
,
14169 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
14170 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14177 dw_loc_descr_ref op2
, bra_node
, drop_node
;
14178 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
14179 VAR_INIT_STATUS_INITIALIZED
);
14180 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
14181 VAR_INIT_STATUS_INITIALIZED
);
14182 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
,
14183 VAR_INIT_STATUS_INITIALIZED
);
14184 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
14187 mem_loc_result
= op1
;
14188 add_loc_descr (&mem_loc_result
, op2
);
14189 add_loc_descr (&mem_loc_result
, op0
);
14190 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14191 add_loc_descr (&mem_loc_result
, bra_node
);
14192 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
14193 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
14194 add_loc_descr (&mem_loc_result
, drop_node
);
14195 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14196 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
14204 /* In theory, we could implement the above. */
14205 /* DWARF cannot represent the unsigned compare operations
14232 case FLOAT_TRUNCATE
:
14234 case UNSIGNED_FLOAT
:
14237 case FRACT_CONVERT
:
14238 case UNSIGNED_FRACT_CONVERT
:
14240 case UNSIGNED_SAT_FRACT
:
14252 case VEC_DUPLICATE
:
14255 /* If delegitimize_address couldn't do anything with the UNSPEC, we
14256 can't express it in the debug info. This can happen e.g. with some
14261 resolve_one_addr (&rtl
, NULL
);
14265 #ifdef ENABLE_CHECKING
14266 print_rtl (stderr
, rtl
);
14267 gcc_unreachable ();
14273 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14274 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14276 return mem_loc_result
;
14279 /* Return a descriptor that describes the concatenation of two locations.
14280 This is typically a complex variable. */
14282 static dw_loc_descr_ref
14283 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
14285 dw_loc_descr_ref cc_loc_result
= NULL
;
14286 dw_loc_descr_ref x0_ref
14287 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14288 dw_loc_descr_ref x1_ref
14289 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14291 if (x0_ref
== 0 || x1_ref
== 0)
14294 cc_loc_result
= x0_ref
;
14295 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
14297 add_loc_descr (&cc_loc_result
, x1_ref
);
14298 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
14300 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14301 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14303 return cc_loc_result
;
14306 /* Return a descriptor that describes the concatenation of N
14309 static dw_loc_descr_ref
14310 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
14313 dw_loc_descr_ref cc_loc_result
= NULL
;
14314 unsigned int n
= XVECLEN (concatn
, 0);
14316 for (i
= 0; i
< n
; ++i
)
14318 dw_loc_descr_ref ref
;
14319 rtx x
= XVECEXP (concatn
, 0, i
);
14321 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14325 add_loc_descr (&cc_loc_result
, ref
);
14326 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
14329 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14330 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14332 return cc_loc_result
;
14335 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
14336 for DEBUG_IMPLICIT_PTR RTL. */
14338 static dw_loc_descr_ref
14339 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
14341 dw_loc_descr_ref ret
;
14346 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
14347 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
14348 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
14349 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
14350 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
14351 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
14354 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14355 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
14356 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14360 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
14361 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
14366 /* Output a proper Dwarf location descriptor for a variable or parameter
14367 which is either allocated in a register or in a memory location. For a
14368 register, we just generate an OP_REG and the register number. For a
14369 memory location we provide a Dwarf postfix expression describing how to
14370 generate the (dynamic) address of the object onto the address stack.
14372 MODE is mode of the decl if this loc_descriptor is going to be used in
14373 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
14374 allowed, VOIDmode otherwise.
14376 If we don't know how to describe it, return 0. */
14378 static dw_loc_descr_ref
14379 loc_descriptor (rtx rtl
, enum machine_mode mode
,
14380 enum var_init_status initialized
)
14382 dw_loc_descr_ref loc_result
= NULL
;
14384 switch (GET_CODE (rtl
))
14387 /* The case of a subreg may arise when we have a local (register)
14388 variable or a formal (register) parameter which doesn't quite fill
14389 up an entire register. For now, just assume that it is
14390 legitimate to make the Dwarf info refer to the whole register which
14391 contains the given subreg. */
14392 loc_result
= loc_descriptor (SUBREG_REG (rtl
), mode
, initialized
);
14396 loc_result
= reg_loc_descriptor (rtl
, initialized
);
14400 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
14402 if (loc_result
== NULL
)
14403 loc_result
= tls_mem_loc_descriptor (rtl
);
14404 if (loc_result
== NULL
)
14406 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
14407 if (new_rtl
!= rtl
)
14408 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
14413 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
14418 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
14423 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
14425 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
14426 if (GET_CODE (loc
) == EXPR_LIST
)
14427 loc
= XEXP (loc
, 0);
14428 loc_result
= loc_descriptor (loc
, mode
, initialized
);
14432 rtl
= XEXP (rtl
, 1);
14437 rtvec par_elems
= XVEC (rtl
, 0);
14438 int num_elem
= GET_NUM_ELEM (par_elems
);
14439 enum machine_mode mode
;
14442 /* Create the first one, so we have something to add to. */
14443 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
14444 VOIDmode
, initialized
);
14445 if (loc_result
== NULL
)
14447 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
14448 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
14449 for (i
= 1; i
< num_elem
; i
++)
14451 dw_loc_descr_ref temp
;
14453 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
14454 VOIDmode
, initialized
);
14457 add_loc_descr (&loc_result
, temp
);
14458 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
14459 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
14465 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
14466 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
14471 if (mode
== VOIDmode
)
14472 mode
= GET_MODE (rtl
);
14474 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
14476 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
14478 /* Note that a CONST_DOUBLE rtx could represent either an integer
14479 or a floating-point constant. A CONST_DOUBLE is used whenever
14480 the constant requires more than one word in order to be
14481 adequately represented. We output CONST_DOUBLEs as blocks. */
14482 loc_result
= new_loc_descr (DW_OP_implicit_value
,
14483 GET_MODE_SIZE (mode
), 0);
14484 if (SCALAR_FLOAT_MODE_P (mode
))
14486 unsigned int length
= GET_MODE_SIZE (mode
);
14487 unsigned char *array
14488 = (unsigned char*) ggc_alloc_atomic (length
);
14490 insert_float (rtl
, array
);
14491 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
14492 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
14493 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
14494 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
14498 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
14499 loc_result
->dw_loc_oprnd2
.v
.val_double
14500 = rtx_to_double_int (rtl
);
14506 if (mode
== VOIDmode
)
14507 mode
= GET_MODE (rtl
);
14509 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
14511 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
14512 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
14513 unsigned char *array
= (unsigned char *)
14514 ggc_alloc_atomic (length
* elt_size
);
14518 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
14519 switch (GET_MODE_CLASS (mode
))
14521 case MODE_VECTOR_INT
:
14522 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14524 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14525 double_int val
= rtx_to_double_int (elt
);
14527 if (elt_size
<= sizeof (HOST_WIDE_INT
))
14528 insert_int (double_int_to_shwi (val
), elt_size
, p
);
14531 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
14532 insert_double (val
, p
);
14537 case MODE_VECTOR_FLOAT
:
14538 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14540 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14541 insert_float (elt
, p
);
14546 gcc_unreachable ();
14549 loc_result
= new_loc_descr (DW_OP_implicit_value
,
14550 length
* elt_size
, 0);
14551 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
14552 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
14553 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
14554 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
14559 if (mode
== VOIDmode
14560 || GET_CODE (XEXP (rtl
, 0)) == CONST_INT
14561 || GET_CODE (XEXP (rtl
, 0)) == CONST_DOUBLE
14562 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
14564 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
14569 if (!const_ok_for_output (rtl
))
14572 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
14573 && (dwarf_version
>= 4 || !dwarf_strict
))
14575 loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
14576 loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
14577 loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
14578 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14579 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
14583 case DEBUG_IMPLICIT_PTR
:
14584 loc_result
= implicit_ptr_descriptor (rtl
, 0);
14588 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
14589 && CONST_INT_P (XEXP (rtl
, 1)))
14592 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
14597 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
14598 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
14599 && (dwarf_version
>= 4 || !dwarf_strict
))
14601 /* Value expression. */
14602 loc_result
= mem_loc_descriptor (rtl
, VOIDmode
, initialized
);
14604 add_loc_descr (&loc_result
,
14605 new_loc_descr (DW_OP_stack_value
, 0, 0));
14613 /* We need to figure out what section we should use as the base for the
14614 address ranges where a given location is valid.
14615 1. If this particular DECL has a section associated with it, use that.
14616 2. If this function has a section associated with it, use that.
14617 3. Otherwise, use the text section.
14618 XXX: If you split a variable across multiple sections, we won't notice. */
14620 static const char *
14621 secname_for_decl (const_tree decl
)
14623 const char *secname
;
14625 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
14627 tree sectree
= DECL_SECTION_NAME (decl
);
14628 secname
= TREE_STRING_POINTER (sectree
);
14630 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
14632 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
14633 secname
= TREE_STRING_POINTER (sectree
);
14635 else if (cfun
&& in_cold_section_p
)
14636 secname
= crtl
->subsections
.cold_section_label
;
14638 secname
= text_section_label
;
14643 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
14646 decl_by_reference_p (tree decl
)
14648 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
14649 || TREE_CODE (decl
) == VAR_DECL
)
14650 && DECL_BY_REFERENCE (decl
));
14653 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14656 static dw_loc_descr_ref
14657 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
14658 enum var_init_status initialized
)
14660 int have_address
= 0;
14661 dw_loc_descr_ref descr
;
14662 enum machine_mode mode
;
14664 if (want_address
!= 2)
14666 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
14668 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
14670 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
14671 if (GET_CODE (varloc
) == EXPR_LIST
)
14672 varloc
= XEXP (varloc
, 0);
14673 mode
= GET_MODE (varloc
);
14674 if (MEM_P (varloc
))
14676 rtx addr
= XEXP (varloc
, 0);
14677 descr
= mem_loc_descriptor (addr
, mode
, initialized
);
14682 rtx x
= avoid_constant_pool_reference (varloc
);
14684 descr
= mem_loc_descriptor (x
, mode
, initialized
);
14688 descr
= mem_loc_descriptor (varloc
, mode
, initialized
);
14695 if (GET_CODE (varloc
) == VAR_LOCATION
)
14696 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
14698 mode
= DECL_MODE (loc
);
14699 descr
= loc_descriptor (varloc
, mode
, initialized
);
14706 if (want_address
== 2 && !have_address
14707 && (dwarf_version
>= 4 || !dwarf_strict
))
14709 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14711 expansion_failed (loc
, NULL_RTX
,
14712 "DWARF address size mismatch");
14715 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14718 /* Show if we can't fill the request for an address. */
14719 if (want_address
&& !have_address
)
14721 expansion_failed (loc
, NULL_RTX
,
14722 "Want address and only have value");
14726 /* If we've got an address and don't want one, dereference. */
14727 if (!want_address
&& have_address
)
14729 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14730 enum dwarf_location_atom op
;
14732 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14734 expansion_failed (loc
, NULL_RTX
,
14735 "DWARF address size mismatch");
14738 else if (size
== DWARF2_ADDR_SIZE
)
14741 op
= DW_OP_deref_size
;
14743 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
14749 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14750 if it is not possible. */
14752 static dw_loc_descr_ref
14753 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
14755 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
14756 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
14757 else if (dwarf_version
>= 3 || !dwarf_strict
)
14758 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
14763 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14764 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14766 static dw_loc_descr_ref
14767 dw_sra_loc_expr (tree decl
, rtx loc
)
14770 unsigned int padsize
= 0;
14771 dw_loc_descr_ref descr
, *descr_tail
;
14772 unsigned HOST_WIDE_INT decl_size
;
14774 enum var_init_status initialized
;
14776 if (DECL_SIZE (decl
) == NULL
14777 || !host_integerp (DECL_SIZE (decl
), 1))
14780 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
14782 descr_tail
= &descr
;
14784 for (p
= loc
; p
; p
= XEXP (p
, 1))
14786 unsigned int bitsize
= decl_piece_bitsize (p
);
14787 rtx loc_note
= *decl_piece_varloc_ptr (p
);
14788 dw_loc_descr_ref cur_descr
;
14789 dw_loc_descr_ref
*tail
, last
= NULL
;
14790 unsigned int opsize
= 0;
14792 if (loc_note
== NULL_RTX
14793 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
14795 padsize
+= bitsize
;
14798 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
14799 varloc
= NOTE_VAR_LOCATION (loc_note
);
14800 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
14801 if (cur_descr
== NULL
)
14803 padsize
+= bitsize
;
14807 /* Check that cur_descr either doesn't use
14808 DW_OP_*piece operations, or their sum is equal
14809 to bitsize. Otherwise we can't embed it. */
14810 for (tail
= &cur_descr
; *tail
!= NULL
;
14811 tail
= &(*tail
)->dw_loc_next
)
14812 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
14814 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
14818 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
14820 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
14824 if (last
!= NULL
&& opsize
!= bitsize
)
14826 padsize
+= bitsize
;
14830 /* If there is a hole, add DW_OP_*piece after empty DWARF
14831 expression, which means that those bits are optimized out. */
14834 if (padsize
> decl_size
)
14836 decl_size
-= padsize
;
14837 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
14838 if (*descr_tail
== NULL
)
14840 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14843 *descr_tail
= cur_descr
;
14845 if (bitsize
> decl_size
)
14847 decl_size
-= bitsize
;
14850 HOST_WIDE_INT offset
= 0;
14851 if (GET_CODE (varloc
) == VAR_LOCATION
14852 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
14854 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
14855 if (GET_CODE (varloc
) == EXPR_LIST
)
14856 varloc
= XEXP (varloc
, 0);
14860 if (GET_CODE (varloc
) == CONST
14861 || GET_CODE (varloc
) == SIGN_EXTEND
14862 || GET_CODE (varloc
) == ZERO_EXTEND
)
14863 varloc
= XEXP (varloc
, 0);
14864 else if (GET_CODE (varloc
) == SUBREG
)
14865 varloc
= SUBREG_REG (varloc
);
14870 /* DW_OP_bit_size offset should be zero for register
14871 or implicit location descriptions and empty location
14872 descriptions, but for memory addresses needs big endian
14874 if (MEM_P (varloc
))
14876 unsigned HOST_WIDE_INT memsize
14877 = INTVAL (MEM_SIZE (varloc
)) * BITS_PER_UNIT
;
14878 if (memsize
!= bitsize
)
14880 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
14881 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
14883 if (memsize
< bitsize
)
14885 if (BITS_BIG_ENDIAN
)
14886 offset
= memsize
- bitsize
;
14890 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
14891 if (*descr_tail
== NULL
)
14893 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14897 /* If there were any non-empty expressions, add padding till the end of
14899 if (descr
!= NULL
&& decl_size
!= 0)
14901 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
14902 if (*descr_tail
== NULL
)
14908 /* Return the dwarf representation of the location list LOC_LIST of
14909 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
14912 static dw_loc_list_ref
14913 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
14915 const char *endname
, *secname
;
14917 enum var_init_status initialized
;
14918 struct var_loc_node
*node
;
14919 dw_loc_descr_ref descr
;
14920 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
14921 dw_loc_list_ref list
= NULL
;
14922 dw_loc_list_ref
*listp
= &list
;
14924 /* Now that we know what section we are using for a base,
14925 actually construct the list of locations.
14926 The first location information is what is passed to the
14927 function that creates the location list, and the remaining
14928 locations just get added on to that list.
14929 Note that we only know the start address for a location
14930 (IE location changes), so to build the range, we use
14931 the range [current location start, next location start].
14932 This means we have to special case the last node, and generate
14933 a range of [last location start, end of function label]. */
14935 secname
= secname_for_decl (decl
);
14937 for (node
= loc_list
->first
; node
; node
= node
->next
)
14938 if (GET_CODE (node
->loc
) == EXPR_LIST
14939 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
14941 if (GET_CODE (node
->loc
) == EXPR_LIST
)
14943 /* This requires DW_OP_{,bit_}piece, which is not usable
14944 inside DWARF expressions. */
14945 if (want_address
!= 2)
14947 descr
= dw_sra_loc_expr (decl
, node
->loc
);
14953 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
14954 varloc
= NOTE_VAR_LOCATION (node
->loc
);
14955 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
14959 /* The variable has a location between NODE->LABEL and
14960 NODE->NEXT->LABEL. */
14962 endname
= node
->next
->label
;
14963 /* If the variable has a location at the last label
14964 it keeps its location until the end of function. */
14965 else if (!current_function_decl
)
14966 endname
= text_end_label
;
14969 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
14970 current_function_funcdef_no
);
14971 endname
= ggc_strdup (label_id
);
14974 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
14975 listp
= &(*listp
)->dw_loc_next
;
14979 /* Try to avoid the overhead of a location list emitting a location
14980 expression instead, but only if we didn't have more than one
14981 location entry in the first place. If some entries were not
14982 representable, we don't want to pretend a single entry that was
14983 applies to the entire scope in which the variable is
14985 if (list
&& loc_list
->first
->next
)
14991 /* Return if the loc_list has only single element and thus can be represented
14992 as location description. */
14995 single_element_loc_list_p (dw_loc_list_ref list
)
14997 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
14998 return !list
->ll_symbol
;
15001 /* To each location in list LIST add loc descr REF. */
15004 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
15006 dw_loc_descr_ref copy
;
15007 add_loc_descr (&list
->expr
, ref
);
15008 list
= list
->dw_loc_next
;
15011 copy
= ggc_alloc_dw_loc_descr_node ();
15012 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
15013 add_loc_descr (&list
->expr
, copy
);
15014 while (copy
->dw_loc_next
)
15016 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
15017 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
15018 copy
->dw_loc_next
= new_copy
;
15021 list
= list
->dw_loc_next
;
15025 /* Given two lists RET and LIST
15026 produce location list that is result of adding expression in LIST
15027 to expression in RET on each possition in program.
15028 Might be destructive on both RET and LIST.
15030 TODO: We handle only simple cases of RET or LIST having at most one
15031 element. General case would inolve sorting the lists in program order
15032 and merging them that will need some additional work.
15033 Adding that will improve quality of debug info especially for SRA-ed
15037 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
15046 if (!list
->dw_loc_next
)
15048 add_loc_descr_to_each (*ret
, list
->expr
);
15051 if (!(*ret
)->dw_loc_next
)
15053 add_loc_descr_to_each (list
, (*ret
)->expr
);
15057 expansion_failed (NULL_TREE
, NULL_RTX
,
15058 "Don't know how to merge two non-trivial"
15059 " location lists.\n");
15064 /* LOC is constant expression. Try a luck, look it up in constant
15065 pool and return its loc_descr of its address. */
15067 static dw_loc_descr_ref
15068 cst_pool_loc_descr (tree loc
)
15070 /* Get an RTL for this, if something has been emitted. */
15071 rtx rtl
= lookup_constant_def (loc
);
15072 enum machine_mode mode
;
15074 if (!rtl
|| !MEM_P (rtl
))
15079 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
15081 /* TODO: We might get more coverage if we was actually delaying expansion
15082 of all expressions till end of compilation when constant pools are fully
15084 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
15086 expansion_failed (loc
, NULL_RTX
,
15087 "CST value in contant pool but not marked.");
15090 mode
= GET_MODE (rtl
);
15091 rtl
= XEXP (rtl
, 0);
15092 return mem_loc_descriptor (rtl
, mode
, VAR_INIT_STATUS_INITIALIZED
);
15095 /* Return dw_loc_list representing address of addr_expr LOC
15096 by looking for innder INDIRECT_REF expression and turing it
15097 into simple arithmetics. */
15099 static dw_loc_list_ref
15100 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
15103 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
15104 enum machine_mode mode
;
15106 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (loc
));
15107 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
15109 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
15110 &bitsize
, &bitpos
, &offset
, &mode
,
15111 &unsignedp
, &volatilep
, false);
15113 if (bitpos
% BITS_PER_UNIT
)
15115 expansion_failed (loc
, NULL_RTX
, "bitfield access");
15118 if (!INDIRECT_REF_P (obj
))
15120 expansion_failed (obj
,
15121 NULL_RTX
, "no indirect ref in inner refrence");
15124 if (!offset
&& !bitpos
)
15125 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
15127 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
15128 && (dwarf_version
>= 4 || !dwarf_strict
))
15130 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
15135 /* Variable offset. */
15136 list_ret1
= loc_list_from_tree (offset
, 0);
15137 if (list_ret1
== 0)
15139 add_loc_list (&list_ret
, list_ret1
);
15142 add_loc_descr_to_each (list_ret
,
15143 new_loc_descr (DW_OP_plus
, 0, 0));
15145 bytepos
= bitpos
/ BITS_PER_UNIT
;
15147 add_loc_descr_to_each (list_ret
,
15148 new_loc_descr (DW_OP_plus_uconst
,
15150 else if (bytepos
< 0)
15151 loc_list_plus_const (list_ret
, bytepos
);
15152 add_loc_descr_to_each (list_ret
,
15153 new_loc_descr (DW_OP_stack_value
, 0, 0));
15159 /* Generate Dwarf location list representing LOC.
15160 If WANT_ADDRESS is false, expression computing LOC will be computed
15161 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
15162 if WANT_ADDRESS is 2, expression computing address useable in location
15163 will be returned (i.e. DW_OP_reg can be used
15164 to refer to register values). */
15166 static dw_loc_list_ref
15167 loc_list_from_tree (tree loc
, int want_address
)
15169 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
15170 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
15171 int have_address
= 0;
15172 enum dwarf_location_atom op
;
15174 /* ??? Most of the time we do not take proper care for sign/zero
15175 extending the values properly. Hopefully this won't be a real
15178 switch (TREE_CODE (loc
))
15181 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
15184 case PLACEHOLDER_EXPR
:
15185 /* This case involves extracting fields from an object to determine the
15186 position of other fields. We don't try to encode this here. The
15187 only user of this is Ada, which encodes the needed information using
15188 the names of types. */
15189 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
15193 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
15194 /* There are no opcodes for these operations. */
15197 case PREINCREMENT_EXPR
:
15198 case PREDECREMENT_EXPR
:
15199 case POSTINCREMENT_EXPR
:
15200 case POSTDECREMENT_EXPR
:
15201 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
15202 /* There are no opcodes for these operations. */
15206 /* If we already want an address, see if there is INDIRECT_REF inside
15207 e.g. for &this->field. */
15210 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
15211 (loc
, want_address
== 2);
15214 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
15215 && (ret
= cst_pool_loc_descr (loc
)))
15218 /* Otherwise, process the argument and look for the address. */
15219 if (!list_ret
&& !ret
)
15220 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
15224 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
15230 if (DECL_THREAD_LOCAL_P (loc
))
15233 enum dwarf_location_atom first_op
;
15234 enum dwarf_location_atom second_op
;
15235 bool dtprel
= false;
15237 if (targetm
.have_tls
)
15239 /* If this is not defined, we have no way to emit the
15241 if (!targetm
.asm_out
.output_dwarf_dtprel
)
15244 /* The way DW_OP_GNU_push_tls_address is specified, we
15245 can only look up addresses of objects in the current
15246 module. We used DW_OP_addr as first op, but that's
15247 wrong, because DW_OP_addr is relocated by the debug
15248 info consumer, while DW_OP_GNU_push_tls_address
15249 operand shouldn't be. */
15250 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
15252 first_op
= DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
;
15254 second_op
= DW_OP_GNU_push_tls_address
;
15258 if (!targetm
.emutls
.debug_form_tls_address
15259 || !(dwarf_version
>= 3 || !dwarf_strict
))
15261 /* We stuffed the control variable into the DECL_VALUE_EXPR
15262 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
15263 no longer appear in gimple code. We used the control
15264 variable in specific so that we could pick it up here. */
15265 loc
= DECL_VALUE_EXPR (loc
);
15266 first_op
= DW_OP_addr
;
15267 second_op
= DW_OP_form_tls_address
;
15270 rtl
= rtl_for_decl_location (loc
);
15271 if (rtl
== NULL_RTX
)
15276 rtl
= XEXP (rtl
, 0);
15277 if (! CONSTANT_P (rtl
))
15280 ret
= new_loc_descr (first_op
, 0, 0);
15281 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
15282 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
15283 ret
->dtprel
= dtprel
;
15285 ret1
= new_loc_descr (second_op
, 0, 0);
15286 add_loc_descr (&ret
, ret1
);
15294 if (DECL_HAS_VALUE_EXPR_P (loc
))
15295 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
15300 case FUNCTION_DECL
:
15303 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
15305 if (loc_list
&& loc_list
->first
)
15307 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
15308 have_address
= want_address
!= 0;
15311 rtl
= rtl_for_decl_location (loc
);
15312 if (rtl
== NULL_RTX
)
15314 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
15317 else if (CONST_INT_P (rtl
))
15319 HOST_WIDE_INT val
= INTVAL (rtl
);
15320 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
15321 val
&= GET_MODE_MASK (DECL_MODE (loc
));
15322 ret
= int_loc_descriptor (val
);
15324 else if (GET_CODE (rtl
) == CONST_STRING
)
15326 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
15329 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
15331 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
15332 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
15333 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
15337 enum machine_mode mode
;
15339 /* Certain constructs can only be represented at top-level. */
15340 if (want_address
== 2)
15342 ret
= loc_descriptor (rtl
, VOIDmode
,
15343 VAR_INIT_STATUS_INITIALIZED
);
15348 mode
= GET_MODE (rtl
);
15351 rtl
= XEXP (rtl
, 0);
15354 ret
= mem_loc_descriptor (rtl
, mode
, VAR_INIT_STATUS_INITIALIZED
);
15357 expansion_failed (loc
, rtl
,
15358 "failed to produce loc descriptor for rtl");
15365 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
15369 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15373 case COMPOUND_EXPR
:
15374 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
15377 case VIEW_CONVERT_EXPR
:
15380 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
15382 case COMPONENT_REF
:
15383 case BIT_FIELD_REF
:
15385 case ARRAY_RANGE_REF
:
15386 case REALPART_EXPR
:
15387 case IMAGPART_EXPR
:
15390 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
15391 enum machine_mode mode
;
15393 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (loc
));
15395 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
15396 &unsignedp
, &volatilep
, false);
15398 gcc_assert (obj
!= loc
);
15400 list_ret
= loc_list_from_tree (obj
,
15402 && !bitpos
&& !offset
? 2 : 1);
15403 /* TODO: We can extract value of the small expression via shifting even
15404 for nonzero bitpos. */
15407 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
15409 expansion_failed (loc
, NULL_RTX
,
15410 "bitfield access");
15414 if (offset
!= NULL_TREE
)
15416 /* Variable offset. */
15417 list_ret1
= loc_list_from_tree (offset
, 0);
15418 if (list_ret1
== 0)
15420 add_loc_list (&list_ret
, list_ret1
);
15423 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
15426 bytepos
= bitpos
/ BITS_PER_UNIT
;
15428 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
15429 else if (bytepos
< 0)
15430 loc_list_plus_const (list_ret
, bytepos
);
15437 if ((want_address
|| !host_integerp (loc
, 0))
15438 && (ret
= cst_pool_loc_descr (loc
)))
15440 else if (want_address
== 2
15441 && host_integerp (loc
, 0)
15442 && (ret
= address_of_int_loc_descriptor
15443 (int_size_in_bytes (TREE_TYPE (loc
)),
15444 tree_low_cst (loc
, 0))))
15446 else if (host_integerp (loc
, 0))
15447 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
15450 expansion_failed (loc
, NULL_RTX
,
15451 "Integer operand is not host integer");
15460 if ((ret
= cst_pool_loc_descr (loc
)))
15463 /* We can construct small constants here using int_loc_descriptor. */
15464 expansion_failed (loc
, NULL_RTX
,
15465 "constructor or constant not in constant pool");
15468 case TRUTH_AND_EXPR
:
15469 case TRUTH_ANDIF_EXPR
:
15474 case TRUTH_XOR_EXPR
:
15479 case TRUTH_OR_EXPR
:
15480 case TRUTH_ORIF_EXPR
:
15485 case FLOOR_DIV_EXPR
:
15486 case CEIL_DIV_EXPR
:
15487 case ROUND_DIV_EXPR
:
15488 case TRUNC_DIV_EXPR
:
15489 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
15498 case FLOOR_MOD_EXPR
:
15499 case CEIL_MOD_EXPR
:
15500 case ROUND_MOD_EXPR
:
15501 case TRUNC_MOD_EXPR
:
15502 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
15507 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15508 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
15509 if (list_ret
== 0 || list_ret1
== 0)
15512 add_loc_list (&list_ret
, list_ret1
);
15515 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
15516 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
15517 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
15518 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
15519 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
15531 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
15534 case POINTER_PLUS_EXPR
:
15536 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
15538 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15542 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
15550 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
15557 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
15564 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
15571 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
15586 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15587 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
15588 if (list_ret
== 0 || list_ret1
== 0)
15591 add_loc_list (&list_ret
, list_ret1
);
15594 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
15597 case TRUTH_NOT_EXPR
:
15611 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15615 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
15621 const enum tree_code code
=
15622 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
15624 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
15625 build2 (code
, integer_type_node
,
15626 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
15627 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
15630 /* ... fall through ... */
15634 dw_loc_descr_ref lhs
15635 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
15636 dw_loc_list_ref rhs
15637 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
15638 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
15640 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15641 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
15644 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
15645 add_loc_descr_to_each (list_ret
, bra_node
);
15647 add_loc_list (&list_ret
, rhs
);
15648 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
15649 add_loc_descr_to_each (list_ret
, jump_node
);
15651 add_loc_descr_to_each (list_ret
, lhs
);
15652 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15653 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
15655 /* ??? Need a node to point the skip at. Use a nop. */
15656 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
15657 add_loc_descr_to_each (list_ret
, tmp
);
15658 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15659 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
15663 case FIX_TRUNC_EXPR
:
15667 /* Leave front-end specific codes as simply unknown. This comes
15668 up, for instance, with the C STMT_EXPR. */
15669 if ((unsigned int) TREE_CODE (loc
)
15670 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
15672 expansion_failed (loc
, NULL_RTX
,
15673 "language specific tree node");
15677 #ifdef ENABLE_CHECKING
15678 /* Otherwise this is a generic code; we should just lists all of
15679 these explicitly. We forgot one. */
15680 gcc_unreachable ();
15682 /* In a release build, we want to degrade gracefully: better to
15683 generate incomplete debugging information than to crash. */
15688 if (!ret
&& !list_ret
)
15691 if (want_address
== 2 && !have_address
15692 && (dwarf_version
>= 4 || !dwarf_strict
))
15694 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
15696 expansion_failed (loc
, NULL_RTX
,
15697 "DWARF address size mismatch");
15701 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15703 add_loc_descr_to_each (list_ret
,
15704 new_loc_descr (DW_OP_stack_value
, 0, 0));
15707 /* Show if we can't fill the request for an address. */
15708 if (want_address
&& !have_address
)
15710 expansion_failed (loc
, NULL_RTX
,
15711 "Want address and only have value");
15715 gcc_assert (!ret
|| !list_ret
);
15717 /* If we've got an address and don't want one, dereference. */
15718 if (!want_address
&& have_address
)
15720 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
15722 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
15724 expansion_failed (loc
, NULL_RTX
,
15725 "DWARF address size mismatch");
15728 else if (size
== DWARF2_ADDR_SIZE
)
15731 op
= DW_OP_deref_size
;
15734 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
15736 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
15739 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
15744 /* Same as above but return only single location expression. */
15745 static dw_loc_descr_ref
15746 loc_descriptor_from_tree (tree loc
, int want_address
)
15748 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
15751 if (ret
->dw_loc_next
)
15753 expansion_failed (loc
, NULL_RTX
,
15754 "Location list where only loc descriptor needed");
15760 /* Given a value, round it up to the lowest multiple of `boundary'
15761 which is not less than the value itself. */
15763 static inline HOST_WIDE_INT
15764 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
15766 return (((value
+ boundary
- 1) / boundary
) * boundary
);
15769 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
15770 pointer to the declared type for the relevant field variable, or return
15771 `integer_type_node' if the given node turns out to be an
15772 ERROR_MARK node. */
15775 field_type (const_tree decl
)
15779 if (TREE_CODE (decl
) == ERROR_MARK
)
15780 return integer_type_node
;
15782 type
= DECL_BIT_FIELD_TYPE (decl
);
15783 if (type
== NULL_TREE
)
15784 type
= TREE_TYPE (decl
);
15789 /* Given a pointer to a tree node, return the alignment in bits for
15790 it, or else return BITS_PER_WORD if the node actually turns out to
15791 be an ERROR_MARK node. */
15793 static inline unsigned
15794 simple_type_align_in_bits (const_tree type
)
15796 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
15799 static inline unsigned
15800 simple_decl_align_in_bits (const_tree decl
)
15802 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
15805 /* Return the result of rounding T up to ALIGN. */
15807 static inline double_int
15808 round_up_to_align (double_int t
, unsigned int align
)
15810 double_int alignd
= uhwi_to_double_int (align
);
15811 t
= double_int_add (t
, alignd
);
15812 t
= double_int_add (t
, double_int_minus_one
);
15813 t
= double_int_div (t
, alignd
, true, TRUNC_DIV_EXPR
);
15814 t
= double_int_mul (t
, alignd
);
15818 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
15819 lowest addressed byte of the "containing object" for the given FIELD_DECL,
15820 or return 0 if we are unable to determine what that offset is, either
15821 because the argument turns out to be a pointer to an ERROR_MARK node, or
15822 because the offset is actually variable. (We can't handle the latter case
15825 static HOST_WIDE_INT
15826 field_byte_offset (const_tree decl
)
15828 double_int object_offset_in_bits
;
15829 double_int object_offset_in_bytes
;
15830 double_int bitpos_int
;
15832 if (TREE_CODE (decl
) == ERROR_MARK
)
15835 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
15837 /* We cannot yet cope with fields whose positions are variable, so
15838 for now, when we see such things, we simply return 0. Someday, we may
15839 be able to handle such cases, but it will be damn difficult. */
15840 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
15843 bitpos_int
= tree_to_double_int (bit_position (decl
));
15845 #ifdef PCC_BITFIELD_TYPE_MATTERS
15846 if (PCC_BITFIELD_TYPE_MATTERS
)
15849 tree field_size_tree
;
15850 double_int deepest_bitpos
;
15851 double_int field_size_in_bits
;
15852 unsigned int type_align_in_bits
;
15853 unsigned int decl_align_in_bits
;
15854 double_int type_size_in_bits
;
15856 type
= field_type (decl
);
15857 type_size_in_bits
= double_int_type_size_in_bits (type
);
15858 type_align_in_bits
= simple_type_align_in_bits (type
);
15860 field_size_tree
= DECL_SIZE (decl
);
15862 /* The size could be unspecified if there was an error, or for
15863 a flexible array member. */
15864 if (!field_size_tree
)
15865 field_size_tree
= bitsize_zero_node
;
15867 /* If the size of the field is not constant, use the type size. */
15868 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
15869 field_size_in_bits
= tree_to_double_int (field_size_tree
);
15871 field_size_in_bits
= type_size_in_bits
;
15873 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
15875 /* The GCC front-end doesn't make any attempt to keep track of the
15876 starting bit offset (relative to the start of the containing
15877 structure type) of the hypothetical "containing object" for a
15878 bit-field. Thus, when computing the byte offset value for the
15879 start of the "containing object" of a bit-field, we must deduce
15880 this information on our own. This can be rather tricky to do in
15881 some cases. For example, handling the following structure type
15882 definition when compiling for an i386/i486 target (which only
15883 aligns long long's to 32-bit boundaries) can be very tricky:
15885 struct S { int field1; long long field2:31; };
15887 Fortunately, there is a simple rule-of-thumb which can be used
15888 in such cases. When compiling for an i386/i486, GCC will
15889 allocate 8 bytes for the structure shown above. It decides to
15890 do this based upon one simple rule for bit-field allocation.
15891 GCC allocates each "containing object" for each bit-field at
15892 the first (i.e. lowest addressed) legitimate alignment boundary
15893 (based upon the required minimum alignment for the declared
15894 type of the field) which it can possibly use, subject to the
15895 condition that there is still enough available space remaining
15896 in the containing object (when allocated at the selected point)
15897 to fully accommodate all of the bits of the bit-field itself.
15899 This simple rule makes it obvious why GCC allocates 8 bytes for
15900 each object of the structure type shown above. When looking
15901 for a place to allocate the "containing object" for `field2',
15902 the compiler simply tries to allocate a 64-bit "containing
15903 object" at each successive 32-bit boundary (starting at zero)
15904 until it finds a place to allocate that 64- bit field such that
15905 at least 31 contiguous (and previously unallocated) bits remain
15906 within that selected 64 bit field. (As it turns out, for the
15907 example above, the compiler finds it is OK to allocate the
15908 "containing object" 64-bit field at bit-offset zero within the
15911 Here we attempt to work backwards from the limited set of facts
15912 we're given, and we try to deduce from those facts, where GCC
15913 must have believed that the containing object started (within
15914 the structure type). The value we deduce is then used (by the
15915 callers of this routine) to generate DW_AT_location and
15916 DW_AT_bit_offset attributes for fields (both bit-fields and, in
15917 the case of DW_AT_location, regular fields as well). */
15919 /* Figure out the bit-distance from the start of the structure to
15920 the "deepest" bit of the bit-field. */
15921 deepest_bitpos
= double_int_add (bitpos_int
, field_size_in_bits
);
15923 /* This is the tricky part. Use some fancy footwork to deduce
15924 where the lowest addressed bit of the containing object must
15926 object_offset_in_bits
15927 = double_int_sub (deepest_bitpos
, type_size_in_bits
);
15929 /* Round up to type_align by default. This works best for
15931 object_offset_in_bits
15932 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
15934 if (double_int_ucmp (object_offset_in_bits
, bitpos_int
) > 0)
15936 object_offset_in_bits
15937 = double_int_sub (deepest_bitpos
, type_size_in_bits
);
15939 /* Round up to decl_align instead. */
15940 object_offset_in_bits
15941 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
15945 #endif /* PCC_BITFIELD_TYPE_MATTERS */
15946 object_offset_in_bits
= bitpos_int
;
15948 object_offset_in_bytes
15949 = double_int_div (object_offset_in_bits
,
15950 uhwi_to_double_int (BITS_PER_UNIT
), true,
15952 return double_int_to_shwi (object_offset_in_bytes
);
15955 /* The following routines define various Dwarf attributes and any data
15956 associated with them. */
15958 /* Add a location description attribute value to a DIE.
15960 This emits location attributes suitable for whole variables and
15961 whole parameters. Note that the location attributes for struct fields are
15962 generated by the routine `data_member_location_attribute' below. */
15965 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
15966 dw_loc_list_ref descr
)
15970 if (single_element_loc_list_p (descr
))
15971 add_AT_loc (die
, attr_kind
, descr
->expr
);
15973 add_AT_loc_list (die
, attr_kind
, descr
);
15976 /* Add DW_AT_accessibility attribute to DIE if needed. */
15979 add_accessibility_attribute (dw_die_ref die
, tree decl
)
15981 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
15982 children, otherwise the default is DW_ACCESS_public. In DWARF2
15983 the default has always been DW_ACCESS_public. */
15984 if (TREE_PROTECTED (decl
))
15985 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
15986 else if (TREE_PRIVATE (decl
))
15988 if (dwarf_version
== 2
15989 || die
->die_parent
== NULL
15990 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
15991 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
15993 else if (dwarf_version
> 2
15995 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
15996 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
15999 /* Attach the specialized form of location attribute used for data members of
16000 struct and union types. In the special case of a FIELD_DECL node which
16001 represents a bit-field, the "offset" part of this special location
16002 descriptor must indicate the distance in bytes from the lowest-addressed
16003 byte of the containing struct or union type to the lowest-addressed byte of
16004 the "containing object" for the bit-field. (See the `field_byte_offset'
16007 For any given bit-field, the "containing object" is a hypothetical object
16008 (of some integral or enum type) within which the given bit-field lives. The
16009 type of this hypothetical "containing object" is always the same as the
16010 declared type of the individual bit-field itself (for GCC anyway... the
16011 DWARF spec doesn't actually mandate this). Note that it is the size (in
16012 bytes) of the hypothetical "containing object" which will be given in the
16013 DW_AT_byte_size attribute for this bit-field. (See the
16014 `byte_size_attribute' function below.) It is also used when calculating the
16015 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
16016 function below.) */
16019 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
16021 HOST_WIDE_INT offset
;
16022 dw_loc_descr_ref loc_descr
= 0;
16024 if (TREE_CODE (decl
) == TREE_BINFO
)
16026 /* We're working on the TAG_inheritance for a base class. */
16027 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
16029 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
16030 aren't at a fixed offset from all (sub)objects of the same
16031 type. We need to extract the appropriate offset from our
16032 vtable. The following dwarf expression means
16034 BaseAddr = ObAddr + *((*ObAddr) - Offset)
16036 This is specific to the V3 ABI, of course. */
16038 dw_loc_descr_ref tmp
;
16040 /* Make a copy of the object address. */
16041 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
16042 add_loc_descr (&loc_descr
, tmp
);
16044 /* Extract the vtable address. */
16045 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
16046 add_loc_descr (&loc_descr
, tmp
);
16048 /* Calculate the address of the offset. */
16049 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
16050 gcc_assert (offset
< 0);
16052 tmp
= int_loc_descriptor (-offset
);
16053 add_loc_descr (&loc_descr
, tmp
);
16054 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
16055 add_loc_descr (&loc_descr
, tmp
);
16057 /* Extract the offset. */
16058 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
16059 add_loc_descr (&loc_descr
, tmp
);
16061 /* Add it to the object address. */
16062 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
16063 add_loc_descr (&loc_descr
, tmp
);
16066 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
16069 offset
= field_byte_offset (decl
);
16073 if (dwarf_version
> 2)
16075 /* Don't need to output a location expression, just the constant. */
16077 add_AT_int (die
, DW_AT_data_member_location
, offset
);
16079 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
16084 enum dwarf_location_atom op
;
16086 /* The DWARF2 standard says that we should assume that the structure
16087 address is already on the stack, so we can specify a structure
16088 field address by using DW_OP_plus_uconst. */
16090 #ifdef MIPS_DEBUGGING_INFO
16091 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
16092 operator correctly. It works only if we leave the offset on the
16096 op
= DW_OP_plus_uconst
;
16099 loc_descr
= new_loc_descr (op
, offset
, 0);
16103 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
16106 /* Writes integer values to dw_vec_const array. */
16109 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
16113 *dest
++ = val
& 0xff;
16119 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
16121 static HOST_WIDE_INT
16122 extract_int (const unsigned char *src
, unsigned int size
)
16124 HOST_WIDE_INT val
= 0;
16130 val
|= *--src
& 0xff;
16136 /* Writes double_int values to dw_vec_const array. */
16139 insert_double (double_int val
, unsigned char *dest
)
16141 unsigned char *p0
= dest
;
16142 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
16144 if (WORDS_BIG_ENDIAN
)
16150 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
16151 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
16154 /* Writes floating point values to dw_vec_const array. */
16157 insert_float (const_rtx rtl
, unsigned char *array
)
16159 REAL_VALUE_TYPE rv
;
16163 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
16164 real_to_target (val
, &rv
, GET_MODE (rtl
));
16166 /* real_to_target puts 32-bit pieces in each long. Pack them. */
16167 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
16169 insert_int (val
[i
], 4, array
);
16174 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
16175 does not have a "location" either in memory or in a register. These
16176 things can arise in GNU C when a constant is passed as an actual parameter
16177 to an inlined function. They can also arise in C++ where declared
16178 constants do not necessarily get memory "homes". */
16181 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
16183 switch (GET_CODE (rtl
))
16187 HOST_WIDE_INT val
= INTVAL (rtl
);
16190 add_AT_int (die
, DW_AT_const_value
, val
);
16192 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
16197 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
16198 floating-point constant. A CONST_DOUBLE is used whenever the
16199 constant requires more than one word in order to be adequately
16202 enum machine_mode mode
= GET_MODE (rtl
);
16204 if (SCALAR_FLOAT_MODE_P (mode
))
16206 unsigned int length
= GET_MODE_SIZE (mode
);
16207 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
16209 insert_float (rtl
, array
);
16210 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
16213 add_AT_double (die
, DW_AT_const_value
,
16214 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
16220 enum machine_mode mode
= GET_MODE (rtl
);
16221 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
16222 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
16223 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
16224 (length
* elt_size
);
16228 switch (GET_MODE_CLASS (mode
))
16230 case MODE_VECTOR_INT
:
16231 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
16233 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
16234 double_int val
= rtx_to_double_int (elt
);
16236 if (elt_size
<= sizeof (HOST_WIDE_INT
))
16237 insert_int (double_int_to_shwi (val
), elt_size
, p
);
16240 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
16241 insert_double (val
, p
);
16246 case MODE_VECTOR_FLOAT
:
16247 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
16249 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
16250 insert_float (elt
, p
);
16255 gcc_unreachable ();
16258 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
16263 if (dwarf_version
>= 4 || !dwarf_strict
)
16265 dw_loc_descr_ref loc_result
;
16266 resolve_one_addr (&rtl
, NULL
);
16268 loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
16269 loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
16270 loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
16271 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
16272 add_AT_loc (die
, DW_AT_location
, loc_result
);
16273 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
16279 if (CONSTANT_P (XEXP (rtl
, 0)))
16280 return add_const_value_attribute (die
, XEXP (rtl
, 0));
16283 if (!const_ok_for_output (rtl
))
16286 if (dwarf_version
>= 4 || !dwarf_strict
)
16291 /* In cases where an inlined instance of an inline function is passed
16292 the address of an `auto' variable (which is local to the caller) we
16293 can get a situation where the DECL_RTL of the artificial local
16294 variable (for the inlining) which acts as a stand-in for the
16295 corresponding formal parameter (of the inline function) will look
16296 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
16297 exactly a compile-time constant expression, but it isn't the address
16298 of the (artificial) local variable either. Rather, it represents the
16299 *value* which the artificial local variable always has during its
16300 lifetime. We currently have no way to represent such quasi-constant
16301 values in Dwarf, so for now we just punt and generate nothing. */
16309 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
16310 && MEM_READONLY_P (rtl
)
16311 && GET_MODE (rtl
) == BLKmode
)
16313 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
16319 /* No other kinds of rtx should be possible here. */
16320 gcc_unreachable ();
16325 /* Determine whether the evaluation of EXPR references any variables
16326 or functions which aren't otherwise used (and therefore may not be
16329 reference_to_unused (tree
* tp
, int * walk_subtrees
,
16330 void * data ATTRIBUTE_UNUSED
)
16332 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
16333 *walk_subtrees
= 0;
16335 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
16336 && ! TREE_ASM_WRITTEN (*tp
))
16338 /* ??? The C++ FE emits debug information for using decls, so
16339 putting gcc_unreachable here falls over. See PR31899. For now
16340 be conservative. */
16341 else if (!cgraph_global_info_ready
16342 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
16344 else if (TREE_CODE (*tp
) == VAR_DECL
)
16346 struct varpool_node
*node
= varpool_get_node (*tp
);
16347 if (!node
|| !node
->needed
)
16350 else if (TREE_CODE (*tp
) == FUNCTION_DECL
16351 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
16353 /* The call graph machinery must have finished analyzing,
16354 optimizing and gimplifying the CU by now.
16355 So if *TP has no call graph node associated
16356 to it, it means *TP will not be emitted. */
16357 if (!cgraph_get_node (*tp
))
16360 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
16366 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
16367 for use in a later add_const_value_attribute call. */
16370 rtl_for_decl_init (tree init
, tree type
)
16372 rtx rtl
= NULL_RTX
;
16374 /* If a variable is initialized with a string constant without embedded
16375 zeros, build CONST_STRING. */
16376 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
16378 tree enttype
= TREE_TYPE (type
);
16379 tree domain
= TYPE_DOMAIN (type
);
16380 enum machine_mode mode
= TYPE_MODE (enttype
);
16382 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
16384 && integer_zerop (TYPE_MIN_VALUE (domain
))
16385 && compare_tree_int (TYPE_MAX_VALUE (domain
),
16386 TREE_STRING_LENGTH (init
) - 1) == 0
16387 && ((size_t) TREE_STRING_LENGTH (init
)
16388 == strlen (TREE_STRING_POINTER (init
)) + 1))
16390 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
16391 ggc_strdup (TREE_STRING_POINTER (init
)));
16392 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
16393 MEM_READONLY_P (rtl
) = 1;
16396 /* Other aggregates, and complex values, could be represented using
16398 else if (AGGREGATE_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
16400 /* Vectors only work if their mode is supported by the target.
16401 FIXME: generic vectors ought to work too. */
16402 else if (TREE_CODE (type
) == VECTOR_TYPE
16403 && !VECTOR_MODE_P (TYPE_MODE (type
)))
16405 /* If the initializer is something that we know will expand into an
16406 immediate RTL constant, expand it now. We must be careful not to
16407 reference variables which won't be output. */
16408 else if (initializer_constant_valid_p (init
, type
)
16409 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
16411 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
16413 if (TREE_CODE (type
) == VECTOR_TYPE
)
16414 switch (TREE_CODE (init
))
16419 if (TREE_CONSTANT (init
))
16421 VEC(constructor_elt
,gc
) *elts
= CONSTRUCTOR_ELTS (init
);
16422 bool constant_p
= true;
16424 unsigned HOST_WIDE_INT ix
;
16426 /* Even when ctor is constant, it might contain non-*_CST
16427 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
16428 belong into VECTOR_CST nodes. */
16429 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
16430 if (!CONSTANT_CLASS_P (value
))
16432 constant_p
= false;
16438 init
= build_vector_from_ctor (type
, elts
);
16448 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
16450 /* If expand_expr returns a MEM, it wasn't immediate. */
16451 gcc_assert (!rtl
|| !MEM_P (rtl
));
16457 /* Generate RTL for the variable DECL to represent its location. */
16460 rtl_for_decl_location (tree decl
)
16464 /* Here we have to decide where we are going to say the parameter "lives"
16465 (as far as the debugger is concerned). We only have a couple of
16466 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
16468 DECL_RTL normally indicates where the parameter lives during most of the
16469 activation of the function. If optimization is enabled however, this
16470 could be either NULL or else a pseudo-reg. Both of those cases indicate
16471 that the parameter doesn't really live anywhere (as far as the code
16472 generation parts of GCC are concerned) during most of the function's
16473 activation. That will happen (for example) if the parameter is never
16474 referenced within the function.
16476 We could just generate a location descriptor here for all non-NULL
16477 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
16478 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
16479 where DECL_RTL is NULL or is a pseudo-reg.
16481 Note however that we can only get away with using DECL_INCOMING_RTL as
16482 a backup substitute for DECL_RTL in certain limited cases. In cases
16483 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
16484 we can be sure that the parameter was passed using the same type as it is
16485 declared to have within the function, and that its DECL_INCOMING_RTL
16486 points us to a place where a value of that type is passed.
16488 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
16489 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
16490 because in these cases DECL_INCOMING_RTL points us to a value of some
16491 type which is *different* from the type of the parameter itself. Thus,
16492 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
16493 such cases, the debugger would end up (for example) trying to fetch a
16494 `float' from a place which actually contains the first part of a
16495 `double'. That would lead to really incorrect and confusing
16496 output at debug-time.
16498 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
16499 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
16500 are a couple of exceptions however. On little-endian machines we can
16501 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
16502 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
16503 an integral type that is smaller than TREE_TYPE (decl). These cases arise
16504 when (on a little-endian machine) a non-prototyped function has a
16505 parameter declared to be of type `short' or `char'. In such cases,
16506 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
16507 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
16508 passed `int' value. If the debugger then uses that address to fetch
16509 a `short' or a `char' (on a little-endian machine) the result will be
16510 the correct data, so we allow for such exceptional cases below.
16512 Note that our goal here is to describe the place where the given formal
16513 parameter lives during most of the function's activation (i.e. between the
16514 end of the prologue and the start of the epilogue). We'll do that as best
16515 as we can. Note however that if the given formal parameter is modified
16516 sometime during the execution of the function, then a stack backtrace (at
16517 debug-time) will show the function as having been called with the *new*
16518 value rather than the value which was originally passed in. This happens
16519 rarely enough that it is not a major problem, but it *is* a problem, and
16520 I'd like to fix it.
16522 A future version of dwarf2out.c may generate two additional attributes for
16523 any given DW_TAG_formal_parameter DIE which will describe the "passed
16524 type" and the "passed location" for the given formal parameter in addition
16525 to the attributes we now generate to indicate the "declared type" and the
16526 "active location" for each parameter. This additional set of attributes
16527 could be used by debuggers for stack backtraces. Separately, note that
16528 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
16529 This happens (for example) for inlined-instances of inline function formal
16530 parameters which are never referenced. This really shouldn't be
16531 happening. All PARM_DECL nodes should get valid non-NULL
16532 DECL_INCOMING_RTL values. FIXME. */
16534 /* Use DECL_RTL as the "location" unless we find something better. */
16535 rtl
= DECL_RTL_IF_SET (decl
);
16537 /* When generating abstract instances, ignore everything except
16538 constants, symbols living in memory, and symbols living in
16539 fixed registers. */
16540 if (! reload_completed
)
16543 && (CONSTANT_P (rtl
)
16545 && CONSTANT_P (XEXP (rtl
, 0)))
16547 && TREE_CODE (decl
) == VAR_DECL
16548 && TREE_STATIC (decl
))))
16550 rtl
= targetm
.delegitimize_address (rtl
);
16555 else if (TREE_CODE (decl
) == PARM_DECL
)
16557 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
16559 tree declared_type
= TREE_TYPE (decl
);
16560 tree passed_type
= DECL_ARG_TYPE (decl
);
16561 enum machine_mode dmode
= TYPE_MODE (declared_type
);
16562 enum machine_mode pmode
= TYPE_MODE (passed_type
);
16564 /* This decl represents a formal parameter which was optimized out.
16565 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
16566 all cases where (rtl == NULL_RTX) just below. */
16567 if (dmode
== pmode
)
16568 rtl
= DECL_INCOMING_RTL (decl
);
16569 else if (SCALAR_INT_MODE_P (dmode
)
16570 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
16571 && DECL_INCOMING_RTL (decl
))
16573 rtx inc
= DECL_INCOMING_RTL (decl
);
16576 else if (MEM_P (inc
))
16578 if (BYTES_BIG_ENDIAN
)
16579 rtl
= adjust_address_nv (inc
, dmode
,
16580 GET_MODE_SIZE (pmode
)
16581 - GET_MODE_SIZE (dmode
));
16588 /* If the parm was passed in registers, but lives on the stack, then
16589 make a big endian correction if the mode of the type of the
16590 parameter is not the same as the mode of the rtl. */
16591 /* ??? This is the same series of checks that are made in dbxout.c before
16592 we reach the big endian correction code there. It isn't clear if all
16593 of these checks are necessary here, but keeping them all is the safe
16595 else if (MEM_P (rtl
)
16596 && XEXP (rtl
, 0) != const0_rtx
16597 && ! CONSTANT_P (XEXP (rtl
, 0))
16598 /* Not passed in memory. */
16599 && !MEM_P (DECL_INCOMING_RTL (decl
))
16600 /* Not passed by invisible reference. */
16601 && (!REG_P (XEXP (rtl
, 0))
16602 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
16603 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
16604 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
16605 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
16608 /* Big endian correction check. */
16609 && BYTES_BIG_ENDIAN
16610 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
16611 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
16614 int offset
= (UNITS_PER_WORD
16615 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
16617 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
16618 plus_constant (XEXP (rtl
, 0), offset
));
16621 else if (TREE_CODE (decl
) == VAR_DECL
16624 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
16625 && BYTES_BIG_ENDIAN
)
16627 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
16628 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
16630 /* If a variable is declared "register" yet is smaller than
16631 a register, then if we store the variable to memory, it
16632 looks like we're storing a register-sized value, when in
16633 fact we are not. We need to adjust the offset of the
16634 storage location to reflect the actual value's bytes,
16635 else gdb will not be able to display it. */
16637 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
16638 plus_constant (XEXP (rtl
, 0), rsize
-dsize
));
16641 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16642 and will have been substituted directly into all expressions that use it.
16643 C does not have such a concept, but C++ and other languages do. */
16644 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
16645 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
16648 rtl
= targetm
.delegitimize_address (rtl
);
16650 /* If we don't look past the constant pool, we risk emitting a
16651 reference to a constant pool entry that isn't referenced from
16652 code, and thus is not emitted. */
16654 rtl
= avoid_constant_pool_reference (rtl
);
16656 /* Try harder to get a rtl. If this symbol ends up not being emitted
16657 in the current CU, resolve_addr will remove the expression referencing
16659 if (rtl
== NULL_RTX
16660 && TREE_CODE (decl
) == VAR_DECL
16661 && !DECL_EXTERNAL (decl
)
16662 && TREE_STATIC (decl
)
16663 && DECL_NAME (decl
)
16664 && !DECL_HARD_REGISTER (decl
)
16665 && DECL_MODE (decl
) != VOIDmode
)
16667 rtl
= make_decl_rtl_for_debug (decl
);
16669 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
16670 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
16677 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
16678 returned. If so, the decl for the COMMON block is returned, and the
16679 value is the offset into the common block for the symbol. */
16682 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
16684 tree val_expr
, cvar
;
16685 enum machine_mode mode
;
16686 HOST_WIDE_INT bitsize
, bitpos
;
16688 int volatilep
= 0, unsignedp
= 0;
16690 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
16691 it does not have a value (the offset into the common area), or if it
16692 is thread local (as opposed to global) then it isn't common, and shouldn't
16693 be handled as such. */
16694 if (TREE_CODE (decl
) != VAR_DECL
16695 || !TREE_STATIC (decl
)
16696 || !DECL_HAS_VALUE_EXPR_P (decl
)
16700 val_expr
= DECL_VALUE_EXPR (decl
);
16701 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
16704 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
16705 &mode
, &unsignedp
, &volatilep
, true);
16707 if (cvar
== NULL_TREE
16708 || TREE_CODE (cvar
) != VAR_DECL
16709 || DECL_ARTIFICIAL (cvar
)
16710 || !TREE_PUBLIC (cvar
))
16714 if (offset
!= NULL
)
16716 if (!host_integerp (offset
, 0))
16718 *value
= tree_low_cst (offset
, 0);
16721 *value
+= bitpos
/ BITS_PER_UNIT
;
16726 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
16727 data attribute for a variable or a parameter. We generate the
16728 DW_AT_const_value attribute only in those cases where the given variable
16729 or parameter does not have a true "location" either in memory or in a
16730 register. This can happen (for example) when a constant is passed as an
16731 actual argument in a call to an inline function. (It's possible that
16732 these things can crop up in other ways also.) Note that one type of
16733 constant value which can be passed into an inlined function is a constant
16734 pointer. This can happen for example if an actual argument in an inlined
16735 function call evaluates to a compile-time constant address. */
16738 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
,
16739 enum dwarf_attribute attr
)
16742 dw_loc_list_ref list
;
16743 var_loc_list
*loc_list
;
16745 if (TREE_CODE (decl
) == ERROR_MARK
)
16748 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
16749 || TREE_CODE (decl
) == RESULT_DECL
);
16751 /* Try to get some constant RTL for this decl, and use that as the value of
16754 rtl
= rtl_for_decl_location (decl
);
16755 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
16756 && add_const_value_attribute (die
, rtl
))
16759 /* See if we have single element location list that is equivalent to
16760 a constant value. That way we are better to use add_const_value_attribute
16761 rather than expanding constant value equivalent. */
16762 loc_list
= lookup_decl_loc (decl
);
16765 && loc_list
->first
->next
== NULL
16766 && NOTE_P (loc_list
->first
->loc
)
16767 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
16768 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
16770 struct var_loc_node
*node
;
16772 node
= loc_list
->first
;
16773 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
16774 if (GET_CODE (rtl
) == EXPR_LIST
)
16775 rtl
= XEXP (rtl
, 0);
16776 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
16777 && add_const_value_attribute (die
, rtl
))
16780 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
16783 add_AT_location_description (die
, attr
, list
);
16786 /* None of that worked, so it must not really have a location;
16787 try adding a constant value attribute from the DECL_INITIAL. */
16788 return tree_add_const_value_attribute_for_decl (die
, decl
);
16791 /* Add VARIABLE and DIE into deferred locations list. */
16794 defer_location (tree variable
, dw_die_ref die
)
16796 deferred_locations entry
;
16797 entry
.variable
= variable
;
16799 VEC_safe_push (deferred_locations
, gc
, deferred_locations_list
, &entry
);
16802 /* Helper function for tree_add_const_value_attribute. Natively encode
16803 initializer INIT into an array. Return true if successful. */
16806 native_encode_initializer (tree init
, unsigned char *array
, int size
)
16810 if (init
== NULL_TREE
)
16814 switch (TREE_CODE (init
))
16817 type
= TREE_TYPE (init
);
16818 if (TREE_CODE (type
) == ARRAY_TYPE
)
16820 tree enttype
= TREE_TYPE (type
);
16821 enum machine_mode mode
= TYPE_MODE (enttype
);
16823 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
16825 if (int_size_in_bytes (type
) != size
)
16827 if (size
> TREE_STRING_LENGTH (init
))
16829 memcpy (array
, TREE_STRING_POINTER (init
),
16830 TREE_STRING_LENGTH (init
));
16831 memset (array
+ TREE_STRING_LENGTH (init
),
16832 '\0', size
- TREE_STRING_LENGTH (init
));
16835 memcpy (array
, TREE_STRING_POINTER (init
), size
);
16840 type
= TREE_TYPE (init
);
16841 if (int_size_in_bytes (type
) != size
)
16843 if (TREE_CODE (type
) == ARRAY_TYPE
)
16845 HOST_WIDE_INT min_index
;
16846 unsigned HOST_WIDE_INT cnt
;
16847 int curpos
= 0, fieldsize
;
16848 constructor_elt
*ce
;
16850 if (TYPE_DOMAIN (type
) == NULL_TREE
16851 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
16854 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
16855 if (fieldsize
<= 0)
16858 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
16859 memset (array
, '\0', size
);
16860 FOR_EACH_VEC_ELT (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
)
16862 tree val
= ce
->value
;
16863 tree index
= ce
->index
;
16865 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
16866 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
16869 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
16874 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
16877 curpos
= pos
+ fieldsize
;
16878 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
16880 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
16881 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
16885 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
16886 curpos
+= fieldsize
;
16889 gcc_assert (curpos
<= size
);
16893 else if (TREE_CODE (type
) == RECORD_TYPE
16894 || TREE_CODE (type
) == UNION_TYPE
)
16896 tree field
= NULL_TREE
;
16897 unsigned HOST_WIDE_INT cnt
;
16898 constructor_elt
*ce
;
16900 if (int_size_in_bytes (type
) != size
)
16903 if (TREE_CODE (type
) == RECORD_TYPE
)
16904 field
= TYPE_FIELDS (type
);
16906 FOR_EACH_VEC_ELT (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
)
16908 tree val
= ce
->value
;
16909 int pos
, fieldsize
;
16911 if (ce
->index
!= 0)
16917 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
16920 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
16921 && TYPE_DOMAIN (TREE_TYPE (field
))
16922 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
16924 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
16925 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
16927 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
16928 pos
= int_byte_position (field
);
16929 gcc_assert (pos
+ fieldsize
<= size
);
16931 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
16937 case VIEW_CONVERT_EXPR
:
16938 case NON_LVALUE_EXPR
:
16939 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
16941 return native_encode_expr (init
, array
, size
) == size
;
16945 /* Attach a DW_AT_const_value attribute to DIE. The value of the
16946 attribute is the const value T. */
16949 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
16952 tree type
= TREE_TYPE (t
);
16955 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
16959 gcc_assert (!DECL_P (init
));
16961 rtl
= rtl_for_decl_init (init
, type
);
16963 return add_const_value_attribute (die
, rtl
);
16964 /* If the host and target are sane, try harder. */
16965 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
16966 && initializer_constant_valid_p (init
, type
))
16968 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
16969 if (size
> 0 && (int) size
== size
)
16971 unsigned char *array
= (unsigned char *)
16972 ggc_alloc_cleared_atomic (size
);
16974 if (native_encode_initializer (init
, array
, size
))
16976 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
16984 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
16985 attribute is the const value of T, where T is an integral constant
16986 variable with static storage duration
16987 (so it can't be a PARM_DECL or a RESULT_DECL). */
16990 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
16994 || (TREE_CODE (decl
) != VAR_DECL
16995 && TREE_CODE (decl
) != CONST_DECL
))
16998 if (TREE_READONLY (decl
)
16999 && ! TREE_THIS_VOLATILE (decl
)
17000 && DECL_INITIAL (decl
))
17005 /* Don't add DW_AT_const_value if abstract origin already has one. */
17006 if (get_AT (var_die
, DW_AT_const_value
))
17009 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
17012 /* Convert the CFI instructions for the current function into a
17013 location list. This is used for DW_AT_frame_base when we targeting
17014 a dwarf2 consumer that does not support the dwarf3
17015 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
17018 static dw_loc_list_ref
17019 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
17022 dw_loc_list_ref list
, *list_tail
;
17024 dw_cfa_location last_cfa
, next_cfa
;
17025 const char *start_label
, *last_label
, *section
;
17026 dw_cfa_location remember
;
17028 fde
= current_fde ();
17029 gcc_assert (fde
!= NULL
);
17031 section
= secname_for_decl (current_function_decl
);
17035 memset (&next_cfa
, 0, sizeof (next_cfa
));
17036 next_cfa
.reg
= INVALID_REGNUM
;
17037 remember
= next_cfa
;
17039 start_label
= fde
->dw_fde_begin
;
17041 /* ??? Bald assumption that the CIE opcode list does not contain
17042 advance opcodes. */
17043 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
17044 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
17046 last_cfa
= next_cfa
;
17047 last_label
= start_label
;
17049 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
17050 switch (cfi
->dw_cfi_opc
)
17052 case DW_CFA_set_loc
:
17053 case DW_CFA_advance_loc1
:
17054 case DW_CFA_advance_loc2
:
17055 case DW_CFA_advance_loc4
:
17056 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
17058 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
17059 start_label
, last_label
, section
);
17061 list_tail
= &(*list_tail
)->dw_loc_next
;
17062 last_cfa
= next_cfa
;
17063 start_label
= last_label
;
17065 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
17068 case DW_CFA_advance_loc
:
17069 /* The encoding is complex enough that we should never emit this. */
17070 gcc_unreachable ();
17073 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
17077 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
17079 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
17080 start_label
, last_label
, section
);
17081 list_tail
= &(*list_tail
)->dw_loc_next
;
17082 start_label
= last_label
;
17085 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
17086 start_label
, fde
->dw_fde_end
, section
);
17088 if (list
&& list
->dw_loc_next
)
17094 /* Compute a displacement from the "steady-state frame pointer" to the
17095 frame base (often the same as the CFA), and store it in
17096 frame_pointer_fb_offset. OFFSET is added to the displacement
17097 before the latter is negated. */
17100 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
17104 #ifdef FRAME_POINTER_CFA_OFFSET
17105 reg
= frame_pointer_rtx
;
17106 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
17108 reg
= arg_pointer_rtx
;
17109 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
17112 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
17113 if (GET_CODE (elim
) == PLUS
)
17115 offset
+= INTVAL (XEXP (elim
, 1));
17116 elim
= XEXP (elim
, 0);
17119 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
17120 && (elim
== hard_frame_pointer_rtx
17121 || elim
== stack_pointer_rtx
))
17122 || elim
== (frame_pointer_needed
17123 ? hard_frame_pointer_rtx
17124 : stack_pointer_rtx
));
17126 frame_pointer_fb_offset
= -offset
;
17129 /* Generate a DW_AT_name attribute given some string value to be included as
17130 the value of the attribute. */
17133 add_name_attribute (dw_die_ref die
, const char *name_string
)
17135 if (name_string
!= NULL
&& *name_string
!= 0)
17137 if (demangle_name_func
)
17138 name_string
= (*demangle_name_func
) (name_string
);
17140 add_AT_string (die
, DW_AT_name
, name_string
);
17144 /* Generate a DW_AT_comp_dir attribute for DIE. */
17147 add_comp_dir_attribute (dw_die_ref die
)
17149 const char *wd
= get_src_pwd ();
17155 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
17159 wdlen
= strlen (wd
);
17160 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
17162 wd1
[wdlen
] = DIR_SEPARATOR
;
17163 wd1
[wdlen
+ 1] = 0;
17167 add_AT_string (die
, DW_AT_comp_dir
, remap_debug_filename (wd
));
17170 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
17174 lower_bound_default (void)
17176 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
17181 case DW_LANG_C_plus_plus
:
17183 case DW_LANG_ObjC_plus_plus
:
17186 case DW_LANG_Fortran77
:
17187 case DW_LANG_Fortran90
:
17188 case DW_LANG_Fortran95
:
17192 case DW_LANG_Python
:
17193 return dwarf_version
>= 4 ? 0 : -1;
17194 case DW_LANG_Ada95
:
17195 case DW_LANG_Ada83
:
17196 case DW_LANG_Cobol74
:
17197 case DW_LANG_Cobol85
:
17198 case DW_LANG_Pascal83
:
17199 case DW_LANG_Modula2
:
17201 return dwarf_version
>= 4 ? 1 : -1;
17207 /* Given a tree node describing an array bound (either lower or upper) output
17208 a representation for that bound. */
17211 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
17213 switch (TREE_CODE (bound
))
17218 /* All fixed-bounds are represented by INTEGER_CST nodes. */
17221 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
17224 /* Use the default if possible. */
17225 if (bound_attr
== DW_AT_lower_bound
17226 && host_integerp (bound
, 0)
17227 && (dflt
= lower_bound_default ()) != -1
17228 && tree_low_cst (bound
, 0) == dflt
)
17231 /* Otherwise represent the bound as an unsigned value with the
17232 precision of its type. The precision and signedness of the
17233 type will be necessary to re-interpret it unambiguously. */
17234 else if (prec
< HOST_BITS_PER_WIDE_INT
)
17236 unsigned HOST_WIDE_INT mask
17237 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
17238 add_AT_unsigned (subrange_die
, bound_attr
,
17239 TREE_INT_CST_LOW (bound
) & mask
);
17241 else if (prec
== HOST_BITS_PER_WIDE_INT
17242 || TREE_INT_CST_HIGH (bound
) == 0)
17243 add_AT_unsigned (subrange_die
, bound_attr
,
17244 TREE_INT_CST_LOW (bound
));
17246 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
17247 TREE_INT_CST_LOW (bound
));
17252 case VIEW_CONVERT_EXPR
:
17253 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
17263 dw_die_ref decl_die
= lookup_decl_die (bound
);
17265 /* ??? Can this happen, or should the variable have been bound
17266 first? Probably it can, since I imagine that we try to create
17267 the types of parameters in the order in which they exist in
17268 the list, and won't have created a forward reference to a
17269 later parameter. */
17270 if (decl_die
!= NULL
)
17272 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
17280 /* Otherwise try to create a stack operation procedure to
17281 evaluate the value of the array bound. */
17283 dw_die_ref ctx
, decl_die
;
17284 dw_loc_list_ref list
;
17286 list
= loc_list_from_tree (bound
, 2);
17287 if (list
== NULL
|| single_element_loc_list_p (list
))
17289 /* If DW_AT_*bound is not a reference nor constant, it is
17290 a DWARF expression rather than location description.
17291 For that loc_list_from_tree (bound, 0) is needed.
17292 If that fails to give a single element list,
17293 fall back to outputting this as a reference anyway. */
17294 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
17295 if (list2
&& single_element_loc_list_p (list2
))
17297 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
17304 if (current_function_decl
== 0)
17305 ctx
= comp_unit_die ();
17307 ctx
= lookup_decl_die (current_function_decl
);
17309 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
17310 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
17311 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
17312 add_AT_location_description (decl_die
, DW_AT_location
, list
);
17313 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
17319 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
17320 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
17321 Note that the block of subscript information for an array type also
17322 includes information about the element type of the given array type. */
17325 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
17327 unsigned dimension_number
;
17329 dw_die_ref subrange_die
;
17331 for (dimension_number
= 0;
17332 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
17333 type
= TREE_TYPE (type
), dimension_number
++)
17335 tree domain
= TYPE_DOMAIN (type
);
17337 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
17340 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
17341 and (in GNU C only) variable bounds. Handle all three forms
17343 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
17346 /* We have an array type with specified bounds. */
17347 lower
= TYPE_MIN_VALUE (domain
);
17348 upper
= TYPE_MAX_VALUE (domain
);
17350 /* Define the index type. */
17351 if (TREE_TYPE (domain
))
17353 /* ??? This is probably an Ada unnamed subrange type. Ignore the
17354 TREE_TYPE field. We can't emit debug info for this
17355 because it is an unnamed integral type. */
17356 if (TREE_CODE (domain
) == INTEGER_TYPE
17357 && TYPE_NAME (domain
) == NULL_TREE
17358 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
17359 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
17362 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
17366 /* ??? If upper is NULL, the array has unspecified length,
17367 but it does have a lower bound. This happens with Fortran
17369 Since the debugger is definitely going to need to know N
17370 to produce useful results, go ahead and output the lower
17371 bound solo, and hope the debugger can cope. */
17373 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
17375 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
17378 /* Otherwise we have an array type with an unspecified length. The
17379 DWARF-2 spec does not say how to handle this; let's just leave out the
17385 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
17389 switch (TREE_CODE (tree_node
))
17394 case ENUMERAL_TYPE
:
17397 case QUAL_UNION_TYPE
:
17398 size
= int_size_in_bytes (tree_node
);
17401 /* For a data member of a struct or union, the DW_AT_byte_size is
17402 generally given as the number of bytes normally allocated for an
17403 object of the *declared* type of the member itself. This is true
17404 even for bit-fields. */
17405 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
17408 gcc_unreachable ();
17411 /* Note that `size' might be -1 when we get to this point. If it is, that
17412 indicates that the byte size of the entity in question is variable. We
17413 have no good way of expressing this fact in Dwarf at the present time,
17414 so just let the -1 pass on through. */
17415 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
17418 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17419 which specifies the distance in bits from the highest order bit of the
17420 "containing object" for the bit-field to the highest order bit of the
17423 For any given bit-field, the "containing object" is a hypothetical object
17424 (of some integral or enum type) within which the given bit-field lives. The
17425 type of this hypothetical "containing object" is always the same as the
17426 declared type of the individual bit-field itself. The determination of the
17427 exact location of the "containing object" for a bit-field is rather
17428 complicated. It's handled by the `field_byte_offset' function (above).
17430 Note that it is the size (in bytes) of the hypothetical "containing object"
17431 which will be given in the DW_AT_byte_size attribute for this bit-field.
17432 (See `byte_size_attribute' above). */
17435 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
17437 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
17438 tree type
= DECL_BIT_FIELD_TYPE (decl
);
17439 HOST_WIDE_INT bitpos_int
;
17440 HOST_WIDE_INT highest_order_object_bit_offset
;
17441 HOST_WIDE_INT highest_order_field_bit_offset
;
17442 HOST_WIDE_INT
unsigned bit_offset
;
17444 /* Must be a field and a bit field. */
17445 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
17447 /* We can't yet handle bit-fields whose offsets are variable, so if we
17448 encounter such things, just return without generating any attribute
17449 whatsoever. Likewise for variable or too large size. */
17450 if (! host_integerp (bit_position (decl
), 0)
17451 || ! host_integerp (DECL_SIZE (decl
), 1))
17454 bitpos_int
= int_bit_position (decl
);
17456 /* Note that the bit offset is always the distance (in bits) from the
17457 highest-order bit of the "containing object" to the highest-order bit of
17458 the bit-field itself. Since the "high-order end" of any object or field
17459 is different on big-endian and little-endian machines, the computation
17460 below must take account of these differences. */
17461 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
17462 highest_order_field_bit_offset
= bitpos_int
;
17464 if (! BYTES_BIG_ENDIAN
)
17466 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
17467 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
17471 = (! BYTES_BIG_ENDIAN
17472 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
17473 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
17475 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
17478 /* For a FIELD_DECL node which represents a bit field, output an attribute
17479 which specifies the length in bits of the given field. */
17482 add_bit_size_attribute (dw_die_ref die
, tree decl
)
17484 /* Must be a field and a bit field. */
17485 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
17486 && DECL_BIT_FIELD_TYPE (decl
));
17488 if (host_integerp (DECL_SIZE (decl
), 1))
17489 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
17492 /* If the compiled language is ANSI C, then add a 'prototyped'
17493 attribute, if arg types are given for the parameters of a function. */
17496 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
17498 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
17499 && TYPE_ARG_TYPES (func_type
) != NULL
)
17500 add_AT_flag (die
, DW_AT_prototyped
, 1);
17503 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17504 by looking in either the type declaration or object declaration
17507 static inline dw_die_ref
17508 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
17510 dw_die_ref origin_die
= NULL
;
17512 if (TREE_CODE (origin
) != FUNCTION_DECL
)
17514 /* We may have gotten separated from the block for the inlined
17515 function, if we're in an exception handler or some such; make
17516 sure that the abstract function has been written out.
17518 Doing this for nested functions is wrong, however; functions are
17519 distinct units, and our context might not even be inline. */
17523 fn
= TYPE_STUB_DECL (fn
);
17525 fn
= decl_function_context (fn
);
17527 dwarf2out_abstract_function (fn
);
17530 if (DECL_P (origin
))
17531 origin_die
= lookup_decl_die (origin
);
17532 else if (TYPE_P (origin
))
17533 origin_die
= lookup_type_die (origin
);
17535 /* XXX: Functions that are never lowered don't always have correct block
17536 trees (in the case of java, they simply have no block tree, in some other
17537 languages). For these functions, there is nothing we can really do to
17538 output correct debug info for inlined functions in all cases. Rather
17539 than die, we'll just produce deficient debug info now, in that we will
17540 have variables without a proper abstract origin. In the future, when all
17541 functions are lowered, we should re-add a gcc_assert (origin_die)
17545 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
17549 /* We do not currently support the pure_virtual attribute. */
17552 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
17554 if (DECL_VINDEX (func_decl
))
17556 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
17558 if (host_integerp (DECL_VINDEX (func_decl
), 0))
17559 add_AT_loc (die
, DW_AT_vtable_elem_location
,
17560 new_loc_descr (DW_OP_constu
,
17561 tree_low_cst (DECL_VINDEX (func_decl
), 0),
17564 /* GNU extension: Record what type this method came from originally. */
17565 if (debug_info_level
> DINFO_LEVEL_TERSE
17566 && DECL_CONTEXT (func_decl
))
17567 add_AT_die_ref (die
, DW_AT_containing_type
,
17568 lookup_type_die (DECL_CONTEXT (func_decl
)));
17572 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
17573 given decl. This used to be a vendor extension until after DWARF 4
17574 standardized it. */
17577 add_linkage_attr (dw_die_ref die
, tree decl
)
17579 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
17581 /* Mimic what assemble_name_raw does with a leading '*'. */
17582 if (name
[0] == '*')
17585 if (dwarf_version
>= 4)
17586 add_AT_string (die
, DW_AT_linkage_name
, name
);
17588 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
17591 /* Add source coordinate attributes for the given decl. */
17594 add_src_coords_attributes (dw_die_ref die
, tree decl
)
17596 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17598 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
17599 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
17602 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
17605 add_linkage_name (dw_die_ref die
, tree decl
)
17607 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
17608 && TREE_PUBLIC (decl
)
17609 && !DECL_ABSTRACT (decl
)
17610 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
17611 && die
->die_tag
!= DW_TAG_member
)
17613 /* Defer until we have an assembler name set. */
17614 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
17616 limbo_die_node
*asm_name
;
17618 asm_name
= ggc_alloc_cleared_limbo_die_node ();
17619 asm_name
->die
= die
;
17620 asm_name
->created_for
= decl
;
17621 asm_name
->next
= deferred_asm_name
;
17622 deferred_asm_name
= asm_name
;
17624 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
17625 add_linkage_attr (die
, decl
);
17629 /* Add a DW_AT_name attribute and source coordinate attribute for the
17630 given decl, but only if it actually has a name. */
17633 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
17637 decl_name
= DECL_NAME (decl
);
17638 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
17640 const char *name
= dwarf2_name (decl
, 0);
17642 add_name_attribute (die
, name
);
17643 if (! DECL_ARTIFICIAL (decl
))
17644 add_src_coords_attributes (die
, decl
);
17646 add_linkage_name (die
, decl
);
17649 #ifdef VMS_DEBUGGING_INFO
17650 /* Get the function's name, as described by its RTL. This may be different
17651 from the DECL_NAME name used in the source file. */
17652 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
17654 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
17655 XEXP (DECL_RTL (decl
), 0));
17656 VEC_safe_push (rtx
, gc
, used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
17658 #endif /* VMS_DEBUGGING_INFO */
17661 #ifdef VMS_DEBUGGING_INFO
17662 /* Output the debug main pointer die for VMS */
17665 dwarf2out_vms_debug_main_pointer (void)
17667 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
17670 /* Allocate the VMS debug main subprogram die. */
17671 die
= ggc_alloc_cleared_die_node ();
17672 die
->die_tag
= DW_TAG_subprogram
;
17673 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
17674 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
17675 current_function_funcdef_no
);
17676 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
17678 /* Make it the first child of comp_unit_die (). */
17679 die
->die_parent
= comp_unit_die ();
17680 if (comp_unit_die ()->die_child
)
17682 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
17683 comp_unit_die ()->die_child
->die_sib
= die
;
17687 die
->die_sib
= die
;
17688 comp_unit_die ()->die_child
= die
;
17691 #endif /* VMS_DEBUGGING_INFO */
17693 /* Push a new declaration scope. */
17696 push_decl_scope (tree scope
)
17698 VEC_safe_push (tree
, gc
, decl_scope_table
, scope
);
17701 /* Pop a declaration scope. */
17704 pop_decl_scope (void)
17706 VEC_pop (tree
, decl_scope_table
);
17709 /* Return the DIE for the scope that immediately contains this type.
17710 Non-named types get global scope. Named types nested in other
17711 types get their containing scope if it's open, or global scope
17712 otherwise. All other types (i.e. function-local named types) get
17713 the current active scope. */
17716 scope_die_for (tree t
, dw_die_ref context_die
)
17718 dw_die_ref scope_die
= NULL
;
17719 tree containing_scope
;
17722 /* Non-types always go in the current scope. */
17723 gcc_assert (TYPE_P (t
));
17725 containing_scope
= TYPE_CONTEXT (t
);
17727 /* Use the containing namespace if it was passed in (for a declaration). */
17728 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
17730 if (context_die
== lookup_decl_die (containing_scope
))
17733 containing_scope
= NULL_TREE
;
17736 /* Ignore function type "scopes" from the C frontend. They mean that
17737 a tagged type is local to a parmlist of a function declarator, but
17738 that isn't useful to DWARF. */
17739 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
17740 containing_scope
= NULL_TREE
;
17742 if (containing_scope
== NULL_TREE
)
17743 scope_die
= comp_unit_die ();
17744 else if (TYPE_P (containing_scope
))
17746 /* For types, we can just look up the appropriate DIE. But
17747 first we check to see if we're in the middle of emitting it
17748 so we know where the new DIE should go. */
17749 for (i
= VEC_length (tree
, decl_scope_table
) - 1; i
>= 0; --i
)
17750 if (VEC_index (tree
, decl_scope_table
, i
) == containing_scope
)
17755 gcc_assert (debug_info_level
<= DINFO_LEVEL_TERSE
17756 || TREE_ASM_WRITTEN (containing_scope
));
17757 /*We are not in the middle of emitting the type
17758 CONTAINING_SCOPE. Let's see if it's emitted already. */
17759 scope_die
= lookup_type_die (containing_scope
);
17761 /* If none of the current dies are suitable, we get file scope. */
17762 if (scope_die
== NULL
)
17763 scope_die
= comp_unit_die ();
17766 scope_die
= lookup_type_die (containing_scope
);
17769 scope_die
= context_die
;
17774 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
17777 local_scope_p (dw_die_ref context_die
)
17779 for (; context_die
; context_die
= context_die
->die_parent
)
17780 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
17781 || context_die
->die_tag
== DW_TAG_subprogram
)
17787 /* Returns nonzero if CONTEXT_DIE is a class. */
17790 class_scope_p (dw_die_ref context_die
)
17792 return (context_die
17793 && (context_die
->die_tag
== DW_TAG_structure_type
17794 || context_die
->die_tag
== DW_TAG_class_type
17795 || context_die
->die_tag
== DW_TAG_interface_type
17796 || context_die
->die_tag
== DW_TAG_union_type
));
17799 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
17800 whether or not to treat a DIE in this context as a declaration. */
17803 class_or_namespace_scope_p (dw_die_ref context_die
)
17805 return (class_scope_p (context_die
)
17806 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
17809 /* Many forms of DIEs require a "type description" attribute. This
17810 routine locates the proper "type descriptor" die for the type given
17811 by 'type', and adds a DW_AT_type attribute below the given die. */
17814 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
17815 int decl_volatile
, dw_die_ref context_die
)
17817 enum tree_code code
= TREE_CODE (type
);
17818 dw_die_ref type_die
= NULL
;
17820 /* ??? If this type is an unnamed subrange type of an integral, floating-point
17821 or fixed-point type, use the inner type. This is because we have no
17822 support for unnamed types in base_type_die. This can happen if this is
17823 an Ada subrange type. Correct solution is emit a subrange type die. */
17824 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
17825 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
17826 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
17828 if (code
== ERROR_MARK
17829 /* Handle a special case. For functions whose return type is void, we
17830 generate *no* type attribute. (Note that no object may have type
17831 `void', so this only applies to function return types). */
17832 || code
== VOID_TYPE
)
17835 type_die
= modified_type_die (type
,
17836 decl_const
|| TYPE_READONLY (type
),
17837 decl_volatile
|| TYPE_VOLATILE (type
),
17840 if (type_die
!= NULL
)
17841 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
17844 /* Given an object die, add the calling convention attribute for the
17845 function call type. */
17847 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
17849 enum dwarf_calling_convention value
= DW_CC_normal
;
17851 value
= ((enum dwarf_calling_convention
)
17852 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
17855 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
17857 /* DWARF 2 doesn't provide a way to identify a program's source-level
17858 entry point. DW_AT_calling_convention attributes are only meant
17859 to describe functions' calling conventions. However, lacking a
17860 better way to signal the Fortran main program, we used this for
17861 a long time, following existing custom. Now, DWARF 4 has
17862 DW_AT_main_subprogram, which we add below, but some tools still
17863 rely on the old way, which we thus keep. */
17864 value
= DW_CC_program
;
17866 if (dwarf_version
>= 4 || !dwarf_strict
)
17867 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
17870 /* Only add the attribute if the backend requests it, and
17871 is not DW_CC_normal. */
17872 if (value
&& (value
!= DW_CC_normal
))
17873 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
17876 /* Given a tree pointer to a struct, class, union, or enum type node, return
17877 a pointer to the (string) tag name for the given type, or zero if the type
17878 was declared without a tag. */
17880 static const char *
17881 type_tag (const_tree type
)
17883 const char *name
= 0;
17885 if (TYPE_NAME (type
) != 0)
17889 /* Find the IDENTIFIER_NODE for the type name. */
17890 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
17891 && !TYPE_NAMELESS (type
))
17892 t
= TYPE_NAME (type
);
17894 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
17895 a TYPE_DECL node, regardless of whether or not a `typedef' was
17897 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
17898 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
17900 /* We want to be extra verbose. Don't call dwarf_name if
17901 DECL_NAME isn't set. The default hook for decl_printable_name
17902 doesn't like that, and in this context it's correct to return
17903 0, instead of "<anonymous>" or the like. */
17904 if (DECL_NAME (TYPE_NAME (type
))
17905 && !DECL_NAMELESS (TYPE_NAME (type
)))
17906 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
17909 /* Now get the name as a string, or invent one. */
17910 if (!name
&& t
!= 0)
17911 name
= IDENTIFIER_POINTER (t
);
17914 return (name
== 0 || *name
== '\0') ? 0 : name
;
17917 /* Return the type associated with a data member, make a special check
17918 for bit field types. */
17921 member_declared_type (const_tree member
)
17923 return (DECL_BIT_FIELD_TYPE (member
)
17924 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
17927 /* Get the decl's label, as described by its RTL. This may be different
17928 from the DECL_NAME name used in the source file. */
17931 static const char *
17932 decl_start_label (tree decl
)
17935 const char *fnname
;
17937 x
= DECL_RTL (decl
);
17938 gcc_assert (MEM_P (x
));
17941 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
17943 fnname
= XSTR (x
, 0);
17948 /* These routines generate the internal representation of the DIE's for
17949 the compilation unit. Debugging information is collected by walking
17950 the declaration trees passed in from dwarf2out_decl(). */
17953 gen_array_type_die (tree type
, dw_die_ref context_die
)
17955 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17956 dw_die_ref array_die
;
17958 /* GNU compilers represent multidimensional array types as sequences of one
17959 dimensional array types whose element types are themselves array types.
17960 We sometimes squish that down to a single array_type DIE with multiple
17961 subscripts in the Dwarf debugging info. The draft Dwarf specification
17962 say that we are allowed to do this kind of compression in C, because
17963 there is no difference between an array of arrays and a multidimensional
17964 array. We don't do this for Ada to remain as close as possible to the
17965 actual representation, which is especially important against the language
17966 flexibilty wrt arrays of variable size. */
17968 bool collapse_nested_arrays
= !is_ada ();
17971 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
17972 DW_TAG_string_type doesn't have DW_AT_type attribute). */
17973 if (TYPE_STRING_FLAG (type
)
17974 && TREE_CODE (type
) == ARRAY_TYPE
17976 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
17978 HOST_WIDE_INT size
;
17980 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
17981 add_name_attribute (array_die
, type_tag (type
));
17982 equate_type_number_to_die (type
, array_die
);
17983 size
= int_size_in_bytes (type
);
17985 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17986 else if (TYPE_DOMAIN (type
) != NULL_TREE
17987 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
17988 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
17990 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
17991 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
17993 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
17994 if (loc
&& size
> 0)
17996 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
17997 if (size
!= DWARF2_ADDR_SIZE
)
17998 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
18004 /* ??? The SGI dwarf reader fails for array of array of enum types
18005 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
18006 array type comes before the outer array type. We thus call gen_type_die
18007 before we new_die and must prevent nested array types collapsing for this
18010 #ifdef MIPS_DEBUGGING_INFO
18011 gen_type_die (TREE_TYPE (type
), context_die
);
18012 collapse_nested_arrays
= false;
18015 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
18016 add_name_attribute (array_die
, type_tag (type
));
18017 equate_type_number_to_die (type
, array_die
);
18019 if (TREE_CODE (type
) == VECTOR_TYPE
)
18020 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
18022 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18024 && TREE_CODE (type
) == ARRAY_TYPE
18025 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
18026 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
18027 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
18030 /* We default the array ordering. SDB will probably do
18031 the right things even if DW_AT_ordering is not present. It's not even
18032 an issue until we start to get into multidimensional arrays anyway. If
18033 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
18034 then we'll have to put the DW_AT_ordering attribute back in. (But if
18035 and when we find out that we need to put these in, we will only do so
18036 for multidimensional arrays. */
18037 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
18040 #ifdef MIPS_DEBUGGING_INFO
18041 /* The SGI compilers handle arrays of unknown bound by setting
18042 AT_declaration and not emitting any subrange DIEs. */
18043 if (TREE_CODE (type
) == ARRAY_TYPE
18044 && ! TYPE_DOMAIN (type
))
18045 add_AT_flag (array_die
, DW_AT_declaration
, 1);
18048 if (TREE_CODE (type
) == VECTOR_TYPE
)
18050 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
18051 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
18052 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
18053 add_bound_info (subrange_die
, DW_AT_upper_bound
,
18054 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
18057 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
18059 /* Add representation of the type of the elements of this array type and
18060 emit the corresponding DIE if we haven't done it already. */
18061 element_type
= TREE_TYPE (type
);
18062 if (collapse_nested_arrays
)
18063 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
18065 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
18067 element_type
= TREE_TYPE (element_type
);
18070 #ifndef MIPS_DEBUGGING_INFO
18071 gen_type_die (element_type
, context_die
);
18074 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
18076 if (get_AT (array_die
, DW_AT_name
))
18077 add_pubtype (type
, array_die
);
18080 static dw_loc_descr_ref
18081 descr_info_loc (tree val
, tree base_decl
)
18083 HOST_WIDE_INT size
;
18084 dw_loc_descr_ref loc
, loc2
;
18085 enum dwarf_location_atom op
;
18087 if (val
== base_decl
)
18088 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
18090 switch (TREE_CODE (val
))
18093 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
18095 return loc_descriptor_from_tree (val
, 0);
18097 if (host_integerp (val
, 0))
18098 return int_loc_descriptor (tree_low_cst (val
, 0));
18101 size
= int_size_in_bytes (TREE_TYPE (val
));
18104 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
18107 if (size
== DWARF2_ADDR_SIZE
)
18108 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
18110 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
18112 case POINTER_PLUS_EXPR
:
18114 if (host_integerp (TREE_OPERAND (val
, 1), 1)
18115 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
18118 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
18121 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
18127 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
18130 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
18133 add_loc_descr (&loc
, loc2
);
18134 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
18156 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
18157 tree val
, tree base_decl
)
18159 dw_loc_descr_ref loc
;
18161 if (host_integerp (val
, 0))
18163 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
18167 loc
= descr_info_loc (val
, base_decl
);
18171 add_AT_loc (die
, attr
, loc
);
18174 /* This routine generates DIE for array with hidden descriptor, details
18175 are filled into *info by a langhook. */
18178 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
18179 dw_die_ref context_die
)
18181 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
18182 dw_die_ref array_die
;
18185 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
18186 add_name_attribute (array_die
, type_tag (type
));
18187 equate_type_number_to_die (type
, array_die
);
18189 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18191 && info
->ndimensions
>= 2)
18192 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
18194 if (info
->data_location
)
18195 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
18197 if (info
->associated
)
18198 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
18200 if (info
->allocated
)
18201 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
18204 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
18206 dw_die_ref subrange_die
18207 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
18209 if (info
->dimen
[dim
].lower_bound
)
18211 /* If it is the default value, omit it. */
18214 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
18215 && (dflt
= lower_bound_default ()) != -1
18216 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
18219 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
18220 info
->dimen
[dim
].lower_bound
,
18223 if (info
->dimen
[dim
].upper_bound
)
18224 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
18225 info
->dimen
[dim
].upper_bound
,
18227 if (info
->dimen
[dim
].stride
)
18228 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
18229 info
->dimen
[dim
].stride
,
18233 gen_type_die (info
->element_type
, context_die
);
18234 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
18236 if (get_AT (array_die
, DW_AT_name
))
18237 add_pubtype (type
, array_die
);
18242 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
18244 tree origin
= decl_ultimate_origin (decl
);
18245 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
18247 if (origin
!= NULL
)
18248 add_abstract_origin_attribute (decl_die
, origin
);
18251 add_name_and_src_coords_attributes (decl_die
, decl
);
18252 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
18253 0, 0, context_die
);
18256 if (DECL_ABSTRACT (decl
))
18257 equate_decl_number_to_die (decl
, decl_die
);
18259 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
18263 /* Walk through the list of incomplete types again, trying once more to
18264 emit full debugging info for them. */
18267 retry_incomplete_types (void)
18271 for (i
= VEC_length (tree
, incomplete_types
) - 1; i
>= 0; i
--)
18272 if (should_emit_struct_debug (VEC_index (tree
, incomplete_types
, i
),
18273 DINFO_USAGE_DIR_USE
))
18274 gen_type_die (VEC_index (tree
, incomplete_types
, i
), comp_unit_die ());
18277 /* Determine what tag to use for a record type. */
18279 static enum dwarf_tag
18280 record_type_tag (tree type
)
18282 if (! lang_hooks
.types
.classify_record
)
18283 return DW_TAG_structure_type
;
18285 switch (lang_hooks
.types
.classify_record (type
))
18287 case RECORD_IS_STRUCT
:
18288 return DW_TAG_structure_type
;
18290 case RECORD_IS_CLASS
:
18291 return DW_TAG_class_type
;
18293 case RECORD_IS_INTERFACE
:
18294 if (dwarf_version
>= 3 || !dwarf_strict
)
18295 return DW_TAG_interface_type
;
18296 return DW_TAG_structure_type
;
18299 gcc_unreachable ();
18303 /* Generate a DIE to represent an enumeration type. Note that these DIEs
18304 include all of the information about the enumeration values also. Each
18305 enumerated type name/value is listed as a child of the enumerated type
18309 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
18311 dw_die_ref type_die
= lookup_type_die (type
);
18313 if (type_die
== NULL
)
18315 type_die
= new_die (DW_TAG_enumeration_type
,
18316 scope_die_for (type
, context_die
), type
);
18317 equate_type_number_to_die (type
, type_die
);
18318 add_name_attribute (type_die
, type_tag (type
));
18319 if (dwarf_version
>= 4 || !dwarf_strict
)
18321 if (ENUM_IS_SCOPED (type
))
18322 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
18323 if (ENUM_IS_OPAQUE (type
))
18324 add_AT_flag (type_die
, DW_AT_declaration
, 1);
18327 else if (! TYPE_SIZE (type
))
18330 remove_AT (type_die
, DW_AT_declaration
);
18332 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
18333 given enum type is incomplete, do not generate the DW_AT_byte_size
18334 attribute or the DW_AT_element_list attribute. */
18335 if (TYPE_SIZE (type
))
18339 TREE_ASM_WRITTEN (type
) = 1;
18340 add_byte_size_attribute (type_die
, type
);
18341 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
18343 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
18344 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
18347 /* If the first reference to this type was as the return type of an
18348 inline function, then it may not have a parent. Fix this now. */
18349 if (type_die
->die_parent
== NULL
)
18350 add_child_die (scope_die_for (type
, context_die
), type_die
);
18352 for (link
= TYPE_VALUES (type
);
18353 link
!= NULL
; link
= TREE_CHAIN (link
))
18355 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
18356 tree value
= TREE_VALUE (link
);
18358 add_name_attribute (enum_die
,
18359 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
18361 if (TREE_CODE (value
) == CONST_DECL
)
18362 value
= DECL_INITIAL (value
);
18364 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
18365 /* DWARF2 does not provide a way of indicating whether or
18366 not enumeration constants are signed or unsigned. GDB
18367 always assumes the values are signed, so we output all
18368 values as if they were signed. That means that
18369 enumeration constants with very large unsigned values
18370 will appear to have negative values in the debugger. */
18371 add_AT_int (enum_die
, DW_AT_const_value
,
18372 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
18376 add_AT_flag (type_die
, DW_AT_declaration
, 1);
18378 if (get_AT (type_die
, DW_AT_name
))
18379 add_pubtype (type
, type_die
);
18384 /* Generate a DIE to represent either a real live formal parameter decl or to
18385 represent just the type of some formal parameter position in some function
18388 Note that this routine is a bit unusual because its argument may be a
18389 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
18390 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
18391 node. If it's the former then this function is being called to output a
18392 DIE to represent a formal parameter object (or some inlining thereof). If
18393 it's the latter, then this function is only being called to output a
18394 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
18395 argument type of some subprogram type.
18396 If EMIT_NAME_P is true, name and source coordinate attributes
18400 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
18401 dw_die_ref context_die
)
18403 tree node_or_origin
= node
? node
: origin
;
18404 tree ultimate_origin
;
18405 dw_die_ref parm_die
18406 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
18408 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
18410 case tcc_declaration
:
18411 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
18412 if (node
|| ultimate_origin
)
18413 origin
= ultimate_origin
;
18414 if (origin
!= NULL
)
18415 add_abstract_origin_attribute (parm_die
, origin
);
18416 else if (emit_name_p
)
18417 add_name_and_src_coords_attributes (parm_die
, node
);
18419 || (! DECL_ABSTRACT (node_or_origin
)
18420 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
18421 decl_function_context
18422 (node_or_origin
))))
18424 tree type
= TREE_TYPE (node_or_origin
);
18425 if (decl_by_reference_p (node_or_origin
))
18426 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
18429 add_type_attribute (parm_die
, type
,
18430 TREE_READONLY (node_or_origin
),
18431 TREE_THIS_VOLATILE (node_or_origin
),
18434 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
18435 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18437 if (node
&& node
!= origin
)
18438 equate_decl_number_to_die (node
, parm_die
);
18439 if (! DECL_ABSTRACT (node_or_origin
))
18440 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
18446 /* We were called with some kind of a ..._TYPE node. */
18447 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
18451 gcc_unreachable ();
18457 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18458 children DW_TAG_formal_parameter DIEs representing the arguments of the
18461 PARM_PACK must be a function parameter pack.
18462 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18463 must point to the subsequent arguments of the function PACK_ARG belongs to.
18464 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18465 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18466 following the last one for which a DIE was generated. */
18469 gen_formal_parameter_pack_die (tree parm_pack
,
18471 dw_die_ref subr_die
,
18475 dw_die_ref parm_pack_die
;
18477 gcc_assert (parm_pack
18478 && lang_hooks
.function_parameter_pack_p (parm_pack
)
18481 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
18482 add_src_coords_attributes (parm_pack_die
, parm_pack
);
18484 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
18486 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
18489 gen_formal_parameter_die (arg
, NULL
,
18490 false /* Don't emit name attribute. */,
18495 return parm_pack_die
;
18498 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18499 at the end of an (ANSI prototyped) formal parameters list. */
18502 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
18504 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
18507 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18508 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18509 parameters as specified in some function type specification (except for
18510 those which appear as part of a function *definition*). */
18513 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
18516 tree formal_type
= NULL
;
18517 tree first_parm_type
;
18520 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
18522 arg
= DECL_ARGUMENTS (function_or_method_type
);
18523 function_or_method_type
= TREE_TYPE (function_or_method_type
);
18528 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
18530 /* Make our first pass over the list of formal parameter types and output a
18531 DW_TAG_formal_parameter DIE for each one. */
18532 for (link
= first_parm_type
; link
; )
18534 dw_die_ref parm_die
;
18536 formal_type
= TREE_VALUE (link
);
18537 if (formal_type
== void_type_node
)
18540 /* Output a (nameless) DIE to represent the formal parameter itself. */
18541 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
18542 true /* Emit name attribute. */,
18544 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
18545 && link
== first_parm_type
)
18547 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18548 if (dwarf_version
>= 3 || !dwarf_strict
)
18549 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
18551 else if (arg
&& DECL_ARTIFICIAL (arg
))
18552 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18554 link
= TREE_CHAIN (link
);
18556 arg
= DECL_CHAIN (arg
);
18559 /* If this function type has an ellipsis, add a
18560 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18561 if (formal_type
!= void_type_node
)
18562 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
18564 /* Make our second (and final) pass over the list of formal parameter types
18565 and output DIEs to represent those types (as necessary). */
18566 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
18567 link
&& TREE_VALUE (link
);
18568 link
= TREE_CHAIN (link
))
18569 gen_type_die (TREE_VALUE (link
), context_die
);
18572 /* We want to generate the DIE for TYPE so that we can generate the
18573 die for MEMBER, which has been defined; we will need to refer back
18574 to the member declaration nested within TYPE. If we're trying to
18575 generate minimal debug info for TYPE, processing TYPE won't do the
18576 trick; we need to attach the member declaration by hand. */
18579 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
18581 gen_type_die (type
, context_die
);
18583 /* If we're trying to avoid duplicate debug info, we may not have
18584 emitted the member decl for this function. Emit it now. */
18585 if (TYPE_STUB_DECL (type
)
18586 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
18587 && ! lookup_decl_die (member
))
18589 dw_die_ref type_die
;
18590 gcc_assert (!decl_ultimate_origin (member
));
18592 push_decl_scope (type
);
18593 type_die
= lookup_type_die (type
);
18594 if (TREE_CODE (member
) == FUNCTION_DECL
)
18595 gen_subprogram_die (member
, type_die
);
18596 else if (TREE_CODE (member
) == FIELD_DECL
)
18598 /* Ignore the nameless fields that are used to skip bits but handle
18599 C++ anonymous unions and structs. */
18600 if (DECL_NAME (member
) != NULL_TREE
18601 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
18602 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
18604 gen_type_die (member_declared_type (member
), type_die
);
18605 gen_field_die (member
, type_die
);
18609 gen_variable_die (member
, NULL_TREE
, type_die
);
18615 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18616 may later generate inlined and/or out-of-line instances of. */
18619 dwarf2out_abstract_function (tree decl
)
18621 dw_die_ref old_die
;
18625 htab_t old_decl_loc_table
;
18627 /* Make sure we have the actual abstract inline, not a clone. */
18628 decl
= DECL_ORIGIN (decl
);
18630 old_die
= lookup_decl_die (decl
);
18631 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
18632 /* We've already generated the abstract instance. */
18635 /* We can be called while recursively when seeing block defining inlined subroutine
18636 DIE. Be sure to not clobber the outer location table nor use it or we would
18637 get locations in abstract instantces. */
18638 old_decl_loc_table
= decl_loc_table
;
18639 decl_loc_table
= NULL
;
18641 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18642 we don't get confused by DECL_ABSTRACT. */
18643 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18645 context
= decl_class_context (decl
);
18647 gen_type_die_for_member
18648 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
18651 /* Pretend we've just finished compiling this function. */
18652 save_fn
= current_function_decl
;
18653 current_function_decl
= decl
;
18654 push_cfun (DECL_STRUCT_FUNCTION (decl
));
18656 was_abstract
= DECL_ABSTRACT (decl
);
18657 set_decl_abstract_flags (decl
, 1);
18658 dwarf2out_decl (decl
);
18659 if (! was_abstract
)
18660 set_decl_abstract_flags (decl
, 0);
18662 current_function_decl
= save_fn
;
18663 decl_loc_table
= old_decl_loc_table
;
18667 /* Helper function of premark_used_types() which gets called through
18670 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18671 marked as unused by prune_unused_types. */
18674 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
18679 type
= (tree
) *slot
;
18680 die
= lookup_type_die (type
);
18682 die
->die_perennial_p
= 1;
18686 /* Helper function of premark_types_used_by_global_vars which gets called
18687 through htab_traverse.
18689 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18690 marked as unused by prune_unused_types. The DIE of the type is marked
18691 only if the global variable using the type will actually be emitted. */
18694 premark_types_used_by_global_vars_helper (void **slot
,
18695 void *data ATTRIBUTE_UNUSED
)
18697 struct types_used_by_vars_entry
*entry
;
18700 entry
= (struct types_used_by_vars_entry
*) *slot
;
18701 gcc_assert (entry
->type
!= NULL
18702 && entry
->var_decl
!= NULL
);
18703 die
= lookup_type_die (entry
->type
);
18706 /* Ask cgraph if the global variable really is to be emitted.
18707 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18708 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
18709 if (node
&& node
->needed
)
18711 die
->die_perennial_p
= 1;
18712 /* Keep the parent DIEs as well. */
18713 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
18714 die
->die_perennial_p
= 1;
18720 /* Mark all members of used_types_hash as perennial. */
18723 premark_used_types (void)
18725 if (cfun
&& cfun
->used_types_hash
)
18726 htab_traverse (cfun
->used_types_hash
, premark_used_types_helper
, NULL
);
18729 /* Mark all members of types_used_by_vars_entry as perennial. */
18732 premark_types_used_by_global_vars (void)
18734 if (types_used_by_vars_hash
)
18735 htab_traverse (types_used_by_vars_hash
,
18736 premark_types_used_by_global_vars_helper
, NULL
);
18739 /* Generate a DIE to represent a declared function (either file-scope or
18743 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
18745 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
18746 tree origin
= decl_ultimate_origin (decl
);
18747 dw_die_ref subr_die
;
18750 dw_die_ref old_die
= lookup_decl_die (decl
);
18751 int declaration
= (current_function_decl
!= decl
18752 || class_or_namespace_scope_p (context_die
));
18754 premark_used_types ();
18756 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
18757 started to generate the abstract instance of an inline, decided to output
18758 its containing class, and proceeded to emit the declaration of the inline
18759 from the member list for the class. If so, DECLARATION takes priority;
18760 we'll get back to the abstract instance when done with the class. */
18762 /* The class-scope declaration DIE must be the primary DIE. */
18763 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
18766 gcc_assert (!old_die
);
18769 /* Now that the C++ front end lazily declares artificial member fns, we
18770 might need to retrofit the declaration into its class. */
18771 if (!declaration
&& !origin
&& !old_die
18772 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
18773 && !class_or_namespace_scope_p (context_die
)
18774 && debug_info_level
> DINFO_LEVEL_TERSE
)
18775 old_die
= force_decl_die (decl
);
18777 if (origin
!= NULL
)
18779 gcc_assert (!declaration
|| local_scope_p (context_die
));
18781 /* Fixup die_parent for the abstract instance of a nested
18782 inline function. */
18783 if (old_die
&& old_die
->die_parent
== NULL
)
18784 add_child_die (context_die
, old_die
);
18786 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18787 add_abstract_origin_attribute (subr_die
, origin
);
18791 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18792 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18794 if (!get_AT_flag (old_die
, DW_AT_declaration
)
18795 /* We can have a normal definition following an inline one in the
18796 case of redefinition of GNU C extern inlines.
18797 It seems reasonable to use AT_specification in this case. */
18798 && !get_AT (old_die
, DW_AT_inline
))
18800 /* Detect and ignore this case, where we are trying to output
18801 something we have already output. */
18805 /* If the definition comes from the same place as the declaration,
18806 maybe use the old DIE. We always want the DIE for this function
18807 that has the *_pc attributes to be under comp_unit_die so the
18808 debugger can find it. We also need to do this for abstract
18809 instances of inlines, since the spec requires the out-of-line copy
18810 to have the same parent. For local class methods, this doesn't
18811 apply; we just use the old DIE. */
18812 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
18813 && (DECL_ARTIFICIAL (decl
)
18814 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
18815 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
18816 == (unsigned) s
.line
))))
18818 subr_die
= old_die
;
18820 /* Clear out the declaration attribute and the formal parameters.
18821 Do not remove all children, because it is possible that this
18822 declaration die was forced using force_decl_die(). In such
18823 cases die that forced declaration die (e.g. TAG_imported_module)
18824 is one of the children that we do not want to remove. */
18825 remove_AT (subr_die
, DW_AT_declaration
);
18826 remove_AT (subr_die
, DW_AT_object_pointer
);
18827 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
18831 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18832 add_AT_specification (subr_die
, old_die
);
18833 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18834 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
18835 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18836 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
18841 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18843 if (TREE_PUBLIC (decl
))
18844 add_AT_flag (subr_die
, DW_AT_external
, 1);
18846 add_name_and_src_coords_attributes (subr_die
, decl
);
18847 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18849 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
18850 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18851 0, 0, context_die
);
18854 add_pure_or_virtual_attribute (subr_die
, decl
);
18855 if (DECL_ARTIFICIAL (decl
))
18856 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18858 add_accessibility_attribute (subr_die
, decl
);
18863 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18865 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
18867 /* If this is an explicit function declaration then generate
18868 a DW_AT_explicit attribute. */
18869 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
18870 && (dwarf_version
>= 3 || !dwarf_strict
))
18871 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
18873 /* The first time we see a member function, it is in the context of
18874 the class to which it belongs. We make sure of this by emitting
18875 the class first. The next time is the definition, which is
18876 handled above. The two may come from the same source text.
18878 Note that force_decl_die() forces function declaration die. It is
18879 later reused to represent definition. */
18880 equate_decl_number_to_die (decl
, subr_die
);
18883 else if (DECL_ABSTRACT (decl
))
18885 if (DECL_DECLARED_INLINE_P (decl
))
18887 if (cgraph_function_possibly_inlined_p (decl
))
18888 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
18890 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
18894 if (cgraph_function_possibly_inlined_p (decl
))
18895 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
18897 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
18900 if (DECL_DECLARED_INLINE_P (decl
)
18901 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
18902 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18904 equate_decl_number_to_die (decl
, subr_die
);
18906 else if (!DECL_EXTERNAL (decl
))
18908 HOST_WIDE_INT cfa_fb_offset
;
18910 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18911 equate_decl_number_to_die (decl
, subr_die
);
18913 if (!flag_reorder_blocks_and_partition
)
18915 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
18916 current_function_funcdef_no
);
18917 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
18918 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
18919 current_function_funcdef_no
);
18920 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
18922 #if VMS_DEBUGGING_INFO
18923 /* HP OpenVMS Industry Standard 64: DWARF Extensions
18924 Section 2.3 Prologue and Epilogue Attributes:
18925 When a breakpoint is set on entry to a function, it is generally
18926 desirable for execution to be suspended, not on the very first
18927 instruction of the function, but rather at a point after the
18928 function's frame has been set up, after any language defined local
18929 declaration processing has been completed, and before execution of
18930 the first statement of the function begins. Debuggers generally
18931 cannot properly determine where this point is. Similarly for a
18932 breakpoint set on exit from a function. The prologue and epilogue
18933 attributes allow a compiler to communicate the location(s) to use. */
18936 dw_fde_ref fde
= &fde_table
[current_funcdef_fde
];
18938 if (fde
->dw_fde_vms_end_prologue
)
18939 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
18940 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
18942 if (fde
->dw_fde_vms_begin_epilogue
)
18943 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
18944 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
18948 add_pubname (decl
, subr_die
);
18949 add_arange (decl
, subr_die
);
18952 { /* Do nothing for now; maybe need to duplicate die, one for
18953 hot section and one for cold section, then use the hot/cold
18954 section begin/end labels to generate the aranges... */
18956 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
18957 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
18958 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
18959 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
18961 add_pubname (decl, subr_die);
18962 add_arange (decl, subr_die);
18963 add_arange (decl, subr_die);
18967 #ifdef MIPS_DEBUGGING_INFO
18968 /* Add a reference to the FDE for this routine. */
18969 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
18972 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
18974 /* We define the "frame base" as the function's CFA. This is more
18975 convenient for several reasons: (1) It's stable across the prologue
18976 and epilogue, which makes it better than just a frame pointer,
18977 (2) With dwarf3, there exists a one-byte encoding that allows us
18978 to reference the .debug_frame data by proxy, but failing that,
18979 (3) We can at least reuse the code inspection and interpretation
18980 code that determines the CFA position at various points in the
18982 if (dwarf_version
>= 3)
18984 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
18985 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
18989 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
18990 if (list
->dw_loc_next
)
18991 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
18993 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
18996 /* Compute a displacement from the "steady-state frame pointer" to
18997 the CFA. The former is what all stack slots and argument slots
18998 will reference in the rtl; the later is what we've told the
18999 debugger about. We'll need to adjust all frame_base references
19000 by this displacement. */
19001 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
19003 if (cfun
->static_chain_decl
)
19004 add_AT_location_description (subr_die
, DW_AT_static_link
,
19005 loc_list_from_tree (cfun
->static_chain_decl
, 2));
19008 /* Generate child dies for template paramaters. */
19009 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19010 gen_generic_params_dies (decl
);
19012 /* Now output descriptions of the arguments for this function. This gets
19013 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
19014 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
19015 `...' at the end of the formal parameter list. In order to find out if
19016 there was a trailing ellipsis or not, we must instead look at the type
19017 associated with the FUNCTION_DECL. This will be a node of type
19018 FUNCTION_TYPE. If the chain of type nodes hanging off of this
19019 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
19020 an ellipsis at the end. */
19022 /* In the case where we are describing a mere function declaration, all we
19023 need to do here (and all we *can* do here) is to describe the *types* of
19024 its formal parameters. */
19025 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19027 else if (declaration
)
19028 gen_formal_types_die (decl
, subr_die
);
19031 /* Generate DIEs to represent all known formal parameters. */
19032 tree parm
= DECL_ARGUMENTS (decl
);
19033 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
19034 tree generic_decl_parm
= generic_decl
19035 ? DECL_ARGUMENTS (generic_decl
)
19038 /* Now we want to walk the list of parameters of the function and
19039 emit their relevant DIEs.
19041 We consider the case of DECL being an instance of a generic function
19042 as well as it being a normal function.
19044 If DECL is an instance of a generic function we walk the
19045 parameters of the generic function declaration _and_ the parameters of
19046 DECL itself. This is useful because we want to emit specific DIEs for
19047 function parameter packs and those are declared as part of the
19048 generic function declaration. In that particular case,
19049 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
19050 That DIE has children DIEs representing the set of arguments
19051 of the pack. Note that the set of pack arguments can be empty.
19052 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
19055 Otherwise, we just consider the parameters of DECL. */
19056 while (generic_decl_parm
|| parm
)
19058 if (generic_decl_parm
19059 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
19060 gen_formal_parameter_pack_die (generic_decl_parm
,
19065 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
19067 if (parm
== DECL_ARGUMENTS (decl
)
19068 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
19070 && (dwarf_version
>= 3 || !dwarf_strict
))
19071 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
19073 parm
= DECL_CHAIN (parm
);
19076 if (generic_decl_parm
)
19077 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
19080 /* Decide whether we need an unspecified_parameters DIE at the end.
19081 There are 2 more cases to do this for: 1) the ansi ... declaration -
19082 this is detectable when the end of the arg list is not a
19083 void_type_node 2) an unprototyped function declaration (not a
19084 definition). This just means that we have no info about the
19085 parameters at all. */
19086 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
19087 if (fn_arg_types
!= NULL
)
19089 /* This is the prototyped case, check for.... */
19090 if (stdarg_p (TREE_TYPE (decl
)))
19091 gen_unspecified_parameters_die (decl
, subr_die
);
19093 else if (DECL_INITIAL (decl
) == NULL_TREE
)
19094 gen_unspecified_parameters_die (decl
, subr_die
);
19097 /* Output Dwarf info for all of the stuff within the body of the function
19098 (if it has one - it may be just a declaration). */
19099 outer_scope
= DECL_INITIAL (decl
);
19101 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
19102 a function. This BLOCK actually represents the outermost binding contour
19103 for the function, i.e. the contour in which the function's formal
19104 parameters and labels get declared. Curiously, it appears that the front
19105 end doesn't actually put the PARM_DECL nodes for the current function onto
19106 the BLOCK_VARS list for this outer scope, but are strung off of the
19107 DECL_ARGUMENTS list for the function instead.
19109 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
19110 the LABEL_DECL nodes for the function however, and we output DWARF info
19111 for those in decls_for_scope. Just within the `outer_scope' there will be
19112 a BLOCK node representing the function's outermost pair of curly braces,
19113 and any blocks used for the base and member initializers of a C++
19114 constructor function. */
19115 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
19117 /* Emit a DW_TAG_variable DIE for a named return value. */
19118 if (DECL_NAME (DECL_RESULT (decl
)))
19119 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
19121 current_function_has_inlines
= 0;
19122 decls_for_scope (outer_scope
, subr_die
, 0);
19124 /* Add the calling convention attribute if requested. */
19125 add_calling_convention_attribute (subr_die
, decl
);
19129 /* Returns a hash value for X (which really is a die_struct). */
19132 common_block_die_table_hash (const void *x
)
19134 const_dw_die_ref d
= (const_dw_die_ref
) x
;
19135 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
19138 /* Return nonzero if decl_id and die_parent of die_struct X is the same
19139 as decl_id and die_parent of die_struct Y. */
19142 common_block_die_table_eq (const void *x
, const void *y
)
19144 const_dw_die_ref d
= (const_dw_die_ref
) x
;
19145 const_dw_die_ref e
= (const_dw_die_ref
) y
;
19146 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
19149 /* Generate a DIE to represent a declared data object.
19150 Either DECL or ORIGIN must be non-null. */
19153 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
19157 tree decl_or_origin
= decl
? decl
: origin
;
19158 tree ultimate_origin
;
19159 dw_die_ref var_die
;
19160 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
19161 dw_die_ref origin_die
;
19162 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
19163 || class_or_namespace_scope_p (context_die
));
19164 bool specialization_p
= false;
19166 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
19167 if (decl
|| ultimate_origin
)
19168 origin
= ultimate_origin
;
19169 com_decl
= fortran_common (decl_or_origin
, &off
);
19171 /* Symbol in common gets emitted as a child of the common block, in the form
19172 of a data member. */
19175 dw_die_ref com_die
;
19176 dw_loc_list_ref loc
;
19177 die_node com_die_arg
;
19179 var_die
= lookup_decl_die (decl_or_origin
);
19182 if (get_AT (var_die
, DW_AT_location
) == NULL
)
19184 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
19189 /* Optimize the common case. */
19190 if (single_element_loc_list_p (loc
)
19191 && loc
->expr
->dw_loc_opc
== DW_OP_addr
19192 && loc
->expr
->dw_loc_next
== NULL
19193 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
19195 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
19196 = plus_constant (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
, off
);
19198 loc_list_plus_const (loc
, off
);
19200 add_AT_location_description (var_die
, DW_AT_location
, loc
);
19201 remove_AT (var_die
, DW_AT_declaration
);
19207 if (common_block_die_table
== NULL
)
19208 common_block_die_table
19209 = htab_create_ggc (10, common_block_die_table_hash
,
19210 common_block_die_table_eq
, NULL
);
19212 com_die_arg
.decl_id
= DECL_UID (com_decl
);
19213 com_die_arg
.die_parent
= context_die
;
19214 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
19215 loc
= loc_list_from_tree (com_decl
, 2);
19216 if (com_die
== NULL
)
19219 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
19222 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
19223 add_name_and_src_coords_attributes (com_die
, com_decl
);
19226 add_AT_location_description (com_die
, DW_AT_location
, loc
);
19227 /* Avoid sharing the same loc descriptor between
19228 DW_TAG_common_block and DW_TAG_variable. */
19229 loc
= loc_list_from_tree (com_decl
, 2);
19231 else if (DECL_EXTERNAL (decl
))
19232 add_AT_flag (com_die
, DW_AT_declaration
, 1);
19233 add_pubname_string (cnam
, com_die
); /* ??? needed? */
19234 com_die
->decl_id
= DECL_UID (com_decl
);
19235 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
19236 *slot
= (void *) com_die
;
19238 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
19240 add_AT_location_description (com_die
, DW_AT_location
, loc
);
19241 loc
= loc_list_from_tree (com_decl
, 2);
19242 remove_AT (com_die
, DW_AT_declaration
);
19244 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
19245 add_name_and_src_coords_attributes (var_die
, decl
);
19246 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
19247 TREE_THIS_VOLATILE (decl
), context_die
);
19248 add_AT_flag (var_die
, DW_AT_external
, 1);
19253 /* Optimize the common case. */
19254 if (single_element_loc_list_p (loc
)
19255 && loc
->expr
->dw_loc_opc
== DW_OP_addr
19256 && loc
->expr
->dw_loc_next
== NULL
19257 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
19258 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
19259 = plus_constant (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
, off
);
19261 loc_list_plus_const (loc
, off
);
19263 add_AT_location_description (var_die
, DW_AT_location
, loc
);
19265 else if (DECL_EXTERNAL (decl
))
19266 add_AT_flag (var_die
, DW_AT_declaration
, 1);
19267 equate_decl_number_to_die (decl
, var_die
);
19271 /* If the compiler emitted a definition for the DECL declaration
19272 and if we already emitted a DIE for it, don't emit a second
19273 DIE for it again. Allow re-declarations of DECLs that are
19274 inside functions, though. */
19275 if (old_die
&& declaration
&& !local_scope_p (context_die
))
19278 /* For static data members, the declaration in the class is supposed
19279 to have DW_TAG_member tag; the specification should still be
19280 DW_TAG_variable referencing the DW_TAG_member DIE. */
19281 if (declaration
&& class_scope_p (context_die
))
19282 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
19284 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
19287 if (origin
!= NULL
)
19288 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
19290 /* Loop unrolling can create multiple blocks that refer to the same
19291 static variable, so we must test for the DW_AT_declaration flag.
19293 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19294 copy decls and set the DECL_ABSTRACT flag on them instead of
19297 ??? Duplicated blocks have been rewritten to use .debug_ranges.
19299 ??? The declare_in_namespace support causes us to get two DIEs for one
19300 variable, both of which are declarations. We want to avoid considering
19301 one to be a specification, so we must test that this DIE is not a
19303 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
19304 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
19306 /* This is a definition of a C++ class level static. */
19307 add_AT_specification (var_die
, old_die
);
19308 specialization_p
= true;
19309 if (DECL_NAME (decl
))
19311 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
19312 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
19314 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
19315 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
19317 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
19318 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
19320 if (old_die
->die_tag
== DW_TAG_member
)
19321 add_linkage_name (var_die
, decl
);
19325 add_name_and_src_coords_attributes (var_die
, decl
);
19327 if ((origin
== NULL
&& !specialization_p
)
19329 && !DECL_ABSTRACT (decl_or_origin
)
19330 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
19331 decl_function_context
19332 (decl_or_origin
))))
19334 tree type
= TREE_TYPE (decl_or_origin
);
19336 if (decl_by_reference_p (decl_or_origin
))
19337 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
19339 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
19340 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
19343 if (origin
== NULL
&& !specialization_p
)
19345 if (TREE_PUBLIC (decl
))
19346 add_AT_flag (var_die
, DW_AT_external
, 1);
19348 if (DECL_ARTIFICIAL (decl
))
19349 add_AT_flag (var_die
, DW_AT_artificial
, 1);
19351 add_accessibility_attribute (var_die
, decl
);
19355 add_AT_flag (var_die
, DW_AT_declaration
, 1);
19357 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
19358 equate_decl_number_to_die (decl
, var_die
);
19361 && (! DECL_ABSTRACT (decl_or_origin
)
19362 /* Local static vars are shared between all clones/inlines,
19363 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19365 || (TREE_CODE (decl_or_origin
) == VAR_DECL
19366 && TREE_STATIC (decl_or_origin
)
19367 && DECL_RTL_SET_P (decl_or_origin
)))
19368 /* When abstract origin already has DW_AT_location attribute, no need
19369 to add it again. */
19370 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
19372 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
19373 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
19374 defer_location (decl_or_origin
, var_die
);
19376 add_location_or_const_value_attribute (var_die
,
19379 add_pubname (decl_or_origin
, var_die
);
19382 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
19385 /* Generate a DIE to represent a named constant. */
19388 gen_const_die (tree decl
, dw_die_ref context_die
)
19390 dw_die_ref const_die
;
19391 tree type
= TREE_TYPE (decl
);
19393 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
19394 add_name_and_src_coords_attributes (const_die
, decl
);
19395 add_type_attribute (const_die
, type
, 1, 0, context_die
);
19396 if (TREE_PUBLIC (decl
))
19397 add_AT_flag (const_die
, DW_AT_external
, 1);
19398 if (DECL_ARTIFICIAL (decl
))
19399 add_AT_flag (const_die
, DW_AT_artificial
, 1);
19400 tree_add_const_value_attribute_for_decl (const_die
, decl
);
19403 /* Generate a DIE to represent a label identifier. */
19406 gen_label_die (tree decl
, dw_die_ref context_die
)
19408 tree origin
= decl_ultimate_origin (decl
);
19409 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
19411 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19413 if (origin
!= NULL
)
19414 add_abstract_origin_attribute (lbl_die
, origin
);
19416 add_name_and_src_coords_attributes (lbl_die
, decl
);
19418 if (DECL_ABSTRACT (decl
))
19419 equate_decl_number_to_die (decl
, lbl_die
);
19422 insn
= DECL_RTL_IF_SET (decl
);
19424 /* Deleted labels are programmer specified labels which have been
19425 eliminated because of various optimizations. We still emit them
19426 here so that it is possible to put breakpoints on them. */
19430 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
19432 /* When optimization is enabled (via -O) some parts of the compiler
19433 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19434 represent source-level labels which were explicitly declared by
19435 the user. This really shouldn't be happening though, so catch
19436 it if it ever does happen. */
19437 gcc_assert (!INSN_DELETED_P (insn
));
19439 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
19440 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19445 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19446 attributes to the DIE for a block STMT, to describe where the inlined
19447 function was called from. This is similar to add_src_coords_attributes. */
19450 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
19452 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
19454 if (dwarf_version
>= 3 || !dwarf_strict
)
19456 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
19457 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
19462 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19463 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19466 add_high_low_attributes (tree stmt
, dw_die_ref die
)
19468 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19470 if (BLOCK_FRAGMENT_CHAIN (stmt
)
19471 && (dwarf_version
>= 3 || !dwarf_strict
))
19475 if (inlined_function_outer_scope_p (stmt
))
19477 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19478 BLOCK_NUMBER (stmt
));
19479 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
19482 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
));
19484 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19487 add_ranges (chain
);
19488 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
19495 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19496 BLOCK_NUMBER (stmt
));
19497 add_AT_lbl_id (die
, DW_AT_low_pc
, label
);
19498 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
19499 BLOCK_NUMBER (stmt
));
19500 add_AT_lbl_id (die
, DW_AT_high_pc
, label
);
19504 /* Generate a DIE for a lexical block. */
19507 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19509 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
19511 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
19512 add_high_low_attributes (stmt
, stmt_die
);
19514 decls_for_scope (stmt
, stmt_die
, depth
);
19517 /* Generate a DIE for an inlined subprogram. */
19520 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
19524 /* The instance of function that is effectively being inlined shall not
19526 gcc_assert (! BLOCK_ABSTRACT (stmt
));
19528 decl
= block_ultimate_origin (stmt
);
19530 /* Emit info for the abstract instance first, if we haven't yet. We
19531 must emit this even if the block is abstract, otherwise when we
19532 emit the block below (or elsewhere), we may end up trying to emit
19533 a die whose origin die hasn't been emitted, and crashing. */
19534 dwarf2out_abstract_function (decl
);
19536 if (! BLOCK_ABSTRACT (stmt
))
19538 dw_die_ref subr_die
19539 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
19541 add_abstract_origin_attribute (subr_die
, decl
);
19542 if (TREE_ASM_WRITTEN (stmt
))
19543 add_high_low_attributes (stmt
, subr_die
);
19544 add_call_src_coords_attributes (stmt
, subr_die
);
19546 decls_for_scope (stmt
, subr_die
, depth
);
19547 current_function_has_inlines
= 1;
19551 /* Generate a DIE for a field in a record, or structure. */
19554 gen_field_die (tree decl
, dw_die_ref context_die
)
19556 dw_die_ref decl_die
;
19558 if (TREE_TYPE (decl
) == error_mark_node
)
19561 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
19562 add_name_and_src_coords_attributes (decl_die
, decl
);
19563 add_type_attribute (decl_die
, member_declared_type (decl
),
19564 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
19567 if (DECL_BIT_FIELD_TYPE (decl
))
19569 add_byte_size_attribute (decl_die
, decl
);
19570 add_bit_size_attribute (decl_die
, decl
);
19571 add_bit_offset_attribute (decl_die
, decl
);
19574 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
19575 add_data_member_location_attribute (decl_die
, decl
);
19577 if (DECL_ARTIFICIAL (decl
))
19578 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19580 add_accessibility_attribute (decl_die
, decl
);
19582 /* Equate decl number to die, so that we can look up this decl later on. */
19583 equate_decl_number_to_die (decl
, decl_die
);
19587 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19588 Use modified_type_die instead.
19589 We keep this code here just in case these types of DIEs may be needed to
19590 represent certain things in other languages (e.g. Pascal) someday. */
19593 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
19596 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
19598 equate_type_number_to_die (type
, ptr_die
);
19599 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19600 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19603 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19604 Use modified_type_die instead.
19605 We keep this code here just in case these types of DIEs may be needed to
19606 represent certain things in other languages (e.g. Pascal) someday. */
19609 gen_reference_type_die (tree type
, dw_die_ref context_die
)
19611 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
19613 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
19614 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
19616 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
19618 equate_type_number_to_die (type
, ref_die
);
19619 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
19620 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19624 /* Generate a DIE for a pointer to a member type. */
19627 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
19630 = new_die (DW_TAG_ptr_to_member_type
,
19631 scope_die_for (type
, context_die
), type
);
19633 equate_type_number_to_die (type
, ptr_die
);
19634 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
19635 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
19636 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19639 /* Generate the DIE for the compilation unit. */
19642 gen_compile_unit_die (const char *filename
)
19645 char producer
[250];
19646 const char *language_string
= lang_hooks
.name
;
19649 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
19653 add_name_attribute (die
, filename
);
19654 /* Don't add cwd for <built-in>. */
19655 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
19656 add_comp_dir_attribute (die
);
19659 sprintf (producer
, "%s %s", language_string
, version_string
);
19661 #ifdef MIPS_DEBUGGING_INFO
19662 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
19663 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
19664 not appear in the producer string, the debugger reaches the conclusion
19665 that the object file is stripped and has no debugging information.
19666 To get the MIPS/SGI debugger to believe that there is debugging
19667 information in the object file, we add a -g to the producer string. */
19668 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19669 strcat (producer
, " -g");
19672 add_AT_string (die
, DW_AT_producer
, producer
);
19674 /* If our producer is LTO try to figure out a common language to use
19675 from the global list of translation units. */
19676 if (strcmp (language_string
, "GNU GIMPLE") == 0)
19680 const char *common_lang
= NULL
;
19682 FOR_EACH_VEC_ELT (tree
, all_translation_units
, i
, t
)
19684 if (!TRANSLATION_UNIT_LANGUAGE (t
))
19687 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
19688 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
19690 else if (strncmp (common_lang
, "GNU C", 5) == 0
19691 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
19692 /* Mixing C and C++ is ok, use C++ in that case. */
19693 common_lang
= "GNU C++";
19696 /* Fall back to C. */
19697 common_lang
= NULL
;
19703 language_string
= common_lang
;
19706 language
= DW_LANG_C89
;
19707 if (strcmp (language_string
, "GNU C++") == 0)
19708 language
= DW_LANG_C_plus_plus
;
19709 else if (strcmp (language_string
, "GNU F77") == 0)
19710 language
= DW_LANG_Fortran77
;
19711 else if (strcmp (language_string
, "GNU Pascal") == 0)
19712 language
= DW_LANG_Pascal83
;
19713 else if (dwarf_version
>= 3 || !dwarf_strict
)
19715 if (strcmp (language_string
, "GNU Ada") == 0)
19716 language
= DW_LANG_Ada95
;
19717 else if (strcmp (language_string
, "GNU Fortran") == 0)
19718 language
= DW_LANG_Fortran95
;
19719 else if (strcmp (language_string
, "GNU Java") == 0)
19720 language
= DW_LANG_Java
;
19721 else if (strcmp (language_string
, "GNU Objective-C") == 0)
19722 language
= DW_LANG_ObjC
;
19723 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
19724 language
= DW_LANG_ObjC_plus_plus
;
19727 add_AT_unsigned (die
, DW_AT_language
, language
);
19731 case DW_LANG_Fortran77
:
19732 case DW_LANG_Fortran90
:
19733 case DW_LANG_Fortran95
:
19734 /* Fortran has case insensitive identifiers and the front-end
19735 lowercases everything. */
19736 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
19739 /* The default DW_ID_case_sensitive doesn't need to be specified. */
19745 /* Generate the DIE for a base class. */
19748 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
19750 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
19752 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
19753 add_data_member_location_attribute (die
, binfo
);
19755 if (BINFO_VIRTUAL_P (binfo
))
19756 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
19758 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19759 children, otherwise the default is DW_ACCESS_public. In DWARF2
19760 the default has always been DW_ACCESS_private. */
19761 if (access
== access_public_node
)
19763 if (dwarf_version
== 2
19764 || context_die
->die_tag
== DW_TAG_class_type
)
19765 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
19767 else if (access
== access_protected_node
)
19768 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19769 else if (dwarf_version
> 2
19770 && context_die
->die_tag
!= DW_TAG_class_type
)
19771 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
19774 /* Generate a DIE for a class member. */
19777 gen_member_die (tree type
, dw_die_ref context_die
)
19780 tree binfo
= TYPE_BINFO (type
);
19783 /* If this is not an incomplete type, output descriptions of each of its
19784 members. Note that as we output the DIEs necessary to represent the
19785 members of this record or union type, we will also be trying to output
19786 DIEs to represent the *types* of those members. However the `type'
19787 function (above) will specifically avoid generating type DIEs for member
19788 types *within* the list of member DIEs for this (containing) type except
19789 for those types (of members) which are explicitly marked as also being
19790 members of this (containing) type themselves. The g++ front- end can
19791 force any given type to be treated as a member of some other (containing)
19792 type by setting the TYPE_CONTEXT of the given (member) type to point to
19793 the TREE node representing the appropriate (containing) type. */
19795 /* First output info about the base classes. */
19798 VEC(tree
,gc
) *accesses
= BINFO_BASE_ACCESSES (binfo
);
19802 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
19803 gen_inheritance_die (base
,
19804 (accesses
? VEC_index (tree
, accesses
, i
)
19805 : access_public_node
), context_die
);
19808 /* Now output info about the data members and type members. */
19809 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
19811 /* If we thought we were generating minimal debug info for TYPE
19812 and then changed our minds, some of the member declarations
19813 may have already been defined. Don't define them again, but
19814 do put them in the right order. */
19816 child
= lookup_decl_die (member
);
19818 splice_child_die (context_die
, child
);
19820 gen_decl_die (member
, NULL
, context_die
);
19823 /* Now output info about the function members (if any). */
19824 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
19826 /* Don't include clones in the member list. */
19827 if (DECL_ABSTRACT_ORIGIN (member
))
19830 child
= lookup_decl_die (member
);
19832 splice_child_die (context_die
, child
);
19834 gen_decl_die (member
, NULL
, context_die
);
19838 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19839 is set, we pretend that the type was never defined, so we only get the
19840 member DIEs needed by later specification DIEs. */
19843 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19844 enum debug_info_usage usage
)
19846 dw_die_ref type_die
= lookup_type_die (type
);
19847 dw_die_ref scope_die
= 0;
19849 int complete
= (TYPE_SIZE (type
)
19850 && (! TYPE_STUB_DECL (type
)
19851 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19852 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19853 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19855 if (type_die
&& ! complete
)
19858 if (TYPE_CONTEXT (type
) != NULL_TREE
19859 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19860 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19863 scope_die
= scope_die_for (type
, context_die
);
19865 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
19866 /* First occurrence of type or toplevel definition of nested class. */
19868 dw_die_ref old_die
= type_die
;
19870 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19871 ? record_type_tag (type
) : DW_TAG_union_type
,
19873 equate_type_number_to_die (type
, type_die
);
19875 add_AT_specification (type_die
, old_die
);
19877 add_name_attribute (type_die
, type_tag (type
));
19880 remove_AT (type_die
, DW_AT_declaration
);
19882 /* Generate child dies for template paramaters. */
19883 if (debug_info_level
> DINFO_LEVEL_TERSE
19884 && COMPLETE_TYPE_P (type
))
19885 gen_generic_params_dies (type
);
19887 /* If this type has been completed, then give it a byte_size attribute and
19888 then give a list of members. */
19889 if (complete
&& !ns_decl
)
19891 /* Prevent infinite recursion in cases where the type of some member of
19892 this type is expressed in terms of this type itself. */
19893 TREE_ASM_WRITTEN (type
) = 1;
19894 add_byte_size_attribute (type_die
, type
);
19895 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19897 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19898 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19901 /* If the first reference to this type was as the return type of an
19902 inline function, then it may not have a parent. Fix this now. */
19903 if (type_die
->die_parent
== NULL
)
19904 add_child_die (scope_die
, type_die
);
19906 push_decl_scope (type
);
19907 gen_member_die (type
, type_die
);
19910 /* GNU extension: Record what type our vtable lives in. */
19911 if (TYPE_VFIELD (type
))
19913 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19915 gen_type_die (vtype
, context_die
);
19916 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19917 lookup_type_die (vtype
));
19922 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19924 /* We don't need to do this for function-local types. */
19925 if (TYPE_STUB_DECL (type
)
19926 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19927 VEC_safe_push (tree
, gc
, incomplete_types
, type
);
19930 if (get_AT (type_die
, DW_AT_name
))
19931 add_pubtype (type
, type_die
);
19934 /* Generate a DIE for a subroutine _type_. */
19937 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19939 tree return_type
= TREE_TYPE (type
);
19940 dw_die_ref subr_die
19941 = new_die (DW_TAG_subroutine_type
,
19942 scope_die_for (type
, context_die
), type
);
19944 equate_type_number_to_die (type
, subr_die
);
19945 add_prototyped_attribute (subr_die
, type
);
19946 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
19947 gen_formal_types_die (type
, subr_die
);
19949 if (get_AT (subr_die
, DW_AT_name
))
19950 add_pubtype (type
, subr_die
);
19953 /* Generate a DIE for a type definition. */
19956 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19958 dw_die_ref type_die
;
19961 if (TREE_ASM_WRITTEN (decl
))
19964 TREE_ASM_WRITTEN (decl
) = 1;
19965 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19966 origin
= decl_ultimate_origin (decl
);
19967 if (origin
!= NULL
)
19968 add_abstract_origin_attribute (type_die
, origin
);
19973 add_name_and_src_coords_attributes (type_die
, decl
);
19974 if (DECL_ORIGINAL_TYPE (decl
))
19976 type
= DECL_ORIGINAL_TYPE (decl
);
19978 gcc_assert (type
!= TREE_TYPE (decl
));
19979 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19983 type
= TREE_TYPE (decl
);
19985 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19987 /* Here, we are in the case of decl being a typedef naming
19988 an anonymous type, e.g:
19989 typedef struct {...} foo;
19990 In that case TREE_TYPE (decl) is not a typedef variant
19991 type and TYPE_NAME of the anonymous type is set to the
19992 TYPE_DECL of the typedef. This construct is emitted by
19995 TYPE is the anonymous struct named by the typedef
19996 DECL. As we need the DW_AT_type attribute of the
19997 DW_TAG_typedef to point to the DIE of TYPE, let's
19998 generate that DIE right away. add_type_attribute
19999 called below will then pick (via lookup_type_die) that
20000 anonymous struct DIE. */
20001 if (!TREE_ASM_WRITTEN (type
))
20002 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
20006 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
20007 TREE_THIS_VOLATILE (decl
), context_die
);
20009 if (is_naming_typedef_decl (decl
))
20010 /* We want that all subsequent calls to lookup_type_die with
20011 TYPE in argument yield the DW_TAG_typedef we have just
20013 equate_type_number_to_die (type
, type_die
);
20015 add_accessibility_attribute (type_die
, decl
);
20018 if (DECL_ABSTRACT (decl
))
20019 equate_decl_number_to_die (decl
, type_die
);
20021 if (get_AT (type_die
, DW_AT_name
))
20022 add_pubtype (decl
, type_die
);
20025 /* Generate a DIE for a struct, class, enum or union type. */
20028 gen_tagged_type_die (tree type
,
20029 dw_die_ref context_die
,
20030 enum debug_info_usage usage
)
20034 if (type
== NULL_TREE
20035 || !is_tagged_type (type
))
20038 /* If this is a nested type whose containing class hasn't been written
20039 out yet, writing it out will cover this one, too. This does not apply
20040 to instantiations of member class templates; they need to be added to
20041 the containing class as they are generated. FIXME: This hurts the
20042 idea of combining type decls from multiple TUs, since we can't predict
20043 what set of template instantiations we'll get. */
20044 if (TYPE_CONTEXT (type
)
20045 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
20046 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
20048 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
20050 if (TREE_ASM_WRITTEN (type
))
20053 /* If that failed, attach ourselves to the stub. */
20054 push_decl_scope (TYPE_CONTEXT (type
));
20055 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
20058 else if (TYPE_CONTEXT (type
) != NULL_TREE
20059 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
20061 /* If this type is local to a function that hasn't been written
20062 out yet, use a NULL context for now; it will be fixed up in
20063 decls_for_scope. */
20064 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
20069 context_die
= declare_in_namespace (type
, context_die
);
20073 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
20075 /* This might have been written out by the call to
20076 declare_in_namespace. */
20077 if (!TREE_ASM_WRITTEN (type
))
20078 gen_enumeration_type_die (type
, context_die
);
20081 gen_struct_or_union_type_die (type
, context_die
, usage
);
20086 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
20087 it up if it is ever completed. gen_*_type_die will set it for us
20088 when appropriate. */
20091 /* Generate a type description DIE. */
20094 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
20095 enum debug_info_usage usage
)
20097 struct array_descr_info info
;
20099 if (type
== NULL_TREE
|| type
== error_mark_node
)
20102 /* If TYPE is a typedef type variant, let's generate debug info
20103 for the parent typedef which TYPE is a type of. */
20104 if (typedef_variant_p (type
))
20106 if (TREE_ASM_WRITTEN (type
))
20109 /* Prevent broken recursion; we can't hand off to the same type. */
20110 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
20112 /* Use the DIE of the containing namespace as the parent DIE of
20113 the type description DIE we want to generate. */
20114 if (DECL_CONTEXT (TYPE_NAME (type
))
20115 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
20116 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
20118 TREE_ASM_WRITTEN (type
) = 1;
20120 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
20124 /* If type is an anonymous tagged type named by a typedef, let's
20125 generate debug info for the typedef. */
20126 if (is_naming_typedef_decl (TYPE_NAME (type
)))
20128 /* Use the DIE of the containing namespace as the parent DIE of
20129 the type description DIE we want to generate. */
20130 if (DECL_CONTEXT (TYPE_NAME (type
))
20131 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
20132 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
20134 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
20138 /* If this is an array type with hidden descriptor, handle it first. */
20139 if (!TREE_ASM_WRITTEN (type
)
20140 && lang_hooks
.types
.get_array_descr_info
20141 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
20142 && (dwarf_version
>= 3 || !dwarf_strict
))
20144 gen_descr_array_type_die (type
, &info
, context_die
);
20145 TREE_ASM_WRITTEN (type
) = 1;
20149 /* We are going to output a DIE to represent the unqualified version
20150 of this type (i.e. without any const or volatile qualifiers) so
20151 get the main variant (i.e. the unqualified version) of this type
20152 now. (Vectors are special because the debugging info is in the
20153 cloned type itself). */
20154 if (TREE_CODE (type
) != VECTOR_TYPE
)
20155 type
= type_main_variant (type
);
20157 if (TREE_ASM_WRITTEN (type
))
20160 switch (TREE_CODE (type
))
20166 case REFERENCE_TYPE
:
20167 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
20168 ensures that the gen_type_die recursion will terminate even if the
20169 type is recursive. Recursive types are possible in Ada. */
20170 /* ??? We could perhaps do this for all types before the switch
20172 TREE_ASM_WRITTEN (type
) = 1;
20174 /* For these types, all that is required is that we output a DIE (or a
20175 set of DIEs) to represent the "basis" type. */
20176 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20177 DINFO_USAGE_IND_USE
);
20181 /* This code is used for C++ pointer-to-data-member types.
20182 Output a description of the relevant class type. */
20183 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
20184 DINFO_USAGE_IND_USE
);
20186 /* Output a description of the type of the object pointed to. */
20187 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20188 DINFO_USAGE_IND_USE
);
20190 /* Now output a DIE to represent this pointer-to-data-member type
20192 gen_ptr_to_mbr_type_die (type
, context_die
);
20195 case FUNCTION_TYPE
:
20196 /* Force out return type (in case it wasn't forced out already). */
20197 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20198 DINFO_USAGE_DIR_USE
);
20199 gen_subroutine_type_die (type
, context_die
);
20203 /* Force out return type (in case it wasn't forced out already). */
20204 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20205 DINFO_USAGE_DIR_USE
);
20206 gen_subroutine_type_die (type
, context_die
);
20210 gen_array_type_die (type
, context_die
);
20214 gen_array_type_die (type
, context_die
);
20217 case ENUMERAL_TYPE
:
20220 case QUAL_UNION_TYPE
:
20221 gen_tagged_type_die (type
, context_die
, usage
);
20227 case FIXED_POINT_TYPE
:
20230 /* No DIEs needed for fundamental types. */
20235 /* Just use DW_TAG_unspecified_type. */
20237 dw_die_ref type_die
= lookup_type_die (type
);
20238 if (type_die
== NULL
)
20240 tree name
= TYPE_NAME (type
);
20241 if (TREE_CODE (name
) == TYPE_DECL
)
20242 name
= DECL_NAME (name
);
20243 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
20244 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
20245 equate_type_number_to_die (type
, type_die
);
20251 gcc_unreachable ();
20254 TREE_ASM_WRITTEN (type
) = 1;
20258 gen_type_die (tree type
, dw_die_ref context_die
)
20260 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
20263 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20264 things which are local to the given block. */
20267 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
20269 int must_output_die
= 0;
20272 /* Ignore blocks that are NULL. */
20273 if (stmt
== NULL_TREE
)
20276 inlined_func
= inlined_function_outer_scope_p (stmt
);
20278 /* If the block is one fragment of a non-contiguous block, do not
20279 process the variables, since they will have been done by the
20280 origin block. Do process subblocks. */
20281 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
20285 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
20286 gen_block_die (sub
, context_die
, depth
+ 1);
20291 /* Determine if we need to output any Dwarf DIEs at all to represent this
20294 /* The outer scopes for inlinings *must* always be represented. We
20295 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20296 must_output_die
= 1;
20299 /* Determine if this block directly contains any "significant"
20300 local declarations which we will need to output DIEs for. */
20301 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20302 /* We are not in terse mode so *any* local declaration counts
20303 as being a "significant" one. */
20304 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
20305 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
20306 && (TREE_USED (stmt
)
20307 || TREE_ASM_WRITTEN (stmt
)
20308 || BLOCK_ABSTRACT (stmt
)));
20309 else if ((TREE_USED (stmt
)
20310 || TREE_ASM_WRITTEN (stmt
)
20311 || BLOCK_ABSTRACT (stmt
))
20312 && !dwarf2out_ignore_block (stmt
))
20313 must_output_die
= 1;
20316 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20317 DIE for any block which contains no significant local declarations at
20318 all. Rather, in such cases we just call `decls_for_scope' so that any
20319 needed Dwarf info for any sub-blocks will get properly generated. Note
20320 that in terse mode, our definition of what constitutes a "significant"
20321 local declaration gets restricted to include only inlined function
20322 instances and local (nested) function definitions. */
20323 if (must_output_die
)
20327 /* If STMT block is abstract, that means we have been called
20328 indirectly from dwarf2out_abstract_function.
20329 That function rightfully marks the descendent blocks (of
20330 the abstract function it is dealing with) as being abstract,
20331 precisely to prevent us from emitting any
20332 DW_TAG_inlined_subroutine DIE as a descendent
20333 of an abstract function instance. So in that case, we should
20334 not call gen_inlined_subroutine_die.
20336 Later though, when cgraph asks dwarf2out to emit info
20337 for the concrete instance of the function decl into which
20338 the concrete instance of STMT got inlined, the later will lead
20339 to the generation of a DW_TAG_inlined_subroutine DIE. */
20340 if (! BLOCK_ABSTRACT (stmt
))
20341 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
20344 gen_lexical_block_die (stmt
, context_die
, depth
);
20347 decls_for_scope (stmt
, context_die
, depth
);
20350 /* Process variable DECL (or variable with origin ORIGIN) within
20351 block STMT and add it to CONTEXT_DIE. */
20353 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
20356 tree decl_or_origin
= decl
? decl
: origin
;
20358 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
20359 die
= lookup_decl_die (decl_or_origin
);
20360 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
20361 && TYPE_DECL_IS_STUB (decl_or_origin
))
20362 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
20366 if (die
!= NULL
&& die
->die_parent
== NULL
)
20367 add_child_die (context_die
, die
);
20368 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
20369 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
20370 stmt
, context_die
);
20372 gen_decl_die (decl
, origin
, context_die
);
20375 /* Generate all of the decls declared within a given scope and (recursively)
20376 all of its sub-blocks. */
20379 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
20385 /* Ignore NULL blocks. */
20386 if (stmt
== NULL_TREE
)
20389 /* Output the DIEs to represent all of the data objects and typedefs
20390 declared directly within this block but not within any nested
20391 sub-blocks. Also, nested function and tag DIEs have been
20392 generated with a parent of NULL; fix that up now. */
20393 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
20394 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
20395 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
20396 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
20399 /* If we're at -g1, we're not interested in subblocks. */
20400 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20403 /* Output the DIEs to represent all sub-blocks (and the items declared
20404 therein) of this block. */
20405 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
20407 subblocks
= BLOCK_CHAIN (subblocks
))
20408 gen_block_die (subblocks
, context_die
, depth
+ 1);
20411 /* Is this a typedef we can avoid emitting? */
20414 is_redundant_typedef (const_tree decl
)
20416 if (TYPE_DECL_IS_STUB (decl
))
20419 if (DECL_ARTIFICIAL (decl
)
20420 && DECL_CONTEXT (decl
)
20421 && is_tagged_type (DECL_CONTEXT (decl
))
20422 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
20423 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
20424 /* Also ignore the artificial member typedef for the class name. */
20430 /* Return TRUE if TYPE is a typedef that names a type for linkage
20431 purposes. This kind of typedefs is produced by the C++ FE for
20434 typedef struct {...} foo;
20436 In that case, there is no typedef variant type produced for foo.
20437 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20441 is_naming_typedef_decl (const_tree decl
)
20443 if (decl
== NULL_TREE
20444 || TREE_CODE (decl
) != TYPE_DECL
20445 || !is_tagged_type (TREE_TYPE (decl
))
20446 || DECL_IS_BUILTIN (decl
)
20447 || is_redundant_typedef (decl
)
20448 /* It looks like Ada produces TYPE_DECLs that are very similar
20449 to C++ naming typedefs but that have different
20450 semantics. Let's be specific to c++ for now. */
20454 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
20455 && TYPE_NAME (TREE_TYPE (decl
)) == decl
20456 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
20457 != TYPE_NAME (TREE_TYPE (decl
))));
20460 /* Returns the DIE for a context. */
20462 static inline dw_die_ref
20463 get_context_die (tree context
)
20467 /* Find die that represents this context. */
20468 if (TYPE_P (context
))
20469 return force_type_die (TYPE_MAIN_VARIANT (context
));
20471 return force_decl_die (context
);
20473 return comp_unit_die ();
20476 /* Returns the DIE for decl. A DIE will always be returned. */
20479 force_decl_die (tree decl
)
20481 dw_die_ref decl_die
;
20482 unsigned saved_external_flag
;
20483 tree save_fn
= NULL_TREE
;
20484 decl_die
= lookup_decl_die (decl
);
20487 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
20489 decl_die
= lookup_decl_die (decl
);
20493 switch (TREE_CODE (decl
))
20495 case FUNCTION_DECL
:
20496 /* Clear current_function_decl, so that gen_subprogram_die thinks
20497 that this is a declaration. At this point, we just want to force
20498 declaration die. */
20499 save_fn
= current_function_decl
;
20500 current_function_decl
= NULL_TREE
;
20501 gen_subprogram_die (decl
, context_die
);
20502 current_function_decl
= save_fn
;
20506 /* Set external flag to force declaration die. Restore it after
20507 gen_decl_die() call. */
20508 saved_external_flag
= DECL_EXTERNAL (decl
);
20509 DECL_EXTERNAL (decl
) = 1;
20510 gen_decl_die (decl
, NULL
, context_die
);
20511 DECL_EXTERNAL (decl
) = saved_external_flag
;
20514 case NAMESPACE_DECL
:
20515 if (dwarf_version
>= 3 || !dwarf_strict
)
20516 dwarf2out_decl (decl
);
20518 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
20519 decl_die
= comp_unit_die ();
20522 case TRANSLATION_UNIT_DECL
:
20523 decl_die
= comp_unit_die ();
20527 gcc_unreachable ();
20530 /* We should be able to find the DIE now. */
20532 decl_die
= lookup_decl_die (decl
);
20533 gcc_assert (decl_die
);
20539 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
20540 always returned. */
20543 force_type_die (tree type
)
20545 dw_die_ref type_die
;
20547 type_die
= lookup_type_die (type
);
20550 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
20552 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
20553 TYPE_VOLATILE (type
), context_die
);
20554 gcc_assert (type_die
);
20559 /* Force out any required namespaces to be able to output DECL,
20560 and return the new context_die for it, if it's changed. */
20563 setup_namespace_context (tree thing
, dw_die_ref context_die
)
20565 tree context
= (DECL_P (thing
)
20566 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
20567 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
20568 /* Force out the namespace. */
20569 context_die
= force_decl_die (context
);
20571 return context_die
;
20574 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
20575 type) within its namespace, if appropriate.
20577 For compatibility with older debuggers, namespace DIEs only contain
20578 declarations; all definitions are emitted at CU scope. */
20581 declare_in_namespace (tree thing
, dw_die_ref context_die
)
20583 dw_die_ref ns_context
;
20585 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20586 return context_die
;
20588 /* If this decl is from an inlined function, then don't try to emit it in its
20589 namespace, as we will get confused. It would have already been emitted
20590 when the abstract instance of the inline function was emitted anyways. */
20591 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
20592 return context_die
;
20594 ns_context
= setup_namespace_context (thing
, context_die
);
20596 if (ns_context
!= context_die
)
20600 if (DECL_P (thing
))
20601 gen_decl_die (thing
, NULL
, ns_context
);
20603 gen_type_die (thing
, ns_context
);
20605 return context_die
;
20608 /* Generate a DIE for a namespace or namespace alias. */
20611 gen_namespace_die (tree decl
, dw_die_ref context_die
)
20613 dw_die_ref namespace_die
;
20615 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
20616 they are an alias of. */
20617 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
20619 /* Output a real namespace or module. */
20620 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20621 namespace_die
= new_die (is_fortran ()
20622 ? DW_TAG_module
: DW_TAG_namespace
,
20623 context_die
, decl
);
20624 /* For Fortran modules defined in different CU don't add src coords. */
20625 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
20627 const char *name
= dwarf2_name (decl
, 0);
20629 add_name_attribute (namespace_die
, name
);
20632 add_name_and_src_coords_attributes (namespace_die
, decl
);
20633 if (DECL_EXTERNAL (decl
))
20634 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
20635 equate_decl_number_to_die (decl
, namespace_die
);
20639 /* Output a namespace alias. */
20641 /* Force out the namespace we are an alias of, if necessary. */
20642 dw_die_ref origin_die
20643 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
20645 if (DECL_FILE_SCOPE_P (decl
)
20646 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
20647 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20648 /* Now create the namespace alias DIE. */
20649 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
20650 add_name_and_src_coords_attributes (namespace_die
, decl
);
20651 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
20652 equate_decl_number_to_die (decl
, namespace_die
);
20656 /* Generate Dwarf debug information for a decl described by DECL.
20657 The return value is currently only meaningful for PARM_DECLs,
20658 for all other decls it returns NULL. */
20661 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
20663 tree decl_or_origin
= decl
? decl
: origin
;
20664 tree class_origin
= NULL
, ultimate_origin
;
20666 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
20669 switch (TREE_CODE (decl_or_origin
))
20675 if (!is_fortran () && !is_ada ())
20677 /* The individual enumerators of an enum type get output when we output
20678 the Dwarf representation of the relevant enum type itself. */
20682 /* Emit its type. */
20683 gen_type_die (TREE_TYPE (decl
), context_die
);
20685 /* And its containing namespace. */
20686 context_die
= declare_in_namespace (decl
, context_die
);
20688 gen_const_die (decl
, context_die
);
20691 case FUNCTION_DECL
:
20692 /* Don't output any DIEs to represent mere function declarations,
20693 unless they are class members or explicit block externs. */
20694 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
20695 && DECL_FILE_SCOPE_P (decl_or_origin
)
20696 && (current_function_decl
== NULL_TREE
20697 || DECL_ARTIFICIAL (decl_or_origin
)))
20702 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
20703 on local redeclarations of global functions. That seems broken. */
20704 if (current_function_decl
!= decl
)
20705 /* This is only a declaration. */;
20708 /* If we're emitting a clone, emit info for the abstract instance. */
20709 if (origin
|| DECL_ORIGIN (decl
) != decl
)
20710 dwarf2out_abstract_function (origin
20711 ? DECL_ORIGIN (origin
)
20712 : DECL_ABSTRACT_ORIGIN (decl
));
20714 /* If we're emitting an out-of-line copy of an inline function,
20715 emit info for the abstract instance and set up to refer to it. */
20716 else if (cgraph_function_possibly_inlined_p (decl
)
20717 && ! DECL_ABSTRACT (decl
)
20718 && ! class_or_namespace_scope_p (context_die
)
20719 /* dwarf2out_abstract_function won't emit a die if this is just
20720 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
20721 that case, because that works only if we have a die. */
20722 && DECL_INITIAL (decl
) != NULL_TREE
)
20724 dwarf2out_abstract_function (decl
);
20725 set_decl_origin_self (decl
);
20728 /* Otherwise we're emitting the primary DIE for this decl. */
20729 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20731 /* Before we describe the FUNCTION_DECL itself, make sure that we
20732 have its containing type. */
20734 origin
= decl_class_context (decl
);
20735 if (origin
!= NULL_TREE
)
20736 gen_type_die (origin
, context_die
);
20738 /* And its return type. */
20739 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
20741 /* And its virtual context. */
20742 if (DECL_VINDEX (decl
) != NULL_TREE
)
20743 gen_type_die (DECL_CONTEXT (decl
), context_die
);
20745 /* Make sure we have a member DIE for decl. */
20746 if (origin
!= NULL_TREE
)
20747 gen_type_die_for_member (origin
, decl
, context_die
);
20749 /* And its containing namespace. */
20750 context_die
= declare_in_namespace (decl
, context_die
);
20753 /* Now output a DIE to represent the function itself. */
20755 gen_subprogram_die (decl
, context_die
);
20759 /* If we are in terse mode, don't generate any DIEs to represent any
20760 actual typedefs. */
20761 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20764 /* In the special case of a TYPE_DECL node representing the declaration
20765 of some type tag, if the given TYPE_DECL is marked as having been
20766 instantiated from some other (original) TYPE_DECL node (e.g. one which
20767 was generated within the original definition of an inline function) we
20768 used to generate a special (abbreviated) DW_TAG_structure_type,
20769 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20770 should be actually referencing those DIEs, as variable DIEs with that
20771 type would be emitted already in the abstract origin, so it was always
20772 removed during unused type prunning. Don't add anything in this
20774 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
20777 if (is_redundant_typedef (decl
))
20778 gen_type_die (TREE_TYPE (decl
), context_die
);
20780 /* Output a DIE to represent the typedef itself. */
20781 gen_typedef_die (decl
, context_die
);
20785 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
20786 gen_label_die (decl
, context_die
);
20791 /* If we are in terse mode, don't generate any DIEs to represent any
20792 variable declarations or definitions. */
20793 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20796 /* Output any DIEs that are needed to specify the type of this data
20798 if (decl_by_reference_p (decl_or_origin
))
20799 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20801 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20803 /* And its containing type. */
20804 class_origin
= decl_class_context (decl_or_origin
);
20805 if (class_origin
!= NULL_TREE
)
20806 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20808 /* And its containing namespace. */
20809 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20811 /* Now output the DIE to represent the data object itself. This gets
20812 complicated because of the possibility that the VAR_DECL really
20813 represents an inlined instance of a formal parameter for an inline
20815 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20816 if (ultimate_origin
!= NULL_TREE
20817 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20818 gen_formal_parameter_die (decl
, origin
,
20819 true /* Emit name attribute. */,
20822 gen_variable_die (decl
, origin
, context_die
);
20826 /* Ignore the nameless fields that are used to skip bits but handle C++
20827 anonymous unions and structs. */
20828 if (DECL_NAME (decl
) != NULL_TREE
20829 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20830 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20832 gen_type_die (member_declared_type (decl
), context_die
);
20833 gen_field_die (decl
, context_die
);
20838 if (DECL_BY_REFERENCE (decl_or_origin
))
20839 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20841 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20842 return gen_formal_parameter_die (decl
, origin
,
20843 true /* Emit name attribute. */,
20846 case NAMESPACE_DECL
:
20847 case IMPORTED_DECL
:
20848 if (dwarf_version
>= 3 || !dwarf_strict
)
20849 gen_namespace_die (decl
, context_die
);
20853 /* Probably some frontend-internal decl. Assume we don't care. */
20854 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20861 /* Output debug information for global decl DECL. Called from toplev.c after
20862 compilation proper has finished. */
20865 dwarf2out_global_decl (tree decl
)
20867 /* Output DWARF2 information for file-scope tentative data object
20868 declarations, file-scope (extern) function declarations (which
20869 had no corresponding body) and file-scope tagged type declarations
20870 and definitions which have not yet been forced out. */
20871 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20872 dwarf2out_decl (decl
);
20875 /* Output debug information for type decl DECL. Called from toplev.c
20876 and from language front ends (to record built-in types). */
20878 dwarf2out_type_decl (tree decl
, int local
)
20881 dwarf2out_decl (decl
);
20884 /* Output debug information for imported module or decl DECL.
20885 NAME is non-NULL name in the lexical block if the decl has been renamed.
20886 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20887 that DECL belongs to.
20888 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20890 dwarf2out_imported_module_or_decl_1 (tree decl
,
20892 tree lexical_block
,
20893 dw_die_ref lexical_block_die
)
20895 expanded_location xloc
;
20896 dw_die_ref imported_die
= NULL
;
20897 dw_die_ref at_import_die
;
20899 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20901 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20902 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20906 xloc
= expand_location (input_location
);
20908 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20910 at_import_die
= force_type_die (TREE_TYPE (decl
));
20911 /* For namespace N { typedef void T; } using N::T; base_type_die
20912 returns NULL, but DW_TAG_imported_declaration requires
20913 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20914 if (!at_import_die
)
20916 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20917 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20918 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20919 gcc_assert (at_import_die
);
20924 at_import_die
= lookup_decl_die (decl
);
20925 if (!at_import_die
)
20927 /* If we're trying to avoid duplicate debug info, we may not have
20928 emitted the member decl for this field. Emit it now. */
20929 if (TREE_CODE (decl
) == FIELD_DECL
)
20931 tree type
= DECL_CONTEXT (decl
);
20933 if (TYPE_CONTEXT (type
)
20934 && TYPE_P (TYPE_CONTEXT (type
))
20935 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20936 DINFO_USAGE_DIR_USE
))
20938 gen_type_die_for_member (type
, decl
,
20939 get_context_die (TYPE_CONTEXT (type
)));
20941 at_import_die
= force_decl_die (decl
);
20945 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20947 if (dwarf_version
>= 3 || !dwarf_strict
)
20948 imported_die
= new_die (DW_TAG_imported_module
,
20955 imported_die
= new_die (DW_TAG_imported_declaration
,
20959 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20960 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20962 add_AT_string (imported_die
, DW_AT_name
,
20963 IDENTIFIER_POINTER (name
));
20964 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20967 /* Output debug information for imported module or decl DECL.
20968 NAME is non-NULL name in context if the decl has been renamed.
20969 CHILD is true if decl is one of the renamed decls as part of
20970 importing whole module. */
20973 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20976 /* dw_die_ref at_import_die; */
20977 dw_die_ref scope_die
;
20979 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20984 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20985 We need decl DIE for reference and scope die. First, get DIE for the decl
20988 /* Get the scope die for decl context. Use comp_unit_die for global module
20989 or decl. If die is not found for non globals, force new die. */
20991 && TYPE_P (context
)
20992 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20995 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20998 scope_die
= get_context_die (context
);
21002 gcc_assert (scope_die
->die_child
);
21003 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
21004 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
21005 scope_die
= scope_die
->die_child
;
21008 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
21009 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
21013 /* Write the debugging output for DECL. */
21016 dwarf2out_decl (tree decl
)
21018 dw_die_ref context_die
= comp_unit_die ();
21020 switch (TREE_CODE (decl
))
21025 case FUNCTION_DECL
:
21026 /* What we would really like to do here is to filter out all mere
21027 file-scope declarations of file-scope functions which are never
21028 referenced later within this translation unit (and keep all of ones
21029 that *are* referenced later on) but we aren't clairvoyant, so we have
21030 no idea which functions will be referenced in the future (i.e. later
21031 on within the current translation unit). So here we just ignore all
21032 file-scope function declarations which are not also definitions. If
21033 and when the debugger needs to know something about these functions,
21034 it will have to hunt around and find the DWARF information associated
21035 with the definition of the function.
21037 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
21038 nodes represent definitions and which ones represent mere
21039 declarations. We have to check DECL_INITIAL instead. That's because
21040 the C front-end supports some weird semantics for "extern inline"
21041 function definitions. These can get inlined within the current
21042 translation unit (and thus, we need to generate Dwarf info for their
21043 abstract instances so that the Dwarf info for the concrete inlined
21044 instances can have something to refer to) but the compiler never
21045 generates any out-of-lines instances of such things (despite the fact
21046 that they *are* definitions).
21048 The important point is that the C front-end marks these "extern
21049 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
21050 them anyway. Note that the C++ front-end also plays some similar games
21051 for inline function definitions appearing within include files which
21052 also contain `#pragma interface' pragmas. */
21053 if (DECL_INITIAL (decl
) == NULL_TREE
)
21056 /* If we're a nested function, initially use a parent of NULL; if we're
21057 a plain function, this will be fixed up in decls_for_scope. If
21058 we're a method, it will be ignored, since we already have a DIE. */
21059 if (decl_function_context (decl
)
21060 /* But if we're in terse mode, we don't care about scope. */
21061 && debug_info_level
> DINFO_LEVEL_TERSE
)
21062 context_die
= NULL
;
21066 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
21067 declaration and if the declaration was never even referenced from
21068 within this entire compilation unit. We suppress these DIEs in
21069 order to save space in the .debug section (by eliminating entries
21070 which are probably useless). Note that we must not suppress
21071 block-local extern declarations (whether used or not) because that
21072 would screw-up the debugger's name lookup mechanism and cause it to
21073 miss things which really ought to be in scope at a given point. */
21074 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
21077 /* For local statics lookup proper context die. */
21078 if (TREE_STATIC (decl
) && decl_function_context (decl
))
21079 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
21081 /* If we are in terse mode, don't generate any DIEs to represent any
21082 variable declarations or definitions. */
21083 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21088 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21090 if (!is_fortran () && !is_ada ())
21092 if (TREE_STATIC (decl
) && decl_function_context (decl
))
21093 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
21096 case NAMESPACE_DECL
:
21097 case IMPORTED_DECL
:
21098 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21100 if (lookup_decl_die (decl
) != NULL
)
21105 /* Don't emit stubs for types unless they are needed by other DIEs. */
21106 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
21109 /* Don't bother trying to generate any DIEs to represent any of the
21110 normal built-in types for the language we are compiling. */
21111 if (DECL_IS_BUILTIN (decl
))
21114 /* If we are in terse mode, don't generate any DIEs for types. */
21115 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21118 /* If we're a function-scope tag, initially use a parent of NULL;
21119 this will be fixed up in decls_for_scope. */
21120 if (decl_function_context (decl
))
21121 context_die
= NULL
;
21129 gen_decl_die (decl
, NULL
, context_die
);
21132 /* Write the debugging output for DECL. */
21135 dwarf2out_function_decl (tree decl
)
21137 dwarf2out_decl (decl
);
21139 htab_empty (decl_loc_table
);
21142 /* Output a marker (i.e. a label) for the beginning of the generated code for
21143 a lexical block. */
21146 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
21147 unsigned int blocknum
)
21149 switch_to_section (current_function_section ());
21150 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
21153 /* Output a marker (i.e. a label) for the end of the generated code for a
21157 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
21159 switch_to_section (current_function_section ());
21160 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
21163 /* Returns nonzero if it is appropriate not to emit any debugging
21164 information for BLOCK, because it doesn't contain any instructions.
21166 Don't allow this for blocks with nested functions or local classes
21167 as we would end up with orphans, and in the presence of scheduling
21168 we may end up calling them anyway. */
21171 dwarf2out_ignore_block (const_tree block
)
21176 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
21177 if (TREE_CODE (decl
) == FUNCTION_DECL
21178 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
21180 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
21182 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
21183 if (TREE_CODE (decl
) == FUNCTION_DECL
21184 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
21191 /* Hash table routines for file_hash. */
21194 file_table_eq (const void *p1_p
, const void *p2_p
)
21196 const struct dwarf_file_data
*const p1
=
21197 (const struct dwarf_file_data
*) p1_p
;
21198 const char *const p2
= (const char *) p2_p
;
21199 return strcmp (p1
->filename
, p2
) == 0;
21203 file_table_hash (const void *p_p
)
21205 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
21206 return htab_hash_string (p
->filename
);
21209 /* Lookup FILE_NAME (in the list of filenames that we know about here in
21210 dwarf2out.c) and return its "index". The index of each (known) filename is
21211 just a unique number which is associated with only that one filename. We
21212 need such numbers for the sake of generating labels (in the .debug_sfnames
21213 section) and references to those files numbers (in the .debug_srcinfo
21214 and.debug_macinfo sections). If the filename given as an argument is not
21215 found in our current list, add it to the list and assign it the next
21216 available unique index number. In order to speed up searches, we remember
21217 the index of the filename was looked up last. This handles the majority of
21220 static struct dwarf_file_data
*
21221 lookup_filename (const char *file_name
)
21224 struct dwarf_file_data
* created
;
21226 /* Check to see if the file name that was searched on the previous
21227 call matches this file name. If so, return the index. */
21228 if (file_table_last_lookup
21229 && (file_name
== file_table_last_lookup
->filename
21230 || strcmp (file_table_last_lookup
->filename
, file_name
) == 0))
21231 return file_table_last_lookup
;
21233 /* Didn't match the previous lookup, search the table. */
21234 slot
= htab_find_slot_with_hash (file_table
, file_name
,
21235 htab_hash_string (file_name
), INSERT
);
21237 return (struct dwarf_file_data
*) *slot
;
21239 created
= ggc_alloc_dwarf_file_data ();
21240 created
->filename
= file_name
;
21241 created
->emitted_number
= 0;
21246 /* If the assembler will construct the file table, then translate the compiler
21247 internal file table number into the assembler file table number, and emit
21248 a .file directive if we haven't already emitted one yet. The file table
21249 numbers are different because we prune debug info for unused variables and
21250 types, which may include filenames. */
21253 maybe_emit_file (struct dwarf_file_data
* fd
)
21255 if (! fd
->emitted_number
)
21257 if (last_emitted_file
)
21258 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
21260 fd
->emitted_number
= 1;
21261 last_emitted_file
= fd
;
21263 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21265 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
21266 output_quoted_string (asm_out_file
,
21267 remap_debug_filename (fd
->filename
));
21268 fputc ('\n', asm_out_file
);
21272 return fd
->emitted_number
;
21275 /* Schedule generation of a DW_AT_const_value attribute to DIE.
21276 That generation should happen after function debug info has been
21277 generated. The value of the attribute is the constant value of ARG. */
21280 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
21282 die_arg_entry entry
;
21287 if (!tmpl_value_parm_die_table
)
21288 tmpl_value_parm_die_table
21289 = VEC_alloc (die_arg_entry
, gc
, 32);
21293 VEC_safe_push (die_arg_entry
, gc
,
21294 tmpl_value_parm_die_table
,
21298 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
21299 by append_entry_to_tmpl_value_parm_die_table. This function must
21300 be called after function DIEs have been generated. */
21303 gen_remaining_tmpl_value_param_die_attribute (void)
21305 if (tmpl_value_parm_die_table
)
21310 FOR_EACH_VEC_ELT (die_arg_entry
, tmpl_value_parm_die_table
, i
, e
)
21311 tree_add_const_value_attribute (e
->die
, e
->arg
);
21316 /* Replace DW_AT_name for the decl with name. */
21319 dwarf2out_set_name (tree decl
, tree name
)
21325 die
= TYPE_SYMTAB_DIE (decl
);
21329 dname
= dwarf2_name (name
, 0);
21333 attr
= get_AT (die
, DW_AT_name
);
21336 struct indirect_string_node
*node
;
21338 node
= find_AT_string (dname
);
21339 /* replace the string. */
21340 attr
->dw_attr_val
.v
.val_str
= node
;
21344 add_name_attribute (die
, dname
);
21347 /* Called by the final INSN scan whenever we see a direct function call.
21348 Make an entry into the direct call table, recording the point of call
21349 and a reference to the target function's debug entry. */
21352 dwarf2out_direct_call (tree targ
)
21355 tree origin
= decl_ultimate_origin (targ
);
21357 /* If this is a clone, use the abstract origin as the target. */
21361 e
.poc_label_num
= poc_label_num
++;
21362 e
.poc_decl
= current_function_decl
;
21363 e
.targ_die
= force_decl_die (targ
);
21364 VEC_safe_push (dcall_entry
, gc
, dcall_table
, &e
);
21366 /* Drop a label at the return point to mark the point of call. */
21367 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LPOC", e
.poc_label_num
);
21370 /* Returns a hash value for X (which really is a struct vcall_insn). */
21373 vcall_insn_table_hash (const void *x
)
21375 return (hashval_t
) ((const struct vcall_insn
*) x
)->insn_uid
;
21378 /* Return nonzero if insn_uid of struct vcall_insn *X is the same as
21379 insnd_uid of *Y. */
21382 vcall_insn_table_eq (const void *x
, const void *y
)
21384 return (((const struct vcall_insn
*) x
)->insn_uid
21385 == ((const struct vcall_insn
*) y
)->insn_uid
);
21388 /* Associate VTABLE_SLOT with INSN_UID in the VCALL_INSN_TABLE. */
21391 store_vcall_insn (unsigned int vtable_slot
, int insn_uid
)
21393 struct vcall_insn
*item
= ggc_alloc_vcall_insn ();
21394 struct vcall_insn
**slot
;
21397 item
->insn_uid
= insn_uid
;
21398 item
->vtable_slot
= vtable_slot
;
21399 slot
= (struct vcall_insn
**)
21400 htab_find_slot_with_hash (vcall_insn_table
, &item
,
21401 (hashval_t
) insn_uid
, INSERT
);
21405 /* Return the VTABLE_SLOT associated with INSN_UID. */
21407 static unsigned int
21408 lookup_vcall_insn (unsigned int insn_uid
)
21410 struct vcall_insn item
;
21411 struct vcall_insn
*p
;
21413 item
.insn_uid
= insn_uid
;
21414 item
.vtable_slot
= 0;
21415 p
= (struct vcall_insn
*) htab_find_with_hash (vcall_insn_table
,
21417 (hashval_t
) insn_uid
);
21419 return (unsigned int) -1;
21420 return p
->vtable_slot
;
21424 /* Called when lowering indirect calls to RTL. We make a note of INSN_UID
21425 and the OBJ_TYPE_REF_TOKEN from ADDR. For C++ virtual calls, the token
21426 is the vtable slot index that we will need to put in the virtual call
21430 dwarf2out_virtual_call_token (tree addr
, int insn_uid
)
21432 if (is_cxx() && TREE_CODE (addr
) == OBJ_TYPE_REF
)
21434 tree token
= OBJ_TYPE_REF_TOKEN (addr
);
21435 if (TREE_CODE (token
) == INTEGER_CST
)
21436 store_vcall_insn (TREE_INT_CST_LOW (token
), insn_uid
);
21440 /* Called when scheduling RTL, when a CALL_INSN is split. Copies the
21441 OBJ_TYPE_REF_TOKEN previously associated with OLD_INSN and associates it
21445 dwarf2out_copy_call_info (rtx old_insn
, rtx new_insn
)
21447 unsigned int vtable_slot
= lookup_vcall_insn (INSN_UID (old_insn
));
21449 if (vtable_slot
!= (unsigned int) -1)
21450 store_vcall_insn (vtable_slot
, INSN_UID (new_insn
));
21453 /* Called by the final INSN scan whenever we see a virtual function call.
21454 Make an entry into the virtual call table, recording the point of call
21455 and the slot index of the vtable entry used to call the virtual member
21456 function. The slot index was associated with the INSN_UID during the
21457 lowering to RTL. */
21460 dwarf2out_virtual_call (int insn_uid
)
21462 unsigned int vtable_slot
= lookup_vcall_insn (insn_uid
);
21465 if (vtable_slot
== (unsigned int) -1)
21468 e
.poc_label_num
= poc_label_num
++;
21469 e
.vtable_slot
= vtable_slot
;
21470 VEC_safe_push (vcall_entry
, gc
, vcall_table
, &e
);
21472 /* Drop a label at the return point to mark the point of call. */
21473 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LPOC", e
.poc_label_num
);
21476 /* Called by the final INSN scan whenever we see a var location. We
21477 use it to drop labels in the right places, and throw the location in
21478 our lookup table. */
21481 dwarf2out_var_location (rtx loc_note
)
21483 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
21484 struct var_loc_node
*newloc
;
21486 static const char *last_label
;
21487 static const char *last_postcall_label
;
21488 static bool last_in_cold_section_p
;
21491 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
21494 next_real
= next_real_insn (loc_note
);
21495 /* If there are no instructions which would be affected by this note,
21496 don't do anything. */
21497 if (next_real
== NULL_RTX
&& !NOTE_DURING_CALL_P (loc_note
))
21500 /* If there were any real insns between note we processed last time
21501 and this note (or if it is the first note), clear
21502 last_{,postcall_}label so that they are not reused this time. */
21503 if (last_var_location_insn
== NULL_RTX
21504 || last_var_location_insn
!= next_real
21505 || last_in_cold_section_p
!= in_cold_section_p
)
21508 last_postcall_label
= NULL
;
21511 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
21512 newloc
= add_var_loc_to_decl (decl
, loc_note
,
21513 NOTE_DURING_CALL_P (loc_note
)
21514 ? last_postcall_label
: last_label
);
21515 if (newloc
== NULL
)
21518 /* If there were no real insns between note we processed last time
21519 and this note, use the label we emitted last time. Otherwise
21520 create a new label and emit it. */
21521 if (last_label
== NULL
)
21523 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
21524 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
21526 last_label
= ggc_strdup (loclabel
);
21529 if (!NOTE_DURING_CALL_P (loc_note
))
21530 newloc
->label
= last_label
;
21533 if (!last_postcall_label
)
21535 sprintf (loclabel
, "%s-1", last_label
);
21536 last_postcall_label
= ggc_strdup (loclabel
);
21538 newloc
->label
= last_postcall_label
;
21541 last_var_location_insn
= next_real
;
21542 last_in_cold_section_p
= in_cold_section_p
;
21545 /* We need to reset the locations at the beginning of each
21546 function. We can't do this in the end_function hook, because the
21547 declarations that use the locations won't have been output when
21548 that hook is called. Also compute have_multiple_function_sections here. */
21551 dwarf2out_begin_function (tree fun
)
21553 if (function_section (fun
) != text_section
)
21554 have_multiple_function_sections
= true;
21556 dwarf2out_note_section_used ();
21559 /* Output a label to mark the beginning of a source code line entry
21560 and record information relating to this source line, in
21561 'line_info_table' for later output of the .debug_line section. */
21564 dwarf2out_source_line (unsigned int line
, const char *filename
,
21565 int discriminator
, bool is_stmt
)
21567 static bool last_is_stmt
= true;
21569 if (debug_info_level
>= DINFO_LEVEL_NORMAL
21572 int file_num
= maybe_emit_file (lookup_filename (filename
));
21574 switch_to_section (current_function_section ());
21576 /* If requested, emit something human-readable. */
21577 if (flag_debug_asm
)
21578 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
21581 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21583 /* Emit the .loc directive understood by GNU as. */
21584 fprintf (asm_out_file
, "\t.loc %d %d 0", file_num
, line
);
21585 if (is_stmt
!= last_is_stmt
)
21587 fprintf (asm_out_file
, " is_stmt %d", is_stmt
? 1 : 0);
21588 last_is_stmt
= is_stmt
;
21590 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
21591 fprintf (asm_out_file
, " discriminator %d", discriminator
);
21592 fputc ('\n', asm_out_file
);
21594 /* Indicate that line number info exists. */
21595 line_info_table_in_use
++;
21597 else if (function_section (current_function_decl
) != text_section
)
21599 dw_separate_line_info_ref line_info
;
21600 targetm
.asm_out
.internal_label (asm_out_file
,
21601 SEPARATE_LINE_CODE_LABEL
,
21602 separate_line_info_table_in_use
);
21604 /* Expand the line info table if necessary. */
21605 if (separate_line_info_table_in_use
21606 == separate_line_info_table_allocated
)
21608 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
21609 separate_line_info_table
21610 = GGC_RESIZEVEC (dw_separate_line_info_entry
,
21611 separate_line_info_table
,
21612 separate_line_info_table_allocated
);
21613 memset (separate_line_info_table
21614 + separate_line_info_table_in_use
,
21616 (LINE_INFO_TABLE_INCREMENT
21617 * sizeof (dw_separate_line_info_entry
)));
21620 /* Add the new entry at the end of the line_info_table. */
21622 = &separate_line_info_table
[separate_line_info_table_in_use
++];
21623 line_info
->dw_file_num
= file_num
;
21624 line_info
->dw_line_num
= line
;
21625 line_info
->function
= current_function_funcdef_no
;
21629 dw_line_info_ref line_info
;
21631 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
,
21632 line_info_table_in_use
);
21634 /* Expand the line info table if necessary. */
21635 if (line_info_table_in_use
== line_info_table_allocated
)
21637 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
21639 = GGC_RESIZEVEC (dw_line_info_entry
, line_info_table
,
21640 line_info_table_allocated
);
21641 memset (line_info_table
+ line_info_table_in_use
, 0,
21642 LINE_INFO_TABLE_INCREMENT
* sizeof (dw_line_info_entry
));
21645 /* Add the new entry at the end of the line_info_table. */
21646 line_info
= &line_info_table
[line_info_table_in_use
++];
21647 line_info
->dw_file_num
= file_num
;
21648 line_info
->dw_line_num
= line
;
21653 /* Record the beginning of a new source file. */
21656 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21658 if (flag_eliminate_dwarf2_dups
&& dwarf_version
< 4)
21660 /* Record the beginning of the file for break_out_includes. */
21661 dw_die_ref bincl_die
;
21663 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
21664 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21667 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21669 int file_num
= maybe_emit_file (lookup_filename (filename
));
21671 switch_to_section (debug_macinfo_section
);
21672 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
21673 dw2_asm_output_data_uleb128 (lineno
, "Included from line number %d",
21676 dw2_asm_output_data_uleb128 (file_num
, "file %s", filename
);
21680 /* Record the end of a source file. */
21683 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21685 if (flag_eliminate_dwarf2_dups
&& dwarf_version
< 4)
21686 /* Record the end of the file for break_out_includes. */
21687 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
21689 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21691 switch_to_section (debug_macinfo_section
);
21692 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
21696 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21697 the tail part of the directive line, i.e. the part which is past the
21698 initial whitespace, #, whitespace, directive-name, whitespace part. */
21701 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
21702 const char *buffer ATTRIBUTE_UNUSED
)
21704 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21706 switch_to_section (debug_macinfo_section
);
21707 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
21708 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
21709 dw2_asm_output_nstring (buffer
, -1, "The macro");
21713 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21714 the tail part of the directive line, i.e. the part which is past the
21715 initial whitespace, #, whitespace, directive-name, whitespace part. */
21718 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21719 const char *buffer ATTRIBUTE_UNUSED
)
21721 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21723 switch_to_section (debug_macinfo_section
);
21724 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
21725 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
21726 dw2_asm_output_nstring (buffer
, -1, "The macro");
21730 /* Set up for Dwarf output at the start of compilation. */
21733 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
21735 /* Allocate the file_table. */
21736 file_table
= htab_create_ggc (50, file_table_hash
,
21737 file_table_eq
, NULL
);
21739 /* Allocate the decl_die_table. */
21740 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
21741 decl_die_table_eq
, NULL
);
21743 /* Allocate the decl_loc_table. */
21744 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
21745 decl_loc_table_eq
, NULL
);
21747 /* Allocate the initial hunk of the decl_scope_table. */
21748 decl_scope_table
= VEC_alloc (tree
, gc
, 256);
21750 /* Allocate the initial hunk of the abbrev_die_table. */
21751 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
21752 (ABBREV_DIE_TABLE_INCREMENT
);
21753 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
21754 /* Zero-th entry is allocated, but unused. */
21755 abbrev_die_table_in_use
= 1;
21757 /* Allocate the initial hunk of the line_info_table. */
21758 line_info_table
= ggc_alloc_cleared_vec_dw_line_info_entry
21759 (LINE_INFO_TABLE_INCREMENT
);
21760 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
21762 /* Zero-th entry is allocated, but unused. */
21763 line_info_table_in_use
= 1;
21765 /* Allocate the pubtypes and pubnames vectors. */
21766 pubname_table
= VEC_alloc (pubname_entry
, gc
, 32);
21767 pubtype_table
= VEC_alloc (pubname_entry
, gc
, 32);
21769 /* Allocate the table that maps insn UIDs to vtable slot indexes. */
21770 vcall_insn_table
= htab_create_ggc (10, vcall_insn_table_hash
,
21771 vcall_insn_table_eq
, NULL
);
21773 incomplete_types
= VEC_alloc (tree
, gc
, 64);
21775 used_rtx_array
= VEC_alloc (rtx
, gc
, 32);
21777 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
21778 SECTION_DEBUG
, NULL
);
21779 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21780 SECTION_DEBUG
, NULL
);
21781 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
21782 SECTION_DEBUG
, NULL
);
21783 debug_macinfo_section
= get_section (DEBUG_MACINFO_SECTION
,
21784 SECTION_DEBUG
, NULL
);
21785 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
21786 SECTION_DEBUG
, NULL
);
21787 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
21788 SECTION_DEBUG
, NULL
);
21789 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
21790 SECTION_DEBUG
, NULL
);
21791 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
21792 SECTION_DEBUG
, NULL
);
21793 debug_dcall_section
= get_section (DEBUG_DCALL_SECTION
,
21794 SECTION_DEBUG
, NULL
);
21795 debug_vcall_section
= get_section (DEBUG_VCALL_SECTION
,
21796 SECTION_DEBUG
, NULL
);
21797 debug_str_section
= get_section (DEBUG_STR_SECTION
,
21798 DEBUG_STR_SECTION_FLAGS
, NULL
);
21799 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
21800 SECTION_DEBUG
, NULL
);
21801 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
21802 SECTION_DEBUG
, NULL
);
21804 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
21805 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
21806 DEBUG_ABBREV_SECTION_LABEL
, 0);
21807 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
21808 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
21809 COLD_TEXT_SECTION_LABEL
, 0);
21810 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
21812 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
21813 DEBUG_INFO_SECTION_LABEL
, 0);
21814 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
21815 DEBUG_LINE_SECTION_LABEL
, 0);
21816 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
21817 DEBUG_RANGES_SECTION_LABEL
, 0);
21818 switch_to_section (debug_abbrev_section
);
21819 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
21820 switch_to_section (debug_info_section
);
21821 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
21822 switch_to_section (debug_line_section
);
21823 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
21825 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21827 switch_to_section (debug_macinfo_section
);
21828 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
21829 DEBUG_MACINFO_SECTION_LABEL
, 0);
21830 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
21833 switch_to_section (text_section
);
21834 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
21835 if (flag_reorder_blocks_and_partition
)
21837 cold_text_section
= unlikely_text_section ();
21838 switch_to_section (cold_text_section
);
21839 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
21844 /* Called before cgraph_optimize starts outputtting functions, variables
21845 and toplevel asms into assembly. */
21848 dwarf2out_assembly_start (void)
21850 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
21851 && dwarf2out_do_cfi_asm ()
21852 && (!(flag_unwind_tables
|| flag_exceptions
)
21853 || targetm
.except_unwind_info () != UI_DWARF2
))
21854 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
21857 /* A helper function for dwarf2out_finish called through
21858 htab_traverse. Emit one queued .debug_str string. */
21861 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
21863 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21865 if (node
->label
&& node
->refcount
)
21867 switch_to_section (debug_str_section
);
21868 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
21869 assemble_string (node
->str
, strlen (node
->str
) + 1);
21875 #if ENABLE_ASSERT_CHECKING
21876 /* Verify that all marks are clear. */
21879 verify_marks_clear (dw_die_ref die
)
21883 gcc_assert (! die
->die_mark
);
21884 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
21886 #endif /* ENABLE_ASSERT_CHECKING */
21888 /* Clear the marks for a die and its children.
21889 Be cool if the mark isn't set. */
21892 prune_unmark_dies (dw_die_ref die
)
21898 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
21901 /* Given DIE that we're marking as used, find any other dies
21902 it references as attributes and mark them as used. */
21905 prune_unused_types_walk_attribs (dw_die_ref die
)
21910 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
21912 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
21914 /* A reference to another DIE.
21915 Make sure that it will get emitted.
21916 If it was broken out into a comdat group, don't follow it. */
21917 if (dwarf_version
< 4
21918 || a
->dw_attr
== DW_AT_specification
21919 || a
->dw_attr_val
.v
.val_die_ref
.die
->die_id
.die_type_node
== NULL
)
21920 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
21922 /* Set the string's refcount to 0 so that prune_unused_types_mark
21923 accounts properly for it. */
21924 if (AT_class (a
) == dw_val_class_str
)
21925 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
21930 /* Mark DIE as being used. If DOKIDS is true, then walk down
21931 to DIE's children. */
21934 prune_unused_types_mark (dw_die_ref die
, int dokids
)
21938 if (die
->die_mark
== 0)
21940 /* We haven't done this node yet. Mark it as used. */
21943 /* We also have to mark its parents as used.
21944 (But we don't want to mark our parents' kids due to this.) */
21945 if (die
->die_parent
)
21946 prune_unused_types_mark (die
->die_parent
, 0);
21948 /* Mark any referenced nodes. */
21949 prune_unused_types_walk_attribs (die
);
21951 /* If this node is a specification,
21952 also mark the definition, if it exists. */
21953 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
21954 prune_unused_types_mark (die
->die_definition
, 1);
21957 if (dokids
&& die
->die_mark
!= 2)
21959 /* We need to walk the children, but haven't done so yet.
21960 Remember that we've walked the kids. */
21963 /* If this is an array type, we need to make sure our
21964 kids get marked, even if they're types. If we're
21965 breaking out types into comdat sections, do this
21966 for all type definitions. */
21967 if (die
->die_tag
== DW_TAG_array_type
21968 || (dwarf_version
>= 4
21969 && is_type_die (die
) && ! is_declaration_die (die
)))
21970 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
21972 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
21976 /* For local classes, look if any static member functions were emitted
21977 and if so, mark them. */
21980 prune_unused_types_walk_local_classes (dw_die_ref die
)
21984 if (die
->die_mark
== 2)
21987 switch (die
->die_tag
)
21989 case DW_TAG_structure_type
:
21990 case DW_TAG_union_type
:
21991 case DW_TAG_class_type
:
21994 case DW_TAG_subprogram
:
21995 if (!get_AT_flag (die
, DW_AT_declaration
)
21996 || die
->die_definition
!= NULL
)
21997 prune_unused_types_mark (die
, 1);
22004 /* Mark children. */
22005 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
22008 /* Walk the tree DIE and mark types that we actually use. */
22011 prune_unused_types_walk (dw_die_ref die
)
22015 /* Don't do anything if this node is already marked and
22016 children have been marked as well. */
22017 if (die
->die_mark
== 2)
22020 switch (die
->die_tag
)
22022 case DW_TAG_structure_type
:
22023 case DW_TAG_union_type
:
22024 case DW_TAG_class_type
:
22025 if (die
->die_perennial_p
)
22028 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
22029 if (c
->die_tag
== DW_TAG_subprogram
)
22032 /* Finding used static member functions inside of classes
22033 is needed just for local classes, because for other classes
22034 static member function DIEs with DW_AT_specification
22035 are emitted outside of the DW_TAG_*_type. If we ever change
22036 it, we'd need to call this even for non-local classes. */
22038 prune_unused_types_walk_local_classes (die
);
22040 /* It's a type node --- don't mark it. */
22043 case DW_TAG_const_type
:
22044 case DW_TAG_packed_type
:
22045 case DW_TAG_pointer_type
:
22046 case DW_TAG_reference_type
:
22047 case DW_TAG_rvalue_reference_type
:
22048 case DW_TAG_volatile_type
:
22049 case DW_TAG_typedef
:
22050 case DW_TAG_array_type
:
22051 case DW_TAG_interface_type
:
22052 case DW_TAG_friend
:
22053 case DW_TAG_variant_part
:
22054 case DW_TAG_enumeration_type
:
22055 case DW_TAG_subroutine_type
:
22056 case DW_TAG_string_type
:
22057 case DW_TAG_set_type
:
22058 case DW_TAG_subrange_type
:
22059 case DW_TAG_ptr_to_member_type
:
22060 case DW_TAG_file_type
:
22061 if (die
->die_perennial_p
)
22064 /* It's a type node --- don't mark it. */
22068 /* Mark everything else. */
22072 if (die
->die_mark
== 0)
22076 /* Now, mark any dies referenced from here. */
22077 prune_unused_types_walk_attribs (die
);
22082 /* Mark children. */
22083 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22086 /* Increment the string counts on strings referred to from DIE's
22090 prune_unused_types_update_strings (dw_die_ref die
)
22095 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
22096 if (AT_class (a
) == dw_val_class_str
)
22098 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22100 /* Avoid unnecessarily putting strings that are used less than
22101 twice in the hash table. */
22103 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22106 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22107 htab_hash_string (s
->str
),
22109 gcc_assert (*slot
== NULL
);
22115 /* Remove from the tree DIE any dies that aren't marked. */
22118 prune_unused_types_prune (dw_die_ref die
)
22122 gcc_assert (die
->die_mark
);
22123 prune_unused_types_update_strings (die
);
22125 if (! die
->die_child
)
22128 c
= die
->die_child
;
22130 dw_die_ref prev
= c
;
22131 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22132 if (c
== die
->die_child
)
22134 /* No marked children between 'prev' and the end of the list. */
22136 /* No marked children at all. */
22137 die
->die_child
= NULL
;
22140 prev
->die_sib
= c
->die_sib
;
22141 die
->die_child
= prev
;
22146 if (c
!= prev
->die_sib
)
22148 prune_unused_types_prune (c
);
22149 } while (c
!= die
->die_child
);
22152 /* A helper function for dwarf2out_finish called through
22153 htab_traverse. Clear .debug_str strings that we haven't already
22154 decided to emit. */
22157 prune_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
22159 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22161 if (!node
->label
|| !node
->refcount
)
22162 htab_clear_slot (debug_str_hash
, h
);
22167 /* Remove dies representing declarations that we never use. */
22170 prune_unused_types (void)
22173 limbo_die_node
*node
;
22174 comdat_type_node
*ctnode
;
22176 dcall_entry
*dcall
;
22178 #if ENABLE_ASSERT_CHECKING
22179 /* All the marks should already be clear. */
22180 verify_marks_clear (comp_unit_die ());
22181 for (node
= limbo_die_list
; node
; node
= node
->next
)
22182 verify_marks_clear (node
->die
);
22183 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22184 verify_marks_clear (ctnode
->root_die
);
22185 #endif /* ENABLE_ASSERT_CHECKING */
22187 /* Mark types that are used in global variables. */
22188 premark_types_used_by_global_vars ();
22190 /* Set the mark on nodes that are actually used. */
22191 prune_unused_types_walk (comp_unit_die ());
22192 for (node
= limbo_die_list
; node
; node
= node
->next
)
22193 prune_unused_types_walk (node
->die
);
22194 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22196 prune_unused_types_walk (ctnode
->root_die
);
22197 prune_unused_types_mark (ctnode
->type_die
, 1);
22200 /* Also set the mark on nodes referenced from the
22201 pubname_table or arange_table. */
22202 FOR_EACH_VEC_ELT (pubname_entry
, pubname_table
, i
, pub
)
22203 prune_unused_types_mark (pub
->die
, 1);
22204 for (i
= 0; i
< arange_table_in_use
; i
++)
22205 prune_unused_types_mark (arange_table
[i
], 1);
22207 /* Mark nodes referenced from the direct call table. */
22208 FOR_EACH_VEC_ELT (dcall_entry
, dcall_table
, i
, dcall
)
22209 prune_unused_types_mark (dcall
->targ_die
, 1);
22211 /* Get rid of nodes that aren't marked; and update the string counts. */
22212 if (debug_str_hash
&& debug_str_hash_forced
)
22213 htab_traverse (debug_str_hash
, prune_indirect_string
, NULL
);
22214 else if (debug_str_hash
)
22215 htab_empty (debug_str_hash
);
22216 prune_unused_types_prune (comp_unit_die ());
22217 for (node
= limbo_die_list
; node
; node
= node
->next
)
22218 prune_unused_types_prune (node
->die
);
22219 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22220 prune_unused_types_prune (ctnode
->root_die
);
22222 /* Leave the marks clear. */
22223 prune_unmark_dies (comp_unit_die ());
22224 for (node
= limbo_die_list
; node
; node
= node
->next
)
22225 prune_unmark_dies (node
->die
);
22226 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22227 prune_unmark_dies (ctnode
->root_die
);
22230 /* Set the parameter to true if there are any relative pathnames in
22233 file_table_relative_p (void ** slot
, void *param
)
22235 bool *p
= (bool *) param
;
22236 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22237 if (!IS_ABSOLUTE_PATH (d
->filename
))
22245 /* Routines to manipulate hash table of comdat type units. */
22248 htab_ct_hash (const void *of
)
22251 const comdat_type_node
*const type_node
= (const comdat_type_node
*) of
;
22253 memcpy (&h
, type_node
->signature
, sizeof (h
));
22258 htab_ct_eq (const void *of1
, const void *of2
)
22260 const comdat_type_node
*const type_node_1
= (const comdat_type_node
*) of1
;
22261 const comdat_type_node
*const type_node_2
= (const comdat_type_node
*) of2
;
22263 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22264 DWARF_TYPE_SIGNATURE_SIZE
));
22267 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22268 to the location it would have been added, should we know its
22269 DECL_ASSEMBLER_NAME when we added other attributes. This will
22270 probably improve compactness of debug info, removing equivalent
22271 abbrevs, and hide any differences caused by deferring the
22272 computation of the assembler name, triggered by e.g. PCH. */
22275 move_linkage_attr (dw_die_ref die
)
22277 unsigned ix
= VEC_length (dw_attr_node
, die
->die_attr
);
22278 dw_attr_node linkage
= *VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
22280 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22281 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22285 dw_attr_node
*prev
= VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
22287 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22291 if (ix
!= VEC_length (dw_attr_node
, die
->die_attr
) - 1)
22293 VEC_pop (dw_attr_node
, die
->die_attr
);
22294 VEC_quick_insert (dw_attr_node
, die
->die_attr
, ix
, &linkage
);
22298 /* Helper function for resolve_addr, attempt to resolve
22299 one CONST_STRING, return non-zero if not successful. Similarly verify that
22300 SYMBOL_REFs refer to variables emitted in the current CU. */
22303 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
22307 if (GET_CODE (rtl
) == CONST_STRING
)
22309 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22310 tree t
= build_string (len
, XSTR (rtl
, 0));
22311 tree tlen
= build_int_cst (NULL_TREE
, len
- 1);
22313 = build_array_type (char_type_node
, build_index_type (tlen
));
22314 rtl
= lookup_constant_def (t
);
22315 if (!rtl
|| !MEM_P (rtl
))
22317 rtl
= XEXP (rtl
, 0);
22318 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
22323 if (GET_CODE (rtl
) == SYMBOL_REF
22324 && SYMBOL_REF_DECL (rtl
)
22325 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22328 if (GET_CODE (rtl
) == CONST
22329 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
22335 /* Helper function for resolve_addr, handle one location
22336 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22337 the location list couldn't be resolved. */
22340 resolve_addr_in_expr (dw_loc_descr_ref loc
)
22342 for (; loc
; loc
= loc
->dw_loc_next
)
22343 if (((loc
->dw_loc_opc
== DW_OP_addr
|| loc
->dtprel
)
22344 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22345 || (loc
->dw_loc_opc
== DW_OP_implicit_value
22346 && loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
22347 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
)))
22349 else if (loc
->dw_loc_opc
== DW_OP_GNU_implicit_pointer
22350 && loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
22353 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
22356 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22357 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22358 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22363 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
22364 an address in .rodata section if the string literal is emitted there,
22365 or remove the containing location list or replace DW_AT_const_value
22366 with DW_AT_location and empty location expression, if it isn't found
22367 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
22368 to something that has been emitted in the current CU. */
22371 resolve_addr (dw_die_ref die
)
22375 dw_loc_list_ref
*curr
;
22378 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
22379 switch (AT_class (a
))
22381 case dw_val_class_loc_list
:
22382 curr
= AT_loc_list_ptr (a
);
22385 if (!resolve_addr_in_expr ((*curr
)->expr
))
22387 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
22388 if (next
&& (*curr
)->ll_symbol
)
22390 gcc_assert (!next
->ll_symbol
);
22391 next
->ll_symbol
= (*curr
)->ll_symbol
;
22396 curr
= &(*curr
)->dw_loc_next
;
22398 if (!AT_loc_list (a
))
22400 remove_AT (die
, a
->dw_attr
);
22404 case dw_val_class_loc
:
22405 if (!resolve_addr_in_expr (AT_loc (a
)))
22407 remove_AT (die
, a
->dw_attr
);
22411 case dw_val_class_addr
:
22412 if (a
->dw_attr
== DW_AT_const_value
22413 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
22415 remove_AT (die
, a
->dw_attr
);
22423 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
22426 /* Helper routines for optimize_location_lists.
22427 This pass tries to share identical local lists in .debug_loc
22430 /* Iteratively hash operands of LOC opcode. */
22432 static inline hashval_t
22433 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
22435 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
22436 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
22438 switch (loc
->dw_loc_opc
)
22440 case DW_OP_const4u
:
22441 case DW_OP_const8u
:
22445 case DW_OP_const1u
:
22446 case DW_OP_const1s
:
22447 case DW_OP_const2u
:
22448 case DW_OP_const2s
:
22449 case DW_OP_const4s
:
22450 case DW_OP_const8s
:
22454 case DW_OP_plus_uconst
:
22490 case DW_OP_deref_size
:
22491 case DW_OP_xderef_size
:
22492 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
22499 gcc_assert (val1
->val_class
== dw_val_class_loc
);
22500 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
22501 hash
= iterative_hash_object (offset
, hash
);
22504 case DW_OP_implicit_value
:
22505 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
22506 switch (val2
->val_class
)
22508 case dw_val_class_const
:
22509 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22511 case dw_val_class_vec
:
22513 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
22514 unsigned int len
= val2
->v
.val_vec
.length
;
22516 hash
= iterative_hash_object (elt_size
, hash
);
22517 hash
= iterative_hash_object (len
, hash
);
22518 hash
= iterative_hash (val2
->v
.val_vec
.array
,
22519 len
* elt_size
, hash
);
22522 case dw_val_class_const_double
:
22523 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
22524 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
22526 case dw_val_class_addr
:
22527 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
22530 gcc_unreachable ();
22534 case DW_OP_bit_piece
:
22535 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
22536 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22542 unsigned char dtprel
= 0xd1;
22543 hash
= iterative_hash_object (dtprel
, hash
);
22545 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
22547 case DW_OP_GNU_implicit_pointer
:
22548 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22552 /* Other codes have no operands. */
22558 /* Iteratively hash the whole DWARF location expression LOC. */
22560 static inline hashval_t
22561 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
22563 dw_loc_descr_ref l
;
22564 bool sizes_computed
= false;
22565 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
22566 size_of_locs (loc
);
22568 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
22570 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
22571 hash
= iterative_hash_object (opc
, hash
);
22572 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
22574 size_of_locs (loc
);
22575 sizes_computed
= true;
22577 hash
= hash_loc_operands (l
, hash
);
22582 /* Compute hash of the whole location list LIST_HEAD. */
22585 hash_loc_list (dw_loc_list_ref list_head
)
22587 dw_loc_list_ref curr
= list_head
;
22588 hashval_t hash
= 0;
22590 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
22592 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
22593 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
22595 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
22597 hash
= hash_locs (curr
->expr
, hash
);
22599 list_head
->hash
= hash
;
22602 /* Return true if X and Y opcodes have the same operands. */
22605 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
22607 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
22608 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
22609 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
22610 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
22612 switch (x
->dw_loc_opc
)
22614 case DW_OP_const4u
:
22615 case DW_OP_const8u
:
22619 case DW_OP_const1u
:
22620 case DW_OP_const1s
:
22621 case DW_OP_const2u
:
22622 case DW_OP_const2s
:
22623 case DW_OP_const4s
:
22624 case DW_OP_const8s
:
22628 case DW_OP_plus_uconst
:
22664 case DW_OP_deref_size
:
22665 case DW_OP_xderef_size
:
22666 return valx1
->v
.val_int
== valy1
->v
.val_int
;
22669 gcc_assert (valx1
->val_class
== dw_val_class_loc
22670 && valy1
->val_class
== dw_val_class_loc
22671 && x
->dw_loc_addr
== y
->dw_loc_addr
);
22672 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
22673 case DW_OP_implicit_value
:
22674 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
22675 || valx2
->val_class
!= valy2
->val_class
)
22677 switch (valx2
->val_class
)
22679 case dw_val_class_const
:
22680 return valx2
->v
.val_int
== valy2
->v
.val_int
;
22681 case dw_val_class_vec
:
22682 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
22683 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
22684 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
22685 valx2
->v
.val_vec
.elt_size
22686 * valx2
->v
.val_vec
.length
) == 0;
22687 case dw_val_class_const_double
:
22688 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
22689 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
22690 case dw_val_class_addr
:
22691 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
22693 gcc_unreachable ();
22696 case DW_OP_bit_piece
:
22697 return valx1
->v
.val_int
== valy1
->v
.val_int
22698 && valx2
->v
.val_int
== valy2
->v
.val_int
;
22701 return rtx_equal_p (valx1
->v
.val_addr
, valx2
->v
.val_addr
);
22702 case DW_OP_GNU_implicit_pointer
:
22703 return valx1
->val_class
== dw_val_class_die_ref
22704 && valx1
->val_class
== valy1
->val_class
22705 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
22706 && valx2
->v
.val_int
== valy2
->v
.val_int
;
22708 /* Other codes have no operands. */
22713 /* Return true if DWARF location expressions X and Y are the same. */
22716 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
22718 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
22719 if (x
->dw_loc_opc
!= y
->dw_loc_opc
22720 || x
->dtprel
!= y
->dtprel
22721 || !compare_loc_operands (x
, y
))
22723 return x
== NULL
&& y
== NULL
;
22726 /* Return precomputed hash of location list X. */
22729 loc_list_hash (const void *x
)
22731 return ((const struct dw_loc_list_struct
*) x
)->hash
;
22734 /* Return 1 if location lists X and Y are the same. */
22737 loc_list_eq (const void *x
, const void *y
)
22739 const struct dw_loc_list_struct
*a
= (const struct dw_loc_list_struct
*) x
;
22740 const struct dw_loc_list_struct
*b
= (const struct dw_loc_list_struct
*) y
;
22743 if (a
->hash
!= b
->hash
)
22745 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
22746 if (strcmp (a
->begin
, b
->begin
) != 0
22747 || strcmp (a
->end
, b
->end
) != 0
22748 || (a
->section
== NULL
) != (b
->section
== NULL
)
22749 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
22750 || !compare_locs (a
->expr
, b
->expr
))
22752 return a
== NULL
&& b
== NULL
;
22755 /* Recursively optimize location lists referenced from DIE
22756 children and share them whenever possible. */
22759 optimize_location_lists_1 (dw_die_ref die
, htab_t htab
)
22766 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
22767 if (AT_class (a
) == dw_val_class_loc_list
)
22769 dw_loc_list_ref list
= AT_loc_list (a
);
22770 /* TODO: perform some optimizations here, before hashing
22771 it and storing into the hash table. */
22772 hash_loc_list (list
);
22773 slot
= htab_find_slot_with_hash (htab
, list
, list
->hash
,
22776 *slot
= (void *) list
;
22778 a
->dw_attr_val
.v
.val_loc_list
= (dw_loc_list_ref
) *slot
;
22781 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
22784 /* Optimize location lists referenced from DIE
22785 children and share them whenever possible. */
22788 optimize_location_lists (dw_die_ref die
)
22790 htab_t htab
= htab_create (500, loc_list_hash
, loc_list_eq
, NULL
);
22791 optimize_location_lists_1 (die
, htab
);
22792 htab_delete (htab
);
22795 /* Output stuff that dwarf requires at the end of every file,
22796 and generate the DWARF-2 debugging info. */
22799 dwarf2out_finish (const char *filename
)
22801 limbo_die_node
*node
, *next_node
;
22802 comdat_type_node
*ctnode
;
22803 htab_t comdat_type_table
;
22804 dw_die_ref die
= 0;
22807 gen_remaining_tmpl_value_param_die_attribute ();
22809 /* Add the name for the main input file now. We delayed this from
22810 dwarf2out_init to avoid complications with PCH. */
22811 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
22812 if (!IS_ABSOLUTE_PATH (filename
))
22813 add_comp_dir_attribute (comp_unit_die ());
22814 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
22817 htab_traverse (file_table
, file_table_relative_p
, &p
);
22819 add_comp_dir_attribute (comp_unit_die ());
22822 for (i
= 0; i
< VEC_length (deferred_locations
, deferred_locations_list
); i
++)
22824 add_location_or_const_value_attribute (
22825 VEC_index (deferred_locations
, deferred_locations_list
, i
)->die
,
22826 VEC_index (deferred_locations
, deferred_locations_list
, i
)->variable
,
22830 /* Traverse the limbo die list, and add parent/child links. The only
22831 dies without parents that should be here are concrete instances of
22832 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
22833 For concrete instances, we can get the parent die from the abstract
22835 for (node
= limbo_die_list
; node
; node
= next_node
)
22837 next_node
= node
->next
;
22840 if (die
->die_parent
== NULL
)
22842 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
22845 add_child_die (origin
->die_parent
, die
);
22846 else if (is_cu_die (die
))
22848 else if (seen_error ())
22849 /* It's OK to be confused by errors in the input. */
22850 add_child_die (comp_unit_die (), die
);
22853 /* In certain situations, the lexical block containing a
22854 nested function can be optimized away, which results
22855 in the nested function die being orphaned. Likewise
22856 with the return type of that nested function. Force
22857 this to be a child of the containing function.
22859 It may happen that even the containing function got fully
22860 inlined and optimized out. In that case we are lost and
22861 assign the empty child. This should not be big issue as
22862 the function is likely unreachable too. */
22863 tree context
= NULL_TREE
;
22865 gcc_assert (node
->created_for
);
22867 if (DECL_P (node
->created_for
))
22868 context
= DECL_CONTEXT (node
->created_for
);
22869 else if (TYPE_P (node
->created_for
))
22870 context
= TYPE_CONTEXT (node
->created_for
);
22872 gcc_assert (context
22873 && (TREE_CODE (context
) == FUNCTION_DECL
22874 || TREE_CODE (context
) == NAMESPACE_DECL
));
22876 origin
= lookup_decl_die (context
);
22878 add_child_die (origin
, die
);
22880 add_child_die (comp_unit_die (), die
);
22885 limbo_die_list
= NULL
;
22887 resolve_addr (comp_unit_die ());
22889 for (node
= deferred_asm_name
; node
; node
= node
->next
)
22891 tree decl
= node
->created_for
;
22892 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
22894 add_linkage_attr (node
->die
, decl
);
22895 move_linkage_attr (node
->die
);
22899 deferred_asm_name
= NULL
;
22901 /* Walk through the list of incomplete types again, trying once more to
22902 emit full debugging info for them. */
22903 retry_incomplete_types ();
22905 if (flag_eliminate_unused_debug_types
)
22906 prune_unused_types ();
22908 /* Generate separate CUs for each of the include files we've seen.
22909 They will go into limbo_die_list. */
22910 if (flag_eliminate_dwarf2_dups
&& dwarf_version
< 4)
22911 break_out_includes (comp_unit_die ());
22913 /* Generate separate COMDAT sections for type DIEs. */
22914 if (dwarf_version
>= 4)
22916 break_out_comdat_types (comp_unit_die ());
22918 /* Each new type_unit DIE was added to the limbo die list when created.
22919 Since these have all been added to comdat_type_list, clear the
22921 limbo_die_list
= NULL
;
22923 /* For each new comdat type unit, copy declarations for incomplete
22924 types to make the new unit self-contained (i.e., no direct
22925 references to the main compile unit). */
22926 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22927 copy_decls_for_unworthy_types (ctnode
->root_die
);
22928 copy_decls_for_unworthy_types (comp_unit_die ());
22930 /* In the process of copying declarations from one unit to another,
22931 we may have left some declarations behind that are no longer
22932 referenced. Prune them. */
22933 prune_unused_types ();
22936 /* Traverse the DIE's and add add sibling attributes to those DIE's
22937 that have children. */
22938 add_sibling_attributes (comp_unit_die ());
22939 for (node
= limbo_die_list
; node
; node
= node
->next
)
22940 add_sibling_attributes (node
->die
);
22941 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22942 add_sibling_attributes (ctnode
->root_die
);
22944 /* Output a terminator label for the .text section. */
22945 switch_to_section (text_section
);
22946 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
22947 if (flag_reorder_blocks_and_partition
)
22949 switch_to_section (unlikely_text_section ());
22950 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
22953 /* We can only use the low/high_pc attributes if all of the code was
22955 if (!have_multiple_function_sections
22956 || !(dwarf_version
>= 3 || !dwarf_strict
))
22958 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc
, text_section_label
);
22959 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc
, text_end_label
);
22964 unsigned fde_idx
= 0;
22965 bool range_list_added
= false;
22967 /* We need to give .debug_loc and .debug_ranges an appropriate
22968 "base address". Use zero so that these addresses become
22969 absolute. Historically, we've emitted the unexpected
22970 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
22971 Emit both to give time for other tools to adapt. */
22972 add_AT_addr (comp_unit_die (), DW_AT_low_pc
, const0_rtx
);
22973 add_AT_addr (comp_unit_die (), DW_AT_entry_pc
, const0_rtx
);
22975 if (text_section_used
)
22976 add_ranges_by_labels (comp_unit_die (), text_section_label
,
22977 text_end_label
, &range_list_added
);
22978 if (flag_reorder_blocks_and_partition
&& cold_text_section_used
)
22979 add_ranges_by_labels (comp_unit_die (), cold_text_section_label
,
22980 cold_end_label
, &range_list_added
);
22982 for (fde_idx
= 0; fde_idx
< fde_table_in_use
; fde_idx
++)
22984 dw_fde_ref fde
= &fde_table
[fde_idx
];
22986 if (fde
->dw_fde_switched_sections
)
22988 if (!fde
->in_std_section
)
22989 add_ranges_by_labels (comp_unit_die (),
22990 fde
->dw_fde_hot_section_label
,
22991 fde
->dw_fde_hot_section_end_label
,
22992 &range_list_added
);
22993 if (!fde
->cold_in_std_section
)
22994 add_ranges_by_labels (comp_unit_die (),
22995 fde
->dw_fde_unlikely_section_label
,
22996 fde
->dw_fde_unlikely_section_end_label
,
22997 &range_list_added
);
22999 else if (!fde
->in_std_section
)
23000 add_ranges_by_labels (comp_unit_die (), fde
->dw_fde_begin
,
23001 fde
->dw_fde_end
, &range_list_added
);
23004 if (range_list_added
)
23008 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23009 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list
,
23010 debug_line_section_label
);
23012 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
23013 add_AT_macptr (comp_unit_die (), DW_AT_macro_info
, macinfo_section_label
);
23015 if (have_location_lists
)
23016 optimize_location_lists (die
);
23018 /* Output all of the compilation units. We put the main one last so that
23019 the offsets are available to output_pubnames. */
23020 for (node
= limbo_die_list
; node
; node
= node
->next
)
23021 output_comp_unit (node
->die
, 0);
23023 comdat_type_table
= htab_create (100, htab_ct_hash
, htab_ct_eq
, NULL
);
23024 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23026 void **slot
= htab_find_slot (comdat_type_table
, ctnode
, INSERT
);
23028 /* Don't output duplicate types. */
23029 if (*slot
!= HTAB_EMPTY_ENTRY
)
23032 /* Add a pointer to the line table for the main compilation unit
23033 so that the debugger can make sense of DW_AT_decl_file
23035 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23036 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
23037 debug_line_section_label
);
23039 output_comdat_type_unit (ctnode
);
23042 htab_delete (comdat_type_table
);
23044 /* Output the main compilation unit if non-empty or if .debug_macinfo
23045 has been emitted. */
23046 output_comp_unit (comp_unit_die (), debug_info_level
>= DINFO_LEVEL_VERBOSE
);
23048 /* Output the abbreviation table. */
23049 switch_to_section (debug_abbrev_section
);
23050 output_abbrev_section ();
23052 /* Output location list section if necessary. */
23053 if (have_location_lists
)
23055 /* Output the location lists info. */
23056 switch_to_section (debug_loc_section
);
23057 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
23058 DEBUG_LOC_SECTION_LABEL
, 0);
23059 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
23060 output_location_lists (die
);
23063 /* Output public names table if necessary. */
23064 if (!VEC_empty (pubname_entry
, pubname_table
))
23066 switch_to_section (debug_pubnames_section
);
23067 output_pubnames (pubname_table
);
23070 /* Output public types table if necessary. */
23071 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
23072 It shouldn't hurt to emit it always, since pure DWARF2 consumers
23073 simply won't look for the section. */
23074 if (!VEC_empty (pubname_entry
, pubtype_table
))
23076 switch_to_section (debug_pubtypes_section
);
23077 output_pubnames (pubtype_table
);
23080 /* Output direct and virtual call tables if necessary. */
23081 if (!VEC_empty (dcall_entry
, dcall_table
))
23083 switch_to_section (debug_dcall_section
);
23084 output_dcall_table ();
23086 if (!VEC_empty (vcall_entry
, vcall_table
))
23088 switch_to_section (debug_vcall_section
);
23089 output_vcall_table ();
23092 /* Output the address range information. We only put functions in the arange
23093 table, so don't write it out if we don't have any. */
23094 if (fde_table_in_use
)
23096 switch_to_section (debug_aranges_section
);
23100 /* Output ranges section if necessary. */
23101 if (ranges_table_in_use
)
23103 switch_to_section (debug_ranges_section
);
23104 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
23108 /* Output the source line correspondence table. We must do this
23109 even if there is no line information. Otherwise, on an empty
23110 translation unit, we will generate a present, but empty,
23111 .debug_info section. IRIX 6.5 `nm' will then complain when
23112 examining the file. This is done late so that any filenames
23113 used by the debug_info section are marked as 'used'. */
23114 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
23116 switch_to_section (debug_line_section
);
23117 output_line_info ();
23120 /* Have to end the macro section. */
23121 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
23123 switch_to_section (debug_macinfo_section
);
23124 dw2_asm_output_data (1, 0, "End compilation unit");
23127 /* If we emitted any DW_FORM_strp form attribute, output the string
23129 if (debug_str_hash
)
23130 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
23133 #include "gt-dwarf2out.h"