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 dw_cfi_ref dw_cfi_next
;
271 enum dwarf_call_frame_info dw_cfi_opc
;
272 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
274 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
279 /* This is how we define the location of the CFA. We use to handle it
280 as REG + OFFSET all the time, but now it can be more complex.
281 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
282 Instead of passing around REG and OFFSET, we pass a copy
283 of this structure. */
284 typedef struct cfa_loc
{
285 HOST_WIDE_INT offset
;
286 HOST_WIDE_INT base_offset
;
288 BOOL_BITFIELD indirect
: 1; /* 1 if CFA is accessed via a dereference. */
289 BOOL_BITFIELD in_use
: 1; /* 1 if a saved cfa is stored here. */
292 /* All call frame descriptions (FDE's) in the GCC generated DWARF
293 refer to a single Common Information Entry (CIE), defined at
294 the beginning of the .debug_frame section. This use of a single
295 CIE obviates the need to keep track of multiple CIE's
296 in the DWARF generation routines below. */
298 typedef struct GTY(()) dw_fde_struct
{
300 const char *dw_fde_begin
;
301 const char *dw_fde_current_label
;
302 const char *dw_fde_end
;
303 const char *dw_fde_vms_end_prologue
;
304 const char *dw_fde_vms_begin_epilogue
;
305 const char *dw_fde_hot_section_label
;
306 const char *dw_fde_hot_section_end_label
;
307 const char *dw_fde_unlikely_section_label
;
308 const char *dw_fde_unlikely_section_end_label
;
309 dw_cfi_ref dw_fde_cfi
;
310 dw_cfi_ref dw_fde_switch_cfi
; /* Last CFI before switching sections. */
311 HOST_WIDE_INT stack_realignment
;
312 unsigned funcdef_number
;
313 /* Dynamic realign argument pointer register. */
314 unsigned int drap_reg
;
315 /* Virtual dynamic realign argument pointer register. */
316 unsigned int vdrap_reg
;
317 /* These 3 flags are copied from rtl_data in function.h. */
318 unsigned all_throwers_are_sibcalls
: 1;
319 unsigned uses_eh_lsda
: 1;
320 unsigned nothrow
: 1;
321 /* Whether we did stack realign in this call frame. */
322 unsigned stack_realign
: 1;
323 /* Whether dynamic realign argument pointer register has been saved. */
324 unsigned drap_reg_saved
: 1;
325 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
326 unsigned in_std_section
: 1;
327 /* True iff dw_fde_unlikely_section_label is in text_section or
328 cold_text_section. */
329 unsigned cold_in_std_section
: 1;
330 /* True iff switched sections. */
331 unsigned dw_fde_switched_sections
: 1;
332 /* True iff switching from cold to hot section. */
333 unsigned dw_fde_switched_cold_to_hot
: 1;
337 /* Maximum size (in bytes) of an artificially generated label. */
338 #define MAX_ARTIFICIAL_LABEL_BYTES 30
340 /* The size of addresses as they appear in the Dwarf 2 data.
341 Some architectures use word addresses to refer to code locations,
342 but Dwarf 2 info always uses byte addresses. On such machines,
343 Dwarf 2 addresses need to be larger than the architecture's
345 #ifndef DWARF2_ADDR_SIZE
346 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
349 /* The size in bytes of a DWARF field indicating an offset or length
350 relative to a debug info section, specified to be 4 bytes in the
351 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
354 #ifndef DWARF_OFFSET_SIZE
355 #define DWARF_OFFSET_SIZE 4
358 /* The size in bytes of a DWARF 4 type signature. */
360 #ifndef DWARF_TYPE_SIGNATURE_SIZE
361 #define DWARF_TYPE_SIGNATURE_SIZE 8
364 /* According to the (draft) DWARF 3 specification, the initial length
365 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
366 bytes are 0xffffffff, followed by the length stored in the next 8
369 However, the SGI/MIPS ABI uses an initial length which is equal to
370 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
372 #ifndef DWARF_INITIAL_LENGTH_SIZE
373 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
376 /* Round SIZE up to the nearest BOUNDARY. */
377 #define DWARF_ROUND(SIZE,BOUNDARY) \
378 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
380 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
381 #ifndef DWARF_CIE_DATA_ALIGNMENT
382 #ifdef STACK_GROWS_DOWNWARD
383 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
385 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
389 /* CIE identifier. */
390 #if HOST_BITS_PER_WIDE_INT >= 64
391 #define DWARF_CIE_ID \
392 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
394 #define DWARF_CIE_ID DW_CIE_ID
397 /* A pointer to the base of a table that contains frame description
398 information for each routine. */
399 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table
;
401 /* Number of elements currently allocated for fde_table. */
402 static GTY(()) unsigned fde_table_allocated
;
404 /* Number of elements in fde_table currently in use. */
405 static GTY(()) unsigned fde_table_in_use
;
407 /* Size (in elements) of increments by which we may expand the
409 #define FDE_TABLE_INCREMENT 256
411 /* Get the current fde_table entry we should use. */
413 static inline dw_fde_ref
416 return fde_table_in_use
? &fde_table
[fde_table_in_use
- 1] : NULL
;
419 /* A list of call frame insns for the CIE. */
420 static GTY(()) dw_cfi_ref cie_cfi_head
;
422 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
423 attribute that accelerates the lookup of the FDE associated
424 with the subprogram. This variable holds the table index of the FDE
425 associated with the current function (body) definition. */
426 static unsigned current_funcdef_fde
;
428 struct GTY(()) indirect_string_node
{
430 unsigned int refcount
;
431 enum dwarf_form form
;
435 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
437 /* True if the compilation unit has location entries that reference
439 static GTY(()) bool debug_str_hash_forced
= false;
441 static GTY(()) int dw2_string_counter
;
442 static GTY(()) unsigned long dwarf2out_cfi_label_num
;
444 /* True if the compilation unit places functions in more than one section. */
445 static GTY(()) bool have_multiple_function_sections
= false;
447 /* Whether the default text and cold text sections have been used at all. */
449 static GTY(()) bool text_section_used
= false;
450 static GTY(()) bool cold_text_section_used
= false;
452 /* The default cold text section. */
453 static GTY(()) section
*cold_text_section
;
455 /* Forward declarations for functions defined in this file. */
457 static char *stripattributes (const char *);
458 static const char *dwarf_cfi_name (unsigned);
459 static dw_cfi_ref
new_cfi (void);
460 static void add_cfi (dw_cfi_ref
*, dw_cfi_ref
);
461 static void add_fde_cfi (const char *, dw_cfi_ref
);
462 static void lookup_cfa_1 (dw_cfi_ref
, dw_cfa_location
*, dw_cfa_location
*);
463 static void lookup_cfa (dw_cfa_location
*);
464 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT
);
465 static void initial_return_save (rtx
);
466 static HOST_WIDE_INT
stack_adjust_offset (const_rtx
, HOST_WIDE_INT
,
468 static void output_cfi (dw_cfi_ref
, dw_fde_ref
, int);
469 static void output_cfi_directive (dw_cfi_ref
);
470 static void output_call_frame_info (int);
471 static void dwarf2out_note_section_used (void);
472 static bool clobbers_queued_reg_save (const_rtx
);
473 static void dwarf2out_frame_debug_expr (rtx
, const char *);
475 /* Support for complex CFA locations. */
476 static void output_cfa_loc (dw_cfi_ref
, int);
477 static void output_cfa_loc_raw (dw_cfi_ref
);
478 static void get_cfa_from_loc_descr (dw_cfa_location
*,
479 struct dw_loc_descr_struct
*);
480 static struct dw_loc_descr_struct
*build_cfa_loc
481 (dw_cfa_location
*, HOST_WIDE_INT
);
482 static struct dw_loc_descr_struct
*build_cfa_aligned_loc
483 (HOST_WIDE_INT
, HOST_WIDE_INT
);
484 static void def_cfa_1 (const char *, dw_cfa_location
*);
485 static struct dw_loc_descr_struct
*mem_loc_descriptor
486 (rtx
, enum machine_mode mode
, enum var_init_status
);
488 /* How to start an assembler comment. */
489 #ifndef ASM_COMMENT_START
490 #define ASM_COMMENT_START ";#"
493 /* Data and reference forms for relocatable data. */
494 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
495 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
497 #ifndef DEBUG_FRAME_SECTION
498 #define DEBUG_FRAME_SECTION ".debug_frame"
501 #ifndef FUNC_BEGIN_LABEL
502 #define FUNC_BEGIN_LABEL "LFB"
505 #ifndef FUNC_END_LABEL
506 #define FUNC_END_LABEL "LFE"
509 #ifndef PROLOGUE_END_LABEL
510 #define PROLOGUE_END_LABEL "LPE"
513 #ifndef EPILOGUE_BEGIN_LABEL
514 #define EPILOGUE_BEGIN_LABEL "LEB"
517 #ifndef FRAME_BEGIN_LABEL
518 #define FRAME_BEGIN_LABEL "Lframe"
520 #define CIE_AFTER_SIZE_LABEL "LSCIE"
521 #define CIE_END_LABEL "LECIE"
522 #define FDE_LABEL "LSFDE"
523 #define FDE_AFTER_SIZE_LABEL "LASFDE"
524 #define FDE_END_LABEL "LEFDE"
525 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
526 #define LINE_NUMBER_END_LABEL "LELT"
527 #define LN_PROLOG_AS_LABEL "LASLTP"
528 #define LN_PROLOG_END_LABEL "LELTP"
529 #define DIE_LABEL_PREFIX "DW"
531 /* The DWARF 2 CFA column which tracks the return address. Normally this
532 is the column for PC, or the first column after all of the hard
534 #ifndef DWARF_FRAME_RETURN_COLUMN
536 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
538 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
542 /* The mapping from gcc register number to DWARF 2 CFA column number. By
543 default, we just provide columns for all registers. */
544 #ifndef DWARF_FRAME_REGNUM
545 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
548 /* Match the base name of a file to the base name of a compilation unit. */
551 matches_main_base (const char *path
)
553 /* Cache the last query. */
554 static const char *last_path
= NULL
;
555 static int last_match
= 0;
556 if (path
!= last_path
)
559 int length
= base_of_path (path
, &base
);
561 last_match
= (length
== main_input_baselength
562 && memcmp (base
, main_input_basename
, length
) == 0);
567 #ifdef DEBUG_DEBUG_STRUCT
570 dump_struct_debug (tree type
, enum debug_info_usage usage
,
571 enum debug_struct_file criterion
, int generic
,
572 int matches
, int result
)
574 /* Find the type name. */
575 tree type_decl
= TYPE_STUB_DECL (type
);
577 const char *name
= 0;
578 if (TREE_CODE (t
) == TYPE_DECL
)
581 name
= IDENTIFIER_POINTER (t
);
583 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
585 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
586 matches
? "bas" : "hdr",
587 generic
? "gen" : "ord",
588 usage
== DINFO_USAGE_DFN
? ";" :
589 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
591 (void*) type_decl
, name
);
594 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
595 dump_struct_debug (type, usage, criterion, generic, matches, result)
599 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
605 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
607 enum debug_struct_file criterion
;
609 bool generic
= lang_hooks
.types
.generic_p (type
);
612 criterion
= debug_struct_generic
[usage
];
614 criterion
= debug_struct_ordinary
[usage
];
616 if (criterion
== DINFO_STRUCT_FILE_NONE
)
617 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
618 if (criterion
== DINFO_STRUCT_FILE_ANY
)
619 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
621 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
623 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
624 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
626 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
627 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
628 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
631 /* Hook used by __throw. */
634 expand_builtin_dwarf_sp_column (void)
636 unsigned int dwarf_regnum
= DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
);
637 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum
, 1));
640 /* Return a pointer to a copy of the section string name S with all
641 attributes stripped off, and an asterisk prepended (for assemble_name). */
644 stripattributes (const char *s
)
646 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
651 while (*s
&& *s
!= ',')
658 /* MEM is a memory reference for the register size table, each element of
659 which has mode MODE. Initialize column C as a return address column. */
662 init_return_column_size (enum machine_mode mode
, rtx mem
, unsigned int c
)
664 HOST_WIDE_INT offset
= c
* GET_MODE_SIZE (mode
);
665 HOST_WIDE_INT size
= GET_MODE_SIZE (Pmode
);
666 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
669 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
671 static inline HOST_WIDE_INT
672 div_data_align (HOST_WIDE_INT off
)
674 HOST_WIDE_INT r
= off
/ DWARF_CIE_DATA_ALIGNMENT
;
675 gcc_assert (r
* DWARF_CIE_DATA_ALIGNMENT
== off
);
679 /* Return true if we need a signed version of a given opcode
680 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
683 need_data_align_sf_opcode (HOST_WIDE_INT off
)
685 return DWARF_CIE_DATA_ALIGNMENT
< 0 ? off
> 0 : off
< 0;
688 /* Generate code to initialize the register size table. */
691 expand_builtin_init_dwarf_reg_sizes (tree address
)
694 enum machine_mode mode
= TYPE_MODE (char_type_node
);
695 rtx addr
= expand_normal (address
);
696 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
697 bool wrote_return_column
= false;
699 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
701 int rnum
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i
), 1);
703 if (rnum
< DWARF_FRAME_REGISTERS
)
705 HOST_WIDE_INT offset
= rnum
* GET_MODE_SIZE (mode
);
706 enum machine_mode save_mode
= reg_raw_mode
[i
];
709 if (HARD_REGNO_CALL_PART_CLOBBERED (i
, save_mode
))
710 save_mode
= choose_hard_reg_mode (i
, 1, true);
711 if (DWARF_FRAME_REGNUM (i
) == DWARF_FRAME_RETURN_COLUMN
)
713 if (save_mode
== VOIDmode
)
715 wrote_return_column
= true;
717 size
= GET_MODE_SIZE (save_mode
);
721 emit_move_insn (adjust_address (mem
, mode
, offset
),
722 gen_int_mode (size
, mode
));
726 if (!wrote_return_column
)
727 init_return_column_size (mode
, mem
, DWARF_FRAME_RETURN_COLUMN
);
729 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
730 init_return_column_size (mode
, mem
, DWARF_ALT_FRAME_RETURN_COLUMN
);
733 targetm
.init_dwarf_reg_sizes_extra (address
);
736 /* Convert a DWARF call frame info. operation to its string name */
739 dwarf_cfi_name (unsigned int cfi_opc
)
743 case DW_CFA_advance_loc
:
744 return "DW_CFA_advance_loc";
746 return "DW_CFA_offset";
748 return "DW_CFA_restore";
752 return "DW_CFA_set_loc";
753 case DW_CFA_advance_loc1
:
754 return "DW_CFA_advance_loc1";
755 case DW_CFA_advance_loc2
:
756 return "DW_CFA_advance_loc2";
757 case DW_CFA_advance_loc4
:
758 return "DW_CFA_advance_loc4";
759 case DW_CFA_offset_extended
:
760 return "DW_CFA_offset_extended";
761 case DW_CFA_restore_extended
:
762 return "DW_CFA_restore_extended";
763 case DW_CFA_undefined
:
764 return "DW_CFA_undefined";
765 case DW_CFA_same_value
:
766 return "DW_CFA_same_value";
767 case DW_CFA_register
:
768 return "DW_CFA_register";
769 case DW_CFA_remember_state
:
770 return "DW_CFA_remember_state";
771 case DW_CFA_restore_state
:
772 return "DW_CFA_restore_state";
774 return "DW_CFA_def_cfa";
775 case DW_CFA_def_cfa_register
:
776 return "DW_CFA_def_cfa_register";
777 case DW_CFA_def_cfa_offset
:
778 return "DW_CFA_def_cfa_offset";
781 case DW_CFA_def_cfa_expression
:
782 return "DW_CFA_def_cfa_expression";
783 case DW_CFA_expression
:
784 return "DW_CFA_expression";
785 case DW_CFA_offset_extended_sf
:
786 return "DW_CFA_offset_extended_sf";
787 case DW_CFA_def_cfa_sf
:
788 return "DW_CFA_def_cfa_sf";
789 case DW_CFA_def_cfa_offset_sf
:
790 return "DW_CFA_def_cfa_offset_sf";
792 /* SGI/MIPS specific */
793 case DW_CFA_MIPS_advance_loc8
:
794 return "DW_CFA_MIPS_advance_loc8";
797 case DW_CFA_GNU_window_save
:
798 return "DW_CFA_GNU_window_save";
799 case DW_CFA_GNU_args_size
:
800 return "DW_CFA_GNU_args_size";
801 case DW_CFA_GNU_negative_offset_extended
:
802 return "DW_CFA_GNU_negative_offset_extended";
805 return "DW_CFA_<unknown>";
809 /* Return a pointer to a newly allocated Call Frame Instruction. */
811 static inline dw_cfi_ref
814 dw_cfi_ref cfi
= ggc_alloc_dw_cfi_node ();
816 cfi
->dw_cfi_next
= NULL
;
817 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
818 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
823 /* Add a Call Frame Instruction to list of instructions. */
826 add_cfi (dw_cfi_ref
*list_head
, dw_cfi_ref cfi
)
829 dw_fde_ref fde
= current_fde ();
831 /* When DRAP is used, CFA is defined with an expression. Redefine
832 CFA may lead to a different CFA value. */
833 /* ??? Of course, this heuristic fails when we're annotating epilogues,
834 because of course we'll always want to redefine the CFA back to the
835 stack pointer on the way out. Where should we move this check? */
836 if (0 && fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
837 switch (cfi
->dw_cfi_opc
)
839 case DW_CFA_def_cfa_register
:
840 case DW_CFA_def_cfa_offset
:
841 case DW_CFA_def_cfa_offset_sf
:
843 case DW_CFA_def_cfa_sf
:
850 /* Find the end of the chain. */
851 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
857 /* Generate a new label for the CFI info to refer to. FORCE is true
858 if a label needs to be output even when using .cfi_* directives. */
861 dwarf2out_cfi_label (bool force
)
863 static char label
[20];
865 if (!force
&& dwarf2out_do_cfi_asm ())
867 /* In this case, we will be emitting the asm directive instead of
868 the label, so just return a placeholder to keep the rest of the
870 strcpy (label
, "<do not output>");
874 int num
= dwarf2out_cfi_label_num
++;
875 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", num
);
876 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LCFI", num
);
882 /* True if remember_state should be emitted before following CFI directive. */
883 static bool emit_cfa_remember
;
885 /* True if any CFI directives were emitted at the current insn. */
886 static bool any_cfis_emitted
;
888 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
889 or to the CIE if LABEL is NULL. */
892 add_fde_cfi (const char *label
, dw_cfi_ref cfi
)
894 dw_cfi_ref
*list_head
;
896 if (emit_cfa_remember
)
898 dw_cfi_ref cfi_remember
;
900 /* Emit the state save. */
901 emit_cfa_remember
= false;
902 cfi_remember
= new_cfi ();
903 cfi_remember
->dw_cfi_opc
= DW_CFA_remember_state
;
904 add_fde_cfi (label
, cfi_remember
);
907 list_head
= &cie_cfi_head
;
909 if (dwarf2out_do_cfi_asm ())
913 dw_fde_ref fde
= current_fde ();
915 gcc_assert (fde
!= NULL
);
917 /* We still have to add the cfi to the list so that lookup_cfa
918 works later on. When -g2 and above we even need to force
919 emitting of CFI labels and add to list a DW_CFA_set_loc for
920 convert_cfa_to_fb_loc_list purposes. If we're generating
921 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
922 convert_cfa_to_fb_loc_list. */
923 if (dwarf_version
== 2
924 && debug_info_level
> DINFO_LEVEL_TERSE
925 && (write_symbols
== DWARF2_DEBUG
926 || write_symbols
== VMS_AND_DWARF2_DEBUG
))
928 switch (cfi
->dw_cfi_opc
)
930 case DW_CFA_def_cfa_offset
:
931 case DW_CFA_def_cfa_offset_sf
:
932 case DW_CFA_def_cfa_register
:
934 case DW_CFA_def_cfa_sf
:
935 case DW_CFA_def_cfa_expression
:
936 case DW_CFA_restore_state
:
937 if (*label
== 0 || strcmp (label
, "<do not output>") == 0)
938 label
= dwarf2out_cfi_label (true);
940 if (fde
->dw_fde_current_label
== NULL
941 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
945 label
= xstrdup (label
);
947 /* Set the location counter to the new label. */
949 /* It doesn't metter whether DW_CFA_set_loc
950 or DW_CFA_advance_loc4 is added here, those aren't
951 emitted into assembly, only looked up by
952 convert_cfa_to_fb_loc_list. */
953 xcfi
->dw_cfi_opc
= DW_CFA_set_loc
;
954 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
955 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
956 fde
->dw_fde_current_label
= label
;
964 output_cfi_directive (cfi
);
966 list_head
= &fde
->dw_fde_cfi
;
967 any_cfis_emitted
= true;
969 /* ??? If this is a CFI for the CIE, we don't emit. This
970 assumes that the standard CIE contents that the assembler
971 uses matches the standard CIE contents that the compiler
972 uses. This is probably a bad assumption. I'm not quite
973 sure how to address this for now. */
977 dw_fde_ref fde
= current_fde ();
979 gcc_assert (fde
!= NULL
);
982 label
= dwarf2out_cfi_label (false);
984 if (fde
->dw_fde_current_label
== NULL
985 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
989 label
= xstrdup (label
);
991 /* Set the location counter to the new label. */
993 /* If we have a current label, advance from there, otherwise
994 set the location directly using set_loc. */
995 xcfi
->dw_cfi_opc
= fde
->dw_fde_current_label
996 ? DW_CFA_advance_loc4
998 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
999 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
1001 fde
->dw_fde_current_label
= label
;
1004 list_head
= &fde
->dw_fde_cfi
;
1005 any_cfis_emitted
= true;
1008 add_cfi (list_head
, cfi
);
1011 /* Subroutine of lookup_cfa. */
1014 lookup_cfa_1 (dw_cfi_ref cfi
, dw_cfa_location
*loc
, dw_cfa_location
*remember
)
1016 switch (cfi
->dw_cfi_opc
)
1018 case DW_CFA_def_cfa_offset
:
1019 case DW_CFA_def_cfa_offset_sf
:
1020 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
1022 case DW_CFA_def_cfa_register
:
1023 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
1025 case DW_CFA_def_cfa
:
1026 case DW_CFA_def_cfa_sf
:
1027 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
1028 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
1030 case DW_CFA_def_cfa_expression
:
1031 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
1034 case DW_CFA_remember_state
:
1035 gcc_assert (!remember
->in_use
);
1037 remember
->in_use
= 1;
1039 case DW_CFA_restore_state
:
1040 gcc_assert (remember
->in_use
);
1042 remember
->in_use
= 0;
1050 /* Find the previous value for the CFA. */
1053 lookup_cfa (dw_cfa_location
*loc
)
1057 dw_cfa_location remember
;
1059 memset (loc
, 0, sizeof (*loc
));
1060 loc
->reg
= INVALID_REGNUM
;
1063 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
1064 lookup_cfa_1 (cfi
, loc
, &remember
);
1066 fde
= current_fde ();
1068 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
1069 lookup_cfa_1 (cfi
, loc
, &remember
);
1072 /* The current rule for calculating the DWARF2 canonical frame address. */
1073 static dw_cfa_location cfa
;
1075 /* The register used for saving registers to the stack, and its offset
1077 static dw_cfa_location cfa_store
;
1079 /* The current save location around an epilogue. */
1080 static dw_cfa_location cfa_remember
;
1082 /* The running total of the size of arguments pushed onto the stack. */
1083 static HOST_WIDE_INT args_size
;
1085 /* The last args_size we actually output. */
1086 static HOST_WIDE_INT old_args_size
;
1088 /* Entry point to update the canonical frame address (CFA).
1089 LABEL is passed to add_fde_cfi. The value of CFA is now to be
1090 calculated from REG+OFFSET. */
1093 dwarf2out_def_cfa (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
1095 dw_cfa_location loc
;
1097 loc
.base_offset
= 0;
1099 loc
.offset
= offset
;
1100 def_cfa_1 (label
, &loc
);
1103 /* Determine if two dw_cfa_location structures define the same data. */
1106 cfa_equal_p (const dw_cfa_location
*loc1
, const dw_cfa_location
*loc2
)
1108 return (loc1
->reg
== loc2
->reg
1109 && loc1
->offset
== loc2
->offset
1110 && loc1
->indirect
== loc2
->indirect
1111 && (loc1
->indirect
== 0
1112 || loc1
->base_offset
== loc2
->base_offset
));
1115 /* This routine does the actual work. The CFA is now calculated from
1116 the dw_cfa_location structure. */
1119 def_cfa_1 (const char *label
, dw_cfa_location
*loc_p
)
1122 dw_cfa_location old_cfa
, loc
;
1127 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
1128 cfa_store
.offset
= loc
.offset
;
1130 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
1131 lookup_cfa (&old_cfa
);
1133 /* If nothing changed, no need to issue any call frame instructions. */
1134 if (cfa_equal_p (&loc
, &old_cfa
))
1139 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
&& !old_cfa
.indirect
)
1141 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1142 the CFA register did not change but the offset did. The data
1143 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1144 in the assembler via the .cfi_def_cfa_offset directive. */
1146 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset_sf
;
1148 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
1149 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
1152 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1153 else if (loc
.offset
== old_cfa
.offset
1154 && old_cfa
.reg
!= INVALID_REGNUM
1156 && !old_cfa
.indirect
)
1158 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1159 indicating the CFA register has changed to <register> but the
1160 offset has not changed. */
1161 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
1162 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
1166 else if (loc
.indirect
== 0)
1168 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1169 indicating the CFA register has changed to <register> with
1170 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1171 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1174 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_sf
;
1176 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
1177 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
1178 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
1182 /* Construct a DW_CFA_def_cfa_expression instruction to
1183 calculate the CFA using a full location expression since no
1184 register-offset pair is available. */
1185 struct dw_loc_descr_struct
*loc_list
;
1187 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
1188 loc_list
= build_cfa_loc (&loc
, 0);
1189 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
1192 add_fde_cfi (label
, cfi
);
1195 /* Add the CFI for saving a register. REG is the CFA column number.
1196 LABEL is passed to add_fde_cfi.
1197 If SREG is -1, the register is saved at OFFSET from the CFA;
1198 otherwise it is saved in SREG. */
1201 reg_save (const char *label
, unsigned int reg
, unsigned int sreg
, HOST_WIDE_INT offset
)
1203 dw_cfi_ref cfi
= new_cfi ();
1204 dw_fde_ref fde
= current_fde ();
1206 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
1208 /* When stack is aligned, store REG using DW_CFA_expression with
1211 && fde
->stack_realign
1212 && sreg
== INVALID_REGNUM
)
1214 cfi
->dw_cfi_opc
= DW_CFA_expression
;
1215 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
1216 cfi
->dw_cfi_oprnd2
.dw_cfi_loc
1217 = build_cfa_aligned_loc (offset
, fde
->stack_realignment
);
1219 else if (sreg
== INVALID_REGNUM
)
1221 if (need_data_align_sf_opcode (offset
))
1222 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
1223 else if (reg
& ~0x3f)
1224 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
1226 cfi
->dw_cfi_opc
= DW_CFA_offset
;
1227 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
1229 else if (sreg
== reg
)
1230 cfi
->dw_cfi_opc
= DW_CFA_same_value
;
1233 cfi
->dw_cfi_opc
= DW_CFA_register
;
1234 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
1237 add_fde_cfi (label
, cfi
);
1240 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1241 This CFI tells the unwinder that it needs to restore the window registers
1242 from the previous frame's window save area.
1244 ??? Perhaps we should note in the CIE where windows are saved (instead of
1245 assuming 0(cfa)) and what registers are in the window. */
1248 dwarf2out_window_save (const char *label
)
1250 dw_cfi_ref cfi
= new_cfi ();
1252 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
1253 add_fde_cfi (label
, cfi
);
1256 /* Entry point for saving a register to the stack. REG is the GCC register
1257 number. LABEL and OFFSET are passed to reg_save. */
1260 dwarf2out_reg_save (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
1262 reg_save (label
, DWARF_FRAME_REGNUM (reg
), INVALID_REGNUM
, offset
);
1265 /* Entry point for saving the return address in the stack.
1266 LABEL and OFFSET are passed to reg_save. */
1269 dwarf2out_return_save (const char *label
, HOST_WIDE_INT offset
)
1271 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, INVALID_REGNUM
, offset
);
1274 /* Entry point for saving the return address in a register.
1275 LABEL and SREG are passed to reg_save. */
1278 dwarf2out_return_reg (const char *label
, unsigned int sreg
)
1280 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, DWARF_FRAME_REGNUM (sreg
), 0);
1283 /* Record the initial position of the return address. RTL is
1284 INCOMING_RETURN_ADDR_RTX. */
1287 initial_return_save (rtx rtl
)
1289 unsigned int reg
= INVALID_REGNUM
;
1290 HOST_WIDE_INT offset
= 0;
1292 switch (GET_CODE (rtl
))
1295 /* RA is in a register. */
1296 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
1300 /* RA is on the stack. */
1301 rtl
= XEXP (rtl
, 0);
1302 switch (GET_CODE (rtl
))
1305 gcc_assert (REGNO (rtl
) == STACK_POINTER_REGNUM
);
1310 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
1311 offset
= INTVAL (XEXP (rtl
, 1));
1315 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
1316 offset
= -INTVAL (XEXP (rtl
, 1));
1326 /* The return address is at some offset from any value we can
1327 actually load. For instance, on the SPARC it is in %i7+8. Just
1328 ignore the offset for now; it doesn't matter for unwinding frames. */
1329 gcc_assert (CONST_INT_P (XEXP (rtl
, 1)));
1330 initial_return_save (XEXP (rtl
, 0));
1337 if (reg
!= DWARF_FRAME_RETURN_COLUMN
)
1338 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
1341 /* Given a SET, calculate the amount of stack adjustment it
1344 static HOST_WIDE_INT
1345 stack_adjust_offset (const_rtx pattern
, HOST_WIDE_INT cur_args_size
,
1346 HOST_WIDE_INT cur_offset
)
1348 const_rtx src
= SET_SRC (pattern
);
1349 const_rtx dest
= SET_DEST (pattern
);
1350 HOST_WIDE_INT offset
= 0;
1353 if (dest
== stack_pointer_rtx
)
1355 code
= GET_CODE (src
);
1357 /* Assume (set (reg sp) (reg whatever)) sets args_size
1359 if (code
== REG
&& src
!= stack_pointer_rtx
)
1361 offset
= -cur_args_size
;
1362 #ifndef STACK_GROWS_DOWNWARD
1365 return offset
- cur_offset
;
1368 if (! (code
== PLUS
|| code
== MINUS
)
1369 || XEXP (src
, 0) != stack_pointer_rtx
1370 || !CONST_INT_P (XEXP (src
, 1)))
1373 /* (set (reg sp) (plus (reg sp) (const_int))) */
1374 offset
= INTVAL (XEXP (src
, 1));
1380 if (MEM_P (src
) && !MEM_P (dest
))
1384 /* (set (mem (pre_dec (reg sp))) (foo)) */
1385 src
= XEXP (dest
, 0);
1386 code
= GET_CODE (src
);
1392 if (XEXP (src
, 0) == stack_pointer_rtx
)
1394 rtx val
= XEXP (XEXP (src
, 1), 1);
1395 /* We handle only adjustments by constant amount. */
1396 gcc_assert (GET_CODE (XEXP (src
, 1)) == PLUS
1397 && CONST_INT_P (val
));
1398 offset
= -INTVAL (val
);
1405 if (XEXP (src
, 0) == stack_pointer_rtx
)
1407 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1414 if (XEXP (src
, 0) == stack_pointer_rtx
)
1416 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
1431 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1432 indexed by INSN_UID. */
1434 static HOST_WIDE_INT
*barrier_args_size
;
1436 /* Helper function for compute_barrier_args_size. Handle one insn. */
1438 static HOST_WIDE_INT
1439 compute_barrier_args_size_1 (rtx insn
, HOST_WIDE_INT cur_args_size
,
1440 VEC (rtx
, heap
) **next
)
1442 HOST_WIDE_INT offset
= 0;
1445 if (! RTX_FRAME_RELATED_P (insn
))
1447 if (prologue_epilogue_contains (insn
))
1449 else if (GET_CODE (PATTERN (insn
)) == SET
)
1450 offset
= stack_adjust_offset (PATTERN (insn
), cur_args_size
, 0);
1451 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1452 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1454 /* There may be stack adjustments inside compound insns. Search
1456 for (i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1457 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1458 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
),
1459 cur_args_size
, offset
);
1464 rtx expr
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1468 expr
= XEXP (expr
, 0);
1469 if (GET_CODE (expr
) == PARALLEL
1470 || GET_CODE (expr
) == SEQUENCE
)
1471 for (i
= 1; i
< XVECLEN (expr
, 0); i
++)
1473 rtx elem
= XVECEXP (expr
, 0, i
);
1475 if (GET_CODE (elem
) == SET
&& !RTX_FRAME_RELATED_P (elem
))
1476 offset
+= stack_adjust_offset (elem
, cur_args_size
, offset
);
1481 #ifndef STACK_GROWS_DOWNWARD
1485 cur_args_size
+= offset
;
1486 if (cur_args_size
< 0)
1491 rtx dest
= JUMP_LABEL (insn
);
1495 if (barrier_args_size
[INSN_UID (dest
)] < 0)
1497 barrier_args_size
[INSN_UID (dest
)] = cur_args_size
;
1498 VEC_safe_push (rtx
, heap
, *next
, dest
);
1503 return cur_args_size
;
1506 /* Walk the whole function and compute args_size on BARRIERs. */
1509 compute_barrier_args_size (void)
1511 int max_uid
= get_max_uid (), i
;
1513 VEC (rtx
, heap
) *worklist
, *next
, *tmp
;
1515 barrier_args_size
= XNEWVEC (HOST_WIDE_INT
, max_uid
);
1516 for (i
= 0; i
< max_uid
; i
++)
1517 barrier_args_size
[i
] = -1;
1519 worklist
= VEC_alloc (rtx
, heap
, 20);
1520 next
= VEC_alloc (rtx
, heap
, 20);
1521 insn
= get_insns ();
1522 barrier_args_size
[INSN_UID (insn
)] = 0;
1523 VEC_quick_push (rtx
, worklist
, insn
);
1526 while (!VEC_empty (rtx
, worklist
))
1528 rtx prev
, body
, first_insn
;
1529 HOST_WIDE_INT cur_args_size
;
1531 first_insn
= insn
= VEC_pop (rtx
, worklist
);
1532 cur_args_size
= barrier_args_size
[INSN_UID (insn
)];
1533 prev
= prev_nonnote_insn (insn
);
1534 if (prev
&& BARRIER_P (prev
))
1535 barrier_args_size
[INSN_UID (prev
)] = cur_args_size
;
1537 for (; insn
; insn
= NEXT_INSN (insn
))
1539 if (INSN_DELETED_P (insn
) || NOTE_P (insn
))
1541 if (BARRIER_P (insn
))
1546 if (insn
== first_insn
)
1548 else if (barrier_args_size
[INSN_UID (insn
)] < 0)
1550 barrier_args_size
[INSN_UID (insn
)] = cur_args_size
;
1555 /* The insns starting with this label have been
1556 already scanned or are in the worklist. */
1561 body
= PATTERN (insn
);
1562 if (GET_CODE (body
) == SEQUENCE
)
1564 HOST_WIDE_INT dest_args_size
= cur_args_size
;
1565 for (i
= 1; i
< XVECLEN (body
, 0); i
++)
1566 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body
, 0, 0))
1567 && INSN_FROM_TARGET_P (XVECEXP (body
, 0, i
)))
1569 = compute_barrier_args_size_1 (XVECEXP (body
, 0, i
),
1570 dest_args_size
, &next
);
1573 = compute_barrier_args_size_1 (XVECEXP (body
, 0, i
),
1574 cur_args_size
, &next
);
1576 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body
, 0, 0)))
1577 compute_barrier_args_size_1 (XVECEXP (body
, 0, 0),
1578 dest_args_size
, &next
);
1581 = compute_barrier_args_size_1 (XVECEXP (body
, 0, 0),
1582 cur_args_size
, &next
);
1586 = compute_barrier_args_size_1 (insn
, cur_args_size
, &next
);
1590 if (VEC_empty (rtx
, next
))
1593 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1597 VEC_truncate (rtx
, next
, 0);
1600 VEC_free (rtx
, heap
, worklist
);
1601 VEC_free (rtx
, heap
, next
);
1604 /* Add a CFI to update the running total of the size of arguments
1605 pushed onto the stack. */
1608 dwarf2out_args_size (const char *label
, HOST_WIDE_INT size
)
1612 if (size
== old_args_size
)
1615 old_args_size
= size
;
1618 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
1619 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
1620 add_fde_cfi (label
, cfi
);
1623 /* Record a stack adjustment of OFFSET bytes. */
1626 dwarf2out_stack_adjust (HOST_WIDE_INT offset
, const char *label
)
1628 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1629 cfa
.offset
+= offset
;
1631 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1632 cfa_store
.offset
+= offset
;
1634 if (ACCUMULATE_OUTGOING_ARGS
)
1637 #ifndef STACK_GROWS_DOWNWARD
1641 args_size
+= offset
;
1645 def_cfa_1 (label
, &cfa
);
1646 if (flag_asynchronous_unwind_tables
)
1647 dwarf2out_args_size (label
, args_size
);
1650 /* Check INSN to see if it looks like a push or a stack adjustment, and
1651 make a note of it if it does. EH uses this information to find out
1652 how much extra space it needs to pop off the stack. */
1655 dwarf2out_notice_stack_adjust (rtx insn
, bool after_p
)
1657 HOST_WIDE_INT offset
;
1661 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1662 with this function. Proper support would require all frame-related
1663 insns to be marked, and to be able to handle saving state around
1664 epilogues textually in the middle of the function. */
1665 if (prologue_epilogue_contains (insn
))
1668 /* If INSN is an instruction from target of an annulled branch, the
1669 effects are for the target only and so current argument size
1670 shouldn't change at all. */
1672 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence
, 0, 0))
1673 && INSN_FROM_TARGET_P (insn
))
1676 /* If only calls can throw, and we have a frame pointer,
1677 save up adjustments until we see the CALL_INSN. */
1678 if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1680 if (CALL_P (insn
) && !after_p
)
1682 /* Extract the size of the args from the CALL rtx itself. */
1683 insn
= PATTERN (insn
);
1684 if (GET_CODE (insn
) == PARALLEL
)
1685 insn
= XVECEXP (insn
, 0, 0);
1686 if (GET_CODE (insn
) == SET
)
1687 insn
= SET_SRC (insn
);
1688 gcc_assert (GET_CODE (insn
) == CALL
);
1689 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1694 if (CALL_P (insn
) && !after_p
)
1696 if (!flag_asynchronous_unwind_tables
)
1697 dwarf2out_args_size ("", args_size
);
1700 else if (BARRIER_P (insn
))
1702 /* Don't call compute_barrier_args_size () if the only
1703 BARRIER is at the end of function. */
1704 if (barrier_args_size
== NULL
&& next_nonnote_insn (insn
))
1705 compute_barrier_args_size ();
1706 if (barrier_args_size
== NULL
)
1710 offset
= barrier_args_size
[INSN_UID (insn
)];
1715 offset
-= args_size
;
1716 #ifndef STACK_GROWS_DOWNWARD
1720 else if (GET_CODE (PATTERN (insn
)) == SET
)
1721 offset
= stack_adjust_offset (PATTERN (insn
), args_size
, 0);
1722 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1723 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1725 /* There may be stack adjustments inside compound insns. Search
1727 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1728 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1729 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
),
1738 label
= dwarf2out_cfi_label (false);
1739 dwarf2out_stack_adjust (offset
, label
);
1742 /* We delay emitting a register save until either (a) we reach the end
1743 of the prologue or (b) the register is clobbered. This clusters
1744 register saves so that there are fewer pc advances. */
1746 struct GTY(()) queued_reg_save
{
1747 struct queued_reg_save
*next
;
1749 HOST_WIDE_INT cfa_offset
;
1753 static GTY(()) struct queued_reg_save
*queued_reg_saves
;
1755 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1756 struct GTY(()) reg_saved_in_data
{
1761 /* A list of registers saved in other registers.
1762 The list intentionally has a small maximum capacity of 4; if your
1763 port needs more than that, you might consider implementing a
1764 more efficient data structure. */
1765 static GTY(()) struct reg_saved_in_data regs_saved_in_regs
[4];
1766 static GTY(()) size_t num_regs_saved_in_regs
;
1768 static const char *last_reg_save_label
;
1770 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1771 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1774 queue_reg_save (const char *label
, rtx reg
, rtx sreg
, HOST_WIDE_INT offset
)
1776 struct queued_reg_save
*q
;
1778 /* Duplicates waste space, but it's also necessary to remove them
1779 for correctness, since the queue gets output in reverse
1781 for (q
= queued_reg_saves
; q
!= NULL
; q
= q
->next
)
1782 if (REGNO (q
->reg
) == REGNO (reg
))
1787 q
= ggc_alloc_queued_reg_save ();
1788 q
->next
= queued_reg_saves
;
1789 queued_reg_saves
= q
;
1793 q
->cfa_offset
= offset
;
1794 q
->saved_reg
= sreg
;
1796 last_reg_save_label
= label
;
1799 /* Output all the entries in QUEUED_REG_SAVES. */
1802 dwarf2out_flush_queued_reg_saves (void)
1804 struct queued_reg_save
*q
;
1806 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1809 unsigned int reg
, sreg
;
1811 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1812 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (q
->reg
))
1814 if (q
->saved_reg
&& i
== num_regs_saved_in_regs
)
1816 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1817 num_regs_saved_in_regs
++;
1819 if (i
!= num_regs_saved_in_regs
)
1821 regs_saved_in_regs
[i
].orig_reg
= q
->reg
;
1822 regs_saved_in_regs
[i
].saved_in_reg
= q
->saved_reg
;
1825 reg
= DWARF_FRAME_REGNUM (REGNO (q
->reg
));
1827 sreg
= DWARF_FRAME_REGNUM (REGNO (q
->saved_reg
));
1829 sreg
= INVALID_REGNUM
;
1830 reg_save (last_reg_save_label
, reg
, sreg
, q
->cfa_offset
);
1833 queued_reg_saves
= NULL
;
1834 last_reg_save_label
= NULL
;
1837 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1838 location for? Or, does it clobber a register which we've previously
1839 said that some other register is saved in, and for which we now
1840 have a new location for? */
1843 clobbers_queued_reg_save (const_rtx insn
)
1845 struct queued_reg_save
*q
;
1847 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1850 if (modified_in_p (q
->reg
, insn
))
1852 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1853 if (REGNO (q
->reg
) == REGNO (regs_saved_in_regs
[i
].orig_reg
)
1854 && modified_in_p (regs_saved_in_regs
[i
].saved_in_reg
, insn
))
1861 /* Entry point for saving the first register into the second. */
1864 dwarf2out_reg_save_reg (const char *label
, rtx reg
, rtx sreg
)
1867 unsigned int regno
, sregno
;
1869 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1870 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (reg
))
1872 if (i
== num_regs_saved_in_regs
)
1874 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1875 num_regs_saved_in_regs
++;
1877 regs_saved_in_regs
[i
].orig_reg
= reg
;
1878 regs_saved_in_regs
[i
].saved_in_reg
= sreg
;
1880 regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
1881 sregno
= DWARF_FRAME_REGNUM (REGNO (sreg
));
1882 reg_save (label
, regno
, sregno
, 0);
1885 /* What register, if any, is currently saved in REG? */
1888 reg_saved_in (rtx reg
)
1890 unsigned int regn
= REGNO (reg
);
1892 struct queued_reg_save
*q
;
1894 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1895 if (q
->saved_reg
&& regn
== REGNO (q
->saved_reg
))
1898 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1899 if (regs_saved_in_regs
[i
].saved_in_reg
1900 && regn
== REGNO (regs_saved_in_regs
[i
].saved_in_reg
))
1901 return regs_saved_in_regs
[i
].orig_reg
;
1907 /* A temporary register holding an integral value used in adjusting SP
1908 or setting up the store_reg. The "offset" field holds the integer
1909 value, not an offset. */
1910 static dw_cfa_location cfa_temp
;
1912 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1915 dwarf2out_frame_debug_def_cfa (rtx pat
, const char *label
)
1917 memset (&cfa
, 0, sizeof (cfa
));
1919 switch (GET_CODE (pat
))
1922 cfa
.reg
= REGNO (XEXP (pat
, 0));
1923 cfa
.offset
= INTVAL (XEXP (pat
, 1));
1927 cfa
.reg
= REGNO (pat
);
1932 pat
= XEXP (pat
, 0);
1933 if (GET_CODE (pat
) == PLUS
)
1935 cfa
.base_offset
= INTVAL (XEXP (pat
, 1));
1936 pat
= XEXP (pat
, 0);
1938 cfa
.reg
= REGNO (pat
);
1942 /* Recurse and define an expression. */
1946 def_cfa_1 (label
, &cfa
);
1949 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1952 dwarf2out_frame_debug_adjust_cfa (rtx pat
, const char *label
)
1956 gcc_assert (GET_CODE (pat
) == SET
);
1957 dest
= XEXP (pat
, 0);
1958 src
= XEXP (pat
, 1);
1960 switch (GET_CODE (src
))
1963 gcc_assert (REGNO (XEXP (src
, 0)) == cfa
.reg
);
1964 cfa
.offset
-= INTVAL (XEXP (src
, 1));
1974 cfa
.reg
= REGNO (dest
);
1975 gcc_assert (cfa
.indirect
== 0);
1977 def_cfa_1 (label
, &cfa
);
1980 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1983 dwarf2out_frame_debug_cfa_offset (rtx set
, const char *label
)
1985 HOST_WIDE_INT offset
;
1986 rtx src
, addr
, span
;
1988 src
= XEXP (set
, 1);
1989 addr
= XEXP (set
, 0);
1990 gcc_assert (MEM_P (addr
));
1991 addr
= XEXP (addr
, 0);
1993 /* As documented, only consider extremely simple addresses. */
1994 switch (GET_CODE (addr
))
1997 gcc_assert (REGNO (addr
) == cfa
.reg
);
1998 offset
= -cfa
.offset
;
2001 gcc_assert (REGNO (XEXP (addr
, 0)) == cfa
.reg
);
2002 offset
= INTVAL (XEXP (addr
, 1)) - cfa
.offset
;
2008 span
= targetm
.dwarf_register_span (src
);
2010 /* ??? We'd like to use queue_reg_save, but we need to come up with
2011 a different flushing heuristic for epilogues. */
2013 reg_save (label
, DWARF_FRAME_REGNUM (REGNO (src
)), INVALID_REGNUM
, offset
);
2016 /* We have a PARALLEL describing where the contents of SRC live.
2017 Queue register saves for each piece of the PARALLEL. */
2020 HOST_WIDE_INT span_offset
= offset
;
2022 gcc_assert (GET_CODE (span
) == PARALLEL
);
2024 limit
= XVECLEN (span
, 0);
2025 for (par_index
= 0; par_index
< limit
; par_index
++)
2027 rtx elem
= XVECEXP (span
, 0, par_index
);
2029 reg_save (label
, DWARF_FRAME_REGNUM (REGNO (elem
)),
2030 INVALID_REGNUM
, span_offset
);
2031 span_offset
+= GET_MODE_SIZE (GET_MODE (elem
));
2036 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
2039 dwarf2out_frame_debug_cfa_register (rtx set
, const char *label
)
2042 unsigned sregno
, dregno
;
2044 src
= XEXP (set
, 1);
2045 dest
= XEXP (set
, 0);
2048 sregno
= DWARF_FRAME_RETURN_COLUMN
;
2050 sregno
= DWARF_FRAME_REGNUM (REGNO (src
));
2052 dregno
= DWARF_FRAME_REGNUM (REGNO (dest
));
2054 /* ??? We'd like to use queue_reg_save, but we need to come up with
2055 a different flushing heuristic for epilogues. */
2056 reg_save (label
, sregno
, dregno
, 0);
2059 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
2062 dwarf2out_frame_debug_cfa_expression (rtx set
, const char *label
)
2064 rtx src
, dest
, span
;
2065 dw_cfi_ref cfi
= new_cfi ();
2067 dest
= SET_DEST (set
);
2068 src
= SET_SRC (set
);
2070 gcc_assert (REG_P (src
));
2071 gcc_assert (MEM_P (dest
));
2073 span
= targetm
.dwarf_register_span (src
);
2076 cfi
->dw_cfi_opc
= DW_CFA_expression
;
2077 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= DWARF_FRAME_REGNUM (REGNO (src
));
2078 cfi
->dw_cfi_oprnd2
.dw_cfi_loc
2079 = mem_loc_descriptor (XEXP (dest
, 0), GET_MODE (dest
),
2080 VAR_INIT_STATUS_INITIALIZED
);
2082 /* ??? We'd like to use queue_reg_save, were the interface different,
2083 and, as above, we could manage flushing for epilogues. */
2084 add_fde_cfi (label
, cfi
);
2087 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
2090 dwarf2out_frame_debug_cfa_restore (rtx reg
, const char *label
)
2092 dw_cfi_ref cfi
= new_cfi ();
2093 unsigned int regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
2095 cfi
->dw_cfi_opc
= (regno
& ~0x3f ? DW_CFA_restore_extended
: DW_CFA_restore
);
2096 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= regno
;
2098 add_fde_cfi (label
, cfi
);
2101 /* Record call frame debugging information for an expression EXPR,
2102 which either sets SP or FP (adjusting how we calculate the frame
2103 address) or saves a register to the stack or another register.
2104 LABEL indicates the address of EXPR.
2106 This function encodes a state machine mapping rtxes to actions on
2107 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
2108 users need not read the source code.
2110 The High-Level Picture
2112 Changes in the register we use to calculate the CFA: Currently we
2113 assume that if you copy the CFA register into another register, we
2114 should take the other one as the new CFA register; this seems to
2115 work pretty well. If it's wrong for some target, it's simple
2116 enough not to set RTX_FRAME_RELATED_P on the insn in question.
2118 Changes in the register we use for saving registers to the stack:
2119 This is usually SP, but not always. Again, we deduce that if you
2120 copy SP into another register (and SP is not the CFA register),
2121 then the new register is the one we will be using for register
2122 saves. This also seems to work.
2124 Register saves: There's not much guesswork about this one; if
2125 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
2126 register save, and the register used to calculate the destination
2127 had better be the one we think we're using for this purpose.
2128 It's also assumed that a copy from a call-saved register to another
2129 register is saving that register if RTX_FRAME_RELATED_P is set on
2130 that instruction. If the copy is from a call-saved register to
2131 the *same* register, that means that the register is now the same
2132 value as in the caller.
2134 Except: If the register being saved is the CFA register, and the
2135 offset is nonzero, we are saving the CFA, so we assume we have to
2136 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
2137 the intent is to save the value of SP from the previous frame.
2139 In addition, if a register has previously been saved to a different
2142 Invariants / Summaries of Rules
2144 cfa current rule for calculating the CFA. It usually
2145 consists of a register and an offset.
2146 cfa_store register used by prologue code to save things to the stack
2147 cfa_store.offset is the offset from the value of
2148 cfa_store.reg to the actual CFA
2149 cfa_temp register holding an integral value. cfa_temp.offset
2150 stores the value, which will be used to adjust the
2151 stack pointer. cfa_temp is also used like cfa_store,
2152 to track stores to the stack via fp or a temp reg.
2154 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2155 with cfa.reg as the first operand changes the cfa.reg and its
2156 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2159 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2160 expression yielding a constant. This sets cfa_temp.reg
2161 and cfa_temp.offset.
2163 Rule 5: Create a new register cfa_store used to save items to the
2166 Rules 10-14: Save a register to the stack. Define offset as the
2167 difference of the original location and cfa_store's
2168 location (or cfa_temp's location if cfa_temp is used).
2170 Rules 16-20: If AND operation happens on sp in prologue, we assume
2171 stack is realigned. We will use a group of DW_OP_XXX
2172 expressions to represent the location of the stored
2173 register instead of CFA+offset.
2177 "{a,b}" indicates a choice of a xor b.
2178 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2181 (set <reg1> <reg2>:cfa.reg)
2182 effects: cfa.reg = <reg1>
2183 cfa.offset unchanged
2184 cfa_temp.reg = <reg1>
2185 cfa_temp.offset = cfa.offset
2188 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2189 {<const_int>,<reg>:cfa_temp.reg}))
2190 effects: cfa.reg = sp if fp used
2191 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2192 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2193 if cfa_store.reg==sp
2196 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2197 effects: cfa.reg = fp
2198 cfa_offset += +/- <const_int>
2201 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2202 constraints: <reg1> != fp
2204 effects: cfa.reg = <reg1>
2205 cfa_temp.reg = <reg1>
2206 cfa_temp.offset = cfa.offset
2209 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2210 constraints: <reg1> != fp
2212 effects: cfa_store.reg = <reg1>
2213 cfa_store.offset = cfa.offset - cfa_temp.offset
2216 (set <reg> <const_int>)
2217 effects: cfa_temp.reg = <reg>
2218 cfa_temp.offset = <const_int>
2221 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2222 effects: cfa_temp.reg = <reg1>
2223 cfa_temp.offset |= <const_int>
2226 (set <reg> (high <exp>))
2230 (set <reg> (lo_sum <exp> <const_int>))
2231 effects: cfa_temp.reg = <reg>
2232 cfa_temp.offset = <const_int>
2235 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2236 effects: cfa_store.offset -= <const_int>
2237 cfa.offset = cfa_store.offset if cfa.reg == sp
2239 cfa.base_offset = -cfa_store.offset
2242 (set (mem ({pre_inc,pre_dec,post_dec} sp:cfa_store.reg)) <reg>)
2243 effects: cfa_store.offset += -/+ mode_size(mem)
2244 cfa.offset = cfa_store.offset if cfa.reg == sp
2246 cfa.base_offset = -cfa_store.offset
2249 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2252 effects: cfa.reg = <reg1>
2253 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2256 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2257 effects: cfa.reg = <reg1>
2258 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2261 (set (mem (post_inc <reg1>:cfa_temp <const_int>)) <reg2>)
2262 effects: cfa.reg = <reg1>
2263 cfa.base_offset = -cfa_temp.offset
2264 cfa_temp.offset -= mode_size(mem)
2267 (set <reg> {unspec, unspec_volatile})
2268 effects: target-dependent
2271 (set sp (and: sp <const_int>))
2272 constraints: cfa_store.reg == sp
2273 effects: current_fde.stack_realign = 1
2274 cfa_store.offset = 0
2275 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2278 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2279 effects: cfa_store.offset += -/+ mode_size(mem)
2282 (set (mem ({pre_inc, pre_dec} sp)) fp)
2283 constraints: fde->stack_realign == 1
2284 effects: cfa_store.offset = 0
2285 cfa.reg != HARD_FRAME_POINTER_REGNUM
2288 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2289 constraints: fde->stack_realign == 1
2291 && cfa.indirect == 0
2292 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2293 effects: Use DW_CFA_def_cfa_expression to define cfa
2294 cfa.reg == fde->drap_reg */
2297 dwarf2out_frame_debug_expr (rtx expr
, const char *label
)
2299 rtx src
, dest
, span
;
2300 HOST_WIDE_INT offset
;
2303 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2304 the PARALLEL independently. The first element is always processed if
2305 it is a SET. This is for backward compatibility. Other elements
2306 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2307 flag is set in them. */
2308 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
2311 int limit
= XVECLEN (expr
, 0);
2314 /* PARALLELs have strict read-modify-write semantics, so we
2315 ought to evaluate every rvalue before changing any lvalue.
2316 It's cumbersome to do that in general, but there's an
2317 easy approximation that is enough for all current users:
2318 handle register saves before register assignments. */
2319 if (GET_CODE (expr
) == PARALLEL
)
2320 for (par_index
= 0; par_index
< limit
; par_index
++)
2322 elem
= XVECEXP (expr
, 0, par_index
);
2323 if (GET_CODE (elem
) == SET
2324 && MEM_P (SET_DEST (elem
))
2325 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
2326 dwarf2out_frame_debug_expr (elem
, label
);
2329 for (par_index
= 0; par_index
< limit
; par_index
++)
2331 elem
= XVECEXP (expr
, 0, par_index
);
2332 if (GET_CODE (elem
) == SET
2333 && (!MEM_P (SET_DEST (elem
)) || GET_CODE (expr
) == SEQUENCE
)
2334 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
2335 dwarf2out_frame_debug_expr (elem
, label
);
2336 else if (GET_CODE (elem
) == SET
2338 && !RTX_FRAME_RELATED_P (elem
))
2340 /* Stack adjustment combining might combine some post-prologue
2341 stack adjustment into a prologue stack adjustment. */
2342 HOST_WIDE_INT offset
= stack_adjust_offset (elem
, args_size
, 0);
2345 dwarf2out_stack_adjust (offset
, label
);
2351 gcc_assert (GET_CODE (expr
) == SET
);
2353 src
= SET_SRC (expr
);
2354 dest
= SET_DEST (expr
);
2358 rtx rsi
= reg_saved_in (src
);
2363 fde
= current_fde ();
2365 switch (GET_CODE (dest
))
2368 switch (GET_CODE (src
))
2370 /* Setting FP from SP. */
2372 if (cfa
.reg
== (unsigned) REGNO (src
))
2375 /* Update the CFA rule wrt SP or FP. Make sure src is
2376 relative to the current CFA register.
2378 We used to require that dest be either SP or FP, but the
2379 ARM copies SP to a temporary register, and from there to
2380 FP. So we just rely on the backends to only set
2381 RTX_FRAME_RELATED_P on appropriate insns. */
2382 cfa
.reg
= REGNO (dest
);
2383 cfa_temp
.reg
= cfa
.reg
;
2384 cfa_temp
.offset
= cfa
.offset
;
2388 /* Saving a register in a register. */
2389 gcc_assert (!fixed_regs
[REGNO (dest
)]
2390 /* For the SPARC and its register window. */
2391 || (DWARF_FRAME_REGNUM (REGNO (src
))
2392 == DWARF_FRAME_RETURN_COLUMN
));
2394 /* After stack is aligned, we can only save SP in FP
2395 if drap register is used. In this case, we have
2396 to restore stack pointer with the CFA value and we
2397 don't generate this DWARF information. */
2399 && fde
->stack_realign
2400 && REGNO (src
) == STACK_POINTER_REGNUM
)
2401 gcc_assert (REGNO (dest
) == HARD_FRAME_POINTER_REGNUM
2402 && fde
->drap_reg
!= INVALID_REGNUM
2403 && cfa
.reg
!= REGNO (src
));
2405 queue_reg_save (label
, src
, dest
, 0);
2412 if (dest
== stack_pointer_rtx
)
2416 switch (GET_CODE (XEXP (src
, 1)))
2419 offset
= INTVAL (XEXP (src
, 1));
2422 gcc_assert ((unsigned) REGNO (XEXP (src
, 1))
2424 offset
= cfa_temp
.offset
;
2430 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
2432 /* Restoring SP from FP in the epilogue. */
2433 gcc_assert (cfa
.reg
== (unsigned) HARD_FRAME_POINTER_REGNUM
);
2434 cfa
.reg
= STACK_POINTER_REGNUM
;
2436 else if (GET_CODE (src
) == LO_SUM
)
2437 /* Assume we've set the source reg of the LO_SUM from sp. */
2440 gcc_assert (XEXP (src
, 0) == stack_pointer_rtx
);
2442 if (GET_CODE (src
) != MINUS
)
2444 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2445 cfa
.offset
+= offset
;
2446 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
2447 cfa_store
.offset
+= offset
;
2449 else if (dest
== hard_frame_pointer_rtx
)
2452 /* Either setting the FP from an offset of the SP,
2453 or adjusting the FP */
2454 gcc_assert (frame_pointer_needed
);
2456 gcc_assert (REG_P (XEXP (src
, 0))
2457 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
2458 && CONST_INT_P (XEXP (src
, 1)));
2459 offset
= INTVAL (XEXP (src
, 1));
2460 if (GET_CODE (src
) != MINUS
)
2462 cfa
.offset
+= offset
;
2463 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
2467 gcc_assert (GET_CODE (src
) != MINUS
);
2470 if (REG_P (XEXP (src
, 0))
2471 && REGNO (XEXP (src
, 0)) == cfa
.reg
2472 && CONST_INT_P (XEXP (src
, 1)))
2474 /* Setting a temporary CFA register that will be copied
2475 into the FP later on. */
2476 offset
= - INTVAL (XEXP (src
, 1));
2477 cfa
.offset
+= offset
;
2478 cfa
.reg
= REGNO (dest
);
2479 /* Or used to save regs to the stack. */
2480 cfa_temp
.reg
= cfa
.reg
;
2481 cfa_temp
.offset
= cfa
.offset
;
2485 else if (REG_P (XEXP (src
, 0))
2486 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
2487 && XEXP (src
, 1) == stack_pointer_rtx
)
2489 /* Setting a scratch register that we will use instead
2490 of SP for saving registers to the stack. */
2491 gcc_assert (cfa
.reg
== STACK_POINTER_REGNUM
);
2492 cfa_store
.reg
= REGNO (dest
);
2493 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
2497 else if (GET_CODE (src
) == LO_SUM
2498 && CONST_INT_P (XEXP (src
, 1)))
2500 cfa_temp
.reg
= REGNO (dest
);
2501 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
2510 cfa_temp
.reg
= REGNO (dest
);
2511 cfa_temp
.offset
= INTVAL (src
);
2516 gcc_assert (REG_P (XEXP (src
, 0))
2517 && (unsigned) REGNO (XEXP (src
, 0)) == cfa_temp
.reg
2518 && CONST_INT_P (XEXP (src
, 1)));
2520 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
2521 cfa_temp
.reg
= REGNO (dest
);
2522 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
2525 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2526 which will fill in all of the bits. */
2533 case UNSPEC_VOLATILE
:
2534 gcc_assert (targetm
.dwarf_handle_frame_unspec
);
2535 targetm
.dwarf_handle_frame_unspec (label
, expr
, XINT (src
, 1));
2540 /* If this AND operation happens on stack pointer in prologue,
2541 we assume the stack is realigned and we extract the
2543 if (fde
&& XEXP (src
, 0) == stack_pointer_rtx
)
2545 /* We interpret reg_save differently with stack_realign set.
2546 Thus we must flush whatever we have queued first. */
2547 dwarf2out_flush_queued_reg_saves ();
2549 gcc_assert (cfa_store
.reg
== REGNO (XEXP (src
, 0)));
2550 fde
->stack_realign
= 1;
2551 fde
->stack_realignment
= INTVAL (XEXP (src
, 1));
2552 cfa_store
.offset
= 0;
2554 if (cfa
.reg
!= STACK_POINTER_REGNUM
2555 && cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
)
2556 fde
->drap_reg
= cfa
.reg
;
2564 def_cfa_1 (label
, &cfa
);
2569 /* Saving a register to the stack. Make sure dest is relative to the
2571 switch (GET_CODE (XEXP (dest
, 0)))
2576 /* We can't handle variable size modifications. */
2577 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1))
2579 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
2581 gcc_assert (REGNO (XEXP (XEXP (dest
, 0), 0)) == STACK_POINTER_REGNUM
2582 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
2584 cfa_store
.offset
+= offset
;
2585 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2586 cfa
.offset
= cfa_store
.offset
;
2588 offset
= -cfa_store
.offset
;
2595 offset
= GET_MODE_SIZE (GET_MODE (dest
));
2596 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
2599 gcc_assert ((REGNO (XEXP (XEXP (dest
, 0), 0))
2600 == STACK_POINTER_REGNUM
)
2601 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
2603 cfa_store
.offset
+= offset
;
2605 /* Rule 18: If stack is aligned, we will use FP as a
2606 reference to represent the address of the stored
2609 && fde
->stack_realign
2610 && src
== hard_frame_pointer_rtx
)
2612 gcc_assert (cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
);
2613 cfa_store
.offset
= 0;
2616 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2617 cfa
.offset
= cfa_store
.offset
;
2619 if (GET_CODE (XEXP (dest
, 0)) == POST_DEC
)
2620 offset
+= -cfa_store
.offset
;
2622 offset
= -cfa_store
.offset
;
2626 /* With an offset. */
2633 gcc_assert (CONST_INT_P (XEXP (XEXP (dest
, 0), 1))
2634 && REG_P (XEXP (XEXP (dest
, 0), 0)));
2635 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
2636 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
2639 regno
= REGNO (XEXP (XEXP (dest
, 0), 0));
2641 if (cfa
.reg
== (unsigned) regno
)
2642 offset
-= cfa
.offset
;
2643 else if (cfa_store
.reg
== (unsigned) regno
)
2644 offset
-= cfa_store
.offset
;
2647 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
2648 offset
-= cfa_temp
.offset
;
2654 /* Without an offset. */
2657 int regno
= REGNO (XEXP (dest
, 0));
2659 if (cfa
.reg
== (unsigned) regno
)
2660 offset
= -cfa
.offset
;
2661 else if (cfa_store
.reg
== (unsigned) regno
)
2662 offset
= -cfa_store
.offset
;
2665 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
2666 offset
= -cfa_temp
.offset
;
2673 gcc_assert (cfa_temp
.reg
2674 == (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)));
2675 offset
= -cfa_temp
.offset
;
2676 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
2684 /* If the source operand of this MEM operation is not a
2685 register, basically the source is return address. Here
2686 we only care how much stack grew and we don't save it. */
2690 if (REGNO (src
) != STACK_POINTER_REGNUM
2691 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
2692 && (unsigned) REGNO (src
) == cfa
.reg
)
2694 /* We're storing the current CFA reg into the stack. */
2696 if (cfa
.offset
== 0)
2699 /* If stack is aligned, putting CFA reg into stack means
2700 we can no longer use reg + offset to represent CFA.
2701 Here we use DW_CFA_def_cfa_expression instead. The
2702 result of this expression equals to the original CFA
2705 && fde
->stack_realign
2706 && cfa
.indirect
== 0
2707 && cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
)
2709 dw_cfa_location cfa_exp
;
2711 gcc_assert (fde
->drap_reg
== cfa
.reg
);
2713 cfa_exp
.indirect
= 1;
2714 cfa_exp
.reg
= HARD_FRAME_POINTER_REGNUM
;
2715 cfa_exp
.base_offset
= offset
;
2718 fde
->drap_reg_saved
= 1;
2720 def_cfa_1 (label
, &cfa_exp
);
2724 /* If the source register is exactly the CFA, assume
2725 we're saving SP like any other register; this happens
2727 def_cfa_1 (label
, &cfa
);
2728 queue_reg_save (label
, stack_pointer_rtx
, NULL_RTX
, offset
);
2733 /* Otherwise, we'll need to look in the stack to
2734 calculate the CFA. */
2735 rtx x
= XEXP (dest
, 0);
2739 gcc_assert (REG_P (x
));
2741 cfa
.reg
= REGNO (x
);
2742 cfa
.base_offset
= offset
;
2744 def_cfa_1 (label
, &cfa
);
2749 def_cfa_1 (label
, &cfa
);
2751 span
= targetm
.dwarf_register_span (src
);
2754 queue_reg_save (label
, src
, NULL_RTX
, offset
);
2757 /* We have a PARALLEL describing where the contents of SRC
2758 live. Queue register saves for each piece of the
2762 HOST_WIDE_INT span_offset
= offset
;
2764 gcc_assert (GET_CODE (span
) == PARALLEL
);
2766 limit
= XVECLEN (span
, 0);
2767 for (par_index
= 0; par_index
< limit
; par_index
++)
2769 rtx elem
= XVECEXP (span
, 0, par_index
);
2771 queue_reg_save (label
, elem
, NULL_RTX
, span_offset
);
2772 span_offset
+= GET_MODE_SIZE (GET_MODE (elem
));
2783 /* Record call frame debugging information for INSN, which either
2784 sets SP or FP (adjusting how we calculate the frame address) or saves a
2785 register to the stack. If INSN is NULL_RTX, initialize our state.
2787 If AFTER_P is false, we're being called before the insn is emitted,
2788 otherwise after. Call instructions get invoked twice. */
2791 dwarf2out_frame_debug (rtx insn
, bool after_p
)
2795 bool handled_one
= false;
2797 if (insn
== NULL_RTX
)
2801 /* Flush any queued register saves. */
2802 dwarf2out_flush_queued_reg_saves ();
2804 /* Set up state for generating call frame debug info. */
2807 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
));
2809 cfa
.reg
= STACK_POINTER_REGNUM
;
2812 cfa_temp
.offset
= 0;
2814 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
2816 regs_saved_in_regs
[i
].orig_reg
= NULL_RTX
;
2817 regs_saved_in_regs
[i
].saved_in_reg
= NULL_RTX
;
2819 num_regs_saved_in_regs
= 0;
2821 if (barrier_args_size
)
2823 XDELETEVEC (barrier_args_size
);
2824 barrier_args_size
= NULL
;
2829 if (!NONJUMP_INSN_P (insn
) || clobbers_queued_reg_save (insn
))
2830 dwarf2out_flush_queued_reg_saves ();
2832 if (!RTX_FRAME_RELATED_P (insn
))
2834 /* ??? This should be done unconditionally since stack adjustments
2835 matter if the stack pointer is not the CFA register anymore but
2836 is still used to save registers. */
2837 if (!ACCUMULATE_OUTGOING_ARGS
)
2838 dwarf2out_notice_stack_adjust (insn
, after_p
);
2842 label
= dwarf2out_cfi_label (false);
2843 any_cfis_emitted
= false;
2845 for (note
= REG_NOTES (insn
); note
; note
= XEXP (note
, 1))
2846 switch (REG_NOTE_KIND (note
))
2848 case REG_FRAME_RELATED_EXPR
:
2849 insn
= XEXP (note
, 0);
2852 case REG_CFA_DEF_CFA
:
2853 dwarf2out_frame_debug_def_cfa (XEXP (note
, 0), label
);
2857 case REG_CFA_ADJUST_CFA
:
2862 if (GET_CODE (n
) == PARALLEL
)
2863 n
= XVECEXP (n
, 0, 0);
2865 dwarf2out_frame_debug_adjust_cfa (n
, label
);
2869 case REG_CFA_OFFSET
:
2872 n
= single_set (insn
);
2873 dwarf2out_frame_debug_cfa_offset (n
, label
);
2877 case REG_CFA_REGISTER
:
2882 if (GET_CODE (n
) == PARALLEL
)
2883 n
= XVECEXP (n
, 0, 0);
2885 dwarf2out_frame_debug_cfa_register (n
, label
);
2889 case REG_CFA_EXPRESSION
:
2892 n
= single_set (insn
);
2893 dwarf2out_frame_debug_cfa_expression (n
, label
);
2897 case REG_CFA_RESTORE
:
2902 if (GET_CODE (n
) == PARALLEL
)
2903 n
= XVECEXP (n
, 0, 0);
2906 dwarf2out_frame_debug_cfa_restore (n
, label
);
2910 case REG_CFA_SET_VDRAP
:
2914 dw_fde_ref fde
= current_fde ();
2917 gcc_assert (fde
->vdrap_reg
== INVALID_REGNUM
);
2919 fde
->vdrap_reg
= REGNO (n
);
2930 if (any_cfis_emitted
)
2931 dwarf2out_flush_queued_reg_saves ();
2935 insn
= PATTERN (insn
);
2937 dwarf2out_frame_debug_expr (insn
, label
);
2939 /* Check again. A parallel can save and update the same register.
2940 We could probably check just once, here, but this is safer than
2941 removing the check above. */
2942 if (any_cfis_emitted
|| clobbers_queued_reg_save (insn
))
2943 dwarf2out_flush_queued_reg_saves ();
2946 /* Determine if we need to save and restore CFI information around this
2947 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2948 we do need to save/restore, then emit the save now, and insert a
2949 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2952 dwarf2out_cfi_begin_epilogue (rtx insn
)
2954 bool saw_frp
= false;
2957 /* Scan forward to the return insn, noticing if there are possible
2958 frame related insns. */
2959 for (i
= NEXT_INSN (insn
); i
; i
= NEXT_INSN (i
))
2964 /* Look for both regular and sibcalls to end the block. */
2965 if (returnjump_p (i
))
2967 if (CALL_P (i
) && SIBLING_CALL_P (i
))
2970 if (GET_CODE (PATTERN (i
)) == SEQUENCE
)
2973 rtx seq
= PATTERN (i
);
2975 if (returnjump_p (XVECEXP (seq
, 0, 0)))
2977 if (CALL_P (XVECEXP (seq
, 0, 0))
2978 && SIBLING_CALL_P (XVECEXP (seq
, 0, 0)))
2981 for (idx
= 0; idx
< XVECLEN (seq
, 0); idx
++)
2982 if (RTX_FRAME_RELATED_P (XVECEXP (seq
, 0, idx
)))
2986 if (RTX_FRAME_RELATED_P (i
))
2990 /* If the port doesn't emit epilogue unwind info, we don't need a
2991 save/restore pair. */
2995 /* Otherwise, search forward to see if the return insn was the last
2996 basic block of the function. If so, we don't need save/restore. */
2997 gcc_assert (i
!= NULL
);
2998 i
= next_real_insn (i
);
3002 /* Insert the restore before that next real insn in the stream, and before
3003 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
3004 properly nested. This should be after any label or alignment. This
3005 will be pushed into the CFI stream by the function below. */
3008 rtx p
= PREV_INSN (i
);
3011 if (NOTE_KIND (p
) == NOTE_INSN_BASIC_BLOCK
)
3015 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE
, i
);
3017 emit_cfa_remember
= true;
3019 /* And emulate the state save. */
3020 gcc_assert (!cfa_remember
.in_use
);
3022 cfa_remember
.in_use
= 1;
3025 /* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
3029 dwarf2out_frame_debug_restore_state (void)
3031 dw_cfi_ref cfi
= new_cfi ();
3032 const char *label
= dwarf2out_cfi_label (false);
3034 cfi
->dw_cfi_opc
= DW_CFA_restore_state
;
3035 add_fde_cfi (label
, cfi
);
3037 gcc_assert (cfa_remember
.in_use
);
3039 cfa_remember
.in_use
= 0;
3042 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
3043 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
3044 (enum dwarf_call_frame_info cfi
);
3046 static enum dw_cfi_oprnd_type
3047 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
3052 case DW_CFA_GNU_window_save
:
3053 case DW_CFA_remember_state
:
3054 case DW_CFA_restore_state
:
3055 return dw_cfi_oprnd_unused
;
3057 case DW_CFA_set_loc
:
3058 case DW_CFA_advance_loc1
:
3059 case DW_CFA_advance_loc2
:
3060 case DW_CFA_advance_loc4
:
3061 case DW_CFA_MIPS_advance_loc8
:
3062 return dw_cfi_oprnd_addr
;
3065 case DW_CFA_offset_extended
:
3066 case DW_CFA_def_cfa
:
3067 case DW_CFA_offset_extended_sf
:
3068 case DW_CFA_def_cfa_sf
:
3069 case DW_CFA_restore
:
3070 case DW_CFA_restore_extended
:
3071 case DW_CFA_undefined
:
3072 case DW_CFA_same_value
:
3073 case DW_CFA_def_cfa_register
:
3074 case DW_CFA_register
:
3075 case DW_CFA_expression
:
3076 return dw_cfi_oprnd_reg_num
;
3078 case DW_CFA_def_cfa_offset
:
3079 case DW_CFA_GNU_args_size
:
3080 case DW_CFA_def_cfa_offset_sf
:
3081 return dw_cfi_oprnd_offset
;
3083 case DW_CFA_def_cfa_expression
:
3084 return dw_cfi_oprnd_loc
;
3091 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
3092 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
3093 (enum dwarf_call_frame_info cfi
);
3095 static enum dw_cfi_oprnd_type
3096 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
3100 case DW_CFA_def_cfa
:
3101 case DW_CFA_def_cfa_sf
:
3103 case DW_CFA_offset_extended_sf
:
3104 case DW_CFA_offset_extended
:
3105 return dw_cfi_oprnd_offset
;
3107 case DW_CFA_register
:
3108 return dw_cfi_oprnd_reg_num
;
3110 case DW_CFA_expression
:
3111 return dw_cfi_oprnd_loc
;
3114 return dw_cfi_oprnd_unused
;
3118 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
3119 switch to the data section instead, and write out a synthetic start label
3120 for collect2 the first time around. */
3123 switch_to_eh_frame_section (bool back
)
3127 #ifdef EH_FRAME_SECTION_NAME
3128 if (eh_frame_section
== 0)
3132 if (EH_TABLES_CAN_BE_READ_ONLY
)
3138 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
3140 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
3142 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
3144 flags
= ((! flag_pic
3145 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
3146 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
3147 && (per_encoding
& 0x70) != DW_EH_PE_absptr
3148 && (per_encoding
& 0x70) != DW_EH_PE_aligned
3149 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
3150 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
3151 ? 0 : SECTION_WRITE
);
3154 flags
= SECTION_WRITE
;
3155 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
3157 #endif /* EH_FRAME_SECTION_NAME */
3159 if (eh_frame_section
)
3160 switch_to_section (eh_frame_section
);
3163 /* We have no special eh_frame section. Put the information in
3164 the data section and emit special labels to guide collect2. */
3165 switch_to_section (data_section
);
3169 label
= get_file_function_name ("F");
3170 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
3171 targetm
.asm_out
.globalize_label (asm_out_file
,
3172 IDENTIFIER_POINTER (label
));
3173 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
3178 /* Switch [BACK] to the eh or debug frame table section, depending on
3182 switch_to_frame_table_section (int for_eh
, bool back
)
3185 switch_to_eh_frame_section (back
);
3188 if (!debug_frame_section
)
3189 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
3190 SECTION_DEBUG
, NULL
);
3191 switch_to_section (debug_frame_section
);
3195 /* Output a Call Frame Information opcode and its operand(s). */
3198 output_cfi (dw_cfi_ref cfi
, dw_fde_ref fde
, int for_eh
)
3203 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
3204 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
3205 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
3206 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX
,
3207 ((unsigned HOST_WIDE_INT
)
3208 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
));
3209 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
3211 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3212 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
3213 "DW_CFA_offset, column %#lx", r
);
3214 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3215 dw2_asm_output_data_uleb128 (off
, NULL
);
3217 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
3219 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3220 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
3221 "DW_CFA_restore, column %#lx", r
);
3225 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
3226 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
3228 switch (cfi
->dw_cfi_opc
)
3230 case DW_CFA_set_loc
:
3232 dw2_asm_output_encoded_addr_rtx (
3233 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3234 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
3237 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
3238 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
3239 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3242 case DW_CFA_advance_loc1
:
3243 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3244 fde
->dw_fde_current_label
, NULL
);
3245 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3248 case DW_CFA_advance_loc2
:
3249 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3250 fde
->dw_fde_current_label
, NULL
);
3251 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3254 case DW_CFA_advance_loc4
:
3255 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3256 fde
->dw_fde_current_label
, NULL
);
3257 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3260 case DW_CFA_MIPS_advance_loc8
:
3261 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3262 fde
->dw_fde_current_label
, NULL
);
3263 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3266 case DW_CFA_offset_extended
:
3267 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3268 dw2_asm_output_data_uleb128 (r
, NULL
);
3269 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3270 dw2_asm_output_data_uleb128 (off
, NULL
);
3273 case DW_CFA_def_cfa
:
3274 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3275 dw2_asm_output_data_uleb128 (r
, NULL
);
3276 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
3279 case DW_CFA_offset_extended_sf
:
3280 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3281 dw2_asm_output_data_uleb128 (r
, NULL
);
3282 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3283 dw2_asm_output_data_sleb128 (off
, NULL
);
3286 case DW_CFA_def_cfa_sf
:
3287 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3288 dw2_asm_output_data_uleb128 (r
, NULL
);
3289 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3290 dw2_asm_output_data_sleb128 (off
, NULL
);
3293 case DW_CFA_restore_extended
:
3294 case DW_CFA_undefined
:
3295 case DW_CFA_same_value
:
3296 case DW_CFA_def_cfa_register
:
3297 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3298 dw2_asm_output_data_uleb128 (r
, NULL
);
3301 case DW_CFA_register
:
3302 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3303 dw2_asm_output_data_uleb128 (r
, NULL
);
3304 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, for_eh
);
3305 dw2_asm_output_data_uleb128 (r
, NULL
);
3308 case DW_CFA_def_cfa_offset
:
3309 case DW_CFA_GNU_args_size
:
3310 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
3313 case DW_CFA_def_cfa_offset_sf
:
3314 off
= div_data_align (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3315 dw2_asm_output_data_sleb128 (off
, NULL
);
3318 case DW_CFA_GNU_window_save
:
3321 case DW_CFA_def_cfa_expression
:
3322 case DW_CFA_expression
:
3323 output_cfa_loc (cfi
, for_eh
);
3326 case DW_CFA_GNU_negative_offset_extended
:
3327 /* Obsoleted by DW_CFA_offset_extended_sf. */
3336 /* Similar, but do it via assembler directives instead. */
3339 output_cfi_directive (dw_cfi_ref cfi
)
3341 unsigned long r
, r2
;
3343 switch (cfi
->dw_cfi_opc
)
3345 case DW_CFA_advance_loc
:
3346 case DW_CFA_advance_loc1
:
3347 case DW_CFA_advance_loc2
:
3348 case DW_CFA_advance_loc4
:
3349 case DW_CFA_MIPS_advance_loc8
:
3350 case DW_CFA_set_loc
:
3351 /* Should only be created by add_fde_cfi in a code path not
3352 followed when emitting via directives. The assembler is
3353 going to take care of this for us. */
3357 case DW_CFA_offset_extended
:
3358 case DW_CFA_offset_extended_sf
:
3359 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3360 fprintf (asm_out_file
, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC
"\n",
3361 r
, cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3364 case DW_CFA_restore
:
3365 case DW_CFA_restore_extended
:
3366 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3367 fprintf (asm_out_file
, "\t.cfi_restore %lu\n", r
);
3370 case DW_CFA_undefined
:
3371 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3372 fprintf (asm_out_file
, "\t.cfi_undefined %lu\n", r
);
3375 case DW_CFA_same_value
:
3376 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3377 fprintf (asm_out_file
, "\t.cfi_same_value %lu\n", r
);
3380 case DW_CFA_def_cfa
:
3381 case DW_CFA_def_cfa_sf
:
3382 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3383 fprintf (asm_out_file
, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC
"\n",
3384 r
, cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3387 case DW_CFA_def_cfa_register
:
3388 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3389 fprintf (asm_out_file
, "\t.cfi_def_cfa_register %lu\n", r
);
3392 case DW_CFA_register
:
3393 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3394 r2
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, 1);
3395 fprintf (asm_out_file
, "\t.cfi_register %lu, %lu\n", r
, r2
);
3398 case DW_CFA_def_cfa_offset
:
3399 case DW_CFA_def_cfa_offset_sf
:
3400 fprintf (asm_out_file
, "\t.cfi_def_cfa_offset "
3401 HOST_WIDE_INT_PRINT_DEC
"\n",
3402 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3405 case DW_CFA_remember_state
:
3406 fprintf (asm_out_file
, "\t.cfi_remember_state\n");
3408 case DW_CFA_restore_state
:
3409 fprintf (asm_out_file
, "\t.cfi_restore_state\n");
3412 case DW_CFA_GNU_args_size
:
3413 fprintf (asm_out_file
, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size
);
3414 dw2_asm_output_data_uleb128_raw (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3416 fprintf (asm_out_file
, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC
,
3417 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3418 fputc ('\n', asm_out_file
);
3421 case DW_CFA_GNU_window_save
:
3422 fprintf (asm_out_file
, "\t.cfi_window_save\n");
3425 case DW_CFA_def_cfa_expression
:
3426 case DW_CFA_expression
:
3427 fprintf (asm_out_file
, "\t.cfi_escape %#x,", cfi
->dw_cfi_opc
);
3428 output_cfa_loc_raw (cfi
);
3429 fputc ('\n', asm_out_file
);
3437 DEF_VEC_P (dw_cfi_ref
);
3438 DEF_VEC_ALLOC_P (dw_cfi_ref
, heap
);
3440 /* Output CFIs to bring current FDE to the same state as after executing
3441 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3442 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3443 other arguments to pass to output_cfi. */
3446 output_cfis (dw_cfi_ref cfi
, bool do_cfi_asm
, dw_fde_ref fde
, bool for_eh
)
3448 struct dw_cfi_struct cfi_buf
;
3450 dw_cfi_ref cfi_args_size
= NULL
, cfi_cfa
= NULL
, cfi_cfa_offset
= NULL
;
3451 VEC (dw_cfi_ref
, heap
) *regs
= VEC_alloc (dw_cfi_ref
, heap
, 32);
3452 unsigned int len
, idx
;
3454 for (;; cfi
= cfi
->dw_cfi_next
)
3455 switch (cfi
? cfi
->dw_cfi_opc
: DW_CFA_nop
)
3457 case DW_CFA_advance_loc
:
3458 case DW_CFA_advance_loc1
:
3459 case DW_CFA_advance_loc2
:
3460 case DW_CFA_advance_loc4
:
3461 case DW_CFA_MIPS_advance_loc8
:
3462 case DW_CFA_set_loc
:
3463 /* All advances should be ignored. */
3465 case DW_CFA_remember_state
:
3467 dw_cfi_ref args_size
= cfi_args_size
;
3469 /* Skip everything between .cfi_remember_state and
3470 .cfi_restore_state. */
3471 for (cfi2
= cfi
->dw_cfi_next
; cfi2
; cfi2
= cfi2
->dw_cfi_next
)
3472 if (cfi2
->dw_cfi_opc
== DW_CFA_restore_state
)
3474 else if (cfi2
->dw_cfi_opc
== DW_CFA_GNU_args_size
)
3477 gcc_assert (cfi2
->dw_cfi_opc
!= DW_CFA_remember_state
);
3484 cfi_args_size
= args_size
;
3488 case DW_CFA_GNU_args_size
:
3489 cfi_args_size
= cfi
;
3491 case DW_CFA_GNU_window_save
:
3494 case DW_CFA_offset_extended
:
3495 case DW_CFA_offset_extended_sf
:
3496 case DW_CFA_restore
:
3497 case DW_CFA_restore_extended
:
3498 case DW_CFA_undefined
:
3499 case DW_CFA_same_value
:
3500 case DW_CFA_register
:
3501 case DW_CFA_val_offset
:
3502 case DW_CFA_val_offset_sf
:
3503 case DW_CFA_expression
:
3504 case DW_CFA_val_expression
:
3505 case DW_CFA_GNU_negative_offset_extended
:
3506 if (VEC_length (dw_cfi_ref
, regs
) <= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
)
3507 VEC_safe_grow_cleared (dw_cfi_ref
, heap
, regs
,
3508 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
+ 1);
3509 VEC_replace (dw_cfi_ref
, regs
, cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, cfi
);
3511 case DW_CFA_def_cfa
:
3512 case DW_CFA_def_cfa_sf
:
3513 case DW_CFA_def_cfa_expression
:
3515 cfi_cfa_offset
= cfi
;
3517 case DW_CFA_def_cfa_register
:
3520 case DW_CFA_def_cfa_offset
:
3521 case DW_CFA_def_cfa_offset_sf
:
3522 cfi_cfa_offset
= cfi
;
3525 gcc_assert (cfi
== NULL
);
3527 len
= VEC_length (dw_cfi_ref
, regs
);
3528 for (idx
= 0; idx
< len
; idx
++)
3530 cfi2
= VEC_replace (dw_cfi_ref
, regs
, idx
, NULL
);
3532 && cfi2
->dw_cfi_opc
!= DW_CFA_restore
3533 && cfi2
->dw_cfi_opc
!= DW_CFA_restore_extended
)
3536 output_cfi_directive (cfi2
);
3538 output_cfi (cfi2
, fde
, for_eh
);
3541 if (cfi_cfa
&& cfi_cfa_offset
&& cfi_cfa_offset
!= cfi_cfa
)
3543 gcc_assert (cfi_cfa
->dw_cfi_opc
!= DW_CFA_def_cfa_expression
);
3545 switch (cfi_cfa_offset
->dw_cfi_opc
)
3547 case DW_CFA_def_cfa_offset
:
3548 cfi_buf
.dw_cfi_opc
= DW_CFA_def_cfa
;
3549 cfi_buf
.dw_cfi_oprnd2
= cfi_cfa_offset
->dw_cfi_oprnd1
;
3551 case DW_CFA_def_cfa_offset_sf
:
3552 cfi_buf
.dw_cfi_opc
= DW_CFA_def_cfa_sf
;
3553 cfi_buf
.dw_cfi_oprnd2
= cfi_cfa_offset
->dw_cfi_oprnd1
;
3555 case DW_CFA_def_cfa
:
3556 case DW_CFA_def_cfa_sf
:
3557 cfi_buf
.dw_cfi_opc
= cfi_cfa_offset
->dw_cfi_opc
;
3558 cfi_buf
.dw_cfi_oprnd2
= cfi_cfa_offset
->dw_cfi_oprnd2
;
3565 else if (cfi_cfa_offset
)
3566 cfi_cfa
= cfi_cfa_offset
;
3570 output_cfi_directive (cfi_cfa
);
3572 output_cfi (cfi_cfa
, fde
, for_eh
);
3575 cfi_cfa_offset
= NULL
;
3577 && cfi_args_size
->dw_cfi_oprnd1
.dw_cfi_offset
)
3580 output_cfi_directive (cfi_args_size
);
3582 output_cfi (cfi_args_size
, fde
, for_eh
);
3584 cfi_args_size
= NULL
;
3587 VEC_free (dw_cfi_ref
, heap
, regs
);
3590 else if (do_cfi_asm
)
3591 output_cfi_directive (cfi
);
3593 output_cfi (cfi
, fde
, for_eh
);
3600 /* Output one FDE. */
3603 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
3604 char *section_start_label
, int fde_encoding
, char *augmentation
,
3605 bool any_lsda_needed
, int lsda_encoding
)
3607 const char *begin
, *end
;
3608 static unsigned int j
;
3609 char l1
[20], l2
[20];
3612 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
3614 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
3616 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
3617 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
3618 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
3619 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3620 " indicating 64-bit DWARF extension");
3621 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
3623 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
3626 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
3628 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
3629 debug_frame_section
, "FDE CIE offset");
3631 if (!fde
->dw_fde_switched_sections
)
3633 begin
= fde
->dw_fde_begin
;
3634 end
= fde
->dw_fde_end
;
3638 /* For the first section, prefer dw_fde_begin over
3639 dw_fde_{hot,cold}_section_label, as the latter
3640 might be separated from the real start of the
3641 function by alignment padding. */
3643 begin
= fde
->dw_fde_begin
;
3644 else if (fde
->dw_fde_switched_cold_to_hot
)
3645 begin
= fde
->dw_fde_hot_section_label
;
3647 begin
= fde
->dw_fde_unlikely_section_label
;
3648 if (second
^ fde
->dw_fde_switched_cold_to_hot
)
3649 end
= fde
->dw_fde_unlikely_section_end_label
;
3651 end
= fde
->dw_fde_hot_section_end_label
;
3656 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
3657 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
3658 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
3659 "FDE initial location");
3660 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
3661 end
, begin
, "FDE address range");
3665 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
3666 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
3669 if (augmentation
[0])
3671 if (any_lsda_needed
)
3673 int size
= size_of_encoded_value (lsda_encoding
);
3675 if (lsda_encoding
== DW_EH_PE_aligned
)
3677 int offset
= ( 4 /* Length */
3678 + 4 /* CIE offset */
3679 + 2 * size_of_encoded_value (fde_encoding
)
3680 + 1 /* Augmentation size */ );
3681 int pad
= -offset
& (PTR_SIZE
- 1);
3684 gcc_assert (size_of_uleb128 (size
) == 1);
3687 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
3689 if (fde
->uses_eh_lsda
)
3691 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
3692 fde
->funcdef_number
);
3693 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
3694 gen_rtx_SYMBOL_REF (Pmode
, l1
),
3696 "Language Specific Data Area");
3700 if (lsda_encoding
== DW_EH_PE_aligned
)
3701 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
3702 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
3703 "Language Specific Data Area (none)");
3707 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3710 /* Loop through the Call Frame Instructions associated with
3712 fde
->dw_fde_current_label
= begin
;
3713 if (!fde
->dw_fde_switched_sections
)
3714 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
3715 output_cfi (cfi
, fde
, for_eh
);
3718 if (fde
->dw_fde_switch_cfi
)
3719 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
3721 output_cfi (cfi
, fde
, for_eh
);
3722 if (cfi
== fde
->dw_fde_switch_cfi
)
3728 dw_cfi_ref cfi_next
= fde
->dw_fde_cfi
;
3730 if (fde
->dw_fde_switch_cfi
)
3732 cfi_next
= fde
->dw_fde_switch_cfi
->dw_cfi_next
;
3733 fde
->dw_fde_switch_cfi
->dw_cfi_next
= NULL
;
3734 output_cfis (fde
->dw_fde_cfi
, false, fde
, for_eh
);
3735 fde
->dw_fde_switch_cfi
->dw_cfi_next
= cfi_next
;
3737 for (cfi
= cfi_next
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
3738 output_cfi (cfi
, fde
, for_eh
);
3741 /* If we are to emit a ref/link from function bodies to their frame tables,
3742 do it now. This is typically performed to make sure that tables
3743 associated with functions are dragged with them and not discarded in
3744 garbage collecting links. We need to do this on a per function basis to
3745 cope with -ffunction-sections. */
3747 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3748 /* Switch to the function section, emit the ref to the tables, and
3749 switch *back* into the table section. */
3750 switch_to_section (function_section (fde
->decl
));
3751 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
3752 switch_to_frame_table_section (for_eh
, true);
3755 /* Pad the FDE out to an address sized boundary. */
3756 ASM_OUTPUT_ALIGN (asm_out_file
,
3757 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
3758 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
3763 /* Return true if frame description entry FDE is needed for EH. */
3766 fde_needed_for_eh_p (dw_fde_ref fde
)
3768 if (flag_asynchronous_unwind_tables
)
3771 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
3774 if (fde
->uses_eh_lsda
)
3777 /* If exceptions are enabled, we have collected nothrow info. */
3778 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
3784 /* Output the call frame information used to record information
3785 that relates to calculating the frame pointer, and records the
3786 location of saved registers. */
3789 output_call_frame_info (int for_eh
)
3794 char l1
[20], l2
[20], section_start_label
[20];
3795 bool any_lsda_needed
= false;
3796 char augmentation
[6];
3797 int augmentation_size
;
3798 int fde_encoding
= DW_EH_PE_absptr
;
3799 int per_encoding
= DW_EH_PE_absptr
;
3800 int lsda_encoding
= DW_EH_PE_absptr
;
3802 rtx personality
= NULL
;
3805 /* Don't emit a CIE if there won't be any FDEs. */
3806 if (fde_table_in_use
== 0)
3809 /* Nothing to do if the assembler's doing it all. */
3810 if (dwarf2out_do_cfi_asm ())
3813 /* If we don't have any functions we'll want to unwind out of, don't emit
3814 any EH unwind information. If we make FDEs linkonce, we may have to
3815 emit an empty label for an FDE that wouldn't otherwise be emitted. We
3816 want to avoid having an FDE kept around when the function it refers to
3817 is discarded. Example where this matters: a primary function template
3818 in C++ requires EH information, an explicit specialization doesn't. */
3821 bool any_eh_needed
= false;
3823 for (i
= 0; i
< fde_table_in_use
; i
++)
3824 if (fde_table
[i
].uses_eh_lsda
)
3825 any_eh_needed
= any_lsda_needed
= true;
3826 else if (fde_needed_for_eh_p (&fde_table
[i
]))
3827 any_eh_needed
= true;
3828 else if (TARGET_USES_WEAK_UNWIND_INFO
)
3829 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde_table
[i
].decl
,
3836 /* We're going to be generating comments, so turn on app. */
3840 /* Switch to the proper frame section, first time. */
3841 switch_to_frame_table_section (for_eh
, false);
3843 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
3844 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
3846 /* Output the CIE. */
3847 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
3848 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
3849 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
3850 dw2_asm_output_data (4, 0xffffffff,
3851 "Initial length escape value indicating 64-bit DWARF extension");
3852 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
3853 "Length of Common Information Entry");
3854 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
3856 /* Now that the CIE pointer is PC-relative for EH,
3857 use 0 to identify the CIE. */
3858 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
3859 (for_eh
? 0 : DWARF_CIE_ID
),
3860 "CIE Identifier Tag");
3862 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3863 use CIE version 1, unless that would produce incorrect results
3864 due to overflowing the return register column. */
3865 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
3867 if (return_reg
>= 256 || dwarf_version
> 2)
3869 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
3871 augmentation
[0] = 0;
3872 augmentation_size
= 0;
3874 personality
= current_unit_personality
;
3880 z Indicates that a uleb128 is present to size the
3881 augmentation section.
3882 L Indicates the encoding (and thus presence) of
3883 an LSDA pointer in the FDE augmentation.
3884 R Indicates a non-default pointer encoding for
3886 P Indicates the presence of an encoding + language
3887 personality routine in the CIE augmentation. */
3889 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3890 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3891 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3893 p
= augmentation
+ 1;
3897 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
3898 assemble_external_libcall (personality
);
3900 if (any_lsda_needed
)
3903 augmentation_size
+= 1;
3905 if (fde_encoding
!= DW_EH_PE_absptr
)
3908 augmentation_size
+= 1;
3910 if (p
> augmentation
+ 1)
3912 augmentation
[0] = 'z';
3916 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3917 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
3919 int offset
= ( 4 /* Length */
3921 + 1 /* CIE version */
3922 + strlen (augmentation
) + 1 /* Augmentation */
3923 + size_of_uleb128 (1) /* Code alignment */
3924 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
3926 + 1 /* Augmentation size */
3927 + 1 /* Personality encoding */ );
3928 int pad
= -offset
& (PTR_SIZE
- 1);
3930 augmentation_size
+= pad
;
3932 /* Augmentations should be small, so there's scarce need to
3933 iterate for a solution. Die if we exceed one uleb128 byte. */
3934 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
3938 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
3939 if (dw_cie_version
>= 4)
3941 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
3942 dw2_asm_output_data (1, 0, "CIE Segment Size");
3944 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3945 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
3946 "CIE Data Alignment Factor");
3948 if (dw_cie_version
== 1)
3949 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
3951 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
3953 if (augmentation
[0])
3955 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
3958 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
3959 eh_data_format_name (per_encoding
));
3960 dw2_asm_output_encoded_addr_rtx (per_encoding
,
3965 if (any_lsda_needed
)
3966 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
3967 eh_data_format_name (lsda_encoding
));
3969 if (fde_encoding
!= DW_EH_PE_absptr
)
3970 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
3971 eh_data_format_name (fde_encoding
));
3974 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
3975 output_cfi (cfi
, NULL
, for_eh
);
3977 /* Pad the CIE out to an address sized boundary. */
3978 ASM_OUTPUT_ALIGN (asm_out_file
,
3979 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
3980 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
3982 /* Loop through all of the FDE's. */
3983 for (i
= 0; i
< fde_table_in_use
; i
++)
3986 fde
= &fde_table
[i
];
3988 /* Don't emit EH unwind info for leaf functions that don't need it. */
3989 if (for_eh
&& !fde_needed_for_eh_p (fde
))
3992 for (k
= 0; k
< (fde
->dw_fde_switched_sections
? 2 : 1); k
++)
3993 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
3994 augmentation
, any_lsda_needed
, lsda_encoding
);
3997 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
3998 dw2_asm_output_data (4, 0, "End of Table");
3999 #ifdef MIPS_DEBUGGING_INFO
4000 /* Work around Irix 6 assembler bug whereby labels at the end of a section
4001 get a value of 0. Putting .align 0 after the label fixes it. */
4002 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
4005 /* Turn off app to make assembly quicker. */
4010 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
4013 dwarf2out_do_cfi_startproc (bool second
)
4017 rtx personality
= get_personality_function (current_function_decl
);
4019 fprintf (asm_out_file
, "\t.cfi_startproc\n");
4023 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
4026 /* ??? The GAS support isn't entirely consistent. We have to
4027 handle indirect support ourselves, but PC-relative is done
4028 in the assembler. Further, the assembler can't handle any
4029 of the weirder relocation types. */
4030 if (enc
& DW_EH_PE_indirect
)
4031 ref
= dw2_force_const_mem (ref
, true);
4033 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
4034 output_addr_const (asm_out_file
, ref
);
4035 fputc ('\n', asm_out_file
);
4038 if (crtl
->uses_eh_lsda
)
4042 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
4043 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
4044 current_function_funcdef_no
);
4045 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
4046 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
4048 if (enc
& DW_EH_PE_indirect
)
4049 ref
= dw2_force_const_mem (ref
, true);
4051 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
4052 output_addr_const (asm_out_file
, ref
);
4053 fputc ('\n', asm_out_file
);
4057 /* Output a marker (i.e. a label) for the beginning of a function, before
4061 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
4062 const char *file ATTRIBUTE_UNUSED
)
4064 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4070 current_function_func_begin_label
= NULL
;
4072 do_frame
= dwarf2out_do_frame ();
4074 /* ??? current_function_func_begin_label is also used by except.c for
4075 call-site information. We must emit this label if it might be used. */
4077 && (!flag_exceptions
4078 || targetm
.except_unwind_info (&global_options
) != UI_TARGET
))
4081 fnsec
= function_section (current_function_decl
);
4082 switch_to_section (fnsec
);
4083 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
4084 current_function_funcdef_no
);
4085 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
4086 current_function_funcdef_no
);
4087 dup_label
= xstrdup (label
);
4088 current_function_func_begin_label
= dup_label
;
4090 /* We can elide the fde allocation if we're not emitting debug info. */
4094 /* Expand the fde table if necessary. */
4095 if (fde_table_in_use
== fde_table_allocated
)
4097 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
4098 fde_table
= GGC_RESIZEVEC (dw_fde_node
, fde_table
, fde_table_allocated
);
4099 memset (fde_table
+ fde_table_in_use
, 0,
4100 FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
4103 /* Record the FDE associated with this function. */
4104 current_funcdef_fde
= fde_table_in_use
;
4106 /* Add the new FDE at the end of the fde_table. */
4107 fde
= &fde_table
[fde_table_in_use
++];
4108 fde
->decl
= current_function_decl
;
4109 fde
->dw_fde_begin
= dup_label
;
4110 fde
->dw_fde_current_label
= dup_label
;
4111 fde
->dw_fde_hot_section_label
= NULL
;
4112 fde
->dw_fde_hot_section_end_label
= NULL
;
4113 fde
->dw_fde_unlikely_section_label
= NULL
;
4114 fde
->dw_fde_unlikely_section_end_label
= NULL
;
4115 fde
->dw_fde_switched_sections
= 0;
4116 fde
->dw_fde_switched_cold_to_hot
= 0;
4117 fde
->dw_fde_end
= NULL
;
4118 fde
->dw_fde_vms_end_prologue
= NULL
;
4119 fde
->dw_fde_vms_begin_epilogue
= NULL
;
4120 fde
->dw_fde_cfi
= NULL
;
4121 fde
->dw_fde_switch_cfi
= NULL
;
4122 fde
->funcdef_number
= current_function_funcdef_no
;
4123 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
4124 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
4125 fde
->nothrow
= crtl
->nothrow
;
4126 fde
->drap_reg
= INVALID_REGNUM
;
4127 fde
->vdrap_reg
= INVALID_REGNUM
;
4128 if (flag_reorder_blocks_and_partition
)
4130 section
*unlikelysec
;
4131 if (first_function_block_is_cold
)
4132 fde
->in_std_section
= 1;
4135 = (fnsec
== text_section
4136 || (cold_text_section
&& fnsec
== cold_text_section
));
4137 unlikelysec
= unlikely_text_section ();
4138 fde
->cold_in_std_section
4139 = (unlikelysec
== text_section
4140 || (cold_text_section
&& unlikelysec
== cold_text_section
));
4145 = (fnsec
== text_section
4146 || (cold_text_section
&& fnsec
== cold_text_section
));
4147 fde
->cold_in_std_section
= 0;
4150 args_size
= old_args_size
= 0;
4152 /* We only want to output line number information for the genuine dwarf2
4153 prologue case, not the eh frame case. */
4154 #ifdef DWARF2_DEBUGGING_INFO
4156 dwarf2out_source_line (line
, file
, 0, true);
4159 if (dwarf2out_do_cfi_asm ())
4160 dwarf2out_do_cfi_startproc (false);
4163 rtx personality
= get_personality_function (current_function_decl
);
4164 if (!current_unit_personality
)
4165 current_unit_personality
= personality
;
4167 /* We cannot keep a current personality per function as without CFI
4168 asm, at the point where we emit the CFI data, there is no current
4169 function anymore. */
4170 if (personality
&& current_unit_personality
!= personality
)
4171 sorry ("multiple EH personalities are supported only with assemblers "
4172 "supporting .cfi_personality directive");
4176 /* Output a marker (i.e. a label) for the end of the generated code
4177 for a function prologue. This gets called *after* the prologue code has
4181 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
4182 const char *file ATTRIBUTE_UNUSED
)
4185 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4187 /* Output a label to mark the endpoint of the code generated for this
4189 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
4190 current_function_funcdef_no
);
4191 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
4192 current_function_funcdef_no
);
4193 fde
= &fde_table
[fde_table_in_use
- 1];
4194 fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
4197 /* Output a marker (i.e. a label) for the beginning of the generated code
4198 for a function epilogue. This gets called *before* the prologue code has
4202 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
4203 const char *file ATTRIBUTE_UNUSED
)
4206 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4208 fde
= &fde_table
[fde_table_in_use
- 1];
4209 if (fde
->dw_fde_vms_begin_epilogue
)
4212 /* Output a label to mark the endpoint of the code generated for this
4214 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
4215 current_function_funcdef_no
);
4216 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
4217 current_function_funcdef_no
);
4218 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
4221 /* Output a marker (i.e. a label) for the absolute end of the generated code
4222 for a function definition. This gets called *after* the epilogue code has
4226 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
4227 const char *file ATTRIBUTE_UNUSED
)
4230 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4232 last_var_location_insn
= NULL_RTX
;
4234 if (dwarf2out_do_cfi_asm ())
4235 fprintf (asm_out_file
, "\t.cfi_endproc\n");
4237 /* Output a label to mark the endpoint of the code generated for this
4239 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
4240 current_function_funcdef_no
);
4241 ASM_OUTPUT_LABEL (asm_out_file
, label
);
4242 fde
= current_fde ();
4243 gcc_assert (fde
!= NULL
);
4244 fde
->dw_fde_end
= xstrdup (label
);
4248 dwarf2out_frame_init (void)
4250 /* Allocate the initial hunk of the fde_table. */
4251 fde_table
= ggc_alloc_cleared_vec_dw_fde_node (FDE_TABLE_INCREMENT
);
4252 fde_table_allocated
= FDE_TABLE_INCREMENT
;
4253 fde_table_in_use
= 0;
4255 /* Generate the CFA instructions common to all FDE's. Do it now for the
4256 sake of lookup_cfa. */
4258 /* On entry, the Canonical Frame Address is at SP. */
4259 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
4261 if (targetm
.debug_unwind_info () == UI_DWARF2
4262 || targetm
.except_unwind_info (&global_options
) == UI_DWARF2
)
4263 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
4267 dwarf2out_frame_finish (void)
4269 /* Output call frame information. */
4270 if (targetm
.debug_unwind_info () == UI_DWARF2
)
4271 output_call_frame_info (0);
4273 /* Output another copy for the unwinder. */
4274 if ((flag_unwind_tables
|| flag_exceptions
)
4275 && targetm
.except_unwind_info (&global_options
) == UI_DWARF2
)
4276 output_call_frame_info (1);
4279 /* Note that the current function section is being used for code. */
4282 dwarf2out_note_section_used (void)
4284 section
*sec
= current_function_section ();
4285 if (sec
== text_section
)
4286 text_section_used
= true;
4287 else if (sec
== cold_text_section
)
4288 cold_text_section_used
= true;
4292 dwarf2out_switch_text_section (void)
4294 dw_fde_ref fde
= current_fde ();
4296 gcc_assert (cfun
&& fde
&& !fde
->dw_fde_switched_sections
);
4298 fde
->dw_fde_switched_sections
= 1;
4299 fde
->dw_fde_switched_cold_to_hot
= !in_cold_section_p
;
4301 fde
->dw_fde_hot_section_label
= crtl
->subsections
.hot_section_label
;
4302 fde
->dw_fde_hot_section_end_label
= crtl
->subsections
.hot_section_end_label
;
4303 fde
->dw_fde_unlikely_section_label
= crtl
->subsections
.cold_section_label
;
4304 fde
->dw_fde_unlikely_section_end_label
= crtl
->subsections
.cold_section_end_label
;
4305 have_multiple_function_sections
= true;
4307 /* Reset the current label on switching text sections, so that we
4308 don't attempt to advance_loc4 between labels in different sections. */
4309 fde
->dw_fde_current_label
= NULL
;
4311 /* There is no need to mark used sections when not debugging. */
4312 if (cold_text_section
!= NULL
)
4313 dwarf2out_note_section_used ();
4315 if (dwarf2out_do_cfi_asm ())
4316 fprintf (asm_out_file
, "\t.cfi_endproc\n");
4318 /* Now do the real section switch. */
4319 switch_to_section (current_function_section ());
4321 if (dwarf2out_do_cfi_asm ())
4323 dwarf2out_do_cfi_startproc (true);
4324 /* As this is a different FDE, insert all current CFI instructions
4326 output_cfis (fde
->dw_fde_cfi
, true, fde
, true);
4330 dw_cfi_ref cfi
= fde
->dw_fde_cfi
;
4332 cfi
= fde
->dw_fde_cfi
;
4334 while (cfi
->dw_cfi_next
!= NULL
)
4335 cfi
= cfi
->dw_cfi_next
;
4336 fde
->dw_fde_switch_cfi
= cfi
;
4340 /* And now, the subset of the debugging information support code necessary
4341 for emitting location expressions. */
4343 /* Data about a single source file. */
4344 struct GTY(()) dwarf_file_data
{
4345 const char * filename
;
4349 typedef struct dw_val_struct
*dw_val_ref
;
4350 typedef struct die_struct
*dw_die_ref
;
4351 typedef const struct die_struct
*const_dw_die_ref
;
4352 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
4353 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
4355 typedef struct GTY(()) deferred_locations_struct
4359 } deferred_locations
;
4361 DEF_VEC_O(deferred_locations
);
4362 DEF_VEC_ALLOC_O(deferred_locations
,gc
);
4364 static GTY(()) VEC(deferred_locations
, gc
) *deferred_locations_list
;
4366 DEF_VEC_P(dw_die_ref
);
4367 DEF_VEC_ALLOC_P(dw_die_ref
,heap
);
4369 /* Each DIE may have a series of attribute/value pairs. Values
4370 can take on several forms. The forms that are used in this
4371 implementation are listed below. */
4376 dw_val_class_offset
,
4378 dw_val_class_loc_list
,
4379 dw_val_class_range_list
,
4381 dw_val_class_unsigned_const
,
4382 dw_val_class_const_double
,
4385 dw_val_class_die_ref
,
4386 dw_val_class_fde_ref
,
4387 dw_val_class_lbl_id
,
4388 dw_val_class_lineptr
,
4390 dw_val_class_macptr
,
4393 dw_val_class_decl_ref
,
4394 dw_val_class_vms_delta
4397 /* Describe a floating point constant value, or a vector constant value. */
4399 typedef struct GTY(()) dw_vec_struct
{
4400 unsigned char * GTY((length ("%h.length"))) array
;
4406 /* The dw_val_node describes an attribute's value, as it is
4407 represented internally. */
4409 typedef struct GTY(()) dw_val_struct
{
4410 enum dw_val_class val_class
;
4411 union dw_val_struct_union
4413 rtx
GTY ((tag ("dw_val_class_addr"))) val_addr
;
4414 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_offset"))) val_offset
;
4415 dw_loc_list_ref
GTY ((tag ("dw_val_class_loc_list"))) val_loc_list
;
4416 dw_loc_descr_ref
GTY ((tag ("dw_val_class_loc"))) val_loc
;
4417 HOST_WIDE_INT
GTY ((default)) val_int
;
4418 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned
;
4419 double_int
GTY ((tag ("dw_val_class_const_double"))) val_double
;
4420 dw_vec_const
GTY ((tag ("dw_val_class_vec"))) val_vec
;
4421 struct dw_val_die_union
4425 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref
;
4426 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index
;
4427 struct indirect_string_node
* GTY ((tag ("dw_val_class_str"))) val_str
;
4428 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id
;
4429 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag
;
4430 struct dwarf_file_data
* GTY ((tag ("dw_val_class_file"))) val_file
;
4431 unsigned char GTY ((tag ("dw_val_class_data8"))) val_data8
[8];
4432 tree
GTY ((tag ("dw_val_class_decl_ref"))) val_decl_ref
;
4433 struct dw_val_vms_delta_union
4437 } GTY ((tag ("dw_val_class_vms_delta"))) val_vms_delta
;
4439 GTY ((desc ("%1.val_class"))) v
;
4443 /* Locations in memory are described using a sequence of stack machine
4446 typedef struct GTY(()) dw_loc_descr_struct
{
4447 dw_loc_descr_ref dw_loc_next
;
4448 ENUM_BITFIELD (dwarf_location_atom
) dw_loc_opc
: 8;
4449 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4450 from DW_OP_addr with a dtp-relative symbol relocation. */
4451 unsigned int dtprel
: 1;
4453 dw_val_node dw_loc_oprnd1
;
4454 dw_val_node dw_loc_oprnd2
;
4458 /* Location lists are ranges + location descriptions for that range,
4459 so you can track variables that are in different places over
4460 their entire life. */
4461 typedef struct GTY(()) dw_loc_list_struct
{
4462 dw_loc_list_ref dw_loc_next
;
4463 const char *begin
; /* Label for begin address of range */
4464 const char *end
; /* Label for end address of range */
4465 char *ll_symbol
; /* Label for beginning of location list.
4466 Only on head of list */
4467 const char *section
; /* Section this loclist is relative to */
4468 dw_loc_descr_ref expr
;
4473 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
4475 /* Convert a DWARF stack opcode into its string name. */
4478 dwarf_stack_op_name (unsigned int op
)
4483 return "DW_OP_addr";
4485 return "DW_OP_deref";
4487 return "DW_OP_const1u";
4489 return "DW_OP_const1s";
4491 return "DW_OP_const2u";
4493 return "DW_OP_const2s";
4495 return "DW_OP_const4u";
4497 return "DW_OP_const4s";
4499 return "DW_OP_const8u";
4501 return "DW_OP_const8s";
4503 return "DW_OP_constu";
4505 return "DW_OP_consts";
4509 return "DW_OP_drop";
4511 return "DW_OP_over";
4513 return "DW_OP_pick";
4515 return "DW_OP_swap";
4519 return "DW_OP_xderef";
4527 return "DW_OP_minus";
4539 return "DW_OP_plus";
4540 case DW_OP_plus_uconst
:
4541 return "DW_OP_plus_uconst";
4547 return "DW_OP_shra";
4565 return "DW_OP_skip";
4567 return "DW_OP_lit0";
4569 return "DW_OP_lit1";
4571 return "DW_OP_lit2";
4573 return "DW_OP_lit3";
4575 return "DW_OP_lit4";
4577 return "DW_OP_lit5";
4579 return "DW_OP_lit6";
4581 return "DW_OP_lit7";
4583 return "DW_OP_lit8";
4585 return "DW_OP_lit9";
4587 return "DW_OP_lit10";
4589 return "DW_OP_lit11";
4591 return "DW_OP_lit12";
4593 return "DW_OP_lit13";
4595 return "DW_OP_lit14";
4597 return "DW_OP_lit15";
4599 return "DW_OP_lit16";
4601 return "DW_OP_lit17";
4603 return "DW_OP_lit18";
4605 return "DW_OP_lit19";
4607 return "DW_OP_lit20";
4609 return "DW_OP_lit21";
4611 return "DW_OP_lit22";
4613 return "DW_OP_lit23";
4615 return "DW_OP_lit24";
4617 return "DW_OP_lit25";
4619 return "DW_OP_lit26";
4621 return "DW_OP_lit27";
4623 return "DW_OP_lit28";
4625 return "DW_OP_lit29";
4627 return "DW_OP_lit30";
4629 return "DW_OP_lit31";
4631 return "DW_OP_reg0";
4633 return "DW_OP_reg1";
4635 return "DW_OP_reg2";
4637 return "DW_OP_reg3";
4639 return "DW_OP_reg4";
4641 return "DW_OP_reg5";
4643 return "DW_OP_reg6";
4645 return "DW_OP_reg7";
4647 return "DW_OP_reg8";
4649 return "DW_OP_reg9";
4651 return "DW_OP_reg10";
4653 return "DW_OP_reg11";
4655 return "DW_OP_reg12";
4657 return "DW_OP_reg13";
4659 return "DW_OP_reg14";
4661 return "DW_OP_reg15";
4663 return "DW_OP_reg16";
4665 return "DW_OP_reg17";
4667 return "DW_OP_reg18";
4669 return "DW_OP_reg19";
4671 return "DW_OP_reg20";
4673 return "DW_OP_reg21";
4675 return "DW_OP_reg22";
4677 return "DW_OP_reg23";
4679 return "DW_OP_reg24";
4681 return "DW_OP_reg25";
4683 return "DW_OP_reg26";
4685 return "DW_OP_reg27";
4687 return "DW_OP_reg28";
4689 return "DW_OP_reg29";
4691 return "DW_OP_reg30";
4693 return "DW_OP_reg31";
4695 return "DW_OP_breg0";
4697 return "DW_OP_breg1";
4699 return "DW_OP_breg2";
4701 return "DW_OP_breg3";
4703 return "DW_OP_breg4";
4705 return "DW_OP_breg5";
4707 return "DW_OP_breg6";
4709 return "DW_OP_breg7";
4711 return "DW_OP_breg8";
4713 return "DW_OP_breg9";
4715 return "DW_OP_breg10";
4717 return "DW_OP_breg11";
4719 return "DW_OP_breg12";
4721 return "DW_OP_breg13";
4723 return "DW_OP_breg14";
4725 return "DW_OP_breg15";
4727 return "DW_OP_breg16";
4729 return "DW_OP_breg17";
4731 return "DW_OP_breg18";
4733 return "DW_OP_breg19";
4735 return "DW_OP_breg20";
4737 return "DW_OP_breg21";
4739 return "DW_OP_breg22";
4741 return "DW_OP_breg23";
4743 return "DW_OP_breg24";
4745 return "DW_OP_breg25";
4747 return "DW_OP_breg26";
4749 return "DW_OP_breg27";
4751 return "DW_OP_breg28";
4753 return "DW_OP_breg29";
4755 return "DW_OP_breg30";
4757 return "DW_OP_breg31";
4759 return "DW_OP_regx";
4761 return "DW_OP_fbreg";
4763 return "DW_OP_bregx";
4765 return "DW_OP_piece";
4766 case DW_OP_deref_size
:
4767 return "DW_OP_deref_size";
4768 case DW_OP_xderef_size
:
4769 return "DW_OP_xderef_size";
4773 case DW_OP_push_object_address
:
4774 return "DW_OP_push_object_address";
4776 return "DW_OP_call2";
4778 return "DW_OP_call4";
4779 case DW_OP_call_ref
:
4780 return "DW_OP_call_ref";
4781 case DW_OP_implicit_value
:
4782 return "DW_OP_implicit_value";
4783 case DW_OP_stack_value
:
4784 return "DW_OP_stack_value";
4785 case DW_OP_form_tls_address
:
4786 return "DW_OP_form_tls_address";
4787 case DW_OP_call_frame_cfa
:
4788 return "DW_OP_call_frame_cfa";
4789 case DW_OP_bit_piece
:
4790 return "DW_OP_bit_piece";
4792 case DW_OP_GNU_push_tls_address
:
4793 return "DW_OP_GNU_push_tls_address";
4794 case DW_OP_GNU_uninit
:
4795 return "DW_OP_GNU_uninit";
4796 case DW_OP_GNU_encoded_addr
:
4797 return "DW_OP_GNU_encoded_addr";
4798 case DW_OP_GNU_implicit_pointer
:
4799 return "DW_OP_GNU_implicit_pointer";
4800 case DW_OP_GNU_entry_value
:
4801 return "DW_OP_GNU_entry_value";
4804 return "OP_<unknown>";
4808 /* Return a pointer to a newly allocated location description. Location
4809 descriptions are simple expression terms that can be strung
4810 together to form more complicated location (address) descriptions. */
4812 static inline dw_loc_descr_ref
4813 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
4814 unsigned HOST_WIDE_INT oprnd2
)
4816 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
4818 descr
->dw_loc_opc
= op
;
4819 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
4820 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
4821 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
4822 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
4827 /* Return a pointer to a newly allocated location description for
4830 static inline dw_loc_descr_ref
4831 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
4834 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
4837 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
4840 /* Add a location description term to a location description expression. */
4843 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
4845 dw_loc_descr_ref
*d
;
4847 /* Find the end of the chain. */
4848 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
4854 /* Add a constant OFFSET to a location expression. */
4857 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
4859 dw_loc_descr_ref loc
;
4862 gcc_assert (*list_head
!= NULL
);
4867 /* Find the end of the chain. */
4868 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
4872 if (loc
->dw_loc_opc
== DW_OP_fbreg
4873 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
4874 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
4875 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
4876 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
4878 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4879 offset. Don't optimize if an signed integer overflow would happen. */
4881 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
4882 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
4885 else if (offset
> 0)
4886 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
4890 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
4891 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
4895 /* Add a constant OFFSET to a location list. */
4898 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
4901 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
4902 loc_descr_plus_const (&d
->expr
, offset
);
4905 #define DWARF_REF_SIZE \
4906 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
4908 static unsigned long size_of_locs (dw_loc_descr_ref
);
4910 /* Return the size of a location descriptor. */
4912 static unsigned long
4913 size_of_loc_descr (dw_loc_descr_ref loc
)
4915 unsigned long size
= 1;
4917 switch (loc
->dw_loc_opc
)
4920 size
+= DWARF2_ADDR_SIZE
;
4939 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4942 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4947 case DW_OP_plus_uconst
:
4948 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4986 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4989 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4992 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4995 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4996 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
4999 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5001 case DW_OP_bit_piece
:
5002 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5003 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
5005 case DW_OP_deref_size
:
5006 case DW_OP_xderef_size
:
5015 case DW_OP_call_ref
:
5016 size
+= DWARF_REF_SIZE
;
5018 case DW_OP_implicit_value
:
5019 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
5020 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
5022 case DW_OP_GNU_implicit_pointer
:
5023 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
5025 case DW_OP_GNU_entry_value
:
5027 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
5028 size
+= size_of_uleb128 (op_size
) + op_size
;
5038 /* Return the size of a series of location descriptors. */
5040 static unsigned long
5041 size_of_locs (dw_loc_descr_ref loc
)
5046 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
5047 field, to avoid writing to a PCH file. */
5048 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
5050 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
5052 size
+= size_of_loc_descr (l
);
5057 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
5059 l
->dw_loc_addr
= size
;
5060 size
+= size_of_loc_descr (l
);
5066 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
5067 static void get_ref_die_offset_label (char *, dw_die_ref
);
5068 static void output_loc_sequence (dw_loc_descr_ref
, int);
5070 /* Output location description stack opcode's operands (if any).
5071 The for_eh_or_skip parameter controls whether register numbers are
5072 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5073 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5074 info). This should be suppressed for the cases that have not been converted
5075 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5078 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
5080 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
5081 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
5083 switch (loc
->dw_loc_opc
)
5085 #ifdef DWARF2_DEBUGGING_INFO
5088 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
5093 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
5094 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
5096 fputc ('\n', asm_out_file
);
5101 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
5106 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
5107 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
5109 fputc ('\n', asm_out_file
);
5114 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
5115 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
5122 gcc_assert (val1
->val_class
== dw_val_class_loc
);
5123 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
5125 dw2_asm_output_data (2, offset
, NULL
);
5128 case DW_OP_implicit_value
:
5129 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5130 switch (val2
->val_class
)
5132 case dw_val_class_const
:
5133 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
5135 case dw_val_class_vec
:
5137 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
5138 unsigned int len
= val2
->v
.val_vec
.length
;
5142 if (elt_size
> sizeof (HOST_WIDE_INT
))
5147 for (i
= 0, p
= val2
->v
.val_vec
.array
;
5150 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
5151 "fp or vector constant word %u", i
);
5154 case dw_val_class_const_double
:
5156 unsigned HOST_WIDE_INT first
, second
;
5158 if (WORDS_BIG_ENDIAN
)
5160 first
= val2
->v
.val_double
.high
;
5161 second
= val2
->v
.val_double
.low
;
5165 first
= val2
->v
.val_double
.low
;
5166 second
= val2
->v
.val_double
.high
;
5168 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
5170 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
5174 case dw_val_class_addr
:
5175 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
5176 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
5191 case DW_OP_implicit_value
:
5192 /* We currently don't make any attempt to make sure these are
5193 aligned properly like we do for the main unwind info, so
5194 don't support emitting things larger than a byte if we're
5195 only doing unwinding. */
5200 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
5203 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5206 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
5209 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
5211 case DW_OP_plus_uconst
:
5212 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5246 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
5250 unsigned r
= val1
->v
.val_unsigned
;
5251 if (for_eh_or_skip
>= 0)
5252 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
5253 gcc_assert (size_of_uleb128 (r
)
5254 == size_of_uleb128 (val1
->v
.val_unsigned
));
5255 dw2_asm_output_data_uleb128 (r
, NULL
);
5259 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
5263 unsigned r
= val1
->v
.val_unsigned
;
5264 if (for_eh_or_skip
>= 0)
5265 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
5266 gcc_assert (size_of_uleb128 (r
)
5267 == size_of_uleb128 (val1
->v
.val_unsigned
));
5268 dw2_asm_output_data_uleb128 (r
, NULL
);
5269 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
5273 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5275 case DW_OP_bit_piece
:
5276 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5277 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
5279 case DW_OP_deref_size
:
5280 case DW_OP_xderef_size
:
5281 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
5287 if (targetm
.asm_out
.output_dwarf_dtprel
)
5289 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
5292 fputc ('\n', asm_out_file
);
5299 #ifdef DWARF2_DEBUGGING_INFO
5300 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
5307 case DW_OP_GNU_implicit_pointer
:
5309 char label
[MAX_ARTIFICIAL_LABEL_BYTES
5310 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
5311 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
5312 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
5313 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
5314 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
5318 case DW_OP_GNU_entry_value
:
5319 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
5320 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
5324 /* Other codes have no operands. */
5329 /* Output a sequence of location operations.
5330 The for_eh_or_skip parameter controls whether register numbers are
5331 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5332 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5333 info). This should be suppressed for the cases that have not been converted
5334 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5337 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
5339 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
5341 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
5342 /* Output the opcode. */
5343 if (for_eh_or_skip
>= 0
5344 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
5346 unsigned r
= (opc
- DW_OP_breg0
);
5347 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
5348 gcc_assert (r
<= 31);
5349 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
5351 else if (for_eh_or_skip
>= 0
5352 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
5354 unsigned r
= (opc
- DW_OP_reg0
);
5355 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
5356 gcc_assert (r
<= 31);
5357 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
5360 dw2_asm_output_data (1, opc
,
5361 "%s", dwarf_stack_op_name (opc
));
5363 /* Output the operand(s) (if any). */
5364 output_loc_operands (loc
, for_eh_or_skip
);
5368 /* Output location description stack opcode's operands (if any).
5369 The output is single bytes on a line, suitable for .cfi_escape. */
5372 output_loc_operands_raw (dw_loc_descr_ref loc
)
5374 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
5375 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
5377 switch (loc
->dw_loc_opc
)
5380 case DW_OP_implicit_value
:
5381 /* We cannot output addresses in .cfi_escape, only bytes. */
5387 case DW_OP_deref_size
:
5388 case DW_OP_xderef_size
:
5389 fputc (',', asm_out_file
);
5390 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
5395 fputc (',', asm_out_file
);
5396 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
5401 fputc (',', asm_out_file
);
5402 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
5407 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
5408 fputc (',', asm_out_file
);
5409 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
5417 gcc_assert (val1
->val_class
== dw_val_class_loc
);
5418 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
5420 fputc (',', asm_out_file
);
5421 dw2_asm_output_data_raw (2, offset
);
5427 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
5428 gcc_assert (size_of_uleb128 (r
)
5429 == size_of_uleb128 (val1
->v
.val_unsigned
));
5430 fputc (',', asm_out_file
);
5431 dw2_asm_output_data_uleb128_raw (r
);
5436 case DW_OP_plus_uconst
:
5438 fputc (',', asm_out_file
);
5439 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
5442 case DW_OP_bit_piece
:
5443 fputc (',', asm_out_file
);
5444 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
5445 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
5482 fputc (',', asm_out_file
);
5483 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
5488 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
5489 gcc_assert (size_of_uleb128 (r
)
5490 == size_of_uleb128 (val1
->v
.val_unsigned
));
5491 fputc (',', asm_out_file
);
5492 dw2_asm_output_data_uleb128_raw (r
);
5493 fputc (',', asm_out_file
);
5494 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
5498 case DW_OP_GNU_implicit_pointer
:
5499 case DW_OP_GNU_entry_value
:
5504 /* Other codes have no operands. */
5510 output_loc_sequence_raw (dw_loc_descr_ref loc
)
5514 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
5515 /* Output the opcode. */
5516 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
5518 unsigned r
= (opc
- DW_OP_breg0
);
5519 r
= DWARF2_FRAME_REG_OUT (r
, 1);
5520 gcc_assert (r
<= 31);
5521 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
5523 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
5525 unsigned r
= (opc
- DW_OP_reg0
);
5526 r
= DWARF2_FRAME_REG_OUT (r
, 1);
5527 gcc_assert (r
<= 31);
5528 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
5530 /* Output the opcode. */
5531 fprintf (asm_out_file
, "%#x", opc
);
5532 output_loc_operands_raw (loc
);
5534 if (!loc
->dw_loc_next
)
5536 loc
= loc
->dw_loc_next
;
5538 fputc (',', asm_out_file
);
5542 /* This routine will generate the correct assembly data for a location
5543 description based on a cfi entry with a complex address. */
5546 output_cfa_loc (dw_cfi_ref cfi
, int for_eh
)
5548 dw_loc_descr_ref loc
;
5551 if (cfi
->dw_cfi_opc
== DW_CFA_expression
)
5554 DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
5555 dw2_asm_output_data (1, r
, NULL
);
5556 loc
= cfi
->dw_cfi_oprnd2
.dw_cfi_loc
;
5559 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
5561 /* Output the size of the block. */
5562 size
= size_of_locs (loc
);
5563 dw2_asm_output_data_uleb128 (size
, NULL
);
5565 /* Now output the operations themselves. */
5566 output_loc_sequence (loc
, for_eh
);
5569 /* Similar, but used for .cfi_escape. */
5572 output_cfa_loc_raw (dw_cfi_ref cfi
)
5574 dw_loc_descr_ref loc
;
5577 if (cfi
->dw_cfi_opc
== DW_CFA_expression
)
5580 DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
5581 fprintf (asm_out_file
, "%#x,", r
);
5582 loc
= cfi
->dw_cfi_oprnd2
.dw_cfi_loc
;
5585 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
5587 /* Output the size of the block. */
5588 size
= size_of_locs (loc
);
5589 dw2_asm_output_data_uleb128_raw (size
);
5590 fputc (',', asm_out_file
);
5592 /* Now output the operations themselves. */
5593 output_loc_sequence_raw (loc
);
5596 /* This function builds a dwarf location descriptor sequence from a
5597 dw_cfa_location, adding the given OFFSET to the result of the
5600 static struct dw_loc_descr_struct
*
5601 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
5603 struct dw_loc_descr_struct
*head
, *tmp
;
5605 offset
+= cfa
->offset
;
5609 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
5610 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
5611 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
5612 add_loc_descr (&head
, tmp
);
5615 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
5616 add_loc_descr (&head
, tmp
);
5620 head
= new_reg_loc_descr (cfa
->reg
, offset
);
5625 /* This function builds a dwarf location descriptor sequence for
5626 the address at OFFSET from the CFA when stack is aligned to
5629 static struct dw_loc_descr_struct
*
5630 build_cfa_aligned_loc (HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
5632 struct dw_loc_descr_struct
*head
;
5633 unsigned int dwarf_fp
5634 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
5636 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5637 if (cfa
.reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
.indirect
== 0)
5639 head
= new_reg_loc_descr (dwarf_fp
, 0);
5640 add_loc_descr (&head
, int_loc_descriptor (alignment
));
5641 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
5642 loc_descr_plus_const (&head
, offset
);
5645 head
= new_reg_loc_descr (dwarf_fp
, offset
);
5649 /* This function fills in aa dw_cfa_location structure from a dwarf location
5650 descriptor sequence. */
5653 get_cfa_from_loc_descr (dw_cfa_location
*cfa
, struct dw_loc_descr_struct
*loc
)
5655 struct dw_loc_descr_struct
*ptr
;
5657 cfa
->base_offset
= 0;
5661 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
5663 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
5699 cfa
->reg
= op
- DW_OP_reg0
;
5702 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
5736 cfa
->reg
= op
- DW_OP_breg0
;
5737 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
5740 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
5741 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
5746 case DW_OP_plus_uconst
:
5747 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
5750 internal_error ("DW_LOC_OP %s not implemented",
5751 dwarf_stack_op_name (ptr
->dw_loc_opc
));
5756 /* And now, the support for symbolic debugging information. */
5758 /* .debug_str support. */
5759 static int output_indirect_string (void **, void *);
5761 static void dwarf2out_init (const char *);
5762 static void dwarf2out_finish (const char *);
5763 static void dwarf2out_assembly_start (void);
5764 static void dwarf2out_define (unsigned int, const char *);
5765 static void dwarf2out_undef (unsigned int, const char *);
5766 static void dwarf2out_start_source_file (unsigned, const char *);
5767 static void dwarf2out_end_source_file (unsigned);
5768 static void dwarf2out_function_decl (tree
);
5769 static void dwarf2out_begin_block (unsigned, unsigned);
5770 static void dwarf2out_end_block (unsigned, unsigned);
5771 static bool dwarf2out_ignore_block (const_tree
);
5772 static void dwarf2out_global_decl (tree
);
5773 static void dwarf2out_type_decl (tree
, int);
5774 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
5775 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
5777 static void dwarf2out_abstract_function (tree
);
5778 static void dwarf2out_var_location (rtx
);
5779 static void dwarf2out_begin_function (tree
);
5780 static void dwarf2out_set_name (tree
, tree
);
5782 /* The debug hooks structure. */
5784 const struct gcc_debug_hooks dwarf2_debug_hooks
=
5788 dwarf2out_assembly_start
,
5791 dwarf2out_start_source_file
,
5792 dwarf2out_end_source_file
,
5793 dwarf2out_begin_block
,
5794 dwarf2out_end_block
,
5795 dwarf2out_ignore_block
,
5796 dwarf2out_source_line
,
5797 dwarf2out_begin_prologue
,
5798 #if VMS_DEBUGGING_INFO
5799 dwarf2out_vms_end_prologue
,
5800 dwarf2out_vms_begin_epilogue
,
5802 debug_nothing_int_charstar
,
5803 debug_nothing_int_charstar
,
5805 dwarf2out_end_epilogue
,
5806 dwarf2out_begin_function
,
5807 debug_nothing_int
, /* end_function */
5808 dwarf2out_function_decl
, /* function_decl */
5809 dwarf2out_global_decl
,
5810 dwarf2out_type_decl
, /* type_decl */
5811 dwarf2out_imported_module_or_decl
,
5812 debug_nothing_tree
, /* deferred_inline_function */
5813 /* The DWARF 2 backend tries to reduce debugging bloat by not
5814 emitting the abstract description of inline functions until
5815 something tries to reference them. */
5816 dwarf2out_abstract_function
, /* outlining_inline_function */
5817 debug_nothing_rtx
, /* label */
5818 debug_nothing_int
, /* handle_pch */
5819 dwarf2out_var_location
,
5820 dwarf2out_switch_text_section
,
5822 1, /* start_end_main_source_file */
5823 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
5826 /* NOTE: In the comments in this file, many references are made to
5827 "Debugging Information Entries". This term is abbreviated as `DIE'
5828 throughout the remainder of this file. */
5830 /* An internal representation of the DWARF output is built, and then
5831 walked to generate the DWARF debugging info. The walk of the internal
5832 representation is done after the entire program has been compiled.
5833 The types below are used to describe the internal representation. */
5835 /* Various DIE's use offsets relative to the beginning of the
5836 .debug_info section to refer to each other. */
5838 typedef long int dw_offset
;
5840 /* Define typedefs here to avoid circular dependencies. */
5842 typedef struct dw_attr_struct
*dw_attr_ref
;
5843 typedef struct dw_line_info_struct
*dw_line_info_ref
;
5844 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
5845 typedef struct pubname_struct
*pubname_ref
;
5846 typedef struct dw_ranges_struct
*dw_ranges_ref
;
5847 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
5848 typedef struct comdat_type_struct
*comdat_type_node_ref
;
5850 /* Each entry in the line_info_table maintains the file and
5851 line number associated with the label generated for that
5852 entry. The label gives the PC value associated with
5853 the line number entry. */
5855 typedef struct GTY(()) dw_line_info_struct
{
5856 unsigned long dw_file_num
;
5857 unsigned long dw_line_num
;
5861 /* Line information for functions in separate sections; each one gets its
5863 typedef struct GTY(()) dw_separate_line_info_struct
{
5864 unsigned long dw_file_num
;
5865 unsigned long dw_line_num
;
5866 unsigned long function
;
5868 dw_separate_line_info_entry
;
5870 /* Each DIE attribute has a field specifying the attribute kind,
5871 a link to the next attribute in the chain, and an attribute value.
5872 Attributes are typically linked below the DIE they modify. */
5874 typedef struct GTY(()) dw_attr_struct
{
5875 enum dwarf_attribute dw_attr
;
5876 dw_val_node dw_attr_val
;
5880 DEF_VEC_O(dw_attr_node
);
5881 DEF_VEC_ALLOC_O(dw_attr_node
,gc
);
5883 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5884 The children of each node form a circular list linked by
5885 die_sib. die_child points to the node *before* the "first" child node. */
5887 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
5888 union die_symbol_or_type_node
5890 char * GTY ((tag ("0"))) die_symbol
;
5891 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
5893 GTY ((desc ("dwarf_version >= 4"))) die_id
;
5894 VEC(dw_attr_node
,gc
) * die_attr
;
5895 dw_die_ref die_parent
;
5896 dw_die_ref die_child
;
5898 dw_die_ref die_definition
; /* ref from a specification to its definition */
5899 dw_offset die_offset
;
5900 unsigned long die_abbrev
;
5902 /* Die is used and must not be pruned as unused. */
5903 int die_perennial_p
;
5904 unsigned int decl_id
;
5905 enum dwarf_tag die_tag
;
5909 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5910 #define FOR_EACH_CHILD(die, c, expr) do { \
5911 c = die->die_child; \
5915 } while (c != die->die_child); \
5918 /* The pubname structure */
5920 typedef struct GTY(()) pubname_struct
{
5926 DEF_VEC_O(pubname_entry
);
5927 DEF_VEC_ALLOC_O(pubname_entry
, gc
);
5929 struct GTY(()) dw_ranges_struct
{
5930 /* If this is positive, it's a block number, otherwise it's a
5931 bitwise-negated index into dw_ranges_by_label. */
5935 /* A structure to hold a macinfo entry. */
5937 typedef struct GTY(()) macinfo_struct
{
5938 unsigned HOST_WIDE_INT code
;
5939 unsigned HOST_WIDE_INT lineno
;
5944 DEF_VEC_O(macinfo_entry
);
5945 DEF_VEC_ALLOC_O(macinfo_entry
, gc
);
5947 struct GTY(()) dw_ranges_by_label_struct
{
5952 /* The comdat type node structure. */
5953 typedef struct GTY(()) comdat_type_struct
5955 dw_die_ref root_die
;
5956 dw_die_ref type_die
;
5957 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
5958 struct comdat_type_struct
*next
;
5962 /* The limbo die list structure. */
5963 typedef struct GTY(()) limbo_die_struct
{
5966 struct limbo_die_struct
*next
;
5970 typedef struct skeleton_chain_struct
5974 struct skeleton_chain_struct
*parent
;
5976 skeleton_chain_node
;
5978 /* How to start an assembler comment. */
5979 #ifndef ASM_COMMENT_START
5980 #define ASM_COMMENT_START ";#"
5983 /* Define a macro which returns nonzero for a TYPE_DECL which was
5984 implicitly generated for a tagged type.
5986 Note that unlike the gcc front end (which generates a NULL named
5987 TYPE_DECL node for each complete tagged type, each array type, and
5988 each function type node created) the g++ front end generates a
5989 _named_ TYPE_DECL node for each tagged type node created.
5990 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
5991 generate a DW_TAG_typedef DIE for them. */
5993 #define TYPE_DECL_IS_STUB(decl) \
5994 (DECL_NAME (decl) == NULL_TREE \
5995 || (DECL_ARTIFICIAL (decl) \
5996 && is_tagged_type (TREE_TYPE (decl)) \
5997 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
5998 /* This is necessary for stub decls that \
5999 appear in nested inline functions. */ \
6000 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
6001 && (decl_ultimate_origin (decl) \
6002 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
6004 /* Information concerning the compilation unit's programming
6005 language, and compiler version. */
6007 /* Fixed size portion of the DWARF compilation unit header. */
6008 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
6009 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
6011 /* Fixed size portion of the DWARF comdat type unit header. */
6012 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
6013 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
6014 + DWARF_OFFSET_SIZE)
6016 /* Fixed size portion of public names info. */
6017 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
6019 /* Fixed size portion of the address range info. */
6020 #define DWARF_ARANGES_HEADER_SIZE \
6021 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6022 DWARF2_ADDR_SIZE * 2) \
6023 - DWARF_INITIAL_LENGTH_SIZE)
6025 /* Size of padding portion in the address range info. It must be
6026 aligned to twice the pointer size. */
6027 #define DWARF_ARANGES_PAD_SIZE \
6028 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6029 DWARF2_ADDR_SIZE * 2) \
6030 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
6032 /* Use assembler line directives if available. */
6033 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
6034 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
6035 #define DWARF2_ASM_LINE_DEBUG_INFO 1
6037 #define DWARF2_ASM_LINE_DEBUG_INFO 0
6041 /* Minimum line offset in a special line info. opcode.
6042 This value was chosen to give a reasonable range of values. */
6043 #define DWARF_LINE_BASE -10
6045 /* First special line opcode - leave room for the standard opcodes. */
6046 #define DWARF_LINE_OPCODE_BASE 10
6048 /* Range of line offsets in a special line info. opcode. */
6049 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
6051 /* Flag that indicates the initial value of the is_stmt_start flag.
6052 In the present implementation, we do not mark any lines as
6053 the beginning of a source statement, because that information
6054 is not made available by the GCC front-end. */
6055 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
6057 /* Maximum number of operations per instruction bundle. */
6058 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
6059 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
6062 /* This location is used by calc_die_sizes() to keep track
6063 the offset of each DIE within the .debug_info section. */
6064 static unsigned long next_die_offset
;
6066 /* Record the root of the DIE's built for the current compilation unit. */
6067 static GTY(()) dw_die_ref single_comp_unit_die
;
6069 /* A list of type DIEs that have been separated into comdat sections. */
6070 static GTY(()) comdat_type_node
*comdat_type_list
;
6072 /* A list of DIEs with a NULL parent waiting to be relocated. */
6073 static GTY(()) limbo_die_node
*limbo_die_list
;
6075 /* A list of DIEs for which we may have to generate
6076 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
6077 static GTY(()) limbo_die_node
*deferred_asm_name
;
6079 /* Filenames referenced by this compilation unit. */
6080 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
6082 /* A hash table of references to DIE's that describe declarations.
6083 The key is a DECL_UID() which is a unique number identifying each decl. */
6084 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
6086 /* A hash table of references to DIE's that describe COMMON blocks.
6087 The key is DECL_UID() ^ die_parent. */
6088 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
6090 typedef struct GTY(()) die_arg_entry_struct
{
6095 DEF_VEC_O(die_arg_entry
);
6096 DEF_VEC_ALLOC_O(die_arg_entry
,gc
);
6098 /* Node of the variable location list. */
6099 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
6100 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
6101 EXPR_LIST chain. For small bitsizes, bitsize is encoded
6102 in mode of the EXPR_LIST node and first EXPR_LIST operand
6103 is either NOTE_INSN_VAR_LOCATION for a piece with a known
6104 location or NULL for padding. For larger bitsizes,
6105 mode is 0 and first operand is a CONCAT with bitsize
6106 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
6107 NULL as second operand. */
6109 const char * GTY (()) label
;
6110 struct var_loc_node
* GTY (()) next
;
6113 /* Variable location list. */
6114 struct GTY (()) var_loc_list_def
{
6115 struct var_loc_node
* GTY (()) first
;
6117 /* Pointer to the last but one or last element of the
6118 chained list. If the list is empty, both first and
6119 last are NULL, if the list contains just one node
6120 or the last node certainly is not redundant, it points
6121 to the last node, otherwise points to the last but one.
6122 Do not mark it for GC because it is marked through the chain. */
6123 struct var_loc_node
* GTY ((skip ("%h"))) last
;
6125 /* DECL_UID of the variable decl. */
6126 unsigned int decl_id
;
6128 typedef struct var_loc_list_def var_loc_list
;
6130 /* Call argument location list. */
6131 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
6132 rtx
GTY (()) call_arg_loc_note
;
6133 const char * GTY (()) label
;
6134 tree
GTY (()) block
;
6136 rtx
GTY (()) symbol_ref
;
6137 struct call_arg_loc_node
* GTY (()) next
;
6141 /* Table of decl location linked lists. */
6142 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
6144 /* Head and tail of call_arg_loc chain. */
6145 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
6146 static struct call_arg_loc_node
*call_arg_loc_last
;
6148 /* Number of call sites in the current function. */
6149 static int call_site_count
= -1;
6150 /* Number of tail call sites in the current function. */
6151 static int tail_call_site_count
= -1;
6153 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
6155 static VEC (dw_die_ref
, heap
) *block_map
;
6157 /* A pointer to the base of a list of references to DIE's that
6158 are uniquely identified by their tag, presence/absence of
6159 children DIE's, and list of attribute/value pairs. */
6160 static GTY((length ("abbrev_die_table_allocated")))
6161 dw_die_ref
*abbrev_die_table
;
6163 /* Number of elements currently allocated for abbrev_die_table. */
6164 static GTY(()) unsigned abbrev_die_table_allocated
;
6166 /* Number of elements in type_die_table currently in use. */
6167 static GTY(()) unsigned abbrev_die_table_in_use
;
6169 /* Size (in elements) of increments by which we may expand the
6170 abbrev_die_table. */
6171 #define ABBREV_DIE_TABLE_INCREMENT 256
6173 /* A pointer to the base of a table that contains line information
6174 for each source code line in .text in the compilation unit. */
6175 static GTY((length ("line_info_table_allocated")))
6176 dw_line_info_ref line_info_table
;
6178 /* Number of elements currently allocated for line_info_table. */
6179 static GTY(()) unsigned line_info_table_allocated
;
6181 /* Number of elements in line_info_table currently in use. */
6182 static GTY(()) unsigned line_info_table_in_use
;
6184 /* A pointer to the base of a table that contains line information
6185 for each source code line outside of .text in the compilation unit. */
6186 static GTY ((length ("separate_line_info_table_allocated")))
6187 dw_separate_line_info_ref separate_line_info_table
;
6189 /* Number of elements currently allocated for separate_line_info_table. */
6190 static GTY(()) unsigned separate_line_info_table_allocated
;
6192 /* Number of elements in separate_line_info_table currently in use. */
6193 static GTY(()) unsigned separate_line_info_table_in_use
;
6195 /* Size (in elements) of increments by which we may expand the
6197 #define LINE_INFO_TABLE_INCREMENT 1024
6199 /* A flag to tell pubnames/types export if there is an info section to
6201 static bool info_section_emitted
;
6203 /* A pointer to the base of a table that contains a list of publicly
6204 accessible names. */
6205 static GTY (()) VEC (pubname_entry
, gc
) * pubname_table
;
6207 /* A pointer to the base of a table that contains a list of publicly
6208 accessible types. */
6209 static GTY (()) VEC (pubname_entry
, gc
) * pubtype_table
;
6211 /* A pointer to the base of a table that contains a list of macro
6212 defines/undefines (and file start/end markers). */
6213 static GTY (()) VEC (macinfo_entry
, gc
) * macinfo_table
;
6215 /* Array of dies for which we should generate .debug_arange info. */
6216 static GTY((length ("arange_table_allocated"))) dw_die_ref
*arange_table
;
6218 /* Number of elements currently allocated for arange_table. */
6219 static GTY(()) unsigned arange_table_allocated
;
6221 /* Number of elements in arange_table currently in use. */
6222 static GTY(()) unsigned arange_table_in_use
;
6224 /* Size (in elements) of increments by which we may expand the
6226 #define ARANGE_TABLE_INCREMENT 64
6228 /* Array of dies for which we should generate .debug_ranges info. */
6229 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
6231 /* Number of elements currently allocated for ranges_table. */
6232 static GTY(()) unsigned ranges_table_allocated
;
6234 /* Number of elements in ranges_table currently in use. */
6235 static GTY(()) unsigned ranges_table_in_use
;
6237 /* Array of pairs of labels referenced in ranges_table. */
6238 static GTY ((length ("ranges_by_label_allocated")))
6239 dw_ranges_by_label_ref ranges_by_label
;
6241 /* Number of elements currently allocated for ranges_by_label. */
6242 static GTY(()) unsigned ranges_by_label_allocated
;
6244 /* Number of elements in ranges_by_label currently in use. */
6245 static GTY(()) unsigned ranges_by_label_in_use
;
6247 /* Size (in elements) of increments by which we may expand the
6249 #define RANGES_TABLE_INCREMENT 64
6251 /* Whether we have location lists that need outputting */
6252 static GTY(()) bool have_location_lists
;
6254 /* Unique label counter. */
6255 static GTY(()) unsigned int loclabel_num
;
6257 /* Unique label counter for point-of-call tables. */
6258 static GTY(()) unsigned int poc_label_num
;
6260 /* Record whether the function being analyzed contains inlined functions. */
6261 static int current_function_has_inlines
;
6263 /* The last file entry emitted by maybe_emit_file(). */
6264 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
6266 /* Number of internal labels generated by gen_internal_sym(). */
6267 static GTY(()) int label_num
;
6269 /* Cached result of previous call to lookup_filename. */
6270 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
6272 static GTY(()) VEC(die_arg_entry
,gc
) *tmpl_value_parm_die_table
;
6274 /* Instances of generic types for which we need to generate debug
6275 info that describe their generic parameters and arguments. That
6276 generation needs to happen once all types are properly laid out so
6277 we do it at the end of compilation. */
6278 static GTY(()) VEC(tree
,gc
) *generic_type_instances
;
6280 /* Offset from the "steady-state frame pointer" to the frame base,
6281 within the current function. */
6282 static HOST_WIDE_INT frame_pointer_fb_offset
;
6284 /* Forward declarations for functions defined in this file. */
6286 static int is_pseudo_reg (const_rtx
);
6287 static tree
type_main_variant (tree
);
6288 static int is_tagged_type (const_tree
);
6289 static const char *dwarf_tag_name (unsigned);
6290 static const char *dwarf_attr_name (unsigned);
6291 static const char *dwarf_form_name (unsigned);
6292 static tree
decl_ultimate_origin (const_tree
);
6293 static tree
decl_class_context (tree
);
6294 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
6295 static inline enum dw_val_class
AT_class (dw_attr_ref
);
6296 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
6297 static inline unsigned AT_flag (dw_attr_ref
);
6298 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
6299 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
6300 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
6301 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
6302 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
6303 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
6304 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
6305 unsigned int, unsigned char *);
6306 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
6307 static hashval_t
debug_str_do_hash (const void *);
6308 static int debug_str_eq (const void *, const void *);
6309 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
6310 static inline const char *AT_string (dw_attr_ref
);
6311 static enum dwarf_form
AT_string_form (dw_attr_ref
);
6312 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
6313 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
6314 static inline dw_die_ref
AT_ref (dw_attr_ref
);
6315 static inline int AT_ref_external (dw_attr_ref
);
6316 static inline void set_AT_ref_external (dw_attr_ref
, int);
6317 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
6318 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
6319 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
6320 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
6322 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
6323 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
6324 static inline rtx
AT_addr (dw_attr_ref
);
6325 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
6326 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
6327 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
6328 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
6329 unsigned HOST_WIDE_INT
);
6330 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
6332 static inline const char *AT_lbl (dw_attr_ref
);
6333 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
6334 static const char *get_AT_low_pc (dw_die_ref
);
6335 static const char *get_AT_hi_pc (dw_die_ref
);
6336 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
6337 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
6338 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
6339 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
6340 static bool is_cxx (void);
6341 static bool is_fortran (void);
6342 static bool is_ada (void);
6343 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
6344 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
6345 static void add_child_die (dw_die_ref
, dw_die_ref
);
6346 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
6347 static dw_die_ref
lookup_type_die (tree
);
6348 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
6349 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
6350 static void equate_type_number_to_die (tree
, dw_die_ref
);
6351 static hashval_t
decl_die_table_hash (const void *);
6352 static int decl_die_table_eq (const void *, const void *);
6353 static dw_die_ref
lookup_decl_die (tree
);
6354 static hashval_t
common_block_die_table_hash (const void *);
6355 static int common_block_die_table_eq (const void *, const void *);
6356 static hashval_t
decl_loc_table_hash (const void *);
6357 static int decl_loc_table_eq (const void *, const void *);
6358 static var_loc_list
*lookup_decl_loc (const_tree
);
6359 static void equate_decl_number_to_die (tree
, dw_die_ref
);
6360 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
6361 static void print_spaces (FILE *);
6362 static void print_die (dw_die_ref
, FILE *);
6363 static void print_dwarf_line_table (FILE *);
6364 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
6365 static dw_die_ref
pop_compile_unit (dw_die_ref
);
6366 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
6367 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
6368 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
6369 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
6370 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
6371 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
6372 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
6373 struct md5_ctx
*, int *);
6374 struct checksum_attributes
;
6375 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
6376 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
6377 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
6378 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
6379 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
6380 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
6381 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
6382 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
6383 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
6384 static void compute_section_prefix (dw_die_ref
);
6385 static int is_type_die (dw_die_ref
);
6386 static int is_comdat_die (dw_die_ref
);
6387 static int is_symbol_die (dw_die_ref
);
6388 static void assign_symbol_names (dw_die_ref
);
6389 static void break_out_includes (dw_die_ref
);
6390 static int is_declaration_die (dw_die_ref
);
6391 static int should_move_die_to_comdat (dw_die_ref
);
6392 static dw_die_ref
clone_as_declaration (dw_die_ref
);
6393 static dw_die_ref
clone_die (dw_die_ref
);
6394 static dw_die_ref
clone_tree (dw_die_ref
);
6395 static void copy_declaration_context (dw_die_ref
, dw_die_ref
);
6396 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
6397 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
6398 static dw_die_ref
generate_skeleton (dw_die_ref
);
6399 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
6401 static void break_out_comdat_types (dw_die_ref
);
6402 static dw_die_ref
copy_ancestor_tree (dw_die_ref
, dw_die_ref
, htab_t
);
6403 static void copy_decls_walk (dw_die_ref
, dw_die_ref
, htab_t
);
6404 static void copy_decls_for_unworthy_types (dw_die_ref
);
6406 static hashval_t
htab_cu_hash (const void *);
6407 static int htab_cu_eq (const void *, const void *);
6408 static void htab_cu_del (void *);
6409 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
6410 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
6411 static void add_sibling_attributes (dw_die_ref
);
6412 static void build_abbrev_table (dw_die_ref
);
6413 static void output_location_lists (dw_die_ref
);
6414 static int constant_size (unsigned HOST_WIDE_INT
);
6415 static unsigned long size_of_die (dw_die_ref
);
6416 static void calc_die_sizes (dw_die_ref
);
6417 static void mark_dies (dw_die_ref
);
6418 static void unmark_dies (dw_die_ref
);
6419 static void unmark_all_dies (dw_die_ref
);
6420 static unsigned long size_of_pubnames (VEC (pubname_entry
,gc
) *);
6421 static unsigned long size_of_aranges (void);
6422 static enum dwarf_form
value_format (dw_attr_ref
);
6423 static void output_value_format (dw_attr_ref
);
6424 static void output_abbrev_section (void);
6425 static void output_die_symbol (dw_die_ref
);
6426 static void output_die (dw_die_ref
);
6427 static void output_compilation_unit_header (void);
6428 static void output_comp_unit (dw_die_ref
, int);
6429 static void output_comdat_type_unit (comdat_type_node
*);
6430 static const char *dwarf2_name (tree
, int);
6431 static void add_pubname (tree
, dw_die_ref
);
6432 static void add_pubname_string (const char *, dw_die_ref
);
6433 static void add_pubtype (tree
, dw_die_ref
);
6434 static void output_pubnames (VEC (pubname_entry
,gc
) *);
6435 static void add_arange (tree
, dw_die_ref
);
6436 static void output_aranges (void);
6437 static unsigned int add_ranges_num (int);
6438 static unsigned int add_ranges (const_tree
);
6439 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
6441 static void output_ranges (void);
6442 static void output_line_info (void);
6443 static void output_file_names (void);
6444 static dw_die_ref
base_type_die (tree
);
6445 static int is_base_type (tree
);
6446 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
6447 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
6448 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
6449 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
6450 static int type_is_enum (const_tree
);
6451 static unsigned int dbx_reg_number (const_rtx
);
6452 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
6453 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
6454 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
6455 enum var_init_status
);
6456 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
6457 enum var_init_status
);
6458 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
6459 enum var_init_status
);
6460 static int is_based_loc (const_rtx
);
6461 static int resolve_one_addr (rtx
*, void *);
6462 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
6463 enum var_init_status
);
6464 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
6465 enum var_init_status
);
6466 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
6467 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
6468 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
6469 static tree
field_type (const_tree
);
6470 static unsigned int simple_type_align_in_bits (const_tree
);
6471 static unsigned int simple_decl_align_in_bits (const_tree
);
6472 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
6473 static HOST_WIDE_INT
field_byte_offset (const_tree
);
6474 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
6476 static void add_data_member_location_attribute (dw_die_ref
, tree
);
6477 static bool add_const_value_attribute (dw_die_ref
, rtx
);
6478 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
6479 static void insert_double (double_int
, unsigned char *);
6480 static void insert_float (const_rtx
, unsigned char *);
6481 static rtx
rtl_for_decl_location (tree
);
6482 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
,
6483 enum dwarf_attribute
);
6484 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
6485 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
6486 static void add_name_attribute (dw_die_ref
, const char *);
6487 static void add_comp_dir_attribute (dw_die_ref
);
6488 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
6489 static void add_subscript_info (dw_die_ref
, tree
, bool);
6490 static void add_byte_size_attribute (dw_die_ref
, tree
);
6491 static void add_bit_offset_attribute (dw_die_ref
, tree
);
6492 static void add_bit_size_attribute (dw_die_ref
, tree
);
6493 static void add_prototyped_attribute (dw_die_ref
, tree
);
6494 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
6495 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
6496 static void add_src_coords_attributes (dw_die_ref
, tree
);
6497 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
6498 static void push_decl_scope (tree
);
6499 static void pop_decl_scope (void);
6500 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
6501 static inline int local_scope_p (dw_die_ref
);
6502 static inline int class_scope_p (dw_die_ref
);
6503 static inline int class_or_namespace_scope_p (dw_die_ref
);
6504 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
6505 static void add_calling_convention_attribute (dw_die_ref
, tree
);
6506 static const char *type_tag (const_tree
);
6507 static tree
member_declared_type (const_tree
);
6509 static const char *decl_start_label (tree
);
6511 static void gen_array_type_die (tree
, dw_die_ref
);
6512 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
6514 static void gen_entry_point_die (tree
, dw_die_ref
);
6516 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
6517 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
6518 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
6519 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
6520 static void gen_formal_types_die (tree
, dw_die_ref
);
6521 static void gen_subprogram_die (tree
, dw_die_ref
);
6522 static void gen_variable_die (tree
, tree
, dw_die_ref
);
6523 static void gen_const_die (tree
, dw_die_ref
);
6524 static void gen_label_die (tree
, dw_die_ref
);
6525 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
6526 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
6527 static void gen_field_die (tree
, dw_die_ref
);
6528 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
6529 static dw_die_ref
gen_compile_unit_die (const char *);
6530 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
6531 static void gen_member_die (tree
, dw_die_ref
);
6532 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
6533 enum debug_info_usage
);
6534 static void gen_subroutine_type_die (tree
, dw_die_ref
);
6535 static void gen_typedef_die (tree
, dw_die_ref
);
6536 static void gen_type_die (tree
, dw_die_ref
);
6537 static void gen_block_die (tree
, dw_die_ref
, int);
6538 static void decls_for_scope (tree
, dw_die_ref
, int);
6539 static int is_redundant_typedef (const_tree
);
6540 static bool is_naming_typedef_decl (const_tree
);
6541 static inline dw_die_ref
get_context_die (tree
);
6542 static void gen_namespace_die (tree
, dw_die_ref
);
6543 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
6544 static dw_die_ref
force_decl_die (tree
);
6545 static dw_die_ref
force_type_die (tree
);
6546 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
6547 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
6548 static struct dwarf_file_data
* lookup_filename (const char *);
6549 static void retry_incomplete_types (void);
6550 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
6551 static void gen_generic_params_dies (tree
);
6552 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
6553 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
6554 static void splice_child_die (dw_die_ref
, dw_die_ref
);
6555 static int file_info_cmp (const void *, const void *);
6556 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
6557 const char *, const char *);
6558 static void output_loc_list (dw_loc_list_ref
);
6559 static char *gen_internal_sym (const char *);
6561 static void prune_unmark_dies (dw_die_ref
);
6562 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
6563 static void prune_unused_types_mark (dw_die_ref
, int);
6564 static void prune_unused_types_walk (dw_die_ref
);
6565 static void prune_unused_types_walk_attribs (dw_die_ref
);
6566 static void prune_unused_types_prune (dw_die_ref
);
6567 static void prune_unused_types (void);
6568 static int maybe_emit_file (struct dwarf_file_data
*fd
);
6569 static inline const char *AT_vms_delta1 (dw_attr_ref
);
6570 static inline const char *AT_vms_delta2 (dw_attr_ref
);
6571 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
6572 const char *, const char *);
6573 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
6574 static void gen_remaining_tmpl_value_param_die_attribute (void);
6575 static bool generic_type_p (tree
);
6576 static void schedule_generic_params_dies_gen (tree t
);
6577 static void gen_scheduled_generic_parms_dies (void);
6579 /* Section names used to hold DWARF debugging information. */
6580 #ifndef DEBUG_INFO_SECTION
6581 #define DEBUG_INFO_SECTION ".debug_info"
6583 #ifndef DEBUG_ABBREV_SECTION
6584 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6586 #ifndef DEBUG_ARANGES_SECTION
6587 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6589 #ifndef DEBUG_MACINFO_SECTION
6590 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6592 #ifndef DEBUG_LINE_SECTION
6593 #define DEBUG_LINE_SECTION ".debug_line"
6595 #ifndef DEBUG_LOC_SECTION
6596 #define DEBUG_LOC_SECTION ".debug_loc"
6598 #ifndef DEBUG_PUBNAMES_SECTION
6599 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6601 #ifndef DEBUG_PUBTYPES_SECTION
6602 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6604 #ifndef DEBUG_STR_SECTION
6605 #define DEBUG_STR_SECTION ".debug_str"
6607 #ifndef DEBUG_RANGES_SECTION
6608 #define DEBUG_RANGES_SECTION ".debug_ranges"
6611 /* Standard ELF section names for compiled code and data. */
6612 #ifndef TEXT_SECTION_NAME
6613 #define TEXT_SECTION_NAME ".text"
6616 /* Section flags for .debug_str section. */
6617 #define DEBUG_STR_SECTION_FLAGS \
6618 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6619 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6622 /* Labels we insert at beginning sections we can reference instead of
6623 the section names themselves. */
6625 #ifndef TEXT_SECTION_LABEL
6626 #define TEXT_SECTION_LABEL "Ltext"
6628 #ifndef COLD_TEXT_SECTION_LABEL
6629 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6631 #ifndef DEBUG_LINE_SECTION_LABEL
6632 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6634 #ifndef DEBUG_INFO_SECTION_LABEL
6635 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6637 #ifndef DEBUG_ABBREV_SECTION_LABEL
6638 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6640 #ifndef DEBUG_LOC_SECTION_LABEL
6641 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6643 #ifndef DEBUG_RANGES_SECTION_LABEL
6644 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6646 #ifndef DEBUG_MACINFO_SECTION_LABEL
6647 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6651 /* Definitions of defaults for formats and names of various special
6652 (artificial) labels which may be generated within this file (when the -g
6653 options is used and DWARF2_DEBUGGING_INFO is in effect.
6654 If necessary, these may be overridden from within the tm.h file, but
6655 typically, overriding these defaults is unnecessary. */
6657 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6658 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6659 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6660 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6661 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6662 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6663 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6664 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6665 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6666 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
6668 #ifndef TEXT_END_LABEL
6669 #define TEXT_END_LABEL "Letext"
6671 #ifndef COLD_END_LABEL
6672 #define COLD_END_LABEL "Letext_cold"
6674 #ifndef BLOCK_BEGIN_LABEL
6675 #define BLOCK_BEGIN_LABEL "LBB"
6677 #ifndef BLOCK_END_LABEL
6678 #define BLOCK_END_LABEL "LBE"
6680 #ifndef LINE_CODE_LABEL
6681 #define LINE_CODE_LABEL "LM"
6683 #ifndef SEPARATE_LINE_CODE_LABEL
6684 #define SEPARATE_LINE_CODE_LABEL "LSM"
6688 /* Return the root of the DIE's built for the current compilation unit. */
6690 comp_unit_die (void)
6692 if (!single_comp_unit_die
)
6693 single_comp_unit_die
= gen_compile_unit_die (NULL
);
6694 return single_comp_unit_die
;
6697 /* We allow a language front-end to designate a function that is to be
6698 called to "demangle" any name before it is put into a DIE. */
6700 static const char *(*demangle_name_func
) (const char *);
6703 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
6705 demangle_name_func
= func
;
6708 /* Test if rtl node points to a pseudo register. */
6711 is_pseudo_reg (const_rtx rtl
)
6713 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
6714 || (GET_CODE (rtl
) == SUBREG
6715 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
6718 /* Return a reference to a type, with its const and volatile qualifiers
6722 type_main_variant (tree type
)
6724 type
= TYPE_MAIN_VARIANT (type
);
6726 /* ??? There really should be only one main variant among any group of
6727 variants of a given type (and all of the MAIN_VARIANT values for all
6728 members of the group should point to that one type) but sometimes the C
6729 front-end messes this up for array types, so we work around that bug
6731 if (TREE_CODE (type
) == ARRAY_TYPE
)
6732 while (type
!= TYPE_MAIN_VARIANT (type
))
6733 type
= TYPE_MAIN_VARIANT (type
);
6738 /* Return nonzero if the given type node represents a tagged type. */
6741 is_tagged_type (const_tree type
)
6743 enum tree_code code
= TREE_CODE (type
);
6745 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
6746 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
6749 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
6752 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
6754 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
6757 /* Convert a DIE tag into its string name. */
6760 dwarf_tag_name (unsigned int tag
)
6764 case DW_TAG_padding
:
6765 return "DW_TAG_padding";
6766 case DW_TAG_array_type
:
6767 return "DW_TAG_array_type";
6768 case DW_TAG_class_type
:
6769 return "DW_TAG_class_type";
6770 case DW_TAG_entry_point
:
6771 return "DW_TAG_entry_point";
6772 case DW_TAG_enumeration_type
:
6773 return "DW_TAG_enumeration_type";
6774 case DW_TAG_formal_parameter
:
6775 return "DW_TAG_formal_parameter";
6776 case DW_TAG_imported_declaration
:
6777 return "DW_TAG_imported_declaration";
6779 return "DW_TAG_label";
6780 case DW_TAG_lexical_block
:
6781 return "DW_TAG_lexical_block";
6783 return "DW_TAG_member";
6784 case DW_TAG_pointer_type
:
6785 return "DW_TAG_pointer_type";
6786 case DW_TAG_reference_type
:
6787 return "DW_TAG_reference_type";
6788 case DW_TAG_compile_unit
:
6789 return "DW_TAG_compile_unit";
6790 case DW_TAG_string_type
:
6791 return "DW_TAG_string_type";
6792 case DW_TAG_structure_type
:
6793 return "DW_TAG_structure_type";
6794 case DW_TAG_subroutine_type
:
6795 return "DW_TAG_subroutine_type";
6796 case DW_TAG_typedef
:
6797 return "DW_TAG_typedef";
6798 case DW_TAG_union_type
:
6799 return "DW_TAG_union_type";
6800 case DW_TAG_unspecified_parameters
:
6801 return "DW_TAG_unspecified_parameters";
6802 case DW_TAG_variant
:
6803 return "DW_TAG_variant";
6804 case DW_TAG_common_block
:
6805 return "DW_TAG_common_block";
6806 case DW_TAG_common_inclusion
:
6807 return "DW_TAG_common_inclusion";
6808 case DW_TAG_inheritance
:
6809 return "DW_TAG_inheritance";
6810 case DW_TAG_inlined_subroutine
:
6811 return "DW_TAG_inlined_subroutine";
6813 return "DW_TAG_module";
6814 case DW_TAG_ptr_to_member_type
:
6815 return "DW_TAG_ptr_to_member_type";
6816 case DW_TAG_set_type
:
6817 return "DW_TAG_set_type";
6818 case DW_TAG_subrange_type
:
6819 return "DW_TAG_subrange_type";
6820 case DW_TAG_with_stmt
:
6821 return "DW_TAG_with_stmt";
6822 case DW_TAG_access_declaration
:
6823 return "DW_TAG_access_declaration";
6824 case DW_TAG_base_type
:
6825 return "DW_TAG_base_type";
6826 case DW_TAG_catch_block
:
6827 return "DW_TAG_catch_block";
6828 case DW_TAG_const_type
:
6829 return "DW_TAG_const_type";
6830 case DW_TAG_constant
:
6831 return "DW_TAG_constant";
6832 case DW_TAG_enumerator
:
6833 return "DW_TAG_enumerator";
6834 case DW_TAG_file_type
:
6835 return "DW_TAG_file_type";
6837 return "DW_TAG_friend";
6838 case DW_TAG_namelist
:
6839 return "DW_TAG_namelist";
6840 case DW_TAG_namelist_item
:
6841 return "DW_TAG_namelist_item";
6842 case DW_TAG_packed_type
:
6843 return "DW_TAG_packed_type";
6844 case DW_TAG_subprogram
:
6845 return "DW_TAG_subprogram";
6846 case DW_TAG_template_type_param
:
6847 return "DW_TAG_template_type_param";
6848 case DW_TAG_template_value_param
:
6849 return "DW_TAG_template_value_param";
6850 case DW_TAG_thrown_type
:
6851 return "DW_TAG_thrown_type";
6852 case DW_TAG_try_block
:
6853 return "DW_TAG_try_block";
6854 case DW_TAG_variant_part
:
6855 return "DW_TAG_variant_part";
6856 case DW_TAG_variable
:
6857 return "DW_TAG_variable";
6858 case DW_TAG_volatile_type
:
6859 return "DW_TAG_volatile_type";
6860 case DW_TAG_dwarf_procedure
:
6861 return "DW_TAG_dwarf_procedure";
6862 case DW_TAG_restrict_type
:
6863 return "DW_TAG_restrict_type";
6864 case DW_TAG_interface_type
:
6865 return "DW_TAG_interface_type";
6866 case DW_TAG_namespace
:
6867 return "DW_TAG_namespace";
6868 case DW_TAG_imported_module
:
6869 return "DW_TAG_imported_module";
6870 case DW_TAG_unspecified_type
:
6871 return "DW_TAG_unspecified_type";
6872 case DW_TAG_partial_unit
:
6873 return "DW_TAG_partial_unit";
6874 case DW_TAG_imported_unit
:
6875 return "DW_TAG_imported_unit";
6876 case DW_TAG_condition
:
6877 return "DW_TAG_condition";
6878 case DW_TAG_shared_type
:
6879 return "DW_TAG_shared_type";
6880 case DW_TAG_type_unit
:
6881 return "DW_TAG_type_unit";
6882 case DW_TAG_rvalue_reference_type
:
6883 return "DW_TAG_rvalue_reference_type";
6884 case DW_TAG_template_alias
:
6885 return "DW_TAG_template_alias";
6886 case DW_TAG_GNU_template_parameter_pack
:
6887 return "DW_TAG_GNU_template_parameter_pack";
6888 case DW_TAG_GNU_formal_parameter_pack
:
6889 return "DW_TAG_GNU_formal_parameter_pack";
6890 case DW_TAG_MIPS_loop
:
6891 return "DW_TAG_MIPS_loop";
6892 case DW_TAG_format_label
:
6893 return "DW_TAG_format_label";
6894 case DW_TAG_function_template
:
6895 return "DW_TAG_function_template";
6896 case DW_TAG_class_template
:
6897 return "DW_TAG_class_template";
6898 case DW_TAG_GNU_BINCL
:
6899 return "DW_TAG_GNU_BINCL";
6900 case DW_TAG_GNU_EINCL
:
6901 return "DW_TAG_GNU_EINCL";
6902 case DW_TAG_GNU_template_template_param
:
6903 return "DW_TAG_GNU_template_template_param";
6904 case DW_TAG_GNU_call_site
:
6905 return "DW_TAG_GNU_call_site";
6906 case DW_TAG_GNU_call_site_parameter
:
6907 return "DW_TAG_GNU_call_site_parameter";
6909 return "DW_TAG_<unknown>";
6913 /* Convert a DWARF attribute code into its string name. */
6916 dwarf_attr_name (unsigned int attr
)
6921 return "DW_AT_sibling";
6922 case DW_AT_location
:
6923 return "DW_AT_location";
6925 return "DW_AT_name";
6926 case DW_AT_ordering
:
6927 return "DW_AT_ordering";
6928 case DW_AT_subscr_data
:
6929 return "DW_AT_subscr_data";
6930 case DW_AT_byte_size
:
6931 return "DW_AT_byte_size";
6932 case DW_AT_bit_offset
:
6933 return "DW_AT_bit_offset";
6934 case DW_AT_bit_size
:
6935 return "DW_AT_bit_size";
6936 case DW_AT_element_list
:
6937 return "DW_AT_element_list";
6938 case DW_AT_stmt_list
:
6939 return "DW_AT_stmt_list";
6941 return "DW_AT_low_pc";
6943 return "DW_AT_high_pc";
6944 case DW_AT_language
:
6945 return "DW_AT_language";
6947 return "DW_AT_member";
6949 return "DW_AT_discr";
6950 case DW_AT_discr_value
:
6951 return "DW_AT_discr_value";
6952 case DW_AT_visibility
:
6953 return "DW_AT_visibility";
6955 return "DW_AT_import";
6956 case DW_AT_string_length
:
6957 return "DW_AT_string_length";
6958 case DW_AT_common_reference
:
6959 return "DW_AT_common_reference";
6960 case DW_AT_comp_dir
:
6961 return "DW_AT_comp_dir";
6962 case DW_AT_const_value
:
6963 return "DW_AT_const_value";
6964 case DW_AT_containing_type
:
6965 return "DW_AT_containing_type";
6966 case DW_AT_default_value
:
6967 return "DW_AT_default_value";
6969 return "DW_AT_inline";
6970 case DW_AT_is_optional
:
6971 return "DW_AT_is_optional";
6972 case DW_AT_lower_bound
:
6973 return "DW_AT_lower_bound";
6974 case DW_AT_producer
:
6975 return "DW_AT_producer";
6976 case DW_AT_prototyped
:
6977 return "DW_AT_prototyped";
6978 case DW_AT_return_addr
:
6979 return "DW_AT_return_addr";
6980 case DW_AT_start_scope
:
6981 return "DW_AT_start_scope";
6982 case DW_AT_bit_stride
:
6983 return "DW_AT_bit_stride";
6984 case DW_AT_upper_bound
:
6985 return "DW_AT_upper_bound";
6986 case DW_AT_abstract_origin
:
6987 return "DW_AT_abstract_origin";
6988 case DW_AT_accessibility
:
6989 return "DW_AT_accessibility";
6990 case DW_AT_address_class
:
6991 return "DW_AT_address_class";
6992 case DW_AT_artificial
:
6993 return "DW_AT_artificial";
6994 case DW_AT_base_types
:
6995 return "DW_AT_base_types";
6996 case DW_AT_calling_convention
:
6997 return "DW_AT_calling_convention";
6999 return "DW_AT_count";
7000 case DW_AT_data_member_location
:
7001 return "DW_AT_data_member_location";
7002 case DW_AT_decl_column
:
7003 return "DW_AT_decl_column";
7004 case DW_AT_decl_file
:
7005 return "DW_AT_decl_file";
7006 case DW_AT_decl_line
:
7007 return "DW_AT_decl_line";
7008 case DW_AT_declaration
:
7009 return "DW_AT_declaration";
7010 case DW_AT_discr_list
:
7011 return "DW_AT_discr_list";
7012 case DW_AT_encoding
:
7013 return "DW_AT_encoding";
7014 case DW_AT_external
:
7015 return "DW_AT_external";
7016 case DW_AT_explicit
:
7017 return "DW_AT_explicit";
7018 case DW_AT_frame_base
:
7019 return "DW_AT_frame_base";
7021 return "DW_AT_friend";
7022 case DW_AT_identifier_case
:
7023 return "DW_AT_identifier_case";
7024 case DW_AT_macro_info
:
7025 return "DW_AT_macro_info";
7026 case DW_AT_namelist_items
:
7027 return "DW_AT_namelist_items";
7028 case DW_AT_priority
:
7029 return "DW_AT_priority";
7031 return "DW_AT_segment";
7032 case DW_AT_specification
:
7033 return "DW_AT_specification";
7034 case DW_AT_static_link
:
7035 return "DW_AT_static_link";
7037 return "DW_AT_type";
7038 case DW_AT_use_location
:
7039 return "DW_AT_use_location";
7040 case DW_AT_variable_parameter
:
7041 return "DW_AT_variable_parameter";
7042 case DW_AT_virtuality
:
7043 return "DW_AT_virtuality";
7044 case DW_AT_vtable_elem_location
:
7045 return "DW_AT_vtable_elem_location";
7047 case DW_AT_allocated
:
7048 return "DW_AT_allocated";
7049 case DW_AT_associated
:
7050 return "DW_AT_associated";
7051 case DW_AT_data_location
:
7052 return "DW_AT_data_location";
7053 case DW_AT_byte_stride
:
7054 return "DW_AT_byte_stride";
7055 case DW_AT_entry_pc
:
7056 return "DW_AT_entry_pc";
7057 case DW_AT_use_UTF8
:
7058 return "DW_AT_use_UTF8";
7059 case DW_AT_extension
:
7060 return "DW_AT_extension";
7062 return "DW_AT_ranges";
7063 case DW_AT_trampoline
:
7064 return "DW_AT_trampoline";
7065 case DW_AT_call_column
:
7066 return "DW_AT_call_column";
7067 case DW_AT_call_file
:
7068 return "DW_AT_call_file";
7069 case DW_AT_call_line
:
7070 return "DW_AT_call_line";
7071 case DW_AT_object_pointer
:
7072 return "DW_AT_object_pointer";
7074 case DW_AT_signature
:
7075 return "DW_AT_signature";
7076 case DW_AT_main_subprogram
:
7077 return "DW_AT_main_subprogram";
7078 case DW_AT_data_bit_offset
:
7079 return "DW_AT_data_bit_offset";
7080 case DW_AT_const_expr
:
7081 return "DW_AT_const_expr";
7082 case DW_AT_enum_class
:
7083 return "DW_AT_enum_class";
7084 case DW_AT_linkage_name
:
7085 return "DW_AT_linkage_name";
7087 case DW_AT_MIPS_fde
:
7088 return "DW_AT_MIPS_fde";
7089 case DW_AT_MIPS_loop_begin
:
7090 return "DW_AT_MIPS_loop_begin";
7091 case DW_AT_MIPS_tail_loop_begin
:
7092 return "DW_AT_MIPS_tail_loop_begin";
7093 case DW_AT_MIPS_epilog_begin
:
7094 return "DW_AT_MIPS_epilog_begin";
7095 #if VMS_DEBUGGING_INFO
7096 case DW_AT_HP_prologue
:
7097 return "DW_AT_HP_prologue";
7099 case DW_AT_MIPS_loop_unroll_factor
:
7100 return "DW_AT_MIPS_loop_unroll_factor";
7102 case DW_AT_MIPS_software_pipeline_depth
:
7103 return "DW_AT_MIPS_software_pipeline_depth";
7104 case DW_AT_MIPS_linkage_name
:
7105 return "DW_AT_MIPS_linkage_name";
7106 #if VMS_DEBUGGING_INFO
7107 case DW_AT_HP_epilogue
:
7108 return "DW_AT_HP_epilogue";
7110 case DW_AT_MIPS_stride
:
7111 return "DW_AT_MIPS_stride";
7113 case DW_AT_MIPS_abstract_name
:
7114 return "DW_AT_MIPS_abstract_name";
7115 case DW_AT_MIPS_clone_origin
:
7116 return "DW_AT_MIPS_clone_origin";
7117 case DW_AT_MIPS_has_inlines
:
7118 return "DW_AT_MIPS_has_inlines";
7120 case DW_AT_sf_names
:
7121 return "DW_AT_sf_names";
7122 case DW_AT_src_info
:
7123 return "DW_AT_src_info";
7124 case DW_AT_mac_info
:
7125 return "DW_AT_mac_info";
7126 case DW_AT_src_coords
:
7127 return "DW_AT_src_coords";
7128 case DW_AT_body_begin
:
7129 return "DW_AT_body_begin";
7130 case DW_AT_body_end
:
7131 return "DW_AT_body_end";
7132 case DW_AT_GNU_vector
:
7133 return "DW_AT_GNU_vector";
7134 case DW_AT_GNU_guarded_by
:
7135 return "DW_AT_GNU_guarded_by";
7136 case DW_AT_GNU_pt_guarded_by
:
7137 return "DW_AT_GNU_pt_guarded_by";
7138 case DW_AT_GNU_guarded
:
7139 return "DW_AT_GNU_guarded";
7140 case DW_AT_GNU_pt_guarded
:
7141 return "DW_AT_GNU_pt_guarded";
7142 case DW_AT_GNU_locks_excluded
:
7143 return "DW_AT_GNU_locks_excluded";
7144 case DW_AT_GNU_exclusive_locks_required
:
7145 return "DW_AT_GNU_exclusive_locks_required";
7146 case DW_AT_GNU_shared_locks_required
:
7147 return "DW_AT_GNU_shared_locks_required";
7148 case DW_AT_GNU_odr_signature
:
7149 return "DW_AT_GNU_odr_signature";
7150 case DW_AT_GNU_template_name
:
7151 return "DW_AT_GNU_template_name";
7152 case DW_AT_GNU_call_site_value
:
7153 return "DW_AT_GNU_call_site_value";
7154 case DW_AT_GNU_call_site_data_value
:
7155 return "DW_AT_GNU_call_site_data_value";
7156 case DW_AT_GNU_call_site_target
:
7157 return "DW_AT_GNU_call_site_target";
7158 case DW_AT_GNU_call_site_target_clobbered
:
7159 return "DW_AT_GNU_call_site_target_clobbered";
7160 case DW_AT_GNU_tail_call
:
7161 return "DW_AT_GNU_tail_call";
7162 case DW_AT_GNU_all_tail_call_sites
:
7163 return "DW_AT_GNU_all_tail_call_sites";
7164 case DW_AT_GNU_all_call_sites
:
7165 return "DW_AT_GNU_all_call_sites";
7166 case DW_AT_GNU_all_source_call_sites
:
7167 return "DW_AT_GNU_all_source_call_sites";
7169 case DW_AT_VMS_rtnbeg_pd_address
:
7170 return "DW_AT_VMS_rtnbeg_pd_address";
7173 return "DW_AT_<unknown>";
7177 /* Convert a DWARF value form code into its string name. */
7180 dwarf_form_name (unsigned int form
)
7185 return "DW_FORM_addr";
7186 case DW_FORM_block2
:
7187 return "DW_FORM_block2";
7188 case DW_FORM_block4
:
7189 return "DW_FORM_block4";
7191 return "DW_FORM_data2";
7193 return "DW_FORM_data4";
7195 return "DW_FORM_data8";
7196 case DW_FORM_string
:
7197 return "DW_FORM_string";
7199 return "DW_FORM_block";
7200 case DW_FORM_block1
:
7201 return "DW_FORM_block1";
7203 return "DW_FORM_data1";
7205 return "DW_FORM_flag";
7207 return "DW_FORM_sdata";
7209 return "DW_FORM_strp";
7211 return "DW_FORM_udata";
7212 case DW_FORM_ref_addr
:
7213 return "DW_FORM_ref_addr";
7215 return "DW_FORM_ref1";
7217 return "DW_FORM_ref2";
7219 return "DW_FORM_ref4";
7221 return "DW_FORM_ref8";
7222 case DW_FORM_ref_udata
:
7223 return "DW_FORM_ref_udata";
7224 case DW_FORM_indirect
:
7225 return "DW_FORM_indirect";
7226 case DW_FORM_sec_offset
:
7227 return "DW_FORM_sec_offset";
7228 case DW_FORM_exprloc
:
7229 return "DW_FORM_exprloc";
7230 case DW_FORM_flag_present
:
7231 return "DW_FORM_flag_present";
7232 case DW_FORM_ref_sig8
:
7233 return "DW_FORM_ref_sig8";
7235 return "DW_FORM_<unknown>";
7239 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
7240 instance of an inlined instance of a decl which is local to an inline
7241 function, so we have to trace all of the way back through the origin chain
7242 to find out what sort of node actually served as the original seed for the
7246 decl_ultimate_origin (const_tree decl
)
7248 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
7251 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
7252 nodes in the function to point to themselves; ignore that if
7253 we're trying to output the abstract instance of this function. */
7254 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
7257 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
7258 most distant ancestor, this should never happen. */
7259 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
7261 return DECL_ABSTRACT_ORIGIN (decl
);
7264 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
7265 of a virtual function may refer to a base class, so we check the 'this'
7269 decl_class_context (tree decl
)
7271 tree context
= NULL_TREE
;
7273 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
7274 context
= DECL_CONTEXT (decl
);
7276 context
= TYPE_MAIN_VARIANT
7277 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
7279 if (context
&& !TYPE_P (context
))
7280 context
= NULL_TREE
;
7285 /* Add an attribute/value pair to a DIE. */
7288 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
7290 /* Maybe this should be an assert? */
7294 if (die
->die_attr
== NULL
)
7295 die
->die_attr
= VEC_alloc (dw_attr_node
, gc
, 1);
7296 VEC_safe_push (dw_attr_node
, gc
, die
->die_attr
, attr
);
7299 static inline enum dw_val_class
7300 AT_class (dw_attr_ref a
)
7302 return a
->dw_attr_val
.val_class
;
7305 /* Add a flag value attribute to a DIE. */
7308 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
7312 attr
.dw_attr
= attr_kind
;
7313 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
7314 attr
.dw_attr_val
.v
.val_flag
= flag
;
7315 add_dwarf_attr (die
, &attr
);
7318 static inline unsigned
7319 AT_flag (dw_attr_ref a
)
7321 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
7322 return a
->dw_attr_val
.v
.val_flag
;
7325 /* Add a signed integer attribute value to a DIE. */
7328 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
7332 attr
.dw_attr
= attr_kind
;
7333 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
7334 attr
.dw_attr_val
.v
.val_int
= int_val
;
7335 add_dwarf_attr (die
, &attr
);
7338 static inline HOST_WIDE_INT
7339 AT_int (dw_attr_ref a
)
7341 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
7342 return a
->dw_attr_val
.v
.val_int
;
7345 /* Add an unsigned integer attribute value to a DIE. */
7348 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7349 unsigned HOST_WIDE_INT unsigned_val
)
7353 attr
.dw_attr
= attr_kind
;
7354 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
7355 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
7356 add_dwarf_attr (die
, &attr
);
7359 static inline unsigned HOST_WIDE_INT
7360 AT_unsigned (dw_attr_ref a
)
7362 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
7363 return a
->dw_attr_val
.v
.val_unsigned
;
7366 /* Add an unsigned double integer attribute value to a DIE. */
7369 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7370 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
7374 attr
.dw_attr
= attr_kind
;
7375 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
7376 attr
.dw_attr_val
.v
.val_double
.high
= high
;
7377 attr
.dw_attr_val
.v
.val_double
.low
= low
;
7378 add_dwarf_attr (die
, &attr
);
7381 /* Add a floating point attribute value to a DIE and return it. */
7384 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7385 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
7389 attr
.dw_attr
= attr_kind
;
7390 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
7391 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
7392 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
7393 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
7394 add_dwarf_attr (die
, &attr
);
7397 /* Add an 8-byte data attribute value to a DIE. */
7400 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7401 unsigned char data8
[8])
7405 attr
.dw_attr
= attr_kind
;
7406 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
7407 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
7408 add_dwarf_attr (die
, &attr
);
7411 /* Hash and equality functions for debug_str_hash. */
7414 debug_str_do_hash (const void *x
)
7416 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
7420 debug_str_eq (const void *x1
, const void *x2
)
7422 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
7423 (const char *)x2
) == 0;
7426 /* Add STR to the indirect string hash table. */
7428 static struct indirect_string_node
*
7429 find_AT_string (const char *str
)
7431 struct indirect_string_node
*node
;
7434 if (! debug_str_hash
)
7435 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
7436 debug_str_eq
, NULL
);
7438 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
7439 htab_hash_string (str
), INSERT
);
7442 node
= ggc_alloc_cleared_indirect_string_node ();
7443 node
->str
= ggc_strdup (str
);
7447 node
= (struct indirect_string_node
*) *slot
;
7453 /* Add a string attribute value to a DIE. */
7456 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
7459 struct indirect_string_node
*node
;
7461 node
= find_AT_string (str
);
7463 attr
.dw_attr
= attr_kind
;
7464 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
7465 attr
.dw_attr_val
.v
.val_str
= node
;
7466 add_dwarf_attr (die
, &attr
);
7469 /* Create a label for an indirect string node, ensuring it is going to
7470 be output, unless its reference count goes down to zero. */
7473 gen_label_for_indirect_string (struct indirect_string_node
*node
)
7480 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
7481 ++dw2_string_counter
;
7482 node
->label
= xstrdup (label
);
7485 /* Create a SYMBOL_REF rtx whose value is the initial address of a
7486 debug string STR. */
7489 get_debug_string_label (const char *str
)
7491 struct indirect_string_node
*node
= find_AT_string (str
);
7493 debug_str_hash_forced
= true;
7495 gen_label_for_indirect_string (node
);
7497 return gen_rtx_SYMBOL_REF (Pmode
, node
->label
);
7500 static inline const char *
7501 AT_string (dw_attr_ref a
)
7503 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
7504 return a
->dw_attr_val
.v
.val_str
->str
;
7507 /* Find out whether a string should be output inline in DIE
7508 or out-of-line in .debug_str section. */
7510 static enum dwarf_form
7511 AT_string_form (dw_attr_ref a
)
7513 struct indirect_string_node
*node
;
7516 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
7518 node
= a
->dw_attr_val
.v
.val_str
;
7522 len
= strlen (node
->str
) + 1;
7524 /* If the string is shorter or equal to the size of the reference, it is
7525 always better to put it inline. */
7526 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
7527 return node
->form
= DW_FORM_string
;
7529 /* If we cannot expect the linker to merge strings in .debug_str
7530 section, only put it into .debug_str if it is worth even in this
7532 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
7533 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
7534 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
7535 return node
->form
= DW_FORM_string
;
7537 gen_label_for_indirect_string (node
);
7539 return node
->form
= DW_FORM_strp
;
7542 /* Add a DIE reference attribute value to a DIE. */
7545 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
7549 #ifdef ENABLE_CHECKING
7550 gcc_assert (targ_die
!= NULL
);
7552 /* With LTO we can end up trying to reference something we didn't create
7553 a DIE for. Avoid crashing later on a NULL referenced DIE. */
7554 if (targ_die
== NULL
)
7558 attr
.dw_attr
= attr_kind
;
7559 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
7560 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
7561 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
7562 add_dwarf_attr (die
, &attr
);
7565 /* Add an AT_specification attribute to a DIE, and also make the back
7566 pointer from the specification to the definition. */
7569 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
7571 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
7572 gcc_assert (!targ_die
->die_definition
);
7573 targ_die
->die_definition
= die
;
7576 static inline dw_die_ref
7577 AT_ref (dw_attr_ref a
)
7579 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
7580 return a
->dw_attr_val
.v
.val_die_ref
.die
;
7584 AT_ref_external (dw_attr_ref a
)
7586 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
7587 return a
->dw_attr_val
.v
.val_die_ref
.external
;
7593 set_AT_ref_external (dw_attr_ref a
, int i
)
7595 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
7596 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
7599 /* Add an FDE reference attribute value to a DIE. */
7602 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
7606 attr
.dw_attr
= attr_kind
;
7607 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
7608 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
7609 add_dwarf_attr (die
, &attr
);
7612 /* Add a location description attribute value to a DIE. */
7615 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
7619 attr
.dw_attr
= attr_kind
;
7620 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
7621 attr
.dw_attr_val
.v
.val_loc
= loc
;
7622 add_dwarf_attr (die
, &attr
);
7625 static inline dw_loc_descr_ref
7626 AT_loc (dw_attr_ref a
)
7628 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
7629 return a
->dw_attr_val
.v
.val_loc
;
7633 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
7637 attr
.dw_attr
= attr_kind
;
7638 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
7639 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
7640 add_dwarf_attr (die
, &attr
);
7641 have_location_lists
= true;
7644 static inline dw_loc_list_ref
7645 AT_loc_list (dw_attr_ref a
)
7647 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
7648 return a
->dw_attr_val
.v
.val_loc_list
;
7651 static inline dw_loc_list_ref
*
7652 AT_loc_list_ptr (dw_attr_ref a
)
7654 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
7655 return &a
->dw_attr_val
.v
.val_loc_list
;
7658 /* Add an address constant attribute value to a DIE. */
7661 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
7665 attr
.dw_attr
= attr_kind
;
7666 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
7667 attr
.dw_attr_val
.v
.val_addr
= addr
;
7668 add_dwarf_attr (die
, &attr
);
7671 /* Get the RTX from to an address DIE attribute. */
7674 AT_addr (dw_attr_ref a
)
7676 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
7677 return a
->dw_attr_val
.v
.val_addr
;
7680 /* Add a file attribute value to a DIE. */
7683 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7684 struct dwarf_file_data
*fd
)
7688 attr
.dw_attr
= attr_kind
;
7689 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
7690 attr
.dw_attr_val
.v
.val_file
= fd
;
7691 add_dwarf_attr (die
, &attr
);
7694 /* Get the dwarf_file_data from a file DIE attribute. */
7696 static inline struct dwarf_file_data
*
7697 AT_file (dw_attr_ref a
)
7699 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
7700 return a
->dw_attr_val
.v
.val_file
;
7703 /* Add a vms delta attribute value to a DIE. */
7706 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7707 const char *lbl1
, const char *lbl2
)
7711 attr
.dw_attr
= attr_kind
;
7712 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
7713 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
7714 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
7715 add_dwarf_attr (die
, &attr
);
7718 /* Add a label identifier attribute value to a DIE. */
7721 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
7725 attr
.dw_attr
= attr_kind
;
7726 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
7727 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
7728 add_dwarf_attr (die
, &attr
);
7731 /* Add a section offset attribute value to a DIE, an offset into the
7732 debug_line section. */
7735 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7740 attr
.dw_attr
= attr_kind
;
7741 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
7742 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
7743 add_dwarf_attr (die
, &attr
);
7746 /* Add a section offset attribute value to a DIE, an offset into the
7747 debug_macinfo section. */
7750 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7755 attr
.dw_attr
= attr_kind
;
7756 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
7757 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
7758 add_dwarf_attr (die
, &attr
);
7761 /* Add an offset attribute value to a DIE. */
7764 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7765 unsigned HOST_WIDE_INT offset
)
7769 attr
.dw_attr
= attr_kind
;
7770 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
7771 attr
.dw_attr_val
.v
.val_offset
= offset
;
7772 add_dwarf_attr (die
, &attr
);
7775 /* Add an range_list attribute value to a DIE. */
7778 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7779 long unsigned int offset
)
7783 attr
.dw_attr
= attr_kind
;
7784 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
7785 attr
.dw_attr_val
.v
.val_offset
= offset
;
7786 add_dwarf_attr (die
, &attr
);
7789 /* Return the start label of a delta attribute. */
7791 static inline const char *
7792 AT_vms_delta1 (dw_attr_ref a
)
7794 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
7795 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
7798 /* Return the end label of a delta attribute. */
7800 static inline const char *
7801 AT_vms_delta2 (dw_attr_ref a
)
7803 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
7804 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
7807 static inline const char *
7808 AT_lbl (dw_attr_ref a
)
7810 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
7811 || AT_class (a
) == dw_val_class_lineptr
7812 || AT_class (a
) == dw_val_class_macptr
));
7813 return a
->dw_attr_val
.v
.val_lbl_id
;
7816 /* Get the attribute of type attr_kind. */
7819 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7823 dw_die_ref spec
= NULL
;
7828 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7829 if (a
->dw_attr
== attr_kind
)
7831 else if (a
->dw_attr
== DW_AT_specification
7832 || a
->dw_attr
== DW_AT_abstract_origin
)
7836 return get_AT (spec
, attr_kind
);
7841 /* Return the "low pc" attribute value, typically associated with a subprogram
7842 DIE. Return null if the "low pc" attribute is either not present, or if it
7843 cannot be represented as an assembler label identifier. */
7845 static inline const char *
7846 get_AT_low_pc (dw_die_ref die
)
7848 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
7850 return a
? AT_lbl (a
) : NULL
;
7853 /* Return the "high pc" attribute value, typically associated with a subprogram
7854 DIE. Return null if the "high pc" attribute is either not present, or if it
7855 cannot be represented as an assembler label identifier. */
7857 static inline const char *
7858 get_AT_hi_pc (dw_die_ref die
)
7860 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
7862 return a
? AT_lbl (a
) : NULL
;
7865 /* Return the value of the string attribute designated by ATTR_KIND, or
7866 NULL if it is not present. */
7868 static inline const char *
7869 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7871 dw_attr_ref a
= get_AT (die
, attr_kind
);
7873 return a
? AT_string (a
) : NULL
;
7876 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
7877 if it is not present. */
7880 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7882 dw_attr_ref a
= get_AT (die
, attr_kind
);
7884 return a
? AT_flag (a
) : 0;
7887 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
7888 if it is not present. */
7890 static inline unsigned
7891 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7893 dw_attr_ref a
= get_AT (die
, attr_kind
);
7895 return a
? AT_unsigned (a
) : 0;
7898 static inline dw_die_ref
7899 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7901 dw_attr_ref a
= get_AT (die
, attr_kind
);
7903 return a
? AT_ref (a
) : NULL
;
7906 static inline struct dwarf_file_data
*
7907 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7909 dw_attr_ref a
= get_AT (die
, attr_kind
);
7911 return a
? AT_file (a
) : NULL
;
7914 /* Return TRUE if the language is C++. */
7919 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
7921 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
7924 /* Return TRUE if the language is Fortran. */
7929 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
7931 return (lang
== DW_LANG_Fortran77
7932 || lang
== DW_LANG_Fortran90
7933 || lang
== DW_LANG_Fortran95
);
7936 /* Return TRUE if the language is Ada. */
7941 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
7943 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
7946 /* Remove the specified attribute if present. */
7949 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7957 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
7958 if (a
->dw_attr
== attr_kind
)
7960 if (AT_class (a
) == dw_val_class_str
)
7961 if (a
->dw_attr_val
.v
.val_str
->refcount
)
7962 a
->dw_attr_val
.v
.val_str
->refcount
--;
7964 /* VEC_ordered_remove should help reduce the number of abbrevs
7966 VEC_ordered_remove (dw_attr_node
, die
->die_attr
, ix
);
7971 /* Remove CHILD from its parent. PREV must have the property that
7972 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
7975 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
7977 gcc_assert (child
->die_parent
== prev
->die_parent
);
7978 gcc_assert (prev
->die_sib
== child
);
7981 gcc_assert (child
->die_parent
->die_child
== child
);
7985 prev
->die_sib
= child
->die_sib
;
7986 if (child
->die_parent
->die_child
== child
)
7987 child
->die_parent
->die_child
= prev
;
7990 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
7991 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
7994 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
7996 dw_die_ref parent
= old_child
->die_parent
;
7998 gcc_assert (parent
== prev
->die_parent
);
7999 gcc_assert (prev
->die_sib
== old_child
);
8001 new_child
->die_parent
= parent
;
8002 if (prev
== old_child
)
8004 gcc_assert (parent
->die_child
== old_child
);
8005 new_child
->die_sib
= new_child
;
8009 prev
->die_sib
= new_child
;
8010 new_child
->die_sib
= old_child
->die_sib
;
8012 if (old_child
->die_parent
->die_child
== old_child
)
8013 old_child
->die_parent
->die_child
= new_child
;
8016 /* Move all children from OLD_PARENT to NEW_PARENT. */
8019 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
8022 new_parent
->die_child
= old_parent
->die_child
;
8023 old_parent
->die_child
= NULL
;
8024 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
8027 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
8031 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
8037 dw_die_ref prev
= c
;
8039 while (c
->die_tag
== tag
)
8041 remove_child_with_prev (c
, prev
);
8042 /* Might have removed every child. */
8043 if (c
== c
->die_sib
)
8047 } while (c
!= die
->die_child
);
8050 /* Add a CHILD_DIE as the last child of DIE. */
8053 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
8055 /* FIXME this should probably be an assert. */
8056 if (! die
|| ! child_die
)
8058 gcc_assert (die
!= child_die
);
8060 child_die
->die_parent
= die
;
8063 child_die
->die_sib
= die
->die_child
->die_sib
;
8064 die
->die_child
->die_sib
= child_die
;
8067 child_die
->die_sib
= child_die
;
8068 die
->die_child
= child_die
;
8071 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
8072 is the specification, to the end of PARENT's list of children.
8073 This is done by removing and re-adding it. */
8076 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
8080 /* We want the declaration DIE from inside the class, not the
8081 specification DIE at toplevel. */
8082 if (child
->die_parent
!= parent
)
8084 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
8090 gcc_assert (child
->die_parent
== parent
8091 || (child
->die_parent
8092 == get_AT_ref (parent
, DW_AT_specification
)));
8094 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
8095 if (p
->die_sib
== child
)
8097 remove_child_with_prev (child
, p
);
8101 add_child_die (parent
, child
);
8104 /* Return a pointer to a newly created DIE node. */
8106 static inline dw_die_ref
8107 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
8109 dw_die_ref die
= ggc_alloc_cleared_die_node ();
8111 die
->die_tag
= tag_value
;
8113 if (parent_die
!= NULL
)
8114 add_child_die (parent_die
, die
);
8117 limbo_die_node
*limbo_node
;
8119 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
8120 limbo_node
->die
= die
;
8121 limbo_node
->created_for
= t
;
8122 limbo_node
->next
= limbo_die_list
;
8123 limbo_die_list
= limbo_node
;
8129 /* Return the DIE associated with the given type specifier. */
8131 static inline dw_die_ref
8132 lookup_type_die (tree type
)
8134 return TYPE_SYMTAB_DIE (type
);
8137 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
8138 anonymous type named by the typedef TYPE_DIE, return the DIE of the
8139 anonymous type instead the one of the naming typedef. */
8141 static inline dw_die_ref
8142 strip_naming_typedef (tree type
, dw_die_ref type_die
)
8145 && TREE_CODE (type
) == RECORD_TYPE
8147 && type_die
->die_tag
== DW_TAG_typedef
8148 && is_naming_typedef_decl (TYPE_NAME (type
)))
8149 type_die
= get_AT_ref (type_die
, DW_AT_type
);
8153 /* Like lookup_type_die, but if type is an anonymous type named by a
8154 typedef[1], return the DIE of the anonymous type instead the one of
8155 the naming typedef. This is because in gen_typedef_die, we did
8156 equate the anonymous struct named by the typedef with the DIE of
8157 the naming typedef. So by default, lookup_type_die on an anonymous
8158 struct yields the DIE of the naming typedef.
8160 [1]: Read the comment of is_naming_typedef_decl to learn about what
8161 a naming typedef is. */
8163 static inline dw_die_ref
8164 lookup_type_die_strip_naming_typedef (tree type
)
8166 dw_die_ref die
= lookup_type_die (type
);
8167 return strip_naming_typedef (type
, die
);
8170 /* Equate a DIE to a given type specifier. */
8173 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
8175 TYPE_SYMTAB_DIE (type
) = type_die
;
8178 /* Returns a hash value for X (which really is a die_struct). */
8181 decl_die_table_hash (const void *x
)
8183 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
8186 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
8189 decl_die_table_eq (const void *x
, const void *y
)
8191 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
8194 /* Return the DIE associated with a given declaration. */
8196 static inline dw_die_ref
8197 lookup_decl_die (tree decl
)
8199 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
8202 /* Returns a hash value for X (which really is a var_loc_list). */
8205 decl_loc_table_hash (const void *x
)
8207 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
8210 /* Return nonzero if decl_id of var_loc_list X is the same as
8214 decl_loc_table_eq (const void *x
, const void *y
)
8216 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
8219 /* Return the var_loc list associated with a given declaration. */
8221 static inline var_loc_list
*
8222 lookup_decl_loc (const_tree decl
)
8224 if (!decl_loc_table
)
8226 return (var_loc_list
*)
8227 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
8230 /* Equate a DIE to a particular declaration. */
8233 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
8235 unsigned int decl_id
= DECL_UID (decl
);
8238 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
8240 decl_die
->decl_id
= decl_id
;
8243 /* Return how many bits covers PIECE EXPR_LIST. */
8246 decl_piece_bitsize (rtx piece
)
8248 int ret
= (int) GET_MODE (piece
);
8251 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
8252 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
8253 return INTVAL (XEXP (XEXP (piece
, 0), 0));
8256 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
8259 decl_piece_varloc_ptr (rtx piece
)
8261 if ((int) GET_MODE (piece
))
8262 return &XEXP (piece
, 0);
8264 return &XEXP (XEXP (piece
, 0), 1);
8267 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
8268 Next is the chain of following piece nodes. */
8271 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
8273 if (bitsize
<= (int) MAX_MACHINE_MODE
)
8274 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
8276 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
8281 /* Return rtx that should be stored into loc field for
8282 LOC_NOTE and BITPOS/BITSIZE. */
8285 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
8286 HOST_WIDE_INT bitsize
)
8290 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
8292 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
8297 /* This function either modifies location piece list *DEST in
8298 place (if SRC and INNER is NULL), or copies location piece list
8299 *SRC to *DEST while modifying it. Location BITPOS is modified
8300 to contain LOC_NOTE, any pieces overlapping it are removed resp.
8301 not copied and if needed some padding around it is added.
8302 When modifying in place, DEST should point to EXPR_LIST where
8303 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
8304 to the start of the whole list and INNER points to the EXPR_LIST
8305 where earlier pieces cover PIECE_BITPOS bits. */
8308 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
8309 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
8310 HOST_WIDE_INT bitsize
, rtx loc_note
)
8313 bool copy
= inner
!= NULL
;
8317 /* First copy all nodes preceeding the current bitpos. */
8318 while (src
!= inner
)
8320 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
8321 decl_piece_bitsize (*src
), NULL_RTX
);
8322 dest
= &XEXP (*dest
, 1);
8323 src
= &XEXP (*src
, 1);
8326 /* Add padding if needed. */
8327 if (bitpos
!= piece_bitpos
)
8329 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
8330 copy
? NULL_RTX
: *dest
);
8331 dest
= &XEXP (*dest
, 1);
8333 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
8336 /* A piece with correct bitpos and bitsize already exist,
8337 just update the location for it and return. */
8338 *decl_piece_varloc_ptr (*dest
) = loc_note
;
8341 /* Add the piece that changed. */
8342 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
8343 dest
= &XEXP (*dest
, 1);
8344 /* Skip over pieces that overlap it. */
8345 diff
= bitpos
- piece_bitpos
+ bitsize
;
8348 while (diff
> 0 && *src
)
8351 diff
-= decl_piece_bitsize (piece
);
8353 src
= &XEXP (piece
, 1);
8356 *src
= XEXP (piece
, 1);
8357 free_EXPR_LIST_node (piece
);
8360 /* Add padding if needed. */
8361 if (diff
< 0 && *src
)
8365 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
8366 dest
= &XEXP (*dest
, 1);
8370 /* Finally copy all nodes following it. */
8373 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
8374 decl_piece_bitsize (*src
), NULL_RTX
);
8375 dest
= &XEXP (*dest
, 1);
8376 src
= &XEXP (*src
, 1);
8380 /* Add a variable location node to the linked list for DECL. */
8382 static struct var_loc_node
*
8383 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
8385 unsigned int decl_id
;
8388 struct var_loc_node
*loc
= NULL
;
8389 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
8391 if (DECL_DEBUG_EXPR_IS_FROM (decl
))
8393 tree realdecl
= DECL_DEBUG_EXPR (decl
);
8394 if (realdecl
&& handled_component_p (realdecl
))
8396 HOST_WIDE_INT maxsize
;
8399 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
8400 if (!DECL_P (innerdecl
)
8401 || DECL_IGNORED_P (innerdecl
)
8402 || TREE_STATIC (innerdecl
)
8404 || bitpos
+ bitsize
> 256
8405 || bitsize
!= maxsize
)
8411 decl_id
= DECL_UID (decl
);
8412 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
8415 temp
= ggc_alloc_cleared_var_loc_list ();
8416 temp
->decl_id
= decl_id
;
8420 temp
= (var_loc_list
*) *slot
;
8424 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
8425 rtx
*piece_loc
= NULL
, last_loc_note
;
8426 int piece_bitpos
= 0;
8430 gcc_assert (last
->next
== NULL
);
8432 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
8434 piece_loc
= &last
->loc
;
8437 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
8438 if (piece_bitpos
+ cur_bitsize
> bitpos
)
8440 piece_bitpos
+= cur_bitsize
;
8441 piece_loc
= &XEXP (*piece_loc
, 1);
8445 /* TEMP->LAST here is either pointer to the last but one or
8446 last element in the chained list, LAST is pointer to the
8448 if (label
&& strcmp (last
->label
, label
) == 0)
8450 /* For SRA optimized variables if there weren't any real
8451 insns since last note, just modify the last node. */
8452 if (piece_loc
!= NULL
)
8454 adjust_piece_list (piece_loc
, NULL
, NULL
,
8455 bitpos
, piece_bitpos
, bitsize
, loc_note
);
8458 /* If the last note doesn't cover any instructions, remove it. */
8459 if (temp
->last
!= last
)
8461 temp
->last
->next
= NULL
;
8464 gcc_assert (strcmp (last
->label
, label
) != 0);
8468 gcc_assert (temp
->first
== temp
->last
);
8469 memset (temp
->last
, '\0', sizeof (*temp
->last
));
8470 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
8474 if (bitsize
== -1 && NOTE_P (last
->loc
))
8475 last_loc_note
= last
->loc
;
8476 else if (piece_loc
!= NULL
8477 && *piece_loc
!= NULL_RTX
8478 && piece_bitpos
== bitpos
8479 && decl_piece_bitsize (*piece_loc
) == bitsize
)
8480 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
8482 last_loc_note
= NULL_RTX
;
8483 /* If the current location is the same as the end of the list,
8484 and either both or neither of the locations is uninitialized,
8485 we have nothing to do. */
8486 if (last_loc_note
== NULL_RTX
8487 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
8488 NOTE_VAR_LOCATION_LOC (loc_note
)))
8489 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
8490 != NOTE_VAR_LOCATION_STATUS (loc_note
))
8491 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
8492 == VAR_INIT_STATUS_UNINITIALIZED
)
8493 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
8494 == VAR_INIT_STATUS_UNINITIALIZED
))))
8496 /* Add LOC to the end of list and update LAST. If the last
8497 element of the list has been removed above, reuse its
8498 memory for the new node, otherwise allocate a new one. */
8502 memset (loc
, '\0', sizeof (*loc
));
8505 loc
= ggc_alloc_cleared_var_loc_node ();
8506 if (bitsize
== -1 || piece_loc
== NULL
)
8507 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
8509 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
8510 bitpos
, piece_bitpos
, bitsize
, loc_note
);
8512 /* Ensure TEMP->LAST will point either to the new last but one
8513 element of the chain, or to the last element in it. */
8514 if (last
!= temp
->last
)
8522 loc
= ggc_alloc_cleared_var_loc_node ();
8525 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
8530 /* Keep track of the number of spaces used to indent the
8531 output of the debugging routines that print the structure of
8532 the DIE internal representation. */
8533 static int print_indent
;
8535 /* Indent the line the number of spaces given by print_indent. */
8538 print_spaces (FILE *outfile
)
8540 fprintf (outfile
, "%*s", print_indent
, "");
8543 /* Print a type signature in hex. */
8546 print_signature (FILE *outfile
, char *sig
)
8550 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8551 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
8554 /* Print the information associated with a given DIE, and its children.
8555 This routine is a debugging aid only. */
8558 print_die (dw_die_ref die
, FILE *outfile
)
8564 print_spaces (outfile
);
8565 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
8566 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
8568 print_spaces (outfile
);
8569 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
8570 fprintf (outfile
, " offset: %ld", die
->die_offset
);
8571 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
8573 if (dwarf_version
>= 4 && die
->die_id
.die_type_node
)
8575 print_spaces (outfile
);
8576 fprintf (outfile
, " signature: ");
8577 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
8578 fprintf (outfile
, "\n");
8581 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
8583 print_spaces (outfile
);
8584 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
8586 switch (AT_class (a
))
8588 case dw_val_class_addr
:
8589 fprintf (outfile
, "address");
8591 case dw_val_class_offset
:
8592 fprintf (outfile
, "offset");
8594 case dw_val_class_loc
:
8595 fprintf (outfile
, "location descriptor");
8597 case dw_val_class_loc_list
:
8598 fprintf (outfile
, "location list -> label:%s",
8599 AT_loc_list (a
)->ll_symbol
);
8601 case dw_val_class_range_list
:
8602 fprintf (outfile
, "range list");
8604 case dw_val_class_const
:
8605 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
8607 case dw_val_class_unsigned_const
:
8608 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
8610 case dw_val_class_const_double
:
8611 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
8612 HOST_WIDE_INT_PRINT_UNSIGNED
")",
8613 a
->dw_attr_val
.v
.val_double
.high
,
8614 a
->dw_attr_val
.v
.val_double
.low
);
8616 case dw_val_class_vec
:
8617 fprintf (outfile
, "floating-point or vector constant");
8619 case dw_val_class_flag
:
8620 fprintf (outfile
, "%u", AT_flag (a
));
8622 case dw_val_class_die_ref
:
8623 if (AT_ref (a
) != NULL
)
8625 if (dwarf_version
>= 4 && AT_ref (a
)->die_id
.die_type_node
)
8627 fprintf (outfile
, "die -> signature: ");
8628 print_signature (outfile
,
8629 AT_ref (a
)->die_id
.die_type_node
->signature
);
8631 else if (dwarf_version
< 4 && AT_ref (a
)->die_id
.die_symbol
)
8632 fprintf (outfile
, "die -> label: %s",
8633 AT_ref (a
)->die_id
.die_symbol
);
8635 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
8636 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
8639 fprintf (outfile
, "die -> <null>");
8641 case dw_val_class_vms_delta
:
8642 fprintf (outfile
, "delta: @slotcount(%s-%s)",
8643 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
8645 case dw_val_class_lbl_id
:
8646 case dw_val_class_lineptr
:
8647 case dw_val_class_macptr
:
8648 fprintf (outfile
, "label: %s", AT_lbl (a
));
8650 case dw_val_class_str
:
8651 if (AT_string (a
) != NULL
)
8652 fprintf (outfile
, "\"%s\"", AT_string (a
));
8654 fprintf (outfile
, "<null>");
8656 case dw_val_class_file
:
8657 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
8658 AT_file (a
)->emitted_number
);
8660 case dw_val_class_data8
:
8664 for (i
= 0; i
< 8; i
++)
8665 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
8672 fprintf (outfile
, "\n");
8675 if (die
->die_child
!= NULL
)
8678 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
8681 if (print_indent
== 0)
8682 fprintf (outfile
, "\n");
8685 /* Print the contents of the source code line number correspondence table.
8686 This routine is a debugging aid only. */
8689 print_dwarf_line_table (FILE *outfile
)
8692 dw_line_info_ref line_info
;
8694 fprintf (outfile
, "\n\nDWARF source line information\n");
8695 for (i
= 1; i
< line_info_table_in_use
; i
++)
8697 line_info
= &line_info_table
[i
];
8698 fprintf (outfile
, "%5d: %4ld %6ld\n", i
,
8699 line_info
->dw_file_num
,
8700 line_info
->dw_line_num
);
8703 fprintf (outfile
, "\n\n");
8706 /* Print the information collected for a given DIE. */
8709 debug_dwarf_die (dw_die_ref die
)
8711 print_die (die
, stderr
);
8714 /* Print all DWARF information collected for the compilation unit.
8715 This routine is a debugging aid only. */
8721 print_die (comp_unit_die (), stderr
);
8722 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
8723 print_dwarf_line_table (stderr
);
8726 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
8727 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
8728 DIE that marks the start of the DIEs for this include file. */
8731 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
8733 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
8734 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
8736 new_unit
->die_sib
= old_unit
;
8740 /* Close an include-file CU and reopen the enclosing one. */
8743 pop_compile_unit (dw_die_ref old_unit
)
8745 dw_die_ref new_unit
= old_unit
->die_sib
;
8747 old_unit
->die_sib
= NULL
;
8751 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8752 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
8754 /* Calculate the checksum of a location expression. */
8757 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
8761 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
8763 CHECKSUM (loc
->dw_loc_oprnd1
);
8764 CHECKSUM (loc
->dw_loc_oprnd2
);
8767 /* Calculate the checksum of an attribute. */
8770 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
8772 dw_loc_descr_ref loc
;
8775 CHECKSUM (at
->dw_attr
);
8777 /* We don't care that this was compiled with a different compiler
8778 snapshot; if the output is the same, that's what matters. */
8779 if (at
->dw_attr
== DW_AT_producer
)
8782 switch (AT_class (at
))
8784 case dw_val_class_const
:
8785 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
8787 case dw_val_class_unsigned_const
:
8788 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
8790 case dw_val_class_const_double
:
8791 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
8793 case dw_val_class_vec
:
8794 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
8796 case dw_val_class_flag
:
8797 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
8799 case dw_val_class_str
:
8800 CHECKSUM_STRING (AT_string (at
));
8803 case dw_val_class_addr
:
8805 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
8806 CHECKSUM_STRING (XSTR (r
, 0));
8809 case dw_val_class_offset
:
8810 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
8813 case dw_val_class_loc
:
8814 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
8815 loc_checksum (loc
, ctx
);
8818 case dw_val_class_die_ref
:
8819 die_checksum (AT_ref (at
), ctx
, mark
);
8822 case dw_val_class_fde_ref
:
8823 case dw_val_class_vms_delta
:
8824 case dw_val_class_lbl_id
:
8825 case dw_val_class_lineptr
:
8826 case dw_val_class_macptr
:
8829 case dw_val_class_file
:
8830 CHECKSUM_STRING (AT_file (at
)->filename
);
8833 case dw_val_class_data8
:
8834 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
8842 /* Calculate the checksum of a DIE. */
8845 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
8851 /* To avoid infinite recursion. */
8854 CHECKSUM (die
->die_mark
);
8857 die
->die_mark
= ++(*mark
);
8859 CHECKSUM (die
->die_tag
);
8861 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
8862 attr_checksum (a
, ctx
, mark
);
8864 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
8868 #undef CHECKSUM_STRING
8870 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
8871 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8872 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
8873 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
8874 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
8875 #define CHECKSUM_ATTR(FOO) \
8876 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
8878 /* Calculate the checksum of a number in signed LEB128 format. */
8881 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
8888 byte
= (value
& 0x7f);
8890 more
= !((value
== 0 && (byte
& 0x40) == 0)
8891 || (value
== -1 && (byte
& 0x40) != 0));
8900 /* Calculate the checksum of a number in unsigned LEB128 format. */
8903 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
8907 unsigned char byte
= (value
& 0x7f);
8910 /* More bytes to follow. */
8918 /* Checksum the context of the DIE. This adds the names of any
8919 surrounding namespaces or structures to the checksum. */
8922 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
8926 int tag
= die
->die_tag
;
8928 if (tag
!= DW_TAG_namespace
8929 && tag
!= DW_TAG_structure_type
8930 && tag
!= DW_TAG_class_type
)
8933 name
= get_AT_string (die
, DW_AT_name
);
8935 spec
= get_AT_ref (die
, DW_AT_specification
);
8939 if (die
->die_parent
!= NULL
)
8940 checksum_die_context (die
->die_parent
, ctx
);
8942 CHECKSUM_ULEB128 ('C');
8943 CHECKSUM_ULEB128 (tag
);
8945 CHECKSUM_STRING (name
);
8948 /* Calculate the checksum of a location expression. */
8951 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
8953 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
8954 were emitted as a DW_FORM_sdata instead of a location expression. */
8955 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
8957 CHECKSUM_ULEB128 (DW_FORM_sdata
);
8958 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
8962 /* Otherwise, just checksum the raw location expression. */
8965 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
8966 CHECKSUM (loc
->dw_loc_oprnd1
);
8967 CHECKSUM (loc
->dw_loc_oprnd2
);
8968 loc
= loc
->dw_loc_next
;
8972 /* Calculate the checksum of an attribute. */
8975 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
8976 struct md5_ctx
*ctx
, int *mark
)
8978 dw_loc_descr_ref loc
;
8981 if (AT_class (at
) == dw_val_class_die_ref
)
8983 dw_die_ref target_die
= AT_ref (at
);
8985 /* For pointer and reference types, we checksum only the (qualified)
8986 name of the target type (if there is a name). For friend entries,
8987 we checksum only the (qualified) name of the target type or function.
8988 This allows the checksum to remain the same whether the target type
8989 is complete or not. */
8990 if ((at
->dw_attr
== DW_AT_type
8991 && (tag
== DW_TAG_pointer_type
8992 || tag
== DW_TAG_reference_type
8993 || tag
== DW_TAG_rvalue_reference_type
8994 || tag
== DW_TAG_ptr_to_member_type
))
8995 || (at
->dw_attr
== DW_AT_friend
8996 && tag
== DW_TAG_friend
))
8998 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
9000 if (name_attr
!= NULL
)
9002 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
9006 CHECKSUM_ULEB128 ('N');
9007 CHECKSUM_ULEB128 (at
->dw_attr
);
9008 if (decl
->die_parent
!= NULL
)
9009 checksum_die_context (decl
->die_parent
, ctx
);
9010 CHECKSUM_ULEB128 ('E');
9011 CHECKSUM_STRING (AT_string (name_attr
));
9016 /* For all other references to another DIE, we check to see if the
9017 target DIE has already been visited. If it has, we emit a
9018 backward reference; if not, we descend recursively. */
9019 if (target_die
->die_mark
> 0)
9021 CHECKSUM_ULEB128 ('R');
9022 CHECKSUM_ULEB128 (at
->dw_attr
);
9023 CHECKSUM_ULEB128 (target_die
->die_mark
);
9027 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
9031 target_die
->die_mark
= ++(*mark
);
9032 CHECKSUM_ULEB128 ('T');
9033 CHECKSUM_ULEB128 (at
->dw_attr
);
9034 if (decl
->die_parent
!= NULL
)
9035 checksum_die_context (decl
->die_parent
, ctx
);
9036 die_checksum_ordered (target_die
, ctx
, mark
);
9041 CHECKSUM_ULEB128 ('A');
9042 CHECKSUM_ULEB128 (at
->dw_attr
);
9044 switch (AT_class (at
))
9046 case dw_val_class_const
:
9047 CHECKSUM_ULEB128 (DW_FORM_sdata
);
9048 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
9051 case dw_val_class_unsigned_const
:
9052 CHECKSUM_ULEB128 (DW_FORM_sdata
);
9053 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
9056 case dw_val_class_const_double
:
9057 CHECKSUM_ULEB128 (DW_FORM_block
);
9058 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
9059 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
9062 case dw_val_class_vec
:
9063 CHECKSUM_ULEB128 (DW_FORM_block
);
9064 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_vec
));
9065 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
9068 case dw_val_class_flag
:
9069 CHECKSUM_ULEB128 (DW_FORM_flag
);
9070 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
9073 case dw_val_class_str
:
9074 CHECKSUM_ULEB128 (DW_FORM_string
);
9075 CHECKSUM_STRING (AT_string (at
));
9078 case dw_val_class_addr
:
9080 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
9081 CHECKSUM_ULEB128 (DW_FORM_string
);
9082 CHECKSUM_STRING (XSTR (r
, 0));
9085 case dw_val_class_offset
:
9086 CHECKSUM_ULEB128 (DW_FORM_sdata
);
9087 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
9090 case dw_val_class_loc
:
9091 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
9092 loc_checksum_ordered (loc
, ctx
);
9095 case dw_val_class_fde_ref
:
9096 case dw_val_class_lbl_id
:
9097 case dw_val_class_lineptr
:
9098 case dw_val_class_macptr
:
9101 case dw_val_class_file
:
9102 CHECKSUM_ULEB128 (DW_FORM_string
);
9103 CHECKSUM_STRING (AT_file (at
)->filename
);
9106 case dw_val_class_data8
:
9107 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
9115 struct checksum_attributes
9117 dw_attr_ref at_name
;
9118 dw_attr_ref at_type
;
9119 dw_attr_ref at_friend
;
9120 dw_attr_ref at_accessibility
;
9121 dw_attr_ref at_address_class
;
9122 dw_attr_ref at_allocated
;
9123 dw_attr_ref at_artificial
;
9124 dw_attr_ref at_associated
;
9125 dw_attr_ref at_binary_scale
;
9126 dw_attr_ref at_bit_offset
;
9127 dw_attr_ref at_bit_size
;
9128 dw_attr_ref at_bit_stride
;
9129 dw_attr_ref at_byte_size
;
9130 dw_attr_ref at_byte_stride
;
9131 dw_attr_ref at_const_value
;
9132 dw_attr_ref at_containing_type
;
9133 dw_attr_ref at_count
;
9134 dw_attr_ref at_data_location
;
9135 dw_attr_ref at_data_member_location
;
9136 dw_attr_ref at_decimal_scale
;
9137 dw_attr_ref at_decimal_sign
;
9138 dw_attr_ref at_default_value
;
9139 dw_attr_ref at_digit_count
;
9140 dw_attr_ref at_discr
;
9141 dw_attr_ref at_discr_list
;
9142 dw_attr_ref at_discr_value
;
9143 dw_attr_ref at_encoding
;
9144 dw_attr_ref at_endianity
;
9145 dw_attr_ref at_explicit
;
9146 dw_attr_ref at_is_optional
;
9147 dw_attr_ref at_location
;
9148 dw_attr_ref at_lower_bound
;
9149 dw_attr_ref at_mutable
;
9150 dw_attr_ref at_ordering
;
9151 dw_attr_ref at_picture_string
;
9152 dw_attr_ref at_prototyped
;
9153 dw_attr_ref at_small
;
9154 dw_attr_ref at_segment
;
9155 dw_attr_ref at_string_length
;
9156 dw_attr_ref at_threads_scaled
;
9157 dw_attr_ref at_upper_bound
;
9158 dw_attr_ref at_use_location
;
9159 dw_attr_ref at_use_UTF8
;
9160 dw_attr_ref at_variable_parameter
;
9161 dw_attr_ref at_virtuality
;
9162 dw_attr_ref at_visibility
;
9163 dw_attr_ref at_vtable_elem_location
;
9166 /* Collect the attributes that we will want to use for the checksum. */
9169 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
9174 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
9185 attrs
->at_friend
= a
;
9187 case DW_AT_accessibility
:
9188 attrs
->at_accessibility
= a
;
9190 case DW_AT_address_class
:
9191 attrs
->at_address_class
= a
;
9193 case DW_AT_allocated
:
9194 attrs
->at_allocated
= a
;
9196 case DW_AT_artificial
:
9197 attrs
->at_artificial
= a
;
9199 case DW_AT_associated
:
9200 attrs
->at_associated
= a
;
9202 case DW_AT_binary_scale
:
9203 attrs
->at_binary_scale
= a
;
9205 case DW_AT_bit_offset
:
9206 attrs
->at_bit_offset
= a
;
9208 case DW_AT_bit_size
:
9209 attrs
->at_bit_size
= a
;
9211 case DW_AT_bit_stride
:
9212 attrs
->at_bit_stride
= a
;
9214 case DW_AT_byte_size
:
9215 attrs
->at_byte_size
= a
;
9217 case DW_AT_byte_stride
:
9218 attrs
->at_byte_stride
= a
;
9220 case DW_AT_const_value
:
9221 attrs
->at_const_value
= a
;
9223 case DW_AT_containing_type
:
9224 attrs
->at_containing_type
= a
;
9227 attrs
->at_count
= a
;
9229 case DW_AT_data_location
:
9230 attrs
->at_data_location
= a
;
9232 case DW_AT_data_member_location
:
9233 attrs
->at_data_member_location
= a
;
9235 case DW_AT_decimal_scale
:
9236 attrs
->at_decimal_scale
= a
;
9238 case DW_AT_decimal_sign
:
9239 attrs
->at_decimal_sign
= a
;
9241 case DW_AT_default_value
:
9242 attrs
->at_default_value
= a
;
9244 case DW_AT_digit_count
:
9245 attrs
->at_digit_count
= a
;
9248 attrs
->at_discr
= a
;
9250 case DW_AT_discr_list
:
9251 attrs
->at_discr_list
= a
;
9253 case DW_AT_discr_value
:
9254 attrs
->at_discr_value
= a
;
9256 case DW_AT_encoding
:
9257 attrs
->at_encoding
= a
;
9259 case DW_AT_endianity
:
9260 attrs
->at_endianity
= a
;
9262 case DW_AT_explicit
:
9263 attrs
->at_explicit
= a
;
9265 case DW_AT_is_optional
:
9266 attrs
->at_is_optional
= a
;
9268 case DW_AT_location
:
9269 attrs
->at_location
= a
;
9271 case DW_AT_lower_bound
:
9272 attrs
->at_lower_bound
= a
;
9275 attrs
->at_mutable
= a
;
9277 case DW_AT_ordering
:
9278 attrs
->at_ordering
= a
;
9280 case DW_AT_picture_string
:
9281 attrs
->at_picture_string
= a
;
9283 case DW_AT_prototyped
:
9284 attrs
->at_prototyped
= a
;
9287 attrs
->at_small
= a
;
9290 attrs
->at_segment
= a
;
9292 case DW_AT_string_length
:
9293 attrs
->at_string_length
= a
;
9295 case DW_AT_threads_scaled
:
9296 attrs
->at_threads_scaled
= a
;
9298 case DW_AT_upper_bound
:
9299 attrs
->at_upper_bound
= a
;
9301 case DW_AT_use_location
:
9302 attrs
->at_use_location
= a
;
9304 case DW_AT_use_UTF8
:
9305 attrs
->at_use_UTF8
= a
;
9307 case DW_AT_variable_parameter
:
9308 attrs
->at_variable_parameter
= a
;
9310 case DW_AT_virtuality
:
9311 attrs
->at_virtuality
= a
;
9313 case DW_AT_visibility
:
9314 attrs
->at_visibility
= a
;
9316 case DW_AT_vtable_elem_location
:
9317 attrs
->at_vtable_elem_location
= a
;
9325 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
9328 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
9332 struct checksum_attributes attrs
;
9334 CHECKSUM_ULEB128 ('D');
9335 CHECKSUM_ULEB128 (die
->die_tag
);
9337 memset (&attrs
, 0, sizeof (attrs
));
9339 decl
= get_AT_ref (die
, DW_AT_specification
);
9341 collect_checksum_attributes (&attrs
, decl
);
9342 collect_checksum_attributes (&attrs
, die
);
9344 CHECKSUM_ATTR (attrs
.at_name
);
9345 CHECKSUM_ATTR (attrs
.at_accessibility
);
9346 CHECKSUM_ATTR (attrs
.at_address_class
);
9347 CHECKSUM_ATTR (attrs
.at_allocated
);
9348 CHECKSUM_ATTR (attrs
.at_artificial
);
9349 CHECKSUM_ATTR (attrs
.at_associated
);
9350 CHECKSUM_ATTR (attrs
.at_binary_scale
);
9351 CHECKSUM_ATTR (attrs
.at_bit_offset
);
9352 CHECKSUM_ATTR (attrs
.at_bit_size
);
9353 CHECKSUM_ATTR (attrs
.at_bit_stride
);
9354 CHECKSUM_ATTR (attrs
.at_byte_size
);
9355 CHECKSUM_ATTR (attrs
.at_byte_stride
);
9356 CHECKSUM_ATTR (attrs
.at_const_value
);
9357 CHECKSUM_ATTR (attrs
.at_containing_type
);
9358 CHECKSUM_ATTR (attrs
.at_count
);
9359 CHECKSUM_ATTR (attrs
.at_data_location
);
9360 CHECKSUM_ATTR (attrs
.at_data_member_location
);
9361 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
9362 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
9363 CHECKSUM_ATTR (attrs
.at_default_value
);
9364 CHECKSUM_ATTR (attrs
.at_digit_count
);
9365 CHECKSUM_ATTR (attrs
.at_discr
);
9366 CHECKSUM_ATTR (attrs
.at_discr_list
);
9367 CHECKSUM_ATTR (attrs
.at_discr_value
);
9368 CHECKSUM_ATTR (attrs
.at_encoding
);
9369 CHECKSUM_ATTR (attrs
.at_endianity
);
9370 CHECKSUM_ATTR (attrs
.at_explicit
);
9371 CHECKSUM_ATTR (attrs
.at_is_optional
);
9372 CHECKSUM_ATTR (attrs
.at_location
);
9373 CHECKSUM_ATTR (attrs
.at_lower_bound
);
9374 CHECKSUM_ATTR (attrs
.at_mutable
);
9375 CHECKSUM_ATTR (attrs
.at_ordering
);
9376 CHECKSUM_ATTR (attrs
.at_picture_string
);
9377 CHECKSUM_ATTR (attrs
.at_prototyped
);
9378 CHECKSUM_ATTR (attrs
.at_small
);
9379 CHECKSUM_ATTR (attrs
.at_segment
);
9380 CHECKSUM_ATTR (attrs
.at_string_length
);
9381 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
9382 CHECKSUM_ATTR (attrs
.at_upper_bound
);
9383 CHECKSUM_ATTR (attrs
.at_use_location
);
9384 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
9385 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
9386 CHECKSUM_ATTR (attrs
.at_virtuality
);
9387 CHECKSUM_ATTR (attrs
.at_visibility
);
9388 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
9389 CHECKSUM_ATTR (attrs
.at_type
);
9390 CHECKSUM_ATTR (attrs
.at_friend
);
9392 /* Checksum the child DIEs, except for nested types and member functions. */
9395 dw_attr_ref name_attr
;
9398 name_attr
= get_AT (c
, DW_AT_name
);
9399 if ((is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
)
9400 && name_attr
!= NULL
)
9402 CHECKSUM_ULEB128 ('S');
9403 CHECKSUM_ULEB128 (c
->die_tag
);
9404 CHECKSUM_STRING (AT_string (name_attr
));
9408 /* Mark this DIE so it gets processed when unmarking. */
9409 if (c
->die_mark
== 0)
9411 die_checksum_ordered (c
, ctx
, mark
);
9413 } while (c
!= die
->die_child
);
9415 CHECKSUM_ULEB128 (0);
9419 #undef CHECKSUM_STRING
9420 #undef CHECKSUM_ATTR
9421 #undef CHECKSUM_LEB128
9422 #undef CHECKSUM_ULEB128
9424 /* Generate the type signature for DIE. This is computed by generating an
9425 MD5 checksum over the DIE's tag, its relevant attributes, and its
9426 children. Attributes that are references to other DIEs are processed
9427 by recursion, using the MARK field to prevent infinite recursion.
9428 If the DIE is nested inside a namespace or another type, we also
9429 need to include that context in the signature. The lower 64 bits
9430 of the resulting MD5 checksum comprise the signature. */
9433 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
9437 unsigned char checksum
[16];
9441 name
= get_AT_string (die
, DW_AT_name
);
9442 decl
= get_AT_ref (die
, DW_AT_specification
);
9444 /* First, compute a signature for just the type name (and its surrounding
9445 context, if any. This is stored in the type unit DIE for link-time
9446 ODR (one-definition rule) checking. */
9448 if (is_cxx() && name
!= NULL
)
9450 md5_init_ctx (&ctx
);
9452 /* Checksum the names of surrounding namespaces and structures. */
9453 if (decl
!= NULL
&& decl
->die_parent
!= NULL
)
9454 checksum_die_context (decl
->die_parent
, &ctx
);
9456 md5_process_bytes (&die
->die_tag
, sizeof (die
->die_tag
), &ctx
);
9457 md5_process_bytes (name
, strlen (name
) + 1, &ctx
);
9458 md5_finish_ctx (&ctx
, checksum
);
9460 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
9463 /* Next, compute the complete type signature. */
9465 md5_init_ctx (&ctx
);
9467 die
->die_mark
= mark
;
9469 /* Checksum the names of surrounding namespaces and structures. */
9470 if (decl
!= NULL
&& decl
->die_parent
!= NULL
)
9471 checksum_die_context (decl
->die_parent
, &ctx
);
9473 /* Checksum the DIE and its children. */
9474 die_checksum_ordered (die
, &ctx
, &mark
);
9475 unmark_all_dies (die
);
9476 md5_finish_ctx (&ctx
, checksum
);
9478 /* Store the signature in the type node and link the type DIE and the
9479 type node together. */
9480 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
9481 DWARF_TYPE_SIGNATURE_SIZE
);
9482 die
->die_id
.die_type_node
= type_node
;
9483 type_node
->type_die
= die
;
9485 /* If the DIE is a specification, link its declaration to the type node
9488 decl
->die_id
.die_type_node
= type_node
;
9491 /* Do the location expressions look same? */
9493 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
9495 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
9496 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
9497 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
9500 /* Do the values look the same? */
9502 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
9504 dw_loc_descr_ref loc1
, loc2
;
9507 if (v1
->val_class
!= v2
->val_class
)
9510 switch (v1
->val_class
)
9512 case dw_val_class_const
:
9513 return v1
->v
.val_int
== v2
->v
.val_int
;
9514 case dw_val_class_unsigned_const
:
9515 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
9516 case dw_val_class_const_double
:
9517 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
9518 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
9519 case dw_val_class_vec
:
9520 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
9521 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
9523 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
9524 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
9527 case dw_val_class_flag
:
9528 return v1
->v
.val_flag
== v2
->v
.val_flag
;
9529 case dw_val_class_str
:
9530 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
9532 case dw_val_class_addr
:
9533 r1
= v1
->v
.val_addr
;
9534 r2
= v2
->v
.val_addr
;
9535 if (GET_CODE (r1
) != GET_CODE (r2
))
9537 return !rtx_equal_p (r1
, r2
);
9539 case dw_val_class_offset
:
9540 return v1
->v
.val_offset
== v2
->v
.val_offset
;
9542 case dw_val_class_loc
:
9543 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
9545 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
9546 if (!same_loc_p (loc1
, loc2
, mark
))
9548 return !loc1
&& !loc2
;
9550 case dw_val_class_die_ref
:
9551 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
9553 case dw_val_class_fde_ref
:
9554 case dw_val_class_vms_delta
:
9555 case dw_val_class_lbl_id
:
9556 case dw_val_class_lineptr
:
9557 case dw_val_class_macptr
:
9560 case dw_val_class_file
:
9561 return v1
->v
.val_file
== v2
->v
.val_file
;
9563 case dw_val_class_data8
:
9564 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
9571 /* Do the attributes look the same? */
9574 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
9576 if (at1
->dw_attr
!= at2
->dw_attr
)
9579 /* We don't care that this was compiled with a different compiler
9580 snapshot; if the output is the same, that's what matters. */
9581 if (at1
->dw_attr
== DW_AT_producer
)
9584 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
9587 /* Do the dies look the same? */
9590 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
9596 /* To avoid infinite recursion. */
9598 return die1
->die_mark
== die2
->die_mark
;
9599 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
9601 if (die1
->die_tag
!= die2
->die_tag
)
9604 if (VEC_length (dw_attr_node
, die1
->die_attr
)
9605 != VEC_length (dw_attr_node
, die2
->die_attr
))
9608 FOR_EACH_VEC_ELT (dw_attr_node
, die1
->die_attr
, ix
, a1
)
9609 if (!same_attr_p (a1
, VEC_index (dw_attr_node
, die2
->die_attr
, ix
), mark
))
9612 c1
= die1
->die_child
;
9613 c2
= die2
->die_child
;
9622 if (!same_die_p (c1
, c2
, mark
))
9626 if (c1
== die1
->die_child
)
9628 if (c2
== die2
->die_child
)
9638 /* Do the dies look the same? Wrapper around same_die_p. */
9641 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
9644 int ret
= same_die_p (die1
, die2
, &mark
);
9646 unmark_all_dies (die1
);
9647 unmark_all_dies (die2
);
9652 /* The prefix to attach to symbols on DIEs in the current comdat debug
9654 static char *comdat_symbol_id
;
9656 /* The index of the current symbol within the current comdat CU. */
9657 static unsigned int comdat_symbol_number
;
9659 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
9660 children, and set comdat_symbol_id accordingly. */
9663 compute_section_prefix (dw_die_ref unit_die
)
9665 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
9666 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
9667 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
9670 unsigned char checksum
[16];
9673 /* Compute the checksum of the DIE, then append part of it as hex digits to
9674 the name filename of the unit. */
9676 md5_init_ctx (&ctx
);
9678 die_checksum (unit_die
, &ctx
, &mark
);
9679 unmark_all_dies (unit_die
);
9680 md5_finish_ctx (&ctx
, checksum
);
9682 sprintf (name
, "%s.", base
);
9683 clean_symbol_name (name
);
9685 p
= name
+ strlen (name
);
9686 for (i
= 0; i
< 4; i
++)
9688 sprintf (p
, "%.2x", checksum
[i
]);
9692 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
9693 comdat_symbol_number
= 0;
9696 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
9699 is_type_die (dw_die_ref die
)
9701 switch (die
->die_tag
)
9703 case DW_TAG_array_type
:
9704 case DW_TAG_class_type
:
9705 case DW_TAG_interface_type
:
9706 case DW_TAG_enumeration_type
:
9707 case DW_TAG_pointer_type
:
9708 case DW_TAG_reference_type
:
9709 case DW_TAG_rvalue_reference_type
:
9710 case DW_TAG_string_type
:
9711 case DW_TAG_structure_type
:
9712 case DW_TAG_subroutine_type
:
9713 case DW_TAG_union_type
:
9714 case DW_TAG_ptr_to_member_type
:
9715 case DW_TAG_set_type
:
9716 case DW_TAG_subrange_type
:
9717 case DW_TAG_base_type
:
9718 case DW_TAG_const_type
:
9719 case DW_TAG_file_type
:
9720 case DW_TAG_packed_type
:
9721 case DW_TAG_volatile_type
:
9722 case DW_TAG_typedef
:
9729 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
9730 Basically, we want to choose the bits that are likely to be shared between
9731 compilations (types) and leave out the bits that are specific to individual
9732 compilations (functions). */
9735 is_comdat_die (dw_die_ref c
)
9737 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
9738 we do for stabs. The advantage is a greater likelihood of sharing between
9739 objects that don't include headers in the same order (and therefore would
9740 put the base types in a different comdat). jason 8/28/00 */
9742 if (c
->die_tag
== DW_TAG_base_type
)
9745 if (c
->die_tag
== DW_TAG_pointer_type
9746 || c
->die_tag
== DW_TAG_reference_type
9747 || c
->die_tag
== DW_TAG_rvalue_reference_type
9748 || c
->die_tag
== DW_TAG_const_type
9749 || c
->die_tag
== DW_TAG_volatile_type
)
9751 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
9753 return t
? is_comdat_die (t
) : 0;
9756 return is_type_die (c
);
9759 /* Returns 1 iff C is the sort of DIE that might be referred to from another
9760 compilation unit. */
9763 is_symbol_die (dw_die_ref c
)
9765 return (is_type_die (c
)
9766 || is_declaration_die (c
)
9767 || c
->die_tag
== DW_TAG_namespace
9768 || c
->die_tag
== DW_TAG_module
);
9771 /* Returns true iff C is a compile-unit DIE. */
9774 is_cu_die (dw_die_ref c
)
9776 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
9780 gen_internal_sym (const char *prefix
)
9784 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
9785 return xstrdup (buf
);
9788 /* Assign symbols to all worthy DIEs under DIE. */
9791 assign_symbol_names (dw_die_ref die
)
9795 if (is_symbol_die (die
))
9797 if (comdat_symbol_id
)
9799 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
9801 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
9802 comdat_symbol_id
, comdat_symbol_number
++);
9803 die
->die_id
.die_symbol
= xstrdup (p
);
9806 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
9809 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
9812 struct cu_hash_table_entry
9815 unsigned min_comdat_num
, max_comdat_num
;
9816 struct cu_hash_table_entry
*next
;
9819 /* Routines to manipulate hash table of CUs. */
9821 htab_cu_hash (const void *of
)
9823 const struct cu_hash_table_entry
*const entry
=
9824 (const struct cu_hash_table_entry
*) of
;
9826 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
9830 htab_cu_eq (const void *of1
, const void *of2
)
9832 const struct cu_hash_table_entry
*const entry1
=
9833 (const struct cu_hash_table_entry
*) of1
;
9834 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
9836 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
9840 htab_cu_del (void *what
)
9842 struct cu_hash_table_entry
*next
,
9843 *entry
= (struct cu_hash_table_entry
*) what
;
9853 /* Check whether we have already seen this CU and set up SYM_NUM
9856 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
9858 struct cu_hash_table_entry dummy
;
9859 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
9861 dummy
.max_comdat_num
= 0;
9863 slot
= (struct cu_hash_table_entry
**)
9864 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
9868 for (; entry
; last
= entry
, entry
= entry
->next
)
9870 if (same_die_p_wrap (cu
, entry
->cu
))
9876 *sym_num
= entry
->min_comdat_num
;
9880 entry
= XCNEW (struct cu_hash_table_entry
);
9882 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
9883 entry
->next
= *slot
;
9889 /* Record SYM_NUM to record of CU in HTABLE. */
9891 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
9893 struct cu_hash_table_entry
**slot
, *entry
;
9895 slot
= (struct cu_hash_table_entry
**)
9896 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
9900 entry
->max_comdat_num
= sym_num
;
9903 /* Traverse the DIE (which is always comp_unit_die), and set up
9904 additional compilation units for each of the include files we see
9905 bracketed by BINCL/EINCL. */
9908 break_out_includes (dw_die_ref die
)
9911 dw_die_ref unit
= NULL
;
9912 limbo_die_node
*node
, **pnode
;
9913 htab_t cu_hash_table
;
9917 dw_die_ref prev
= c
;
9919 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
9920 || (unit
&& is_comdat_die (c
)))
9922 dw_die_ref next
= c
->die_sib
;
9924 /* This DIE is for a secondary CU; remove it from the main one. */
9925 remove_child_with_prev (c
, prev
);
9927 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
9928 unit
= push_new_compile_unit (unit
, c
);
9929 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
9930 unit
= pop_compile_unit (unit
);
9932 add_child_die (unit
, c
);
9934 if (c
== die
->die_child
)
9937 } while (c
!= die
->die_child
);
9940 /* We can only use this in debugging, since the frontend doesn't check
9941 to make sure that we leave every include file we enter. */
9945 assign_symbol_names (die
);
9946 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
9947 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
9953 compute_section_prefix (node
->die
);
9954 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
9955 &comdat_symbol_number
);
9956 assign_symbol_names (node
->die
);
9958 *pnode
= node
->next
;
9961 pnode
= &node
->next
;
9962 record_comdat_symbol_number (node
->die
, cu_hash_table
,
9963 comdat_symbol_number
);
9966 htab_delete (cu_hash_table
);
9969 /* Return non-zero if this DIE is a declaration. */
9972 is_declaration_die (dw_die_ref die
)
9977 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
9978 if (a
->dw_attr
== DW_AT_declaration
)
9984 /* Return non-zero if this DIE is nested inside a subprogram. */
9987 is_nested_in_subprogram (dw_die_ref die
)
9989 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
9993 return local_scope_p (decl
);
9996 /* Return non-zero if this is a type DIE that should be moved to a
9997 COMDAT .debug_types section. */
10000 should_move_die_to_comdat (dw_die_ref die
)
10002 switch (die
->die_tag
)
10004 case DW_TAG_class_type
:
10005 case DW_TAG_structure_type
:
10006 case DW_TAG_enumeration_type
:
10007 case DW_TAG_union_type
:
10008 /* Don't move declarations, inlined instances, or types nested in a
10010 if (is_declaration_die (die
)
10011 || get_AT (die
, DW_AT_abstract_origin
)
10012 || is_nested_in_subprogram (die
))
10015 case DW_TAG_array_type
:
10016 case DW_TAG_interface_type
:
10017 case DW_TAG_pointer_type
:
10018 case DW_TAG_reference_type
:
10019 case DW_TAG_rvalue_reference_type
:
10020 case DW_TAG_string_type
:
10021 case DW_TAG_subroutine_type
:
10022 case DW_TAG_ptr_to_member_type
:
10023 case DW_TAG_set_type
:
10024 case DW_TAG_subrange_type
:
10025 case DW_TAG_base_type
:
10026 case DW_TAG_const_type
:
10027 case DW_TAG_file_type
:
10028 case DW_TAG_packed_type
:
10029 case DW_TAG_volatile_type
:
10030 case DW_TAG_typedef
:
10036 /* Make a clone of DIE. */
10039 clone_die (dw_die_ref die
)
10045 clone
= ggc_alloc_cleared_die_node ();
10046 clone
->die_tag
= die
->die_tag
;
10048 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
10049 add_dwarf_attr (clone
, a
);
10054 /* Make a clone of the tree rooted at DIE. */
10057 clone_tree (dw_die_ref die
)
10060 dw_die_ref clone
= clone_die (die
);
10062 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree(c
)));
10067 /* Make a clone of DIE as a declaration. */
10070 clone_as_declaration (dw_die_ref die
)
10077 /* If the DIE is already a declaration, just clone it. */
10078 if (is_declaration_die (die
))
10079 return clone_die (die
);
10081 /* If the DIE is a specification, just clone its declaration DIE. */
10082 decl
= get_AT_ref (die
, DW_AT_specification
);
10084 return clone_die (decl
);
10086 clone
= ggc_alloc_cleared_die_node ();
10087 clone
->die_tag
= die
->die_tag
;
10089 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
10091 /* We don't want to copy over all attributes.
10092 For example we don't want DW_AT_byte_size because otherwise we will no
10093 longer have a declaration and GDB will treat it as a definition. */
10095 switch (a
->dw_attr
)
10097 case DW_AT_artificial
:
10098 case DW_AT_containing_type
:
10099 case DW_AT_external
:
10102 case DW_AT_virtuality
:
10103 case DW_AT_linkage_name
:
10104 case DW_AT_MIPS_linkage_name
:
10105 add_dwarf_attr (clone
, a
);
10107 case DW_AT_byte_size
:
10113 if (die
->die_id
.die_type_node
)
10114 add_AT_die_ref (clone
, DW_AT_signature
, die
);
10116 add_AT_flag (clone
, DW_AT_declaration
, 1);
10120 /* Copy the declaration context to the new compile unit DIE. This includes
10121 any surrounding namespace or type declarations. If the DIE has an
10122 AT_specification attribute, it also includes attributes and children
10123 attached to the specification. */
10126 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
10129 dw_die_ref new_decl
;
10131 decl
= get_AT_ref (die
, DW_AT_specification
);
10140 /* Copy the type node pointer from the new DIE to the original
10141 declaration DIE so we can forward references later. */
10142 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
10144 remove_AT (die
, DW_AT_specification
);
10146 FOR_EACH_VEC_ELT (dw_attr_node
, decl
->die_attr
, ix
, a
)
10148 if (a
->dw_attr
!= DW_AT_name
10149 && a
->dw_attr
!= DW_AT_declaration
10150 && a
->dw_attr
!= DW_AT_external
)
10151 add_dwarf_attr (die
, a
);
10154 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree(c
)));
10157 if (decl
->die_parent
!= NULL
10158 && decl
->die_parent
->die_tag
!= DW_TAG_compile_unit
10159 && decl
->die_parent
->die_tag
!= DW_TAG_type_unit
)
10161 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
10162 if (new_decl
!= NULL
)
10164 remove_AT (new_decl
, DW_AT_signature
);
10165 add_AT_specification (die
, new_decl
);
10170 /* Generate the skeleton ancestor tree for the given NODE, then clone
10171 the DIE and add the clone into the tree. */
10174 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
10176 if (node
->new_die
!= NULL
)
10179 node
->new_die
= clone_as_declaration (node
->old_die
);
10181 if (node
->parent
!= NULL
)
10183 generate_skeleton_ancestor_tree (node
->parent
);
10184 add_child_die (node
->parent
->new_die
, node
->new_die
);
10188 /* Generate a skeleton tree of DIEs containing any declarations that are
10189 found in the original tree. We traverse the tree looking for declaration
10190 DIEs, and construct the skeleton from the bottom up whenever we find one. */
10193 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
10195 skeleton_chain_node node
;
10198 dw_die_ref prev
= NULL
;
10199 dw_die_ref next
= NULL
;
10201 node
.parent
= parent
;
10203 first
= c
= parent
->old_die
->die_child
;
10207 if (prev
== NULL
|| prev
->die_sib
== c
)
10210 next
= (c
== first
? NULL
: c
->die_sib
);
10212 node
.new_die
= NULL
;
10213 if (is_declaration_die (c
))
10215 /* Clone the existing DIE, move the original to the skeleton
10216 tree (which is in the main CU), and put the clone, with
10217 all the original's children, where the original came from. */
10218 dw_die_ref clone
= clone_die (c
);
10219 move_all_children (c
, clone
);
10221 replace_child (c
, clone
, prev
);
10222 generate_skeleton_ancestor_tree (parent
);
10223 add_child_die (parent
->new_die
, c
);
10227 generate_skeleton_bottom_up (&node
);
10228 } while (next
!= NULL
);
10231 /* Wrapper function for generate_skeleton_bottom_up. */
10234 generate_skeleton (dw_die_ref die
)
10236 skeleton_chain_node node
;
10238 node
.old_die
= die
;
10239 node
.new_die
= NULL
;
10240 node
.parent
= NULL
;
10242 /* If this type definition is nested inside another type,
10243 always leave at least a declaration in its place. */
10244 if (die
->die_parent
!= NULL
&& is_type_die (die
->die_parent
))
10245 node
.new_die
= clone_as_declaration (die
);
10247 generate_skeleton_bottom_up (&node
);
10248 return node
.new_die
;
10251 /* Remove the DIE from its parent, possibly replacing it with a cloned
10252 declaration. The original DIE will be moved to a new compile unit
10253 so that existing references to it follow it to the new location. If
10254 any of the original DIE's descendants is a declaration, we need to
10255 replace the original DIE with a skeleton tree and move the
10256 declarations back into the skeleton tree. */
10259 remove_child_or_replace_with_skeleton (dw_die_ref child
, dw_die_ref prev
)
10261 dw_die_ref skeleton
;
10263 skeleton
= generate_skeleton (child
);
10264 if (skeleton
== NULL
)
10265 remove_child_with_prev (child
, prev
);
10268 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
10269 replace_child (child
, skeleton
, prev
);
10275 /* Traverse the DIE and set up additional .debug_types sections for each
10276 type worthy of being placed in a COMDAT section. */
10279 break_out_comdat_types (dw_die_ref die
)
10283 dw_die_ref prev
= NULL
;
10284 dw_die_ref next
= NULL
;
10285 dw_die_ref unit
= NULL
;
10287 first
= c
= die
->die_child
;
10291 if (prev
== NULL
|| prev
->die_sib
== c
)
10294 next
= (c
== first
? NULL
: c
->die_sib
);
10295 if (should_move_die_to_comdat (c
))
10297 dw_die_ref replacement
;
10298 comdat_type_node_ref type_node
;
10300 /* Create a new type unit DIE as the root for the new tree, and
10301 add it to the list of comdat types. */
10302 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
10303 add_AT_unsigned (unit
, DW_AT_language
,
10304 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
10305 type_node
= ggc_alloc_cleared_comdat_type_node ();
10306 type_node
->root_die
= unit
;
10307 type_node
->next
= comdat_type_list
;
10308 comdat_type_list
= type_node
;
10310 /* Generate the type signature. */
10311 generate_type_signature (c
, type_node
);
10313 /* Copy the declaration context, attributes, and children of the
10314 declaration into the new compile unit DIE. */
10315 copy_declaration_context (unit
, c
);
10317 /* Remove this DIE from the main CU. */
10318 replacement
= remove_child_or_replace_with_skeleton (c
, prev
);
10320 /* Break out nested types into their own type units. */
10321 break_out_comdat_types (c
);
10323 /* Add the DIE to the new compunit. */
10324 add_child_die (unit
, c
);
10326 if (replacement
!= NULL
)
10329 else if (c
->die_tag
== DW_TAG_namespace
10330 || c
->die_tag
== DW_TAG_class_type
10331 || c
->die_tag
== DW_TAG_structure_type
10332 || c
->die_tag
== DW_TAG_union_type
)
10334 /* Look for nested types that can be broken out. */
10335 break_out_comdat_types (c
);
10337 } while (next
!= NULL
);
10340 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
10342 struct decl_table_entry
10348 /* Routines to manipulate hash table of copied declarations. */
10351 htab_decl_hash (const void *of
)
10353 const struct decl_table_entry
*const entry
=
10354 (const struct decl_table_entry
*) of
;
10356 return htab_hash_pointer (entry
->orig
);
10360 htab_decl_eq (const void *of1
, const void *of2
)
10362 const struct decl_table_entry
*const entry1
=
10363 (const struct decl_table_entry
*) of1
;
10364 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
10366 return entry1
->orig
== entry2
;
10370 htab_decl_del (void *what
)
10372 struct decl_table_entry
*entry
= (struct decl_table_entry
*) what
;
10377 /* Copy DIE and its ancestors, up to, but not including, the compile unit
10378 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
10379 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
10380 to check if the ancestor has already been copied into UNIT. */
10383 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
10385 dw_die_ref parent
= die
->die_parent
;
10386 dw_die_ref new_parent
= unit
;
10388 void **slot
= NULL
;
10389 struct decl_table_entry
*entry
= NULL
;
10393 /* Check if the entry has already been copied to UNIT. */
10394 slot
= htab_find_slot_with_hash (decl_table
, die
,
10395 htab_hash_pointer (die
), INSERT
);
10396 if (*slot
!= HTAB_EMPTY_ENTRY
)
10398 entry
= (struct decl_table_entry
*) *slot
;
10399 return entry
->copy
;
10402 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
10403 entry
= XCNEW (struct decl_table_entry
);
10405 entry
->copy
= NULL
;
10409 if (parent
!= NULL
)
10411 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
10414 if (parent
->die_tag
!= DW_TAG_compile_unit
10415 && parent
->die_tag
!= DW_TAG_type_unit
)
10416 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
10419 copy
= clone_as_declaration (die
);
10420 add_child_die (new_parent
, copy
);
10422 if (decl_table
!= NULL
)
10424 /* Record the pointer to the copy. */
10425 entry
->copy
= copy
;
10431 /* Walk the DIE and its children, looking for references to incomplete
10432 or trivial types that are unmarked (i.e., that are not in the current
10436 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
10442 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
10444 if (AT_class (a
) == dw_val_class_die_ref
)
10446 dw_die_ref targ
= AT_ref (a
);
10447 comdat_type_node_ref type_node
= targ
->die_id
.die_type_node
;
10449 struct decl_table_entry
*entry
;
10451 if (targ
->die_mark
!= 0 || type_node
!= NULL
)
10454 slot
= htab_find_slot_with_hash (decl_table
, targ
,
10455 htab_hash_pointer (targ
), INSERT
);
10457 if (*slot
!= HTAB_EMPTY_ENTRY
)
10459 /* TARG has already been copied, so we just need to
10460 modify the reference to point to the copy. */
10461 entry
= (struct decl_table_entry
*) *slot
;
10462 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
10466 dw_die_ref parent
= unit
;
10467 dw_die_ref copy
= clone_tree (targ
);
10469 /* Make sure the cloned tree is marked as part of the
10473 /* Record in DECL_TABLE that TARG has been copied.
10474 Need to do this now, before the recursive call,
10475 because DECL_TABLE may be expanded and SLOT
10476 would no longer be a valid pointer. */
10477 entry
= XCNEW (struct decl_table_entry
);
10478 entry
->orig
= targ
;
10479 entry
->copy
= copy
;
10482 /* If TARG has surrounding context, copy its ancestor tree
10483 into the new type unit. */
10484 if (targ
->die_parent
!= NULL
10485 && targ
->die_parent
->die_tag
!= DW_TAG_compile_unit
10486 && targ
->die_parent
->die_tag
!= DW_TAG_type_unit
)
10487 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
10490 add_child_die (parent
, copy
);
10491 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
10493 /* Make sure the newly-copied DIE is walked. If it was
10494 installed in a previously-added context, it won't
10495 get visited otherwise. */
10496 if (parent
!= unit
)
10498 /* Find the highest point of the newly-added tree,
10499 mark each node along the way, and walk from there. */
10500 parent
->die_mark
= 1;
10501 while (parent
->die_parent
10502 && parent
->die_parent
->die_mark
== 0)
10504 parent
= parent
->die_parent
;
10505 parent
->die_mark
= 1;
10507 copy_decls_walk (unit
, parent
, decl_table
);
10513 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
10516 /* Copy declarations for "unworthy" types into the new comdat section.
10517 Incomplete types, modified types, and certain other types aren't broken
10518 out into comdat sections of their own, so they don't have a signature,
10519 and we need to copy the declaration into the same section so that we
10520 don't have an external reference. */
10523 copy_decls_for_unworthy_types (dw_die_ref unit
)
10528 decl_table
= htab_create (10, htab_decl_hash
, htab_decl_eq
, htab_decl_del
);
10529 copy_decls_walk (unit
, unit
, decl_table
);
10530 htab_delete (decl_table
);
10531 unmark_dies (unit
);
10534 /* Traverse the DIE and add a sibling attribute if it may have the
10535 effect of speeding up access to siblings. To save some space,
10536 avoid generating sibling attributes for DIE's without children. */
10539 add_sibling_attributes (dw_die_ref die
)
10543 if (! die
->die_child
)
10546 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
10547 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
10549 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
10552 /* Output all location lists for the DIE and its children. */
10555 output_location_lists (dw_die_ref die
)
10561 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
10562 if (AT_class (a
) == dw_val_class_loc_list
)
10563 output_loc_list (AT_loc_list (a
));
10565 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
10568 /* The format of each DIE (and its attribute value pairs) is encoded in an
10569 abbreviation table. This routine builds the abbreviation table and assigns
10570 a unique abbreviation id for each abbreviation entry. The children of each
10571 die are visited recursively. */
10574 build_abbrev_table (dw_die_ref die
)
10576 unsigned long abbrev_id
;
10577 unsigned int n_alloc
;
10582 /* Scan the DIE references, and mark as external any that refer to
10583 DIEs from other CUs (i.e. those which are not marked). */
10584 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
10585 if (AT_class (a
) == dw_val_class_die_ref
10586 && AT_ref (a
)->die_mark
== 0)
10588 gcc_assert (dwarf_version
>= 4 || AT_ref (a
)->die_id
.die_symbol
);
10589 set_AT_ref_external (a
, 1);
10592 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
10594 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
10595 dw_attr_ref die_a
, abbrev_a
;
10599 if (abbrev
->die_tag
!= die
->die_tag
)
10601 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
10604 if (VEC_length (dw_attr_node
, abbrev
->die_attr
)
10605 != VEC_length (dw_attr_node
, die
->die_attr
))
10608 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, die_a
)
10610 abbrev_a
= VEC_index (dw_attr_node
, abbrev
->die_attr
, ix
);
10611 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
10612 || (value_format (abbrev_a
) != value_format (die_a
)))
10622 if (abbrev_id
>= abbrev_die_table_in_use
)
10624 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
10626 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
10627 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
10630 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
10631 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
10632 abbrev_die_table_allocated
= n_alloc
;
10635 ++abbrev_die_table_in_use
;
10636 abbrev_die_table
[abbrev_id
] = die
;
10639 die
->die_abbrev
= abbrev_id
;
10640 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
));
10643 /* Return the power-of-two number of bytes necessary to represent VALUE. */
10646 constant_size (unsigned HOST_WIDE_INT value
)
10653 log
= floor_log2 (value
);
10656 log
= 1 << (floor_log2 (log
) + 1);
10661 /* Return the size of a DIE as it is represented in the
10662 .debug_info section. */
10664 static unsigned long
10665 size_of_die (dw_die_ref die
)
10667 unsigned long size
= 0;
10671 size
+= size_of_uleb128 (die
->die_abbrev
);
10672 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
10674 switch (AT_class (a
))
10676 case dw_val_class_addr
:
10677 size
+= DWARF2_ADDR_SIZE
;
10679 case dw_val_class_offset
:
10680 size
+= DWARF_OFFSET_SIZE
;
10682 case dw_val_class_loc
:
10684 unsigned long lsize
= size_of_locs (AT_loc (a
));
10686 /* Block length. */
10687 if (dwarf_version
>= 4)
10688 size
+= size_of_uleb128 (lsize
);
10690 size
+= constant_size (lsize
);
10694 case dw_val_class_loc_list
:
10695 size
+= DWARF_OFFSET_SIZE
;
10697 case dw_val_class_range_list
:
10698 size
+= DWARF_OFFSET_SIZE
;
10700 case dw_val_class_const
:
10701 size
+= size_of_sleb128 (AT_int (a
));
10703 case dw_val_class_unsigned_const
:
10704 size
+= constant_size (AT_unsigned (a
));
10706 case dw_val_class_const_double
:
10707 size
+= 2 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
10708 if (HOST_BITS_PER_WIDE_INT
>= 64)
10709 size
++; /* block */
10711 case dw_val_class_vec
:
10712 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
10713 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
10714 + a
->dw_attr_val
.v
.val_vec
.length
10715 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
10717 case dw_val_class_flag
:
10718 if (dwarf_version
>= 4)
10719 /* Currently all add_AT_flag calls pass in 1 as last argument,
10720 so DW_FORM_flag_present can be used. If that ever changes,
10721 we'll need to use DW_FORM_flag and have some optimization
10722 in build_abbrev_table that will change those to
10723 DW_FORM_flag_present if it is set to 1 in all DIEs using
10724 the same abbrev entry. */
10725 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
10729 case dw_val_class_die_ref
:
10730 if (AT_ref_external (a
))
10732 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
10733 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
10734 is sized by target address length, whereas in DWARF3
10735 it's always sized as an offset. */
10736 if (dwarf_version
>= 4)
10737 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
10738 else if (dwarf_version
== 2)
10739 size
+= DWARF2_ADDR_SIZE
;
10741 size
+= DWARF_OFFSET_SIZE
;
10744 size
+= DWARF_OFFSET_SIZE
;
10746 case dw_val_class_fde_ref
:
10747 size
+= DWARF_OFFSET_SIZE
;
10749 case dw_val_class_lbl_id
:
10750 size
+= DWARF2_ADDR_SIZE
;
10752 case dw_val_class_lineptr
:
10753 case dw_val_class_macptr
:
10754 size
+= DWARF_OFFSET_SIZE
;
10756 case dw_val_class_str
:
10757 if (AT_string_form (a
) == DW_FORM_strp
)
10758 size
+= DWARF_OFFSET_SIZE
;
10760 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
10762 case dw_val_class_file
:
10763 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
10765 case dw_val_class_data8
:
10768 case dw_val_class_vms_delta
:
10769 size
+= DWARF_OFFSET_SIZE
;
10772 gcc_unreachable ();
10779 /* Size the debugging information associated with a given DIE. Visits the
10780 DIE's children recursively. Updates the global variable next_die_offset, on
10781 each time through. Uses the current value of next_die_offset to update the
10782 die_offset field in each DIE. */
10785 calc_die_sizes (dw_die_ref die
)
10789 die
->die_offset
= next_die_offset
;
10790 next_die_offset
+= size_of_die (die
);
10792 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
10794 if (die
->die_child
!= NULL
)
10795 /* Count the null byte used to terminate sibling lists. */
10796 next_die_offset
+= 1;
10799 /* Set the marks for a die and its children. We do this so
10800 that we know whether or not a reference needs to use FORM_ref_addr; only
10801 DIEs in the same CU will be marked. We used to clear out the offset
10802 and use that as the flag, but ran into ordering problems. */
10805 mark_dies (dw_die_ref die
)
10809 gcc_assert (!die
->die_mark
);
10812 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
10815 /* Clear the marks for a die and its children. */
10818 unmark_dies (dw_die_ref die
)
10822 if (dwarf_version
< 4)
10823 gcc_assert (die
->die_mark
);
10826 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
10829 /* Clear the marks for a die, its children and referred dies. */
10832 unmark_all_dies (dw_die_ref die
)
10838 if (!die
->die_mark
)
10842 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
10844 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
10845 if (AT_class (a
) == dw_val_class_die_ref
)
10846 unmark_all_dies (AT_ref (a
));
10849 /* Return the size of the .debug_pubnames or .debug_pubtypes table
10850 generated for the compilation unit. */
10852 static unsigned long
10853 size_of_pubnames (VEC (pubname_entry
, gc
) * names
)
10855 unsigned long size
;
10859 size
= DWARF_PUBNAMES_HEADER_SIZE
;
10860 FOR_EACH_VEC_ELT (pubname_entry
, names
, i
, p
)
10861 if (names
!= pubtype_table
10862 || p
->die
->die_offset
!= 0
10863 || !flag_eliminate_unused_debug_types
)
10864 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
10866 size
+= DWARF_OFFSET_SIZE
;
10870 /* Return the size of the information in the .debug_aranges section. */
10872 static unsigned long
10873 size_of_aranges (void)
10875 unsigned long size
;
10877 size
= DWARF_ARANGES_HEADER_SIZE
;
10879 /* Count the address/length pair for this compilation unit. */
10880 if (text_section_used
)
10881 size
+= 2 * DWARF2_ADDR_SIZE
;
10882 if (cold_text_section_used
)
10883 size
+= 2 * DWARF2_ADDR_SIZE
;
10884 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
10886 /* Count the two zero words used to terminated the address range table. */
10887 size
+= 2 * DWARF2_ADDR_SIZE
;
10891 /* Select the encoding of an attribute value. */
10893 static enum dwarf_form
10894 value_format (dw_attr_ref a
)
10896 switch (a
->dw_attr_val
.val_class
)
10898 case dw_val_class_addr
:
10899 /* Only very few attributes allow DW_FORM_addr. */
10900 switch (a
->dw_attr
)
10903 case DW_AT_high_pc
:
10904 case DW_AT_entry_pc
:
10905 case DW_AT_trampoline
:
10906 return DW_FORM_addr
;
10910 switch (DWARF2_ADDR_SIZE
)
10913 return DW_FORM_data1
;
10915 return DW_FORM_data2
;
10917 return DW_FORM_data4
;
10919 return DW_FORM_data8
;
10921 gcc_unreachable ();
10923 case dw_val_class_range_list
:
10924 case dw_val_class_loc_list
:
10925 if (dwarf_version
>= 4)
10926 return DW_FORM_sec_offset
;
10928 case dw_val_class_vms_delta
:
10929 case dw_val_class_offset
:
10930 switch (DWARF_OFFSET_SIZE
)
10933 return DW_FORM_data4
;
10935 return DW_FORM_data8
;
10937 gcc_unreachable ();
10939 case dw_val_class_loc
:
10940 if (dwarf_version
>= 4)
10941 return DW_FORM_exprloc
;
10942 switch (constant_size (size_of_locs (AT_loc (a
))))
10945 return DW_FORM_block1
;
10947 return DW_FORM_block2
;
10949 gcc_unreachable ();
10951 case dw_val_class_const
:
10952 return DW_FORM_sdata
;
10953 case dw_val_class_unsigned_const
:
10954 switch (constant_size (AT_unsigned (a
)))
10957 return DW_FORM_data1
;
10959 return DW_FORM_data2
;
10961 return DW_FORM_data4
;
10963 return DW_FORM_data8
;
10965 gcc_unreachable ();
10967 case dw_val_class_const_double
:
10968 switch (HOST_BITS_PER_WIDE_INT
)
10971 return DW_FORM_data2
;
10973 return DW_FORM_data4
;
10975 return DW_FORM_data8
;
10978 return DW_FORM_block1
;
10980 case dw_val_class_vec
:
10981 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
10982 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
10985 return DW_FORM_block1
;
10987 return DW_FORM_block2
;
10989 return DW_FORM_block4
;
10991 gcc_unreachable ();
10993 case dw_val_class_flag
:
10994 if (dwarf_version
>= 4)
10996 /* Currently all add_AT_flag calls pass in 1 as last argument,
10997 so DW_FORM_flag_present can be used. If that ever changes,
10998 we'll need to use DW_FORM_flag and have some optimization
10999 in build_abbrev_table that will change those to
11000 DW_FORM_flag_present if it is set to 1 in all DIEs using
11001 the same abbrev entry. */
11002 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
11003 return DW_FORM_flag_present
;
11005 return DW_FORM_flag
;
11006 case dw_val_class_die_ref
:
11007 if (AT_ref_external (a
))
11008 return dwarf_version
>= 4 ? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
11010 return DW_FORM_ref
;
11011 case dw_val_class_fde_ref
:
11012 return DW_FORM_data
;
11013 case dw_val_class_lbl_id
:
11014 return DW_FORM_addr
;
11015 case dw_val_class_lineptr
:
11016 case dw_val_class_macptr
:
11017 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
11018 case dw_val_class_str
:
11019 return AT_string_form (a
);
11020 case dw_val_class_file
:
11021 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
11024 return DW_FORM_data1
;
11026 return DW_FORM_data2
;
11028 return DW_FORM_data4
;
11030 gcc_unreachable ();
11033 case dw_val_class_data8
:
11034 return DW_FORM_data8
;
11037 gcc_unreachable ();
11041 /* Output the encoding of an attribute value. */
11044 output_value_format (dw_attr_ref a
)
11046 enum dwarf_form form
= value_format (a
);
11048 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
11051 /* Output the .debug_abbrev section which defines the DIE abbreviation
11055 output_abbrev_section (void)
11057 unsigned long abbrev_id
;
11059 if (abbrev_die_table_in_use
== 1)
11062 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
11064 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
11066 dw_attr_ref a_attr
;
11068 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
11069 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
11070 dwarf_tag_name (abbrev
->die_tag
));
11072 if (abbrev
->die_child
!= NULL
)
11073 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
11075 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
11077 for (ix
= 0; VEC_iterate (dw_attr_node
, abbrev
->die_attr
, ix
, a_attr
);
11080 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
11081 dwarf_attr_name (a_attr
->dw_attr
));
11082 output_value_format (a_attr
);
11085 dw2_asm_output_data (1, 0, NULL
);
11086 dw2_asm_output_data (1, 0, NULL
);
11089 /* Terminate the table. */
11090 dw2_asm_output_data (1, 0, NULL
);
11093 /* Output a symbol we can use to refer to this DIE from another CU. */
11096 output_die_symbol (dw_die_ref die
)
11098 char *sym
= die
->die_id
.die_symbol
;
11103 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
11104 /* We make these global, not weak; if the target doesn't support
11105 .linkonce, it doesn't support combining the sections, so debugging
11107 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
11109 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
11112 /* Return a new location list, given the begin and end range, and the
11115 static inline dw_loc_list_ref
11116 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
11117 const char *section
)
11119 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
11121 retlist
->begin
= begin
;
11122 retlist
->end
= end
;
11123 retlist
->expr
= expr
;
11124 retlist
->section
= section
;
11129 /* Generate a new internal symbol for this location list node, if it
11130 hasn't got one yet. */
11133 gen_llsym (dw_loc_list_ref list
)
11135 gcc_assert (!list
->ll_symbol
);
11136 list
->ll_symbol
= gen_internal_sym ("LLST");
11139 /* Output the location list given to us. */
11142 output_loc_list (dw_loc_list_ref list_head
)
11144 dw_loc_list_ref curr
= list_head
;
11146 if (list_head
->emitted
)
11148 list_head
->emitted
= true;
11150 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
11152 /* Walk the location list, and output each range + expression. */
11153 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
11155 unsigned long size
;
11156 /* Don't output an entry that starts and ends at the same address. */
11157 if (strcmp (curr
->begin
, curr
->end
) == 0)
11159 if (!have_multiple_function_sections
)
11161 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
11162 "Location list begin address (%s)",
11163 list_head
->ll_symbol
);
11164 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
11165 "Location list end address (%s)",
11166 list_head
->ll_symbol
);
11170 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
11171 "Location list begin address (%s)",
11172 list_head
->ll_symbol
);
11173 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
11174 "Location list end address (%s)",
11175 list_head
->ll_symbol
);
11177 size
= size_of_locs (curr
->expr
);
11179 /* Output the block length for this list of location operations. */
11180 gcc_assert (size
<= 0xffff);
11181 dw2_asm_output_data (2, size
, "%s", "Location expression size");
11183 output_loc_sequence (curr
->expr
, -1);
11186 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
11187 "Location list terminator begin (%s)",
11188 list_head
->ll_symbol
);
11189 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
11190 "Location list terminator end (%s)",
11191 list_head
->ll_symbol
);
11194 /* Output a type signature. */
11197 output_signature (const char *sig
, const char *name
)
11201 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
11202 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
11205 /* Output the DIE and its attributes. Called recursively to generate
11206 the definitions of each child DIE. */
11209 output_die (dw_die_ref die
)
11213 unsigned long size
;
11216 /* If someone in another CU might refer to us, set up a symbol for
11217 them to point to. */
11218 if (dwarf_version
< 4 && die
->die_id
.die_symbol
)
11219 output_die_symbol (die
);
11221 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
11222 (unsigned long)die
->die_offset
,
11223 dwarf_tag_name (die
->die_tag
));
11225 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
11227 const char *name
= dwarf_attr_name (a
->dw_attr
);
11229 switch (AT_class (a
))
11231 case dw_val_class_addr
:
11232 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
11235 case dw_val_class_offset
:
11236 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
11240 case dw_val_class_range_list
:
11242 char *p
= strchr (ranges_section_label
, '\0');
11244 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
11245 a
->dw_attr_val
.v
.val_offset
);
11246 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
11247 debug_ranges_section
, "%s", name
);
11252 case dw_val_class_loc
:
11253 size
= size_of_locs (AT_loc (a
));
11255 /* Output the block length for this list of location operations. */
11256 if (dwarf_version
>= 4)
11257 dw2_asm_output_data_uleb128 (size
, "%s", name
);
11259 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
11261 output_loc_sequence (AT_loc (a
), -1);
11264 case dw_val_class_const
:
11265 /* ??? It would be slightly more efficient to use a scheme like is
11266 used for unsigned constants below, but gdb 4.x does not sign
11267 extend. Gdb 5.x does sign extend. */
11268 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
11271 case dw_val_class_unsigned_const
:
11272 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
11273 AT_unsigned (a
), "%s", name
);
11276 case dw_val_class_const_double
:
11278 unsigned HOST_WIDE_INT first
, second
;
11280 if (HOST_BITS_PER_WIDE_INT
>= 64)
11281 dw2_asm_output_data (1,
11282 2 * HOST_BITS_PER_WIDE_INT
11283 / HOST_BITS_PER_CHAR
,
11286 if (WORDS_BIG_ENDIAN
)
11288 first
= a
->dw_attr_val
.v
.val_double
.high
;
11289 second
= a
->dw_attr_val
.v
.val_double
.low
;
11293 first
= a
->dw_attr_val
.v
.val_double
.low
;
11294 second
= a
->dw_attr_val
.v
.val_double
.high
;
11297 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
11299 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
11304 case dw_val_class_vec
:
11306 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
11307 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
11311 dw2_asm_output_data (constant_size (len
* elt_size
),
11312 len
* elt_size
, "%s", name
);
11313 if (elt_size
> sizeof (HOST_WIDE_INT
))
11318 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
11320 i
++, p
+= elt_size
)
11321 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
11322 "fp or vector constant word %u", i
);
11326 case dw_val_class_flag
:
11327 if (dwarf_version
>= 4)
11329 /* Currently all add_AT_flag calls pass in 1 as last argument,
11330 so DW_FORM_flag_present can be used. If that ever changes,
11331 we'll need to use DW_FORM_flag and have some optimization
11332 in build_abbrev_table that will change those to
11333 DW_FORM_flag_present if it is set to 1 in all DIEs using
11334 the same abbrev entry. */
11335 gcc_assert (AT_flag (a
) == 1);
11336 if (flag_debug_asm
)
11337 fprintf (asm_out_file
, "\t\t\t%s %s\n",
11338 ASM_COMMENT_START
, name
);
11341 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
11344 case dw_val_class_loc_list
:
11346 char *sym
= AT_loc_list (a
)->ll_symbol
;
11349 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
11354 case dw_val_class_die_ref
:
11355 if (AT_ref_external (a
))
11357 if (dwarf_version
>= 4)
11359 comdat_type_node_ref type_node
=
11360 AT_ref (a
)->die_id
.die_type_node
;
11362 gcc_assert (type_node
);
11363 output_signature (type_node
->signature
, name
);
11367 char *sym
= AT_ref (a
)->die_id
.die_symbol
;
11371 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11372 length, whereas in DWARF3 it's always sized as an
11374 if (dwarf_version
== 2)
11375 size
= DWARF2_ADDR_SIZE
;
11377 size
= DWARF_OFFSET_SIZE
;
11378 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
11384 gcc_assert (AT_ref (a
)->die_offset
);
11385 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
11390 case dw_val_class_fde_ref
:
11394 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
11395 a
->dw_attr_val
.v
.val_fde_index
* 2);
11396 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
11401 case dw_val_class_vms_delta
:
11402 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
11403 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
11407 case dw_val_class_lbl_id
:
11408 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
11411 case dw_val_class_lineptr
:
11412 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
11413 debug_line_section
, "%s", name
);
11416 case dw_val_class_macptr
:
11417 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
11418 debug_macinfo_section
, "%s", name
);
11421 case dw_val_class_str
:
11422 if (AT_string_form (a
) == DW_FORM_strp
)
11423 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
11424 a
->dw_attr_val
.v
.val_str
->label
,
11426 "%s: \"%s\"", name
, AT_string (a
));
11428 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
11431 case dw_val_class_file
:
11433 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
11435 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
11436 a
->dw_attr_val
.v
.val_file
->filename
);
11440 case dw_val_class_data8
:
11444 for (i
= 0; i
< 8; i
++)
11445 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
11446 i
== 0 ? "%s" : NULL
, name
);
11451 gcc_unreachable ();
11455 FOR_EACH_CHILD (die
, c
, output_die (c
));
11457 /* Add null byte to terminate sibling list. */
11458 if (die
->die_child
!= NULL
)
11459 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11460 (unsigned long) die
->die_offset
);
11463 /* Output the compilation unit that appears at the beginning of the
11464 .debug_info section, and precedes the DIE descriptions. */
11467 output_compilation_unit_header (void)
11469 int ver
= dwarf_version
;
11471 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11472 dw2_asm_output_data (4, 0xffffffff,
11473 "Initial length escape value indicating 64-bit DWARF extension");
11474 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
11475 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
11476 "Length of Compilation Unit Info");
11477 dw2_asm_output_data (2, ver
, "DWARF version number");
11478 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
11479 debug_abbrev_section
,
11480 "Offset Into Abbrev. Section");
11481 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
11484 /* Output the compilation unit DIE and its children. */
11487 output_comp_unit (dw_die_ref die
, int output_if_empty
)
11489 const char *secname
;
11490 char *oldsym
, *tmp
;
11492 /* Unless we are outputting main CU, we may throw away empty ones. */
11493 if (!output_if_empty
&& die
->die_child
== NULL
)
11496 /* Even if there are no children of this DIE, we must output the information
11497 about the compilation unit. Otherwise, on an empty translation unit, we
11498 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11499 will then complain when examining the file. First mark all the DIEs in
11500 this CU so we know which get local refs. */
11503 build_abbrev_table (die
);
11505 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11506 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
11507 calc_die_sizes (die
);
11509 oldsym
= die
->die_id
.die_symbol
;
11512 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
11514 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
11516 die
->die_id
.die_symbol
= NULL
;
11517 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
11521 switch_to_section (debug_info_section
);
11522 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
11523 info_section_emitted
= true;
11526 /* Output debugging information. */
11527 output_compilation_unit_header ();
11530 /* Leave the marks on the main CU, so we can check them in
11531 output_pubnames. */
11535 die
->die_id
.die_symbol
= oldsym
;
11539 /* Output a comdat type unit DIE and its children. */
11542 output_comdat_type_unit (comdat_type_node
*node
)
11544 const char *secname
;
11547 #if defined (OBJECT_FORMAT_ELF)
11551 /* First mark all the DIEs in this CU so we know which get local refs. */
11552 mark_dies (node
->root_die
);
11554 build_abbrev_table (node
->root_die
);
11556 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11557 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
11558 calc_die_sizes (node
->root_die
);
11560 #if defined (OBJECT_FORMAT_ELF)
11561 secname
= ".debug_types";
11562 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
11563 sprintf (tmp
, "wt.");
11564 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
11565 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
11566 comdat_key
= get_identifier (tmp
);
11567 targetm
.asm_out
.named_section (secname
,
11568 SECTION_DEBUG
| SECTION_LINKONCE
,
11571 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
11572 sprintf (tmp
, ".gnu.linkonce.wt.");
11573 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
11574 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
11576 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
11579 /* Output debugging information. */
11580 output_compilation_unit_header ();
11581 output_signature (node
->signature
, "Type Signature");
11582 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
11583 "Offset to Type DIE");
11584 output_die (node
->root_die
);
11586 unmark_dies (node
->root_die
);
11589 /* Return the DWARF2/3 pubname associated with a decl. */
11591 static const char *
11592 dwarf2_name (tree decl
, int scope
)
11594 if (DECL_NAMELESS (decl
))
11596 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
11599 /* Add a new entry to .debug_pubnames if appropriate. */
11602 add_pubname_string (const char *str
, dw_die_ref die
)
11604 if (targetm
.want_debug_pub_sections
)
11609 e
.name
= xstrdup (str
);
11610 VEC_safe_push (pubname_entry
, gc
, pubname_table
, &e
);
11615 add_pubname (tree decl
, dw_die_ref die
)
11617 if (targetm
.want_debug_pub_sections
&& TREE_PUBLIC (decl
))
11619 const char *name
= dwarf2_name (decl
, 1);
11621 add_pubname_string (name
, die
);
11625 /* Add a new entry to .debug_pubtypes if appropriate. */
11628 add_pubtype (tree decl
, dw_die_ref die
)
11632 if (!targetm
.want_debug_pub_sections
)
11636 if ((TREE_PUBLIC (decl
)
11637 || is_cu_die (die
->die_parent
))
11638 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
11643 if (TYPE_NAME (decl
))
11645 if (TREE_CODE (TYPE_NAME (decl
)) == IDENTIFIER_NODE
)
11646 e
.name
= IDENTIFIER_POINTER (TYPE_NAME (decl
));
11647 else if (TREE_CODE (TYPE_NAME (decl
)) == TYPE_DECL
11648 && DECL_NAME (TYPE_NAME (decl
)))
11649 e
.name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl
)));
11651 e
.name
= xstrdup ((const char *) get_AT_string (die
, DW_AT_name
));
11656 e
.name
= dwarf2_name (decl
, 1);
11658 e
.name
= xstrdup (e
.name
);
11661 /* If we don't have a name for the type, there's no point in adding
11662 it to the table. */
11663 if (e
.name
&& e
.name
[0] != '\0')
11664 VEC_safe_push (pubname_entry
, gc
, pubtype_table
, &e
);
11668 /* Output the public names table used to speed up access to externally
11669 visible names; or the public types table used to find type definitions. */
11672 output_pubnames (VEC (pubname_entry
, gc
) * names
)
11675 unsigned long pubnames_length
= size_of_pubnames (names
);
11678 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11679 dw2_asm_output_data (4, 0xffffffff,
11680 "Initial length escape value indicating 64-bit DWARF extension");
11681 if (names
== pubname_table
)
11682 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
11683 "Length of Public Names Info");
11685 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
11686 "Length of Public Type Names Info");
11687 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
11688 dw2_asm_output_data (2, 2, "DWARF Version");
11689 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
11690 debug_info_section
,
11691 "Offset of Compilation Unit Info");
11692 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
11693 "Compilation Unit Length");
11695 FOR_EACH_VEC_ELT (pubname_entry
, names
, i
, pub
)
11697 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11698 if (names
== pubname_table
)
11699 gcc_assert (pub
->die
->die_mark
);
11701 if (names
!= pubtype_table
11702 || pub
->die
->die_offset
!= 0
11703 || !flag_eliminate_unused_debug_types
)
11705 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
11708 dw2_asm_output_nstring (pub
->name
, -1, "external name");
11712 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
11715 /* Add a new entry to .debug_aranges if appropriate. */
11718 add_arange (tree decl
, dw_die_ref die
)
11720 if (! DECL_SECTION_NAME (decl
))
11723 if (arange_table_in_use
== arange_table_allocated
)
11725 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
11726 arange_table
= GGC_RESIZEVEC (dw_die_ref
, arange_table
,
11727 arange_table_allocated
);
11728 memset (arange_table
+ arange_table_in_use
, 0,
11729 ARANGE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
11732 arange_table
[arange_table_in_use
++] = die
;
11735 /* Output the information that goes into the .debug_aranges table.
11736 Namely, define the beginning and ending address range of the
11737 text section generated for this compilation unit. */
11740 output_aranges (void)
11743 unsigned long aranges_length
= size_of_aranges ();
11745 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11746 dw2_asm_output_data (4, 0xffffffff,
11747 "Initial length escape value indicating 64-bit DWARF extension");
11748 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
11749 "Length of Address Ranges Info");
11750 /* Version number for aranges is still 2, even in DWARF3. */
11751 dw2_asm_output_data (2, 2, "DWARF Version");
11752 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
11753 debug_info_section
,
11754 "Offset of Compilation Unit Info");
11755 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
11756 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11758 /* We need to align to twice the pointer size here. */
11759 if (DWARF_ARANGES_PAD_SIZE
)
11761 /* Pad using a 2 byte words so that padding is correct for any
11763 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11764 2 * DWARF2_ADDR_SIZE
);
11765 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
11766 dw2_asm_output_data (2, 0, NULL
);
11769 /* It is necessary not to output these entries if the sections were
11770 not used; if the sections were not used, the length will be 0 and
11771 the address may end up as 0 if the section is discarded by ld
11772 --gc-sections, leaving an invalid (0, 0) entry that can be
11773 confused with the terminator. */
11774 if (text_section_used
)
11776 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
11777 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
11778 text_section_label
, "Length");
11780 if (cold_text_section_used
)
11782 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
11784 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
11785 cold_text_section_label
, "Length");
11788 for (i
= 0; i
< arange_table_in_use
; i
++)
11790 dw_die_ref die
= arange_table
[i
];
11792 /* We shouldn't see aranges for DIEs outside of the main CU. */
11793 gcc_assert (die
->die_mark
);
11795 if (die
->die_tag
== DW_TAG_subprogram
)
11797 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
11799 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
11800 get_AT_low_pc (die
), "Length");
11804 /* A static variable; extract the symbol from DW_AT_location.
11805 Note that this code isn't currently hit, as we only emit
11806 aranges for functions (jason 9/23/99). */
11807 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
11808 dw_loc_descr_ref loc
;
11810 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
11813 gcc_assert (loc
->dw_loc_opc
== DW_OP_addr
);
11815 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
11816 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
11817 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
11818 get_AT_unsigned (die
, DW_AT_byte_size
),
11823 /* Output the terminator words. */
11824 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11825 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11828 /* Add a new entry to .debug_ranges. Return the offset at which it
11831 static unsigned int
11832 add_ranges_num (int num
)
11834 unsigned int in_use
= ranges_table_in_use
;
11836 if (in_use
== ranges_table_allocated
)
11838 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
11839 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
11840 ranges_table_allocated
);
11841 memset (ranges_table
+ ranges_table_in_use
, 0,
11842 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
11845 ranges_table
[in_use
].num
= num
;
11846 ranges_table_in_use
= in_use
+ 1;
11848 return in_use
* 2 * DWARF2_ADDR_SIZE
;
11851 /* Add a new entry to .debug_ranges corresponding to a block, or a
11852 range terminator if BLOCK is NULL. */
11854 static unsigned int
11855 add_ranges (const_tree block
)
11857 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
11860 /* Add a new entry to .debug_ranges corresponding to a pair of
11864 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
11867 unsigned int in_use
= ranges_by_label_in_use
;
11868 unsigned int offset
;
11870 if (in_use
== ranges_by_label_allocated
)
11872 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
11873 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
11875 ranges_by_label_allocated
);
11876 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
11877 RANGES_TABLE_INCREMENT
11878 * sizeof (struct dw_ranges_by_label_struct
));
11881 ranges_by_label
[in_use
].begin
= begin
;
11882 ranges_by_label
[in_use
].end
= end
;
11883 ranges_by_label_in_use
= in_use
+ 1;
11885 offset
= add_ranges_num (-(int)in_use
- 1);
11888 add_AT_range_list (die
, DW_AT_ranges
, offset
);
11894 output_ranges (void)
11897 static const char *const start_fmt
= "Offset %#x";
11898 const char *fmt
= start_fmt
;
11900 for (i
= 0; i
< ranges_table_in_use
; i
++)
11902 int block_num
= ranges_table
[i
].num
;
11906 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11907 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11909 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
11910 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
11912 /* If all code is in the text section, then the compilation
11913 unit base address defaults to DW_AT_low_pc, which is the
11914 base of the text section. */
11915 if (!have_multiple_function_sections
)
11917 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
11918 text_section_label
,
11919 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11920 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
11921 text_section_label
, NULL
);
11924 /* Otherwise, the compilation unit base address is zero,
11925 which allows us to use absolute addresses, and not worry
11926 about whether the target supports cross-section
11930 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11931 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11932 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
11938 /* Negative block_num stands for an index into ranges_by_label. */
11939 else if (block_num
< 0)
11941 int lab_idx
= - block_num
- 1;
11943 if (!have_multiple_function_sections
)
11945 gcc_unreachable ();
11947 /* If we ever use add_ranges_by_labels () for a single
11948 function section, all we have to do is to take out
11949 the #if 0 above. */
11950 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11951 ranges_by_label
[lab_idx
].begin
,
11952 text_section_label
,
11953 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11954 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11955 ranges_by_label
[lab_idx
].end
,
11956 text_section_label
, NULL
);
11961 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11962 ranges_by_label
[lab_idx
].begin
,
11963 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11964 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11965 ranges_by_label
[lab_idx
].end
,
11971 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11972 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11978 /* Data structure containing information about input files. */
11981 const char *path
; /* Complete file name. */
11982 const char *fname
; /* File name part. */
11983 int length
; /* Length of entire string. */
11984 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
11985 int dir_idx
; /* Index in directory table. */
11988 /* Data structure containing information about directories with source
11992 const char *path
; /* Path including directory name. */
11993 int length
; /* Path length. */
11994 int prefix
; /* Index of directory entry which is a prefix. */
11995 int count
; /* Number of files in this directory. */
11996 int dir_idx
; /* Index of directory used as base. */
11999 /* Callback function for file_info comparison. We sort by looking at
12000 the directories in the path. */
12003 file_info_cmp (const void *p1
, const void *p2
)
12005 const struct file_info
*const s1
= (const struct file_info
*) p1
;
12006 const struct file_info
*const s2
= (const struct file_info
*) p2
;
12007 const unsigned char *cp1
;
12008 const unsigned char *cp2
;
12010 /* Take care of file names without directories. We need to make sure that
12011 we return consistent values to qsort since some will get confused if
12012 we return the same value when identical operands are passed in opposite
12013 orders. So if neither has a directory, return 0 and otherwise return
12014 1 or -1 depending on which one has the directory. */
12015 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
12016 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
12018 cp1
= (const unsigned char *) s1
->path
;
12019 cp2
= (const unsigned char *) s2
->path
;
12025 /* Reached the end of the first path? If so, handle like above. */
12026 if ((cp1
== (const unsigned char *) s1
->fname
)
12027 || (cp2
== (const unsigned char *) s2
->fname
))
12028 return ((cp2
== (const unsigned char *) s2
->fname
)
12029 - (cp1
== (const unsigned char *) s1
->fname
));
12031 /* Character of current path component the same? */
12032 else if (*cp1
!= *cp2
)
12033 return *cp1
- *cp2
;
12037 struct file_name_acquire_data
12039 struct file_info
*files
;
12044 /* Traversal function for the hash table. */
12047 file_name_acquire (void ** slot
, void *data
)
12049 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
12050 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
12051 struct file_info
*fi
;
12054 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
12056 if (! d
->emitted_number
)
12059 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
12061 fi
= fnad
->files
+ fnad
->used_files
++;
12063 /* Skip all leading "./". */
12065 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
12068 /* Create a new array entry. */
12070 fi
->length
= strlen (f
);
12073 /* Search for the file name part. */
12074 f
= strrchr (f
, DIR_SEPARATOR
);
12075 #if defined (DIR_SEPARATOR_2)
12077 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
12081 if (f
== NULL
|| f
< g
)
12087 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
12091 /* Output the directory table and the file name table. We try to minimize
12092 the total amount of memory needed. A heuristic is used to avoid large
12093 slowdowns with many input files. */
12096 output_file_names (void)
12098 struct file_name_acquire_data fnad
;
12100 struct file_info
*files
;
12101 struct dir_info
*dirs
;
12109 if (!last_emitted_file
)
12111 dw2_asm_output_data (1, 0, "End directory table");
12112 dw2_asm_output_data (1, 0, "End file name table");
12116 numfiles
= last_emitted_file
->emitted_number
;
12118 /* Allocate the various arrays we need. */
12119 files
= XALLOCAVEC (struct file_info
, numfiles
);
12120 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
12122 fnad
.files
= files
;
12123 fnad
.used_files
= 0;
12124 fnad
.max_files
= numfiles
;
12125 htab_traverse (file_table
, file_name_acquire
, &fnad
);
12126 gcc_assert (fnad
.used_files
== fnad
.max_files
);
12128 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
12130 /* Find all the different directories used. */
12131 dirs
[0].path
= files
[0].path
;
12132 dirs
[0].length
= files
[0].fname
- files
[0].path
;
12133 dirs
[0].prefix
= -1;
12135 dirs
[0].dir_idx
= 0;
12136 files
[0].dir_idx
= 0;
12139 for (i
= 1; i
< numfiles
; i
++)
12140 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
12141 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
12142 dirs
[ndirs
- 1].length
) == 0)
12144 /* Same directory as last entry. */
12145 files
[i
].dir_idx
= ndirs
- 1;
12146 ++dirs
[ndirs
- 1].count
;
12152 /* This is a new directory. */
12153 dirs
[ndirs
].path
= files
[i
].path
;
12154 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
12155 dirs
[ndirs
].count
= 1;
12156 dirs
[ndirs
].dir_idx
= ndirs
;
12157 files
[i
].dir_idx
= ndirs
;
12159 /* Search for a prefix. */
12160 dirs
[ndirs
].prefix
= -1;
12161 for (j
= 0; j
< ndirs
; j
++)
12162 if (dirs
[j
].length
< dirs
[ndirs
].length
12163 && dirs
[j
].length
> 1
12164 && (dirs
[ndirs
].prefix
== -1
12165 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
12166 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
12167 dirs
[ndirs
].prefix
= j
;
12172 /* Now to the actual work. We have to find a subset of the directories which
12173 allow expressing the file name using references to the directory table
12174 with the least amount of characters. We do not do an exhaustive search
12175 where we would have to check out every combination of every single
12176 possible prefix. Instead we use a heuristic which provides nearly optimal
12177 results in most cases and never is much off. */
12178 saved
= XALLOCAVEC (int, ndirs
);
12179 savehere
= XALLOCAVEC (int, ndirs
);
12181 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
12182 for (i
= 0; i
< ndirs
; i
++)
12187 /* We can always save some space for the current directory. But this
12188 does not mean it will be enough to justify adding the directory. */
12189 savehere
[i
] = dirs
[i
].length
;
12190 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
12192 for (j
= i
+ 1; j
< ndirs
; j
++)
12195 if (saved
[j
] < dirs
[i
].length
)
12197 /* Determine whether the dirs[i] path is a prefix of the
12201 k
= dirs
[j
].prefix
;
12202 while (k
!= -1 && k
!= (int) i
)
12203 k
= dirs
[k
].prefix
;
12207 /* Yes it is. We can possibly save some memory by
12208 writing the filenames in dirs[j] relative to
12210 savehere
[j
] = dirs
[i
].length
;
12211 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
12216 /* Check whether we can save enough to justify adding the dirs[i]
12218 if (total
> dirs
[i
].length
+ 1)
12220 /* It's worthwhile adding. */
12221 for (j
= i
; j
< ndirs
; j
++)
12222 if (savehere
[j
] > 0)
12224 /* Remember how much we saved for this directory so far. */
12225 saved
[j
] = savehere
[j
];
12227 /* Remember the prefix directory. */
12228 dirs
[j
].dir_idx
= i
;
12233 /* Emit the directory name table. */
12234 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
12235 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
12236 dw2_asm_output_nstring (dirs
[i
].path
,
12238 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
12239 "Directory Entry: %#x", i
+ idx_offset
);
12241 dw2_asm_output_data (1, 0, "End directory table");
12243 /* We have to emit them in the order of emitted_number since that's
12244 used in the debug info generation. To do this efficiently we
12245 generate a back-mapping of the indices first. */
12246 backmap
= XALLOCAVEC (int, numfiles
);
12247 for (i
= 0; i
< numfiles
; i
++)
12248 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
12250 /* Now write all the file names. */
12251 for (i
= 0; i
< numfiles
; i
++)
12253 int file_idx
= backmap
[i
];
12254 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
12256 #ifdef VMS_DEBUGGING_INFO
12257 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12259 /* Setting these fields can lead to debugger miscomparisons,
12260 but VMS Debug requires them to be set correctly. */
12265 int maxfilelen
= strlen (files
[file_idx
].path
)
12266 + dirs
[dir_idx
].length
12267 + MAX_VMS_VERSION_LEN
+ 1;
12268 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
12270 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
12271 snprintf (filebuf
, maxfilelen
, "%s;%d",
12272 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
12274 dw2_asm_output_nstring
12275 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
12277 /* Include directory index. */
12278 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
12280 /* Modification time. */
12281 dw2_asm_output_data_uleb128
12282 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
12286 /* File length in bytes. */
12287 dw2_asm_output_data_uleb128
12288 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
12292 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
12293 "File Entry: %#x", (unsigned) i
+ 1);
12295 /* Include directory index. */
12296 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
12298 /* Modification time. */
12299 dw2_asm_output_data_uleb128 (0, NULL
);
12301 /* File length in bytes. */
12302 dw2_asm_output_data_uleb128 (0, NULL
);
12303 #endif /* VMS_DEBUGGING_INFO */
12306 dw2_asm_output_data (1, 0, "End file name table");
12310 /* Output the source line number correspondence information. This
12311 information goes into the .debug_line section. */
12314 output_line_info (void)
12316 char l1
[20], l2
[20], p1
[20], p2
[20];
12317 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
12318 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
12320 unsigned n_op_args
;
12321 unsigned long lt_index
;
12322 unsigned long current_line
;
12325 unsigned long current_file
;
12326 unsigned long function
;
12327 int ver
= dwarf_version
;
12329 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
12330 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
12331 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
12332 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
12334 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
12335 dw2_asm_output_data (4, 0xffffffff,
12336 "Initial length escape value indicating 64-bit DWARF extension");
12337 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
12338 "Length of Source Line Info");
12339 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
12341 dw2_asm_output_data (2, ver
, "DWARF Version");
12342 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
12343 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
12345 /* Define the architecture-dependent minimum instruction length (in
12346 bytes). In this implementation of DWARF, this field is used for
12347 information purposes only. Since GCC generates assembly language,
12348 we have no a priori knowledge of how many instruction bytes are
12349 generated for each source line, and therefore can use only the
12350 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
12351 commands. Accordingly, we fix this as `1', which is "correct
12352 enough" for all architectures, and don't let the target override. */
12353 dw2_asm_output_data (1, 1,
12354 "Minimum Instruction Length");
12357 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
12358 "Maximum Operations Per Instruction");
12359 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
12360 "Default is_stmt_start flag");
12361 dw2_asm_output_data (1, DWARF_LINE_BASE
,
12362 "Line Base Value (Special Opcodes)");
12363 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
12364 "Line Range Value (Special Opcodes)");
12365 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
12366 "Special Opcode Base");
12368 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
12372 case DW_LNS_advance_pc
:
12373 case DW_LNS_advance_line
:
12374 case DW_LNS_set_file
:
12375 case DW_LNS_set_column
:
12376 case DW_LNS_fixed_advance_pc
:
12384 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
12388 /* Write out the information about the files we use. */
12389 output_file_names ();
12390 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
12392 /* We used to set the address register to the first location in the text
12393 section here, but that didn't accomplish anything since we already
12394 have a line note for the opening brace of the first function. */
12396 /* Generate the line number to PC correspondence table, encoded as
12397 a series of state machine operations. */
12401 if (cfun
&& in_cold_section_p
)
12402 strcpy (prev_line_label
, crtl
->subsections
.cold_section_label
);
12404 strcpy (prev_line_label
, text_section_label
);
12405 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
12407 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
12410 /* Disable this optimization for now; GDB wants to see two line notes
12411 at the beginning of a function so it can find the end of the
12414 /* Don't emit anything for redundant notes. Just updating the
12415 address doesn't accomplish anything, because we already assume
12416 that anything after the last address is this line. */
12417 if (line_info
->dw_line_num
== current_line
12418 && line_info
->dw_file_num
== current_file
)
12422 /* Emit debug info for the address of the current line.
12424 Unfortunately, we have little choice here currently, and must always
12425 use the most general form. GCC does not know the address delta
12426 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
12427 attributes which will give an upper bound on the address range. We
12428 could perhaps use length attributes to determine when it is safe to
12429 use DW_LNS_fixed_advance_pc. */
12431 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
12434 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
12435 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
12436 "DW_LNS_fixed_advance_pc");
12437 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
12441 /* This can handle any delta. This takes
12442 4+DWARF2_ADDR_SIZE bytes. */
12443 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12444 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12445 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12446 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
12449 strcpy (prev_line_label
, line_label
);
12451 /* Emit debug info for the source file of the current line, if
12452 different from the previous line. */
12453 if (line_info
->dw_file_num
!= current_file
)
12455 current_file
= line_info
->dw_file_num
;
12456 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
12457 dw2_asm_output_data_uleb128 (current_file
, "%lu", current_file
);
12460 /* Emit debug info for the current line number, choosing the encoding
12461 that uses the least amount of space. */
12462 if (line_info
->dw_line_num
!= current_line
)
12464 line_offset
= line_info
->dw_line_num
- current_line
;
12465 line_delta
= line_offset
- DWARF_LINE_BASE
;
12466 current_line
= line_info
->dw_line_num
;
12467 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
12468 /* This can handle deltas from -10 to 234, using the current
12469 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
12471 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
12472 "line %lu", current_line
);
12475 /* This can handle any delta. This takes at least 4 bytes,
12476 depending on the value being encoded. */
12477 dw2_asm_output_data (1, DW_LNS_advance_line
,
12478 "advance to line %lu", current_line
);
12479 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
12480 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
12484 /* We still need to start a new row, so output a copy insn. */
12485 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
12488 /* Emit debug info for the address of the end of the function. */
12491 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
12492 "DW_LNS_fixed_advance_pc");
12493 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
12497 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12498 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12499 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12500 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
12503 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12504 dw2_asm_output_data_uleb128 (1, NULL
);
12505 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
12510 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
12512 dw_separate_line_info_ref line_info
12513 = &separate_line_info_table
[lt_index
];
12516 /* Don't emit anything for redundant notes. */
12517 if (line_info
->dw_line_num
== current_line
12518 && line_info
->dw_file_num
== current_file
12519 && line_info
->function
== function
)
12523 /* Emit debug info for the address of the current line. If this is
12524 a new function, or the first line of a function, then we need
12525 to handle it differently. */
12526 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
12528 if (function
!= line_info
->function
)
12530 function
= line_info
->function
;
12532 /* Set the address register to the first line in the function. */
12533 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12534 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12535 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12536 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
12540 /* ??? See the DW_LNS_advance_pc comment above. */
12543 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
12544 "DW_LNS_fixed_advance_pc");
12545 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
12549 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12550 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12551 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12552 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
12556 strcpy (prev_line_label
, line_label
);
12558 /* Emit debug info for the source file of the current line, if
12559 different from the previous line. */
12560 if (line_info
->dw_file_num
!= current_file
)
12562 current_file
= line_info
->dw_file_num
;
12563 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
12564 dw2_asm_output_data_uleb128 (current_file
, "%lu", current_file
);
12567 /* Emit debug info for the current line number, choosing the encoding
12568 that uses the least amount of space. */
12569 if (line_info
->dw_line_num
!= current_line
)
12571 line_offset
= line_info
->dw_line_num
- current_line
;
12572 line_delta
= line_offset
- DWARF_LINE_BASE
;
12573 current_line
= line_info
->dw_line_num
;
12574 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
12575 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
12576 "line %lu", current_line
);
12579 dw2_asm_output_data (1, DW_LNS_advance_line
,
12580 "advance to line %lu", current_line
);
12581 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
12582 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
12586 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
12594 /* If we're done with a function, end its sequence. */
12595 if (lt_index
== separate_line_info_table_in_use
12596 || separate_line_info_table
[lt_index
].function
!= function
)
12601 /* Emit debug info for the address of the end of the function. */
12602 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
12605 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
12606 "DW_LNS_fixed_advance_pc");
12607 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
12611 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12612 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12613 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12614 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
12617 /* Output the marker for the end of this sequence. */
12618 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12619 dw2_asm_output_data_uleb128 (1, NULL
);
12620 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
12624 /* Output the marker for the end of the line number info. */
12625 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
12628 /* Given a pointer to a tree node for some base type, return a pointer to
12629 a DIE that describes the given type.
12631 This routine must only be called for GCC type nodes that correspond to
12632 Dwarf base (fundamental) types. */
12635 base_type_die (tree type
)
12637 dw_die_ref base_type_result
;
12638 enum dwarf_type encoding
;
12640 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
12643 /* If this is a subtype that should not be emitted as a subrange type,
12644 use the base type. See subrange_type_for_debug_p. */
12645 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
12646 type
= TREE_TYPE (type
);
12648 switch (TREE_CODE (type
))
12651 if ((dwarf_version
>= 4 || !dwarf_strict
)
12652 && TYPE_NAME (type
)
12653 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12654 && DECL_IS_BUILTIN (TYPE_NAME (type
))
12655 && DECL_NAME (TYPE_NAME (type
)))
12657 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
12658 if (strcmp (name
, "char16_t") == 0
12659 || strcmp (name
, "char32_t") == 0)
12661 encoding
= DW_ATE_UTF
;
12665 if (TYPE_STRING_FLAG (type
))
12667 if (TYPE_UNSIGNED (type
))
12668 encoding
= DW_ATE_unsigned_char
;
12670 encoding
= DW_ATE_signed_char
;
12672 else if (TYPE_UNSIGNED (type
))
12673 encoding
= DW_ATE_unsigned
;
12675 encoding
= DW_ATE_signed
;
12679 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
12681 if (dwarf_version
>= 3 || !dwarf_strict
)
12682 encoding
= DW_ATE_decimal_float
;
12684 encoding
= DW_ATE_lo_user
;
12687 encoding
= DW_ATE_float
;
12690 case FIXED_POINT_TYPE
:
12691 if (!(dwarf_version
>= 3 || !dwarf_strict
))
12692 encoding
= DW_ATE_lo_user
;
12693 else if (TYPE_UNSIGNED (type
))
12694 encoding
= DW_ATE_unsigned_fixed
;
12696 encoding
= DW_ATE_signed_fixed
;
12699 /* Dwarf2 doesn't know anything about complex ints, so use
12700 a user defined type for it. */
12702 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
12703 encoding
= DW_ATE_complex_float
;
12705 encoding
= DW_ATE_lo_user
;
12709 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12710 encoding
= DW_ATE_boolean
;
12714 /* No other TREE_CODEs are Dwarf fundamental types. */
12715 gcc_unreachable ();
12718 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
12720 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
12721 int_size_in_bytes (type
));
12722 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
12724 return base_type_result
;
12727 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12728 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12731 is_base_type (tree type
)
12733 switch (TREE_CODE (type
))
12739 case FIXED_POINT_TYPE
:
12747 case QUAL_UNION_TYPE
:
12748 case ENUMERAL_TYPE
:
12749 case FUNCTION_TYPE
:
12752 case REFERENCE_TYPE
:
12760 gcc_unreachable ();
12766 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12767 node, return the size in bits for the type if it is a constant, or else
12768 return the alignment for the type if the type's size is not constant, or
12769 else return BITS_PER_WORD if the type actually turns out to be an
12770 ERROR_MARK node. */
12772 static inline unsigned HOST_WIDE_INT
12773 simple_type_size_in_bits (const_tree type
)
12775 if (TREE_CODE (type
) == ERROR_MARK
)
12776 return BITS_PER_WORD
;
12777 else if (TYPE_SIZE (type
) == NULL_TREE
)
12779 else if (host_integerp (TYPE_SIZE (type
), 1))
12780 return tree_low_cst (TYPE_SIZE (type
), 1);
12782 return TYPE_ALIGN (type
);
12785 /* Similarly, but return a double_int instead of UHWI. */
12787 static inline double_int
12788 double_int_type_size_in_bits (const_tree type
)
12790 if (TREE_CODE (type
) == ERROR_MARK
)
12791 return uhwi_to_double_int (BITS_PER_WORD
);
12792 else if (TYPE_SIZE (type
) == NULL_TREE
)
12793 return double_int_zero
;
12794 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
12795 return tree_to_double_int (TYPE_SIZE (type
));
12797 return uhwi_to_double_int (TYPE_ALIGN (type
));
12800 /* Given a pointer to a tree node for a subrange type, return a pointer
12801 to a DIE that describes the given type. */
12804 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
12806 dw_die_ref subrange_die
;
12807 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
12809 if (context_die
== NULL
)
12810 context_die
= comp_unit_die ();
12812 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
12814 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
12816 /* The size of the subrange type and its base type do not match,
12817 so we need to generate a size attribute for the subrange type. */
12818 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
12822 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
12824 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
12826 return subrange_die
;
12829 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12830 entry that chains various modifiers in front of the given type. */
12833 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
12834 dw_die_ref context_die
)
12836 enum tree_code code
= TREE_CODE (type
);
12837 dw_die_ref mod_type_die
;
12838 dw_die_ref sub_die
= NULL
;
12839 tree item_type
= NULL
;
12840 tree qualified_type
;
12841 tree name
, low
, high
;
12843 if (code
== ERROR_MARK
)
12846 /* See if we already have the appropriately qualified variant of
12849 = get_qualified_type (type
,
12850 ((is_const_type
? TYPE_QUAL_CONST
: 0)
12851 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
12853 if (qualified_type
== sizetype
12854 && TYPE_NAME (qualified_type
)
12855 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
12857 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
12859 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
12860 && TYPE_PRECISION (t
)
12861 == TYPE_PRECISION (qualified_type
)
12862 && TYPE_UNSIGNED (t
)
12863 == TYPE_UNSIGNED (qualified_type
));
12864 qualified_type
= t
;
12867 /* If we do, then we can just use its DIE, if it exists. */
12868 if (qualified_type
)
12870 mod_type_die
= lookup_type_die (qualified_type
);
12872 return mod_type_die
;
12875 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
12877 /* Handle C typedef types. */
12878 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
12879 && !DECL_ARTIFICIAL (name
))
12881 tree dtype
= TREE_TYPE (name
);
12883 if (qualified_type
== dtype
)
12885 /* For a named type, use the typedef. */
12886 gen_type_die (qualified_type
, context_die
);
12887 return lookup_type_die (qualified_type
);
12889 else if (is_const_type
< TYPE_READONLY (dtype
)
12890 || is_volatile_type
< TYPE_VOLATILE (dtype
)
12891 || (is_const_type
<= TYPE_READONLY (dtype
)
12892 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
12893 && DECL_ORIGINAL_TYPE (name
) != type
))
12894 /* cv-unqualified version of named type. Just use the unnamed
12895 type to which it refers. */
12896 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
12897 is_const_type
, is_volatile_type
,
12899 /* Else cv-qualified version of named type; fall through. */
12903 /* If both is_const_type and is_volatile_type, prefer the path
12904 which leads to a qualified type. */
12905 && (!is_volatile_type
12906 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
12907 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
12909 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die (), type
);
12910 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
12912 else if (is_volatile_type
)
12914 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die (), type
);
12915 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
12917 else if (code
== POINTER_TYPE
)
12919 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die (), type
);
12920 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
12921 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
12922 item_type
= TREE_TYPE (type
);
12923 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
12924 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
12925 TYPE_ADDR_SPACE (item_type
));
12927 else if (code
== REFERENCE_TYPE
)
12929 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
12930 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, comp_unit_die (),
12933 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die (), type
);
12934 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
12935 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
12936 item_type
= TREE_TYPE (type
);
12937 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
12938 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
12939 TYPE_ADDR_SPACE (item_type
));
12941 else if (code
== INTEGER_TYPE
12942 && TREE_TYPE (type
) != NULL_TREE
12943 && subrange_type_for_debug_p (type
, &low
, &high
))
12945 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
12946 item_type
= TREE_TYPE (type
);
12948 else if (is_base_type (type
))
12949 mod_type_die
= base_type_die (type
);
12952 gen_type_die (type
, context_die
);
12954 /* We have to get the type_main_variant here (and pass that to the
12955 `lookup_type_die' routine) because the ..._TYPE node we have
12956 might simply be a *copy* of some original type node (where the
12957 copy was created to help us keep track of typedef names) and
12958 that copy might have a different TYPE_UID from the original
12960 if (TREE_CODE (type
) != VECTOR_TYPE
)
12961 return lookup_type_die (type_main_variant (type
));
12963 /* Vectors have the debugging information in the type,
12964 not the main variant. */
12965 return lookup_type_die (type
);
12968 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
12969 don't output a DW_TAG_typedef, since there isn't one in the
12970 user's program; just attach a DW_AT_name to the type.
12971 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
12972 if the base type already has the same name. */
12974 && ((TREE_CODE (name
) != TYPE_DECL
12975 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
12976 || (!is_const_type
&& !is_volatile_type
)))
12977 || (TREE_CODE (name
) == TYPE_DECL
12978 && TREE_TYPE (name
) == qualified_type
12979 && DECL_NAME (name
))))
12981 if (TREE_CODE (name
) == TYPE_DECL
)
12982 /* Could just call add_name_and_src_coords_attributes here,
12983 but since this is a builtin type it doesn't have any
12984 useful source coordinates anyway. */
12985 name
= DECL_NAME (name
);
12986 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
12988 /* This probably indicates a bug. */
12989 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
12990 add_name_attribute (mod_type_die
, "__unknown__");
12992 if (qualified_type
)
12993 equate_type_number_to_die (qualified_type
, mod_type_die
);
12996 /* We must do this after the equate_type_number_to_die call, in case
12997 this is a recursive type. This ensures that the modified_type_die
12998 recursion will terminate even if the type is recursive. Recursive
12999 types are possible in Ada. */
13000 sub_die
= modified_type_die (item_type
,
13001 TYPE_READONLY (item_type
),
13002 TYPE_VOLATILE (item_type
),
13005 if (sub_die
!= NULL
)
13006 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
13008 return mod_type_die
;
13011 /* Generate DIEs for the generic parameters of T.
13012 T must be either a generic type or a generic function.
13013 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
13016 gen_generic_params_dies (tree t
)
13020 dw_die_ref die
= NULL
;
13022 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
13026 die
= lookup_type_die (t
);
13027 else if (DECL_P (t
))
13028 die
= lookup_decl_die (t
);
13032 parms
= lang_hooks
.get_innermost_generic_parms (t
);
13034 /* T has no generic parameter. It means T is neither a generic type
13035 or function. End of story. */
13038 parms_num
= TREE_VEC_LENGTH (parms
);
13039 args
= lang_hooks
.get_innermost_generic_args (t
);
13040 for (i
= 0; i
< parms_num
; i
++)
13042 tree parm
, arg
, arg_pack_elems
;
13044 parm
= TREE_VEC_ELT (parms
, i
);
13045 arg
= TREE_VEC_ELT (args
, i
);
13046 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
13047 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
13049 if (parm
&& TREE_VALUE (parm
) && arg
)
13051 /* If PARM represents a template parameter pack,
13052 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
13053 by DW_TAG_template_*_parameter DIEs for the argument
13054 pack elements of ARG. Note that ARG would then be
13055 an argument pack. */
13056 if (arg_pack_elems
)
13057 template_parameter_pack_die (TREE_VALUE (parm
),
13061 generic_parameter_die (TREE_VALUE (parm
), arg
,
13062 true /* Emit DW_AT_name */, die
);
13067 /* Create and return a DIE for PARM which should be
13068 the representation of a generic type parameter.
13069 For instance, in the C++ front end, PARM would be a template parameter.
13070 ARG is the argument to PARM.
13071 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
13073 PARENT_DIE is the parent DIE which the new created DIE should be added to,
13074 as a child node. */
13077 generic_parameter_die (tree parm
, tree arg
,
13079 dw_die_ref parent_die
)
13081 dw_die_ref tmpl_die
= NULL
;
13082 const char *name
= NULL
;
13084 if (!parm
|| !DECL_NAME (parm
) || !arg
)
13087 /* We support non-type generic parameters and arguments,
13088 type generic parameters and arguments, as well as
13089 generic generic parameters (a.k.a. template template parameters in C++)
13091 if (TREE_CODE (parm
) == PARM_DECL
)
13092 /* PARM is a nontype generic parameter */
13093 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
13094 else if (TREE_CODE (parm
) == TYPE_DECL
)
13095 /* PARM is a type generic parameter. */
13096 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
13097 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
13098 /* PARM is a generic generic parameter.
13099 Its DIE is a GNU extension. It shall have a
13100 DW_AT_name attribute to represent the name of the template template
13101 parameter, and a DW_AT_GNU_template_name attribute to represent the
13102 name of the template template argument. */
13103 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
13106 gcc_unreachable ();
13112 /* If PARM is a generic parameter pack, it means we are
13113 emitting debug info for a template argument pack element.
13114 In other terms, ARG is a template argument pack element.
13115 In that case, we don't emit any DW_AT_name attribute for
13119 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
13121 add_AT_string (tmpl_die
, DW_AT_name
, name
);
13124 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
13126 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
13127 TMPL_DIE should have a child DW_AT_type attribute that is set
13128 to the type of the argument to PARM, which is ARG.
13129 If PARM is a type generic parameter, TMPL_DIE should have a
13130 child DW_AT_type that is set to ARG. */
13131 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
13132 add_type_attribute (tmpl_die
, tmpl_type
, 0,
13133 TREE_THIS_VOLATILE (tmpl_type
),
13138 /* So TMPL_DIE is a DIE representing a
13139 a generic generic template parameter, a.k.a template template
13140 parameter in C++ and arg is a template. */
13142 /* The DW_AT_GNU_template_name attribute of the DIE must be set
13143 to the name of the argument. */
13144 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
13146 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
13149 if (TREE_CODE (parm
) == PARM_DECL
)
13150 /* So PARM is a non-type generic parameter.
13151 DWARF3 5.6.8 says we must set a DW_AT_const_value child
13152 attribute of TMPL_DIE which value represents the value
13154 We must be careful here:
13155 The value of ARG might reference some function decls.
13156 We might currently be emitting debug info for a generic
13157 type and types are emitted before function decls, we don't
13158 know if the function decls referenced by ARG will actually be
13159 emitted after cgraph computations.
13160 So must defer the generation of the DW_AT_const_value to
13161 after cgraph is ready. */
13162 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
13168 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
13169 PARM_PACK must be a template parameter pack. The returned DIE
13170 will be child DIE of PARENT_DIE. */
13173 template_parameter_pack_die (tree parm_pack
,
13174 tree parm_pack_args
,
13175 dw_die_ref parent_die
)
13180 gcc_assert (parent_die
&& parm_pack
);
13182 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
13183 add_name_and_src_coords_attributes (die
, parm_pack
);
13184 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
13185 generic_parameter_die (parm_pack
,
13186 TREE_VEC_ELT (parm_pack_args
, j
),
13187 false /* Don't emit DW_AT_name */,
13192 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
13193 an enumerated type. */
13196 type_is_enum (const_tree type
)
13198 return TREE_CODE (type
) == ENUMERAL_TYPE
;
13201 /* Return the DBX register number described by a given RTL node. */
13203 static unsigned int
13204 dbx_reg_number (const_rtx rtl
)
13206 unsigned regno
= REGNO (rtl
);
13208 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
13210 #ifdef LEAF_REG_REMAP
13211 if (current_function_uses_only_leaf_regs
)
13213 int leaf_reg
= LEAF_REG_REMAP (regno
);
13214 if (leaf_reg
!= -1)
13215 regno
= (unsigned) leaf_reg
;
13219 return DBX_REGISTER_NUMBER (regno
);
13222 /* Optionally add a DW_OP_piece term to a location description expression.
13223 DW_OP_piece is only added if the location description expression already
13224 doesn't end with DW_OP_piece. */
13227 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
13229 dw_loc_descr_ref loc
;
13231 if (*list_head
!= NULL
)
13233 /* Find the end of the chain. */
13234 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
13237 if (loc
->dw_loc_opc
!= DW_OP_piece
)
13238 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
13242 /* Return a location descriptor that designates a machine register or
13243 zero if there is none. */
13245 static dw_loc_descr_ref
13246 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
13250 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
13253 /* We only use "frame base" when we're sure we're talking about the
13254 post-prologue local stack frame. We do this by *not* running
13255 register elimination until this point, and recognizing the special
13256 argument pointer and soft frame pointer rtx's.
13257 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13258 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
13259 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
13261 dw_loc_descr_ref result
= NULL
;
13263 if (dwarf_version
>= 4 || !dwarf_strict
)
13265 result
= mem_loc_descriptor (rtl
, VOIDmode
, initialized
);
13267 add_loc_descr (&result
,
13268 new_loc_descr (DW_OP_stack_value
, 0, 0));
13273 regs
= targetm
.dwarf_register_span (rtl
);
13275 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
13276 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
13278 return one_reg_loc_descriptor (dbx_reg_number (rtl
), initialized
);
13281 /* Return a location descriptor that designates a machine register for
13282 a given hard register number. */
13284 static dw_loc_descr_ref
13285 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
13287 dw_loc_descr_ref reg_loc_descr
;
13291 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
13293 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
13295 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13296 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13298 return reg_loc_descr
;
13301 /* Given an RTL of a register, return a location descriptor that
13302 designates a value that spans more than one register. */
13304 static dw_loc_descr_ref
13305 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
13306 enum var_init_status initialized
)
13308 int nregs
, size
, i
;
13310 dw_loc_descr_ref loc_result
= NULL
;
13313 #ifdef LEAF_REG_REMAP
13314 if (current_function_uses_only_leaf_regs
)
13316 int leaf_reg
= LEAF_REG_REMAP (reg
);
13317 if (leaf_reg
!= -1)
13318 reg
= (unsigned) leaf_reg
;
13321 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
13322 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
13324 /* Simple, contiguous registers. */
13325 if (regs
== NULL_RTX
)
13327 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
13332 dw_loc_descr_ref t
;
13334 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
13335 VAR_INIT_STATUS_INITIALIZED
);
13336 add_loc_descr (&loc_result
, t
);
13337 add_loc_descr_op_piece (&loc_result
, size
);
13343 /* Now onto stupid register sets in non contiguous locations. */
13345 gcc_assert (GET_CODE (regs
) == PARALLEL
);
13347 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
13350 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
13352 dw_loc_descr_ref t
;
13354 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
13355 VAR_INIT_STATUS_INITIALIZED
);
13356 add_loc_descr (&loc_result
, t
);
13357 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
13358 add_loc_descr_op_piece (&loc_result
, size
);
13361 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13362 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13366 /* Return a location descriptor that designates a constant. */
13368 static dw_loc_descr_ref
13369 int_loc_descriptor (HOST_WIDE_INT i
)
13371 enum dwarf_location_atom op
;
13373 /* Pick the smallest representation of a constant, rather than just
13374 defaulting to the LEB encoding. */
13378 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
13379 else if (i
<= 0xff)
13380 op
= DW_OP_const1u
;
13381 else if (i
<= 0xffff)
13382 op
= DW_OP_const2u
;
13383 else if (HOST_BITS_PER_WIDE_INT
== 32
13384 || i
<= 0xffffffff)
13385 op
= DW_OP_const4u
;
13392 op
= DW_OP_const1s
;
13393 else if (i
>= -0x8000)
13394 op
= DW_OP_const2s
;
13395 else if (HOST_BITS_PER_WIDE_INT
== 32
13396 || i
>= -0x80000000)
13397 op
= DW_OP_const4s
;
13402 return new_loc_descr (op
, i
, 0);
13405 /* Return loc description representing "address" of integer value.
13406 This can appear only as toplevel expression. */
13408 static dw_loc_descr_ref
13409 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
13412 dw_loc_descr_ref loc_result
= NULL
;
13414 if (!(dwarf_version
>= 4 || !dwarf_strict
))
13421 else if (i
<= 0xff)
13423 else if (i
<= 0xffff)
13425 else if (HOST_BITS_PER_WIDE_INT
== 32
13426 || i
<= 0xffffffff)
13429 litsize
= 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
13435 else if (i
>= -0x8000)
13437 else if (HOST_BITS_PER_WIDE_INT
== 32
13438 || i
>= -0x80000000)
13441 litsize
= 1 + size_of_sleb128 (i
);
13443 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13444 is more compact. For DW_OP_stack_value we need:
13445 litsize + 1 (DW_OP_stack_value)
13446 and for DW_OP_implicit_value:
13447 1 (DW_OP_implicit_value) + 1 (length) + size. */
13448 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
13450 loc_result
= int_loc_descriptor (i
);
13451 add_loc_descr (&loc_result
,
13452 new_loc_descr (DW_OP_stack_value
, 0, 0));
13456 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13458 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13459 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
13463 /* Return a location descriptor that designates a base+offset location. */
13465 static dw_loc_descr_ref
13466 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
13467 enum var_init_status initialized
)
13469 unsigned int regno
;
13470 dw_loc_descr_ref result
;
13471 dw_fde_ref fde
= current_fde ();
13473 /* We only use "frame base" when we're sure we're talking about the
13474 post-prologue local stack frame. We do this by *not* running
13475 register elimination until this point, and recognizing the special
13476 argument pointer and soft frame pointer rtx's. */
13477 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
13479 rtx elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
13483 if (GET_CODE (elim
) == PLUS
)
13485 offset
+= INTVAL (XEXP (elim
, 1));
13486 elim
= XEXP (elim
, 0);
13488 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13489 && (elim
== hard_frame_pointer_rtx
13490 || elim
== stack_pointer_rtx
))
13491 || elim
== (frame_pointer_needed
13492 ? hard_frame_pointer_rtx
13493 : stack_pointer_rtx
));
13495 /* If drap register is used to align stack, use frame
13496 pointer + offset to access stack variables. If stack
13497 is aligned without drap, use stack pointer + offset to
13498 access stack variables. */
13499 if (crtl
->stack_realign_tried
13500 && reg
== frame_pointer_rtx
)
13503 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
13504 ? HARD_FRAME_POINTER_REGNUM
13505 : STACK_POINTER_REGNUM
);
13506 return new_reg_loc_descr (base_reg
, offset
);
13509 offset
+= frame_pointer_fb_offset
;
13510 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
13515 && (fde
->drap_reg
== REGNO (reg
)
13516 || fde
->vdrap_reg
== REGNO (reg
)))
13518 /* Use cfa+offset to represent the location of arguments passed
13519 on the stack when drap is used to align stack.
13520 Only do this when not optimizing, for optimized code var-tracking
13521 is supposed to track where the arguments live and the register
13522 used as vdrap or drap in some spot might be used for something
13523 else in other part of the routine. */
13524 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
13527 regno
= dbx_reg_number (reg
);
13529 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
13532 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
13534 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13535 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13540 /* Return true if this RTL expression describes a base+offset calculation. */
13543 is_based_loc (const_rtx rtl
)
13545 return (GET_CODE (rtl
) == PLUS
13546 && ((REG_P (XEXP (rtl
, 0))
13547 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
13548 && CONST_INT_P (XEXP (rtl
, 1)))));
13551 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13554 static dw_loc_descr_ref
13555 tls_mem_loc_descriptor (rtx mem
)
13558 dw_loc_descr_ref loc_result
;
13560 if (MEM_EXPR (mem
) == NULL_TREE
|| MEM_OFFSET (mem
) == NULL_RTX
)
13563 base
= get_base_address (MEM_EXPR (mem
));
13565 || TREE_CODE (base
) != VAR_DECL
13566 || !DECL_THREAD_LOCAL_P (base
))
13569 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
13570 if (loc_result
== NULL
)
13573 if (INTVAL (MEM_OFFSET (mem
)))
13574 loc_descr_plus_const (&loc_result
, INTVAL (MEM_OFFSET (mem
)));
13579 /* Output debug info about reason why we failed to expand expression as dwarf
13583 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
13585 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
13587 fprintf (dump_file
, "Failed to expand as dwarf: ");
13589 print_generic_expr (dump_file
, expr
, dump_flags
);
13592 fprintf (dump_file
, "\n");
13593 print_rtl (dump_file
, rtl
);
13595 fprintf (dump_file
, "\nReason: %s\n", reason
);
13599 /* Helper function for const_ok_for_output, called either directly
13600 or via for_each_rtx. */
13603 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
13607 if (GET_CODE (rtl
) == UNSPEC
)
13609 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13610 we can't express it in the debug info. */
13611 #ifdef ENABLE_CHECKING
13612 /* Don't complain about TLS UNSPECs, those are just too hard to
13614 if (XVECLEN (rtl
, 0) != 1
13615 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
13616 || SYMBOL_REF_DECL (XVECEXP (rtl
, 0, 0)) == NULL
13617 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl
, 0, 0))) != VAR_DECL
13618 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl
, 0, 0))))
13619 inform (current_function_decl
13620 ? DECL_SOURCE_LOCATION (current_function_decl
)
13621 : UNKNOWN_LOCATION
,
13622 #if NUM_UNSPEC_VALUES > 0
13623 "non-delegitimized UNSPEC %s (%d) found in variable location",
13624 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
13625 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
13628 "non-delegitimized UNSPEC %d found in variable location",
13632 expansion_failed (NULL_TREE
, rtl
,
13633 "UNSPEC hasn't been delegitimized.\n");
13637 if (GET_CODE (rtl
) != SYMBOL_REF
)
13640 if (CONSTANT_POOL_ADDRESS_P (rtl
))
13643 get_pool_constant_mark (rtl
, &marked
);
13644 /* If all references to this pool constant were optimized away,
13645 it was not output and thus we can't represent it. */
13648 expansion_failed (NULL_TREE
, rtl
,
13649 "Constant was removed from constant pool.\n");
13654 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
13657 /* Avoid references to external symbols in debug info, on several targets
13658 the linker might even refuse to link when linking a shared library,
13659 and in many other cases the relocations for .debug_info/.debug_loc are
13660 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13661 to be defined within the same shared library or executable are fine. */
13662 if (SYMBOL_REF_EXTERNAL_P (rtl
))
13664 tree decl
= SYMBOL_REF_DECL (rtl
);
13666 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
13668 expansion_failed (NULL_TREE
, rtl
,
13669 "Symbol not defined in current TU.\n");
13677 /* Return true if constant RTL can be emitted in DW_OP_addr or
13678 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13679 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13682 const_ok_for_output (rtx rtl
)
13684 if (GET_CODE (rtl
) == SYMBOL_REF
)
13685 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
13687 if (GET_CODE (rtl
) == CONST
)
13688 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
13693 /* The following routine converts the RTL for a variable or parameter
13694 (resident in memory) into an equivalent Dwarf representation of a
13695 mechanism for getting the address of that same variable onto the top of a
13696 hypothetical "address evaluation" stack.
13698 When creating memory location descriptors, we are effectively transforming
13699 the RTL for a memory-resident object into its Dwarf postfix expression
13700 equivalent. This routine recursively descends an RTL tree, turning
13701 it into Dwarf postfix code as it goes.
13703 MODE is the mode of the memory reference, needed to handle some
13704 autoincrement addressing modes.
13706 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
13707 location list for RTL.
13709 Return 0 if we can't represent the location. */
13711 static dw_loc_descr_ref
13712 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
13713 enum var_init_status initialized
)
13715 dw_loc_descr_ref mem_loc_result
= NULL
;
13716 enum dwarf_location_atom op
;
13717 dw_loc_descr_ref op0
, op1
;
13719 /* Note that for a dynamically sized array, the location we will generate a
13720 description of here will be the lowest numbered location which is
13721 actually within the array. That's *not* necessarily the same as the
13722 zeroth element of the array. */
13724 rtl
= targetm
.delegitimize_address (rtl
);
13726 switch (GET_CODE (rtl
))
13731 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13734 /* The case of a subreg may arise when we have a local (register)
13735 variable or a formal (register) parameter which doesn't quite fill
13736 up an entire register. For now, just assume that it is
13737 legitimate to make the Dwarf info refer to the whole register which
13738 contains the given subreg. */
13739 if (!subreg_lowpart_p (rtl
))
13741 rtl
= SUBREG_REG (rtl
);
13742 if (GET_MODE_SIZE (GET_MODE (rtl
)) > DWARF2_ADDR_SIZE
)
13744 if (GET_MODE_CLASS (GET_MODE (rtl
)) != MODE_INT
)
13746 mem_loc_result
= mem_loc_descriptor (rtl
, mode
, initialized
);
13750 /* Whenever a register number forms a part of the description of the
13751 method for calculating the (dynamic) address of a memory resident
13752 object, DWARF rules require the register number be referred to as
13753 a "base register". This distinction is not based in any way upon
13754 what category of register the hardware believes the given register
13755 belongs to. This is strictly DWARF terminology we're dealing with
13756 here. Note that in cases where the location of a memory-resident
13757 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
13758 OP_CONST (0)) the actual DWARF location descriptor that we generate
13759 may just be OP_BASEREG (basereg). This may look deceptively like
13760 the object in question was allocated to a register (rather than in
13761 memory) so DWARF consumers need to be aware of the subtle
13762 distinction between OP_REG and OP_BASEREG. */
13763 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
13764 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
13765 else if (stack_realign_drap
13767 && crtl
->args
.internal_arg_pointer
== rtl
13768 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
13770 /* If RTL is internal_arg_pointer, which has been optimized
13771 out, use DRAP instead. */
13772 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
13773 VAR_INIT_STATUS_INITIALIZED
);
13779 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13780 VAR_INIT_STATUS_INITIALIZED
);
13785 int shift
= DWARF2_ADDR_SIZE
13786 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
13787 shift
*= BITS_PER_UNIT
;
13788 if (GET_CODE (rtl
) == SIGN_EXTEND
)
13792 mem_loc_result
= op0
;
13793 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
13794 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
13795 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
13796 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13801 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
13802 VAR_INIT_STATUS_INITIALIZED
);
13803 if (mem_loc_result
== NULL
)
13804 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
13805 if (mem_loc_result
!= 0)
13807 if (GET_MODE_SIZE (GET_MODE (rtl
)) > DWARF2_ADDR_SIZE
)
13809 expansion_failed (NULL_TREE
, rtl
, "DWARF address size mismatch");
13812 else if (GET_MODE_SIZE (GET_MODE (rtl
)) == DWARF2_ADDR_SIZE
)
13813 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
13815 add_loc_descr (&mem_loc_result
,
13816 new_loc_descr (DW_OP_deref_size
,
13817 GET_MODE_SIZE (GET_MODE (rtl
)), 0));
13821 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13822 if (new_rtl
!= rtl
)
13823 return mem_loc_descriptor (new_rtl
, mode
, initialized
);
13828 rtl
= XEXP (rtl
, 1);
13830 /* ... fall through ... */
13833 /* Some ports can transform a symbol ref into a label ref, because
13834 the symbol ref is too far away and has to be dumped into a constant
13838 if (GET_CODE (rtl
) == SYMBOL_REF
13839 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
13841 dw_loc_descr_ref temp
;
13843 /* If this is not defined, we have no way to emit the data. */
13844 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
13847 /* We used to emit DW_OP_addr here, but that's wrong, since
13848 DW_OP_addr should be relocated by the debug info consumer,
13849 while DW_OP_GNU_push_tls_address operand should not. */
13850 temp
= new_loc_descr (DWARF2_ADDR_SIZE
== 4
13851 ? DW_OP_const4u
: DW_OP_const8u
, 0, 0);
13852 temp
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
13853 temp
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
13854 temp
->dtprel
= true;
13856 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
13857 add_loc_descr (&mem_loc_result
, temp
);
13862 if (!const_ok_for_output (rtl
))
13866 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
13867 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
13868 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
13869 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
13875 case DEBUG_IMPLICIT_PTR
:
13876 expansion_failed (NULL_TREE
, rtl
,
13877 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
13883 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
13884 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13885 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
13886 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
13887 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl
)),
13888 VAR_INIT_STATUS_INITIALIZED
);
13889 else if (MEM_P (ENTRY_VALUE_EXP (rtl
)) && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
13891 dw_loc_descr_ref ref
13892 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), GET_MODE (rtl
),
13893 VAR_INIT_STATUS_INITIALIZED
);
13896 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= ref
;
13899 gcc_unreachable ();
13900 return mem_loc_result
;
13903 /* Extract the PLUS expression nested inside and fall into
13904 PLUS code below. */
13905 rtl
= XEXP (rtl
, 1);
13910 /* Turn these into a PLUS expression and fall into the PLUS code
13912 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
13913 GEN_INT (GET_CODE (rtl
) == PRE_INC
13914 ? GET_MODE_UNIT_SIZE (mode
)
13915 : -GET_MODE_UNIT_SIZE (mode
)));
13917 /* ... fall through ... */
13921 if (is_based_loc (rtl
))
13922 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
13923 INTVAL (XEXP (rtl
, 1)),
13924 VAR_INIT_STATUS_INITIALIZED
);
13927 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13928 VAR_INIT_STATUS_INITIALIZED
);
13929 if (mem_loc_result
== 0)
13932 if (CONST_INT_P (XEXP (rtl
, 1)))
13933 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
13936 dw_loc_descr_ref mem_loc_result2
13937 = mem_loc_descriptor (XEXP (rtl
, 1), mode
,
13938 VAR_INIT_STATUS_INITIALIZED
);
13939 if (mem_loc_result2
== 0)
13941 add_loc_descr (&mem_loc_result
, mem_loc_result2
);
13942 add_loc_descr (&mem_loc_result
,
13943 new_loc_descr (DW_OP_plus
, 0, 0));
13948 /* If a pseudo-reg is optimized away, it is possible for it to
13949 be replaced with a MEM containing a multiply or shift. */
13991 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13992 VAR_INIT_STATUS_INITIALIZED
);
13993 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
13994 VAR_INIT_STATUS_INITIALIZED
);
13996 if (op0
== 0 || op1
== 0)
13999 mem_loc_result
= op0
;
14000 add_loc_descr (&mem_loc_result
, op1
);
14001 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14005 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
14006 VAR_INIT_STATUS_INITIALIZED
);
14007 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
14008 VAR_INIT_STATUS_INITIALIZED
);
14010 if (op0
== 0 || op1
== 0)
14013 mem_loc_result
= op0
;
14014 add_loc_descr (&mem_loc_result
, op1
);
14015 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
14016 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
14017 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
14018 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
14019 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
14035 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
14036 VAR_INIT_STATUS_INITIALIZED
);
14041 mem_loc_result
= op0
;
14042 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14046 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
14074 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) > DWARF2_ADDR_SIZE
14075 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 1))) > DWARF2_ADDR_SIZE
)
14079 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
14081 if (op_mode
== VOIDmode
)
14082 op_mode
= GET_MODE (XEXP (rtl
, 1));
14083 if (op_mode
!= VOIDmode
&& GET_MODE_CLASS (op_mode
) != MODE_INT
)
14086 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
14087 VAR_INIT_STATUS_INITIALIZED
);
14088 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
14089 VAR_INIT_STATUS_INITIALIZED
);
14091 if (op0
== 0 || op1
== 0)
14094 if (op_mode
!= VOIDmode
14095 && GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
14097 int shift
= DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
);
14098 shift
*= BITS_PER_UNIT
;
14099 /* For eq/ne, if the operands are known to be zero-extended,
14100 there is no need to do the fancy shifting up. */
14101 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
14103 dw_loc_descr_ref last0
, last1
;
14105 last0
->dw_loc_next
!= NULL
;
14106 last0
= last0
->dw_loc_next
)
14109 last1
->dw_loc_next
!= NULL
;
14110 last1
= last1
->dw_loc_next
)
14112 /* deref_size zero extends, and for constants we can check
14113 whether they are zero extended or not. */
14114 if (((last0
->dw_loc_opc
== DW_OP_deref_size
14115 && last0
->dw_loc_oprnd1
.v
.val_int
14116 <= GET_MODE_SIZE (op_mode
))
14117 || (CONST_INT_P (XEXP (rtl
, 0))
14118 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
14119 == (INTVAL (XEXP (rtl
, 0))
14120 & GET_MODE_MASK (op_mode
))))
14121 && ((last1
->dw_loc_opc
== DW_OP_deref_size
14122 && last1
->dw_loc_oprnd1
.v
.val_int
14123 <= GET_MODE_SIZE (op_mode
))
14124 || (CONST_INT_P (XEXP (rtl
, 1))
14125 && (unsigned HOST_WIDE_INT
)
14126 INTVAL (XEXP (rtl
, 1))
14127 == (INTVAL (XEXP (rtl
, 1))
14128 & GET_MODE_MASK (op_mode
)))))
14131 add_loc_descr (&op0
, int_loc_descriptor (shift
));
14132 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
14133 if (CONST_INT_P (XEXP (rtl
, 1)))
14134 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
14137 add_loc_descr (&op1
, int_loc_descriptor (shift
));
14138 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
14144 mem_loc_result
= op0
;
14145 add_loc_descr (&mem_loc_result
, op1
);
14146 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14147 if (STORE_FLAG_VALUE
!= 1)
14149 add_loc_descr (&mem_loc_result
,
14150 int_loc_descriptor (STORE_FLAG_VALUE
));
14151 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
14172 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) > DWARF2_ADDR_SIZE
14173 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 1))) > DWARF2_ADDR_SIZE
)
14177 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
14179 if (op_mode
== VOIDmode
)
14180 op_mode
= GET_MODE (XEXP (rtl
, 1));
14181 if (op_mode
!= VOIDmode
&& GET_MODE_CLASS (op_mode
) != MODE_INT
)
14184 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
14185 VAR_INIT_STATUS_INITIALIZED
);
14186 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
14187 VAR_INIT_STATUS_INITIALIZED
);
14189 if (op0
== 0 || op1
== 0)
14192 if (op_mode
!= VOIDmode
14193 && GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
14195 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
14196 dw_loc_descr_ref last0
, last1
;
14198 last0
->dw_loc_next
!= NULL
;
14199 last0
= last0
->dw_loc_next
)
14202 last1
->dw_loc_next
!= NULL
;
14203 last1
= last1
->dw_loc_next
)
14205 if (CONST_INT_P (XEXP (rtl
, 0)))
14206 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
14207 /* deref_size zero extends, so no need to mask it again. */
14208 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
14209 || last0
->dw_loc_oprnd1
.v
.val_int
14210 > GET_MODE_SIZE (op_mode
))
14212 add_loc_descr (&op0
, int_loc_descriptor (mask
));
14213 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14215 if (CONST_INT_P (XEXP (rtl
, 1)))
14216 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
14217 /* deref_size zero extends, so no need to mask it again. */
14218 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
14219 || last1
->dw_loc_oprnd1
.v
.val_int
14220 > GET_MODE_SIZE (op_mode
))
14222 add_loc_descr (&op1
, int_loc_descriptor (mask
));
14223 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
14228 HOST_WIDE_INT bias
= 1;
14229 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
14230 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14231 if (CONST_INT_P (XEXP (rtl
, 1)))
14232 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
14233 + INTVAL (XEXP (rtl
, 1)));
14235 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
14245 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) != MODE_INT
14246 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) > DWARF2_ADDR_SIZE
14247 || GET_MODE (XEXP (rtl
, 0)) != GET_MODE (XEXP (rtl
, 1)))
14250 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
14251 VAR_INIT_STATUS_INITIALIZED
);
14252 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
14253 VAR_INIT_STATUS_INITIALIZED
);
14255 if (op0
== 0 || op1
== 0)
14258 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
14259 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
14260 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
14261 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
14263 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) < DWARF2_ADDR_SIZE
)
14265 HOST_WIDE_INT mask
= GET_MODE_MASK (GET_MODE (XEXP (rtl
, 0)));
14266 add_loc_descr (&op0
, int_loc_descriptor (mask
));
14267 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14268 add_loc_descr (&op1
, int_loc_descriptor (mask
));
14269 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
14273 HOST_WIDE_INT bias
= 1;
14274 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
14275 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14276 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14279 else if (GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) < DWARF2_ADDR_SIZE
)
14281 int shift
= DWARF2_ADDR_SIZE
14282 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
14283 shift
*= BITS_PER_UNIT
;
14284 add_loc_descr (&op0
, int_loc_descriptor (shift
));
14285 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
14286 add_loc_descr (&op1
, int_loc_descriptor (shift
));
14287 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
14290 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
14294 mem_loc_result
= op0
;
14295 add_loc_descr (&mem_loc_result
, op1
);
14296 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14298 dw_loc_descr_ref bra_node
, drop_node
;
14300 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14301 add_loc_descr (&mem_loc_result
, bra_node
);
14302 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
14303 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
14304 add_loc_descr (&mem_loc_result
, drop_node
);
14305 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14306 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
14312 if (CONST_INT_P (XEXP (rtl
, 1))
14313 && CONST_INT_P (XEXP (rtl
, 2))
14314 && ((unsigned) INTVAL (XEXP (rtl
, 1))
14315 + (unsigned) INTVAL (XEXP (rtl
, 2))
14316 <= GET_MODE_BITSIZE (GET_MODE (rtl
)))
14317 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
14318 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
14321 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
14322 VAR_INIT_STATUS_INITIALIZED
);
14325 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
14329 mem_loc_result
= op0
;
14330 size
= INTVAL (XEXP (rtl
, 1));
14331 shift
= INTVAL (XEXP (rtl
, 2));
14332 if (BITS_BIG_ENDIAN
)
14333 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
14335 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
14337 add_loc_descr (&mem_loc_result
,
14338 int_loc_descriptor (DWARF2_ADDR_SIZE
14340 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
14342 if (size
!= (int) DWARF2_ADDR_SIZE
)
14344 add_loc_descr (&mem_loc_result
,
14345 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
14346 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14353 dw_loc_descr_ref op2
, bra_node
, drop_node
;
14354 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
14355 VAR_INIT_STATUS_INITIALIZED
);
14356 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
14357 VAR_INIT_STATUS_INITIALIZED
);
14358 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
,
14359 VAR_INIT_STATUS_INITIALIZED
);
14360 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
14363 mem_loc_result
= op1
;
14364 add_loc_descr (&mem_loc_result
, op2
);
14365 add_loc_descr (&mem_loc_result
, op0
);
14366 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14367 add_loc_descr (&mem_loc_result
, bra_node
);
14368 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
14369 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
14370 add_loc_descr (&mem_loc_result
, drop_node
);
14371 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14372 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
14380 /* In theory, we could implement the above. */
14381 /* DWARF cannot represent the unsigned compare operations
14408 case FLOAT_TRUNCATE
:
14410 case UNSIGNED_FLOAT
:
14413 case FRACT_CONVERT
:
14414 case UNSIGNED_FRACT_CONVERT
:
14416 case UNSIGNED_SAT_FRACT
:
14428 case VEC_DUPLICATE
:
14431 /* If delegitimize_address couldn't do anything with the UNSPEC, we
14432 can't express it in the debug info. This can happen e.g. with some
14437 resolve_one_addr (&rtl
, NULL
);
14441 #ifdef ENABLE_CHECKING
14442 print_rtl (stderr
, rtl
);
14443 gcc_unreachable ();
14449 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14450 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14452 return mem_loc_result
;
14455 /* Return a descriptor that describes the concatenation of two locations.
14456 This is typically a complex variable. */
14458 static dw_loc_descr_ref
14459 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
14461 dw_loc_descr_ref cc_loc_result
= NULL
;
14462 dw_loc_descr_ref x0_ref
14463 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14464 dw_loc_descr_ref x1_ref
14465 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14467 if (x0_ref
== 0 || x1_ref
== 0)
14470 cc_loc_result
= x0_ref
;
14471 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
14473 add_loc_descr (&cc_loc_result
, x1_ref
);
14474 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
14476 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14477 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14479 return cc_loc_result
;
14482 /* Return a descriptor that describes the concatenation of N
14485 static dw_loc_descr_ref
14486 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
14489 dw_loc_descr_ref cc_loc_result
= NULL
;
14490 unsigned int n
= XVECLEN (concatn
, 0);
14492 for (i
= 0; i
< n
; ++i
)
14494 dw_loc_descr_ref ref
;
14495 rtx x
= XVECEXP (concatn
, 0, i
);
14497 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14501 add_loc_descr (&cc_loc_result
, ref
);
14502 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
14505 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14506 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14508 return cc_loc_result
;
14511 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
14512 for DEBUG_IMPLICIT_PTR RTL. */
14514 static dw_loc_descr_ref
14515 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
14517 dw_loc_descr_ref ret
;
14522 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
14523 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
14524 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
14525 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
14526 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
14527 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
14530 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14531 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
14532 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14536 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
14537 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
14542 /* Output a proper Dwarf location descriptor for a variable or parameter
14543 which is either allocated in a register or in a memory location. For a
14544 register, we just generate an OP_REG and the register number. For a
14545 memory location we provide a Dwarf postfix expression describing how to
14546 generate the (dynamic) address of the object onto the address stack.
14548 MODE is mode of the decl if this loc_descriptor is going to be used in
14549 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
14550 allowed, VOIDmode otherwise.
14552 If we don't know how to describe it, return 0. */
14554 static dw_loc_descr_ref
14555 loc_descriptor (rtx rtl
, enum machine_mode mode
,
14556 enum var_init_status initialized
)
14558 dw_loc_descr_ref loc_result
= NULL
;
14560 switch (GET_CODE (rtl
))
14563 /* The case of a subreg may arise when we have a local (register)
14564 variable or a formal (register) parameter which doesn't quite fill
14565 up an entire register. For now, just assume that it is
14566 legitimate to make the Dwarf info refer to the whole register which
14567 contains the given subreg. */
14568 loc_result
= loc_descriptor (SUBREG_REG (rtl
), mode
, initialized
);
14572 loc_result
= reg_loc_descriptor (rtl
, initialized
);
14576 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
14578 if (loc_result
== NULL
)
14579 loc_result
= tls_mem_loc_descriptor (rtl
);
14580 if (loc_result
== NULL
)
14582 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
14583 if (new_rtl
!= rtl
)
14584 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
14589 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
14594 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
14599 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
14601 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
14602 if (GET_CODE (loc
) == EXPR_LIST
)
14603 loc
= XEXP (loc
, 0);
14604 loc_result
= loc_descriptor (loc
, mode
, initialized
);
14608 rtl
= XEXP (rtl
, 1);
14613 rtvec par_elems
= XVEC (rtl
, 0);
14614 int num_elem
= GET_NUM_ELEM (par_elems
);
14615 enum machine_mode mode
;
14618 /* Create the first one, so we have something to add to. */
14619 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
14620 VOIDmode
, initialized
);
14621 if (loc_result
== NULL
)
14623 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
14624 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
14625 for (i
= 1; i
< num_elem
; i
++)
14627 dw_loc_descr_ref temp
;
14629 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
14630 VOIDmode
, initialized
);
14633 add_loc_descr (&loc_result
, temp
);
14634 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
14635 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
14641 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
14642 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
14647 if (mode
== VOIDmode
)
14648 mode
= GET_MODE (rtl
);
14650 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
14652 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
14654 /* Note that a CONST_DOUBLE rtx could represent either an integer
14655 or a floating-point constant. A CONST_DOUBLE is used whenever
14656 the constant requires more than one word in order to be
14657 adequately represented. We output CONST_DOUBLEs as blocks. */
14658 loc_result
= new_loc_descr (DW_OP_implicit_value
,
14659 GET_MODE_SIZE (mode
), 0);
14660 if (SCALAR_FLOAT_MODE_P (mode
))
14662 unsigned int length
= GET_MODE_SIZE (mode
);
14663 unsigned char *array
14664 = (unsigned char*) ggc_alloc_atomic (length
);
14666 insert_float (rtl
, array
);
14667 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
14668 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
14669 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
14670 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
14674 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
14675 loc_result
->dw_loc_oprnd2
.v
.val_double
14676 = rtx_to_double_int (rtl
);
14682 if (mode
== VOIDmode
)
14683 mode
= GET_MODE (rtl
);
14685 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
14687 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
14688 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
14689 unsigned char *array
= (unsigned char *)
14690 ggc_alloc_atomic (length
* elt_size
);
14694 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
14695 switch (GET_MODE_CLASS (mode
))
14697 case MODE_VECTOR_INT
:
14698 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14700 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14701 double_int val
= rtx_to_double_int (elt
);
14703 if (elt_size
<= sizeof (HOST_WIDE_INT
))
14704 insert_int (double_int_to_shwi (val
), elt_size
, p
);
14707 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
14708 insert_double (val
, p
);
14713 case MODE_VECTOR_FLOAT
:
14714 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14716 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14717 insert_float (elt
, p
);
14722 gcc_unreachable ();
14725 loc_result
= new_loc_descr (DW_OP_implicit_value
,
14726 length
* elt_size
, 0);
14727 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
14728 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
14729 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
14730 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
14735 if (mode
== VOIDmode
14736 || GET_CODE (XEXP (rtl
, 0)) == CONST_INT
14737 || GET_CODE (XEXP (rtl
, 0)) == CONST_DOUBLE
14738 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
14740 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
14745 if (!const_ok_for_output (rtl
))
14748 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
14749 && (dwarf_version
>= 4 || !dwarf_strict
))
14751 loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
14752 loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
14753 loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
14754 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14755 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
14759 case DEBUG_IMPLICIT_PTR
:
14760 loc_result
= implicit_ptr_descriptor (rtl
, 0);
14764 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
14765 && CONST_INT_P (XEXP (rtl
, 1)))
14768 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
14773 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
14774 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
14775 && (dwarf_version
>= 4 || !dwarf_strict
))
14777 /* Value expression. */
14778 loc_result
= mem_loc_descriptor (rtl
, VOIDmode
, initialized
);
14780 add_loc_descr (&loc_result
,
14781 new_loc_descr (DW_OP_stack_value
, 0, 0));
14789 /* We need to figure out what section we should use as the base for the
14790 address ranges where a given location is valid.
14791 1. If this particular DECL has a section associated with it, use that.
14792 2. If this function has a section associated with it, use that.
14793 3. Otherwise, use the text section.
14794 XXX: If you split a variable across multiple sections, we won't notice. */
14796 static const char *
14797 secname_for_decl (const_tree decl
)
14799 const char *secname
;
14801 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
14803 tree sectree
= DECL_SECTION_NAME (decl
);
14804 secname
= TREE_STRING_POINTER (sectree
);
14806 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
14808 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
14809 secname
= TREE_STRING_POINTER (sectree
);
14811 else if (cfun
&& in_cold_section_p
)
14812 secname
= crtl
->subsections
.cold_section_label
;
14814 secname
= text_section_label
;
14819 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
14822 decl_by_reference_p (tree decl
)
14824 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
14825 || TREE_CODE (decl
) == VAR_DECL
)
14826 && DECL_BY_REFERENCE (decl
));
14829 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14832 static dw_loc_descr_ref
14833 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
14834 enum var_init_status initialized
)
14836 int have_address
= 0;
14837 dw_loc_descr_ref descr
;
14838 enum machine_mode mode
;
14840 if (want_address
!= 2)
14842 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
14844 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
14846 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
14847 if (GET_CODE (varloc
) == EXPR_LIST
)
14848 varloc
= XEXP (varloc
, 0);
14849 mode
= GET_MODE (varloc
);
14850 if (MEM_P (varloc
))
14852 rtx addr
= XEXP (varloc
, 0);
14853 descr
= mem_loc_descriptor (addr
, mode
, initialized
);
14858 rtx x
= avoid_constant_pool_reference (varloc
);
14860 descr
= mem_loc_descriptor (x
, mode
, initialized
);
14864 descr
= mem_loc_descriptor (varloc
, mode
, initialized
);
14871 if (GET_CODE (varloc
) == VAR_LOCATION
)
14872 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
14874 mode
= DECL_MODE (loc
);
14875 descr
= loc_descriptor (varloc
, mode
, initialized
);
14882 if (want_address
== 2 && !have_address
14883 && (dwarf_version
>= 4 || !dwarf_strict
))
14885 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14887 expansion_failed (loc
, NULL_RTX
,
14888 "DWARF address size mismatch");
14891 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14894 /* Show if we can't fill the request for an address. */
14895 if (want_address
&& !have_address
)
14897 expansion_failed (loc
, NULL_RTX
,
14898 "Want address and only have value");
14902 /* If we've got an address and don't want one, dereference. */
14903 if (!want_address
&& have_address
)
14905 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14906 enum dwarf_location_atom op
;
14908 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14910 expansion_failed (loc
, NULL_RTX
,
14911 "DWARF address size mismatch");
14914 else if (size
== DWARF2_ADDR_SIZE
)
14917 op
= DW_OP_deref_size
;
14919 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
14925 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14926 if it is not possible. */
14928 static dw_loc_descr_ref
14929 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
14931 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
14932 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
14933 else if (dwarf_version
>= 3 || !dwarf_strict
)
14934 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
14939 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14940 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14942 static dw_loc_descr_ref
14943 dw_sra_loc_expr (tree decl
, rtx loc
)
14946 unsigned int padsize
= 0;
14947 dw_loc_descr_ref descr
, *descr_tail
;
14948 unsigned HOST_WIDE_INT decl_size
;
14950 enum var_init_status initialized
;
14952 if (DECL_SIZE (decl
) == NULL
14953 || !host_integerp (DECL_SIZE (decl
), 1))
14956 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
14958 descr_tail
= &descr
;
14960 for (p
= loc
; p
; p
= XEXP (p
, 1))
14962 unsigned int bitsize
= decl_piece_bitsize (p
);
14963 rtx loc_note
= *decl_piece_varloc_ptr (p
);
14964 dw_loc_descr_ref cur_descr
;
14965 dw_loc_descr_ref
*tail
, last
= NULL
;
14966 unsigned int opsize
= 0;
14968 if (loc_note
== NULL_RTX
14969 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
14971 padsize
+= bitsize
;
14974 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
14975 varloc
= NOTE_VAR_LOCATION (loc_note
);
14976 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
14977 if (cur_descr
== NULL
)
14979 padsize
+= bitsize
;
14983 /* Check that cur_descr either doesn't use
14984 DW_OP_*piece operations, or their sum is equal
14985 to bitsize. Otherwise we can't embed it. */
14986 for (tail
= &cur_descr
; *tail
!= NULL
;
14987 tail
= &(*tail
)->dw_loc_next
)
14988 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
14990 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
14994 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
14996 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
15000 if (last
!= NULL
&& opsize
!= bitsize
)
15002 padsize
+= bitsize
;
15006 /* If there is a hole, add DW_OP_*piece after empty DWARF
15007 expression, which means that those bits are optimized out. */
15010 if (padsize
> decl_size
)
15012 decl_size
-= padsize
;
15013 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
15014 if (*descr_tail
== NULL
)
15016 descr_tail
= &(*descr_tail
)->dw_loc_next
;
15019 *descr_tail
= cur_descr
;
15021 if (bitsize
> decl_size
)
15023 decl_size
-= bitsize
;
15026 HOST_WIDE_INT offset
= 0;
15027 if (GET_CODE (varloc
) == VAR_LOCATION
15028 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
15030 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
15031 if (GET_CODE (varloc
) == EXPR_LIST
)
15032 varloc
= XEXP (varloc
, 0);
15036 if (GET_CODE (varloc
) == CONST
15037 || GET_CODE (varloc
) == SIGN_EXTEND
15038 || GET_CODE (varloc
) == ZERO_EXTEND
)
15039 varloc
= XEXP (varloc
, 0);
15040 else if (GET_CODE (varloc
) == SUBREG
)
15041 varloc
= SUBREG_REG (varloc
);
15046 /* DW_OP_bit_size offset should be zero for register
15047 or implicit location descriptions and empty location
15048 descriptions, but for memory addresses needs big endian
15050 if (MEM_P (varloc
))
15052 unsigned HOST_WIDE_INT memsize
15053 = INTVAL (MEM_SIZE (varloc
)) * BITS_PER_UNIT
;
15054 if (memsize
!= bitsize
)
15056 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
15057 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
15059 if (memsize
< bitsize
)
15061 if (BITS_BIG_ENDIAN
)
15062 offset
= memsize
- bitsize
;
15066 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
15067 if (*descr_tail
== NULL
)
15069 descr_tail
= &(*descr_tail
)->dw_loc_next
;
15073 /* If there were any non-empty expressions, add padding till the end of
15075 if (descr
!= NULL
&& decl_size
!= 0)
15077 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
15078 if (*descr_tail
== NULL
)
15084 /* Return the dwarf representation of the location list LOC_LIST of
15085 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
15088 static dw_loc_list_ref
15089 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
15091 const char *endname
, *secname
;
15093 enum var_init_status initialized
;
15094 struct var_loc_node
*node
;
15095 dw_loc_descr_ref descr
;
15096 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
15097 dw_loc_list_ref list
= NULL
;
15098 dw_loc_list_ref
*listp
= &list
;
15100 /* Now that we know what section we are using for a base,
15101 actually construct the list of locations.
15102 The first location information is what is passed to the
15103 function that creates the location list, and the remaining
15104 locations just get added on to that list.
15105 Note that we only know the start address for a location
15106 (IE location changes), so to build the range, we use
15107 the range [current location start, next location start].
15108 This means we have to special case the last node, and generate
15109 a range of [last location start, end of function label]. */
15111 secname
= secname_for_decl (decl
);
15113 for (node
= loc_list
->first
; node
; node
= node
->next
)
15114 if (GET_CODE (node
->loc
) == EXPR_LIST
15115 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
15117 if (GET_CODE (node
->loc
) == EXPR_LIST
)
15119 /* This requires DW_OP_{,bit_}piece, which is not usable
15120 inside DWARF expressions. */
15121 if (want_address
!= 2)
15123 descr
= dw_sra_loc_expr (decl
, node
->loc
);
15129 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
15130 varloc
= NOTE_VAR_LOCATION (node
->loc
);
15131 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
15135 /* The variable has a location between NODE->LABEL and
15136 NODE->NEXT->LABEL. */
15138 endname
= node
->next
->label
;
15139 /* If the variable has a location at the last label
15140 it keeps its location until the end of function. */
15141 else if (!current_function_decl
)
15142 endname
= text_end_label
;
15145 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
15146 current_function_funcdef_no
);
15147 endname
= ggc_strdup (label_id
);
15150 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
15151 listp
= &(*listp
)->dw_loc_next
;
15155 /* Try to avoid the overhead of a location list emitting a location
15156 expression instead, but only if we didn't have more than one
15157 location entry in the first place. If some entries were not
15158 representable, we don't want to pretend a single entry that was
15159 applies to the entire scope in which the variable is
15161 if (list
&& loc_list
->first
->next
)
15167 /* Return if the loc_list has only single element and thus can be represented
15168 as location description. */
15171 single_element_loc_list_p (dw_loc_list_ref list
)
15173 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
15174 return !list
->ll_symbol
;
15177 /* To each location in list LIST add loc descr REF. */
15180 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
15182 dw_loc_descr_ref copy
;
15183 add_loc_descr (&list
->expr
, ref
);
15184 list
= list
->dw_loc_next
;
15187 copy
= ggc_alloc_dw_loc_descr_node ();
15188 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
15189 add_loc_descr (&list
->expr
, copy
);
15190 while (copy
->dw_loc_next
)
15192 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
15193 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
15194 copy
->dw_loc_next
= new_copy
;
15197 list
= list
->dw_loc_next
;
15201 /* Given two lists RET and LIST
15202 produce location list that is result of adding expression in LIST
15203 to expression in RET on each possition in program.
15204 Might be destructive on both RET and LIST.
15206 TODO: We handle only simple cases of RET or LIST having at most one
15207 element. General case would inolve sorting the lists in program order
15208 and merging them that will need some additional work.
15209 Adding that will improve quality of debug info especially for SRA-ed
15213 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
15222 if (!list
->dw_loc_next
)
15224 add_loc_descr_to_each (*ret
, list
->expr
);
15227 if (!(*ret
)->dw_loc_next
)
15229 add_loc_descr_to_each (list
, (*ret
)->expr
);
15233 expansion_failed (NULL_TREE
, NULL_RTX
,
15234 "Don't know how to merge two non-trivial"
15235 " location lists.\n");
15240 /* LOC is constant expression. Try a luck, look it up in constant
15241 pool and return its loc_descr of its address. */
15243 static dw_loc_descr_ref
15244 cst_pool_loc_descr (tree loc
)
15246 /* Get an RTL for this, if something has been emitted. */
15247 rtx rtl
= lookup_constant_def (loc
);
15248 enum machine_mode mode
;
15250 if (!rtl
|| !MEM_P (rtl
))
15255 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
15257 /* TODO: We might get more coverage if we was actually delaying expansion
15258 of all expressions till end of compilation when constant pools are fully
15260 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
15262 expansion_failed (loc
, NULL_RTX
,
15263 "CST value in contant pool but not marked.");
15266 mode
= GET_MODE (rtl
);
15267 rtl
= XEXP (rtl
, 0);
15268 return mem_loc_descriptor (rtl
, mode
, VAR_INIT_STATUS_INITIALIZED
);
15271 /* Return dw_loc_list representing address of addr_expr LOC
15272 by looking for innder INDIRECT_REF expression and turing it
15273 into simple arithmetics. */
15275 static dw_loc_list_ref
15276 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
15279 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
15280 enum machine_mode mode
;
15282 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (loc
));
15283 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
15285 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
15286 &bitsize
, &bitpos
, &offset
, &mode
,
15287 &unsignedp
, &volatilep
, false);
15289 if (bitpos
% BITS_PER_UNIT
)
15291 expansion_failed (loc
, NULL_RTX
, "bitfield access");
15294 if (!INDIRECT_REF_P (obj
))
15296 expansion_failed (obj
,
15297 NULL_RTX
, "no indirect ref in inner refrence");
15300 if (!offset
&& !bitpos
)
15301 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
15303 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
15304 && (dwarf_version
>= 4 || !dwarf_strict
))
15306 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
15311 /* Variable offset. */
15312 list_ret1
= loc_list_from_tree (offset
, 0);
15313 if (list_ret1
== 0)
15315 add_loc_list (&list_ret
, list_ret1
);
15318 add_loc_descr_to_each (list_ret
,
15319 new_loc_descr (DW_OP_plus
, 0, 0));
15321 bytepos
= bitpos
/ BITS_PER_UNIT
;
15323 add_loc_descr_to_each (list_ret
,
15324 new_loc_descr (DW_OP_plus_uconst
,
15326 else if (bytepos
< 0)
15327 loc_list_plus_const (list_ret
, bytepos
);
15328 add_loc_descr_to_each (list_ret
,
15329 new_loc_descr (DW_OP_stack_value
, 0, 0));
15335 /* Generate Dwarf location list representing LOC.
15336 If WANT_ADDRESS is false, expression computing LOC will be computed
15337 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
15338 if WANT_ADDRESS is 2, expression computing address useable in location
15339 will be returned (i.e. DW_OP_reg can be used
15340 to refer to register values). */
15342 static dw_loc_list_ref
15343 loc_list_from_tree (tree loc
, int want_address
)
15345 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
15346 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
15347 int have_address
= 0;
15348 enum dwarf_location_atom op
;
15350 /* ??? Most of the time we do not take proper care for sign/zero
15351 extending the values properly. Hopefully this won't be a real
15354 switch (TREE_CODE (loc
))
15357 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
15360 case PLACEHOLDER_EXPR
:
15361 /* This case involves extracting fields from an object to determine the
15362 position of other fields. We don't try to encode this here. The
15363 only user of this is Ada, which encodes the needed information using
15364 the names of types. */
15365 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
15369 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
15370 /* There are no opcodes for these operations. */
15373 case PREINCREMENT_EXPR
:
15374 case PREDECREMENT_EXPR
:
15375 case POSTINCREMENT_EXPR
:
15376 case POSTDECREMENT_EXPR
:
15377 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
15378 /* There are no opcodes for these operations. */
15382 /* If we already want an address, see if there is INDIRECT_REF inside
15383 e.g. for &this->field. */
15386 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
15387 (loc
, want_address
== 2);
15390 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
15391 && (ret
= cst_pool_loc_descr (loc
)))
15394 /* Otherwise, process the argument and look for the address. */
15395 if (!list_ret
&& !ret
)
15396 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
15400 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
15406 if (DECL_THREAD_LOCAL_P (loc
))
15409 enum dwarf_location_atom first_op
;
15410 enum dwarf_location_atom second_op
;
15411 bool dtprel
= false;
15413 if (targetm
.have_tls
)
15415 /* If this is not defined, we have no way to emit the
15417 if (!targetm
.asm_out
.output_dwarf_dtprel
)
15420 /* The way DW_OP_GNU_push_tls_address is specified, we
15421 can only look up addresses of objects in the current
15422 module. We used DW_OP_addr as first op, but that's
15423 wrong, because DW_OP_addr is relocated by the debug
15424 info consumer, while DW_OP_GNU_push_tls_address
15425 operand shouldn't be. */
15426 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
15428 first_op
= DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
;
15430 second_op
= DW_OP_GNU_push_tls_address
;
15434 if (!targetm
.emutls
.debug_form_tls_address
15435 || !(dwarf_version
>= 3 || !dwarf_strict
))
15437 /* We stuffed the control variable into the DECL_VALUE_EXPR
15438 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
15439 no longer appear in gimple code. We used the control
15440 variable in specific so that we could pick it up here. */
15441 loc
= DECL_VALUE_EXPR (loc
);
15442 first_op
= DW_OP_addr
;
15443 second_op
= DW_OP_form_tls_address
;
15446 rtl
= rtl_for_decl_location (loc
);
15447 if (rtl
== NULL_RTX
)
15452 rtl
= XEXP (rtl
, 0);
15453 if (! CONSTANT_P (rtl
))
15456 ret
= new_loc_descr (first_op
, 0, 0);
15457 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
15458 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
15459 ret
->dtprel
= dtprel
;
15461 ret1
= new_loc_descr (second_op
, 0, 0);
15462 add_loc_descr (&ret
, ret1
);
15471 if (DECL_HAS_VALUE_EXPR_P (loc
))
15472 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
15476 case FUNCTION_DECL
:
15479 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
15481 if (loc_list
&& loc_list
->first
)
15483 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
15484 have_address
= want_address
!= 0;
15487 rtl
= rtl_for_decl_location (loc
);
15488 if (rtl
== NULL_RTX
)
15490 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
15493 else if (CONST_INT_P (rtl
))
15495 HOST_WIDE_INT val
= INTVAL (rtl
);
15496 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
15497 val
&= GET_MODE_MASK (DECL_MODE (loc
));
15498 ret
= int_loc_descriptor (val
);
15500 else if (GET_CODE (rtl
) == CONST_STRING
)
15502 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
15505 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
15507 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
15508 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
15509 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
15513 enum machine_mode mode
;
15515 /* Certain constructs can only be represented at top-level. */
15516 if (want_address
== 2)
15518 ret
= loc_descriptor (rtl
, VOIDmode
,
15519 VAR_INIT_STATUS_INITIALIZED
);
15524 mode
= GET_MODE (rtl
);
15527 rtl
= XEXP (rtl
, 0);
15530 ret
= mem_loc_descriptor (rtl
, mode
, VAR_INIT_STATUS_INITIALIZED
);
15533 expansion_failed (loc
, rtl
,
15534 "failed to produce loc descriptor for rtl");
15541 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
15545 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15549 case COMPOUND_EXPR
:
15550 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
15553 case VIEW_CONVERT_EXPR
:
15556 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
15558 case COMPONENT_REF
:
15559 case BIT_FIELD_REF
:
15561 case ARRAY_RANGE_REF
:
15562 case REALPART_EXPR
:
15563 case IMAGPART_EXPR
:
15566 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
15567 enum machine_mode mode
;
15569 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (loc
));
15571 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
15572 &unsignedp
, &volatilep
, false);
15574 gcc_assert (obj
!= loc
);
15576 list_ret
= loc_list_from_tree (obj
,
15578 && !bitpos
&& !offset
? 2 : 1);
15579 /* TODO: We can extract value of the small expression via shifting even
15580 for nonzero bitpos. */
15583 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
15585 expansion_failed (loc
, NULL_RTX
,
15586 "bitfield access");
15590 if (offset
!= NULL_TREE
)
15592 /* Variable offset. */
15593 list_ret1
= loc_list_from_tree (offset
, 0);
15594 if (list_ret1
== 0)
15596 add_loc_list (&list_ret
, list_ret1
);
15599 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
15602 bytepos
= bitpos
/ BITS_PER_UNIT
;
15604 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
15605 else if (bytepos
< 0)
15606 loc_list_plus_const (list_ret
, bytepos
);
15613 if ((want_address
|| !host_integerp (loc
, 0))
15614 && (ret
= cst_pool_loc_descr (loc
)))
15616 else if (want_address
== 2
15617 && host_integerp (loc
, 0)
15618 && (ret
= address_of_int_loc_descriptor
15619 (int_size_in_bytes (TREE_TYPE (loc
)),
15620 tree_low_cst (loc
, 0))))
15622 else if (host_integerp (loc
, 0))
15623 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
15626 expansion_failed (loc
, NULL_RTX
,
15627 "Integer operand is not host integer");
15636 if ((ret
= cst_pool_loc_descr (loc
)))
15639 /* We can construct small constants here using int_loc_descriptor. */
15640 expansion_failed (loc
, NULL_RTX
,
15641 "constructor or constant not in constant pool");
15644 case TRUTH_AND_EXPR
:
15645 case TRUTH_ANDIF_EXPR
:
15650 case TRUTH_XOR_EXPR
:
15655 case TRUTH_OR_EXPR
:
15656 case TRUTH_ORIF_EXPR
:
15661 case FLOOR_DIV_EXPR
:
15662 case CEIL_DIV_EXPR
:
15663 case ROUND_DIV_EXPR
:
15664 case TRUNC_DIV_EXPR
:
15665 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
15674 case FLOOR_MOD_EXPR
:
15675 case CEIL_MOD_EXPR
:
15676 case ROUND_MOD_EXPR
:
15677 case TRUNC_MOD_EXPR
:
15678 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
15683 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15684 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
15685 if (list_ret
== 0 || list_ret1
== 0)
15688 add_loc_list (&list_ret
, list_ret1
);
15691 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
15692 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
15693 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
15694 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
15695 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
15707 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
15710 case POINTER_PLUS_EXPR
:
15712 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
15714 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15718 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
15726 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
15733 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
15740 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
15747 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
15762 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15763 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
15764 if (list_ret
== 0 || list_ret1
== 0)
15767 add_loc_list (&list_ret
, list_ret1
);
15770 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
15773 case TRUTH_NOT_EXPR
:
15787 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15791 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
15797 const enum tree_code code
=
15798 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
15800 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
15801 build2 (code
, integer_type_node
,
15802 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
15803 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
15806 /* ... fall through ... */
15810 dw_loc_descr_ref lhs
15811 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
15812 dw_loc_list_ref rhs
15813 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
15814 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
15816 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15817 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
15820 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
15821 add_loc_descr_to_each (list_ret
, bra_node
);
15823 add_loc_list (&list_ret
, rhs
);
15824 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
15825 add_loc_descr_to_each (list_ret
, jump_node
);
15827 add_loc_descr_to_each (list_ret
, lhs
);
15828 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15829 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
15831 /* ??? Need a node to point the skip at. Use a nop. */
15832 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
15833 add_loc_descr_to_each (list_ret
, tmp
);
15834 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15835 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
15839 case FIX_TRUNC_EXPR
:
15843 /* Leave front-end specific codes as simply unknown. This comes
15844 up, for instance, with the C STMT_EXPR. */
15845 if ((unsigned int) TREE_CODE (loc
)
15846 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
15848 expansion_failed (loc
, NULL_RTX
,
15849 "language specific tree node");
15853 #ifdef ENABLE_CHECKING
15854 /* Otherwise this is a generic code; we should just lists all of
15855 these explicitly. We forgot one. */
15856 gcc_unreachable ();
15858 /* In a release build, we want to degrade gracefully: better to
15859 generate incomplete debugging information than to crash. */
15864 if (!ret
&& !list_ret
)
15867 if (want_address
== 2 && !have_address
15868 && (dwarf_version
>= 4 || !dwarf_strict
))
15870 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
15872 expansion_failed (loc
, NULL_RTX
,
15873 "DWARF address size mismatch");
15877 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15879 add_loc_descr_to_each (list_ret
,
15880 new_loc_descr (DW_OP_stack_value
, 0, 0));
15883 /* Show if we can't fill the request for an address. */
15884 if (want_address
&& !have_address
)
15886 expansion_failed (loc
, NULL_RTX
,
15887 "Want address and only have value");
15891 gcc_assert (!ret
|| !list_ret
);
15893 /* If we've got an address and don't want one, dereference. */
15894 if (!want_address
&& have_address
)
15896 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
15898 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
15900 expansion_failed (loc
, NULL_RTX
,
15901 "DWARF address size mismatch");
15904 else if (size
== DWARF2_ADDR_SIZE
)
15907 op
= DW_OP_deref_size
;
15910 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
15912 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
15915 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
15920 /* Same as above but return only single location expression. */
15921 static dw_loc_descr_ref
15922 loc_descriptor_from_tree (tree loc
, int want_address
)
15924 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
15927 if (ret
->dw_loc_next
)
15929 expansion_failed (loc
, NULL_RTX
,
15930 "Location list where only loc descriptor needed");
15936 /* Given a value, round it up to the lowest multiple of `boundary'
15937 which is not less than the value itself. */
15939 static inline HOST_WIDE_INT
15940 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
15942 return (((value
+ boundary
- 1) / boundary
) * boundary
);
15945 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
15946 pointer to the declared type for the relevant field variable, or return
15947 `integer_type_node' if the given node turns out to be an
15948 ERROR_MARK node. */
15951 field_type (const_tree decl
)
15955 if (TREE_CODE (decl
) == ERROR_MARK
)
15956 return integer_type_node
;
15958 type
= DECL_BIT_FIELD_TYPE (decl
);
15959 if (type
== NULL_TREE
)
15960 type
= TREE_TYPE (decl
);
15965 /* Given a pointer to a tree node, return the alignment in bits for
15966 it, or else return BITS_PER_WORD if the node actually turns out to
15967 be an ERROR_MARK node. */
15969 static inline unsigned
15970 simple_type_align_in_bits (const_tree type
)
15972 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
15975 static inline unsigned
15976 simple_decl_align_in_bits (const_tree decl
)
15978 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
15981 /* Return the result of rounding T up to ALIGN. */
15983 static inline double_int
15984 round_up_to_align (double_int t
, unsigned int align
)
15986 double_int alignd
= uhwi_to_double_int (align
);
15987 t
= double_int_add (t
, alignd
);
15988 t
= double_int_add (t
, double_int_minus_one
);
15989 t
= double_int_div (t
, alignd
, true, TRUNC_DIV_EXPR
);
15990 t
= double_int_mul (t
, alignd
);
15994 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
15995 lowest addressed byte of the "containing object" for the given FIELD_DECL,
15996 or return 0 if we are unable to determine what that offset is, either
15997 because the argument turns out to be a pointer to an ERROR_MARK node, or
15998 because the offset is actually variable. (We can't handle the latter case
16001 static HOST_WIDE_INT
16002 field_byte_offset (const_tree decl
)
16004 double_int object_offset_in_bits
;
16005 double_int object_offset_in_bytes
;
16006 double_int bitpos_int
;
16008 if (TREE_CODE (decl
) == ERROR_MARK
)
16011 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
16013 /* We cannot yet cope with fields whose positions are variable, so
16014 for now, when we see such things, we simply return 0. Someday, we may
16015 be able to handle such cases, but it will be damn difficult. */
16016 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
16019 bitpos_int
= tree_to_double_int (bit_position (decl
));
16021 #ifdef PCC_BITFIELD_TYPE_MATTERS
16022 if (PCC_BITFIELD_TYPE_MATTERS
)
16025 tree field_size_tree
;
16026 double_int deepest_bitpos
;
16027 double_int field_size_in_bits
;
16028 unsigned int type_align_in_bits
;
16029 unsigned int decl_align_in_bits
;
16030 double_int type_size_in_bits
;
16032 type
= field_type (decl
);
16033 type_size_in_bits
= double_int_type_size_in_bits (type
);
16034 type_align_in_bits
= simple_type_align_in_bits (type
);
16036 field_size_tree
= DECL_SIZE (decl
);
16038 /* The size could be unspecified if there was an error, or for
16039 a flexible array member. */
16040 if (!field_size_tree
)
16041 field_size_tree
= bitsize_zero_node
;
16043 /* If the size of the field is not constant, use the type size. */
16044 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
16045 field_size_in_bits
= tree_to_double_int (field_size_tree
);
16047 field_size_in_bits
= type_size_in_bits
;
16049 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
16051 /* The GCC front-end doesn't make any attempt to keep track of the
16052 starting bit offset (relative to the start of the containing
16053 structure type) of the hypothetical "containing object" for a
16054 bit-field. Thus, when computing the byte offset value for the
16055 start of the "containing object" of a bit-field, we must deduce
16056 this information on our own. This can be rather tricky to do in
16057 some cases. For example, handling the following structure type
16058 definition when compiling for an i386/i486 target (which only
16059 aligns long long's to 32-bit boundaries) can be very tricky:
16061 struct S { int field1; long long field2:31; };
16063 Fortunately, there is a simple rule-of-thumb which can be used
16064 in such cases. When compiling for an i386/i486, GCC will
16065 allocate 8 bytes for the structure shown above. It decides to
16066 do this based upon one simple rule for bit-field allocation.
16067 GCC allocates each "containing object" for each bit-field at
16068 the first (i.e. lowest addressed) legitimate alignment boundary
16069 (based upon the required minimum alignment for the declared
16070 type of the field) which it can possibly use, subject to the
16071 condition that there is still enough available space remaining
16072 in the containing object (when allocated at the selected point)
16073 to fully accommodate all of the bits of the bit-field itself.
16075 This simple rule makes it obvious why GCC allocates 8 bytes for
16076 each object of the structure type shown above. When looking
16077 for a place to allocate the "containing object" for `field2',
16078 the compiler simply tries to allocate a 64-bit "containing
16079 object" at each successive 32-bit boundary (starting at zero)
16080 until it finds a place to allocate that 64- bit field such that
16081 at least 31 contiguous (and previously unallocated) bits remain
16082 within that selected 64 bit field. (As it turns out, for the
16083 example above, the compiler finds it is OK to allocate the
16084 "containing object" 64-bit field at bit-offset zero within the
16087 Here we attempt to work backwards from the limited set of facts
16088 we're given, and we try to deduce from those facts, where GCC
16089 must have believed that the containing object started (within
16090 the structure type). The value we deduce is then used (by the
16091 callers of this routine) to generate DW_AT_location and
16092 DW_AT_bit_offset attributes for fields (both bit-fields and, in
16093 the case of DW_AT_location, regular fields as well). */
16095 /* Figure out the bit-distance from the start of the structure to
16096 the "deepest" bit of the bit-field. */
16097 deepest_bitpos
= double_int_add (bitpos_int
, field_size_in_bits
);
16099 /* This is the tricky part. Use some fancy footwork to deduce
16100 where the lowest addressed bit of the containing object must
16102 object_offset_in_bits
16103 = double_int_sub (deepest_bitpos
, type_size_in_bits
);
16105 /* Round up to type_align by default. This works best for
16107 object_offset_in_bits
16108 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
16110 if (double_int_ucmp (object_offset_in_bits
, bitpos_int
) > 0)
16112 object_offset_in_bits
16113 = double_int_sub (deepest_bitpos
, type_size_in_bits
);
16115 /* Round up to decl_align instead. */
16116 object_offset_in_bits
16117 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
16121 #endif /* PCC_BITFIELD_TYPE_MATTERS */
16122 object_offset_in_bits
= bitpos_int
;
16124 object_offset_in_bytes
16125 = double_int_div (object_offset_in_bits
,
16126 uhwi_to_double_int (BITS_PER_UNIT
), true,
16128 return double_int_to_shwi (object_offset_in_bytes
);
16131 /* The following routines define various Dwarf attributes and any data
16132 associated with them. */
16134 /* Add a location description attribute value to a DIE.
16136 This emits location attributes suitable for whole variables and
16137 whole parameters. Note that the location attributes for struct fields are
16138 generated by the routine `data_member_location_attribute' below. */
16141 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
16142 dw_loc_list_ref descr
)
16146 if (single_element_loc_list_p (descr
))
16147 add_AT_loc (die
, attr_kind
, descr
->expr
);
16149 add_AT_loc_list (die
, attr_kind
, descr
);
16152 /* Add DW_AT_accessibility attribute to DIE if needed. */
16155 add_accessibility_attribute (dw_die_ref die
, tree decl
)
16157 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
16158 children, otherwise the default is DW_ACCESS_public. In DWARF2
16159 the default has always been DW_ACCESS_public. */
16160 if (TREE_PROTECTED (decl
))
16161 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
16162 else if (TREE_PRIVATE (decl
))
16164 if (dwarf_version
== 2
16165 || die
->die_parent
== NULL
16166 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
16167 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
16169 else if (dwarf_version
> 2
16171 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
16172 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
16175 /* Attach the specialized form of location attribute used for data members of
16176 struct and union types. In the special case of a FIELD_DECL node which
16177 represents a bit-field, the "offset" part of this special location
16178 descriptor must indicate the distance in bytes from the lowest-addressed
16179 byte of the containing struct or union type to the lowest-addressed byte of
16180 the "containing object" for the bit-field. (See the `field_byte_offset'
16183 For any given bit-field, the "containing object" is a hypothetical object
16184 (of some integral or enum type) within which the given bit-field lives. The
16185 type of this hypothetical "containing object" is always the same as the
16186 declared type of the individual bit-field itself (for GCC anyway... the
16187 DWARF spec doesn't actually mandate this). Note that it is the size (in
16188 bytes) of the hypothetical "containing object" which will be given in the
16189 DW_AT_byte_size attribute for this bit-field. (See the
16190 `byte_size_attribute' function below.) It is also used when calculating the
16191 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
16192 function below.) */
16195 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
16197 HOST_WIDE_INT offset
;
16198 dw_loc_descr_ref loc_descr
= 0;
16200 if (TREE_CODE (decl
) == TREE_BINFO
)
16202 /* We're working on the TAG_inheritance for a base class. */
16203 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
16205 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
16206 aren't at a fixed offset from all (sub)objects of the same
16207 type. We need to extract the appropriate offset from our
16208 vtable. The following dwarf expression means
16210 BaseAddr = ObAddr + *((*ObAddr) - Offset)
16212 This is specific to the V3 ABI, of course. */
16214 dw_loc_descr_ref tmp
;
16216 /* Make a copy of the object address. */
16217 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
16218 add_loc_descr (&loc_descr
, tmp
);
16220 /* Extract the vtable address. */
16221 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
16222 add_loc_descr (&loc_descr
, tmp
);
16224 /* Calculate the address of the offset. */
16225 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
16226 gcc_assert (offset
< 0);
16228 tmp
= int_loc_descriptor (-offset
);
16229 add_loc_descr (&loc_descr
, tmp
);
16230 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
16231 add_loc_descr (&loc_descr
, tmp
);
16233 /* Extract the offset. */
16234 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
16235 add_loc_descr (&loc_descr
, tmp
);
16237 /* Add it to the object address. */
16238 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
16239 add_loc_descr (&loc_descr
, tmp
);
16242 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
16245 offset
= field_byte_offset (decl
);
16249 if (dwarf_version
> 2)
16251 /* Don't need to output a location expression, just the constant. */
16253 add_AT_int (die
, DW_AT_data_member_location
, offset
);
16255 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
16260 enum dwarf_location_atom op
;
16262 /* The DWARF2 standard says that we should assume that the structure
16263 address is already on the stack, so we can specify a structure
16264 field address by using DW_OP_plus_uconst. */
16266 #ifdef MIPS_DEBUGGING_INFO
16267 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
16268 operator correctly. It works only if we leave the offset on the
16272 op
= DW_OP_plus_uconst
;
16275 loc_descr
= new_loc_descr (op
, offset
, 0);
16279 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
16282 /* Writes integer values to dw_vec_const array. */
16285 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
16289 *dest
++ = val
& 0xff;
16295 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
16297 static HOST_WIDE_INT
16298 extract_int (const unsigned char *src
, unsigned int size
)
16300 HOST_WIDE_INT val
= 0;
16306 val
|= *--src
& 0xff;
16312 /* Writes double_int values to dw_vec_const array. */
16315 insert_double (double_int val
, unsigned char *dest
)
16317 unsigned char *p0
= dest
;
16318 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
16320 if (WORDS_BIG_ENDIAN
)
16326 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
16327 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
16330 /* Writes floating point values to dw_vec_const array. */
16333 insert_float (const_rtx rtl
, unsigned char *array
)
16335 REAL_VALUE_TYPE rv
;
16339 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
16340 real_to_target (val
, &rv
, GET_MODE (rtl
));
16342 /* real_to_target puts 32-bit pieces in each long. Pack them. */
16343 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
16345 insert_int (val
[i
], 4, array
);
16350 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
16351 does not have a "location" either in memory or in a register. These
16352 things can arise in GNU C when a constant is passed as an actual parameter
16353 to an inlined function. They can also arise in C++ where declared
16354 constants do not necessarily get memory "homes". */
16357 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
16359 switch (GET_CODE (rtl
))
16363 HOST_WIDE_INT val
= INTVAL (rtl
);
16366 add_AT_int (die
, DW_AT_const_value
, val
);
16368 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
16373 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
16374 floating-point constant. A CONST_DOUBLE is used whenever the
16375 constant requires more than one word in order to be adequately
16378 enum machine_mode mode
= GET_MODE (rtl
);
16380 if (SCALAR_FLOAT_MODE_P (mode
))
16382 unsigned int length
= GET_MODE_SIZE (mode
);
16383 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
16385 insert_float (rtl
, array
);
16386 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
16389 add_AT_double (die
, DW_AT_const_value
,
16390 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
16396 enum machine_mode mode
= GET_MODE (rtl
);
16397 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
16398 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
16399 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
16400 (length
* elt_size
);
16404 switch (GET_MODE_CLASS (mode
))
16406 case MODE_VECTOR_INT
:
16407 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
16409 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
16410 double_int val
= rtx_to_double_int (elt
);
16412 if (elt_size
<= sizeof (HOST_WIDE_INT
))
16413 insert_int (double_int_to_shwi (val
), elt_size
, p
);
16416 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
16417 insert_double (val
, p
);
16422 case MODE_VECTOR_FLOAT
:
16423 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
16425 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
16426 insert_float (elt
, p
);
16431 gcc_unreachable ();
16434 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
16439 if (dwarf_version
>= 4 || !dwarf_strict
)
16441 dw_loc_descr_ref loc_result
;
16442 resolve_one_addr (&rtl
, NULL
);
16444 loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
16445 loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
16446 loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
16447 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
16448 add_AT_loc (die
, DW_AT_location
, loc_result
);
16449 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
16455 if (CONSTANT_P (XEXP (rtl
, 0)))
16456 return add_const_value_attribute (die
, XEXP (rtl
, 0));
16459 if (!const_ok_for_output (rtl
))
16462 if (dwarf_version
>= 4 || !dwarf_strict
)
16467 /* In cases where an inlined instance of an inline function is passed
16468 the address of an `auto' variable (which is local to the caller) we
16469 can get a situation where the DECL_RTL of the artificial local
16470 variable (for the inlining) which acts as a stand-in for the
16471 corresponding formal parameter (of the inline function) will look
16472 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
16473 exactly a compile-time constant expression, but it isn't the address
16474 of the (artificial) local variable either. Rather, it represents the
16475 *value* which the artificial local variable always has during its
16476 lifetime. We currently have no way to represent such quasi-constant
16477 values in Dwarf, so for now we just punt and generate nothing. */
16485 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
16486 && MEM_READONLY_P (rtl
)
16487 && GET_MODE (rtl
) == BLKmode
)
16489 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
16495 /* No other kinds of rtx should be possible here. */
16496 gcc_unreachable ();
16501 /* Determine whether the evaluation of EXPR references any variables
16502 or functions which aren't otherwise used (and therefore may not be
16505 reference_to_unused (tree
* tp
, int * walk_subtrees
,
16506 void * data ATTRIBUTE_UNUSED
)
16508 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
16509 *walk_subtrees
= 0;
16511 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
16512 && ! TREE_ASM_WRITTEN (*tp
))
16514 /* ??? The C++ FE emits debug information for using decls, so
16515 putting gcc_unreachable here falls over. See PR31899. For now
16516 be conservative. */
16517 else if (!cgraph_global_info_ready
16518 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
16520 else if (TREE_CODE (*tp
) == VAR_DECL
)
16522 struct varpool_node
*node
= varpool_get_node (*tp
);
16523 if (!node
|| !node
->needed
)
16526 else if (TREE_CODE (*tp
) == FUNCTION_DECL
16527 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
16529 /* The call graph machinery must have finished analyzing,
16530 optimizing and gimplifying the CU by now.
16531 So if *TP has no call graph node associated
16532 to it, it means *TP will not be emitted. */
16533 if (!cgraph_get_node (*tp
))
16536 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
16542 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
16543 for use in a later add_const_value_attribute call. */
16546 rtl_for_decl_init (tree init
, tree type
)
16548 rtx rtl
= NULL_RTX
;
16552 /* If a variable is initialized with a string constant without embedded
16553 zeros, build CONST_STRING. */
16554 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
16556 tree enttype
= TREE_TYPE (type
);
16557 tree domain
= TYPE_DOMAIN (type
);
16558 enum machine_mode mode
= TYPE_MODE (enttype
);
16560 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
16562 && integer_zerop (TYPE_MIN_VALUE (domain
))
16563 && compare_tree_int (TYPE_MAX_VALUE (domain
),
16564 TREE_STRING_LENGTH (init
) - 1) == 0
16565 && ((size_t) TREE_STRING_LENGTH (init
)
16566 == strlen (TREE_STRING_POINTER (init
)) + 1))
16568 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
16569 ggc_strdup (TREE_STRING_POINTER (init
)));
16570 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
16571 MEM_READONLY_P (rtl
) = 1;
16574 /* Other aggregates, and complex values, could be represented using
16576 else if (AGGREGATE_TYPE_P (type
)
16577 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
16578 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
16579 || TREE_CODE (type
) == COMPLEX_TYPE
)
16581 /* Vectors only work if their mode is supported by the target.
16582 FIXME: generic vectors ought to work too. */
16583 else if (TREE_CODE (type
) == VECTOR_TYPE
16584 && !VECTOR_MODE_P (TYPE_MODE (type
)))
16586 /* If the initializer is something that we know will expand into an
16587 immediate RTL constant, expand it now. We must be careful not to
16588 reference variables which won't be output. */
16589 else if (initializer_constant_valid_p (init
, type
)
16590 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
16592 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
16594 if (TREE_CODE (type
) == VECTOR_TYPE
)
16595 switch (TREE_CODE (init
))
16600 if (TREE_CONSTANT (init
))
16602 VEC(constructor_elt
,gc
) *elts
= CONSTRUCTOR_ELTS (init
);
16603 bool constant_p
= true;
16605 unsigned HOST_WIDE_INT ix
;
16607 /* Even when ctor is constant, it might contain non-*_CST
16608 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
16609 belong into VECTOR_CST nodes. */
16610 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
16611 if (!CONSTANT_CLASS_P (value
))
16613 constant_p
= false;
16619 init
= build_vector_from_ctor (type
, elts
);
16629 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
16631 /* If expand_expr returns a MEM, it wasn't immediate. */
16632 gcc_assert (!rtl
|| !MEM_P (rtl
));
16638 /* Generate RTL for the variable DECL to represent its location. */
16641 rtl_for_decl_location (tree decl
)
16645 /* Here we have to decide where we are going to say the parameter "lives"
16646 (as far as the debugger is concerned). We only have a couple of
16647 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
16649 DECL_RTL normally indicates where the parameter lives during most of the
16650 activation of the function. If optimization is enabled however, this
16651 could be either NULL or else a pseudo-reg. Both of those cases indicate
16652 that the parameter doesn't really live anywhere (as far as the code
16653 generation parts of GCC are concerned) during most of the function's
16654 activation. That will happen (for example) if the parameter is never
16655 referenced within the function.
16657 We could just generate a location descriptor here for all non-NULL
16658 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
16659 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
16660 where DECL_RTL is NULL or is a pseudo-reg.
16662 Note however that we can only get away with using DECL_INCOMING_RTL as
16663 a backup substitute for DECL_RTL in certain limited cases. In cases
16664 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
16665 we can be sure that the parameter was passed using the same type as it is
16666 declared to have within the function, and that its DECL_INCOMING_RTL
16667 points us to a place where a value of that type is passed.
16669 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
16670 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
16671 because in these cases DECL_INCOMING_RTL points us to a value of some
16672 type which is *different* from the type of the parameter itself. Thus,
16673 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
16674 such cases, the debugger would end up (for example) trying to fetch a
16675 `float' from a place which actually contains the first part of a
16676 `double'. That would lead to really incorrect and confusing
16677 output at debug-time.
16679 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
16680 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
16681 are a couple of exceptions however. On little-endian machines we can
16682 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
16683 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
16684 an integral type that is smaller than TREE_TYPE (decl). These cases arise
16685 when (on a little-endian machine) a non-prototyped function has a
16686 parameter declared to be of type `short' or `char'. In such cases,
16687 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
16688 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
16689 passed `int' value. If the debugger then uses that address to fetch
16690 a `short' or a `char' (on a little-endian machine) the result will be
16691 the correct data, so we allow for such exceptional cases below.
16693 Note that our goal here is to describe the place where the given formal
16694 parameter lives during most of the function's activation (i.e. between the
16695 end of the prologue and the start of the epilogue). We'll do that as best
16696 as we can. Note however that if the given formal parameter is modified
16697 sometime during the execution of the function, then a stack backtrace (at
16698 debug-time) will show the function as having been called with the *new*
16699 value rather than the value which was originally passed in. This happens
16700 rarely enough that it is not a major problem, but it *is* a problem, and
16701 I'd like to fix it.
16703 A future version of dwarf2out.c may generate two additional attributes for
16704 any given DW_TAG_formal_parameter DIE which will describe the "passed
16705 type" and the "passed location" for the given formal parameter in addition
16706 to the attributes we now generate to indicate the "declared type" and the
16707 "active location" for each parameter. This additional set of attributes
16708 could be used by debuggers for stack backtraces. Separately, note that
16709 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
16710 This happens (for example) for inlined-instances of inline function formal
16711 parameters which are never referenced. This really shouldn't be
16712 happening. All PARM_DECL nodes should get valid non-NULL
16713 DECL_INCOMING_RTL values. FIXME. */
16715 /* Use DECL_RTL as the "location" unless we find something better. */
16716 rtl
= DECL_RTL_IF_SET (decl
);
16718 /* When generating abstract instances, ignore everything except
16719 constants, symbols living in memory, and symbols living in
16720 fixed registers. */
16721 if (! reload_completed
)
16724 && (CONSTANT_P (rtl
)
16726 && CONSTANT_P (XEXP (rtl
, 0)))
16728 && TREE_CODE (decl
) == VAR_DECL
16729 && TREE_STATIC (decl
))))
16731 rtl
= targetm
.delegitimize_address (rtl
);
16736 else if (TREE_CODE (decl
) == PARM_DECL
)
16738 if (rtl
== NULL_RTX
16739 || is_pseudo_reg (rtl
)
16741 && is_pseudo_reg (XEXP (rtl
, 0))
16742 && DECL_INCOMING_RTL (decl
)
16743 && MEM_P (DECL_INCOMING_RTL (decl
))
16744 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
16746 tree declared_type
= TREE_TYPE (decl
);
16747 tree passed_type
= DECL_ARG_TYPE (decl
);
16748 enum machine_mode dmode
= TYPE_MODE (declared_type
);
16749 enum machine_mode pmode
= TYPE_MODE (passed_type
);
16751 /* This decl represents a formal parameter which was optimized out.
16752 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
16753 all cases where (rtl == NULL_RTX) just below. */
16754 if (dmode
== pmode
)
16755 rtl
= DECL_INCOMING_RTL (decl
);
16756 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
16757 && SCALAR_INT_MODE_P (dmode
)
16758 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
16759 && DECL_INCOMING_RTL (decl
))
16761 rtx inc
= DECL_INCOMING_RTL (decl
);
16764 else if (MEM_P (inc
))
16766 if (BYTES_BIG_ENDIAN
)
16767 rtl
= adjust_address_nv (inc
, dmode
,
16768 GET_MODE_SIZE (pmode
)
16769 - GET_MODE_SIZE (dmode
));
16776 /* If the parm was passed in registers, but lives on the stack, then
16777 make a big endian correction if the mode of the type of the
16778 parameter is not the same as the mode of the rtl. */
16779 /* ??? This is the same series of checks that are made in dbxout.c before
16780 we reach the big endian correction code there. It isn't clear if all
16781 of these checks are necessary here, but keeping them all is the safe
16783 else if (MEM_P (rtl
)
16784 && XEXP (rtl
, 0) != const0_rtx
16785 && ! CONSTANT_P (XEXP (rtl
, 0))
16786 /* Not passed in memory. */
16787 && !MEM_P (DECL_INCOMING_RTL (decl
))
16788 /* Not passed by invisible reference. */
16789 && (!REG_P (XEXP (rtl
, 0))
16790 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
16791 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
16792 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
16793 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
16796 /* Big endian correction check. */
16797 && BYTES_BIG_ENDIAN
16798 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
16799 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
16802 int offset
= (UNITS_PER_WORD
16803 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
16805 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
16806 plus_constant (XEXP (rtl
, 0), offset
));
16809 else if (TREE_CODE (decl
) == VAR_DECL
16812 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
16813 && BYTES_BIG_ENDIAN
)
16815 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
16816 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
16818 /* If a variable is declared "register" yet is smaller than
16819 a register, then if we store the variable to memory, it
16820 looks like we're storing a register-sized value, when in
16821 fact we are not. We need to adjust the offset of the
16822 storage location to reflect the actual value's bytes,
16823 else gdb will not be able to display it. */
16825 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
16826 plus_constant (XEXP (rtl
, 0), rsize
-dsize
));
16829 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16830 and will have been substituted directly into all expressions that use it.
16831 C does not have such a concept, but C++ and other languages do. */
16832 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
16833 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
16836 rtl
= targetm
.delegitimize_address (rtl
);
16838 /* If we don't look past the constant pool, we risk emitting a
16839 reference to a constant pool entry that isn't referenced from
16840 code, and thus is not emitted. */
16842 rtl
= avoid_constant_pool_reference (rtl
);
16844 /* Try harder to get a rtl. If this symbol ends up not being emitted
16845 in the current CU, resolve_addr will remove the expression referencing
16847 if (rtl
== NULL_RTX
16848 && TREE_CODE (decl
) == VAR_DECL
16849 && !DECL_EXTERNAL (decl
)
16850 && TREE_STATIC (decl
)
16851 && DECL_NAME (decl
)
16852 && !DECL_HARD_REGISTER (decl
)
16853 && DECL_MODE (decl
) != VOIDmode
)
16855 rtl
= make_decl_rtl_for_debug (decl
);
16857 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
16858 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
16865 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
16866 returned. If so, the decl for the COMMON block is returned, and the
16867 value is the offset into the common block for the symbol. */
16870 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
16872 tree val_expr
, cvar
;
16873 enum machine_mode mode
;
16874 HOST_WIDE_INT bitsize
, bitpos
;
16876 int volatilep
= 0, unsignedp
= 0;
16878 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
16879 it does not have a value (the offset into the common area), or if it
16880 is thread local (as opposed to global) then it isn't common, and shouldn't
16881 be handled as such. */
16882 if (TREE_CODE (decl
) != VAR_DECL
16883 || !TREE_STATIC (decl
)
16884 || !DECL_HAS_VALUE_EXPR_P (decl
)
16888 val_expr
= DECL_VALUE_EXPR (decl
);
16889 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
16892 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
16893 &mode
, &unsignedp
, &volatilep
, true);
16895 if (cvar
== NULL_TREE
16896 || TREE_CODE (cvar
) != VAR_DECL
16897 || DECL_ARTIFICIAL (cvar
)
16898 || !TREE_PUBLIC (cvar
))
16902 if (offset
!= NULL
)
16904 if (!host_integerp (offset
, 0))
16906 *value
= tree_low_cst (offset
, 0);
16909 *value
+= bitpos
/ BITS_PER_UNIT
;
16914 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
16915 data attribute for a variable or a parameter. We generate the
16916 DW_AT_const_value attribute only in those cases where the given variable
16917 or parameter does not have a true "location" either in memory or in a
16918 register. This can happen (for example) when a constant is passed as an
16919 actual argument in a call to an inline function. (It's possible that
16920 these things can crop up in other ways also.) Note that one type of
16921 constant value which can be passed into an inlined function is a constant
16922 pointer. This can happen for example if an actual argument in an inlined
16923 function call evaluates to a compile-time constant address. */
16926 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
,
16927 enum dwarf_attribute attr
)
16930 dw_loc_list_ref list
;
16931 var_loc_list
*loc_list
;
16933 if (TREE_CODE (decl
) == ERROR_MARK
)
16936 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
16937 || TREE_CODE (decl
) == RESULT_DECL
);
16939 /* Try to get some constant RTL for this decl, and use that as the value of
16942 rtl
= rtl_for_decl_location (decl
);
16943 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
16944 && add_const_value_attribute (die
, rtl
))
16947 /* See if we have single element location list that is equivalent to
16948 a constant value. That way we are better to use add_const_value_attribute
16949 rather than expanding constant value equivalent. */
16950 loc_list
= lookup_decl_loc (decl
);
16953 && loc_list
->first
->next
== NULL
16954 && NOTE_P (loc_list
->first
->loc
)
16955 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
16956 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
16958 struct var_loc_node
*node
;
16960 node
= loc_list
->first
;
16961 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
16962 if (GET_CODE (rtl
) == EXPR_LIST
)
16963 rtl
= XEXP (rtl
, 0);
16964 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
16965 && add_const_value_attribute (die
, rtl
))
16968 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
16971 add_AT_location_description (die
, attr
, list
);
16974 /* None of that worked, so it must not really have a location;
16975 try adding a constant value attribute from the DECL_INITIAL. */
16976 return tree_add_const_value_attribute_for_decl (die
, decl
);
16979 /* Add VARIABLE and DIE into deferred locations list. */
16982 defer_location (tree variable
, dw_die_ref die
)
16984 deferred_locations entry
;
16985 entry
.variable
= variable
;
16987 VEC_safe_push (deferred_locations
, gc
, deferred_locations_list
, &entry
);
16990 /* Helper function for tree_add_const_value_attribute. Natively encode
16991 initializer INIT into an array. Return true if successful. */
16994 native_encode_initializer (tree init
, unsigned char *array
, int size
)
16998 if (init
== NULL_TREE
)
17002 switch (TREE_CODE (init
))
17005 type
= TREE_TYPE (init
);
17006 if (TREE_CODE (type
) == ARRAY_TYPE
)
17008 tree enttype
= TREE_TYPE (type
);
17009 enum machine_mode mode
= TYPE_MODE (enttype
);
17011 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
17013 if (int_size_in_bytes (type
) != size
)
17015 if (size
> TREE_STRING_LENGTH (init
))
17017 memcpy (array
, TREE_STRING_POINTER (init
),
17018 TREE_STRING_LENGTH (init
));
17019 memset (array
+ TREE_STRING_LENGTH (init
),
17020 '\0', size
- TREE_STRING_LENGTH (init
));
17023 memcpy (array
, TREE_STRING_POINTER (init
), size
);
17028 type
= TREE_TYPE (init
);
17029 if (int_size_in_bytes (type
) != size
)
17031 if (TREE_CODE (type
) == ARRAY_TYPE
)
17033 HOST_WIDE_INT min_index
;
17034 unsigned HOST_WIDE_INT cnt
;
17035 int curpos
= 0, fieldsize
;
17036 constructor_elt
*ce
;
17038 if (TYPE_DOMAIN (type
) == NULL_TREE
17039 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
17042 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
17043 if (fieldsize
<= 0)
17046 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
17047 memset (array
, '\0', size
);
17048 FOR_EACH_VEC_ELT (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
)
17050 tree val
= ce
->value
;
17051 tree index
= ce
->index
;
17053 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
17054 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
17057 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
17062 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
17065 curpos
= pos
+ fieldsize
;
17066 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
17068 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
17069 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
17073 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
17074 curpos
+= fieldsize
;
17077 gcc_assert (curpos
<= size
);
17081 else if (TREE_CODE (type
) == RECORD_TYPE
17082 || TREE_CODE (type
) == UNION_TYPE
)
17084 tree field
= NULL_TREE
;
17085 unsigned HOST_WIDE_INT cnt
;
17086 constructor_elt
*ce
;
17088 if (int_size_in_bytes (type
) != size
)
17091 if (TREE_CODE (type
) == RECORD_TYPE
)
17092 field
= TYPE_FIELDS (type
);
17094 FOR_EACH_VEC_ELT (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
)
17096 tree val
= ce
->value
;
17097 int pos
, fieldsize
;
17099 if (ce
->index
!= 0)
17105 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
17108 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
17109 && TYPE_DOMAIN (TREE_TYPE (field
))
17110 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
17112 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
17113 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
17115 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
17116 pos
= int_byte_position (field
);
17117 gcc_assert (pos
+ fieldsize
<= size
);
17119 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
17125 case VIEW_CONVERT_EXPR
:
17126 case NON_LVALUE_EXPR
:
17127 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
17129 return native_encode_expr (init
, array
, size
) == size
;
17133 /* Attach a DW_AT_const_value attribute to DIE. The value of the
17134 attribute is the const value T. */
17137 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
17140 tree type
= TREE_TYPE (t
);
17143 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
17147 gcc_assert (!DECL_P (init
));
17149 rtl
= rtl_for_decl_init (init
, type
);
17151 return add_const_value_attribute (die
, rtl
);
17152 /* If the host and target are sane, try harder. */
17153 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
17154 && initializer_constant_valid_p (init
, type
))
17156 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
17157 if (size
> 0 && (int) size
== size
)
17159 unsigned char *array
= (unsigned char *)
17160 ggc_alloc_cleared_atomic (size
);
17162 if (native_encode_initializer (init
, array
, size
))
17164 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
17172 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
17173 attribute is the const value of T, where T is an integral constant
17174 variable with static storage duration
17175 (so it can't be a PARM_DECL or a RESULT_DECL). */
17178 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
17182 || (TREE_CODE (decl
) != VAR_DECL
17183 && TREE_CODE (decl
) != CONST_DECL
))
17186 if (TREE_READONLY (decl
)
17187 && ! TREE_THIS_VOLATILE (decl
)
17188 && DECL_INITIAL (decl
))
17193 /* Don't add DW_AT_const_value if abstract origin already has one. */
17194 if (get_AT (var_die
, DW_AT_const_value
))
17197 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
17200 /* Convert the CFI instructions for the current function into a
17201 location list. This is used for DW_AT_frame_base when we targeting
17202 a dwarf2 consumer that does not support the dwarf3
17203 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
17206 static dw_loc_list_ref
17207 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
17210 dw_loc_list_ref list
, *list_tail
;
17212 dw_cfa_location last_cfa
, next_cfa
;
17213 const char *start_label
, *last_label
, *section
;
17214 dw_cfa_location remember
;
17216 fde
= current_fde ();
17217 gcc_assert (fde
!= NULL
);
17219 section
= secname_for_decl (current_function_decl
);
17223 memset (&next_cfa
, 0, sizeof (next_cfa
));
17224 next_cfa
.reg
= INVALID_REGNUM
;
17225 remember
= next_cfa
;
17227 start_label
= fde
->dw_fde_begin
;
17229 /* ??? Bald assumption that the CIE opcode list does not contain
17230 advance opcodes. */
17231 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
17232 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
17234 last_cfa
= next_cfa
;
17235 last_label
= start_label
;
17237 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
17238 switch (cfi
->dw_cfi_opc
)
17240 case DW_CFA_set_loc
:
17241 case DW_CFA_advance_loc1
:
17242 case DW_CFA_advance_loc2
:
17243 case DW_CFA_advance_loc4
:
17244 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
17246 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
17247 start_label
, last_label
, section
);
17249 list_tail
= &(*list_tail
)->dw_loc_next
;
17250 last_cfa
= next_cfa
;
17251 start_label
= last_label
;
17253 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
17256 case DW_CFA_advance_loc
:
17257 /* The encoding is complex enough that we should never emit this. */
17258 gcc_unreachable ();
17261 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
17265 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
17267 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
17268 start_label
, last_label
, section
);
17269 list_tail
= &(*list_tail
)->dw_loc_next
;
17270 start_label
= last_label
;
17273 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
17274 start_label
, fde
->dw_fde_end
, section
);
17276 if (list
&& list
->dw_loc_next
)
17282 /* Compute a displacement from the "steady-state frame pointer" to the
17283 frame base (often the same as the CFA), and store it in
17284 frame_pointer_fb_offset. OFFSET is added to the displacement
17285 before the latter is negated. */
17288 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
17292 #ifdef FRAME_POINTER_CFA_OFFSET
17293 reg
= frame_pointer_rtx
;
17294 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
17296 reg
= arg_pointer_rtx
;
17297 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
17300 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
17301 if (GET_CODE (elim
) == PLUS
)
17303 offset
+= INTVAL (XEXP (elim
, 1));
17304 elim
= XEXP (elim
, 0);
17307 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
17308 && (elim
== hard_frame_pointer_rtx
17309 || elim
== stack_pointer_rtx
))
17310 || elim
== (frame_pointer_needed
17311 ? hard_frame_pointer_rtx
17312 : stack_pointer_rtx
));
17314 frame_pointer_fb_offset
= -offset
;
17317 /* Generate a DW_AT_name attribute given some string value to be included as
17318 the value of the attribute. */
17321 add_name_attribute (dw_die_ref die
, const char *name_string
)
17323 if (name_string
!= NULL
&& *name_string
!= 0)
17325 if (demangle_name_func
)
17326 name_string
= (*demangle_name_func
) (name_string
);
17328 add_AT_string (die
, DW_AT_name
, name_string
);
17332 /* Generate a DW_AT_comp_dir attribute for DIE. */
17335 add_comp_dir_attribute (dw_die_ref die
)
17337 const char *wd
= get_src_pwd ();
17343 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
17347 wdlen
= strlen (wd
);
17348 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
17350 wd1
[wdlen
] = DIR_SEPARATOR
;
17351 wd1
[wdlen
+ 1] = 0;
17355 add_AT_string (die
, DW_AT_comp_dir
, remap_debug_filename (wd
));
17358 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
17362 lower_bound_default (void)
17364 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
17369 case DW_LANG_C_plus_plus
:
17371 case DW_LANG_ObjC_plus_plus
:
17374 case DW_LANG_Fortran77
:
17375 case DW_LANG_Fortran90
:
17376 case DW_LANG_Fortran95
:
17380 case DW_LANG_Python
:
17381 return dwarf_version
>= 4 ? 0 : -1;
17382 case DW_LANG_Ada95
:
17383 case DW_LANG_Ada83
:
17384 case DW_LANG_Cobol74
:
17385 case DW_LANG_Cobol85
:
17386 case DW_LANG_Pascal83
:
17387 case DW_LANG_Modula2
:
17389 return dwarf_version
>= 4 ? 1 : -1;
17395 /* Given a tree node describing an array bound (either lower or upper) output
17396 a representation for that bound. */
17399 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
17401 switch (TREE_CODE (bound
))
17406 /* All fixed-bounds are represented by INTEGER_CST nodes. */
17409 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
17412 /* Use the default if possible. */
17413 if (bound_attr
== DW_AT_lower_bound
17414 && host_integerp (bound
, 0)
17415 && (dflt
= lower_bound_default ()) != -1
17416 && tree_low_cst (bound
, 0) == dflt
)
17419 /* Otherwise represent the bound as an unsigned value with the
17420 precision of its type. The precision and signedness of the
17421 type will be necessary to re-interpret it unambiguously. */
17422 else if (prec
< HOST_BITS_PER_WIDE_INT
)
17424 unsigned HOST_WIDE_INT mask
17425 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
17426 add_AT_unsigned (subrange_die
, bound_attr
,
17427 TREE_INT_CST_LOW (bound
) & mask
);
17429 else if (prec
== HOST_BITS_PER_WIDE_INT
17430 || TREE_INT_CST_HIGH (bound
) == 0)
17431 add_AT_unsigned (subrange_die
, bound_attr
,
17432 TREE_INT_CST_LOW (bound
));
17434 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
17435 TREE_INT_CST_LOW (bound
));
17440 case VIEW_CONVERT_EXPR
:
17441 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
17451 dw_die_ref decl_die
= lookup_decl_die (bound
);
17453 /* ??? Can this happen, or should the variable have been bound
17454 first? Probably it can, since I imagine that we try to create
17455 the types of parameters in the order in which they exist in
17456 the list, and won't have created a forward reference to a
17457 later parameter. */
17458 if (decl_die
!= NULL
)
17460 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
17468 /* Otherwise try to create a stack operation procedure to
17469 evaluate the value of the array bound. */
17471 dw_die_ref ctx
, decl_die
;
17472 dw_loc_list_ref list
;
17474 list
= loc_list_from_tree (bound
, 2);
17475 if (list
== NULL
|| single_element_loc_list_p (list
))
17477 /* If DW_AT_*bound is not a reference nor constant, it is
17478 a DWARF expression rather than location description.
17479 For that loc_list_from_tree (bound, 0) is needed.
17480 If that fails to give a single element list,
17481 fall back to outputting this as a reference anyway. */
17482 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
17483 if (list2
&& single_element_loc_list_p (list2
))
17485 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
17492 if (current_function_decl
== 0)
17493 ctx
= comp_unit_die ();
17495 ctx
= lookup_decl_die (current_function_decl
);
17497 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
17498 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
17499 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
17500 add_AT_location_description (decl_die
, DW_AT_location
, list
);
17501 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
17507 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
17508 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
17509 Note that the block of subscript information for an array type also
17510 includes information about the element type of the given array type. */
17513 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
17515 unsigned dimension_number
;
17517 dw_die_ref subrange_die
;
17519 for (dimension_number
= 0;
17520 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
17521 type
= TREE_TYPE (type
), dimension_number
++)
17523 tree domain
= TYPE_DOMAIN (type
);
17525 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
17528 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
17529 and (in GNU C only) variable bounds. Handle all three forms
17531 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
17534 /* We have an array type with specified bounds. */
17535 lower
= TYPE_MIN_VALUE (domain
);
17536 upper
= TYPE_MAX_VALUE (domain
);
17538 /* Define the index type. */
17539 if (TREE_TYPE (domain
))
17541 /* ??? This is probably an Ada unnamed subrange type. Ignore the
17542 TREE_TYPE field. We can't emit debug info for this
17543 because it is an unnamed integral type. */
17544 if (TREE_CODE (domain
) == INTEGER_TYPE
17545 && TYPE_NAME (domain
) == NULL_TREE
17546 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
17547 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
17550 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
17554 /* ??? If upper is NULL, the array has unspecified length,
17555 but it does have a lower bound. This happens with Fortran
17557 Since the debugger is definitely going to need to know N
17558 to produce useful results, go ahead and output the lower
17559 bound solo, and hope the debugger can cope. */
17561 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
17563 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
17566 /* Otherwise we have an array type with an unspecified length. The
17567 DWARF-2 spec does not say how to handle this; let's just leave out the
17573 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
17577 switch (TREE_CODE (tree_node
))
17582 case ENUMERAL_TYPE
:
17585 case QUAL_UNION_TYPE
:
17586 size
= int_size_in_bytes (tree_node
);
17589 /* For a data member of a struct or union, the DW_AT_byte_size is
17590 generally given as the number of bytes normally allocated for an
17591 object of the *declared* type of the member itself. This is true
17592 even for bit-fields. */
17593 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
17596 gcc_unreachable ();
17599 /* Note that `size' might be -1 when we get to this point. If it is, that
17600 indicates that the byte size of the entity in question is variable. We
17601 have no good way of expressing this fact in Dwarf at the present time,
17602 so just let the -1 pass on through. */
17603 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
17606 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17607 which specifies the distance in bits from the highest order bit of the
17608 "containing object" for the bit-field to the highest order bit of the
17611 For any given bit-field, the "containing object" is a hypothetical object
17612 (of some integral or enum type) within which the given bit-field lives. The
17613 type of this hypothetical "containing object" is always the same as the
17614 declared type of the individual bit-field itself. The determination of the
17615 exact location of the "containing object" for a bit-field is rather
17616 complicated. It's handled by the `field_byte_offset' function (above).
17618 Note that it is the size (in bytes) of the hypothetical "containing object"
17619 which will be given in the DW_AT_byte_size attribute for this bit-field.
17620 (See `byte_size_attribute' above). */
17623 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
17625 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
17626 tree type
= DECL_BIT_FIELD_TYPE (decl
);
17627 HOST_WIDE_INT bitpos_int
;
17628 HOST_WIDE_INT highest_order_object_bit_offset
;
17629 HOST_WIDE_INT highest_order_field_bit_offset
;
17630 HOST_WIDE_INT bit_offset
;
17632 /* Must be a field and a bit field. */
17633 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
17635 /* We can't yet handle bit-fields whose offsets are variable, so if we
17636 encounter such things, just return without generating any attribute
17637 whatsoever. Likewise for variable or too large size. */
17638 if (! host_integerp (bit_position (decl
), 0)
17639 || ! host_integerp (DECL_SIZE (decl
), 1))
17642 bitpos_int
= int_bit_position (decl
);
17644 /* Note that the bit offset is always the distance (in bits) from the
17645 highest-order bit of the "containing object" to the highest-order bit of
17646 the bit-field itself. Since the "high-order end" of any object or field
17647 is different on big-endian and little-endian machines, the computation
17648 below must take account of these differences. */
17649 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
17650 highest_order_field_bit_offset
= bitpos_int
;
17652 if (! BYTES_BIG_ENDIAN
)
17654 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
17655 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
17659 = (! BYTES_BIG_ENDIAN
17660 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
17661 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
17663 if (bit_offset
< 0)
17664 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
17666 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
17669 /* For a FIELD_DECL node which represents a bit field, output an attribute
17670 which specifies the length in bits of the given field. */
17673 add_bit_size_attribute (dw_die_ref die
, tree decl
)
17675 /* Must be a field and a bit field. */
17676 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
17677 && DECL_BIT_FIELD_TYPE (decl
));
17679 if (host_integerp (DECL_SIZE (decl
), 1))
17680 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
17683 /* If the compiled language is ANSI C, then add a 'prototyped'
17684 attribute, if arg types are given for the parameters of a function. */
17687 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
17689 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
17690 && prototype_p (func_type
))
17691 add_AT_flag (die
, DW_AT_prototyped
, 1);
17694 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17695 by looking in either the type declaration or object declaration
17698 static inline dw_die_ref
17699 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
17701 dw_die_ref origin_die
= NULL
;
17703 if (TREE_CODE (origin
) != FUNCTION_DECL
)
17705 /* We may have gotten separated from the block for the inlined
17706 function, if we're in an exception handler or some such; make
17707 sure that the abstract function has been written out.
17709 Doing this for nested functions is wrong, however; functions are
17710 distinct units, and our context might not even be inline. */
17714 fn
= TYPE_STUB_DECL (fn
);
17716 fn
= decl_function_context (fn
);
17718 dwarf2out_abstract_function (fn
);
17721 if (DECL_P (origin
))
17722 origin_die
= lookup_decl_die (origin
);
17723 else if (TYPE_P (origin
))
17724 origin_die
= lookup_type_die (origin
);
17726 /* XXX: Functions that are never lowered don't always have correct block
17727 trees (in the case of java, they simply have no block tree, in some other
17728 languages). For these functions, there is nothing we can really do to
17729 output correct debug info for inlined functions in all cases. Rather
17730 than die, we'll just produce deficient debug info now, in that we will
17731 have variables without a proper abstract origin. In the future, when all
17732 functions are lowered, we should re-add a gcc_assert (origin_die)
17736 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
17740 /* We do not currently support the pure_virtual attribute. */
17743 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
17745 if (DECL_VINDEX (func_decl
))
17747 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
17749 if (host_integerp (DECL_VINDEX (func_decl
), 0))
17750 add_AT_loc (die
, DW_AT_vtable_elem_location
,
17751 new_loc_descr (DW_OP_constu
,
17752 tree_low_cst (DECL_VINDEX (func_decl
), 0),
17755 /* GNU extension: Record what type this method came from originally. */
17756 if (debug_info_level
> DINFO_LEVEL_TERSE
17757 && DECL_CONTEXT (func_decl
))
17758 add_AT_die_ref (die
, DW_AT_containing_type
,
17759 lookup_type_die (DECL_CONTEXT (func_decl
)));
17763 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
17764 given decl. This used to be a vendor extension until after DWARF 4
17765 standardized it. */
17768 add_linkage_attr (dw_die_ref die
, tree decl
)
17770 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
17772 /* Mimic what assemble_name_raw does with a leading '*'. */
17773 if (name
[0] == '*')
17776 if (dwarf_version
>= 4)
17777 add_AT_string (die
, DW_AT_linkage_name
, name
);
17779 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
17782 /* Add source coordinate attributes for the given decl. */
17785 add_src_coords_attributes (dw_die_ref die
, tree decl
)
17787 expanded_location s
;
17789 if (DECL_SOURCE_LOCATION (decl
) == UNKNOWN_LOCATION
)
17791 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17792 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
17793 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
17796 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
17799 add_linkage_name (dw_die_ref die
, tree decl
)
17801 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
17802 && TREE_PUBLIC (decl
)
17803 && !DECL_ABSTRACT (decl
)
17804 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
17805 && die
->die_tag
!= DW_TAG_member
)
17807 /* Defer until we have an assembler name set. */
17808 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
17810 limbo_die_node
*asm_name
;
17812 asm_name
= ggc_alloc_cleared_limbo_die_node ();
17813 asm_name
->die
= die
;
17814 asm_name
->created_for
= decl
;
17815 asm_name
->next
= deferred_asm_name
;
17816 deferred_asm_name
= asm_name
;
17818 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
17819 add_linkage_attr (die
, decl
);
17823 /* Add a DW_AT_name attribute and source coordinate attribute for the
17824 given decl, but only if it actually has a name. */
17827 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
17831 decl_name
= DECL_NAME (decl
);
17832 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
17834 const char *name
= dwarf2_name (decl
, 0);
17836 add_name_attribute (die
, name
);
17837 if (! DECL_ARTIFICIAL (decl
))
17838 add_src_coords_attributes (die
, decl
);
17840 add_linkage_name (die
, decl
);
17843 #ifdef VMS_DEBUGGING_INFO
17844 /* Get the function's name, as described by its RTL. This may be different
17845 from the DECL_NAME name used in the source file. */
17846 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
17848 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
17849 XEXP (DECL_RTL (decl
), 0));
17850 VEC_safe_push (rtx
, gc
, used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
17852 #endif /* VMS_DEBUGGING_INFO */
17855 #ifdef VMS_DEBUGGING_INFO
17856 /* Output the debug main pointer die for VMS */
17859 dwarf2out_vms_debug_main_pointer (void)
17861 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
17864 /* Allocate the VMS debug main subprogram die. */
17865 die
= ggc_alloc_cleared_die_node ();
17866 die
->die_tag
= DW_TAG_subprogram
;
17867 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
17868 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
17869 current_function_funcdef_no
);
17870 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
17872 /* Make it the first child of comp_unit_die (). */
17873 die
->die_parent
= comp_unit_die ();
17874 if (comp_unit_die ()->die_child
)
17876 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
17877 comp_unit_die ()->die_child
->die_sib
= die
;
17881 die
->die_sib
= die
;
17882 comp_unit_die ()->die_child
= die
;
17885 #endif /* VMS_DEBUGGING_INFO */
17887 /* Push a new declaration scope. */
17890 push_decl_scope (tree scope
)
17892 VEC_safe_push (tree
, gc
, decl_scope_table
, scope
);
17895 /* Pop a declaration scope. */
17898 pop_decl_scope (void)
17900 VEC_pop (tree
, decl_scope_table
);
17903 /* Return the DIE for the scope that immediately contains this type.
17904 Non-named types get global scope. Named types nested in other
17905 types get their containing scope if it's open, or global scope
17906 otherwise. All other types (i.e. function-local named types) get
17907 the current active scope. */
17910 scope_die_for (tree t
, dw_die_ref context_die
)
17912 dw_die_ref scope_die
= NULL
;
17913 tree containing_scope
;
17916 /* Non-types always go in the current scope. */
17917 gcc_assert (TYPE_P (t
));
17919 containing_scope
= TYPE_CONTEXT (t
);
17921 /* Use the containing namespace if it was passed in (for a declaration). */
17922 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
17924 if (context_die
== lookup_decl_die (containing_scope
))
17927 containing_scope
= NULL_TREE
;
17930 /* Ignore function type "scopes" from the C frontend. They mean that
17931 a tagged type is local to a parmlist of a function declarator, but
17932 that isn't useful to DWARF. */
17933 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
17934 containing_scope
= NULL_TREE
;
17936 if (SCOPE_FILE_SCOPE_P (containing_scope
))
17937 scope_die
= comp_unit_die ();
17938 else if (TYPE_P (containing_scope
))
17940 /* For types, we can just look up the appropriate DIE. But
17941 first we check to see if we're in the middle of emitting it
17942 so we know where the new DIE should go. */
17943 for (i
= VEC_length (tree
, decl_scope_table
) - 1; i
>= 0; --i
)
17944 if (VEC_index (tree
, decl_scope_table
, i
) == containing_scope
)
17949 gcc_assert (debug_info_level
<= DINFO_LEVEL_TERSE
17950 || TREE_ASM_WRITTEN (containing_scope
));
17951 /*We are not in the middle of emitting the type
17952 CONTAINING_SCOPE. Let's see if it's emitted already. */
17953 scope_die
= lookup_type_die (containing_scope
);
17955 /* If none of the current dies are suitable, we get file scope. */
17956 if (scope_die
== NULL
)
17957 scope_die
= comp_unit_die ();
17960 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
17963 scope_die
= context_die
;
17968 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
17971 local_scope_p (dw_die_ref context_die
)
17973 for (; context_die
; context_die
= context_die
->die_parent
)
17974 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
17975 || context_die
->die_tag
== DW_TAG_subprogram
)
17981 /* Returns nonzero if CONTEXT_DIE is a class. */
17984 class_scope_p (dw_die_ref context_die
)
17986 return (context_die
17987 && (context_die
->die_tag
== DW_TAG_structure_type
17988 || context_die
->die_tag
== DW_TAG_class_type
17989 || context_die
->die_tag
== DW_TAG_interface_type
17990 || context_die
->die_tag
== DW_TAG_union_type
));
17993 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
17994 whether or not to treat a DIE in this context as a declaration. */
17997 class_or_namespace_scope_p (dw_die_ref context_die
)
17999 return (class_scope_p (context_die
)
18000 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
18003 /* Many forms of DIEs require a "type description" attribute. This
18004 routine locates the proper "type descriptor" die for the type given
18005 by 'type', and adds a DW_AT_type attribute below the given die. */
18008 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
18009 int decl_volatile
, dw_die_ref context_die
)
18011 enum tree_code code
= TREE_CODE (type
);
18012 dw_die_ref type_die
= NULL
;
18014 /* ??? If this type is an unnamed subrange type of an integral, floating-point
18015 or fixed-point type, use the inner type. This is because we have no
18016 support for unnamed types in base_type_die. This can happen if this is
18017 an Ada subrange type. Correct solution is emit a subrange type die. */
18018 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
18019 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
18020 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
18022 if (code
== ERROR_MARK
18023 /* Handle a special case. For functions whose return type is void, we
18024 generate *no* type attribute. (Note that no object may have type
18025 `void', so this only applies to function return types). */
18026 || code
== VOID_TYPE
)
18029 type_die
= modified_type_die (type
,
18030 decl_const
|| TYPE_READONLY (type
),
18031 decl_volatile
|| TYPE_VOLATILE (type
),
18034 if (type_die
!= NULL
)
18035 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
18038 /* Given an object die, add the calling convention attribute for the
18039 function call type. */
18041 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
18043 enum dwarf_calling_convention value
= DW_CC_normal
;
18045 value
= ((enum dwarf_calling_convention
)
18046 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
18049 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
18051 /* DWARF 2 doesn't provide a way to identify a program's source-level
18052 entry point. DW_AT_calling_convention attributes are only meant
18053 to describe functions' calling conventions. However, lacking a
18054 better way to signal the Fortran main program, we used this for
18055 a long time, following existing custom. Now, DWARF 4 has
18056 DW_AT_main_subprogram, which we add below, but some tools still
18057 rely on the old way, which we thus keep. */
18058 value
= DW_CC_program
;
18060 if (dwarf_version
>= 4 || !dwarf_strict
)
18061 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
18064 /* Only add the attribute if the backend requests it, and
18065 is not DW_CC_normal. */
18066 if (value
&& (value
!= DW_CC_normal
))
18067 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
18070 /* Given a tree pointer to a struct, class, union, or enum type node, return
18071 a pointer to the (string) tag name for the given type, or zero if the type
18072 was declared without a tag. */
18074 static const char *
18075 type_tag (const_tree type
)
18077 const char *name
= 0;
18079 if (TYPE_NAME (type
) != 0)
18083 /* Find the IDENTIFIER_NODE for the type name. */
18084 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
18085 && !TYPE_NAMELESS (type
))
18086 t
= TYPE_NAME (type
);
18088 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
18089 a TYPE_DECL node, regardless of whether or not a `typedef' was
18091 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
18092 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
18094 /* We want to be extra verbose. Don't call dwarf_name if
18095 DECL_NAME isn't set. The default hook for decl_printable_name
18096 doesn't like that, and in this context it's correct to return
18097 0, instead of "<anonymous>" or the like. */
18098 if (DECL_NAME (TYPE_NAME (type
))
18099 && !DECL_NAMELESS (TYPE_NAME (type
)))
18100 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
18103 /* Now get the name as a string, or invent one. */
18104 if (!name
&& t
!= 0)
18105 name
= IDENTIFIER_POINTER (t
);
18108 return (name
== 0 || *name
== '\0') ? 0 : name
;
18111 /* Return the type associated with a data member, make a special check
18112 for bit field types. */
18115 member_declared_type (const_tree member
)
18117 return (DECL_BIT_FIELD_TYPE (member
)
18118 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
18121 /* Get the decl's label, as described by its RTL. This may be different
18122 from the DECL_NAME name used in the source file. */
18125 static const char *
18126 decl_start_label (tree decl
)
18129 const char *fnname
;
18131 x
= DECL_RTL (decl
);
18132 gcc_assert (MEM_P (x
));
18135 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
18137 fnname
= XSTR (x
, 0);
18142 /* These routines generate the internal representation of the DIE's for
18143 the compilation unit. Debugging information is collected by walking
18144 the declaration trees passed in from dwarf2out_decl(). */
18147 gen_array_type_die (tree type
, dw_die_ref context_die
)
18149 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
18150 dw_die_ref array_die
;
18152 /* GNU compilers represent multidimensional array types as sequences of one
18153 dimensional array types whose element types are themselves array types.
18154 We sometimes squish that down to a single array_type DIE with multiple
18155 subscripts in the Dwarf debugging info. The draft Dwarf specification
18156 say that we are allowed to do this kind of compression in C, because
18157 there is no difference between an array of arrays and a multidimensional
18158 array. We don't do this for Ada to remain as close as possible to the
18159 actual representation, which is especially important against the language
18160 flexibilty wrt arrays of variable size. */
18162 bool collapse_nested_arrays
= !is_ada ();
18165 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
18166 DW_TAG_string_type doesn't have DW_AT_type attribute). */
18167 if (TYPE_STRING_FLAG (type
)
18168 && TREE_CODE (type
) == ARRAY_TYPE
18170 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
18172 HOST_WIDE_INT size
;
18174 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
18175 add_name_attribute (array_die
, type_tag (type
));
18176 equate_type_number_to_die (type
, array_die
);
18177 size
= int_size_in_bytes (type
);
18179 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
18180 else if (TYPE_DOMAIN (type
) != NULL_TREE
18181 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
18182 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
18184 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
18185 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
18187 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
18188 if (loc
&& size
> 0)
18190 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
18191 if (size
!= DWARF2_ADDR_SIZE
)
18192 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
18198 /* ??? The SGI dwarf reader fails for array of array of enum types
18199 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
18200 array type comes before the outer array type. We thus call gen_type_die
18201 before we new_die and must prevent nested array types collapsing for this
18204 #ifdef MIPS_DEBUGGING_INFO
18205 gen_type_die (TREE_TYPE (type
), context_die
);
18206 collapse_nested_arrays
= false;
18209 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
18210 add_name_attribute (array_die
, type_tag (type
));
18211 equate_type_number_to_die (type
, array_die
);
18213 if (TREE_CODE (type
) == VECTOR_TYPE
)
18214 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
18216 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18218 && TREE_CODE (type
) == ARRAY_TYPE
18219 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
18220 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
18221 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
18224 /* We default the array ordering. SDB will probably do
18225 the right things even if DW_AT_ordering is not present. It's not even
18226 an issue until we start to get into multidimensional arrays anyway. If
18227 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
18228 then we'll have to put the DW_AT_ordering attribute back in. (But if
18229 and when we find out that we need to put these in, we will only do so
18230 for multidimensional arrays. */
18231 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
18234 #ifdef MIPS_DEBUGGING_INFO
18235 /* The SGI compilers handle arrays of unknown bound by setting
18236 AT_declaration and not emitting any subrange DIEs. */
18237 if (TREE_CODE (type
) == ARRAY_TYPE
18238 && ! TYPE_DOMAIN (type
))
18239 add_AT_flag (array_die
, DW_AT_declaration
, 1);
18242 if (TREE_CODE (type
) == VECTOR_TYPE
)
18244 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
18245 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
18246 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
18247 add_bound_info (subrange_die
, DW_AT_upper_bound
,
18248 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
18251 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
18253 /* Add representation of the type of the elements of this array type and
18254 emit the corresponding DIE if we haven't done it already. */
18255 element_type
= TREE_TYPE (type
);
18256 if (collapse_nested_arrays
)
18257 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
18259 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
18261 element_type
= TREE_TYPE (element_type
);
18264 #ifndef MIPS_DEBUGGING_INFO
18265 gen_type_die (element_type
, context_die
);
18268 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
18270 if (get_AT (array_die
, DW_AT_name
))
18271 add_pubtype (type
, array_die
);
18274 static dw_loc_descr_ref
18275 descr_info_loc (tree val
, tree base_decl
)
18277 HOST_WIDE_INT size
;
18278 dw_loc_descr_ref loc
, loc2
;
18279 enum dwarf_location_atom op
;
18281 if (val
== base_decl
)
18282 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
18284 switch (TREE_CODE (val
))
18287 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
18289 return loc_descriptor_from_tree (val
, 0);
18291 if (host_integerp (val
, 0))
18292 return int_loc_descriptor (tree_low_cst (val
, 0));
18295 size
= int_size_in_bytes (TREE_TYPE (val
));
18298 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
18301 if (size
== DWARF2_ADDR_SIZE
)
18302 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
18304 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
18306 case POINTER_PLUS_EXPR
:
18308 if (host_integerp (TREE_OPERAND (val
, 1), 1)
18309 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
18312 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
18315 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
18321 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
18324 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
18327 add_loc_descr (&loc
, loc2
);
18328 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
18350 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
18351 tree val
, tree base_decl
)
18353 dw_loc_descr_ref loc
;
18355 if (host_integerp (val
, 0))
18357 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
18361 loc
= descr_info_loc (val
, base_decl
);
18365 add_AT_loc (die
, attr
, loc
);
18368 /* This routine generates DIE for array with hidden descriptor, details
18369 are filled into *info by a langhook. */
18372 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
18373 dw_die_ref context_die
)
18375 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
18376 dw_die_ref array_die
;
18379 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
18380 add_name_attribute (array_die
, type_tag (type
));
18381 equate_type_number_to_die (type
, array_die
);
18383 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18385 && info
->ndimensions
>= 2)
18386 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
18388 if (info
->data_location
)
18389 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
18391 if (info
->associated
)
18392 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
18394 if (info
->allocated
)
18395 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
18398 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
18400 dw_die_ref subrange_die
18401 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
18403 if (info
->dimen
[dim
].lower_bound
)
18405 /* If it is the default value, omit it. */
18408 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
18409 && (dflt
= lower_bound_default ()) != -1
18410 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
18413 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
18414 info
->dimen
[dim
].lower_bound
,
18417 if (info
->dimen
[dim
].upper_bound
)
18418 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
18419 info
->dimen
[dim
].upper_bound
,
18421 if (info
->dimen
[dim
].stride
)
18422 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
18423 info
->dimen
[dim
].stride
,
18427 gen_type_die (info
->element_type
, context_die
);
18428 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
18430 if (get_AT (array_die
, DW_AT_name
))
18431 add_pubtype (type
, array_die
);
18436 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
18438 tree origin
= decl_ultimate_origin (decl
);
18439 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
18441 if (origin
!= NULL
)
18442 add_abstract_origin_attribute (decl_die
, origin
);
18445 add_name_and_src_coords_attributes (decl_die
, decl
);
18446 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
18447 0, 0, context_die
);
18450 if (DECL_ABSTRACT (decl
))
18451 equate_decl_number_to_die (decl
, decl_die
);
18453 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
18457 /* Walk through the list of incomplete types again, trying once more to
18458 emit full debugging info for them. */
18461 retry_incomplete_types (void)
18465 for (i
= VEC_length (tree
, incomplete_types
) - 1; i
>= 0; i
--)
18466 if (should_emit_struct_debug (VEC_index (tree
, incomplete_types
, i
),
18467 DINFO_USAGE_DIR_USE
))
18468 gen_type_die (VEC_index (tree
, incomplete_types
, i
), comp_unit_die ());
18471 /* Determine what tag to use for a record type. */
18473 static enum dwarf_tag
18474 record_type_tag (tree type
)
18476 if (! lang_hooks
.types
.classify_record
)
18477 return DW_TAG_structure_type
;
18479 switch (lang_hooks
.types
.classify_record (type
))
18481 case RECORD_IS_STRUCT
:
18482 return DW_TAG_structure_type
;
18484 case RECORD_IS_CLASS
:
18485 return DW_TAG_class_type
;
18487 case RECORD_IS_INTERFACE
:
18488 if (dwarf_version
>= 3 || !dwarf_strict
)
18489 return DW_TAG_interface_type
;
18490 return DW_TAG_structure_type
;
18493 gcc_unreachable ();
18497 /* Generate a DIE to represent an enumeration type. Note that these DIEs
18498 include all of the information about the enumeration values also. Each
18499 enumerated type name/value is listed as a child of the enumerated type
18503 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
18505 dw_die_ref type_die
= lookup_type_die (type
);
18507 if (type_die
== NULL
)
18509 type_die
= new_die (DW_TAG_enumeration_type
,
18510 scope_die_for (type
, context_die
), type
);
18511 equate_type_number_to_die (type
, type_die
);
18512 add_name_attribute (type_die
, type_tag (type
));
18513 if (dwarf_version
>= 4 || !dwarf_strict
)
18515 if (ENUM_IS_SCOPED (type
))
18516 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
18517 if (ENUM_IS_OPAQUE (type
))
18518 add_AT_flag (type_die
, DW_AT_declaration
, 1);
18521 else if (! TYPE_SIZE (type
))
18524 remove_AT (type_die
, DW_AT_declaration
);
18526 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
18527 given enum type is incomplete, do not generate the DW_AT_byte_size
18528 attribute or the DW_AT_element_list attribute. */
18529 if (TYPE_SIZE (type
))
18533 TREE_ASM_WRITTEN (type
) = 1;
18534 add_byte_size_attribute (type_die
, type
);
18535 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
18537 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
18538 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
18541 /* If the first reference to this type was as the return type of an
18542 inline function, then it may not have a parent. Fix this now. */
18543 if (type_die
->die_parent
== NULL
)
18544 add_child_die (scope_die_for (type
, context_die
), type_die
);
18546 for (link
= TYPE_VALUES (type
);
18547 link
!= NULL
; link
= TREE_CHAIN (link
))
18549 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
18550 tree value
= TREE_VALUE (link
);
18552 add_name_attribute (enum_die
,
18553 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
18555 if (TREE_CODE (value
) == CONST_DECL
)
18556 value
= DECL_INITIAL (value
);
18558 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
18559 /* DWARF2 does not provide a way of indicating whether or
18560 not enumeration constants are signed or unsigned. GDB
18561 always assumes the values are signed, so we output all
18562 values as if they were signed. That means that
18563 enumeration constants with very large unsigned values
18564 will appear to have negative values in the debugger. */
18565 add_AT_int (enum_die
, DW_AT_const_value
,
18566 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
18570 add_AT_flag (type_die
, DW_AT_declaration
, 1);
18572 if (get_AT (type_die
, DW_AT_name
))
18573 add_pubtype (type
, type_die
);
18578 /* Generate a DIE to represent either a real live formal parameter decl or to
18579 represent just the type of some formal parameter position in some function
18582 Note that this routine is a bit unusual because its argument may be a
18583 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
18584 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
18585 node. If it's the former then this function is being called to output a
18586 DIE to represent a formal parameter object (or some inlining thereof). If
18587 it's the latter, then this function is only being called to output a
18588 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
18589 argument type of some subprogram type.
18590 If EMIT_NAME_P is true, name and source coordinate attributes
18594 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
18595 dw_die_ref context_die
)
18597 tree node_or_origin
= node
? node
: origin
;
18598 tree ultimate_origin
;
18599 dw_die_ref parm_die
18600 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
18602 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
18604 case tcc_declaration
:
18605 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
18606 if (node
|| ultimate_origin
)
18607 origin
= ultimate_origin
;
18608 if (origin
!= NULL
)
18609 add_abstract_origin_attribute (parm_die
, origin
);
18610 else if (emit_name_p
)
18611 add_name_and_src_coords_attributes (parm_die
, node
);
18613 || (! DECL_ABSTRACT (node_or_origin
)
18614 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
18615 decl_function_context
18616 (node_or_origin
))))
18618 tree type
= TREE_TYPE (node_or_origin
);
18619 if (decl_by_reference_p (node_or_origin
))
18620 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
18623 add_type_attribute (parm_die
, type
,
18624 TREE_READONLY (node_or_origin
),
18625 TREE_THIS_VOLATILE (node_or_origin
),
18628 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
18629 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18631 if (node
&& node
!= origin
)
18632 equate_decl_number_to_die (node
, parm_die
);
18633 if (! DECL_ABSTRACT (node_or_origin
))
18634 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
18640 /* We were called with some kind of a ..._TYPE node. */
18641 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
18645 gcc_unreachable ();
18651 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18652 children DW_TAG_formal_parameter DIEs representing the arguments of the
18655 PARM_PACK must be a function parameter pack.
18656 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18657 must point to the subsequent arguments of the function PACK_ARG belongs to.
18658 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18659 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18660 following the last one for which a DIE was generated. */
18663 gen_formal_parameter_pack_die (tree parm_pack
,
18665 dw_die_ref subr_die
,
18669 dw_die_ref parm_pack_die
;
18671 gcc_assert (parm_pack
18672 && lang_hooks
.function_parameter_pack_p (parm_pack
)
18675 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
18676 add_src_coords_attributes (parm_pack_die
, parm_pack
);
18678 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
18680 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
18683 gen_formal_parameter_die (arg
, NULL
,
18684 false /* Don't emit name attribute. */,
18689 return parm_pack_die
;
18692 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18693 at the end of an (ANSI prototyped) formal parameters list. */
18696 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
18698 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
18701 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18702 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18703 parameters as specified in some function type specification (except for
18704 those which appear as part of a function *definition*). */
18707 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
18710 tree formal_type
= NULL
;
18711 tree first_parm_type
;
18714 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
18716 arg
= DECL_ARGUMENTS (function_or_method_type
);
18717 function_or_method_type
= TREE_TYPE (function_or_method_type
);
18722 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
18724 /* Make our first pass over the list of formal parameter types and output a
18725 DW_TAG_formal_parameter DIE for each one. */
18726 for (link
= first_parm_type
; link
; )
18728 dw_die_ref parm_die
;
18730 formal_type
= TREE_VALUE (link
);
18731 if (formal_type
== void_type_node
)
18734 /* Output a (nameless) DIE to represent the formal parameter itself. */
18735 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
18736 true /* Emit name attribute. */,
18738 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
18739 && link
== first_parm_type
)
18741 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18742 if (dwarf_version
>= 3 || !dwarf_strict
)
18743 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
18745 else if (arg
&& DECL_ARTIFICIAL (arg
))
18746 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18748 link
= TREE_CHAIN (link
);
18750 arg
= DECL_CHAIN (arg
);
18753 /* If this function type has an ellipsis, add a
18754 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18755 if (formal_type
!= void_type_node
)
18756 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
18758 /* Make our second (and final) pass over the list of formal parameter types
18759 and output DIEs to represent those types (as necessary). */
18760 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
18761 link
&& TREE_VALUE (link
);
18762 link
= TREE_CHAIN (link
))
18763 gen_type_die (TREE_VALUE (link
), context_die
);
18766 /* We want to generate the DIE for TYPE so that we can generate the
18767 die for MEMBER, which has been defined; we will need to refer back
18768 to the member declaration nested within TYPE. If we're trying to
18769 generate minimal debug info for TYPE, processing TYPE won't do the
18770 trick; we need to attach the member declaration by hand. */
18773 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
18775 gen_type_die (type
, context_die
);
18777 /* If we're trying to avoid duplicate debug info, we may not have
18778 emitted the member decl for this function. Emit it now. */
18779 if (TYPE_STUB_DECL (type
)
18780 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
18781 && ! lookup_decl_die (member
))
18783 dw_die_ref type_die
;
18784 gcc_assert (!decl_ultimate_origin (member
));
18786 push_decl_scope (type
);
18787 type_die
= lookup_type_die_strip_naming_typedef (type
);
18788 if (TREE_CODE (member
) == FUNCTION_DECL
)
18789 gen_subprogram_die (member
, type_die
);
18790 else if (TREE_CODE (member
) == FIELD_DECL
)
18792 /* Ignore the nameless fields that are used to skip bits but handle
18793 C++ anonymous unions and structs. */
18794 if (DECL_NAME (member
) != NULL_TREE
18795 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
18796 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
18798 gen_type_die (member_declared_type (member
), type_die
);
18799 gen_field_die (member
, type_die
);
18803 gen_variable_die (member
, NULL_TREE
, type_die
);
18809 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18810 may later generate inlined and/or out-of-line instances of. */
18813 dwarf2out_abstract_function (tree decl
)
18815 dw_die_ref old_die
;
18819 htab_t old_decl_loc_table
;
18820 int old_call_site_count
, old_tail_call_site_count
;
18821 struct call_arg_loc_node
*old_call_arg_locations
;
18823 /* Make sure we have the actual abstract inline, not a clone. */
18824 decl
= DECL_ORIGIN (decl
);
18826 old_die
= lookup_decl_die (decl
);
18827 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
18828 /* We've already generated the abstract instance. */
18831 /* We can be called while recursively when seeing block defining inlined subroutine
18832 DIE. Be sure to not clobber the outer location table nor use it or we would
18833 get locations in abstract instantces. */
18834 old_decl_loc_table
= decl_loc_table
;
18835 decl_loc_table
= NULL
;
18836 old_call_arg_locations
= call_arg_locations
;
18837 call_arg_locations
= NULL
;
18838 old_call_site_count
= call_site_count
;
18839 call_site_count
= -1;
18840 old_tail_call_site_count
= tail_call_site_count
;
18841 tail_call_site_count
= -1;
18843 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18844 we don't get confused by DECL_ABSTRACT. */
18845 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18847 context
= decl_class_context (decl
);
18849 gen_type_die_for_member
18850 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
18853 /* Pretend we've just finished compiling this function. */
18854 save_fn
= current_function_decl
;
18855 current_function_decl
= decl
;
18856 push_cfun (DECL_STRUCT_FUNCTION (decl
));
18858 was_abstract
= DECL_ABSTRACT (decl
);
18859 set_decl_abstract_flags (decl
, 1);
18860 dwarf2out_decl (decl
);
18861 if (! was_abstract
)
18862 set_decl_abstract_flags (decl
, 0);
18864 current_function_decl
= save_fn
;
18865 decl_loc_table
= old_decl_loc_table
;
18866 call_arg_locations
= old_call_arg_locations
;
18867 call_site_count
= old_call_site_count
;
18868 tail_call_site_count
= old_tail_call_site_count
;
18872 /* Helper function of premark_used_types() which gets called through
18875 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18876 marked as unused by prune_unused_types. */
18879 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
18884 type
= (tree
) *slot
;
18885 die
= lookup_type_die (type
);
18887 die
->die_perennial_p
= 1;
18891 /* Helper function of premark_types_used_by_global_vars which gets called
18892 through htab_traverse.
18894 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18895 marked as unused by prune_unused_types. The DIE of the type is marked
18896 only if the global variable using the type will actually be emitted. */
18899 premark_types_used_by_global_vars_helper (void **slot
,
18900 void *data ATTRIBUTE_UNUSED
)
18902 struct types_used_by_vars_entry
*entry
;
18905 entry
= (struct types_used_by_vars_entry
*) *slot
;
18906 gcc_assert (entry
->type
!= NULL
18907 && entry
->var_decl
!= NULL
);
18908 die
= lookup_type_die (entry
->type
);
18911 /* Ask cgraph if the global variable really is to be emitted.
18912 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18913 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
18914 if (node
&& node
->needed
)
18916 die
->die_perennial_p
= 1;
18917 /* Keep the parent DIEs as well. */
18918 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
18919 die
->die_perennial_p
= 1;
18925 /* Mark all members of used_types_hash as perennial. */
18928 premark_used_types (void)
18930 if (cfun
&& cfun
->used_types_hash
)
18931 htab_traverse (cfun
->used_types_hash
, premark_used_types_helper
, NULL
);
18934 /* Mark all members of types_used_by_vars_entry as perennial. */
18937 premark_types_used_by_global_vars (void)
18939 if (types_used_by_vars_hash
)
18940 htab_traverse (types_used_by_vars_hash
,
18941 premark_types_used_by_global_vars_helper
, NULL
);
18944 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
18945 for CA_LOC call arg loc node. */
18948 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
18949 struct call_arg_loc_node
*ca_loc
)
18951 dw_die_ref stmt_die
= NULL
, die
;
18952 tree block
= ca_loc
->block
;
18955 && block
!= DECL_INITIAL (decl
)
18956 && TREE_CODE (block
) == BLOCK
)
18958 if (VEC_length (dw_die_ref
, block_map
) > BLOCK_NUMBER (block
))
18959 stmt_die
= VEC_index (dw_die_ref
, block_map
, BLOCK_NUMBER (block
));
18962 block
= BLOCK_SUPERCONTEXT (block
);
18964 if (stmt_die
== NULL
)
18965 stmt_die
= subr_die
;
18966 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
18967 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
18968 if (ca_loc
->tail_call_p
)
18969 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
18970 if (ca_loc
->symbol_ref
)
18972 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
18974 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
18976 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
);
18981 /* Generate a DIE to represent a declared function (either file-scope or
18985 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
18987 tree origin
= decl_ultimate_origin (decl
);
18988 dw_die_ref subr_die
;
18990 dw_die_ref old_die
= lookup_decl_die (decl
);
18991 int declaration
= (current_function_decl
!= decl
18992 || class_or_namespace_scope_p (context_die
));
18994 premark_used_types ();
18996 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
18997 started to generate the abstract instance of an inline, decided to output
18998 its containing class, and proceeded to emit the declaration of the inline
18999 from the member list for the class. If so, DECLARATION takes priority;
19000 we'll get back to the abstract instance when done with the class. */
19002 /* The class-scope declaration DIE must be the primary DIE. */
19003 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
19006 gcc_assert (!old_die
);
19009 /* Now that the C++ front end lazily declares artificial member fns, we
19010 might need to retrofit the declaration into its class. */
19011 if (!declaration
&& !origin
&& !old_die
19012 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
19013 && !class_or_namespace_scope_p (context_die
)
19014 && debug_info_level
> DINFO_LEVEL_TERSE
)
19015 old_die
= force_decl_die (decl
);
19017 if (origin
!= NULL
)
19019 gcc_assert (!declaration
|| local_scope_p (context_die
));
19021 /* Fixup die_parent for the abstract instance of a nested
19022 inline function. */
19023 if (old_die
&& old_die
->die_parent
== NULL
)
19024 add_child_die (context_die
, old_die
);
19026 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
19027 add_abstract_origin_attribute (subr_die
, origin
);
19031 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
19032 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
19034 if (!get_AT_flag (old_die
, DW_AT_declaration
)
19035 /* We can have a normal definition following an inline one in the
19036 case of redefinition of GNU C extern inlines.
19037 It seems reasonable to use AT_specification in this case. */
19038 && !get_AT (old_die
, DW_AT_inline
))
19040 /* Detect and ignore this case, where we are trying to output
19041 something we have already output. */
19045 /* If the definition comes from the same place as the declaration,
19046 maybe use the old DIE. We always want the DIE for this function
19047 that has the *_pc attributes to be under comp_unit_die so the
19048 debugger can find it. We also need to do this for abstract
19049 instances of inlines, since the spec requires the out-of-line copy
19050 to have the same parent. For local class methods, this doesn't
19051 apply; we just use the old DIE. */
19052 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
19053 && (DECL_ARTIFICIAL (decl
)
19054 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
19055 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
19056 == (unsigned) s
.line
))))
19058 subr_die
= old_die
;
19060 /* Clear out the declaration attribute and the formal parameters.
19061 Do not remove all children, because it is possible that this
19062 declaration die was forced using force_decl_die(). In such
19063 cases die that forced declaration die (e.g. TAG_imported_module)
19064 is one of the children that we do not want to remove. */
19065 remove_AT (subr_die
, DW_AT_declaration
);
19066 remove_AT (subr_die
, DW_AT_object_pointer
);
19067 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
19071 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
19072 add_AT_specification (subr_die
, old_die
);
19073 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
19074 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
19075 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
19076 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
19081 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
19083 if (TREE_PUBLIC (decl
))
19084 add_AT_flag (subr_die
, DW_AT_external
, 1);
19086 add_name_and_src_coords_attributes (subr_die
, decl
);
19087 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19089 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
19090 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
19091 0, 0, context_die
);
19094 add_pure_or_virtual_attribute (subr_die
, decl
);
19095 if (DECL_ARTIFICIAL (decl
))
19096 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
19098 add_accessibility_attribute (subr_die
, decl
);
19103 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
19105 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
19107 /* If this is an explicit function declaration then generate
19108 a DW_AT_explicit attribute. */
19109 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
19110 && (dwarf_version
>= 3 || !dwarf_strict
))
19111 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
19113 /* The first time we see a member function, it is in the context of
19114 the class to which it belongs. We make sure of this by emitting
19115 the class first. The next time is the definition, which is
19116 handled above. The two may come from the same source text.
19118 Note that force_decl_die() forces function declaration die. It is
19119 later reused to represent definition. */
19120 equate_decl_number_to_die (decl
, subr_die
);
19123 else if (DECL_ABSTRACT (decl
))
19125 if (DECL_DECLARED_INLINE_P (decl
))
19127 if (cgraph_function_possibly_inlined_p (decl
))
19128 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
19130 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
19134 if (cgraph_function_possibly_inlined_p (decl
))
19135 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
19137 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
19140 if (DECL_DECLARED_INLINE_P (decl
)
19141 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
19142 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
19144 equate_decl_number_to_die (decl
, subr_die
);
19146 else if (!DECL_EXTERNAL (decl
))
19148 HOST_WIDE_INT cfa_fb_offset
;
19150 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
19151 equate_decl_number_to_die (decl
, subr_die
);
19153 if (!flag_reorder_blocks_and_partition
)
19155 dw_fde_ref fde
= &fde_table
[current_funcdef_fde
];
19156 if (fde
->dw_fde_begin
)
19158 /* We have already generated the labels. */
19159 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, fde
->dw_fde_begin
);
19160 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, fde
->dw_fde_end
);
19164 /* Create start/end labels and add the range. */
19165 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
19166 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
19167 current_function_funcdef_no
);
19168 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
19169 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
19170 current_function_funcdef_no
);
19171 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
19174 #if VMS_DEBUGGING_INFO
19175 /* HP OpenVMS Industry Standard 64: DWARF Extensions
19176 Section 2.3 Prologue and Epilogue Attributes:
19177 When a breakpoint is set on entry to a function, it is generally
19178 desirable for execution to be suspended, not on the very first
19179 instruction of the function, but rather at a point after the
19180 function's frame has been set up, after any language defined local
19181 declaration processing has been completed, and before execution of
19182 the first statement of the function begins. Debuggers generally
19183 cannot properly determine where this point is. Similarly for a
19184 breakpoint set on exit from a function. The prologue and epilogue
19185 attributes allow a compiler to communicate the location(s) to use. */
19188 if (fde
->dw_fde_vms_end_prologue
)
19189 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
19190 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
19192 if (fde
->dw_fde_vms_begin_epilogue
)
19193 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
19194 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
19198 add_pubname (decl
, subr_die
);
19199 add_arange (decl
, subr_die
);
19202 { /* Generate pubnames entries for the split function code
19204 dw_fde_ref fde
= &fde_table
[current_funcdef_fde
];
19206 if (fde
->dw_fde_switched_sections
)
19208 if (dwarf_version
>= 3 || !dwarf_strict
)
19210 /* We should use ranges for non-contiguous code section
19211 addresses. Use the actual code range for the initial
19212 section, since the HOT/COLD labels might precede an
19213 alignment offset. */
19214 bool range_list_added
= false;
19215 if (fde
->in_std_section
)
19217 add_ranges_by_labels (subr_die
,
19220 &range_list_added
);
19221 add_ranges_by_labels (subr_die
,
19222 fde
->dw_fde_unlikely_section_label
,
19223 fde
->dw_fde_unlikely_section_end_label
,
19224 &range_list_added
);
19228 add_ranges_by_labels (subr_die
,
19231 &range_list_added
);
19232 add_ranges_by_labels (subr_die
,
19233 fde
->dw_fde_hot_section_label
,
19234 fde
->dw_fde_hot_section_end_label
,
19235 &range_list_added
);
19237 add_pubname (decl
, subr_die
);
19238 if (range_list_added
)
19243 /* There is no real support in DW2 for this .. so we make
19244 a work-around. First, emit the pub name for the segment
19245 containing the function label. Then make and emit a
19246 simplified subprogram DIE for the second segment with the
19247 name pre-fixed by __hot/cold_sect_of_. We use the same
19248 linkage name for the second die so that gdb will find both
19249 sections when given "b foo". */
19250 const char *name
= NULL
;
19251 tree decl_name
= DECL_NAME (decl
);
19252 dw_die_ref seg_die
;
19254 /* Do the 'primary' section. */
19255 add_AT_lbl_id (subr_die
, DW_AT_low_pc
,
19256 fde
->dw_fde_begin
);
19257 add_AT_lbl_id (subr_die
, DW_AT_high_pc
,
19260 add_pubname (decl
, subr_die
);
19261 add_arange (decl
, subr_die
);
19263 /* Build a minimal DIE for the secondary section. */
19264 seg_die
= new_die (DW_TAG_subprogram
,
19265 subr_die
->die_parent
, decl
);
19267 if (TREE_PUBLIC (decl
))
19268 add_AT_flag (seg_die
, DW_AT_external
, 1);
19270 if (decl_name
!= NULL
19271 && IDENTIFIER_POINTER (decl_name
) != NULL
)
19273 name
= dwarf2_name (decl
, 1);
19274 if (! DECL_ARTIFICIAL (decl
))
19275 add_src_coords_attributes (seg_die
, decl
);
19277 add_linkage_name (seg_die
, decl
);
19279 gcc_assert (name
!=NULL
);
19280 add_pure_or_virtual_attribute (seg_die
, decl
);
19281 if (DECL_ARTIFICIAL (decl
))
19282 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
19284 if (fde
->in_std_section
)
19286 name
= concat ("__cold_sect_of_", name
, NULL
);
19287 add_AT_lbl_id (seg_die
, DW_AT_low_pc
,
19288 fde
->dw_fde_unlikely_section_label
);
19289 add_AT_lbl_id (seg_die
, DW_AT_high_pc
,
19290 fde
->dw_fde_unlikely_section_end_label
);
19294 name
= concat ("__hot_sect_of_", name
, NULL
);
19295 add_AT_lbl_id (seg_die
, DW_AT_low_pc
,
19296 fde
->dw_fde_hot_section_label
);
19297 add_AT_lbl_id (seg_die
, DW_AT_high_pc
,
19298 fde
->dw_fde_hot_section_end_label
);
19300 add_name_attribute (seg_die
, name
);
19301 add_pubname_string (name
, seg_die
);
19302 add_arange (decl
, seg_die
);
19307 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, fde
->dw_fde_begin
);
19308 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, fde
->dw_fde_end
);
19309 add_pubname (decl
, subr_die
);
19310 add_arange (decl
, subr_die
);
19314 #ifdef MIPS_DEBUGGING_INFO
19315 /* Add a reference to the FDE for this routine. */
19316 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
19319 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
19321 /* We define the "frame base" as the function's CFA. This is more
19322 convenient for several reasons: (1) It's stable across the prologue
19323 and epilogue, which makes it better than just a frame pointer,
19324 (2) With dwarf3, there exists a one-byte encoding that allows us
19325 to reference the .debug_frame data by proxy, but failing that,
19326 (3) We can at least reuse the code inspection and interpretation
19327 code that determines the CFA position at various points in the
19329 if (dwarf_version
>= 3)
19331 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
19332 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
19336 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
19337 if (list
->dw_loc_next
)
19338 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
19340 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
19343 /* Compute a displacement from the "steady-state frame pointer" to
19344 the CFA. The former is what all stack slots and argument slots
19345 will reference in the rtl; the later is what we've told the
19346 debugger about. We'll need to adjust all frame_base references
19347 by this displacement. */
19348 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
19350 if (cfun
->static_chain_decl
)
19351 add_AT_location_description (subr_die
, DW_AT_static_link
,
19352 loc_list_from_tree (cfun
->static_chain_decl
, 2));
19355 /* Generate child dies for template paramaters. */
19356 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19357 gen_generic_params_dies (decl
);
19359 /* Now output descriptions of the arguments for this function. This gets
19360 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
19361 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
19362 `...' at the end of the formal parameter list. In order to find out if
19363 there was a trailing ellipsis or not, we must instead look at the type
19364 associated with the FUNCTION_DECL. This will be a node of type
19365 FUNCTION_TYPE. If the chain of type nodes hanging off of this
19366 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
19367 an ellipsis at the end. */
19369 /* In the case where we are describing a mere function declaration, all we
19370 need to do here (and all we *can* do here) is to describe the *types* of
19371 its formal parameters. */
19372 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19374 else if (declaration
)
19375 gen_formal_types_die (decl
, subr_die
);
19378 /* Generate DIEs to represent all known formal parameters. */
19379 tree parm
= DECL_ARGUMENTS (decl
);
19380 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
19381 tree generic_decl_parm
= generic_decl
19382 ? DECL_ARGUMENTS (generic_decl
)
19385 /* Now we want to walk the list of parameters of the function and
19386 emit their relevant DIEs.
19388 We consider the case of DECL being an instance of a generic function
19389 as well as it being a normal function.
19391 If DECL is an instance of a generic function we walk the
19392 parameters of the generic function declaration _and_ the parameters of
19393 DECL itself. This is useful because we want to emit specific DIEs for
19394 function parameter packs and those are declared as part of the
19395 generic function declaration. In that particular case,
19396 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
19397 That DIE has children DIEs representing the set of arguments
19398 of the pack. Note that the set of pack arguments can be empty.
19399 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
19402 Otherwise, we just consider the parameters of DECL. */
19403 while (generic_decl_parm
|| parm
)
19405 if (generic_decl_parm
19406 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
19407 gen_formal_parameter_pack_die (generic_decl_parm
,
19412 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
19414 if (parm
== DECL_ARGUMENTS (decl
)
19415 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
19417 && (dwarf_version
>= 3 || !dwarf_strict
))
19418 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
19420 parm
= DECL_CHAIN (parm
);
19423 if (generic_decl_parm
)
19424 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
19427 /* Decide whether we need an unspecified_parameters DIE at the end.
19428 There are 2 more cases to do this for: 1) the ansi ... declaration -
19429 this is detectable when the end of the arg list is not a
19430 void_type_node 2) an unprototyped function declaration (not a
19431 definition). This just means that we have no info about the
19432 parameters at all. */
19433 if (prototype_p (TREE_TYPE (decl
)))
19435 /* This is the prototyped case, check for.... */
19436 if (stdarg_p (TREE_TYPE (decl
)))
19437 gen_unspecified_parameters_die (decl
, subr_die
);
19439 else if (DECL_INITIAL (decl
) == NULL_TREE
)
19440 gen_unspecified_parameters_die (decl
, subr_die
);
19443 /* Output Dwarf info for all of the stuff within the body of the function
19444 (if it has one - it may be just a declaration). */
19445 outer_scope
= DECL_INITIAL (decl
);
19447 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
19448 a function. This BLOCK actually represents the outermost binding contour
19449 for the function, i.e. the contour in which the function's formal
19450 parameters and labels get declared. Curiously, it appears that the front
19451 end doesn't actually put the PARM_DECL nodes for the current function onto
19452 the BLOCK_VARS list for this outer scope, but are strung off of the
19453 DECL_ARGUMENTS list for the function instead.
19455 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
19456 the LABEL_DECL nodes for the function however, and we output DWARF info
19457 for those in decls_for_scope. Just within the `outer_scope' there will be
19458 a BLOCK node representing the function's outermost pair of curly braces,
19459 and any blocks used for the base and member initializers of a C++
19460 constructor function. */
19461 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
19463 int call_site_note_count
= 0;
19464 int tail_call_site_note_count
= 0;
19466 /* Emit a DW_TAG_variable DIE for a named return value. */
19467 if (DECL_NAME (DECL_RESULT (decl
)))
19468 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
19470 current_function_has_inlines
= 0;
19471 decls_for_scope (outer_scope
, subr_die
, 0);
19473 if (call_arg_locations
&& !dwarf_strict
)
19475 struct call_arg_loc_node
*ca_loc
;
19476 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
19478 dw_die_ref die
= NULL
;
19479 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
19482 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
19483 arg
; arg
= next_arg
)
19485 dw_loc_descr_ref reg
, val
;
19486 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
19489 next_arg
= XEXP (arg
, 1);
19490 if (REG_P (XEXP (XEXP (arg
, 0), 0))
19492 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
19493 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
19494 && REGNO (XEXP (XEXP (arg
, 0), 0))
19495 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
19496 next_arg
= XEXP (next_arg
, 1);
19497 if (mode
== VOIDmode
)
19499 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
19500 if (mode
== VOIDmode
)
19501 mode
= GET_MODE (XEXP (arg
, 0));
19503 if (GET_MODE_CLASS (mode
) != MODE_INT
19504 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
19506 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
19508 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
19509 tloc
= XEXP (XEXP (arg
, 0), 1);
19512 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
19513 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
19515 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
19516 tlocc
= XEXP (XEXP (arg
, 0), 1);
19519 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
19520 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
19521 VAR_INIT_STATUS_INITIALIZED
);
19522 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
19523 reg
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 0),
19525 VAR_INIT_STATUS_INITIALIZED
);
19530 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), VOIDmode
,
19531 VAR_INIT_STATUS_INITIALIZED
);
19535 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
19536 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
19538 add_AT_loc (cdie
, DW_AT_location
, reg
);
19539 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
19540 if (next_arg
!= XEXP (arg
, 1))
19542 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
19544 VAR_INIT_STATUS_INITIALIZED
);
19546 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
19550 && (ca_loc
->symbol_ref
|| tloc
))
19551 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
19552 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
19554 dw_loc_descr_ref tval
= NULL
;
19556 if (tloc
!= NULL_RTX
)
19557 tval
= mem_loc_descriptor (tloc
, VOIDmode
,
19558 VAR_INIT_STATUS_INITIALIZED
);
19560 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
19561 else if (tlocc
!= NULL_RTX
)
19563 tval
= mem_loc_descriptor (tlocc
, VOIDmode
,
19564 VAR_INIT_STATUS_INITIALIZED
);
19566 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
19572 call_site_note_count
++;
19573 if (ca_loc
->tail_call_p
)
19574 tail_call_site_note_count
++;
19578 call_arg_locations
= NULL
;
19579 call_arg_loc_last
= NULL
;
19580 if (tail_call_site_count
>= 0
19581 && tail_call_site_count
== tail_call_site_note_count
19584 if (call_site_count
>= 0
19585 && call_site_count
== call_site_note_count
)
19586 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
19588 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
19590 call_site_count
= -1;
19591 tail_call_site_count
= -1;
19593 /* Add the calling convention attribute if requested. */
19594 add_calling_convention_attribute (subr_die
, decl
);
19598 /* Returns a hash value for X (which really is a die_struct). */
19601 common_block_die_table_hash (const void *x
)
19603 const_dw_die_ref d
= (const_dw_die_ref
) x
;
19604 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
19607 /* Return nonzero if decl_id and die_parent of die_struct X is the same
19608 as decl_id and die_parent of die_struct Y. */
19611 common_block_die_table_eq (const void *x
, const void *y
)
19613 const_dw_die_ref d
= (const_dw_die_ref
) x
;
19614 const_dw_die_ref e
= (const_dw_die_ref
) y
;
19615 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
19618 /* Generate a DIE to represent a declared data object.
19619 Either DECL or ORIGIN must be non-null. */
19622 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
19626 tree decl_or_origin
= decl
? decl
: origin
;
19627 tree ultimate_origin
;
19628 dw_die_ref var_die
;
19629 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
19630 dw_die_ref origin_die
;
19631 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
19632 || class_or_namespace_scope_p (context_die
));
19633 bool specialization_p
= false;
19635 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
19636 if (decl
|| ultimate_origin
)
19637 origin
= ultimate_origin
;
19638 com_decl
= fortran_common (decl_or_origin
, &off
);
19640 /* Symbol in common gets emitted as a child of the common block, in the form
19641 of a data member. */
19644 dw_die_ref com_die
;
19645 dw_loc_list_ref loc
;
19646 die_node com_die_arg
;
19648 var_die
= lookup_decl_die (decl_or_origin
);
19651 if (get_AT (var_die
, DW_AT_location
) == NULL
)
19653 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
19658 /* Optimize the common case. */
19659 if (single_element_loc_list_p (loc
)
19660 && loc
->expr
->dw_loc_opc
== DW_OP_addr
19661 && loc
->expr
->dw_loc_next
== NULL
19662 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
19664 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
19665 = plus_constant (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
, off
);
19667 loc_list_plus_const (loc
, off
);
19669 add_AT_location_description (var_die
, DW_AT_location
, loc
);
19670 remove_AT (var_die
, DW_AT_declaration
);
19676 if (common_block_die_table
== NULL
)
19677 common_block_die_table
19678 = htab_create_ggc (10, common_block_die_table_hash
,
19679 common_block_die_table_eq
, NULL
);
19681 com_die_arg
.decl_id
= DECL_UID (com_decl
);
19682 com_die_arg
.die_parent
= context_die
;
19683 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
19684 loc
= loc_list_from_tree (com_decl
, 2);
19685 if (com_die
== NULL
)
19688 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
19691 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
19692 add_name_and_src_coords_attributes (com_die
, com_decl
);
19695 add_AT_location_description (com_die
, DW_AT_location
, loc
);
19696 /* Avoid sharing the same loc descriptor between
19697 DW_TAG_common_block and DW_TAG_variable. */
19698 loc
= loc_list_from_tree (com_decl
, 2);
19700 else if (DECL_EXTERNAL (decl
))
19701 add_AT_flag (com_die
, DW_AT_declaration
, 1);
19702 add_pubname_string (cnam
, com_die
); /* ??? needed? */
19703 com_die
->decl_id
= DECL_UID (com_decl
);
19704 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
19705 *slot
= (void *) com_die
;
19707 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
19709 add_AT_location_description (com_die
, DW_AT_location
, loc
);
19710 loc
= loc_list_from_tree (com_decl
, 2);
19711 remove_AT (com_die
, DW_AT_declaration
);
19713 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
19714 add_name_and_src_coords_attributes (var_die
, decl
);
19715 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
19716 TREE_THIS_VOLATILE (decl
), context_die
);
19717 add_AT_flag (var_die
, DW_AT_external
, 1);
19722 /* Optimize the common case. */
19723 if (single_element_loc_list_p (loc
)
19724 && loc
->expr
->dw_loc_opc
== DW_OP_addr
19725 && loc
->expr
->dw_loc_next
== NULL
19726 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
19727 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
19728 = plus_constant (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
, off
);
19730 loc_list_plus_const (loc
, off
);
19732 add_AT_location_description (var_die
, DW_AT_location
, loc
);
19734 else if (DECL_EXTERNAL (decl
))
19735 add_AT_flag (var_die
, DW_AT_declaration
, 1);
19736 equate_decl_number_to_die (decl
, var_die
);
19740 /* If the compiler emitted a definition for the DECL declaration
19741 and if we already emitted a DIE for it, don't emit a second
19742 DIE for it again. Allow re-declarations of DECLs that are
19743 inside functions, though. */
19744 if (old_die
&& declaration
&& !local_scope_p (context_die
))
19747 /* For static data members, the declaration in the class is supposed
19748 to have DW_TAG_member tag; the specification should still be
19749 DW_TAG_variable referencing the DW_TAG_member DIE. */
19750 if (declaration
&& class_scope_p (context_die
))
19751 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
19753 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
19756 if (origin
!= NULL
)
19757 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
19759 /* Loop unrolling can create multiple blocks that refer to the same
19760 static variable, so we must test for the DW_AT_declaration flag.
19762 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19763 copy decls and set the DECL_ABSTRACT flag on them instead of
19766 ??? Duplicated blocks have been rewritten to use .debug_ranges.
19768 ??? The declare_in_namespace support causes us to get two DIEs for one
19769 variable, both of which are declarations. We want to avoid considering
19770 one to be a specification, so we must test that this DIE is not a
19772 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
19773 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
19775 /* This is a definition of a C++ class level static. */
19776 add_AT_specification (var_die
, old_die
);
19777 specialization_p
= true;
19778 if (DECL_NAME (decl
))
19780 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
19781 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
19783 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
19784 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
19786 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
19787 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
19789 if (old_die
->die_tag
== DW_TAG_member
)
19790 add_linkage_name (var_die
, decl
);
19794 add_name_and_src_coords_attributes (var_die
, decl
);
19796 if ((origin
== NULL
&& !specialization_p
)
19798 && !DECL_ABSTRACT (decl_or_origin
)
19799 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
19800 decl_function_context
19801 (decl_or_origin
))))
19803 tree type
= TREE_TYPE (decl_or_origin
);
19805 if (decl_by_reference_p (decl_or_origin
))
19806 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
19808 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
19809 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
19812 if (origin
== NULL
&& !specialization_p
)
19814 if (TREE_PUBLIC (decl
))
19815 add_AT_flag (var_die
, DW_AT_external
, 1);
19817 if (DECL_ARTIFICIAL (decl
))
19818 add_AT_flag (var_die
, DW_AT_artificial
, 1);
19820 add_accessibility_attribute (var_die
, decl
);
19824 add_AT_flag (var_die
, DW_AT_declaration
, 1);
19826 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
19827 equate_decl_number_to_die (decl
, var_die
);
19830 && (! DECL_ABSTRACT (decl_or_origin
)
19831 /* Local static vars are shared between all clones/inlines,
19832 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19834 || (TREE_CODE (decl_or_origin
) == VAR_DECL
19835 && TREE_STATIC (decl_or_origin
)
19836 && DECL_RTL_SET_P (decl_or_origin
)))
19837 /* When abstract origin already has DW_AT_location attribute, no need
19838 to add it again. */
19839 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
19841 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
19842 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
19843 defer_location (decl_or_origin
, var_die
);
19845 add_location_or_const_value_attribute (var_die
,
19848 add_pubname (decl_or_origin
, var_die
);
19851 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
19854 /* Generate a DIE to represent a named constant. */
19857 gen_const_die (tree decl
, dw_die_ref context_die
)
19859 dw_die_ref const_die
;
19860 tree type
= TREE_TYPE (decl
);
19862 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
19863 add_name_and_src_coords_attributes (const_die
, decl
);
19864 add_type_attribute (const_die
, type
, 1, 0, context_die
);
19865 if (TREE_PUBLIC (decl
))
19866 add_AT_flag (const_die
, DW_AT_external
, 1);
19867 if (DECL_ARTIFICIAL (decl
))
19868 add_AT_flag (const_die
, DW_AT_artificial
, 1);
19869 tree_add_const_value_attribute_for_decl (const_die
, decl
);
19872 /* Generate a DIE to represent a label identifier. */
19875 gen_label_die (tree decl
, dw_die_ref context_die
)
19877 tree origin
= decl_ultimate_origin (decl
);
19878 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
19880 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19882 if (origin
!= NULL
)
19883 add_abstract_origin_attribute (lbl_die
, origin
);
19885 add_name_and_src_coords_attributes (lbl_die
, decl
);
19887 if (DECL_ABSTRACT (decl
))
19888 equate_decl_number_to_die (decl
, lbl_die
);
19891 insn
= DECL_RTL_IF_SET (decl
);
19893 /* Deleted labels are programmer specified labels which have been
19894 eliminated because of various optimizations. We still emit them
19895 here so that it is possible to put breakpoints on them. */
19899 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
19901 /* When optimization is enabled (via -O) some parts of the compiler
19902 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19903 represent source-level labels which were explicitly declared by
19904 the user. This really shouldn't be happening though, so catch
19905 it if it ever does happen. */
19906 gcc_assert (!INSN_DELETED_P (insn
));
19908 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
19909 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19914 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19915 attributes to the DIE for a block STMT, to describe where the inlined
19916 function was called from. This is similar to add_src_coords_attributes. */
19919 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
19921 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
19923 if (dwarf_version
>= 3 || !dwarf_strict
)
19925 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
19926 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
19931 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19932 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19935 add_high_low_attributes (tree stmt
, dw_die_ref die
)
19937 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19939 if (BLOCK_FRAGMENT_CHAIN (stmt
)
19940 && (dwarf_version
>= 3 || !dwarf_strict
))
19944 if (inlined_function_outer_scope_p (stmt
))
19946 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19947 BLOCK_NUMBER (stmt
));
19948 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
19951 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
));
19953 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19956 add_ranges (chain
);
19957 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
19964 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19965 BLOCK_NUMBER (stmt
));
19966 add_AT_lbl_id (die
, DW_AT_low_pc
, label
);
19967 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
19968 BLOCK_NUMBER (stmt
));
19969 add_AT_lbl_id (die
, DW_AT_high_pc
, label
);
19973 /* Generate a DIE for a lexical block. */
19976 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19978 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
19980 if (call_arg_locations
)
19982 if (VEC_length (dw_die_ref
, block_map
) <= BLOCK_NUMBER (stmt
))
19983 VEC_safe_grow_cleared (dw_die_ref
, heap
, block_map
,
19984 BLOCK_NUMBER (stmt
) + 1);
19985 VEC_replace (dw_die_ref
, block_map
, BLOCK_NUMBER (stmt
), stmt_die
);
19988 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
19989 add_high_low_attributes (stmt
, stmt_die
);
19991 decls_for_scope (stmt
, stmt_die
, depth
);
19994 /* Generate a DIE for an inlined subprogram. */
19997 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
20001 /* The instance of function that is effectively being inlined shall not
20003 gcc_assert (! BLOCK_ABSTRACT (stmt
));
20005 decl
= block_ultimate_origin (stmt
);
20007 /* Emit info for the abstract instance first, if we haven't yet. We
20008 must emit this even if the block is abstract, otherwise when we
20009 emit the block below (or elsewhere), we may end up trying to emit
20010 a die whose origin die hasn't been emitted, and crashing. */
20011 dwarf2out_abstract_function (decl
);
20013 if (! BLOCK_ABSTRACT (stmt
))
20015 dw_die_ref subr_die
20016 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
20018 if (call_arg_locations
)
20020 if (VEC_length (dw_die_ref
, block_map
) <= BLOCK_NUMBER (stmt
))
20021 VEC_safe_grow_cleared (dw_die_ref
, heap
, block_map
,
20022 BLOCK_NUMBER (stmt
) + 1);
20023 VEC_replace (dw_die_ref
, block_map
, BLOCK_NUMBER (stmt
), subr_die
);
20025 add_abstract_origin_attribute (subr_die
, decl
);
20026 if (TREE_ASM_WRITTEN (stmt
))
20027 add_high_low_attributes (stmt
, subr_die
);
20028 add_call_src_coords_attributes (stmt
, subr_die
);
20030 decls_for_scope (stmt
, subr_die
, depth
);
20031 current_function_has_inlines
= 1;
20035 /* Generate a DIE for a field in a record, or structure. */
20038 gen_field_die (tree decl
, dw_die_ref context_die
)
20040 dw_die_ref decl_die
;
20042 if (TREE_TYPE (decl
) == error_mark_node
)
20045 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
20046 add_name_and_src_coords_attributes (decl_die
, decl
);
20047 add_type_attribute (decl_die
, member_declared_type (decl
),
20048 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
20051 if (DECL_BIT_FIELD_TYPE (decl
))
20053 add_byte_size_attribute (decl_die
, decl
);
20054 add_bit_size_attribute (decl_die
, decl
);
20055 add_bit_offset_attribute (decl_die
, decl
);
20058 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
20059 add_data_member_location_attribute (decl_die
, decl
);
20061 if (DECL_ARTIFICIAL (decl
))
20062 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
20064 add_accessibility_attribute (decl_die
, decl
);
20066 /* Equate decl number to die, so that we can look up this decl later on. */
20067 equate_decl_number_to_die (decl
, decl_die
);
20071 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20072 Use modified_type_die instead.
20073 We keep this code here just in case these types of DIEs may be needed to
20074 represent certain things in other languages (e.g. Pascal) someday. */
20077 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
20080 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
20082 equate_type_number_to_die (type
, ptr_die
);
20083 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
20084 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
20087 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20088 Use modified_type_die instead.
20089 We keep this code here just in case these types of DIEs may be needed to
20090 represent certain things in other languages (e.g. Pascal) someday. */
20093 gen_reference_type_die (tree type
, dw_die_ref context_die
)
20095 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
20097 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
20098 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
20100 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
20102 equate_type_number_to_die (type
, ref_die
);
20103 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
20104 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
20108 /* Generate a DIE for a pointer to a member type. */
20111 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
20114 = new_die (DW_TAG_ptr_to_member_type
,
20115 scope_die_for (type
, context_die
), type
);
20117 equate_type_number_to_die (type
, ptr_die
);
20118 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
20119 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
20120 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
20123 /* Generate the DIE for the compilation unit. */
20126 gen_compile_unit_die (const char *filename
)
20129 char producer
[250];
20130 const char *language_string
= lang_hooks
.name
;
20133 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
20137 add_name_attribute (die
, filename
);
20138 /* Don't add cwd for <built-in>. */
20139 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
20140 add_comp_dir_attribute (die
);
20143 sprintf (producer
, "%s %s", language_string
, version_string
);
20145 #ifdef MIPS_DEBUGGING_INFO
20146 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
20147 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
20148 not appear in the producer string, the debugger reaches the conclusion
20149 that the object file is stripped and has no debugging information.
20150 To get the MIPS/SGI debugger to believe that there is debugging
20151 information in the object file, we add a -g to the producer string. */
20152 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20153 strcat (producer
, " -g");
20156 add_AT_string (die
, DW_AT_producer
, producer
);
20158 /* If our producer is LTO try to figure out a common language to use
20159 from the global list of translation units. */
20160 if (strcmp (language_string
, "GNU GIMPLE") == 0)
20164 const char *common_lang
= NULL
;
20166 FOR_EACH_VEC_ELT (tree
, all_translation_units
, i
, t
)
20168 if (!TRANSLATION_UNIT_LANGUAGE (t
))
20171 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
20172 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
20174 else if (strncmp (common_lang
, "GNU C", 5) == 0
20175 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
20176 /* Mixing C and C++ is ok, use C++ in that case. */
20177 common_lang
= "GNU C++";
20180 /* Fall back to C. */
20181 common_lang
= NULL
;
20187 language_string
= common_lang
;
20190 language
= DW_LANG_C89
;
20191 if (strcmp (language_string
, "GNU C++") == 0)
20192 language
= DW_LANG_C_plus_plus
;
20193 else if (strcmp (language_string
, "GNU F77") == 0)
20194 language
= DW_LANG_Fortran77
;
20195 else if (strcmp (language_string
, "GNU Pascal") == 0)
20196 language
= DW_LANG_Pascal83
;
20197 else if (dwarf_version
>= 3 || !dwarf_strict
)
20199 if (strcmp (language_string
, "GNU Ada") == 0)
20200 language
= DW_LANG_Ada95
;
20201 else if (strcmp (language_string
, "GNU Fortran") == 0)
20202 language
= DW_LANG_Fortran95
;
20203 else if (strcmp (language_string
, "GNU Java") == 0)
20204 language
= DW_LANG_Java
;
20205 else if (strcmp (language_string
, "GNU Objective-C") == 0)
20206 language
= DW_LANG_ObjC
;
20207 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
20208 language
= DW_LANG_ObjC_plus_plus
;
20211 add_AT_unsigned (die
, DW_AT_language
, language
);
20215 case DW_LANG_Fortran77
:
20216 case DW_LANG_Fortran90
:
20217 case DW_LANG_Fortran95
:
20218 /* Fortran has case insensitive identifiers and the front-end
20219 lowercases everything. */
20220 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
20223 /* The default DW_ID_case_sensitive doesn't need to be specified. */
20229 /* Generate the DIE for a base class. */
20232 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
20234 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
20236 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
20237 add_data_member_location_attribute (die
, binfo
);
20239 if (BINFO_VIRTUAL_P (binfo
))
20240 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
20242 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
20243 children, otherwise the default is DW_ACCESS_public. In DWARF2
20244 the default has always been DW_ACCESS_private. */
20245 if (access
== access_public_node
)
20247 if (dwarf_version
== 2
20248 || context_die
->die_tag
== DW_TAG_class_type
)
20249 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
20251 else if (access
== access_protected_node
)
20252 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
20253 else if (dwarf_version
> 2
20254 && context_die
->die_tag
!= DW_TAG_class_type
)
20255 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
20258 /* Generate a DIE for a class member. */
20261 gen_member_die (tree type
, dw_die_ref context_die
)
20264 tree binfo
= TYPE_BINFO (type
);
20267 /* If this is not an incomplete type, output descriptions of each of its
20268 members. Note that as we output the DIEs necessary to represent the
20269 members of this record or union type, we will also be trying to output
20270 DIEs to represent the *types* of those members. However the `type'
20271 function (above) will specifically avoid generating type DIEs for member
20272 types *within* the list of member DIEs for this (containing) type except
20273 for those types (of members) which are explicitly marked as also being
20274 members of this (containing) type themselves. The g++ front- end can
20275 force any given type to be treated as a member of some other (containing)
20276 type by setting the TYPE_CONTEXT of the given (member) type to point to
20277 the TREE node representing the appropriate (containing) type. */
20279 /* First output info about the base classes. */
20282 VEC(tree
,gc
) *accesses
= BINFO_BASE_ACCESSES (binfo
);
20286 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
20287 gen_inheritance_die (base
,
20288 (accesses
? VEC_index (tree
, accesses
, i
)
20289 : access_public_node
), context_die
);
20292 /* Now output info about the data members and type members. */
20293 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
20295 /* If we thought we were generating minimal debug info for TYPE
20296 and then changed our minds, some of the member declarations
20297 may have already been defined. Don't define them again, but
20298 do put them in the right order. */
20300 child
= lookup_decl_die (member
);
20302 splice_child_die (context_die
, child
);
20304 gen_decl_die (member
, NULL
, context_die
);
20307 /* Now output info about the function members (if any). */
20308 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
20310 /* Don't include clones in the member list. */
20311 if (DECL_ABSTRACT_ORIGIN (member
))
20314 child
= lookup_decl_die (member
);
20316 splice_child_die (context_die
, child
);
20318 gen_decl_die (member
, NULL
, context_die
);
20322 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
20323 is set, we pretend that the type was never defined, so we only get the
20324 member DIEs needed by later specification DIEs. */
20327 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
20328 enum debug_info_usage usage
)
20330 dw_die_ref type_die
= lookup_type_die (type
);
20331 dw_die_ref scope_die
= 0;
20333 int complete
= (TYPE_SIZE (type
)
20334 && (! TYPE_STUB_DECL (type
)
20335 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
20336 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
20337 complete
= complete
&& should_emit_struct_debug (type
, usage
);
20339 if (type_die
&& ! complete
)
20342 if (TYPE_CONTEXT (type
) != NULL_TREE
20343 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
20344 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
20347 scope_die
= scope_die_for (type
, context_die
);
20349 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
20350 /* First occurrence of type or toplevel definition of nested class. */
20352 dw_die_ref old_die
= type_die
;
20354 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
20355 ? record_type_tag (type
) : DW_TAG_union_type
,
20357 equate_type_number_to_die (type
, type_die
);
20359 add_AT_specification (type_die
, old_die
);
20361 add_name_attribute (type_die
, type_tag (type
));
20364 remove_AT (type_die
, DW_AT_declaration
);
20366 /* Generate child dies for template paramaters. */
20367 if (debug_info_level
> DINFO_LEVEL_TERSE
20368 && COMPLETE_TYPE_P (type
))
20369 schedule_generic_params_dies_gen (type
);
20371 /* If this type has been completed, then give it a byte_size attribute and
20372 then give a list of members. */
20373 if (complete
&& !ns_decl
)
20375 /* Prevent infinite recursion in cases where the type of some member of
20376 this type is expressed in terms of this type itself. */
20377 TREE_ASM_WRITTEN (type
) = 1;
20378 add_byte_size_attribute (type_die
, type
);
20379 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
20381 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
20382 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
20385 /* If the first reference to this type was as the return type of an
20386 inline function, then it may not have a parent. Fix this now. */
20387 if (type_die
->die_parent
== NULL
)
20388 add_child_die (scope_die
, type_die
);
20390 push_decl_scope (type
);
20391 gen_member_die (type
, type_die
);
20394 /* GNU extension: Record what type our vtable lives in. */
20395 if (TYPE_VFIELD (type
))
20397 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
20399 gen_type_die (vtype
, context_die
);
20400 add_AT_die_ref (type_die
, DW_AT_containing_type
,
20401 lookup_type_die (vtype
));
20406 add_AT_flag (type_die
, DW_AT_declaration
, 1);
20408 /* We don't need to do this for function-local types. */
20409 if (TYPE_STUB_DECL (type
)
20410 && ! decl_function_context (TYPE_STUB_DECL (type
)))
20411 VEC_safe_push (tree
, gc
, incomplete_types
, type
);
20414 if (get_AT (type_die
, DW_AT_name
))
20415 add_pubtype (type
, type_die
);
20418 /* Generate a DIE for a subroutine _type_. */
20421 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
20423 tree return_type
= TREE_TYPE (type
);
20424 dw_die_ref subr_die
20425 = new_die (DW_TAG_subroutine_type
,
20426 scope_die_for (type
, context_die
), type
);
20428 equate_type_number_to_die (type
, subr_die
);
20429 add_prototyped_attribute (subr_die
, type
);
20430 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
20431 gen_formal_types_die (type
, subr_die
);
20433 if (get_AT (subr_die
, DW_AT_name
))
20434 add_pubtype (type
, subr_die
);
20437 /* Generate a DIE for a type definition. */
20440 gen_typedef_die (tree decl
, dw_die_ref context_die
)
20442 dw_die_ref type_die
;
20445 if (TREE_ASM_WRITTEN (decl
))
20448 TREE_ASM_WRITTEN (decl
) = 1;
20449 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
20450 origin
= decl_ultimate_origin (decl
);
20451 if (origin
!= NULL
)
20452 add_abstract_origin_attribute (type_die
, origin
);
20457 add_name_and_src_coords_attributes (type_die
, decl
);
20458 if (DECL_ORIGINAL_TYPE (decl
))
20460 type
= DECL_ORIGINAL_TYPE (decl
);
20462 gcc_assert (type
!= TREE_TYPE (decl
));
20463 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
20467 type
= TREE_TYPE (decl
);
20469 if (is_naming_typedef_decl (TYPE_NAME (type
)))
20471 /* Here, we are in the case of decl being a typedef naming
20472 an anonymous type, e.g:
20473 typedef struct {...} foo;
20474 In that case TREE_TYPE (decl) is not a typedef variant
20475 type and TYPE_NAME of the anonymous type is set to the
20476 TYPE_DECL of the typedef. This construct is emitted by
20479 TYPE is the anonymous struct named by the typedef
20480 DECL. As we need the DW_AT_type attribute of the
20481 DW_TAG_typedef to point to the DIE of TYPE, let's
20482 generate that DIE right away. add_type_attribute
20483 called below will then pick (via lookup_type_die) that
20484 anonymous struct DIE. */
20485 if (!TREE_ASM_WRITTEN (type
))
20486 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
20488 /* This is a GNU Extension. We are adding a
20489 DW_AT_linkage_name attribute to the DIE of the
20490 anonymous struct TYPE. The value of that attribute
20491 is the name of the typedef decl naming the anonymous
20492 struct. This greatly eases the work of consumers of
20493 this debug info. */
20494 add_linkage_attr (lookup_type_die (type
), decl
);
20498 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
20499 TREE_THIS_VOLATILE (decl
), context_die
);
20501 if (is_naming_typedef_decl (decl
))
20502 /* We want that all subsequent calls to lookup_type_die with
20503 TYPE in argument yield the DW_TAG_typedef we have just
20505 equate_type_number_to_die (type
, type_die
);
20507 add_accessibility_attribute (type_die
, decl
);
20510 if (DECL_ABSTRACT (decl
))
20511 equate_decl_number_to_die (decl
, type_die
);
20513 if (get_AT (type_die
, DW_AT_name
))
20514 add_pubtype (decl
, type_die
);
20517 /* Generate a DIE for a struct, class, enum or union type. */
20520 gen_tagged_type_die (tree type
,
20521 dw_die_ref context_die
,
20522 enum debug_info_usage usage
)
20526 if (type
== NULL_TREE
20527 || !is_tagged_type (type
))
20530 /* If this is a nested type whose containing class hasn't been written
20531 out yet, writing it out will cover this one, too. This does not apply
20532 to instantiations of member class templates; they need to be added to
20533 the containing class as they are generated. FIXME: This hurts the
20534 idea of combining type decls from multiple TUs, since we can't predict
20535 what set of template instantiations we'll get. */
20536 if (TYPE_CONTEXT (type
)
20537 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
20538 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
20540 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
20542 if (TREE_ASM_WRITTEN (type
))
20545 /* If that failed, attach ourselves to the stub. */
20546 push_decl_scope (TYPE_CONTEXT (type
));
20547 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
20550 else if (TYPE_CONTEXT (type
) != NULL_TREE
20551 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
20553 /* If this type is local to a function that hasn't been written
20554 out yet, use a NULL context for now; it will be fixed up in
20555 decls_for_scope. */
20556 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
20557 /* A declaration DIE doesn't count; nested types need to go in the
20559 if (context_die
&& is_declaration_die (context_die
))
20560 context_die
= NULL
;
20565 context_die
= declare_in_namespace (type
, context_die
);
20569 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
20571 /* This might have been written out by the call to
20572 declare_in_namespace. */
20573 if (!TREE_ASM_WRITTEN (type
))
20574 gen_enumeration_type_die (type
, context_die
);
20577 gen_struct_or_union_type_die (type
, context_die
, usage
);
20582 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
20583 it up if it is ever completed. gen_*_type_die will set it for us
20584 when appropriate. */
20587 /* Generate a type description DIE. */
20590 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
20591 enum debug_info_usage usage
)
20593 struct array_descr_info info
;
20595 if (type
== NULL_TREE
|| type
== error_mark_node
)
20598 if (TYPE_NAME (type
) != NULL_TREE
20599 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
20600 && is_redundant_typedef (TYPE_NAME (type
))
20601 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
20602 /* The DECL of this type is a typedef we don't want to emit debug
20603 info for but we want debug info for its underlying typedef.
20604 This can happen for e.g, the injected-class-name of a C++
20606 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
20608 /* If TYPE is a typedef type variant, let's generate debug info
20609 for the parent typedef which TYPE is a type of. */
20610 if (typedef_variant_p (type
))
20612 if (TREE_ASM_WRITTEN (type
))
20615 /* Prevent broken recursion; we can't hand off to the same type. */
20616 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
20618 /* Use the DIE of the containing namespace as the parent DIE of
20619 the type description DIE we want to generate. */
20620 if (DECL_CONTEXT (TYPE_NAME (type
))
20621 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
20622 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
20624 TREE_ASM_WRITTEN (type
) = 1;
20626 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
20630 /* If type is an anonymous tagged type named by a typedef, let's
20631 generate debug info for the typedef. */
20632 if (is_naming_typedef_decl (TYPE_NAME (type
)))
20634 /* Use the DIE of the containing namespace as the parent DIE of
20635 the type description DIE we want to generate. */
20636 if (DECL_CONTEXT (TYPE_NAME (type
))
20637 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
20638 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
20640 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
20644 /* If this is an array type with hidden descriptor, handle it first. */
20645 if (!TREE_ASM_WRITTEN (type
)
20646 && lang_hooks
.types
.get_array_descr_info
20647 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
20648 && (dwarf_version
>= 3 || !dwarf_strict
))
20650 gen_descr_array_type_die (type
, &info
, context_die
);
20651 TREE_ASM_WRITTEN (type
) = 1;
20655 /* We are going to output a DIE to represent the unqualified version
20656 of this type (i.e. without any const or volatile qualifiers) so
20657 get the main variant (i.e. the unqualified version) of this type
20658 now. (Vectors are special because the debugging info is in the
20659 cloned type itself). */
20660 if (TREE_CODE (type
) != VECTOR_TYPE
)
20661 type
= type_main_variant (type
);
20663 if (TREE_ASM_WRITTEN (type
))
20666 switch (TREE_CODE (type
))
20672 case REFERENCE_TYPE
:
20673 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
20674 ensures that the gen_type_die recursion will terminate even if the
20675 type is recursive. Recursive types are possible in Ada. */
20676 /* ??? We could perhaps do this for all types before the switch
20678 TREE_ASM_WRITTEN (type
) = 1;
20680 /* For these types, all that is required is that we output a DIE (or a
20681 set of DIEs) to represent the "basis" type. */
20682 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20683 DINFO_USAGE_IND_USE
);
20687 /* This code is used for C++ pointer-to-data-member types.
20688 Output a description of the relevant class type. */
20689 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
20690 DINFO_USAGE_IND_USE
);
20692 /* Output a description of the type of the object pointed to. */
20693 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20694 DINFO_USAGE_IND_USE
);
20696 /* Now output a DIE to represent this pointer-to-data-member type
20698 gen_ptr_to_mbr_type_die (type
, context_die
);
20701 case FUNCTION_TYPE
:
20702 /* Force out return type (in case it wasn't forced out already). */
20703 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20704 DINFO_USAGE_DIR_USE
);
20705 gen_subroutine_type_die (type
, context_die
);
20709 /* Force out return type (in case it wasn't forced out already). */
20710 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20711 DINFO_USAGE_DIR_USE
);
20712 gen_subroutine_type_die (type
, context_die
);
20716 gen_array_type_die (type
, context_die
);
20720 gen_array_type_die (type
, context_die
);
20723 case ENUMERAL_TYPE
:
20726 case QUAL_UNION_TYPE
:
20727 gen_tagged_type_die (type
, context_die
, usage
);
20733 case FIXED_POINT_TYPE
:
20736 /* No DIEs needed for fundamental types. */
20741 /* Just use DW_TAG_unspecified_type. */
20743 dw_die_ref type_die
= lookup_type_die (type
);
20744 if (type_die
== NULL
)
20746 tree name
= TYPE_NAME (type
);
20747 if (TREE_CODE (name
) == TYPE_DECL
)
20748 name
= DECL_NAME (name
);
20749 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
20750 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
20751 equate_type_number_to_die (type
, type_die
);
20757 gcc_unreachable ();
20760 TREE_ASM_WRITTEN (type
) = 1;
20764 gen_type_die (tree type
, dw_die_ref context_die
)
20766 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
20769 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20770 things which are local to the given block. */
20773 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
20775 int must_output_die
= 0;
20778 /* Ignore blocks that are NULL. */
20779 if (stmt
== NULL_TREE
)
20782 inlined_func
= inlined_function_outer_scope_p (stmt
);
20784 /* If the block is one fragment of a non-contiguous block, do not
20785 process the variables, since they will have been done by the
20786 origin block. Do process subblocks. */
20787 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
20791 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
20792 gen_block_die (sub
, context_die
, depth
+ 1);
20797 /* Determine if we need to output any Dwarf DIEs at all to represent this
20800 /* The outer scopes for inlinings *must* always be represented. We
20801 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20802 must_output_die
= 1;
20805 /* Determine if this block directly contains any "significant"
20806 local declarations which we will need to output DIEs for. */
20807 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20808 /* We are not in terse mode so *any* local declaration counts
20809 as being a "significant" one. */
20810 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
20811 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
20812 && (TREE_USED (stmt
)
20813 || TREE_ASM_WRITTEN (stmt
)
20814 || BLOCK_ABSTRACT (stmt
)));
20815 else if ((TREE_USED (stmt
)
20816 || TREE_ASM_WRITTEN (stmt
)
20817 || BLOCK_ABSTRACT (stmt
))
20818 && !dwarf2out_ignore_block (stmt
))
20819 must_output_die
= 1;
20822 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20823 DIE for any block which contains no significant local declarations at
20824 all. Rather, in such cases we just call `decls_for_scope' so that any
20825 needed Dwarf info for any sub-blocks will get properly generated. Note
20826 that in terse mode, our definition of what constitutes a "significant"
20827 local declaration gets restricted to include only inlined function
20828 instances and local (nested) function definitions. */
20829 if (must_output_die
)
20833 /* If STMT block is abstract, that means we have been called
20834 indirectly from dwarf2out_abstract_function.
20835 That function rightfully marks the descendent blocks (of
20836 the abstract function it is dealing with) as being abstract,
20837 precisely to prevent us from emitting any
20838 DW_TAG_inlined_subroutine DIE as a descendent
20839 of an abstract function instance. So in that case, we should
20840 not call gen_inlined_subroutine_die.
20842 Later though, when cgraph asks dwarf2out to emit info
20843 for the concrete instance of the function decl into which
20844 the concrete instance of STMT got inlined, the later will lead
20845 to the generation of a DW_TAG_inlined_subroutine DIE. */
20846 if (! BLOCK_ABSTRACT (stmt
))
20847 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
20850 gen_lexical_block_die (stmt
, context_die
, depth
);
20853 decls_for_scope (stmt
, context_die
, depth
);
20856 /* Process variable DECL (or variable with origin ORIGIN) within
20857 block STMT and add it to CONTEXT_DIE. */
20859 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
20862 tree decl_or_origin
= decl
? decl
: origin
;
20864 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
20865 die
= lookup_decl_die (decl_or_origin
);
20866 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
20867 && TYPE_DECL_IS_STUB (decl_or_origin
))
20868 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
20872 if (die
!= NULL
&& die
->die_parent
== NULL
)
20873 add_child_die (context_die
, die
);
20874 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
20875 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
20876 stmt
, context_die
);
20878 gen_decl_die (decl
, origin
, context_die
);
20881 /* Generate all of the decls declared within a given scope and (recursively)
20882 all of its sub-blocks. */
20885 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
20891 /* Ignore NULL blocks. */
20892 if (stmt
== NULL_TREE
)
20895 /* Output the DIEs to represent all of the data objects and typedefs
20896 declared directly within this block but not within any nested
20897 sub-blocks. Also, nested function and tag DIEs have been
20898 generated with a parent of NULL; fix that up now. */
20899 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
20900 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
20901 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
20902 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
20905 /* If we're at -g1, we're not interested in subblocks. */
20906 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20909 /* Output the DIEs to represent all sub-blocks (and the items declared
20910 therein) of this block. */
20911 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
20913 subblocks
= BLOCK_CHAIN (subblocks
))
20914 gen_block_die (subblocks
, context_die
, depth
+ 1);
20917 /* Is this a typedef we can avoid emitting? */
20920 is_redundant_typedef (const_tree decl
)
20922 if (TYPE_DECL_IS_STUB (decl
))
20925 if (DECL_ARTIFICIAL (decl
)
20926 && DECL_CONTEXT (decl
)
20927 && is_tagged_type (DECL_CONTEXT (decl
))
20928 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
20929 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
20930 /* Also ignore the artificial member typedef for the class name. */
20936 /* Return TRUE if TYPE is a typedef that names a type for linkage
20937 purposes. This kind of typedefs is produced by the C++ FE for
20940 typedef struct {...} foo;
20942 In that case, there is no typedef variant type produced for foo.
20943 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20947 is_naming_typedef_decl (const_tree decl
)
20949 if (decl
== NULL_TREE
20950 || TREE_CODE (decl
) != TYPE_DECL
20951 || !is_tagged_type (TREE_TYPE (decl
))
20952 || DECL_IS_BUILTIN (decl
)
20953 || is_redundant_typedef (decl
)
20954 /* It looks like Ada produces TYPE_DECLs that are very similar
20955 to C++ naming typedefs but that have different
20956 semantics. Let's be specific to c++ for now. */
20960 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
20961 && TYPE_NAME (TREE_TYPE (decl
)) == decl
20962 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
20963 != TYPE_NAME (TREE_TYPE (decl
))));
20966 /* Returns the DIE for a context. */
20968 static inline dw_die_ref
20969 get_context_die (tree context
)
20973 /* Find die that represents this context. */
20974 if (TYPE_P (context
))
20976 context
= TYPE_MAIN_VARIANT (context
);
20977 return strip_naming_typedef (context
, force_type_die (context
));
20980 return force_decl_die (context
);
20982 return comp_unit_die ();
20985 /* Returns the DIE for decl. A DIE will always be returned. */
20988 force_decl_die (tree decl
)
20990 dw_die_ref decl_die
;
20991 unsigned saved_external_flag
;
20992 tree save_fn
= NULL_TREE
;
20993 decl_die
= lookup_decl_die (decl
);
20996 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
20998 decl_die
= lookup_decl_die (decl
);
21002 switch (TREE_CODE (decl
))
21004 case FUNCTION_DECL
:
21005 /* Clear current_function_decl, so that gen_subprogram_die thinks
21006 that this is a declaration. At this point, we just want to force
21007 declaration die. */
21008 save_fn
= current_function_decl
;
21009 current_function_decl
= NULL_TREE
;
21010 gen_subprogram_die (decl
, context_die
);
21011 current_function_decl
= save_fn
;
21015 /* Set external flag to force declaration die. Restore it after
21016 gen_decl_die() call. */
21017 saved_external_flag
= DECL_EXTERNAL (decl
);
21018 DECL_EXTERNAL (decl
) = 1;
21019 gen_decl_die (decl
, NULL
, context_die
);
21020 DECL_EXTERNAL (decl
) = saved_external_flag
;
21023 case NAMESPACE_DECL
:
21024 if (dwarf_version
>= 3 || !dwarf_strict
)
21025 dwarf2out_decl (decl
);
21027 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
21028 decl_die
= comp_unit_die ();
21031 case TRANSLATION_UNIT_DECL
:
21032 decl_die
= comp_unit_die ();
21036 gcc_unreachable ();
21039 /* We should be able to find the DIE now. */
21041 decl_die
= lookup_decl_die (decl
);
21042 gcc_assert (decl_die
);
21048 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
21049 always returned. */
21052 force_type_die (tree type
)
21054 dw_die_ref type_die
;
21056 type_die
= lookup_type_die (type
);
21059 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
21061 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
21062 TYPE_VOLATILE (type
), context_die
);
21063 gcc_assert (type_die
);
21068 /* Force out any required namespaces to be able to output DECL,
21069 and return the new context_die for it, if it's changed. */
21072 setup_namespace_context (tree thing
, dw_die_ref context_die
)
21074 tree context
= (DECL_P (thing
)
21075 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
21076 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
21077 /* Force out the namespace. */
21078 context_die
= force_decl_die (context
);
21080 return context_die
;
21083 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
21084 type) within its namespace, if appropriate.
21086 For compatibility with older debuggers, namespace DIEs only contain
21087 declarations; all definitions are emitted at CU scope. */
21090 declare_in_namespace (tree thing
, dw_die_ref context_die
)
21092 dw_die_ref ns_context
;
21094 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21095 return context_die
;
21097 /* If this decl is from an inlined function, then don't try to emit it in its
21098 namespace, as we will get confused. It would have already been emitted
21099 when the abstract instance of the inline function was emitted anyways. */
21100 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
21101 return context_die
;
21103 ns_context
= setup_namespace_context (thing
, context_die
);
21105 if (ns_context
!= context_die
)
21109 if (DECL_P (thing
))
21110 gen_decl_die (thing
, NULL
, ns_context
);
21112 gen_type_die (thing
, ns_context
);
21114 return context_die
;
21117 /* Generate a DIE for a namespace or namespace alias. */
21120 gen_namespace_die (tree decl
, dw_die_ref context_die
)
21122 dw_die_ref namespace_die
;
21124 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
21125 they are an alias of. */
21126 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
21128 /* Output a real namespace or module. */
21129 context_die
= setup_namespace_context (decl
, comp_unit_die ());
21130 namespace_die
= new_die (is_fortran ()
21131 ? DW_TAG_module
: DW_TAG_namespace
,
21132 context_die
, decl
);
21133 /* For Fortran modules defined in different CU don't add src coords. */
21134 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
21136 const char *name
= dwarf2_name (decl
, 0);
21138 add_name_attribute (namespace_die
, name
);
21141 add_name_and_src_coords_attributes (namespace_die
, decl
);
21142 if (DECL_EXTERNAL (decl
))
21143 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
21144 equate_decl_number_to_die (decl
, namespace_die
);
21148 /* Output a namespace alias. */
21150 /* Force out the namespace we are an alias of, if necessary. */
21151 dw_die_ref origin_die
21152 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
21154 if (DECL_FILE_SCOPE_P (decl
)
21155 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
21156 context_die
= setup_namespace_context (decl
, comp_unit_die ());
21157 /* Now create the namespace alias DIE. */
21158 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
21159 add_name_and_src_coords_attributes (namespace_die
, decl
);
21160 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
21161 equate_decl_number_to_die (decl
, namespace_die
);
21165 /* Generate Dwarf debug information for a decl described by DECL.
21166 The return value is currently only meaningful for PARM_DECLs,
21167 for all other decls it returns NULL. */
21170 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
21172 tree decl_or_origin
= decl
? decl
: origin
;
21173 tree class_origin
= NULL
, ultimate_origin
;
21175 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
21178 switch (TREE_CODE (decl_or_origin
))
21184 if (!is_fortran () && !is_ada ())
21186 /* The individual enumerators of an enum type get output when we output
21187 the Dwarf representation of the relevant enum type itself. */
21191 /* Emit its type. */
21192 gen_type_die (TREE_TYPE (decl
), context_die
);
21194 /* And its containing namespace. */
21195 context_die
= declare_in_namespace (decl
, context_die
);
21197 gen_const_die (decl
, context_die
);
21200 case FUNCTION_DECL
:
21201 /* Don't output any DIEs to represent mere function declarations,
21202 unless they are class members or explicit block externs. */
21203 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
21204 && DECL_FILE_SCOPE_P (decl_or_origin
)
21205 && (current_function_decl
== NULL_TREE
21206 || DECL_ARTIFICIAL (decl_or_origin
)))
21211 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
21212 on local redeclarations of global functions. That seems broken. */
21213 if (current_function_decl
!= decl
)
21214 /* This is only a declaration. */;
21217 /* If we're emitting a clone, emit info for the abstract instance. */
21218 if (origin
|| DECL_ORIGIN (decl
) != decl
)
21219 dwarf2out_abstract_function (origin
21220 ? DECL_ORIGIN (origin
)
21221 : DECL_ABSTRACT_ORIGIN (decl
));
21223 /* If we're emitting an out-of-line copy of an inline function,
21224 emit info for the abstract instance and set up to refer to it. */
21225 else if (cgraph_function_possibly_inlined_p (decl
)
21226 && ! DECL_ABSTRACT (decl
)
21227 && ! class_or_namespace_scope_p (context_die
)
21228 /* dwarf2out_abstract_function won't emit a die if this is just
21229 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
21230 that case, because that works only if we have a die. */
21231 && DECL_INITIAL (decl
) != NULL_TREE
)
21233 dwarf2out_abstract_function (decl
);
21234 set_decl_origin_self (decl
);
21237 /* Otherwise we're emitting the primary DIE for this decl. */
21238 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
21240 /* Before we describe the FUNCTION_DECL itself, make sure that we
21241 have its containing type. */
21243 origin
= decl_class_context (decl
);
21244 if (origin
!= NULL_TREE
)
21245 gen_type_die (origin
, context_die
);
21247 /* And its return type. */
21248 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
21250 /* And its virtual context. */
21251 if (DECL_VINDEX (decl
) != NULL_TREE
)
21252 gen_type_die (DECL_CONTEXT (decl
), context_die
);
21254 /* Make sure we have a member DIE for decl. */
21255 if (origin
!= NULL_TREE
)
21256 gen_type_die_for_member (origin
, decl
, context_die
);
21258 /* And its containing namespace. */
21259 context_die
= declare_in_namespace (decl
, context_die
);
21262 /* Now output a DIE to represent the function itself. */
21264 gen_subprogram_die (decl
, context_die
);
21268 /* If we are in terse mode, don't generate any DIEs to represent any
21269 actual typedefs. */
21270 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21273 /* In the special case of a TYPE_DECL node representing the declaration
21274 of some type tag, if the given TYPE_DECL is marked as having been
21275 instantiated from some other (original) TYPE_DECL node (e.g. one which
21276 was generated within the original definition of an inline function) we
21277 used to generate a special (abbreviated) DW_TAG_structure_type,
21278 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
21279 should be actually referencing those DIEs, as variable DIEs with that
21280 type would be emitted already in the abstract origin, so it was always
21281 removed during unused type prunning. Don't add anything in this
21283 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
21286 if (is_redundant_typedef (decl
))
21287 gen_type_die (TREE_TYPE (decl
), context_die
);
21289 /* Output a DIE to represent the typedef itself. */
21290 gen_typedef_die (decl
, context_die
);
21294 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
21295 gen_label_die (decl
, context_die
);
21300 /* If we are in terse mode, don't generate any DIEs to represent any
21301 variable declarations or definitions. */
21302 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21305 /* Output any DIEs that are needed to specify the type of this data
21307 if (decl_by_reference_p (decl_or_origin
))
21308 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
21310 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
21312 /* And its containing type. */
21313 class_origin
= decl_class_context (decl_or_origin
);
21314 if (class_origin
!= NULL_TREE
)
21315 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
21317 /* And its containing namespace. */
21318 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
21320 /* Now output the DIE to represent the data object itself. This gets
21321 complicated because of the possibility that the VAR_DECL really
21322 represents an inlined instance of a formal parameter for an inline
21324 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
21325 if (ultimate_origin
!= NULL_TREE
21326 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
21327 gen_formal_parameter_die (decl
, origin
,
21328 true /* Emit name attribute. */,
21331 gen_variable_die (decl
, origin
, context_die
);
21335 /* Ignore the nameless fields that are used to skip bits but handle C++
21336 anonymous unions and structs. */
21337 if (DECL_NAME (decl
) != NULL_TREE
21338 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
21339 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
21341 gen_type_die (member_declared_type (decl
), context_die
);
21342 gen_field_die (decl
, context_die
);
21347 if (DECL_BY_REFERENCE (decl_or_origin
))
21348 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
21350 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
21351 return gen_formal_parameter_die (decl
, origin
,
21352 true /* Emit name attribute. */,
21355 case NAMESPACE_DECL
:
21356 case IMPORTED_DECL
:
21357 if (dwarf_version
>= 3 || !dwarf_strict
)
21358 gen_namespace_die (decl
, context_die
);
21362 /* Probably some frontend-internal decl. Assume we don't care. */
21363 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
21370 /* Output debug information for global decl DECL. Called from toplev.c after
21371 compilation proper has finished. */
21374 dwarf2out_global_decl (tree decl
)
21376 /* Output DWARF2 information for file-scope tentative data object
21377 declarations, file-scope (extern) function declarations (which
21378 had no corresponding body) and file-scope tagged type declarations
21379 and definitions which have not yet been forced out. */
21380 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
21381 dwarf2out_decl (decl
);
21384 /* Output debug information for type decl DECL. Called from toplev.c
21385 and from language front ends (to record built-in types). */
21387 dwarf2out_type_decl (tree decl
, int local
)
21390 dwarf2out_decl (decl
);
21393 /* Output debug information for imported module or decl DECL.
21394 NAME is non-NULL name in the lexical block if the decl has been renamed.
21395 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
21396 that DECL belongs to.
21397 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
21399 dwarf2out_imported_module_or_decl_1 (tree decl
,
21401 tree lexical_block
,
21402 dw_die_ref lexical_block_die
)
21404 expanded_location xloc
;
21405 dw_die_ref imported_die
= NULL
;
21406 dw_die_ref at_import_die
;
21408 if (TREE_CODE (decl
) == IMPORTED_DECL
)
21410 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
21411 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
21415 xloc
= expand_location (input_location
);
21417 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
21419 at_import_die
= force_type_die (TREE_TYPE (decl
));
21420 /* For namespace N { typedef void T; } using N::T; base_type_die
21421 returns NULL, but DW_TAG_imported_declaration requires
21422 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
21423 if (!at_import_die
)
21425 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
21426 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
21427 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
21428 gcc_assert (at_import_die
);
21433 at_import_die
= lookup_decl_die (decl
);
21434 if (!at_import_die
)
21436 /* If we're trying to avoid duplicate debug info, we may not have
21437 emitted the member decl for this field. Emit it now. */
21438 if (TREE_CODE (decl
) == FIELD_DECL
)
21440 tree type
= DECL_CONTEXT (decl
);
21442 if (TYPE_CONTEXT (type
)
21443 && TYPE_P (TYPE_CONTEXT (type
))
21444 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
21445 DINFO_USAGE_DIR_USE
))
21447 gen_type_die_for_member (type
, decl
,
21448 get_context_die (TYPE_CONTEXT (type
)));
21450 at_import_die
= force_decl_die (decl
);
21454 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
21456 if (dwarf_version
>= 3 || !dwarf_strict
)
21457 imported_die
= new_die (DW_TAG_imported_module
,
21464 imported_die
= new_die (DW_TAG_imported_declaration
,
21468 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
21469 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
21471 add_AT_string (imported_die
, DW_AT_name
,
21472 IDENTIFIER_POINTER (name
));
21473 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
21476 /* Output debug information for imported module or decl DECL.
21477 NAME is non-NULL name in context if the decl has been renamed.
21478 CHILD is true if decl is one of the renamed decls as part of
21479 importing whole module. */
21482 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
21485 /* dw_die_ref at_import_die; */
21486 dw_die_ref scope_die
;
21488 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21493 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
21494 We need decl DIE for reference and scope die. First, get DIE for the decl
21497 /* Get the scope die for decl context. Use comp_unit_die for global module
21498 or decl. If die is not found for non globals, force new die. */
21500 && TYPE_P (context
)
21501 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
21504 if (!(dwarf_version
>= 3 || !dwarf_strict
))
21507 scope_die
= get_context_die (context
);
21511 gcc_assert (scope_die
->die_child
);
21512 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
21513 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
21514 scope_die
= scope_die
->die_child
;
21517 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
21518 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
21522 /* Write the debugging output for DECL. */
21525 dwarf2out_decl (tree decl
)
21527 dw_die_ref context_die
= comp_unit_die ();
21529 switch (TREE_CODE (decl
))
21534 case FUNCTION_DECL
:
21535 /* What we would really like to do here is to filter out all mere
21536 file-scope declarations of file-scope functions which are never
21537 referenced later within this translation unit (and keep all of ones
21538 that *are* referenced later on) but we aren't clairvoyant, so we have
21539 no idea which functions will be referenced in the future (i.e. later
21540 on within the current translation unit). So here we just ignore all
21541 file-scope function declarations which are not also definitions. If
21542 and when the debugger needs to know something about these functions,
21543 it will have to hunt around and find the DWARF information associated
21544 with the definition of the function.
21546 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
21547 nodes represent definitions and which ones represent mere
21548 declarations. We have to check DECL_INITIAL instead. That's because
21549 the C front-end supports some weird semantics for "extern inline"
21550 function definitions. These can get inlined within the current
21551 translation unit (and thus, we need to generate Dwarf info for their
21552 abstract instances so that the Dwarf info for the concrete inlined
21553 instances can have something to refer to) but the compiler never
21554 generates any out-of-lines instances of such things (despite the fact
21555 that they *are* definitions).
21557 The important point is that the C front-end marks these "extern
21558 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
21559 them anyway. Note that the C++ front-end also plays some similar games
21560 for inline function definitions appearing within include files which
21561 also contain `#pragma interface' pragmas. */
21562 if (DECL_INITIAL (decl
) == NULL_TREE
)
21565 /* If we're a nested function, initially use a parent of NULL; if we're
21566 a plain function, this will be fixed up in decls_for_scope. If
21567 we're a method, it will be ignored, since we already have a DIE. */
21568 if (decl_function_context (decl
)
21569 /* But if we're in terse mode, we don't care about scope. */
21570 && debug_info_level
> DINFO_LEVEL_TERSE
)
21571 context_die
= NULL
;
21575 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
21576 declaration and if the declaration was never even referenced from
21577 within this entire compilation unit. We suppress these DIEs in
21578 order to save space in the .debug section (by eliminating entries
21579 which are probably useless). Note that we must not suppress
21580 block-local extern declarations (whether used or not) because that
21581 would screw-up the debugger's name lookup mechanism and cause it to
21582 miss things which really ought to be in scope at a given point. */
21583 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
21586 /* For local statics lookup proper context die. */
21587 if (TREE_STATIC (decl
) && decl_function_context (decl
))
21588 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
21590 /* If we are in terse mode, don't generate any DIEs to represent any
21591 variable declarations or definitions. */
21592 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21597 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21599 if (!is_fortran () && !is_ada ())
21601 if (TREE_STATIC (decl
) && decl_function_context (decl
))
21602 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
21605 case NAMESPACE_DECL
:
21606 case IMPORTED_DECL
:
21607 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21609 if (lookup_decl_die (decl
) != NULL
)
21614 /* Don't emit stubs for types unless they are needed by other DIEs. */
21615 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
21618 /* Don't bother trying to generate any DIEs to represent any of the
21619 normal built-in types for the language we are compiling. */
21620 if (DECL_IS_BUILTIN (decl
))
21623 /* If we are in terse mode, don't generate any DIEs for types. */
21624 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21627 /* If we're a function-scope tag, initially use a parent of NULL;
21628 this will be fixed up in decls_for_scope. */
21629 if (decl_function_context (decl
))
21630 context_die
= NULL
;
21638 gen_decl_die (decl
, NULL
, context_die
);
21641 /* Write the debugging output for DECL. */
21644 dwarf2out_function_decl (tree decl
)
21646 dwarf2out_decl (decl
);
21647 call_arg_locations
= NULL
;
21648 call_arg_loc_last
= NULL
;
21649 call_site_count
= -1;
21650 tail_call_site_count
= -1;
21651 VEC_free (dw_die_ref
, heap
, block_map
);
21652 htab_empty (decl_loc_table
);
21655 /* Output a marker (i.e. a label) for the beginning of the generated code for
21656 a lexical block. */
21659 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
21660 unsigned int blocknum
)
21662 switch_to_section (current_function_section ());
21663 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
21666 /* Output a marker (i.e. a label) for the end of the generated code for a
21670 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
21672 switch_to_section (current_function_section ());
21673 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
21676 /* Returns nonzero if it is appropriate not to emit any debugging
21677 information for BLOCK, because it doesn't contain any instructions.
21679 Don't allow this for blocks with nested functions or local classes
21680 as we would end up with orphans, and in the presence of scheduling
21681 we may end up calling them anyway. */
21684 dwarf2out_ignore_block (const_tree block
)
21689 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
21690 if (TREE_CODE (decl
) == FUNCTION_DECL
21691 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
21693 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
21695 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
21696 if (TREE_CODE (decl
) == FUNCTION_DECL
21697 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
21704 /* Hash table routines for file_hash. */
21707 file_table_eq (const void *p1_p
, const void *p2_p
)
21709 const struct dwarf_file_data
*const p1
=
21710 (const struct dwarf_file_data
*) p1_p
;
21711 const char *const p2
= (const char *) p2_p
;
21712 return filename_cmp (p1
->filename
, p2
) == 0;
21716 file_table_hash (const void *p_p
)
21718 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
21719 return htab_hash_string (p
->filename
);
21722 /* Lookup FILE_NAME (in the list of filenames that we know about here in
21723 dwarf2out.c) and return its "index". The index of each (known) filename is
21724 just a unique number which is associated with only that one filename. We
21725 need such numbers for the sake of generating labels (in the .debug_sfnames
21726 section) and references to those files numbers (in the .debug_srcinfo
21727 and.debug_macinfo sections). If the filename given as an argument is not
21728 found in our current list, add it to the list and assign it the next
21729 available unique index number. In order to speed up searches, we remember
21730 the index of the filename was looked up last. This handles the majority of
21733 static struct dwarf_file_data
*
21734 lookup_filename (const char *file_name
)
21737 struct dwarf_file_data
* created
;
21739 /* Check to see if the file name that was searched on the previous
21740 call matches this file name. If so, return the index. */
21741 if (file_table_last_lookup
21742 && (file_name
== file_table_last_lookup
->filename
21743 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
21744 return file_table_last_lookup
;
21746 /* Didn't match the previous lookup, search the table. */
21747 slot
= htab_find_slot_with_hash (file_table
, file_name
,
21748 htab_hash_string (file_name
), INSERT
);
21750 return (struct dwarf_file_data
*) *slot
;
21752 created
= ggc_alloc_dwarf_file_data ();
21753 created
->filename
= file_name
;
21754 created
->emitted_number
= 0;
21759 /* If the assembler will construct the file table, then translate the compiler
21760 internal file table number into the assembler file table number, and emit
21761 a .file directive if we haven't already emitted one yet. The file table
21762 numbers are different because we prune debug info for unused variables and
21763 types, which may include filenames. */
21766 maybe_emit_file (struct dwarf_file_data
* fd
)
21768 if (! fd
->emitted_number
)
21770 if (last_emitted_file
)
21771 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
21773 fd
->emitted_number
= 1;
21774 last_emitted_file
= fd
;
21776 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21778 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
21779 output_quoted_string (asm_out_file
,
21780 remap_debug_filename (fd
->filename
));
21781 fputc ('\n', asm_out_file
);
21785 return fd
->emitted_number
;
21788 /* Schedule generation of a DW_AT_const_value attribute to DIE.
21789 That generation should happen after function debug info has been
21790 generated. The value of the attribute is the constant value of ARG. */
21793 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
21795 die_arg_entry entry
;
21800 if (!tmpl_value_parm_die_table
)
21801 tmpl_value_parm_die_table
21802 = VEC_alloc (die_arg_entry
, gc
, 32);
21806 VEC_safe_push (die_arg_entry
, gc
,
21807 tmpl_value_parm_die_table
,
21811 /* Return TRUE if T is an instance of generic type, FALSE
21815 generic_type_p (tree t
)
21817 if (t
== NULL_TREE
|| !TYPE_P (t
))
21819 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
21822 /* Schedule the generation of the generic parameter dies for the
21823 instance of generic type T. The proper generation itself is later
21824 done by gen_scheduled_generic_parms_dies. */
21827 schedule_generic_params_dies_gen (tree t
)
21829 if (!generic_type_p (t
))
21832 if (generic_type_instances
== NULL
)
21833 generic_type_instances
= VEC_alloc (tree
, gc
, 256);
21835 VEC_safe_push (tree
, gc
, generic_type_instances
, t
);
21838 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
21839 by append_entry_to_tmpl_value_parm_die_table. This function must
21840 be called after function DIEs have been generated. */
21843 gen_remaining_tmpl_value_param_die_attribute (void)
21845 if (tmpl_value_parm_die_table
)
21850 FOR_EACH_VEC_ELT (die_arg_entry
, tmpl_value_parm_die_table
, i
, e
)
21851 tree_add_const_value_attribute (e
->die
, e
->arg
);
21855 /* Generate generic parameters DIEs for instances of generic types
21856 that have been previously scheduled by
21857 schedule_generic_params_dies_gen. This function must be called
21858 after all the types of the CU have been laid out. */
21861 gen_scheduled_generic_parms_dies (void)
21866 if (generic_type_instances
== NULL
)
21869 FOR_EACH_VEC_ELT (tree
, generic_type_instances
, i
, t
)
21870 gen_generic_params_dies (t
);
21874 /* Replace DW_AT_name for the decl with name. */
21877 dwarf2out_set_name (tree decl
, tree name
)
21883 die
= TYPE_SYMTAB_DIE (decl
);
21887 dname
= dwarf2_name (name
, 0);
21891 attr
= get_AT (die
, DW_AT_name
);
21894 struct indirect_string_node
*node
;
21896 node
= find_AT_string (dname
);
21897 /* replace the string. */
21898 attr
->dw_attr_val
.v
.val_str
= node
;
21902 add_name_attribute (die
, dname
);
21905 /* Called by the final INSN scan whenever we see a var location. We
21906 use it to drop labels in the right places, and throw the location in
21907 our lookup table. */
21910 dwarf2out_var_location (rtx loc_note
)
21912 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
21913 struct var_loc_node
*newloc
;
21915 static const char *last_label
;
21916 static const char *last_postcall_label
;
21917 static bool last_in_cold_section_p
;
21921 if (!NOTE_P (loc_note
))
21923 if (CALL_P (loc_note
))
21926 if (SIBLING_CALL_P (loc_note
))
21927 tail_call_site_count
++;
21932 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
21933 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
21936 next_real
= next_real_insn (loc_note
);
21938 /* If there are no instructions which would be affected by this note,
21939 don't do anything. */
21941 && next_real
== NULL_RTX
21942 && !NOTE_DURING_CALL_P (loc_note
))
21945 if (next_real
== NULL_RTX
)
21946 next_real
= get_last_insn ();
21948 /* If there were any real insns between note we processed last time
21949 and this note (or if it is the first note), clear
21950 last_{,postcall_}label so that they are not reused this time. */
21951 if (last_var_location_insn
== NULL_RTX
21952 || last_var_location_insn
!= next_real
21953 || last_in_cold_section_p
!= in_cold_section_p
)
21956 last_postcall_label
= NULL
;
21961 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
21962 newloc
= add_var_loc_to_decl (decl
, loc_note
,
21963 NOTE_DURING_CALL_P (loc_note
)
21964 ? last_postcall_label
: last_label
);
21965 if (newloc
== NULL
)
21974 /* If there were no real insns between note we processed last time
21975 and this note, use the label we emitted last time. Otherwise
21976 create a new label and emit it. */
21977 if (last_label
== NULL
)
21979 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
21980 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
21982 last_label
= ggc_strdup (loclabel
);
21987 struct call_arg_loc_node
*ca_loc
21988 = ggc_alloc_cleared_call_arg_loc_node ();
21989 rtx prev
= prev_real_insn (loc_note
), x
;
21990 ca_loc
->call_arg_loc_note
= loc_note
;
21991 ca_loc
->next
= NULL
;
21992 ca_loc
->label
= last_label
;
21995 || (NONJUMP_INSN_P (prev
)
21996 && GET_CODE (PATTERN (prev
)) == SEQUENCE
21997 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
21998 if (!CALL_P (prev
))
21999 prev
= XVECEXP (PATTERN (prev
), 0, 0);
22000 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
22001 x
= PATTERN (prev
);
22002 if (GET_CODE (x
) == PARALLEL
)
22003 x
= XVECEXP (x
, 0, 0);
22004 if (GET_CODE (x
) == SET
)
22006 if (GET_CODE (x
) == CALL
&& MEM_P (XEXP (x
, 0)))
22008 x
= XEXP (XEXP (x
, 0), 0);
22009 if (GET_CODE (x
) == SYMBOL_REF
22010 && SYMBOL_REF_DECL (x
)
22011 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
22012 ca_loc
->symbol_ref
= x
;
22014 ca_loc
->block
= insn_scope (prev
);
22015 if (call_arg_locations
)
22016 call_arg_loc_last
->next
= ca_loc
;
22018 call_arg_locations
= ca_loc
;
22019 call_arg_loc_last
= ca_loc
;
22021 else if (!NOTE_DURING_CALL_P (loc_note
))
22022 newloc
->label
= last_label
;
22025 if (!last_postcall_label
)
22027 sprintf (loclabel
, "%s-1", last_label
);
22028 last_postcall_label
= ggc_strdup (loclabel
);
22030 newloc
->label
= last_postcall_label
;
22033 last_var_location_insn
= next_real
;
22034 last_in_cold_section_p
= in_cold_section_p
;
22037 /* We need to reset the locations at the beginning of each
22038 function. We can't do this in the end_function hook, because the
22039 declarations that use the locations won't have been output when
22040 that hook is called. Also compute have_multiple_function_sections here. */
22043 dwarf2out_begin_function (tree fun
)
22045 if (function_section (fun
) != text_section
)
22046 have_multiple_function_sections
= true;
22047 else if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
22049 gcc_assert (current_function_decl
== fun
);
22050 cold_text_section
= unlikely_text_section ();
22051 switch_to_section (cold_text_section
);
22052 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
22053 switch_to_section (current_function_section ());
22056 dwarf2out_note_section_used ();
22057 call_site_count
= 0;
22058 tail_call_site_count
= 0;
22061 /* Output a label to mark the beginning of a source code line entry
22062 and record information relating to this source line, in
22063 'line_info_table' for later output of the .debug_line section. */
22066 dwarf2out_source_line (unsigned int line
, const char *filename
,
22067 int discriminator
, bool is_stmt
)
22069 static bool last_is_stmt
= true;
22071 if (debug_info_level
>= DINFO_LEVEL_NORMAL
22074 int file_num
= maybe_emit_file (lookup_filename (filename
));
22076 switch_to_section (current_function_section ());
22078 /* If requested, emit something human-readable. */
22079 if (flag_debug_asm
)
22080 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
22083 if (DWARF2_ASM_LINE_DEBUG_INFO
)
22085 /* Emit the .loc directive understood by GNU as. */
22086 fprintf (asm_out_file
, "\t.loc %d %d 0", file_num
, line
);
22087 if (is_stmt
!= last_is_stmt
)
22089 fprintf (asm_out_file
, " is_stmt %d", is_stmt
? 1 : 0);
22090 last_is_stmt
= is_stmt
;
22092 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
22093 fprintf (asm_out_file
, " discriminator %d", discriminator
);
22094 fputc ('\n', asm_out_file
);
22096 /* Indicate that line number info exists. */
22097 line_info_table_in_use
++;
22099 else if (function_section (current_function_decl
) != text_section
)
22101 dw_separate_line_info_ref line_info
;
22102 targetm
.asm_out
.internal_label (asm_out_file
,
22103 SEPARATE_LINE_CODE_LABEL
,
22104 separate_line_info_table_in_use
);
22106 /* Expand the line info table if necessary. */
22107 if (separate_line_info_table_in_use
22108 == separate_line_info_table_allocated
)
22110 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
22111 separate_line_info_table
22112 = GGC_RESIZEVEC (dw_separate_line_info_entry
,
22113 separate_line_info_table
,
22114 separate_line_info_table_allocated
);
22115 memset (separate_line_info_table
22116 + separate_line_info_table_in_use
,
22118 (LINE_INFO_TABLE_INCREMENT
22119 * sizeof (dw_separate_line_info_entry
)));
22122 /* Add the new entry at the end of the line_info_table. */
22124 = &separate_line_info_table
[separate_line_info_table_in_use
++];
22125 line_info
->dw_file_num
= file_num
;
22126 line_info
->dw_line_num
= line
;
22127 line_info
->function
= current_function_funcdef_no
;
22131 dw_line_info_ref line_info
;
22133 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
,
22134 line_info_table_in_use
);
22136 /* Expand the line info table if necessary. */
22137 if (line_info_table_in_use
== line_info_table_allocated
)
22139 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
22141 = GGC_RESIZEVEC (dw_line_info_entry
, line_info_table
,
22142 line_info_table_allocated
);
22143 memset (line_info_table
+ line_info_table_in_use
, 0,
22144 LINE_INFO_TABLE_INCREMENT
* sizeof (dw_line_info_entry
));
22147 /* Add the new entry at the end of the line_info_table. */
22148 line_info
= &line_info_table
[line_info_table_in_use
++];
22149 line_info
->dw_file_num
= file_num
;
22150 line_info
->dw_line_num
= line
;
22155 /* Record the beginning of a new source file. */
22158 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
22160 if (flag_eliminate_dwarf2_dups
&& dwarf_version
< 4)
22162 /* Record the beginning of the file for break_out_includes. */
22163 dw_die_ref bincl_die
;
22165 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
22166 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
22169 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22172 e
.code
= DW_MACINFO_start_file
;
22174 e
.info
= xstrdup (filename
);
22175 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
22179 /* Record the end of a source file. */
22182 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
22184 if (flag_eliminate_dwarf2_dups
&& dwarf_version
< 4)
22185 /* Record the end of the file for break_out_includes. */
22186 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
22188 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22191 e
.code
= DW_MACINFO_end_file
;
22194 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
22198 /* Called from debug_define in toplev.c. The `buffer' parameter contains
22199 the tail part of the directive line, i.e. the part which is past the
22200 initial whitespace, #, whitespace, directive-name, whitespace part. */
22203 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
22204 const char *buffer ATTRIBUTE_UNUSED
)
22206 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22209 e
.code
= DW_MACINFO_define
;
22211 e
.info
= xstrdup (buffer
);;
22212 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
22216 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
22217 the tail part of the directive line, i.e. the part which is past the
22218 initial whitespace, #, whitespace, directive-name, whitespace part. */
22221 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
22222 const char *buffer ATTRIBUTE_UNUSED
)
22224 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22227 e
.code
= DW_MACINFO_undef
;
22229 e
.info
= xstrdup (buffer
);;
22230 VEC_safe_push (macinfo_entry
, gc
, macinfo_table
, &e
);
22235 output_macinfo (void)
22238 unsigned long length
= VEC_length (macinfo_entry
, macinfo_table
);
22239 macinfo_entry
*ref
;
22244 for (i
= 0; VEC_iterate (macinfo_entry
, macinfo_table
, i
, ref
); i
++)
22248 case DW_MACINFO_start_file
:
22250 int file_num
= maybe_emit_file (lookup_filename (ref
->info
));
22251 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
22252 dw2_asm_output_data_uleb128
22253 (ref
->lineno
, "Included from line number %lu",
22254 (unsigned long)ref
->lineno
);
22255 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
22258 case DW_MACINFO_end_file
:
22259 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
22261 case DW_MACINFO_define
:
22262 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
22263 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
22264 (unsigned long)ref
->lineno
);
22265 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
22267 case DW_MACINFO_undef
:
22268 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
22269 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
22270 (unsigned long)ref
->lineno
);
22271 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
22274 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
22275 ASM_COMMENT_START
, (unsigned long)ref
->code
);
22281 /* Set up for Dwarf output at the start of compilation. */
22284 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
22286 /* Allocate the file_table. */
22287 file_table
= htab_create_ggc (50, file_table_hash
,
22288 file_table_eq
, NULL
);
22290 /* Allocate the decl_die_table. */
22291 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
22292 decl_die_table_eq
, NULL
);
22294 /* Allocate the decl_loc_table. */
22295 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
22296 decl_loc_table_eq
, NULL
);
22298 /* Allocate the initial hunk of the decl_scope_table. */
22299 decl_scope_table
= VEC_alloc (tree
, gc
, 256);
22301 /* Allocate the initial hunk of the abbrev_die_table. */
22302 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
22303 (ABBREV_DIE_TABLE_INCREMENT
);
22304 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
22305 /* Zero-th entry is allocated, but unused. */
22306 abbrev_die_table_in_use
= 1;
22308 /* Allocate the initial hunk of the line_info_table. */
22309 line_info_table
= ggc_alloc_cleared_vec_dw_line_info_entry
22310 (LINE_INFO_TABLE_INCREMENT
);
22311 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
22313 /* Zero-th entry is allocated, but unused. */
22314 line_info_table_in_use
= 1;
22316 /* Allocate the pubtypes and pubnames vectors. */
22317 pubname_table
= VEC_alloc (pubname_entry
, gc
, 32);
22318 pubtype_table
= VEC_alloc (pubname_entry
, gc
, 32);
22320 incomplete_types
= VEC_alloc (tree
, gc
, 64);
22322 used_rtx_array
= VEC_alloc (rtx
, gc
, 32);
22324 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
22325 SECTION_DEBUG
, NULL
);
22326 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
22327 SECTION_DEBUG
, NULL
);
22328 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
22329 SECTION_DEBUG
, NULL
);
22330 debug_macinfo_section
= get_section (DEBUG_MACINFO_SECTION
,
22331 SECTION_DEBUG
, NULL
);
22332 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
22333 SECTION_DEBUG
, NULL
);
22334 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
22335 SECTION_DEBUG
, NULL
);
22336 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
22337 SECTION_DEBUG
, NULL
);
22338 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
22339 SECTION_DEBUG
, NULL
);
22340 debug_str_section
= get_section (DEBUG_STR_SECTION
,
22341 DEBUG_STR_SECTION_FLAGS
, NULL
);
22342 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
22343 SECTION_DEBUG
, NULL
);
22344 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
22345 SECTION_DEBUG
, NULL
);
22347 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
22348 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
22349 DEBUG_ABBREV_SECTION_LABEL
, 0);
22350 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
22351 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
22352 COLD_TEXT_SECTION_LABEL
, 0);
22353 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
22355 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
22356 DEBUG_INFO_SECTION_LABEL
, 0);
22357 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
22358 DEBUG_LINE_SECTION_LABEL
, 0);
22359 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
22360 DEBUG_RANGES_SECTION_LABEL
, 0);
22361 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
22362 DEBUG_MACINFO_SECTION_LABEL
, 0);
22364 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22365 macinfo_table
= VEC_alloc (macinfo_entry
, gc
, 64);
22367 switch_to_section (text_section
);
22368 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
22371 /* Called before cgraph_optimize starts outputtting functions, variables
22372 and toplevel asms into assembly. */
22375 dwarf2out_assembly_start (void)
22377 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
22378 && dwarf2out_do_cfi_asm ()
22379 && (!(flag_unwind_tables
|| flag_exceptions
)
22380 || targetm
.except_unwind_info (&global_options
) != UI_DWARF2
))
22381 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
22384 /* A helper function for dwarf2out_finish called through
22385 htab_traverse. Emit one queued .debug_str string. */
22388 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
22390 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22392 if (node
->label
&& node
->refcount
)
22394 switch_to_section (debug_str_section
);
22395 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
22396 assemble_string (node
->str
, strlen (node
->str
) + 1);
22402 #if ENABLE_ASSERT_CHECKING
22403 /* Verify that all marks are clear. */
22406 verify_marks_clear (dw_die_ref die
)
22410 gcc_assert (! die
->die_mark
);
22411 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
22413 #endif /* ENABLE_ASSERT_CHECKING */
22415 /* Clear the marks for a die and its children.
22416 Be cool if the mark isn't set. */
22419 prune_unmark_dies (dw_die_ref die
)
22425 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
22428 /* Given DIE that we're marking as used, find any other dies
22429 it references as attributes and mark them as used. */
22432 prune_unused_types_walk_attribs (dw_die_ref die
)
22437 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
22439 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
22441 /* A reference to another DIE.
22442 Make sure that it will get emitted.
22443 If it was broken out into a comdat group, don't follow it. */
22444 if (dwarf_version
< 4
22445 || a
->dw_attr
== DW_AT_specification
22446 || a
->dw_attr_val
.v
.val_die_ref
.die
->die_id
.die_type_node
== NULL
)
22447 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
22449 /* Set the string's refcount to 0 so that prune_unused_types_mark
22450 accounts properly for it. */
22451 if (AT_class (a
) == dw_val_class_str
)
22452 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
22456 /* Mark the generic parameters and arguments children DIEs of DIE. */
22459 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
22463 if (die
== NULL
|| die
->die_child
== NULL
)
22465 c
= die
->die_child
;
22468 switch (c
->die_tag
)
22470 case DW_TAG_template_type_param
:
22471 case DW_TAG_template_value_param
:
22472 case DW_TAG_GNU_template_template_param
:
22473 case DW_TAG_GNU_template_parameter_pack
:
22474 prune_unused_types_mark (c
, 1);
22480 } while (c
&& c
!= die
->die_child
);
22483 /* Mark DIE as being used. If DOKIDS is true, then walk down
22484 to DIE's children. */
22487 prune_unused_types_mark (dw_die_ref die
, int dokids
)
22491 if (die
->die_mark
== 0)
22493 /* We haven't done this node yet. Mark it as used. */
22495 /* If this is the DIE of a generic type instantiation,
22496 mark the children DIEs that describe its generic parms and
22498 prune_unused_types_mark_generic_parms_dies (die
);
22500 /* We also have to mark its parents as used.
22501 (But we don't want to mark our parents' kids due to this.) */
22502 if (die
->die_parent
)
22503 prune_unused_types_mark (die
->die_parent
, 0);
22505 /* Mark any referenced nodes. */
22506 prune_unused_types_walk_attribs (die
);
22508 /* If this node is a specification,
22509 also mark the definition, if it exists. */
22510 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
22511 prune_unused_types_mark (die
->die_definition
, 1);
22514 if (dokids
&& die
->die_mark
!= 2)
22516 /* We need to walk the children, but haven't done so yet.
22517 Remember that we've walked the kids. */
22520 /* If this is an array type, we need to make sure our
22521 kids get marked, even if they're types. If we're
22522 breaking out types into comdat sections, do this
22523 for all type definitions. */
22524 if (die
->die_tag
== DW_TAG_array_type
22525 || (dwarf_version
>= 4
22526 && is_type_die (die
) && ! is_declaration_die (die
)))
22527 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
22529 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22533 /* For local classes, look if any static member functions were emitted
22534 and if so, mark them. */
22537 prune_unused_types_walk_local_classes (dw_die_ref die
)
22541 if (die
->die_mark
== 2)
22544 switch (die
->die_tag
)
22546 case DW_TAG_structure_type
:
22547 case DW_TAG_union_type
:
22548 case DW_TAG_class_type
:
22551 case DW_TAG_subprogram
:
22552 if (!get_AT_flag (die
, DW_AT_declaration
)
22553 || die
->die_definition
!= NULL
)
22554 prune_unused_types_mark (die
, 1);
22561 /* Mark children. */
22562 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
22565 /* Walk the tree DIE and mark types that we actually use. */
22568 prune_unused_types_walk (dw_die_ref die
)
22572 /* Don't do anything if this node is already marked and
22573 children have been marked as well. */
22574 if (die
->die_mark
== 2)
22577 switch (die
->die_tag
)
22579 case DW_TAG_structure_type
:
22580 case DW_TAG_union_type
:
22581 case DW_TAG_class_type
:
22582 if (die
->die_perennial_p
)
22585 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
22586 if (c
->die_tag
== DW_TAG_subprogram
)
22589 /* Finding used static member functions inside of classes
22590 is needed just for local classes, because for other classes
22591 static member function DIEs with DW_AT_specification
22592 are emitted outside of the DW_TAG_*_type. If we ever change
22593 it, we'd need to call this even for non-local classes. */
22595 prune_unused_types_walk_local_classes (die
);
22597 /* It's a type node --- don't mark it. */
22600 case DW_TAG_const_type
:
22601 case DW_TAG_packed_type
:
22602 case DW_TAG_pointer_type
:
22603 case DW_TAG_reference_type
:
22604 case DW_TAG_rvalue_reference_type
:
22605 case DW_TAG_volatile_type
:
22606 case DW_TAG_typedef
:
22607 case DW_TAG_array_type
:
22608 case DW_TAG_interface_type
:
22609 case DW_TAG_friend
:
22610 case DW_TAG_variant_part
:
22611 case DW_TAG_enumeration_type
:
22612 case DW_TAG_subroutine_type
:
22613 case DW_TAG_string_type
:
22614 case DW_TAG_set_type
:
22615 case DW_TAG_subrange_type
:
22616 case DW_TAG_ptr_to_member_type
:
22617 case DW_TAG_file_type
:
22618 if (die
->die_perennial_p
)
22621 /* It's a type node --- don't mark it. */
22625 /* Mark everything else. */
22629 if (die
->die_mark
== 0)
22633 /* Now, mark any dies referenced from here. */
22634 prune_unused_types_walk_attribs (die
);
22639 /* Mark children. */
22640 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22643 /* Increment the string counts on strings referred to from DIE's
22647 prune_unused_types_update_strings (dw_die_ref die
)
22652 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
22653 if (AT_class (a
) == dw_val_class_str
)
22655 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22657 /* Avoid unnecessarily putting strings that are used less than
22658 twice in the hash table. */
22660 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22663 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22664 htab_hash_string (s
->str
),
22666 gcc_assert (*slot
== NULL
);
22672 /* Remove from the tree DIE any dies that aren't marked. */
22675 prune_unused_types_prune (dw_die_ref die
)
22679 gcc_assert (die
->die_mark
);
22680 prune_unused_types_update_strings (die
);
22682 if (! die
->die_child
)
22685 c
= die
->die_child
;
22687 dw_die_ref prev
= c
;
22688 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22689 if (c
== die
->die_child
)
22691 /* No marked children between 'prev' and the end of the list. */
22693 /* No marked children at all. */
22694 die
->die_child
= NULL
;
22697 prev
->die_sib
= c
->die_sib
;
22698 die
->die_child
= prev
;
22703 if (c
!= prev
->die_sib
)
22705 prune_unused_types_prune (c
);
22706 } while (c
!= die
->die_child
);
22709 /* A helper function for dwarf2out_finish called through
22710 htab_traverse. Clear .debug_str strings that we haven't already
22711 decided to emit. */
22714 prune_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
22716 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22718 if (!node
->label
|| !node
->refcount
)
22719 htab_clear_slot (debug_str_hash
, h
);
22724 /* Remove dies representing declarations that we never use. */
22727 prune_unused_types (void)
22730 limbo_die_node
*node
;
22731 comdat_type_node
*ctnode
;
22734 #if ENABLE_ASSERT_CHECKING
22735 /* All the marks should already be clear. */
22736 verify_marks_clear (comp_unit_die ());
22737 for (node
= limbo_die_list
; node
; node
= node
->next
)
22738 verify_marks_clear (node
->die
);
22739 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22740 verify_marks_clear (ctnode
->root_die
);
22741 #endif /* ENABLE_ASSERT_CHECKING */
22743 /* Mark types that are used in global variables. */
22744 premark_types_used_by_global_vars ();
22746 /* Set the mark on nodes that are actually used. */
22747 prune_unused_types_walk (comp_unit_die ());
22748 for (node
= limbo_die_list
; node
; node
= node
->next
)
22749 prune_unused_types_walk (node
->die
);
22750 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22752 prune_unused_types_walk (ctnode
->root_die
);
22753 prune_unused_types_mark (ctnode
->type_die
, 1);
22756 /* Also set the mark on nodes referenced from the
22757 pubname_table or arange_table. */
22758 FOR_EACH_VEC_ELT (pubname_entry
, pubname_table
, i
, pub
)
22759 prune_unused_types_mark (pub
->die
, 1);
22760 for (i
= 0; i
< arange_table_in_use
; i
++)
22761 prune_unused_types_mark (arange_table
[i
], 1);
22763 /* Get rid of nodes that aren't marked; and update the string counts. */
22764 if (debug_str_hash
&& debug_str_hash_forced
)
22765 htab_traverse (debug_str_hash
, prune_indirect_string
, NULL
);
22766 else if (debug_str_hash
)
22767 htab_empty (debug_str_hash
);
22768 prune_unused_types_prune (comp_unit_die ());
22769 for (node
= limbo_die_list
; node
; node
= node
->next
)
22770 prune_unused_types_prune (node
->die
);
22771 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22772 prune_unused_types_prune (ctnode
->root_die
);
22774 /* Leave the marks clear. */
22775 prune_unmark_dies (comp_unit_die ());
22776 for (node
= limbo_die_list
; node
; node
= node
->next
)
22777 prune_unmark_dies (node
->die
);
22778 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22779 prune_unmark_dies (ctnode
->root_die
);
22782 /* Set the parameter to true if there are any relative pathnames in
22785 file_table_relative_p (void ** slot
, void *param
)
22787 bool *p
= (bool *) param
;
22788 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22789 if (!IS_ABSOLUTE_PATH (d
->filename
))
22797 /* Routines to manipulate hash table of comdat type units. */
22800 htab_ct_hash (const void *of
)
22803 const comdat_type_node
*const type_node
= (const comdat_type_node
*) of
;
22805 memcpy (&h
, type_node
->signature
, sizeof (h
));
22810 htab_ct_eq (const void *of1
, const void *of2
)
22812 const comdat_type_node
*const type_node_1
= (const comdat_type_node
*) of1
;
22813 const comdat_type_node
*const type_node_2
= (const comdat_type_node
*) of2
;
22815 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22816 DWARF_TYPE_SIGNATURE_SIZE
));
22819 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22820 to the location it would have been added, should we know its
22821 DECL_ASSEMBLER_NAME when we added other attributes. This will
22822 probably improve compactness of debug info, removing equivalent
22823 abbrevs, and hide any differences caused by deferring the
22824 computation of the assembler name, triggered by e.g. PCH. */
22827 move_linkage_attr (dw_die_ref die
)
22829 unsigned ix
= VEC_length (dw_attr_node
, die
->die_attr
);
22830 dw_attr_node linkage
= *VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
22832 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22833 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22837 dw_attr_node
*prev
= VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
22839 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22843 if (ix
!= VEC_length (dw_attr_node
, die
->die_attr
) - 1)
22845 VEC_pop (dw_attr_node
, die
->die_attr
);
22846 VEC_quick_insert (dw_attr_node
, die
->die_attr
, ix
, &linkage
);
22850 /* Helper function for resolve_addr, attempt to resolve
22851 one CONST_STRING, return non-zero if not successful. Similarly verify that
22852 SYMBOL_REFs refer to variables emitted in the current CU. */
22855 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
22859 if (GET_CODE (rtl
) == CONST_STRING
)
22861 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22862 tree t
= build_string (len
, XSTR (rtl
, 0));
22863 tree tlen
= build_int_cst (NULL_TREE
, len
- 1);
22865 = build_array_type (char_type_node
, build_index_type (tlen
));
22866 rtl
= lookup_constant_def (t
);
22867 if (!rtl
|| !MEM_P (rtl
))
22869 rtl
= XEXP (rtl
, 0);
22870 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
22875 if (GET_CODE (rtl
) == SYMBOL_REF
22876 && SYMBOL_REF_DECL (rtl
))
22878 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
22880 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
22883 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22887 if (GET_CODE (rtl
) == CONST
22888 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
22894 /* Helper function for resolve_addr, handle one location
22895 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22896 the location list couldn't be resolved. */
22899 resolve_addr_in_expr (dw_loc_descr_ref loc
)
22901 for (; loc
; loc
= loc
->dw_loc_next
)
22902 if (((loc
->dw_loc_opc
== DW_OP_addr
|| loc
->dtprel
)
22903 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22904 || (loc
->dw_loc_opc
== DW_OP_implicit_value
22905 && loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
22906 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
)))
22908 else if (loc
->dw_loc_opc
== DW_OP_GNU_implicit_pointer
22909 && loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
22912 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
22915 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22916 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22917 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22922 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
22923 an address in .rodata section if the string literal is emitted there,
22924 or remove the containing location list or replace DW_AT_const_value
22925 with DW_AT_location and empty location expression, if it isn't found
22926 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
22927 to something that has been emitted in the current CU. */
22930 resolve_addr (dw_die_ref die
)
22934 dw_loc_list_ref
*curr
;
22937 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
22938 switch (AT_class (a
))
22940 case dw_val_class_loc_list
:
22941 curr
= AT_loc_list_ptr (a
);
22944 if (!resolve_addr_in_expr ((*curr
)->expr
))
22946 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
22947 if (next
&& (*curr
)->ll_symbol
)
22949 gcc_assert (!next
->ll_symbol
);
22950 next
->ll_symbol
= (*curr
)->ll_symbol
;
22955 curr
= &(*curr
)->dw_loc_next
;
22957 if (!AT_loc_list (a
))
22959 remove_AT (die
, a
->dw_attr
);
22963 case dw_val_class_loc
:
22964 if (!resolve_addr_in_expr (AT_loc (a
)))
22966 remove_AT (die
, a
->dw_attr
);
22970 case dw_val_class_addr
:
22971 if (a
->dw_attr
== DW_AT_const_value
22972 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
22974 remove_AT (die
, a
->dw_attr
);
22977 if (die
->die_tag
== DW_TAG_GNU_call_site
22978 && a
->dw_attr
== DW_AT_abstract_origin
)
22980 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
22981 dw_die_ref tdie
= lookup_decl_die (tdecl
);
22982 if (tdie
== NULL
&& DECL_EXTERNAL (tdecl
))
22984 force_decl_die (tdecl
);
22985 tdie
= lookup_decl_die (tdecl
);
22989 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
22990 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
22991 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
22995 remove_AT (die
, a
->dw_attr
);
23004 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
23007 /* Helper routines for optimize_location_lists.
23008 This pass tries to share identical local lists in .debug_loc
23011 /* Iteratively hash operands of LOC opcode. */
23013 static inline hashval_t
23014 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
23016 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
23017 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
23019 switch (loc
->dw_loc_opc
)
23021 case DW_OP_const4u
:
23022 case DW_OP_const8u
:
23026 case DW_OP_const1u
:
23027 case DW_OP_const1s
:
23028 case DW_OP_const2u
:
23029 case DW_OP_const2s
:
23030 case DW_OP_const4s
:
23031 case DW_OP_const8s
:
23035 case DW_OP_plus_uconst
:
23071 case DW_OP_deref_size
:
23072 case DW_OP_xderef_size
:
23073 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23080 gcc_assert (val1
->val_class
== dw_val_class_loc
);
23081 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
23082 hash
= iterative_hash_object (offset
, hash
);
23085 case DW_OP_implicit_value
:
23086 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23087 switch (val2
->val_class
)
23089 case dw_val_class_const
:
23090 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23092 case dw_val_class_vec
:
23094 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23095 unsigned int len
= val2
->v
.val_vec
.length
;
23097 hash
= iterative_hash_object (elt_size
, hash
);
23098 hash
= iterative_hash_object (len
, hash
);
23099 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23100 len
* elt_size
, hash
);
23103 case dw_val_class_const_double
:
23104 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23105 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23107 case dw_val_class_addr
:
23108 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
23111 gcc_unreachable ();
23115 case DW_OP_bit_piece
:
23116 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23117 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23123 unsigned char dtprel
= 0xd1;
23124 hash
= iterative_hash_object (dtprel
, hash
);
23126 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
23128 case DW_OP_GNU_implicit_pointer
:
23129 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23131 case DW_OP_GNU_entry_value
:
23132 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
23136 /* Other codes have no operands. */
23142 /* Iteratively hash the whole DWARF location expression LOC. */
23144 static inline hashval_t
23145 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
23147 dw_loc_descr_ref l
;
23148 bool sizes_computed
= false;
23149 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23150 size_of_locs (loc
);
23152 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
23154 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
23155 hash
= iterative_hash_object (opc
, hash
);
23156 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
23158 size_of_locs (loc
);
23159 sizes_computed
= true;
23161 hash
= hash_loc_operands (l
, hash
);
23166 /* Compute hash of the whole location list LIST_HEAD. */
23169 hash_loc_list (dw_loc_list_ref list_head
)
23171 dw_loc_list_ref curr
= list_head
;
23172 hashval_t hash
= 0;
23174 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23176 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
23177 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
23179 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
23181 hash
= hash_locs (curr
->expr
, hash
);
23183 list_head
->hash
= hash
;
23186 /* Return true if X and Y opcodes have the same operands. */
23189 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23191 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
23192 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
23193 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
23194 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
23196 switch (x
->dw_loc_opc
)
23198 case DW_OP_const4u
:
23199 case DW_OP_const8u
:
23203 case DW_OP_const1u
:
23204 case DW_OP_const1s
:
23205 case DW_OP_const2u
:
23206 case DW_OP_const2s
:
23207 case DW_OP_const4s
:
23208 case DW_OP_const8s
:
23212 case DW_OP_plus_uconst
:
23248 case DW_OP_deref_size
:
23249 case DW_OP_xderef_size
:
23250 return valx1
->v
.val_int
== valy1
->v
.val_int
;
23253 gcc_assert (valx1
->val_class
== dw_val_class_loc
23254 && valy1
->val_class
== dw_val_class_loc
23255 && x
->dw_loc_addr
== y
->dw_loc_addr
);
23256 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
23257 case DW_OP_implicit_value
:
23258 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
23259 || valx2
->val_class
!= valy2
->val_class
)
23261 switch (valx2
->val_class
)
23263 case dw_val_class_const
:
23264 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23265 case dw_val_class_vec
:
23266 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23267 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23268 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23269 valx2
->v
.val_vec
.elt_size
23270 * valx2
->v
.val_vec
.length
) == 0;
23271 case dw_val_class_const_double
:
23272 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23273 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23274 case dw_val_class_addr
:
23275 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
23277 gcc_unreachable ();
23280 case DW_OP_bit_piece
:
23281 return valx1
->v
.val_int
== valy1
->v
.val_int
23282 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23285 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
23286 case DW_OP_GNU_implicit_pointer
:
23287 return valx1
->val_class
== dw_val_class_die_ref
23288 && valx1
->val_class
== valy1
->val_class
23289 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
23290 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23291 case DW_OP_GNU_entry_value
:
23292 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
23294 /* Other codes have no operands. */
23299 /* Return true if DWARF location expressions X and Y are the same. */
23302 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23304 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
23305 if (x
->dw_loc_opc
!= y
->dw_loc_opc
23306 || x
->dtprel
!= y
->dtprel
23307 || !compare_loc_operands (x
, y
))
23309 return x
== NULL
&& y
== NULL
;
23312 /* Return precomputed hash of location list X. */
23315 loc_list_hash (const void *x
)
23317 return ((const struct dw_loc_list_struct
*) x
)->hash
;
23320 /* Return 1 if location lists X and Y are the same. */
23323 loc_list_eq (const void *x
, const void *y
)
23325 const struct dw_loc_list_struct
*a
= (const struct dw_loc_list_struct
*) x
;
23326 const struct dw_loc_list_struct
*b
= (const struct dw_loc_list_struct
*) y
;
23329 if (a
->hash
!= b
->hash
)
23331 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
23332 if (strcmp (a
->begin
, b
->begin
) != 0
23333 || strcmp (a
->end
, b
->end
) != 0
23334 || (a
->section
== NULL
) != (b
->section
== NULL
)
23335 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
23336 || !compare_locs (a
->expr
, b
->expr
))
23338 return a
== NULL
&& b
== NULL
;
23341 /* Recursively optimize location lists referenced from DIE
23342 children and share them whenever possible. */
23345 optimize_location_lists_1 (dw_die_ref die
, htab_t htab
)
23352 FOR_EACH_VEC_ELT (dw_attr_node
, die
->die_attr
, ix
, a
)
23353 if (AT_class (a
) == dw_val_class_loc_list
)
23355 dw_loc_list_ref list
= AT_loc_list (a
);
23356 /* TODO: perform some optimizations here, before hashing
23357 it and storing into the hash table. */
23358 hash_loc_list (list
);
23359 slot
= htab_find_slot_with_hash (htab
, list
, list
->hash
,
23362 *slot
= (void *) list
;
23364 a
->dw_attr_val
.v
.val_loc_list
= (dw_loc_list_ref
) *slot
;
23367 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
23370 /* Optimize location lists referenced from DIE
23371 children and share them whenever possible. */
23374 optimize_location_lists (dw_die_ref die
)
23376 htab_t htab
= htab_create (500, loc_list_hash
, loc_list_eq
, NULL
);
23377 optimize_location_lists_1 (die
, htab
);
23378 htab_delete (htab
);
23381 /* Output stuff that dwarf requires at the end of every file,
23382 and generate the DWARF-2 debugging info. */
23385 dwarf2out_finish (const char *filename
)
23387 limbo_die_node
*node
, *next_node
;
23388 comdat_type_node
*ctnode
;
23389 htab_t comdat_type_table
;
23392 gen_scheduled_generic_parms_dies ();
23393 gen_remaining_tmpl_value_param_die_attribute ();
23395 /* Add the name for the main input file now. We delayed this from
23396 dwarf2out_init to avoid complications with PCH. */
23397 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
23398 if (!IS_ABSOLUTE_PATH (filename
))
23399 add_comp_dir_attribute (comp_unit_die ());
23400 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
23403 htab_traverse (file_table
, file_table_relative_p
, &p
);
23405 add_comp_dir_attribute (comp_unit_die ());
23408 for (i
= 0; i
< VEC_length (deferred_locations
, deferred_locations_list
); i
++)
23410 add_location_or_const_value_attribute (
23411 VEC_index (deferred_locations
, deferred_locations_list
, i
)->die
,
23412 VEC_index (deferred_locations
, deferred_locations_list
, i
)->variable
,
23416 /* Traverse the limbo die list, and add parent/child links. The only
23417 dies without parents that should be here are concrete instances of
23418 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23419 For concrete instances, we can get the parent die from the abstract
23421 for (node
= limbo_die_list
; node
; node
= next_node
)
23423 dw_die_ref die
= node
->die
;
23424 next_node
= node
->next
;
23426 if (die
->die_parent
== NULL
)
23428 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
23431 add_child_die (origin
->die_parent
, die
);
23432 else if (is_cu_die (die
))
23434 else if (seen_error ())
23435 /* It's OK to be confused by errors in the input. */
23436 add_child_die (comp_unit_die (), die
);
23439 /* In certain situations, the lexical block containing a
23440 nested function can be optimized away, which results
23441 in the nested function die being orphaned. Likewise
23442 with the return type of that nested function. Force
23443 this to be a child of the containing function.
23445 It may happen that even the containing function got fully
23446 inlined and optimized out. In that case we are lost and
23447 assign the empty child. This should not be big issue as
23448 the function is likely unreachable too. */
23449 tree context
= NULL_TREE
;
23451 gcc_assert (node
->created_for
);
23453 if (DECL_P (node
->created_for
))
23454 context
= DECL_CONTEXT (node
->created_for
);
23455 else if (TYPE_P (node
->created_for
))
23456 context
= TYPE_CONTEXT (node
->created_for
);
23458 gcc_assert (context
23459 && (TREE_CODE (context
) == FUNCTION_DECL
23460 || TREE_CODE (context
) == NAMESPACE_DECL
));
23462 origin
= lookup_decl_die (context
);
23464 add_child_die (origin
, die
);
23466 add_child_die (comp_unit_die (), die
);
23471 limbo_die_list
= NULL
;
23473 resolve_addr (comp_unit_die ());
23475 for (node
= deferred_asm_name
; node
; node
= node
->next
)
23477 tree decl
= node
->created_for
;
23478 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
23480 add_linkage_attr (node
->die
, decl
);
23481 move_linkage_attr (node
->die
);
23485 deferred_asm_name
= NULL
;
23487 /* Walk through the list of incomplete types again, trying once more to
23488 emit full debugging info for them. */
23489 retry_incomplete_types ();
23491 if (flag_eliminate_unused_debug_types
)
23492 prune_unused_types ();
23494 /* Generate separate CUs for each of the include files we've seen.
23495 They will go into limbo_die_list. */
23496 if (flag_eliminate_dwarf2_dups
&& dwarf_version
< 4)
23497 break_out_includes (comp_unit_die ());
23499 /* Generate separate COMDAT sections for type DIEs. */
23500 if (dwarf_version
>= 4)
23502 break_out_comdat_types (comp_unit_die ());
23504 /* Each new type_unit DIE was added to the limbo die list when created.
23505 Since these have all been added to comdat_type_list, clear the
23507 limbo_die_list
= NULL
;
23509 /* For each new comdat type unit, copy declarations for incomplete
23510 types to make the new unit self-contained (i.e., no direct
23511 references to the main compile unit). */
23512 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23513 copy_decls_for_unworthy_types (ctnode
->root_die
);
23514 copy_decls_for_unworthy_types (comp_unit_die ());
23516 /* In the process of copying declarations from one unit to another,
23517 we may have left some declarations behind that are no longer
23518 referenced. Prune them. */
23519 prune_unused_types ();
23522 /* Traverse the DIE's and add add sibling attributes to those DIE's
23523 that have children. */
23524 add_sibling_attributes (comp_unit_die ());
23525 for (node
= limbo_die_list
; node
; node
= node
->next
)
23526 add_sibling_attributes (node
->die
);
23527 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23528 add_sibling_attributes (ctnode
->root_die
);
23530 /* Output a terminator label for the .text section. */
23531 switch_to_section (text_section
);
23532 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
23533 if (cold_text_section
)
23535 switch_to_section (cold_text_section
);
23536 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
23539 /* We can only use the low/high_pc attributes if all of the code was
23541 if (!have_multiple_function_sections
23542 || (dwarf_version
< 3 && dwarf_strict
))
23544 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc
, text_section_label
);
23545 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc
, text_end_label
);
23550 unsigned fde_idx
= 0;
23551 bool range_list_added
= false;
23553 /* We need to give .debug_loc and .debug_ranges an appropriate
23554 "base address". Use zero so that these addresses become
23555 absolute. Historically, we've emitted the unexpected
23556 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23557 Emit both to give time for other tools to adapt. */
23558 add_AT_addr (comp_unit_die (), DW_AT_low_pc
, const0_rtx
);
23559 add_AT_addr (comp_unit_die (), DW_AT_entry_pc
, const0_rtx
);
23561 if (text_section_used
)
23562 add_ranges_by_labels (comp_unit_die (), text_section_label
,
23563 text_end_label
, &range_list_added
);
23564 if (flag_reorder_blocks_and_partition
&& cold_text_section_used
)
23565 add_ranges_by_labels (comp_unit_die (), cold_text_section_label
,
23566 cold_end_label
, &range_list_added
);
23568 for (fde_idx
= 0; fde_idx
< fde_table_in_use
; fde_idx
++)
23570 dw_fde_ref fde
= &fde_table
[fde_idx
];
23572 if (fde
->dw_fde_switched_sections
)
23574 if (!fde
->in_std_section
)
23575 add_ranges_by_labels (comp_unit_die (),
23576 fde
->dw_fde_hot_section_label
,
23577 fde
->dw_fde_hot_section_end_label
,
23578 &range_list_added
);
23579 if (!fde
->cold_in_std_section
)
23580 add_ranges_by_labels (comp_unit_die (),
23581 fde
->dw_fde_unlikely_section_label
,
23582 fde
->dw_fde_unlikely_section_end_label
,
23583 &range_list_added
);
23585 else if (!fde
->in_std_section
)
23586 add_ranges_by_labels (comp_unit_die (), fde
->dw_fde_begin
,
23587 fde
->dw_fde_end
, &range_list_added
);
23590 if (range_list_added
)
23594 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23595 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list
,
23596 debug_line_section_label
);
23598 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
23599 add_AT_macptr (comp_unit_die (), DW_AT_macro_info
, macinfo_section_label
);
23601 if (have_location_lists
)
23602 optimize_location_lists (comp_unit_die ());
23604 /* Output all of the compilation units. We put the main one last so that
23605 the offsets are available to output_pubnames. */
23606 for (node
= limbo_die_list
; node
; node
= node
->next
)
23607 output_comp_unit (node
->die
, 0);
23609 comdat_type_table
= htab_create (100, htab_ct_hash
, htab_ct_eq
, NULL
);
23610 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23612 void **slot
= htab_find_slot (comdat_type_table
, ctnode
, INSERT
);
23614 /* Don't output duplicate types. */
23615 if (*slot
!= HTAB_EMPTY_ENTRY
)
23618 /* Add a pointer to the line table for the main compilation unit
23619 so that the debugger can make sense of DW_AT_decl_file
23621 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23622 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
23623 debug_line_section_label
);
23625 output_comdat_type_unit (ctnode
);
23628 htab_delete (comdat_type_table
);
23630 /* Output the main compilation unit if non-empty or if .debug_macinfo
23631 will be emitted. */
23632 output_comp_unit (comp_unit_die (), debug_info_level
>= DINFO_LEVEL_VERBOSE
);
23634 /* Output the abbreviation table. */
23635 switch_to_section (debug_abbrev_section
);
23636 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
23637 output_abbrev_section ();
23639 /* Output location list section if necessary. */
23640 if (have_location_lists
)
23642 /* Output the location lists info. */
23643 switch_to_section (debug_loc_section
);
23644 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
23645 DEBUG_LOC_SECTION_LABEL
, 0);
23646 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
23647 output_location_lists (comp_unit_die ());
23650 /* Output public names table if necessary. */
23651 if (!VEC_empty (pubname_entry
, pubname_table
))
23653 gcc_assert (info_section_emitted
);
23654 switch_to_section (debug_pubnames_section
);
23655 output_pubnames (pubname_table
);
23658 /* Output public types table if necessary. */
23659 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
23660 It shouldn't hurt to emit it always, since pure DWARF2 consumers
23661 simply won't look for the section. */
23662 if (!VEC_empty (pubname_entry
, pubtype_table
))
23664 bool empty
= false;
23666 if (flag_eliminate_unused_debug_types
)
23668 /* The pubtypes table might be emptied by pruning unused items. */
23672 FOR_EACH_VEC_ELT (pubname_entry
, pubtype_table
, i
, p
)
23673 if (p
->die
->die_offset
!= 0)
23681 gcc_assert (info_section_emitted
);
23682 switch_to_section (debug_pubtypes_section
);
23683 output_pubnames (pubtype_table
);
23687 /* Output the address range information. We only put functions in the arange
23688 table, so don't write it out if we don't have any. */
23689 if ((text_section_used
|| cold_text_section_used
|| arange_table_in_use
)
23690 && info_section_emitted
)
23692 switch_to_section (debug_aranges_section
);
23696 /* Output ranges section if necessary. */
23697 if (ranges_table_in_use
)
23699 switch_to_section (debug_ranges_section
);
23700 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
23704 /* Output the source line correspondence table. We must do this
23705 even if there is no line information. Otherwise, on an empty
23706 translation unit, we will generate a present, but empty,
23707 .debug_info section. IRIX 6.5 `nm' will then complain when
23708 examining the file. This is done late so that any filenames
23709 used by the debug_info section are marked as 'used'. */
23710 switch_to_section (debug_line_section
);
23711 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
23712 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
23713 output_line_info ();
23715 /* Have to end the macro section. */
23716 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
23718 switch_to_section (debug_macinfo_section
);
23719 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
23720 if (!VEC_empty (macinfo_entry
, macinfo_table
))
23722 dw2_asm_output_data (1, 0, "End compilation unit");
23725 /* If we emitted any DW_FORM_strp form attribute, output the string
23727 if (debug_str_hash
)
23728 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
23731 #include "gt-dwarf2out.h"