1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
5 Contributed by Gary Funck (gary@intrepid.com).
6 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
7 Extensively modified by Jason Merrill (jason@cygnus.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
37 /* DWARF2 Abbreviation Glossary:
39 CFA = Canonical Frame Address
40 a fixed address on the stack which identifies a call frame.
41 We define it to be the value of SP just before the call insn.
42 The CFA register and offset, which may change during the course
43 of the function, are used to calculate its value at runtime.
45 CFI = Call Frame Instruction
46 an instruction for the DWARF2 abstract machine
48 CIE = Common Information Entry
49 information describing information common to one or more FDEs
51 DIE = Debugging Information Entry
53 FDE = Frame Description Entry
54 information describing the stack call frame, in particular,
55 how to restore registers
57 DW_CFA_... = DWARF2 CFA call frame instruction
58 DW_TAG_... = DWARF2 DIE tag */
62 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
84 #include "diagnostic.h"
85 #include "tree-pretty-print.h"
88 #include "langhooks.h"
93 #include "tree-pass.h"
94 #include "tree-flow.h"
96 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
97 static rtx last_var_location_insn;
99 #ifdef VMS_DEBUGGING_INFO
100 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
102 /* Define this macro to be a nonzero value if the directory specifications
103 which are output in the debug info should end with a separator. */
104 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
105 /* Define this macro to evaluate to a nonzero value if GCC should refrain
106 from generating indirect strings in DWARF2 debug information, for instance
107 if your target is stuck with an old version of GDB that is unable to
108 process them properly or uses VMS Debug. */
109 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
111 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
112 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
115 #ifndef DWARF2_UNWIND_INFO
116 #define DWARF2_UNWIND_INFO 0
119 #ifndef INCOMING_RETURN_ADDR_RTX
120 #define INCOMING_RETURN_ADDR_RTX (gcc_unreachable (), NULL_RTX)
123 #ifndef DWARF2_FRAME_INFO
124 # ifdef DWARF2_DEBUGGING_INFO
125 # define DWARF2_FRAME_INFO \
126 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
128 # define DWARF2_FRAME_INFO 0
132 /* Map register numbers held in the call frame info that gcc has
133 collected using DWARF_FRAME_REGNUM to those that should be output in
134 .debug_frame and .eh_frame. */
135 #ifndef DWARF2_FRAME_REG_OUT
136 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
139 /* Save the result of dwarf2out_do_frame across PCH. */
140 static GTY(()) bool saved_do_cfi_asm = 0;
142 /* Decide whether we want to emit frame unwind information for the current
146 dwarf2out_do_frame (void)
148 /* We want to emit correct CFA location expressions or lists, so we
149 have to return true if we're going to output debug info, even if
150 we're not going to output frame or unwind info. */
151 return (write_symbols == DWARF2_DEBUG
152 || write_symbols == VMS_AND_DWARF2_DEBUG
153 || DWARF2_FRAME_INFO || saved_do_cfi_asm
154 || (DWARF2_UNWIND_INFO
155 && (flag_unwind_tables
156 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
160 /* Decide whether to emit frame unwind via assembler directives. */
163 dwarf2out_do_cfi_asm (void)
167 #ifdef MIPS_DEBUGGING_INFO
170 if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
172 if (saved_do_cfi_asm)
174 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
177 /* Make sure the personality encoding is one the assembler can support.
178 In particular, aligned addresses can't be handled. */
179 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
180 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
182 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
183 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
186 if (!HAVE_GAS_CFI_SECTIONS_DIRECTIVE)
188 #ifdef TARGET_UNWIND_INFO
191 if (USING_SJLJ_EXCEPTIONS || (!flag_unwind_tables && !flag_exceptions))
196 saved_do_cfi_asm = true;
200 /* The size of the target's pointer type. */
202 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
205 /* Array of RTXes referenced by the debugging information, which therefore
206 must be kept around forever. */
207 static GTY(()) VEC(rtx,gc) *used_rtx_array;
209 /* A pointer to the base of a list of incomplete types which might be
210 completed at some later time. incomplete_types_list needs to be a
211 VEC(tree,gc) because we want to tell the garbage collector about
213 static GTY(()) VEC(tree,gc) *incomplete_types;
215 /* A pointer to the base of a table of references to declaration
216 scopes. This table is a display which tracks the nesting
217 of declaration scopes at the current scope and containing
218 scopes. This table is used to find the proper place to
219 define type declaration DIE's. */
220 static GTY(()) VEC(tree,gc) *decl_scope_table;
222 /* Pointers to various DWARF2 sections. */
223 static GTY(()) section *debug_info_section;
224 static GTY(()) section *debug_abbrev_section;
225 static GTY(()) section *debug_aranges_section;
226 static GTY(()) section *debug_macinfo_section;
227 static GTY(()) section *debug_line_section;
228 static GTY(()) section *debug_loc_section;
229 static GTY(()) section *debug_pubnames_section;
230 static GTY(()) section *debug_pubtypes_section;
231 static GTY(()) section *debug_dcall_section;
232 static GTY(()) section *debug_vcall_section;
233 static GTY(()) section *debug_str_section;
234 static GTY(()) section *debug_ranges_section;
235 static GTY(()) section *debug_frame_section;
237 /* Personality decl of current unit. Used only when assembler does not support
239 static GTY(()) rtx current_unit_personality;
241 /* How to start an assembler comment. */
242 #ifndef ASM_COMMENT_START
243 #define ASM_COMMENT_START ";#"
246 typedef struct dw_cfi_struct *dw_cfi_ref;
247 typedef struct dw_fde_struct *dw_fde_ref;
248 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
250 /* Call frames are described using a sequence of Call Frame
251 Information instructions. The register number, offset
252 and address fields are provided as possible operands;
253 their use is selected by the opcode field. */
255 enum dw_cfi_oprnd_type {
257 dw_cfi_oprnd_reg_num,
263 typedef union GTY(()) dw_cfi_oprnd_struct {
264 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
265 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
266 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
267 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
271 typedef struct GTY(()) dw_cfi_struct {
272 dw_cfi_ref dw_cfi_next;
273 enum dwarf_call_frame_info dw_cfi_opc;
274 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
276 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
281 /* This is how we define the location of the CFA. We use to handle it
282 as REG + OFFSET all the time, but now it can be more complex.
283 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
284 Instead of passing around REG and OFFSET, we pass a copy
285 of this structure. */
286 typedef struct GTY(()) cfa_loc {
287 HOST_WIDE_INT offset;
288 HOST_WIDE_INT base_offset;
290 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
291 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
294 /* All call frame descriptions (FDE's) in the GCC generated DWARF
295 refer to a single Common Information Entry (CIE), defined at
296 the beginning of the .debug_frame section. This use of a single
297 CIE obviates the need to keep track of multiple CIE's
298 in the DWARF generation routines below. */
300 typedef struct GTY(()) dw_fde_struct {
302 const char *dw_fde_begin;
303 const char *dw_fde_current_label;
304 const char *dw_fde_end;
305 const char *dw_fde_vms_end_prologue;
306 const char *dw_fde_vms_begin_epilogue;
307 const char *dw_fde_hot_section_label;
308 const char *dw_fde_hot_section_end_label;
309 const char *dw_fde_unlikely_section_label;
310 const char *dw_fde_unlikely_section_end_label;
311 dw_cfi_ref dw_fde_cfi;
312 dw_cfi_ref dw_fde_switch_cfi; /* Last CFI before switching sections. */
313 HOST_WIDE_INT stack_realignment;
314 unsigned funcdef_number;
315 /* Dynamic realign argument pointer register. */
316 unsigned int drap_reg;
317 /* Virtual dynamic realign argument pointer register. */
318 unsigned int vdrap_reg;
319 /* These 3 flags are copied from rtl_data in function.h. */
320 unsigned all_throwers_are_sibcalls : 1;
321 unsigned uses_eh_lsda : 1;
322 unsigned nothrow : 1;
323 /* Whether we did stack realign in this call frame. */
324 unsigned stack_realign : 1;
325 /* Whether dynamic realign argument pointer register has been saved. */
326 unsigned drap_reg_saved: 1;
327 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
328 unsigned in_std_section : 1;
329 /* True iff dw_fde_unlikely_section_label is in text_section or
330 cold_text_section. */
331 unsigned cold_in_std_section : 1;
332 /* True iff switched sections. */
333 unsigned dw_fde_switched_sections : 1;
334 /* True iff switching from cold to hot section. */
335 unsigned dw_fde_switched_cold_to_hot : 1;
339 /* Maximum size (in bytes) of an artificially generated label. */
340 #define MAX_ARTIFICIAL_LABEL_BYTES 30
342 /* The size of addresses as they appear in the Dwarf 2 data.
343 Some architectures use word addresses to refer to code locations,
344 but Dwarf 2 info always uses byte addresses. On such machines,
345 Dwarf 2 addresses need to be larger than the architecture's
347 #ifndef DWARF2_ADDR_SIZE
348 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
351 /* The size in bytes of a DWARF field indicating an offset or length
352 relative to a debug info section, specified to be 4 bytes in the
353 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
356 #ifndef DWARF_OFFSET_SIZE
357 #define DWARF_OFFSET_SIZE 4
360 /* The size in bytes of a DWARF 4 type signature. */
362 #ifndef DWARF_TYPE_SIGNATURE_SIZE
363 #define DWARF_TYPE_SIGNATURE_SIZE 8
366 /* According to the (draft) DWARF 3 specification, the initial length
367 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
368 bytes are 0xffffffff, followed by the length stored in the next 8
371 However, the SGI/MIPS ABI uses an initial length which is equal to
372 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
374 #ifndef DWARF_INITIAL_LENGTH_SIZE
375 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
378 /* Round SIZE up to the nearest BOUNDARY. */
379 #define DWARF_ROUND(SIZE,BOUNDARY) \
380 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
382 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
383 #ifndef DWARF_CIE_DATA_ALIGNMENT
384 #ifdef STACK_GROWS_DOWNWARD
385 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
387 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
391 /* CIE identifier. */
392 #if HOST_BITS_PER_WIDE_INT >= 64
393 #define DWARF_CIE_ID \
394 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
396 #define DWARF_CIE_ID DW_CIE_ID
399 /* A pointer to the base of a table that contains frame description
400 information for each routine. */
401 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
403 /* Number of elements currently allocated for fde_table. */
404 static GTY(()) unsigned fde_table_allocated;
406 /* Number of elements in fde_table currently in use. */
407 static GTY(()) unsigned fde_table_in_use;
409 /* Size (in elements) of increments by which we may expand the
411 #define FDE_TABLE_INCREMENT 256
413 /* Get the current fde_table entry we should use. */
415 static inline dw_fde_ref
418 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
421 /* A list of call frame insns for the CIE. */
422 static GTY(()) dw_cfi_ref cie_cfi_head;
424 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
425 attribute that accelerates the lookup of the FDE associated
426 with the subprogram. This variable holds the table index of the FDE
427 associated with the current function (body) definition. */
428 static unsigned current_funcdef_fde;
430 struct GTY(()) indirect_string_node {
432 unsigned int refcount;
433 enum dwarf_form form;
437 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
439 /* True if the compilation unit has location entries that reference
441 static GTY(()) bool debug_str_hash_forced = false;
443 static GTY(()) int dw2_string_counter;
444 static GTY(()) unsigned long dwarf2out_cfi_label_num;
446 /* True if the compilation unit places functions in more than one section. */
447 static GTY(()) bool have_multiple_function_sections = false;
449 /* Whether the default text and cold text sections have been used at all. */
451 static GTY(()) bool text_section_used = false;
452 static GTY(()) bool cold_text_section_used = false;
454 /* The default cold text section. */
455 static GTY(()) section *cold_text_section;
457 /* Forward declarations for functions defined in this file. */
459 static char *stripattributes (const char *);
460 static const char *dwarf_cfi_name (unsigned);
461 static dw_cfi_ref new_cfi (void);
462 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
463 static void add_fde_cfi (const char *, dw_cfi_ref);
464 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
465 static void lookup_cfa (dw_cfa_location *);
466 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
467 static void initial_return_save (rtx);
468 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
470 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
471 static void output_cfi_directive (dw_cfi_ref);
472 static void output_call_frame_info (int);
473 static void dwarf2out_note_section_used (void);
474 static void flush_queued_reg_saves (void);
475 static bool clobbers_queued_reg_save (const_rtx);
476 static void dwarf2out_frame_debug_expr (rtx, const char *);
478 /* Support for complex CFA locations. */
479 static void output_cfa_loc (dw_cfi_ref);
480 static void output_cfa_loc_raw (dw_cfi_ref);
481 static void get_cfa_from_loc_descr (dw_cfa_location *,
482 struct dw_loc_descr_struct *);
483 static struct dw_loc_descr_struct *build_cfa_loc
484 (dw_cfa_location *, HOST_WIDE_INT);
485 static struct dw_loc_descr_struct *build_cfa_aligned_loc
486 (HOST_WIDE_INT, HOST_WIDE_INT);
487 static void def_cfa_1 (const char *, dw_cfa_location *);
488 static struct dw_loc_descr_struct *mem_loc_descriptor
489 (rtx, enum machine_mode mode, enum var_init_status);
491 /* How to start an assembler comment. */
492 #ifndef ASM_COMMENT_START
493 #define ASM_COMMENT_START ";#"
496 /* Data and reference forms for relocatable data. */
497 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
498 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
500 #ifndef DEBUG_FRAME_SECTION
501 #define DEBUG_FRAME_SECTION ".debug_frame"
504 #ifndef FUNC_BEGIN_LABEL
505 #define FUNC_BEGIN_LABEL "LFB"
508 #ifndef FUNC_END_LABEL
509 #define FUNC_END_LABEL "LFE"
512 #ifndef PROLOGUE_END_LABEL
513 #define PROLOGUE_END_LABEL "LPE"
516 #ifndef EPILOGUE_BEGIN_LABEL
517 #define EPILOGUE_BEGIN_LABEL "LEB"
520 #ifndef FRAME_BEGIN_LABEL
521 #define FRAME_BEGIN_LABEL "Lframe"
523 #define CIE_AFTER_SIZE_LABEL "LSCIE"
524 #define CIE_END_LABEL "LECIE"
525 #define FDE_LABEL "LSFDE"
526 #define FDE_AFTER_SIZE_LABEL "LASFDE"
527 #define FDE_END_LABEL "LEFDE"
528 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
529 #define LINE_NUMBER_END_LABEL "LELT"
530 #define LN_PROLOG_AS_LABEL "LASLTP"
531 #define LN_PROLOG_END_LABEL "LELTP"
532 #define DIE_LABEL_PREFIX "DW"
534 /* The DWARF 2 CFA column which tracks the return address. Normally this
535 is the column for PC, or the first column after all of the hard
537 #ifndef DWARF_FRAME_RETURN_COLUMN
539 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
541 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
545 /* The mapping from gcc register number to DWARF 2 CFA column number. By
546 default, we just provide columns for all registers. */
547 #ifndef DWARF_FRAME_REGNUM
548 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
551 /* Hook used by __throw. */
554 expand_builtin_dwarf_sp_column (void)
556 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
557 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
560 /* Return a pointer to a copy of the section string name S with all
561 attributes stripped off, and an asterisk prepended (for assemble_name). */
564 stripattributes (const char *s)
566 char *stripped = XNEWVEC (char, strlen (s) + 2);
571 while (*s && *s != ',')
578 /* MEM is a memory reference for the register size table, each element of
579 which has mode MODE. Initialize column C as a return address column. */
582 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
584 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
585 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
586 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
589 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
591 static inline HOST_WIDE_INT
592 div_data_align (HOST_WIDE_INT off)
594 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
595 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
599 /* Return true if we need a signed version of a given opcode
600 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
603 need_data_align_sf_opcode (HOST_WIDE_INT off)
605 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
608 /* Generate code to initialize the register size table. */
611 expand_builtin_init_dwarf_reg_sizes (tree address)
614 enum machine_mode mode = TYPE_MODE (char_type_node);
615 rtx addr = expand_normal (address);
616 rtx mem = gen_rtx_MEM (BLKmode, addr);
617 bool wrote_return_column = false;
619 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
621 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
623 if (rnum < DWARF_FRAME_REGISTERS)
625 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
626 enum machine_mode save_mode = reg_raw_mode[i];
629 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
630 save_mode = choose_hard_reg_mode (i, 1, true);
631 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
633 if (save_mode == VOIDmode)
635 wrote_return_column = true;
637 size = GET_MODE_SIZE (save_mode);
641 emit_move_insn (adjust_address (mem, mode, offset),
642 gen_int_mode (size, mode));
646 if (!wrote_return_column)
647 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
649 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
650 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
653 targetm.init_dwarf_reg_sizes_extra (address);
656 /* Convert a DWARF call frame info. operation to its string name */
659 dwarf_cfi_name (unsigned int cfi_opc)
663 case DW_CFA_advance_loc:
664 return "DW_CFA_advance_loc";
666 return "DW_CFA_offset";
668 return "DW_CFA_restore";
672 return "DW_CFA_set_loc";
673 case DW_CFA_advance_loc1:
674 return "DW_CFA_advance_loc1";
675 case DW_CFA_advance_loc2:
676 return "DW_CFA_advance_loc2";
677 case DW_CFA_advance_loc4:
678 return "DW_CFA_advance_loc4";
679 case DW_CFA_offset_extended:
680 return "DW_CFA_offset_extended";
681 case DW_CFA_restore_extended:
682 return "DW_CFA_restore_extended";
683 case DW_CFA_undefined:
684 return "DW_CFA_undefined";
685 case DW_CFA_same_value:
686 return "DW_CFA_same_value";
687 case DW_CFA_register:
688 return "DW_CFA_register";
689 case DW_CFA_remember_state:
690 return "DW_CFA_remember_state";
691 case DW_CFA_restore_state:
692 return "DW_CFA_restore_state";
694 return "DW_CFA_def_cfa";
695 case DW_CFA_def_cfa_register:
696 return "DW_CFA_def_cfa_register";
697 case DW_CFA_def_cfa_offset:
698 return "DW_CFA_def_cfa_offset";
701 case DW_CFA_def_cfa_expression:
702 return "DW_CFA_def_cfa_expression";
703 case DW_CFA_expression:
704 return "DW_CFA_expression";
705 case DW_CFA_offset_extended_sf:
706 return "DW_CFA_offset_extended_sf";
707 case DW_CFA_def_cfa_sf:
708 return "DW_CFA_def_cfa_sf";
709 case DW_CFA_def_cfa_offset_sf:
710 return "DW_CFA_def_cfa_offset_sf";
712 /* SGI/MIPS specific */
713 case DW_CFA_MIPS_advance_loc8:
714 return "DW_CFA_MIPS_advance_loc8";
717 case DW_CFA_GNU_window_save:
718 return "DW_CFA_GNU_window_save";
719 case DW_CFA_GNU_args_size:
720 return "DW_CFA_GNU_args_size";
721 case DW_CFA_GNU_negative_offset_extended:
722 return "DW_CFA_GNU_negative_offset_extended";
725 return "DW_CFA_<unknown>";
729 /* Return a pointer to a newly allocated Call Frame Instruction. */
731 static inline dw_cfi_ref
734 dw_cfi_ref cfi = ggc_alloc_dw_cfi_node ();
736 cfi->dw_cfi_next = NULL;
737 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
738 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
743 /* Add a Call Frame Instruction to list of instructions. */
746 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
749 dw_fde_ref fde = current_fde ();
751 /* When DRAP is used, CFA is defined with an expression. Redefine
752 CFA may lead to a different CFA value. */
753 /* ??? Of course, this heuristic fails when we're annotating epilogues,
754 because of course we'll always want to redefine the CFA back to the
755 stack pointer on the way out. Where should we move this check? */
756 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
757 switch (cfi->dw_cfi_opc)
759 case DW_CFA_def_cfa_register:
760 case DW_CFA_def_cfa_offset:
761 case DW_CFA_def_cfa_offset_sf:
763 case DW_CFA_def_cfa_sf:
770 /* Find the end of the chain. */
771 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
777 /* Generate a new label for the CFI info to refer to. FORCE is true
778 if a label needs to be output even when using .cfi_* directives. */
781 dwarf2out_cfi_label (bool force)
783 static char label[20];
785 if (!force && dwarf2out_do_cfi_asm ())
787 /* In this case, we will be emitting the asm directive instead of
788 the label, so just return a placeholder to keep the rest of the
790 strcpy (label, "<do not output>");
794 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
795 ASM_OUTPUT_LABEL (asm_out_file, label);
801 /* True if remember_state should be emitted before following CFI directive. */
802 static bool emit_cfa_remember;
804 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
805 or to the CIE if LABEL is NULL. */
808 add_fde_cfi (const char *label, dw_cfi_ref cfi)
810 dw_cfi_ref *list_head;
812 if (emit_cfa_remember)
814 dw_cfi_ref cfi_remember;
816 /* Emit the state save. */
817 emit_cfa_remember = false;
818 cfi_remember = new_cfi ();
819 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
820 add_fde_cfi (label, cfi_remember);
823 list_head = &cie_cfi_head;
825 if (dwarf2out_do_cfi_asm ())
829 dw_fde_ref fde = current_fde ();
831 gcc_assert (fde != NULL);
833 /* We still have to add the cfi to the list so that lookup_cfa
834 works later on. When -g2 and above we even need to force
835 emitting of CFI labels and add to list a DW_CFA_set_loc for
836 convert_cfa_to_fb_loc_list purposes. If we're generating
837 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
838 convert_cfa_to_fb_loc_list. */
839 if (dwarf_version == 2
840 && debug_info_level > DINFO_LEVEL_TERSE
841 && (write_symbols == DWARF2_DEBUG
842 || write_symbols == VMS_AND_DWARF2_DEBUG))
844 switch (cfi->dw_cfi_opc)
846 case DW_CFA_def_cfa_offset:
847 case DW_CFA_def_cfa_offset_sf:
848 case DW_CFA_def_cfa_register:
850 case DW_CFA_def_cfa_sf:
851 case DW_CFA_def_cfa_expression:
852 case DW_CFA_restore_state:
853 if (*label == 0 || strcmp (label, "<do not output>") == 0)
854 label = dwarf2out_cfi_label (true);
856 if (fde->dw_fde_current_label == NULL
857 || strcmp (label, fde->dw_fde_current_label) != 0)
861 label = xstrdup (label);
863 /* Set the location counter to the new label. */
865 /* It doesn't metter whether DW_CFA_set_loc
866 or DW_CFA_advance_loc4 is added here, those aren't
867 emitted into assembly, only looked up by
868 convert_cfa_to_fb_loc_list. */
869 xcfi->dw_cfi_opc = DW_CFA_set_loc;
870 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
871 add_cfi (&fde->dw_fde_cfi, xcfi);
872 fde->dw_fde_current_label = label;
880 output_cfi_directive (cfi);
882 list_head = &fde->dw_fde_cfi;
884 /* ??? If this is a CFI for the CIE, we don't emit. This
885 assumes that the standard CIE contents that the assembler
886 uses matches the standard CIE contents that the compiler
887 uses. This is probably a bad assumption. I'm not quite
888 sure how to address this for now. */
892 dw_fde_ref fde = current_fde ();
894 gcc_assert (fde != NULL);
897 label = dwarf2out_cfi_label (false);
899 if (fde->dw_fde_current_label == NULL
900 || strcmp (label, fde->dw_fde_current_label) != 0)
904 label = xstrdup (label);
906 /* Set the location counter to the new label. */
908 /* If we have a current label, advance from there, otherwise
909 set the location directly using set_loc. */
910 xcfi->dw_cfi_opc = fde->dw_fde_current_label
911 ? DW_CFA_advance_loc4
913 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
914 add_cfi (&fde->dw_fde_cfi, xcfi);
916 fde->dw_fde_current_label = label;
919 list_head = &fde->dw_fde_cfi;
922 add_cfi (list_head, cfi);
925 /* Subroutine of lookup_cfa. */
928 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
930 switch (cfi->dw_cfi_opc)
932 case DW_CFA_def_cfa_offset:
933 case DW_CFA_def_cfa_offset_sf:
934 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
936 case DW_CFA_def_cfa_register:
937 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
940 case DW_CFA_def_cfa_sf:
941 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
942 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
944 case DW_CFA_def_cfa_expression:
945 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
948 case DW_CFA_remember_state:
949 gcc_assert (!remember->in_use);
951 remember->in_use = 1;
953 case DW_CFA_restore_state:
954 gcc_assert (remember->in_use);
956 remember->in_use = 0;
964 /* Find the previous value for the CFA. */
967 lookup_cfa (dw_cfa_location *loc)
971 dw_cfa_location remember;
973 memset (loc, 0, sizeof (*loc));
974 loc->reg = INVALID_REGNUM;
977 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
978 lookup_cfa_1 (cfi, loc, &remember);
980 fde = current_fde ();
982 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
983 lookup_cfa_1 (cfi, loc, &remember);
986 /* The current rule for calculating the DWARF2 canonical frame address. */
987 static dw_cfa_location cfa;
989 /* The register used for saving registers to the stack, and its offset
991 static dw_cfa_location cfa_store;
993 /* The current save location around an epilogue. */
994 static dw_cfa_location cfa_remember;
996 /* The running total of the size of arguments pushed onto the stack. */
997 static HOST_WIDE_INT args_size;
999 /* The last args_size we actually output. */
1000 static HOST_WIDE_INT old_args_size;
1002 /* Entry point to update the canonical frame address (CFA).
1003 LABEL is passed to add_fde_cfi. The value of CFA is now to be
1004 calculated from REG+OFFSET. */
1007 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1009 dw_cfa_location loc;
1011 loc.base_offset = 0;
1013 loc.offset = offset;
1014 def_cfa_1 (label, &loc);
1017 /* Determine if two dw_cfa_location structures define the same data. */
1020 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
1022 return (loc1->reg == loc2->reg
1023 && loc1->offset == loc2->offset
1024 && loc1->indirect == loc2->indirect
1025 && (loc1->indirect == 0
1026 || loc1->base_offset == loc2->base_offset));
1029 /* This routine does the actual work. The CFA is now calculated from
1030 the dw_cfa_location structure. */
1033 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
1036 dw_cfa_location old_cfa, loc;
1041 if (cfa_store.reg == loc.reg && loc.indirect == 0)
1042 cfa_store.offset = loc.offset;
1044 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
1045 lookup_cfa (&old_cfa);
1047 /* If nothing changed, no need to issue any call frame instructions. */
1048 if (cfa_equal_p (&loc, &old_cfa))
1053 if (loc.reg == old_cfa.reg && !loc.indirect && !old_cfa.indirect)
1055 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1056 the CFA register did not change but the offset did. The data
1057 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1058 in the assembler via the .cfi_def_cfa_offset directive. */
1060 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1062 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1063 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1066 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1067 else if (loc.offset == old_cfa.offset
1068 && old_cfa.reg != INVALID_REGNUM
1070 && !old_cfa.indirect)
1072 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1073 indicating the CFA register has changed to <register> but the
1074 offset has not changed. */
1075 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1076 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1080 else if (loc.indirect == 0)
1082 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1083 indicating the CFA register has changed to <register> with
1084 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1085 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1088 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1090 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1091 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1092 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1096 /* Construct a DW_CFA_def_cfa_expression instruction to
1097 calculate the CFA using a full location expression since no
1098 register-offset pair is available. */
1099 struct dw_loc_descr_struct *loc_list;
1101 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1102 loc_list = build_cfa_loc (&loc, 0);
1103 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1106 add_fde_cfi (label, cfi);
1109 /* Add the CFI for saving a register. REG is the CFA column number.
1110 LABEL is passed to add_fde_cfi.
1111 If SREG is -1, the register is saved at OFFSET from the CFA;
1112 otherwise it is saved in SREG. */
1115 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1117 dw_cfi_ref cfi = new_cfi ();
1118 dw_fde_ref fde = current_fde ();
1120 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1122 /* When stack is aligned, store REG using DW_CFA_expression with
1125 && fde->stack_realign
1126 && sreg == INVALID_REGNUM)
1128 cfi->dw_cfi_opc = DW_CFA_expression;
1129 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1130 cfi->dw_cfi_oprnd2.dw_cfi_loc
1131 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1133 else if (sreg == INVALID_REGNUM)
1135 if (need_data_align_sf_opcode (offset))
1136 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1137 else if (reg & ~0x3f)
1138 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1140 cfi->dw_cfi_opc = DW_CFA_offset;
1141 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1143 else if (sreg == reg)
1144 cfi->dw_cfi_opc = DW_CFA_same_value;
1147 cfi->dw_cfi_opc = DW_CFA_register;
1148 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1151 add_fde_cfi (label, cfi);
1154 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1155 This CFI tells the unwinder that it needs to restore the window registers
1156 from the previous frame's window save area.
1158 ??? Perhaps we should note in the CIE where windows are saved (instead of
1159 assuming 0(cfa)) and what registers are in the window. */
1162 dwarf2out_window_save (const char *label)
1164 dw_cfi_ref cfi = new_cfi ();
1166 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1167 add_fde_cfi (label, cfi);
1170 /* Entry point for saving a register to the stack. REG is the GCC register
1171 number. LABEL and OFFSET are passed to reg_save. */
1174 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1176 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1179 /* Entry point for saving the return address in the stack.
1180 LABEL and OFFSET are passed to reg_save. */
1183 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1185 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1188 /* Entry point for saving the return address in a register.
1189 LABEL and SREG are passed to reg_save. */
1192 dwarf2out_return_reg (const char *label, unsigned int sreg)
1194 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1197 /* Record the initial position of the return address. RTL is
1198 INCOMING_RETURN_ADDR_RTX. */
1201 initial_return_save (rtx rtl)
1203 unsigned int reg = INVALID_REGNUM;
1204 HOST_WIDE_INT offset = 0;
1206 switch (GET_CODE (rtl))
1209 /* RA is in a register. */
1210 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1214 /* RA is on the stack. */
1215 rtl = XEXP (rtl, 0);
1216 switch (GET_CODE (rtl))
1219 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1224 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1225 offset = INTVAL (XEXP (rtl, 1));
1229 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1230 offset = -INTVAL (XEXP (rtl, 1));
1240 /* The return address is at some offset from any value we can
1241 actually load. For instance, on the SPARC it is in %i7+8. Just
1242 ignore the offset for now; it doesn't matter for unwinding frames. */
1243 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1244 initial_return_save (XEXP (rtl, 0));
1251 if (reg != DWARF_FRAME_RETURN_COLUMN)
1252 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1255 /* Given a SET, calculate the amount of stack adjustment it
1258 static HOST_WIDE_INT
1259 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1260 HOST_WIDE_INT cur_offset)
1262 const_rtx src = SET_SRC (pattern);
1263 const_rtx dest = SET_DEST (pattern);
1264 HOST_WIDE_INT offset = 0;
1267 if (dest == stack_pointer_rtx)
1269 code = GET_CODE (src);
1271 /* Assume (set (reg sp) (reg whatever)) sets args_size
1273 if (code == REG && src != stack_pointer_rtx)
1275 offset = -cur_args_size;
1276 #ifndef STACK_GROWS_DOWNWARD
1279 return offset - cur_offset;
1282 if (! (code == PLUS || code == MINUS)
1283 || XEXP (src, 0) != stack_pointer_rtx
1284 || !CONST_INT_P (XEXP (src, 1)))
1287 /* (set (reg sp) (plus (reg sp) (const_int))) */
1288 offset = INTVAL (XEXP (src, 1));
1294 if (MEM_P (src) && !MEM_P (dest))
1298 /* (set (mem (pre_dec (reg sp))) (foo)) */
1299 src = XEXP (dest, 0);
1300 code = GET_CODE (src);
1306 if (XEXP (src, 0) == stack_pointer_rtx)
1308 rtx val = XEXP (XEXP (src, 1), 1);
1309 /* We handle only adjustments by constant amount. */
1310 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1311 && CONST_INT_P (val));
1312 offset = -INTVAL (val);
1319 if (XEXP (src, 0) == stack_pointer_rtx)
1321 offset = GET_MODE_SIZE (GET_MODE (dest));
1328 if (XEXP (src, 0) == stack_pointer_rtx)
1330 offset = -GET_MODE_SIZE (GET_MODE (dest));
1345 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1346 indexed by INSN_UID. */
1348 static HOST_WIDE_INT *barrier_args_size;
1350 /* Helper function for compute_barrier_args_size. Handle one insn. */
1352 static HOST_WIDE_INT
1353 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1354 VEC (rtx, heap) **next)
1356 HOST_WIDE_INT offset = 0;
1359 if (! RTX_FRAME_RELATED_P (insn))
1361 if (prologue_epilogue_contains (insn))
1363 else if (GET_CODE (PATTERN (insn)) == SET)
1364 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1365 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1366 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1368 /* There may be stack adjustments inside compound insns. Search
1370 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1371 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1372 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1373 cur_args_size, offset);
1378 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1382 expr = XEXP (expr, 0);
1383 if (GET_CODE (expr) == PARALLEL
1384 || GET_CODE (expr) == SEQUENCE)
1385 for (i = 1; i < XVECLEN (expr, 0); i++)
1387 rtx elem = XVECEXP (expr, 0, i);
1389 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1390 offset += stack_adjust_offset (elem, cur_args_size, offset);
1395 #ifndef STACK_GROWS_DOWNWARD
1399 cur_args_size += offset;
1400 if (cur_args_size < 0)
1405 rtx dest = JUMP_LABEL (insn);
1409 if (barrier_args_size [INSN_UID (dest)] < 0)
1411 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1412 VEC_safe_push (rtx, heap, *next, dest);
1417 return cur_args_size;
1420 /* Walk the whole function and compute args_size on BARRIERs. */
1423 compute_barrier_args_size (void)
1425 int max_uid = get_max_uid (), i;
1427 VEC (rtx, heap) *worklist, *next, *tmp;
1429 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1430 for (i = 0; i < max_uid; i++)
1431 barrier_args_size[i] = -1;
1433 worklist = VEC_alloc (rtx, heap, 20);
1434 next = VEC_alloc (rtx, heap, 20);
1435 insn = get_insns ();
1436 barrier_args_size[INSN_UID (insn)] = 0;
1437 VEC_quick_push (rtx, worklist, insn);
1440 while (!VEC_empty (rtx, worklist))
1442 rtx prev, body, first_insn;
1443 HOST_WIDE_INT cur_args_size;
1445 first_insn = insn = VEC_pop (rtx, worklist);
1446 cur_args_size = barrier_args_size[INSN_UID (insn)];
1447 prev = prev_nonnote_insn (insn);
1448 if (prev && BARRIER_P (prev))
1449 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1451 for (; insn; insn = NEXT_INSN (insn))
1453 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1455 if (BARRIER_P (insn))
1460 if (insn == first_insn)
1462 else if (barrier_args_size[INSN_UID (insn)] < 0)
1464 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1469 /* The insns starting with this label have been
1470 already scanned or are in the worklist. */
1475 body = PATTERN (insn);
1476 if (GET_CODE (body) == SEQUENCE)
1478 HOST_WIDE_INT dest_args_size = cur_args_size;
1479 for (i = 1; i < XVECLEN (body, 0); i++)
1480 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1481 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1483 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1484 dest_args_size, &next);
1487 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1488 cur_args_size, &next);
1490 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1491 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1492 dest_args_size, &next);
1495 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1496 cur_args_size, &next);
1500 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1504 if (VEC_empty (rtx, next))
1507 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1511 VEC_truncate (rtx, next, 0);
1514 VEC_free (rtx, heap, worklist);
1515 VEC_free (rtx, heap, next);
1518 /* Add a CFI to update the running total of the size of arguments
1519 pushed onto the stack. */
1522 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1526 if (size == old_args_size)
1529 old_args_size = size;
1532 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1533 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1534 add_fde_cfi (label, cfi);
1537 /* Record a stack adjustment of OFFSET bytes. */
1540 dwarf2out_stack_adjust (HOST_WIDE_INT offset, const char *label)
1542 if (cfa.reg == STACK_POINTER_REGNUM)
1543 cfa.offset += offset;
1545 if (cfa_store.reg == STACK_POINTER_REGNUM)
1546 cfa_store.offset += offset;
1548 if (ACCUMULATE_OUTGOING_ARGS)
1551 #ifndef STACK_GROWS_DOWNWARD
1555 args_size += offset;
1559 def_cfa_1 (label, &cfa);
1560 if (flag_asynchronous_unwind_tables)
1561 dwarf2out_args_size (label, args_size);
1564 /* Check INSN to see if it looks like a push or a stack adjustment, and
1565 make a note of it if it does. EH uses this information to find out
1566 how much extra space it needs to pop off the stack. */
1569 dwarf2out_notice_stack_adjust (rtx insn, bool after_p)
1571 HOST_WIDE_INT offset;
1575 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1576 with this function. Proper support would require all frame-related
1577 insns to be marked, and to be able to handle saving state around
1578 epilogues textually in the middle of the function. */
1579 if (prologue_epilogue_contains (insn))
1582 /* If INSN is an instruction from target of an annulled branch, the
1583 effects are for the target only and so current argument size
1584 shouldn't change at all. */
1586 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1587 && INSN_FROM_TARGET_P (insn))
1590 /* If only calls can throw, and we have a frame pointer,
1591 save up adjustments until we see the CALL_INSN. */
1592 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1594 if (CALL_P (insn) && !after_p)
1596 /* Extract the size of the args from the CALL rtx itself. */
1597 insn = PATTERN (insn);
1598 if (GET_CODE (insn) == PARALLEL)
1599 insn = XVECEXP (insn, 0, 0);
1600 if (GET_CODE (insn) == SET)
1601 insn = SET_SRC (insn);
1602 gcc_assert (GET_CODE (insn) == CALL);
1603 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1608 if (CALL_P (insn) && !after_p)
1610 if (!flag_asynchronous_unwind_tables)
1611 dwarf2out_args_size ("", args_size);
1614 else if (BARRIER_P (insn))
1616 /* Don't call compute_barrier_args_size () if the only
1617 BARRIER is at the end of function. */
1618 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1619 compute_barrier_args_size ();
1620 if (barrier_args_size == NULL)
1624 offset = barrier_args_size[INSN_UID (insn)];
1629 offset -= args_size;
1630 #ifndef STACK_GROWS_DOWNWARD
1634 else if (GET_CODE (PATTERN (insn)) == SET)
1635 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1636 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1637 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1639 /* There may be stack adjustments inside compound insns. Search
1641 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1642 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1643 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1652 label = dwarf2out_cfi_label (false);
1653 dwarf2out_stack_adjust (offset, label);
1656 /* We delay emitting a register save until either (a) we reach the end
1657 of the prologue or (b) the register is clobbered. This clusters
1658 register saves so that there are fewer pc advances. */
1660 struct GTY(()) queued_reg_save {
1661 struct queued_reg_save *next;
1663 HOST_WIDE_INT cfa_offset;
1667 static GTY(()) struct queued_reg_save *queued_reg_saves;
1669 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1670 struct GTY(()) reg_saved_in_data {
1675 /* A list of registers saved in other registers.
1676 The list intentionally has a small maximum capacity of 4; if your
1677 port needs more than that, you might consider implementing a
1678 more efficient data structure. */
1679 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1680 static GTY(()) size_t num_regs_saved_in_regs;
1682 static const char *last_reg_save_label;
1684 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1685 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1688 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1690 struct queued_reg_save *q;
1692 /* Duplicates waste space, but it's also necessary to remove them
1693 for correctness, since the queue gets output in reverse
1695 for (q = queued_reg_saves; q != NULL; q = q->next)
1696 if (REGNO (q->reg) == REGNO (reg))
1701 q = ggc_alloc_queued_reg_save ();
1702 q->next = queued_reg_saves;
1703 queued_reg_saves = q;
1707 q->cfa_offset = offset;
1708 q->saved_reg = sreg;
1710 last_reg_save_label = label;
1713 /* Output all the entries in QUEUED_REG_SAVES. */
1716 flush_queued_reg_saves (void)
1718 struct queued_reg_save *q;
1720 for (q = queued_reg_saves; q; q = q->next)
1723 unsigned int reg, sreg;
1725 for (i = 0; i < num_regs_saved_in_regs; i++)
1726 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1728 if (q->saved_reg && i == num_regs_saved_in_regs)
1730 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1731 num_regs_saved_in_regs++;
1733 if (i != num_regs_saved_in_regs)
1735 regs_saved_in_regs[i].orig_reg = q->reg;
1736 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1739 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1741 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1743 sreg = INVALID_REGNUM;
1744 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1747 queued_reg_saves = NULL;
1748 last_reg_save_label = NULL;
1751 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1752 location for? Or, does it clobber a register which we've previously
1753 said that some other register is saved in, and for which we now
1754 have a new location for? */
1757 clobbers_queued_reg_save (const_rtx insn)
1759 struct queued_reg_save *q;
1761 for (q = queued_reg_saves; q; q = q->next)
1764 if (modified_in_p (q->reg, insn))
1766 for (i = 0; i < num_regs_saved_in_regs; i++)
1767 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1768 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1775 /* Entry point for saving the first register into the second. */
1778 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1781 unsigned int regno, sregno;
1783 for (i = 0; i < num_regs_saved_in_regs; i++)
1784 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1786 if (i == num_regs_saved_in_regs)
1788 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1789 num_regs_saved_in_regs++;
1791 regs_saved_in_regs[i].orig_reg = reg;
1792 regs_saved_in_regs[i].saved_in_reg = sreg;
1794 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1795 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1796 reg_save (label, regno, sregno, 0);
1799 /* What register, if any, is currently saved in REG? */
1802 reg_saved_in (rtx reg)
1804 unsigned int regn = REGNO (reg);
1806 struct queued_reg_save *q;
1808 for (q = queued_reg_saves; q; q = q->next)
1809 if (q->saved_reg && regn == REGNO (q->saved_reg))
1812 for (i = 0; i < num_regs_saved_in_regs; i++)
1813 if (regs_saved_in_regs[i].saved_in_reg
1814 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1815 return regs_saved_in_regs[i].orig_reg;
1821 /* A temporary register holding an integral value used in adjusting SP
1822 or setting up the store_reg. The "offset" field holds the integer
1823 value, not an offset. */
1824 static dw_cfa_location cfa_temp;
1826 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1829 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1831 memset (&cfa, 0, sizeof (cfa));
1833 switch (GET_CODE (pat))
1836 cfa.reg = REGNO (XEXP (pat, 0));
1837 cfa.offset = INTVAL (XEXP (pat, 1));
1841 cfa.reg = REGNO (pat);
1846 pat = XEXP (pat, 0);
1847 if (GET_CODE (pat) == PLUS)
1849 cfa.base_offset = INTVAL (XEXP (pat, 1));
1850 pat = XEXP (pat, 0);
1852 cfa.reg = REGNO (pat);
1856 /* Recurse and define an expression. */
1860 def_cfa_1 (label, &cfa);
1863 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1866 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1870 gcc_assert (GET_CODE (pat) == SET);
1871 dest = XEXP (pat, 0);
1872 src = XEXP (pat, 1);
1874 switch (GET_CODE (src))
1877 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1878 cfa.offset -= INTVAL (XEXP (src, 1));
1888 cfa.reg = REGNO (dest);
1889 gcc_assert (cfa.indirect == 0);
1891 def_cfa_1 (label, &cfa);
1894 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1897 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1899 HOST_WIDE_INT offset;
1900 rtx src, addr, span;
1902 src = XEXP (set, 1);
1903 addr = XEXP (set, 0);
1904 gcc_assert (MEM_P (addr));
1905 addr = XEXP (addr, 0);
1907 /* As documented, only consider extremely simple addresses. */
1908 switch (GET_CODE (addr))
1911 gcc_assert (REGNO (addr) == cfa.reg);
1912 offset = -cfa.offset;
1915 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
1916 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
1922 span = targetm.dwarf_register_span (src);
1924 /* ??? We'd like to use queue_reg_save, but we need to come up with
1925 a different flushing heuristic for epilogues. */
1927 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
1930 /* We have a PARALLEL describing where the contents of SRC live.
1931 Queue register saves for each piece of the PARALLEL. */
1934 HOST_WIDE_INT span_offset = offset;
1936 gcc_assert (GET_CODE (span) == PARALLEL);
1938 limit = XVECLEN (span, 0);
1939 for (par_index = 0; par_index < limit; par_index++)
1941 rtx elem = XVECEXP (span, 0, par_index);
1943 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
1944 INVALID_REGNUM, span_offset);
1945 span_offset += GET_MODE_SIZE (GET_MODE (elem));
1950 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
1953 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
1956 unsigned sregno, dregno;
1958 src = XEXP (set, 1);
1959 dest = XEXP (set, 0);
1962 sregno = DWARF_FRAME_RETURN_COLUMN;
1964 sregno = DWARF_FRAME_REGNUM (REGNO (src));
1966 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
1968 /* ??? We'd like to use queue_reg_save, but we need to come up with
1969 a different flushing heuristic for epilogues. */
1970 reg_save (label, sregno, dregno, 0);
1973 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
1976 dwarf2out_frame_debug_cfa_expression (rtx set, const char *label)
1978 rtx src, dest, span;
1979 dw_cfi_ref cfi = new_cfi ();
1981 dest = SET_DEST (set);
1982 src = SET_SRC (set);
1984 gcc_assert (REG_P (src));
1985 gcc_assert (MEM_P (dest));
1987 span = targetm.dwarf_register_span (src);
1990 cfi->dw_cfi_opc = DW_CFA_expression;
1991 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DWARF_FRAME_REGNUM (REGNO (src));
1992 cfi->dw_cfi_oprnd2.dw_cfi_loc
1993 = mem_loc_descriptor (XEXP (dest, 0), GET_MODE (dest),
1994 VAR_INIT_STATUS_INITIALIZED);
1996 /* ??? We'd like to use queue_reg_save, were the interface different,
1997 and, as above, we could manage flushing for epilogues. */
1998 add_fde_cfi (label, cfi);
2001 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
2004 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
2006 dw_cfi_ref cfi = new_cfi ();
2007 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
2009 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
2010 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
2012 add_fde_cfi (label, cfi);
2015 /* Record call frame debugging information for an expression EXPR,
2016 which either sets SP or FP (adjusting how we calculate the frame
2017 address) or saves a register to the stack or another register.
2018 LABEL indicates the address of EXPR.
2020 This function encodes a state machine mapping rtxes to actions on
2021 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
2022 users need not read the source code.
2024 The High-Level Picture
2026 Changes in the register we use to calculate the CFA: Currently we
2027 assume that if you copy the CFA register into another register, we
2028 should take the other one as the new CFA register; this seems to
2029 work pretty well. If it's wrong for some target, it's simple
2030 enough not to set RTX_FRAME_RELATED_P on the insn in question.
2032 Changes in the register we use for saving registers to the stack:
2033 This is usually SP, but not always. Again, we deduce that if you
2034 copy SP into another register (and SP is not the CFA register),
2035 then the new register is the one we will be using for register
2036 saves. This also seems to work.
2038 Register saves: There's not much guesswork about this one; if
2039 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
2040 register save, and the register used to calculate the destination
2041 had better be the one we think we're using for this purpose.
2042 It's also assumed that a copy from a call-saved register to another
2043 register is saving that register if RTX_FRAME_RELATED_P is set on
2044 that instruction. If the copy is from a call-saved register to
2045 the *same* register, that means that the register is now the same
2046 value as in the caller.
2048 Except: If the register being saved is the CFA register, and the
2049 offset is nonzero, we are saving the CFA, so we assume we have to
2050 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
2051 the intent is to save the value of SP from the previous frame.
2053 In addition, if a register has previously been saved to a different
2056 Invariants / Summaries of Rules
2058 cfa current rule for calculating the CFA. It usually
2059 consists of a register and an offset.
2060 cfa_store register used by prologue code to save things to the stack
2061 cfa_store.offset is the offset from the value of
2062 cfa_store.reg to the actual CFA
2063 cfa_temp register holding an integral value. cfa_temp.offset
2064 stores the value, which will be used to adjust the
2065 stack pointer. cfa_temp is also used like cfa_store,
2066 to track stores to the stack via fp or a temp reg.
2068 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2069 with cfa.reg as the first operand changes the cfa.reg and its
2070 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2073 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2074 expression yielding a constant. This sets cfa_temp.reg
2075 and cfa_temp.offset.
2077 Rule 5: Create a new register cfa_store used to save items to the
2080 Rules 10-14: Save a register to the stack. Define offset as the
2081 difference of the original location and cfa_store's
2082 location (or cfa_temp's location if cfa_temp is used).
2084 Rules 16-20: If AND operation happens on sp in prologue, we assume
2085 stack is realigned. We will use a group of DW_OP_XXX
2086 expressions to represent the location of the stored
2087 register instead of CFA+offset.
2091 "{a,b}" indicates a choice of a xor b.
2092 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2095 (set <reg1> <reg2>:cfa.reg)
2096 effects: cfa.reg = <reg1>
2097 cfa.offset unchanged
2098 cfa_temp.reg = <reg1>
2099 cfa_temp.offset = cfa.offset
2102 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2103 {<const_int>,<reg>:cfa_temp.reg}))
2104 effects: cfa.reg = sp if fp used
2105 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2106 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2107 if cfa_store.reg==sp
2110 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2111 effects: cfa.reg = fp
2112 cfa_offset += +/- <const_int>
2115 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2116 constraints: <reg1> != fp
2118 effects: cfa.reg = <reg1>
2119 cfa_temp.reg = <reg1>
2120 cfa_temp.offset = cfa.offset
2123 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2124 constraints: <reg1> != fp
2126 effects: cfa_store.reg = <reg1>
2127 cfa_store.offset = cfa.offset - cfa_temp.offset
2130 (set <reg> <const_int>)
2131 effects: cfa_temp.reg = <reg>
2132 cfa_temp.offset = <const_int>
2135 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2136 effects: cfa_temp.reg = <reg1>
2137 cfa_temp.offset |= <const_int>
2140 (set <reg> (high <exp>))
2144 (set <reg> (lo_sum <exp> <const_int>))
2145 effects: cfa_temp.reg = <reg>
2146 cfa_temp.offset = <const_int>
2149 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2150 effects: cfa_store.offset -= <const_int>
2151 cfa.offset = cfa_store.offset if cfa.reg == sp
2153 cfa.base_offset = -cfa_store.offset
2156 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
2157 effects: cfa_store.offset += -/+ mode_size(mem)
2158 cfa.offset = cfa_store.offset if cfa.reg == sp
2160 cfa.base_offset = -cfa_store.offset
2163 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2166 effects: cfa.reg = <reg1>
2167 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2170 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2171 effects: cfa.reg = <reg1>
2172 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2175 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
2176 effects: cfa.reg = <reg1>
2177 cfa.base_offset = -cfa_temp.offset
2178 cfa_temp.offset -= mode_size(mem)
2181 (set <reg> {unspec, unspec_volatile})
2182 effects: target-dependent
2185 (set sp (and: sp <const_int>))
2186 constraints: cfa_store.reg == sp
2187 effects: current_fde.stack_realign = 1
2188 cfa_store.offset = 0
2189 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2192 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2193 effects: cfa_store.offset += -/+ mode_size(mem)
2196 (set (mem ({pre_inc, pre_dec} sp)) fp)
2197 constraints: fde->stack_realign == 1
2198 effects: cfa_store.offset = 0
2199 cfa.reg != HARD_FRAME_POINTER_REGNUM
2202 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2203 constraints: fde->stack_realign == 1
2205 && cfa.indirect == 0
2206 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2207 effects: Use DW_CFA_def_cfa_expression to define cfa
2208 cfa.reg == fde->drap_reg */
2211 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2213 rtx src, dest, span;
2214 HOST_WIDE_INT offset;
2217 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2218 the PARALLEL independently. The first element is always processed if
2219 it is a SET. This is for backward compatibility. Other elements
2220 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2221 flag is set in them. */
2222 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2225 int limit = XVECLEN (expr, 0);
2228 /* PARALLELs have strict read-modify-write semantics, so we
2229 ought to evaluate every rvalue before changing any lvalue.
2230 It's cumbersome to do that in general, but there's an
2231 easy approximation that is enough for all current users:
2232 handle register saves before register assignments. */
2233 if (GET_CODE (expr) == PARALLEL)
2234 for (par_index = 0; par_index < limit; par_index++)
2236 elem = XVECEXP (expr, 0, par_index);
2237 if (GET_CODE (elem) == SET
2238 && MEM_P (SET_DEST (elem))
2239 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2240 dwarf2out_frame_debug_expr (elem, label);
2243 for (par_index = 0; par_index < limit; par_index++)
2245 elem = XVECEXP (expr, 0, par_index);
2246 if (GET_CODE (elem) == SET
2247 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2248 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2249 dwarf2out_frame_debug_expr (elem, label);
2250 else if (GET_CODE (elem) == SET
2252 && !RTX_FRAME_RELATED_P (elem))
2254 /* Stack adjustment combining might combine some post-prologue
2255 stack adjustment into a prologue stack adjustment. */
2256 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2259 dwarf2out_stack_adjust (offset, label);
2265 gcc_assert (GET_CODE (expr) == SET);
2267 src = SET_SRC (expr);
2268 dest = SET_DEST (expr);
2272 rtx rsi = reg_saved_in (src);
2277 fde = current_fde ();
2279 switch (GET_CODE (dest))
2282 switch (GET_CODE (src))
2284 /* Setting FP from SP. */
2286 if (cfa.reg == (unsigned) REGNO (src))
2289 /* Update the CFA rule wrt SP or FP. Make sure src is
2290 relative to the current CFA register.
2292 We used to require that dest be either SP or FP, but the
2293 ARM copies SP to a temporary register, and from there to
2294 FP. So we just rely on the backends to only set
2295 RTX_FRAME_RELATED_P on appropriate insns. */
2296 cfa.reg = REGNO (dest);
2297 cfa_temp.reg = cfa.reg;
2298 cfa_temp.offset = cfa.offset;
2302 /* Saving a register in a register. */
2303 gcc_assert (!fixed_regs [REGNO (dest)]
2304 /* For the SPARC and its register window. */
2305 || (DWARF_FRAME_REGNUM (REGNO (src))
2306 == DWARF_FRAME_RETURN_COLUMN));
2308 /* After stack is aligned, we can only save SP in FP
2309 if drap register is used. In this case, we have
2310 to restore stack pointer with the CFA value and we
2311 don't generate this DWARF information. */
2313 && fde->stack_realign
2314 && REGNO (src) == STACK_POINTER_REGNUM)
2315 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2316 && fde->drap_reg != INVALID_REGNUM
2317 && cfa.reg != REGNO (src));
2319 queue_reg_save (label, src, dest, 0);
2326 if (dest == stack_pointer_rtx)
2330 switch (GET_CODE (XEXP (src, 1)))
2333 offset = INTVAL (XEXP (src, 1));
2336 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2338 offset = cfa_temp.offset;
2344 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2346 /* Restoring SP from FP in the epilogue. */
2347 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2348 cfa.reg = STACK_POINTER_REGNUM;
2350 else if (GET_CODE (src) == LO_SUM)
2351 /* Assume we've set the source reg of the LO_SUM from sp. */
2354 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2356 if (GET_CODE (src) != MINUS)
2358 if (cfa.reg == STACK_POINTER_REGNUM)
2359 cfa.offset += offset;
2360 if (cfa_store.reg == STACK_POINTER_REGNUM)
2361 cfa_store.offset += offset;
2363 else if (dest == hard_frame_pointer_rtx)
2366 /* Either setting the FP from an offset of the SP,
2367 or adjusting the FP */
2368 gcc_assert (frame_pointer_needed);
2370 gcc_assert (REG_P (XEXP (src, 0))
2371 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2372 && CONST_INT_P (XEXP (src, 1)));
2373 offset = INTVAL (XEXP (src, 1));
2374 if (GET_CODE (src) != MINUS)
2376 cfa.offset += offset;
2377 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2381 gcc_assert (GET_CODE (src) != MINUS);
2384 if (REG_P (XEXP (src, 0))
2385 && REGNO (XEXP (src, 0)) == cfa.reg
2386 && CONST_INT_P (XEXP (src, 1)))
2388 /* Setting a temporary CFA register that will be copied
2389 into the FP later on. */
2390 offset = - INTVAL (XEXP (src, 1));
2391 cfa.offset += offset;
2392 cfa.reg = REGNO (dest);
2393 /* Or used to save regs to the stack. */
2394 cfa_temp.reg = cfa.reg;
2395 cfa_temp.offset = cfa.offset;
2399 else if (REG_P (XEXP (src, 0))
2400 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2401 && XEXP (src, 1) == stack_pointer_rtx)
2403 /* Setting a scratch register that we will use instead
2404 of SP for saving registers to the stack. */
2405 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2406 cfa_store.reg = REGNO (dest);
2407 cfa_store.offset = cfa.offset - cfa_temp.offset;
2411 else if (GET_CODE (src) == LO_SUM
2412 && CONST_INT_P (XEXP (src, 1)))
2414 cfa_temp.reg = REGNO (dest);
2415 cfa_temp.offset = INTVAL (XEXP (src, 1));
2424 cfa_temp.reg = REGNO (dest);
2425 cfa_temp.offset = INTVAL (src);
2430 gcc_assert (REG_P (XEXP (src, 0))
2431 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2432 && CONST_INT_P (XEXP (src, 1)));
2434 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2435 cfa_temp.reg = REGNO (dest);
2436 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2439 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2440 which will fill in all of the bits. */
2447 case UNSPEC_VOLATILE:
2448 gcc_assert (targetm.dwarf_handle_frame_unspec);
2449 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2454 /* If this AND operation happens on stack pointer in prologue,
2455 we assume the stack is realigned and we extract the
2457 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2459 /* We interpret reg_save differently with stack_realign set.
2460 Thus we must flush whatever we have queued first. */
2461 flush_queued_reg_saves ();
2463 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2464 fde->stack_realign = 1;
2465 fde->stack_realignment = INTVAL (XEXP (src, 1));
2466 cfa_store.offset = 0;
2468 if (cfa.reg != STACK_POINTER_REGNUM
2469 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2470 fde->drap_reg = cfa.reg;
2478 def_cfa_1 (label, &cfa);
2483 /* Saving a register to the stack. Make sure dest is relative to the
2485 switch (GET_CODE (XEXP (dest, 0)))
2490 /* We can't handle variable size modifications. */
2491 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2493 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2495 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2496 && cfa_store.reg == STACK_POINTER_REGNUM);
2498 cfa_store.offset += offset;
2499 if (cfa.reg == STACK_POINTER_REGNUM)
2500 cfa.offset = cfa_store.offset;
2502 offset = -cfa_store.offset;
2508 offset = GET_MODE_SIZE (GET_MODE (dest));
2509 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2512 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2513 == STACK_POINTER_REGNUM)
2514 && cfa_store.reg == STACK_POINTER_REGNUM);
2516 cfa_store.offset += offset;
2518 /* Rule 18: If stack is aligned, we will use FP as a
2519 reference to represent the address of the stored
2522 && fde->stack_realign
2523 && src == hard_frame_pointer_rtx)
2525 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2526 cfa_store.offset = 0;
2529 if (cfa.reg == STACK_POINTER_REGNUM)
2530 cfa.offset = cfa_store.offset;
2532 offset = -cfa_store.offset;
2536 /* With an offset. */
2543 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2544 && REG_P (XEXP (XEXP (dest, 0), 0)));
2545 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2546 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2549 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2551 if (cfa_store.reg == (unsigned) regno)
2552 offset -= cfa_store.offset;
2555 gcc_assert (cfa_temp.reg == (unsigned) regno);
2556 offset -= cfa_temp.offset;
2562 /* Without an offset. */
2565 int regno = REGNO (XEXP (dest, 0));
2567 if (cfa_store.reg == (unsigned) regno)
2568 offset = -cfa_store.offset;
2571 gcc_assert (cfa_temp.reg == (unsigned) regno);
2572 offset = -cfa_temp.offset;
2579 gcc_assert (cfa_temp.reg
2580 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2581 offset = -cfa_temp.offset;
2582 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2590 /* If the source operand of this MEM operation is not a
2591 register, basically the source is return address. Here
2592 we only care how much stack grew and we don't save it. */
2596 if (REGNO (src) != STACK_POINTER_REGNUM
2597 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2598 && (unsigned) REGNO (src) == cfa.reg)
2600 /* We're storing the current CFA reg into the stack. */
2602 if (cfa.offset == 0)
2605 /* If stack is aligned, putting CFA reg into stack means
2606 we can no longer use reg + offset to represent CFA.
2607 Here we use DW_CFA_def_cfa_expression instead. The
2608 result of this expression equals to the original CFA
2611 && fde->stack_realign
2612 && cfa.indirect == 0
2613 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2615 dw_cfa_location cfa_exp;
2617 gcc_assert (fde->drap_reg == cfa.reg);
2619 cfa_exp.indirect = 1;
2620 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2621 cfa_exp.base_offset = offset;
2624 fde->drap_reg_saved = 1;
2626 def_cfa_1 (label, &cfa_exp);
2630 /* If the source register is exactly the CFA, assume
2631 we're saving SP like any other register; this happens
2633 def_cfa_1 (label, &cfa);
2634 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2639 /* Otherwise, we'll need to look in the stack to
2640 calculate the CFA. */
2641 rtx x = XEXP (dest, 0);
2645 gcc_assert (REG_P (x));
2647 cfa.reg = REGNO (x);
2648 cfa.base_offset = offset;
2650 def_cfa_1 (label, &cfa);
2655 def_cfa_1 (label, &cfa);
2657 span = targetm.dwarf_register_span (src);
2660 queue_reg_save (label, src, NULL_RTX, offset);
2663 /* We have a PARALLEL describing where the contents of SRC
2664 live. Queue register saves for each piece of the
2668 HOST_WIDE_INT span_offset = offset;
2670 gcc_assert (GET_CODE (span) == PARALLEL);
2672 limit = XVECLEN (span, 0);
2673 for (par_index = 0; par_index < limit; par_index++)
2675 rtx elem = XVECEXP (span, 0, par_index);
2677 queue_reg_save (label, elem, NULL_RTX, span_offset);
2678 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2689 /* Record call frame debugging information for INSN, which either
2690 sets SP or FP (adjusting how we calculate the frame address) or saves a
2691 register to the stack. If INSN is NULL_RTX, initialize our state.
2693 If AFTER_P is false, we're being called before the insn is emitted,
2694 otherwise after. Call instructions get invoked twice. */
2697 dwarf2out_frame_debug (rtx insn, bool after_p)
2701 bool handled_one = false;
2703 if (insn == NULL_RTX)
2707 /* Flush any queued register saves. */
2708 flush_queued_reg_saves ();
2710 /* Set up state for generating call frame debug info. */
2713 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2715 cfa.reg = STACK_POINTER_REGNUM;
2718 cfa_temp.offset = 0;
2720 for (i = 0; i < num_regs_saved_in_regs; i++)
2722 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2723 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2725 num_regs_saved_in_regs = 0;
2727 if (barrier_args_size)
2729 XDELETEVEC (barrier_args_size);
2730 barrier_args_size = NULL;
2735 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2736 flush_queued_reg_saves ();
2738 if (!RTX_FRAME_RELATED_P (insn))
2740 /* ??? This should be done unconditionally since stack adjustments
2741 matter if the stack pointer is not the CFA register anymore but
2742 is still used to save registers. */
2743 if (!ACCUMULATE_OUTGOING_ARGS)
2744 dwarf2out_notice_stack_adjust (insn, after_p);
2748 label = dwarf2out_cfi_label (false);
2750 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2751 switch (REG_NOTE_KIND (note))
2753 case REG_FRAME_RELATED_EXPR:
2754 insn = XEXP (note, 0);
2757 case REG_CFA_DEF_CFA:
2758 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2762 case REG_CFA_ADJUST_CFA:
2767 if (GET_CODE (n) == PARALLEL)
2768 n = XVECEXP (n, 0, 0);
2770 dwarf2out_frame_debug_adjust_cfa (n, label);
2774 case REG_CFA_OFFSET:
2777 n = single_set (insn);
2778 dwarf2out_frame_debug_cfa_offset (n, label);
2782 case REG_CFA_REGISTER:
2787 if (GET_CODE (n) == PARALLEL)
2788 n = XVECEXP (n, 0, 0);
2790 dwarf2out_frame_debug_cfa_register (n, label);
2794 case REG_CFA_EXPRESSION:
2797 n = single_set (insn);
2798 dwarf2out_frame_debug_cfa_expression (n, label);
2802 case REG_CFA_RESTORE:
2807 if (GET_CODE (n) == PARALLEL)
2808 n = XVECEXP (n, 0, 0);
2811 dwarf2out_frame_debug_cfa_restore (n, label);
2815 case REG_CFA_SET_VDRAP:
2819 dw_fde_ref fde = current_fde ();
2822 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2824 fde->vdrap_reg = REGNO (n);
2836 insn = PATTERN (insn);
2838 dwarf2out_frame_debug_expr (insn, label);
2840 /* Check again. A parallel can save and update the same register.
2841 We could probably check just once, here, but this is safer than
2842 removing the check above. */
2843 if (clobbers_queued_reg_save (insn))
2844 flush_queued_reg_saves ();
2847 /* Determine if we need to save and restore CFI information around this
2848 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2849 we do need to save/restore, then emit the save now, and insert a
2850 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2853 dwarf2out_cfi_begin_epilogue (rtx insn)
2855 bool saw_frp = false;
2858 /* Scan forward to the return insn, noticing if there are possible
2859 frame related insns. */
2860 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2865 /* Look for both regular and sibcalls to end the block. */
2866 if (returnjump_p (i))
2868 if (CALL_P (i) && SIBLING_CALL_P (i))
2871 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2874 rtx seq = PATTERN (i);
2876 if (returnjump_p (XVECEXP (seq, 0, 0)))
2878 if (CALL_P (XVECEXP (seq, 0, 0))
2879 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2882 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2883 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2887 if (RTX_FRAME_RELATED_P (i))
2891 /* If the port doesn't emit epilogue unwind info, we don't need a
2892 save/restore pair. */
2896 /* Otherwise, search forward to see if the return insn was the last
2897 basic block of the function. If so, we don't need save/restore. */
2898 gcc_assert (i != NULL);
2899 i = next_real_insn (i);
2903 /* Insert the restore before that next real insn in the stream, and before
2904 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
2905 properly nested. This should be after any label or alignment. This
2906 will be pushed into the CFI stream by the function below. */
2909 rtx p = PREV_INSN (i);
2912 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
2916 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
2918 emit_cfa_remember = true;
2920 /* And emulate the state save. */
2921 gcc_assert (!cfa_remember.in_use);
2923 cfa_remember.in_use = 1;
2926 /* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
2930 dwarf2out_frame_debug_restore_state (void)
2932 dw_cfi_ref cfi = new_cfi ();
2933 const char *label = dwarf2out_cfi_label (false);
2935 cfi->dw_cfi_opc = DW_CFA_restore_state;
2936 add_fde_cfi (label, cfi);
2938 gcc_assert (cfa_remember.in_use);
2940 cfa_remember.in_use = 0;
2943 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2944 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2945 (enum dwarf_call_frame_info cfi);
2947 static enum dw_cfi_oprnd_type
2948 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2953 case DW_CFA_GNU_window_save:
2954 case DW_CFA_remember_state:
2955 case DW_CFA_restore_state:
2956 return dw_cfi_oprnd_unused;
2958 case DW_CFA_set_loc:
2959 case DW_CFA_advance_loc1:
2960 case DW_CFA_advance_loc2:
2961 case DW_CFA_advance_loc4:
2962 case DW_CFA_MIPS_advance_loc8:
2963 return dw_cfi_oprnd_addr;
2966 case DW_CFA_offset_extended:
2967 case DW_CFA_def_cfa:
2968 case DW_CFA_offset_extended_sf:
2969 case DW_CFA_def_cfa_sf:
2970 case DW_CFA_restore:
2971 case DW_CFA_restore_extended:
2972 case DW_CFA_undefined:
2973 case DW_CFA_same_value:
2974 case DW_CFA_def_cfa_register:
2975 case DW_CFA_register:
2976 case DW_CFA_expression:
2977 return dw_cfi_oprnd_reg_num;
2979 case DW_CFA_def_cfa_offset:
2980 case DW_CFA_GNU_args_size:
2981 case DW_CFA_def_cfa_offset_sf:
2982 return dw_cfi_oprnd_offset;
2984 case DW_CFA_def_cfa_expression:
2985 return dw_cfi_oprnd_loc;
2992 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2993 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2994 (enum dwarf_call_frame_info cfi);
2996 static enum dw_cfi_oprnd_type
2997 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
3001 case DW_CFA_def_cfa:
3002 case DW_CFA_def_cfa_sf:
3004 case DW_CFA_offset_extended_sf:
3005 case DW_CFA_offset_extended:
3006 return dw_cfi_oprnd_offset;
3008 case DW_CFA_register:
3009 return dw_cfi_oprnd_reg_num;
3011 case DW_CFA_expression:
3012 return dw_cfi_oprnd_loc;
3015 return dw_cfi_oprnd_unused;
3019 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
3020 switch to the data section instead, and write out a synthetic start label
3021 for collect2 the first time around. */
3024 switch_to_eh_frame_section (bool back)
3028 #ifdef EH_FRAME_SECTION_NAME
3029 if (eh_frame_section == 0)
3033 if (EH_TABLES_CAN_BE_READ_ONLY)
3039 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
3041 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
3043 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
3045 flags = ((! flag_pic
3046 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
3047 && (fde_encoding & 0x70) != DW_EH_PE_aligned
3048 && (per_encoding & 0x70) != DW_EH_PE_absptr
3049 && (per_encoding & 0x70) != DW_EH_PE_aligned
3050 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
3051 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
3052 ? 0 : SECTION_WRITE);
3055 flags = SECTION_WRITE;
3056 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
3058 #endif /* EH_FRAME_SECTION_NAME */
3060 if (eh_frame_section)
3061 switch_to_section (eh_frame_section);
3064 /* We have no special eh_frame section. Put the information in
3065 the data section and emit special labels to guide collect2. */
3066 switch_to_section (data_section);
3070 label = get_file_function_name ("F");
3071 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3072 targetm.asm_out.globalize_label (asm_out_file,
3073 IDENTIFIER_POINTER (label));
3074 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3079 /* Switch [BACK] to the eh or debug frame table section, depending on
3083 switch_to_frame_table_section (int for_eh, bool back)
3086 switch_to_eh_frame_section (back);
3089 if (!debug_frame_section)
3090 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3091 SECTION_DEBUG, NULL);
3092 switch_to_section (debug_frame_section);
3096 /* Output a Call Frame Information opcode and its operand(s). */
3099 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3104 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3105 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3106 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3107 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3108 ((unsigned HOST_WIDE_INT)
3109 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3110 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3112 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3113 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3114 "DW_CFA_offset, column %#lx", r);
3115 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3116 dw2_asm_output_data_uleb128 (off, NULL);
3118 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3120 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3121 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3122 "DW_CFA_restore, column %#lx", r);
3126 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3127 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3129 switch (cfi->dw_cfi_opc)
3131 case DW_CFA_set_loc:
3133 dw2_asm_output_encoded_addr_rtx (
3134 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3135 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3138 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3139 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3140 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3143 case DW_CFA_advance_loc1:
3144 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3145 fde->dw_fde_current_label, NULL);
3146 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3149 case DW_CFA_advance_loc2:
3150 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3151 fde->dw_fde_current_label, NULL);
3152 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3155 case DW_CFA_advance_loc4:
3156 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3157 fde->dw_fde_current_label, NULL);
3158 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3161 case DW_CFA_MIPS_advance_loc8:
3162 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3163 fde->dw_fde_current_label, NULL);
3164 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3167 case DW_CFA_offset_extended:
3168 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3169 dw2_asm_output_data_uleb128 (r, NULL);
3170 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3171 dw2_asm_output_data_uleb128 (off, NULL);
3174 case DW_CFA_def_cfa:
3175 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3176 dw2_asm_output_data_uleb128 (r, NULL);
3177 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3180 case DW_CFA_offset_extended_sf:
3181 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3182 dw2_asm_output_data_uleb128 (r, NULL);
3183 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3184 dw2_asm_output_data_sleb128 (off, NULL);
3187 case DW_CFA_def_cfa_sf:
3188 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3189 dw2_asm_output_data_uleb128 (r, NULL);
3190 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3191 dw2_asm_output_data_sleb128 (off, NULL);
3194 case DW_CFA_restore_extended:
3195 case DW_CFA_undefined:
3196 case DW_CFA_same_value:
3197 case DW_CFA_def_cfa_register:
3198 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3199 dw2_asm_output_data_uleb128 (r, NULL);
3202 case DW_CFA_register:
3203 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3204 dw2_asm_output_data_uleb128 (r, NULL);
3205 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3206 dw2_asm_output_data_uleb128 (r, NULL);
3209 case DW_CFA_def_cfa_offset:
3210 case DW_CFA_GNU_args_size:
3211 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3214 case DW_CFA_def_cfa_offset_sf:
3215 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3216 dw2_asm_output_data_sleb128 (off, NULL);
3219 case DW_CFA_GNU_window_save:
3222 case DW_CFA_def_cfa_expression:
3223 case DW_CFA_expression:
3224 output_cfa_loc (cfi);
3227 case DW_CFA_GNU_negative_offset_extended:
3228 /* Obsoleted by DW_CFA_offset_extended_sf. */
3237 /* Similar, but do it via assembler directives instead. */
3240 output_cfi_directive (dw_cfi_ref cfi)
3242 unsigned long r, r2;
3244 switch (cfi->dw_cfi_opc)
3246 case DW_CFA_advance_loc:
3247 case DW_CFA_advance_loc1:
3248 case DW_CFA_advance_loc2:
3249 case DW_CFA_advance_loc4:
3250 case DW_CFA_MIPS_advance_loc8:
3251 case DW_CFA_set_loc:
3252 /* Should only be created by add_fde_cfi in a code path not
3253 followed when emitting via directives. The assembler is
3254 going to take care of this for us. */
3258 case DW_CFA_offset_extended:
3259 case DW_CFA_offset_extended_sf:
3260 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3261 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3262 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3265 case DW_CFA_restore:
3266 case DW_CFA_restore_extended:
3267 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3268 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3271 case DW_CFA_undefined:
3272 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3273 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3276 case DW_CFA_same_value:
3277 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3278 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3281 case DW_CFA_def_cfa:
3282 case DW_CFA_def_cfa_sf:
3283 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3284 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3285 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3288 case DW_CFA_def_cfa_register:
3289 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3290 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3293 case DW_CFA_register:
3294 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3295 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3296 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3299 case DW_CFA_def_cfa_offset:
3300 case DW_CFA_def_cfa_offset_sf:
3301 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3302 HOST_WIDE_INT_PRINT_DEC"\n",
3303 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3306 case DW_CFA_remember_state:
3307 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3309 case DW_CFA_restore_state:
3310 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3313 case DW_CFA_GNU_args_size:
3314 fprintf (asm_out_file, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
3315 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3317 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3318 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3319 fputc ('\n', asm_out_file);
3322 case DW_CFA_GNU_window_save:
3323 fprintf (asm_out_file, "\t.cfi_window_save\n");
3326 case DW_CFA_def_cfa_expression:
3327 case DW_CFA_expression:
3328 fprintf (asm_out_file, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
3329 output_cfa_loc_raw (cfi);
3330 fputc ('\n', asm_out_file);
3338 DEF_VEC_P (dw_cfi_ref);
3339 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3341 /* Output CFIs to bring current FDE to the same state as after executing
3342 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3343 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3344 other arguments to pass to output_cfi. */
3347 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3349 struct dw_cfi_struct cfi_buf;
3351 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3352 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3353 unsigned int len, idx;
3355 for (;; cfi = cfi->dw_cfi_next)
3356 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3358 case DW_CFA_advance_loc:
3359 case DW_CFA_advance_loc1:
3360 case DW_CFA_advance_loc2:
3361 case DW_CFA_advance_loc4:
3362 case DW_CFA_MIPS_advance_loc8:
3363 case DW_CFA_set_loc:
3364 /* All advances should be ignored. */
3366 case DW_CFA_remember_state:
3368 dw_cfi_ref args_size = cfi_args_size;
3370 /* Skip everything between .cfi_remember_state and
3371 .cfi_restore_state. */
3372 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3373 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3375 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3378 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3385 cfi_args_size = args_size;
3389 case DW_CFA_GNU_args_size:
3390 cfi_args_size = cfi;
3392 case DW_CFA_GNU_window_save:
3395 case DW_CFA_offset_extended:
3396 case DW_CFA_offset_extended_sf:
3397 case DW_CFA_restore:
3398 case DW_CFA_restore_extended:
3399 case DW_CFA_undefined:
3400 case DW_CFA_same_value:
3401 case DW_CFA_register:
3402 case DW_CFA_val_offset:
3403 case DW_CFA_val_offset_sf:
3404 case DW_CFA_expression:
3405 case DW_CFA_val_expression:
3406 case DW_CFA_GNU_negative_offset_extended:
3407 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3408 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3409 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3410 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3412 case DW_CFA_def_cfa:
3413 case DW_CFA_def_cfa_sf:
3414 case DW_CFA_def_cfa_expression:
3416 cfi_cfa_offset = cfi;
3418 case DW_CFA_def_cfa_register:
3421 case DW_CFA_def_cfa_offset:
3422 case DW_CFA_def_cfa_offset_sf:
3423 cfi_cfa_offset = cfi;
3426 gcc_assert (cfi == NULL);
3428 len = VEC_length (dw_cfi_ref, regs);
3429 for (idx = 0; idx < len; idx++)
3431 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3433 && cfi2->dw_cfi_opc != DW_CFA_restore
3434 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3437 output_cfi_directive (cfi2);
3439 output_cfi (cfi2, fde, for_eh);
3442 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3444 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3446 switch (cfi_cfa_offset->dw_cfi_opc)
3448 case DW_CFA_def_cfa_offset:
3449 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3450 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3452 case DW_CFA_def_cfa_offset_sf:
3453 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3454 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3456 case DW_CFA_def_cfa:
3457 case DW_CFA_def_cfa_sf:
3458 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3459 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3466 else if (cfi_cfa_offset)
3467 cfi_cfa = cfi_cfa_offset;
3471 output_cfi_directive (cfi_cfa);
3473 output_cfi (cfi_cfa, fde, for_eh);
3476 cfi_cfa_offset = NULL;
3478 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3481 output_cfi_directive (cfi_args_size);
3483 output_cfi (cfi_args_size, fde, for_eh);
3485 cfi_args_size = NULL;
3488 VEC_free (dw_cfi_ref, heap, regs);
3491 else if (do_cfi_asm)
3492 output_cfi_directive (cfi);
3494 output_cfi (cfi, fde, for_eh);
3501 /* Output one FDE. */
3504 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3505 char *section_start_label, int fde_encoding, char *augmentation,
3506 bool any_lsda_needed, int lsda_encoding)
3508 const char *begin, *end;
3509 static unsigned int j;
3510 char l1[20], l2[20];
3513 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
3515 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3517 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3518 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3519 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3520 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3521 " indicating 64-bit DWARF extension");
3522 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3524 ASM_OUTPUT_LABEL (asm_out_file, l1);
3527 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3529 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3530 debug_frame_section, "FDE CIE offset");
3532 if (!fde->dw_fde_switched_sections)
3534 begin = fde->dw_fde_begin;
3535 end = fde->dw_fde_end;
3539 /* For the first section, prefer dw_fde_begin over
3540 dw_fde_{hot,cold}_section_label, as the latter
3541 might be separated from the real start of the
3542 function by alignment padding. */
3544 begin = fde->dw_fde_begin;
3545 else if (fde->dw_fde_switched_cold_to_hot)
3546 begin = fde->dw_fde_hot_section_label;
3548 begin = fde->dw_fde_unlikely_section_label;
3549 if (second ^ fde->dw_fde_switched_cold_to_hot)
3550 end = fde->dw_fde_unlikely_section_end_label;
3552 end = fde->dw_fde_hot_section_end_label;
3557 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3558 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3559 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3560 "FDE initial location");
3561 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3562 end, begin, "FDE address range");
3566 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3567 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3570 if (augmentation[0])
3572 if (any_lsda_needed)
3574 int size = size_of_encoded_value (lsda_encoding);
3576 if (lsda_encoding == DW_EH_PE_aligned)
3578 int offset = ( 4 /* Length */
3579 + 4 /* CIE offset */
3580 + 2 * size_of_encoded_value (fde_encoding)
3581 + 1 /* Augmentation size */ );
3582 int pad = -offset & (PTR_SIZE - 1);
3585 gcc_assert (size_of_uleb128 (size) == 1);
3588 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3590 if (fde->uses_eh_lsda)
3592 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3593 fde->funcdef_number);
3594 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3595 gen_rtx_SYMBOL_REF (Pmode, l1),
3597 "Language Specific Data Area");
3601 if (lsda_encoding == DW_EH_PE_aligned)
3602 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3603 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3604 "Language Specific Data Area (none)");
3608 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3611 /* Loop through the Call Frame Instructions associated with
3613 fde->dw_fde_current_label = begin;
3614 if (!fde->dw_fde_switched_sections)
3615 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3616 output_cfi (cfi, fde, for_eh);
3619 if (fde->dw_fde_switch_cfi)
3620 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3622 output_cfi (cfi, fde, for_eh);
3623 if (cfi == fde->dw_fde_switch_cfi)
3629 dw_cfi_ref cfi_next = fde->dw_fde_cfi;
3631 if (fde->dw_fde_switch_cfi)
3633 cfi_next = fde->dw_fde_switch_cfi->dw_cfi_next;
3634 fde->dw_fde_switch_cfi->dw_cfi_next = NULL;
3635 output_cfis (fde->dw_fde_cfi, false, fde, for_eh);
3636 fde->dw_fde_switch_cfi->dw_cfi_next = cfi_next;
3638 for (cfi = cfi_next; cfi != NULL; cfi = cfi->dw_cfi_next)
3639 output_cfi (cfi, fde, for_eh);
3642 /* If we are to emit a ref/link from function bodies to their frame tables,
3643 do it now. This is typically performed to make sure that tables
3644 associated with functions are dragged with them and not discarded in
3645 garbage collecting links. We need to do this on a per function basis to
3646 cope with -ffunction-sections. */
3648 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3649 /* Switch to the function section, emit the ref to the tables, and
3650 switch *back* into the table section. */
3651 switch_to_section (function_section (fde->decl));
3652 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
3653 switch_to_frame_table_section (for_eh, true);
3656 /* Pad the FDE out to an address sized boundary. */
3657 ASM_OUTPUT_ALIGN (asm_out_file,
3658 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3659 ASM_OUTPUT_LABEL (asm_out_file, l2);
3664 /* Return true if frame description entry FDE is needed for EH. */
3667 fde_needed_for_eh_p (dw_fde_ref fde)
3669 if (flag_asynchronous_unwind_tables)
3672 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
3675 if (fde->uses_eh_lsda)
3678 /* If exceptions are enabled, we have collected nothrow info. */
3679 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
3685 /* Output the call frame information used to record information
3686 that relates to calculating the frame pointer, and records the
3687 location of saved registers. */
3690 output_call_frame_info (int for_eh)
3695 char l1[20], l2[20], section_start_label[20];
3696 bool any_lsda_needed = false;
3697 char augmentation[6];
3698 int augmentation_size;
3699 int fde_encoding = DW_EH_PE_absptr;
3700 int per_encoding = DW_EH_PE_absptr;
3701 int lsda_encoding = DW_EH_PE_absptr;
3703 rtx personality = NULL;
3706 /* Don't emit a CIE if there won't be any FDEs. */
3707 if (fde_table_in_use == 0)
3710 /* Nothing to do if the assembler's doing it all. */
3711 if (dwarf2out_do_cfi_asm ())
3714 /* If we don't have any functions we'll want to unwind out of, don't emit
3715 any EH unwind information. If we make FDEs linkonce, we may have to
3716 emit an empty label for an FDE that wouldn't otherwise be emitted. We
3717 want to avoid having an FDE kept around when the function it refers to
3718 is discarded. Example where this matters: a primary function template
3719 in C++ requires EH information, an explicit specialization doesn't. */
3722 bool any_eh_needed = false;
3724 for (i = 0; i < fde_table_in_use; i++)
3725 if (fde_table[i].uses_eh_lsda)
3726 any_eh_needed = any_lsda_needed = true;
3727 else if (fde_needed_for_eh_p (&fde_table[i]))
3728 any_eh_needed = true;
3729 else if (TARGET_USES_WEAK_UNWIND_INFO)
3730 targetm.asm_out.emit_unwind_label (asm_out_file, fde_table[i].decl,
3737 /* We're going to be generating comments, so turn on app. */
3741 /* Switch to the proper frame section, first time. */
3742 switch_to_frame_table_section (for_eh, false);
3744 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3745 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3747 /* Output the CIE. */
3748 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3749 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3750 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3751 dw2_asm_output_data (4, 0xffffffff,
3752 "Initial length escape value indicating 64-bit DWARF extension");
3753 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3754 "Length of Common Information Entry");
3755 ASM_OUTPUT_LABEL (asm_out_file, l1);
3757 /* Now that the CIE pointer is PC-relative for EH,
3758 use 0 to identify the CIE. */
3759 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3760 (for_eh ? 0 : DWARF_CIE_ID),
3761 "CIE Identifier Tag");
3763 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3764 use CIE version 1, unless that would produce incorrect results
3765 due to overflowing the return register column. */
3766 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3768 if (return_reg >= 256 || dwarf_version > 2)
3770 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3772 augmentation[0] = 0;
3773 augmentation_size = 0;
3775 personality = current_unit_personality;
3781 z Indicates that a uleb128 is present to size the
3782 augmentation section.
3783 L Indicates the encoding (and thus presence) of
3784 an LSDA pointer in the FDE augmentation.
3785 R Indicates a non-default pointer encoding for
3787 P Indicates the presence of an encoding + language
3788 personality routine in the CIE augmentation. */
3790 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3791 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3792 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3794 p = augmentation + 1;
3798 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3799 assemble_external_libcall (personality);
3801 if (any_lsda_needed)
3804 augmentation_size += 1;
3806 if (fde_encoding != DW_EH_PE_absptr)
3809 augmentation_size += 1;
3811 if (p > augmentation + 1)
3813 augmentation[0] = 'z';
3817 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3818 if (personality && per_encoding == DW_EH_PE_aligned)
3820 int offset = ( 4 /* Length */
3822 + 1 /* CIE version */
3823 + strlen (augmentation) + 1 /* Augmentation */
3824 + size_of_uleb128 (1) /* Code alignment */
3825 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3827 + 1 /* Augmentation size */
3828 + 1 /* Personality encoding */ );
3829 int pad = -offset & (PTR_SIZE - 1);
3831 augmentation_size += pad;
3833 /* Augmentations should be small, so there's scarce need to
3834 iterate for a solution. Die if we exceed one uleb128 byte. */
3835 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3839 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3840 if (dw_cie_version >= 4)
3842 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
3843 dw2_asm_output_data (1, 0, "CIE Segment Size");
3845 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3846 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3847 "CIE Data Alignment Factor");
3849 if (dw_cie_version == 1)
3850 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3852 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3854 if (augmentation[0])
3856 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3859 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3860 eh_data_format_name (per_encoding));
3861 dw2_asm_output_encoded_addr_rtx (per_encoding,
3866 if (any_lsda_needed)
3867 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3868 eh_data_format_name (lsda_encoding));
3870 if (fde_encoding != DW_EH_PE_absptr)
3871 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3872 eh_data_format_name (fde_encoding));
3875 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3876 output_cfi (cfi, NULL, for_eh);
3878 /* Pad the CIE out to an address sized boundary. */
3879 ASM_OUTPUT_ALIGN (asm_out_file,
3880 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3881 ASM_OUTPUT_LABEL (asm_out_file, l2);
3883 /* Loop through all of the FDE's. */
3884 for (i = 0; i < fde_table_in_use; i++)
3887 fde = &fde_table[i];
3889 /* Don't emit EH unwind info for leaf functions that don't need it. */
3890 if (for_eh && !fde_needed_for_eh_p (fde))
3893 for (k = 0; k < (fde->dw_fde_switched_sections ? 2 : 1); k++)
3894 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
3895 augmentation, any_lsda_needed, lsda_encoding);
3898 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3899 dw2_asm_output_data (4, 0, "End of Table");
3900 #ifdef MIPS_DEBUGGING_INFO
3901 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3902 get a value of 0. Putting .align 0 after the label fixes it. */
3903 ASM_OUTPUT_ALIGN (asm_out_file, 0);
3906 /* Turn off app to make assembly quicker. */
3911 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
3914 dwarf2out_do_cfi_startproc (bool second)
3918 rtx personality = get_personality_function (current_function_decl);
3920 fprintf (asm_out_file, "\t.cfi_startproc\n");
3924 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3927 /* ??? The GAS support isn't entirely consistent. We have to
3928 handle indirect support ourselves, but PC-relative is done
3929 in the assembler. Further, the assembler can't handle any
3930 of the weirder relocation types. */
3931 if (enc & DW_EH_PE_indirect)
3932 ref = dw2_force_const_mem (ref, true);
3934 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
3935 output_addr_const (asm_out_file, ref);
3936 fputc ('\n', asm_out_file);
3939 if (crtl->uses_eh_lsda)
3943 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3944 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
3945 current_function_funcdef_no);
3946 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
3947 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
3949 if (enc & DW_EH_PE_indirect)
3950 ref = dw2_force_const_mem (ref, true);
3952 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
3953 output_addr_const (asm_out_file, ref);
3954 fputc ('\n', asm_out_file);
3958 /* Output a marker (i.e. a label) for the beginning of a function, before
3962 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
3963 const char *file ATTRIBUTE_UNUSED)
3965 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3970 current_function_func_begin_label = NULL;
3972 #ifdef TARGET_UNWIND_INFO
3973 /* ??? current_function_func_begin_label is also used by except.c
3974 for call-site information. We must emit this label if it might
3976 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
3977 && ! dwarf2out_do_frame ())
3980 if (! dwarf2out_do_frame ())
3984 fnsec = function_section (current_function_decl);
3985 switch_to_section (fnsec);
3986 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
3987 current_function_funcdef_no);
3988 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
3989 current_function_funcdef_no);
3990 dup_label = xstrdup (label);
3991 current_function_func_begin_label = dup_label;
3993 #ifdef TARGET_UNWIND_INFO
3994 /* We can elide the fde allocation if we're not emitting debug info. */
3995 if (! dwarf2out_do_frame ())
3999 /* Expand the fde table if necessary. */
4000 if (fde_table_in_use == fde_table_allocated)
4002 fde_table_allocated += FDE_TABLE_INCREMENT;
4003 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
4004 memset (fde_table + fde_table_in_use, 0,
4005 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
4008 /* Record the FDE associated with this function. */
4009 current_funcdef_fde = fde_table_in_use;
4011 /* Add the new FDE at the end of the fde_table. */
4012 fde = &fde_table[fde_table_in_use++];
4013 fde->decl = current_function_decl;
4014 fde->dw_fde_begin = dup_label;
4015 fde->dw_fde_current_label = dup_label;
4016 fde->dw_fde_hot_section_label = NULL;
4017 fde->dw_fde_hot_section_end_label = NULL;
4018 fde->dw_fde_unlikely_section_label = NULL;
4019 fde->dw_fde_unlikely_section_end_label = NULL;
4020 fde->dw_fde_switched_sections = 0;
4021 fde->dw_fde_switched_cold_to_hot = 0;
4022 fde->dw_fde_end = NULL;
4023 fde->dw_fde_vms_end_prologue = NULL;
4024 fde->dw_fde_vms_begin_epilogue = NULL;
4025 fde->dw_fde_cfi = NULL;
4026 fde->dw_fde_switch_cfi = NULL;
4027 fde->funcdef_number = current_function_funcdef_no;
4028 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
4029 fde->uses_eh_lsda = crtl->uses_eh_lsda;
4030 fde->nothrow = crtl->nothrow;
4031 fde->drap_reg = INVALID_REGNUM;
4032 fde->vdrap_reg = INVALID_REGNUM;
4033 if (flag_reorder_blocks_and_partition)
4035 section *unlikelysec;
4036 if (first_function_block_is_cold)
4037 fde->in_std_section = 1;
4040 = (fnsec == text_section
4041 || (cold_text_section && fnsec == cold_text_section));
4042 unlikelysec = unlikely_text_section ();
4043 fde->cold_in_std_section
4044 = (unlikelysec == text_section
4045 || (cold_text_section && unlikelysec == cold_text_section));
4050 = (fnsec == text_section
4051 || (cold_text_section && fnsec == cold_text_section));
4052 fde->cold_in_std_section = 0;
4055 args_size = old_args_size = 0;
4057 /* We only want to output line number information for the genuine dwarf2
4058 prologue case, not the eh frame case. */
4059 #ifdef DWARF2_DEBUGGING_INFO
4061 dwarf2out_source_line (line, file, 0, true);
4064 if (dwarf2out_do_cfi_asm ())
4065 dwarf2out_do_cfi_startproc (false);
4068 rtx personality = get_personality_function (current_function_decl);
4069 if (!current_unit_personality)
4070 current_unit_personality = personality;
4072 /* We cannot keep a current personality per function as without CFI
4073 asm, at the point where we emit the CFI data, there is no current
4074 function anymore. */
4075 if (personality && current_unit_personality != personality)
4076 sorry ("multiple EH personalities are supported only with assemblers "
4077 "supporting .cfi_personality directive");
4081 /* Output a marker (i.e. a label) for the end of the generated code
4082 for a function prologue. This gets called *after* the prologue code has
4086 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
4087 const char *file ATTRIBUTE_UNUSED)
4090 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4092 /* Output a label to mark the endpoint of the code generated for this
4094 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
4095 current_function_funcdef_no);
4096 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
4097 current_function_funcdef_no);
4098 fde = &fde_table[fde_table_in_use - 1];
4099 fde->dw_fde_vms_end_prologue = xstrdup (label);
4102 /* Output a marker (i.e. a label) for the beginning of the generated code
4103 for a function epilogue. This gets called *before* the prologue code has
4107 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4108 const char *file ATTRIBUTE_UNUSED)
4111 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4113 fde = &fde_table[fde_table_in_use - 1];
4114 if (fde->dw_fde_vms_begin_epilogue)
4117 /* Output a label to mark the endpoint of the code generated for this
4119 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
4120 current_function_funcdef_no);
4121 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
4122 current_function_funcdef_no);
4123 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
4126 /* Output a marker (i.e. a label) for the absolute end of the generated code
4127 for a function definition. This gets called *after* the epilogue code has
4131 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4132 const char *file ATTRIBUTE_UNUSED)
4135 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4137 last_var_location_insn = NULL_RTX;
4139 if (dwarf2out_do_cfi_asm ())
4140 fprintf (asm_out_file, "\t.cfi_endproc\n");
4142 /* Output a label to mark the endpoint of the code generated for this
4144 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
4145 current_function_funcdef_no);
4146 ASM_OUTPUT_LABEL (asm_out_file, label);
4147 fde = current_fde ();
4148 gcc_assert (fde != NULL);
4149 fde->dw_fde_end = xstrdup (label);
4153 dwarf2out_frame_init (void)
4155 /* Allocate the initial hunk of the fde_table. */
4156 fde_table = ggc_alloc_cleared_vec_dw_fde_node (FDE_TABLE_INCREMENT);
4157 fde_table_allocated = FDE_TABLE_INCREMENT;
4158 fde_table_in_use = 0;
4160 /* Generate the CFA instructions common to all FDE's. Do it now for the
4161 sake of lookup_cfa. */
4163 /* On entry, the Canonical Frame Address is at SP. */
4164 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
4166 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
4167 initial_return_save (INCOMING_RETURN_ADDR_RTX);
4171 dwarf2out_frame_finish (void)
4173 /* Output call frame information. */
4174 if (DWARF2_FRAME_INFO)
4175 output_call_frame_info (0);
4177 #ifndef TARGET_UNWIND_INFO
4178 /* Output another copy for the unwinder. */
4179 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
4180 output_call_frame_info (1);
4184 /* Note that the current function section is being used for code. */
4187 dwarf2out_note_section_used (void)
4189 section *sec = current_function_section ();
4190 if (sec == text_section)
4191 text_section_used = true;
4192 else if (sec == cold_text_section)
4193 cold_text_section_used = true;
4197 dwarf2out_switch_text_section (void)
4199 dw_fde_ref fde = current_fde ();
4201 gcc_assert (cfun && fde && !fde->dw_fde_switched_sections);
4203 fde->dw_fde_switched_sections = 1;
4204 fde->dw_fde_switched_cold_to_hot = !in_cold_section_p;
4206 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
4207 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
4208 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
4209 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
4210 have_multiple_function_sections = true;
4212 /* Reset the current label on switching text sections, so that we
4213 don't attempt to advance_loc4 between labels in different sections. */
4214 fde->dw_fde_current_label = NULL;
4216 /* There is no need to mark used sections when not debugging. */
4217 if (cold_text_section != NULL)
4218 dwarf2out_note_section_used ();
4220 if (dwarf2out_do_cfi_asm ())
4221 fprintf (asm_out_file, "\t.cfi_endproc\n");
4223 /* Now do the real section switch. */
4224 switch_to_section (current_function_section ());
4226 if (dwarf2out_do_cfi_asm ())
4228 dwarf2out_do_cfi_startproc (true);
4229 /* As this is a different FDE, insert all current CFI instructions
4231 output_cfis (fde->dw_fde_cfi, true, fde, true);
4235 dw_cfi_ref cfi = fde->dw_fde_cfi;
4237 cfi = fde->dw_fde_cfi;
4239 while (cfi->dw_cfi_next != NULL)
4240 cfi = cfi->dw_cfi_next;
4241 fde->dw_fde_switch_cfi = cfi;
4245 /* And now, the subset of the debugging information support code necessary
4246 for emitting location expressions. */
4248 /* Data about a single source file. */
4249 struct GTY(()) dwarf_file_data {
4250 const char * filename;
4254 typedef struct dw_val_struct *dw_val_ref;
4255 typedef struct die_struct *dw_die_ref;
4256 typedef const struct die_struct *const_dw_die_ref;
4257 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
4258 typedef struct dw_loc_list_struct *dw_loc_list_ref;
4260 typedef struct GTY(()) deferred_locations_struct
4264 } deferred_locations;
4266 DEF_VEC_O(deferred_locations);
4267 DEF_VEC_ALLOC_O(deferred_locations,gc);
4269 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
4271 DEF_VEC_P(dw_die_ref);
4272 DEF_VEC_ALLOC_P(dw_die_ref,heap);
4274 /* Each DIE may have a series of attribute/value pairs. Values
4275 can take on several forms. The forms that are used in this
4276 implementation are listed below. */
4281 dw_val_class_offset,
4283 dw_val_class_loc_list,
4284 dw_val_class_range_list,
4286 dw_val_class_unsigned_const,
4287 dw_val_class_const_double,
4290 dw_val_class_die_ref,
4291 dw_val_class_fde_ref,
4292 dw_val_class_lbl_id,
4293 dw_val_class_lineptr,
4295 dw_val_class_macptr,
4298 dw_val_class_vms_delta
4301 /* Describe a floating point constant value, or a vector constant value. */
4303 typedef struct GTY(()) dw_vec_struct {
4304 unsigned char * GTY((length ("%h.length"))) array;
4310 /* The dw_val_node describes an attribute's value, as it is
4311 represented internally. */
4313 typedef struct GTY(()) dw_val_struct {
4314 enum dw_val_class val_class;
4315 union dw_val_struct_union
4317 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
4318 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
4319 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
4320 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
4321 HOST_WIDE_INT GTY ((default)) val_int;
4322 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
4323 double_int GTY ((tag ("dw_val_class_const_double"))) val_double;
4324 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
4325 struct dw_val_die_union
4329 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
4330 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
4331 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
4332 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
4333 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
4334 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
4335 unsigned char GTY ((tag ("dw_val_class_data8"))) val_data8[8];
4336 struct dw_val_vms_delta_union
4340 } GTY ((tag ("dw_val_class_vms_delta"))) val_vms_delta;
4342 GTY ((desc ("%1.val_class"))) v;
4346 /* Locations in memory are described using a sequence of stack machine
4349 typedef struct GTY(()) dw_loc_descr_struct {
4350 dw_loc_descr_ref dw_loc_next;
4351 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
4352 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4353 from DW_OP_addr with a dtp-relative symbol relocation. */
4354 unsigned int dtprel : 1;
4356 dw_val_node dw_loc_oprnd1;
4357 dw_val_node dw_loc_oprnd2;
4361 /* Location lists are ranges + location descriptions for that range,
4362 so you can track variables that are in different places over
4363 their entire life. */
4364 typedef struct GTY(()) dw_loc_list_struct {
4365 dw_loc_list_ref dw_loc_next;
4366 const char *begin; /* Label for begin address of range */
4367 const char *end; /* Label for end address of range */
4368 char *ll_symbol; /* Label for beginning of location list.
4369 Only on head of list */
4370 const char *section; /* Section this loclist is relative to */
4371 dw_loc_descr_ref expr;
4374 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4376 /* Convert a DWARF stack opcode into its string name. */
4379 dwarf_stack_op_name (unsigned int op)
4384 return "DW_OP_addr";
4386 return "DW_OP_deref";
4388 return "DW_OP_const1u";
4390 return "DW_OP_const1s";
4392 return "DW_OP_const2u";
4394 return "DW_OP_const2s";
4396 return "DW_OP_const4u";
4398 return "DW_OP_const4s";
4400 return "DW_OP_const8u";
4402 return "DW_OP_const8s";
4404 return "DW_OP_constu";
4406 return "DW_OP_consts";
4410 return "DW_OP_drop";
4412 return "DW_OP_over";
4414 return "DW_OP_pick";
4416 return "DW_OP_swap";
4420 return "DW_OP_xderef";
4428 return "DW_OP_minus";
4440 return "DW_OP_plus";
4441 case DW_OP_plus_uconst:
4442 return "DW_OP_plus_uconst";
4448 return "DW_OP_shra";
4466 return "DW_OP_skip";
4468 return "DW_OP_lit0";
4470 return "DW_OP_lit1";
4472 return "DW_OP_lit2";
4474 return "DW_OP_lit3";
4476 return "DW_OP_lit4";
4478 return "DW_OP_lit5";
4480 return "DW_OP_lit6";
4482 return "DW_OP_lit7";
4484 return "DW_OP_lit8";
4486 return "DW_OP_lit9";
4488 return "DW_OP_lit10";
4490 return "DW_OP_lit11";
4492 return "DW_OP_lit12";
4494 return "DW_OP_lit13";
4496 return "DW_OP_lit14";
4498 return "DW_OP_lit15";
4500 return "DW_OP_lit16";
4502 return "DW_OP_lit17";
4504 return "DW_OP_lit18";
4506 return "DW_OP_lit19";
4508 return "DW_OP_lit20";
4510 return "DW_OP_lit21";
4512 return "DW_OP_lit22";
4514 return "DW_OP_lit23";
4516 return "DW_OP_lit24";
4518 return "DW_OP_lit25";
4520 return "DW_OP_lit26";
4522 return "DW_OP_lit27";
4524 return "DW_OP_lit28";
4526 return "DW_OP_lit29";
4528 return "DW_OP_lit30";
4530 return "DW_OP_lit31";
4532 return "DW_OP_reg0";
4534 return "DW_OP_reg1";
4536 return "DW_OP_reg2";
4538 return "DW_OP_reg3";
4540 return "DW_OP_reg4";
4542 return "DW_OP_reg5";
4544 return "DW_OP_reg6";
4546 return "DW_OP_reg7";
4548 return "DW_OP_reg8";
4550 return "DW_OP_reg9";
4552 return "DW_OP_reg10";
4554 return "DW_OP_reg11";
4556 return "DW_OP_reg12";
4558 return "DW_OP_reg13";
4560 return "DW_OP_reg14";
4562 return "DW_OP_reg15";
4564 return "DW_OP_reg16";
4566 return "DW_OP_reg17";
4568 return "DW_OP_reg18";
4570 return "DW_OP_reg19";
4572 return "DW_OP_reg20";
4574 return "DW_OP_reg21";
4576 return "DW_OP_reg22";
4578 return "DW_OP_reg23";
4580 return "DW_OP_reg24";
4582 return "DW_OP_reg25";
4584 return "DW_OP_reg26";
4586 return "DW_OP_reg27";
4588 return "DW_OP_reg28";
4590 return "DW_OP_reg29";
4592 return "DW_OP_reg30";
4594 return "DW_OP_reg31";
4596 return "DW_OP_breg0";
4598 return "DW_OP_breg1";
4600 return "DW_OP_breg2";
4602 return "DW_OP_breg3";
4604 return "DW_OP_breg4";
4606 return "DW_OP_breg5";
4608 return "DW_OP_breg6";
4610 return "DW_OP_breg7";
4612 return "DW_OP_breg8";
4614 return "DW_OP_breg9";
4616 return "DW_OP_breg10";
4618 return "DW_OP_breg11";
4620 return "DW_OP_breg12";
4622 return "DW_OP_breg13";
4624 return "DW_OP_breg14";
4626 return "DW_OP_breg15";
4628 return "DW_OP_breg16";
4630 return "DW_OP_breg17";
4632 return "DW_OP_breg18";
4634 return "DW_OP_breg19";
4636 return "DW_OP_breg20";
4638 return "DW_OP_breg21";
4640 return "DW_OP_breg22";
4642 return "DW_OP_breg23";
4644 return "DW_OP_breg24";
4646 return "DW_OP_breg25";
4648 return "DW_OP_breg26";
4650 return "DW_OP_breg27";
4652 return "DW_OP_breg28";
4654 return "DW_OP_breg29";
4656 return "DW_OP_breg30";
4658 return "DW_OP_breg31";
4660 return "DW_OP_regx";
4662 return "DW_OP_fbreg";
4664 return "DW_OP_bregx";
4666 return "DW_OP_piece";
4667 case DW_OP_deref_size:
4668 return "DW_OP_deref_size";
4669 case DW_OP_xderef_size:
4670 return "DW_OP_xderef_size";
4674 case DW_OP_push_object_address:
4675 return "DW_OP_push_object_address";
4677 return "DW_OP_call2";
4679 return "DW_OP_call4";
4680 case DW_OP_call_ref:
4681 return "DW_OP_call_ref";
4682 case DW_OP_implicit_value:
4683 return "DW_OP_implicit_value";
4684 case DW_OP_stack_value:
4685 return "DW_OP_stack_value";
4686 case DW_OP_form_tls_address:
4687 return "DW_OP_form_tls_address";
4688 case DW_OP_call_frame_cfa:
4689 return "DW_OP_call_frame_cfa";
4690 case DW_OP_bit_piece:
4691 return "DW_OP_bit_piece";
4693 case DW_OP_GNU_push_tls_address:
4694 return "DW_OP_GNU_push_tls_address";
4695 case DW_OP_GNU_uninit:
4696 return "DW_OP_GNU_uninit";
4697 case DW_OP_GNU_encoded_addr:
4698 return "DW_OP_GNU_encoded_addr";
4701 return "OP_<unknown>";
4705 /* Return a pointer to a newly allocated location description. Location
4706 descriptions are simple expression terms that can be strung
4707 together to form more complicated location (address) descriptions. */
4709 static inline dw_loc_descr_ref
4710 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4711 unsigned HOST_WIDE_INT oprnd2)
4713 dw_loc_descr_ref descr = ggc_alloc_cleared_dw_loc_descr_node ();
4715 descr->dw_loc_opc = op;
4716 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4717 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4718 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4719 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4724 /* Return a pointer to a newly allocated location description for
4727 static inline dw_loc_descr_ref
4728 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4731 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4734 return new_loc_descr (DW_OP_bregx, reg, offset);
4737 /* Add a location description term to a location description expression. */
4740 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4742 dw_loc_descr_ref *d;
4744 /* Find the end of the chain. */
4745 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4751 /* Add a constant OFFSET to a location expression. */
4754 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4756 dw_loc_descr_ref loc;
4759 gcc_assert (*list_head != NULL);
4764 /* Find the end of the chain. */
4765 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4769 if (loc->dw_loc_opc == DW_OP_fbreg
4770 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4771 p = &loc->dw_loc_oprnd1.v.val_int;
4772 else if (loc->dw_loc_opc == DW_OP_bregx)
4773 p = &loc->dw_loc_oprnd2.v.val_int;
4775 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4776 offset. Don't optimize if an signed integer overflow would happen. */
4778 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4779 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4782 else if (offset > 0)
4783 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4787 loc->dw_loc_next = int_loc_descriptor (-offset);
4788 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
4792 /* Add a constant OFFSET to a location list. */
4795 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
4798 for (d = list_head; d != NULL; d = d->dw_loc_next)
4799 loc_descr_plus_const (&d->expr, offset);
4802 /* Return the size of a location descriptor. */
4804 static unsigned long
4805 size_of_loc_descr (dw_loc_descr_ref loc)
4807 unsigned long size = 1;
4809 switch (loc->dw_loc_opc)
4812 size += DWARF2_ADDR_SIZE;
4831 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4834 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4839 case DW_OP_plus_uconst:
4840 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4878 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4881 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4884 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4887 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4888 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4891 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4893 case DW_OP_bit_piece:
4894 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4895 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
4897 case DW_OP_deref_size:
4898 case DW_OP_xderef_size:
4907 case DW_OP_call_ref:
4908 size += DWARF2_ADDR_SIZE;
4910 case DW_OP_implicit_value:
4911 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
4912 + loc->dw_loc_oprnd1.v.val_unsigned;
4921 /* Return the size of a series of location descriptors. */
4923 static unsigned long
4924 size_of_locs (dw_loc_descr_ref loc)
4929 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
4930 field, to avoid writing to a PCH file. */
4931 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4933 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
4935 size += size_of_loc_descr (l);
4940 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4942 l->dw_loc_addr = size;
4943 size += size_of_loc_descr (l);
4949 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
4951 /* Output location description stack opcode's operands (if any). */
4954 output_loc_operands (dw_loc_descr_ref loc)
4956 dw_val_ref val1 = &loc->dw_loc_oprnd1;
4957 dw_val_ref val2 = &loc->dw_loc_oprnd2;
4959 switch (loc->dw_loc_opc)
4961 #ifdef DWARF2_DEBUGGING_INFO
4964 dw2_asm_output_data (2, val1->v.val_int, NULL);
4969 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
4970 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
4972 fputc ('\n', asm_out_file);
4977 dw2_asm_output_data (4, val1->v.val_int, NULL);
4982 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
4983 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
4985 fputc ('\n', asm_out_file);
4990 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
4991 dw2_asm_output_data (8, val1->v.val_int, NULL);
4998 gcc_assert (val1->val_class == dw_val_class_loc);
4999 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5001 dw2_asm_output_data (2, offset, NULL);
5004 case DW_OP_implicit_value:
5005 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5006 switch (val2->val_class)
5008 case dw_val_class_const:
5009 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
5011 case dw_val_class_vec:
5013 unsigned int elt_size = val2->v.val_vec.elt_size;
5014 unsigned int len = val2->v.val_vec.length;
5018 if (elt_size > sizeof (HOST_WIDE_INT))
5023 for (i = 0, p = val2->v.val_vec.array;
5026 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
5027 "fp or vector constant word %u", i);
5030 case dw_val_class_const_double:
5032 unsigned HOST_WIDE_INT first, second;
5034 if (WORDS_BIG_ENDIAN)
5036 first = val2->v.val_double.high;
5037 second = val2->v.val_double.low;
5041 first = val2->v.val_double.low;
5042 second = val2->v.val_double.high;
5044 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5046 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5050 case dw_val_class_addr:
5051 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
5052 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
5067 case DW_OP_implicit_value:
5068 /* We currently don't make any attempt to make sure these are
5069 aligned properly like we do for the main unwind info, so
5070 don't support emitting things larger than a byte if we're
5071 only doing unwinding. */
5076 dw2_asm_output_data (1, val1->v.val_int, NULL);
5079 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5082 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5085 dw2_asm_output_data (1, val1->v.val_int, NULL);
5087 case DW_OP_plus_uconst:
5088 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5122 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5125 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5128 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5131 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5132 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5135 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5137 case DW_OP_bit_piece:
5138 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5139 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
5141 case DW_OP_deref_size:
5142 case DW_OP_xderef_size:
5143 dw2_asm_output_data (1, val1->v.val_int, NULL);
5149 if (targetm.asm_out.output_dwarf_dtprel)
5151 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
5154 fputc ('\n', asm_out_file);
5161 #ifdef DWARF2_DEBUGGING_INFO
5162 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
5170 /* Other codes have no operands. */
5175 /* Output a sequence of location operations. */
5178 output_loc_sequence (dw_loc_descr_ref loc)
5180 for (; loc != NULL; loc = loc->dw_loc_next)
5182 /* Output the opcode. */
5183 dw2_asm_output_data (1, loc->dw_loc_opc,
5184 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
5186 /* Output the operand(s) (if any). */
5187 output_loc_operands (loc);
5191 /* Output location description stack opcode's operands (if any).
5192 The output is single bytes on a line, suitable for .cfi_escape. */
5195 output_loc_operands_raw (dw_loc_descr_ref loc)
5197 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5198 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5200 switch (loc->dw_loc_opc)
5203 case DW_OP_implicit_value:
5204 /* We cannot output addresses in .cfi_escape, only bytes. */
5210 case DW_OP_deref_size:
5211 case DW_OP_xderef_size:
5212 fputc (',', asm_out_file);
5213 dw2_asm_output_data_raw (1, val1->v.val_int);
5218 fputc (',', asm_out_file);
5219 dw2_asm_output_data_raw (2, val1->v.val_int);
5224 fputc (',', asm_out_file);
5225 dw2_asm_output_data_raw (4, val1->v.val_int);
5230 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5231 fputc (',', asm_out_file);
5232 dw2_asm_output_data_raw (8, val1->v.val_int);
5240 gcc_assert (val1->val_class == dw_val_class_loc);
5241 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5243 fputc (',', asm_out_file);
5244 dw2_asm_output_data_raw (2, offset);
5249 case DW_OP_plus_uconst:
5252 fputc (',', asm_out_file);
5253 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5256 case DW_OP_bit_piece:
5257 fputc (',', asm_out_file);
5258 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5259 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
5296 fputc (',', asm_out_file);
5297 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
5301 fputc (',', asm_out_file);
5302 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5303 fputc (',', asm_out_file);
5304 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
5308 /* Other codes have no operands. */
5314 output_loc_sequence_raw (dw_loc_descr_ref loc)
5318 /* Output the opcode. */
5319 fprintf (asm_out_file, "%#x", loc->dw_loc_opc);
5320 output_loc_operands_raw (loc);
5322 if (!loc->dw_loc_next)
5324 loc = loc->dw_loc_next;
5326 fputc (',', asm_out_file);
5330 /* This routine will generate the correct assembly data for a location
5331 description based on a cfi entry with a complex address. */
5334 output_cfa_loc (dw_cfi_ref cfi)
5336 dw_loc_descr_ref loc;
5339 if (cfi->dw_cfi_opc == DW_CFA_expression)
5341 dw2_asm_output_data (1, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
5342 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5345 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5347 /* Output the size of the block. */
5348 size = size_of_locs (loc);
5349 dw2_asm_output_data_uleb128 (size, NULL);
5351 /* Now output the operations themselves. */
5352 output_loc_sequence (loc);
5355 /* Similar, but used for .cfi_escape. */
5358 output_cfa_loc_raw (dw_cfi_ref cfi)
5360 dw_loc_descr_ref loc;
5363 if (cfi->dw_cfi_opc == DW_CFA_expression)
5365 fprintf (asm_out_file, "%#x,", cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
5366 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5369 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5371 /* Output the size of the block. */
5372 size = size_of_locs (loc);
5373 dw2_asm_output_data_uleb128_raw (size);
5374 fputc (',', asm_out_file);
5376 /* Now output the operations themselves. */
5377 output_loc_sequence_raw (loc);
5380 /* This function builds a dwarf location descriptor sequence from a
5381 dw_cfa_location, adding the given OFFSET to the result of the
5384 static struct dw_loc_descr_struct *
5385 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
5387 struct dw_loc_descr_struct *head, *tmp;
5389 offset += cfa->offset;
5393 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
5394 head->dw_loc_oprnd1.val_class = dw_val_class_const;
5395 tmp = new_loc_descr (DW_OP_deref, 0, 0);
5396 add_loc_descr (&head, tmp);
5399 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
5400 add_loc_descr (&head, tmp);
5404 head = new_reg_loc_descr (cfa->reg, offset);
5409 /* This function builds a dwarf location descriptor sequence for
5410 the address at OFFSET from the CFA when stack is aligned to
5413 static struct dw_loc_descr_struct *
5414 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
5416 struct dw_loc_descr_struct *head;
5417 unsigned int dwarf_fp
5418 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
5420 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5421 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
5423 head = new_reg_loc_descr (dwarf_fp, 0);
5424 add_loc_descr (&head, int_loc_descriptor (alignment));
5425 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
5426 loc_descr_plus_const (&head, offset);
5429 head = new_reg_loc_descr (dwarf_fp, offset);
5433 /* This function fills in aa dw_cfa_location structure from a dwarf location
5434 descriptor sequence. */
5437 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
5439 struct dw_loc_descr_struct *ptr;
5441 cfa->base_offset = 0;
5445 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
5447 enum dwarf_location_atom op = ptr->dw_loc_opc;
5483 cfa->reg = op - DW_OP_reg0;
5486 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5520 cfa->reg = op - DW_OP_breg0;
5521 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
5524 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5525 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
5530 case DW_OP_plus_uconst:
5531 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
5534 internal_error ("DW_LOC_OP %s not implemented",
5535 dwarf_stack_op_name (ptr->dw_loc_opc));
5540 /* And now, the support for symbolic debugging information. */
5542 /* .debug_str support. */
5543 static int output_indirect_string (void **, void *);
5545 static void dwarf2out_init (const char *);
5546 static void dwarf2out_finish (const char *);
5547 static void dwarf2out_assembly_start (void);
5548 static void dwarf2out_define (unsigned int, const char *);
5549 static void dwarf2out_undef (unsigned int, const char *);
5550 static void dwarf2out_start_source_file (unsigned, const char *);
5551 static void dwarf2out_end_source_file (unsigned);
5552 static void dwarf2out_function_decl (tree);
5553 static void dwarf2out_begin_block (unsigned, unsigned);
5554 static void dwarf2out_end_block (unsigned, unsigned);
5555 static bool dwarf2out_ignore_block (const_tree);
5556 static void dwarf2out_global_decl (tree);
5557 static void dwarf2out_type_decl (tree, int);
5558 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
5559 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
5561 static void dwarf2out_abstract_function (tree);
5562 static void dwarf2out_var_location (rtx);
5563 static void dwarf2out_direct_call (tree);
5564 static void dwarf2out_virtual_call_token (tree, int);
5565 static void dwarf2out_copy_call_info (rtx, rtx);
5566 static void dwarf2out_virtual_call (int);
5567 static void dwarf2out_begin_function (tree);
5568 static void dwarf2out_set_name (tree, tree);
5570 /* The debug hooks structure. */
5572 const struct gcc_debug_hooks dwarf2_debug_hooks =
5576 dwarf2out_assembly_start,
5579 dwarf2out_start_source_file,
5580 dwarf2out_end_source_file,
5581 dwarf2out_begin_block,
5582 dwarf2out_end_block,
5583 dwarf2out_ignore_block,
5584 dwarf2out_source_line,
5585 dwarf2out_begin_prologue,
5586 #if VMS_DEBUGGING_INFO
5587 dwarf2out_vms_end_prologue,
5588 dwarf2out_vms_begin_epilogue,
5590 debug_nothing_int_charstar,
5591 debug_nothing_int_charstar,
5593 dwarf2out_end_epilogue,
5594 dwarf2out_begin_function,
5595 debug_nothing_int, /* end_function */
5596 dwarf2out_function_decl, /* function_decl */
5597 dwarf2out_global_decl,
5598 dwarf2out_type_decl, /* type_decl */
5599 dwarf2out_imported_module_or_decl,
5600 debug_nothing_tree, /* deferred_inline_function */
5601 /* The DWARF 2 backend tries to reduce debugging bloat by not
5602 emitting the abstract description of inline functions until
5603 something tries to reference them. */
5604 dwarf2out_abstract_function, /* outlining_inline_function */
5605 debug_nothing_rtx, /* label */
5606 debug_nothing_int, /* handle_pch */
5607 dwarf2out_var_location,
5608 dwarf2out_switch_text_section,
5609 dwarf2out_direct_call,
5610 dwarf2out_virtual_call_token,
5611 dwarf2out_copy_call_info,
5612 dwarf2out_virtual_call,
5614 1 /* start_end_main_source_file */
5617 /* NOTE: In the comments in this file, many references are made to
5618 "Debugging Information Entries". This term is abbreviated as `DIE'
5619 throughout the remainder of this file. */
5621 /* An internal representation of the DWARF output is built, and then
5622 walked to generate the DWARF debugging info. The walk of the internal
5623 representation is done after the entire program has been compiled.
5624 The types below are used to describe the internal representation. */
5626 /* Various DIE's use offsets relative to the beginning of the
5627 .debug_info section to refer to each other. */
5629 typedef long int dw_offset;
5631 /* Define typedefs here to avoid circular dependencies. */
5633 typedef struct dw_attr_struct *dw_attr_ref;
5634 typedef struct dw_line_info_struct *dw_line_info_ref;
5635 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
5636 typedef struct pubname_struct *pubname_ref;
5637 typedef struct dw_ranges_struct *dw_ranges_ref;
5638 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
5639 typedef struct comdat_type_struct *comdat_type_node_ref;
5641 /* Each entry in the line_info_table maintains the file and
5642 line number associated with the label generated for that
5643 entry. The label gives the PC value associated with
5644 the line number entry. */
5646 typedef struct GTY(()) dw_line_info_struct {
5647 unsigned long dw_file_num;
5648 unsigned long dw_line_num;
5652 /* Line information for functions in separate sections; each one gets its
5654 typedef struct GTY(()) dw_separate_line_info_struct {
5655 unsigned long dw_file_num;
5656 unsigned long dw_line_num;
5657 unsigned long function;
5659 dw_separate_line_info_entry;
5661 /* Each DIE attribute has a field specifying the attribute kind,
5662 a link to the next attribute in the chain, and an attribute value.
5663 Attributes are typically linked below the DIE they modify. */
5665 typedef struct GTY(()) dw_attr_struct {
5666 enum dwarf_attribute dw_attr;
5667 dw_val_node dw_attr_val;
5671 DEF_VEC_O(dw_attr_node);
5672 DEF_VEC_ALLOC_O(dw_attr_node,gc);
5674 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5675 The children of each node form a circular list linked by
5676 die_sib. die_child points to the node *before* the "first" child node. */
5678 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
5679 union die_symbol_or_type_node
5681 char * GTY ((tag ("0"))) die_symbol;
5682 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
5684 GTY ((desc ("dwarf_version >= 4"))) die_id;
5685 VEC(dw_attr_node,gc) * die_attr;
5686 dw_die_ref die_parent;
5687 dw_die_ref die_child;
5689 dw_die_ref die_definition; /* ref from a specification to its definition */
5690 dw_offset die_offset;
5691 unsigned long die_abbrev;
5693 /* Die is used and must not be pruned as unused. */
5694 int die_perennial_p;
5695 unsigned int decl_id;
5696 enum dwarf_tag die_tag;
5700 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5701 #define FOR_EACH_CHILD(die, c, expr) do { \
5702 c = die->die_child; \
5706 } while (c != die->die_child); \
5709 /* The pubname structure */
5711 typedef struct GTY(()) pubname_struct {
5717 DEF_VEC_O(pubname_entry);
5718 DEF_VEC_ALLOC_O(pubname_entry, gc);
5720 struct GTY(()) dw_ranges_struct {
5721 /* If this is positive, it's a block number, otherwise it's a
5722 bitwise-negated index into dw_ranges_by_label. */
5726 struct GTY(()) dw_ranges_by_label_struct {
5731 /* The comdat type node structure. */
5732 typedef struct GTY(()) comdat_type_struct
5734 dw_die_ref root_die;
5735 dw_die_ref type_die;
5736 char signature[DWARF_TYPE_SIGNATURE_SIZE];
5737 struct comdat_type_struct *next;
5741 /* The limbo die list structure. */
5742 typedef struct GTY(()) limbo_die_struct {
5745 struct limbo_die_struct *next;
5749 typedef struct GTY(()) skeleton_chain_struct
5753 struct skeleton_chain_struct *parent;
5755 skeleton_chain_node;
5757 /* How to start an assembler comment. */
5758 #ifndef ASM_COMMENT_START
5759 #define ASM_COMMENT_START ";#"
5762 /* Define a macro which returns nonzero for a TYPE_DECL which was
5763 implicitly generated for a tagged type.
5765 Note that unlike the gcc front end (which generates a NULL named
5766 TYPE_DECL node for each complete tagged type, each array type, and
5767 each function type node created) the g++ front end generates a
5768 _named_ TYPE_DECL node for each tagged type node created.
5769 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
5770 generate a DW_TAG_typedef DIE for them. */
5772 #define TYPE_DECL_IS_STUB(decl) \
5773 (DECL_NAME (decl) == NULL_TREE \
5774 || (DECL_ARTIFICIAL (decl) \
5775 && is_tagged_type (TREE_TYPE (decl)) \
5776 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
5777 /* This is necessary for stub decls that \
5778 appear in nested inline functions. */ \
5779 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
5780 && (decl_ultimate_origin (decl) \
5781 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
5783 /* Information concerning the compilation unit's programming
5784 language, and compiler version. */
5786 /* Fixed size portion of the DWARF compilation unit header. */
5787 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
5788 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
5790 /* Fixed size portion of the DWARF comdat type unit header. */
5791 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
5792 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
5793 + DWARF_OFFSET_SIZE)
5795 /* Fixed size portion of public names info. */
5796 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
5798 /* Fixed size portion of the address range info. */
5799 #define DWARF_ARANGES_HEADER_SIZE \
5800 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5801 DWARF2_ADDR_SIZE * 2) \
5802 - DWARF_INITIAL_LENGTH_SIZE)
5804 /* Size of padding portion in the address range info. It must be
5805 aligned to twice the pointer size. */
5806 #define DWARF_ARANGES_PAD_SIZE \
5807 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5808 DWARF2_ADDR_SIZE * 2) \
5809 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
5811 /* Use assembler line directives if available. */
5812 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
5813 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
5814 #define DWARF2_ASM_LINE_DEBUG_INFO 1
5816 #define DWARF2_ASM_LINE_DEBUG_INFO 0
5820 /* Minimum line offset in a special line info. opcode.
5821 This value was chosen to give a reasonable range of values. */
5822 #define DWARF_LINE_BASE -10
5824 /* First special line opcode - leave room for the standard opcodes. */
5825 #define DWARF_LINE_OPCODE_BASE 10
5827 /* Range of line offsets in a special line info. opcode. */
5828 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
5830 /* Flag that indicates the initial value of the is_stmt_start flag.
5831 In the present implementation, we do not mark any lines as
5832 the beginning of a source statement, because that information
5833 is not made available by the GCC front-end. */
5834 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
5836 /* Maximum number of operations per instruction bundle. */
5837 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
5838 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
5841 /* This location is used by calc_die_sizes() to keep track
5842 the offset of each DIE within the .debug_info section. */
5843 static unsigned long next_die_offset;
5845 /* Record the root of the DIE's built for the current compilation unit. */
5846 static GTY(()) dw_die_ref comp_unit_die;
5848 /* A list of type DIEs that have been separated into comdat sections. */
5849 static GTY(()) comdat_type_node *comdat_type_list;
5851 /* A list of DIEs with a NULL parent waiting to be relocated. */
5852 static GTY(()) limbo_die_node *limbo_die_list;
5854 /* A list of DIEs for which we may have to generate
5855 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
5856 static GTY(()) limbo_die_node *deferred_asm_name;
5858 /* Filenames referenced by this compilation unit. */
5859 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
5861 /* A hash table of references to DIE's that describe declarations.
5862 The key is a DECL_UID() which is a unique number identifying each decl. */
5863 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
5865 /* A hash table of references to DIE's that describe COMMON blocks.
5866 The key is DECL_UID() ^ die_parent. */
5867 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
5869 typedef struct GTY(()) die_arg_entry_struct {
5874 DEF_VEC_O(die_arg_entry);
5875 DEF_VEC_ALLOC_O(die_arg_entry,gc);
5877 /* Node of the variable location list. */
5878 struct GTY ((chain_next ("%h.next"))) var_loc_node {
5879 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
5880 EXPR_LIST chain. For small bitsizes, bitsize is encoded
5881 in mode of the EXPR_LIST node and first EXPR_LIST operand
5882 is either NOTE_INSN_VAR_LOCATION for a piece with a known
5883 location or NULL for padding. For larger bitsizes,
5884 mode is 0 and first operand is a CONCAT with bitsize
5885 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
5886 NULL as second operand. */
5888 const char * GTY (()) label;
5889 struct var_loc_node * GTY (()) next;
5892 /* Variable location list. */
5893 struct GTY (()) var_loc_list_def {
5894 struct var_loc_node * GTY (()) first;
5896 /* Pointer to the last but one or last element of the
5897 chained list. If the list is empty, both first and
5898 last are NULL, if the list contains just one node
5899 or the last node certainly is not redundant, it points
5900 to the last node, otherwise points to the last but one.
5901 Do not mark it for GC because it is marked through the chain. */
5902 struct var_loc_node * GTY ((skip ("%h"))) last;
5904 /* DECL_UID of the variable decl. */
5905 unsigned int decl_id;
5907 typedef struct var_loc_list_def var_loc_list;
5910 /* Table of decl location linked lists. */
5911 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
5913 /* A pointer to the base of a list of references to DIE's that
5914 are uniquely identified by their tag, presence/absence of
5915 children DIE's, and list of attribute/value pairs. */
5916 static GTY((length ("abbrev_die_table_allocated")))
5917 dw_die_ref *abbrev_die_table;
5919 /* Number of elements currently allocated for abbrev_die_table. */
5920 static GTY(()) unsigned abbrev_die_table_allocated;
5922 /* Number of elements in type_die_table currently in use. */
5923 static GTY(()) unsigned abbrev_die_table_in_use;
5925 /* Size (in elements) of increments by which we may expand the
5926 abbrev_die_table. */
5927 #define ABBREV_DIE_TABLE_INCREMENT 256
5929 /* A pointer to the base of a table that contains line information
5930 for each source code line in .text in the compilation unit. */
5931 static GTY((length ("line_info_table_allocated")))
5932 dw_line_info_ref line_info_table;
5934 /* Number of elements currently allocated for line_info_table. */
5935 static GTY(()) unsigned line_info_table_allocated;
5937 /* Number of elements in line_info_table currently in use. */
5938 static GTY(()) unsigned line_info_table_in_use;
5940 /* A pointer to the base of a table that contains line information
5941 for each source code line outside of .text in the compilation unit. */
5942 static GTY ((length ("separate_line_info_table_allocated")))
5943 dw_separate_line_info_ref separate_line_info_table;
5945 /* Number of elements currently allocated for separate_line_info_table. */
5946 static GTY(()) unsigned separate_line_info_table_allocated;
5948 /* Number of elements in separate_line_info_table currently in use. */
5949 static GTY(()) unsigned separate_line_info_table_in_use;
5951 /* Size (in elements) of increments by which we may expand the
5953 #define LINE_INFO_TABLE_INCREMENT 1024
5955 /* A pointer to the base of a table that contains a list of publicly
5956 accessible names. */
5957 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
5959 /* A pointer to the base of a table that contains a list of publicly
5960 accessible types. */
5961 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
5963 /* Array of dies for which we should generate .debug_arange info. */
5964 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
5966 /* Number of elements currently allocated for arange_table. */
5967 static GTY(()) unsigned arange_table_allocated;
5969 /* Number of elements in arange_table currently in use. */
5970 static GTY(()) unsigned arange_table_in_use;
5972 /* Size (in elements) of increments by which we may expand the
5974 #define ARANGE_TABLE_INCREMENT 64
5976 /* Array of dies for which we should generate .debug_ranges info. */
5977 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
5979 /* Number of elements currently allocated for ranges_table. */
5980 static GTY(()) unsigned ranges_table_allocated;
5982 /* Number of elements in ranges_table currently in use. */
5983 static GTY(()) unsigned ranges_table_in_use;
5985 /* Array of pairs of labels referenced in ranges_table. */
5986 static GTY ((length ("ranges_by_label_allocated")))
5987 dw_ranges_by_label_ref ranges_by_label;
5989 /* Number of elements currently allocated for ranges_by_label. */
5990 static GTY(()) unsigned ranges_by_label_allocated;
5992 /* Number of elements in ranges_by_label currently in use. */
5993 static GTY(()) unsigned ranges_by_label_in_use;
5995 /* Size (in elements) of increments by which we may expand the
5997 #define RANGES_TABLE_INCREMENT 64
5999 /* Whether we have location lists that need outputting */
6000 static GTY(()) bool have_location_lists;
6002 /* Unique label counter. */
6003 static GTY(()) unsigned int loclabel_num;
6005 /* Unique label counter for point-of-call tables. */
6006 static GTY(()) unsigned int poc_label_num;
6008 /* The direct call table structure. */
6010 typedef struct GTY(()) dcall_struct {
6011 unsigned int poc_label_num;
6013 dw_die_ref targ_die;
6017 DEF_VEC_O(dcall_entry);
6018 DEF_VEC_ALLOC_O(dcall_entry, gc);
6020 /* The virtual call table structure. */
6022 typedef struct GTY(()) vcall_struct {
6023 unsigned int poc_label_num;
6024 unsigned int vtable_slot;
6028 DEF_VEC_O(vcall_entry);
6029 DEF_VEC_ALLOC_O(vcall_entry, gc);
6031 /* Pointers to the direct and virtual call tables. */
6032 static GTY (()) VEC (dcall_entry, gc) * dcall_table = NULL;
6033 static GTY (()) VEC (vcall_entry, gc) * vcall_table = NULL;
6035 /* A hash table to map INSN_UIDs to vtable slot indexes. */
6037 struct GTY (()) vcall_insn {
6039 unsigned int vtable_slot;
6042 static GTY ((param_is (struct vcall_insn))) htab_t vcall_insn_table;
6044 /* Record whether the function being analyzed contains inlined functions. */
6045 static int current_function_has_inlines;
6046 #if 0 && defined (MIPS_DEBUGGING_INFO)
6047 static int comp_unit_has_inlines;
6050 /* The last file entry emitted by maybe_emit_file(). */
6051 static GTY(()) struct dwarf_file_data * last_emitted_file;
6053 /* Number of internal labels generated by gen_internal_sym(). */
6054 static GTY(()) int label_num;
6056 /* Cached result of previous call to lookup_filename. */
6057 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
6059 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
6061 /* Offset from the "steady-state frame pointer" to the frame base,
6062 within the current function. */
6063 static HOST_WIDE_INT frame_pointer_fb_offset;
6065 /* Forward declarations for functions defined in this file. */
6067 static int is_pseudo_reg (const_rtx);
6068 static tree type_main_variant (tree);
6069 static int is_tagged_type (const_tree);
6070 static const char *dwarf_tag_name (unsigned);
6071 static const char *dwarf_attr_name (unsigned);
6072 static const char *dwarf_form_name (unsigned);
6073 static tree decl_ultimate_origin (const_tree);
6074 static tree decl_class_context (tree);
6075 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
6076 static inline enum dw_val_class AT_class (dw_attr_ref);
6077 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
6078 static inline unsigned AT_flag (dw_attr_ref);
6079 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
6080 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
6081 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
6082 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
6083 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
6084 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
6085 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
6086 unsigned int, unsigned char *);
6087 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
6088 static hashval_t debug_str_do_hash (const void *);
6089 static int debug_str_eq (const void *, const void *);
6090 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
6091 static inline const char *AT_string (dw_attr_ref);
6092 static enum dwarf_form AT_string_form (dw_attr_ref);
6093 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
6094 static void add_AT_specification (dw_die_ref, dw_die_ref);
6095 static inline dw_die_ref AT_ref (dw_attr_ref);
6096 static inline int AT_ref_external (dw_attr_ref);
6097 static inline void set_AT_ref_external (dw_attr_ref, int);
6098 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
6099 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
6100 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
6101 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
6103 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
6104 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
6105 static inline rtx AT_addr (dw_attr_ref);
6106 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
6107 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
6108 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
6109 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
6110 unsigned HOST_WIDE_INT);
6111 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
6113 static inline const char *AT_lbl (dw_attr_ref);
6114 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
6115 static const char *get_AT_low_pc (dw_die_ref);
6116 static const char *get_AT_hi_pc (dw_die_ref);
6117 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
6118 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
6119 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
6120 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
6121 static bool is_cxx (void);
6122 static bool is_fortran (void);
6123 static bool is_ada (void);
6124 static void remove_AT (dw_die_ref, enum dwarf_attribute);
6125 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
6126 static void add_child_die (dw_die_ref, dw_die_ref);
6127 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
6128 static dw_die_ref lookup_type_die (tree);
6129 static void equate_type_number_to_die (tree, dw_die_ref);
6130 static hashval_t decl_die_table_hash (const void *);
6131 static int decl_die_table_eq (const void *, const void *);
6132 static dw_die_ref lookup_decl_die (tree);
6133 static hashval_t common_block_die_table_hash (const void *);
6134 static int common_block_die_table_eq (const void *, const void *);
6135 static hashval_t decl_loc_table_hash (const void *);
6136 static int decl_loc_table_eq (const void *, const void *);
6137 static var_loc_list *lookup_decl_loc (const_tree);
6138 static void equate_decl_number_to_die (tree, dw_die_ref);
6139 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
6140 static void print_spaces (FILE *);
6141 static void print_die (dw_die_ref, FILE *);
6142 static void print_dwarf_line_table (FILE *);
6143 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
6144 static dw_die_ref pop_compile_unit (dw_die_ref);
6145 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
6146 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
6147 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
6148 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
6149 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
6150 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
6151 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
6152 struct md5_ctx *, int *);
6153 struct checksum_attributes;
6154 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
6155 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
6156 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
6157 static void generate_type_signature (dw_die_ref, comdat_type_node *);
6158 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
6159 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
6160 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
6161 static int same_die_p (dw_die_ref, dw_die_ref, int *);
6162 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
6163 static void compute_section_prefix (dw_die_ref);
6164 static int is_type_die (dw_die_ref);
6165 static int is_comdat_die (dw_die_ref);
6166 static int is_symbol_die (dw_die_ref);
6167 static void assign_symbol_names (dw_die_ref);
6168 static void break_out_includes (dw_die_ref);
6169 static int is_declaration_die (dw_die_ref);
6170 static int should_move_die_to_comdat (dw_die_ref);
6171 static dw_die_ref clone_as_declaration (dw_die_ref);
6172 static dw_die_ref clone_die (dw_die_ref);
6173 static dw_die_ref clone_tree (dw_die_ref);
6174 static void copy_declaration_context (dw_die_ref, dw_die_ref);
6175 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
6176 static void generate_skeleton_bottom_up (skeleton_chain_node *);
6177 static dw_die_ref generate_skeleton (dw_die_ref);
6178 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
6180 static void break_out_comdat_types (dw_die_ref);
6181 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
6182 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
6183 static void copy_decls_for_unworthy_types (dw_die_ref);
6185 static hashval_t htab_cu_hash (const void *);
6186 static int htab_cu_eq (const void *, const void *);
6187 static void htab_cu_del (void *);
6188 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
6189 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
6190 static void add_sibling_attributes (dw_die_ref);
6191 static void build_abbrev_table (dw_die_ref);
6192 static void output_location_lists (dw_die_ref);
6193 static int constant_size (unsigned HOST_WIDE_INT);
6194 static unsigned long size_of_die (dw_die_ref);
6195 static void calc_die_sizes (dw_die_ref);
6196 static void mark_dies (dw_die_ref);
6197 static void unmark_dies (dw_die_ref);
6198 static void unmark_all_dies (dw_die_ref);
6199 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
6200 static unsigned long size_of_aranges (void);
6201 static enum dwarf_form value_format (dw_attr_ref);
6202 static void output_value_format (dw_attr_ref);
6203 static void output_abbrev_section (void);
6204 static void output_die_symbol (dw_die_ref);
6205 static void output_die (dw_die_ref);
6206 static void output_compilation_unit_header (void);
6207 static void output_comp_unit (dw_die_ref, int);
6208 static void output_comdat_type_unit (comdat_type_node *);
6209 static const char *dwarf2_name (tree, int);
6210 static void add_pubname (tree, dw_die_ref);
6211 static void add_pubname_string (const char *, dw_die_ref);
6212 static void add_pubtype (tree, dw_die_ref);
6213 static void output_pubnames (VEC (pubname_entry,gc) *);
6214 static void add_arange (tree, dw_die_ref);
6215 static void output_aranges (void);
6216 static unsigned int add_ranges_num (int);
6217 static unsigned int add_ranges (const_tree);
6218 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
6220 static void output_ranges (void);
6221 static void output_line_info (void);
6222 static void output_file_names (void);
6223 static dw_die_ref base_type_die (tree);
6224 static int is_base_type (tree);
6225 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
6226 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
6227 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
6228 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
6229 static int type_is_enum (const_tree);
6230 static unsigned int dbx_reg_number (const_rtx);
6231 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
6232 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
6233 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
6234 enum var_init_status);
6235 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
6236 enum var_init_status);
6237 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
6238 enum var_init_status);
6239 static int is_based_loc (const_rtx);
6240 static int resolve_one_addr (rtx *, void *);
6241 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
6242 enum var_init_status);
6243 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
6244 enum var_init_status);
6245 static dw_loc_list_ref loc_list_from_tree (tree, int);
6246 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
6247 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
6248 static tree field_type (const_tree);
6249 static unsigned int simple_type_align_in_bits (const_tree);
6250 static unsigned int simple_decl_align_in_bits (const_tree);
6251 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
6252 static HOST_WIDE_INT field_byte_offset (const_tree);
6253 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
6255 static void add_data_member_location_attribute (dw_die_ref, tree);
6256 static bool add_const_value_attribute (dw_die_ref, rtx);
6257 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
6258 static void insert_double (double_int, unsigned char *);
6259 static void insert_float (const_rtx, unsigned char *);
6260 static rtx rtl_for_decl_location (tree);
6261 static bool add_location_or_const_value_attribute (dw_die_ref, tree,
6262 enum dwarf_attribute);
6263 static bool tree_add_const_value_attribute (dw_die_ref, tree);
6264 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
6265 static void add_name_attribute (dw_die_ref, const char *);
6266 static void add_comp_dir_attribute (dw_die_ref);
6267 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
6268 static void add_subscript_info (dw_die_ref, tree, bool);
6269 static void add_byte_size_attribute (dw_die_ref, tree);
6270 static void add_bit_offset_attribute (dw_die_ref, tree);
6271 static void add_bit_size_attribute (dw_die_ref, tree);
6272 static void add_prototyped_attribute (dw_die_ref, tree);
6273 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
6274 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
6275 static void add_src_coords_attributes (dw_die_ref, tree);
6276 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
6277 static void push_decl_scope (tree);
6278 static void pop_decl_scope (void);
6279 static dw_die_ref scope_die_for (tree, dw_die_ref);
6280 static inline int local_scope_p (dw_die_ref);
6281 static inline int class_scope_p (dw_die_ref);
6282 static inline int class_or_namespace_scope_p (dw_die_ref);
6283 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
6284 static void add_calling_convention_attribute (dw_die_ref, tree);
6285 static const char *type_tag (const_tree);
6286 static tree member_declared_type (const_tree);
6288 static const char *decl_start_label (tree);
6290 static void gen_array_type_die (tree, dw_die_ref);
6291 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
6293 static void gen_entry_point_die (tree, dw_die_ref);
6295 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
6296 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
6297 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
6298 static void gen_unspecified_parameters_die (tree, dw_die_ref);
6299 static void gen_formal_types_die (tree, dw_die_ref);
6300 static void gen_subprogram_die (tree, dw_die_ref);
6301 static void gen_variable_die (tree, tree, dw_die_ref);
6302 static void gen_const_die (tree, dw_die_ref);
6303 static void gen_label_die (tree, dw_die_ref);
6304 static void gen_lexical_block_die (tree, dw_die_ref, int);
6305 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
6306 static void gen_field_die (tree, dw_die_ref);
6307 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
6308 static dw_die_ref gen_compile_unit_die (const char *);
6309 static void gen_inheritance_die (tree, tree, dw_die_ref);
6310 static void gen_member_die (tree, dw_die_ref);
6311 static void gen_struct_or_union_type_die (tree, dw_die_ref,
6312 enum debug_info_usage);
6313 static void gen_subroutine_type_die (tree, dw_die_ref);
6314 static void gen_typedef_die (tree, dw_die_ref);
6315 static void gen_type_die (tree, dw_die_ref);
6316 static void gen_block_die (tree, dw_die_ref, int);
6317 static void decls_for_scope (tree, dw_die_ref, int);
6318 static int is_redundant_typedef (const_tree);
6319 static bool is_naming_typedef_decl (const_tree);
6320 static inline dw_die_ref get_context_die (tree);
6321 static void gen_namespace_die (tree, dw_die_ref);
6322 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
6323 static dw_die_ref force_decl_die (tree);
6324 static dw_die_ref force_type_die (tree);
6325 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
6326 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
6327 static struct dwarf_file_data * lookup_filename (const char *);
6328 static void retry_incomplete_types (void);
6329 static void gen_type_die_for_member (tree, tree, dw_die_ref);
6330 static void gen_generic_params_dies (tree);
6331 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
6332 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
6333 static void splice_child_die (dw_die_ref, dw_die_ref);
6334 static int file_info_cmp (const void *, const void *);
6335 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
6336 const char *, const char *);
6337 static void output_loc_list (dw_loc_list_ref);
6338 static char *gen_internal_sym (const char *);
6340 static void prune_unmark_dies (dw_die_ref);
6341 static void prune_unused_types_mark (dw_die_ref, int);
6342 static void prune_unused_types_walk (dw_die_ref);
6343 static void prune_unused_types_walk_attribs (dw_die_ref);
6344 static void prune_unused_types_prune (dw_die_ref);
6345 static void prune_unused_types (void);
6346 static int maybe_emit_file (struct dwarf_file_data *fd);
6347 static inline const char *AT_vms_delta1 (dw_attr_ref);
6348 static inline const char *AT_vms_delta2 (dw_attr_ref);
6349 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
6350 const char *, const char *);
6351 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
6352 static void gen_remaining_tmpl_value_param_die_attribute (void);
6354 /* Section names used to hold DWARF debugging information. */
6355 #ifndef DEBUG_INFO_SECTION
6356 #define DEBUG_INFO_SECTION ".debug_info"
6358 #ifndef DEBUG_ABBREV_SECTION
6359 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6361 #ifndef DEBUG_ARANGES_SECTION
6362 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6364 #ifndef DEBUG_MACINFO_SECTION
6365 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6367 #ifndef DEBUG_LINE_SECTION
6368 #define DEBUG_LINE_SECTION ".debug_line"
6370 #ifndef DEBUG_LOC_SECTION
6371 #define DEBUG_LOC_SECTION ".debug_loc"
6373 #ifndef DEBUG_PUBNAMES_SECTION
6374 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6376 #ifndef DEBUG_PUBTYPES_SECTION
6377 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6379 #ifndef DEBUG_DCALL_SECTION
6380 #define DEBUG_DCALL_SECTION ".debug_dcall"
6382 #ifndef DEBUG_VCALL_SECTION
6383 #define DEBUG_VCALL_SECTION ".debug_vcall"
6385 #ifndef DEBUG_STR_SECTION
6386 #define DEBUG_STR_SECTION ".debug_str"
6388 #ifndef DEBUG_RANGES_SECTION
6389 #define DEBUG_RANGES_SECTION ".debug_ranges"
6392 /* Standard ELF section names for compiled code and data. */
6393 #ifndef TEXT_SECTION_NAME
6394 #define TEXT_SECTION_NAME ".text"
6397 /* Section flags for .debug_str section. */
6398 #define DEBUG_STR_SECTION_FLAGS \
6399 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6400 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6403 /* Labels we insert at beginning sections we can reference instead of
6404 the section names themselves. */
6406 #ifndef TEXT_SECTION_LABEL
6407 #define TEXT_SECTION_LABEL "Ltext"
6409 #ifndef COLD_TEXT_SECTION_LABEL
6410 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6412 #ifndef DEBUG_LINE_SECTION_LABEL
6413 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6415 #ifndef DEBUG_INFO_SECTION_LABEL
6416 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6418 #ifndef DEBUG_ABBREV_SECTION_LABEL
6419 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6421 #ifndef DEBUG_LOC_SECTION_LABEL
6422 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6424 #ifndef DEBUG_RANGES_SECTION_LABEL
6425 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6427 #ifndef DEBUG_MACINFO_SECTION_LABEL
6428 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6432 /* Definitions of defaults for formats and names of various special
6433 (artificial) labels which may be generated within this file (when the -g
6434 options is used and DWARF2_DEBUGGING_INFO is in effect.
6435 If necessary, these may be overridden from within the tm.h file, but
6436 typically, overriding these defaults is unnecessary. */
6438 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6439 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6440 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6441 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6442 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6443 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6444 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6445 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6446 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6447 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
6449 #ifndef TEXT_END_LABEL
6450 #define TEXT_END_LABEL "Letext"
6452 #ifndef COLD_END_LABEL
6453 #define COLD_END_LABEL "Letext_cold"
6455 #ifndef BLOCK_BEGIN_LABEL
6456 #define BLOCK_BEGIN_LABEL "LBB"
6458 #ifndef BLOCK_END_LABEL
6459 #define BLOCK_END_LABEL "LBE"
6461 #ifndef LINE_CODE_LABEL
6462 #define LINE_CODE_LABEL "LM"
6464 #ifndef SEPARATE_LINE_CODE_LABEL
6465 #define SEPARATE_LINE_CODE_LABEL "LSM"
6469 /* We allow a language front-end to designate a function that is to be
6470 called to "demangle" any name before it is put into a DIE. */
6472 static const char *(*demangle_name_func) (const char *);
6475 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
6477 demangle_name_func = func;
6480 /* Test if rtl node points to a pseudo register. */
6483 is_pseudo_reg (const_rtx rtl)
6485 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
6486 || (GET_CODE (rtl) == SUBREG
6487 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
6490 /* Return a reference to a type, with its const and volatile qualifiers
6494 type_main_variant (tree type)
6496 type = TYPE_MAIN_VARIANT (type);
6498 /* ??? There really should be only one main variant among any group of
6499 variants of a given type (and all of the MAIN_VARIANT values for all
6500 members of the group should point to that one type) but sometimes the C
6501 front-end messes this up for array types, so we work around that bug
6503 if (TREE_CODE (type) == ARRAY_TYPE)
6504 while (type != TYPE_MAIN_VARIANT (type))
6505 type = TYPE_MAIN_VARIANT (type);
6510 /* Return nonzero if the given type node represents a tagged type. */
6513 is_tagged_type (const_tree type)
6515 enum tree_code code = TREE_CODE (type);
6517 return (code == RECORD_TYPE || code == UNION_TYPE
6518 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
6521 /* Convert a DIE tag into its string name. */
6524 dwarf_tag_name (unsigned int tag)
6528 case DW_TAG_padding:
6529 return "DW_TAG_padding";
6530 case DW_TAG_array_type:
6531 return "DW_TAG_array_type";
6532 case DW_TAG_class_type:
6533 return "DW_TAG_class_type";
6534 case DW_TAG_entry_point:
6535 return "DW_TAG_entry_point";
6536 case DW_TAG_enumeration_type:
6537 return "DW_TAG_enumeration_type";
6538 case DW_TAG_formal_parameter:
6539 return "DW_TAG_formal_parameter";
6540 case DW_TAG_imported_declaration:
6541 return "DW_TAG_imported_declaration";
6543 return "DW_TAG_label";
6544 case DW_TAG_lexical_block:
6545 return "DW_TAG_lexical_block";
6547 return "DW_TAG_member";
6548 case DW_TAG_pointer_type:
6549 return "DW_TAG_pointer_type";
6550 case DW_TAG_reference_type:
6551 return "DW_TAG_reference_type";
6552 case DW_TAG_compile_unit:
6553 return "DW_TAG_compile_unit";
6554 case DW_TAG_string_type:
6555 return "DW_TAG_string_type";
6556 case DW_TAG_structure_type:
6557 return "DW_TAG_structure_type";
6558 case DW_TAG_subroutine_type:
6559 return "DW_TAG_subroutine_type";
6560 case DW_TAG_typedef:
6561 return "DW_TAG_typedef";
6562 case DW_TAG_union_type:
6563 return "DW_TAG_union_type";
6564 case DW_TAG_unspecified_parameters:
6565 return "DW_TAG_unspecified_parameters";
6566 case DW_TAG_variant:
6567 return "DW_TAG_variant";
6568 case DW_TAG_common_block:
6569 return "DW_TAG_common_block";
6570 case DW_TAG_common_inclusion:
6571 return "DW_TAG_common_inclusion";
6572 case DW_TAG_inheritance:
6573 return "DW_TAG_inheritance";
6574 case DW_TAG_inlined_subroutine:
6575 return "DW_TAG_inlined_subroutine";
6577 return "DW_TAG_module";
6578 case DW_TAG_ptr_to_member_type:
6579 return "DW_TAG_ptr_to_member_type";
6580 case DW_TAG_set_type:
6581 return "DW_TAG_set_type";
6582 case DW_TAG_subrange_type:
6583 return "DW_TAG_subrange_type";
6584 case DW_TAG_with_stmt:
6585 return "DW_TAG_with_stmt";
6586 case DW_TAG_access_declaration:
6587 return "DW_TAG_access_declaration";
6588 case DW_TAG_base_type:
6589 return "DW_TAG_base_type";
6590 case DW_TAG_catch_block:
6591 return "DW_TAG_catch_block";
6592 case DW_TAG_const_type:
6593 return "DW_TAG_const_type";
6594 case DW_TAG_constant:
6595 return "DW_TAG_constant";
6596 case DW_TAG_enumerator:
6597 return "DW_TAG_enumerator";
6598 case DW_TAG_file_type:
6599 return "DW_TAG_file_type";
6601 return "DW_TAG_friend";
6602 case DW_TAG_namelist:
6603 return "DW_TAG_namelist";
6604 case DW_TAG_namelist_item:
6605 return "DW_TAG_namelist_item";
6606 case DW_TAG_packed_type:
6607 return "DW_TAG_packed_type";
6608 case DW_TAG_subprogram:
6609 return "DW_TAG_subprogram";
6610 case DW_TAG_template_type_param:
6611 return "DW_TAG_template_type_param";
6612 case DW_TAG_template_value_param:
6613 return "DW_TAG_template_value_param";
6614 case DW_TAG_thrown_type:
6615 return "DW_TAG_thrown_type";
6616 case DW_TAG_try_block:
6617 return "DW_TAG_try_block";
6618 case DW_TAG_variant_part:
6619 return "DW_TAG_variant_part";
6620 case DW_TAG_variable:
6621 return "DW_TAG_variable";
6622 case DW_TAG_volatile_type:
6623 return "DW_TAG_volatile_type";
6624 case DW_TAG_dwarf_procedure:
6625 return "DW_TAG_dwarf_procedure";
6626 case DW_TAG_restrict_type:
6627 return "DW_TAG_restrict_type";
6628 case DW_TAG_interface_type:
6629 return "DW_TAG_interface_type";
6630 case DW_TAG_namespace:
6631 return "DW_TAG_namespace";
6632 case DW_TAG_imported_module:
6633 return "DW_TAG_imported_module";
6634 case DW_TAG_unspecified_type:
6635 return "DW_TAG_unspecified_type";
6636 case DW_TAG_partial_unit:
6637 return "DW_TAG_partial_unit";
6638 case DW_TAG_imported_unit:
6639 return "DW_TAG_imported_unit";
6640 case DW_TAG_condition:
6641 return "DW_TAG_condition";
6642 case DW_TAG_shared_type:
6643 return "DW_TAG_shared_type";
6644 case DW_TAG_type_unit:
6645 return "DW_TAG_type_unit";
6646 case DW_TAG_rvalue_reference_type:
6647 return "DW_TAG_rvalue_reference_type";
6648 case DW_TAG_template_alias:
6649 return "DW_TAG_template_alias";
6650 case DW_TAG_GNU_template_parameter_pack:
6651 return "DW_TAG_GNU_template_parameter_pack";
6652 case DW_TAG_GNU_formal_parameter_pack:
6653 return "DW_TAG_GNU_formal_parameter_pack";
6654 case DW_TAG_MIPS_loop:
6655 return "DW_TAG_MIPS_loop";
6656 case DW_TAG_format_label:
6657 return "DW_TAG_format_label";
6658 case DW_TAG_function_template:
6659 return "DW_TAG_function_template";
6660 case DW_TAG_class_template:
6661 return "DW_TAG_class_template";
6662 case DW_TAG_GNU_BINCL:
6663 return "DW_TAG_GNU_BINCL";
6664 case DW_TAG_GNU_EINCL:
6665 return "DW_TAG_GNU_EINCL";
6666 case DW_TAG_GNU_template_template_param:
6667 return "DW_TAG_GNU_template_template_param";
6669 return "DW_TAG_<unknown>";
6673 /* Convert a DWARF attribute code into its string name. */
6676 dwarf_attr_name (unsigned int attr)
6681 return "DW_AT_sibling";
6682 case DW_AT_location:
6683 return "DW_AT_location";
6685 return "DW_AT_name";
6686 case DW_AT_ordering:
6687 return "DW_AT_ordering";
6688 case DW_AT_subscr_data:
6689 return "DW_AT_subscr_data";
6690 case DW_AT_byte_size:
6691 return "DW_AT_byte_size";
6692 case DW_AT_bit_offset:
6693 return "DW_AT_bit_offset";
6694 case DW_AT_bit_size:
6695 return "DW_AT_bit_size";
6696 case DW_AT_element_list:
6697 return "DW_AT_element_list";
6698 case DW_AT_stmt_list:
6699 return "DW_AT_stmt_list";
6701 return "DW_AT_low_pc";
6703 return "DW_AT_high_pc";
6704 case DW_AT_language:
6705 return "DW_AT_language";
6707 return "DW_AT_member";
6709 return "DW_AT_discr";
6710 case DW_AT_discr_value:
6711 return "DW_AT_discr_value";
6712 case DW_AT_visibility:
6713 return "DW_AT_visibility";
6715 return "DW_AT_import";
6716 case DW_AT_string_length:
6717 return "DW_AT_string_length";
6718 case DW_AT_common_reference:
6719 return "DW_AT_common_reference";
6720 case DW_AT_comp_dir:
6721 return "DW_AT_comp_dir";
6722 case DW_AT_const_value:
6723 return "DW_AT_const_value";
6724 case DW_AT_containing_type:
6725 return "DW_AT_containing_type";
6726 case DW_AT_default_value:
6727 return "DW_AT_default_value";
6729 return "DW_AT_inline";
6730 case DW_AT_is_optional:
6731 return "DW_AT_is_optional";
6732 case DW_AT_lower_bound:
6733 return "DW_AT_lower_bound";
6734 case DW_AT_producer:
6735 return "DW_AT_producer";
6736 case DW_AT_prototyped:
6737 return "DW_AT_prototyped";
6738 case DW_AT_return_addr:
6739 return "DW_AT_return_addr";
6740 case DW_AT_start_scope:
6741 return "DW_AT_start_scope";
6742 case DW_AT_bit_stride:
6743 return "DW_AT_bit_stride";
6744 case DW_AT_upper_bound:
6745 return "DW_AT_upper_bound";
6746 case DW_AT_abstract_origin:
6747 return "DW_AT_abstract_origin";
6748 case DW_AT_accessibility:
6749 return "DW_AT_accessibility";
6750 case DW_AT_address_class:
6751 return "DW_AT_address_class";
6752 case DW_AT_artificial:
6753 return "DW_AT_artificial";
6754 case DW_AT_base_types:
6755 return "DW_AT_base_types";
6756 case DW_AT_calling_convention:
6757 return "DW_AT_calling_convention";
6759 return "DW_AT_count";
6760 case DW_AT_data_member_location:
6761 return "DW_AT_data_member_location";
6762 case DW_AT_decl_column:
6763 return "DW_AT_decl_column";
6764 case DW_AT_decl_file:
6765 return "DW_AT_decl_file";
6766 case DW_AT_decl_line:
6767 return "DW_AT_decl_line";
6768 case DW_AT_declaration:
6769 return "DW_AT_declaration";
6770 case DW_AT_discr_list:
6771 return "DW_AT_discr_list";
6772 case DW_AT_encoding:
6773 return "DW_AT_encoding";
6774 case DW_AT_external:
6775 return "DW_AT_external";
6776 case DW_AT_explicit:
6777 return "DW_AT_explicit";
6778 case DW_AT_frame_base:
6779 return "DW_AT_frame_base";
6781 return "DW_AT_friend";
6782 case DW_AT_identifier_case:
6783 return "DW_AT_identifier_case";
6784 case DW_AT_macro_info:
6785 return "DW_AT_macro_info";
6786 case DW_AT_namelist_items:
6787 return "DW_AT_namelist_items";
6788 case DW_AT_priority:
6789 return "DW_AT_priority";
6791 return "DW_AT_segment";
6792 case DW_AT_specification:
6793 return "DW_AT_specification";
6794 case DW_AT_static_link:
6795 return "DW_AT_static_link";
6797 return "DW_AT_type";
6798 case DW_AT_use_location:
6799 return "DW_AT_use_location";
6800 case DW_AT_variable_parameter:
6801 return "DW_AT_variable_parameter";
6802 case DW_AT_virtuality:
6803 return "DW_AT_virtuality";
6804 case DW_AT_vtable_elem_location:
6805 return "DW_AT_vtable_elem_location";
6807 case DW_AT_allocated:
6808 return "DW_AT_allocated";
6809 case DW_AT_associated:
6810 return "DW_AT_associated";
6811 case DW_AT_data_location:
6812 return "DW_AT_data_location";
6813 case DW_AT_byte_stride:
6814 return "DW_AT_byte_stride";
6815 case DW_AT_entry_pc:
6816 return "DW_AT_entry_pc";
6817 case DW_AT_use_UTF8:
6818 return "DW_AT_use_UTF8";
6819 case DW_AT_extension:
6820 return "DW_AT_extension";
6822 return "DW_AT_ranges";
6823 case DW_AT_trampoline:
6824 return "DW_AT_trampoline";
6825 case DW_AT_call_column:
6826 return "DW_AT_call_column";
6827 case DW_AT_call_file:
6828 return "DW_AT_call_file";
6829 case DW_AT_call_line:
6830 return "DW_AT_call_line";
6831 case DW_AT_object_pointer:
6832 return "DW_AT_object_pointer";
6834 case DW_AT_signature:
6835 return "DW_AT_signature";
6836 case DW_AT_main_subprogram:
6837 return "DW_AT_main_subprogram";
6838 case DW_AT_data_bit_offset:
6839 return "DW_AT_data_bit_offset";
6840 case DW_AT_const_expr:
6841 return "DW_AT_const_expr";
6842 case DW_AT_enum_class:
6843 return "DW_AT_enum_class";
6844 case DW_AT_linkage_name:
6845 return "DW_AT_linkage_name";
6847 case DW_AT_MIPS_fde:
6848 return "DW_AT_MIPS_fde";
6849 case DW_AT_MIPS_loop_begin:
6850 return "DW_AT_MIPS_loop_begin";
6851 case DW_AT_MIPS_tail_loop_begin:
6852 return "DW_AT_MIPS_tail_loop_begin";
6853 case DW_AT_MIPS_epilog_begin:
6854 return "DW_AT_MIPS_epilog_begin";
6855 #if VMS_DEBUGGING_INFO
6856 case DW_AT_HP_prologue:
6857 return "DW_AT_HP_prologue";
6859 case DW_AT_MIPS_loop_unroll_factor:
6860 return "DW_AT_MIPS_loop_unroll_factor";
6862 case DW_AT_MIPS_software_pipeline_depth:
6863 return "DW_AT_MIPS_software_pipeline_depth";
6864 case DW_AT_MIPS_linkage_name:
6865 return "DW_AT_MIPS_linkage_name";
6866 #if VMS_DEBUGGING_INFO
6867 case DW_AT_HP_epilogue:
6868 return "DW_AT_HP_epilogue";
6870 case DW_AT_MIPS_stride:
6871 return "DW_AT_MIPS_stride";
6873 case DW_AT_MIPS_abstract_name:
6874 return "DW_AT_MIPS_abstract_name";
6875 case DW_AT_MIPS_clone_origin:
6876 return "DW_AT_MIPS_clone_origin";
6877 case DW_AT_MIPS_has_inlines:
6878 return "DW_AT_MIPS_has_inlines";
6880 case DW_AT_sf_names:
6881 return "DW_AT_sf_names";
6882 case DW_AT_src_info:
6883 return "DW_AT_src_info";
6884 case DW_AT_mac_info:
6885 return "DW_AT_mac_info";
6886 case DW_AT_src_coords:
6887 return "DW_AT_src_coords";
6888 case DW_AT_body_begin:
6889 return "DW_AT_body_begin";
6890 case DW_AT_body_end:
6891 return "DW_AT_body_end";
6892 case DW_AT_GNU_vector:
6893 return "DW_AT_GNU_vector";
6894 case DW_AT_GNU_guarded_by:
6895 return "DW_AT_GNU_guarded_by";
6896 case DW_AT_GNU_pt_guarded_by:
6897 return "DW_AT_GNU_pt_guarded_by";
6898 case DW_AT_GNU_guarded:
6899 return "DW_AT_GNU_guarded";
6900 case DW_AT_GNU_pt_guarded:
6901 return "DW_AT_GNU_pt_guarded";
6902 case DW_AT_GNU_locks_excluded:
6903 return "DW_AT_GNU_locks_excluded";
6904 case DW_AT_GNU_exclusive_locks_required:
6905 return "DW_AT_GNU_exclusive_locks_required";
6906 case DW_AT_GNU_shared_locks_required:
6907 return "DW_AT_GNU_shared_locks_required";
6908 case DW_AT_GNU_odr_signature:
6909 return "DW_AT_GNU_odr_signature";
6910 case DW_AT_GNU_template_name:
6911 return "DW_AT_GNU_template_name";
6913 case DW_AT_VMS_rtnbeg_pd_address:
6914 return "DW_AT_VMS_rtnbeg_pd_address";
6917 return "DW_AT_<unknown>";
6921 /* Convert a DWARF value form code into its string name. */
6924 dwarf_form_name (unsigned int form)
6929 return "DW_FORM_addr";
6930 case DW_FORM_block2:
6931 return "DW_FORM_block2";
6932 case DW_FORM_block4:
6933 return "DW_FORM_block4";
6935 return "DW_FORM_data2";
6937 return "DW_FORM_data4";
6939 return "DW_FORM_data8";
6940 case DW_FORM_string:
6941 return "DW_FORM_string";
6943 return "DW_FORM_block";
6944 case DW_FORM_block1:
6945 return "DW_FORM_block1";
6947 return "DW_FORM_data1";
6949 return "DW_FORM_flag";
6951 return "DW_FORM_sdata";
6953 return "DW_FORM_strp";
6955 return "DW_FORM_udata";
6956 case DW_FORM_ref_addr:
6957 return "DW_FORM_ref_addr";
6959 return "DW_FORM_ref1";
6961 return "DW_FORM_ref2";
6963 return "DW_FORM_ref4";
6965 return "DW_FORM_ref8";
6966 case DW_FORM_ref_udata:
6967 return "DW_FORM_ref_udata";
6968 case DW_FORM_indirect:
6969 return "DW_FORM_indirect";
6970 case DW_FORM_sec_offset:
6971 return "DW_FORM_sec_offset";
6972 case DW_FORM_exprloc:
6973 return "DW_FORM_exprloc";
6974 case DW_FORM_flag_present:
6975 return "DW_FORM_flag_present";
6976 case DW_FORM_ref_sig8:
6977 return "DW_FORM_ref_sig8";
6979 return "DW_FORM_<unknown>";
6983 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
6984 instance of an inlined instance of a decl which is local to an inline
6985 function, so we have to trace all of the way back through the origin chain
6986 to find out what sort of node actually served as the original seed for the
6990 decl_ultimate_origin (const_tree decl)
6992 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
6995 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
6996 nodes in the function to point to themselves; ignore that if
6997 we're trying to output the abstract instance of this function. */
6998 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
7001 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
7002 most distant ancestor, this should never happen. */
7003 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
7005 return DECL_ABSTRACT_ORIGIN (decl);
7008 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
7009 of a virtual function may refer to a base class, so we check the 'this'
7013 decl_class_context (tree decl)
7015 tree context = NULL_TREE;
7017 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
7018 context = DECL_CONTEXT (decl);
7020 context = TYPE_MAIN_VARIANT
7021 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
7023 if (context && !TYPE_P (context))
7024 context = NULL_TREE;
7029 /* Add an attribute/value pair to a DIE. */
7032 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
7034 /* Maybe this should be an assert? */
7038 if (die->die_attr == NULL)
7039 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
7040 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
7043 static inline enum dw_val_class
7044 AT_class (dw_attr_ref a)
7046 return a->dw_attr_val.val_class;
7049 /* Add a flag value attribute to a DIE. */
7052 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
7056 attr.dw_attr = attr_kind;
7057 attr.dw_attr_val.val_class = dw_val_class_flag;
7058 attr.dw_attr_val.v.val_flag = flag;
7059 add_dwarf_attr (die, &attr);
7062 static inline unsigned
7063 AT_flag (dw_attr_ref a)
7065 gcc_assert (a && AT_class (a) == dw_val_class_flag);
7066 return a->dw_attr_val.v.val_flag;
7069 /* Add a signed integer attribute value to a DIE. */
7072 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
7076 attr.dw_attr = attr_kind;
7077 attr.dw_attr_val.val_class = dw_val_class_const;
7078 attr.dw_attr_val.v.val_int = int_val;
7079 add_dwarf_attr (die, &attr);
7082 static inline HOST_WIDE_INT
7083 AT_int (dw_attr_ref a)
7085 gcc_assert (a && AT_class (a) == dw_val_class_const);
7086 return a->dw_attr_val.v.val_int;
7089 /* Add an unsigned integer attribute value to a DIE. */
7092 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
7093 unsigned HOST_WIDE_INT unsigned_val)
7097 attr.dw_attr = attr_kind;
7098 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
7099 attr.dw_attr_val.v.val_unsigned = unsigned_val;
7100 add_dwarf_attr (die, &attr);
7103 static inline unsigned HOST_WIDE_INT
7104 AT_unsigned (dw_attr_ref a)
7106 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
7107 return a->dw_attr_val.v.val_unsigned;
7110 /* Add an unsigned double integer attribute value to a DIE. */
7113 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
7114 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
7118 attr.dw_attr = attr_kind;
7119 attr.dw_attr_val.val_class = dw_val_class_const_double;
7120 attr.dw_attr_val.v.val_double.high = high;
7121 attr.dw_attr_val.v.val_double.low = low;
7122 add_dwarf_attr (die, &attr);
7125 /* Add a floating point attribute value to a DIE and return it. */
7128 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
7129 unsigned int length, unsigned int elt_size, unsigned char *array)
7133 attr.dw_attr = attr_kind;
7134 attr.dw_attr_val.val_class = dw_val_class_vec;
7135 attr.dw_attr_val.v.val_vec.length = length;
7136 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
7137 attr.dw_attr_val.v.val_vec.array = array;
7138 add_dwarf_attr (die, &attr);
7141 /* Add an 8-byte data attribute value to a DIE. */
7144 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
7145 unsigned char data8[8])
7149 attr.dw_attr = attr_kind;
7150 attr.dw_attr_val.val_class = dw_val_class_data8;
7151 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
7152 add_dwarf_attr (die, &attr);
7155 /* Hash and equality functions for debug_str_hash. */
7158 debug_str_do_hash (const void *x)
7160 return htab_hash_string (((const struct indirect_string_node *)x)->str);
7164 debug_str_eq (const void *x1, const void *x2)
7166 return strcmp ((((const struct indirect_string_node *)x1)->str),
7167 (const char *)x2) == 0;
7170 /* Add STR to the indirect string hash table. */
7172 static struct indirect_string_node *
7173 find_AT_string (const char *str)
7175 struct indirect_string_node *node;
7178 if (! debug_str_hash)
7179 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
7180 debug_str_eq, NULL);
7182 slot = htab_find_slot_with_hash (debug_str_hash, str,
7183 htab_hash_string (str), INSERT);
7186 node = ggc_alloc_cleared_indirect_string_node ();
7187 node->str = ggc_strdup (str);
7191 node = (struct indirect_string_node *) *slot;
7197 /* Add a string attribute value to a DIE. */
7200 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
7203 struct indirect_string_node *node;
7205 node = find_AT_string (str);
7207 attr.dw_attr = attr_kind;
7208 attr.dw_attr_val.val_class = dw_val_class_str;
7209 attr.dw_attr_val.v.val_str = node;
7210 add_dwarf_attr (die, &attr);
7213 /* Create a label for an indirect string node, ensuring it is going to
7214 be output, unless its reference count goes down to zero. */
7217 gen_label_for_indirect_string (struct indirect_string_node *node)
7224 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
7225 ++dw2_string_counter;
7226 node->label = xstrdup (label);
7229 /* Create a SYMBOL_REF rtx whose value is the initial address of a
7230 debug string STR. */
7233 get_debug_string_label (const char *str)
7235 struct indirect_string_node *node = find_AT_string (str);
7237 debug_str_hash_forced = true;
7239 gen_label_for_indirect_string (node);
7241 return gen_rtx_SYMBOL_REF (Pmode, node->label);
7244 static inline const char *
7245 AT_string (dw_attr_ref a)
7247 gcc_assert (a && AT_class (a) == dw_val_class_str);
7248 return a->dw_attr_val.v.val_str->str;
7251 /* Find out whether a string should be output inline in DIE
7252 or out-of-line in .debug_str section. */
7254 static enum dwarf_form
7255 AT_string_form (dw_attr_ref a)
7257 struct indirect_string_node *node;
7260 gcc_assert (a && AT_class (a) == dw_val_class_str);
7262 node = a->dw_attr_val.v.val_str;
7266 len = strlen (node->str) + 1;
7268 /* If the string is shorter or equal to the size of the reference, it is
7269 always better to put it inline. */
7270 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
7271 return node->form = DW_FORM_string;
7273 /* If we cannot expect the linker to merge strings in .debug_str
7274 section, only put it into .debug_str if it is worth even in this
7276 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
7277 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
7278 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
7279 return node->form = DW_FORM_string;
7281 gen_label_for_indirect_string (node);
7283 return node->form = DW_FORM_strp;
7286 /* Add a DIE reference attribute value to a DIE. */
7289 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
7293 attr.dw_attr = attr_kind;
7294 attr.dw_attr_val.val_class = dw_val_class_die_ref;
7295 attr.dw_attr_val.v.val_die_ref.die = targ_die;
7296 attr.dw_attr_val.v.val_die_ref.external = 0;
7297 add_dwarf_attr (die, &attr);
7300 /* Add an AT_specification attribute to a DIE, and also make the back
7301 pointer from the specification to the definition. */
7304 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
7306 add_AT_die_ref (die, DW_AT_specification, targ_die);
7307 gcc_assert (!targ_die->die_definition);
7308 targ_die->die_definition = die;
7311 static inline dw_die_ref
7312 AT_ref (dw_attr_ref a)
7314 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7315 return a->dw_attr_val.v.val_die_ref.die;
7319 AT_ref_external (dw_attr_ref a)
7321 if (a && AT_class (a) == dw_val_class_die_ref)
7322 return a->dw_attr_val.v.val_die_ref.external;
7328 set_AT_ref_external (dw_attr_ref a, int i)
7330 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7331 a->dw_attr_val.v.val_die_ref.external = i;
7334 /* Add an FDE reference attribute value to a DIE. */
7337 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
7341 attr.dw_attr = attr_kind;
7342 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
7343 attr.dw_attr_val.v.val_fde_index = targ_fde;
7344 add_dwarf_attr (die, &attr);
7347 /* Add a location description attribute value to a DIE. */
7350 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
7354 attr.dw_attr = attr_kind;
7355 attr.dw_attr_val.val_class = dw_val_class_loc;
7356 attr.dw_attr_val.v.val_loc = loc;
7357 add_dwarf_attr (die, &attr);
7360 static inline dw_loc_descr_ref
7361 AT_loc (dw_attr_ref a)
7363 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7364 return a->dw_attr_val.v.val_loc;
7368 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
7372 attr.dw_attr = attr_kind;
7373 attr.dw_attr_val.val_class = dw_val_class_loc_list;
7374 attr.dw_attr_val.v.val_loc_list = loc_list;
7375 add_dwarf_attr (die, &attr);
7376 have_location_lists = true;
7379 static inline dw_loc_list_ref
7380 AT_loc_list (dw_attr_ref a)
7382 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7383 return a->dw_attr_val.v.val_loc_list;
7386 static inline dw_loc_list_ref *
7387 AT_loc_list_ptr (dw_attr_ref a)
7389 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7390 return &a->dw_attr_val.v.val_loc_list;
7393 /* Add an address constant attribute value to a DIE. */
7396 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
7400 attr.dw_attr = attr_kind;
7401 attr.dw_attr_val.val_class = dw_val_class_addr;
7402 attr.dw_attr_val.v.val_addr = addr;
7403 add_dwarf_attr (die, &attr);
7406 /* Get the RTX from to an address DIE attribute. */
7409 AT_addr (dw_attr_ref a)
7411 gcc_assert (a && AT_class (a) == dw_val_class_addr);
7412 return a->dw_attr_val.v.val_addr;
7415 /* Add a file attribute value to a DIE. */
7418 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
7419 struct dwarf_file_data *fd)
7423 attr.dw_attr = attr_kind;
7424 attr.dw_attr_val.val_class = dw_val_class_file;
7425 attr.dw_attr_val.v.val_file = fd;
7426 add_dwarf_attr (die, &attr);
7429 /* Get the dwarf_file_data from a file DIE attribute. */
7431 static inline struct dwarf_file_data *
7432 AT_file (dw_attr_ref a)
7434 gcc_assert (a && AT_class (a) == dw_val_class_file);
7435 return a->dw_attr_val.v.val_file;
7438 /* Add a vms delta attribute value to a DIE. */
7441 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
7442 const char *lbl1, const char *lbl2)
7446 attr.dw_attr = attr_kind;
7447 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
7448 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
7449 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
7450 add_dwarf_attr (die, &attr);
7453 /* Add a label identifier attribute value to a DIE. */
7456 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
7460 attr.dw_attr = attr_kind;
7461 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
7462 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
7463 add_dwarf_attr (die, &attr);
7466 /* Add a section offset attribute value to a DIE, an offset into the
7467 debug_line section. */
7470 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7475 attr.dw_attr = attr_kind;
7476 attr.dw_attr_val.val_class = dw_val_class_lineptr;
7477 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7478 add_dwarf_attr (die, &attr);
7481 /* Add a section offset attribute value to a DIE, an offset into the
7482 debug_macinfo section. */
7485 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7490 attr.dw_attr = attr_kind;
7491 attr.dw_attr_val.val_class = dw_val_class_macptr;
7492 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7493 add_dwarf_attr (die, &attr);
7496 /* Add an offset attribute value to a DIE. */
7499 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
7500 unsigned HOST_WIDE_INT offset)
7504 attr.dw_attr = attr_kind;
7505 attr.dw_attr_val.val_class = dw_val_class_offset;
7506 attr.dw_attr_val.v.val_offset = offset;
7507 add_dwarf_attr (die, &attr);
7510 /* Add an range_list attribute value to a DIE. */
7513 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
7514 long unsigned int offset)
7518 attr.dw_attr = attr_kind;
7519 attr.dw_attr_val.val_class = dw_val_class_range_list;
7520 attr.dw_attr_val.v.val_offset = offset;
7521 add_dwarf_attr (die, &attr);
7524 /* Return the start label of a delta attribute. */
7526 static inline const char *
7527 AT_vms_delta1 (dw_attr_ref a)
7529 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7530 return a->dw_attr_val.v.val_vms_delta.lbl1;
7533 /* Return the end label of a delta attribute. */
7535 static inline const char *
7536 AT_vms_delta2 (dw_attr_ref a)
7538 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7539 return a->dw_attr_val.v.val_vms_delta.lbl2;
7542 static inline const char *
7543 AT_lbl (dw_attr_ref a)
7545 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
7546 || AT_class (a) == dw_val_class_lineptr
7547 || AT_class (a) == dw_val_class_macptr));
7548 return a->dw_attr_val.v.val_lbl_id;
7551 /* Get the attribute of type attr_kind. */
7554 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7558 dw_die_ref spec = NULL;
7563 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7564 if (a->dw_attr == attr_kind)
7566 else if (a->dw_attr == DW_AT_specification
7567 || a->dw_attr == DW_AT_abstract_origin)
7571 return get_AT (spec, attr_kind);
7576 /* Return the "low pc" attribute value, typically associated with a subprogram
7577 DIE. Return null if the "low pc" attribute is either not present, or if it
7578 cannot be represented as an assembler label identifier. */
7580 static inline const char *
7581 get_AT_low_pc (dw_die_ref die)
7583 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
7585 return a ? AT_lbl (a) : NULL;
7588 /* Return the "high pc" attribute value, typically associated with a subprogram
7589 DIE. Return null if the "high pc" attribute is either not present, or if it
7590 cannot be represented as an assembler label identifier. */
7592 static inline const char *
7593 get_AT_hi_pc (dw_die_ref die)
7595 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
7597 return a ? AT_lbl (a) : NULL;
7600 /* Return the value of the string attribute designated by ATTR_KIND, or
7601 NULL if it is not present. */
7603 static inline const char *
7604 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
7606 dw_attr_ref a = get_AT (die, attr_kind);
7608 return a ? AT_string (a) : NULL;
7611 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
7612 if it is not present. */
7615 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
7617 dw_attr_ref a = get_AT (die, attr_kind);
7619 return a ? AT_flag (a) : 0;
7622 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
7623 if it is not present. */
7625 static inline unsigned
7626 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
7628 dw_attr_ref a = get_AT (die, attr_kind);
7630 return a ? AT_unsigned (a) : 0;
7633 static inline dw_die_ref
7634 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
7636 dw_attr_ref a = get_AT (die, attr_kind);
7638 return a ? AT_ref (a) : NULL;
7641 static inline struct dwarf_file_data *
7642 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
7644 dw_attr_ref a = get_AT (die, attr_kind);
7646 return a ? AT_file (a) : NULL;
7649 /* Return TRUE if the language is C++. */
7654 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7656 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
7659 /* Return TRUE if the language is Fortran. */
7664 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7666 return (lang == DW_LANG_Fortran77
7667 || lang == DW_LANG_Fortran90
7668 || lang == DW_LANG_Fortran95);
7671 /* Return TRUE if the language is Ada. */
7676 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7678 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
7681 /* Remove the specified attribute if present. */
7684 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7692 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7693 if (a->dw_attr == attr_kind)
7695 if (AT_class (a) == dw_val_class_str)
7696 if (a->dw_attr_val.v.val_str->refcount)
7697 a->dw_attr_val.v.val_str->refcount--;
7699 /* VEC_ordered_remove should help reduce the number of abbrevs
7701 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
7706 /* Remove CHILD from its parent. PREV must have the property that
7707 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
7710 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
7712 gcc_assert (child->die_parent == prev->die_parent);
7713 gcc_assert (prev->die_sib == child);
7716 gcc_assert (child->die_parent->die_child == child);
7720 prev->die_sib = child->die_sib;
7721 if (child->die_parent->die_child == child)
7722 child->die_parent->die_child = prev;
7725 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
7726 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
7729 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
7731 dw_die_ref parent = old_child->die_parent;
7733 gcc_assert (parent == prev->die_parent);
7734 gcc_assert (prev->die_sib == old_child);
7736 new_child->die_parent = parent;
7737 if (prev == old_child)
7739 gcc_assert (parent->die_child == old_child);
7740 new_child->die_sib = new_child;
7744 prev->die_sib = new_child;
7745 new_child->die_sib = old_child->die_sib;
7747 if (old_child->die_parent->die_child == old_child)
7748 old_child->die_parent->die_child = new_child;
7751 /* Move all children from OLD_PARENT to NEW_PARENT. */
7754 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
7757 new_parent->die_child = old_parent->die_child;
7758 old_parent->die_child = NULL;
7759 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
7762 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
7766 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
7772 dw_die_ref prev = c;
7774 while (c->die_tag == tag)
7776 remove_child_with_prev (c, prev);
7777 /* Might have removed every child. */
7778 if (c == c->die_sib)
7782 } while (c != die->die_child);
7785 /* Add a CHILD_DIE as the last child of DIE. */
7788 add_child_die (dw_die_ref die, dw_die_ref child_die)
7790 /* FIXME this should probably be an assert. */
7791 if (! die || ! child_die)
7793 gcc_assert (die != child_die);
7795 child_die->die_parent = die;
7798 child_die->die_sib = die->die_child->die_sib;
7799 die->die_child->die_sib = child_die;
7802 child_die->die_sib = child_die;
7803 die->die_child = child_die;
7806 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
7807 is the specification, to the end of PARENT's list of children.
7808 This is done by removing and re-adding it. */
7811 splice_child_die (dw_die_ref parent, dw_die_ref child)
7815 /* We want the declaration DIE from inside the class, not the
7816 specification DIE at toplevel. */
7817 if (child->die_parent != parent)
7819 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
7825 gcc_assert (child->die_parent == parent
7826 || (child->die_parent
7827 == get_AT_ref (parent, DW_AT_specification)));
7829 for (p = child->die_parent->die_child; ; p = p->die_sib)
7830 if (p->die_sib == child)
7832 remove_child_with_prev (child, p);
7836 add_child_die (parent, child);
7839 /* Return a pointer to a newly created DIE node. */
7841 static inline dw_die_ref
7842 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
7844 dw_die_ref die = ggc_alloc_cleared_die_node ();
7846 die->die_tag = tag_value;
7848 if (parent_die != NULL)
7849 add_child_die (parent_die, die);
7852 limbo_die_node *limbo_node;
7854 limbo_node = ggc_alloc_cleared_limbo_die_node ();
7855 limbo_node->die = die;
7856 limbo_node->created_for = t;
7857 limbo_node->next = limbo_die_list;
7858 limbo_die_list = limbo_node;
7864 /* Return the DIE associated with the given type specifier. */
7866 static inline dw_die_ref
7867 lookup_type_die (tree type)
7869 return TYPE_SYMTAB_DIE (type);
7872 /* Equate a DIE to a given type specifier. */
7875 equate_type_number_to_die (tree type, dw_die_ref type_die)
7877 TYPE_SYMTAB_DIE (type) = type_die;
7880 /* Returns a hash value for X (which really is a die_struct). */
7883 decl_die_table_hash (const void *x)
7885 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
7888 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
7891 decl_die_table_eq (const void *x, const void *y)
7893 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
7896 /* Return the DIE associated with a given declaration. */
7898 static inline dw_die_ref
7899 lookup_decl_die (tree decl)
7901 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
7904 /* Returns a hash value for X (which really is a var_loc_list). */
7907 decl_loc_table_hash (const void *x)
7909 return (hashval_t) ((const var_loc_list *) x)->decl_id;
7912 /* Return nonzero if decl_id of var_loc_list X is the same as
7916 decl_loc_table_eq (const void *x, const void *y)
7918 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
7921 /* Return the var_loc list associated with a given declaration. */
7923 static inline var_loc_list *
7924 lookup_decl_loc (const_tree decl)
7926 if (!decl_loc_table)
7928 return (var_loc_list *)
7929 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
7932 /* Equate a DIE to a particular declaration. */
7935 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
7937 unsigned int decl_id = DECL_UID (decl);
7940 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
7942 decl_die->decl_id = decl_id;
7945 /* Return how many bits covers PIECE EXPR_LIST. */
7948 decl_piece_bitsize (rtx piece)
7950 int ret = (int) GET_MODE (piece);
7953 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
7954 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
7955 return INTVAL (XEXP (XEXP (piece, 0), 0));
7958 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
7961 decl_piece_varloc_ptr (rtx piece)
7963 if ((int) GET_MODE (piece))
7964 return &XEXP (piece, 0);
7966 return &XEXP (XEXP (piece, 0), 1);
7969 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
7970 Next is the chain of following piece nodes. */
7973 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
7975 if (bitsize <= (int) MAX_MACHINE_MODE)
7976 return alloc_EXPR_LIST (bitsize, loc_note, next);
7978 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
7983 /* Return rtx that should be stored into loc field for
7984 LOC_NOTE and BITPOS/BITSIZE. */
7987 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
7988 HOST_WIDE_INT bitsize)
7992 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
7994 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
7999 /* This function either modifies location piece list *DEST in
8000 place (if SRC and INNER is NULL), or copies location piece list
8001 *SRC to *DEST while modifying it. Location BITPOS is modified
8002 to contain LOC_NOTE, any pieces overlapping it are removed resp.
8003 not copied and if needed some padding around it is added.
8004 When modifying in place, DEST should point to EXPR_LIST where
8005 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
8006 to the start of the whole list and INNER points to the EXPR_LIST
8007 where earlier pieces cover PIECE_BITPOS bits. */
8010 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
8011 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
8012 HOST_WIDE_INT bitsize, rtx loc_note)
8015 bool copy = inner != NULL;
8019 /* First copy all nodes preceeding the current bitpos. */
8020 while (src != inner)
8022 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8023 decl_piece_bitsize (*src), NULL_RTX);
8024 dest = &XEXP (*dest, 1);
8025 src = &XEXP (*src, 1);
8028 /* Add padding if needed. */
8029 if (bitpos != piece_bitpos)
8031 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
8032 copy ? NULL_RTX : *dest);
8033 dest = &XEXP (*dest, 1);
8035 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
8038 /* A piece with correct bitpos and bitsize already exist,
8039 just update the location for it and return. */
8040 *decl_piece_varloc_ptr (*dest) = loc_note;
8043 /* Add the piece that changed. */
8044 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
8045 dest = &XEXP (*dest, 1);
8046 /* Skip over pieces that overlap it. */
8047 diff = bitpos - piece_bitpos + bitsize;
8050 while (diff > 0 && *src)
8053 diff -= decl_piece_bitsize (piece);
8055 src = &XEXP (piece, 1);
8058 *src = XEXP (piece, 1);
8059 free_EXPR_LIST_node (piece);
8062 /* Add padding if needed. */
8063 if (diff < 0 && *src)
8067 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
8068 dest = &XEXP (*dest, 1);
8072 /* Finally copy all nodes following it. */
8075 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8076 decl_piece_bitsize (*src), NULL_RTX);
8077 dest = &XEXP (*dest, 1);
8078 src = &XEXP (*src, 1);
8082 /* Add a variable location node to the linked list for DECL. */
8084 static struct var_loc_node *
8085 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
8087 unsigned int decl_id;
8090 struct var_loc_node *loc = NULL;
8091 HOST_WIDE_INT bitsize = -1, bitpos = -1;
8093 if (DECL_DEBUG_EXPR_IS_FROM (decl))
8095 tree realdecl = DECL_DEBUG_EXPR (decl);
8096 if (realdecl && handled_component_p (realdecl))
8098 HOST_WIDE_INT maxsize;
8101 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
8102 if (!DECL_P (innerdecl)
8103 || DECL_IGNORED_P (innerdecl)
8104 || TREE_STATIC (innerdecl)
8106 || bitpos + bitsize > 256
8107 || bitsize != maxsize)
8113 decl_id = DECL_UID (decl);
8114 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
8117 temp = ggc_alloc_cleared_var_loc_list ();
8118 temp->decl_id = decl_id;
8122 temp = (var_loc_list *) *slot;
8126 struct var_loc_node *last = temp->last, *unused = NULL;
8127 rtx *piece_loc = NULL, last_loc_note;
8128 int piece_bitpos = 0;
8132 gcc_assert (last->next == NULL);
8134 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
8136 piece_loc = &last->loc;
8139 int cur_bitsize = decl_piece_bitsize (*piece_loc);
8140 if (piece_bitpos + cur_bitsize > bitpos)
8142 piece_bitpos += cur_bitsize;
8143 piece_loc = &XEXP (*piece_loc, 1);
8147 /* TEMP->LAST here is either pointer to the last but one or
8148 last element in the chained list, LAST is pointer to the
8150 if (label && strcmp (last->label, label) == 0)
8152 /* For SRA optimized variables if there weren't any real
8153 insns since last note, just modify the last node. */
8154 if (piece_loc != NULL)
8156 adjust_piece_list (piece_loc, NULL, NULL,
8157 bitpos, piece_bitpos, bitsize, loc_note);
8160 /* If the last note doesn't cover any instructions, remove it. */
8161 if (temp->last != last)
8163 temp->last->next = NULL;
8166 gcc_assert (strcmp (last->label, label) != 0);
8170 gcc_assert (temp->first == temp->last);
8171 memset (temp->last, '\0', sizeof (*temp->last));
8172 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
8176 if (bitsize == -1 && NOTE_P (last->loc))
8177 last_loc_note = last->loc;
8178 else if (piece_loc != NULL
8179 && *piece_loc != NULL_RTX
8180 && piece_bitpos == bitpos
8181 && decl_piece_bitsize (*piece_loc) == bitsize)
8182 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
8184 last_loc_note = NULL_RTX;
8185 /* If the current location is the same as the end of the list,
8186 and either both or neither of the locations is uninitialized,
8187 we have nothing to do. */
8188 if (last_loc_note == NULL_RTX
8189 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
8190 NOTE_VAR_LOCATION_LOC (loc_note)))
8191 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8192 != NOTE_VAR_LOCATION_STATUS (loc_note))
8193 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8194 == VAR_INIT_STATUS_UNINITIALIZED)
8195 || (NOTE_VAR_LOCATION_STATUS (loc_note)
8196 == VAR_INIT_STATUS_UNINITIALIZED))))
8198 /* Add LOC to the end of list and update LAST. If the last
8199 element of the list has been removed above, reuse its
8200 memory for the new node, otherwise allocate a new one. */
8204 memset (loc, '\0', sizeof (*loc));
8207 loc = ggc_alloc_cleared_var_loc_node ();
8208 if (bitsize == -1 || piece_loc == NULL)
8209 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8211 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
8212 bitpos, piece_bitpos, bitsize, loc_note);
8214 /* Ensure TEMP->LAST will point either to the new last but one
8215 element of the chain, or to the last element in it. */
8216 if (last != temp->last)
8224 loc = ggc_alloc_cleared_var_loc_node ();
8227 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8232 /* Keep track of the number of spaces used to indent the
8233 output of the debugging routines that print the structure of
8234 the DIE internal representation. */
8235 static int print_indent;
8237 /* Indent the line the number of spaces given by print_indent. */
8240 print_spaces (FILE *outfile)
8242 fprintf (outfile, "%*s", print_indent, "");
8245 /* Print a type signature in hex. */
8248 print_signature (FILE *outfile, char *sig)
8252 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8253 fprintf (outfile, "%02x", sig[i] & 0xff);
8256 /* Print the information associated with a given DIE, and its children.
8257 This routine is a debugging aid only. */
8260 print_die (dw_die_ref die, FILE *outfile)
8266 print_spaces (outfile);
8267 fprintf (outfile, "DIE %4ld: %s\n",
8268 die->die_offset, dwarf_tag_name (die->die_tag));
8269 print_spaces (outfile);
8270 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
8271 fprintf (outfile, " offset: %ld\n", die->die_offset);
8272 if (dwarf_version >= 4 && die->die_id.die_type_node)
8274 print_spaces (outfile);
8275 fprintf (outfile, " signature: ");
8276 print_signature (outfile, die->die_id.die_type_node->signature);
8277 fprintf (outfile, "\n");
8280 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8282 print_spaces (outfile);
8283 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
8285 switch (AT_class (a))
8287 case dw_val_class_addr:
8288 fprintf (outfile, "address");
8290 case dw_val_class_offset:
8291 fprintf (outfile, "offset");
8293 case dw_val_class_loc:
8294 fprintf (outfile, "location descriptor");
8296 case dw_val_class_loc_list:
8297 fprintf (outfile, "location list -> label:%s",
8298 AT_loc_list (a)->ll_symbol);
8300 case dw_val_class_range_list:
8301 fprintf (outfile, "range list");
8303 case dw_val_class_const:
8304 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
8306 case dw_val_class_unsigned_const:
8307 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
8309 case dw_val_class_const_double:
8310 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
8311 HOST_WIDE_INT_PRINT_UNSIGNED")",
8312 a->dw_attr_val.v.val_double.high,
8313 a->dw_attr_val.v.val_double.low);
8315 case dw_val_class_vec:
8316 fprintf (outfile, "floating-point or vector constant");
8318 case dw_val_class_flag:
8319 fprintf (outfile, "%u", AT_flag (a));
8321 case dw_val_class_die_ref:
8322 if (AT_ref (a) != NULL)
8324 if (dwarf_version >= 4 && AT_ref (a)->die_id.die_type_node)
8326 fprintf (outfile, "die -> signature: ");
8327 print_signature (outfile,
8328 AT_ref (a)->die_id.die_type_node->signature);
8330 else if (dwarf_version < 4 && AT_ref (a)->die_id.die_symbol)
8331 fprintf (outfile, "die -> label: %s",
8332 AT_ref (a)->die_id.die_symbol);
8334 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
8337 fprintf (outfile, "die -> <null>");
8339 case dw_val_class_vms_delta:
8340 fprintf (outfile, "delta: @slotcount(%s-%s)",
8341 AT_vms_delta2 (a), AT_vms_delta1 (a));
8343 case dw_val_class_lbl_id:
8344 case dw_val_class_lineptr:
8345 case dw_val_class_macptr:
8346 fprintf (outfile, "label: %s", AT_lbl (a));
8348 case dw_val_class_str:
8349 if (AT_string (a) != NULL)
8350 fprintf (outfile, "\"%s\"", AT_string (a));
8352 fprintf (outfile, "<null>");
8354 case dw_val_class_file:
8355 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
8356 AT_file (a)->emitted_number);
8358 case dw_val_class_data8:
8362 for (i = 0; i < 8; i++)
8363 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
8370 fprintf (outfile, "\n");
8373 if (die->die_child != NULL)
8376 FOR_EACH_CHILD (die, c, print_die (c, outfile));
8379 if (print_indent == 0)
8380 fprintf (outfile, "\n");
8383 /* Print the contents of the source code line number correspondence table.
8384 This routine is a debugging aid only. */
8387 print_dwarf_line_table (FILE *outfile)
8390 dw_line_info_ref line_info;
8392 fprintf (outfile, "\n\nDWARF source line information\n");
8393 for (i = 1; i < line_info_table_in_use; i++)
8395 line_info = &line_info_table[i];
8396 fprintf (outfile, "%5d: %4ld %6ld\n", i,
8397 line_info->dw_file_num,
8398 line_info->dw_line_num);
8401 fprintf (outfile, "\n\n");
8404 /* Print the information collected for a given DIE. */
8407 debug_dwarf_die (dw_die_ref die)
8409 print_die (die, stderr);
8412 /* Print all DWARF information collected for the compilation unit.
8413 This routine is a debugging aid only. */
8419 print_die (comp_unit_die, stderr);
8420 if (! DWARF2_ASM_LINE_DEBUG_INFO)
8421 print_dwarf_line_table (stderr);
8424 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
8425 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
8426 DIE that marks the start of the DIEs for this include file. */
8429 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
8431 const char *filename = get_AT_string (bincl_die, DW_AT_name);
8432 dw_die_ref new_unit = gen_compile_unit_die (filename);
8434 new_unit->die_sib = old_unit;
8438 /* Close an include-file CU and reopen the enclosing one. */
8441 pop_compile_unit (dw_die_ref old_unit)
8443 dw_die_ref new_unit = old_unit->die_sib;
8445 old_unit->die_sib = NULL;
8449 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8450 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
8452 /* Calculate the checksum of a location expression. */
8455 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8459 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
8461 CHECKSUM (loc->dw_loc_oprnd1);
8462 CHECKSUM (loc->dw_loc_oprnd2);
8465 /* Calculate the checksum of an attribute. */
8468 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
8470 dw_loc_descr_ref loc;
8473 CHECKSUM (at->dw_attr);
8475 /* We don't care that this was compiled with a different compiler
8476 snapshot; if the output is the same, that's what matters. */
8477 if (at->dw_attr == DW_AT_producer)
8480 switch (AT_class (at))
8482 case dw_val_class_const:
8483 CHECKSUM (at->dw_attr_val.v.val_int);
8485 case dw_val_class_unsigned_const:
8486 CHECKSUM (at->dw_attr_val.v.val_unsigned);
8488 case dw_val_class_const_double:
8489 CHECKSUM (at->dw_attr_val.v.val_double);
8491 case dw_val_class_vec:
8492 CHECKSUM (at->dw_attr_val.v.val_vec);
8494 case dw_val_class_flag:
8495 CHECKSUM (at->dw_attr_val.v.val_flag);
8497 case dw_val_class_str:
8498 CHECKSUM_STRING (AT_string (at));
8501 case dw_val_class_addr:
8503 gcc_assert (GET_CODE (r) == SYMBOL_REF);
8504 CHECKSUM_STRING (XSTR (r, 0));
8507 case dw_val_class_offset:
8508 CHECKSUM (at->dw_attr_val.v.val_offset);
8511 case dw_val_class_loc:
8512 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
8513 loc_checksum (loc, ctx);
8516 case dw_val_class_die_ref:
8517 die_checksum (AT_ref (at), ctx, mark);
8520 case dw_val_class_fde_ref:
8521 case dw_val_class_vms_delta:
8522 case dw_val_class_lbl_id:
8523 case dw_val_class_lineptr:
8524 case dw_val_class_macptr:
8527 case dw_val_class_file:
8528 CHECKSUM_STRING (AT_file (at)->filename);
8531 case dw_val_class_data8:
8532 CHECKSUM (at->dw_attr_val.v.val_data8);
8540 /* Calculate the checksum of a DIE. */
8543 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
8549 /* To avoid infinite recursion. */
8552 CHECKSUM (die->die_mark);
8555 die->die_mark = ++(*mark);
8557 CHECKSUM (die->die_tag);
8559 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8560 attr_checksum (a, ctx, mark);
8562 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
8566 #undef CHECKSUM_STRING
8568 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
8569 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8570 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
8571 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
8572 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
8573 #define CHECKSUM_ATTR(FOO) \
8574 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
8576 /* Calculate the checksum of a number in signed LEB128 format. */
8579 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
8586 byte = (value & 0x7f);
8588 more = !((value == 0 && (byte & 0x40) == 0)
8589 || (value == -1 && (byte & 0x40) != 0));
8598 /* Calculate the checksum of a number in unsigned LEB128 format. */
8601 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
8605 unsigned char byte = (value & 0x7f);
8608 /* More bytes to follow. */
8616 /* Checksum the context of the DIE. This adds the names of any
8617 surrounding namespaces or structures to the checksum. */
8620 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
8624 int tag = die->die_tag;
8626 if (tag != DW_TAG_namespace
8627 && tag != DW_TAG_structure_type
8628 && tag != DW_TAG_class_type)
8631 name = get_AT_string (die, DW_AT_name);
8633 spec = get_AT_ref (die, DW_AT_specification);
8637 if (die->die_parent != NULL)
8638 checksum_die_context (die->die_parent, ctx);
8640 CHECKSUM_ULEB128 ('C');
8641 CHECKSUM_ULEB128 (tag);
8643 CHECKSUM_STRING (name);
8646 /* Calculate the checksum of a location expression. */
8649 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8651 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
8652 were emitted as a DW_FORM_sdata instead of a location expression. */
8653 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
8655 CHECKSUM_ULEB128 (DW_FORM_sdata);
8656 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
8660 /* Otherwise, just checksum the raw location expression. */
8663 CHECKSUM_ULEB128 (loc->dw_loc_opc);
8664 CHECKSUM (loc->dw_loc_oprnd1);
8665 CHECKSUM (loc->dw_loc_oprnd2);
8666 loc = loc->dw_loc_next;
8670 /* Calculate the checksum of an attribute. */
8673 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
8674 struct md5_ctx *ctx, int *mark)
8676 dw_loc_descr_ref loc;
8679 if (AT_class (at) == dw_val_class_die_ref)
8681 dw_die_ref target_die = AT_ref (at);
8683 /* For pointer and reference types, we checksum only the (qualified)
8684 name of the target type (if there is a name). For friend entries,
8685 we checksum only the (qualified) name of the target type or function.
8686 This allows the checksum to remain the same whether the target type
8687 is complete or not. */
8688 if ((at->dw_attr == DW_AT_type
8689 && (tag == DW_TAG_pointer_type
8690 || tag == DW_TAG_reference_type
8691 || tag == DW_TAG_rvalue_reference_type
8692 || tag == DW_TAG_ptr_to_member_type))
8693 || (at->dw_attr == DW_AT_friend
8694 && tag == DW_TAG_friend))
8696 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
8698 if (name_attr != NULL)
8700 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
8704 CHECKSUM_ULEB128 ('N');
8705 CHECKSUM_ULEB128 (at->dw_attr);
8706 if (decl->die_parent != NULL)
8707 checksum_die_context (decl->die_parent, ctx);
8708 CHECKSUM_ULEB128 ('E');
8709 CHECKSUM_STRING (AT_string (name_attr));
8714 /* For all other references to another DIE, we check to see if the
8715 target DIE has already been visited. If it has, we emit a
8716 backward reference; if not, we descend recursively. */
8717 if (target_die->die_mark > 0)
8719 CHECKSUM_ULEB128 ('R');
8720 CHECKSUM_ULEB128 (at->dw_attr);
8721 CHECKSUM_ULEB128 (target_die->die_mark);
8725 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
8729 target_die->die_mark = ++(*mark);
8730 CHECKSUM_ULEB128 ('T');
8731 CHECKSUM_ULEB128 (at->dw_attr);
8732 if (decl->die_parent != NULL)
8733 checksum_die_context (decl->die_parent, ctx);
8734 die_checksum_ordered (target_die, ctx, mark);
8739 CHECKSUM_ULEB128 ('A');
8740 CHECKSUM_ULEB128 (at->dw_attr);
8742 switch (AT_class (at))
8744 case dw_val_class_const:
8745 CHECKSUM_ULEB128 (DW_FORM_sdata);
8746 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
8749 case dw_val_class_unsigned_const:
8750 CHECKSUM_ULEB128 (DW_FORM_sdata);
8751 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
8754 case dw_val_class_const_double:
8755 CHECKSUM_ULEB128 (DW_FORM_block);
8756 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
8757 CHECKSUM (at->dw_attr_val.v.val_double);
8760 case dw_val_class_vec:
8761 CHECKSUM_ULEB128 (DW_FORM_block);
8762 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
8763 CHECKSUM (at->dw_attr_val.v.val_vec);
8766 case dw_val_class_flag:
8767 CHECKSUM_ULEB128 (DW_FORM_flag);
8768 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
8771 case dw_val_class_str:
8772 CHECKSUM_ULEB128 (DW_FORM_string);
8773 CHECKSUM_STRING (AT_string (at));
8776 case dw_val_class_addr:
8778 gcc_assert (GET_CODE (r) == SYMBOL_REF);
8779 CHECKSUM_ULEB128 (DW_FORM_string);
8780 CHECKSUM_STRING (XSTR (r, 0));
8783 case dw_val_class_offset:
8784 CHECKSUM_ULEB128 (DW_FORM_sdata);
8785 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
8788 case dw_val_class_loc:
8789 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
8790 loc_checksum_ordered (loc, ctx);
8793 case dw_val_class_fde_ref:
8794 case dw_val_class_lbl_id:
8795 case dw_val_class_lineptr:
8796 case dw_val_class_macptr:
8799 case dw_val_class_file:
8800 CHECKSUM_ULEB128 (DW_FORM_string);
8801 CHECKSUM_STRING (AT_file (at)->filename);
8804 case dw_val_class_data8:
8805 CHECKSUM (at->dw_attr_val.v.val_data8);
8813 struct checksum_attributes
8815 dw_attr_ref at_name;
8816 dw_attr_ref at_type;
8817 dw_attr_ref at_friend;
8818 dw_attr_ref at_accessibility;
8819 dw_attr_ref at_address_class;
8820 dw_attr_ref at_allocated;
8821 dw_attr_ref at_artificial;
8822 dw_attr_ref at_associated;
8823 dw_attr_ref at_binary_scale;
8824 dw_attr_ref at_bit_offset;
8825 dw_attr_ref at_bit_size;
8826 dw_attr_ref at_bit_stride;
8827 dw_attr_ref at_byte_size;
8828 dw_attr_ref at_byte_stride;
8829 dw_attr_ref at_const_value;
8830 dw_attr_ref at_containing_type;
8831 dw_attr_ref at_count;
8832 dw_attr_ref at_data_location;
8833 dw_attr_ref at_data_member_location;
8834 dw_attr_ref at_decimal_scale;
8835 dw_attr_ref at_decimal_sign;
8836 dw_attr_ref at_default_value;
8837 dw_attr_ref at_digit_count;
8838 dw_attr_ref at_discr;
8839 dw_attr_ref at_discr_list;
8840 dw_attr_ref at_discr_value;
8841 dw_attr_ref at_encoding;
8842 dw_attr_ref at_endianity;
8843 dw_attr_ref at_explicit;
8844 dw_attr_ref at_is_optional;
8845 dw_attr_ref at_location;
8846 dw_attr_ref at_lower_bound;
8847 dw_attr_ref at_mutable;
8848 dw_attr_ref at_ordering;
8849 dw_attr_ref at_picture_string;
8850 dw_attr_ref at_prototyped;
8851 dw_attr_ref at_small;
8852 dw_attr_ref at_segment;
8853 dw_attr_ref at_string_length;
8854 dw_attr_ref at_threads_scaled;
8855 dw_attr_ref at_upper_bound;
8856 dw_attr_ref at_use_location;
8857 dw_attr_ref at_use_UTF8;
8858 dw_attr_ref at_variable_parameter;
8859 dw_attr_ref at_virtuality;
8860 dw_attr_ref at_visibility;
8861 dw_attr_ref at_vtable_elem_location;
8864 /* Collect the attributes that we will want to use for the checksum. */
8867 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
8872 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8883 attrs->at_friend = a;
8885 case DW_AT_accessibility:
8886 attrs->at_accessibility = a;
8888 case DW_AT_address_class:
8889 attrs->at_address_class = a;
8891 case DW_AT_allocated:
8892 attrs->at_allocated = a;
8894 case DW_AT_artificial:
8895 attrs->at_artificial = a;
8897 case DW_AT_associated:
8898 attrs->at_associated = a;
8900 case DW_AT_binary_scale:
8901 attrs->at_binary_scale = a;
8903 case DW_AT_bit_offset:
8904 attrs->at_bit_offset = a;
8906 case DW_AT_bit_size:
8907 attrs->at_bit_size = a;
8909 case DW_AT_bit_stride:
8910 attrs->at_bit_stride = a;
8912 case DW_AT_byte_size:
8913 attrs->at_byte_size = a;
8915 case DW_AT_byte_stride:
8916 attrs->at_byte_stride = a;
8918 case DW_AT_const_value:
8919 attrs->at_const_value = a;
8921 case DW_AT_containing_type:
8922 attrs->at_containing_type = a;
8925 attrs->at_count = a;
8927 case DW_AT_data_location:
8928 attrs->at_data_location = a;
8930 case DW_AT_data_member_location:
8931 attrs->at_data_member_location = a;
8933 case DW_AT_decimal_scale:
8934 attrs->at_decimal_scale = a;
8936 case DW_AT_decimal_sign:
8937 attrs->at_decimal_sign = a;
8939 case DW_AT_default_value:
8940 attrs->at_default_value = a;
8942 case DW_AT_digit_count:
8943 attrs->at_digit_count = a;
8946 attrs->at_discr = a;
8948 case DW_AT_discr_list:
8949 attrs->at_discr_list = a;
8951 case DW_AT_discr_value:
8952 attrs->at_discr_value = a;
8954 case DW_AT_encoding:
8955 attrs->at_encoding = a;
8957 case DW_AT_endianity:
8958 attrs->at_endianity = a;
8960 case DW_AT_explicit:
8961 attrs->at_explicit = a;
8963 case DW_AT_is_optional:
8964 attrs->at_is_optional = a;
8966 case DW_AT_location:
8967 attrs->at_location = a;
8969 case DW_AT_lower_bound:
8970 attrs->at_lower_bound = a;
8973 attrs->at_mutable = a;
8975 case DW_AT_ordering:
8976 attrs->at_ordering = a;
8978 case DW_AT_picture_string:
8979 attrs->at_picture_string = a;
8981 case DW_AT_prototyped:
8982 attrs->at_prototyped = a;
8985 attrs->at_small = a;
8988 attrs->at_segment = a;
8990 case DW_AT_string_length:
8991 attrs->at_string_length = a;
8993 case DW_AT_threads_scaled:
8994 attrs->at_threads_scaled = a;
8996 case DW_AT_upper_bound:
8997 attrs->at_upper_bound = a;
8999 case DW_AT_use_location:
9000 attrs->at_use_location = a;
9002 case DW_AT_use_UTF8:
9003 attrs->at_use_UTF8 = a;
9005 case DW_AT_variable_parameter:
9006 attrs->at_variable_parameter = a;
9008 case DW_AT_virtuality:
9009 attrs->at_virtuality = a;
9011 case DW_AT_visibility:
9012 attrs->at_visibility = a;
9014 case DW_AT_vtable_elem_location:
9015 attrs->at_vtable_elem_location = a;
9023 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
9026 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
9030 struct checksum_attributes attrs;
9032 CHECKSUM_ULEB128 ('D');
9033 CHECKSUM_ULEB128 (die->die_tag);
9035 memset (&attrs, 0, sizeof (attrs));
9037 decl = get_AT_ref (die, DW_AT_specification);
9039 collect_checksum_attributes (&attrs, decl);
9040 collect_checksum_attributes (&attrs, die);
9042 CHECKSUM_ATTR (attrs.at_name);
9043 CHECKSUM_ATTR (attrs.at_accessibility);
9044 CHECKSUM_ATTR (attrs.at_address_class);
9045 CHECKSUM_ATTR (attrs.at_allocated);
9046 CHECKSUM_ATTR (attrs.at_artificial);
9047 CHECKSUM_ATTR (attrs.at_associated);
9048 CHECKSUM_ATTR (attrs.at_binary_scale);
9049 CHECKSUM_ATTR (attrs.at_bit_offset);
9050 CHECKSUM_ATTR (attrs.at_bit_size);
9051 CHECKSUM_ATTR (attrs.at_bit_stride);
9052 CHECKSUM_ATTR (attrs.at_byte_size);
9053 CHECKSUM_ATTR (attrs.at_byte_stride);
9054 CHECKSUM_ATTR (attrs.at_const_value);
9055 CHECKSUM_ATTR (attrs.at_containing_type);
9056 CHECKSUM_ATTR (attrs.at_count);
9057 CHECKSUM_ATTR (attrs.at_data_location);
9058 CHECKSUM_ATTR (attrs.at_data_member_location);
9059 CHECKSUM_ATTR (attrs.at_decimal_scale);
9060 CHECKSUM_ATTR (attrs.at_decimal_sign);
9061 CHECKSUM_ATTR (attrs.at_default_value);
9062 CHECKSUM_ATTR (attrs.at_digit_count);
9063 CHECKSUM_ATTR (attrs.at_discr);
9064 CHECKSUM_ATTR (attrs.at_discr_list);
9065 CHECKSUM_ATTR (attrs.at_discr_value);
9066 CHECKSUM_ATTR (attrs.at_encoding);
9067 CHECKSUM_ATTR (attrs.at_endianity);
9068 CHECKSUM_ATTR (attrs.at_explicit);
9069 CHECKSUM_ATTR (attrs.at_is_optional);
9070 CHECKSUM_ATTR (attrs.at_location);
9071 CHECKSUM_ATTR (attrs.at_lower_bound);
9072 CHECKSUM_ATTR (attrs.at_mutable);
9073 CHECKSUM_ATTR (attrs.at_ordering);
9074 CHECKSUM_ATTR (attrs.at_picture_string);
9075 CHECKSUM_ATTR (attrs.at_prototyped);
9076 CHECKSUM_ATTR (attrs.at_small);
9077 CHECKSUM_ATTR (attrs.at_segment);
9078 CHECKSUM_ATTR (attrs.at_string_length);
9079 CHECKSUM_ATTR (attrs.at_threads_scaled);
9080 CHECKSUM_ATTR (attrs.at_upper_bound);
9081 CHECKSUM_ATTR (attrs.at_use_location);
9082 CHECKSUM_ATTR (attrs.at_use_UTF8);
9083 CHECKSUM_ATTR (attrs.at_variable_parameter);
9084 CHECKSUM_ATTR (attrs.at_virtuality);
9085 CHECKSUM_ATTR (attrs.at_visibility);
9086 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
9087 CHECKSUM_ATTR (attrs.at_type);
9088 CHECKSUM_ATTR (attrs.at_friend);
9090 /* Checksum the child DIEs, except for nested types and member functions. */
9093 dw_attr_ref name_attr;
9096 name_attr = get_AT (c, DW_AT_name);
9097 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
9098 && name_attr != NULL)
9100 CHECKSUM_ULEB128 ('S');
9101 CHECKSUM_ULEB128 (c->die_tag);
9102 CHECKSUM_STRING (AT_string (name_attr));
9106 /* Mark this DIE so it gets processed when unmarking. */
9107 if (c->die_mark == 0)
9109 die_checksum_ordered (c, ctx, mark);
9111 } while (c != die->die_child);
9113 CHECKSUM_ULEB128 (0);
9117 #undef CHECKSUM_STRING
9118 #undef CHECKSUM_ATTR
9119 #undef CHECKSUM_LEB128
9120 #undef CHECKSUM_ULEB128
9122 /* Generate the type signature for DIE. This is computed by generating an
9123 MD5 checksum over the DIE's tag, its relevant attributes, and its
9124 children. Attributes that are references to other DIEs are processed
9125 by recursion, using the MARK field to prevent infinite recursion.
9126 If the DIE is nested inside a namespace or another type, we also
9127 need to include that context in the signature. The lower 64 bits
9128 of the resulting MD5 checksum comprise the signature. */
9131 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
9135 unsigned char checksum[16];
9139 name = get_AT_string (die, DW_AT_name);
9140 decl = get_AT_ref (die, DW_AT_specification);
9142 /* First, compute a signature for just the type name (and its surrounding
9143 context, if any. This is stored in the type unit DIE for link-time
9144 ODR (one-definition rule) checking. */
9146 if (is_cxx() && name != NULL)
9148 md5_init_ctx (&ctx);
9150 /* Checksum the names of surrounding namespaces and structures. */
9151 if (decl != NULL && decl->die_parent != NULL)
9152 checksum_die_context (decl->die_parent, &ctx);
9154 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
9155 md5_process_bytes (name, strlen (name) + 1, &ctx);
9156 md5_finish_ctx (&ctx, checksum);
9158 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
9161 /* Next, compute the complete type signature. */
9163 md5_init_ctx (&ctx);
9165 die->die_mark = mark;
9167 /* Checksum the names of surrounding namespaces and structures. */
9168 if (decl != NULL && decl->die_parent != NULL)
9169 checksum_die_context (decl->die_parent, &ctx);
9171 /* Checksum the DIE and its children. */
9172 die_checksum_ordered (die, &ctx, &mark);
9173 unmark_all_dies (die);
9174 md5_finish_ctx (&ctx, checksum);
9176 /* Store the signature in the type node and link the type DIE and the
9177 type node together. */
9178 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
9179 DWARF_TYPE_SIGNATURE_SIZE);
9180 die->die_id.die_type_node = type_node;
9181 type_node->type_die = die;
9183 /* If the DIE is a specification, link its declaration to the type node
9186 decl->die_id.die_type_node = type_node;
9189 /* Do the location expressions look same? */
9191 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
9193 return loc1->dw_loc_opc == loc2->dw_loc_opc
9194 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
9195 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
9198 /* Do the values look the same? */
9200 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
9202 dw_loc_descr_ref loc1, loc2;
9205 if (v1->val_class != v2->val_class)
9208 switch (v1->val_class)
9210 case dw_val_class_const:
9211 return v1->v.val_int == v2->v.val_int;
9212 case dw_val_class_unsigned_const:
9213 return v1->v.val_unsigned == v2->v.val_unsigned;
9214 case dw_val_class_const_double:
9215 return v1->v.val_double.high == v2->v.val_double.high
9216 && v1->v.val_double.low == v2->v.val_double.low;
9217 case dw_val_class_vec:
9218 if (v1->v.val_vec.length != v2->v.val_vec.length
9219 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
9221 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
9222 v1->v.val_vec.length * v1->v.val_vec.elt_size))
9225 case dw_val_class_flag:
9226 return v1->v.val_flag == v2->v.val_flag;
9227 case dw_val_class_str:
9228 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
9230 case dw_val_class_addr:
9231 r1 = v1->v.val_addr;
9232 r2 = v2->v.val_addr;
9233 if (GET_CODE (r1) != GET_CODE (r2))
9235 return !rtx_equal_p (r1, r2);
9237 case dw_val_class_offset:
9238 return v1->v.val_offset == v2->v.val_offset;
9240 case dw_val_class_loc:
9241 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
9243 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
9244 if (!same_loc_p (loc1, loc2, mark))
9246 return !loc1 && !loc2;
9248 case dw_val_class_die_ref:
9249 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
9251 case dw_val_class_fde_ref:
9252 case dw_val_class_vms_delta:
9253 case dw_val_class_lbl_id:
9254 case dw_val_class_lineptr:
9255 case dw_val_class_macptr:
9258 case dw_val_class_file:
9259 return v1->v.val_file == v2->v.val_file;
9261 case dw_val_class_data8:
9262 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
9269 /* Do the attributes look the same? */
9272 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
9274 if (at1->dw_attr != at2->dw_attr)
9277 /* We don't care that this was compiled with a different compiler
9278 snapshot; if the output is the same, that's what matters. */
9279 if (at1->dw_attr == DW_AT_producer)
9282 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
9285 /* Do the dies look the same? */
9288 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
9294 /* To avoid infinite recursion. */
9296 return die1->die_mark == die2->die_mark;
9297 die1->die_mark = die2->die_mark = ++(*mark);
9299 if (die1->die_tag != die2->die_tag)
9302 if (VEC_length (dw_attr_node, die1->die_attr)
9303 != VEC_length (dw_attr_node, die2->die_attr))
9306 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
9307 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
9310 c1 = die1->die_child;
9311 c2 = die2->die_child;
9320 if (!same_die_p (c1, c2, mark))
9324 if (c1 == die1->die_child)
9326 if (c2 == die2->die_child)
9336 /* Do the dies look the same? Wrapper around same_die_p. */
9339 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
9342 int ret = same_die_p (die1, die2, &mark);
9344 unmark_all_dies (die1);
9345 unmark_all_dies (die2);
9350 /* The prefix to attach to symbols on DIEs in the current comdat debug
9352 static char *comdat_symbol_id;
9354 /* The index of the current symbol within the current comdat CU. */
9355 static unsigned int comdat_symbol_number;
9357 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
9358 children, and set comdat_symbol_id accordingly. */
9361 compute_section_prefix (dw_die_ref unit_die)
9363 const char *die_name = get_AT_string (unit_die, DW_AT_name);
9364 const char *base = die_name ? lbasename (die_name) : "anonymous";
9365 char *name = XALLOCAVEC (char, strlen (base) + 64);
9368 unsigned char checksum[16];
9371 /* Compute the checksum of the DIE, then append part of it as hex digits to
9372 the name filename of the unit. */
9374 md5_init_ctx (&ctx);
9376 die_checksum (unit_die, &ctx, &mark);
9377 unmark_all_dies (unit_die);
9378 md5_finish_ctx (&ctx, checksum);
9380 sprintf (name, "%s.", base);
9381 clean_symbol_name (name);
9383 p = name + strlen (name);
9384 for (i = 0; i < 4; i++)
9386 sprintf (p, "%.2x", checksum[i]);
9390 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
9391 comdat_symbol_number = 0;
9394 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
9397 is_type_die (dw_die_ref die)
9399 switch (die->die_tag)
9401 case DW_TAG_array_type:
9402 case DW_TAG_class_type:
9403 case DW_TAG_interface_type:
9404 case DW_TAG_enumeration_type:
9405 case DW_TAG_pointer_type:
9406 case DW_TAG_reference_type:
9407 case DW_TAG_rvalue_reference_type:
9408 case DW_TAG_string_type:
9409 case DW_TAG_structure_type:
9410 case DW_TAG_subroutine_type:
9411 case DW_TAG_union_type:
9412 case DW_TAG_ptr_to_member_type:
9413 case DW_TAG_set_type:
9414 case DW_TAG_subrange_type:
9415 case DW_TAG_base_type:
9416 case DW_TAG_const_type:
9417 case DW_TAG_file_type:
9418 case DW_TAG_packed_type:
9419 case DW_TAG_volatile_type:
9420 case DW_TAG_typedef:
9427 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
9428 Basically, we want to choose the bits that are likely to be shared between
9429 compilations (types) and leave out the bits that are specific to individual
9430 compilations (functions). */
9433 is_comdat_die (dw_die_ref c)
9435 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
9436 we do for stabs. The advantage is a greater likelihood of sharing between
9437 objects that don't include headers in the same order (and therefore would
9438 put the base types in a different comdat). jason 8/28/00 */
9440 if (c->die_tag == DW_TAG_base_type)
9443 if (c->die_tag == DW_TAG_pointer_type
9444 || c->die_tag == DW_TAG_reference_type
9445 || c->die_tag == DW_TAG_rvalue_reference_type
9446 || c->die_tag == DW_TAG_const_type
9447 || c->die_tag == DW_TAG_volatile_type)
9449 dw_die_ref t = get_AT_ref (c, DW_AT_type);
9451 return t ? is_comdat_die (t) : 0;
9454 return is_type_die (c);
9457 /* Returns 1 iff C is the sort of DIE that might be referred to from another
9458 compilation unit. */
9461 is_symbol_die (dw_die_ref c)
9463 return (is_type_die (c)
9464 || is_declaration_die (c)
9465 || c->die_tag == DW_TAG_namespace
9466 || c->die_tag == DW_TAG_module);
9470 gen_internal_sym (const char *prefix)
9474 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
9475 return xstrdup (buf);
9478 /* Assign symbols to all worthy DIEs under DIE. */
9481 assign_symbol_names (dw_die_ref die)
9485 if (is_symbol_die (die))
9487 if (comdat_symbol_id)
9489 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
9491 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
9492 comdat_symbol_id, comdat_symbol_number++);
9493 die->die_id.die_symbol = xstrdup (p);
9496 die->die_id.die_symbol = gen_internal_sym ("LDIE");
9499 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
9502 struct cu_hash_table_entry
9505 unsigned min_comdat_num, max_comdat_num;
9506 struct cu_hash_table_entry *next;
9509 /* Routines to manipulate hash table of CUs. */
9511 htab_cu_hash (const void *of)
9513 const struct cu_hash_table_entry *const entry =
9514 (const struct cu_hash_table_entry *) of;
9516 return htab_hash_string (entry->cu->die_id.die_symbol);
9520 htab_cu_eq (const void *of1, const void *of2)
9522 const struct cu_hash_table_entry *const entry1 =
9523 (const struct cu_hash_table_entry *) of1;
9524 const struct die_struct *const entry2 = (const struct die_struct *) of2;
9526 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
9530 htab_cu_del (void *what)
9532 struct cu_hash_table_entry *next,
9533 *entry = (struct cu_hash_table_entry *) what;
9543 /* Check whether we have already seen this CU and set up SYM_NUM
9546 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
9548 struct cu_hash_table_entry dummy;
9549 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
9551 dummy.max_comdat_num = 0;
9553 slot = (struct cu_hash_table_entry **)
9554 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9558 for (; entry; last = entry, entry = entry->next)
9560 if (same_die_p_wrap (cu, entry->cu))
9566 *sym_num = entry->min_comdat_num;
9570 entry = XCNEW (struct cu_hash_table_entry);
9572 entry->min_comdat_num = *sym_num = last->max_comdat_num;
9573 entry->next = *slot;
9579 /* Record SYM_NUM to record of CU in HTABLE. */
9581 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
9583 struct cu_hash_table_entry **slot, *entry;
9585 slot = (struct cu_hash_table_entry **)
9586 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9590 entry->max_comdat_num = sym_num;
9593 /* Traverse the DIE (which is always comp_unit_die), and set up
9594 additional compilation units for each of the include files we see
9595 bracketed by BINCL/EINCL. */
9598 break_out_includes (dw_die_ref die)
9601 dw_die_ref unit = NULL;
9602 limbo_die_node *node, **pnode;
9603 htab_t cu_hash_table;
9607 dw_die_ref prev = c;
9609 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
9610 || (unit && is_comdat_die (c)))
9612 dw_die_ref next = c->die_sib;
9614 /* This DIE is for a secondary CU; remove it from the main one. */
9615 remove_child_with_prev (c, prev);
9617 if (c->die_tag == DW_TAG_GNU_BINCL)
9618 unit = push_new_compile_unit (unit, c);
9619 else if (c->die_tag == DW_TAG_GNU_EINCL)
9620 unit = pop_compile_unit (unit);
9622 add_child_die (unit, c);
9624 if (c == die->die_child)
9627 } while (c != die->die_child);
9630 /* We can only use this in debugging, since the frontend doesn't check
9631 to make sure that we leave every include file we enter. */
9635 assign_symbol_names (die);
9636 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
9637 for (node = limbo_die_list, pnode = &limbo_die_list;
9643 compute_section_prefix (node->die);
9644 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
9645 &comdat_symbol_number);
9646 assign_symbol_names (node->die);
9648 *pnode = node->next;
9651 pnode = &node->next;
9652 record_comdat_symbol_number (node->die, cu_hash_table,
9653 comdat_symbol_number);
9656 htab_delete (cu_hash_table);
9659 /* Return non-zero if this DIE is a declaration. */
9662 is_declaration_die (dw_die_ref die)
9667 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9668 if (a->dw_attr == DW_AT_declaration)
9674 /* Return non-zero if this DIE is nested inside a subprogram. */
9677 is_nested_in_subprogram (dw_die_ref die)
9679 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
9683 return local_scope_p (decl);
9686 /* Return non-zero if this is a type DIE that should be moved to a
9687 COMDAT .debug_types section. */
9690 should_move_die_to_comdat (dw_die_ref die)
9692 switch (die->die_tag)
9694 case DW_TAG_class_type:
9695 case DW_TAG_structure_type:
9696 case DW_TAG_enumeration_type:
9697 case DW_TAG_union_type:
9698 /* Don't move declarations, inlined instances, or types nested in a
9700 if (is_declaration_die (die)
9701 || get_AT (die, DW_AT_abstract_origin)
9702 || is_nested_in_subprogram (die))
9705 case DW_TAG_array_type:
9706 case DW_TAG_interface_type:
9707 case DW_TAG_pointer_type:
9708 case DW_TAG_reference_type:
9709 case DW_TAG_rvalue_reference_type:
9710 case DW_TAG_string_type:
9711 case DW_TAG_subroutine_type:
9712 case DW_TAG_ptr_to_member_type:
9713 case DW_TAG_set_type:
9714 case DW_TAG_subrange_type:
9715 case DW_TAG_base_type:
9716 case DW_TAG_const_type:
9717 case DW_TAG_file_type:
9718 case DW_TAG_packed_type:
9719 case DW_TAG_volatile_type:
9720 case DW_TAG_typedef:
9726 /* Make a clone of DIE. */
9729 clone_die (dw_die_ref die)
9735 clone = ggc_alloc_cleared_die_node ();
9736 clone->die_tag = die->die_tag;
9738 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9739 add_dwarf_attr (clone, a);
9744 /* Make a clone of the tree rooted at DIE. */
9747 clone_tree (dw_die_ref die)
9750 dw_die_ref clone = clone_die (die);
9752 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
9757 /* Make a clone of DIE as a declaration. */
9760 clone_as_declaration (dw_die_ref die)
9767 /* If the DIE is already a declaration, just clone it. */
9768 if (is_declaration_die (die))
9769 return clone_die (die);
9771 /* If the DIE is a specification, just clone its declaration DIE. */
9772 decl = get_AT_ref (die, DW_AT_specification);
9774 return clone_die (decl);
9776 clone = ggc_alloc_cleared_die_node ();
9777 clone->die_tag = die->die_tag;
9779 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9781 /* We don't want to copy over all attributes.
9782 For example we don't want DW_AT_byte_size because otherwise we will no
9783 longer have a declaration and GDB will treat it as a definition. */
9787 case DW_AT_artificial:
9788 case DW_AT_containing_type:
9789 case DW_AT_external:
9792 case DW_AT_virtuality:
9793 case DW_AT_linkage_name:
9794 case DW_AT_MIPS_linkage_name:
9795 add_dwarf_attr (clone, a);
9797 case DW_AT_byte_size:
9803 if (die->die_id.die_type_node)
9804 add_AT_die_ref (clone, DW_AT_signature, die);
9806 add_AT_flag (clone, DW_AT_declaration, 1);
9810 /* Copy the declaration context to the new compile unit DIE. This includes
9811 any surrounding namespace or type declarations. If the DIE has an
9812 AT_specification attribute, it also includes attributes and children
9813 attached to the specification. */
9816 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
9819 dw_die_ref new_decl;
9821 decl = get_AT_ref (die, DW_AT_specification);
9830 /* Copy the type node pointer from the new DIE to the original
9831 declaration DIE so we can forward references later. */
9832 decl->die_id.die_type_node = die->die_id.die_type_node;
9834 remove_AT (die, DW_AT_specification);
9836 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
9838 if (a->dw_attr != DW_AT_name
9839 && a->dw_attr != DW_AT_declaration
9840 && a->dw_attr != DW_AT_external)
9841 add_dwarf_attr (die, a);
9844 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
9847 if (decl->die_parent != NULL
9848 && decl->die_parent->die_tag != DW_TAG_compile_unit
9849 && decl->die_parent->die_tag != DW_TAG_type_unit)
9851 new_decl = copy_ancestor_tree (unit, decl, NULL);
9852 if (new_decl != NULL)
9854 remove_AT (new_decl, DW_AT_signature);
9855 add_AT_specification (die, new_decl);
9860 /* Generate the skeleton ancestor tree for the given NODE, then clone
9861 the DIE and add the clone into the tree. */
9864 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
9866 if (node->new_die != NULL)
9869 node->new_die = clone_as_declaration (node->old_die);
9871 if (node->parent != NULL)
9873 generate_skeleton_ancestor_tree (node->parent);
9874 add_child_die (node->parent->new_die, node->new_die);
9878 /* Generate a skeleton tree of DIEs containing any declarations that are
9879 found in the original tree. We traverse the tree looking for declaration
9880 DIEs, and construct the skeleton from the bottom up whenever we find one. */
9883 generate_skeleton_bottom_up (skeleton_chain_node *parent)
9885 skeleton_chain_node node;
9888 dw_die_ref prev = NULL;
9889 dw_die_ref next = NULL;
9891 node.parent = parent;
9893 first = c = parent->old_die->die_child;
9897 if (prev == NULL || prev->die_sib == c)
9900 next = (c == first ? NULL : c->die_sib);
9902 node.new_die = NULL;
9903 if (is_declaration_die (c))
9905 /* Clone the existing DIE, move the original to the skeleton
9906 tree (which is in the main CU), and put the clone, with
9907 all the original's children, where the original came from. */
9908 dw_die_ref clone = clone_die (c);
9909 move_all_children (c, clone);
9911 replace_child (c, clone, prev);
9912 generate_skeleton_ancestor_tree (parent);
9913 add_child_die (parent->new_die, c);
9917 generate_skeleton_bottom_up (&node);
9918 } while (next != NULL);
9921 /* Wrapper function for generate_skeleton_bottom_up. */
9924 generate_skeleton (dw_die_ref die)
9926 skeleton_chain_node node;
9929 node.new_die = NULL;
9932 /* If this type definition is nested inside another type,
9933 always leave at least a declaration in its place. */
9934 if (die->die_parent != NULL && is_type_die (die->die_parent))
9935 node.new_die = clone_as_declaration (die);
9937 generate_skeleton_bottom_up (&node);
9938 return node.new_die;
9941 /* Remove the DIE from its parent, possibly replacing it with a cloned
9942 declaration. The original DIE will be moved to a new compile unit
9943 so that existing references to it follow it to the new location. If
9944 any of the original DIE's descendants is a declaration, we need to
9945 replace the original DIE with a skeleton tree and move the
9946 declarations back into the skeleton tree. */
9949 remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev)
9951 dw_die_ref skeleton;
9953 skeleton = generate_skeleton (child);
9954 if (skeleton == NULL)
9955 remove_child_with_prev (child, prev);
9958 skeleton->die_id.die_type_node = child->die_id.die_type_node;
9959 replace_child (child, skeleton, prev);
9965 /* Traverse the DIE and set up additional .debug_types sections for each
9966 type worthy of being placed in a COMDAT section. */
9969 break_out_comdat_types (dw_die_ref die)
9973 dw_die_ref prev = NULL;
9974 dw_die_ref next = NULL;
9975 dw_die_ref unit = NULL;
9977 first = c = die->die_child;
9981 if (prev == NULL || prev->die_sib == c)
9984 next = (c == first ? NULL : c->die_sib);
9985 if (should_move_die_to_comdat (c))
9987 dw_die_ref replacement;
9988 comdat_type_node_ref type_node;
9990 /* Create a new type unit DIE as the root for the new tree, and
9991 add it to the list of comdat types. */
9992 unit = new_die (DW_TAG_type_unit, NULL, NULL);
9993 add_AT_unsigned (unit, DW_AT_language,
9994 get_AT_unsigned (comp_unit_die, DW_AT_language));
9995 type_node = ggc_alloc_cleared_comdat_type_node ();
9996 type_node->root_die = unit;
9997 type_node->next = comdat_type_list;
9998 comdat_type_list = type_node;
10000 /* Generate the type signature. */
10001 generate_type_signature (c, type_node);
10003 /* Copy the declaration context, attributes, and children of the
10004 declaration into the new compile unit DIE. */
10005 copy_declaration_context (unit, c);
10007 /* Remove this DIE from the main CU. */
10008 replacement = remove_child_or_replace_with_skeleton (c, prev);
10010 /* Break out nested types into their own type units. */
10011 break_out_comdat_types (c);
10013 /* Add the DIE to the new compunit. */
10014 add_child_die (unit, c);
10016 if (replacement != NULL)
10019 else if (c->die_tag == DW_TAG_namespace
10020 || c->die_tag == DW_TAG_class_type
10021 || c->die_tag == DW_TAG_structure_type
10022 || c->die_tag == DW_TAG_union_type)
10024 /* Look for nested types that can be broken out. */
10025 break_out_comdat_types (c);
10027 } while (next != NULL);
10030 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
10032 struct decl_table_entry
10038 /* Routines to manipulate hash table of copied declarations. */
10041 htab_decl_hash (const void *of)
10043 const struct decl_table_entry *const entry =
10044 (const struct decl_table_entry *) of;
10046 return htab_hash_pointer (entry->orig);
10050 htab_decl_eq (const void *of1, const void *of2)
10052 const struct decl_table_entry *const entry1 =
10053 (const struct decl_table_entry *) of1;
10054 const struct die_struct *const entry2 = (const struct die_struct *) of2;
10056 return entry1->orig == entry2;
10060 htab_decl_del (void *what)
10062 struct decl_table_entry *entry = (struct decl_table_entry *) what;
10067 /* Copy DIE and its ancestors, up to, but not including, the compile unit
10068 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
10069 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
10070 to check if the ancestor has already been copied into UNIT. */
10073 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10075 dw_die_ref parent = die->die_parent;
10076 dw_die_ref new_parent = unit;
10078 void **slot = NULL;
10079 struct decl_table_entry *entry = NULL;
10083 /* Check if the entry has already been copied to UNIT. */
10084 slot = htab_find_slot_with_hash (decl_table, die,
10085 htab_hash_pointer (die), INSERT);
10086 if (*slot != HTAB_EMPTY_ENTRY)
10088 entry = (struct decl_table_entry *) *slot;
10089 return entry->copy;
10092 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
10093 entry = XCNEW (struct decl_table_entry);
10095 entry->copy = NULL;
10099 if (parent != NULL)
10101 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
10104 if (parent->die_tag != DW_TAG_compile_unit
10105 && parent->die_tag != DW_TAG_type_unit)
10106 new_parent = copy_ancestor_tree (unit, parent, decl_table);
10109 copy = clone_as_declaration (die);
10110 add_child_die (new_parent, copy);
10112 if (decl_table != NULL)
10114 /* Record the pointer to the copy. */
10115 entry->copy = copy;
10121 /* Walk the DIE and its children, looking for references to incomplete
10122 or trivial types that are unmarked (i.e., that are not in the current
10126 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10132 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10134 if (AT_class (a) == dw_val_class_die_ref)
10136 dw_die_ref targ = AT_ref (a);
10137 comdat_type_node_ref type_node = targ->die_id.die_type_node;
10139 struct decl_table_entry *entry;
10141 if (targ->die_mark != 0 || type_node != NULL)
10144 slot = htab_find_slot_with_hash (decl_table, targ,
10145 htab_hash_pointer (targ), INSERT);
10147 if (*slot != HTAB_EMPTY_ENTRY)
10149 /* TARG has already been copied, so we just need to
10150 modify the reference to point to the copy. */
10151 entry = (struct decl_table_entry *) *slot;
10152 a->dw_attr_val.v.val_die_ref.die = entry->copy;
10156 dw_die_ref parent = unit;
10157 dw_die_ref copy = clone_tree (targ);
10159 /* Make sure the cloned tree is marked as part of the
10163 /* Record in DECL_TABLE that TARG has been copied.
10164 Need to do this now, before the recursive call,
10165 because DECL_TABLE may be expanded and SLOT
10166 would no longer be a valid pointer. */
10167 entry = XCNEW (struct decl_table_entry);
10168 entry->orig = targ;
10169 entry->copy = copy;
10172 /* If TARG has surrounding context, copy its ancestor tree
10173 into the new type unit. */
10174 if (targ->die_parent != NULL
10175 && targ->die_parent->die_tag != DW_TAG_compile_unit
10176 && targ->die_parent->die_tag != DW_TAG_type_unit)
10177 parent = copy_ancestor_tree (unit, targ->die_parent,
10180 add_child_die (parent, copy);
10181 a->dw_attr_val.v.val_die_ref.die = copy;
10183 /* Make sure the newly-copied DIE is walked. If it was
10184 installed in a previously-added context, it won't
10185 get visited otherwise. */
10186 if (parent != unit)
10188 /* Find the highest point of the newly-added tree,
10189 mark each node along the way, and walk from there. */
10190 parent->die_mark = 1;
10191 while (parent->die_parent
10192 && parent->die_parent->die_mark == 0)
10194 parent = parent->die_parent;
10195 parent->die_mark = 1;
10197 copy_decls_walk (unit, parent, decl_table);
10203 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
10206 /* Copy declarations for "unworthy" types into the new comdat section.
10207 Incomplete types, modified types, and certain other types aren't broken
10208 out into comdat sections of their own, so they don't have a signature,
10209 and we need to copy the declaration into the same section so that we
10210 don't have an external reference. */
10213 copy_decls_for_unworthy_types (dw_die_ref unit)
10218 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
10219 copy_decls_walk (unit, unit, decl_table);
10220 htab_delete (decl_table);
10221 unmark_dies (unit);
10224 /* Traverse the DIE and add a sibling attribute if it may have the
10225 effect of speeding up access to siblings. To save some space,
10226 avoid generating sibling attributes for DIE's without children. */
10229 add_sibling_attributes (dw_die_ref die)
10233 if (! die->die_child)
10236 if (die->die_parent && die != die->die_parent->die_child)
10237 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
10239 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
10242 /* Output all location lists for the DIE and its children. */
10245 output_location_lists (dw_die_ref die)
10251 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10252 if (AT_class (a) == dw_val_class_loc_list)
10253 output_loc_list (AT_loc_list (a));
10255 FOR_EACH_CHILD (die, c, output_location_lists (c));
10258 /* The format of each DIE (and its attribute value pairs) is encoded in an
10259 abbreviation table. This routine builds the abbreviation table and assigns
10260 a unique abbreviation id for each abbreviation entry. The children of each
10261 die are visited recursively. */
10264 build_abbrev_table (dw_die_ref die)
10266 unsigned long abbrev_id;
10267 unsigned int n_alloc;
10272 /* Scan the DIE references, and mark as external any that refer to
10273 DIEs from other CUs (i.e. those which are not marked). */
10274 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10275 if (AT_class (a) == dw_val_class_die_ref
10276 && AT_ref (a)->die_mark == 0)
10278 gcc_assert (dwarf_version >= 4 || AT_ref (a)->die_id.die_symbol);
10279 set_AT_ref_external (a, 1);
10282 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
10284 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
10285 dw_attr_ref die_a, abbrev_a;
10289 if (abbrev->die_tag != die->die_tag)
10291 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
10294 if (VEC_length (dw_attr_node, abbrev->die_attr)
10295 != VEC_length (dw_attr_node, die->die_attr))
10298 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
10300 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
10301 if ((abbrev_a->dw_attr != die_a->dw_attr)
10302 || (value_format (abbrev_a) != value_format (die_a)))
10312 if (abbrev_id >= abbrev_die_table_in_use)
10314 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
10316 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
10317 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
10320 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
10321 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
10322 abbrev_die_table_allocated = n_alloc;
10325 ++abbrev_die_table_in_use;
10326 abbrev_die_table[abbrev_id] = die;
10329 die->die_abbrev = abbrev_id;
10330 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
10333 /* Return the power-of-two number of bytes necessary to represent VALUE. */
10336 constant_size (unsigned HOST_WIDE_INT value)
10343 log = floor_log2 (value);
10346 log = 1 << (floor_log2 (log) + 1);
10351 /* Return the size of a DIE as it is represented in the
10352 .debug_info section. */
10354 static unsigned long
10355 size_of_die (dw_die_ref die)
10357 unsigned long size = 0;
10361 size += size_of_uleb128 (die->die_abbrev);
10362 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10364 switch (AT_class (a))
10366 case dw_val_class_addr:
10367 size += DWARF2_ADDR_SIZE;
10369 case dw_val_class_offset:
10370 size += DWARF_OFFSET_SIZE;
10372 case dw_val_class_loc:
10374 unsigned long lsize = size_of_locs (AT_loc (a));
10376 /* Block length. */
10377 if (dwarf_version >= 4)
10378 size += size_of_uleb128 (lsize);
10380 size += constant_size (lsize);
10384 case dw_val_class_loc_list:
10385 size += DWARF_OFFSET_SIZE;
10387 case dw_val_class_range_list:
10388 size += DWARF_OFFSET_SIZE;
10390 case dw_val_class_const:
10391 size += size_of_sleb128 (AT_int (a));
10393 case dw_val_class_unsigned_const:
10394 size += constant_size (AT_unsigned (a));
10396 case dw_val_class_const_double:
10397 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
10398 if (HOST_BITS_PER_WIDE_INT >= 64)
10399 size++; /* block */
10401 case dw_val_class_vec:
10402 size += constant_size (a->dw_attr_val.v.val_vec.length
10403 * a->dw_attr_val.v.val_vec.elt_size)
10404 + a->dw_attr_val.v.val_vec.length
10405 * a->dw_attr_val.v.val_vec.elt_size; /* block */
10407 case dw_val_class_flag:
10408 if (dwarf_version >= 4)
10409 /* Currently all add_AT_flag calls pass in 1 as last argument,
10410 so DW_FORM_flag_present can be used. If that ever changes,
10411 we'll need to use DW_FORM_flag and have some optimization
10412 in build_abbrev_table that will change those to
10413 DW_FORM_flag_present if it is set to 1 in all DIEs using
10414 the same abbrev entry. */
10415 gcc_assert (a->dw_attr_val.v.val_flag == 1);
10419 case dw_val_class_die_ref:
10420 if (AT_ref_external (a))
10422 /* In DWARF4, we use DW_FORM_sig8; for earlier versions
10423 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
10424 is sized by target address length, whereas in DWARF3
10425 it's always sized as an offset. */
10426 if (dwarf_version >= 4)
10427 size += DWARF_TYPE_SIGNATURE_SIZE;
10428 else if (dwarf_version == 2)
10429 size += DWARF2_ADDR_SIZE;
10431 size += DWARF_OFFSET_SIZE;
10434 size += DWARF_OFFSET_SIZE;
10436 case dw_val_class_fde_ref:
10437 size += DWARF_OFFSET_SIZE;
10439 case dw_val_class_lbl_id:
10440 size += DWARF2_ADDR_SIZE;
10442 case dw_val_class_lineptr:
10443 case dw_val_class_macptr:
10444 size += DWARF_OFFSET_SIZE;
10446 case dw_val_class_str:
10447 if (AT_string_form (a) == DW_FORM_strp)
10448 size += DWARF_OFFSET_SIZE;
10450 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
10452 case dw_val_class_file:
10453 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
10455 case dw_val_class_data8:
10458 case dw_val_class_vms_delta:
10459 size += DWARF_OFFSET_SIZE;
10462 gcc_unreachable ();
10469 /* Size the debugging information associated with a given DIE. Visits the
10470 DIE's children recursively. Updates the global variable next_die_offset, on
10471 each time through. Uses the current value of next_die_offset to update the
10472 die_offset field in each DIE. */
10475 calc_die_sizes (dw_die_ref die)
10479 die->die_offset = next_die_offset;
10480 next_die_offset += size_of_die (die);
10482 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
10484 if (die->die_child != NULL)
10485 /* Count the null byte used to terminate sibling lists. */
10486 next_die_offset += 1;
10489 /* Set the marks for a die and its children. We do this so
10490 that we know whether or not a reference needs to use FORM_ref_addr; only
10491 DIEs in the same CU will be marked. We used to clear out the offset
10492 and use that as the flag, but ran into ordering problems. */
10495 mark_dies (dw_die_ref die)
10499 gcc_assert (!die->die_mark);
10502 FOR_EACH_CHILD (die, c, mark_dies (c));
10505 /* Clear the marks for a die and its children. */
10508 unmark_dies (dw_die_ref die)
10512 if (dwarf_version < 4)
10513 gcc_assert (die->die_mark);
10516 FOR_EACH_CHILD (die, c, unmark_dies (c));
10519 /* Clear the marks for a die, its children and referred dies. */
10522 unmark_all_dies (dw_die_ref die)
10528 if (!die->die_mark)
10532 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
10534 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10535 if (AT_class (a) == dw_val_class_die_ref)
10536 unmark_all_dies (AT_ref (a));
10539 /* Return the size of the .debug_pubnames or .debug_pubtypes table
10540 generated for the compilation unit. */
10542 static unsigned long
10543 size_of_pubnames (VEC (pubname_entry, gc) * names)
10545 unsigned long size;
10549 size = DWARF_PUBNAMES_HEADER_SIZE;
10550 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
10551 if (names != pubtype_table
10552 || p->die->die_offset != 0
10553 || !flag_eliminate_unused_debug_types)
10554 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
10556 size += DWARF_OFFSET_SIZE;
10560 /* Return the size of the information in the .debug_aranges section. */
10562 static unsigned long
10563 size_of_aranges (void)
10565 unsigned long size;
10567 size = DWARF_ARANGES_HEADER_SIZE;
10569 /* Count the address/length pair for this compilation unit. */
10570 if (text_section_used)
10571 size += 2 * DWARF2_ADDR_SIZE;
10572 if (cold_text_section_used)
10573 size += 2 * DWARF2_ADDR_SIZE;
10574 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
10576 /* Count the two zero words used to terminated the address range table. */
10577 size += 2 * DWARF2_ADDR_SIZE;
10581 /* Select the encoding of an attribute value. */
10583 static enum dwarf_form
10584 value_format (dw_attr_ref a)
10586 switch (a->dw_attr_val.val_class)
10588 case dw_val_class_addr:
10589 /* Only very few attributes allow DW_FORM_addr. */
10590 switch (a->dw_attr)
10593 case DW_AT_high_pc:
10594 case DW_AT_entry_pc:
10595 case DW_AT_trampoline:
10596 return DW_FORM_addr;
10600 switch (DWARF2_ADDR_SIZE)
10603 return DW_FORM_data1;
10605 return DW_FORM_data2;
10607 return DW_FORM_data4;
10609 return DW_FORM_data8;
10611 gcc_unreachable ();
10613 case dw_val_class_range_list:
10614 case dw_val_class_loc_list:
10615 if (dwarf_version >= 4)
10616 return DW_FORM_sec_offset;
10618 case dw_val_class_vms_delta:
10619 case dw_val_class_offset:
10620 switch (DWARF_OFFSET_SIZE)
10623 return DW_FORM_data4;
10625 return DW_FORM_data8;
10627 gcc_unreachable ();
10629 case dw_val_class_loc:
10630 if (dwarf_version >= 4)
10631 return DW_FORM_exprloc;
10632 switch (constant_size (size_of_locs (AT_loc (a))))
10635 return DW_FORM_block1;
10637 return DW_FORM_block2;
10639 gcc_unreachable ();
10641 case dw_val_class_const:
10642 return DW_FORM_sdata;
10643 case dw_val_class_unsigned_const:
10644 switch (constant_size (AT_unsigned (a)))
10647 return DW_FORM_data1;
10649 return DW_FORM_data2;
10651 return DW_FORM_data4;
10653 return DW_FORM_data8;
10655 gcc_unreachable ();
10657 case dw_val_class_const_double:
10658 switch (HOST_BITS_PER_WIDE_INT)
10661 return DW_FORM_data2;
10663 return DW_FORM_data4;
10665 return DW_FORM_data8;
10668 return DW_FORM_block1;
10670 case dw_val_class_vec:
10671 switch (constant_size (a->dw_attr_val.v.val_vec.length
10672 * a->dw_attr_val.v.val_vec.elt_size))
10675 return DW_FORM_block1;
10677 return DW_FORM_block2;
10679 return DW_FORM_block4;
10681 gcc_unreachable ();
10683 case dw_val_class_flag:
10684 if (dwarf_version >= 4)
10686 /* Currently all add_AT_flag calls pass in 1 as last argument,
10687 so DW_FORM_flag_present can be used. If that ever changes,
10688 we'll need to use DW_FORM_flag and have some optimization
10689 in build_abbrev_table that will change those to
10690 DW_FORM_flag_present if it is set to 1 in all DIEs using
10691 the same abbrev entry. */
10692 gcc_assert (a->dw_attr_val.v.val_flag == 1);
10693 return DW_FORM_flag_present;
10695 return DW_FORM_flag;
10696 case dw_val_class_die_ref:
10697 if (AT_ref_external (a))
10698 return dwarf_version >= 4 ? DW_FORM_sig8 : DW_FORM_ref_addr;
10700 return DW_FORM_ref;
10701 case dw_val_class_fde_ref:
10702 return DW_FORM_data;
10703 case dw_val_class_lbl_id:
10704 return DW_FORM_addr;
10705 case dw_val_class_lineptr:
10706 case dw_val_class_macptr:
10707 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
10708 case dw_val_class_str:
10709 return AT_string_form (a);
10710 case dw_val_class_file:
10711 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
10714 return DW_FORM_data1;
10716 return DW_FORM_data2;
10718 return DW_FORM_data4;
10720 gcc_unreachable ();
10723 case dw_val_class_data8:
10724 return DW_FORM_data8;
10727 gcc_unreachable ();
10731 /* Output the encoding of an attribute value. */
10734 output_value_format (dw_attr_ref a)
10736 enum dwarf_form form = value_format (a);
10738 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
10741 /* Output the .debug_abbrev section which defines the DIE abbreviation
10745 output_abbrev_section (void)
10747 unsigned long abbrev_id;
10749 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
10751 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
10753 dw_attr_ref a_attr;
10755 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
10756 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
10757 dwarf_tag_name (abbrev->die_tag));
10759 if (abbrev->die_child != NULL)
10760 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
10762 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
10764 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
10767 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
10768 dwarf_attr_name (a_attr->dw_attr));
10769 output_value_format (a_attr);
10772 dw2_asm_output_data (1, 0, NULL);
10773 dw2_asm_output_data (1, 0, NULL);
10776 /* Terminate the table. */
10777 dw2_asm_output_data (1, 0, NULL);
10780 /* Output a symbol we can use to refer to this DIE from another CU. */
10783 output_die_symbol (dw_die_ref die)
10785 char *sym = die->die_id.die_symbol;
10790 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
10791 /* We make these global, not weak; if the target doesn't support
10792 .linkonce, it doesn't support combining the sections, so debugging
10794 targetm.asm_out.globalize_label (asm_out_file, sym);
10796 ASM_OUTPUT_LABEL (asm_out_file, sym);
10799 /* Return a new location list, given the begin and end range, and the
10802 static inline dw_loc_list_ref
10803 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
10804 const char *section)
10806 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
10808 retlist->begin = begin;
10809 retlist->end = end;
10810 retlist->expr = expr;
10811 retlist->section = section;
10816 /* Generate a new internal symbol for this location list node, if it
10817 hasn't got one yet. */
10820 gen_llsym (dw_loc_list_ref list)
10822 gcc_assert (!list->ll_symbol);
10823 list->ll_symbol = gen_internal_sym ("LLST");
10826 /* Output the location list given to us. */
10829 output_loc_list (dw_loc_list_ref list_head)
10831 dw_loc_list_ref curr = list_head;
10833 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
10835 /* Walk the location list, and output each range + expression. */
10836 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
10838 unsigned long size;
10839 /* Don't output an entry that starts and ends at the same address. */
10840 if (strcmp (curr->begin, curr->end) == 0)
10842 if (!have_multiple_function_sections)
10844 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
10845 "Location list begin address (%s)",
10846 list_head->ll_symbol);
10847 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
10848 "Location list end address (%s)",
10849 list_head->ll_symbol);
10853 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
10854 "Location list begin address (%s)",
10855 list_head->ll_symbol);
10856 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
10857 "Location list end address (%s)",
10858 list_head->ll_symbol);
10860 size = size_of_locs (curr->expr);
10862 /* Output the block length for this list of location operations. */
10863 gcc_assert (size <= 0xffff);
10864 dw2_asm_output_data (2, size, "%s", "Location expression size");
10866 output_loc_sequence (curr->expr);
10869 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
10870 "Location list terminator begin (%s)",
10871 list_head->ll_symbol);
10872 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
10873 "Location list terminator end (%s)",
10874 list_head->ll_symbol);
10877 /* Output a type signature. */
10880 output_signature (const char *sig, const char *name)
10884 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
10885 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
10888 /* Output the DIE and its attributes. Called recursively to generate
10889 the definitions of each child DIE. */
10892 output_die (dw_die_ref die)
10896 unsigned long size;
10899 /* If someone in another CU might refer to us, set up a symbol for
10900 them to point to. */
10901 if (dwarf_version < 4 && die->die_id.die_symbol)
10902 output_die_symbol (die);
10904 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
10905 (unsigned long)die->die_offset,
10906 dwarf_tag_name (die->die_tag));
10908 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10910 const char *name = dwarf_attr_name (a->dw_attr);
10912 switch (AT_class (a))
10914 case dw_val_class_addr:
10915 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
10918 case dw_val_class_offset:
10919 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
10923 case dw_val_class_range_list:
10925 char *p = strchr (ranges_section_label, '\0');
10927 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
10928 a->dw_attr_val.v.val_offset);
10929 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
10930 debug_ranges_section, "%s", name);
10935 case dw_val_class_loc:
10936 size = size_of_locs (AT_loc (a));
10938 /* Output the block length for this list of location operations. */
10939 if (dwarf_version >= 4)
10940 dw2_asm_output_data_uleb128 (size, "%s", name);
10942 dw2_asm_output_data (constant_size (size), size, "%s", name);
10944 output_loc_sequence (AT_loc (a));
10947 case dw_val_class_const:
10948 /* ??? It would be slightly more efficient to use a scheme like is
10949 used for unsigned constants below, but gdb 4.x does not sign
10950 extend. Gdb 5.x does sign extend. */
10951 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
10954 case dw_val_class_unsigned_const:
10955 dw2_asm_output_data (constant_size (AT_unsigned (a)),
10956 AT_unsigned (a), "%s", name);
10959 case dw_val_class_const_double:
10961 unsigned HOST_WIDE_INT first, second;
10963 if (HOST_BITS_PER_WIDE_INT >= 64)
10964 dw2_asm_output_data (1,
10965 2 * HOST_BITS_PER_WIDE_INT
10966 / HOST_BITS_PER_CHAR,
10969 if (WORDS_BIG_ENDIAN)
10971 first = a->dw_attr_val.v.val_double.high;
10972 second = a->dw_attr_val.v.val_double.low;
10976 first = a->dw_attr_val.v.val_double.low;
10977 second = a->dw_attr_val.v.val_double.high;
10980 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
10982 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
10987 case dw_val_class_vec:
10989 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
10990 unsigned int len = a->dw_attr_val.v.val_vec.length;
10994 dw2_asm_output_data (constant_size (len * elt_size),
10995 len * elt_size, "%s", name);
10996 if (elt_size > sizeof (HOST_WIDE_INT))
11001 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
11003 i++, p += elt_size)
11004 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
11005 "fp or vector constant word %u", i);
11009 case dw_val_class_flag:
11010 if (dwarf_version >= 4)
11012 /* Currently all add_AT_flag calls pass in 1 as last argument,
11013 so DW_FORM_flag_present can be used. If that ever changes,
11014 we'll need to use DW_FORM_flag and have some optimization
11015 in build_abbrev_table that will change those to
11016 DW_FORM_flag_present if it is set to 1 in all DIEs using
11017 the same abbrev entry. */
11018 gcc_assert (AT_flag (a) == 1);
11019 if (flag_debug_asm)
11020 fprintf (asm_out_file, "\t\t\t%s %s\n",
11021 ASM_COMMENT_START, name);
11024 dw2_asm_output_data (1, AT_flag (a), "%s", name);
11027 case dw_val_class_loc_list:
11029 char *sym = AT_loc_list (a)->ll_symbol;
11032 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
11037 case dw_val_class_die_ref:
11038 if (AT_ref_external (a))
11040 if (dwarf_version >= 4)
11042 comdat_type_node_ref type_node =
11043 AT_ref (a)->die_id.die_type_node;
11045 gcc_assert (type_node);
11046 output_signature (type_node->signature, name);
11050 char *sym = AT_ref (a)->die_id.die_symbol;
11054 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11055 length, whereas in DWARF3 it's always sized as an
11057 if (dwarf_version == 2)
11058 size = DWARF2_ADDR_SIZE;
11060 size = DWARF_OFFSET_SIZE;
11061 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
11067 gcc_assert (AT_ref (a)->die_offset);
11068 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
11073 case dw_val_class_fde_ref:
11077 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
11078 a->dw_attr_val.v.val_fde_index * 2);
11079 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
11084 case dw_val_class_vms_delta:
11085 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
11086 AT_vms_delta2 (a), AT_vms_delta1 (a),
11090 case dw_val_class_lbl_id:
11091 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
11094 case dw_val_class_lineptr:
11095 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11096 debug_line_section, "%s", name);
11099 case dw_val_class_macptr:
11100 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11101 debug_macinfo_section, "%s", name);
11104 case dw_val_class_str:
11105 if (AT_string_form (a) == DW_FORM_strp)
11106 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
11107 a->dw_attr_val.v.val_str->label,
11109 "%s: \"%s\"", name, AT_string (a));
11111 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
11114 case dw_val_class_file:
11116 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
11118 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
11119 a->dw_attr_val.v.val_file->filename);
11123 case dw_val_class_data8:
11127 for (i = 0; i < 8; i++)
11128 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
11129 i == 0 ? "%s" : NULL, name);
11134 gcc_unreachable ();
11138 FOR_EACH_CHILD (die, c, output_die (c));
11140 /* Add null byte to terminate sibling list. */
11141 if (die->die_child != NULL)
11142 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11143 (unsigned long) die->die_offset);
11146 /* Output the compilation unit that appears at the beginning of the
11147 .debug_info section, and precedes the DIE descriptions. */
11150 output_compilation_unit_header (void)
11152 int ver = dwarf_version;
11154 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11155 dw2_asm_output_data (4, 0xffffffff,
11156 "Initial length escape value indicating 64-bit DWARF extension");
11157 dw2_asm_output_data (DWARF_OFFSET_SIZE,
11158 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
11159 "Length of Compilation Unit Info");
11160 dw2_asm_output_data (2, ver, "DWARF version number");
11161 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
11162 debug_abbrev_section,
11163 "Offset Into Abbrev. Section");
11164 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11167 /* Output the compilation unit DIE and its children. */
11170 output_comp_unit (dw_die_ref die, int output_if_empty)
11172 const char *secname;
11173 char *oldsym, *tmp;
11175 /* Unless we are outputting main CU, we may throw away empty ones. */
11176 if (!output_if_empty && die->die_child == NULL)
11179 /* Even if there are no children of this DIE, we must output the information
11180 about the compilation unit. Otherwise, on an empty translation unit, we
11181 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11182 will then complain when examining the file. First mark all the DIEs in
11183 this CU so we know which get local refs. */
11186 build_abbrev_table (die);
11188 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11189 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
11190 calc_die_sizes (die);
11192 oldsym = die->die_id.die_symbol;
11195 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
11197 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
11199 die->die_id.die_symbol = NULL;
11200 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11203 switch_to_section (debug_info_section);
11205 /* Output debugging information. */
11206 output_compilation_unit_header ();
11209 /* Leave the marks on the main CU, so we can check them in
11210 output_pubnames. */
11214 die->die_id.die_symbol = oldsym;
11218 /* Output a comdat type unit DIE and its children. */
11221 output_comdat_type_unit (comdat_type_node *node)
11223 const char *secname;
11226 #if defined (OBJECT_FORMAT_ELF)
11230 /* First mark all the DIEs in this CU so we know which get local refs. */
11231 mark_dies (node->root_die);
11233 build_abbrev_table (node->root_die);
11235 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11236 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
11237 calc_die_sizes (node->root_die);
11239 #if defined (OBJECT_FORMAT_ELF)
11240 secname = ".debug_types";
11241 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11242 sprintf (tmp, "wt.");
11243 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11244 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
11245 comdat_key = get_identifier (tmp);
11246 targetm.asm_out.named_section (secname,
11247 SECTION_DEBUG | SECTION_LINKONCE,
11250 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11251 sprintf (tmp, ".gnu.linkonce.wt.");
11252 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11253 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
11255 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11258 /* Output debugging information. */
11259 output_compilation_unit_header ();
11260 output_signature (node->signature, "Type Signature");
11261 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
11262 "Offset to Type DIE");
11263 output_die (node->root_die);
11265 unmark_dies (node->root_die);
11268 /* Return the DWARF2/3 pubname associated with a decl. */
11270 static const char *
11271 dwarf2_name (tree decl, int scope)
11273 if (DECL_NAMELESS (decl))
11275 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
11278 /* Add a new entry to .debug_pubnames if appropriate. */
11281 add_pubname_string (const char *str, dw_die_ref die)
11283 if (targetm.want_debug_pub_sections)
11288 e.name = xstrdup (str);
11289 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
11294 add_pubname (tree decl, dw_die_ref die)
11296 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
11298 const char *name = dwarf2_name (decl, 1);
11300 add_pubname_string (name, die);
11304 /* Add a new entry to .debug_pubtypes if appropriate. */
11307 add_pubtype (tree decl, dw_die_ref die)
11311 if (!targetm.want_debug_pub_sections)
11315 if ((TREE_PUBLIC (decl)
11316 || die->die_parent == comp_unit_die)
11317 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
11322 if (TYPE_NAME (decl))
11324 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
11325 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
11326 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
11327 && DECL_NAME (TYPE_NAME (decl)))
11328 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
11330 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
11335 e.name = dwarf2_name (decl, 1);
11337 e.name = xstrdup (e.name);
11340 /* If we don't have a name for the type, there's no point in adding
11341 it to the table. */
11342 if (e.name && e.name[0] != '\0')
11343 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
11347 /* Output the public names table used to speed up access to externally
11348 visible names; or the public types table used to find type definitions. */
11351 output_pubnames (VEC (pubname_entry, gc) * names)
11354 unsigned long pubnames_length = size_of_pubnames (names);
11357 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11358 dw2_asm_output_data (4, 0xffffffff,
11359 "Initial length escape value indicating 64-bit DWARF extension");
11360 if (names == pubname_table)
11361 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11362 "Length of Public Names Info");
11364 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11365 "Length of Public Type Names Info");
11366 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
11367 dw2_asm_output_data (2, 2, "DWARF Version");
11368 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11369 debug_info_section,
11370 "Offset of Compilation Unit Info");
11371 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
11372 "Compilation Unit Length");
11374 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
11376 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11377 if (names == pubname_table)
11378 gcc_assert (pub->die->die_mark);
11380 if (names != pubtype_table
11381 || pub->die->die_offset != 0
11382 || !flag_eliminate_unused_debug_types)
11384 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
11387 dw2_asm_output_nstring (pub->name, -1, "external name");
11391 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
11394 /* Add a new entry to .debug_aranges if appropriate. */
11397 add_arange (tree decl, dw_die_ref die)
11399 if (! DECL_SECTION_NAME (decl))
11402 if (arange_table_in_use == arange_table_allocated)
11404 arange_table_allocated += ARANGE_TABLE_INCREMENT;
11405 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
11406 arange_table_allocated);
11407 memset (arange_table + arange_table_in_use, 0,
11408 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
11411 arange_table[arange_table_in_use++] = die;
11414 /* Output the information that goes into the .debug_aranges table.
11415 Namely, define the beginning and ending address range of the
11416 text section generated for this compilation unit. */
11419 output_aranges (void)
11422 unsigned long aranges_length = size_of_aranges ();
11424 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11425 dw2_asm_output_data (4, 0xffffffff,
11426 "Initial length escape value indicating 64-bit DWARF extension");
11427 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
11428 "Length of Address Ranges Info");
11429 /* Version number for aranges is still 2, even in DWARF3. */
11430 dw2_asm_output_data (2, 2, "DWARF Version");
11431 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11432 debug_info_section,
11433 "Offset of Compilation Unit Info");
11434 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
11435 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11437 /* We need to align to twice the pointer size here. */
11438 if (DWARF_ARANGES_PAD_SIZE)
11440 /* Pad using a 2 byte words so that padding is correct for any
11442 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11443 2 * DWARF2_ADDR_SIZE);
11444 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
11445 dw2_asm_output_data (2, 0, NULL);
11448 /* It is necessary not to output these entries if the sections were
11449 not used; if the sections were not used, the length will be 0 and
11450 the address may end up as 0 if the section is discarded by ld
11451 --gc-sections, leaving an invalid (0, 0) entry that can be
11452 confused with the terminator. */
11453 if (text_section_used)
11455 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
11456 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
11457 text_section_label, "Length");
11459 if (cold_text_section_used)
11461 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
11463 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
11464 cold_text_section_label, "Length");
11467 for (i = 0; i < arange_table_in_use; i++)
11469 dw_die_ref die = arange_table[i];
11471 /* We shouldn't see aranges for DIEs outside of the main CU. */
11472 gcc_assert (die->die_mark);
11474 if (die->die_tag == DW_TAG_subprogram)
11476 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
11478 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
11479 get_AT_low_pc (die), "Length");
11483 /* A static variable; extract the symbol from DW_AT_location.
11484 Note that this code isn't currently hit, as we only emit
11485 aranges for functions (jason 9/23/99). */
11486 dw_attr_ref a = get_AT (die, DW_AT_location);
11487 dw_loc_descr_ref loc;
11489 gcc_assert (a && AT_class (a) == dw_val_class_loc);
11492 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
11494 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
11495 loc->dw_loc_oprnd1.v.val_addr, "Address");
11496 dw2_asm_output_data (DWARF2_ADDR_SIZE,
11497 get_AT_unsigned (die, DW_AT_byte_size),
11502 /* Output the terminator words. */
11503 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11504 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11507 /* Add a new entry to .debug_ranges. Return the offset at which it
11510 static unsigned int
11511 add_ranges_num (int num)
11513 unsigned int in_use = ranges_table_in_use;
11515 if (in_use == ranges_table_allocated)
11517 ranges_table_allocated += RANGES_TABLE_INCREMENT;
11518 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
11519 ranges_table_allocated);
11520 memset (ranges_table + ranges_table_in_use, 0,
11521 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
11524 ranges_table[in_use].num = num;
11525 ranges_table_in_use = in_use + 1;
11527 return in_use * 2 * DWARF2_ADDR_SIZE;
11530 /* Add a new entry to .debug_ranges corresponding to a block, or a
11531 range terminator if BLOCK is NULL. */
11533 static unsigned int
11534 add_ranges (const_tree block)
11536 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
11539 /* Add a new entry to .debug_ranges corresponding to a pair of
11543 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
11546 unsigned int in_use = ranges_by_label_in_use;
11547 unsigned int offset;
11549 if (in_use == ranges_by_label_allocated)
11551 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
11552 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
11554 ranges_by_label_allocated);
11555 memset (ranges_by_label + ranges_by_label_in_use, 0,
11556 RANGES_TABLE_INCREMENT
11557 * sizeof (struct dw_ranges_by_label_struct));
11560 ranges_by_label[in_use].begin = begin;
11561 ranges_by_label[in_use].end = end;
11562 ranges_by_label_in_use = in_use + 1;
11564 offset = add_ranges_num (-(int)in_use - 1);
11567 add_AT_range_list (die, DW_AT_ranges, offset);
11573 output_ranges (void)
11576 static const char *const start_fmt = "Offset %#x";
11577 const char *fmt = start_fmt;
11579 for (i = 0; i < ranges_table_in_use; i++)
11581 int block_num = ranges_table[i].num;
11585 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
11586 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
11588 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
11589 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
11591 /* If all code is in the text section, then the compilation
11592 unit base address defaults to DW_AT_low_pc, which is the
11593 base of the text section. */
11594 if (!have_multiple_function_sections)
11596 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
11597 text_section_label,
11598 fmt, i * 2 * DWARF2_ADDR_SIZE);
11599 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
11600 text_section_label, NULL);
11603 /* Otherwise, the compilation unit base address is zero,
11604 which allows us to use absolute addresses, and not worry
11605 about whether the target supports cross-section
11609 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
11610 fmt, i * 2 * DWARF2_ADDR_SIZE);
11611 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
11617 /* Negative block_num stands for an index into ranges_by_label. */
11618 else if (block_num < 0)
11620 int lab_idx = - block_num - 1;
11622 if (!have_multiple_function_sections)
11624 gcc_unreachable ();
11626 /* If we ever use add_ranges_by_labels () for a single
11627 function section, all we have to do is to take out
11628 the #if 0 above. */
11629 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11630 ranges_by_label[lab_idx].begin,
11631 text_section_label,
11632 fmt, i * 2 * DWARF2_ADDR_SIZE);
11633 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11634 ranges_by_label[lab_idx].end,
11635 text_section_label, NULL);
11640 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11641 ranges_by_label[lab_idx].begin,
11642 fmt, i * 2 * DWARF2_ADDR_SIZE);
11643 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11644 ranges_by_label[lab_idx].end,
11650 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11651 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11657 /* Data structure containing information about input files. */
11660 const char *path; /* Complete file name. */
11661 const char *fname; /* File name part. */
11662 int length; /* Length of entire string. */
11663 struct dwarf_file_data * file_idx; /* Index in input file table. */
11664 int dir_idx; /* Index in directory table. */
11667 /* Data structure containing information about directories with source
11671 const char *path; /* Path including directory name. */
11672 int length; /* Path length. */
11673 int prefix; /* Index of directory entry which is a prefix. */
11674 int count; /* Number of files in this directory. */
11675 int dir_idx; /* Index of directory used as base. */
11678 /* Callback function for file_info comparison. We sort by looking at
11679 the directories in the path. */
11682 file_info_cmp (const void *p1, const void *p2)
11684 const struct file_info *const s1 = (const struct file_info *) p1;
11685 const struct file_info *const s2 = (const struct file_info *) p2;
11686 const unsigned char *cp1;
11687 const unsigned char *cp2;
11689 /* Take care of file names without directories. We need to make sure that
11690 we return consistent values to qsort since some will get confused if
11691 we return the same value when identical operands are passed in opposite
11692 orders. So if neither has a directory, return 0 and otherwise return
11693 1 or -1 depending on which one has the directory. */
11694 if ((s1->path == s1->fname || s2->path == s2->fname))
11695 return (s2->path == s2->fname) - (s1->path == s1->fname);
11697 cp1 = (const unsigned char *) s1->path;
11698 cp2 = (const unsigned char *) s2->path;
11704 /* Reached the end of the first path? If so, handle like above. */
11705 if ((cp1 == (const unsigned char *) s1->fname)
11706 || (cp2 == (const unsigned char *) s2->fname))
11707 return ((cp2 == (const unsigned char *) s2->fname)
11708 - (cp1 == (const unsigned char *) s1->fname));
11710 /* Character of current path component the same? */
11711 else if (*cp1 != *cp2)
11712 return *cp1 - *cp2;
11716 struct file_name_acquire_data
11718 struct file_info *files;
11723 /* Traversal function for the hash table. */
11726 file_name_acquire (void ** slot, void *data)
11728 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
11729 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
11730 struct file_info *fi;
11733 gcc_assert (fnad->max_files >= d->emitted_number);
11735 if (! d->emitted_number)
11738 gcc_assert (fnad->max_files != fnad->used_files);
11740 fi = fnad->files + fnad->used_files++;
11742 /* Skip all leading "./". */
11744 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
11747 /* Create a new array entry. */
11749 fi->length = strlen (f);
11752 /* Search for the file name part. */
11753 f = strrchr (f, DIR_SEPARATOR);
11754 #if defined (DIR_SEPARATOR_2)
11756 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
11760 if (f == NULL || f < g)
11766 fi->fname = f == NULL ? fi->path : f + 1;
11770 /* Output the directory table and the file name table. We try to minimize
11771 the total amount of memory needed. A heuristic is used to avoid large
11772 slowdowns with many input files. */
11775 output_file_names (void)
11777 struct file_name_acquire_data fnad;
11779 struct file_info *files;
11780 struct dir_info *dirs;
11788 if (!last_emitted_file)
11790 dw2_asm_output_data (1, 0, "End directory table");
11791 dw2_asm_output_data (1, 0, "End file name table");
11795 numfiles = last_emitted_file->emitted_number;
11797 /* Allocate the various arrays we need. */
11798 files = XALLOCAVEC (struct file_info, numfiles);
11799 dirs = XALLOCAVEC (struct dir_info, numfiles);
11801 fnad.files = files;
11802 fnad.used_files = 0;
11803 fnad.max_files = numfiles;
11804 htab_traverse (file_table, file_name_acquire, &fnad);
11805 gcc_assert (fnad.used_files == fnad.max_files);
11807 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
11809 /* Find all the different directories used. */
11810 dirs[0].path = files[0].path;
11811 dirs[0].length = files[0].fname - files[0].path;
11812 dirs[0].prefix = -1;
11814 dirs[0].dir_idx = 0;
11815 files[0].dir_idx = 0;
11818 for (i = 1; i < numfiles; i++)
11819 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
11820 && memcmp (dirs[ndirs - 1].path, files[i].path,
11821 dirs[ndirs - 1].length) == 0)
11823 /* Same directory as last entry. */
11824 files[i].dir_idx = ndirs - 1;
11825 ++dirs[ndirs - 1].count;
11831 /* This is a new directory. */
11832 dirs[ndirs].path = files[i].path;
11833 dirs[ndirs].length = files[i].fname - files[i].path;
11834 dirs[ndirs].count = 1;
11835 dirs[ndirs].dir_idx = ndirs;
11836 files[i].dir_idx = ndirs;
11838 /* Search for a prefix. */
11839 dirs[ndirs].prefix = -1;
11840 for (j = 0; j < ndirs; j++)
11841 if (dirs[j].length < dirs[ndirs].length
11842 && dirs[j].length > 1
11843 && (dirs[ndirs].prefix == -1
11844 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
11845 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
11846 dirs[ndirs].prefix = j;
11851 /* Now to the actual work. We have to find a subset of the directories which
11852 allow expressing the file name using references to the directory table
11853 with the least amount of characters. We do not do an exhaustive search
11854 where we would have to check out every combination of every single
11855 possible prefix. Instead we use a heuristic which provides nearly optimal
11856 results in most cases and never is much off. */
11857 saved = XALLOCAVEC (int, ndirs);
11858 savehere = XALLOCAVEC (int, ndirs);
11860 memset (saved, '\0', ndirs * sizeof (saved[0]));
11861 for (i = 0; i < ndirs; i++)
11866 /* We can always save some space for the current directory. But this
11867 does not mean it will be enough to justify adding the directory. */
11868 savehere[i] = dirs[i].length;
11869 total = (savehere[i] - saved[i]) * dirs[i].count;
11871 for (j = i + 1; j < ndirs; j++)
11874 if (saved[j] < dirs[i].length)
11876 /* Determine whether the dirs[i] path is a prefix of the
11880 k = dirs[j].prefix;
11881 while (k != -1 && k != (int) i)
11882 k = dirs[k].prefix;
11886 /* Yes it is. We can possibly save some memory by
11887 writing the filenames in dirs[j] relative to
11889 savehere[j] = dirs[i].length;
11890 total += (savehere[j] - saved[j]) * dirs[j].count;
11895 /* Check whether we can save enough to justify adding the dirs[i]
11897 if (total > dirs[i].length + 1)
11899 /* It's worthwhile adding. */
11900 for (j = i; j < ndirs; j++)
11901 if (savehere[j] > 0)
11903 /* Remember how much we saved for this directory so far. */
11904 saved[j] = savehere[j];
11906 /* Remember the prefix directory. */
11907 dirs[j].dir_idx = i;
11912 /* Emit the directory name table. */
11913 idx_offset = dirs[0].length > 0 ? 1 : 0;
11914 for (i = 1 - idx_offset; i < ndirs; i++)
11915 dw2_asm_output_nstring (dirs[i].path,
11917 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
11918 "Directory Entry: %#x", i + idx_offset);
11920 dw2_asm_output_data (1, 0, "End directory table");
11922 /* We have to emit them in the order of emitted_number since that's
11923 used in the debug info generation. To do this efficiently we
11924 generate a back-mapping of the indices first. */
11925 backmap = XALLOCAVEC (int, numfiles);
11926 for (i = 0; i < numfiles; i++)
11927 backmap[files[i].file_idx->emitted_number - 1] = i;
11929 /* Now write all the file names. */
11930 for (i = 0; i < numfiles; i++)
11932 int file_idx = backmap[i];
11933 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
11935 #ifdef VMS_DEBUGGING_INFO
11936 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
11938 /* Setting these fields can lead to debugger miscomparisons,
11939 but VMS Debug requires them to be set correctly. */
11944 int maxfilelen = strlen (files[file_idx].path)
11945 + dirs[dir_idx].length
11946 + MAX_VMS_VERSION_LEN + 1;
11947 char *filebuf = XALLOCAVEC (char, maxfilelen);
11949 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
11950 snprintf (filebuf, maxfilelen, "%s;%d",
11951 files[file_idx].path + dirs[dir_idx].length, ver);
11953 dw2_asm_output_nstring
11954 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
11956 /* Include directory index. */
11957 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
11959 /* Modification time. */
11960 dw2_asm_output_data_uleb128
11961 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
11965 /* File length in bytes. */
11966 dw2_asm_output_data_uleb128
11967 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
11971 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
11972 "File Entry: %#x", (unsigned) i + 1);
11974 /* Include directory index. */
11975 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
11977 /* Modification time. */
11978 dw2_asm_output_data_uleb128 (0, NULL);
11980 /* File length in bytes. */
11981 dw2_asm_output_data_uleb128 (0, NULL);
11982 #endif /* VMS_DEBUGGING_INFO */
11985 dw2_asm_output_data (1, 0, "End file name table");
11989 /* Output the source line number correspondence information. This
11990 information goes into the .debug_line section. */
11993 output_line_info (void)
11995 char l1[20], l2[20], p1[20], p2[20];
11996 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
11997 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
11999 unsigned n_op_args;
12000 unsigned long lt_index;
12001 unsigned long current_line;
12004 unsigned long current_file;
12005 unsigned long function;
12006 int ver = dwarf_version;
12008 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
12009 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
12010 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
12011 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
12013 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12014 dw2_asm_output_data (4, 0xffffffff,
12015 "Initial length escape value indicating 64-bit DWARF extension");
12016 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
12017 "Length of Source Line Info");
12018 ASM_OUTPUT_LABEL (asm_out_file, l1);
12020 dw2_asm_output_data (2, ver, "DWARF Version");
12021 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
12022 ASM_OUTPUT_LABEL (asm_out_file, p1);
12024 /* Define the architecture-dependent minimum instruction length (in
12025 bytes). In this implementation of DWARF, this field is used for
12026 information purposes only. Since GCC generates assembly language,
12027 we have no a priori knowledge of how many instruction bytes are
12028 generated for each source line, and therefore can use only the
12029 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
12030 commands. Accordingly, we fix this as `1', which is "correct
12031 enough" for all architectures, and don't let the target override. */
12032 dw2_asm_output_data (1, 1,
12033 "Minimum Instruction Length");
12036 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
12037 "Maximum Operations Per Instruction");
12038 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
12039 "Default is_stmt_start flag");
12040 dw2_asm_output_data (1, DWARF_LINE_BASE,
12041 "Line Base Value (Special Opcodes)");
12042 dw2_asm_output_data (1, DWARF_LINE_RANGE,
12043 "Line Range Value (Special Opcodes)");
12044 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
12045 "Special Opcode Base");
12047 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
12051 case DW_LNS_advance_pc:
12052 case DW_LNS_advance_line:
12053 case DW_LNS_set_file:
12054 case DW_LNS_set_column:
12055 case DW_LNS_fixed_advance_pc:
12063 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
12067 /* Write out the information about the files we use. */
12068 output_file_names ();
12069 ASM_OUTPUT_LABEL (asm_out_file, p2);
12071 /* We used to set the address register to the first location in the text
12072 section here, but that didn't accomplish anything since we already
12073 have a line note for the opening brace of the first function. */
12075 /* Generate the line number to PC correspondence table, encoded as
12076 a series of state machine operations. */
12080 if (cfun && in_cold_section_p)
12081 strcpy (prev_line_label, crtl->subsections.cold_section_label);
12083 strcpy (prev_line_label, text_section_label);
12084 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
12086 dw_line_info_ref line_info = &line_info_table[lt_index];
12089 /* Disable this optimization for now; GDB wants to see two line notes
12090 at the beginning of a function so it can find the end of the
12093 /* Don't emit anything for redundant notes. Just updating the
12094 address doesn't accomplish anything, because we already assume
12095 that anything after the last address is this line. */
12096 if (line_info->dw_line_num == current_line
12097 && line_info->dw_file_num == current_file)
12101 /* Emit debug info for the address of the current line.
12103 Unfortunately, we have little choice here currently, and must always
12104 use the most general form. GCC does not know the address delta
12105 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
12106 attributes which will give an upper bound on the address range. We
12107 could perhaps use length attributes to determine when it is safe to
12108 use DW_LNS_fixed_advance_pc. */
12110 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
12113 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
12114 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12115 "DW_LNS_fixed_advance_pc");
12116 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12120 /* This can handle any delta. This takes
12121 4+DWARF2_ADDR_SIZE bytes. */
12122 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12123 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12124 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12125 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12128 strcpy (prev_line_label, line_label);
12130 /* Emit debug info for the source file of the current line, if
12131 different from the previous line. */
12132 if (line_info->dw_file_num != current_file)
12134 current_file = line_info->dw_file_num;
12135 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
12136 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
12139 /* Emit debug info for the current line number, choosing the encoding
12140 that uses the least amount of space. */
12141 if (line_info->dw_line_num != current_line)
12143 line_offset = line_info->dw_line_num - current_line;
12144 line_delta = line_offset - DWARF_LINE_BASE;
12145 current_line = line_info->dw_line_num;
12146 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12147 /* This can handle deltas from -10 to 234, using the current
12148 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
12150 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12151 "line %lu", current_line);
12154 /* This can handle any delta. This takes at least 4 bytes,
12155 depending on the value being encoded. */
12156 dw2_asm_output_data (1, DW_LNS_advance_line,
12157 "advance to line %lu", current_line);
12158 dw2_asm_output_data_sleb128 (line_offset, NULL);
12159 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12163 /* We still need to start a new row, so output a copy insn. */
12164 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12167 /* Emit debug info for the address of the end of the function. */
12170 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12171 "DW_LNS_fixed_advance_pc");
12172 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
12176 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12177 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12178 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12179 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
12182 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12183 dw2_asm_output_data_uleb128 (1, NULL);
12184 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12189 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
12191 dw_separate_line_info_ref line_info
12192 = &separate_line_info_table[lt_index];
12195 /* Don't emit anything for redundant notes. */
12196 if (line_info->dw_line_num == current_line
12197 && line_info->dw_file_num == current_file
12198 && line_info->function == function)
12202 /* Emit debug info for the address of the current line. If this is
12203 a new function, or the first line of a function, then we need
12204 to handle it differently. */
12205 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
12207 if (function != line_info->function)
12209 function = line_info->function;
12211 /* Set the address register to the first line in the function. */
12212 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12213 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12214 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12215 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12219 /* ??? See the DW_LNS_advance_pc comment above. */
12222 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12223 "DW_LNS_fixed_advance_pc");
12224 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12228 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12229 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12230 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12231 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12235 strcpy (prev_line_label, line_label);
12237 /* Emit debug info for the source file of the current line, if
12238 different from the previous line. */
12239 if (line_info->dw_file_num != current_file)
12241 current_file = line_info->dw_file_num;
12242 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
12243 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
12246 /* Emit debug info for the current line number, choosing the encoding
12247 that uses the least amount of space. */
12248 if (line_info->dw_line_num != current_line)
12250 line_offset = line_info->dw_line_num - current_line;
12251 line_delta = line_offset - DWARF_LINE_BASE;
12252 current_line = line_info->dw_line_num;
12253 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12254 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12255 "line %lu", current_line);
12258 dw2_asm_output_data (1, DW_LNS_advance_line,
12259 "advance to line %lu", current_line);
12260 dw2_asm_output_data_sleb128 (line_offset, NULL);
12261 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12265 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12273 /* If we're done with a function, end its sequence. */
12274 if (lt_index == separate_line_info_table_in_use
12275 || separate_line_info_table[lt_index].function != function)
12280 /* Emit debug info for the address of the end of the function. */
12281 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
12284 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12285 "DW_LNS_fixed_advance_pc");
12286 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12290 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12291 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12292 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12293 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12296 /* Output the marker for the end of this sequence. */
12297 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12298 dw2_asm_output_data_uleb128 (1, NULL);
12299 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12303 /* Output the marker for the end of the line number info. */
12304 ASM_OUTPUT_LABEL (asm_out_file, l2);
12307 /* Return the size of the .debug_dcall table for the compilation unit. */
12309 static unsigned long
12310 size_of_dcall_table (void)
12312 unsigned long size;
12315 tree last_poc_decl = NULL;
12317 /* Header: version + debug info section pointer + pointer size. */
12318 size = 2 + DWARF_OFFSET_SIZE + 1;
12320 /* Each entry: code label + DIE offset. */
12321 FOR_EACH_VEC_ELT (dcall_entry, dcall_table, i, p)
12323 gcc_assert (p->targ_die != NULL);
12324 /* Insert a "from" entry when the point-of-call DIE offset changes. */
12325 if (p->poc_decl != last_poc_decl)
12327 dw_die_ref poc_die = lookup_decl_die (p->poc_decl);
12328 gcc_assert (poc_die);
12329 last_poc_decl = p->poc_decl;
12331 size += (DWARF_OFFSET_SIZE
12332 + size_of_uleb128 (poc_die->die_offset));
12334 size += DWARF_OFFSET_SIZE + size_of_uleb128 (p->targ_die->die_offset);
12340 /* Output the direct call table used to disambiguate PC values when
12341 identical function have been merged. */
12344 output_dcall_table (void)
12347 unsigned long dcall_length = size_of_dcall_table ();
12349 char poc_label[MAX_ARTIFICIAL_LABEL_BYTES];
12350 tree last_poc_decl = NULL;
12352 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12353 dw2_asm_output_data (4, 0xffffffff,
12354 "Initial length escape value indicating 64-bit DWARF extension");
12355 dw2_asm_output_data (DWARF_OFFSET_SIZE, dcall_length,
12356 "Length of Direct Call Table");
12357 dw2_asm_output_data (2, 4, "Version number");
12358 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
12359 debug_info_section,
12360 "Offset of Compilation Unit Info");
12361 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
12363 FOR_EACH_VEC_ELT (dcall_entry, dcall_table, i, p)
12365 /* Insert a "from" entry when the point-of-call DIE offset changes. */
12366 if (p->poc_decl != last_poc_decl)
12368 dw_die_ref poc_die = lookup_decl_die (p->poc_decl);
12369 last_poc_decl = p->poc_decl;
12372 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, "New caller");
12373 dw2_asm_output_data_uleb128 (poc_die->die_offset,
12374 "Caller DIE offset");
12377 ASM_GENERATE_INTERNAL_LABEL (poc_label, "LPOC", p->poc_label_num);
12378 dw2_asm_output_addr (DWARF_OFFSET_SIZE, poc_label, "Point of call");
12379 dw2_asm_output_data_uleb128 (p->targ_die->die_offset,
12380 "Callee DIE offset");
12384 /* Return the size of the .debug_vcall table for the compilation unit. */
12386 static unsigned long
12387 size_of_vcall_table (void)
12389 unsigned long size;
12393 /* Header: version + pointer size. */
12396 /* Each entry: code label + vtable slot index. */
12397 FOR_EACH_VEC_ELT (vcall_entry, vcall_table, i, p)
12398 size += DWARF_OFFSET_SIZE + size_of_uleb128 (p->vtable_slot);
12403 /* Output the virtual call table used to disambiguate PC values when
12404 identical function have been merged. */
12407 output_vcall_table (void)
12410 unsigned long vcall_length = size_of_vcall_table ();
12412 char poc_label[MAX_ARTIFICIAL_LABEL_BYTES];
12414 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12415 dw2_asm_output_data (4, 0xffffffff,
12416 "Initial length escape value indicating 64-bit DWARF extension");
12417 dw2_asm_output_data (DWARF_OFFSET_SIZE, vcall_length,
12418 "Length of Virtual Call Table");
12419 dw2_asm_output_data (2, 4, "Version number");
12420 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
12422 FOR_EACH_VEC_ELT (vcall_entry, vcall_table, i, p)
12424 ASM_GENERATE_INTERNAL_LABEL (poc_label, "LPOC", p->poc_label_num);
12425 dw2_asm_output_addr (DWARF_OFFSET_SIZE, poc_label, "Point of call");
12426 dw2_asm_output_data_uleb128 (p->vtable_slot, "Vtable slot");
12430 /* Given a pointer to a tree node for some base type, return a pointer to
12431 a DIE that describes the given type.
12433 This routine must only be called for GCC type nodes that correspond to
12434 Dwarf base (fundamental) types. */
12437 base_type_die (tree type)
12439 dw_die_ref base_type_result;
12440 enum dwarf_type encoding;
12442 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
12445 /* If this is a subtype that should not be emitted as a subrange type,
12446 use the base type. See subrange_type_for_debug_p. */
12447 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
12448 type = TREE_TYPE (type);
12450 switch (TREE_CODE (type))
12453 if ((dwarf_version >= 4 || !dwarf_strict)
12454 && TYPE_NAME (type)
12455 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12456 && DECL_IS_BUILTIN (TYPE_NAME (type))
12457 && DECL_NAME (TYPE_NAME (type)))
12459 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
12460 if (strcmp (name, "char16_t") == 0
12461 || strcmp (name, "char32_t") == 0)
12463 encoding = DW_ATE_UTF;
12467 if (TYPE_STRING_FLAG (type))
12469 if (TYPE_UNSIGNED (type))
12470 encoding = DW_ATE_unsigned_char;
12472 encoding = DW_ATE_signed_char;
12474 else if (TYPE_UNSIGNED (type))
12475 encoding = DW_ATE_unsigned;
12477 encoding = DW_ATE_signed;
12481 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
12483 if (dwarf_version >= 3 || !dwarf_strict)
12484 encoding = DW_ATE_decimal_float;
12486 encoding = DW_ATE_lo_user;
12489 encoding = DW_ATE_float;
12492 case FIXED_POINT_TYPE:
12493 if (!(dwarf_version >= 3 || !dwarf_strict))
12494 encoding = DW_ATE_lo_user;
12495 else if (TYPE_UNSIGNED (type))
12496 encoding = DW_ATE_unsigned_fixed;
12498 encoding = DW_ATE_signed_fixed;
12501 /* Dwarf2 doesn't know anything about complex ints, so use
12502 a user defined type for it. */
12504 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
12505 encoding = DW_ATE_complex_float;
12507 encoding = DW_ATE_lo_user;
12511 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12512 encoding = DW_ATE_boolean;
12516 /* No other TREE_CODEs are Dwarf fundamental types. */
12517 gcc_unreachable ();
12520 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
12522 add_AT_unsigned (base_type_result, DW_AT_byte_size,
12523 int_size_in_bytes (type));
12524 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
12526 return base_type_result;
12529 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12530 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12533 is_base_type (tree type)
12535 switch (TREE_CODE (type))
12541 case FIXED_POINT_TYPE:
12549 case QUAL_UNION_TYPE:
12550 case ENUMERAL_TYPE:
12551 case FUNCTION_TYPE:
12554 case REFERENCE_TYPE:
12561 gcc_unreachable ();
12567 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12568 node, return the size in bits for the type if it is a constant, or else
12569 return the alignment for the type if the type's size is not constant, or
12570 else return BITS_PER_WORD if the type actually turns out to be an
12571 ERROR_MARK node. */
12573 static inline unsigned HOST_WIDE_INT
12574 simple_type_size_in_bits (const_tree type)
12576 if (TREE_CODE (type) == ERROR_MARK)
12577 return BITS_PER_WORD;
12578 else if (TYPE_SIZE (type) == NULL_TREE)
12580 else if (host_integerp (TYPE_SIZE (type), 1))
12581 return tree_low_cst (TYPE_SIZE (type), 1);
12583 return TYPE_ALIGN (type);
12586 /* Similarly, but return a double_int instead of UHWI. */
12588 static inline double_int
12589 double_int_type_size_in_bits (const_tree type)
12591 if (TREE_CODE (type) == ERROR_MARK)
12592 return uhwi_to_double_int (BITS_PER_WORD);
12593 else if (TYPE_SIZE (type) == NULL_TREE)
12594 return double_int_zero;
12595 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
12596 return tree_to_double_int (TYPE_SIZE (type));
12598 return uhwi_to_double_int (TYPE_ALIGN (type));
12601 /* Given a pointer to a tree node for a subrange type, return a pointer
12602 to a DIE that describes the given type. */
12605 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
12607 dw_die_ref subrange_die;
12608 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
12610 if (context_die == NULL)
12611 context_die = comp_unit_die;
12613 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
12615 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
12617 /* The size of the subrange type and its base type do not match,
12618 so we need to generate a size attribute for the subrange type. */
12619 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
12623 add_bound_info (subrange_die, DW_AT_lower_bound, low);
12625 add_bound_info (subrange_die, DW_AT_upper_bound, high);
12627 return subrange_die;
12630 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12631 entry that chains various modifiers in front of the given type. */
12634 modified_type_die (tree type, int is_const_type, int is_volatile_type,
12635 dw_die_ref context_die)
12637 enum tree_code code = TREE_CODE (type);
12638 dw_die_ref mod_type_die;
12639 dw_die_ref sub_die = NULL;
12640 tree item_type = NULL;
12641 tree qualified_type;
12642 tree name, low, high;
12644 if (code == ERROR_MARK)
12647 /* See if we already have the appropriately qualified variant of
12650 = get_qualified_type (type,
12651 ((is_const_type ? TYPE_QUAL_CONST : 0)
12652 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
12654 if (qualified_type == sizetype
12655 && TYPE_NAME (qualified_type)
12656 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
12658 #ifdef ENABLE_CHECKING
12659 gcc_assert (TREE_CODE (TREE_TYPE (TYPE_NAME (qualified_type)))
12661 && TYPE_PRECISION (TREE_TYPE (TYPE_NAME (qualified_type)))
12662 == TYPE_PRECISION (qualified_type)
12663 && TYPE_UNSIGNED (TREE_TYPE (TYPE_NAME (qualified_type)))
12664 == TYPE_UNSIGNED (qualified_type));
12666 qualified_type = TREE_TYPE (TYPE_NAME (qualified_type));
12669 /* If we do, then we can just use its DIE, if it exists. */
12670 if (qualified_type)
12672 mod_type_die = lookup_type_die (qualified_type);
12674 return mod_type_die;
12677 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
12679 /* Handle C typedef types. */
12680 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
12681 && !DECL_ARTIFICIAL (name))
12683 tree dtype = TREE_TYPE (name);
12685 if (qualified_type == dtype)
12687 /* For a named type, use the typedef. */
12688 gen_type_die (qualified_type, context_die);
12689 return lookup_type_die (qualified_type);
12691 else if (is_const_type < TYPE_READONLY (dtype)
12692 || is_volatile_type < TYPE_VOLATILE (dtype)
12693 || (is_const_type <= TYPE_READONLY (dtype)
12694 && is_volatile_type <= TYPE_VOLATILE (dtype)
12695 && DECL_ORIGINAL_TYPE (name) != type))
12696 /* cv-unqualified version of named type. Just use the unnamed
12697 type to which it refers. */
12698 return modified_type_die (DECL_ORIGINAL_TYPE (name),
12699 is_const_type, is_volatile_type,
12701 /* Else cv-qualified version of named type; fall through. */
12706 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
12707 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
12709 else if (is_volatile_type)
12711 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
12712 sub_die = modified_type_die (type, 0, 0, context_die);
12714 else if (code == POINTER_TYPE)
12716 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
12717 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
12718 simple_type_size_in_bits (type) / BITS_PER_UNIT);
12719 item_type = TREE_TYPE (type);
12720 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
12721 add_AT_unsigned (mod_type_die, DW_AT_address_class,
12722 TYPE_ADDR_SPACE (item_type));
12724 else if (code == REFERENCE_TYPE)
12726 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
12727 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die,
12730 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
12731 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
12732 simple_type_size_in_bits (type) / BITS_PER_UNIT);
12733 item_type = TREE_TYPE (type);
12734 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
12735 add_AT_unsigned (mod_type_die, DW_AT_address_class,
12736 TYPE_ADDR_SPACE (item_type));
12738 else if (code == INTEGER_TYPE
12739 && TREE_TYPE (type) != NULL_TREE
12740 && subrange_type_for_debug_p (type, &low, &high))
12742 mod_type_die = subrange_type_die (type, low, high, context_die);
12743 item_type = TREE_TYPE (type);
12745 else if (is_base_type (type))
12746 mod_type_die = base_type_die (type);
12749 gen_type_die (type, context_die);
12751 /* We have to get the type_main_variant here (and pass that to the
12752 `lookup_type_die' routine) because the ..._TYPE node we have
12753 might simply be a *copy* of some original type node (where the
12754 copy was created to help us keep track of typedef names) and
12755 that copy might have a different TYPE_UID from the original
12757 if (TREE_CODE (type) != VECTOR_TYPE)
12758 return lookup_type_die (type_main_variant (type));
12760 /* Vectors have the debugging information in the type,
12761 not the main variant. */
12762 return lookup_type_die (type);
12765 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
12766 don't output a DW_TAG_typedef, since there isn't one in the
12767 user's program; just attach a DW_AT_name to the type.
12768 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
12769 if the base type already has the same name. */
12771 && ((TREE_CODE (name) != TYPE_DECL
12772 && (qualified_type == TYPE_MAIN_VARIANT (type)
12773 || (!is_const_type && !is_volatile_type)))
12774 || (TREE_CODE (name) == TYPE_DECL
12775 && TREE_TYPE (name) == qualified_type
12776 && DECL_NAME (name))))
12778 if (TREE_CODE (name) == TYPE_DECL)
12779 /* Could just call add_name_and_src_coords_attributes here,
12780 but since this is a builtin type it doesn't have any
12781 useful source coordinates anyway. */
12782 name = DECL_NAME (name);
12783 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
12785 /* This probably indicates a bug. */
12786 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
12787 add_name_attribute (mod_type_die, "__unknown__");
12789 if (qualified_type)
12790 equate_type_number_to_die (qualified_type, mod_type_die);
12793 /* We must do this after the equate_type_number_to_die call, in case
12794 this is a recursive type. This ensures that the modified_type_die
12795 recursion will terminate even if the type is recursive. Recursive
12796 types are possible in Ada. */
12797 sub_die = modified_type_die (item_type,
12798 TYPE_READONLY (item_type),
12799 TYPE_VOLATILE (item_type),
12802 if (sub_die != NULL)
12803 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
12805 return mod_type_die;
12808 /* Generate DIEs for the generic parameters of T.
12809 T must be either a generic type or a generic function.
12810 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
12813 gen_generic_params_dies (tree t)
12817 dw_die_ref die = NULL;
12819 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
12823 die = lookup_type_die (t);
12824 else if (DECL_P (t))
12825 die = lookup_decl_die (t);
12829 parms = lang_hooks.get_innermost_generic_parms (t);
12831 /* T has no generic parameter. It means T is neither a generic type
12832 or function. End of story. */
12835 parms_num = TREE_VEC_LENGTH (parms);
12836 args = lang_hooks.get_innermost_generic_args (t);
12837 for (i = 0; i < parms_num; i++)
12839 tree parm, arg, arg_pack_elems;
12841 parm = TREE_VEC_ELT (parms, i);
12842 arg = TREE_VEC_ELT (args, i);
12843 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
12844 gcc_assert (parm && TREE_VALUE (parm) && arg);
12846 if (parm && TREE_VALUE (parm) && arg)
12848 /* If PARM represents a template parameter pack,
12849 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
12850 by DW_TAG_template_*_parameter DIEs for the argument
12851 pack elements of ARG. Note that ARG would then be
12852 an argument pack. */
12853 if (arg_pack_elems)
12854 template_parameter_pack_die (TREE_VALUE (parm),
12858 generic_parameter_die (TREE_VALUE (parm), arg,
12859 true /* Emit DW_AT_name */, die);
12864 /* Create and return a DIE for PARM which should be
12865 the representation of a generic type parameter.
12866 For instance, in the C++ front end, PARM would be a template parameter.
12867 ARG is the argument to PARM.
12868 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
12870 PARENT_DIE is the parent DIE which the new created DIE should be added to,
12871 as a child node. */
12874 generic_parameter_die (tree parm, tree arg,
12876 dw_die_ref parent_die)
12878 dw_die_ref tmpl_die = NULL;
12879 const char *name = NULL;
12881 if (!parm || !DECL_NAME (parm) || !arg)
12884 /* We support non-type generic parameters and arguments,
12885 type generic parameters and arguments, as well as
12886 generic generic parameters (a.k.a. template template parameters in C++)
12888 if (TREE_CODE (parm) == PARM_DECL)
12889 /* PARM is a nontype generic parameter */
12890 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
12891 else if (TREE_CODE (parm) == TYPE_DECL)
12892 /* PARM is a type generic parameter. */
12893 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
12894 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
12895 /* PARM is a generic generic parameter.
12896 Its DIE is a GNU extension. It shall have a
12897 DW_AT_name attribute to represent the name of the template template
12898 parameter, and a DW_AT_GNU_template_name attribute to represent the
12899 name of the template template argument. */
12900 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
12903 gcc_unreachable ();
12909 /* If PARM is a generic parameter pack, it means we are
12910 emitting debug info for a template argument pack element.
12911 In other terms, ARG is a template argument pack element.
12912 In that case, we don't emit any DW_AT_name attribute for
12916 name = IDENTIFIER_POINTER (DECL_NAME (parm));
12918 add_AT_string (tmpl_die, DW_AT_name, name);
12921 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
12923 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
12924 TMPL_DIE should have a child DW_AT_type attribute that is set
12925 to the type of the argument to PARM, which is ARG.
12926 If PARM is a type generic parameter, TMPL_DIE should have a
12927 child DW_AT_type that is set to ARG. */
12928 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
12929 add_type_attribute (tmpl_die, tmpl_type, 0,
12930 TREE_THIS_VOLATILE (tmpl_type),
12935 /* So TMPL_DIE is a DIE representing a
12936 a generic generic template parameter, a.k.a template template
12937 parameter in C++ and arg is a template. */
12939 /* The DW_AT_GNU_template_name attribute of the DIE must be set
12940 to the name of the argument. */
12941 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
12943 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
12946 if (TREE_CODE (parm) == PARM_DECL)
12947 /* So PARM is a non-type generic parameter.
12948 DWARF3 5.6.8 says we must set a DW_AT_const_value child
12949 attribute of TMPL_DIE which value represents the value
12951 We must be careful here:
12952 The value of ARG might reference some function decls.
12953 We might currently be emitting debug info for a generic
12954 type and types are emitted before function decls, we don't
12955 know if the function decls referenced by ARG will actually be
12956 emitted after cgraph computations.
12957 So must defer the generation of the DW_AT_const_value to
12958 after cgraph is ready. */
12959 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
12965 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
12966 PARM_PACK must be a template parameter pack. The returned DIE
12967 will be child DIE of PARENT_DIE. */
12970 template_parameter_pack_die (tree parm_pack,
12971 tree parm_pack_args,
12972 dw_die_ref parent_die)
12977 gcc_assert (parent_die && parm_pack);
12979 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
12980 add_name_and_src_coords_attributes (die, parm_pack);
12981 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
12982 generic_parameter_die (parm_pack,
12983 TREE_VEC_ELT (parm_pack_args, j),
12984 false /* Don't emit DW_AT_name */,
12989 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
12990 an enumerated type. */
12993 type_is_enum (const_tree type)
12995 return TREE_CODE (type) == ENUMERAL_TYPE;
12998 /* Return the DBX register number described by a given RTL node. */
13000 static unsigned int
13001 dbx_reg_number (const_rtx rtl)
13003 unsigned regno = REGNO (rtl);
13005 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
13007 #ifdef LEAF_REG_REMAP
13008 if (current_function_uses_only_leaf_regs)
13010 int leaf_reg = LEAF_REG_REMAP (regno);
13011 if (leaf_reg != -1)
13012 regno = (unsigned) leaf_reg;
13016 return DBX_REGISTER_NUMBER (regno);
13019 /* Optionally add a DW_OP_piece term to a location description expression.
13020 DW_OP_piece is only added if the location description expression already
13021 doesn't end with DW_OP_piece. */
13024 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
13026 dw_loc_descr_ref loc;
13028 if (*list_head != NULL)
13030 /* Find the end of the chain. */
13031 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
13034 if (loc->dw_loc_opc != DW_OP_piece)
13035 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
13039 /* Return a location descriptor that designates a machine register or
13040 zero if there is none. */
13042 static dw_loc_descr_ref
13043 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
13047 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
13050 /* We only use "frame base" when we're sure we're talking about the
13051 post-prologue local stack frame. We do this by *not* running
13052 register elimination until this point, and recognizing the special
13053 argument pointer and soft frame pointer rtx's.
13054 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13055 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
13056 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
13058 dw_loc_descr_ref result = NULL;
13060 if (dwarf_version >= 4 || !dwarf_strict)
13062 result = mem_loc_descriptor (rtl, VOIDmode, initialized);
13064 add_loc_descr (&result,
13065 new_loc_descr (DW_OP_stack_value, 0, 0));
13070 regs = targetm.dwarf_register_span (rtl);
13072 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
13073 return multiple_reg_loc_descriptor (rtl, regs, initialized);
13075 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
13078 /* Return a location descriptor that designates a machine register for
13079 a given hard register number. */
13081 static dw_loc_descr_ref
13082 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
13084 dw_loc_descr_ref reg_loc_descr;
13088 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
13090 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
13092 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13093 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13095 return reg_loc_descr;
13098 /* Given an RTL of a register, return a location descriptor that
13099 designates a value that spans more than one register. */
13101 static dw_loc_descr_ref
13102 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
13103 enum var_init_status initialized)
13105 int nregs, size, i;
13107 dw_loc_descr_ref loc_result = NULL;
13110 #ifdef LEAF_REG_REMAP
13111 if (current_function_uses_only_leaf_regs)
13113 int leaf_reg = LEAF_REG_REMAP (reg);
13114 if (leaf_reg != -1)
13115 reg = (unsigned) leaf_reg;
13118 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
13119 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
13121 /* Simple, contiguous registers. */
13122 if (regs == NULL_RTX)
13124 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
13129 dw_loc_descr_ref t;
13131 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
13132 VAR_INIT_STATUS_INITIALIZED);
13133 add_loc_descr (&loc_result, t);
13134 add_loc_descr_op_piece (&loc_result, size);
13140 /* Now onto stupid register sets in non contiguous locations. */
13142 gcc_assert (GET_CODE (regs) == PARALLEL);
13144 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13147 for (i = 0; i < XVECLEN (regs, 0); ++i)
13149 dw_loc_descr_ref t;
13151 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
13152 VAR_INIT_STATUS_INITIALIZED);
13153 add_loc_descr (&loc_result, t);
13154 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13155 add_loc_descr_op_piece (&loc_result, size);
13158 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
13159 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13163 /* Return a location descriptor that designates a constant. */
13165 static dw_loc_descr_ref
13166 int_loc_descriptor (HOST_WIDE_INT i)
13168 enum dwarf_location_atom op;
13170 /* Pick the smallest representation of a constant, rather than just
13171 defaulting to the LEB encoding. */
13175 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
13176 else if (i <= 0xff)
13177 op = DW_OP_const1u;
13178 else if (i <= 0xffff)
13179 op = DW_OP_const2u;
13180 else if (HOST_BITS_PER_WIDE_INT == 32
13181 || i <= 0xffffffff)
13182 op = DW_OP_const4u;
13189 op = DW_OP_const1s;
13190 else if (i >= -0x8000)
13191 op = DW_OP_const2s;
13192 else if (HOST_BITS_PER_WIDE_INT == 32
13193 || i >= -0x80000000)
13194 op = DW_OP_const4s;
13199 return new_loc_descr (op, i, 0);
13202 /* Return loc description representing "address" of integer value.
13203 This can appear only as toplevel expression. */
13205 static dw_loc_descr_ref
13206 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
13209 dw_loc_descr_ref loc_result = NULL;
13211 if (!(dwarf_version >= 4 || !dwarf_strict))
13218 else if (i <= 0xff)
13220 else if (i <= 0xffff)
13222 else if (HOST_BITS_PER_WIDE_INT == 32
13223 || i <= 0xffffffff)
13226 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
13232 else if (i >= -0x8000)
13234 else if (HOST_BITS_PER_WIDE_INT == 32
13235 || i >= -0x80000000)
13238 litsize = 1 + size_of_sleb128 (i);
13240 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13241 is more compact. For DW_OP_stack_value we need:
13242 litsize + 1 (DW_OP_stack_value)
13243 and for DW_OP_implicit_value:
13244 1 (DW_OP_implicit_value) + 1 (length) + size. */
13245 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
13247 loc_result = int_loc_descriptor (i);
13248 add_loc_descr (&loc_result,
13249 new_loc_descr (DW_OP_stack_value, 0, 0));
13253 loc_result = new_loc_descr (DW_OP_implicit_value,
13255 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
13256 loc_result->dw_loc_oprnd2.v.val_int = i;
13260 /* Return a location descriptor that designates a base+offset location. */
13262 static dw_loc_descr_ref
13263 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
13264 enum var_init_status initialized)
13266 unsigned int regno;
13267 dw_loc_descr_ref result;
13268 dw_fde_ref fde = current_fde ();
13270 /* We only use "frame base" when we're sure we're talking about the
13271 post-prologue local stack frame. We do this by *not* running
13272 register elimination until this point, and recognizing the special
13273 argument pointer and soft frame pointer rtx's. */
13274 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
13276 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
13280 if (GET_CODE (elim) == PLUS)
13282 offset += INTVAL (XEXP (elim, 1));
13283 elim = XEXP (elim, 0);
13285 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13286 && (elim == hard_frame_pointer_rtx
13287 || elim == stack_pointer_rtx))
13288 || elim == (frame_pointer_needed
13289 ? hard_frame_pointer_rtx
13290 : stack_pointer_rtx));
13292 /* If drap register is used to align stack, use frame
13293 pointer + offset to access stack variables. If stack
13294 is aligned without drap, use stack pointer + offset to
13295 access stack variables. */
13296 if (crtl->stack_realign_tried
13297 && reg == frame_pointer_rtx)
13300 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
13301 ? HARD_FRAME_POINTER_REGNUM
13302 : STACK_POINTER_REGNUM);
13303 return new_reg_loc_descr (base_reg, offset);
13306 offset += frame_pointer_fb_offset;
13307 return new_loc_descr (DW_OP_fbreg, offset, 0);
13312 && (fde->drap_reg == REGNO (reg)
13313 || fde->vdrap_reg == REGNO (reg)))
13315 /* Use cfa+offset to represent the location of arguments passed
13316 on the stack when drap is used to align stack.
13317 Only do this when not optimizing, for optimized code var-tracking
13318 is supposed to track where the arguments live and the register
13319 used as vdrap or drap in some spot might be used for something
13320 else in other part of the routine. */
13321 return new_loc_descr (DW_OP_fbreg, offset, 0);
13324 regno = dbx_reg_number (reg);
13326 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
13329 result = new_loc_descr (DW_OP_bregx, regno, offset);
13331 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13332 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13337 /* Return true if this RTL expression describes a base+offset calculation. */
13340 is_based_loc (const_rtx rtl)
13342 return (GET_CODE (rtl) == PLUS
13343 && ((REG_P (XEXP (rtl, 0))
13344 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
13345 && CONST_INT_P (XEXP (rtl, 1)))));
13348 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13351 static dw_loc_descr_ref
13352 tls_mem_loc_descriptor (rtx mem)
13355 dw_loc_descr_ref loc_result;
13357 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
13360 base = get_base_address (MEM_EXPR (mem));
13362 || TREE_CODE (base) != VAR_DECL
13363 || !DECL_THREAD_LOCAL_P (base))
13366 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
13367 if (loc_result == NULL)
13370 if (INTVAL (MEM_OFFSET (mem)))
13371 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
13376 /* Output debug info about reason why we failed to expand expression as dwarf
13380 expansion_failed (tree expr, rtx rtl, char const *reason)
13382 if (dump_file && (dump_flags & TDF_DETAILS))
13384 fprintf (dump_file, "Failed to expand as dwarf: ");
13386 print_generic_expr (dump_file, expr, dump_flags);
13389 fprintf (dump_file, "\n");
13390 print_rtl (dump_file, rtl);
13392 fprintf (dump_file, "\nReason: %s\n", reason);
13396 /* Helper function for const_ok_for_output, called either directly
13397 or via for_each_rtx. */
13400 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
13404 if (GET_CODE (rtl) == UNSPEC)
13406 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13407 we can't express it in the debug info. */
13408 #ifdef ENABLE_CHECKING
13409 inform (current_function_decl
13410 ? DECL_SOURCE_LOCATION (current_function_decl)
13411 : UNKNOWN_LOCATION,
13412 "non-delegitimized UNSPEC %d found in variable location",
13415 expansion_failed (NULL_TREE, rtl,
13416 "UNSPEC hasn't been delegitimized.\n");
13420 if (GET_CODE (rtl) != SYMBOL_REF)
13423 if (CONSTANT_POOL_ADDRESS_P (rtl))
13426 get_pool_constant_mark (rtl, &marked);
13427 /* If all references to this pool constant were optimized away,
13428 it was not output and thus we can't represent it. */
13431 expansion_failed (NULL_TREE, rtl,
13432 "Constant was removed from constant pool.\n");
13437 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13440 /* Avoid references to external symbols in debug info, on several targets
13441 the linker might even refuse to link when linking a shared library,
13442 and in many other cases the relocations for .debug_info/.debug_loc are
13443 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13444 to be defined within the same shared library or executable are fine. */
13445 if (SYMBOL_REF_EXTERNAL_P (rtl))
13447 tree decl = SYMBOL_REF_DECL (rtl);
13449 if (decl == NULL || !targetm.binds_local_p (decl))
13451 expansion_failed (NULL_TREE, rtl,
13452 "Symbol not defined in current TU.\n");
13460 /* Return true if constant RTL can be emitted in DW_OP_addr or
13461 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13462 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13465 const_ok_for_output (rtx rtl)
13467 if (GET_CODE (rtl) == SYMBOL_REF)
13468 return const_ok_for_output_1 (&rtl, NULL) == 0;
13470 if (GET_CODE (rtl) == CONST)
13471 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
13476 /* The following routine converts the RTL for a variable or parameter
13477 (resident in memory) into an equivalent Dwarf representation of a
13478 mechanism for getting the address of that same variable onto the top of a
13479 hypothetical "address evaluation" stack.
13481 When creating memory location descriptors, we are effectively transforming
13482 the RTL for a memory-resident object into its Dwarf postfix expression
13483 equivalent. This routine recursively descends an RTL tree, turning
13484 it into Dwarf postfix code as it goes.
13486 MODE is the mode of the memory reference, needed to handle some
13487 autoincrement addressing modes.
13489 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
13490 location list for RTL.
13492 Return 0 if we can't represent the location. */
13494 static dw_loc_descr_ref
13495 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
13496 enum var_init_status initialized)
13498 dw_loc_descr_ref mem_loc_result = NULL;
13499 enum dwarf_location_atom op;
13500 dw_loc_descr_ref op0, op1;
13502 /* Note that for a dynamically sized array, the location we will generate a
13503 description of here will be the lowest numbered location which is
13504 actually within the array. That's *not* necessarily the same as the
13505 zeroth element of the array. */
13507 rtl = targetm.delegitimize_address (rtl);
13509 switch (GET_CODE (rtl))
13514 return mem_loc_descriptor (XEXP (rtl, 0), mode, initialized);
13517 /* The case of a subreg may arise when we have a local (register)
13518 variable or a formal (register) parameter which doesn't quite fill
13519 up an entire register. For now, just assume that it is
13520 legitimate to make the Dwarf info refer to the whole register which
13521 contains the given subreg. */
13522 if (!subreg_lowpart_p (rtl))
13524 rtl = SUBREG_REG (rtl);
13525 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13527 if (GET_MODE_CLASS (GET_MODE (rtl)) != MODE_INT)
13529 mem_loc_result = mem_loc_descriptor (rtl, mode, initialized);
13533 /* Whenever a register number forms a part of the description of the
13534 method for calculating the (dynamic) address of a memory resident
13535 object, DWARF rules require the register number be referred to as
13536 a "base register". This distinction is not based in any way upon
13537 what category of register the hardware believes the given register
13538 belongs to. This is strictly DWARF terminology we're dealing with
13539 here. Note that in cases where the location of a memory-resident
13540 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
13541 OP_CONST (0)) the actual DWARF location descriptor that we generate
13542 may just be OP_BASEREG (basereg). This may look deceptively like
13543 the object in question was allocated to a register (rather than in
13544 memory) so DWARF consumers need to be aware of the subtle
13545 distinction between OP_REG and OP_BASEREG. */
13546 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
13547 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
13548 else if (stack_realign_drap
13550 && crtl->args.internal_arg_pointer == rtl
13551 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
13553 /* If RTL is internal_arg_pointer, which has been optimized
13554 out, use DRAP instead. */
13555 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
13556 VAR_INIT_STATUS_INITIALIZED);
13562 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13563 VAR_INIT_STATUS_INITIALIZED);
13568 int shift = DWARF2_ADDR_SIZE
13569 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
13570 shift *= BITS_PER_UNIT;
13571 if (GET_CODE (rtl) == SIGN_EXTEND)
13575 mem_loc_result = op0;
13576 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13577 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
13578 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13579 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13584 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
13585 VAR_INIT_STATUS_INITIALIZED);
13586 if (mem_loc_result == NULL)
13587 mem_loc_result = tls_mem_loc_descriptor (rtl);
13588 if (mem_loc_result != 0)
13590 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13592 expansion_failed (NULL_TREE, rtl, "DWARF address size mismatch");
13595 else if (GET_MODE_SIZE (GET_MODE (rtl)) == DWARF2_ADDR_SIZE)
13596 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
13598 add_loc_descr (&mem_loc_result,
13599 new_loc_descr (DW_OP_deref_size,
13600 GET_MODE_SIZE (GET_MODE (rtl)), 0));
13604 rtx new_rtl = avoid_constant_pool_reference (rtl);
13605 if (new_rtl != rtl)
13606 return mem_loc_descriptor (new_rtl, mode, initialized);
13611 rtl = XEXP (rtl, 1);
13613 /* ... fall through ... */
13616 /* Some ports can transform a symbol ref into a label ref, because
13617 the symbol ref is too far away and has to be dumped into a constant
13621 if (GET_CODE (rtl) == SYMBOL_REF
13622 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13624 dw_loc_descr_ref temp;
13626 /* If this is not defined, we have no way to emit the data. */
13627 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
13630 /* We used to emit DW_OP_addr here, but that's wrong, since
13631 DW_OP_addr should be relocated by the debug info consumer,
13632 while DW_OP_GNU_push_tls_address operand should not. */
13633 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
13634 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
13635 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
13636 temp->dw_loc_oprnd1.v.val_addr = rtl;
13637 temp->dtprel = true;
13639 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
13640 add_loc_descr (&mem_loc_result, temp);
13645 if (!const_ok_for_output (rtl))
13649 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
13650 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
13651 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
13652 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
13658 expansion_failed (NULL_TREE, rtl,
13659 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
13663 /* Extract the PLUS expression nested inside and fall into
13664 PLUS code below. */
13665 rtl = XEXP (rtl, 1);
13670 /* Turn these into a PLUS expression and fall into the PLUS code
13672 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
13673 GEN_INT (GET_CODE (rtl) == PRE_INC
13674 ? GET_MODE_UNIT_SIZE (mode)
13675 : -GET_MODE_UNIT_SIZE (mode)));
13677 /* ... fall through ... */
13681 if (is_based_loc (rtl))
13682 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
13683 INTVAL (XEXP (rtl, 1)),
13684 VAR_INIT_STATUS_INITIALIZED);
13687 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
13688 VAR_INIT_STATUS_INITIALIZED);
13689 if (mem_loc_result == 0)
13692 if (CONST_INT_P (XEXP (rtl, 1)))
13693 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
13696 dw_loc_descr_ref mem_loc_result2
13697 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13698 VAR_INIT_STATUS_INITIALIZED);
13699 if (mem_loc_result2 == 0)
13701 add_loc_descr (&mem_loc_result, mem_loc_result2);
13702 add_loc_descr (&mem_loc_result,
13703 new_loc_descr (DW_OP_plus, 0, 0));
13708 /* If a pseudo-reg is optimized away, it is possible for it to
13709 be replaced with a MEM containing a multiply or shift. */
13751 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13752 VAR_INIT_STATUS_INITIALIZED);
13753 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13754 VAR_INIT_STATUS_INITIALIZED);
13756 if (op0 == 0 || op1 == 0)
13759 mem_loc_result = op0;
13760 add_loc_descr (&mem_loc_result, op1);
13761 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13765 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13766 VAR_INIT_STATUS_INITIALIZED);
13767 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13768 VAR_INIT_STATUS_INITIALIZED);
13770 if (op0 == 0 || op1 == 0)
13773 mem_loc_result = op0;
13774 add_loc_descr (&mem_loc_result, op1);
13775 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
13776 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
13777 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
13778 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
13779 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
13795 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13796 VAR_INIT_STATUS_INITIALIZED);
13801 mem_loc_result = op0;
13802 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13806 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
13834 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
13835 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
13839 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
13841 if (op_mode == VOIDmode)
13842 op_mode = GET_MODE (XEXP (rtl, 1));
13843 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
13846 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13847 VAR_INIT_STATUS_INITIALIZED);
13848 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13849 VAR_INIT_STATUS_INITIALIZED);
13851 if (op0 == 0 || op1 == 0)
13854 if (op_mode != VOIDmode
13855 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
13857 int shift = DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode);
13858 shift *= BITS_PER_UNIT;
13859 /* For eq/ne, if the operands are known to be zero-extended,
13860 there is no need to do the fancy shifting up. */
13861 if (op == DW_OP_eq || op == DW_OP_ne)
13863 dw_loc_descr_ref last0, last1;
13865 last0->dw_loc_next != NULL;
13866 last0 = last0->dw_loc_next)
13869 last1->dw_loc_next != NULL;
13870 last1 = last1->dw_loc_next)
13872 /* deref_size zero extends, and for constants we can check
13873 whether they are zero extended or not. */
13874 if (((last0->dw_loc_opc == DW_OP_deref_size
13875 && last0->dw_loc_oprnd1.v.val_int
13876 <= GET_MODE_SIZE (op_mode))
13877 || (CONST_INT_P (XEXP (rtl, 0))
13878 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
13879 == (INTVAL (XEXP (rtl, 0))
13880 & GET_MODE_MASK (op_mode))))
13881 && ((last1->dw_loc_opc == DW_OP_deref_size
13882 && last1->dw_loc_oprnd1.v.val_int
13883 <= GET_MODE_SIZE (op_mode))
13884 || (CONST_INT_P (XEXP (rtl, 1))
13885 && (unsigned HOST_WIDE_INT)
13886 INTVAL (XEXP (rtl, 1))
13887 == (INTVAL (XEXP (rtl, 1))
13888 & GET_MODE_MASK (op_mode)))))
13891 add_loc_descr (&op0, int_loc_descriptor (shift));
13892 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
13893 if (CONST_INT_P (XEXP (rtl, 1)))
13894 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
13897 add_loc_descr (&op1, int_loc_descriptor (shift));
13898 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
13904 mem_loc_result = op0;
13905 add_loc_descr (&mem_loc_result, op1);
13906 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13907 if (STORE_FLAG_VALUE != 1)
13909 add_loc_descr (&mem_loc_result,
13910 int_loc_descriptor (STORE_FLAG_VALUE));
13911 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
13932 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
13933 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
13937 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
13939 if (op_mode == VOIDmode)
13940 op_mode = GET_MODE (XEXP (rtl, 1));
13941 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
13944 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13945 VAR_INIT_STATUS_INITIALIZED);
13946 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13947 VAR_INIT_STATUS_INITIALIZED);
13949 if (op0 == 0 || op1 == 0)
13952 if (op_mode != VOIDmode
13953 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
13955 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
13956 dw_loc_descr_ref last0, last1;
13958 last0->dw_loc_next != NULL;
13959 last0 = last0->dw_loc_next)
13962 last1->dw_loc_next != NULL;
13963 last1 = last1->dw_loc_next)
13965 if (CONST_INT_P (XEXP (rtl, 0)))
13966 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
13967 /* deref_size zero extends, so no need to mask it again. */
13968 else if (last0->dw_loc_opc != DW_OP_deref_size
13969 || last0->dw_loc_oprnd1.v.val_int
13970 > GET_MODE_SIZE (op_mode))
13972 add_loc_descr (&op0, int_loc_descriptor (mask));
13973 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
13975 if (CONST_INT_P (XEXP (rtl, 1)))
13976 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
13977 /* deref_size zero extends, so no need to mask it again. */
13978 else if (last1->dw_loc_opc != DW_OP_deref_size
13979 || last1->dw_loc_oprnd1.v.val_int
13980 > GET_MODE_SIZE (op_mode))
13982 add_loc_descr (&op1, int_loc_descriptor (mask));
13983 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
13988 HOST_WIDE_INT bias = 1;
13989 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
13990 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
13991 if (CONST_INT_P (XEXP (rtl, 1)))
13992 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
13993 + INTVAL (XEXP (rtl, 1)));
13995 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
14005 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
14006 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14007 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
14010 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14011 VAR_INIT_STATUS_INITIALIZED);
14012 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14013 VAR_INIT_STATUS_INITIALIZED);
14015 if (op0 == 0 || op1 == 0)
14018 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
14019 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
14020 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
14021 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
14023 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14025 HOST_WIDE_INT mask = GET_MODE_MASK (GET_MODE (XEXP (rtl, 0)));
14026 add_loc_descr (&op0, int_loc_descriptor (mask));
14027 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14028 add_loc_descr (&op1, int_loc_descriptor (mask));
14029 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14033 HOST_WIDE_INT bias = 1;
14034 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14035 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14036 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14039 else if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14041 int shift = DWARF2_ADDR_SIZE
14042 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
14043 shift *= BITS_PER_UNIT;
14044 add_loc_descr (&op0, int_loc_descriptor (shift));
14045 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14046 add_loc_descr (&op1, int_loc_descriptor (shift));
14047 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14050 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
14054 mem_loc_result = op0;
14055 add_loc_descr (&mem_loc_result, op1);
14056 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14058 dw_loc_descr_ref bra_node, drop_node;
14060 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14061 add_loc_descr (&mem_loc_result, bra_node);
14062 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14063 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14064 add_loc_descr (&mem_loc_result, drop_node);
14065 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14066 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14072 if (CONST_INT_P (XEXP (rtl, 1))
14073 && CONST_INT_P (XEXP (rtl, 2))
14074 && ((unsigned) INTVAL (XEXP (rtl, 1))
14075 + (unsigned) INTVAL (XEXP (rtl, 2))
14076 <= GET_MODE_BITSIZE (GET_MODE (rtl)))
14077 && GET_MODE_BITSIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14078 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
14081 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14082 VAR_INIT_STATUS_INITIALIZED);
14085 if (GET_CODE (rtl) == SIGN_EXTRACT)
14089 mem_loc_result = op0;
14090 size = INTVAL (XEXP (rtl, 1));
14091 shift = INTVAL (XEXP (rtl, 2));
14092 if (BITS_BIG_ENDIAN)
14093 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
14095 if (shift + size != (int) DWARF2_ADDR_SIZE)
14097 add_loc_descr (&mem_loc_result,
14098 int_loc_descriptor (DWARF2_ADDR_SIZE
14100 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
14102 if (size != (int) DWARF2_ADDR_SIZE)
14104 add_loc_descr (&mem_loc_result,
14105 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
14106 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14116 /* In theory, we could implement the above. */
14117 /* DWARF cannot represent the unsigned compare operations
14144 case FLOAT_TRUNCATE:
14146 case UNSIGNED_FLOAT:
14149 case FRACT_CONVERT:
14150 case UNSIGNED_FRACT_CONVERT:
14152 case UNSIGNED_SAT_FRACT:
14164 case VEC_DUPLICATE:
14167 /* If delegitimize_address couldn't do anything with the UNSPEC, we
14168 can't express it in the debug info. This can happen e.g. with some
14173 resolve_one_addr (&rtl, NULL);
14177 #ifdef ENABLE_CHECKING
14178 print_rtl (stderr, rtl);
14179 gcc_unreachable ();
14185 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14186 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14188 return mem_loc_result;
14191 /* Return a descriptor that describes the concatenation of two locations.
14192 This is typically a complex variable. */
14194 static dw_loc_descr_ref
14195 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
14197 dw_loc_descr_ref cc_loc_result = NULL;
14198 dw_loc_descr_ref x0_ref
14199 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14200 dw_loc_descr_ref x1_ref
14201 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14203 if (x0_ref == 0 || x1_ref == 0)
14206 cc_loc_result = x0_ref;
14207 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
14209 add_loc_descr (&cc_loc_result, x1_ref);
14210 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
14212 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
14213 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14215 return cc_loc_result;
14218 /* Return a descriptor that describes the concatenation of N
14221 static dw_loc_descr_ref
14222 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
14225 dw_loc_descr_ref cc_loc_result = NULL;
14226 unsigned int n = XVECLEN (concatn, 0);
14228 for (i = 0; i < n; ++i)
14230 dw_loc_descr_ref ref;
14231 rtx x = XVECEXP (concatn, 0, i);
14233 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14237 add_loc_descr (&cc_loc_result, ref);
14238 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
14241 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14242 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14244 return cc_loc_result;
14247 /* Output a proper Dwarf location descriptor for a variable or parameter
14248 which is either allocated in a register or in a memory location. For a
14249 register, we just generate an OP_REG and the register number. For a
14250 memory location we provide a Dwarf postfix expression describing how to
14251 generate the (dynamic) address of the object onto the address stack.
14253 MODE is mode of the decl if this loc_descriptor is going to be used in
14254 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
14255 allowed, VOIDmode otherwise.
14257 If we don't know how to describe it, return 0. */
14259 static dw_loc_descr_ref
14260 loc_descriptor (rtx rtl, enum machine_mode mode,
14261 enum var_init_status initialized)
14263 dw_loc_descr_ref loc_result = NULL;
14265 switch (GET_CODE (rtl))
14268 /* The case of a subreg may arise when we have a local (register)
14269 variable or a formal (register) parameter which doesn't quite fill
14270 up an entire register. For now, just assume that it is
14271 legitimate to make the Dwarf info refer to the whole register which
14272 contains the given subreg. */
14273 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
14277 loc_result = reg_loc_descriptor (rtl, initialized);
14281 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
14283 if (loc_result == NULL)
14284 loc_result = tls_mem_loc_descriptor (rtl);
14285 if (loc_result == NULL)
14287 rtx new_rtl = avoid_constant_pool_reference (rtl);
14288 if (new_rtl != rtl)
14289 loc_result = loc_descriptor (new_rtl, mode, initialized);
14294 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
14299 loc_result = concatn_loc_descriptor (rtl, initialized);
14304 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
14306 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
14307 if (GET_CODE (loc) == EXPR_LIST)
14308 loc = XEXP (loc, 0);
14309 loc_result = loc_descriptor (loc, mode, initialized);
14313 rtl = XEXP (rtl, 1);
14318 rtvec par_elems = XVEC (rtl, 0);
14319 int num_elem = GET_NUM_ELEM (par_elems);
14320 enum machine_mode mode;
14323 /* Create the first one, so we have something to add to. */
14324 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
14325 VOIDmode, initialized);
14326 if (loc_result == NULL)
14328 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
14329 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14330 for (i = 1; i < num_elem; i++)
14332 dw_loc_descr_ref temp;
14334 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
14335 VOIDmode, initialized);
14338 add_loc_descr (&loc_result, temp);
14339 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
14340 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14346 if (mode != VOIDmode && mode != BLKmode)
14347 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
14352 if (mode == VOIDmode)
14353 mode = GET_MODE (rtl);
14355 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14357 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14359 /* Note that a CONST_DOUBLE rtx could represent either an integer
14360 or a floating-point constant. A CONST_DOUBLE is used whenever
14361 the constant requires more than one word in order to be
14362 adequately represented. We output CONST_DOUBLEs as blocks. */
14363 loc_result = new_loc_descr (DW_OP_implicit_value,
14364 GET_MODE_SIZE (mode), 0);
14365 if (SCALAR_FLOAT_MODE_P (mode))
14367 unsigned int length = GET_MODE_SIZE (mode);
14368 unsigned char *array
14369 = (unsigned char*) ggc_alloc_atomic (length);
14371 insert_float (rtl, array);
14372 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14373 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
14374 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
14375 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14379 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
14380 loc_result->dw_loc_oprnd2.v.val_double
14381 = rtx_to_double_int (rtl);
14387 if (mode == VOIDmode)
14388 mode = GET_MODE (rtl);
14390 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14392 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
14393 unsigned int length = CONST_VECTOR_NUNITS (rtl);
14394 unsigned char *array = (unsigned char *)
14395 ggc_alloc_atomic (length * elt_size);
14399 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14400 switch (GET_MODE_CLASS (mode))
14402 case MODE_VECTOR_INT:
14403 for (i = 0, p = array; i < length; i++, p += elt_size)
14405 rtx elt = CONST_VECTOR_ELT (rtl, i);
14406 double_int val = rtx_to_double_int (elt);
14408 if (elt_size <= sizeof (HOST_WIDE_INT))
14409 insert_int (double_int_to_shwi (val), elt_size, p);
14412 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
14413 insert_double (val, p);
14418 case MODE_VECTOR_FLOAT:
14419 for (i = 0, p = array; i < length; i++, p += elt_size)
14421 rtx elt = CONST_VECTOR_ELT (rtl, i);
14422 insert_float (elt, p);
14427 gcc_unreachable ();
14430 loc_result = new_loc_descr (DW_OP_implicit_value,
14431 length * elt_size, 0);
14432 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14433 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
14434 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
14435 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14440 if (mode == VOIDmode
14441 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
14442 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
14443 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
14445 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
14450 if (!const_ok_for_output (rtl))
14453 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
14454 && (dwarf_version >= 4 || !dwarf_strict))
14456 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14457 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14458 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14459 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
14460 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14465 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
14466 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14467 && (dwarf_version >= 4 || !dwarf_strict))
14469 /* Value expression. */
14470 loc_result = mem_loc_descriptor (rtl, VOIDmode, initialized);
14472 add_loc_descr (&loc_result,
14473 new_loc_descr (DW_OP_stack_value, 0, 0));
14481 /* We need to figure out what section we should use as the base for the
14482 address ranges where a given location is valid.
14483 1. If this particular DECL has a section associated with it, use that.
14484 2. If this function has a section associated with it, use that.
14485 3. Otherwise, use the text section.
14486 XXX: If you split a variable across multiple sections, we won't notice. */
14488 static const char *
14489 secname_for_decl (const_tree decl)
14491 const char *secname;
14493 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
14495 tree sectree = DECL_SECTION_NAME (decl);
14496 secname = TREE_STRING_POINTER (sectree);
14498 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
14500 tree sectree = DECL_SECTION_NAME (current_function_decl);
14501 secname = TREE_STRING_POINTER (sectree);
14503 else if (cfun && in_cold_section_p)
14504 secname = crtl->subsections.cold_section_label;
14506 secname = text_section_label;
14511 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
14514 decl_by_reference_p (tree decl)
14516 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
14517 || TREE_CODE (decl) == VAR_DECL)
14518 && DECL_BY_REFERENCE (decl));
14521 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14524 static dw_loc_descr_ref
14525 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
14526 enum var_init_status initialized)
14528 int have_address = 0;
14529 dw_loc_descr_ref descr;
14530 enum machine_mode mode;
14532 if (want_address != 2)
14534 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
14536 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14538 varloc = PAT_VAR_LOCATION_LOC (varloc);
14539 if (GET_CODE (varloc) == EXPR_LIST)
14540 varloc = XEXP (varloc, 0);
14541 mode = GET_MODE (varloc);
14542 if (MEM_P (varloc))
14544 rtx addr = XEXP (varloc, 0);
14545 descr = mem_loc_descriptor (addr, mode, initialized);
14550 rtx x = avoid_constant_pool_reference (varloc);
14552 descr = mem_loc_descriptor (x, mode, initialized);
14556 descr = mem_loc_descriptor (varloc, mode, initialized);
14563 if (GET_CODE (varloc) == VAR_LOCATION)
14564 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
14566 mode = DECL_MODE (loc);
14567 descr = loc_descriptor (varloc, mode, initialized);
14574 if (want_address == 2 && !have_address
14575 && (dwarf_version >= 4 || !dwarf_strict))
14577 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
14579 expansion_failed (loc, NULL_RTX,
14580 "DWARF address size mismatch");
14583 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
14586 /* Show if we can't fill the request for an address. */
14587 if (want_address && !have_address)
14589 expansion_failed (loc, NULL_RTX,
14590 "Want address and only have value");
14594 /* If we've got an address and don't want one, dereference. */
14595 if (!want_address && have_address)
14597 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
14598 enum dwarf_location_atom op;
14600 if (size > DWARF2_ADDR_SIZE || size == -1)
14602 expansion_failed (loc, NULL_RTX,
14603 "DWARF address size mismatch");
14606 else if (size == DWARF2_ADDR_SIZE)
14609 op = DW_OP_deref_size;
14611 add_loc_descr (&descr, new_loc_descr (op, size, 0));
14617 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14618 if it is not possible. */
14620 static dw_loc_descr_ref
14621 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
14623 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
14624 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
14625 else if (dwarf_version >= 3 || !dwarf_strict)
14626 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
14631 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14632 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14634 static dw_loc_descr_ref
14635 dw_sra_loc_expr (tree decl, rtx loc)
14638 unsigned int padsize = 0;
14639 dw_loc_descr_ref descr, *descr_tail;
14640 unsigned HOST_WIDE_INT decl_size;
14642 enum var_init_status initialized;
14644 if (DECL_SIZE (decl) == NULL
14645 || !host_integerp (DECL_SIZE (decl), 1))
14648 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
14650 descr_tail = &descr;
14652 for (p = loc; p; p = XEXP (p, 1))
14654 unsigned int bitsize = decl_piece_bitsize (p);
14655 rtx loc_note = *decl_piece_varloc_ptr (p);
14656 dw_loc_descr_ref cur_descr;
14657 dw_loc_descr_ref *tail, last = NULL;
14658 unsigned int opsize = 0;
14660 if (loc_note == NULL_RTX
14661 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
14663 padsize += bitsize;
14666 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
14667 varloc = NOTE_VAR_LOCATION (loc_note);
14668 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
14669 if (cur_descr == NULL)
14671 padsize += bitsize;
14675 /* Check that cur_descr either doesn't use
14676 DW_OP_*piece operations, or their sum is equal
14677 to bitsize. Otherwise we can't embed it. */
14678 for (tail = &cur_descr; *tail != NULL;
14679 tail = &(*tail)->dw_loc_next)
14680 if ((*tail)->dw_loc_opc == DW_OP_piece)
14682 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
14686 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
14688 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
14692 if (last != NULL && opsize != bitsize)
14694 padsize += bitsize;
14698 /* If there is a hole, add DW_OP_*piece after empty DWARF
14699 expression, which means that those bits are optimized out. */
14702 if (padsize > decl_size)
14704 decl_size -= padsize;
14705 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
14706 if (*descr_tail == NULL)
14708 descr_tail = &(*descr_tail)->dw_loc_next;
14711 *descr_tail = cur_descr;
14713 if (bitsize > decl_size)
14715 decl_size -= bitsize;
14718 HOST_WIDE_INT offset = 0;
14719 if (GET_CODE (varloc) == VAR_LOCATION
14720 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14722 varloc = PAT_VAR_LOCATION_LOC (varloc);
14723 if (GET_CODE (varloc) == EXPR_LIST)
14724 varloc = XEXP (varloc, 0);
14728 if (GET_CODE (varloc) == CONST
14729 || GET_CODE (varloc) == SIGN_EXTEND
14730 || GET_CODE (varloc) == ZERO_EXTEND)
14731 varloc = XEXP (varloc, 0);
14732 else if (GET_CODE (varloc) == SUBREG)
14733 varloc = SUBREG_REG (varloc);
14738 /* DW_OP_bit_size offset should be zero for register
14739 or implicit location descriptions and empty location
14740 descriptions, but for memory addresses needs big endian
14742 if (MEM_P (varloc))
14744 unsigned HOST_WIDE_INT memsize
14745 = INTVAL (MEM_SIZE (varloc)) * BITS_PER_UNIT;
14746 if (memsize != bitsize)
14748 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
14749 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
14751 if (memsize < bitsize)
14753 if (BITS_BIG_ENDIAN)
14754 offset = memsize - bitsize;
14758 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
14759 if (*descr_tail == NULL)
14761 descr_tail = &(*descr_tail)->dw_loc_next;
14765 /* If there were any non-empty expressions, add padding till the end of
14767 if (descr != NULL && decl_size != 0)
14769 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
14770 if (*descr_tail == NULL)
14776 /* Return the dwarf representation of the location list LOC_LIST of
14777 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
14780 static dw_loc_list_ref
14781 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
14783 const char *endname, *secname;
14785 enum var_init_status initialized;
14786 struct var_loc_node *node;
14787 dw_loc_descr_ref descr;
14788 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
14789 dw_loc_list_ref list = NULL;
14790 dw_loc_list_ref *listp = &list;
14792 /* Now that we know what section we are using for a base,
14793 actually construct the list of locations.
14794 The first location information is what is passed to the
14795 function that creates the location list, and the remaining
14796 locations just get added on to that list.
14797 Note that we only know the start address for a location
14798 (IE location changes), so to build the range, we use
14799 the range [current location start, next location start].
14800 This means we have to special case the last node, and generate
14801 a range of [last location start, end of function label]. */
14803 secname = secname_for_decl (decl);
14805 for (node = loc_list->first; node; node = node->next)
14806 if (GET_CODE (node->loc) == EXPR_LIST
14807 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
14809 if (GET_CODE (node->loc) == EXPR_LIST)
14811 /* This requires DW_OP_{,bit_}piece, which is not usable
14812 inside DWARF expressions. */
14813 if (want_address != 2)
14815 descr = dw_sra_loc_expr (decl, node->loc);
14821 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
14822 varloc = NOTE_VAR_LOCATION (node->loc);
14823 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
14827 /* The variable has a location between NODE->LABEL and
14828 NODE->NEXT->LABEL. */
14830 endname = node->next->label;
14831 /* If the variable has a location at the last label
14832 it keeps its location until the end of function. */
14833 else if (!current_function_decl)
14834 endname = text_end_label;
14837 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
14838 current_function_funcdef_no);
14839 endname = ggc_strdup (label_id);
14842 *listp = new_loc_list (descr, node->label, endname, secname);
14843 listp = &(*listp)->dw_loc_next;
14847 /* Try to avoid the overhead of a location list emitting a location
14848 expression instead, but only if we didn't have more than one
14849 location entry in the first place. If some entries were not
14850 representable, we don't want to pretend a single entry that was
14851 applies to the entire scope in which the variable is
14853 if (list && loc_list->first->next)
14859 /* Return if the loc_list has only single element and thus can be represented
14860 as location description. */
14863 single_element_loc_list_p (dw_loc_list_ref list)
14865 gcc_assert (!list->dw_loc_next || list->ll_symbol);
14866 return !list->ll_symbol;
14869 /* To each location in list LIST add loc descr REF. */
14872 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
14874 dw_loc_descr_ref copy;
14875 add_loc_descr (&list->expr, ref);
14876 list = list->dw_loc_next;
14879 copy = ggc_alloc_dw_loc_descr_node ();
14880 memcpy (copy, ref, sizeof (dw_loc_descr_node));
14881 add_loc_descr (&list->expr, copy);
14882 while (copy->dw_loc_next)
14884 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
14885 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
14886 copy->dw_loc_next = new_copy;
14889 list = list->dw_loc_next;
14893 /* Given two lists RET and LIST
14894 produce location list that is result of adding expression in LIST
14895 to expression in RET on each possition in program.
14896 Might be destructive on both RET and LIST.
14898 TODO: We handle only simple cases of RET or LIST having at most one
14899 element. General case would inolve sorting the lists in program order
14900 and merging them that will need some additional work.
14901 Adding that will improve quality of debug info especially for SRA-ed
14905 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
14914 if (!list->dw_loc_next)
14916 add_loc_descr_to_each (*ret, list->expr);
14919 if (!(*ret)->dw_loc_next)
14921 add_loc_descr_to_each (list, (*ret)->expr);
14925 expansion_failed (NULL_TREE, NULL_RTX,
14926 "Don't know how to merge two non-trivial"
14927 " location lists.\n");
14932 /* LOC is constant expression. Try a luck, look it up in constant
14933 pool and return its loc_descr of its address. */
14935 static dw_loc_descr_ref
14936 cst_pool_loc_descr (tree loc)
14938 /* Get an RTL for this, if something has been emitted. */
14939 rtx rtl = lookup_constant_def (loc);
14940 enum machine_mode mode;
14942 if (!rtl || !MEM_P (rtl))
14947 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
14949 /* TODO: We might get more coverage if we was actually delaying expansion
14950 of all expressions till end of compilation when constant pools are fully
14952 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
14954 expansion_failed (loc, NULL_RTX,
14955 "CST value in contant pool but not marked.");
14958 mode = GET_MODE (rtl);
14959 rtl = XEXP (rtl, 0);
14960 return mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
14963 /* Return dw_loc_list representing address of addr_expr LOC
14964 by looking for innder INDIRECT_REF expression and turing it
14965 into simple arithmetics. */
14967 static dw_loc_list_ref
14968 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
14971 HOST_WIDE_INT bitsize, bitpos, bytepos;
14972 enum machine_mode mode;
14974 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
14975 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
14977 obj = get_inner_reference (TREE_OPERAND (loc, 0),
14978 &bitsize, &bitpos, &offset, &mode,
14979 &unsignedp, &volatilep, false);
14981 if (bitpos % BITS_PER_UNIT)
14983 expansion_failed (loc, NULL_RTX, "bitfield access");
14986 if (!INDIRECT_REF_P (obj))
14988 expansion_failed (obj,
14989 NULL_RTX, "no indirect ref in inner refrence");
14992 if (!offset && !bitpos)
14993 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
14995 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
14996 && (dwarf_version >= 4 || !dwarf_strict))
14998 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
15003 /* Variable offset. */
15004 list_ret1 = loc_list_from_tree (offset, 0);
15005 if (list_ret1 == 0)
15007 add_loc_list (&list_ret, list_ret1);
15010 add_loc_descr_to_each (list_ret,
15011 new_loc_descr (DW_OP_plus, 0, 0));
15013 bytepos = bitpos / BITS_PER_UNIT;
15015 add_loc_descr_to_each (list_ret,
15016 new_loc_descr (DW_OP_plus_uconst,
15018 else if (bytepos < 0)
15019 loc_list_plus_const (list_ret, bytepos);
15020 add_loc_descr_to_each (list_ret,
15021 new_loc_descr (DW_OP_stack_value, 0, 0));
15027 /* Generate Dwarf location list representing LOC.
15028 If WANT_ADDRESS is false, expression computing LOC will be computed
15029 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
15030 if WANT_ADDRESS is 2, expression computing address useable in location
15031 will be returned (i.e. DW_OP_reg can be used
15032 to refer to register values). */
15034 static dw_loc_list_ref
15035 loc_list_from_tree (tree loc, int want_address)
15037 dw_loc_descr_ref ret = NULL, ret1 = NULL;
15038 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15039 int have_address = 0;
15040 enum dwarf_location_atom op;
15042 /* ??? Most of the time we do not take proper care for sign/zero
15043 extending the values properly. Hopefully this won't be a real
15046 switch (TREE_CODE (loc))
15049 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
15052 case PLACEHOLDER_EXPR:
15053 /* This case involves extracting fields from an object to determine the
15054 position of other fields. We don't try to encode this here. The
15055 only user of this is Ada, which encodes the needed information using
15056 the names of types. */
15057 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
15061 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
15062 /* There are no opcodes for these operations. */
15065 case PREINCREMENT_EXPR:
15066 case PREDECREMENT_EXPR:
15067 case POSTINCREMENT_EXPR:
15068 case POSTDECREMENT_EXPR:
15069 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
15070 /* There are no opcodes for these operations. */
15074 /* If we already want an address, see if there is INDIRECT_REF inside
15075 e.g. for &this->field. */
15078 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
15079 (loc, want_address == 2);
15082 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
15083 && (ret = cst_pool_loc_descr (loc)))
15086 /* Otherwise, process the argument and look for the address. */
15087 if (!list_ret && !ret)
15088 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
15092 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
15098 if (DECL_THREAD_LOCAL_P (loc))
15101 enum dwarf_location_atom first_op;
15102 enum dwarf_location_atom second_op;
15103 bool dtprel = false;
15105 if (targetm.have_tls)
15107 /* If this is not defined, we have no way to emit the
15109 if (!targetm.asm_out.output_dwarf_dtprel)
15112 /* The way DW_OP_GNU_push_tls_address is specified, we
15113 can only look up addresses of objects in the current
15114 module. We used DW_OP_addr as first op, but that's
15115 wrong, because DW_OP_addr is relocated by the debug
15116 info consumer, while DW_OP_GNU_push_tls_address
15117 operand shouldn't be. */
15118 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
15120 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
15122 second_op = DW_OP_GNU_push_tls_address;
15126 if (!targetm.emutls.debug_form_tls_address
15127 || !(dwarf_version >= 3 || !dwarf_strict))
15129 /* We stuffed the control variable into the DECL_VALUE_EXPR
15130 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
15131 no longer appear in gimple code. We used the control
15132 variable in specific so that we could pick it up here. */
15133 loc = DECL_VALUE_EXPR (loc);
15134 first_op = DW_OP_addr;
15135 second_op = DW_OP_form_tls_address;
15138 rtl = rtl_for_decl_location (loc);
15139 if (rtl == NULL_RTX)
15144 rtl = XEXP (rtl, 0);
15145 if (! CONSTANT_P (rtl))
15148 ret = new_loc_descr (first_op, 0, 0);
15149 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15150 ret->dw_loc_oprnd1.v.val_addr = rtl;
15151 ret->dtprel = dtprel;
15153 ret1 = new_loc_descr (second_op, 0, 0);
15154 add_loc_descr (&ret, ret1);
15162 if (DECL_HAS_VALUE_EXPR_P (loc))
15163 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
15168 case FUNCTION_DECL:
15171 var_loc_list *loc_list = lookup_decl_loc (loc);
15173 if (loc_list && loc_list->first)
15175 list_ret = dw_loc_list (loc_list, loc, want_address);
15176 have_address = want_address != 0;
15179 rtl = rtl_for_decl_location (loc);
15180 if (rtl == NULL_RTX)
15182 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
15185 else if (CONST_INT_P (rtl))
15187 HOST_WIDE_INT val = INTVAL (rtl);
15188 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15189 val &= GET_MODE_MASK (DECL_MODE (loc));
15190 ret = int_loc_descriptor (val);
15192 else if (GET_CODE (rtl) == CONST_STRING)
15194 expansion_failed (loc, NULL_RTX, "CONST_STRING");
15197 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
15199 ret = new_loc_descr (DW_OP_addr, 0, 0);
15200 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15201 ret->dw_loc_oprnd1.v.val_addr = rtl;
15205 enum machine_mode mode;
15207 /* Certain constructs can only be represented at top-level. */
15208 if (want_address == 2)
15210 ret = loc_descriptor (rtl, VOIDmode,
15211 VAR_INIT_STATUS_INITIALIZED);
15216 mode = GET_MODE (rtl);
15219 rtl = XEXP (rtl, 0);
15222 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15225 expansion_failed (loc, rtl,
15226 "failed to produce loc descriptor for rtl");
15233 if (!integer_zerop (TREE_OPERAND (loc, 1)))
15237 case MISALIGNED_INDIRECT_REF:
15238 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15242 case COMPOUND_EXPR:
15243 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
15246 case VIEW_CONVERT_EXPR:
15249 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
15251 case COMPONENT_REF:
15252 case BIT_FIELD_REF:
15254 case ARRAY_RANGE_REF:
15255 case REALPART_EXPR:
15256 case IMAGPART_EXPR:
15259 HOST_WIDE_INT bitsize, bitpos, bytepos;
15260 enum machine_mode mode;
15262 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15264 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
15265 &unsignedp, &volatilep, false);
15267 gcc_assert (obj != loc);
15269 list_ret = loc_list_from_tree (obj,
15271 && !bitpos && !offset ? 2 : 1);
15272 /* TODO: We can extract value of the small expression via shifting even
15273 for nonzero bitpos. */
15276 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
15278 expansion_failed (loc, NULL_RTX,
15279 "bitfield access");
15283 if (offset != NULL_TREE)
15285 /* Variable offset. */
15286 list_ret1 = loc_list_from_tree (offset, 0);
15287 if (list_ret1 == 0)
15289 add_loc_list (&list_ret, list_ret1);
15292 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
15295 bytepos = bitpos / BITS_PER_UNIT;
15297 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
15298 else if (bytepos < 0)
15299 loc_list_plus_const (list_ret, bytepos);
15306 if ((want_address || !host_integerp (loc, 0))
15307 && (ret = cst_pool_loc_descr (loc)))
15309 else if (want_address == 2
15310 && host_integerp (loc, 0)
15311 && (ret = address_of_int_loc_descriptor
15312 (int_size_in_bytes (TREE_TYPE (loc)),
15313 tree_low_cst (loc, 0))))
15315 else if (host_integerp (loc, 0))
15316 ret = int_loc_descriptor (tree_low_cst (loc, 0));
15319 expansion_failed (loc, NULL_RTX,
15320 "Integer operand is not host integer");
15329 if ((ret = cst_pool_loc_descr (loc)))
15332 /* We can construct small constants here using int_loc_descriptor. */
15333 expansion_failed (loc, NULL_RTX,
15334 "constructor or constant not in constant pool");
15337 case TRUTH_AND_EXPR:
15338 case TRUTH_ANDIF_EXPR:
15343 case TRUTH_XOR_EXPR:
15348 case TRUTH_OR_EXPR:
15349 case TRUTH_ORIF_EXPR:
15354 case FLOOR_DIV_EXPR:
15355 case CEIL_DIV_EXPR:
15356 case ROUND_DIV_EXPR:
15357 case TRUNC_DIV_EXPR:
15358 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15367 case FLOOR_MOD_EXPR:
15368 case CEIL_MOD_EXPR:
15369 case ROUND_MOD_EXPR:
15370 case TRUNC_MOD_EXPR:
15371 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15376 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15377 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15378 if (list_ret == 0 || list_ret1 == 0)
15381 add_loc_list (&list_ret, list_ret1);
15384 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15385 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15386 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
15387 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
15388 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
15400 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
15403 case POINTER_PLUS_EXPR:
15405 if (host_integerp (TREE_OPERAND (loc, 1), 0))
15407 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15411 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
15419 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15426 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15433 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15440 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15455 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15456 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15457 if (list_ret == 0 || list_ret1 == 0)
15460 add_loc_list (&list_ret, list_ret1);
15463 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15466 case TRUTH_NOT_EXPR:
15480 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15484 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15490 const enum tree_code code =
15491 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
15493 loc = build3 (COND_EXPR, TREE_TYPE (loc),
15494 build2 (code, integer_type_node,
15495 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
15496 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
15499 /* ... fall through ... */
15503 dw_loc_descr_ref lhs
15504 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
15505 dw_loc_list_ref rhs
15506 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
15507 dw_loc_descr_ref bra_node, jump_node, tmp;
15509 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15510 if (list_ret == 0 || lhs == 0 || rhs == 0)
15513 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
15514 add_loc_descr_to_each (list_ret, bra_node);
15516 add_loc_list (&list_ret, rhs);
15517 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
15518 add_loc_descr_to_each (list_ret, jump_node);
15520 add_loc_descr_to_each (list_ret, lhs);
15521 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15522 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
15524 /* ??? Need a node to point the skip at. Use a nop. */
15525 tmp = new_loc_descr (DW_OP_nop, 0, 0);
15526 add_loc_descr_to_each (list_ret, tmp);
15527 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15528 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
15532 case FIX_TRUNC_EXPR:
15536 /* Leave front-end specific codes as simply unknown. This comes
15537 up, for instance, with the C STMT_EXPR. */
15538 if ((unsigned int) TREE_CODE (loc)
15539 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
15541 expansion_failed (loc, NULL_RTX,
15542 "language specific tree node");
15546 #ifdef ENABLE_CHECKING
15547 /* Otherwise this is a generic code; we should just lists all of
15548 these explicitly. We forgot one. */
15549 gcc_unreachable ();
15551 /* In a release build, we want to degrade gracefully: better to
15552 generate incomplete debugging information than to crash. */
15557 if (!ret && !list_ret)
15560 if (want_address == 2 && !have_address
15561 && (dwarf_version >= 4 || !dwarf_strict))
15563 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
15565 expansion_failed (loc, NULL_RTX,
15566 "DWARF address size mismatch");
15570 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
15572 add_loc_descr_to_each (list_ret,
15573 new_loc_descr (DW_OP_stack_value, 0, 0));
15576 /* Show if we can't fill the request for an address. */
15577 if (want_address && !have_address)
15579 expansion_failed (loc, NULL_RTX,
15580 "Want address and only have value");
15584 gcc_assert (!ret || !list_ret);
15586 /* If we've got an address and don't want one, dereference. */
15587 if (!want_address && have_address)
15589 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
15591 if (size > DWARF2_ADDR_SIZE || size == -1)
15593 expansion_failed (loc, NULL_RTX,
15594 "DWARF address size mismatch");
15597 else if (size == DWARF2_ADDR_SIZE)
15600 op = DW_OP_deref_size;
15603 add_loc_descr (&ret, new_loc_descr (op, size, 0));
15605 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
15608 list_ret = new_loc_list (ret, NULL, NULL, NULL);
15613 /* Same as above but return only single location expression. */
15614 static dw_loc_descr_ref
15615 loc_descriptor_from_tree (tree loc, int want_address)
15617 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
15620 if (ret->dw_loc_next)
15622 expansion_failed (loc, NULL_RTX,
15623 "Location list where only loc descriptor needed");
15629 /* Given a value, round it up to the lowest multiple of `boundary'
15630 which is not less than the value itself. */
15632 static inline HOST_WIDE_INT
15633 ceiling (HOST_WIDE_INT value, unsigned int boundary)
15635 return (((value + boundary - 1) / boundary) * boundary);
15638 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
15639 pointer to the declared type for the relevant field variable, or return
15640 `integer_type_node' if the given node turns out to be an
15641 ERROR_MARK node. */
15644 field_type (const_tree decl)
15648 if (TREE_CODE (decl) == ERROR_MARK)
15649 return integer_type_node;
15651 type = DECL_BIT_FIELD_TYPE (decl);
15652 if (type == NULL_TREE)
15653 type = TREE_TYPE (decl);
15658 /* Given a pointer to a tree node, return the alignment in bits for
15659 it, or else return BITS_PER_WORD if the node actually turns out to
15660 be an ERROR_MARK node. */
15662 static inline unsigned
15663 simple_type_align_in_bits (const_tree type)
15665 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
15668 static inline unsigned
15669 simple_decl_align_in_bits (const_tree decl)
15671 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
15674 /* Return the result of rounding T up to ALIGN. */
15676 static inline double_int
15677 round_up_to_align (double_int t, unsigned int align)
15679 double_int alignd = uhwi_to_double_int (align);
15680 t = double_int_add (t, alignd);
15681 t = double_int_add (t, double_int_minus_one);
15682 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
15683 t = double_int_mul (t, alignd);
15687 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
15688 lowest addressed byte of the "containing object" for the given FIELD_DECL,
15689 or return 0 if we are unable to determine what that offset is, either
15690 because the argument turns out to be a pointer to an ERROR_MARK node, or
15691 because the offset is actually variable. (We can't handle the latter case
15694 static HOST_WIDE_INT
15695 field_byte_offset (const_tree decl)
15697 double_int object_offset_in_bits;
15698 double_int object_offset_in_bytes;
15699 double_int bitpos_int;
15701 if (TREE_CODE (decl) == ERROR_MARK)
15704 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
15706 /* We cannot yet cope with fields whose positions are variable, so
15707 for now, when we see such things, we simply return 0. Someday, we may
15708 be able to handle such cases, but it will be damn difficult. */
15709 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
15712 bitpos_int = tree_to_double_int (bit_position (decl));
15714 #ifdef PCC_BITFIELD_TYPE_MATTERS
15715 if (PCC_BITFIELD_TYPE_MATTERS)
15718 tree field_size_tree;
15719 double_int deepest_bitpos;
15720 double_int field_size_in_bits;
15721 unsigned int type_align_in_bits;
15722 unsigned int decl_align_in_bits;
15723 double_int type_size_in_bits;
15725 type = field_type (decl);
15726 type_size_in_bits = double_int_type_size_in_bits (type);
15727 type_align_in_bits = simple_type_align_in_bits (type);
15729 field_size_tree = DECL_SIZE (decl);
15731 /* The size could be unspecified if there was an error, or for
15732 a flexible array member. */
15733 if (!field_size_tree)
15734 field_size_tree = bitsize_zero_node;
15736 /* If the size of the field is not constant, use the type size. */
15737 if (TREE_CODE (field_size_tree) == INTEGER_CST)
15738 field_size_in_bits = tree_to_double_int (field_size_tree);
15740 field_size_in_bits = type_size_in_bits;
15742 decl_align_in_bits = simple_decl_align_in_bits (decl);
15744 /* The GCC front-end doesn't make any attempt to keep track of the
15745 starting bit offset (relative to the start of the containing
15746 structure type) of the hypothetical "containing object" for a
15747 bit-field. Thus, when computing the byte offset value for the
15748 start of the "containing object" of a bit-field, we must deduce
15749 this information on our own. This can be rather tricky to do in
15750 some cases. For example, handling the following structure type
15751 definition when compiling for an i386/i486 target (which only
15752 aligns long long's to 32-bit boundaries) can be very tricky:
15754 struct S { int field1; long long field2:31; };
15756 Fortunately, there is a simple rule-of-thumb which can be used
15757 in such cases. When compiling for an i386/i486, GCC will
15758 allocate 8 bytes for the structure shown above. It decides to
15759 do this based upon one simple rule for bit-field allocation.
15760 GCC allocates each "containing object" for each bit-field at
15761 the first (i.e. lowest addressed) legitimate alignment boundary
15762 (based upon the required minimum alignment for the declared
15763 type of the field) which it can possibly use, subject to the
15764 condition that there is still enough available space remaining
15765 in the containing object (when allocated at the selected point)
15766 to fully accommodate all of the bits of the bit-field itself.
15768 This simple rule makes it obvious why GCC allocates 8 bytes for
15769 each object of the structure type shown above. When looking
15770 for a place to allocate the "containing object" for `field2',
15771 the compiler simply tries to allocate a 64-bit "containing
15772 object" at each successive 32-bit boundary (starting at zero)
15773 until it finds a place to allocate that 64- bit field such that
15774 at least 31 contiguous (and previously unallocated) bits remain
15775 within that selected 64 bit field. (As it turns out, for the
15776 example above, the compiler finds it is OK to allocate the
15777 "containing object" 64-bit field at bit-offset zero within the
15780 Here we attempt to work backwards from the limited set of facts
15781 we're given, and we try to deduce from those facts, where GCC
15782 must have believed that the containing object started (within
15783 the structure type). The value we deduce is then used (by the
15784 callers of this routine) to generate DW_AT_location and
15785 DW_AT_bit_offset attributes for fields (both bit-fields and, in
15786 the case of DW_AT_location, regular fields as well). */
15788 /* Figure out the bit-distance from the start of the structure to
15789 the "deepest" bit of the bit-field. */
15790 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
15792 /* This is the tricky part. Use some fancy footwork to deduce
15793 where the lowest addressed bit of the containing object must
15795 object_offset_in_bits
15796 = double_int_sub (deepest_bitpos, type_size_in_bits);
15798 /* Round up to type_align by default. This works best for
15800 object_offset_in_bits
15801 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
15803 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
15805 object_offset_in_bits
15806 = double_int_sub (deepest_bitpos, type_size_in_bits);
15808 /* Round up to decl_align instead. */
15809 object_offset_in_bits
15810 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
15814 #endif /* PCC_BITFIELD_TYPE_MATTERS */
15815 object_offset_in_bits = bitpos_int;
15817 object_offset_in_bytes
15818 = double_int_div (object_offset_in_bits,
15819 uhwi_to_double_int (BITS_PER_UNIT), true,
15821 return double_int_to_shwi (object_offset_in_bytes);
15824 /* The following routines define various Dwarf attributes and any data
15825 associated with them. */
15827 /* Add a location description attribute value to a DIE.
15829 This emits location attributes suitable for whole variables and
15830 whole parameters. Note that the location attributes for struct fields are
15831 generated by the routine `data_member_location_attribute' below. */
15834 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
15835 dw_loc_list_ref descr)
15839 if (single_element_loc_list_p (descr))
15840 add_AT_loc (die, attr_kind, descr->expr);
15842 add_AT_loc_list (die, attr_kind, descr);
15845 /* Add DW_AT_accessibility attribute to DIE if needed. */
15848 add_accessibility_attribute (dw_die_ref die, tree decl)
15850 if (TREE_PROTECTED (decl))
15851 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
15852 else if (TREE_PRIVATE (decl))
15853 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
15856 /* Attach the specialized form of location attribute used for data members of
15857 struct and union types. In the special case of a FIELD_DECL node which
15858 represents a bit-field, the "offset" part of this special location
15859 descriptor must indicate the distance in bytes from the lowest-addressed
15860 byte of the containing struct or union type to the lowest-addressed byte of
15861 the "containing object" for the bit-field. (See the `field_byte_offset'
15864 For any given bit-field, the "containing object" is a hypothetical object
15865 (of some integral or enum type) within which the given bit-field lives. The
15866 type of this hypothetical "containing object" is always the same as the
15867 declared type of the individual bit-field itself (for GCC anyway... the
15868 DWARF spec doesn't actually mandate this). Note that it is the size (in
15869 bytes) of the hypothetical "containing object" which will be given in the
15870 DW_AT_byte_size attribute for this bit-field. (See the
15871 `byte_size_attribute' function below.) It is also used when calculating the
15872 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
15873 function below.) */
15876 add_data_member_location_attribute (dw_die_ref die, tree decl)
15878 HOST_WIDE_INT offset;
15879 dw_loc_descr_ref loc_descr = 0;
15881 if (TREE_CODE (decl) == TREE_BINFO)
15883 /* We're working on the TAG_inheritance for a base class. */
15884 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
15886 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
15887 aren't at a fixed offset from all (sub)objects of the same
15888 type. We need to extract the appropriate offset from our
15889 vtable. The following dwarf expression means
15891 BaseAddr = ObAddr + *((*ObAddr) - Offset)
15893 This is specific to the V3 ABI, of course. */
15895 dw_loc_descr_ref tmp;
15897 /* Make a copy of the object address. */
15898 tmp = new_loc_descr (DW_OP_dup, 0, 0);
15899 add_loc_descr (&loc_descr, tmp);
15901 /* Extract the vtable address. */
15902 tmp = new_loc_descr (DW_OP_deref, 0, 0);
15903 add_loc_descr (&loc_descr, tmp);
15905 /* Calculate the address of the offset. */
15906 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
15907 gcc_assert (offset < 0);
15909 tmp = int_loc_descriptor (-offset);
15910 add_loc_descr (&loc_descr, tmp);
15911 tmp = new_loc_descr (DW_OP_minus, 0, 0);
15912 add_loc_descr (&loc_descr, tmp);
15914 /* Extract the offset. */
15915 tmp = new_loc_descr (DW_OP_deref, 0, 0);
15916 add_loc_descr (&loc_descr, tmp);
15918 /* Add it to the object address. */
15919 tmp = new_loc_descr (DW_OP_plus, 0, 0);
15920 add_loc_descr (&loc_descr, tmp);
15923 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
15926 offset = field_byte_offset (decl);
15930 if (dwarf_version > 2)
15932 /* Don't need to output a location expression, just the constant. */
15934 add_AT_int (die, DW_AT_data_member_location, offset);
15936 add_AT_unsigned (die, DW_AT_data_member_location, offset);
15941 enum dwarf_location_atom op;
15943 /* The DWARF2 standard says that we should assume that the structure
15944 address is already on the stack, so we can specify a structure
15945 field address by using DW_OP_plus_uconst. */
15947 #ifdef MIPS_DEBUGGING_INFO
15948 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
15949 operator correctly. It works only if we leave the offset on the
15953 op = DW_OP_plus_uconst;
15956 loc_descr = new_loc_descr (op, offset, 0);
15960 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
15963 /* Writes integer values to dw_vec_const array. */
15966 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
15970 *dest++ = val & 0xff;
15976 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
15978 static HOST_WIDE_INT
15979 extract_int (const unsigned char *src, unsigned int size)
15981 HOST_WIDE_INT val = 0;
15987 val |= *--src & 0xff;
15993 /* Writes double_int values to dw_vec_const array. */
15996 insert_double (double_int val, unsigned char *dest)
15998 unsigned char *p0 = dest;
15999 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
16001 if (WORDS_BIG_ENDIAN)
16007 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
16008 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
16011 /* Writes floating point values to dw_vec_const array. */
16014 insert_float (const_rtx rtl, unsigned char *array)
16016 REAL_VALUE_TYPE rv;
16020 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
16021 real_to_target (val, &rv, GET_MODE (rtl));
16023 /* real_to_target puts 32-bit pieces in each long. Pack them. */
16024 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
16026 insert_int (val[i], 4, array);
16031 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
16032 does not have a "location" either in memory or in a register. These
16033 things can arise in GNU C when a constant is passed as an actual parameter
16034 to an inlined function. They can also arise in C++ where declared
16035 constants do not necessarily get memory "homes". */
16038 add_const_value_attribute (dw_die_ref die, rtx rtl)
16040 switch (GET_CODE (rtl))
16044 HOST_WIDE_INT val = INTVAL (rtl);
16047 add_AT_int (die, DW_AT_const_value, val);
16049 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
16054 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
16055 floating-point constant. A CONST_DOUBLE is used whenever the
16056 constant requires more than one word in order to be adequately
16059 enum machine_mode mode = GET_MODE (rtl);
16061 if (SCALAR_FLOAT_MODE_P (mode))
16063 unsigned int length = GET_MODE_SIZE (mode);
16064 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
16066 insert_float (rtl, array);
16067 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
16070 add_AT_double (die, DW_AT_const_value,
16071 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
16077 enum machine_mode mode = GET_MODE (rtl);
16078 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
16079 unsigned int length = CONST_VECTOR_NUNITS (rtl);
16080 unsigned char *array = (unsigned char *) ggc_alloc_atomic
16081 (length * elt_size);
16085 switch (GET_MODE_CLASS (mode))
16087 case MODE_VECTOR_INT:
16088 for (i = 0, p = array; i < length; i++, p += elt_size)
16090 rtx elt = CONST_VECTOR_ELT (rtl, i);
16091 double_int val = rtx_to_double_int (elt);
16093 if (elt_size <= sizeof (HOST_WIDE_INT))
16094 insert_int (double_int_to_shwi (val), elt_size, p);
16097 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
16098 insert_double (val, p);
16103 case MODE_VECTOR_FLOAT:
16104 for (i = 0, p = array; i < length; i++, p += elt_size)
16106 rtx elt = CONST_VECTOR_ELT (rtl, i);
16107 insert_float (elt, p);
16112 gcc_unreachable ();
16115 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
16120 if (dwarf_version >= 4 || !dwarf_strict)
16122 dw_loc_descr_ref loc_result;
16123 resolve_one_addr (&rtl, NULL);
16125 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
16126 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
16127 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
16128 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
16129 add_AT_loc (die, DW_AT_location, loc_result);
16130 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
16136 if (CONSTANT_P (XEXP (rtl, 0)))
16137 return add_const_value_attribute (die, XEXP (rtl, 0));
16140 if (!const_ok_for_output (rtl))
16143 if (dwarf_version >= 4 || !dwarf_strict)
16148 /* In cases where an inlined instance of an inline function is passed
16149 the address of an `auto' variable (which is local to the caller) we
16150 can get a situation where the DECL_RTL of the artificial local
16151 variable (for the inlining) which acts as a stand-in for the
16152 corresponding formal parameter (of the inline function) will look
16153 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
16154 exactly a compile-time constant expression, but it isn't the address
16155 of the (artificial) local variable either. Rather, it represents the
16156 *value* which the artificial local variable always has during its
16157 lifetime. We currently have no way to represent such quasi-constant
16158 values in Dwarf, so for now we just punt and generate nothing. */
16166 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
16167 && MEM_READONLY_P (rtl)
16168 && GET_MODE (rtl) == BLKmode)
16170 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
16176 /* No other kinds of rtx should be possible here. */
16177 gcc_unreachable ();
16182 /* Determine whether the evaluation of EXPR references any variables
16183 or functions which aren't otherwise used (and therefore may not be
16186 reference_to_unused (tree * tp, int * walk_subtrees,
16187 void * data ATTRIBUTE_UNUSED)
16189 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
16190 *walk_subtrees = 0;
16192 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
16193 && ! TREE_ASM_WRITTEN (*tp))
16195 /* ??? The C++ FE emits debug information for using decls, so
16196 putting gcc_unreachable here falls over. See PR31899. For now
16197 be conservative. */
16198 else if (!cgraph_global_info_ready
16199 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
16201 else if (TREE_CODE (*tp) == VAR_DECL)
16203 struct varpool_node *node = varpool_get_node (*tp);
16204 if (!node || !node->needed)
16207 else if (TREE_CODE (*tp) == FUNCTION_DECL
16208 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
16210 /* The call graph machinery must have finished analyzing,
16211 optimizing and gimplifying the CU by now.
16212 So if *TP has no call graph node associated
16213 to it, it means *TP will not be emitted. */
16214 if (!cgraph_get_node (*tp))
16217 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
16223 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
16224 for use in a later add_const_value_attribute call. */
16227 rtl_for_decl_init (tree init, tree type)
16229 rtx rtl = NULL_RTX;
16231 /* If a variable is initialized with a string constant without embedded
16232 zeros, build CONST_STRING. */
16233 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
16235 tree enttype = TREE_TYPE (type);
16236 tree domain = TYPE_DOMAIN (type);
16237 enum machine_mode mode = TYPE_MODE (enttype);
16239 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
16241 && integer_zerop (TYPE_MIN_VALUE (domain))
16242 && compare_tree_int (TYPE_MAX_VALUE (domain),
16243 TREE_STRING_LENGTH (init) - 1) == 0
16244 && ((size_t) TREE_STRING_LENGTH (init)
16245 == strlen (TREE_STRING_POINTER (init)) + 1))
16247 rtl = gen_rtx_CONST_STRING (VOIDmode,
16248 ggc_strdup (TREE_STRING_POINTER (init)));
16249 rtl = gen_rtx_MEM (BLKmode, rtl);
16250 MEM_READONLY_P (rtl) = 1;
16253 /* Other aggregates, and complex values, could be represented using
16255 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
16257 /* Vectors only work if their mode is supported by the target.
16258 FIXME: generic vectors ought to work too. */
16259 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
16261 /* If the initializer is something that we know will expand into an
16262 immediate RTL constant, expand it now. We must be careful not to
16263 reference variables which won't be output. */
16264 else if (initializer_constant_valid_p (init, type)
16265 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
16267 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
16269 if (TREE_CODE (type) == VECTOR_TYPE)
16270 switch (TREE_CODE (init))
16275 if (TREE_CONSTANT (init))
16277 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
16278 bool constant_p = true;
16280 unsigned HOST_WIDE_INT ix;
16282 /* Even when ctor is constant, it might contain non-*_CST
16283 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
16284 belong into VECTOR_CST nodes. */
16285 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
16286 if (!CONSTANT_CLASS_P (value))
16288 constant_p = false;
16294 init = build_vector_from_ctor (type, elts);
16304 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
16306 /* If expand_expr returns a MEM, it wasn't immediate. */
16307 gcc_assert (!rtl || !MEM_P (rtl));
16313 /* Generate RTL for the variable DECL to represent its location. */
16316 rtl_for_decl_location (tree decl)
16320 /* Here we have to decide where we are going to say the parameter "lives"
16321 (as far as the debugger is concerned). We only have a couple of
16322 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
16324 DECL_RTL normally indicates where the parameter lives during most of the
16325 activation of the function. If optimization is enabled however, this
16326 could be either NULL or else a pseudo-reg. Both of those cases indicate
16327 that the parameter doesn't really live anywhere (as far as the code
16328 generation parts of GCC are concerned) during most of the function's
16329 activation. That will happen (for example) if the parameter is never
16330 referenced within the function.
16332 We could just generate a location descriptor here for all non-NULL
16333 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
16334 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
16335 where DECL_RTL is NULL or is a pseudo-reg.
16337 Note however that we can only get away with using DECL_INCOMING_RTL as
16338 a backup substitute for DECL_RTL in certain limited cases. In cases
16339 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
16340 we can be sure that the parameter was passed using the same type as it is
16341 declared to have within the function, and that its DECL_INCOMING_RTL
16342 points us to a place where a value of that type is passed.
16344 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
16345 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
16346 because in these cases DECL_INCOMING_RTL points us to a value of some
16347 type which is *different* from the type of the parameter itself. Thus,
16348 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
16349 such cases, the debugger would end up (for example) trying to fetch a
16350 `float' from a place which actually contains the first part of a
16351 `double'. That would lead to really incorrect and confusing
16352 output at debug-time.
16354 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
16355 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
16356 are a couple of exceptions however. On little-endian machines we can
16357 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
16358 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
16359 an integral type that is smaller than TREE_TYPE (decl). These cases arise
16360 when (on a little-endian machine) a non-prototyped function has a
16361 parameter declared to be of type `short' or `char'. In such cases,
16362 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
16363 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
16364 passed `int' value. If the debugger then uses that address to fetch
16365 a `short' or a `char' (on a little-endian machine) the result will be
16366 the correct data, so we allow for such exceptional cases below.
16368 Note that our goal here is to describe the place where the given formal
16369 parameter lives during most of the function's activation (i.e. between the
16370 end of the prologue and the start of the epilogue). We'll do that as best
16371 as we can. Note however that if the given formal parameter is modified
16372 sometime during the execution of the function, then a stack backtrace (at
16373 debug-time) will show the function as having been called with the *new*
16374 value rather than the value which was originally passed in. This happens
16375 rarely enough that it is not a major problem, but it *is* a problem, and
16376 I'd like to fix it.
16378 A future version of dwarf2out.c may generate two additional attributes for
16379 any given DW_TAG_formal_parameter DIE which will describe the "passed
16380 type" and the "passed location" for the given formal parameter in addition
16381 to the attributes we now generate to indicate the "declared type" and the
16382 "active location" for each parameter. This additional set of attributes
16383 could be used by debuggers for stack backtraces. Separately, note that
16384 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
16385 This happens (for example) for inlined-instances of inline function formal
16386 parameters which are never referenced. This really shouldn't be
16387 happening. All PARM_DECL nodes should get valid non-NULL
16388 DECL_INCOMING_RTL values. FIXME. */
16390 /* Use DECL_RTL as the "location" unless we find something better. */
16391 rtl = DECL_RTL_IF_SET (decl);
16393 /* When generating abstract instances, ignore everything except
16394 constants, symbols living in memory, and symbols living in
16395 fixed registers. */
16396 if (! reload_completed)
16399 && (CONSTANT_P (rtl)
16401 && CONSTANT_P (XEXP (rtl, 0)))
16403 && TREE_CODE (decl) == VAR_DECL
16404 && TREE_STATIC (decl))))
16406 rtl = targetm.delegitimize_address (rtl);
16411 else if (TREE_CODE (decl) == PARM_DECL)
16413 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
16415 tree declared_type = TREE_TYPE (decl);
16416 tree passed_type = DECL_ARG_TYPE (decl);
16417 enum machine_mode dmode = TYPE_MODE (declared_type);
16418 enum machine_mode pmode = TYPE_MODE (passed_type);
16420 /* This decl represents a formal parameter which was optimized out.
16421 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
16422 all cases where (rtl == NULL_RTX) just below. */
16423 if (dmode == pmode)
16424 rtl = DECL_INCOMING_RTL (decl);
16425 else if (SCALAR_INT_MODE_P (dmode)
16426 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
16427 && DECL_INCOMING_RTL (decl))
16429 rtx inc = DECL_INCOMING_RTL (decl);
16432 else if (MEM_P (inc))
16434 if (BYTES_BIG_ENDIAN)
16435 rtl = adjust_address_nv (inc, dmode,
16436 GET_MODE_SIZE (pmode)
16437 - GET_MODE_SIZE (dmode));
16444 /* If the parm was passed in registers, but lives on the stack, then
16445 make a big endian correction if the mode of the type of the
16446 parameter is not the same as the mode of the rtl. */
16447 /* ??? This is the same series of checks that are made in dbxout.c before
16448 we reach the big endian correction code there. It isn't clear if all
16449 of these checks are necessary here, but keeping them all is the safe
16451 else if (MEM_P (rtl)
16452 && XEXP (rtl, 0) != const0_rtx
16453 && ! CONSTANT_P (XEXP (rtl, 0))
16454 /* Not passed in memory. */
16455 && !MEM_P (DECL_INCOMING_RTL (decl))
16456 /* Not passed by invisible reference. */
16457 && (!REG_P (XEXP (rtl, 0))
16458 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
16459 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
16460 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
16461 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
16464 /* Big endian correction check. */
16465 && BYTES_BIG_ENDIAN
16466 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
16467 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
16470 int offset = (UNITS_PER_WORD
16471 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
16473 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16474 plus_constant (XEXP (rtl, 0), offset));
16477 else if (TREE_CODE (decl) == VAR_DECL
16480 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
16481 && BYTES_BIG_ENDIAN)
16483 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
16484 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
16486 /* If a variable is declared "register" yet is smaller than
16487 a register, then if we store the variable to memory, it
16488 looks like we're storing a register-sized value, when in
16489 fact we are not. We need to adjust the offset of the
16490 storage location to reflect the actual value's bytes,
16491 else gdb will not be able to display it. */
16493 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16494 plus_constant (XEXP (rtl, 0), rsize-dsize));
16497 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16498 and will have been substituted directly into all expressions that use it.
16499 C does not have such a concept, but C++ and other languages do. */
16500 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
16501 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
16504 rtl = targetm.delegitimize_address (rtl);
16506 /* If we don't look past the constant pool, we risk emitting a
16507 reference to a constant pool entry that isn't referenced from
16508 code, and thus is not emitted. */
16510 rtl = avoid_constant_pool_reference (rtl);
16512 /* Try harder to get a rtl. If this symbol ends up not being emitted
16513 in the current CU, resolve_addr will remove the expression referencing
16515 if (rtl == NULL_RTX
16516 && TREE_CODE (decl) == VAR_DECL
16517 && !DECL_EXTERNAL (decl)
16518 && TREE_STATIC (decl)
16519 && DECL_NAME (decl)
16520 && !DECL_HARD_REGISTER (decl)
16521 && DECL_MODE (decl) != VOIDmode)
16523 rtl = make_decl_rtl_for_debug (decl);
16525 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
16526 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
16533 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
16534 returned. If so, the decl for the COMMON block is returned, and the
16535 value is the offset into the common block for the symbol. */
16538 fortran_common (tree decl, HOST_WIDE_INT *value)
16540 tree val_expr, cvar;
16541 enum machine_mode mode;
16542 HOST_WIDE_INT bitsize, bitpos;
16544 int volatilep = 0, unsignedp = 0;
16546 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
16547 it does not have a value (the offset into the common area), or if it
16548 is thread local (as opposed to global) then it isn't common, and shouldn't
16549 be handled as such. */
16550 if (TREE_CODE (decl) != VAR_DECL
16551 || !TREE_STATIC (decl)
16552 || !DECL_HAS_VALUE_EXPR_P (decl)
16556 val_expr = DECL_VALUE_EXPR (decl);
16557 if (TREE_CODE (val_expr) != COMPONENT_REF)
16560 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
16561 &mode, &unsignedp, &volatilep, true);
16563 if (cvar == NULL_TREE
16564 || TREE_CODE (cvar) != VAR_DECL
16565 || DECL_ARTIFICIAL (cvar)
16566 || !TREE_PUBLIC (cvar))
16570 if (offset != NULL)
16572 if (!host_integerp (offset, 0))
16574 *value = tree_low_cst (offset, 0);
16577 *value += bitpos / BITS_PER_UNIT;
16582 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
16583 data attribute for a variable or a parameter. We generate the
16584 DW_AT_const_value attribute only in those cases where the given variable
16585 or parameter does not have a true "location" either in memory or in a
16586 register. This can happen (for example) when a constant is passed as an
16587 actual argument in a call to an inline function. (It's possible that
16588 these things can crop up in other ways also.) Note that one type of
16589 constant value which can be passed into an inlined function is a constant
16590 pointer. This can happen for example if an actual argument in an inlined
16591 function call evaluates to a compile-time constant address. */
16594 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
16595 enum dwarf_attribute attr)
16598 dw_loc_list_ref list;
16599 var_loc_list *loc_list;
16601 if (TREE_CODE (decl) == ERROR_MARK)
16604 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
16605 || TREE_CODE (decl) == RESULT_DECL);
16607 /* Try to get some constant RTL for this decl, and use that as the value of
16610 rtl = rtl_for_decl_location (decl);
16611 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16612 && add_const_value_attribute (die, rtl))
16615 /* See if we have single element location list that is equivalent to
16616 a constant value. That way we are better to use add_const_value_attribute
16617 rather than expanding constant value equivalent. */
16618 loc_list = lookup_decl_loc (decl);
16621 && loc_list->first->next == NULL
16622 && NOTE_P (loc_list->first->loc)
16623 && NOTE_VAR_LOCATION (loc_list->first->loc)
16624 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
16626 struct var_loc_node *node;
16628 node = loc_list->first;
16629 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
16630 if (GET_CODE (rtl) == EXPR_LIST)
16631 rtl = XEXP (rtl, 0);
16632 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16633 && add_const_value_attribute (die, rtl))
16636 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
16639 add_AT_location_description (die, attr, list);
16642 /* None of that worked, so it must not really have a location;
16643 try adding a constant value attribute from the DECL_INITIAL. */
16644 return tree_add_const_value_attribute_for_decl (die, decl);
16647 /* Add VARIABLE and DIE into deferred locations list. */
16650 defer_location (tree variable, dw_die_ref die)
16652 deferred_locations entry;
16653 entry.variable = variable;
16655 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
16658 /* Helper function for tree_add_const_value_attribute. Natively encode
16659 initializer INIT into an array. Return true if successful. */
16662 native_encode_initializer (tree init, unsigned char *array, int size)
16666 if (init == NULL_TREE)
16670 switch (TREE_CODE (init))
16673 type = TREE_TYPE (init);
16674 if (TREE_CODE (type) == ARRAY_TYPE)
16676 tree enttype = TREE_TYPE (type);
16677 enum machine_mode mode = TYPE_MODE (enttype);
16679 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
16681 if (int_size_in_bytes (type) != size)
16683 if (size > TREE_STRING_LENGTH (init))
16685 memcpy (array, TREE_STRING_POINTER (init),
16686 TREE_STRING_LENGTH (init));
16687 memset (array + TREE_STRING_LENGTH (init),
16688 '\0', size - TREE_STRING_LENGTH (init));
16691 memcpy (array, TREE_STRING_POINTER (init), size);
16696 type = TREE_TYPE (init);
16697 if (int_size_in_bytes (type) != size)
16699 if (TREE_CODE (type) == ARRAY_TYPE)
16701 HOST_WIDE_INT min_index;
16702 unsigned HOST_WIDE_INT cnt;
16703 int curpos = 0, fieldsize;
16704 constructor_elt *ce;
16706 if (TYPE_DOMAIN (type) == NULL_TREE
16707 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
16710 fieldsize = int_size_in_bytes (TREE_TYPE (type));
16711 if (fieldsize <= 0)
16714 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
16715 memset (array, '\0', size);
16716 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
16718 tree val = ce->value;
16719 tree index = ce->index;
16721 if (index && TREE_CODE (index) == RANGE_EXPR)
16722 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
16725 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
16730 if (!native_encode_initializer (val, array + pos, fieldsize))
16733 curpos = pos + fieldsize;
16734 if (index && TREE_CODE (index) == RANGE_EXPR)
16736 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
16737 - tree_low_cst (TREE_OPERAND (index, 0), 0);
16741 memcpy (array + curpos, array + pos, fieldsize);
16742 curpos += fieldsize;
16745 gcc_assert (curpos <= size);
16749 else if (TREE_CODE (type) == RECORD_TYPE
16750 || TREE_CODE (type) == UNION_TYPE)
16752 tree field = NULL_TREE;
16753 unsigned HOST_WIDE_INT cnt;
16754 constructor_elt *ce;
16756 if (int_size_in_bytes (type) != size)
16759 if (TREE_CODE (type) == RECORD_TYPE)
16760 field = TYPE_FIELDS (type);
16762 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
16764 tree val = ce->value;
16765 int pos, fieldsize;
16767 if (ce->index != 0)
16773 if (field == NULL_TREE || DECL_BIT_FIELD (field))
16776 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
16777 && TYPE_DOMAIN (TREE_TYPE (field))
16778 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
16780 else if (DECL_SIZE_UNIT (field) == NULL_TREE
16781 || !host_integerp (DECL_SIZE_UNIT (field), 0))
16783 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
16784 pos = int_byte_position (field);
16785 gcc_assert (pos + fieldsize <= size);
16787 && !native_encode_initializer (val, array + pos, fieldsize))
16793 case VIEW_CONVERT_EXPR:
16794 case NON_LVALUE_EXPR:
16795 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
16797 return native_encode_expr (init, array, size) == size;
16801 /* Attach a DW_AT_const_value attribute to DIE. The value of the
16802 attribute is the const value T. */
16805 tree_add_const_value_attribute (dw_die_ref die, tree t)
16808 tree type = TREE_TYPE (t);
16811 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
16815 gcc_assert (!DECL_P (init));
16817 rtl = rtl_for_decl_init (init, type);
16819 return add_const_value_attribute (die, rtl);
16820 /* If the host and target are sane, try harder. */
16821 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
16822 && initializer_constant_valid_p (init, type))
16824 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
16825 if (size > 0 && (int) size == size)
16827 unsigned char *array = (unsigned char *)
16828 ggc_alloc_cleared_atomic (size);
16830 if (native_encode_initializer (init, array, size))
16832 add_AT_vec (die, DW_AT_const_value, size, 1, array);
16840 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
16841 attribute is the const value of T, where T is an integral constant
16842 variable with static storage duration
16843 (so it can't be a PARM_DECL or a RESULT_DECL). */
16846 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
16850 || (TREE_CODE (decl) != VAR_DECL
16851 && TREE_CODE (decl) != CONST_DECL))
16854 if (TREE_READONLY (decl)
16855 && ! TREE_THIS_VOLATILE (decl)
16856 && DECL_INITIAL (decl))
16861 /* Don't add DW_AT_const_value if abstract origin already has one. */
16862 if (get_AT (var_die, DW_AT_const_value))
16865 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
16868 /* Convert the CFI instructions for the current function into a
16869 location list. This is used for DW_AT_frame_base when we targeting
16870 a dwarf2 consumer that does not support the dwarf3
16871 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
16874 static dw_loc_list_ref
16875 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
16878 dw_loc_list_ref list, *list_tail;
16880 dw_cfa_location last_cfa, next_cfa;
16881 const char *start_label, *last_label, *section;
16882 dw_cfa_location remember;
16884 fde = current_fde ();
16885 gcc_assert (fde != NULL);
16887 section = secname_for_decl (current_function_decl);
16891 memset (&next_cfa, 0, sizeof (next_cfa));
16892 next_cfa.reg = INVALID_REGNUM;
16893 remember = next_cfa;
16895 start_label = fde->dw_fde_begin;
16897 /* ??? Bald assumption that the CIE opcode list does not contain
16898 advance opcodes. */
16899 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
16900 lookup_cfa_1 (cfi, &next_cfa, &remember);
16902 last_cfa = next_cfa;
16903 last_label = start_label;
16905 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
16906 switch (cfi->dw_cfi_opc)
16908 case DW_CFA_set_loc:
16909 case DW_CFA_advance_loc1:
16910 case DW_CFA_advance_loc2:
16911 case DW_CFA_advance_loc4:
16912 if (!cfa_equal_p (&last_cfa, &next_cfa))
16914 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
16915 start_label, last_label, section);
16917 list_tail = &(*list_tail)->dw_loc_next;
16918 last_cfa = next_cfa;
16919 start_label = last_label;
16921 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
16924 case DW_CFA_advance_loc:
16925 /* The encoding is complex enough that we should never emit this. */
16926 gcc_unreachable ();
16929 lookup_cfa_1 (cfi, &next_cfa, &remember);
16933 if (!cfa_equal_p (&last_cfa, &next_cfa))
16935 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
16936 start_label, last_label, section);
16937 list_tail = &(*list_tail)->dw_loc_next;
16938 start_label = last_label;
16941 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
16942 start_label, fde->dw_fde_end, section);
16944 if (list && list->dw_loc_next)
16950 /* Compute a displacement from the "steady-state frame pointer" to the
16951 frame base (often the same as the CFA), and store it in
16952 frame_pointer_fb_offset. OFFSET is added to the displacement
16953 before the latter is negated. */
16956 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
16960 #ifdef FRAME_POINTER_CFA_OFFSET
16961 reg = frame_pointer_rtx;
16962 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
16964 reg = arg_pointer_rtx;
16965 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
16968 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
16969 if (GET_CODE (elim) == PLUS)
16971 offset += INTVAL (XEXP (elim, 1));
16972 elim = XEXP (elim, 0);
16975 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
16976 && (elim == hard_frame_pointer_rtx
16977 || elim == stack_pointer_rtx))
16978 || elim == (frame_pointer_needed
16979 ? hard_frame_pointer_rtx
16980 : stack_pointer_rtx));
16982 frame_pointer_fb_offset = -offset;
16985 /* Generate a DW_AT_name attribute given some string value to be included as
16986 the value of the attribute. */
16989 add_name_attribute (dw_die_ref die, const char *name_string)
16991 if (name_string != NULL && *name_string != 0)
16993 if (demangle_name_func)
16994 name_string = (*demangle_name_func) (name_string);
16996 add_AT_string (die, DW_AT_name, name_string);
17000 /* Generate a DW_AT_comp_dir attribute for DIE. */
17003 add_comp_dir_attribute (dw_die_ref die)
17005 const char *wd = get_src_pwd ();
17011 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
17015 wdlen = strlen (wd);
17016 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
17018 wd1 [wdlen] = DIR_SEPARATOR;
17019 wd1 [wdlen + 1] = 0;
17023 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
17026 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
17030 lower_bound_default (void)
17032 switch (get_AT_unsigned (comp_unit_die, DW_AT_language))
17037 case DW_LANG_C_plus_plus:
17039 case DW_LANG_ObjC_plus_plus:
17042 case DW_LANG_Fortran77:
17043 case DW_LANG_Fortran90:
17044 case DW_LANG_Fortran95:
17048 case DW_LANG_Python:
17049 return dwarf_version >= 4 ? 0 : -1;
17050 case DW_LANG_Ada95:
17051 case DW_LANG_Ada83:
17052 case DW_LANG_Cobol74:
17053 case DW_LANG_Cobol85:
17054 case DW_LANG_Pascal83:
17055 case DW_LANG_Modula2:
17057 return dwarf_version >= 4 ? 1 : -1;
17063 /* Given a tree node describing an array bound (either lower or upper) output
17064 a representation for that bound. */
17067 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
17069 switch (TREE_CODE (bound))
17074 /* All fixed-bounds are represented by INTEGER_CST nodes. */
17077 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
17080 /* Use the default if possible. */
17081 if (bound_attr == DW_AT_lower_bound
17082 && host_integerp (bound, 0)
17083 && (dflt = lower_bound_default ()) != -1
17084 && tree_low_cst (bound, 0) == dflt)
17087 /* Otherwise represent the bound as an unsigned value with the
17088 precision of its type. The precision and signedness of the
17089 type will be necessary to re-interpret it unambiguously. */
17090 else if (prec < HOST_BITS_PER_WIDE_INT)
17092 unsigned HOST_WIDE_INT mask
17093 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
17094 add_AT_unsigned (subrange_die, bound_attr,
17095 TREE_INT_CST_LOW (bound) & mask);
17097 else if (prec == HOST_BITS_PER_WIDE_INT
17098 || TREE_INT_CST_HIGH (bound) == 0)
17099 add_AT_unsigned (subrange_die, bound_attr,
17100 TREE_INT_CST_LOW (bound));
17102 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
17103 TREE_INT_CST_LOW (bound));
17108 case VIEW_CONVERT_EXPR:
17109 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
17119 dw_die_ref decl_die = lookup_decl_die (bound);
17121 /* ??? Can this happen, or should the variable have been bound
17122 first? Probably it can, since I imagine that we try to create
17123 the types of parameters in the order in which they exist in
17124 the list, and won't have created a forward reference to a
17125 later parameter. */
17126 if (decl_die != NULL)
17128 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17136 /* Otherwise try to create a stack operation procedure to
17137 evaluate the value of the array bound. */
17139 dw_die_ref ctx, decl_die;
17140 dw_loc_list_ref list;
17142 list = loc_list_from_tree (bound, 2);
17143 if (list == NULL || single_element_loc_list_p (list))
17145 /* If DW_AT_*bound is not a reference nor constant, it is
17146 a DWARF expression rather than location description.
17147 For that loc_list_from_tree (bound, 0) is needed.
17148 If that fails to give a single element list,
17149 fall back to outputting this as a reference anyway. */
17150 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
17151 if (list2 && single_element_loc_list_p (list2))
17153 add_AT_loc (subrange_die, bound_attr, list2->expr);
17160 if (current_function_decl == 0)
17161 ctx = comp_unit_die;
17163 ctx = lookup_decl_die (current_function_decl);
17165 decl_die = new_die (DW_TAG_variable, ctx, bound);
17166 add_AT_flag (decl_die, DW_AT_artificial, 1);
17167 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
17168 add_AT_location_description (decl_die, DW_AT_location, list);
17169 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17175 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
17176 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
17177 Note that the block of subscript information for an array type also
17178 includes information about the element type of the given array type. */
17181 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
17183 unsigned dimension_number;
17185 dw_die_ref subrange_die;
17187 for (dimension_number = 0;
17188 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
17189 type = TREE_TYPE (type), dimension_number++)
17191 tree domain = TYPE_DOMAIN (type);
17193 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
17196 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
17197 and (in GNU C only) variable bounds. Handle all three forms
17199 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
17202 /* We have an array type with specified bounds. */
17203 lower = TYPE_MIN_VALUE (domain);
17204 upper = TYPE_MAX_VALUE (domain);
17206 /* Define the index type. */
17207 if (TREE_TYPE (domain))
17209 /* ??? This is probably an Ada unnamed subrange type. Ignore the
17210 TREE_TYPE field. We can't emit debug info for this
17211 because it is an unnamed integral type. */
17212 if (TREE_CODE (domain) == INTEGER_TYPE
17213 && TYPE_NAME (domain) == NULL_TREE
17214 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
17215 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
17218 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
17222 /* ??? If upper is NULL, the array has unspecified length,
17223 but it does have a lower bound. This happens with Fortran
17225 Since the debugger is definitely going to need to know N
17226 to produce useful results, go ahead and output the lower
17227 bound solo, and hope the debugger can cope. */
17229 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
17231 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
17234 /* Otherwise we have an array type with an unspecified length. The
17235 DWARF-2 spec does not say how to handle this; let's just leave out the
17241 add_byte_size_attribute (dw_die_ref die, tree tree_node)
17245 switch (TREE_CODE (tree_node))
17250 case ENUMERAL_TYPE:
17253 case QUAL_UNION_TYPE:
17254 size = int_size_in_bytes (tree_node);
17257 /* For a data member of a struct or union, the DW_AT_byte_size is
17258 generally given as the number of bytes normally allocated for an
17259 object of the *declared* type of the member itself. This is true
17260 even for bit-fields. */
17261 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
17264 gcc_unreachable ();
17267 /* Note that `size' might be -1 when we get to this point. If it is, that
17268 indicates that the byte size of the entity in question is variable. We
17269 have no good way of expressing this fact in Dwarf at the present time,
17270 so just let the -1 pass on through. */
17271 add_AT_unsigned (die, DW_AT_byte_size, size);
17274 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17275 which specifies the distance in bits from the highest order bit of the
17276 "containing object" for the bit-field to the highest order bit of the
17279 For any given bit-field, the "containing object" is a hypothetical object
17280 (of some integral or enum type) within which the given bit-field lives. The
17281 type of this hypothetical "containing object" is always the same as the
17282 declared type of the individual bit-field itself. The determination of the
17283 exact location of the "containing object" for a bit-field is rather
17284 complicated. It's handled by the `field_byte_offset' function (above).
17286 Note that it is the size (in bytes) of the hypothetical "containing object"
17287 which will be given in the DW_AT_byte_size attribute for this bit-field.
17288 (See `byte_size_attribute' above). */
17291 add_bit_offset_attribute (dw_die_ref die, tree decl)
17293 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
17294 tree type = DECL_BIT_FIELD_TYPE (decl);
17295 HOST_WIDE_INT bitpos_int;
17296 HOST_WIDE_INT highest_order_object_bit_offset;
17297 HOST_WIDE_INT highest_order_field_bit_offset;
17298 HOST_WIDE_INT unsigned bit_offset;
17300 /* Must be a field and a bit field. */
17301 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
17303 /* We can't yet handle bit-fields whose offsets are variable, so if we
17304 encounter such things, just return without generating any attribute
17305 whatsoever. Likewise for variable or too large size. */
17306 if (! host_integerp (bit_position (decl), 0)
17307 || ! host_integerp (DECL_SIZE (decl), 1))
17310 bitpos_int = int_bit_position (decl);
17312 /* Note that the bit offset is always the distance (in bits) from the
17313 highest-order bit of the "containing object" to the highest-order bit of
17314 the bit-field itself. Since the "high-order end" of any object or field
17315 is different on big-endian and little-endian machines, the computation
17316 below must take account of these differences. */
17317 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
17318 highest_order_field_bit_offset = bitpos_int;
17320 if (! BYTES_BIG_ENDIAN)
17322 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
17323 highest_order_object_bit_offset += simple_type_size_in_bits (type);
17327 = (! BYTES_BIG_ENDIAN
17328 ? highest_order_object_bit_offset - highest_order_field_bit_offset
17329 : highest_order_field_bit_offset - highest_order_object_bit_offset);
17331 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
17334 /* For a FIELD_DECL node which represents a bit field, output an attribute
17335 which specifies the length in bits of the given field. */
17338 add_bit_size_attribute (dw_die_ref die, tree decl)
17340 /* Must be a field and a bit field. */
17341 gcc_assert (TREE_CODE (decl) == FIELD_DECL
17342 && DECL_BIT_FIELD_TYPE (decl));
17344 if (host_integerp (DECL_SIZE (decl), 1))
17345 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
17348 /* If the compiled language is ANSI C, then add a 'prototyped'
17349 attribute, if arg types are given for the parameters of a function. */
17352 add_prototyped_attribute (dw_die_ref die, tree func_type)
17354 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
17355 && TYPE_ARG_TYPES (func_type) != NULL)
17356 add_AT_flag (die, DW_AT_prototyped, 1);
17359 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17360 by looking in either the type declaration or object declaration
17363 static inline dw_die_ref
17364 add_abstract_origin_attribute (dw_die_ref die, tree origin)
17366 dw_die_ref origin_die = NULL;
17368 if (TREE_CODE (origin) != FUNCTION_DECL)
17370 /* We may have gotten separated from the block for the inlined
17371 function, if we're in an exception handler or some such; make
17372 sure that the abstract function has been written out.
17374 Doing this for nested functions is wrong, however; functions are
17375 distinct units, and our context might not even be inline. */
17379 fn = TYPE_STUB_DECL (fn);
17381 fn = decl_function_context (fn);
17383 dwarf2out_abstract_function (fn);
17386 if (DECL_P (origin))
17387 origin_die = lookup_decl_die (origin);
17388 else if (TYPE_P (origin))
17389 origin_die = lookup_type_die (origin);
17391 /* XXX: Functions that are never lowered don't always have correct block
17392 trees (in the case of java, they simply have no block tree, in some other
17393 languages). For these functions, there is nothing we can really do to
17394 output correct debug info for inlined functions in all cases. Rather
17395 than die, we'll just produce deficient debug info now, in that we will
17396 have variables without a proper abstract origin. In the future, when all
17397 functions are lowered, we should re-add a gcc_assert (origin_die)
17401 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
17405 /* We do not currently support the pure_virtual attribute. */
17408 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
17410 if (DECL_VINDEX (func_decl))
17412 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
17414 if (host_integerp (DECL_VINDEX (func_decl), 0))
17415 add_AT_loc (die, DW_AT_vtable_elem_location,
17416 new_loc_descr (DW_OP_constu,
17417 tree_low_cst (DECL_VINDEX (func_decl), 0),
17420 /* GNU extension: Record what type this method came from originally. */
17421 if (debug_info_level > DINFO_LEVEL_TERSE
17422 && DECL_CONTEXT (func_decl))
17423 add_AT_die_ref (die, DW_AT_containing_type,
17424 lookup_type_die (DECL_CONTEXT (func_decl)));
17428 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
17429 given decl. This used to be a vendor extension until after DWARF 4
17430 standardized it. */
17433 add_linkage_attr (dw_die_ref die, tree decl)
17435 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
17437 /* Mimic what assemble_name_raw does with a leading '*'. */
17438 if (name[0] == '*')
17441 if (dwarf_version >= 4)
17442 add_AT_string (die, DW_AT_linkage_name, name);
17444 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
17447 /* Add source coordinate attributes for the given decl. */
17450 add_src_coords_attributes (dw_die_ref die, tree decl)
17452 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
17454 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
17455 add_AT_unsigned (die, DW_AT_decl_line, s.line);
17458 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
17461 add_linkage_name (dw_die_ref die, tree decl)
17463 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
17464 && TREE_PUBLIC (decl)
17465 && !DECL_ABSTRACT (decl)
17466 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
17467 && die->die_tag != DW_TAG_member)
17469 /* Defer until we have an assembler name set. */
17470 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
17472 limbo_die_node *asm_name;
17474 asm_name = ggc_alloc_cleared_limbo_die_node ();
17475 asm_name->die = die;
17476 asm_name->created_for = decl;
17477 asm_name->next = deferred_asm_name;
17478 deferred_asm_name = asm_name;
17480 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
17481 add_linkage_attr (die, decl);
17485 /* Add a DW_AT_name attribute and source coordinate attribute for the
17486 given decl, but only if it actually has a name. */
17489 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
17493 decl_name = DECL_NAME (decl);
17494 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
17496 const char *name = dwarf2_name (decl, 0);
17498 add_name_attribute (die, name);
17499 if (! DECL_ARTIFICIAL (decl))
17500 add_src_coords_attributes (die, decl);
17502 add_linkage_name (die, decl);
17505 #ifdef VMS_DEBUGGING_INFO
17506 /* Get the function's name, as described by its RTL. This may be different
17507 from the DECL_NAME name used in the source file. */
17508 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
17510 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
17511 XEXP (DECL_RTL (decl), 0));
17512 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
17514 #endif /* VMS_DEBUGGING_INFO */
17517 #ifdef VMS_DEBUGGING_INFO
17518 /* Output the debug main pointer die for VMS */
17521 dwarf2out_vms_debug_main_pointer (void)
17523 char label[MAX_ARTIFICIAL_LABEL_BYTES];
17526 /* Allocate the VMS debug main subprogram die. */
17527 die = ggc_alloc_cleared_die_node ();
17528 die->die_tag = DW_TAG_subprogram;
17529 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
17530 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
17531 current_function_funcdef_no);
17532 add_AT_lbl_id (die, DW_AT_entry_pc, label);
17534 /* Make it the first child of comp_unit_die. */
17535 die->die_parent = comp_unit_die;
17536 if (comp_unit_die->die_child)
17538 die->die_sib = comp_unit_die->die_child->die_sib;
17539 comp_unit_die->die_child->die_sib = die;
17543 die->die_sib = die;
17544 comp_unit_die->die_child = die;
17547 #endif /* VMS_DEBUGGING_INFO */
17549 /* Push a new declaration scope. */
17552 push_decl_scope (tree scope)
17554 VEC_safe_push (tree, gc, decl_scope_table, scope);
17557 /* Pop a declaration scope. */
17560 pop_decl_scope (void)
17562 VEC_pop (tree, decl_scope_table);
17565 /* Return the DIE for the scope that immediately contains this type.
17566 Non-named types get global scope. Named types nested in other
17567 types get their containing scope if it's open, or global scope
17568 otherwise. All other types (i.e. function-local named types) get
17569 the current active scope. */
17572 scope_die_for (tree t, dw_die_ref context_die)
17574 dw_die_ref scope_die = NULL;
17575 tree containing_scope;
17578 /* Non-types always go in the current scope. */
17579 gcc_assert (TYPE_P (t));
17581 containing_scope = TYPE_CONTEXT (t);
17583 /* Use the containing namespace if it was passed in (for a declaration). */
17584 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
17586 if (context_die == lookup_decl_die (containing_scope))
17589 containing_scope = NULL_TREE;
17592 /* Ignore function type "scopes" from the C frontend. They mean that
17593 a tagged type is local to a parmlist of a function declarator, but
17594 that isn't useful to DWARF. */
17595 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
17596 containing_scope = NULL_TREE;
17598 if (containing_scope == NULL_TREE)
17599 scope_die = comp_unit_die;
17600 else if (TYPE_P (containing_scope))
17602 /* For types, we can just look up the appropriate DIE. But
17603 first we check to see if we're in the middle of emitting it
17604 so we know where the new DIE should go. */
17605 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
17606 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
17611 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
17612 || TREE_ASM_WRITTEN (containing_scope));
17613 /*We are not in the middle of emitting the type
17614 CONTAINING_SCOPE. Let's see if it's emitted already. */
17615 scope_die = lookup_type_die (containing_scope);
17617 /* If none of the current dies are suitable, we get file scope. */
17618 if (scope_die == NULL)
17619 scope_die = comp_unit_die;
17622 scope_die = lookup_type_die (containing_scope);
17625 scope_die = context_die;
17630 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
17633 local_scope_p (dw_die_ref context_die)
17635 for (; context_die; context_die = context_die->die_parent)
17636 if (context_die->die_tag == DW_TAG_inlined_subroutine
17637 || context_die->die_tag == DW_TAG_subprogram)
17643 /* Returns nonzero if CONTEXT_DIE is a class. */
17646 class_scope_p (dw_die_ref context_die)
17648 return (context_die
17649 && (context_die->die_tag == DW_TAG_structure_type
17650 || context_die->die_tag == DW_TAG_class_type
17651 || context_die->die_tag == DW_TAG_interface_type
17652 || context_die->die_tag == DW_TAG_union_type));
17655 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
17656 whether or not to treat a DIE in this context as a declaration. */
17659 class_or_namespace_scope_p (dw_die_ref context_die)
17661 return (class_scope_p (context_die)
17662 || (context_die && context_die->die_tag == DW_TAG_namespace));
17665 /* Many forms of DIEs require a "type description" attribute. This
17666 routine locates the proper "type descriptor" die for the type given
17667 by 'type', and adds a DW_AT_type attribute below the given die. */
17670 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
17671 int decl_volatile, dw_die_ref context_die)
17673 enum tree_code code = TREE_CODE (type);
17674 dw_die_ref type_die = NULL;
17676 /* ??? If this type is an unnamed subrange type of an integral, floating-point
17677 or fixed-point type, use the inner type. This is because we have no
17678 support for unnamed types in base_type_die. This can happen if this is
17679 an Ada subrange type. Correct solution is emit a subrange type die. */
17680 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
17681 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
17682 type = TREE_TYPE (type), code = TREE_CODE (type);
17684 if (code == ERROR_MARK
17685 /* Handle a special case. For functions whose return type is void, we
17686 generate *no* type attribute. (Note that no object may have type
17687 `void', so this only applies to function return types). */
17688 || code == VOID_TYPE)
17691 type_die = modified_type_die (type,
17692 decl_const || TYPE_READONLY (type),
17693 decl_volatile || TYPE_VOLATILE (type),
17696 if (type_die != NULL)
17697 add_AT_die_ref (object_die, DW_AT_type, type_die);
17700 /* Given an object die, add the calling convention attribute for the
17701 function call type. */
17703 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
17705 enum dwarf_calling_convention value = DW_CC_normal;
17707 value = ((enum dwarf_calling_convention)
17708 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
17710 /* DWARF doesn't provide a way to identify a program's source-level
17711 entry point. DW_AT_calling_convention attributes are only meant
17712 to describe functions' calling conventions. However, lacking a
17713 better way to signal the Fortran main program, we use this for the
17714 time being, following existing custom. */
17716 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
17717 value = DW_CC_program;
17719 /* Only add the attribute if the backend requests it, and
17720 is not DW_CC_normal. */
17721 if (value && (value != DW_CC_normal))
17722 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
17725 /* Given a tree pointer to a struct, class, union, or enum type node, return
17726 a pointer to the (string) tag name for the given type, or zero if the type
17727 was declared without a tag. */
17729 static const char *
17730 type_tag (const_tree type)
17732 const char *name = 0;
17734 if (TYPE_NAME (type) != 0)
17738 /* Find the IDENTIFIER_NODE for the type name. */
17739 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
17740 && !TYPE_NAMELESS (type))
17741 t = TYPE_NAME (type);
17743 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
17744 a TYPE_DECL node, regardless of whether or not a `typedef' was
17746 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
17747 && ! DECL_IGNORED_P (TYPE_NAME (type)))
17749 /* We want to be extra verbose. Don't call dwarf_name if
17750 DECL_NAME isn't set. The default hook for decl_printable_name
17751 doesn't like that, and in this context it's correct to return
17752 0, instead of "<anonymous>" or the like. */
17753 if (DECL_NAME (TYPE_NAME (type))
17754 && !DECL_NAMELESS (TYPE_NAME (type)))
17755 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
17758 /* Now get the name as a string, or invent one. */
17759 if (!name && t != 0)
17760 name = IDENTIFIER_POINTER (t);
17763 return (name == 0 || *name == '\0') ? 0 : name;
17766 /* Return the type associated with a data member, make a special check
17767 for bit field types. */
17770 member_declared_type (const_tree member)
17772 return (DECL_BIT_FIELD_TYPE (member)
17773 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
17776 /* Get the decl's label, as described by its RTL. This may be different
17777 from the DECL_NAME name used in the source file. */
17780 static const char *
17781 decl_start_label (tree decl)
17784 const char *fnname;
17786 x = DECL_RTL (decl);
17787 gcc_assert (MEM_P (x));
17790 gcc_assert (GET_CODE (x) == SYMBOL_REF);
17792 fnname = XSTR (x, 0);
17797 /* These routines generate the internal representation of the DIE's for
17798 the compilation unit. Debugging information is collected by walking
17799 the declaration trees passed in from dwarf2out_decl(). */
17802 gen_array_type_die (tree type, dw_die_ref context_die)
17804 dw_die_ref scope_die = scope_die_for (type, context_die);
17805 dw_die_ref array_die;
17807 /* GNU compilers represent multidimensional array types as sequences of one
17808 dimensional array types whose element types are themselves array types.
17809 We sometimes squish that down to a single array_type DIE with multiple
17810 subscripts in the Dwarf debugging info. The draft Dwarf specification
17811 say that we are allowed to do this kind of compression in C, because
17812 there is no difference between an array of arrays and a multidimensional
17813 array. We don't do this for Ada to remain as close as possible to the
17814 actual representation, which is especially important against the language
17815 flexibilty wrt arrays of variable size. */
17817 bool collapse_nested_arrays = !is_ada ();
17820 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
17821 DW_TAG_string_type doesn't have DW_AT_type attribute). */
17822 if (TYPE_STRING_FLAG (type)
17823 && TREE_CODE (type) == ARRAY_TYPE
17825 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
17827 HOST_WIDE_INT size;
17829 array_die = new_die (DW_TAG_string_type, scope_die, type);
17830 add_name_attribute (array_die, type_tag (type));
17831 equate_type_number_to_die (type, array_die);
17832 size = int_size_in_bytes (type);
17834 add_AT_unsigned (array_die, DW_AT_byte_size, size);
17835 else if (TYPE_DOMAIN (type) != NULL_TREE
17836 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
17837 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
17839 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
17840 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
17842 size = int_size_in_bytes (TREE_TYPE (szdecl));
17843 if (loc && size > 0)
17845 add_AT_location_description (array_die, DW_AT_string_length, loc);
17846 if (size != DWARF2_ADDR_SIZE)
17847 add_AT_unsigned (array_die, DW_AT_byte_size, size);
17853 /* ??? The SGI dwarf reader fails for array of array of enum types
17854 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
17855 array type comes before the outer array type. We thus call gen_type_die
17856 before we new_die and must prevent nested array types collapsing for this
17859 #ifdef MIPS_DEBUGGING_INFO
17860 gen_type_die (TREE_TYPE (type), context_die);
17861 collapse_nested_arrays = false;
17864 array_die = new_die (DW_TAG_array_type, scope_die, type);
17865 add_name_attribute (array_die, type_tag (type));
17866 equate_type_number_to_die (type, array_die);
17868 if (TREE_CODE (type) == VECTOR_TYPE)
17870 /* The frontend feeds us a representation for the vector as a struct
17871 containing an array. Pull out the array type. */
17872 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
17873 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
17876 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17878 && TREE_CODE (type) == ARRAY_TYPE
17879 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
17880 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
17881 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
17884 /* We default the array ordering. SDB will probably do
17885 the right things even if DW_AT_ordering is not present. It's not even
17886 an issue until we start to get into multidimensional arrays anyway. If
17887 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
17888 then we'll have to put the DW_AT_ordering attribute back in. (But if
17889 and when we find out that we need to put these in, we will only do so
17890 for multidimensional arrays. */
17891 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
17894 #ifdef MIPS_DEBUGGING_INFO
17895 /* The SGI compilers handle arrays of unknown bound by setting
17896 AT_declaration and not emitting any subrange DIEs. */
17897 if (! TYPE_DOMAIN (type))
17898 add_AT_flag (array_die, DW_AT_declaration, 1);
17901 add_subscript_info (array_die, type, collapse_nested_arrays);
17903 /* Add representation of the type of the elements of this array type and
17904 emit the corresponding DIE if we haven't done it already. */
17905 element_type = TREE_TYPE (type);
17906 if (collapse_nested_arrays)
17907 while (TREE_CODE (element_type) == ARRAY_TYPE)
17909 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
17911 element_type = TREE_TYPE (element_type);
17914 #ifndef MIPS_DEBUGGING_INFO
17915 gen_type_die (element_type, context_die);
17918 add_type_attribute (array_die, element_type, 0, 0, context_die);
17920 if (get_AT (array_die, DW_AT_name))
17921 add_pubtype (type, array_die);
17924 static dw_loc_descr_ref
17925 descr_info_loc (tree val, tree base_decl)
17927 HOST_WIDE_INT size;
17928 dw_loc_descr_ref loc, loc2;
17929 enum dwarf_location_atom op;
17931 if (val == base_decl)
17932 return new_loc_descr (DW_OP_push_object_address, 0, 0);
17934 switch (TREE_CODE (val))
17937 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
17939 return loc_descriptor_from_tree (val, 0);
17941 if (host_integerp (val, 0))
17942 return int_loc_descriptor (tree_low_cst (val, 0));
17945 size = int_size_in_bytes (TREE_TYPE (val));
17948 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
17951 if (size == DWARF2_ADDR_SIZE)
17952 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
17954 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
17956 case POINTER_PLUS_EXPR:
17958 if (host_integerp (TREE_OPERAND (val, 1), 1)
17959 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
17962 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
17965 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
17971 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
17974 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
17977 add_loc_descr (&loc, loc2);
17978 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
18000 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
18001 tree val, tree base_decl)
18003 dw_loc_descr_ref loc;
18005 if (host_integerp (val, 0))
18007 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
18011 loc = descr_info_loc (val, base_decl);
18015 add_AT_loc (die, attr, loc);
18018 /* This routine generates DIE for array with hidden descriptor, details
18019 are filled into *info by a langhook. */
18022 gen_descr_array_type_die (tree type, struct array_descr_info *info,
18023 dw_die_ref context_die)
18025 dw_die_ref scope_die = scope_die_for (type, context_die);
18026 dw_die_ref array_die;
18029 array_die = new_die (DW_TAG_array_type, scope_die, type);
18030 add_name_attribute (array_die, type_tag (type));
18031 equate_type_number_to_die (type, array_die);
18033 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18035 && info->ndimensions >= 2)
18036 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18038 if (info->data_location)
18039 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
18041 if (info->associated)
18042 add_descr_info_field (array_die, DW_AT_associated, info->associated,
18044 if (info->allocated)
18045 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
18048 for (dim = 0; dim < info->ndimensions; dim++)
18050 dw_die_ref subrange_die
18051 = new_die (DW_TAG_subrange_type, array_die, NULL);
18053 if (info->dimen[dim].lower_bound)
18055 /* If it is the default value, omit it. */
18058 if (host_integerp (info->dimen[dim].lower_bound, 0)
18059 && (dflt = lower_bound_default ()) != -1
18060 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
18063 add_descr_info_field (subrange_die, DW_AT_lower_bound,
18064 info->dimen[dim].lower_bound,
18067 if (info->dimen[dim].upper_bound)
18068 add_descr_info_field (subrange_die, DW_AT_upper_bound,
18069 info->dimen[dim].upper_bound,
18071 if (info->dimen[dim].stride)
18072 add_descr_info_field (subrange_die, DW_AT_byte_stride,
18073 info->dimen[dim].stride,
18077 gen_type_die (info->element_type, context_die);
18078 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
18080 if (get_AT (array_die, DW_AT_name))
18081 add_pubtype (type, array_die);
18086 gen_entry_point_die (tree decl, dw_die_ref context_die)
18088 tree origin = decl_ultimate_origin (decl);
18089 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
18091 if (origin != NULL)
18092 add_abstract_origin_attribute (decl_die, origin);
18095 add_name_and_src_coords_attributes (decl_die, decl);
18096 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
18097 0, 0, context_die);
18100 if (DECL_ABSTRACT (decl))
18101 equate_decl_number_to_die (decl, decl_die);
18103 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
18107 /* Walk through the list of incomplete types again, trying once more to
18108 emit full debugging info for them. */
18111 retry_incomplete_types (void)
18115 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
18116 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
18117 DINFO_USAGE_DIR_USE))
18118 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
18121 /* Determine what tag to use for a record type. */
18123 static enum dwarf_tag
18124 record_type_tag (tree type)
18126 if (! lang_hooks.types.classify_record)
18127 return DW_TAG_structure_type;
18129 switch (lang_hooks.types.classify_record (type))
18131 case RECORD_IS_STRUCT:
18132 return DW_TAG_structure_type;
18134 case RECORD_IS_CLASS:
18135 return DW_TAG_class_type;
18137 case RECORD_IS_INTERFACE:
18138 if (dwarf_version >= 3 || !dwarf_strict)
18139 return DW_TAG_interface_type;
18140 return DW_TAG_structure_type;
18143 gcc_unreachable ();
18147 /* Generate a DIE to represent an enumeration type. Note that these DIEs
18148 include all of the information about the enumeration values also. Each
18149 enumerated type name/value is listed as a child of the enumerated type
18153 gen_enumeration_type_die (tree type, dw_die_ref context_die)
18155 dw_die_ref type_die = lookup_type_die (type);
18157 if (type_die == NULL)
18159 type_die = new_die (DW_TAG_enumeration_type,
18160 scope_die_for (type, context_die), type);
18161 equate_type_number_to_die (type, type_die);
18162 add_name_attribute (type_die, type_tag (type));
18163 if ((dwarf_version >= 4 || !dwarf_strict)
18164 && ENUM_IS_SCOPED (type))
18165 add_AT_flag (type_die, DW_AT_enum_class, 1);
18167 else if (! TYPE_SIZE (type))
18170 remove_AT (type_die, DW_AT_declaration);
18172 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
18173 given enum type is incomplete, do not generate the DW_AT_byte_size
18174 attribute or the DW_AT_element_list attribute. */
18175 if (TYPE_SIZE (type))
18179 TREE_ASM_WRITTEN (type) = 1;
18180 add_byte_size_attribute (type_die, type);
18181 if (TYPE_STUB_DECL (type) != NULL_TREE)
18183 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
18184 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
18187 /* If the first reference to this type was as the return type of an
18188 inline function, then it may not have a parent. Fix this now. */
18189 if (type_die->die_parent == NULL)
18190 add_child_die (scope_die_for (type, context_die), type_die);
18192 for (link = TYPE_VALUES (type);
18193 link != NULL; link = TREE_CHAIN (link))
18195 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
18196 tree value = TREE_VALUE (link);
18198 add_name_attribute (enum_die,
18199 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
18201 if (TREE_CODE (value) == CONST_DECL)
18202 value = DECL_INITIAL (value);
18204 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
18205 /* DWARF2 does not provide a way of indicating whether or
18206 not enumeration constants are signed or unsigned. GDB
18207 always assumes the values are signed, so we output all
18208 values as if they were signed. That means that
18209 enumeration constants with very large unsigned values
18210 will appear to have negative values in the debugger. */
18211 add_AT_int (enum_die, DW_AT_const_value,
18212 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
18216 add_AT_flag (type_die, DW_AT_declaration, 1);
18218 if (get_AT (type_die, DW_AT_name))
18219 add_pubtype (type, type_die);
18224 /* Generate a DIE to represent either a real live formal parameter decl or to
18225 represent just the type of some formal parameter position in some function
18228 Note that this routine is a bit unusual because its argument may be a
18229 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
18230 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
18231 node. If it's the former then this function is being called to output a
18232 DIE to represent a formal parameter object (or some inlining thereof). If
18233 it's the latter, then this function is only being called to output a
18234 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
18235 argument type of some subprogram type.
18236 If EMIT_NAME_P is true, name and source coordinate attributes
18240 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
18241 dw_die_ref context_die)
18243 tree node_or_origin = node ? node : origin;
18244 tree ultimate_origin;
18245 dw_die_ref parm_die
18246 = new_die (DW_TAG_formal_parameter, context_die, node);
18248 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
18250 case tcc_declaration:
18251 ultimate_origin = decl_ultimate_origin (node_or_origin);
18252 if (node || ultimate_origin)
18253 origin = ultimate_origin;
18254 if (origin != NULL)
18255 add_abstract_origin_attribute (parm_die, origin);
18256 else if (emit_name_p)
18257 add_name_and_src_coords_attributes (parm_die, node);
18259 || (! DECL_ABSTRACT (node_or_origin)
18260 && variably_modified_type_p (TREE_TYPE (node_or_origin),
18261 decl_function_context
18262 (node_or_origin))))
18264 tree type = TREE_TYPE (node_or_origin);
18265 if (decl_by_reference_p (node_or_origin))
18266 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
18269 add_type_attribute (parm_die, type,
18270 TREE_READONLY (node_or_origin),
18271 TREE_THIS_VOLATILE (node_or_origin),
18274 if (origin == NULL && DECL_ARTIFICIAL (node))
18275 add_AT_flag (parm_die, DW_AT_artificial, 1);
18277 if (node && node != origin)
18278 equate_decl_number_to_die (node, parm_die);
18279 if (! DECL_ABSTRACT (node_or_origin))
18280 add_location_or_const_value_attribute (parm_die, node_or_origin,
18286 /* We were called with some kind of a ..._TYPE node. */
18287 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
18291 gcc_unreachable ();
18297 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18298 children DW_TAG_formal_parameter DIEs representing the arguments of the
18301 PARM_PACK must be a function parameter pack.
18302 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18303 must point to the subsequent arguments of the function PACK_ARG belongs to.
18304 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18305 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18306 following the last one for which a DIE was generated. */
18309 gen_formal_parameter_pack_die (tree parm_pack,
18311 dw_die_ref subr_die,
18315 dw_die_ref parm_pack_die;
18317 gcc_assert (parm_pack
18318 && lang_hooks.function_parameter_pack_p (parm_pack)
18321 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
18322 add_src_coords_attributes (parm_pack_die, parm_pack);
18324 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
18326 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
18329 gen_formal_parameter_die (arg, NULL,
18330 false /* Don't emit name attribute. */,
18335 return parm_pack_die;
18338 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18339 at the end of an (ANSI prototyped) formal parameters list. */
18342 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
18344 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
18347 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18348 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18349 parameters as specified in some function type specification (except for
18350 those which appear as part of a function *definition*). */
18353 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
18356 tree formal_type = NULL;
18357 tree first_parm_type;
18360 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
18362 arg = DECL_ARGUMENTS (function_or_method_type);
18363 function_or_method_type = TREE_TYPE (function_or_method_type);
18368 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
18370 /* Make our first pass over the list of formal parameter types and output a
18371 DW_TAG_formal_parameter DIE for each one. */
18372 for (link = first_parm_type; link; )
18374 dw_die_ref parm_die;
18376 formal_type = TREE_VALUE (link);
18377 if (formal_type == void_type_node)
18380 /* Output a (nameless) DIE to represent the formal parameter itself. */
18381 parm_die = gen_formal_parameter_die (formal_type, NULL,
18382 true /* Emit name attribute. */,
18384 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
18385 && link == first_parm_type)
18387 add_AT_flag (parm_die, DW_AT_artificial, 1);
18388 if (dwarf_version >= 3 || !dwarf_strict)
18389 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
18391 else if (arg && DECL_ARTIFICIAL (arg))
18392 add_AT_flag (parm_die, DW_AT_artificial, 1);
18394 link = TREE_CHAIN (link);
18396 arg = DECL_CHAIN (arg);
18399 /* If this function type has an ellipsis, add a
18400 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18401 if (formal_type != void_type_node)
18402 gen_unspecified_parameters_die (function_or_method_type, context_die);
18404 /* Make our second (and final) pass over the list of formal parameter types
18405 and output DIEs to represent those types (as necessary). */
18406 for (link = TYPE_ARG_TYPES (function_or_method_type);
18407 link && TREE_VALUE (link);
18408 link = TREE_CHAIN (link))
18409 gen_type_die (TREE_VALUE (link), context_die);
18412 /* We want to generate the DIE for TYPE so that we can generate the
18413 die for MEMBER, which has been defined; we will need to refer back
18414 to the member declaration nested within TYPE. If we're trying to
18415 generate minimal debug info for TYPE, processing TYPE won't do the
18416 trick; we need to attach the member declaration by hand. */
18419 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
18421 gen_type_die (type, context_die);
18423 /* If we're trying to avoid duplicate debug info, we may not have
18424 emitted the member decl for this function. Emit it now. */
18425 if (TYPE_STUB_DECL (type)
18426 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
18427 && ! lookup_decl_die (member))
18429 dw_die_ref type_die;
18430 gcc_assert (!decl_ultimate_origin (member));
18432 push_decl_scope (type);
18433 type_die = lookup_type_die (type);
18434 if (TREE_CODE (member) == FUNCTION_DECL)
18435 gen_subprogram_die (member, type_die);
18436 else if (TREE_CODE (member) == FIELD_DECL)
18438 /* Ignore the nameless fields that are used to skip bits but handle
18439 C++ anonymous unions and structs. */
18440 if (DECL_NAME (member) != NULL_TREE
18441 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
18442 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
18444 gen_type_die (member_declared_type (member), type_die);
18445 gen_field_die (member, type_die);
18449 gen_variable_die (member, NULL_TREE, type_die);
18455 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18456 may later generate inlined and/or out-of-line instances of. */
18459 dwarf2out_abstract_function (tree decl)
18461 dw_die_ref old_die;
18465 htab_t old_decl_loc_table;
18467 /* Make sure we have the actual abstract inline, not a clone. */
18468 decl = DECL_ORIGIN (decl);
18470 old_die = lookup_decl_die (decl);
18471 if (old_die && get_AT (old_die, DW_AT_inline))
18472 /* We've already generated the abstract instance. */
18475 /* We can be called while recursively when seeing block defining inlined subroutine
18476 DIE. Be sure to not clobber the outer location table nor use it or we would
18477 get locations in abstract instantces. */
18478 old_decl_loc_table = decl_loc_table;
18479 decl_loc_table = NULL;
18481 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18482 we don't get confused by DECL_ABSTRACT. */
18483 if (debug_info_level > DINFO_LEVEL_TERSE)
18485 context = decl_class_context (decl);
18487 gen_type_die_for_member
18488 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
18491 /* Pretend we've just finished compiling this function. */
18492 save_fn = current_function_decl;
18493 current_function_decl = decl;
18494 push_cfun (DECL_STRUCT_FUNCTION (decl));
18496 was_abstract = DECL_ABSTRACT (decl);
18497 set_decl_abstract_flags (decl, 1);
18498 dwarf2out_decl (decl);
18499 if (! was_abstract)
18500 set_decl_abstract_flags (decl, 0);
18502 current_function_decl = save_fn;
18503 decl_loc_table = old_decl_loc_table;
18507 /* Helper function of premark_used_types() which gets called through
18510 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18511 marked as unused by prune_unused_types. */
18514 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
18519 type = (tree) *slot;
18520 die = lookup_type_die (type);
18522 die->die_perennial_p = 1;
18526 /* Helper function of premark_types_used_by_global_vars which gets called
18527 through htab_traverse.
18529 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18530 marked as unused by prune_unused_types. The DIE of the type is marked
18531 only if the global variable using the type will actually be emitted. */
18534 premark_types_used_by_global_vars_helper (void **slot,
18535 void *data ATTRIBUTE_UNUSED)
18537 struct types_used_by_vars_entry *entry;
18540 entry = (struct types_used_by_vars_entry *) *slot;
18541 gcc_assert (entry->type != NULL
18542 && entry->var_decl != NULL);
18543 die = lookup_type_die (entry->type);
18546 /* Ask cgraph if the global variable really is to be emitted.
18547 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18548 struct varpool_node *node = varpool_get_node (entry->var_decl);
18549 if (node && node->needed)
18551 die->die_perennial_p = 1;
18552 /* Keep the parent DIEs as well. */
18553 while ((die = die->die_parent) && die->die_perennial_p == 0)
18554 die->die_perennial_p = 1;
18560 /* Mark all members of used_types_hash as perennial. */
18563 premark_used_types (void)
18565 if (cfun && cfun->used_types_hash)
18566 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
18569 /* Mark all members of types_used_by_vars_entry as perennial. */
18572 premark_types_used_by_global_vars (void)
18574 if (types_used_by_vars_hash)
18575 htab_traverse (types_used_by_vars_hash,
18576 premark_types_used_by_global_vars_helper, NULL);
18579 /* Generate a DIE to represent a declared function (either file-scope or
18583 gen_subprogram_die (tree decl, dw_die_ref context_die)
18585 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
18586 tree origin = decl_ultimate_origin (decl);
18587 dw_die_ref subr_die;
18590 dw_die_ref old_die = lookup_decl_die (decl);
18591 int declaration = (current_function_decl != decl
18592 || class_or_namespace_scope_p (context_die));
18594 premark_used_types ();
18596 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
18597 started to generate the abstract instance of an inline, decided to output
18598 its containing class, and proceeded to emit the declaration of the inline
18599 from the member list for the class. If so, DECLARATION takes priority;
18600 we'll get back to the abstract instance when done with the class. */
18602 /* The class-scope declaration DIE must be the primary DIE. */
18603 if (origin && declaration && class_or_namespace_scope_p (context_die))
18606 gcc_assert (!old_die);
18609 /* Now that the C++ front end lazily declares artificial member fns, we
18610 might need to retrofit the declaration into its class. */
18611 if (!declaration && !origin && !old_die
18612 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
18613 && !class_or_namespace_scope_p (context_die)
18614 && debug_info_level > DINFO_LEVEL_TERSE)
18615 old_die = force_decl_die (decl);
18617 if (origin != NULL)
18619 gcc_assert (!declaration || local_scope_p (context_die));
18621 /* Fixup die_parent for the abstract instance of a nested
18622 inline function. */
18623 if (old_die && old_die->die_parent == NULL)
18624 add_child_die (context_die, old_die);
18626 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
18627 add_abstract_origin_attribute (subr_die, origin);
18631 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
18632 struct dwarf_file_data * file_index = lookup_filename (s.file);
18634 if (!get_AT_flag (old_die, DW_AT_declaration)
18635 /* We can have a normal definition following an inline one in the
18636 case of redefinition of GNU C extern inlines.
18637 It seems reasonable to use AT_specification in this case. */
18638 && !get_AT (old_die, DW_AT_inline))
18640 /* Detect and ignore this case, where we are trying to output
18641 something we have already output. */
18645 /* If the definition comes from the same place as the declaration,
18646 maybe use the old DIE. We always want the DIE for this function
18647 that has the *_pc attributes to be under comp_unit_die so the
18648 debugger can find it. We also need to do this for abstract
18649 instances of inlines, since the spec requires the out-of-line copy
18650 to have the same parent. For local class methods, this doesn't
18651 apply; we just use the old DIE. */
18652 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
18653 && (DECL_ARTIFICIAL (decl)
18654 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
18655 && (get_AT_unsigned (old_die, DW_AT_decl_line)
18656 == (unsigned) s.line))))
18658 subr_die = old_die;
18660 /* Clear out the declaration attribute and the formal parameters.
18661 Do not remove all children, because it is possible that this
18662 declaration die was forced using force_decl_die(). In such
18663 cases die that forced declaration die (e.g. TAG_imported_module)
18664 is one of the children that we do not want to remove. */
18665 remove_AT (subr_die, DW_AT_declaration);
18666 remove_AT (subr_die, DW_AT_object_pointer);
18667 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
18671 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
18672 add_AT_specification (subr_die, old_die);
18673 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
18674 add_AT_file (subr_die, DW_AT_decl_file, file_index);
18675 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
18676 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
18681 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
18683 if (TREE_PUBLIC (decl))
18684 add_AT_flag (subr_die, DW_AT_external, 1);
18686 add_name_and_src_coords_attributes (subr_die, decl);
18687 if (debug_info_level > DINFO_LEVEL_TERSE)
18689 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
18690 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
18691 0, 0, context_die);
18694 add_pure_or_virtual_attribute (subr_die, decl);
18695 if (DECL_ARTIFICIAL (decl))
18696 add_AT_flag (subr_die, DW_AT_artificial, 1);
18698 add_accessibility_attribute (subr_die, decl);
18703 if (!old_die || !get_AT (old_die, DW_AT_inline))
18705 add_AT_flag (subr_die, DW_AT_declaration, 1);
18707 /* If this is an explicit function declaration then generate
18708 a DW_AT_explicit attribute. */
18709 if (lang_hooks.decls.function_decl_explicit_p (decl)
18710 && (dwarf_version >= 3 || !dwarf_strict))
18711 add_AT_flag (subr_die, DW_AT_explicit, 1);
18713 /* The first time we see a member function, it is in the context of
18714 the class to which it belongs. We make sure of this by emitting
18715 the class first. The next time is the definition, which is
18716 handled above. The two may come from the same source text.
18718 Note that force_decl_die() forces function declaration die. It is
18719 later reused to represent definition. */
18720 equate_decl_number_to_die (decl, subr_die);
18723 else if (DECL_ABSTRACT (decl))
18725 if (DECL_DECLARED_INLINE_P (decl))
18727 if (cgraph_function_possibly_inlined_p (decl))
18728 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
18730 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
18734 if (cgraph_function_possibly_inlined_p (decl))
18735 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
18737 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
18740 if (DECL_DECLARED_INLINE_P (decl)
18741 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
18742 add_AT_flag (subr_die, DW_AT_artificial, 1);
18744 equate_decl_number_to_die (decl, subr_die);
18746 else if (!DECL_EXTERNAL (decl))
18748 HOST_WIDE_INT cfa_fb_offset;
18750 if (!old_die || !get_AT (old_die, DW_AT_inline))
18751 equate_decl_number_to_die (decl, subr_die);
18753 if (!flag_reorder_blocks_and_partition)
18755 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
18756 current_function_funcdef_no);
18757 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
18758 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
18759 current_function_funcdef_no);
18760 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
18762 #if VMS_DEBUGGING_INFO
18763 /* HP OpenVMS Industry Standard 64: DWARF Extensions
18764 Section 2.3 Prologue and Epilogue Attributes:
18765 When a breakpoint is set on entry to a function, it is generally
18766 desirable for execution to be suspended, not on the very first
18767 instruction of the function, but rather at a point after the
18768 function's frame has been set up, after any language defined local
18769 declaration processing has been completed, and before execution of
18770 the first statement of the function begins. Debuggers generally
18771 cannot properly determine where this point is. Similarly for a
18772 breakpoint set on exit from a function. The prologue and epilogue
18773 attributes allow a compiler to communicate the location(s) to use. */
18776 dw_fde_ref fde = &fde_table[current_funcdef_fde];
18778 if (fde->dw_fde_vms_end_prologue)
18779 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
18780 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
18782 if (fde->dw_fde_vms_begin_epilogue)
18783 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
18784 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
18788 add_pubname (decl, subr_die);
18789 add_arange (decl, subr_die);
18792 { /* Do nothing for now; maybe need to duplicate die, one for
18793 hot section and one for cold section, then use the hot/cold
18794 section begin/end labels to generate the aranges... */
18796 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
18797 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
18798 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
18799 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
18801 add_pubname (decl, subr_die);
18802 add_arange (decl, subr_die);
18803 add_arange (decl, subr_die);
18807 #ifdef MIPS_DEBUGGING_INFO
18808 /* Add a reference to the FDE for this routine. */
18809 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
18812 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
18814 /* We define the "frame base" as the function's CFA. This is more
18815 convenient for several reasons: (1) It's stable across the prologue
18816 and epilogue, which makes it better than just a frame pointer,
18817 (2) With dwarf3, there exists a one-byte encoding that allows us
18818 to reference the .debug_frame data by proxy, but failing that,
18819 (3) We can at least reuse the code inspection and interpretation
18820 code that determines the CFA position at various points in the
18822 if (dwarf_version >= 3)
18824 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
18825 add_AT_loc (subr_die, DW_AT_frame_base, op);
18829 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
18830 if (list->dw_loc_next)
18831 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
18833 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
18836 /* Compute a displacement from the "steady-state frame pointer" to
18837 the CFA. The former is what all stack slots and argument slots
18838 will reference in the rtl; the later is what we've told the
18839 debugger about. We'll need to adjust all frame_base references
18840 by this displacement. */
18841 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
18843 if (cfun->static_chain_decl)
18844 add_AT_location_description (subr_die, DW_AT_static_link,
18845 loc_list_from_tree (cfun->static_chain_decl, 2));
18848 /* Generate child dies for template paramaters. */
18849 if (debug_info_level > DINFO_LEVEL_TERSE)
18850 gen_generic_params_dies (decl);
18852 /* Now output descriptions of the arguments for this function. This gets
18853 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
18854 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
18855 `...' at the end of the formal parameter list. In order to find out if
18856 there was a trailing ellipsis or not, we must instead look at the type
18857 associated with the FUNCTION_DECL. This will be a node of type
18858 FUNCTION_TYPE. If the chain of type nodes hanging off of this
18859 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
18860 an ellipsis at the end. */
18862 /* In the case where we are describing a mere function declaration, all we
18863 need to do here (and all we *can* do here) is to describe the *types* of
18864 its formal parameters. */
18865 if (debug_info_level <= DINFO_LEVEL_TERSE)
18867 else if (declaration)
18868 gen_formal_types_die (decl, subr_die);
18871 /* Generate DIEs to represent all known formal parameters. */
18872 tree parm = DECL_ARGUMENTS (decl);
18873 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
18874 tree generic_decl_parm = generic_decl
18875 ? DECL_ARGUMENTS (generic_decl)
18878 /* Now we want to walk the list of parameters of the function and
18879 emit their relevant DIEs.
18881 We consider the case of DECL being an instance of a generic function
18882 as well as it being a normal function.
18884 If DECL is an instance of a generic function we walk the
18885 parameters of the generic function declaration _and_ the parameters of
18886 DECL itself. This is useful because we want to emit specific DIEs for
18887 function parameter packs and those are declared as part of the
18888 generic function declaration. In that particular case,
18889 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
18890 That DIE has children DIEs representing the set of arguments
18891 of the pack. Note that the set of pack arguments can be empty.
18892 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
18895 Otherwise, we just consider the parameters of DECL. */
18896 while (generic_decl_parm || parm)
18898 if (generic_decl_parm
18899 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
18900 gen_formal_parameter_pack_die (generic_decl_parm,
18905 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
18907 if (parm == DECL_ARGUMENTS (decl)
18908 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
18910 && (dwarf_version >= 3 || !dwarf_strict))
18911 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
18913 parm = DECL_CHAIN (parm);
18916 if (generic_decl_parm)
18917 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
18920 /* Decide whether we need an unspecified_parameters DIE at the end.
18921 There are 2 more cases to do this for: 1) the ansi ... declaration -
18922 this is detectable when the end of the arg list is not a
18923 void_type_node 2) an unprototyped function declaration (not a
18924 definition). This just means that we have no info about the
18925 parameters at all. */
18926 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
18927 if (fn_arg_types != NULL)
18929 /* This is the prototyped case, check for.... */
18930 if (stdarg_p (TREE_TYPE (decl)))
18931 gen_unspecified_parameters_die (decl, subr_die);
18933 else if (DECL_INITIAL (decl) == NULL_TREE)
18934 gen_unspecified_parameters_die (decl, subr_die);
18937 /* Output Dwarf info for all of the stuff within the body of the function
18938 (if it has one - it may be just a declaration). */
18939 outer_scope = DECL_INITIAL (decl);
18941 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
18942 a function. This BLOCK actually represents the outermost binding contour
18943 for the function, i.e. the contour in which the function's formal
18944 parameters and labels get declared. Curiously, it appears that the front
18945 end doesn't actually put the PARM_DECL nodes for the current function onto
18946 the BLOCK_VARS list for this outer scope, but are strung off of the
18947 DECL_ARGUMENTS list for the function instead.
18949 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
18950 the LABEL_DECL nodes for the function however, and we output DWARF info
18951 for those in decls_for_scope. Just within the `outer_scope' there will be
18952 a BLOCK node representing the function's outermost pair of curly braces,
18953 and any blocks used for the base and member initializers of a C++
18954 constructor function. */
18955 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
18957 /* Emit a DW_TAG_variable DIE for a named return value. */
18958 if (DECL_NAME (DECL_RESULT (decl)))
18959 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
18961 current_function_has_inlines = 0;
18962 decls_for_scope (outer_scope, subr_die, 0);
18964 #if 0 && defined (MIPS_DEBUGGING_INFO)
18965 if (current_function_has_inlines)
18967 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
18968 if (! comp_unit_has_inlines)
18970 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
18971 comp_unit_has_inlines = 1;
18976 /* Add the calling convention attribute if requested. */
18977 add_calling_convention_attribute (subr_die, decl);
18981 /* Returns a hash value for X (which really is a die_struct). */
18984 common_block_die_table_hash (const void *x)
18986 const_dw_die_ref d = (const_dw_die_ref) x;
18987 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
18990 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18991 as decl_id and die_parent of die_struct Y. */
18994 common_block_die_table_eq (const void *x, const void *y)
18996 const_dw_die_ref d = (const_dw_die_ref) x;
18997 const_dw_die_ref e = (const_dw_die_ref) y;
18998 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
19001 /* Generate a DIE to represent a declared data object.
19002 Either DECL or ORIGIN must be non-null. */
19005 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
19009 tree decl_or_origin = decl ? decl : origin;
19010 tree ultimate_origin;
19011 dw_die_ref var_die;
19012 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
19013 dw_die_ref origin_die;
19014 bool declaration = (DECL_EXTERNAL (decl_or_origin)
19015 || class_or_namespace_scope_p (context_die));
19016 bool specialization_p = false;
19018 ultimate_origin = decl_ultimate_origin (decl_or_origin);
19019 if (decl || ultimate_origin)
19020 origin = ultimate_origin;
19021 com_decl = fortran_common (decl_or_origin, &off);
19023 /* Symbol in common gets emitted as a child of the common block, in the form
19024 of a data member. */
19027 dw_die_ref com_die;
19028 dw_loc_list_ref loc;
19029 die_node com_die_arg;
19031 var_die = lookup_decl_die (decl_or_origin);
19034 if (get_AT (var_die, DW_AT_location) == NULL)
19036 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
19041 /* Optimize the common case. */
19042 if (single_element_loc_list_p (loc)
19043 && loc->expr->dw_loc_opc == DW_OP_addr
19044 && loc->expr->dw_loc_next == NULL
19045 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
19047 loc->expr->dw_loc_oprnd1.v.val_addr
19048 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19050 loc_list_plus_const (loc, off);
19052 add_AT_location_description (var_die, DW_AT_location, loc);
19053 remove_AT (var_die, DW_AT_declaration);
19059 if (common_block_die_table == NULL)
19060 common_block_die_table
19061 = htab_create_ggc (10, common_block_die_table_hash,
19062 common_block_die_table_eq, NULL);
19064 com_die_arg.decl_id = DECL_UID (com_decl);
19065 com_die_arg.die_parent = context_die;
19066 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
19067 loc = loc_list_from_tree (com_decl, 2);
19068 if (com_die == NULL)
19071 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
19074 com_die = new_die (DW_TAG_common_block, context_die, decl);
19075 add_name_and_src_coords_attributes (com_die, com_decl);
19078 add_AT_location_description (com_die, DW_AT_location, loc);
19079 /* Avoid sharing the same loc descriptor between
19080 DW_TAG_common_block and DW_TAG_variable. */
19081 loc = loc_list_from_tree (com_decl, 2);
19083 else if (DECL_EXTERNAL (decl))
19084 add_AT_flag (com_die, DW_AT_declaration, 1);
19085 add_pubname_string (cnam, com_die); /* ??? needed? */
19086 com_die->decl_id = DECL_UID (com_decl);
19087 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
19088 *slot = (void *) com_die;
19090 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
19092 add_AT_location_description (com_die, DW_AT_location, loc);
19093 loc = loc_list_from_tree (com_decl, 2);
19094 remove_AT (com_die, DW_AT_declaration);
19096 var_die = new_die (DW_TAG_variable, com_die, decl);
19097 add_name_and_src_coords_attributes (var_die, decl);
19098 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
19099 TREE_THIS_VOLATILE (decl), context_die);
19100 add_AT_flag (var_die, DW_AT_external, 1);
19105 /* Optimize the common case. */
19106 if (single_element_loc_list_p (loc)
19107 && loc->expr->dw_loc_opc == DW_OP_addr
19108 && loc->expr->dw_loc_next == NULL
19109 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
19110 loc->expr->dw_loc_oprnd1.v.val_addr
19111 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19113 loc_list_plus_const (loc, off);
19115 add_AT_location_description (var_die, DW_AT_location, loc);
19117 else if (DECL_EXTERNAL (decl))
19118 add_AT_flag (var_die, DW_AT_declaration, 1);
19119 equate_decl_number_to_die (decl, var_die);
19123 /* If the compiler emitted a definition for the DECL declaration
19124 and if we already emitted a DIE for it, don't emit a second
19125 DIE for it again. Allow re-declarations of DECLs that are
19126 inside functions, though. */
19127 if (old_die && declaration && !local_scope_p (context_die))
19130 /* For static data members, the declaration in the class is supposed
19131 to have DW_TAG_member tag; the specification should still be
19132 DW_TAG_variable referencing the DW_TAG_member DIE. */
19133 if (declaration && class_scope_p (context_die))
19134 var_die = new_die (DW_TAG_member, context_die, decl);
19136 var_die = new_die (DW_TAG_variable, context_die, decl);
19139 if (origin != NULL)
19140 origin_die = add_abstract_origin_attribute (var_die, origin);
19142 /* Loop unrolling can create multiple blocks that refer to the same
19143 static variable, so we must test for the DW_AT_declaration flag.
19145 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19146 copy decls and set the DECL_ABSTRACT flag on them instead of
19149 ??? Duplicated blocks have been rewritten to use .debug_ranges.
19151 ??? The declare_in_namespace support causes us to get two DIEs for one
19152 variable, both of which are declarations. We want to avoid considering
19153 one to be a specification, so we must test that this DIE is not a
19155 else if (old_die && TREE_STATIC (decl) && ! declaration
19156 && get_AT_flag (old_die, DW_AT_declaration) == 1)
19158 /* This is a definition of a C++ class level static. */
19159 add_AT_specification (var_die, old_die);
19160 specialization_p = true;
19161 if (DECL_NAME (decl))
19163 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
19164 struct dwarf_file_data * file_index = lookup_filename (s.file);
19166 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
19167 add_AT_file (var_die, DW_AT_decl_file, file_index);
19169 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
19170 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
19172 if (old_die->die_tag == DW_TAG_member)
19173 add_linkage_name (var_die, decl);
19177 add_name_and_src_coords_attributes (var_die, decl);
19179 if ((origin == NULL && !specialization_p)
19181 && !DECL_ABSTRACT (decl_or_origin)
19182 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
19183 decl_function_context
19184 (decl_or_origin))))
19186 tree type = TREE_TYPE (decl_or_origin);
19188 if (decl_by_reference_p (decl_or_origin))
19189 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
19191 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
19192 TREE_THIS_VOLATILE (decl_or_origin), context_die);
19195 if (origin == NULL && !specialization_p)
19197 if (TREE_PUBLIC (decl))
19198 add_AT_flag (var_die, DW_AT_external, 1);
19200 if (DECL_ARTIFICIAL (decl))
19201 add_AT_flag (var_die, DW_AT_artificial, 1);
19203 add_accessibility_attribute (var_die, decl);
19207 add_AT_flag (var_die, DW_AT_declaration, 1);
19209 if (decl && (DECL_ABSTRACT (decl) || declaration))
19210 equate_decl_number_to_die (decl, var_die);
19213 && (! DECL_ABSTRACT (decl_or_origin)
19214 /* Local static vars are shared between all clones/inlines,
19215 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19217 || (TREE_CODE (decl_or_origin) == VAR_DECL
19218 && TREE_STATIC (decl_or_origin)
19219 && DECL_RTL_SET_P (decl_or_origin)))
19220 /* When abstract origin already has DW_AT_location attribute, no need
19221 to add it again. */
19222 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
19224 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
19225 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
19226 defer_location (decl_or_origin, var_die);
19228 add_location_or_const_value_attribute (var_die,
19231 add_pubname (decl_or_origin, var_die);
19234 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
19237 /* Generate a DIE to represent a named constant. */
19240 gen_const_die (tree decl, dw_die_ref context_die)
19242 dw_die_ref const_die;
19243 tree type = TREE_TYPE (decl);
19245 const_die = new_die (DW_TAG_constant, context_die, decl);
19246 add_name_and_src_coords_attributes (const_die, decl);
19247 add_type_attribute (const_die, type, 1, 0, context_die);
19248 if (TREE_PUBLIC (decl))
19249 add_AT_flag (const_die, DW_AT_external, 1);
19250 if (DECL_ARTIFICIAL (decl))
19251 add_AT_flag (const_die, DW_AT_artificial, 1);
19252 tree_add_const_value_attribute_for_decl (const_die, decl);
19255 /* Generate a DIE to represent a label identifier. */
19258 gen_label_die (tree decl, dw_die_ref context_die)
19260 tree origin = decl_ultimate_origin (decl);
19261 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
19263 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19265 if (origin != NULL)
19266 add_abstract_origin_attribute (lbl_die, origin);
19268 add_name_and_src_coords_attributes (lbl_die, decl);
19270 if (DECL_ABSTRACT (decl))
19271 equate_decl_number_to_die (decl, lbl_die);
19274 insn = DECL_RTL_IF_SET (decl);
19276 /* Deleted labels are programmer specified labels which have been
19277 eliminated because of various optimizations. We still emit them
19278 here so that it is possible to put breakpoints on them. */
19282 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
19284 /* When optimization is enabled (via -O) some parts of the compiler
19285 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19286 represent source-level labels which were explicitly declared by
19287 the user. This really shouldn't be happening though, so catch
19288 it if it ever does happen. */
19289 gcc_assert (!INSN_DELETED_P (insn));
19291 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
19292 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
19297 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19298 attributes to the DIE for a block STMT, to describe where the inlined
19299 function was called from. This is similar to add_src_coords_attributes. */
19302 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
19304 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
19306 if (dwarf_version >= 3 || !dwarf_strict)
19308 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
19309 add_AT_unsigned (die, DW_AT_call_line, s.line);
19314 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19315 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19318 add_high_low_attributes (tree stmt, dw_die_ref die)
19320 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19322 if (BLOCK_FRAGMENT_CHAIN (stmt)
19323 && (dwarf_version >= 3 || !dwarf_strict))
19327 if (inlined_function_outer_scope_p (stmt))
19329 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19330 BLOCK_NUMBER (stmt));
19331 add_AT_lbl_id (die, DW_AT_entry_pc, label);
19334 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
19336 chain = BLOCK_FRAGMENT_CHAIN (stmt);
19339 add_ranges (chain);
19340 chain = BLOCK_FRAGMENT_CHAIN (chain);
19347 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19348 BLOCK_NUMBER (stmt));
19349 add_AT_lbl_id (die, DW_AT_low_pc, label);
19350 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
19351 BLOCK_NUMBER (stmt));
19352 add_AT_lbl_id (die, DW_AT_high_pc, label);
19356 /* Generate a DIE for a lexical block. */
19359 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
19361 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
19363 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
19364 add_high_low_attributes (stmt, stmt_die);
19366 decls_for_scope (stmt, stmt_die, depth);
19369 /* Generate a DIE for an inlined subprogram. */
19372 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
19376 /* The instance of function that is effectively being inlined shall not
19378 gcc_assert (! BLOCK_ABSTRACT (stmt));
19380 decl = block_ultimate_origin (stmt);
19382 /* Emit info for the abstract instance first, if we haven't yet. We
19383 must emit this even if the block is abstract, otherwise when we
19384 emit the block below (or elsewhere), we may end up trying to emit
19385 a die whose origin die hasn't been emitted, and crashing. */
19386 dwarf2out_abstract_function (decl);
19388 if (! BLOCK_ABSTRACT (stmt))
19390 dw_die_ref subr_die
19391 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
19393 add_abstract_origin_attribute (subr_die, decl);
19394 if (TREE_ASM_WRITTEN (stmt))
19395 add_high_low_attributes (stmt, subr_die);
19396 add_call_src_coords_attributes (stmt, subr_die);
19398 decls_for_scope (stmt, subr_die, depth);
19399 current_function_has_inlines = 1;
19403 /* Generate a DIE for a field in a record, or structure. */
19406 gen_field_die (tree decl, dw_die_ref context_die)
19408 dw_die_ref decl_die;
19410 if (TREE_TYPE (decl) == error_mark_node)
19413 decl_die = new_die (DW_TAG_member, context_die, decl);
19414 add_name_and_src_coords_attributes (decl_die, decl);
19415 add_type_attribute (decl_die, member_declared_type (decl),
19416 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
19419 if (DECL_BIT_FIELD_TYPE (decl))
19421 add_byte_size_attribute (decl_die, decl);
19422 add_bit_size_attribute (decl_die, decl);
19423 add_bit_offset_attribute (decl_die, decl);
19426 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
19427 add_data_member_location_attribute (decl_die, decl);
19429 if (DECL_ARTIFICIAL (decl))
19430 add_AT_flag (decl_die, DW_AT_artificial, 1);
19432 add_accessibility_attribute (decl_die, decl);
19434 /* Equate decl number to die, so that we can look up this decl later on. */
19435 equate_decl_number_to_die (decl, decl_die);
19439 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19440 Use modified_type_die instead.
19441 We keep this code here just in case these types of DIEs may be needed to
19442 represent certain things in other languages (e.g. Pascal) someday. */
19445 gen_pointer_type_die (tree type, dw_die_ref context_die)
19448 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
19450 equate_type_number_to_die (type, ptr_die);
19451 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
19452 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
19455 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19456 Use modified_type_die instead.
19457 We keep this code here just in case these types of DIEs may be needed to
19458 represent certain things in other languages (e.g. Pascal) someday. */
19461 gen_reference_type_die (tree type, dw_die_ref context_die)
19463 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
19465 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
19466 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
19468 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
19470 equate_type_number_to_die (type, ref_die);
19471 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
19472 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
19476 /* Generate a DIE for a pointer to a member type. */
19479 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
19482 = new_die (DW_TAG_ptr_to_member_type,
19483 scope_die_for (type, context_die), type);
19485 equate_type_number_to_die (type, ptr_die);
19486 add_AT_die_ref (ptr_die, DW_AT_containing_type,
19487 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
19488 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
19491 /* Generate the DIE for the compilation unit. */
19494 gen_compile_unit_die (const char *filename)
19497 char producer[250];
19498 const char *language_string = lang_hooks.name;
19501 die = new_die (DW_TAG_compile_unit, NULL, NULL);
19505 add_name_attribute (die, filename);
19506 /* Don't add cwd for <built-in>. */
19507 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
19508 add_comp_dir_attribute (die);
19511 sprintf (producer, "%s %s", language_string, version_string);
19513 #ifdef MIPS_DEBUGGING_INFO
19514 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
19515 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
19516 not appear in the producer string, the debugger reaches the conclusion
19517 that the object file is stripped and has no debugging information.
19518 To get the MIPS/SGI debugger to believe that there is debugging
19519 information in the object file, we add a -g to the producer string. */
19520 if (debug_info_level > DINFO_LEVEL_TERSE)
19521 strcat (producer, " -g");
19524 add_AT_string (die, DW_AT_producer, producer);
19526 language = DW_LANG_C89;
19527 if (strcmp (language_string, "GNU C++") == 0)
19528 language = DW_LANG_C_plus_plus;
19529 else if (strcmp (language_string, "GNU F77") == 0)
19530 language = DW_LANG_Fortran77;
19531 else if (strcmp (language_string, "GNU Pascal") == 0)
19532 language = DW_LANG_Pascal83;
19533 else if (dwarf_version >= 3 || !dwarf_strict)
19535 if (strcmp (language_string, "GNU Ada") == 0)
19536 language = DW_LANG_Ada95;
19537 else if (strcmp (language_string, "GNU Fortran") == 0)
19538 language = DW_LANG_Fortran95;
19539 else if (strcmp (language_string, "GNU Java") == 0)
19540 language = DW_LANG_Java;
19541 else if (strcmp (language_string, "GNU Objective-C") == 0)
19542 language = DW_LANG_ObjC;
19543 else if (strcmp (language_string, "GNU Objective-C++") == 0)
19544 language = DW_LANG_ObjC_plus_plus;
19547 add_AT_unsigned (die, DW_AT_language, language);
19551 case DW_LANG_Fortran77:
19552 case DW_LANG_Fortran90:
19553 case DW_LANG_Fortran95:
19554 /* Fortran has case insensitive identifiers and the front-end
19555 lowercases everything. */
19556 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
19559 /* The default DW_ID_case_sensitive doesn't need to be specified. */
19565 /* Generate the DIE for a base class. */
19568 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
19570 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
19572 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
19573 add_data_member_location_attribute (die, binfo);
19575 if (BINFO_VIRTUAL_P (binfo))
19576 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
19578 if (access == access_public_node)
19579 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
19580 else if (access == access_protected_node)
19581 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
19584 /* Generate a DIE for a class member. */
19587 gen_member_die (tree type, dw_die_ref context_die)
19590 tree binfo = TYPE_BINFO (type);
19593 /* If this is not an incomplete type, output descriptions of each of its
19594 members. Note that as we output the DIEs necessary to represent the
19595 members of this record or union type, we will also be trying to output
19596 DIEs to represent the *types* of those members. However the `type'
19597 function (above) will specifically avoid generating type DIEs for member
19598 types *within* the list of member DIEs for this (containing) type except
19599 for those types (of members) which are explicitly marked as also being
19600 members of this (containing) type themselves. The g++ front- end can
19601 force any given type to be treated as a member of some other (containing)
19602 type by setting the TYPE_CONTEXT of the given (member) type to point to
19603 the TREE node representing the appropriate (containing) type. */
19605 /* First output info about the base classes. */
19608 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
19612 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
19613 gen_inheritance_die (base,
19614 (accesses ? VEC_index (tree, accesses, i)
19615 : access_public_node), context_die);
19618 /* Now output info about the data members and type members. */
19619 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
19621 /* If we thought we were generating minimal debug info for TYPE
19622 and then changed our minds, some of the member declarations
19623 may have already been defined. Don't define them again, but
19624 do put them in the right order. */
19626 child = lookup_decl_die (member);
19628 splice_child_die (context_die, child);
19630 gen_decl_die (member, NULL, context_die);
19633 /* Now output info about the function members (if any). */
19634 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
19636 /* Don't include clones in the member list. */
19637 if (DECL_ABSTRACT_ORIGIN (member))
19640 child = lookup_decl_die (member);
19642 splice_child_die (context_die, child);
19644 gen_decl_die (member, NULL, context_die);
19648 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19649 is set, we pretend that the type was never defined, so we only get the
19650 member DIEs needed by later specification DIEs. */
19653 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
19654 enum debug_info_usage usage)
19656 dw_die_ref type_die = lookup_type_die (type);
19657 dw_die_ref scope_die = 0;
19659 int complete = (TYPE_SIZE (type)
19660 && (! TYPE_STUB_DECL (type)
19661 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
19662 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
19663 complete = complete && should_emit_struct_debug (type, usage);
19665 if (type_die && ! complete)
19668 if (TYPE_CONTEXT (type) != NULL_TREE
19669 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
19670 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
19673 scope_die = scope_die_for (type, context_die);
19675 if (! type_die || (nested && scope_die == comp_unit_die))
19676 /* First occurrence of type or toplevel definition of nested class. */
19678 dw_die_ref old_die = type_die;
19680 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
19681 ? record_type_tag (type) : DW_TAG_union_type,
19683 equate_type_number_to_die (type, type_die);
19685 add_AT_specification (type_die, old_die);
19687 add_name_attribute (type_die, type_tag (type));
19690 remove_AT (type_die, DW_AT_declaration);
19692 /* Generate child dies for template paramaters. */
19693 if (debug_info_level > DINFO_LEVEL_TERSE
19694 && COMPLETE_TYPE_P (type))
19695 gen_generic_params_dies (type);
19697 /* If this type has been completed, then give it a byte_size attribute and
19698 then give a list of members. */
19699 if (complete && !ns_decl)
19701 /* Prevent infinite recursion in cases where the type of some member of
19702 this type is expressed in terms of this type itself. */
19703 TREE_ASM_WRITTEN (type) = 1;
19704 add_byte_size_attribute (type_die, type);
19705 if (TYPE_STUB_DECL (type) != NULL_TREE)
19707 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
19708 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
19711 /* If the first reference to this type was as the return type of an
19712 inline function, then it may not have a parent. Fix this now. */
19713 if (type_die->die_parent == NULL)
19714 add_child_die (scope_die, type_die);
19716 push_decl_scope (type);
19717 gen_member_die (type, type_die);
19720 /* GNU extension: Record what type our vtable lives in. */
19721 if (TYPE_VFIELD (type))
19723 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
19725 gen_type_die (vtype, context_die);
19726 add_AT_die_ref (type_die, DW_AT_containing_type,
19727 lookup_type_die (vtype));
19732 add_AT_flag (type_die, DW_AT_declaration, 1);
19734 /* We don't need to do this for function-local types. */
19735 if (TYPE_STUB_DECL (type)
19736 && ! decl_function_context (TYPE_STUB_DECL (type)))
19737 VEC_safe_push (tree, gc, incomplete_types, type);
19740 if (get_AT (type_die, DW_AT_name))
19741 add_pubtype (type, type_die);
19744 /* Generate a DIE for a subroutine _type_. */
19747 gen_subroutine_type_die (tree type, dw_die_ref context_die)
19749 tree return_type = TREE_TYPE (type);
19750 dw_die_ref subr_die
19751 = new_die (DW_TAG_subroutine_type,
19752 scope_die_for (type, context_die), type);
19754 equate_type_number_to_die (type, subr_die);
19755 add_prototyped_attribute (subr_die, type);
19756 add_type_attribute (subr_die, return_type, 0, 0, context_die);
19757 gen_formal_types_die (type, subr_die);
19759 if (get_AT (subr_die, DW_AT_name))
19760 add_pubtype (type, subr_die);
19763 /* Generate a DIE for a type definition. */
19766 gen_typedef_die (tree decl, dw_die_ref context_die)
19768 dw_die_ref type_die;
19771 if (TREE_ASM_WRITTEN (decl))
19774 TREE_ASM_WRITTEN (decl) = 1;
19775 type_die = new_die (DW_TAG_typedef, context_die, decl);
19776 origin = decl_ultimate_origin (decl);
19777 if (origin != NULL)
19778 add_abstract_origin_attribute (type_die, origin);
19783 add_name_and_src_coords_attributes (type_die, decl);
19784 if (DECL_ORIGINAL_TYPE (decl))
19786 type = DECL_ORIGINAL_TYPE (decl);
19788 gcc_assert (type != TREE_TYPE (decl));
19789 equate_type_number_to_die (TREE_TYPE (decl), type_die);
19793 type = TREE_TYPE (decl);
19795 if (is_naming_typedef_decl (TYPE_NAME (type)))
19797 /* Here, we are in the case of decl being a typedef naming
19798 an anonymous type, e.g:
19799 typedef struct {...} foo;
19800 In that case TREE_TYPE (decl) is not a typedef variant
19801 type and TYPE_NAME of the anonymous type is set to the
19802 TYPE_DECL of the typedef. This construct is emitted by
19805 TYPE is the anonymous struct named by the typedef
19806 DECL. As we need the DW_AT_type attribute of the
19807 DW_TAG_typedef to point to the DIE of TYPE, let's
19808 generate that DIE right away. add_type_attribute
19809 called below will then pick (via lookup_type_die) that
19810 anonymous struct DIE. */
19811 if (!TREE_ASM_WRITTEN (type))
19812 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
19816 add_type_attribute (type_die, type, TREE_READONLY (decl),
19817 TREE_THIS_VOLATILE (decl), context_die);
19819 if (is_naming_typedef_decl (decl))
19820 /* We want that all subsequent calls to lookup_type_die with
19821 TYPE in argument yield the DW_TAG_typedef we have just
19823 equate_type_number_to_die (type, type_die);
19825 add_accessibility_attribute (type_die, decl);
19828 if (DECL_ABSTRACT (decl))
19829 equate_decl_number_to_die (decl, type_die);
19831 if (get_AT (type_die, DW_AT_name))
19832 add_pubtype (decl, type_die);
19835 /* Generate a DIE for a struct, class, enum or union type. */
19838 gen_tagged_type_die (tree type,
19839 dw_die_ref context_die,
19840 enum debug_info_usage usage)
19844 if (type == NULL_TREE
19845 || !is_tagged_type (type))
19848 /* If this is a nested type whose containing class hasn't been written
19849 out yet, writing it out will cover this one, too. This does not apply
19850 to instantiations of member class templates; they need to be added to
19851 the containing class as they are generated. FIXME: This hurts the
19852 idea of combining type decls from multiple TUs, since we can't predict
19853 what set of template instantiations we'll get. */
19854 if (TYPE_CONTEXT (type)
19855 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
19856 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
19858 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
19860 if (TREE_ASM_WRITTEN (type))
19863 /* If that failed, attach ourselves to the stub. */
19864 push_decl_scope (TYPE_CONTEXT (type));
19865 context_die = lookup_type_die (TYPE_CONTEXT (type));
19868 else if (TYPE_CONTEXT (type) != NULL_TREE
19869 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
19871 /* If this type is local to a function that hasn't been written
19872 out yet, use a NULL context for now; it will be fixed up in
19873 decls_for_scope. */
19874 context_die = lookup_decl_die (TYPE_CONTEXT (type));
19879 context_die = declare_in_namespace (type, context_die);
19883 if (TREE_CODE (type) == ENUMERAL_TYPE)
19885 /* This might have been written out by the call to
19886 declare_in_namespace. */
19887 if (!TREE_ASM_WRITTEN (type))
19888 gen_enumeration_type_die (type, context_die);
19891 gen_struct_or_union_type_die (type, context_die, usage);
19896 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19897 it up if it is ever completed. gen_*_type_die will set it for us
19898 when appropriate. */
19901 /* Generate a type description DIE. */
19904 gen_type_die_with_usage (tree type, dw_die_ref context_die,
19905 enum debug_info_usage usage)
19907 struct array_descr_info info;
19909 if (type == NULL_TREE || type == error_mark_node)
19912 /* If TYPE is a typedef type variant, let's generate debug info
19913 for the parent typedef which TYPE is a type of. */
19914 if (typedef_variant_p (type))
19916 if (TREE_ASM_WRITTEN (type))
19919 /* Prevent broken recursion; we can't hand off to the same type. */
19920 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
19922 /* Use the DIE of the containing namespace as the parent DIE of
19923 the type description DIE we want to generate. */
19924 if (DECL_CONTEXT (TYPE_NAME (type))
19925 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
19926 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
19928 TREE_ASM_WRITTEN (type) = 1;
19930 gen_decl_die (TYPE_NAME (type), NULL, context_die);
19934 /* If type is an anonymous tagged type named by a typedef, let's
19935 generate debug info for the typedef. */
19936 if (is_naming_typedef_decl (TYPE_NAME (type)))
19938 /* Use the DIE of the containing namespace as the parent DIE of
19939 the type description DIE we want to generate. */
19940 if (DECL_CONTEXT (TYPE_NAME (type))
19941 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
19942 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
19944 gen_decl_die (TYPE_NAME (type), NULL, context_die);
19948 /* If this is an array type with hidden descriptor, handle it first. */
19949 if (!TREE_ASM_WRITTEN (type)
19950 && lang_hooks.types.get_array_descr_info
19951 && lang_hooks.types.get_array_descr_info (type, &info)
19952 && (dwarf_version >= 3 || !dwarf_strict))
19954 gen_descr_array_type_die (type, &info, context_die);
19955 TREE_ASM_WRITTEN (type) = 1;
19959 /* We are going to output a DIE to represent the unqualified version
19960 of this type (i.e. without any const or volatile qualifiers) so
19961 get the main variant (i.e. the unqualified version) of this type
19962 now. (Vectors are special because the debugging info is in the
19963 cloned type itself). */
19964 if (TREE_CODE (type) != VECTOR_TYPE)
19965 type = type_main_variant (type);
19967 if (TREE_ASM_WRITTEN (type))
19970 switch (TREE_CODE (type))
19976 case REFERENCE_TYPE:
19977 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19978 ensures that the gen_type_die recursion will terminate even if the
19979 type is recursive. Recursive types are possible in Ada. */
19980 /* ??? We could perhaps do this for all types before the switch
19982 TREE_ASM_WRITTEN (type) = 1;
19984 /* For these types, all that is required is that we output a DIE (or a
19985 set of DIEs) to represent the "basis" type. */
19986 gen_type_die_with_usage (TREE_TYPE (type), context_die,
19987 DINFO_USAGE_IND_USE);
19991 /* This code is used for C++ pointer-to-data-member types.
19992 Output a description of the relevant class type. */
19993 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
19994 DINFO_USAGE_IND_USE);
19996 /* Output a description of the type of the object pointed to. */
19997 gen_type_die_with_usage (TREE_TYPE (type), context_die,
19998 DINFO_USAGE_IND_USE);
20000 /* Now output a DIE to represent this pointer-to-data-member type
20002 gen_ptr_to_mbr_type_die (type, context_die);
20005 case FUNCTION_TYPE:
20006 /* Force out return type (in case it wasn't forced out already). */
20007 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20008 DINFO_USAGE_DIR_USE);
20009 gen_subroutine_type_die (type, context_die);
20013 /* Force out return type (in case it wasn't forced out already). */
20014 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20015 DINFO_USAGE_DIR_USE);
20016 gen_subroutine_type_die (type, context_die);
20020 gen_array_type_die (type, context_die);
20024 gen_array_type_die (type, context_die);
20027 case ENUMERAL_TYPE:
20030 case QUAL_UNION_TYPE:
20031 gen_tagged_type_die (type, context_die, usage);
20037 case FIXED_POINT_TYPE:
20040 /* No DIEs needed for fundamental types. */
20044 /* Just use DW_TAG_unspecified_type. */
20046 dw_die_ref type_die = lookup_type_die (type);
20047 if (type_die == NULL)
20049 tree name = TYPE_NAME (type);
20050 if (TREE_CODE (name) == TYPE_DECL)
20051 name = DECL_NAME (name);
20052 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die, type);
20053 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
20054 equate_type_number_to_die (type, type_die);
20060 gcc_unreachable ();
20063 TREE_ASM_WRITTEN (type) = 1;
20067 gen_type_die (tree type, dw_die_ref context_die)
20069 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
20072 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20073 things which are local to the given block. */
20076 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
20078 int must_output_die = 0;
20081 /* Ignore blocks that are NULL. */
20082 if (stmt == NULL_TREE)
20085 inlined_func = inlined_function_outer_scope_p (stmt);
20087 /* If the block is one fragment of a non-contiguous block, do not
20088 process the variables, since they will have been done by the
20089 origin block. Do process subblocks. */
20090 if (BLOCK_FRAGMENT_ORIGIN (stmt))
20094 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
20095 gen_block_die (sub, context_die, depth + 1);
20100 /* Determine if we need to output any Dwarf DIEs at all to represent this
20103 /* The outer scopes for inlinings *must* always be represented. We
20104 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20105 must_output_die = 1;
20108 /* Determine if this block directly contains any "significant"
20109 local declarations which we will need to output DIEs for. */
20110 if (debug_info_level > DINFO_LEVEL_TERSE)
20111 /* We are not in terse mode so *any* local declaration counts
20112 as being a "significant" one. */
20113 must_output_die = ((BLOCK_VARS (stmt) != NULL
20114 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
20115 && (TREE_USED (stmt)
20116 || TREE_ASM_WRITTEN (stmt)
20117 || BLOCK_ABSTRACT (stmt)));
20118 else if ((TREE_USED (stmt)
20119 || TREE_ASM_WRITTEN (stmt)
20120 || BLOCK_ABSTRACT (stmt))
20121 && !dwarf2out_ignore_block (stmt))
20122 must_output_die = 1;
20125 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20126 DIE for any block which contains no significant local declarations at
20127 all. Rather, in such cases we just call `decls_for_scope' so that any
20128 needed Dwarf info for any sub-blocks will get properly generated. Note
20129 that in terse mode, our definition of what constitutes a "significant"
20130 local declaration gets restricted to include only inlined function
20131 instances and local (nested) function definitions. */
20132 if (must_output_die)
20136 /* If STMT block is abstract, that means we have been called
20137 indirectly from dwarf2out_abstract_function.
20138 That function rightfully marks the descendent blocks (of
20139 the abstract function it is dealing with) as being abstract,
20140 precisely to prevent us from emitting any
20141 DW_TAG_inlined_subroutine DIE as a descendent
20142 of an abstract function instance. So in that case, we should
20143 not call gen_inlined_subroutine_die.
20145 Later though, when cgraph asks dwarf2out to emit info
20146 for the concrete instance of the function decl into which
20147 the concrete instance of STMT got inlined, the later will lead
20148 to the generation of a DW_TAG_inlined_subroutine DIE. */
20149 if (! BLOCK_ABSTRACT (stmt))
20150 gen_inlined_subroutine_die (stmt, context_die, depth);
20153 gen_lexical_block_die (stmt, context_die, depth);
20156 decls_for_scope (stmt, context_die, depth);
20159 /* Process variable DECL (or variable with origin ORIGIN) within
20160 block STMT and add it to CONTEXT_DIE. */
20162 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
20165 tree decl_or_origin = decl ? decl : origin;
20167 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
20168 die = lookup_decl_die (decl_or_origin);
20169 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
20170 && TYPE_DECL_IS_STUB (decl_or_origin))
20171 die = lookup_type_die (TREE_TYPE (decl_or_origin));
20175 if (die != NULL && die->die_parent == NULL)
20176 add_child_die (context_die, die);
20177 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
20178 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
20179 stmt, context_die);
20181 gen_decl_die (decl, origin, context_die);
20184 /* Generate all of the decls declared within a given scope and (recursively)
20185 all of its sub-blocks. */
20188 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
20194 /* Ignore NULL blocks. */
20195 if (stmt == NULL_TREE)
20198 /* Output the DIEs to represent all of the data objects and typedefs
20199 declared directly within this block but not within any nested
20200 sub-blocks. Also, nested function and tag DIEs have been
20201 generated with a parent of NULL; fix that up now. */
20202 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
20203 process_scope_var (stmt, decl, NULL_TREE, context_die);
20204 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
20205 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
20208 /* If we're at -g1, we're not interested in subblocks. */
20209 if (debug_info_level <= DINFO_LEVEL_TERSE)
20212 /* Output the DIEs to represent all sub-blocks (and the items declared
20213 therein) of this block. */
20214 for (subblocks = BLOCK_SUBBLOCKS (stmt);
20216 subblocks = BLOCK_CHAIN (subblocks))
20217 gen_block_die (subblocks, context_die, depth + 1);
20220 /* Is this a typedef we can avoid emitting? */
20223 is_redundant_typedef (const_tree decl)
20225 if (TYPE_DECL_IS_STUB (decl))
20228 if (DECL_ARTIFICIAL (decl)
20229 && DECL_CONTEXT (decl)
20230 && is_tagged_type (DECL_CONTEXT (decl))
20231 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
20232 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
20233 /* Also ignore the artificial member typedef for the class name. */
20239 /* Return TRUE if TYPE is a typedef that names a type for linkage
20240 purposes. This kind of typedefs is produced by the C++ FE for
20243 typedef struct {...} foo;
20245 In that case, there is no typedef variant type produced for foo.
20246 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20250 is_naming_typedef_decl (const_tree decl)
20252 if (decl == NULL_TREE
20253 || TREE_CODE (decl) != TYPE_DECL
20254 || !is_tagged_type (TREE_TYPE (decl))
20255 || DECL_IS_BUILTIN (decl)
20256 || is_redundant_typedef (decl)
20257 /* It looks like Ada produces TYPE_DECLs that are very similar
20258 to C++ naming typedefs but that have different
20259 semantics. Let's be specific to c++ for now. */
20263 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
20264 && TYPE_NAME (TREE_TYPE (decl)) == decl
20265 && (TYPE_STUB_DECL (TREE_TYPE (decl))
20266 != TYPE_NAME (TREE_TYPE (decl))));
20269 /* Returns the DIE for a context. */
20271 static inline dw_die_ref
20272 get_context_die (tree context)
20276 /* Find die that represents this context. */
20277 if (TYPE_P (context))
20278 return force_type_die (TYPE_MAIN_VARIANT (context));
20280 return force_decl_die (context);
20282 return comp_unit_die;
20285 /* Returns the DIE for decl. A DIE will always be returned. */
20288 force_decl_die (tree decl)
20290 dw_die_ref decl_die;
20291 unsigned saved_external_flag;
20292 tree save_fn = NULL_TREE;
20293 decl_die = lookup_decl_die (decl);
20296 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
20298 decl_die = lookup_decl_die (decl);
20302 switch (TREE_CODE (decl))
20304 case FUNCTION_DECL:
20305 /* Clear current_function_decl, so that gen_subprogram_die thinks
20306 that this is a declaration. At this point, we just want to force
20307 declaration die. */
20308 save_fn = current_function_decl;
20309 current_function_decl = NULL_TREE;
20310 gen_subprogram_die (decl, context_die);
20311 current_function_decl = save_fn;
20315 /* Set external flag to force declaration die. Restore it after
20316 gen_decl_die() call. */
20317 saved_external_flag = DECL_EXTERNAL (decl);
20318 DECL_EXTERNAL (decl) = 1;
20319 gen_decl_die (decl, NULL, context_die);
20320 DECL_EXTERNAL (decl) = saved_external_flag;
20323 case NAMESPACE_DECL:
20324 if (dwarf_version >= 3 || !dwarf_strict)
20325 dwarf2out_decl (decl);
20327 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
20328 decl_die = comp_unit_die;
20332 gcc_unreachable ();
20335 /* We should be able to find the DIE now. */
20337 decl_die = lookup_decl_die (decl);
20338 gcc_assert (decl_die);
20344 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
20345 always returned. */
20348 force_type_die (tree type)
20350 dw_die_ref type_die;
20352 type_die = lookup_type_die (type);
20355 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
20357 type_die = modified_type_die (type, TYPE_READONLY (type),
20358 TYPE_VOLATILE (type), context_die);
20359 gcc_assert (type_die);
20364 /* Force out any required namespaces to be able to output DECL,
20365 and return the new context_die for it, if it's changed. */
20368 setup_namespace_context (tree thing, dw_die_ref context_die)
20370 tree context = (DECL_P (thing)
20371 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
20372 if (context && TREE_CODE (context) == NAMESPACE_DECL)
20373 /* Force out the namespace. */
20374 context_die = force_decl_die (context);
20376 return context_die;
20379 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
20380 type) within its namespace, if appropriate.
20382 For compatibility with older debuggers, namespace DIEs only contain
20383 declarations; all definitions are emitted at CU scope. */
20386 declare_in_namespace (tree thing, dw_die_ref context_die)
20388 dw_die_ref ns_context;
20390 if (debug_info_level <= DINFO_LEVEL_TERSE)
20391 return context_die;
20393 /* If this decl is from an inlined function, then don't try to emit it in its
20394 namespace, as we will get confused. It would have already been emitted
20395 when the abstract instance of the inline function was emitted anyways. */
20396 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
20397 return context_die;
20399 ns_context = setup_namespace_context (thing, context_die);
20401 if (ns_context != context_die)
20405 if (DECL_P (thing))
20406 gen_decl_die (thing, NULL, ns_context);
20408 gen_type_die (thing, ns_context);
20410 return context_die;
20413 /* Generate a DIE for a namespace or namespace alias. */
20416 gen_namespace_die (tree decl, dw_die_ref context_die)
20418 dw_die_ref namespace_die;
20420 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
20421 they are an alias of. */
20422 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
20424 /* Output a real namespace or module. */
20425 context_die = setup_namespace_context (decl, comp_unit_die);
20426 namespace_die = new_die (is_fortran ()
20427 ? DW_TAG_module : DW_TAG_namespace,
20428 context_die, decl);
20429 /* For Fortran modules defined in different CU don't add src coords. */
20430 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
20432 const char *name = dwarf2_name (decl, 0);
20434 add_name_attribute (namespace_die, name);
20437 add_name_and_src_coords_attributes (namespace_die, decl);
20438 if (DECL_EXTERNAL (decl))
20439 add_AT_flag (namespace_die, DW_AT_declaration, 1);
20440 equate_decl_number_to_die (decl, namespace_die);
20444 /* Output a namespace alias. */
20446 /* Force out the namespace we are an alias of, if necessary. */
20447 dw_die_ref origin_die
20448 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
20450 if (DECL_CONTEXT (decl) == NULL_TREE
20451 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
20452 context_die = setup_namespace_context (decl, comp_unit_die);
20453 /* Now create the namespace alias DIE. */
20454 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
20455 add_name_and_src_coords_attributes (namespace_die, decl);
20456 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
20457 equate_decl_number_to_die (decl, namespace_die);
20461 /* Generate Dwarf debug information for a decl described by DECL.
20462 The return value is currently only meaningful for PARM_DECLs,
20463 for all other decls it returns NULL. */
20466 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
20468 tree decl_or_origin = decl ? decl : origin;
20469 tree class_origin = NULL, ultimate_origin;
20471 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
20474 switch (TREE_CODE (decl_or_origin))
20480 if (!is_fortran ())
20482 /* The individual enumerators of an enum type get output when we output
20483 the Dwarf representation of the relevant enum type itself. */
20487 /* Emit its type. */
20488 gen_type_die (TREE_TYPE (decl), context_die);
20490 /* And its containing namespace. */
20491 context_die = declare_in_namespace (decl, context_die);
20493 gen_const_die (decl, context_die);
20496 case FUNCTION_DECL:
20497 /* Don't output any DIEs to represent mere function declarations,
20498 unless they are class members or explicit block externs. */
20499 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
20500 && DECL_CONTEXT (decl_or_origin) == NULL_TREE
20501 && (current_function_decl == NULL_TREE
20502 || DECL_ARTIFICIAL (decl_or_origin)))
20507 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
20508 on local redeclarations of global functions. That seems broken. */
20509 if (current_function_decl != decl)
20510 /* This is only a declaration. */;
20513 /* If we're emitting a clone, emit info for the abstract instance. */
20514 if (origin || DECL_ORIGIN (decl) != decl)
20515 dwarf2out_abstract_function (origin
20516 ? DECL_ORIGIN (origin)
20517 : DECL_ABSTRACT_ORIGIN (decl));
20519 /* If we're emitting an out-of-line copy of an inline function,
20520 emit info for the abstract instance and set up to refer to it. */
20521 else if (cgraph_function_possibly_inlined_p (decl)
20522 && ! DECL_ABSTRACT (decl)
20523 && ! class_or_namespace_scope_p (context_die)
20524 /* dwarf2out_abstract_function won't emit a die if this is just
20525 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
20526 that case, because that works only if we have a die. */
20527 && DECL_INITIAL (decl) != NULL_TREE)
20529 dwarf2out_abstract_function (decl);
20530 set_decl_origin_self (decl);
20533 /* Otherwise we're emitting the primary DIE for this decl. */
20534 else if (debug_info_level > DINFO_LEVEL_TERSE)
20536 /* Before we describe the FUNCTION_DECL itself, make sure that we
20537 have described its return type. */
20538 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
20540 /* And its virtual context. */
20541 if (DECL_VINDEX (decl) != NULL_TREE)
20542 gen_type_die (DECL_CONTEXT (decl), context_die);
20544 /* And its containing type. */
20546 origin = decl_class_context (decl);
20547 if (origin != NULL_TREE)
20548 gen_type_die_for_member (origin, decl, context_die);
20550 /* And its containing namespace. */
20551 context_die = declare_in_namespace (decl, context_die);
20554 /* Now output a DIE to represent the function itself. */
20556 gen_subprogram_die (decl, context_die);
20560 /* If we are in terse mode, don't generate any DIEs to represent any
20561 actual typedefs. */
20562 if (debug_info_level <= DINFO_LEVEL_TERSE)
20565 /* In the special case of a TYPE_DECL node representing the declaration
20566 of some type tag, if the given TYPE_DECL is marked as having been
20567 instantiated from some other (original) TYPE_DECL node (e.g. one which
20568 was generated within the original definition of an inline function) we
20569 used to generate a special (abbreviated) DW_TAG_structure_type,
20570 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20571 should be actually referencing those DIEs, as variable DIEs with that
20572 type would be emitted already in the abstract origin, so it was always
20573 removed during unused type prunning. Don't add anything in this
20575 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
20578 if (is_redundant_typedef (decl))
20579 gen_type_die (TREE_TYPE (decl), context_die);
20581 /* Output a DIE to represent the typedef itself. */
20582 gen_typedef_die (decl, context_die);
20586 if (debug_info_level >= DINFO_LEVEL_NORMAL)
20587 gen_label_die (decl, context_die);
20592 /* If we are in terse mode, don't generate any DIEs to represent any
20593 variable declarations or definitions. */
20594 if (debug_info_level <= DINFO_LEVEL_TERSE)
20597 /* Output any DIEs that are needed to specify the type of this data
20599 if (decl_by_reference_p (decl_or_origin))
20600 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
20602 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
20604 /* And its containing type. */
20605 class_origin = decl_class_context (decl_or_origin);
20606 if (class_origin != NULL_TREE)
20607 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
20609 /* And its containing namespace. */
20610 context_die = declare_in_namespace (decl_or_origin, context_die);
20612 /* Now output the DIE to represent the data object itself. This gets
20613 complicated because of the possibility that the VAR_DECL really
20614 represents an inlined instance of a formal parameter for an inline
20616 ultimate_origin = decl_ultimate_origin (decl_or_origin);
20617 if (ultimate_origin != NULL_TREE
20618 && TREE_CODE (ultimate_origin) == PARM_DECL)
20619 gen_formal_parameter_die (decl, origin,
20620 true /* Emit name attribute. */,
20623 gen_variable_die (decl, origin, context_die);
20627 /* Ignore the nameless fields that are used to skip bits but handle C++
20628 anonymous unions and structs. */
20629 if (DECL_NAME (decl) != NULL_TREE
20630 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
20631 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
20633 gen_type_die (member_declared_type (decl), context_die);
20634 gen_field_die (decl, context_die);
20639 if (DECL_BY_REFERENCE (decl_or_origin))
20640 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
20642 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
20643 return gen_formal_parameter_die (decl, origin,
20644 true /* Emit name attribute. */,
20647 case NAMESPACE_DECL:
20648 case IMPORTED_DECL:
20649 if (dwarf_version >= 3 || !dwarf_strict)
20650 gen_namespace_die (decl, context_die);
20654 /* Probably some frontend-internal decl. Assume we don't care. */
20655 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
20662 /* Output debug information for global decl DECL. Called from toplev.c after
20663 compilation proper has finished. */
20666 dwarf2out_global_decl (tree decl)
20668 /* Output DWARF2 information for file-scope tentative data object
20669 declarations, file-scope (extern) function declarations (which
20670 had no corresponding body) and file-scope tagged type declarations
20671 and definitions which have not yet been forced out. */
20672 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
20673 dwarf2out_decl (decl);
20676 /* Output debug information for type decl DECL. Called from toplev.c
20677 and from language front ends (to record built-in types). */
20679 dwarf2out_type_decl (tree decl, int local)
20682 dwarf2out_decl (decl);
20685 /* Output debug information for imported module or decl DECL.
20686 NAME is non-NULL name in the lexical block if the decl has been renamed.
20687 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20688 that DECL belongs to.
20689 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20691 dwarf2out_imported_module_or_decl_1 (tree decl,
20693 tree lexical_block,
20694 dw_die_ref lexical_block_die)
20696 expanded_location xloc;
20697 dw_die_ref imported_die = NULL;
20698 dw_die_ref at_import_die;
20700 if (TREE_CODE (decl) == IMPORTED_DECL)
20702 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
20703 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
20707 xloc = expand_location (input_location);
20709 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
20711 at_import_die = force_type_die (TREE_TYPE (decl));
20712 /* For namespace N { typedef void T; } using N::T; base_type_die
20713 returns NULL, but DW_TAG_imported_declaration requires
20714 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20715 if (!at_import_die)
20717 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
20718 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
20719 at_import_die = lookup_type_die (TREE_TYPE (decl));
20720 gcc_assert (at_import_die);
20725 at_import_die = lookup_decl_die (decl);
20726 if (!at_import_die)
20728 /* If we're trying to avoid duplicate debug info, we may not have
20729 emitted the member decl for this field. Emit it now. */
20730 if (TREE_CODE (decl) == FIELD_DECL)
20732 tree type = DECL_CONTEXT (decl);
20734 if (TYPE_CONTEXT (type)
20735 && TYPE_P (TYPE_CONTEXT (type))
20736 && !should_emit_struct_debug (TYPE_CONTEXT (type),
20737 DINFO_USAGE_DIR_USE))
20739 gen_type_die_for_member (type, decl,
20740 get_context_die (TYPE_CONTEXT (type)));
20742 at_import_die = force_decl_die (decl);
20746 if (TREE_CODE (decl) == NAMESPACE_DECL)
20748 if (dwarf_version >= 3 || !dwarf_strict)
20749 imported_die = new_die (DW_TAG_imported_module,
20756 imported_die = new_die (DW_TAG_imported_declaration,
20760 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
20761 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
20763 add_AT_string (imported_die, DW_AT_name,
20764 IDENTIFIER_POINTER (name));
20765 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
20768 /* Output debug information for imported module or decl DECL.
20769 NAME is non-NULL name in context if the decl has been renamed.
20770 CHILD is true if decl is one of the renamed decls as part of
20771 importing whole module. */
20774 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
20777 /* dw_die_ref at_import_die; */
20778 dw_die_ref scope_die;
20780 if (debug_info_level <= DINFO_LEVEL_TERSE)
20785 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20786 We need decl DIE for reference and scope die. First, get DIE for the decl
20789 /* Get the scope die for decl context. Use comp_unit_die for global module
20790 or decl. If die is not found for non globals, force new die. */
20792 && TYPE_P (context)
20793 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
20796 if (!(dwarf_version >= 3 || !dwarf_strict))
20799 scope_die = get_context_die (context);
20803 gcc_assert (scope_die->die_child);
20804 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
20805 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
20806 scope_die = scope_die->die_child;
20809 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20810 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
20814 /* Write the debugging output for DECL. */
20817 dwarf2out_decl (tree decl)
20819 dw_die_ref context_die = comp_unit_die;
20821 switch (TREE_CODE (decl))
20826 case FUNCTION_DECL:
20827 /* What we would really like to do here is to filter out all mere
20828 file-scope declarations of file-scope functions which are never
20829 referenced later within this translation unit (and keep all of ones
20830 that *are* referenced later on) but we aren't clairvoyant, so we have
20831 no idea which functions will be referenced in the future (i.e. later
20832 on within the current translation unit). So here we just ignore all
20833 file-scope function declarations which are not also definitions. If
20834 and when the debugger needs to know something about these functions,
20835 it will have to hunt around and find the DWARF information associated
20836 with the definition of the function.
20838 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20839 nodes represent definitions and which ones represent mere
20840 declarations. We have to check DECL_INITIAL instead. That's because
20841 the C front-end supports some weird semantics for "extern inline"
20842 function definitions. These can get inlined within the current
20843 translation unit (and thus, we need to generate Dwarf info for their
20844 abstract instances so that the Dwarf info for the concrete inlined
20845 instances can have something to refer to) but the compiler never
20846 generates any out-of-lines instances of such things (despite the fact
20847 that they *are* definitions).
20849 The important point is that the C front-end marks these "extern
20850 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20851 them anyway. Note that the C++ front-end also plays some similar games
20852 for inline function definitions appearing within include files which
20853 also contain `#pragma interface' pragmas. */
20854 if (DECL_INITIAL (decl) == NULL_TREE)
20857 /* If we're a nested function, initially use a parent of NULL; if we're
20858 a plain function, this will be fixed up in decls_for_scope. If
20859 we're a method, it will be ignored, since we already have a DIE. */
20860 if (decl_function_context (decl)
20861 /* But if we're in terse mode, we don't care about scope. */
20862 && debug_info_level > DINFO_LEVEL_TERSE)
20863 context_die = NULL;
20867 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20868 declaration and if the declaration was never even referenced from
20869 within this entire compilation unit. We suppress these DIEs in
20870 order to save space in the .debug section (by eliminating entries
20871 which are probably useless). Note that we must not suppress
20872 block-local extern declarations (whether used or not) because that
20873 would screw-up the debugger's name lookup mechanism and cause it to
20874 miss things which really ought to be in scope at a given point. */
20875 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
20878 /* For local statics lookup proper context die. */
20879 if (TREE_STATIC (decl) && decl_function_context (decl))
20880 context_die = lookup_decl_die (DECL_CONTEXT (decl));
20882 /* If we are in terse mode, don't generate any DIEs to represent any
20883 variable declarations or definitions. */
20884 if (debug_info_level <= DINFO_LEVEL_TERSE)
20889 if (debug_info_level <= DINFO_LEVEL_TERSE)
20891 if (!is_fortran ())
20893 if (TREE_STATIC (decl) && decl_function_context (decl))
20894 context_die = lookup_decl_die (DECL_CONTEXT (decl));
20897 case NAMESPACE_DECL:
20898 case IMPORTED_DECL:
20899 if (debug_info_level <= DINFO_LEVEL_TERSE)
20901 if (lookup_decl_die (decl) != NULL)
20906 /* Don't emit stubs for types unless they are needed by other DIEs. */
20907 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
20910 /* Don't bother trying to generate any DIEs to represent any of the
20911 normal built-in types for the language we are compiling. */
20912 if (DECL_IS_BUILTIN (decl))
20914 /* OK, we need to generate one for `bool' so GDB knows what type
20915 comparisons have. */
20917 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
20918 && ! DECL_IGNORED_P (decl))
20919 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
20924 /* If we are in terse mode, don't generate any DIEs for types. */
20925 if (debug_info_level <= DINFO_LEVEL_TERSE)
20928 /* If we're a function-scope tag, initially use a parent of NULL;
20929 this will be fixed up in decls_for_scope. */
20930 if (decl_function_context (decl))
20931 context_die = NULL;
20939 gen_decl_die (decl, NULL, context_die);
20942 /* Write the debugging output for DECL. */
20945 dwarf2out_function_decl (tree decl)
20947 dwarf2out_decl (decl);
20949 htab_empty (decl_loc_table);
20952 /* Output a marker (i.e. a label) for the beginning of the generated code for
20953 a lexical block. */
20956 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
20957 unsigned int blocknum)
20959 switch_to_section (current_function_section ());
20960 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
20963 /* Output a marker (i.e. a label) for the end of the generated code for a
20967 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
20969 switch_to_section (current_function_section ());
20970 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
20973 /* Returns nonzero if it is appropriate not to emit any debugging
20974 information for BLOCK, because it doesn't contain any instructions.
20976 Don't allow this for blocks with nested functions or local classes
20977 as we would end up with orphans, and in the presence of scheduling
20978 we may end up calling them anyway. */
20981 dwarf2out_ignore_block (const_tree block)
20986 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
20987 if (TREE_CODE (decl) == FUNCTION_DECL
20988 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
20990 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
20992 decl = BLOCK_NONLOCALIZED_VAR (block, i);
20993 if (TREE_CODE (decl) == FUNCTION_DECL
20994 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
21001 /* Hash table routines for file_hash. */
21004 file_table_eq (const void *p1_p, const void *p2_p)
21006 const struct dwarf_file_data *const p1 =
21007 (const struct dwarf_file_data *) p1_p;
21008 const char *const p2 = (const char *) p2_p;
21009 return strcmp (p1->filename, p2) == 0;
21013 file_table_hash (const void *p_p)
21015 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
21016 return htab_hash_string (p->filename);
21019 /* Lookup FILE_NAME (in the list of filenames that we know about here in
21020 dwarf2out.c) and return its "index". The index of each (known) filename is
21021 just a unique number which is associated with only that one filename. We
21022 need such numbers for the sake of generating labels (in the .debug_sfnames
21023 section) and references to those files numbers (in the .debug_srcinfo
21024 and.debug_macinfo sections). If the filename given as an argument is not
21025 found in our current list, add it to the list and assign it the next
21026 available unique index number. In order to speed up searches, we remember
21027 the index of the filename was looked up last. This handles the majority of
21030 static struct dwarf_file_data *
21031 lookup_filename (const char *file_name)
21034 struct dwarf_file_data * created;
21036 /* Check to see if the file name that was searched on the previous
21037 call matches this file name. If so, return the index. */
21038 if (file_table_last_lookup
21039 && (file_name == file_table_last_lookup->filename
21040 || strcmp (file_table_last_lookup->filename, file_name) == 0))
21041 return file_table_last_lookup;
21043 /* Didn't match the previous lookup, search the table. */
21044 slot = htab_find_slot_with_hash (file_table, file_name,
21045 htab_hash_string (file_name), INSERT);
21047 return (struct dwarf_file_data *) *slot;
21049 created = ggc_alloc_dwarf_file_data ();
21050 created->filename = file_name;
21051 created->emitted_number = 0;
21056 /* If the assembler will construct the file table, then translate the compiler
21057 internal file table number into the assembler file table number, and emit
21058 a .file directive if we haven't already emitted one yet. The file table
21059 numbers are different because we prune debug info for unused variables and
21060 types, which may include filenames. */
21063 maybe_emit_file (struct dwarf_file_data * fd)
21065 if (! fd->emitted_number)
21067 if (last_emitted_file)
21068 fd->emitted_number = last_emitted_file->emitted_number + 1;
21070 fd->emitted_number = 1;
21071 last_emitted_file = fd;
21073 if (DWARF2_ASM_LINE_DEBUG_INFO)
21075 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
21076 output_quoted_string (asm_out_file,
21077 remap_debug_filename (fd->filename));
21078 fputc ('\n', asm_out_file);
21082 return fd->emitted_number;
21085 /* Schedule generation of a DW_AT_const_value attribute to DIE.
21086 That generation should happen after function debug info has been
21087 generated. The value of the attribute is the constant value of ARG. */
21090 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
21092 die_arg_entry entry;
21097 if (!tmpl_value_parm_die_table)
21098 tmpl_value_parm_die_table
21099 = VEC_alloc (die_arg_entry, gc, 32);
21103 VEC_safe_push (die_arg_entry, gc,
21104 tmpl_value_parm_die_table,
21108 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
21109 by append_entry_to_tmpl_value_parm_die_table. This function must
21110 be called after function DIEs have been generated. */
21113 gen_remaining_tmpl_value_param_die_attribute (void)
21115 if (tmpl_value_parm_die_table)
21120 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
21121 tree_add_const_value_attribute (e->die, e->arg);
21126 /* Replace DW_AT_name for the decl with name. */
21129 dwarf2out_set_name (tree decl, tree name)
21135 die = TYPE_SYMTAB_DIE (decl);
21139 dname = dwarf2_name (name, 0);
21143 attr = get_AT (die, DW_AT_name);
21146 struct indirect_string_node *node;
21148 node = find_AT_string (dname);
21149 /* replace the string. */
21150 attr->dw_attr_val.v.val_str = node;
21154 add_name_attribute (die, dname);
21157 /* Called by the final INSN scan whenever we see a direct function call.
21158 Make an entry into the direct call table, recording the point of call
21159 and a reference to the target function's debug entry. */
21162 dwarf2out_direct_call (tree targ)
21165 tree origin = decl_ultimate_origin (targ);
21167 /* If this is a clone, use the abstract origin as the target. */
21171 e.poc_label_num = poc_label_num++;
21172 e.poc_decl = current_function_decl;
21173 e.targ_die = force_decl_die (targ);
21174 VEC_safe_push (dcall_entry, gc, dcall_table, &e);
21176 /* Drop a label at the return point to mark the point of call. */
21177 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LPOC", e.poc_label_num);
21180 /* Returns a hash value for X (which really is a struct vcall_insn). */
21183 vcall_insn_table_hash (const void *x)
21185 return (hashval_t) ((const struct vcall_insn *) x)->insn_uid;
21188 /* Return nonzero if insn_uid of struct vcall_insn *X is the same as
21189 insnd_uid of *Y. */
21192 vcall_insn_table_eq (const void *x, const void *y)
21194 return (((const struct vcall_insn *) x)->insn_uid
21195 == ((const struct vcall_insn *) y)->insn_uid);
21198 /* Associate VTABLE_SLOT with INSN_UID in the VCALL_INSN_TABLE. */
21201 store_vcall_insn (unsigned int vtable_slot, int insn_uid)
21203 struct vcall_insn *item = ggc_alloc_vcall_insn ();
21204 struct vcall_insn **slot;
21207 item->insn_uid = insn_uid;
21208 item->vtable_slot = vtable_slot;
21209 slot = (struct vcall_insn **)
21210 htab_find_slot_with_hash (vcall_insn_table, &item,
21211 (hashval_t) insn_uid, INSERT);
21215 /* Return the VTABLE_SLOT associated with INSN_UID. */
21217 static unsigned int
21218 lookup_vcall_insn (unsigned int insn_uid)
21220 struct vcall_insn item;
21221 struct vcall_insn *p;
21223 item.insn_uid = insn_uid;
21224 item.vtable_slot = 0;
21225 p = (struct vcall_insn *) htab_find_with_hash (vcall_insn_table,
21227 (hashval_t) insn_uid);
21229 return (unsigned int) -1;
21230 return p->vtable_slot;
21234 /* Called when lowering indirect calls to RTL. We make a note of INSN_UID
21235 and the OBJ_TYPE_REF_TOKEN from ADDR. For C++ virtual calls, the token
21236 is the vtable slot index that we will need to put in the virtual call
21240 dwarf2out_virtual_call_token (tree addr, int insn_uid)
21242 if (is_cxx() && TREE_CODE (addr) == OBJ_TYPE_REF)
21244 tree token = OBJ_TYPE_REF_TOKEN (addr);
21245 if (TREE_CODE (token) == INTEGER_CST)
21246 store_vcall_insn (TREE_INT_CST_LOW (token), insn_uid);
21250 /* Called when scheduling RTL, when a CALL_INSN is split. Copies the
21251 OBJ_TYPE_REF_TOKEN previously associated with OLD_INSN and associates it
21255 dwarf2out_copy_call_info (rtx old_insn, rtx new_insn)
21257 unsigned int vtable_slot = lookup_vcall_insn (INSN_UID (old_insn));
21259 if (vtable_slot != (unsigned int) -1)
21260 store_vcall_insn (vtable_slot, INSN_UID (new_insn));
21263 /* Called by the final INSN scan whenever we see a virtual function call.
21264 Make an entry into the virtual call table, recording the point of call
21265 and the slot index of the vtable entry used to call the virtual member
21266 function. The slot index was associated with the INSN_UID during the
21267 lowering to RTL. */
21270 dwarf2out_virtual_call (int insn_uid)
21272 unsigned int vtable_slot = lookup_vcall_insn (insn_uid);
21275 if (vtable_slot == (unsigned int) -1)
21278 e.poc_label_num = poc_label_num++;
21279 e.vtable_slot = vtable_slot;
21280 VEC_safe_push (vcall_entry, gc, vcall_table, &e);
21282 /* Drop a label at the return point to mark the point of call. */
21283 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LPOC", e.poc_label_num);
21286 /* Called by the final INSN scan whenever we see a var location. We
21287 use it to drop labels in the right places, and throw the location in
21288 our lookup table. */
21291 dwarf2out_var_location (rtx loc_note)
21293 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
21294 struct var_loc_node *newloc;
21296 static const char *last_label;
21297 static const char *last_postcall_label;
21298 static bool last_in_cold_section_p;
21301 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
21304 next_real = next_real_insn (loc_note);
21305 /* If there are no instructions which would be affected by this note,
21306 don't do anything. */
21307 if (next_real == NULL_RTX && !NOTE_DURING_CALL_P (loc_note))
21310 /* If there were any real insns between note we processed last time
21311 and this note (or if it is the first note), clear
21312 last_{,postcall_}label so that they are not reused this time. */
21313 if (last_var_location_insn == NULL_RTX
21314 || last_var_location_insn != next_real
21315 || last_in_cold_section_p != in_cold_section_p)
21318 last_postcall_label = NULL;
21321 decl = NOTE_VAR_LOCATION_DECL (loc_note);
21322 newloc = add_var_loc_to_decl (decl, loc_note,
21323 NOTE_DURING_CALL_P (loc_note)
21324 ? last_postcall_label : last_label);
21325 if (newloc == NULL)
21328 /* If there were no real insns between note we processed last time
21329 and this note, use the label we emitted last time. Otherwise
21330 create a new label and emit it. */
21331 if (last_label == NULL)
21333 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
21334 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
21336 last_label = ggc_strdup (loclabel);
21339 if (!NOTE_DURING_CALL_P (loc_note))
21340 newloc->label = last_label;
21343 if (!last_postcall_label)
21345 sprintf (loclabel, "%s-1", last_label);
21346 last_postcall_label = ggc_strdup (loclabel);
21348 newloc->label = last_postcall_label;
21351 last_var_location_insn = next_real;
21352 last_in_cold_section_p = in_cold_section_p;
21355 /* We need to reset the locations at the beginning of each
21356 function. We can't do this in the end_function hook, because the
21357 declarations that use the locations won't have been output when
21358 that hook is called. Also compute have_multiple_function_sections here. */
21361 dwarf2out_begin_function (tree fun)
21363 if (function_section (fun) != text_section)
21364 have_multiple_function_sections = true;
21366 dwarf2out_note_section_used ();
21369 /* Output a label to mark the beginning of a source code line entry
21370 and record information relating to this source line, in
21371 'line_info_table' for later output of the .debug_line section. */
21374 dwarf2out_source_line (unsigned int line, const char *filename,
21375 int discriminator, bool is_stmt)
21377 static bool last_is_stmt = true;
21379 if (debug_info_level >= DINFO_LEVEL_NORMAL
21382 int file_num = maybe_emit_file (lookup_filename (filename));
21384 switch_to_section (current_function_section ());
21386 /* If requested, emit something human-readable. */
21387 if (flag_debug_asm)
21388 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
21391 if (DWARF2_ASM_LINE_DEBUG_INFO)
21393 /* Emit the .loc directive understood by GNU as. */
21394 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
21395 if (is_stmt != last_is_stmt)
21397 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
21398 last_is_stmt = is_stmt;
21400 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
21401 fprintf (asm_out_file, " discriminator %d", discriminator);
21402 fputc ('\n', asm_out_file);
21404 /* Indicate that line number info exists. */
21405 line_info_table_in_use++;
21407 else if (function_section (current_function_decl) != text_section)
21409 dw_separate_line_info_ref line_info;
21410 targetm.asm_out.internal_label (asm_out_file,
21411 SEPARATE_LINE_CODE_LABEL,
21412 separate_line_info_table_in_use);
21414 /* Expand the line info table if necessary. */
21415 if (separate_line_info_table_in_use
21416 == separate_line_info_table_allocated)
21418 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
21419 separate_line_info_table
21420 = GGC_RESIZEVEC (dw_separate_line_info_entry,
21421 separate_line_info_table,
21422 separate_line_info_table_allocated);
21423 memset (separate_line_info_table
21424 + separate_line_info_table_in_use,
21426 (LINE_INFO_TABLE_INCREMENT
21427 * sizeof (dw_separate_line_info_entry)));
21430 /* Add the new entry at the end of the line_info_table. */
21432 = &separate_line_info_table[separate_line_info_table_in_use++];
21433 line_info->dw_file_num = file_num;
21434 line_info->dw_line_num = line;
21435 line_info->function = current_function_funcdef_no;
21439 dw_line_info_ref line_info;
21441 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
21442 line_info_table_in_use);
21444 /* Expand the line info table if necessary. */
21445 if (line_info_table_in_use == line_info_table_allocated)
21447 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
21449 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
21450 line_info_table_allocated);
21451 memset (line_info_table + line_info_table_in_use, 0,
21452 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
21455 /* Add the new entry at the end of the line_info_table. */
21456 line_info = &line_info_table[line_info_table_in_use++];
21457 line_info->dw_file_num = file_num;
21458 line_info->dw_line_num = line;
21463 /* Record the beginning of a new source file. */
21466 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
21468 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
21470 /* Record the beginning of the file for break_out_includes. */
21471 dw_die_ref bincl_die;
21473 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
21474 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
21477 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21479 int file_num = maybe_emit_file (lookup_filename (filename));
21481 switch_to_section (debug_macinfo_section);
21482 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
21483 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
21486 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
21490 /* Record the end of a source file. */
21493 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
21495 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
21496 /* Record the end of the file for break_out_includes. */
21497 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
21499 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21501 switch_to_section (debug_macinfo_section);
21502 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
21506 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21507 the tail part of the directive line, i.e. the part which is past the
21508 initial whitespace, #, whitespace, directive-name, whitespace part. */
21511 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
21512 const char *buffer ATTRIBUTE_UNUSED)
21514 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21516 switch_to_section (debug_macinfo_section);
21517 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
21518 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
21519 dw2_asm_output_nstring (buffer, -1, "The macro");
21523 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21524 the tail part of the directive line, i.e. the part which is past the
21525 initial whitespace, #, whitespace, directive-name, whitespace part. */
21528 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
21529 const char *buffer ATTRIBUTE_UNUSED)
21531 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21533 switch_to_section (debug_macinfo_section);
21534 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
21535 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
21536 dw2_asm_output_nstring (buffer, -1, "The macro");
21540 /* Set up for Dwarf output at the start of compilation. */
21543 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
21545 /* Allocate the file_table. */
21546 file_table = htab_create_ggc (50, file_table_hash,
21547 file_table_eq, NULL);
21549 /* Allocate the decl_die_table. */
21550 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
21551 decl_die_table_eq, NULL);
21553 /* Allocate the decl_loc_table. */
21554 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
21555 decl_loc_table_eq, NULL);
21557 /* Allocate the initial hunk of the decl_scope_table. */
21558 decl_scope_table = VEC_alloc (tree, gc, 256);
21560 /* Allocate the initial hunk of the abbrev_die_table. */
21561 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
21562 (ABBREV_DIE_TABLE_INCREMENT);
21563 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
21564 /* Zero-th entry is allocated, but unused. */
21565 abbrev_die_table_in_use = 1;
21567 /* Allocate the initial hunk of the line_info_table. */
21568 line_info_table = ggc_alloc_cleared_vec_dw_line_info_entry
21569 (LINE_INFO_TABLE_INCREMENT);
21570 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
21572 /* Zero-th entry is allocated, but unused. */
21573 line_info_table_in_use = 1;
21575 /* Allocate the pubtypes and pubnames vectors. */
21576 pubname_table = VEC_alloc (pubname_entry, gc, 32);
21577 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
21579 /* Allocate the table that maps insn UIDs to vtable slot indexes. */
21580 vcall_insn_table = htab_create_ggc (10, vcall_insn_table_hash,
21581 vcall_insn_table_eq, NULL);
21583 /* Generate the initial DIE for the .debug section. Note that the (string)
21584 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
21585 will (typically) be a relative pathname and that this pathname should be
21586 taken as being relative to the directory from which the compiler was
21587 invoked when the given (base) source file was compiled. We will fill
21588 in this value in dwarf2out_finish. */
21589 comp_unit_die = gen_compile_unit_die (NULL);
21591 incomplete_types = VEC_alloc (tree, gc, 64);
21593 used_rtx_array = VEC_alloc (rtx, gc, 32);
21595 debug_info_section = get_section (DEBUG_INFO_SECTION,
21596 SECTION_DEBUG, NULL);
21597 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
21598 SECTION_DEBUG, NULL);
21599 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
21600 SECTION_DEBUG, NULL);
21601 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
21602 SECTION_DEBUG, NULL);
21603 debug_line_section = get_section (DEBUG_LINE_SECTION,
21604 SECTION_DEBUG, NULL);
21605 debug_loc_section = get_section (DEBUG_LOC_SECTION,
21606 SECTION_DEBUG, NULL);
21607 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
21608 SECTION_DEBUG, NULL);
21609 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
21610 SECTION_DEBUG, NULL);
21611 debug_dcall_section = get_section (DEBUG_DCALL_SECTION,
21612 SECTION_DEBUG, NULL);
21613 debug_vcall_section = get_section (DEBUG_VCALL_SECTION,
21614 SECTION_DEBUG, NULL);
21615 debug_str_section = get_section (DEBUG_STR_SECTION,
21616 DEBUG_STR_SECTION_FLAGS, NULL);
21617 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
21618 SECTION_DEBUG, NULL);
21619 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
21620 SECTION_DEBUG, NULL);
21622 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
21623 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
21624 DEBUG_ABBREV_SECTION_LABEL, 0);
21625 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
21626 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
21627 COLD_TEXT_SECTION_LABEL, 0);
21628 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
21630 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
21631 DEBUG_INFO_SECTION_LABEL, 0);
21632 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
21633 DEBUG_LINE_SECTION_LABEL, 0);
21634 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
21635 DEBUG_RANGES_SECTION_LABEL, 0);
21636 switch_to_section (debug_abbrev_section);
21637 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
21638 switch_to_section (debug_info_section);
21639 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
21640 switch_to_section (debug_line_section);
21641 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
21643 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21645 switch_to_section (debug_macinfo_section);
21646 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
21647 DEBUG_MACINFO_SECTION_LABEL, 0);
21648 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
21651 switch_to_section (text_section);
21652 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
21653 if (flag_reorder_blocks_and_partition)
21655 cold_text_section = unlikely_text_section ();
21656 switch_to_section (cold_text_section);
21657 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
21662 /* Called before cgraph_optimize starts outputtting functions, variables
21663 and toplevel asms into assembly. */
21666 dwarf2out_assembly_start (void)
21668 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE && dwarf2out_do_cfi_asm ())
21670 #ifndef TARGET_UNWIND_INFO
21671 if (USING_SJLJ_EXCEPTIONS || (!flag_unwind_tables && !flag_exceptions))
21673 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
21677 /* A helper function for dwarf2out_finish called through
21678 htab_traverse. Emit one queued .debug_str string. */
21681 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
21683 struct indirect_string_node *node = (struct indirect_string_node *) *h;
21685 if (node->label && node->refcount)
21687 switch_to_section (debug_str_section);
21688 ASM_OUTPUT_LABEL (asm_out_file, node->label);
21689 assemble_string (node->str, strlen (node->str) + 1);
21695 #if ENABLE_ASSERT_CHECKING
21696 /* Verify that all marks are clear. */
21699 verify_marks_clear (dw_die_ref die)
21703 gcc_assert (! die->die_mark);
21704 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
21706 #endif /* ENABLE_ASSERT_CHECKING */
21708 /* Clear the marks for a die and its children.
21709 Be cool if the mark isn't set. */
21712 prune_unmark_dies (dw_die_ref die)
21718 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
21721 /* Given DIE that we're marking as used, find any other dies
21722 it references as attributes and mark them as used. */
21725 prune_unused_types_walk_attribs (dw_die_ref die)
21730 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
21732 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
21734 /* A reference to another DIE.
21735 Make sure that it will get emitted.
21736 If it was broken out into a comdat group, don't follow it. */
21737 if (dwarf_version < 4
21738 || a->dw_attr == DW_AT_specification
21739 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
21740 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
21742 /* Set the string's refcount to 0 so that prune_unused_types_mark
21743 accounts properly for it. */
21744 if (AT_class (a) == dw_val_class_str)
21745 a->dw_attr_val.v.val_str->refcount = 0;
21750 /* Mark DIE as being used. If DOKIDS is true, then walk down
21751 to DIE's children. */
21754 prune_unused_types_mark (dw_die_ref die, int dokids)
21758 if (die->die_mark == 0)
21760 /* We haven't done this node yet. Mark it as used. */
21763 /* We also have to mark its parents as used.
21764 (But we don't want to mark our parents' kids due to this.) */
21765 if (die->die_parent)
21766 prune_unused_types_mark (die->die_parent, 0);
21768 /* Mark any referenced nodes. */
21769 prune_unused_types_walk_attribs (die);
21771 /* If this node is a specification,
21772 also mark the definition, if it exists. */
21773 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
21774 prune_unused_types_mark (die->die_definition, 1);
21777 if (dokids && die->die_mark != 2)
21779 /* We need to walk the children, but haven't done so yet.
21780 Remember that we've walked the kids. */
21783 /* If this is an array type, we need to make sure our
21784 kids get marked, even if they're types. If we're
21785 breaking out types into comdat sections, do this
21786 for all type definitions. */
21787 if (die->die_tag == DW_TAG_array_type
21788 || (dwarf_version >= 4
21789 && is_type_die (die) && ! is_declaration_die (die)))
21790 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
21792 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
21796 /* For local classes, look if any static member functions were emitted
21797 and if so, mark them. */
21800 prune_unused_types_walk_local_classes (dw_die_ref die)
21804 if (die->die_mark == 2)
21807 switch (die->die_tag)
21809 case DW_TAG_structure_type:
21810 case DW_TAG_union_type:
21811 case DW_TAG_class_type:
21814 case DW_TAG_subprogram:
21815 if (!get_AT_flag (die, DW_AT_declaration)
21816 || die->die_definition != NULL)
21817 prune_unused_types_mark (die, 1);
21824 /* Mark children. */
21825 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
21828 /* Walk the tree DIE and mark types that we actually use. */
21831 prune_unused_types_walk (dw_die_ref die)
21835 /* Don't do anything if this node is already marked and
21836 children have been marked as well. */
21837 if (die->die_mark == 2)
21840 switch (die->die_tag)
21842 case DW_TAG_structure_type:
21843 case DW_TAG_union_type:
21844 case DW_TAG_class_type:
21845 if (die->die_perennial_p)
21848 for (c = die->die_parent; c; c = c->die_parent)
21849 if (c->die_tag == DW_TAG_subprogram)
21852 /* Finding used static member functions inside of classes
21853 is needed just for local classes, because for other classes
21854 static member function DIEs with DW_AT_specification
21855 are emitted outside of the DW_TAG_*_type. If we ever change
21856 it, we'd need to call this even for non-local classes. */
21858 prune_unused_types_walk_local_classes (die);
21860 /* It's a type node --- don't mark it. */
21863 case DW_TAG_const_type:
21864 case DW_TAG_packed_type:
21865 case DW_TAG_pointer_type:
21866 case DW_TAG_reference_type:
21867 case DW_TAG_rvalue_reference_type:
21868 case DW_TAG_volatile_type:
21869 case DW_TAG_typedef:
21870 case DW_TAG_array_type:
21871 case DW_TAG_interface_type:
21872 case DW_TAG_friend:
21873 case DW_TAG_variant_part:
21874 case DW_TAG_enumeration_type:
21875 case DW_TAG_subroutine_type:
21876 case DW_TAG_string_type:
21877 case DW_TAG_set_type:
21878 case DW_TAG_subrange_type:
21879 case DW_TAG_ptr_to_member_type:
21880 case DW_TAG_file_type:
21881 if (die->die_perennial_p)
21884 /* It's a type node --- don't mark it. */
21888 /* Mark everything else. */
21892 if (die->die_mark == 0)
21896 /* Now, mark any dies referenced from here. */
21897 prune_unused_types_walk_attribs (die);
21902 /* Mark children. */
21903 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
21906 /* Increment the string counts on strings referred to from DIE's
21910 prune_unused_types_update_strings (dw_die_ref die)
21915 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
21916 if (AT_class (a) == dw_val_class_str)
21918 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
21920 /* Avoid unnecessarily putting strings that are used less than
21921 twice in the hash table. */
21923 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
21926 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
21927 htab_hash_string (s->str),
21929 gcc_assert (*slot == NULL);
21935 /* Remove from the tree DIE any dies that aren't marked. */
21938 prune_unused_types_prune (dw_die_ref die)
21942 gcc_assert (die->die_mark);
21943 prune_unused_types_update_strings (die);
21945 if (! die->die_child)
21948 c = die->die_child;
21950 dw_die_ref prev = c;
21951 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
21952 if (c == die->die_child)
21954 /* No marked children between 'prev' and the end of the list. */
21956 /* No marked children at all. */
21957 die->die_child = NULL;
21960 prev->die_sib = c->die_sib;
21961 die->die_child = prev;
21966 if (c != prev->die_sib)
21968 prune_unused_types_prune (c);
21969 } while (c != die->die_child);
21972 /* A helper function for dwarf2out_finish called through
21973 htab_traverse. Clear .debug_str strings that we haven't already
21974 decided to emit. */
21977 prune_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
21979 struct indirect_string_node *node = (struct indirect_string_node *) *h;
21981 if (!node->label || !node->refcount)
21982 htab_clear_slot (debug_str_hash, h);
21987 /* Remove dies representing declarations that we never use. */
21990 prune_unused_types (void)
21993 limbo_die_node *node;
21994 comdat_type_node *ctnode;
21996 dcall_entry *dcall;
21998 #if ENABLE_ASSERT_CHECKING
21999 /* All the marks should already be clear. */
22000 verify_marks_clear (comp_unit_die);
22001 for (node = limbo_die_list; node; node = node->next)
22002 verify_marks_clear (node->die);
22003 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22004 verify_marks_clear (ctnode->root_die);
22005 #endif /* ENABLE_ASSERT_CHECKING */
22007 /* Mark types that are used in global variables. */
22008 premark_types_used_by_global_vars ();
22010 /* Set the mark on nodes that are actually used. */
22011 prune_unused_types_walk (comp_unit_die);
22012 for (node = limbo_die_list; node; node = node->next)
22013 prune_unused_types_walk (node->die);
22014 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22016 prune_unused_types_walk (ctnode->root_die);
22017 prune_unused_types_mark (ctnode->type_die, 1);
22020 /* Also set the mark on nodes referenced from the
22021 pubname_table or arange_table. */
22022 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
22023 prune_unused_types_mark (pub->die, 1);
22024 for (i = 0; i < arange_table_in_use; i++)
22025 prune_unused_types_mark (arange_table[i], 1);
22027 /* Mark nodes referenced from the direct call table. */
22028 FOR_EACH_VEC_ELT (dcall_entry, dcall_table, i, dcall)
22029 prune_unused_types_mark (dcall->targ_die, 1);
22031 /* Get rid of nodes that aren't marked; and update the string counts. */
22032 if (debug_str_hash && debug_str_hash_forced)
22033 htab_traverse (debug_str_hash, prune_indirect_string, NULL);
22034 else if (debug_str_hash)
22035 htab_empty (debug_str_hash);
22036 prune_unused_types_prune (comp_unit_die);
22037 for (node = limbo_die_list; node; node = node->next)
22038 prune_unused_types_prune (node->die);
22039 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22040 prune_unused_types_prune (ctnode->root_die);
22042 /* Leave the marks clear. */
22043 prune_unmark_dies (comp_unit_die);
22044 for (node = limbo_die_list; node; node = node->next)
22045 prune_unmark_dies (node->die);
22046 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22047 prune_unmark_dies (ctnode->root_die);
22050 /* Set the parameter to true if there are any relative pathnames in
22053 file_table_relative_p (void ** slot, void *param)
22055 bool *p = (bool *) param;
22056 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
22057 if (!IS_ABSOLUTE_PATH (d->filename))
22065 /* Routines to manipulate hash table of comdat type units. */
22068 htab_ct_hash (const void *of)
22071 const comdat_type_node *const type_node = (const comdat_type_node *) of;
22073 memcpy (&h, type_node->signature, sizeof (h));
22078 htab_ct_eq (const void *of1, const void *of2)
22080 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
22081 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
22083 return (! memcmp (type_node_1->signature, type_node_2->signature,
22084 DWARF_TYPE_SIGNATURE_SIZE));
22087 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22088 to the location it would have been added, should we know its
22089 DECL_ASSEMBLER_NAME when we added other attributes. This will
22090 probably improve compactness of debug info, removing equivalent
22091 abbrevs, and hide any differences caused by deferring the
22092 computation of the assembler name, triggered by e.g. PCH. */
22095 move_linkage_attr (dw_die_ref die)
22097 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
22098 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
22100 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
22101 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
22105 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
22107 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
22111 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
22113 VEC_pop (dw_attr_node, die->die_attr);
22114 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
22118 /* Helper function for resolve_addr, attempt to resolve
22119 one CONST_STRING, return non-zero if not successful. Similarly verify that
22120 SYMBOL_REFs refer to variables emitted in the current CU. */
22123 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
22127 if (GET_CODE (rtl) == CONST_STRING)
22129 size_t len = strlen (XSTR (rtl, 0)) + 1;
22130 tree t = build_string (len, XSTR (rtl, 0));
22131 tree tlen = build_int_cst (NULL_TREE, len - 1);
22133 = build_array_type (char_type_node, build_index_type (tlen));
22134 rtl = lookup_constant_def (t);
22135 if (!rtl || !MEM_P (rtl))
22137 rtl = XEXP (rtl, 0);
22138 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
22143 if (GET_CODE (rtl) == SYMBOL_REF
22144 && SYMBOL_REF_DECL (rtl)
22145 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
22148 if (GET_CODE (rtl) == CONST
22149 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
22155 /* Helper function for resolve_addr, handle one location
22156 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22157 the location list couldn't be resolved. */
22160 resolve_addr_in_expr (dw_loc_descr_ref loc)
22162 for (; loc; loc = loc->dw_loc_next)
22163 if (((loc->dw_loc_opc == DW_OP_addr || loc->dtprel)
22164 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
22165 || (loc->dw_loc_opc == DW_OP_implicit_value
22166 && loc->dw_loc_oprnd2.val_class == dw_val_class_addr
22167 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL)))
22172 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
22173 an address in .rodata section if the string literal is emitted there,
22174 or remove the containing location list or replace DW_AT_const_value
22175 with DW_AT_location and empty location expression, if it isn't found
22176 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
22177 to something that has been emitted in the current CU. */
22180 resolve_addr (dw_die_ref die)
22184 dw_loc_list_ref *curr;
22187 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22188 switch (AT_class (a))
22190 case dw_val_class_loc_list:
22191 curr = AT_loc_list_ptr (a);
22194 if (!resolve_addr_in_expr ((*curr)->expr))
22196 dw_loc_list_ref next = (*curr)->dw_loc_next;
22197 if (next && (*curr)->ll_symbol)
22199 gcc_assert (!next->ll_symbol);
22200 next->ll_symbol = (*curr)->ll_symbol;
22205 curr = &(*curr)->dw_loc_next;
22207 if (!AT_loc_list (a))
22209 remove_AT (die, a->dw_attr);
22213 case dw_val_class_loc:
22214 if (!resolve_addr_in_expr (AT_loc (a)))
22216 remove_AT (die, a->dw_attr);
22220 case dw_val_class_addr:
22221 if (a->dw_attr == DW_AT_const_value
22222 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
22224 remove_AT (die, a->dw_attr);
22232 FOR_EACH_CHILD (die, c, resolve_addr (c));
22235 /* Output stuff that dwarf requires at the end of every file,
22236 and generate the DWARF-2 debugging info. */
22239 dwarf2out_finish (const char *filename)
22241 limbo_die_node *node, *next_node;
22242 comdat_type_node *ctnode;
22243 htab_t comdat_type_table;
22244 dw_die_ref die = 0;
22247 gen_remaining_tmpl_value_param_die_attribute ();
22249 /* Add the name for the main input file now. We delayed this from
22250 dwarf2out_init to avoid complications with PCH. */
22251 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
22252 if (!IS_ABSOLUTE_PATH (filename))
22253 add_comp_dir_attribute (comp_unit_die);
22254 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
22257 htab_traverse (file_table, file_table_relative_p, &p);
22259 add_comp_dir_attribute (comp_unit_die);
22262 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
22264 add_location_or_const_value_attribute (
22265 VEC_index (deferred_locations, deferred_locations_list, i)->die,
22266 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
22270 /* Traverse the limbo die list, and add parent/child links. The only
22271 dies without parents that should be here are concrete instances of
22272 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
22273 For concrete instances, we can get the parent die from the abstract
22275 for (node = limbo_die_list; node; node = next_node)
22277 next_node = node->next;
22280 if (die->die_parent == NULL)
22282 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
22285 add_child_die (origin->die_parent, die);
22286 else if (die == comp_unit_die)
22288 else if (seen_error ())
22289 /* It's OK to be confused by errors in the input. */
22290 add_child_die (comp_unit_die, die);
22293 /* In certain situations, the lexical block containing a
22294 nested function can be optimized away, which results
22295 in the nested function die being orphaned. Likewise
22296 with the return type of that nested function. Force
22297 this to be a child of the containing function.
22299 It may happen that even the containing function got fully
22300 inlined and optimized out. In that case we are lost and
22301 assign the empty child. This should not be big issue as
22302 the function is likely unreachable too. */
22303 tree context = NULL_TREE;
22305 gcc_assert (node->created_for);
22307 if (DECL_P (node->created_for))
22308 context = DECL_CONTEXT (node->created_for);
22309 else if (TYPE_P (node->created_for))
22310 context = TYPE_CONTEXT (node->created_for);
22312 gcc_assert (context
22313 && (TREE_CODE (context) == FUNCTION_DECL
22314 || TREE_CODE (context) == NAMESPACE_DECL));
22316 origin = lookup_decl_die (context);
22318 add_child_die (origin, die);
22320 add_child_die (comp_unit_die, die);
22325 limbo_die_list = NULL;
22327 resolve_addr (comp_unit_die);
22329 for (node = deferred_asm_name; node; node = node->next)
22331 tree decl = node->created_for;
22332 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
22334 add_linkage_attr (node->die, decl);
22335 move_linkage_attr (node->die);
22339 deferred_asm_name = NULL;
22341 /* Walk through the list of incomplete types again, trying once more to
22342 emit full debugging info for them. */
22343 retry_incomplete_types ();
22345 if (flag_eliminate_unused_debug_types)
22346 prune_unused_types ();
22348 /* Generate separate CUs for each of the include files we've seen.
22349 They will go into limbo_die_list. */
22350 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
22351 break_out_includes (comp_unit_die);
22353 /* Generate separate COMDAT sections for type DIEs. */
22354 if (dwarf_version >= 4)
22356 break_out_comdat_types (comp_unit_die);
22358 /* Each new type_unit DIE was added to the limbo die list when created.
22359 Since these have all been added to comdat_type_list, clear the
22361 limbo_die_list = NULL;
22363 /* For each new comdat type unit, copy declarations for incomplete
22364 types to make the new unit self-contained (i.e., no direct
22365 references to the main compile unit). */
22366 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22367 copy_decls_for_unworthy_types (ctnode->root_die);
22368 copy_decls_for_unworthy_types (comp_unit_die);
22370 /* In the process of copying declarations from one unit to another,
22371 we may have left some declarations behind that are no longer
22372 referenced. Prune them. */
22373 prune_unused_types ();
22376 /* Traverse the DIE's and add add sibling attributes to those DIE's
22377 that have children. */
22378 add_sibling_attributes (comp_unit_die);
22379 for (node = limbo_die_list; node; node = node->next)
22380 add_sibling_attributes (node->die);
22381 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22382 add_sibling_attributes (ctnode->root_die);
22384 /* Output a terminator label for the .text section. */
22385 switch_to_section (text_section);
22386 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
22387 if (flag_reorder_blocks_and_partition)
22389 switch_to_section (unlikely_text_section ());
22390 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
22393 /* We can only use the low/high_pc attributes if all of the code was
22395 if (!have_multiple_function_sections
22396 || !(dwarf_version >= 3 || !dwarf_strict))
22398 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
22399 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
22404 unsigned fde_idx = 0;
22405 bool range_list_added = false;
22407 /* We need to give .debug_loc and .debug_ranges an appropriate
22408 "base address". Use zero so that these addresses become
22409 absolute. Historically, we've emitted the unexpected
22410 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
22411 Emit both to give time for other tools to adapt. */
22412 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
22413 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
22415 if (text_section_used)
22416 add_ranges_by_labels (comp_unit_die, text_section_label,
22417 text_end_label, &range_list_added);
22418 if (flag_reorder_blocks_and_partition && cold_text_section_used)
22419 add_ranges_by_labels (comp_unit_die, cold_text_section_label,
22420 cold_end_label, &range_list_added);
22422 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
22424 dw_fde_ref fde = &fde_table[fde_idx];
22426 if (fde->dw_fde_switched_sections)
22428 if (!fde->in_std_section)
22429 add_ranges_by_labels (comp_unit_die,
22430 fde->dw_fde_hot_section_label,
22431 fde->dw_fde_hot_section_end_label,
22432 &range_list_added);
22433 if (!fde->cold_in_std_section)
22434 add_ranges_by_labels (comp_unit_die,
22435 fde->dw_fde_unlikely_section_label,
22436 fde->dw_fde_unlikely_section_end_label,
22437 &range_list_added);
22439 else if (!fde->in_std_section)
22440 add_ranges_by_labels (comp_unit_die, fde->dw_fde_begin,
22441 fde->dw_fde_end, &range_list_added);
22444 if (range_list_added)
22448 /* Output location list section if necessary. */
22449 if (have_location_lists)
22451 /* Output the location lists info. */
22452 switch_to_section (debug_loc_section);
22453 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
22454 DEBUG_LOC_SECTION_LABEL, 0);
22455 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
22456 output_location_lists (die);
22459 if (debug_info_level >= DINFO_LEVEL_NORMAL)
22460 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
22461 debug_line_section_label);
22463 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22464 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
22466 /* Output all of the compilation units. We put the main one last so that
22467 the offsets are available to output_pubnames. */
22468 for (node = limbo_die_list; node; node = node->next)
22469 output_comp_unit (node->die, 0);
22471 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
22472 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22474 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
22476 /* Don't output duplicate types. */
22477 if (*slot != HTAB_EMPTY_ENTRY)
22480 /* Add a pointer to the line table for the main compilation unit
22481 so that the debugger can make sense of DW_AT_decl_file
22483 if (debug_info_level >= DINFO_LEVEL_NORMAL)
22484 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
22485 debug_line_section_label);
22487 output_comdat_type_unit (ctnode);
22490 htab_delete (comdat_type_table);
22492 /* Output the main compilation unit if non-empty or if .debug_macinfo
22493 has been emitted. */
22494 output_comp_unit (comp_unit_die, debug_info_level >= DINFO_LEVEL_VERBOSE);
22496 /* Output the abbreviation table. */
22497 switch_to_section (debug_abbrev_section);
22498 output_abbrev_section ();
22500 /* Output public names table if necessary. */
22501 if (!VEC_empty (pubname_entry, pubname_table))
22503 switch_to_section (debug_pubnames_section);
22504 output_pubnames (pubname_table);
22507 /* Output public types table if necessary. */
22508 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
22509 It shouldn't hurt to emit it always, since pure DWARF2 consumers
22510 simply won't look for the section. */
22511 if (!VEC_empty (pubname_entry, pubtype_table))
22513 switch_to_section (debug_pubtypes_section);
22514 output_pubnames (pubtype_table);
22517 /* Output direct and virtual call tables if necessary. */
22518 if (!VEC_empty (dcall_entry, dcall_table))
22520 switch_to_section (debug_dcall_section);
22521 output_dcall_table ();
22523 if (!VEC_empty (vcall_entry, vcall_table))
22525 switch_to_section (debug_vcall_section);
22526 output_vcall_table ();
22529 /* Output the address range information. We only put functions in the arange
22530 table, so don't write it out if we don't have any. */
22531 if (fde_table_in_use)
22533 switch_to_section (debug_aranges_section);
22537 /* Output ranges section if necessary. */
22538 if (ranges_table_in_use)
22540 switch_to_section (debug_ranges_section);
22541 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
22545 /* Output the source line correspondence table. We must do this
22546 even if there is no line information. Otherwise, on an empty
22547 translation unit, we will generate a present, but empty,
22548 .debug_info section. IRIX 6.5 `nm' will then complain when
22549 examining the file. This is done late so that any filenames
22550 used by the debug_info section are marked as 'used'. */
22551 if (! DWARF2_ASM_LINE_DEBUG_INFO)
22553 switch_to_section (debug_line_section);
22554 output_line_info ();
22557 /* Have to end the macro section. */
22558 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22560 switch_to_section (debug_macinfo_section);
22561 dw2_asm_output_data (1, 0, "End compilation unit");
22564 /* If we emitted any DW_FORM_strp form attribute, output the string
22566 if (debug_str_hash)
22567 htab_traverse (debug_str_hash, output_indirect_string, NULL);
22570 #include "gt-dwarf2out.h"