1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
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"
95 #include "cfglayout.h"
97 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
98 static rtx last_var_location_insn
;
100 #ifdef VMS_DEBUGGING_INFO
101 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
103 /* Define this macro to be a nonzero value if the directory specifications
104 which are output in the debug info should end with a separator. */
105 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
106 /* Define this macro to evaluate to a nonzero value if GCC should refrain
107 from generating indirect strings in DWARF2 debug information, for instance
108 if your target is stuck with an old version of GDB that is unable to
109 process them properly or uses VMS Debug. */
110 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
112 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
113 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
116 /* ??? Poison these here until it can be done generically. They've been
117 totally replaced in this file; make sure it stays that way. */
118 #undef DWARF2_UNWIND_INFO
119 #undef DWARF2_FRAME_INFO
120 #if (GCC_VERSION >= 3000)
121 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
124 #ifndef INCOMING_RETURN_ADDR_RTX
125 #define INCOMING_RETURN_ADDR_RTX (gcc_unreachable (), NULL_RTX)
128 /* Map register numbers held in the call frame info that gcc has
129 collected using DWARF_FRAME_REGNUM to those that should be output in
130 .debug_frame and .eh_frame. */
131 #ifndef DWARF2_FRAME_REG_OUT
132 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
135 /* Save the result of dwarf2out_do_frame across PCH. */
136 static GTY(()) bool saved_do_cfi_asm
= 0;
138 /* Decide whether we want to emit frame unwind information for the current
142 dwarf2out_do_frame (void)
144 /* We want to emit correct CFA location expressions or lists, so we
145 have to return true if we're going to output debug info, even if
146 we're not going to output frame or unwind info. */
147 if (write_symbols
== DWARF2_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
150 if (saved_do_cfi_asm
)
153 if (targetm
.debug_unwind_info () == UI_DWARF2
)
156 if ((flag_unwind_tables
|| flag_exceptions
)
157 && targetm
.except_unwind_info (&global_options
) == UI_DWARF2
)
163 /* Decide whether to emit frame unwind via assembler directives. */
166 dwarf2out_do_cfi_asm (void)
170 #ifdef MIPS_DEBUGGING_INFO
173 if (saved_do_cfi_asm
)
175 if (!flag_dwarf2_cfi_asm
|| !dwarf2out_do_frame ())
177 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE
)
180 /* Make sure the personality encoding is one the assembler can support.
181 In particular, aligned addresses can't be handled. */
182 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
183 if ((enc
& 0x70) != 0 && (enc
& 0x70) != DW_EH_PE_pcrel
)
185 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
186 if ((enc
& 0x70) != 0 && (enc
& 0x70) != DW_EH_PE_pcrel
)
189 /* If we can't get the assembler to emit only .debug_frame, and we don't need
190 dwarf2 unwind info for exceptions, then emit .debug_frame by hand. */
191 if (!HAVE_GAS_CFI_SECTIONS_DIRECTIVE
192 && !flag_unwind_tables
&& !flag_exceptions
193 && targetm
.except_unwind_info (&global_options
) != UI_DWARF2
)
196 saved_do_cfi_asm
= true;
200 /* The size of the target's pointer type. */
202 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
205 /* Array of RTXes referenced by the debugging information, which therefore
206 must be kept around forever. */
207 static GTY(()) VEC(rtx
,gc
) *used_rtx_array
;
209 /* A pointer to the base of a list of incomplete types which might be
210 completed at some later time. incomplete_types_list needs to be a
211 VEC(tree,gc) because we want to tell the garbage collector about
213 static GTY(()) VEC(tree
,gc
) *incomplete_types
;
215 /* A pointer to the base of a table of references to declaration
216 scopes. This table is a display which tracks the nesting
217 of declaration scopes at the current scope and containing
218 scopes. This table is used to find the proper place to
219 define type declaration DIE's. */
220 static GTY(()) VEC(tree
,gc
) *decl_scope_table
;
222 /* Pointers to various DWARF2 sections. */
223 static GTY(()) section
*debug_info_section
;
224 static GTY(()) section
*debug_abbrev_section
;
225 static GTY(()) section
*debug_aranges_section
;
226 static GTY(()) section
*debug_macinfo_section
;
227 static GTY(()) section
*debug_line_section
;
228 static GTY(()) section
*debug_loc_section
;
229 static GTY(()) section
*debug_pubnames_section
;
230 static GTY(()) section
*debug_pubtypes_section
;
231 static GTY(()) section
*debug_str_section
;
232 static GTY(()) section
*debug_ranges_section
;
233 static GTY(()) section
*debug_frame_section
;
235 /* Personality decl of current unit. Used only when assembler does not support
237 static GTY(()) rtx current_unit_personality
;
239 /* How to start an assembler comment. */
240 #ifndef ASM_COMMENT_START
241 #define ASM_COMMENT_START ";#"
244 typedef struct dw_cfi_struct
*dw_cfi_ref
;
245 typedef struct dw_fde_struct
*dw_fde_ref
;
246 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
248 /* Call frames are described using a sequence of Call Frame
249 Information instructions. The register number, offset
250 and address fields are provided as possible operands;
251 their use is selected by the opcode field. */
253 enum dw_cfi_oprnd_type
{
255 dw_cfi_oprnd_reg_num
,
261 typedef union GTY(()) dw_cfi_oprnd_struct
{
262 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num
;
263 HOST_WIDE_INT
GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset
;
264 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr
;
265 struct dw_loc_descr_struct
* GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc
;
269 typedef struct GTY(()) dw_cfi_struct
{
270 enum dwarf_call_frame_info dw_cfi_opc
;
271 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
273 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
278 DEF_VEC_P (dw_cfi_ref
);
279 DEF_VEC_ALLOC_P (dw_cfi_ref
, heap
);
280 DEF_VEC_ALLOC_P (dw_cfi_ref
, gc
);
282 typedef VEC(dw_cfi_ref
, gc
) *cfi_vec
;
284 /* This is how we define the location of the CFA. We use to handle it
285 as REG + OFFSET all the time, but now it can be more complex.
286 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
287 Instead of passing around REG and OFFSET, we pass a copy
288 of this structure. */
289 typedef struct cfa_loc
{
290 HOST_WIDE_INT offset
;
291 HOST_WIDE_INT base_offset
;
293 BOOL_BITFIELD indirect
: 1; /* 1 if CFA is accessed via a dereference. */
294 BOOL_BITFIELD in_use
: 1; /* 1 if a saved cfa is stored here. */
297 /* All call frame descriptions (FDE's) in the GCC generated DWARF
298 refer to a single Common Information Entry (CIE), defined at
299 the beginning of the .debug_frame section. This use of a single
300 CIE obviates the need to keep track of multiple CIE's
301 in the DWARF generation routines below. */
303 typedef struct GTY(()) dw_fde_struct
{
305 const char *dw_fde_begin
;
306 const char *dw_fde_current_label
;
307 const char *dw_fde_end
;
308 const char *dw_fde_vms_end_prologue
;
309 const char *dw_fde_vms_begin_epilogue
;
310 const char *dw_fde_second_begin
;
311 const char *dw_fde_second_end
;
313 int dw_fde_switch_cfi_index
; /* Last CFI before switching sections. */
314 HOST_WIDE_INT stack_realignment
;
315 unsigned funcdef_number
;
316 /* Dynamic realign argument pointer register. */
317 unsigned int drap_reg
;
318 /* Virtual dynamic realign argument pointer register. */
319 unsigned int vdrap_reg
;
320 /* These 3 flags are copied from rtl_data in function.h. */
321 unsigned all_throwers_are_sibcalls
: 1;
322 unsigned uses_eh_lsda
: 1;
323 unsigned nothrow
: 1;
324 /* Whether we did stack realign in this call frame. */
325 unsigned stack_realign
: 1;
326 /* Whether dynamic realign argument pointer register has been saved. */
327 unsigned drap_reg_saved
: 1;
328 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
329 unsigned in_std_section
: 1;
330 /* True iff dw_fde_second_begin label is in text_section or
331 cold_text_section. */
332 unsigned second_in_std_section
: 1;
336 /* Maximum size (in bytes) of an artificially generated label. */
337 #define MAX_ARTIFICIAL_LABEL_BYTES 30
339 /* The size of addresses as they appear in the Dwarf 2 data.
340 Some architectures use word addresses to refer to code locations,
341 but Dwarf 2 info always uses byte addresses. On such machines,
342 Dwarf 2 addresses need to be larger than the architecture's
344 #ifndef DWARF2_ADDR_SIZE
345 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
348 /* The size in bytes of a DWARF field indicating an offset or length
349 relative to a debug info section, specified to be 4 bytes in the
350 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
353 #ifndef DWARF_OFFSET_SIZE
354 #define DWARF_OFFSET_SIZE 4
357 /* The size in bytes of a DWARF 4 type signature. */
359 #ifndef DWARF_TYPE_SIGNATURE_SIZE
360 #define DWARF_TYPE_SIGNATURE_SIZE 8
363 /* According to the (draft) DWARF 3 specification, the initial length
364 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
365 bytes are 0xffffffff, followed by the length stored in the next 8
368 However, the SGI/MIPS ABI uses an initial length which is equal to
369 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
371 #ifndef DWARF_INITIAL_LENGTH_SIZE
372 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
375 /* Round SIZE up to the nearest BOUNDARY. */
376 #define DWARF_ROUND(SIZE,BOUNDARY) \
377 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
379 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
380 #ifndef DWARF_CIE_DATA_ALIGNMENT
381 #ifdef STACK_GROWS_DOWNWARD
382 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
384 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
388 /* CIE identifier. */
389 #if HOST_BITS_PER_WIDE_INT >= 64
390 #define DWARF_CIE_ID \
391 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
393 #define DWARF_CIE_ID DW_CIE_ID
396 /* A pointer to the base of a table that contains frame description
397 information for each routine. */
398 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table
;
400 /* Number of elements currently allocated for fde_table. */
401 static GTY(()) unsigned fde_table_allocated
;
403 /* Number of elements in fde_table currently in use. */
404 static GTY(()) unsigned fde_table_in_use
;
406 /* Size (in elements) of increments by which we may expand the
408 #define FDE_TABLE_INCREMENT 256
410 /* Get the current fde_table entry we should use. */
412 static inline dw_fde_ref
415 return fde_table_in_use
? &fde_table
[fde_table_in_use
- 1] : NULL
;
418 /* A vector of call frame insns for the CIE. */
419 static GTY(()) cfi_vec cie_cfi_vec
;
421 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
422 attribute that accelerates the lookup of the FDE associated
423 with the subprogram. This variable holds the table index of the FDE
424 associated with the current function (body) definition. */
425 static unsigned current_funcdef_fde
;
427 struct GTY(()) indirect_string_node
{
429 unsigned int refcount
;
430 enum dwarf_form form
;
434 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
436 /* True if the compilation unit has location entries that reference
438 static GTY(()) bool debug_str_hash_forced
= false;
440 static GTY(()) int dw2_string_counter
;
441 static GTY(()) unsigned long dwarf2out_cfi_label_num
;
443 /* True if the compilation unit places functions in more than one section. */
444 static GTY(()) bool have_multiple_function_sections
= false;
446 /* Whether the default text and cold text sections have been used at all. */
448 static GTY(()) bool text_section_used
= false;
449 static GTY(()) bool cold_text_section_used
= false;
451 /* The default cold text section. */
452 static GTY(()) section
*cold_text_section
;
454 /* Forward declarations for functions defined in this file. */
456 static char *stripattributes (const char *);
457 static const char *dwarf_cfi_name (unsigned);
458 static dw_cfi_ref
new_cfi (void);
459 static void add_cfi (cfi_vec
*, dw_cfi_ref
);
460 static void add_fde_cfi (const char *, dw_cfi_ref
);
461 static void lookup_cfa_1 (dw_cfi_ref
, dw_cfa_location
*, dw_cfa_location
*);
462 static void lookup_cfa (dw_cfa_location
*);
463 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT
);
464 static void initial_return_save (rtx
);
465 static HOST_WIDE_INT
stack_adjust_offset (const_rtx
, HOST_WIDE_INT
,
467 static void output_cfi (dw_cfi_ref
, dw_fde_ref
, int);
468 static void output_cfi_directive (dw_cfi_ref
);
469 static void output_call_frame_info (int);
470 static void dwarf2out_note_section_used (void);
471 static bool clobbers_queued_reg_save (const_rtx
);
472 static void dwarf2out_frame_debug_expr (rtx
, const char *);
474 /* Support for complex CFA locations. */
475 static void output_cfa_loc (dw_cfi_ref
, int);
476 static void output_cfa_loc_raw (dw_cfi_ref
);
477 static void get_cfa_from_loc_descr (dw_cfa_location
*,
478 struct dw_loc_descr_struct
*);
479 static struct dw_loc_descr_struct
*build_cfa_loc
480 (dw_cfa_location
*, HOST_WIDE_INT
);
481 static struct dw_loc_descr_struct
*build_cfa_aligned_loc
482 (HOST_WIDE_INT
, HOST_WIDE_INT
);
483 static void def_cfa_1 (const char *, dw_cfa_location
*);
484 static struct dw_loc_descr_struct
*mem_loc_descriptor
485 (rtx
, enum machine_mode mode
, enum var_init_status
);
487 /* How to start an assembler comment. */
488 #ifndef ASM_COMMENT_START
489 #define ASM_COMMENT_START ";#"
492 /* Data and reference forms for relocatable data. */
493 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
494 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
496 #ifndef DEBUG_FRAME_SECTION
497 #define DEBUG_FRAME_SECTION ".debug_frame"
500 #ifndef FUNC_BEGIN_LABEL
501 #define FUNC_BEGIN_LABEL "LFB"
504 #ifndef FUNC_END_LABEL
505 #define FUNC_END_LABEL "LFE"
508 #ifndef PROLOGUE_END_LABEL
509 #define PROLOGUE_END_LABEL "LPE"
512 #ifndef EPILOGUE_BEGIN_LABEL
513 #define EPILOGUE_BEGIN_LABEL "LEB"
516 #ifndef FRAME_BEGIN_LABEL
517 #define FRAME_BEGIN_LABEL "Lframe"
519 #define CIE_AFTER_SIZE_LABEL "LSCIE"
520 #define CIE_END_LABEL "LECIE"
521 #define FDE_LABEL "LSFDE"
522 #define FDE_AFTER_SIZE_LABEL "LASFDE"
523 #define FDE_END_LABEL "LEFDE"
524 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
525 #define LINE_NUMBER_END_LABEL "LELT"
526 #define LN_PROLOG_AS_LABEL "LASLTP"
527 #define LN_PROLOG_END_LABEL "LELTP"
528 #define DIE_LABEL_PREFIX "DW"
530 /* The DWARF 2 CFA column which tracks the return address. Normally this
531 is the column for PC, or the first column after all of the hard
533 #ifndef DWARF_FRAME_RETURN_COLUMN
535 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
537 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
541 /* The mapping from gcc register number to DWARF 2 CFA column number. By
542 default, we just provide columns for all registers. */
543 #ifndef DWARF_FRAME_REGNUM
544 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
547 /* Match the base name of a file to the base name of a compilation unit. */
550 matches_main_base (const char *path
)
552 /* Cache the last query. */
553 static const char *last_path
= NULL
;
554 static int last_match
= 0;
555 if (path
!= last_path
)
558 int length
= base_of_path (path
, &base
);
560 last_match
= (length
== main_input_baselength
561 && memcmp (base
, main_input_basename
, length
) == 0);
566 #ifdef DEBUG_DEBUG_STRUCT
569 dump_struct_debug (tree type
, enum debug_info_usage usage
,
570 enum debug_struct_file criterion
, int generic
,
571 int matches
, int result
)
573 /* Find the type name. */
574 tree type_decl
= TYPE_STUB_DECL (type
);
576 const char *name
= 0;
577 if (TREE_CODE (t
) == TYPE_DECL
)
580 name
= IDENTIFIER_POINTER (t
);
582 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
584 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
585 matches
? "bas" : "hdr",
586 generic
? "gen" : "ord",
587 usage
== DINFO_USAGE_DFN
? ";" :
588 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
590 (void*) type_decl
, name
);
593 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
594 dump_struct_debug (type, usage, criterion, generic, matches, result)
598 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
604 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
606 enum debug_struct_file criterion
;
608 bool generic
= lang_hooks
.types
.generic_p (type
);
611 criterion
= debug_struct_generic
[usage
];
613 criterion
= debug_struct_ordinary
[usage
];
615 if (criterion
== DINFO_STRUCT_FILE_NONE
)
616 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
617 if (criterion
== DINFO_STRUCT_FILE_ANY
)
618 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
620 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
622 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
623 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
625 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
626 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
627 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
630 /* Hook used by __throw. */
633 expand_builtin_dwarf_sp_column (void)
635 unsigned int dwarf_regnum
= DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
);
636 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum
, 1));
639 /* Return a pointer to a copy of the section string name S with all
640 attributes stripped off, and an asterisk prepended (for assemble_name). */
643 stripattributes (const char *s
)
645 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
650 while (*s
&& *s
!= ',')
657 /* MEM is a memory reference for the register size table, each element of
658 which has mode MODE. Initialize column C as a return address column. */
661 init_return_column_size (enum machine_mode mode
, rtx mem
, unsigned int c
)
663 HOST_WIDE_INT offset
= c
* GET_MODE_SIZE (mode
);
664 HOST_WIDE_INT size
= GET_MODE_SIZE (Pmode
);
665 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
668 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
670 static inline HOST_WIDE_INT
671 div_data_align (HOST_WIDE_INT off
)
673 HOST_WIDE_INT r
= off
/ DWARF_CIE_DATA_ALIGNMENT
;
674 gcc_assert (r
* DWARF_CIE_DATA_ALIGNMENT
== off
);
678 /* Return true if we need a signed version of a given opcode
679 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
682 need_data_align_sf_opcode (HOST_WIDE_INT off
)
684 return DWARF_CIE_DATA_ALIGNMENT
< 0 ? off
> 0 : off
< 0;
687 /* Generate code to initialize the register size table. */
690 expand_builtin_init_dwarf_reg_sizes (tree address
)
693 enum machine_mode mode
= TYPE_MODE (char_type_node
);
694 rtx addr
= expand_normal (address
);
695 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
696 bool wrote_return_column
= false;
698 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
700 int rnum
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i
), 1);
702 if (rnum
< DWARF_FRAME_REGISTERS
)
704 HOST_WIDE_INT offset
= rnum
* GET_MODE_SIZE (mode
);
705 enum machine_mode save_mode
= reg_raw_mode
[i
];
708 if (HARD_REGNO_CALL_PART_CLOBBERED (i
, save_mode
))
709 save_mode
= choose_hard_reg_mode (i
, 1, true);
710 if (DWARF_FRAME_REGNUM (i
) == DWARF_FRAME_RETURN_COLUMN
)
712 if (save_mode
== VOIDmode
)
714 wrote_return_column
= true;
716 size
= GET_MODE_SIZE (save_mode
);
720 emit_move_insn (adjust_address (mem
, mode
, offset
),
721 gen_int_mode (size
, mode
));
725 if (!wrote_return_column
)
726 init_return_column_size (mode
, mem
, DWARF_FRAME_RETURN_COLUMN
);
728 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
729 init_return_column_size (mode
, mem
, DWARF_ALT_FRAME_RETURN_COLUMN
);
732 targetm
.init_dwarf_reg_sizes_extra (address
);
735 /* Convert a DWARF call frame info. operation to its string name */
738 dwarf_cfi_name (unsigned int cfi_opc
)
742 case DW_CFA_advance_loc
:
743 return "DW_CFA_advance_loc";
745 return "DW_CFA_offset";
747 return "DW_CFA_restore";
751 return "DW_CFA_set_loc";
752 case DW_CFA_advance_loc1
:
753 return "DW_CFA_advance_loc1";
754 case DW_CFA_advance_loc2
:
755 return "DW_CFA_advance_loc2";
756 case DW_CFA_advance_loc4
:
757 return "DW_CFA_advance_loc4";
758 case DW_CFA_offset_extended
:
759 return "DW_CFA_offset_extended";
760 case DW_CFA_restore_extended
:
761 return "DW_CFA_restore_extended";
762 case DW_CFA_undefined
:
763 return "DW_CFA_undefined";
764 case DW_CFA_same_value
:
765 return "DW_CFA_same_value";
766 case DW_CFA_register
:
767 return "DW_CFA_register";
768 case DW_CFA_remember_state
:
769 return "DW_CFA_remember_state";
770 case DW_CFA_restore_state
:
771 return "DW_CFA_restore_state";
773 return "DW_CFA_def_cfa";
774 case DW_CFA_def_cfa_register
:
775 return "DW_CFA_def_cfa_register";
776 case DW_CFA_def_cfa_offset
:
777 return "DW_CFA_def_cfa_offset";
780 case DW_CFA_def_cfa_expression
:
781 return "DW_CFA_def_cfa_expression";
782 case DW_CFA_expression
:
783 return "DW_CFA_expression";
784 case DW_CFA_offset_extended_sf
:
785 return "DW_CFA_offset_extended_sf";
786 case DW_CFA_def_cfa_sf
:
787 return "DW_CFA_def_cfa_sf";
788 case DW_CFA_def_cfa_offset_sf
:
789 return "DW_CFA_def_cfa_offset_sf";
791 /* SGI/MIPS specific */
792 case DW_CFA_MIPS_advance_loc8
:
793 return "DW_CFA_MIPS_advance_loc8";
796 case DW_CFA_GNU_window_save
:
797 return "DW_CFA_GNU_window_save";
798 case DW_CFA_GNU_args_size
:
799 return "DW_CFA_GNU_args_size";
800 case DW_CFA_GNU_negative_offset_extended
:
801 return "DW_CFA_GNU_negative_offset_extended";
804 return "DW_CFA_<unknown>";
808 /* Return a pointer to a newly allocated Call Frame Instruction. */
810 static inline dw_cfi_ref
813 dw_cfi_ref cfi
= ggc_alloc_dw_cfi_node ();
815 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
816 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
821 /* Add a Call Frame Instruction to list of instructions. */
824 add_cfi (cfi_vec
*vec
, dw_cfi_ref cfi
)
826 dw_fde_ref fde
= current_fde ();
828 /* When DRAP is used, CFA is defined with an expression. Redefine
829 CFA may lead to a different CFA value. */
830 /* ??? Of course, this heuristic fails when we're annotating epilogues,
831 because of course we'll always want to redefine the CFA back to the
832 stack pointer on the way out. Where should we move this check? */
833 if (0 && fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
834 switch (cfi
->dw_cfi_opc
)
836 case DW_CFA_def_cfa_register
:
837 case DW_CFA_def_cfa_offset
:
838 case DW_CFA_def_cfa_offset_sf
:
840 case DW_CFA_def_cfa_sf
:
847 VEC_safe_push (dw_cfi_ref
, gc
, *vec
, cfi
);
850 /* Generate a new label for the CFI info to refer to. FORCE is true
851 if a label needs to be output even when using .cfi_* directives. */
854 dwarf2out_cfi_label (bool force
)
856 static char label
[20];
858 if (!force
&& dwarf2out_do_cfi_asm ())
860 /* In this case, we will be emitting the asm directive instead of
861 the label, so just return a placeholder to keep the rest of the
863 strcpy (label
, "<do not output>");
867 int num
= dwarf2out_cfi_label_num
++;
868 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", num
);
869 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LCFI", num
);
875 /* True if remember_state should be emitted before following CFI directive. */
876 static bool emit_cfa_remember
;
878 /* True if any CFI directives were emitted at the current insn. */
879 static bool any_cfis_emitted
;
881 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
882 or to the CIE if LABEL is NULL. */
885 add_fde_cfi (const char *label
, dw_cfi_ref cfi
)
889 if (cie_cfi_vec
== NULL
)
890 cie_cfi_vec
= VEC_alloc (dw_cfi_ref
, gc
, 20);
894 if (emit_cfa_remember
)
896 dw_cfi_ref cfi_remember
;
898 /* Emit the state save. */
899 emit_cfa_remember
= false;
900 cfi_remember
= new_cfi ();
901 cfi_remember
->dw_cfi_opc
= DW_CFA_remember_state
;
902 add_fde_cfi (label
, cfi_remember
);
905 if (dwarf2out_do_cfi_asm ())
909 dw_fde_ref fde
= current_fde ();
911 gcc_assert (fde
!= NULL
);
913 /* We still have to add the cfi to the list so that lookup_cfa
914 works later on. When -g2 and above we even need to force
915 emitting of CFI labels and add to list a DW_CFA_set_loc for
916 convert_cfa_to_fb_loc_list purposes. If we're generating
917 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
918 convert_cfa_to_fb_loc_list. */
919 if (dwarf_version
== 2
920 && debug_info_level
> DINFO_LEVEL_TERSE
921 && (write_symbols
== DWARF2_DEBUG
922 || write_symbols
== VMS_AND_DWARF2_DEBUG
))
924 switch (cfi
->dw_cfi_opc
)
926 case DW_CFA_def_cfa_offset
:
927 case DW_CFA_def_cfa_offset_sf
:
928 case DW_CFA_def_cfa_register
:
930 case DW_CFA_def_cfa_sf
:
931 case DW_CFA_def_cfa_expression
:
932 case DW_CFA_restore_state
:
933 if (*label
== 0 || strcmp (label
, "<do not output>") == 0)
934 label
= dwarf2out_cfi_label (true);
936 if (fde
->dw_fde_current_label
== NULL
937 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
941 label
= xstrdup (label
);
943 /* Set the location counter to the new label. */
945 /* It doesn't metter whether DW_CFA_set_loc
946 or DW_CFA_advance_loc4 is added here, those aren't
947 emitted into assembly, only looked up by
948 convert_cfa_to_fb_loc_list. */
949 xcfi
->dw_cfi_opc
= DW_CFA_set_loc
;
950 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
951 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
952 fde
->dw_fde_current_label
= label
;
960 output_cfi_directive (cfi
);
962 vec
= &fde
->dw_fde_cfi
;
963 any_cfis_emitted
= true;
965 /* ??? If this is a CFI for the CIE, we don't emit. This
966 assumes that the standard CIE contents that the assembler
967 uses matches the standard CIE contents that the compiler
968 uses. This is probably a bad assumption. I'm not quite
969 sure how to address this for now. */
973 dw_fde_ref fde
= current_fde ();
975 gcc_assert (fde
!= NULL
);
978 label
= dwarf2out_cfi_label (false);
980 if (fde
->dw_fde_current_label
== NULL
981 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
985 label
= xstrdup (label
);
987 /* Set the location counter to the new label. */
989 /* If we have a current label, advance from there, otherwise
990 set the location directly using set_loc. */
991 xcfi
->dw_cfi_opc
= fde
->dw_fde_current_label
992 ? DW_CFA_advance_loc4
994 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
995 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
997 fde
->dw_fde_current_label
= label
;
1000 vec
= &fde
->dw_fde_cfi
;
1001 any_cfis_emitted
= true;
1007 /* Subroutine of lookup_cfa. */
1010 lookup_cfa_1 (dw_cfi_ref cfi
, dw_cfa_location
*loc
, dw_cfa_location
*remember
)
1012 switch (cfi
->dw_cfi_opc
)
1014 case DW_CFA_def_cfa_offset
:
1015 case DW_CFA_def_cfa_offset_sf
:
1016 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
1018 case DW_CFA_def_cfa_register
:
1019 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
1021 case DW_CFA_def_cfa
:
1022 case DW_CFA_def_cfa_sf
:
1023 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
1024 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
1026 case DW_CFA_def_cfa_expression
:
1027 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
1030 case DW_CFA_remember_state
:
1031 gcc_assert (!remember
->in_use
);
1033 remember
->in_use
= 1;
1035 case DW_CFA_restore_state
:
1036 gcc_assert (remember
->in_use
);
1038 remember
->in_use
= 0;
1046 /* Find the previous value for the CFA. */
1049 lookup_cfa (dw_cfa_location
*loc
)
1054 dw_cfa_location remember
;
1056 memset (loc
, 0, sizeof (*loc
));
1057 loc
->reg
= INVALID_REGNUM
;
1060 FOR_EACH_VEC_ELT (dw_cfi_ref
, cie_cfi_vec
, ix
, cfi
)
1061 lookup_cfa_1 (cfi
, loc
, &remember
);
1063 fde
= current_fde ();
1065 FOR_EACH_VEC_ELT (dw_cfi_ref
, fde
->dw_fde_cfi
, ix
, cfi
)
1066 lookup_cfa_1 (cfi
, loc
, &remember
);
1069 /* The current rule for calculating the DWARF2 canonical frame address. */
1070 static dw_cfa_location cfa
;
1072 /* The register used for saving registers to the stack, and its offset
1074 static dw_cfa_location cfa_store
;
1076 /* The current save location around an epilogue. */
1077 static dw_cfa_location cfa_remember
;
1079 /* The running total of the size of arguments pushed onto the stack. */
1080 static HOST_WIDE_INT args_size
;
1082 /* The last args_size we actually output. */
1083 static HOST_WIDE_INT old_args_size
;
1085 /* Entry point to update the canonical frame address (CFA).
1086 LABEL is passed to add_fde_cfi. The value of CFA is now to be
1087 calculated from REG+OFFSET. */
1090 dwarf2out_def_cfa (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
1092 dw_cfa_location loc
;
1094 loc
.base_offset
= 0;
1096 loc
.offset
= offset
;
1097 def_cfa_1 (label
, &loc
);
1100 /* Determine if two dw_cfa_location structures define the same data. */
1103 cfa_equal_p (const dw_cfa_location
*loc1
, const dw_cfa_location
*loc2
)
1105 return (loc1
->reg
== loc2
->reg
1106 && loc1
->offset
== loc2
->offset
1107 && loc1
->indirect
== loc2
->indirect
1108 && (loc1
->indirect
== 0
1109 || loc1
->base_offset
== loc2
->base_offset
));
1112 /* This routine does the actual work. The CFA is now calculated from
1113 the dw_cfa_location structure. */
1116 def_cfa_1 (const char *label
, dw_cfa_location
*loc_p
)
1119 dw_cfa_location old_cfa
, loc
;
1124 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
1125 cfa_store
.offset
= loc
.offset
;
1127 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
1128 lookup_cfa (&old_cfa
);
1130 /* If nothing changed, no need to issue any call frame instructions. */
1131 if (cfa_equal_p (&loc
, &old_cfa
))
1136 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
&& !old_cfa
.indirect
)
1138 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1139 the CFA register did not change but the offset did. The data
1140 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1141 in the assembler via the .cfi_def_cfa_offset directive. */
1143 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset_sf
;
1145 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
1146 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
1149 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1150 else if (loc
.offset
== old_cfa
.offset
1151 && old_cfa
.reg
!= INVALID_REGNUM
1153 && !old_cfa
.indirect
)
1155 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1156 indicating the CFA register has changed to <register> but the
1157 offset has not changed. */
1158 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
1159 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
1163 else if (loc
.indirect
== 0)
1165 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1166 indicating the CFA register has changed to <register> with
1167 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1168 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1171 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_sf
;
1173 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
1174 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
1175 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
1179 /* Construct a DW_CFA_def_cfa_expression instruction to
1180 calculate the CFA using a full location expression since no
1181 register-offset pair is available. */
1182 struct dw_loc_descr_struct
*loc_list
;
1184 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
1185 loc_list
= build_cfa_loc (&loc
, 0);
1186 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
1189 add_fde_cfi (label
, cfi
);
1192 /* Add the CFI for saving a register. REG is the CFA column number.
1193 LABEL is passed to add_fde_cfi.
1194 If SREG is -1, the register is saved at OFFSET from the CFA;
1195 otherwise it is saved in SREG. */
1198 reg_save (const char *label
, unsigned int reg
, unsigned int sreg
, HOST_WIDE_INT offset
)
1200 dw_cfi_ref cfi
= new_cfi ();
1201 dw_fde_ref fde
= current_fde ();
1203 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
1205 /* When stack is aligned, store REG using DW_CFA_expression with
1208 && fde
->stack_realign
1209 && sreg
== INVALID_REGNUM
)
1211 cfi
->dw_cfi_opc
= DW_CFA_expression
;
1212 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
1213 cfi
->dw_cfi_oprnd2
.dw_cfi_loc
1214 = build_cfa_aligned_loc (offset
, fde
->stack_realignment
);
1216 else if (sreg
== INVALID_REGNUM
)
1218 if (need_data_align_sf_opcode (offset
))
1219 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
1220 else if (reg
& ~0x3f)
1221 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
1223 cfi
->dw_cfi_opc
= DW_CFA_offset
;
1224 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
1226 else if (sreg
== reg
)
1227 cfi
->dw_cfi_opc
= DW_CFA_same_value
;
1230 cfi
->dw_cfi_opc
= DW_CFA_register
;
1231 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
1234 add_fde_cfi (label
, cfi
);
1237 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1238 This CFI tells the unwinder that it needs to restore the window registers
1239 from the previous frame's window save area.
1241 ??? Perhaps we should note in the CIE where windows are saved (instead of
1242 assuming 0(cfa)) and what registers are in the window. */
1245 dwarf2out_window_save (const char *label
)
1247 dw_cfi_ref cfi
= new_cfi ();
1249 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
1250 add_fde_cfi (label
, cfi
);
1253 /* Entry point for saving a register to the stack. REG is the GCC register
1254 number. LABEL and OFFSET are passed to reg_save. */
1257 dwarf2out_reg_save (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
1259 reg_save (label
, DWARF_FRAME_REGNUM (reg
), INVALID_REGNUM
, offset
);
1262 /* Entry point for saving the return address in the stack.
1263 LABEL and OFFSET are passed to reg_save. */
1266 dwarf2out_return_save (const char *label
, HOST_WIDE_INT offset
)
1268 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, INVALID_REGNUM
, offset
);
1271 /* Entry point for saving the return address in a register.
1272 LABEL and SREG are passed to reg_save. */
1275 dwarf2out_return_reg (const char *label
, unsigned int sreg
)
1277 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, DWARF_FRAME_REGNUM (sreg
), 0);
1280 /* Record the initial position of the return address. RTL is
1281 INCOMING_RETURN_ADDR_RTX. */
1284 initial_return_save (rtx rtl
)
1286 unsigned int reg
= INVALID_REGNUM
;
1287 HOST_WIDE_INT offset
= 0;
1289 switch (GET_CODE (rtl
))
1292 /* RA is in a register. */
1293 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
1297 /* RA is on the stack. */
1298 rtl
= XEXP (rtl
, 0);
1299 switch (GET_CODE (rtl
))
1302 gcc_assert (REGNO (rtl
) == STACK_POINTER_REGNUM
);
1307 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
1308 offset
= INTVAL (XEXP (rtl
, 1));
1312 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
1313 offset
= -INTVAL (XEXP (rtl
, 1));
1323 /* The return address is at some offset from any value we can
1324 actually load. For instance, on the SPARC it is in %i7+8. Just
1325 ignore the offset for now; it doesn't matter for unwinding frames. */
1326 gcc_assert (CONST_INT_P (XEXP (rtl
, 1)));
1327 initial_return_save (XEXP (rtl
, 0));
1334 if (reg
!= DWARF_FRAME_RETURN_COLUMN
)
1335 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
1338 /* Given a SET, calculate the amount of stack adjustment it
1341 static HOST_WIDE_INT
1342 stack_adjust_offset (const_rtx pattern
, HOST_WIDE_INT cur_args_size
,
1343 HOST_WIDE_INT cur_offset
)
1345 const_rtx src
= SET_SRC (pattern
);
1346 const_rtx dest
= SET_DEST (pattern
);
1347 HOST_WIDE_INT offset
= 0;
1350 if (dest
== stack_pointer_rtx
)
1352 code
= GET_CODE (src
);
1354 /* Assume (set (reg sp) (reg whatever)) sets args_size
1356 if (code
== REG
&& src
!= stack_pointer_rtx
)
1358 offset
= -cur_args_size
;
1359 #ifndef STACK_GROWS_DOWNWARD
1362 return offset
- cur_offset
;
1365 if (! (code
== PLUS
|| code
== MINUS
)
1366 || XEXP (src
, 0) != stack_pointer_rtx
1367 || !CONST_INT_P (XEXP (src
, 1)))
1370 /* (set (reg sp) (plus (reg sp) (const_int))) */
1371 offset
= INTVAL (XEXP (src
, 1));
1377 if (MEM_P (src
) && !MEM_P (dest
))
1381 /* (set (mem (pre_dec (reg sp))) (foo)) */
1382 src
= XEXP (dest
, 0);
1383 code
= GET_CODE (src
);
1389 if (XEXP (src
, 0) == stack_pointer_rtx
)
1391 rtx val
= XEXP (XEXP (src
, 1), 1);
1392 /* We handle only adjustments by constant amount. */
1393 gcc_assert (GET_CODE (XEXP (src
, 1)) == PLUS
1394 && CONST_INT_P (val
));
1395 offset
= -INTVAL (val
);
1402 if (XEXP (src
, 0) == stack_pointer_rtx
)
1404 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1411 if (XEXP (src
, 0) == stack_pointer_rtx
)
1413 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
1428 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1429 indexed by INSN_UID. */
1431 static HOST_WIDE_INT
*barrier_args_size
;
1433 /* Helper function for compute_barrier_args_size. Handle one insn. */
1435 static HOST_WIDE_INT
1436 compute_barrier_args_size_1 (rtx insn
, HOST_WIDE_INT cur_args_size
,
1437 VEC (rtx
, heap
) **next
)
1439 HOST_WIDE_INT offset
= 0;
1442 if (! RTX_FRAME_RELATED_P (insn
))
1444 if (prologue_epilogue_contains (insn
))
1446 else if (GET_CODE (PATTERN (insn
)) == SET
)
1447 offset
= stack_adjust_offset (PATTERN (insn
), cur_args_size
, 0);
1448 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1449 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1451 /* There may be stack adjustments inside compound insns. Search
1453 for (i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1454 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1455 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
),
1456 cur_args_size
, offset
);
1461 rtx expr
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1465 expr
= XEXP (expr
, 0);
1466 if (GET_CODE (expr
) == PARALLEL
1467 || GET_CODE (expr
) == SEQUENCE
)
1468 for (i
= 1; i
< XVECLEN (expr
, 0); i
++)
1470 rtx elem
= XVECEXP (expr
, 0, i
);
1472 if (GET_CODE (elem
) == SET
&& !RTX_FRAME_RELATED_P (elem
))
1473 offset
+= stack_adjust_offset (elem
, cur_args_size
, offset
);
1478 #ifndef STACK_GROWS_DOWNWARD
1482 cur_args_size
+= offset
;
1483 if (cur_args_size
< 0)
1488 rtx dest
= JUMP_LABEL (insn
);
1492 if (barrier_args_size
[INSN_UID (dest
)] < 0)
1494 barrier_args_size
[INSN_UID (dest
)] = cur_args_size
;
1495 VEC_safe_push (rtx
, heap
, *next
, dest
);
1500 return cur_args_size
;
1503 /* Walk the whole function and compute args_size on BARRIERs. */
1506 compute_barrier_args_size (void)
1508 int max_uid
= get_max_uid (), i
;
1510 VEC (rtx
, heap
) *worklist
, *next
, *tmp
;
1512 barrier_args_size
= XNEWVEC (HOST_WIDE_INT
, max_uid
);
1513 for (i
= 0; i
< max_uid
; i
++)
1514 barrier_args_size
[i
] = -1;
1516 worklist
= VEC_alloc (rtx
, heap
, 20);
1517 next
= VEC_alloc (rtx
, heap
, 20);
1518 insn
= get_insns ();
1519 barrier_args_size
[INSN_UID (insn
)] = 0;
1520 VEC_quick_push (rtx
, worklist
, insn
);
1523 while (!VEC_empty (rtx
, worklist
))
1525 rtx prev
, body
, first_insn
;
1526 HOST_WIDE_INT cur_args_size
;
1528 first_insn
= insn
= VEC_pop (rtx
, worklist
);
1529 cur_args_size
= barrier_args_size
[INSN_UID (insn
)];
1530 prev
= prev_nonnote_insn (insn
);
1531 if (prev
&& BARRIER_P (prev
))
1532 barrier_args_size
[INSN_UID (prev
)] = cur_args_size
;
1534 for (; insn
; insn
= NEXT_INSN (insn
))
1536 if (INSN_DELETED_P (insn
) || NOTE_P (insn
))
1538 if (BARRIER_P (insn
))
1543 if (insn
== first_insn
)
1545 else if (barrier_args_size
[INSN_UID (insn
)] < 0)
1547 barrier_args_size
[INSN_UID (insn
)] = cur_args_size
;
1552 /* The insns starting with this label have been
1553 already scanned or are in the worklist. */
1558 body
= PATTERN (insn
);
1559 if (GET_CODE (body
) == SEQUENCE
)
1561 HOST_WIDE_INT dest_args_size
= cur_args_size
;
1562 for (i
= 1; i
< XVECLEN (body
, 0); i
++)
1563 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body
, 0, 0))
1564 && INSN_FROM_TARGET_P (XVECEXP (body
, 0, i
)))
1566 = compute_barrier_args_size_1 (XVECEXP (body
, 0, i
),
1567 dest_args_size
, &next
);
1570 = compute_barrier_args_size_1 (XVECEXP (body
, 0, i
),
1571 cur_args_size
, &next
);
1573 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body
, 0, 0)))
1574 compute_barrier_args_size_1 (XVECEXP (body
, 0, 0),
1575 dest_args_size
, &next
);
1578 = compute_barrier_args_size_1 (XVECEXP (body
, 0, 0),
1579 cur_args_size
, &next
);
1583 = compute_barrier_args_size_1 (insn
, cur_args_size
, &next
);
1587 if (VEC_empty (rtx
, next
))
1590 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1594 VEC_truncate (rtx
, next
, 0);
1597 VEC_free (rtx
, heap
, worklist
);
1598 VEC_free (rtx
, heap
, next
);
1601 /* Add a CFI to update the running total of the size of arguments
1602 pushed onto the stack. */
1605 dwarf2out_args_size (const char *label
, HOST_WIDE_INT size
)
1609 if (size
== old_args_size
)
1612 old_args_size
= size
;
1615 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
1616 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
1617 add_fde_cfi (label
, cfi
);
1620 /* Record a stack adjustment of OFFSET bytes. */
1623 dwarf2out_stack_adjust (HOST_WIDE_INT offset
, const char *label
)
1625 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1626 cfa
.offset
+= offset
;
1628 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1629 cfa_store
.offset
+= offset
;
1631 if (ACCUMULATE_OUTGOING_ARGS
)
1634 #ifndef STACK_GROWS_DOWNWARD
1638 args_size
+= offset
;
1642 def_cfa_1 (label
, &cfa
);
1643 if (flag_asynchronous_unwind_tables
)
1644 dwarf2out_args_size (label
, args_size
);
1647 /* Check INSN to see if it looks like a push or a stack adjustment, and
1648 make a note of it if it does. EH uses this information to find out
1649 how much extra space it needs to pop off the stack. */
1652 dwarf2out_notice_stack_adjust (rtx insn
, bool after_p
)
1654 HOST_WIDE_INT offset
;
1658 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1659 with this function. Proper support would require all frame-related
1660 insns to be marked, and to be able to handle saving state around
1661 epilogues textually in the middle of the function. */
1662 if (prologue_epilogue_contains (insn
))
1665 /* If INSN is an instruction from target of an annulled branch, the
1666 effects are for the target only and so current argument size
1667 shouldn't change at all. */
1669 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence
, 0, 0))
1670 && INSN_FROM_TARGET_P (insn
))
1673 /* If only calls can throw, and we have a frame pointer,
1674 save up adjustments until we see the CALL_INSN. */
1675 if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1677 if (CALL_P (insn
) && !after_p
)
1679 /* Extract the size of the args from the CALL rtx itself. */
1680 insn
= PATTERN (insn
);
1681 if (GET_CODE (insn
) == PARALLEL
)
1682 insn
= XVECEXP (insn
, 0, 0);
1683 if (GET_CODE (insn
) == SET
)
1684 insn
= SET_SRC (insn
);
1685 gcc_assert (GET_CODE (insn
) == CALL
);
1686 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1691 if (CALL_P (insn
) && !after_p
)
1693 if (!flag_asynchronous_unwind_tables
)
1694 dwarf2out_args_size ("", args_size
);
1697 else if (BARRIER_P (insn
))
1699 /* Don't call compute_barrier_args_size () if the only
1700 BARRIER is at the end of function. */
1701 if (barrier_args_size
== NULL
&& next_nonnote_insn (insn
))
1702 compute_barrier_args_size ();
1703 if (barrier_args_size
== NULL
)
1707 offset
= barrier_args_size
[INSN_UID (insn
)];
1712 offset
-= args_size
;
1713 #ifndef STACK_GROWS_DOWNWARD
1717 else if (GET_CODE (PATTERN (insn
)) == SET
)
1718 offset
= stack_adjust_offset (PATTERN (insn
), args_size
, 0);
1719 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1720 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1722 /* There may be stack adjustments inside compound insns. Search
1724 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1725 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1726 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
),
1735 label
= dwarf2out_cfi_label (false);
1736 dwarf2out_stack_adjust (offset
, label
);
1739 /* We delay emitting a register save until either (a) we reach the end
1740 of the prologue or (b) the register is clobbered. This clusters
1741 register saves so that there are fewer pc advances. */
1743 struct GTY(()) queued_reg_save
{
1744 struct queued_reg_save
*next
;
1746 HOST_WIDE_INT cfa_offset
;
1750 static GTY(()) struct queued_reg_save
*queued_reg_saves
;
1752 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1753 struct GTY(()) reg_saved_in_data
{
1758 /* A list of registers saved in other registers.
1759 The list intentionally has a small maximum capacity of 4; if your
1760 port needs more than that, you might consider implementing a
1761 more efficient data structure. */
1762 static GTY(()) struct reg_saved_in_data regs_saved_in_regs
[4];
1763 static GTY(()) size_t num_regs_saved_in_regs
;
1765 static const char *last_reg_save_label
;
1767 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1768 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1771 queue_reg_save (const char *label
, rtx reg
, rtx sreg
, HOST_WIDE_INT offset
)
1773 struct queued_reg_save
*q
;
1775 /* Duplicates waste space, but it's also necessary to remove them
1776 for correctness, since the queue gets output in reverse
1778 for (q
= queued_reg_saves
; q
!= NULL
; q
= q
->next
)
1779 if (REGNO (q
->reg
) == REGNO (reg
))
1784 q
= ggc_alloc_queued_reg_save ();
1785 q
->next
= queued_reg_saves
;
1786 queued_reg_saves
= q
;
1790 q
->cfa_offset
= offset
;
1791 q
->saved_reg
= sreg
;
1793 last_reg_save_label
= label
;
1796 /* Output all the entries in QUEUED_REG_SAVES. */
1799 dwarf2out_flush_queued_reg_saves (void)
1801 struct queued_reg_save
*q
;
1803 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1806 unsigned int reg
, sreg
;
1808 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1809 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (q
->reg
))
1811 if (q
->saved_reg
&& i
== num_regs_saved_in_regs
)
1813 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1814 num_regs_saved_in_regs
++;
1816 if (i
!= num_regs_saved_in_regs
)
1818 regs_saved_in_regs
[i
].orig_reg
= q
->reg
;
1819 regs_saved_in_regs
[i
].saved_in_reg
= q
->saved_reg
;
1822 reg
= DWARF_FRAME_REGNUM (REGNO (q
->reg
));
1824 sreg
= DWARF_FRAME_REGNUM (REGNO (q
->saved_reg
));
1826 sreg
= INVALID_REGNUM
;
1827 reg_save (last_reg_save_label
, reg
, sreg
, q
->cfa_offset
);
1830 queued_reg_saves
= NULL
;
1831 last_reg_save_label
= NULL
;
1834 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1835 location for? Or, does it clobber a register which we've previously
1836 said that some other register is saved in, and for which we now
1837 have a new location for? */
1840 clobbers_queued_reg_save (const_rtx insn
)
1842 struct queued_reg_save
*q
;
1844 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1847 if (modified_in_p (q
->reg
, insn
))
1849 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1850 if (REGNO (q
->reg
) == REGNO (regs_saved_in_regs
[i
].orig_reg
)
1851 && modified_in_p (regs_saved_in_regs
[i
].saved_in_reg
, insn
))
1858 /* Entry point for saving the first register into the second. */
1861 dwarf2out_reg_save_reg (const char *label
, rtx reg
, rtx sreg
)
1864 unsigned int regno
, sregno
;
1866 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1867 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (reg
))
1869 if (i
== num_regs_saved_in_regs
)
1871 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1872 num_regs_saved_in_regs
++;
1874 regs_saved_in_regs
[i
].orig_reg
= reg
;
1875 regs_saved_in_regs
[i
].saved_in_reg
= sreg
;
1877 regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
1878 sregno
= DWARF_FRAME_REGNUM (REGNO (sreg
));
1879 reg_save (label
, regno
, sregno
, 0);
1882 /* What register, if any, is currently saved in REG? */
1885 reg_saved_in (rtx reg
)
1887 unsigned int regn
= REGNO (reg
);
1889 struct queued_reg_save
*q
;
1891 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1892 if (q
->saved_reg
&& regn
== REGNO (q
->saved_reg
))
1895 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1896 if (regs_saved_in_regs
[i
].saved_in_reg
1897 && regn
== REGNO (regs_saved_in_regs
[i
].saved_in_reg
))
1898 return regs_saved_in_regs
[i
].orig_reg
;
1904 /* A temporary register holding an integral value used in adjusting SP
1905 or setting up the store_reg. The "offset" field holds the integer
1906 value, not an offset. */
1907 static dw_cfa_location cfa_temp
;
1909 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1912 dwarf2out_frame_debug_def_cfa (rtx pat
, const char *label
)
1914 memset (&cfa
, 0, sizeof (cfa
));
1916 switch (GET_CODE (pat
))
1919 cfa
.reg
= REGNO (XEXP (pat
, 0));
1920 cfa
.offset
= INTVAL (XEXP (pat
, 1));
1924 cfa
.reg
= REGNO (pat
);
1929 pat
= XEXP (pat
, 0);
1930 if (GET_CODE (pat
) == PLUS
)
1932 cfa
.base_offset
= INTVAL (XEXP (pat
, 1));
1933 pat
= XEXP (pat
, 0);
1935 cfa
.reg
= REGNO (pat
);
1939 /* Recurse and define an expression. */
1943 def_cfa_1 (label
, &cfa
);
1946 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1949 dwarf2out_frame_debug_adjust_cfa (rtx pat
, const char *label
)
1953 gcc_assert (GET_CODE (pat
) == SET
);
1954 dest
= XEXP (pat
, 0);
1955 src
= XEXP (pat
, 1);
1957 switch (GET_CODE (src
))
1960 gcc_assert (REGNO (XEXP (src
, 0)) == cfa
.reg
);
1961 cfa
.offset
-= INTVAL (XEXP (src
, 1));
1971 cfa
.reg
= REGNO (dest
);
1972 gcc_assert (cfa
.indirect
== 0);
1974 def_cfa_1 (label
, &cfa
);
1977 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1980 dwarf2out_frame_debug_cfa_offset (rtx set
, const char *label
)
1982 HOST_WIDE_INT offset
;
1983 rtx src
, addr
, span
;
1985 src
= XEXP (set
, 1);
1986 addr
= XEXP (set
, 0);
1987 gcc_assert (MEM_P (addr
));
1988 addr
= XEXP (addr
, 0);
1990 /* As documented, only consider extremely simple addresses. */
1991 switch (GET_CODE (addr
))
1994 gcc_assert (REGNO (addr
) == cfa
.reg
);
1995 offset
= -cfa
.offset
;
1998 gcc_assert (REGNO (XEXP (addr
, 0)) == cfa
.reg
);
1999 offset
= INTVAL (XEXP (addr
, 1)) - cfa
.offset
;
2005 span
= targetm
.dwarf_register_span (src
);
2007 /* ??? We'd like to use queue_reg_save, but we need to come up with
2008 a different flushing heuristic for epilogues. */
2010 reg_save (label
, DWARF_FRAME_REGNUM (REGNO (src
)), INVALID_REGNUM
, offset
);
2013 /* We have a PARALLEL describing where the contents of SRC live.
2014 Queue register saves for each piece of the PARALLEL. */
2017 HOST_WIDE_INT span_offset
= offset
;
2019 gcc_assert (GET_CODE (span
) == PARALLEL
);
2021 limit
= XVECLEN (span
, 0);
2022 for (par_index
= 0; par_index
< limit
; par_index
++)
2024 rtx elem
= XVECEXP (span
, 0, par_index
);
2026 reg_save (label
, DWARF_FRAME_REGNUM (REGNO (elem
)),
2027 INVALID_REGNUM
, span_offset
);
2028 span_offset
+= GET_MODE_SIZE (GET_MODE (elem
));
2033 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
2036 dwarf2out_frame_debug_cfa_register (rtx set
, const char *label
)
2039 unsigned sregno
, dregno
;
2041 src
= XEXP (set
, 1);
2042 dest
= XEXP (set
, 0);
2045 sregno
= DWARF_FRAME_RETURN_COLUMN
;
2047 sregno
= DWARF_FRAME_REGNUM (REGNO (src
));
2049 dregno
= DWARF_FRAME_REGNUM (REGNO (dest
));
2051 /* ??? We'd like to use queue_reg_save, but we need to come up with
2052 a different flushing heuristic for epilogues. */
2053 reg_save (label
, sregno
, dregno
, 0);
2056 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
2059 dwarf2out_frame_debug_cfa_expression (rtx set
, const char *label
)
2061 rtx src
, dest
, span
;
2062 dw_cfi_ref cfi
= new_cfi ();
2064 dest
= SET_DEST (set
);
2065 src
= SET_SRC (set
);
2067 gcc_assert (REG_P (src
));
2068 gcc_assert (MEM_P (dest
));
2070 span
= targetm
.dwarf_register_span (src
);
2073 cfi
->dw_cfi_opc
= DW_CFA_expression
;
2074 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= DWARF_FRAME_REGNUM (REGNO (src
));
2075 cfi
->dw_cfi_oprnd2
.dw_cfi_loc
2076 = mem_loc_descriptor (XEXP (dest
, 0), GET_MODE (dest
),
2077 VAR_INIT_STATUS_INITIALIZED
);
2079 /* ??? We'd like to use queue_reg_save, were the interface different,
2080 and, as above, we could manage flushing for epilogues. */
2081 add_fde_cfi (label
, cfi
);
2084 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
2087 dwarf2out_frame_debug_cfa_restore (rtx reg
, const char *label
)
2089 dw_cfi_ref cfi
= new_cfi ();
2090 unsigned int regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
2092 cfi
->dw_cfi_opc
= (regno
& ~0x3f ? DW_CFA_restore_extended
: DW_CFA_restore
);
2093 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= regno
;
2095 add_fde_cfi (label
, cfi
);
2098 /* Record call frame debugging information for an expression EXPR,
2099 which either sets SP or FP (adjusting how we calculate the frame
2100 address) or saves a register to the stack or another register.
2101 LABEL indicates the address of EXPR.
2103 This function encodes a state machine mapping rtxes to actions on
2104 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
2105 users need not read the source code.
2107 The High-Level Picture
2109 Changes in the register we use to calculate the CFA: Currently we
2110 assume that if you copy the CFA register into another register, we
2111 should take the other one as the new CFA register; this seems to
2112 work pretty well. If it's wrong for some target, it's simple
2113 enough not to set RTX_FRAME_RELATED_P on the insn in question.
2115 Changes in the register we use for saving registers to the stack:
2116 This is usually SP, but not always. Again, we deduce that if you
2117 copy SP into another register (and SP is not the CFA register),
2118 then the new register is the one we will be using for register
2119 saves. This also seems to work.
2121 Register saves: There's not much guesswork about this one; if
2122 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
2123 register save, and the register used to calculate the destination
2124 had better be the one we think we're using for this purpose.
2125 It's also assumed that a copy from a call-saved register to another
2126 register is saving that register if RTX_FRAME_RELATED_P is set on
2127 that instruction. If the copy is from a call-saved register to
2128 the *same* register, that means that the register is now the same
2129 value as in the caller.
2131 Except: If the register being saved is the CFA register, and the
2132 offset is nonzero, we are saving the CFA, so we assume we have to
2133 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
2134 the intent is to save the value of SP from the previous frame.
2136 In addition, if a register has previously been saved to a different
2139 Invariants / Summaries of Rules
2141 cfa current rule for calculating the CFA. It usually
2142 consists of a register and an offset.
2143 cfa_store register used by prologue code to save things to the stack
2144 cfa_store.offset is the offset from the value of
2145 cfa_store.reg to the actual CFA
2146 cfa_temp register holding an integral value. cfa_temp.offset
2147 stores the value, which will be used to adjust the
2148 stack pointer. cfa_temp is also used like cfa_store,
2149 to track stores to the stack via fp or a temp reg.
2151 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2152 with cfa.reg as the first operand changes the cfa.reg and its
2153 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2156 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2157 expression yielding a constant. This sets cfa_temp.reg
2158 and cfa_temp.offset.
2160 Rule 5: Create a new register cfa_store used to save items to the
2163 Rules 10-14: Save a register to the stack. Define offset as the
2164 difference of the original location and cfa_store's
2165 location (or cfa_temp's location if cfa_temp is used).
2167 Rules 16-20: If AND operation happens on sp in prologue, we assume
2168 stack is realigned. We will use a group of DW_OP_XXX
2169 expressions to represent the location of the stored
2170 register instead of CFA+offset.
2174 "{a,b}" indicates a choice of a xor b.
2175 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2178 (set <reg1> <reg2>:cfa.reg)
2179 effects: cfa.reg = <reg1>
2180 cfa.offset unchanged
2181 cfa_temp.reg = <reg1>
2182 cfa_temp.offset = cfa.offset
2185 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2186 {<const_int>,<reg>:cfa_temp.reg}))
2187 effects: cfa.reg = sp if fp used
2188 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2189 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2190 if cfa_store.reg==sp
2193 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2194 effects: cfa.reg = fp
2195 cfa_offset += +/- <const_int>
2198 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2199 constraints: <reg1> != fp
2201 effects: cfa.reg = <reg1>
2202 cfa_temp.reg = <reg1>
2203 cfa_temp.offset = cfa.offset
2206 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2207 constraints: <reg1> != fp
2209 effects: cfa_store.reg = <reg1>
2210 cfa_store.offset = cfa.offset - cfa_temp.offset
2213 (set <reg> <const_int>)
2214 effects: cfa_temp.reg = <reg>
2215 cfa_temp.offset = <const_int>
2218 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2219 effects: cfa_temp.reg = <reg1>
2220 cfa_temp.offset |= <const_int>
2223 (set <reg> (high <exp>))
2227 (set <reg> (lo_sum <exp> <const_int>))
2228 effects: cfa_temp.reg = <reg>
2229 cfa_temp.offset = <const_int>
2232 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2233 effects: cfa_store.offset -= <const_int>
2234 cfa.offset = cfa_store.offset if cfa.reg == sp
2236 cfa.base_offset = -cfa_store.offset
2239 (set (mem ({pre_inc,pre_dec,post_dec} sp:cfa_store.reg)) <reg>)
2240 effects: cfa_store.offset += -/+ mode_size(mem)
2241 cfa.offset = cfa_store.offset if cfa.reg == sp
2243 cfa.base_offset = -cfa_store.offset
2246 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2249 effects: cfa.reg = <reg1>
2250 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2253 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2254 effects: cfa.reg = <reg1>
2255 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2258 (set (mem (post_inc <reg1>:cfa_temp <const_int>)) <reg2>)
2259 effects: cfa.reg = <reg1>
2260 cfa.base_offset = -cfa_temp.offset
2261 cfa_temp.offset -= mode_size(mem)
2264 (set <reg> {unspec, unspec_volatile})
2265 effects: target-dependent
2268 (set sp (and: sp <const_int>))
2269 constraints: cfa_store.reg == sp
2270 effects: current_fde.stack_realign = 1
2271 cfa_store.offset = 0
2272 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2275 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2276 effects: cfa_store.offset += -/+ mode_size(mem)
2279 (set (mem ({pre_inc, pre_dec} sp)) fp)
2280 constraints: fde->stack_realign == 1
2281 effects: cfa_store.offset = 0
2282 cfa.reg != HARD_FRAME_POINTER_REGNUM
2285 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2286 constraints: fde->stack_realign == 1
2288 && cfa.indirect == 0
2289 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2290 effects: Use DW_CFA_def_cfa_expression to define cfa
2291 cfa.reg == fde->drap_reg */
2294 dwarf2out_frame_debug_expr (rtx expr
, const char *label
)
2296 rtx src
, dest
, span
;
2297 HOST_WIDE_INT offset
;
2300 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2301 the PARALLEL independently. The first element is always processed if
2302 it is a SET. This is for backward compatibility. Other elements
2303 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2304 flag is set in them. */
2305 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
2308 int limit
= XVECLEN (expr
, 0);
2311 /* PARALLELs have strict read-modify-write semantics, so we
2312 ought to evaluate every rvalue before changing any lvalue.
2313 It's cumbersome to do that in general, but there's an
2314 easy approximation that is enough for all current users:
2315 handle register saves before register assignments. */
2316 if (GET_CODE (expr
) == PARALLEL
)
2317 for (par_index
= 0; par_index
< limit
; par_index
++)
2319 elem
= XVECEXP (expr
, 0, par_index
);
2320 if (GET_CODE (elem
) == SET
2321 && MEM_P (SET_DEST (elem
))
2322 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
2323 dwarf2out_frame_debug_expr (elem
, label
);
2326 for (par_index
= 0; par_index
< limit
; par_index
++)
2328 elem
= XVECEXP (expr
, 0, par_index
);
2329 if (GET_CODE (elem
) == SET
2330 && (!MEM_P (SET_DEST (elem
)) || GET_CODE (expr
) == SEQUENCE
)
2331 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
2332 dwarf2out_frame_debug_expr (elem
, label
);
2333 else if (GET_CODE (elem
) == SET
2335 && !RTX_FRAME_RELATED_P (elem
))
2337 /* Stack adjustment combining might combine some post-prologue
2338 stack adjustment into a prologue stack adjustment. */
2339 HOST_WIDE_INT offset
= stack_adjust_offset (elem
, args_size
, 0);
2342 dwarf2out_stack_adjust (offset
, label
);
2348 gcc_assert (GET_CODE (expr
) == SET
);
2350 src
= SET_SRC (expr
);
2351 dest
= SET_DEST (expr
);
2355 rtx rsi
= reg_saved_in (src
);
2360 fde
= current_fde ();
2362 switch (GET_CODE (dest
))
2365 switch (GET_CODE (src
))
2367 /* Setting FP from SP. */
2369 if (cfa
.reg
== (unsigned) REGNO (src
))
2372 /* Update the CFA rule wrt SP or FP. Make sure src is
2373 relative to the current CFA register.
2375 We used to require that dest be either SP or FP, but the
2376 ARM copies SP to a temporary register, and from there to
2377 FP. So we just rely on the backends to only set
2378 RTX_FRAME_RELATED_P on appropriate insns. */
2379 cfa
.reg
= REGNO (dest
);
2380 cfa_temp
.reg
= cfa
.reg
;
2381 cfa_temp
.offset
= cfa
.offset
;
2385 /* Saving a register in a register. */
2386 gcc_assert (!fixed_regs
[REGNO (dest
)]
2387 /* For the SPARC and its register window. */
2388 || (DWARF_FRAME_REGNUM (REGNO (src
))
2389 == DWARF_FRAME_RETURN_COLUMN
));
2391 /* After stack is aligned, we can only save SP in FP
2392 if drap register is used. In this case, we have
2393 to restore stack pointer with the CFA value and we
2394 don't generate this DWARF information. */
2396 && fde
->stack_realign
2397 && REGNO (src
) == STACK_POINTER_REGNUM
)
2398 gcc_assert (REGNO (dest
) == HARD_FRAME_POINTER_REGNUM
2399 && fde
->drap_reg
!= INVALID_REGNUM
2400 && cfa
.reg
!= REGNO (src
));
2402 queue_reg_save (label
, src
, dest
, 0);
2409 if (dest
== stack_pointer_rtx
)
2413 switch (GET_CODE (XEXP (src
, 1)))
2416 offset
= INTVAL (XEXP (src
, 1));
2419 gcc_assert ((unsigned) REGNO (XEXP (src
, 1))
2421 offset
= cfa_temp
.offset
;
2427 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
2429 /* Restoring SP from FP in the epilogue. */
2430 gcc_assert (cfa
.reg
== (unsigned) HARD_FRAME_POINTER_REGNUM
);
2431 cfa
.reg
= STACK_POINTER_REGNUM
;
2433 else if (GET_CODE (src
) == LO_SUM
)
2434 /* Assume we've set the source reg of the LO_SUM from sp. */
2437 gcc_assert (XEXP (src
, 0) == stack_pointer_rtx
);
2439 if (GET_CODE (src
) != MINUS
)
2441 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2442 cfa
.offset
+= offset
;
2443 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
2444 cfa_store
.offset
+= offset
;
2446 else if (dest
== hard_frame_pointer_rtx
)
2449 /* Either setting the FP from an offset of the SP,
2450 or adjusting the FP */
2451 gcc_assert (frame_pointer_needed
);
2453 gcc_assert (REG_P (XEXP (src
, 0))
2454 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
2455 && CONST_INT_P (XEXP (src
, 1)));
2456 offset
= INTVAL (XEXP (src
, 1));
2457 if (GET_CODE (src
) != MINUS
)
2459 cfa
.offset
+= offset
;
2460 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
2464 gcc_assert (GET_CODE (src
) != MINUS
);
2467 if (REG_P (XEXP (src
, 0))
2468 && REGNO (XEXP (src
, 0)) == cfa
.reg
2469 && CONST_INT_P (XEXP (src
, 1)))
2471 /* Setting a temporary CFA register that will be copied
2472 into the FP later on. */
2473 offset
= - INTVAL (XEXP (src
, 1));
2474 cfa
.offset
+= offset
;
2475 cfa
.reg
= REGNO (dest
);
2476 /* Or used to save regs to the stack. */
2477 cfa_temp
.reg
= cfa
.reg
;
2478 cfa_temp
.offset
= cfa
.offset
;
2482 else if (REG_P (XEXP (src
, 0))
2483 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
2484 && XEXP (src
, 1) == stack_pointer_rtx
)
2486 /* Setting a scratch register that we will use instead
2487 of SP for saving registers to the stack. */
2488 gcc_assert (cfa
.reg
== STACK_POINTER_REGNUM
);
2489 cfa_store
.reg
= REGNO (dest
);
2490 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
2494 else if (GET_CODE (src
) == LO_SUM
2495 && CONST_INT_P (XEXP (src
, 1)))
2497 cfa_temp
.reg
= REGNO (dest
);
2498 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
2507 cfa_temp
.reg
= REGNO (dest
);
2508 cfa_temp
.offset
= INTVAL (src
);
2513 gcc_assert (REG_P (XEXP (src
, 0))
2514 && (unsigned) REGNO (XEXP (src
, 0)) == cfa_temp
.reg
2515 && CONST_INT_P (XEXP (src
, 1)));
2517 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
2518 cfa_temp
.reg
= REGNO (dest
);
2519 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
2522 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2523 which will fill in all of the bits. */
2530 case UNSPEC_VOLATILE
:
2531 gcc_assert (targetm
.dwarf_handle_frame_unspec
);
2532 targetm
.dwarf_handle_frame_unspec (label
, expr
, XINT (src
, 1));
2537 /* If this AND operation happens on stack pointer in prologue,
2538 we assume the stack is realigned and we extract the
2540 if (fde
&& XEXP (src
, 0) == stack_pointer_rtx
)
2542 /* We interpret reg_save differently with stack_realign set.
2543 Thus we must flush whatever we have queued first. */
2544 dwarf2out_flush_queued_reg_saves ();
2546 gcc_assert (cfa_store
.reg
== REGNO (XEXP (src
, 0)));
2547 fde
->stack_realign
= 1;
2548 fde
->stack_realignment
= INTVAL (XEXP (src
, 1));
2549 cfa_store
.offset
= 0;
2551 if (cfa
.reg
!= STACK_POINTER_REGNUM
2552 && cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
)
2553 fde
->drap_reg
= cfa
.reg
;
2561 def_cfa_1 (label
, &cfa
);
2566 /* Saving a register to the stack. Make sure dest is relative to the
2568 switch (GET_CODE (XEXP (dest
, 0)))
2573 /* We can't handle variable size modifications. */
2574 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1))
2576 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
2578 gcc_assert (REGNO (XEXP (XEXP (dest
, 0), 0)) == STACK_POINTER_REGNUM
2579 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
2581 cfa_store
.offset
+= offset
;
2582 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2583 cfa
.offset
= cfa_store
.offset
;
2585 offset
= -cfa_store
.offset
;
2592 offset
= GET_MODE_SIZE (GET_MODE (dest
));
2593 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
2596 gcc_assert ((REGNO (XEXP (XEXP (dest
, 0), 0))
2597 == STACK_POINTER_REGNUM
)
2598 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
2600 cfa_store
.offset
+= offset
;
2602 /* Rule 18: If stack is aligned, we will use FP as a
2603 reference to represent the address of the stored
2606 && fde
->stack_realign
2607 && src
== hard_frame_pointer_rtx
)
2609 gcc_assert (cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
);
2610 cfa_store
.offset
= 0;
2613 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2614 cfa
.offset
= cfa_store
.offset
;
2616 if (GET_CODE (XEXP (dest
, 0)) == POST_DEC
)
2617 offset
+= -cfa_store
.offset
;
2619 offset
= -cfa_store
.offset
;
2623 /* With an offset. */
2630 gcc_assert (CONST_INT_P (XEXP (XEXP (dest
, 0), 1))
2631 && REG_P (XEXP (XEXP (dest
, 0), 0)));
2632 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
2633 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
2636 regno
= REGNO (XEXP (XEXP (dest
, 0), 0));
2638 if (cfa
.reg
== (unsigned) regno
)
2639 offset
-= cfa
.offset
;
2640 else if (cfa_store
.reg
== (unsigned) regno
)
2641 offset
-= cfa_store
.offset
;
2644 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
2645 offset
-= cfa_temp
.offset
;
2651 /* Without an offset. */
2654 int regno
= REGNO (XEXP (dest
, 0));
2656 if (cfa
.reg
== (unsigned) regno
)
2657 offset
= -cfa
.offset
;
2658 else if (cfa_store
.reg
== (unsigned) regno
)
2659 offset
= -cfa_store
.offset
;
2662 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
2663 offset
= -cfa_temp
.offset
;
2670 gcc_assert (cfa_temp
.reg
2671 == (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)));
2672 offset
= -cfa_temp
.offset
;
2673 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
2681 /* If the source operand of this MEM operation is not a
2682 register, basically the source is return address. Here
2683 we only care how much stack grew and we don't save it. */
2687 if (REGNO (src
) != STACK_POINTER_REGNUM
2688 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
2689 && (unsigned) REGNO (src
) == cfa
.reg
)
2691 /* We're storing the current CFA reg into the stack. */
2693 if (cfa
.offset
== 0)
2696 /* If stack is aligned, putting CFA reg into stack means
2697 we can no longer use reg + offset to represent CFA.
2698 Here we use DW_CFA_def_cfa_expression instead. The
2699 result of this expression equals to the original CFA
2702 && fde
->stack_realign
2703 && cfa
.indirect
== 0
2704 && cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
)
2706 dw_cfa_location cfa_exp
;
2708 gcc_assert (fde
->drap_reg
== cfa
.reg
);
2710 cfa_exp
.indirect
= 1;
2711 cfa_exp
.reg
= HARD_FRAME_POINTER_REGNUM
;
2712 cfa_exp
.base_offset
= offset
;
2715 fde
->drap_reg_saved
= 1;
2717 def_cfa_1 (label
, &cfa_exp
);
2721 /* If the source register is exactly the CFA, assume
2722 we're saving SP like any other register; this happens
2724 def_cfa_1 (label
, &cfa
);
2725 queue_reg_save (label
, stack_pointer_rtx
, NULL_RTX
, offset
);
2730 /* Otherwise, we'll need to look in the stack to
2731 calculate the CFA. */
2732 rtx x
= XEXP (dest
, 0);
2736 gcc_assert (REG_P (x
));
2738 cfa
.reg
= REGNO (x
);
2739 cfa
.base_offset
= offset
;
2741 def_cfa_1 (label
, &cfa
);
2746 def_cfa_1 (label
, &cfa
);
2748 span
= targetm
.dwarf_register_span (src
);
2751 queue_reg_save (label
, src
, NULL_RTX
, offset
);
2754 /* We have a PARALLEL describing where the contents of SRC
2755 live. Queue register saves for each piece of the
2759 HOST_WIDE_INT span_offset
= offset
;
2761 gcc_assert (GET_CODE (span
) == PARALLEL
);
2763 limit
= XVECLEN (span
, 0);
2764 for (par_index
= 0; par_index
< limit
; par_index
++)
2766 rtx elem
= XVECEXP (span
, 0, par_index
);
2768 queue_reg_save (label
, elem
, NULL_RTX
, span_offset
);
2769 span_offset
+= GET_MODE_SIZE (GET_MODE (elem
));
2780 /* Record call frame debugging information for INSN, which either
2781 sets SP or FP (adjusting how we calculate the frame address) or saves a
2782 register to the stack. If INSN is NULL_RTX, initialize our state.
2784 If AFTER_P is false, we're being called before the insn is emitted,
2785 otherwise after. Call instructions get invoked twice. */
2788 dwarf2out_frame_debug (rtx insn
, bool after_p
)
2792 bool handled_one
= false;
2794 if (!NONJUMP_INSN_P (insn
) || clobbers_queued_reg_save (insn
))
2795 dwarf2out_flush_queued_reg_saves ();
2797 if (!RTX_FRAME_RELATED_P (insn
))
2799 /* ??? This should be done unconditionally since stack adjustments
2800 matter if the stack pointer is not the CFA register anymore but
2801 is still used to save registers. */
2802 if (!ACCUMULATE_OUTGOING_ARGS
)
2803 dwarf2out_notice_stack_adjust (insn
, after_p
);
2807 label
= dwarf2out_cfi_label (false);
2808 any_cfis_emitted
= false;
2810 for (note
= REG_NOTES (insn
); note
; note
= XEXP (note
, 1))
2811 switch (REG_NOTE_KIND (note
))
2813 case REG_FRAME_RELATED_EXPR
:
2814 insn
= XEXP (note
, 0);
2817 case REG_CFA_DEF_CFA
:
2818 dwarf2out_frame_debug_def_cfa (XEXP (note
, 0), label
);
2822 case REG_CFA_ADJUST_CFA
:
2827 if (GET_CODE (n
) == PARALLEL
)
2828 n
= XVECEXP (n
, 0, 0);
2830 dwarf2out_frame_debug_adjust_cfa (n
, label
);
2834 case REG_CFA_OFFSET
:
2837 n
= single_set (insn
);
2838 dwarf2out_frame_debug_cfa_offset (n
, label
);
2842 case REG_CFA_REGISTER
:
2847 if (GET_CODE (n
) == PARALLEL
)
2848 n
= XVECEXP (n
, 0, 0);
2850 dwarf2out_frame_debug_cfa_register (n
, label
);
2854 case REG_CFA_EXPRESSION
:
2857 n
= single_set (insn
);
2858 dwarf2out_frame_debug_cfa_expression (n
, label
);
2862 case REG_CFA_RESTORE
:
2867 if (GET_CODE (n
) == PARALLEL
)
2868 n
= XVECEXP (n
, 0, 0);
2871 dwarf2out_frame_debug_cfa_restore (n
, label
);
2875 case REG_CFA_SET_VDRAP
:
2879 dw_fde_ref fde
= current_fde ();
2882 gcc_assert (fde
->vdrap_reg
== INVALID_REGNUM
);
2884 fde
->vdrap_reg
= REGNO (n
);
2895 if (any_cfis_emitted
)
2896 dwarf2out_flush_queued_reg_saves ();
2900 insn
= PATTERN (insn
);
2902 dwarf2out_frame_debug_expr (insn
, label
);
2904 /* Check again. A parallel can save and update the same register.
2905 We could probably check just once, here, but this is safer than
2906 removing the check above. */
2907 if (any_cfis_emitted
|| clobbers_queued_reg_save (insn
))
2908 dwarf2out_flush_queued_reg_saves ();
2911 /* Called once at the start of final to initialize some data for the
2912 current function. */
2914 dwarf2out_frame_debug_init (void)
2918 /* Flush any queued register saves. */
2919 dwarf2out_flush_queued_reg_saves ();
2921 /* Set up state for generating call frame debug info. */
2924 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
));
2926 cfa
.reg
= STACK_POINTER_REGNUM
;
2929 cfa_temp
.offset
= 0;
2931 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
2933 regs_saved_in_regs
[i
].orig_reg
= NULL_RTX
;
2934 regs_saved_in_regs
[i
].saved_in_reg
= NULL_RTX
;
2936 num_regs_saved_in_regs
= 0;
2938 if (barrier_args_size
)
2940 XDELETEVEC (barrier_args_size
);
2941 barrier_args_size
= NULL
;
2945 /* Determine if we need to save and restore CFI information around this
2946 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2947 we do need to save/restore, then emit the save now, and insert a
2948 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2951 dwarf2out_cfi_begin_epilogue (rtx insn
)
2953 bool saw_frp
= false;
2956 /* Scan forward to the return insn, noticing if there are possible
2957 frame related insns. */
2958 for (i
= NEXT_INSN (insn
); i
; i
= NEXT_INSN (i
))
2963 /* Look for both regular and sibcalls to end the block. */
2964 if (returnjump_p (i
))
2966 if (CALL_P (i
) && SIBLING_CALL_P (i
))
2969 if (GET_CODE (PATTERN (i
)) == SEQUENCE
)
2972 rtx seq
= PATTERN (i
);
2974 if (returnjump_p (XVECEXP (seq
, 0, 0)))
2976 if (CALL_P (XVECEXP (seq
, 0, 0))
2977 && SIBLING_CALL_P (XVECEXP (seq
, 0, 0)))
2980 for (idx
= 0; idx
< XVECLEN (seq
, 0); idx
++)
2981 if (RTX_FRAME_RELATED_P (XVECEXP (seq
, 0, idx
)))
2985 if (RTX_FRAME_RELATED_P (i
))
2989 /* If the port doesn't emit epilogue unwind info, we don't need a
2990 save/restore pair. */
2994 /* Otherwise, search forward to see if the return insn was the last
2995 basic block of the function. If so, we don't need save/restore. */
2996 gcc_assert (i
!= NULL
);
2997 i
= next_real_insn (i
);
3001 /* Insert the restore before that next real insn in the stream, and before
3002 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
3003 properly nested. This should be after any label or alignment. This
3004 will be pushed into the CFI stream by the function below. */
3007 rtx p
= PREV_INSN (i
);
3010 if (NOTE_KIND (p
) == NOTE_INSN_BASIC_BLOCK
)
3014 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE
, i
);
3016 emit_cfa_remember
= true;
3018 /* And emulate the state save. */
3019 gcc_assert (!cfa_remember
.in_use
);
3021 cfa_remember
.in_use
= 1;
3024 /* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
3028 dwarf2out_frame_debug_restore_state (void)
3030 dw_cfi_ref cfi
= new_cfi ();
3031 const char *label
= dwarf2out_cfi_label (false);
3033 cfi
->dw_cfi_opc
= DW_CFA_restore_state
;
3034 add_fde_cfi (label
, cfi
);
3036 gcc_assert (cfa_remember
.in_use
);
3038 cfa_remember
.in_use
= 0;
3041 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
3042 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
3043 (enum dwarf_call_frame_info cfi
);
3045 static enum dw_cfi_oprnd_type
3046 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
3051 case DW_CFA_GNU_window_save
:
3052 case DW_CFA_remember_state
:
3053 case DW_CFA_restore_state
:
3054 return dw_cfi_oprnd_unused
;
3056 case DW_CFA_set_loc
:
3057 case DW_CFA_advance_loc1
:
3058 case DW_CFA_advance_loc2
:
3059 case DW_CFA_advance_loc4
:
3060 case DW_CFA_MIPS_advance_loc8
:
3061 return dw_cfi_oprnd_addr
;
3064 case DW_CFA_offset_extended
:
3065 case DW_CFA_def_cfa
:
3066 case DW_CFA_offset_extended_sf
:
3067 case DW_CFA_def_cfa_sf
:
3068 case DW_CFA_restore
:
3069 case DW_CFA_restore_extended
:
3070 case DW_CFA_undefined
:
3071 case DW_CFA_same_value
:
3072 case DW_CFA_def_cfa_register
:
3073 case DW_CFA_register
:
3074 case DW_CFA_expression
:
3075 return dw_cfi_oprnd_reg_num
;
3077 case DW_CFA_def_cfa_offset
:
3078 case DW_CFA_GNU_args_size
:
3079 case DW_CFA_def_cfa_offset_sf
:
3080 return dw_cfi_oprnd_offset
;
3082 case DW_CFA_def_cfa_expression
:
3083 return dw_cfi_oprnd_loc
;
3090 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
3091 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
3092 (enum dwarf_call_frame_info cfi
);
3094 static enum dw_cfi_oprnd_type
3095 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
3099 case DW_CFA_def_cfa
:
3100 case DW_CFA_def_cfa_sf
:
3102 case DW_CFA_offset_extended_sf
:
3103 case DW_CFA_offset_extended
:
3104 return dw_cfi_oprnd_offset
;
3106 case DW_CFA_register
:
3107 return dw_cfi_oprnd_reg_num
;
3109 case DW_CFA_expression
:
3110 return dw_cfi_oprnd_loc
;
3113 return dw_cfi_oprnd_unused
;
3117 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
3118 switch to the data section instead, and write out a synthetic start label
3119 for collect2 the first time around. */
3122 switch_to_eh_frame_section (bool back
)
3126 #ifdef EH_FRAME_SECTION_NAME
3127 if (eh_frame_section
== 0)
3131 if (EH_TABLES_CAN_BE_READ_ONLY
)
3137 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
3139 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
3141 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
3143 flags
= ((! flag_pic
3144 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
3145 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
3146 && (per_encoding
& 0x70) != DW_EH_PE_absptr
3147 && (per_encoding
& 0x70) != DW_EH_PE_aligned
3148 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
3149 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
3150 ? 0 : SECTION_WRITE
);
3153 flags
= SECTION_WRITE
;
3154 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
3156 #endif /* EH_FRAME_SECTION_NAME */
3158 if (eh_frame_section
)
3159 switch_to_section (eh_frame_section
);
3162 /* We have no special eh_frame section. Put the information in
3163 the data section and emit special labels to guide collect2. */
3164 switch_to_section (data_section
);
3168 label
= get_file_function_name ("F");
3169 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
3170 targetm
.asm_out
.globalize_label (asm_out_file
,
3171 IDENTIFIER_POINTER (label
));
3172 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
3177 /* Switch [BACK] to the eh or debug frame table section, depending on
3181 switch_to_frame_table_section (int for_eh
, bool back
)
3184 switch_to_eh_frame_section (back
);
3187 if (!debug_frame_section
)
3188 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
3189 SECTION_DEBUG
, NULL
);
3190 switch_to_section (debug_frame_section
);
3194 /* Output a Call Frame Information opcode and its operand(s). */
3197 output_cfi (dw_cfi_ref cfi
, dw_fde_ref fde
, int for_eh
)
3202 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
3203 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
3204 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
3205 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX
,
3206 ((unsigned HOST_WIDE_INT
)
3207 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
));
3208 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
3210 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3211 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
3212 "DW_CFA_offset, column %#lx", r
);
3213 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3214 dw2_asm_output_data_uleb128 (off
, NULL
);
3216 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
3218 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3219 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
3220 "DW_CFA_restore, column %#lx", r
);
3224 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
3225 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
3227 switch (cfi
->dw_cfi_opc
)
3229 case DW_CFA_set_loc
:
3231 dw2_asm_output_encoded_addr_rtx (
3232 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3233 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
3236 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
3237 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
3238 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3241 case DW_CFA_advance_loc1
:
3242 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3243 fde
->dw_fde_current_label
, NULL
);
3244 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3247 case DW_CFA_advance_loc2
:
3248 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3249 fde
->dw_fde_current_label
, NULL
);
3250 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3253 case DW_CFA_advance_loc4
:
3254 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3255 fde
->dw_fde_current_label
, NULL
);
3256 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3259 case DW_CFA_MIPS_advance_loc8
:
3260 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3261 fde
->dw_fde_current_label
, NULL
);
3262 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3265 case DW_CFA_offset_extended
:
3266 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3267 dw2_asm_output_data_uleb128 (r
, NULL
);
3268 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3269 dw2_asm_output_data_uleb128 (off
, NULL
);
3272 case DW_CFA_def_cfa
:
3273 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3274 dw2_asm_output_data_uleb128 (r
, NULL
);
3275 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
3278 case DW_CFA_offset_extended_sf
:
3279 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3280 dw2_asm_output_data_uleb128 (r
, NULL
);
3281 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3282 dw2_asm_output_data_sleb128 (off
, NULL
);
3285 case DW_CFA_def_cfa_sf
:
3286 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3287 dw2_asm_output_data_uleb128 (r
, NULL
);
3288 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3289 dw2_asm_output_data_sleb128 (off
, NULL
);
3292 case DW_CFA_restore_extended
:
3293 case DW_CFA_undefined
:
3294 case DW_CFA_same_value
:
3295 case DW_CFA_def_cfa_register
:
3296 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3297 dw2_asm_output_data_uleb128 (r
, NULL
);
3300 case DW_CFA_register
:
3301 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3302 dw2_asm_output_data_uleb128 (r
, NULL
);
3303 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, for_eh
);
3304 dw2_asm_output_data_uleb128 (r
, NULL
);
3307 case DW_CFA_def_cfa_offset
:
3308 case DW_CFA_GNU_args_size
:
3309 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
3312 case DW_CFA_def_cfa_offset_sf
:
3313 off
= div_data_align (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3314 dw2_asm_output_data_sleb128 (off
, NULL
);
3317 case DW_CFA_GNU_window_save
:
3320 case DW_CFA_def_cfa_expression
:
3321 case DW_CFA_expression
:
3322 output_cfa_loc (cfi
, for_eh
);
3325 case DW_CFA_GNU_negative_offset_extended
:
3326 /* Obsoleted by DW_CFA_offset_extended_sf. */
3335 /* Similar, but do it via assembler directives instead. */
3338 output_cfi_directive (dw_cfi_ref cfi
)
3340 unsigned long r
, r2
;
3342 switch (cfi
->dw_cfi_opc
)
3344 case DW_CFA_advance_loc
:
3345 case DW_CFA_advance_loc1
:
3346 case DW_CFA_advance_loc2
:
3347 case DW_CFA_advance_loc4
:
3348 case DW_CFA_MIPS_advance_loc8
:
3349 case DW_CFA_set_loc
:
3350 /* Should only be created by add_fde_cfi in a code path not
3351 followed when emitting via directives. The assembler is
3352 going to take care of this for us. */
3356 case DW_CFA_offset_extended
:
3357 case DW_CFA_offset_extended_sf
:
3358 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3359 fprintf (asm_out_file
, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC
"\n",
3360 r
, cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3363 case DW_CFA_restore
:
3364 case DW_CFA_restore_extended
:
3365 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3366 fprintf (asm_out_file
, "\t.cfi_restore %lu\n", r
);
3369 case DW_CFA_undefined
:
3370 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3371 fprintf (asm_out_file
, "\t.cfi_undefined %lu\n", r
);
3374 case DW_CFA_same_value
:
3375 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3376 fprintf (asm_out_file
, "\t.cfi_same_value %lu\n", r
);
3379 case DW_CFA_def_cfa
:
3380 case DW_CFA_def_cfa_sf
:
3381 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3382 fprintf (asm_out_file
, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC
"\n",
3383 r
, cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3386 case DW_CFA_def_cfa_register
:
3387 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3388 fprintf (asm_out_file
, "\t.cfi_def_cfa_register %lu\n", r
);
3391 case DW_CFA_register
:
3392 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3393 r2
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, 1);
3394 fprintf (asm_out_file
, "\t.cfi_register %lu, %lu\n", r
, r2
);
3397 case DW_CFA_def_cfa_offset
:
3398 case DW_CFA_def_cfa_offset_sf
:
3399 fprintf (asm_out_file
, "\t.cfi_def_cfa_offset "
3400 HOST_WIDE_INT_PRINT_DEC
"\n",
3401 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3404 case DW_CFA_remember_state
:
3405 fprintf (asm_out_file
, "\t.cfi_remember_state\n");
3407 case DW_CFA_restore_state
:
3408 fprintf (asm_out_file
, "\t.cfi_restore_state\n");
3411 case DW_CFA_GNU_args_size
:
3412 fprintf (asm_out_file
, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size
);
3413 dw2_asm_output_data_uleb128_raw (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3415 fprintf (asm_out_file
, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC
,
3416 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3417 fputc ('\n', asm_out_file
);
3420 case DW_CFA_GNU_window_save
:
3421 fprintf (asm_out_file
, "\t.cfi_window_save\n");
3424 case DW_CFA_def_cfa_expression
:
3425 case DW_CFA_expression
:
3426 fprintf (asm_out_file
, "\t.cfi_escape %#x,", cfi
->dw_cfi_opc
);
3427 output_cfa_loc_raw (cfi
);
3428 fputc ('\n', asm_out_file
);
3436 /* Output CFIs from VEC, up to index UPTO, to bring current FDE to the
3437 same state as after executing CFIs in CFI chain. DO_CFI_ASM is
3438 true if .cfi_* directives shall be emitted, false otherwise. If it
3439 is false, FDE and FOR_EH are the other arguments to pass to
3443 output_cfis (cfi_vec vec
, int upto
, bool do_cfi_asm
,
3444 dw_fde_ref fde
, bool for_eh
)
3447 struct dw_cfi_struct cfi_buf
;
3449 dw_cfi_ref cfi_args_size
= NULL
, cfi_cfa
= NULL
, cfi_cfa_offset
= NULL
;
3450 VEC(dw_cfi_ref
, heap
) *regs
= VEC_alloc (dw_cfi_ref
, heap
, 32);
3451 unsigned int len
, idx
;
3453 for (ix
= 0; ix
< upto
+ 1; ix
++)
3455 dw_cfi_ref cfi
= ix
< upto
? VEC_index (dw_cfi_ref
, vec
, ix
) : NULL
;
3456 switch (cfi
? cfi
->dw_cfi_opc
: DW_CFA_nop
)
3458 case DW_CFA_advance_loc
:
3459 case DW_CFA_advance_loc1
:
3460 case DW_CFA_advance_loc2
:
3461 case DW_CFA_advance_loc4
:
3462 case DW_CFA_MIPS_advance_loc8
:
3463 case DW_CFA_set_loc
:
3464 /* All advances should be ignored. */
3466 case DW_CFA_remember_state
:
3468 dw_cfi_ref args_size
= cfi_args_size
;
3470 /* Skip everything between .cfi_remember_state and
3471 .cfi_restore_state. */
3476 for (; ix
< upto
; ix
++)
3478 cfi2
= VEC_index (dw_cfi_ref
, vec
, ix
);
3479 if (cfi2
->dw_cfi_opc
== DW_CFA_restore_state
)
3481 else if (cfi2
->dw_cfi_opc
== DW_CFA_GNU_args_size
)
3484 gcc_assert (cfi2
->dw_cfi_opc
!= DW_CFA_remember_state
);
3487 cfi_args_size
= args_size
;
3490 case DW_CFA_GNU_args_size
:
3491 cfi_args_size
= cfi
;
3493 case DW_CFA_GNU_window_save
:
3496 case DW_CFA_offset_extended
:
3497 case DW_CFA_offset_extended_sf
:
3498 case DW_CFA_restore
:
3499 case DW_CFA_restore_extended
:
3500 case DW_CFA_undefined
:
3501 case DW_CFA_same_value
:
3502 case DW_CFA_register
:
3503 case DW_CFA_val_offset
:
3504 case DW_CFA_val_offset_sf
:
3505 case DW_CFA_expression
:
3506 case DW_CFA_val_expression
:
3507 case DW_CFA_GNU_negative_offset_extended
:
3508 if (VEC_length (dw_cfi_ref
, regs
)
3509 <= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
)
3510 VEC_safe_grow_cleared (dw_cfi_ref
, heap
, regs
,
3511 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
+ 1);
3512 VEC_replace (dw_cfi_ref
, regs
, cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
3515 case DW_CFA_def_cfa
:
3516 case DW_CFA_def_cfa_sf
:
3517 case DW_CFA_def_cfa_expression
:
3519 cfi_cfa_offset
= cfi
;
3521 case DW_CFA_def_cfa_register
:
3524 case DW_CFA_def_cfa_offset
:
3525 case DW_CFA_def_cfa_offset_sf
:
3526 cfi_cfa_offset
= cfi
;
3529 gcc_assert (cfi
== NULL
);
3531 len
= VEC_length (dw_cfi_ref
, regs
);
3532 for (idx
= 0; idx
< len
; idx
++)
3534 cfi2
= VEC_replace (dw_cfi_ref
, regs
, idx
, NULL
);
3536 && cfi2
->dw_cfi_opc
!= DW_CFA_restore
3537 && cfi2
->dw_cfi_opc
!= DW_CFA_restore_extended
)
3540 output_cfi_directive (cfi2
);
3542 output_cfi (cfi2
, fde
, for_eh
);
3545 if (cfi_cfa
&& cfi_cfa_offset
&& cfi_cfa_offset
!= cfi_cfa
)
3547 gcc_assert (cfi_cfa
->dw_cfi_opc
!= DW_CFA_def_cfa_expression
);
3549 switch (cfi_cfa_offset
->dw_cfi_opc
)
3551 case DW_CFA_def_cfa_offset
:
3552 cfi_buf
.dw_cfi_opc
= DW_CFA_def_cfa
;
3553 cfi_buf
.dw_cfi_oprnd2
= cfi_cfa_offset
->dw_cfi_oprnd1
;
3555 case DW_CFA_def_cfa_offset_sf
:
3556 cfi_buf
.dw_cfi_opc
= DW_CFA_def_cfa_sf
;
3557 cfi_buf
.dw_cfi_oprnd2
= cfi_cfa_offset
->dw_cfi_oprnd1
;
3559 case DW_CFA_def_cfa
:
3560 case DW_CFA_def_cfa_sf
:
3561 cfi_buf
.dw_cfi_opc
= cfi_cfa_offset
->dw_cfi_opc
;
3562 cfi_buf
.dw_cfi_oprnd2
= cfi_cfa_offset
->dw_cfi_oprnd2
;
3569 else if (cfi_cfa_offset
)
3570 cfi_cfa
= cfi_cfa_offset
;
3574 output_cfi_directive (cfi_cfa
);
3576 output_cfi (cfi_cfa
, fde
, for_eh
);
3579 cfi_cfa_offset
= NULL
;
3581 && cfi_args_size
->dw_cfi_oprnd1
.dw_cfi_offset
)
3584 output_cfi_directive (cfi_args_size
);
3586 output_cfi (cfi_args_size
, fde
, for_eh
);
3588 cfi_args_size
= NULL
;
3591 VEC_free (dw_cfi_ref
, heap
, regs
);
3594 else if (do_cfi_asm
)
3595 output_cfi_directive (cfi
);
3597 output_cfi (cfi
, fde
, for_eh
);
3605 /* Like output_cfis, but emit all CFIs in the vector. */
3607 output_all_cfis (cfi_vec vec
, bool do_cfi_asm
,
3608 dw_fde_ref fde
, bool for_eh
)
3610 output_cfis (vec
, VEC_length (dw_cfi_ref
, vec
), do_cfi_asm
, fde
, for_eh
);
3613 /* Output one FDE. */
3616 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
3617 char *section_start_label
, int fde_encoding
, char *augmentation
,
3618 bool any_lsda_needed
, int lsda_encoding
)
3621 const char *begin
, *end
;
3622 static unsigned int j
;
3623 char l1
[20], l2
[20];
3626 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
3628 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
3630 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
3631 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
3632 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
3633 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3634 " indicating 64-bit DWARF extension");
3635 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
3637 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
3640 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
3642 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
3643 debug_frame_section
, "FDE CIE offset");
3645 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
3646 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
3650 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
3651 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
3652 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
3653 "FDE initial location");
3654 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
3655 end
, begin
, "FDE address range");
3659 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
3660 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
3663 if (augmentation
[0])
3665 if (any_lsda_needed
)
3667 int size
= size_of_encoded_value (lsda_encoding
);
3669 if (lsda_encoding
== DW_EH_PE_aligned
)
3671 int offset
= ( 4 /* Length */
3672 + 4 /* CIE offset */
3673 + 2 * size_of_encoded_value (fde_encoding
)
3674 + 1 /* Augmentation size */ );
3675 int pad
= -offset
& (PTR_SIZE
- 1);
3678 gcc_assert (size_of_uleb128 (size
) == 1);
3681 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
3683 if (fde
->uses_eh_lsda
)
3685 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
3686 fde
->funcdef_number
);
3687 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
3688 gen_rtx_SYMBOL_REF (Pmode
, l1
),
3690 "Language Specific Data Area");
3694 if (lsda_encoding
== DW_EH_PE_aligned
)
3695 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
3696 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
3697 "Language Specific Data Area (none)");
3701 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3704 /* Loop through the Call Frame Instructions associated with
3706 fde
->dw_fde_current_label
= begin
;
3707 if (fde
->dw_fde_second_begin
== NULL
)
3708 FOR_EACH_VEC_ELT (dw_cfi_ref
, fde
->dw_fde_cfi
, ix
, cfi
)
3709 output_cfi (cfi
, fde
, for_eh
);
3712 if (fde
->dw_fde_switch_cfi_index
> 0)
3713 FOR_EACH_VEC_ELT (dw_cfi_ref
, fde
->dw_fde_cfi
, ix
, cfi
)
3715 if (ix
== fde
->dw_fde_switch_cfi_index
)
3717 output_cfi (cfi
, fde
, for_eh
);
3723 int until
= VEC_length (dw_cfi_ref
, fde
->dw_fde_cfi
);
3725 if (fde
->dw_fde_switch_cfi_index
> 0)
3727 from
= fde
->dw_fde_switch_cfi_index
;
3728 output_cfis (fde
->dw_fde_cfi
, from
, false, fde
, for_eh
);
3730 for (i
= from
; i
< until
; i
++)
3731 output_cfi (VEC_index (dw_cfi_ref
, fde
->dw_fde_cfi
, i
),
3735 /* If we are to emit a ref/link from function bodies to their frame tables,
3736 do it now. This is typically performed to make sure that tables
3737 associated with functions are dragged with them and not discarded in
3738 garbage collecting links. We need to do this on a per function basis to
3739 cope with -ffunction-sections. */
3741 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3742 /* Switch to the function section, emit the ref to the tables, and
3743 switch *back* into the table section. */
3744 switch_to_section (function_section (fde
->decl
));
3745 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
3746 switch_to_frame_table_section (for_eh
, true);
3749 /* Pad the FDE out to an address sized boundary. */
3750 ASM_OUTPUT_ALIGN (asm_out_file
,
3751 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
3752 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
3757 /* Return true if frame description entry FDE is needed for EH. */
3760 fde_needed_for_eh_p (dw_fde_ref fde
)
3762 if (flag_asynchronous_unwind_tables
)
3765 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
3768 if (fde
->uses_eh_lsda
)
3771 /* If exceptions are enabled, we have collected nothrow info. */
3772 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
3778 /* Output the call frame information used to record information
3779 that relates to calculating the frame pointer, and records the
3780 location of saved registers. */
3783 output_call_frame_info (int for_eh
)
3788 char l1
[20], l2
[20], section_start_label
[20];
3789 bool any_lsda_needed
= false;
3790 char augmentation
[6];
3791 int augmentation_size
;
3792 int fde_encoding
= DW_EH_PE_absptr
;
3793 int per_encoding
= DW_EH_PE_absptr
;
3794 int lsda_encoding
= DW_EH_PE_absptr
;
3796 rtx personality
= NULL
;
3799 /* Don't emit a CIE if there won't be any FDEs. */
3800 if (fde_table_in_use
== 0)
3803 /* Nothing to do if the assembler's doing it all. */
3804 if (dwarf2out_do_cfi_asm ())
3807 /* If we don't have any functions we'll want to unwind out of, don't emit
3808 any EH unwind information. If we make FDEs linkonce, we may have to
3809 emit an empty label for an FDE that wouldn't otherwise be emitted. We
3810 want to avoid having an FDE kept around when the function it refers to
3811 is discarded. Example where this matters: a primary function template
3812 in C++ requires EH information, an explicit specialization doesn't. */
3815 bool any_eh_needed
= false;
3817 for (i
= 0; i
< fde_table_in_use
; i
++)
3818 if (fde_table
[i
].uses_eh_lsda
)
3819 any_eh_needed
= any_lsda_needed
= true;
3820 else if (fde_needed_for_eh_p (&fde_table
[i
]))
3821 any_eh_needed
= true;
3822 else if (TARGET_USES_WEAK_UNWIND_INFO
)
3823 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde_table
[i
].decl
,
3830 /* We're going to be generating comments, so turn on app. */
3834 /* Switch to the proper frame section, first time. */
3835 switch_to_frame_table_section (for_eh
, false);
3837 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
3838 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
3840 /* Output the CIE. */
3841 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
3842 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
3843 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
3844 dw2_asm_output_data (4, 0xffffffff,
3845 "Initial length escape value indicating 64-bit DWARF extension");
3846 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
3847 "Length of Common Information Entry");
3848 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
3850 /* Now that the CIE pointer is PC-relative for EH,
3851 use 0 to identify the CIE. */
3852 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
3853 (for_eh
? 0 : DWARF_CIE_ID
),
3854 "CIE Identifier Tag");
3856 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3857 use CIE version 1, unless that would produce incorrect results
3858 due to overflowing the return register column. */
3859 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
3861 if (return_reg
>= 256 || dwarf_version
> 2)
3863 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
3865 augmentation
[0] = 0;
3866 augmentation_size
= 0;
3868 personality
= current_unit_personality
;
3874 z Indicates that a uleb128 is present to size the
3875 augmentation section.
3876 L Indicates the encoding (and thus presence) of
3877 an LSDA pointer in the FDE augmentation.
3878 R Indicates a non-default pointer encoding for
3880 P Indicates the presence of an encoding + language
3881 personality routine in the CIE augmentation. */
3883 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3884 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3885 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3887 p
= augmentation
+ 1;
3891 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
3892 assemble_external_libcall (personality
);
3894 if (any_lsda_needed
)
3897 augmentation_size
+= 1;
3899 if (fde_encoding
!= DW_EH_PE_absptr
)
3902 augmentation_size
+= 1;
3904 if (p
> augmentation
+ 1)
3906 augmentation
[0] = 'z';
3910 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3911 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
3913 int offset
= ( 4 /* Length */
3915 + 1 /* CIE version */
3916 + strlen (augmentation
) + 1 /* Augmentation */
3917 + size_of_uleb128 (1) /* Code alignment */
3918 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
3920 + 1 /* Augmentation size */
3921 + 1 /* Personality encoding */ );
3922 int pad
= -offset
& (PTR_SIZE
- 1);
3924 augmentation_size
+= pad
;
3926 /* Augmentations should be small, so there's scarce need to
3927 iterate for a solution. Die if we exceed one uleb128 byte. */
3928 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
3932 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
3933 if (dw_cie_version
>= 4)
3935 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
3936 dw2_asm_output_data (1, 0, "CIE Segment Size");
3938 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3939 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
3940 "CIE Data Alignment Factor");
3942 if (dw_cie_version
== 1)
3943 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
3945 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
3947 if (augmentation
[0])
3949 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
3952 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
3953 eh_data_format_name (per_encoding
));
3954 dw2_asm_output_encoded_addr_rtx (per_encoding
,
3959 if (any_lsda_needed
)
3960 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
3961 eh_data_format_name (lsda_encoding
));
3963 if (fde_encoding
!= DW_EH_PE_absptr
)
3964 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
3965 eh_data_format_name (fde_encoding
));
3968 FOR_EACH_VEC_ELT (dw_cfi_ref
, cie_cfi_vec
, i
, cfi
)
3969 output_cfi (cfi
, NULL
, for_eh
);
3971 /* Pad the CIE out to an address sized boundary. */
3972 ASM_OUTPUT_ALIGN (asm_out_file
,
3973 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
3974 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
3976 /* Loop through all of the FDE's. */
3977 for (i
= 0; i
< fde_table_in_use
; i
++)
3980 fde
= &fde_table
[i
];
3982 /* Don't emit EH unwind info for leaf functions that don't need it. */
3983 if (for_eh
&& !fde_needed_for_eh_p (fde
))
3986 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
3987 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
3988 augmentation
, any_lsda_needed
, lsda_encoding
);
3991 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
3992 dw2_asm_output_data (4, 0, "End of Table");
3993 #ifdef MIPS_DEBUGGING_INFO
3994 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3995 get a value of 0. Putting .align 0 after the label fixes it. */
3996 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
3999 /* Turn off app to make assembly quicker. */
4004 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
4007 dwarf2out_do_cfi_startproc (bool second
)
4011 rtx personality
= get_personality_function (current_function_decl
);
4013 fprintf (asm_out_file
, "\t.cfi_startproc\n");
4017 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
4020 /* ??? The GAS support isn't entirely consistent. We have to
4021 handle indirect support ourselves, but PC-relative is done
4022 in the assembler. Further, the assembler can't handle any
4023 of the weirder relocation types. */
4024 if (enc
& DW_EH_PE_indirect
)
4025 ref
= dw2_force_const_mem (ref
, true);
4027 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
4028 output_addr_const (asm_out_file
, ref
);
4029 fputc ('\n', asm_out_file
);
4032 if (crtl
->uses_eh_lsda
)
4036 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
4037 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
4038 current_function_funcdef_no
);
4039 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
4040 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
4042 if (enc
& DW_EH_PE_indirect
)
4043 ref
= dw2_force_const_mem (ref
, true);
4045 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
4046 output_addr_const (asm_out_file
, ref
);
4047 fputc ('\n', asm_out_file
);
4051 /* Output a marker (i.e. a label) for the beginning of a function, before
4055 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
4056 const char *file ATTRIBUTE_UNUSED
)
4058 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4064 current_function_func_begin_label
= NULL
;
4066 do_frame
= dwarf2out_do_frame ();
4068 /* ??? current_function_func_begin_label is also used by except.c for
4069 call-site information. We must emit this label if it might be used. */
4071 && (!flag_exceptions
4072 || targetm
.except_unwind_info (&global_options
) != UI_TARGET
))
4075 fnsec
= function_section (current_function_decl
);
4076 switch_to_section (fnsec
);
4077 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
4078 current_function_funcdef_no
);
4079 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
4080 current_function_funcdef_no
);
4081 dup_label
= xstrdup (label
);
4082 current_function_func_begin_label
= dup_label
;
4084 /* We can elide the fde allocation if we're not emitting debug info. */
4088 /* Expand the fde table if necessary. */
4089 if (fde_table_in_use
== fde_table_allocated
)
4091 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
4092 fde_table
= GGC_RESIZEVEC (dw_fde_node
, fde_table
, fde_table_allocated
);
4093 memset (fde_table
+ fde_table_in_use
, 0,
4094 FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
4097 /* Record the FDE associated with this function. */
4098 current_funcdef_fde
= fde_table_in_use
;
4100 /* Add the new FDE at the end of the fde_table. */
4101 fde
= &fde_table
[fde_table_in_use
++];
4102 fde
->decl
= current_function_decl
;
4103 fde
->dw_fde_begin
= dup_label
;
4104 fde
->dw_fde_end
= NULL
;
4105 fde
->dw_fde_current_label
= dup_label
;
4106 fde
->dw_fde_second_begin
= NULL
;
4107 fde
->dw_fde_second_end
= NULL
;
4108 fde
->dw_fde_vms_end_prologue
= NULL
;
4109 fde
->dw_fde_vms_begin_epilogue
= NULL
;
4110 fde
->dw_fde_cfi
= VEC_alloc (dw_cfi_ref
, gc
, 20);
4111 fde
->dw_fde_switch_cfi_index
= 0;
4112 fde
->funcdef_number
= current_function_funcdef_no
;
4113 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
4114 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
4115 fde
->nothrow
= crtl
->nothrow
;
4116 fde
->drap_reg
= INVALID_REGNUM
;
4117 fde
->vdrap_reg
= INVALID_REGNUM
;
4118 fde
->in_std_section
= (fnsec
== text_section
4119 || (cold_text_section
&& fnsec
== cold_text_section
));
4120 fde
->second_in_std_section
= 0;
4122 args_size
= old_args_size
= 0;
4124 /* We only want to output line number information for the genuine dwarf2
4125 prologue case, not the eh frame case. */
4126 #ifdef DWARF2_DEBUGGING_INFO
4128 dwarf2out_source_line (line
, file
, 0, true);
4131 if (dwarf2out_do_cfi_asm ())
4132 dwarf2out_do_cfi_startproc (false);
4135 rtx personality
= get_personality_function (current_function_decl
);
4136 if (!current_unit_personality
)
4137 current_unit_personality
= personality
;
4139 /* We cannot keep a current personality per function as without CFI
4140 asm, at the point where we emit the CFI data, there is no current
4141 function anymore. */
4142 if (personality
&& current_unit_personality
!= personality
)
4143 sorry ("multiple EH personalities are supported only with assemblers "
4144 "supporting .cfi_personality directive");
4148 /* Output a marker (i.e. a label) for the end of the generated code
4149 for a function prologue. This gets called *after* the prologue code has
4153 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
4154 const char *file ATTRIBUTE_UNUSED
)
4157 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4159 /* Output a label to mark the endpoint of the code generated for this
4161 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
4162 current_function_funcdef_no
);
4163 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
4164 current_function_funcdef_no
);
4165 fde
= &fde_table
[fde_table_in_use
- 1];
4166 fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
4169 /* Output a marker (i.e. a label) for the beginning of the generated code
4170 for a function epilogue. This gets called *before* the prologue code has
4174 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
4175 const char *file ATTRIBUTE_UNUSED
)
4178 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4180 fde
= &fde_table
[fde_table_in_use
- 1];
4181 if (fde
->dw_fde_vms_begin_epilogue
)
4184 /* Output a label to mark the endpoint of the code generated for this
4186 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
4187 current_function_funcdef_no
);
4188 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
4189 current_function_funcdef_no
);
4190 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
4193 /* Output a marker (i.e. a label) for the absolute end of the generated code
4194 for a function definition. This gets called *after* the epilogue code has
4198 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
4199 const char *file ATTRIBUTE_UNUSED
)
4202 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4204 last_var_location_insn
= NULL_RTX
;
4206 if (dwarf2out_do_cfi_asm ())
4207 fprintf (asm_out_file
, "\t.cfi_endproc\n");
4209 /* Output a label to mark the endpoint of the code generated for this
4211 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
4212 current_function_funcdef_no
);
4213 ASM_OUTPUT_LABEL (asm_out_file
, label
);
4214 fde
= current_fde ();
4215 gcc_assert (fde
!= NULL
);
4216 if (fde
->dw_fde_second_begin
== NULL
)
4217 fde
->dw_fde_end
= xstrdup (label
);
4221 dwarf2out_frame_init (void)
4223 /* Allocate the initial hunk of the fde_table. */
4224 fde_table
= ggc_alloc_cleared_vec_dw_fde_node (FDE_TABLE_INCREMENT
);
4225 fde_table_allocated
= FDE_TABLE_INCREMENT
;
4226 fde_table_in_use
= 0;
4228 /* Generate the CFA instructions common to all FDE's. Do it now for the
4229 sake of lookup_cfa. */
4231 /* On entry, the Canonical Frame Address is at SP. */
4232 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
4234 if (targetm
.debug_unwind_info () == UI_DWARF2
4235 || targetm
.except_unwind_info (&global_options
) == UI_DWARF2
)
4236 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
4240 dwarf2out_frame_finish (void)
4242 /* Output call frame information. */
4243 if (targetm
.debug_unwind_info () == UI_DWARF2
)
4244 output_call_frame_info (0);
4246 /* Output another copy for the unwinder. */
4247 if ((flag_unwind_tables
|| flag_exceptions
)
4248 && targetm
.except_unwind_info (&global_options
) == UI_DWARF2
)
4249 output_call_frame_info (1);
4252 /* Note that the current function section is being used for code. */
4255 dwarf2out_note_section_used (void)
4257 section
*sec
= current_function_section ();
4258 if (sec
== text_section
)
4259 text_section_used
= true;
4260 else if (sec
== cold_text_section
)
4261 cold_text_section_used
= true;
4264 static void var_location_switch_text_section (void);
4265 static void set_cur_line_info_table (section
*);
4268 dwarf2out_switch_text_section (void)
4271 dw_fde_ref fde
= current_fde ();
4273 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
4275 if (!in_cold_section_p
)
4277 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
4278 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
4279 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
4283 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
4284 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
4285 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
4287 have_multiple_function_sections
= true;
4289 /* Reset the current label on switching text sections, so that we
4290 don't attempt to advance_loc4 between labels in different sections. */
4291 fde
->dw_fde_current_label
= NULL
;
4293 /* There is no need to mark used sections when not debugging. */
4294 if (cold_text_section
!= NULL
)
4295 dwarf2out_note_section_used ();
4297 if (dwarf2out_do_cfi_asm ())
4298 fprintf (asm_out_file
, "\t.cfi_endproc\n");
4300 /* Now do the real section switch. */
4301 sect
= current_function_section ();
4302 switch_to_section (sect
);
4304 fde
->second_in_std_section
4305 = (sect
== text_section
4306 || (cold_text_section
&& sect
== cold_text_section
));
4308 if (dwarf2out_do_cfi_asm ())
4310 dwarf2out_do_cfi_startproc (true);
4311 /* As this is a different FDE, insert all current CFI instructions
4313 output_all_cfis (fde
->dw_fde_cfi
, true, fde
, true);
4315 fde
->dw_fde_switch_cfi_index
= VEC_length (dw_cfi_ref
, fde
->dw_fde_cfi
);
4316 var_location_switch_text_section ();
4318 set_cur_line_info_table (sect
);
4321 /* And now, the subset of the debugging information support code necessary
4322 for emitting location expressions. */
4324 /* Data about a single source file. */
4325 struct GTY(()) dwarf_file_data
{
4326 const char * filename
;
4330 typedef struct dw_val_struct
*dw_val_ref
;
4331 typedef struct die_struct
*dw_die_ref
;
4332 typedef const struct die_struct
*const_dw_die_ref
;
4333 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
4334 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
4336 typedef struct GTY(()) deferred_locations_struct
4340 } deferred_locations
;
4342 DEF_VEC_O(deferred_locations
);
4343 DEF_VEC_ALLOC_O(deferred_locations
,gc
);
4345 static GTY(()) VEC(deferred_locations
, gc
) *deferred_locations_list
;
4347 DEF_VEC_P(dw_die_ref
);
4348 DEF_VEC_ALLOC_P(dw_die_ref
,heap
);
4350 /* Each DIE may have a series of attribute/value pairs. Values
4351 can take on several forms. The forms that are used in this
4352 implementation are listed below. */
4357 dw_val_class_offset
,
4359 dw_val_class_loc_list
,
4360 dw_val_class_range_list
,
4362 dw_val_class_unsigned_const
,
4363 dw_val_class_const_double
,
4366 dw_val_class_die_ref
,
4367 dw_val_class_fde_ref
,
4368 dw_val_class_lbl_id
,
4369 dw_val_class_lineptr
,
4371 dw_val_class_macptr
,
4374 dw_val_class_decl_ref
,
4375 dw_val_class_vms_delta
4378 /* Describe a floating point constant value, or a vector constant value. */
4380 typedef struct GTY(()) dw_vec_struct
{
4381 unsigned char * GTY((length ("%h.length"))) array
;
4387 /* The dw_val_node describes an attribute's value, as it is
4388 represented internally. */
4390 typedef struct GTY(()) dw_val_struct
{
4391 enum dw_val_class val_class
;
4392 union dw_val_struct_union
4394 rtx
GTY ((tag ("dw_val_class_addr"))) val_addr
;
4395 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_offset"))) val_offset
;
4396 dw_loc_list_ref
GTY ((tag ("dw_val_class_loc_list"))) val_loc_list
;
4397 dw_loc_descr_ref
GTY ((tag ("dw_val_class_loc"))) val_loc
;
4398 HOST_WIDE_INT
GTY ((default)) val_int
;
4399 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned
;
4400 double_int
GTY ((tag ("dw_val_class_const_double"))) val_double
;
4401 dw_vec_const
GTY ((tag ("dw_val_class_vec"))) val_vec
;
4402 struct dw_val_die_union
4406 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref
;
4407 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index
;
4408 struct indirect_string_node
* GTY ((tag ("dw_val_class_str"))) val_str
;
4409 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id
;
4410 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag
;
4411 struct dwarf_file_data
* GTY ((tag ("dw_val_class_file"))) val_file
;
4412 unsigned char GTY ((tag ("dw_val_class_data8"))) val_data8
[8];
4413 tree
GTY ((tag ("dw_val_class_decl_ref"))) val_decl_ref
;
4414 struct dw_val_vms_delta_union
4418 } GTY ((tag ("dw_val_class_vms_delta"))) val_vms_delta
;
4420 GTY ((desc ("%1.val_class"))) v
;
4424 /* Locations in memory are described using a sequence of stack machine
4427 typedef struct GTY(()) dw_loc_descr_struct
{
4428 dw_loc_descr_ref dw_loc_next
;
4429 ENUM_BITFIELD (dwarf_location_atom
) dw_loc_opc
: 8;
4430 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4431 from DW_OP_addr with a dtp-relative symbol relocation. */
4432 unsigned int dtprel
: 1;
4434 dw_val_node dw_loc_oprnd1
;
4435 dw_val_node dw_loc_oprnd2
;
4439 /* Location lists are ranges + location descriptions for that range,
4440 so you can track variables that are in different places over
4441 their entire life. */
4442 typedef struct GTY(()) dw_loc_list_struct
{
4443 dw_loc_list_ref dw_loc_next
;
4444 const char *begin
; /* Label for begin address of range */
4445 const char *end
; /* Label for end address of range */
4446 char *ll_symbol
; /* Label for beginning of location list.
4447 Only on head of list */
4448 const char *section
; /* Section this loclist is relative to */
4449 dw_loc_descr_ref expr
;
4451 /* True if all addresses in this and subsequent lists are known to be
4454 /* True if this list has been replaced by dw_loc_next. */
4459 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
4461 /* Convert a DWARF stack opcode into its string name. */
4464 dwarf_stack_op_name (unsigned int op
)
4469 return "DW_OP_addr";
4471 return "DW_OP_deref";
4473 return "DW_OP_const1u";
4475 return "DW_OP_const1s";
4477 return "DW_OP_const2u";
4479 return "DW_OP_const2s";
4481 return "DW_OP_const4u";
4483 return "DW_OP_const4s";
4485 return "DW_OP_const8u";
4487 return "DW_OP_const8s";
4489 return "DW_OP_constu";
4491 return "DW_OP_consts";
4495 return "DW_OP_drop";
4497 return "DW_OP_over";
4499 return "DW_OP_pick";
4501 return "DW_OP_swap";
4505 return "DW_OP_xderef";
4513 return "DW_OP_minus";
4525 return "DW_OP_plus";
4526 case DW_OP_plus_uconst
:
4527 return "DW_OP_plus_uconst";
4533 return "DW_OP_shra";
4551 return "DW_OP_skip";
4553 return "DW_OP_lit0";
4555 return "DW_OP_lit1";
4557 return "DW_OP_lit2";
4559 return "DW_OP_lit3";
4561 return "DW_OP_lit4";
4563 return "DW_OP_lit5";
4565 return "DW_OP_lit6";
4567 return "DW_OP_lit7";
4569 return "DW_OP_lit8";
4571 return "DW_OP_lit9";
4573 return "DW_OP_lit10";
4575 return "DW_OP_lit11";
4577 return "DW_OP_lit12";
4579 return "DW_OP_lit13";
4581 return "DW_OP_lit14";
4583 return "DW_OP_lit15";
4585 return "DW_OP_lit16";
4587 return "DW_OP_lit17";
4589 return "DW_OP_lit18";
4591 return "DW_OP_lit19";
4593 return "DW_OP_lit20";
4595 return "DW_OP_lit21";
4597 return "DW_OP_lit22";
4599 return "DW_OP_lit23";
4601 return "DW_OP_lit24";
4603 return "DW_OP_lit25";
4605 return "DW_OP_lit26";
4607 return "DW_OP_lit27";
4609 return "DW_OP_lit28";
4611 return "DW_OP_lit29";
4613 return "DW_OP_lit30";
4615 return "DW_OP_lit31";
4617 return "DW_OP_reg0";
4619 return "DW_OP_reg1";
4621 return "DW_OP_reg2";
4623 return "DW_OP_reg3";
4625 return "DW_OP_reg4";
4627 return "DW_OP_reg5";
4629 return "DW_OP_reg6";
4631 return "DW_OP_reg7";
4633 return "DW_OP_reg8";
4635 return "DW_OP_reg9";
4637 return "DW_OP_reg10";
4639 return "DW_OP_reg11";
4641 return "DW_OP_reg12";
4643 return "DW_OP_reg13";
4645 return "DW_OP_reg14";
4647 return "DW_OP_reg15";
4649 return "DW_OP_reg16";
4651 return "DW_OP_reg17";
4653 return "DW_OP_reg18";
4655 return "DW_OP_reg19";
4657 return "DW_OP_reg20";
4659 return "DW_OP_reg21";
4661 return "DW_OP_reg22";
4663 return "DW_OP_reg23";
4665 return "DW_OP_reg24";
4667 return "DW_OP_reg25";
4669 return "DW_OP_reg26";
4671 return "DW_OP_reg27";
4673 return "DW_OP_reg28";
4675 return "DW_OP_reg29";
4677 return "DW_OP_reg30";
4679 return "DW_OP_reg31";
4681 return "DW_OP_breg0";
4683 return "DW_OP_breg1";
4685 return "DW_OP_breg2";
4687 return "DW_OP_breg3";
4689 return "DW_OP_breg4";
4691 return "DW_OP_breg5";
4693 return "DW_OP_breg6";
4695 return "DW_OP_breg7";
4697 return "DW_OP_breg8";
4699 return "DW_OP_breg9";
4701 return "DW_OP_breg10";
4703 return "DW_OP_breg11";
4705 return "DW_OP_breg12";
4707 return "DW_OP_breg13";
4709 return "DW_OP_breg14";
4711 return "DW_OP_breg15";
4713 return "DW_OP_breg16";
4715 return "DW_OP_breg17";
4717 return "DW_OP_breg18";
4719 return "DW_OP_breg19";
4721 return "DW_OP_breg20";
4723 return "DW_OP_breg21";
4725 return "DW_OP_breg22";
4727 return "DW_OP_breg23";
4729 return "DW_OP_breg24";
4731 return "DW_OP_breg25";
4733 return "DW_OP_breg26";
4735 return "DW_OP_breg27";
4737 return "DW_OP_breg28";
4739 return "DW_OP_breg29";
4741 return "DW_OP_breg30";
4743 return "DW_OP_breg31";
4745 return "DW_OP_regx";
4747 return "DW_OP_fbreg";
4749 return "DW_OP_bregx";
4751 return "DW_OP_piece";
4752 case DW_OP_deref_size
:
4753 return "DW_OP_deref_size";
4754 case DW_OP_xderef_size
:
4755 return "DW_OP_xderef_size";
4759 case DW_OP_push_object_address
:
4760 return "DW_OP_push_object_address";
4762 return "DW_OP_call2";
4764 return "DW_OP_call4";
4765 case DW_OP_call_ref
:
4766 return "DW_OP_call_ref";
4767 case DW_OP_implicit_value
:
4768 return "DW_OP_implicit_value";
4769 case DW_OP_stack_value
:
4770 return "DW_OP_stack_value";
4771 case DW_OP_form_tls_address
:
4772 return "DW_OP_form_tls_address";
4773 case DW_OP_call_frame_cfa
:
4774 return "DW_OP_call_frame_cfa";
4775 case DW_OP_bit_piece
:
4776 return "DW_OP_bit_piece";
4778 case DW_OP_GNU_push_tls_address
:
4779 return "DW_OP_GNU_push_tls_address";
4780 case DW_OP_GNU_uninit
:
4781 return "DW_OP_GNU_uninit";
4782 case DW_OP_GNU_encoded_addr
:
4783 return "DW_OP_GNU_encoded_addr";
4784 case DW_OP_GNU_implicit_pointer
:
4785 return "DW_OP_GNU_implicit_pointer";
4786 case DW_OP_GNU_entry_value
:
4787 return "DW_OP_GNU_entry_value";
4790 return "OP_<unknown>";
4794 /* Return a pointer to a newly allocated location description. Location
4795 descriptions are simple expression terms that can be strung
4796 together to form more complicated location (address) descriptions. */
4798 static inline dw_loc_descr_ref
4799 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
4800 unsigned HOST_WIDE_INT oprnd2
)
4802 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
4804 descr
->dw_loc_opc
= op
;
4805 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
4806 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
4807 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
4808 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
4813 /* Return a pointer to a newly allocated location description for
4816 static inline dw_loc_descr_ref
4817 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
4820 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
4823 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
4826 /* Add a location description term to a location description expression. */
4829 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
4831 dw_loc_descr_ref
*d
;
4833 /* Find the end of the chain. */
4834 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
4840 /* Add a constant OFFSET to a location expression. */
4843 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
4845 dw_loc_descr_ref loc
;
4848 gcc_assert (*list_head
!= NULL
);
4853 /* Find the end of the chain. */
4854 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
4858 if (loc
->dw_loc_opc
== DW_OP_fbreg
4859 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
4860 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
4861 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
4862 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
4864 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4865 offset. Don't optimize if an signed integer overflow would happen. */
4867 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
4868 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
4871 else if (offset
> 0)
4872 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
4876 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
4877 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
4881 /* Add a constant OFFSET to a location list. */
4884 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
4887 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
4888 loc_descr_plus_const (&d
->expr
, offset
);
4891 #define DWARF_REF_SIZE \
4892 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
4894 static unsigned long size_of_locs (dw_loc_descr_ref
);
4896 /* Return the size of a location descriptor. */
4898 static unsigned long
4899 size_of_loc_descr (dw_loc_descr_ref loc
)
4901 unsigned long size
= 1;
4903 switch (loc
->dw_loc_opc
)
4906 size
+= DWARF2_ADDR_SIZE
;
4925 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4928 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4933 case DW_OP_plus_uconst
:
4934 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4972 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4975 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4978 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4981 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4982 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
4985 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4987 case DW_OP_bit_piece
:
4988 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4989 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
4991 case DW_OP_deref_size
:
4992 case DW_OP_xderef_size
:
5001 case DW_OP_call_ref
:
5002 size
+= DWARF_REF_SIZE
;
5004 case DW_OP_implicit_value
:
5005 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
5006 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
5008 case DW_OP_GNU_implicit_pointer
:
5009 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
5011 case DW_OP_GNU_entry_value
:
5013 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
5014 size
+= size_of_uleb128 (op_size
) + op_size
;
5024 /* Return the size of a series of location descriptors. */
5026 static unsigned long
5027 size_of_locs (dw_loc_descr_ref loc
)
5032 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
5033 field, to avoid writing to a PCH file. */
5034 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
5036 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
5038 size
+= size_of_loc_descr (l
);
5043 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
5045 l
->dw_loc_addr
= size
;
5046 size
+= size_of_loc_descr (l
);
5052 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
5053 static void get_ref_die_offset_label (char *, dw_die_ref
);
5054 static void output_loc_sequence (dw_loc_descr_ref
, int);
5056 /* Output location description stack opcode's operands (if any).
5057 The for_eh_or_skip parameter controls whether register numbers are
5058 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5059 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5060 info). This should be suppressed for the cases that have not been converted
5061 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5064 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
5066 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
5067 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
5069 switch (loc
->dw_loc_opc
)
5071 #ifdef DWARF2_DEBUGGING_INFO
5074 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
5079 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
5080 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
5082 fputc ('\n', asm_out_file
);
5087 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
5092 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
5093 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
5095 fputc ('\n', asm_out_file
);
5100 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
5101 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
5108 gcc_assert (val1
->val_class
== dw_val_class_loc
);
5109 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
5111 dw2_asm_output_data (2, offset
, NULL
);
5114 case DW_OP_implicit_value
:
5115 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5116 switch (val2
->val_class
)
5118 case dw_val_class_const
:
5119 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
5121 case dw_val_class_vec
:
5123 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
5124 unsigned int len
= val2
->v
.val_vec
.length
;
5128 if (elt_size
> sizeof (HOST_WIDE_INT
))
5133 for (i
= 0, p
= val2
->v
.val_vec
.array
;
5136 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
5137 "fp or vector constant word %u", i
);
5140 case dw_val_class_const_double
:
5142 unsigned HOST_WIDE_INT first
, second
;
5144 if (WORDS_BIG_ENDIAN
)
5146 first
= val2
->v
.val_double
.high
;
5147 second
= val2
->v
.val_double
.low
;
5151 first
= val2
->v
.val_double
.low
;
5152 second
= val2
->v
.val_double
.high
;
5154 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
5156 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
5160 case dw_val_class_addr
:
5161 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
5162 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
5177 case DW_OP_implicit_value
:
5178 /* We currently don't make any attempt to make sure these are
5179 aligned properly like we do for the main unwind info, so
5180 don't support emitting things larger than a byte if we're
5181 only doing unwinding. */
5186 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
5189 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5192 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
5195 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
5197 case DW_OP_plus_uconst
:
5198 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5232 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
5236 unsigned r
= val1
->v
.val_unsigned
;
5237 if (for_eh_or_skip
>= 0)
5238 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
5239 gcc_assert (size_of_uleb128 (r
)
5240 == size_of_uleb128 (val1
->v
.val_unsigned
));
5241 dw2_asm_output_data_uleb128 (r
, NULL
);
5245 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
5249 unsigned r
= val1
->v
.val_unsigned
;
5250 if (for_eh_or_skip
>= 0)
5251 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
5252 gcc_assert (size_of_uleb128 (r
)
5253 == size_of_uleb128 (val1
->v
.val_unsigned
));
5254 dw2_asm_output_data_uleb128 (r
, NULL
);
5255 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
5259 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5261 case DW_OP_bit_piece
:
5262 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5263 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
5265 case DW_OP_deref_size
:
5266 case DW_OP_xderef_size
:
5267 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
5273 if (targetm
.asm_out
.output_dwarf_dtprel
)
5275 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
5278 fputc ('\n', asm_out_file
);
5285 #ifdef DWARF2_DEBUGGING_INFO
5286 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
5293 case DW_OP_GNU_implicit_pointer
:
5295 char label
[MAX_ARTIFICIAL_LABEL_BYTES
5296 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
5297 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
5298 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
5299 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
5300 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
5304 case DW_OP_GNU_entry_value
:
5305 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
5306 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
5310 /* Other codes have no operands. */
5315 /* Output a sequence of location operations.
5316 The for_eh_or_skip parameter controls whether register numbers are
5317 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5318 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5319 info). This should be suppressed for the cases that have not been converted
5320 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5323 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
5325 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
5327 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
5328 /* Output the opcode. */
5329 if (for_eh_or_skip
>= 0
5330 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
5332 unsigned r
= (opc
- DW_OP_breg0
);
5333 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
5334 gcc_assert (r
<= 31);
5335 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
5337 else if (for_eh_or_skip
>= 0
5338 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
5340 unsigned r
= (opc
- DW_OP_reg0
);
5341 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
5342 gcc_assert (r
<= 31);
5343 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
5346 dw2_asm_output_data (1, opc
,
5347 "%s", dwarf_stack_op_name (opc
));
5349 /* Output the operand(s) (if any). */
5350 output_loc_operands (loc
, for_eh_or_skip
);
5354 /* Output location description stack opcode's operands (if any).
5355 The output is single bytes on a line, suitable for .cfi_escape. */
5358 output_loc_operands_raw (dw_loc_descr_ref loc
)
5360 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
5361 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
5363 switch (loc
->dw_loc_opc
)
5366 case DW_OP_implicit_value
:
5367 /* We cannot output addresses in .cfi_escape, only bytes. */
5373 case DW_OP_deref_size
:
5374 case DW_OP_xderef_size
:
5375 fputc (',', asm_out_file
);
5376 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
5381 fputc (',', asm_out_file
);
5382 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
5387 fputc (',', asm_out_file
);
5388 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
5393 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
5394 fputc (',', asm_out_file
);
5395 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
5403 gcc_assert (val1
->val_class
== dw_val_class_loc
);
5404 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
5406 fputc (',', asm_out_file
);
5407 dw2_asm_output_data_raw (2, offset
);
5413 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
5414 gcc_assert (size_of_uleb128 (r
)
5415 == size_of_uleb128 (val1
->v
.val_unsigned
));
5416 fputc (',', asm_out_file
);
5417 dw2_asm_output_data_uleb128_raw (r
);
5422 case DW_OP_plus_uconst
:
5424 fputc (',', asm_out_file
);
5425 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
5428 case DW_OP_bit_piece
:
5429 fputc (',', asm_out_file
);
5430 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
5431 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
5468 fputc (',', asm_out_file
);
5469 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
5474 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
5475 gcc_assert (size_of_uleb128 (r
)
5476 == size_of_uleb128 (val1
->v
.val_unsigned
));
5477 fputc (',', asm_out_file
);
5478 dw2_asm_output_data_uleb128_raw (r
);
5479 fputc (',', asm_out_file
);
5480 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
5484 case DW_OP_GNU_implicit_pointer
:
5485 case DW_OP_GNU_entry_value
:
5490 /* Other codes have no operands. */
5496 output_loc_sequence_raw (dw_loc_descr_ref loc
)
5500 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
5501 /* Output the opcode. */
5502 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
5504 unsigned r
= (opc
- DW_OP_breg0
);
5505 r
= DWARF2_FRAME_REG_OUT (r
, 1);
5506 gcc_assert (r
<= 31);
5507 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
5509 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
5511 unsigned r
= (opc
- DW_OP_reg0
);
5512 r
= DWARF2_FRAME_REG_OUT (r
, 1);
5513 gcc_assert (r
<= 31);
5514 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
5516 /* Output the opcode. */
5517 fprintf (asm_out_file
, "%#x", opc
);
5518 output_loc_operands_raw (loc
);
5520 if (!loc
->dw_loc_next
)
5522 loc
= loc
->dw_loc_next
;
5524 fputc (',', asm_out_file
);
5528 /* This routine will generate the correct assembly data for a location
5529 description based on a cfi entry with a complex address. */
5532 output_cfa_loc (dw_cfi_ref cfi
, int for_eh
)
5534 dw_loc_descr_ref loc
;
5537 if (cfi
->dw_cfi_opc
== DW_CFA_expression
)
5540 DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
5541 dw2_asm_output_data (1, r
, NULL
);
5542 loc
= cfi
->dw_cfi_oprnd2
.dw_cfi_loc
;
5545 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
5547 /* Output the size of the block. */
5548 size
= size_of_locs (loc
);
5549 dw2_asm_output_data_uleb128 (size
, NULL
);
5551 /* Now output the operations themselves. */
5552 output_loc_sequence (loc
, for_eh
);
5555 /* Similar, but used for .cfi_escape. */
5558 output_cfa_loc_raw (dw_cfi_ref cfi
)
5560 dw_loc_descr_ref loc
;
5563 if (cfi
->dw_cfi_opc
== DW_CFA_expression
)
5566 DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
5567 fprintf (asm_out_file
, "%#x,", r
);
5568 loc
= cfi
->dw_cfi_oprnd2
.dw_cfi_loc
;
5571 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
5573 /* Output the size of the block. */
5574 size
= size_of_locs (loc
);
5575 dw2_asm_output_data_uleb128_raw (size
);
5576 fputc (',', asm_out_file
);
5578 /* Now output the operations themselves. */
5579 output_loc_sequence_raw (loc
);
5582 /* This function builds a dwarf location descriptor sequence from a
5583 dw_cfa_location, adding the given OFFSET to the result of the
5586 static struct dw_loc_descr_struct
*
5587 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
5589 struct dw_loc_descr_struct
*head
, *tmp
;
5591 offset
+= cfa
->offset
;
5595 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
5596 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
5597 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
5598 add_loc_descr (&head
, tmp
);
5601 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
5602 add_loc_descr (&head
, tmp
);
5606 head
= new_reg_loc_descr (cfa
->reg
, offset
);
5611 /* This function builds a dwarf location descriptor sequence for
5612 the address at OFFSET from the CFA when stack is aligned to
5615 static struct dw_loc_descr_struct
*
5616 build_cfa_aligned_loc (HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
5618 struct dw_loc_descr_struct
*head
;
5619 unsigned int dwarf_fp
5620 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
5622 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5623 if (cfa
.reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
.indirect
== 0)
5625 head
= new_reg_loc_descr (dwarf_fp
, 0);
5626 add_loc_descr (&head
, int_loc_descriptor (alignment
));
5627 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
5628 loc_descr_plus_const (&head
, offset
);
5631 head
= new_reg_loc_descr (dwarf_fp
, offset
);
5635 /* This function fills in aa dw_cfa_location structure from a dwarf location
5636 descriptor sequence. */
5639 get_cfa_from_loc_descr (dw_cfa_location
*cfa
, struct dw_loc_descr_struct
*loc
)
5641 struct dw_loc_descr_struct
*ptr
;
5643 cfa
->base_offset
= 0;
5647 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
5649 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
5685 cfa
->reg
= op
- DW_OP_reg0
;
5688 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
5722 cfa
->reg
= op
- DW_OP_breg0
;
5723 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
5726 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
5727 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
5732 case DW_OP_plus_uconst
:
5733 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
5736 internal_error ("DW_LOC_OP %s not implemented",
5737 dwarf_stack_op_name (ptr
->dw_loc_opc
));
5742 /* And now, the support for symbolic debugging information. */
5744 /* .debug_str support. */
5745 static int output_indirect_string (void **, void *);
5747 static void dwarf2out_init (const char *);
5748 static void dwarf2out_finish (const char *);
5749 static void dwarf2out_assembly_start (void);
5750 static void dwarf2out_define (unsigned int, const char *);
5751 static void dwarf2out_undef (unsigned int, const char *);
5752 static void dwarf2out_start_source_file (unsigned, const char *);
5753 static void dwarf2out_end_source_file (unsigned);
5754 static void dwarf2out_function_decl (tree
);
5755 static void dwarf2out_begin_block (unsigned, unsigned);
5756 static void dwarf2out_end_block (unsigned, unsigned);
5757 static bool dwarf2out_ignore_block (const_tree
);
5758 static void dwarf2out_global_decl (tree
);
5759 static void dwarf2out_type_decl (tree
, int);
5760 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
5761 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
5763 static void dwarf2out_abstract_function (tree
);
5764 static void dwarf2out_var_location (rtx
);
5765 static void dwarf2out_begin_function (tree
);
5766 static void dwarf2out_set_name (tree
, tree
);
5768 /* The debug hooks structure. */
5770 const struct gcc_debug_hooks dwarf2_debug_hooks
=
5774 dwarf2out_assembly_start
,
5777 dwarf2out_start_source_file
,
5778 dwarf2out_end_source_file
,
5779 dwarf2out_begin_block
,
5780 dwarf2out_end_block
,
5781 dwarf2out_ignore_block
,
5782 dwarf2out_source_line
,
5783 dwarf2out_begin_prologue
,
5784 #if VMS_DEBUGGING_INFO
5785 dwarf2out_vms_end_prologue
,
5786 dwarf2out_vms_begin_epilogue
,
5788 debug_nothing_int_charstar
,
5789 debug_nothing_int_charstar
,
5791 dwarf2out_end_epilogue
,
5792 dwarf2out_begin_function
,
5793 debug_nothing_int
, /* end_function */
5794 dwarf2out_function_decl
, /* function_decl */
5795 dwarf2out_global_decl
,
5796 dwarf2out_type_decl
, /* type_decl */
5797 dwarf2out_imported_module_or_decl
,
5798 debug_nothing_tree
, /* deferred_inline_function */
5799 /* The DWARF 2 backend tries to reduce debugging bloat by not
5800 emitting the abstract description of inline functions until
5801 something tries to reference them. */
5802 dwarf2out_abstract_function
, /* outlining_inline_function */
5803 debug_nothing_rtx
, /* label */
5804 debug_nothing_int
, /* handle_pch */
5805 dwarf2out_var_location
,
5806 dwarf2out_switch_text_section
,
5808 1, /* start_end_main_source_file */
5809 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
5812 /* NOTE: In the comments in this file, many references are made to
5813 "Debugging Information Entries". This term is abbreviated as `DIE'
5814 throughout the remainder of this file. */
5816 /* An internal representation of the DWARF output is built, and then
5817 walked to generate the DWARF debugging info. The walk of the internal
5818 representation is done after the entire program has been compiled.
5819 The types below are used to describe the internal representation. */
5821 /* Whether to put type DIEs into their own section .debug_types instead
5822 of making them part of the .debug_info section. Only supported for
5823 Dwarf V4 or higher and the user didn't disable them through
5824 -fno-debug-types-section. It is more efficient to put them in a
5825 separate comdat sections since the linker will then be able to
5826 remove duplicates. But not all tools support .debug_types sections
5829 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
5831 /* Various DIE's use offsets relative to the beginning of the
5832 .debug_info section to refer to each other. */
5834 typedef long int dw_offset
;
5836 /* Define typedefs here to avoid circular dependencies. */
5838 typedef struct dw_attr_struct
*dw_attr_ref
;
5839 typedef struct dw_line_info_struct
*dw_line_info_ref
;
5840 typedef struct pubname_struct
*pubname_ref
;
5841 typedef struct dw_ranges_struct
*dw_ranges_ref
;
5842 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
5843 typedef struct comdat_type_struct
*comdat_type_node_ref
;
5845 /* The entries in the line_info table more-or-less mirror the opcodes
5846 that are used in the real dwarf line table. Arrays of these entries
5847 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
5850 enum dw_line_info_opcode
{
5851 /* Emit DW_LNE_set_address; the operand is the label index. */
5854 /* Emit a row to the matrix with the given line. This may be done
5855 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
5859 /* Emit a DW_LNS_set_file. */
5862 /* Emit a DW_LNS_set_column. */
5865 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
5868 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
5869 LI_set_prologue_end
,
5870 LI_set_epilogue_begin
,
5872 /* Emit a DW_LNE_set_discriminator. */
5873 LI_set_discriminator
5876 typedef struct GTY(()) dw_line_info_struct
{
5877 enum dw_line_info_opcode opcode
;
5879 } dw_line_info_entry
;
5881 DEF_VEC_O(dw_line_info_entry
);
5882 DEF_VEC_ALLOC_O(dw_line_info_entry
, gc
);
5884 typedef struct GTY(()) dw_line_info_table_struct
{
5885 /* The label that marks the end of this section. */
5886 const char *end_label
;
5888 /* The values for the last row of the matrix, as collected in the table.
5889 These are used to minimize the changes to the next row. */
5890 unsigned int file_num
;
5891 unsigned int line_num
;
5892 unsigned int column_num
;
5897 VEC(dw_line_info_entry
, gc
) *entries
;
5898 } dw_line_info_table
;
5900 typedef dw_line_info_table
*dw_line_info_table_p
;
5902 DEF_VEC_P(dw_line_info_table_p
);
5903 DEF_VEC_ALLOC_P(dw_line_info_table_p
, gc
);
5905 /* Each DIE attribute has a field specifying the attribute kind,
5906 a link to the next attribute in the chain, and an attribute value.
5907 Attributes are typically linked below the DIE they modify. */
5909 typedef struct GTY(()) dw_attr_struct
{
5910 enum dwarf_attribute dw_attr
;
5911 dw_val_node dw_attr_val
;
5915 DEF_VEC_O(dw_attr_node
);
5916 DEF_VEC_ALLOC_O(dw_attr_node
,gc
);
5918 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5919 The children of each node form a circular list linked by
5920 die_sib. die_child points to the node *before* the "first" child node. */
5922 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
5923 union die_symbol_or_type_node
5925 char * GTY ((tag ("0"))) die_symbol
;
5926 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
5928 GTY ((desc ("use_debug_types"))) die_id
;
5929 VEC(dw_attr_node
,gc
) * die_attr
;
5930 dw_die_ref die_parent
;
5931 dw_die_ref die_child
;
5933 dw_die_ref die_definition
; /* ref from a specification to its definition */
5934 dw_offset die_offset
;
5935 unsigned long die_abbrev
;
5937 /* Die is used and must not be pruned as unused. */
5938 int die_perennial_p
;
5939 unsigned int decl_id
;
5940 enum dwarf_tag die_tag
;
5944 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5945 #define FOR_EACH_CHILD(die, c, expr) do { \
5946 c = die->die_child; \
5950 } while (c != die->die_child); \
5953 /* The pubname structure */
5955 typedef struct GTY(()) pubname_struct
{
5961 DEF_VEC_O(pubname_entry
);
5962 DEF_VEC_ALLOC_O(pubname_entry
, gc
);
5964 struct GTY(()) dw_ranges_struct
{
5965 /* If this is positive, it's a block number, otherwise it's a
5966 bitwise-negated index into dw_ranges_by_label. */
5970 /* A structure to hold a macinfo entry. */
5972 typedef struct GTY(()) macinfo_struct
{
5973 unsigned HOST_WIDE_INT code
;
5974 unsigned HOST_WIDE_INT lineno
;
5979 DEF_VEC_O(macinfo_entry
);
5980 DEF_VEC_ALLOC_O(macinfo_entry
, gc
);
5982 struct GTY(()) dw_ranges_by_label_struct
{
5987 /* The comdat type node structure. */
5988 typedef struct GTY(()) comdat_type_struct
5990 dw_die_ref root_die
;
5991 dw_die_ref type_die
;
5992 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
5993 struct comdat_type_struct
*next
;
5997 /* The limbo die list structure. */
5998 typedef struct GTY(()) limbo_die_struct
{
6001 struct limbo_die_struct
*next
;
6005 typedef struct skeleton_chain_struct
6009 struct skeleton_chain_struct
*parent
;
6011 skeleton_chain_node
;
6013 /* How to start an assembler comment. */
6014 #ifndef ASM_COMMENT_START
6015 #define ASM_COMMENT_START ";#"
6018 /* Define a macro which returns nonzero for a TYPE_DECL which was
6019 implicitly generated for a tagged type.
6021 Note that unlike the gcc front end (which generates a NULL named
6022 TYPE_DECL node for each complete tagged type, each array type, and
6023 each function type node created) the g++ front end generates a
6024 _named_ TYPE_DECL node for each tagged type node created.
6025 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
6026 generate a DW_TAG_typedef DIE for them. */
6028 #define TYPE_DECL_IS_STUB(decl) \
6029 (DECL_NAME (decl) == NULL_TREE \
6030 || (DECL_ARTIFICIAL (decl) \
6031 && is_tagged_type (TREE_TYPE (decl)) \
6032 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
6033 /* This is necessary for stub decls that \
6034 appear in nested inline functions. */ \
6035 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
6036 && (decl_ultimate_origin (decl) \
6037 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
6039 /* Information concerning the compilation unit's programming
6040 language, and compiler version. */
6042 /* Fixed size portion of the DWARF compilation unit header. */
6043 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
6044 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
6046 /* Fixed size portion of the DWARF comdat type unit header. */
6047 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
6048 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
6049 + DWARF_OFFSET_SIZE)
6051 /* Fixed size portion of public names info. */
6052 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
6054 /* Fixed size portion of the address range info. */
6055 #define DWARF_ARANGES_HEADER_SIZE \
6056 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6057 DWARF2_ADDR_SIZE * 2) \
6058 - DWARF_INITIAL_LENGTH_SIZE)
6060 /* Size of padding portion in the address range info. It must be
6061 aligned to twice the pointer size. */
6062 #define DWARF_ARANGES_PAD_SIZE \
6063 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6064 DWARF2_ADDR_SIZE * 2) \
6065 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
6067 /* Use assembler line directives if available. */
6068 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
6069 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
6070 #define DWARF2_ASM_LINE_DEBUG_INFO 1
6072 #define DWARF2_ASM_LINE_DEBUG_INFO 0
6076 /* Minimum line offset in a special line info. opcode.
6077 This value was chosen to give a reasonable range of values. */
6078 #define DWARF_LINE_BASE -10
6080 /* First special line opcode - leave room for the standard opcodes. */
6081 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
6083 /* Range of line offsets in a special line info. opcode. */
6084 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
6086 /* Flag that indicates the initial value of the is_stmt_start flag.
6087 In the present implementation, we do not mark any lines as
6088 the beginning of a source statement, because that information
6089 is not made available by the GCC front-end. */
6090 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
6092 /* Maximum number of operations per instruction bundle. */
6093 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
6094 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
6097 /* This location is used by calc_die_sizes() to keep track
6098 the offset of each DIE within the .debug_info section. */
6099 static unsigned long next_die_offset
;
6101 /* Record the root of the DIE's built for the current compilation unit. */
6102 static GTY(()) dw_die_ref single_comp_unit_die
;
6104 /* A list of type DIEs that have been separated into comdat sections. */
6105 static GTY(()) comdat_type_node
*comdat_type_list
;
6107 /* A list of DIEs with a NULL parent waiting to be relocated. */
6108 static GTY(()) limbo_die_node
*limbo_die_list
;
6110 /* A list of DIEs for which we may have to generate
6111 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
6112 static GTY(()) limbo_die_node
*deferred_asm_name
;
6114 /* Filenames referenced by this compilation unit. */
6115 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
6117 /* A hash table of references to DIE's that describe declarations.
6118 The key is a DECL_UID() which is a unique number identifying each decl. */
6119 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
6121 /* A hash table of references to DIE's that describe COMMON blocks.
6122 The key is DECL_UID() ^ die_parent. */
6123 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
6125 typedef struct GTY(()) die_arg_entry_struct
{
6130 DEF_VEC_O(die_arg_entry
);
6131 DEF_VEC_ALLOC_O(die_arg_entry
,gc
);
6133 /* Node of the variable location list. */
6134 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
6135 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
6136 EXPR_LIST chain. For small bitsizes, bitsize is encoded
6137 in mode of the EXPR_LIST node and first EXPR_LIST operand
6138 is either NOTE_INSN_VAR_LOCATION for a piece with a known
6139 location or NULL for padding. For larger bitsizes,
6140 mode is 0 and first operand is a CONCAT with bitsize
6141 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
6142 NULL as second operand. */
6144 const char * GTY (()) label
;
6145 struct var_loc_node
* GTY (()) next
;
6148 /* Variable location list. */
6149 struct GTY (()) var_loc_list_def
{
6150 struct var_loc_node
* GTY (()) first
;
6152 /* Pointer to the last but one or last element of the
6153 chained list. If the list is empty, both first and
6154 last are NULL, if the list contains just one node
6155 or the last node certainly is not redundant, it points
6156 to the last node, otherwise points to the last but one.
6157 Do not mark it for GC because it is marked through the chain. */
6158 struct var_loc_node
* GTY ((skip ("%h"))) last
;
6160 /* Pointer to the last element before section switch,
6161 if NULL, either sections weren't switched or first
6162 is after section switch. */
6163 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
6165 /* DECL_UID of the variable decl. */
6166 unsigned int decl_id
;
6168 typedef struct var_loc_list_def var_loc_list
;
6170 /* Call argument location list. */
6171 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
6172 rtx
GTY (()) call_arg_loc_note
;
6173 const char * GTY (()) label
;
6174 tree
GTY (()) block
;
6176 rtx
GTY (()) symbol_ref
;
6177 struct call_arg_loc_node
* GTY (()) next
;
6181 /* Table of decl location linked lists. */
6182 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
6184 /* Head and tail of call_arg_loc chain. */
6185 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
6186 static struct call_arg_loc_node
*call_arg_loc_last
;
6188 /* Number of call sites in the current function. */
6189 static int call_site_count
= -1;
6190 /* Number of tail call sites in the current function. */
6191 static int tail_call_site_count
= -1;
6193 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
6195 static VEC (dw_die_ref
, heap
) *block_map
;
6197 /* A cached location list. */
6198 struct GTY (()) cached_dw_loc_list_def
{
6199 /* The DECL_UID of the decl that this entry describes. */
6200 unsigned int decl_id
;
6202 /* The cached location list. */
6203 dw_loc_list_ref loc_list
;
6205 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
6207 /* Table of cached location lists. */
6208 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
6210 /* A pointer to the base of a list of references to DIE's that
6211 are uniquely identified by their tag, presence/absence of
6212 children DIE's, and list of attribute/value pairs. */
6213 static GTY((length ("abbrev_die_table_allocated")))
6214 dw_die_ref
*abbrev_die_table
;
6216 /* Number of elements currently allocated for abbrev_die_table. */
6217 static GTY(()) unsigned abbrev_die_table_allocated
;
6219 /* Number of elements in type_die_table currently in use. */
6220 static GTY(()) unsigned abbrev_die_table_in_use
;
6222 /* Size (in elements) of increments by which we may expand the
6223 abbrev_die_table. */
6224 #define ABBREV_DIE_TABLE_INCREMENT 256
6226 /* A global counter for generating labels for line number data. */
6227 static unsigned int line_info_label_num
;
6229 /* The current table to which we should emit line number information
6230 for the current function. This will be set up at the beginning of
6231 assembly for the function. */
6232 static dw_line_info_table
*cur_line_info_table
;
6234 /* The two default tables of line number info. */
6235 static GTY(()) dw_line_info_table
*text_section_line_info
;
6236 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
6238 /* The set of all non-default tables of line number info. */
6239 static GTY(()) VEC (dw_line_info_table_p
, gc
) *separate_line_info
;
6241 /* A flag to tell pubnames/types export if there is an info section to
6243 static bool info_section_emitted
;
6245 /* A pointer to the base of a table that contains a list of publicly
6246 accessible names. */
6247 static GTY (()) VEC (pubname_entry
, gc
) * pubname_table
;
6249 /* A pointer to the base of a table that contains a list of publicly
6250 accessible types. */
6251 static GTY (()) VEC (pubname_entry
, gc
) * pubtype_table
;
6253 /* A pointer to the base of a table that contains a list of macro
6254 defines/undefines (and file start/end markers). */
6255 static GTY (()) VEC (macinfo_entry
, gc
) * macinfo_table
;
6257 /* Array of dies for which we should generate .debug_ranges info. */
6258 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
6260 /* Number of elements currently allocated for ranges_table. */
6261 static GTY(()) unsigned ranges_table_allocated
;
6263 /* Number of elements in ranges_table currently in use. */
6264 static GTY(()) unsigned ranges_table_in_use
;
6266 /* Array of pairs of labels referenced in ranges_table. */
6267 static GTY ((length ("ranges_by_label_allocated")))
6268 dw_ranges_by_label_ref ranges_by_label
;
6270 /* Number of elements currently allocated for ranges_by_label. */
6271 static GTY(()) unsigned ranges_by_label_allocated
;
6273 /* Number of elements in ranges_by_label currently in use. */
6274 static GTY(()) unsigned ranges_by_label_in_use
;
6276 /* Size (in elements) of increments by which we may expand the
6278 #define RANGES_TABLE_INCREMENT 64
6280 /* Whether we have location lists that need outputting */
6281 static GTY(()) bool have_location_lists
;
6283 /* Unique label counter. */
6284 static GTY(()) unsigned int loclabel_num
;
6286 /* Unique label counter for point-of-call tables. */
6287 static GTY(()) unsigned int poc_label_num
;
6289 /* Record whether the function being analyzed contains inlined functions. */
6290 static int current_function_has_inlines
;
6292 /* The last file entry emitted by maybe_emit_file(). */
6293 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
6295 /* Number of internal labels generated by gen_internal_sym(). */
6296 static GTY(()) int label_num
;
6298 /* Cached result of previous call to lookup_filename. */
6299 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
6301 static GTY(()) VEC(die_arg_entry
,gc
) *tmpl_value_parm_die_table
;
6303 /* Instances of generic types for which we need to generate debug
6304 info that describe their generic parameters and arguments. That
6305 generation needs to happen once all types are properly laid out so
6306 we do it at the end of compilation. */
6307 static GTY(()) VEC(tree
,gc
) *generic_type_instances
;
6309 /* Offset from the "steady-state frame pointer" to the frame base,
6310 within the current function. */
6311 static HOST_WIDE_INT frame_pointer_fb_offset
;
6313 /* Forward declarations for functions defined in this file. */
6315 static int is_pseudo_reg (const_rtx
);
6316 static tree
type_main_variant (tree
);
6317 static int is_tagged_type (const_tree
);
6318 static const char *dwarf_tag_name (unsigned);
6319 static const char *dwarf_attr_name (unsigned);
6320 static const char *dwarf_form_name (unsigned);
6321 static tree
decl_ultimate_origin (const_tree
);
6322 static tree
decl_class_context (tree
);
6323 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
6324 static inline enum dw_val_class
AT_class (dw_attr_ref
);
6325 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
6326 static inline unsigned AT_flag (dw_attr_ref
);
6327 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
6328 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
6329 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
6330 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
6331 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
6332 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
6333 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
6334 unsigned int, unsigned char *);
6335 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
6336 static hashval_t
debug_str_do_hash (const void *);
6337 static int debug_str_eq (const void *, const void *);
6338 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
6339 static inline const char *AT_string (dw_attr_ref
);
6340 static enum dwarf_form
AT_string_form (dw_attr_ref
);
6341 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
6342 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
6343 static inline dw_die_ref
AT_ref (dw_attr_ref
);
6344 static inline int AT_ref_external (dw_attr_ref
);
6345 static inline void set_AT_ref_external (dw_attr_ref
, int);
6346 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
6347 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
6348 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
6349 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
6351 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
6352 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
6353 static inline rtx
AT_addr (dw_attr_ref
);
6354 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
6355 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
6356 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
6357 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
6358 unsigned HOST_WIDE_INT
);
6359 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
6361 static inline const char *AT_lbl (dw_attr_ref
);
6362 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
6363 static const char *get_AT_low_pc (dw_die_ref
);
6364 static const char *get_AT_hi_pc (dw_die_ref
);
6365 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
6366 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
6367 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
6368 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
6369 static bool is_cxx (void);
6370 static bool is_fortran (void);
6371 static bool is_ada (void);
6372 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
6373 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
6374 static void add_child_die (dw_die_ref
, dw_die_ref
);
6375 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
6376 static dw_die_ref
lookup_type_die (tree
);
6377 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
6378 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
6379 static void equate_type_number_to_die (tree
, dw_die_ref
);
6380 static hashval_t
decl_die_table_hash (const void *);
6381 static int decl_die_table_eq (const void *, const void *);
6382 static dw_die_ref
lookup_decl_die (tree
);
6383 static hashval_t
common_block_die_table_hash (const void *);
6384 static int common_block_die_table_eq (const void *, const void *);
6385 static hashval_t
decl_loc_table_hash (const void *);
6386 static int decl_loc_table_eq (const void *, const void *);
6387 static var_loc_list
*lookup_decl_loc (const_tree
);
6388 static void equate_decl_number_to_die (tree
, dw_die_ref
);
6389 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
6390 static void print_spaces (FILE *);
6391 static void print_die (dw_die_ref
, FILE *);
6392 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
6393 static dw_die_ref
pop_compile_unit (dw_die_ref
);
6394 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
6395 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
6396 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
6397 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
6398 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
6399 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
6400 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
6401 struct md5_ctx
*, int *);
6402 struct checksum_attributes
;
6403 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
6404 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
6405 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
6406 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
6407 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
6408 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
6409 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
6410 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
6411 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
6412 static void compute_section_prefix (dw_die_ref
);
6413 static int is_type_die (dw_die_ref
);
6414 static int is_comdat_die (dw_die_ref
);
6415 static int is_symbol_die (dw_die_ref
);
6416 static void assign_symbol_names (dw_die_ref
);
6417 static void break_out_includes (dw_die_ref
);
6418 static int is_declaration_die (dw_die_ref
);
6419 static int should_move_die_to_comdat (dw_die_ref
);
6420 static dw_die_ref
clone_as_declaration (dw_die_ref
);
6421 static dw_die_ref
clone_die (dw_die_ref
);
6422 static dw_die_ref
clone_tree (dw_die_ref
);
6423 static void copy_declaration_context (dw_die_ref
, dw_die_ref
);
6424 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
6425 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
6426 static dw_die_ref
generate_skeleton (dw_die_ref
);
6427 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
6429 static void break_out_comdat_types (dw_die_ref
);
6430 static dw_die_ref
copy_ancestor_tree (dw_die_ref
, dw_die_ref
, htab_t
);
6431 static void copy_decls_walk (dw_die_ref
, dw_die_ref
, htab_t
);
6432 static void copy_decls_for_unworthy_types (dw_die_ref
);
6434 static hashval_t
htab_cu_hash (const void *);
6435 static int htab_cu_eq (const void *, const void *);
6436 static void htab_cu_del (void *);
6437 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
6438 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
6439 static void add_sibling_attributes (dw_die_ref
);
6440 static void build_abbrev_table (dw_die_ref
);
6441 static void output_location_lists (dw_die_ref
);
6442 static int constant_size (unsigned HOST_WIDE_INT
);
6443 static unsigned long size_of_die (dw_die_ref
);
6444 static void calc_die_sizes (dw_die_ref
);
6445 static void mark_dies (dw_die_ref
);
6446 static void unmark_dies (dw_die_ref
);
6447 static void unmark_all_dies (dw_die_ref
);
6448 static unsigned long size_of_pubnames (VEC (pubname_entry
,gc
) *);
6449 static unsigned long size_of_aranges (void);
6450 static enum dwarf_form
value_format (dw_attr_ref
);
6451 static void output_value_format (dw_attr_ref
);
6452 static void output_abbrev_section (void);
6453 static void output_die_symbol (dw_die_ref
);
6454 static void output_die (dw_die_ref
);
6455 static void output_compilation_unit_header (void);
6456 static void output_comp_unit (dw_die_ref
, int);
6457 static void output_comdat_type_unit (comdat_type_node
*);
6458 static const char *dwarf2_name (tree
, int);
6459 static void add_pubname (tree
, dw_die_ref
);
6460 static void add_pubname_string (const char *, dw_die_ref
);
6461 static void add_pubtype (tree
, dw_die_ref
);
6462 static void output_pubnames (VEC (pubname_entry
,gc
) *);
6463 static void output_aranges (unsigned long);
6464 static unsigned int add_ranges_num (int);
6465 static unsigned int add_ranges (const_tree
);
6466 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
6468 static void output_ranges (void);
6469 static dw_line_info_table
*new_line_info_table (void);
6470 static void output_line_info (void);
6471 static void output_file_names (void);
6472 static dw_die_ref
base_type_die (tree
);
6473 static int is_base_type (tree
);
6474 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
6475 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
6476 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
6477 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
6478 static int type_is_enum (const_tree
);
6479 static unsigned int dbx_reg_number (const_rtx
);
6480 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
6481 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
6482 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
6483 enum var_init_status
);
6484 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
6485 enum var_init_status
);
6486 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
6487 enum var_init_status
);
6488 static int is_based_loc (const_rtx
);
6489 static int resolve_one_addr (rtx
*, void *);
6490 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
6491 enum var_init_status
);
6492 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
6493 enum var_init_status
);
6494 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
6495 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
6496 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
6497 static tree
field_type (const_tree
);
6498 static unsigned int simple_type_align_in_bits (const_tree
);
6499 static unsigned int simple_decl_align_in_bits (const_tree
);
6500 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
6501 static HOST_WIDE_INT
field_byte_offset (const_tree
);
6502 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
6504 static void add_data_member_location_attribute (dw_die_ref
, tree
);
6505 static bool add_const_value_attribute (dw_die_ref
, rtx
);
6506 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
6507 static void insert_double (double_int
, unsigned char *);
6508 static void insert_float (const_rtx
, unsigned char *);
6509 static rtx
rtl_for_decl_location (tree
);
6510 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
6511 enum dwarf_attribute
);
6512 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
6513 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
6514 static void add_name_attribute (dw_die_ref
, const char *);
6515 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
6516 static void add_comp_dir_attribute (dw_die_ref
);
6517 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
6518 static void add_subscript_info (dw_die_ref
, tree
, bool);
6519 static void add_byte_size_attribute (dw_die_ref
, tree
);
6520 static void add_bit_offset_attribute (dw_die_ref
, tree
);
6521 static void add_bit_size_attribute (dw_die_ref
, tree
);
6522 static void add_prototyped_attribute (dw_die_ref
, tree
);
6523 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
6524 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
6525 static void add_src_coords_attributes (dw_die_ref
, tree
);
6526 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
6527 static void push_decl_scope (tree
);
6528 static void pop_decl_scope (void);
6529 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
6530 static inline int local_scope_p (dw_die_ref
);
6531 static inline int class_scope_p (dw_die_ref
);
6532 static inline int class_or_namespace_scope_p (dw_die_ref
);
6533 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
6534 static void add_calling_convention_attribute (dw_die_ref
, tree
);
6535 static const char *type_tag (const_tree
);
6536 static tree
member_declared_type (const_tree
);
6538 static const char *decl_start_label (tree
);
6540 static void gen_array_type_die (tree
, dw_die_ref
);
6541 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
6543 static void gen_entry_point_die (tree
, dw_die_ref
);
6545 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
6546 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
6547 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
6548 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
6549 static void gen_formal_types_die (tree
, dw_die_ref
);
6550 static void gen_subprogram_die (tree
, dw_die_ref
);
6551 static void gen_variable_die (tree
, tree
, dw_die_ref
);
6552 static void gen_const_die (tree
, dw_die_ref
);
6553 static void gen_label_die (tree
, dw_die_ref
);
6554 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
6555 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
6556 static void gen_field_die (tree
, dw_die_ref
);
6557 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
6558 static dw_die_ref
gen_compile_unit_die (const char *);
6559 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
6560 static void gen_member_die (tree
, dw_die_ref
);
6561 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
6562 enum debug_info_usage
);
6563 static void gen_subroutine_type_die (tree
, dw_die_ref
);
6564 static void gen_typedef_die (tree
, dw_die_ref
);
6565 static void gen_type_die (tree
, dw_die_ref
);
6566 static void gen_block_die (tree
, dw_die_ref
, int);
6567 static void decls_for_scope (tree
, dw_die_ref
, int);
6568 static inline int is_redundant_typedef (const_tree
);
6569 static bool is_naming_typedef_decl (const_tree
);
6570 static inline dw_die_ref
get_context_die (tree
);
6571 static void gen_namespace_die (tree
, dw_die_ref
);
6572 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
6573 static dw_die_ref
force_decl_die (tree
);
6574 static dw_die_ref
force_type_die (tree
);
6575 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
6576 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
6577 static struct dwarf_file_data
* lookup_filename (const char *);
6578 static void retry_incomplete_types (void);
6579 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
6580 static void gen_generic_params_dies (tree
);
6581 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
6582 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
6583 static void splice_child_die (dw_die_ref
, dw_die_ref
);
6584 static int file_info_cmp (const void *, const void *);
6585 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
6586 const char *, const char *);
6587 static void output_loc_list (dw_loc_list_ref
);
6588 static char *gen_internal_sym (const char *);
6590 static void prune_unmark_dies (dw_die_ref
);
6591 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
6592 static void prune_unused_types_mark (dw_die_ref
, int);
6593 static void prune_unused_types_walk (dw_die_ref
);
6594 static void prune_unused_types_walk_attribs (dw_die_ref
);
6595 static void prune_unused_types_prune (dw_die_ref
);
6596 static void prune_unused_types (void);
6597 static int maybe_emit_file (struct dwarf_file_data
*fd
);
6598 static inline const char *AT_vms_delta1 (dw_attr_ref
);
6599 static inline const char *AT_vms_delta2 (dw_attr_ref
);
6600 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
6601 const char *, const char *);
6602 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
6603 static void gen_remaining_tmpl_value_param_die_attribute (void);
6604 static bool generic_type_p (tree
);
6605 static void schedule_generic_params_dies_gen (tree t
);
6606 static void gen_scheduled_generic_parms_dies (void);
6608 /* Section names used to hold DWARF debugging information. */
6609 #ifndef DEBUG_INFO_SECTION
6610 #define DEBUG_INFO_SECTION ".debug_info"
6612 #ifndef DEBUG_ABBREV_SECTION
6613 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6615 #ifndef DEBUG_ARANGES_SECTION
6616 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6618 #ifndef DEBUG_MACINFO_SECTION
6619 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6621 #ifndef DEBUG_LINE_SECTION
6622 #define DEBUG_LINE_SECTION ".debug_line"
6624 #ifndef DEBUG_LOC_SECTION
6625 #define DEBUG_LOC_SECTION ".debug_loc"
6627 #ifndef DEBUG_PUBNAMES_SECTION
6628 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6630 #ifndef DEBUG_PUBTYPES_SECTION
6631 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6633 #ifndef DEBUG_STR_SECTION
6634 #define DEBUG_STR_SECTION ".debug_str"
6636 #ifndef DEBUG_RANGES_SECTION
6637 #define DEBUG_RANGES_SECTION ".debug_ranges"
6640 /* Standard ELF section names for compiled code and data. */
6641 #ifndef TEXT_SECTION_NAME
6642 #define TEXT_SECTION_NAME ".text"
6645 /* Section flags for .debug_str section. */
6646 #define DEBUG_STR_SECTION_FLAGS \
6647 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6648 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6651 /* Labels we insert at beginning sections we can reference instead of
6652 the section names themselves. */
6654 #ifndef TEXT_SECTION_LABEL
6655 #define TEXT_SECTION_LABEL "Ltext"
6657 #ifndef COLD_TEXT_SECTION_LABEL
6658 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6660 #ifndef DEBUG_LINE_SECTION_LABEL
6661 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6663 #ifndef DEBUG_INFO_SECTION_LABEL
6664 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6666 #ifndef DEBUG_ABBREV_SECTION_LABEL
6667 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6669 #ifndef DEBUG_LOC_SECTION_LABEL
6670 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6672 #ifndef DEBUG_RANGES_SECTION_LABEL
6673 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6675 #ifndef DEBUG_MACINFO_SECTION_LABEL
6676 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6680 /* Definitions of defaults for formats and names of various special
6681 (artificial) labels which may be generated within this file (when the -g
6682 options is used and DWARF2_DEBUGGING_INFO is in effect.
6683 If necessary, these may be overridden from within the tm.h file, but
6684 typically, overriding these defaults is unnecessary. */
6686 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6687 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6688 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6689 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6690 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6691 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6692 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6693 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6694 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6695 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
6697 #ifndef TEXT_END_LABEL
6698 #define TEXT_END_LABEL "Letext"
6700 #ifndef COLD_END_LABEL
6701 #define COLD_END_LABEL "Letext_cold"
6703 #ifndef BLOCK_BEGIN_LABEL
6704 #define BLOCK_BEGIN_LABEL "LBB"
6706 #ifndef BLOCK_END_LABEL
6707 #define BLOCK_END_LABEL "LBE"
6709 #ifndef LINE_CODE_LABEL
6710 #define LINE_CODE_LABEL "LM"
6714 /* Return the root of the DIE's built for the current compilation unit. */
6716 comp_unit_die (void)
6718 if (!single_comp_unit_die
)
6719 single_comp_unit_die
= gen_compile_unit_die (NULL
);
6720 return single_comp_unit_die
;
6723 /* We allow a language front-end to designate a function that is to be
6724 called to "demangle" any name before it is put into a DIE. */
6726 static const char *(*demangle_name_func
) (const char *);
6729 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
6731 demangle_name_func
= func
;
6734 /* Test if rtl node points to a pseudo register. */
6737 is_pseudo_reg (const_rtx rtl
)
6739 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
6740 || (GET_CODE (rtl
) == SUBREG
6741 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
6744 /* Return a reference to a type, with its const and volatile qualifiers
6748 type_main_variant (tree type
)
6750 type
= TYPE_MAIN_VARIANT (type
);
6752 /* ??? There really should be only one main variant among any group of
6753 variants of a given type (and all of the MAIN_VARIANT values for all
6754 members of the group should point to that one type) but sometimes the C
6755 front-end messes this up for array types, so we work around that bug
6757 if (TREE_CODE (type
) == ARRAY_TYPE
)
6758 while (type
!= TYPE_MAIN_VARIANT (type
))
6759 type
= TYPE_MAIN_VARIANT (type
);
6764 /* Return nonzero if the given type node represents a tagged type. */
6767 is_tagged_type (const_tree type
)
6769 enum tree_code code
= TREE_CODE (type
);
6771 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
6772 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
6775 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
6778 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
6780 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
6783 /* Convert a DIE tag into its string name. */
6786 dwarf_tag_name (unsigned int tag
)
6790 case DW_TAG_padding
:
6791 return "DW_TAG_padding";
6792 case DW_TAG_array_type
:
6793 return "DW_TAG_array_type";
6794 case DW_TAG_class_type
:
6795 return "DW_TAG_class_type";
6796 case DW_TAG_entry_point
:
6797 return "DW_TAG_entry_point";
6798 case DW_TAG_enumeration_type
:
6799 return "DW_TAG_enumeration_type";
6800 case DW_TAG_formal_parameter
:
6801 return "DW_TAG_formal_parameter";
6802 case DW_TAG_imported_declaration
:
6803 return "DW_TAG_imported_declaration";
6805 return "DW_TAG_label";
6806 case DW_TAG_lexical_block
:
6807 return "DW_TAG_lexical_block";
6809 return "DW_TAG_member";
6810 case DW_TAG_pointer_type
:
6811 return "DW_TAG_pointer_type";
6812 case DW_TAG_reference_type
:
6813 return "DW_TAG_reference_type";
6814 case DW_TAG_compile_unit
:
6815 return "DW_TAG_compile_unit";
6816 case DW_TAG_string_type
:
6817 return "DW_TAG_string_type";
6818 case DW_TAG_structure_type
:
6819 return "DW_TAG_structure_type";
6820 case DW_TAG_subroutine_type
:
6821 return "DW_TAG_subroutine_type";
6822 case DW_TAG_typedef
:
6823 return "DW_TAG_typedef";
6824 case DW_TAG_union_type
:
6825 return "DW_TAG_union_type";
6826 case DW_TAG_unspecified_parameters
:
6827 return "DW_TAG_unspecified_parameters";
6828 case DW_TAG_variant
:
6829 return "DW_TAG_variant";
6830 case DW_TAG_common_block
:
6831 return "DW_TAG_common_block";
6832 case DW_TAG_common_inclusion
:
6833 return "DW_TAG_common_inclusion";
6834 case DW_TAG_inheritance
:
6835 return "DW_TAG_inheritance";
6836 case DW_TAG_inlined_subroutine
:
6837 return "DW_TAG_inlined_subroutine";
6839 return "DW_TAG_module";
6840 case DW_TAG_ptr_to_member_type
:
6841 return "DW_TAG_ptr_to_member_type";
6842 case DW_TAG_set_type
:
6843 return "DW_TAG_set_type";
6844 case DW_TAG_subrange_type
:
6845 return "DW_TAG_subrange_type";
6846 case DW_TAG_with_stmt
:
6847 return "DW_TAG_with_stmt";
6848 case DW_TAG_access_declaration
:
6849 return "DW_TAG_access_declaration";
6850 case DW_TAG_base_type
:
6851 return "DW_TAG_base_type";
6852 case DW_TAG_catch_block
:
6853 return "DW_TAG_catch_block";
6854 case DW_TAG_const_type
:
6855 return "DW_TAG_const_type";
6856 case DW_TAG_constant
:
6857 return "DW_TAG_constant";
6858 case DW_TAG_enumerator
:
6859 return "DW_TAG_enumerator";
6860 case DW_TAG_file_type
:
6861 return "DW_TAG_file_type";
6863 return "DW_TAG_friend";
6864 case DW_TAG_namelist
:
6865 return "DW_TAG_namelist";
6866 case DW_TAG_namelist_item
:
6867 return "DW_TAG_namelist_item";
6868 case DW_TAG_packed_type
:
6869 return "DW_TAG_packed_type";
6870 case DW_TAG_subprogram
:
6871 return "DW_TAG_subprogram";
6872 case DW_TAG_template_type_param
:
6873 return "DW_TAG_template_type_param";
6874 case DW_TAG_template_value_param
:
6875 return "DW_TAG_template_value_param";
6876 case DW_TAG_thrown_type
:
6877 return "DW_TAG_thrown_type";
6878 case DW_TAG_try_block
:
6879 return "DW_TAG_try_block";
6880 case DW_TAG_variant_part
:
6881 return "DW_TAG_variant_part";
6882 case DW_TAG_variable
:
6883 return "DW_TAG_variable";
6884 case DW_TAG_volatile_type
:
6885 return "DW_TAG_volatile_type";
6886 case DW_TAG_dwarf_procedure
:
6887 return "DW_TAG_dwarf_procedure";
6888 case DW_TAG_restrict_type
:
6889 return "DW_TAG_restrict_type";
6890 case DW_TAG_interface_type
:
6891 return "DW_TAG_interface_type";
6892 case DW_TAG_namespace
:
6893 return "DW_TAG_namespace";
6894 case DW_TAG_imported_module
:
6895 return "DW_TAG_imported_module";
6896 case DW_TAG_unspecified_type
:
6897 return "DW_TAG_unspecified_type";
6898 case DW_TAG_partial_unit
:
6899 return "DW_TAG_partial_unit";
6900 case DW_TAG_imported_unit
:
6901 return "DW_TAG_imported_unit";
6902 case DW_TAG_condition
:
6903 return "DW_TAG_condition";
6904 case DW_TAG_shared_type
:
6905 return "DW_TAG_shared_type";
6906 case DW_TAG_type_unit
:
6907 return "DW_TAG_type_unit";
6908 case DW_TAG_rvalue_reference_type
:
6909 return "DW_TAG_rvalue_reference_type";
6910 case DW_TAG_template_alias
:
6911 return "DW_TAG_template_alias";
6912 case DW_TAG_GNU_template_parameter_pack
:
6913 return "DW_TAG_GNU_template_parameter_pack";
6914 case DW_TAG_GNU_formal_parameter_pack
:
6915 return "DW_TAG_GNU_formal_parameter_pack";
6916 case DW_TAG_MIPS_loop
:
6917 return "DW_TAG_MIPS_loop";
6918 case DW_TAG_format_label
:
6919 return "DW_TAG_format_label";
6920 case DW_TAG_function_template
:
6921 return "DW_TAG_function_template";
6922 case DW_TAG_class_template
:
6923 return "DW_TAG_class_template";
6924 case DW_TAG_GNU_BINCL
:
6925 return "DW_TAG_GNU_BINCL";
6926 case DW_TAG_GNU_EINCL
:
6927 return "DW_TAG_GNU_EINCL";
6928 case DW_TAG_GNU_template_template_param
:
6929 return "DW_TAG_GNU_template_template_param";
6930 case DW_TAG_GNU_call_site
:
6931 return "DW_TAG_GNU_call_site";
6932 case DW_TAG_GNU_call_site_parameter
:
6933 return "DW_TAG_GNU_call_site_parameter";
6935 return "DW_TAG_<unknown>";
6939 /* Convert a DWARF attribute code into its string name. */
6942 dwarf_attr_name (unsigned int attr
)
6947 return "DW_AT_sibling";
6948 case DW_AT_location
:
6949 return "DW_AT_location";
6951 return "DW_AT_name";
6952 case DW_AT_ordering
:
6953 return "DW_AT_ordering";
6954 case DW_AT_subscr_data
:
6955 return "DW_AT_subscr_data";
6956 case DW_AT_byte_size
:
6957 return "DW_AT_byte_size";
6958 case DW_AT_bit_offset
:
6959 return "DW_AT_bit_offset";
6960 case DW_AT_bit_size
:
6961 return "DW_AT_bit_size";
6962 case DW_AT_element_list
:
6963 return "DW_AT_element_list";
6964 case DW_AT_stmt_list
:
6965 return "DW_AT_stmt_list";
6967 return "DW_AT_low_pc";
6969 return "DW_AT_high_pc";
6970 case DW_AT_language
:
6971 return "DW_AT_language";
6973 return "DW_AT_member";
6975 return "DW_AT_discr";
6976 case DW_AT_discr_value
:
6977 return "DW_AT_discr_value";
6978 case DW_AT_visibility
:
6979 return "DW_AT_visibility";
6981 return "DW_AT_import";
6982 case DW_AT_string_length
:
6983 return "DW_AT_string_length";
6984 case DW_AT_common_reference
:
6985 return "DW_AT_common_reference";
6986 case DW_AT_comp_dir
:
6987 return "DW_AT_comp_dir";
6988 case DW_AT_const_value
:
6989 return "DW_AT_const_value";
6990 case DW_AT_containing_type
:
6991 return "DW_AT_containing_type";
6992 case DW_AT_default_value
:
6993 return "DW_AT_default_value";
6995 return "DW_AT_inline";
6996 case DW_AT_is_optional
:
6997 return "DW_AT_is_optional";
6998 case DW_AT_lower_bound
:
6999 return "DW_AT_lower_bound";
7000 case DW_AT_producer
:
7001 return "DW_AT_producer";
7002 case DW_AT_prototyped
:
7003 return "DW_AT_prototyped";
7004 case DW_AT_return_addr
:
7005 return "DW_AT_return_addr";
7006 case DW_AT_start_scope
:
7007 return "DW_AT_start_scope";
7008 case DW_AT_bit_stride
:
7009 return "DW_AT_bit_stride";
7010 case DW_AT_upper_bound
:
7011 return "DW_AT_upper_bound";
7012 case DW_AT_abstract_origin
:
7013 return "DW_AT_abstract_origin";
7014 case DW_AT_accessibility
:
7015 return "DW_AT_accessibility";
7016 case DW_AT_address_class
:
7017 return "DW_AT_address_class";
7018 case DW_AT_artificial
:
7019 return "DW_AT_artificial";
7020 case DW_AT_base_types
:
7021 return "DW_AT_base_types";
7022 case DW_AT_calling_convention
:
7023 return "DW_AT_calling_convention";
7025 return "DW_AT_count";
7026 case DW_AT_data_member_location
:
7027 return "DW_AT_data_member_location";
7028 case DW_AT_decl_column
:
7029 return "DW_AT_decl_column";
7030 case DW_AT_decl_file
:
7031 return "DW_AT_decl_file";
7032 case DW_AT_decl_line
:
7033 return "DW_AT_decl_line";
7034 case DW_AT_declaration
:
7035 return "DW_AT_declaration";
7036 case DW_AT_discr_list
:
7037 return "DW_AT_discr_list";
7038 case DW_AT_encoding
:
7039 return "DW_AT_encoding";
7040 case DW_AT_external
:
7041 return "DW_AT_external";
7042 case DW_AT_explicit
:
7043 return "DW_AT_explicit";
7044 case DW_AT_frame_base
:
7045 return "DW_AT_frame_base";
7047 return "DW_AT_friend";
7048 case DW_AT_identifier_case
:
7049 return "DW_AT_identifier_case";
7050 case DW_AT_macro_info
:
7051 return "DW_AT_macro_info";
7052 case DW_AT_namelist_items
:
7053 return "DW_AT_namelist_items";
7054 case DW_AT_priority
:
7055 return "DW_AT_priority";
7057 return "DW_AT_segment";
7058 case DW_AT_specification
:
7059 return "DW_AT_specification";
7060 case DW_AT_static_link
:
7061 return "DW_AT_static_link";
7063 return "DW_AT_type";
7064 case DW_AT_use_location
:
7065 return "DW_AT_use_location";
7066 case DW_AT_variable_parameter
:
7067 return "DW_AT_variable_parameter";
7068 case DW_AT_virtuality
:
7069 return "DW_AT_virtuality";
7070 case DW_AT_vtable_elem_location
:
7071 return "DW_AT_vtable_elem_location";
7073 case DW_AT_allocated
:
7074 return "DW_AT_allocated";
7075 case DW_AT_associated
:
7076 return "DW_AT_associated";
7077 case DW_AT_data_location
:
7078 return "DW_AT_data_location";
7079 case DW_AT_byte_stride
:
7080 return "DW_AT_byte_stride";
7081 case DW_AT_entry_pc
:
7082 return "DW_AT_entry_pc";
7083 case DW_AT_use_UTF8
:
7084 return "DW_AT_use_UTF8";
7085 case DW_AT_extension
:
7086 return "DW_AT_extension";
7088 return "DW_AT_ranges";
7089 case DW_AT_trampoline
:
7090 return "DW_AT_trampoline";
7091 case DW_AT_call_column
:
7092 return "DW_AT_call_column";
7093 case DW_AT_call_file
:
7094 return "DW_AT_call_file";
7095 case DW_AT_call_line
:
7096 return "DW_AT_call_line";
7097 case DW_AT_object_pointer
:
7098 return "DW_AT_object_pointer";
7100 case DW_AT_signature
:
7101 return "DW_AT_signature";
7102 case DW_AT_main_subprogram
:
7103 return "DW_AT_main_subprogram";
7104 case DW_AT_data_bit_offset
:
7105 return "DW_AT_data_bit_offset";
7106 case DW_AT_const_expr
:
7107 return "DW_AT_const_expr";
7108 case DW_AT_enum_class
:
7109 return "DW_AT_enum_class";
7110 case DW_AT_linkage_name
:
7111 return "DW_AT_linkage_name";
7113 case DW_AT_MIPS_fde
:
7114 return "DW_AT_MIPS_fde";
7115 case DW_AT_MIPS_loop_begin
:
7116 return "DW_AT_MIPS_loop_begin";
7117 case DW_AT_MIPS_tail_loop_begin
:
7118 return "DW_AT_MIPS_tail_loop_begin";
7119 case DW_AT_MIPS_epilog_begin
:
7120 return "DW_AT_MIPS_epilog_begin";
7121 #if VMS_DEBUGGING_INFO
7122 case DW_AT_HP_prologue
:
7123 return "DW_AT_HP_prologue";
7125 case DW_AT_MIPS_loop_unroll_factor
:
7126 return "DW_AT_MIPS_loop_unroll_factor";
7128 case DW_AT_MIPS_software_pipeline_depth
:
7129 return "DW_AT_MIPS_software_pipeline_depth";
7130 case DW_AT_MIPS_linkage_name
:
7131 return "DW_AT_MIPS_linkage_name";
7132 #if VMS_DEBUGGING_INFO
7133 case DW_AT_HP_epilogue
:
7134 return "DW_AT_HP_epilogue";
7136 case DW_AT_MIPS_stride
:
7137 return "DW_AT_MIPS_stride";
7139 case DW_AT_MIPS_abstract_name
:
7140 return "DW_AT_MIPS_abstract_name";
7141 case DW_AT_MIPS_clone_origin
:
7142 return "DW_AT_MIPS_clone_origin";
7143 case DW_AT_MIPS_has_inlines
:
7144 return "DW_AT_MIPS_has_inlines";
7146 case DW_AT_sf_names
:
7147 return "DW_AT_sf_names";
7148 case DW_AT_src_info
:
7149 return "DW_AT_src_info";
7150 case DW_AT_mac_info
:
7151 return "DW_AT_mac_info";
7152 case DW_AT_src_coords
:
7153 return "DW_AT_src_coords";
7154 case DW_AT_body_begin
:
7155 return "DW_AT_body_begin";
7156 case DW_AT_body_end
:
7157 return "DW_AT_body_end";
7159 case DW_AT_GNU_vector
:
7160 return "DW_AT_GNU_vector";
7161 case DW_AT_GNU_guarded_by
:
7162 return "DW_AT_GNU_guarded_by";
7163 case DW_AT_GNU_pt_guarded_by
:
7164 return "DW_AT_GNU_pt_guarded_by";
7165 case DW_AT_GNU_guarded
:
7166 return "DW_AT_GNU_guarded";
7167 case DW_AT_GNU_pt_guarded
:
7168 return "DW_AT_GNU_pt_guarded";
7169 case DW_AT_GNU_locks_excluded
:
7170 return "DW_AT_GNU_locks_excluded";
7171 case DW_AT_GNU_exclusive_locks_required
:
7172 return "DW_AT_GNU_exclusive_locks_required";
7173 case DW_AT_GNU_shared_locks_required
:
7174 return "DW_AT_GNU_shared_locks_required";
7175 case DW_AT_GNU_odr_signature
:
7176 return "DW_AT_GNU_odr_signature";
7177 case DW_AT_GNU_template_name
:
7178 return "DW_AT_GNU_template_name";
7179 case DW_AT_GNU_call_site_value
:
7180 return "DW_AT_GNU_call_site_value";
7181 case DW_AT_GNU_call_site_data_value
:
7182 return "DW_AT_GNU_call_site_data_value";
7183 case DW_AT_GNU_call_site_target
:
7184 return "DW_AT_GNU_call_site_target";
7185 case DW_AT_GNU_call_site_target_clobbered
:
7186 return "DW_AT_GNU_call_site_target_clobbered";
7187 case DW_AT_GNU_tail_call
:
7188 return "DW_AT_GNU_tail_call";
7189 case DW_AT_GNU_all_tail_call_sites
:
7190 return "DW_AT_GNU_all_tail_call_sites";
7191 case DW_AT_GNU_all_call_sites
:
7192 return "DW_AT_GNU_all_call_sites";
7193 case DW_AT_GNU_all_source_call_sites
:
7194 return "DW_AT_GNU_all_source_call_sites";
7196 case DW_AT_GNAT_descriptive_type
:
7197 return "DW_AT_GNAT_descriptive_type";
7199 case DW_AT_VMS_rtnbeg_pd_address
:
7200 return "DW_AT_VMS_rtnbeg_pd_address";
7203 return "DW_AT_<unknown>";
7207 /* Convert a DWARF value form code into its string name. */
7210 dwarf_form_name (unsigned int form
)
7215 return "DW_FORM_addr";
7216 case DW_FORM_block2
:
7217 return "DW_FORM_block2";
7218 case DW_FORM_block4
:
7219 return "DW_FORM_block4";
7221 return "DW_FORM_data2";
7223 return "DW_FORM_data4";
7225 return "DW_FORM_data8";
7226 case DW_FORM_string
:
7227 return "DW_FORM_string";
7229 return "DW_FORM_block";
7230 case DW_FORM_block1
:
7231 return "DW_FORM_block1";
7233 return "DW_FORM_data1";
7235 return "DW_FORM_flag";
7237 return "DW_FORM_sdata";
7239 return "DW_FORM_strp";
7241 return "DW_FORM_udata";
7242 case DW_FORM_ref_addr
:
7243 return "DW_FORM_ref_addr";
7245 return "DW_FORM_ref1";
7247 return "DW_FORM_ref2";
7249 return "DW_FORM_ref4";
7251 return "DW_FORM_ref8";
7252 case DW_FORM_ref_udata
:
7253 return "DW_FORM_ref_udata";
7254 case DW_FORM_indirect
:
7255 return "DW_FORM_indirect";
7256 case DW_FORM_sec_offset
:
7257 return "DW_FORM_sec_offset";
7258 case DW_FORM_exprloc
:
7259 return "DW_FORM_exprloc";
7260 case DW_FORM_flag_present
:
7261 return "DW_FORM_flag_present";
7262 case DW_FORM_ref_sig8
:
7263 return "DW_FORM_ref_sig8";
7265 return "DW_FORM_<unknown>";
7269 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
7270 instance of an inlined instance of a decl which is local to an inline
7271 function, so we have to trace all of the way back through the origin chain
7272 to find out what sort of node actually served as the original seed for the
7276 decl_ultimate_origin (const_tree decl
)
7278 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
7281 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
7282 nodes in the function to point to themselves; ignore that if
7283 we're trying to output the abstract instance of this function. */
7284 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
7287 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
7288 most distant ancestor, this should never happen. */
7289 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
7291 return DECL_ABSTRACT_ORIGIN (decl
);
7294 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
7295 of a virtual function may refer to a base class, so we check the 'this'
7299 decl_class_context (tree decl
)
7301 tree context
= NULL_TREE
;
7303 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
7304 context
= DECL_CONTEXT (decl
);
7306 context
= TYPE_MAIN_VARIANT
7307 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
7309 if (context
&& !TYPE_P (context
))
7310 context
= NULL_TREE
;
7315 /* Add an attribute/value pair to a DIE. */
7318 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
7320 /* Maybe this should be an assert? */
7324 if (die
->die_attr
== NULL
)
7325 die
->die_attr
= VEC_alloc (dw_attr_node
, gc
, 1);
7326 VEC_safe_push (dw_attr_node
, gc
, die
->die_attr
, attr
);
7329 static inline enum dw_val_class
7330 AT_class (dw_attr_ref a
)
7332 return a
->dw_attr_val
.val_class
;
7335 /* Add a flag value attribute to a DIE. */
7338 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
7342 attr
.dw_attr
= attr_kind
;
7343 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
7344 attr
.dw_attr_val
.v
.val_flag
= flag
;
7345 add_dwarf_attr (die
, &attr
);
7348 static inline unsigned
7349 AT_flag (dw_attr_ref a
)
7351 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
7352 return a
->dw_attr_val
.v
.val_flag
;
7355 /* Add a signed integer attribute value to a DIE. */
7358 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
7362 attr
.dw_attr
= attr_kind
;
7363 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
7364 attr
.dw_attr_val
.v
.val_int
= int_val
;
7365 add_dwarf_attr (die
, &attr
);
7368 static inline HOST_WIDE_INT
7369 AT_int (dw_attr_ref a
)
7371 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
7372 return a
->dw_attr_val
.v
.val_int
;
7375 /* Add an unsigned integer attribute value to a DIE. */
7378 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7379 unsigned HOST_WIDE_INT unsigned_val
)
7383 attr
.dw_attr
= attr_kind
;
7384 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
7385 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
7386 add_dwarf_attr (die
, &attr
);
7389 static inline unsigned HOST_WIDE_INT
7390 AT_unsigned (dw_attr_ref a
)
7392 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
7393 return a
->dw_attr_val
.v
.val_unsigned
;
7396 /* Add an unsigned double integer attribute value to a DIE. */
7399 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7400 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
7404 attr
.dw_attr
= attr_kind
;
7405 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
7406 attr
.dw_attr_val
.v
.val_double
.high
= high
;
7407 attr
.dw_attr_val
.v
.val_double
.low
= low
;
7408 add_dwarf_attr (die
, &attr
);
7411 /* Add a floating point attribute value to a DIE and return it. */
7414 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7415 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
7419 attr
.dw_attr
= attr_kind
;
7420 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
7421 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
7422 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
7423 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
7424 add_dwarf_attr (die
, &attr
);
7427 /* Add an 8-byte data attribute value to a DIE. */
7430 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7431 unsigned char data8
[8])
7435 attr
.dw_attr
= attr_kind
;
7436 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
7437 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
7438 add_dwarf_attr (die
, &attr
);
7441 /* Hash and equality functions for debug_str_hash. */
7444 debug_str_do_hash (const void *x
)
7446 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
7450 debug_str_eq (const void *x1
, const void *x2
)
7452 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
7453 (const char *)x2
) == 0;
7456 /* Add STR to the indirect string hash table. */
7458 static struct indirect_string_node
*
7459 find_AT_string (const char *str
)
7461 struct indirect_string_node
*node
;
7464 if (! debug_str_hash
)
7465 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
7466 debug_str_eq
, NULL
);
7468 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
7469 htab_hash_string (str
), INSERT
);
7472 node
= ggc_alloc_cleared_indirect_string_node ();
7473 node
->str
= ggc_strdup (str
);
7477 node
= (struct indirect_string_node
*) *slot
;
7483 /* Add a string attribute value to a DIE. */
7486 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
7489 struct indirect_string_node
*node
;
7491 node
= find_AT_string (str
);
7493 attr
.dw_attr
= attr_kind
;
7494 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
7495 attr
.dw_attr_val
.v
.val_str
= node
;
7496 add_dwarf_attr (die
, &attr
);
7499 /* Create a label for an indirect string node, ensuring it is going to
7500 be output, unless its reference count goes down to zero. */
7503 gen_label_for_indirect_string (struct indirect_string_node
*node
)
7510 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
7511 ++dw2_string_counter
;
7512 node
->label
= xstrdup (label
);
7515 /* Create a SYMBOL_REF rtx whose value is the initial address of a
7516 debug string STR. */
7519 get_debug_string_label (const char *str
)
7521 struct indirect_string_node
*node
= find_AT_string (str
);
7523 debug_str_hash_forced
= true;
7525 gen_label_for_indirect_string (node
);
7527 return gen_rtx_SYMBOL_REF (Pmode
, node
->label
);
7530 static inline const char *
7531 AT_string (dw_attr_ref a
)
7533 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
7534 return a
->dw_attr_val
.v
.val_str
->str
;
7537 /* Find out whether a string should be output inline in DIE
7538 or out-of-line in .debug_str section. */
7540 static enum dwarf_form
7541 AT_string_form (dw_attr_ref a
)
7543 struct indirect_string_node
*node
;
7546 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
7548 node
= a
->dw_attr_val
.v
.val_str
;
7552 len
= strlen (node
->str
) + 1;
7554 /* If the string is shorter or equal to the size of the reference, it is
7555 always better to put it inline. */
7556 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
7557 return node
->form
= DW_FORM_string
;
7559 /* If we cannot expect the linker to merge strings in .debug_str
7560 section, only put it into .debug_str if it is worth even in this
7562 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
7563 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
7564 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
7565 return node
->form
= DW_FORM_string
;
7567 gen_label_for_indirect_string (node
);
7569 return node
->form
= DW_FORM_strp
;
7572 /* Add a DIE reference attribute value to a DIE. */
7575 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
7579 #ifdef ENABLE_CHECKING
7580 gcc_assert (targ_die
!= NULL
);
7582 /* With LTO we can end up trying to reference something we didn't create
7583 a DIE for. Avoid crashing later on a NULL referenced DIE. */
7584 if (targ_die
== NULL
)
7588 attr
.dw_attr
= attr_kind
;
7589 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
7590 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
7591 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
7592 add_dwarf_attr (die
, &attr
);
7595 /* Add an AT_specification attribute to a DIE, and also make the back
7596 pointer from the specification to the definition. */
7599 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
7601 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
7602 gcc_assert (!targ_die
->die_definition
);
7603 targ_die
->die_definition
= die
;
7606 static inline dw_die_ref
7607 AT_ref (dw_attr_ref a
)
7609 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
7610 return a
->dw_attr_val
.v
.val_die_ref
.die
;
7614 AT_ref_external (dw_attr_ref a
)
7616 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
7617 return a
->dw_attr_val
.v
.val_die_ref
.external
;
7623 set_AT_ref_external (dw_attr_ref a
, int i
)
7625 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
7626 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
7629 /* Add an FDE reference attribute value to a DIE. */
7632 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
7636 attr
.dw_attr
= attr_kind
;
7637 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
7638 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
7639 add_dwarf_attr (die
, &attr
);
7642 /* Add a location description attribute value to a DIE. */
7645 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
7649 attr
.dw_attr
= attr_kind
;
7650 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
7651 attr
.dw_attr_val
.v
.val_loc
= loc
;
7652 add_dwarf_attr (die
, &attr
);
7655 static inline dw_loc_descr_ref
7656 AT_loc (dw_attr_ref a
)
7658 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
7659 return a
->dw_attr_val
.v
.val_loc
;
7663 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
7667 attr
.dw_attr
= attr_kind
;
7668 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
7669 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
7670 add_dwarf_attr (die
, &attr
);
7671 have_location_lists
= true;
7674 static inline dw_loc_list_ref
7675 AT_loc_list (dw_attr_ref a
)
7677 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
7678 return a
->dw_attr_val
.v
.val_loc_list
;
7681 static inline dw_loc_list_ref
*
7682 AT_loc_list_ptr (dw_attr_ref a
)
7684 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
7685 return &a
->dw_attr_val
.v
.val_loc_list
;
7688 /* Add an address constant attribute value to a DIE. */
7691 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
7695 attr
.dw_attr
= attr_kind
;
7696 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
7697 attr
.dw_attr_val
.v
.val_addr
= addr
;
7698 add_dwarf_attr (die
, &attr
);
7701 /* Get the RTX from to an address DIE attribute. */
7704 AT_addr (dw_attr_ref a
)
7706 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
7707 return a
->dw_attr_val
.v
.val_addr
;
7710 /* Add a file attribute value to a DIE. */
7713 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7714 struct dwarf_file_data
*fd
)
7718 attr
.dw_attr
= attr_kind
;
7719 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
7720 attr
.dw_attr_val
.v
.val_file
= fd
;
7721 add_dwarf_attr (die
, &attr
);
7724 /* Get the dwarf_file_data from a file DIE attribute. */
7726 static inline struct dwarf_file_data
*
7727 AT_file (dw_attr_ref a
)
7729 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
7730 return a
->dw_attr_val
.v
.val_file
;
7733 /* Add a vms delta attribute value to a DIE. */
7736 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7737 const char *lbl1
, const char *lbl2
)
7741 attr
.dw_attr
= attr_kind
;
7742 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
7743 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
7744 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
7745 add_dwarf_attr (die
, &attr
);
7748 /* Add a label identifier attribute value to a DIE. */
7751 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
7755 attr
.dw_attr
= attr_kind
;
7756 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
7757 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
7758 add_dwarf_attr (die
, &attr
);
7761 /* Add a section offset attribute value to a DIE, an offset into the
7762 debug_line section. */
7765 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7770 attr
.dw_attr
= attr_kind
;
7771 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
7772 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
7773 add_dwarf_attr (die
, &attr
);
7776 /* Add a section offset attribute value to a DIE, an offset into the
7777 debug_macinfo section. */
7780 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7785 attr
.dw_attr
= attr_kind
;
7786 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
7787 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
7788 add_dwarf_attr (die
, &attr
);
7791 /* Add an offset attribute value to a DIE. */
7794 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7795 unsigned HOST_WIDE_INT offset
)
7799 attr
.dw_attr
= attr_kind
;
7800 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
7801 attr
.dw_attr_val
.v
.val_offset
= offset
;
7802 add_dwarf_attr (die
, &attr
);
7805 /* Add an range_list attribute value to a DIE. */
7808 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7809 long unsigned int offset
)
7813 attr
.dw_attr
= attr_kind
;
7814 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
7815 attr
.dw_attr_val
.v
.val_offset
= offset
;
7816 add_dwarf_attr (die
, &attr
);
7819 /* Return the start label of a delta attribute. */
7821 static inline const char *
7822 AT_vms_delta1 (dw_attr_ref a
)
7824 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
7825 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
7828 /* Return the end label of a delta attribute. */
7830 static inline const char *
7831 AT_vms_delta2 (dw_attr_ref a
)
7833 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
7834 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
7837 static inline const char *
7838 AT_lbl (dw_attr_ref a
)
7840 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
7841 || AT_class (a
) == dw_val_class_lineptr
7842 || AT_class (a
) == dw_val_class_macptr
));
7843 return a
->dw_attr_val
.v
.val_lbl_id
;
7846 /* Get the attribute of type attr_kind. */
7849 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7853 dw_die_ref spec
= NULL
;
7858 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7859 if (a
->dw_attr
== attr_kind
)
7861 else if (a
->dw_attr
== DW_AT_specification
7862 || a
->dw_attr
== DW_AT_abstract_origin
)
7866 return get_AT (spec
, attr_kind
);
7871 /* Return the "low pc" attribute value, typically associated with a subprogram
7872 DIE. Return null if the "low pc" attribute is either not present, or if it
7873 cannot be represented as an assembler label identifier. */
7875 static inline const char *
7876 get_AT_low_pc (dw_die_ref die
)
7878 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
7880 return a
? AT_lbl (a
) : NULL
;
7883 /* Return the "high pc" attribute value, typically associated with a subprogram
7884 DIE. Return null if the "high pc" attribute is either not present, or if it
7885 cannot be represented as an assembler label identifier. */
7887 static inline const char *
7888 get_AT_hi_pc (dw_die_ref die
)
7890 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
7892 return a
? AT_lbl (a
) : NULL
;
7895 /* Return the value of the string attribute designated by ATTR_KIND, or
7896 NULL if it is not present. */
7898 static inline const char *
7899 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7901 dw_attr_ref a
= get_AT (die
, attr_kind
);
7903 return a
? AT_string (a
) : NULL
;
7906 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
7907 if it is not present. */
7910 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7912 dw_attr_ref a
= get_AT (die
, attr_kind
);
7914 return a
? AT_flag (a
) : 0;
7917 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
7918 if it is not present. */
7920 static inline unsigned
7921 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7923 dw_attr_ref a
= get_AT (die
, attr_kind
);
7925 return a
? AT_unsigned (a
) : 0;
7928 static inline dw_die_ref
7929 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7931 dw_attr_ref a
= get_AT (die
, attr_kind
);
7933 return a
? AT_ref (a
) : NULL
;
7936 static inline struct dwarf_file_data
*
7937 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7939 dw_attr_ref a
= get_AT (die
, attr_kind
);
7941 return a
? AT_file (a
) : NULL
;
7944 /* Return TRUE if the language is C++. */
7949 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
7951 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
7954 /* Return TRUE if the language is Fortran. */
7959 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
7961 return (lang
== DW_LANG_Fortran77
7962 || lang
== DW_LANG_Fortran90
7963 || lang
== DW_LANG_Fortran95
);
7966 /* Return TRUE if the language is Ada. */
7971 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
7973 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
7976 /* Remove the specified attribute if present. */
7979 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7987 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7988 if (a
->dw_attr
== attr_kind
)
7990 if (AT_class (a
) == dw_val_class_str
)
7991 if (a
->dw_attr_val
.v
.val_str
->refcount
)
7992 a
->dw_attr_val
.v
.val_str
->refcount
--;
7994 /* VEC_ordered_remove should help reduce the number of abbrevs
7996 VEC_ordered_remove (dw_attr_node
, die
->die_attr
, ix
);
8001 /* Remove CHILD from its parent. PREV must have the property that
8002 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
8005 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
8007 gcc_assert (child
->die_parent
== prev
->die_parent
);
8008 gcc_assert (prev
->die_sib
== child
);
8011 gcc_assert (child
->die_parent
->die_child
== child
);
8015 prev
->die_sib
= child
->die_sib
;
8016 if (child
->die_parent
->die_child
== child
)
8017 child
->die_parent
->die_child
= prev
;
8020 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
8021 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
8024 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
8026 dw_die_ref parent
= old_child
->die_parent
;
8028 gcc_assert (parent
== prev
->die_parent
);
8029 gcc_assert (prev
->die_sib
== old_child
);
8031 new_child
->die_parent
= parent
;
8032 if (prev
== old_child
)
8034 gcc_assert (parent
->die_child
== old_child
);
8035 new_child
->die_sib
= new_child
;
8039 prev
->die_sib
= new_child
;
8040 new_child
->die_sib
= old_child
->die_sib
;
8042 if (old_child
->die_parent
->die_child
== old_child
)
8043 old_child
->die_parent
->die_child
= new_child
;
8046 /* Move all children from OLD_PARENT to NEW_PARENT. */
8049 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
8052 new_parent
->die_child
= old_parent
->die_child
;
8053 old_parent
->die_child
= NULL
;
8054 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
8057 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
8061 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
8067 dw_die_ref prev
= c
;
8069 while (c
->die_tag
== tag
)
8071 remove_child_with_prev (c
, prev
);
8072 /* Might have removed every child. */
8073 if (c
== c
->die_sib
)
8077 } while (c
!= die
->die_child
);
8080 /* Add a CHILD_DIE as the last child of DIE. */
8083 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
8085 /* FIXME this should probably be an assert. */
8086 if (! die
|| ! child_die
)
8088 gcc_assert (die
!= child_die
);
8090 child_die
->die_parent
= die
;
8093 child_die
->die_sib
= die
->die_child
->die_sib
;
8094 die
->die_child
->die_sib
= child_die
;
8097 child_die
->die_sib
= child_die
;
8098 die
->die_child
= child_die
;
8101 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
8102 is the specification, to the end of PARENT's list of children.
8103 This is done by removing and re-adding it. */
8106 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
8110 /* We want the declaration DIE from inside the class, not the
8111 specification DIE at toplevel. */
8112 if (child
->die_parent
!= parent
)
8114 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
8120 gcc_assert (child
->die_parent
== parent
8121 || (child
->die_parent
8122 == get_AT_ref (parent
, DW_AT_specification
)));
8124 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
8125 if (p
->die_sib
== child
)
8127 remove_child_with_prev (child
, p
);
8131 add_child_die (parent
, child
);
8134 /* Return a pointer to a newly created DIE node. */
8136 static inline dw_die_ref
8137 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
8139 dw_die_ref die
= ggc_alloc_cleared_die_node ();
8141 die
->die_tag
= tag_value
;
8143 if (parent_die
!= NULL
)
8144 add_child_die (parent_die
, die
);
8147 limbo_die_node
*limbo_node
;
8149 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
8150 limbo_node
->die
= die
;
8151 limbo_node
->created_for
= t
;
8152 limbo_node
->next
= limbo_die_list
;
8153 limbo_die_list
= limbo_node
;
8159 /* Return the DIE associated with the given type specifier. */
8161 static inline dw_die_ref
8162 lookup_type_die (tree type
)
8164 return TYPE_SYMTAB_DIE (type
);
8167 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
8168 anonymous type named by the typedef TYPE_DIE, return the DIE of the
8169 anonymous type instead the one of the naming typedef. */
8171 static inline dw_die_ref
8172 strip_naming_typedef (tree type
, dw_die_ref type_die
)
8175 && TREE_CODE (type
) == RECORD_TYPE
8177 && type_die
->die_tag
== DW_TAG_typedef
8178 && is_naming_typedef_decl (TYPE_NAME (type
)))
8179 type_die
= get_AT_ref (type_die
, DW_AT_type
);
8183 /* Like lookup_type_die, but if type is an anonymous type named by a
8184 typedef[1], return the DIE of the anonymous type instead the one of
8185 the naming typedef. This is because in gen_typedef_die, we did
8186 equate the anonymous struct named by the typedef with the DIE of
8187 the naming typedef. So by default, lookup_type_die on an anonymous
8188 struct yields the DIE of the naming typedef.
8190 [1]: Read the comment of is_naming_typedef_decl to learn about what
8191 a naming typedef is. */
8193 static inline dw_die_ref
8194 lookup_type_die_strip_naming_typedef (tree type
)
8196 dw_die_ref die
= lookup_type_die (type
);
8197 return strip_naming_typedef (type
, die
);
8200 /* Equate a DIE to a given type specifier. */
8203 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
8205 TYPE_SYMTAB_DIE (type
) = type_die
;
8208 /* Returns a hash value for X (which really is a die_struct). */
8211 decl_die_table_hash (const void *x
)
8213 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
8216 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
8219 decl_die_table_eq (const void *x
, const void *y
)
8221 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
8224 /* Return the DIE associated with a given declaration. */
8226 static inline dw_die_ref
8227 lookup_decl_die (tree decl
)
8229 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
8232 /* Returns a hash value for X (which really is a var_loc_list). */
8235 decl_loc_table_hash (const void *x
)
8237 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
8240 /* Return nonzero if decl_id of var_loc_list X is the same as
8244 decl_loc_table_eq (const void *x
, const void *y
)
8246 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
8249 /* Return the var_loc list associated with a given declaration. */
8251 static inline var_loc_list
*
8252 lookup_decl_loc (const_tree decl
)
8254 if (!decl_loc_table
)
8256 return (var_loc_list
*)
8257 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
8260 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
8263 cached_dw_loc_list_table_hash (const void *x
)
8265 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
8268 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
8272 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
8274 return (((const cached_dw_loc_list
*) x
)->decl_id
8275 == DECL_UID ((const_tree
) y
));
8278 /* Equate a DIE to a particular declaration. */
8281 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
8283 unsigned int decl_id
= DECL_UID (decl
);
8286 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
8288 decl_die
->decl_id
= decl_id
;
8291 /* Return how many bits covers PIECE EXPR_LIST. */
8294 decl_piece_bitsize (rtx piece
)
8296 int ret
= (int) GET_MODE (piece
);
8299 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
8300 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
8301 return INTVAL (XEXP (XEXP (piece
, 0), 0));
8304 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
8307 decl_piece_varloc_ptr (rtx piece
)
8309 if ((int) GET_MODE (piece
))
8310 return &XEXP (piece
, 0);
8312 return &XEXP (XEXP (piece
, 0), 1);
8315 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
8316 Next is the chain of following piece nodes. */
8319 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
8321 if (bitsize
<= (int) MAX_MACHINE_MODE
)
8322 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
8324 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
8329 /* Return rtx that should be stored into loc field for
8330 LOC_NOTE and BITPOS/BITSIZE. */
8333 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
8334 HOST_WIDE_INT bitsize
)
8338 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
8340 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
8345 /* This function either modifies location piece list *DEST in
8346 place (if SRC and INNER is NULL), or copies location piece list
8347 *SRC to *DEST while modifying it. Location BITPOS is modified
8348 to contain LOC_NOTE, any pieces overlapping it are removed resp.
8349 not copied and if needed some padding around it is added.
8350 When modifying in place, DEST should point to EXPR_LIST where
8351 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
8352 to the start of the whole list and INNER points to the EXPR_LIST
8353 where earlier pieces cover PIECE_BITPOS bits. */
8356 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
8357 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
8358 HOST_WIDE_INT bitsize
, rtx loc_note
)
8361 bool copy
= inner
!= NULL
;
8365 /* First copy all nodes preceeding the current bitpos. */
8366 while (src
!= inner
)
8368 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
8369 decl_piece_bitsize (*src
), NULL_RTX
);
8370 dest
= &XEXP (*dest
, 1);
8371 src
= &XEXP (*src
, 1);
8374 /* Add padding if needed. */
8375 if (bitpos
!= piece_bitpos
)
8377 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
8378 copy
? NULL_RTX
: *dest
);
8379 dest
= &XEXP (*dest
, 1);
8381 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
8384 /* A piece with correct bitpos and bitsize already exist,
8385 just update the location for it and return. */
8386 *decl_piece_varloc_ptr (*dest
) = loc_note
;
8389 /* Add the piece that changed. */
8390 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
8391 dest
= &XEXP (*dest
, 1);
8392 /* Skip over pieces that overlap it. */
8393 diff
= bitpos
- piece_bitpos
+ bitsize
;
8396 while (diff
> 0 && *src
)
8399 diff
-= decl_piece_bitsize (piece
);
8401 src
= &XEXP (piece
, 1);
8404 *src
= XEXP (piece
, 1);
8405 free_EXPR_LIST_node (piece
);
8408 /* Add padding if needed. */
8409 if (diff
< 0 && *src
)
8413 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
8414 dest
= &XEXP (*dest
, 1);
8418 /* Finally copy all nodes following it. */
8421 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
8422 decl_piece_bitsize (*src
), NULL_RTX
);
8423 dest
= &XEXP (*dest
, 1);
8424 src
= &XEXP (*src
, 1);
8428 /* Add a variable location node to the linked list for DECL. */
8430 static struct var_loc_node
*
8431 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
8433 unsigned int decl_id
;
8436 struct var_loc_node
*loc
= NULL
;
8437 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
8439 if (DECL_DEBUG_EXPR_IS_FROM (decl
))
8441 tree realdecl
= DECL_DEBUG_EXPR (decl
);
8442 if (realdecl
&& handled_component_p (realdecl
))
8444 HOST_WIDE_INT maxsize
;
8447 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
8448 if (!DECL_P (innerdecl
)
8449 || DECL_IGNORED_P (innerdecl
)
8450 || TREE_STATIC (innerdecl
)
8452 || bitpos
+ bitsize
> 256
8453 || bitsize
!= maxsize
)
8459 decl_id
= DECL_UID (decl
);
8460 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
8463 temp
= ggc_alloc_cleared_var_loc_list ();
8464 temp
->decl_id
= decl_id
;
8468 temp
= (var_loc_list
*) *slot
;
8472 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
8473 rtx
*piece_loc
= NULL
, last_loc_note
;
8474 int piece_bitpos
= 0;
8478 gcc_assert (last
->next
== NULL
);
8480 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
8482 piece_loc
= &last
->loc
;
8485 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
8486 if (piece_bitpos
+ cur_bitsize
> bitpos
)
8488 piece_bitpos
+= cur_bitsize
;
8489 piece_loc
= &XEXP (*piece_loc
, 1);
8493 /* TEMP->LAST here is either pointer to the last but one or
8494 last element in the chained list, LAST is pointer to the
8496 if (label
&& strcmp (last
->label
, label
) == 0)
8498 /* For SRA optimized variables if there weren't any real
8499 insns since last note, just modify the last node. */
8500 if (piece_loc
!= NULL
)
8502 adjust_piece_list (piece_loc
, NULL
, NULL
,
8503 bitpos
, piece_bitpos
, bitsize
, loc_note
);
8506 /* If the last note doesn't cover any instructions, remove it. */
8507 if (temp
->last
!= last
)
8509 temp
->last
->next
= NULL
;
8512 gcc_assert (strcmp (last
->label
, label
) != 0);
8516 gcc_assert (temp
->first
== temp
->last
);
8517 memset (temp
->last
, '\0', sizeof (*temp
->last
));
8518 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
8522 if (bitsize
== -1 && NOTE_P (last
->loc
))
8523 last_loc_note
= last
->loc
;
8524 else if (piece_loc
!= NULL
8525 && *piece_loc
!= NULL_RTX
8526 && piece_bitpos
== bitpos
8527 && decl_piece_bitsize (*piece_loc
) == bitsize
)
8528 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
8530 last_loc_note
= NULL_RTX
;
8531 /* If the current location is the same as the end of the list,
8532 and either both or neither of the locations is uninitialized,
8533 we have nothing to do. */
8534 if (last_loc_note
== NULL_RTX
8535 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
8536 NOTE_VAR_LOCATION_LOC (loc_note
)))
8537 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
8538 != NOTE_VAR_LOCATION_STATUS (loc_note
))
8539 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
8540 == VAR_INIT_STATUS_UNINITIALIZED
)
8541 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
8542 == VAR_INIT_STATUS_UNINITIALIZED
))))
8544 /* Add LOC to the end of list and update LAST. If the last
8545 element of the list has been removed above, reuse its
8546 memory for the new node, otherwise allocate a new one. */
8550 memset (loc
, '\0', sizeof (*loc
));
8553 loc
= ggc_alloc_cleared_var_loc_node ();
8554 if (bitsize
== -1 || piece_loc
== NULL
)
8555 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
8557 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
8558 bitpos
, piece_bitpos
, bitsize
, loc_note
);
8560 /* Ensure TEMP->LAST will point either to the new last but one
8561 element of the chain, or to the last element in it. */
8562 if (last
!= temp
->last
)
8570 loc
= ggc_alloc_cleared_var_loc_node ();
8573 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
8578 /* Keep track of the number of spaces used to indent the
8579 output of the debugging routines that print the structure of
8580 the DIE internal representation. */
8581 static int print_indent
;
8583 /* Indent the line the number of spaces given by print_indent. */
8586 print_spaces (FILE *outfile
)
8588 fprintf (outfile
, "%*s", print_indent
, "");
8591 /* Print a type signature in hex. */
8594 print_signature (FILE *outfile
, char *sig
)
8598 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8599 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
8602 /* Print the information associated with a given DIE, and its children.
8603 This routine is a debugging aid only. */
8606 print_die (dw_die_ref die
, FILE *outfile
)
8612 print_spaces (outfile
);
8613 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
8614 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
8616 print_spaces (outfile
);
8617 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
8618 fprintf (outfile
, " offset: %ld", die
->die_offset
);
8619 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
8621 if (use_debug_types
&& die
->die_id
.die_type_node
)
8623 print_spaces (outfile
);
8624 fprintf (outfile
, " signature: ");
8625 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
8626 fprintf (outfile
, "\n");
8629 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
8631 print_spaces (outfile
);
8632 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
8634 switch (AT_class (a
))
8636 case dw_val_class_addr
:
8637 fprintf (outfile
, "address");
8639 case dw_val_class_offset
:
8640 fprintf (outfile
, "offset");
8642 case dw_val_class_loc
:
8643 fprintf (outfile
, "location descriptor");
8645 case dw_val_class_loc_list
:
8646 fprintf (outfile
, "location list -> label:%s",
8647 AT_loc_list (a
)->ll_symbol
);
8649 case dw_val_class_range_list
:
8650 fprintf (outfile
, "range list");
8652 case dw_val_class_const
:
8653 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
8655 case dw_val_class_unsigned_const
:
8656 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
8658 case dw_val_class_const_double
:
8659 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
8660 HOST_WIDE_INT_PRINT_UNSIGNED
")",
8661 a
->dw_attr_val
.v
.val_double
.high
,
8662 a
->dw_attr_val
.v
.val_double
.low
);
8664 case dw_val_class_vec
:
8665 fprintf (outfile
, "floating-point or vector constant");
8667 case dw_val_class_flag
:
8668 fprintf (outfile
, "%u", AT_flag (a
));
8670 case dw_val_class_die_ref
:
8671 if (AT_ref (a
) != NULL
)
8673 if (use_debug_types
&& AT_ref (a
)->die_id
.die_type_node
)
8675 fprintf (outfile
, "die -> signature: ");
8676 print_signature (outfile
,
8677 AT_ref (a
)->die_id
.die_type_node
->signature
);
8679 else if (! use_debug_types
&& AT_ref (a
)->die_id
.die_symbol
)
8680 fprintf (outfile
, "die -> label: %s",
8681 AT_ref (a
)->die_id
.die_symbol
);
8683 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
8684 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
8687 fprintf (outfile
, "die -> <null>");
8689 case dw_val_class_vms_delta
:
8690 fprintf (outfile
, "delta: @slotcount(%s-%s)",
8691 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
8693 case dw_val_class_lbl_id
:
8694 case dw_val_class_lineptr
:
8695 case dw_val_class_macptr
:
8696 fprintf (outfile
, "label: %s", AT_lbl (a
));
8698 case dw_val_class_str
:
8699 if (AT_string (a
) != NULL
)
8700 fprintf (outfile
, "\"%s\"", AT_string (a
));
8702 fprintf (outfile
, "<null>");
8704 case dw_val_class_file
:
8705 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
8706 AT_file (a
)->emitted_number
);
8708 case dw_val_class_data8
:
8712 for (i
= 0; i
< 8; i
++)
8713 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
8720 fprintf (outfile
, "\n");
8723 if (die
->die_child
!= NULL
)
8726 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
8729 if (print_indent
== 0)
8730 fprintf (outfile
, "\n");
8733 /* Print the information collected for a given DIE. */
8736 debug_dwarf_die (dw_die_ref die
)
8738 print_die (die
, stderr
);
8741 /* Print all DWARF information collected for the compilation unit.
8742 This routine is a debugging aid only. */
8748 print_die (comp_unit_die (), stderr
);
8751 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
8752 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
8753 DIE that marks the start of the DIEs for this include file. */
8756 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
8758 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
8759 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
8761 new_unit
->die_sib
= old_unit
;
8765 /* Close an include-file CU and reopen the enclosing one. */
8768 pop_compile_unit (dw_die_ref old_unit
)
8770 dw_die_ref new_unit
= old_unit
->die_sib
;
8772 old_unit
->die_sib
= NULL
;
8776 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8777 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
8779 /* Calculate the checksum of a location expression. */
8782 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
8786 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
8788 CHECKSUM (loc
->dw_loc_oprnd1
);
8789 CHECKSUM (loc
->dw_loc_oprnd2
);
8792 /* Calculate the checksum of an attribute. */
8795 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
8797 dw_loc_descr_ref loc
;
8800 CHECKSUM (at
->dw_attr
);
8802 /* We don't care that this was compiled with a different compiler
8803 snapshot; if the output is the same, that's what matters. */
8804 if (at
->dw_attr
== DW_AT_producer
)
8807 switch (AT_class (at
))
8809 case dw_val_class_const
:
8810 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
8812 case dw_val_class_unsigned_const
:
8813 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
8815 case dw_val_class_const_double
:
8816 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
8818 case dw_val_class_vec
:
8819 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
8821 case dw_val_class_flag
:
8822 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
8824 case dw_val_class_str
:
8825 CHECKSUM_STRING (AT_string (at
));
8828 case dw_val_class_addr
:
8830 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
8831 CHECKSUM_STRING (XSTR (r
, 0));
8834 case dw_val_class_offset
:
8835 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
8838 case dw_val_class_loc
:
8839 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
8840 loc_checksum (loc
, ctx
);
8843 case dw_val_class_die_ref
:
8844 die_checksum (AT_ref (at
), ctx
, mark
);
8847 case dw_val_class_fde_ref
:
8848 case dw_val_class_vms_delta
:
8849 case dw_val_class_lbl_id
:
8850 case dw_val_class_lineptr
:
8851 case dw_val_class_macptr
:
8854 case dw_val_class_file
:
8855 CHECKSUM_STRING (AT_file (at
)->filename
);
8858 case dw_val_class_data8
:
8859 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
8867 /* Calculate the checksum of a DIE. */
8870 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
8876 /* To avoid infinite recursion. */
8879 CHECKSUM (die
->die_mark
);
8882 die
->die_mark
= ++(*mark
);
8884 CHECKSUM (die
->die_tag
);
8886 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
8887 attr_checksum (a
, ctx
, mark
);
8889 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
8893 #undef CHECKSUM_STRING
8895 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
8896 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8897 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
8898 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
8899 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
8900 #define CHECKSUM_ATTR(FOO) \
8901 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
8903 /* Calculate the checksum of a number in signed LEB128 format. */
8906 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
8913 byte
= (value
& 0x7f);
8915 more
= !((value
== 0 && (byte
& 0x40) == 0)
8916 || (value
== -1 && (byte
& 0x40) != 0));
8925 /* Calculate the checksum of a number in unsigned LEB128 format. */
8928 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
8932 unsigned char byte
= (value
& 0x7f);
8935 /* More bytes to follow. */
8943 /* Checksum the context of the DIE. This adds the names of any
8944 surrounding namespaces or structures to the checksum. */
8947 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
8951 int tag
= die
->die_tag
;
8953 if (tag
!= DW_TAG_namespace
8954 && tag
!= DW_TAG_structure_type
8955 && tag
!= DW_TAG_class_type
)
8958 name
= get_AT_string (die
, DW_AT_name
);
8960 spec
= get_AT_ref (die
, DW_AT_specification
);
8964 if (die
->die_parent
!= NULL
)
8965 checksum_die_context (die
->die_parent
, ctx
);
8967 CHECKSUM_ULEB128 ('C');
8968 CHECKSUM_ULEB128 (tag
);
8970 CHECKSUM_STRING (name
);
8973 /* Calculate the checksum of a location expression. */
8976 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
8978 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
8979 were emitted as a DW_FORM_sdata instead of a location expression. */
8980 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
8982 CHECKSUM_ULEB128 (DW_FORM_sdata
);
8983 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
8987 /* Otherwise, just checksum the raw location expression. */
8990 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
8991 CHECKSUM (loc
->dw_loc_oprnd1
);
8992 CHECKSUM (loc
->dw_loc_oprnd2
);
8993 loc
= loc
->dw_loc_next
;
8997 /* Calculate the checksum of an attribute. */
9000 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
9001 struct md5_ctx
*ctx
, int *mark
)
9003 dw_loc_descr_ref loc
;
9006 if (AT_class (at
) == dw_val_class_die_ref
)
9008 dw_die_ref target_die
= AT_ref (at
);
9010 /* For pointer and reference types, we checksum only the (qualified)
9011 name of the target type (if there is a name). For friend entries,
9012 we checksum only the (qualified) name of the target type or function.
9013 This allows the checksum to remain the same whether the target type
9014 is complete or not. */
9015 if ((at
->dw_attr
== DW_AT_type
9016 && (tag
== DW_TAG_pointer_type
9017 || tag
== DW_TAG_reference_type
9018 || tag
== DW_TAG_rvalue_reference_type
9019 || tag
== DW_TAG_ptr_to_member_type
))
9020 || (at
->dw_attr
== DW_AT_friend
9021 && tag
== DW_TAG_friend
))
9023 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
9025 if (name_attr
!= NULL
)
9027 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
9031 CHECKSUM_ULEB128 ('N');
9032 CHECKSUM_ULEB128 (at
->dw_attr
);
9033 if (decl
->die_parent
!= NULL
)
9034 checksum_die_context (decl
->die_parent
, ctx
);
9035 CHECKSUM_ULEB128 ('E');
9036 CHECKSUM_STRING (AT_string (name_attr
));
9041 /* For all other references to another DIE, we check to see if the
9042 target DIE has already been visited. If it has, we emit a
9043 backward reference; if not, we descend recursively. */
9044 if (target_die
->die_mark
> 0)
9046 CHECKSUM_ULEB128 ('R');
9047 CHECKSUM_ULEB128 (at
->dw_attr
);
9048 CHECKSUM_ULEB128 (target_die
->die_mark
);
9052 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
9056 target_die
->die_mark
= ++(*mark
);
9057 CHECKSUM_ULEB128 ('T');
9058 CHECKSUM_ULEB128 (at
->dw_attr
);
9059 if (decl
->die_parent
!= NULL
)
9060 checksum_die_context (decl
->die_parent
, ctx
);
9061 die_checksum_ordered (target_die
, ctx
, mark
);
9066 CHECKSUM_ULEB128 ('A');
9067 CHECKSUM_ULEB128 (at
->dw_attr
);
9069 switch (AT_class (at
))
9071 case dw_val_class_const
:
9072 CHECKSUM_ULEB128 (DW_FORM_sdata
);
9073 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
9076 case dw_val_class_unsigned_const
:
9077 CHECKSUM_ULEB128 (DW_FORM_sdata
);
9078 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
9081 case dw_val_class_const_double
:
9082 CHECKSUM_ULEB128 (DW_FORM_block
);
9083 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
9084 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
9087 case dw_val_class_vec
:
9088 CHECKSUM_ULEB128 (DW_FORM_block
);
9089 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_vec
));
9090 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
9093 case dw_val_class_flag
:
9094 CHECKSUM_ULEB128 (DW_FORM_flag
);
9095 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
9098 case dw_val_class_str
:
9099 CHECKSUM_ULEB128 (DW_FORM_string
);
9100 CHECKSUM_STRING (AT_string (at
));
9103 case dw_val_class_addr
:
9105 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
9106 CHECKSUM_ULEB128 (DW_FORM_string
);
9107 CHECKSUM_STRING (XSTR (r
, 0));
9110 case dw_val_class_offset
:
9111 CHECKSUM_ULEB128 (DW_FORM_sdata
);
9112 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
9115 case dw_val_class_loc
:
9116 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
9117 loc_checksum_ordered (loc
, ctx
);
9120 case dw_val_class_fde_ref
:
9121 case dw_val_class_lbl_id
:
9122 case dw_val_class_lineptr
:
9123 case dw_val_class_macptr
:
9126 case dw_val_class_file
:
9127 CHECKSUM_ULEB128 (DW_FORM_string
);
9128 CHECKSUM_STRING (AT_file (at
)->filename
);
9131 case dw_val_class_data8
:
9132 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
9140 struct checksum_attributes
9142 dw_attr_ref at_name
;
9143 dw_attr_ref at_type
;
9144 dw_attr_ref at_friend
;
9145 dw_attr_ref at_accessibility
;
9146 dw_attr_ref at_address_class
;
9147 dw_attr_ref at_allocated
;
9148 dw_attr_ref at_artificial
;
9149 dw_attr_ref at_associated
;
9150 dw_attr_ref at_binary_scale
;
9151 dw_attr_ref at_bit_offset
;
9152 dw_attr_ref at_bit_size
;
9153 dw_attr_ref at_bit_stride
;
9154 dw_attr_ref at_byte_size
;
9155 dw_attr_ref at_byte_stride
;
9156 dw_attr_ref at_const_value
;
9157 dw_attr_ref at_containing_type
;
9158 dw_attr_ref at_count
;
9159 dw_attr_ref at_data_location
;
9160 dw_attr_ref at_data_member_location
;
9161 dw_attr_ref at_decimal_scale
;
9162 dw_attr_ref at_decimal_sign
;
9163 dw_attr_ref at_default_value
;
9164 dw_attr_ref at_digit_count
;
9165 dw_attr_ref at_discr
;
9166 dw_attr_ref at_discr_list
;
9167 dw_attr_ref at_discr_value
;
9168 dw_attr_ref at_encoding
;
9169 dw_attr_ref at_endianity
;
9170 dw_attr_ref at_explicit
;
9171 dw_attr_ref at_is_optional
;
9172 dw_attr_ref at_location
;
9173 dw_attr_ref at_lower_bound
;
9174 dw_attr_ref at_mutable
;
9175 dw_attr_ref at_ordering
;
9176 dw_attr_ref at_picture_string
;
9177 dw_attr_ref at_prototyped
;
9178 dw_attr_ref at_small
;
9179 dw_attr_ref at_segment
;
9180 dw_attr_ref at_string_length
;
9181 dw_attr_ref at_threads_scaled
;
9182 dw_attr_ref at_upper_bound
;
9183 dw_attr_ref at_use_location
;
9184 dw_attr_ref at_use_UTF8
;
9185 dw_attr_ref at_variable_parameter
;
9186 dw_attr_ref at_virtuality
;
9187 dw_attr_ref at_visibility
;
9188 dw_attr_ref at_vtable_elem_location
;
9191 /* Collect the attributes that we will want to use for the checksum. */
9194 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
9199 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
9210 attrs
->at_friend
= a
;
9212 case DW_AT_accessibility
:
9213 attrs
->at_accessibility
= a
;
9215 case DW_AT_address_class
:
9216 attrs
->at_address_class
= a
;
9218 case DW_AT_allocated
:
9219 attrs
->at_allocated
= a
;
9221 case DW_AT_artificial
:
9222 attrs
->at_artificial
= a
;
9224 case DW_AT_associated
:
9225 attrs
->at_associated
= a
;
9227 case DW_AT_binary_scale
:
9228 attrs
->at_binary_scale
= a
;
9230 case DW_AT_bit_offset
:
9231 attrs
->at_bit_offset
= a
;
9233 case DW_AT_bit_size
:
9234 attrs
->at_bit_size
= a
;
9236 case DW_AT_bit_stride
:
9237 attrs
->at_bit_stride
= a
;
9239 case DW_AT_byte_size
:
9240 attrs
->at_byte_size
= a
;
9242 case DW_AT_byte_stride
:
9243 attrs
->at_byte_stride
= a
;
9245 case DW_AT_const_value
:
9246 attrs
->at_const_value
= a
;
9248 case DW_AT_containing_type
:
9249 attrs
->at_containing_type
= a
;
9252 attrs
->at_count
= a
;
9254 case DW_AT_data_location
:
9255 attrs
->at_data_location
= a
;
9257 case DW_AT_data_member_location
:
9258 attrs
->at_data_member_location
= a
;
9260 case DW_AT_decimal_scale
:
9261 attrs
->at_decimal_scale
= a
;
9263 case DW_AT_decimal_sign
:
9264 attrs
->at_decimal_sign
= a
;
9266 case DW_AT_default_value
:
9267 attrs
->at_default_value
= a
;
9269 case DW_AT_digit_count
:
9270 attrs
->at_digit_count
= a
;
9273 attrs
->at_discr
= a
;
9275 case DW_AT_discr_list
:
9276 attrs
->at_discr_list
= a
;
9278 case DW_AT_discr_value
:
9279 attrs
->at_discr_value
= a
;
9281 case DW_AT_encoding
:
9282 attrs
->at_encoding
= a
;
9284 case DW_AT_endianity
:
9285 attrs
->at_endianity
= a
;
9287 case DW_AT_explicit
:
9288 attrs
->at_explicit
= a
;
9290 case DW_AT_is_optional
:
9291 attrs
->at_is_optional
= a
;
9293 case DW_AT_location
:
9294 attrs
->at_location
= a
;
9296 case DW_AT_lower_bound
:
9297 attrs
->at_lower_bound
= a
;
9300 attrs
->at_mutable
= a
;
9302 case DW_AT_ordering
:
9303 attrs
->at_ordering
= a
;
9305 case DW_AT_picture_string
:
9306 attrs
->at_picture_string
= a
;
9308 case DW_AT_prototyped
:
9309 attrs
->at_prototyped
= a
;
9312 attrs
->at_small
= a
;
9315 attrs
->at_segment
= a
;
9317 case DW_AT_string_length
:
9318 attrs
->at_string_length
= a
;
9320 case DW_AT_threads_scaled
:
9321 attrs
->at_threads_scaled
= a
;
9323 case DW_AT_upper_bound
:
9324 attrs
->at_upper_bound
= a
;
9326 case DW_AT_use_location
:
9327 attrs
->at_use_location
= a
;
9329 case DW_AT_use_UTF8
:
9330 attrs
->at_use_UTF8
= a
;
9332 case DW_AT_variable_parameter
:
9333 attrs
->at_variable_parameter
= a
;
9335 case DW_AT_virtuality
:
9336 attrs
->at_virtuality
= a
;
9338 case DW_AT_visibility
:
9339 attrs
->at_visibility
= a
;
9341 case DW_AT_vtable_elem_location
:
9342 attrs
->at_vtable_elem_location
= a
;
9350 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
9353 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
9357 struct checksum_attributes attrs
;
9359 CHECKSUM_ULEB128 ('D');
9360 CHECKSUM_ULEB128 (die
->die_tag
);
9362 memset (&attrs
, 0, sizeof (attrs
));
9364 decl
= get_AT_ref (die
, DW_AT_specification
);
9366 collect_checksum_attributes (&attrs
, decl
);
9367 collect_checksum_attributes (&attrs
, die
);
9369 CHECKSUM_ATTR (attrs
.at_name
);
9370 CHECKSUM_ATTR (attrs
.at_accessibility
);
9371 CHECKSUM_ATTR (attrs
.at_address_class
);
9372 CHECKSUM_ATTR (attrs
.at_allocated
);
9373 CHECKSUM_ATTR (attrs
.at_artificial
);
9374 CHECKSUM_ATTR (attrs
.at_associated
);
9375 CHECKSUM_ATTR (attrs
.at_binary_scale
);
9376 CHECKSUM_ATTR (attrs
.at_bit_offset
);
9377 CHECKSUM_ATTR (attrs
.at_bit_size
);
9378 CHECKSUM_ATTR (attrs
.at_bit_stride
);
9379 CHECKSUM_ATTR (attrs
.at_byte_size
);
9380 CHECKSUM_ATTR (attrs
.at_byte_stride
);
9381 CHECKSUM_ATTR (attrs
.at_const_value
);
9382 CHECKSUM_ATTR (attrs
.at_containing_type
);
9383 CHECKSUM_ATTR (attrs
.at_count
);
9384 CHECKSUM_ATTR (attrs
.at_data_location
);
9385 CHECKSUM_ATTR (attrs
.at_data_member_location
);
9386 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
9387 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
9388 CHECKSUM_ATTR (attrs
.at_default_value
);
9389 CHECKSUM_ATTR (attrs
.at_digit_count
);
9390 CHECKSUM_ATTR (attrs
.at_discr
);
9391 CHECKSUM_ATTR (attrs
.at_discr_list
);
9392 CHECKSUM_ATTR (attrs
.at_discr_value
);
9393 CHECKSUM_ATTR (attrs
.at_encoding
);
9394 CHECKSUM_ATTR (attrs
.at_endianity
);
9395 CHECKSUM_ATTR (attrs
.at_explicit
);
9396 CHECKSUM_ATTR (attrs
.at_is_optional
);
9397 CHECKSUM_ATTR (attrs
.at_location
);
9398 CHECKSUM_ATTR (attrs
.at_lower_bound
);
9399 CHECKSUM_ATTR (attrs
.at_mutable
);
9400 CHECKSUM_ATTR (attrs
.at_ordering
);
9401 CHECKSUM_ATTR (attrs
.at_picture_string
);
9402 CHECKSUM_ATTR (attrs
.at_prototyped
);
9403 CHECKSUM_ATTR (attrs
.at_small
);
9404 CHECKSUM_ATTR (attrs
.at_segment
);
9405 CHECKSUM_ATTR (attrs
.at_string_length
);
9406 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
9407 CHECKSUM_ATTR (attrs
.at_upper_bound
);
9408 CHECKSUM_ATTR (attrs
.at_use_location
);
9409 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
9410 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
9411 CHECKSUM_ATTR (attrs
.at_virtuality
);
9412 CHECKSUM_ATTR (attrs
.at_visibility
);
9413 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
9414 CHECKSUM_ATTR (attrs
.at_type
);
9415 CHECKSUM_ATTR (attrs
.at_friend
);
9417 /* Checksum the child DIEs, except for nested types and member functions. */
9420 dw_attr_ref name_attr
;
9423 name_attr
= get_AT (c
, DW_AT_name
);
9424 if ((is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
)
9425 && name_attr
!= NULL
)
9427 CHECKSUM_ULEB128 ('S');
9428 CHECKSUM_ULEB128 (c
->die_tag
);
9429 CHECKSUM_STRING (AT_string (name_attr
));
9433 /* Mark this DIE so it gets processed when unmarking. */
9434 if (c
->die_mark
== 0)
9436 die_checksum_ordered (c
, ctx
, mark
);
9438 } while (c
!= die
->die_child
);
9440 CHECKSUM_ULEB128 (0);
9444 #undef CHECKSUM_STRING
9445 #undef CHECKSUM_ATTR
9446 #undef CHECKSUM_LEB128
9447 #undef CHECKSUM_ULEB128
9449 /* Generate the type signature for DIE. This is computed by generating an
9450 MD5 checksum over the DIE's tag, its relevant attributes, and its
9451 children. Attributes that are references to other DIEs are processed
9452 by recursion, using the MARK field to prevent infinite recursion.
9453 If the DIE is nested inside a namespace or another type, we also
9454 need to include that context in the signature. The lower 64 bits
9455 of the resulting MD5 checksum comprise the signature. */
9458 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
9462 unsigned char checksum
[16];
9466 name
= get_AT_string (die
, DW_AT_name
);
9467 decl
= get_AT_ref (die
, DW_AT_specification
);
9469 /* First, compute a signature for just the type name (and its surrounding
9470 context, if any. This is stored in the type unit DIE for link-time
9471 ODR (one-definition rule) checking. */
9473 if (is_cxx() && name
!= NULL
)
9475 md5_init_ctx (&ctx
);
9477 /* Checksum the names of surrounding namespaces and structures. */
9478 if (decl
!= NULL
&& decl
->die_parent
!= NULL
)
9479 checksum_die_context (decl
->die_parent
, &ctx
);
9481 md5_process_bytes (&die
->die_tag
, sizeof (die
->die_tag
), &ctx
);
9482 md5_process_bytes (name
, strlen (name
) + 1, &ctx
);
9483 md5_finish_ctx (&ctx
, checksum
);
9485 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
9488 /* Next, compute the complete type signature. */
9490 md5_init_ctx (&ctx
);
9492 die
->die_mark
= mark
;
9494 /* Checksum the names of surrounding namespaces and structures. */
9495 if (decl
!= NULL
&& decl
->die_parent
!= NULL
)
9496 checksum_die_context (decl
->die_parent
, &ctx
);
9498 /* Checksum the DIE and its children. */
9499 die_checksum_ordered (die
, &ctx
, &mark
);
9500 unmark_all_dies (die
);
9501 md5_finish_ctx (&ctx
, checksum
);
9503 /* Store the signature in the type node and link the type DIE and the
9504 type node together. */
9505 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
9506 DWARF_TYPE_SIGNATURE_SIZE
);
9507 die
->die_id
.die_type_node
= type_node
;
9508 type_node
->type_die
= die
;
9510 /* If the DIE is a specification, link its declaration to the type node
9513 decl
->die_id
.die_type_node
= type_node
;
9516 /* Do the location expressions look same? */
9518 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
9520 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
9521 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
9522 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
9525 /* Do the values look the same? */
9527 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
9529 dw_loc_descr_ref loc1
, loc2
;
9532 if (v1
->val_class
!= v2
->val_class
)
9535 switch (v1
->val_class
)
9537 case dw_val_class_const
:
9538 return v1
->v
.val_int
== v2
->v
.val_int
;
9539 case dw_val_class_unsigned_const
:
9540 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
9541 case dw_val_class_const_double
:
9542 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
9543 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
9544 case dw_val_class_vec
:
9545 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
9546 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
9548 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
9549 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
9552 case dw_val_class_flag
:
9553 return v1
->v
.val_flag
== v2
->v
.val_flag
;
9554 case dw_val_class_str
:
9555 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
9557 case dw_val_class_addr
:
9558 r1
= v1
->v
.val_addr
;
9559 r2
= v2
->v
.val_addr
;
9560 if (GET_CODE (r1
) != GET_CODE (r2
))
9562 return !rtx_equal_p (r1
, r2
);
9564 case dw_val_class_offset
:
9565 return v1
->v
.val_offset
== v2
->v
.val_offset
;
9567 case dw_val_class_loc
:
9568 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
9570 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
9571 if (!same_loc_p (loc1
, loc2
, mark
))
9573 return !loc1
&& !loc2
;
9575 case dw_val_class_die_ref
:
9576 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
9578 case dw_val_class_fde_ref
:
9579 case dw_val_class_vms_delta
:
9580 case dw_val_class_lbl_id
:
9581 case dw_val_class_lineptr
:
9582 case dw_val_class_macptr
:
9585 case dw_val_class_file
:
9586 return v1
->v
.val_file
== v2
->v
.val_file
;
9588 case dw_val_class_data8
:
9589 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
9596 /* Do the attributes look the same? */
9599 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
9601 if (at1
->dw_attr
!= at2
->dw_attr
)
9604 /* We don't care that this was compiled with a different compiler
9605 snapshot; if the output is the same, that's what matters. */
9606 if (at1
->dw_attr
== DW_AT_producer
)
9609 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
9612 /* Do the dies look the same? */
9615 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
9621 /* To avoid infinite recursion. */
9623 return die1
->die_mark
== die2
->die_mark
;
9624 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
9626 if (die1
->die_tag
!= die2
->die_tag
)
9629 if (VEC_length (dw_attr_node
, die1
->die_attr
)
9630 != VEC_length (dw_attr_node
, die2
->die_attr
))
9633 FOR_EACH_VEC_ELT (dw_attr_node
, die1
->die_attr
, ix
, a1
)
9634 if (!same_attr_p (a1
, VEC_index (dw_attr_node
, die2
->die_attr
, ix
), mark
))
9637 c1
= die1
->die_child
;
9638 c2
= die2
->die_child
;
9647 if (!same_die_p (c1
, c2
, mark
))
9651 if (c1
== die1
->die_child
)
9653 if (c2
== die2
->die_child
)
9663 /* Do the dies look the same? Wrapper around same_die_p. */
9666 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
9669 int ret
= same_die_p (die1
, die2
, &mark
);
9671 unmark_all_dies (die1
);
9672 unmark_all_dies (die2
);
9677 /* The prefix to attach to symbols on DIEs in the current comdat debug
9679 static char *comdat_symbol_id
;
9681 /* The index of the current symbol within the current comdat CU. */
9682 static unsigned int comdat_symbol_number
;
9684 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
9685 children, and set comdat_symbol_id accordingly. */
9688 compute_section_prefix (dw_die_ref unit_die
)
9690 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
9691 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
9692 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
9695 unsigned char checksum
[16];
9698 /* Compute the checksum of the DIE, then append part of it as hex digits to
9699 the name filename of the unit. */
9701 md5_init_ctx (&ctx
);
9703 die_checksum (unit_die
, &ctx
, &mark
);
9704 unmark_all_dies (unit_die
);
9705 md5_finish_ctx (&ctx
, checksum
);
9707 sprintf (name
, "%s.", base
);
9708 clean_symbol_name (name
);
9710 p
= name
+ strlen (name
);
9711 for (i
= 0; i
< 4; i
++)
9713 sprintf (p
, "%.2x", checksum
[i
]);
9717 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
9718 comdat_symbol_number
= 0;
9721 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
9724 is_type_die (dw_die_ref die
)
9726 switch (die
->die_tag
)
9728 case DW_TAG_array_type
:
9729 case DW_TAG_class_type
:
9730 case DW_TAG_interface_type
:
9731 case DW_TAG_enumeration_type
:
9732 case DW_TAG_pointer_type
:
9733 case DW_TAG_reference_type
:
9734 case DW_TAG_rvalue_reference_type
:
9735 case DW_TAG_string_type
:
9736 case DW_TAG_structure_type
:
9737 case DW_TAG_subroutine_type
:
9738 case DW_TAG_union_type
:
9739 case DW_TAG_ptr_to_member_type
:
9740 case DW_TAG_set_type
:
9741 case DW_TAG_subrange_type
:
9742 case DW_TAG_base_type
:
9743 case DW_TAG_const_type
:
9744 case DW_TAG_file_type
:
9745 case DW_TAG_packed_type
:
9746 case DW_TAG_volatile_type
:
9747 case DW_TAG_typedef
:
9754 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
9755 Basically, we want to choose the bits that are likely to be shared between
9756 compilations (types) and leave out the bits that are specific to individual
9757 compilations (functions). */
9760 is_comdat_die (dw_die_ref c
)
9762 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
9763 we do for stabs. The advantage is a greater likelihood of sharing between
9764 objects that don't include headers in the same order (and therefore would
9765 put the base types in a different comdat). jason 8/28/00 */
9767 if (c
->die_tag
== DW_TAG_base_type
)
9770 if (c
->die_tag
== DW_TAG_pointer_type
9771 || c
->die_tag
== DW_TAG_reference_type
9772 || c
->die_tag
== DW_TAG_rvalue_reference_type
9773 || c
->die_tag
== DW_TAG_const_type
9774 || c
->die_tag
== DW_TAG_volatile_type
)
9776 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
9778 return t
? is_comdat_die (t
) : 0;
9781 return is_type_die (c
);
9784 /* Returns 1 iff C is the sort of DIE that might be referred to from another
9785 compilation unit. */
9788 is_symbol_die (dw_die_ref c
)
9790 return (is_type_die (c
)
9791 || is_declaration_die (c
)
9792 || c
->die_tag
== DW_TAG_namespace
9793 || c
->die_tag
== DW_TAG_module
);
9796 /* Returns true iff C is a compile-unit DIE. */
9799 is_cu_die (dw_die_ref c
)
9801 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
9805 gen_internal_sym (const char *prefix
)
9809 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
9810 return xstrdup (buf
);
9813 /* Assign symbols to all worthy DIEs under DIE. */
9816 assign_symbol_names (dw_die_ref die
)
9820 if (is_symbol_die (die
))
9822 if (comdat_symbol_id
)
9824 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
9826 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
9827 comdat_symbol_id
, comdat_symbol_number
++);
9828 die
->die_id
.die_symbol
= xstrdup (p
);
9831 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
9834 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
9837 struct cu_hash_table_entry
9840 unsigned min_comdat_num
, max_comdat_num
;
9841 struct cu_hash_table_entry
*next
;
9844 /* Routines to manipulate hash table of CUs. */
9846 htab_cu_hash (const void *of
)
9848 const struct cu_hash_table_entry
*const entry
=
9849 (const struct cu_hash_table_entry
*) of
;
9851 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
9855 htab_cu_eq (const void *of1
, const void *of2
)
9857 const struct cu_hash_table_entry
*const entry1
=
9858 (const struct cu_hash_table_entry
*) of1
;
9859 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
9861 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
9865 htab_cu_del (void *what
)
9867 struct cu_hash_table_entry
*next
,
9868 *entry
= (struct cu_hash_table_entry
*) what
;
9878 /* Check whether we have already seen this CU and set up SYM_NUM
9881 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
9883 struct cu_hash_table_entry dummy
;
9884 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
9886 dummy
.max_comdat_num
= 0;
9888 slot
= (struct cu_hash_table_entry
**)
9889 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
9893 for (; entry
; last
= entry
, entry
= entry
->next
)
9895 if (same_die_p_wrap (cu
, entry
->cu
))
9901 *sym_num
= entry
->min_comdat_num
;
9905 entry
= XCNEW (struct cu_hash_table_entry
);
9907 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
9908 entry
->next
= *slot
;
9914 /* Record SYM_NUM to record of CU in HTABLE. */
9916 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
9918 struct cu_hash_table_entry
**slot
, *entry
;
9920 slot
= (struct cu_hash_table_entry
**)
9921 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
9925 entry
->max_comdat_num
= sym_num
;
9928 /* Traverse the DIE (which is always comp_unit_die), and set up
9929 additional compilation units for each of the include files we see
9930 bracketed by BINCL/EINCL. */
9933 break_out_includes (dw_die_ref die
)
9936 dw_die_ref unit
= NULL
;
9937 limbo_die_node
*node
, **pnode
;
9938 htab_t cu_hash_table
;
9942 dw_die_ref prev
= c
;
9944 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
9945 || (unit
&& is_comdat_die (c
)))
9947 dw_die_ref next
= c
->die_sib
;
9949 /* This DIE is for a secondary CU; remove it from the main one. */
9950 remove_child_with_prev (c
, prev
);
9952 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
9953 unit
= push_new_compile_unit (unit
, c
);
9954 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
9955 unit
= pop_compile_unit (unit
);
9957 add_child_die (unit
, c
);
9959 if (c
== die
->die_child
)
9962 } while (c
!= die
->die_child
);
9965 /* We can only use this in debugging, since the frontend doesn't check
9966 to make sure that we leave every include file we enter. */
9970 assign_symbol_names (die
);
9971 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
9972 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
9978 compute_section_prefix (node
->die
);
9979 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
9980 &comdat_symbol_number
);
9981 assign_symbol_names (node
->die
);
9983 *pnode
= node
->next
;
9986 pnode
= &node
->next
;
9987 record_comdat_symbol_number (node
->die
, cu_hash_table
,
9988 comdat_symbol_number
);
9991 htab_delete (cu_hash_table
);
9994 /* Return non-zero if this DIE is a declaration. */
9997 is_declaration_die (dw_die_ref die
)
10002 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
10003 if (a
->dw_attr
== DW_AT_declaration
)
10009 /* Return non-zero if this DIE is nested inside a subprogram. */
10012 is_nested_in_subprogram (dw_die_ref die
)
10014 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
10018 return local_scope_p (decl
);
10021 /* Return non-zero if this is a type DIE that should be moved to a
10022 COMDAT .debug_types section. */
10025 should_move_die_to_comdat (dw_die_ref die
)
10027 switch (die
->die_tag
)
10029 case DW_TAG_class_type
:
10030 case DW_TAG_structure_type
:
10031 case DW_TAG_enumeration_type
:
10032 case DW_TAG_union_type
:
10033 /* Don't move declarations, inlined instances, or types nested in a
10035 if (is_declaration_die (die
)
10036 || get_AT (die
, DW_AT_abstract_origin
)
10037 || is_nested_in_subprogram (die
))
10040 case DW_TAG_array_type
:
10041 case DW_TAG_interface_type
:
10042 case DW_TAG_pointer_type
:
10043 case DW_TAG_reference_type
:
10044 case DW_TAG_rvalue_reference_type
:
10045 case DW_TAG_string_type
:
10046 case DW_TAG_subroutine_type
:
10047 case DW_TAG_ptr_to_member_type
:
10048 case DW_TAG_set_type
:
10049 case DW_TAG_subrange_type
:
10050 case DW_TAG_base_type
:
10051 case DW_TAG_const_type
:
10052 case DW_TAG_file_type
:
10053 case DW_TAG_packed_type
:
10054 case DW_TAG_volatile_type
:
10055 case DW_TAG_typedef
:
10061 /* Make a clone of DIE. */
10064 clone_die (dw_die_ref die
)
10070 clone
= ggc_alloc_cleared_die_node ();
10071 clone
->die_tag
= die
->die_tag
;
10073 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
10074 add_dwarf_attr (clone
, a
);
10079 /* Make a clone of the tree rooted at DIE. */
10082 clone_tree (dw_die_ref die
)
10085 dw_die_ref clone
= clone_die (die
);
10087 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree(c
)));
10092 /* Make a clone of DIE as a declaration. */
10095 clone_as_declaration (dw_die_ref die
)
10102 /* If the DIE is already a declaration, just clone it. */
10103 if (is_declaration_die (die
))
10104 return clone_die (die
);
10106 /* If the DIE is a specification, just clone its declaration DIE. */
10107 decl
= get_AT_ref (die
, DW_AT_specification
);
10109 return clone_die (decl
);
10111 clone
= ggc_alloc_cleared_die_node ();
10112 clone
->die_tag
= die
->die_tag
;
10114 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
10116 /* We don't want to copy over all attributes.
10117 For example we don't want DW_AT_byte_size because otherwise we will no
10118 longer have a declaration and GDB will treat it as a definition. */
10120 switch (a
->dw_attr
)
10122 case DW_AT_artificial
:
10123 case DW_AT_containing_type
:
10124 case DW_AT_external
:
10127 case DW_AT_virtuality
:
10128 case DW_AT_linkage_name
:
10129 case DW_AT_MIPS_linkage_name
:
10130 add_dwarf_attr (clone
, a
);
10132 case DW_AT_byte_size
:
10138 if (die
->die_id
.die_type_node
)
10139 add_AT_die_ref (clone
, DW_AT_signature
, die
);
10141 add_AT_flag (clone
, DW_AT_declaration
, 1);
10145 /* Copy the declaration context to the new compile unit DIE. This includes
10146 any surrounding namespace or type declarations. If the DIE has an
10147 AT_specification attribute, it also includes attributes and children
10148 attached to the specification. */
10151 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
10154 dw_die_ref new_decl
;
10156 decl
= get_AT_ref (die
, DW_AT_specification
);
10165 /* Copy the type node pointer from the new DIE to the original
10166 declaration DIE so we can forward references later. */
10167 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
10169 remove_AT (die
, DW_AT_specification
);
10171 FOR_EACH_VEC_ELT (dw_attr_node
, decl
->die_attr
, ix
, a
)
10173 if (a
->dw_attr
!= DW_AT_name
10174 && a
->dw_attr
!= DW_AT_declaration
10175 && a
->dw_attr
!= DW_AT_external
)
10176 add_dwarf_attr (die
, a
);
10179 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree(c
)));
10182 if (decl
->die_parent
!= NULL
10183 && decl
->die_parent
->die_tag
!= DW_TAG_compile_unit
10184 && decl
->die_parent
->die_tag
!= DW_TAG_type_unit
)
10186 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
10187 if (new_decl
!= NULL
)
10189 remove_AT (new_decl
, DW_AT_signature
);
10190 add_AT_specification (die
, new_decl
);
10195 /* Generate the skeleton ancestor tree for the given NODE, then clone
10196 the DIE and add the clone into the tree. */
10199 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
10201 if (node
->new_die
!= NULL
)
10204 node
->new_die
= clone_as_declaration (node
->old_die
);
10206 if (node
->parent
!= NULL
)
10208 generate_skeleton_ancestor_tree (node
->parent
);
10209 add_child_die (node
->parent
->new_die
, node
->new_die
);
10213 /* Generate a skeleton tree of DIEs containing any declarations that are
10214 found in the original tree. We traverse the tree looking for declaration
10215 DIEs, and construct the skeleton from the bottom up whenever we find one. */
10218 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
10220 skeleton_chain_node node
;
10223 dw_die_ref prev
= NULL
;
10224 dw_die_ref next
= NULL
;
10226 node
.parent
= parent
;
10228 first
= c
= parent
->old_die
->die_child
;
10232 if (prev
== NULL
|| prev
->die_sib
== c
)
10235 next
= (c
== first
? NULL
: c
->die_sib
);
10237 node
.new_die
= NULL
;
10238 if (is_declaration_die (c
))
10240 /* Clone the existing DIE, move the original to the skeleton
10241 tree (which is in the main CU), and put the clone, with
10242 all the original's children, where the original came from. */
10243 dw_die_ref clone
= clone_die (c
);
10244 move_all_children (c
, clone
);
10246 replace_child (c
, clone
, prev
);
10247 generate_skeleton_ancestor_tree (parent
);
10248 add_child_die (parent
->new_die
, c
);
10252 generate_skeleton_bottom_up (&node
);
10253 } while (next
!= NULL
);
10256 /* Wrapper function for generate_skeleton_bottom_up. */
10259 generate_skeleton (dw_die_ref die
)
10261 skeleton_chain_node node
;
10263 node
.old_die
= die
;
10264 node
.new_die
= NULL
;
10265 node
.parent
= NULL
;
10267 /* If this type definition is nested inside another type,
10268 always leave at least a declaration in its place. */
10269 if (die
->die_parent
!= NULL
&& is_type_die (die
->die_parent
))
10270 node
.new_die
= clone_as_declaration (die
);
10272 generate_skeleton_bottom_up (&node
);
10273 return node
.new_die
;
10276 /* Remove the DIE from its parent, possibly replacing it with a cloned
10277 declaration. The original DIE will be moved to a new compile unit
10278 so that existing references to it follow it to the new location. If
10279 any of the original DIE's descendants is a declaration, we need to
10280 replace the original DIE with a skeleton tree and move the
10281 declarations back into the skeleton tree. */
10284 remove_child_or_replace_with_skeleton (dw_die_ref child
, dw_die_ref prev
)
10286 dw_die_ref skeleton
;
10288 skeleton
= generate_skeleton (child
);
10289 if (skeleton
== NULL
)
10290 remove_child_with_prev (child
, prev
);
10293 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
10294 replace_child (child
, skeleton
, prev
);
10300 /* Traverse the DIE and set up additional .debug_types sections for each
10301 type worthy of being placed in a COMDAT section. */
10304 break_out_comdat_types (dw_die_ref die
)
10308 dw_die_ref prev
= NULL
;
10309 dw_die_ref next
= NULL
;
10310 dw_die_ref unit
= NULL
;
10312 first
= c
= die
->die_child
;
10316 if (prev
== NULL
|| prev
->die_sib
== c
)
10319 next
= (c
== first
? NULL
: c
->die_sib
);
10320 if (should_move_die_to_comdat (c
))
10322 dw_die_ref replacement
;
10323 comdat_type_node_ref type_node
;
10325 /* Create a new type unit DIE as the root for the new tree, and
10326 add it to the list of comdat types. */
10327 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
10328 add_AT_unsigned (unit
, DW_AT_language
,
10329 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
10330 type_node
= ggc_alloc_cleared_comdat_type_node ();
10331 type_node
->root_die
= unit
;
10332 type_node
->next
= comdat_type_list
;
10333 comdat_type_list
= type_node
;
10335 /* Generate the type signature. */
10336 generate_type_signature (c
, type_node
);
10338 /* Copy the declaration context, attributes, and children of the
10339 declaration into the new compile unit DIE. */
10340 copy_declaration_context (unit
, c
);
10342 /* Remove this DIE from the main CU. */
10343 replacement
= remove_child_or_replace_with_skeleton (c
, prev
);
10345 /* Break out nested types into their own type units. */
10346 break_out_comdat_types (c
);
10348 /* Add the DIE to the new compunit. */
10349 add_child_die (unit
, c
);
10351 if (replacement
!= NULL
)
10354 else if (c
->die_tag
== DW_TAG_namespace
10355 || c
->die_tag
== DW_TAG_class_type
10356 || c
->die_tag
== DW_TAG_structure_type
10357 || c
->die_tag
== DW_TAG_union_type
)
10359 /* Look for nested types that can be broken out. */
10360 break_out_comdat_types (c
);
10362 } while (next
!= NULL
);
10365 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
10367 struct decl_table_entry
10373 /* Routines to manipulate hash table of copied declarations. */
10376 htab_decl_hash (const void *of
)
10378 const struct decl_table_entry
*const entry
=
10379 (const struct decl_table_entry
*) of
;
10381 return htab_hash_pointer (entry
->orig
);
10385 htab_decl_eq (const void *of1
, const void *of2
)
10387 const struct decl_table_entry
*const entry1
=
10388 (const struct decl_table_entry
*) of1
;
10389 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
10391 return entry1
->orig
== entry2
;
10395 htab_decl_del (void *what
)
10397 struct decl_table_entry
*entry
= (struct decl_table_entry
*) what
;
10402 /* Copy DIE and its ancestors, up to, but not including, the compile unit
10403 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
10404 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
10405 to check if the ancestor has already been copied into UNIT. */
10408 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
10410 dw_die_ref parent
= die
->die_parent
;
10411 dw_die_ref new_parent
= unit
;
10413 void **slot
= NULL
;
10414 struct decl_table_entry
*entry
= NULL
;
10418 /* Check if the entry has already been copied to UNIT. */
10419 slot
= htab_find_slot_with_hash (decl_table
, die
,
10420 htab_hash_pointer (die
), INSERT
);
10421 if (*slot
!= HTAB_EMPTY_ENTRY
)
10423 entry
= (struct decl_table_entry
*) *slot
;
10424 return entry
->copy
;
10427 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
10428 entry
= XCNEW (struct decl_table_entry
);
10430 entry
->copy
= NULL
;
10434 if (parent
!= NULL
)
10436 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
10439 if (parent
->die_tag
!= DW_TAG_compile_unit
10440 && parent
->die_tag
!= DW_TAG_type_unit
)
10441 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
10444 copy
= clone_as_declaration (die
);
10445 add_child_die (new_parent
, copy
);
10447 if (decl_table
!= NULL
)
10449 /* Record the pointer to the copy. */
10450 entry
->copy
= copy
;
10456 /* Walk the DIE and its children, looking for references to incomplete
10457 or trivial types that are unmarked (i.e., that are not in the current
10461 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
10467 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
10469 if (AT_class (a
) == dw_val_class_die_ref
)
10471 dw_die_ref targ
= AT_ref (a
);
10472 comdat_type_node_ref type_node
= targ
->die_id
.die_type_node
;
10474 struct decl_table_entry
*entry
;
10476 if (targ
->die_mark
!= 0 || type_node
!= NULL
)
10479 slot
= htab_find_slot_with_hash (decl_table
, targ
,
10480 htab_hash_pointer (targ
), INSERT
);
10482 if (*slot
!= HTAB_EMPTY_ENTRY
)
10484 /* TARG has already been copied, so we just need to
10485 modify the reference to point to the copy. */
10486 entry
= (struct decl_table_entry
*) *slot
;
10487 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
10491 dw_die_ref parent
= unit
;
10492 dw_die_ref copy
= clone_tree (targ
);
10494 /* Make sure the cloned tree is marked as part of the
10498 /* Record in DECL_TABLE that TARG has been copied.
10499 Need to do this now, before the recursive call,
10500 because DECL_TABLE may be expanded and SLOT
10501 would no longer be a valid pointer. */
10502 entry
= XCNEW (struct decl_table_entry
);
10503 entry
->orig
= targ
;
10504 entry
->copy
= copy
;
10507 /* If TARG has surrounding context, copy its ancestor tree
10508 into the new type unit. */
10509 if (targ
->die_parent
!= NULL
10510 && targ
->die_parent
->die_tag
!= DW_TAG_compile_unit
10511 && targ
->die_parent
->die_tag
!= DW_TAG_type_unit
)
10512 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
10515 add_child_die (parent
, copy
);
10516 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
10518 /* Make sure the newly-copied DIE is walked. If it was
10519 installed in a previously-added context, it won't
10520 get visited otherwise. */
10521 if (parent
!= unit
)
10523 /* Find the highest point of the newly-added tree,
10524 mark each node along the way, and walk from there. */
10525 parent
->die_mark
= 1;
10526 while (parent
->die_parent
10527 && parent
->die_parent
->die_mark
== 0)
10529 parent
= parent
->die_parent
;
10530 parent
->die_mark
= 1;
10532 copy_decls_walk (unit
, parent
, decl_table
);
10538 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
10541 /* Copy declarations for "unworthy" types into the new comdat section.
10542 Incomplete types, modified types, and certain other types aren't broken
10543 out into comdat sections of their own, so they don't have a signature,
10544 and we need to copy the declaration into the same section so that we
10545 don't have an external reference. */
10548 copy_decls_for_unworthy_types (dw_die_ref unit
)
10553 decl_table
= htab_create (10, htab_decl_hash
, htab_decl_eq
, htab_decl_del
);
10554 copy_decls_walk (unit
, unit
, decl_table
);
10555 htab_delete (decl_table
);
10556 unmark_dies (unit
);
10559 /* Traverse the DIE and add a sibling attribute if it may have the
10560 effect of speeding up access to siblings. To save some space,
10561 avoid generating sibling attributes for DIE's without children. */
10564 add_sibling_attributes (dw_die_ref die
)
10568 if (! die
->die_child
)
10571 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
10572 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
10574 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
10577 /* Output all location lists for the DIE and its children. */
10580 output_location_lists (dw_die_ref die
)
10586 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
10587 if (AT_class (a
) == dw_val_class_loc_list
)
10588 output_loc_list (AT_loc_list (a
));
10590 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
10593 /* The format of each DIE (and its attribute value pairs) is encoded in an
10594 abbreviation table. This routine builds the abbreviation table and assigns
10595 a unique abbreviation id for each abbreviation entry. The children of each
10596 die are visited recursively. */
10599 build_abbrev_table (dw_die_ref die
)
10601 unsigned long abbrev_id
;
10602 unsigned int n_alloc
;
10607 /* Scan the DIE references, and mark as external any that refer to
10608 DIEs from other CUs (i.e. those which are not marked). */
10609 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
10610 if (AT_class (a
) == dw_val_class_die_ref
10611 && AT_ref (a
)->die_mark
== 0)
10613 gcc_assert (use_debug_types
|| AT_ref (a
)->die_id
.die_symbol
);
10614 set_AT_ref_external (a
, 1);
10617 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
10619 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
10620 dw_attr_ref die_a
, abbrev_a
;
10624 if (abbrev
->die_tag
!= die
->die_tag
)
10626 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
10629 if (VEC_length (dw_attr_node
, abbrev
->die_attr
)
10630 != VEC_length (dw_attr_node
, die
->die_attr
))
10633 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, die_a
)
10635 abbrev_a
= VEC_index (dw_attr_node
, abbrev
->die_attr
, ix
);
10636 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
10637 || (value_format (abbrev_a
) != value_format (die_a
)))
10647 if (abbrev_id
>= abbrev_die_table_in_use
)
10649 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
10651 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
10652 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
10655 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
10656 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
10657 abbrev_die_table_allocated
= n_alloc
;
10660 ++abbrev_die_table_in_use
;
10661 abbrev_die_table
[abbrev_id
] = die
;
10664 die
->die_abbrev
= abbrev_id
;
10665 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
));
10668 /* Return the power-of-two number of bytes necessary to represent VALUE. */
10671 constant_size (unsigned HOST_WIDE_INT value
)
10678 log
= floor_log2 (value
);
10681 log
= 1 << (floor_log2 (log
) + 1);
10686 /* Return the size of a DIE as it is represented in the
10687 .debug_info section. */
10689 static unsigned long
10690 size_of_die (dw_die_ref die
)
10692 unsigned long size
= 0;
10696 size
+= size_of_uleb128 (die
->die_abbrev
);
10697 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
10699 switch (AT_class (a
))
10701 case dw_val_class_addr
:
10702 size
+= DWARF2_ADDR_SIZE
;
10704 case dw_val_class_offset
:
10705 size
+= DWARF_OFFSET_SIZE
;
10707 case dw_val_class_loc
:
10709 unsigned long lsize
= size_of_locs (AT_loc (a
));
10711 /* Block length. */
10712 if (dwarf_version
>= 4)
10713 size
+= size_of_uleb128 (lsize
);
10715 size
+= constant_size (lsize
);
10719 case dw_val_class_loc_list
:
10720 size
+= DWARF_OFFSET_SIZE
;
10722 case dw_val_class_range_list
:
10723 size
+= DWARF_OFFSET_SIZE
;
10725 case dw_val_class_const
:
10726 size
+= size_of_sleb128 (AT_int (a
));
10728 case dw_val_class_unsigned_const
:
10729 size
+= constant_size (AT_unsigned (a
));
10731 case dw_val_class_const_double
:
10732 size
+= 2 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
10733 if (HOST_BITS_PER_WIDE_INT
>= 64)
10734 size
++; /* block */
10736 case dw_val_class_vec
:
10737 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
10738 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
10739 + a
->dw_attr_val
.v
.val_vec
.length
10740 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
10742 case dw_val_class_flag
:
10743 if (dwarf_version
>= 4)
10744 /* Currently all add_AT_flag calls pass in 1 as last argument,
10745 so DW_FORM_flag_present can be used. If that ever changes,
10746 we'll need to use DW_FORM_flag and have some optimization
10747 in build_abbrev_table that will change those to
10748 DW_FORM_flag_present if it is set to 1 in all DIEs using
10749 the same abbrev entry. */
10750 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
10754 case dw_val_class_die_ref
:
10755 if (AT_ref_external (a
))
10757 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
10758 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
10759 is sized by target address length, whereas in DWARF3
10760 it's always sized as an offset. */
10761 if (use_debug_types
)
10762 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
10763 else if (dwarf_version
== 2)
10764 size
+= DWARF2_ADDR_SIZE
;
10766 size
+= DWARF_OFFSET_SIZE
;
10769 size
+= DWARF_OFFSET_SIZE
;
10771 case dw_val_class_fde_ref
:
10772 size
+= DWARF_OFFSET_SIZE
;
10774 case dw_val_class_lbl_id
:
10775 size
+= DWARF2_ADDR_SIZE
;
10777 case dw_val_class_lineptr
:
10778 case dw_val_class_macptr
:
10779 size
+= DWARF_OFFSET_SIZE
;
10781 case dw_val_class_str
:
10782 if (AT_string_form (a
) == DW_FORM_strp
)
10783 size
+= DWARF_OFFSET_SIZE
;
10785 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
10787 case dw_val_class_file
:
10788 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
10790 case dw_val_class_data8
:
10793 case dw_val_class_vms_delta
:
10794 size
+= DWARF_OFFSET_SIZE
;
10797 gcc_unreachable ();
10804 /* Size the debugging information associated with a given DIE. Visits the
10805 DIE's children recursively. Updates the global variable next_die_offset, on
10806 each time through. Uses the current value of next_die_offset to update the
10807 die_offset field in each DIE. */
10810 calc_die_sizes (dw_die_ref die
)
10814 die
->die_offset
= next_die_offset
;
10815 next_die_offset
+= size_of_die (die
);
10817 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
10819 if (die
->die_child
!= NULL
)
10820 /* Count the null byte used to terminate sibling lists. */
10821 next_die_offset
+= 1;
10824 /* Set the marks for a die and its children. We do this so
10825 that we know whether or not a reference needs to use FORM_ref_addr; only
10826 DIEs in the same CU will be marked. We used to clear out the offset
10827 and use that as the flag, but ran into ordering problems. */
10830 mark_dies (dw_die_ref die
)
10834 gcc_assert (!die
->die_mark
);
10837 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
10840 /* Clear the marks for a die and its children. */
10843 unmark_dies (dw_die_ref die
)
10847 if (! use_debug_types
)
10848 gcc_assert (die
->die_mark
);
10851 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
10854 /* Clear the marks for a die, its children and referred dies. */
10857 unmark_all_dies (dw_die_ref die
)
10863 if (!die
->die_mark
)
10867 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
10869 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
10870 if (AT_class (a
) == dw_val_class_die_ref
)
10871 unmark_all_dies (AT_ref (a
));
10874 /* Return the size of the .debug_pubnames or .debug_pubtypes table
10875 generated for the compilation unit. */
10877 static unsigned long
10878 size_of_pubnames (VEC (pubname_entry
, gc
) * names
)
10880 unsigned long size
;
10884 size
= DWARF_PUBNAMES_HEADER_SIZE
;
10885 FOR_EACH_VEC_ELT (pubname_entry
, names
, i
, p
)
10886 if (names
!= pubtype_table
10887 || p
->die
->die_offset
!= 0
10888 || !flag_eliminate_unused_debug_types
)
10889 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
10891 size
+= DWARF_OFFSET_SIZE
;
10895 /* Return the size of the information in the .debug_aranges section. */
10897 static unsigned long
10898 size_of_aranges (void)
10900 unsigned long size
;
10902 size
= DWARF_ARANGES_HEADER_SIZE
;
10904 /* Count the address/length pair for this compilation unit. */
10905 if (text_section_used
)
10906 size
+= 2 * DWARF2_ADDR_SIZE
;
10907 if (cold_text_section_used
)
10908 size
+= 2 * DWARF2_ADDR_SIZE
;
10909 if (have_multiple_function_sections
)
10911 unsigned fde_idx
= 0;
10913 for (fde_idx
= 0; fde_idx
< fde_table_in_use
; fde_idx
++)
10915 dw_fde_ref fde
= &fde_table
[fde_idx
];
10917 if (!fde
->in_std_section
)
10918 size
+= 2 * DWARF2_ADDR_SIZE
;
10919 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
10920 size
+= 2 * DWARF2_ADDR_SIZE
;
10924 /* Count the two zero words used to terminated the address range table. */
10925 size
+= 2 * DWARF2_ADDR_SIZE
;
10929 /* Select the encoding of an attribute value. */
10931 static enum dwarf_form
10932 value_format (dw_attr_ref a
)
10934 switch (a
->dw_attr_val
.val_class
)
10936 case dw_val_class_addr
:
10937 /* Only very few attributes allow DW_FORM_addr. */
10938 switch (a
->dw_attr
)
10941 case DW_AT_high_pc
:
10942 case DW_AT_entry_pc
:
10943 case DW_AT_trampoline
:
10944 return DW_FORM_addr
;
10948 switch (DWARF2_ADDR_SIZE
)
10951 return DW_FORM_data1
;
10953 return DW_FORM_data2
;
10955 return DW_FORM_data4
;
10957 return DW_FORM_data8
;
10959 gcc_unreachable ();
10961 case dw_val_class_range_list
:
10962 case dw_val_class_loc_list
:
10963 if (dwarf_version
>= 4)
10964 return DW_FORM_sec_offset
;
10966 case dw_val_class_vms_delta
:
10967 case dw_val_class_offset
:
10968 switch (DWARF_OFFSET_SIZE
)
10971 return DW_FORM_data4
;
10973 return DW_FORM_data8
;
10975 gcc_unreachable ();
10977 case dw_val_class_loc
:
10978 if (dwarf_version
>= 4)
10979 return DW_FORM_exprloc
;
10980 switch (constant_size (size_of_locs (AT_loc (a
))))
10983 return DW_FORM_block1
;
10985 return DW_FORM_block2
;
10987 gcc_unreachable ();
10989 case dw_val_class_const
:
10990 return DW_FORM_sdata
;
10991 case dw_val_class_unsigned_const
:
10992 switch (constant_size (AT_unsigned (a
)))
10995 return DW_FORM_data1
;
10997 return DW_FORM_data2
;
10999 return DW_FORM_data4
;
11001 return DW_FORM_data8
;
11003 gcc_unreachable ();
11005 case dw_val_class_const_double
:
11006 switch (HOST_BITS_PER_WIDE_INT
)
11009 return DW_FORM_data2
;
11011 return DW_FORM_data4
;
11013 return DW_FORM_data8
;
11016 return DW_FORM_block1
;
11018 case dw_val_class_vec
:
11019 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
11020 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
11023 return DW_FORM_block1
;
11025 return DW_FORM_block2
;
11027 return DW_FORM_block4
;
11029 gcc_unreachable ();
11031 case dw_val_class_flag
:
11032 if (dwarf_version
>= 4)
11034 /* Currently all add_AT_flag calls pass in 1 as last argument,
11035 so DW_FORM_flag_present can be used. If that ever changes,
11036 we'll need to use DW_FORM_flag and have some optimization
11037 in build_abbrev_table that will change those to
11038 DW_FORM_flag_present if it is set to 1 in all DIEs using
11039 the same abbrev entry. */
11040 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
11041 return DW_FORM_flag_present
;
11043 return DW_FORM_flag
;
11044 case dw_val_class_die_ref
:
11045 if (AT_ref_external (a
))
11046 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
11048 return DW_FORM_ref
;
11049 case dw_val_class_fde_ref
:
11050 return DW_FORM_data
;
11051 case dw_val_class_lbl_id
:
11052 return DW_FORM_addr
;
11053 case dw_val_class_lineptr
:
11054 case dw_val_class_macptr
:
11055 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
11056 case dw_val_class_str
:
11057 return AT_string_form (a
);
11058 case dw_val_class_file
:
11059 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
11062 return DW_FORM_data1
;
11064 return DW_FORM_data2
;
11066 return DW_FORM_data4
;
11068 gcc_unreachable ();
11071 case dw_val_class_data8
:
11072 return DW_FORM_data8
;
11075 gcc_unreachable ();
11079 /* Output the encoding of an attribute value. */
11082 output_value_format (dw_attr_ref a
)
11084 enum dwarf_form form
= value_format (a
);
11086 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
11089 /* Output the .debug_abbrev section which defines the DIE abbreviation
11093 output_abbrev_section (void)
11095 unsigned long abbrev_id
;
11097 if (abbrev_die_table_in_use
== 1)
11100 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
11102 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
11104 dw_attr_ref a_attr
;
11106 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
11107 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
11108 dwarf_tag_name (abbrev
->die_tag
));
11110 if (abbrev
->die_child
!= NULL
)
11111 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
11113 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
11115 for (ix
= 0; VEC_iterate (dw_attr_node
, abbrev
->die_attr
, ix
, a_attr
);
11118 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
11119 dwarf_attr_name (a_attr
->dw_attr
));
11120 output_value_format (a_attr
);
11123 dw2_asm_output_data (1, 0, NULL
);
11124 dw2_asm_output_data (1, 0, NULL
);
11127 /* Terminate the table. */
11128 dw2_asm_output_data (1, 0, NULL
);
11131 /* Output a symbol we can use to refer to this DIE from another CU. */
11134 output_die_symbol (dw_die_ref die
)
11136 char *sym
= die
->die_id
.die_symbol
;
11141 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
11142 /* We make these global, not weak; if the target doesn't support
11143 .linkonce, it doesn't support combining the sections, so debugging
11145 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
11147 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
11150 /* Return a new location list, given the begin and end range, and the
11153 static inline dw_loc_list_ref
11154 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
11155 const char *section
)
11157 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
11159 retlist
->begin
= begin
;
11160 retlist
->end
= end
;
11161 retlist
->expr
= expr
;
11162 retlist
->section
= section
;
11167 /* Generate a new internal symbol for this location list node, if it
11168 hasn't got one yet. */
11171 gen_llsym (dw_loc_list_ref list
)
11173 gcc_assert (!list
->ll_symbol
);
11174 list
->ll_symbol
= gen_internal_sym ("LLST");
11177 /* Output the location list given to us. */
11180 output_loc_list (dw_loc_list_ref list_head
)
11182 dw_loc_list_ref curr
= list_head
;
11184 if (list_head
->emitted
)
11186 list_head
->emitted
= true;
11188 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
11190 /* Walk the location list, and output each range + expression. */
11191 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
11193 unsigned long size
;
11194 /* Don't output an entry that starts and ends at the same address. */
11195 if (strcmp (curr
->begin
, curr
->end
) == 0)
11197 if (!have_multiple_function_sections
)
11199 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
11200 "Location list begin address (%s)",
11201 list_head
->ll_symbol
);
11202 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
11203 "Location list end address (%s)",
11204 list_head
->ll_symbol
);
11208 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
11209 "Location list begin address (%s)",
11210 list_head
->ll_symbol
);
11211 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
11212 "Location list end address (%s)",
11213 list_head
->ll_symbol
);
11215 size
= size_of_locs (curr
->expr
);
11217 /* Output the block length for this list of location operations. */
11218 gcc_assert (size
<= 0xffff);
11219 dw2_asm_output_data (2, size
, "%s", "Location expression size");
11221 output_loc_sequence (curr
->expr
, -1);
11224 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
11225 "Location list terminator begin (%s)",
11226 list_head
->ll_symbol
);
11227 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
11228 "Location list terminator end (%s)",
11229 list_head
->ll_symbol
);
11232 /* Output a type signature. */
11235 output_signature (const char *sig
, const char *name
)
11239 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
11240 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
11243 /* Output the DIE and its attributes. Called recursively to generate
11244 the definitions of each child DIE. */
11247 output_die (dw_die_ref die
)
11251 unsigned long size
;
11254 /* If someone in another CU might refer to us, set up a symbol for
11255 them to point to. */
11256 if (! use_debug_types
&& die
->die_id
.die_symbol
)
11257 output_die_symbol (die
);
11259 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
11260 (unsigned long)die
->die_offset
,
11261 dwarf_tag_name (die
->die_tag
));
11263 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
11265 const char *name
= dwarf_attr_name (a
->dw_attr
);
11267 switch (AT_class (a
))
11269 case dw_val_class_addr
:
11270 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
11273 case dw_val_class_offset
:
11274 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
11278 case dw_val_class_range_list
:
11280 char *p
= strchr (ranges_section_label
, '\0');
11282 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
11283 a
->dw_attr_val
.v
.val_offset
);
11284 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
11285 debug_ranges_section
, "%s", name
);
11290 case dw_val_class_loc
:
11291 size
= size_of_locs (AT_loc (a
));
11293 /* Output the block length for this list of location operations. */
11294 if (dwarf_version
>= 4)
11295 dw2_asm_output_data_uleb128 (size
, "%s", name
);
11297 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
11299 output_loc_sequence (AT_loc (a
), -1);
11302 case dw_val_class_const
:
11303 /* ??? It would be slightly more efficient to use a scheme like is
11304 used for unsigned constants below, but gdb 4.x does not sign
11305 extend. Gdb 5.x does sign extend. */
11306 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
11309 case dw_val_class_unsigned_const
:
11310 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
11311 AT_unsigned (a
), "%s", name
);
11314 case dw_val_class_const_double
:
11316 unsigned HOST_WIDE_INT first
, second
;
11318 if (HOST_BITS_PER_WIDE_INT
>= 64)
11319 dw2_asm_output_data (1,
11320 2 * HOST_BITS_PER_WIDE_INT
11321 / HOST_BITS_PER_CHAR
,
11324 if (WORDS_BIG_ENDIAN
)
11326 first
= a
->dw_attr_val
.v
.val_double
.high
;
11327 second
= a
->dw_attr_val
.v
.val_double
.low
;
11331 first
= a
->dw_attr_val
.v
.val_double
.low
;
11332 second
= a
->dw_attr_val
.v
.val_double
.high
;
11335 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
11337 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
11342 case dw_val_class_vec
:
11344 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
11345 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
11349 dw2_asm_output_data (constant_size (len
* elt_size
),
11350 len
* elt_size
, "%s", name
);
11351 if (elt_size
> sizeof (HOST_WIDE_INT
))
11356 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
11358 i
++, p
+= elt_size
)
11359 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
11360 "fp or vector constant word %u", i
);
11364 case dw_val_class_flag
:
11365 if (dwarf_version
>= 4)
11367 /* Currently all add_AT_flag calls pass in 1 as last argument,
11368 so DW_FORM_flag_present can be used. If that ever changes,
11369 we'll need to use DW_FORM_flag and have some optimization
11370 in build_abbrev_table that will change those to
11371 DW_FORM_flag_present if it is set to 1 in all DIEs using
11372 the same abbrev entry. */
11373 gcc_assert (AT_flag (a
) == 1);
11374 if (flag_debug_asm
)
11375 fprintf (asm_out_file
, "\t\t\t%s %s\n",
11376 ASM_COMMENT_START
, name
);
11379 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
11382 case dw_val_class_loc_list
:
11384 char *sym
= AT_loc_list (a
)->ll_symbol
;
11387 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
11392 case dw_val_class_die_ref
:
11393 if (AT_ref_external (a
))
11395 if (use_debug_types
)
11397 comdat_type_node_ref type_node
=
11398 AT_ref (a
)->die_id
.die_type_node
;
11400 gcc_assert (type_node
);
11401 output_signature (type_node
->signature
, name
);
11405 char *sym
= AT_ref (a
)->die_id
.die_symbol
;
11409 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11410 length, whereas in DWARF3 it's always sized as an
11412 if (dwarf_version
== 2)
11413 size
= DWARF2_ADDR_SIZE
;
11415 size
= DWARF_OFFSET_SIZE
;
11416 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
11422 gcc_assert (AT_ref (a
)->die_offset
);
11423 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
11428 case dw_val_class_fde_ref
:
11432 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
11433 a
->dw_attr_val
.v
.val_fde_index
* 2);
11434 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
11439 case dw_val_class_vms_delta
:
11440 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
11441 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
11445 case dw_val_class_lbl_id
:
11446 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
11449 case dw_val_class_lineptr
:
11450 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
11451 debug_line_section
, "%s", name
);
11454 case dw_val_class_macptr
:
11455 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
11456 debug_macinfo_section
, "%s", name
);
11459 case dw_val_class_str
:
11460 if (AT_string_form (a
) == DW_FORM_strp
)
11461 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
11462 a
->dw_attr_val
.v
.val_str
->label
,
11464 "%s: \"%s\"", name
, AT_string (a
));
11466 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
11469 case dw_val_class_file
:
11471 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
11473 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
11474 a
->dw_attr_val
.v
.val_file
->filename
);
11478 case dw_val_class_data8
:
11482 for (i
= 0; i
< 8; i
++)
11483 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
11484 i
== 0 ? "%s" : NULL
, name
);
11489 gcc_unreachable ();
11493 FOR_EACH_CHILD (die
, c
, output_die (c
));
11495 /* Add null byte to terminate sibling list. */
11496 if (die
->die_child
!= NULL
)
11497 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11498 (unsigned long) die
->die_offset
);
11501 /* Output the compilation unit that appears at the beginning of the
11502 .debug_info section, and precedes the DIE descriptions. */
11505 output_compilation_unit_header (void)
11507 int ver
= dwarf_version
;
11509 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11510 dw2_asm_output_data (4, 0xffffffff,
11511 "Initial length escape value indicating 64-bit DWARF extension");
11512 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
11513 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
11514 "Length of Compilation Unit Info");
11515 dw2_asm_output_data (2, ver
, "DWARF version number");
11516 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
11517 debug_abbrev_section
,
11518 "Offset Into Abbrev. Section");
11519 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
11522 /* Output the compilation unit DIE and its children. */
11525 output_comp_unit (dw_die_ref die
, int output_if_empty
)
11527 const char *secname
;
11528 char *oldsym
, *tmp
;
11530 /* Unless we are outputting main CU, we may throw away empty ones. */
11531 if (!output_if_empty
&& die
->die_child
== NULL
)
11534 /* Even if there are no children of this DIE, we must output the information
11535 about the compilation unit. Otherwise, on an empty translation unit, we
11536 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11537 will then complain when examining the file. First mark all the DIEs in
11538 this CU so we know which get local refs. */
11541 build_abbrev_table (die
);
11543 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11544 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
11545 calc_die_sizes (die
);
11547 oldsym
= die
->die_id
.die_symbol
;
11550 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
11552 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
11554 die
->die_id
.die_symbol
= NULL
;
11555 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
11559 switch_to_section (debug_info_section
);
11560 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
11561 info_section_emitted
= true;
11564 /* Output debugging information. */
11565 output_compilation_unit_header ();
11568 /* Leave the marks on the main CU, so we can check them in
11569 output_pubnames. */
11573 die
->die_id
.die_symbol
= oldsym
;
11577 /* Output a comdat type unit DIE and its children. */
11580 output_comdat_type_unit (comdat_type_node
*node
)
11582 const char *secname
;
11585 #if defined (OBJECT_FORMAT_ELF)
11589 /* First mark all the DIEs in this CU so we know which get local refs. */
11590 mark_dies (node
->root_die
);
11592 build_abbrev_table (node
->root_die
);
11594 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11595 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
11596 calc_die_sizes (node
->root_die
);
11598 #if defined (OBJECT_FORMAT_ELF)
11599 secname
= ".debug_types";
11600 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
11601 sprintf (tmp
, "wt.");
11602 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
11603 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
11604 comdat_key
= get_identifier (tmp
);
11605 targetm
.asm_out
.named_section (secname
,
11606 SECTION_DEBUG
| SECTION_LINKONCE
,
11609 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
11610 sprintf (tmp
, ".gnu.linkonce.wt.");
11611 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
11612 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
11614 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
11617 /* Output debugging information. */
11618 output_compilation_unit_header ();
11619 output_signature (node
->signature
, "Type Signature");
11620 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
11621 "Offset to Type DIE");
11622 output_die (node
->root_die
);
11624 unmark_dies (node
->root_die
);
11627 /* Return the DWARF2/3 pubname associated with a decl. */
11629 static const char *
11630 dwarf2_name (tree decl
, int scope
)
11632 if (DECL_NAMELESS (decl
))
11634 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
11637 /* Add a new entry to .debug_pubnames if appropriate. */
11640 add_pubname_string (const char *str
, dw_die_ref die
)
11642 if (targetm
.want_debug_pub_sections
)
11647 e
.name
= xstrdup (str
);
11648 VEC_safe_push (pubname_entry
, gc
, pubname_table
, &e
);
11653 add_pubname (tree decl
, dw_die_ref die
)
11655 if (targetm
.want_debug_pub_sections
&& TREE_PUBLIC (decl
))
11657 const char *name
= dwarf2_name (decl
, 1);
11659 add_pubname_string (name
, die
);
11663 /* Add a new entry to .debug_pubtypes if appropriate. */
11666 add_pubtype (tree decl
, dw_die_ref die
)
11670 if (!targetm
.want_debug_pub_sections
)
11674 if ((TREE_PUBLIC (decl
)
11675 || is_cu_die (die
->die_parent
))
11676 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
11681 if (TYPE_NAME (decl
))
11683 if (TREE_CODE (TYPE_NAME (decl
)) == IDENTIFIER_NODE
)
11684 e
.name
= IDENTIFIER_POINTER (TYPE_NAME (decl
));
11685 else if (TREE_CODE (TYPE_NAME (decl
)) == TYPE_DECL
11686 && DECL_NAME (TYPE_NAME (decl
)))
11687 e
.name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl
)));
11689 e
.name
= xstrdup ((const char *) get_AT_string (die
, DW_AT_name
));
11694 e
.name
= dwarf2_name (decl
, 1);
11696 e
.name
= xstrdup (e
.name
);
11699 /* If we don't have a name for the type, there's no point in adding
11700 it to the table. */
11701 if (e
.name
&& e
.name
[0] != '\0')
11702 VEC_safe_push (pubname_entry
, gc
, pubtype_table
, &e
);
11706 /* Output the public names table used to speed up access to externally
11707 visible names; or the public types table used to find type definitions. */
11710 output_pubnames (VEC (pubname_entry
, gc
) * names
)
11713 unsigned long pubnames_length
= size_of_pubnames (names
);
11716 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11717 dw2_asm_output_data (4, 0xffffffff,
11718 "Initial length escape value indicating 64-bit DWARF extension");
11719 if (names
== pubname_table
)
11720 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
11721 "Length of Public Names Info");
11723 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
11724 "Length of Public Type Names Info");
11725 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
11726 dw2_asm_output_data (2, 2, "DWARF Version");
11727 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
11728 debug_info_section
,
11729 "Offset of Compilation Unit Info");
11730 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
11731 "Compilation Unit Length");
11733 FOR_EACH_VEC_ELT (pubname_entry
, names
, i
, pub
)
11735 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11736 if (names
== pubname_table
)
11737 gcc_assert (pub
->die
->die_mark
);
11739 if (names
!= pubtype_table
11740 || pub
->die
->die_offset
!= 0
11741 || !flag_eliminate_unused_debug_types
)
11743 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
11746 dw2_asm_output_nstring (pub
->name
, -1, "external name");
11750 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
11753 /* Output the information that goes into the .debug_aranges table.
11754 Namely, define the beginning and ending address range of the
11755 text section generated for this compilation unit. */
11758 output_aranges (unsigned long aranges_length
)
11762 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11763 dw2_asm_output_data (4, 0xffffffff,
11764 "Initial length escape value indicating 64-bit DWARF extension");
11765 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
11766 "Length of Address Ranges Info");
11767 /* Version number for aranges is still 2, even in DWARF3. */
11768 dw2_asm_output_data (2, 2, "DWARF Version");
11769 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
11770 debug_info_section
,
11771 "Offset of Compilation Unit Info");
11772 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
11773 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11775 /* We need to align to twice the pointer size here. */
11776 if (DWARF_ARANGES_PAD_SIZE
)
11778 /* Pad using a 2 byte words so that padding is correct for any
11780 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11781 2 * DWARF2_ADDR_SIZE
);
11782 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
11783 dw2_asm_output_data (2, 0, NULL
);
11786 /* It is necessary not to output these entries if the sections were
11787 not used; if the sections were not used, the length will be 0 and
11788 the address may end up as 0 if the section is discarded by ld
11789 --gc-sections, leaving an invalid (0, 0) entry that can be
11790 confused with the terminator. */
11791 if (text_section_used
)
11793 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
11794 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
11795 text_section_label
, "Length");
11797 if (cold_text_section_used
)
11799 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
11801 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
11802 cold_text_section_label
, "Length");
11805 if (have_multiple_function_sections
)
11807 unsigned fde_idx
= 0;
11809 for (fde_idx
= 0; fde_idx
< fde_table_in_use
; fde_idx
++)
11811 dw_fde_ref fde
= &fde_table
[fde_idx
];
11813 if (!fde
->in_std_section
)
11815 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
11817 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
11818 fde
->dw_fde_begin
, "Length");
11820 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
11822 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
11824 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
11825 fde
->dw_fde_second_begin
, "Length");
11830 /* Output the terminator words. */
11831 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11832 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11835 /* Add a new entry to .debug_ranges. Return the offset at which it
11838 static unsigned int
11839 add_ranges_num (int num
)
11841 unsigned int in_use
= ranges_table_in_use
;
11843 if (in_use
== ranges_table_allocated
)
11845 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
11846 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
11847 ranges_table_allocated
);
11848 memset (ranges_table
+ ranges_table_in_use
, 0,
11849 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
11852 ranges_table
[in_use
].num
= num
;
11853 ranges_table_in_use
= in_use
+ 1;
11855 return in_use
* 2 * DWARF2_ADDR_SIZE
;
11858 /* Add a new entry to .debug_ranges corresponding to a block, or a
11859 range terminator if BLOCK is NULL. */
11861 static unsigned int
11862 add_ranges (const_tree block
)
11864 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
11867 /* Add a new entry to .debug_ranges corresponding to a pair of
11871 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
11874 unsigned int in_use
= ranges_by_label_in_use
;
11875 unsigned int offset
;
11877 if (in_use
== ranges_by_label_allocated
)
11879 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
11880 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
11882 ranges_by_label_allocated
);
11883 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
11884 RANGES_TABLE_INCREMENT
11885 * sizeof (struct dw_ranges_by_label_struct
));
11888 ranges_by_label
[in_use
].begin
= begin
;
11889 ranges_by_label
[in_use
].end
= end
;
11890 ranges_by_label_in_use
= in_use
+ 1;
11892 offset
= add_ranges_num (-(int)in_use
- 1);
11895 add_AT_range_list (die
, DW_AT_ranges
, offset
);
11901 output_ranges (void)
11904 static const char *const start_fmt
= "Offset %#x";
11905 const char *fmt
= start_fmt
;
11907 for (i
= 0; i
< ranges_table_in_use
; i
++)
11909 int block_num
= ranges_table
[i
].num
;
11913 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11914 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11916 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
11917 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
11919 /* If all code is in the text section, then the compilation
11920 unit base address defaults to DW_AT_low_pc, which is the
11921 base of the text section. */
11922 if (!have_multiple_function_sections
)
11924 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
11925 text_section_label
,
11926 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11927 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
11928 text_section_label
, NULL
);
11931 /* Otherwise, the compilation unit base address is zero,
11932 which allows us to use absolute addresses, and not worry
11933 about whether the target supports cross-section
11937 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11938 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11939 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
11945 /* Negative block_num stands for an index into ranges_by_label. */
11946 else if (block_num
< 0)
11948 int lab_idx
= - block_num
- 1;
11950 if (!have_multiple_function_sections
)
11952 gcc_unreachable ();
11954 /* If we ever use add_ranges_by_labels () for a single
11955 function section, all we have to do is to take out
11956 the #if 0 above. */
11957 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11958 ranges_by_label
[lab_idx
].begin
,
11959 text_section_label
,
11960 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11961 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11962 ranges_by_label
[lab_idx
].end
,
11963 text_section_label
, NULL
);
11968 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11969 ranges_by_label
[lab_idx
].begin
,
11970 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11971 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11972 ranges_by_label
[lab_idx
].end
,
11978 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11979 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11985 /* Data structure containing information about input files. */
11988 const char *path
; /* Complete file name. */
11989 const char *fname
; /* File name part. */
11990 int length
; /* Length of entire string. */
11991 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
11992 int dir_idx
; /* Index in directory table. */
11995 /* Data structure containing information about directories with source
11999 const char *path
; /* Path including directory name. */
12000 int length
; /* Path length. */
12001 int prefix
; /* Index of directory entry which is a prefix. */
12002 int count
; /* Number of files in this directory. */
12003 int dir_idx
; /* Index of directory used as base. */
12006 /* Callback function for file_info comparison. We sort by looking at
12007 the directories in the path. */
12010 file_info_cmp (const void *p1
, const void *p2
)
12012 const struct file_info
*const s1
= (const struct file_info
*) p1
;
12013 const struct file_info
*const s2
= (const struct file_info
*) p2
;
12014 const unsigned char *cp1
;
12015 const unsigned char *cp2
;
12017 /* Take care of file names without directories. We need to make sure that
12018 we return consistent values to qsort since some will get confused if
12019 we return the same value when identical operands are passed in opposite
12020 orders. So if neither has a directory, return 0 and otherwise return
12021 1 or -1 depending on which one has the directory. */
12022 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
12023 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
12025 cp1
= (const unsigned char *) s1
->path
;
12026 cp2
= (const unsigned char *) s2
->path
;
12032 /* Reached the end of the first path? If so, handle like above. */
12033 if ((cp1
== (const unsigned char *) s1
->fname
)
12034 || (cp2
== (const unsigned char *) s2
->fname
))
12035 return ((cp2
== (const unsigned char *) s2
->fname
)
12036 - (cp1
== (const unsigned char *) s1
->fname
));
12038 /* Character of current path component the same? */
12039 else if (*cp1
!= *cp2
)
12040 return *cp1
- *cp2
;
12044 struct file_name_acquire_data
12046 struct file_info
*files
;
12051 /* Traversal function for the hash table. */
12054 file_name_acquire (void ** slot
, void *data
)
12056 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
12057 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
12058 struct file_info
*fi
;
12061 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
12063 if (! d
->emitted_number
)
12066 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
12068 fi
= fnad
->files
+ fnad
->used_files
++;
12070 /* Skip all leading "./". */
12072 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
12075 /* Create a new array entry. */
12077 fi
->length
= strlen (f
);
12080 /* Search for the file name part. */
12081 f
= strrchr (f
, DIR_SEPARATOR
);
12082 #if defined (DIR_SEPARATOR_2)
12084 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
12088 if (f
== NULL
|| f
< g
)
12094 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
12098 /* Output the directory table and the file name table. We try to minimize
12099 the total amount of memory needed. A heuristic is used to avoid large
12100 slowdowns with many input files. */
12103 output_file_names (void)
12105 struct file_name_acquire_data fnad
;
12107 struct file_info
*files
;
12108 struct dir_info
*dirs
;
12116 if (!last_emitted_file
)
12118 dw2_asm_output_data (1, 0, "End directory table");
12119 dw2_asm_output_data (1, 0, "End file name table");
12123 numfiles
= last_emitted_file
->emitted_number
;
12125 /* Allocate the various arrays we need. */
12126 files
= XALLOCAVEC (struct file_info
, numfiles
);
12127 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
12129 fnad
.files
= files
;
12130 fnad
.used_files
= 0;
12131 fnad
.max_files
= numfiles
;
12132 htab_traverse (file_table
, file_name_acquire
, &fnad
);
12133 gcc_assert (fnad
.used_files
== fnad
.max_files
);
12135 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
12137 /* Find all the different directories used. */
12138 dirs
[0].path
= files
[0].path
;
12139 dirs
[0].length
= files
[0].fname
- files
[0].path
;
12140 dirs
[0].prefix
= -1;
12142 dirs
[0].dir_idx
= 0;
12143 files
[0].dir_idx
= 0;
12146 for (i
= 1; i
< numfiles
; i
++)
12147 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
12148 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
12149 dirs
[ndirs
- 1].length
) == 0)
12151 /* Same directory as last entry. */
12152 files
[i
].dir_idx
= ndirs
- 1;
12153 ++dirs
[ndirs
- 1].count
;
12159 /* This is a new directory. */
12160 dirs
[ndirs
].path
= files
[i
].path
;
12161 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
12162 dirs
[ndirs
].count
= 1;
12163 dirs
[ndirs
].dir_idx
= ndirs
;
12164 files
[i
].dir_idx
= ndirs
;
12166 /* Search for a prefix. */
12167 dirs
[ndirs
].prefix
= -1;
12168 for (j
= 0; j
< ndirs
; j
++)
12169 if (dirs
[j
].length
< dirs
[ndirs
].length
12170 && dirs
[j
].length
> 1
12171 && (dirs
[ndirs
].prefix
== -1
12172 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
12173 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
12174 dirs
[ndirs
].prefix
= j
;
12179 /* Now to the actual work. We have to find a subset of the directories which
12180 allow expressing the file name using references to the directory table
12181 with the least amount of characters. We do not do an exhaustive search
12182 where we would have to check out every combination of every single
12183 possible prefix. Instead we use a heuristic which provides nearly optimal
12184 results in most cases and never is much off. */
12185 saved
= XALLOCAVEC (int, ndirs
);
12186 savehere
= XALLOCAVEC (int, ndirs
);
12188 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
12189 for (i
= 0; i
< ndirs
; i
++)
12194 /* We can always save some space for the current directory. But this
12195 does not mean it will be enough to justify adding the directory. */
12196 savehere
[i
] = dirs
[i
].length
;
12197 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
12199 for (j
= i
+ 1; j
< ndirs
; j
++)
12202 if (saved
[j
] < dirs
[i
].length
)
12204 /* Determine whether the dirs[i] path is a prefix of the
12208 k
= dirs
[j
].prefix
;
12209 while (k
!= -1 && k
!= (int) i
)
12210 k
= dirs
[k
].prefix
;
12214 /* Yes it is. We can possibly save some memory by
12215 writing the filenames in dirs[j] relative to
12217 savehere
[j
] = dirs
[i
].length
;
12218 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
12223 /* Check whether we can save enough to justify adding the dirs[i]
12225 if (total
> dirs
[i
].length
+ 1)
12227 /* It's worthwhile adding. */
12228 for (j
= i
; j
< ndirs
; j
++)
12229 if (savehere
[j
] > 0)
12231 /* Remember how much we saved for this directory so far. */
12232 saved
[j
] = savehere
[j
];
12234 /* Remember the prefix directory. */
12235 dirs
[j
].dir_idx
= i
;
12240 /* Emit the directory name table. */
12241 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
12242 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
12243 dw2_asm_output_nstring (dirs
[i
].path
,
12245 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
12246 "Directory Entry: %#x", i
+ idx_offset
);
12248 dw2_asm_output_data (1, 0, "End directory table");
12250 /* We have to emit them in the order of emitted_number since that's
12251 used in the debug info generation. To do this efficiently we
12252 generate a back-mapping of the indices first. */
12253 backmap
= XALLOCAVEC (int, numfiles
);
12254 for (i
= 0; i
< numfiles
; i
++)
12255 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
12257 /* Now write all the file names. */
12258 for (i
= 0; i
< numfiles
; i
++)
12260 int file_idx
= backmap
[i
];
12261 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
12263 #ifdef VMS_DEBUGGING_INFO
12264 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12266 /* Setting these fields can lead to debugger miscomparisons,
12267 but VMS Debug requires them to be set correctly. */
12272 int maxfilelen
= strlen (files
[file_idx
].path
)
12273 + dirs
[dir_idx
].length
12274 + MAX_VMS_VERSION_LEN
+ 1;
12275 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
12277 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
12278 snprintf (filebuf
, maxfilelen
, "%s;%d",
12279 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
12281 dw2_asm_output_nstring
12282 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
12284 /* Include directory index. */
12285 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
12287 /* Modification time. */
12288 dw2_asm_output_data_uleb128
12289 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
12293 /* File length in bytes. */
12294 dw2_asm_output_data_uleb128
12295 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
12299 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
12300 "File Entry: %#x", (unsigned) i
+ 1);
12302 /* Include directory index. */
12303 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
12305 /* Modification time. */
12306 dw2_asm_output_data_uleb128 (0, NULL
);
12308 /* File length in bytes. */
12309 dw2_asm_output_data_uleb128 (0, NULL
);
12310 #endif /* VMS_DEBUGGING_INFO */
12313 dw2_asm_output_data (1, 0, "End file name table");
12317 /* Output one line number table into the .debug_line section. */
12320 output_one_line_info_table (dw_line_info_table
*table
)
12322 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
12323 unsigned int current_line
= 1;
12324 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
12325 dw_line_info_entry
*ent
;
12328 FOR_EACH_VEC_ELT (dw_line_info_entry
, table
->entries
, i
, ent
)
12330 switch (ent
->opcode
)
12332 case LI_set_address
:
12333 /* ??? Unfortunately, we have little choice here currently, and
12334 must always use the most general form. GCC does not know the
12335 address delta itself, so we can't use DW_LNS_advance_pc. Many
12336 ports do have length attributes which will give an upper bound
12337 on the address range. We could perhaps use length attributes
12338 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
12339 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
12341 /* This can handle any delta. This takes
12342 4+DWARF2_ADDR_SIZE bytes. */
12343 dw2_asm_output_data (1, 0, "set address %s", line_label
);
12344 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12345 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12346 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
12350 if (ent
->val
== current_line
)
12352 /* We still need to start a new row, so output a copy insn. */
12353 dw2_asm_output_data (1, DW_LNS_copy
,
12354 "copy line %u", current_line
);
12358 int line_offset
= ent
->val
- current_line
;
12359 int line_delta
= line_offset
- DWARF_LINE_BASE
;
12361 current_line
= ent
->val
;
12362 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
12364 /* This can handle deltas from -10 to 234, using the current
12365 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
12366 This takes 1 byte. */
12367 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
12368 "line %u", current_line
);
12372 /* This can handle any delta. This takes at least 4 bytes,
12373 depending on the value being encoded. */
12374 dw2_asm_output_data (1, DW_LNS_advance_line
,
12375 "advance to line %u", current_line
);
12376 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
12377 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
12383 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
12384 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
12387 case LI_set_column
:
12388 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
12389 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
12392 case LI_negate_stmt
:
12393 current_is_stmt
= !current_is_stmt
;
12394 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
12395 "is_stmt %d", current_is_stmt
);
12398 case LI_set_prologue_end
:
12399 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
12400 "set prologue end");
12403 case LI_set_epilogue_begin
:
12404 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
12405 "set epilogue begin");
12408 case LI_set_discriminator
:
12409 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
12410 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
12411 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
12412 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
12417 /* Emit debug info for the address of the end of the table. */
12418 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
12419 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12420 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12421 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
12423 dw2_asm_output_data (1, 0, "end sequence");
12424 dw2_asm_output_data_uleb128 (1, NULL
);
12425 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
12428 /* Output the source line number correspondence information. This
12429 information goes into the .debug_line section. */
12432 output_line_info (void)
12434 char l1
[20], l2
[20], p1
[20], p2
[20];
12435 int ver
= dwarf_version
;
12436 bool saw_one
= false;
12439 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
12440 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
12441 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
12442 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
12444 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
12445 dw2_asm_output_data (4, 0xffffffff,
12446 "Initial length escape value indicating 64-bit DWARF extension");
12447 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
12448 "Length of Source Line Info");
12449 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
12451 dw2_asm_output_data (2, ver
, "DWARF Version");
12452 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
12453 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
12455 /* Define the architecture-dependent minimum instruction length (in bytes).
12456 In this implementation of DWARF, this field is used for information
12457 purposes only. Since GCC generates assembly language, we have no
12458 a priori knowledge of how many instruction bytes are generated for each
12459 source line, and therefore can use only the DW_LNE_set_address and
12460 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
12461 this as '1', which is "correct enough" for all architectures,
12462 and don't let the target override. */
12463 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
12466 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
12467 "Maximum Operations Per Instruction");
12468 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
12469 "Default is_stmt_start flag");
12470 dw2_asm_output_data (1, DWARF_LINE_BASE
,
12471 "Line Base Value (Special Opcodes)");
12472 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
12473 "Line Range Value (Special Opcodes)");
12474 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
12475 "Special Opcode Base");
12477 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
12482 case DW_LNS_advance_pc
:
12483 case DW_LNS_advance_line
:
12484 case DW_LNS_set_file
:
12485 case DW_LNS_set_column
:
12486 case DW_LNS_fixed_advance_pc
:
12487 case DW_LNS_set_isa
:
12495 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
12499 /* Write out the information about the files we use. */
12500 output_file_names ();
12501 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
12503 if (separate_line_info
)
12505 dw_line_info_table
*table
;
12508 FOR_EACH_VEC_ELT (dw_line_info_table_p
, separate_line_info
, i
, table
)
12511 output_one_line_info_table (table
);
12515 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
12517 output_one_line_info_table (cold_text_section_line_info
);
12521 /* ??? Some Darwin linkers crash on a .debug_line section with no
12522 sequences. Further, merely a DW_LNE_end_sequence entry is not
12523 sufficient -- the address column must also be initialized.
12524 Make sure to output at least one set_address/end_sequence pair,
12525 choosing .text since that section is always present. */
12526 if (text_section_line_info
->in_use
|| !saw_one
)
12527 output_one_line_info_table (text_section_line_info
);
12529 /* Output the marker for the end of the line number info. */
12530 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
12533 /* Given a pointer to a tree node for some base type, return a pointer to
12534 a DIE that describes the given type.
12536 This routine must only be called for GCC type nodes that correspond to
12537 Dwarf base (fundamental) types. */
12540 base_type_die (tree type
)
12542 dw_die_ref base_type_result
;
12543 enum dwarf_type encoding
;
12545 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
12548 /* If this is a subtype that should not be emitted as a subrange type,
12549 use the base type. See subrange_type_for_debug_p. */
12550 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
12551 type
= TREE_TYPE (type
);
12553 switch (TREE_CODE (type
))
12556 if ((dwarf_version
>= 4 || !dwarf_strict
)
12557 && TYPE_NAME (type
)
12558 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12559 && DECL_IS_BUILTIN (TYPE_NAME (type
))
12560 && DECL_NAME (TYPE_NAME (type
)))
12562 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
12563 if (strcmp (name
, "char16_t") == 0
12564 || strcmp (name
, "char32_t") == 0)
12566 encoding
= DW_ATE_UTF
;
12570 if (TYPE_STRING_FLAG (type
))
12572 if (TYPE_UNSIGNED (type
))
12573 encoding
= DW_ATE_unsigned_char
;
12575 encoding
= DW_ATE_signed_char
;
12577 else if (TYPE_UNSIGNED (type
))
12578 encoding
= DW_ATE_unsigned
;
12580 encoding
= DW_ATE_signed
;
12584 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
12586 if (dwarf_version
>= 3 || !dwarf_strict
)
12587 encoding
= DW_ATE_decimal_float
;
12589 encoding
= DW_ATE_lo_user
;
12592 encoding
= DW_ATE_float
;
12595 case FIXED_POINT_TYPE
:
12596 if (!(dwarf_version
>= 3 || !dwarf_strict
))
12597 encoding
= DW_ATE_lo_user
;
12598 else if (TYPE_UNSIGNED (type
))
12599 encoding
= DW_ATE_unsigned_fixed
;
12601 encoding
= DW_ATE_signed_fixed
;
12604 /* Dwarf2 doesn't know anything about complex ints, so use
12605 a user defined type for it. */
12607 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
12608 encoding
= DW_ATE_complex_float
;
12610 encoding
= DW_ATE_lo_user
;
12614 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12615 encoding
= DW_ATE_boolean
;
12619 /* No other TREE_CODEs are Dwarf fundamental types. */
12620 gcc_unreachable ();
12623 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
12625 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
12626 int_size_in_bytes (type
));
12627 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
12629 return base_type_result
;
12632 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12633 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12636 is_base_type (tree type
)
12638 switch (TREE_CODE (type
))
12644 case FIXED_POINT_TYPE
:
12652 case QUAL_UNION_TYPE
:
12653 case ENUMERAL_TYPE
:
12654 case FUNCTION_TYPE
:
12657 case REFERENCE_TYPE
:
12665 gcc_unreachable ();
12671 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12672 node, return the size in bits for the type if it is a constant, or else
12673 return the alignment for the type if the type's size is not constant, or
12674 else return BITS_PER_WORD if the type actually turns out to be an
12675 ERROR_MARK node. */
12677 static inline unsigned HOST_WIDE_INT
12678 simple_type_size_in_bits (const_tree type
)
12680 if (TREE_CODE (type
) == ERROR_MARK
)
12681 return BITS_PER_WORD
;
12682 else if (TYPE_SIZE (type
) == NULL_TREE
)
12684 else if (host_integerp (TYPE_SIZE (type
), 1))
12685 return tree_low_cst (TYPE_SIZE (type
), 1);
12687 return TYPE_ALIGN (type
);
12690 /* Similarly, but return a double_int instead of UHWI. */
12692 static inline double_int
12693 double_int_type_size_in_bits (const_tree type
)
12695 if (TREE_CODE (type
) == ERROR_MARK
)
12696 return uhwi_to_double_int (BITS_PER_WORD
);
12697 else if (TYPE_SIZE (type
) == NULL_TREE
)
12698 return double_int_zero
;
12699 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
12700 return tree_to_double_int (TYPE_SIZE (type
));
12702 return uhwi_to_double_int (TYPE_ALIGN (type
));
12705 /* Given a pointer to a tree node for a subrange type, return a pointer
12706 to a DIE that describes the given type. */
12709 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
12711 dw_die_ref subrange_die
;
12712 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
12714 if (context_die
== NULL
)
12715 context_die
= comp_unit_die ();
12717 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
12719 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
12721 /* The size of the subrange type and its base type do not match,
12722 so we need to generate a size attribute for the subrange type. */
12723 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
12727 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
12729 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
12731 return subrange_die
;
12734 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12735 entry that chains various modifiers in front of the given type. */
12738 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
12739 dw_die_ref context_die
)
12741 enum tree_code code
= TREE_CODE (type
);
12742 dw_die_ref mod_type_die
;
12743 dw_die_ref sub_die
= NULL
;
12744 tree item_type
= NULL
;
12745 tree qualified_type
;
12746 tree name
, low
, high
;
12748 if (code
== ERROR_MARK
)
12751 /* See if we already have the appropriately qualified variant of
12754 = get_qualified_type (type
,
12755 ((is_const_type
? TYPE_QUAL_CONST
: 0)
12756 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
12758 if (qualified_type
== sizetype
12759 && TYPE_NAME (qualified_type
)
12760 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
12762 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
12764 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
12765 && TYPE_PRECISION (t
)
12766 == TYPE_PRECISION (qualified_type
)
12767 && TYPE_UNSIGNED (t
)
12768 == TYPE_UNSIGNED (qualified_type
));
12769 qualified_type
= t
;
12772 /* If we do, then we can just use its DIE, if it exists. */
12773 if (qualified_type
)
12775 mod_type_die
= lookup_type_die (qualified_type
);
12777 return mod_type_die
;
12780 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
12782 /* Handle C typedef types. */
12783 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
12784 && !DECL_ARTIFICIAL (name
))
12786 tree dtype
= TREE_TYPE (name
);
12788 if (qualified_type
== dtype
)
12790 /* For a named type, use the typedef. */
12791 gen_type_die (qualified_type
, context_die
);
12792 return lookup_type_die (qualified_type
);
12794 else if (is_const_type
< TYPE_READONLY (dtype
)
12795 || is_volatile_type
< TYPE_VOLATILE (dtype
)
12796 || (is_const_type
<= TYPE_READONLY (dtype
)
12797 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
12798 && DECL_ORIGINAL_TYPE (name
) != type
))
12799 /* cv-unqualified version of named type. Just use the unnamed
12800 type to which it refers. */
12801 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
12802 is_const_type
, is_volatile_type
,
12804 /* Else cv-qualified version of named type; fall through. */
12808 /* If both is_const_type and is_volatile_type, prefer the path
12809 which leads to a qualified type. */
12810 && (!is_volatile_type
12811 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
12812 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
12814 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die (), type
);
12815 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
12817 else if (is_volatile_type
)
12819 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die (), type
);
12820 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
12822 else if (code
== POINTER_TYPE
)
12824 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die (), type
);
12825 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
12826 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
12827 item_type
= TREE_TYPE (type
);
12828 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
12829 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
12830 TYPE_ADDR_SPACE (item_type
));
12832 else if (code
== REFERENCE_TYPE
)
12834 if (TYPE_REF_IS_RVALUE (type
) && use_debug_types
)
12835 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, comp_unit_die (),
12838 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die (), type
);
12839 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
12840 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
12841 item_type
= TREE_TYPE (type
);
12842 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
12843 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
12844 TYPE_ADDR_SPACE (item_type
));
12846 else if (code
== INTEGER_TYPE
12847 && TREE_TYPE (type
) != NULL_TREE
12848 && subrange_type_for_debug_p (type
, &low
, &high
))
12850 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
12851 item_type
= TREE_TYPE (type
);
12853 else if (is_base_type (type
))
12854 mod_type_die
= base_type_die (type
);
12857 gen_type_die (type
, context_die
);
12859 /* We have to get the type_main_variant here (and pass that to the
12860 `lookup_type_die' routine) because the ..._TYPE node we have
12861 might simply be a *copy* of some original type node (where the
12862 copy was created to help us keep track of typedef names) and
12863 that copy might have a different TYPE_UID from the original
12865 if (TREE_CODE (type
) != VECTOR_TYPE
)
12866 return lookup_type_die (type_main_variant (type
));
12868 /* Vectors have the debugging information in the type,
12869 not the main variant. */
12870 return lookup_type_die (type
);
12873 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
12874 don't output a DW_TAG_typedef, since there isn't one in the
12875 user's program; just attach a DW_AT_name to the type.
12876 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
12877 if the base type already has the same name. */
12879 && ((TREE_CODE (name
) != TYPE_DECL
12880 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
12881 || (!is_const_type
&& !is_volatile_type
)))
12882 || (TREE_CODE (name
) == TYPE_DECL
12883 && TREE_TYPE (name
) == qualified_type
12884 && DECL_NAME (name
))))
12886 if (TREE_CODE (name
) == TYPE_DECL
)
12887 /* Could just call add_name_and_src_coords_attributes here,
12888 but since this is a builtin type it doesn't have any
12889 useful source coordinates anyway. */
12890 name
= DECL_NAME (name
);
12891 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
12892 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
12894 /* This probably indicates a bug. */
12895 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
12896 add_name_attribute (mod_type_die
, "__unknown__");
12898 if (qualified_type
)
12899 equate_type_number_to_die (qualified_type
, mod_type_die
);
12902 /* We must do this after the equate_type_number_to_die call, in case
12903 this is a recursive type. This ensures that the modified_type_die
12904 recursion will terminate even if the type is recursive. Recursive
12905 types are possible in Ada. */
12906 sub_die
= modified_type_die (item_type
,
12907 TYPE_READONLY (item_type
),
12908 TYPE_VOLATILE (item_type
),
12911 if (sub_die
!= NULL
)
12912 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
12914 return mod_type_die
;
12917 /* Generate DIEs for the generic parameters of T.
12918 T must be either a generic type or a generic function.
12919 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
12922 gen_generic_params_dies (tree t
)
12926 dw_die_ref die
= NULL
;
12928 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
12932 die
= lookup_type_die (t
);
12933 else if (DECL_P (t
))
12934 die
= lookup_decl_die (t
);
12938 parms
= lang_hooks
.get_innermost_generic_parms (t
);
12940 /* T has no generic parameter. It means T is neither a generic type
12941 or function. End of story. */
12944 parms_num
= TREE_VEC_LENGTH (parms
);
12945 args
= lang_hooks
.get_innermost_generic_args (t
);
12946 for (i
= 0; i
< parms_num
; i
++)
12948 tree parm
, arg
, arg_pack_elems
;
12950 parm
= TREE_VEC_ELT (parms
, i
);
12951 arg
= TREE_VEC_ELT (args
, i
);
12952 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
12953 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
12955 if (parm
&& TREE_VALUE (parm
) && arg
)
12957 /* If PARM represents a template parameter pack,
12958 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
12959 by DW_TAG_template_*_parameter DIEs for the argument
12960 pack elements of ARG. Note that ARG would then be
12961 an argument pack. */
12962 if (arg_pack_elems
)
12963 template_parameter_pack_die (TREE_VALUE (parm
),
12967 generic_parameter_die (TREE_VALUE (parm
), arg
,
12968 true /* Emit DW_AT_name */, die
);
12973 /* Create and return a DIE for PARM which should be
12974 the representation of a generic type parameter.
12975 For instance, in the C++ front end, PARM would be a template parameter.
12976 ARG is the argument to PARM.
12977 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
12979 PARENT_DIE is the parent DIE which the new created DIE should be added to,
12980 as a child node. */
12983 generic_parameter_die (tree parm
, tree arg
,
12985 dw_die_ref parent_die
)
12987 dw_die_ref tmpl_die
= NULL
;
12988 const char *name
= NULL
;
12990 if (!parm
|| !DECL_NAME (parm
) || !arg
)
12993 /* We support non-type generic parameters and arguments,
12994 type generic parameters and arguments, as well as
12995 generic generic parameters (a.k.a. template template parameters in C++)
12997 if (TREE_CODE (parm
) == PARM_DECL
)
12998 /* PARM is a nontype generic parameter */
12999 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
13000 else if (TREE_CODE (parm
) == TYPE_DECL
)
13001 /* PARM is a type generic parameter. */
13002 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
13003 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
13004 /* PARM is a generic generic parameter.
13005 Its DIE is a GNU extension. It shall have a
13006 DW_AT_name attribute to represent the name of the template template
13007 parameter, and a DW_AT_GNU_template_name attribute to represent the
13008 name of the template template argument. */
13009 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
13012 gcc_unreachable ();
13018 /* If PARM is a generic parameter pack, it means we are
13019 emitting debug info for a template argument pack element.
13020 In other terms, ARG is a template argument pack element.
13021 In that case, we don't emit any DW_AT_name attribute for
13025 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
13027 add_AT_string (tmpl_die
, DW_AT_name
, name
);
13030 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
13032 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
13033 TMPL_DIE should have a child DW_AT_type attribute that is set
13034 to the type of the argument to PARM, which is ARG.
13035 If PARM is a type generic parameter, TMPL_DIE should have a
13036 child DW_AT_type that is set to ARG. */
13037 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
13038 add_type_attribute (tmpl_die
, tmpl_type
, 0,
13039 TREE_THIS_VOLATILE (tmpl_type
),
13044 /* So TMPL_DIE is a DIE representing a
13045 a generic generic template parameter, a.k.a template template
13046 parameter in C++ and arg is a template. */
13048 /* The DW_AT_GNU_template_name attribute of the DIE must be set
13049 to the name of the argument. */
13050 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
13052 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
13055 if (TREE_CODE (parm
) == PARM_DECL
)
13056 /* So PARM is a non-type generic parameter.
13057 DWARF3 5.6.8 says we must set a DW_AT_const_value child
13058 attribute of TMPL_DIE which value represents the value
13060 We must be careful here:
13061 The value of ARG might reference some function decls.
13062 We might currently be emitting debug info for a generic
13063 type and types are emitted before function decls, we don't
13064 know if the function decls referenced by ARG will actually be
13065 emitted after cgraph computations.
13066 So must defer the generation of the DW_AT_const_value to
13067 after cgraph is ready. */
13068 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
13074 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
13075 PARM_PACK must be a template parameter pack. The returned DIE
13076 will be child DIE of PARENT_DIE. */
13079 template_parameter_pack_die (tree parm_pack
,
13080 tree parm_pack_args
,
13081 dw_die_ref parent_die
)
13086 gcc_assert (parent_die
&& parm_pack
);
13088 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
13089 add_name_and_src_coords_attributes (die
, parm_pack
);
13090 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
13091 generic_parameter_die (parm_pack
,
13092 TREE_VEC_ELT (parm_pack_args
, j
),
13093 false /* Don't emit DW_AT_name */,
13098 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
13099 an enumerated type. */
13102 type_is_enum (const_tree type
)
13104 return TREE_CODE (type
) == ENUMERAL_TYPE
;
13107 /* Return the DBX register number described by a given RTL node. */
13109 static unsigned int
13110 dbx_reg_number (const_rtx rtl
)
13112 unsigned regno
= REGNO (rtl
);
13114 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
13116 #ifdef LEAF_REG_REMAP
13117 if (current_function_uses_only_leaf_regs
)
13119 int leaf_reg
= LEAF_REG_REMAP (regno
);
13120 if (leaf_reg
!= -1)
13121 regno
= (unsigned) leaf_reg
;
13125 return DBX_REGISTER_NUMBER (regno
);
13128 /* Optionally add a DW_OP_piece term to a location description expression.
13129 DW_OP_piece is only added if the location description expression already
13130 doesn't end with DW_OP_piece. */
13133 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
13135 dw_loc_descr_ref loc
;
13137 if (*list_head
!= NULL
)
13139 /* Find the end of the chain. */
13140 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
13143 if (loc
->dw_loc_opc
!= DW_OP_piece
)
13144 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
13148 /* Return a location descriptor that designates a machine register or
13149 zero if there is none. */
13151 static dw_loc_descr_ref
13152 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
13156 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
13159 /* We only use "frame base" when we're sure we're talking about the
13160 post-prologue local stack frame. We do this by *not* running
13161 register elimination until this point, and recognizing the special
13162 argument pointer and soft frame pointer rtx's.
13163 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13164 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
13165 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
13167 dw_loc_descr_ref result
= NULL
;
13169 if (dwarf_version
>= 4 || !dwarf_strict
)
13171 result
= mem_loc_descriptor (rtl
, VOIDmode
, initialized
);
13173 add_loc_descr (&result
,
13174 new_loc_descr (DW_OP_stack_value
, 0, 0));
13179 regs
= targetm
.dwarf_register_span (rtl
);
13181 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
13182 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
13184 return one_reg_loc_descriptor (dbx_reg_number (rtl
), initialized
);
13187 /* Return a location descriptor that designates a machine register for
13188 a given hard register number. */
13190 static dw_loc_descr_ref
13191 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
13193 dw_loc_descr_ref reg_loc_descr
;
13197 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
13199 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
13201 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13202 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13204 return reg_loc_descr
;
13207 /* Given an RTL of a register, return a location descriptor that
13208 designates a value that spans more than one register. */
13210 static dw_loc_descr_ref
13211 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
13212 enum var_init_status initialized
)
13214 int nregs
, size
, i
;
13216 dw_loc_descr_ref loc_result
= NULL
;
13219 #ifdef LEAF_REG_REMAP
13220 if (current_function_uses_only_leaf_regs
)
13222 int leaf_reg
= LEAF_REG_REMAP (reg
);
13223 if (leaf_reg
!= -1)
13224 reg
= (unsigned) leaf_reg
;
13227 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
13228 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
13230 /* Simple, contiguous registers. */
13231 if (regs
== NULL_RTX
)
13233 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
13238 dw_loc_descr_ref t
;
13240 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
13241 VAR_INIT_STATUS_INITIALIZED
);
13242 add_loc_descr (&loc_result
, t
);
13243 add_loc_descr_op_piece (&loc_result
, size
);
13249 /* Now onto stupid register sets in non contiguous locations. */
13251 gcc_assert (GET_CODE (regs
) == PARALLEL
);
13253 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
13256 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
13258 dw_loc_descr_ref t
;
13260 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
13261 VAR_INIT_STATUS_INITIALIZED
);
13262 add_loc_descr (&loc_result
, t
);
13263 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
13264 add_loc_descr_op_piece (&loc_result
, size
);
13267 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13268 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13272 /* Return a location descriptor that designates a constant. */
13274 static dw_loc_descr_ref
13275 int_loc_descriptor (HOST_WIDE_INT i
)
13277 enum dwarf_location_atom op
;
13279 /* Pick the smallest representation of a constant, rather than just
13280 defaulting to the LEB encoding. */
13284 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
13285 else if (i
<= 0xff)
13286 op
= DW_OP_const1u
;
13287 else if (i
<= 0xffff)
13288 op
= DW_OP_const2u
;
13289 else if (HOST_BITS_PER_WIDE_INT
== 32
13290 || i
<= 0xffffffff)
13291 op
= DW_OP_const4u
;
13298 op
= DW_OP_const1s
;
13299 else if (i
>= -0x8000)
13300 op
= DW_OP_const2s
;
13301 else if (HOST_BITS_PER_WIDE_INT
== 32
13302 || i
>= -0x80000000)
13303 op
= DW_OP_const4s
;
13308 return new_loc_descr (op
, i
, 0);
13311 /* Return loc description representing "address" of integer value.
13312 This can appear only as toplevel expression. */
13314 static dw_loc_descr_ref
13315 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
13318 dw_loc_descr_ref loc_result
= NULL
;
13320 if (!(dwarf_version
>= 4 || !dwarf_strict
))
13327 else if (i
<= 0xff)
13329 else if (i
<= 0xffff)
13331 else if (HOST_BITS_PER_WIDE_INT
== 32
13332 || i
<= 0xffffffff)
13335 litsize
= 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
13341 else if (i
>= -0x8000)
13343 else if (HOST_BITS_PER_WIDE_INT
== 32
13344 || i
>= -0x80000000)
13347 litsize
= 1 + size_of_sleb128 (i
);
13349 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13350 is more compact. For DW_OP_stack_value we need:
13351 litsize + 1 (DW_OP_stack_value)
13352 and for DW_OP_implicit_value:
13353 1 (DW_OP_implicit_value) + 1 (length) + size. */
13354 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
13356 loc_result
= int_loc_descriptor (i
);
13357 add_loc_descr (&loc_result
,
13358 new_loc_descr (DW_OP_stack_value
, 0, 0));
13362 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13364 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13365 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
13369 /* Return a location descriptor that designates a base+offset location. */
13371 static dw_loc_descr_ref
13372 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
13373 enum var_init_status initialized
)
13375 unsigned int regno
;
13376 dw_loc_descr_ref result
;
13377 dw_fde_ref fde
= current_fde ();
13379 /* We only use "frame base" when we're sure we're talking about the
13380 post-prologue local stack frame. We do this by *not* running
13381 register elimination until this point, and recognizing the special
13382 argument pointer and soft frame pointer rtx's. */
13383 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
13385 rtx elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
13389 if (GET_CODE (elim
) == PLUS
)
13391 offset
+= INTVAL (XEXP (elim
, 1));
13392 elim
= XEXP (elim
, 0);
13394 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13395 && (elim
== hard_frame_pointer_rtx
13396 || elim
== stack_pointer_rtx
))
13397 || elim
== (frame_pointer_needed
13398 ? hard_frame_pointer_rtx
13399 : stack_pointer_rtx
));
13401 /* If drap register is used to align stack, use frame
13402 pointer + offset to access stack variables. If stack
13403 is aligned without drap, use stack pointer + offset to
13404 access stack variables. */
13405 if (crtl
->stack_realign_tried
13406 && reg
== frame_pointer_rtx
)
13409 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
13410 ? HARD_FRAME_POINTER_REGNUM
13412 return new_reg_loc_descr (base_reg
, offset
);
13415 offset
+= frame_pointer_fb_offset
;
13416 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
13421 && (fde
->drap_reg
== REGNO (reg
)
13422 || fde
->vdrap_reg
== REGNO (reg
)))
13424 /* Use cfa+offset to represent the location of arguments passed
13425 on the stack when drap is used to align stack.
13426 Only do this when not optimizing, for optimized code var-tracking
13427 is supposed to track where the arguments live and the register
13428 used as vdrap or drap in some spot might be used for something
13429 else in other part of the routine. */
13430 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
13433 regno
= dbx_reg_number (reg
);
13435 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
13438 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
13440 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13441 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13446 /* Return true if this RTL expression describes a base+offset calculation. */
13449 is_based_loc (const_rtx rtl
)
13451 return (GET_CODE (rtl
) == PLUS
13452 && ((REG_P (XEXP (rtl
, 0))
13453 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
13454 && CONST_INT_P (XEXP (rtl
, 1)))));
13457 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13460 static dw_loc_descr_ref
13461 tls_mem_loc_descriptor (rtx mem
)
13464 dw_loc_descr_ref loc_result
;
13466 if (MEM_EXPR (mem
) == NULL_TREE
|| MEM_OFFSET (mem
) == NULL_RTX
)
13469 base
= get_base_address (MEM_EXPR (mem
));
13471 || TREE_CODE (base
) != VAR_DECL
13472 || !DECL_THREAD_LOCAL_P (base
))
13475 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
13476 if (loc_result
== NULL
)
13479 if (INTVAL (MEM_OFFSET (mem
)))
13480 loc_descr_plus_const (&loc_result
, INTVAL (MEM_OFFSET (mem
)));
13485 /* Output debug info about reason why we failed to expand expression as dwarf
13489 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
13491 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
13493 fprintf (dump_file
, "Failed to expand as dwarf: ");
13495 print_generic_expr (dump_file
, expr
, dump_flags
);
13498 fprintf (dump_file
, "\n");
13499 print_rtl (dump_file
, rtl
);
13501 fprintf (dump_file
, "\nReason: %s\n", reason
);
13505 /* Helper function for const_ok_for_output, called either directly
13506 or via for_each_rtx. */
13509 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
13513 if (GET_CODE (rtl
) == UNSPEC
)
13515 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13516 we can't express it in the debug info. */
13517 #ifdef ENABLE_CHECKING
13518 /* Don't complain about TLS UNSPECs, those are just too hard to
13520 if (XVECLEN (rtl
, 0) != 1
13521 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
13522 || SYMBOL_REF_DECL (XVECEXP (rtl
, 0, 0)) == NULL
13523 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl
, 0, 0))) != VAR_DECL
13524 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl
, 0, 0))))
13525 inform (current_function_decl
13526 ? DECL_SOURCE_LOCATION (current_function_decl
)
13527 : UNKNOWN_LOCATION
,
13528 #if NUM_UNSPEC_VALUES > 0
13529 "non-delegitimized UNSPEC %s (%d) found in variable location",
13530 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
13531 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
13534 "non-delegitimized UNSPEC %d found in variable location",
13538 expansion_failed (NULL_TREE
, rtl
,
13539 "UNSPEC hasn't been delegitimized.\n");
13543 if (GET_CODE (rtl
) != SYMBOL_REF
)
13546 if (CONSTANT_POOL_ADDRESS_P (rtl
))
13549 get_pool_constant_mark (rtl
, &marked
);
13550 /* If all references to this pool constant were optimized away,
13551 it was not output and thus we can't represent it. */
13554 expansion_failed (NULL_TREE
, rtl
,
13555 "Constant was removed from constant pool.\n");
13560 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
13563 /* Avoid references to external symbols in debug info, on several targets
13564 the linker might even refuse to link when linking a shared library,
13565 and in many other cases the relocations for .debug_info/.debug_loc are
13566 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13567 to be defined within the same shared library or executable are fine. */
13568 if (SYMBOL_REF_EXTERNAL_P (rtl
))
13570 tree decl
= SYMBOL_REF_DECL (rtl
);
13572 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
13574 expansion_failed (NULL_TREE
, rtl
,
13575 "Symbol not defined in current TU.\n");
13583 /* Return true if constant RTL can be emitted in DW_OP_addr or
13584 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13585 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13588 const_ok_for_output (rtx rtl
)
13590 if (GET_CODE (rtl
) == SYMBOL_REF
)
13591 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
13593 if (GET_CODE (rtl
) == CONST
)
13594 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
13599 /* The following routine converts the RTL for a variable or parameter
13600 (resident in memory) into an equivalent Dwarf representation of a
13601 mechanism for getting the address of that same variable onto the top of a
13602 hypothetical "address evaluation" stack.
13604 When creating memory location descriptors, we are effectively transforming
13605 the RTL for a memory-resident object into its Dwarf postfix expression
13606 equivalent. This routine recursively descends an RTL tree, turning
13607 it into Dwarf postfix code as it goes.
13609 MODE is the mode of the memory reference, needed to handle some
13610 autoincrement addressing modes.
13612 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
13613 location list for RTL.
13615 Return 0 if we can't represent the location. */
13617 static dw_loc_descr_ref
13618 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
13619 enum var_init_status initialized
)
13621 dw_loc_descr_ref mem_loc_result
= NULL
;
13622 enum dwarf_location_atom op
;
13623 dw_loc_descr_ref op0
, op1
;
13625 /* Note that for a dynamically sized array, the location we will generate a
13626 description of here will be the lowest numbered location which is
13627 actually within the array. That's *not* necessarily the same as the
13628 zeroth element of the array. */
13630 rtl
= targetm
.delegitimize_address (rtl
);
13632 switch (GET_CODE (rtl
))
13637 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13640 /* The case of a subreg may arise when we have a local (register)
13641 variable or a formal (register) parameter which doesn't quite fill
13642 up an entire register. For now, just assume that it is
13643 legitimate to make the Dwarf info refer to the whole register which
13644 contains the given subreg. */
13645 if (!subreg_lowpart_p (rtl
))
13647 rtl
= SUBREG_REG (rtl
);
13648 if (GET_MODE_SIZE (GET_MODE (rtl
)) > DWARF2_ADDR_SIZE
)
13650 if (GET_MODE_CLASS (GET_MODE (rtl
)) != MODE_INT
)
13652 mem_loc_result
= mem_loc_descriptor (rtl
, mode
, initialized
);
13656 /* Whenever a register number forms a part of the description of the
13657 method for calculating the (dynamic) address of a memory resident
13658 object, DWARF rules require the register number be referred to as
13659 a "base register". This distinction is not based in any way upon
13660 what category of register the hardware believes the given register
13661 belongs to. This is strictly DWARF terminology we're dealing with
13662 here. Note that in cases where the location of a memory-resident
13663 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
13664 OP_CONST (0)) the actual DWARF location descriptor that we generate
13665 may just be OP_BASEREG (basereg). This may look deceptively like
13666 the object in question was allocated to a register (rather than in
13667 memory) so DWARF consumers need to be aware of the subtle
13668 distinction between OP_REG and OP_BASEREG. */
13669 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
13670 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
13671 else if (stack_realign_drap
13673 && crtl
->args
.internal_arg_pointer
== rtl
13674 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
13676 /* If RTL is internal_arg_pointer, which has been optimized
13677 out, use DRAP instead. */
13678 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
13679 VAR_INIT_STATUS_INITIALIZED
);
13685 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13686 VAR_INIT_STATUS_INITIALIZED
);
13691 int shift
= DWARF2_ADDR_SIZE
13692 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
13693 shift
*= BITS_PER_UNIT
;
13694 if (GET_CODE (rtl
) == SIGN_EXTEND
)
13698 mem_loc_result
= op0
;
13699 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
13700 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
13701 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
13702 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13707 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
13708 VAR_INIT_STATUS_INITIALIZED
);
13709 if (mem_loc_result
== NULL
)
13710 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
13711 if (mem_loc_result
!= 0)
13713 if (GET_MODE_SIZE (GET_MODE (rtl
)) > DWARF2_ADDR_SIZE
)
13715 expansion_failed (NULL_TREE
, rtl
, "DWARF address size mismatch");
13718 else if (GET_MODE_SIZE (GET_MODE (rtl
)) == DWARF2_ADDR_SIZE
)
13719 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
13721 add_loc_descr (&mem_loc_result
,
13722 new_loc_descr (DW_OP_deref_size
,
13723 GET_MODE_SIZE (GET_MODE (rtl
)), 0));
13727 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13728 if (new_rtl
!= rtl
)
13729 return mem_loc_descriptor (new_rtl
, mode
, initialized
);
13734 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, initialized
);
13737 /* Some ports can transform a symbol ref into a label ref, because
13738 the symbol ref is too far away and has to be dumped into a constant
13742 if (GET_CODE (rtl
) == SYMBOL_REF
13743 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
13745 dw_loc_descr_ref temp
;
13747 /* If this is not defined, we have no way to emit the data. */
13748 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
13751 /* We used to emit DW_OP_addr here, but that's wrong, since
13752 DW_OP_addr should be relocated by the debug info consumer,
13753 while DW_OP_GNU_push_tls_address operand should not. */
13754 temp
= new_loc_descr (DWARF2_ADDR_SIZE
== 4
13755 ? DW_OP_const4u
: DW_OP_const8u
, 0, 0);
13756 temp
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
13757 temp
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
13758 temp
->dtprel
= true;
13760 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
13761 add_loc_descr (&mem_loc_result
, temp
);
13766 if (!const_ok_for_output (rtl
))
13770 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
13771 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
13772 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
13773 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
13779 case DEBUG_IMPLICIT_PTR
:
13780 expansion_failed (NULL_TREE
, rtl
,
13781 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
13787 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
13788 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13789 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
13790 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
13791 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl
)),
13792 VAR_INIT_STATUS_INITIALIZED
);
13793 else if (MEM_P (ENTRY_VALUE_EXP (rtl
)) && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
13795 dw_loc_descr_ref ref
13796 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), GET_MODE (rtl
),
13797 VAR_INIT_STATUS_INITIALIZED
);
13798 if (ref
== NULL
|| ref
->dw_loc_opc
== DW_OP_fbreg
)
13800 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= ref
;
13803 gcc_unreachable ();
13804 return mem_loc_result
;
13807 /* Extract the PLUS expression nested inside and fall into
13808 PLUS code below. */
13809 rtl
= XEXP (rtl
, 1);
13814 /* Turn these into a PLUS expression and fall into the PLUS code
13816 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
13817 GEN_INT (GET_CODE (rtl
) == PRE_INC
13818 ? GET_MODE_UNIT_SIZE (mode
)
13819 : -GET_MODE_UNIT_SIZE (mode
)));
13821 /* ... fall through ... */
13825 if (is_based_loc (rtl
))
13826 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
13827 INTVAL (XEXP (rtl
, 1)),
13828 VAR_INIT_STATUS_INITIALIZED
);
13831 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13832 VAR_INIT_STATUS_INITIALIZED
);
13833 if (mem_loc_result
== 0)
13836 if (CONST_INT_P (XEXP (rtl
, 1)))
13837 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
13840 dw_loc_descr_ref mem_loc_result2
13841 = mem_loc_descriptor (XEXP (rtl
, 1), mode
,
13842 VAR_INIT_STATUS_INITIALIZED
);
13843 if (mem_loc_result2
== 0)
13845 add_loc_descr (&mem_loc_result
, mem_loc_result2
);
13846 add_loc_descr (&mem_loc_result
,
13847 new_loc_descr (DW_OP_plus
, 0, 0));
13852 /* If a pseudo-reg is optimized away, it is possible for it to
13853 be replaced with a MEM containing a multiply or shift. */
13895 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13896 VAR_INIT_STATUS_INITIALIZED
);
13897 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
13898 VAR_INIT_STATUS_INITIALIZED
);
13900 if (op0
== 0 || op1
== 0)
13903 mem_loc_result
= op0
;
13904 add_loc_descr (&mem_loc_result
, op1
);
13905 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13909 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13910 VAR_INIT_STATUS_INITIALIZED
);
13911 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
13912 VAR_INIT_STATUS_INITIALIZED
);
13914 if (op0
== 0 || op1
== 0)
13917 mem_loc_result
= op0
;
13918 add_loc_descr (&mem_loc_result
, op1
);
13919 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13920 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13921 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
13922 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
13923 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
13939 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13940 VAR_INIT_STATUS_INITIALIZED
);
13945 mem_loc_result
= op0
;
13946 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13950 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
13978 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) > DWARF2_ADDR_SIZE
13979 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 1))) > DWARF2_ADDR_SIZE
)
13983 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
13985 if (op_mode
== VOIDmode
)
13986 op_mode
= GET_MODE (XEXP (rtl
, 1));
13987 if (op_mode
!= VOIDmode
&& GET_MODE_CLASS (op_mode
) != MODE_INT
)
13990 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13991 VAR_INIT_STATUS_INITIALIZED
);
13992 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
13993 VAR_INIT_STATUS_INITIALIZED
);
13995 if (op0
== 0 || op1
== 0)
13998 if (op_mode
!= VOIDmode
13999 && GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
14001 int shift
= DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
);
14002 shift
*= BITS_PER_UNIT
;
14003 /* For eq/ne, if the operands are known to be zero-extended,
14004 there is no need to do the fancy shifting up. */
14005 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
14007 dw_loc_descr_ref last0
, last1
;
14009 last0
->dw_loc_next
!= NULL
;
14010 last0
= last0
->dw_loc_next
)
14013 last1
->dw_loc_next
!= NULL
;
14014 last1
= last1
->dw_loc_next
)
14016 /* deref_size zero extends, and for constants we can check
14017 whether they are zero extended or not. */
14018 if (((last0
->dw_loc_opc
== DW_OP_deref_size
14019 && last0
->dw_loc_oprnd1
.v
.val_int
14020 <= GET_MODE_SIZE (op_mode
))
14021 || (CONST_INT_P (XEXP (rtl
, 0))
14022 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
14023 == (INTVAL (XEXP (rtl
, 0))
14024 & GET_MODE_MASK (op_mode
))))
14025 && ((last1
->dw_loc_opc
== DW_OP_deref_size
14026 && last1
->dw_loc_oprnd1
.v
.val_int
14027 <= GET_MODE_SIZE (op_mode
))
14028 || (CONST_INT_P (XEXP (rtl
, 1))
14029 && (unsigned HOST_WIDE_INT
)
14030 INTVAL (XEXP (rtl
, 1))
14031 == (INTVAL (XEXP (rtl
, 1))
14032 & GET_MODE_MASK (op_mode
)))))
14035 add_loc_descr (&op0
, int_loc_descriptor (shift
));
14036 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
14037 if (CONST_INT_P (XEXP (rtl
, 1)))
14038 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
14041 add_loc_descr (&op1
, int_loc_descriptor (shift
));
14042 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
14048 mem_loc_result
= op0
;
14049 add_loc_descr (&mem_loc_result
, op1
);
14050 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14051 if (STORE_FLAG_VALUE
!= 1)
14053 add_loc_descr (&mem_loc_result
,
14054 int_loc_descriptor (STORE_FLAG_VALUE
));
14055 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
14076 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) > DWARF2_ADDR_SIZE
14077 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 1))) > DWARF2_ADDR_SIZE
)
14081 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
14083 if (op_mode
== VOIDmode
)
14084 op_mode
= GET_MODE (XEXP (rtl
, 1));
14085 if (op_mode
!= VOIDmode
&& GET_MODE_CLASS (op_mode
) != MODE_INT
)
14088 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
14089 VAR_INIT_STATUS_INITIALIZED
);
14090 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
14091 VAR_INIT_STATUS_INITIALIZED
);
14093 if (op0
== 0 || op1
== 0)
14096 if (op_mode
!= VOIDmode
14097 && GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
14099 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
14100 dw_loc_descr_ref last0
, last1
;
14102 last0
->dw_loc_next
!= NULL
;
14103 last0
= last0
->dw_loc_next
)
14106 last1
->dw_loc_next
!= NULL
;
14107 last1
= last1
->dw_loc_next
)
14109 if (CONST_INT_P (XEXP (rtl
, 0)))
14110 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
14111 /* deref_size zero extends, so no need to mask it again. */
14112 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
14113 || last0
->dw_loc_oprnd1
.v
.val_int
14114 > GET_MODE_SIZE (op_mode
))
14116 add_loc_descr (&op0
, int_loc_descriptor (mask
));
14117 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14119 if (CONST_INT_P (XEXP (rtl
, 1)))
14120 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
14121 /* deref_size zero extends, so no need to mask it again. */
14122 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
14123 || last1
->dw_loc_oprnd1
.v
.val_int
14124 > GET_MODE_SIZE (op_mode
))
14126 add_loc_descr (&op1
, int_loc_descriptor (mask
));
14127 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
14132 HOST_WIDE_INT bias
= 1;
14133 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
14134 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14135 if (CONST_INT_P (XEXP (rtl
, 1)))
14136 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
14137 + INTVAL (XEXP (rtl
, 1)));
14139 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
14149 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) != MODE_INT
14150 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) > DWARF2_ADDR_SIZE
14151 || GET_MODE (XEXP (rtl
, 0)) != GET_MODE (XEXP (rtl
, 1)))
14154 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
14155 VAR_INIT_STATUS_INITIALIZED
);
14156 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
14157 VAR_INIT_STATUS_INITIALIZED
);
14159 if (op0
== 0 || op1
== 0)
14162 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
14163 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
14164 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
14165 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
14167 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) < DWARF2_ADDR_SIZE
)
14169 HOST_WIDE_INT mask
= GET_MODE_MASK (GET_MODE (XEXP (rtl
, 0)));
14170 add_loc_descr (&op0
, int_loc_descriptor (mask
));
14171 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14172 add_loc_descr (&op1
, int_loc_descriptor (mask
));
14173 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
14177 HOST_WIDE_INT bias
= 1;
14178 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
14179 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14180 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14183 else if (GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) < DWARF2_ADDR_SIZE
)
14185 int shift
= DWARF2_ADDR_SIZE
14186 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
14187 shift
*= BITS_PER_UNIT
;
14188 add_loc_descr (&op0
, int_loc_descriptor (shift
));
14189 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
14190 add_loc_descr (&op1
, int_loc_descriptor (shift
));
14191 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
14194 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
14198 mem_loc_result
= op0
;
14199 add_loc_descr (&mem_loc_result
, op1
);
14200 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14202 dw_loc_descr_ref bra_node
, drop_node
;
14204 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14205 add_loc_descr (&mem_loc_result
, bra_node
);
14206 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
14207 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
14208 add_loc_descr (&mem_loc_result
, drop_node
);
14209 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14210 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
14216 if (CONST_INT_P (XEXP (rtl
, 1))
14217 && CONST_INT_P (XEXP (rtl
, 2))
14218 && ((unsigned) INTVAL (XEXP (rtl
, 1))
14219 + (unsigned) INTVAL (XEXP (rtl
, 2))
14220 <= GET_MODE_BITSIZE (GET_MODE (rtl
)))
14221 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
14222 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
14225 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
14226 VAR_INIT_STATUS_INITIALIZED
);
14229 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
14233 mem_loc_result
= op0
;
14234 size
= INTVAL (XEXP (rtl
, 1));
14235 shift
= INTVAL (XEXP (rtl
, 2));
14236 if (BITS_BIG_ENDIAN
)
14237 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
14239 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
14241 add_loc_descr (&mem_loc_result
,
14242 int_loc_descriptor (DWARF2_ADDR_SIZE
14244 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
14246 if (size
!= (int) DWARF2_ADDR_SIZE
)
14248 add_loc_descr (&mem_loc_result
,
14249 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
14250 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14257 dw_loc_descr_ref op2
, bra_node
, drop_node
;
14258 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
14259 VAR_INIT_STATUS_INITIALIZED
);
14260 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
14261 VAR_INIT_STATUS_INITIALIZED
);
14262 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
,
14263 VAR_INIT_STATUS_INITIALIZED
);
14264 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
14267 mem_loc_result
= op1
;
14268 add_loc_descr (&mem_loc_result
, op2
);
14269 add_loc_descr (&mem_loc_result
, op0
);
14270 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14271 add_loc_descr (&mem_loc_result
, bra_node
);
14272 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
14273 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
14274 add_loc_descr (&mem_loc_result
, drop_node
);
14275 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14276 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
14284 /* In theory, we could implement the above. */
14285 /* DWARF cannot represent the unsigned compare operations
14312 case FLOAT_TRUNCATE
:
14314 case UNSIGNED_FLOAT
:
14317 case FRACT_CONVERT
:
14318 case UNSIGNED_FRACT_CONVERT
:
14320 case UNSIGNED_SAT_FRACT
:
14332 case VEC_DUPLICATE
:
14335 /* If delegitimize_address couldn't do anything with the UNSPEC, we
14336 can't express it in the debug info. This can happen e.g. with some
14341 resolve_one_addr (&rtl
, NULL
);
14345 #ifdef ENABLE_CHECKING
14346 print_rtl (stderr
, rtl
);
14347 gcc_unreachable ();
14353 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14354 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14356 return mem_loc_result
;
14359 /* Return a descriptor that describes the concatenation of two locations.
14360 This is typically a complex variable. */
14362 static dw_loc_descr_ref
14363 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
14365 dw_loc_descr_ref cc_loc_result
= NULL
;
14366 dw_loc_descr_ref x0_ref
14367 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14368 dw_loc_descr_ref x1_ref
14369 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14371 if (x0_ref
== 0 || x1_ref
== 0)
14374 cc_loc_result
= x0_ref
;
14375 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
14377 add_loc_descr (&cc_loc_result
, x1_ref
);
14378 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
14380 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14381 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14383 return cc_loc_result
;
14386 /* Return a descriptor that describes the concatenation of N
14389 static dw_loc_descr_ref
14390 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
14393 dw_loc_descr_ref cc_loc_result
= NULL
;
14394 unsigned int n
= XVECLEN (concatn
, 0);
14396 for (i
= 0; i
< n
; ++i
)
14398 dw_loc_descr_ref ref
;
14399 rtx x
= XVECEXP (concatn
, 0, i
);
14401 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14405 add_loc_descr (&cc_loc_result
, ref
);
14406 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
14409 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14410 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14412 return cc_loc_result
;
14415 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
14416 for DEBUG_IMPLICIT_PTR RTL. */
14418 static dw_loc_descr_ref
14419 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
14421 dw_loc_descr_ref ret
;
14426 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
14427 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
14428 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
14429 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
14430 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
14431 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
14434 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14435 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
14436 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14440 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
14441 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
14446 /* Output a proper Dwarf location descriptor for a variable or parameter
14447 which is either allocated in a register or in a memory location. For a
14448 register, we just generate an OP_REG and the register number. For a
14449 memory location we provide a Dwarf postfix expression describing how to
14450 generate the (dynamic) address of the object onto the address stack.
14452 MODE is mode of the decl if this loc_descriptor is going to be used in
14453 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
14454 allowed, VOIDmode otherwise.
14456 If we don't know how to describe it, return 0. */
14458 static dw_loc_descr_ref
14459 loc_descriptor (rtx rtl
, enum machine_mode mode
,
14460 enum var_init_status initialized
)
14462 dw_loc_descr_ref loc_result
= NULL
;
14464 switch (GET_CODE (rtl
))
14467 /* The case of a subreg may arise when we have a local (register)
14468 variable or a formal (register) parameter which doesn't quite fill
14469 up an entire register. For now, just assume that it is
14470 legitimate to make the Dwarf info refer to the whole register which
14471 contains the given subreg. */
14472 loc_result
= loc_descriptor (SUBREG_REG (rtl
), mode
, initialized
);
14476 loc_result
= reg_loc_descriptor (rtl
, initialized
);
14480 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
14482 if (loc_result
== NULL
)
14483 loc_result
= tls_mem_loc_descriptor (rtl
);
14484 if (loc_result
== NULL
)
14486 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
14487 if (new_rtl
!= rtl
)
14488 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
14493 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
14498 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
14503 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
14505 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
14506 if (GET_CODE (loc
) == EXPR_LIST
)
14507 loc
= XEXP (loc
, 0);
14508 loc_result
= loc_descriptor (loc
, mode
, initialized
);
14512 rtl
= XEXP (rtl
, 1);
14517 rtvec par_elems
= XVEC (rtl
, 0);
14518 int num_elem
= GET_NUM_ELEM (par_elems
);
14519 enum machine_mode mode
;
14522 /* Create the first one, so we have something to add to. */
14523 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
14524 VOIDmode
, initialized
);
14525 if (loc_result
== NULL
)
14527 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
14528 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
14529 for (i
= 1; i
< num_elem
; i
++)
14531 dw_loc_descr_ref temp
;
14533 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
14534 VOIDmode
, initialized
);
14537 add_loc_descr (&loc_result
, temp
);
14538 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
14539 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
14545 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
14546 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
14551 if (mode
== VOIDmode
)
14552 mode
= GET_MODE (rtl
);
14554 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
14556 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
14558 /* Note that a CONST_DOUBLE rtx could represent either an integer
14559 or a floating-point constant. A CONST_DOUBLE is used whenever
14560 the constant requires more than one word in order to be
14561 adequately represented. We output CONST_DOUBLEs as blocks. */
14562 loc_result
= new_loc_descr (DW_OP_implicit_value
,
14563 GET_MODE_SIZE (mode
), 0);
14564 if (SCALAR_FLOAT_MODE_P (mode
))
14566 unsigned int length
= GET_MODE_SIZE (mode
);
14567 unsigned char *array
14568 = (unsigned char*) ggc_alloc_atomic (length
);
14570 insert_float (rtl
, array
);
14571 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
14572 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
14573 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
14574 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
14578 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
14579 loc_result
->dw_loc_oprnd2
.v
.val_double
14580 = rtx_to_double_int (rtl
);
14586 if (mode
== VOIDmode
)
14587 mode
= GET_MODE (rtl
);
14589 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
14591 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
14592 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
14593 unsigned char *array
= (unsigned char *)
14594 ggc_alloc_atomic (length
* elt_size
);
14598 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
14599 switch (GET_MODE_CLASS (mode
))
14601 case MODE_VECTOR_INT
:
14602 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14604 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14605 double_int val
= rtx_to_double_int (elt
);
14607 if (elt_size
<= sizeof (HOST_WIDE_INT
))
14608 insert_int (double_int_to_shwi (val
), elt_size
, p
);
14611 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
14612 insert_double (val
, p
);
14617 case MODE_VECTOR_FLOAT
:
14618 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14620 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14621 insert_float (elt
, p
);
14626 gcc_unreachable ();
14629 loc_result
= new_loc_descr (DW_OP_implicit_value
,
14630 length
* elt_size
, 0);
14631 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
14632 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
14633 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
14634 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
14639 if (mode
== VOIDmode
14640 || GET_CODE (XEXP (rtl
, 0)) == CONST_INT
14641 || GET_CODE (XEXP (rtl
, 0)) == CONST_DOUBLE
14642 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
14644 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
14649 if (!const_ok_for_output (rtl
))
14652 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
14653 && (dwarf_version
>= 4 || !dwarf_strict
))
14655 loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
14656 loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
14657 loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
14658 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14659 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
14663 case DEBUG_IMPLICIT_PTR
:
14664 loc_result
= implicit_ptr_descriptor (rtl
, 0);
14668 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
14669 && CONST_INT_P (XEXP (rtl
, 1)))
14672 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
14677 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
14678 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
14679 && (dwarf_version
>= 4 || !dwarf_strict
))
14681 /* Value expression. */
14682 loc_result
= mem_loc_descriptor (rtl
, VOIDmode
, initialized
);
14684 add_loc_descr (&loc_result
,
14685 new_loc_descr (DW_OP_stack_value
, 0, 0));
14693 /* We need to figure out what section we should use as the base for the
14694 address ranges where a given location is valid.
14695 1. If this particular DECL has a section associated with it, use that.
14696 2. If this function has a section associated with it, use that.
14697 3. Otherwise, use the text section.
14698 XXX: If you split a variable across multiple sections, we won't notice. */
14700 static const char *
14701 secname_for_decl (const_tree decl
)
14703 const char *secname
;
14705 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
14707 tree sectree
= DECL_SECTION_NAME (decl
);
14708 secname
= TREE_STRING_POINTER (sectree
);
14710 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
14712 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
14713 secname
= TREE_STRING_POINTER (sectree
);
14715 else if (cfun
&& in_cold_section_p
)
14716 secname
= crtl
->subsections
.cold_section_label
;
14718 secname
= text_section_label
;
14723 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
14726 decl_by_reference_p (tree decl
)
14728 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
14729 || TREE_CODE (decl
) == VAR_DECL
)
14730 && DECL_BY_REFERENCE (decl
));
14733 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14736 static dw_loc_descr_ref
14737 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
14738 enum var_init_status initialized
)
14740 int have_address
= 0;
14741 dw_loc_descr_ref descr
;
14742 enum machine_mode mode
;
14744 if (want_address
!= 2)
14746 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
14748 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
14750 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
14751 if (GET_CODE (varloc
) == EXPR_LIST
)
14752 varloc
= XEXP (varloc
, 0);
14753 mode
= GET_MODE (varloc
);
14754 if (MEM_P (varloc
))
14756 rtx addr
= XEXP (varloc
, 0);
14757 descr
= mem_loc_descriptor (addr
, mode
, initialized
);
14762 rtx x
= avoid_constant_pool_reference (varloc
);
14764 descr
= mem_loc_descriptor (x
, mode
, initialized
);
14768 descr
= mem_loc_descriptor (varloc
, mode
, initialized
);
14775 if (GET_CODE (varloc
) == VAR_LOCATION
)
14776 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
14778 mode
= DECL_MODE (loc
);
14779 descr
= loc_descriptor (varloc
, mode
, initialized
);
14786 if (want_address
== 2 && !have_address
14787 && (dwarf_version
>= 4 || !dwarf_strict
))
14789 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14791 expansion_failed (loc
, NULL_RTX
,
14792 "DWARF address size mismatch");
14795 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14798 /* Show if we can't fill the request for an address. */
14799 if (want_address
&& !have_address
)
14801 expansion_failed (loc
, NULL_RTX
,
14802 "Want address and only have value");
14806 /* If we've got an address and don't want one, dereference. */
14807 if (!want_address
&& have_address
)
14809 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14810 enum dwarf_location_atom op
;
14812 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14814 expansion_failed (loc
, NULL_RTX
,
14815 "DWARF address size mismatch");
14818 else if (size
== DWARF2_ADDR_SIZE
)
14821 op
= DW_OP_deref_size
;
14823 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
14829 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14830 if it is not possible. */
14832 static dw_loc_descr_ref
14833 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
14835 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
14836 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
14837 else if (dwarf_version
>= 3 || !dwarf_strict
)
14838 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
14843 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14844 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14846 static dw_loc_descr_ref
14847 dw_sra_loc_expr (tree decl
, rtx loc
)
14850 unsigned int padsize
= 0;
14851 dw_loc_descr_ref descr
, *descr_tail
;
14852 unsigned HOST_WIDE_INT decl_size
;
14854 enum var_init_status initialized
;
14856 if (DECL_SIZE (decl
) == NULL
14857 || !host_integerp (DECL_SIZE (decl
), 1))
14860 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
14862 descr_tail
= &descr
;
14864 for (p
= loc
; p
; p
= XEXP (p
, 1))
14866 unsigned int bitsize
= decl_piece_bitsize (p
);
14867 rtx loc_note
= *decl_piece_varloc_ptr (p
);
14868 dw_loc_descr_ref cur_descr
;
14869 dw_loc_descr_ref
*tail
, last
= NULL
;
14870 unsigned int opsize
= 0;
14872 if (loc_note
== NULL_RTX
14873 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
14875 padsize
+= bitsize
;
14878 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
14879 varloc
= NOTE_VAR_LOCATION (loc_note
);
14880 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
14881 if (cur_descr
== NULL
)
14883 padsize
+= bitsize
;
14887 /* Check that cur_descr either doesn't use
14888 DW_OP_*piece operations, or their sum is equal
14889 to bitsize. Otherwise we can't embed it. */
14890 for (tail
= &cur_descr
; *tail
!= NULL
;
14891 tail
= &(*tail
)->dw_loc_next
)
14892 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
14894 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
14898 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
14900 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
14904 if (last
!= NULL
&& opsize
!= bitsize
)
14906 padsize
+= bitsize
;
14910 /* If there is a hole, add DW_OP_*piece after empty DWARF
14911 expression, which means that those bits are optimized out. */
14914 if (padsize
> decl_size
)
14916 decl_size
-= padsize
;
14917 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
14918 if (*descr_tail
== NULL
)
14920 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14923 *descr_tail
= cur_descr
;
14925 if (bitsize
> decl_size
)
14927 decl_size
-= bitsize
;
14930 HOST_WIDE_INT offset
= 0;
14931 if (GET_CODE (varloc
) == VAR_LOCATION
14932 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
14934 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
14935 if (GET_CODE (varloc
) == EXPR_LIST
)
14936 varloc
= XEXP (varloc
, 0);
14940 if (GET_CODE (varloc
) == CONST
14941 || GET_CODE (varloc
) == SIGN_EXTEND
14942 || GET_CODE (varloc
) == ZERO_EXTEND
)
14943 varloc
= XEXP (varloc
, 0);
14944 else if (GET_CODE (varloc
) == SUBREG
)
14945 varloc
= SUBREG_REG (varloc
);
14950 /* DW_OP_bit_size offset should be zero for register
14951 or implicit location descriptions and empty location
14952 descriptions, but for memory addresses needs big endian
14954 if (MEM_P (varloc
))
14956 unsigned HOST_WIDE_INT memsize
14957 = INTVAL (MEM_SIZE (varloc
)) * BITS_PER_UNIT
;
14958 if (memsize
!= bitsize
)
14960 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
14961 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
14963 if (memsize
< bitsize
)
14965 if (BITS_BIG_ENDIAN
)
14966 offset
= memsize
- bitsize
;
14970 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
14971 if (*descr_tail
== NULL
)
14973 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14977 /* If there were any non-empty expressions, add padding till the end of
14979 if (descr
!= NULL
&& decl_size
!= 0)
14981 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
14982 if (*descr_tail
== NULL
)
14988 /* Return the dwarf representation of the location list LOC_LIST of
14989 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
14992 static dw_loc_list_ref
14993 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
14995 const char *endname
, *secname
;
14997 enum var_init_status initialized
;
14998 struct var_loc_node
*node
;
14999 dw_loc_descr_ref descr
;
15000 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
15001 dw_loc_list_ref list
= NULL
;
15002 dw_loc_list_ref
*listp
= &list
;
15004 /* Now that we know what section we are using for a base,
15005 actually construct the list of locations.
15006 The first location information is what is passed to the
15007 function that creates the location list, and the remaining
15008 locations just get added on to that list.
15009 Note that we only know the start address for a location
15010 (IE location changes), so to build the range, we use
15011 the range [current location start, next location start].
15012 This means we have to special case the last node, and generate
15013 a range of [last location start, end of function label]. */
15015 secname
= secname_for_decl (decl
);
15017 for (node
= loc_list
->first
; node
; node
= node
->next
)
15018 if (GET_CODE (node
->loc
) == EXPR_LIST
15019 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
15021 if (GET_CODE (node
->loc
) == EXPR_LIST
)
15023 /* This requires DW_OP_{,bit_}piece, which is not usable
15024 inside DWARF expressions. */
15025 if (want_address
!= 2)
15027 descr
= dw_sra_loc_expr (decl
, node
->loc
);
15033 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
15034 varloc
= NOTE_VAR_LOCATION (node
->loc
);
15035 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
15039 bool range_across_switch
= false;
15040 /* If section switch happens in between node->label
15041 and node->next->label (or end of function) and
15042 we can't emit it as a single entry list,
15043 emit two ranges, first one ending at the end
15044 of first partition and second one starting at the
15045 beginning of second partition. */
15046 if (node
== loc_list
->last_before_switch
15047 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
15048 && current_function_decl
)
15050 endname
= current_fde ()->dw_fde_end
;
15051 range_across_switch
= true;
15053 /* The variable has a location between NODE->LABEL and
15054 NODE->NEXT->LABEL. */
15055 else if (node
->next
)
15056 endname
= node
->next
->label
;
15057 /* If the variable has a location at the last label
15058 it keeps its location until the end of function. */
15059 else if (!current_function_decl
)
15060 endname
= text_end_label
;
15063 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
15064 current_function_funcdef_no
);
15065 endname
= ggc_strdup (label_id
);
15068 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
15069 listp
= &(*listp
)->dw_loc_next
;
15071 if (range_across_switch
)
15073 if (GET_CODE (node
->loc
) == EXPR_LIST
)
15074 descr
= dw_sra_loc_expr (decl
, node
->loc
);
15077 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
15078 varloc
= NOTE_VAR_LOCATION (node
->loc
);
15079 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
15082 gcc_assert (descr
);
15083 /* The variable has a location between NODE->LABEL and
15084 NODE->NEXT->LABEL. */
15086 endname
= node
->next
->label
;
15088 endname
= current_fde ()->dw_fde_second_end
;
15089 *listp
= new_loc_list (descr
,
15090 current_fde ()->dw_fde_second_begin
,
15092 listp
= &(*listp
)->dw_loc_next
;
15097 /* Try to avoid the overhead of a location list emitting a location
15098 expression instead, but only if we didn't have more than one
15099 location entry in the first place. If some entries were not
15100 representable, we don't want to pretend a single entry that was
15101 applies to the entire scope in which the variable is
15103 if (list
&& loc_list
->first
->next
)
15109 /* Return if the loc_list has only single element and thus can be represented
15110 as location description. */
15113 single_element_loc_list_p (dw_loc_list_ref list
)
15115 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
15116 return !list
->ll_symbol
;
15119 /* To each location in list LIST add loc descr REF. */
15122 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
15124 dw_loc_descr_ref copy
;
15125 add_loc_descr (&list
->expr
, ref
);
15126 list
= list
->dw_loc_next
;
15129 copy
= ggc_alloc_dw_loc_descr_node ();
15130 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
15131 add_loc_descr (&list
->expr
, copy
);
15132 while (copy
->dw_loc_next
)
15134 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
15135 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
15136 copy
->dw_loc_next
= new_copy
;
15139 list
= list
->dw_loc_next
;
15143 /* Given two lists RET and LIST
15144 produce location list that is result of adding expression in LIST
15145 to expression in RET on each possition in program.
15146 Might be destructive on both RET and LIST.
15148 TODO: We handle only simple cases of RET or LIST having at most one
15149 element. General case would inolve sorting the lists in program order
15150 and merging them that will need some additional work.
15151 Adding that will improve quality of debug info especially for SRA-ed
15155 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
15164 if (!list
->dw_loc_next
)
15166 add_loc_descr_to_each (*ret
, list
->expr
);
15169 if (!(*ret
)->dw_loc_next
)
15171 add_loc_descr_to_each (list
, (*ret
)->expr
);
15175 expansion_failed (NULL_TREE
, NULL_RTX
,
15176 "Don't know how to merge two non-trivial"
15177 " location lists.\n");
15182 /* LOC is constant expression. Try a luck, look it up in constant
15183 pool and return its loc_descr of its address. */
15185 static dw_loc_descr_ref
15186 cst_pool_loc_descr (tree loc
)
15188 /* Get an RTL for this, if something has been emitted. */
15189 rtx rtl
= lookup_constant_def (loc
);
15190 enum machine_mode mode
;
15192 if (!rtl
|| !MEM_P (rtl
))
15197 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
15199 /* TODO: We might get more coverage if we was actually delaying expansion
15200 of all expressions till end of compilation when constant pools are fully
15202 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
15204 expansion_failed (loc
, NULL_RTX
,
15205 "CST value in contant pool but not marked.");
15208 mode
= GET_MODE (rtl
);
15209 rtl
= XEXP (rtl
, 0);
15210 return mem_loc_descriptor (rtl
, mode
, VAR_INIT_STATUS_INITIALIZED
);
15213 /* Return dw_loc_list representing address of addr_expr LOC
15214 by looking for innder INDIRECT_REF expression and turing it
15215 into simple arithmetics. */
15217 static dw_loc_list_ref
15218 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
15221 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
15222 enum machine_mode mode
;
15224 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (loc
));
15225 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
15227 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
15228 &bitsize
, &bitpos
, &offset
, &mode
,
15229 &unsignedp
, &volatilep
, false);
15231 if (bitpos
% BITS_PER_UNIT
)
15233 expansion_failed (loc
, NULL_RTX
, "bitfield access");
15236 if (!INDIRECT_REF_P (obj
))
15238 expansion_failed (obj
,
15239 NULL_RTX
, "no indirect ref in inner refrence");
15242 if (!offset
&& !bitpos
)
15243 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
15245 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
15246 && (dwarf_version
>= 4 || !dwarf_strict
))
15248 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
15253 /* Variable offset. */
15254 list_ret1
= loc_list_from_tree (offset
, 0);
15255 if (list_ret1
== 0)
15257 add_loc_list (&list_ret
, list_ret1
);
15260 add_loc_descr_to_each (list_ret
,
15261 new_loc_descr (DW_OP_plus
, 0, 0));
15263 bytepos
= bitpos
/ BITS_PER_UNIT
;
15265 add_loc_descr_to_each (list_ret
,
15266 new_loc_descr (DW_OP_plus_uconst
,
15268 else if (bytepos
< 0)
15269 loc_list_plus_const (list_ret
, bytepos
);
15270 add_loc_descr_to_each (list_ret
,
15271 new_loc_descr (DW_OP_stack_value
, 0, 0));
15277 /* Generate Dwarf location list representing LOC.
15278 If WANT_ADDRESS is false, expression computing LOC will be computed
15279 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
15280 if WANT_ADDRESS is 2, expression computing address useable in location
15281 will be returned (i.e. DW_OP_reg can be used
15282 to refer to register values). */
15284 static dw_loc_list_ref
15285 loc_list_from_tree (tree loc
, int want_address
)
15287 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
15288 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
15289 int have_address
= 0;
15290 enum dwarf_location_atom op
;
15292 /* ??? Most of the time we do not take proper care for sign/zero
15293 extending the values properly. Hopefully this won't be a real
15296 switch (TREE_CODE (loc
))
15299 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
15302 case PLACEHOLDER_EXPR
:
15303 /* This case involves extracting fields from an object to determine the
15304 position of other fields. We don't try to encode this here. The
15305 only user of this is Ada, which encodes the needed information using
15306 the names of types. */
15307 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
15311 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
15312 /* There are no opcodes for these operations. */
15315 case PREINCREMENT_EXPR
:
15316 case PREDECREMENT_EXPR
:
15317 case POSTINCREMENT_EXPR
:
15318 case POSTDECREMENT_EXPR
:
15319 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
15320 /* There are no opcodes for these operations. */
15324 /* If we already want an address, see if there is INDIRECT_REF inside
15325 e.g. for &this->field. */
15328 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
15329 (loc
, want_address
== 2);
15332 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
15333 && (ret
= cst_pool_loc_descr (loc
)))
15336 /* Otherwise, process the argument and look for the address. */
15337 if (!list_ret
&& !ret
)
15338 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
15342 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
15348 if (DECL_THREAD_LOCAL_P (loc
))
15351 enum dwarf_location_atom first_op
;
15352 enum dwarf_location_atom second_op
;
15353 bool dtprel
= false;
15355 if (targetm
.have_tls
)
15357 /* If this is not defined, we have no way to emit the
15359 if (!targetm
.asm_out
.output_dwarf_dtprel
)
15362 /* The way DW_OP_GNU_push_tls_address is specified, we
15363 can only look up addresses of objects in the current
15364 module. We used DW_OP_addr as first op, but that's
15365 wrong, because DW_OP_addr is relocated by the debug
15366 info consumer, while DW_OP_GNU_push_tls_address
15367 operand shouldn't be. */
15368 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
15370 first_op
= DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
;
15372 second_op
= DW_OP_GNU_push_tls_address
;
15376 if (!targetm
.emutls
.debug_form_tls_address
15377 || !(dwarf_version
>= 3 || !dwarf_strict
))
15379 /* We stuffed the control variable into the DECL_VALUE_EXPR
15380 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
15381 no longer appear in gimple code. We used the control
15382 variable in specific so that we could pick it up here. */
15383 loc
= DECL_VALUE_EXPR (loc
);
15384 first_op
= DW_OP_addr
;
15385 second_op
= DW_OP_form_tls_address
;
15388 rtl
= rtl_for_decl_location (loc
);
15389 if (rtl
== NULL_RTX
)
15394 rtl
= XEXP (rtl
, 0);
15395 if (! CONSTANT_P (rtl
))
15398 ret
= new_loc_descr (first_op
, 0, 0);
15399 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
15400 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
15401 ret
->dtprel
= dtprel
;
15403 ret1
= new_loc_descr (second_op
, 0, 0);
15404 add_loc_descr (&ret
, ret1
);
15413 if (DECL_HAS_VALUE_EXPR_P (loc
))
15414 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
15418 case FUNCTION_DECL
:
15421 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
15423 if (loc_list
&& loc_list
->first
)
15425 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
15426 have_address
= want_address
!= 0;
15429 rtl
= rtl_for_decl_location (loc
);
15430 if (rtl
== NULL_RTX
)
15432 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
15435 else if (CONST_INT_P (rtl
))
15437 HOST_WIDE_INT val
= INTVAL (rtl
);
15438 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
15439 val
&= GET_MODE_MASK (DECL_MODE (loc
));
15440 ret
= int_loc_descriptor (val
);
15442 else if (GET_CODE (rtl
) == CONST_STRING
)
15444 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
15447 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
15449 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
15450 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
15451 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
15455 enum machine_mode mode
;
15457 /* Certain constructs can only be represented at top-level. */
15458 if (want_address
== 2)
15460 ret
= loc_descriptor (rtl
, VOIDmode
,
15461 VAR_INIT_STATUS_INITIALIZED
);
15466 mode
= GET_MODE (rtl
);
15469 rtl
= XEXP (rtl
, 0);
15472 ret
= mem_loc_descriptor (rtl
, mode
, VAR_INIT_STATUS_INITIALIZED
);
15475 expansion_failed (loc
, rtl
,
15476 "failed to produce loc descriptor for rtl");
15483 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
15487 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15491 case COMPOUND_EXPR
:
15492 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
15495 case VIEW_CONVERT_EXPR
:
15498 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
15500 case COMPONENT_REF
:
15501 case BIT_FIELD_REF
:
15503 case ARRAY_RANGE_REF
:
15504 case REALPART_EXPR
:
15505 case IMAGPART_EXPR
:
15508 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
15509 enum machine_mode mode
;
15511 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (loc
));
15513 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
15514 &unsignedp
, &volatilep
, false);
15516 gcc_assert (obj
!= loc
);
15518 list_ret
= loc_list_from_tree (obj
,
15520 && !bitpos
&& !offset
? 2 : 1);
15521 /* TODO: We can extract value of the small expression via shifting even
15522 for nonzero bitpos. */
15525 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
15527 expansion_failed (loc
, NULL_RTX
,
15528 "bitfield access");
15532 if (offset
!= NULL_TREE
)
15534 /* Variable offset. */
15535 list_ret1
= loc_list_from_tree (offset
, 0);
15536 if (list_ret1
== 0)
15538 add_loc_list (&list_ret
, list_ret1
);
15541 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
15544 bytepos
= bitpos
/ BITS_PER_UNIT
;
15546 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
15547 else if (bytepos
< 0)
15548 loc_list_plus_const (list_ret
, bytepos
);
15555 if ((want_address
|| !host_integerp (loc
, 0))
15556 && (ret
= cst_pool_loc_descr (loc
)))
15558 else if (want_address
== 2
15559 && host_integerp (loc
, 0)
15560 && (ret
= address_of_int_loc_descriptor
15561 (int_size_in_bytes (TREE_TYPE (loc
)),
15562 tree_low_cst (loc
, 0))))
15564 else if (host_integerp (loc
, 0))
15565 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
15568 expansion_failed (loc
, NULL_RTX
,
15569 "Integer operand is not host integer");
15578 if ((ret
= cst_pool_loc_descr (loc
)))
15581 /* We can construct small constants here using int_loc_descriptor. */
15582 expansion_failed (loc
, NULL_RTX
,
15583 "constructor or constant not in constant pool");
15586 case TRUTH_AND_EXPR
:
15587 case TRUTH_ANDIF_EXPR
:
15592 case TRUTH_XOR_EXPR
:
15597 case TRUTH_OR_EXPR
:
15598 case TRUTH_ORIF_EXPR
:
15603 case FLOOR_DIV_EXPR
:
15604 case CEIL_DIV_EXPR
:
15605 case ROUND_DIV_EXPR
:
15606 case TRUNC_DIV_EXPR
:
15607 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
15616 case FLOOR_MOD_EXPR
:
15617 case CEIL_MOD_EXPR
:
15618 case ROUND_MOD_EXPR
:
15619 case TRUNC_MOD_EXPR
:
15620 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
15625 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15626 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
15627 if (list_ret
== 0 || list_ret1
== 0)
15630 add_loc_list (&list_ret
, list_ret1
);
15633 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
15634 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
15635 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
15636 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
15637 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
15649 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
15652 case POINTER_PLUS_EXPR
:
15654 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
15656 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15660 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
15668 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
15675 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
15682 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
15689 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
15704 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15705 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
15706 if (list_ret
== 0 || list_ret1
== 0)
15709 add_loc_list (&list_ret
, list_ret1
);
15712 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
15715 case TRUTH_NOT_EXPR
:
15729 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15733 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
15739 const enum tree_code code
=
15740 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
15742 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
15743 build2 (code
, integer_type_node
,
15744 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
15745 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
15748 /* ... fall through ... */
15752 dw_loc_descr_ref lhs
15753 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
15754 dw_loc_list_ref rhs
15755 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
15756 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
15758 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15759 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
15762 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
15763 add_loc_descr_to_each (list_ret
, bra_node
);
15765 add_loc_list (&list_ret
, rhs
);
15766 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
15767 add_loc_descr_to_each (list_ret
, jump_node
);
15769 add_loc_descr_to_each (list_ret
, lhs
);
15770 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15771 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
15773 /* ??? Need a node to point the skip at. Use a nop. */
15774 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
15775 add_loc_descr_to_each (list_ret
, tmp
);
15776 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15777 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
15781 case FIX_TRUNC_EXPR
:
15785 /* Leave front-end specific codes as simply unknown. This comes
15786 up, for instance, with the C STMT_EXPR. */
15787 if ((unsigned int) TREE_CODE (loc
)
15788 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
15790 expansion_failed (loc
, NULL_RTX
,
15791 "language specific tree node");
15795 #ifdef ENABLE_CHECKING
15796 /* Otherwise this is a generic code; we should just lists all of
15797 these explicitly. We forgot one. */
15798 gcc_unreachable ();
15800 /* In a release build, we want to degrade gracefully: better to
15801 generate incomplete debugging information than to crash. */
15806 if (!ret
&& !list_ret
)
15809 if (want_address
== 2 && !have_address
15810 && (dwarf_version
>= 4 || !dwarf_strict
))
15812 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
15814 expansion_failed (loc
, NULL_RTX
,
15815 "DWARF address size mismatch");
15819 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15821 add_loc_descr_to_each (list_ret
,
15822 new_loc_descr (DW_OP_stack_value
, 0, 0));
15825 /* Show if we can't fill the request for an address. */
15826 if (want_address
&& !have_address
)
15828 expansion_failed (loc
, NULL_RTX
,
15829 "Want address and only have value");
15833 gcc_assert (!ret
|| !list_ret
);
15835 /* If we've got an address and don't want one, dereference. */
15836 if (!want_address
&& have_address
)
15838 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
15840 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
15842 expansion_failed (loc
, NULL_RTX
,
15843 "DWARF address size mismatch");
15846 else if (size
== DWARF2_ADDR_SIZE
)
15849 op
= DW_OP_deref_size
;
15852 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
15854 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
15857 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
15862 /* Same as above but return only single location expression. */
15863 static dw_loc_descr_ref
15864 loc_descriptor_from_tree (tree loc
, int want_address
)
15866 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
15869 if (ret
->dw_loc_next
)
15871 expansion_failed (loc
, NULL_RTX
,
15872 "Location list where only loc descriptor needed");
15878 /* Given a value, round it up to the lowest multiple of `boundary'
15879 which is not less than the value itself. */
15881 static inline HOST_WIDE_INT
15882 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
15884 return (((value
+ boundary
- 1) / boundary
) * boundary
);
15887 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
15888 pointer to the declared type for the relevant field variable, or return
15889 `integer_type_node' if the given node turns out to be an
15890 ERROR_MARK node. */
15893 field_type (const_tree decl
)
15897 if (TREE_CODE (decl
) == ERROR_MARK
)
15898 return integer_type_node
;
15900 type
= DECL_BIT_FIELD_TYPE (decl
);
15901 if (type
== NULL_TREE
)
15902 type
= TREE_TYPE (decl
);
15907 /* Given a pointer to a tree node, return the alignment in bits for
15908 it, or else return BITS_PER_WORD if the node actually turns out to
15909 be an ERROR_MARK node. */
15911 static inline unsigned
15912 simple_type_align_in_bits (const_tree type
)
15914 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
15917 static inline unsigned
15918 simple_decl_align_in_bits (const_tree decl
)
15920 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
15923 /* Return the result of rounding T up to ALIGN. */
15925 static inline double_int
15926 round_up_to_align (double_int t
, unsigned int align
)
15928 double_int alignd
= uhwi_to_double_int (align
);
15929 t
= double_int_add (t
, alignd
);
15930 t
= double_int_add (t
, double_int_minus_one
);
15931 t
= double_int_div (t
, alignd
, true, TRUNC_DIV_EXPR
);
15932 t
= double_int_mul (t
, alignd
);
15936 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
15937 lowest addressed byte of the "containing object" for the given FIELD_DECL,
15938 or return 0 if we are unable to determine what that offset is, either
15939 because the argument turns out to be a pointer to an ERROR_MARK node, or
15940 because the offset is actually variable. (We can't handle the latter case
15943 static HOST_WIDE_INT
15944 field_byte_offset (const_tree decl
)
15946 double_int object_offset_in_bits
;
15947 double_int object_offset_in_bytes
;
15948 double_int bitpos_int
;
15950 if (TREE_CODE (decl
) == ERROR_MARK
)
15953 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
15955 /* We cannot yet cope with fields whose positions are variable, so
15956 for now, when we see such things, we simply return 0. Someday, we may
15957 be able to handle such cases, but it will be damn difficult. */
15958 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
15961 bitpos_int
= tree_to_double_int (bit_position (decl
));
15963 #ifdef PCC_BITFIELD_TYPE_MATTERS
15964 if (PCC_BITFIELD_TYPE_MATTERS
)
15967 tree field_size_tree
;
15968 double_int deepest_bitpos
;
15969 double_int field_size_in_bits
;
15970 unsigned int type_align_in_bits
;
15971 unsigned int decl_align_in_bits
;
15972 double_int type_size_in_bits
;
15974 type
= field_type (decl
);
15975 type_size_in_bits
= double_int_type_size_in_bits (type
);
15976 type_align_in_bits
= simple_type_align_in_bits (type
);
15978 field_size_tree
= DECL_SIZE (decl
);
15980 /* The size could be unspecified if there was an error, or for
15981 a flexible array member. */
15982 if (!field_size_tree
)
15983 field_size_tree
= bitsize_zero_node
;
15985 /* If the size of the field is not constant, use the type size. */
15986 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
15987 field_size_in_bits
= tree_to_double_int (field_size_tree
);
15989 field_size_in_bits
= type_size_in_bits
;
15991 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
15993 /* The GCC front-end doesn't make any attempt to keep track of the
15994 starting bit offset (relative to the start of the containing
15995 structure type) of the hypothetical "containing object" for a
15996 bit-field. Thus, when computing the byte offset value for the
15997 start of the "containing object" of a bit-field, we must deduce
15998 this information on our own. This can be rather tricky to do in
15999 some cases. For example, handling the following structure type
16000 definition when compiling for an i386/i486 target (which only
16001 aligns long long's to 32-bit boundaries) can be very tricky:
16003 struct S { int field1; long long field2:31; };
16005 Fortunately, there is a simple rule-of-thumb which can be used
16006 in such cases. When compiling for an i386/i486, GCC will
16007 allocate 8 bytes for the structure shown above. It decides to
16008 do this based upon one simple rule for bit-field allocation.
16009 GCC allocates each "containing object" for each bit-field at
16010 the first (i.e. lowest addressed) legitimate alignment boundary
16011 (based upon the required minimum alignment for the declared
16012 type of the field) which it can possibly use, subject to the
16013 condition that there is still enough available space remaining
16014 in the containing object (when allocated at the selected point)
16015 to fully accommodate all of the bits of the bit-field itself.
16017 This simple rule makes it obvious why GCC allocates 8 bytes for
16018 each object of the structure type shown above. When looking
16019 for a place to allocate the "containing object" for `field2',
16020 the compiler simply tries to allocate a 64-bit "containing
16021 object" at each successive 32-bit boundary (starting at zero)
16022 until it finds a place to allocate that 64- bit field such that
16023 at least 31 contiguous (and previously unallocated) bits remain
16024 within that selected 64 bit field. (As it turns out, for the
16025 example above, the compiler finds it is OK to allocate the
16026 "containing object" 64-bit field at bit-offset zero within the
16029 Here we attempt to work backwards from the limited set of facts
16030 we're given, and we try to deduce from those facts, where GCC
16031 must have believed that the containing object started (within
16032 the structure type). The value we deduce is then used (by the
16033 callers of this routine) to generate DW_AT_location and
16034 DW_AT_bit_offset attributes for fields (both bit-fields and, in
16035 the case of DW_AT_location, regular fields as well). */
16037 /* Figure out the bit-distance from the start of the structure to
16038 the "deepest" bit of the bit-field. */
16039 deepest_bitpos
= double_int_add (bitpos_int
, field_size_in_bits
);
16041 /* This is the tricky part. Use some fancy footwork to deduce
16042 where the lowest addressed bit of the containing object must
16044 object_offset_in_bits
16045 = double_int_sub (deepest_bitpos
, type_size_in_bits
);
16047 /* Round up to type_align by default. This works best for
16049 object_offset_in_bits
16050 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
16052 if (double_int_ucmp (object_offset_in_bits
, bitpos_int
) > 0)
16054 object_offset_in_bits
16055 = double_int_sub (deepest_bitpos
, type_size_in_bits
);
16057 /* Round up to decl_align instead. */
16058 object_offset_in_bits
16059 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
16063 #endif /* PCC_BITFIELD_TYPE_MATTERS */
16064 object_offset_in_bits
= bitpos_int
;
16066 object_offset_in_bytes
16067 = double_int_div (object_offset_in_bits
,
16068 uhwi_to_double_int (BITS_PER_UNIT
), true,
16070 return double_int_to_shwi (object_offset_in_bytes
);
16073 /* The following routines define various Dwarf attributes and any data
16074 associated with them. */
16076 /* Add a location description attribute value to a DIE.
16078 This emits location attributes suitable for whole variables and
16079 whole parameters. Note that the location attributes for struct fields are
16080 generated by the routine `data_member_location_attribute' below. */
16083 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
16084 dw_loc_list_ref descr
)
16088 if (single_element_loc_list_p (descr
))
16089 add_AT_loc (die
, attr_kind
, descr
->expr
);
16091 add_AT_loc_list (die
, attr_kind
, descr
);
16094 /* Add DW_AT_accessibility attribute to DIE if needed. */
16097 add_accessibility_attribute (dw_die_ref die
, tree decl
)
16099 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
16100 children, otherwise the default is DW_ACCESS_public. In DWARF2
16101 the default has always been DW_ACCESS_public. */
16102 if (TREE_PROTECTED (decl
))
16103 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
16104 else if (TREE_PRIVATE (decl
))
16106 if (dwarf_version
== 2
16107 || die
->die_parent
== NULL
16108 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
16109 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
16111 else if (dwarf_version
> 2
16113 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
16114 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
16117 /* Attach the specialized form of location attribute used for data members of
16118 struct and union types. In the special case of a FIELD_DECL node which
16119 represents a bit-field, the "offset" part of this special location
16120 descriptor must indicate the distance in bytes from the lowest-addressed
16121 byte of the containing struct or union type to the lowest-addressed byte of
16122 the "containing object" for the bit-field. (See the `field_byte_offset'
16125 For any given bit-field, the "containing object" is a hypothetical object
16126 (of some integral or enum type) within which the given bit-field lives. The
16127 type of this hypothetical "containing object" is always the same as the
16128 declared type of the individual bit-field itself (for GCC anyway... the
16129 DWARF spec doesn't actually mandate this). Note that it is the size (in
16130 bytes) of the hypothetical "containing object" which will be given in the
16131 DW_AT_byte_size attribute for this bit-field. (See the
16132 `byte_size_attribute' function below.) It is also used when calculating the
16133 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
16134 function below.) */
16137 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
16139 HOST_WIDE_INT offset
;
16140 dw_loc_descr_ref loc_descr
= 0;
16142 if (TREE_CODE (decl
) == TREE_BINFO
)
16144 /* We're working on the TAG_inheritance for a base class. */
16145 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
16147 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
16148 aren't at a fixed offset from all (sub)objects of the same
16149 type. We need to extract the appropriate offset from our
16150 vtable. The following dwarf expression means
16152 BaseAddr = ObAddr + *((*ObAddr) - Offset)
16154 This is specific to the V3 ABI, of course. */
16156 dw_loc_descr_ref tmp
;
16158 /* Make a copy of the object address. */
16159 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
16160 add_loc_descr (&loc_descr
, tmp
);
16162 /* Extract the vtable address. */
16163 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
16164 add_loc_descr (&loc_descr
, tmp
);
16166 /* Calculate the address of the offset. */
16167 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
16168 gcc_assert (offset
< 0);
16170 tmp
= int_loc_descriptor (-offset
);
16171 add_loc_descr (&loc_descr
, tmp
);
16172 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
16173 add_loc_descr (&loc_descr
, tmp
);
16175 /* Extract the offset. */
16176 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
16177 add_loc_descr (&loc_descr
, tmp
);
16179 /* Add it to the object address. */
16180 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
16181 add_loc_descr (&loc_descr
, tmp
);
16184 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
16187 offset
= field_byte_offset (decl
);
16191 if (dwarf_version
> 2)
16193 /* Don't need to output a location expression, just the constant. */
16195 add_AT_int (die
, DW_AT_data_member_location
, offset
);
16197 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
16202 enum dwarf_location_atom op
;
16204 /* The DWARF2 standard says that we should assume that the structure
16205 address is already on the stack, so we can specify a structure
16206 field address by using DW_OP_plus_uconst. */
16208 #ifdef MIPS_DEBUGGING_INFO
16209 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
16210 operator correctly. It works only if we leave the offset on the
16214 op
= DW_OP_plus_uconst
;
16217 loc_descr
= new_loc_descr (op
, offset
, 0);
16221 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
16224 /* Writes integer values to dw_vec_const array. */
16227 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
16231 *dest
++ = val
& 0xff;
16237 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
16239 static HOST_WIDE_INT
16240 extract_int (const unsigned char *src
, unsigned int size
)
16242 HOST_WIDE_INT val
= 0;
16248 val
|= *--src
& 0xff;
16254 /* Writes double_int values to dw_vec_const array. */
16257 insert_double (double_int val
, unsigned char *dest
)
16259 unsigned char *p0
= dest
;
16260 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
16262 if (WORDS_BIG_ENDIAN
)
16268 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
16269 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
16272 /* Writes floating point values to dw_vec_const array. */
16275 insert_float (const_rtx rtl
, unsigned char *array
)
16277 REAL_VALUE_TYPE rv
;
16281 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
16282 real_to_target (val
, &rv
, GET_MODE (rtl
));
16284 /* real_to_target puts 32-bit pieces in each long. Pack them. */
16285 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
16287 insert_int (val
[i
], 4, array
);
16292 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
16293 does not have a "location" either in memory or in a register. These
16294 things can arise in GNU C when a constant is passed as an actual parameter
16295 to an inlined function. They can also arise in C++ where declared
16296 constants do not necessarily get memory "homes". */
16299 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
16301 switch (GET_CODE (rtl
))
16305 HOST_WIDE_INT val
= INTVAL (rtl
);
16308 add_AT_int (die
, DW_AT_const_value
, val
);
16310 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
16315 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
16316 floating-point constant. A CONST_DOUBLE is used whenever the
16317 constant requires more than one word in order to be adequately
16320 enum machine_mode mode
= GET_MODE (rtl
);
16322 if (SCALAR_FLOAT_MODE_P (mode
))
16324 unsigned int length
= GET_MODE_SIZE (mode
);
16325 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
16327 insert_float (rtl
, array
);
16328 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
16331 add_AT_double (die
, DW_AT_const_value
,
16332 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
16338 enum machine_mode mode
= GET_MODE (rtl
);
16339 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
16340 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
16341 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
16342 (length
* elt_size
);
16346 switch (GET_MODE_CLASS (mode
))
16348 case MODE_VECTOR_INT
:
16349 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
16351 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
16352 double_int val
= rtx_to_double_int (elt
);
16354 if (elt_size
<= sizeof (HOST_WIDE_INT
))
16355 insert_int (double_int_to_shwi (val
), elt_size
, p
);
16358 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
16359 insert_double (val
, p
);
16364 case MODE_VECTOR_FLOAT
:
16365 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
16367 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
16368 insert_float (elt
, p
);
16373 gcc_unreachable ();
16376 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
16381 if (dwarf_version
>= 4 || !dwarf_strict
)
16383 dw_loc_descr_ref loc_result
;
16384 resolve_one_addr (&rtl
, NULL
);
16386 loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
16387 loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
16388 loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
16389 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
16390 add_AT_loc (die
, DW_AT_location
, loc_result
);
16391 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
16397 if (CONSTANT_P (XEXP (rtl
, 0)))
16398 return add_const_value_attribute (die
, XEXP (rtl
, 0));
16401 if (!const_ok_for_output (rtl
))
16404 if (dwarf_version
>= 4 || !dwarf_strict
)
16409 /* In cases where an inlined instance of an inline function is passed
16410 the address of an `auto' variable (which is local to the caller) we
16411 can get a situation where the DECL_RTL of the artificial local
16412 variable (for the inlining) which acts as a stand-in for the
16413 corresponding formal parameter (of the inline function) will look
16414 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
16415 exactly a compile-time constant expression, but it isn't the address
16416 of the (artificial) local variable either. Rather, it represents the
16417 *value* which the artificial local variable always has during its
16418 lifetime. We currently have no way to represent such quasi-constant
16419 values in Dwarf, so for now we just punt and generate nothing. */
16427 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
16428 && MEM_READONLY_P (rtl
)
16429 && GET_MODE (rtl
) == BLKmode
)
16431 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
16437 /* No other kinds of rtx should be possible here. */
16438 gcc_unreachable ();
16443 /* Determine whether the evaluation of EXPR references any variables
16444 or functions which aren't otherwise used (and therefore may not be
16447 reference_to_unused (tree
* tp
, int * walk_subtrees
,
16448 void * data ATTRIBUTE_UNUSED
)
16450 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
16451 *walk_subtrees
= 0;
16453 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
16454 && ! TREE_ASM_WRITTEN (*tp
))
16456 /* ??? The C++ FE emits debug information for using decls, so
16457 putting gcc_unreachable here falls over. See PR31899. For now
16458 be conservative. */
16459 else if (!cgraph_global_info_ready
16460 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
16462 else if (TREE_CODE (*tp
) == VAR_DECL
)
16464 struct varpool_node
*node
= varpool_get_node (*tp
);
16465 if (!node
|| !node
->needed
)
16468 else if (TREE_CODE (*tp
) == FUNCTION_DECL
16469 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
16471 /* The call graph machinery must have finished analyzing,
16472 optimizing and gimplifying the CU by now.
16473 So if *TP has no call graph node associated
16474 to it, it means *TP will not be emitted. */
16475 if (!cgraph_get_node (*tp
))
16478 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
16484 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
16485 for use in a later add_const_value_attribute call. */
16488 rtl_for_decl_init (tree init
, tree type
)
16490 rtx rtl
= NULL_RTX
;
16494 /* If a variable is initialized with a string constant without embedded
16495 zeros, build CONST_STRING. */
16496 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
16498 tree enttype
= TREE_TYPE (type
);
16499 tree domain
= TYPE_DOMAIN (type
);
16500 enum machine_mode mode
= TYPE_MODE (enttype
);
16502 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
16504 && integer_zerop (TYPE_MIN_VALUE (domain
))
16505 && compare_tree_int (TYPE_MAX_VALUE (domain
),
16506 TREE_STRING_LENGTH (init
) - 1) == 0
16507 && ((size_t) TREE_STRING_LENGTH (init
)
16508 == strlen (TREE_STRING_POINTER (init
)) + 1))
16510 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
16511 ggc_strdup (TREE_STRING_POINTER (init
)));
16512 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
16513 MEM_READONLY_P (rtl
) = 1;
16516 /* Other aggregates, and complex values, could be represented using
16518 else if (AGGREGATE_TYPE_P (type
)
16519 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
16520 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
16521 || TREE_CODE (type
) == COMPLEX_TYPE
)
16523 /* Vectors only work if their mode is supported by the target.
16524 FIXME: generic vectors ought to work too. */
16525 else if (TREE_CODE (type
) == VECTOR_TYPE
16526 && !VECTOR_MODE_P (TYPE_MODE (type
)))
16528 /* If the initializer is something that we know will expand into an
16529 immediate RTL constant, expand it now. We must be careful not to
16530 reference variables which won't be output. */
16531 else if (initializer_constant_valid_p (init
, type
)
16532 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
16534 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
16536 if (TREE_CODE (type
) == VECTOR_TYPE
)
16537 switch (TREE_CODE (init
))
16542 if (TREE_CONSTANT (init
))
16544 VEC(constructor_elt
,gc
) *elts
= CONSTRUCTOR_ELTS (init
);
16545 bool constant_p
= true;
16547 unsigned HOST_WIDE_INT ix
;
16549 /* Even when ctor is constant, it might contain non-*_CST
16550 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
16551 belong into VECTOR_CST nodes. */
16552 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
16553 if (!CONSTANT_CLASS_P (value
))
16555 constant_p
= false;
16561 init
= build_vector_from_ctor (type
, elts
);
16571 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
16573 /* If expand_expr returns a MEM, it wasn't immediate. */
16574 gcc_assert (!rtl
|| !MEM_P (rtl
));
16580 /* Generate RTL for the variable DECL to represent its location. */
16583 rtl_for_decl_location (tree decl
)
16587 /* Here we have to decide where we are going to say the parameter "lives"
16588 (as far as the debugger is concerned). We only have a couple of
16589 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
16591 DECL_RTL normally indicates where the parameter lives during most of the
16592 activation of the function. If optimization is enabled however, this
16593 could be either NULL or else a pseudo-reg. Both of those cases indicate
16594 that the parameter doesn't really live anywhere (as far as the code
16595 generation parts of GCC are concerned) during most of the function's
16596 activation. That will happen (for example) if the parameter is never
16597 referenced within the function.
16599 We could just generate a location descriptor here for all non-NULL
16600 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
16601 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
16602 where DECL_RTL is NULL or is a pseudo-reg.
16604 Note however that we can only get away with using DECL_INCOMING_RTL as
16605 a backup substitute for DECL_RTL in certain limited cases. In cases
16606 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
16607 we can be sure that the parameter was passed using the same type as it is
16608 declared to have within the function, and that its DECL_INCOMING_RTL
16609 points us to a place where a value of that type is passed.
16611 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
16612 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
16613 because in these cases DECL_INCOMING_RTL points us to a value of some
16614 type which is *different* from the type of the parameter itself. Thus,
16615 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
16616 such cases, the debugger would end up (for example) trying to fetch a
16617 `float' from a place which actually contains the first part of a
16618 `double'. That would lead to really incorrect and confusing
16619 output at debug-time.
16621 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
16622 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
16623 are a couple of exceptions however. On little-endian machines we can
16624 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
16625 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
16626 an integral type that is smaller than TREE_TYPE (decl). These cases arise
16627 when (on a little-endian machine) a non-prototyped function has a
16628 parameter declared to be of type `short' or `char'. In such cases,
16629 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
16630 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
16631 passed `int' value. If the debugger then uses that address to fetch
16632 a `short' or a `char' (on a little-endian machine) the result will be
16633 the correct data, so we allow for such exceptional cases below.
16635 Note that our goal here is to describe the place where the given formal
16636 parameter lives during most of the function's activation (i.e. between the
16637 end of the prologue and the start of the epilogue). We'll do that as best
16638 as we can. Note however that if the given formal parameter is modified
16639 sometime during the execution of the function, then a stack backtrace (at
16640 debug-time) will show the function as having been called with the *new*
16641 value rather than the value which was originally passed in. This happens
16642 rarely enough that it is not a major problem, but it *is* a problem, and
16643 I'd like to fix it.
16645 A future version of dwarf2out.c may generate two additional attributes for
16646 any given DW_TAG_formal_parameter DIE which will describe the "passed
16647 type" and the "passed location" for the given formal parameter in addition
16648 to the attributes we now generate to indicate the "declared type" and the
16649 "active location" for each parameter. This additional set of attributes
16650 could be used by debuggers for stack backtraces. Separately, note that
16651 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
16652 This happens (for example) for inlined-instances of inline function formal
16653 parameters which are never referenced. This really shouldn't be
16654 happening. All PARM_DECL nodes should get valid non-NULL
16655 DECL_INCOMING_RTL values. FIXME. */
16657 /* Use DECL_RTL as the "location" unless we find something better. */
16658 rtl
= DECL_RTL_IF_SET (decl
);
16660 /* When generating abstract instances, ignore everything except
16661 constants, symbols living in memory, and symbols living in
16662 fixed registers. */
16663 if (! reload_completed
)
16666 && (CONSTANT_P (rtl
)
16668 && CONSTANT_P (XEXP (rtl
, 0)))
16670 && TREE_CODE (decl
) == VAR_DECL
16671 && TREE_STATIC (decl
))))
16673 rtl
= targetm
.delegitimize_address (rtl
);
16678 else if (TREE_CODE (decl
) == PARM_DECL
)
16680 if (rtl
== NULL_RTX
16681 || is_pseudo_reg (rtl
)
16683 && is_pseudo_reg (XEXP (rtl
, 0))
16684 && DECL_INCOMING_RTL (decl
)
16685 && MEM_P (DECL_INCOMING_RTL (decl
))
16686 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
16688 tree declared_type
= TREE_TYPE (decl
);
16689 tree passed_type
= DECL_ARG_TYPE (decl
);
16690 enum machine_mode dmode
= TYPE_MODE (declared_type
);
16691 enum machine_mode pmode
= TYPE_MODE (passed_type
);
16693 /* This decl represents a formal parameter which was optimized out.
16694 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
16695 all cases where (rtl == NULL_RTX) just below. */
16696 if (dmode
== pmode
)
16697 rtl
= DECL_INCOMING_RTL (decl
);
16698 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
16699 && SCALAR_INT_MODE_P (dmode
)
16700 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
16701 && DECL_INCOMING_RTL (decl
))
16703 rtx inc
= DECL_INCOMING_RTL (decl
);
16706 else if (MEM_P (inc
))
16708 if (BYTES_BIG_ENDIAN
)
16709 rtl
= adjust_address_nv (inc
, dmode
,
16710 GET_MODE_SIZE (pmode
)
16711 - GET_MODE_SIZE (dmode
));
16718 /* If the parm was passed in registers, but lives on the stack, then
16719 make a big endian correction if the mode of the type of the
16720 parameter is not the same as the mode of the rtl. */
16721 /* ??? This is the same series of checks that are made in dbxout.c before
16722 we reach the big endian correction code there. It isn't clear if all
16723 of these checks are necessary here, but keeping them all is the safe
16725 else if (MEM_P (rtl
)
16726 && XEXP (rtl
, 0) != const0_rtx
16727 && ! CONSTANT_P (XEXP (rtl
, 0))
16728 /* Not passed in memory. */
16729 && !MEM_P (DECL_INCOMING_RTL (decl
))
16730 /* Not passed by invisible reference. */
16731 && (!REG_P (XEXP (rtl
, 0))
16732 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
16733 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
16734 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
16735 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
16738 /* Big endian correction check. */
16739 && BYTES_BIG_ENDIAN
16740 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
16741 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
16744 int offset
= (UNITS_PER_WORD
16745 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
16747 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
16748 plus_constant (XEXP (rtl
, 0), offset
));
16751 else if (TREE_CODE (decl
) == VAR_DECL
16754 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
16755 && BYTES_BIG_ENDIAN
)
16757 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
16758 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
16760 /* If a variable is declared "register" yet is smaller than
16761 a register, then if we store the variable to memory, it
16762 looks like we're storing a register-sized value, when in
16763 fact we are not. We need to adjust the offset of the
16764 storage location to reflect the actual value's bytes,
16765 else gdb will not be able to display it. */
16767 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
16768 plus_constant (XEXP (rtl
, 0), rsize
-dsize
));
16771 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16772 and will have been substituted directly into all expressions that use it.
16773 C does not have such a concept, but C++ and other languages do. */
16774 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
16775 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
16778 rtl
= targetm
.delegitimize_address (rtl
);
16780 /* If we don't look past the constant pool, we risk emitting a
16781 reference to a constant pool entry that isn't referenced from
16782 code, and thus is not emitted. */
16784 rtl
= avoid_constant_pool_reference (rtl
);
16786 /* Try harder to get a rtl. If this symbol ends up not being emitted
16787 in the current CU, resolve_addr will remove the expression referencing
16789 if (rtl
== NULL_RTX
16790 && TREE_CODE (decl
) == VAR_DECL
16791 && !DECL_EXTERNAL (decl
)
16792 && TREE_STATIC (decl
)
16793 && DECL_NAME (decl
)
16794 && !DECL_HARD_REGISTER (decl
)
16795 && DECL_MODE (decl
) != VOIDmode
)
16797 rtl
= make_decl_rtl_for_debug (decl
);
16799 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
16800 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
16807 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
16808 returned. If so, the decl for the COMMON block is returned, and the
16809 value is the offset into the common block for the symbol. */
16812 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
16814 tree val_expr
, cvar
;
16815 enum machine_mode mode
;
16816 HOST_WIDE_INT bitsize
, bitpos
;
16818 int volatilep
= 0, unsignedp
= 0;
16820 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
16821 it does not have a value (the offset into the common area), or if it
16822 is thread local (as opposed to global) then it isn't common, and shouldn't
16823 be handled as such. */
16824 if (TREE_CODE (decl
) != VAR_DECL
16825 || !TREE_STATIC (decl
)
16826 || !DECL_HAS_VALUE_EXPR_P (decl
)
16830 val_expr
= DECL_VALUE_EXPR (decl
);
16831 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
16834 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
16835 &mode
, &unsignedp
, &volatilep
, true);
16837 if (cvar
== NULL_TREE
16838 || TREE_CODE (cvar
) != VAR_DECL
16839 || DECL_ARTIFICIAL (cvar
)
16840 || !TREE_PUBLIC (cvar
))
16844 if (offset
!= NULL
)
16846 if (!host_integerp (offset
, 0))
16848 *value
= tree_low_cst (offset
, 0);
16851 *value
+= bitpos
/ BITS_PER_UNIT
;
16856 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
16857 data attribute for a variable or a parameter. We generate the
16858 DW_AT_const_value attribute only in those cases where the given variable
16859 or parameter does not have a true "location" either in memory or in a
16860 register. This can happen (for example) when a constant is passed as an
16861 actual argument in a call to an inline function. (It's possible that
16862 these things can crop up in other ways also.) Note that one type of
16863 constant value which can be passed into an inlined function is a constant
16864 pointer. This can happen for example if an actual argument in an inlined
16865 function call evaluates to a compile-time constant address.
16867 CACHE_P is true if it is worth caching the location list for DECL,
16868 so that future calls can reuse it rather than regenerate it from scratch.
16869 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
16870 since we will need to refer to them each time the function is inlined. */
16873 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
16874 enum dwarf_attribute attr
)
16877 dw_loc_list_ref list
;
16878 var_loc_list
*loc_list
;
16879 cached_dw_loc_list
*cache
;
16882 if (TREE_CODE (decl
) == ERROR_MARK
)
16885 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
16886 || TREE_CODE (decl
) == RESULT_DECL
);
16888 /* Try to get some constant RTL for this decl, and use that as the value of
16891 rtl
= rtl_for_decl_location (decl
);
16892 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
16893 && add_const_value_attribute (die
, rtl
))
16896 /* See if we have single element location list that is equivalent to
16897 a constant value. That way we are better to use add_const_value_attribute
16898 rather than expanding constant value equivalent. */
16899 loc_list
= lookup_decl_loc (decl
);
16902 && loc_list
->first
->next
== NULL
16903 && NOTE_P (loc_list
->first
->loc
)
16904 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
16905 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
16907 struct var_loc_node
*node
;
16909 node
= loc_list
->first
;
16910 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
16911 if (GET_CODE (rtl
) == EXPR_LIST
)
16912 rtl
= XEXP (rtl
, 0);
16913 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
16914 && add_const_value_attribute (die
, rtl
))
16917 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
16918 list several times. See if we've already cached the contents. */
16920 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
16924 cache
= (cached_dw_loc_list
*)
16925 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
16927 list
= cache
->loc_list
;
16931 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
16932 /* It is usually worth caching this result if the decl is from
16933 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
16934 if (cache_p
&& list
&& list
->dw_loc_next
)
16936 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
16937 DECL_UID (decl
), INSERT
);
16938 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
16939 cache
->decl_id
= DECL_UID (decl
);
16940 cache
->loc_list
= list
;
16946 add_AT_location_description (die
, attr
, list
);
16949 /* None of that worked, so it must not really have a location;
16950 try adding a constant value attribute from the DECL_INITIAL. */
16951 return tree_add_const_value_attribute_for_decl (die
, decl
);
16954 /* Add VARIABLE and DIE into deferred locations list. */
16957 defer_location (tree variable
, dw_die_ref die
)
16959 deferred_locations entry
;
16960 entry
.variable
= variable
;
16962 VEC_safe_push (deferred_locations
, gc
, deferred_locations_list
, &entry
);
16965 /* Helper function for tree_add_const_value_attribute. Natively encode
16966 initializer INIT into an array. Return true if successful. */
16969 native_encode_initializer (tree init
, unsigned char *array
, int size
)
16973 if (init
== NULL_TREE
)
16977 switch (TREE_CODE (init
))
16980 type
= TREE_TYPE (init
);
16981 if (TREE_CODE (type
) == ARRAY_TYPE
)
16983 tree enttype
= TREE_TYPE (type
);
16984 enum machine_mode mode
= TYPE_MODE (enttype
);
16986 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
16988 if (int_size_in_bytes (type
) != size
)
16990 if (size
> TREE_STRING_LENGTH (init
))
16992 memcpy (array
, TREE_STRING_POINTER (init
),
16993 TREE_STRING_LENGTH (init
));
16994 memset (array
+ TREE_STRING_LENGTH (init
),
16995 '\0', size
- TREE_STRING_LENGTH (init
));
16998 memcpy (array
, TREE_STRING_POINTER (init
), size
);
17003 type
= TREE_TYPE (init
);
17004 if (int_size_in_bytes (type
) != size
)
17006 if (TREE_CODE (type
) == ARRAY_TYPE
)
17008 HOST_WIDE_INT min_index
;
17009 unsigned HOST_WIDE_INT cnt
;
17010 int curpos
= 0, fieldsize
;
17011 constructor_elt
*ce
;
17013 if (TYPE_DOMAIN (type
) == NULL_TREE
17014 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
17017 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
17018 if (fieldsize
<= 0)
17021 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
17022 memset (array
, '\0', size
);
17023 FOR_EACH_VEC_ELT (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
)
17025 tree val
= ce
->value
;
17026 tree index
= ce
->index
;
17028 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
17029 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
17032 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
17037 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
17040 curpos
= pos
+ fieldsize
;
17041 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
17043 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
17044 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
17048 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
17049 curpos
+= fieldsize
;
17052 gcc_assert (curpos
<= size
);
17056 else if (TREE_CODE (type
) == RECORD_TYPE
17057 || TREE_CODE (type
) == UNION_TYPE
)
17059 tree field
= NULL_TREE
;
17060 unsigned HOST_WIDE_INT cnt
;
17061 constructor_elt
*ce
;
17063 if (int_size_in_bytes (type
) != size
)
17066 if (TREE_CODE (type
) == RECORD_TYPE
)
17067 field
= TYPE_FIELDS (type
);
17069 FOR_EACH_VEC_ELT (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
)
17071 tree val
= ce
->value
;
17072 int pos
, fieldsize
;
17074 if (ce
->index
!= 0)
17080 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
17083 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
17084 && TYPE_DOMAIN (TREE_TYPE (field
))
17085 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
17087 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
17088 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
17090 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
17091 pos
= int_byte_position (field
);
17092 gcc_assert (pos
+ fieldsize
<= size
);
17094 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
17100 case VIEW_CONVERT_EXPR
:
17101 case NON_LVALUE_EXPR
:
17102 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
17104 return native_encode_expr (init
, array
, size
) == size
;
17108 /* Attach a DW_AT_const_value attribute to DIE. The value of the
17109 attribute is the const value T. */
17112 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
17115 tree type
= TREE_TYPE (t
);
17118 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
17122 gcc_assert (!DECL_P (init
));
17124 rtl
= rtl_for_decl_init (init
, type
);
17126 return add_const_value_attribute (die
, rtl
);
17127 /* If the host and target are sane, try harder. */
17128 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
17129 && initializer_constant_valid_p (init
, type
))
17131 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
17132 if (size
> 0 && (int) size
== size
)
17134 unsigned char *array
= (unsigned char *)
17135 ggc_alloc_cleared_atomic (size
);
17137 if (native_encode_initializer (init
, array
, size
))
17139 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
17147 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
17148 attribute is the const value of T, where T is an integral constant
17149 variable with static storage duration
17150 (so it can't be a PARM_DECL or a RESULT_DECL). */
17153 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
17157 || (TREE_CODE (decl
) != VAR_DECL
17158 && TREE_CODE (decl
) != CONST_DECL
))
17161 if (TREE_READONLY (decl
)
17162 && ! TREE_THIS_VOLATILE (decl
)
17163 && DECL_INITIAL (decl
))
17168 /* Don't add DW_AT_const_value if abstract origin already has one. */
17169 if (get_AT (var_die
, DW_AT_const_value
))
17172 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
17175 /* Convert the CFI instructions for the current function into a
17176 location list. This is used for DW_AT_frame_base when we targeting
17177 a dwarf2 consumer that does not support the dwarf3
17178 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
17181 static dw_loc_list_ref
17182 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
17186 dw_loc_list_ref list
, *list_tail
;
17188 dw_cfa_location last_cfa
, next_cfa
;
17189 const char *start_label
, *last_label
, *section
;
17190 dw_cfa_location remember
;
17192 fde
= current_fde ();
17193 gcc_assert (fde
!= NULL
);
17195 section
= secname_for_decl (current_function_decl
);
17199 memset (&next_cfa
, 0, sizeof (next_cfa
));
17200 next_cfa
.reg
= INVALID_REGNUM
;
17201 remember
= next_cfa
;
17203 start_label
= fde
->dw_fde_begin
;
17205 /* ??? Bald assumption that the CIE opcode list does not contain
17206 advance opcodes. */
17207 FOR_EACH_VEC_ELT (dw_cfi_ref
, cie_cfi_vec
, ix
, cfi
)
17208 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
17210 last_cfa
= next_cfa
;
17211 last_label
= start_label
;
17213 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
17215 /* If the first partition contained no CFI adjustments, the
17216 CIE opcodes apply to the whole first partition. */
17217 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
17218 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
17219 list_tail
=&(*list_tail
)->dw_loc_next
;
17220 start_label
= last_label
= fde
->dw_fde_second_begin
;
17223 FOR_EACH_VEC_ELT (dw_cfi_ref
, fde
->dw_fde_cfi
, ix
, cfi
)
17225 switch (cfi
->dw_cfi_opc
)
17227 case DW_CFA_set_loc
:
17228 case DW_CFA_advance_loc1
:
17229 case DW_CFA_advance_loc2
:
17230 case DW_CFA_advance_loc4
:
17231 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
17233 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
17234 start_label
, last_label
, section
);
17236 list_tail
= &(*list_tail
)->dw_loc_next
;
17237 last_cfa
= next_cfa
;
17238 start_label
= last_label
;
17240 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
17243 case DW_CFA_advance_loc
:
17244 /* The encoding is complex enough that we should never emit this. */
17245 gcc_unreachable ();
17248 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
17251 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
17253 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
17255 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
17256 start_label
, last_label
, section
);
17258 list_tail
= &(*list_tail
)->dw_loc_next
;
17259 last_cfa
= next_cfa
;
17260 start_label
= last_label
;
17262 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
17263 start_label
, fde
->dw_fde_end
, section
);
17264 list_tail
= &(*list_tail
)->dw_loc_next
;
17265 start_label
= last_label
= fde
->dw_fde_second_begin
;
17269 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
17271 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
17272 start_label
, last_label
, section
);
17273 list_tail
= &(*list_tail
)->dw_loc_next
;
17274 start_label
= last_label
;
17277 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
17279 fde
->dw_fde_second_begin
17280 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
17283 if (list
&& list
->dw_loc_next
)
17289 /* Compute a displacement from the "steady-state frame pointer" to the
17290 frame base (often the same as the CFA), and store it in
17291 frame_pointer_fb_offset. OFFSET is added to the displacement
17292 before the latter is negated. */
17295 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
17299 #ifdef FRAME_POINTER_CFA_OFFSET
17300 reg
= frame_pointer_rtx
;
17301 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
17303 reg
= arg_pointer_rtx
;
17304 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
17307 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
17308 if (GET_CODE (elim
) == PLUS
)
17310 offset
+= INTVAL (XEXP (elim
, 1));
17311 elim
= XEXP (elim
, 0);
17314 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
17315 && (elim
== hard_frame_pointer_rtx
17316 || elim
== stack_pointer_rtx
))
17317 || elim
== (frame_pointer_needed
17318 ? hard_frame_pointer_rtx
17319 : stack_pointer_rtx
));
17321 frame_pointer_fb_offset
= -offset
;
17324 /* Generate a DW_AT_name attribute given some string value to be included as
17325 the value of the attribute. */
17328 add_name_attribute (dw_die_ref die
, const char *name_string
)
17330 if (name_string
!= NULL
&& *name_string
!= 0)
17332 if (demangle_name_func
)
17333 name_string
= (*demangle_name_func
) (name_string
);
17335 add_AT_string (die
, DW_AT_name
, name_string
);
17339 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
17340 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
17341 of TYPE accordingly.
17343 ??? This is a temporary measure until after we're able to generate
17344 regular DWARF for the complex Ada type system. */
17347 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
17348 dw_die_ref context_die
)
17351 dw_die_ref dtype_die
;
17353 if (!lang_hooks
.types
.descriptive_type
)
17356 dtype
= lang_hooks
.types
.descriptive_type (type
);
17360 dtype_die
= lookup_type_die (dtype
);
17363 gen_type_die (dtype
, context_die
);
17364 dtype_die
= lookup_type_die (dtype
);
17365 gcc_assert (dtype_die
);
17368 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
17371 /* Generate a DW_AT_comp_dir attribute for DIE. */
17374 add_comp_dir_attribute (dw_die_ref die
)
17376 const char *wd
= get_src_pwd ();
17382 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
17386 wdlen
= strlen (wd
);
17387 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
17389 wd1
[wdlen
] = DIR_SEPARATOR
;
17390 wd1
[wdlen
+ 1] = 0;
17394 add_AT_string (die
, DW_AT_comp_dir
, remap_debug_filename (wd
));
17397 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
17401 lower_bound_default (void)
17403 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
17408 case DW_LANG_C_plus_plus
:
17410 case DW_LANG_ObjC_plus_plus
:
17413 case DW_LANG_Fortran77
:
17414 case DW_LANG_Fortran90
:
17415 case DW_LANG_Fortran95
:
17419 case DW_LANG_Python
:
17420 return dwarf_version
>= 4 ? 0 : -1;
17421 case DW_LANG_Ada95
:
17422 case DW_LANG_Ada83
:
17423 case DW_LANG_Cobol74
:
17424 case DW_LANG_Cobol85
:
17425 case DW_LANG_Pascal83
:
17426 case DW_LANG_Modula2
:
17428 return dwarf_version
>= 4 ? 1 : -1;
17434 /* Given a tree node describing an array bound (either lower or upper) output
17435 a representation for that bound. */
17438 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
17440 switch (TREE_CODE (bound
))
17445 /* All fixed-bounds are represented by INTEGER_CST nodes. */
17448 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
17451 /* Use the default if possible. */
17452 if (bound_attr
== DW_AT_lower_bound
17453 && host_integerp (bound
, 0)
17454 && (dflt
= lower_bound_default ()) != -1
17455 && tree_low_cst (bound
, 0) == dflt
)
17458 /* Otherwise represent the bound as an unsigned value with the
17459 precision of its type. The precision and signedness of the
17460 type will be necessary to re-interpret it unambiguously. */
17461 else if (prec
< HOST_BITS_PER_WIDE_INT
)
17463 unsigned HOST_WIDE_INT mask
17464 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
17465 add_AT_unsigned (subrange_die
, bound_attr
,
17466 TREE_INT_CST_LOW (bound
) & mask
);
17468 else if (prec
== HOST_BITS_PER_WIDE_INT
17469 || TREE_INT_CST_HIGH (bound
) == 0)
17470 add_AT_unsigned (subrange_die
, bound_attr
,
17471 TREE_INT_CST_LOW (bound
));
17473 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
17474 TREE_INT_CST_LOW (bound
));
17479 case VIEW_CONVERT_EXPR
:
17480 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
17490 dw_die_ref decl_die
= lookup_decl_die (bound
);
17492 /* ??? Can this happen, or should the variable have been bound
17493 first? Probably it can, since I imagine that we try to create
17494 the types of parameters in the order in which they exist in
17495 the list, and won't have created a forward reference to a
17496 later parameter. */
17497 if (decl_die
!= NULL
)
17499 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
17507 /* Otherwise try to create a stack operation procedure to
17508 evaluate the value of the array bound. */
17510 dw_die_ref ctx
, decl_die
;
17511 dw_loc_list_ref list
;
17513 list
= loc_list_from_tree (bound
, 2);
17514 if (list
== NULL
|| single_element_loc_list_p (list
))
17516 /* If DW_AT_*bound is not a reference nor constant, it is
17517 a DWARF expression rather than location description.
17518 For that loc_list_from_tree (bound, 0) is needed.
17519 If that fails to give a single element list,
17520 fall back to outputting this as a reference anyway. */
17521 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
17522 if (list2
&& single_element_loc_list_p (list2
))
17524 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
17531 if (current_function_decl
== 0)
17532 ctx
= comp_unit_die ();
17534 ctx
= lookup_decl_die (current_function_decl
);
17536 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
17537 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
17538 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
17539 add_AT_location_description (decl_die
, DW_AT_location
, list
);
17540 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
17546 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
17547 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
17548 Note that the block of subscript information for an array type also
17549 includes information about the element type of the given array type. */
17552 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
17554 unsigned dimension_number
;
17556 dw_die_ref subrange_die
;
17558 for (dimension_number
= 0;
17559 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
17560 type
= TREE_TYPE (type
), dimension_number
++)
17562 tree domain
= TYPE_DOMAIN (type
);
17564 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
17567 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
17568 and (in GNU C only) variable bounds. Handle all three forms
17570 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
17573 /* We have an array type with specified bounds. */
17574 lower
= TYPE_MIN_VALUE (domain
);
17575 upper
= TYPE_MAX_VALUE (domain
);
17577 /* Define the index type. */
17578 if (TREE_TYPE (domain
))
17580 /* ??? This is probably an Ada unnamed subrange type. Ignore the
17581 TREE_TYPE field. We can't emit debug info for this
17582 because it is an unnamed integral type. */
17583 if (TREE_CODE (domain
) == INTEGER_TYPE
17584 && TYPE_NAME (domain
) == NULL_TREE
17585 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
17586 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
17589 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
17593 /* ??? If upper is NULL, the array has unspecified length,
17594 but it does have a lower bound. This happens with Fortran
17596 Since the debugger is definitely going to need to know N
17597 to produce useful results, go ahead and output the lower
17598 bound solo, and hope the debugger can cope. */
17600 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
17602 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
17605 /* Otherwise we have an array type with an unspecified length. The
17606 DWARF-2 spec does not say how to handle this; let's just leave out the
17612 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
17616 switch (TREE_CODE (tree_node
))
17621 case ENUMERAL_TYPE
:
17624 case QUAL_UNION_TYPE
:
17625 size
= int_size_in_bytes (tree_node
);
17628 /* For a data member of a struct or union, the DW_AT_byte_size is
17629 generally given as the number of bytes normally allocated for an
17630 object of the *declared* type of the member itself. This is true
17631 even for bit-fields. */
17632 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
17635 gcc_unreachable ();
17638 /* Note that `size' might be -1 when we get to this point. If it is, that
17639 indicates that the byte size of the entity in question is variable. We
17640 have no good way of expressing this fact in Dwarf at the present time,
17641 so just let the -1 pass on through. */
17642 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
17645 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17646 which specifies the distance in bits from the highest order bit of the
17647 "containing object" for the bit-field to the highest order bit of the
17650 For any given bit-field, the "containing object" is a hypothetical object
17651 (of some integral or enum type) within which the given bit-field lives. The
17652 type of this hypothetical "containing object" is always the same as the
17653 declared type of the individual bit-field itself. The determination of the
17654 exact location of the "containing object" for a bit-field is rather
17655 complicated. It's handled by the `field_byte_offset' function (above).
17657 Note that it is the size (in bytes) of the hypothetical "containing object"
17658 which will be given in the DW_AT_byte_size attribute for this bit-field.
17659 (See `byte_size_attribute' above). */
17662 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
17664 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
17665 tree type
= DECL_BIT_FIELD_TYPE (decl
);
17666 HOST_WIDE_INT bitpos_int
;
17667 HOST_WIDE_INT highest_order_object_bit_offset
;
17668 HOST_WIDE_INT highest_order_field_bit_offset
;
17669 HOST_WIDE_INT bit_offset
;
17671 /* Must be a field and a bit field. */
17672 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
17674 /* We can't yet handle bit-fields whose offsets are variable, so if we
17675 encounter such things, just return without generating any attribute
17676 whatsoever. Likewise for variable or too large size. */
17677 if (! host_integerp (bit_position (decl
), 0)
17678 || ! host_integerp (DECL_SIZE (decl
), 1))
17681 bitpos_int
= int_bit_position (decl
);
17683 /* Note that the bit offset is always the distance (in bits) from the
17684 highest-order bit of the "containing object" to the highest-order bit of
17685 the bit-field itself. Since the "high-order end" of any object or field
17686 is different on big-endian and little-endian machines, the computation
17687 below must take account of these differences. */
17688 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
17689 highest_order_field_bit_offset
= bitpos_int
;
17691 if (! BYTES_BIG_ENDIAN
)
17693 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
17694 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
17698 = (! BYTES_BIG_ENDIAN
17699 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
17700 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
17702 if (bit_offset
< 0)
17703 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
17705 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
17708 /* For a FIELD_DECL node which represents a bit field, output an attribute
17709 which specifies the length in bits of the given field. */
17712 add_bit_size_attribute (dw_die_ref die
, tree decl
)
17714 /* Must be a field and a bit field. */
17715 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
17716 && DECL_BIT_FIELD_TYPE (decl
));
17718 if (host_integerp (DECL_SIZE (decl
), 1))
17719 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
17722 /* If the compiled language is ANSI C, then add a 'prototyped'
17723 attribute, if arg types are given for the parameters of a function. */
17726 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
17728 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
17729 && prototype_p (func_type
))
17730 add_AT_flag (die
, DW_AT_prototyped
, 1);
17733 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17734 by looking in either the type declaration or object declaration
17737 static inline dw_die_ref
17738 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
17740 dw_die_ref origin_die
= NULL
;
17742 if (TREE_CODE (origin
) != FUNCTION_DECL
)
17744 /* We may have gotten separated from the block for the inlined
17745 function, if we're in an exception handler or some such; make
17746 sure that the abstract function has been written out.
17748 Doing this for nested functions is wrong, however; functions are
17749 distinct units, and our context might not even be inline. */
17753 fn
= TYPE_STUB_DECL (fn
);
17755 fn
= decl_function_context (fn
);
17757 dwarf2out_abstract_function (fn
);
17760 if (DECL_P (origin
))
17761 origin_die
= lookup_decl_die (origin
);
17762 else if (TYPE_P (origin
))
17763 origin_die
= lookup_type_die (origin
);
17765 /* XXX: Functions that are never lowered don't always have correct block
17766 trees (in the case of java, they simply have no block tree, in some other
17767 languages). For these functions, there is nothing we can really do to
17768 output correct debug info for inlined functions in all cases. Rather
17769 than die, we'll just produce deficient debug info now, in that we will
17770 have variables without a proper abstract origin. In the future, when all
17771 functions are lowered, we should re-add a gcc_assert (origin_die)
17775 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
17779 /* We do not currently support the pure_virtual attribute. */
17782 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
17784 if (DECL_VINDEX (func_decl
))
17786 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
17788 if (host_integerp (DECL_VINDEX (func_decl
), 0))
17789 add_AT_loc (die
, DW_AT_vtable_elem_location
,
17790 new_loc_descr (DW_OP_constu
,
17791 tree_low_cst (DECL_VINDEX (func_decl
), 0),
17794 /* GNU extension: Record what type this method came from originally. */
17795 if (debug_info_level
> DINFO_LEVEL_TERSE
17796 && DECL_CONTEXT (func_decl
))
17797 add_AT_die_ref (die
, DW_AT_containing_type
,
17798 lookup_type_die (DECL_CONTEXT (func_decl
)));
17802 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
17803 given decl. This used to be a vendor extension until after DWARF 4
17804 standardized it. */
17807 add_linkage_attr (dw_die_ref die
, tree decl
)
17809 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
17811 /* Mimic what assemble_name_raw does with a leading '*'. */
17812 if (name
[0] == '*')
17815 if (dwarf_version
>= 4)
17816 add_AT_string (die
, DW_AT_linkage_name
, name
);
17818 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
17821 /* Add source coordinate attributes for the given decl. */
17824 add_src_coords_attributes (dw_die_ref die
, tree decl
)
17826 expanded_location s
;
17828 if (DECL_SOURCE_LOCATION (decl
) == UNKNOWN_LOCATION
)
17830 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17831 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
17832 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
17835 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
17838 add_linkage_name (dw_die_ref die
, tree decl
)
17840 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
17841 && TREE_PUBLIC (decl
)
17842 && !DECL_ABSTRACT (decl
)
17843 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
17844 && die
->die_tag
!= DW_TAG_member
)
17846 /* Defer until we have an assembler name set. */
17847 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
17849 limbo_die_node
*asm_name
;
17851 asm_name
= ggc_alloc_cleared_limbo_die_node ();
17852 asm_name
->die
= die
;
17853 asm_name
->created_for
= decl
;
17854 asm_name
->next
= deferred_asm_name
;
17855 deferred_asm_name
= asm_name
;
17857 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
17858 add_linkage_attr (die
, decl
);
17862 /* Add a DW_AT_name attribute and source coordinate attribute for the
17863 given decl, but only if it actually has a name. */
17866 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
17870 decl_name
= DECL_NAME (decl
);
17871 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
17873 const char *name
= dwarf2_name (decl
, 0);
17875 add_name_attribute (die
, name
);
17876 if (! DECL_ARTIFICIAL (decl
))
17877 add_src_coords_attributes (die
, decl
);
17879 add_linkage_name (die
, decl
);
17882 #ifdef VMS_DEBUGGING_INFO
17883 /* Get the function's name, as described by its RTL. This may be different
17884 from the DECL_NAME name used in the source file. */
17885 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
17887 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
17888 XEXP (DECL_RTL (decl
), 0));
17889 VEC_safe_push (rtx
, gc
, used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
17891 #endif /* VMS_DEBUGGING_INFO */
17894 #ifdef VMS_DEBUGGING_INFO
17895 /* Output the debug main pointer die for VMS */
17898 dwarf2out_vms_debug_main_pointer (void)
17900 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
17903 /* Allocate the VMS debug main subprogram die. */
17904 die
= ggc_alloc_cleared_die_node ();
17905 die
->die_tag
= DW_TAG_subprogram
;
17906 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
17907 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
17908 current_function_funcdef_no
);
17909 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
17911 /* Make it the first child of comp_unit_die (). */
17912 die
->die_parent
= comp_unit_die ();
17913 if (comp_unit_die ()->die_child
)
17915 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
17916 comp_unit_die ()->die_child
->die_sib
= die
;
17920 die
->die_sib
= die
;
17921 comp_unit_die ()->die_child
= die
;
17924 #endif /* VMS_DEBUGGING_INFO */
17926 /* Push a new declaration scope. */
17929 push_decl_scope (tree scope
)
17931 VEC_safe_push (tree
, gc
, decl_scope_table
, scope
);
17934 /* Pop a declaration scope. */
17937 pop_decl_scope (void)
17939 VEC_pop (tree
, decl_scope_table
);
17942 /* Return the DIE for the scope that immediately contains this type.
17943 Non-named types get global scope. Named types nested in other
17944 types get their containing scope if it's open, or global scope
17945 otherwise. All other types (i.e. function-local named types) get
17946 the current active scope. */
17949 scope_die_for (tree t
, dw_die_ref context_die
)
17951 dw_die_ref scope_die
= NULL
;
17952 tree containing_scope
;
17955 /* Non-types always go in the current scope. */
17956 gcc_assert (TYPE_P (t
));
17958 containing_scope
= TYPE_CONTEXT (t
);
17960 /* Use the containing namespace if it was passed in (for a declaration). */
17961 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
17963 if (context_die
== lookup_decl_die (containing_scope
))
17966 containing_scope
= NULL_TREE
;
17969 /* Ignore function type "scopes" from the C frontend. They mean that
17970 a tagged type is local to a parmlist of a function declarator, but
17971 that isn't useful to DWARF. */
17972 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
17973 containing_scope
= NULL_TREE
;
17975 if (SCOPE_FILE_SCOPE_P (containing_scope
))
17976 scope_die
= comp_unit_die ();
17977 else if (TYPE_P (containing_scope
))
17979 /* For types, we can just look up the appropriate DIE. But
17980 first we check to see if we're in the middle of emitting it
17981 so we know where the new DIE should go. */
17982 for (i
= VEC_length (tree
, decl_scope_table
) - 1; i
>= 0; --i
)
17983 if (VEC_index (tree
, decl_scope_table
, i
) == containing_scope
)
17988 gcc_assert (debug_info_level
<= DINFO_LEVEL_TERSE
17989 || TREE_ASM_WRITTEN (containing_scope
));
17990 /*We are not in the middle of emitting the type
17991 CONTAINING_SCOPE. Let's see if it's emitted already. */
17992 scope_die
= lookup_type_die (containing_scope
);
17994 /* If none of the current dies are suitable, we get file scope. */
17995 if (scope_die
== NULL
)
17996 scope_die
= comp_unit_die ();
17999 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
18002 scope_die
= context_die
;
18007 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
18010 local_scope_p (dw_die_ref context_die
)
18012 for (; context_die
; context_die
= context_die
->die_parent
)
18013 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
18014 || context_die
->die_tag
== DW_TAG_subprogram
)
18020 /* Returns nonzero if CONTEXT_DIE is a class. */
18023 class_scope_p (dw_die_ref context_die
)
18025 return (context_die
18026 && (context_die
->die_tag
== DW_TAG_structure_type
18027 || context_die
->die_tag
== DW_TAG_class_type
18028 || context_die
->die_tag
== DW_TAG_interface_type
18029 || context_die
->die_tag
== DW_TAG_union_type
));
18032 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
18033 whether or not to treat a DIE in this context as a declaration. */
18036 class_or_namespace_scope_p (dw_die_ref context_die
)
18038 return (class_scope_p (context_die
)
18039 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
18042 /* Many forms of DIEs require a "type description" attribute. This
18043 routine locates the proper "type descriptor" die for the type given
18044 by 'type', and adds a DW_AT_type attribute below the given die. */
18047 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
18048 int decl_volatile
, dw_die_ref context_die
)
18050 enum tree_code code
= TREE_CODE (type
);
18051 dw_die_ref type_die
= NULL
;
18053 /* ??? If this type is an unnamed subrange type of an integral, floating-point
18054 or fixed-point type, use the inner type. This is because we have no
18055 support for unnamed types in base_type_die. This can happen if this is
18056 an Ada subrange type. Correct solution is emit a subrange type die. */
18057 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
18058 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
18059 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
18061 if (code
== ERROR_MARK
18062 /* Handle a special case. For functions whose return type is void, we
18063 generate *no* type attribute. (Note that no object may have type
18064 `void', so this only applies to function return types). */
18065 || code
== VOID_TYPE
)
18068 type_die
= modified_type_die (type
,
18069 decl_const
|| TYPE_READONLY (type
),
18070 decl_volatile
|| TYPE_VOLATILE (type
),
18073 if (type_die
!= NULL
)
18074 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
18077 /* Given an object die, add the calling convention attribute for the
18078 function call type. */
18080 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
18082 enum dwarf_calling_convention value
= DW_CC_normal
;
18084 value
= ((enum dwarf_calling_convention
)
18085 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
18088 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
18090 /* DWARF 2 doesn't provide a way to identify a program's source-level
18091 entry point. DW_AT_calling_convention attributes are only meant
18092 to describe functions' calling conventions. However, lacking a
18093 better way to signal the Fortran main program, we used this for
18094 a long time, following existing custom. Now, DWARF 4 has
18095 DW_AT_main_subprogram, which we add below, but some tools still
18096 rely on the old way, which we thus keep. */
18097 value
= DW_CC_program
;
18099 if (dwarf_version
>= 4 || !dwarf_strict
)
18100 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
18103 /* Only add the attribute if the backend requests it, and
18104 is not DW_CC_normal. */
18105 if (value
&& (value
!= DW_CC_normal
))
18106 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
18109 /* Given a tree pointer to a struct, class, union, or enum type node, return
18110 a pointer to the (string) tag name for the given type, or zero if the type
18111 was declared without a tag. */
18113 static const char *
18114 type_tag (const_tree type
)
18116 const char *name
= 0;
18118 if (TYPE_NAME (type
) != 0)
18122 /* Find the IDENTIFIER_NODE for the type name. */
18123 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
18124 && !TYPE_NAMELESS (type
))
18125 t
= TYPE_NAME (type
);
18127 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
18128 a TYPE_DECL node, regardless of whether or not a `typedef' was
18130 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
18131 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
18133 /* We want to be extra verbose. Don't call dwarf_name if
18134 DECL_NAME isn't set. The default hook for decl_printable_name
18135 doesn't like that, and in this context it's correct to return
18136 0, instead of "<anonymous>" or the like. */
18137 if (DECL_NAME (TYPE_NAME (type
))
18138 && !DECL_NAMELESS (TYPE_NAME (type
)))
18139 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
18142 /* Now get the name as a string, or invent one. */
18143 if (!name
&& t
!= 0)
18144 name
= IDENTIFIER_POINTER (t
);
18147 return (name
== 0 || *name
== '\0') ? 0 : name
;
18150 /* Return the type associated with a data member, make a special check
18151 for bit field types. */
18154 member_declared_type (const_tree member
)
18156 return (DECL_BIT_FIELD_TYPE (member
)
18157 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
18160 /* Get the decl's label, as described by its RTL. This may be different
18161 from the DECL_NAME name used in the source file. */
18164 static const char *
18165 decl_start_label (tree decl
)
18168 const char *fnname
;
18170 x
= DECL_RTL (decl
);
18171 gcc_assert (MEM_P (x
));
18174 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
18176 fnname
= XSTR (x
, 0);
18181 /* These routines generate the internal representation of the DIE's for
18182 the compilation unit. Debugging information is collected by walking
18183 the declaration trees passed in from dwarf2out_decl(). */
18186 gen_array_type_die (tree type
, dw_die_ref context_die
)
18188 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
18189 dw_die_ref array_die
;
18191 /* GNU compilers represent multidimensional array types as sequences of one
18192 dimensional array types whose element types are themselves array types.
18193 We sometimes squish that down to a single array_type DIE with multiple
18194 subscripts in the Dwarf debugging info. The draft Dwarf specification
18195 say that we are allowed to do this kind of compression in C, because
18196 there is no difference between an array of arrays and a multidimensional
18197 array. We don't do this for Ada to remain as close as possible to the
18198 actual representation, which is especially important against the language
18199 flexibilty wrt arrays of variable size. */
18201 bool collapse_nested_arrays
= !is_ada ();
18204 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
18205 DW_TAG_string_type doesn't have DW_AT_type attribute). */
18206 if (TYPE_STRING_FLAG (type
)
18207 && TREE_CODE (type
) == ARRAY_TYPE
18209 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
18211 HOST_WIDE_INT size
;
18213 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
18214 add_name_attribute (array_die
, type_tag (type
));
18215 equate_type_number_to_die (type
, array_die
);
18216 size
= int_size_in_bytes (type
);
18218 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
18219 else if (TYPE_DOMAIN (type
) != NULL_TREE
18220 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
18221 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
18223 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
18224 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
18226 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
18227 if (loc
&& size
> 0)
18229 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
18230 if (size
!= DWARF2_ADDR_SIZE
)
18231 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
18237 /* ??? The SGI dwarf reader fails for array of array of enum types
18238 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
18239 array type comes before the outer array type. We thus call gen_type_die
18240 before we new_die and must prevent nested array types collapsing for this
18243 #ifdef MIPS_DEBUGGING_INFO
18244 gen_type_die (TREE_TYPE (type
), context_die
);
18245 collapse_nested_arrays
= false;
18248 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
18249 add_name_attribute (array_die
, type_tag (type
));
18250 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
18251 equate_type_number_to_die (type
, array_die
);
18253 if (TREE_CODE (type
) == VECTOR_TYPE
)
18254 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
18256 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18258 && TREE_CODE (type
) == ARRAY_TYPE
18259 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
18260 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
18261 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
18264 /* We default the array ordering. SDB will probably do
18265 the right things even if DW_AT_ordering is not present. It's not even
18266 an issue until we start to get into multidimensional arrays anyway. If
18267 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
18268 then we'll have to put the DW_AT_ordering attribute back in. (But if
18269 and when we find out that we need to put these in, we will only do so
18270 for multidimensional arrays. */
18271 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
18274 #ifdef MIPS_DEBUGGING_INFO
18275 /* The SGI compilers handle arrays of unknown bound by setting
18276 AT_declaration and not emitting any subrange DIEs. */
18277 if (TREE_CODE (type
) == ARRAY_TYPE
18278 && ! TYPE_DOMAIN (type
))
18279 add_AT_flag (array_die
, DW_AT_declaration
, 1);
18282 if (TREE_CODE (type
) == VECTOR_TYPE
)
18284 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
18285 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
18286 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
18287 add_bound_info (subrange_die
, DW_AT_upper_bound
,
18288 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
18291 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
18293 /* Add representation of the type of the elements of this array type and
18294 emit the corresponding DIE if we haven't done it already. */
18295 element_type
= TREE_TYPE (type
);
18296 if (collapse_nested_arrays
)
18297 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
18299 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
18301 element_type
= TREE_TYPE (element_type
);
18304 #ifndef MIPS_DEBUGGING_INFO
18305 gen_type_die (element_type
, context_die
);
18308 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
18310 if (get_AT (array_die
, DW_AT_name
))
18311 add_pubtype (type
, array_die
);
18314 static dw_loc_descr_ref
18315 descr_info_loc (tree val
, tree base_decl
)
18317 HOST_WIDE_INT size
;
18318 dw_loc_descr_ref loc
, loc2
;
18319 enum dwarf_location_atom op
;
18321 if (val
== base_decl
)
18322 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
18324 switch (TREE_CODE (val
))
18327 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
18329 return loc_descriptor_from_tree (val
, 0);
18331 if (host_integerp (val
, 0))
18332 return int_loc_descriptor (tree_low_cst (val
, 0));
18335 size
= int_size_in_bytes (TREE_TYPE (val
));
18338 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
18341 if (size
== DWARF2_ADDR_SIZE
)
18342 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
18344 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
18346 case POINTER_PLUS_EXPR
:
18348 if (host_integerp (TREE_OPERAND (val
, 1), 1)
18349 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
18352 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
18355 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
18361 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
18364 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
18367 add_loc_descr (&loc
, loc2
);
18368 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
18390 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
18391 tree val
, tree base_decl
)
18393 dw_loc_descr_ref loc
;
18395 if (host_integerp (val
, 0))
18397 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
18401 loc
= descr_info_loc (val
, base_decl
);
18405 add_AT_loc (die
, attr
, loc
);
18408 /* This routine generates DIE for array with hidden descriptor, details
18409 are filled into *info by a langhook. */
18412 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
18413 dw_die_ref context_die
)
18415 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
18416 dw_die_ref array_die
;
18419 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
18420 add_name_attribute (array_die
, type_tag (type
));
18421 equate_type_number_to_die (type
, array_die
);
18423 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18425 && info
->ndimensions
>= 2)
18426 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
18428 if (info
->data_location
)
18429 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
18431 if (info
->associated
)
18432 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
18434 if (info
->allocated
)
18435 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
18438 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
18440 dw_die_ref subrange_die
18441 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
18443 if (info
->dimen
[dim
].lower_bound
)
18445 /* If it is the default value, omit it. */
18448 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
18449 && (dflt
= lower_bound_default ()) != -1
18450 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
18453 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
18454 info
->dimen
[dim
].lower_bound
,
18457 if (info
->dimen
[dim
].upper_bound
)
18458 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
18459 info
->dimen
[dim
].upper_bound
,
18461 if (info
->dimen
[dim
].stride
)
18462 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
18463 info
->dimen
[dim
].stride
,
18467 gen_type_die (info
->element_type
, context_die
);
18468 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
18470 if (get_AT (array_die
, DW_AT_name
))
18471 add_pubtype (type
, array_die
);
18476 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
18478 tree origin
= decl_ultimate_origin (decl
);
18479 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
18481 if (origin
!= NULL
)
18482 add_abstract_origin_attribute (decl_die
, origin
);
18485 add_name_and_src_coords_attributes (decl_die
, decl
);
18486 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
18487 0, 0, context_die
);
18490 if (DECL_ABSTRACT (decl
))
18491 equate_decl_number_to_die (decl
, decl_die
);
18493 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
18497 /* Walk through the list of incomplete types again, trying once more to
18498 emit full debugging info for them. */
18501 retry_incomplete_types (void)
18505 for (i
= VEC_length (tree
, incomplete_types
) - 1; i
>= 0; i
--)
18506 if (should_emit_struct_debug (VEC_index (tree
, incomplete_types
, i
),
18507 DINFO_USAGE_DIR_USE
))
18508 gen_type_die (VEC_index (tree
, incomplete_types
, i
), comp_unit_die ());
18511 /* Determine what tag to use for a record type. */
18513 static enum dwarf_tag
18514 record_type_tag (tree type
)
18516 if (! lang_hooks
.types
.classify_record
)
18517 return DW_TAG_structure_type
;
18519 switch (lang_hooks
.types
.classify_record (type
))
18521 case RECORD_IS_STRUCT
:
18522 return DW_TAG_structure_type
;
18524 case RECORD_IS_CLASS
:
18525 return DW_TAG_class_type
;
18527 case RECORD_IS_INTERFACE
:
18528 if (dwarf_version
>= 3 || !dwarf_strict
)
18529 return DW_TAG_interface_type
;
18530 return DW_TAG_structure_type
;
18533 gcc_unreachable ();
18537 /* Generate a DIE to represent an enumeration type. Note that these DIEs
18538 include all of the information about the enumeration values also. Each
18539 enumerated type name/value is listed as a child of the enumerated type
18543 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
18545 dw_die_ref type_die
= lookup_type_die (type
);
18547 if (type_die
== NULL
)
18549 type_die
= new_die (DW_TAG_enumeration_type
,
18550 scope_die_for (type
, context_die
), type
);
18551 equate_type_number_to_die (type
, type_die
);
18552 add_name_attribute (type_die
, type_tag (type
));
18553 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
18554 if (dwarf_version
>= 4 || !dwarf_strict
)
18556 if (ENUM_IS_SCOPED (type
))
18557 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
18558 if (ENUM_IS_OPAQUE (type
))
18559 add_AT_flag (type_die
, DW_AT_declaration
, 1);
18562 else if (! TYPE_SIZE (type
))
18565 remove_AT (type_die
, DW_AT_declaration
);
18567 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
18568 given enum type is incomplete, do not generate the DW_AT_byte_size
18569 attribute or the DW_AT_element_list attribute. */
18570 if (TYPE_SIZE (type
))
18574 TREE_ASM_WRITTEN (type
) = 1;
18575 add_byte_size_attribute (type_die
, type
);
18576 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
18578 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
18579 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
18582 /* If the first reference to this type was as the return type of an
18583 inline function, then it may not have a parent. Fix this now. */
18584 if (type_die
->die_parent
== NULL
)
18585 add_child_die (scope_die_for (type
, context_die
), type_die
);
18587 for (link
= TYPE_VALUES (type
);
18588 link
!= NULL
; link
= TREE_CHAIN (link
))
18590 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
18591 tree value
= TREE_VALUE (link
);
18593 add_name_attribute (enum_die
,
18594 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
18596 if (TREE_CODE (value
) == CONST_DECL
)
18597 value
= DECL_INITIAL (value
);
18599 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
18600 /* DWARF2 does not provide a way of indicating whether or
18601 not enumeration constants are signed or unsigned. GDB
18602 always assumes the values are signed, so we output all
18603 values as if they were signed. That means that
18604 enumeration constants with very large unsigned values
18605 will appear to have negative values in the debugger. */
18606 add_AT_int (enum_die
, DW_AT_const_value
,
18607 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
18611 add_AT_flag (type_die
, DW_AT_declaration
, 1);
18613 if (get_AT (type_die
, DW_AT_name
))
18614 add_pubtype (type
, type_die
);
18619 /* Generate a DIE to represent either a real live formal parameter decl or to
18620 represent just the type of some formal parameter position in some function
18623 Note that this routine is a bit unusual because its argument may be a
18624 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
18625 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
18626 node. If it's the former then this function is being called to output a
18627 DIE to represent a formal parameter object (or some inlining thereof). If
18628 it's the latter, then this function is only being called to output a
18629 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
18630 argument type of some subprogram type.
18631 If EMIT_NAME_P is true, name and source coordinate attributes
18635 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
18636 dw_die_ref context_die
)
18638 tree node_or_origin
= node
? node
: origin
;
18639 tree ultimate_origin
;
18640 dw_die_ref parm_die
18641 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
18643 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
18645 case tcc_declaration
:
18646 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
18647 if (node
|| ultimate_origin
)
18648 origin
= ultimate_origin
;
18649 if (origin
!= NULL
)
18650 add_abstract_origin_attribute (parm_die
, origin
);
18651 else if (emit_name_p
)
18652 add_name_and_src_coords_attributes (parm_die
, node
);
18654 || (! DECL_ABSTRACT (node_or_origin
)
18655 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
18656 decl_function_context
18657 (node_or_origin
))))
18659 tree type
= TREE_TYPE (node_or_origin
);
18660 if (decl_by_reference_p (node_or_origin
))
18661 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
18664 add_type_attribute (parm_die
, type
,
18665 TREE_READONLY (node_or_origin
),
18666 TREE_THIS_VOLATILE (node_or_origin
),
18669 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
18670 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18672 if (node
&& node
!= origin
)
18673 equate_decl_number_to_die (node
, parm_die
);
18674 if (! DECL_ABSTRACT (node_or_origin
))
18675 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
18676 node
== NULL
, DW_AT_location
);
18681 /* We were called with some kind of a ..._TYPE node. */
18682 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
18686 gcc_unreachable ();
18692 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18693 children DW_TAG_formal_parameter DIEs representing the arguments of the
18696 PARM_PACK must be a function parameter pack.
18697 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18698 must point to the subsequent arguments of the function PACK_ARG belongs to.
18699 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18700 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18701 following the last one for which a DIE was generated. */
18704 gen_formal_parameter_pack_die (tree parm_pack
,
18706 dw_die_ref subr_die
,
18710 dw_die_ref parm_pack_die
;
18712 gcc_assert (parm_pack
18713 && lang_hooks
.function_parameter_pack_p (parm_pack
)
18716 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
18717 add_src_coords_attributes (parm_pack_die
, parm_pack
);
18719 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
18721 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
18724 gen_formal_parameter_die (arg
, NULL
,
18725 false /* Don't emit name attribute. */,
18730 return parm_pack_die
;
18733 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18734 at the end of an (ANSI prototyped) formal parameters list. */
18737 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
18739 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
18742 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18743 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18744 parameters as specified in some function type specification (except for
18745 those which appear as part of a function *definition*). */
18748 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
18751 tree formal_type
= NULL
;
18752 tree first_parm_type
;
18755 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
18757 arg
= DECL_ARGUMENTS (function_or_method_type
);
18758 function_or_method_type
= TREE_TYPE (function_or_method_type
);
18763 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
18765 /* Make our first pass over the list of formal parameter types and output a
18766 DW_TAG_formal_parameter DIE for each one. */
18767 for (link
= first_parm_type
; link
; )
18769 dw_die_ref parm_die
;
18771 formal_type
= TREE_VALUE (link
);
18772 if (formal_type
== void_type_node
)
18775 /* Output a (nameless) DIE to represent the formal parameter itself. */
18776 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
18777 true /* Emit name attribute. */,
18779 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
18780 && link
== first_parm_type
)
18782 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18783 if (dwarf_version
>= 3 || !dwarf_strict
)
18784 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
18786 else if (arg
&& DECL_ARTIFICIAL (arg
))
18787 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18789 link
= TREE_CHAIN (link
);
18791 arg
= DECL_CHAIN (arg
);
18794 /* If this function type has an ellipsis, add a
18795 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18796 if (formal_type
!= void_type_node
)
18797 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
18799 /* Make our second (and final) pass over the list of formal parameter types
18800 and output DIEs to represent those types (as necessary). */
18801 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
18802 link
&& TREE_VALUE (link
);
18803 link
= TREE_CHAIN (link
))
18804 gen_type_die (TREE_VALUE (link
), context_die
);
18807 /* We want to generate the DIE for TYPE so that we can generate the
18808 die for MEMBER, which has been defined; we will need to refer back
18809 to the member declaration nested within TYPE. If we're trying to
18810 generate minimal debug info for TYPE, processing TYPE won't do the
18811 trick; we need to attach the member declaration by hand. */
18814 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
18816 gen_type_die (type
, context_die
);
18818 /* If we're trying to avoid duplicate debug info, we may not have
18819 emitted the member decl for this function. Emit it now. */
18820 if (TYPE_STUB_DECL (type
)
18821 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
18822 && ! lookup_decl_die (member
))
18824 dw_die_ref type_die
;
18825 gcc_assert (!decl_ultimate_origin (member
));
18827 push_decl_scope (type
);
18828 type_die
= lookup_type_die_strip_naming_typedef (type
);
18829 if (TREE_CODE (member
) == FUNCTION_DECL
)
18830 gen_subprogram_die (member
, type_die
);
18831 else if (TREE_CODE (member
) == FIELD_DECL
)
18833 /* Ignore the nameless fields that are used to skip bits but handle
18834 C++ anonymous unions and structs. */
18835 if (DECL_NAME (member
) != NULL_TREE
18836 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
18837 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
18839 gen_type_die (member_declared_type (member
), type_die
);
18840 gen_field_die (member
, type_die
);
18844 gen_variable_die (member
, NULL_TREE
, type_die
);
18850 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18851 may later generate inlined and/or out-of-line instances of. */
18854 dwarf2out_abstract_function (tree decl
)
18856 dw_die_ref old_die
;
18860 htab_t old_decl_loc_table
;
18861 htab_t old_cached_dw_loc_list_table
;
18862 int old_call_site_count
, old_tail_call_site_count
;
18863 struct call_arg_loc_node
*old_call_arg_locations
;
18865 /* Make sure we have the actual abstract inline, not a clone. */
18866 decl
= DECL_ORIGIN (decl
);
18868 old_die
= lookup_decl_die (decl
);
18869 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
18870 /* We've already generated the abstract instance. */
18873 /* We can be called while recursively when seeing block defining inlined subroutine
18874 DIE. Be sure to not clobber the outer location table nor use it or we would
18875 get locations in abstract instantces. */
18876 old_decl_loc_table
= decl_loc_table
;
18877 decl_loc_table
= NULL
;
18878 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
18879 cached_dw_loc_list_table
= NULL
;
18880 old_call_arg_locations
= call_arg_locations
;
18881 call_arg_locations
= NULL
;
18882 old_call_site_count
= call_site_count
;
18883 call_site_count
= -1;
18884 old_tail_call_site_count
= tail_call_site_count
;
18885 tail_call_site_count
= -1;
18887 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18888 we don't get confused by DECL_ABSTRACT. */
18889 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18891 context
= decl_class_context (decl
);
18893 gen_type_die_for_member
18894 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
18897 /* Pretend we've just finished compiling this function. */
18898 save_fn
= current_function_decl
;
18899 current_function_decl
= decl
;
18900 push_cfun (DECL_STRUCT_FUNCTION (decl
));
18902 was_abstract
= DECL_ABSTRACT (decl
);
18903 set_decl_abstract_flags (decl
, 1);
18904 dwarf2out_decl (decl
);
18905 if (! was_abstract
)
18906 set_decl_abstract_flags (decl
, 0);
18908 current_function_decl
= save_fn
;
18909 decl_loc_table
= old_decl_loc_table
;
18910 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
18911 call_arg_locations
= old_call_arg_locations
;
18912 call_site_count
= old_call_site_count
;
18913 tail_call_site_count
= old_tail_call_site_count
;
18917 /* Helper function of premark_used_types() which gets called through
18920 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18921 marked as unused by prune_unused_types. */
18924 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
18929 type
= (tree
) *slot
;
18930 die
= lookup_type_die (type
);
18932 die
->die_perennial_p
= 1;
18936 /* Helper function of premark_types_used_by_global_vars which gets called
18937 through htab_traverse.
18939 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18940 marked as unused by prune_unused_types. The DIE of the type is marked
18941 only if the global variable using the type will actually be emitted. */
18944 premark_types_used_by_global_vars_helper (void **slot
,
18945 void *data ATTRIBUTE_UNUSED
)
18947 struct types_used_by_vars_entry
*entry
;
18950 entry
= (struct types_used_by_vars_entry
*) *slot
;
18951 gcc_assert (entry
->type
!= NULL
18952 && entry
->var_decl
!= NULL
);
18953 die
= lookup_type_die (entry
->type
);
18956 /* Ask cgraph if the global variable really is to be emitted.
18957 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18958 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
18959 if (node
&& node
->needed
)
18961 die
->die_perennial_p
= 1;
18962 /* Keep the parent DIEs as well. */
18963 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
18964 die
->die_perennial_p
= 1;
18970 /* Mark all members of used_types_hash as perennial. */
18973 premark_used_types (void)
18975 if (cfun
&& cfun
->used_types_hash
)
18976 htab_traverse (cfun
->used_types_hash
, premark_used_types_helper
, NULL
);
18979 /* Mark all members of types_used_by_vars_entry as perennial. */
18982 premark_types_used_by_global_vars (void)
18984 if (types_used_by_vars_hash
)
18985 htab_traverse (types_used_by_vars_hash
,
18986 premark_types_used_by_global_vars_helper
, NULL
);
18989 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
18990 for CA_LOC call arg loc node. */
18993 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
18994 struct call_arg_loc_node
*ca_loc
)
18996 dw_die_ref stmt_die
= NULL
, die
;
18997 tree block
= ca_loc
->block
;
19000 && block
!= DECL_INITIAL (decl
)
19001 && TREE_CODE (block
) == BLOCK
)
19003 if (VEC_length (dw_die_ref
, block_map
) > BLOCK_NUMBER (block
))
19004 stmt_die
= VEC_index (dw_die_ref
, block_map
, BLOCK_NUMBER (block
));
19007 block
= BLOCK_SUPERCONTEXT (block
);
19009 if (stmt_die
== NULL
)
19010 stmt_die
= subr_die
;
19011 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
19012 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
19013 if (ca_loc
->tail_call_p
)
19014 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
19015 if (ca_loc
->symbol_ref
)
19017 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
19019 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
19021 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
);
19026 /* Generate a DIE to represent a declared function (either file-scope or
19030 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
19032 tree origin
= decl_ultimate_origin (decl
);
19033 dw_die_ref subr_die
;
19035 dw_die_ref old_die
= lookup_decl_die (decl
);
19036 int declaration
= (current_function_decl
!= decl
19037 || class_or_namespace_scope_p (context_die
));
19039 premark_used_types ();
19041 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
19042 started to generate the abstract instance of an inline, decided to output
19043 its containing class, and proceeded to emit the declaration of the inline
19044 from the member list for the class. If so, DECLARATION takes priority;
19045 we'll get back to the abstract instance when done with the class. */
19047 /* The class-scope declaration DIE must be the primary DIE. */
19048 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
19051 gcc_assert (!old_die
);
19054 /* Now that the C++ front end lazily declares artificial member fns, we
19055 might need to retrofit the declaration into its class. */
19056 if (!declaration
&& !origin
&& !old_die
19057 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
19058 && !class_or_namespace_scope_p (context_die
)
19059 && debug_info_level
> DINFO_LEVEL_TERSE
)
19060 old_die
= force_decl_die (decl
);
19062 if (origin
!= NULL
)
19064 gcc_assert (!declaration
|| local_scope_p (context_die
));
19066 /* Fixup die_parent for the abstract instance of a nested
19067 inline function. */
19068 if (old_die
&& old_die
->die_parent
== NULL
)
19069 add_child_die (context_die
, old_die
);
19071 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
19072 add_abstract_origin_attribute (subr_die
, origin
);
19076 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
19077 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
19079 if (!get_AT_flag (old_die
, DW_AT_declaration
)
19080 /* We can have a normal definition following an inline one in the
19081 case of redefinition of GNU C extern inlines.
19082 It seems reasonable to use AT_specification in this case. */
19083 && !get_AT (old_die
, DW_AT_inline
))
19085 /* Detect and ignore this case, where we are trying to output
19086 something we have already output. */
19090 /* If the definition comes from the same place as the declaration,
19091 maybe use the old DIE. We always want the DIE for this function
19092 that has the *_pc attributes to be under comp_unit_die so the
19093 debugger can find it. We also need to do this for abstract
19094 instances of inlines, since the spec requires the out-of-line copy
19095 to have the same parent. For local class methods, this doesn't
19096 apply; we just use the old DIE. */
19097 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
19098 && (DECL_ARTIFICIAL (decl
)
19099 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
19100 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
19101 == (unsigned) s
.line
))))
19103 subr_die
= old_die
;
19105 /* Clear out the declaration attribute and the formal parameters.
19106 Do not remove all children, because it is possible that this
19107 declaration die was forced using force_decl_die(). In such
19108 cases die that forced declaration die (e.g. TAG_imported_module)
19109 is one of the children that we do not want to remove. */
19110 remove_AT (subr_die
, DW_AT_declaration
);
19111 remove_AT (subr_die
, DW_AT_object_pointer
);
19112 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
19116 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
19117 add_AT_specification (subr_die
, old_die
);
19118 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
19119 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
19120 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
19121 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
19126 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
19128 if (TREE_PUBLIC (decl
))
19129 add_AT_flag (subr_die
, DW_AT_external
, 1);
19131 add_name_and_src_coords_attributes (subr_die
, decl
);
19132 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19134 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
19135 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
19136 0, 0, context_die
);
19139 add_pure_or_virtual_attribute (subr_die
, decl
);
19140 if (DECL_ARTIFICIAL (decl
))
19141 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
19143 add_accessibility_attribute (subr_die
, decl
);
19148 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
19150 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
19152 /* If this is an explicit function declaration then generate
19153 a DW_AT_explicit attribute. */
19154 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
19155 && (dwarf_version
>= 3 || !dwarf_strict
))
19156 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
19158 /* The first time we see a member function, it is in the context of
19159 the class to which it belongs. We make sure of this by emitting
19160 the class first. The next time is the definition, which is
19161 handled above. The two may come from the same source text.
19163 Note that force_decl_die() forces function declaration die. It is
19164 later reused to represent definition. */
19165 equate_decl_number_to_die (decl
, subr_die
);
19168 else if (DECL_ABSTRACT (decl
))
19170 if (DECL_DECLARED_INLINE_P (decl
))
19172 if (cgraph_function_possibly_inlined_p (decl
))
19173 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
19175 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
19179 if (cgraph_function_possibly_inlined_p (decl
))
19180 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
19182 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
19185 if (DECL_DECLARED_INLINE_P (decl
)
19186 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
19187 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
19189 equate_decl_number_to_die (decl
, subr_die
);
19191 else if (!DECL_EXTERNAL (decl
))
19193 HOST_WIDE_INT cfa_fb_offset
;
19195 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
19196 equate_decl_number_to_die (decl
, subr_die
);
19198 if (!flag_reorder_blocks_and_partition
)
19200 dw_fde_ref fde
= &fde_table
[current_funcdef_fde
];
19201 if (fde
->dw_fde_begin
)
19203 /* We have already generated the labels. */
19204 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, fde
->dw_fde_begin
);
19205 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, fde
->dw_fde_end
);
19209 /* Create start/end labels and add the range. */
19210 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
19211 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
19212 current_function_funcdef_no
);
19213 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
19214 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
19215 current_function_funcdef_no
);
19216 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
19219 #if VMS_DEBUGGING_INFO
19220 /* HP OpenVMS Industry Standard 64: DWARF Extensions
19221 Section 2.3 Prologue and Epilogue Attributes:
19222 When a breakpoint is set on entry to a function, it is generally
19223 desirable for execution to be suspended, not on the very first
19224 instruction of the function, but rather at a point after the
19225 function's frame has been set up, after any language defined local
19226 declaration processing has been completed, and before execution of
19227 the first statement of the function begins. Debuggers generally
19228 cannot properly determine where this point is. Similarly for a
19229 breakpoint set on exit from a function. The prologue and epilogue
19230 attributes allow a compiler to communicate the location(s) to use. */
19233 if (fde
->dw_fde_vms_end_prologue
)
19234 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
19235 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
19237 if (fde
->dw_fde_vms_begin_epilogue
)
19238 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
19239 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
19243 add_pubname (decl
, subr_die
);
19246 { /* Generate pubnames entries for the split function code
19248 dw_fde_ref fde
= &fde_table
[current_funcdef_fde
];
19250 if (fde
->dw_fde_second_begin
)
19252 if (dwarf_version
>= 3 || !dwarf_strict
)
19254 /* We should use ranges for non-contiguous code section
19255 addresses. Use the actual code range for the initial
19256 section, since the HOT/COLD labels might precede an
19257 alignment offset. */
19258 bool range_list_added
= false;
19259 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
19260 fde
->dw_fde_end
, &range_list_added
);
19261 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
19262 fde
->dw_fde_second_end
,
19263 &range_list_added
);
19264 add_pubname (decl
, subr_die
);
19265 if (range_list_added
)
19270 /* There is no real support in DW2 for this .. so we make
19271 a work-around. First, emit the pub name for the segment
19272 containing the function label. Then make and emit a
19273 simplified subprogram DIE for the second segment with the
19274 name pre-fixed by __hot/cold_sect_of_. We use the same
19275 linkage name for the second die so that gdb will find both
19276 sections when given "b foo". */
19277 const char *name
= NULL
;
19278 tree decl_name
= DECL_NAME (decl
);
19279 dw_die_ref seg_die
;
19281 /* Do the 'primary' section. */
19282 add_AT_lbl_id (subr_die
, DW_AT_low_pc
,
19283 fde
->dw_fde_begin
);
19284 add_AT_lbl_id (subr_die
, DW_AT_high_pc
,
19287 add_pubname (decl
, subr_die
);
19289 /* Build a minimal DIE for the secondary section. */
19290 seg_die
= new_die (DW_TAG_subprogram
,
19291 subr_die
->die_parent
, decl
);
19293 if (TREE_PUBLIC (decl
))
19294 add_AT_flag (seg_die
, DW_AT_external
, 1);
19296 if (decl_name
!= NULL
19297 && IDENTIFIER_POINTER (decl_name
) != NULL
)
19299 name
= dwarf2_name (decl
, 1);
19300 if (! DECL_ARTIFICIAL (decl
))
19301 add_src_coords_attributes (seg_die
, decl
);
19303 add_linkage_name (seg_die
, decl
);
19305 gcc_assert (name
!= NULL
);
19306 add_pure_or_virtual_attribute (seg_die
, decl
);
19307 if (DECL_ARTIFICIAL (decl
))
19308 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
19310 name
= concat ("__second_sect_of_", name
, NULL
);
19311 add_AT_lbl_id (seg_die
, DW_AT_low_pc
,
19312 fde
->dw_fde_second_begin
);
19313 add_AT_lbl_id (seg_die
, DW_AT_high_pc
,
19314 fde
->dw_fde_second_end
);
19315 add_name_attribute (seg_die
, name
);
19316 add_pubname_string (name
, seg_die
);
19321 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, fde
->dw_fde_begin
);
19322 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, fde
->dw_fde_end
);
19323 add_pubname (decl
, subr_die
);
19327 #ifdef MIPS_DEBUGGING_INFO
19328 /* Add a reference to the FDE for this routine. */
19329 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
19332 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
19334 /* We define the "frame base" as the function's CFA. This is more
19335 convenient for several reasons: (1) It's stable across the prologue
19336 and epilogue, which makes it better than just a frame pointer,
19337 (2) With dwarf3, there exists a one-byte encoding that allows us
19338 to reference the .debug_frame data by proxy, but failing that,
19339 (3) We can at least reuse the code inspection and interpretation
19340 code that determines the CFA position at various points in the
19342 if (dwarf_version
>= 3)
19344 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
19345 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
19349 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
19350 if (list
->dw_loc_next
)
19351 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
19353 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
19356 /* Compute a displacement from the "steady-state frame pointer" to
19357 the CFA. The former is what all stack slots and argument slots
19358 will reference in the rtl; the later is what we've told the
19359 debugger about. We'll need to adjust all frame_base references
19360 by this displacement. */
19361 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
19363 if (cfun
->static_chain_decl
)
19364 add_AT_location_description (subr_die
, DW_AT_static_link
,
19365 loc_list_from_tree (cfun
->static_chain_decl
, 2));
19368 /* Generate child dies for template paramaters. */
19369 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19370 gen_generic_params_dies (decl
);
19372 /* Now output descriptions of the arguments for this function. This gets
19373 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
19374 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
19375 `...' at the end of the formal parameter list. In order to find out if
19376 there was a trailing ellipsis or not, we must instead look at the type
19377 associated with the FUNCTION_DECL. This will be a node of type
19378 FUNCTION_TYPE. If the chain of type nodes hanging off of this
19379 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
19380 an ellipsis at the end. */
19382 /* In the case where we are describing a mere function declaration, all we
19383 need to do here (and all we *can* do here) is to describe the *types* of
19384 its formal parameters. */
19385 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19387 else if (declaration
)
19388 gen_formal_types_die (decl
, subr_die
);
19391 /* Generate DIEs to represent all known formal parameters. */
19392 tree parm
= DECL_ARGUMENTS (decl
);
19393 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
19394 tree generic_decl_parm
= generic_decl
19395 ? DECL_ARGUMENTS (generic_decl
)
19398 /* Now we want to walk the list of parameters of the function and
19399 emit their relevant DIEs.
19401 We consider the case of DECL being an instance of a generic function
19402 as well as it being a normal function.
19404 If DECL is an instance of a generic function we walk the
19405 parameters of the generic function declaration _and_ the parameters of
19406 DECL itself. This is useful because we want to emit specific DIEs for
19407 function parameter packs and those are declared as part of the
19408 generic function declaration. In that particular case,
19409 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
19410 That DIE has children DIEs representing the set of arguments
19411 of the pack. Note that the set of pack arguments can be empty.
19412 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
19415 Otherwise, we just consider the parameters of DECL. */
19416 while (generic_decl_parm
|| parm
)
19418 if (generic_decl_parm
19419 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
19420 gen_formal_parameter_pack_die (generic_decl_parm
,
19425 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
19427 if (parm
== DECL_ARGUMENTS (decl
)
19428 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
19430 && (dwarf_version
>= 3 || !dwarf_strict
))
19431 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
19433 parm
= DECL_CHAIN (parm
);
19436 if (generic_decl_parm
)
19437 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
19440 /* Decide whether we need an unspecified_parameters DIE at the end.
19441 There are 2 more cases to do this for: 1) the ansi ... declaration -
19442 this is detectable when the end of the arg list is not a
19443 void_type_node 2) an unprototyped function declaration (not a
19444 definition). This just means that we have no info about the
19445 parameters at all. */
19446 if (prototype_p (TREE_TYPE (decl
)))
19448 /* This is the prototyped case, check for.... */
19449 if (stdarg_p (TREE_TYPE (decl
)))
19450 gen_unspecified_parameters_die (decl
, subr_die
);
19452 else if (DECL_INITIAL (decl
) == NULL_TREE
)
19453 gen_unspecified_parameters_die (decl
, subr_die
);
19456 /* Output Dwarf info for all of the stuff within the body of the function
19457 (if it has one - it may be just a declaration). */
19458 outer_scope
= DECL_INITIAL (decl
);
19460 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
19461 a function. This BLOCK actually represents the outermost binding contour
19462 for the function, i.e. the contour in which the function's formal
19463 parameters and labels get declared. Curiously, it appears that the front
19464 end doesn't actually put the PARM_DECL nodes for the current function onto
19465 the BLOCK_VARS list for this outer scope, but are strung off of the
19466 DECL_ARGUMENTS list for the function instead.
19468 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
19469 the LABEL_DECL nodes for the function however, and we output DWARF info
19470 for those in decls_for_scope. Just within the `outer_scope' there will be
19471 a BLOCK node representing the function's outermost pair of curly braces,
19472 and any blocks used for the base and member initializers of a C++
19473 constructor function. */
19474 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
19476 int call_site_note_count
= 0;
19477 int tail_call_site_note_count
= 0;
19479 /* Emit a DW_TAG_variable DIE for a named return value. */
19480 if (DECL_NAME (DECL_RESULT (decl
)))
19481 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
19483 current_function_has_inlines
= 0;
19484 decls_for_scope (outer_scope
, subr_die
, 0);
19486 if (call_arg_locations
&& !dwarf_strict
)
19488 struct call_arg_loc_node
*ca_loc
;
19489 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
19491 dw_die_ref die
= NULL
;
19492 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
19495 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
19496 arg
; arg
= next_arg
)
19498 dw_loc_descr_ref reg
, val
;
19499 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
19502 next_arg
= XEXP (arg
, 1);
19503 if (REG_P (XEXP (XEXP (arg
, 0), 0))
19505 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
19506 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
19507 && REGNO (XEXP (XEXP (arg
, 0), 0))
19508 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
19509 next_arg
= XEXP (next_arg
, 1);
19510 if (mode
== VOIDmode
)
19512 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
19513 if (mode
== VOIDmode
)
19514 mode
= GET_MODE (XEXP (arg
, 0));
19516 if (GET_MODE_CLASS (mode
) != MODE_INT
19517 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
19519 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
19521 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
19522 tloc
= XEXP (XEXP (arg
, 0), 1);
19525 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
19526 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
19528 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
19529 tlocc
= XEXP (XEXP (arg
, 0), 1);
19532 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
19533 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
19534 VAR_INIT_STATUS_INITIALIZED
);
19535 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
19536 reg
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 0),
19538 VAR_INIT_STATUS_INITIALIZED
);
19543 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), VOIDmode
,
19544 VAR_INIT_STATUS_INITIALIZED
);
19548 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
19549 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
19551 add_AT_loc (cdie
, DW_AT_location
, reg
);
19552 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
19553 if (next_arg
!= XEXP (arg
, 1))
19555 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
19557 VAR_INIT_STATUS_INITIALIZED
);
19559 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
19563 && (ca_loc
->symbol_ref
|| tloc
))
19564 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
19565 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
19567 dw_loc_descr_ref tval
= NULL
;
19569 if (tloc
!= NULL_RTX
)
19570 tval
= mem_loc_descriptor (tloc
, VOIDmode
,
19571 VAR_INIT_STATUS_INITIALIZED
);
19573 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
19574 else if (tlocc
!= NULL_RTX
)
19576 tval
= mem_loc_descriptor (tlocc
, VOIDmode
,
19577 VAR_INIT_STATUS_INITIALIZED
);
19579 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
19585 call_site_note_count
++;
19586 if (ca_loc
->tail_call_p
)
19587 tail_call_site_note_count
++;
19591 call_arg_locations
= NULL
;
19592 call_arg_loc_last
= NULL
;
19593 if (tail_call_site_count
>= 0
19594 && tail_call_site_count
== tail_call_site_note_count
19597 if (call_site_count
>= 0
19598 && call_site_count
== call_site_note_count
)
19599 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
19601 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
19603 call_site_count
= -1;
19604 tail_call_site_count
= -1;
19606 /* Add the calling convention attribute if requested. */
19607 add_calling_convention_attribute (subr_die
, decl
);
19611 /* Returns a hash value for X (which really is a die_struct). */
19614 common_block_die_table_hash (const void *x
)
19616 const_dw_die_ref d
= (const_dw_die_ref
) x
;
19617 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
19620 /* Return nonzero if decl_id and die_parent of die_struct X is the same
19621 as decl_id and die_parent of die_struct Y. */
19624 common_block_die_table_eq (const void *x
, const void *y
)
19626 const_dw_die_ref d
= (const_dw_die_ref
) x
;
19627 const_dw_die_ref e
= (const_dw_die_ref
) y
;
19628 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
19631 /* Generate a DIE to represent a declared data object.
19632 Either DECL or ORIGIN must be non-null. */
19635 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
19639 tree decl_or_origin
= decl
? decl
: origin
;
19640 tree ultimate_origin
;
19641 dw_die_ref var_die
;
19642 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
19643 dw_die_ref origin_die
;
19644 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
19645 || class_or_namespace_scope_p (context_die
));
19646 bool specialization_p
= false;
19648 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
19649 if (decl
|| ultimate_origin
)
19650 origin
= ultimate_origin
;
19651 com_decl
= fortran_common (decl_or_origin
, &off
);
19653 /* Symbol in common gets emitted as a child of the common block, in the form
19654 of a data member. */
19657 dw_die_ref com_die
;
19658 dw_loc_list_ref loc
;
19659 die_node com_die_arg
;
19661 var_die
= lookup_decl_die (decl_or_origin
);
19664 if (get_AT (var_die
, DW_AT_location
) == NULL
)
19666 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
19671 /* Optimize the common case. */
19672 if (single_element_loc_list_p (loc
)
19673 && loc
->expr
->dw_loc_opc
== DW_OP_addr
19674 && loc
->expr
->dw_loc_next
== NULL
19675 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
19677 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
19678 = plus_constant (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
, off
);
19680 loc_list_plus_const (loc
, off
);
19682 add_AT_location_description (var_die
, DW_AT_location
, loc
);
19683 remove_AT (var_die
, DW_AT_declaration
);
19689 if (common_block_die_table
== NULL
)
19690 common_block_die_table
19691 = htab_create_ggc (10, common_block_die_table_hash
,
19692 common_block_die_table_eq
, NULL
);
19694 com_die_arg
.decl_id
= DECL_UID (com_decl
);
19695 com_die_arg
.die_parent
= context_die
;
19696 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
19697 loc
= loc_list_from_tree (com_decl
, 2);
19698 if (com_die
== NULL
)
19701 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
19704 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
19705 add_name_and_src_coords_attributes (com_die
, com_decl
);
19708 add_AT_location_description (com_die
, DW_AT_location
, loc
);
19709 /* Avoid sharing the same loc descriptor between
19710 DW_TAG_common_block and DW_TAG_variable. */
19711 loc
= loc_list_from_tree (com_decl
, 2);
19713 else if (DECL_EXTERNAL (decl
))
19714 add_AT_flag (com_die
, DW_AT_declaration
, 1);
19715 add_pubname_string (cnam
, com_die
); /* ??? needed? */
19716 com_die
->decl_id
= DECL_UID (com_decl
);
19717 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
19718 *slot
= (void *) com_die
;
19720 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
19722 add_AT_location_description (com_die
, DW_AT_location
, loc
);
19723 loc
= loc_list_from_tree (com_decl
, 2);
19724 remove_AT (com_die
, DW_AT_declaration
);
19726 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
19727 add_name_and_src_coords_attributes (var_die
, decl
);
19728 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
19729 TREE_THIS_VOLATILE (decl
), context_die
);
19730 add_AT_flag (var_die
, DW_AT_external
, 1);
19735 /* Optimize the common case. */
19736 if (single_element_loc_list_p (loc
)
19737 && loc
->expr
->dw_loc_opc
== DW_OP_addr
19738 && loc
->expr
->dw_loc_next
== NULL
19739 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
19740 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
19741 = plus_constant (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
, off
);
19743 loc_list_plus_const (loc
, off
);
19745 add_AT_location_description (var_die
, DW_AT_location
, loc
);
19747 else if (DECL_EXTERNAL (decl
))
19748 add_AT_flag (var_die
, DW_AT_declaration
, 1);
19749 equate_decl_number_to_die (decl
, var_die
);
19753 /* If the compiler emitted a definition for the DECL declaration
19754 and if we already emitted a DIE for it, don't emit a second
19755 DIE for it again. Allow re-declarations of DECLs that are
19756 inside functions, though. */
19757 if (old_die
&& declaration
&& !local_scope_p (context_die
))
19760 /* For static data members, the declaration in the class is supposed
19761 to have DW_TAG_member tag; the specification should still be
19762 DW_TAG_variable referencing the DW_TAG_member DIE. */
19763 if (declaration
&& class_scope_p (context_die
))
19764 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
19766 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
19769 if (origin
!= NULL
)
19770 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
19772 /* Loop unrolling can create multiple blocks that refer to the same
19773 static variable, so we must test for the DW_AT_declaration flag.
19775 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19776 copy decls and set the DECL_ABSTRACT flag on them instead of
19779 ??? Duplicated blocks have been rewritten to use .debug_ranges.
19781 ??? The declare_in_namespace support causes us to get two DIEs for one
19782 variable, both of which are declarations. We want to avoid considering
19783 one to be a specification, so we must test that this DIE is not a
19785 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
19786 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
19788 /* This is a definition of a C++ class level static. */
19789 add_AT_specification (var_die
, old_die
);
19790 specialization_p
= true;
19791 if (DECL_NAME (decl
))
19793 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
19794 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
19796 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
19797 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
19799 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
19800 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
19802 if (old_die
->die_tag
== DW_TAG_member
)
19803 add_linkage_name (var_die
, decl
);
19807 add_name_and_src_coords_attributes (var_die
, decl
);
19809 if ((origin
== NULL
&& !specialization_p
)
19811 && !DECL_ABSTRACT (decl_or_origin
)
19812 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
19813 decl_function_context
19814 (decl_or_origin
))))
19816 tree type
= TREE_TYPE (decl_or_origin
);
19818 if (decl_by_reference_p (decl_or_origin
))
19819 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
19821 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
19822 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
19825 if (origin
== NULL
&& !specialization_p
)
19827 if (TREE_PUBLIC (decl
))
19828 add_AT_flag (var_die
, DW_AT_external
, 1);
19830 if (DECL_ARTIFICIAL (decl
))
19831 add_AT_flag (var_die
, DW_AT_artificial
, 1);
19833 add_accessibility_attribute (var_die
, decl
);
19837 add_AT_flag (var_die
, DW_AT_declaration
, 1);
19839 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
19840 equate_decl_number_to_die (decl
, var_die
);
19843 && (! DECL_ABSTRACT (decl_or_origin
)
19844 /* Local static vars are shared between all clones/inlines,
19845 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19847 || (TREE_CODE (decl_or_origin
) == VAR_DECL
19848 && TREE_STATIC (decl_or_origin
)
19849 && DECL_RTL_SET_P (decl_or_origin
)))
19850 /* When abstract origin already has DW_AT_location attribute, no need
19851 to add it again. */
19852 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
19854 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
19855 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
19856 defer_location (decl_or_origin
, var_die
);
19858 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
19859 decl
== NULL
, DW_AT_location
);
19860 add_pubname (decl_or_origin
, var_die
);
19863 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
19866 /* Generate a DIE to represent a named constant. */
19869 gen_const_die (tree decl
, dw_die_ref context_die
)
19871 dw_die_ref const_die
;
19872 tree type
= TREE_TYPE (decl
);
19874 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
19875 add_name_and_src_coords_attributes (const_die
, decl
);
19876 add_type_attribute (const_die
, type
, 1, 0, context_die
);
19877 if (TREE_PUBLIC (decl
))
19878 add_AT_flag (const_die
, DW_AT_external
, 1);
19879 if (DECL_ARTIFICIAL (decl
))
19880 add_AT_flag (const_die
, DW_AT_artificial
, 1);
19881 tree_add_const_value_attribute_for_decl (const_die
, decl
);
19884 /* Generate a DIE to represent a label identifier. */
19887 gen_label_die (tree decl
, dw_die_ref context_die
)
19889 tree origin
= decl_ultimate_origin (decl
);
19890 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
19892 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19894 if (origin
!= NULL
)
19895 add_abstract_origin_attribute (lbl_die
, origin
);
19897 add_name_and_src_coords_attributes (lbl_die
, decl
);
19899 if (DECL_ABSTRACT (decl
))
19900 equate_decl_number_to_die (decl
, lbl_die
);
19903 insn
= DECL_RTL_IF_SET (decl
);
19905 /* Deleted labels are programmer specified labels which have been
19906 eliminated because of various optimizations. We still emit them
19907 here so that it is possible to put breakpoints on them. */
19911 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
19913 /* When optimization is enabled (via -O) some parts of the compiler
19914 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19915 represent source-level labels which were explicitly declared by
19916 the user. This really shouldn't be happening though, so catch
19917 it if it ever does happen. */
19918 gcc_assert (!INSN_DELETED_P (insn
));
19920 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
19921 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19926 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19927 attributes to the DIE for a block STMT, to describe where the inlined
19928 function was called from. This is similar to add_src_coords_attributes. */
19931 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
19933 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
19935 if (dwarf_version
>= 3 || !dwarf_strict
)
19937 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
19938 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
19943 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19944 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19947 add_high_low_attributes (tree stmt
, dw_die_ref die
)
19949 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19951 if (BLOCK_FRAGMENT_CHAIN (stmt
)
19952 && (dwarf_version
>= 3 || !dwarf_strict
))
19956 if (inlined_function_outer_scope_p (stmt
))
19958 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19959 BLOCK_NUMBER (stmt
));
19960 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
19963 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
));
19965 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19968 add_ranges (chain
);
19969 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
19976 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19977 BLOCK_NUMBER (stmt
));
19978 add_AT_lbl_id (die
, DW_AT_low_pc
, label
);
19979 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
19980 BLOCK_NUMBER (stmt
));
19981 add_AT_lbl_id (die
, DW_AT_high_pc
, label
);
19985 /* Generate a DIE for a lexical block. */
19988 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19990 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
19992 if (call_arg_locations
)
19994 if (VEC_length (dw_die_ref
, block_map
) <= BLOCK_NUMBER (stmt
))
19995 VEC_safe_grow_cleared (dw_die_ref
, heap
, block_map
,
19996 BLOCK_NUMBER (stmt
) + 1);
19997 VEC_replace (dw_die_ref
, block_map
, BLOCK_NUMBER (stmt
), stmt_die
);
20000 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
20001 add_high_low_attributes (stmt
, stmt_die
);
20003 decls_for_scope (stmt
, stmt_die
, depth
);
20006 /* Generate a DIE for an inlined subprogram. */
20009 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
20013 /* The instance of function that is effectively being inlined shall not
20015 gcc_assert (! BLOCK_ABSTRACT (stmt
));
20017 decl
= block_ultimate_origin (stmt
);
20019 /* Emit info for the abstract instance first, if we haven't yet. We
20020 must emit this even if the block is abstract, otherwise when we
20021 emit the block below (or elsewhere), we may end up trying to emit
20022 a die whose origin die hasn't been emitted, and crashing. */
20023 dwarf2out_abstract_function (decl
);
20025 if (! BLOCK_ABSTRACT (stmt
))
20027 dw_die_ref subr_die
20028 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
20030 if (call_arg_locations
)
20032 if (VEC_length (dw_die_ref
, block_map
) <= BLOCK_NUMBER (stmt
))
20033 VEC_safe_grow_cleared (dw_die_ref
, heap
, block_map
,
20034 BLOCK_NUMBER (stmt
) + 1);
20035 VEC_replace (dw_die_ref
, block_map
, BLOCK_NUMBER (stmt
), subr_die
);
20037 add_abstract_origin_attribute (subr_die
, decl
);
20038 if (TREE_ASM_WRITTEN (stmt
))
20039 add_high_low_attributes (stmt
, subr_die
);
20040 add_call_src_coords_attributes (stmt
, subr_die
);
20042 decls_for_scope (stmt
, subr_die
, depth
);
20043 current_function_has_inlines
= 1;
20047 /* Generate a DIE for a field in a record, or structure. */
20050 gen_field_die (tree decl
, dw_die_ref context_die
)
20052 dw_die_ref decl_die
;
20054 if (TREE_TYPE (decl
) == error_mark_node
)
20057 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
20058 add_name_and_src_coords_attributes (decl_die
, decl
);
20059 add_type_attribute (decl_die
, member_declared_type (decl
),
20060 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
20063 if (DECL_BIT_FIELD_TYPE (decl
))
20065 add_byte_size_attribute (decl_die
, decl
);
20066 add_bit_size_attribute (decl_die
, decl
);
20067 add_bit_offset_attribute (decl_die
, decl
);
20070 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
20071 add_data_member_location_attribute (decl_die
, decl
);
20073 if (DECL_ARTIFICIAL (decl
))
20074 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
20076 add_accessibility_attribute (decl_die
, decl
);
20078 /* Equate decl number to die, so that we can look up this decl later on. */
20079 equate_decl_number_to_die (decl
, decl_die
);
20083 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20084 Use modified_type_die instead.
20085 We keep this code here just in case these types of DIEs may be needed to
20086 represent certain things in other languages (e.g. Pascal) someday. */
20089 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
20092 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
20094 equate_type_number_to_die (type
, ptr_die
);
20095 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
20096 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
20099 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20100 Use modified_type_die instead.
20101 We keep this code here just in case these types of DIEs may be needed to
20102 represent certain things in other languages (e.g. Pascal) someday. */
20105 gen_reference_type_die (tree type
, dw_die_ref context_die
)
20107 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
20109 if (TYPE_REF_IS_RVALUE (type
) && use_debug_types
)
20110 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
20112 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
20114 equate_type_number_to_die (type
, ref_die
);
20115 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
20116 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
20120 /* Generate a DIE for a pointer to a member type. */
20123 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
20126 = new_die (DW_TAG_ptr_to_member_type
,
20127 scope_die_for (type
, context_die
), type
);
20129 equate_type_number_to_die (type
, ptr_die
);
20130 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
20131 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
20132 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
20135 /* Generate the DIE for the compilation unit. */
20138 gen_compile_unit_die (const char *filename
)
20141 char producer
[250];
20142 const char *language_string
= lang_hooks
.name
;
20145 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
20149 add_name_attribute (die
, filename
);
20150 /* Don't add cwd for <built-in>. */
20151 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
20152 add_comp_dir_attribute (die
);
20155 sprintf (producer
, "%s %s", language_string
, version_string
);
20157 #ifdef MIPS_DEBUGGING_INFO
20158 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
20159 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
20160 not appear in the producer string, the debugger reaches the conclusion
20161 that the object file is stripped and has no debugging information.
20162 To get the MIPS/SGI debugger to believe that there is debugging
20163 information in the object file, we add a -g to the producer string. */
20164 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20165 strcat (producer
, " -g");
20168 add_AT_string (die
, DW_AT_producer
, producer
);
20170 /* If our producer is LTO try to figure out a common language to use
20171 from the global list of translation units. */
20172 if (strcmp (language_string
, "GNU GIMPLE") == 0)
20176 const char *common_lang
= NULL
;
20178 FOR_EACH_VEC_ELT (tree
, all_translation_units
, i
, t
)
20180 if (!TRANSLATION_UNIT_LANGUAGE (t
))
20183 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
20184 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
20186 else if (strncmp (common_lang
, "GNU C", 5) == 0
20187 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
20188 /* Mixing C and C++ is ok, use C++ in that case. */
20189 common_lang
= "GNU C++";
20192 /* Fall back to C. */
20193 common_lang
= NULL
;
20199 language_string
= common_lang
;
20202 language
= DW_LANG_C89
;
20203 if (strcmp (language_string
, "GNU C++") == 0)
20204 language
= DW_LANG_C_plus_plus
;
20205 else if (strcmp (language_string
, "GNU F77") == 0)
20206 language
= DW_LANG_Fortran77
;
20207 else if (strcmp (language_string
, "GNU Pascal") == 0)
20208 language
= DW_LANG_Pascal83
;
20209 else if (dwarf_version
>= 3 || !dwarf_strict
)
20211 if (strcmp (language_string
, "GNU Ada") == 0)
20212 language
= DW_LANG_Ada95
;
20213 else if (strcmp (language_string
, "GNU Fortran") == 0)
20214 language
= DW_LANG_Fortran95
;
20215 else if (strcmp (language_string
, "GNU Java") == 0)
20216 language
= DW_LANG_Java
;
20217 else if (strcmp (language_string
, "GNU Objective-C") == 0)
20218 language
= DW_LANG_ObjC
;
20219 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
20220 language
= DW_LANG_ObjC_plus_plus
;
20223 add_AT_unsigned (die
, DW_AT_language
, language
);
20227 case DW_LANG_Fortran77
:
20228 case DW_LANG_Fortran90
:
20229 case DW_LANG_Fortran95
:
20230 /* Fortran has case insensitive identifiers and the front-end
20231 lowercases everything. */
20232 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
20235 /* The default DW_ID_case_sensitive doesn't need to be specified. */
20241 /* Generate the DIE for a base class. */
20244 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
20246 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
20248 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
20249 add_data_member_location_attribute (die
, binfo
);
20251 if (BINFO_VIRTUAL_P (binfo
))
20252 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
20254 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
20255 children, otherwise the default is DW_ACCESS_public. In DWARF2
20256 the default has always been DW_ACCESS_private. */
20257 if (access
== access_public_node
)
20259 if (dwarf_version
== 2
20260 || context_die
->die_tag
== DW_TAG_class_type
)
20261 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
20263 else if (access
== access_protected_node
)
20264 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
20265 else if (dwarf_version
> 2
20266 && context_die
->die_tag
!= DW_TAG_class_type
)
20267 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
20270 /* Generate a DIE for a class member. */
20273 gen_member_die (tree type
, dw_die_ref context_die
)
20276 tree binfo
= TYPE_BINFO (type
);
20279 /* If this is not an incomplete type, output descriptions of each of its
20280 members. Note that as we output the DIEs necessary to represent the
20281 members of this record or union type, we will also be trying to output
20282 DIEs to represent the *types* of those members. However the `type'
20283 function (above) will specifically avoid generating type DIEs for member
20284 types *within* the list of member DIEs for this (containing) type except
20285 for those types (of members) which are explicitly marked as also being
20286 members of this (containing) type themselves. The g++ front- end can
20287 force any given type to be treated as a member of some other (containing)
20288 type by setting the TYPE_CONTEXT of the given (member) type to point to
20289 the TREE node representing the appropriate (containing) type. */
20291 /* First output info about the base classes. */
20294 VEC(tree
,gc
) *accesses
= BINFO_BASE_ACCESSES (binfo
);
20298 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
20299 gen_inheritance_die (base
,
20300 (accesses
? VEC_index (tree
, accesses
, i
)
20301 : access_public_node
), context_die
);
20304 /* Now output info about the data members and type members. */
20305 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
20307 /* If we thought we were generating minimal debug info for TYPE
20308 and then changed our minds, some of the member declarations
20309 may have already been defined. Don't define them again, but
20310 do put them in the right order. */
20312 child
= lookup_decl_die (member
);
20314 splice_child_die (context_die
, child
);
20316 gen_decl_die (member
, NULL
, context_die
);
20319 /* Now output info about the function members (if any). */
20320 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
20322 /* Don't include clones in the member list. */
20323 if (DECL_ABSTRACT_ORIGIN (member
))
20326 child
= lookup_decl_die (member
);
20328 splice_child_die (context_die
, child
);
20330 gen_decl_die (member
, NULL
, context_die
);
20334 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
20335 is set, we pretend that the type was never defined, so we only get the
20336 member DIEs needed by later specification DIEs. */
20339 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
20340 enum debug_info_usage usage
)
20342 dw_die_ref type_die
= lookup_type_die (type
);
20343 dw_die_ref scope_die
= 0;
20345 int complete
= (TYPE_SIZE (type
)
20346 && (! TYPE_STUB_DECL (type
)
20347 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
20348 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
20349 complete
= complete
&& should_emit_struct_debug (type
, usage
);
20351 if (type_die
&& ! complete
)
20354 if (TYPE_CONTEXT (type
) != NULL_TREE
20355 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
20356 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
20359 scope_die
= scope_die_for (type
, context_die
);
20361 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
20362 /* First occurrence of type or toplevel definition of nested class. */
20364 dw_die_ref old_die
= type_die
;
20366 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
20367 ? record_type_tag (type
) : DW_TAG_union_type
,
20369 equate_type_number_to_die (type
, type_die
);
20371 add_AT_specification (type_die
, old_die
);
20374 add_name_attribute (type_die
, type_tag (type
));
20375 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
20379 remove_AT (type_die
, DW_AT_declaration
);
20381 /* Generate child dies for template paramaters. */
20382 if (debug_info_level
> DINFO_LEVEL_TERSE
20383 && COMPLETE_TYPE_P (type
))
20384 schedule_generic_params_dies_gen (type
);
20386 /* If this type has been completed, then give it a byte_size attribute and
20387 then give a list of members. */
20388 if (complete
&& !ns_decl
)
20390 /* Prevent infinite recursion in cases where the type of some member of
20391 this type is expressed in terms of this type itself. */
20392 TREE_ASM_WRITTEN (type
) = 1;
20393 add_byte_size_attribute (type_die
, type
);
20394 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
20396 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
20397 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
20400 /* If the first reference to this type was as the return type of an
20401 inline function, then it may not have a parent. Fix this now. */
20402 if (type_die
->die_parent
== NULL
)
20403 add_child_die (scope_die
, type_die
);
20405 push_decl_scope (type
);
20406 gen_member_die (type
, type_die
);
20409 /* GNU extension: Record what type our vtable lives in. */
20410 if (TYPE_VFIELD (type
))
20412 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
20414 gen_type_die (vtype
, context_die
);
20415 add_AT_die_ref (type_die
, DW_AT_containing_type
,
20416 lookup_type_die (vtype
));
20421 add_AT_flag (type_die
, DW_AT_declaration
, 1);
20423 /* We don't need to do this for function-local types. */
20424 if (TYPE_STUB_DECL (type
)
20425 && ! decl_function_context (TYPE_STUB_DECL (type
)))
20426 VEC_safe_push (tree
, gc
, incomplete_types
, type
);
20429 if (get_AT (type_die
, DW_AT_name
))
20430 add_pubtype (type
, type_die
);
20433 /* Generate a DIE for a subroutine _type_. */
20436 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
20438 tree return_type
= TREE_TYPE (type
);
20439 dw_die_ref subr_die
20440 = new_die (DW_TAG_subroutine_type
,
20441 scope_die_for (type
, context_die
), type
);
20443 equate_type_number_to_die (type
, subr_die
);
20444 add_prototyped_attribute (subr_die
, type
);
20445 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
20446 gen_formal_types_die (type
, subr_die
);
20448 if (get_AT (subr_die
, DW_AT_name
))
20449 add_pubtype (type
, subr_die
);
20452 /* Generate a DIE for a type definition. */
20455 gen_typedef_die (tree decl
, dw_die_ref context_die
)
20457 dw_die_ref type_die
;
20460 if (TREE_ASM_WRITTEN (decl
))
20463 TREE_ASM_WRITTEN (decl
) = 1;
20464 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
20465 origin
= decl_ultimate_origin (decl
);
20466 if (origin
!= NULL
)
20467 add_abstract_origin_attribute (type_die
, origin
);
20472 add_name_and_src_coords_attributes (type_die
, decl
);
20473 if (DECL_ORIGINAL_TYPE (decl
))
20475 type
= DECL_ORIGINAL_TYPE (decl
);
20477 gcc_assert (type
!= TREE_TYPE (decl
));
20478 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
20482 type
= TREE_TYPE (decl
);
20484 if (is_naming_typedef_decl (TYPE_NAME (type
)))
20486 /* Here, we are in the case of decl being a typedef naming
20487 an anonymous type, e.g:
20488 typedef struct {...} foo;
20489 In that case TREE_TYPE (decl) is not a typedef variant
20490 type and TYPE_NAME of the anonymous type is set to the
20491 TYPE_DECL of the typedef. This construct is emitted by
20494 TYPE is the anonymous struct named by the typedef
20495 DECL. As we need the DW_AT_type attribute of the
20496 DW_TAG_typedef to point to the DIE of TYPE, let's
20497 generate that DIE right away. add_type_attribute
20498 called below will then pick (via lookup_type_die) that
20499 anonymous struct DIE. */
20500 if (!TREE_ASM_WRITTEN (type
))
20501 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
20503 /* This is a GNU Extension. We are adding a
20504 DW_AT_linkage_name attribute to the DIE of the
20505 anonymous struct TYPE. The value of that attribute
20506 is the name of the typedef decl naming the anonymous
20507 struct. This greatly eases the work of consumers of
20508 this debug info. */
20509 add_linkage_attr (lookup_type_die (type
), decl
);
20513 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
20514 TREE_THIS_VOLATILE (decl
), context_die
);
20516 if (is_naming_typedef_decl (decl
))
20517 /* We want that all subsequent calls to lookup_type_die with
20518 TYPE in argument yield the DW_TAG_typedef we have just
20520 equate_type_number_to_die (type
, type_die
);
20522 add_accessibility_attribute (type_die
, decl
);
20525 if (DECL_ABSTRACT (decl
))
20526 equate_decl_number_to_die (decl
, type_die
);
20528 if (get_AT (type_die
, DW_AT_name
))
20529 add_pubtype (decl
, type_die
);
20532 /* Generate a DIE for a struct, class, enum or union type. */
20535 gen_tagged_type_die (tree type
,
20536 dw_die_ref context_die
,
20537 enum debug_info_usage usage
)
20541 if (type
== NULL_TREE
20542 || !is_tagged_type (type
))
20545 /* If this is a nested type whose containing class hasn't been written
20546 out yet, writing it out will cover this one, too. This does not apply
20547 to instantiations of member class templates; they need to be added to
20548 the containing class as they are generated. FIXME: This hurts the
20549 idea of combining type decls from multiple TUs, since we can't predict
20550 what set of template instantiations we'll get. */
20551 if (TYPE_CONTEXT (type
)
20552 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
20553 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
20555 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
20557 if (TREE_ASM_WRITTEN (type
))
20560 /* If that failed, attach ourselves to the stub. */
20561 push_decl_scope (TYPE_CONTEXT (type
));
20562 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
20565 else if (TYPE_CONTEXT (type
) != NULL_TREE
20566 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
20568 /* If this type is local to a function that hasn't been written
20569 out yet, use a NULL context for now; it will be fixed up in
20570 decls_for_scope. */
20571 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
20572 /* A declaration DIE doesn't count; nested types need to go in the
20574 if (context_die
&& is_declaration_die (context_die
))
20575 context_die
= NULL
;
20580 context_die
= declare_in_namespace (type
, context_die
);
20584 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
20586 /* This might have been written out by the call to
20587 declare_in_namespace. */
20588 if (!TREE_ASM_WRITTEN (type
))
20589 gen_enumeration_type_die (type
, context_die
);
20592 gen_struct_or_union_type_die (type
, context_die
, usage
);
20597 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
20598 it up if it is ever completed. gen_*_type_die will set it for us
20599 when appropriate. */
20602 /* Generate a type description DIE. */
20605 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
20606 enum debug_info_usage usage
)
20608 struct array_descr_info info
;
20610 if (type
== NULL_TREE
|| type
== error_mark_node
)
20613 if (TYPE_NAME (type
) != NULL_TREE
20614 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
20615 && is_redundant_typedef (TYPE_NAME (type
))
20616 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
20617 /* The DECL of this type is a typedef we don't want to emit debug
20618 info for but we want debug info for its underlying typedef.
20619 This can happen for e.g, the injected-class-name of a C++
20621 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
20623 /* If TYPE is a typedef type variant, let's generate debug info
20624 for the parent typedef which TYPE is a type of. */
20625 if (typedef_variant_p (type
))
20627 if (TREE_ASM_WRITTEN (type
))
20630 /* Prevent broken recursion; we can't hand off to the same type. */
20631 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
20633 /* Use the DIE of the containing namespace as the parent DIE of
20634 the type description DIE we want to generate. */
20635 if (DECL_CONTEXT (TYPE_NAME (type
))
20636 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
20637 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
20639 TREE_ASM_WRITTEN (type
) = 1;
20641 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
20645 /* If type is an anonymous tagged type named by a typedef, let's
20646 generate debug info for the typedef. */
20647 if (is_naming_typedef_decl (TYPE_NAME (type
)))
20649 /* Use the DIE of the containing namespace as the parent DIE of
20650 the type description DIE we want to generate. */
20651 if (DECL_CONTEXT (TYPE_NAME (type
))
20652 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
20653 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
20655 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
20659 /* If this is an array type with hidden descriptor, handle it first. */
20660 if (!TREE_ASM_WRITTEN (type
)
20661 && lang_hooks
.types
.get_array_descr_info
20662 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
20663 && (dwarf_version
>= 3 || !dwarf_strict
))
20665 gen_descr_array_type_die (type
, &info
, context_die
);
20666 TREE_ASM_WRITTEN (type
) = 1;
20670 /* We are going to output a DIE to represent the unqualified version
20671 of this type (i.e. without any const or volatile qualifiers) so
20672 get the main variant (i.e. the unqualified version) of this type
20673 now. (Vectors are special because the debugging info is in the
20674 cloned type itself). */
20675 if (TREE_CODE (type
) != VECTOR_TYPE
)
20676 type
= type_main_variant (type
);
20678 if (TREE_ASM_WRITTEN (type
))
20681 switch (TREE_CODE (type
))
20687 case REFERENCE_TYPE
:
20688 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
20689 ensures that the gen_type_die recursion will terminate even if the
20690 type is recursive. Recursive types are possible in Ada. */
20691 /* ??? We could perhaps do this for all types before the switch
20693 TREE_ASM_WRITTEN (type
) = 1;
20695 /* For these types, all that is required is that we output a DIE (or a
20696 set of DIEs) to represent the "basis" type. */
20697 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20698 DINFO_USAGE_IND_USE
);
20702 /* This code is used for C++ pointer-to-data-member types.
20703 Output a description of the relevant class type. */
20704 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
20705 DINFO_USAGE_IND_USE
);
20707 /* Output a description of the type of the object pointed to. */
20708 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20709 DINFO_USAGE_IND_USE
);
20711 /* Now output a DIE to represent this pointer-to-data-member type
20713 gen_ptr_to_mbr_type_die (type
, context_die
);
20716 case FUNCTION_TYPE
:
20717 /* Force out return type (in case it wasn't forced out already). */
20718 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20719 DINFO_USAGE_DIR_USE
);
20720 gen_subroutine_type_die (type
, context_die
);
20724 /* Force out return type (in case it wasn't forced out already). */
20725 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20726 DINFO_USAGE_DIR_USE
);
20727 gen_subroutine_type_die (type
, context_die
);
20731 gen_array_type_die (type
, context_die
);
20735 gen_array_type_die (type
, context_die
);
20738 case ENUMERAL_TYPE
:
20741 case QUAL_UNION_TYPE
:
20742 gen_tagged_type_die (type
, context_die
, usage
);
20748 case FIXED_POINT_TYPE
:
20751 /* No DIEs needed for fundamental types. */
20756 /* Just use DW_TAG_unspecified_type. */
20758 dw_die_ref type_die
= lookup_type_die (type
);
20759 if (type_die
== NULL
)
20761 tree name
= TYPE_NAME (type
);
20762 if (TREE_CODE (name
) == TYPE_DECL
)
20763 name
= DECL_NAME (name
);
20764 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
20765 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
20766 equate_type_number_to_die (type
, type_die
);
20772 gcc_unreachable ();
20775 TREE_ASM_WRITTEN (type
) = 1;
20779 gen_type_die (tree type
, dw_die_ref context_die
)
20781 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
20784 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20785 things which are local to the given block. */
20788 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
20790 int must_output_die
= 0;
20793 /* Ignore blocks that are NULL. */
20794 if (stmt
== NULL_TREE
)
20797 inlined_func
= inlined_function_outer_scope_p (stmt
);
20799 /* If the block is one fragment of a non-contiguous block, do not
20800 process the variables, since they will have been done by the
20801 origin block. Do process subblocks. */
20802 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
20806 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
20807 gen_block_die (sub
, context_die
, depth
+ 1);
20812 /* Determine if we need to output any Dwarf DIEs at all to represent this
20815 /* The outer scopes for inlinings *must* always be represented. We
20816 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20817 must_output_die
= 1;
20820 /* Determine if this block directly contains any "significant"
20821 local declarations which we will need to output DIEs for. */
20822 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20823 /* We are not in terse mode so *any* local declaration counts
20824 as being a "significant" one. */
20825 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
20826 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
20827 && (TREE_USED (stmt
)
20828 || TREE_ASM_WRITTEN (stmt
)
20829 || BLOCK_ABSTRACT (stmt
)));
20830 else if ((TREE_USED (stmt
)
20831 || TREE_ASM_WRITTEN (stmt
)
20832 || BLOCK_ABSTRACT (stmt
))
20833 && !dwarf2out_ignore_block (stmt
))
20834 must_output_die
= 1;
20837 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20838 DIE for any block which contains no significant local declarations at
20839 all. Rather, in such cases we just call `decls_for_scope' so that any
20840 needed Dwarf info for any sub-blocks will get properly generated. Note
20841 that in terse mode, our definition of what constitutes a "significant"
20842 local declaration gets restricted to include only inlined function
20843 instances and local (nested) function definitions. */
20844 if (must_output_die
)
20848 /* If STMT block is abstract, that means we have been called
20849 indirectly from dwarf2out_abstract_function.
20850 That function rightfully marks the descendent blocks (of
20851 the abstract function it is dealing with) as being abstract,
20852 precisely to prevent us from emitting any
20853 DW_TAG_inlined_subroutine DIE as a descendent
20854 of an abstract function instance. So in that case, we should
20855 not call gen_inlined_subroutine_die.
20857 Later though, when cgraph asks dwarf2out to emit info
20858 for the concrete instance of the function decl into which
20859 the concrete instance of STMT got inlined, the later will lead
20860 to the generation of a DW_TAG_inlined_subroutine DIE. */
20861 if (! BLOCK_ABSTRACT (stmt
))
20862 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
20865 gen_lexical_block_die (stmt
, context_die
, depth
);
20868 decls_for_scope (stmt
, context_die
, depth
);
20871 /* Process variable DECL (or variable with origin ORIGIN) within
20872 block STMT and add it to CONTEXT_DIE. */
20874 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
20877 tree decl_or_origin
= decl
? decl
: origin
;
20879 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
20880 die
= lookup_decl_die (decl_or_origin
);
20881 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
20882 && TYPE_DECL_IS_STUB (decl_or_origin
))
20883 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
20887 if (die
!= NULL
&& die
->die_parent
== NULL
)
20888 add_child_die (context_die
, die
);
20889 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
20890 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
20891 stmt
, context_die
);
20893 gen_decl_die (decl
, origin
, context_die
);
20896 /* Generate all of the decls declared within a given scope and (recursively)
20897 all of its sub-blocks. */
20900 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
20906 /* Ignore NULL blocks. */
20907 if (stmt
== NULL_TREE
)
20910 /* Output the DIEs to represent all of the data objects and typedefs
20911 declared directly within this block but not within any nested
20912 sub-blocks. Also, nested function and tag DIEs have been
20913 generated with a parent of NULL; fix that up now. */
20914 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
20915 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
20916 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
20917 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
20920 /* If we're at -g1, we're not interested in subblocks. */
20921 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20924 /* Output the DIEs to represent all sub-blocks (and the items declared
20925 therein) of this block. */
20926 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
20928 subblocks
= BLOCK_CHAIN (subblocks
))
20929 gen_block_die (subblocks
, context_die
, depth
+ 1);
20932 /* Is this a typedef we can avoid emitting? */
20935 is_redundant_typedef (const_tree decl
)
20937 if (TYPE_DECL_IS_STUB (decl
))
20940 if (DECL_ARTIFICIAL (decl
)
20941 && DECL_CONTEXT (decl
)
20942 && is_tagged_type (DECL_CONTEXT (decl
))
20943 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
20944 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
20945 /* Also ignore the artificial member typedef for the class name. */
20951 /* Return TRUE if TYPE is a typedef that names a type for linkage
20952 purposes. This kind of typedefs is produced by the C++ FE for
20955 typedef struct {...} foo;
20957 In that case, there is no typedef variant type produced for foo.
20958 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20962 is_naming_typedef_decl (const_tree decl
)
20964 if (decl
== NULL_TREE
20965 || TREE_CODE (decl
) != TYPE_DECL
20966 || !is_tagged_type (TREE_TYPE (decl
))
20967 || DECL_IS_BUILTIN (decl
)
20968 || is_redundant_typedef (decl
)
20969 /* It looks like Ada produces TYPE_DECLs that are very similar
20970 to C++ naming typedefs but that have different
20971 semantics. Let's be specific to c++ for now. */
20975 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
20976 && TYPE_NAME (TREE_TYPE (decl
)) == decl
20977 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
20978 != TYPE_NAME (TREE_TYPE (decl
))));
20981 /* Returns the DIE for a context. */
20983 static inline dw_die_ref
20984 get_context_die (tree context
)
20988 /* Find die that represents this context. */
20989 if (TYPE_P (context
))
20991 context
= TYPE_MAIN_VARIANT (context
);
20992 return strip_naming_typedef (context
, force_type_die (context
));
20995 return force_decl_die (context
);
20997 return comp_unit_die ();
21000 /* Returns the DIE for decl. A DIE will always be returned. */
21003 force_decl_die (tree decl
)
21005 dw_die_ref decl_die
;
21006 unsigned saved_external_flag
;
21007 tree save_fn
= NULL_TREE
;
21008 decl_die
= lookup_decl_die (decl
);
21011 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
21013 decl_die
= lookup_decl_die (decl
);
21017 switch (TREE_CODE (decl
))
21019 case FUNCTION_DECL
:
21020 /* Clear current_function_decl, so that gen_subprogram_die thinks
21021 that this is a declaration. At this point, we just want to force
21022 declaration die. */
21023 save_fn
= current_function_decl
;
21024 current_function_decl
= NULL_TREE
;
21025 gen_subprogram_die (decl
, context_die
);
21026 current_function_decl
= save_fn
;
21030 /* Set external flag to force declaration die. Restore it after
21031 gen_decl_die() call. */
21032 saved_external_flag
= DECL_EXTERNAL (decl
);
21033 DECL_EXTERNAL (decl
) = 1;
21034 gen_decl_die (decl
, NULL
, context_die
);
21035 DECL_EXTERNAL (decl
) = saved_external_flag
;
21038 case NAMESPACE_DECL
:
21039 if (dwarf_version
>= 3 || !dwarf_strict
)
21040 dwarf2out_decl (decl
);
21042 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
21043 decl_die
= comp_unit_die ();
21046 case TRANSLATION_UNIT_DECL
:
21047 decl_die
= comp_unit_die ();
21051 gcc_unreachable ();
21054 /* We should be able to find the DIE now. */
21056 decl_die
= lookup_decl_die (decl
);
21057 gcc_assert (decl_die
);
21063 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
21064 always returned. */
21067 force_type_die (tree type
)
21069 dw_die_ref type_die
;
21071 type_die
= lookup_type_die (type
);
21074 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
21076 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
21077 TYPE_VOLATILE (type
), context_die
);
21078 gcc_assert (type_die
);
21083 /* Force out any required namespaces to be able to output DECL,
21084 and return the new context_die for it, if it's changed. */
21087 setup_namespace_context (tree thing
, dw_die_ref context_die
)
21089 tree context
= (DECL_P (thing
)
21090 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
21091 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
21092 /* Force out the namespace. */
21093 context_die
= force_decl_die (context
);
21095 return context_die
;
21098 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
21099 type) within its namespace, if appropriate.
21101 For compatibility with older debuggers, namespace DIEs only contain
21102 declarations; all definitions are emitted at CU scope. */
21105 declare_in_namespace (tree thing
, dw_die_ref context_die
)
21107 dw_die_ref ns_context
;
21109 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21110 return context_die
;
21112 /* If this decl is from an inlined function, then don't try to emit it in its
21113 namespace, as we will get confused. It would have already been emitted
21114 when the abstract instance of the inline function was emitted anyways. */
21115 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
21116 return context_die
;
21118 ns_context
= setup_namespace_context (thing
, context_die
);
21120 if (ns_context
!= context_die
)
21124 if (DECL_P (thing
))
21125 gen_decl_die (thing
, NULL
, ns_context
);
21127 gen_type_die (thing
, ns_context
);
21129 return context_die
;
21132 /* Generate a DIE for a namespace or namespace alias. */
21135 gen_namespace_die (tree decl
, dw_die_ref context_die
)
21137 dw_die_ref namespace_die
;
21139 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
21140 they are an alias of. */
21141 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
21143 /* Output a real namespace or module. */
21144 context_die
= setup_namespace_context (decl
, comp_unit_die ());
21145 namespace_die
= new_die (is_fortran ()
21146 ? DW_TAG_module
: DW_TAG_namespace
,
21147 context_die
, decl
);
21148 /* For Fortran modules defined in different CU don't add src coords. */
21149 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
21151 const char *name
= dwarf2_name (decl
, 0);
21153 add_name_attribute (namespace_die
, name
);
21156 add_name_and_src_coords_attributes (namespace_die
, decl
);
21157 if (DECL_EXTERNAL (decl
))
21158 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
21159 equate_decl_number_to_die (decl
, namespace_die
);
21163 /* Output a namespace alias. */
21165 /* Force out the namespace we are an alias of, if necessary. */
21166 dw_die_ref origin_die
21167 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
21169 if (DECL_FILE_SCOPE_P (decl
)
21170 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
21171 context_die
= setup_namespace_context (decl
, comp_unit_die ());
21172 /* Now create the namespace alias DIE. */
21173 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
21174 add_name_and_src_coords_attributes (namespace_die
, decl
);
21175 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
21176 equate_decl_number_to_die (decl
, namespace_die
);
21180 /* Generate Dwarf debug information for a decl described by DECL.
21181 The return value is currently only meaningful for PARM_DECLs,
21182 for all other decls it returns NULL. */
21185 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
21187 tree decl_or_origin
= decl
? decl
: origin
;
21188 tree class_origin
= NULL
, ultimate_origin
;
21190 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
21193 switch (TREE_CODE (decl_or_origin
))
21199 if (!is_fortran () && !is_ada ())
21201 /* The individual enumerators of an enum type get output when we output
21202 the Dwarf representation of the relevant enum type itself. */
21206 /* Emit its type. */
21207 gen_type_die (TREE_TYPE (decl
), context_die
);
21209 /* And its containing namespace. */
21210 context_die
= declare_in_namespace (decl
, context_die
);
21212 gen_const_die (decl
, context_die
);
21215 case FUNCTION_DECL
:
21216 /* Don't output any DIEs to represent mere function declarations,
21217 unless they are class members or explicit block externs. */
21218 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
21219 && DECL_FILE_SCOPE_P (decl_or_origin
)
21220 && (current_function_decl
== NULL_TREE
21221 || DECL_ARTIFICIAL (decl_or_origin
)))
21226 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
21227 on local redeclarations of global functions. That seems broken. */
21228 if (current_function_decl
!= decl
)
21229 /* This is only a declaration. */;
21232 /* If we're emitting a clone, emit info for the abstract instance. */
21233 if (origin
|| DECL_ORIGIN (decl
) != decl
)
21234 dwarf2out_abstract_function (origin
21235 ? DECL_ORIGIN (origin
)
21236 : DECL_ABSTRACT_ORIGIN (decl
));
21238 /* If we're emitting an out-of-line copy of an inline function,
21239 emit info for the abstract instance and set up to refer to it. */
21240 else if (cgraph_function_possibly_inlined_p (decl
)
21241 && ! DECL_ABSTRACT (decl
)
21242 && ! class_or_namespace_scope_p (context_die
)
21243 /* dwarf2out_abstract_function won't emit a die if this is just
21244 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
21245 that case, because that works only if we have a die. */
21246 && DECL_INITIAL (decl
) != NULL_TREE
)
21248 dwarf2out_abstract_function (decl
);
21249 set_decl_origin_self (decl
);
21252 /* Otherwise we're emitting the primary DIE for this decl. */
21253 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
21255 /* Before we describe the FUNCTION_DECL itself, make sure that we
21256 have its containing type. */
21258 origin
= decl_class_context (decl
);
21259 if (origin
!= NULL_TREE
)
21260 gen_type_die (origin
, context_die
);
21262 /* And its return type. */
21263 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
21265 /* And its virtual context. */
21266 if (DECL_VINDEX (decl
) != NULL_TREE
)
21267 gen_type_die (DECL_CONTEXT (decl
), context_die
);
21269 /* Make sure we have a member DIE for decl. */
21270 if (origin
!= NULL_TREE
)
21271 gen_type_die_for_member (origin
, decl
, context_die
);
21273 /* And its containing namespace. */
21274 context_die
= declare_in_namespace (decl
, context_die
);
21277 /* Now output a DIE to represent the function itself. */
21279 gen_subprogram_die (decl
, context_die
);
21283 /* If we are in terse mode, don't generate any DIEs to represent any
21284 actual typedefs. */
21285 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21288 /* In the special case of a TYPE_DECL node representing the declaration
21289 of some type tag, if the given TYPE_DECL is marked as having been
21290 instantiated from some other (original) TYPE_DECL node (e.g. one which
21291 was generated within the original definition of an inline function) we
21292 used to generate a special (abbreviated) DW_TAG_structure_type,
21293 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
21294 should be actually referencing those DIEs, as variable DIEs with that
21295 type would be emitted already in the abstract origin, so it was always
21296 removed during unused type prunning. Don't add anything in this
21298 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
21301 if (is_redundant_typedef (decl
))
21302 gen_type_die (TREE_TYPE (decl
), context_die
);
21304 /* Output a DIE to represent the typedef itself. */
21305 gen_typedef_die (decl
, context_die
);
21309 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
21310 gen_label_die (decl
, context_die
);
21315 /* If we are in terse mode, don't generate any DIEs to represent any
21316 variable declarations or definitions. */
21317 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21320 /* Output any DIEs that are needed to specify the type of this data
21322 if (decl_by_reference_p (decl_or_origin
))
21323 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
21325 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
21327 /* And its containing type. */
21328 class_origin
= decl_class_context (decl_or_origin
);
21329 if (class_origin
!= NULL_TREE
)
21330 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
21332 /* And its containing namespace. */
21333 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
21335 /* Now output the DIE to represent the data object itself. This gets
21336 complicated because of the possibility that the VAR_DECL really
21337 represents an inlined instance of a formal parameter for an inline
21339 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
21340 if (ultimate_origin
!= NULL_TREE
21341 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
21342 gen_formal_parameter_die (decl
, origin
,
21343 true /* Emit name attribute. */,
21346 gen_variable_die (decl
, origin
, context_die
);
21350 /* Ignore the nameless fields that are used to skip bits but handle C++
21351 anonymous unions and structs. */
21352 if (DECL_NAME (decl
) != NULL_TREE
21353 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
21354 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
21356 gen_type_die (member_declared_type (decl
), context_die
);
21357 gen_field_die (decl
, context_die
);
21362 if (DECL_BY_REFERENCE (decl_or_origin
))
21363 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
21365 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
21366 return gen_formal_parameter_die (decl
, origin
,
21367 true /* Emit name attribute. */,
21370 case NAMESPACE_DECL
:
21371 case IMPORTED_DECL
:
21372 if (dwarf_version
>= 3 || !dwarf_strict
)
21373 gen_namespace_die (decl
, context_die
);
21377 /* Probably some frontend-internal decl. Assume we don't care. */
21378 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
21385 /* Output debug information for global decl DECL. Called from toplev.c after
21386 compilation proper has finished. */
21389 dwarf2out_global_decl (tree decl
)
21391 /* Output DWARF2 information for file-scope tentative data object
21392 declarations, file-scope (extern) function declarations (which
21393 had no corresponding body) and file-scope tagged type declarations
21394 and definitions which have not yet been forced out. */
21395 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
21396 dwarf2out_decl (decl
);
21399 /* Output debug information for type decl DECL. Called from toplev.c
21400 and from language front ends (to record built-in types). */
21402 dwarf2out_type_decl (tree decl
, int local
)
21405 dwarf2out_decl (decl
);
21408 /* Output debug information for imported module or decl DECL.
21409 NAME is non-NULL name in the lexical block if the decl has been renamed.
21410 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
21411 that DECL belongs to.
21412 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
21414 dwarf2out_imported_module_or_decl_1 (tree decl
,
21416 tree lexical_block
,
21417 dw_die_ref lexical_block_die
)
21419 expanded_location xloc
;
21420 dw_die_ref imported_die
= NULL
;
21421 dw_die_ref at_import_die
;
21423 if (TREE_CODE (decl
) == IMPORTED_DECL
)
21425 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
21426 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
21430 xloc
= expand_location (input_location
);
21432 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
21434 at_import_die
= force_type_die (TREE_TYPE (decl
));
21435 /* For namespace N { typedef void T; } using N::T; base_type_die
21436 returns NULL, but DW_TAG_imported_declaration requires
21437 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
21438 if (!at_import_die
)
21440 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
21441 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
21442 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
21443 gcc_assert (at_import_die
);
21448 at_import_die
= lookup_decl_die (decl
);
21449 if (!at_import_die
)
21451 /* If we're trying to avoid duplicate debug info, we may not have
21452 emitted the member decl for this field. Emit it now. */
21453 if (TREE_CODE (decl
) == FIELD_DECL
)
21455 tree type
= DECL_CONTEXT (decl
);
21457 if (TYPE_CONTEXT (type
)
21458 && TYPE_P (TYPE_CONTEXT (type
))
21459 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
21460 DINFO_USAGE_DIR_USE
))
21462 gen_type_die_for_member (type
, decl
,
21463 get_context_die (TYPE_CONTEXT (type
)));
21465 at_import_die
= force_decl_die (decl
);
21469 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
21471 if (dwarf_version
>= 3 || !dwarf_strict
)
21472 imported_die
= new_die (DW_TAG_imported_module
,
21479 imported_die
= new_die (DW_TAG_imported_declaration
,
21483 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
21484 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
21486 add_AT_string (imported_die
, DW_AT_name
,
21487 IDENTIFIER_POINTER (name
));
21488 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
21491 /* Output debug information for imported module or decl DECL.
21492 NAME is non-NULL name in context if the decl has been renamed.
21493 CHILD is true if decl is one of the renamed decls as part of
21494 importing whole module. */
21497 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
21500 /* dw_die_ref at_import_die; */
21501 dw_die_ref scope_die
;
21503 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21508 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
21509 We need decl DIE for reference and scope die. First, get DIE for the decl
21512 /* Get the scope die for decl context. Use comp_unit_die for global module
21513 or decl. If die is not found for non globals, force new die. */
21515 && TYPE_P (context
)
21516 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
21519 if (!(dwarf_version
>= 3 || !dwarf_strict
))
21522 scope_die
= get_context_die (context
);
21526 gcc_assert (scope_die
->die_child
);
21527 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
21528 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
21529 scope_die
= scope_die
->die_child
;
21532 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
21533 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
21537 /* Write the debugging output for DECL. */
21540 dwarf2out_decl (tree decl
)
21542 dw_die_ref context_die
= comp_unit_die ();
21544 switch (TREE_CODE (decl
))
21549 case FUNCTION_DECL
:
21550 /* What we would really like to do here is to filter out all mere
21551 file-scope declarations of file-scope functions which are never
21552 referenced later within this translation unit (and keep all of ones
21553 that *are* referenced later on) but we aren't clairvoyant, so we have
21554 no idea which functions will be referenced in the future (i.e. later
21555 on within the current translation unit). So here we just ignore all
21556 file-scope function declarations which are not also definitions. If
21557 and when the debugger needs to know something about these functions,
21558 it will have to hunt around and find the DWARF information associated
21559 with the definition of the function.
21561 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
21562 nodes represent definitions and which ones represent mere
21563 declarations. We have to check DECL_INITIAL instead. That's because
21564 the C front-end supports some weird semantics for "extern inline"
21565 function definitions. These can get inlined within the current
21566 translation unit (and thus, we need to generate Dwarf info for their
21567 abstract instances so that the Dwarf info for the concrete inlined
21568 instances can have something to refer to) but the compiler never
21569 generates any out-of-lines instances of such things (despite the fact
21570 that they *are* definitions).
21572 The important point is that the C front-end marks these "extern
21573 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
21574 them anyway. Note that the C++ front-end also plays some similar games
21575 for inline function definitions appearing within include files which
21576 also contain `#pragma interface' pragmas. */
21577 if (DECL_INITIAL (decl
) == NULL_TREE
)
21580 /* If we're a nested function, initially use a parent of NULL; if we're
21581 a plain function, this will be fixed up in decls_for_scope. If
21582 we're a method, it will be ignored, since we already have a DIE. */
21583 if (decl_function_context (decl
)
21584 /* But if we're in terse mode, we don't care about scope. */
21585 && debug_info_level
> DINFO_LEVEL_TERSE
)
21586 context_die
= NULL
;
21590 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
21591 declaration and if the declaration was never even referenced from
21592 within this entire compilation unit. We suppress these DIEs in
21593 order to save space in the .debug section (by eliminating entries
21594 which are probably useless). Note that we must not suppress
21595 block-local extern declarations (whether used or not) because that
21596 would screw-up the debugger's name lookup mechanism and cause it to
21597 miss things which really ought to be in scope at a given point. */
21598 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
21601 /* For local statics lookup proper context die. */
21602 if (TREE_STATIC (decl
) && decl_function_context (decl
))
21603 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
21605 /* If we are in terse mode, don't generate any DIEs to represent any
21606 variable declarations or definitions. */
21607 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21612 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21614 if (!is_fortran () && !is_ada ())
21616 if (TREE_STATIC (decl
) && decl_function_context (decl
))
21617 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
21620 case NAMESPACE_DECL
:
21621 case IMPORTED_DECL
:
21622 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21624 if (lookup_decl_die (decl
) != NULL
)
21629 /* Don't emit stubs for types unless they are needed by other DIEs. */
21630 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
21633 /* Don't bother trying to generate any DIEs to represent any of the
21634 normal built-in types for the language we are compiling. */
21635 if (DECL_IS_BUILTIN (decl
))
21638 /* If we are in terse mode, don't generate any DIEs for types. */
21639 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21642 /* If we're a function-scope tag, initially use a parent of NULL;
21643 this will be fixed up in decls_for_scope. */
21644 if (decl_function_context (decl
))
21645 context_die
= NULL
;
21653 gen_decl_die (decl
, NULL
, context_die
);
21656 /* Write the debugging output for DECL. */
21659 dwarf2out_function_decl (tree decl
)
21661 dwarf2out_decl (decl
);
21662 call_arg_locations
= NULL
;
21663 call_arg_loc_last
= NULL
;
21664 call_site_count
= -1;
21665 tail_call_site_count
= -1;
21666 VEC_free (dw_die_ref
, heap
, block_map
);
21667 htab_empty (decl_loc_table
);
21668 htab_empty (cached_dw_loc_list_table
);
21671 /* Output a marker (i.e. a label) for the beginning of the generated code for
21672 a lexical block. */
21675 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
21676 unsigned int blocknum
)
21678 switch_to_section (current_function_section ());
21679 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
21682 /* Output a marker (i.e. a label) for the end of the generated code for a
21686 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
21688 switch_to_section (current_function_section ());
21689 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
21692 /* Returns nonzero if it is appropriate not to emit any debugging
21693 information for BLOCK, because it doesn't contain any instructions.
21695 Don't allow this for blocks with nested functions or local classes
21696 as we would end up with orphans, and in the presence of scheduling
21697 we may end up calling them anyway. */
21700 dwarf2out_ignore_block (const_tree block
)
21705 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
21706 if (TREE_CODE (decl
) == FUNCTION_DECL
21707 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
21709 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
21711 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
21712 if (TREE_CODE (decl
) == FUNCTION_DECL
21713 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
21720 /* Hash table routines for file_hash. */
21723 file_table_eq (const void *p1_p
, const void *p2_p
)
21725 const struct dwarf_file_data
*const p1
=
21726 (const struct dwarf_file_data
*) p1_p
;
21727 const char *const p2
= (const char *) p2_p
;
21728 return filename_cmp (p1
->filename
, p2
) == 0;
21732 file_table_hash (const void *p_p
)
21734 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
21735 return htab_hash_string (p
->filename
);
21738 /* Lookup FILE_NAME (in the list of filenames that we know about here in
21739 dwarf2out.c) and return its "index". The index of each (known) filename is
21740 just a unique number which is associated with only that one filename. We
21741 need such numbers for the sake of generating labels (in the .debug_sfnames
21742 section) and references to those files numbers (in the .debug_srcinfo
21743 and.debug_macinfo sections). If the filename given as an argument is not
21744 found in our current list, add it to the list and assign it the next
21745 available unique index number. In order to speed up searches, we remember
21746 the index of the filename was looked up last. This handles the majority of
21749 static struct dwarf_file_data
*
21750 lookup_filename (const char *file_name
)
21753 struct dwarf_file_data
* created
;
21755 /* Check to see if the file name that was searched on the previous
21756 call matches this file name. If so, return the index. */
21757 if (file_table_last_lookup
21758 && (file_name
== file_table_last_lookup
->filename
21759 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
21760 return file_table_last_lookup
;
21762 /* Didn't match the previous lookup, search the table. */
21763 slot
= htab_find_slot_with_hash (file_table
, file_name
,
21764 htab_hash_string (file_name
), INSERT
);
21766 return (struct dwarf_file_data
*) *slot
;
21768 created
= ggc_alloc_dwarf_file_data ();
21769 created
->filename
= file_name
;
21770 created
->emitted_number
= 0;
21775 /* If the assembler will construct the file table, then translate the compiler
21776 internal file table number into the assembler file table number, and emit
21777 a .file directive if we haven't already emitted one yet. The file table
21778 numbers are different because we prune debug info for unused variables and
21779 types, which may include filenames. */
21782 maybe_emit_file (struct dwarf_file_data
* fd
)
21784 if (! fd
->emitted_number
)
21786 if (last_emitted_file
)
21787 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
21789 fd
->emitted_number
= 1;
21790 last_emitted_file
= fd
;
21792 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21794 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
21795 output_quoted_string (asm_out_file
,
21796 remap_debug_filename (fd
->filename
));
21797 fputc ('\n', asm_out_file
);
21801 return fd
->emitted_number
;
21804 /* Schedule generation of a DW_AT_const_value attribute to DIE.
21805 That generation should happen after function debug info has been
21806 generated. The value of the attribute is the constant value of ARG. */
21809 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
21811 die_arg_entry entry
;
21816 if (!tmpl_value_parm_die_table
)
21817 tmpl_value_parm_die_table
21818 = VEC_alloc (die_arg_entry
, gc
, 32);
21822 VEC_safe_push (die_arg_entry
, gc
,
21823 tmpl_value_parm_die_table
,
21827 /* Return TRUE if T is an instance of generic type, FALSE
21831 generic_type_p (tree t
)
21833 if (t
== NULL_TREE
|| !TYPE_P (t
))
21835 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
21838 /* Schedule the generation of the generic parameter dies for the
21839 instance of generic type T. The proper generation itself is later
21840 done by gen_scheduled_generic_parms_dies. */
21843 schedule_generic_params_dies_gen (tree t
)
21845 if (!generic_type_p (t
))
21848 if (generic_type_instances
== NULL
)
21849 generic_type_instances
= VEC_alloc (tree
, gc
, 256);
21851 VEC_safe_push (tree
, gc
, generic_type_instances
, t
);
21854 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
21855 by append_entry_to_tmpl_value_parm_die_table. This function must
21856 be called after function DIEs have been generated. */
21859 gen_remaining_tmpl_value_param_die_attribute (void)
21861 if (tmpl_value_parm_die_table
)
21866 FOR_EACH_VEC_ELT (die_arg_entry
, tmpl_value_parm_die_table
, i
, e
)
21867 tree_add_const_value_attribute (e
->die
, e
->arg
);
21871 /* Generate generic parameters DIEs for instances of generic types
21872 that have been previously scheduled by
21873 schedule_generic_params_dies_gen. This function must be called
21874 after all the types of the CU have been laid out. */
21877 gen_scheduled_generic_parms_dies (void)
21882 if (generic_type_instances
== NULL
)
21885 FOR_EACH_VEC_ELT (tree
, generic_type_instances
, i
, t
)
21886 gen_generic_params_dies (t
);
21890 /* Replace DW_AT_name for the decl with name. */
21893 dwarf2out_set_name (tree decl
, tree name
)
21899 die
= TYPE_SYMTAB_DIE (decl
);
21903 dname
= dwarf2_name (name
, 0);
21907 attr
= get_AT (die
, DW_AT_name
);
21910 struct indirect_string_node
*node
;
21912 node
= find_AT_string (dname
);
21913 /* replace the string. */
21914 attr
->dw_attr_val
.v
.val_str
= node
;
21918 add_name_attribute (die
, dname
);
21921 /* Called by the final INSN scan whenever we see a var location. We
21922 use it to drop labels in the right places, and throw the location in
21923 our lookup table. */
21926 dwarf2out_var_location (rtx loc_note
)
21928 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
21929 struct var_loc_node
*newloc
;
21931 static const char *last_label
;
21932 static const char *last_postcall_label
;
21933 static bool last_in_cold_section_p
;
21937 if (!NOTE_P (loc_note
))
21939 if (CALL_P (loc_note
))
21942 if (SIBLING_CALL_P (loc_note
))
21943 tail_call_site_count
++;
21948 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
21949 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
21952 next_real
= next_real_insn (loc_note
);
21954 /* If there are no instructions which would be affected by this note,
21955 don't do anything. */
21957 && next_real
== NULL_RTX
21958 && !NOTE_DURING_CALL_P (loc_note
))
21961 if (next_real
== NULL_RTX
)
21962 next_real
= get_last_insn ();
21964 /* If there were any real insns between note we processed last time
21965 and this note (or if it is the first note), clear
21966 last_{,postcall_}label so that they are not reused this time. */
21967 if (last_var_location_insn
== NULL_RTX
21968 || last_var_location_insn
!= next_real
21969 || last_in_cold_section_p
!= in_cold_section_p
)
21972 last_postcall_label
= NULL
;
21977 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
21978 newloc
= add_var_loc_to_decl (decl
, loc_note
,
21979 NOTE_DURING_CALL_P (loc_note
)
21980 ? last_postcall_label
: last_label
);
21981 if (newloc
== NULL
)
21990 /* If there were no real insns between note we processed last time
21991 and this note, use the label we emitted last time. Otherwise
21992 create a new label and emit it. */
21993 if (last_label
== NULL
)
21995 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
21996 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
21998 last_label
= ggc_strdup (loclabel
);
22003 struct call_arg_loc_node
*ca_loc
22004 = ggc_alloc_cleared_call_arg_loc_node ();
22005 rtx prev
= prev_real_insn (loc_note
), x
;
22006 ca_loc
->call_arg_loc_note
= loc_note
;
22007 ca_loc
->next
= NULL
;
22008 ca_loc
->label
= last_label
;
22011 || (NONJUMP_INSN_P (prev
)
22012 && GET_CODE (PATTERN (prev
)) == SEQUENCE
22013 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
22014 if (!CALL_P (prev
))
22015 prev
= XVECEXP (PATTERN (prev
), 0, 0);
22016 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
22017 x
= PATTERN (prev
);
22018 if (GET_CODE (x
) == PARALLEL
)
22019 x
= XVECEXP (x
, 0, 0);
22020 if (GET_CODE (x
) == SET
)
22022 if (GET_CODE (x
) == CALL
&& MEM_P (XEXP (x
, 0)))
22024 x
= XEXP (XEXP (x
, 0), 0);
22025 if (GET_CODE (x
) == SYMBOL_REF
22026 && SYMBOL_REF_DECL (x
)
22027 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
22028 ca_loc
->symbol_ref
= x
;
22030 ca_loc
->block
= insn_scope (prev
);
22031 if (call_arg_locations
)
22032 call_arg_loc_last
->next
= ca_loc
;
22034 call_arg_locations
= ca_loc
;
22035 call_arg_loc_last
= ca_loc
;
22037 else if (!NOTE_DURING_CALL_P (loc_note
))
22038 newloc
->label
= last_label
;
22041 if (!last_postcall_label
)
22043 sprintf (loclabel
, "%s-1", last_label
);
22044 last_postcall_label
= ggc_strdup (loclabel
);
22046 newloc
->label
= last_postcall_label
;
22049 last_var_location_insn
= next_real
;
22050 last_in_cold_section_p
= in_cold_section_p
;
22053 /* Note in one location list that text section has changed. */
22056 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
22058 var_loc_list
*list
= (var_loc_list
*) *slot
;
22060 list
->last_before_switch
22061 = list
->last
->next
? list
->last
->next
: list
->last
;
22065 /* Note in all location lists that text section has changed. */
22068 var_location_switch_text_section (void)
22070 if (decl_loc_table
== NULL
)
22073 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
22076 /* Create a new line number table. */
22078 static dw_line_info_table
*
22079 new_line_info_table (void)
22081 dw_line_info_table
*table
;
22083 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
22084 table
->file_num
= 1;
22085 table
->line_num
= 1;
22086 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
22091 /* Lookup the "current" table into which we emit line info, so
22092 that we don't have to do it for every source line. */
22095 set_cur_line_info_table (section
*sec
)
22097 dw_line_info_table
*table
;
22099 if (sec
== text_section
)
22100 table
= text_section_line_info
;
22101 else if (sec
== cold_text_section
)
22103 table
= cold_text_section_line_info
;
22106 cold_text_section_line_info
= table
= new_line_info_table ();
22107 table
->end_label
= cold_end_label
;
22112 const char *end_label
;
22114 if (flag_reorder_blocks_and_partition
)
22116 if (in_cold_section_p
)
22117 end_label
= crtl
->subsections
.cold_section_end_label
;
22119 end_label
= crtl
->subsections
.hot_section_end_label
;
22123 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22124 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
22125 current_function_funcdef_no
);
22126 end_label
= ggc_strdup (label
);
22129 table
= new_line_info_table ();
22130 table
->end_label
= end_label
;
22132 VEC_safe_push (dw_line_info_table_p
, gc
, separate_line_info
, table
);
22135 cur_line_info_table
= table
;
22139 /* We need to reset the locations at the beginning of each
22140 function. We can't do this in the end_function hook, because the
22141 declarations that use the locations won't have been output when
22142 that hook is called. Also compute have_multiple_function_sections here. */
22145 dwarf2out_begin_function (tree fun
)
22147 section
*sec
= function_section (fun
);
22149 if (sec
!= text_section
)
22150 have_multiple_function_sections
= true;
22152 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
22154 gcc_assert (current_function_decl
== fun
);
22155 cold_text_section
= unlikely_text_section ();
22156 switch_to_section (cold_text_section
);
22157 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
22158 switch_to_section (sec
);
22161 dwarf2out_note_section_used ();
22162 call_site_count
= 0;
22163 tail_call_site_count
= 0;
22165 set_cur_line_info_table (sec
);
22168 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
22171 push_dw_line_info_entry (dw_line_info_table
*table
,
22172 enum dw_line_info_opcode opcode
, unsigned int val
)
22174 dw_line_info_entry e
;
22177 VEC_safe_push (dw_line_info_entry
, gc
, table
->entries
, &e
);
22180 /* Output a label to mark the beginning of a source code line entry
22181 and record information relating to this source line, in
22182 'line_info_table' for later output of the .debug_line section. */
22183 /* ??? The discriminator parameter ought to be unsigned. */
22186 dwarf2out_source_line (unsigned int line
, const char *filename
,
22187 int discriminator
, bool is_stmt
)
22189 unsigned int file_num
;
22190 dw_line_info_table
*table
;
22192 if (debug_info_level
< DINFO_LEVEL_NORMAL
|| line
== 0)
22195 /* The discriminator column was added in dwarf4. Simplify the below
22196 by simply removing it if we're not supposed to output it. */
22197 if (dwarf_version
< 4 && dwarf_strict
)
22200 table
= cur_line_info_table
;
22201 file_num
= maybe_emit_file (lookup_filename (filename
));
22203 /* ??? TODO: Elide duplicate line number entries. Traditionally,
22204 the debugger has used the second (possibly duplicate) line number
22205 at the beginning of the function to mark the end of the prologue.
22206 We could eliminate any other duplicates within the function. For
22207 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
22208 that second line number entry. */
22209 /* Recall that this end-of-prologue indication is *not* the same thing
22210 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
22211 to which the hook corresponds, follows the last insn that was
22212 emitted by gen_prologue. What we need is to preceed the first insn
22213 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
22214 insn that corresponds to something the user wrote. These may be
22215 very different locations once scheduling is enabled. */
22217 if (0 && file_num
== table
->file_num
22218 && line
== table
->line_num
22219 && discriminator
== table
->discrim_num
22220 && is_stmt
== table
->is_stmt
)
22223 switch_to_section (current_function_section ());
22225 /* If requested, emit something human-readable. */
22226 if (flag_debug_asm
)
22227 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
22229 if (DWARF2_ASM_LINE_DEBUG_INFO
)
22231 /* Emit the .loc directive understood by GNU as. */
22232 fprintf (asm_out_file
, "\t.loc %d %d 0", file_num
, line
);
22233 if (is_stmt
!= table
->is_stmt
)
22234 fprintf (asm_out_file
, " is_stmt %d", is_stmt
? 1 : 0);
22235 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
22236 fprintf (asm_out_file
, " discriminator %d", discriminator
);
22237 fputc ('\n', asm_out_file
);
22241 unsigned int label_num
= ++line_info_label_num
;
22243 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
22245 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
22246 if (file_num
!= table
->file_num
)
22247 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
22248 if (discriminator
!= table
->discrim_num
)
22249 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
22250 if (is_stmt
!= table
->is_stmt
)
22251 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
22252 push_dw_line_info_entry (table
, LI_set_line
, line
);
22255 table
->file_num
= file_num
;
22256 table
->line_num
= line
;
22257 table
->discrim_num
= discriminator
;
22258 table
->is_stmt
= is_stmt
;
22259 table
->in_use
= true;
22262 /* Record the beginning of a new source file. */
22265 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
22267 if (flag_eliminate_dwarf2_dups
&& ! use_debug_types
)
22269 /* Record the beginning of the file for break_out_includes. */
22270 dw_die_ref bincl_die
;
22272 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
22273 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
22276 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22279 e
.code
= DW_MACINFO_start_file
;
22281 e
.info
= xstrdup (filename
);
22282 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
22286 /* Record the end of a source file. */
22289 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
22291 if (flag_eliminate_dwarf2_dups
&& ! use_debug_types
)
22292 /* Record the end of the file for break_out_includes. */
22293 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
22295 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22298 e
.code
= DW_MACINFO_end_file
;
22301 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
22305 /* Called from debug_define in toplev.c. The `buffer' parameter contains
22306 the tail part of the directive line, i.e. the part which is past the
22307 initial whitespace, #, whitespace, directive-name, whitespace part. */
22310 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
22311 const char *buffer ATTRIBUTE_UNUSED
)
22313 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22316 e
.code
= DW_MACINFO_define
;
22318 e
.info
= xstrdup (buffer
);;
22319 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
22323 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
22324 the tail part of the directive line, i.e. the part which is past the
22325 initial whitespace, #, whitespace, directive-name, whitespace part. */
22328 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
22329 const char *buffer ATTRIBUTE_UNUSED
)
22331 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22334 e
.code
= DW_MACINFO_undef
;
22336 e
.info
= xstrdup (buffer
);;
22337 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
22342 output_macinfo (void)
22345 unsigned long length
= VEC_length (macinfo_entry
, macinfo_table
);
22346 macinfo_entry
*ref
;
22351 for (i
= 0; VEC_iterate (macinfo_entry
, macinfo_table
, i
, ref
); i
++)
22355 case DW_MACINFO_start_file
:
22357 int file_num
= maybe_emit_file (lookup_filename (ref
->info
));
22358 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
22359 dw2_asm_output_data_uleb128
22360 (ref
->lineno
, "Included from line number %lu",
22361 (unsigned long)ref
->lineno
);
22362 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
22365 case DW_MACINFO_end_file
:
22366 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
22368 case DW_MACINFO_define
:
22369 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
22370 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
22371 (unsigned long)ref
->lineno
);
22372 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
22374 case DW_MACINFO_undef
:
22375 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
22376 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
22377 (unsigned long)ref
->lineno
);
22378 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
22381 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
22382 ASM_COMMENT_START
, (unsigned long)ref
->code
);
22388 /* Set up for Dwarf output at the start of compilation. */
22391 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
22393 /* Allocate the file_table. */
22394 file_table
= htab_create_ggc (50, file_table_hash
,
22395 file_table_eq
, NULL
);
22397 /* Allocate the decl_die_table. */
22398 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
22399 decl_die_table_eq
, NULL
);
22401 /* Allocate the decl_loc_table. */
22402 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
22403 decl_loc_table_eq
, NULL
);
22405 /* Allocate the cached_dw_loc_list_table. */
22406 cached_dw_loc_list_table
22407 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
22408 cached_dw_loc_list_table_eq
, NULL
);
22410 /* Allocate the initial hunk of the decl_scope_table. */
22411 decl_scope_table
= VEC_alloc (tree
, gc
, 256);
22413 /* Allocate the initial hunk of the abbrev_die_table. */
22414 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
22415 (ABBREV_DIE_TABLE_INCREMENT
);
22416 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
22417 /* Zero-th entry is allocated, but unused. */
22418 abbrev_die_table_in_use
= 1;
22420 /* Allocate the pubtypes and pubnames vectors. */
22421 pubname_table
= VEC_alloc (pubname_entry
, gc
, 32);
22422 pubtype_table
= VEC_alloc (pubname_entry
, gc
, 32);
22424 incomplete_types
= VEC_alloc (tree
, gc
, 64);
22426 used_rtx_array
= VEC_alloc (rtx
, gc
, 32);
22428 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
22429 SECTION_DEBUG
, NULL
);
22430 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
22431 SECTION_DEBUG
, NULL
);
22432 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
22433 SECTION_DEBUG
, NULL
);
22434 debug_macinfo_section
= get_section (DEBUG_MACINFO_SECTION
,
22435 SECTION_DEBUG
, NULL
);
22436 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
22437 SECTION_DEBUG
, NULL
);
22438 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
22439 SECTION_DEBUG
, NULL
);
22440 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
22441 SECTION_DEBUG
, NULL
);
22442 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
22443 SECTION_DEBUG
, NULL
);
22444 debug_str_section
= get_section (DEBUG_STR_SECTION
,
22445 DEBUG_STR_SECTION_FLAGS
, NULL
);
22446 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
22447 SECTION_DEBUG
, NULL
);
22448 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
22449 SECTION_DEBUG
, NULL
);
22451 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
22452 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
22453 DEBUG_ABBREV_SECTION_LABEL
, 0);
22454 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
22455 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
22456 COLD_TEXT_SECTION_LABEL
, 0);
22457 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
22459 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
22460 DEBUG_INFO_SECTION_LABEL
, 0);
22461 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
22462 DEBUG_LINE_SECTION_LABEL
, 0);
22463 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
22464 DEBUG_RANGES_SECTION_LABEL
, 0);
22465 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
22466 DEBUG_MACINFO_SECTION_LABEL
, 0);
22468 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22469 macinfo_table
= VEC_alloc (macinfo_entry
, gc
, 64);
22471 switch_to_section (text_section
);
22472 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
22474 /* Make sure the line number table for .text always exists. */
22475 text_section_line_info
= new_line_info_table ();
22476 text_section_line_info
->end_label
= text_end_label
;
22479 /* Called before cgraph_optimize starts outputtting functions, variables
22480 and toplevel asms into assembly. */
22483 dwarf2out_assembly_start (void)
22485 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
22486 && dwarf2out_do_cfi_asm ()
22487 && (!(flag_unwind_tables
|| flag_exceptions
)
22488 || targetm
.except_unwind_info (&global_options
) != UI_DWARF2
))
22489 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
22492 /* A helper function for dwarf2out_finish called through
22493 htab_traverse. Emit one queued .debug_str string. */
22496 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
22498 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22500 if (node
->label
&& node
->refcount
)
22502 switch_to_section (debug_str_section
);
22503 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
22504 assemble_string (node
->str
, strlen (node
->str
) + 1);
22510 #if ENABLE_ASSERT_CHECKING
22511 /* Verify that all marks are clear. */
22514 verify_marks_clear (dw_die_ref die
)
22518 gcc_assert (! die
->die_mark
);
22519 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
22521 #endif /* ENABLE_ASSERT_CHECKING */
22523 /* Clear the marks for a die and its children.
22524 Be cool if the mark isn't set. */
22527 prune_unmark_dies (dw_die_ref die
)
22533 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
22536 /* Given DIE that we're marking as used, find any other dies
22537 it references as attributes and mark them as used. */
22540 prune_unused_types_walk_attribs (dw_die_ref die
)
22545 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
22547 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
22549 /* A reference to another DIE.
22550 Make sure that it will get emitted.
22551 If it was broken out into a comdat group, don't follow it. */
22552 if (! use_debug_types
22553 || a
->dw_attr
== DW_AT_specification
22554 || a
->dw_attr_val
.v
.val_die_ref
.die
->die_id
.die_type_node
== NULL
)
22555 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
22557 /* Set the string's refcount to 0 so that prune_unused_types_mark
22558 accounts properly for it. */
22559 if (AT_class (a
) == dw_val_class_str
)
22560 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
22564 /* Mark the generic parameters and arguments children DIEs of DIE. */
22567 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
22571 if (die
== NULL
|| die
->die_child
== NULL
)
22573 c
= die
->die_child
;
22576 switch (c
->die_tag
)
22578 case DW_TAG_template_type_param
:
22579 case DW_TAG_template_value_param
:
22580 case DW_TAG_GNU_template_template_param
:
22581 case DW_TAG_GNU_template_parameter_pack
:
22582 prune_unused_types_mark (c
, 1);
22588 } while (c
&& c
!= die
->die_child
);
22591 /* Mark DIE as being used. If DOKIDS is true, then walk down
22592 to DIE's children. */
22595 prune_unused_types_mark (dw_die_ref die
, int dokids
)
22599 if (die
->die_mark
== 0)
22601 /* We haven't done this node yet. Mark it as used. */
22603 /* If this is the DIE of a generic type instantiation,
22604 mark the children DIEs that describe its generic parms and
22606 prune_unused_types_mark_generic_parms_dies (die
);
22608 /* We also have to mark its parents as used.
22609 (But we don't want to mark our parents' kids due to this.) */
22610 if (die
->die_parent
)
22611 prune_unused_types_mark (die
->die_parent
, 0);
22613 /* Mark any referenced nodes. */
22614 prune_unused_types_walk_attribs (die
);
22616 /* If this node is a specification,
22617 also mark the definition, if it exists. */
22618 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
22619 prune_unused_types_mark (die
->die_definition
, 1);
22622 if (dokids
&& die
->die_mark
!= 2)
22624 /* We need to walk the children, but haven't done so yet.
22625 Remember that we've walked the kids. */
22628 /* If this is an array type, we need to make sure our
22629 kids get marked, even if they're types. If we're
22630 breaking out types into comdat sections, do this
22631 for all type definitions. */
22632 if (die
->die_tag
== DW_TAG_array_type
22633 || (use_debug_types
22634 && is_type_die (die
) && ! is_declaration_die (die
)))
22635 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
22637 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22641 /* For local classes, look if any static member functions were emitted
22642 and if so, mark them. */
22645 prune_unused_types_walk_local_classes (dw_die_ref die
)
22649 if (die
->die_mark
== 2)
22652 switch (die
->die_tag
)
22654 case DW_TAG_structure_type
:
22655 case DW_TAG_union_type
:
22656 case DW_TAG_class_type
:
22659 case DW_TAG_subprogram
:
22660 if (!get_AT_flag (die
, DW_AT_declaration
)
22661 || die
->die_definition
!= NULL
)
22662 prune_unused_types_mark (die
, 1);
22669 /* Mark children. */
22670 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
22673 /* Walk the tree DIE and mark types that we actually use. */
22676 prune_unused_types_walk (dw_die_ref die
)
22680 /* Don't do anything if this node is already marked and
22681 children have been marked as well. */
22682 if (die
->die_mark
== 2)
22685 switch (die
->die_tag
)
22687 case DW_TAG_structure_type
:
22688 case DW_TAG_union_type
:
22689 case DW_TAG_class_type
:
22690 if (die
->die_perennial_p
)
22693 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
22694 if (c
->die_tag
== DW_TAG_subprogram
)
22697 /* Finding used static member functions inside of classes
22698 is needed just for local classes, because for other classes
22699 static member function DIEs with DW_AT_specification
22700 are emitted outside of the DW_TAG_*_type. If we ever change
22701 it, we'd need to call this even for non-local classes. */
22703 prune_unused_types_walk_local_classes (die
);
22705 /* It's a type node --- don't mark it. */
22708 case DW_TAG_const_type
:
22709 case DW_TAG_packed_type
:
22710 case DW_TAG_pointer_type
:
22711 case DW_TAG_reference_type
:
22712 case DW_TAG_rvalue_reference_type
:
22713 case DW_TAG_volatile_type
:
22714 case DW_TAG_typedef
:
22715 case DW_TAG_array_type
:
22716 case DW_TAG_interface_type
:
22717 case DW_TAG_friend
:
22718 case DW_TAG_variant_part
:
22719 case DW_TAG_enumeration_type
:
22720 case DW_TAG_subroutine_type
:
22721 case DW_TAG_string_type
:
22722 case DW_TAG_set_type
:
22723 case DW_TAG_subrange_type
:
22724 case DW_TAG_ptr_to_member_type
:
22725 case DW_TAG_file_type
:
22726 if (die
->die_perennial_p
)
22729 /* It's a type node --- don't mark it. */
22733 /* Mark everything else. */
22737 if (die
->die_mark
== 0)
22741 /* Now, mark any dies referenced from here. */
22742 prune_unused_types_walk_attribs (die
);
22747 /* Mark children. */
22748 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22751 /* Increment the string counts on strings referred to from DIE's
22755 prune_unused_types_update_strings (dw_die_ref die
)
22760 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
22761 if (AT_class (a
) == dw_val_class_str
)
22763 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22765 /* Avoid unnecessarily putting strings that are used less than
22766 twice in the hash table. */
22768 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22771 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22772 htab_hash_string (s
->str
),
22774 gcc_assert (*slot
== NULL
);
22780 /* Remove from the tree DIE any dies that aren't marked. */
22783 prune_unused_types_prune (dw_die_ref die
)
22787 gcc_assert (die
->die_mark
);
22788 prune_unused_types_update_strings (die
);
22790 if (! die
->die_child
)
22793 c
= die
->die_child
;
22795 dw_die_ref prev
= c
;
22796 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22797 if (c
== die
->die_child
)
22799 /* No marked children between 'prev' and the end of the list. */
22801 /* No marked children at all. */
22802 die
->die_child
= NULL
;
22805 prev
->die_sib
= c
->die_sib
;
22806 die
->die_child
= prev
;
22811 if (c
!= prev
->die_sib
)
22813 prune_unused_types_prune (c
);
22814 } while (c
!= die
->die_child
);
22817 /* A helper function for dwarf2out_finish called through
22818 htab_traverse. Clear .debug_str strings that we haven't already
22819 decided to emit. */
22822 prune_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
22824 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22826 if (!node
->label
|| !node
->refcount
)
22827 htab_clear_slot (debug_str_hash
, h
);
22832 /* Remove dies representing declarations that we never use. */
22835 prune_unused_types (void)
22838 limbo_die_node
*node
;
22839 comdat_type_node
*ctnode
;
22842 #if ENABLE_ASSERT_CHECKING
22843 /* All the marks should already be clear. */
22844 verify_marks_clear (comp_unit_die ());
22845 for (node
= limbo_die_list
; node
; node
= node
->next
)
22846 verify_marks_clear (node
->die
);
22847 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22848 verify_marks_clear (ctnode
->root_die
);
22849 #endif /* ENABLE_ASSERT_CHECKING */
22851 /* Mark types that are used in global variables. */
22852 premark_types_used_by_global_vars ();
22854 /* Set the mark on nodes that are actually used. */
22855 prune_unused_types_walk (comp_unit_die ());
22856 for (node
= limbo_die_list
; node
; node
= node
->next
)
22857 prune_unused_types_walk (node
->die
);
22858 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22860 prune_unused_types_walk (ctnode
->root_die
);
22861 prune_unused_types_mark (ctnode
->type_die
, 1);
22864 /* Also set the mark on nodes referenced from the
22866 FOR_EACH_VEC_ELT (pubname_entry
, pubname_table
, i
, pub
)
22867 prune_unused_types_mark (pub
->die
, 1);
22869 /* Get rid of nodes that aren't marked; and update the string counts. */
22870 if (debug_str_hash
&& debug_str_hash_forced
)
22871 htab_traverse (debug_str_hash
, prune_indirect_string
, NULL
);
22872 else if (debug_str_hash
)
22873 htab_empty (debug_str_hash
);
22874 prune_unused_types_prune (comp_unit_die ());
22875 for (node
= limbo_die_list
; node
; node
= node
->next
)
22876 prune_unused_types_prune (node
->die
);
22877 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22878 prune_unused_types_prune (ctnode
->root_die
);
22880 /* Leave the marks clear. */
22881 prune_unmark_dies (comp_unit_die ());
22882 for (node
= limbo_die_list
; node
; node
= node
->next
)
22883 prune_unmark_dies (node
->die
);
22884 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22885 prune_unmark_dies (ctnode
->root_die
);
22888 /* Set the parameter to true if there are any relative pathnames in
22891 file_table_relative_p (void ** slot
, void *param
)
22893 bool *p
= (bool *) param
;
22894 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22895 if (!IS_ABSOLUTE_PATH (d
->filename
))
22903 /* Routines to manipulate hash table of comdat type units. */
22906 htab_ct_hash (const void *of
)
22909 const comdat_type_node
*const type_node
= (const comdat_type_node
*) of
;
22911 memcpy (&h
, type_node
->signature
, sizeof (h
));
22916 htab_ct_eq (const void *of1
, const void *of2
)
22918 const comdat_type_node
*const type_node_1
= (const comdat_type_node
*) of1
;
22919 const comdat_type_node
*const type_node_2
= (const comdat_type_node
*) of2
;
22921 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22922 DWARF_TYPE_SIGNATURE_SIZE
));
22925 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22926 to the location it would have been added, should we know its
22927 DECL_ASSEMBLER_NAME when we added other attributes. This will
22928 probably improve compactness of debug info, removing equivalent
22929 abbrevs, and hide any differences caused by deferring the
22930 computation of the assembler name, triggered by e.g. PCH. */
22933 move_linkage_attr (dw_die_ref die
)
22935 unsigned ix
= VEC_length (dw_attr_node
, die
->die_attr
);
22936 dw_attr_node linkage
= *VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
22938 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22939 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22943 dw_attr_node
*prev
= VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
22945 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22949 if (ix
!= VEC_length (dw_attr_node
, die
->die_attr
) - 1)
22951 VEC_pop (dw_attr_node
, die
->die_attr
);
22952 VEC_quick_insert (dw_attr_node
, die
->die_attr
, ix
, &linkage
);
22956 /* Helper function for resolve_addr, attempt to resolve
22957 one CONST_STRING, return non-zero if not successful. Similarly verify that
22958 SYMBOL_REFs refer to variables emitted in the current CU. */
22961 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
22965 if (GET_CODE (rtl
) == CONST_STRING
)
22967 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22968 tree t
= build_string (len
, XSTR (rtl
, 0));
22969 tree tlen
= build_int_cst (NULL_TREE
, len
- 1);
22971 = build_array_type (char_type_node
, build_index_type (tlen
));
22972 rtl
= lookup_constant_def (t
);
22973 if (!rtl
|| !MEM_P (rtl
))
22975 rtl
= XEXP (rtl
, 0);
22976 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
22981 if (GET_CODE (rtl
) == SYMBOL_REF
22982 && SYMBOL_REF_DECL (rtl
))
22984 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
22986 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
22989 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22993 if (GET_CODE (rtl
) == CONST
22994 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
23000 /* Helper function for resolve_addr, handle one location
23001 expression, return false if at least one CONST_STRING or SYMBOL_REF in
23002 the location list couldn't be resolved. */
23005 resolve_addr_in_expr (dw_loc_descr_ref loc
)
23007 for (; loc
; loc
= loc
->dw_loc_next
)
23008 if (((loc
->dw_loc_opc
== DW_OP_addr
|| loc
->dtprel
)
23009 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
23010 || (loc
->dw_loc_opc
== DW_OP_implicit_value
23011 && loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
23012 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
)))
23014 else if (loc
->dw_loc_opc
== DW_OP_GNU_implicit_pointer
23015 && loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
23018 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
23021 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23022 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23023 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23028 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
23029 an address in .rodata section if the string literal is emitted there,
23030 or remove the containing location list or replace DW_AT_const_value
23031 with DW_AT_location and empty location expression, if it isn't found
23032 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
23033 to something that has been emitted in the current CU. */
23036 resolve_addr (dw_die_ref die
)
23040 dw_loc_list_ref
*curr
, *start
, loc
;
23043 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
23044 switch (AT_class (a
))
23046 case dw_val_class_loc_list
:
23047 start
= curr
= AT_loc_list_ptr (a
);
23050 /* The same list can be referenced more than once. See if we have
23051 already recorded the result from a previous pass. */
23053 *curr
= loc
->dw_loc_next
;
23054 else if (!loc
->resolved_addr
)
23056 /* As things stand, we do not expect or allow one die to
23057 reference a suffix of another die's location list chain.
23058 References must be identical or completely separate.
23059 There is therefore no need to cache the result of this
23060 pass on any list other than the first; doing so
23061 would lead to unnecessary writes. */
23064 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
23065 if (!resolve_addr_in_expr ((*curr
)->expr
))
23067 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
23068 if (next
&& (*curr
)->ll_symbol
)
23070 gcc_assert (!next
->ll_symbol
);
23071 next
->ll_symbol
= (*curr
)->ll_symbol
;
23076 curr
= &(*curr
)->dw_loc_next
;
23079 loc
->resolved_addr
= 1;
23083 loc
->dw_loc_next
= *start
;
23088 remove_AT (die
, a
->dw_attr
);
23092 case dw_val_class_loc
:
23093 if (!resolve_addr_in_expr (AT_loc (a
)))
23095 remove_AT (die
, a
->dw_attr
);
23099 case dw_val_class_addr
:
23100 if (a
->dw_attr
== DW_AT_const_value
23101 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
23103 remove_AT (die
, a
->dw_attr
);
23106 if (die
->die_tag
== DW_TAG_GNU_call_site
23107 && a
->dw_attr
== DW_AT_abstract_origin
)
23109 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
23110 dw_die_ref tdie
= lookup_decl_die (tdecl
);
23112 && DECL_EXTERNAL (tdecl
)
23113 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
23115 force_decl_die (tdecl
);
23116 tdie
= lookup_decl_die (tdecl
);
23120 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
23121 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
23122 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
23126 remove_AT (die
, a
->dw_attr
);
23135 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
23138 /* Helper routines for optimize_location_lists.
23139 This pass tries to share identical local lists in .debug_loc
23142 /* Iteratively hash operands of LOC opcode. */
23144 static inline hashval_t
23145 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
23147 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
23148 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
23150 switch (loc
->dw_loc_opc
)
23152 case DW_OP_const4u
:
23153 case DW_OP_const8u
:
23157 case DW_OP_const1u
:
23158 case DW_OP_const1s
:
23159 case DW_OP_const2u
:
23160 case DW_OP_const2s
:
23161 case DW_OP_const4s
:
23162 case DW_OP_const8s
:
23166 case DW_OP_plus_uconst
:
23202 case DW_OP_deref_size
:
23203 case DW_OP_xderef_size
:
23204 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23211 gcc_assert (val1
->val_class
== dw_val_class_loc
);
23212 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
23213 hash
= iterative_hash_object (offset
, hash
);
23216 case DW_OP_implicit_value
:
23217 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23218 switch (val2
->val_class
)
23220 case dw_val_class_const
:
23221 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23223 case dw_val_class_vec
:
23225 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23226 unsigned int len
= val2
->v
.val_vec
.length
;
23228 hash
= iterative_hash_object (elt_size
, hash
);
23229 hash
= iterative_hash_object (len
, hash
);
23230 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23231 len
* elt_size
, hash
);
23234 case dw_val_class_const_double
:
23235 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23236 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23238 case dw_val_class_addr
:
23239 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
23242 gcc_unreachable ();
23246 case DW_OP_bit_piece
:
23247 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23248 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23254 unsigned char dtprel
= 0xd1;
23255 hash
= iterative_hash_object (dtprel
, hash
);
23257 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
23259 case DW_OP_GNU_implicit_pointer
:
23260 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23262 case DW_OP_GNU_entry_value
:
23263 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
23267 /* Other codes have no operands. */
23273 /* Iteratively hash the whole DWARF location expression LOC. */
23275 static inline hashval_t
23276 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
23278 dw_loc_descr_ref l
;
23279 bool sizes_computed
= false;
23280 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23281 size_of_locs (loc
);
23283 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
23285 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
23286 hash
= iterative_hash_object (opc
, hash
);
23287 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
23289 size_of_locs (loc
);
23290 sizes_computed
= true;
23292 hash
= hash_loc_operands (l
, hash
);
23297 /* Compute hash of the whole location list LIST_HEAD. */
23300 hash_loc_list (dw_loc_list_ref list_head
)
23302 dw_loc_list_ref curr
= list_head
;
23303 hashval_t hash
= 0;
23305 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23307 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
23308 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
23310 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
23312 hash
= hash_locs (curr
->expr
, hash
);
23314 list_head
->hash
= hash
;
23317 /* Return true if X and Y opcodes have the same operands. */
23320 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23322 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
23323 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
23324 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
23325 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
23327 switch (x
->dw_loc_opc
)
23329 case DW_OP_const4u
:
23330 case DW_OP_const8u
:
23334 case DW_OP_const1u
:
23335 case DW_OP_const1s
:
23336 case DW_OP_const2u
:
23337 case DW_OP_const2s
:
23338 case DW_OP_const4s
:
23339 case DW_OP_const8s
:
23343 case DW_OP_plus_uconst
:
23379 case DW_OP_deref_size
:
23380 case DW_OP_xderef_size
:
23381 return valx1
->v
.val_int
== valy1
->v
.val_int
;
23384 gcc_assert (valx1
->val_class
== dw_val_class_loc
23385 && valy1
->val_class
== dw_val_class_loc
23386 && x
->dw_loc_addr
== y
->dw_loc_addr
);
23387 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
23388 case DW_OP_implicit_value
:
23389 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
23390 || valx2
->val_class
!= valy2
->val_class
)
23392 switch (valx2
->val_class
)
23394 case dw_val_class_const
:
23395 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23396 case dw_val_class_vec
:
23397 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23398 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23399 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23400 valx2
->v
.val_vec
.elt_size
23401 * valx2
->v
.val_vec
.length
) == 0;
23402 case dw_val_class_const_double
:
23403 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23404 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23405 case dw_val_class_addr
:
23406 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
23408 gcc_unreachable ();
23411 case DW_OP_bit_piece
:
23412 return valx1
->v
.val_int
== valy1
->v
.val_int
23413 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23416 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
23417 case DW_OP_GNU_implicit_pointer
:
23418 return valx1
->val_class
== dw_val_class_die_ref
23419 && valx1
->val_class
== valy1
->val_class
23420 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
23421 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23422 case DW_OP_GNU_entry_value
:
23423 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
23425 /* Other codes have no operands. */
23430 /* Return true if DWARF location expressions X and Y are the same. */
23433 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23435 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
23436 if (x
->dw_loc_opc
!= y
->dw_loc_opc
23437 || x
->dtprel
!= y
->dtprel
23438 || !compare_loc_operands (x
, y
))
23440 return x
== NULL
&& y
== NULL
;
23443 /* Return precomputed hash of location list X. */
23446 loc_list_hash (const void *x
)
23448 return ((const struct dw_loc_list_struct
*) x
)->hash
;
23451 /* Return 1 if location lists X and Y are the same. */
23454 loc_list_eq (const void *x
, const void *y
)
23456 const struct dw_loc_list_struct
*a
= (const struct dw_loc_list_struct
*) x
;
23457 const struct dw_loc_list_struct
*b
= (const struct dw_loc_list_struct
*) y
;
23460 if (a
->hash
!= b
->hash
)
23462 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
23463 if (strcmp (a
->begin
, b
->begin
) != 0
23464 || strcmp (a
->end
, b
->end
) != 0
23465 || (a
->section
== NULL
) != (b
->section
== NULL
)
23466 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
23467 || !compare_locs (a
->expr
, b
->expr
))
23469 return a
== NULL
&& b
== NULL
;
23472 /* Recursively optimize location lists referenced from DIE
23473 children and share them whenever possible. */
23476 optimize_location_lists_1 (dw_die_ref die
, htab_t htab
)
23483 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
23484 if (AT_class (a
) == dw_val_class_loc_list
)
23486 dw_loc_list_ref list
= AT_loc_list (a
);
23487 /* TODO: perform some optimizations here, before hashing
23488 it and storing into the hash table. */
23489 hash_loc_list (list
);
23490 slot
= htab_find_slot_with_hash (htab
, list
, list
->hash
,
23493 *slot
= (void *) list
;
23495 a
->dw_attr_val
.v
.val_loc_list
= (dw_loc_list_ref
) *slot
;
23498 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
23501 /* Optimize location lists referenced from DIE
23502 children and share them whenever possible. */
23505 optimize_location_lists (dw_die_ref die
)
23507 htab_t htab
= htab_create (500, loc_list_hash
, loc_list_eq
, NULL
);
23508 optimize_location_lists_1 (die
, htab
);
23509 htab_delete (htab
);
23512 /* Output stuff that dwarf requires at the end of every file,
23513 and generate the DWARF-2 debugging info. */
23516 dwarf2out_finish (const char *filename
)
23518 limbo_die_node
*node
, *next_node
;
23519 comdat_type_node
*ctnode
;
23520 htab_t comdat_type_table
;
23523 gen_scheduled_generic_parms_dies ();
23524 gen_remaining_tmpl_value_param_die_attribute ();
23526 /* Add the name for the main input file now. We delayed this from
23527 dwarf2out_init to avoid complications with PCH. */
23528 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
23529 if (!IS_ABSOLUTE_PATH (filename
))
23530 add_comp_dir_attribute (comp_unit_die ());
23531 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
23534 htab_traverse (file_table
, file_table_relative_p
, &p
);
23536 add_comp_dir_attribute (comp_unit_die ());
23539 for (i
= 0; i
< VEC_length (deferred_locations
, deferred_locations_list
); i
++)
23541 add_location_or_const_value_attribute (
23542 VEC_index (deferred_locations
, deferred_locations_list
, i
)->die
,
23543 VEC_index (deferred_locations
, deferred_locations_list
, i
)->variable
,
23548 /* Traverse the limbo die list, and add parent/child links. The only
23549 dies without parents that should be here are concrete instances of
23550 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23551 For concrete instances, we can get the parent die from the abstract
23553 for (node
= limbo_die_list
; node
; node
= next_node
)
23555 dw_die_ref die
= node
->die
;
23556 next_node
= node
->next
;
23558 if (die
->die_parent
== NULL
)
23560 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
23563 add_child_die (origin
->die_parent
, die
);
23564 else if (is_cu_die (die
))
23566 else if (seen_error ())
23567 /* It's OK to be confused by errors in the input. */
23568 add_child_die (comp_unit_die (), die
);
23571 /* In certain situations, the lexical block containing a
23572 nested function can be optimized away, which results
23573 in the nested function die being orphaned. Likewise
23574 with the return type of that nested function. Force
23575 this to be a child of the containing function.
23577 It may happen that even the containing function got fully
23578 inlined and optimized out. In that case we are lost and
23579 assign the empty child. This should not be big issue as
23580 the function is likely unreachable too. */
23581 tree context
= NULL_TREE
;
23583 gcc_assert (node
->created_for
);
23585 if (DECL_P (node
->created_for
))
23586 context
= DECL_CONTEXT (node
->created_for
);
23587 else if (TYPE_P (node
->created_for
))
23588 context
= TYPE_CONTEXT (node
->created_for
);
23590 gcc_assert (context
23591 && (TREE_CODE (context
) == FUNCTION_DECL
23592 || TREE_CODE (context
) == NAMESPACE_DECL
));
23594 origin
= lookup_decl_die (context
);
23596 add_child_die (origin
, die
);
23598 add_child_die (comp_unit_die (), die
);
23603 limbo_die_list
= NULL
;
23605 resolve_addr (comp_unit_die ());
23607 for (node
= deferred_asm_name
; node
; node
= node
->next
)
23609 tree decl
= node
->created_for
;
23610 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
23612 add_linkage_attr (node
->die
, decl
);
23613 move_linkage_attr (node
->die
);
23617 deferred_asm_name
= NULL
;
23619 /* Walk through the list of incomplete types again, trying once more to
23620 emit full debugging info for them. */
23621 retry_incomplete_types ();
23623 if (flag_eliminate_unused_debug_types
)
23624 prune_unused_types ();
23626 /* Generate separate CUs for each of the include files we've seen.
23627 They will go into limbo_die_list. */
23628 if (flag_eliminate_dwarf2_dups
&& ! use_debug_types
)
23629 break_out_includes (comp_unit_die ());
23631 /* Generate separate COMDAT sections for type DIEs. */
23632 if (use_debug_types
)
23634 break_out_comdat_types (comp_unit_die ());
23636 /* Each new type_unit DIE was added to the limbo die list when created.
23637 Since these have all been added to comdat_type_list, clear the
23639 limbo_die_list
= NULL
;
23641 /* For each new comdat type unit, copy declarations for incomplete
23642 types to make the new unit self-contained (i.e., no direct
23643 references to the main compile unit). */
23644 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23645 copy_decls_for_unworthy_types (ctnode
->root_die
);
23646 copy_decls_for_unworthy_types (comp_unit_die ());
23648 /* In the process of copying declarations from one unit to another,
23649 we may have left some declarations behind that are no longer
23650 referenced. Prune them. */
23651 prune_unused_types ();
23654 /* Traverse the DIE's and add add sibling attributes to those DIE's
23655 that have children. */
23656 add_sibling_attributes (comp_unit_die ());
23657 for (node
= limbo_die_list
; node
; node
= node
->next
)
23658 add_sibling_attributes (node
->die
);
23659 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23660 add_sibling_attributes (ctnode
->root_die
);
23662 /* Output a terminator label for the .text section. */
23663 switch_to_section (text_section
);
23664 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
23665 if (cold_text_section
)
23667 switch_to_section (cold_text_section
);
23668 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
23671 /* We can only use the low/high_pc attributes if all of the code was
23673 if (!have_multiple_function_sections
23674 || (dwarf_version
< 3 && dwarf_strict
))
23676 /* Don't add if the CU has no associated code. */
23677 if (text_section_used
)
23679 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc
, text_section_label
);
23680 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc
, text_end_label
);
23685 unsigned fde_idx
= 0;
23686 bool range_list_added
= false;
23688 if (text_section_used
)
23689 add_ranges_by_labels (comp_unit_die (), text_section_label
,
23690 text_end_label
, &range_list_added
);
23691 if (cold_text_section_used
)
23692 add_ranges_by_labels (comp_unit_die (), cold_text_section_label
,
23693 cold_end_label
, &range_list_added
);
23695 for (fde_idx
= 0; fde_idx
< fde_table_in_use
; fde_idx
++)
23697 dw_fde_ref fde
= &fde_table
[fde_idx
];
23699 if (!fde
->in_std_section
)
23700 add_ranges_by_labels (comp_unit_die (), fde
->dw_fde_begin
,
23701 fde
->dw_fde_end
, &range_list_added
);
23702 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
23703 add_ranges_by_labels (comp_unit_die (), fde
->dw_fde_second_begin
,
23704 fde
->dw_fde_second_end
, &range_list_added
);
23707 if (range_list_added
)
23709 /* We need to give .debug_loc and .debug_ranges an appropriate
23710 "base address". Use zero so that these addresses become
23711 absolute. Historically, we've emitted the unexpected
23712 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23713 Emit both to give time for other tools to adapt. */
23714 add_AT_addr (comp_unit_die (), DW_AT_low_pc
, const0_rtx
);
23715 if (! dwarf_strict
&& dwarf_version
< 4)
23716 add_AT_addr (comp_unit_die (), DW_AT_entry_pc
, const0_rtx
);
23722 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23723 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list
,
23724 debug_line_section_label
);
23726 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
23727 add_AT_macptr (comp_unit_die (), DW_AT_macro_info
, macinfo_section_label
);
23729 if (have_location_lists
)
23730 optimize_location_lists (comp_unit_die ());
23732 /* Output all of the compilation units. We put the main one last so that
23733 the offsets are available to output_pubnames. */
23734 for (node
= limbo_die_list
; node
; node
= node
->next
)
23735 output_comp_unit (node
->die
, 0);
23737 comdat_type_table
= htab_create (100, htab_ct_hash
, htab_ct_eq
, NULL
);
23738 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23740 void **slot
= htab_find_slot (comdat_type_table
, ctnode
, INSERT
);
23742 /* Don't output duplicate types. */
23743 if (*slot
!= HTAB_EMPTY_ENTRY
)
23746 /* Add a pointer to the line table for the main compilation unit
23747 so that the debugger can make sense of DW_AT_decl_file
23749 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23750 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
23751 debug_line_section_label
);
23753 output_comdat_type_unit (ctnode
);
23756 htab_delete (comdat_type_table
);
23758 /* Output the main compilation unit if non-empty or if .debug_macinfo
23759 will be emitted. */
23760 output_comp_unit (comp_unit_die (), debug_info_level
>= DINFO_LEVEL_VERBOSE
);
23762 /* Output the abbreviation table. */
23763 switch_to_section (debug_abbrev_section
);
23764 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
23765 output_abbrev_section ();
23767 /* Output location list section if necessary. */
23768 if (have_location_lists
)
23770 /* Output the location lists info. */
23771 switch_to_section (debug_loc_section
);
23772 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
23773 DEBUG_LOC_SECTION_LABEL
, 0);
23774 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
23775 output_location_lists (comp_unit_die ());
23778 /* Output public names table if necessary. */
23779 if (!VEC_empty (pubname_entry
, pubname_table
))
23781 gcc_assert (info_section_emitted
);
23782 switch_to_section (debug_pubnames_section
);
23783 output_pubnames (pubname_table
);
23786 /* Output public types table if necessary. */
23787 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
23788 It shouldn't hurt to emit it always, since pure DWARF2 consumers
23789 simply won't look for the section. */
23790 if (!VEC_empty (pubname_entry
, pubtype_table
))
23792 bool empty
= false;
23794 if (flag_eliminate_unused_debug_types
)
23796 /* The pubtypes table might be emptied by pruning unused items. */
23800 FOR_EACH_VEC_ELT (pubname_entry
, pubtype_table
, i
, p
)
23801 if (p
->die
->die_offset
!= 0)
23809 gcc_assert (info_section_emitted
);
23810 switch_to_section (debug_pubtypes_section
);
23811 output_pubnames (pubtype_table
);
23815 /* Output the address range information. We only put functions in the
23816 arange table, so don't write it out if we don't have any. */
23817 if (info_section_emitted
)
23819 unsigned long aranges_length
= size_of_aranges ();
23821 /* Empty .debug_aranges would contain just header and
23822 terminating 0,0. */
23824 != (unsigned long) (DWARF_ARANGES_HEADER_SIZE
23825 + 2 * DWARF2_ADDR_SIZE
))
23827 switch_to_section (debug_aranges_section
);
23828 output_aranges (aranges_length
);
23832 /* Output ranges section if necessary. */
23833 if (ranges_table_in_use
)
23835 switch_to_section (debug_ranges_section
);
23836 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
23840 /* Output the source line correspondence table. We must do this
23841 even if there is no line information. Otherwise, on an empty
23842 translation unit, we will generate a present, but empty,
23843 .debug_info section. IRIX 6.5 `nm' will then complain when
23844 examining the file. This is done late so that any filenames
23845 used by the debug_info section are marked as 'used'. */
23846 switch_to_section (debug_line_section
);
23847 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
23848 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
23849 output_line_info ();
23851 /* Have to end the macro section. */
23852 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
23854 switch_to_section (debug_macinfo_section
);
23855 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
23856 if (!VEC_empty (macinfo_entry
, macinfo_table
))
23858 dw2_asm_output_data (1, 0, "End compilation unit");
23861 /* If we emitted any DW_FORM_strp form attribute, output the string
23863 if (debug_str_hash
)
23864 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
23867 #include "gt-dwarf2out.h"