1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
5 Contributed by Gary Funck (gary@intrepid.com).
6 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
7 Extensively modified by Jason Merrill (jason@cygnus.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
37 /* DWARF2 Abbreviation Glossary:
39 CFA = Canonical Frame Address
40 a fixed address on the stack which identifies a call frame.
41 We define it to be the value of SP just before the call insn.
42 The CFA register and offset, which may change during the course
43 of the function, are used to calculate its value at runtime.
45 CFI = Call Frame Instruction
46 an instruction for the DWARF2 abstract machine
48 CIE = Common Information Entry
49 information describing information common to one or more FDEs
51 DIE = Debugging Information Entry
53 FDE = Frame Description Entry
54 information describing the stack call frame, in particular,
55 how to restore registers
57 DW_CFA_... = DWARF2 CFA call frame instruction
58 DW_TAG_... = DWARF2 DIE tag */
62 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
84 #include "diagnostic.h"
85 #include "tree-pretty-print.h"
88 #include "langhooks.h"
93 #include "tree-pass.h"
94 #include "tree-flow.h"
96 #ifdef DWARF2_DEBUGGING_INFO
97 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
99 static rtx last_var_location_insn
;
102 #ifdef VMS_DEBUGGING_INFO
103 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
105 /* Define this macro to be a nonzero value if the directory specifications
106 which are output in the debug info should end with a separator. */
107 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
108 /* Define this macro to evaluate to a nonzero value if GCC should refrain
109 from generating indirect strings in DWARF2 debug information, for instance
110 if your target is stuck with an old version of GDB that is unable to
111 process them properly or uses VMS Debug. */
112 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
114 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
115 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
118 #ifndef DWARF2_FRAME_INFO
119 # ifdef DWARF2_DEBUGGING_INFO
120 # define DWARF2_FRAME_INFO \
121 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
123 # define DWARF2_FRAME_INFO 0
127 /* Map register numbers held in the call frame info that gcc has
128 collected using DWARF_FRAME_REGNUM to those that should be output in
129 .debug_frame and .eh_frame. */
130 #ifndef DWARF2_FRAME_REG_OUT
131 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
134 /* Save the result of dwarf2out_do_frame across PCH. */
135 static GTY(()) bool saved_do_cfi_asm
= 0;
137 /* Decide whether we want to emit frame unwind information for the current
141 dwarf2out_do_frame (void)
143 /* We want to emit correct CFA location expressions or lists, so we
144 have to return true if we're going to output debug info, even if
145 we're not going to output frame or unwind info. */
146 return (write_symbols
== DWARF2_DEBUG
147 || write_symbols
== VMS_AND_DWARF2_DEBUG
148 || DWARF2_FRAME_INFO
|| saved_do_cfi_asm
149 #ifdef DWARF2_UNWIND_INFO
150 || (DWARF2_UNWIND_INFO
151 && (flag_unwind_tables
152 || (flag_exceptions
&& ! USING_SJLJ_EXCEPTIONS
)))
157 /* Decide whether to emit frame unwind via assembler directives. */
160 dwarf2out_do_cfi_asm (void)
164 #ifdef MIPS_DEBUGGING_INFO
167 if (!flag_dwarf2_cfi_asm
|| !dwarf2out_do_frame ())
169 if (saved_do_cfi_asm
)
171 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE
)
174 /* Make sure the personality encoding is one the assembler can support.
175 In particular, aligned addresses can't be handled. */
176 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
177 if ((enc
& 0x70) != 0 && (enc
& 0x70) != DW_EH_PE_pcrel
)
179 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
180 if ((enc
& 0x70) != 0 && (enc
& 0x70) != DW_EH_PE_pcrel
)
183 if (!HAVE_GAS_CFI_SECTIONS_DIRECTIVE
)
185 #ifdef TARGET_UNWIND_INFO
188 if (USING_SJLJ_EXCEPTIONS
|| (!flag_unwind_tables
&& !flag_exceptions
))
193 saved_do_cfi_asm
= true;
197 /* The size of the target's pointer type. */
199 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
202 /* Array of RTXes referenced by the debugging information, which therefore
203 must be kept around forever. */
204 static GTY(()) VEC(rtx
,gc
) *used_rtx_array
;
206 /* A pointer to the base of a list of incomplete types which might be
207 completed at some later time. incomplete_types_list needs to be a
208 VEC(tree,gc) because we want to tell the garbage collector about
210 static GTY(()) VEC(tree
,gc
) *incomplete_types
;
212 /* A pointer to the base of a table of references to declaration
213 scopes. This table is a display which tracks the nesting
214 of declaration scopes at the current scope and containing
215 scopes. This table is used to find the proper place to
216 define type declaration DIE's. */
217 static GTY(()) VEC(tree
,gc
) *decl_scope_table
;
219 /* Pointers to various DWARF2 sections. */
220 static GTY(()) section
*debug_info_section
;
221 static GTY(()) section
*debug_abbrev_section
;
222 static GTY(()) section
*debug_aranges_section
;
223 static GTY(()) section
*debug_macinfo_section
;
224 static GTY(()) section
*debug_line_section
;
225 static GTY(()) section
*debug_loc_section
;
226 static GTY(()) section
*debug_pubnames_section
;
227 static GTY(()) section
*debug_pubtypes_section
;
228 static GTY(()) section
*debug_dcall_section
;
229 static GTY(()) section
*debug_vcall_section
;
230 static GTY(()) section
*debug_str_section
;
231 static GTY(()) section
*debug_ranges_section
;
232 static GTY(()) section
*debug_frame_section
;
234 /* Personality decl of current unit. Used only when assembler does not support
236 static GTY(()) rtx current_unit_personality
;
238 /* How to start an assembler comment. */
239 #ifndef ASM_COMMENT_START
240 #define ASM_COMMENT_START ";#"
243 typedef struct dw_cfi_struct
*dw_cfi_ref
;
244 typedef struct dw_fde_struct
*dw_fde_ref
;
245 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
247 /* Call frames are described using a sequence of Call Frame
248 Information instructions. The register number, offset
249 and address fields are provided as possible operands;
250 their use is selected by the opcode field. */
252 enum dw_cfi_oprnd_type
{
254 dw_cfi_oprnd_reg_num
,
260 typedef union GTY(()) dw_cfi_oprnd_struct
{
261 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num
;
262 HOST_WIDE_INT
GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset
;
263 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr
;
264 struct dw_loc_descr_struct
* GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc
;
268 typedef struct GTY(()) dw_cfi_struct
{
269 dw_cfi_ref dw_cfi_next
;
270 enum dwarf_call_frame_info dw_cfi_opc
;
271 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
273 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
278 /* This is how we define the location of the CFA. We use to handle it
279 as REG + OFFSET all the time, but now it can be more complex.
280 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
281 Instead of passing around REG and OFFSET, we pass a copy
282 of this structure. */
283 typedef struct GTY(()) cfa_loc
{
284 HOST_WIDE_INT offset
;
285 HOST_WIDE_INT base_offset
;
287 BOOL_BITFIELD indirect
: 1; /* 1 if CFA is accessed via a dereference. */
288 BOOL_BITFIELD in_use
: 1; /* 1 if a saved cfa is stored here. */
291 /* All call frame descriptions (FDE's) in the GCC generated DWARF
292 refer to a single Common Information Entry (CIE), defined at
293 the beginning of the .debug_frame section. This use of a single
294 CIE obviates the need to keep track of multiple CIE's
295 in the DWARF generation routines below. */
297 typedef struct GTY(()) dw_fde_struct
{
299 const char *dw_fde_begin
;
300 const char *dw_fde_current_label
;
301 const char *dw_fde_end
;
302 const char *dw_fde_vms_end_prologue
;
303 const char *dw_fde_vms_begin_epilogue
;
304 const char *dw_fde_hot_section_label
;
305 const char *dw_fde_hot_section_end_label
;
306 const char *dw_fde_unlikely_section_label
;
307 const char *dw_fde_unlikely_section_end_label
;
308 dw_cfi_ref dw_fde_cfi
;
309 dw_cfi_ref dw_fde_switch_cfi
; /* Last CFI before switching sections. */
310 HOST_WIDE_INT stack_realignment
;
311 unsigned funcdef_number
;
312 /* Dynamic realign argument pointer register. */
313 unsigned int drap_reg
;
314 /* Virtual dynamic realign argument pointer register. */
315 unsigned int vdrap_reg
;
316 /* These 3 flags are copied from rtl_data in function.h. */
317 unsigned all_throwers_are_sibcalls
: 1;
318 unsigned uses_eh_lsda
: 1;
319 unsigned nothrow
: 1;
320 /* Whether we did stack realign in this call frame. */
321 unsigned stack_realign
: 1;
322 /* Whether dynamic realign argument pointer register has been saved. */
323 unsigned drap_reg_saved
: 1;
324 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
325 unsigned in_std_section
: 1;
326 /* True iff dw_fde_unlikely_section_label is in text_section or
327 cold_text_section. */
328 unsigned cold_in_std_section
: 1;
329 /* True iff switched sections. */
330 unsigned dw_fde_switched_sections
: 1;
331 /* True iff switching from cold to hot section. */
332 unsigned dw_fde_switched_cold_to_hot
: 1;
336 /* Maximum size (in bytes) of an artificially generated label. */
337 #define MAX_ARTIFICIAL_LABEL_BYTES 30
339 /* The size of addresses as they appear in the Dwarf 2 data.
340 Some architectures use word addresses to refer to code locations,
341 but Dwarf 2 info always uses byte addresses. On such machines,
342 Dwarf 2 addresses need to be larger than the architecture's
344 #ifndef DWARF2_ADDR_SIZE
345 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
348 /* The size in bytes of a DWARF field indicating an offset or length
349 relative to a debug info section, specified to be 4 bytes in the
350 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
353 #ifndef DWARF_OFFSET_SIZE
354 #define DWARF_OFFSET_SIZE 4
357 /* The size in bytes of a DWARF 4 type signature. */
359 #ifndef DWARF_TYPE_SIGNATURE_SIZE
360 #define DWARF_TYPE_SIGNATURE_SIZE 8
363 /* According to the (draft) DWARF 3 specification, the initial length
364 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
365 bytes are 0xffffffff, followed by the length stored in the next 8
368 However, the SGI/MIPS ABI uses an initial length which is equal to
369 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
371 #ifndef DWARF_INITIAL_LENGTH_SIZE
372 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
375 /* Round SIZE up to the nearest BOUNDARY. */
376 #define DWARF_ROUND(SIZE,BOUNDARY) \
377 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
379 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
380 #ifndef DWARF_CIE_DATA_ALIGNMENT
381 #ifdef STACK_GROWS_DOWNWARD
382 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
384 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
388 /* CIE identifier. */
389 #if HOST_BITS_PER_WIDE_INT >= 64
390 #define DWARF_CIE_ID \
391 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
393 #define DWARF_CIE_ID DW_CIE_ID
396 /* A pointer to the base of a table that contains frame description
397 information for each routine. */
398 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table
;
400 /* Number of elements currently allocated for fde_table. */
401 static GTY(()) unsigned fde_table_allocated
;
403 /* Number of elements in fde_table currently in use. */
404 static GTY(()) unsigned fde_table_in_use
;
406 /* Size (in elements) of increments by which we may expand the
408 #define FDE_TABLE_INCREMENT 256
410 /* Get the current fde_table entry we should use. */
412 static inline dw_fde_ref
415 return fde_table_in_use
? &fde_table
[fde_table_in_use
- 1] : NULL
;
418 /* A list of call frame insns for the CIE. */
419 static GTY(()) dw_cfi_ref cie_cfi_head
;
421 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
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
;
429 struct GTY(()) indirect_string_node
{
431 unsigned int refcount
;
432 enum dwarf_form form
;
436 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
438 /* True if the compilation unit has location entries that reference
440 static GTY(()) bool debug_str_hash_forced
= false;
442 static GTY(()) int dw2_string_counter
;
443 static GTY(()) unsigned long dwarf2out_cfi_label_num
;
445 /* True if the compilation unit places functions in more than one section. */
446 static GTY(()) bool have_multiple_function_sections
= false;
448 /* Whether the default text and cold text sections have been used at all. */
450 static GTY(()) bool text_section_used
= false;
451 static GTY(()) bool cold_text_section_used
= false;
453 /* The default cold text section. */
454 static GTY(()) section
*cold_text_section
;
456 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
458 /* Forward declarations for functions defined in this file. */
460 static char *stripattributes (const char *);
461 static const char *dwarf_cfi_name (unsigned);
462 static dw_cfi_ref
new_cfi (void);
463 static void add_cfi (dw_cfi_ref
*, dw_cfi_ref
);
464 static void add_fde_cfi (const char *, dw_cfi_ref
);
465 static void lookup_cfa_1 (dw_cfi_ref
, dw_cfa_location
*, dw_cfa_location
*);
466 static void lookup_cfa (dw_cfa_location
*);
467 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT
);
468 #ifdef DWARF2_UNWIND_INFO
469 static void initial_return_save (rtx
);
471 static HOST_WIDE_INT
stack_adjust_offset (const_rtx
, HOST_WIDE_INT
,
473 static void output_cfi (dw_cfi_ref
, dw_fde_ref
, int);
474 static void output_cfi_directive (dw_cfi_ref
);
475 static void output_call_frame_info (int);
476 static void dwarf2out_note_section_used (void);
477 static void flush_queued_reg_saves (void);
478 static bool clobbers_queued_reg_save (const_rtx
);
479 static void dwarf2out_frame_debug_expr (rtx
, const char *);
481 /* Support for complex CFA locations. */
482 static void output_cfa_loc (dw_cfi_ref
);
483 static void output_cfa_loc_raw (dw_cfi_ref
);
484 static void get_cfa_from_loc_descr (dw_cfa_location
*,
485 struct dw_loc_descr_struct
*);
486 static struct dw_loc_descr_struct
*build_cfa_loc
487 (dw_cfa_location
*, HOST_WIDE_INT
);
488 static struct dw_loc_descr_struct
*build_cfa_aligned_loc
489 (HOST_WIDE_INT
, HOST_WIDE_INT
);
490 static void def_cfa_1 (const char *, dw_cfa_location
*);
492 /* How to start an assembler comment. */
493 #ifndef ASM_COMMENT_START
494 #define ASM_COMMENT_START ";#"
497 /* Data and reference forms for relocatable data. */
498 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
499 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
501 #ifndef DEBUG_FRAME_SECTION
502 #define DEBUG_FRAME_SECTION ".debug_frame"
505 #ifndef FUNC_BEGIN_LABEL
506 #define FUNC_BEGIN_LABEL "LFB"
509 #ifndef FUNC_END_LABEL
510 #define FUNC_END_LABEL "LFE"
513 #ifndef PROLOGUE_END_LABEL
514 #define PROLOGUE_END_LABEL "LPE"
517 #ifndef EPILOGUE_BEGIN_LABEL
518 #define EPILOGUE_BEGIN_LABEL "LEB"
521 #ifndef FRAME_BEGIN_LABEL
522 #define FRAME_BEGIN_LABEL "Lframe"
524 #define CIE_AFTER_SIZE_LABEL "LSCIE"
525 #define CIE_END_LABEL "LECIE"
526 #define FDE_LABEL "LSFDE"
527 #define FDE_AFTER_SIZE_LABEL "LASFDE"
528 #define FDE_END_LABEL "LEFDE"
529 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
530 #define LINE_NUMBER_END_LABEL "LELT"
531 #define LN_PROLOG_AS_LABEL "LASLTP"
532 #define LN_PROLOG_END_LABEL "LELTP"
533 #define DIE_LABEL_PREFIX "DW"
535 /* The DWARF 2 CFA column which tracks the return address. Normally this
536 is the column for PC, or the first column after all of the hard
538 #ifndef DWARF_FRAME_RETURN_COLUMN
540 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
542 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
546 /* The mapping from gcc register number to DWARF 2 CFA column number. By
547 default, we just provide columns for all registers. */
548 #ifndef DWARF_FRAME_REGNUM
549 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
552 /* Hook used by __throw. */
555 expand_builtin_dwarf_sp_column (void)
557 unsigned int dwarf_regnum
= DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
);
558 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum
, 1));
561 /* Return a pointer to a copy of the section string name S with all
562 attributes stripped off, and an asterisk prepended (for assemble_name). */
565 stripattributes (const char *s
)
567 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
572 while (*s
&& *s
!= ',')
579 /* MEM is a memory reference for the register size table, each element of
580 which has mode MODE. Initialize column C as a return address column. */
583 init_return_column_size (enum machine_mode mode
, rtx mem
, unsigned int c
)
585 HOST_WIDE_INT offset
= c
* GET_MODE_SIZE (mode
);
586 HOST_WIDE_INT size
= GET_MODE_SIZE (Pmode
);
587 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
590 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
592 static inline HOST_WIDE_INT
593 div_data_align (HOST_WIDE_INT off
)
595 HOST_WIDE_INT r
= off
/ DWARF_CIE_DATA_ALIGNMENT
;
596 gcc_assert (r
* DWARF_CIE_DATA_ALIGNMENT
== off
);
600 /* Return true if we need a signed version of a given opcode
601 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
604 need_data_align_sf_opcode (HOST_WIDE_INT off
)
606 return DWARF_CIE_DATA_ALIGNMENT
< 0 ? off
> 0 : off
< 0;
609 /* Generate code to initialize the register size table. */
612 expand_builtin_init_dwarf_reg_sizes (tree address
)
615 enum machine_mode mode
= TYPE_MODE (char_type_node
);
616 rtx addr
= expand_normal (address
);
617 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
618 bool wrote_return_column
= false;
620 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
622 int rnum
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i
), 1);
624 if (rnum
< DWARF_FRAME_REGISTERS
)
626 HOST_WIDE_INT offset
= rnum
* GET_MODE_SIZE (mode
);
627 enum machine_mode save_mode
= reg_raw_mode
[i
];
630 if (HARD_REGNO_CALL_PART_CLOBBERED (i
, save_mode
))
631 save_mode
= choose_hard_reg_mode (i
, 1, true);
632 if (DWARF_FRAME_REGNUM (i
) == DWARF_FRAME_RETURN_COLUMN
)
634 if (save_mode
== VOIDmode
)
636 wrote_return_column
= true;
638 size
= GET_MODE_SIZE (save_mode
);
642 emit_move_insn (adjust_address (mem
, mode
, offset
),
643 gen_int_mode (size
, mode
));
647 if (!wrote_return_column
)
648 init_return_column_size (mode
, mem
, DWARF_FRAME_RETURN_COLUMN
);
650 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
651 init_return_column_size (mode
, mem
, DWARF_ALT_FRAME_RETURN_COLUMN
);
654 targetm
.init_dwarf_reg_sizes_extra (address
);
657 /* Convert a DWARF call frame info. operation to its string name */
660 dwarf_cfi_name (unsigned int cfi_opc
)
664 case DW_CFA_advance_loc
:
665 return "DW_CFA_advance_loc";
667 return "DW_CFA_offset";
669 return "DW_CFA_restore";
673 return "DW_CFA_set_loc";
674 case DW_CFA_advance_loc1
:
675 return "DW_CFA_advance_loc1";
676 case DW_CFA_advance_loc2
:
677 return "DW_CFA_advance_loc2";
678 case DW_CFA_advance_loc4
:
679 return "DW_CFA_advance_loc4";
680 case DW_CFA_offset_extended
:
681 return "DW_CFA_offset_extended";
682 case DW_CFA_restore_extended
:
683 return "DW_CFA_restore_extended";
684 case DW_CFA_undefined
:
685 return "DW_CFA_undefined";
686 case DW_CFA_same_value
:
687 return "DW_CFA_same_value";
688 case DW_CFA_register
:
689 return "DW_CFA_register";
690 case DW_CFA_remember_state
:
691 return "DW_CFA_remember_state";
692 case DW_CFA_restore_state
:
693 return "DW_CFA_restore_state";
695 return "DW_CFA_def_cfa";
696 case DW_CFA_def_cfa_register
:
697 return "DW_CFA_def_cfa_register";
698 case DW_CFA_def_cfa_offset
:
699 return "DW_CFA_def_cfa_offset";
702 case DW_CFA_def_cfa_expression
:
703 return "DW_CFA_def_cfa_expression";
704 case DW_CFA_expression
:
705 return "DW_CFA_expression";
706 case DW_CFA_offset_extended_sf
:
707 return "DW_CFA_offset_extended_sf";
708 case DW_CFA_def_cfa_sf
:
709 return "DW_CFA_def_cfa_sf";
710 case DW_CFA_def_cfa_offset_sf
:
711 return "DW_CFA_def_cfa_offset_sf";
713 /* SGI/MIPS specific */
714 case DW_CFA_MIPS_advance_loc8
:
715 return "DW_CFA_MIPS_advance_loc8";
718 case DW_CFA_GNU_window_save
:
719 return "DW_CFA_GNU_window_save";
720 case DW_CFA_GNU_args_size
:
721 return "DW_CFA_GNU_args_size";
722 case DW_CFA_GNU_negative_offset_extended
:
723 return "DW_CFA_GNU_negative_offset_extended";
726 return "DW_CFA_<unknown>";
730 /* Return a pointer to a newly allocated Call Frame Instruction. */
732 static inline dw_cfi_ref
735 dw_cfi_ref cfi
= ggc_alloc_dw_cfi_node ();
737 cfi
->dw_cfi_next
= NULL
;
738 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
739 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
744 /* Add a Call Frame Instruction to list of instructions. */
747 add_cfi (dw_cfi_ref
*list_head
, dw_cfi_ref cfi
)
750 dw_fde_ref fde
= current_fde ();
752 /* When DRAP is used, CFA is defined with an expression. Redefine
753 CFA may lead to a different CFA value. */
754 /* ??? Of course, this heuristic fails when we're annotating epilogues,
755 because of course we'll always want to redefine the CFA back to the
756 stack pointer on the way out. Where should we move this check? */
757 if (0 && fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
758 switch (cfi
->dw_cfi_opc
)
760 case DW_CFA_def_cfa_register
:
761 case DW_CFA_def_cfa_offset
:
762 case DW_CFA_def_cfa_offset_sf
:
764 case DW_CFA_def_cfa_sf
:
771 /* Find the end of the chain. */
772 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
778 /* Generate a new label for the CFI info to refer to. FORCE is true
779 if a label needs to be output even when using .cfi_* directives. */
782 dwarf2out_cfi_label (bool force
)
784 static char label
[20];
786 if (!force
&& dwarf2out_do_cfi_asm ())
788 /* In this case, we will be emitting the asm directive instead of
789 the label, so just return a placeholder to keep the rest of the
791 strcpy (label
, "<do not output>");
795 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", dwarf2out_cfi_label_num
++);
796 ASM_OUTPUT_LABEL (asm_out_file
, label
);
802 /* True if remember_state should be emitted before following CFI directive. */
803 static bool emit_cfa_remember
;
805 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
806 or to the CIE if LABEL is NULL. */
809 add_fde_cfi (const char *label
, dw_cfi_ref cfi
)
811 dw_cfi_ref
*list_head
;
813 if (emit_cfa_remember
)
815 dw_cfi_ref cfi_remember
;
817 /* Emit the state save. */
818 emit_cfa_remember
= false;
819 cfi_remember
= new_cfi ();
820 cfi_remember
->dw_cfi_opc
= DW_CFA_remember_state
;
821 add_fde_cfi (label
, cfi_remember
);
824 list_head
= &cie_cfi_head
;
826 if (dwarf2out_do_cfi_asm ())
830 dw_fde_ref fde
= current_fde ();
832 gcc_assert (fde
!= NULL
);
834 /* We still have to add the cfi to the list so that lookup_cfa
835 works later on. When -g2 and above we even need to force
836 emitting of CFI labels and add to list a DW_CFA_set_loc for
837 convert_cfa_to_fb_loc_list purposes. If we're generating
838 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
839 convert_cfa_to_fb_loc_list. */
840 if (dwarf_version
== 2
841 && debug_info_level
> DINFO_LEVEL_TERSE
842 && (write_symbols
== DWARF2_DEBUG
843 || write_symbols
== VMS_AND_DWARF2_DEBUG
))
845 switch (cfi
->dw_cfi_opc
)
847 case DW_CFA_def_cfa_offset
:
848 case DW_CFA_def_cfa_offset_sf
:
849 case DW_CFA_def_cfa_register
:
851 case DW_CFA_def_cfa_sf
:
852 case DW_CFA_def_cfa_expression
:
853 case DW_CFA_restore_state
:
854 if (*label
== 0 || strcmp (label
, "<do not output>") == 0)
855 label
= dwarf2out_cfi_label (true);
857 if (fde
->dw_fde_current_label
== NULL
858 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
862 label
= xstrdup (label
);
864 /* Set the location counter to the new label. */
866 /* It doesn't metter whether DW_CFA_set_loc
867 or DW_CFA_advance_loc4 is added here, those aren't
868 emitted into assembly, only looked up by
869 convert_cfa_to_fb_loc_list. */
870 xcfi
->dw_cfi_opc
= DW_CFA_set_loc
;
871 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
872 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
873 fde
->dw_fde_current_label
= label
;
881 output_cfi_directive (cfi
);
883 list_head
= &fde
->dw_fde_cfi
;
885 /* ??? If this is a CFI for the CIE, we don't emit. This
886 assumes that the standard CIE contents that the assembler
887 uses matches the standard CIE contents that the compiler
888 uses. This is probably a bad assumption. I'm not quite
889 sure how to address this for now. */
893 dw_fde_ref fde
= current_fde ();
895 gcc_assert (fde
!= NULL
);
898 label
= dwarf2out_cfi_label (false);
900 if (fde
->dw_fde_current_label
== NULL
901 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
905 label
= xstrdup (label
);
907 /* Set the location counter to the new label. */
909 /* If we have a current label, advance from there, otherwise
910 set the location directly using set_loc. */
911 xcfi
->dw_cfi_opc
= fde
->dw_fde_current_label
912 ? DW_CFA_advance_loc4
914 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
915 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
917 fde
->dw_fde_current_label
= label
;
920 list_head
= &fde
->dw_fde_cfi
;
923 add_cfi (list_head
, cfi
);
926 /* Subroutine of lookup_cfa. */
929 lookup_cfa_1 (dw_cfi_ref cfi
, dw_cfa_location
*loc
, dw_cfa_location
*remember
)
931 switch (cfi
->dw_cfi_opc
)
933 case DW_CFA_def_cfa_offset
:
934 case DW_CFA_def_cfa_offset_sf
:
935 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
937 case DW_CFA_def_cfa_register
:
938 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
941 case DW_CFA_def_cfa_sf
:
942 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
943 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
945 case DW_CFA_def_cfa_expression
:
946 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
949 case DW_CFA_remember_state
:
950 gcc_assert (!remember
->in_use
);
952 remember
->in_use
= 1;
954 case DW_CFA_restore_state
:
955 gcc_assert (remember
->in_use
);
957 remember
->in_use
= 0;
965 /* Find the previous value for the CFA. */
968 lookup_cfa (dw_cfa_location
*loc
)
972 dw_cfa_location remember
;
974 memset (loc
, 0, sizeof (*loc
));
975 loc
->reg
= INVALID_REGNUM
;
978 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
979 lookup_cfa_1 (cfi
, loc
, &remember
);
981 fde
= current_fde ();
983 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
984 lookup_cfa_1 (cfi
, loc
, &remember
);
987 /* The current rule for calculating the DWARF2 canonical frame address. */
988 static dw_cfa_location cfa
;
990 /* The register used for saving registers to the stack, and its offset
992 static dw_cfa_location cfa_store
;
994 /* The current save location around an epilogue. */
995 static dw_cfa_location cfa_remember
;
997 /* The running total of the size of arguments pushed onto the stack. */
998 static HOST_WIDE_INT args_size
;
1000 /* The last args_size we actually output. */
1001 static HOST_WIDE_INT old_args_size
;
1003 /* Entry point to update the canonical frame address (CFA).
1004 LABEL is passed to add_fde_cfi. The value of CFA is now to be
1005 calculated from REG+OFFSET. */
1008 dwarf2out_def_cfa (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
1010 dw_cfa_location loc
;
1012 loc
.base_offset
= 0;
1014 loc
.offset
= offset
;
1015 def_cfa_1 (label
, &loc
);
1018 /* Determine if two dw_cfa_location structures define the same data. */
1021 cfa_equal_p (const dw_cfa_location
*loc1
, const dw_cfa_location
*loc2
)
1023 return (loc1
->reg
== loc2
->reg
1024 && loc1
->offset
== loc2
->offset
1025 && loc1
->indirect
== loc2
->indirect
1026 && (loc1
->indirect
== 0
1027 || loc1
->base_offset
== loc2
->base_offset
));
1030 /* This routine does the actual work. The CFA is now calculated from
1031 the dw_cfa_location structure. */
1034 def_cfa_1 (const char *label
, dw_cfa_location
*loc_p
)
1037 dw_cfa_location old_cfa
, loc
;
1042 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
1043 cfa_store
.offset
= loc
.offset
;
1045 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
1046 lookup_cfa (&old_cfa
);
1048 /* If nothing changed, no need to issue any call frame instructions. */
1049 if (cfa_equal_p (&loc
, &old_cfa
))
1054 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
&& !old_cfa
.indirect
)
1056 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1057 the CFA register did not change but the offset did. The data
1058 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1059 in the assembler via the .cfi_def_cfa_offset directive. */
1061 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset_sf
;
1063 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
1064 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
1067 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1068 else if (loc
.offset
== old_cfa
.offset
1069 && old_cfa
.reg
!= INVALID_REGNUM
1071 && !old_cfa
.indirect
)
1073 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1074 indicating the CFA register has changed to <register> but the
1075 offset has not changed. */
1076 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
1077 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
1081 else if (loc
.indirect
== 0)
1083 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1084 indicating the CFA register has changed to <register> with
1085 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1086 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1089 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_sf
;
1091 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
1092 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
1093 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
1097 /* Construct a DW_CFA_def_cfa_expression instruction to
1098 calculate the CFA using a full location expression since no
1099 register-offset pair is available. */
1100 struct dw_loc_descr_struct
*loc_list
;
1102 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
1103 loc_list
= build_cfa_loc (&loc
, 0);
1104 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
1107 add_fde_cfi (label
, cfi
);
1110 /* Add the CFI for saving a register. REG is the CFA column number.
1111 LABEL is passed to add_fde_cfi.
1112 If SREG is -1, the register is saved at OFFSET from the CFA;
1113 otherwise it is saved in SREG. */
1116 reg_save (const char *label
, unsigned int reg
, unsigned int sreg
, HOST_WIDE_INT offset
)
1118 dw_cfi_ref cfi
= new_cfi ();
1119 dw_fde_ref fde
= current_fde ();
1121 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
1123 /* When stack is aligned, store REG using DW_CFA_expression with
1126 && fde
->stack_realign
1127 && sreg
== INVALID_REGNUM
)
1129 cfi
->dw_cfi_opc
= DW_CFA_expression
;
1130 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
1131 cfi
->dw_cfi_oprnd2
.dw_cfi_loc
1132 = build_cfa_aligned_loc (offset
, fde
->stack_realignment
);
1134 else if (sreg
== INVALID_REGNUM
)
1136 if (need_data_align_sf_opcode (offset
))
1137 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
1138 else if (reg
& ~0x3f)
1139 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
1141 cfi
->dw_cfi_opc
= DW_CFA_offset
;
1142 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
1144 else if (sreg
== reg
)
1145 cfi
->dw_cfi_opc
= DW_CFA_same_value
;
1148 cfi
->dw_cfi_opc
= DW_CFA_register
;
1149 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
1152 add_fde_cfi (label
, cfi
);
1155 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1156 This CFI tells the unwinder that it needs to restore the window registers
1157 from the previous frame's window save area.
1159 ??? Perhaps we should note in the CIE where windows are saved (instead of
1160 assuming 0(cfa)) and what registers are in the window. */
1163 dwarf2out_window_save (const char *label
)
1165 dw_cfi_ref cfi
= new_cfi ();
1167 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
1168 add_fde_cfi (label
, cfi
);
1171 /* Entry point for saving a register to the stack. REG is the GCC register
1172 number. LABEL and OFFSET are passed to reg_save. */
1175 dwarf2out_reg_save (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
1177 reg_save (label
, DWARF_FRAME_REGNUM (reg
), INVALID_REGNUM
, offset
);
1180 /* Entry point for saving the return address in the stack.
1181 LABEL and OFFSET are passed to reg_save. */
1184 dwarf2out_return_save (const char *label
, HOST_WIDE_INT offset
)
1186 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, INVALID_REGNUM
, offset
);
1189 /* Entry point for saving the return address in a register.
1190 LABEL and SREG are passed to reg_save. */
1193 dwarf2out_return_reg (const char *label
, unsigned int sreg
)
1195 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, DWARF_FRAME_REGNUM (sreg
), 0);
1198 #ifdef DWARF2_UNWIND_INFO
1199 /* Record the initial position of the return address. RTL is
1200 INCOMING_RETURN_ADDR_RTX. */
1203 initial_return_save (rtx rtl
)
1205 unsigned int reg
= INVALID_REGNUM
;
1206 HOST_WIDE_INT offset
= 0;
1208 switch (GET_CODE (rtl
))
1211 /* RA is in a register. */
1212 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
1216 /* RA is on the stack. */
1217 rtl
= XEXP (rtl
, 0);
1218 switch (GET_CODE (rtl
))
1221 gcc_assert (REGNO (rtl
) == STACK_POINTER_REGNUM
);
1226 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
1227 offset
= INTVAL (XEXP (rtl
, 1));
1231 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
1232 offset
= -INTVAL (XEXP (rtl
, 1));
1242 /* The return address is at some offset from any value we can
1243 actually load. For instance, on the SPARC it is in %i7+8. Just
1244 ignore the offset for now; it doesn't matter for unwinding frames. */
1245 gcc_assert (CONST_INT_P (XEXP (rtl
, 1)));
1246 initial_return_save (XEXP (rtl
, 0));
1253 if (reg
!= DWARF_FRAME_RETURN_COLUMN
)
1254 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
1258 /* Given a SET, calculate the amount of stack adjustment it
1261 static HOST_WIDE_INT
1262 stack_adjust_offset (const_rtx pattern
, HOST_WIDE_INT cur_args_size
,
1263 HOST_WIDE_INT cur_offset
)
1265 const_rtx src
= SET_SRC (pattern
);
1266 const_rtx dest
= SET_DEST (pattern
);
1267 HOST_WIDE_INT offset
= 0;
1270 if (dest
== stack_pointer_rtx
)
1272 code
= GET_CODE (src
);
1274 /* Assume (set (reg sp) (reg whatever)) sets args_size
1276 if (code
== REG
&& src
!= stack_pointer_rtx
)
1278 offset
= -cur_args_size
;
1279 #ifndef STACK_GROWS_DOWNWARD
1282 return offset
- cur_offset
;
1285 if (! (code
== PLUS
|| code
== MINUS
)
1286 || XEXP (src
, 0) != stack_pointer_rtx
1287 || !CONST_INT_P (XEXP (src
, 1)))
1290 /* (set (reg sp) (plus (reg sp) (const_int))) */
1291 offset
= INTVAL (XEXP (src
, 1));
1297 if (MEM_P (src
) && !MEM_P (dest
))
1301 /* (set (mem (pre_dec (reg sp))) (foo)) */
1302 src
= XEXP (dest
, 0);
1303 code
= GET_CODE (src
);
1309 if (XEXP (src
, 0) == stack_pointer_rtx
)
1311 rtx val
= XEXP (XEXP (src
, 1), 1);
1312 /* We handle only adjustments by constant amount. */
1313 gcc_assert (GET_CODE (XEXP (src
, 1)) == PLUS
1314 && CONST_INT_P (val
));
1315 offset
= -INTVAL (val
);
1322 if (XEXP (src
, 0) == stack_pointer_rtx
)
1324 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1331 if (XEXP (src
, 0) == stack_pointer_rtx
)
1333 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
1348 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1349 indexed by INSN_UID. */
1351 static HOST_WIDE_INT
*barrier_args_size
;
1353 /* Helper function for compute_barrier_args_size. Handle one insn. */
1355 static HOST_WIDE_INT
1356 compute_barrier_args_size_1 (rtx insn
, HOST_WIDE_INT cur_args_size
,
1357 VEC (rtx
, heap
) **next
)
1359 HOST_WIDE_INT offset
= 0;
1362 if (! RTX_FRAME_RELATED_P (insn
))
1364 if (prologue_epilogue_contains (insn
))
1366 else if (GET_CODE (PATTERN (insn
)) == SET
)
1367 offset
= stack_adjust_offset (PATTERN (insn
), cur_args_size
, 0);
1368 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1369 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1371 /* There may be stack adjustments inside compound insns. Search
1373 for (i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1374 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1375 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
),
1376 cur_args_size
, offset
);
1381 rtx expr
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1385 expr
= XEXP (expr
, 0);
1386 if (GET_CODE (expr
) == PARALLEL
1387 || GET_CODE (expr
) == SEQUENCE
)
1388 for (i
= 1; i
< XVECLEN (expr
, 0); i
++)
1390 rtx elem
= XVECEXP (expr
, 0, i
);
1392 if (GET_CODE (elem
) == SET
&& !RTX_FRAME_RELATED_P (elem
))
1393 offset
+= stack_adjust_offset (elem
, cur_args_size
, offset
);
1398 #ifndef STACK_GROWS_DOWNWARD
1402 cur_args_size
+= offset
;
1403 if (cur_args_size
< 0)
1408 rtx dest
= JUMP_LABEL (insn
);
1412 if (barrier_args_size
[INSN_UID (dest
)] < 0)
1414 barrier_args_size
[INSN_UID (dest
)] = cur_args_size
;
1415 VEC_safe_push (rtx
, heap
, *next
, dest
);
1420 return cur_args_size
;
1423 /* Walk the whole function and compute args_size on BARRIERs. */
1426 compute_barrier_args_size (void)
1428 int max_uid
= get_max_uid (), i
;
1430 VEC (rtx
, heap
) *worklist
, *next
, *tmp
;
1432 barrier_args_size
= XNEWVEC (HOST_WIDE_INT
, max_uid
);
1433 for (i
= 0; i
< max_uid
; i
++)
1434 barrier_args_size
[i
] = -1;
1436 worklist
= VEC_alloc (rtx
, heap
, 20);
1437 next
= VEC_alloc (rtx
, heap
, 20);
1438 insn
= get_insns ();
1439 barrier_args_size
[INSN_UID (insn
)] = 0;
1440 VEC_quick_push (rtx
, worklist
, insn
);
1443 while (!VEC_empty (rtx
, worklist
))
1445 rtx prev
, body
, first_insn
;
1446 HOST_WIDE_INT cur_args_size
;
1448 first_insn
= insn
= VEC_pop (rtx
, worklist
);
1449 cur_args_size
= barrier_args_size
[INSN_UID (insn
)];
1450 prev
= prev_nonnote_insn (insn
);
1451 if (prev
&& BARRIER_P (prev
))
1452 barrier_args_size
[INSN_UID (prev
)] = cur_args_size
;
1454 for (; insn
; insn
= NEXT_INSN (insn
))
1456 if (INSN_DELETED_P (insn
) || NOTE_P (insn
))
1458 if (BARRIER_P (insn
))
1463 if (insn
== first_insn
)
1465 else if (barrier_args_size
[INSN_UID (insn
)] < 0)
1467 barrier_args_size
[INSN_UID (insn
)] = cur_args_size
;
1472 /* The insns starting with this label have been
1473 already scanned or are in the worklist. */
1478 body
= PATTERN (insn
);
1479 if (GET_CODE (body
) == SEQUENCE
)
1481 HOST_WIDE_INT dest_args_size
= cur_args_size
;
1482 for (i
= 1; i
< XVECLEN (body
, 0); i
++)
1483 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body
, 0, 0))
1484 && INSN_FROM_TARGET_P (XVECEXP (body
, 0, i
)))
1486 = compute_barrier_args_size_1 (XVECEXP (body
, 0, i
),
1487 dest_args_size
, &next
);
1490 = compute_barrier_args_size_1 (XVECEXP (body
, 0, i
),
1491 cur_args_size
, &next
);
1493 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body
, 0, 0)))
1494 compute_barrier_args_size_1 (XVECEXP (body
, 0, 0),
1495 dest_args_size
, &next
);
1498 = compute_barrier_args_size_1 (XVECEXP (body
, 0, 0),
1499 cur_args_size
, &next
);
1503 = compute_barrier_args_size_1 (insn
, cur_args_size
, &next
);
1507 if (VEC_empty (rtx
, next
))
1510 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1514 VEC_truncate (rtx
, next
, 0);
1517 VEC_free (rtx
, heap
, worklist
);
1518 VEC_free (rtx
, heap
, next
);
1521 /* Add a CFI to update the running total of the size of arguments
1522 pushed onto the stack. */
1525 dwarf2out_args_size (const char *label
, HOST_WIDE_INT size
)
1529 if (size
== old_args_size
)
1532 old_args_size
= size
;
1535 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
1536 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
1537 add_fde_cfi (label
, cfi
);
1540 /* Record a stack adjustment of OFFSET bytes. */
1543 dwarf2out_stack_adjust (HOST_WIDE_INT offset
, const char *label
)
1545 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1546 cfa
.offset
+= offset
;
1548 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1549 cfa_store
.offset
+= offset
;
1551 if (ACCUMULATE_OUTGOING_ARGS
)
1554 #ifndef STACK_GROWS_DOWNWARD
1558 args_size
+= offset
;
1562 def_cfa_1 (label
, &cfa
);
1563 if (flag_asynchronous_unwind_tables
)
1564 dwarf2out_args_size (label
, args_size
);
1567 /* Check INSN to see if it looks like a push or a stack adjustment, and
1568 make a note of it if it does. EH uses this information to find out
1569 how much extra space it needs to pop off the stack. */
1572 dwarf2out_notice_stack_adjust (rtx insn
, bool after_p
)
1574 HOST_WIDE_INT offset
;
1578 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1579 with this function. Proper support would require all frame-related
1580 insns to be marked, and to be able to handle saving state around
1581 epilogues textually in the middle of the function. */
1582 if (prologue_epilogue_contains (insn
))
1585 /* If INSN is an instruction from target of an annulled branch, the
1586 effects are for the target only and so current argument size
1587 shouldn't change at all. */
1589 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence
, 0, 0))
1590 && INSN_FROM_TARGET_P (insn
))
1593 /* If only calls can throw, and we have a frame pointer,
1594 save up adjustments until we see the CALL_INSN. */
1595 if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1597 if (CALL_P (insn
) && !after_p
)
1599 /* Extract the size of the args from the CALL rtx itself. */
1600 insn
= PATTERN (insn
);
1601 if (GET_CODE (insn
) == PARALLEL
)
1602 insn
= XVECEXP (insn
, 0, 0);
1603 if (GET_CODE (insn
) == SET
)
1604 insn
= SET_SRC (insn
);
1605 gcc_assert (GET_CODE (insn
) == CALL
);
1606 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1611 if (CALL_P (insn
) && !after_p
)
1613 if (!flag_asynchronous_unwind_tables
)
1614 dwarf2out_args_size ("", args_size
);
1617 else if (BARRIER_P (insn
))
1619 /* Don't call compute_barrier_args_size () if the only
1620 BARRIER is at the end of function. */
1621 if (barrier_args_size
== NULL
&& next_nonnote_insn (insn
))
1622 compute_barrier_args_size ();
1623 if (barrier_args_size
== NULL
)
1627 offset
= barrier_args_size
[INSN_UID (insn
)];
1632 offset
-= args_size
;
1633 #ifndef STACK_GROWS_DOWNWARD
1637 else if (GET_CODE (PATTERN (insn
)) == SET
)
1638 offset
= stack_adjust_offset (PATTERN (insn
), args_size
, 0);
1639 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1640 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1642 /* There may be stack adjustments inside compound insns. Search
1644 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1645 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1646 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
),
1655 label
= dwarf2out_cfi_label (false);
1656 dwarf2out_stack_adjust (offset
, label
);
1661 /* We delay emitting a register save until either (a) we reach the end
1662 of the prologue or (b) the register is clobbered. This clusters
1663 register saves so that there are fewer pc advances. */
1665 struct GTY(()) queued_reg_save
{
1666 struct queued_reg_save
*next
;
1668 HOST_WIDE_INT cfa_offset
;
1672 static GTY(()) struct queued_reg_save
*queued_reg_saves
;
1674 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1675 struct GTY(()) reg_saved_in_data
{
1680 /* A list of registers saved in other registers.
1681 The list intentionally has a small maximum capacity of 4; if your
1682 port needs more than that, you might consider implementing a
1683 more efficient data structure. */
1684 static GTY(()) struct reg_saved_in_data regs_saved_in_regs
[4];
1685 static GTY(()) size_t num_regs_saved_in_regs
;
1687 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1688 static const char *last_reg_save_label
;
1690 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1691 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1694 queue_reg_save (const char *label
, rtx reg
, rtx sreg
, HOST_WIDE_INT offset
)
1696 struct queued_reg_save
*q
;
1698 /* Duplicates waste space, but it's also necessary to remove them
1699 for correctness, since the queue gets output in reverse
1701 for (q
= queued_reg_saves
; q
!= NULL
; q
= q
->next
)
1702 if (REGNO (q
->reg
) == REGNO (reg
))
1707 q
= ggc_alloc_queued_reg_save ();
1708 q
->next
= queued_reg_saves
;
1709 queued_reg_saves
= q
;
1713 q
->cfa_offset
= offset
;
1714 q
->saved_reg
= sreg
;
1716 last_reg_save_label
= label
;
1719 /* Output all the entries in QUEUED_REG_SAVES. */
1722 flush_queued_reg_saves (void)
1724 struct queued_reg_save
*q
;
1726 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1729 unsigned int reg
, sreg
;
1731 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1732 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (q
->reg
))
1734 if (q
->saved_reg
&& i
== num_regs_saved_in_regs
)
1736 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1737 num_regs_saved_in_regs
++;
1739 if (i
!= num_regs_saved_in_regs
)
1741 regs_saved_in_regs
[i
].orig_reg
= q
->reg
;
1742 regs_saved_in_regs
[i
].saved_in_reg
= q
->saved_reg
;
1745 reg
= DWARF_FRAME_REGNUM (REGNO (q
->reg
));
1747 sreg
= DWARF_FRAME_REGNUM (REGNO (q
->saved_reg
));
1749 sreg
= INVALID_REGNUM
;
1750 reg_save (last_reg_save_label
, reg
, sreg
, q
->cfa_offset
);
1753 queued_reg_saves
= NULL
;
1754 last_reg_save_label
= NULL
;
1757 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1758 location for? Or, does it clobber a register which we've previously
1759 said that some other register is saved in, and for which we now
1760 have a new location for? */
1763 clobbers_queued_reg_save (const_rtx insn
)
1765 struct queued_reg_save
*q
;
1767 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1770 if (modified_in_p (q
->reg
, insn
))
1772 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1773 if (REGNO (q
->reg
) == REGNO (regs_saved_in_regs
[i
].orig_reg
)
1774 && modified_in_p (regs_saved_in_regs
[i
].saved_in_reg
, insn
))
1781 /* Entry point for saving the first register into the second. */
1784 dwarf2out_reg_save_reg (const char *label
, rtx reg
, rtx sreg
)
1787 unsigned int regno
, sregno
;
1789 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1790 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (reg
))
1792 if (i
== num_regs_saved_in_regs
)
1794 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1795 num_regs_saved_in_regs
++;
1797 regs_saved_in_regs
[i
].orig_reg
= reg
;
1798 regs_saved_in_regs
[i
].saved_in_reg
= sreg
;
1800 regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
1801 sregno
= DWARF_FRAME_REGNUM (REGNO (sreg
));
1802 reg_save (label
, regno
, sregno
, 0);
1805 /* What register, if any, is currently saved in REG? */
1808 reg_saved_in (rtx reg
)
1810 unsigned int regn
= REGNO (reg
);
1812 struct queued_reg_save
*q
;
1814 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1815 if (q
->saved_reg
&& regn
== REGNO (q
->saved_reg
))
1818 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1819 if (regs_saved_in_regs
[i
].saved_in_reg
1820 && regn
== REGNO (regs_saved_in_regs
[i
].saved_in_reg
))
1821 return regs_saved_in_regs
[i
].orig_reg
;
1827 /* A temporary register holding an integral value used in adjusting SP
1828 or setting up the store_reg. The "offset" field holds the integer
1829 value, not an offset. */
1830 static dw_cfa_location cfa_temp
;
1832 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1835 dwarf2out_frame_debug_def_cfa (rtx pat
, const char *label
)
1837 memset (&cfa
, 0, sizeof (cfa
));
1839 switch (GET_CODE (pat
))
1842 cfa
.reg
= REGNO (XEXP (pat
, 0));
1843 cfa
.offset
= INTVAL (XEXP (pat
, 1));
1847 cfa
.reg
= REGNO (pat
);
1851 /* Recurse and define an expression. */
1855 def_cfa_1 (label
, &cfa
);
1858 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1861 dwarf2out_frame_debug_adjust_cfa (rtx pat
, const char *label
)
1865 gcc_assert (GET_CODE (pat
) == SET
);
1866 dest
= XEXP (pat
, 0);
1867 src
= XEXP (pat
, 1);
1869 switch (GET_CODE (src
))
1872 gcc_assert (REGNO (XEXP (src
, 0)) == cfa
.reg
);
1873 cfa
.offset
-= INTVAL (XEXP (src
, 1));
1883 cfa
.reg
= REGNO (dest
);
1884 gcc_assert (cfa
.indirect
== 0);
1886 def_cfa_1 (label
, &cfa
);
1889 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1892 dwarf2out_frame_debug_cfa_offset (rtx set
, const char *label
)
1894 HOST_WIDE_INT offset
;
1895 rtx src
, addr
, span
;
1897 src
= XEXP (set
, 1);
1898 addr
= XEXP (set
, 0);
1899 gcc_assert (MEM_P (addr
));
1900 addr
= XEXP (addr
, 0);
1902 /* As documented, only consider extremely simple addresses. */
1903 switch (GET_CODE (addr
))
1906 gcc_assert (REGNO (addr
) == cfa
.reg
);
1907 offset
= -cfa
.offset
;
1910 gcc_assert (REGNO (XEXP (addr
, 0)) == cfa
.reg
);
1911 offset
= INTVAL (XEXP (addr
, 1)) - cfa
.offset
;
1917 span
= targetm
.dwarf_register_span (src
);
1919 /* ??? We'd like to use queue_reg_save, but we need to come up with
1920 a different flushing heuristic for epilogues. */
1922 reg_save (label
, DWARF_FRAME_REGNUM (REGNO (src
)), INVALID_REGNUM
, offset
);
1925 /* We have a PARALLEL describing where the contents of SRC live.
1926 Queue register saves for each piece of the PARALLEL. */
1929 HOST_WIDE_INT span_offset
= offset
;
1931 gcc_assert (GET_CODE (span
) == PARALLEL
);
1933 limit
= XVECLEN (span
, 0);
1934 for (par_index
= 0; par_index
< limit
; par_index
++)
1936 rtx elem
= XVECEXP (span
, 0, par_index
);
1938 reg_save (label
, DWARF_FRAME_REGNUM (REGNO (elem
)),
1939 INVALID_REGNUM
, span_offset
);
1940 span_offset
+= GET_MODE_SIZE (GET_MODE (elem
));
1945 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
1948 dwarf2out_frame_debug_cfa_register (rtx set
, const char *label
)
1951 unsigned sregno
, dregno
;
1953 src
= XEXP (set
, 1);
1954 dest
= XEXP (set
, 0);
1957 sregno
= DWARF_FRAME_RETURN_COLUMN
;
1959 sregno
= DWARF_FRAME_REGNUM (REGNO (src
));
1961 dregno
= DWARF_FRAME_REGNUM (REGNO (dest
));
1963 /* ??? We'd like to use queue_reg_save, but we need to come up with
1964 a different flushing heuristic for epilogues. */
1965 reg_save (label
, sregno
, dregno
, 0);
1968 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
1971 dwarf2out_frame_debug_cfa_restore (rtx reg
, const char *label
)
1973 dw_cfi_ref cfi
= new_cfi ();
1974 unsigned int regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
1976 cfi
->dw_cfi_opc
= (regno
& ~0x3f ? DW_CFA_restore_extended
: DW_CFA_restore
);
1977 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= regno
;
1979 add_fde_cfi (label
, cfi
);
1982 /* Record call frame debugging information for an expression EXPR,
1983 which either sets SP or FP (adjusting how we calculate the frame
1984 address) or saves a register to the stack or another register.
1985 LABEL indicates the address of EXPR.
1987 This function encodes a state machine mapping rtxes to actions on
1988 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1989 users need not read the source code.
1991 The High-Level Picture
1993 Changes in the register we use to calculate the CFA: Currently we
1994 assume that if you copy the CFA register into another register, we
1995 should take the other one as the new CFA register; this seems to
1996 work pretty well. If it's wrong for some target, it's simple
1997 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1999 Changes in the register we use for saving registers to the stack:
2000 This is usually SP, but not always. Again, we deduce that if you
2001 copy SP into another register (and SP is not the CFA register),
2002 then the new register is the one we will be using for register
2003 saves. This also seems to work.
2005 Register saves: There's not much guesswork about this one; if
2006 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
2007 register save, and the register used to calculate the destination
2008 had better be the one we think we're using for this purpose.
2009 It's also assumed that a copy from a call-saved register to another
2010 register is saving that register if RTX_FRAME_RELATED_P is set on
2011 that instruction. If the copy is from a call-saved register to
2012 the *same* register, that means that the register is now the same
2013 value as in the caller.
2015 Except: If the register being saved is the CFA register, and the
2016 offset is nonzero, we are saving the CFA, so we assume we have to
2017 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
2018 the intent is to save the value of SP from the previous frame.
2020 In addition, if a register has previously been saved to a different
2023 Invariants / Summaries of Rules
2025 cfa current rule for calculating the CFA. It usually
2026 consists of a register and an offset.
2027 cfa_store register used by prologue code to save things to the stack
2028 cfa_store.offset is the offset from the value of
2029 cfa_store.reg to the actual CFA
2030 cfa_temp register holding an integral value. cfa_temp.offset
2031 stores the value, which will be used to adjust the
2032 stack pointer. cfa_temp is also used like cfa_store,
2033 to track stores to the stack via fp or a temp reg.
2035 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2036 with cfa.reg as the first operand changes the cfa.reg and its
2037 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2040 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2041 expression yielding a constant. This sets cfa_temp.reg
2042 and cfa_temp.offset.
2044 Rule 5: Create a new register cfa_store used to save items to the
2047 Rules 10-14: Save a register to the stack. Define offset as the
2048 difference of the original location and cfa_store's
2049 location (or cfa_temp's location if cfa_temp is used).
2051 Rules 16-20: If AND operation happens on sp in prologue, we assume
2052 stack is realigned. We will use a group of DW_OP_XXX
2053 expressions to represent the location of the stored
2054 register instead of CFA+offset.
2058 "{a,b}" indicates a choice of a xor b.
2059 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2062 (set <reg1> <reg2>:cfa.reg)
2063 effects: cfa.reg = <reg1>
2064 cfa.offset unchanged
2065 cfa_temp.reg = <reg1>
2066 cfa_temp.offset = cfa.offset
2069 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2070 {<const_int>,<reg>:cfa_temp.reg}))
2071 effects: cfa.reg = sp if fp used
2072 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2073 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2074 if cfa_store.reg==sp
2077 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2078 effects: cfa.reg = fp
2079 cfa_offset += +/- <const_int>
2082 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2083 constraints: <reg1> != fp
2085 effects: cfa.reg = <reg1>
2086 cfa_temp.reg = <reg1>
2087 cfa_temp.offset = cfa.offset
2090 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2091 constraints: <reg1> != fp
2093 effects: cfa_store.reg = <reg1>
2094 cfa_store.offset = cfa.offset - cfa_temp.offset
2097 (set <reg> <const_int>)
2098 effects: cfa_temp.reg = <reg>
2099 cfa_temp.offset = <const_int>
2102 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2103 effects: cfa_temp.reg = <reg1>
2104 cfa_temp.offset |= <const_int>
2107 (set <reg> (high <exp>))
2111 (set <reg> (lo_sum <exp> <const_int>))
2112 effects: cfa_temp.reg = <reg>
2113 cfa_temp.offset = <const_int>
2116 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2117 effects: cfa_store.offset -= <const_int>
2118 cfa.offset = cfa_store.offset if cfa.reg == sp
2120 cfa.base_offset = -cfa_store.offset
2123 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
2124 effects: cfa_store.offset += -/+ mode_size(mem)
2125 cfa.offset = cfa_store.offset if cfa.reg == sp
2127 cfa.base_offset = -cfa_store.offset
2130 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2133 effects: cfa.reg = <reg1>
2134 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2137 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2138 effects: cfa.reg = <reg1>
2139 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2142 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
2143 effects: cfa.reg = <reg1>
2144 cfa.base_offset = -cfa_temp.offset
2145 cfa_temp.offset -= mode_size(mem)
2148 (set <reg> {unspec, unspec_volatile})
2149 effects: target-dependent
2152 (set sp (and: sp <const_int>))
2153 constraints: cfa_store.reg == sp
2154 effects: current_fde.stack_realign = 1
2155 cfa_store.offset = 0
2156 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2159 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2160 effects: cfa_store.offset += -/+ mode_size(mem)
2163 (set (mem ({pre_inc, pre_dec} sp)) fp)
2164 constraints: fde->stack_realign == 1
2165 effects: cfa_store.offset = 0
2166 cfa.reg != HARD_FRAME_POINTER_REGNUM
2169 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2170 constraints: fde->stack_realign == 1
2172 && cfa.indirect == 0
2173 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2174 effects: Use DW_CFA_def_cfa_expression to define cfa
2175 cfa.reg == fde->drap_reg */
2178 dwarf2out_frame_debug_expr (rtx expr
, const char *label
)
2180 rtx src
, dest
, span
;
2181 HOST_WIDE_INT offset
;
2184 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2185 the PARALLEL independently. The first element is always processed if
2186 it is a SET. This is for backward compatibility. Other elements
2187 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2188 flag is set in them. */
2189 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
2192 int limit
= XVECLEN (expr
, 0);
2195 /* PARALLELs have strict read-modify-write semantics, so we
2196 ought to evaluate every rvalue before changing any lvalue.
2197 It's cumbersome to do that in general, but there's an
2198 easy approximation that is enough for all current users:
2199 handle register saves before register assignments. */
2200 if (GET_CODE (expr
) == PARALLEL
)
2201 for (par_index
= 0; par_index
< limit
; par_index
++)
2203 elem
= XVECEXP (expr
, 0, par_index
);
2204 if (GET_CODE (elem
) == SET
2205 && MEM_P (SET_DEST (elem
))
2206 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
2207 dwarf2out_frame_debug_expr (elem
, label
);
2210 for (par_index
= 0; par_index
< limit
; par_index
++)
2212 elem
= XVECEXP (expr
, 0, par_index
);
2213 if (GET_CODE (elem
) == SET
2214 && (!MEM_P (SET_DEST (elem
)) || GET_CODE (expr
) == SEQUENCE
)
2215 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
2216 dwarf2out_frame_debug_expr (elem
, label
);
2217 else if (GET_CODE (elem
) == SET
2219 && !RTX_FRAME_RELATED_P (elem
))
2221 /* Stack adjustment combining might combine some post-prologue
2222 stack adjustment into a prologue stack adjustment. */
2223 HOST_WIDE_INT offset
= stack_adjust_offset (elem
, args_size
, 0);
2226 dwarf2out_stack_adjust (offset
, label
);
2232 gcc_assert (GET_CODE (expr
) == SET
);
2234 src
= SET_SRC (expr
);
2235 dest
= SET_DEST (expr
);
2239 rtx rsi
= reg_saved_in (src
);
2244 fde
= current_fde ();
2246 switch (GET_CODE (dest
))
2249 switch (GET_CODE (src
))
2251 /* Setting FP from SP. */
2253 if (cfa
.reg
== (unsigned) REGNO (src
))
2256 /* Update the CFA rule wrt SP or FP. Make sure src is
2257 relative to the current CFA register.
2259 We used to require that dest be either SP or FP, but the
2260 ARM copies SP to a temporary register, and from there to
2261 FP. So we just rely on the backends to only set
2262 RTX_FRAME_RELATED_P on appropriate insns. */
2263 cfa
.reg
= REGNO (dest
);
2264 cfa_temp
.reg
= cfa
.reg
;
2265 cfa_temp
.offset
= cfa
.offset
;
2269 /* Saving a register in a register. */
2270 gcc_assert (!fixed_regs
[REGNO (dest
)]
2271 /* For the SPARC and its register window. */
2272 || (DWARF_FRAME_REGNUM (REGNO (src
))
2273 == DWARF_FRAME_RETURN_COLUMN
));
2275 /* After stack is aligned, we can only save SP in FP
2276 if drap register is used. In this case, we have
2277 to restore stack pointer with the CFA value and we
2278 don't generate this DWARF information. */
2280 && fde
->stack_realign
2281 && REGNO (src
) == STACK_POINTER_REGNUM
)
2282 gcc_assert (REGNO (dest
) == HARD_FRAME_POINTER_REGNUM
2283 && fde
->drap_reg
!= INVALID_REGNUM
2284 && cfa
.reg
!= REGNO (src
));
2286 queue_reg_save (label
, src
, dest
, 0);
2293 if (dest
== stack_pointer_rtx
)
2297 switch (GET_CODE (XEXP (src
, 1)))
2300 offset
= INTVAL (XEXP (src
, 1));
2303 gcc_assert ((unsigned) REGNO (XEXP (src
, 1))
2305 offset
= cfa_temp
.offset
;
2311 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
2313 /* Restoring SP from FP in the epilogue. */
2314 gcc_assert (cfa
.reg
== (unsigned) HARD_FRAME_POINTER_REGNUM
);
2315 cfa
.reg
= STACK_POINTER_REGNUM
;
2317 else if (GET_CODE (src
) == LO_SUM
)
2318 /* Assume we've set the source reg of the LO_SUM from sp. */
2321 gcc_assert (XEXP (src
, 0) == stack_pointer_rtx
);
2323 if (GET_CODE (src
) != MINUS
)
2325 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2326 cfa
.offset
+= offset
;
2327 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
2328 cfa_store
.offset
+= offset
;
2330 else if (dest
== hard_frame_pointer_rtx
)
2333 /* Either setting the FP from an offset of the SP,
2334 or adjusting the FP */
2335 gcc_assert (frame_pointer_needed
);
2337 gcc_assert (REG_P (XEXP (src
, 0))
2338 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
2339 && CONST_INT_P (XEXP (src
, 1)));
2340 offset
= INTVAL (XEXP (src
, 1));
2341 if (GET_CODE (src
) != MINUS
)
2343 cfa
.offset
+= offset
;
2344 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
2348 gcc_assert (GET_CODE (src
) != MINUS
);
2351 if (REG_P (XEXP (src
, 0))
2352 && REGNO (XEXP (src
, 0)) == cfa
.reg
2353 && CONST_INT_P (XEXP (src
, 1)))
2355 /* Setting a temporary CFA register that will be copied
2356 into the FP later on. */
2357 offset
= - INTVAL (XEXP (src
, 1));
2358 cfa
.offset
+= offset
;
2359 cfa
.reg
= REGNO (dest
);
2360 /* Or used to save regs to the stack. */
2361 cfa_temp
.reg
= cfa
.reg
;
2362 cfa_temp
.offset
= cfa
.offset
;
2366 else if (REG_P (XEXP (src
, 0))
2367 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
2368 && XEXP (src
, 1) == stack_pointer_rtx
)
2370 /* Setting a scratch register that we will use instead
2371 of SP for saving registers to the stack. */
2372 gcc_assert (cfa
.reg
== STACK_POINTER_REGNUM
);
2373 cfa_store
.reg
= REGNO (dest
);
2374 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
2378 else if (GET_CODE (src
) == LO_SUM
2379 && CONST_INT_P (XEXP (src
, 1)))
2381 cfa_temp
.reg
= REGNO (dest
);
2382 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
2391 cfa_temp
.reg
= REGNO (dest
);
2392 cfa_temp
.offset
= INTVAL (src
);
2397 gcc_assert (REG_P (XEXP (src
, 0))
2398 && (unsigned) REGNO (XEXP (src
, 0)) == cfa_temp
.reg
2399 && CONST_INT_P (XEXP (src
, 1)));
2401 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
2402 cfa_temp
.reg
= REGNO (dest
);
2403 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
2406 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2407 which will fill in all of the bits. */
2414 case UNSPEC_VOLATILE
:
2415 gcc_assert (targetm
.dwarf_handle_frame_unspec
);
2416 targetm
.dwarf_handle_frame_unspec (label
, expr
, XINT (src
, 1));
2421 /* If this AND operation happens on stack pointer in prologue,
2422 we assume the stack is realigned and we extract the
2424 if (fde
&& XEXP (src
, 0) == stack_pointer_rtx
)
2426 gcc_assert (cfa_store
.reg
== REGNO (XEXP (src
, 0)));
2427 fde
->stack_realign
= 1;
2428 fde
->stack_realignment
= INTVAL (XEXP (src
, 1));
2429 cfa_store
.offset
= 0;
2431 if (cfa
.reg
!= STACK_POINTER_REGNUM
2432 && cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
)
2433 fde
->drap_reg
= cfa
.reg
;
2441 def_cfa_1 (label
, &cfa
);
2446 /* Saving a register to the stack. Make sure dest is relative to the
2448 switch (GET_CODE (XEXP (dest
, 0)))
2453 /* We can't handle variable size modifications. */
2454 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1))
2456 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
2458 gcc_assert (REGNO (XEXP (XEXP (dest
, 0), 0)) == STACK_POINTER_REGNUM
2459 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
2461 cfa_store
.offset
+= offset
;
2462 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2463 cfa
.offset
= cfa_store
.offset
;
2465 offset
= -cfa_store
.offset
;
2471 offset
= GET_MODE_SIZE (GET_MODE (dest
));
2472 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
2475 gcc_assert ((REGNO (XEXP (XEXP (dest
, 0), 0))
2476 == STACK_POINTER_REGNUM
)
2477 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
2479 cfa_store
.offset
+= offset
;
2481 /* Rule 18: If stack is aligned, we will use FP as a
2482 reference to represent the address of the stored
2485 && fde
->stack_realign
2486 && src
== hard_frame_pointer_rtx
)
2488 gcc_assert (cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
);
2489 cfa_store
.offset
= 0;
2492 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2493 cfa
.offset
= cfa_store
.offset
;
2495 offset
= -cfa_store
.offset
;
2499 /* With an offset. */
2506 gcc_assert (CONST_INT_P (XEXP (XEXP (dest
, 0), 1))
2507 && REG_P (XEXP (XEXP (dest
, 0), 0)));
2508 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
2509 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
2512 regno
= REGNO (XEXP (XEXP (dest
, 0), 0));
2514 if (cfa_store
.reg
== (unsigned) regno
)
2515 offset
-= cfa_store
.offset
;
2518 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
2519 offset
-= cfa_temp
.offset
;
2525 /* Without an offset. */
2528 int regno
= REGNO (XEXP (dest
, 0));
2530 if (cfa_store
.reg
== (unsigned) regno
)
2531 offset
= -cfa_store
.offset
;
2534 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
2535 offset
= -cfa_temp
.offset
;
2542 gcc_assert (cfa_temp
.reg
2543 == (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)));
2544 offset
= -cfa_temp
.offset
;
2545 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
2553 /* If the source operand of this MEM operation is not a
2554 register, basically the source is return address. Here
2555 we only care how much stack grew and we don't save it. */
2559 if (REGNO (src
) != STACK_POINTER_REGNUM
2560 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
2561 && (unsigned) REGNO (src
) == cfa
.reg
)
2563 /* We're storing the current CFA reg into the stack. */
2565 if (cfa
.offset
== 0)
2568 /* If stack is aligned, putting CFA reg into stack means
2569 we can no longer use reg + offset to represent CFA.
2570 Here we use DW_CFA_def_cfa_expression instead. The
2571 result of this expression equals to the original CFA
2574 && fde
->stack_realign
2575 && cfa
.indirect
== 0
2576 && cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
)
2578 dw_cfa_location cfa_exp
;
2580 gcc_assert (fde
->drap_reg
== cfa
.reg
);
2582 cfa_exp
.indirect
= 1;
2583 cfa_exp
.reg
= HARD_FRAME_POINTER_REGNUM
;
2584 cfa_exp
.base_offset
= offset
;
2587 fde
->drap_reg_saved
= 1;
2589 def_cfa_1 (label
, &cfa_exp
);
2593 /* If the source register is exactly the CFA, assume
2594 we're saving SP like any other register; this happens
2596 def_cfa_1 (label
, &cfa
);
2597 queue_reg_save (label
, stack_pointer_rtx
, NULL_RTX
, offset
);
2602 /* Otherwise, we'll need to look in the stack to
2603 calculate the CFA. */
2604 rtx x
= XEXP (dest
, 0);
2608 gcc_assert (REG_P (x
));
2610 cfa
.reg
= REGNO (x
);
2611 cfa
.base_offset
= offset
;
2613 def_cfa_1 (label
, &cfa
);
2618 def_cfa_1 (label
, &cfa
);
2620 span
= targetm
.dwarf_register_span (src
);
2623 queue_reg_save (label
, src
, NULL_RTX
, offset
);
2626 /* We have a PARALLEL describing where the contents of SRC
2627 live. Queue register saves for each piece of the
2631 HOST_WIDE_INT span_offset
= offset
;
2633 gcc_assert (GET_CODE (span
) == PARALLEL
);
2635 limit
= XVECLEN (span
, 0);
2636 for (par_index
= 0; par_index
< limit
; par_index
++)
2638 rtx elem
= XVECEXP (span
, 0, par_index
);
2640 queue_reg_save (label
, elem
, NULL_RTX
, span_offset
);
2641 span_offset
+= GET_MODE_SIZE (GET_MODE (elem
));
2652 /* Record call frame debugging information for INSN, which either
2653 sets SP or FP (adjusting how we calculate the frame address) or saves a
2654 register to the stack. If INSN is NULL_RTX, initialize our state.
2656 If AFTER_P is false, we're being called before the insn is emitted,
2657 otherwise after. Call instructions get invoked twice. */
2660 dwarf2out_frame_debug (rtx insn
, bool after_p
)
2664 bool handled_one
= false;
2666 if (insn
== NULL_RTX
)
2670 /* Flush any queued register saves. */
2671 flush_queued_reg_saves ();
2673 /* Set up state for generating call frame debug info. */
2676 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
));
2678 cfa
.reg
= STACK_POINTER_REGNUM
;
2681 cfa_temp
.offset
= 0;
2683 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
2685 regs_saved_in_regs
[i
].orig_reg
= NULL_RTX
;
2686 regs_saved_in_regs
[i
].saved_in_reg
= NULL_RTX
;
2688 num_regs_saved_in_regs
= 0;
2690 if (barrier_args_size
)
2692 XDELETEVEC (barrier_args_size
);
2693 barrier_args_size
= NULL
;
2698 if (!NONJUMP_INSN_P (insn
) || clobbers_queued_reg_save (insn
))
2699 flush_queued_reg_saves ();
2701 if (!RTX_FRAME_RELATED_P (insn
))
2703 /* ??? This should be done unconditionally since stack adjustments
2704 matter if the stack pointer is not the CFA register anymore but
2705 is still used to save registers. */
2706 if (!ACCUMULATE_OUTGOING_ARGS
)
2707 dwarf2out_notice_stack_adjust (insn
, after_p
);
2711 label
= dwarf2out_cfi_label (false);
2713 for (note
= REG_NOTES (insn
); note
; note
= XEXP (note
, 1))
2714 switch (REG_NOTE_KIND (note
))
2716 case REG_FRAME_RELATED_EXPR
:
2717 insn
= XEXP (note
, 0);
2720 case REG_CFA_DEF_CFA
:
2721 dwarf2out_frame_debug_def_cfa (XEXP (note
, 0), label
);
2725 case REG_CFA_ADJUST_CFA
:
2730 if (GET_CODE (n
) == PARALLEL
)
2731 n
= XVECEXP (n
, 0, 0);
2733 dwarf2out_frame_debug_adjust_cfa (n
, label
);
2737 case REG_CFA_OFFSET
:
2740 n
= single_set (insn
);
2741 dwarf2out_frame_debug_cfa_offset (n
, label
);
2745 case REG_CFA_REGISTER
:
2750 if (GET_CODE (n
) == PARALLEL
)
2751 n
= XVECEXP (n
, 0, 0);
2753 dwarf2out_frame_debug_cfa_register (n
, label
);
2757 case REG_CFA_RESTORE
:
2762 if (GET_CODE (n
) == PARALLEL
)
2763 n
= XVECEXP (n
, 0, 0);
2766 dwarf2out_frame_debug_cfa_restore (n
, label
);
2770 case REG_CFA_SET_VDRAP
:
2774 dw_fde_ref fde
= current_fde ();
2777 gcc_assert (fde
->vdrap_reg
== INVALID_REGNUM
);
2779 fde
->vdrap_reg
= REGNO (n
);
2791 insn
= PATTERN (insn
);
2793 dwarf2out_frame_debug_expr (insn
, label
);
2796 /* Determine if we need to save and restore CFI information around this
2797 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2798 we do need to save/restore, then emit the save now, and insert a
2799 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2802 dwarf2out_cfi_begin_epilogue (rtx insn
)
2804 bool saw_frp
= false;
2807 /* Scan forward to the return insn, noticing if there are possible
2808 frame related insns. */
2809 for (i
= NEXT_INSN (insn
); i
; i
= NEXT_INSN (i
))
2814 /* Look for both regular and sibcalls to end the block. */
2815 if (returnjump_p (i
))
2817 if (CALL_P (i
) && SIBLING_CALL_P (i
))
2820 if (GET_CODE (PATTERN (i
)) == SEQUENCE
)
2823 rtx seq
= PATTERN (i
);
2825 if (returnjump_p (XVECEXP (seq
, 0, 0)))
2827 if (CALL_P (XVECEXP (seq
, 0, 0))
2828 && SIBLING_CALL_P (XVECEXP (seq
, 0, 0)))
2831 for (idx
= 0; idx
< XVECLEN (seq
, 0); idx
++)
2832 if (RTX_FRAME_RELATED_P (XVECEXP (seq
, 0, idx
)))
2836 if (RTX_FRAME_RELATED_P (i
))
2840 /* If the port doesn't emit epilogue unwind info, we don't need a
2841 save/restore pair. */
2845 /* Otherwise, search forward to see if the return insn was the last
2846 basic block of the function. If so, we don't need save/restore. */
2847 gcc_assert (i
!= NULL
);
2848 i
= next_real_insn (i
);
2852 /* Insert the restore before that next real insn in the stream, and before
2853 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
2854 properly nested. This should be after any label or alignment. This
2855 will be pushed into the CFI stream by the function below. */
2858 rtx p
= PREV_INSN (i
);
2861 if (NOTE_KIND (p
) == NOTE_INSN_BASIC_BLOCK
)
2865 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE
, i
);
2867 emit_cfa_remember
= true;
2869 /* And emulate the state save. */
2870 gcc_assert (!cfa_remember
.in_use
);
2872 cfa_remember
.in_use
= 1;
2875 /* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
2879 dwarf2out_frame_debug_restore_state (void)
2881 dw_cfi_ref cfi
= new_cfi ();
2882 const char *label
= dwarf2out_cfi_label (false);
2884 cfi
->dw_cfi_opc
= DW_CFA_restore_state
;
2885 add_fde_cfi (label
, cfi
);
2887 gcc_assert (cfa_remember
.in_use
);
2889 cfa_remember
.in_use
= 0;
2894 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2895 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2896 (enum dwarf_call_frame_info cfi
);
2898 static enum dw_cfi_oprnd_type
2899 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
2904 case DW_CFA_GNU_window_save
:
2905 case DW_CFA_remember_state
:
2906 case DW_CFA_restore_state
:
2907 return dw_cfi_oprnd_unused
;
2909 case DW_CFA_set_loc
:
2910 case DW_CFA_advance_loc1
:
2911 case DW_CFA_advance_loc2
:
2912 case DW_CFA_advance_loc4
:
2913 case DW_CFA_MIPS_advance_loc8
:
2914 return dw_cfi_oprnd_addr
;
2917 case DW_CFA_offset_extended
:
2918 case DW_CFA_def_cfa
:
2919 case DW_CFA_offset_extended_sf
:
2920 case DW_CFA_def_cfa_sf
:
2921 case DW_CFA_restore
:
2922 case DW_CFA_restore_extended
:
2923 case DW_CFA_undefined
:
2924 case DW_CFA_same_value
:
2925 case DW_CFA_def_cfa_register
:
2926 case DW_CFA_register
:
2927 case DW_CFA_expression
:
2928 return dw_cfi_oprnd_reg_num
;
2930 case DW_CFA_def_cfa_offset
:
2931 case DW_CFA_GNU_args_size
:
2932 case DW_CFA_def_cfa_offset_sf
:
2933 return dw_cfi_oprnd_offset
;
2935 case DW_CFA_def_cfa_expression
:
2936 return dw_cfi_oprnd_loc
;
2943 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2944 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2945 (enum dwarf_call_frame_info cfi
);
2947 static enum dw_cfi_oprnd_type
2948 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
2952 case DW_CFA_def_cfa
:
2953 case DW_CFA_def_cfa_sf
:
2955 case DW_CFA_offset_extended_sf
:
2956 case DW_CFA_offset_extended
:
2957 return dw_cfi_oprnd_offset
;
2959 case DW_CFA_register
:
2960 return dw_cfi_oprnd_reg_num
;
2962 case DW_CFA_expression
:
2963 return dw_cfi_oprnd_loc
;
2966 return dw_cfi_oprnd_unused
;
2970 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2972 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
2973 switch to the data section instead, and write out a synthetic start label
2974 for collect2 the first time around. */
2977 switch_to_eh_frame_section (bool back
)
2981 #ifdef EH_FRAME_SECTION_NAME
2982 if (eh_frame_section
== 0)
2986 if (EH_TABLES_CAN_BE_READ_ONLY
)
2992 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2994 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2996 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2998 flags
= ((! flag_pic
2999 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
3000 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
3001 && (per_encoding
& 0x70) != DW_EH_PE_absptr
3002 && (per_encoding
& 0x70) != DW_EH_PE_aligned
3003 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
3004 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
3005 ? 0 : SECTION_WRITE
);
3008 flags
= SECTION_WRITE
;
3009 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
3013 if (eh_frame_section
)
3014 switch_to_section (eh_frame_section
);
3017 /* We have no special eh_frame section. Put the information in
3018 the data section and emit special labels to guide collect2. */
3019 switch_to_section (data_section
);
3023 label
= get_file_function_name ("F");
3024 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
3025 targetm
.asm_out
.globalize_label (asm_out_file
,
3026 IDENTIFIER_POINTER (label
));
3027 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
3032 /* Switch [BACK] to the eh or debug frame table section, depending on
3036 switch_to_frame_table_section (int for_eh
, bool back
)
3039 switch_to_eh_frame_section (back
);
3042 if (!debug_frame_section
)
3043 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
3044 SECTION_DEBUG
, NULL
);
3045 switch_to_section (debug_frame_section
);
3049 /* Output a Call Frame Information opcode and its operand(s). */
3052 output_cfi (dw_cfi_ref cfi
, dw_fde_ref fde
, int for_eh
)
3057 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
3058 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
3059 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
3060 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX
,
3061 ((unsigned HOST_WIDE_INT
)
3062 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
));
3063 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
3065 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3066 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
3067 "DW_CFA_offset, column %#lx", r
);
3068 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3069 dw2_asm_output_data_uleb128 (off
, NULL
);
3071 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
3073 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3074 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
3075 "DW_CFA_restore, column %#lx", r
);
3079 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
3080 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
3082 switch (cfi
->dw_cfi_opc
)
3084 case DW_CFA_set_loc
:
3086 dw2_asm_output_encoded_addr_rtx (
3087 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3088 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
3091 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
3092 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
3093 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3096 case DW_CFA_advance_loc1
:
3097 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3098 fde
->dw_fde_current_label
, NULL
);
3099 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3102 case DW_CFA_advance_loc2
:
3103 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3104 fde
->dw_fde_current_label
, NULL
);
3105 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3108 case DW_CFA_advance_loc4
:
3109 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3110 fde
->dw_fde_current_label
, NULL
);
3111 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3114 case DW_CFA_MIPS_advance_loc8
:
3115 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3116 fde
->dw_fde_current_label
, NULL
);
3117 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3120 case DW_CFA_offset_extended
:
3121 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3122 dw2_asm_output_data_uleb128 (r
, NULL
);
3123 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3124 dw2_asm_output_data_uleb128 (off
, NULL
);
3127 case DW_CFA_def_cfa
:
3128 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3129 dw2_asm_output_data_uleb128 (r
, NULL
);
3130 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
3133 case DW_CFA_offset_extended_sf
:
3134 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3135 dw2_asm_output_data_uleb128 (r
, NULL
);
3136 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3137 dw2_asm_output_data_sleb128 (off
, NULL
);
3140 case DW_CFA_def_cfa_sf
:
3141 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3142 dw2_asm_output_data_uleb128 (r
, NULL
);
3143 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3144 dw2_asm_output_data_sleb128 (off
, NULL
);
3147 case DW_CFA_restore_extended
:
3148 case DW_CFA_undefined
:
3149 case DW_CFA_same_value
:
3150 case DW_CFA_def_cfa_register
:
3151 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3152 dw2_asm_output_data_uleb128 (r
, NULL
);
3155 case DW_CFA_register
:
3156 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3157 dw2_asm_output_data_uleb128 (r
, NULL
);
3158 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, for_eh
);
3159 dw2_asm_output_data_uleb128 (r
, NULL
);
3162 case DW_CFA_def_cfa_offset
:
3163 case DW_CFA_GNU_args_size
:
3164 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
3167 case DW_CFA_def_cfa_offset_sf
:
3168 off
= div_data_align (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3169 dw2_asm_output_data_sleb128 (off
, NULL
);
3172 case DW_CFA_GNU_window_save
:
3175 case DW_CFA_def_cfa_expression
:
3176 case DW_CFA_expression
:
3177 output_cfa_loc (cfi
);
3180 case DW_CFA_GNU_negative_offset_extended
:
3181 /* Obsoleted by DW_CFA_offset_extended_sf. */
3190 /* Similar, but do it via assembler directives instead. */
3193 output_cfi_directive (dw_cfi_ref cfi
)
3195 unsigned long r
, r2
;
3197 switch (cfi
->dw_cfi_opc
)
3199 case DW_CFA_advance_loc
:
3200 case DW_CFA_advance_loc1
:
3201 case DW_CFA_advance_loc2
:
3202 case DW_CFA_advance_loc4
:
3203 case DW_CFA_MIPS_advance_loc8
:
3204 case DW_CFA_set_loc
:
3205 /* Should only be created by add_fde_cfi in a code path not
3206 followed when emitting via directives. The assembler is
3207 going to take care of this for us. */
3211 case DW_CFA_offset_extended
:
3212 case DW_CFA_offset_extended_sf
:
3213 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3214 fprintf (asm_out_file
, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC
"\n",
3215 r
, cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3218 case DW_CFA_restore
:
3219 case DW_CFA_restore_extended
:
3220 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3221 fprintf (asm_out_file
, "\t.cfi_restore %lu\n", r
);
3224 case DW_CFA_undefined
:
3225 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3226 fprintf (asm_out_file
, "\t.cfi_undefined %lu\n", r
);
3229 case DW_CFA_same_value
:
3230 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3231 fprintf (asm_out_file
, "\t.cfi_same_value %lu\n", r
);
3234 case DW_CFA_def_cfa
:
3235 case DW_CFA_def_cfa_sf
:
3236 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3237 fprintf (asm_out_file
, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC
"\n",
3238 r
, cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3241 case DW_CFA_def_cfa_register
:
3242 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3243 fprintf (asm_out_file
, "\t.cfi_def_cfa_register %lu\n", r
);
3246 case DW_CFA_register
:
3247 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3248 r2
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, 1);
3249 fprintf (asm_out_file
, "\t.cfi_register %lu, %lu\n", r
, r2
);
3252 case DW_CFA_def_cfa_offset
:
3253 case DW_CFA_def_cfa_offset_sf
:
3254 fprintf (asm_out_file
, "\t.cfi_def_cfa_offset "
3255 HOST_WIDE_INT_PRINT_DEC
"\n",
3256 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3259 case DW_CFA_remember_state
:
3260 fprintf (asm_out_file
, "\t.cfi_remember_state\n");
3262 case DW_CFA_restore_state
:
3263 fprintf (asm_out_file
, "\t.cfi_restore_state\n");
3266 case DW_CFA_GNU_args_size
:
3267 fprintf (asm_out_file
, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size
);
3268 dw2_asm_output_data_uleb128_raw (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3270 fprintf (asm_out_file
, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC
,
3271 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3272 fputc ('\n', asm_out_file
);
3275 case DW_CFA_GNU_window_save
:
3276 fprintf (asm_out_file
, "\t.cfi_window_save\n");
3279 case DW_CFA_def_cfa_expression
:
3280 case DW_CFA_expression
:
3281 fprintf (asm_out_file
, "\t.cfi_escape %#x,", cfi
->dw_cfi_opc
);
3282 output_cfa_loc_raw (cfi
);
3283 fputc ('\n', asm_out_file
);
3291 DEF_VEC_P (dw_cfi_ref
);
3292 DEF_VEC_ALLOC_P (dw_cfi_ref
, heap
);
3294 /* Output CFIs to bring current FDE to the same state as after executing
3295 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3296 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3297 other arguments to pass to output_cfi. */
3300 output_cfis (dw_cfi_ref cfi
, bool do_cfi_asm
, dw_fde_ref fde
, bool for_eh
)
3302 struct dw_cfi_struct cfi_buf
;
3304 dw_cfi_ref cfi_args_size
= NULL
, cfi_cfa
= NULL
, cfi_cfa_offset
= NULL
;
3305 VEC (dw_cfi_ref
, heap
) *regs
= VEC_alloc (dw_cfi_ref
, heap
, 32);
3306 unsigned int len
, idx
;
3308 for (;; cfi
= cfi
->dw_cfi_next
)
3309 switch (cfi
? cfi
->dw_cfi_opc
: DW_CFA_nop
)
3311 case DW_CFA_advance_loc
:
3312 case DW_CFA_advance_loc1
:
3313 case DW_CFA_advance_loc2
:
3314 case DW_CFA_advance_loc4
:
3315 case DW_CFA_MIPS_advance_loc8
:
3316 case DW_CFA_set_loc
:
3317 /* All advances should be ignored. */
3319 case DW_CFA_remember_state
:
3321 dw_cfi_ref args_size
= cfi_args_size
;
3323 /* Skip everything between .cfi_remember_state and
3324 .cfi_restore_state. */
3325 for (cfi2
= cfi
->dw_cfi_next
; cfi2
; cfi2
= cfi2
->dw_cfi_next
)
3326 if (cfi2
->dw_cfi_opc
== DW_CFA_restore_state
)
3328 else if (cfi2
->dw_cfi_opc
== DW_CFA_GNU_args_size
)
3331 gcc_assert (cfi2
->dw_cfi_opc
!= DW_CFA_remember_state
);
3338 cfi_args_size
= args_size
;
3342 case DW_CFA_GNU_args_size
:
3343 cfi_args_size
= cfi
;
3345 case DW_CFA_GNU_window_save
:
3348 case DW_CFA_offset_extended
:
3349 case DW_CFA_offset_extended_sf
:
3350 case DW_CFA_restore
:
3351 case DW_CFA_restore_extended
:
3352 case DW_CFA_undefined
:
3353 case DW_CFA_same_value
:
3354 case DW_CFA_register
:
3355 case DW_CFA_val_offset
:
3356 case DW_CFA_val_offset_sf
:
3357 case DW_CFA_expression
:
3358 case DW_CFA_val_expression
:
3359 case DW_CFA_GNU_negative_offset_extended
:
3360 if (VEC_length (dw_cfi_ref
, regs
) <= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
)
3361 VEC_safe_grow_cleared (dw_cfi_ref
, heap
, regs
,
3362 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
+ 1);
3363 VEC_replace (dw_cfi_ref
, regs
, cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, cfi
);
3365 case DW_CFA_def_cfa
:
3366 case DW_CFA_def_cfa_sf
:
3367 case DW_CFA_def_cfa_expression
:
3369 cfi_cfa_offset
= cfi
;
3371 case DW_CFA_def_cfa_register
:
3374 case DW_CFA_def_cfa_offset
:
3375 case DW_CFA_def_cfa_offset_sf
:
3376 cfi_cfa_offset
= cfi
;
3379 gcc_assert (cfi
== NULL
);
3381 len
= VEC_length (dw_cfi_ref
, regs
);
3382 for (idx
= 0; idx
< len
; idx
++)
3384 cfi2
= VEC_replace (dw_cfi_ref
, regs
, idx
, NULL
);
3386 && cfi2
->dw_cfi_opc
!= DW_CFA_restore
3387 && cfi2
->dw_cfi_opc
!= DW_CFA_restore_extended
)
3390 output_cfi_directive (cfi2
);
3392 output_cfi (cfi2
, fde
, for_eh
);
3395 if (cfi_cfa
&& cfi_cfa_offset
&& cfi_cfa_offset
!= cfi_cfa
)
3397 gcc_assert (cfi_cfa
->dw_cfi_opc
!= DW_CFA_def_cfa_expression
);
3399 switch (cfi_cfa_offset
->dw_cfi_opc
)
3401 case DW_CFA_def_cfa_offset
:
3402 cfi_buf
.dw_cfi_opc
= DW_CFA_def_cfa
;
3403 cfi_buf
.dw_cfi_oprnd2
= cfi_cfa_offset
->dw_cfi_oprnd1
;
3405 case DW_CFA_def_cfa_offset_sf
:
3406 cfi_buf
.dw_cfi_opc
= DW_CFA_def_cfa_sf
;
3407 cfi_buf
.dw_cfi_oprnd2
= cfi_cfa_offset
->dw_cfi_oprnd1
;
3409 case DW_CFA_def_cfa
:
3410 case DW_CFA_def_cfa_sf
:
3411 cfi_buf
.dw_cfi_opc
= cfi_cfa_offset
->dw_cfi_opc
;
3412 cfi_buf
.dw_cfi_oprnd2
= cfi_cfa_offset
->dw_cfi_oprnd2
;
3419 else if (cfi_cfa_offset
)
3420 cfi_cfa
= cfi_cfa_offset
;
3424 output_cfi_directive (cfi_cfa
);
3426 output_cfi (cfi_cfa
, fde
, for_eh
);
3429 cfi_cfa_offset
= NULL
;
3431 && cfi_args_size
->dw_cfi_oprnd1
.dw_cfi_offset
)
3434 output_cfi_directive (cfi_args_size
);
3436 output_cfi (cfi_args_size
, fde
, for_eh
);
3438 cfi_args_size
= NULL
;
3441 VEC_free (dw_cfi_ref
, heap
, regs
);
3444 else if (do_cfi_asm
)
3445 output_cfi_directive (cfi
);
3447 output_cfi (cfi
, fde
, for_eh
);
3454 /* Output one FDE. */
3457 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
3458 char *section_start_label
, int fde_encoding
, char *augmentation
,
3459 bool any_lsda_needed
, int lsda_encoding
)
3461 const char *begin
, *end
;
3462 static unsigned int j
;
3463 char l1
[20], l2
[20];
3466 targetm
.asm_out
.unwind_label (asm_out_file
, fde
->decl
, for_eh
,
3468 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
3470 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
3471 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
3472 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
3473 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3474 " indicating 64-bit DWARF extension");
3475 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
3477 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
3480 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
3482 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
3483 debug_frame_section
, "FDE CIE offset");
3485 if (!fde
->dw_fde_switched_sections
)
3487 begin
= fde
->dw_fde_begin
;
3488 end
= fde
->dw_fde_end
;
3492 /* For the first section, prefer dw_fde_begin over
3493 dw_fde_{hot,cold}_section_label, as the latter
3494 might be separated from the real start of the
3495 function by alignment padding. */
3497 begin
= fde
->dw_fde_begin
;
3498 else if (fde
->dw_fde_switched_cold_to_hot
)
3499 begin
= fde
->dw_fde_hot_section_label
;
3501 begin
= fde
->dw_fde_unlikely_section_label
;
3502 if (second
^ fde
->dw_fde_switched_cold_to_hot
)
3503 end
= fde
->dw_fde_unlikely_section_end_label
;
3505 end
= fde
->dw_fde_hot_section_end_label
;
3510 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
3511 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
3512 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
3513 "FDE initial location");
3514 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
3515 end
, begin
, "FDE address range");
3519 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
3520 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
3523 if (augmentation
[0])
3525 if (any_lsda_needed
)
3527 int size
= size_of_encoded_value (lsda_encoding
);
3529 if (lsda_encoding
== DW_EH_PE_aligned
)
3531 int offset
= ( 4 /* Length */
3532 + 4 /* CIE offset */
3533 + 2 * size_of_encoded_value (fde_encoding
)
3534 + 1 /* Augmentation size */ );
3535 int pad
= -offset
& (PTR_SIZE
- 1);
3538 gcc_assert (size_of_uleb128 (size
) == 1);
3541 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
3543 if (fde
->uses_eh_lsda
)
3545 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
3546 fde
->funcdef_number
);
3547 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
3548 gen_rtx_SYMBOL_REF (Pmode
, l1
),
3550 "Language Specific Data Area");
3554 if (lsda_encoding
== DW_EH_PE_aligned
)
3555 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
3556 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
3557 "Language Specific Data Area (none)");
3561 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3564 /* Loop through the Call Frame Instructions associated with
3566 fde
->dw_fde_current_label
= begin
;
3567 if (!fde
->dw_fde_switched_sections
)
3568 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
3569 output_cfi (cfi
, fde
, for_eh
);
3572 if (fde
->dw_fde_switch_cfi
)
3573 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
3575 output_cfi (cfi
, fde
, for_eh
);
3576 if (cfi
== fde
->dw_fde_switch_cfi
)
3582 dw_cfi_ref cfi_next
= fde
->dw_fde_cfi
;
3584 if (fde
->dw_fde_switch_cfi
)
3586 cfi_next
= fde
->dw_fde_switch_cfi
->dw_cfi_next
;
3587 fde
->dw_fde_switch_cfi
->dw_cfi_next
= NULL
;
3588 output_cfis (fde
->dw_fde_cfi
, false, fde
, for_eh
);
3589 fde
->dw_fde_switch_cfi
->dw_cfi_next
= cfi_next
;
3591 for (cfi
= cfi_next
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
3592 output_cfi (cfi
, fde
, for_eh
);
3595 /* If we are to emit a ref/link from function bodies to their frame tables,
3596 do it now. This is typically performed to make sure that tables
3597 associated with functions are dragged with them and not discarded in
3598 garbage collecting links. We need to do this on a per function basis to
3599 cope with -ffunction-sections. */
3601 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3602 /* Switch to the function section, emit the ref to the tables, and
3603 switch *back* into the table section. */
3604 switch_to_section (function_section (fde
->decl
));
3605 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
3606 switch_to_frame_table_section (for_eh
, true);
3609 /* Pad the FDE out to an address sized boundary. */
3610 ASM_OUTPUT_ALIGN (asm_out_file
,
3611 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
3612 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
3617 /* Return true if frame description entry FDE is needed for EH. */
3620 fde_needed_for_eh_p (dw_fde_ref fde
)
3622 if (flag_asynchronous_unwind_tables
)
3625 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
3628 if (fde
->uses_eh_lsda
)
3631 /* If exceptions are enabled, we have collected nothrow info. */
3632 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
3638 /* Output the call frame information used to record information
3639 that relates to calculating the frame pointer, and records the
3640 location of saved registers. */
3643 output_call_frame_info (int for_eh
)
3648 char l1
[20], l2
[20], section_start_label
[20];
3649 bool any_lsda_needed
= false;
3650 char augmentation
[6];
3651 int augmentation_size
;
3652 int fde_encoding
= DW_EH_PE_absptr
;
3653 int per_encoding
= DW_EH_PE_absptr
;
3654 int lsda_encoding
= DW_EH_PE_absptr
;
3656 rtx personality
= NULL
;
3659 /* Don't emit a CIE if there won't be any FDEs. */
3660 if (fde_table_in_use
== 0)
3663 /* Nothing to do if the assembler's doing it all. */
3664 if (dwarf2out_do_cfi_asm ())
3667 /* If we don't have any functions we'll want to unwind out of, don't emit
3668 any EH unwind information. If we make FDEs linkonce, we may have to
3669 emit an empty label for an FDE that wouldn't otherwise be emitted. We
3670 want to avoid having an FDE kept around when the function it refers to
3671 is discarded. Example where this matters: a primary function template
3672 in C++ requires EH information, an explicit specialization doesn't. */
3675 bool any_eh_needed
= false;
3677 for (i
= 0; i
< fde_table_in_use
; i
++)
3678 if (fde_table
[i
].uses_eh_lsda
)
3679 any_eh_needed
= any_lsda_needed
= true;
3680 else if (fde_needed_for_eh_p (&fde_table
[i
]))
3681 any_eh_needed
= true;
3682 else if (TARGET_USES_WEAK_UNWIND_INFO
)
3683 targetm
.asm_out
.unwind_label (asm_out_file
, fde_table
[i
].decl
, 1, 1);
3689 /* We're going to be generating comments, so turn on app. */
3693 /* Switch to the proper frame section, first time. */
3694 switch_to_frame_table_section (for_eh
, false);
3696 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
3697 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
3699 /* Output the CIE. */
3700 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
3701 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
3702 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
3703 dw2_asm_output_data (4, 0xffffffff,
3704 "Initial length escape value indicating 64-bit DWARF extension");
3705 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
3706 "Length of Common Information Entry");
3707 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
3709 /* Now that the CIE pointer is PC-relative for EH,
3710 use 0 to identify the CIE. */
3711 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
3712 (for_eh
? 0 : DWARF_CIE_ID
),
3713 "CIE Identifier Tag");
3715 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3716 use CIE version 1, unless that would produce incorrect results
3717 due to overflowing the return register column. */
3718 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
3720 if (return_reg
>= 256 || dwarf_version
> 2)
3722 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
3724 augmentation
[0] = 0;
3725 augmentation_size
= 0;
3727 personality
= current_unit_personality
;
3733 z Indicates that a uleb128 is present to size the
3734 augmentation section.
3735 L Indicates the encoding (and thus presence) of
3736 an LSDA pointer in the FDE augmentation.
3737 R Indicates a non-default pointer encoding for
3739 P Indicates the presence of an encoding + language
3740 personality routine in the CIE augmentation. */
3742 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3743 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3744 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3746 p
= augmentation
+ 1;
3750 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
3751 assemble_external_libcall (personality
);
3753 if (any_lsda_needed
)
3756 augmentation_size
+= 1;
3758 if (fde_encoding
!= DW_EH_PE_absptr
)
3761 augmentation_size
+= 1;
3763 if (p
> augmentation
+ 1)
3765 augmentation
[0] = 'z';
3769 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3770 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
3772 int offset
= ( 4 /* Length */
3774 + 1 /* CIE version */
3775 + strlen (augmentation
) + 1 /* Augmentation */
3776 + size_of_uleb128 (1) /* Code alignment */
3777 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
3779 + 1 /* Augmentation size */
3780 + 1 /* Personality encoding */ );
3781 int pad
= -offset
& (PTR_SIZE
- 1);
3783 augmentation_size
+= pad
;
3785 /* Augmentations should be small, so there's scarce need to
3786 iterate for a solution. Die if we exceed one uleb128 byte. */
3787 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
3791 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
3792 if (dw_cie_version
>= 4)
3794 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
3795 dw2_asm_output_data (1, 0, "CIE Segment Size");
3797 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3798 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
3799 "CIE Data Alignment Factor");
3801 if (dw_cie_version
== 1)
3802 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
3804 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
3806 if (augmentation
[0])
3808 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
3811 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
3812 eh_data_format_name (per_encoding
));
3813 dw2_asm_output_encoded_addr_rtx (per_encoding
,
3818 if (any_lsda_needed
)
3819 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
3820 eh_data_format_name (lsda_encoding
));
3822 if (fde_encoding
!= DW_EH_PE_absptr
)
3823 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
3824 eh_data_format_name (fde_encoding
));
3827 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
3828 output_cfi (cfi
, NULL
, for_eh
);
3830 /* Pad the CIE out to an address sized boundary. */
3831 ASM_OUTPUT_ALIGN (asm_out_file
,
3832 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
3833 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
3835 /* Loop through all of the FDE's. */
3836 for (i
= 0; i
< fde_table_in_use
; i
++)
3839 fde
= &fde_table
[i
];
3841 /* Don't emit EH unwind info for leaf functions that don't need it. */
3842 if (for_eh
&& !fde_needed_for_eh_p (fde
))
3845 for (k
= 0; k
< (fde
->dw_fde_switched_sections
? 2 : 1); k
++)
3846 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
3847 augmentation
, any_lsda_needed
, lsda_encoding
);
3850 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
3851 dw2_asm_output_data (4, 0, "End of Table");
3852 #ifdef MIPS_DEBUGGING_INFO
3853 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3854 get a value of 0. Putting .align 0 after the label fixes it. */
3855 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
3858 /* Turn off app to make assembly quicker. */
3863 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
3866 dwarf2out_do_cfi_startproc (bool second
)
3870 rtx personality
= get_personality_function (current_function_decl
);
3872 fprintf (asm_out_file
, "\t.cfi_startproc\n");
3876 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3879 /* ??? The GAS support isn't entirely consistent. We have to
3880 handle indirect support ourselves, but PC-relative is done
3881 in the assembler. Further, the assembler can't handle any
3882 of the weirder relocation types. */
3883 if (enc
& DW_EH_PE_indirect
)
3884 ref
= dw2_force_const_mem (ref
, true);
3886 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
3887 output_addr_const (asm_out_file
, ref
);
3888 fputc ('\n', asm_out_file
);
3891 if (crtl
->uses_eh_lsda
)
3895 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3896 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
3897 current_function_funcdef_no
);
3898 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
3899 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
3901 if (enc
& DW_EH_PE_indirect
)
3902 ref
= dw2_force_const_mem (ref
, true);
3904 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
3905 output_addr_const (asm_out_file
, ref
);
3906 fputc ('\n', asm_out_file
);
3910 /* Output a marker (i.e. a label) for the beginning of a function, before
3914 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
3915 const char *file ATTRIBUTE_UNUSED
)
3917 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3922 current_function_func_begin_label
= NULL
;
3924 #ifdef TARGET_UNWIND_INFO
3925 /* ??? current_function_func_begin_label is also used by except.c
3926 for call-site information. We must emit this label if it might
3928 if ((! flag_exceptions
|| USING_SJLJ_EXCEPTIONS
)
3929 && ! dwarf2out_do_frame ())
3932 if (! dwarf2out_do_frame ())
3936 fnsec
= function_section (current_function_decl
);
3937 switch_to_section (fnsec
);
3938 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
3939 current_function_funcdef_no
);
3940 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
3941 current_function_funcdef_no
);
3942 dup_label
= xstrdup (label
);
3943 current_function_func_begin_label
= dup_label
;
3945 #ifdef TARGET_UNWIND_INFO
3946 /* We can elide the fde allocation if we're not emitting debug info. */
3947 if (! dwarf2out_do_frame ())
3951 /* Expand the fde table if necessary. */
3952 if (fde_table_in_use
== fde_table_allocated
)
3954 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
3955 fde_table
= GGC_RESIZEVEC (dw_fde_node
, fde_table
, fde_table_allocated
);
3956 memset (fde_table
+ fde_table_in_use
, 0,
3957 FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
3960 /* Record the FDE associated with this function. */
3961 current_funcdef_fde
= fde_table_in_use
;
3963 /* Add the new FDE at the end of the fde_table. */
3964 fde
= &fde_table
[fde_table_in_use
++];
3965 fde
->decl
= current_function_decl
;
3966 fde
->dw_fde_begin
= dup_label
;
3967 fde
->dw_fde_current_label
= dup_label
;
3968 fde
->dw_fde_hot_section_label
= NULL
;
3969 fde
->dw_fde_hot_section_end_label
= NULL
;
3970 fde
->dw_fde_unlikely_section_label
= NULL
;
3971 fde
->dw_fde_unlikely_section_end_label
= NULL
;
3972 fde
->dw_fde_switched_sections
= 0;
3973 fde
->dw_fde_switched_cold_to_hot
= 0;
3974 fde
->dw_fde_end
= NULL
;
3975 fde
->dw_fde_vms_end_prologue
= NULL
;
3976 fde
->dw_fde_vms_begin_epilogue
= NULL
;
3977 fde
->dw_fde_cfi
= NULL
;
3978 fde
->dw_fde_switch_cfi
= NULL
;
3979 fde
->funcdef_number
= current_function_funcdef_no
;
3980 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
3981 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
3982 fde
->nothrow
= crtl
->nothrow
;
3983 fde
->drap_reg
= INVALID_REGNUM
;
3984 fde
->vdrap_reg
= INVALID_REGNUM
;
3985 if (flag_reorder_blocks_and_partition
)
3987 section
*unlikelysec
;
3988 if (first_function_block_is_cold
)
3989 fde
->in_std_section
= 1;
3992 = (fnsec
== text_section
3993 || (cold_text_section
&& fnsec
== cold_text_section
));
3994 unlikelysec
= unlikely_text_section ();
3995 fde
->cold_in_std_section
3996 = (unlikelysec
== text_section
3997 || (cold_text_section
&& unlikelysec
== cold_text_section
));
4002 = (fnsec
== text_section
4003 || (cold_text_section
&& fnsec
== cold_text_section
));
4004 fde
->cold_in_std_section
= 0;
4007 args_size
= old_args_size
= 0;
4009 /* We only want to output line number information for the genuine dwarf2
4010 prologue case, not the eh frame case. */
4011 #ifdef DWARF2_DEBUGGING_INFO
4013 dwarf2out_source_line (line
, file
, 0, true);
4016 if (dwarf2out_do_cfi_asm ())
4017 dwarf2out_do_cfi_startproc (false);
4020 rtx personality
= get_personality_function (current_function_decl
);
4021 if (!current_unit_personality
)
4022 current_unit_personality
= personality
;
4024 /* We cannot keep a current personality per function as without CFI
4025 asm, at the point where we emit the CFI data, there is no current
4026 function anymore. */
4027 if (personality
&& current_unit_personality
!= personality
)
4028 sorry ("multiple EH personalities are supported only with assemblers "
4029 "supporting .cfi_personality directive");
4033 /* Output a marker (i.e. a label) for the end of the generated code
4034 for a function prologue. This gets called *after* the prologue code has
4038 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
4039 const char *file ATTRIBUTE_UNUSED
)
4042 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4044 /* Output a label to mark the endpoint of the code generated for this
4046 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
4047 current_function_funcdef_no
);
4048 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
4049 current_function_funcdef_no
);
4050 fde
= &fde_table
[fde_table_in_use
- 1];
4051 fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
4054 /* Output a marker (i.e. a label) for the beginning of the generated code
4055 for a function epilogue. This gets called *before* the prologue code has
4059 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
4060 const char *file ATTRIBUTE_UNUSED
)
4063 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4065 fde
= &fde_table
[fde_table_in_use
- 1];
4066 if (fde
->dw_fde_vms_begin_epilogue
)
4069 /* Output a label to mark the endpoint of the code generated for this
4071 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
4072 current_function_funcdef_no
);
4073 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
4074 current_function_funcdef_no
);
4075 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
4078 /* Output a marker (i.e. a label) for the absolute end of the generated code
4079 for a function definition. This gets called *after* the epilogue code has
4083 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
4084 const char *file ATTRIBUTE_UNUSED
)
4087 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4089 #ifdef DWARF2_DEBUGGING_INFO
4090 last_var_location_insn
= NULL_RTX
;
4093 if (dwarf2out_do_cfi_asm ())
4094 fprintf (asm_out_file
, "\t.cfi_endproc\n");
4096 /* Output a label to mark the endpoint of the code generated for this
4098 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
4099 current_function_funcdef_no
);
4100 ASM_OUTPUT_LABEL (asm_out_file
, label
);
4101 fde
= current_fde ();
4102 gcc_assert (fde
!= NULL
);
4103 fde
->dw_fde_end
= xstrdup (label
);
4107 dwarf2out_frame_init (void)
4109 /* Allocate the initial hunk of the fde_table. */
4110 fde_table
= ggc_alloc_cleared_vec_dw_fde_node (FDE_TABLE_INCREMENT
);
4111 fde_table_allocated
= FDE_TABLE_INCREMENT
;
4112 fde_table_in_use
= 0;
4114 /* Generate the CFA instructions common to all FDE's. Do it now for the
4115 sake of lookup_cfa. */
4117 /* On entry, the Canonical Frame Address is at SP. */
4118 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
4120 #ifdef DWARF2_UNWIND_INFO
4121 if (DWARF2_UNWIND_INFO
|| DWARF2_FRAME_INFO
)
4122 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
4127 dwarf2out_frame_finish (void)
4129 /* Output call frame information. */
4130 if (DWARF2_FRAME_INFO
)
4131 output_call_frame_info (0);
4133 #ifndef TARGET_UNWIND_INFO
4134 /* Output another copy for the unwinder. */
4135 if (! USING_SJLJ_EXCEPTIONS
&& (flag_unwind_tables
|| flag_exceptions
))
4136 output_call_frame_info (1);
4140 /* Note that the current function section is being used for code. */
4143 dwarf2out_note_section_used (void)
4145 section
*sec
= current_function_section ();
4146 if (sec
== text_section
)
4147 text_section_used
= true;
4148 else if (sec
== cold_text_section
)
4149 cold_text_section_used
= true;
4153 dwarf2out_switch_text_section (void)
4155 dw_fde_ref fde
= current_fde ();
4157 gcc_assert (cfun
&& fde
&& !fde
->dw_fde_switched_sections
);
4159 fde
->dw_fde_switched_sections
= 1;
4160 fde
->dw_fde_switched_cold_to_hot
= !in_cold_section_p
;
4162 fde
->dw_fde_hot_section_label
= crtl
->subsections
.hot_section_label
;
4163 fde
->dw_fde_hot_section_end_label
= crtl
->subsections
.hot_section_end_label
;
4164 fde
->dw_fde_unlikely_section_label
= crtl
->subsections
.cold_section_label
;
4165 fde
->dw_fde_unlikely_section_end_label
= crtl
->subsections
.cold_section_end_label
;
4166 have_multiple_function_sections
= true;
4168 /* Reset the current label on switching text sections, so that we
4169 don't attempt to advance_loc4 between labels in different sections. */
4170 fde
->dw_fde_current_label
= NULL
;
4172 /* There is no need to mark used sections when not debugging. */
4173 if (cold_text_section
!= NULL
)
4174 dwarf2out_note_section_used ();
4176 if (dwarf2out_do_cfi_asm ())
4177 fprintf (asm_out_file
, "\t.cfi_endproc\n");
4179 /* Now do the real section switch. */
4180 switch_to_section (current_function_section ());
4182 if (dwarf2out_do_cfi_asm ())
4184 dwarf2out_do_cfi_startproc (true);
4185 /* As this is a different FDE, insert all current CFI instructions
4187 output_cfis (fde
->dw_fde_cfi
, true, fde
, true);
4191 dw_cfi_ref cfi
= fde
->dw_fde_cfi
;
4193 cfi
= fde
->dw_fde_cfi
;
4195 while (cfi
->dw_cfi_next
!= NULL
)
4196 cfi
= cfi
->dw_cfi_next
;
4197 fde
->dw_fde_switch_cfi
= cfi
;
4202 /* And now, the subset of the debugging information support code necessary
4203 for emitting location expressions. */
4205 /* Data about a single source file. */
4206 struct GTY(()) dwarf_file_data
{
4207 const char * filename
;
4211 typedef struct dw_val_struct
*dw_val_ref
;
4212 typedef struct die_struct
*dw_die_ref
;
4213 typedef const struct die_struct
*const_dw_die_ref
;
4214 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
4215 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
4217 typedef struct GTY(()) deferred_locations_struct
4221 } deferred_locations
;
4223 DEF_VEC_O(deferred_locations
);
4224 DEF_VEC_ALLOC_O(deferred_locations
,gc
);
4226 static GTY(()) VEC(deferred_locations
, gc
) *deferred_locations_list
;
4228 DEF_VEC_P(dw_die_ref
);
4229 DEF_VEC_ALLOC_P(dw_die_ref
,heap
);
4231 /* Each DIE may have a series of attribute/value pairs. Values
4232 can take on several forms. The forms that are used in this
4233 implementation are listed below. */
4238 dw_val_class_offset
,
4240 dw_val_class_loc_list
,
4241 dw_val_class_range_list
,
4243 dw_val_class_unsigned_const
,
4244 dw_val_class_const_double
,
4247 dw_val_class_die_ref
,
4248 dw_val_class_fde_ref
,
4249 dw_val_class_lbl_id
,
4250 dw_val_class_lineptr
,
4252 dw_val_class_macptr
,
4255 dw_val_class_vms_delta
4258 /* Describe a floating point constant value, or a vector constant value. */
4260 typedef struct GTY(()) dw_vec_struct
{
4261 unsigned char * GTY((length ("%h.length"))) array
;
4267 /* The dw_val_node describes an attribute's value, as it is
4268 represented internally. */
4270 typedef struct GTY(()) dw_val_struct
{
4271 enum dw_val_class val_class
;
4272 union dw_val_struct_union
4274 rtx
GTY ((tag ("dw_val_class_addr"))) val_addr
;
4275 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_offset"))) val_offset
;
4276 dw_loc_list_ref
GTY ((tag ("dw_val_class_loc_list"))) val_loc_list
;
4277 dw_loc_descr_ref
GTY ((tag ("dw_val_class_loc"))) val_loc
;
4278 HOST_WIDE_INT
GTY ((default)) val_int
;
4279 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned
;
4280 double_int
GTY ((tag ("dw_val_class_const_double"))) val_double
;
4281 dw_vec_const
GTY ((tag ("dw_val_class_vec"))) val_vec
;
4282 struct dw_val_die_union
4286 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref
;
4287 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index
;
4288 struct indirect_string_node
* GTY ((tag ("dw_val_class_str"))) val_str
;
4289 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id
;
4290 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag
;
4291 struct dwarf_file_data
* GTY ((tag ("dw_val_class_file"))) val_file
;
4292 unsigned char GTY ((tag ("dw_val_class_data8"))) val_data8
[8];
4293 struct dw_val_vms_delta_union
4297 } GTY ((tag ("dw_val_class_vms_delta"))) val_vms_delta
;
4299 GTY ((desc ("%1.val_class"))) v
;
4303 /* Locations in memory are described using a sequence of stack machine
4306 typedef struct GTY(()) dw_loc_descr_struct
{
4307 dw_loc_descr_ref dw_loc_next
;
4308 ENUM_BITFIELD (dwarf_location_atom
) dw_loc_opc
: 8;
4309 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4310 from DW_OP_addr with a dtp-relative symbol relocation. */
4311 unsigned int dtprel
: 1;
4313 dw_val_node dw_loc_oprnd1
;
4314 dw_val_node dw_loc_oprnd2
;
4318 /* Location lists are ranges + location descriptions for that range,
4319 so you can track variables that are in different places over
4320 their entire life. */
4321 typedef struct GTY(()) dw_loc_list_struct
{
4322 dw_loc_list_ref dw_loc_next
;
4323 const char *begin
; /* Label for begin address of range */
4324 const char *end
; /* Label for end address of range */
4325 char *ll_symbol
; /* Label for beginning of location list.
4326 Only on head of list */
4327 const char *section
; /* Section this loclist is relative to */
4328 dw_loc_descr_ref expr
;
4331 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
4333 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
4335 /* Convert a DWARF stack opcode into its string name. */
4338 dwarf_stack_op_name (unsigned int op
)
4343 return "DW_OP_addr";
4345 return "DW_OP_deref";
4347 return "DW_OP_const1u";
4349 return "DW_OP_const1s";
4351 return "DW_OP_const2u";
4353 return "DW_OP_const2s";
4355 return "DW_OP_const4u";
4357 return "DW_OP_const4s";
4359 return "DW_OP_const8u";
4361 return "DW_OP_const8s";
4363 return "DW_OP_constu";
4365 return "DW_OP_consts";
4369 return "DW_OP_drop";
4371 return "DW_OP_over";
4373 return "DW_OP_pick";
4375 return "DW_OP_swap";
4379 return "DW_OP_xderef";
4387 return "DW_OP_minus";
4399 return "DW_OP_plus";
4400 case DW_OP_plus_uconst
:
4401 return "DW_OP_plus_uconst";
4407 return "DW_OP_shra";
4425 return "DW_OP_skip";
4427 return "DW_OP_lit0";
4429 return "DW_OP_lit1";
4431 return "DW_OP_lit2";
4433 return "DW_OP_lit3";
4435 return "DW_OP_lit4";
4437 return "DW_OP_lit5";
4439 return "DW_OP_lit6";
4441 return "DW_OP_lit7";
4443 return "DW_OP_lit8";
4445 return "DW_OP_lit9";
4447 return "DW_OP_lit10";
4449 return "DW_OP_lit11";
4451 return "DW_OP_lit12";
4453 return "DW_OP_lit13";
4455 return "DW_OP_lit14";
4457 return "DW_OP_lit15";
4459 return "DW_OP_lit16";
4461 return "DW_OP_lit17";
4463 return "DW_OP_lit18";
4465 return "DW_OP_lit19";
4467 return "DW_OP_lit20";
4469 return "DW_OP_lit21";
4471 return "DW_OP_lit22";
4473 return "DW_OP_lit23";
4475 return "DW_OP_lit24";
4477 return "DW_OP_lit25";
4479 return "DW_OP_lit26";
4481 return "DW_OP_lit27";
4483 return "DW_OP_lit28";
4485 return "DW_OP_lit29";
4487 return "DW_OP_lit30";
4489 return "DW_OP_lit31";
4491 return "DW_OP_reg0";
4493 return "DW_OP_reg1";
4495 return "DW_OP_reg2";
4497 return "DW_OP_reg3";
4499 return "DW_OP_reg4";
4501 return "DW_OP_reg5";
4503 return "DW_OP_reg6";
4505 return "DW_OP_reg7";
4507 return "DW_OP_reg8";
4509 return "DW_OP_reg9";
4511 return "DW_OP_reg10";
4513 return "DW_OP_reg11";
4515 return "DW_OP_reg12";
4517 return "DW_OP_reg13";
4519 return "DW_OP_reg14";
4521 return "DW_OP_reg15";
4523 return "DW_OP_reg16";
4525 return "DW_OP_reg17";
4527 return "DW_OP_reg18";
4529 return "DW_OP_reg19";
4531 return "DW_OP_reg20";
4533 return "DW_OP_reg21";
4535 return "DW_OP_reg22";
4537 return "DW_OP_reg23";
4539 return "DW_OP_reg24";
4541 return "DW_OP_reg25";
4543 return "DW_OP_reg26";
4545 return "DW_OP_reg27";
4547 return "DW_OP_reg28";
4549 return "DW_OP_reg29";
4551 return "DW_OP_reg30";
4553 return "DW_OP_reg31";
4555 return "DW_OP_breg0";
4557 return "DW_OP_breg1";
4559 return "DW_OP_breg2";
4561 return "DW_OP_breg3";
4563 return "DW_OP_breg4";
4565 return "DW_OP_breg5";
4567 return "DW_OP_breg6";
4569 return "DW_OP_breg7";
4571 return "DW_OP_breg8";
4573 return "DW_OP_breg9";
4575 return "DW_OP_breg10";
4577 return "DW_OP_breg11";
4579 return "DW_OP_breg12";
4581 return "DW_OP_breg13";
4583 return "DW_OP_breg14";
4585 return "DW_OP_breg15";
4587 return "DW_OP_breg16";
4589 return "DW_OP_breg17";
4591 return "DW_OP_breg18";
4593 return "DW_OP_breg19";
4595 return "DW_OP_breg20";
4597 return "DW_OP_breg21";
4599 return "DW_OP_breg22";
4601 return "DW_OP_breg23";
4603 return "DW_OP_breg24";
4605 return "DW_OP_breg25";
4607 return "DW_OP_breg26";
4609 return "DW_OP_breg27";
4611 return "DW_OP_breg28";
4613 return "DW_OP_breg29";
4615 return "DW_OP_breg30";
4617 return "DW_OP_breg31";
4619 return "DW_OP_regx";
4621 return "DW_OP_fbreg";
4623 return "DW_OP_bregx";
4625 return "DW_OP_piece";
4626 case DW_OP_deref_size
:
4627 return "DW_OP_deref_size";
4628 case DW_OP_xderef_size
:
4629 return "DW_OP_xderef_size";
4633 case DW_OP_push_object_address
:
4634 return "DW_OP_push_object_address";
4636 return "DW_OP_call2";
4638 return "DW_OP_call4";
4639 case DW_OP_call_ref
:
4640 return "DW_OP_call_ref";
4641 case DW_OP_implicit_value
:
4642 return "DW_OP_implicit_value";
4643 case DW_OP_stack_value
:
4644 return "DW_OP_stack_value";
4645 case DW_OP_form_tls_address
:
4646 return "DW_OP_form_tls_address";
4647 case DW_OP_call_frame_cfa
:
4648 return "DW_OP_call_frame_cfa";
4649 case DW_OP_bit_piece
:
4650 return "DW_OP_bit_piece";
4652 case DW_OP_GNU_push_tls_address
:
4653 return "DW_OP_GNU_push_tls_address";
4654 case DW_OP_GNU_uninit
:
4655 return "DW_OP_GNU_uninit";
4656 case DW_OP_GNU_encoded_addr
:
4657 return "DW_OP_GNU_encoded_addr";
4660 return "OP_<unknown>";
4664 /* Return a pointer to a newly allocated location description. Location
4665 descriptions are simple expression terms that can be strung
4666 together to form more complicated location (address) descriptions. */
4668 static inline dw_loc_descr_ref
4669 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
4670 unsigned HOST_WIDE_INT oprnd2
)
4672 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
4674 descr
->dw_loc_opc
= op
;
4675 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
4676 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
4677 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
4678 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
4683 /* Return a pointer to a newly allocated location description for
4686 static inline dw_loc_descr_ref
4687 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
4690 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
4693 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
4696 /* Add a location description term to a location description expression. */
4699 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
4701 dw_loc_descr_ref
*d
;
4703 /* Find the end of the chain. */
4704 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
4710 /* Add a constant OFFSET to a location expression. */
4713 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
4715 dw_loc_descr_ref loc
;
4718 gcc_assert (*list_head
!= NULL
);
4723 /* Find the end of the chain. */
4724 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
4728 if (loc
->dw_loc_opc
== DW_OP_fbreg
4729 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
4730 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
4731 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
4732 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
4734 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4735 offset. Don't optimize if an signed integer overflow would happen. */
4737 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
4738 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
4741 else if (offset
> 0)
4742 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
4746 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
4747 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
4751 #ifdef DWARF2_DEBUGGING_INFO
4752 /* Add a constant OFFSET to a location list. */
4755 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
4758 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
4759 loc_descr_plus_const (&d
->expr
, offset
);
4763 /* Return the size of a location descriptor. */
4765 static unsigned long
4766 size_of_loc_descr (dw_loc_descr_ref loc
)
4768 unsigned long size
= 1;
4770 switch (loc
->dw_loc_opc
)
4773 size
+= DWARF2_ADDR_SIZE
;
4792 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4795 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4800 case DW_OP_plus_uconst
:
4801 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4839 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4842 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4845 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4848 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4849 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
4852 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4854 case DW_OP_bit_piece
:
4855 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4856 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
4858 case DW_OP_deref_size
:
4859 case DW_OP_xderef_size
:
4868 case DW_OP_call_ref
:
4869 size
+= DWARF2_ADDR_SIZE
;
4871 case DW_OP_implicit_value
:
4872 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
4873 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
4882 /* Return the size of a series of location descriptors. */
4884 static unsigned long
4885 size_of_locs (dw_loc_descr_ref loc
)
4890 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
4891 field, to avoid writing to a PCH file. */
4892 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
4894 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
4896 size
+= size_of_loc_descr (l
);
4901 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
4903 l
->dw_loc_addr
= size
;
4904 size
+= size_of_loc_descr (l
);
4910 #ifdef DWARF2_DEBUGGING_INFO
4911 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
4914 /* Output location description stack opcode's operands (if any). */
4917 output_loc_operands (dw_loc_descr_ref loc
)
4919 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
4920 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
4922 switch (loc
->dw_loc_opc
)
4924 #ifdef DWARF2_DEBUGGING_INFO
4927 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
4931 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
4935 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
4936 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
4943 gcc_assert (val1
->val_class
== dw_val_class_loc
);
4944 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
4946 dw2_asm_output_data (2, offset
, NULL
);
4949 case DW_OP_implicit_value
:
4950 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
4951 switch (val2
->val_class
)
4953 case dw_val_class_const
:
4954 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
4956 case dw_val_class_vec
:
4958 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
4959 unsigned int len
= val2
->v
.val_vec
.length
;
4963 if (elt_size
> sizeof (HOST_WIDE_INT
))
4968 for (i
= 0, p
= val2
->v
.val_vec
.array
;
4971 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
4972 "fp or vector constant word %u", i
);
4975 case dw_val_class_const_double
:
4977 unsigned HOST_WIDE_INT first
, second
;
4979 if (WORDS_BIG_ENDIAN
)
4981 first
= val2
->v
.val_double
.high
;
4982 second
= val2
->v
.val_double
.low
;
4986 first
= val2
->v
.val_double
.low
;
4987 second
= val2
->v
.val_double
.high
;
4989 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
4991 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
4995 case dw_val_class_addr
:
4996 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
4997 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
5012 case DW_OP_implicit_value
:
5013 /* We currently don't make any attempt to make sure these are
5014 aligned properly like we do for the main unwind info, so
5015 don't support emitting things larger than a byte if we're
5016 only doing unwinding. */
5021 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
5024 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5027 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
5030 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
5032 case DW_OP_plus_uconst
:
5033 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5067 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
5070 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5073 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
5076 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5077 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
5080 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5082 case DW_OP_bit_piece
:
5083 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
5084 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
5086 case DW_OP_deref_size
:
5087 case DW_OP_xderef_size
:
5088 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
5094 if (targetm
.asm_out
.output_dwarf_dtprel
)
5096 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
5099 fputc ('\n', asm_out_file
);
5106 #ifdef DWARF2_DEBUGGING_INFO
5107 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
5115 /* Other codes have no operands. */
5120 /* Output a sequence of location operations. */
5123 output_loc_sequence (dw_loc_descr_ref loc
)
5125 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
5127 /* Output the opcode. */
5128 dw2_asm_output_data (1, loc
->dw_loc_opc
,
5129 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
5131 /* Output the operand(s) (if any). */
5132 output_loc_operands (loc
);
5136 /* Output location description stack opcode's operands (if any).
5137 The output is single bytes on a line, suitable for .cfi_escape. */
5140 output_loc_operands_raw (dw_loc_descr_ref loc
)
5142 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
5143 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
5145 switch (loc
->dw_loc_opc
)
5148 case DW_OP_implicit_value
:
5149 /* We cannot output addresses in .cfi_escape, only bytes. */
5155 case DW_OP_deref_size
:
5156 case DW_OP_xderef_size
:
5157 fputc (',', asm_out_file
);
5158 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
5163 fputc (',', asm_out_file
);
5164 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
5169 fputc (',', asm_out_file
);
5170 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
5175 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
5176 fputc (',', asm_out_file
);
5177 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
5185 gcc_assert (val1
->val_class
== dw_val_class_loc
);
5186 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
5188 fputc (',', asm_out_file
);
5189 dw2_asm_output_data_raw (2, offset
);
5194 case DW_OP_plus_uconst
:
5197 fputc (',', asm_out_file
);
5198 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
5201 case DW_OP_bit_piece
:
5202 fputc (',', asm_out_file
);
5203 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
5204 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
5241 fputc (',', asm_out_file
);
5242 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
5246 fputc (',', asm_out_file
);
5247 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
5248 fputc (',', asm_out_file
);
5249 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
5253 /* Other codes have no operands. */
5259 output_loc_sequence_raw (dw_loc_descr_ref loc
)
5263 /* Output the opcode. */
5264 fprintf (asm_out_file
, "%#x", loc
->dw_loc_opc
);
5265 output_loc_operands_raw (loc
);
5267 if (!loc
->dw_loc_next
)
5269 loc
= loc
->dw_loc_next
;
5271 fputc (',', asm_out_file
);
5275 /* This routine will generate the correct assembly data for a location
5276 description based on a cfi entry with a complex address. */
5279 output_cfa_loc (dw_cfi_ref cfi
)
5281 dw_loc_descr_ref loc
;
5284 if (cfi
->dw_cfi_opc
== DW_CFA_expression
)
5286 dw2_asm_output_data (1, cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, NULL
);
5287 loc
= cfi
->dw_cfi_oprnd2
.dw_cfi_loc
;
5290 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
5292 /* Output the size of the block. */
5293 size
= size_of_locs (loc
);
5294 dw2_asm_output_data_uleb128 (size
, NULL
);
5296 /* Now output the operations themselves. */
5297 output_loc_sequence (loc
);
5300 /* Similar, but used for .cfi_escape. */
5303 output_cfa_loc_raw (dw_cfi_ref cfi
)
5305 dw_loc_descr_ref loc
;
5308 if (cfi
->dw_cfi_opc
== DW_CFA_expression
)
5310 fprintf (asm_out_file
, "%#x,", cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
5311 loc
= cfi
->dw_cfi_oprnd2
.dw_cfi_loc
;
5314 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
5316 /* Output the size of the block. */
5317 size
= size_of_locs (loc
);
5318 dw2_asm_output_data_uleb128_raw (size
);
5319 fputc (',', asm_out_file
);
5321 /* Now output the operations themselves. */
5322 output_loc_sequence_raw (loc
);
5325 /* This function builds a dwarf location descriptor sequence from a
5326 dw_cfa_location, adding the given OFFSET to the result of the
5329 static struct dw_loc_descr_struct
*
5330 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
5332 struct dw_loc_descr_struct
*head
, *tmp
;
5334 offset
+= cfa
->offset
;
5338 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
5339 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
5340 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
5341 add_loc_descr (&head
, tmp
);
5344 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
5345 add_loc_descr (&head
, tmp
);
5349 head
= new_reg_loc_descr (cfa
->reg
, offset
);
5354 /* This function builds a dwarf location descriptor sequence for
5355 the address at OFFSET from the CFA when stack is aligned to
5358 static struct dw_loc_descr_struct
*
5359 build_cfa_aligned_loc (HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
5361 struct dw_loc_descr_struct
*head
;
5362 unsigned int dwarf_fp
5363 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
5365 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5366 if (cfa
.reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
.indirect
== 0)
5368 head
= new_reg_loc_descr (dwarf_fp
, 0);
5369 add_loc_descr (&head
, int_loc_descriptor (alignment
));
5370 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
5371 loc_descr_plus_const (&head
, offset
);
5374 head
= new_reg_loc_descr (dwarf_fp
, offset
);
5378 /* This function fills in aa dw_cfa_location structure from a dwarf location
5379 descriptor sequence. */
5382 get_cfa_from_loc_descr (dw_cfa_location
*cfa
, struct dw_loc_descr_struct
*loc
)
5384 struct dw_loc_descr_struct
*ptr
;
5386 cfa
->base_offset
= 0;
5390 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
5392 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
5428 cfa
->reg
= op
- DW_OP_reg0
;
5431 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
5465 cfa
->reg
= op
- DW_OP_breg0
;
5466 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
5469 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
5470 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
5475 case DW_OP_plus_uconst
:
5476 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
5479 internal_error ("DW_LOC_OP %s not implemented",
5480 dwarf_stack_op_name (ptr
->dw_loc_opc
));
5484 #endif /* .debug_frame support */
5486 /* And now, the support for symbolic debugging information. */
5487 #ifdef DWARF2_DEBUGGING_INFO
5489 /* .debug_str support. */
5490 static int output_indirect_string (void **, void *);
5492 static void dwarf2out_init (const char *);
5493 static void dwarf2out_finish (const char *);
5494 static void dwarf2out_assembly_start (void);
5495 static void dwarf2out_define (unsigned int, const char *);
5496 static void dwarf2out_undef (unsigned int, const char *);
5497 static void dwarf2out_start_source_file (unsigned, const char *);
5498 static void dwarf2out_end_source_file (unsigned);
5499 static void dwarf2out_function_decl (tree
);
5500 static void dwarf2out_begin_block (unsigned, unsigned);
5501 static void dwarf2out_end_block (unsigned, unsigned);
5502 static bool dwarf2out_ignore_block (const_tree
);
5503 static void dwarf2out_global_decl (tree
);
5504 static void dwarf2out_type_decl (tree
, int);
5505 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
5506 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
5508 static void dwarf2out_abstract_function (tree
);
5509 static void dwarf2out_var_location (rtx
);
5510 static void dwarf2out_direct_call (tree
);
5511 static void dwarf2out_virtual_call_token (tree
, int);
5512 static void dwarf2out_copy_call_info (rtx
, rtx
);
5513 static void dwarf2out_virtual_call (int);
5514 static void dwarf2out_begin_function (tree
);
5515 static void dwarf2out_set_name (tree
, tree
);
5517 /* The debug hooks structure. */
5519 const struct gcc_debug_hooks dwarf2_debug_hooks
=
5523 dwarf2out_assembly_start
,
5526 dwarf2out_start_source_file
,
5527 dwarf2out_end_source_file
,
5528 dwarf2out_begin_block
,
5529 dwarf2out_end_block
,
5530 dwarf2out_ignore_block
,
5531 dwarf2out_source_line
,
5532 dwarf2out_begin_prologue
,
5533 #if VMS_DEBUGGING_INFO
5534 dwarf2out_vms_end_prologue
,
5535 dwarf2out_vms_begin_epilogue
,
5537 debug_nothing_int_charstar
,
5538 debug_nothing_int_charstar
,
5540 dwarf2out_end_epilogue
,
5541 dwarf2out_begin_function
,
5542 debug_nothing_int
, /* end_function */
5543 dwarf2out_function_decl
, /* function_decl */
5544 dwarf2out_global_decl
,
5545 dwarf2out_type_decl
, /* type_decl */
5546 dwarf2out_imported_module_or_decl
,
5547 debug_nothing_tree
, /* deferred_inline_function */
5548 /* The DWARF 2 backend tries to reduce debugging bloat by not
5549 emitting the abstract description of inline functions until
5550 something tries to reference them. */
5551 dwarf2out_abstract_function
, /* outlining_inline_function */
5552 debug_nothing_rtx
, /* label */
5553 debug_nothing_int
, /* handle_pch */
5554 dwarf2out_var_location
,
5555 dwarf2out_switch_text_section
,
5556 dwarf2out_direct_call
,
5557 dwarf2out_virtual_call_token
,
5558 dwarf2out_copy_call_info
,
5559 dwarf2out_virtual_call
,
5561 1 /* start_end_main_source_file */
5565 /* NOTE: In the comments in this file, many references are made to
5566 "Debugging Information Entries". This term is abbreviated as `DIE'
5567 throughout the remainder of this file. */
5569 /* An internal representation of the DWARF output is built, and then
5570 walked to generate the DWARF debugging info. The walk of the internal
5571 representation is done after the entire program has been compiled.
5572 The types below are used to describe the internal representation. */
5574 /* Various DIE's use offsets relative to the beginning of the
5575 .debug_info section to refer to each other. */
5577 typedef long int dw_offset
;
5579 /* Define typedefs here to avoid circular dependencies. */
5581 typedef struct dw_attr_struct
*dw_attr_ref
;
5582 typedef struct dw_line_info_struct
*dw_line_info_ref
;
5583 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
5584 typedef struct pubname_struct
*pubname_ref
;
5585 typedef struct dw_ranges_struct
*dw_ranges_ref
;
5586 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
5587 typedef struct comdat_type_struct
*comdat_type_node_ref
;
5589 /* Each entry in the line_info_table maintains the file and
5590 line number associated with the label generated for that
5591 entry. The label gives the PC value associated with
5592 the line number entry. */
5594 typedef struct GTY(()) dw_line_info_struct
{
5595 unsigned long dw_file_num
;
5596 unsigned long dw_line_num
;
5600 /* Line information for functions in separate sections; each one gets its
5602 typedef struct GTY(()) dw_separate_line_info_struct
{
5603 unsigned long dw_file_num
;
5604 unsigned long dw_line_num
;
5605 unsigned long function
;
5607 dw_separate_line_info_entry
;
5609 /* Each DIE attribute has a field specifying the attribute kind,
5610 a link to the next attribute in the chain, and an attribute value.
5611 Attributes are typically linked below the DIE they modify. */
5613 typedef struct GTY(()) dw_attr_struct
{
5614 enum dwarf_attribute dw_attr
;
5615 dw_val_node dw_attr_val
;
5619 DEF_VEC_O(dw_attr_node
);
5620 DEF_VEC_ALLOC_O(dw_attr_node
,gc
);
5622 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5623 The children of each node form a circular list linked by
5624 die_sib. die_child points to the node *before* the "first" child node. */
5626 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
5627 enum dwarf_tag die_tag
;
5628 union die_symbol_or_type_node
5630 char * GTY ((tag ("0"))) die_symbol
;
5631 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
5633 GTY ((desc ("dwarf_version >= 4"))) die_id
;
5634 VEC(dw_attr_node
,gc
) * die_attr
;
5635 dw_die_ref die_parent
;
5636 dw_die_ref die_child
;
5638 dw_die_ref die_definition
; /* ref from a specification to its definition */
5639 dw_offset die_offset
;
5640 unsigned long die_abbrev
;
5642 /* Die is used and must not be pruned as unused. */
5643 int die_perennial_p
;
5644 unsigned int decl_id
;
5648 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5649 #define FOR_EACH_CHILD(die, c, expr) do { \
5650 c = die->die_child; \
5654 } while (c != die->die_child); \
5657 /* The pubname structure */
5659 typedef struct GTY(()) pubname_struct
{
5665 DEF_VEC_O(pubname_entry
);
5666 DEF_VEC_ALLOC_O(pubname_entry
, gc
);
5668 struct GTY(()) dw_ranges_struct
{
5669 /* If this is positive, it's a block number, otherwise it's a
5670 bitwise-negated index into dw_ranges_by_label. */
5674 struct GTY(()) dw_ranges_by_label_struct
{
5679 /* The comdat type node structure. */
5680 typedef struct GTY(()) comdat_type_struct
5682 dw_die_ref root_die
;
5683 dw_die_ref type_die
;
5684 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
5685 struct comdat_type_struct
*next
;
5689 /* The limbo die list structure. */
5690 typedef struct GTY(()) limbo_die_struct
{
5693 struct limbo_die_struct
*next
;
5697 typedef struct GTY(()) skeleton_chain_struct
5701 struct skeleton_chain_struct
*parent
;
5703 skeleton_chain_node
;
5705 /* How to start an assembler comment. */
5706 #ifndef ASM_COMMENT_START
5707 #define ASM_COMMENT_START ";#"
5710 /* Define a macro which returns nonzero for a TYPE_DECL which was
5711 implicitly generated for a tagged type.
5713 Note that unlike the gcc front end (which generates a NULL named
5714 TYPE_DECL node for each complete tagged type, each array type, and
5715 each function type node created) the g++ front end generates a
5716 _named_ TYPE_DECL node for each tagged type node created.
5717 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
5718 generate a DW_TAG_typedef DIE for them. */
5720 #define TYPE_DECL_IS_STUB(decl) \
5721 (DECL_NAME (decl) == NULL_TREE \
5722 || (DECL_ARTIFICIAL (decl) \
5723 && is_tagged_type (TREE_TYPE (decl)) \
5724 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
5725 /* This is necessary for stub decls that \
5726 appear in nested inline functions. */ \
5727 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
5728 && (decl_ultimate_origin (decl) \
5729 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
5731 /* Information concerning the compilation unit's programming
5732 language, and compiler version. */
5734 /* Fixed size portion of the DWARF compilation unit header. */
5735 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
5736 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
5738 /* Fixed size portion of the DWARF comdat type unit header. */
5739 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
5740 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
5741 + DWARF_OFFSET_SIZE)
5743 /* Fixed size portion of public names info. */
5744 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
5746 /* Fixed size portion of the address range info. */
5747 #define DWARF_ARANGES_HEADER_SIZE \
5748 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5749 DWARF2_ADDR_SIZE * 2) \
5750 - DWARF_INITIAL_LENGTH_SIZE)
5752 /* Size of padding portion in the address range info. It must be
5753 aligned to twice the pointer size. */
5754 #define DWARF_ARANGES_PAD_SIZE \
5755 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5756 DWARF2_ADDR_SIZE * 2) \
5757 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
5759 /* Use assembler line directives if available. */
5760 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
5761 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
5762 #define DWARF2_ASM_LINE_DEBUG_INFO 1
5764 #define DWARF2_ASM_LINE_DEBUG_INFO 0
5768 /* Minimum line offset in a special line info. opcode.
5769 This value was chosen to give a reasonable range of values. */
5770 #define DWARF_LINE_BASE -10
5772 /* First special line opcode - leave room for the standard opcodes. */
5773 #define DWARF_LINE_OPCODE_BASE 10
5775 /* Range of line offsets in a special line info. opcode. */
5776 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
5778 /* Flag that indicates the initial value of the is_stmt_start flag.
5779 In the present implementation, we do not mark any lines as
5780 the beginning of a source statement, because that information
5781 is not made available by the GCC front-end. */
5782 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
5784 /* Maximum number of operations per instruction bundle. */
5785 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
5786 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
5789 #ifdef DWARF2_DEBUGGING_INFO
5790 /* This location is used by calc_die_sizes() to keep track
5791 the offset of each DIE within the .debug_info section. */
5792 static unsigned long next_die_offset
;
5795 /* Record the root of the DIE's built for the current compilation unit. */
5796 static GTY(()) dw_die_ref comp_unit_die
;
5798 /* A list of type DIEs that have been separated into comdat sections. */
5799 static GTY(()) comdat_type_node
*comdat_type_list
;
5801 /* A list of DIEs with a NULL parent waiting to be relocated. */
5802 static GTY(()) limbo_die_node
*limbo_die_list
;
5804 /* A list of DIEs for which we may have to generate
5805 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
5806 static GTY(()) limbo_die_node
*deferred_asm_name
;
5808 /* Filenames referenced by this compilation unit. */
5809 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
5811 /* A hash table of references to DIE's that describe declarations.
5812 The key is a DECL_UID() which is a unique number identifying each decl. */
5813 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
5815 /* A hash table of references to DIE's that describe COMMON blocks.
5816 The key is DECL_UID() ^ die_parent. */
5817 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
5819 typedef struct GTY(()) die_arg_entry_struct
{
5824 DEF_VEC_O(die_arg_entry
);
5825 DEF_VEC_ALLOC_O(die_arg_entry
,gc
);
5827 /* Node of the variable location list. */
5828 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
5829 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
5830 EXPR_LIST chain. For small bitsizes, bitsize is encoded
5831 in mode of the EXPR_LIST node and first EXPR_LIST operand
5832 is either NOTE_INSN_VAR_LOCATION for a piece with a known
5833 location or NULL for padding. For larger bitsizes,
5834 mode is 0 and first operand is a CONCAT with bitsize
5835 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
5836 NULL as second operand. */
5838 const char * GTY (()) label
;
5839 struct var_loc_node
* GTY (()) next
;
5842 /* Variable location list. */
5843 struct GTY (()) var_loc_list_def
{
5844 struct var_loc_node
* GTY (()) first
;
5846 /* Pointer to the last but one or last element of the
5847 chained list. If the list is empty, both first and
5848 last are NULL, if the list contains just one node
5849 or the last node certainly is not redundant, it points
5850 to the last node, otherwise points to the last but one.
5851 Do not mark it for GC because it is marked through the chain. */
5852 struct var_loc_node
* GTY ((skip ("%h"))) last
;
5854 /* DECL_UID of the variable decl. */
5855 unsigned int decl_id
;
5857 typedef struct var_loc_list_def var_loc_list
;
5860 /* Table of decl location linked lists. */
5861 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
5863 /* A pointer to the base of a list of references to DIE's that
5864 are uniquely identified by their tag, presence/absence of
5865 children DIE's, and list of attribute/value pairs. */
5866 static GTY((length ("abbrev_die_table_allocated")))
5867 dw_die_ref
*abbrev_die_table
;
5869 /* Number of elements currently allocated for abbrev_die_table. */
5870 static GTY(()) unsigned abbrev_die_table_allocated
;
5872 /* Number of elements in type_die_table currently in use. */
5873 static GTY(()) unsigned abbrev_die_table_in_use
;
5875 /* Size (in elements) of increments by which we may expand the
5876 abbrev_die_table. */
5877 #define ABBREV_DIE_TABLE_INCREMENT 256
5879 /* A pointer to the base of a table that contains line information
5880 for each source code line in .text in the compilation unit. */
5881 static GTY((length ("line_info_table_allocated")))
5882 dw_line_info_ref line_info_table
;
5884 /* Number of elements currently allocated for line_info_table. */
5885 static GTY(()) unsigned line_info_table_allocated
;
5887 /* Number of elements in line_info_table currently in use. */
5888 static GTY(()) unsigned line_info_table_in_use
;
5890 /* A pointer to the base of a table that contains line information
5891 for each source code line outside of .text in the compilation unit. */
5892 static GTY ((length ("separate_line_info_table_allocated")))
5893 dw_separate_line_info_ref separate_line_info_table
;
5895 /* Number of elements currently allocated for separate_line_info_table. */
5896 static GTY(()) unsigned separate_line_info_table_allocated
;
5898 /* Number of elements in separate_line_info_table currently in use. */
5899 static GTY(()) unsigned separate_line_info_table_in_use
;
5901 /* Size (in elements) of increments by which we may expand the
5903 #define LINE_INFO_TABLE_INCREMENT 1024
5905 /* A pointer to the base of a table that contains a list of publicly
5906 accessible names. */
5907 static GTY (()) VEC (pubname_entry
, gc
) * pubname_table
;
5909 /* A pointer to the base of a table that contains a list of publicly
5910 accessible types. */
5911 static GTY (()) VEC (pubname_entry
, gc
) * pubtype_table
;
5913 /* Array of dies for which we should generate .debug_arange info. */
5914 static GTY((length ("arange_table_allocated"))) dw_die_ref
*arange_table
;
5916 /* Number of elements currently allocated for arange_table. */
5917 static GTY(()) unsigned arange_table_allocated
;
5919 /* Number of elements in arange_table currently in use. */
5920 static GTY(()) unsigned arange_table_in_use
;
5922 /* Size (in elements) of increments by which we may expand the
5924 #define ARANGE_TABLE_INCREMENT 64
5926 /* Array of dies for which we should generate .debug_ranges info. */
5927 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
5929 /* Number of elements currently allocated for ranges_table. */
5930 static GTY(()) unsigned ranges_table_allocated
;
5932 /* Number of elements in ranges_table currently in use. */
5933 static GTY(()) unsigned ranges_table_in_use
;
5935 /* Array of pairs of labels referenced in ranges_table. */
5936 static GTY ((length ("ranges_by_label_allocated")))
5937 dw_ranges_by_label_ref ranges_by_label
;
5939 /* Number of elements currently allocated for ranges_by_label. */
5940 static GTY(()) unsigned ranges_by_label_allocated
;
5942 /* Number of elements in ranges_by_label currently in use. */
5943 static GTY(()) unsigned ranges_by_label_in_use
;
5945 /* Size (in elements) of increments by which we may expand the
5947 #define RANGES_TABLE_INCREMENT 64
5949 /* Whether we have location lists that need outputting */
5950 static GTY(()) bool have_location_lists
;
5952 /* Unique label counter. */
5953 static GTY(()) unsigned int loclabel_num
;
5955 /* Unique label counter for point-of-call tables. */
5956 static GTY(()) unsigned int poc_label_num
;
5958 /* The direct call table structure. */
5960 typedef struct GTY(()) dcall_struct
{
5961 unsigned int poc_label_num
;
5963 dw_die_ref targ_die
;
5967 DEF_VEC_O(dcall_entry
);
5968 DEF_VEC_ALLOC_O(dcall_entry
, gc
);
5970 /* The virtual call table structure. */
5972 typedef struct GTY(()) vcall_struct
{
5973 unsigned int poc_label_num
;
5974 unsigned int vtable_slot
;
5978 DEF_VEC_O(vcall_entry
);
5979 DEF_VEC_ALLOC_O(vcall_entry
, gc
);
5981 /* Pointers to the direct and virtual call tables. */
5982 static GTY (()) VEC (dcall_entry
, gc
) * dcall_table
= NULL
;
5983 static GTY (()) VEC (vcall_entry
, gc
) * vcall_table
= NULL
;
5985 /* A hash table to map INSN_UIDs to vtable slot indexes. */
5987 struct GTY (()) vcall_insn
{
5989 unsigned int vtable_slot
;
5992 static GTY ((param_is (struct vcall_insn
))) htab_t vcall_insn_table
;
5994 #ifdef DWARF2_DEBUGGING_INFO
5995 /* Record whether the function being analyzed contains inlined functions. */
5996 static int current_function_has_inlines
;
5998 #if 0 && defined (MIPS_DEBUGGING_INFO)
5999 static int comp_unit_has_inlines
;
6002 /* The last file entry emitted by maybe_emit_file(). */
6003 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
6005 /* Number of internal labels generated by gen_internal_sym(). */
6006 static GTY(()) int label_num
;
6008 /* Cached result of previous call to lookup_filename. */
6009 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
6011 static GTY(()) VEC(die_arg_entry
,gc
) *tmpl_value_parm_die_table
;
6013 #ifdef DWARF2_DEBUGGING_INFO
6015 /* Offset from the "steady-state frame pointer" to the frame base,
6016 within the current function. */
6017 static HOST_WIDE_INT frame_pointer_fb_offset
;
6019 /* Forward declarations for functions defined in this file. */
6021 static int is_pseudo_reg (const_rtx
);
6022 static tree
type_main_variant (tree
);
6023 static int is_tagged_type (const_tree
);
6024 static const char *dwarf_tag_name (unsigned);
6025 static const char *dwarf_attr_name (unsigned);
6026 static const char *dwarf_form_name (unsigned);
6027 static tree
decl_ultimate_origin (const_tree
);
6028 static tree
decl_class_context (tree
);
6029 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
6030 static inline enum dw_val_class
AT_class (dw_attr_ref
);
6031 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
6032 static inline unsigned AT_flag (dw_attr_ref
);
6033 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
6034 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
6035 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
6036 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
6037 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
6038 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
6039 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
6040 unsigned int, unsigned char *);
6041 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
6042 static hashval_t
debug_str_do_hash (const void *);
6043 static int debug_str_eq (const void *, const void *);
6044 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
6045 static inline const char *AT_string (dw_attr_ref
);
6046 static enum dwarf_form
AT_string_form (dw_attr_ref
);
6047 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
6048 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
6049 static inline dw_die_ref
AT_ref (dw_attr_ref
);
6050 static inline int AT_ref_external (dw_attr_ref
);
6051 static inline void set_AT_ref_external (dw_attr_ref
, int);
6052 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
6053 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
6054 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
6055 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
6057 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
6058 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
6059 static inline rtx
AT_addr (dw_attr_ref
);
6060 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
6061 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
6062 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
6063 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
6064 unsigned HOST_WIDE_INT
);
6065 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
6067 static inline const char *AT_lbl (dw_attr_ref
);
6068 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
6069 static const char *get_AT_low_pc (dw_die_ref
);
6070 static const char *get_AT_hi_pc (dw_die_ref
);
6071 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
6072 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
6073 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
6074 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
6075 static bool is_cxx (void);
6076 static bool is_fortran (void);
6077 static bool is_ada (void);
6078 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
6079 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
6080 static void add_child_die (dw_die_ref
, dw_die_ref
);
6081 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
6082 static dw_die_ref
lookup_type_die (tree
);
6083 static void equate_type_number_to_die (tree
, dw_die_ref
);
6084 static hashval_t
decl_die_table_hash (const void *);
6085 static int decl_die_table_eq (const void *, const void *);
6086 static dw_die_ref
lookup_decl_die (tree
);
6087 static hashval_t
common_block_die_table_hash (const void *);
6088 static int common_block_die_table_eq (const void *, const void *);
6089 static hashval_t
decl_loc_table_hash (const void *);
6090 static int decl_loc_table_eq (const void *, const void *);
6091 static var_loc_list
*lookup_decl_loc (const_tree
);
6092 static void equate_decl_number_to_die (tree
, dw_die_ref
);
6093 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
6094 static void print_spaces (FILE *);
6095 static void print_die (dw_die_ref
, FILE *);
6096 static void print_dwarf_line_table (FILE *);
6097 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
6098 static dw_die_ref
pop_compile_unit (dw_die_ref
);
6099 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
6100 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
6101 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
6102 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
6103 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
6104 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
6105 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
6106 struct md5_ctx
*, int *);
6107 struct checksum_attributes
;
6108 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
6109 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
6110 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
6111 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
6112 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
6113 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
6114 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
6115 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
6116 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
6117 static void compute_section_prefix (dw_die_ref
);
6118 static int is_type_die (dw_die_ref
);
6119 static int is_comdat_die (dw_die_ref
);
6120 static int is_symbol_die (dw_die_ref
);
6121 static void assign_symbol_names (dw_die_ref
);
6122 static void break_out_includes (dw_die_ref
);
6123 static int is_declaration_die (dw_die_ref
);
6124 static int should_move_die_to_comdat (dw_die_ref
);
6125 static dw_die_ref
clone_as_declaration (dw_die_ref
);
6126 static dw_die_ref
clone_die (dw_die_ref
);
6127 static dw_die_ref
clone_tree (dw_die_ref
);
6128 static void copy_declaration_context (dw_die_ref
, dw_die_ref
);
6129 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
6130 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
6131 static dw_die_ref
generate_skeleton (dw_die_ref
);
6132 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
6134 static void break_out_comdat_types (dw_die_ref
);
6135 static dw_die_ref
copy_ancestor_tree (dw_die_ref
, dw_die_ref
, htab_t
);
6136 static void copy_decls_walk (dw_die_ref
, dw_die_ref
, htab_t
);
6137 static void copy_decls_for_unworthy_types (dw_die_ref
);
6139 static hashval_t
htab_cu_hash (const void *);
6140 static int htab_cu_eq (const void *, const void *);
6141 static void htab_cu_del (void *);
6142 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
6143 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
6144 static void add_sibling_attributes (dw_die_ref
);
6145 static void build_abbrev_table (dw_die_ref
);
6146 static void output_location_lists (dw_die_ref
);
6147 static int constant_size (unsigned HOST_WIDE_INT
);
6148 static unsigned long size_of_die (dw_die_ref
);
6149 static void calc_die_sizes (dw_die_ref
);
6150 static void mark_dies (dw_die_ref
);
6151 static void unmark_dies (dw_die_ref
);
6152 static void unmark_all_dies (dw_die_ref
);
6153 static unsigned long size_of_pubnames (VEC (pubname_entry
,gc
) *);
6154 static unsigned long size_of_aranges (void);
6155 static enum dwarf_form
value_format (dw_attr_ref
);
6156 static void output_value_format (dw_attr_ref
);
6157 static void output_abbrev_section (void);
6158 static void output_die_symbol (dw_die_ref
);
6159 static void output_die (dw_die_ref
);
6160 static void output_compilation_unit_header (void);
6161 static void output_comp_unit (dw_die_ref
, int);
6162 static void output_comdat_type_unit (comdat_type_node
*);
6163 static const char *dwarf2_name (tree
, int);
6164 static void add_pubname (tree
, dw_die_ref
);
6165 static void add_pubname_string (const char *, dw_die_ref
);
6166 static void add_pubtype (tree
, dw_die_ref
);
6167 static void output_pubnames (VEC (pubname_entry
,gc
) *);
6168 static void add_arange (tree
, dw_die_ref
);
6169 static void output_aranges (void);
6170 static unsigned int add_ranges_num (int);
6171 static unsigned int add_ranges (const_tree
);
6172 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
6174 static void output_ranges (void);
6175 static void output_line_info (void);
6176 static void output_file_names (void);
6177 static dw_die_ref
base_type_die (tree
);
6178 static int is_base_type (tree
);
6179 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
6180 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
6181 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
6182 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
6183 static int type_is_enum (const_tree
);
6184 static unsigned int dbx_reg_number (const_rtx
);
6185 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
6186 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
6187 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
6188 enum var_init_status
);
6189 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
6190 enum var_init_status
);
6191 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
6192 enum var_init_status
);
6193 static int is_based_loc (const_rtx
);
6194 static int resolve_one_addr (rtx
*, void *);
6195 static dw_loc_descr_ref
mem_loc_descriptor (rtx
, enum machine_mode mode
,
6196 enum var_init_status
);
6197 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
6198 enum var_init_status
);
6199 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
6200 enum var_init_status
);
6201 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
6202 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
6203 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
6204 static tree
field_type (const_tree
);
6205 static unsigned int simple_type_align_in_bits (const_tree
);
6206 static unsigned int simple_decl_align_in_bits (const_tree
);
6207 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
6208 static HOST_WIDE_INT
field_byte_offset (const_tree
);
6209 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
6211 static void add_data_member_location_attribute (dw_die_ref
, tree
);
6212 static bool add_const_value_attribute (dw_die_ref
, rtx
);
6213 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
6214 static void insert_double (double_int
, unsigned char *);
6215 static void insert_float (const_rtx
, unsigned char *);
6216 static rtx
rtl_for_decl_location (tree
);
6217 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
,
6218 enum dwarf_attribute
);
6219 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
6220 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
6221 static void add_name_attribute (dw_die_ref
, const char *);
6222 static void add_comp_dir_attribute (dw_die_ref
);
6223 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
6224 static void add_subscript_info (dw_die_ref
, tree
, bool);
6225 static void add_byte_size_attribute (dw_die_ref
, tree
);
6226 static void add_bit_offset_attribute (dw_die_ref
, tree
);
6227 static void add_bit_size_attribute (dw_die_ref
, tree
);
6228 static void add_prototyped_attribute (dw_die_ref
, tree
);
6229 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
6230 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
6231 static void add_src_coords_attributes (dw_die_ref
, tree
);
6232 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
6233 static void push_decl_scope (tree
);
6234 static void pop_decl_scope (void);
6235 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
6236 static inline int local_scope_p (dw_die_ref
);
6237 static inline int class_scope_p (dw_die_ref
);
6238 static inline int class_or_namespace_scope_p (dw_die_ref
);
6239 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
6240 static void add_calling_convention_attribute (dw_die_ref
, tree
);
6241 static const char *type_tag (const_tree
);
6242 static tree
member_declared_type (const_tree
);
6244 static const char *decl_start_label (tree
);
6246 static void gen_array_type_die (tree
, dw_die_ref
);
6247 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
6249 static void gen_entry_point_die (tree
, dw_die_ref
);
6251 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
6252 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
6253 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
6254 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
6255 static void gen_formal_types_die (tree
, dw_die_ref
);
6256 static void gen_subprogram_die (tree
, dw_die_ref
);
6257 static void gen_variable_die (tree
, tree
, dw_die_ref
);
6258 static void gen_const_die (tree
, dw_die_ref
);
6259 static void gen_label_die (tree
, dw_die_ref
);
6260 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
6261 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
6262 static void gen_field_die (tree
, dw_die_ref
);
6263 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
6264 static dw_die_ref
gen_compile_unit_die (const char *);
6265 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
6266 static void gen_member_die (tree
, dw_die_ref
);
6267 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
6268 enum debug_info_usage
);
6269 static void gen_subroutine_type_die (tree
, dw_die_ref
);
6270 static void gen_typedef_die (tree
, dw_die_ref
);
6271 static void gen_type_die (tree
, dw_die_ref
);
6272 static void gen_block_die (tree
, dw_die_ref
, int);
6273 static void decls_for_scope (tree
, dw_die_ref
, int);
6274 static int is_redundant_typedef (const_tree
);
6275 static bool is_naming_typedef_decl (const_tree
);
6276 static inline dw_die_ref
get_context_die (tree
);
6277 static void gen_namespace_die (tree
, dw_die_ref
);
6278 static void gen_decl_die (tree
, tree
, dw_die_ref
);
6279 static dw_die_ref
force_decl_die (tree
);
6280 static dw_die_ref
force_type_die (tree
);
6281 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
6282 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
6283 static struct dwarf_file_data
* lookup_filename (const char *);
6284 static void retry_incomplete_types (void);
6285 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
6286 static void gen_generic_params_dies (tree
);
6287 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
6288 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
6289 static void splice_child_die (dw_die_ref
, dw_die_ref
);
6290 static int file_info_cmp (const void *, const void *);
6291 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
6292 const char *, const char *);
6293 static void output_loc_list (dw_loc_list_ref
);
6294 static char *gen_internal_sym (const char *);
6296 static void prune_unmark_dies (dw_die_ref
);
6297 static void prune_unused_types_mark (dw_die_ref
, int);
6298 static void prune_unused_types_walk (dw_die_ref
);
6299 static void prune_unused_types_walk_attribs (dw_die_ref
);
6300 static void prune_unused_types_prune (dw_die_ref
);
6301 static void prune_unused_types (void);
6302 static int maybe_emit_file (struct dwarf_file_data
*fd
);
6303 static inline const char *AT_vms_delta1 (dw_attr_ref
);
6304 static inline const char *AT_vms_delta2 (dw_attr_ref
);
6305 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
6306 const char *, const char *);
6307 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
6308 static void gen_remaining_tmpl_value_param_die_attribute (void);
6310 /* Section names used to hold DWARF debugging information. */
6311 #ifndef DEBUG_INFO_SECTION
6312 #define DEBUG_INFO_SECTION ".debug_info"
6314 #ifndef DEBUG_ABBREV_SECTION
6315 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6317 #ifndef DEBUG_ARANGES_SECTION
6318 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6320 #ifndef DEBUG_MACINFO_SECTION
6321 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6323 #ifndef DEBUG_LINE_SECTION
6324 #define DEBUG_LINE_SECTION ".debug_line"
6326 #ifndef DEBUG_LOC_SECTION
6327 #define DEBUG_LOC_SECTION ".debug_loc"
6329 #ifndef DEBUG_PUBNAMES_SECTION
6330 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6332 #ifndef DEBUG_PUBTYPES_SECTION
6333 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6335 #ifndef DEBUG_DCALL_SECTION
6336 #define DEBUG_DCALL_SECTION ".debug_dcall"
6338 #ifndef DEBUG_VCALL_SECTION
6339 #define DEBUG_VCALL_SECTION ".debug_vcall"
6341 #ifndef DEBUG_STR_SECTION
6342 #define DEBUG_STR_SECTION ".debug_str"
6344 #ifndef DEBUG_RANGES_SECTION
6345 #define DEBUG_RANGES_SECTION ".debug_ranges"
6348 /* Standard ELF section names for compiled code and data. */
6349 #ifndef TEXT_SECTION_NAME
6350 #define TEXT_SECTION_NAME ".text"
6353 /* Section flags for .debug_str section. */
6354 #define DEBUG_STR_SECTION_FLAGS \
6355 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6356 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6359 /* Labels we insert at beginning sections we can reference instead of
6360 the section names themselves. */
6362 #ifndef TEXT_SECTION_LABEL
6363 #define TEXT_SECTION_LABEL "Ltext"
6365 #ifndef COLD_TEXT_SECTION_LABEL
6366 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6368 #ifndef DEBUG_LINE_SECTION_LABEL
6369 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6371 #ifndef DEBUG_INFO_SECTION_LABEL
6372 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6374 #ifndef DEBUG_ABBREV_SECTION_LABEL
6375 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6377 #ifndef DEBUG_LOC_SECTION_LABEL
6378 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6380 #ifndef DEBUG_RANGES_SECTION_LABEL
6381 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6383 #ifndef DEBUG_MACINFO_SECTION_LABEL
6384 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6387 /* Mangled name attribute to use. This used to be a vendor extension
6388 until DWARF 4 standardized it. */
6389 #define AT_linkage_name \
6390 (dwarf_version >= 4 ? DW_AT_linkage_name : DW_AT_MIPS_linkage_name)
6393 /* Definitions of defaults for formats and names of various special
6394 (artificial) labels which may be generated within this file (when the -g
6395 options is used and DWARF2_DEBUGGING_INFO is in effect.
6396 If necessary, these may be overridden from within the tm.h file, but
6397 typically, overriding these defaults is unnecessary. */
6399 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6400 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6401 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6402 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6403 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6404 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6405 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6406 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6407 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6408 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
6410 #ifndef TEXT_END_LABEL
6411 #define TEXT_END_LABEL "Letext"
6413 #ifndef COLD_END_LABEL
6414 #define COLD_END_LABEL "Letext_cold"
6416 #ifndef BLOCK_BEGIN_LABEL
6417 #define BLOCK_BEGIN_LABEL "LBB"
6419 #ifndef BLOCK_END_LABEL
6420 #define BLOCK_END_LABEL "LBE"
6422 #ifndef LINE_CODE_LABEL
6423 #define LINE_CODE_LABEL "LM"
6425 #ifndef SEPARATE_LINE_CODE_LABEL
6426 #define SEPARATE_LINE_CODE_LABEL "LSM"
6430 /* We allow a language front-end to designate a function that is to be
6431 called to "demangle" any name before it is put into a DIE. */
6433 static const char *(*demangle_name_func
) (const char *);
6436 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
6438 demangle_name_func
= func
;
6441 /* Test if rtl node points to a pseudo register. */
6444 is_pseudo_reg (const_rtx rtl
)
6446 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
6447 || (GET_CODE (rtl
) == SUBREG
6448 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
6451 /* Return a reference to a type, with its const and volatile qualifiers
6455 type_main_variant (tree type
)
6457 type
= TYPE_MAIN_VARIANT (type
);
6459 /* ??? There really should be only one main variant among any group of
6460 variants of a given type (and all of the MAIN_VARIANT values for all
6461 members of the group should point to that one type) but sometimes the C
6462 front-end messes this up for array types, so we work around that bug
6464 if (TREE_CODE (type
) == ARRAY_TYPE
)
6465 while (type
!= TYPE_MAIN_VARIANT (type
))
6466 type
= TYPE_MAIN_VARIANT (type
);
6471 /* Return nonzero if the given type node represents a tagged type. */
6474 is_tagged_type (const_tree type
)
6476 enum tree_code code
= TREE_CODE (type
);
6478 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
6479 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
6482 /* Convert a DIE tag into its string name. */
6485 dwarf_tag_name (unsigned int tag
)
6489 case DW_TAG_padding
:
6490 return "DW_TAG_padding";
6491 case DW_TAG_array_type
:
6492 return "DW_TAG_array_type";
6493 case DW_TAG_class_type
:
6494 return "DW_TAG_class_type";
6495 case DW_TAG_entry_point
:
6496 return "DW_TAG_entry_point";
6497 case DW_TAG_enumeration_type
:
6498 return "DW_TAG_enumeration_type";
6499 case DW_TAG_formal_parameter
:
6500 return "DW_TAG_formal_parameter";
6501 case DW_TAG_imported_declaration
:
6502 return "DW_TAG_imported_declaration";
6504 return "DW_TAG_label";
6505 case DW_TAG_lexical_block
:
6506 return "DW_TAG_lexical_block";
6508 return "DW_TAG_member";
6509 case DW_TAG_pointer_type
:
6510 return "DW_TAG_pointer_type";
6511 case DW_TAG_reference_type
:
6512 return "DW_TAG_reference_type";
6513 case DW_TAG_compile_unit
:
6514 return "DW_TAG_compile_unit";
6515 case DW_TAG_string_type
:
6516 return "DW_TAG_string_type";
6517 case DW_TAG_structure_type
:
6518 return "DW_TAG_structure_type";
6519 case DW_TAG_subroutine_type
:
6520 return "DW_TAG_subroutine_type";
6521 case DW_TAG_typedef
:
6522 return "DW_TAG_typedef";
6523 case DW_TAG_union_type
:
6524 return "DW_TAG_union_type";
6525 case DW_TAG_unspecified_parameters
:
6526 return "DW_TAG_unspecified_parameters";
6527 case DW_TAG_variant
:
6528 return "DW_TAG_variant";
6529 case DW_TAG_common_block
:
6530 return "DW_TAG_common_block";
6531 case DW_TAG_common_inclusion
:
6532 return "DW_TAG_common_inclusion";
6533 case DW_TAG_inheritance
:
6534 return "DW_TAG_inheritance";
6535 case DW_TAG_inlined_subroutine
:
6536 return "DW_TAG_inlined_subroutine";
6538 return "DW_TAG_module";
6539 case DW_TAG_ptr_to_member_type
:
6540 return "DW_TAG_ptr_to_member_type";
6541 case DW_TAG_set_type
:
6542 return "DW_TAG_set_type";
6543 case DW_TAG_subrange_type
:
6544 return "DW_TAG_subrange_type";
6545 case DW_TAG_with_stmt
:
6546 return "DW_TAG_with_stmt";
6547 case DW_TAG_access_declaration
:
6548 return "DW_TAG_access_declaration";
6549 case DW_TAG_base_type
:
6550 return "DW_TAG_base_type";
6551 case DW_TAG_catch_block
:
6552 return "DW_TAG_catch_block";
6553 case DW_TAG_const_type
:
6554 return "DW_TAG_const_type";
6555 case DW_TAG_constant
:
6556 return "DW_TAG_constant";
6557 case DW_TAG_enumerator
:
6558 return "DW_TAG_enumerator";
6559 case DW_TAG_file_type
:
6560 return "DW_TAG_file_type";
6562 return "DW_TAG_friend";
6563 case DW_TAG_namelist
:
6564 return "DW_TAG_namelist";
6565 case DW_TAG_namelist_item
:
6566 return "DW_TAG_namelist_item";
6567 case DW_TAG_packed_type
:
6568 return "DW_TAG_packed_type";
6569 case DW_TAG_subprogram
:
6570 return "DW_TAG_subprogram";
6571 case DW_TAG_template_type_param
:
6572 return "DW_TAG_template_type_param";
6573 case DW_TAG_template_value_param
:
6574 return "DW_TAG_template_value_param";
6575 case DW_TAG_thrown_type
:
6576 return "DW_TAG_thrown_type";
6577 case DW_TAG_try_block
:
6578 return "DW_TAG_try_block";
6579 case DW_TAG_variant_part
:
6580 return "DW_TAG_variant_part";
6581 case DW_TAG_variable
:
6582 return "DW_TAG_variable";
6583 case DW_TAG_volatile_type
:
6584 return "DW_TAG_volatile_type";
6585 case DW_TAG_dwarf_procedure
:
6586 return "DW_TAG_dwarf_procedure";
6587 case DW_TAG_restrict_type
:
6588 return "DW_TAG_restrict_type";
6589 case DW_TAG_interface_type
:
6590 return "DW_TAG_interface_type";
6591 case DW_TAG_namespace
:
6592 return "DW_TAG_namespace";
6593 case DW_TAG_imported_module
:
6594 return "DW_TAG_imported_module";
6595 case DW_TAG_unspecified_type
:
6596 return "DW_TAG_unspecified_type";
6597 case DW_TAG_partial_unit
:
6598 return "DW_TAG_partial_unit";
6599 case DW_TAG_imported_unit
:
6600 return "DW_TAG_imported_unit";
6601 case DW_TAG_condition
:
6602 return "DW_TAG_condition";
6603 case DW_TAG_shared_type
:
6604 return "DW_TAG_shared_type";
6605 case DW_TAG_type_unit
:
6606 return "DW_TAG_type_unit";
6607 case DW_TAG_rvalue_reference_type
:
6608 return "DW_TAG_rvalue_reference_type";
6609 case DW_TAG_template_alias
:
6610 return "DW_TAG_template_alias";
6611 case DW_TAG_GNU_template_parameter_pack
:
6612 return "DW_TAG_GNU_template_parameter_pack";
6613 case DW_TAG_GNU_formal_parameter_pack
:
6614 return "DW_TAG_GNU_formal_parameter_pack";
6615 case DW_TAG_MIPS_loop
:
6616 return "DW_TAG_MIPS_loop";
6617 case DW_TAG_format_label
:
6618 return "DW_TAG_format_label";
6619 case DW_TAG_function_template
:
6620 return "DW_TAG_function_template";
6621 case DW_TAG_class_template
:
6622 return "DW_TAG_class_template";
6623 case DW_TAG_GNU_BINCL
:
6624 return "DW_TAG_GNU_BINCL";
6625 case DW_TAG_GNU_EINCL
:
6626 return "DW_TAG_GNU_EINCL";
6627 case DW_TAG_GNU_template_template_param
:
6628 return "DW_TAG_GNU_template_template_param";
6630 return "DW_TAG_<unknown>";
6634 /* Convert a DWARF attribute code into its string name. */
6637 dwarf_attr_name (unsigned int attr
)
6642 return "DW_AT_sibling";
6643 case DW_AT_location
:
6644 return "DW_AT_location";
6646 return "DW_AT_name";
6647 case DW_AT_ordering
:
6648 return "DW_AT_ordering";
6649 case DW_AT_subscr_data
:
6650 return "DW_AT_subscr_data";
6651 case DW_AT_byte_size
:
6652 return "DW_AT_byte_size";
6653 case DW_AT_bit_offset
:
6654 return "DW_AT_bit_offset";
6655 case DW_AT_bit_size
:
6656 return "DW_AT_bit_size";
6657 case DW_AT_element_list
:
6658 return "DW_AT_element_list";
6659 case DW_AT_stmt_list
:
6660 return "DW_AT_stmt_list";
6662 return "DW_AT_low_pc";
6664 return "DW_AT_high_pc";
6665 case DW_AT_language
:
6666 return "DW_AT_language";
6668 return "DW_AT_member";
6670 return "DW_AT_discr";
6671 case DW_AT_discr_value
:
6672 return "DW_AT_discr_value";
6673 case DW_AT_visibility
:
6674 return "DW_AT_visibility";
6676 return "DW_AT_import";
6677 case DW_AT_string_length
:
6678 return "DW_AT_string_length";
6679 case DW_AT_common_reference
:
6680 return "DW_AT_common_reference";
6681 case DW_AT_comp_dir
:
6682 return "DW_AT_comp_dir";
6683 case DW_AT_const_value
:
6684 return "DW_AT_const_value";
6685 case DW_AT_containing_type
:
6686 return "DW_AT_containing_type";
6687 case DW_AT_default_value
:
6688 return "DW_AT_default_value";
6690 return "DW_AT_inline";
6691 case DW_AT_is_optional
:
6692 return "DW_AT_is_optional";
6693 case DW_AT_lower_bound
:
6694 return "DW_AT_lower_bound";
6695 case DW_AT_producer
:
6696 return "DW_AT_producer";
6697 case DW_AT_prototyped
:
6698 return "DW_AT_prototyped";
6699 case DW_AT_return_addr
:
6700 return "DW_AT_return_addr";
6701 case DW_AT_start_scope
:
6702 return "DW_AT_start_scope";
6703 case DW_AT_bit_stride
:
6704 return "DW_AT_bit_stride";
6705 case DW_AT_upper_bound
:
6706 return "DW_AT_upper_bound";
6707 case DW_AT_abstract_origin
:
6708 return "DW_AT_abstract_origin";
6709 case DW_AT_accessibility
:
6710 return "DW_AT_accessibility";
6711 case DW_AT_address_class
:
6712 return "DW_AT_address_class";
6713 case DW_AT_artificial
:
6714 return "DW_AT_artificial";
6715 case DW_AT_base_types
:
6716 return "DW_AT_base_types";
6717 case DW_AT_calling_convention
:
6718 return "DW_AT_calling_convention";
6720 return "DW_AT_count";
6721 case DW_AT_data_member_location
:
6722 return "DW_AT_data_member_location";
6723 case DW_AT_decl_column
:
6724 return "DW_AT_decl_column";
6725 case DW_AT_decl_file
:
6726 return "DW_AT_decl_file";
6727 case DW_AT_decl_line
:
6728 return "DW_AT_decl_line";
6729 case DW_AT_declaration
:
6730 return "DW_AT_declaration";
6731 case DW_AT_discr_list
:
6732 return "DW_AT_discr_list";
6733 case DW_AT_encoding
:
6734 return "DW_AT_encoding";
6735 case DW_AT_external
:
6736 return "DW_AT_external";
6737 case DW_AT_explicit
:
6738 return "DW_AT_explicit";
6739 case DW_AT_frame_base
:
6740 return "DW_AT_frame_base";
6742 return "DW_AT_friend";
6743 case DW_AT_identifier_case
:
6744 return "DW_AT_identifier_case";
6745 case DW_AT_macro_info
:
6746 return "DW_AT_macro_info";
6747 case DW_AT_namelist_items
:
6748 return "DW_AT_namelist_items";
6749 case DW_AT_priority
:
6750 return "DW_AT_priority";
6752 return "DW_AT_segment";
6753 case DW_AT_specification
:
6754 return "DW_AT_specification";
6755 case DW_AT_static_link
:
6756 return "DW_AT_static_link";
6758 return "DW_AT_type";
6759 case DW_AT_use_location
:
6760 return "DW_AT_use_location";
6761 case DW_AT_variable_parameter
:
6762 return "DW_AT_variable_parameter";
6763 case DW_AT_virtuality
:
6764 return "DW_AT_virtuality";
6765 case DW_AT_vtable_elem_location
:
6766 return "DW_AT_vtable_elem_location";
6768 case DW_AT_allocated
:
6769 return "DW_AT_allocated";
6770 case DW_AT_associated
:
6771 return "DW_AT_associated";
6772 case DW_AT_data_location
:
6773 return "DW_AT_data_location";
6774 case DW_AT_byte_stride
:
6775 return "DW_AT_byte_stride";
6776 case DW_AT_entry_pc
:
6777 return "DW_AT_entry_pc";
6778 case DW_AT_use_UTF8
:
6779 return "DW_AT_use_UTF8";
6780 case DW_AT_extension
:
6781 return "DW_AT_extension";
6783 return "DW_AT_ranges";
6784 case DW_AT_trampoline
:
6785 return "DW_AT_trampoline";
6786 case DW_AT_call_column
:
6787 return "DW_AT_call_column";
6788 case DW_AT_call_file
:
6789 return "DW_AT_call_file";
6790 case DW_AT_call_line
:
6791 return "DW_AT_call_line";
6793 case DW_AT_signature
:
6794 return "DW_AT_signature";
6795 case DW_AT_main_subprogram
:
6796 return "DW_AT_main_subprogram";
6797 case DW_AT_data_bit_offset
:
6798 return "DW_AT_data_bit_offset";
6799 case DW_AT_const_expr
:
6800 return "DW_AT_const_expr";
6801 case DW_AT_enum_class
:
6802 return "DW_AT_enum_class";
6803 case DW_AT_linkage_name
:
6804 return "DW_AT_linkage_name";
6806 case DW_AT_MIPS_fde
:
6807 return "DW_AT_MIPS_fde";
6808 case DW_AT_MIPS_loop_begin
:
6809 return "DW_AT_MIPS_loop_begin";
6810 case DW_AT_MIPS_tail_loop_begin
:
6811 return "DW_AT_MIPS_tail_loop_begin";
6812 case DW_AT_MIPS_epilog_begin
:
6813 return "DW_AT_MIPS_epilog_begin";
6814 #if VMS_DEBUGGING_INFO
6815 case DW_AT_HP_prologue
:
6816 return "DW_AT_HP_prologue";
6818 case DW_AT_MIPS_loop_unroll_factor
:
6819 return "DW_AT_MIPS_loop_unroll_factor";
6821 case DW_AT_MIPS_software_pipeline_depth
:
6822 return "DW_AT_MIPS_software_pipeline_depth";
6823 case DW_AT_MIPS_linkage_name
:
6824 return "DW_AT_MIPS_linkage_name";
6825 #if VMS_DEBUGGING_INFO
6826 case DW_AT_HP_epilogue
:
6827 return "DW_AT_HP_epilogue";
6829 case DW_AT_MIPS_stride
:
6830 return "DW_AT_MIPS_stride";
6832 case DW_AT_MIPS_abstract_name
:
6833 return "DW_AT_MIPS_abstract_name";
6834 case DW_AT_MIPS_clone_origin
:
6835 return "DW_AT_MIPS_clone_origin";
6836 case DW_AT_MIPS_has_inlines
:
6837 return "DW_AT_MIPS_has_inlines";
6839 case DW_AT_sf_names
:
6840 return "DW_AT_sf_names";
6841 case DW_AT_src_info
:
6842 return "DW_AT_src_info";
6843 case DW_AT_mac_info
:
6844 return "DW_AT_mac_info";
6845 case DW_AT_src_coords
:
6846 return "DW_AT_src_coords";
6847 case DW_AT_body_begin
:
6848 return "DW_AT_body_begin";
6849 case DW_AT_body_end
:
6850 return "DW_AT_body_end";
6851 case DW_AT_GNU_vector
:
6852 return "DW_AT_GNU_vector";
6853 case DW_AT_GNU_guarded_by
:
6854 return "DW_AT_GNU_guarded_by";
6855 case DW_AT_GNU_pt_guarded_by
:
6856 return "DW_AT_GNU_pt_guarded_by";
6857 case DW_AT_GNU_guarded
:
6858 return "DW_AT_GNU_guarded";
6859 case DW_AT_GNU_pt_guarded
:
6860 return "DW_AT_GNU_pt_guarded";
6861 case DW_AT_GNU_locks_excluded
:
6862 return "DW_AT_GNU_locks_excluded";
6863 case DW_AT_GNU_exclusive_locks_required
:
6864 return "DW_AT_GNU_exclusive_locks_required";
6865 case DW_AT_GNU_shared_locks_required
:
6866 return "DW_AT_GNU_shared_locks_required";
6867 case DW_AT_GNU_odr_signature
:
6868 return "DW_AT_GNU_odr_signature";
6869 case DW_AT_GNU_template_name
:
6870 return "DW_AT_GNU_template_name";
6872 case DW_AT_VMS_rtnbeg_pd_address
:
6873 return "DW_AT_VMS_rtnbeg_pd_address";
6876 return "DW_AT_<unknown>";
6880 /* Convert a DWARF value form code into its string name. */
6883 dwarf_form_name (unsigned int form
)
6888 return "DW_FORM_addr";
6889 case DW_FORM_block2
:
6890 return "DW_FORM_block2";
6891 case DW_FORM_block4
:
6892 return "DW_FORM_block4";
6894 return "DW_FORM_data2";
6896 return "DW_FORM_data4";
6898 return "DW_FORM_data8";
6899 case DW_FORM_string
:
6900 return "DW_FORM_string";
6902 return "DW_FORM_block";
6903 case DW_FORM_block1
:
6904 return "DW_FORM_block1";
6906 return "DW_FORM_data1";
6908 return "DW_FORM_flag";
6910 return "DW_FORM_sdata";
6912 return "DW_FORM_strp";
6914 return "DW_FORM_udata";
6915 case DW_FORM_ref_addr
:
6916 return "DW_FORM_ref_addr";
6918 return "DW_FORM_ref1";
6920 return "DW_FORM_ref2";
6922 return "DW_FORM_ref4";
6924 return "DW_FORM_ref8";
6925 case DW_FORM_ref_udata
:
6926 return "DW_FORM_ref_udata";
6927 case DW_FORM_indirect
:
6928 return "DW_FORM_indirect";
6929 case DW_FORM_sec_offset
:
6930 return "DW_FORM_sec_offset";
6931 case DW_FORM_exprloc
:
6932 return "DW_FORM_exprloc";
6933 case DW_FORM_flag_present
:
6934 return "DW_FORM_flag_present";
6935 case DW_FORM_ref_sig8
:
6936 return "DW_FORM_ref_sig8";
6938 return "DW_FORM_<unknown>";
6942 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
6943 instance of an inlined instance of a decl which is local to an inline
6944 function, so we have to trace all of the way back through the origin chain
6945 to find out what sort of node actually served as the original seed for the
6949 decl_ultimate_origin (const_tree decl
)
6951 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
6954 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
6955 nodes in the function to point to themselves; ignore that if
6956 we're trying to output the abstract instance of this function. */
6957 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
6960 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
6961 most distant ancestor, this should never happen. */
6962 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
6964 return DECL_ABSTRACT_ORIGIN (decl
);
6967 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
6968 of a virtual function may refer to a base class, so we check the 'this'
6972 decl_class_context (tree decl
)
6974 tree context
= NULL_TREE
;
6976 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
6977 context
= DECL_CONTEXT (decl
);
6979 context
= TYPE_MAIN_VARIANT
6980 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
6982 if (context
&& !TYPE_P (context
))
6983 context
= NULL_TREE
;
6988 /* Add an attribute/value pair to a DIE. */
6991 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
6993 /* Maybe this should be an assert? */
6997 if (die
->die_attr
== NULL
)
6998 die
->die_attr
= VEC_alloc (dw_attr_node
, gc
, 1);
6999 VEC_safe_push (dw_attr_node
, gc
, die
->die_attr
, attr
);
7002 static inline enum dw_val_class
7003 AT_class (dw_attr_ref a
)
7005 return a
->dw_attr_val
.val_class
;
7008 /* Add a flag value attribute to a DIE. */
7011 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
7015 attr
.dw_attr
= attr_kind
;
7016 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
7017 attr
.dw_attr_val
.v
.val_flag
= flag
;
7018 add_dwarf_attr (die
, &attr
);
7021 static inline unsigned
7022 AT_flag (dw_attr_ref a
)
7024 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
7025 return a
->dw_attr_val
.v
.val_flag
;
7028 /* Add a signed integer attribute value to a DIE. */
7031 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
7035 attr
.dw_attr
= attr_kind
;
7036 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
7037 attr
.dw_attr_val
.v
.val_int
= int_val
;
7038 add_dwarf_attr (die
, &attr
);
7041 static inline HOST_WIDE_INT
7042 AT_int (dw_attr_ref a
)
7044 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
7045 return a
->dw_attr_val
.v
.val_int
;
7048 /* Add an unsigned integer attribute value to a DIE. */
7051 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7052 unsigned HOST_WIDE_INT unsigned_val
)
7056 attr
.dw_attr
= attr_kind
;
7057 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
7058 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
7059 add_dwarf_attr (die
, &attr
);
7062 static inline unsigned HOST_WIDE_INT
7063 AT_unsigned (dw_attr_ref a
)
7065 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
7066 return a
->dw_attr_val
.v
.val_unsigned
;
7069 /* Add an unsigned double integer attribute value to a DIE. */
7072 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7073 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
7077 attr
.dw_attr
= attr_kind
;
7078 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
7079 attr
.dw_attr_val
.v
.val_double
.high
= high
;
7080 attr
.dw_attr_val
.v
.val_double
.low
= low
;
7081 add_dwarf_attr (die
, &attr
);
7084 /* Add a floating point attribute value to a DIE and return it. */
7087 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7088 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
7092 attr
.dw_attr
= attr_kind
;
7093 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
7094 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
7095 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
7096 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
7097 add_dwarf_attr (die
, &attr
);
7100 /* Add an 8-byte data attribute value to a DIE. */
7103 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7104 unsigned char data8
[8])
7108 attr
.dw_attr
= attr_kind
;
7109 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
7110 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
7111 add_dwarf_attr (die
, &attr
);
7114 /* Hash and equality functions for debug_str_hash. */
7117 debug_str_do_hash (const void *x
)
7119 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
7123 debug_str_eq (const void *x1
, const void *x2
)
7125 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
7126 (const char *)x2
) == 0;
7129 /* Add STR to the indirect string hash table. */
7131 static struct indirect_string_node
*
7132 find_AT_string (const char *str
)
7134 struct indirect_string_node
*node
;
7137 if (! debug_str_hash
)
7138 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
7139 debug_str_eq
, NULL
);
7141 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
7142 htab_hash_string (str
), INSERT
);
7145 node
= ggc_alloc_cleared_indirect_string_node ();
7146 node
->str
= ggc_strdup (str
);
7150 node
= (struct indirect_string_node
*) *slot
;
7156 /* Add a string attribute value to a DIE. */
7159 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
7162 struct indirect_string_node
*node
;
7164 node
= find_AT_string (str
);
7166 attr
.dw_attr
= attr_kind
;
7167 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
7168 attr
.dw_attr_val
.v
.val_str
= node
;
7169 add_dwarf_attr (die
, &attr
);
7172 /* Create a label for an indirect string node, ensuring it is going to
7173 be output, unless its reference count goes down to zero. */
7176 gen_label_for_indirect_string (struct indirect_string_node
*node
)
7183 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
7184 ++dw2_string_counter
;
7185 node
->label
= xstrdup (label
);
7188 /* Create a SYMBOL_REF rtx whose value is the initial address of a
7189 debug string STR. */
7192 get_debug_string_label (const char *str
)
7194 struct indirect_string_node
*node
= find_AT_string (str
);
7196 debug_str_hash_forced
= true;
7198 gen_label_for_indirect_string (node
);
7200 return gen_rtx_SYMBOL_REF (Pmode
, node
->label
);
7203 static inline const char *
7204 AT_string (dw_attr_ref a
)
7206 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
7207 return a
->dw_attr_val
.v
.val_str
->str
;
7210 /* Find out whether a string should be output inline in DIE
7211 or out-of-line in .debug_str section. */
7213 static enum dwarf_form
7214 AT_string_form (dw_attr_ref a
)
7216 struct indirect_string_node
*node
;
7219 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
7221 node
= a
->dw_attr_val
.v
.val_str
;
7225 len
= strlen (node
->str
) + 1;
7227 /* If the string is shorter or equal to the size of the reference, it is
7228 always better to put it inline. */
7229 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
7230 return node
->form
= DW_FORM_string
;
7232 /* If we cannot expect the linker to merge strings in .debug_str
7233 section, only put it into .debug_str if it is worth even in this
7235 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
7236 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
7237 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
7238 return node
->form
= DW_FORM_string
;
7240 gen_label_for_indirect_string (node
);
7242 return node
->form
= DW_FORM_strp
;
7245 /* Add a DIE reference attribute value to a DIE. */
7248 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
7252 attr
.dw_attr
= attr_kind
;
7253 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
7254 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
7255 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
7256 add_dwarf_attr (die
, &attr
);
7259 /* Add an AT_specification attribute to a DIE, and also make the back
7260 pointer from the specification to the definition. */
7263 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
7265 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
7266 gcc_assert (!targ_die
->die_definition
);
7267 targ_die
->die_definition
= die
;
7270 static inline dw_die_ref
7271 AT_ref (dw_attr_ref a
)
7273 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
7274 return a
->dw_attr_val
.v
.val_die_ref
.die
;
7278 AT_ref_external (dw_attr_ref a
)
7280 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
7281 return a
->dw_attr_val
.v
.val_die_ref
.external
;
7287 set_AT_ref_external (dw_attr_ref a
, int i
)
7289 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
7290 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
7293 /* Add an FDE reference attribute value to a DIE. */
7296 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
7300 attr
.dw_attr
= attr_kind
;
7301 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
7302 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
7303 add_dwarf_attr (die
, &attr
);
7306 /* Add a location description attribute value to a DIE. */
7309 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
7313 attr
.dw_attr
= attr_kind
;
7314 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
7315 attr
.dw_attr_val
.v
.val_loc
= loc
;
7316 add_dwarf_attr (die
, &attr
);
7319 static inline dw_loc_descr_ref
7320 AT_loc (dw_attr_ref a
)
7322 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
7323 return a
->dw_attr_val
.v
.val_loc
;
7327 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
7331 attr
.dw_attr
= attr_kind
;
7332 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
7333 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
7334 add_dwarf_attr (die
, &attr
);
7335 have_location_lists
= true;
7338 static inline dw_loc_list_ref
7339 AT_loc_list (dw_attr_ref a
)
7341 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
7342 return a
->dw_attr_val
.v
.val_loc_list
;
7345 static inline dw_loc_list_ref
*
7346 AT_loc_list_ptr (dw_attr_ref a
)
7348 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
7349 return &a
->dw_attr_val
.v
.val_loc_list
;
7352 /* Add an address constant attribute value to a DIE. */
7355 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
7359 attr
.dw_attr
= attr_kind
;
7360 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
7361 attr
.dw_attr_val
.v
.val_addr
= addr
;
7362 add_dwarf_attr (die
, &attr
);
7365 /* Get the RTX from to an address DIE attribute. */
7368 AT_addr (dw_attr_ref a
)
7370 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
7371 return a
->dw_attr_val
.v
.val_addr
;
7374 /* Add a file attribute value to a DIE. */
7377 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7378 struct dwarf_file_data
*fd
)
7382 attr
.dw_attr
= attr_kind
;
7383 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
7384 attr
.dw_attr_val
.v
.val_file
= fd
;
7385 add_dwarf_attr (die
, &attr
);
7388 /* Get the dwarf_file_data from a file DIE attribute. */
7390 static inline struct dwarf_file_data
*
7391 AT_file (dw_attr_ref a
)
7393 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
7394 return a
->dw_attr_val
.v
.val_file
;
7397 /* Add a vms delta attribute value to a DIE. */
7400 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7401 const char *lbl1
, const char *lbl2
)
7405 attr
.dw_attr
= attr_kind
;
7406 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
7407 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
7408 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
7409 add_dwarf_attr (die
, &attr
);
7412 /* Add a label identifier attribute value to a DIE. */
7415 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
7419 attr
.dw_attr
= attr_kind
;
7420 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
7421 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
7422 add_dwarf_attr (die
, &attr
);
7425 /* Add a section offset attribute value to a DIE, an offset into the
7426 debug_line section. */
7429 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7434 attr
.dw_attr
= attr_kind
;
7435 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
7436 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
7437 add_dwarf_attr (die
, &attr
);
7440 /* Add a section offset attribute value to a DIE, an offset into the
7441 debug_macinfo section. */
7444 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7449 attr
.dw_attr
= attr_kind
;
7450 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
7451 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
7452 add_dwarf_attr (die
, &attr
);
7455 /* Add an offset attribute value to a DIE. */
7458 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7459 unsigned HOST_WIDE_INT offset
)
7463 attr
.dw_attr
= attr_kind
;
7464 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
7465 attr
.dw_attr_val
.v
.val_offset
= offset
;
7466 add_dwarf_attr (die
, &attr
);
7469 /* Add an range_list attribute value to a DIE. */
7472 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
7473 long unsigned int offset
)
7477 attr
.dw_attr
= attr_kind
;
7478 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
7479 attr
.dw_attr_val
.v
.val_offset
= offset
;
7480 add_dwarf_attr (die
, &attr
);
7483 /* Return the start label of a delta attribute. */
7485 static inline const char *
7486 AT_vms_delta1 (dw_attr_ref a
)
7488 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
7489 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
7492 /* Return the end label of a delta attribute. */
7494 static inline const char *
7495 AT_vms_delta2 (dw_attr_ref a
)
7497 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
7498 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
7501 static inline const char *
7502 AT_lbl (dw_attr_ref a
)
7504 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
7505 || AT_class (a
) == dw_val_class_lineptr
7506 || AT_class (a
) == dw_val_class_macptr
));
7507 return a
->dw_attr_val
.v
.val_lbl_id
;
7510 /* Get the attribute of type attr_kind. */
7513 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7517 dw_die_ref spec
= NULL
;
7522 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7523 if (a
->dw_attr
== attr_kind
)
7525 else if (a
->dw_attr
== DW_AT_specification
7526 || a
->dw_attr
== DW_AT_abstract_origin
)
7530 return get_AT (spec
, attr_kind
);
7535 /* Return the "low pc" attribute value, typically associated with a subprogram
7536 DIE. Return null if the "low pc" attribute is either not present, or if it
7537 cannot be represented as an assembler label identifier. */
7539 static inline const char *
7540 get_AT_low_pc (dw_die_ref die
)
7542 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
7544 return a
? AT_lbl (a
) : NULL
;
7547 /* Return the "high pc" attribute value, typically associated with a subprogram
7548 DIE. Return null if the "high pc" attribute is either not present, or if it
7549 cannot be represented as an assembler label identifier. */
7551 static inline const char *
7552 get_AT_hi_pc (dw_die_ref die
)
7554 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
7556 return a
? AT_lbl (a
) : NULL
;
7559 /* Return the value of the string attribute designated by ATTR_KIND, or
7560 NULL if it is not present. */
7562 static inline const char *
7563 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7565 dw_attr_ref a
= get_AT (die
, attr_kind
);
7567 return a
? AT_string (a
) : NULL
;
7570 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
7571 if it is not present. */
7574 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7576 dw_attr_ref a
= get_AT (die
, attr_kind
);
7578 return a
? AT_flag (a
) : 0;
7581 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
7582 if it is not present. */
7584 static inline unsigned
7585 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7587 dw_attr_ref a
= get_AT (die
, attr_kind
);
7589 return a
? AT_unsigned (a
) : 0;
7592 static inline dw_die_ref
7593 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7595 dw_attr_ref a
= get_AT (die
, attr_kind
);
7597 return a
? AT_ref (a
) : NULL
;
7600 static inline struct dwarf_file_data
*
7601 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7603 dw_attr_ref a
= get_AT (die
, attr_kind
);
7605 return a
? AT_file (a
) : NULL
;
7608 /* Return TRUE if the language is C++. */
7613 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
7615 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
7618 /* Return TRUE if the language is Fortran. */
7623 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
7625 return (lang
== DW_LANG_Fortran77
7626 || lang
== DW_LANG_Fortran90
7627 || lang
== DW_LANG_Fortran95
);
7630 /* Return TRUE if the language is Ada. */
7635 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
7637 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
7640 /* Remove the specified attribute if present. */
7643 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
7651 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7652 if (a
->dw_attr
== attr_kind
)
7654 if (AT_class (a
) == dw_val_class_str
)
7655 if (a
->dw_attr_val
.v
.val_str
->refcount
)
7656 a
->dw_attr_val
.v
.val_str
->refcount
--;
7658 /* VEC_ordered_remove should help reduce the number of abbrevs
7660 VEC_ordered_remove (dw_attr_node
, die
->die_attr
, ix
);
7665 /* Remove CHILD from its parent. PREV must have the property that
7666 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
7669 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
7671 gcc_assert (child
->die_parent
== prev
->die_parent
);
7672 gcc_assert (prev
->die_sib
== child
);
7675 gcc_assert (child
->die_parent
->die_child
== child
);
7679 prev
->die_sib
= child
->die_sib
;
7680 if (child
->die_parent
->die_child
== child
)
7681 child
->die_parent
->die_child
= prev
;
7684 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
7685 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
7688 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
7690 dw_die_ref parent
= old_child
->die_parent
;
7692 gcc_assert (parent
== prev
->die_parent
);
7693 gcc_assert (prev
->die_sib
== old_child
);
7695 new_child
->die_parent
= parent
;
7696 if (prev
== old_child
)
7698 gcc_assert (parent
->die_child
== old_child
);
7699 new_child
->die_sib
= new_child
;
7703 prev
->die_sib
= new_child
;
7704 new_child
->die_sib
= old_child
->die_sib
;
7706 if (old_child
->die_parent
->die_child
== old_child
)
7707 old_child
->die_parent
->die_child
= new_child
;
7710 /* Move all children from OLD_PARENT to NEW_PARENT. */
7713 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
7716 new_parent
->die_child
= old_parent
->die_child
;
7717 old_parent
->die_child
= NULL
;
7718 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
7721 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
7725 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
7731 dw_die_ref prev
= c
;
7733 while (c
->die_tag
== tag
)
7735 remove_child_with_prev (c
, prev
);
7736 /* Might have removed every child. */
7737 if (c
== c
->die_sib
)
7741 } while (c
!= die
->die_child
);
7744 /* Add a CHILD_DIE as the last child of DIE. */
7747 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
7749 /* FIXME this should probably be an assert. */
7750 if (! die
|| ! child_die
)
7752 gcc_assert (die
!= child_die
);
7754 child_die
->die_parent
= die
;
7757 child_die
->die_sib
= die
->die_child
->die_sib
;
7758 die
->die_child
->die_sib
= child_die
;
7761 child_die
->die_sib
= child_die
;
7762 die
->die_child
= child_die
;
7765 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
7766 is the specification, to the end of PARENT's list of children.
7767 This is done by removing and re-adding it. */
7770 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
7774 /* We want the declaration DIE from inside the class, not the
7775 specification DIE at toplevel. */
7776 if (child
->die_parent
!= parent
)
7778 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
7784 gcc_assert (child
->die_parent
== parent
7785 || (child
->die_parent
7786 == get_AT_ref (parent
, DW_AT_specification
)));
7788 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
7789 if (p
->die_sib
== child
)
7791 remove_child_with_prev (child
, p
);
7795 add_child_die (parent
, child
);
7798 /* Return a pointer to a newly created DIE node. */
7800 static inline dw_die_ref
7801 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
7803 dw_die_ref die
= ggc_alloc_cleared_die_node ();
7805 die
->die_tag
= tag_value
;
7807 if (parent_die
!= NULL
)
7808 add_child_die (parent_die
, die
);
7811 limbo_die_node
*limbo_node
;
7813 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
7814 limbo_node
->die
= die
;
7815 limbo_node
->created_for
= t
;
7816 limbo_node
->next
= limbo_die_list
;
7817 limbo_die_list
= limbo_node
;
7823 /* Return the DIE associated with the given type specifier. */
7825 static inline dw_die_ref
7826 lookup_type_die (tree type
)
7828 return TYPE_SYMTAB_DIE (type
);
7831 /* Equate a DIE to a given type specifier. */
7834 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
7836 TYPE_SYMTAB_DIE (type
) = type_die
;
7839 /* Returns a hash value for X (which really is a die_struct). */
7842 decl_die_table_hash (const void *x
)
7844 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
7847 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
7850 decl_die_table_eq (const void *x
, const void *y
)
7852 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
7855 /* Return the DIE associated with a given declaration. */
7857 static inline dw_die_ref
7858 lookup_decl_die (tree decl
)
7860 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
7863 /* Returns a hash value for X (which really is a var_loc_list). */
7866 decl_loc_table_hash (const void *x
)
7868 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
7871 /* Return nonzero if decl_id of var_loc_list X is the same as
7875 decl_loc_table_eq (const void *x
, const void *y
)
7877 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
7880 /* Return the var_loc list associated with a given declaration. */
7882 static inline var_loc_list
*
7883 lookup_decl_loc (const_tree decl
)
7885 if (!decl_loc_table
)
7887 return (var_loc_list
*)
7888 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
7891 /* Equate a DIE to a particular declaration. */
7894 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
7896 unsigned int decl_id
= DECL_UID (decl
);
7899 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
7901 decl_die
->decl_id
= decl_id
;
7904 /* Return how many bits covers PIECE EXPR_LIST. */
7907 decl_piece_bitsize (rtx piece
)
7909 int ret
= (int) GET_MODE (piece
);
7912 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
7913 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
7914 return INTVAL (XEXP (XEXP (piece
, 0), 0));
7917 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
7920 decl_piece_varloc_ptr (rtx piece
)
7922 if ((int) GET_MODE (piece
))
7923 return &XEXP (piece
, 0);
7925 return &XEXP (XEXP (piece
, 0), 1);
7928 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
7929 Next is the chain of following piece nodes. */
7932 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
7934 if (bitsize
<= (int) MAX_MACHINE_MODE
)
7935 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
7937 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
7942 /* Return rtx that should be stored into loc field for
7943 LOC_NOTE and BITPOS/BITSIZE. */
7946 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
7947 HOST_WIDE_INT bitsize
)
7951 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
7953 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
7958 /* This function either modifies location piece list *DEST in
7959 place (if SRC and INNER is NULL), or copies location piece list
7960 *SRC to *DEST while modifying it. Location BITPOS is modified
7961 to contain LOC_NOTE, any pieces overlapping it are removed resp.
7962 not copied and if needed some padding around it is added.
7963 When modifying in place, DEST should point to EXPR_LIST where
7964 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
7965 to the start of the whole list and INNER points to the EXPR_LIST
7966 where earlier pieces cover PIECE_BITPOS bits. */
7969 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
7970 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
7971 HOST_WIDE_INT bitsize
, rtx loc_note
)
7974 bool copy
= inner
!= NULL
;
7978 /* First copy all nodes preceeding the current bitpos. */
7979 while (src
!= inner
)
7981 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
7982 decl_piece_bitsize (*src
), NULL_RTX
);
7983 dest
= &XEXP (*dest
, 1);
7984 src
= &XEXP (*src
, 1);
7987 /* Add padding if needed. */
7988 if (bitpos
!= piece_bitpos
)
7990 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
7991 copy
? NULL_RTX
: *dest
);
7992 dest
= &XEXP (*dest
, 1);
7994 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
7997 /* A piece with correct bitpos and bitsize already exist,
7998 just update the location for it and return. */
7999 *decl_piece_varloc_ptr (*dest
) = loc_note
;
8002 /* Add the piece that changed. */
8003 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
8004 dest
= &XEXP (*dest
, 1);
8005 /* Skip over pieces that overlap it. */
8006 diff
= bitpos
- piece_bitpos
+ bitsize
;
8009 while (diff
> 0 && *src
)
8012 diff
-= decl_piece_bitsize (piece
);
8014 src
= &XEXP (piece
, 1);
8017 *src
= XEXP (piece
, 1);
8018 free_EXPR_LIST_node (piece
);
8021 /* Add padding if needed. */
8022 if (diff
< 0 && *src
)
8026 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
8027 dest
= &XEXP (*dest
, 1);
8031 /* Finally copy all nodes following it. */
8034 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
8035 decl_piece_bitsize (*src
), NULL_RTX
);
8036 dest
= &XEXP (*dest
, 1);
8037 src
= &XEXP (*src
, 1);
8041 /* Add a variable location node to the linked list for DECL. */
8043 static struct var_loc_node
*
8044 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
8046 unsigned int decl_id
;
8049 struct var_loc_node
*loc
= NULL
;
8050 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
8052 if (DECL_DEBUG_EXPR_IS_FROM (decl
))
8054 tree realdecl
= DECL_DEBUG_EXPR (decl
);
8055 if (realdecl
&& handled_component_p (realdecl
))
8057 HOST_WIDE_INT maxsize
;
8060 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
8061 if (!DECL_P (innerdecl
)
8062 || DECL_IGNORED_P (innerdecl
)
8063 || TREE_STATIC (innerdecl
)
8065 || bitpos
+ bitsize
> 256
8066 || bitsize
!= maxsize
)
8072 decl_id
= DECL_UID (decl
);
8073 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
8076 temp
= ggc_alloc_cleared_var_loc_list ();
8077 temp
->decl_id
= decl_id
;
8081 temp
= (var_loc_list
*) *slot
;
8085 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
8086 rtx
*piece_loc
= NULL
, last_loc_note
;
8087 int piece_bitpos
= 0;
8091 gcc_assert (last
->next
== NULL
);
8093 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
8095 piece_loc
= &last
->loc
;
8098 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
8099 if (piece_bitpos
+ cur_bitsize
> bitpos
)
8101 piece_bitpos
+= cur_bitsize
;
8102 piece_loc
= &XEXP (*piece_loc
, 1);
8106 /* TEMP->LAST here is either pointer to the last but one or
8107 last element in the chained list, LAST is pointer to the
8109 if (label
&& strcmp (last
->label
, label
) == 0)
8111 /* For SRA optimized variables if there weren't any real
8112 insns since last note, just modify the last node. */
8113 if (piece_loc
!= NULL
)
8115 adjust_piece_list (piece_loc
, NULL
, NULL
,
8116 bitpos
, piece_bitpos
, bitsize
, loc_note
);
8119 /* If the last note doesn't cover any instructions, remove it. */
8120 if (temp
->last
!= last
)
8122 temp
->last
->next
= NULL
;
8125 gcc_assert (strcmp (last
->label
, label
) != 0);
8129 gcc_assert (temp
->first
== temp
->last
);
8130 memset (temp
->last
, '\0', sizeof (*temp
->last
));
8131 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
8135 if (bitsize
== -1 && NOTE_P (last
->loc
))
8136 last_loc_note
= last
->loc
;
8137 else if (piece_loc
!= NULL
8138 && *piece_loc
!= NULL_RTX
8139 && piece_bitpos
== bitpos
8140 && decl_piece_bitsize (*piece_loc
) == bitsize
)
8141 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
8143 last_loc_note
= NULL_RTX
;
8144 /* If the current location is the same as the end of the list,
8145 and either both or neither of the locations is uninitialized,
8146 we have nothing to do. */
8147 if (last_loc_note
== NULL_RTX
8148 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
8149 NOTE_VAR_LOCATION_LOC (loc_note
)))
8150 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
8151 != NOTE_VAR_LOCATION_STATUS (loc_note
))
8152 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
8153 == VAR_INIT_STATUS_UNINITIALIZED
)
8154 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
8155 == VAR_INIT_STATUS_UNINITIALIZED
))))
8157 /* Add LOC to the end of list and update LAST. If the last
8158 element of the list has been removed above, reuse its
8159 memory for the new node, otherwise allocate a new one. */
8163 memset (loc
, '\0', sizeof (*loc
));
8166 loc
= ggc_alloc_cleared_var_loc_node ();
8167 if (bitsize
== -1 || piece_loc
== NULL
)
8168 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
8170 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
8171 bitpos
, piece_bitpos
, bitsize
, loc_note
);
8173 /* Ensure TEMP->LAST will point either to the new last but one
8174 element of the chain, or to the last element in it. */
8175 if (last
!= temp
->last
)
8183 loc
= ggc_alloc_cleared_var_loc_node ();
8186 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
8191 /* Keep track of the number of spaces used to indent the
8192 output of the debugging routines that print the structure of
8193 the DIE internal representation. */
8194 static int print_indent
;
8196 /* Indent the line the number of spaces given by print_indent. */
8199 print_spaces (FILE *outfile
)
8201 fprintf (outfile
, "%*s", print_indent
, "");
8204 /* Print a type signature in hex. */
8207 print_signature (FILE *outfile
, char *sig
)
8211 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8212 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
8215 /* Print the information associated with a given DIE, and its children.
8216 This routine is a debugging aid only. */
8219 print_die (dw_die_ref die
, FILE *outfile
)
8225 print_spaces (outfile
);
8226 fprintf (outfile
, "DIE %4ld: %s\n",
8227 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
8228 print_spaces (outfile
);
8229 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
8230 fprintf (outfile
, " offset: %ld\n", die
->die_offset
);
8231 if (dwarf_version
>= 4 && die
->die_id
.die_type_node
)
8233 print_spaces (outfile
);
8234 fprintf (outfile
, " signature: ");
8235 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
8236 fprintf (outfile
, "\n");
8239 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
8241 print_spaces (outfile
);
8242 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
8244 switch (AT_class (a
))
8246 case dw_val_class_addr
:
8247 fprintf (outfile
, "address");
8249 case dw_val_class_offset
:
8250 fprintf (outfile
, "offset");
8252 case dw_val_class_loc
:
8253 fprintf (outfile
, "location descriptor");
8255 case dw_val_class_loc_list
:
8256 fprintf (outfile
, "location list -> label:%s",
8257 AT_loc_list (a
)->ll_symbol
);
8259 case dw_val_class_range_list
:
8260 fprintf (outfile
, "range list");
8262 case dw_val_class_const
:
8263 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
8265 case dw_val_class_unsigned_const
:
8266 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
8268 case dw_val_class_const_double
:
8269 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
8270 HOST_WIDE_INT_PRINT_UNSIGNED
")",
8271 a
->dw_attr_val
.v
.val_double
.high
,
8272 a
->dw_attr_val
.v
.val_double
.low
);
8274 case dw_val_class_vec
:
8275 fprintf (outfile
, "floating-point or vector constant");
8277 case dw_val_class_flag
:
8278 fprintf (outfile
, "%u", AT_flag (a
));
8280 case dw_val_class_die_ref
:
8281 if (AT_ref (a
) != NULL
)
8283 if (dwarf_version
>= 4 && AT_ref (a
)->die_id
.die_type_node
)
8285 fprintf (outfile
, "die -> signature: ");
8286 print_signature (outfile
,
8287 AT_ref (a
)->die_id
.die_type_node
->signature
);
8289 else if (dwarf_version
< 4 && AT_ref (a
)->die_id
.die_symbol
)
8290 fprintf (outfile
, "die -> label: %s",
8291 AT_ref (a
)->die_id
.die_symbol
);
8293 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
8296 fprintf (outfile
, "die -> <null>");
8298 case dw_val_class_vms_delta
:
8299 fprintf (outfile
, "delta: @slotcount(%s-%s)",
8300 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
8302 case dw_val_class_lbl_id
:
8303 case dw_val_class_lineptr
:
8304 case dw_val_class_macptr
:
8305 fprintf (outfile
, "label: %s", AT_lbl (a
));
8307 case dw_val_class_str
:
8308 if (AT_string (a
) != NULL
)
8309 fprintf (outfile
, "\"%s\"", AT_string (a
));
8311 fprintf (outfile
, "<null>");
8313 case dw_val_class_file
:
8314 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
8315 AT_file (a
)->emitted_number
);
8317 case dw_val_class_data8
:
8321 for (i
= 0; i
< 8; i
++)
8322 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
8329 fprintf (outfile
, "\n");
8332 if (die
->die_child
!= NULL
)
8335 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
8338 if (print_indent
== 0)
8339 fprintf (outfile
, "\n");
8342 /* Print the contents of the source code line number correspondence table.
8343 This routine is a debugging aid only. */
8346 print_dwarf_line_table (FILE *outfile
)
8349 dw_line_info_ref line_info
;
8351 fprintf (outfile
, "\n\nDWARF source line information\n");
8352 for (i
= 1; i
< line_info_table_in_use
; i
++)
8354 line_info
= &line_info_table
[i
];
8355 fprintf (outfile
, "%5d: %4ld %6ld\n", i
,
8356 line_info
->dw_file_num
,
8357 line_info
->dw_line_num
);
8360 fprintf (outfile
, "\n\n");
8363 /* Print the information collected for a given DIE. */
8366 debug_dwarf_die (dw_die_ref die
)
8368 print_die (die
, stderr
);
8371 /* Print all DWARF information collected for the compilation unit.
8372 This routine is a debugging aid only. */
8378 print_die (comp_unit_die
, stderr
);
8379 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
8380 print_dwarf_line_table (stderr
);
8383 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
8384 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
8385 DIE that marks the start of the DIEs for this include file. */
8388 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
8390 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
8391 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
8393 new_unit
->die_sib
= old_unit
;
8397 /* Close an include-file CU and reopen the enclosing one. */
8400 pop_compile_unit (dw_die_ref old_unit
)
8402 dw_die_ref new_unit
= old_unit
->die_sib
;
8404 old_unit
->die_sib
= NULL
;
8408 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8409 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
8411 /* Calculate the checksum of a location expression. */
8414 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
8418 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
8420 CHECKSUM (loc
->dw_loc_oprnd1
);
8421 CHECKSUM (loc
->dw_loc_oprnd2
);
8424 /* Calculate the checksum of an attribute. */
8427 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
8429 dw_loc_descr_ref loc
;
8432 CHECKSUM (at
->dw_attr
);
8434 /* We don't care that this was compiled with a different compiler
8435 snapshot; if the output is the same, that's what matters. */
8436 if (at
->dw_attr
== DW_AT_producer
)
8439 switch (AT_class (at
))
8441 case dw_val_class_const
:
8442 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
8444 case dw_val_class_unsigned_const
:
8445 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
8447 case dw_val_class_const_double
:
8448 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
8450 case dw_val_class_vec
:
8451 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
8453 case dw_val_class_flag
:
8454 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
8456 case dw_val_class_str
:
8457 CHECKSUM_STRING (AT_string (at
));
8460 case dw_val_class_addr
:
8462 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
8463 CHECKSUM_STRING (XSTR (r
, 0));
8466 case dw_val_class_offset
:
8467 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
8470 case dw_val_class_loc
:
8471 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
8472 loc_checksum (loc
, ctx
);
8475 case dw_val_class_die_ref
:
8476 die_checksum (AT_ref (at
), ctx
, mark
);
8479 case dw_val_class_fde_ref
:
8480 case dw_val_class_vms_delta
:
8481 case dw_val_class_lbl_id
:
8482 case dw_val_class_lineptr
:
8483 case dw_val_class_macptr
:
8486 case dw_val_class_file
:
8487 CHECKSUM_STRING (AT_file (at
)->filename
);
8490 case dw_val_class_data8
:
8491 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
8499 /* Calculate the checksum of a DIE. */
8502 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
8508 /* To avoid infinite recursion. */
8511 CHECKSUM (die
->die_mark
);
8514 die
->die_mark
= ++(*mark
);
8516 CHECKSUM (die
->die_tag
);
8518 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
8519 attr_checksum (a
, ctx
, mark
);
8521 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
8525 #undef CHECKSUM_STRING
8527 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
8528 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8529 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
8530 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
8531 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
8532 #define CHECKSUM_ATTR(FOO) \
8533 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
8535 /* Calculate the checksum of a number in signed LEB128 format. */
8538 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
8545 byte
= (value
& 0x7f);
8547 more
= !((value
== 0 && (byte
& 0x40) == 0)
8548 || (value
== -1 && (byte
& 0x40) != 0));
8557 /* Calculate the checksum of a number in unsigned LEB128 format. */
8560 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
8564 unsigned char byte
= (value
& 0x7f);
8567 /* More bytes to follow. */
8575 /* Checksum the context of the DIE. This adds the names of any
8576 surrounding namespaces or structures to the checksum. */
8579 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
8583 int tag
= die
->die_tag
;
8585 if (tag
!= DW_TAG_namespace
8586 && tag
!= DW_TAG_structure_type
8587 && tag
!= DW_TAG_class_type
)
8590 name
= get_AT_string (die
, DW_AT_name
);
8592 spec
= get_AT_ref (die
, DW_AT_specification
);
8596 if (die
->die_parent
!= NULL
)
8597 checksum_die_context (die
->die_parent
, ctx
);
8599 CHECKSUM_ULEB128 ('C');
8600 CHECKSUM_ULEB128 (tag
);
8602 CHECKSUM_STRING (name
);
8605 /* Calculate the checksum of a location expression. */
8608 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
8610 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
8611 were emitted as a DW_FORM_sdata instead of a location expression. */
8612 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
8614 CHECKSUM_ULEB128 (DW_FORM_sdata
);
8615 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
8619 /* Otherwise, just checksum the raw location expression. */
8622 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
8623 CHECKSUM (loc
->dw_loc_oprnd1
);
8624 CHECKSUM (loc
->dw_loc_oprnd2
);
8625 loc
= loc
->dw_loc_next
;
8629 /* Calculate the checksum of an attribute. */
8632 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
8633 struct md5_ctx
*ctx
, int *mark
)
8635 dw_loc_descr_ref loc
;
8638 if (AT_class (at
) == dw_val_class_die_ref
)
8640 dw_die_ref target_die
= AT_ref (at
);
8642 /* For pointer and reference types, we checksum only the (qualified)
8643 name of the target type (if there is a name). For friend entries,
8644 we checksum only the (qualified) name of the target type or function.
8645 This allows the checksum to remain the same whether the target type
8646 is complete or not. */
8647 if ((at
->dw_attr
== DW_AT_type
8648 && (tag
== DW_TAG_pointer_type
8649 || tag
== DW_TAG_reference_type
8650 || tag
== DW_TAG_rvalue_reference_type
8651 || tag
== DW_TAG_ptr_to_member_type
))
8652 || (at
->dw_attr
== DW_AT_friend
8653 && tag
== DW_TAG_friend
))
8655 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
8657 if (name_attr
!= NULL
)
8659 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
8663 CHECKSUM_ULEB128 ('N');
8664 CHECKSUM_ULEB128 (at
->dw_attr
);
8665 if (decl
->die_parent
!= NULL
)
8666 checksum_die_context (decl
->die_parent
, ctx
);
8667 CHECKSUM_ULEB128 ('E');
8668 CHECKSUM_STRING (AT_string (name_attr
));
8673 /* For all other references to another DIE, we check to see if the
8674 target DIE has already been visited. If it has, we emit a
8675 backward reference; if not, we descend recursively. */
8676 if (target_die
->die_mark
> 0)
8678 CHECKSUM_ULEB128 ('R');
8679 CHECKSUM_ULEB128 (at
->dw_attr
);
8680 CHECKSUM_ULEB128 (target_die
->die_mark
);
8684 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
8688 target_die
->die_mark
= ++(*mark
);
8689 CHECKSUM_ULEB128 ('T');
8690 CHECKSUM_ULEB128 (at
->dw_attr
);
8691 if (decl
->die_parent
!= NULL
)
8692 checksum_die_context (decl
->die_parent
, ctx
);
8693 die_checksum_ordered (target_die
, ctx
, mark
);
8698 CHECKSUM_ULEB128 ('A');
8699 CHECKSUM_ULEB128 (at
->dw_attr
);
8701 switch (AT_class (at
))
8703 case dw_val_class_const
:
8704 CHECKSUM_ULEB128 (DW_FORM_sdata
);
8705 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
8708 case dw_val_class_unsigned_const
:
8709 CHECKSUM_ULEB128 (DW_FORM_sdata
);
8710 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
8713 case dw_val_class_const_double
:
8714 CHECKSUM_ULEB128 (DW_FORM_block
);
8715 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
8716 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
8719 case dw_val_class_vec
:
8720 CHECKSUM_ULEB128 (DW_FORM_block
);
8721 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_vec
));
8722 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
8725 case dw_val_class_flag
:
8726 CHECKSUM_ULEB128 (DW_FORM_flag
);
8727 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
8730 case dw_val_class_str
:
8731 CHECKSUM_ULEB128 (DW_FORM_string
);
8732 CHECKSUM_STRING (AT_string (at
));
8735 case dw_val_class_addr
:
8737 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
8738 CHECKSUM_ULEB128 (DW_FORM_string
);
8739 CHECKSUM_STRING (XSTR (r
, 0));
8742 case dw_val_class_offset
:
8743 CHECKSUM_ULEB128 (DW_FORM_sdata
);
8744 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
8747 case dw_val_class_loc
:
8748 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
8749 loc_checksum_ordered (loc
, ctx
);
8752 case dw_val_class_fde_ref
:
8753 case dw_val_class_lbl_id
:
8754 case dw_val_class_lineptr
:
8755 case dw_val_class_macptr
:
8758 case dw_val_class_file
:
8759 CHECKSUM_ULEB128 (DW_FORM_string
);
8760 CHECKSUM_STRING (AT_file (at
)->filename
);
8763 case dw_val_class_data8
:
8764 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
8772 struct checksum_attributes
8774 dw_attr_ref at_name
;
8775 dw_attr_ref at_type
;
8776 dw_attr_ref at_friend
;
8777 dw_attr_ref at_accessibility
;
8778 dw_attr_ref at_address_class
;
8779 dw_attr_ref at_allocated
;
8780 dw_attr_ref at_artificial
;
8781 dw_attr_ref at_associated
;
8782 dw_attr_ref at_binary_scale
;
8783 dw_attr_ref at_bit_offset
;
8784 dw_attr_ref at_bit_size
;
8785 dw_attr_ref at_bit_stride
;
8786 dw_attr_ref at_byte_size
;
8787 dw_attr_ref at_byte_stride
;
8788 dw_attr_ref at_const_value
;
8789 dw_attr_ref at_containing_type
;
8790 dw_attr_ref at_count
;
8791 dw_attr_ref at_data_location
;
8792 dw_attr_ref at_data_member_location
;
8793 dw_attr_ref at_decimal_scale
;
8794 dw_attr_ref at_decimal_sign
;
8795 dw_attr_ref at_default_value
;
8796 dw_attr_ref at_digit_count
;
8797 dw_attr_ref at_discr
;
8798 dw_attr_ref at_discr_list
;
8799 dw_attr_ref at_discr_value
;
8800 dw_attr_ref at_encoding
;
8801 dw_attr_ref at_endianity
;
8802 dw_attr_ref at_explicit
;
8803 dw_attr_ref at_is_optional
;
8804 dw_attr_ref at_location
;
8805 dw_attr_ref at_lower_bound
;
8806 dw_attr_ref at_mutable
;
8807 dw_attr_ref at_ordering
;
8808 dw_attr_ref at_picture_string
;
8809 dw_attr_ref at_prototyped
;
8810 dw_attr_ref at_small
;
8811 dw_attr_ref at_segment
;
8812 dw_attr_ref at_string_length
;
8813 dw_attr_ref at_threads_scaled
;
8814 dw_attr_ref at_upper_bound
;
8815 dw_attr_ref at_use_location
;
8816 dw_attr_ref at_use_UTF8
;
8817 dw_attr_ref at_variable_parameter
;
8818 dw_attr_ref at_virtuality
;
8819 dw_attr_ref at_visibility
;
8820 dw_attr_ref at_vtable_elem_location
;
8823 /* Collect the attributes that we will want to use for the checksum. */
8826 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
8831 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
8842 attrs
->at_friend
= a
;
8844 case DW_AT_accessibility
:
8845 attrs
->at_accessibility
= a
;
8847 case DW_AT_address_class
:
8848 attrs
->at_address_class
= a
;
8850 case DW_AT_allocated
:
8851 attrs
->at_allocated
= a
;
8853 case DW_AT_artificial
:
8854 attrs
->at_artificial
= a
;
8856 case DW_AT_associated
:
8857 attrs
->at_associated
= a
;
8859 case DW_AT_binary_scale
:
8860 attrs
->at_binary_scale
= a
;
8862 case DW_AT_bit_offset
:
8863 attrs
->at_bit_offset
= a
;
8865 case DW_AT_bit_size
:
8866 attrs
->at_bit_size
= a
;
8868 case DW_AT_bit_stride
:
8869 attrs
->at_bit_stride
= a
;
8871 case DW_AT_byte_size
:
8872 attrs
->at_byte_size
= a
;
8874 case DW_AT_byte_stride
:
8875 attrs
->at_byte_stride
= a
;
8877 case DW_AT_const_value
:
8878 attrs
->at_const_value
= a
;
8880 case DW_AT_containing_type
:
8881 attrs
->at_containing_type
= a
;
8884 attrs
->at_count
= a
;
8886 case DW_AT_data_location
:
8887 attrs
->at_data_location
= a
;
8889 case DW_AT_data_member_location
:
8890 attrs
->at_data_member_location
= a
;
8892 case DW_AT_decimal_scale
:
8893 attrs
->at_decimal_scale
= a
;
8895 case DW_AT_decimal_sign
:
8896 attrs
->at_decimal_sign
= a
;
8898 case DW_AT_default_value
:
8899 attrs
->at_default_value
= a
;
8901 case DW_AT_digit_count
:
8902 attrs
->at_digit_count
= a
;
8905 attrs
->at_discr
= a
;
8907 case DW_AT_discr_list
:
8908 attrs
->at_discr_list
= a
;
8910 case DW_AT_discr_value
:
8911 attrs
->at_discr_value
= a
;
8913 case DW_AT_encoding
:
8914 attrs
->at_encoding
= a
;
8916 case DW_AT_endianity
:
8917 attrs
->at_endianity
= a
;
8919 case DW_AT_explicit
:
8920 attrs
->at_explicit
= a
;
8922 case DW_AT_is_optional
:
8923 attrs
->at_is_optional
= a
;
8925 case DW_AT_location
:
8926 attrs
->at_location
= a
;
8928 case DW_AT_lower_bound
:
8929 attrs
->at_lower_bound
= a
;
8932 attrs
->at_mutable
= a
;
8934 case DW_AT_ordering
:
8935 attrs
->at_ordering
= a
;
8937 case DW_AT_picture_string
:
8938 attrs
->at_picture_string
= a
;
8940 case DW_AT_prototyped
:
8941 attrs
->at_prototyped
= a
;
8944 attrs
->at_small
= a
;
8947 attrs
->at_segment
= a
;
8949 case DW_AT_string_length
:
8950 attrs
->at_string_length
= a
;
8952 case DW_AT_threads_scaled
:
8953 attrs
->at_threads_scaled
= a
;
8955 case DW_AT_upper_bound
:
8956 attrs
->at_upper_bound
= a
;
8958 case DW_AT_use_location
:
8959 attrs
->at_use_location
= a
;
8961 case DW_AT_use_UTF8
:
8962 attrs
->at_use_UTF8
= a
;
8964 case DW_AT_variable_parameter
:
8965 attrs
->at_variable_parameter
= a
;
8967 case DW_AT_virtuality
:
8968 attrs
->at_virtuality
= a
;
8970 case DW_AT_visibility
:
8971 attrs
->at_visibility
= a
;
8973 case DW_AT_vtable_elem_location
:
8974 attrs
->at_vtable_elem_location
= a
;
8982 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
8985 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
8989 struct checksum_attributes attrs
;
8991 CHECKSUM_ULEB128 ('D');
8992 CHECKSUM_ULEB128 (die
->die_tag
);
8994 memset (&attrs
, 0, sizeof (attrs
));
8996 decl
= get_AT_ref (die
, DW_AT_specification
);
8998 collect_checksum_attributes (&attrs
, decl
);
8999 collect_checksum_attributes (&attrs
, die
);
9001 CHECKSUM_ATTR (attrs
.at_name
);
9002 CHECKSUM_ATTR (attrs
.at_accessibility
);
9003 CHECKSUM_ATTR (attrs
.at_address_class
);
9004 CHECKSUM_ATTR (attrs
.at_allocated
);
9005 CHECKSUM_ATTR (attrs
.at_artificial
);
9006 CHECKSUM_ATTR (attrs
.at_associated
);
9007 CHECKSUM_ATTR (attrs
.at_binary_scale
);
9008 CHECKSUM_ATTR (attrs
.at_bit_offset
);
9009 CHECKSUM_ATTR (attrs
.at_bit_size
);
9010 CHECKSUM_ATTR (attrs
.at_bit_stride
);
9011 CHECKSUM_ATTR (attrs
.at_byte_size
);
9012 CHECKSUM_ATTR (attrs
.at_byte_stride
);
9013 CHECKSUM_ATTR (attrs
.at_const_value
);
9014 CHECKSUM_ATTR (attrs
.at_containing_type
);
9015 CHECKSUM_ATTR (attrs
.at_count
);
9016 CHECKSUM_ATTR (attrs
.at_data_location
);
9017 CHECKSUM_ATTR (attrs
.at_data_member_location
);
9018 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
9019 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
9020 CHECKSUM_ATTR (attrs
.at_default_value
);
9021 CHECKSUM_ATTR (attrs
.at_digit_count
);
9022 CHECKSUM_ATTR (attrs
.at_discr
);
9023 CHECKSUM_ATTR (attrs
.at_discr_list
);
9024 CHECKSUM_ATTR (attrs
.at_discr_value
);
9025 CHECKSUM_ATTR (attrs
.at_encoding
);
9026 CHECKSUM_ATTR (attrs
.at_endianity
);
9027 CHECKSUM_ATTR (attrs
.at_explicit
);
9028 CHECKSUM_ATTR (attrs
.at_is_optional
);
9029 CHECKSUM_ATTR (attrs
.at_location
);
9030 CHECKSUM_ATTR (attrs
.at_lower_bound
);
9031 CHECKSUM_ATTR (attrs
.at_mutable
);
9032 CHECKSUM_ATTR (attrs
.at_ordering
);
9033 CHECKSUM_ATTR (attrs
.at_picture_string
);
9034 CHECKSUM_ATTR (attrs
.at_prototyped
);
9035 CHECKSUM_ATTR (attrs
.at_small
);
9036 CHECKSUM_ATTR (attrs
.at_segment
);
9037 CHECKSUM_ATTR (attrs
.at_string_length
);
9038 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
9039 CHECKSUM_ATTR (attrs
.at_upper_bound
);
9040 CHECKSUM_ATTR (attrs
.at_use_location
);
9041 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
9042 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
9043 CHECKSUM_ATTR (attrs
.at_virtuality
);
9044 CHECKSUM_ATTR (attrs
.at_visibility
);
9045 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
9046 CHECKSUM_ATTR (attrs
.at_type
);
9047 CHECKSUM_ATTR (attrs
.at_friend
);
9049 /* Checksum the child DIEs, except for nested types and member functions. */
9052 dw_attr_ref name_attr
;
9055 name_attr
= get_AT (c
, DW_AT_name
);
9056 if ((is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
)
9057 && name_attr
!= NULL
)
9059 CHECKSUM_ULEB128 ('S');
9060 CHECKSUM_ULEB128 (c
->die_tag
);
9061 CHECKSUM_STRING (AT_string (name_attr
));
9065 /* Mark this DIE so it gets processed when unmarking. */
9066 if (c
->die_mark
== 0)
9068 die_checksum_ordered (c
, ctx
, mark
);
9070 } while (c
!= die
->die_child
);
9072 CHECKSUM_ULEB128 (0);
9076 #undef CHECKSUM_STRING
9077 #undef CHECKSUM_ATTR
9078 #undef CHECKSUM_LEB128
9079 #undef CHECKSUM_ULEB128
9081 /* Generate the type signature for DIE. This is computed by generating an
9082 MD5 checksum over the DIE's tag, its relevant attributes, and its
9083 children. Attributes that are references to other DIEs are processed
9084 by recursion, using the MARK field to prevent infinite recursion.
9085 If the DIE is nested inside a namespace or another type, we also
9086 need to include that context in the signature. The lower 64 bits
9087 of the resulting MD5 checksum comprise the signature. */
9090 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
9094 unsigned char checksum
[16];
9098 name
= get_AT_string (die
, DW_AT_name
);
9099 decl
= get_AT_ref (die
, DW_AT_specification
);
9101 /* First, compute a signature for just the type name (and its surrounding
9102 context, if any. This is stored in the type unit DIE for link-time
9103 ODR (one-definition rule) checking. */
9105 if (is_cxx() && name
!= NULL
)
9107 md5_init_ctx (&ctx
);
9109 /* Checksum the names of surrounding namespaces and structures. */
9110 if (decl
!= NULL
&& decl
->die_parent
!= NULL
)
9111 checksum_die_context (decl
->die_parent
, &ctx
);
9113 md5_process_bytes (&die
->die_tag
, sizeof (die
->die_tag
), &ctx
);
9114 md5_process_bytes (name
, strlen (name
) + 1, &ctx
);
9115 md5_finish_ctx (&ctx
, checksum
);
9117 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
9120 /* Next, compute the complete type signature. */
9122 md5_init_ctx (&ctx
);
9124 die
->die_mark
= mark
;
9126 /* Checksum the names of surrounding namespaces and structures. */
9127 if (decl
!= NULL
&& decl
->die_parent
!= NULL
)
9128 checksum_die_context (decl
->die_parent
, &ctx
);
9130 /* Checksum the DIE and its children. */
9131 die_checksum_ordered (die
, &ctx
, &mark
);
9132 unmark_all_dies (die
);
9133 md5_finish_ctx (&ctx
, checksum
);
9135 /* Store the signature in the type node and link the type DIE and the
9136 type node together. */
9137 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
9138 DWARF_TYPE_SIGNATURE_SIZE
);
9139 die
->die_id
.die_type_node
= type_node
;
9140 type_node
->type_die
= die
;
9142 /* If the DIE is a specification, link its declaration to the type node
9145 decl
->die_id
.die_type_node
= type_node
;
9148 /* Do the location expressions look same? */
9150 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
9152 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
9153 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
9154 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
9157 /* Do the values look the same? */
9159 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
9161 dw_loc_descr_ref loc1
, loc2
;
9164 if (v1
->val_class
!= v2
->val_class
)
9167 switch (v1
->val_class
)
9169 case dw_val_class_const
:
9170 return v1
->v
.val_int
== v2
->v
.val_int
;
9171 case dw_val_class_unsigned_const
:
9172 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
9173 case dw_val_class_const_double
:
9174 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
9175 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
9176 case dw_val_class_vec
:
9177 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
9178 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
9180 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
9181 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
9184 case dw_val_class_flag
:
9185 return v1
->v
.val_flag
== v2
->v
.val_flag
;
9186 case dw_val_class_str
:
9187 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
9189 case dw_val_class_addr
:
9190 r1
= v1
->v
.val_addr
;
9191 r2
= v2
->v
.val_addr
;
9192 if (GET_CODE (r1
) != GET_CODE (r2
))
9194 return !rtx_equal_p (r1
, r2
);
9196 case dw_val_class_offset
:
9197 return v1
->v
.val_offset
== v2
->v
.val_offset
;
9199 case dw_val_class_loc
:
9200 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
9202 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
9203 if (!same_loc_p (loc1
, loc2
, mark
))
9205 return !loc1
&& !loc2
;
9207 case dw_val_class_die_ref
:
9208 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
9210 case dw_val_class_fde_ref
:
9211 case dw_val_class_vms_delta
:
9212 case dw_val_class_lbl_id
:
9213 case dw_val_class_lineptr
:
9214 case dw_val_class_macptr
:
9217 case dw_val_class_file
:
9218 return v1
->v
.val_file
== v2
->v
.val_file
;
9220 case dw_val_class_data8
:
9221 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
9228 /* Do the attributes look the same? */
9231 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
9233 if (at1
->dw_attr
!= at2
->dw_attr
)
9236 /* We don't care that this was compiled with a different compiler
9237 snapshot; if the output is the same, that's what matters. */
9238 if (at1
->dw_attr
== DW_AT_producer
)
9241 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
9244 /* Do the dies look the same? */
9247 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
9253 /* To avoid infinite recursion. */
9255 return die1
->die_mark
== die2
->die_mark
;
9256 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
9258 if (die1
->die_tag
!= die2
->die_tag
)
9261 if (VEC_length (dw_attr_node
, die1
->die_attr
)
9262 != VEC_length (dw_attr_node
, die2
->die_attr
))
9265 for (ix
= 0; VEC_iterate (dw_attr_node
, die1
->die_attr
, ix
, a1
); ix
++)
9266 if (!same_attr_p (a1
, VEC_index (dw_attr_node
, die2
->die_attr
, ix
), mark
))
9269 c1
= die1
->die_child
;
9270 c2
= die2
->die_child
;
9279 if (!same_die_p (c1
, c2
, mark
))
9283 if (c1
== die1
->die_child
)
9285 if (c2
== die2
->die_child
)
9295 /* Do the dies look the same? Wrapper around same_die_p. */
9298 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
9301 int ret
= same_die_p (die1
, die2
, &mark
);
9303 unmark_all_dies (die1
);
9304 unmark_all_dies (die2
);
9309 /* The prefix to attach to symbols on DIEs in the current comdat debug
9311 static char *comdat_symbol_id
;
9313 /* The index of the current symbol within the current comdat CU. */
9314 static unsigned int comdat_symbol_number
;
9316 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
9317 children, and set comdat_symbol_id accordingly. */
9320 compute_section_prefix (dw_die_ref unit_die
)
9322 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
9323 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
9324 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
9327 unsigned char checksum
[16];
9330 /* Compute the checksum of the DIE, then append part of it as hex digits to
9331 the name filename of the unit. */
9333 md5_init_ctx (&ctx
);
9335 die_checksum (unit_die
, &ctx
, &mark
);
9336 unmark_all_dies (unit_die
);
9337 md5_finish_ctx (&ctx
, checksum
);
9339 sprintf (name
, "%s.", base
);
9340 clean_symbol_name (name
);
9342 p
= name
+ strlen (name
);
9343 for (i
= 0; i
< 4; i
++)
9345 sprintf (p
, "%.2x", checksum
[i
]);
9349 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
9350 comdat_symbol_number
= 0;
9353 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
9356 is_type_die (dw_die_ref die
)
9358 switch (die
->die_tag
)
9360 case DW_TAG_array_type
:
9361 case DW_TAG_class_type
:
9362 case DW_TAG_interface_type
:
9363 case DW_TAG_enumeration_type
:
9364 case DW_TAG_pointer_type
:
9365 case DW_TAG_reference_type
:
9366 case DW_TAG_rvalue_reference_type
:
9367 case DW_TAG_string_type
:
9368 case DW_TAG_structure_type
:
9369 case DW_TAG_subroutine_type
:
9370 case DW_TAG_union_type
:
9371 case DW_TAG_ptr_to_member_type
:
9372 case DW_TAG_set_type
:
9373 case DW_TAG_subrange_type
:
9374 case DW_TAG_base_type
:
9375 case DW_TAG_const_type
:
9376 case DW_TAG_file_type
:
9377 case DW_TAG_packed_type
:
9378 case DW_TAG_volatile_type
:
9379 case DW_TAG_typedef
:
9386 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
9387 Basically, we want to choose the bits that are likely to be shared between
9388 compilations (types) and leave out the bits that are specific to individual
9389 compilations (functions). */
9392 is_comdat_die (dw_die_ref c
)
9394 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
9395 we do for stabs. The advantage is a greater likelihood of sharing between
9396 objects that don't include headers in the same order (and therefore would
9397 put the base types in a different comdat). jason 8/28/00 */
9399 if (c
->die_tag
== DW_TAG_base_type
)
9402 if (c
->die_tag
== DW_TAG_pointer_type
9403 || c
->die_tag
== DW_TAG_reference_type
9404 || c
->die_tag
== DW_TAG_rvalue_reference_type
9405 || c
->die_tag
== DW_TAG_const_type
9406 || c
->die_tag
== DW_TAG_volatile_type
)
9408 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
9410 return t
? is_comdat_die (t
) : 0;
9413 return is_type_die (c
);
9416 /* Returns 1 iff C is the sort of DIE that might be referred to from another
9417 compilation unit. */
9420 is_symbol_die (dw_die_ref c
)
9422 return (is_type_die (c
)
9423 || is_declaration_die (c
)
9424 || c
->die_tag
== DW_TAG_namespace
9425 || c
->die_tag
== DW_TAG_module
);
9429 gen_internal_sym (const char *prefix
)
9433 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
9434 return xstrdup (buf
);
9437 /* Assign symbols to all worthy DIEs under DIE. */
9440 assign_symbol_names (dw_die_ref die
)
9444 if (is_symbol_die (die
))
9446 if (comdat_symbol_id
)
9448 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
9450 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
9451 comdat_symbol_id
, comdat_symbol_number
++);
9452 die
->die_id
.die_symbol
= xstrdup (p
);
9455 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
9458 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
9461 struct cu_hash_table_entry
9464 unsigned min_comdat_num
, max_comdat_num
;
9465 struct cu_hash_table_entry
*next
;
9468 /* Routines to manipulate hash table of CUs. */
9470 htab_cu_hash (const void *of
)
9472 const struct cu_hash_table_entry
*const entry
=
9473 (const struct cu_hash_table_entry
*) of
;
9475 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
9479 htab_cu_eq (const void *of1
, const void *of2
)
9481 const struct cu_hash_table_entry
*const entry1
=
9482 (const struct cu_hash_table_entry
*) of1
;
9483 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
9485 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
9489 htab_cu_del (void *what
)
9491 struct cu_hash_table_entry
*next
,
9492 *entry
= (struct cu_hash_table_entry
*) what
;
9502 /* Check whether we have already seen this CU and set up SYM_NUM
9505 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
9507 struct cu_hash_table_entry dummy
;
9508 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
9510 dummy
.max_comdat_num
= 0;
9512 slot
= (struct cu_hash_table_entry
**)
9513 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
9517 for (; entry
; last
= entry
, entry
= entry
->next
)
9519 if (same_die_p_wrap (cu
, entry
->cu
))
9525 *sym_num
= entry
->min_comdat_num
;
9529 entry
= XCNEW (struct cu_hash_table_entry
);
9531 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
9532 entry
->next
= *slot
;
9538 /* Record SYM_NUM to record of CU in HTABLE. */
9540 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
9542 struct cu_hash_table_entry
**slot
, *entry
;
9544 slot
= (struct cu_hash_table_entry
**)
9545 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
9549 entry
->max_comdat_num
= sym_num
;
9552 /* Traverse the DIE (which is always comp_unit_die), and set up
9553 additional compilation units for each of the include files we see
9554 bracketed by BINCL/EINCL. */
9557 break_out_includes (dw_die_ref die
)
9560 dw_die_ref unit
= NULL
;
9561 limbo_die_node
*node
, **pnode
;
9562 htab_t cu_hash_table
;
9566 dw_die_ref prev
= c
;
9568 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
9569 || (unit
&& is_comdat_die (c
)))
9571 dw_die_ref next
= c
->die_sib
;
9573 /* This DIE is for a secondary CU; remove it from the main one. */
9574 remove_child_with_prev (c
, prev
);
9576 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
9577 unit
= push_new_compile_unit (unit
, c
);
9578 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
9579 unit
= pop_compile_unit (unit
);
9581 add_child_die (unit
, c
);
9583 if (c
== die
->die_child
)
9586 } while (c
!= die
->die_child
);
9589 /* We can only use this in debugging, since the frontend doesn't check
9590 to make sure that we leave every include file we enter. */
9594 assign_symbol_names (die
);
9595 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
9596 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
9602 compute_section_prefix (node
->die
);
9603 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
9604 &comdat_symbol_number
);
9605 assign_symbol_names (node
->die
);
9607 *pnode
= node
->next
;
9610 pnode
= &node
->next
;
9611 record_comdat_symbol_number (node
->die
, cu_hash_table
,
9612 comdat_symbol_number
);
9615 htab_delete (cu_hash_table
);
9618 /* Return non-zero if this DIE is a declaration. */
9621 is_declaration_die (dw_die_ref die
)
9626 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
9627 if (a
->dw_attr
== DW_AT_declaration
)
9633 /* Return non-zero if this DIE is nested inside a subprogram. */
9636 is_nested_in_subprogram (dw_die_ref die
)
9638 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
9642 return local_scope_p (decl
);
9645 /* Return non-zero if this is a type DIE that should be moved to a
9646 COMDAT .debug_types section. */
9649 should_move_die_to_comdat (dw_die_ref die
)
9651 switch (die
->die_tag
)
9653 case DW_TAG_class_type
:
9654 case DW_TAG_structure_type
:
9655 case DW_TAG_enumeration_type
:
9656 case DW_TAG_union_type
:
9657 /* Don't move declarations, inlined instances, or types nested in a
9659 if (is_declaration_die (die
)
9660 || get_AT (die
, DW_AT_abstract_origin
)
9661 || is_nested_in_subprogram (die
))
9664 case DW_TAG_array_type
:
9665 case DW_TAG_interface_type
:
9666 case DW_TAG_pointer_type
:
9667 case DW_TAG_reference_type
:
9668 case DW_TAG_rvalue_reference_type
:
9669 case DW_TAG_string_type
:
9670 case DW_TAG_subroutine_type
:
9671 case DW_TAG_ptr_to_member_type
:
9672 case DW_TAG_set_type
:
9673 case DW_TAG_subrange_type
:
9674 case DW_TAG_base_type
:
9675 case DW_TAG_const_type
:
9676 case DW_TAG_file_type
:
9677 case DW_TAG_packed_type
:
9678 case DW_TAG_volatile_type
:
9679 case DW_TAG_typedef
:
9685 /* Make a clone of DIE. */
9688 clone_die (dw_die_ref die
)
9694 clone
= ggc_alloc_cleared_die_node ();
9695 clone
->die_tag
= die
->die_tag
;
9697 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
9698 add_dwarf_attr (clone
, a
);
9703 /* Make a clone of the tree rooted at DIE. */
9706 clone_tree (dw_die_ref die
)
9709 dw_die_ref clone
= clone_die (die
);
9711 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree(c
)));
9716 /* Make a clone of DIE as a declaration. */
9719 clone_as_declaration (dw_die_ref die
)
9726 /* If the DIE is already a declaration, just clone it. */
9727 if (is_declaration_die (die
))
9728 return clone_die (die
);
9730 /* If the DIE is a specification, just clone its declaration DIE. */
9731 decl
= get_AT_ref (die
, DW_AT_specification
);
9733 return clone_die (decl
);
9735 clone
= ggc_alloc_cleared_die_node ();
9736 clone
->die_tag
= die
->die_tag
;
9738 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
9740 /* We don't want to copy over all attributes.
9741 For example we don't want DW_AT_byte_size because otherwise we will no
9742 longer have a declaration and GDB will treat it as a definition. */
9746 case DW_AT_artificial
:
9747 case DW_AT_containing_type
:
9748 case DW_AT_external
:
9751 case DW_AT_virtuality
:
9752 case DW_AT_linkage_name
:
9753 case DW_AT_MIPS_linkage_name
:
9754 add_dwarf_attr (clone
, a
);
9756 case DW_AT_byte_size
:
9762 if (die
->die_id
.die_type_node
)
9763 add_AT_die_ref (clone
, DW_AT_signature
, die
);
9765 add_AT_flag (clone
, DW_AT_declaration
, 1);
9769 /* Copy the declaration context to the new compile unit DIE. This includes
9770 any surrounding namespace or type declarations. If the DIE has an
9771 AT_specification attribute, it also includes attributes and children
9772 attached to the specification. */
9775 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
9778 dw_die_ref new_decl
;
9780 decl
= get_AT_ref (die
, DW_AT_specification
);
9789 /* Copy the type node pointer from the new DIE to the original
9790 declaration DIE so we can forward references later. */
9791 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
9793 remove_AT (die
, DW_AT_specification
);
9795 for (ix
= 0; VEC_iterate (dw_attr_node
, decl
->die_attr
, ix
, a
); ix
++)
9797 if (a
->dw_attr
!= DW_AT_name
9798 && a
->dw_attr
!= DW_AT_declaration
9799 && a
->dw_attr
!= DW_AT_external
)
9800 add_dwarf_attr (die
, a
);
9803 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree(c
)));
9806 if (decl
->die_parent
!= NULL
9807 && decl
->die_parent
->die_tag
!= DW_TAG_compile_unit
9808 && decl
->die_parent
->die_tag
!= DW_TAG_type_unit
)
9810 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
9811 if (new_decl
!= NULL
)
9813 remove_AT (new_decl
, DW_AT_signature
);
9814 add_AT_specification (die
, new_decl
);
9819 /* Generate the skeleton ancestor tree for the given NODE, then clone
9820 the DIE and add the clone into the tree. */
9823 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
9825 if (node
->new_die
!= NULL
)
9828 node
->new_die
= clone_as_declaration (node
->old_die
);
9830 if (node
->parent
!= NULL
)
9832 generate_skeleton_ancestor_tree (node
->parent
);
9833 add_child_die (node
->parent
->new_die
, node
->new_die
);
9837 /* Generate a skeleton tree of DIEs containing any declarations that are
9838 found in the original tree. We traverse the tree looking for declaration
9839 DIEs, and construct the skeleton from the bottom up whenever we find one. */
9842 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
9844 skeleton_chain_node node
;
9847 dw_die_ref prev
= NULL
;
9848 dw_die_ref next
= NULL
;
9850 node
.parent
= parent
;
9852 first
= c
= parent
->old_die
->die_child
;
9856 if (prev
== NULL
|| prev
->die_sib
== c
)
9859 next
= (c
== first
? NULL
: c
->die_sib
);
9861 node
.new_die
= NULL
;
9862 if (is_declaration_die (c
))
9864 /* Clone the existing DIE, move the original to the skeleton
9865 tree (which is in the main CU), and put the clone, with
9866 all the original's children, where the original came from. */
9867 dw_die_ref clone
= clone_die (c
);
9868 move_all_children (c
, clone
);
9870 replace_child (c
, clone
, prev
);
9871 generate_skeleton_ancestor_tree (parent
);
9872 add_child_die (parent
->new_die
, c
);
9876 generate_skeleton_bottom_up (&node
);
9877 } while (next
!= NULL
);
9880 /* Wrapper function for generate_skeleton_bottom_up. */
9883 generate_skeleton (dw_die_ref die
)
9885 skeleton_chain_node node
;
9888 node
.new_die
= NULL
;
9891 /* If this type definition is nested inside another type,
9892 always leave at least a declaration in its place. */
9893 if (die
->die_parent
!= NULL
&& is_type_die (die
->die_parent
))
9894 node
.new_die
= clone_as_declaration (die
);
9896 generate_skeleton_bottom_up (&node
);
9897 return node
.new_die
;
9900 /* Remove the DIE from its parent, possibly replacing it with a cloned
9901 declaration. The original DIE will be moved to a new compile unit
9902 so that existing references to it follow it to the new location. If
9903 any of the original DIE's descendants is a declaration, we need to
9904 replace the original DIE with a skeleton tree and move the
9905 declarations back into the skeleton tree. */
9908 remove_child_or_replace_with_skeleton (dw_die_ref child
, dw_die_ref prev
)
9910 dw_die_ref skeleton
;
9912 skeleton
= generate_skeleton (child
);
9913 if (skeleton
== NULL
)
9914 remove_child_with_prev (child
, prev
);
9917 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
9918 replace_child (child
, skeleton
, prev
);
9924 /* Traverse the DIE and set up additional .debug_types sections for each
9925 type worthy of being placed in a COMDAT section. */
9928 break_out_comdat_types (dw_die_ref die
)
9932 dw_die_ref prev
= NULL
;
9933 dw_die_ref next
= NULL
;
9934 dw_die_ref unit
= NULL
;
9936 first
= c
= die
->die_child
;
9940 if (prev
== NULL
|| prev
->die_sib
== c
)
9943 next
= (c
== first
? NULL
: c
->die_sib
);
9944 if (should_move_die_to_comdat (c
))
9946 dw_die_ref replacement
;
9947 comdat_type_node_ref type_node
;
9949 /* Create a new type unit DIE as the root for the new tree, and
9950 add it to the list of comdat types. */
9951 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
9952 add_AT_unsigned (unit
, DW_AT_language
,
9953 get_AT_unsigned (comp_unit_die
, DW_AT_language
));
9954 type_node
= ggc_alloc_cleared_comdat_type_node ();
9955 type_node
->root_die
= unit
;
9956 type_node
->next
= comdat_type_list
;
9957 comdat_type_list
= type_node
;
9959 /* Generate the type signature. */
9960 generate_type_signature (c
, type_node
);
9962 /* Copy the declaration context, attributes, and children of the
9963 declaration into the new compile unit DIE. */
9964 copy_declaration_context (unit
, c
);
9966 /* Remove this DIE from the main CU. */
9967 replacement
= remove_child_or_replace_with_skeleton (c
, prev
);
9969 /* Break out nested types into their own type units. */
9970 break_out_comdat_types (c
);
9972 /* Add the DIE to the new compunit. */
9973 add_child_die (unit
, c
);
9975 if (replacement
!= NULL
)
9978 else if (c
->die_tag
== DW_TAG_namespace
9979 || c
->die_tag
== DW_TAG_class_type
9980 || c
->die_tag
== DW_TAG_structure_type
9981 || c
->die_tag
== DW_TAG_union_type
)
9983 /* Look for nested types that can be broken out. */
9984 break_out_comdat_types (c
);
9986 } while (next
!= NULL
);
9989 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
9991 struct decl_table_entry
9997 /* Routines to manipulate hash table of copied declarations. */
10000 htab_decl_hash (const void *of
)
10002 const struct decl_table_entry
*const entry
=
10003 (const struct decl_table_entry
*) of
;
10005 return htab_hash_pointer (entry
->orig
);
10009 htab_decl_eq (const void *of1
, const void *of2
)
10011 const struct decl_table_entry
*const entry1
=
10012 (const struct decl_table_entry
*) of1
;
10013 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
10015 return entry1
->orig
== entry2
;
10019 htab_decl_del (void *what
)
10021 struct decl_table_entry
*entry
= (struct decl_table_entry
*) what
;
10026 /* Copy DIE and its ancestors, up to, but not including, the compile unit
10027 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
10028 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
10029 to check if the ancestor has already been copied into UNIT. */
10032 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
10034 dw_die_ref parent
= die
->die_parent
;
10035 dw_die_ref new_parent
= unit
;
10037 void **slot
= NULL
;
10038 struct decl_table_entry
*entry
= NULL
;
10042 /* Check if the entry has already been copied to UNIT. */
10043 slot
= htab_find_slot_with_hash (decl_table
, die
,
10044 htab_hash_pointer (die
), INSERT
);
10045 if (*slot
!= HTAB_EMPTY_ENTRY
)
10047 entry
= (struct decl_table_entry
*) *slot
;
10048 return entry
->copy
;
10051 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
10052 entry
= XCNEW (struct decl_table_entry
);
10054 entry
->copy
= NULL
;
10058 if (parent
!= NULL
)
10060 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
10063 if (parent
->die_tag
!= DW_TAG_compile_unit
10064 && parent
->die_tag
!= DW_TAG_type_unit
)
10065 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
10068 copy
= clone_as_declaration (die
);
10069 add_child_die (new_parent
, copy
);
10071 if (decl_table
!= NULL
)
10073 /* Record the pointer to the copy. */
10074 entry
->copy
= copy
;
10080 /* Walk the DIE and its children, looking for references to incomplete
10081 or trivial types that are unmarked (i.e., that are not in the current
10085 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
10091 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
10093 if (AT_class (a
) == dw_val_class_die_ref
)
10095 dw_die_ref targ
= AT_ref (a
);
10096 comdat_type_node_ref type_node
= targ
->die_id
.die_type_node
;
10098 struct decl_table_entry
*entry
;
10100 if (targ
->die_mark
!= 0 || type_node
!= NULL
)
10103 slot
= htab_find_slot_with_hash (decl_table
, targ
,
10104 htab_hash_pointer (targ
), INSERT
);
10106 if (*slot
!= HTAB_EMPTY_ENTRY
)
10108 /* TARG has already been copied, so we just need to
10109 modify the reference to point to the copy. */
10110 entry
= (struct decl_table_entry
*) *slot
;
10111 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
10115 dw_die_ref parent
= unit
;
10116 dw_die_ref copy
= clone_tree (targ
);
10118 /* Make sure the cloned tree is marked as part of the
10122 /* Record in DECL_TABLE that TARG has been copied.
10123 Need to do this now, before the recursive call,
10124 because DECL_TABLE may be expanded and SLOT
10125 would no longer be a valid pointer. */
10126 entry
= XCNEW (struct decl_table_entry
);
10127 entry
->orig
= targ
;
10128 entry
->copy
= copy
;
10131 /* If TARG has surrounding context, copy its ancestor tree
10132 into the new type unit. */
10133 if (targ
->die_parent
!= NULL
10134 && targ
->die_parent
->die_tag
!= DW_TAG_compile_unit
10135 && targ
->die_parent
->die_tag
!= DW_TAG_type_unit
)
10136 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
10139 add_child_die (parent
, copy
);
10140 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
10142 /* Make sure the newly-copied DIE is walked. If it was
10143 installed in a previously-added context, it won't
10144 get visited otherwise. */
10145 if (parent
!= unit
)
10147 /* Find the highest point of the newly-added tree,
10148 mark each node along the way, and walk from there. */
10149 parent
->die_mark
= 1;
10150 while (parent
->die_parent
10151 && parent
->die_parent
->die_mark
== 0)
10153 parent
= parent
->die_parent
;
10154 parent
->die_mark
= 1;
10156 copy_decls_walk (unit
, parent
, decl_table
);
10162 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
10165 /* Copy declarations for "unworthy" types into the new comdat section.
10166 Incomplete types, modified types, and certain other types aren't broken
10167 out into comdat sections of their own, so they don't have a signature,
10168 and we need to copy the declaration into the same section so that we
10169 don't have an external reference. */
10172 copy_decls_for_unworthy_types (dw_die_ref unit
)
10177 decl_table
= htab_create (10, htab_decl_hash
, htab_decl_eq
, htab_decl_del
);
10178 copy_decls_walk (unit
, unit
, decl_table
);
10179 htab_delete (decl_table
);
10180 unmark_dies (unit
);
10183 /* Traverse the DIE and add a sibling attribute if it may have the
10184 effect of speeding up access to siblings. To save some space,
10185 avoid generating sibling attributes for DIE's without children. */
10188 add_sibling_attributes (dw_die_ref die
)
10192 if (! die
->die_child
)
10195 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
10196 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
10198 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
10201 /* Output all location lists for the DIE and its children. */
10204 output_location_lists (dw_die_ref die
)
10210 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
10211 if (AT_class (a
) == dw_val_class_loc_list
)
10212 output_loc_list (AT_loc_list (a
));
10214 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
10217 /* The format of each DIE (and its attribute value pairs) is encoded in an
10218 abbreviation table. This routine builds the abbreviation table and assigns
10219 a unique abbreviation id for each abbreviation entry. The children of each
10220 die are visited recursively. */
10223 build_abbrev_table (dw_die_ref die
)
10225 unsigned long abbrev_id
;
10226 unsigned int n_alloc
;
10231 /* Scan the DIE references, and mark as external any that refer to
10232 DIEs from other CUs (i.e. those which are not marked). */
10233 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
10234 if (AT_class (a
) == dw_val_class_die_ref
10235 && AT_ref (a
)->die_mark
== 0)
10237 gcc_assert (dwarf_version
>= 4 || AT_ref (a
)->die_id
.die_symbol
);
10238 set_AT_ref_external (a
, 1);
10241 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
10243 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
10244 dw_attr_ref die_a
, abbrev_a
;
10248 if (abbrev
->die_tag
!= die
->die_tag
)
10250 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
10253 if (VEC_length (dw_attr_node
, abbrev
->die_attr
)
10254 != VEC_length (dw_attr_node
, die
->die_attr
))
10257 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, die_a
); ix
++)
10259 abbrev_a
= VEC_index (dw_attr_node
, abbrev
->die_attr
, ix
);
10260 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
10261 || (value_format (abbrev_a
) != value_format (die_a
)))
10271 if (abbrev_id
>= abbrev_die_table_in_use
)
10273 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
10275 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
10276 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
10279 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
10280 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
10281 abbrev_die_table_allocated
= n_alloc
;
10284 ++abbrev_die_table_in_use
;
10285 abbrev_die_table
[abbrev_id
] = die
;
10288 die
->die_abbrev
= abbrev_id
;
10289 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
));
10292 /* Return the power-of-two number of bytes necessary to represent VALUE. */
10295 constant_size (unsigned HOST_WIDE_INT value
)
10302 log
= floor_log2 (value
);
10305 log
= 1 << (floor_log2 (log
) + 1);
10310 /* Return the size of a DIE as it is represented in the
10311 .debug_info section. */
10313 static unsigned long
10314 size_of_die (dw_die_ref die
)
10316 unsigned long size
= 0;
10320 size
+= size_of_uleb128 (die
->die_abbrev
);
10321 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
10323 switch (AT_class (a
))
10325 case dw_val_class_addr
:
10326 size
+= DWARF2_ADDR_SIZE
;
10328 case dw_val_class_offset
:
10329 size
+= DWARF_OFFSET_SIZE
;
10331 case dw_val_class_loc
:
10333 unsigned long lsize
= size_of_locs (AT_loc (a
));
10335 /* Block length. */
10336 if (dwarf_version
>= 4)
10337 size
+= size_of_uleb128 (lsize
);
10339 size
+= constant_size (lsize
);
10343 case dw_val_class_loc_list
:
10344 size
+= DWARF_OFFSET_SIZE
;
10346 case dw_val_class_range_list
:
10347 size
+= DWARF_OFFSET_SIZE
;
10349 case dw_val_class_const
:
10350 size
+= size_of_sleb128 (AT_int (a
));
10352 case dw_val_class_unsigned_const
:
10353 size
+= constant_size (AT_unsigned (a
));
10355 case dw_val_class_const_double
:
10356 size
+= 2 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
10357 if (HOST_BITS_PER_WIDE_INT
>= 64)
10358 size
++; /* block */
10360 case dw_val_class_vec
:
10361 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
10362 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
10363 + a
->dw_attr_val
.v
.val_vec
.length
10364 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
10366 case dw_val_class_flag
:
10367 if (dwarf_version
>= 4)
10368 /* Currently all add_AT_flag calls pass in 1 as last argument,
10369 so DW_FORM_flag_present can be used. If that ever changes,
10370 we'll need to use DW_FORM_flag and have some optimization
10371 in build_abbrev_table that will change those to
10372 DW_FORM_flag_present if it is set to 1 in all DIEs using
10373 the same abbrev entry. */
10374 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
10378 case dw_val_class_die_ref
:
10379 if (AT_ref_external (a
))
10381 /* In DWARF4, we use DW_FORM_sig8; for earlier versions
10382 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
10383 is sized by target address length, whereas in DWARF3
10384 it's always sized as an offset. */
10385 if (dwarf_version
>= 4)
10386 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
10387 else if (dwarf_version
== 2)
10388 size
+= DWARF2_ADDR_SIZE
;
10390 size
+= DWARF_OFFSET_SIZE
;
10393 size
+= DWARF_OFFSET_SIZE
;
10395 case dw_val_class_fde_ref
:
10396 size
+= DWARF_OFFSET_SIZE
;
10398 case dw_val_class_lbl_id
:
10399 size
+= DWARF2_ADDR_SIZE
;
10401 case dw_val_class_lineptr
:
10402 case dw_val_class_macptr
:
10403 size
+= DWARF_OFFSET_SIZE
;
10405 case dw_val_class_str
:
10406 if (AT_string_form (a
) == DW_FORM_strp
)
10407 size
+= DWARF_OFFSET_SIZE
;
10409 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
10411 case dw_val_class_file
:
10412 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
10414 case dw_val_class_data8
:
10417 case dw_val_class_vms_delta
:
10418 size
+= DWARF_OFFSET_SIZE
;
10421 gcc_unreachable ();
10428 /* Size the debugging information associated with a given DIE. Visits the
10429 DIE's children recursively. Updates the global variable next_die_offset, on
10430 each time through. Uses the current value of next_die_offset to update the
10431 die_offset field in each DIE. */
10434 calc_die_sizes (dw_die_ref die
)
10438 die
->die_offset
= next_die_offset
;
10439 next_die_offset
+= size_of_die (die
);
10441 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
10443 if (die
->die_child
!= NULL
)
10444 /* Count the null byte used to terminate sibling lists. */
10445 next_die_offset
+= 1;
10448 /* Set the marks for a die and its children. We do this so
10449 that we know whether or not a reference needs to use FORM_ref_addr; only
10450 DIEs in the same CU will be marked. We used to clear out the offset
10451 and use that as the flag, but ran into ordering problems. */
10454 mark_dies (dw_die_ref die
)
10458 gcc_assert (!die
->die_mark
);
10461 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
10464 /* Clear the marks for a die and its children. */
10467 unmark_dies (dw_die_ref die
)
10471 if (dwarf_version
< 4)
10472 gcc_assert (die
->die_mark
);
10475 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
10478 /* Clear the marks for a die, its children and referred dies. */
10481 unmark_all_dies (dw_die_ref die
)
10487 if (!die
->die_mark
)
10491 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
10493 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
10494 if (AT_class (a
) == dw_val_class_die_ref
)
10495 unmark_all_dies (AT_ref (a
));
10498 /* Return the size of the .debug_pubnames or .debug_pubtypes table
10499 generated for the compilation unit. */
10501 static unsigned long
10502 size_of_pubnames (VEC (pubname_entry
, gc
) * names
)
10504 unsigned long size
;
10508 size
= DWARF_PUBNAMES_HEADER_SIZE
;
10509 for (i
= 0; VEC_iterate (pubname_entry
, names
, i
, p
); i
++)
10510 if (names
!= pubtype_table
10511 || p
->die
->die_offset
!= 0
10512 || !flag_eliminate_unused_debug_types
)
10513 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
10515 size
+= DWARF_OFFSET_SIZE
;
10519 /* Return the size of the information in the .debug_aranges section. */
10521 static unsigned long
10522 size_of_aranges (void)
10524 unsigned long size
;
10526 size
= DWARF_ARANGES_HEADER_SIZE
;
10528 /* Count the address/length pair for this compilation unit. */
10529 if (text_section_used
)
10530 size
+= 2 * DWARF2_ADDR_SIZE
;
10531 if (cold_text_section_used
)
10532 size
+= 2 * DWARF2_ADDR_SIZE
;
10533 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
10535 /* Count the two zero words used to terminated the address range table. */
10536 size
+= 2 * DWARF2_ADDR_SIZE
;
10540 /* Select the encoding of an attribute value. */
10542 static enum dwarf_form
10543 value_format (dw_attr_ref a
)
10545 switch (a
->dw_attr_val
.val_class
)
10547 case dw_val_class_addr
:
10548 /* Only very few attributes allow DW_FORM_addr. */
10549 switch (a
->dw_attr
)
10552 case DW_AT_high_pc
:
10553 case DW_AT_entry_pc
:
10554 case DW_AT_trampoline
:
10555 return DW_FORM_addr
;
10559 switch (DWARF2_ADDR_SIZE
)
10562 return DW_FORM_data1
;
10564 return DW_FORM_data2
;
10566 return DW_FORM_data4
;
10568 return DW_FORM_data8
;
10570 gcc_unreachable ();
10572 case dw_val_class_range_list
:
10573 case dw_val_class_loc_list
:
10574 if (dwarf_version
>= 4)
10575 return DW_FORM_sec_offset
;
10577 case dw_val_class_vms_delta
:
10578 case dw_val_class_offset
:
10579 switch (DWARF_OFFSET_SIZE
)
10582 return DW_FORM_data4
;
10584 return DW_FORM_data8
;
10586 gcc_unreachable ();
10588 case dw_val_class_loc
:
10589 if (dwarf_version
>= 4)
10590 return DW_FORM_exprloc
;
10591 switch (constant_size (size_of_locs (AT_loc (a
))))
10594 return DW_FORM_block1
;
10596 return DW_FORM_block2
;
10598 gcc_unreachable ();
10600 case dw_val_class_const
:
10601 return DW_FORM_sdata
;
10602 case dw_val_class_unsigned_const
:
10603 switch (constant_size (AT_unsigned (a
)))
10606 return DW_FORM_data1
;
10608 return DW_FORM_data2
;
10610 return DW_FORM_data4
;
10612 return DW_FORM_data8
;
10614 gcc_unreachable ();
10616 case dw_val_class_const_double
:
10617 switch (HOST_BITS_PER_WIDE_INT
)
10620 return DW_FORM_data2
;
10622 return DW_FORM_data4
;
10624 return DW_FORM_data8
;
10627 return DW_FORM_block1
;
10629 case dw_val_class_vec
:
10630 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
10631 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
10634 return DW_FORM_block1
;
10636 return DW_FORM_block2
;
10638 return DW_FORM_block4
;
10640 gcc_unreachable ();
10642 case dw_val_class_flag
:
10643 if (dwarf_version
>= 4)
10645 /* Currently all add_AT_flag calls pass in 1 as last argument,
10646 so DW_FORM_flag_present can be used. If that ever changes,
10647 we'll need to use DW_FORM_flag and have some optimization
10648 in build_abbrev_table that will change those to
10649 DW_FORM_flag_present if it is set to 1 in all DIEs using
10650 the same abbrev entry. */
10651 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
10652 return DW_FORM_flag_present
;
10654 return DW_FORM_flag
;
10655 case dw_val_class_die_ref
:
10656 if (AT_ref_external (a
))
10657 return dwarf_version
>= 4 ? DW_FORM_sig8
: DW_FORM_ref_addr
;
10659 return DW_FORM_ref
;
10660 case dw_val_class_fde_ref
:
10661 return DW_FORM_data
;
10662 case dw_val_class_lbl_id
:
10663 return DW_FORM_addr
;
10664 case dw_val_class_lineptr
:
10665 case dw_val_class_macptr
:
10666 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
10667 case dw_val_class_str
:
10668 return AT_string_form (a
);
10669 case dw_val_class_file
:
10670 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
10673 return DW_FORM_data1
;
10675 return DW_FORM_data2
;
10677 return DW_FORM_data4
;
10679 gcc_unreachable ();
10682 case dw_val_class_data8
:
10683 return DW_FORM_data8
;
10686 gcc_unreachable ();
10690 /* Output the encoding of an attribute value. */
10693 output_value_format (dw_attr_ref a
)
10695 enum dwarf_form form
= value_format (a
);
10697 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
10700 /* Output the .debug_abbrev section which defines the DIE abbreviation
10704 output_abbrev_section (void)
10706 unsigned long abbrev_id
;
10708 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
10710 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
10712 dw_attr_ref a_attr
;
10714 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
10715 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
10716 dwarf_tag_name (abbrev
->die_tag
));
10718 if (abbrev
->die_child
!= NULL
)
10719 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
10721 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
10723 for (ix
= 0; VEC_iterate (dw_attr_node
, abbrev
->die_attr
, ix
, a_attr
);
10726 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
10727 dwarf_attr_name (a_attr
->dw_attr
));
10728 output_value_format (a_attr
);
10731 dw2_asm_output_data (1, 0, NULL
);
10732 dw2_asm_output_data (1, 0, NULL
);
10735 /* Terminate the table. */
10736 dw2_asm_output_data (1, 0, NULL
);
10739 /* Output a symbol we can use to refer to this DIE from another CU. */
10742 output_die_symbol (dw_die_ref die
)
10744 char *sym
= die
->die_id
.die_symbol
;
10749 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
10750 /* We make these global, not weak; if the target doesn't support
10751 .linkonce, it doesn't support combining the sections, so debugging
10753 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
10755 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
10758 /* Return a new location list, given the begin and end range, and the
10761 static inline dw_loc_list_ref
10762 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
10763 const char *section
)
10765 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
10767 retlist
->begin
= begin
;
10768 retlist
->end
= end
;
10769 retlist
->expr
= expr
;
10770 retlist
->section
= section
;
10775 /* Generate a new internal symbol for this location list node, if it
10776 hasn't got one yet. */
10779 gen_llsym (dw_loc_list_ref list
)
10781 gcc_assert (!list
->ll_symbol
);
10782 list
->ll_symbol
= gen_internal_sym ("LLST");
10785 /* Output the location list given to us. */
10788 output_loc_list (dw_loc_list_ref list_head
)
10790 dw_loc_list_ref curr
= list_head
;
10792 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
10794 /* Walk the location list, and output each range + expression. */
10795 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
10797 unsigned long size
;
10798 /* Don't output an entry that starts and ends at the same address. */
10799 if (strcmp (curr
->begin
, curr
->end
) == 0)
10801 if (!have_multiple_function_sections
)
10803 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
10804 "Location list begin address (%s)",
10805 list_head
->ll_symbol
);
10806 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
10807 "Location list end address (%s)",
10808 list_head
->ll_symbol
);
10812 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
10813 "Location list begin address (%s)",
10814 list_head
->ll_symbol
);
10815 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
10816 "Location list end address (%s)",
10817 list_head
->ll_symbol
);
10819 size
= size_of_locs (curr
->expr
);
10821 /* Output the block length for this list of location operations. */
10822 gcc_assert (size
<= 0xffff);
10823 dw2_asm_output_data (2, size
, "%s", "Location expression size");
10825 output_loc_sequence (curr
->expr
);
10828 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
10829 "Location list terminator begin (%s)",
10830 list_head
->ll_symbol
);
10831 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
10832 "Location list terminator end (%s)",
10833 list_head
->ll_symbol
);
10836 /* Output a type signature. */
10839 output_signature (const char *sig
, const char *name
)
10843 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
10844 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
10847 /* Output the DIE and its attributes. Called recursively to generate
10848 the definitions of each child DIE. */
10851 output_die (dw_die_ref die
)
10855 unsigned long size
;
10858 /* If someone in another CU might refer to us, set up a symbol for
10859 them to point to. */
10860 if (dwarf_version
< 4 && die
->die_id
.die_symbol
)
10861 output_die_symbol (die
);
10863 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
10864 (unsigned long)die
->die_offset
,
10865 dwarf_tag_name (die
->die_tag
));
10867 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
10869 const char *name
= dwarf_attr_name (a
->dw_attr
);
10871 switch (AT_class (a
))
10873 case dw_val_class_addr
:
10874 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
10877 case dw_val_class_offset
:
10878 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
10882 case dw_val_class_range_list
:
10884 char *p
= strchr (ranges_section_label
, '\0');
10886 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
10887 a
->dw_attr_val
.v
.val_offset
);
10888 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
10889 debug_ranges_section
, "%s", name
);
10894 case dw_val_class_loc
:
10895 size
= size_of_locs (AT_loc (a
));
10897 /* Output the block length for this list of location operations. */
10898 if (dwarf_version
>= 4)
10899 dw2_asm_output_data_uleb128 (size
, "%s", name
);
10901 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
10903 output_loc_sequence (AT_loc (a
));
10906 case dw_val_class_const
:
10907 /* ??? It would be slightly more efficient to use a scheme like is
10908 used for unsigned constants below, but gdb 4.x does not sign
10909 extend. Gdb 5.x does sign extend. */
10910 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
10913 case dw_val_class_unsigned_const
:
10914 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
10915 AT_unsigned (a
), "%s", name
);
10918 case dw_val_class_const_double
:
10920 unsigned HOST_WIDE_INT first
, second
;
10922 if (HOST_BITS_PER_WIDE_INT
>= 64)
10923 dw2_asm_output_data (1,
10924 2 * HOST_BITS_PER_WIDE_INT
10925 / HOST_BITS_PER_CHAR
,
10928 if (WORDS_BIG_ENDIAN
)
10930 first
= a
->dw_attr_val
.v
.val_double
.high
;
10931 second
= a
->dw_attr_val
.v
.val_double
.low
;
10935 first
= a
->dw_attr_val
.v
.val_double
.low
;
10936 second
= a
->dw_attr_val
.v
.val_double
.high
;
10939 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10941 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10946 case dw_val_class_vec
:
10948 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
10949 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
10953 dw2_asm_output_data (constant_size (len
* elt_size
),
10954 len
* elt_size
, "%s", name
);
10955 if (elt_size
> sizeof (HOST_WIDE_INT
))
10960 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
10962 i
++, p
+= elt_size
)
10963 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
10964 "fp or vector constant word %u", i
);
10968 case dw_val_class_flag
:
10969 if (dwarf_version
>= 4)
10971 /* Currently all add_AT_flag calls pass in 1 as last argument,
10972 so DW_FORM_flag_present can be used. If that ever changes,
10973 we'll need to use DW_FORM_flag and have some optimization
10974 in build_abbrev_table that will change those to
10975 DW_FORM_flag_present if it is set to 1 in all DIEs using
10976 the same abbrev entry. */
10977 gcc_assert (AT_flag (a
) == 1);
10978 if (flag_debug_asm
)
10979 fprintf (asm_out_file
, "\t\t\t%s %s\n",
10980 ASM_COMMENT_START
, name
);
10983 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
10986 case dw_val_class_loc_list
:
10988 char *sym
= AT_loc_list (a
)->ll_symbol
;
10991 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
10996 case dw_val_class_die_ref
:
10997 if (AT_ref_external (a
))
10999 if (dwarf_version
>= 4)
11001 comdat_type_node_ref type_node
=
11002 AT_ref (a
)->die_id
.die_type_node
;
11004 gcc_assert (type_node
);
11005 output_signature (type_node
->signature
, name
);
11009 char *sym
= AT_ref (a
)->die_id
.die_symbol
;
11013 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11014 length, whereas in DWARF3 it's always sized as an
11016 if (dwarf_version
== 2)
11017 size
= DWARF2_ADDR_SIZE
;
11019 size
= DWARF_OFFSET_SIZE
;
11020 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
11026 gcc_assert (AT_ref (a
)->die_offset
);
11027 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
11032 case dw_val_class_fde_ref
:
11036 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
11037 a
->dw_attr_val
.v
.val_fde_index
* 2);
11038 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
11043 case dw_val_class_vms_delta
:
11044 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
11045 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
11049 case dw_val_class_lbl_id
:
11050 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
11053 case dw_val_class_lineptr
:
11054 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
11055 debug_line_section
, "%s", name
);
11058 case dw_val_class_macptr
:
11059 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
11060 debug_macinfo_section
, "%s", name
);
11063 case dw_val_class_str
:
11064 if (AT_string_form (a
) == DW_FORM_strp
)
11065 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
11066 a
->dw_attr_val
.v
.val_str
->label
,
11068 "%s: \"%s\"", name
, AT_string (a
));
11070 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
11073 case dw_val_class_file
:
11075 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
11077 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
11078 a
->dw_attr_val
.v
.val_file
->filename
);
11082 case dw_val_class_data8
:
11086 for (i
= 0; i
< 8; i
++)
11087 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
11088 i
== 0 ? "%s" : NULL
, name
);
11093 gcc_unreachable ();
11097 FOR_EACH_CHILD (die
, c
, output_die (c
));
11099 /* Add null byte to terminate sibling list. */
11100 if (die
->die_child
!= NULL
)
11101 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11102 (unsigned long) die
->die_offset
);
11105 /* Output the compilation unit that appears at the beginning of the
11106 .debug_info section, and precedes the DIE descriptions. */
11109 output_compilation_unit_header (void)
11111 int ver
= dwarf_version
;
11113 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11114 dw2_asm_output_data (4, 0xffffffff,
11115 "Initial length escape value indicating 64-bit DWARF extension");
11116 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
11117 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
11118 "Length of Compilation Unit Info");
11119 dw2_asm_output_data (2, ver
, "DWARF version number");
11120 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
11121 debug_abbrev_section
,
11122 "Offset Into Abbrev. Section");
11123 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
11126 /* Output the compilation unit DIE and its children. */
11129 output_comp_unit (dw_die_ref die
, int output_if_empty
)
11131 const char *secname
;
11132 char *oldsym
, *tmp
;
11134 /* Unless we are outputting main CU, we may throw away empty ones. */
11135 if (!output_if_empty
&& die
->die_child
== NULL
)
11138 /* Even if there are no children of this DIE, we must output the information
11139 about the compilation unit. Otherwise, on an empty translation unit, we
11140 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11141 will then complain when examining the file. First mark all the DIEs in
11142 this CU so we know which get local refs. */
11145 build_abbrev_table (die
);
11147 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11148 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
11149 calc_die_sizes (die
);
11151 oldsym
= die
->die_id
.die_symbol
;
11154 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
11156 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
11158 die
->die_id
.die_symbol
= NULL
;
11159 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
11162 switch_to_section (debug_info_section
);
11164 /* Output debugging information. */
11165 output_compilation_unit_header ();
11168 /* Leave the marks on the main CU, so we can check them in
11169 output_pubnames. */
11173 die
->die_id
.die_symbol
= oldsym
;
11177 /* Output a comdat type unit DIE and its children. */
11180 output_comdat_type_unit (comdat_type_node
*node
)
11182 const char *secname
;
11185 #if defined (OBJECT_FORMAT_ELF)
11189 /* First mark all the DIEs in this CU so we know which get local refs. */
11190 mark_dies (node
->root_die
);
11192 build_abbrev_table (node
->root_die
);
11194 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11195 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
11196 calc_die_sizes (node
->root_die
);
11198 #if defined (OBJECT_FORMAT_ELF)
11199 secname
= ".debug_types";
11200 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
11201 sprintf (tmp
, "wt.");
11202 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
11203 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
11204 comdat_key
= get_identifier (tmp
);
11205 targetm
.asm_out
.named_section (secname
,
11206 SECTION_DEBUG
| SECTION_LINKONCE
,
11209 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
11210 sprintf (tmp
, ".gnu.linkonce.wt.");
11211 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
11212 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
11214 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
11217 /* Output debugging information. */
11218 output_compilation_unit_header ();
11219 output_signature (node
->signature
, "Type Signature");
11220 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
11221 "Offset to Type DIE");
11222 output_die (node
->root_die
);
11224 unmark_dies (node
->root_die
);
11227 /* Return the DWARF2/3 pubname associated with a decl. */
11229 static const char *
11230 dwarf2_name (tree decl
, int scope
)
11232 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
11235 /* Add a new entry to .debug_pubnames if appropriate. */
11238 add_pubname_string (const char *str
, dw_die_ref die
)
11243 e
.name
= xstrdup (str
);
11244 VEC_safe_push (pubname_entry
, gc
, pubname_table
, &e
);
11248 add_pubname (tree decl
, dw_die_ref die
)
11250 if (TREE_PUBLIC (decl
))
11252 const char *name
= dwarf2_name (decl
, 1);
11254 add_pubname_string (name
, die
);
11258 /* Add a new entry to .debug_pubtypes if appropriate. */
11261 add_pubtype (tree decl
, dw_die_ref die
)
11266 if ((TREE_PUBLIC (decl
)
11267 || die
->die_parent
== comp_unit_die
)
11268 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
11273 if (TYPE_NAME (decl
))
11275 if (TREE_CODE (TYPE_NAME (decl
)) == IDENTIFIER_NODE
)
11276 e
.name
= IDENTIFIER_POINTER (TYPE_NAME (decl
));
11277 else if (TREE_CODE (TYPE_NAME (decl
)) == TYPE_DECL
11278 && DECL_NAME (TYPE_NAME (decl
)))
11279 e
.name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl
)));
11281 e
.name
= xstrdup ((const char *) get_AT_string (die
, DW_AT_name
));
11286 e
.name
= dwarf2_name (decl
, 1);
11288 e
.name
= xstrdup (e
.name
);
11291 /* If we don't have a name for the type, there's no point in adding
11292 it to the table. */
11293 if (e
.name
&& e
.name
[0] != '\0')
11294 VEC_safe_push (pubname_entry
, gc
, pubtype_table
, &e
);
11298 /* Output the public names table used to speed up access to externally
11299 visible names; or the public types table used to find type definitions. */
11302 output_pubnames (VEC (pubname_entry
, gc
) * names
)
11305 unsigned long pubnames_length
= size_of_pubnames (names
);
11308 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11309 dw2_asm_output_data (4, 0xffffffff,
11310 "Initial length escape value indicating 64-bit DWARF extension");
11311 if (names
== pubname_table
)
11312 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
11313 "Length of Public Names Info");
11315 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
11316 "Length of Public Type Names Info");
11317 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
11318 dw2_asm_output_data (2, 2, "DWARF Version");
11319 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
11320 debug_info_section
,
11321 "Offset of Compilation Unit Info");
11322 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
11323 "Compilation Unit Length");
11325 for (i
= 0; VEC_iterate (pubname_entry
, names
, i
, pub
); i
++)
11327 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11328 if (names
== pubname_table
)
11329 gcc_assert (pub
->die
->die_mark
);
11331 if (names
!= pubtype_table
11332 || pub
->die
->die_offset
!= 0
11333 || !flag_eliminate_unused_debug_types
)
11335 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
11338 dw2_asm_output_nstring (pub
->name
, -1, "external name");
11342 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
11345 /* Add a new entry to .debug_aranges if appropriate. */
11348 add_arange (tree decl
, dw_die_ref die
)
11350 if (! DECL_SECTION_NAME (decl
))
11353 if (arange_table_in_use
== arange_table_allocated
)
11355 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
11356 arange_table
= GGC_RESIZEVEC (dw_die_ref
, arange_table
,
11357 arange_table_allocated
);
11358 memset (arange_table
+ arange_table_in_use
, 0,
11359 ARANGE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
11362 arange_table
[arange_table_in_use
++] = die
;
11365 /* Output the information that goes into the .debug_aranges table.
11366 Namely, define the beginning and ending address range of the
11367 text section generated for this compilation unit. */
11370 output_aranges (void)
11373 unsigned long aranges_length
= size_of_aranges ();
11375 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11376 dw2_asm_output_data (4, 0xffffffff,
11377 "Initial length escape value indicating 64-bit DWARF extension");
11378 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
11379 "Length of Address Ranges Info");
11380 /* Version number for aranges is still 2, even in DWARF3. */
11381 dw2_asm_output_data (2, 2, "DWARF Version");
11382 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
11383 debug_info_section
,
11384 "Offset of Compilation Unit Info");
11385 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
11386 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11388 /* We need to align to twice the pointer size here. */
11389 if (DWARF_ARANGES_PAD_SIZE
)
11391 /* Pad using a 2 byte words so that padding is correct for any
11393 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11394 2 * DWARF2_ADDR_SIZE
);
11395 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
11396 dw2_asm_output_data (2, 0, NULL
);
11399 /* It is necessary not to output these entries if the sections were
11400 not used; if the sections were not used, the length will be 0 and
11401 the address may end up as 0 if the section is discarded by ld
11402 --gc-sections, leaving an invalid (0, 0) entry that can be
11403 confused with the terminator. */
11404 if (text_section_used
)
11406 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
11407 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
11408 text_section_label
, "Length");
11410 if (cold_text_section_used
)
11412 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
11414 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
11415 cold_text_section_label
, "Length");
11418 for (i
= 0; i
< arange_table_in_use
; i
++)
11420 dw_die_ref die
= arange_table
[i
];
11422 /* We shouldn't see aranges for DIEs outside of the main CU. */
11423 gcc_assert (die
->die_mark
);
11425 if (die
->die_tag
== DW_TAG_subprogram
)
11427 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
11429 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
11430 get_AT_low_pc (die
), "Length");
11434 /* A static variable; extract the symbol from DW_AT_location.
11435 Note that this code isn't currently hit, as we only emit
11436 aranges for functions (jason 9/23/99). */
11437 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
11438 dw_loc_descr_ref loc
;
11440 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
11443 gcc_assert (loc
->dw_loc_opc
== DW_OP_addr
);
11445 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
11446 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
11447 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
11448 get_AT_unsigned (die
, DW_AT_byte_size
),
11453 /* Output the terminator words. */
11454 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11455 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11458 /* Add a new entry to .debug_ranges. Return the offset at which it
11461 static unsigned int
11462 add_ranges_num (int num
)
11464 unsigned int in_use
= ranges_table_in_use
;
11466 if (in_use
== ranges_table_allocated
)
11468 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
11469 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
11470 ranges_table_allocated
);
11471 memset (ranges_table
+ ranges_table_in_use
, 0,
11472 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
11475 ranges_table
[in_use
].num
= num
;
11476 ranges_table_in_use
= in_use
+ 1;
11478 return in_use
* 2 * DWARF2_ADDR_SIZE
;
11481 /* Add a new entry to .debug_ranges corresponding to a block, or a
11482 range terminator if BLOCK is NULL. */
11484 static unsigned int
11485 add_ranges (const_tree block
)
11487 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
11490 /* Add a new entry to .debug_ranges corresponding to a pair of
11494 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
11497 unsigned int in_use
= ranges_by_label_in_use
;
11498 unsigned int offset
;
11500 if (in_use
== ranges_by_label_allocated
)
11502 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
11503 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
11505 ranges_by_label_allocated
);
11506 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
11507 RANGES_TABLE_INCREMENT
11508 * sizeof (struct dw_ranges_by_label_struct
));
11511 ranges_by_label
[in_use
].begin
= begin
;
11512 ranges_by_label
[in_use
].end
= end
;
11513 ranges_by_label_in_use
= in_use
+ 1;
11515 offset
= add_ranges_num (-(int)in_use
- 1);
11518 add_AT_range_list (die
, DW_AT_ranges
, offset
);
11524 output_ranges (void)
11527 static const char *const start_fmt
= "Offset %#x";
11528 const char *fmt
= start_fmt
;
11530 for (i
= 0; i
< ranges_table_in_use
; i
++)
11532 int block_num
= ranges_table
[i
].num
;
11536 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11537 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11539 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
11540 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
11542 /* If all code is in the text section, then the compilation
11543 unit base address defaults to DW_AT_low_pc, which is the
11544 base of the text section. */
11545 if (!have_multiple_function_sections
)
11547 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
11548 text_section_label
,
11549 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11550 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
11551 text_section_label
, NULL
);
11554 /* Otherwise, the compilation unit base address is zero,
11555 which allows us to use absolute addresses, and not worry
11556 about whether the target supports cross-section
11560 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11561 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11562 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
11568 /* Negative block_num stands for an index into ranges_by_label. */
11569 else if (block_num
< 0)
11571 int lab_idx
= - block_num
- 1;
11573 if (!have_multiple_function_sections
)
11575 gcc_unreachable ();
11577 /* If we ever use add_ranges_by_labels () for a single
11578 function section, all we have to do is to take out
11579 the #if 0 above. */
11580 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11581 ranges_by_label
[lab_idx
].begin
,
11582 text_section_label
,
11583 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11584 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11585 ranges_by_label
[lab_idx
].end
,
11586 text_section_label
, NULL
);
11591 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11592 ranges_by_label
[lab_idx
].begin
,
11593 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11594 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11595 ranges_by_label
[lab_idx
].end
,
11601 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11602 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11608 /* Data structure containing information about input files. */
11611 const char *path
; /* Complete file name. */
11612 const char *fname
; /* File name part. */
11613 int length
; /* Length of entire string. */
11614 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
11615 int dir_idx
; /* Index in directory table. */
11618 /* Data structure containing information about directories with source
11622 const char *path
; /* Path including directory name. */
11623 int length
; /* Path length. */
11624 int prefix
; /* Index of directory entry which is a prefix. */
11625 int count
; /* Number of files in this directory. */
11626 int dir_idx
; /* Index of directory used as base. */
11629 /* Callback function for file_info comparison. We sort by looking at
11630 the directories in the path. */
11633 file_info_cmp (const void *p1
, const void *p2
)
11635 const struct file_info
*const s1
= (const struct file_info
*) p1
;
11636 const struct file_info
*const s2
= (const struct file_info
*) p2
;
11637 const unsigned char *cp1
;
11638 const unsigned char *cp2
;
11640 /* Take care of file names without directories. We need to make sure that
11641 we return consistent values to qsort since some will get confused if
11642 we return the same value when identical operands are passed in opposite
11643 orders. So if neither has a directory, return 0 and otherwise return
11644 1 or -1 depending on which one has the directory. */
11645 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
11646 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
11648 cp1
= (const unsigned char *) s1
->path
;
11649 cp2
= (const unsigned char *) s2
->path
;
11655 /* Reached the end of the first path? If so, handle like above. */
11656 if ((cp1
== (const unsigned char *) s1
->fname
)
11657 || (cp2
== (const unsigned char *) s2
->fname
))
11658 return ((cp2
== (const unsigned char *) s2
->fname
)
11659 - (cp1
== (const unsigned char *) s1
->fname
));
11661 /* Character of current path component the same? */
11662 else if (*cp1
!= *cp2
)
11663 return *cp1
- *cp2
;
11667 struct file_name_acquire_data
11669 struct file_info
*files
;
11674 /* Traversal function for the hash table. */
11677 file_name_acquire (void ** slot
, void *data
)
11679 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
11680 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
11681 struct file_info
*fi
;
11684 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
11686 if (! d
->emitted_number
)
11689 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
11691 fi
= fnad
->files
+ fnad
->used_files
++;
11693 /* Skip all leading "./". */
11695 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
11698 /* Create a new array entry. */
11700 fi
->length
= strlen (f
);
11703 /* Search for the file name part. */
11704 f
= strrchr (f
, DIR_SEPARATOR
);
11705 #if defined (DIR_SEPARATOR_2)
11707 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
11711 if (f
== NULL
|| f
< g
)
11717 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
11721 /* Output the directory table and the file name table. We try to minimize
11722 the total amount of memory needed. A heuristic is used to avoid large
11723 slowdowns with many input files. */
11726 output_file_names (void)
11728 struct file_name_acquire_data fnad
;
11730 struct file_info
*files
;
11731 struct dir_info
*dirs
;
11739 if (!last_emitted_file
)
11741 dw2_asm_output_data (1, 0, "End directory table");
11742 dw2_asm_output_data (1, 0, "End file name table");
11746 numfiles
= last_emitted_file
->emitted_number
;
11748 /* Allocate the various arrays we need. */
11749 files
= XALLOCAVEC (struct file_info
, numfiles
);
11750 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
11752 fnad
.files
= files
;
11753 fnad
.used_files
= 0;
11754 fnad
.max_files
= numfiles
;
11755 htab_traverse (file_table
, file_name_acquire
, &fnad
);
11756 gcc_assert (fnad
.used_files
== fnad
.max_files
);
11758 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
11760 /* Find all the different directories used. */
11761 dirs
[0].path
= files
[0].path
;
11762 dirs
[0].length
= files
[0].fname
- files
[0].path
;
11763 dirs
[0].prefix
= -1;
11765 dirs
[0].dir_idx
= 0;
11766 files
[0].dir_idx
= 0;
11769 for (i
= 1; i
< numfiles
; i
++)
11770 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
11771 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
11772 dirs
[ndirs
- 1].length
) == 0)
11774 /* Same directory as last entry. */
11775 files
[i
].dir_idx
= ndirs
- 1;
11776 ++dirs
[ndirs
- 1].count
;
11782 /* This is a new directory. */
11783 dirs
[ndirs
].path
= files
[i
].path
;
11784 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
11785 dirs
[ndirs
].count
= 1;
11786 dirs
[ndirs
].dir_idx
= ndirs
;
11787 files
[i
].dir_idx
= ndirs
;
11789 /* Search for a prefix. */
11790 dirs
[ndirs
].prefix
= -1;
11791 for (j
= 0; j
< ndirs
; j
++)
11792 if (dirs
[j
].length
< dirs
[ndirs
].length
11793 && dirs
[j
].length
> 1
11794 && (dirs
[ndirs
].prefix
== -1
11795 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
11796 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
11797 dirs
[ndirs
].prefix
= j
;
11802 /* Now to the actual work. We have to find a subset of the directories which
11803 allow expressing the file name using references to the directory table
11804 with the least amount of characters. We do not do an exhaustive search
11805 where we would have to check out every combination of every single
11806 possible prefix. Instead we use a heuristic which provides nearly optimal
11807 results in most cases and never is much off. */
11808 saved
= XALLOCAVEC (int, ndirs
);
11809 savehere
= XALLOCAVEC (int, ndirs
);
11811 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
11812 for (i
= 0; i
< ndirs
; i
++)
11817 /* We can always save some space for the current directory. But this
11818 does not mean it will be enough to justify adding the directory. */
11819 savehere
[i
] = dirs
[i
].length
;
11820 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
11822 for (j
= i
+ 1; j
< ndirs
; j
++)
11825 if (saved
[j
] < dirs
[i
].length
)
11827 /* Determine whether the dirs[i] path is a prefix of the
11831 k
= dirs
[j
].prefix
;
11832 while (k
!= -1 && k
!= (int) i
)
11833 k
= dirs
[k
].prefix
;
11837 /* Yes it is. We can possibly save some memory by
11838 writing the filenames in dirs[j] relative to
11840 savehere
[j
] = dirs
[i
].length
;
11841 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
11846 /* Check whether we can save enough to justify adding the dirs[i]
11848 if (total
> dirs
[i
].length
+ 1)
11850 /* It's worthwhile adding. */
11851 for (j
= i
; j
< ndirs
; j
++)
11852 if (savehere
[j
] > 0)
11854 /* Remember how much we saved for this directory so far. */
11855 saved
[j
] = savehere
[j
];
11857 /* Remember the prefix directory. */
11858 dirs
[j
].dir_idx
= i
;
11863 /* Emit the directory name table. */
11864 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
11865 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11866 dw2_asm_output_nstring (dirs
[i
].path
,
11868 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
11869 "Directory Entry: %#x", i
+ idx_offset
);
11871 dw2_asm_output_data (1, 0, "End directory table");
11873 /* We have to emit them in the order of emitted_number since that's
11874 used in the debug info generation. To do this efficiently we
11875 generate a back-mapping of the indices first. */
11876 backmap
= XALLOCAVEC (int, numfiles
);
11877 for (i
= 0; i
< numfiles
; i
++)
11878 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
11880 /* Now write all the file names. */
11881 for (i
= 0; i
< numfiles
; i
++)
11883 int file_idx
= backmap
[i
];
11884 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
11886 #ifdef VMS_DEBUGGING_INFO
11887 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
11889 /* Setting these fields can lead to debugger miscomparisons,
11890 but VMS Debug requires them to be set correctly. */
11895 int maxfilelen
= strlen (files
[file_idx
].path
)
11896 + dirs
[dir_idx
].length
11897 + MAX_VMS_VERSION_LEN
+ 1;
11898 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
11900 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
11901 snprintf (filebuf
, maxfilelen
, "%s;%d",
11902 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
11904 dw2_asm_output_nstring
11905 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
11907 /* Include directory index. */
11908 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
11910 /* Modification time. */
11911 dw2_asm_output_data_uleb128
11912 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
11916 /* File length in bytes. */
11917 dw2_asm_output_data_uleb128
11918 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
11922 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
11923 "File Entry: %#x", (unsigned) i
+ 1);
11925 /* Include directory index. */
11926 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
11928 /* Modification time. */
11929 dw2_asm_output_data_uleb128 (0, NULL
);
11931 /* File length in bytes. */
11932 dw2_asm_output_data_uleb128 (0, NULL
);
11936 dw2_asm_output_data (1, 0, "End file name table");
11940 /* Output the source line number correspondence information. This
11941 information goes into the .debug_line section. */
11944 output_line_info (void)
11946 char l1
[20], l2
[20], p1
[20], p2
[20];
11947 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11948 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11950 unsigned n_op_args
;
11951 unsigned long lt_index
;
11952 unsigned long current_line
;
11955 unsigned long current_file
;
11956 unsigned long function
;
11957 int ver
= dwarf_version
;
11959 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
11960 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
11961 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
11962 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
11964 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11965 dw2_asm_output_data (4, 0xffffffff,
11966 "Initial length escape value indicating 64-bit DWARF extension");
11967 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
11968 "Length of Source Line Info");
11969 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
11971 dw2_asm_output_data (2, ver
, "DWARF Version");
11972 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
11973 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
11975 /* Define the architecture-dependent minimum instruction length (in
11976 bytes). In this implementation of DWARF, this field is used for
11977 information purposes only. Since GCC generates assembly language,
11978 we have no a priori knowledge of how many instruction bytes are
11979 generated for each source line, and therefore can use only the
11980 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
11981 commands. Accordingly, we fix this as `1', which is "correct
11982 enough" for all architectures, and don't let the target override. */
11983 dw2_asm_output_data (1, 1,
11984 "Minimum Instruction Length");
11987 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
11988 "Maximum Operations Per Instruction");
11989 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
11990 "Default is_stmt_start flag");
11991 dw2_asm_output_data (1, DWARF_LINE_BASE
,
11992 "Line Base Value (Special Opcodes)");
11993 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
11994 "Line Range Value (Special Opcodes)");
11995 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
11996 "Special Opcode Base");
11998 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
12002 case DW_LNS_advance_pc
:
12003 case DW_LNS_advance_line
:
12004 case DW_LNS_set_file
:
12005 case DW_LNS_set_column
:
12006 case DW_LNS_fixed_advance_pc
:
12014 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
12018 /* Write out the information about the files we use. */
12019 output_file_names ();
12020 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
12022 /* We used to set the address register to the first location in the text
12023 section here, but that didn't accomplish anything since we already
12024 have a line note for the opening brace of the first function. */
12026 /* Generate the line number to PC correspondence table, encoded as
12027 a series of state machine operations. */
12031 if (cfun
&& in_cold_section_p
)
12032 strcpy (prev_line_label
, crtl
->subsections
.cold_section_label
);
12034 strcpy (prev_line_label
, text_section_label
);
12035 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
12037 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
12040 /* Disable this optimization for now; GDB wants to see two line notes
12041 at the beginning of a function so it can find the end of the
12044 /* Don't emit anything for redundant notes. Just updating the
12045 address doesn't accomplish anything, because we already assume
12046 that anything after the last address is this line. */
12047 if (line_info
->dw_line_num
== current_line
12048 && line_info
->dw_file_num
== current_file
)
12052 /* Emit debug info for the address of the current line.
12054 Unfortunately, we have little choice here currently, and must always
12055 use the most general form. GCC does not know the address delta
12056 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
12057 attributes which will give an upper bound on the address range. We
12058 could perhaps use length attributes to determine when it is safe to
12059 use DW_LNS_fixed_advance_pc. */
12061 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
12064 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
12065 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
12066 "DW_LNS_fixed_advance_pc");
12067 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
12071 /* This can handle any delta. This takes
12072 4+DWARF2_ADDR_SIZE bytes. */
12073 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12074 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12075 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12076 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
12079 strcpy (prev_line_label
, line_label
);
12081 /* Emit debug info for the source file of the current line, if
12082 different from the previous line. */
12083 if (line_info
->dw_file_num
!= current_file
)
12085 current_file
= line_info
->dw_file_num
;
12086 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
12087 dw2_asm_output_data_uleb128 (current_file
, "%lu", current_file
);
12090 /* Emit debug info for the current line number, choosing the encoding
12091 that uses the least amount of space. */
12092 if (line_info
->dw_line_num
!= current_line
)
12094 line_offset
= line_info
->dw_line_num
- current_line
;
12095 line_delta
= line_offset
- DWARF_LINE_BASE
;
12096 current_line
= line_info
->dw_line_num
;
12097 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
12098 /* This can handle deltas from -10 to 234, using the current
12099 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
12101 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
12102 "line %lu", current_line
);
12105 /* This can handle any delta. This takes at least 4 bytes,
12106 depending on the value being encoded. */
12107 dw2_asm_output_data (1, DW_LNS_advance_line
,
12108 "advance to line %lu", current_line
);
12109 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
12110 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
12114 /* We still need to start a new row, so output a copy insn. */
12115 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
12118 /* Emit debug info for the address of the end of the function. */
12121 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
12122 "DW_LNS_fixed_advance_pc");
12123 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
12127 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12128 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12129 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12130 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
12133 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12134 dw2_asm_output_data_uleb128 (1, NULL
);
12135 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
12140 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
12142 dw_separate_line_info_ref line_info
12143 = &separate_line_info_table
[lt_index
];
12146 /* Don't emit anything for redundant notes. */
12147 if (line_info
->dw_line_num
== current_line
12148 && line_info
->dw_file_num
== current_file
12149 && line_info
->function
== function
)
12153 /* Emit debug info for the address of the current line. If this is
12154 a new function, or the first line of a function, then we need
12155 to handle it differently. */
12156 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
12158 if (function
!= line_info
->function
)
12160 function
= line_info
->function
;
12162 /* Set the address register to the first line in the function. */
12163 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12164 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12165 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12166 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
12170 /* ??? See the DW_LNS_advance_pc comment above. */
12173 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
12174 "DW_LNS_fixed_advance_pc");
12175 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
12179 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12180 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12181 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12182 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
12186 strcpy (prev_line_label
, line_label
);
12188 /* Emit debug info for the source file of the current line, if
12189 different from the previous line. */
12190 if (line_info
->dw_file_num
!= current_file
)
12192 current_file
= line_info
->dw_file_num
;
12193 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
12194 dw2_asm_output_data_uleb128 (current_file
, "%lu", current_file
);
12197 /* Emit debug info for the current line number, choosing the encoding
12198 that uses the least amount of space. */
12199 if (line_info
->dw_line_num
!= current_line
)
12201 line_offset
= line_info
->dw_line_num
- current_line
;
12202 line_delta
= line_offset
- DWARF_LINE_BASE
;
12203 current_line
= line_info
->dw_line_num
;
12204 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
12205 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
12206 "line %lu", current_line
);
12209 dw2_asm_output_data (1, DW_LNS_advance_line
,
12210 "advance to line %lu", current_line
);
12211 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
12212 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
12216 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
12224 /* If we're done with a function, end its sequence. */
12225 if (lt_index
== separate_line_info_table_in_use
12226 || separate_line_info_table
[lt_index
].function
!= function
)
12231 /* Emit debug info for the address of the end of the function. */
12232 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
12235 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
12236 "DW_LNS_fixed_advance_pc");
12237 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
12241 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12242 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12243 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12244 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
12247 /* Output the marker for the end of this sequence. */
12248 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12249 dw2_asm_output_data_uleb128 (1, NULL
);
12250 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
12254 /* Output the marker for the end of the line number info. */
12255 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
12258 /* Return the size of the .debug_dcall table for the compilation unit. */
12260 static unsigned long
12261 size_of_dcall_table (void)
12263 unsigned long size
;
12266 tree last_poc_decl
= NULL
;
12268 /* Header: version + debug info section pointer + pointer size. */
12269 size
= 2 + DWARF_OFFSET_SIZE
+ 1;
12271 /* Each entry: code label + DIE offset. */
12272 for (i
= 0; VEC_iterate (dcall_entry
, dcall_table
, i
, p
); i
++)
12274 gcc_assert (p
->targ_die
!= NULL
);
12275 /* Insert a "from" entry when the point-of-call DIE offset changes. */
12276 if (p
->poc_decl
!= last_poc_decl
)
12278 dw_die_ref poc_die
= lookup_decl_die (p
->poc_decl
);
12279 gcc_assert (poc_die
);
12280 last_poc_decl
= p
->poc_decl
;
12282 size
+= (DWARF_OFFSET_SIZE
12283 + size_of_uleb128 (poc_die
->die_offset
));
12285 size
+= DWARF_OFFSET_SIZE
+ size_of_uleb128 (p
->targ_die
->die_offset
);
12291 /* Output the direct call table used to disambiguate PC values when
12292 identical function have been merged. */
12295 output_dcall_table (void)
12298 unsigned long dcall_length
= size_of_dcall_table ();
12300 char poc_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
12301 tree last_poc_decl
= NULL
;
12303 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
12304 dw2_asm_output_data (4, 0xffffffff,
12305 "Initial length escape value indicating 64-bit DWARF extension");
12306 dw2_asm_output_data (DWARF_OFFSET_SIZE
, dcall_length
,
12307 "Length of Direct Call Table");
12308 dw2_asm_output_data (2, 4, "Version number");
12309 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
12310 debug_info_section
,
12311 "Offset of Compilation Unit Info");
12312 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
12314 for (i
= 0; VEC_iterate (dcall_entry
, dcall_table
, i
, p
); i
++)
12316 /* Insert a "from" entry when the point-of-call DIE offset changes. */
12317 if (p
->poc_decl
!= last_poc_decl
)
12319 dw_die_ref poc_die
= lookup_decl_die (p
->poc_decl
);
12320 last_poc_decl
= p
->poc_decl
;
12323 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, "New caller");
12324 dw2_asm_output_data_uleb128 (poc_die
->die_offset
,
12325 "Caller DIE offset");
12328 ASM_GENERATE_INTERNAL_LABEL (poc_label
, "LPOC", p
->poc_label_num
);
12329 dw2_asm_output_addr (DWARF_OFFSET_SIZE
, poc_label
, "Point of call");
12330 dw2_asm_output_data_uleb128 (p
->targ_die
->die_offset
,
12331 "Callee DIE offset");
12335 /* Return the size of the .debug_vcall table for the compilation unit. */
12337 static unsigned long
12338 size_of_vcall_table (void)
12340 unsigned long size
;
12344 /* Header: version + pointer size. */
12347 /* Each entry: code label + vtable slot index. */
12348 for (i
= 0; VEC_iterate (vcall_entry
, vcall_table
, i
, p
); i
++)
12349 size
+= DWARF_OFFSET_SIZE
+ size_of_uleb128 (p
->vtable_slot
);
12354 /* Output the virtual call table used to disambiguate PC values when
12355 identical function have been merged. */
12358 output_vcall_table (void)
12361 unsigned long vcall_length
= size_of_vcall_table ();
12363 char poc_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
12365 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
12366 dw2_asm_output_data (4, 0xffffffff,
12367 "Initial length escape value indicating 64-bit DWARF extension");
12368 dw2_asm_output_data (DWARF_OFFSET_SIZE
, vcall_length
,
12369 "Length of Virtual Call Table");
12370 dw2_asm_output_data (2, 4, "Version number");
12371 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
12373 for (i
= 0; VEC_iterate (vcall_entry
, vcall_table
, i
, p
); i
++)
12375 ASM_GENERATE_INTERNAL_LABEL (poc_label
, "LPOC", p
->poc_label_num
);
12376 dw2_asm_output_addr (DWARF_OFFSET_SIZE
, poc_label
, "Point of call");
12377 dw2_asm_output_data_uleb128 (p
->vtable_slot
, "Vtable slot");
12381 /* Given a pointer to a tree node for some base type, return a pointer to
12382 a DIE that describes the given type.
12384 This routine must only be called for GCC type nodes that correspond to
12385 Dwarf base (fundamental) types. */
12388 base_type_die (tree type
)
12390 dw_die_ref base_type_result
;
12391 enum dwarf_type encoding
;
12393 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
12396 /* If this is a subtype that should not be emitted as a subrange type,
12397 use the base type. See subrange_type_for_debug_p. */
12398 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
12399 type
= TREE_TYPE (type
);
12401 switch (TREE_CODE (type
))
12404 if ((dwarf_version
>= 4 || !dwarf_strict
)
12405 && TYPE_NAME (type
)
12406 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12407 && DECL_IS_BUILTIN (TYPE_NAME (type
))
12408 && DECL_NAME (TYPE_NAME (type
)))
12410 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
12411 if (strcmp (name
, "char16_t") == 0
12412 || strcmp (name
, "char32_t") == 0)
12414 encoding
= DW_ATE_UTF
;
12418 if (TYPE_STRING_FLAG (type
))
12420 if (TYPE_UNSIGNED (type
))
12421 encoding
= DW_ATE_unsigned_char
;
12423 encoding
= DW_ATE_signed_char
;
12425 else if (TYPE_UNSIGNED (type
))
12426 encoding
= DW_ATE_unsigned
;
12428 encoding
= DW_ATE_signed
;
12432 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
12434 if (dwarf_version
>= 3 || !dwarf_strict
)
12435 encoding
= DW_ATE_decimal_float
;
12437 encoding
= DW_ATE_lo_user
;
12440 encoding
= DW_ATE_float
;
12443 case FIXED_POINT_TYPE
:
12444 if (!(dwarf_version
>= 3 || !dwarf_strict
))
12445 encoding
= DW_ATE_lo_user
;
12446 else if (TYPE_UNSIGNED (type
))
12447 encoding
= DW_ATE_unsigned_fixed
;
12449 encoding
= DW_ATE_signed_fixed
;
12452 /* Dwarf2 doesn't know anything about complex ints, so use
12453 a user defined type for it. */
12455 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
12456 encoding
= DW_ATE_complex_float
;
12458 encoding
= DW_ATE_lo_user
;
12462 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12463 encoding
= DW_ATE_boolean
;
12467 /* No other TREE_CODEs are Dwarf fundamental types. */
12468 gcc_unreachable ();
12471 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
, type
);
12473 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
12474 int_size_in_bytes (type
));
12475 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
12477 return base_type_result
;
12480 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12481 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12484 is_base_type (tree type
)
12486 switch (TREE_CODE (type
))
12492 case FIXED_POINT_TYPE
:
12500 case QUAL_UNION_TYPE
:
12501 case ENUMERAL_TYPE
:
12502 case FUNCTION_TYPE
:
12505 case REFERENCE_TYPE
:
12512 gcc_unreachable ();
12518 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12519 node, return the size in bits for the type if it is a constant, or else
12520 return the alignment for the type if the type's size is not constant, or
12521 else return BITS_PER_WORD if the type actually turns out to be an
12522 ERROR_MARK node. */
12524 static inline unsigned HOST_WIDE_INT
12525 simple_type_size_in_bits (const_tree type
)
12527 if (TREE_CODE (type
) == ERROR_MARK
)
12528 return BITS_PER_WORD
;
12529 else if (TYPE_SIZE (type
) == NULL_TREE
)
12531 else if (host_integerp (TYPE_SIZE (type
), 1))
12532 return tree_low_cst (TYPE_SIZE (type
), 1);
12534 return TYPE_ALIGN (type
);
12537 /* Similarly, but return a double_int instead of UHWI. */
12539 static inline double_int
12540 double_int_type_size_in_bits (const_tree type
)
12542 if (TREE_CODE (type
) == ERROR_MARK
)
12543 return uhwi_to_double_int (BITS_PER_WORD
);
12544 else if (TYPE_SIZE (type
) == NULL_TREE
)
12545 return double_int_zero
;
12546 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
12547 return tree_to_double_int (TYPE_SIZE (type
));
12549 return uhwi_to_double_int (TYPE_ALIGN (type
));
12552 /* Given a pointer to a tree node for a subrange type, return a pointer
12553 to a DIE that describes the given type. */
12556 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
12558 dw_die_ref subrange_die
;
12559 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
12561 if (context_die
== NULL
)
12562 context_die
= comp_unit_die
;
12564 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
12566 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
12568 /* The size of the subrange type and its base type do not match,
12569 so we need to generate a size attribute for the subrange type. */
12570 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
12574 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
12576 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
12578 return subrange_die
;
12581 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12582 entry that chains various modifiers in front of the given type. */
12585 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
12586 dw_die_ref context_die
)
12588 enum tree_code code
= TREE_CODE (type
);
12589 dw_die_ref mod_type_die
;
12590 dw_die_ref sub_die
= NULL
;
12591 tree item_type
= NULL
;
12592 tree qualified_type
;
12593 tree name
, low
, high
;
12595 if (code
== ERROR_MARK
)
12598 /* See if we already have the appropriately qualified variant of
12601 = get_qualified_type (type
,
12602 ((is_const_type
? TYPE_QUAL_CONST
: 0)
12603 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
12605 if (qualified_type
== sizetype
12606 && TYPE_NAME (qualified_type
)
12607 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
12609 #ifdef ENABLE_CHECKING
12610 gcc_assert (TREE_CODE (TREE_TYPE (TYPE_NAME (qualified_type
)))
12612 && TYPE_PRECISION (TREE_TYPE (TYPE_NAME (qualified_type
)))
12613 == TYPE_PRECISION (qualified_type
)
12614 && TYPE_UNSIGNED (TREE_TYPE (TYPE_NAME (qualified_type
)))
12615 == TYPE_UNSIGNED (qualified_type
));
12617 qualified_type
= TREE_TYPE (TYPE_NAME (qualified_type
));
12620 /* If we do, then we can just use its DIE, if it exists. */
12621 if (qualified_type
)
12623 mod_type_die
= lookup_type_die (qualified_type
);
12625 return mod_type_die
;
12628 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
12630 /* Handle C typedef types. */
12631 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
12632 && !DECL_ARTIFICIAL (name
))
12634 tree dtype
= TREE_TYPE (name
);
12636 if (qualified_type
== dtype
)
12638 /* For a named type, use the typedef. */
12639 gen_type_die (qualified_type
, context_die
);
12640 return lookup_type_die (qualified_type
);
12642 else if (is_const_type
< TYPE_READONLY (dtype
)
12643 || is_volatile_type
< TYPE_VOLATILE (dtype
)
12644 || (is_const_type
<= TYPE_READONLY (dtype
)
12645 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
12646 && DECL_ORIGINAL_TYPE (name
) != type
))
12647 /* cv-unqualified version of named type. Just use the unnamed
12648 type to which it refers. */
12649 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
12650 is_const_type
, is_volatile_type
,
12652 /* Else cv-qualified version of named type; fall through. */
12657 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
, type
);
12658 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
12660 else if (is_volatile_type
)
12662 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
, type
);
12663 sub_die
= modified_type_die (type
, 0, 0, context_die
);
12665 else if (code
== POINTER_TYPE
)
12667 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
, type
);
12668 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
12669 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
12670 item_type
= TREE_TYPE (type
);
12671 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
12672 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
12673 TYPE_ADDR_SPACE (item_type
));
12675 else if (code
== REFERENCE_TYPE
)
12677 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
12678 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, comp_unit_die
,
12681 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
, type
);
12682 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
12683 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
12684 item_type
= TREE_TYPE (type
);
12685 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
12686 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
12687 TYPE_ADDR_SPACE (item_type
));
12689 else if (code
== INTEGER_TYPE
12690 && TREE_TYPE (type
) != NULL_TREE
12691 && subrange_type_for_debug_p (type
, &low
, &high
))
12693 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
12694 item_type
= TREE_TYPE (type
);
12696 else if (is_base_type (type
))
12697 mod_type_die
= base_type_die (type
);
12700 gen_type_die (type
, context_die
);
12702 /* We have to get the type_main_variant here (and pass that to the
12703 `lookup_type_die' routine) because the ..._TYPE node we have
12704 might simply be a *copy* of some original type node (where the
12705 copy was created to help us keep track of typedef names) and
12706 that copy might have a different TYPE_UID from the original
12708 if (TREE_CODE (type
) != VECTOR_TYPE
)
12709 return lookup_type_die (type_main_variant (type
));
12711 /* Vectors have the debugging information in the type,
12712 not the main variant. */
12713 return lookup_type_die (type
);
12716 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
12717 don't output a DW_TAG_typedef, since there isn't one in the
12718 user's program; just attach a DW_AT_name to the type.
12719 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
12720 if the base type already has the same name. */
12722 && ((TREE_CODE (name
) != TYPE_DECL
12723 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
12724 || (!is_const_type
&& !is_volatile_type
)))
12725 || (TREE_CODE (name
) == TYPE_DECL
12726 && TREE_TYPE (name
) == qualified_type
12727 && DECL_NAME (name
))))
12729 if (TREE_CODE (name
) == TYPE_DECL
)
12730 /* Could just call add_name_and_src_coords_attributes here,
12731 but since this is a builtin type it doesn't have any
12732 useful source coordinates anyway. */
12733 name
= DECL_NAME (name
);
12734 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
12736 /* This probably indicates a bug. */
12737 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
12738 add_name_attribute (mod_type_die
, "__unknown__");
12740 if (qualified_type
)
12741 equate_type_number_to_die (qualified_type
, mod_type_die
);
12744 /* We must do this after the equate_type_number_to_die call, in case
12745 this is a recursive type. This ensures that the modified_type_die
12746 recursion will terminate even if the type is recursive. Recursive
12747 types are possible in Ada. */
12748 sub_die
= modified_type_die (item_type
,
12749 TYPE_READONLY (item_type
),
12750 TYPE_VOLATILE (item_type
),
12753 if (sub_die
!= NULL
)
12754 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
12756 return mod_type_die
;
12759 /* Generate DIEs for the generic parameters of T.
12760 T must be either a generic type or a generic function.
12761 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
12764 gen_generic_params_dies (tree t
)
12768 dw_die_ref die
= NULL
;
12770 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
12774 die
= lookup_type_die (t
);
12775 else if (DECL_P (t
))
12776 die
= lookup_decl_die (t
);
12780 parms
= lang_hooks
.get_innermost_generic_parms (t
);
12782 /* T has no generic parameter. It means T is neither a generic type
12783 or function. End of story. */
12786 parms_num
= TREE_VEC_LENGTH (parms
);
12787 args
= lang_hooks
.get_innermost_generic_args (t
);
12788 for (i
= 0; i
< parms_num
; i
++)
12790 tree parm
, arg
, arg_pack_elems
;
12792 parm
= TREE_VEC_ELT (parms
, i
);
12793 arg
= TREE_VEC_ELT (args
, i
);
12794 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
12795 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
12797 if (parm
&& TREE_VALUE (parm
) && arg
)
12799 /* If PARM represents a template parameter pack,
12800 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
12801 by DW_TAG_template_*_parameter DIEs for the argument
12802 pack elements of ARG. Note that ARG would then be
12803 an argument pack. */
12804 if (arg_pack_elems
)
12805 template_parameter_pack_die (TREE_VALUE (parm
),
12809 generic_parameter_die (TREE_VALUE (parm
), arg
,
12810 true /* Emit DW_AT_name */, die
);
12815 /* Create and return a DIE for PARM which should be
12816 the representation of a generic type parameter.
12817 For instance, in the C++ front end, PARM would be a template parameter.
12818 ARG is the argument to PARM.
12819 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
12821 PARENT_DIE is the parent DIE which the new created DIE should be added to,
12822 as a child node. */
12825 generic_parameter_die (tree parm
, tree arg
,
12827 dw_die_ref parent_die
)
12829 dw_die_ref tmpl_die
= NULL
;
12830 const char *name
= NULL
;
12832 if (!parm
|| !DECL_NAME (parm
) || !arg
)
12835 /* We support non-type generic parameters and arguments,
12836 type generic parameters and arguments, as well as
12837 generic generic parameters (a.k.a. template template parameters in C++)
12839 if (TREE_CODE (parm
) == PARM_DECL
)
12840 /* PARM is a nontype generic parameter */
12841 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
12842 else if (TREE_CODE (parm
) == TYPE_DECL
)
12843 /* PARM is a type generic parameter. */
12844 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
12845 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
12846 /* PARM is a generic generic parameter.
12847 Its DIE is a GNU extension. It shall have a
12848 DW_AT_name attribute to represent the name of the template template
12849 parameter, and a DW_AT_GNU_template_name attribute to represent the
12850 name of the template template argument. */
12851 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
12854 gcc_unreachable ();
12860 /* If PARM is a generic parameter pack, it means we are
12861 emitting debug info for a template argument pack element.
12862 In other terms, ARG is a template argument pack element.
12863 In that case, we don't emit any DW_AT_name attribute for
12867 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
12869 add_AT_string (tmpl_die
, DW_AT_name
, name
);
12872 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
12874 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
12875 TMPL_DIE should have a child DW_AT_type attribute that is set
12876 to the type of the argument to PARM, which is ARG.
12877 If PARM is a type generic parameter, TMPL_DIE should have a
12878 child DW_AT_type that is set to ARG. */
12879 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
12880 add_type_attribute (tmpl_die
, tmpl_type
, 0,
12881 TREE_THIS_VOLATILE (tmpl_type
),
12886 /* So TMPL_DIE is a DIE representing a
12887 a generic generic template parameter, a.k.a template template
12888 parameter in C++ and arg is a template. */
12890 /* The DW_AT_GNU_template_name attribute of the DIE must be set
12891 to the name of the argument. */
12892 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
12894 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
12897 if (TREE_CODE (parm
) == PARM_DECL
)
12898 /* So PARM is a non-type generic parameter.
12899 DWARF3 5.6.8 says we must set a DW_AT_const_value child
12900 attribute of TMPL_DIE which value represents the value
12902 We must be careful here:
12903 The value of ARG might reference some function decls.
12904 We might currently be emitting debug info for a generic
12905 type and types are emitted before function decls, we don't
12906 know if the function decls referenced by ARG will actually be
12907 emitted after cgraph computations.
12908 So must defer the generation of the DW_AT_const_value to
12909 after cgraph is ready. */
12910 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
12916 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
12917 PARM_PACK must be a template parameter pack. The returned DIE
12918 will be child DIE of PARENT_DIE. */
12921 template_parameter_pack_die (tree parm_pack
,
12922 tree parm_pack_args
,
12923 dw_die_ref parent_die
)
12928 gcc_assert (parent_die
&& parm_pack
);
12930 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
12931 add_name_and_src_coords_attributes (die
, parm_pack
);
12932 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
12933 generic_parameter_die (parm_pack
,
12934 TREE_VEC_ELT (parm_pack_args
, j
),
12935 false /* Don't emit DW_AT_name */,
12940 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
12941 an enumerated type. */
12944 type_is_enum (const_tree type
)
12946 return TREE_CODE (type
) == ENUMERAL_TYPE
;
12949 /* Return the DBX register number described by a given RTL node. */
12951 static unsigned int
12952 dbx_reg_number (const_rtx rtl
)
12954 unsigned regno
= REGNO (rtl
);
12956 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
12958 #ifdef LEAF_REG_REMAP
12959 if (current_function_uses_only_leaf_regs
)
12961 int leaf_reg
= LEAF_REG_REMAP (regno
);
12962 if (leaf_reg
!= -1)
12963 regno
= (unsigned) leaf_reg
;
12967 return DBX_REGISTER_NUMBER (regno
);
12970 /* Optionally add a DW_OP_piece term to a location description expression.
12971 DW_OP_piece is only added if the location description expression already
12972 doesn't end with DW_OP_piece. */
12975 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
12977 dw_loc_descr_ref loc
;
12979 if (*list_head
!= NULL
)
12981 /* Find the end of the chain. */
12982 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
12985 if (loc
->dw_loc_opc
!= DW_OP_piece
)
12986 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
12990 /* Return a location descriptor that designates a machine register or
12991 zero if there is none. */
12993 static dw_loc_descr_ref
12994 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
12998 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
13001 regs
= targetm
.dwarf_register_span (rtl
);
13003 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
13004 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
13006 return one_reg_loc_descriptor (dbx_reg_number (rtl
), initialized
);
13009 /* Return a location descriptor that designates a machine register for
13010 a given hard register number. */
13012 static dw_loc_descr_ref
13013 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
13015 dw_loc_descr_ref reg_loc_descr
;
13019 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
13021 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
13023 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13024 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13026 return reg_loc_descr
;
13029 /* Given an RTL of a register, return a location descriptor that
13030 designates a value that spans more than one register. */
13032 static dw_loc_descr_ref
13033 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
13034 enum var_init_status initialized
)
13036 int nregs
, size
, i
;
13038 dw_loc_descr_ref loc_result
= NULL
;
13041 #ifdef LEAF_REG_REMAP
13042 if (current_function_uses_only_leaf_regs
)
13044 int leaf_reg
= LEAF_REG_REMAP (reg
);
13045 if (leaf_reg
!= -1)
13046 reg
= (unsigned) leaf_reg
;
13049 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
13050 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
13052 /* Simple, contiguous registers. */
13053 if (regs
== NULL_RTX
)
13055 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
13060 dw_loc_descr_ref t
;
13062 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
13063 VAR_INIT_STATUS_INITIALIZED
);
13064 add_loc_descr (&loc_result
, t
);
13065 add_loc_descr_op_piece (&loc_result
, size
);
13071 /* Now onto stupid register sets in non contiguous locations. */
13073 gcc_assert (GET_CODE (regs
) == PARALLEL
);
13075 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
13078 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
13080 dw_loc_descr_ref t
;
13082 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
13083 VAR_INIT_STATUS_INITIALIZED
);
13084 add_loc_descr (&loc_result
, t
);
13085 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
13086 add_loc_descr_op_piece (&loc_result
, size
);
13089 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13090 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13094 #endif /* DWARF2_DEBUGGING_INFO */
13096 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
13098 /* Return a location descriptor that designates a constant. */
13100 static dw_loc_descr_ref
13101 int_loc_descriptor (HOST_WIDE_INT i
)
13103 enum dwarf_location_atom op
;
13105 /* Pick the smallest representation of a constant, rather than just
13106 defaulting to the LEB encoding. */
13110 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
13111 else if (i
<= 0xff)
13112 op
= DW_OP_const1u
;
13113 else if (i
<= 0xffff)
13114 op
= DW_OP_const2u
;
13115 else if (HOST_BITS_PER_WIDE_INT
== 32
13116 || i
<= 0xffffffff)
13117 op
= DW_OP_const4u
;
13124 op
= DW_OP_const1s
;
13125 else if (i
>= -0x8000)
13126 op
= DW_OP_const2s
;
13127 else if (HOST_BITS_PER_WIDE_INT
== 32
13128 || i
>= -0x80000000)
13129 op
= DW_OP_const4s
;
13134 return new_loc_descr (op
, i
, 0);
13138 #ifdef DWARF2_DEBUGGING_INFO
13139 /* Return loc description representing "address" of integer value.
13140 This can appear only as toplevel expression. */
13142 static dw_loc_descr_ref
13143 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
13146 dw_loc_descr_ref loc_result
= NULL
;
13148 if (!(dwarf_version
>= 4 || !dwarf_strict
))
13155 else if (i
<= 0xff)
13157 else if (i
<= 0xffff)
13159 else if (HOST_BITS_PER_WIDE_INT
== 32
13160 || i
<= 0xffffffff)
13163 litsize
= 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
13169 else if (i
>= -0x8000)
13171 else if (HOST_BITS_PER_WIDE_INT
== 32
13172 || i
>= -0x80000000)
13175 litsize
= 1 + size_of_sleb128 (i
);
13177 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13178 is more compact. For DW_OP_stack_value we need:
13179 litsize + 1 (DW_OP_stack_value)
13180 and for DW_OP_implicit_value:
13181 1 (DW_OP_implicit_value) + 1 (length) + size. */
13182 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
13184 loc_result
= int_loc_descriptor (i
);
13185 add_loc_descr (&loc_result
,
13186 new_loc_descr (DW_OP_stack_value
, 0, 0));
13190 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13192 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13193 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
13197 /* Return a location descriptor that designates a base+offset location. */
13199 static dw_loc_descr_ref
13200 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
13201 enum var_init_status initialized
)
13203 unsigned int regno
;
13204 dw_loc_descr_ref result
;
13205 dw_fde_ref fde
= current_fde ();
13207 /* We only use "frame base" when we're sure we're talking about the
13208 post-prologue local stack frame. We do this by *not* running
13209 register elimination until this point, and recognizing the special
13210 argument pointer and soft frame pointer rtx's. */
13211 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
13213 rtx elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
13217 if (GET_CODE (elim
) == PLUS
)
13219 offset
+= INTVAL (XEXP (elim
, 1));
13220 elim
= XEXP (elim
, 0);
13222 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13223 && (elim
== hard_frame_pointer_rtx
13224 || elim
== stack_pointer_rtx
))
13225 || elim
== (frame_pointer_needed
13226 ? hard_frame_pointer_rtx
13227 : stack_pointer_rtx
));
13229 /* If drap register is used to align stack, use frame
13230 pointer + offset to access stack variables. If stack
13231 is aligned without drap, use stack pointer + offset to
13232 access stack variables. */
13233 if (crtl
->stack_realign_tried
13234 && reg
== frame_pointer_rtx
)
13237 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
13238 ? HARD_FRAME_POINTER_REGNUM
13239 : STACK_POINTER_REGNUM
);
13240 return new_reg_loc_descr (base_reg
, offset
);
13243 offset
+= frame_pointer_fb_offset
;
13244 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
13249 && (fde
->drap_reg
== REGNO (reg
)
13250 || fde
->vdrap_reg
== REGNO (reg
)))
13252 /* Use cfa+offset to represent the location of arguments passed
13253 on the stack when drap is used to align stack.
13254 Only do this when not optimizing, for optimized code var-tracking
13255 is supposed to track where the arguments live and the register
13256 used as vdrap or drap in some spot might be used for something
13257 else in other part of the routine. */
13258 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
13261 regno
= dbx_reg_number (reg
);
13263 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
13266 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
13268 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13269 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13274 /* Return true if this RTL expression describes a base+offset calculation. */
13277 is_based_loc (const_rtx rtl
)
13279 return (GET_CODE (rtl
) == PLUS
13280 && ((REG_P (XEXP (rtl
, 0))
13281 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
13282 && CONST_INT_P (XEXP (rtl
, 1)))));
13285 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13288 static dw_loc_descr_ref
13289 tls_mem_loc_descriptor (rtx mem
)
13292 dw_loc_descr_ref loc_result
;
13294 if (MEM_EXPR (mem
) == NULL_TREE
|| MEM_OFFSET (mem
) == NULL_RTX
)
13297 base
= get_base_address (MEM_EXPR (mem
));
13299 || TREE_CODE (base
) != VAR_DECL
13300 || !DECL_THREAD_LOCAL_P (base
))
13303 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
13304 if (loc_result
== NULL
)
13307 if (INTVAL (MEM_OFFSET (mem
)))
13308 loc_descr_plus_const (&loc_result
, INTVAL (MEM_OFFSET (mem
)));
13313 /* Output debug info about reason why we failed to expand expression as dwarf
13317 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
13319 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
13321 fprintf (dump_file
, "Failed to expand as dwarf: ");
13323 print_generic_expr (dump_file
, expr
, dump_flags
);
13326 fprintf (dump_file
, "\n");
13327 print_rtl (dump_file
, rtl
);
13329 fprintf (dump_file
, "\nReason: %s\n", reason
);
13333 /* Helper function for const_ok_for_output, called either directly
13334 or via for_each_rtx. */
13337 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
13341 if (GET_CODE (rtl
) == UNSPEC
)
13343 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13344 we can't express it in the debug info. */
13345 #ifdef ENABLE_CHECKING
13346 inform (current_function_decl
13347 ? DECL_SOURCE_LOCATION (current_function_decl
)
13348 : UNKNOWN_LOCATION
,
13349 "non-delegitimized UNSPEC %d found in variable location",
13352 expansion_failed (NULL_TREE
, rtl
,
13353 "UNSPEC hasn't been delegitimized.\n");
13357 if (GET_CODE (rtl
) != SYMBOL_REF
)
13360 if (CONSTANT_POOL_ADDRESS_P (rtl
))
13363 get_pool_constant_mark (rtl
, &marked
);
13364 /* If all references to this pool constant were optimized away,
13365 it was not output and thus we can't represent it. */
13368 expansion_failed (NULL_TREE
, rtl
,
13369 "Constant was removed from constant pool.\n");
13374 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
13377 /* Avoid references to external symbols in debug info, on several targets
13378 the linker might even refuse to link when linking a shared library,
13379 and in many other cases the relocations for .debug_info/.debug_loc are
13380 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13381 to be defined within the same shared library or executable are fine. */
13382 if (SYMBOL_REF_EXTERNAL_P (rtl
))
13384 tree decl
= SYMBOL_REF_DECL (rtl
);
13386 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
13388 expansion_failed (NULL_TREE
, rtl
,
13389 "Symbol not defined in current TU.\n");
13397 /* Return true if constant RTL can be emitted in DW_OP_addr or
13398 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13399 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13402 const_ok_for_output (rtx rtl
)
13404 if (GET_CODE (rtl
) == SYMBOL_REF
)
13405 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
13407 if (GET_CODE (rtl
) == CONST
)
13408 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
13413 /* The following routine converts the RTL for a variable or parameter
13414 (resident in memory) into an equivalent Dwarf representation of a
13415 mechanism for getting the address of that same variable onto the top of a
13416 hypothetical "address evaluation" stack.
13418 When creating memory location descriptors, we are effectively transforming
13419 the RTL for a memory-resident object into its Dwarf postfix expression
13420 equivalent. This routine recursively descends an RTL tree, turning
13421 it into Dwarf postfix code as it goes.
13423 MODE is the mode of the memory reference, needed to handle some
13424 autoincrement addressing modes.
13426 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
13427 location list for RTL.
13429 Return 0 if we can't represent the location. */
13431 static dw_loc_descr_ref
13432 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
13433 enum var_init_status initialized
)
13435 dw_loc_descr_ref mem_loc_result
= NULL
;
13436 enum dwarf_location_atom op
;
13437 dw_loc_descr_ref op0
, op1
;
13439 /* Note that for a dynamically sized array, the location we will generate a
13440 description of here will be the lowest numbered location which is
13441 actually within the array. That's *not* necessarily the same as the
13442 zeroth element of the array. */
13444 rtl
= targetm
.delegitimize_address (rtl
);
13446 switch (GET_CODE (rtl
))
13451 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13454 /* The case of a subreg may arise when we have a local (register)
13455 variable or a formal (register) parameter which doesn't quite fill
13456 up an entire register. For now, just assume that it is
13457 legitimate to make the Dwarf info refer to the whole register which
13458 contains the given subreg. */
13459 if (!subreg_lowpart_p (rtl
))
13461 rtl
= SUBREG_REG (rtl
);
13462 if (GET_MODE_SIZE (GET_MODE (rtl
)) > DWARF2_ADDR_SIZE
)
13464 if (GET_MODE_CLASS (GET_MODE (rtl
)) != MODE_INT
)
13466 mem_loc_result
= mem_loc_descriptor (rtl
, mode
, initialized
);
13470 /* Whenever a register number forms a part of the description of the
13471 method for calculating the (dynamic) address of a memory resident
13472 object, DWARF rules require the register number be referred to as
13473 a "base register". This distinction is not based in any way upon
13474 what category of register the hardware believes the given register
13475 belongs to. This is strictly DWARF terminology we're dealing with
13476 here. Note that in cases where the location of a memory-resident
13477 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
13478 OP_CONST (0)) the actual DWARF location descriptor that we generate
13479 may just be OP_BASEREG (basereg). This may look deceptively like
13480 the object in question was allocated to a register (rather than in
13481 memory) so DWARF consumers need to be aware of the subtle
13482 distinction between OP_REG and OP_BASEREG. */
13483 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
13484 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
13485 else if (stack_realign_drap
13487 && crtl
->args
.internal_arg_pointer
== rtl
13488 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
13490 /* If RTL is internal_arg_pointer, which has been optimized
13491 out, use DRAP instead. */
13492 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
13493 VAR_INIT_STATUS_INITIALIZED
);
13499 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13500 VAR_INIT_STATUS_INITIALIZED
);
13505 int shift
= DWARF2_ADDR_SIZE
13506 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
13507 shift
*= BITS_PER_UNIT
;
13508 if (GET_CODE (rtl
) == SIGN_EXTEND
)
13512 mem_loc_result
= op0
;
13513 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
13514 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
13515 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
13516 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13521 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
13522 VAR_INIT_STATUS_INITIALIZED
);
13523 if (mem_loc_result
== NULL
)
13524 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
13525 if (mem_loc_result
!= 0)
13527 if (GET_MODE_SIZE (GET_MODE (rtl
)) > DWARF2_ADDR_SIZE
)
13529 expansion_failed (NULL_TREE
, rtl
, "DWARF address size mismatch");
13532 else if (GET_MODE_SIZE (GET_MODE (rtl
)) == DWARF2_ADDR_SIZE
)
13533 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
13535 add_loc_descr (&mem_loc_result
,
13536 new_loc_descr (DW_OP_deref_size
,
13537 GET_MODE_SIZE (GET_MODE (rtl
)), 0));
13541 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13542 if (new_rtl
!= rtl
)
13543 return mem_loc_descriptor (new_rtl
, mode
, initialized
);
13548 rtl
= XEXP (rtl
, 1);
13550 /* ... fall through ... */
13553 /* Some ports can transform a symbol ref into a label ref, because
13554 the symbol ref is too far away and has to be dumped into a constant
13558 if (GET_CODE (rtl
) == SYMBOL_REF
13559 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
13561 dw_loc_descr_ref temp
;
13563 /* If this is not defined, we have no way to emit the data. */
13564 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
13567 temp
= new_loc_descr (DW_OP_addr
, 0, 0);
13568 temp
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
13569 temp
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
13570 temp
->dtprel
= true;
13572 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
13573 add_loc_descr (&mem_loc_result
, temp
);
13578 if (!const_ok_for_output (rtl
))
13582 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
13583 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
13584 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
13585 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
13591 expansion_failed (NULL_TREE
, rtl
,
13592 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
13596 /* Extract the PLUS expression nested inside and fall into
13597 PLUS code below. */
13598 rtl
= XEXP (rtl
, 1);
13603 /* Turn these into a PLUS expression and fall into the PLUS code
13605 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
13606 GEN_INT (GET_CODE (rtl
) == PRE_INC
13607 ? GET_MODE_UNIT_SIZE (mode
)
13608 : -GET_MODE_UNIT_SIZE (mode
)));
13610 /* ... fall through ... */
13614 if (is_based_loc (rtl
))
13615 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
13616 INTVAL (XEXP (rtl
, 1)),
13617 VAR_INIT_STATUS_INITIALIZED
);
13620 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13621 VAR_INIT_STATUS_INITIALIZED
);
13622 if (mem_loc_result
== 0)
13625 if (CONST_INT_P (XEXP (rtl
, 1)))
13626 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
13629 dw_loc_descr_ref mem_loc_result2
13630 = mem_loc_descriptor (XEXP (rtl
, 1), mode
,
13631 VAR_INIT_STATUS_INITIALIZED
);
13632 if (mem_loc_result2
== 0)
13634 add_loc_descr (&mem_loc_result
, mem_loc_result2
);
13635 add_loc_descr (&mem_loc_result
,
13636 new_loc_descr (DW_OP_plus
, 0, 0));
13641 /* If a pseudo-reg is optimized away, it is possible for it to
13642 be replaced with a MEM containing a multiply or shift. */
13684 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13685 VAR_INIT_STATUS_INITIALIZED
);
13686 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
13687 VAR_INIT_STATUS_INITIALIZED
);
13689 if (op0
== 0 || op1
== 0)
13692 mem_loc_result
= op0
;
13693 add_loc_descr (&mem_loc_result
, op1
);
13694 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13698 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13699 VAR_INIT_STATUS_INITIALIZED
);
13700 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
13701 VAR_INIT_STATUS_INITIALIZED
);
13703 if (op0
== 0 || op1
== 0)
13706 mem_loc_result
= op0
;
13707 add_loc_descr (&mem_loc_result
, op1
);
13708 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13709 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13710 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
13711 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
13712 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
13728 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13729 VAR_INIT_STATUS_INITIALIZED
);
13734 mem_loc_result
= op0
;
13735 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13739 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
13767 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) > DWARF2_ADDR_SIZE
13768 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 1))) > DWARF2_ADDR_SIZE
)
13772 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
13774 if (op_mode
== VOIDmode
)
13775 op_mode
= GET_MODE (XEXP (rtl
, 1));
13776 if (op_mode
!= VOIDmode
&& GET_MODE_CLASS (op_mode
) != MODE_INT
)
13779 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13780 VAR_INIT_STATUS_INITIALIZED
);
13781 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
13782 VAR_INIT_STATUS_INITIALIZED
);
13784 if (op0
== 0 || op1
== 0)
13787 if (op_mode
!= VOIDmode
13788 && GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
13790 int shift
= DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
);
13791 shift
*= BITS_PER_UNIT
;
13792 /* For eq/ne, if the operands are known to be zero-extended,
13793 there is no need to do the fancy shifting up. */
13794 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
13796 dw_loc_descr_ref last0
, last1
;
13798 last0
->dw_loc_next
!= NULL
;
13799 last0
= last0
->dw_loc_next
)
13802 last1
->dw_loc_next
!= NULL
;
13803 last1
= last1
->dw_loc_next
)
13805 /* deref_size zero extends, and for constants we can check
13806 whether they are zero extended or not. */
13807 if (((last0
->dw_loc_opc
== DW_OP_deref_size
13808 && last0
->dw_loc_oprnd1
.v
.val_int
13809 <= GET_MODE_SIZE (op_mode
))
13810 || (CONST_INT_P (XEXP (rtl
, 0))
13811 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
13812 == (INTVAL (XEXP (rtl
, 0))
13813 & GET_MODE_MASK (op_mode
))))
13814 && ((last1
->dw_loc_opc
== DW_OP_deref_size
13815 && last1
->dw_loc_oprnd1
.v
.val_int
13816 <= GET_MODE_SIZE (op_mode
))
13817 || (CONST_INT_P (XEXP (rtl
, 1))
13818 && (unsigned HOST_WIDE_INT
)
13819 INTVAL (XEXP (rtl
, 1))
13820 == (INTVAL (XEXP (rtl
, 1))
13821 & GET_MODE_MASK (op_mode
)))))
13824 add_loc_descr (&op0
, int_loc_descriptor (shift
));
13825 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
13826 if (CONST_INT_P (XEXP (rtl
, 1)))
13827 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
13830 add_loc_descr (&op1
, int_loc_descriptor (shift
));
13831 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
13837 mem_loc_result
= op0
;
13838 add_loc_descr (&mem_loc_result
, op1
);
13839 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13840 if (STORE_FLAG_VALUE
!= 1)
13842 add_loc_descr (&mem_loc_result
,
13843 int_loc_descriptor (STORE_FLAG_VALUE
));
13844 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
13865 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) > DWARF2_ADDR_SIZE
13866 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 1))) > DWARF2_ADDR_SIZE
)
13870 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
13872 if (op_mode
== VOIDmode
)
13873 op_mode
= GET_MODE (XEXP (rtl
, 1));
13874 if (op_mode
!= VOIDmode
&& GET_MODE_CLASS (op_mode
) != MODE_INT
)
13877 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13878 VAR_INIT_STATUS_INITIALIZED
);
13879 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
13880 VAR_INIT_STATUS_INITIALIZED
);
13882 if (op0
== 0 || op1
== 0)
13885 if (op_mode
!= VOIDmode
13886 && GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
13888 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
13889 dw_loc_descr_ref last0
, last1
;
13891 last0
->dw_loc_next
!= NULL
;
13892 last0
= last0
->dw_loc_next
)
13895 last1
->dw_loc_next
!= NULL
;
13896 last1
= last1
->dw_loc_next
)
13898 if (CONST_INT_P (XEXP (rtl
, 0)))
13899 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
13900 /* deref_size zero extends, so no need to mask it again. */
13901 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
13902 || last0
->dw_loc_oprnd1
.v
.val_int
13903 > GET_MODE_SIZE (op_mode
))
13905 add_loc_descr (&op0
, int_loc_descriptor (mask
));
13906 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
13908 if (CONST_INT_P (XEXP (rtl
, 1)))
13909 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
13910 /* deref_size zero extends, so no need to mask it again. */
13911 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
13912 || last1
->dw_loc_oprnd1
.v
.val_int
13913 > GET_MODE_SIZE (op_mode
))
13915 add_loc_descr (&op1
, int_loc_descriptor (mask
));
13916 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
13921 HOST_WIDE_INT bias
= 1;
13922 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
13923 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
13924 if (CONST_INT_P (XEXP (rtl
, 1)))
13925 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
13926 + INTVAL (XEXP (rtl
, 1)));
13928 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
13938 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) != MODE_INT
13939 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) > DWARF2_ADDR_SIZE
13940 || GET_MODE (XEXP (rtl
, 0)) != GET_MODE (XEXP (rtl
, 1)))
13943 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
13944 VAR_INIT_STATUS_INITIALIZED
);
13945 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
13946 VAR_INIT_STATUS_INITIALIZED
);
13948 if (op0
== 0 || op1
== 0)
13951 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
13952 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
13953 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
13954 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
13956 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) < DWARF2_ADDR_SIZE
)
13958 HOST_WIDE_INT mask
= GET_MODE_MASK (GET_MODE (XEXP (rtl
, 0)));
13959 add_loc_descr (&op0
, int_loc_descriptor (mask
));
13960 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
13961 add_loc_descr (&op1
, int_loc_descriptor (mask
));
13962 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
13966 HOST_WIDE_INT bias
= 1;
13967 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
13968 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
13969 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
13972 else if (GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) < DWARF2_ADDR_SIZE
)
13974 int shift
= DWARF2_ADDR_SIZE
13975 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
13976 shift
*= BITS_PER_UNIT
;
13977 add_loc_descr (&op0
, int_loc_descriptor (shift
));
13978 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
13979 add_loc_descr (&op1
, int_loc_descriptor (shift
));
13980 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
13983 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
13987 mem_loc_result
= op0
;
13988 add_loc_descr (&mem_loc_result
, op1
);
13989 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13991 dw_loc_descr_ref bra_node
, drop_node
;
13993 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13994 add_loc_descr (&mem_loc_result
, bra_node
);
13995 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
13996 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
13997 add_loc_descr (&mem_loc_result
, drop_node
);
13998 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13999 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
14005 if (CONST_INT_P (XEXP (rtl
, 1))
14006 && CONST_INT_P (XEXP (rtl
, 2))
14007 && ((unsigned) INTVAL (XEXP (rtl
, 1))
14008 + (unsigned) INTVAL (XEXP (rtl
, 2))
14009 <= GET_MODE_BITSIZE (GET_MODE (rtl
)))
14010 && GET_MODE_BITSIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
14011 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
14014 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
14015 VAR_INIT_STATUS_INITIALIZED
);
14018 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
14022 mem_loc_result
= op0
;
14023 size
= INTVAL (XEXP (rtl
, 1));
14024 shift
= INTVAL (XEXP (rtl
, 2));
14025 if (BITS_BIG_ENDIAN
)
14026 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
14028 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
14030 add_loc_descr (&mem_loc_result
,
14031 int_loc_descriptor (DWARF2_ADDR_SIZE
14033 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
14035 if (size
!= (int) DWARF2_ADDR_SIZE
)
14037 add_loc_descr (&mem_loc_result
,
14038 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
14039 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14049 /* In theory, we could implement the above. */
14050 /* DWARF cannot represent the unsigned compare operations
14077 case FLOAT_TRUNCATE
:
14079 case UNSIGNED_FLOAT
:
14082 case FRACT_CONVERT
:
14083 case UNSIGNED_FRACT_CONVERT
:
14085 case UNSIGNED_SAT_FRACT
:
14097 case VEC_DUPLICATE
:
14100 /* If delegitimize_address couldn't do anything with the UNSPEC, we
14101 can't express it in the debug info. This can happen e.g. with some
14106 resolve_one_addr (&rtl
, NULL
);
14110 #ifdef ENABLE_CHECKING
14111 print_rtl (stderr
, rtl
);
14112 gcc_unreachable ();
14118 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14119 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14121 return mem_loc_result
;
14124 /* Return a descriptor that describes the concatenation of two locations.
14125 This is typically a complex variable. */
14127 static dw_loc_descr_ref
14128 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
14130 dw_loc_descr_ref cc_loc_result
= NULL
;
14131 dw_loc_descr_ref x0_ref
14132 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14133 dw_loc_descr_ref x1_ref
14134 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14136 if (x0_ref
== 0 || x1_ref
== 0)
14139 cc_loc_result
= x0_ref
;
14140 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
14142 add_loc_descr (&cc_loc_result
, x1_ref
);
14143 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
14145 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14146 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14148 return cc_loc_result
;
14151 /* Return a descriptor that describes the concatenation of N
14154 static dw_loc_descr_ref
14155 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
14158 dw_loc_descr_ref cc_loc_result
= NULL
;
14159 unsigned int n
= XVECLEN (concatn
, 0);
14161 for (i
= 0; i
< n
; ++i
)
14163 dw_loc_descr_ref ref
;
14164 rtx x
= XVECEXP (concatn
, 0, i
);
14166 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14170 add_loc_descr (&cc_loc_result
, ref
);
14171 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
14174 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14175 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14177 return cc_loc_result
;
14180 /* Output a proper Dwarf location descriptor for a variable or parameter
14181 which is either allocated in a register or in a memory location. For a
14182 register, we just generate an OP_REG and the register number. For a
14183 memory location we provide a Dwarf postfix expression describing how to
14184 generate the (dynamic) address of the object onto the address stack.
14186 MODE is mode of the decl if this loc_descriptor is going to be used in
14187 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
14188 allowed, VOIDmode otherwise.
14190 If we don't know how to describe it, return 0. */
14192 static dw_loc_descr_ref
14193 loc_descriptor (rtx rtl
, enum machine_mode mode
,
14194 enum var_init_status initialized
)
14196 dw_loc_descr_ref loc_result
= NULL
;
14198 switch (GET_CODE (rtl
))
14201 /* The case of a subreg may arise when we have a local (register)
14202 variable or a formal (register) parameter which doesn't quite fill
14203 up an entire register. For now, just assume that it is
14204 legitimate to make the Dwarf info refer to the whole register which
14205 contains the given subreg. */
14206 loc_result
= loc_descriptor (SUBREG_REG (rtl
), mode
, initialized
);
14210 loc_result
= reg_loc_descriptor (rtl
, initialized
);
14215 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
14219 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
14221 if (loc_result
== NULL
)
14222 loc_result
= tls_mem_loc_descriptor (rtl
);
14223 if (loc_result
== NULL
)
14225 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
14226 if (new_rtl
!= rtl
)
14227 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
14232 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
14237 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
14242 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
14244 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
14245 if (GET_CODE (loc
) == EXPR_LIST
)
14246 loc
= XEXP (loc
, 0);
14247 loc_result
= loc_descriptor (loc
, mode
, initialized
);
14251 rtl
= XEXP (rtl
, 1);
14256 rtvec par_elems
= XVEC (rtl
, 0);
14257 int num_elem
= GET_NUM_ELEM (par_elems
);
14258 enum machine_mode mode
;
14261 /* Create the first one, so we have something to add to. */
14262 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
14263 VOIDmode
, initialized
);
14264 if (loc_result
== NULL
)
14266 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
14267 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
14268 for (i
= 1; i
< num_elem
; i
++)
14270 dw_loc_descr_ref temp
;
14272 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
14273 VOIDmode
, initialized
);
14276 add_loc_descr (&loc_result
, temp
);
14277 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
14278 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
14284 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
14285 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
14290 if (mode
== VOIDmode
)
14291 mode
= GET_MODE (rtl
);
14293 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
14295 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
14297 /* Note that a CONST_DOUBLE rtx could represent either an integer
14298 or a floating-point constant. A CONST_DOUBLE is used whenever
14299 the constant requires more than one word in order to be
14300 adequately represented. We output CONST_DOUBLEs as blocks. */
14301 loc_result
= new_loc_descr (DW_OP_implicit_value
,
14302 GET_MODE_SIZE (mode
), 0);
14303 if (SCALAR_FLOAT_MODE_P (mode
))
14305 unsigned int length
= GET_MODE_SIZE (mode
);
14306 unsigned char *array
14307 = (unsigned char*) ggc_alloc_atomic (length
);
14309 insert_float (rtl
, array
);
14310 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
14311 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
14312 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
14313 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
14317 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
14318 loc_result
->dw_loc_oprnd2
.v
.val_double
14319 = rtx_to_double_int (rtl
);
14325 if (mode
== VOIDmode
)
14326 mode
= GET_MODE (rtl
);
14328 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
14330 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
14331 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
14332 unsigned char *array
= (unsigned char *)
14333 ggc_alloc_atomic (length
* elt_size
);
14337 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
14338 switch (GET_MODE_CLASS (mode
))
14340 case MODE_VECTOR_INT
:
14341 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14343 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14344 double_int val
= rtx_to_double_int (elt
);
14346 if (elt_size
<= sizeof (HOST_WIDE_INT
))
14347 insert_int (double_int_to_shwi (val
), elt_size
, p
);
14350 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
14351 insert_double (val
, p
);
14356 case MODE_VECTOR_FLOAT
:
14357 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14359 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14360 insert_float (elt
, p
);
14365 gcc_unreachable ();
14368 loc_result
= new_loc_descr (DW_OP_implicit_value
,
14369 length
* elt_size
, 0);
14370 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
14371 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
14372 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
14373 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
14378 if (mode
== VOIDmode
14379 || GET_CODE (XEXP (rtl
, 0)) == CONST_INT
14380 || GET_CODE (XEXP (rtl
, 0)) == CONST_DOUBLE
14381 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
14383 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
14388 if (!const_ok_for_output (rtl
))
14391 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
14392 && (dwarf_version
>= 4 || !dwarf_strict
))
14394 loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
14395 loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
14396 loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
14397 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14398 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
14403 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
14404 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
14405 && (dwarf_version
>= 4 || !dwarf_strict
))
14407 /* Value expression. */
14408 loc_result
= mem_loc_descriptor (rtl
, VOIDmode
, initialized
);
14410 add_loc_descr (&loc_result
,
14411 new_loc_descr (DW_OP_stack_value
, 0, 0));
14419 /* We need to figure out what section we should use as the base for the
14420 address ranges where a given location is valid.
14421 1. If this particular DECL has a section associated with it, use that.
14422 2. If this function has a section associated with it, use that.
14423 3. Otherwise, use the text section.
14424 XXX: If you split a variable across multiple sections, we won't notice. */
14426 static const char *
14427 secname_for_decl (const_tree decl
)
14429 const char *secname
;
14431 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
14433 tree sectree
= DECL_SECTION_NAME (decl
);
14434 secname
= TREE_STRING_POINTER (sectree
);
14436 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
14438 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
14439 secname
= TREE_STRING_POINTER (sectree
);
14441 else if (cfun
&& in_cold_section_p
)
14442 secname
= crtl
->subsections
.cold_section_label
;
14444 secname
= text_section_label
;
14449 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
14452 decl_by_reference_p (tree decl
)
14454 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
14455 || TREE_CODE (decl
) == VAR_DECL
)
14456 && DECL_BY_REFERENCE (decl
));
14459 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14462 static dw_loc_descr_ref
14463 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
14464 enum var_init_status initialized
)
14466 int have_address
= 0;
14467 dw_loc_descr_ref descr
;
14468 enum machine_mode mode
;
14470 if (want_address
!= 2)
14472 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
14474 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
14476 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
14477 if (GET_CODE (varloc
) == EXPR_LIST
)
14478 varloc
= XEXP (varloc
, 0);
14479 mode
= GET_MODE (varloc
);
14480 if (MEM_P (varloc
))
14482 rtx addr
= XEXP (varloc
, 0);
14483 descr
= mem_loc_descriptor (addr
, mode
, initialized
);
14488 rtx x
= avoid_constant_pool_reference (varloc
);
14490 descr
= mem_loc_descriptor (x
, mode
, initialized
);
14494 descr
= mem_loc_descriptor (varloc
, mode
, initialized
);
14501 if (GET_CODE (varloc
) == VAR_LOCATION
)
14502 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
14504 mode
= DECL_MODE (loc
);
14505 descr
= loc_descriptor (varloc
, mode
, initialized
);
14512 if (want_address
== 2 && !have_address
14513 && (dwarf_version
>= 4 || !dwarf_strict
))
14515 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14517 expansion_failed (loc
, NULL_RTX
,
14518 "DWARF address size mismatch");
14521 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14524 /* Show if we can't fill the request for an address. */
14525 if (want_address
&& !have_address
)
14527 expansion_failed (loc
, NULL_RTX
,
14528 "Want address and only have value");
14532 /* If we've got an address and don't want one, dereference. */
14533 if (!want_address
&& have_address
)
14535 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14536 enum dwarf_location_atom op
;
14538 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14540 expansion_failed (loc
, NULL_RTX
,
14541 "DWARF address size mismatch");
14544 else if (size
== DWARF2_ADDR_SIZE
)
14547 op
= DW_OP_deref_size
;
14549 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
14555 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14556 if it is not possible. */
14558 static dw_loc_descr_ref
14559 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
14561 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
14562 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
14563 else if (dwarf_version
>= 3 || !dwarf_strict
)
14564 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
14569 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14570 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14572 static dw_loc_descr_ref
14573 dw_sra_loc_expr (tree decl
, rtx loc
)
14576 unsigned int padsize
= 0;
14577 dw_loc_descr_ref descr
, *descr_tail
;
14578 unsigned HOST_WIDE_INT decl_size
;
14580 enum var_init_status initialized
;
14582 if (DECL_SIZE (decl
) == NULL
14583 || !host_integerp (DECL_SIZE (decl
), 1))
14586 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
14588 descr_tail
= &descr
;
14590 for (p
= loc
; p
; p
= XEXP (p
, 1))
14592 unsigned int bitsize
= decl_piece_bitsize (p
);
14593 rtx loc_note
= *decl_piece_varloc_ptr (p
);
14594 dw_loc_descr_ref cur_descr
;
14595 dw_loc_descr_ref
*tail
, last
= NULL
;
14596 unsigned int opsize
= 0;
14598 if (loc_note
== NULL_RTX
14599 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
14601 padsize
+= bitsize
;
14604 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
14605 varloc
= NOTE_VAR_LOCATION (loc_note
);
14606 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
14607 if (cur_descr
== NULL
)
14609 padsize
+= bitsize
;
14613 /* Check that cur_descr either doesn't use
14614 DW_OP_*piece operations, or their sum is equal
14615 to bitsize. Otherwise we can't embed it. */
14616 for (tail
= &cur_descr
; *tail
!= NULL
;
14617 tail
= &(*tail
)->dw_loc_next
)
14618 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
14620 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
14624 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
14626 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
14630 if (last
!= NULL
&& opsize
!= bitsize
)
14632 padsize
+= bitsize
;
14636 /* If there is a hole, add DW_OP_*piece after empty DWARF
14637 expression, which means that those bits are optimized out. */
14640 if (padsize
> decl_size
)
14642 decl_size
-= padsize
;
14643 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
14644 if (*descr_tail
== NULL
)
14646 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14649 *descr_tail
= cur_descr
;
14651 if (bitsize
> decl_size
)
14653 decl_size
-= bitsize
;
14656 HOST_WIDE_INT offset
= 0;
14657 if (GET_CODE (varloc
) == VAR_LOCATION
14658 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
14660 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
14661 if (GET_CODE (varloc
) == EXPR_LIST
)
14662 varloc
= XEXP (varloc
, 0);
14666 if (GET_CODE (varloc
) == CONST
14667 || GET_CODE (varloc
) == SIGN_EXTEND
14668 || GET_CODE (varloc
) == ZERO_EXTEND
)
14669 varloc
= XEXP (varloc
, 0);
14670 else if (GET_CODE (varloc
) == SUBREG
)
14671 varloc
= SUBREG_REG (varloc
);
14676 /* DW_OP_bit_size offset should be zero for register
14677 or implicit location descriptions and empty location
14678 descriptions, but for memory addresses needs big endian
14680 if (MEM_P (varloc
))
14682 unsigned HOST_WIDE_INT memsize
14683 = INTVAL (MEM_SIZE (varloc
)) * BITS_PER_UNIT
;
14684 if (memsize
!= bitsize
)
14686 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
14687 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
14689 if (memsize
< bitsize
)
14691 if (BITS_BIG_ENDIAN
)
14692 offset
= memsize
- bitsize
;
14696 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
14697 if (*descr_tail
== NULL
)
14699 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14703 /* If there were any non-empty expressions, add padding till the end of
14705 if (descr
!= NULL
&& decl_size
!= 0)
14707 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
14708 if (*descr_tail
== NULL
)
14714 /* Return the dwarf representation of the location list LOC_LIST of
14715 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
14718 static dw_loc_list_ref
14719 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
14721 const char *endname
, *secname
;
14723 enum var_init_status initialized
;
14724 struct var_loc_node
*node
;
14725 dw_loc_descr_ref descr
;
14726 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
14727 dw_loc_list_ref list
= NULL
;
14728 dw_loc_list_ref
*listp
= &list
;
14730 /* Now that we know what section we are using for a base,
14731 actually construct the list of locations.
14732 The first location information is what is passed to the
14733 function that creates the location list, and the remaining
14734 locations just get added on to that list.
14735 Note that we only know the start address for a location
14736 (IE location changes), so to build the range, we use
14737 the range [current location start, next location start].
14738 This means we have to special case the last node, and generate
14739 a range of [last location start, end of function label]. */
14741 secname
= secname_for_decl (decl
);
14743 for (node
= loc_list
->first
; node
; node
= node
->next
)
14744 if (GET_CODE (node
->loc
) == EXPR_LIST
14745 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
14747 if (GET_CODE (node
->loc
) == EXPR_LIST
)
14749 /* This requires DW_OP_{,bit_}piece, which is not usable
14750 inside DWARF expressions. */
14751 if (want_address
!= 2)
14753 descr
= dw_sra_loc_expr (decl
, node
->loc
);
14759 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
14760 varloc
= NOTE_VAR_LOCATION (node
->loc
);
14761 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
14765 /* The variable has a location between NODE->LABEL and
14766 NODE->NEXT->LABEL. */
14768 endname
= node
->next
->label
;
14769 /* If the variable has a location at the last label
14770 it keeps its location until the end of function. */
14771 else if (!current_function_decl
)
14772 endname
= text_end_label
;
14775 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
14776 current_function_funcdef_no
);
14777 endname
= ggc_strdup (label_id
);
14780 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
14781 listp
= &(*listp
)->dw_loc_next
;
14785 /* Try to avoid the overhead of a location list emitting a location
14786 expression instead, but only if we didn't have more than one
14787 location entry in the first place. If some entries were not
14788 representable, we don't want to pretend a single entry that was
14789 applies to the entire scope in which the variable is
14791 if (list
&& loc_list
->first
->next
)
14797 /* Return if the loc_list has only single element and thus can be represented
14798 as location description. */
14801 single_element_loc_list_p (dw_loc_list_ref list
)
14803 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
14804 return !list
->ll_symbol
;
14807 /* To each location in list LIST add loc descr REF. */
14810 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
14812 dw_loc_descr_ref copy
;
14813 add_loc_descr (&list
->expr
, ref
);
14814 list
= list
->dw_loc_next
;
14817 copy
= ggc_alloc_dw_loc_descr_node ();
14818 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
14819 add_loc_descr (&list
->expr
, copy
);
14820 while (copy
->dw_loc_next
)
14822 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
14823 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
14824 copy
->dw_loc_next
= new_copy
;
14827 list
= list
->dw_loc_next
;
14831 /* Given two lists RET and LIST
14832 produce location list that is result of adding expression in LIST
14833 to expression in RET on each possition in program.
14834 Might be destructive on both RET and LIST.
14836 TODO: We handle only simple cases of RET or LIST having at most one
14837 element. General case would inolve sorting the lists in program order
14838 and merging them that will need some additional work.
14839 Adding that will improve quality of debug info especially for SRA-ed
14843 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
14852 if (!list
->dw_loc_next
)
14854 add_loc_descr_to_each (*ret
, list
->expr
);
14857 if (!(*ret
)->dw_loc_next
)
14859 add_loc_descr_to_each (list
, (*ret
)->expr
);
14863 expansion_failed (NULL_TREE
, NULL_RTX
,
14864 "Don't know how to merge two non-trivial"
14865 " location lists.\n");
14870 /* LOC is constant expression. Try a luck, look it up in constant
14871 pool and return its loc_descr of its address. */
14873 static dw_loc_descr_ref
14874 cst_pool_loc_descr (tree loc
)
14876 /* Get an RTL for this, if something has been emitted. */
14877 rtx rtl
= lookup_constant_def (loc
);
14878 enum machine_mode mode
;
14880 if (!rtl
|| !MEM_P (rtl
))
14885 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
14887 /* TODO: We might get more coverage if we was actually delaying expansion
14888 of all expressions till end of compilation when constant pools are fully
14890 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
14892 expansion_failed (loc
, NULL_RTX
,
14893 "CST value in contant pool but not marked.");
14896 mode
= GET_MODE (rtl
);
14897 rtl
= XEXP (rtl
, 0);
14898 return mem_loc_descriptor (rtl
, mode
, VAR_INIT_STATUS_INITIALIZED
);
14901 /* Return dw_loc_list representing address of addr_expr LOC
14902 by looking for innder INDIRECT_REF expression and turing it
14903 into simple arithmetics. */
14905 static dw_loc_list_ref
14906 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
14909 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14910 enum machine_mode mode
;
14912 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (loc
));
14913 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14915 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
14916 &bitsize
, &bitpos
, &offset
, &mode
,
14917 &unsignedp
, &volatilep
, false);
14919 if (bitpos
% BITS_PER_UNIT
)
14921 expansion_failed (loc
, NULL_RTX
, "bitfield access");
14924 if (!INDIRECT_REF_P (obj
))
14926 expansion_failed (obj
,
14927 NULL_RTX
, "no indirect ref in inner refrence");
14930 if (!offset
&& !bitpos
)
14931 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
14933 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
14934 && (dwarf_version
>= 4 || !dwarf_strict
))
14936 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
14941 /* Variable offset. */
14942 list_ret1
= loc_list_from_tree (offset
, 0);
14943 if (list_ret1
== 0)
14945 add_loc_list (&list_ret
, list_ret1
);
14948 add_loc_descr_to_each (list_ret
,
14949 new_loc_descr (DW_OP_plus
, 0, 0));
14951 bytepos
= bitpos
/ BITS_PER_UNIT
;
14953 add_loc_descr_to_each (list_ret
,
14954 new_loc_descr (DW_OP_plus_uconst
,
14956 else if (bytepos
< 0)
14957 loc_list_plus_const (list_ret
, bytepos
);
14958 add_loc_descr_to_each (list_ret
,
14959 new_loc_descr (DW_OP_stack_value
, 0, 0));
14965 /* Generate Dwarf location list representing LOC.
14966 If WANT_ADDRESS is false, expression computing LOC will be computed
14967 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
14968 if WANT_ADDRESS is 2, expression computing address useable in location
14969 will be returned (i.e. DW_OP_reg can be used
14970 to refer to register values). */
14972 static dw_loc_list_ref
14973 loc_list_from_tree (tree loc
, int want_address
)
14975 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
14976 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14977 int have_address
= 0;
14978 enum dwarf_location_atom op
;
14980 /* ??? Most of the time we do not take proper care for sign/zero
14981 extending the values properly. Hopefully this won't be a real
14984 switch (TREE_CODE (loc
))
14987 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
14990 case PLACEHOLDER_EXPR
:
14991 /* This case involves extracting fields from an object to determine the
14992 position of other fields. We don't try to encode this here. The
14993 only user of this is Ada, which encodes the needed information using
14994 the names of types. */
14995 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
14999 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
15000 /* There are no opcodes for these operations. */
15003 case PREINCREMENT_EXPR
:
15004 case PREDECREMENT_EXPR
:
15005 case POSTINCREMENT_EXPR
:
15006 case POSTDECREMENT_EXPR
:
15007 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
15008 /* There are no opcodes for these operations. */
15012 /* If we already want an address, see if there is INDIRECT_REF inside
15013 e.g. for &this->field. */
15016 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
15017 (loc
, want_address
== 2);
15020 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
15021 && (ret
= cst_pool_loc_descr (loc
)))
15024 /* Otherwise, process the argument and look for the address. */
15025 if (!list_ret
&& !ret
)
15026 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
15030 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
15036 if (DECL_THREAD_LOCAL_P (loc
))
15039 enum dwarf_location_atom first_op
;
15040 enum dwarf_location_atom second_op
;
15041 bool dtprel
= false;
15043 if (targetm
.have_tls
)
15045 /* If this is not defined, we have no way to emit the
15047 if (!targetm
.asm_out
.output_dwarf_dtprel
)
15050 /* The way DW_OP_GNU_push_tls_address is specified, we
15051 can only look up addresses of objects in the current
15053 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
15055 first_op
= DW_OP_addr
;
15057 second_op
= DW_OP_GNU_push_tls_address
;
15061 if (!targetm
.emutls
.debug_form_tls_address
15062 || !(dwarf_version
>= 3 || !dwarf_strict
))
15064 loc
= emutls_decl (loc
);
15065 first_op
= DW_OP_addr
;
15066 second_op
= DW_OP_form_tls_address
;
15069 rtl
= rtl_for_decl_location (loc
);
15070 if (rtl
== NULL_RTX
)
15075 rtl
= XEXP (rtl
, 0);
15076 if (! CONSTANT_P (rtl
))
15079 ret
= new_loc_descr (first_op
, 0, 0);
15080 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
15081 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
15082 ret
->dtprel
= dtprel
;
15084 ret1
= new_loc_descr (second_op
, 0, 0);
15085 add_loc_descr (&ret
, ret1
);
15093 if (DECL_HAS_VALUE_EXPR_P (loc
))
15094 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
15099 case FUNCTION_DECL
:
15102 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
15104 if (loc_list
&& loc_list
->first
)
15106 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
15107 have_address
= want_address
!= 0;
15110 rtl
= rtl_for_decl_location (loc
);
15111 if (rtl
== NULL_RTX
)
15113 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
15116 else if (CONST_INT_P (rtl
))
15118 HOST_WIDE_INT val
= INTVAL (rtl
);
15119 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
15120 val
&= GET_MODE_MASK (DECL_MODE (loc
));
15121 ret
= int_loc_descriptor (val
);
15123 else if (GET_CODE (rtl
) == CONST_STRING
)
15125 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
15128 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
15130 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
15131 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
15132 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
15136 enum machine_mode mode
;
15138 /* Certain constructs can only be represented at top-level. */
15139 if (want_address
== 2)
15141 ret
= loc_descriptor (rtl
, VOIDmode
,
15142 VAR_INIT_STATUS_INITIALIZED
);
15147 mode
= GET_MODE (rtl
);
15150 rtl
= XEXP (rtl
, 0);
15153 ret
= mem_loc_descriptor (rtl
, mode
, VAR_INIT_STATUS_INITIALIZED
);
15156 expansion_failed (loc
, rtl
,
15157 "failed to produce loc descriptor for rtl");
15163 case ALIGN_INDIRECT_REF
:
15164 case MISALIGNED_INDIRECT_REF
:
15165 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15169 case COMPOUND_EXPR
:
15170 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
15173 case VIEW_CONVERT_EXPR
:
15176 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
15178 case COMPONENT_REF
:
15179 case BIT_FIELD_REF
:
15181 case ARRAY_RANGE_REF
:
15182 case REALPART_EXPR
:
15183 case IMAGPART_EXPR
:
15186 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
15187 enum machine_mode mode
;
15189 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (loc
));
15191 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
15192 &unsignedp
, &volatilep
, false);
15194 gcc_assert (obj
!= loc
);
15196 list_ret
= loc_list_from_tree (obj
,
15198 && !bitpos
&& !offset
? 2 : 1);
15199 /* TODO: We can extract value of the small expression via shifting even
15200 for nonzero bitpos. */
15203 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
15205 expansion_failed (loc
, NULL_RTX
,
15206 "bitfield access");
15210 if (offset
!= NULL_TREE
)
15212 /* Variable offset. */
15213 list_ret1
= loc_list_from_tree (offset
, 0);
15214 if (list_ret1
== 0)
15216 add_loc_list (&list_ret
, list_ret1
);
15219 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
15222 bytepos
= bitpos
/ BITS_PER_UNIT
;
15224 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
15225 else if (bytepos
< 0)
15226 loc_list_plus_const (list_ret
, bytepos
);
15233 if ((want_address
|| !host_integerp (loc
, 0))
15234 && (ret
= cst_pool_loc_descr (loc
)))
15236 else if (want_address
== 2
15237 && host_integerp (loc
, 0)
15238 && (ret
= address_of_int_loc_descriptor
15239 (int_size_in_bytes (TREE_TYPE (loc
)),
15240 tree_low_cst (loc
, 0))))
15242 else if (host_integerp (loc
, 0))
15243 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
15246 expansion_failed (loc
, NULL_RTX
,
15247 "Integer operand is not host integer");
15256 if ((ret
= cst_pool_loc_descr (loc
)))
15259 /* We can construct small constants here using int_loc_descriptor. */
15260 expansion_failed (loc
, NULL_RTX
,
15261 "constructor or constant not in constant pool");
15264 case TRUTH_AND_EXPR
:
15265 case TRUTH_ANDIF_EXPR
:
15270 case TRUTH_XOR_EXPR
:
15275 case TRUTH_OR_EXPR
:
15276 case TRUTH_ORIF_EXPR
:
15281 case FLOOR_DIV_EXPR
:
15282 case CEIL_DIV_EXPR
:
15283 case ROUND_DIV_EXPR
:
15284 case TRUNC_DIV_EXPR
:
15285 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
15294 case FLOOR_MOD_EXPR
:
15295 case CEIL_MOD_EXPR
:
15296 case ROUND_MOD_EXPR
:
15297 case TRUNC_MOD_EXPR
:
15298 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
15303 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15304 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
15305 if (list_ret
== 0 || list_ret1
== 0)
15308 add_loc_list (&list_ret
, list_ret1
);
15311 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
15312 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
15313 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
15314 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
15315 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
15327 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
15330 case POINTER_PLUS_EXPR
:
15332 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
15334 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15338 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
15346 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
15353 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
15360 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
15367 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
15382 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15383 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
15384 if (list_ret
== 0 || list_ret1
== 0)
15387 add_loc_list (&list_ret
, list_ret1
);
15390 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
15393 case TRUTH_NOT_EXPR
:
15407 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15411 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
15417 const enum tree_code code
=
15418 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
15420 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
15421 build2 (code
, integer_type_node
,
15422 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
15423 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
15426 /* ... fall through ... */
15430 dw_loc_descr_ref lhs
15431 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
15432 dw_loc_list_ref rhs
15433 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
15434 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
15436 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
15437 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
15440 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
15441 add_loc_descr_to_each (list_ret
, bra_node
);
15443 add_loc_list (&list_ret
, rhs
);
15444 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
15445 add_loc_descr_to_each (list_ret
, jump_node
);
15447 add_loc_descr_to_each (list_ret
, lhs
);
15448 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15449 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
15451 /* ??? Need a node to point the skip at. Use a nop. */
15452 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
15453 add_loc_descr_to_each (list_ret
, tmp
);
15454 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15455 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
15459 case FIX_TRUNC_EXPR
:
15463 /* Leave front-end specific codes as simply unknown. This comes
15464 up, for instance, with the C STMT_EXPR. */
15465 if ((unsigned int) TREE_CODE (loc
)
15466 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
15468 expansion_failed (loc
, NULL_RTX
,
15469 "language specific tree node");
15473 #ifdef ENABLE_CHECKING
15474 /* Otherwise this is a generic code; we should just lists all of
15475 these explicitly. We forgot one. */
15476 gcc_unreachable ();
15478 /* In a release build, we want to degrade gracefully: better to
15479 generate incomplete debugging information than to crash. */
15484 if (!ret
&& !list_ret
)
15487 if (want_address
== 2 && !have_address
15488 && (dwarf_version
>= 4 || !dwarf_strict
))
15490 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
15492 expansion_failed (loc
, NULL_RTX
,
15493 "DWARF address size mismatch");
15497 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15499 add_loc_descr_to_each (list_ret
,
15500 new_loc_descr (DW_OP_stack_value
, 0, 0));
15503 /* Show if we can't fill the request for an address. */
15504 if (want_address
&& !have_address
)
15506 expansion_failed (loc
, NULL_RTX
,
15507 "Want address and only have value");
15511 gcc_assert (!ret
|| !list_ret
);
15513 /* If we've got an address and don't want one, dereference. */
15514 if (!want_address
&& have_address
)
15516 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
15518 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
15520 expansion_failed (loc
, NULL_RTX
,
15521 "DWARF address size mismatch");
15524 else if (size
== DWARF2_ADDR_SIZE
)
15527 op
= DW_OP_deref_size
;
15530 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
15532 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
15535 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
15540 /* Same as above but return only single location expression. */
15541 static dw_loc_descr_ref
15542 loc_descriptor_from_tree (tree loc
, int want_address
)
15544 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
15547 if (ret
->dw_loc_next
)
15549 expansion_failed (loc
, NULL_RTX
,
15550 "Location list where only loc descriptor needed");
15556 /* Given a value, round it up to the lowest multiple of `boundary'
15557 which is not less than the value itself. */
15559 static inline HOST_WIDE_INT
15560 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
15562 return (((value
+ boundary
- 1) / boundary
) * boundary
);
15565 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
15566 pointer to the declared type for the relevant field variable, or return
15567 `integer_type_node' if the given node turns out to be an
15568 ERROR_MARK node. */
15571 field_type (const_tree decl
)
15575 if (TREE_CODE (decl
) == ERROR_MARK
)
15576 return integer_type_node
;
15578 type
= DECL_BIT_FIELD_TYPE (decl
);
15579 if (type
== NULL_TREE
)
15580 type
= TREE_TYPE (decl
);
15585 /* Given a pointer to a tree node, return the alignment in bits for
15586 it, or else return BITS_PER_WORD if the node actually turns out to
15587 be an ERROR_MARK node. */
15589 static inline unsigned
15590 simple_type_align_in_bits (const_tree type
)
15592 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
15595 static inline unsigned
15596 simple_decl_align_in_bits (const_tree decl
)
15598 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
15601 /* Return the result of rounding T up to ALIGN. */
15603 static inline double_int
15604 round_up_to_align (double_int t
, unsigned int align
)
15606 double_int alignd
= uhwi_to_double_int (align
);
15607 t
= double_int_add (t
, alignd
);
15608 t
= double_int_add (t
, double_int_minus_one
);
15609 t
= double_int_div (t
, alignd
, true, TRUNC_DIV_EXPR
);
15610 t
= double_int_mul (t
, alignd
);
15614 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
15615 lowest addressed byte of the "containing object" for the given FIELD_DECL,
15616 or return 0 if we are unable to determine what that offset is, either
15617 because the argument turns out to be a pointer to an ERROR_MARK node, or
15618 because the offset is actually variable. (We can't handle the latter case
15621 static HOST_WIDE_INT
15622 field_byte_offset (const_tree decl
)
15624 double_int object_offset_in_bits
;
15625 double_int object_offset_in_bytes
;
15626 double_int bitpos_int
;
15628 if (TREE_CODE (decl
) == ERROR_MARK
)
15631 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
15633 /* We cannot yet cope with fields whose positions are variable, so
15634 for now, when we see such things, we simply return 0. Someday, we may
15635 be able to handle such cases, but it will be damn difficult. */
15636 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
15639 bitpos_int
= tree_to_double_int (bit_position (decl
));
15641 #ifdef PCC_BITFIELD_TYPE_MATTERS
15642 if (PCC_BITFIELD_TYPE_MATTERS
)
15645 tree field_size_tree
;
15646 double_int deepest_bitpos
;
15647 double_int field_size_in_bits
;
15648 unsigned int type_align_in_bits
;
15649 unsigned int decl_align_in_bits
;
15650 double_int type_size_in_bits
;
15652 type
= field_type (decl
);
15653 type_size_in_bits
= double_int_type_size_in_bits (type
);
15654 type_align_in_bits
= simple_type_align_in_bits (type
);
15656 field_size_tree
= DECL_SIZE (decl
);
15658 /* The size could be unspecified if there was an error, or for
15659 a flexible array member. */
15660 if (!field_size_tree
)
15661 field_size_tree
= bitsize_zero_node
;
15663 /* If the size of the field is not constant, use the type size. */
15664 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
15665 field_size_in_bits
= tree_to_double_int (field_size_tree
);
15667 field_size_in_bits
= type_size_in_bits
;
15669 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
15671 /* The GCC front-end doesn't make any attempt to keep track of the
15672 starting bit offset (relative to the start of the containing
15673 structure type) of the hypothetical "containing object" for a
15674 bit-field. Thus, when computing the byte offset value for the
15675 start of the "containing object" of a bit-field, we must deduce
15676 this information on our own. This can be rather tricky to do in
15677 some cases. For example, handling the following structure type
15678 definition when compiling for an i386/i486 target (which only
15679 aligns long long's to 32-bit boundaries) can be very tricky:
15681 struct S { int field1; long long field2:31; };
15683 Fortunately, there is a simple rule-of-thumb which can be used
15684 in such cases. When compiling for an i386/i486, GCC will
15685 allocate 8 bytes for the structure shown above. It decides to
15686 do this based upon one simple rule for bit-field allocation.
15687 GCC allocates each "containing object" for each bit-field at
15688 the first (i.e. lowest addressed) legitimate alignment boundary
15689 (based upon the required minimum alignment for the declared
15690 type of the field) which it can possibly use, subject to the
15691 condition that there is still enough available space remaining
15692 in the containing object (when allocated at the selected point)
15693 to fully accommodate all of the bits of the bit-field itself.
15695 This simple rule makes it obvious why GCC allocates 8 bytes for
15696 each object of the structure type shown above. When looking
15697 for a place to allocate the "containing object" for `field2',
15698 the compiler simply tries to allocate a 64-bit "containing
15699 object" at each successive 32-bit boundary (starting at zero)
15700 until it finds a place to allocate that 64- bit field such that
15701 at least 31 contiguous (and previously unallocated) bits remain
15702 within that selected 64 bit field. (As it turns out, for the
15703 example above, the compiler finds it is OK to allocate the
15704 "containing object" 64-bit field at bit-offset zero within the
15707 Here we attempt to work backwards from the limited set of facts
15708 we're given, and we try to deduce from those facts, where GCC
15709 must have believed that the containing object started (within
15710 the structure type). The value we deduce is then used (by the
15711 callers of this routine) to generate DW_AT_location and
15712 DW_AT_bit_offset attributes for fields (both bit-fields and, in
15713 the case of DW_AT_location, regular fields as well). */
15715 /* Figure out the bit-distance from the start of the structure to
15716 the "deepest" bit of the bit-field. */
15717 deepest_bitpos
= double_int_add (bitpos_int
, field_size_in_bits
);
15719 /* This is the tricky part. Use some fancy footwork to deduce
15720 where the lowest addressed bit of the containing object must
15722 object_offset_in_bits
15723 = double_int_add (deepest_bitpos
, double_int_neg (type_size_in_bits
));
15725 /* Round up to type_align by default. This works best for
15727 object_offset_in_bits
15728 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
15730 if (double_int_ucmp (object_offset_in_bits
, bitpos_int
) > 0)
15732 object_offset_in_bits
15733 = double_int_add (deepest_bitpos
,
15734 double_int_neg (type_size_in_bits
));
15736 /* Round up to decl_align instead. */
15737 object_offset_in_bits
15738 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
15743 object_offset_in_bits
= bitpos_int
;
15745 object_offset_in_bytes
15746 = double_int_div (object_offset_in_bits
,
15747 uhwi_to_double_int (BITS_PER_UNIT
), true,
15749 return double_int_to_shwi (object_offset_in_bytes
);
15752 /* The following routines define various Dwarf attributes and any data
15753 associated with them. */
15755 /* Add a location description attribute value to a DIE.
15757 This emits location attributes suitable for whole variables and
15758 whole parameters. Note that the location attributes for struct fields are
15759 generated by the routine `data_member_location_attribute' below. */
15762 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
15763 dw_loc_list_ref descr
)
15767 if (single_element_loc_list_p (descr
))
15768 add_AT_loc (die
, attr_kind
, descr
->expr
);
15770 add_AT_loc_list (die
, attr_kind
, descr
);
15773 /* Attach the specialized form of location attribute used for data members of
15774 struct and union types. In the special case of a FIELD_DECL node which
15775 represents a bit-field, the "offset" part of this special location
15776 descriptor must indicate the distance in bytes from the lowest-addressed
15777 byte of the containing struct or union type to the lowest-addressed byte of
15778 the "containing object" for the bit-field. (See the `field_byte_offset'
15781 For any given bit-field, the "containing object" is a hypothetical object
15782 (of some integral or enum type) within which the given bit-field lives. The
15783 type of this hypothetical "containing object" is always the same as the
15784 declared type of the individual bit-field itself (for GCC anyway... the
15785 DWARF spec doesn't actually mandate this). Note that it is the size (in
15786 bytes) of the hypothetical "containing object" which will be given in the
15787 DW_AT_byte_size attribute for this bit-field. (See the
15788 `byte_size_attribute' function below.) It is also used when calculating the
15789 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
15790 function below.) */
15793 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
15795 HOST_WIDE_INT offset
;
15796 dw_loc_descr_ref loc_descr
= 0;
15798 if (TREE_CODE (decl
) == TREE_BINFO
)
15800 /* We're working on the TAG_inheritance for a base class. */
15801 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
15803 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
15804 aren't at a fixed offset from all (sub)objects of the same
15805 type. We need to extract the appropriate offset from our
15806 vtable. The following dwarf expression means
15808 BaseAddr = ObAddr + *((*ObAddr) - Offset)
15810 This is specific to the V3 ABI, of course. */
15812 dw_loc_descr_ref tmp
;
15814 /* Make a copy of the object address. */
15815 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
15816 add_loc_descr (&loc_descr
, tmp
);
15818 /* Extract the vtable address. */
15819 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
15820 add_loc_descr (&loc_descr
, tmp
);
15822 /* Calculate the address of the offset. */
15823 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
15824 gcc_assert (offset
< 0);
15826 tmp
= int_loc_descriptor (-offset
);
15827 add_loc_descr (&loc_descr
, tmp
);
15828 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
15829 add_loc_descr (&loc_descr
, tmp
);
15831 /* Extract the offset. */
15832 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
15833 add_loc_descr (&loc_descr
, tmp
);
15835 /* Add it to the object address. */
15836 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
15837 add_loc_descr (&loc_descr
, tmp
);
15840 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
15843 offset
= field_byte_offset (decl
);
15847 if (dwarf_version
> 2)
15849 /* Don't need to output a location expression, just the constant. */
15850 add_AT_int (die
, DW_AT_data_member_location
, offset
);
15855 enum dwarf_location_atom op
;
15857 /* The DWARF2 standard says that we should assume that the structure
15858 address is already on the stack, so we can specify a structure
15859 field address by using DW_OP_plus_uconst. */
15861 #ifdef MIPS_DEBUGGING_INFO
15862 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
15863 operator correctly. It works only if we leave the offset on the
15867 op
= DW_OP_plus_uconst
;
15870 loc_descr
= new_loc_descr (op
, offset
, 0);
15874 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
15877 /* Writes integer values to dw_vec_const array. */
15880 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
15884 *dest
++ = val
& 0xff;
15890 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
15892 static HOST_WIDE_INT
15893 extract_int (const unsigned char *src
, unsigned int size
)
15895 HOST_WIDE_INT val
= 0;
15901 val
|= *--src
& 0xff;
15907 /* Writes double_int values to dw_vec_const array. */
15910 insert_double (double_int val
, unsigned char *dest
)
15912 unsigned char *p0
= dest
;
15913 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
15915 if (WORDS_BIG_ENDIAN
)
15921 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
15922 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
15925 /* Writes floating point values to dw_vec_const array. */
15928 insert_float (const_rtx rtl
, unsigned char *array
)
15930 REAL_VALUE_TYPE rv
;
15934 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
15935 real_to_target (val
, &rv
, GET_MODE (rtl
));
15937 /* real_to_target puts 32-bit pieces in each long. Pack them. */
15938 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
15940 insert_int (val
[i
], 4, array
);
15945 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
15946 does not have a "location" either in memory or in a register. These
15947 things can arise in GNU C when a constant is passed as an actual parameter
15948 to an inlined function. They can also arise in C++ where declared
15949 constants do not necessarily get memory "homes". */
15952 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
15954 switch (GET_CODE (rtl
))
15958 HOST_WIDE_INT val
= INTVAL (rtl
);
15961 add_AT_int (die
, DW_AT_const_value
, val
);
15963 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
15968 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
15969 floating-point constant. A CONST_DOUBLE is used whenever the
15970 constant requires more than one word in order to be adequately
15973 enum machine_mode mode
= GET_MODE (rtl
);
15975 if (SCALAR_FLOAT_MODE_P (mode
))
15977 unsigned int length
= GET_MODE_SIZE (mode
);
15978 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
15980 insert_float (rtl
, array
);
15981 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
15984 add_AT_double (die
, DW_AT_const_value
,
15985 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
15991 enum machine_mode mode
= GET_MODE (rtl
);
15992 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
15993 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15994 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
15995 (length
* elt_size
);
15999 switch (GET_MODE_CLASS (mode
))
16001 case MODE_VECTOR_INT
:
16002 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
16004 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
16005 double_int val
= rtx_to_double_int (elt
);
16007 if (elt_size
<= sizeof (HOST_WIDE_INT
))
16008 insert_int (double_int_to_shwi (val
), elt_size
, p
);
16011 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
16012 insert_double (val
, p
);
16017 case MODE_VECTOR_FLOAT
:
16018 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
16020 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
16021 insert_float (elt
, p
);
16026 gcc_unreachable ();
16029 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
16034 if (dwarf_version
>= 4 || !dwarf_strict
)
16036 dw_loc_descr_ref loc_result
;
16037 resolve_one_addr (&rtl
, NULL
);
16039 loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
16040 loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
16041 loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
16042 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
16043 add_AT_loc (die
, DW_AT_location
, loc_result
);
16044 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
16050 if (CONSTANT_P (XEXP (rtl
, 0)))
16051 return add_const_value_attribute (die
, XEXP (rtl
, 0));
16054 if (!const_ok_for_output (rtl
))
16057 if (dwarf_version
>= 4 || !dwarf_strict
)
16062 /* In cases where an inlined instance of an inline function is passed
16063 the address of an `auto' variable (which is local to the caller) we
16064 can get a situation where the DECL_RTL of the artificial local
16065 variable (for the inlining) which acts as a stand-in for the
16066 corresponding formal parameter (of the inline function) will look
16067 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
16068 exactly a compile-time constant expression, but it isn't the address
16069 of the (artificial) local variable either. Rather, it represents the
16070 *value* which the artificial local variable always has during its
16071 lifetime. We currently have no way to represent such quasi-constant
16072 values in Dwarf, so for now we just punt and generate nothing. */
16080 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
16081 && MEM_READONLY_P (rtl
)
16082 && GET_MODE (rtl
) == BLKmode
)
16084 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
16090 /* No other kinds of rtx should be possible here. */
16091 gcc_unreachable ();
16096 /* Determine whether the evaluation of EXPR references any variables
16097 or functions which aren't otherwise used (and therefore may not be
16100 reference_to_unused (tree
* tp
, int * walk_subtrees
,
16101 void * data ATTRIBUTE_UNUSED
)
16103 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
16104 *walk_subtrees
= 0;
16106 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
16107 && ! TREE_ASM_WRITTEN (*tp
))
16109 /* ??? The C++ FE emits debug information for using decls, so
16110 putting gcc_unreachable here falls over. See PR31899. For now
16111 be conservative. */
16112 else if (!cgraph_global_info_ready
16113 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
16115 else if (TREE_CODE (*tp
) == VAR_DECL
)
16117 struct varpool_node
*node
= varpool_get_node (*tp
);
16118 if (!node
|| !node
->needed
)
16121 else if (TREE_CODE (*tp
) == FUNCTION_DECL
16122 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
16124 /* The call graph machinery must have finished analyzing,
16125 optimizing and gimplifying the CU by now.
16126 So if *TP has no call graph node associated
16127 to it, it means *TP will not be emitted. */
16128 if (!cgraph_get_node (*tp
))
16131 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
16137 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
16138 for use in a later add_const_value_attribute call. */
16141 rtl_for_decl_init (tree init
, tree type
)
16143 rtx rtl
= NULL_RTX
;
16145 /* If a variable is initialized with a string constant without embedded
16146 zeros, build CONST_STRING. */
16147 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
16149 tree enttype
= TREE_TYPE (type
);
16150 tree domain
= TYPE_DOMAIN (type
);
16151 enum machine_mode mode
= TYPE_MODE (enttype
);
16153 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
16155 && integer_zerop (TYPE_MIN_VALUE (domain
))
16156 && compare_tree_int (TYPE_MAX_VALUE (domain
),
16157 TREE_STRING_LENGTH (init
) - 1) == 0
16158 && ((size_t) TREE_STRING_LENGTH (init
)
16159 == strlen (TREE_STRING_POINTER (init
)) + 1))
16161 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
16162 ggc_strdup (TREE_STRING_POINTER (init
)));
16163 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
16164 MEM_READONLY_P (rtl
) = 1;
16167 /* Other aggregates, and complex values, could be represented using
16169 else if (AGGREGATE_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
16171 /* Vectors only work if their mode is supported by the target.
16172 FIXME: generic vectors ought to work too. */
16173 else if (TREE_CODE (type
) == VECTOR_TYPE
&& TYPE_MODE (type
) == BLKmode
)
16175 /* If the initializer is something that we know will expand into an
16176 immediate RTL constant, expand it now. We must be careful not to
16177 reference variables which won't be output. */
16178 else if (initializer_constant_valid_p (init
, type
)
16179 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
16181 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
16183 if (TREE_CODE (type
) == VECTOR_TYPE
)
16184 switch (TREE_CODE (init
))
16189 if (TREE_CONSTANT (init
))
16191 VEC(constructor_elt
,gc
) *elts
= CONSTRUCTOR_ELTS (init
);
16192 bool constant_p
= true;
16194 unsigned HOST_WIDE_INT ix
;
16196 /* Even when ctor is constant, it might contain non-*_CST
16197 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
16198 belong into VECTOR_CST nodes. */
16199 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
16200 if (!CONSTANT_CLASS_P (value
))
16202 constant_p
= false;
16208 init
= build_vector_from_ctor (type
, elts
);
16218 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
16220 /* If expand_expr returns a MEM, it wasn't immediate. */
16221 gcc_assert (!rtl
|| !MEM_P (rtl
));
16227 /* Generate RTL for the variable DECL to represent its location. */
16230 rtl_for_decl_location (tree decl
)
16234 /* Here we have to decide where we are going to say the parameter "lives"
16235 (as far as the debugger is concerned). We only have a couple of
16236 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
16238 DECL_RTL normally indicates where the parameter lives during most of the
16239 activation of the function. If optimization is enabled however, this
16240 could be either NULL or else a pseudo-reg. Both of those cases indicate
16241 that the parameter doesn't really live anywhere (as far as the code
16242 generation parts of GCC are concerned) during most of the function's
16243 activation. That will happen (for example) if the parameter is never
16244 referenced within the function.
16246 We could just generate a location descriptor here for all non-NULL
16247 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
16248 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
16249 where DECL_RTL is NULL or is a pseudo-reg.
16251 Note however that we can only get away with using DECL_INCOMING_RTL as
16252 a backup substitute for DECL_RTL in certain limited cases. In cases
16253 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
16254 we can be sure that the parameter was passed using the same type as it is
16255 declared to have within the function, and that its DECL_INCOMING_RTL
16256 points us to a place where a value of that type is passed.
16258 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
16259 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
16260 because in these cases DECL_INCOMING_RTL points us to a value of some
16261 type which is *different* from the type of the parameter itself. Thus,
16262 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
16263 such cases, the debugger would end up (for example) trying to fetch a
16264 `float' from a place which actually contains the first part of a
16265 `double'. That would lead to really incorrect and confusing
16266 output at debug-time.
16268 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
16269 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
16270 are a couple of exceptions however. On little-endian machines we can
16271 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
16272 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
16273 an integral type that is smaller than TREE_TYPE (decl). These cases arise
16274 when (on a little-endian machine) a non-prototyped function has a
16275 parameter declared to be of type `short' or `char'. In such cases,
16276 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
16277 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
16278 passed `int' value. If the debugger then uses that address to fetch
16279 a `short' or a `char' (on a little-endian machine) the result will be
16280 the correct data, so we allow for such exceptional cases below.
16282 Note that our goal here is to describe the place where the given formal
16283 parameter lives during most of the function's activation (i.e. between the
16284 end of the prologue and the start of the epilogue). We'll do that as best
16285 as we can. Note however that if the given formal parameter is modified
16286 sometime during the execution of the function, then a stack backtrace (at
16287 debug-time) will show the function as having been called with the *new*
16288 value rather than the value which was originally passed in. This happens
16289 rarely enough that it is not a major problem, but it *is* a problem, and
16290 I'd like to fix it.
16292 A future version of dwarf2out.c may generate two additional attributes for
16293 any given DW_TAG_formal_parameter DIE which will describe the "passed
16294 type" and the "passed location" for the given formal parameter in addition
16295 to the attributes we now generate to indicate the "declared type" and the
16296 "active location" for each parameter. This additional set of attributes
16297 could be used by debuggers for stack backtraces. Separately, note that
16298 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
16299 This happens (for example) for inlined-instances of inline function formal
16300 parameters which are never referenced. This really shouldn't be
16301 happening. All PARM_DECL nodes should get valid non-NULL
16302 DECL_INCOMING_RTL values. FIXME. */
16304 /* Use DECL_RTL as the "location" unless we find something better. */
16305 rtl
= DECL_RTL_IF_SET (decl
);
16307 /* When generating abstract instances, ignore everything except
16308 constants, symbols living in memory, and symbols living in
16309 fixed registers. */
16310 if (! reload_completed
)
16313 && (CONSTANT_P (rtl
)
16315 && CONSTANT_P (XEXP (rtl
, 0)))
16317 && TREE_CODE (decl
) == VAR_DECL
16318 && TREE_STATIC (decl
))))
16320 rtl
= targetm
.delegitimize_address (rtl
);
16325 else if (TREE_CODE (decl
) == PARM_DECL
)
16327 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
16329 tree declared_type
= TREE_TYPE (decl
);
16330 tree passed_type
= DECL_ARG_TYPE (decl
);
16331 enum machine_mode dmode
= TYPE_MODE (declared_type
);
16332 enum machine_mode pmode
= TYPE_MODE (passed_type
);
16334 /* This decl represents a formal parameter which was optimized out.
16335 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
16336 all cases where (rtl == NULL_RTX) just below. */
16337 if (dmode
== pmode
)
16338 rtl
= DECL_INCOMING_RTL (decl
);
16339 else if (SCALAR_INT_MODE_P (dmode
)
16340 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
16341 && DECL_INCOMING_RTL (decl
))
16343 rtx inc
= DECL_INCOMING_RTL (decl
);
16346 else if (MEM_P (inc
))
16348 if (BYTES_BIG_ENDIAN
)
16349 rtl
= adjust_address_nv (inc
, dmode
,
16350 GET_MODE_SIZE (pmode
)
16351 - GET_MODE_SIZE (dmode
));
16358 /* If the parm was passed in registers, but lives on the stack, then
16359 make a big endian correction if the mode of the type of the
16360 parameter is not the same as the mode of the rtl. */
16361 /* ??? This is the same series of checks that are made in dbxout.c before
16362 we reach the big endian correction code there. It isn't clear if all
16363 of these checks are necessary here, but keeping them all is the safe
16365 else if (MEM_P (rtl
)
16366 && XEXP (rtl
, 0) != const0_rtx
16367 && ! CONSTANT_P (XEXP (rtl
, 0))
16368 /* Not passed in memory. */
16369 && !MEM_P (DECL_INCOMING_RTL (decl
))
16370 /* Not passed by invisible reference. */
16371 && (!REG_P (XEXP (rtl
, 0))
16372 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
16373 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
16374 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
16375 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
16378 /* Big endian correction check. */
16379 && BYTES_BIG_ENDIAN
16380 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
16381 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
16384 int offset
= (UNITS_PER_WORD
16385 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
16387 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
16388 plus_constant (XEXP (rtl
, 0), offset
));
16391 else if (TREE_CODE (decl
) == VAR_DECL
16394 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
16395 && BYTES_BIG_ENDIAN
)
16397 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
16398 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
16400 /* If a variable is declared "register" yet is smaller than
16401 a register, then if we store the variable to memory, it
16402 looks like we're storing a register-sized value, when in
16403 fact we are not. We need to adjust the offset of the
16404 storage location to reflect the actual value's bytes,
16405 else gdb will not be able to display it. */
16407 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
16408 plus_constant (XEXP (rtl
, 0), rsize
-dsize
));
16411 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16412 and will have been substituted directly into all expressions that use it.
16413 C does not have such a concept, but C++ and other languages do. */
16414 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
16415 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
16418 rtl
= targetm
.delegitimize_address (rtl
);
16420 /* If we don't look past the constant pool, we risk emitting a
16421 reference to a constant pool entry that isn't referenced from
16422 code, and thus is not emitted. */
16424 rtl
= avoid_constant_pool_reference (rtl
);
16426 /* Try harder to get a rtl. If this symbol ends up not being emitted
16427 in the current CU, resolve_addr will remove the expression referencing
16429 if (rtl
== NULL_RTX
16430 && TREE_CODE (decl
) == VAR_DECL
16431 && !DECL_EXTERNAL (decl
)
16432 && TREE_STATIC (decl
)
16433 && DECL_NAME (decl
)
16434 && !DECL_HARD_REGISTER (decl
)
16435 && DECL_MODE (decl
) != VOIDmode
)
16437 rtl
= make_decl_rtl_for_debug (decl
);
16439 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
16440 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
16447 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
16448 returned. If so, the decl for the COMMON block is returned, and the
16449 value is the offset into the common block for the symbol. */
16452 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
16454 tree val_expr
, cvar
;
16455 enum machine_mode mode
;
16456 HOST_WIDE_INT bitsize
, bitpos
;
16458 int volatilep
= 0, unsignedp
= 0;
16460 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
16461 it does not have a value (the offset into the common area), or if it
16462 is thread local (as opposed to global) then it isn't common, and shouldn't
16463 be handled as such. */
16464 if (TREE_CODE (decl
) != VAR_DECL
16465 || !TREE_STATIC (decl
)
16466 || !DECL_HAS_VALUE_EXPR_P (decl
)
16470 val_expr
= DECL_VALUE_EXPR (decl
);
16471 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
16474 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
16475 &mode
, &unsignedp
, &volatilep
, true);
16477 if (cvar
== NULL_TREE
16478 || TREE_CODE (cvar
) != VAR_DECL
16479 || DECL_ARTIFICIAL (cvar
)
16480 || !TREE_PUBLIC (cvar
))
16484 if (offset
!= NULL
)
16486 if (!host_integerp (offset
, 0))
16488 *value
= tree_low_cst (offset
, 0);
16491 *value
+= bitpos
/ BITS_PER_UNIT
;
16496 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
16497 data attribute for a variable or a parameter. We generate the
16498 DW_AT_const_value attribute only in those cases where the given variable
16499 or parameter does not have a true "location" either in memory or in a
16500 register. This can happen (for example) when a constant is passed as an
16501 actual argument in a call to an inline function. (It's possible that
16502 these things can crop up in other ways also.) Note that one type of
16503 constant value which can be passed into an inlined function is a constant
16504 pointer. This can happen for example if an actual argument in an inlined
16505 function call evaluates to a compile-time constant address. */
16508 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
,
16509 enum dwarf_attribute attr
)
16512 dw_loc_list_ref list
;
16513 var_loc_list
*loc_list
;
16515 if (TREE_CODE (decl
) == ERROR_MARK
)
16518 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
16519 || TREE_CODE (decl
) == RESULT_DECL
);
16521 /* Try to get some constant RTL for this decl, and use that as the value of
16524 rtl
= rtl_for_decl_location (decl
);
16525 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
16526 && add_const_value_attribute (die
, rtl
))
16529 /* See if we have single element location list that is equivalent to
16530 a constant value. That way we are better to use add_const_value_attribute
16531 rather than expanding constant value equivalent. */
16532 loc_list
= lookup_decl_loc (decl
);
16535 && loc_list
->first
->next
== NULL
16536 && NOTE_P (loc_list
->first
->loc
)
16537 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
16538 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
16540 struct var_loc_node
*node
;
16542 node
= loc_list
->first
;
16543 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
16544 if (GET_CODE (rtl
) == EXPR_LIST
)
16545 rtl
= XEXP (rtl
, 0);
16546 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
16547 && add_const_value_attribute (die
, rtl
))
16550 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
16553 add_AT_location_description (die
, attr
, list
);
16556 /* None of that worked, so it must not really have a location;
16557 try adding a constant value attribute from the DECL_INITIAL. */
16558 return tree_add_const_value_attribute_for_decl (die
, decl
);
16561 /* Add VARIABLE and DIE into deferred locations list. */
16564 defer_location (tree variable
, dw_die_ref die
)
16566 deferred_locations entry
;
16567 entry
.variable
= variable
;
16569 VEC_safe_push (deferred_locations
, gc
, deferred_locations_list
, &entry
);
16572 /* Helper function for tree_add_const_value_attribute. Natively encode
16573 initializer INIT into an array. Return true if successful. */
16576 native_encode_initializer (tree init
, unsigned char *array
, int size
)
16580 if (init
== NULL_TREE
)
16584 switch (TREE_CODE (init
))
16587 type
= TREE_TYPE (init
);
16588 if (TREE_CODE (type
) == ARRAY_TYPE
)
16590 tree enttype
= TREE_TYPE (type
);
16591 enum machine_mode mode
= TYPE_MODE (enttype
);
16593 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
16595 if (int_size_in_bytes (type
) != size
)
16597 if (size
> TREE_STRING_LENGTH (init
))
16599 memcpy (array
, TREE_STRING_POINTER (init
),
16600 TREE_STRING_LENGTH (init
));
16601 memset (array
+ TREE_STRING_LENGTH (init
),
16602 '\0', size
- TREE_STRING_LENGTH (init
));
16605 memcpy (array
, TREE_STRING_POINTER (init
), size
);
16610 type
= TREE_TYPE (init
);
16611 if (int_size_in_bytes (type
) != size
)
16613 if (TREE_CODE (type
) == ARRAY_TYPE
)
16615 HOST_WIDE_INT min_index
;
16616 unsigned HOST_WIDE_INT cnt
;
16617 int curpos
= 0, fieldsize
;
16618 constructor_elt
*ce
;
16620 if (TYPE_DOMAIN (type
) == NULL_TREE
16621 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
16624 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
16625 if (fieldsize
<= 0)
16628 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
16629 memset (array
, '\0', size
);
16631 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
);
16634 tree val
= ce
->value
;
16635 tree index
= ce
->index
;
16637 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
16638 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
16641 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
16646 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
16649 curpos
= pos
+ fieldsize
;
16650 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
16652 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
16653 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
16657 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
16658 curpos
+= fieldsize
;
16661 gcc_assert (curpos
<= size
);
16665 else if (TREE_CODE (type
) == RECORD_TYPE
16666 || TREE_CODE (type
) == UNION_TYPE
)
16668 tree field
= NULL_TREE
;
16669 unsigned HOST_WIDE_INT cnt
;
16670 constructor_elt
*ce
;
16672 if (int_size_in_bytes (type
) != size
)
16675 if (TREE_CODE (type
) == RECORD_TYPE
)
16676 field
= TYPE_FIELDS (type
);
16679 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
);
16680 cnt
++, field
= field
? TREE_CHAIN (field
) : 0)
16682 tree val
= ce
->value
;
16683 int pos
, fieldsize
;
16685 if (ce
->index
!= 0)
16691 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
16694 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
16695 && TYPE_DOMAIN (TREE_TYPE (field
))
16696 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
16698 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
16699 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
16701 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
16702 pos
= int_byte_position (field
);
16703 gcc_assert (pos
+ fieldsize
<= size
);
16705 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
16711 case VIEW_CONVERT_EXPR
:
16712 case NON_LVALUE_EXPR
:
16713 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
16715 return native_encode_expr (init
, array
, size
) == size
;
16719 /* Attach a DW_AT_const_value attribute to DIE. The value of the
16720 attribute is the const value T. */
16723 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
16726 tree type
= TREE_TYPE (t
);
16729 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
16733 gcc_assert (!DECL_P (init
));
16735 rtl
= rtl_for_decl_init (init
, type
);
16737 return add_const_value_attribute (die
, rtl
);
16738 /* If the host and target are sane, try harder. */
16739 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
16740 && initializer_constant_valid_p (init
, type
))
16742 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
16743 if (size
> 0 && (int) size
== size
)
16745 unsigned char *array
= (unsigned char *)
16746 ggc_alloc_cleared_atomic (size
);
16748 if (native_encode_initializer (init
, array
, size
))
16750 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
16758 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
16759 attribute is the const value of T, where T is an integral constant
16760 variable with static storage duration
16761 (so it can't be a PARM_DECL or a RESULT_DECL). */
16764 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
16768 || (TREE_CODE (decl
) != VAR_DECL
16769 && TREE_CODE (decl
) != CONST_DECL
))
16772 if (TREE_READONLY (decl
)
16773 && ! TREE_THIS_VOLATILE (decl
)
16774 && DECL_INITIAL (decl
))
16779 /* Don't add DW_AT_const_value if abstract origin already has one. */
16780 if (get_AT (var_die
, DW_AT_const_value
))
16783 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
16786 /* Convert the CFI instructions for the current function into a
16787 location list. This is used for DW_AT_frame_base when we targeting
16788 a dwarf2 consumer that does not support the dwarf3
16789 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
16792 static dw_loc_list_ref
16793 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
16796 dw_loc_list_ref list
, *list_tail
;
16798 dw_cfa_location last_cfa
, next_cfa
;
16799 const char *start_label
, *last_label
, *section
;
16800 dw_cfa_location remember
;
16802 fde
= current_fde ();
16803 gcc_assert (fde
!= NULL
);
16805 section
= secname_for_decl (current_function_decl
);
16809 memset (&next_cfa
, 0, sizeof (next_cfa
));
16810 next_cfa
.reg
= INVALID_REGNUM
;
16811 remember
= next_cfa
;
16813 start_label
= fde
->dw_fde_begin
;
16815 /* ??? Bald assumption that the CIE opcode list does not contain
16816 advance opcodes. */
16817 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
16818 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
16820 last_cfa
= next_cfa
;
16821 last_label
= start_label
;
16823 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
16824 switch (cfi
->dw_cfi_opc
)
16826 case DW_CFA_set_loc
:
16827 case DW_CFA_advance_loc1
:
16828 case DW_CFA_advance_loc2
:
16829 case DW_CFA_advance_loc4
:
16830 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16832 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16833 start_label
, last_label
, section
);
16835 list_tail
= &(*list_tail
)->dw_loc_next
;
16836 last_cfa
= next_cfa
;
16837 start_label
= last_label
;
16839 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
16842 case DW_CFA_advance_loc
:
16843 /* The encoding is complex enough that we should never emit this. */
16844 gcc_unreachable ();
16847 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
16851 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16853 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16854 start_label
, last_label
, section
);
16855 list_tail
= &(*list_tail
)->dw_loc_next
;
16856 start_label
= last_label
;
16859 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
16860 start_label
, fde
->dw_fde_end
, section
);
16862 if (list
&& list
->dw_loc_next
)
16868 /* Compute a displacement from the "steady-state frame pointer" to the
16869 frame base (often the same as the CFA), and store it in
16870 frame_pointer_fb_offset. OFFSET is added to the displacement
16871 before the latter is negated. */
16874 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
16878 #ifdef FRAME_POINTER_CFA_OFFSET
16879 reg
= frame_pointer_rtx
;
16880 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
16882 reg
= arg_pointer_rtx
;
16883 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
16886 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
16887 if (GET_CODE (elim
) == PLUS
)
16889 offset
+= INTVAL (XEXP (elim
, 1));
16890 elim
= XEXP (elim
, 0);
16893 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
16894 && (elim
== hard_frame_pointer_rtx
16895 || elim
== stack_pointer_rtx
))
16896 || elim
== (frame_pointer_needed
16897 ? hard_frame_pointer_rtx
16898 : stack_pointer_rtx
));
16900 frame_pointer_fb_offset
= -offset
;
16903 /* Generate a DW_AT_name attribute given some string value to be included as
16904 the value of the attribute. */
16907 add_name_attribute (dw_die_ref die
, const char *name_string
)
16909 if (name_string
!= NULL
&& *name_string
!= 0)
16911 if (demangle_name_func
)
16912 name_string
= (*demangle_name_func
) (name_string
);
16914 add_AT_string (die
, DW_AT_name
, name_string
);
16918 /* Generate a DW_AT_comp_dir attribute for DIE. */
16921 add_comp_dir_attribute (dw_die_ref die
)
16923 const char *wd
= get_src_pwd ();
16929 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
16933 wdlen
= strlen (wd
);
16934 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
16936 wd1
[wdlen
] = DIR_SEPARATOR
;
16937 wd1
[wdlen
+ 1] = 0;
16941 add_AT_string (die
, DW_AT_comp_dir
, remap_debug_filename (wd
));
16944 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
16948 lower_bound_default (void)
16950 switch (get_AT_unsigned (comp_unit_die
, DW_AT_language
))
16955 case DW_LANG_C_plus_plus
:
16957 case DW_LANG_ObjC_plus_plus
:
16960 case DW_LANG_Fortran77
:
16961 case DW_LANG_Fortran90
:
16962 case DW_LANG_Fortran95
:
16966 case DW_LANG_Python
:
16967 return dwarf_version
>= 4 ? 0 : -1;
16968 case DW_LANG_Ada95
:
16969 case DW_LANG_Ada83
:
16970 case DW_LANG_Cobol74
:
16971 case DW_LANG_Cobol85
:
16972 case DW_LANG_Pascal83
:
16973 case DW_LANG_Modula2
:
16975 return dwarf_version
>= 4 ? 1 : -1;
16981 /* Given a tree node describing an array bound (either lower or upper) output
16982 a representation for that bound. */
16985 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
16987 switch (TREE_CODE (bound
))
16992 /* All fixed-bounds are represented by INTEGER_CST nodes. */
16995 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
16998 /* Use the default if possible. */
16999 if (bound_attr
== DW_AT_lower_bound
17000 && host_integerp (bound
, 0)
17001 && (dflt
= lower_bound_default ()) != -1
17002 && tree_low_cst (bound
, 0) == dflt
)
17005 /* Otherwise represent the bound as an unsigned value with the
17006 precision of its type. The precision and signedness of the
17007 type will be necessary to re-interpret it unambiguously. */
17008 else if (prec
< HOST_BITS_PER_WIDE_INT
)
17010 unsigned HOST_WIDE_INT mask
17011 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
17012 add_AT_unsigned (subrange_die
, bound_attr
,
17013 TREE_INT_CST_LOW (bound
) & mask
);
17015 else if (prec
== HOST_BITS_PER_WIDE_INT
17016 || TREE_INT_CST_HIGH (bound
) == 0)
17017 add_AT_unsigned (subrange_die
, bound_attr
,
17018 TREE_INT_CST_LOW (bound
));
17020 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
17021 TREE_INT_CST_LOW (bound
));
17026 case VIEW_CONVERT_EXPR
:
17027 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
17037 dw_die_ref decl_die
= lookup_decl_die (bound
);
17039 /* ??? Can this happen, or should the variable have been bound
17040 first? Probably it can, since I imagine that we try to create
17041 the types of parameters in the order in which they exist in
17042 the list, and won't have created a forward reference to a
17043 later parameter. */
17044 if (decl_die
!= NULL
)
17046 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
17054 /* Otherwise try to create a stack operation procedure to
17055 evaluate the value of the array bound. */
17057 dw_die_ref ctx
, decl_die
;
17058 dw_loc_list_ref list
;
17060 list
= loc_list_from_tree (bound
, 2);
17061 if (list
== NULL
|| single_element_loc_list_p (list
))
17063 /* If DW_AT_*bound is not a reference nor constant, it is
17064 a DWARF expression rather than location description.
17065 For that loc_list_from_tree (bound, 0) is needed.
17066 If that fails to give a single element list,
17067 fall back to outputting this as a reference anyway. */
17068 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
17069 if (list2
&& single_element_loc_list_p (list2
))
17071 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
17078 if (current_function_decl
== 0)
17079 ctx
= comp_unit_die
;
17081 ctx
= lookup_decl_die (current_function_decl
);
17083 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
17084 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
17085 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
17086 add_AT_location_description (decl_die
, DW_AT_location
, list
);
17087 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
17093 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
17094 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
17095 Note that the block of subscript information for an array type also
17096 includes information about the element type of the given array type. */
17099 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
17101 unsigned dimension_number
;
17103 dw_die_ref subrange_die
;
17105 for (dimension_number
= 0;
17106 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
17107 type
= TREE_TYPE (type
), dimension_number
++)
17109 tree domain
= TYPE_DOMAIN (type
);
17111 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
17114 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
17115 and (in GNU C only) variable bounds. Handle all three forms
17117 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
17120 /* We have an array type with specified bounds. */
17121 lower
= TYPE_MIN_VALUE (domain
);
17122 upper
= TYPE_MAX_VALUE (domain
);
17124 /* Define the index type. */
17125 if (TREE_TYPE (domain
))
17127 /* ??? This is probably an Ada unnamed subrange type. Ignore the
17128 TREE_TYPE field. We can't emit debug info for this
17129 because it is an unnamed integral type. */
17130 if (TREE_CODE (domain
) == INTEGER_TYPE
17131 && TYPE_NAME (domain
) == NULL_TREE
17132 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
17133 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
17136 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
17140 /* ??? If upper is NULL, the array has unspecified length,
17141 but it does have a lower bound. This happens with Fortran
17143 Since the debugger is definitely going to need to know N
17144 to produce useful results, go ahead and output the lower
17145 bound solo, and hope the debugger can cope. */
17147 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
17149 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
17152 /* Otherwise we have an array type with an unspecified length. The
17153 DWARF-2 spec does not say how to handle this; let's just leave out the
17159 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
17163 switch (TREE_CODE (tree_node
))
17168 case ENUMERAL_TYPE
:
17171 case QUAL_UNION_TYPE
:
17172 size
= int_size_in_bytes (tree_node
);
17175 /* For a data member of a struct or union, the DW_AT_byte_size is
17176 generally given as the number of bytes normally allocated for an
17177 object of the *declared* type of the member itself. This is true
17178 even for bit-fields. */
17179 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
17182 gcc_unreachable ();
17185 /* Note that `size' might be -1 when we get to this point. If it is, that
17186 indicates that the byte size of the entity in question is variable. We
17187 have no good way of expressing this fact in Dwarf at the present time,
17188 so just let the -1 pass on through. */
17189 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
17192 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17193 which specifies the distance in bits from the highest order bit of the
17194 "containing object" for the bit-field to the highest order bit of the
17197 For any given bit-field, the "containing object" is a hypothetical object
17198 (of some integral or enum type) within which the given bit-field lives. The
17199 type of this hypothetical "containing object" is always the same as the
17200 declared type of the individual bit-field itself. The determination of the
17201 exact location of the "containing object" for a bit-field is rather
17202 complicated. It's handled by the `field_byte_offset' function (above).
17204 Note that it is the size (in bytes) of the hypothetical "containing object"
17205 which will be given in the DW_AT_byte_size attribute for this bit-field.
17206 (See `byte_size_attribute' above). */
17209 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
17211 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
17212 tree type
= DECL_BIT_FIELD_TYPE (decl
);
17213 HOST_WIDE_INT bitpos_int
;
17214 HOST_WIDE_INT highest_order_object_bit_offset
;
17215 HOST_WIDE_INT highest_order_field_bit_offset
;
17216 HOST_WIDE_INT
unsigned bit_offset
;
17218 /* Must be a field and a bit field. */
17219 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
17221 /* We can't yet handle bit-fields whose offsets are variable, so if we
17222 encounter such things, just return without generating any attribute
17223 whatsoever. Likewise for variable or too large size. */
17224 if (! host_integerp (bit_position (decl
), 0)
17225 || ! host_integerp (DECL_SIZE (decl
), 1))
17228 bitpos_int
= int_bit_position (decl
);
17230 /* Note that the bit offset is always the distance (in bits) from the
17231 highest-order bit of the "containing object" to the highest-order bit of
17232 the bit-field itself. Since the "high-order end" of any object or field
17233 is different on big-endian and little-endian machines, the computation
17234 below must take account of these differences. */
17235 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
17236 highest_order_field_bit_offset
= bitpos_int
;
17238 if (! BYTES_BIG_ENDIAN
)
17240 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
17241 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
17245 = (! BYTES_BIG_ENDIAN
17246 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
17247 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
17249 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
17252 /* For a FIELD_DECL node which represents a bit field, output an attribute
17253 which specifies the length in bits of the given field. */
17256 add_bit_size_attribute (dw_die_ref die
, tree decl
)
17258 /* Must be a field and a bit field. */
17259 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
17260 && DECL_BIT_FIELD_TYPE (decl
));
17262 if (host_integerp (DECL_SIZE (decl
), 1))
17263 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
17266 /* If the compiled language is ANSI C, then add a 'prototyped'
17267 attribute, if arg types are given for the parameters of a function. */
17270 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
17272 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
17273 && TYPE_ARG_TYPES (func_type
) != NULL
)
17274 add_AT_flag (die
, DW_AT_prototyped
, 1);
17277 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17278 by looking in either the type declaration or object declaration
17281 static inline dw_die_ref
17282 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
17284 dw_die_ref origin_die
= NULL
;
17286 if (TREE_CODE (origin
) != FUNCTION_DECL
)
17288 /* We may have gotten separated from the block for the inlined
17289 function, if we're in an exception handler or some such; make
17290 sure that the abstract function has been written out.
17292 Doing this for nested functions is wrong, however; functions are
17293 distinct units, and our context might not even be inline. */
17297 fn
= TYPE_STUB_DECL (fn
);
17299 fn
= decl_function_context (fn
);
17301 dwarf2out_abstract_function (fn
);
17304 if (DECL_P (origin
))
17305 origin_die
= lookup_decl_die (origin
);
17306 else if (TYPE_P (origin
))
17307 origin_die
= lookup_type_die (origin
);
17309 /* XXX: Functions that are never lowered don't always have correct block
17310 trees (in the case of java, they simply have no block tree, in some other
17311 languages). For these functions, there is nothing we can really do to
17312 output correct debug info for inlined functions in all cases. Rather
17313 than die, we'll just produce deficient debug info now, in that we will
17314 have variables without a proper abstract origin. In the future, when all
17315 functions are lowered, we should re-add a gcc_assert (origin_die)
17319 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
17323 /* We do not currently support the pure_virtual attribute. */
17326 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
17328 if (DECL_VINDEX (func_decl
))
17330 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
17332 if (host_integerp (DECL_VINDEX (func_decl
), 0))
17333 add_AT_loc (die
, DW_AT_vtable_elem_location
,
17334 new_loc_descr (DW_OP_constu
,
17335 tree_low_cst (DECL_VINDEX (func_decl
), 0),
17338 /* GNU extension: Record what type this method came from originally. */
17339 if (debug_info_level
> DINFO_LEVEL_TERSE
17340 && DECL_CONTEXT (func_decl
))
17341 add_AT_die_ref (die
, DW_AT_containing_type
,
17342 lookup_type_die (DECL_CONTEXT (func_decl
)));
17346 /* Add source coordinate attributes for the given decl. */
17349 add_src_coords_attributes (dw_die_ref die
, tree decl
)
17351 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17353 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
17354 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
17357 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
17360 add_linkage_name (dw_die_ref die
, tree decl
)
17362 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
17363 && TREE_PUBLIC (decl
)
17364 && !DECL_ABSTRACT (decl
)
17365 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
17366 && die
->die_tag
!= DW_TAG_member
)
17368 /* Defer until we have an assembler name set. */
17369 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
17371 limbo_die_node
*asm_name
;
17373 asm_name
= ggc_alloc_cleared_limbo_die_node ();
17374 asm_name
->die
= die
;
17375 asm_name
->created_for
= decl
;
17376 asm_name
->next
= deferred_asm_name
;
17377 deferred_asm_name
= asm_name
;
17379 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
17380 add_AT_string (die
, AT_linkage_name
,
17381 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
17385 /* Add a DW_AT_name attribute and source coordinate attribute for the
17386 given decl, but only if it actually has a name. */
17389 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
17393 decl_name
= DECL_NAME (decl
);
17394 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
17396 const char *name
= dwarf2_name (decl
, 0);
17398 add_name_attribute (die
, name
);
17399 if (! DECL_ARTIFICIAL (decl
))
17400 add_src_coords_attributes (die
, decl
);
17402 add_linkage_name (die
, decl
);
17405 #ifdef VMS_DEBUGGING_INFO
17406 /* Get the function's name, as described by its RTL. This may be different
17407 from the DECL_NAME name used in the source file. */
17408 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
17410 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
17411 XEXP (DECL_RTL (decl
), 0));
17412 VEC_safe_push (rtx
, gc
, used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
17417 #ifdef VMS_DEBUGGING_INFO
17419 /* Output the debug main pointer die for VMS */
17422 dwarf2out_vms_debug_main_pointer (void)
17424 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
17427 /* Allocate the VMS debug main subprogram die. */
17428 die
= ggc_alloc_cleared_die_node ();
17429 die
->die_tag
= DW_TAG_subprogram
;
17430 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
17431 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
17432 current_function_funcdef_no
);
17433 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
17435 /* Make it the first child of comp_unit_die. */
17436 die
->die_parent
= comp_unit_die
;
17437 if (comp_unit_die
->die_child
)
17439 die
->die_sib
= comp_unit_die
->die_child
->die_sib
;
17440 comp_unit_die
->die_child
->die_sib
= die
;
17444 die
->die_sib
= die
;
17445 comp_unit_die
->die_child
= die
;
17450 /* Push a new declaration scope. */
17453 push_decl_scope (tree scope
)
17455 VEC_safe_push (tree
, gc
, decl_scope_table
, scope
);
17458 /* Pop a declaration scope. */
17461 pop_decl_scope (void)
17463 VEC_pop (tree
, decl_scope_table
);
17466 /* Return the DIE for the scope that immediately contains this type.
17467 Non-named types get global scope. Named types nested in other
17468 types get their containing scope if it's open, or global scope
17469 otherwise. All other types (i.e. function-local named types) get
17470 the current active scope. */
17473 scope_die_for (tree t
, dw_die_ref context_die
)
17475 dw_die_ref scope_die
= NULL
;
17476 tree containing_scope
;
17479 /* Non-types always go in the current scope. */
17480 gcc_assert (TYPE_P (t
));
17482 containing_scope
= TYPE_CONTEXT (t
);
17484 /* Use the containing namespace if it was passed in (for a declaration). */
17485 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
17487 if (context_die
== lookup_decl_die (containing_scope
))
17490 containing_scope
= NULL_TREE
;
17493 /* Ignore function type "scopes" from the C frontend. They mean that
17494 a tagged type is local to a parmlist of a function declarator, but
17495 that isn't useful to DWARF. */
17496 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
17497 containing_scope
= NULL_TREE
;
17499 if (containing_scope
== NULL_TREE
)
17500 scope_die
= comp_unit_die
;
17501 else if (TYPE_P (containing_scope
))
17503 /* For types, we can just look up the appropriate DIE. But
17504 first we check to see if we're in the middle of emitting it
17505 so we know where the new DIE should go. */
17506 for (i
= VEC_length (tree
, decl_scope_table
) - 1; i
>= 0; --i
)
17507 if (VEC_index (tree
, decl_scope_table
, i
) == containing_scope
)
17512 gcc_assert (debug_info_level
<= DINFO_LEVEL_TERSE
17513 || TREE_ASM_WRITTEN (containing_scope
));
17515 /* If none of the current dies are suitable, we get file scope. */
17516 scope_die
= comp_unit_die
;
17519 scope_die
= lookup_type_die (containing_scope
);
17522 scope_die
= context_die
;
17527 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
17530 local_scope_p (dw_die_ref context_die
)
17532 for (; context_die
; context_die
= context_die
->die_parent
)
17533 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
17534 || context_die
->die_tag
== DW_TAG_subprogram
)
17540 /* Returns nonzero if CONTEXT_DIE is a class. */
17543 class_scope_p (dw_die_ref context_die
)
17545 return (context_die
17546 && (context_die
->die_tag
== DW_TAG_structure_type
17547 || context_die
->die_tag
== DW_TAG_class_type
17548 || context_die
->die_tag
== DW_TAG_interface_type
17549 || context_die
->die_tag
== DW_TAG_union_type
));
17552 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
17553 whether or not to treat a DIE in this context as a declaration. */
17556 class_or_namespace_scope_p (dw_die_ref context_die
)
17558 return (class_scope_p (context_die
)
17559 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
17562 /* Many forms of DIEs require a "type description" attribute. This
17563 routine locates the proper "type descriptor" die for the type given
17564 by 'type', and adds a DW_AT_type attribute below the given die. */
17567 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
17568 int decl_volatile
, dw_die_ref context_die
)
17570 enum tree_code code
= TREE_CODE (type
);
17571 dw_die_ref type_die
= NULL
;
17573 /* ??? If this type is an unnamed subrange type of an integral, floating-point
17574 or fixed-point type, use the inner type. This is because we have no
17575 support for unnamed types in base_type_die. This can happen if this is
17576 an Ada subrange type. Correct solution is emit a subrange type die. */
17577 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
17578 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
17579 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
17581 if (code
== ERROR_MARK
17582 /* Handle a special case. For functions whose return type is void, we
17583 generate *no* type attribute. (Note that no object may have type
17584 `void', so this only applies to function return types). */
17585 || code
== VOID_TYPE
)
17588 type_die
= modified_type_die (type
,
17589 decl_const
|| TYPE_READONLY (type
),
17590 decl_volatile
|| TYPE_VOLATILE (type
),
17593 if (type_die
!= NULL
)
17594 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
17597 /* Given an object die, add the calling convention attribute for the
17598 function call type. */
17600 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
17602 enum dwarf_calling_convention value
= DW_CC_normal
;
17604 value
= ((enum dwarf_calling_convention
)
17605 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
17607 /* DWARF doesn't provide a way to identify a program's source-level
17608 entry point. DW_AT_calling_convention attributes are only meant
17609 to describe functions' calling conventions. However, lacking a
17610 better way to signal the Fortran main program, we use this for the
17611 time being, following existing custom. */
17613 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
17614 value
= DW_CC_program
;
17616 /* Only add the attribute if the backend requests it, and
17617 is not DW_CC_normal. */
17618 if (value
&& (value
!= DW_CC_normal
))
17619 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
17622 /* Given a tree pointer to a struct, class, union, or enum type node, return
17623 a pointer to the (string) tag name for the given type, or zero if the type
17624 was declared without a tag. */
17626 static const char *
17627 type_tag (const_tree type
)
17629 const char *name
= 0;
17631 if (TYPE_NAME (type
) != 0)
17635 /* Find the IDENTIFIER_NODE for the type name. */
17636 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
17637 t
= TYPE_NAME (type
);
17639 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
17640 a TYPE_DECL node, regardless of whether or not a `typedef' was
17642 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
17643 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
17645 /* We want to be extra verbose. Don't call dwarf_name if
17646 DECL_NAME isn't set. The default hook for decl_printable_name
17647 doesn't like that, and in this context it's correct to return
17648 0, instead of "<anonymous>" or the like. */
17649 if (DECL_NAME (TYPE_NAME (type
)))
17650 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
17653 /* Now get the name as a string, or invent one. */
17654 if (!name
&& t
!= 0)
17655 name
= IDENTIFIER_POINTER (t
);
17658 return (name
== 0 || *name
== '\0') ? 0 : name
;
17661 /* Return the type associated with a data member, make a special check
17662 for bit field types. */
17665 member_declared_type (const_tree member
)
17667 return (DECL_BIT_FIELD_TYPE (member
)
17668 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
17671 /* Get the decl's label, as described by its RTL. This may be different
17672 from the DECL_NAME name used in the source file. */
17675 static const char *
17676 decl_start_label (tree decl
)
17679 const char *fnname
;
17681 x
= DECL_RTL (decl
);
17682 gcc_assert (MEM_P (x
));
17685 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
17687 fnname
= XSTR (x
, 0);
17692 /* These routines generate the internal representation of the DIE's for
17693 the compilation unit. Debugging information is collected by walking
17694 the declaration trees passed in from dwarf2out_decl(). */
17697 gen_array_type_die (tree type
, dw_die_ref context_die
)
17699 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17700 dw_die_ref array_die
;
17702 /* GNU compilers represent multidimensional array types as sequences of one
17703 dimensional array types whose element types are themselves array types.
17704 We sometimes squish that down to a single array_type DIE with multiple
17705 subscripts in the Dwarf debugging info. The draft Dwarf specification
17706 say that we are allowed to do this kind of compression in C, because
17707 there is no difference between an array of arrays and a multidimensional
17708 array. We don't do this for Ada to remain as close as possible to the
17709 actual representation, which is especially important against the language
17710 flexibilty wrt arrays of variable size. */
17712 bool collapse_nested_arrays
= !is_ada ();
17715 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
17716 DW_TAG_string_type doesn't have DW_AT_type attribute). */
17717 if (TYPE_STRING_FLAG (type
)
17718 && TREE_CODE (type
) == ARRAY_TYPE
17720 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
17722 HOST_WIDE_INT size
;
17724 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
17725 add_name_attribute (array_die
, type_tag (type
));
17726 equate_type_number_to_die (type
, array_die
);
17727 size
= int_size_in_bytes (type
);
17729 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17730 else if (TYPE_DOMAIN (type
) != NULL_TREE
17731 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
17732 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
17734 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
17735 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
17737 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
17738 if (loc
&& size
> 0)
17740 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
17741 if (size
!= DWARF2_ADDR_SIZE
)
17742 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17748 /* ??? The SGI dwarf reader fails for array of array of enum types
17749 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
17750 array type comes before the outer array type. We thus call gen_type_die
17751 before we new_die and must prevent nested array types collapsing for this
17754 #ifdef MIPS_DEBUGGING_INFO
17755 gen_type_die (TREE_TYPE (type
), context_die
);
17756 collapse_nested_arrays
= false;
17759 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17760 add_name_attribute (array_die
, type_tag (type
));
17761 equate_type_number_to_die (type
, array_die
);
17763 if (TREE_CODE (type
) == VECTOR_TYPE
)
17765 /* The frontend feeds us a representation for the vector as a struct
17766 containing an array. Pull out the array type. */
17767 type
= TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type
)));
17768 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
17771 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17773 && TREE_CODE (type
) == ARRAY_TYPE
17774 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
17775 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
17776 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17779 /* We default the array ordering. SDB will probably do
17780 the right things even if DW_AT_ordering is not present. It's not even
17781 an issue until we start to get into multidimensional arrays anyway. If
17782 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
17783 then we'll have to put the DW_AT_ordering attribute back in. (But if
17784 and when we find out that we need to put these in, we will only do so
17785 for multidimensional arrays. */
17786 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
17789 #ifdef MIPS_DEBUGGING_INFO
17790 /* The SGI compilers handle arrays of unknown bound by setting
17791 AT_declaration and not emitting any subrange DIEs. */
17792 if (! TYPE_DOMAIN (type
))
17793 add_AT_flag (array_die
, DW_AT_declaration
, 1);
17796 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
17798 /* Add representation of the type of the elements of this array type and
17799 emit the corresponding DIE if we haven't done it already. */
17800 element_type
= TREE_TYPE (type
);
17801 if (collapse_nested_arrays
)
17802 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
17804 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
17806 element_type
= TREE_TYPE (element_type
);
17809 #ifndef MIPS_DEBUGGING_INFO
17810 gen_type_die (element_type
, context_die
);
17813 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
17815 if (get_AT (array_die
, DW_AT_name
))
17816 add_pubtype (type
, array_die
);
17819 static dw_loc_descr_ref
17820 descr_info_loc (tree val
, tree base_decl
)
17822 HOST_WIDE_INT size
;
17823 dw_loc_descr_ref loc
, loc2
;
17824 enum dwarf_location_atom op
;
17826 if (val
== base_decl
)
17827 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
17829 switch (TREE_CODE (val
))
17832 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17834 return loc_descriptor_from_tree (val
, 0);
17836 if (host_integerp (val
, 0))
17837 return int_loc_descriptor (tree_low_cst (val
, 0));
17840 size
= int_size_in_bytes (TREE_TYPE (val
));
17843 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17846 if (size
== DWARF2_ADDR_SIZE
)
17847 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
17849 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
17851 case POINTER_PLUS_EXPR
:
17853 if (host_integerp (TREE_OPERAND (val
, 1), 1)
17854 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
17857 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17860 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
17866 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17869 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
17872 add_loc_descr (&loc
, loc2
);
17873 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
17895 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
17896 tree val
, tree base_decl
)
17898 dw_loc_descr_ref loc
;
17900 if (host_integerp (val
, 0))
17902 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
17906 loc
= descr_info_loc (val
, base_decl
);
17910 add_AT_loc (die
, attr
, loc
);
17913 /* This routine generates DIE for array with hidden descriptor, details
17914 are filled into *info by a langhook. */
17917 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
17918 dw_die_ref context_die
)
17920 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17921 dw_die_ref array_die
;
17924 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17925 add_name_attribute (array_die
, type_tag (type
));
17926 equate_type_number_to_die (type
, array_die
);
17928 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17930 && info
->ndimensions
>= 2)
17931 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17933 if (info
->data_location
)
17934 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
17936 if (info
->associated
)
17937 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
17939 if (info
->allocated
)
17940 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
17943 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
17945 dw_die_ref subrange_die
17946 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17948 if (info
->dimen
[dim
].lower_bound
)
17950 /* If it is the default value, omit it. */
17953 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
17954 && (dflt
= lower_bound_default ()) != -1
17955 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
17958 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
17959 info
->dimen
[dim
].lower_bound
,
17962 if (info
->dimen
[dim
].upper_bound
)
17963 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
17964 info
->dimen
[dim
].upper_bound
,
17966 if (info
->dimen
[dim
].stride
)
17967 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
17968 info
->dimen
[dim
].stride
,
17972 gen_type_die (info
->element_type
, context_die
);
17973 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
17975 if (get_AT (array_die
, DW_AT_name
))
17976 add_pubtype (type
, array_die
);
17981 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
17983 tree origin
= decl_ultimate_origin (decl
);
17984 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
17986 if (origin
!= NULL
)
17987 add_abstract_origin_attribute (decl_die
, origin
);
17990 add_name_and_src_coords_attributes (decl_die
, decl
);
17991 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
17992 0, 0, context_die
);
17995 if (DECL_ABSTRACT (decl
))
17996 equate_decl_number_to_die (decl
, decl_die
);
17998 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
18002 /* Walk through the list of incomplete types again, trying once more to
18003 emit full debugging info for them. */
18006 retry_incomplete_types (void)
18010 for (i
= VEC_length (tree
, incomplete_types
) - 1; i
>= 0; i
--)
18011 if (should_emit_struct_debug (VEC_index (tree
, incomplete_types
, i
),
18012 DINFO_USAGE_DIR_USE
))
18013 gen_type_die (VEC_index (tree
, incomplete_types
, i
), comp_unit_die
);
18016 /* Determine what tag to use for a record type. */
18018 static enum dwarf_tag
18019 record_type_tag (tree type
)
18021 if (! lang_hooks
.types
.classify_record
)
18022 return DW_TAG_structure_type
;
18024 switch (lang_hooks
.types
.classify_record (type
))
18026 case RECORD_IS_STRUCT
:
18027 return DW_TAG_structure_type
;
18029 case RECORD_IS_CLASS
:
18030 return DW_TAG_class_type
;
18032 case RECORD_IS_INTERFACE
:
18033 if (dwarf_version
>= 3 || !dwarf_strict
)
18034 return DW_TAG_interface_type
;
18035 return DW_TAG_structure_type
;
18038 gcc_unreachable ();
18042 /* Generate a DIE to represent an enumeration type. Note that these DIEs
18043 include all of the information about the enumeration values also. Each
18044 enumerated type name/value is listed as a child of the enumerated type
18048 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
18050 dw_die_ref type_die
= lookup_type_die (type
);
18052 if (type_die
== NULL
)
18054 type_die
= new_die (DW_TAG_enumeration_type
,
18055 scope_die_for (type
, context_die
), type
);
18056 equate_type_number_to_die (type
, type_die
);
18057 add_name_attribute (type_die
, type_tag (type
));
18058 if ((dwarf_version
>= 4 || !dwarf_strict
)
18059 && ENUM_IS_SCOPED (type
))
18060 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
18062 else if (! TYPE_SIZE (type
))
18065 remove_AT (type_die
, DW_AT_declaration
);
18067 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
18068 given enum type is incomplete, do not generate the DW_AT_byte_size
18069 attribute or the DW_AT_element_list attribute. */
18070 if (TYPE_SIZE (type
))
18074 TREE_ASM_WRITTEN (type
) = 1;
18075 add_byte_size_attribute (type_die
, type
);
18076 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
18077 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
18079 /* If the first reference to this type was as the return type of an
18080 inline function, then it may not have a parent. Fix this now. */
18081 if (type_die
->die_parent
== NULL
)
18082 add_child_die (scope_die_for (type
, context_die
), type_die
);
18084 for (link
= TYPE_VALUES (type
);
18085 link
!= NULL
; link
= TREE_CHAIN (link
))
18087 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
18088 tree value
= TREE_VALUE (link
);
18090 add_name_attribute (enum_die
,
18091 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
18093 if (TREE_CODE (value
) == CONST_DECL
)
18094 value
= DECL_INITIAL (value
);
18096 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
18097 /* DWARF2 does not provide a way of indicating whether or
18098 not enumeration constants are signed or unsigned. GDB
18099 always assumes the values are signed, so we output all
18100 values as if they were signed. That means that
18101 enumeration constants with very large unsigned values
18102 will appear to have negative values in the debugger. */
18103 add_AT_int (enum_die
, DW_AT_const_value
,
18104 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
18108 add_AT_flag (type_die
, DW_AT_declaration
, 1);
18110 if (get_AT (type_die
, DW_AT_name
))
18111 add_pubtype (type
, type_die
);
18116 /* Generate a DIE to represent either a real live formal parameter decl or to
18117 represent just the type of some formal parameter position in some function
18120 Note that this routine is a bit unusual because its argument may be a
18121 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
18122 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
18123 node. If it's the former then this function is being called to output a
18124 DIE to represent a formal parameter object (or some inlining thereof). If
18125 it's the latter, then this function is only being called to output a
18126 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
18127 argument type of some subprogram type.
18128 If EMIT_NAME_P is true, name and source coordinate attributes
18132 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
18133 dw_die_ref context_die
)
18135 tree node_or_origin
= node
? node
: origin
;
18136 tree ultimate_origin
;
18137 dw_die_ref parm_die
18138 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
18140 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
18142 case tcc_declaration
:
18143 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
18144 if (node
|| ultimate_origin
)
18145 origin
= ultimate_origin
;
18146 if (origin
!= NULL
)
18147 add_abstract_origin_attribute (parm_die
, origin
);
18148 else if (emit_name_p
)
18149 add_name_and_src_coords_attributes (parm_die
, node
);
18151 || (! DECL_ABSTRACT (node_or_origin
)
18152 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
18153 decl_function_context
18154 (node_or_origin
))))
18156 tree type
= TREE_TYPE (node_or_origin
);
18157 if (decl_by_reference_p (node_or_origin
))
18158 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
18161 add_type_attribute (parm_die
, type
,
18162 TREE_READONLY (node_or_origin
),
18163 TREE_THIS_VOLATILE (node_or_origin
),
18166 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
18167 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18169 if (node
&& node
!= origin
)
18170 equate_decl_number_to_die (node
, parm_die
);
18171 if (! DECL_ABSTRACT (node_or_origin
))
18172 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
18178 /* We were called with some kind of a ..._TYPE node. */
18179 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
18183 gcc_unreachable ();
18189 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18190 children DW_TAG_formal_parameter DIEs representing the arguments of the
18193 PARM_PACK must be a function parameter pack.
18194 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18195 must point to the subsequent arguments of the function PACK_ARG belongs to.
18196 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18197 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18198 following the last one for which a DIE was generated. */
18201 gen_formal_parameter_pack_die (tree parm_pack
,
18203 dw_die_ref subr_die
,
18207 dw_die_ref parm_pack_die
;
18209 gcc_assert (parm_pack
18210 && lang_hooks
.function_parameter_pack_p (parm_pack
)
18213 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
18214 add_src_coords_attributes (parm_pack_die
, parm_pack
);
18216 for (arg
= pack_arg
; arg
; arg
= TREE_CHAIN (arg
))
18218 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
18221 gen_formal_parameter_die (arg
, NULL
,
18222 false /* Don't emit name attribute. */,
18227 return parm_pack_die
;
18230 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18231 at the end of an (ANSI prototyped) formal parameters list. */
18234 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
18236 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
18239 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18240 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18241 parameters as specified in some function type specification (except for
18242 those which appear as part of a function *definition*). */
18245 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
18248 tree formal_type
= NULL
;
18249 tree first_parm_type
;
18252 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
18254 arg
= DECL_ARGUMENTS (function_or_method_type
);
18255 function_or_method_type
= TREE_TYPE (function_or_method_type
);
18260 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
18262 /* Make our first pass over the list of formal parameter types and output a
18263 DW_TAG_formal_parameter DIE for each one. */
18264 for (link
= first_parm_type
; link
; )
18266 dw_die_ref parm_die
;
18268 formal_type
= TREE_VALUE (link
);
18269 if (formal_type
== void_type_node
)
18272 /* Output a (nameless) DIE to represent the formal parameter itself. */
18273 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
18274 true /* Emit name attribute. */,
18276 if ((TREE_CODE (function_or_method_type
) == METHOD_TYPE
18277 && link
== first_parm_type
)
18278 || (arg
&& DECL_ARTIFICIAL (arg
)))
18279 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18281 link
= TREE_CHAIN (link
);
18283 arg
= TREE_CHAIN (arg
);
18286 /* If this function type has an ellipsis, add a
18287 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18288 if (formal_type
!= void_type_node
)
18289 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
18291 /* Make our second (and final) pass over the list of formal parameter types
18292 and output DIEs to represent those types (as necessary). */
18293 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
18294 link
&& TREE_VALUE (link
);
18295 link
= TREE_CHAIN (link
))
18296 gen_type_die (TREE_VALUE (link
), context_die
);
18299 /* We want to generate the DIE for TYPE so that we can generate the
18300 die for MEMBER, which has been defined; we will need to refer back
18301 to the member declaration nested within TYPE. If we're trying to
18302 generate minimal debug info for TYPE, processing TYPE won't do the
18303 trick; we need to attach the member declaration by hand. */
18306 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
18308 gen_type_die (type
, context_die
);
18310 /* If we're trying to avoid duplicate debug info, we may not have
18311 emitted the member decl for this function. Emit it now. */
18312 if (TYPE_STUB_DECL (type
)
18313 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
18314 && ! lookup_decl_die (member
))
18316 dw_die_ref type_die
;
18317 gcc_assert (!decl_ultimate_origin (member
));
18319 push_decl_scope (type
);
18320 type_die
= lookup_type_die (type
);
18321 if (TREE_CODE (member
) == FUNCTION_DECL
)
18322 gen_subprogram_die (member
, type_die
);
18323 else if (TREE_CODE (member
) == FIELD_DECL
)
18325 /* Ignore the nameless fields that are used to skip bits but handle
18326 C++ anonymous unions and structs. */
18327 if (DECL_NAME (member
) != NULL_TREE
18328 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
18329 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
18331 gen_type_die (member_declared_type (member
), type_die
);
18332 gen_field_die (member
, type_die
);
18336 gen_variable_die (member
, NULL_TREE
, type_die
);
18342 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18343 may later generate inlined and/or out-of-line instances of. */
18346 dwarf2out_abstract_function (tree decl
)
18348 dw_die_ref old_die
;
18352 htab_t old_decl_loc_table
;
18354 /* Make sure we have the actual abstract inline, not a clone. */
18355 decl
= DECL_ORIGIN (decl
);
18357 old_die
= lookup_decl_die (decl
);
18358 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
18359 /* We've already generated the abstract instance. */
18362 /* We can be called while recursively when seeing block defining inlined subroutine
18363 DIE. Be sure to not clobber the outer location table nor use it or we would
18364 get locations in abstract instantces. */
18365 old_decl_loc_table
= decl_loc_table
;
18366 decl_loc_table
= NULL
;
18368 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18369 we don't get confused by DECL_ABSTRACT. */
18370 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18372 context
= decl_class_context (decl
);
18374 gen_type_die_for_member
18375 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die
);
18378 /* Pretend we've just finished compiling this function. */
18379 save_fn
= current_function_decl
;
18380 current_function_decl
= decl
;
18381 push_cfun (DECL_STRUCT_FUNCTION (decl
));
18383 was_abstract
= DECL_ABSTRACT (decl
);
18384 set_decl_abstract_flags (decl
, 1);
18385 dwarf2out_decl (decl
);
18386 if (! was_abstract
)
18387 set_decl_abstract_flags (decl
, 0);
18389 current_function_decl
= save_fn
;
18390 decl_loc_table
= old_decl_loc_table
;
18394 /* Helper function of premark_used_types() which gets called through
18397 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18398 marked as unused by prune_unused_types. */
18401 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
18406 type
= (tree
) *slot
;
18407 die
= lookup_type_die (type
);
18409 die
->die_perennial_p
= 1;
18413 /* Helper function of premark_types_used_by_global_vars which gets called
18414 through htab_traverse.
18416 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18417 marked as unused by prune_unused_types. The DIE of the type is marked
18418 only if the global variable using the type will actually be emitted. */
18421 premark_types_used_by_global_vars_helper (void **slot
,
18422 void *data ATTRIBUTE_UNUSED
)
18424 struct types_used_by_vars_entry
*entry
;
18427 entry
= (struct types_used_by_vars_entry
*) *slot
;
18428 gcc_assert (entry
->type
!= NULL
18429 && entry
->var_decl
!= NULL
);
18430 die
= lookup_type_die (entry
->type
);
18433 /* Ask cgraph if the global variable really is to be emitted.
18434 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18435 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
18436 if (node
&& node
->needed
)
18438 die
->die_perennial_p
= 1;
18439 /* Keep the parent DIEs as well. */
18440 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
18441 die
->die_perennial_p
= 1;
18447 /* Mark all members of used_types_hash as perennial. */
18450 premark_used_types (void)
18452 if (cfun
&& cfun
->used_types_hash
)
18453 htab_traverse (cfun
->used_types_hash
, premark_used_types_helper
, NULL
);
18456 /* Mark all members of types_used_by_vars_entry as perennial. */
18459 premark_types_used_by_global_vars (void)
18461 if (types_used_by_vars_hash
)
18462 htab_traverse (types_used_by_vars_hash
,
18463 premark_types_used_by_global_vars_helper
, NULL
);
18466 /* Generate a DIE to represent a declared function (either file-scope or
18470 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
18472 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
18473 tree origin
= decl_ultimate_origin (decl
);
18474 dw_die_ref subr_die
;
18477 dw_die_ref old_die
= lookup_decl_die (decl
);
18478 int declaration
= (current_function_decl
!= decl
18479 || class_or_namespace_scope_p (context_die
));
18481 premark_used_types ();
18483 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
18484 started to generate the abstract instance of an inline, decided to output
18485 its containing class, and proceeded to emit the declaration of the inline
18486 from the member list for the class. If so, DECLARATION takes priority;
18487 we'll get back to the abstract instance when done with the class. */
18489 /* The class-scope declaration DIE must be the primary DIE. */
18490 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
18493 gcc_assert (!old_die
);
18496 /* Now that the C++ front end lazily declares artificial member fns, we
18497 might need to retrofit the declaration into its class. */
18498 if (!declaration
&& !origin
&& !old_die
18499 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
18500 && !class_or_namespace_scope_p (context_die
)
18501 && debug_info_level
> DINFO_LEVEL_TERSE
)
18502 old_die
= force_decl_die (decl
);
18504 if (origin
!= NULL
)
18506 gcc_assert (!declaration
|| local_scope_p (context_die
));
18508 /* Fixup die_parent for the abstract instance of a nested
18509 inline function. */
18510 if (old_die
&& old_die
->die_parent
== NULL
)
18511 add_child_die (context_die
, old_die
);
18513 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18514 add_abstract_origin_attribute (subr_die
, origin
);
18518 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18519 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18521 if (!get_AT_flag (old_die
, DW_AT_declaration
)
18522 /* We can have a normal definition following an inline one in the
18523 case of redefinition of GNU C extern inlines.
18524 It seems reasonable to use AT_specification in this case. */
18525 && !get_AT (old_die
, DW_AT_inline
))
18527 /* Detect and ignore this case, where we are trying to output
18528 something we have already output. */
18532 /* If the definition comes from the same place as the declaration,
18533 maybe use the old DIE. We always want the DIE for this function
18534 that has the *_pc attributes to be under comp_unit_die so the
18535 debugger can find it. We also need to do this for abstract
18536 instances of inlines, since the spec requires the out-of-line copy
18537 to have the same parent. For local class methods, this doesn't
18538 apply; we just use the old DIE. */
18539 if ((old_die
->die_parent
== comp_unit_die
|| context_die
== NULL
)
18540 && (DECL_ARTIFICIAL (decl
)
18541 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
18542 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
18543 == (unsigned) s
.line
))))
18545 subr_die
= old_die
;
18547 /* Clear out the declaration attribute and the formal parameters.
18548 Do not remove all children, because it is possible that this
18549 declaration die was forced using force_decl_die(). In such
18550 cases die that forced declaration die (e.g. TAG_imported_module)
18551 is one of the children that we do not want to remove. */
18552 remove_AT (subr_die
, DW_AT_declaration
);
18553 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
18557 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18558 add_AT_specification (subr_die
, old_die
);
18559 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18560 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
18561 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18562 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
18567 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18569 if (TREE_PUBLIC (decl
))
18570 add_AT_flag (subr_die
, DW_AT_external
, 1);
18572 add_name_and_src_coords_attributes (subr_die
, decl
);
18573 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18575 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
18576 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18577 0, 0, context_die
);
18580 add_pure_or_virtual_attribute (subr_die
, decl
);
18581 if (DECL_ARTIFICIAL (decl
))
18582 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18584 if (TREE_PROTECTED (decl
))
18585 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
18586 else if (TREE_PRIVATE (decl
))
18587 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
18592 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18594 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
18596 /* If this is an explicit function declaration then generate
18597 a DW_AT_explicit attribute. */
18598 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
18599 && (dwarf_version
>= 3 || !dwarf_strict
))
18600 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
18602 /* The first time we see a member function, it is in the context of
18603 the class to which it belongs. We make sure of this by emitting
18604 the class first. The next time is the definition, which is
18605 handled above. The two may come from the same source text.
18607 Note that force_decl_die() forces function declaration die. It is
18608 later reused to represent definition. */
18609 equate_decl_number_to_die (decl
, subr_die
);
18612 else if (DECL_ABSTRACT (decl
))
18614 if (DECL_DECLARED_INLINE_P (decl
))
18616 if (cgraph_function_possibly_inlined_p (decl
))
18617 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
18619 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
18623 if (cgraph_function_possibly_inlined_p (decl
))
18624 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
18626 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
18629 if (DECL_DECLARED_INLINE_P (decl
)
18630 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
18631 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18633 equate_decl_number_to_die (decl
, subr_die
);
18635 else if (!DECL_EXTERNAL (decl
))
18637 HOST_WIDE_INT cfa_fb_offset
;
18639 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18640 equate_decl_number_to_die (decl
, subr_die
);
18642 if (!flag_reorder_blocks_and_partition
)
18644 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
18645 current_function_funcdef_no
);
18646 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
18647 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
18648 current_function_funcdef_no
);
18649 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
18651 #if VMS_DEBUGGING_INFO
18652 /* HP OpenVMS Industry Standard 64: DWARF Extensions
18653 Section 2.3 Prologue and Epilogue Attributes:
18654 When a breakpoint is set on entry to a function, it is generally
18655 desirable for execution to be suspended, not on the very first
18656 instruction of the function, but rather at a point after the
18657 function's frame has been set up, after any language defined local
18658 declaration processing has been completed, and before execution of
18659 the first statement of the function begins. Debuggers generally
18660 cannot properly determine where this point is. Similarly for a
18661 breakpoint set on exit from a function. The prologue and epilogue
18662 attributes allow a compiler to communicate the location(s) to use. */
18665 dw_fde_ref fde
= &fde_table
[current_funcdef_fde
];
18667 if (fde
->dw_fde_vms_end_prologue
)
18668 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
18669 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
18671 if (fde
->dw_fde_vms_begin_epilogue
)
18672 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
18673 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
18677 add_pubname (decl
, subr_die
);
18678 add_arange (decl
, subr_die
);
18681 { /* Do nothing for now; maybe need to duplicate die, one for
18682 hot section and one for cold section, then use the hot/cold
18683 section begin/end labels to generate the aranges... */
18685 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
18686 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
18687 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
18688 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
18690 add_pubname (decl, subr_die);
18691 add_arange (decl, subr_die);
18692 add_arange (decl, subr_die);
18696 #ifdef MIPS_DEBUGGING_INFO
18697 /* Add a reference to the FDE for this routine. */
18698 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
18701 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
18703 /* We define the "frame base" as the function's CFA. This is more
18704 convenient for several reasons: (1) It's stable across the prologue
18705 and epilogue, which makes it better than just a frame pointer,
18706 (2) With dwarf3, there exists a one-byte encoding that allows us
18707 to reference the .debug_frame data by proxy, but failing that,
18708 (3) We can at least reuse the code inspection and interpretation
18709 code that determines the CFA position at various points in the
18711 if (dwarf_version
>= 3)
18713 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
18714 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
18718 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
18719 if (list
->dw_loc_next
)
18720 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
18722 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
18725 /* Compute a displacement from the "steady-state frame pointer" to
18726 the CFA. The former is what all stack slots and argument slots
18727 will reference in the rtl; the later is what we've told the
18728 debugger about. We'll need to adjust all frame_base references
18729 by this displacement. */
18730 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
18732 if (cfun
->static_chain_decl
)
18733 add_AT_location_description (subr_die
, DW_AT_static_link
,
18734 loc_list_from_tree (cfun
->static_chain_decl
, 2));
18737 /* Generate child dies for template paramaters. */
18738 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18739 gen_generic_params_dies (decl
);
18741 /* Now output descriptions of the arguments for this function. This gets
18742 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
18743 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
18744 `...' at the end of the formal parameter list. In order to find out if
18745 there was a trailing ellipsis or not, we must instead look at the type
18746 associated with the FUNCTION_DECL. This will be a node of type
18747 FUNCTION_TYPE. If the chain of type nodes hanging off of this
18748 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
18749 an ellipsis at the end. */
18751 /* In the case where we are describing a mere function declaration, all we
18752 need to do here (and all we *can* do here) is to describe the *types* of
18753 its formal parameters. */
18754 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
18756 else if (declaration
)
18757 gen_formal_types_die (decl
, subr_die
);
18760 /* Generate DIEs to represent all known formal parameters. */
18761 tree parm
= DECL_ARGUMENTS (decl
);
18762 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
18763 tree generic_decl_parm
= generic_decl
18764 ? DECL_ARGUMENTS (generic_decl
)
18767 /* Now we want to walk the list of parameters of the function and
18768 emit their relevant DIEs.
18770 We consider the case of DECL being an instance of a generic function
18771 as well as it being a normal function.
18773 If DECL is an instance of a generic function we walk the
18774 parameters of the generic function declaration _and_ the parameters of
18775 DECL itself. This is useful because we want to emit specific DIEs for
18776 function parameter packs and those are declared as part of the
18777 generic function declaration. In that particular case,
18778 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
18779 That DIE has children DIEs representing the set of arguments
18780 of the pack. Note that the set of pack arguments can be empty.
18781 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
18784 Otherwise, we just consider the parameters of DECL. */
18785 while (generic_decl_parm
|| parm
)
18787 if (generic_decl_parm
18788 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
18789 gen_formal_parameter_pack_die (generic_decl_parm
,
18794 gen_decl_die (parm
, NULL
, subr_die
);
18795 parm
= TREE_CHAIN (parm
);
18798 if (generic_decl_parm
)
18799 generic_decl_parm
= TREE_CHAIN (generic_decl_parm
);
18802 /* Decide whether we need an unspecified_parameters DIE at the end.
18803 There are 2 more cases to do this for: 1) the ansi ... declaration -
18804 this is detectable when the end of the arg list is not a
18805 void_type_node 2) an unprototyped function declaration (not a
18806 definition). This just means that we have no info about the
18807 parameters at all. */
18808 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
18809 if (fn_arg_types
!= NULL
)
18811 /* This is the prototyped case, check for.... */
18812 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
18813 gen_unspecified_parameters_die (decl
, subr_die
);
18815 else if (DECL_INITIAL (decl
) == NULL_TREE
)
18816 gen_unspecified_parameters_die (decl
, subr_die
);
18819 /* Output Dwarf info for all of the stuff within the body of the function
18820 (if it has one - it may be just a declaration). */
18821 outer_scope
= DECL_INITIAL (decl
);
18823 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
18824 a function. This BLOCK actually represents the outermost binding contour
18825 for the function, i.e. the contour in which the function's formal
18826 parameters and labels get declared. Curiously, it appears that the front
18827 end doesn't actually put the PARM_DECL nodes for the current function onto
18828 the BLOCK_VARS list for this outer scope, but are strung off of the
18829 DECL_ARGUMENTS list for the function instead.
18831 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
18832 the LABEL_DECL nodes for the function however, and we output DWARF info
18833 for those in decls_for_scope. Just within the `outer_scope' there will be
18834 a BLOCK node representing the function's outermost pair of curly braces,
18835 and any blocks used for the base and member initializers of a C++
18836 constructor function. */
18837 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
18839 /* Emit a DW_TAG_variable DIE for a named return value. */
18840 if (DECL_NAME (DECL_RESULT (decl
)))
18841 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
18843 current_function_has_inlines
= 0;
18844 decls_for_scope (outer_scope
, subr_die
, 0);
18846 #if 0 && defined (MIPS_DEBUGGING_INFO)
18847 if (current_function_has_inlines
)
18849 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
18850 if (! comp_unit_has_inlines
)
18852 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
18853 comp_unit_has_inlines
= 1;
18858 /* Add the calling convention attribute if requested. */
18859 add_calling_convention_attribute (subr_die
, decl
);
18863 /* Returns a hash value for X (which really is a die_struct). */
18866 common_block_die_table_hash (const void *x
)
18868 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18869 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
18872 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18873 as decl_id and die_parent of die_struct Y. */
18876 common_block_die_table_eq (const void *x
, const void *y
)
18878 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18879 const_dw_die_ref e
= (const_dw_die_ref
) y
;
18880 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
18883 /* Generate a DIE to represent a declared data object.
18884 Either DECL or ORIGIN must be non-null. */
18887 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
18891 tree decl_or_origin
= decl
? decl
: origin
;
18892 tree ultimate_origin
;
18893 dw_die_ref var_die
;
18894 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
18895 dw_die_ref origin_die
;
18896 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
18897 || class_or_namespace_scope_p (context_die
));
18898 bool specialization_p
= false;
18900 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
18901 if (decl
|| ultimate_origin
)
18902 origin
= ultimate_origin
;
18903 com_decl
= fortran_common (decl_or_origin
, &off
);
18905 /* Symbol in common gets emitted as a child of the common block, in the form
18906 of a data member. */
18909 dw_die_ref com_die
;
18910 dw_loc_list_ref loc
;
18911 die_node com_die_arg
;
18913 var_die
= lookup_decl_die (decl_or_origin
);
18916 if (get_AT (var_die
, DW_AT_location
) == NULL
)
18918 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
18923 /* Optimize the common case. */
18924 if (single_element_loc_list_p (loc
)
18925 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18926 && loc
->expr
->dw_loc_next
== NULL
18927 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
18929 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18930 = plus_constant (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
, off
);
18932 loc_list_plus_const (loc
, off
);
18934 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18935 remove_AT (var_die
, DW_AT_declaration
);
18941 if (common_block_die_table
== NULL
)
18942 common_block_die_table
18943 = htab_create_ggc (10, common_block_die_table_hash
,
18944 common_block_die_table_eq
, NULL
);
18946 com_die_arg
.decl_id
= DECL_UID (com_decl
);
18947 com_die_arg
.die_parent
= context_die
;
18948 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
18949 loc
= loc_list_from_tree (com_decl
, 2);
18950 if (com_die
== NULL
)
18953 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
18956 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
18957 add_name_and_src_coords_attributes (com_die
, com_decl
);
18960 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18961 /* Avoid sharing the same loc descriptor between
18962 DW_TAG_common_block and DW_TAG_variable. */
18963 loc
= loc_list_from_tree (com_decl
, 2);
18965 else if (DECL_EXTERNAL (decl
))
18966 add_AT_flag (com_die
, DW_AT_declaration
, 1);
18967 add_pubname_string (cnam
, com_die
); /* ??? needed? */
18968 com_die
->decl_id
= DECL_UID (com_decl
);
18969 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
18970 *slot
= (void *) com_die
;
18972 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
18974 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18975 loc
= loc_list_from_tree (com_decl
, 2);
18976 remove_AT (com_die
, DW_AT_declaration
);
18978 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
18979 add_name_and_src_coords_attributes (var_die
, decl
);
18980 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
18981 TREE_THIS_VOLATILE (decl
), context_die
);
18982 add_AT_flag (var_die
, DW_AT_external
, 1);
18987 /* Optimize the common case. */
18988 if (single_element_loc_list_p (loc
)
18989 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18990 && loc
->expr
->dw_loc_next
== NULL
18991 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
18992 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18993 = plus_constant (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
, off
);
18995 loc_list_plus_const (loc
, off
);
18997 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18999 else if (DECL_EXTERNAL (decl
))
19000 add_AT_flag (var_die
, DW_AT_declaration
, 1);
19001 equate_decl_number_to_die (decl
, var_die
);
19005 /* If the compiler emitted a definition for the DECL declaration
19006 and if we already emitted a DIE for it, don't emit a second
19007 DIE for it again. Allow re-declarations of DECLs that are
19008 inside functions, though. */
19009 if (old_die
&& declaration
&& !local_scope_p (context_die
))
19012 /* For static data members, the declaration in the class is supposed
19013 to have DW_TAG_member tag; the specification should still be
19014 DW_TAG_variable referencing the DW_TAG_member DIE. */
19015 if (declaration
&& class_scope_p (context_die
))
19016 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
19018 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
19021 if (origin
!= NULL
)
19022 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
19024 /* Loop unrolling can create multiple blocks that refer to the same
19025 static variable, so we must test for the DW_AT_declaration flag.
19027 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19028 copy decls and set the DECL_ABSTRACT flag on them instead of
19031 ??? Duplicated blocks have been rewritten to use .debug_ranges.
19033 ??? The declare_in_namespace support causes us to get two DIEs for one
19034 variable, both of which are declarations. We want to avoid considering
19035 one to be a specification, so we must test that this DIE is not a
19037 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
19038 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
19040 /* This is a definition of a C++ class level static. */
19041 add_AT_specification (var_die
, old_die
);
19042 specialization_p
= true;
19043 if (DECL_NAME (decl
))
19045 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
19046 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
19048 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
19049 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
19051 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
19052 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
19054 if (old_die
->die_tag
== DW_TAG_member
)
19055 add_linkage_name (var_die
, decl
);
19059 add_name_and_src_coords_attributes (var_die
, decl
);
19061 if ((origin
== NULL
&& !specialization_p
)
19063 && !DECL_ABSTRACT (decl_or_origin
)
19064 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
19065 decl_function_context
19066 (decl_or_origin
))))
19068 tree type
= TREE_TYPE (decl_or_origin
);
19070 if (decl_by_reference_p (decl_or_origin
))
19071 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
19073 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
19074 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
19077 if (origin
== NULL
&& !specialization_p
)
19079 if (TREE_PUBLIC (decl
))
19080 add_AT_flag (var_die
, DW_AT_external
, 1);
19082 if (DECL_ARTIFICIAL (decl
))
19083 add_AT_flag (var_die
, DW_AT_artificial
, 1);
19085 if (TREE_PROTECTED (decl
))
19086 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19087 else if (TREE_PRIVATE (decl
))
19088 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
19092 add_AT_flag (var_die
, DW_AT_declaration
, 1);
19094 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
))
19095 equate_decl_number_to_die (decl
, var_die
);
19098 && (! DECL_ABSTRACT (decl_or_origin
)
19099 /* Local static vars are shared between all clones/inlines,
19100 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19102 || (TREE_CODE (decl_or_origin
) == VAR_DECL
19103 && TREE_STATIC (decl_or_origin
)
19104 && DECL_RTL_SET_P (decl_or_origin
)))
19105 /* When abstract origin already has DW_AT_location attribute, no need
19106 to add it again. */
19107 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
19109 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
19110 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
19111 defer_location (decl_or_origin
, var_die
);
19113 add_location_or_const_value_attribute (var_die
,
19116 add_pubname (decl_or_origin
, var_die
);
19119 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
19122 /* Generate a DIE to represent a named constant. */
19125 gen_const_die (tree decl
, dw_die_ref context_die
)
19127 dw_die_ref const_die
;
19128 tree type
= TREE_TYPE (decl
);
19130 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
19131 add_name_and_src_coords_attributes (const_die
, decl
);
19132 add_type_attribute (const_die
, type
, 1, 0, context_die
);
19133 if (TREE_PUBLIC (decl
))
19134 add_AT_flag (const_die
, DW_AT_external
, 1);
19135 if (DECL_ARTIFICIAL (decl
))
19136 add_AT_flag (const_die
, DW_AT_artificial
, 1);
19137 tree_add_const_value_attribute_for_decl (const_die
, decl
);
19140 /* Generate a DIE to represent a label identifier. */
19143 gen_label_die (tree decl
, dw_die_ref context_die
)
19145 tree origin
= decl_ultimate_origin (decl
);
19146 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
19148 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19150 if (origin
!= NULL
)
19151 add_abstract_origin_attribute (lbl_die
, origin
);
19153 add_name_and_src_coords_attributes (lbl_die
, decl
);
19155 if (DECL_ABSTRACT (decl
))
19156 equate_decl_number_to_die (decl
, lbl_die
);
19159 insn
= DECL_RTL_IF_SET (decl
);
19161 /* Deleted labels are programmer specified labels which have been
19162 eliminated because of various optimizations. We still emit them
19163 here so that it is possible to put breakpoints on them. */
19167 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
19169 /* When optimization is enabled (via -O) some parts of the compiler
19170 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19171 represent source-level labels which were explicitly declared by
19172 the user. This really shouldn't be happening though, so catch
19173 it if it ever does happen. */
19174 gcc_assert (!INSN_DELETED_P (insn
));
19176 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
19177 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19182 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19183 attributes to the DIE for a block STMT, to describe where the inlined
19184 function was called from. This is similar to add_src_coords_attributes. */
19187 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
19189 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
19191 if (dwarf_version
>= 3 || !dwarf_strict
)
19193 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
19194 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
19199 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19200 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19203 add_high_low_attributes (tree stmt
, dw_die_ref die
)
19205 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19207 if (BLOCK_FRAGMENT_CHAIN (stmt
)
19208 && (dwarf_version
>= 3 || !dwarf_strict
))
19212 if (inlined_function_outer_scope_p (stmt
))
19214 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19215 BLOCK_NUMBER (stmt
));
19216 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
19219 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
));
19221 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19224 add_ranges (chain
);
19225 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
19232 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19233 BLOCK_NUMBER (stmt
));
19234 add_AT_lbl_id (die
, DW_AT_low_pc
, label
);
19235 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
19236 BLOCK_NUMBER (stmt
));
19237 add_AT_lbl_id (die
, DW_AT_high_pc
, label
);
19241 /* Generate a DIE for a lexical block. */
19244 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19246 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
19248 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
19249 add_high_low_attributes (stmt
, stmt_die
);
19251 decls_for_scope (stmt
, stmt_die
, depth
);
19254 /* Generate a DIE for an inlined subprogram. */
19257 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
19261 /* The instance of function that is effectively being inlined shall not
19263 gcc_assert (! BLOCK_ABSTRACT (stmt
));
19265 decl
= block_ultimate_origin (stmt
);
19267 /* Emit info for the abstract instance first, if we haven't yet. We
19268 must emit this even if the block is abstract, otherwise when we
19269 emit the block below (or elsewhere), we may end up trying to emit
19270 a die whose origin die hasn't been emitted, and crashing. */
19271 dwarf2out_abstract_function (decl
);
19273 if (! BLOCK_ABSTRACT (stmt
))
19275 dw_die_ref subr_die
19276 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
19278 add_abstract_origin_attribute (subr_die
, decl
);
19279 if (TREE_ASM_WRITTEN (stmt
))
19280 add_high_low_attributes (stmt
, subr_die
);
19281 add_call_src_coords_attributes (stmt
, subr_die
);
19283 decls_for_scope (stmt
, subr_die
, depth
);
19284 current_function_has_inlines
= 1;
19288 /* Generate a DIE for a field in a record, or structure. */
19291 gen_field_die (tree decl
, dw_die_ref context_die
)
19293 dw_die_ref decl_die
;
19295 if (TREE_TYPE (decl
) == error_mark_node
)
19298 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
19299 add_name_and_src_coords_attributes (decl_die
, decl
);
19300 add_type_attribute (decl_die
, member_declared_type (decl
),
19301 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
19304 if (DECL_BIT_FIELD_TYPE (decl
))
19306 add_byte_size_attribute (decl_die
, decl
);
19307 add_bit_size_attribute (decl_die
, decl
);
19308 add_bit_offset_attribute (decl_die
, decl
);
19311 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
19312 add_data_member_location_attribute (decl_die
, decl
);
19314 if (DECL_ARTIFICIAL (decl
))
19315 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19317 if (TREE_PROTECTED (decl
))
19318 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19319 else if (TREE_PRIVATE (decl
))
19320 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
19322 /* Equate decl number to die, so that we can look up this decl later on. */
19323 equate_decl_number_to_die (decl
, decl_die
);
19327 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19328 Use modified_type_die instead.
19329 We keep this code here just in case these types of DIEs may be needed to
19330 represent certain things in other languages (e.g. Pascal) someday. */
19333 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
19336 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
19338 equate_type_number_to_die (type
, ptr_die
);
19339 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19340 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19343 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19344 Use modified_type_die instead.
19345 We keep this code here just in case these types of DIEs may be needed to
19346 represent certain things in other languages (e.g. Pascal) someday. */
19349 gen_reference_type_die (tree type
, dw_die_ref context_die
)
19351 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
19353 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
19354 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
19356 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
19358 equate_type_number_to_die (type
, ref_die
);
19359 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
19360 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19364 /* Generate a DIE for a pointer to a member type. */
19367 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
19370 = new_die (DW_TAG_ptr_to_member_type
,
19371 scope_die_for (type
, context_die
), type
);
19373 equate_type_number_to_die (type
, ptr_die
);
19374 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
19375 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
19376 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19379 /* Generate the DIE for the compilation unit. */
19382 gen_compile_unit_die (const char *filename
)
19385 char producer
[250];
19386 const char *language_string
= lang_hooks
.name
;
19389 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
19393 add_name_attribute (die
, filename
);
19394 /* Don't add cwd for <built-in>. */
19395 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
19396 add_comp_dir_attribute (die
);
19399 sprintf (producer
, "%s %s", language_string
, version_string
);
19401 #ifdef MIPS_DEBUGGING_INFO
19402 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
19403 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
19404 not appear in the producer string, the debugger reaches the conclusion
19405 that the object file is stripped and has no debugging information.
19406 To get the MIPS/SGI debugger to believe that there is debugging
19407 information in the object file, we add a -g to the producer string. */
19408 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19409 strcat (producer
, " -g");
19412 add_AT_string (die
, DW_AT_producer
, producer
);
19414 language
= DW_LANG_C89
;
19415 if (strcmp (language_string
, "GNU C++") == 0)
19416 language
= DW_LANG_C_plus_plus
;
19417 else if (strcmp (language_string
, "GNU F77") == 0)
19418 language
= DW_LANG_Fortran77
;
19419 else if (strcmp (language_string
, "GNU Pascal") == 0)
19420 language
= DW_LANG_Pascal83
;
19421 else if (dwarf_version
>= 3 || !dwarf_strict
)
19423 if (strcmp (language_string
, "GNU Ada") == 0)
19424 language
= DW_LANG_Ada95
;
19425 else if (strcmp (language_string
, "GNU Fortran") == 0)
19426 language
= DW_LANG_Fortran95
;
19427 else if (strcmp (language_string
, "GNU Java") == 0)
19428 language
= DW_LANG_Java
;
19429 else if (strcmp (language_string
, "GNU Objective-C") == 0)
19430 language
= DW_LANG_ObjC
;
19431 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
19432 language
= DW_LANG_ObjC_plus_plus
;
19435 add_AT_unsigned (die
, DW_AT_language
, language
);
19439 case DW_LANG_Fortran77
:
19440 case DW_LANG_Fortran90
:
19441 case DW_LANG_Fortran95
:
19442 /* Fortran has case insensitive identifiers and the front-end
19443 lowercases everything. */
19444 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
19447 /* The default DW_ID_case_sensitive doesn't need to be specified. */
19453 /* Generate the DIE for a base class. */
19456 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
19458 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
19460 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
19461 add_data_member_location_attribute (die
, binfo
);
19463 if (BINFO_VIRTUAL_P (binfo
))
19464 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
19466 if (access
== access_public_node
)
19467 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
19468 else if (access
== access_protected_node
)
19469 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19472 /* Generate a DIE for a class member. */
19475 gen_member_die (tree type
, dw_die_ref context_die
)
19478 tree binfo
= TYPE_BINFO (type
);
19481 /* If this is not an incomplete type, output descriptions of each of its
19482 members. Note that as we output the DIEs necessary to represent the
19483 members of this record or union type, we will also be trying to output
19484 DIEs to represent the *types* of those members. However the `type'
19485 function (above) will specifically avoid generating type DIEs for member
19486 types *within* the list of member DIEs for this (containing) type except
19487 for those types (of members) which are explicitly marked as also being
19488 members of this (containing) type themselves. The g++ front- end can
19489 force any given type to be treated as a member of some other (containing)
19490 type by setting the TYPE_CONTEXT of the given (member) type to point to
19491 the TREE node representing the appropriate (containing) type. */
19493 /* First output info about the base classes. */
19496 VEC(tree
,gc
) *accesses
= BINFO_BASE_ACCESSES (binfo
);
19500 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
19501 gen_inheritance_die (base
,
19502 (accesses
? VEC_index (tree
, accesses
, i
)
19503 : access_public_node
), context_die
);
19506 /* Now output info about the data members and type members. */
19507 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
19509 /* If we thought we were generating minimal debug info for TYPE
19510 and then changed our minds, some of the member declarations
19511 may have already been defined. Don't define them again, but
19512 do put them in the right order. */
19514 child
= lookup_decl_die (member
);
19516 splice_child_die (context_die
, child
);
19518 gen_decl_die (member
, NULL
, context_die
);
19521 /* Now output info about the function members (if any). */
19522 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
19524 /* Don't include clones in the member list. */
19525 if (DECL_ABSTRACT_ORIGIN (member
))
19528 child
= lookup_decl_die (member
);
19530 splice_child_die (context_die
, child
);
19532 gen_decl_die (member
, NULL
, context_die
);
19536 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19537 is set, we pretend that the type was never defined, so we only get the
19538 member DIEs needed by later specification DIEs. */
19541 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19542 enum debug_info_usage usage
)
19544 dw_die_ref type_die
= lookup_type_die (type
);
19545 dw_die_ref scope_die
= 0;
19547 int complete
= (TYPE_SIZE (type
)
19548 && (! TYPE_STUB_DECL (type
)
19549 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19550 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19551 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19553 if (type_die
&& ! complete
)
19556 if (TYPE_CONTEXT (type
) != NULL_TREE
19557 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19558 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19561 scope_die
= scope_die_for (type
, context_die
);
19563 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
19564 /* First occurrence of type or toplevel definition of nested class. */
19566 dw_die_ref old_die
= type_die
;
19568 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19569 ? record_type_tag (type
) : DW_TAG_union_type
,
19571 equate_type_number_to_die (type
, type_die
);
19573 add_AT_specification (type_die
, old_die
);
19575 add_name_attribute (type_die
, type_tag (type
));
19578 remove_AT (type_die
, DW_AT_declaration
);
19580 /* Generate child dies for template paramaters. */
19581 if (debug_info_level
> DINFO_LEVEL_TERSE
19582 && COMPLETE_TYPE_P (type
))
19583 gen_generic_params_dies (type
);
19585 /* If this type has been completed, then give it a byte_size attribute and
19586 then give a list of members. */
19587 if (complete
&& !ns_decl
)
19589 /* Prevent infinite recursion in cases where the type of some member of
19590 this type is expressed in terms of this type itself. */
19591 TREE_ASM_WRITTEN (type
) = 1;
19592 add_byte_size_attribute (type_die
, type
);
19593 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19594 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19596 /* If the first reference to this type was as the return type of an
19597 inline function, then it may not have a parent. Fix this now. */
19598 if (type_die
->die_parent
== NULL
)
19599 add_child_die (scope_die
, type_die
);
19601 push_decl_scope (type
);
19602 gen_member_die (type
, type_die
);
19605 /* GNU extension: Record what type our vtable lives in. */
19606 if (TYPE_VFIELD (type
))
19608 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19610 gen_type_die (vtype
, context_die
);
19611 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19612 lookup_type_die (vtype
));
19617 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19619 /* We don't need to do this for function-local types. */
19620 if (TYPE_STUB_DECL (type
)
19621 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19622 VEC_safe_push (tree
, gc
, incomplete_types
, type
);
19625 if (get_AT (type_die
, DW_AT_name
))
19626 add_pubtype (type
, type_die
);
19629 /* Generate a DIE for a subroutine _type_. */
19632 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19634 tree return_type
= TREE_TYPE (type
);
19635 dw_die_ref subr_die
19636 = new_die (DW_TAG_subroutine_type
,
19637 scope_die_for (type
, context_die
), type
);
19639 equate_type_number_to_die (type
, subr_die
);
19640 add_prototyped_attribute (subr_die
, type
);
19641 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
19642 gen_formal_types_die (type
, subr_die
);
19644 if (get_AT (subr_die
, DW_AT_name
))
19645 add_pubtype (type
, subr_die
);
19648 /* Generate a DIE for a type definition. */
19651 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19653 dw_die_ref type_die
;
19656 if (TREE_ASM_WRITTEN (decl
))
19659 TREE_ASM_WRITTEN (decl
) = 1;
19660 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19661 origin
= decl_ultimate_origin (decl
);
19662 if (origin
!= NULL
)
19663 add_abstract_origin_attribute (type_die
, origin
);
19668 add_name_and_src_coords_attributes (type_die
, decl
);
19669 if (DECL_ORIGINAL_TYPE (decl
))
19671 type
= DECL_ORIGINAL_TYPE (decl
);
19673 gcc_assert (type
!= TREE_TYPE (decl
));
19674 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19678 type
= TREE_TYPE (decl
);
19680 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19682 Here, we are in the case of decl being a typedef naming
19683 an anonymous type, e.g:
19684 typedef struct {...} foo;
19685 In that case TREE_TYPE (decl) is not a typedef variant
19686 type and TYPE_NAME of the anonymous type is set to the
19687 TYPE_DECL of the typedef. This construct is emitted by
19690 TYPE is the anonymous struct named by the typedef
19691 DECL. As we need the DW_AT_type attribute of the
19692 DW_TAG_typedef to point to the DIE of TYPE, let's
19693 generate that DIE right away. add_type_attribute
19694 called below will then pick (via lookup_type_die) that
19695 anonymous struct DIE. */
19696 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
19699 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
19700 TREE_THIS_VOLATILE (decl
), context_die
);
19702 if (is_naming_typedef_decl (decl
))
19703 /* We want that all subsequent calls to lookup_type_die with
19704 TYPE in argument yield the DW_TAG_typedef we have just
19706 equate_type_number_to_die (type
, type_die
);
19709 if (DECL_ABSTRACT (decl
))
19710 equate_decl_number_to_die (decl
, type_die
);
19712 if (get_AT (type_die
, DW_AT_name
))
19713 add_pubtype (decl
, type_die
);
19716 /* Generate a DIE for a struct, class, enum or union type. */
19719 gen_tagged_type_die (tree type
,
19720 dw_die_ref context_die
,
19721 enum debug_info_usage usage
)
19725 if (type
== NULL_TREE
19726 || !is_tagged_type (type
))
19729 /* If this is a nested type whose containing class hasn't been written
19730 out yet, writing it out will cover this one, too. This does not apply
19731 to instantiations of member class templates; they need to be added to
19732 the containing class as they are generated. FIXME: This hurts the
19733 idea of combining type decls from multiple TUs, since we can't predict
19734 what set of template instantiations we'll get. */
19735 if (TYPE_CONTEXT (type
)
19736 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19737 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
19739 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
19741 if (TREE_ASM_WRITTEN (type
))
19744 /* If that failed, attach ourselves to the stub. */
19745 push_decl_scope (TYPE_CONTEXT (type
));
19746 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
19749 else if (TYPE_CONTEXT (type
) != NULL_TREE
19750 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
19752 /* If this type is local to a function that hasn't been written
19753 out yet, use a NULL context for now; it will be fixed up in
19754 decls_for_scope. */
19755 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
19760 context_die
= declare_in_namespace (type
, context_die
);
19764 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
19766 /* This might have been written out by the call to
19767 declare_in_namespace. */
19768 if (!TREE_ASM_WRITTEN (type
))
19769 gen_enumeration_type_die (type
, context_die
);
19772 gen_struct_or_union_type_die (type
, context_die
, usage
);
19777 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19778 it up if it is ever completed. gen_*_type_die will set it for us
19779 when appropriate. */
19782 /* Generate a type description DIE. */
19785 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
19786 enum debug_info_usage usage
)
19788 struct array_descr_info info
;
19790 if (type
== NULL_TREE
|| type
== error_mark_node
)
19793 /* If TYPE is a typedef type variant, let's generate debug info
19794 for the parent typedef which TYPE is a type of. */
19795 if (typedef_variant_p (type
))
19797 if (TREE_ASM_WRITTEN (type
))
19800 /* Prevent broken recursion; we can't hand off to the same type. */
19801 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
19803 /* Use the DIE of the containing namespace as the parent DIE of
19804 the type description DIE we want to generate. */
19805 if (DECL_CONTEXT (TYPE_NAME (type
))
19806 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
19807 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
19809 TREE_ASM_WRITTEN (type
) = 1;
19811 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19815 /* If type is an anonymous tagged type named by a typedef, let's
19816 generate debug info for the typedef. */
19817 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19819 /* Use the DIE of the containing namespace as the parent DIE of
19820 the type description DIE we want to generate. */
19821 if (DECL_CONTEXT (TYPE_NAME (type
))
19822 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
19823 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
19825 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19829 /* If this is an array type with hidden descriptor, handle it first. */
19830 if (!TREE_ASM_WRITTEN (type
)
19831 && lang_hooks
.types
.get_array_descr_info
19832 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
19833 && (dwarf_version
>= 3 || !dwarf_strict
))
19835 gen_descr_array_type_die (type
, &info
, context_die
);
19836 TREE_ASM_WRITTEN (type
) = 1;
19840 /* We are going to output a DIE to represent the unqualified version
19841 of this type (i.e. without any const or volatile qualifiers) so
19842 get the main variant (i.e. the unqualified version) of this type
19843 now. (Vectors are special because the debugging info is in the
19844 cloned type itself). */
19845 if (TREE_CODE (type
) != VECTOR_TYPE
)
19846 type
= type_main_variant (type
);
19848 if (TREE_ASM_WRITTEN (type
))
19851 switch (TREE_CODE (type
))
19857 case REFERENCE_TYPE
:
19858 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19859 ensures that the gen_type_die recursion will terminate even if the
19860 type is recursive. Recursive types are possible in Ada. */
19861 /* ??? We could perhaps do this for all types before the switch
19863 TREE_ASM_WRITTEN (type
) = 1;
19865 /* For these types, all that is required is that we output a DIE (or a
19866 set of DIEs) to represent the "basis" type. */
19867 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19868 DINFO_USAGE_IND_USE
);
19872 /* This code is used for C++ pointer-to-data-member types.
19873 Output a description of the relevant class type. */
19874 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
19875 DINFO_USAGE_IND_USE
);
19877 /* Output a description of the type of the object pointed to. */
19878 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19879 DINFO_USAGE_IND_USE
);
19881 /* Now output a DIE to represent this pointer-to-data-member type
19883 gen_ptr_to_mbr_type_die (type
, context_die
);
19886 case FUNCTION_TYPE
:
19887 /* Force out return type (in case it wasn't forced out already). */
19888 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19889 DINFO_USAGE_DIR_USE
);
19890 gen_subroutine_type_die (type
, context_die
);
19894 /* Force out return type (in case it wasn't forced out already). */
19895 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19896 DINFO_USAGE_DIR_USE
);
19897 gen_subroutine_type_die (type
, context_die
);
19901 gen_array_type_die (type
, context_die
);
19905 gen_array_type_die (type
, context_die
);
19908 case ENUMERAL_TYPE
:
19911 case QUAL_UNION_TYPE
:
19912 gen_tagged_type_die (type
, context_die
, usage
);
19918 case FIXED_POINT_TYPE
:
19921 /* No DIEs needed for fundamental types. */
19925 /* Just use DW_TAG_unspecified_type. */
19927 dw_die_ref type_die
= lookup_type_die (type
);
19928 if (type_die
== NULL
)
19930 tree name
= TYPE_NAME (type
);
19931 if (TREE_CODE (name
) == TYPE_DECL
)
19932 name
= DECL_NAME (name
);
19933 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die
, type
);
19934 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
19935 equate_type_number_to_die (type
, type_die
);
19941 gcc_unreachable ();
19944 TREE_ASM_WRITTEN (type
) = 1;
19948 gen_type_die (tree type
, dw_die_ref context_die
)
19950 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
19953 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19954 things which are local to the given block. */
19957 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19959 int must_output_die
= 0;
19962 /* Ignore blocks that are NULL. */
19963 if (stmt
== NULL_TREE
)
19966 inlined_func
= inlined_function_outer_scope_p (stmt
);
19968 /* If the block is one fragment of a non-contiguous block, do not
19969 process the variables, since they will have been done by the
19970 origin block. Do process subblocks. */
19971 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
19975 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
19976 gen_block_die (sub
, context_die
, depth
+ 1);
19981 /* Determine if we need to output any Dwarf DIEs at all to represent this
19984 /* The outer scopes for inlinings *must* always be represented. We
19985 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19986 must_output_die
= 1;
19989 /* Determine if this block directly contains any "significant"
19990 local declarations which we will need to output DIEs for. */
19991 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19992 /* We are not in terse mode so *any* local declaration counts
19993 as being a "significant" one. */
19994 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
19995 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
19996 && (TREE_USED (stmt
)
19997 || TREE_ASM_WRITTEN (stmt
)
19998 || BLOCK_ABSTRACT (stmt
)));
19999 else if ((TREE_USED (stmt
)
20000 || TREE_ASM_WRITTEN (stmt
)
20001 || BLOCK_ABSTRACT (stmt
))
20002 && !dwarf2out_ignore_block (stmt
))
20003 must_output_die
= 1;
20006 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20007 DIE for any block which contains no significant local declarations at
20008 all. Rather, in such cases we just call `decls_for_scope' so that any
20009 needed Dwarf info for any sub-blocks will get properly generated. Note
20010 that in terse mode, our definition of what constitutes a "significant"
20011 local declaration gets restricted to include only inlined function
20012 instances and local (nested) function definitions. */
20013 if (must_output_die
)
20017 /* If STMT block is abstract, that means we have been called
20018 indirectly from dwarf2out_abstract_function.
20019 That function rightfully marks the descendent blocks (of
20020 the abstract function it is dealing with) as being abstract,
20021 precisely to prevent us from emitting any
20022 DW_TAG_inlined_subroutine DIE as a descendent
20023 of an abstract function instance. So in that case, we should
20024 not call gen_inlined_subroutine_die.
20026 Later though, when cgraph asks dwarf2out to emit info
20027 for the concrete instance of the function decl into which
20028 the concrete instance of STMT got inlined, the later will lead
20029 to the generation of a DW_TAG_inlined_subroutine DIE. */
20030 if (! BLOCK_ABSTRACT (stmt
))
20031 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
20034 gen_lexical_block_die (stmt
, context_die
, depth
);
20037 decls_for_scope (stmt
, context_die
, depth
);
20040 /* Process variable DECL (or variable with origin ORIGIN) within
20041 block STMT and add it to CONTEXT_DIE. */
20043 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
20046 tree decl_or_origin
= decl
? decl
: origin
;
20048 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
20049 die
= lookup_decl_die (decl_or_origin
);
20050 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
20051 && TYPE_DECL_IS_STUB (decl_or_origin
))
20052 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
20056 if (die
!= NULL
&& die
->die_parent
== NULL
)
20057 add_child_die (context_die
, die
);
20058 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
20059 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
20060 stmt
, context_die
);
20062 gen_decl_die (decl
, origin
, context_die
);
20065 /* Generate all of the decls declared within a given scope and (recursively)
20066 all of its sub-blocks. */
20069 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
20075 /* Ignore NULL blocks. */
20076 if (stmt
== NULL_TREE
)
20079 /* Output the DIEs to represent all of the data objects and typedefs
20080 declared directly within this block but not within any nested
20081 sub-blocks. Also, nested function and tag DIEs have been
20082 generated with a parent of NULL; fix that up now. */
20083 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= TREE_CHAIN (decl
))
20084 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
20085 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
20086 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
20089 /* If we're at -g1, we're not interested in subblocks. */
20090 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20093 /* Output the DIEs to represent all sub-blocks (and the items declared
20094 therein) of this block. */
20095 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
20097 subblocks
= BLOCK_CHAIN (subblocks
))
20098 gen_block_die (subblocks
, context_die
, depth
+ 1);
20101 /* Is this a typedef we can avoid emitting? */
20104 is_redundant_typedef (const_tree decl
)
20106 if (TYPE_DECL_IS_STUB (decl
))
20109 if (DECL_ARTIFICIAL (decl
)
20110 && DECL_CONTEXT (decl
)
20111 && is_tagged_type (DECL_CONTEXT (decl
))
20112 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
20113 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
20114 /* Also ignore the artificial member typedef for the class name. */
20120 /* Return TRUE if TYPE is a typedef that names a type for linkage
20121 purposes. This kind of typedefs is produced by the C++ FE for
20124 typedef struct {...} foo;
20126 In that case, there is no typedef variant type produced for foo.
20127 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20131 is_naming_typedef_decl (const_tree decl
)
20133 if (decl
== NULL_TREE
20134 || TREE_CODE (decl
) != TYPE_DECL
20135 || !is_tagged_type (TREE_TYPE (decl
))
20136 || DECL_IS_BUILTIN (decl
)
20137 || is_redundant_typedef (decl
)
20138 /* It looks like Ada produces TYPE_DECLs that are very similar
20139 to C++ naming typedefs but that have different
20140 semantics. Let's be specific to c++ for now. */
20144 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
20145 && TYPE_NAME (TREE_TYPE (decl
)) == decl
20146 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
20147 != TYPE_NAME (TREE_TYPE (decl
))));
20150 /* Returns the DIE for a context. */
20152 static inline dw_die_ref
20153 get_context_die (tree context
)
20157 /* Find die that represents this context. */
20158 if (TYPE_P (context
))
20159 return force_type_die (TYPE_MAIN_VARIANT (context
));
20161 return force_decl_die (context
);
20163 return comp_unit_die
;
20166 /* Returns the DIE for decl. A DIE will always be returned. */
20169 force_decl_die (tree decl
)
20171 dw_die_ref decl_die
;
20172 unsigned saved_external_flag
;
20173 tree save_fn
= NULL_TREE
;
20174 decl_die
= lookup_decl_die (decl
);
20177 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
20179 decl_die
= lookup_decl_die (decl
);
20183 switch (TREE_CODE (decl
))
20185 case FUNCTION_DECL
:
20186 /* Clear current_function_decl, so that gen_subprogram_die thinks
20187 that this is a declaration. At this point, we just want to force
20188 declaration die. */
20189 save_fn
= current_function_decl
;
20190 current_function_decl
= NULL_TREE
;
20191 gen_subprogram_die (decl
, context_die
);
20192 current_function_decl
= save_fn
;
20196 /* Set external flag to force declaration die. Restore it after
20197 gen_decl_die() call. */
20198 saved_external_flag
= DECL_EXTERNAL (decl
);
20199 DECL_EXTERNAL (decl
) = 1;
20200 gen_decl_die (decl
, NULL
, context_die
);
20201 DECL_EXTERNAL (decl
) = saved_external_flag
;
20204 case NAMESPACE_DECL
:
20205 if (dwarf_version
>= 3 || !dwarf_strict
)
20206 dwarf2out_decl (decl
);
20208 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
20209 decl_die
= comp_unit_die
;
20213 gcc_unreachable ();
20216 /* We should be able to find the DIE now. */
20218 decl_die
= lookup_decl_die (decl
);
20219 gcc_assert (decl_die
);
20225 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
20226 always returned. */
20229 force_type_die (tree type
)
20231 dw_die_ref type_die
;
20233 type_die
= lookup_type_die (type
);
20236 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
20238 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
20239 TYPE_VOLATILE (type
), context_die
);
20240 gcc_assert (type_die
);
20245 /* Force out any required namespaces to be able to output DECL,
20246 and return the new context_die for it, if it's changed. */
20249 setup_namespace_context (tree thing
, dw_die_ref context_die
)
20251 tree context
= (DECL_P (thing
)
20252 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
20253 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
20254 /* Force out the namespace. */
20255 context_die
= force_decl_die (context
);
20257 return context_die
;
20260 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
20261 type) within its namespace, if appropriate.
20263 For compatibility with older debuggers, namespace DIEs only contain
20264 declarations; all definitions are emitted at CU scope. */
20267 declare_in_namespace (tree thing
, dw_die_ref context_die
)
20269 dw_die_ref ns_context
;
20271 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20272 return context_die
;
20274 /* If this decl is from an inlined function, then don't try to emit it in its
20275 namespace, as we will get confused. It would have already been emitted
20276 when the abstract instance of the inline function was emitted anyways. */
20277 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
20278 return context_die
;
20280 ns_context
= setup_namespace_context (thing
, context_die
);
20282 if (ns_context
!= context_die
)
20286 if (DECL_P (thing
))
20287 gen_decl_die (thing
, NULL
, ns_context
);
20289 gen_type_die (thing
, ns_context
);
20291 return context_die
;
20294 /* Generate a DIE for a namespace or namespace alias. */
20297 gen_namespace_die (tree decl
, dw_die_ref context_die
)
20299 dw_die_ref namespace_die
;
20301 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
20302 they are an alias of. */
20303 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
20305 /* Output a real namespace or module. */
20306 context_die
= setup_namespace_context (decl
, comp_unit_die
);
20307 namespace_die
= new_die (is_fortran ()
20308 ? DW_TAG_module
: DW_TAG_namespace
,
20309 context_die
, decl
);
20310 /* For Fortran modules defined in different CU don't add src coords. */
20311 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
20313 const char *name
= dwarf2_name (decl
, 0);
20315 add_name_attribute (namespace_die
, name
);
20318 add_name_and_src_coords_attributes (namespace_die
, decl
);
20319 if (DECL_EXTERNAL (decl
))
20320 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
20321 equate_decl_number_to_die (decl
, namespace_die
);
20325 /* Output a namespace alias. */
20327 /* Force out the namespace we are an alias of, if necessary. */
20328 dw_die_ref origin_die
20329 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
20331 if (DECL_CONTEXT (decl
) == NULL_TREE
20332 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
20333 context_die
= setup_namespace_context (decl
, comp_unit_die
);
20334 /* Now create the namespace alias DIE. */
20335 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
20336 add_name_and_src_coords_attributes (namespace_die
, decl
);
20337 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
20338 equate_decl_number_to_die (decl
, namespace_die
);
20342 /* Generate Dwarf debug information for a decl described by DECL. */
20345 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
20347 tree decl_or_origin
= decl
? decl
: origin
;
20348 tree class_origin
= NULL
, ultimate_origin
;
20350 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
20353 switch (TREE_CODE (decl_or_origin
))
20359 if (!is_fortran ())
20361 /* The individual enumerators of an enum type get output when we output
20362 the Dwarf representation of the relevant enum type itself. */
20366 /* Emit its type. */
20367 gen_type_die (TREE_TYPE (decl
), context_die
);
20369 /* And its containing namespace. */
20370 context_die
= declare_in_namespace (decl
, context_die
);
20372 gen_const_die (decl
, context_die
);
20375 case FUNCTION_DECL
:
20376 /* Don't output any DIEs to represent mere function declarations,
20377 unless they are class members or explicit block externs. */
20378 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
20379 && DECL_CONTEXT (decl_or_origin
) == NULL_TREE
20380 && (current_function_decl
== NULL_TREE
20381 || DECL_ARTIFICIAL (decl_or_origin
)))
20386 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
20387 on local redeclarations of global functions. That seems broken. */
20388 if (current_function_decl
!= decl
)
20389 /* This is only a declaration. */;
20392 /* If we're emitting a clone, emit info for the abstract instance. */
20393 if (origin
|| DECL_ORIGIN (decl
) != decl
)
20394 dwarf2out_abstract_function (origin
20395 ? DECL_ORIGIN (origin
)
20396 : DECL_ABSTRACT_ORIGIN (decl
));
20398 /* If we're emitting an out-of-line copy of an inline function,
20399 emit info for the abstract instance and set up to refer to it. */
20400 else if (cgraph_function_possibly_inlined_p (decl
)
20401 && ! DECL_ABSTRACT (decl
)
20402 && ! class_or_namespace_scope_p (context_die
)
20403 /* dwarf2out_abstract_function won't emit a die if this is just
20404 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
20405 that case, because that works only if we have a die. */
20406 && DECL_INITIAL (decl
) != NULL_TREE
)
20408 dwarf2out_abstract_function (decl
);
20409 set_decl_origin_self (decl
);
20412 /* Otherwise we're emitting the primary DIE for this decl. */
20413 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20415 /* Before we describe the FUNCTION_DECL itself, make sure that we
20416 have described its return type. */
20417 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
20419 /* And its virtual context. */
20420 if (DECL_VINDEX (decl
) != NULL_TREE
)
20421 gen_type_die (DECL_CONTEXT (decl
), context_die
);
20423 /* And its containing type. */
20425 origin
= decl_class_context (decl
);
20426 if (origin
!= NULL_TREE
)
20427 gen_type_die_for_member (origin
, decl
, context_die
);
20429 /* And its containing namespace. */
20430 context_die
= declare_in_namespace (decl
, context_die
);
20433 /* Now output a DIE to represent the function itself. */
20435 gen_subprogram_die (decl
, context_die
);
20439 /* If we are in terse mode, don't generate any DIEs to represent any
20440 actual typedefs. */
20441 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20444 /* In the special case of a TYPE_DECL node representing the declaration
20445 of some type tag, if the given TYPE_DECL is marked as having been
20446 instantiated from some other (original) TYPE_DECL node (e.g. one which
20447 was generated within the original definition of an inline function) we
20448 used to generate a special (abbreviated) DW_TAG_structure_type,
20449 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20450 should be actually referencing those DIEs, as variable DIEs with that
20451 type would be emitted already in the abstract origin, so it was always
20452 removed during unused type prunning. Don't add anything in this
20454 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
20457 if (is_redundant_typedef (decl
))
20458 gen_type_die (TREE_TYPE (decl
), context_die
);
20460 /* Output a DIE to represent the typedef itself. */
20461 gen_typedef_die (decl
, context_die
);
20465 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
20466 gen_label_die (decl
, context_die
);
20471 /* If we are in terse mode, don't generate any DIEs to represent any
20472 variable declarations or definitions. */
20473 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20476 /* Output any DIEs that are needed to specify the type of this data
20478 if (decl_by_reference_p (decl_or_origin
))
20479 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20481 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20483 /* And its containing type. */
20484 class_origin
= decl_class_context (decl_or_origin
);
20485 if (class_origin
!= NULL_TREE
)
20486 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20488 /* And its containing namespace. */
20489 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20491 /* Now output the DIE to represent the data object itself. This gets
20492 complicated because of the possibility that the VAR_DECL really
20493 represents an inlined instance of a formal parameter for an inline
20495 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20496 if (ultimate_origin
!= NULL_TREE
20497 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20498 gen_formal_parameter_die (decl
, origin
,
20499 true /* Emit name attribute. */,
20502 gen_variable_die (decl
, origin
, context_die
);
20506 /* Ignore the nameless fields that are used to skip bits but handle C++
20507 anonymous unions and structs. */
20508 if (DECL_NAME (decl
) != NULL_TREE
20509 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20510 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20512 gen_type_die (member_declared_type (decl
), context_die
);
20513 gen_field_die (decl
, context_die
);
20518 if (DECL_BY_REFERENCE (decl_or_origin
))
20519 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20521 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20522 gen_formal_parameter_die (decl
, origin
,
20523 true /* Emit name attribute. */,
20527 case NAMESPACE_DECL
:
20528 case IMPORTED_DECL
:
20529 if (dwarf_version
>= 3 || !dwarf_strict
)
20530 gen_namespace_die (decl
, context_die
);
20534 /* Probably some frontend-internal decl. Assume we don't care. */
20535 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20540 /* Output debug information for global decl DECL. Called from toplev.c after
20541 compilation proper has finished. */
20544 dwarf2out_global_decl (tree decl
)
20546 /* Output DWARF2 information for file-scope tentative data object
20547 declarations, file-scope (extern) function declarations (which
20548 had no corresponding body) and file-scope tagged type declarations
20549 and definitions which have not yet been forced out. */
20550 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20551 dwarf2out_decl (decl
);
20554 /* Output debug information for type decl DECL. Called from toplev.c
20555 and from language front ends (to record built-in types). */
20557 dwarf2out_type_decl (tree decl
, int local
)
20560 dwarf2out_decl (decl
);
20563 /* Output debug information for imported module or decl DECL.
20564 NAME is non-NULL name in the lexical block if the decl has been renamed.
20565 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20566 that DECL belongs to.
20567 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20569 dwarf2out_imported_module_or_decl_1 (tree decl
,
20571 tree lexical_block
,
20572 dw_die_ref lexical_block_die
)
20574 expanded_location xloc
;
20575 dw_die_ref imported_die
= NULL
;
20576 dw_die_ref at_import_die
;
20578 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20580 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20581 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20585 xloc
= expand_location (input_location
);
20587 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20589 at_import_die
= force_type_die (TREE_TYPE (decl
));
20590 /* For namespace N { typedef void T; } using N::T; base_type_die
20591 returns NULL, but DW_TAG_imported_declaration requires
20592 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20593 if (!at_import_die
)
20595 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20596 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20597 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20598 gcc_assert (at_import_die
);
20603 at_import_die
= lookup_decl_die (decl
);
20604 if (!at_import_die
)
20606 /* If we're trying to avoid duplicate debug info, we may not have
20607 emitted the member decl for this field. Emit it now. */
20608 if (TREE_CODE (decl
) == FIELD_DECL
)
20610 tree type
= DECL_CONTEXT (decl
);
20612 if (TYPE_CONTEXT (type
)
20613 && TYPE_P (TYPE_CONTEXT (type
))
20614 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20615 DINFO_USAGE_DIR_USE
))
20617 gen_type_die_for_member (type
, decl
,
20618 get_context_die (TYPE_CONTEXT (type
)));
20620 at_import_die
= force_decl_die (decl
);
20624 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20626 if (dwarf_version
>= 3 || !dwarf_strict
)
20627 imported_die
= new_die (DW_TAG_imported_module
,
20634 imported_die
= new_die (DW_TAG_imported_declaration
,
20638 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20639 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20641 add_AT_string (imported_die
, DW_AT_name
,
20642 IDENTIFIER_POINTER (name
));
20643 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20646 /* Output debug information for imported module or decl DECL.
20647 NAME is non-NULL name in context if the decl has been renamed.
20648 CHILD is true if decl is one of the renamed decls as part of
20649 importing whole module. */
20652 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20655 /* dw_die_ref at_import_die; */
20656 dw_die_ref scope_die
;
20658 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20663 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20664 We need decl DIE for reference and scope die. First, get DIE for the decl
20667 /* Get the scope die for decl context. Use comp_unit_die for global module
20668 or decl. If die is not found for non globals, force new die. */
20670 && TYPE_P (context
)
20671 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20674 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20677 scope_die
= get_context_die (context
);
20681 gcc_assert (scope_die
->die_child
);
20682 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
20683 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
20684 scope_die
= scope_die
->die_child
;
20687 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20688 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
20692 /* Write the debugging output for DECL. */
20695 dwarf2out_decl (tree decl
)
20697 dw_die_ref context_die
= comp_unit_die
;
20699 switch (TREE_CODE (decl
))
20704 case FUNCTION_DECL
:
20705 /* What we would really like to do here is to filter out all mere
20706 file-scope declarations of file-scope functions which are never
20707 referenced later within this translation unit (and keep all of ones
20708 that *are* referenced later on) but we aren't clairvoyant, so we have
20709 no idea which functions will be referenced in the future (i.e. later
20710 on within the current translation unit). So here we just ignore all
20711 file-scope function declarations which are not also definitions. If
20712 and when the debugger needs to know something about these functions,
20713 it will have to hunt around and find the DWARF information associated
20714 with the definition of the function.
20716 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20717 nodes represent definitions and which ones represent mere
20718 declarations. We have to check DECL_INITIAL instead. That's because
20719 the C front-end supports some weird semantics for "extern inline"
20720 function definitions. These can get inlined within the current
20721 translation unit (and thus, we need to generate Dwarf info for their
20722 abstract instances so that the Dwarf info for the concrete inlined
20723 instances can have something to refer to) but the compiler never
20724 generates any out-of-lines instances of such things (despite the fact
20725 that they *are* definitions).
20727 The important point is that the C front-end marks these "extern
20728 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20729 them anyway. Note that the C++ front-end also plays some similar games
20730 for inline function definitions appearing within include files which
20731 also contain `#pragma interface' pragmas. */
20732 if (DECL_INITIAL (decl
) == NULL_TREE
)
20735 /* If we're a nested function, initially use a parent of NULL; if we're
20736 a plain function, this will be fixed up in decls_for_scope. If
20737 we're a method, it will be ignored, since we already have a DIE. */
20738 if (decl_function_context (decl
)
20739 /* But if we're in terse mode, we don't care about scope. */
20740 && debug_info_level
> DINFO_LEVEL_TERSE
)
20741 context_die
= NULL
;
20745 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20746 declaration and if the declaration was never even referenced from
20747 within this entire compilation unit. We suppress these DIEs in
20748 order to save space in the .debug section (by eliminating entries
20749 which are probably useless). Note that we must not suppress
20750 block-local extern declarations (whether used or not) because that
20751 would screw-up the debugger's name lookup mechanism and cause it to
20752 miss things which really ought to be in scope at a given point. */
20753 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
20756 /* For local statics lookup proper context die. */
20757 if (TREE_STATIC (decl
) && decl_function_context (decl
))
20758 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20760 /* If we are in terse mode, don't generate any DIEs to represent any
20761 variable declarations or definitions. */
20762 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20767 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20769 if (!is_fortran ())
20771 if (TREE_STATIC (decl
) && decl_function_context (decl
))
20772 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20775 case NAMESPACE_DECL
:
20776 case IMPORTED_DECL
:
20777 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20779 if (lookup_decl_die (decl
) != NULL
)
20784 /* Don't emit stubs for types unless they are needed by other DIEs. */
20785 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
20788 /* Don't bother trying to generate any DIEs to represent any of the
20789 normal built-in types for the language we are compiling. */
20790 if (DECL_IS_BUILTIN (decl
))
20792 /* OK, we need to generate one for `bool' so GDB knows what type
20793 comparisons have. */
20795 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
20796 && ! DECL_IGNORED_P (decl
))
20797 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
20802 /* If we are in terse mode, don't generate any DIEs for types. */
20803 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20806 /* If we're a function-scope tag, initially use a parent of NULL;
20807 this will be fixed up in decls_for_scope. */
20808 if (decl_function_context (decl
))
20809 context_die
= NULL
;
20817 gen_decl_die (decl
, NULL
, context_die
);
20820 /* Write the debugging output for DECL. */
20823 dwarf2out_function_decl (tree decl
)
20825 dwarf2out_decl (decl
);
20827 htab_empty (decl_loc_table
);
20830 /* Output a marker (i.e. a label) for the beginning of the generated code for
20831 a lexical block. */
20834 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
20835 unsigned int blocknum
)
20837 switch_to_section (current_function_section ());
20838 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
20841 /* Output a marker (i.e. a label) for the end of the generated code for a
20845 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
20847 switch_to_section (current_function_section ());
20848 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
20851 /* Returns nonzero if it is appropriate not to emit any debugging
20852 information for BLOCK, because it doesn't contain any instructions.
20854 Don't allow this for blocks with nested functions or local classes
20855 as we would end up with orphans, and in the presence of scheduling
20856 we may end up calling them anyway. */
20859 dwarf2out_ignore_block (const_tree block
)
20864 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
20865 if (TREE_CODE (decl
) == FUNCTION_DECL
20866 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20868 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
20870 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
20871 if (TREE_CODE (decl
) == FUNCTION_DECL
20872 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20879 /* Hash table routines for file_hash. */
20882 file_table_eq (const void *p1_p
, const void *p2_p
)
20884 const struct dwarf_file_data
*const p1
=
20885 (const struct dwarf_file_data
*) p1_p
;
20886 const char *const p2
= (const char *) p2_p
;
20887 return strcmp (p1
->filename
, p2
) == 0;
20891 file_table_hash (const void *p_p
)
20893 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
20894 return htab_hash_string (p
->filename
);
20897 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20898 dwarf2out.c) and return its "index". The index of each (known) filename is
20899 just a unique number which is associated with only that one filename. We
20900 need such numbers for the sake of generating labels (in the .debug_sfnames
20901 section) and references to those files numbers (in the .debug_srcinfo
20902 and.debug_macinfo sections). If the filename given as an argument is not
20903 found in our current list, add it to the list and assign it the next
20904 available unique index number. In order to speed up searches, we remember
20905 the index of the filename was looked up last. This handles the majority of
20908 static struct dwarf_file_data
*
20909 lookup_filename (const char *file_name
)
20912 struct dwarf_file_data
* created
;
20914 /* Check to see if the file name that was searched on the previous
20915 call matches this file name. If so, return the index. */
20916 if (file_table_last_lookup
20917 && (file_name
== file_table_last_lookup
->filename
20918 || strcmp (file_table_last_lookup
->filename
, file_name
) == 0))
20919 return file_table_last_lookup
;
20921 /* Didn't match the previous lookup, search the table. */
20922 slot
= htab_find_slot_with_hash (file_table
, file_name
,
20923 htab_hash_string (file_name
), INSERT
);
20925 return (struct dwarf_file_data
*) *slot
;
20927 created
= ggc_alloc_dwarf_file_data ();
20928 created
->filename
= file_name
;
20929 created
->emitted_number
= 0;
20934 /* If the assembler will construct the file table, then translate the compiler
20935 internal file table number into the assembler file table number, and emit
20936 a .file directive if we haven't already emitted one yet. The file table
20937 numbers are different because we prune debug info for unused variables and
20938 types, which may include filenames. */
20941 maybe_emit_file (struct dwarf_file_data
* fd
)
20943 if (! fd
->emitted_number
)
20945 if (last_emitted_file
)
20946 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
20948 fd
->emitted_number
= 1;
20949 last_emitted_file
= fd
;
20951 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20953 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
20954 output_quoted_string (asm_out_file
,
20955 remap_debug_filename (fd
->filename
));
20956 fputc ('\n', asm_out_file
);
20960 return fd
->emitted_number
;
20963 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20964 That generation should happen after function debug info has been
20965 generated. The value of the attribute is the constant value of ARG. */
20968 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
20970 die_arg_entry entry
;
20975 if (!tmpl_value_parm_die_table
)
20976 tmpl_value_parm_die_table
20977 = VEC_alloc (die_arg_entry
, gc
, 32);
20981 VEC_safe_push (die_arg_entry
, gc
,
20982 tmpl_value_parm_die_table
,
20986 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20987 by append_entry_to_tmpl_value_parm_die_table. This function must
20988 be called after function DIEs have been generated. */
20991 gen_remaining_tmpl_value_param_die_attribute (void)
20993 if (tmpl_value_parm_die_table
)
20999 VEC_iterate (die_arg_entry
, tmpl_value_parm_die_table
, i
, e
);
21001 tree_add_const_value_attribute (e
->die
, e
->arg
);
21006 /* Replace DW_AT_name for the decl with name. */
21009 dwarf2out_set_name (tree decl
, tree name
)
21015 die
= TYPE_SYMTAB_DIE (decl
);
21019 dname
= dwarf2_name (name
, 0);
21023 attr
= get_AT (die
, DW_AT_name
);
21026 struct indirect_string_node
*node
;
21028 node
= find_AT_string (dname
);
21029 /* replace the string. */
21030 attr
->dw_attr_val
.v
.val_str
= node
;
21034 add_name_attribute (die
, dname
);
21037 /* Called by the final INSN scan whenever we see a direct function call.
21038 Make an entry into the direct call table, recording the point of call
21039 and a reference to the target function's debug entry. */
21042 dwarf2out_direct_call (tree targ
)
21045 tree origin
= decl_ultimate_origin (targ
);
21047 /* If this is a clone, use the abstract origin as the target. */
21051 e
.poc_label_num
= poc_label_num
++;
21052 e
.poc_decl
= current_function_decl
;
21053 e
.targ_die
= force_decl_die (targ
);
21054 VEC_safe_push (dcall_entry
, gc
, dcall_table
, &e
);
21056 /* Drop a label at the return point to mark the point of call. */
21057 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LPOC", e
.poc_label_num
);
21060 /* Returns a hash value for X (which really is a struct vcall_insn). */
21063 vcall_insn_table_hash (const void *x
)
21065 return (hashval_t
) ((const struct vcall_insn
*) x
)->insn_uid
;
21068 /* Return nonzero if insn_uid of struct vcall_insn *X is the same as
21069 insnd_uid of *Y. */
21072 vcall_insn_table_eq (const void *x
, const void *y
)
21074 return (((const struct vcall_insn
*) x
)->insn_uid
21075 == ((const struct vcall_insn
*) y
)->insn_uid
);
21078 /* Associate VTABLE_SLOT with INSN_UID in the VCALL_INSN_TABLE. */
21081 store_vcall_insn (unsigned int vtable_slot
, int insn_uid
)
21083 struct vcall_insn
*item
= ggc_alloc_vcall_insn ();
21084 struct vcall_insn
**slot
;
21087 item
->insn_uid
= insn_uid
;
21088 item
->vtable_slot
= vtable_slot
;
21089 slot
= (struct vcall_insn
**)
21090 htab_find_slot_with_hash (vcall_insn_table
, &item
,
21091 (hashval_t
) insn_uid
, INSERT
);
21095 /* Return the VTABLE_SLOT associated with INSN_UID. */
21097 static unsigned int
21098 lookup_vcall_insn (unsigned int insn_uid
)
21100 struct vcall_insn item
;
21101 struct vcall_insn
*p
;
21103 item
.insn_uid
= insn_uid
;
21104 item
.vtable_slot
= 0;
21105 p
= (struct vcall_insn
*) htab_find_with_hash (vcall_insn_table
,
21107 (hashval_t
) insn_uid
);
21109 return (unsigned int) -1;
21110 return p
->vtable_slot
;
21114 /* Called when lowering indirect calls to RTL. We make a note of INSN_UID
21115 and the OBJ_TYPE_REF_TOKEN from ADDR. For C++ virtual calls, the token
21116 is the vtable slot index that we will need to put in the virtual call
21120 dwarf2out_virtual_call_token (tree addr
, int insn_uid
)
21122 if (is_cxx() && TREE_CODE (addr
) == OBJ_TYPE_REF
)
21124 tree token
= OBJ_TYPE_REF_TOKEN (addr
);
21125 if (TREE_CODE (token
) == INTEGER_CST
)
21126 store_vcall_insn (TREE_INT_CST_LOW (token
), insn_uid
);
21130 /* Called when scheduling RTL, when a CALL_INSN is split. Copies the
21131 OBJ_TYPE_REF_TOKEN previously associated with OLD_INSN and associates it
21135 dwarf2out_copy_call_info (rtx old_insn
, rtx new_insn
)
21137 unsigned int vtable_slot
= lookup_vcall_insn (INSN_UID (old_insn
));
21139 if (vtable_slot
!= (unsigned int) -1)
21140 store_vcall_insn (vtable_slot
, INSN_UID (new_insn
));
21143 /* Called by the final INSN scan whenever we see a virtual function call.
21144 Make an entry into the virtual call table, recording the point of call
21145 and the slot index of the vtable entry used to call the virtual member
21146 function. The slot index was associated with the INSN_UID during the
21147 lowering to RTL. */
21150 dwarf2out_virtual_call (int insn_uid
)
21152 unsigned int vtable_slot
= lookup_vcall_insn (insn_uid
);
21155 if (vtable_slot
== (unsigned int) -1)
21158 e
.poc_label_num
= poc_label_num
++;
21159 e
.vtable_slot
= vtable_slot
;
21160 VEC_safe_push (vcall_entry
, gc
, vcall_table
, &e
);
21162 /* Drop a label at the return point to mark the point of call. */
21163 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LPOC", e
.poc_label_num
);
21166 /* Called by the final INSN scan whenever we see a var location. We
21167 use it to drop labels in the right places, and throw the location in
21168 our lookup table. */
21171 dwarf2out_var_location (rtx loc_note
)
21173 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
21174 struct var_loc_node
*newloc
;
21176 static const char *last_label
;
21177 static const char *last_postcall_label
;
21178 static bool last_in_cold_section_p
;
21181 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
21184 next_real
= next_real_insn (loc_note
);
21185 /* If there are no instructions which would be affected by this note,
21186 don't do anything. */
21187 if (next_real
== NULL_RTX
)
21190 /* If there were any real insns between note we processed last time
21191 and this note (or if it is the first note), clear
21192 last_{,postcall_}label so that they are not reused this time. */
21193 if (last_var_location_insn
== NULL_RTX
21194 || last_var_location_insn
!= next_real
21195 || last_in_cold_section_p
!= in_cold_section_p
)
21198 last_postcall_label
= NULL
;
21201 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
21202 newloc
= add_var_loc_to_decl (decl
, loc_note
,
21203 NOTE_DURING_CALL_P (loc_note
)
21204 ? last_postcall_label
: last_label
);
21205 if (newloc
== NULL
)
21208 /* If there were no real insns between note we processed last time
21209 and this note, use the label we emitted last time. Otherwise
21210 create a new label and emit it. */
21211 if (last_label
== NULL
)
21213 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
21214 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
21216 last_label
= ggc_strdup (loclabel
);
21219 if (!NOTE_DURING_CALL_P (loc_note
))
21220 newloc
->label
= last_label
;
21223 if (!last_postcall_label
)
21225 sprintf (loclabel
, "%s-1", last_label
);
21226 last_postcall_label
= ggc_strdup (loclabel
);
21228 newloc
->label
= last_postcall_label
;
21231 last_var_location_insn
= next_real
;
21232 last_in_cold_section_p
= in_cold_section_p
;
21235 /* We need to reset the locations at the beginning of each
21236 function. We can't do this in the end_function hook, because the
21237 declarations that use the locations won't have been output when
21238 that hook is called. Also compute have_multiple_function_sections here. */
21241 dwarf2out_begin_function (tree fun
)
21243 if (function_section (fun
) != text_section
)
21244 have_multiple_function_sections
= true;
21246 dwarf2out_note_section_used ();
21249 /* Output a label to mark the beginning of a source code line entry
21250 and record information relating to this source line, in
21251 'line_info_table' for later output of the .debug_line section. */
21254 dwarf2out_source_line (unsigned int line
, const char *filename
,
21255 int discriminator
, bool is_stmt
)
21257 static bool last_is_stmt
= true;
21259 if (debug_info_level
>= DINFO_LEVEL_NORMAL
21262 int file_num
= maybe_emit_file (lookup_filename (filename
));
21264 switch_to_section (current_function_section ());
21266 /* If requested, emit something human-readable. */
21267 if (flag_debug_asm
)
21268 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
21271 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21273 /* Emit the .loc directive understood by GNU as. */
21274 fprintf (asm_out_file
, "\t.loc %d %d 0", file_num
, line
);
21275 if (is_stmt
!= last_is_stmt
)
21277 fprintf (asm_out_file
, " is_stmt %d", is_stmt
? 1 : 0);
21278 last_is_stmt
= is_stmt
;
21280 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
21281 fprintf (asm_out_file
, " discriminator %d", discriminator
);
21282 fputc ('\n', asm_out_file
);
21284 /* Indicate that line number info exists. */
21285 line_info_table_in_use
++;
21287 else if (function_section (current_function_decl
) != text_section
)
21289 dw_separate_line_info_ref line_info
;
21290 targetm
.asm_out
.internal_label (asm_out_file
,
21291 SEPARATE_LINE_CODE_LABEL
,
21292 separate_line_info_table_in_use
);
21294 /* Expand the line info table if necessary. */
21295 if (separate_line_info_table_in_use
21296 == separate_line_info_table_allocated
)
21298 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
21299 separate_line_info_table
21300 = GGC_RESIZEVEC (dw_separate_line_info_entry
,
21301 separate_line_info_table
,
21302 separate_line_info_table_allocated
);
21303 memset (separate_line_info_table
21304 + separate_line_info_table_in_use
,
21306 (LINE_INFO_TABLE_INCREMENT
21307 * sizeof (dw_separate_line_info_entry
)));
21310 /* Add the new entry at the end of the line_info_table. */
21312 = &separate_line_info_table
[separate_line_info_table_in_use
++];
21313 line_info
->dw_file_num
= file_num
;
21314 line_info
->dw_line_num
= line
;
21315 line_info
->function
= current_function_funcdef_no
;
21319 dw_line_info_ref line_info
;
21321 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
,
21322 line_info_table_in_use
);
21324 /* Expand the line info table if necessary. */
21325 if (line_info_table_in_use
== line_info_table_allocated
)
21327 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
21329 = GGC_RESIZEVEC (dw_line_info_entry
, line_info_table
,
21330 line_info_table_allocated
);
21331 memset (line_info_table
+ line_info_table_in_use
, 0,
21332 LINE_INFO_TABLE_INCREMENT
* sizeof (dw_line_info_entry
));
21335 /* Add the new entry at the end of the line_info_table. */
21336 line_info
= &line_info_table
[line_info_table_in_use
++];
21337 line_info
->dw_file_num
= file_num
;
21338 line_info
->dw_line_num
= line
;
21343 /* Record the beginning of a new source file. */
21346 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21348 if (flag_eliminate_dwarf2_dups
&& dwarf_version
< 4)
21350 /* Record the beginning of the file for break_out_includes. */
21351 dw_die_ref bincl_die
;
21353 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die
, NULL
);
21354 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21357 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21359 int file_num
= maybe_emit_file (lookup_filename (filename
));
21361 switch_to_section (debug_macinfo_section
);
21362 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
21363 dw2_asm_output_data_uleb128 (lineno
, "Included from line number %d",
21366 dw2_asm_output_data_uleb128 (file_num
, "file %s", filename
);
21370 /* Record the end of a source file. */
21373 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21375 if (flag_eliminate_dwarf2_dups
&& dwarf_version
< 4)
21376 /* Record the end of the file for break_out_includes. */
21377 new_die (DW_TAG_GNU_EINCL
, comp_unit_die
, NULL
);
21379 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21381 switch_to_section (debug_macinfo_section
);
21382 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
21386 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21387 the tail part of the directive line, i.e. the part which is past the
21388 initial whitespace, #, whitespace, directive-name, whitespace part. */
21391 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
21392 const char *buffer ATTRIBUTE_UNUSED
)
21394 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21396 switch_to_section (debug_macinfo_section
);
21397 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
21398 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
21399 dw2_asm_output_nstring (buffer
, -1, "The macro");
21403 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21404 the tail part of the directive line, i.e. the part which is past the
21405 initial whitespace, #, whitespace, directive-name, whitespace part. */
21408 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21409 const char *buffer ATTRIBUTE_UNUSED
)
21411 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21413 switch_to_section (debug_macinfo_section
);
21414 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
21415 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
21416 dw2_asm_output_nstring (buffer
, -1, "The macro");
21420 /* Set up for Dwarf output at the start of compilation. */
21423 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
21425 /* Allocate the file_table. */
21426 file_table
= htab_create_ggc (50, file_table_hash
,
21427 file_table_eq
, NULL
);
21429 /* Allocate the decl_die_table. */
21430 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
21431 decl_die_table_eq
, NULL
);
21433 /* Allocate the decl_loc_table. */
21434 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
21435 decl_loc_table_eq
, NULL
);
21437 /* Allocate the initial hunk of the decl_scope_table. */
21438 decl_scope_table
= VEC_alloc (tree
, gc
, 256);
21440 /* Allocate the initial hunk of the abbrev_die_table. */
21441 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
21442 (ABBREV_DIE_TABLE_INCREMENT
);
21443 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
21444 /* Zero-th entry is allocated, but unused. */
21445 abbrev_die_table_in_use
= 1;
21447 /* Allocate the initial hunk of the line_info_table. */
21448 line_info_table
= ggc_alloc_cleared_vec_dw_line_info_entry
21449 (LINE_INFO_TABLE_INCREMENT
);
21450 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
21452 /* Zero-th entry is allocated, but unused. */
21453 line_info_table_in_use
= 1;
21455 /* Allocate the pubtypes and pubnames vectors. */
21456 pubname_table
= VEC_alloc (pubname_entry
, gc
, 32);
21457 pubtype_table
= VEC_alloc (pubname_entry
, gc
, 32);
21459 /* Allocate the table that maps insn UIDs to vtable slot indexes. */
21460 vcall_insn_table
= htab_create_ggc (10, vcall_insn_table_hash
,
21461 vcall_insn_table_eq
, NULL
);
21463 /* Generate the initial DIE for the .debug section. Note that the (string)
21464 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
21465 will (typically) be a relative pathname and that this pathname should be
21466 taken as being relative to the directory from which the compiler was
21467 invoked when the given (base) source file was compiled. We will fill
21468 in this value in dwarf2out_finish. */
21469 comp_unit_die
= gen_compile_unit_die (NULL
);
21471 incomplete_types
= VEC_alloc (tree
, gc
, 64);
21473 used_rtx_array
= VEC_alloc (rtx
, gc
, 32);
21475 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
21476 SECTION_DEBUG
, NULL
);
21477 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21478 SECTION_DEBUG
, NULL
);
21479 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
21480 SECTION_DEBUG
, NULL
);
21481 debug_macinfo_section
= get_section (DEBUG_MACINFO_SECTION
,
21482 SECTION_DEBUG
, NULL
);
21483 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
21484 SECTION_DEBUG
, NULL
);
21485 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
21486 SECTION_DEBUG
, NULL
);
21487 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
21488 SECTION_DEBUG
, NULL
);
21489 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
21490 SECTION_DEBUG
, NULL
);
21491 debug_dcall_section
= get_section (DEBUG_DCALL_SECTION
,
21492 SECTION_DEBUG
, NULL
);
21493 debug_vcall_section
= get_section (DEBUG_VCALL_SECTION
,
21494 SECTION_DEBUG
, NULL
);
21495 debug_str_section
= get_section (DEBUG_STR_SECTION
,
21496 DEBUG_STR_SECTION_FLAGS
, NULL
);
21497 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
21498 SECTION_DEBUG
, NULL
);
21499 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
21500 SECTION_DEBUG
, NULL
);
21502 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
21503 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
21504 DEBUG_ABBREV_SECTION_LABEL
, 0);
21505 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
21506 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
21507 COLD_TEXT_SECTION_LABEL
, 0);
21508 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
21510 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
21511 DEBUG_INFO_SECTION_LABEL
, 0);
21512 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
21513 DEBUG_LINE_SECTION_LABEL
, 0);
21514 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
21515 DEBUG_RANGES_SECTION_LABEL
, 0);
21516 switch_to_section (debug_abbrev_section
);
21517 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
21518 switch_to_section (debug_info_section
);
21519 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
21520 switch_to_section (debug_line_section
);
21521 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
21523 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21525 switch_to_section (debug_macinfo_section
);
21526 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
21527 DEBUG_MACINFO_SECTION_LABEL
, 0);
21528 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
21531 switch_to_section (text_section
);
21532 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
21533 if (flag_reorder_blocks_and_partition
)
21535 cold_text_section
= unlikely_text_section ();
21536 switch_to_section (cold_text_section
);
21537 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
21542 /* Called before cgraph_optimize starts outputtting functions, variables
21543 and toplevel asms into assembly. */
21546 dwarf2out_assembly_start (void)
21548 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
&& dwarf2out_do_cfi_asm ())
21550 #ifndef TARGET_UNWIND_INFO
21551 if (USING_SJLJ_EXCEPTIONS
|| (!flag_unwind_tables
&& !flag_exceptions
))
21553 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
21557 /* A helper function for dwarf2out_finish called through
21558 htab_traverse. Emit one queued .debug_str string. */
21561 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
21563 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21565 if (node
->label
&& node
->refcount
)
21567 switch_to_section (debug_str_section
);
21568 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
21569 assemble_string (node
->str
, strlen (node
->str
) + 1);
21575 #if ENABLE_ASSERT_CHECKING
21576 /* Verify that all marks are clear. */
21579 verify_marks_clear (dw_die_ref die
)
21583 gcc_assert (! die
->die_mark
);
21584 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
21586 #endif /* ENABLE_ASSERT_CHECKING */
21588 /* Clear the marks for a die and its children.
21589 Be cool if the mark isn't set. */
21592 prune_unmark_dies (dw_die_ref die
)
21598 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
21601 /* Given DIE that we're marking as used, find any other dies
21602 it references as attributes and mark them as used. */
21605 prune_unused_types_walk_attribs (dw_die_ref die
)
21610 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
21612 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
21614 /* A reference to another DIE.
21615 Make sure that it will get emitted.
21616 If it was broken out into a comdat group, don't follow it. */
21617 if (dwarf_version
< 4
21618 || a
->dw_attr
== DW_AT_specification
21619 || a
->dw_attr_val
.v
.val_die_ref
.die
->die_id
.die_type_node
== NULL
)
21620 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
21622 /* Set the string's refcount to 0 so that prune_unused_types_mark
21623 accounts properly for it. */
21624 if (AT_class (a
) == dw_val_class_str
)
21625 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
21630 /* Mark DIE as being used. If DOKIDS is true, then walk down
21631 to DIE's children. */
21634 prune_unused_types_mark (dw_die_ref die
, int dokids
)
21638 if (die
->die_mark
== 0)
21640 /* We haven't done this node yet. Mark it as used. */
21643 /* We also have to mark its parents as used.
21644 (But we don't want to mark our parents' kids due to this.) */
21645 if (die
->die_parent
)
21646 prune_unused_types_mark (die
->die_parent
, 0);
21648 /* Mark any referenced nodes. */
21649 prune_unused_types_walk_attribs (die
);
21651 /* If this node is a specification,
21652 also mark the definition, if it exists. */
21653 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
21654 prune_unused_types_mark (die
->die_definition
, 1);
21657 if (dokids
&& die
->die_mark
!= 2)
21659 /* We need to walk the children, but haven't done so yet.
21660 Remember that we've walked the kids. */
21663 /* If this is an array type, we need to make sure our
21664 kids get marked, even if they're types. If we're
21665 breaking out types into comdat sections, do this
21666 for all type definitions. */
21667 if (die
->die_tag
== DW_TAG_array_type
21668 || (dwarf_version
>= 4
21669 && is_type_die (die
) && ! is_declaration_die (die
)))
21670 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
21672 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
21676 /* For local classes, look if any static member functions were emitted
21677 and if so, mark them. */
21680 prune_unused_types_walk_local_classes (dw_die_ref die
)
21684 if (die
->die_mark
== 2)
21687 switch (die
->die_tag
)
21689 case DW_TAG_structure_type
:
21690 case DW_TAG_union_type
:
21691 case DW_TAG_class_type
:
21694 case DW_TAG_subprogram
:
21695 if (!get_AT_flag (die
, DW_AT_declaration
)
21696 || die
->die_definition
!= NULL
)
21697 prune_unused_types_mark (die
, 1);
21704 /* Mark children. */
21705 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
21708 /* Walk the tree DIE and mark types that we actually use. */
21711 prune_unused_types_walk (dw_die_ref die
)
21715 /* Don't do anything if this node is already marked and
21716 children have been marked as well. */
21717 if (die
->die_mark
== 2)
21720 switch (die
->die_tag
)
21722 case DW_TAG_structure_type
:
21723 case DW_TAG_union_type
:
21724 case DW_TAG_class_type
:
21725 if (die
->die_perennial_p
)
21728 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
21729 if (c
->die_tag
== DW_TAG_subprogram
)
21732 /* Finding used static member functions inside of classes
21733 is needed just for local classes, because for other classes
21734 static member function DIEs with DW_AT_specification
21735 are emitted outside of the DW_TAG_*_type. If we ever change
21736 it, we'd need to call this even for non-local classes. */
21738 prune_unused_types_walk_local_classes (die
);
21740 /* It's a type node --- don't mark it. */
21743 case DW_TAG_const_type
:
21744 case DW_TAG_packed_type
:
21745 case DW_TAG_pointer_type
:
21746 case DW_TAG_reference_type
:
21747 case DW_TAG_rvalue_reference_type
:
21748 case DW_TAG_volatile_type
:
21749 case DW_TAG_typedef
:
21750 case DW_TAG_array_type
:
21751 case DW_TAG_interface_type
:
21752 case DW_TAG_friend
:
21753 case DW_TAG_variant_part
:
21754 case DW_TAG_enumeration_type
:
21755 case DW_TAG_subroutine_type
:
21756 case DW_TAG_string_type
:
21757 case DW_TAG_set_type
:
21758 case DW_TAG_subrange_type
:
21759 case DW_TAG_ptr_to_member_type
:
21760 case DW_TAG_file_type
:
21761 if (die
->die_perennial_p
)
21764 /* It's a type node --- don't mark it. */
21768 /* Mark everything else. */
21772 if (die
->die_mark
== 0)
21776 /* Now, mark any dies referenced from here. */
21777 prune_unused_types_walk_attribs (die
);
21782 /* Mark children. */
21783 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
21786 /* Increment the string counts on strings referred to from DIE's
21790 prune_unused_types_update_strings (dw_die_ref die
)
21795 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
21796 if (AT_class (a
) == dw_val_class_str
)
21798 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
21800 /* Avoid unnecessarily putting strings that are used less than
21801 twice in the hash table. */
21803 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
21806 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
21807 htab_hash_string (s
->str
),
21809 gcc_assert (*slot
== NULL
);
21815 /* Remove from the tree DIE any dies that aren't marked. */
21818 prune_unused_types_prune (dw_die_ref die
)
21822 gcc_assert (die
->die_mark
);
21823 prune_unused_types_update_strings (die
);
21825 if (! die
->die_child
)
21828 c
= die
->die_child
;
21830 dw_die_ref prev
= c
;
21831 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
21832 if (c
== die
->die_child
)
21834 /* No marked children between 'prev' and the end of the list. */
21836 /* No marked children at all. */
21837 die
->die_child
= NULL
;
21840 prev
->die_sib
= c
->die_sib
;
21841 die
->die_child
= prev
;
21846 if (c
!= prev
->die_sib
)
21848 prune_unused_types_prune (c
);
21849 } while (c
!= die
->die_child
);
21852 /* A helper function for dwarf2out_finish called through
21853 htab_traverse. Clear .debug_str strings that we haven't already
21854 decided to emit. */
21857 prune_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
21859 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21861 if (!node
->label
|| !node
->refcount
)
21862 htab_clear_slot (debug_str_hash
, h
);
21867 /* Remove dies representing declarations that we never use. */
21870 prune_unused_types (void)
21873 limbo_die_node
*node
;
21874 comdat_type_node
*ctnode
;
21876 dcall_entry
*dcall
;
21878 #if ENABLE_ASSERT_CHECKING
21879 /* All the marks should already be clear. */
21880 verify_marks_clear (comp_unit_die
);
21881 for (node
= limbo_die_list
; node
; node
= node
->next
)
21882 verify_marks_clear (node
->die
);
21883 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21884 verify_marks_clear (ctnode
->root_die
);
21885 #endif /* ENABLE_ASSERT_CHECKING */
21887 /* Mark types that are used in global variables. */
21888 premark_types_used_by_global_vars ();
21890 /* Set the mark on nodes that are actually used. */
21891 prune_unused_types_walk (comp_unit_die
);
21892 for (node
= limbo_die_list
; node
; node
= node
->next
)
21893 prune_unused_types_walk (node
->die
);
21894 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21896 prune_unused_types_walk (ctnode
->root_die
);
21897 prune_unused_types_mark (ctnode
->type_die
, 1);
21900 /* Also set the mark on nodes referenced from the
21901 pubname_table or arange_table. */
21902 for (i
= 0; VEC_iterate (pubname_entry
, pubname_table
, i
, pub
); i
++)
21903 prune_unused_types_mark (pub
->die
, 1);
21904 for (i
= 0; i
< arange_table_in_use
; i
++)
21905 prune_unused_types_mark (arange_table
[i
], 1);
21907 /* Mark nodes referenced from the direct call table. */
21908 for (i
= 0; VEC_iterate (dcall_entry
, dcall_table
, i
, dcall
); i
++)
21909 prune_unused_types_mark (dcall
->targ_die
, 1);
21911 /* Get rid of nodes that aren't marked; and update the string counts. */
21912 if (debug_str_hash
&& debug_str_hash_forced
)
21913 htab_traverse (debug_str_hash
, prune_indirect_string
, NULL
);
21914 else if (debug_str_hash
)
21915 htab_empty (debug_str_hash
);
21916 prune_unused_types_prune (comp_unit_die
);
21917 for (node
= limbo_die_list
; node
; node
= node
->next
)
21918 prune_unused_types_prune (node
->die
);
21919 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21920 prune_unused_types_prune (ctnode
->root_die
);
21922 /* Leave the marks clear. */
21923 prune_unmark_dies (comp_unit_die
);
21924 for (node
= limbo_die_list
; node
; node
= node
->next
)
21925 prune_unmark_dies (node
->die
);
21926 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
21927 prune_unmark_dies (ctnode
->root_die
);
21930 /* Set the parameter to true if there are any relative pathnames in
21933 file_table_relative_p (void ** slot
, void *param
)
21935 bool *p
= (bool *) param
;
21936 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
21937 if (!IS_ABSOLUTE_PATH (d
->filename
))
21945 /* Routines to manipulate hash table of comdat type units. */
21948 htab_ct_hash (const void *of
)
21951 const comdat_type_node
*const type_node
= (const comdat_type_node
*) of
;
21953 memcpy (&h
, type_node
->signature
, sizeof (h
));
21958 htab_ct_eq (const void *of1
, const void *of2
)
21960 const comdat_type_node
*const type_node_1
= (const comdat_type_node
*) of1
;
21961 const comdat_type_node
*const type_node_2
= (const comdat_type_node
*) of2
;
21963 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
21964 DWARF_TYPE_SIGNATURE_SIZE
));
21967 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
21968 to the location it would have been added, should we know its
21969 DECL_ASSEMBLER_NAME when we added other attributes. This will
21970 probably improve compactness of debug info, removing equivalent
21971 abbrevs, and hide any differences caused by deferring the
21972 computation of the assembler name, triggered by e.g. PCH. */
21975 move_linkage_attr (dw_die_ref die
)
21977 unsigned ix
= VEC_length (dw_attr_node
, die
->die_attr
);
21978 dw_attr_node linkage
= *VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
21980 gcc_assert (linkage
.dw_attr
== AT_linkage_name
);
21984 dw_attr_node
*prev
= VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
21986 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
21990 if (ix
!= VEC_length (dw_attr_node
, die
->die_attr
) - 1)
21992 VEC_pop (dw_attr_node
, die
->die_attr
);
21993 VEC_quick_insert (dw_attr_node
, die
->die_attr
, ix
, &linkage
);
21997 /* Helper function for resolve_addr, attempt to resolve
21998 one CONST_STRING, return non-zero if not successful. Similarly verify that
21999 SYMBOL_REFs refer to variables emitted in the current CU. */
22002 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
22006 if (GET_CODE (rtl
) == CONST_STRING
)
22008 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22009 tree t
= build_string (len
, XSTR (rtl
, 0));
22010 tree tlen
= build_int_cst (NULL_TREE
, len
- 1);
22012 = build_array_type (char_type_node
, build_index_type (tlen
));
22013 rtl
= lookup_constant_def (t
);
22014 if (!rtl
|| !MEM_P (rtl
))
22016 rtl
= XEXP (rtl
, 0);
22017 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
22022 if (GET_CODE (rtl
) == SYMBOL_REF
22023 && SYMBOL_REF_DECL (rtl
)
22024 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22027 if (GET_CODE (rtl
) == CONST
22028 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
22034 /* Helper function for resolve_addr, handle one location
22035 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22036 the location list couldn't be resolved. */
22039 resolve_addr_in_expr (dw_loc_descr_ref loc
)
22041 for (; loc
; loc
= loc
->dw_loc_next
)
22042 if ((loc
->dw_loc_opc
== DW_OP_addr
22043 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22044 || (loc
->dw_loc_opc
== DW_OP_implicit_value
22045 && loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
22046 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
)))
22051 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
22052 an address in .rodata section if the string literal is emitted there,
22053 or remove the containing location list or replace DW_AT_const_value
22054 with DW_AT_location and empty location expression, if it isn't found
22055 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
22056 to something that has been emitted in the current CU. */
22059 resolve_addr (dw_die_ref die
)
22063 dw_loc_list_ref
*curr
;
22066 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
22067 switch (AT_class (a
))
22069 case dw_val_class_loc_list
:
22070 curr
= AT_loc_list_ptr (a
);
22073 if (!resolve_addr_in_expr ((*curr
)->expr
))
22075 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
22076 if (next
&& (*curr
)->ll_symbol
)
22078 gcc_assert (!next
->ll_symbol
);
22079 next
->ll_symbol
= (*curr
)->ll_symbol
;
22084 curr
= &(*curr
)->dw_loc_next
;
22086 if (!AT_loc_list (a
))
22088 remove_AT (die
, a
->dw_attr
);
22092 case dw_val_class_loc
:
22093 if (!resolve_addr_in_expr (AT_loc (a
)))
22095 remove_AT (die
, a
->dw_attr
);
22099 case dw_val_class_addr
:
22100 if (a
->dw_attr
== DW_AT_const_value
22101 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
22103 remove_AT (die
, a
->dw_attr
);
22111 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
22114 /* Output stuff that dwarf requires at the end of every file,
22115 and generate the DWARF-2 debugging info. */
22118 dwarf2out_finish (const char *filename
)
22120 limbo_die_node
*node
, *next_node
;
22121 comdat_type_node
*ctnode
;
22122 htab_t comdat_type_table
;
22123 dw_die_ref die
= 0;
22126 gen_remaining_tmpl_value_param_die_attribute ();
22128 /* Add the name for the main input file now. We delayed this from
22129 dwarf2out_init to avoid complications with PCH. */
22130 add_name_attribute (comp_unit_die
, remap_debug_filename (filename
));
22131 if (!IS_ABSOLUTE_PATH (filename
))
22132 add_comp_dir_attribute (comp_unit_die
);
22133 else if (get_AT (comp_unit_die
, DW_AT_comp_dir
) == NULL
)
22136 htab_traverse (file_table
, file_table_relative_p
, &p
);
22138 add_comp_dir_attribute (comp_unit_die
);
22141 for (i
= 0; i
< VEC_length (deferred_locations
, deferred_locations_list
); i
++)
22143 add_location_or_const_value_attribute (
22144 VEC_index (deferred_locations
, deferred_locations_list
, i
)->die
,
22145 VEC_index (deferred_locations
, deferred_locations_list
, i
)->variable
,
22149 /* Traverse the limbo die list, and add parent/child links. The only
22150 dies without parents that should be here are concrete instances of
22151 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
22152 For concrete instances, we can get the parent die from the abstract
22154 for (node
= limbo_die_list
; node
; node
= next_node
)
22156 next_node
= node
->next
;
22159 if (die
->die_parent
== NULL
)
22161 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
22164 add_child_die (origin
->die_parent
, die
);
22165 else if (die
== comp_unit_die
)
22167 else if (seen_error ())
22168 /* It's OK to be confused by errors in the input. */
22169 add_child_die (comp_unit_die
, die
);
22172 /* In certain situations, the lexical block containing a
22173 nested function can be optimized away, which results
22174 in the nested function die being orphaned. Likewise
22175 with the return type of that nested function. Force
22176 this to be a child of the containing function.
22178 It may happen that even the containing function got fully
22179 inlined and optimized out. In that case we are lost and
22180 assign the empty child. This should not be big issue as
22181 the function is likely unreachable too. */
22182 tree context
= NULL_TREE
;
22184 gcc_assert (node
->created_for
);
22186 if (DECL_P (node
->created_for
))
22187 context
= DECL_CONTEXT (node
->created_for
);
22188 else if (TYPE_P (node
->created_for
))
22189 context
= TYPE_CONTEXT (node
->created_for
);
22191 gcc_assert (context
22192 && (TREE_CODE (context
) == FUNCTION_DECL
22193 || TREE_CODE (context
) == NAMESPACE_DECL
));
22195 origin
= lookup_decl_die (context
);
22197 add_child_die (origin
, die
);
22199 add_child_die (comp_unit_die
, die
);
22204 limbo_die_list
= NULL
;
22206 resolve_addr (comp_unit_die
);
22208 for (node
= deferred_asm_name
; node
; node
= node
->next
)
22210 tree decl
= node
->created_for
;
22211 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
22213 add_AT_string (node
->die
, AT_linkage_name
,
22214 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
22215 move_linkage_attr (node
->die
);
22219 deferred_asm_name
= NULL
;
22221 /* Walk through the list of incomplete types again, trying once more to
22222 emit full debugging info for them. */
22223 retry_incomplete_types ();
22225 if (flag_eliminate_unused_debug_types
)
22226 prune_unused_types ();
22228 /* Generate separate CUs for each of the include files we've seen.
22229 They will go into limbo_die_list. */
22230 if (flag_eliminate_dwarf2_dups
&& dwarf_version
< 4)
22231 break_out_includes (comp_unit_die
);
22233 /* Generate separate COMDAT sections for type DIEs. */
22234 if (dwarf_version
>= 4)
22236 break_out_comdat_types (comp_unit_die
);
22238 /* Each new type_unit DIE was added to the limbo die list when created.
22239 Since these have all been added to comdat_type_list, clear the
22241 limbo_die_list
= NULL
;
22243 /* For each new comdat type unit, copy declarations for incomplete
22244 types to make the new unit self-contained (i.e., no direct
22245 references to the main compile unit). */
22246 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22247 copy_decls_for_unworthy_types (ctnode
->root_die
);
22248 copy_decls_for_unworthy_types (comp_unit_die
);
22250 /* In the process of copying declarations from one unit to another,
22251 we may have left some declarations behind that are no longer
22252 referenced. Prune them. */
22253 prune_unused_types ();
22256 /* Traverse the DIE's and add add sibling attributes to those DIE's
22257 that have children. */
22258 add_sibling_attributes (comp_unit_die
);
22259 for (node
= limbo_die_list
; node
; node
= node
->next
)
22260 add_sibling_attributes (node
->die
);
22261 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22262 add_sibling_attributes (ctnode
->root_die
);
22264 /* Output a terminator label for the .text section. */
22265 switch_to_section (text_section
);
22266 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
22267 if (flag_reorder_blocks_and_partition
)
22269 switch_to_section (unlikely_text_section ());
22270 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
22273 /* We can only use the low/high_pc attributes if all of the code was
22275 if (!have_multiple_function_sections
22276 || !(dwarf_version
>= 3 || !dwarf_strict
))
22278 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
22279 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
22284 unsigned fde_idx
= 0;
22285 bool range_list_added
= false;
22287 /* We need to give .debug_loc and .debug_ranges an appropriate
22288 "base address". Use zero so that these addresses become
22289 absolute. Historically, we've emitted the unexpected
22290 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
22291 Emit both to give time for other tools to adapt. */
22292 add_AT_addr (comp_unit_die
, DW_AT_low_pc
, const0_rtx
);
22293 add_AT_addr (comp_unit_die
, DW_AT_entry_pc
, const0_rtx
);
22295 if (text_section_used
)
22296 add_ranges_by_labels (comp_unit_die
, text_section_label
,
22297 text_end_label
, &range_list_added
);
22298 if (flag_reorder_blocks_and_partition
&& cold_text_section_used
)
22299 add_ranges_by_labels (comp_unit_die
, cold_text_section_label
,
22300 cold_end_label
, &range_list_added
);
22302 for (fde_idx
= 0; fde_idx
< fde_table_in_use
; fde_idx
++)
22304 dw_fde_ref fde
= &fde_table
[fde_idx
];
22306 if (fde
->dw_fde_switched_sections
)
22308 if (!fde
->in_std_section
)
22309 add_ranges_by_labels (comp_unit_die
,
22310 fde
->dw_fde_hot_section_label
,
22311 fde
->dw_fde_hot_section_end_label
,
22312 &range_list_added
);
22313 if (!fde
->cold_in_std_section
)
22314 add_ranges_by_labels (comp_unit_die
,
22315 fde
->dw_fde_unlikely_section_label
,
22316 fde
->dw_fde_unlikely_section_end_label
,
22317 &range_list_added
);
22319 else if (!fde
->in_std_section
)
22320 add_ranges_by_labels (comp_unit_die
, fde
->dw_fde_begin
,
22321 fde
->dw_fde_end
, &range_list_added
);
22324 if (range_list_added
)
22328 /* Output location list section if necessary. */
22329 if (have_location_lists
)
22331 /* Output the location lists info. */
22332 switch_to_section (debug_loc_section
);
22333 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
22334 DEBUG_LOC_SECTION_LABEL
, 0);
22335 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
22336 output_location_lists (die
);
22339 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
22340 add_AT_lineptr (comp_unit_die
, DW_AT_stmt_list
,
22341 debug_line_section_label
);
22343 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22344 add_AT_macptr (comp_unit_die
, DW_AT_macro_info
, macinfo_section_label
);
22346 /* Output all of the compilation units. We put the main one last so that
22347 the offsets are available to output_pubnames. */
22348 for (node
= limbo_die_list
; node
; node
= node
->next
)
22349 output_comp_unit (node
->die
, 0);
22351 comdat_type_table
= htab_create (100, htab_ct_hash
, htab_ct_eq
, NULL
);
22352 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
22354 void **slot
= htab_find_slot (comdat_type_table
, ctnode
, INSERT
);
22356 /* Don't output duplicate types. */
22357 if (*slot
!= HTAB_EMPTY_ENTRY
)
22360 /* Add a pointer to the line table for the main compilation unit
22361 so that the debugger can make sense of DW_AT_decl_file
22363 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
22364 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
22365 debug_line_section_label
);
22367 output_comdat_type_unit (ctnode
);
22370 htab_delete (comdat_type_table
);
22372 /* Output the main compilation unit if non-empty or if .debug_macinfo
22373 has been emitted. */
22374 output_comp_unit (comp_unit_die
, debug_info_level
>= DINFO_LEVEL_VERBOSE
);
22376 /* Output the abbreviation table. */
22377 switch_to_section (debug_abbrev_section
);
22378 output_abbrev_section ();
22380 /* Output public names table if necessary. */
22381 if (!VEC_empty (pubname_entry
, pubname_table
))
22383 switch_to_section (debug_pubnames_section
);
22384 output_pubnames (pubname_table
);
22387 /* Output public types table if necessary. */
22388 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
22389 It shouldn't hurt to emit it always, since pure DWARF2 consumers
22390 simply won't look for the section. */
22391 if (!VEC_empty (pubname_entry
, pubtype_table
))
22393 switch_to_section (debug_pubtypes_section
);
22394 output_pubnames (pubtype_table
);
22397 /* Output direct and virtual call tables if necessary. */
22398 if (!VEC_empty (dcall_entry
, dcall_table
))
22400 switch_to_section (debug_dcall_section
);
22401 output_dcall_table ();
22403 if (!VEC_empty (vcall_entry
, vcall_table
))
22405 switch_to_section (debug_vcall_section
);
22406 output_vcall_table ();
22409 /* Output the address range information. We only put functions in the arange
22410 table, so don't write it out if we don't have any. */
22411 if (fde_table_in_use
)
22413 switch_to_section (debug_aranges_section
);
22417 /* Output ranges section if necessary. */
22418 if (ranges_table_in_use
)
22420 switch_to_section (debug_ranges_section
);
22421 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
22425 /* Output the source line correspondence table. We must do this
22426 even if there is no line information. Otherwise, on an empty
22427 translation unit, we will generate a present, but empty,
22428 .debug_info section. IRIX 6.5 `nm' will then complain when
22429 examining the file. This is done late so that any filenames
22430 used by the debug_info section are marked as 'used'. */
22431 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
22433 switch_to_section (debug_line_section
);
22434 output_line_info ();
22437 /* Have to end the macro section. */
22438 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22440 switch_to_section (debug_macinfo_section
);
22441 dw2_asm_output_data (1, 0, "End compilation unit");
22444 /* If we emitted any DW_FORM_strp form attribute, output the string
22446 if (debug_str_hash
)
22447 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
22451 /* This should never be used, but its address is needed for comparisons. */
22452 const struct gcc_debug_hooks dwarf2_debug_hooks
=
22456 0, /* assembly_start */
22459 0, /* start_source_file */
22460 0, /* end_source_file */
22461 0, /* begin_block */
22463 0, /* ignore_block */
22464 0, /* source_line */
22465 0, /* begin_prologue */
22466 0, /* end_prologue */
22467 0, /* begin_epilogue */
22468 0, /* end_epilogue */
22469 0, /* begin_function */
22470 0, /* end_function */
22471 0, /* function_decl */
22472 0, /* global_decl */
22474 0, /* imported_module_or_decl */
22475 0, /* deferred_inline_function */
22476 0, /* outlining_inline_function */
22478 0, /* handle_pch */
22479 0, /* var_location */
22480 0, /* switch_text_section */
22481 0, /* direct_call */
22482 0, /* virtual_call_token */
22483 0, /* copy_call_info */
22484 0, /* virtual_call */
22486 0 /* start_end_main_source_file */
22489 #endif /* DWARF2_DEBUGGING_INFO */
22491 #include "gt-dwarf2out.h"